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  TrackerSingleRecHit const * hit= dynamic_cast<TrackerSingleRecHit const *>(thit);
37  BaseTrackerRecHit const * bhit = dynamic_cast<BaseTrackerRecHit const *>(thit);
38  if (!bhit)
39  std::cout << "not a tracker hit! " << typeid(*thit).name() << std::endl;
40 
41  if (trackerHitRTTI::isUndef(*thit))
42  std::cout << "undef hit! " << typeid(*thit).name() << std::endl;
43 
44  if (dynamic_cast<SiPixelRecHit const *>(hit)) {
45  static int n=0;
46  if (++n<5) {
47  std::cout << "Pixel:" << subd << " " << bhit->isSingle() << ". ";
48  verify(hit->omniCluster());
49  }
50  }
51  if (dynamic_cast<SiStripRecHit1D const *>(hit)) {
52  static int n=0;
53  if (++n<5) {
54  std::cout << "Strip1D:" << subd << " " << (id&3) << " "<< bhit->isSingle() << ". ";
55  verify(hit->omniCluster());
56  }
57  }
58  if (dynamic_cast<SiStripRecHit2D const *>(hit)) {
59  static int n=0;
60  if (++n<5) {
61  std::cout << "Strip2D:" << subd << " " << (id&3) << " "<< bhit->isSingle() << ". ";
62  verify(hit->omniCluster());
63  }
64  }
65  if (dynamic_cast<SiStripMatchedRecHit2D const *>(thit)) {
66  static int n=0;
67  if (++n<5) {
68  std::cout << "Strip Matched:" << subd << " " << (id&3) << " " << bhit->isMatched() << ". " << std::endl;
69  // verify(hit->omniCluster());
70  }
71  }
72  if (dynamic_cast<ProjectedSiStripRecHit2D const *>(thit)) {
73  static int n=0;
74  if (++n<5) {
75  std::cout << "Strip Matched:" << subd << " " << (id&3) << " " << bhit->isProjected() << ". " << std::endl;
76  // verify(hit->omniCluster());
77  }
78  }
79 
80 
81  }
82 
83  void problem(const TrackingRecHit* thit, const char * what) {
84  std::cout << "not sharing with itself! " << what << " "
85  << typeid(*thit).name() << std::endl;
86  verify(thit);
87 
88  }
89 
90  bool doingCheck = false;
91  inline void checkSelf(const TrackingRecHit* one,const TrackingRecHit* two) {
92  doingCheck=true;
93  if (!one->sharesInput(one,TrackingRecHit::all)) problem(one,"all");
94  if (!one->sharesInput(one,TrackingRecHit::some)) problem(one,"some");
95  if (!two->sharesInput(two,TrackingRecHit::all)) problem(two,"all");
96  if (!two->sharesInput(two,TrackingRecHit::some)) problem(two,"some");
97  doingCheck=false;
98  }
99 }
100 #endif
101 
102 bool
104  SharedInputType what) const
105 {
106 #if defined(DO_INTERNAL_CHECKS)
107  verify(this); verify(other);
108  if (!doingCheck && (other!=this)) checkSelf(this,other);
109 #endif
110 
111  if (!sameDetModule(*other)) return false;
112 
113  // move to switch?
114  if (trackerHitRTTI::isSingleType(*other)) {
115  const TrackerSingleRecHit & otherCast = static_cast<const TrackerSingleRecHit&>(*other);
116  return sharesInput(otherCast);
117  }
118 
119  if (trackerHitRTTI::isMatched(*other) ) {
120  if (what == all) return false;
121  return static_cast<SiStripMatchedRecHit2D const &>(*other).sharesInput(*this);
122  }
123 
124  // last resort, recur to 'recHits()', even if it returns a vector by value
125  std::vector<const TrackingRecHit*> otherHits = other->recHits();
126  int ncomponents=otherHits.size();
127  if(ncomponents==0)return false; //bho
128  if(ncomponents==1) return sharesInput(otherHits.front(),what);
129  // ncomponents>1
130  if(what == all )return false;
131 
132  for(int i=0;i<ncomponents;i++){
133  if(sharesInput(otherHits[i],what))return true;
134  }
135  return false;
136 }
137 
138 // a simple hit has no components
139 std::vector<const TrackingRecHit*> TrackerSingleRecHit::recHits() const {
140  std::vector<const TrackingRecHit*> nullvector;
141  return nullvector;
142 }
143 std::vector<TrackingRecHit*> TrackerSingleRecHit::recHits() {
144  std::vector<TrackingRecHit*> nullvector;
145  return nullvector;
146 }
147 
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:47
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)
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:250
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