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