BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TBuilderCosmic.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TBuilderCosmic.cxx,v 1.6 2010/03/31 09:58:59 liucy Exp $
3//-----------------------------------------------------------------------------
4// Filename : TBuilderCosmic.cc
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : yoshihito.iwasaki@kek.jp
8//-----------------------------------------------------------------------------
9// Description : A class to build a cosmic track.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13#ifdef TRKRECO_DEBUG_DETAIL
14# ifndef TRKRECO_DEBUG
15# define TRKRECO_DEBUG
16# endif
17#endif
18#include "TrkReco/TBuilderCosmic.h"
19#include "TrkReco/T3DLine.h"
20#include "TrkReco/TLine0.h"
21#include "TrkReco/TMLink.h"
22#include "TrkReco/TTrack.h"
23
24TBuilderCosmic::TBuilderCosmic( const std::string& name, float salvageLevel )
25 : TBuilder0( name, salvageLevel ), _fitter( "TBuilderCosmic Fitter" ) {}
26
28
30#ifdef TRKRECO_DEBUG_DETAIL
31 std::cout << name() << "(stereo) ... dump of stereo candidate hits" << std::endl;
32 AList<TMLink> tmp = list;
33 tmp.sort( SortByWireId );
34 std::cout << " ";
35 for ( unsigned i = 0; i < tmp.length(); i++ )
36 {
37 TMLink* l = tmp[i];
38 std::cout << l->wire()->layerId() << "-";
39 std::cout << l->wire()->localId() << ",";
40 }
41 std::cout << std::endl;
42#endif
43
44 //...Check # of links...
45 if ( list.length() < _lineSelector.nLinksStereo() )
46 {
47#ifdef TRKRECO_DEBUG_DETAIL
48 std::cout << name() << "(stereo) ... rejected by nLinks(";
49 std::cout << list.length() << ") < ";
50 std::cout << _lineSelector.nLinks() << std::endl;
51#endif
52 return NULL;
53 }
54
55 //...Calculate s and z for every links...
56 unsigned n = list.length();
57 AList<TMLink> forLine;
58 for ( unsigned i = 0; i < n; i++ )
59 {
60 TMLink* l = list[i];
61
62 //... Require Fitting vaildation
63 if ( !( l->hit()->state() & WireHitFittingValid ) ) continue;
64
65 TMLink* t = new TMLink( *l );
66
67 //...Assuming wire position...
68 t->leftRight( 2 );
69 int err = track.szPosition( *t );
70 if ( err )
71 {
72 delete t;
73 continue;
74 }
75
76 //...Store the sz link...
77 t->link( l );
78 forLine.append( t );
79 }
80
81#ifdef TRKRECO_DEBUG_DETAIL
82 std::cout << name() << "(stereo) ... dump of sz links" << std::endl;
83 std::cout << " ";
84 tmp = forLine;
85 tmp.sort( SortByWireId );
86 for ( unsigned i = 0; i < tmp.length(); i++ )
87 {
88 TMLink* l = tmp[i];
89 std::cout << l->wire()->layerId() << "-";
90 std::cout << l->wire()->localId() << ",";
91 }
92 std::cout << std::endl;
93#endif
94
95 //...Check # of sz links...
96 if ( forLine.length() < _lineSelector.nLinksStereo() )
97 {
98#ifdef TRKRECO_DEBUG_DETAIL
99 std::cout << name() << "(stereo) ... rejected by sz nLinks(";
100 std::cout << forLine.length() << ") < ";
101 std::cout << _lineSelector.nLinks() << std::endl;
102#endif
103 HepAListDeleteAll( forLine );
104 return NULL;
105 }
106
107 //...Make a line...
108 unsigned nLine = forLine.length();
109 TLine0 line( forLine );
110 int err = line.fit();
111
112 //...Linear fit...
113 if ( err < 0 )
114 {
115#ifdef TRKRECO_DEBUG_DETAIL
116 std::cout << name() << "(stereo) ... linear fit failure. nLinks(";
117 std::cout << forLine.length() << ")" << std::endl;
118#endif
119 HepAListDeleteAll( forLine );
120 return NULL;
121 }
122
123#ifdef TRKRECO_DEBUG_DETAIL
124 std::cout << name() << "(stereo) ... dump of left-right" << std::endl;
125#endif
126
127 //...Decide Left or Right...
128 AList<TMLink> forNewLine;
129 for ( unsigned i = 0; i < nLine; i++ )
130 {
131 TMLink* t = forLine[i];
132 TMLink* tl = new TMLink( *t );
133 TMLink* tr = new TMLink( *t );
134
135 tl->leftRight( WireHitLeft );
136 tr->leftRight( WireHitRight );
137
138 int err = track.szPosition( *tl );
139 if ( err )
140 {
141 delete tl;
142 tl = NULL;
143 }
144 err = track.szPosition( *tr );
145 if ( err )
146 {
147 delete tr;
148 tr = NULL;
149 }
150 if ( ( tl == NULL ) && ( tr == NULL ) ) continue;
151
152 TMLink* best;
153 if ( tl == NULL ) best = tr;
154 else if ( tr == NULL ) best = tl;
155 else
156 {
157 if ( line.distance( *tl ) < line.distance( *tr ) )
158 {
159 best = tl;
160 delete tr;
161 }
162 else
163 {
164 best = tr;
165 delete tl;
166 }
167 }
168
169#ifdef TRKRECO_DEBUG_DETAIL
170 std::cout << " ";
171 std::cout << t->wire()->layerId() << "-";
172 std::cout << t->wire()->localId();
173 if ( tl != NULL ) std::cout << ",left " << tl->position() << "," << line.distance( *tl );
174 if ( tr != NULL ) std::cout << ",right " << tr->position() << "," << line.distance( *tr );
175 std::cout << std::endl;
176#endif
177
178 best->link( t->link() );
179 forNewLine.append( best );
180 }
181
182 //...Check # of sz links...
183 if ( forNewLine.length() < _lineSelector.nLinksStereo() )
184 {
185#ifdef TRKRECO_DEBUG_DETAIL
186 std::cout << name() << "(stereo) ... rejected by lr nLinks(";
187 std::cout << forNewLine.length() << ") < ";
188 std::cout << _lineSelector.nLinks() << std::endl;
189#endif
190 HepAListDeleteAll( forLine );
191 HepAListDeleteAll( forNewLine );
192 return NULL;
193 }
194
195 //...Create new line...
196#ifdef TRKRECO_DEBUG_DETAIL
197 std::cout << name() << "(stereo) ... creating a new line" << std::endl;
198#endif
199 unsigned nNewLine = forNewLine.length();
200 TLine0 newLine( forNewLine );
201
202 //...Make a seed track again
203 err = newLine.fit();
204
205 //...Linear fit...
206 if ( err < 0 )
207 {
208#ifdef TRKRECO_DEBUG_DETAIL
209 std::cout << name() << "(stereo) ... 2nd linear fit failure. nLinks(";
210 std::cout << forNewLine.length() << ")" << std::endl;
211#endif
212 HepAListDeleteAll( forLine );
213 HepAListDeleteAll( forNewLine );
214 return NULL;
215 }
216
217 //...Remove bad points...
218 AList<TMLink> bad;
219 // newLine.refine(bad, 40.); //Liuqg, meaningless while without magnetic field
220 // err = newLine.fit();
221 // newLine.refine(bad, 20.);
222 // err = newLine.fit();
223 // newLine.refine(bad, 10.);
224 // err = newLine.fit();
225
226 //...Linear fit again...
227 if ( err < 0 )
228 {
229 HepAListDeleteAll( forLine );
230 HepAListDeleteAll( forNewLine );
231#ifdef TRKRECO_DEBUG_DETAIL
232 std::cout << " appendStereo cut ... new line 2nd linear fit failure. ";
233 std::cout << "# of links = " << n << "," << nLine;
234 std::cout << "," << nNewLine << std::endl;
235#endif
236 return NULL;
237 }
238
239 //...3D fit...
240 const AList<TMLink>& good = newLine.links();
241 unsigned nn = good.length();
242 for ( unsigned i = 0; i < nn; i++ ) { track.append( *good[i]->link() ); }
243 Vector a( 5 );
244 a = track.helix().a();
245 a[3] = newLine.b();
246 a[4] = track.charge() * newLine.a();
247 track._helix->a( a );
248
249#ifdef LINE_COSMIC
250 T3DLine* Ltrack = new T3DLine( track );
251
252 //...Refine...
253 err = _fitter.fit( *Ltrack );
254 Ltrack->refine( bad, _trackSelector.maxSigma() * 30. );
255 err = _fitter.fit( *Ltrack );
256 Ltrack->refine( bad, _trackSelector.maxSigma() * 3. );
257 err = _fitter.fit( *Ltrack );
258 // Ltrack->refine(bad, _trackSelector.maxSigma() * 0.21); //liuqg, for prelimilary test
259 track.refine( bad, _trackSelector.maxSigma() );
260 err = _fitter.fit( *Ltrack );
261
262 //...Test it...
263 /* if (! _trackSelector.select(*Ltrack)) {
264 HepAListDeleteAll(forLine);
265 HepAListDeleteAll(forNewLine);
266 delete Ltrack;
267 return NULL;
268 }
269 */
270 //...Termination...
271 HepAListDeleteAll( forLine );
272 HepAListDeleteAll( forNewLine );
273 track.removeLinks();
274 track.append( Ltrack->links() );
275 Vector a1( 5 );
276 a1 = Ltrack->helix().a();
277 track._helix->a( a1 );
278 delete Ltrack;
279 return &track;
280#endif
281
282 //...Refine...
283 err = _fitter.fit( track );
284 track.refine( bad, _trackSelector.maxSigma() * 30. );
285 err = _fitter.fit( track );
286 track.refine( bad, _trackSelector.maxSigma() * 3. );
287 err = _fitter.fit( track );
288 track.refine( bad, _trackSelector.maxSigma() ); // liuqg, for prelimilary test
289 // track.refine(bad, _trackSelector.maxSigma() * 0.21);
290 err = _fitter.fit( track );
291 //...Test it...
292 if ( !_trackSelector.select( track ) )
293 {
294 HepAListDeleteAll( forLine );
295 HepAListDeleteAll( forNewLine );
296 return NULL;
297 }
298
299 //...Termination...
300 HepAListDeleteAll( forLine );
301 HepAListDeleteAll( forNewLine );
302 return &track;
303}
const Int_t n
DOUBLE_PRECISION tr[3]
const HepVector & a(void) const
returns helix parameters.
A class to represent a track in tracking.
Helix helix(void) const
approximated helix class
Definition T3DLine.cxx:111
const std::string & name(void) const
returns name.
TBuilder0(const std::string &name)
Constructor.
Definition TBuilder0.cxx:31
virtual ~TBuilderCosmic()
Destructor.
TTrack * buildStereo(TTrack &track, const AList< TMLink > &) const
appends stereo hits to a track.
TBuilderCosmic(const std::string &name, float salvageLevel)
Constructor.
A class to represent a track in tracking.
double distance(const TMLink &) const
returns distance to a position of TMLink itself. (not to a wire)
double b(void) const
returns coefficient b.
double a(void) const
returns coefficient a.
unsigned localId(void) const
returns local id in a wire layer.
unsigned layerId(void) const
returns layer id.
virtual int fit(void)
fits itself by a default fitter. Error was happened if return value is not zero.
virtual void refine(AList< TMLink > &list, double maxSigma)
virtual void removeLinks(void)
void append(TMLink &)
appends a TMLink.
const AList< TMLink > & links(unsigned mask=0) const
A class to represent a track in tracking.
const Helix & helix(void) const
returns helix parameter.
int szPosition(TMLink &link) const
calculates arc length and z for a stereo hit.
Definition TTrack.cxx:3387
double charge(void) const
returns charge.
int t()
Definition t.c:1