Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:07

0001 #ifndef _ResidualRefitting_h__
0002 #define __ResidualRefitting_h_ (1)
0003 
0004 #include <vector>
0005 #include <string>
0006 
0007 #include "TFile.h"
0008 #include "TBranch.h"
0009 #include "TTree.h"
0010 
0011 #include "DataFormats/Common/interface/Handle.h"
0012 #include "DataFormats/MuonReco/interface/Muon.h"
0013 #include "DataFormats/MuonReco/interface/MuonFwd.h"
0014 #include "DataFormats/TrackReco/interface/Track.h"
0015 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0016 
0017 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0018 #include "FWCore/Utilities/interface/InputTag.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0021 
0022 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0023 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0024 
0025 #include "MagneticField/Engine/interface/MagneticField.h"
0026 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
0027 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0028 
0029 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0030 
0031 class TrackerTopology;
0032 
0033 class ResidualRefitting : public edm::one::EDAnalyzer<> {
0034   static const int N_MAX_STORED = 10;
0035   static const int N_MAX_STORED_HIT = 1000;
0036 
0037   static const int PXB = 1;
0038   static const int PXF = 2;
0039   static const int TIB = 3;
0040   static const int TID = 4;
0041   static const int TOB = 5;
0042   static const int TEC = 6;
0043 
0044 public:
0045   //    typedef std::pair<const Trajectory*, const reco::Track*> ConstTrajTrackPair;
0046   //    typedef std::vector< ConstTrajTrackPair >  ConstTrajTrackPairCollection;
0047 
0048   typedef struct {
0049     int evtNum_;
0050     int runNum_;
0051   } storage_event;
0052 
0053   ResidualRefitting::storage_event eventInfo_;
0054 
0055   typedef struct StorageMuon {
0056     int n_;
0057 
0058     int charge_[N_MAX_STORED];
0059     float pt_[N_MAX_STORED];
0060     float eta_[N_MAX_STORED];
0061     float p_[N_MAX_STORED];
0062     float phi_[N_MAX_STORED];
0063     int numRecHits_[N_MAX_STORED];
0064     float chiSq_[N_MAX_STORED];
0065     float ndf_[N_MAX_STORED];
0066     float chiSqOvrNdf_[N_MAX_STORED];
0067 
0068     StorageMuon() : n_(0) {
0069       for (int i = 0; i < N_MAX_STORED; ++i) {
0070         charge_[i] = 0;
0071         pt_[i] = 0.;
0072         eta_[i] = 0.;
0073         p_[i] = 0.;
0074         phi_[i] = 0.;
0075         numRecHits_[i] = 0;
0076         chiSq_[i] = 0.;
0077         ndf_[i] = 0.;
0078         chiSqOvrNdf_[i] = 0.;
0079       }
0080     }
0081   } storage_muon;  // Storage for standard muon information
0082 
0083   typedef struct StorageHit {
0084     int n_;
0085     int muonLink_[N_MAX_STORED_HIT];
0086 
0087     int system_[N_MAX_STORED_HIT];
0088     int endcap_[N_MAX_STORED_HIT];
0089     int station_[N_MAX_STORED_HIT];
0090     int ring_[N_MAX_STORED_HIT];
0091     int chamber_[N_MAX_STORED_HIT];
0092     int layer_[N_MAX_STORED_HIT];
0093     int superLayer_[N_MAX_STORED_HIT];
0094     int wheel_[N_MAX_STORED_HIT];
0095     int sector_[N_MAX_STORED_HIT];
0096 
0097     float gpX_[N_MAX_STORED_HIT];
0098     float gpY_[N_MAX_STORED_HIT];
0099     float gpZ_[N_MAX_STORED_HIT];
0100     float gpEta_[N_MAX_STORED_HIT];
0101     float gpPhi_[N_MAX_STORED_HIT];
0102     float lpX_[N_MAX_STORED_HIT];
0103     float lpY_[N_MAX_STORED_HIT];
0104     float lpZ_[N_MAX_STORED_HIT];
0105 
0106     StorageHit() : n_(0) {
0107       for (int i = 0; i < N_MAX_STORED_HIT; ++i) {
0108         muonLink_[i] = 0;
0109         system_[i] = 0;
0110         endcap_[i] = 0;
0111         station_[i] = 0;
0112         ring_[i] = 0;
0113         chamber_[i] = 0;
0114         layer_[i] = 0;
0115         superLayer_[i] = 0;
0116         wheel_[i] = 0;
0117         sector_[i] = 0;
0118         gpX_[i] = 0.;
0119         gpY_[i] = 0.;
0120         gpZ_[i] = 0.;
0121         gpEta_[i] = 0.;
0122         gpPhi_[i] = 0.;
0123         lpX_[i] = 0.;
0124         lpY_[i] = 0.;
0125         lpZ_[i] = 0.;
0126       }
0127     }
0128   } storage_hit;
0129 
0130   typedef struct StorageTrackExtrap {
0131     int n_;
0132 
0133     int muonLink_[N_MAX_STORED_HIT];
0134     int recLink_[N_MAX_STORED_HIT];
0135     float gpX_[N_MAX_STORED_HIT];
0136     float gpY_[N_MAX_STORED_HIT];
0137     float gpZ_[N_MAX_STORED_HIT];
0138     float gpEta_[N_MAX_STORED_HIT];
0139     float gpPhi_[N_MAX_STORED_HIT];
0140     float lpX_[N_MAX_STORED_HIT];
0141     float lpY_[N_MAX_STORED_HIT];
0142     float lpZ_[N_MAX_STORED_HIT];
0143     float resX_[N_MAX_STORED_HIT];
0144     float resY_[N_MAX_STORED_HIT];
0145     float resZ_[N_MAX_STORED_HIT];
0146 
0147     StorageTrackExtrap() : n_(0) {
0148       for (int i = 0; i < N_MAX_STORED_HIT; ++i) {
0149         muonLink_[i] = 0;
0150         recLink_[i] = 0;
0151         gpX_[i] = 0.;
0152         gpY_[i] = 0.;
0153         gpZ_[i] = 0.;
0154         gpEta_[i] = 0.;
0155         gpPhi_[i] = 0.;
0156         lpX_[i] = 0.;
0157         lpY_[i] = 0.;
0158         lpZ_[i] = 0.;
0159         resX_[i] = 0.;
0160         resY_[i] = 0.;
0161         resZ_[i] = 0.;
0162       }
0163     }
0164   } storage_trackExtrap;
0165 
0166   typedef struct StorageTrackHit {
0167     int n_;
0168 
0169     int muonLink_[N_MAX_STORED_HIT];
0170     int detector_[N_MAX_STORED_HIT];
0171     int subdetector_[N_MAX_STORED_HIT];
0172     int blade_[N_MAX_STORED_HIT];
0173     int disk_[N_MAX_STORED_HIT];
0174     int ladder_[N_MAX_STORED_HIT];
0175     int layer_[N_MAX_STORED_HIT];
0176     int module_[N_MAX_STORED_HIT];
0177     int panel_[N_MAX_STORED_HIT];
0178     int ring_[N_MAX_STORED_HIT];
0179     int side_[N_MAX_STORED_HIT];
0180     int wheel_[N_MAX_STORED_HIT];
0181 
0182     float gpX_[N_MAX_STORED_HIT];
0183     float gpY_[N_MAX_STORED_HIT];
0184     float gpZ_[N_MAX_STORED_HIT];
0185     float gpEta_[N_MAX_STORED_HIT];
0186     float gpPhi_[N_MAX_STORED_HIT];
0187     float lpX_[N_MAX_STORED_HIT];
0188     float lpY_[N_MAX_STORED_HIT];
0189     float lpZ_[N_MAX_STORED_HIT];
0190 
0191     StorageTrackHit() : n_(0) {
0192       for (int i = 0; i < N_MAX_STORED_HIT; ++i) {
0193         muonLink_[i] = 0;
0194         detector_[i] = 0;
0195         subdetector_[i] = 0;
0196         blade_[i] = 0;
0197         disk_[i] = 0;
0198         ladder_[i] = 0;
0199         layer_[i] = 0;
0200         module_[i] = 0;
0201         panel_[i] = 0;
0202         ring_[i] = 0;
0203         side_[i] = 0;
0204         wheel_[i] = 0;
0205         gpX_[i] = 0.;
0206         gpY_[i] = 0.;
0207         gpZ_[i] = 0.;
0208         gpEta_[i] = 0.;
0209         gpPhi_[i] = 0.;
0210         lpX_[i] = 0.;
0211         lpY_[i] = 0.;
0212         lpZ_[i] = 0.;
0213       }
0214     }
0215   } storage_trackHit;
0216 
0217   //Standard Muon info storage
0218   ResidualRefitting::storage_muon storageGmrOld_, storageGmrNew_, storageSamNew_, storageTrkNew_, storageGmrNoSt1_,
0219       storageSamNoSt1_, storageGmrNoSt2_, storageSamNoSt2_, storageGmrNoSt3_, storageSamNoSt3_, storageGmrNoSt4_,
0220       storageSamNoSt4_,
0221 
0222       storageGmrNoPXBLayer1, storageGmrNoPXBLayer2, storageGmrNoPXBLayer3, storageTrkNoPXBLayer1, storageTrkNoPXBLayer2,
0223       storageTrkNoPXBLayer3,
0224 
0225       storageGmrNoPXF, storageTrkNoPXF,
0226 
0227       storageGmrNoTIBLayer1, storageGmrNoTIBLayer2, storageGmrNoTIBLayer3, storageGmrNoTIBLayer4, storageTrkNoTIBLayer1,
0228       storageTrkNoTIBLayer2, storageTrkNoTIBLayer3, storageTrkNoTIBLayer4, storageGmrNoTID, storageTrkNoTID,
0229       storageGmrNoTOBLayer1, storageGmrNoTOBLayer2, storageGmrNoTOBLayer3, storageGmrNoTOBLayer4, storageGmrNoTOBLayer5,
0230       storageGmrNoTOBLayer6, storageTrkNoTOBLayer1, storageTrkNoTOBLayer2, storageTrkNoTOBLayer3, storageTrkNoTOBLayer4,
0231       storageTrkNoTOBLayer5, storageTrkNoTOBLayer6, storageGmrNoTEC, storageTrkNoTEC;
0232 
0233   //Rec hit storage
0234   ResidualRefitting::storage_hit storageRecMuon_;
0235   ResidualRefitting::storage_trackHit storageTrackHit_;
0236 
0237   //Track Extrapolation to Muon System
0238   ResidualRefitting::storage_trackExtrap storageTrackExtrapRec_, storageTrackExtrapRecNoSt1_,
0239       storageTrackExtrapRecNoSt2_, storageTrackExtrapRecNoSt3_, storageTrackExtrapRecNoSt4_;
0240 
0241   //Track Extrapolation with Cylinder
0242   ResidualRefitting::storage_trackExtrap trackExtrap120_, samExtrap120_;
0243 
0244   //Track Extrapolation to Tracker system
0245   ResidualRefitting::storage_trackExtrap storageTrackExtrapTracker_, storageTrackNoPXBLayer1, storageTrackNoPXBLayer2,
0246       storageTrackNoPXBLayer3, storageTrackNoPXF, storageTrackNoTIBLayer1, storageTrackNoTIBLayer2,
0247       storageTrackNoTIBLayer3, storageTrackNoTIBLayer4, storageTrackNoTID, storageTrackNoTOBLayer1,
0248       storageTrackNoTOBLayer2, storageTrackNoTOBLayer3, storageTrackNoTOBLayer4, storageTrackNoTOBLayer5,
0249       storageTrackNoTOBLayer6, storageTrackNoTEC;
0250 
0251   //
0252   // Start of the method declarations
0253   //
0254 
0255   explicit ResidualRefitting(const edm::ParameterSet&);
0256   ~ResidualRefitting() override;
0257   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0258 
0259   void analyze(const edm::Event&, const edm::EventSetup&) override;
0260   void beginJob() override;
0261   void endJob() override;
0262   //Zero Storage
0263   void zero_storage();
0264   void zero_muon(ResidualRefitting::storage_muon* str);
0265   void zero_trackExtrap(ResidualRefitting::storage_trackExtrap* str);
0266   void branchMuon(ResidualRefitting::storage_muon& storageTmp, std::string branchName);
0267   void branchTrackExtrap(ResidualRefitting::storage_trackExtrap& storageTmp, std::string branchName);
0268 
0269   //    void collectTrackRecExtrap(reco::MuonCollection::const_iterator muon, ResidualRefitting::storage_trackExtrap& storeTemp);
0270   void muonInfo(ResidualRefitting::storage_muon& storeMuon, reco::TrackRef muon, int val);
0271 
0272   void CollectTrackHits(edm::Handle<reco::TrackCollection> trackColl,
0273                         ResidualRefitting::storage_trackExtrap& trackExtrap,
0274                         const edm::EventSetup& eventSetup);
0275   void StoreTrackerRecHits(DetId detid, const TrackerTopology* tTopo, int iTrack, int iRec);
0276   void NewTrackMeasurements(const edm::Handle<reco::TrackCollection>& trackCollOrig,
0277                             const edm::Handle<reco::TrackCollection>& trackColl,
0278                             ResidualRefitting::storage_trackExtrap& trackExtrap);
0279   int MatchTrackWithRecHits(reco::TrackCollection::const_iterator trackIt, edm::Handle<reco::TrackCollection> ref);
0280 
0281   bool IsSameHit(TrackingRecHit const& hit1, TrackingRecHit const& hit2);
0282 
0283   void trkExtrap(const DetId& detid,
0284                  int iTrkLink,
0285                  int iTrk,
0286                  int iRec,
0287                  const FreeTrajectoryState& freeTrajState,
0288                  const LocalPoint& recPoint,
0289                  storage_trackExtrap& storeTemp);
0290 
0291   void cylExtrapTrkSam(int recNum, reco::TrackRef track, ResidualRefitting::storage_trackExtrap& storage, double rho);
0292 
0293   //Simplifiying functions
0294   FreeTrajectoryState freeTrajStateMuon(reco::TrackRef muon);  //Returns a Free Trajectory State
0295                                                                //Debug Data Dumps
0296   //    void dumpRecoMuonColl(reco::MuonCollection::const_iterator muon); //
0297   //    void dumpRecoTrack(reco::TrackCollection::const_iterator muon);
0298   void dumpTrackRef(reco::TrackRef muon, std::string str);
0299   void dumpTrackExtrap(const ResidualRefitting::storage_trackExtrap& track);
0300   void dumpTrackHits(const ResidualRefitting::storage_trackHit& hit);
0301   void dumpMuonRecHits(const ResidualRefitting::storage_hit& hit);
0302 
0303   int ReturnSector(DetId detid);
0304   int ReturnStation(DetId detid);
0305 
0306   // Deprecated Functions
0307   void omitStation(edm::Handle<reco::MuonCollection> funcMuons,
0308                    edm::Handle<reco::TrackCollection>,
0309                    ResidualRefitting::storage_muon& storeGmr,
0310                    ResidualRefitting::storage_muon& storeSam,
0311                    ResidualRefitting::storage_trackExtrap& storeExtrap,
0312                    int omitStation);
0313   void omitTrackerSystem(edm::Handle<reco::MuonCollection> trkMuons,
0314                          ResidualRefitting::storage_muon& storeGmr,
0315                          ResidualRefitting::storage_muon& storeTrk,
0316                          ResidualRefitting::storage_trackExtrap& storeExtrap,
0317                          int omitSystem);
0318 
0319   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magFieldToken_;
0320   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0321   const edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> trackingGeometryToken_;
0322   const edm::ESGetToken<Propagator, TrackingComponentsRecord> propagatorToken_;
0323 
0324   // output histogram file name
0325   std::string outputFileName_;
0326   //edm::InputTag PropagatorSource_;
0327   std::string PropagatorSource_;
0328 
0329   // names of product labels
0330   const edm::InputTag tracks_, muons_, muonsRemake_, muonsNoStation1_, muonsNoStation2_, muonsNoStation3_,
0331       muonsNoStation4_;  //Global Muon Collections
0332 
0333   const bool debug_;
0334   const edm::EDGetTokenT<reco::MuonCollection> muonsToken_;
0335   const edm::EDGetTokenT<reco::TrackCollection> muonTracksToken_;
0336   const edm::EDGetTokenT<reco::TrackCollection> muonsNoSt1Token_;
0337   const edm::EDGetTokenT<reco::TrackCollection> muonsNoSt2Token_;
0338   const edm::EDGetTokenT<reco::TrackCollection> muonsNoSt3Token_;
0339   const edm::EDGetTokenT<reco::TrackCollection> muonsNoSt4Token_;
0340 
0341   // output ROOT file
0342   TFile* outputFile_;
0343 
0344   TTree* outputTree_;
0345   TBranch* outputBranch_;
0346 
0347   //    unsigned int nBins_;
0348 
0349   const MagneticField* theField;
0350   const edm::ESHandle<GlobalTrackingGeometry> trackingGeometry;
0351   MuonServiceProxy* theService;
0352   edm::ESHandle<Propagator> thePropagator;
0353 };
0354 
0355 #endif