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
00017 #include "DataFormats/VertexReco/interface/Vertex.h"
00018 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00019 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
00020
00021
00022
00023 #include <string>
00024 #include "TMath.h"
00025 using namespace std;
00026 using namespace edm;
00027
00028
00029
00030
00031 MuonRecoOneHLT::MuonRecoOneHLT(const edm::ParameterSet& pSet, MuonServiceProxy *theService):MuonAnalyzerBase(theService) {
00032 parameters = pSet;
00033
00034 ParameterSet muonparms = parameters.getParameter<edm::ParameterSet>("SingleMuonTrigger");
00035 ParameterSet dimuonparms = parameters.getParameter<edm::ParameterSet>("DoubleMuonTrigger");
00036 _SingleMuonEventFlag = new GenericTriggerEventFlag( muonparms );
00037 _DoubleMuonEventFlag = new GenericTriggerEventFlag( dimuonparms );
00038
00039
00040 singlemuonExpr_ = muonparms.getParameter<std::vector<std::string> >("hltPaths");
00041 doublemuonExpr_ = dimuonparms.getParameter<std::vector<std::string> >("hltPaths");
00042 }
00043
00044
00045 MuonRecoOneHLT::~MuonRecoOneHLT() {
00046 delete _SingleMuonEventFlag;
00047 delete _DoubleMuonEventFlag;
00048 }
00049 void MuonRecoOneHLT::beginJob(DQMStore * dbe) {
00050 #ifdef DEBUG
00051 cout << "[MuonRecoOneHLT] beginJob " << endl;
00052 #endif
00053 dbe->setCurrentFolder("Muons/MuonRecoOneHLT");
00054
00055 theMuonCollectionLabel = parameters.getParameter<edm::InputTag>("MuonCollection");
00056 vertexTag = parameters.getParameter<edm::InputTag>("vertexLabel");
00057 bsTag = parameters.getParameter<edm::InputTag>("bsLabel");
00058
00059
00060 muReco = dbe->book1D("Muon_Reco", "Muon Reconstructed Tracks", 6, 1, 7);
00061 muReco->setBinLabel(1,"glb+tk+sta");
00062 muReco->setBinLabel(2,"glb+sta");
00063 muReco->setBinLabel(3,"tk+sta");
00064 muReco->setBinLabel(4,"tk");
00065 muReco->setBinLabel(5,"sta");
00066 muReco->setBinLabel(6,"calo");
00067
00068
00069 etaBin = parameters.getParameter<int>("etaBin");
00070 etaMin = parameters.getParameter<double>("etaMin");
00071 etaMax = parameters.getParameter<double>("etaMax");
00072
00073 std::string histname = "GlbMuon_";
00074 etaGlbTrack.push_back(dbe->book1D(histname+"Glb_eta", "#eta_{GLB}", etaBin, etaMin, etaMax));
00075 etaGlbTrack.push_back(dbe->book1D(histname+"Tk_eta", "#eta_{TKfromGLB}", etaBin, etaMin, etaMax));
00076 etaGlbTrack.push_back(dbe->book1D(histname+"Sta_eta", "#eta_{STAfromGLB}", etaBin, etaMin, etaMax));
00077 etaTight = dbe->book1D("TightMuon_eta", "#eta_{GLB}", etaBin, etaMin, etaMax);
00078 etaTrack = dbe->book1D("TkMuon_eta", "#eta_{TK}", etaBin, etaMin, etaMax);
00079 etaStaTrack = dbe->book1D("StaMuon_eta", "#eta_{STA}", etaBin, etaMin, etaMax);
00080
00081
00082 phiBin = parameters.getParameter<int>("phiBin");
00083 phiMin = parameters.getParameter<double>("phiMin");
00084 phiMax = parameters.getParameter<double>("phiMax");
00085 phiGlbTrack.push_back(dbe->book1D(histname+"Glb_phi", "#phi_{GLB}", phiBin, phiMin, phiMax));
00086 phiGlbTrack[0]->setAxisTitle("rad");
00087 phiGlbTrack.push_back(dbe->book1D(histname+"Tk_phi", "#phi_{TKfromGLB}", phiBin, phiMin, phiMax));
00088 phiGlbTrack[1]->setAxisTitle("rad");
00089 phiGlbTrack.push_back(dbe->book1D(histname+"Sta_phi", "#phi_{STAfromGLB}", phiBin, phiMin, phiMax));
00090 phiGlbTrack[2]->setAxisTitle("rad");
00091 phiTight = dbe->book1D("TightMuon_phi", "#phi_{GLB}", phiBin, phiMin, phiMax);
00092 phiTrack = dbe->book1D("TkMuon_phi", "#phi_{TK}", phiBin, phiMin, phiMax);
00093 phiTrack->setAxisTitle("rad");
00094 phiStaTrack = dbe->book1D("StaMuon_phi", "#phi_{STA}", phiBin, phiMin, phiMax);
00095 phiStaTrack->setAxisTitle("rad");
00096
00097
00098 chi2Bin = parameters.getParameter<int>("chi2Bin");
00099 chi2Min = parameters.getParameter<double>("chi2Min");
00100 chi2Max = parameters.getParameter<double>("chi2Max");
00101 chi2OvDFGlbTrack.push_back(dbe->book1D(histname+"Glb_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max));
00102 chi2OvDFGlbTrack.push_back(dbe->book1D(histname+"Tk_chi2OverDf", "#chi_{2}OverDF_{TKfromGLB}", phiBin, chi2Min, chi2Max));
00103 chi2OvDFGlbTrack.push_back(dbe->book1D(histname+"Sta_chi2OverDf", "#chi_{2}OverDF_{STAfromGLB}", chi2Bin, chi2Min, chi2Max));
00104 chi2OvDFTight = dbe->book1D("TightMuon_chi2OverDf", "#chi_{2}OverDF_{GLB}", chi2Bin, chi2Min, chi2Max);
00105 chi2OvDFTrack = dbe->book1D("TkMuon_chi2OverDf", "#chi_{2}OverDF_{TK}", chi2Bin, chi2Min, chi2Max);
00106 chi2OvDFStaTrack = dbe->book1D("StaMuon_chi2OverDf", "#chi_{2}OverDF_{STA}", chi2Bin, chi2Min, chi2Max);
00107
00108
00109 ptBin = parameters.getParameter<int>("ptBin");
00110 ptMin = parameters.getParameter<double>("ptMin");
00111 ptMax = parameters.getParameter<double>("ptMax");
00112 ptGlbTrack.push_back(dbe->book1D(histname+"Glb_pt", "pt_{GLB}", ptBin, ptMin, ptMax));
00113 ptGlbTrack[0]->setAxisTitle("GeV");
00114 ptGlbTrack.push_back(dbe->book1D(histname+"Tk_pt", "pt_{TKfromGLB}", ptBin, ptMin, ptMax));
00115 ptGlbTrack[1]->setAxisTitle("GeV");
00116 ptGlbTrack.push_back(dbe->book1D(histname+"Sta_pt", "pt_{STAfromGLB}", ptBin, ptMin, ptMax));
00117 ptGlbTrack[2]->setAxisTitle("GeV");
00118 ptTight = dbe->book1D("TightMuon_pt", "pt_{GLB}", ptBin, ptMin, ptMax);
00119 ptTight->setAxisTitle("GeV");
00120 ptTrack = dbe->book1D("TkMuon_pt", "pt_{TK}", ptBin, ptMin, ptMax);
00121 ptTrack->setAxisTitle("GeV");
00122 ptStaTrack = dbe->book1D("StaMuon_pt", "pt_{STA}", ptBin, ptMin, ptMax);
00123 ptStaTrack->setAxisTitle("GeV");
00124 }
00125
00126 void MuonRecoOneHLT::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup){
00127 #ifdef DEBUG
00128 cout << "[MuonRecoOneHLT] beginRun " << endl;
00129 cout << "[MuonRecoOneHLT] Is MuonEventFlag On? "<< _SignleMuonEventFlag->on() << endl;
00130 #endif
00131 if ( _SingleMuonEventFlag->on() ) _SingleMuonEventFlag->initRun( iRun, iSetup );
00132 if ( _DoubleMuonEventFlag->on() ) _DoubleMuonEventFlag->initRun( iRun, iSetup );
00133
00134 if (_SingleMuonEventFlag->on() && _SingleMuonEventFlag->expressionsFromDB(_SingleMuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00135 singlemuonExpr_ = _SingleMuonEventFlag->expressionsFromDB(_SingleMuonEventFlag->hltDBKey(),iSetup);
00136 if (_DoubleMuonEventFlag->on() && _DoubleMuonEventFlag->expressionsFromDB(_DoubleMuonEventFlag->hltDBKey(), iSetup)[0] != "CONFIG_ERROR")
00137 singlemuonExpr_ = _DoubleMuonEventFlag->expressionsFromDB(_DoubleMuonEventFlag->hltDBKey(),iSetup);
00138 }
00139 void MuonRecoOneHLT::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup,
00140
00141 const edm::TriggerResults& triggerResults) {
00142 #ifdef DEBUG
00143 cout << "[MuonRecoOneHLT] analyze "<< endl;
00144 #endif
00145
00146
00147
00148
00149
00150 reco::Vertex::Point posVtx;
00151 reco::Vertex::Error errVtx;
00152
00153 unsigned int theIndexOfThePrimaryVertex = 999.;
00154
00155 edm::Handle<reco::VertexCollection> vertex;
00156 iEvent.getByLabel(vertexTag, vertex);
00157
00158 if ( vertex.isValid() ){
00159 for (unsigned int ind=0; ind<vertex->size(); ++ind) {
00160 if ( (*vertex)[ind].isValid() && !((*vertex)[ind].isFake()) ) {
00161 theIndexOfThePrimaryVertex = ind;
00162 break;
00163 }
00164 }
00165 }
00166 if (theIndexOfThePrimaryVertex<100) {
00167 posVtx = ((*vertex)[theIndexOfThePrimaryVertex]).position();
00168 errVtx = ((*vertex)[theIndexOfThePrimaryVertex]).error();
00169 } else {
00170 LogInfo("RecoMuonValidator") << "reco::PrimaryVertex not found, use BeamSpot position instead\n";
00171
00172 edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00173 iEvent.getByLabel(bsTag,recoBeamSpotHandle);
00174
00175 reco::BeamSpot bs = *recoBeamSpotHandle;
00176
00177 posVtx = bs.position();
00178 errVtx(0,0) = bs.BeamWidthX();
00179 errVtx(1,1) = bs.BeamWidthY();
00180 errVtx(2,2) = bs.sigmaZ();
00181 }
00182 const reco::Vertex thePrimaryVertex(posVtx,errVtx);
00183
00184
00185
00186
00187
00188
00189
00190 edm::Handle<reco::MuonCollection> muons;
00191 iEvent.getByLabel(theMuonCollectionLabel,muons);
00192
00193
00194 std::map<float,reco::Muon> muonMap;
00195 for (reco::MuonCollection::const_iterator recoMu = muons->begin(); recoMu!=muons->end(); ++recoMu){
00196 muonMap[recoMu->pt()] = *recoMu;
00197 }
00198 std::vector<reco::Muon> LeadingMuon;
00199 for( std::map<float,reco::Muon>::reverse_iterator rit=muonMap.rbegin(); rit!=muonMap.rend(); ++rit){
00200 LeadingMuon.push_back( (*rit).second );
00201 }
00202
00203 reco::BeamSpot beamSpot;
00204 Handle<reco::BeamSpot> beamSpotHandle;
00205 iEvent.getByLabel("offlineBeamSpot", beamSpotHandle);
00206 beamSpot = *beamSpotHandle;
00207
00208 const edm::TriggerNames& triggerNames = iEvent.triggerNames(triggerResults);
00209 const unsigned int nTrig(triggerNames.size());
00210 bool _trig_SingleMu = false;
00211 bool _trig_DoubleMu = false;
00212 for (unsigned int i=0;i<nTrig;++i){
00213 if (triggerNames.triggerName(i).find(singlemuonExpr_[0].substr(0,singlemuonExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00214 _trig_SingleMu = true;
00215 if (triggerNames.triggerName(i).find(doublemuonExpr_[0].substr(0,doublemuonExpr_[0].rfind("_v")+2))!=std::string::npos && triggerResults.accept(i))
00216 _trig_DoubleMu = true;
00217 }
00218 #ifdef DEBUG
00219 cout << "[MuonRecoOneHLT] Trigger Fired ? "<< _trig_SingleMu << endl;
00220 #endif
00221
00222 if (!_trig_SingleMu && !_trig_DoubleMu) return;
00223 if (LeadingMuon.size() == 0) return;
00224
00225
00226
00227 if(LeadingMuon[0].isGlobalMuon()) {
00228 LogTrace(metname)<<"[MuonRecoOneHLT] The mu is global - filling the histos";
00229 if(LeadingMuon[0].isTrackerMuon() && LeadingMuon[0].isStandAloneMuon()) muReco->Fill(1);
00230 if(!(LeadingMuon[0].isTrackerMuon()) && LeadingMuon[0].isStandAloneMuon()) muReco->Fill(2);
00231 if(!LeadingMuon[0].isStandAloneMuon())
00232 LogTrace(metname)<<"[MuonRecoOneHLT] ERROR: the mu is global but not standalone!";
00233
00234
00235 reco::TrackRef recoCombinedGlbTrack = LeadingMuon[0].combinedMuon();
00236
00237 reco::TrackRef recoTkGlbTrack = LeadingMuon[0].track();
00238
00239 reco::TrackRef recoStaGlbTrack = LeadingMuon[0].standAloneMuon();
00240
00241 etaGlbTrack[0]->Fill(recoCombinedGlbTrack->eta());
00242 etaGlbTrack[1]->Fill(recoTkGlbTrack->eta());
00243 etaGlbTrack[2]->Fill(recoStaGlbTrack->eta());
00244
00245 phiGlbTrack[0]->Fill(recoCombinedGlbTrack->phi());
00246 phiGlbTrack[1]->Fill(recoTkGlbTrack->phi());
00247 phiGlbTrack[2]->Fill(recoStaGlbTrack->phi());
00248
00249 chi2OvDFGlbTrack[0]->Fill(recoCombinedGlbTrack->normalizedChi2());
00250 chi2OvDFGlbTrack[1]->Fill(recoTkGlbTrack->normalizedChi2());
00251 chi2OvDFGlbTrack[2]->Fill(recoStaGlbTrack->normalizedChi2());
00252
00253 ptGlbTrack[0]->Fill(recoCombinedGlbTrack->pt());
00254 ptGlbTrack[1]->Fill(recoTkGlbTrack->pt());
00255 ptGlbTrack[2]->Fill(recoStaGlbTrack->pt());
00256 }
00257
00258 if (muon::isTightMuon(LeadingMuon[0], thePrimaryVertex) ) {
00259
00260 LogTrace(metname)<<"[MuonRecoOneHLT] The mu is tracker only - filling the histos";
00261
00262 reco::TrackRef recoCombinedGlbTrack = LeadingMuon[0].combinedMuon();
00263
00264 etaTight->Fill(recoCombinedGlbTrack->eta());
00265 phiTight->Fill(recoCombinedGlbTrack->phi());
00266 chi2OvDFTight->Fill(recoCombinedGlbTrack->normalizedChi2());
00267 ptTight->Fill(recoCombinedGlbTrack->pt());
00268 }
00269
00270
00271 if(LeadingMuon[0].isTrackerMuon() && !(LeadingMuon[0].isGlobalMuon())) {
00272 LogTrace(metname)<<"[MuonRecoOneHLT] The mu is tracker only - filling the histos";
00273 if(LeadingMuon[0].isStandAloneMuon()) muReco->Fill(3);
00274 if(!(LeadingMuon[0].isStandAloneMuon())) muReco->Fill(4);
00275
00276
00277 reco::TrackRef recoTrack = LeadingMuon[0].track();
00278
00279 etaTrack->Fill(recoTrack->eta());
00280 phiTrack->Fill(recoTrack->phi());
00281 chi2OvDFTrack->Fill(recoTrack->normalizedChi2());
00282 ptTrack->Fill(recoTrack->pt());
00283 }
00284
00285
00286 if(LeadingMuon[0].isStandAloneMuon() && !(LeadingMuon[0].isGlobalMuon())) {
00287 LogTrace(metname)<<"[MuonRecoOneHLT] The mu is STA only - filling the histos";
00288 if(!(LeadingMuon[0].isTrackerMuon())) muReco->Fill(5);
00289
00290
00291 reco::TrackRef recoStaTrack = LeadingMuon[0].standAloneMuon();
00292
00293 etaStaTrack->Fill(recoStaTrack->eta());
00294 phiStaTrack->Fill(recoStaTrack->phi());
00295 chi2OvDFStaTrack->Fill(recoStaTrack->normalizedChi2());
00296 ptStaTrack->Fill(recoStaTrack->pt());
00297 }
00298
00299 if(LeadingMuon[0].isCaloMuon() && !(LeadingMuon[0].isGlobalMuon()) && !(LeadingMuon[0].isTrackerMuon()) && !(LeadingMuon[0].isStandAloneMuon()))
00300 muReco->Fill(6);
00301 }