00001
00002
00003
00004
00005
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "DQM/HLTEvF/interface/HLTMuonRecoDQMSource.h"
00022 #include "DQMServices/Core/interface/DQMStore.h"
00023 #include "DataFormats/Common/interface/Handle.h"
00024 #include "FWCore/Framework/interface/Event.h"
00025 #include "FWCore/Framework/interface/EventSetup.h"
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 #include "FWCore/ServiceRegistry/interface/Service.h"
00028 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidate.h"
00029 #include "DataFormats/RecoCandidate/interface/RecoChargedCandidateFwd.h"
00030 #include "DataFormats/TrackReco/interface/Track.h"
00031 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00032 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00033 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00034 #include "DataFormats/MuonSeed/interface/L2MuonTrajectorySeed.h"
00035 #include "DataFormats/MuonSeed/interface/L2MuonTrajectorySeedCollection.h"
00036 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeed.h"
00037 #include "DataFormats/MuonSeed/interface/L3MuonTrajectorySeedCollection.h"
00038 #include "DataFormats/L1Trigger/interface/L1MuonParticleFwd.h"
00039 #include "DataFormats/L1Trigger/interface/L1MuonParticle.h"
00040 #include "TMath.h"
00041
00042
00043 using namespace std;
00044 using namespace edm;
00045 using namespace reco;
00046 using namespace l1extra;
00047
00048
00049
00050 HLTMuonRecoDQMSource::HLTMuonRecoDQMSource( const edm::ParameterSet& parameters_ ) :counterEvt_(0)
00051
00052 {
00053 verbose_ = parameters_.getUntrackedParameter < bool > ("verbose", false);
00054 monitorName_ = parameters_.getUntrackedParameter<string>("monitorName","HLT/HLTMuon");
00055 level_ = parameters_.getUntrackedParameter<int>("Level",2);
00056 prescaleEvt_ = parameters_.getUntrackedParameter<int>("prescaleEvt", -1);
00057 candCollectionTag_ = parameters_.getUntrackedParameter<InputTag>("CandMuonTag",edm::InputTag("hltL2MuonCandidates"));
00058 beamSpotTag_ = parameters_.getUntrackedParameter<InputTag>("BeamSpotTag",edm::InputTag("offlineBeamSpot"));
00059 l2seedscollectionTag_ = parameters_.getUntrackedParameter<InputTag>("l2MuonSeedTag",edm::InputTag("hltL2MuonSeeds"));
00060
00061 dbe_ = 0 ;
00062 if (parameters_.getUntrackedParameter < bool > ("DQMStore", false)) {
00063 dbe_ = Service < DQMStore > ().operator->();
00064 dbe_->setVerbose(0);
00065 }
00066
00067 outputFile_ =
00068 parameters_.getUntrackedParameter < std::string > ("outputFile", "");
00069 if (outputFile_.size() != 0) {
00070 if (verbose_) std::cout << "Muon HLT Monitoring histograms will be saved to "
00071 << outputFile_ << std::endl;
00072 }
00073 else {
00074 outputFile_ = "HLTMuonDQM.root";
00075 }
00076
00077 bool disable =
00078 parameters_.getUntrackedParameter < bool > ("disableROOToutput", true);
00079 if (disable) {
00080 outputFile_ = "";
00081 }
00082
00083 if (dbe_ != NULL) {
00084 dbe_->setCurrentFolder("HLT/HLTMuon");
00085 }
00086
00087
00088 }
00089
00090
00091 HLTMuonRecoDQMSource::~HLTMuonRecoDQMSource()
00092 {
00093
00094
00095
00096
00097 }
00098
00099
00100
00101 void HLTMuonRecoDQMSource::beginJob(const EventSetup& context){
00102
00103 if (dbe_) {
00104 dbe_->setCurrentFolder("monitorName_");
00105 if (monitorName_ != "" ) monitorName_ = monitorName_+"/" ;
00106 if (verbose_)cout << "===>DQM event prescale = " << prescaleEvt_ << " events "<< endl;
00107
00108
00110 const int NBINS = 100; XMIN = 0; XMAX = 50;
00111
00112
00113 char name[512], title[512];
00114 sprintf(name,"Level%i",level_);
00115 dbe_->setCurrentFolder(monitorName_+name);
00116 sprintf(name,"HLTMuonL%i_NMu",level_);
00117 sprintf(title,"L%i number of muons",level_);
00118 hNMu= dbe_->book1D(name,title, 5, 0., 5.);
00119 hNMu->setAxisTitle("Number of muons", 1);
00120 sprintf(name,"HLTMuonL%i_pt",level_);
00121 sprintf(title,"L%i Pt",level_);
00122 hpt = dbe_->book1D(name,title, NBINS, 0., 100);
00123 hpt->setAxisTitle("Pt", 1);
00124 sprintf(name,"HLTMuonL%i_eta",level_);
00125 sprintf(title,"L%i Muon #eta",level_);
00126 heta = dbe_->book1D(name,title, NBINS, -2.5, 2.5);
00127 heta->setAxisTitle("#eta", 1);
00128 sprintf(name,"HLTMuonL%i_phi",level_);
00129 sprintf(title,"L%i Muon #phi",level_);
00130 hphi = dbe_->book1D(name,title, NBINS, -3.15, 3.15);
00131 hphi->setAxisTitle("#phi", 1);
00132 sprintf(name,"HLTMuonL%i_etaphi",level_);
00133 sprintf(title,"L%i Muon #eta vs #phi",level_);
00134 hetaphi = dbe_->book2D(name,title, NBINS, -3.15, 3.15,NBINS,-2.5, 2.5);
00135 hetaphi->setAxisTitle("#phi", 1);
00136 hetaphi->setAxisTitle("#eta", 2);
00137 sprintf(name,"HLTMuonL%i_ptphi",level_);
00138 sprintf(title,"L%i Muon pt vs #phi",level_);
00139 hptphi = dbe_->book2D(name,title, NBINS, 0., 100.,NBINS,-3.15, 3.15);
00140 hptphi->setAxisTitle("pt", 1);
00141 hptphi->setAxisTitle("#phi", 2);
00142 sprintf(name,"HLTMuonL%i_pteta",level_);
00143 sprintf(title,"L%i Muon pt vs #eta",level_);
00144 hpteta = dbe_->book2D(name,title, NBINS, 0., 100.,NBINS,-2.5, 2.5);
00145 hpteta->setAxisTitle("pt", 1);
00146 hpteta->setAxisTitle("#eta", 2);
00147 sprintf(name,"HLTMuonL%i_nhit",level_);
00148 sprintf(title,"L%i Number of Valid Hits",level_);
00149 hnhit = dbe_->book1D(name,title, NBINS, 0., 100.);
00150 hnhit->setAxisTitle("Number of Valid Hits", 1);
00151 sprintf(name,"HLTMuonL%i_charge",level_);
00152 sprintf(title,"L%i Muon Charge",level_);
00153 hcharge = dbe_->book1D(name,title, 3, -1.5, 1.5);
00154 hcharge->setAxisTitle("Charge", 1);
00155 sprintf(name,"HLTMuonL%i_dr",level_);
00156 sprintf(title,"L%i Muon radial impact vs BeamSpot",level_);
00157 hdr = dbe_->book1D(name,title, NBINS, -0.3, 0.3);
00158 hdr->setAxisTitle("R Impact (cm) vs BeamSpot", 1);
00159 sprintf(name,"HLTMuonL%i_d0",level_);
00160 sprintf(title,"L%i Muon radial impact vs (0,0)",level_);
00161 hd0 = dbe_->book1D(name,title, NBINS, -0.3, 0.3);
00162 hd0->setAxisTitle("R Impact (cm) vs 0,0", 1);
00163 sprintf(name,"HLTMuonL%i_dz",level_);
00164 sprintf(title,"L%i Muon Z impact",level_);
00165 hdz = dbe_->book1D(name,title, NBINS, -25., 25.);
00166 hdz->setAxisTitle("Z impact (cm)", 1);
00167 sprintf(name,"HLTMuonL%i_err0",level_);
00168 sprintf(title,"L%i Muon Error on Pt",level_);
00169 herr0 = dbe_->book1D(name,title,NBINS, 0., 0.03);
00170 herr0->setAxisTitle("Error on Pt", 1);
00171 sprintf(name,"HLTMuonL%i_DiMuMass",level_);
00172 sprintf(title,"L%i Opposite charge DiMuon invariant Mass",level_);
00173 hdimumass= dbe_->book1D(name,title, NBINS, 0., 150.);
00174 hdimumass->setAxisTitle("Di Muon Invariant Mass (GeV)");
00175 sprintf(name,"HLTMuonL%i_drphi",level_);
00176 sprintf(title,"L%i #Deltar vs #phi",level_);
00177 hdrphi = dbe_->bookProfile(name,title, NBINS, -3.15, 3.15,1,-999.,999.,"s");
00178 hdrphi->setAxisTitle("#phi", 1);
00179 hdrphi->setAxisTitle("#Deltar", 2);
00180 sprintf(name,"HLTMuonL%i_d0phi",level_);
00181 sprintf(title,"L%i #Delta0 vs #phi",level_);
00182 hd0phi = dbe_->bookProfile(name,title, NBINS, -3.15, 3.15,1,-999.,999.,"s");
00183 hd0phi->setAxisTitle("#phi", 1);
00184 hd0phi->setAxisTitle("#Delta0", 2);
00185 sprintf(name,"HLTMuonL%i_dzeta",level_);
00186 sprintf(title,"L%i #Deltaz vs #eta",level_);
00187 hdzeta = dbe_->bookProfile(name,title, NBINS,-2.5, 2.5,1,-999.,999.,"s");
00188 hdzeta->setAxisTitle("#eta", 1);
00189 hdzeta->setAxisTitle("#Deltaz", 2);
00190 sprintf(name,"Level%i",level_-1);
00191 dbe_->setCurrentFolder(monitorName_+name);
00192 sprintf(name,"HLTMuonL%i_ptres",level_-1);
00193 sprintf(title,"L%iMuon1/Pt - L%iMuon1/Pt",level_-1,level_);
00194 hptres = dbe_->book1D(name,title, NBINS, -0.1, 0.1);
00195 sprintf(title,"1/PtL%i - 1/PtL%i",level_-1,level_);
00196 hptres->setAxisTitle(title, 1);
00197 sprintf(name,"HLTMuonL%i_etares",level_-1);
00198 sprintf(title,"L%i Muon #Delta#eta (wrt L%i)",level_-1,level_);
00199 hetares =dbe_->book1D(name,title, NBINS, -0.1, 0.1);
00200 hetares->setAxisTitle("#Delta#eta", 1);
00201 sprintf(name,"HLTMuonL%i_phires",level_-1);
00202 sprintf(title,"L%i Muon #Delta#phi (wrt L%i)",level_-1,level_);
00203 hphires =dbe_->book1D(name,title, NBINS, -0.1, 0.1);
00204 hphires->setAxisTitle("#Delta#phi", 1);
00205 sprintf(name,"HLTMuonL%i_phiresphi",level_-1);
00206 sprintf(title,"L%i Muon #Delta#phi vs #phi ",level_-1);
00207 hphiresphi =dbe_->bookProfile(name,title, NBINS, -3.15, 3.15,1,-999.,999.,"s");
00208 hphiresphi->setAxisTitle("<#Delta#phi>", 2);
00209 hphiresphi->setAxisTitle("#phi", 1);
00210 sprintf(name,"HLTMuonL%i_etareseta",level_-1);
00211 sprintf(title,"L%i Muon #Delta#eta vs #eta ",level_-1);
00212 hetareseta =dbe_->bookProfile(name,title, NBINS,-2.5, 2.5,1,-999.,999.,"s");
00213 hetareseta->setAxisTitle("<#Delta#eta>", 2);
00214 hetareseta->setAxisTitle("#eta", 1);
00215 if(verbose_)dbe_->showDirStructure();
00216
00217 const unsigned int detector_id = 2<<28;
00218 dbe_->tagContents(monitorName_, detector_id);
00219 }
00220 }
00221
00222
00223 void HLTMuonRecoDQMSource::beginRun(const edm::Run& r, const EventSetup& context) {
00224
00225 vector<MonitorElement*> AllME=dbe_->getAllContents(monitorName_);
00226 vector<MonitorElement*>::iterator me=AllME.begin();
00227 for ( ; me != AllME.end() ; ++me ){
00228 (*me)->Reset();
00229 }
00230 }
00231
00232
00233 void HLTMuonRecoDQMSource::beginLuminosityBlock(const LuminosityBlock& lumiSeg,
00234 const EventSetup& context) {
00235
00236 }
00237
00238
00239 void HLTMuonRecoDQMSource::analyze(const Event& iEvent,
00240 const EventSetup& iSetup )
00241 {
00242 if ( !dbe_) return;
00243 counterEvt_++;
00244 if (prescaleEvt_ > 0 && counterEvt_%prescaleEvt_!=0) return;
00245 if (verbose_)cout << " processing conterEvt_: " << counterEvt_ <<endl;
00246
00247 Handle<RecoChargedCandidateCollection> mucands;
00248 iEvent.getByLabel (candCollectionTag_,mucands);
00249
00250 reco::BeamSpot beamSpot;
00251 Handle<reco::BeamSpot> recoBeamSpotHandle;
00252 iEvent.getByLabel(beamSpotTag_,recoBeamSpotHandle);
00253 if (!recoBeamSpotHandle.failedToGet()) beamSpot = *recoBeamSpotHandle;
00254 RecoChargedCandidateCollection::const_iterator cand,cand2;
00255 if (!mucands.failedToGet()) {
00256 if (verbose_)cout << " filling Reco stuff " << endl;
00257 hNMu->Fill(mucands->size());
00258 for (cand=mucands->begin(); cand!=mucands->end(); ++cand) {
00259 TrackRef tk = cand->get<TrackRef>();
00260
00261 hpt->Fill(tk->pt());
00262 hcharge->Fill(tk->charge());
00263 if ( tk->charge() != 0 ) {
00264 heta->Fill(tk->eta());
00265 hphi->Fill(tk->phi());
00266 hetaphi->Fill(tk->phi(),tk->eta());
00267 hptphi->Fill(tk->pt(),tk->phi());
00268 hpteta->Fill(tk->pt(),tk->eta());
00269 hnhit->Fill(tk->numberOfValidHits());
00270 hd0->Fill(tk->d0());
00271 if (!recoBeamSpotHandle.failedToGet()){
00272 hdr->Fill(tk->dxy(beamSpot.position()));
00273 hdrphi->Fill(tk->phi(),tk->dxy(beamSpot.position()));
00274 }
00275 hd0phi->Fill(tk->phi(),tk->d0());
00276 hdz->Fill(tk->dz());
00277 hdzeta->Fill(tk->eta(),tk->dz());
00278 herr0->Fill(tk->error(0));
00279 cand2=cand;
00280 ++cand2;
00281 for (; cand2!=mucands->end(); cand2++) {
00282 TrackRef tk2=cand2->get<TrackRef>();
00283 if ( tk->charge()*tk2->charge() == -1 ){
00284 double mass=(cand->p4()+cand2->p4()).M();
00285 hdimumass->Fill(mass);
00286 }
00287 }
00288 if ( level_ == 3 ) {
00289 TrackRef l2tk=tk->seedRef().castTo<Ref<L3MuonTrajectorySeedCollection> >()->l2Track();
00290 if(tk->pt()*l2tk->pt() != 0 )hptres->Fill(1/tk->pt() - 1/l2tk->pt());
00291 hetares->Fill(tk->eta()-l2tk->eta());
00292 hetareseta->Fill(tk->eta(),tk->eta()-l2tk->eta());
00293 hphires->Fill(tk->phi()-l2tk->phi());
00294 double dphi=tk->phi()-l2tk->phi();
00295 if (dphi>TMath::TwoPi())dphi-=2*TMath::TwoPi();
00296 else if (dphi<-TMath::TwoPi()) dphi+=TMath::TwoPi();
00297 hphiresphi->Fill(tk->phi(),dphi);
00298 } else {
00299 Handle<L2MuonTrajectorySeedCollection> museeds;
00300 iEvent.getByLabel (l2seedscollectionTag_,museeds);
00301 if (!museeds.failedToGet()){
00302 RefToBase<TrajectorySeed> seed=tk->seedRef();
00303 L1MuonParticleRef l1ref;
00304 for(uint iMuSeed=0 ; iMuSeed!=museeds->size(); ++iMuSeed){
00305 Ref<L2MuonTrajectorySeedCollection> l2seed(museeds,iMuSeed);
00306 if (l2seed.id()==seed.id() && l2seed.key()==seed.key()){
00307 l1ref = l2seed->l1Particle();
00308 break;
00309 }
00310 }
00311 if( tk->pt()*l1ref->pt() != 0 )hptres->Fill(1/tk->pt() - 1/l1ref->pt());
00312 hetares->Fill(tk->eta()-l1ref->eta());
00313 hetareseta->Fill(tk->eta(),tk->eta()-l1ref->eta());
00314 hphires->Fill(tk->phi()-l1ref->phi());
00315 double dphi=tk->phi()-l1ref->phi();
00316 if (dphi>TMath::TwoPi())dphi-=2*TMath::TwoPi();
00317 else if (dphi<-TMath::TwoPi()) dphi+=TMath::TwoPi();
00318 hphiresphi->Fill(tk->phi(),dphi);
00319 }
00320 }
00321 } else LogWarning("HLTMonMuon")<<"stop filling candidate with update@Vtx failure";
00322 }
00323 }
00324 }
00325
00326
00327
00328
00329
00330 void HLTMuonRecoDQMSource::endLuminosityBlock(const LuminosityBlock& lumiSeg,
00331 const EventSetup& context) {
00332 }
00333
00334 void HLTMuonRecoDQMSource::endRun(const Run& r, const EventSetup& context){
00335 }
00336
00337 void HLTMuonRecoDQMSource::endJob(){
00338 LogInfo("HLTMonMuon") << "analyzed " << counterEvt_ << " events";
00339
00340 if (outputFile_.size() != 0 && dbe_)
00341 dbe_->save(outputFile_);
00342
00343 return;
00344 }