CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DataFormats/TrackerRecHit2D/src/TrackerSingleRecHit.cc

Go to the documentation of this file.
00001 #include "DataFormats/TrackerRecHit2D/interface/TrackerSingleRecHit.h"
00002 
00003 
00004 
00005 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
00006 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00007 
00008 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
00009 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
00010 #include<iostream>
00011 
00012 namespace {
00013   
00014   void verify(OmniClusterRef const ref) {
00015     std::cout << 
00016       ref.rawIndex() << " " <<
00017       ref.isValid() << " " <<
00018       ref.isPixel() << " " <<
00019       ref.isStrip()  << " " <<
00020       ref.isRegional() << " " <<
00021       ref.cluster_strip().isNull() << " " <<
00022       ref.cluster_pixel().isNull() << " " <<
00023       ref.cluster_regional().isNull()  << " " << std::endl;
00024   }
00025   
00026   void verify(TrackingRecHit const * thit) {
00027 
00028     static bool once=true;
00029     if (once) {
00030       once=false;
00031       DetId Lim(DetId::Tracker,3);
00032       std::cout << "detid lim " << (Lim.rawId() >> (DetId::kSubdetOffset)) << std::endl;
00033     }
00034     int id = thit->geographicalId().rawId();
00035     int subd =   thit->geographicalId().rawId() >> (DetId::kSubdetOffset);
00036     
00037     TrackerSingleRecHit const * hit= dynamic_cast<TrackerSingleRecHit const *>(thit);
00038     BaseTrackerRecHit const * bhit = dynamic_cast<BaseTrackerRecHit const *>(thit);    
00039     if (!bhit)
00040       std::cout << "not a tracker hit! " << typeid(*thit).name() << std::endl;
00041 
00042     if (trackerHitRTTI::isUndef(*thit))
00043       std::cout << "undef hit! " << typeid(*thit).name() << std::endl;
00044     
00045     if (dynamic_cast<SiPixelRecHit const *>(hit)) {
00046       static int n=0;
00047       if (++n<5) {
00048         std::cout << "Pixel:" << subd << " " << bhit->isSingle() << ". ";
00049         verify(hit->omniCluster());
00050       }
00051     }
00052     if (dynamic_cast<SiStripRecHit1D const *>(hit)) {
00053       static int n=0;
00054       if (++n<5) {
00055         std::cout << "Strip1D:" << subd << " " << (id&3) << " "<< bhit->isSingle() << ". ";
00056         verify(hit->omniCluster());
00057       }
00058     }
00059     if (dynamic_cast<SiStripRecHit2D const *>(hit)) {
00060       static int n=0;
00061       if (++n<5) {
00062         std::cout << "Strip2D:" << subd << " " << (id&3) << " "<< bhit->isSingle() << ". ";
00063         verify(hit->omniCluster());
00064       }
00065     }
00066     if (dynamic_cast<SiStripMatchedRecHit2D const *>(thit)) {
00067       static int n=0;
00068       if (++n<5) {
00069         std::cout << "Strip Matched:" << subd << " " << (id&3) << " " << bhit->isMatched() << ". " << std::endl;
00070         // verify(hit->omniCluster());
00071       }
00072     }
00073     if (dynamic_cast<ProjectedSiStripRecHit2D const *>(thit)) {
00074       static int n=0;
00075       if (++n<5) {
00076         std::cout << "Strip Matched:" << subd << " " << (id&3) << " " << bhit->isProjected() << ". " << std::endl;
00077         // verify(hit->omniCluster());
00078       }
00079     }
00080     
00081 
00082   }
00083   
00084   void problem(const TrackingRecHit* thit, const char * what) {
00085     std::cout << "not sharing with itself! " << what << " "
00086               << typeid(*thit).name() << std::endl;
00087     verify(thit);
00088 
00089   }
00090   
00091   bool doingCheck = false;
00092   void checkSelf(const TrackingRecHit* one,const TrackingRecHit* two) {
00093     doingCheck=true;
00094     if (!one->sharesInput(one,TrackingRecHit::all)) problem(one,"all");
00095     if (!one->sharesInput(one,TrackingRecHit::some)) problem(one,"some");
00096     if (!two->sharesInput(two,TrackingRecHit::all)) problem(two,"all");
00097     if (!two->sharesInput(two,TrackingRecHit::some)) problem(two,"some");
00098     doingCheck=false;
00099   }
00100 
00101 }
00102 
00103 bool 
00104 TrackerSingleRecHit::sharesInput( const TrackingRecHit* other, 
00105                               SharedInputType what) const
00106 {
00107   //  verify(this); verify(other);
00108   // if (!doingCheck && (other!=this)) checkSelf(this,other);
00109 
00110 
00111   if (!sameDetModule(*other)) return false;
00112 
00113   // move to switch?
00114   if (trackerHitRTTI::isSingle(*other)) {
00115     const TrackerSingleRecHit & otherCast = static_cast<const TrackerSingleRecHit&>(*other);
00116     return sharesInput(otherCast);
00117   } 
00118 
00119   if (trackerHitRTTI::isProjected(*other)) 
00120     return other->sharesInput(this,what);
00121 
00122   if (trackerHitRTTI::isMatched(*other) ) {
00123     if (what == all) return false;
00124     return static_cast<SiStripMatchedRecHit2D const &>(*other).sharesInput(*this);
00125   }
00126 
00127   // last resort, recur to 'recHits()', even if it returns a vector by value
00128   std::vector<const TrackingRecHit*> otherHits = other->recHits();
00129   int ncomponents=otherHits.size();
00130   if(ncomponents==0)return false; //bho
00131   if(ncomponents==1) return sharesInput(otherHits.front(),what);
00132   // ncomponents>1
00133   if(what == all )return false;
00134 
00135   for(int i=0;i<ncomponents;i++){
00136     if(sharesInput(otherHits[i],what))return true;
00137   }
00138   return false; 
00139 }
00140 
00141 // a simple hit has no components
00142 std::vector<const TrackingRecHit*> TrackerSingleRecHit::recHits() const {
00143   std::vector<const TrackingRecHit*> nullvector;
00144   return nullvector; 
00145 }
00146 std::vector<TrackingRecHit*> TrackerSingleRecHit::recHits() {
00147   std::vector<TrackingRecHit*> nullvector;
00148   return nullvector; 
00149 }
00150