CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/RecoTracker/DebugTools/interface/CkfDebugger.h

Go to the documentation of this file.
00001 #ifndef CkfDebugger_H
00002 #define CkfDebugger_H
00003 
00004 #include "DataFormats/Common/interface/Handle.h"
00005 #include "FWCore/Framework/interface/ESHandle.h"
00006 #include "FWCore/Framework/interface/EventSetup.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00012 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00013 #include "MagneticField/Engine/interface/MagneticField.h"
00014 
00015 #include "SimTracker/TrackerHitAssociation/interface/TrackerHitAssociator.h"
00016 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00017 #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimator.h"
00018 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
00019 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
00020 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00021 #include "TrackingTools/PatternTools/interface/MeasurementExtractor.h"
00022 
00023 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00024 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00025 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00026 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00027 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00028 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00029 
00030 #include <vector>
00031 #include <iostream>
00032 #include <TFile.h>
00033 #include <TH1F.h>
00034 #include <TH2F.h>
00035 
00036 class Trajectory;
00037 class TrajectoryMeasurement;
00038 class PSimHit;
00039 class TransientTrackingRecHit;
00040 class MeasurementTracker;
00041 class TrajectoryStateOnSurface;
00042 class MagneticField;
00043 class Chi2MeasurementEstimator;
00044 class Propagator;
00045 
00046 typedef TransientTrackingRecHit::ConstRecHitPointer CTTRHp;
00047 
00048 class CkfDebugger {
00049  public:
00050   CkfDebugger( edm::EventSetup const & es );
00051 
00052   ~CkfDebugger();
00053   
00054   void printSimHits( const edm::Event& iEvent);
00055 
00056   void countSeed(){totSeeds++;}
00057 
00058   void fillSeedHist(CTTRHp h1,CTTRHp h2, TrajectoryStateOnSurface t) {
00059     //edm::LogVerbatim("CkfDebugger") << "CkfDebugger::fillSeedHist";
00060     hchi2seedAll->Fill( testSeed(h1,h2,t) );
00061   }
00062 
00063   bool analyseCompatibleMeasurements( const Trajectory&,
00064                                       const std::vector<TrajectoryMeasurement>&,
00065                                       const MeasurementTracker*,
00066                                       const Propagator*,
00067                                       const Chi2MeasurementEstimatorBase*,
00068                                       const TransientTrackingRecHitBuilder*);
00069 
00070   void deleteHitAssociator(){
00071     delete hitAssociator;
00072   }
00073 
00074  private:
00075   typedef TrajectoryMeasurement        TM;
00076   typedef TrajectoryStateOnSurface     TSOS;
00077 
00078   class SimHit {
00079   public:
00080 
00081     SimHit( const PSimHit* phit, const GeomDetUnit* gdu) : thePHit( phit), theDet(gdu) {}
00082     LocalPoint localPosition() const {return thePHit->localPosition();}
00083     GlobalPoint globalPosition() const {return theDet->toGlobal( thePHit->localPosition());}
00084     const GeomDetUnit* det() const {return theDet;}
00085     unsigned int trackId()      const {return thePHit->trackId();}
00086     LocalVector  localDirection()  const {return thePHit->localDirection();}
00087     Geom::Theta<float> thetaAtEntry() const {return thePHit->thetaAtEntry();}
00088     Geom::Phi<float>   phiAtEntry()   const {return thePHit->phiAtEntry();}
00089     float        pabs()         const {return thePHit->pabs();}
00090     float        timeOfFlight() const {return thePHit->timeOfFlight();}
00091     float        energyLoss()   const {return thePHit->energyLoss();}
00092     int          particleType() const {return thePHit->particleType();}
00093     unsigned int detUnitId()    const {return thePHit->detUnitId();}
00094     unsigned short processType() const {return thePHit->processType();}
00095     const PSimHit& psimHit() const { return *thePHit;}
00096 
00097   private:
00098 
00099     const PSimHit*     thePHit;
00100     const GeomDetUnit* theDet;
00101 
00102   };
00103 
00104   const TrackerGeometry*           theTrackerGeom;
00105   const MagneticField*             theMagField;
00106   const GeometricSearchTracker*    theGeomSearchTracker;
00107   const MeasurementEstimator*  theChi2;
00108   const Propagator*                theForwardPropagator;
00109   TrackerHitAssociator*      hitAssociator;
00110   const MeasurementTracker*        theMeasurementTracker;
00111   const TransientTrackingRecHitBuilder* theTTRHBuilder;
00112 
00113   std::map<unsigned int, std::vector<PSimHit*> > idHitsMap;
00114 
00115   void dumpSimHit( const SimHit& hit) const;
00116 
00117   bool correctTrajectory( const Trajectory&, unsigned int&) const;
00118 
00119   int assocTrackId(CTTRHp rechit) const;
00120 
00121   //const PSimHit* nextCorrectHit( const Trajectory&, unsigned int&) ;
00122   std::vector<const PSimHit*> nextCorrectHits( const Trajectory&, unsigned int&) ;
00123 
00124   bool associated(CTTRHp rechit, const PSimHit& sh) const;
00125 
00126   bool goodSimHit(const PSimHit& sh) const;
00127 
00128   bool correctMeas( const TM& tm, const PSimHit* correctHit) const;
00129 
00130   std::pair<CTTRHp, double> analyseRecHitExistance( const PSimHit& sh, const TSOS& startingState);
00131 
00132   int analyseRecHitNotFound(const Trajectory&,CTTRHp);
00133 
00134   double testSeed(CTTRHp,CTTRHp, TrajectoryStateOnSurface);
00135 
00136   const PSimHit* pSimHit(unsigned int tkId, DetId detId);
00137 
00138   bool hasDelta(const PSimHit* correctHit){
00139     bool delta = false;
00140     for (std::vector<PSimHit>::iterator isim = hitAssociator->SimHitMap[correctHit->detUnitId()].begin();
00141          isim != hitAssociator->SimHitMap[correctHit->detUnitId()].end(); ++isim){ 
00142 /*       edm::LogVerbatim("CkfDebugger") << "SimHit on this det at pos="<< position(&*isim)  */
00143 /*           << " det=" << isim->detUnitId() << " process=" << isim->processType() ; */
00144       if (isim->processType() == 9) delta = true;
00145     }
00146     return delta;
00147   }
00148 
00149   Global3DPoint position(const PSimHit* sh) const {
00150     return theTrackerGeom->idToDetUnit(DetId(sh->detUnitId()))->toGlobal(sh->localPosition());
00151   };
00152   const GeomDetUnit* det(const PSimHit* sh) const {return theTrackerGeom->idToDetUnit(DetId(sh->detUnitId()));};
00153 
00154   int layer(const GeomDetUnit* det){
00155     //return ((int)(((det->geographicalId().rawId() >>16) & 0xF)));
00156     DetId id=det->geographicalId();
00157     if (id.subdetId()==3) return ((TIBDetId)(id)).layer();
00158     if (id.subdetId()==5) return ((TOBDetId)(id)).layer();
00159     if (id.subdetId()==1) return ((PXBDetId)(id)).layer();
00160     if (id.subdetId()==4) return ((TIDDetId)(id)).wheel();
00161     if (id.subdetId()==6) return ((TECDetId)(id)).wheel();
00162     if (id.subdetId()==2) return ((PXFDetId)(id)).disk();
00163     return 0;
00164   }
00165   int layer(const GeomDet* det){
00166     //return ((int)(((det->geographicalId().rawId() >>16) & 0xF)));
00167     DetId id=det->geographicalId();
00168     if (id.subdetId()==3) return ((TIBDetId)(id)).layer();
00169     if (id.subdetId()==5) return ((TOBDetId)(id)).layer();
00170     if (id.subdetId()==1) return ((PXBDetId)(id)).layer();
00171     if (id.subdetId()==4) return ((TIDDetId)(id)).wheel();
00172     if (id.subdetId()==6) return ((TECDetId)(id)).wheel();
00173     if (id.subdetId()==2) return ((PXFDetId)(id)).disk();
00174     return 0;
00175   }
00176 
00177   template<unsigned int D>  
00178   std::pair<double,double> computePulls(CTTRHp recHit, TSOS startingState){
00179     typedef typename AlgebraicROOTObject<D>::Vector VecD;
00180     typedef typename AlgebraicROOTObject<D,D>::SymMatrix SMatDD;
00181     TSOS detState = theForwardPropagator->propagate(startingState,recHit->det()->surface());
00182     LogTrace("CkfDebugger") << "parameters=" << recHit->parameters() ;
00183     LogTrace("CkfDebugger") << "parametersError=" << recHit->parametersError() ;
00184     MeasurementExtractor me(detState);
00185     VecD r = asSVector<D>(recHit->parameters()) - me.measuredParameters<D>(*recHit);
00186     LogTrace("CkfDebugger") << "me.measuredParameters=" << me.measuredParameters<D>(*recHit) ;
00187     LogTrace("CkfDebugger") << "me.measuredError=" << me.measuredError<D>(*recHit) ;
00188     SMatDD R = asSMatrix<D>(recHit->parametersError()) + me.measuredError<D>(*recHit);
00189     LogTrace("CkfDebugger") << "r=" << r ;
00190     LogTrace("CkfDebugger") << "R=" << R ;
00191     R.Invert();
00192     LogTrace("CkfDebugger") << "R(-1)=" << R ;
00193     LogTrace("CkfDebugger") << "chi2=" << ROOT::Math::Similarity(r,R) ;
00194     double pullX=(-r[0])*sqrt(R(0,0));
00195     double r_1 = 0;
00196     if ( VecD::Dim() >= 2 )
00197       {
00198         r_1 = r[1];
00199       }
00200     double pullY=(-r_1)*sqrt(R(1,1));
00201     LogTrace("CkfDebugger") << "pullX=" << pullX ;
00202     LogTrace("CkfDebugger") << "pullY=" << pullY ;
00203     return  std::pair<double,double>(pullX,pullY);
00204   }
00205   std::pair<double,double> computePulls(CTTRHp recHit, TSOS startingState) {
00206         switch (recHit->dimension()) {
00207                 case 1: return computePulls<1>(recHit,startingState);
00208                 case 2: return computePulls<2>(recHit,startingState);
00209                 case 3: return computePulls<3>(recHit,startingState);
00210                 case 4: return computePulls<4>(recHit,startingState);
00211                 case 5: return computePulls<5>(recHit,startingState);
00212         }
00213         throw cms::Exception("CkfDebugger error: rechit of dimension not 1,2,3,4,5");
00214   }
00215 
00216   std::vector<int> dump;
00217   std::map<std::pair<int,int>, int> dump2;
00218   std::map<std::pair<int,int>, int> dump3;
00219   std::map<std::pair<int,int>, int> dump4;
00220   std::map<std::pair<int,int>, int> dump5;
00221   std::map<std::pair<int,int>, int> dump6;
00222 
00223   TFile*  file;
00224   TH1F* hchi2seedAll, *hchi2seedProb;
00225 
00226   std::map<std::string,TH1F*> hPullX_shrh;
00227   std::map<std::string,TH1F*> hPullY_shrh;
00228   std::map<std::string,TH1F*> hPullX_shst;
00229   std::map<std::string,TH1F*> hPullY_shst;
00230   std::map<std::string,TH1F*> hPullX_strh;
00231   std::map<std::string,TH1F*> hPullY_strh;
00232 
00233   std::map<std::string,TH1F*> hPullM_shrh;
00234   std::map<std::string,TH1F*> hPullS_shrh;
00235   std::map<std::string,TH1F*> hPullM_shst;
00236   std::map<std::string,TH1F*> hPullS_shst;
00237   std::map<std::string,TH1F*> hPullM_strh;
00238   std::map<std::string,TH1F*> hPullS_strh;
00239 
00240   std::map<std::string,TH1F*> hPullGP_X_shst;
00241   std::map<std::string,TH1F*> hPullGP_Y_shst;
00242   std::map<std::string,TH1F*> hPullGP_Z_shst;
00243 
00244   TH2F* hPullGPXvsGPX_shst;
00245   TH2F* hPullGPXvsGPY_shst;
00246   TH2F* hPullGPXvsGPZ_shst;
00247   TH2F* hPullGPXvsGPr_shst;
00248   TH2F* hPullGPXvsGPeta_shst;
00249   TH2F* hPullGPXvsGPphi_shst;
00250 
00251   int seedWithDelta;
00252   int problems;
00253   int no_sim_hit;
00254   int no_layer;
00255   int layer_not_found;
00256   int det_not_found;
00257   int chi2gt30;
00258   int chi2gt30delta;
00259   int chi2gt30deltaSeed;
00260   int chi2ls30;
00261   int simple_hit_not_found;
00262   int no_component;
00263   int only_one_component;
00264   int matched_not_found;
00265   int matched_not_associated;
00266   int partner_det_not_fuond;
00267   int glued_det_not_fuond;
00268   int propagation;
00269   int other;
00270   int totchi2gt30;
00271 
00272   int totSeeds;
00273 };
00274 
00275 class less_mag : public std::binary_function<PSimHit*, PSimHit*, bool> {
00276  public:
00277   less_mag(){ }
00278   bool operator()(const PSimHit* a,const PSimHit* b) { 
00279     return 
00280       ( a->timeOfFlight()< b->timeOfFlight() );
00281   }
00282 };
00283 
00284 #endif