BOSS 7.0.1
BESIII Offline Software System
Loading...
Searching...
No Matches
TTrackBase.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TTrackBase.cxx,v 1.19 2011/09/05 17:32:47 maoh Exp $
3//-----------------------------------------------------------------------------
4// Filename : TTrackBase.h
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : [email protected]
8//-----------------------------------------------------------------------------
9// Description : A virtual class for a track class in tracking.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13#define HEP_SHORT_NAMES
14#include "CLHEP/Alist/CList.h"
15#include "TrkReco/TTrackBase.h"
16#include "TrkReco/TMLink.h"
17#include "TrkReco/TMDCWire.h"
18#include "TrkReco/TMDCWireHit.h"
19#include "TrkReco/TMDCWireHitMC.h"
20#include "TrkReco/TMDCUtil.h"
21#include "TrkReco/TTrackHEP.h"
22#include "TrkReco/TMFitter.h"
23
25: _links(a),
26 _mc(0),
27// _superLayer(0),
28// _nSuperLayers(0),
29 _fitter(0),
30 _updated(false),
31 _fitted(false),
32 _time(0.) {
33// _layer[0] = 0;
34// _layer[1] = 0;
35// _nLayers[0] = 0;
36// _nLayers[1] = 0;
37// update();
38}
39
41: _mc(0),
42// _superLayer(0),
43// _nSuperLayers(0),
44 _fitter(0),
45 _updated(true),
46 _fitted(false),
47 _time(0.) {
48// _layer[0] = 0;
49// _layer[1] = 0;
50// _nLayers[0] = 0;
51// _nLayers[1] = 0;
52}
53
55}
56
57void
58TTrackBase::dump(const std::string & msg, const std::string & pre) const {
59 bool mc = (msg.find("mc") != std::string::npos);
60 bool pull = (msg.find("pull") != std::string::npos);
61 bool flag = (msg.find("flag") != std::string::npos);
62 bool detail = (msg.find("detail") != std::string::npos);
63 if (detail)
64 mc = pull = flag = true;
65
66 if (detail || (msg.find("layer") != std::string::npos)) {
67 if (! _updated) update();
68 }
69 if (detail || (msg.find("hits") != std::string::npos)) {
70 Dump(_links, msg, pre);
71 }
72}
73
74void
75TTrackBase::update(void) const {
76 _cores.removeAll();
77 unsigned n = _links.length();
78 for (unsigned i = 0; i < n; i++) {
79 TMLink * l = _links[i];
80 const TMDCWireHit & h = * l->hit();
81 if (h.state() & WireHitInvalidForFit) continue;
82 if (! (h.state() & WireHitFittingValid)) continue;
83 _cores.append(l);
84 }
85 _updated = true;
86}
87
88double
90 std::cout << "TTrackBase::distance !!! not implemented" << std::endl;
91 return 0.;
92}
93
94int
96 std::cout << "TTrackBase::approach !!! not implemented" << std::endl;
97 return -1;
98}
99
100void
102#ifdef TRKRECO_DEBUG_DETAIL
103 std::cout << " TTrackBase::appendByApproach ... sigma=" << maxSigma << std::endl;
104#endif
105
106 AList<TMLink> unused;
107 unsigned n = list.length();
108 for (unsigned i = 0; i < n; i++) {
109 TMLink & l = * list[i];
110
111 if ((_links.hasMember(l)) || (l.hit()->state() & WireHitUsed))
112 continue;
113
114 //...Calculate closest approach...
115 int err = approach(l);
116 if (err < 0) {
117 unused.append(l);
118 continue;
119 }
120
121 //...Calculate sigma...
122 float distance = (l.positionOnWire() - l.positionOnTrack()).mag();
123 float diff = fabs(distance - l.drift());
124 float sigma = diff / l.dDrift();
125
126 //...For debug...
127#ifdef TRKRECO_DEBUG_DETAIL
128 std::cout << " sigma=" << sigma;
129 std::cout << ",dist=" << distance;
130 std::cout << ",diff=" << diff;
131 std::cout << ",err=" << l.hit()->dDrift() << ",";
132 if (sigma < maxSigma) std::cout << "ok,";
133 else std::cout << "X,";
134 l.dump("mc");
135#endif
136
137 //...Make sigma cut...
138 if (sigma > maxSigma) {
139 unused.append(l);
140 continue;
141 }
142
143 //...OK...
144 _links.append(l);
145 _updated = false;
146 _fitted = false;
147 }
148 list.remove(unused);
149}
150
151void
153 std::cout << "TTrackBase::appendByDistance !!! not implemented" << std::endl;
154 list.removeAll();
155}
156
158TTrackBase::refineMain(double sigma) {
159 AList<TMLink> bad;
160 unsigned n = _links.length();
161 for (unsigned i = 0; i < n; i++){
162// std::cout<<" pull of link = "<<_links[i]->pull()<<std::endl;
163 if (_links[i]->pull() > sigma)
164 bad.append(_links[i]);
165 }
166 return bad;
167}
168
169void
170TTrackBase::refine(AList<TMLink> & list, double sigma) {
171 AList<TMLink> bad = refineMain(sigma);
172#ifdef TRKRECO_DEBUG
173 std::cout << " refine ... sigma=" << sigma << ", # of rejected hits=";
174 std::cout << bad.length() << std::endl;
175#endif
176#ifdef TRKRECO_DEBUG
177 Dump(bad, "sort pull mc", " ");
178#endif
179
180 if (bad.length()) {
181 _links.remove(bad);
182 list.append(bad);
183 _fitted = false;
184 _updated = false;
185 }
186}
187
188void
190 _links.removeAll();
191}
192
193void
194TTrackBase::refine(double sigma) {
195 AList<TMLink> bad = refineMain(sigma);
196// for (unsigned i = 0; i < bad.length(); i++) {
197// const TMDCWireHit * hit = bad[i]->hit();
198// hit->state(hit->state() | WireHitInvalidForFit);
199// }
200
201#ifdef TRKRECO_DEBUG_DETAIL
202 std::cout << " refine ... sigma=" << sigma << std::endl;
203 Dump(bad, "detail sort", " ");
204#endif
205
206 if (bad.length()) {
207 _fitted = false;
208 _updated = false;
209 }
210}
211int
213 AList<TMLink> bad;
214 int jbad=-1;
215 double sigma=0;
216 unsigned n = _links.length();
217 double chi2=0;
218 for (unsigned i = 0; i < n; i++){
219 // if(g_sigmalyr1)g_sigmalyr1->fill(sqrt(_links[i]->pull()),_links[i]->wire()->layerId());
220 chi2+=_links[i]->pull();
221 if (_links[i]->pull() > sigma){
222 jbad=i;
223 sigma = _links[i]->pull();
224 }
225 }
226
227 chi2=chi2/n;
228 //if(sigma>9){bad.append(_links[jbad]);if(g_sigmalyr)g_sigmalyr->fill(sqrt(sigma),_links[jbad]->wire()->layerId());}
229// if(sigma>20.25&&chi2>2.08){bad.append(_links[jbad]);}
230 if(sigma>9){bad.append(_links[jbad]);}
231 if (bad.length()) {
232 _links.remove(bad);
233 _fitted = false;
234 _updated = false;
235 }
236 return bad.length();
237}
238
239unsigned
240TTrackBase::testByApproach(const AList<TMLink> & list, double maxSigma) const {
241#ifdef TRKRECO_DEBUG_DETAIL
242 std::cout << " TTrackBase::testByApproach ... sigma=" << maxSigma << std::endl;
243#endif
244
245 unsigned nOK = 0;
246 unsigned n = list.length();
247 for (unsigned i = 0; i < n; i++) {
248 TMLink & l = * list[i];
249 nOK += testByApproach(l, maxSigma);
250 }
251 return nOK;
252}
253
254unsigned
255TTrackBase::testByApproach(const TMLink & link, double maxSigma) const {
256#ifdef TRKRECO_DEBUG_DETAIL
257 std::cout << " TTrackBase::testByApproach ... sigma=" << maxSigma << std::endl;
258#endif
259 TMLink l = link;
260
261 //...Calculate closest approach...
262 int err = approach(l);
263 if (err < 0) return 0;
264 //...Calculate sigma...
265 float distance = l.distance();
266 float diff = fabs(distance - l.hit()->drift());
267 float sigma = diff / l.hit()->dDrift();
268 l.pull(sigma * sigma);
269
270 //...For debug...
271#ifdef TRKRECO_DEBUG_DETAIL
272 std::cout << " sigma=" << sigma;
273 std::cout << ",dist=" << distance;
274 std::cout << ",diff=" << diff << ",";
275 if (sigma < maxSigma) std::cout << "ok,";
276 else std::cout << "X,";
277 l.dump("mc");
278#endif
279
280 //...Make sigma cut...
281 if (sigma < maxSigma) return 1;
282
283 return 0;
284}
285
286// unsigned
287// TTrackBase::nAxialHits(void) const {
288// unsigned n = _links.length();
289// unsigned a = 0;
290// for (unsigned i = 0; i < n; i++) {
291// if (_links[i]->wire()->axial()) ++a;
292// }
293// return a;
294// }
295
296const AList<TMLink> &
297TTrackBase::links(unsigned mask) const {
298 if (mask == 0) return _links;
299
300 std::cout << "TTrackBase::links !!! mask is not supportted yet" << std::endl;
301 return _links;
302}
303
304unsigned
305TTrackBase::nLinks(unsigned mask) const {
306 unsigned n = _links.length();
307 if (mask == 0) return n;
308 unsigned nn = 0;
309 for (unsigned i = 0; i < n; i++) {
310 const TMDCWireHit & h = * _links[i]->hit();
311 if (h.state() & mask) ++nn;
312 }
313 return nn;
314}
315
316const AList<TMLink> &
317TTrackBase::cores(unsigned mask) const {
318 if (mask)
319 std::cout << "TTrackBase::cores !!! mask is not supported" << std::endl;
320 if (! _updated) update();
321 return _cores;
322}
323
324unsigned
325TTrackBase::nCores(unsigned mask) const {
326 if (mask)
327 std::cout << "TTrackBase::nCores !!! mask is not supported" << std::endl;
328 if (! _updated) update();
329 return _cores.length();
330}
331
332// TMLink *
333// TTrackBase::innerMostLink(unsigned mask) const {
334// if (mask == 0) return InnerMost(_links);
335// unsigned n = _links.length();
336// AList<TMLink> tmp;
337// for (unsigned i = 0; i < n; i++) {
338// const TMDCWireHit & h = * _links[i]->hit();
339// if (h.state() & mask) tmp.append(_links[i]);
340// }
341// return InnerMost(tmp);
342// }
343
344// TMLink *
345// TTrackBase::outerMostLink(unsigned mask) const {
346// if (mask == 0) return OuterMost(_links);
347// unsigned n = _links.length();
348// AList<TMLink> tmp;
349// for (unsigned i = 0; i < n; i++) {
350// const TMDCWireHit & h = * _links[i]->hit();
351// if (h.state() & mask) tmp.append(_links[i]);
352// }
353// return OuterMost(tmp);
354// }
355
356int
358 return _fitter->fit(* this);
359}
360
361void
363 if ((a.hit()->state() & WireHitUsed)) {
364#ifdef TRKRECO_DEBUG_DETAIL
365 std::cout << "TTrackBase::append !!! " << a.wire()->name()
366 << " this is already used by another track!" << std::endl;
367#endif
368 return;
369 }
370 if (_links.hasMember(a)) {
371#ifdef TRKRECO_DEBUG_DETAIL
372 std::cout << "TTrackBase::append !!! " << a.wire()->name()
373 << " this is already included in this track!" << std::endl;
374#endif
375 return;
376 }
377 _links.append(a);
378 _updated = false;
379 _fitted = false;
380 _fittedWithCathode = false; // added by matsu ( 1999/05/24 )
381}
382
383void
385 AList<TMLink> tmp;
386 for (unsigned i = 0; i < a.length(); i++) {
387 if ((_links.hasMember(a[i])) || (a[i]->hit()->state() & WireHitUsed)) {
388#ifdef TRKRECO_DEBUG_DETAIL
389 std::cout << " TTrackBase::append(list) !!! ";
390 std::cout << a[i]->wire()->name();
391 std::cout << " Hey!, this is already used! Don't mess with me.";
392 std::cout << std::endl;
393#endif
394 continue;
395 }
396 else {
397 tmp.append(a[i]);
398 }
399 }
400 _links.append(tmp);
401 _updated = false;
402 _fitted = false;
403 _fittedWithCathode = false; // added by matsu ( 1999/05/24 )
404}
405
406const TTrackHEP * const
407TTrackBase::hep(void) const {
408 unsigned n = _links.length();
409 CAList<TTrackHEP> hepList;
410 CList<unsigned> hepCounter;
411 for (unsigned i = 0; i < n; i++) {
412 const TTrackHEP * hep = _links[i]->hit()->mc()->hep();
413 unsigned nH = hepList.length();
414 bool found = false;
415 for (unsigned j = 0; j < nH; j++) {
416 if (hepList[j] == hep) {
417 found = true;
418 ++(* hepCounter[j]);
419 }
420 }
421
422 if (! found) {
423 hepList.append(hep);
424 unsigned c = 0;
425 hepCounter.append(c);
426 }
427 }
428
429 _nHeps = hepList.length();
430 _hep = 0;
431 unsigned max = 0;
432 for (unsigned i = 0; i < _nHeps; i++) {
433 if ((* hepCounter[i]) > max) {
434 max = (* hepCounter[i]);
435 _hep = hepList[i];
436 }
437 }
438
439 return _hep;
440}
441
442unsigned
443TTrackBase::nHeps(void) const {
444 hep();
445 return _nHeps;
446}
const Int_t n
unsigned state(void) const
returns state.
float dDrift(unsigned) const
returns drift distance error.
float drift(unsigned) const
returns drift distance.
std::string name(void) const
returns name.
virtual int fit(TTrackBase &) const =0
virtual int approach(TMLink &) const
calculates the closest approach to a wire in real space. Results are stored in TMLink....
Definition: TTrackBase.cxx:95
virtual double distance(const TMLink &) const
returns distance to a position of TMLink in TMLink space.
Definition: TTrackBase.cxx:89
virtual int fit(void)
fits itself by a default fitter. Error was happened if return value is not zero.
Definition: TTrackBase.cxx:357
virtual void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition: TTrackBase.cxx:58
virtual void refine(AList< TMLink > &list, double maxSigma)
removes bad points by pull. The bad points are removed from the track, and are returned in 'list'.
Definition: TTrackBase.cxx:170
virtual void removeLinks(void)
Definition: TTrackBase.cxx:189
void appendByDistance(AList< TMLink > &list, double maxDistance)
appends TMLinks by distance. 'list' is an input. Unappended TMLinks will be removed from 'list' when ...
Definition: TTrackBase.cxx:152
unsigned testByApproach(const TMLink &list, double sigma) const
returns # of good hits to be appended.
Definition: TTrackBase.cxx:255
const TTrackMC *const mc(void) const
returns a pointer to TTrackMC.
virtual int DropWorst()
Definition: TTrackBase.cxx:212
unsigned nHeps(void) const
returns # of contributed TTrackHEP tracks.
Definition: TTrackBase.cxx:443
void append(TMLink &)
appends a TMLink.
Definition: TTrackBase.cxx:362
const AList< TMLink > & links(unsigned mask=0) const
returns a list of masked TMLinks assigned to this track. 'mask' will be applied if mask is not 0.
Definition: TTrackBase.cxx:297
const TTrackHEP *const hep(void) const
returns TTrackHEP.
Definition: TTrackBase.cxx:407
unsigned nCores(unsigned mask=0) const
returns # of masked TMLinks for fit. 'mask' will be applied if mask is not 0.
Definition: TTrackBase.cxx:325
void appendByApproach(AList< TMLink > &list, double maxSigma)
appends TMLinks by approach. 'list' is an input. Unappended TMLinks will be removed from 'list' when ...
Definition: TTrackBase.cxx:101
virtual ~TTrackBase()
Destructor.
Definition: TTrackBase.cxx:54
TTrackBase()
Constructor.
Definition: TTrackBase.cxx:40
const AList< TMLink > & cores(unsigned mask=0) const
returns a list of masked TMLinks for fit. 'mask' will be applied if mask is not 0.
Definition: TTrackBase.cxx:317
unsigned nLinks(unsigned mask=0) const
returns # of masked TMLinks assigned to this track object.
Definition: TTrackBase.cxx:305
void update(void) const
update cache.
Definition: TTrackBase.cxx:75
A class to represent a GEN_HEPEVT particle in tracking.