CMS 3D CMS Logo

TrackerSingleRecHit.cc
Go to the documentation of this file.
2 #include <iostream>
3 #include <typeinfo>
9 
10 //#define DO_INTERNAL_CHECKS
11 #if defined(DO_INTERNAL_CHECKS)
12 namespace {
13 
14  void verify(OmniClusterRef const ref) {
15  std::cout <<
16  ref.rawIndex() << " " <<
17  ref.isValid() << " " <<
18  ref.isPixel() << " " <<
19  ref.isStrip() << " " <<
20 // ref.isRegional() << " " <<
21  ref.cluster_strip().isNull() << " " <<
22  ref.cluster_pixel().isNull() << " " << std::endl;
23  }
24 
25  void verify(TrackingRecHit const * thit) {
26 
27  static bool once=true;
28  if (once) {
29  once=false;
30  DetId Lim(DetId::Tracker,3);
31  std::cout << "detid lim " << (Lim.rawId() >> (DetId::kSubdetOffset)) << std::endl;
32  }
33  int id = thit->geographicalId().rawId();
34  int subd = thit->geographicalId().rawId() >> (DetId::kSubdetOffset);
35 
36  if (trackerHitRTTI::isNotFromDet(*thit)) {
37  static int n=0;
38  if (++n<5) {
39  std::cout << "NotFromDet:" << subd << " " << (id&3) << " "<< thit->dimension() << ". " << std::endl;
40  }
41  return;
42  }
43 
44  TrackerSingleRecHit const * hit= dynamic_cast<TrackerSingleRecHit const *>(thit);
45  BaseTrackerRecHit const * bhit = dynamic_cast<BaseTrackerRecHit const *>(thit);
46  if (!bhit)
47  std::cout << "not a tracker hit! " << typeid(*thit).name() << std::endl;
48 
49  if (trackerHitRTTI::isUndef(*thit))
50  std::cout << "undef hit! " << typeid(*thit).name() << std::endl;
51 
52  if (dynamic_cast<SiPixelRecHit const *>(hit)) {
53  static int n=0;
54  if (++n<5) {
55  std::cout << "Pixel:" << subd << " " << bhit->isSingle() << ". ";
56  verify(hit->omniCluster());
57  }
58  }
59  if (dynamic_cast<SiStripRecHit1D const *>(hit)) {
60  static int n=0;
61  if (++n<5) {
62  std::cout << "Strip1D:" << subd << " " << (id&3) << " "<< bhit->isSingle() << ". ";
63  verify(hit->omniCluster());
64  }
65  }
66  if (dynamic_cast<SiStripRecHit2D const *>(hit)) {
67  static int n=0;
68  if (++n<5) {
69  std::cout << "Strip2D:" << subd << " " << (id&3) << " "<< bhit->isSingle() << ". ";
70  verify(hit->omniCluster());
71  }
72  }
73  if (dynamic_cast<SiStripMatchedRecHit2D const *>(thit)) {
74  static int n=0;
75  if (++n<5) {
76  std::cout << "Strip Matched:" << subd << " " << (id&3) << " " << bhit->isMatched() << ". " << std::endl;
77  // verify(hit->omniCluster());
78  }
79  }
80  if (dynamic_cast<ProjectedSiStripRecHit2D const *>(thit)) {
81  static int n=0;
82  if (++n<5) {
83  std::cout << "Strip Matched:" << subd << " " << (id&3) << " " << bhit->isProjected() << ". " << std::endl;
84  // verify(hit->omniCluster());
85  }
86  }
87 
88 
89  }
90 
91  void problem(const TrackingRecHit* thit, const char * what) {
92  std::cout << "not sharing with itself! " << what << " "
93  << typeid(*thit).name() << std::endl;
94  verify(thit);
95 
96  }
97 
98  bool doingCheck = false;
99  inline void checkSelf(const TrackingRecHit* one,const TrackingRecHit* two) {
100  doingCheck=true;
101  if (!one->sharesInput(one,TrackingRecHit::all)) problem(one,"all");
102  if (!one->sharesInput(one,TrackingRecHit::some)) problem(one,"some");
103  if (!two->sharesInput(two,TrackingRecHit::all)) problem(two,"all");
104  if (!two->sharesInput(two,TrackingRecHit::some)) problem(two,"some");
105  doingCheck=false;
106  }
107 }
108 #endif
109 
110 bool
112  SharedInputType what) const
113 {
114 #if defined(DO_INTERNAL_CHECKS)
115  verify(this); verify(other);
116  if (!doingCheck && (other!=this)) checkSelf(this,other);
117 #endif
118 
119  if (!sameDetModule(*other)) return false;
120 
121  // move to switch?
122  if (trackerHitRTTI::isSingleType(*other)) {
123  const TrackerSingleRecHit & otherCast = static_cast<const TrackerSingleRecHit&>(*other);
124  return sharesInput(otherCast);
125  }
126 
127  if (trackerHitRTTI::isMatched(*other) ) {
128  if (what == all) return false;
129  return static_cast<SiStripMatchedRecHit2D const &>(*other).sharesInput(*this);
130  }
131 
132  // last resort, recur to 'recHits()', even if it returns a vector by value
133  std::vector<const TrackingRecHit*> otherHits = other->recHits();
134  int ncomponents=otherHits.size();
135  if(ncomponents==0)return false; //bho
136  if(ncomponents==1) return sharesInput(otherHits.front(),what);
137  // ncomponents>1
138  if(what == all )return false;
139 
140  for(int i=0;i<ncomponents;i++){
141  if(sharesInput(otherHits[i],what))return true;
142  }
143  return false;
144 }
145 
146 // a simple hit has no components
147 std::vector<const TrackingRecHit*> TrackerSingleRecHit::recHits() const {
148  std::vector<const TrackingRecHit*> nullvector;
149  return nullvector;
150 }
151 std::vector<TrackingRecHit*> TrackerSingleRecHit::recHits() {
152  std::vector<TrackingRecHit*> nullvector;
153  return nullvector;
154 }
155 
SharedInputType
definition of equality via shared input
unsigned int rawIndex() const
bool isStrip() const
bool isSingleType(TrackingRecHit const &hit)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
virtual bool sharesInput(const TrackingRecHit *other, SharedInputType what) const
static const int kSubdetOffset
Definition: DetId.h:23
bool sharesInput(const TrackingRecHit *other, SharedInputType what) const final
bool sameDetModule(TrackingRecHit const &hit) const
ClusterPixelRef cluster_pixel() const
bool isValid() const
virtual std::vector< const TrackingRecHit * > recHits() const =0
Access to component RecHits (if any)
virtual int dimension() const =0
ClusterStripRef cluster_strip() const
OmniClusterRef const & omniCluster() const
bool isMatched(TrackingRecHit const &hit)
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
bool isPixel() const
bool isNull() const
Checks for null.
Definition: Ref.h:248
Definition: DetId.h:18
bool isProjected() const
bool isMatched() const
bool isUndef(TrackingRecHit const &hit)
bool sharesInput(const TrackingRecHit *other, SharedInputType what) const override
DetId geographicalId() const
bool isSingle() const