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