Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:09:41

0001 #include "DQMOffline/Muon/interface/MuonRecoOneHLT.h"
0002 
0003 #include "FWCore/Common/interface/TriggerNames.h"
0004 
0005 #include <string>
0006 #include "TMath.h"
0007 using namespace std;
0008 using namespace edm;
0009 
0010 // Uncomment to DEBUG
0011 //#define DEBUG
0012 
0013 MuonRecoOneHLT::MuonRecoOneHLT(const edm::ParameterSet& pSet) {
0014   parameters = pSet;
0015 
0016   ParameterSet muonparms = parameters.getParameter<edm::ParameterSet>("SingleMuonTrigger");
0017   ParameterSet dimuonparms = parameters.getParameter<edm::ParameterSet>("DoubleMuonTrigger");
0018   _SingleMuonEventFlag = new GenericTriggerEventFlag(muonparms, consumesCollector(), *this, l1t::UseEventSetupIn::Run);
0019   _DoubleMuonEventFlag =
0020       new GenericTriggerEventFlag(dimuonparms, consumesCollector(), *this, l1t::UseEventSetupIn::Run);
0021 
0022   // Trigger Expresions in case de connection to the DB fails
0023   singlemuonExpr_ = muonparms.getParameter<std::vector<std::string> >("hltPaths");
0024   doublemuonExpr_ = dimuonparms.getParameter<std::vector<std::string> >("hltPaths");
0025 
0026   theMuonCollectionLabel_ = consumes<reco::MuonCollection>(parameters.getParameter<edm::InputTag>("MuonCollection"));
0027   theVertexLabel_ = consumes<reco::VertexCollection>(parameters.getParameter<edm::InputTag>("VertexLabel"));
0028   theBeamSpotLabel_ = mayConsume<reco::BeamSpot>(parameters.getParameter<edm::InputTag>("BeamSpotLabel"));
0029   theTriggerResultsLabel_ = consumes<TriggerResults>(parameters.getParameter<InputTag>("TriggerResultsLabel"));
0030 
0031   // Parameters
0032   etaBin = parameters.getParameter<int>("etaBin");
0033   etaMin = parameters.getParameter<double>("etaMin");
0034   etaMax = parameters.getParameter<double>("etaMax");
0035   ptBin = parameters.getParameter<int>("ptBin");
0036   ptMin = parameters.getParameter<double>("ptMin");
0037   ptMax = parameters.getParameter<double>("ptMax");
0038   chi2Bin = parameters.getParameter<int>("chi2Bin");
0039   chi2Min = parameters.getParameter<double>("chi2Min");
0040   chi2Max = parameters.getParameter<double>("chi2Max");
0041   phiBin = parameters.getParameter<int>("phiBin");
0042   phiMin = parameters.getParameter<double>("phiMin");
0043   phiMax = parameters.getParameter<double>("phiMax");
0044 }
0045 MuonRecoOneHLT::~MuonRecoOneHLT() {
0046   delete _SingleMuonEventFlag;
0047   delete _DoubleMuonEventFlag;
0048 }
0049 void MuonRecoOneHLT::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
0050 #ifdef DEBUG
0051   cout << "[MuonRecoOneHLT]  beginRun " << endl;
0052   cout << "[MuonRecoOneHLT]  Is MuonEventFlag On? " << _SingleMuonEventFlag->on() << endl;
0053 #endif
0054 
0055   ibooker.cd();
0056   ibooker.setCurrentFolder("Muons/MuonRecoOneHLT");
0057 
0058   muReco = ibooker.book1D("Muon_Reco", "Muon Reconstructed Tracks", 6, 1, 7);
0059   muReco->setBinLabel(1, "glb+tk+sta");
0060   muReco->setBinLabel(2, "glb+sta");
0061   muReco->setBinLabel(3, "tk+sta");
0062   muReco->setBinLabel(4, "tk");
0063   muReco->setBinLabel(5, "sta");
0064   muReco->setBinLabel(6, "calo");
0065 
0066   // monitoring of eta parameter
0067   std::string histname = "GlbMuon_";
0068   etaGlbTrack.push_back(ibooker.book1D(histname + "Glb_eta", "#eta_{GLB}", etaBin, etaMin, etaMax));
0069   etaGlbTrack.push_back(ibooker.book1D(histname + "Tk_eta", "#eta_{TKfromGLB}", etaBin, etaMin, etaMax));
0070   etaGlbTrack.push_back(ibooker.book1D(histname + "Sta_eta", "#eta_{STAfromGLB}", etaBin, etaMin, etaMax));
0071   etaTight = ibooker.book1D("TightMuon_eta", "#eta_{GLB}", etaBin, etaMin, etaMax);
0072   etaTrack = ibooker.book1D("TkMuon_eta", "#eta_{TK}", etaBin, etaMin, etaMax);
0073   etaStaTrack = ibooker.book1D("StaMuon_eta", "#eta_{STA}", etaBin, etaMin, etaMax);
0074 
0075   // monitoring of phi paramater
0076   phiGlbTrack.push_back(ibooker.book1D(histname + "Glb_phi", "#phi_{GLB}", phiBin, phiMin, phiMax));
0077   phiGlbTrack[0]->setAxisTitle("rad");
0078   phiGlbTrack.push_back(ibooker.book1D(histname + "Tk_phi", "#phi_{TKfromGLB}", phiBin, phiMin, phiMax));
0079   phiGlbTrack[1]->setAxisTitle("rad");
0080   phiGlbTrack.push_back(ibooker.book1D(histname + "Sta_phi", "#phi_{STAfromGLB}", phiBin, phiMin, phiMax));
0081   phiGlbTrack[2]->setAxisTitle("rad");
0082   phiTight = ibooker.book1D("TightMuon_phi", "#phi_{GLB}", phiBin, phiMin, phiMax);
0083   phiTrack = ibooker.book1D("TkMuon_phi", "#phi_{TK}", phiBin, phiMin, phiMax);
0084   phiTrack->setAxisTitle("rad");
0085   phiStaTrack = ibooker.book1D("StaMuon_phi", "#phi_{STA}", phiBin, phiMin, phiMax);
0086   phiStaTrack->setAxisTitle("rad");
0087 
0088   // monitoring of the chi2 parameter
0089   chi2OvDFGlbTrack.push_back(
0090       ibooker.book1D(histname + "Glb_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max));
0091   chi2OvDFGlbTrack.push_back(
0092       ibooker.book1D(histname + "Tk_chi2OverDf", "#chi_{2}OverDF_{TKfromGLB}", phiBin, chi2Min, chi2Max));
0093   chi2OvDFGlbTrack.push_back(
0094       ibooker.book1D(histname + "Sta_chi2OverDf", "#chi_{2}OverDF_{STAfromGLB}", chi2Bin, chi2Min, chi2Max));
0095   chi2OvDFTight = ibooker.book1D("TightMuon_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max);
0096   chi2OvDFTrack = ibooker.book1D("TkMuon_chi2OverDf", "#chi_{2}OverDF_{TK}", chi2Bin, chi2Min, chi2Max);
0097   chi2OvDFStaTrack = ibooker.book1D("StaMuon_chi2OverDf", "#chi_{2}OverDF_{STA}", chi2Bin, chi2Min, chi2Max);
0098 
0099   // monitoring of the transverse momentum
0100   ptGlbTrack.push_back(ibooker.book1D(histname + "Glb_pt", "pt_{GLB}", ptBin, ptMin, ptMax));
0101   ptGlbTrack[0]->setAxisTitle("GeV");
0102   ptGlbTrack.push_back(ibooker.book1D(histname + "Tk_pt", "pt_{TKfromGLB}", ptBin, ptMin, ptMax));
0103   ptGlbTrack[1]->setAxisTitle("GeV");
0104   ptGlbTrack.push_back(ibooker.book1D(histname + "Sta_pt", "pt_{STAfromGLB}", ptBin, ptMin, ptMax));
0105   ptGlbTrack[2]->setAxisTitle("GeV");
0106   ptTight = ibooker.book1D("TightMuon_pt", "pt_{GLB}", ptBin, ptMin, ptMax);
0107   ptTight->setAxisTitle("GeV");
0108   ptTrack = ibooker.book1D("TkMuon_pt", "pt_{TK}", ptBin, ptMin, ptMax);
0109   ptTrack->setAxisTitle("GeV");
0110   ptStaTrack = ibooker.book1D("StaMuon_pt", "pt_{STA}", ptBin, ptMin, ptMax);
0111   ptStaTrack->setAxisTitle("GeV");
0112 
0113   if (_SingleMuonEventFlag->on())
0114     _SingleMuonEventFlag->initRun(iRun, iSetup);
0115   if (_DoubleMuonEventFlag->on())
0116     _DoubleMuonEventFlag->initRun(iRun, iSetup);
0117 
0118   if (_SingleMuonEventFlag->on() &&
0119       _SingleMuonEventFlag->expressionsFromDB(_SingleMuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
0120     singlemuonExpr_ = _SingleMuonEventFlag->expressionsFromDB(_SingleMuonEventFlag->hltDBKey(), iSetup);
0121   if (_DoubleMuonEventFlag->on() &&
0122       _DoubleMuonEventFlag->expressionsFromDB(_DoubleMuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
0123     singlemuonExpr_ = _DoubleMuonEventFlag->expressionsFromDB(_DoubleMuonEventFlag->hltDBKey(), iSetup);
0124 }
0125 void MuonRecoOneHLT::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0126   // =================================================================================
0127   // Look for the Primary Vertex (and use the BeamSpot instead, if you can't find it):
0128   reco::Vertex::Point posVtx;
0129   reco::Vertex::Error errVtx;
0130   unsigned int theIndexOfThePrimaryVertex = 999.;
0131 
0132   edm::Handle<reco::VertexCollection> vertex;
0133   iEvent.getByToken(theVertexLabel_, vertex);
0134   if (vertex.isValid()) {
0135     for (unsigned int ind = 0; ind < vertex->size(); ++ind) {
0136       if ((*vertex)[ind].isValid() && !((*vertex)[ind].isFake())) {
0137         theIndexOfThePrimaryVertex = ind;
0138         break;
0139       }
0140     }
0141   }
0142 
0143   if (theIndexOfThePrimaryVertex < 100) {
0144     posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
0145     errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
0146   } else {
0147     LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
0148 
0149     edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
0150     iEvent.getByToken(theBeamSpotLabel_, recoBeamSpotHandle);
0151     const reco::BeamSpot& bs = *recoBeamSpotHandle;
0152 
0153     posVtx = bs.position();
0154     errVtx(0, 0) = bs.BeamWidthX();
0155     errVtx(1, 1) = bs.BeamWidthY();
0156     errVtx(2, 2) = bs.sigmaZ();
0157   }
0158 
0159   const reco::Vertex vtx(posVtx, errVtx);
0160 
0161   // ==========================================================
0162   //  READ DATA:
0163   edm::Handle<reco::MuonCollection> muons;
0164   iEvent.getByToken(theMuonCollectionLabel_, muons);
0165 
0166   edm::Handle<TriggerResults> triggerResults;
0167   iEvent.getByToken(theTriggerResultsLabel_, triggerResults);
0168 
0169   // check if muon collection is valid
0170   if (!muons.isValid())
0171     return;
0172 
0173   //  Pick the leading lepton.
0174   std::map<float, const reco::Muon*> muonMap;
0175   for (reco::MuonCollection::const_iterator recoMu = muons->begin(); recoMu != muons->end(); ++recoMu) {
0176     muonMap[recoMu->pt()] = &*recoMu;
0177   }
0178   std::vector<const reco::Muon*> LeadingMuon;
0179   for (std::map<float, const reco::Muon*>::reverse_iterator rit = muonMap.rbegin(); rit != muonMap.rend(); ++rit) {
0180     LeadingMuon.push_back((*rit).second);
0181   }
0182 
0183   // Pick Trigger information.
0184   const edm::TriggerNames& triggerNames = iEvent.triggerNames(*triggerResults);
0185   const unsigned int nTrig(triggerNames.size());
0186   bool _trig_SingleMu = false;
0187   bool _trig_DoubleMu = false;
0188   for (unsigned int i = 0; i < nTrig; ++i) {
0189     if (triggerNames.triggerName(i).find(singlemuonExpr_[0].substr(0, singlemuonExpr_[0].rfind("_v") + 2)) !=
0190             std::string::npos &&
0191         triggerResults->accept(i))
0192       _trig_SingleMu = true;
0193     if (triggerNames.triggerName(i).find(doublemuonExpr_[0].substr(0, doublemuonExpr_[0].rfind("_v") + 2)) !=
0194             std::string::npos &&
0195         triggerResults->accept(i))
0196       _trig_DoubleMu = true;
0197   }
0198 #ifdef DEBUG
0199   cout << "[MuonRecoOneHLT]  Trigger Fired ? " << (_trig_SingleMu || _trig_DoubleMu) << endl;
0200 #endif
0201 
0202   if (!_trig_SingleMu && !_trig_DoubleMu)
0203     return;
0204   if (LeadingMuon.empty())
0205     return;
0206   //  if (_MuonEventFlag->on() && !(_MuonEventFlag->accept(iEvent,iSetup))) return;
0207 
0208   // Check if Muon is Global
0209   if ((*LeadingMuon[0]).isGlobalMuon()) {
0210     LogTrace(metname) << "[MuonRecoOneHLT] The mu is global - filling the histos";
0211     if ((*LeadingMuon[0]).isTrackerMuon() && (*LeadingMuon[0]).isStandAloneMuon())
0212       muReco->Fill(1);
0213     if (!((*LeadingMuon[0]).isTrackerMuon()) && (*LeadingMuon[0]).isStandAloneMuon())
0214       muReco->Fill(2);
0215     if (!(*LeadingMuon[0]).isStandAloneMuon())
0216       LogTrace(metname) << "[MuonRecoOneHLT] ERROR: the mu is global but not standalone!";
0217 
0218     // get the track combinig the information from both the Tracker and the Spectrometer
0219     reco::TrackRef recoCombinedGlbTrack = (*LeadingMuon[0]).combinedMuon();
0220     // get the track using only the tracker data
0221     reco::TrackRef recoTkGlbTrack = (*LeadingMuon[0]).track();
0222     // get the track using only the mu spectrometer data
0223     reco::TrackRef recoStaGlbTrack = (*LeadingMuon[0]).standAloneMuon();
0224 
0225     etaGlbTrack[0]->Fill(recoCombinedGlbTrack->eta());
0226     etaGlbTrack[1]->Fill(recoTkGlbTrack->eta());
0227     etaGlbTrack[2]->Fill(recoStaGlbTrack->eta());
0228 
0229     phiGlbTrack[0]->Fill(recoCombinedGlbTrack->phi());
0230     phiGlbTrack[1]->Fill(recoTkGlbTrack->phi());
0231     phiGlbTrack[2]->Fill(recoStaGlbTrack->phi());
0232 
0233     chi2OvDFGlbTrack[0]->Fill(recoCombinedGlbTrack->normalizedChi2());
0234     chi2OvDFGlbTrack[1]->Fill(recoTkGlbTrack->normalizedChi2());
0235     chi2OvDFGlbTrack[2]->Fill(recoStaGlbTrack->normalizedChi2());
0236 
0237     ptGlbTrack[0]->Fill(recoCombinedGlbTrack->pt());
0238     ptGlbTrack[1]->Fill(recoTkGlbTrack->pt());
0239     ptGlbTrack[2]->Fill(recoStaGlbTrack->pt());
0240   }
0241   // Check if Muon is Tight
0242   if (muon::isTightMuon((*LeadingMuon[0]), vtx)) {
0243     LogTrace(metname) << "[MuonRecoOneHLT] The mu is tracker only - filling the histos";
0244 
0245     reco::TrackRef recoCombinedGlbTrack = (*LeadingMuon[0]).combinedMuon();
0246 
0247     etaTight->Fill(recoCombinedGlbTrack->eta());
0248     phiTight->Fill(recoCombinedGlbTrack->phi());
0249     chi2OvDFTight->Fill(recoCombinedGlbTrack->normalizedChi2());
0250     ptTight->Fill(recoCombinedGlbTrack->pt());
0251   }
0252 
0253   // Check if Muon is Tracker but NOT Global
0254   if ((*LeadingMuon[0]).isTrackerMuon() && !((*LeadingMuon[0]).isGlobalMuon())) {
0255     LogTrace(metname) << "[MuonRecoOneHLT] The mu is tracker only - filling the histos";
0256     if ((*LeadingMuon[0]).isStandAloneMuon())
0257       muReco->Fill(3);
0258     if (!((*LeadingMuon[0]).isStandAloneMuon()))
0259       muReco->Fill(4);
0260 
0261     // get the track using only the tracker data
0262     reco::TrackRef recoTrack = (*LeadingMuon[0]).track();
0263 
0264     etaTrack->Fill(recoTrack->eta());
0265     phiTrack->Fill(recoTrack->phi());
0266     chi2OvDFTrack->Fill(recoTrack->normalizedChi2());
0267     ptTrack->Fill(recoTrack->pt());
0268   }
0269 
0270   // Check if Muon is STA but NOT Global
0271   if ((*LeadingMuon[0]).isStandAloneMuon() && !((*LeadingMuon[0]).isGlobalMuon())) {
0272     LogTrace(metname) << "[MuonRecoOneHLT] The mu is STA only - filling the histos";
0273     if (!((*LeadingMuon[0]).isTrackerMuon()))
0274       muReco->Fill(5);
0275 
0276     // get the track using only the mu spectrometer data
0277     reco::TrackRef recoStaTrack = (*LeadingMuon[0]).standAloneMuon();
0278 
0279     etaStaTrack->Fill(recoStaTrack->eta());
0280     phiStaTrack->Fill(recoStaTrack->phi());
0281     chi2OvDFStaTrack->Fill(recoStaTrack->normalizedChi2());
0282     ptStaTrack->Fill(recoStaTrack->pt());
0283   }
0284   // Check if Muon is Only CaloMuon
0285   if ((*LeadingMuon[0]).isCaloMuon() && !((*LeadingMuon[0]).isGlobalMuon()) && !((*LeadingMuon[0]).isTrackerMuon()) &&
0286       !((*LeadingMuon[0]).isStandAloneMuon()))
0287     muReco->Fill(6);
0288 }