Belle II Software development
Link.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9//-----------------------------------------------------------------------------
10// Description : A class to relate TRGCDCWireHit and TRGCDCTrack objects.
11//-----------------------------------------------------------------------------
12
13#define TRG_SHORT_NAMES
14#define TRGCDC_SHORT_NAMES
15
16#include <string>
17#include <cstring>
18#include <algorithm>
19#include "trg/trg/Utilities.h"
20#include "trg/cdc/Wire.h"
21#include "trg/cdc/WireHit.h"
22#include "trg/cdc/WireHitMC.h"
23#include "trg/cdc/TRGCDCTrack.h"
24#include "trg/cdc/TrackMC.h"
25#include "trg/cdc/Segment.h"
26#include "trg/cdc/Link.h"
27
28using namespace std;
29
30namespace Belle2 {
36 bool TRGCDCLink::ms_smallcell(false);
37 bool TRGCDCLink::ms_superb(false);
38 unsigned TRGCDCLink::m_nL = 56;
39 unsigned TRGCDCLink::m_nSL = 9;
40 unsigned TRGCDCLink::m_nSLA = 5;
41 unsigned* TRGCDCLink::m_nHitsSL = 0;
42 vector<TCLink*> TRGCDCLink::m_all;
43
45 const TRGCDCCellHit* h,
47 : m_track(t),
48 m_hit(h),
49 m_position(p),
50 m_dPhi(0),
51 m_leftRight(0),
52 m_pull(0),
53 m_link(0),
54 m_fit2D(0)
55 {
56 if (h) {
57 m_drift[0] = h->drift(0);
58 m_drift[1] = h->drift(1);
59 m_dDrift[0] = h->dDrift(0);
60 m_dDrift[1] = h->dDrift(1);
61 } else {
62 m_drift[0] = 0.;
63 m_drift[1] = 0.;
64 m_dDrift[0] = 0.;
65 m_dDrift[1] = 0.;
66 }
67
68 for (unsigned i = 0; i < 7; ++i)
69 m_neighbor[i] = NULL;
70
71 if (h) {
72 m_onTrack = m_onWire = h->xyPosition();
73 }
74 }
75
77 : m_track(l.m_track),
78 m_hit(l.m_hit),
79 m_onTrack(l.m_onTrack),
80 m_onWire(l.m_onWire),
81 m_position(l.m_position),
82 m_dPhi(l.m_dPhi),
83 m_leftRight(l.m_leftRight),
84 m_zStatus(l.m_zStatus),
85 m_zPair(l.m_zPair),
86 m_pull(l.m_pull),
87 m_link(l.m_link),
88 m_fit2D(l.m_fit2D)
89 {
90 m_drift[0] = l.m_drift[0];
91 m_drift[1] = l.m_drift[1];
92 m_dDrift[0] = l.m_dDrift[0];
93 m_dDrift[1] = l.m_dDrift[1];
94 for (unsigned i = 0; i < 7; ++i)
95 m_neighbor[i] = l.m_neighbor[i];
96 for (unsigned i = 0; i < 4; ++i)
97 m_arcZ[i] = l.m_arcZ[i];
98 }
99
101 {
102 }
103
104 unsigned
105 TRGCDCLink::nLayers(const vector<TRGCDCLink*>& list)
106 {
107 unsigned l0 = 0;
108 unsigned l1 = 0;
109 unsigned n = list.size();
110 for (unsigned i = 0; i < n; i++) {
111 unsigned id = list[i]->cell()->layerId();
112 if (id < 32) l0 |= (1u << id);
113 else l1 |= (1 << (id - 32));
114 }
115
116 unsigned l = 0;
117 for (unsigned i = 0; i < 32; i++) {
118 if (l0 & (1u << i)) ++l;
119 if (l1 & (1u << i)) ++l;
120 }
121 return l;
122 }
123
124 void
125 TRGCDCLink::nHits(const vector<TRGCDCLink*>& links, unsigned* nHits)
126 {
127 for (unsigned i = 0; i < m_nL; i++)
128 nHits[i] = 0;
129 unsigned nLinks = links.size();
130 for (unsigned i = 0; i < nLinks; i++)
131 ++nHits[links[i]->cell()->layerId()];
132 }
133
134 void
135 TRGCDCLink::nHitsSuperLayer(const vector<TRGCDCLink*>& links, unsigned* nHits)
136 {
137 const unsigned nLinks = links.size();
138 for (unsigned i = 0; i < nLinks; i++)
139 ++nHits[links[i]->cell()->superLayerId()];
140 }
141
142 void
143 TRGCDCLink::dump_base(const string& msg, const string& pre) const
144 {
145
146 //...Basic options...
147// bool track = (msg.find("track") != string::npos);
148// bool mc = (msg.find("mc") != string::npos);
149 bool pull = (msg.find("pull") != string::npos);
150 bool flag = (msg.find("flag") != string::npos);
151 bool stereo = (msg.find("stereo") != string::npos);
152 bool pos = (msg.find("position") != string::npos);
153
154 //...Strong options...
155 bool breif = (msg.find("breif") != string::npos);
156 bool detail = (msg.find("detail") != string::npos);
157 if (detail)
158// track = mc = pull = flag = stereo = pos = true;
159 pull = flag = stereo = pos = true;
160 if (breif)
161 pull = flag = true;
162
163 //...Output...
164 cout << pre;
165 if (m_hit) {
166 cout << cell()->name();
167 } else {
168 cout << "No hit linked";
169 }
170// if (mc) {
171// if (_hit) {
172// if (_hit->mc()) {
173// if (_hit->mc()->hep())
174// cout << "(mc" << _hit->mc()->hep()->id() << ")";
175// else
176// cout << "(mc?)";
177// }
178// else {
179// cout << "(mc?)";
180// }
181// }
182// }
183 if (pull)
184 cout << "[pul=" << this->pull() << "]";
185 if (flag) {
186 if (m_hit) {
187 if (m_hit->state() & CellHitFindingValid)
188 cout << "o";
189 if (m_hit->state() & CellHitFittingValid)
190 cout << "+";
191 if (m_hit->state() & CellHitInvalidForFit)
192 cout << "x";
193 }
194 }
195 if (stereo) {
196 cout << "{" << leftRight() << "," << m_zStatus << "}";
197 }
198 if (pos) {
199 cout << ",pos=" << position();
200 cout << ",drift=" << drift(0) << "," << drift(1);
201 }
202 }
203
204 void
205 TRGCDCLink::dump(const string& msg, const string& pre) const
206 {
207 dump_base(msg, pre);
208 cout << endl;
209 }
210
211 void
212 TRGCDCLink::dump(const vector<TRGCDCLink*>& links,
213 const string& msg,
214 const string& pre)
215 {
216 vector<const TRGCDCLink*> clinks;
217 for (unsigned i = 0; i < links.size(); i++)
218 clinks.push_back(links[i]);
219 TRGCDCLink::dump(clinks, msg, pre);
220 }
221
222 void
223 TRGCDCLink::dump(const vector<const TRGCDCLink*>& links,
224 const string& msg,
225 const string& pre)
226 {
227
228 //...Basic options...
229 bool mc = (msg.find("mc") != string::npos);
230 bool sort = (msg.find("sort") != string::npos);
231 bool flag = (msg.find("flag") != string::npos);
232
233 //...Strong options...
234 bool detail = (msg.find("detail") != string::npos);
235 if (detail)
236 mc = flag = true;
237
238 vector<const TRGCDCLink*> tmp = links;
239 if (sort)
240 std::sort(tmp.begin(), tmp.end(), TRGCDCLink::sortById);
241// sort(tmp.begin(), tmp.end(), TRGCDCLink::sortById);
242 unsigned n = tmp.size();
243 unsigned nForFit = 0;
244#define MCC_MAX 1000
245 unsigned MCC0[MCC_MAX];
246 unsigned MCC1[MCC_MAX];
247 memset((char*) MCC0, 0, sizeof(unsigned) * MCC_MAX);
248 memset((char*) MCC1, 0, sizeof(unsigned) * MCC_MAX);
249 bool MCCOverFlow = false;
250
251 cout << pre;
252 for (unsigned i = 0; i < n; i++) {
253 const TRGCDCLink& l = * tmp[i];
254
255// if (mc) {
256// unsigned mcId = 999;
257// if (l.hit()) {
258// if (l.hit()->mc())
259// if (l.hit()->mc()->hep())
260// mcId = l.hit()->mc()->hep()->id();
261// if (mcId < MCC_MAX) {
262// ++MCC0[mcId];
263// if (l.hit()->state() & WireHitFittingValid) {
264// if (! (l.hit()->state() & WireHitInvalidForFit))
265// ++MCC1[mcId];
266// }
267// }
268// else {
269// MCCOverFlow = true;
270// }
271// }
272// }
273 if (flag) {
274 if (l.hit()) {
275 if (l.hit()->state() & CellHitFittingValid) {
276 if (!(l.hit()->state() & CellHitInvalidForFit))
277 ++nForFit;
278 }
279 }
280 }
281 if (i)
282 cout << ",";
283 l.dump_base(msg);
284 }
285 if (n)
286 cout << ",Total " << n << " links";
287 else
288 cout << "no link";
289 if (flag) cout << ",fv " << nForFit << " l(s)";
290 if (mc) {
291 unsigned nMC = 0;
292 cout << ", mc";
293 for (unsigned i = 0; i < MCC_MAX; i++) {
294 if (MCC0[i] > 0) {
295 ++nMC;
296 cout << i << ":" << MCC0[i] << ",";
297 }
298 }
299 cout << "total " << nMC << " mc contributions";
300 if (flag) {
301 nMC = 0;
302 cout << ", fv mc";
303 for (unsigned i = 0; i < MCC_MAX; i++) {
304 if (MCC1[i] > 0) {
305 ++nMC;
306 cout << i << ":" << MCC1[i] << ",";
307 }
308 }
309 cout << " total " << nMC << " mc fit valid contribution(s)";
310 }
311
312 // cppcheck-suppress knownConditionTrueFalse
313 if (MCCOverFlow)
314 cout << "(counter overflow)";
315 }
316 cout << endl;
317
318 //...Parent...
319 if (mc) {
320 vector<const Belle2::TRGCDCTrackMC*> list = Belle2::TRGCDCTrackMC::list();
321 if (! list.size()) return;
322 cout << pre;
323//cnv unsigned nMC = 0;
324 for (unsigned i = 0; i < MCC_MAX; i++) {
325 if (MCC0[i] > 0) {
326 const Belle2::TRGCDCTrackMC* h = list[i];
327// cout << ", mc" << i << "(" << h->pType() << ")";
328 cout << ", mc" << i << "(";
329 if (h)
330 cout << h->pType() << ")";
331 else
332 cout << "?)";
333 while (h) {
334 const Belle2::TRGCDCTrackMC* m = h->mother();
335 if (m) {
336 cout << "<-mc" << m->id();
337 h = m;
338 } else {
339 break;
340 }
341 }
342 }
343 }
344 if (MCCOverFlow)
345 cout << "(counter overflow)";
346 cout << endl;
347 }
348 }
349
350 void
352 const string& msg,
353 const string& pre)
354 {
355 vector<const TRGCDCLink*> tmp;
356 tmp.push_back(& link);
357 dump(tmp, msg, pre);
358 }
359
360 unsigned
361 TRGCDCLink::nStereoHits(const vector<TRGCDCLink*>& links)
362 {
363 unsigned nLinks = links.size();
364 unsigned n = 0;
365 for (unsigned i = 0; i < nLinks; i++)
366 if (links[i]->cell()->stereo())
367 ++n;
368 return n;
369 }
370
371 unsigned
372 TRGCDCLink::nAxialHits(const vector<TRGCDCLink*>& links)
373 {
374 unsigned nLinks = links.size();
375 unsigned n = 0;
376 for (unsigned i = 0; i < nLinks; i++)
377 if (links[i]->cell()->axial())
378 ++n;
379 return n;
380 }
381
382 vector<TRGCDCLink*>
383 TRGCDCLink::axialHits(const vector<TRGCDCLink*>& links)
384 {
385 vector<TRGCDCLink*> a;
386 unsigned n = links.size();
387 for (unsigned i = 0; i < n; i++) {
388 if (links[i]->cell()->axial())
389 a.push_back(links[i]);
390 }
391 return a;
392 }
393
394 vector<TRGCDCLink*>
395 TRGCDCLink::stereoHits(const vector<TRGCDCLink*>& links)
396 {
397 vector<TRGCDCLink*> a;
398 unsigned n = links.size();
399 for (unsigned i = 0; i < n; i++) {
400 if (! links[i]->cell()->axial())
401 a.push_back(links[i]);
402 }
403 return a;
404 }
405
407 TRGCDCLink::innerMost(const vector<TRGCDCLink*>& a)
408 {
409 unsigned n = a.size();
410 unsigned minId = 19999;
411 TRGCDCLink* t = 0;
412 for (unsigned i = 0; i < n; i++) {
413 unsigned id = a[i]->cell()->id();
414 if (id < minId) {
415 minId = id;
416 t = a[i];
417 }
418 }
419 return t;
420 }
421
423 TRGCDCLink::outerMost(const vector<TRGCDCLink*>& a)
424 {
425 unsigned n = a.size();
426 unsigned maxId = 0;
427 TRGCDCLink* t = 0;
428 for (unsigned i = 0; i < n; i++) {
429 unsigned id = a[i]->cell()->id();
430 if (id >= maxId) {
431 maxId = id;
432 t = a[i];
433 }
434 }
435 return t;
436 }
437
438 void
439 TRGCDCLink::separateCores(const vector<TRGCDCLink*>& input,
440 vector<TRGCDCLink*>& cores,
441 vector<TRGCDCLink*>& nonCores)
442 {
443 unsigned n = input.size();
444 for (unsigned i = 0; i < n; i++) {
445 TRGCDCLink& t = * input[i];
446 const Belle2::TCCHit& h = * t.hit();
447 if (h.state() & CellHitFittingValid)
448 cores.push_back(& t);
449 else
450 nonCores.push_back(& t);
451 }
452 }
453
454 vector<TRGCDCLink*>
455 TRGCDCLink::cores(const vector<TRGCDCLink*>& input)
456 {
457 vector<TRGCDCLink*> a;
458 unsigned n = input.size();
459 for (unsigned i = 0; i < n; i++) {
460 TRGCDCLink& t = * input[i];
461 const Belle2::TCCHit& h = * t.hit();
462 if (h.state() & CellHitFittingValid)
463 a.push_back(& t);
464 }
465 return a;
466 }
467
468 bool
470 {
471 return a->cell()->id() < b->cell()->id();
472 }
473
474 int
476 {
477 return a->position().x() < b->position().x();
478 }
479
480 unsigned
481 TRGCDCLink::width(const vector<TRGCDCLink*>& list)
482 {
483 const unsigned n = list.size();
484 if (n < 2) return n;
485
486 const TCCell* const w0 = list[0]->cell();
487//cnv const unsigned sId = w0->superLayerId();
488 unsigned nWires = w0->layer().nCells();
489 unsigned center = w0->localId();
490
491 if (ms_smallcell && w0->layerId() < 3) {
492 nWires /= 2;
493 center /= 2;
494 }
495
496 unsigned left = 0;
497 unsigned right = 0;
498 for (unsigned i = 1; i < n; i++) {
499 const TCCell* const w = list[i]->cell();
500 unsigned id = w->localId();
501
502 if (ms_smallcell && w->layerId() < 3)
503 id /= 2;
504
505 unsigned distance0, distance1;
506 if (id > center) {
507 distance0 = id - center;
508 distance1 = nWires - distance0;
509 } else {
510 distance1 = center - id;
511 distance0 = nWires - distance1;
512 }
513
514 if (distance0 < distance1) {
515 if (distance0 > right) right = distance0;
516 } else {
517 if (distance1 > left) left = distance1;
518 }
519 }
520
521 return right + left + 1;
522 }
523
524 vector<TRGCDCLink*>
525 TRGCDCLink::edges(const vector<TRGCDCLink*>& list)
526 {
527 vector<TRGCDCLink*> a;
528
529 unsigned n = list.size();
530 if (n < 2) return a;
531 else if (n == 2) return list;
532
533 const TCCell* w = list[0]->cell();
534 unsigned nWires = w->layer().nCells();
535 unsigned center = w->localId();
536
537 unsigned left = 0;
538 unsigned right = 0;
539 TRGCDCLink* leftL = list[0];
540 TRGCDCLink* rightL = list[0];
541 for (unsigned i = 1; i < n; i++) {
542 w = list[i]->cell();
543 unsigned id = w->localId();
544
545 unsigned distance0, distance1;
546 if (id > center) {
547 distance0 = id - center;
548 distance1 = nWires - distance0;
549 } else {
550 distance1 = center - id;
551 distance0 = nWires - distance1;
552 }
553
554 if (distance0 < distance1) {
555 if (distance0 > right) {
556 right = distance0;
557 rightL = list[i];
558 }
559 } else {
560 if (distance1 > left) {
561 left = distance1;
562 leftL = list[i];
563 }
564 }
565 }
566
567 a.push_back(leftL);
568 a.push_back(rightL);
569 return a;
570 }
571
572 vector<TRGCDCLink*>
573 TRGCDCLink::sameLayer(const vector<TRGCDCLink*>& list, const TRGCDCLink& a)
574 {
575 vector<TRGCDCLink*> same;
576 unsigned id = a.cell()->layerId();
577 unsigned n = list.size();
578 for (unsigned i = 0; i < n; i++) {
579 if (list[i]->cell()->layerId() == id) same.push_back(list[i]);
580 }
581 return same;
582 }
583
584 vector<TRGCDCLink*>
585 TRGCDCLink::sameSuperLayer(const vector<TRGCDCLink*>& list, const TRGCDCLink& a)
586 {
587 vector<TRGCDCLink*> same;
588 unsigned id = a.cell()->superLayerId();
589 unsigned n = list.size();
590 for (unsigned i = 0; i < n; i++) {
591 if (list[i]->cell()->superLayerId() == id) same.push_back(list[i]);
592 }
593 return same;
594 }
595
596 vector<TRGCDCLink*>
597 TRGCDCLink::sameLayer(const vector<TRGCDCLink*>& list, unsigned id)
598 {
599 vector<TRGCDCLink*> same;
600 unsigned n = list.size();
601 for (unsigned i = 0; i < n; i++) {
602 if (list[i]->cell()->layerId() == id) same.push_back(list[i]);
603 }
604 return same;
605 }
606
607 vector<TRGCDCLink*>
608 TRGCDCLink::sameSuperLayer(const vector<TRGCDCLink*>& list, unsigned id)
609 {
610 vector<TRGCDCLink*> same;
611 unsigned n = list.size();
612 for (unsigned i = 0; i < n; i++) {
613 if (list[i]->cell()->superLayerId() == id) same.push_back(list[i]);
614 }
615 return same;
616 }
617
618 vector<TRGCDCLink*>
619 TRGCDCLink::inOut(const vector<TRGCDCLink*>& list)
620 {
621 vector<TRGCDCLink*> inners;
622 vector<TRGCDCLink*> outers;
623 unsigned n = list.size();
624 unsigned innerMostLayer = 999;
625 unsigned outerMostLayer = 0;
626 for (unsigned i = 0; i < n; i++) {
627 unsigned id = list[i]->cell()->layerId();
628 if (id < innerMostLayer) innerMostLayer = id;
629 else if (id > outerMostLayer) outerMostLayer = id;
630 }
631 for (unsigned i = 0; i < n; i++) {
632 unsigned id = list[i]->cell()->layerId();
633 if (id == innerMostLayer) inners.push_back(list[i]);
634 else if (id == outerMostLayer) outers.push_back(list[i]);
635 }
636// inners.push_back(outers);
637 inners.insert(inners.end(), outers.begin(), outers.end());
638 return inners;
639 }
640
641 unsigned
642 TRGCDCLink::superLayer(const vector<TRGCDCLink*>& list)
643 {
644 unsigned sl = 0;
645 unsigned n = list.size();
646 for (unsigned i = 0; i < n; i++)
647 sl |= (1 << (list[i]->cell()->superLayerId()));
648 return sl;
649 }
650
651 unsigned
652 TRGCDCLink::superLayer(const vector<TRGCDCLink*>& links, unsigned minN)
653 {
655 unsigned n = links.size();
656 for (unsigned i = 0; i < n; i++)
657 ++m_nHitsSL[links[i]->cell()->superLayerId()];
658 unsigned sl = 0;
659 for (unsigned i = 0; i < m_nSL; i++)
660 if (m_nHitsSL[i] >= minN)
661 sl |= (1 << i);
662 return sl;
663 }
664
665 unsigned
666 TRGCDCLink::nSuperLayers(const vector<TRGCDCLink*>& list)
667 {
668 unsigned l0 = 0;
669 unsigned n = list.size();
670 for (unsigned i = 0; i < n; i++) {
671 unsigned id = list[i]->cell()->superLayerId();
672 l0 |= (1 << id);
673 }
674
675 unsigned l = 0;
676 for (unsigned i = 0; i < m_nSL; i++) {
677 if (l0 & (1 << i)) ++l;
678 }
679 return l;
680 }
681
682 unsigned
683 TRGCDCLink::nSuperLayers(const vector<TRGCDCLink*>& links, unsigned minN)
684 {
686 unsigned n = links.size();
687 for (unsigned i = 0; i < n; i++)
688 ++m_nHitsSL[links[i]->cell()->superLayerId()];
689 unsigned sl = 0;
690 for (unsigned i = 0; i < m_nSL; i++)
691 if (m_nHitsSL[i] >= minN)
692 ++sl;
693 return sl;
694 }
695
696 unsigned
697 TRGCDCLink::nMissingAxialSuperLayers(const vector<TRGCDCLink*>& links)
698 {
700 const unsigned n = links.size();
701// unsigned nHits[6] = {0, 0, 0, 0, 0, 0};
702 for (unsigned i = 0; i < n; i++)
703 if (links[i]->cell()->axial())
704 ++m_nHitsSL[links[i]->cell()->axialStereoSuperLayerId()];
705// ++nHits[links[i]->cell()->superLayerId() / 2];
706 unsigned j = 0;
707 while (m_nHitsSL[j] == 0) ++j;
708 unsigned nMissing = 0;
709 unsigned nMax = 0;
710 for (unsigned i = j; i < m_nSLA; i++) {
711 if (+m_nHitsSL[i] == 0) ++nMissing;
712 else {
713 if (nMax < nMissing) nMax = nMissing;
714 nMissing = 0;
715 }
716 }
717 return nMax;
718 }
719
721 TRGCDCLink::links2HEP(const vector<TRGCDCLink*>&)
722 {
724 const vector<const Belle2::TRGCDCTrackMC*> list =
726 unsigned nHep = list.size();
727
728 if (! nHep) return * best;
729
730 unsigned* N;
731 if (NULL == (N = (unsigned*) malloc(nHep * sizeof(unsigned)))) {
732// perror("$Id: TRGCDCLink.cc 11153 2010-04-28 03:36:53Z yiwasaki $:N:malloc");
733 exit(1);
734 }
735 for (unsigned i = 0; i < nHep; i++) N[i] = 0;
736
737// for (unsigned i = 0; i < (unsigned) links.size(); i++) {
738// const TRGCDCLink & l = * links[i];
739// const Belle2::TRGCDCTrackMC & hep = * l.hit()->mc()->hep();
740// for (unsigned j = 0; j < nHep; j++)
741// if (list[j] == & hep)
742// ++N[j];
743// }
744
745 unsigned nMax = 0;
746 for (unsigned i = 0; i < nHep; i++) {
747 if (N[i] > nMax) {
748 best = list[i];
749 nMax = N[i];
750 }
751 }
752
753 free(N);
754
755 return * best;
756 }
757
758 void
759 TRGCDCLink::nHitsSuperLayer(const vector<TRGCDCLink*>& links, vector<TRGCDCLink*>* list)
760 {
761 const unsigned nLinks = links.size();
762 for (unsigned i = 0; i < nLinks; i++)
763 list[links[i]->cell()->superLayerId()].push_back(links[i]);
764 }
765
766 string
767 TRGCDCLink::layerUsage(const vector<TRGCDCLink*>& links)
768 {
769// unsigned n[11];
770 static unsigned* n = new unsigned[Belle2::TRGCDC::getTRGCDC()->nSuperLayers()];
771 for (unsigned i = 0; i < m_nSL; i++) {
772 n[i] = 0;
773 }
774 nHitsSuperLayer(links, n);
775 string nh = "";
776 for (unsigned i = 0; i < m_nSL; i++) {
777 nh += TRGUtil::itostring(n[i]);
778 if (i % 2) nh += ",";
779 else if (i < 10) nh += "-";
780 }
781 return nh;
782 }
783
784 void
785 TRGCDCLink::remove(vector<TRGCDCLink*>& list,
786 const vector<TRGCDCLink*>& links)
787 {
788 const unsigned n = list.size();
789 const unsigned m = links.size();
790 // vector<TRGCDCLink *> toBeRemoved;
791
792 for (unsigned i = 0; i < n; i++) {
793 for (unsigned j = 0; j < m; j++) {
794 if (list[i]->cell()->id() == links[j]->cell()->id())
795// toBeRemoved.push_back(list[i]);
796
797 cout << "TCLink::remove !!! not implemented yet" << endl;
798 }
799 }
800
801// list.remove(toBeRemoved);
802 }
803
804 void
806 {
807 static bool first = true;
808 if (first) {
810 m_nL = cdc.nLayers();
811 m_nSL = cdc.nSuperLayers();
812 m_nSLA = cdc.nAxialSuperLayers();
813 m_nHitsSL = new unsigned[m_nSL];
814 first = false;
815 }
816 }
817
818 void
819 TRGCDCLink::separate(const vector<TRGCDCLink*>& links,
820 unsigned nLayers,
821 vector<TRGCDCLink*>* layers)
822 {
823 for (unsigned i = 0; i < links.size(); i++) {
824 const TCCell* c = links[i]->cell();
825 if (c) {
826 unsigned lid = c->layer().id();
827 if (lid < nLayers)
828 layers[lid].push_back(links[i]);
829 }
830 }
831 }
832
833 const TRGCDCWire*
835 {
836 if (m_hit)
837 return dynamic_cast<const TRGCDCWire*>(& m_hit->cell());
838 return 0;
839 }
840
841// inline
842// const TRGCDCSegment *
843// TRGCDCLink::segment(void) const {
844// if (_hit)
845// return dynamic_cast<const TRGCDCSegment *>(& _hit->cell());
846// return 0;
847// }
848
849 void
851 {
852 while (m_all.size())
853 delete m_all.back();
854 }
855
856 void*
857 TRGCDCLink::operator new (size_t size)
858 {
859 void* p = malloc(size);
860 m_all.push_back(static_cast<TRGCDCLink*>(p));
861
862// cout << ">---------------------" << endl;
863// for (unsigned i = 0; i < _all.size(); i++)
864// cout << "> " << i << " " << _all[i] << endl;
865
866 return p;
867 }
868
869 void
870 TRGCDCLink::operator delete (void* t)
871 {
872 for (vector<TRGCDCLink*>::iterator it = m_all.begin();
873 it != m_all.end();
874 ++it) {
875 if ((* it) == static_cast<TRGCDCLink*>(t)) {
876 m_all.erase(it);
877 break;
878 }
879 }
880 free(t);
881
882// cout << "<---------------------" << endl;
883// cout << "==> " << t << " erased" << endl;
884// for (unsigned i = 0; i < _all.size(); i++)
885// cout << "< " << i << " " << _all[i] << endl;
886 }
887
889} // namespace Belle
A class to represent a wire hit in CDC.
Definition: CellHit.h:74
virtual std::string name(void) const =0
returns name.
A class to represent a GEN_HEPEVT particle in tracking.
Definition: TrackMC.h:32
A class to represent a reconstructed charged track in TRGCDC.
Definition: TRGCDCTrack.h:38
A class to represent a wire in CDC.
Definition: Wire.h:56
The instance of TRGCDC is a singleton.
Definition: TRGCDC.h:69
const TRGCDCWire * wire(void) const
returns a pointer to a wire.
Definition: Link.cc:834
float drift(void) const
returns drift distance.
Definition: Link.h:663
static std::vector< TRGCDCLink * > sameLayer(const std::vector< TRGCDCLink * > &list, const TRGCDCLink &a)
returns links which are in the same layer as 'a' or 'id'.
Definition: Link.cc:573
static const TRGCDCTrackMC & links2HEP(const std::vector< TRGCDCLink * > &links)
returns TRGCDCTrackMC
Definition: Link.cc:721
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:192
static unsigned m_nSLA
...Buffers...
Definition: Link.h:402
virtual const TRGCDCCell & cell(void) const
returns a pointer to a TRGCDCWire.
Definition: CellHit.h:252
virtual ~TRGCDCLink()
Destructor.
Definition: Link.cc:100
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition: Link.cc:205
const TRGCDCCell * cell(void) const
returns a pointer to a cell.
Definition: Link.h:684
static std::vector< TRGCDCLink * > inOut(const std::vector< TRGCDCLink * > &)
returns links which are in the inner most and outer most layer.
Definition: Link.cc:619
static std::vector< TRGCDCLink * > edges(const std::vector< TRGCDCLink * > &)
returns links which are edges.
Definition: Link.cc:525
TRGCDCLink(TRGCDCTrack *track=0, const TRGCDCCellHit *hit=0, const HepGeom::Point3D< double > &position=Point3D())
Constructor.
Definition: Link.cc:44
static TRGCDCLink * outerMost(const std::vector< TRGCDCLink * > &links)
returns the outer-most link.
Definition: Link.cc:423
const HepGeom::Point3D< double > & position(void) const
returns position.
Definition: Link.h:551
unsigned layerId(void) const
returns layer id.
Definition: Cell.h:214
static std::vector< TRGCDCLink * > m_all
Keeps all TRGCDCLinks created by new().
Definition: Link.h:348
static unsigned width(const std::vector< TRGCDCLink * > &)
returns width(wire cell unit) of given std::vector<TRGCDCLink *>.
Definition: Link.cc:481
static TRGCDCLink * innerMost(const std::vector< TRGCDCLink * > &links)
returns the inner-most link.
Definition: Link.cc:407
static std::vector< TRGCDCLink * > sameSuperLayer(const std::vector< TRGCDCLink * > &list, const TRGCDCLink &a)
returns links which are in the same super layer as 'a' or 'id'.
Definition: Link.cc:585
static unsigned superLayer(const std::vector< TRGCDCLink * > &list)
returns super layer pattern.
Definition: Link.cc:642
unsigned superLayerId(void) const
returns super layer id.
Definition: Cell.h:221
static void clearBufferSL(void)
clear buffers
Definition: Link.h:677
const TRGCDCCellHit * hit(void) const
returns a pointer to a hit.
Definition: Link.h:420
static int sortByX(const TRGCDCLink *a, const TRGCDCLink *b)
sorts by X position.
Definition: Link.cc:475
static void separateCores(const std::vector< TRGCDCLink * > &input, std::vector< TRGCDCLink * > &cores, std::vector< TRGCDCLink * > &nonCores)
separate cores and non-cores.
Definition: Link.cc:439
static bool sortById(const TRGCDCLink *a, const TRGCDCLink *b)
sorts by ID.
Definition: Link.cc:469
static unsigned m_nSL
...Buffers...
Definition: Link.h:400
static TRGCDCTrackMC * _undefined
returns a pointer to gen_hepevt.
Definition: TrackMC.h:88
static unsigned nMissingAxialSuperLayers(const std::vector< TRGCDCLink * > &links)
returns # of missing axial super layers.
Definition: Link.cc:697
static void removeAll(void)
destructs all TRGCDCLink objects. (Called by TRGCDC)
Definition: Link.cc:850
TRGCDCLink * link(void) const
returns a pointer to a TRGCDCLink.
Definition: Link.h:595
unsigned nSuperLayers(void) const
returns # of super layers.
Definition: TRGCDC.h:870
static void remove(std::vector< TRGCDCLink * > &list, const std::vector< TRGCDCLink * > &links)
removes links from list if wire is same
Definition: Link.cc:785
static bool ms_superb
ms_superb
Definition: Link.h:395
static unsigned nSuperLayers(const std::vector< TRGCDCLink * > &links)
returns # of layers.
Definition: Link.cc:666
static void nHits(const std::vector< TRGCDCLink * > &links, unsigned *nHits)
returns # of hits per layer.
Definition: Link.cc:125
static std::vector< TRGCDCLink * > stereoHits(const std::vector< TRGCDCLink * > &links)
returns stereo hits.
Definition: Link.cc:395
double pull(void) const
returns pull.
Definition: Link.h:461
static std::vector< TRGCDCLink * > axialHits(const std::vector< TRGCDCLink * > &links)
returns axial hits.
Definition: Link.cc:383
static unsigned * m_nHitsSL
...Buffers...
Definition: Link.h:404
void dump_base(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition: Link.cc:143
static unsigned m_nL
...Buffers...
Definition: Link.h:398
static std::string layerUsage(const std::vector< TRGCDCLink * > &links)
usage of each layer
Definition: Link.cc:767
static unsigned nLayers(const std::vector< TRGCDCLink * > &links)
returns # of layers.
Definition: Link.cc:105
static bool ms_smallcell
ms_smallcell
Definition: Link.h:393
static std::vector< TRGCDCLink * > cores(const std::vector< TRGCDCLink * > &input)
separate cores and non-cores.
Definition: Link.cc:455
static void initializeBuffers(void)
initialize the Buffers
Definition: Link.cc:805
static unsigned nAxialHits(const std::vector< TRGCDCLink * > &links)
returns # of axial hits.
Definition: Link.cc:372
unsigned leftRight(void) const
returns left-right. 0:left, 1:right, 2:wire
Definition: Link.h:523
unsigned state(void) const
returns state.
Definition: CellHit.h:259
static unsigned nStereoHits(const std::vector< TRGCDCLink * > &links)
returns # of stereo hits.
Definition: Link.cc:361
static void nHitsSuperLayer(const std::vector< TRGCDCLink * > &links, unsigned *nHits)
returns # of hits per super layer.
Definition: Link.cc:135
static void separate(const std::vector< TRGCDCLink * > &links, unsigned nLayers, std::vector< TRGCDCLink * > *layers)
separates into layers.
Definition: Link.cc:819
static std::vector< const TRGCDCTrackMC * > list(void)
returns a list of TRGCDCTrackMC's.
Definition: TrackMC.cc:94
Abstract base class for different kinds of events.
STL namespace.