13 #define TRG_SHORT_NAMES
14 #define TRGCDC_SHORT_NAMES
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"
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;
44 TRGCDCLink::TRGCDCLink(TCTrack* t,
45 const Belle2::TCCHit* 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);
68 for (
unsigned i = 0; i < 7; ++i)
72 _onTrack = _onWire = h->xyPosition();
81 _position(l._position),
83 _leftRight(l._leftRight),
94 for (
unsigned i = 0; i < 7; ++i)
96 for (
unsigned i = 0; i < 4; ++i)
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));
117 for (
unsigned i = 0; i < 32; i++) {
118 if (l0 & (1u << i)) ++l;
119 if (l1 & (1u << i)) ++l;
127 for (
unsigned i = 0; i <
_nL; i++)
129 unsigned nLinks = links.size();
130 for (
unsigned i = 0; i < nLinks; i++)
137 for (
unsigned i = 0; i <
_nSL; i++)
139 const unsigned nLinks = links.size();
140 for (
unsigned i = 0; i < nLinks; i++)
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);
157 bool breif = (msg.find(
"breif") != string::npos);
158 bool detail = (msg.find(
"detail") != string::npos);
161 pull = flag = stereo = pos =
true;
170 cout <<
"No hit linked";
186 cout <<
"[pul=" << this->
pull() <<
"]";
193 if (
_hit->
state() & CellHitInvalidForFit)
202 cout <<
",drift=" <<
drift(0) <<
"," <<
drift(1);
218 vector<const TRGCDCLink*> clinks;
219 for (
unsigned i = 0; i < links.size(); i++)
220 clinks.push_back(links[i]);
231 bool mc = (msg.find(
"mc") != string::npos);
232 bool sort = (msg.find(
"sort") != string::npos);
233 bool flag = (msg.find(
"flag") != string::npos);
236 bool detail = (msg.find(
"detail") != string::npos);
240 vector<const TRGCDCLink*> tmp = links;
244 unsigned n = tmp.size();
245 unsigned nForFit = 0;
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;
254 for (
unsigned i = 0; i < n; i++) {
277 if (l.
hit()->
state() & CellHitFittingValid) {
278 if (!(l.
hit()->
state() & CellHitInvalidForFit))
288 cout <<
",Total " << n <<
" links";
291 if (flag) cout <<
",fv " << nForFit <<
" l(s)";
295 for (
unsigned i = 0; i < MCC_MAX; i++) {
298 cout << i <<
":" << MCC0[i] <<
",";
301 cout <<
"total " << nMC <<
" mc contributions";
305 for (
unsigned i = 0; i < MCC_MAX; i++) {
308 cout << i <<
":" << MCC1[i] <<
",";
311 cout <<
" total " << nMC <<
" mc fit valid contribution(s)";
316 cout <<
"(counter overflow)";
323 if (! list.size())
return;
326 for (
unsigned i = 0; i < MCC_MAX; i++) {
330 cout <<
", mc" << i <<
"(";
332 cout << h->pType() <<
")";
338 cout <<
"<-mc" << m->id();
348 cout <<
"(counter overflow)";
358 vector<const TRGCDCLink*> tmp;
359 tmp.push_back(&
link);
366 unsigned nLinks = links.size();
368 for (
unsigned i = 0; i < nLinks; i++)
369 if (links[i]->
cell()->stereo())
377 unsigned nLinks = links.size();
379 for (
unsigned i = 0; i < nLinks; i++)
380 if (links[i]->
cell()->axial())
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]);
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]);
412 unsigned n = a.size();
413 unsigned minId = 19999;
415 for (
unsigned i = 0; i < n; i++) {
416 unsigned id = a[i]->cell()->id();
428 unsigned n = a.size();
431 for (
unsigned i = 0; i < n; i++) {
432 unsigned id = a[i]->cell()->id();
443 vector<TRGCDCLink*>& cores,
444 vector<TRGCDCLink*>& nonCores)
446 unsigned n = input.size();
447 for (
unsigned i = 0; i < n; i++) {
449 const Belle2::TCCHit& h = * t.hit();
450 if (h.state() & CellHitFittingValid)
451 cores.push_back(& t);
453 nonCores.push_back(& t);
460 vector<TRGCDCLink*> a;
461 unsigned n = input.size();
462 for (
unsigned i = 0; i < n; i++) {
464 const Belle2::TCCHit& h = * t.hit();
465 if (h.state() & CellHitFittingValid)
474 return a->cell()->id() < b->cell()->id();
480 return a->position().x() < b->position().x();
486 const unsigned n = list.size();
489 const TCCell*
const w0 = list[0]->cell();
491 unsigned nWires = w0->layer().nCells();
492 unsigned center = w0->localId();
501 for (
unsigned i = 1; i < n; i++) {
502 const TCCell*
const w = list[i]->cell();
503 unsigned id = w->localId();
508 unsigned distance0, distance1;
510 distance0 =
id - center;
511 distance1 = nWires - distance0;
513 distance1 = center - id;
514 distance0 = nWires - distance1;
517 if (distance0 < distance1) {
518 if (distance0 > right) right = distance0;
520 if (distance1 > left) left = distance1;
524 return right + left + 1;
530 vector<TRGCDCLink*> a;
532 unsigned n = list.size();
534 else if (n == 2)
return list;
536 const TCCell* w = list[0]->cell();
537 unsigned nWires = w->layer().nCells();
538 unsigned center = w->localId();
544 for (
unsigned i = 1; i < n; i++) {
546 unsigned id = w->localId();
548 unsigned distance0, distance1;
550 distance0 =
id - center;
551 distance1 = nWires - distance0;
553 distance1 = center - id;
554 distance0 = nWires - distance1;
557 if (distance0 < distance1) {
558 if (distance0 > right) {
563 if (distance1 > left) {
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]);
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]);
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]);
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]);
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;
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]);
640 inners.insert(inners.end(), outers.begin(), outers.end());
648 unsigned n = list.size();
649 for (
unsigned i = 0; i < n; i++)
650 sl |= (1 << (list[i]->
cell()->superLayerId()));
658 unsigned n = links.size();
659 for (
unsigned i = 0; i < n; i++)
662 for (
unsigned i = 0; i <
_nSL; i++)
672 unsigned n = list.size();
673 for (
unsigned i = 0; i < n; i++) {
674 unsigned id = list[i]->cell()->superLayerId();
679 for (
unsigned i = 0; i <
_nSL; i++) {
680 if (l0 & (1 << i)) ++l;
689 unsigned n = links.size();
690 for (
unsigned i = 0; i < n; i++)
693 for (
unsigned i = 0; i <
_nSL; i++)
703 const unsigned n = links.size();
705 for (
unsigned i = 0; i < n; i++)
706 if (links[i]->
cell()->axial())
707 ++
_nHitsSL[links[i]->cell()->axialStereoSuperLayerId()];
711 unsigned nMissing = 0;
713 for (
unsigned i = j; i <
_nSLA; i++) {
716 if (nMax < nMissing) nMax = nMissing;
727 const vector<const Belle2::TRGCDCTrackMC*> list =
729 unsigned nHep = list.size();
731 if (! nHep)
return * best;
734 if (NULL == (N = (
unsigned*) malloc(nHep *
sizeof(
unsigned)))) {
738 for (
unsigned i = 0; i < nHep; i++) N[i] = 0;
749 for (
unsigned i = 0; i < nHep; i++) {
764 const unsigned nLinks = links.size();
765 for (
unsigned i = 0; i < nLinks; i++)
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 +=
"-";
786 const vector<TRGCDCLink*>& links)
788 const unsigned n = list.size();
789 const unsigned m = links.size();
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())
797 cout <<
"TCLink::remove !!! not implemented yet" << endl;
807 static bool first =
true;
811 _nSL = cdc.nSuperLayers();
812 _nSLA = cdc.nAxialSuperLayers();
821 vector<TRGCDCLink*>* layers)
823 for (
unsigned i = 0; i < links.size(); i++) {
824 const TCCell* c = links[i]->cell();
826 unsigned lid = c->layer().id();
828 layers[lid].push_back(links[i]);
857 TRGCDCLink::operator
new(
size_t size)
859 void* p = malloc(size);
870 TRGCDCLink::operator
delete(
void* t)
872 for (vector<TRGCDCLink*>::iterator it = _all.begin();
virtual std::string name(void) const =0
returns name.
A class to relate TRGCDCCellHit and TRGCDCTrack objects.
HepGeom::Point3D< double > _arcZ[4]
arcZ
int _zStatus
z status of stereo
const TRGCDCCellHit * _hit
Cell hit object.
float _drift[2]
drift distance
TRGCDCLink * _neighbor[7]
neighbor TRGCDCLink
float _dDrift[2]
drift distance error
A class to represent a GEN_HEPEVT particle in tracking.
A class to represent a wire in CDC.
The instance of TRGCDC is a singleton.
const TRGCDCWire * wire(void) const
returns a pointer to a wire.
float drift(void) const
returns drift distance.
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'.
static const TRGCDCTrackMC & links2HEP(const std::vector< TRGCDCLink * > &links)
returns TRGCDCTrackMC
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
virtual const TRGCDCCell & cell(void) const
returns a pointer to a TRGCDCWire.
virtual ~TRGCDCLink()
Destructor.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
const TRGCDCCell * cell(void) const
returns a pointer to a cell.
static std::vector< TRGCDCLink * > inOut(const std::vector< TRGCDCLink * > &)
returns links which are in the inner most and outer most layer.
static std::vector< TRGCDCLink * > edges(const std::vector< TRGCDCLink * > &)
returns links which are edges.
static TRGCDCLink * outerMost(const std::vector< TRGCDCLink * > &links)
returns the outer-most link.
const HepGeom::Point3D< double > & position(void) const
returns position.
unsigned layerId(void) const
returns layer id.
static unsigned width(const std::vector< TRGCDCLink * > &)
returns width(wire cell unit) of given std::vector<TRGCDCLink *>.
static TRGCDCLink * innerMost(const std::vector< TRGCDCLink * > &links)
returns the inner-most link.
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'.
static unsigned superLayer(const std::vector< TRGCDCLink * > &list)
returns super layer pattern.
unsigned superLayerId(void) const
returns super layer id.
static void clearBufferSL(void)
clear buffers
const TRGCDCCellHit * hit(void) const
returns a pointer to a hit.
static int sortByX(const TRGCDCLink *a, const TRGCDCLink *b)
sorts by X position.
static unsigned _nSL
...Buffers...
static void separateCores(const std::vector< TRGCDCLink * > &input, std::vector< TRGCDCLink * > &cores, std::vector< TRGCDCLink * > &nonCores)
separate cores and non-cores.
static bool sortById(const TRGCDCLink *a, const TRGCDCLink *b)
sorts by ID.
static TRGCDCTrackMC * _undefined
returns a pointer to gen_hepevt.
static unsigned nMissingAxialSuperLayers(const std::vector< TRGCDCLink * > &links)
returns # of missing axial super layers.
static void removeAll(void)
destructs all TRGCDCLink objects. (Called by TRGCDC)
static std::vector< TRGCDCLink * > _all
Keeps all TRGCDCLinks created by new().
TRGCDCLink * link(void) const
returns a pointer to a TRGCDCLink.
unsigned nSuperLayers(void) const
returns # of super layers.
static void remove(std::vector< TRGCDCLink * > &list, const std::vector< TRGCDCLink * > &links)
removes links from list if wire is same
static unsigned nSuperLayers(const std::vector< TRGCDCLink * > &links)
returns # of layers.
static void nHits(const std::vector< TRGCDCLink * > &links, unsigned *nHits)
returns # of hits per layer.
static std::vector< TRGCDCLink * > stereoHits(const std::vector< TRGCDCLink * > &links)
returns stereo hits.
double pull(void) const
returns pull.
static std::vector< TRGCDCLink * > axialHits(const std::vector< TRGCDCLink * > &links)
returns axial hits.
void dump_base(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
static std::string layerUsage(const std::vector< TRGCDCLink * > &links)
usage of each layer
static unsigned nLayers(const std::vector< TRGCDCLink * > &links)
returns # of layers.
static bool ms_smallcell
ms_smallcell
static std::vector< TRGCDCLink * > cores(const std::vector< TRGCDCLink * > &input)
separate cores and non-cores.
static void initializeBuffers(void)
initialize the Buffers
static unsigned nAxialHits(const std::vector< TRGCDCLink * > &links)
returns # of axial hits.
unsigned leftRight(void) const
returns left-right. 0:left, 1:right, 2:wire
static unsigned _nL
...Buffers...
static unsigned * _nHitsSL
...Buffers...
unsigned state(void) const
returns state.
static unsigned nStereoHits(const std::vector< TRGCDCLink * > &links)
returns # of stereo hits.
static void nHitsSuperLayer(const std::vector< TRGCDCLink * > &links, unsigned *nHits)
returns # of hits per super layer.
static void separate(const std::vector< TRGCDCLink * > &links, unsigned nLayers, std::vector< TRGCDCLink * > *layers)
separates into layers.
static std::vector< const TRGCDCTrackMC * > list(void)
returns a list of TRGCDCTrackMC's.
static unsigned _nSLA
...Buffers...
Abstract base class for different kinds of events.