CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/Alignment/OfflineValidation/plugins/ResidualRefitting.h

Go to the documentation of this file.
00001 #ifndef _ResidualRefitting_h__
00002 #define __ResidualRefitting_h_ (1)
00003 
00004 
00005 #include <vector>
00006 #include <string>
00007 
00008 #include "TFile.h"
00009 #include "TBranch.h"
00010 #include "TTree.h"
00011 
00012 #include "DataFormats/Common/interface/Handle.h"
00013 #include "DataFormats/MuonReco/interface/Muon.h"
00014 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00015 #include "DataFormats/TrackReco/interface/Track.h"
00016 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00017 
00018 #include "FWCore/Framework/interface/EDAnalyzer.h"
00019 #include "FWCore/Utilities/interface/InputTag.h"
00020 
00021 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00022 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00023 
00024 #include "MagneticField/Engine/interface/MagneticField.h"
00025 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00026 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00027 //#include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
00028 //#include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
00029 
00030 //#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00031 
00032 //#include "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
00033 
00034 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00035 //#include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00036 //#include "TrackingTools/TrackRefitter/interface/TrackTransformer.h"
00037 
00038 class ResidualRefitting : public edm::EDAnalyzer{
00039 
00040         static const int N_MAX_STORED = 10;
00041         static const int N_MAX_STORED_HIT = 1000;
00042 
00043         static const int PXB = 1;
00044         static const int PXF = 2;
00045         static const int TIB = 3;
00046         static const int TID = 4;
00047         static const int TOB = 5;
00048         static const int TEC = 6;
00049         
00050 
00051  public:
00052 
00053 //      typedef std::pair<const Trajectory*, const reco::Track*> ConstTrajTrackPair;
00054 //      typedef std::vector< ConstTrajTrackPair >  ConstTrajTrackPairCollection;
00055 
00056         typedef struct {
00057                 int evtNum_;
00058                 int runNum_;
00059         } storage_event;
00060 
00061         ResidualRefitting::storage_event eventInfo_;
00062 
00063  
00064         typedef struct StorageMuon {
00065 
00066                 int n_;
00067     
00068                 int     charge_         [N_MAX_STORED];
00069                 float   pt_             [N_MAX_STORED];
00070                 float   eta_            [N_MAX_STORED];
00071                 float   p_              [N_MAX_STORED];
00072                 float   phi_            [N_MAX_STORED];
00073                 int     numRecHits_     [N_MAX_STORED];
00074                 float   chiSq_          [N_MAX_STORED];
00075                 float   ndf_            [N_MAX_STORED];
00076                 float   chiSqOvrNdf_    [N_MAX_STORED];
00077 
00078                 StorageMuon() :
00079                   n_(0) {
00080                   for (int i=0;i<N_MAX_STORED;++i) {
00081                     charge_[i] = 0;
00082                     pt_[i] = 0.;
00083                     eta_[i] = 0.;
00084                     p_[i] = 0.;
00085                     phi_[i] = 0.;
00086                     numRecHits_[i] = 0;
00087                     chiSq_[i] = 0.;
00088                     ndf_[i] = 0.;
00089                     chiSqOvrNdf_[i] = 0.;
00090                   }
00091                 }
00092         } storage_muon; // Storage for standard muon information
00093 
00094         typedef struct StorageHit {
00095         
00096                 int n_;
00097                 int muonLink_           [N_MAX_STORED_HIT];
00098                 
00099                 int system_             [N_MAX_STORED_HIT];
00100                 int endcap_             [N_MAX_STORED_HIT];
00101                 int station_            [N_MAX_STORED_HIT];
00102                 int ring_               [N_MAX_STORED_HIT];
00103                 int chamber_            [N_MAX_STORED_HIT];
00104                 int layer_              [N_MAX_STORED_HIT];
00105                 int superLayer_         [N_MAX_STORED_HIT];
00106                 int wheel_              [N_MAX_STORED_HIT];
00107                 int sector_             [N_MAX_STORED_HIT];
00108                 
00109                 float   gpX_            [N_MAX_STORED_HIT];
00110                 float   gpY_            [N_MAX_STORED_HIT];
00111                 float   gpZ_            [N_MAX_STORED_HIT];
00112                 float   gpEta_          [N_MAX_STORED_HIT];
00113                 float   gpPhi_          [N_MAX_STORED_HIT];
00114                 float   lpX_            [N_MAX_STORED_HIT];
00115                 float   lpY_            [N_MAX_STORED_HIT];
00116                 float   lpZ_            [N_MAX_STORED_HIT];
00117                 
00118                 StorageHit() :
00119                   n_(0) {
00120                   for (int i=0;i<N_MAX_STORED_HIT;++i) {
00121                     muonLink_[i] = 0;
00122                     system_[i] = 0;
00123                     endcap_[i] = 0;
00124                     station_[i] = 0;
00125                     ring_[i] = 0;
00126                     chamber_[i] = 0;
00127                     layer_[i] = 0;
00128                     superLayer_[i] = 0;
00129                     wheel_[i] = 0;
00130                     sector_[i] = 0;
00131                     gpX_[i] = 0.;
00132                     gpY_[i] = 0.;
00133                     gpZ_[i] = 0.;
00134                     gpEta_[i] = 0.;
00135                     gpPhi_[i] = 0.;
00136                     lpX_[i] = 0.;
00137                     lpY_[i] = 0.;
00138                     lpZ_[i] = 0.;                   
00139                   }
00140                 }
00141         } storage_hit;
00142 
00143         typedef struct StorageTrackExtrap {
00144         
00145                 int n_;
00146                 
00147                 int muonLink_           [N_MAX_STORED_HIT];
00148                 int recLink_            [N_MAX_STORED_HIT];
00149                 float gpX_                      [N_MAX_STORED_HIT];
00150                 float gpY_                      [N_MAX_STORED_HIT];
00151                 float gpZ_                      [N_MAX_STORED_HIT];
00152                 float gpEta_            [N_MAX_STORED_HIT];
00153                 float gpPhi_            [N_MAX_STORED_HIT];
00154                 float lpX_                      [N_MAX_STORED_HIT];
00155                 float lpY_                      [N_MAX_STORED_HIT];
00156                 float lpZ_                      [N_MAX_STORED_HIT];
00157                 float resX_                     [N_MAX_STORED_HIT];
00158                 float resY_                     [N_MAX_STORED_HIT];
00159                 float resZ_                     [N_MAX_STORED_HIT];
00160 
00161                 StorageTrackExtrap() :
00162                   n_(0) {
00163                   for (int i=0;i<N_MAX_STORED_HIT;++i) {
00164                     muonLink_[i] = 0;
00165                     recLink_[i] = 0;
00166                     gpX_[i] = 0.;
00167                     gpY_[i] = 0.;
00168                     gpZ_[i] = 0.;
00169                     gpEta_[i] = 0.;
00170                     gpPhi_[i] = 0.;
00171                     lpX_[i] = 0.;
00172                     lpY_[i] = 0.;
00173                     lpZ_[i] = 0.;
00174                     resX_[i] = 0.;
00175                     resY_[i] = 0.;
00176                     resZ_[i] = 0.;
00177                   }
00178                 }
00179         } storage_trackExtrap;
00180                 
00181         typedef struct StorageTrackHit {
00182         
00183                 int n_;
00184                 
00185                 int muonLink_   [N_MAX_STORED_HIT];
00186                 int detector_   [N_MAX_STORED_HIT];
00187                 int subdetector_[N_MAX_STORED_HIT];
00188                 int blade_              [N_MAX_STORED_HIT];
00189                 int disk_               [N_MAX_STORED_HIT];
00190                 int ladder_             [N_MAX_STORED_HIT];
00191                 int layer_              [N_MAX_STORED_HIT];
00192                 int module_             [N_MAX_STORED_HIT];
00193                 int panel_              [N_MAX_STORED_HIT];
00194                 int ring_               [N_MAX_STORED_HIT];
00195                 int side_               [N_MAX_STORED_HIT];
00196                 int wheel_              [N_MAX_STORED_HIT];
00197                                 
00198                 float gpX_              [N_MAX_STORED_HIT];
00199                 float gpY_              [N_MAX_STORED_HIT];
00200                 float gpZ_              [N_MAX_STORED_HIT];
00201                 float gpEta_    [N_MAX_STORED_HIT];
00202                 float gpPhi_    [N_MAX_STORED_HIT];
00203                 float lpX_              [N_MAX_STORED_HIT];
00204                 float lpY_              [N_MAX_STORED_HIT];
00205                 float lpZ_              [N_MAX_STORED_HIT];
00206                                 
00207                 StorageTrackHit() :
00208                   n_(0) {
00209                   for (int i=0;i<N_MAX_STORED_HIT;++i) {
00210                     muonLink_[i] = 0;
00211                     detector_[i] = 0;
00212                     subdetector_[i] = 0;
00213                     blade_[i] = 0;
00214                     disk_[i] = 0;
00215                     ladder_[i] = 0;
00216                     layer_[i] = 0;
00217                     module_[i] = 0;
00218                     panel_[i] = 0;
00219                     ring_[i] = 0;
00220                     side_[i] = 0;
00221                     wheel_[i] = 0;
00222                     gpX_[i] = 0.;
00223                     gpY_[i] = 0.;
00224                     gpZ_[i] = 0.;
00225                     gpEta_[i] = 0.;
00226                     gpPhi_[i] = 0.;
00227                     lpX_[i] = 0.;
00228                     lpY_[i] = 0.;
00229                     lpZ_[i] = 0.;
00230                   }
00231                 }
00232         } storage_trackHit;
00233                 
00234 //Standard Muon info storage
00235         ResidualRefitting::storage_muon
00236          storageGmrOld_  ,      
00237          storageGmrNew_  , storageSamNew_       , storageTrkNew_,
00238          storageGmrNoSt1_, storageSamNoSt1_     ,
00239          storageGmrNoSt2_, storageSamNoSt2_     ,
00240          storageGmrNoSt3_, storageSamNoSt3_     ,
00241          storageGmrNoSt4_, storageSamNoSt4_     ,
00242          
00243          storageGmrNoPXBLayer1, storageGmrNoPXBLayer2, storageGmrNoPXBLayer3, 
00244          storageTrkNoPXBLayer1, storageTrkNoPXBLayer2, storageTrkNoPXBLayer3,           
00245 
00246          storageGmrNoPXF, storageTrkNoPXF,
00247 
00248          storageGmrNoTIBLayer1, storageGmrNoTIBLayer2, storageGmrNoTIBLayer3, storageGmrNoTIBLayer4, 
00249          storageTrkNoTIBLayer1, storageTrkNoTIBLayer2, storageTrkNoTIBLayer3, storageTrkNoTIBLayer4, 
00250          storageGmrNoTID, storageTrkNoTID,
00251          storageGmrNoTOBLayer1, storageGmrNoTOBLayer2, storageGmrNoTOBLayer3, storageGmrNoTOBLayer4, storageGmrNoTOBLayer5, storageGmrNoTOBLayer6,
00252          storageTrkNoTOBLayer1, storageTrkNoTOBLayer2, storageTrkNoTOBLayer3, storageTrkNoTOBLayer4, storageTrkNoTOBLayer5, storageTrkNoTOBLayer6,
00253          storageGmrNoTEC, storageTrkNoTEC;      
00254          
00255          
00256          
00257 //Rec hit storage        
00258         ResidualRefitting::storage_hit                  storageRecMuon_;
00259         ResidualRefitting::storage_trackHit     storageTrackHit_;
00260 
00261 //Track Extrapolation to Muon System
00262         ResidualRefitting::storage_trackExtrap          storageTrackExtrapRec_, storageTrackExtrapRecNoSt1_,
00263                                                                                         storageTrackExtrapRecNoSt2_, storageTrackExtrapRecNoSt3_, storageTrackExtrapRecNoSt4_;
00264 
00265 //Track Extrapolation with Cylinder
00266     ResidualRefitting::storage_trackExtrap              trackExtrap120_, samExtrap120_;
00267    
00268 //Track Extrapolation to Tracker system
00269         ResidualRefitting::storage_trackExtrap          storageTrackExtrapTracker_,
00270                         storageTrackNoPXBLayer1, storageTrackNoPXBLayer2, storageTrackNoPXBLayer3,
00271                         storageTrackNoPXF,
00272                         storageTrackNoTIBLayer1, storageTrackNoTIBLayer2, storageTrackNoTIBLayer3,storageTrackNoTIBLayer4,
00273                         storageTrackNoTID,
00274                         storageTrackNoTOBLayer1, storageTrackNoTOBLayer2, storageTrackNoTOBLayer3,
00275                         storageTrackNoTOBLayer4, storageTrackNoTOBLayer5, storageTrackNoTOBLayer6,
00276                         storageTrackNoTEC;
00277   
00278 //
00279 // Start of the method declarations
00280 //
00281  
00282         explicit ResidualRefitting( const edm::ParameterSet & );
00283         ~ResidualRefitting();
00284         
00285         virtual void analyze(const edm::Event&, const edm::EventSetup&);
00286         virtual void beginJob() ;
00287         virtual void endJob() ;
00288 //Zero Storage
00289         void zero_storage();
00290         void zero_muon(ResidualRefitting::storage_muon* str);
00291         void zero_trackExtrap(ResidualRefitting::storage_trackExtrap* str);
00292         void branchMuon(ResidualRefitting::storage_muon& storageTmp, std::string branchName);
00293         void branchTrackExtrap(ResidualRefitting::storage_trackExtrap& storageTmp, std::string branchName);
00294         
00295         
00296 
00297 //      void collectTrackRecExtrap(reco::MuonCollection::const_iterator muon, ResidualRefitting::storage_trackExtrap& storeTemp);
00298         void muonInfo(ResidualRefitting::storage_muon& storeMuon, reco::TrackRef muon, int val);
00299         
00300         void CollectTrackHits(edm::Handle<reco::TrackCollection> trackColl, ResidualRefitting::storage_trackExtrap& trackExtrap);
00301         void StoreTrackerRecHits(DetId detid, int iTrack, int iRec);
00302         void NewTrackMeasurements(edm::Handle<reco::TrackCollection> trackCollOrig, edm::Handle<reco::TrackCollection> trackColl,
00303           ResidualRefitting::storage_trackExtrap& trackExtrap);
00304         int MatchTrackWithRecHits(reco::TrackCollection::const_iterator trackIt, edm::Handle<reco::TrackCollection> ref);
00305         
00306         bool IsSameHit(trackingRecHit_iterator hit1, trackingRecHit_iterator hit2);
00307 
00308 
00309         void trkExtrap(const DetId& detid, int iTrkLink, int iTrk, int iRec,
00310                        const FreeTrajectoryState& freeTrajState,
00311                        const LocalPoint& recPoint,
00312                        storage_trackExtrap& storeTemp);
00313         
00314         void cylExtrapTrkSam(int recNum, reco::TrackRef track, ResidualRefitting::storage_trackExtrap& storage, double rho);
00315 
00316 //Simplifiying functions
00317         FreeTrajectoryState freeTrajStateMuon(reco::TrackRef muon);//Returns a Free Trajectory State
00318 //Debug Data Dumps
00319 //      void dumpRecoMuonColl(reco::MuonCollection::const_iterator muon); //
00320 //      void dumpRecoTrack(reco::TrackCollection::const_iterator muon);
00321         void dumpTrackRef(reco::TrackRef muon, std::string str); 
00322         void dumpTrackExtrap(ResidualRefitting::storage_trackExtrap track);
00323         void dumpTrackHits(ResidualRefitting::storage_trackHit hit);
00324         void dumpMuonRecHits(ResidualRefitting::storage_hit hit);
00325 
00326         int ReturnSector(DetId detid);
00327         int ReturnStation(DetId detid);
00328 
00329         
00330 // Deprecated Functions
00331         void omitStation(edm::Handle<reco::MuonCollection> funcMuons, edm::Handle<reco::TrackCollection>,
00332                 ResidualRefitting::storage_muon& storeGmr, ResidualRefitting::storage_muon& storeSam,
00333                 ResidualRefitting::storage_trackExtrap& storeExtrap, int omitStation);
00334         void omitTrackerSystem(edm::Handle<reco::MuonCollection> trkMuons, ResidualRefitting::storage_muon& storeGmr,
00335                 ResidualRefitting::storage_muon& storeTrk,
00336                 ResidualRefitting::storage_trackExtrap& storeExtrap, int omitSystem);
00337       
00338         // output histogram file name
00339         std::string outputFileName_;
00340         //edm::InputTag PropagatorSource_;              
00341         std::string PropagatorSource_;          
00342 
00343         // names of product labels
00344         edm::InputTag tracks_,
00345          muons_, muonsRemake_,
00346          muonsNoStation1_, muonsNoStation2_, muonsNoStation3_,muonsNoStation4_,//Global Muon Collections
00347          muonsNoPXBLayer1_, muonsNoPXBLayer2_, muonsNoPXBLayer3_,
00348          muonsNoPXF_,
00349          muonsNoTIBLayer1_, muonsNoTIBLayer2_, muonsNoTIBLayer3_, muonsNoTIBLayer4_,
00350          muonsNoTID_,
00351          muonsNoTOBLayer1_, muonsNoTOBLayer2_, muonsNoTOBLayer3_, muonsNoTOBLayer4_, muonsNoTOBLayer5_, muonsNoTOBLayer6_,
00352          muonsNoTEC_;
00353 //         tjTag; 
00354 
00355 
00356         bool debug_;
00357 
00358         // output ROOT file
00359         TFile * outputFile_ ;
00360 
00361         TTree   *outputTree_;
00362         TBranch *outputBranch_;
00363 
00364 //      unsigned int nBins_;
00365   
00366         const MagneticField* theField;
00367         const edm::ESHandle<GlobalTrackingGeometry> trackingGeometry;
00368         MuonServiceProxy* theService;
00369         edm::ESHandle<Propagator> thePropagator;
00370   
00371 };
00372 
00373 #endif