Belle II Software  release-06-02-00
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 
28 using namespace std;
29 
30 namespace 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 
44  TRGCDCLink::TRGCDCLink(TCTrack* t,
45  const Belle2::TCCHit* h,
46  const HepGeom::Point3D<double>& p)
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 
76  TRGCDCLink::TRGCDCLink(const TRGCDCLink& l)
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  // cppcheck-suppress knownConditionTrueFalse
347  if (MCCOverFlow)
348  cout << "(counter overflow)";
349  cout << endl;
350  }
351  }
352 
353  void
355  const string& msg,
356  const string& pre)
357  {
358  vector<const TRGCDCLink*> tmp;
359  tmp.push_back(& link);
360  dump(tmp, msg, pre);
361  }
362 
363  unsigned
364  TRGCDCLink::nStereoHits(const vector<TRGCDCLink*>& links)
365  {
366  unsigned nLinks = links.size();
367  unsigned n = 0;
368  for (unsigned i = 0; i < nLinks; i++)
369  if (links[i]->cell()->stereo())
370  ++n;
371  return n;
372  }
373 
374  unsigned
375  TRGCDCLink::nAxialHits(const vector<TRGCDCLink*>& links)
376  {
377  unsigned nLinks = links.size();
378  unsigned n = 0;
379  for (unsigned i = 0; i < nLinks; i++)
380  if (links[i]->cell()->axial())
381  ++n;
382  return n;
383  }
384 
385  vector<TRGCDCLink*>
386  TRGCDCLink::axialHits(const vector<TRGCDCLink*>& links)
387  {
388  vector<TRGCDCLink*> a;
389  unsigned n = links.size();
390  for (unsigned i = 0; i < n; i++) {
391  if (links[i]->cell()->axial())
392  a.push_back(links[i]);
393  }
394  return a;
395  }
396 
397  vector<TRGCDCLink*>
398  TRGCDCLink::stereoHits(const vector<TRGCDCLink*>& links)
399  {
400  vector<TRGCDCLink*> a;
401  unsigned n = links.size();
402  for (unsigned i = 0; i < n; i++) {
403  if (! links[i]->cell()->axial())
404  a.push_back(links[i]);
405  }
406  return a;
407  }
408 
409  TRGCDCLink*
410  TRGCDCLink::innerMost(const vector<TRGCDCLink*>& a)
411  {
412  unsigned n = a.size();
413  unsigned minId = 19999;
414  TRGCDCLink* t = 0;
415  for (unsigned i = 0; i < n; i++) {
416  unsigned id = a[i]->cell()->id();
417  if (id < minId) {
418  minId = id;
419  t = a[i];
420  }
421  }
422  return t;
423  }
424 
425  TRGCDCLink*
426  TRGCDCLink::outerMost(const vector<TRGCDCLink*>& a)
427  {
428  unsigned n = a.size();
429  unsigned maxId = 0;
430  TRGCDCLink* t = 0;
431  for (unsigned i = 0; i < n; i++) {
432  unsigned id = a[i]->cell()->id();
433  if (id >= maxId) {
434  maxId = id;
435  t = a[i];
436  }
437  }
438  return t;
439  }
440 
441  void
442  TRGCDCLink::separateCores(const vector<TRGCDCLink*>& input,
443  vector<TRGCDCLink*>& cores,
444  vector<TRGCDCLink*>& nonCores)
445  {
446  unsigned n = input.size();
447  for (unsigned i = 0; i < n; i++) {
448  TRGCDCLink& t = * input[i];
449  const Belle2::TCCHit& h = * t.hit();
450  if (h.state() & CellHitFittingValid)
451  cores.push_back(& t);
452  else
453  nonCores.push_back(& t);
454  }
455  }
456 
457  vector<TRGCDCLink*>
458  TRGCDCLink::cores(const vector<TRGCDCLink*>& input)
459  {
460  vector<TRGCDCLink*> a;
461  unsigned n = input.size();
462  for (unsigned i = 0; i < n; i++) {
463  TRGCDCLink& t = * input[i];
464  const Belle2::TCCHit& h = * t.hit();
465  if (h.state() & CellHitFittingValid)
466  a.push_back(& t);
467  }
468  return a;
469  }
470 
471  bool
473  {
474  return a->cell()->id() < b->cell()->id();
475  }
476 
477  int
479  {
480  return a->position().x() < b->position().x();
481  }
482 
483  unsigned
484  TRGCDCLink::width(const vector<TRGCDCLink*>& list)
485  {
486  const unsigned n = list.size();
487  if (n < 2) return n;
488 
489  const TCCell* const w0 = list[0]->cell();
490 //cnv const unsigned sId = w0->superLayerId();
491  unsigned nWires = w0->layer().nCells();
492  unsigned center = w0->localId();
493 
494  if (ms_smallcell && w0->layerId() < 3) {
495  nWires /= 2;
496  center /= 2;
497  }
498 
499  unsigned left = 0;
500  unsigned right = 0;
501  for (unsigned i = 1; i < n; i++) {
502  const TCCell* const w = list[i]->cell();
503  unsigned id = w->localId();
504 
505  if (ms_smallcell && w->layerId() < 3)
506  id /= 2;
507 
508  unsigned distance0, distance1;
509  if (id > center) {
510  distance0 = id - center;
511  distance1 = nWires - distance0;
512  } else {
513  distance1 = center - id;
514  distance0 = nWires - distance1;
515  }
516 
517  if (distance0 < distance1) {
518  if (distance0 > right) right = distance0;
519  } else {
520  if (distance1 > left) left = distance1;
521  }
522  }
523 
524  return right + left + 1;
525  }
526 
527  vector<TRGCDCLink*>
528  TRGCDCLink::edges(const vector<TRGCDCLink*>& list)
529  {
530  vector<TRGCDCLink*> a;
531 
532  unsigned n = list.size();
533  if (n < 2) return a;
534  else if (n == 2) return list;
535 
536  const TCCell* w = list[0]->cell();
537  unsigned nWires = w->layer().nCells();
538  unsigned center = w->localId();
539 
540  unsigned left = 0;
541  unsigned right = 0;
542  TRGCDCLink* leftL = list[0];
543  TRGCDCLink* rightL = list[0];
544  for (unsigned i = 1; i < n; i++) {
545  w = list[i]->cell();
546  unsigned id = w->localId();
547 
548  unsigned distance0, distance1;
549  if (id > center) {
550  distance0 = id - center;
551  distance1 = nWires - distance0;
552  } else {
553  distance1 = center - id;
554  distance0 = nWires - distance1;
555  }
556 
557  if (distance0 < distance1) {
558  if (distance0 > right) {
559  right = distance0;
560  rightL = list[i];
561  }
562  } else {
563  if (distance1 > left) {
564  left = distance1;
565  leftL = list[i];
566  }
567  }
568  }
569 
570  a.push_back(leftL);
571  a.push_back(rightL);
572  return a;
573  }
574 
575  vector<TRGCDCLink*>
576  TRGCDCLink::sameLayer(const vector<TRGCDCLink*>& list, const TRGCDCLink& a)
577  {
578  vector<TRGCDCLink*> same;
579  unsigned id = a.cell()->layerId();
580  unsigned n = list.size();
581  for (unsigned i = 0; i < n; i++) {
582  if (list[i]->cell()->layerId() == id) same.push_back(list[i]);
583  }
584  return same;
585  }
586 
587  vector<TRGCDCLink*>
588  TRGCDCLink::sameSuperLayer(const vector<TRGCDCLink*>& list, const TRGCDCLink& a)
589  {
590  vector<TRGCDCLink*> same;
591  unsigned id = a.cell()->superLayerId();
592  unsigned n = list.size();
593  for (unsigned i = 0; i < n; i++) {
594  if (list[i]->cell()->superLayerId() == id) same.push_back(list[i]);
595  }
596  return same;
597  }
598 
599  vector<TRGCDCLink*>
600  TRGCDCLink::sameLayer(const vector<TRGCDCLink*>& list, unsigned id)
601  {
602  vector<TRGCDCLink*> same;
603  unsigned n = list.size();
604  for (unsigned i = 0; i < n; i++) {
605  if (list[i]->cell()->layerId() == id) same.push_back(list[i]);
606  }
607  return same;
608  }
609 
610  vector<TRGCDCLink*>
611  TRGCDCLink::sameSuperLayer(const vector<TRGCDCLink*>& list, unsigned id)
612  {
613  vector<TRGCDCLink*> same;
614  unsigned n = list.size();
615  for (unsigned i = 0; i < n; i++) {
616  if (list[i]->cell()->superLayerId() == id) same.push_back(list[i]);
617  }
618  return same;
619  }
620 
621  vector<TRGCDCLink*>
622  TRGCDCLink::inOut(const vector<TRGCDCLink*>& list)
623  {
624  vector<TRGCDCLink*> inners;
625  vector<TRGCDCLink*> outers;
626  unsigned n = list.size();
627  unsigned innerMostLayer = 999;
628  unsigned outerMostLayer = 0;
629  for (unsigned i = 0; i < n; i++) {
630  unsigned id = list[i]->cell()->layerId();
631  if (id < innerMostLayer) innerMostLayer = id;
632  else if (id > outerMostLayer) outerMostLayer = id;
633  }
634  for (unsigned i = 0; i < n; i++) {
635  unsigned id = list[i]->cell()->layerId();
636  if (id == innerMostLayer) inners.push_back(list[i]);
637  else if (id == outerMostLayer) outers.push_back(list[i]);
638  }
639 // inners.push_back(outers);
640  inners.insert(inners.end(), outers.begin(), outers.end());
641  return inners;
642  }
643 
644  unsigned
645  TRGCDCLink::superLayer(const vector<TRGCDCLink*>& list)
646  {
647  unsigned sl = 0;
648  unsigned n = list.size();
649  for (unsigned i = 0; i < n; i++)
650  sl |= (1 << (list[i]->cell()->superLayerId()));
651  return sl;
652  }
653 
654  unsigned
655  TRGCDCLink::superLayer(const vector<TRGCDCLink*>& links, unsigned minN)
656  {
657  clearBufferSL();
658  unsigned n = links.size();
659  for (unsigned i = 0; i < n; i++)
660  ++_nHitsSL[links[i]->cell()->superLayerId()];
661  unsigned sl = 0;
662  for (unsigned i = 0; i < _nSL; i++)
663  if (_nHitsSL[i] >= minN)
664  sl |= (1 << i);
665  return sl;
666  }
667 
668  unsigned
669  TRGCDCLink::nSuperLayers(const vector<TRGCDCLink*>& list)
670  {
671  unsigned l0 = 0;
672  unsigned n = list.size();
673  for (unsigned i = 0; i < n; i++) {
674  unsigned id = list[i]->cell()->superLayerId();
675  l0 |= (1 << id);
676  }
677 
678  unsigned l = 0;
679  for (unsigned i = 0; i < _nSL; i++) {
680  if (l0 & (1 << i)) ++l;
681  }
682  return l;
683  }
684 
685  unsigned
686  TRGCDCLink::nSuperLayers(const vector<TRGCDCLink*>& links, unsigned minN)
687  {
688  clearBufferSL();
689  unsigned n = links.size();
690  for (unsigned i = 0; i < n; i++)
691  ++_nHitsSL[links[i]->cell()->superLayerId()];
692  unsigned sl = 0;
693  for (unsigned i = 0; i < _nSL; i++)
694  if (_nHitsSL[i] >= minN)
695  ++sl;
696  return sl;
697  }
698 
699  unsigned
700  TRGCDCLink::nMissingAxialSuperLayers(const vector<TRGCDCLink*>& links)
701  {
702  clearBufferSL();
703  const unsigned n = links.size();
704 // unsigned nHits[6] = {0, 0, 0, 0, 0, 0};
705  for (unsigned i = 0; i < n; i++)
706  if (links[i]->cell()->axial())
707  ++_nHitsSL[links[i]->cell()->axialStereoSuperLayerId()];
708 // ++nHits[links[i]->cell()->superLayerId() / 2];
709  unsigned j = 0;
710  while (_nHitsSL[j] == 0) ++j;
711  unsigned nMissing = 0;
712  unsigned nMax = 0;
713  for (unsigned i = j; i < _nSLA; i++) {
714  if (+_nHitsSL[i] == 0) ++nMissing;
715  else {
716  if (nMax < nMissing) nMax = nMissing;
717  nMissing = 0;
718  }
719  }
720  return nMax;
721  }
722 
723  const Belle2::TRGCDCTrackMC&
724  TRGCDCLink::links2HEP(const vector<TRGCDCLink*>&)
725  {
727  const vector<const Belle2::TRGCDCTrackMC*> list =
729  unsigned nHep = list.size();
730 
731  if (! nHep) return * best;
732 
733  unsigned* N;
734  if (NULL == (N = (unsigned*) malloc(nHep * sizeof(unsigned)))) {
735 // perror("$Id: TRGCDCLink.cc 11153 2010-04-28 03:36:53Z yiwasaki $:N:malloc");
736  exit(1);
737  }
738  for (unsigned i = 0; i < nHep; i++) N[i] = 0;
739 
740 // for (unsigned i = 0; i < (unsigned) links.size(); i++) {
741 // const TRGCDCLink & l = * links[i];
742 // const Belle2::TRGCDCTrackMC & hep = * l.hit()->mc()->hep();
743 // for (unsigned j = 0; j < nHep; j++)
744 // if (list[j] == & hep)
745 // ++N[j];
746 // }
747 
748  unsigned nMax = 0;
749  for (unsigned i = 0; i < nHep; i++) {
750  if (N[i] > nMax) {
751  best = list[i];
752  nMax = N[i];
753  }
754  }
755 
756  free(N);
757 
758  return * best;
759  }
760 
761  void
762  TRGCDCLink::nHitsSuperLayer(const vector<TRGCDCLink*>& links, vector<TRGCDCLink*>* list)
763  {
764  const unsigned nLinks = links.size();
765  for (unsigned i = 0; i < nLinks; i++)
766  list[links[i]->cell()->superLayerId()].push_back(links[i]);
767  }
768 
769  string
770  TRGCDCLink::layerUsage(const vector<TRGCDCLink*>& links)
771  {
772 // unsigned n[11];
773  static unsigned* n = new unsigned[Belle2::TRGCDC::getTRGCDC()->nSuperLayers()];
774  nHitsSuperLayer(links, n);
775  string nh;
776  for (unsigned i = 0; i < _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) {
809  const Belle2::TRGCDC& cdc = * Belle2::TRGCDC::getTRGCDC();
810  _nL = cdc.nLayers();
811  _nSL = cdc.nSuperLayers();
812  _nSLA = cdc.nAxialSuperLayers();
813  _nHitsSL = new unsigned[_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*
834  TRGCDCLink::wire(void) const
835  {
836  if (_hit)
837  return dynamic_cast<const TRGCDCWire*>(& _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 (_all.size())
853  delete _all.back();
854  }
855 
856  void*
857  TRGCDCLink::operator new(size_t size)
858  {
859  void* p = malloc(size);
860  _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 = _all.begin();
873  it != _all.end();
874  ++it) {
875  if ((* it) == static_cast<TRGCDCLink*>(t)) {
876  _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
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 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:576
static const TRGCDCTrackMC & links2HEP(const std::vector< TRGCDCLink * > &links)
returns TRGCDCTrackMC
Definition: Link.cc:724
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:190
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:622
static std::vector< TRGCDCLink * > edges(const std::vector< TRGCDCLink * > &)
returns links which are edges.
Definition: Link.cc:528
static TRGCDCLink * outerMost(const std::vector< TRGCDCLink * > &links)
returns the outer-most link.
Definition: Link.cc:426
const HepGeom::Point3D< double > & position(void) const
returns position.
Definition: Link.h:551
unsigned layerId(void) const
returns layer id.
Definition: Cell.h:211
static unsigned width(const std::vector< TRGCDCLink * > &)
returns width(wire cell unit) of given std::vector<TRGCDCLink *>.
Definition: Link.cc:484
static TRGCDCLink * innerMost(const std::vector< TRGCDCLink * > &links)
returns the inner-most link.
Definition: Link.cc:410
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:588
static unsigned superLayer(const std::vector< TRGCDCLink * > &list)
returns super layer pattern.
Definition: Link.cc:645
unsigned superLayerId(void) const
returns super layer id.
Definition: Cell.h:218
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:478
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:442
static bool sortById(const TRGCDCLink *a, const TRGCDCLink *b)
sorts by ID.
Definition: Link.cc:472
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:700
static void removeAll(void)
destructs all TRGCDCLink objects. (Called by TRGCDC)
Definition: Link.cc:850
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:785
static unsigned nSuperLayers(const std::vector< TRGCDCLink * > &links)
returns # of layers.
Definition: Link.cc:669
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:398
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:386
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:770
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:458
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:375
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:364
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
static unsigned _nSLA
...Buffers...
Definition: Link.h:402
Abstract base class for different kinds of events.