Belle II Software  release-05-01-25
Link.cc
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : Link.cc
5 // Section : TRG CDC
6 // Owner : Yoshihito Iwasaki
7 // Email : yoshihito.iwasaki@kek.jp
8 //-----------------------------------------------------------------------------
9 // Description : A class to relate TRGCDCWireHit and TRGCDCTrack objects.
10 //-----------------------------------------------------------------------------
11 // $Log$
12 //-----------------------------------------------------------------------------
13 
14 #define TRG_SHORT_NAMES
15 #define TRGCDC_SHORT_NAMES
16 
17 #include <string>
18 #include <cstring>
19 #include <algorithm>
20 #include "trg/trg/Utilities.h"
21 #include "trg/cdc/Wire.h"
22 #include "trg/cdc/WireHit.h"
23 #include "trg/cdc/WireHitMC.h"
24 #include "trg/cdc/Track.h"
25 #include "trg/cdc/TrackMC.h"
26 #include "trg/cdc/Segment.h"
27 #include "trg/cdc/Link.h"
28 
29 using namespace std;
30 
31 namespace Belle2 {
37  bool TRGCDCLink::ms_smallcell(false);
38  bool TRGCDCLink::ms_superb(false);
39  unsigned TRGCDCLink::_nL = 56;
40  unsigned TRGCDCLink::_nSL = 9;
41  unsigned TRGCDCLink::_nSLA = 5;
42  unsigned* TRGCDCLink::_nHitsSL = 0;
43  vector<TCLink*> TRGCDCLink::_all;
44 
45  TRGCDCLink::TRGCDCLink(TCTrack* t,
46  const Belle2::TCCHit* h,
47  const HepGeom::Point3D<double>& p)
48  : _track(t),
49  _hit(h),
50  _position(p),
51  _dPhi(0),
52  _leftRight(0),
53  _pull(0),
54  _link(0),
55  _fit2D(0)
56  {
57  if (h) {
58  _drift[0] = h->drift(0);
59  _drift[1] = h->drift(1);
60  _dDrift[0] = h->dDrift(0);
61  _dDrift[1] = h->dDrift(1);
62  } else {
63  _drift[0] = 0.;
64  _drift[1] = 0.;
65  _dDrift[0] = 0.;
66  _dDrift[1] = 0.;
67  }
68 
69  for (unsigned i = 0; i < 7; ++i)
70  _neighbor[i] = NULL;
71 
72  if (h) {
73  _onTrack = _onWire = h->xyPosition();
74  }
75  }
76 
78  : _track(l._track),
79  _hit(l._hit),
80  _onTrack(l._onTrack),
81  _onWire(l._onWire),
82  _position(l._position),
83  _dPhi(l._dPhi),
84  _leftRight(l._leftRight),
85  _zStatus(l._zStatus),
86  _zPair(l._zPair),
87  _pull(l._pull),
88  _link(l._link),
89  _fit2D(l._fit2D)
90  {
91  _drift[0] = l._drift[0];
92  _drift[1] = l._drift[1];
93  _dDrift[0] = l._dDrift[0];
94  _dDrift[1] = l._dDrift[1];
95  for (unsigned i = 0; i < 7; ++i)
96  _neighbor[i] = l._neighbor[i];
97  for (unsigned i = 0; i < 4; ++i)
98  _arcZ[i] = l._arcZ[i];
99  }
100 
102  {
103  }
104 
105  unsigned
106  TRGCDCLink::nLayers(const vector<TRGCDCLink*>& list)
107  {
108  unsigned l0 = 0;
109  unsigned l1 = 0;
110  unsigned n = list.size();
111  for (unsigned i = 0; i < n; i++) {
112  unsigned id = list[i]->cell()->layerId();
113  if (id < 32) l0 |= (1 << id);
114  else l1 |= (1 << (id - 32));
115  }
116 
117  unsigned l = 0;
118  for (unsigned i = 0; i < 32; i++) {
119  if (l0 & (1 << i)) ++l;
120  if (l1 & (1 << i)) ++l;
121  }
122  return l;
123  }
124 
125  void
126  TRGCDCLink::nHits(const vector<TRGCDCLink*>& links, unsigned* nHits)
127  {
128  for (unsigned i = 0; i < _nL; i++)
129  nHits[i] = 0;
130  unsigned nLinks = links.size();
131  for (unsigned i = 0; i < nLinks; i++)
132  ++nHits[links[i]->cell()->layerId()];
133  }
134 
135  void
136  TRGCDCLink::nHitsSuperLayer(const vector<TRGCDCLink*>& links, unsigned* nHits)
137  {
138  for (unsigned i = 0; i < _nSL; i++)
139  nHits[i] = 0;
140  const unsigned nLinks = links.size();
141  for (unsigned i = 0; i < nLinks; i++)
142  ++nHits[links[i]->cell()->superLayerId()];
143  }
144 
145  void
146  TRGCDCLink::dump_base(const string& msg, const string& pre) const
147  {
148 
149  //...Basic options...
150 // bool track = (msg.find("track") != string::npos);
151 // bool mc = (msg.find("mc") != string::npos);
152  bool pull = (msg.find("pull") != string::npos);
153  bool flag = (msg.find("flag") != string::npos);
154  bool stereo = (msg.find("stereo") != string::npos);
155  bool pos = (msg.find("position") != string::npos);
156 
157  //...Strong options...
158  bool breif = (msg.find("breif") != string::npos);
159  bool detail = (msg.find("detail") != string::npos);
160  if (detail)
161 // track = mc = pull = flag = stereo = pos = true;
162  pull = flag = stereo = pos = true;
163  if (breif)
164  pull = flag = true;
165 
166  //...Output...
167  cout << pre;
168  if (_hit) {
169  cout << cell()->name();
170  } else {
171  cout << "No hit linked";
172  }
173 // if (mc) {
174 // if (_hit) {
175 // if (_hit->mc()) {
176 // if (_hit->mc()->hep())
177 // cout << "(mc" << _hit->mc()->hep()->id() << ")";
178 // else
179 // cout << "(mc?)";
180 // }
181 // else {
182 // cout << "(mc?)";
183 // }
184 // }
185 // }
186  if (pull)
187  cout << "[pul=" << this->pull() << "]";
188  if (flag) {
189  if (_hit) {
190  if (_hit->state() & CellHitFindingValid)
191  cout << "o";
192  if (_hit->state() & CellHitFittingValid)
193  cout << "+";
194  if (_hit->state() & CellHitInvalidForFit)
195  cout << "x";
196  }
197  }
198  if (stereo) {
199  cout << "{" << leftRight() << "," << _zStatus << "}";
200  }
201  if (pos) {
202  cout << ",pos=" << position();
203  cout << ",drift=" << drift(0) << "," << drift(1);
204  }
205  }
206 
207  void
208  TRGCDCLink::dump(const string& msg, const string& pre) const
209  {
210  dump_base(msg, pre);
211  cout << endl;
212  }
213 
214  void
215  TRGCDCLink::dump(const vector<TRGCDCLink*>& links,
216  const string& msg,
217  const string& pre)
218  {
219  vector<const TRGCDCLink*> clinks;
220  for (unsigned i = 0; i < links.size(); i++)
221  clinks.push_back(links[i]);
222  TRGCDCLink::dump(clinks, msg, pre);
223  }
224 
225  void
226  TRGCDCLink::dump(const vector<const TRGCDCLink*>& links,
227  const string& msg,
228  const string& pre)
229  {
230 
231  //...Basic options...
232  bool mc = (msg.find("mc") != string::npos);
233  bool sort = (msg.find("sort") != string::npos);
234  bool flag = (msg.find("flag") != string::npos);
235 
236  //...Strong options...
237  bool detail = (msg.find("detail") != string::npos);
238  if (detail)
239  mc = flag = true;
240 
241  vector<const TRGCDCLink*> tmp = links;
242  if (sort)
243  std::sort(tmp.begin(), tmp.end(), TRGCDCLink::sortById);
244 // sort(tmp.begin(), tmp.end(), TRGCDCLink::sortById);
245  unsigned n = tmp.size();
246  unsigned nForFit = 0;
247 #define MCC_MAX 1000
248  unsigned MCC0[MCC_MAX];
249  unsigned MCC1[MCC_MAX];
250  memset((char*) MCC0, 0, sizeof(unsigned) * MCC_MAX);
251  memset((char*) MCC1, 0, sizeof(unsigned) * MCC_MAX);
252  bool MCCOverFlow = false;
253 
254  cout << pre;
255  for (unsigned i = 0; i < n; i++) {
256  const TRGCDCLink& l = * tmp[i];
257 
258 // if (mc) {
259 // unsigned mcId = 999;
260 // if (l.hit()) {
261 // if (l.hit()->mc())
262 // if (l.hit()->mc()->hep())
263 // mcId = l.hit()->mc()->hep()->id();
264 // if (mcId < MCC_MAX) {
265 // ++MCC0[mcId];
266 // if (l.hit()->state() & WireHitFittingValid) {
267 // if (! (l.hit()->state() & WireHitInvalidForFit))
268 // ++MCC1[mcId];
269 // }
270 // }
271 // else {
272 // MCCOverFlow = true;
273 // }
274 // }
275 // }
276  if (flag) {
277  if (l.hit()) {
278  if (l.hit()->state() & CellHitFittingValid) {
279  if (!(l.hit()->state() & CellHitInvalidForFit))
280  ++nForFit;
281  }
282  }
283  }
284  if (i)
285  cout << ",";
286  l.dump_base(msg);
287  }
288  if (n)
289  cout << ",Total " << n << " links";
290  else
291  cout << "no link";
292  if (flag) cout << ",fv " << nForFit << " l(s)";
293  if (mc) {
294  unsigned nMC = 0;
295  cout << ", mc";
296  for (unsigned i = 0; i < MCC_MAX; i++) {
297  if (MCC0[i] > 0) {
298  ++nMC;
299  cout << i << ":" << MCC0[i] << ",";
300  }
301  }
302  cout << "total " << nMC << " mc contributions";
303  if (flag) {
304  nMC = 0;
305  cout << ", fv mc";
306  for (unsigned i = 0; i < MCC_MAX; i++) {
307  if (MCC1[i] > 0) {
308  ++nMC;
309  cout << i << ":" << MCC1[i] << ",";
310  }
311  }
312  cout << " total " << nMC << " mc fit valid contribution(s)";
313  }
314 
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 
408  TRGCDCLink*
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 
424  TRGCDCLink*
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  {
656  clearBufferSL();
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  {
687  clearBufferSL();
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  {
701  clearBufferSL();
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 
722  const Belle2::TRGCDCTrackMC&
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) {
808  const Belle2::TRGCDC& cdc = * Belle2::TRGCDC::getTRGCDC();
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*
833  TRGCDCLink::wire(void) const
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((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) == (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
Belle2::TRGCDCLink::_nL
static unsigned _nL
...Buffers...
Definition: Link.h:399
Belle2::TRGCDCLink::axialHits
static std::vector< TRGCDCLink * > axialHits(const std::vector< TRGCDCLink * > &links)
returns axial hits.
Definition: Link.cc:385
Belle2::TRGCDCLink::initializeBuffers
static void initializeBuffers(void)
initialize the Buffers
Definition: Link.cc:804
Belle2::TRGCDCLink::dump
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition: Link.cc:208
Belle2::TRGCDCLink::nHits
static void nHits(const std::vector< TRGCDCLink * > &links, unsigned *nHits)
returns # of hits per layer.
Definition: Link.cc:126
Belle2::TRGCDCTrackMC::_undefined
static TRGCDCTrackMC * _undefined
returns a pointer to gen_hepevt.
Definition: TrackMC.h:89
Belle2::TRGCDCLink::_nSL
static unsigned _nSL
...Buffers...
Definition: Link.h:401
Belle2::TRGCDCLink::separate
static void separate(const std::vector< TRGCDCLink * > &links, unsigned nLayers, std::vector< TRGCDCLink * > *layers)
separates into layers.
Definition: Link.cc:818
Belle2::TRGCDCTrackMC::list
static std::vector< const TRGCDCTrackMC * > list(void)
returns a list of TRGCDCTrackMC's.
Definition: TrackMC.cc:95
Belle2::TRGCDCCellHit::state
unsigned state(void) const
returns state.
Definition: CellHit.h:260
Belle2::TRGCDCTrackMC
A class to represent a GEN_HEPEVT particle in tracking.
Definition: TrackMC.h:33
Belle2::TRGCDCLink::width
static unsigned width(const std::vector< TRGCDCLink * > &)
returns width(wire cell unit) of given std::vector<TRGCDCLink *>.
Definition: Link.cc:483
Belle2::TRGCDCLink::sortById
static bool sortById(const TRGCDCLink *a, const TRGCDCLink *b)
sorts by ID.
Definition: Link.cc:471
Belle2::TRGCDCLink::_all
static std::vector< TRGCDCLink * > _all
Keeps all TRGCDCLinks created by new().
Definition: Link.h:349
Belle2::TRGCDCWire
A class to represent a wire in CDC.
Definition: Wire.h:57
Belle2::TRGCDCLink::pull
double pull(void) const
returns pull.
Definition: Link.h:462
Belle2::TRGCDCLink::superLayer
static unsigned superLayer(const std::vector< TRGCDCLink * > &list)
returns super layer pattern.
Definition: Link.cc:644
Belle2::TRGCDCLink::nMissingAxialSuperLayers
static unsigned nMissingAxialSuperLayers(const std::vector< TRGCDCLink * > &links)
returns # of missing axial super layers.
Definition: Link.cc:699
Belle2::TRGCDCLink::link
TRGCDCLink * link(void) const
returns a pointer to a TRGCDCLink.
Definition: Link.h:596
Belle2::TRGCDCLink::edges
static std::vector< TRGCDCLink * > edges(const std::vector< TRGCDCLink * > &)
returns links which are edges.
Definition: Link.cc:527
Belle2::TRGCDCLink::sameLayer
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
Belle2::TRGCDCLink::nHitsSuperLayer
static void nHitsSuperLayer(const std::vector< TRGCDCLink * > &links, unsigned *nHits)
returns # of hits per super layer.
Definition: Link.cc:136
Belle2::TRGCDCLink::nSuperLayers
static unsigned nSuperLayers(const std::vector< TRGCDCLink * > &links)
returns # of layers.
Definition: Link.cc:668
Belle2::TRGCDCLink::ms_smallcell
static bool ms_smallcell
ms_smallcell
Definition: Link.h:394
Belle2::TRGCDCLink::cores
static std::vector< TRGCDCLink * > cores(const std::vector< TRGCDCLink * > &input)
separate cores and non-cores.
Definition: Link.cc:457
Belle2::TRGCDC::nSuperLayers
unsigned nSuperLayers(void) const
returns # of super layers.
Definition: TRGCDC.h:871
Belle2::TRGCDCLink::nLayers
static unsigned nLayers(const std::vector< TRGCDCLink * > &links)
returns # of layers.
Definition: Link.cc:106
Belle2::TRGCDCLink::innerMost
static TRGCDCLink * innerMost(const std::vector< TRGCDCLink * > &links)
returns the inner-most link.
Definition: Link.cc:409
Belle2::TRGCDCLink::stereoHits
static std::vector< TRGCDCLink * > stereoHits(const std::vector< TRGCDCLink * > &links)
returns stereo hits.
Definition: Link.cc:397
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TRGCDCCell::name
virtual std::string name(void) const =0
returns name.
Belle2::TRGCDCLink::nAxialHits
static unsigned nAxialHits(const std::vector< TRGCDCLink * > &links)
returns # of axial hits.
Definition: Link.cc:374
Belle2::TRGCDC::getTRGCDC
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:190
Belle2::TRGCDCLink::nStereoHits
static unsigned nStereoHits(const std::vector< TRGCDCLink * > &links)
returns # of stereo hits.
Definition: Link.cc:363
Belle2::TRGCDCLink::sameSuperLayer
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
Belle2::TRGCDCLink::remove
static void remove(std::vector< TRGCDCLink * > &list, const std::vector< TRGCDCLink * > &links)
removes links from list if wire is same
Definition: Link.cc:784
Belle2::TRGCDCCell::superLayerId
unsigned superLayerId(void) const
returns super layer id.
Definition: Cell.h:219
Belle2::TRGCDCLink::links2HEP
static const TRGCDCTrackMC & links2HEP(const std::vector< TRGCDCLink * > &links)
returns TRGCDCTrackMC
Definition: Link.cc:723
Belle2::TRGCDC
The instance of TRGCDC is a singleton.
Definition: TRGCDC.h:70
Belle2::TRGCDCLink::cell
const TRGCDCCell * cell(void) const
returns a pointer to a cell.
Definition: Link.h:685
Belle2::TRGCDCLink::layerUsage
static std::string layerUsage(const std::vector< TRGCDCLink * > &links)
usage of each layer
Definition: Link.cc:769
Belle2::TRGCDCLink::_nHitsSL
static unsigned * _nHitsSL
...Buffers...
Definition: Link.h:405
Belle2::TRGCDCLink::_nSLA
static unsigned _nSLA
...Buffers...
Definition: Link.h:403
Belle2::TRGCDCLink::position
const HepGeom::Point3D< double > & position(void) const
returns position.
Definition: Link.h:552
Belle2::TRGCDCLink::inOut
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
Belle2::TRGCDCLink::leftRight
unsigned leftRight(void) const
returns left-right. 0:left, 1:right, 2:wire
Definition: Link.h:524
Belle2::TRGCDCLink::dump_base
void dump_base(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition: Link.cc:146
Belle2::TRGCDCCellHit::cell
virtual const TRGCDCCell & cell(void) const
returns a pointer to a TRGCDCWire.
Definition: CellHit.h:253
HepGeom::Point3D< double >
Belle2::TRGCDCLink::drift
float drift(void) const
returns drift distance.
Definition: Link.h:664
Belle2::TRGCDCLink::clearBufferSL
static void clearBufferSL(void)
clear buffers
Definition: Link.h:678
Belle2::TRGCDCLink::~TRGCDCLink
virtual ~TRGCDCLink()
Destructor.
Definition: Link.cc:101
Belle2::TRGCDCCell::layerId
unsigned layerId(void) const
returns layer id.
Definition: Cell.h:212
Belle2::TRGCDCLink::separateCores
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
Belle2::TRGCDCLink::sortByX
static int sortByX(const TRGCDCLink *a, const TRGCDCLink *b)
sorts by X position.
Definition: Link.cc:477
Belle2::TRGCDCLink::removeAll
static void removeAll(void)
destructs all TRGCDCLink objects. (Called by TRGCDC)
Definition: Link.cc:849
Belle2::TRGCDCLink::wire
const TRGCDCWire * wire(void) const
returns a pointer to a wire.
Definition: Link.cc:833
Belle2::TRGCDCLink::outerMost
static TRGCDCLink * outerMost(const std::vector< TRGCDCLink * > &links)
returns the outer-most link.
Definition: Link.cc:425