00001 #include "DQMOffline/Muon/src/MuonRecoOneHLT.h"
00002
00003 #include "DataFormats/Common/interface/Handle.h"
00004 #include "DataFormats/MuonReco/interface/Muon.h"
00005 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00006 #include "DataFormats/MuonReco/interface/MuonEnergy.h"
00007
00008 #include "FWCore/Common/interface/TriggerNames.h"
00009
00010 #include "DataFormats/TrackReco/interface/Track.h"
00011 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00012 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00013
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015
00016 #include <string>
00017 #include "TMath.h"
00018 using namespace std;
00019 using namespace edm;
00020
00021
00022
00023
00024 MuonRecoOneHLT::MuonRecoOneHLT(const edm::ParameterSet& pSet, MuonServiceProxy *theService):MuonAnalyzerBase(theService) {
00025 parameters = pSet;
00026
00027 ParameterSet muonparms = parameters.getParameter<edm::ParameterSet>("SingleMuonTrigger");
00028 ParameterSet dimuonparms = parameters.getParameter<edm::ParameterSet>("DoubleMuonTrigger");
00029 _SingleMuonEventFlag = new GenericTriggerEventFlag( muonparms );
00030 _DoubleMuonEventFlag = new GenericTriggerEventFlag( dimuonparms );
00031
00032
00033 singlemuonExpr_ = muonparms.getParameter<std::vector<std::string> >("hltPaths");
00034 doublemuonExpr_ = dimuonparms.getParameter<std::vector<std::string> >("hltPaths");
00035 }
00036
00037
00038 MuonRecoOneHLT::~MuonRecoOneHLT() {
00039 delete _SingleMuonEventFlag;
00040 delete _DoubleMuonEventFlag;
00041 }
00042 void MuonRecoOneHLT::beginJob(DQMStore * dbe) {
00043 #ifdef DEBUG
00044 cout << "[MuonRecoOneHLT] beginJob " << endl;
00045 #endif
00046 dbe->setCurrentFolder("Muons/MuonRecoOneHLT");
00047
00048 theMuonCollectionLabel = parameters.getParameter<edm::InputTag>("MuonCollection");
00049
00050 muReco = dbe->book1D("Muon_Reco", "Muon Reconstructed Tracks", 6, 1, 7);
00051 muReco->setBinLabel(1,"glb+tk+sta");
00052 muReco->setBinLabel(2,"glb+sta");
00053 muReco->setBinLabel(3,"tk+sta");
00054 muReco->setBinLabel(4,"tk");
00055 muReco->setBinLabel(5,"sta");
00056 muReco->setBinLabel(6,"calo");
00057
00058
00059 etaBin = parameters.getParameter<int>("etaBin");
00060 etaMin = parameters.getParameter<double>("etaMin");
00061 etaMax = parameters.getParameter<double>("etaMax");
00062
00063 std::string histname = "GlbMuon_";
00064 etaGlbTrack.push_back(dbe->book1D(histname+"Glb_eta", "#eta_{GLB}", etaBin, etaMin, etaMax));
00065 etaGlbTrack.push_back(dbe->book1D(histname+"Tk_eta", "#eta_{TKfromGLB}", etaBin, etaMin, etaMax));
00066 etaGlbTrack.push_back(dbe->book1D(histname+"Sta_eta", "#eta_{STAfromGLB}", etaBin, etaMin, etaMax));
00067 etaTight = dbe->book1D("TightMuon_eta", "#eta_{GLB}", etaBin, etaMin, etaMax);
00068 etaTrack = dbe->book1D("TkMuon_eta", "#eta_{TK}", etaBin, etaMin, etaMax);
00069 etaStaTrack = dbe->book1D("StaMuon_eta", "#eta_{STA}", etaBin, etaMin, etaMax);
00070
00071
00072 phiBin = parameters.getParameter<int>("phiBin");
00073 phiMin = parameters.getParameter<double>("phiMin");
00074 phiMax = parameters.getParameter<double>("phiMax");
00075 phiGlbTrack.push_back(dbe->book1D(histname+"Glb_phi", "#phi_{GLB}", phiBin, phiMin, phiMax));
00076 phiGlbTrack[0]->setAxisTitle("rad");
00077 phiGlbTrack.push_back(dbe->book1D(histname+"Tk_phi", "#phi_{TKfromGLB}", phiBin, phiMin, phiMax));
00078 phiGlbTrack[1]->setAxisTitle("rad");
00079 phiGlbTrack.push_back(dbe->book1D(histname+"Sta_phi", "#phi_{STAfromGLB}", phiBin, phiMin, phiMax));
00080 phiGlbTrack[2]->setAxisTitle("rad");
00081 phiTight = dbe->book1D("TightMuon_phi", "#phi_{GLB}", phiBin, phiMin, phiMax);
00082 phiTrack = dbe->book1D("TkMuon_phi", "#phi_{TK}", phiBin, phiMin, phiMax);
00083 phiTrack->setAxisTitle("rad");
00084 phiStaTrack = dbe->book1D("StaMuon_phi", "#phi_{STA}", phiBin, phiMin, phiMax);
00085 phiStaTrack->setAxisTitle("rad");
00086
00087
00088 chi2Bin = parameters.getParameter<int>("chi2Bin");
00089 chi2Min = parameters.getParameter<double>("chi2Min");
00090 chi2Max = parameters.getParameter<double>("chi2Max");
00091 chi2OvDFGlbTrack.push_back(dbe->book1D(histname+"Glb_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max));
00092 chi2OvDFGlbTrack.push_back(dbe->book1D(histname+"Tk_chi2OverDf", "#chi_{2}OverDF_{TKfromGLB}", phiBin, chi2Min, chi2Max));
00093 chi2OvDFGlbTrack.push_back(dbe->book1D(histname+"Sta_chi2OverDf", "#chi_{2}OverDF_{STAfromGLB}", chi2Bin, chi2Min, chi2Max));
00094 chi2OvDFTight = dbe->book1D("TightMuon_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max);
00095 chi2OvDFTrack = dbe->book1D("TkMuon_chi2OverDf", "#chi_{2}OverDF_{TK}", chi2Bin, chi2Min, chi2Max);
00096 chi2OvDFStaTrack = dbe->book1D("StaMuon_chi2OverDf", "#chi_{2}OverDF_{STA}", chi2Bin, chi2Min, chi2Max);
00097
00098
00099 ptBin = parameters.getParameter<int>("ptBin");
00100 ptMin = parameters.getParameter<double>("ptMin");
00101 ptMax = parameters.getParameter<double>("ptMax");
00102 ptGlbTrack.push_back(dbe->book1D(histname+"Glb_pt", "pt_{GLB}", ptBin, ptMin, ptMax));
00103 ptGlbTrack[0]->setAxisTitle("GeV");
00104 ptGlbTrack.push_back(dbe->book1D(histname+"Tk_pt", "pt_{TKfromGLB}", ptBin, ptMin, ptMax));
00105 ptGlbTrack[1]->setAxisTitle("GeV");
00106 ptGlbTrack.push_back(dbe->book1D(histname+"Sta_pt", "pt_{STAfromGLB}", ptBin, ptMin, ptMax));
00107 ptGlbTrack[2]->setAxisTitle("GeV");
00108 ptTight = dbe->book1D("TightMuon_pt", "pt_{GLB}", ptBin, ptMin, ptMax);
00109 ptTight->setAxisTitle("GeV");
00110 ptTrack = dbe->book1D("TkMuon_pt", "pt_{TK}", ptBin, ptMin, ptMax);
00111 ptTrack->setAxisTitle("GeV");
00112 ptStaTrack = dbe->book1D("StaMuon_pt", "pt_{STA}", ptBin, ptMin, ptMax);
00113 ptStaTrack->setAxisTitle("GeV");
00114 }
00115
00116 void MuonRecoOneHLT::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup){
00117 #ifdef DEBUG
00118 cout << "[MuonRecoOneHLT] beginRun " << endl;
00119 cout << "[MuonRecoOneHLT] Is MuonEventFlag On? "<< _SignleMuonEventFlag->on() << endl;
00120 #endif
00121 if ( _SingleMuonEventFlag->on() ) _SingleMuonEventFlag->initRun( iRun, iSetup );
00122 if ( _DoubleMuonEventFlag->on() ) _DoubleMuonEventFlag->initRun( iRun, iSetup );
00123
00124 if (_SingleMuonEventFlag->on() && _SingleMuonEventFlag->expressionsFromDB(_SingleMuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00125 singlemuonExpr_ = _SingleMuonEventFlag->expressionsFromDB(_SingleMuonEventFlag->hltDBKey(),iSetup);
00126 if (_DoubleMuonEventFlag->on() && _DoubleMuonEventFlag->expressionsFromDB(_DoubleMuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00127 singlemuonExpr_ = _DoubleMuonEventFlag->expressionsFromDB(_DoubleMuonEventFlag->hltDBKey(),iSetup);
00128 }
00129 void MuonRecoOneHLT::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup,
00130
00131 const edm::TriggerResults& triggerResults) {
00132 #ifdef DEBUG
00133 cout << "[MuonRecoOneHLT] analyze "<< endl;
00134 #endif
00135
00136
00137 edm::Handle<reco::MuonCollection> muons;
00138 iEvent.getByLabel(theMuonCollectionLabel,muons);
00139
00140
00141 std::map<float,reco::Muon> muonMap;
00142 for (reco::MuonCollection::const_iterator recoMu = muons->begin(); recoMu!=muons->end(); ++recoMu){
00143 muonMap[recoMu->pt()] = *recoMu;
00144 }
00145 std::vector<reco::Muon> LeadingMuon;
00146 for( std::map<float,reco::Muon>::reverse_iterator rit=muonMap.rbegin(); rit!=muonMap.rend(); ++rit){
00147 LeadingMuon.push_back( (*rit).second );
00148 }
00149
00150 reco::BeamSpot beamSpot;
00151 Handle<reco::BeamSpot> beamSpotHandle;
00152 iEvent.getByLabel("offlineBeamSpot", beamSpotHandle);
00153 beamSpot = *beamSpotHandle;
00154
00155 const edm::TriggerNames& triggerNames = iEvent.triggerNames(triggerResults);
00156 const unsigned int nTrig(triggerNames.size());
00157 bool _trig_SingleMu = false;
00158 bool _trig_DoubleMu = false;
00159 for (unsigned int i=0;i<nTrig;++i){
00160 if (triggerNames.triggerName(i).find(singlemuonExpr_[0].substr(0,singlemuonExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00161 _trig_SingleMu = true;
00162 if (triggerNames.triggerName(i).find(doublemuonExpr_[0].substr(0,doublemuonExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00163 _trig_DoubleMu = true;
00164 }
00165 #ifdef DEBUG
00166 cout << "[MuonRecoOneHLT] Trigger Fired ? "<< _trig_SingleMu << endl;
00167 #endif
00168
00169 if (!_trig_SingleMu && !_trig_DoubleMu) return;
00170 if (LeadingMuon.size() == 0) return;
00171
00172
00173
00174 if(LeadingMuon[0].isGlobalMuon()) {
00175 LogTrace(metname)<<"[MuonRecoOneHLT] The mu is global - filling the histos";
00176 if(LeadingMuon[0].isTrackerMuon() && LeadingMuon[0].isStandAloneMuon()) muReco->Fill(1);
00177 if(!(LeadingMuon[0].isTrackerMuon()) && LeadingMuon[0].isStandAloneMuon()) muReco->Fill(2);
00178 if(!LeadingMuon[0].isStandAloneMuon())
00179 LogTrace(metname)<<"[MuonRecoOneHLT] ERROR: the mu is global but not standalone!";
00180
00181
00182 reco::TrackRef recoCombinedGlbTrack = LeadingMuon[0].combinedMuon();
00183
00184 reco::TrackRef recoTkGlbTrack = LeadingMuon[0].track();
00185
00186 reco::TrackRef recoStaGlbTrack = LeadingMuon[0].standAloneMuon();
00187
00188 etaGlbTrack[0]->Fill(recoCombinedGlbTrack->eta());
00189 etaGlbTrack[1]->Fill(recoTkGlbTrack->eta());
00190 etaGlbTrack[2]->Fill(recoStaGlbTrack->eta());
00191
00192 phiGlbTrack[0]->Fill(recoCombinedGlbTrack->phi());
00193 phiGlbTrack[1]->Fill(recoTkGlbTrack->phi());
00194 phiGlbTrack[2]->Fill(recoStaGlbTrack->phi());
00195
00196 chi2OvDFGlbTrack[0]->Fill(recoCombinedGlbTrack->normalizedChi2());
00197 chi2OvDFGlbTrack[1]->Fill(recoTkGlbTrack->normalizedChi2());
00198 chi2OvDFGlbTrack[2]->Fill(recoStaGlbTrack->normalizedChi2());
00199
00200 ptGlbTrack[0]->Fill(recoCombinedGlbTrack->pt());
00201 ptGlbTrack[1]->Fill(recoTkGlbTrack->pt());
00202 ptGlbTrack[2]->Fill(recoStaGlbTrack->pt());
00203 }
00204
00205 if (LeadingMuon[0].isGlobalMuon() &&
00206 LeadingMuon[0].isTrackerMuon() &&
00207 LeadingMuon[0].combinedMuon()->normalizedChi2()<10. &&
00208 LeadingMuon[0].combinedMuon()->hitPattern().numberOfValidMuonHits()>0 &&
00209 fabs(LeadingMuon[0].combinedMuon()->dxy(beamSpot.position()))<0.2 &&
00210 LeadingMuon[0].combinedMuon()->hitPattern().numberOfValidPixelHits()>0 &&
00211 LeadingMuon[0].numberOfMatches() > 1){
00212
00213 LogTrace(metname)<<"[MuonRecoOneHLT] The mu is tracker only - filling the histos";
00214
00215 reco::TrackRef recoCombinedGlbTrack = LeadingMuon[0].combinedMuon();
00216
00217 etaTight->Fill(recoCombinedGlbTrack->eta());
00218 phiTight->Fill(recoCombinedGlbTrack->phi());
00219 chi2OvDFTight->Fill(recoCombinedGlbTrack->normalizedChi2());
00220 ptTight->Fill(recoCombinedGlbTrack->pt());
00221 }
00222
00223
00224 if(LeadingMuon[0].isTrackerMuon() && !(LeadingMuon[0].isGlobalMuon())) {
00225 LogTrace(metname)<<"[MuonRecoOneHLT] The mu is tracker only - filling the histos";
00226 if(LeadingMuon[0].isStandAloneMuon()) muReco->Fill(3);
00227 if(!(LeadingMuon[0].isStandAloneMuon())) muReco->Fill(4);
00228
00229
00230 reco::TrackRef recoTrack = LeadingMuon[0].track();
00231
00232 etaTrack->Fill(recoTrack->eta());
00233 phiTrack->Fill(recoTrack->phi());
00234 chi2OvDFTrack->Fill(recoTrack->normalizedChi2());
00235 ptTrack->Fill(recoTrack->pt());
00236 }
00237
00238
00239 if(LeadingMuon[0].isStandAloneMuon() && !(LeadingMuon[0].isGlobalMuon())) {
00240 LogTrace(metname)<<"[MuonRecoOneHLT] The mu is STA only - filling the histos";
00241 if(!(LeadingMuon[0].isTrackerMuon())) muReco->Fill(5);
00242
00243
00244 reco::TrackRef recoStaTrack = LeadingMuon[0].standAloneMuon();
00245
00246 etaStaTrack->Fill(recoStaTrack->eta());
00247 phiStaTrack->Fill(recoStaTrack->phi());
00248 chi2OvDFStaTrack->Fill(recoStaTrack->normalizedChi2());
00249 ptStaTrack->Fill(recoStaTrack->pt());
00250 }
00251
00252 if(LeadingMuon[0].isCaloMuon() && !(LeadingMuon[0].isGlobalMuon()) && !(LeadingMuon[0].isTrackerMuon()) && !(LeadingMuon[0].isStandAloneMuon()))
00253 muReco->Fill(6);
00254 }