CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DQMOffline/Trigger/interface/HLTMuonMatchAndPlot.h

Go to the documentation of this file.
00001 #ifndef DQMOffline_Trigger_HLTMuonMatchAndPlot_H
00002 #define DQMOffline_Trigger_HLTMuonMatchAndPlot_H
00003 
00015 // Base Class Headers
00016 
00017 #include "FWCore/Framework/interface/EDAnalyzer.h"
00018 #include "FWCore/Framework/interface/Frameworkfwd.h"
00019 #include "FWCore/Framework/interface/Event.h"
00020 #include "FWCore/Framework/interface/MakerMacros.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "FWCore/Utilities/interface/InputTag.h"
00023 #include "DataFormats/Common/interface/RefToBase.h"
00024 #include "DataFormats/TrackReco/interface/Track.h"
00025 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00026 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00027 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
00028 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
00029 #include "DataFormats/Candidate/interface/Candidate.h"
00030 //#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00031 #include "DQMServices/Core/interface/DQMStore.h"
00032 #include "DQMServices/Core/interface/MonitorElement.h"
00033 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00034 
00035 #include "DataFormats/Math/interface/LorentzVector.h"
00036 
00037 #include "DataFormats/HLTReco/interface/TriggerObject.h"
00038 #include "DataFormats/MuonReco/interface/Muon.h"
00039 //#include "CommonTools/Utilities/interface/StringCutObjectSelector.h"
00040 #include "CommonTools/Utils/interface/StringCutObjectSelector.h"
00041 
00042 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00043 
00044 #include <vector>
00045 #include "TFile.h"
00046 #include "TNtuple.h"
00047 #include "TString.h"
00048 
00049 
00050 typedef math::XYZTLorentzVector LorentzVector;
00051 
00052 //-----------------------------------------
00053 // Add in a struct that gathers together
00054 // the selectors and string that form the
00055 // definition of each object
00056 //-----------------------------------------
00057 
00058 struct MuonSelectionStruct {
00059 
00060   // constructor is empty, but passes in arguments
00061   MuonSelectionStruct(StringCutObjectSelector<reco::Muon> rsel, StringCutObjectSelector<trigger::TriggerObject> hltsel,
00062                       std::string cl, double pD0cut, double pZ0cut, std::string trackCol, std::vector<std::string> reqTrigs)
00063     :recoMuonSelector(rsel), hltMuonSelector(hltsel), customLabel(cl),
00064      d0cut(pD0cut), z0cut(pZ0cut), trackCollection(trackCol),
00065      requiredTriggers(reqTrigs) {};
00066   
00067   StringCutObjectSelector<reco::Muon> recoMuonSelector;
00068   StringCutObjectSelector<trigger::TriggerObject> hltMuonSelector;
00069   std::string customLabel;
00070 
00071   
00072   // the track cuts you want to use
00073   // note: for future dev, you may want to
00074   // also include some way to force use of beamspot
00075   // paramters.
00076 
00077 
00078   double d0cut;
00079   double z0cut;
00080 
00081   
00082   // the track collection you want to use
00083   std::string trackCollection;
00084 
00085 
00086   // included here for completeness, but not
00087   // yet fully implemented
00088 
00089   std::vector<std::string> requiredTriggers;
00090   
00091   // note... do we want to make a raw selector?
00092   // raw trigger events are called trig event with refs
00093   
00094 };
00095 
00096 
00097 
00098 class HLTMuonMatchAndPlot {
00099 
00100 public:
00101 
00103   HLTMuonMatchAndPlot( const edm::ParameterSet& pset, std::string triggerName,
00104                        std::vector<std::string> moduleNames, MuonSelectionStruct inputSelection,
00105                        std::string customName,
00106                        std::vector<std::string> validTriggers,
00107                        const edm::Run & currentRun,
00108                        const edm::EventSetup & currentEventSetup );
00109 
00110   // Operations
00111   virtual void            begin  ( );
00112   virtual void            analyze( const edm::Event & iEvent );
00113   virtual void            finish ( );
00114   virtual void            endRun (const edm::Run& r, const edm::EventSetup& c);
00115   virtual MonitorElement* bookIt ( TString name, TString title, std::vector<double> );
00116   virtual MonitorElement* bookIt ( TString name, TString title, int nbins, float* xBinLowEdges);
00117   
00118   TString             calcHistoSuffix (std::string moduleName);
00119 
00120   // Struct and methods for matching
00121 
00122   // Big Change from RelVal
00123   // Now we store Muons and TriggerObjects
00124   // instead of Tracks and 4-vectors
00125   struct MatchStruct {
00126 
00127     // this is the reco muon
00128     const reco::Muon*         recCand;
00129     
00130     // this is the cand from the L1 filter
00131     // in L1 passthru triggers
00132     // that matches the reco muon
00133     // (from trigger summary aod)
00134     trigger::TriggerObject l1Cand;
00135 
00136     // this is the L1 seed candidate from
00137     // HLT trigger paths
00138 
00139     trigger::TriggerObject l1Seed;
00140 
00141     // this is the raw candidate from
00142     // the trigger summary with refs
00143     // that matches the reco muon    
00144     LorentzVector l1RawCand;
00145 
00146     // these are the hlt candidates from
00147     // trigger sum AOD that match
00148     // the reco muon
00149     std::vector<trigger::TriggerObject> hltCands;
00150 
00151     // these are the hlt candidates from
00152     // trigger sum w/ refs that match
00153     // the reco muon
00154     std::vector<LorentzVector> hltRawCands;
00155     
00156   };
00157 
00158   // Structure that  holds a Lorentz Vector corresponding
00159   // to an HLT object and a bool to indicate whether or
00160   // not it is a fake
00161   struct HltFakeStruct {    
00162     trigger::TriggerObject              myHltCand;
00163     bool                       isAFake;    
00164   };
00165 
00166   // store the matches for each event
00167   std::vector<MatchStruct> recMatches;
00168 
00169   std::vector< std::vector<HltFakeStruct> > hltFakeCands;
00170 
00171   virtual ~HLTMuonMatchAndPlot() {} ;
00172 
00173   //-------- The fuctions/data below used to be private, but we want to
00174   //-------- have other classes inherit them, so we make them public
00175 
00176   
00177 
00178   // Functions that are an internal decomposition of the stages of the
00179   // public "analyze" function
00180 
00181   // They need to be public so that other modules can use them?
00182   
00183   bool virtual selectAndMatchMuons(const edm::Event & iEvent,
00184                                    std::vector<MatchStruct> & myRecMatches,
00185                                    std::vector< std::vector<HltFakeStruct> > & myHltFakeCands
00186                                    );
00187 
00188   // does this need to be generalized to work for a given trigger too?
00189   bool  selectAndMatchMuons(const edm::Event & iEvent,
00190                             std::vector<MatchStruct> & myRecMatches,
00191                             std::vector< std::vector<HltFakeStruct> > & myHltFakeCands,
00192                             MuonSelectionStruct muonSelection
00193                             );
00194 
00195   
00196   void virtual fillPlots(std::vector<MatchStruct> & myRecMatches,
00197                          std::vector< std::vector<HltFakeStruct> > & myHltFakeCands);
00198 
00199 protected:
00200   
00202   
00203   const reco::Candidate* findMother( const reco::Candidate* );
00204   int findGenMatch( double eta, double phi, double maxDeltaR,
00205                     std::vector<MatchStruct> matches );
00206   int findRecMatch( double eta, double phi, double maxdeltaR,
00207                     std::vector<MatchStruct> matches );
00208 
00209   bool virtual applyTrackSelection (MuonSelectionStruct mySelection, reco::Muon candMuon);
00210   reco::TrackRef getCandTrackRef (MuonSelectionStruct mySelection, reco::Muon candMuon);
00211 
00212   bool virtual applyTriggerSelection (MuonSelectionStruct mySelection, const edm::Event & event);
00213 
00214   // boolean to turn on/off overflow inclusion
00215   // function to do the overflow
00216   bool includeOverflow;
00217   void moveOverflow (MonitorElement * myElement);
00218 
00219 
00220   // put the code for getting trigger objects into a single module
00221   // fills up foundObjects with your matching trigger objects
00222   void getAodTriggerObjectsForModule (edm::InputTag collectionTag,
00223                                       edm::Handle<trigger::TriggerEvent> aodTriggerEvent,
00224                                       trigger::TriggerObjectCollection trigObjs,
00225                                       std::vector<trigger::TriggerObject> & foundObjects,
00226                                       MuonSelectionStruct muonSelection);
00227   
00228   // keep track of the ME's you've booked,
00229   // rebin them at job end.
00230   std::vector<MonitorElement*> booked1DMonitorElements;
00231   
00232   // Data members
00233 
00234   // flag to decide how you want to label output histos
00235   // old label scheme kept lots of the trigger name,
00236   // but complicated harvesting step
00237   bool    useOldLabels;
00238   bool    useFullDebugInformation;
00239   int     HLT_PLOT_OFFSET;
00240   bool    isL1Path, isL2Path, isL3Path;
00241 
00242   unsigned int numL1Cands;
00243 
00244   bool    makeNtuple;
00245   float   theNtuplePars[100]; 
00246   TNtuple *theNtuple;
00247   TFile   *theFile;
00248 
00249   reco::BeamSpot  beamSpot;
00250   bool foundBeamSpot;
00251 
00252 
00253   // Input from cfg file
00254 
00255   std::string              theHltProcessName;
00256   std::string              theTriggerName;
00257   std::string              theL1CollectionLabel;
00258   std::vector<std::string> theHltCollectionLabels;
00259   unsigned int             theNumberOfObjects;
00260 
00261   //bool         useMuonFromGenerator;
00262   bool         useMuonFromReco;
00263   //std::string  theGenLabel;
00264   //std::string  theRecoLabel;
00265   
00266   edm::InputTag RecoMuonInputTag;
00267   edm::InputTag BeamSpotInputTag;
00268   edm::InputTag HltRawInputTag;
00269   edm::InputTag HltAodInputTag;
00270   
00271   bool         useAod;
00272   std::string  theAodL1Label;
00273   std::string  theAodL2Label;
00274 
00275   bool requireL1SeedForHLTPaths;
00276 
00277 
00278   std::string matchType;
00279 
00280   MuonSelectionStruct mySelection;
00281 
00282   //======= Trigger Selection info ==========
00283   edm::InputTag TriggerResultLabel;
00284 
00285   std::vector<std::string> selectedValidTriggers;
00286 
00287   std::string theL1SeedModuleForHLTPath;
00288   
00289   //StringCutObjectSelector<reco::Muon> myMuonSelector;
00290   //std::string myCustomName;
00291   
00292   // constants and a method
00293   // to simplify charge plots
00294 
00295   static const int POS_CHARGE = 1;
00296   static const int NEG_CHARGE = -1;
00297   int getCharge (int pdgId); 
00298 
00299   // 1-D histogram paramters
00300   std::vector<double> theMaxPtParameters;
00301   std::vector<double> thePtParameters;
00302   std::vector<double> theEtaParameters;
00303   std::vector<double> thePhiParameters;
00304   std::vector<double> thePhiParameters0Pi;
00305   std::vector<double> theD0Parameters; 
00306   std::vector<double> theZ0Parameters;
00307   std::vector<double> theChargeParameters;
00308   std::vector<double> theDRParameters;
00309   std::vector<double> theChargeFlipParameters;
00310 
00311   // variable width pt bins
00312   // don't allow more than 100
00313   float  ptBins[100];
00314   int numBinsInPtHisto;
00315 
00316   // 2-D histogram parameters
00317   std::vector<double> thePhiEtaParameters2d;
00318 
00319   //   std::vector<double> theMaxPtParameters2d;
00320   //   std::vector<double> theEtaParameters2d;
00321   //   std::vector<double> thePhiParameters2d;
00322   
00323   //   std::vector<double> theDeltaPhiVsPhiParameters;
00324   //   std::vector<double> theDeltaPhiVsZ0Parameters;
00325   //   std::vector<double> theDeltaPhiVsD0Parameters;
00326   
00327 
00328   // Resolution hisotgram parameters
00329   std::vector<double> theResParameters;
00330 
00331   // isolation parameters
00332   std::vector<double> theIsolationParameters;
00333   
00334 
00335 
00336   double       theMinPtCut;
00337   double       theMaxEtaCut;
00338   double       theL1DrCut;
00339   double       theL2DrCut;
00340   double       theL3DrCut;
00341   int          theMotherParticleId;
00342   std::vector<double> theNSigmas;
00343 
00344   std::string  theNtupleFileName;
00345   std::string  theNtuplePath;
00346 
00347   // Book-keeping information
00348 
00349   int          eventNumber;
00350   unsigned int numHltLabels;
00351   bool         isIsolatedPath;
00352 
00353   // Monitor Elements (Histograms and ints)
00354 
00355   DQMStore* dbe_;
00356 
00357   bool createStandAloneHistos;
00358   std::string histoFileName;
00359   
00360 
00361  //  std::vector <MonitorElement*> hPassMaxPtGen;
00362 //   std::vector <MonitorElement*> hPassEtaGen;
00363 //   std::vector <MonitorElement*> hPassPhiGen;
00364   std::vector <MonitorElement*> hPassMaxPtRec;
00365   std::vector <MonitorElement*> hPassEtaRec;
00366   std::vector <MonitorElement*> hPassPhiRec;
00367   std::vector <MonitorElement*> hPassMatchPtRec;
00368   std::vector <MonitorElement*> hPassExaclyOneMuonMaxPtRec;
00369   //std::vector <MonitorElement*> hPtMatchVsPtRec;
00370   //std::vector <MonitorElement*> hEtaMatchVsEtaRec;
00371   //std::vector <MonitorElement*> hPhiMatchVsPhiRec;
00372   std::vector <MonitorElement*> hPhiVsEtaRec;
00373   std::vector <MonitorElement*> hPassPtRec;
00374   std::vector <MonitorElement*> hPassPtRecExactlyOne;
00375   std::vector <MonitorElement*> hResoPtAodRec;
00376   std::vector <MonitorElement*> hResoEtaAodRec;
00377   std::vector <MonitorElement*> hResoPhiAodRec;
00378   std::vector <MonitorElement*> hPassD0Rec;
00379   std::vector <MonitorElement*> hPassZ0Rec;
00380   std::vector <MonitorElement*> hPassCharge;
00381   std::vector <MonitorElement*> hPassD0BeamRec;
00382   std::vector <MonitorElement*> hPassZ0BeamRec;
00383   std::vector <MonitorElement*> hBeamSpotZ0Rec;
00384 
00385   // studies for cosmics
00386   std::vector <MonitorElement*> hMatchedDeltaPhi;
00387   //std::vector <MonitorElement*> hDeltaPhiVsPhi;
00388   //std::vector <MonitorElement*> hDeltaPhiVsZ0;
00389   //std::vector <MonitorElement*> hDeltaPhiVsD0;
00390   
00391   
00392 
00393   std::vector <MonitorElement*> hDeltaRMatched;
00394   std::vector <MonitorElement*> hIsolationRec;
00395   std::vector <MonitorElement*> hChargeFlipMatched;
00396 
00397   std::vector <MonitorElement*> allHltCandPt;
00398   std::vector <MonitorElement*> allHltCandEta;
00399   std::vector <MonitorElement*> allHltCandPhi;
00400   // can't do d0, z0 becuase only have 4 vectors
00401   //std::vector <MonitorElement*> allHltCandD0Rec;
00402   //std::vector <MonitorElement*> allHltCandZ0Rec;
00403     
00404   std::vector <MonitorElement*> fakeHltCandPt;
00405   std::vector <MonitorElement*> fakeHltCandEta;
00406   std::vector <MonitorElement*> fakeHltCandPhi;
00407   //std::vector <MonitorElement*> fakeHltCandD0Rec;
00408   //std::vector <MonitorElement*> fakeHltCandZ0Rec;
00409 
00410   //std::vector <MonitorElement*> fakeHltCandEtaPhi;
00411   //std::vector <MonitorElement*> fakeHltCandDeltaR;
00412 
00413   // RAW histograms
00414   // L1, L2, L3
00415   std::vector <MonitorElement*> rawMatchHltCandPt;
00416   std::vector <MonitorElement*> rawMatchHltCandEta;
00417   std::vector <MonitorElement*> rawMatchHltCandPhi;
00418 
00419   // 
00420   //std::string highPtTrackCollection;
00421   
00422   
00423   MonitorElement *hNumObjects;
00424   //MonitorElement *hNumOrphansGen;
00425   MonitorElement *hNumOrphansRec;
00426   MonitorElement *meNumberOfEvents;
00427 
00428 };
00429 #endif