CMS 3D CMS Logo

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