BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
TMLink.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TMLink.cxx,v 1.15 2011/10/08 01:56:15 maoh Exp $
3//-----------------------------------------------------------------------------
4// Filename : TMLink.cc
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : [email protected]
8//-----------------------------------------------------------------------------
9// Description : A class to relate TMDCWireHit and TTrack objects.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13#include "TrkReco/TMLink.h"
14#include "TrkReco/TMDCWireHit.h"
16#include "TrkReco/TMDCUtil.h"
17#include "TrkReco/TTrackHEP.h"
18#include "CLHEP/Alist/ConstAList.h"
19
20//zangsl 040518 : move inlined function here
21const TMDCWire * const
22TMLink::wire(void) const {
23 if (_hit) return _hit->wire();
24 return NULL;
25}
26
27const HepPoint3D &
28TMLink::xyPosition(void) const {
29 return _hit->wire()->xyPosition();
30}
31//zangsl 040518 end
32
33/*TMLink::TMLink(TTrack * t, const TMDCWireHit * h, const HepPoint3D & p)
34: _track(t),
35 _hit(h),
36 _dPhi(0),
37 _leftRight(0),
38 _pull(0),
39 _position(p),
40 _link(0),
41 _fit2D(0) {
42// _usecathode(0) {
43 if (h) {
44 _drift[0] = h->drift(0);
45 _drift[1] = h->drift(1);
46 _dDrift[0] = h->dDrift(0);
47 _dDrift[1] = h->dDrift(1);
48 }
49 else {
50 _drift[0] = 0.;
51 _drift[1] = 0.;
52 _dDrift[0] = 0.;
53 _dDrift[1] = 0.;
54 }
55
56 for (unsigned i = 0; i < 6; ++i)
57 _neighbor[i] = NULL;
58 for (unsigned i = 0; i < 4; ++i)
59 _arcZ[i];
60
61 if (h) {
62 _onTrack = _onWire = h->xyPosition();
63 }
64}
65*/
66//for Tsf
67TMLink::TMLink(TTrack * t, const TMDCWireHit * h, const HepPoint3D & p, const HepPoint3D & d, double dr)
68: _track(t),
69 _hit(h),
70 _dPhi(0),
71 _leftRight(0),
72 _pull(0),
73 _position(p),
74 _positionD(d),
75 _link(0),
76 _fit2D(0),
77 _tsfTag(0) {
78 if (h) {
79 _cDrift[0] = dr; //after conformal transformation.
80 _cDrift[1] = dr;
81 _drift[0] = h->drift(0);
82 _drift[1] = h->drift(1);
83 _dDrift[0] = h->dDrift(0);
84 _dDrift[1] = h->dDrift(1);
85 }
86 else {
87 _cDrift[0] = 0.;
88 _cDrift[1] = 0.;
89 _drift[0] = 0.;
90 _drift[1] = 0.;
91 _dDrift[0] = 0.;
92 _dDrift[1] = 0.;
93 }
94
95 for (unsigned i = 0; i < 6; ++i)
96 _neighbor[i] = NULL;
97 for (unsigned i = 0; i < 4; ++i)
98 _arcZ[i];
99
100
101 if (h) {
102 _onTrack = _onWire = h->xyPosition();
103 }
104}
105
107: _track(l._track),
108 _hit(l._hit),
109 _onTrack(l._onTrack),
110 _onWire(l._onWire),
111 _position(l._position),
112 _positionD(l._positionD),
113 _dPhi(l._dPhi),
114 _leftRight(l._leftRight),
115 _pull(l._pull),
116 _link(l._link),
117 _distance(l._distance),
118 // addition by matsu ( 1999/07/05 )
119// _mclust(l._mclust ),
120// _usecathode(l._usecathode ),
121 // end of addition
122 _fit2D(l._fit2D),
123 _tsfTag(l._tsfTag) {
124 _drift[0] = l._drift[0];
125 _drift[1] = l._drift[1];
126 _dDrift[0] = l._dDrift[0];
127 _dDrift[1] = l._dDrift[1];
128 _cDrift[0] = l._cDrift[0];
129 _cDrift[1] = l._cDrift[1];
130 for (unsigned i = 0; i < 6; ++i)
131 _neighbor[i] = l._neighbor[i];
132 for (unsigned i = 0; i < 4; ++i)
133 _arcZ[i] = l._arcZ[i];
134
135}
136
139
140void
141TMLink::dump(const std::string & msg, const std::string & pre) const {
142 std::cout << pre;
143 if (_track) std::cout << "track#=,";
144 if (_hit) {
145 _hit->dump(msg);
146 }
147}
148
149unsigned
150NLayers(const AList<TMLink> & list) {
151 unsigned l0 = 0;
152 unsigned l1 = 0;
153 unsigned n = list.length();
154 for (unsigned i = 0; i < n; i++) {
155 unsigned id = list[i]->wire()->layerId();
156 if (id < 32) l0 |= (1 << id);
157 else l1 |= (1 << (id - 32));
158 }
159
160 unsigned l = 0;
161 for (unsigned i = 0; i < 32; i++) {
162 if (l0 & (1 << i)) ++l;
163 if (l1 & (1 << i)) ++l;
164 }
165 return l;
166}
167
168void
169NHits(const AList<TMLink> & links, unsigned nHits[43]) {
170 for (unsigned i = 0; i < 43; i++) nHits[i] = 0;
171 unsigned nLinks = links.length();
172 for (unsigned i = 0; i < nLinks; i++)
173 ++nHits[links[i]->wire()->layerId()];
174}
175
176void
177NHitsSuperLayer(const AList<TMLink> & links, unsigned nHits[11]) {
178 for (unsigned i = 0; i < 11; i++) nHits[i] = 0;
179 unsigned nLinks = links.length();
180 for (unsigned i = 0; i < nLinks; i++)
181 ++nHits[links[i]->wire()->superLayerId()];
182}
183
184void
185Dump(const CAList<TMLink> & links, const std::string & msg, const std::string & pre) {
186 bool mc = (msg.find("mc") != std::string::npos);
187 bool pull = (msg.find("pull") != std::string::npos);
188 bool flag = (msg.find("flag") != std::string::npos);
189 bool sort = (msg.find("sort") != std::string::npos);
190 bool stereo = (msg.find("stereo") != std::string::npos);
191 bool detail = (msg.find("detail") != std::string::npos);
192 bool pos = (msg.find("position") != std::string::npos);
193 if (detail)
194 mc = pull = flag = sort = true;
195
196 CAList<TMLink> tmp = links;
197 if (sort)
198 tmp.sort(SortByWireId);
199 unsigned n = tmp.length();
200 unsigned nForFit = 0;
201#define MCC_MAX 1000
202 unsigned MCC0[MCC_MAX];
203 unsigned MCC1[MCC_MAX];
204 for (unsigned i = 0; i < MCC_MAX; i++) {
205 MCC0[i] = 0;
206 MCC1[i] = 0;
207 }
208 bool MCCOverFlow = false;
209
210 std::cout << pre;
211 for (unsigned i = 0; i < n; i++) {
212 const TMLink & l = * tmp[i];
213 std::cout << l.wire()->name();
214
215 double a = l.pull();
216 unsigned mcId = 0;
217 if (mc)
218 if (l.hit()->mc())
219 if (l.hit()->mc()->hep())
220 mcId = l.hit()->mc()->hep()->id();
221 if (pull) {
222 std::cout << "[" << a << "]";
223 }
224 if (mc) {
225 std::cout << "(" << mcId << ")";
226 if (mcId < MCC_MAX) {
227 ++MCC0[mcId];
228 if (l.hit()->state() & WireHitFittingValid) {
229 if (! (l.hit()->state() & WireHitInvalidForFit))
230 ++MCC1[mcId];
231 }
232 }
233 else {
234 MCCOverFlow = true;
235 }
236 }
237 if (flag) {
238 if (l.hit()->state() & WireHitFindingValid)
239 std::cout << "o";
240 if (l.hit()->state() & WireHitFittingValid) {
241 std::cout << "+";
242 if (! (l.hit()->state() & WireHitInvalidForFit))
243 ++nForFit;
244 }
245 if (l.hit()->state() & WireHitInvalidForFit)
246 std::cout << "x";
247 }
248 if (stereo) {
249 std::cout << "{" << l.leftRight() << "," << l.zStatus() << "}";
250 }
251 if (pos) {
252 std::cout << ",pos=" << l.position();
253 }
254 std::cout << ",";
255 }
256 std::cout << " " << n << " l(s)";
257 if (flag) std::cout << ", fv " << nForFit << " l(s)";
258 if (mc) {
259 unsigned nMC = 0;
260 std::cout << ", mc";
261 for (unsigned i = 0; i < MCC_MAX; i++) {
262 if (MCC0[i] > 0) {
263 ++nMC;
264 std::cout << i << ":" << MCC0[i] << ",";
265 }
266 }
267 std::cout << " total " << nMC << " contributions";
268 if (flag) {
269 nMC = 0;
270 std::cout << ", fv mc";
271 for (unsigned i = 0; i < MCC_MAX; i++) {
272 if (MCC1[i] > 0) {
273 ++nMC;
274 std::cout << i << ":" << MCC1[i] << ",";
275 }
276 }
277 std::cout << " total " << nMC << " contributions";
278 }
279
280 if (MCCOverFlow)
281 std::cout << "(counter overflow)";
282 }
283 std::cout << std::endl;
284}
285
286void
287Dump(const TMLink & link, const std::string & msg, const std::string & pre) {
288 CAList<TMLink> tmp;
289 tmp.append(link);
290 Dump(tmp, msg, pre);
291}
292
293unsigned
295 unsigned nLinks = links.length();
296 unsigned n = 0;
297 for (unsigned i = 0; i < nLinks; i++)
298 if (links[i]->wire()->stereo())
299 ++n;
300 return n;
301}
302
303unsigned
304NAxialHits(const AList<TMLink> & links) {
305 unsigned nLinks = links.length();
306 unsigned n = 0;
307 for (unsigned i = 0; i < nLinks; i++)
308 if (links[i]->wire()->axial())
309 ++n;
310 return n;
311}
312
314AxialHits(const AList<TMLink> & links) {
316 unsigned n = links.length();
317 for (unsigned i = 0; i < n; i++) {
318 if (links[i]->wire()->axial())
319 a.append(links[i]);
320 }
321 return a;
322}
323
325StereoHits(const AList<TMLink> & links) {
327 unsigned n = links.length();
328 for (unsigned i = 0; i < n; i++) {
329 if (! links[i]->wire()->axial())
330 a.append(links[i]);
331 }
332 return a;
333}
334
335TMLink *
337 unsigned n = a.length();
338 unsigned minId = 9999;
339 TMLink * t = 0;
340 for (unsigned i = 0; i < n; i++) {
341 unsigned id = a[i]->wire()->id();
342 if (id < minId) {
343 minId = id;
344 t = a[i];
345 }
346 }
347 return t;
348}
349
350TMLink *
352 unsigned n = a.length();
353 unsigned maxId = 0;
354 TMLink * t = 0;
355 for (unsigned i = 0; i < n; i++) {
356 unsigned id = a[i]->wire()->id();
357 if (id > maxId) {
358 maxId = id;
359 t = a[i];
360 }
361 }
362 return t;
363}
364
365void
367 AList<TMLink> & cores,
368 AList<TMLink> & nonCores) {
369 unsigned n = input.length();
370 for (unsigned i = 0; i < n; i++) {
371 TMLink & t = * input[i];
372 const TMDCWireHit & h = * t.hit();
373 if (h.state() & WireHitFittingValid)
374 cores.append(t);
375 else
376 nonCores.append(t);
377 }
378}
379
381Cores(const AList<TMLink> & input) {
383 unsigned n = input.length();
384 for (unsigned i = 0; i < n; i++) {
385 TMLink & t = * input[i];
386 const TMDCWireHit & h = * t.hit();
387 if (h.state() & WireHitFittingValid)
388 a.append(t);
389 }
390 return a;
391}
392
393#if defined(__GNUG__)
394int
395SortByWireId(const TMLink ** a, const TMLink ** b) {
396 if ((* a)->wire()->id() > (* b)->wire()->id()) return 1;
397 else if
398 ((* a)->wire()->id() == (* b)->wire()->id()) return 0;
399 else return -1;
400}
401
402int
403SortByX(const TMLink ** a, const TMLink ** b) {
404 if ((* a)->position().x() > (* b)->position().x()) return 1;
405 else if ((* a)->position().x() == (* b)->position().x()) return 0;
406 else return -1;
407}
408
409#else
410extern "C" int
411SortByWireId(const void * av, const void * bv) {
412 const TMLink ** a((const TMLink**)av);
413 const TMLink ** b((const TMLink**)bv);
414 if ((* a)->wire()->id() > (* b)->wire()->id()) return 1;
415 else if
416 ((* a)->wire()->id() == (* b)->wire()->id()) return 0;
417 else return -1;
418}
419
420extern "C" int
421SortByX(const void* av, const void* bv) {
422 const TMLink ** a((const TMLink**)av);
423 const TMLink ** b((const TMLink**)bv);
424 if ((* a)->position().x() > (* b)->position().x()) return 1;
425 else if ((* a)->position().x() == (* b)->position().x()) return 0;
426 else return -1;
427}
428
429#endif
430
431unsigned
432Width(const AList<TMLink> & list) {
433 unsigned n = list.length();
434 if (n < 2) return n;
435
436 const TMDCWire * w = list[0]->wire();
437 unsigned nWires = w->layer()->nWires();
438 unsigned center = w->localId();
439
440#ifdef TRKRECO_DEBUG_DETAIL
441 unsigned sId = w->superLayerId();
442#endif
443
444 unsigned left = 0;
445 unsigned right = 0;
446 for (unsigned i = 1; i < n; i++) {
447 w = list[i]->wire();
448 unsigned id = w->localId();
449
450 unsigned distance0, distance1;
451 if (id > center) {
452 distance0 = id - center;
453 distance1 = nWires - distance0;
454 }
455 else {
456 distance1 = center - id;
457 distance0 = nWires - distance1;
458 }
459
460 if (distance0 < distance1) {
461 if (distance0 > right) right = distance0;
462 }
463 else {
464 if (distance1 > left) left = distance1;
465 }
466
467#ifdef TRKRECO_DEBUG_DETAIL
468 if (w->superLayerId() != sId)
469 std::cout << "::width !!! super layer assumption violation" << std::endl;
470#endif
471 }
472
473 return right + left + 1;
474}
475
477Edges(const AList<TMLink> & list) {
479
480 unsigned n = list.length();
481 if (n < 2) return a;
482 else if (n == 2) return list;
483
484 const TMDCWire * w = list[0]->wire();
485 unsigned nWires = w->layer()->nWires();
486 unsigned center = w->localId();
487
488 unsigned left = 0;
489 unsigned right = 0;
490 TMLink * leftL = list[0];
491 TMLink * rightL = list[0];
492 for (unsigned i = 1; i < n; i++) {
493 w = list[i]->wire();
494 unsigned id = w->localId();
495
496 unsigned distance0, distance1;
497 if (id > center) {
498 distance0 = id - center;
499 distance1 = nWires - distance0;
500 }
501 else {
502 distance1 = center - id;
503 distance0 = nWires - distance1;
504 }
505
506 if (distance0 < distance1) {
507 if (distance0 > right) {
508 right = distance0;
509 rightL = list[i];
510 }
511 }
512 else {
513 if (distance1 > left) {
514 left = distance1;
515 leftL = list[i];
516 }
517 }
518 }
519
520 a.append(leftL);
521 a.append(rightL);
522 return a;
523}
524
526SameLayer(const AList<TMLink> & list, const TMLink & a) {
527 AList<TMLink> same;
528 unsigned id = a.wire()->layerId();
529 unsigned n = list.length();
530 for (unsigned i = 0; i < n; i++) {
531 if (list[i]->wire()->layerId() == id) same.append(list[i]);
532 }
533 return same;
534}
535
537SameSuperLayer(const AList<TMLink> & list, const TMLink & a) {
538 AList<TMLink> same;
539 unsigned id = a.wire()->superLayerId();
540 unsigned n = list.length();
541 for (unsigned i = 0; i < n; i++) {
542 if (list[i]->wire()->superLayerId() == id) same.append(list[i]);
543 }
544 return same;
545}
546
548SameLayer(const AList<TMLink> & list, unsigned id) {
549 AList<TMLink> same;
550 unsigned n = list.length();
551 for (unsigned i = 0; i < n; i++) {
552 if (list[i]->wire()->layerId() == id) same.append(list[i]);
553 }
554 return same;
555}
556
558SameSuperLayer(const AList<TMLink> & list, unsigned id) {
559 AList<TMLink> same;
560 unsigned n = list.length();
561 for (unsigned i = 0; i < n; i++) {
562 if (list[i]->wire()->superLayerId() == id) same.append(list[i]);
563 }
564 return same;
565}
566
568InOut(const AList<TMLink> & list) {
569 AList<TMLink> inners;
570 AList<TMLink> outers;
571 unsigned n = list.length();
572 unsigned innerMostLayer = 999;
573 unsigned outerMostLayer = 0;
574 for (unsigned i = 0; i < n; i++) {
575 unsigned id = list[i]->wire()->layerId();
576 if (id < innerMostLayer) innerMostLayer = id;
577 else if (id > outerMostLayer) outerMostLayer = id;
578 }
579 for (unsigned i = 0; i < n; i++) {
580 unsigned id = list[i]->wire()->layerId();
581 if (id == innerMostLayer) inners.append(list[i]);
582 else if (id == outerMostLayer) outers.append(list[i]);
583 }
584 inners.append(outers);
585 return inners;
586}
587
588unsigned
590 unsigned sl = 0;
591 unsigned n = list.length();
592 for (unsigned i = 0; i < n; i++)
593 sl |= (1 << (list[i]->wire()->superLayerId()));
594 return sl;
595}
596
597unsigned
598SuperLayer(const AList<TMLink> & links, unsigned minN) {
599 unsigned n = links.length();
600 unsigned nHits[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
601 for (unsigned i = 0; i < n; i++)
602 ++nHits[links[i]->wire()->superLayerId()];
603 unsigned sl = 0;
604 for (unsigned i = 0; i < 11; i++)
605 if (nHits[i] >= minN)
606 sl |= (1 << i);
607 return sl;
608}
609
610unsigned
612 unsigned l0 = 0;
613 unsigned n = list.length();
614 for (unsigned i = 0; i < n; i++) {
615 unsigned id = list[i]->wire()->superLayerId();
616 l0 |= (1 << id);
617 }
618
619 unsigned l = 0;
620 for (unsigned i = 0; i < 11; i++) {
621 if (l0 & (1 << i)) ++l;
622 }
623 return l;
624}
625
626unsigned
627NSuperLayers(const AList<TMLink> & links, unsigned minN) {
628 unsigned n = links.length();
629 unsigned nHits[11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
630 for (unsigned i = 0; i < n; i++)
631 ++nHits[links[i]->wire()->superLayerId()];
632 unsigned sl = 0;
633 for (unsigned i = 0; i < 11; i++)
634 if (nHits[i] >= minN)
635 ++sl;
636 return sl;
637}
638
639unsigned
641 unsigned n = links.length();
642//Liuqg, change the following to BES. unsigned nHits[6] = {0, 0, 0, 0, 0, 0};
643 unsigned nHits[5] = {0, 0, 0, 0, 0};
644 for (unsigned i = 0; i < n; i++)
645 if (links[i]->wire()->axial())
646 ++nHits[links[i]->wire()->axialStereoLayerId() / 4];
647 unsigned j = 0;
648 while (nHits[j] == 0) ++j;
649 unsigned nMissing = 0;
650 unsigned nMax = 0;
651 for (unsigned i = j; i < 5; i++) {
652 if (nHits[i] == 0) ++nMissing;
653 else {
654 if (nMax < nMissing) nMax = nMissing;
655 nMissing = 0;
656 }
657 }
658 return nMax;
659}
660
661const TTrackHEP &
662Links2HEP(const AList<TMLink> & links) {
663 const TTrackHEP * best = NULL;
664 const AList<TTrackHEP> & list = TTrackHEP::list();
665 unsigned nHep = list.length();
666
667 if (! nHep) return * best;
668
669 unsigned * N = (unsigned *) malloc(nHep * sizeof(unsigned));
670 for (unsigned i = 0; i < nHep; i++) N[i] = 0;
671
672 for (unsigned i = 0; i < links.length(); i++) {
673 const TMLink & l = * links[i];
674 const TTrackHEP & hep = * l.hit()->mc()->hep();
675 for (unsigned j = 0; j < nHep; j++)
676 if (list[j] == & hep)
677 ++N[j];
678 }
679
680 unsigned nMax = 0;
681 for (unsigned i = 0; i < nHep; i++) {
682 if (N[i] > nMax) {
683 best = list[i];
684 nMax = N[i];
685 }
686 }
687
688 return * best;
689}
690
691
692/*
693double
694TMLink::DriftTime(double _tof,double z) const {
695 double tprop = 0.;
696 double _vprop = (_layer<8) ? Constants::vpropInner : Constants::vpropOuter;
697 if (0 == _layer%2){
698 tprop = (0.5*_zlen + z)/_vprop; //odd
699 }else{
700 tprop = (0.5*_zlen - z)/_vprop; //even
701 }
702 double driftT;
703 driftT = fabs(_rawTime - _T0Walk -1.e9*tof - tprop);
704
705 //std::cout<< "lay "<<_layer<<" cell "<<_wire<<" zhit "<<z<<" tprop "<<tprop << std::endl;
706 return driftT;
707}
708*/
const Int_t n
double w
#define WireHitFindingValid
Definition TMDCWireHit.h:28
#define WireHitFittingValid
Definition TMDCWireHit.h:29
#define WireHitInvalidForFit
Definition TMDCWireHit.h:55
#define NULL
TTree * t
Definition binning.cxx:23
const TTrackHEP *const hep(void) const
returns a pointer to a GEN_HEPEVT.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
unsigned state(void) const
returns state.
float dDrift(unsigned) const
returns drift distance error.
float drift(unsigned) const
returns drift distance.
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
const HepPoint3D & xyPosition(void) const
returns drift time
const TMDCWireHitMC *const mc(void) const
returns a pointer to TMDCWireHitMC.
A class to represent a wire in MDC.
Definition TMDCWire.h:55
unsigned layerId(void) const
returns layer id.
Definition TMDCWire.h:219
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
Definition TMDCWire.h:327
unsigned superLayerId(void) const
returns super layer id.
Definition TMDCWire.h:225
std::string name(void) const
returns name.
Definition TMDCWire.h:412
A class to represent a GEN_HEPEVT particle in tracking.
Definition TTrackHEP.h:37
unsigned id(void) const
returns an id started from 0.
Definition TTrackHEP.h:122
static const AList< TTrackHEP > & list(void)
returns a list of TTrackHEP's.
Definition TTrackHEP.cxx:72
A class to represent a track in tracking.
Definition TTrack.h:129
const double b
Definition slope.cxx:9