Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:20

0001 #include "DataFormats/TrackerRecHit2D/interface/TrackerSingleRecHit.h"
0002 #include <iostream>
0003 #include <typeinfo>
0004 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
0005 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
0006 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
0007 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
0008 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
0009 
0010 //#define DO_INTERNAL_CHECKS
0011 #if defined(DO_INTERNAL_CHECKS)
0012 namespace {
0013 
0014   void verify(OmniClusterRef const ref) {
0015     std::cout << ref.rawIndex() << " " << ref.isValid() << " " << ref.isPixel() << " " << ref.isStrip() << " " <<
0016         //      ref.isRegional() << " " <<
0017         ref.cluster_strip().isNull() << " " << ref.cluster_pixel().isNull() << " " << std::endl;
0018   }
0019 
0020   void verify(TrackingRecHit const *thit) {
0021     static bool once = true;
0022     if (once) {
0023       once = false;
0024       DetId Lim(DetId::Tracker, 3);
0025       std::cout << "detid lim " << (Lim.rawId() >> (DetId::kSubdetOffset)) << std::endl;
0026     }
0027     int id = thit->geographicalId().rawId();
0028     int subd = thit->geographicalId().rawId() >> (DetId::kSubdetOffset);
0029 
0030     if (trackerHitRTTI::isNotFromDet(*thit)) {
0031       static int n = 0;
0032       if (++n < 5) {
0033         std::cout << "NotFromDet:" << subd << " " << (id & 3) << " " << thit->dimension() << ". " << std::endl;
0034       }
0035       return;
0036     }
0037 
0038     TrackerSingleRecHit const *hit = dynamic_cast<TrackerSingleRecHit const *>(thit);
0039     BaseTrackerRecHit const *bhit = dynamic_cast<BaseTrackerRecHit const *>(thit);
0040     if (!bhit)
0041       std::cout << "not a tracker hit! " << typeid(*thit).name() << std::endl;
0042 
0043     if (trackerHitRTTI::isUndef(*thit))
0044       std::cout << "undef hit! " << typeid(*thit).name() << std::endl;
0045 
0046     if (dynamic_cast<SiPixelRecHit const *>(hit)) {
0047       static int n = 0;
0048       if (++n < 5) {
0049         std::cout << "Pixel:" << subd << " " << bhit->isSingle() << ". ";
0050         verify(hit->omniCluster());
0051       }
0052     }
0053     if (dynamic_cast<SiStripRecHit1D const *>(hit)) {
0054       static int n = 0;
0055       if (++n < 5) {
0056         std::cout << "Strip1D:" << subd << " " << (id & 3) << " " << bhit->isSingle() << ". ";
0057         verify(hit->omniCluster());
0058       }
0059     }
0060     if (dynamic_cast<SiStripRecHit2D const *>(hit)) {
0061       static int n = 0;
0062       if (++n < 5) {
0063         std::cout << "Strip2D:" << subd << " " << (id & 3) << " " << bhit->isSingle() << ". ";
0064         verify(hit->omniCluster());
0065       }
0066     }
0067     if (dynamic_cast<SiStripMatchedRecHit2D const *>(thit)) {
0068       static int n = 0;
0069       if (++n < 5) {
0070         std::cout << "Strip Matched:" << subd << " " << (id & 3) << " " << bhit->isMatched() << ". " << std::endl;
0071         // verify(hit->omniCluster());
0072       }
0073     }
0074     if (dynamic_cast<ProjectedSiStripRecHit2D const *>(thit)) {
0075       static int n = 0;
0076       if (++n < 5) {
0077         std::cout << "Strip Matched:" << subd << " " << (id & 3) << " " << bhit->isProjected() << ". " << std::endl;
0078         // verify(hit->omniCluster());
0079       }
0080     }
0081   }
0082 
0083   void problem(const TrackingRecHit *thit, const char *what) {
0084     std::cout << "not sharing with itself! " << what << " " << typeid(*thit).name() << std::endl;
0085     verify(thit);
0086   }
0087 
0088   bool doingCheck = false;
0089   inline void checkSelf(const TrackingRecHit *one, const TrackingRecHit *two) {
0090     doingCheck = true;
0091     if (!one->sharesInput(one, TrackingRecHit::all))
0092       problem(one, "all");
0093     if (!one->sharesInput(one, TrackingRecHit::some))
0094       problem(one, "some");
0095     if (!two->sharesInput(two, TrackingRecHit::all))
0096       problem(two, "all");
0097     if (!two->sharesInput(two, TrackingRecHit::some))
0098       problem(two, "some");
0099     doingCheck = false;
0100   }
0101 }  // namespace
0102 #endif
0103 
0104 bool TrackerSingleRecHit::sharesInput(const TrackingRecHit *other, SharedInputType what) const {
0105 #if defined(DO_INTERNAL_CHECKS)
0106   verify(this);
0107   verify(other);
0108   if (!doingCheck && (other != this))
0109     checkSelf(this, other);
0110 #endif
0111 
0112   if (!sameDetModule(*other))
0113     return false;
0114 
0115   // move to switch?
0116   if (trackerHitRTTI::isSingleType(*other)) {
0117     const TrackerSingleRecHit &otherCast = static_cast<const TrackerSingleRecHit &>(*other);
0118     return sharesInput(otherCast);
0119   }
0120 
0121   if (trackerHitRTTI::isMatched(*other)) {
0122     if (what == all)
0123       return false;
0124     return static_cast<SiStripMatchedRecHit2D const &>(*other).sharesInput(*this);
0125   }
0126 
0127   // last resort, recur to 'recHits()', even if it returns a vector by value
0128   std::vector<const TrackingRecHit *> otherHits = other->recHits();
0129   int ncomponents = otherHits.size();
0130   if (ncomponents == 0)
0131     return false;  //bho
0132   if (ncomponents == 1)
0133     return sharesInput(otherHits.front(), what);
0134   // ncomponents>1
0135   if (what == all)
0136     return false;
0137 
0138   for (int i = 0; i < ncomponents; i++) {
0139     if (sharesInput(otherHits[i], what))
0140       return true;
0141   }
0142   return false;
0143 }
0144 
0145 // a simple hit has no components
0146 std::vector<const TrackingRecHit *> TrackerSingleRecHit::recHits() const {
0147   std::vector<const TrackingRecHit *> nullvector;
0148   return nullvector;
0149 }
0150 std::vector<TrackingRecHit *> TrackerSingleRecHit::recHits() {
0151   std::vector<TrackingRecHit *> nullvector;
0152   return nullvector;
0153 }