CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TopDiLeptonHLTOfflineDQM.cc
Go to the documentation of this file.
1 //#include <algorithm>
15 
17 
19 
20 /*Originally from DQM/Physics by R. Wolf and J. Andrea*/
21 using namespace std;
22 namespace HLTOfflineDQMTopDiLepton {
23 
24  // maximal Delta to consider
25  // hlt and reco objects matched
26  static const double DRMIN = 0.05;
27 
28  MonitorDiLepton::MonitorDiLepton(const char* label, const edm::ParameterSet& cfg, edm::ConsumesCollector&& iC) :
29  label_(label), eidPattern_(0), elecIso_(0), elecSelect_(0), muonIso_(0), muonSelect_(0), jetIDSelect_(0),
30  lowerEdge_(-1.), upperEdge_(-1.), elecMuLogged_(0), diMuonLogged_(0), diElecLogged_(0)
31  {
32  // sources have to be given; this PSet is not optional
33  edm::ParameterSet sources=cfg.getParameter<edm::ParameterSet>("sources");
34  muons_= iC.consumes< edm::View<reco::Muon> >(sources.getParameter<edm::InputTag>("muons"));
35  elecs_= iC.consumes< edm::View<reco::GsfElectron> >(sources.getParameter<edm::InputTag>("elecs"));
36  jets_ = iC.consumes< edm::View<reco::Jet> >(sources.getParameter<edm::InputTag>("jets" ));
37 
38  const auto& mets = sources.getParameter<std::vector<edm::InputTag>>("mets");
39  for (const auto& met: mets) {
40  mets_.push_back(iC.consumes<edm::View<reco::MET>>(met));
41  }
42 
43  // elecExtras are optional; they may be omitted or empty
44  if( cfg.existsAs<edm::ParameterSet>("elecExtras") ){
45  edm::ParameterSet elecExtras=cfg.getParameter<edm::ParameterSet>("elecExtras");
46  // select is optional; in case it's not found no
47  // selection will be applied
48  if( elecExtras.existsAs<std::string>("select") ){
50  }
51  // isolation is optional; in case it's not found no
52  // isolation will be applied
53  if( elecExtras.existsAs<std::string>("isolation") ){
55  }
56  // electronId is optional; in case it's not found the
57  // InputTag will remain empty
58  if( elecExtras.existsAs<edm::ParameterSet>("electronId") ){
59  edm::ParameterSet elecId=elecExtras.getParameter<edm::ParameterSet>("electronId");
60  electronId_= iC.consumes< edm::ValueMap<float> >(elecId.getParameter<edm::InputTag>("src"));
61  eidPattern_= elecId.getParameter<int>("pattern");
62  }
63  }
64  // muonExtras are optional; they may be omitted or empty
65  if( cfg.existsAs<edm::ParameterSet>("muonExtras") ){
66  edm::ParameterSet muonExtras=cfg.getParameter<edm::ParameterSet>("muonExtras");
67  // select is optional; in case it's not found no
68  // selection will be applied
69  if( muonExtras.existsAs<std::string>("select") ){
71  }
72  // isolation is optional; in case it's not found no
73  // isolation will be applied
74  if( muonExtras.existsAs<std::string>("isolation") ){
76  }
77  }
78  // jetExtras are optional; they may be omitted or empty
79  if( cfg.existsAs<edm::ParameterSet>("jetExtras") ){
80  edm::ParameterSet jetExtras=cfg.getParameter<edm::ParameterSet>("jetExtras");
81  // jetCorrector is optional; in case it's not found
82  // the InputTag will remain empty
83  if( jetExtras.existsAs<std::string>("jetCorrector") ){
84  jetCorrector_= jetExtras.getParameter<std::string>("jetCorrector");
85  }
86  // read jetID information if it exists
87  if(jetExtras.existsAs<edm::ParameterSet>("jetID")){
88  edm::ParameterSet jetID=jetExtras.getParameter<edm::ParameterSet>("jetID");
89  jetIDLabel_ = iC.consumes< reco::JetIDValueMap >(jetID.getParameter<edm::InputTag>("label"));
91  }
92  // select is optional; in case it's not found no
93  // selection will be applied (only implemented for
94  // CaloJets at the moment)
95  if( jetExtras.existsAs<std::string>("select") ){
96  jetSelect_= jetExtras.getParameter<std::string>("select");
97  }
98  }
99  // triggerExtras are optional; they may be omitted or empty
100  processName_ = "HLT";
101  if( cfg.existsAs<edm::ParameterSet>("triggerExtras") ){
102  edm::ParameterSet triggerExtras=cfg.getParameter<edm::ParameterSet>("triggerExtras");
103  triggerTable_= iC.consumes< edm::TriggerResults >(triggerExtras.getParameter<edm::InputTag>("src"));
104  processName_ = triggerExtras.getParameter<edm::InputTag>("src").process();
105  elecMuPaths_ = triggerExtras.getParameter<std::vector<std::string> >("pathsELECMU");
106  diMuonPaths_ = triggerExtras.getParameter<std::vector<std::string> >("pathsDIMUON");
107  diElecPaths_ = triggerExtras.getParameter<std::vector<std::string> >("pathsDIELEC");
108  }
109  // massExtras is optional; in case it's not found no mass
110  // window cuts are applied for the same flavor monitor
111  // histograms
112  if( cfg.existsAs<edm::ParameterSet>("massExtras") ){
113  edm::ParameterSet massExtras=cfg.getParameter<edm::ParameterSet>("massExtras");
114  lowerEdge_= massExtras.getParameter<double>("lowerEdge");
115  upperEdge_= massExtras.getParameter<double>("upperEdge");
116  }
117 
118  // and don't forget to do the histogram booking
119  folder_=cfg.getParameter<std::string>("directory");
120 
121  triggerEventWithRefsTag_ = iC.consumes< trigger::TriggerEventWithRefs >(edm::InputTag("hltTriggerSummaryRAW","",processName_));
122 
123  }
124 
125  void
127  {
128  //set up the current directory path
129  std::string current(folder_); current+=label_;
130  store_.setCurrentFolder(current);
131 
132  // determine number of bins for trigger monitoring
133  unsigned int nElecMu=elecMuPaths_.size();
134  unsigned int nDiMuon=diMuonPaths_.size();
135  unsigned int nDiElec=diElecPaths_.size();
136 
137  // invariant mass of opposite charge lepton pair (only filled for same flavor)
138  hists_["invMass_" ] = store_.book1D("InvMass" , "M(lep1, lep2)" , 80, 0., 320.);
139  // invariant mass of same charge lepton pair (only filled for same flavor)
140  hists_["invMassWC_" ] = store_.book1D("InvMassWC" , "M_{WC}(L1, L2)" , 80, 0., 320.);
141  // decay channel [1]: muon/muon, [2]:elec/elec, [3]:elec/muon
142  hists_["decayChannel_"] = store_.book1D("DecayChannel", "Decay Channel" , 3, 0, 3);
143  // // trigger efficiency estimates for the electron muon channel
144  // hists_["elecMuEff_" ] = store_.book1D("ElecMuEff" , "Eff(e/#mu paths)" , nElecMu, 0., nElecMu);
145  // monitored trigger occupancy for the electron muon channel
146  hists_["elecMuMon_" ] = store_.book1D("ElecMuMon" , "Mon(e/#mu paths)" , nElecMu, 0., nElecMu);
147  // // trigger efficiency estimates for the di muon channel
148  // hists_["diMuonEff_" ] = store_.book1D("DiMuonEff" , "Eff(#mu/#mu paths)" , nDiMuon, 0., nDiMuon);
149  // monitored trigger occupancy for the di muon channel
150  hists_["diMuonMon_" ] = store_.book1D("DiMuonMon" , "Mon(#mu/#mu paths)" , nDiMuon, 0., nDiMuon);
151  // // trigger efficiency estimates for the di electron channel
152  // hists_["diElecEff_" ] = store_.book1D("DiElecEff" , "Eff(e/e paths)" , nDiElec, 0., nDiElec);
153  // monitored trigger occupancy for the di electron channel
154  hists_["diElecMon_" ] = store_.book1D("DiElecMon" , "Mon(e/e paths)" , nDiElec, 0., nDiElec);
155  // multiplicity of jets with pt>30 (corrected to L2+L3)
156  hists_["jetMult_" ] = store_.book1D("JetMult" , "N_{30}(jet)" , 20, 0., 20.);
157 
158  // set bin labels for trigger monitoring
162  // set bin labels for decayChannel_
163  hists_["decayChannel_"]->setBinLabel( 1, "#mu e" , 1);
164  hists_["decayChannel_"]->setBinLabel( 2, "#mu #mu", 1);
165  hists_["decayChannel_"]->setBinLabel( 3, "e e" , 1);
166 
167  // selected dimuon events
168  hists_["diMuonLogger_"] = store_.book2D("DiMuonLogger", "Logged DiMuon Events" , 8, 0., 8., 10, 0., 10.); //OK
169  // selected dielec events
170  hists_["diElecLogger_"] = store_.book2D("DiElecLogger", "Logged DiElec Events" , 8, 0., 8., 10, 0., 10.); //OK
171  // selected elemu events
172  hists_["elecMuLogger_"] = store_.book2D("ElecMuLogger", "Logged ElecMu Events" , 8, 0., 8., 10, 0., 10.); //OK
173 
174  // set bin labels for trigger monitoring
175  loggerBinLabels(std::string("diMuonLogger_"));
176  loggerBinLabels(std::string("diElecLogger_"));
177  loggerBinLabels(std::string("elecMuLogger_"));
178 
179  // deltaR min between hlt iso lepton and reco iso lepton wrt eta
180  hists_["leptDeltaREta_"] = store_.book2D("DeltaRMinEtaLepton", "#Delta R_{min}(leptons) wrt #eta", 30, -3, 3, 10, 0., 0.1);
181  // resolution in pT for matched isolated leptons
182  hists_["leptResolution_"] = store_.book1D("ResIsoLeptons", "#Delta p_{T}/p_{T}(matched leptons)", 20, 0., 0.1);
183  // matching monitoring
184  hists_["matchingMon_"] = store_.book1D("MatchingMon", "Mon(matching)", 3, 0., 3.);
185  // set axes titles for matching monitoring
186  hists_["matchingMon_"]->setBinLabel( 1 , "1st lepton" );
187  hists_["matchingMon_"]->setBinLabel( 2 , "2nd lepton" );
188  hists_["matchingMon_"]->setBinLabel( 3 , "both " );
189 
190  return;
191  }
192 
193  void
194  MonitorDiLepton::fill(const edm::Event& event, const edm::EventSetup& setup, const HLTConfigProvider& hltConfig, const std::vector<std::string> triggerPaths)
195  {
196  // fetch trigger event if configured such
199  if( !event.getByToken(triggerTable_, triggerTable) ) return;
200  }
201 
202  /*
203  ------------------------------------------------------------
204 
205  Run information
206 
207  ------------------------------------------------------------
208  */
209 
210  if (!event.eventAuxiliary().run()) return;
211 
212  /*
213  ------------------------------------------------------------
214 
215  Muon Selection
216 
217  ------------------------------------------------------------
218  */
219 
220  // buffer isolated muons
221  std::vector<const reco::Muon*> isoMuons;
222 
224  if( !event.getByToken(muons_, muons) ) {
225  edm::LogWarning( "TopSingleLeptonHLTOfflineDQM" )
226  << "Muon collection not found \n";
227  return;
228  }
229 
230  for(edm::View<reco::Muon>::const_iterator muon=muons->begin(); muon!=muons->end(); ++muon){
231  // restrict to globalMuons
232  if( muon->isGlobalMuon() ){
233  // apply preselection
234  if(!muonSelect_ || (*muonSelect_)(*muon)){
235  if(!muonIso_ || (*muonIso_)(*muon)) isoMuons.push_back(&(*muon));
236  }
237  }
238  }
239 
240  /*
241  ------------------------------------------------------------
242 
243  Electron Selection
244 
245  ------------------------------------------------------------
246  */
247 
248  // buffer isolated electronss
249  std::vector<const reco::GsfElectron*> isoElecs;
250  edm::Handle<edm::ValueMap<float> > electronId;
252  if( !event.getByToken(electronId_, electronId) ) return;
253  }
254 
256  if( !event.getByToken(elecs_, elecs) ) {
257  edm::LogWarning( "TopSingleLeptonHLTOfflineDQM" )
258  << "Electron collection not found \n";
259  return;
260  }
261 
262  for(edm::View<reco::GsfElectron>::const_iterator elec=elecs->begin(); elec!=elecs->end(); ++elec){
263  // restrict to electrons with good electronId
264  int idx = elec-elecs->begin();
265  if( electronId_.isUninitialized() ? true : ((int)(*electronId)[elecs->refAt(idx)] & eidPattern_) ){
266  // apply preselection
267  if(!elecSelect_ || (*elecSelect_)(*elec)){
268  if(!elecIso_ || (*elecIso_)(*elec)) isoElecs.push_back(&(*elec));
269  }
270  }
271  }
272 
273  /*
274  ------------------------------------------------------------
275 
276  Jet Selection
277 
278  ------------------------------------------------------------
279  */
280 
281  const JetCorrector* corrector=0;
282  if(!jetCorrector_.empty()){
283  // check whether a jet correcto is in the event setup or not
284  if(setup.find( edm::eventsetup::EventSetupRecordKey::makeKey<JetCorrectionsRecord>() )){
285  corrector = JetCorrector::getJetCorrector(jetCorrector_, setup);
286  }
287  else{
288  edm::LogVerbatim( "TopDiLeptonHLTOfflineDQM" )
289  << "\n"
290  << "------------------------------------------------------------------------------------- \n"
291  << " No JetCorrectionsRecord available from EventSetup: \n"
292  << " - Jets will not be corrected. \n"
293  << " - If you want to change this add the following lines to your cfg file: \n"
294  << " \n"
295  << " ## load jet corrections \n"
296  << " process.load(\"JetMETCorrections.Configuration.JetCorrectionServicesAllAlgos_cff\") \n"
297  << " process.prefer(\"ak5CaloL2L3\") \n"
298  << " \n"
299  << "------------------------------------------------------------------------------------- \n";
300  }
301  }
302 
303  unsigned int mult=0;
304  // buffer leadingJets
305  std::vector<reco::Jet> leadingJets;
307  if( !event.getByToken(jets_, jets) ) {
308  edm::LogWarning( "TopSingleLeptonHLTOfflineDQM" )
309  << "Jet collection not found \n";
310  return;
311  }
312 
314  if(jetIDSelect_){
315  if( !event.getByToken(jetIDLabel_, jetID) ) return;
316  }
317 
318  for(edm::View<reco::Jet>::const_iterator jet=jets->begin(); jet!=jets->end(); ++jet){
319  unsigned int idx=jet-jets->begin();
320  if( jetIDSelect_ && dynamic_cast<const reco::CaloJet*>(jets->refAt(idx).get())){
321  if(!(*jetIDSelect_)((*jetID)[jets->refAt(idx)])) continue;
322  }
323  // chekc additional jet selection for calo, pf and bare reco jets
324  if(dynamic_cast<const reco::CaloJet*>(&*jet)){
325  reco::CaloJet sel = dynamic_cast<const reco::CaloJet&>(*jet); sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
326  StringCutObjectSelector<reco::CaloJet> jetSelect(jetSelect_); if(!jetSelect(sel)){ continue;}
327  }
328  else if(dynamic_cast<const reco::PFJet*>(&*jet)){
329  reco::PFJet sel= dynamic_cast<const reco::PFJet&>(*jet); sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
330  StringCutObjectSelector<reco::PFJet> jetSelect(jetSelect_); if(!jetSelect(sel)) continue;
331  }
332  else{
333  reco::Jet sel = *jet; sel.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
334  StringCutObjectSelector<reco::Jet> jetSelect(jetSelect_); if(!jetSelect(sel)) continue;
335  }
336  // check for overlaps
337  bool overlap=false;
338  for(std::vector<const reco::GsfElectron*>::const_iterator elec=isoElecs.begin(); elec!=isoElecs.end(); ++elec){
339  if(reco::deltaR((*elec)->eta(), (*elec)->phi(), jet->eta(), jet->phi())<0.4){overlap=true; break;}
340  } if(overlap){continue;}
341  // prepare jet to fill monitor histograms
342  reco::Jet monitorJet=*jet; monitorJet.scaleEnergy(corrector ? corrector->correction(*jet) : 1.);
343  ++mult; // determine jet multiplicity
344  if(idx==0) {
345  leadingJets.push_back(monitorJet);
346  }
347  if(idx==1) {
348  leadingJets.push_back(monitorJet);
349  }
350  }
351  fill("jetMult_", mult);
352 
353  /*
354  ------------------------------------------------------------
355 
356  MET Selection
357 
358  ------------------------------------------------------------
359  */
360 
361  // buffer for event logging
362  reco::MET caloMET;
363  for(std::vector< edm::EDGetTokenT< edm::View<reco::MET> > >::const_iterator met_=mets_.begin(); met_!=mets_.end(); ++met_){
364 
366  if( !event.getByToken(*met_, met) ) continue;
367 
368  if(met->begin()!=met->end()){
369  unsigned int idx=met_-mets_.begin();
370  if(idx==0){
371  caloMET=*met->begin();
372  }
373  }
374  }
375 
376 
377  /*
378  ------------------------------------------------------------
379 
380  Event Monitoring
381 
382  ------------------------------------------------------------
383  */
384  const edm::TriggerNames& triggerNames = event.triggerNames(*triggerTable);
385  // loop over trigger paths
386  for(unsigned int i=0; i<triggerNames.triggerNames().size(); ++i){
387  bool elecmu = false;
388  bool dielec = false;
389  bool dimuon = false;
390  // consider only path from triggerPaths
391  string name = triggerNames.triggerNames()[i];
392  for (unsigned int j=0; j<triggerPaths.size(); j++) {
393  if (TString(name.c_str()).Contains(TString(triggerPaths[j]), TString::kIgnoreCase) && TString(name.c_str()).Contains(TString("ele"), TString::kIgnoreCase) && TString(name.c_str()).Contains(TString("mu"), TString::kIgnoreCase)) elecmu = true;
394  else {
395  if (TString(name.c_str()).Contains(TString(triggerPaths[j]), TString::kIgnoreCase) && TString(name.c_str()).Contains(TString("ele"), TString::kIgnoreCase)) dielec = true;
396  if (TString(name.c_str()).Contains(TString(triggerPaths[j]), TString::kIgnoreCase) && TString(name.c_str()).Contains(TString("mu"), TString::kIgnoreCase)) dimuon = true;
397  }
398  }
399 
400  // ELECMU channel
401  if( elecmu ){
402  fill("decayChannel_", 0.5);
403  if( isoElecs.size()>0 && isoMuons.size()>0 ) {
404  double mass = (isoElecs[0]->p4()+isoMuons[0]->p4()).mass();
405  if( (lowerEdge_==-1. && upperEdge_==-1.) || (lowerEdge_<mass && mass<upperEdge_) ){
406  // fill plots for trigger monitoring
407  if(!triggerTable_.isUninitialized()) fill(event, *triggerTable, "elecMu", elecMuPaths_);
408  if(elecMuLogged_<=hists_.find("elecMuLogger_")->second->getNbinsY()){
409  // log runnumber, lumi block, event number & some
410  // more pysics infomation for interesting events
411  // We're doing a static_cast here to denote the explicity of the cast
412  double runID = static_cast<double>(event.eventAuxiliary().run());
413  double luminosityBlockID = static_cast<double>(event.eventAuxiliary().luminosityBlock());
414  double eventID = static_cast<double>(event.eventAuxiliary().event());
415  fill("elecMuLogger_", 0.5, elecMuLogged_+0.5, runID);
416  fill("elecMuLogger_", 1.5, elecMuLogged_+0.5, luminosityBlockID);
417  fill("elecMuLogger_", 2.5, elecMuLogged_+0.5, eventID);
418  fill("elecMuLogger_", 3.5, elecMuLogged_+0.5, isoMuons[0]->pt());
419  fill("elecMuLogger_", 4.5, elecMuLogged_+0.5, isoElecs[0]->pt());
420  if(leadingJets.size()>0) fill("elecMuLogger_", 5.5, elecMuLogged_+0.5, leadingJets[0].pt());
421  if(leadingJets.size()>1) fill("elecMuLogger_", 6.5, elecMuLogged_+0.5, leadingJets[1].pt());
422  fill("elecMuLogger_", 7.5, elecMuLogged_+0.5, caloMET.et());
423  ++elecMuLogged_;
424  }
425  }
426  }
427  }
428 
429  // DIMUON channel
430  if( dimuon ){
431  fill("decayChannel_", 1.5);
432  if (isoMuons.size()>1) {
433  int charge = isoMuons[0]->charge()*isoMuons[1]->charge();
434  double mass = (isoMuons[0]->p4()+isoMuons[1]->p4()).mass();
435  fill(charge<0 ? "invMass_" : "invMassWC_" , mass );
436  if((lowerEdge_==-1. && upperEdge_==-1.) || (lowerEdge_<mass && mass<upperEdge_) ){
437  // fill plots for trigger monitoring
438  if(!triggerTable_.isUninitialized()) fill(event, *triggerTable, "diMuon", diMuonPaths_);
439  if(diMuonLogged_<=hists_.find("diMuonLogger_")->second->getNbinsY()){
440  // log runnumber, lumi block, event number & some
441  // more pysics infomation for interesting events
442  // We're doing a static_cast here to denote the explicity of the cast
443  double runID = static_cast<double>(event.eventAuxiliary().run());
444  double luminosityBlockID = static_cast<double>(event.eventAuxiliary().luminosityBlock());
445  double eventID = static_cast<double>(event.eventAuxiliary().event());
446  fill("diMuonLogger_", 0.5, diMuonLogged_+0.5, runID);
447  fill("diMuonLogger_", 1.5, diMuonLogged_+0.5, luminosityBlockID);
448  fill("diMuonLogger_", 2.5, diMuonLogged_+0.5, eventID);
449  fill("diMuonLogger_", 3.5, diMuonLogged_+0.5, isoMuons[0]->pt());
450  fill("diMuonLogger_", 4.5, diMuonLogged_+0.5, isoMuons[1]->pt());
451  if(leadingJets.size()>0) fill("diMuonLogger_", 5.5, diMuonLogged_+0.5, leadingJets[0].pt());
452  if(leadingJets.size()>1) fill("diMuonLogger_", 6.5, diMuonLogged_+0.5, leadingJets[1].pt());
453  fill("diMuonLogger_", 7.5, diMuonLogged_+0.5, caloMET.et());
454  ++diMuonLogged_;
455  }
456  }
457  }
458  }
459 
460  // DIELEC channel
461  if( dielec ){
462  fill("decayChannel_", 2.5);
463  if( dielec && isoElecs.size()>1 ){
464  int charge = isoElecs[0]->charge()*isoElecs[1]->charge();
465  double mass = (isoElecs[0]->p4()+isoElecs[1]->p4()).mass();
466  fill(charge<0 ? "invMass_" : "invMassWC_" , mass );
467  if((lowerEdge_==-1. && upperEdge_==-1.) || (lowerEdge_<mass && mass<upperEdge_) ){
468  // fill plots for trigger monitoring
469  if(!triggerTable_.isUninitialized()) fill(event, *triggerTable, "diElec", diElecPaths_);
470  if(diElecLogged_<=hists_.find("diElecLogger_")->second->getNbinsY()){
471  // log runnumber, lumi block, event number & some
472  // more pysics infomation for interesting events
473  // We're doing a static_cast here to denote the explicity of the cast
474  double runID = static_cast<double>(event.eventAuxiliary().run());
475  double luminosityBlockID = static_cast<double>(event.eventAuxiliary().luminosityBlock());
476  double eventID = static_cast<double>(event.eventAuxiliary().event());
477  fill("diElecLogger_", 0.5, diElecLogged_+0.5, runID);
478  fill("diElecLogger_", 1.5, diElecLogged_+0.5, luminosityBlockID);
479  fill("diElecLogger_", 2.5, diElecLogged_+0.5, eventID);
480  fill("diElecLogger_", 3.5, diElecLogged_+0.5, isoElecs[0]->pt());
481  fill("diElecLogger_", 4.5, diElecLogged_+0.5, isoElecs[1]->pt());
482  if(leadingJets.size()>0) fill("diElecLogger_", 5.5, diElecLogged_+0.5, leadingJets[0].pt());
483  if(leadingJets.size()>1) fill("diElecLogger_", 6.5, diElecLogged_+0.5, leadingJets[1].pt());
484  fill("diElecLogger_", 7.5, diElecLogged_+0.5, caloMET.et());
485  ++diElecLogged_;
486  }
487  }
488  }
489  }
490  }
491 
492  /*
493  ------------------------------------------------------------
494 
495  HLT Objects Monitoring
496 
497  ------------------------------------------------------------
498  */
499 
500  edm::Handle<trigger::TriggerEventWithRefs> triggerEventWithRefsHandle;
501  if(event.getByToken(triggerEventWithRefsTag_,triggerEventWithRefsHandle)) {
502 
503  // loop over trigger paths
504  for(unsigned int i=0; i<triggerNames.triggerNames().size(); ++i){
505  // consider only path from triggerPaths
506  string name = triggerNames.triggerNames()[i].c_str();
507  bool isInteresting = false;
508  for (unsigned int j=0; j<triggerPaths.size(); j++) {
509  if (TString(name.c_str()).Contains(TString(triggerPaths[j]), TString::kIgnoreCase)) isInteresting = true;
510  }
511  if (!isInteresting) continue;
512  // dump infos on the considered trigger path
513  const unsigned int triggerIndex = triggerNames.triggerIndex(name);
514  // get modules for the considered trigger path
515  const vector<string>& moduleLabels(hltConfig.moduleLabels(triggerIndex));
516  const unsigned int moduleIndex(triggerTable->index(triggerIndex));
517  // Results from TriggerEventWithRefs product
518  electronIds_.clear(); electronRefs_.clear();
519  muonIds_.clear(); muonRefs_.clear();
520  // look only for modules actually run in this path
521  unsigned int kElec=0;
522  unsigned int kMuon=0;
523  for (unsigned int k=0; k<=moduleIndex; ++k) {
524  const string& moduleLabel(moduleLabels[k]);
525  const string moduleType(hltConfig.moduleType(moduleLabel));
526  // check whether the module is packed up in TriggerEventWithRef product
527  const unsigned int filterIndex(triggerEventWithRefsHandle->filterIndex(edm::InputTag(moduleLabel,"",processName_)));
528  if (filterIndex<triggerEventWithRefsHandle->size()) {
529  triggerEventWithRefsHandle->getObjects(filterIndex,electronIds_,electronRefs_);
530  const unsigned int nElectrons(electronIds_.size());
531  if (nElectrons>0) kElec = k;
532 
533  triggerEventWithRefsHandle->getObjects(filterIndex,muonIds_,muonRefs_);
534  const unsigned int nMuons(muonIds_.size());
535  if (nMuons>0) kMuon = k;
536 
537  }
538  }
539  bool l1Matched = false;
540  bool l2Matched = false;
541  double l1DeltaRMin = 500.;
542  double l2DeltaRMin = 500.;
543  unsigned int l1IndMatched = 500;
544  unsigned int l2IndMatched = 500;
545  // access to hlt dielecs
546  electronIds_.clear(); electronRefs_.clear();
547  if (kElec > 0 && kMuon < 1 && isoElecs.size()>0) {
548  const string& moduleLabelElec(moduleLabels[kElec]);
549  const string moduleTypeElec(hltConfig.moduleType(moduleLabelElec));
550  const unsigned int filterIndexElec(triggerEventWithRefsHandle->filterIndex(edm::InputTag(moduleLabelElec,"",processName_)));
551  triggerEventWithRefsHandle->getObjects(filterIndexElec,electronIds_,electronRefs_);
552  const unsigned int nElectrons(electronIds_.size());
553  double deltar1 = 600.;
554  double deltar2 = 600.;
555  for (unsigned int inde = 0; inde < isoElecs.size(); inde++) {
556  if (nElectrons > 0) deltar1 = deltaR(*electronRefs_[0],*isoElecs[inde]);
557  if (nElectrons > 1) deltar2 = deltaR(*electronRefs_[1],*isoElecs[inde]);
558  if (deltar1 < deltar2 && deltar1 < l1DeltaRMin) {
559  l1DeltaRMin = deltar1;
560  l1IndMatched = inde;
561  }
562  if (deltar2 < deltar1 && deltar2 < l2DeltaRMin) {
563  l2DeltaRMin = deltar2;
564  l2IndMatched = inde;
565  }
566  }
567  if (nElectrons > 0 && l1IndMatched < 500) fill("leptDeltaREta_", isoElecs[l1IndMatched]->eta(), l1DeltaRMin);
568  if (nElectrons > 1 && l2IndMatched < 500) fill("leptDeltaREta_", isoElecs[l2IndMatched]->eta(), l2DeltaRMin);
569  if (l1DeltaRMin < DRMIN) {
570  l1Matched = true;
571  fill("matchingMon_", 0.5 );
572  fill("leptResolution_", fabs(isoElecs[l1IndMatched]->pt()-electronRefs_[0]->pt())/isoElecs[l1IndMatched]->pt() );
573  }
574  if (l2DeltaRMin < DRMIN) {
575  l2Matched = true;
576  fill("matchingMon_", 1.5 );
577  fill("leptResolution_", fabs(isoElecs[l2IndMatched]->pt()-electronRefs_[1]->pt())/isoElecs[l2IndMatched]->pt() );
578  }
579  }
580  // access to hlt dimuons
581  muonIds_.clear(); muonRefs_.clear();
582  l1DeltaRMin = 500.; l2DeltaRMin = 500.; double l3DeltaRMin = 500.;
583  l1IndMatched = 500; l2IndMatched = 500; double l3IndMatched = 500;
584  if (kMuon > 0 && kElec < 1 && isoMuons.size()>0) {
585  const string& moduleLabelMuon(moduleLabels[kMuon]);
586  const string moduleTypeMuon(hltConfig.moduleType(moduleLabelMuon));
587  const unsigned int filterIndexMuon(triggerEventWithRefsHandle->filterIndex(edm::InputTag(moduleLabelMuon,"",processName_)));
588  triggerEventWithRefsHandle->getObjects(filterIndexMuon,muonIds_,muonRefs_);
589  trigger::VRmuon myMuonRefs;
590  const unsigned int nMuons(muonIds_.size());
591  for (unsigned int l=0; l<nMuons; l++) {
592  bool isNew = true;
593  for (unsigned int ll=0; ll<myMuonRefs.size(); ll++) {
594  if (fabs((myMuonRefs[ll]->pt()-muonRefs_[l]->pt())/muonRefs_[l]->pt()) < 1e-5) isNew = false;
595  }
596  if (isNew) myMuonRefs.push_back(muonRefs_[l]);
597  }
598  const unsigned int nMyMuons(myMuonRefs.size());
599  double deltar1 = 600.;
600  double deltar2 = 600.;
601  double deltar3 = 600.;
602  for (unsigned int indm = 0; indm < isoMuons.size(); indm++) {
603  if (nMyMuons > 0) deltar1 = deltaR(*myMuonRefs[0],*isoMuons[indm]);
604  if (nMyMuons > 1) deltar2 = deltaR(*myMuonRefs[1],*isoMuons[indm]);
605  if (nMyMuons > 2) deltar3 = deltaR(*myMuonRefs[2],*isoMuons[indm]);
606  if (nMyMuons > 0 && (nMyMuons<1 || deltar1 < deltar2) && (nMyMuons<2 || deltar1<deltar3) && deltar1 < l1DeltaRMin) {
607  l1DeltaRMin = deltar1;
608  l1IndMatched = indm;
609  }
610  if (nMyMuons > 1 && deltar2 < deltar1 && (nMyMuons<3 || deltar2<deltar3) && deltar2 < l2DeltaRMin) {
611  l2DeltaRMin = deltar2;
612  l2IndMatched = indm;
613  }
614  if (nMyMuons > 2 && deltar3 < deltar1 && deltar3 < deltar2 && deltar3 < l3DeltaRMin) {
615  l3DeltaRMin = deltar3;
616  l3IndMatched = indm;
617  }
618  }
619  if (nMyMuons > 0 && l1IndMatched < 500) fill("leptDeltaREta_", isoMuons[l1IndMatched]->eta(), l1DeltaRMin);
620  if (nMyMuons > 1 && l2IndMatched < 500) fill("leptDeltaREta_", isoMuons[l2IndMatched]->eta(), l2DeltaRMin);
621  if (nMyMuons > 2 && l3IndMatched < 500) fill("leptDeltaREta_", isoMuons[l3IndMatched]->eta(), l3DeltaRMin);
622  if (l1DeltaRMin < DRMIN) {
623  l1Matched = true;
624  fill("matchingMon_", 0.5 );
625  fill("leptResolution_", fabs(isoMuons[l1IndMatched]->pt()-myMuonRefs[0]->pt())/isoMuons[l1IndMatched]->pt() );
626  if (l2DeltaRMin < DRMIN) {
627  l2Matched = true;
628  fill("matchingMon_", 1.5 );
629  fill("leptResolution_", fabs(isoMuons[l2IndMatched]->pt()-myMuonRefs[1]->pt())/isoMuons[l2IndMatched]->pt() );
630  } else if (l3DeltaRMin < DRMIN) {
631  l2Matched = true;
632  fill("matchingMon_", 1.5 );
633  fill("leptResolution_", fabs(isoMuons[l3IndMatched]->pt()-myMuonRefs[2]->pt())/isoMuons[l3IndMatched]->pt() );
634  }
635  } else {
636  if (l2DeltaRMin < DRMIN) {
637  l1Matched = true;
638  fill("matchingMon_", 0.5 );
639  fill("leptResolution_", fabs(isoMuons[l2IndMatched]->pt()-myMuonRefs[1]->pt())/isoMuons[l2IndMatched]->pt() );
640  if (l3DeltaRMin < DRMIN) {
641  l2Matched = true;
642  fill("matchingMon_", 1.5 );
643  fill("leptResolution_", fabs(isoMuons[l3IndMatched]->pt()-myMuonRefs[2]->pt())/isoMuons[l3IndMatched]->pt() );
644  }
645  }
646  if (l3DeltaRMin < DRMIN) {
647  l1Matched = true;
648  fill("matchingMon_", 0.5 );
649  fill("leptResolution_", fabs(isoMuons[l3IndMatched]->pt()-myMuonRefs[2]->pt())/isoMuons[l3IndMatched]->pt() );
650  }
651  }
652  }
653  // access to hlt elec-muon
654  electronIds_.clear(); electronRefs_.clear();
655  muonIds_.clear(); muonRefs_.clear();
656  l1DeltaRMin = 500.; l2DeltaRMin = 500.;
657  l1IndMatched = 500; l2IndMatched = 500;
658  if (kElec > 0 && kMuon > 0 && isoElecs.size()>0) {
659  const string& moduleLabelElec(moduleLabels[kElec]);
660  const string moduleTypeElec(hltConfig.moduleType(moduleLabelElec));
661  const unsigned int filterIndexElec(triggerEventWithRefsHandle->filterIndex(edm::InputTag(moduleLabelElec,"",processName_)));
662  triggerEventWithRefsHandle->getObjects(filterIndexElec,electronIds_,electronRefs_);
663  const unsigned int nElectrons(electronIds_.size());
664  double deltar = 600.;
665  for (unsigned int inde = 0; inde < isoElecs.size(); inde++) {
666  if (nElectrons > 0) deltar = deltaR(*electronRefs_[0],*isoElecs[inde]);
667  if (deltar < l1DeltaRMin) {
668  l1DeltaRMin = deltar;
669  l1IndMatched = inde;
670  }
671  }
672  if (nElectrons > 0 && l1IndMatched < 500) fill("leptDeltaREta_", isoElecs[l1IndMatched]->eta(), l1DeltaRMin);
673  if (l1DeltaRMin < DRMIN) {
674  l1Matched = true;
675  fill("matchingMon_", 0.5 );
676  fill("leptResolution_", fabs(isoElecs[l1IndMatched]->pt()-electronRefs_[0]->pt())/isoElecs[l1IndMatched]->pt() );
677  }
678  }
679  if (kElec > 0 && kMuon > 0 && isoMuons.size()>0) {
680  const string& moduleLabelMuon(moduleLabels[kMuon]);
681  const string moduleTypeMuon(hltConfig.moduleType(moduleLabelMuon));
682  const unsigned int filterIndexMuon(triggerEventWithRefsHandle->filterIndex(edm::InputTag(moduleLabelMuon,"",processName_)));
683  triggerEventWithRefsHandle->getObjects(filterIndexMuon,muonIds_,muonRefs_);
684  const unsigned int nMuons(muonIds_.size());
685  if (isoMuons.size()<1) continue;
686  double deltar = 600.;
687  for (unsigned int indm = 0; indm < isoMuons.size(); indm++) {
688  if (nMuons > 0) deltar = deltaR(*muonRefs_[0],*isoMuons[indm]);
689  if (deltar < l2DeltaRMin) {
690  l2DeltaRMin = deltar;
691  l2IndMatched = indm;
692  }
693  }
694  if (nMuons > 0 && l2IndMatched < 500) fill("leptDeltaREta_", isoMuons[l2IndMatched]->eta(), l2DeltaRMin);
695  if (l2DeltaRMin < DRMIN) {
696  l2Matched = true;
697  fill("matchingMon_", 1.5 );
698  fill("leptResolution_", fabs(isoMuons[l2IndMatched]->pt()-muonRefs_[0]->pt())/isoMuons[l2IndMatched]->pt() );
699  }
700  }
701  if (l1Matched && l2Matched) fill("matchingMon_", 2.5 );
702  }
703  }
704 
705  }
706 
707 }
708 
709 TopDiLeptonHLTOfflineDQM::TopDiLeptonHLTOfflineDQM(const edm::ParameterSet& cfg): vertexSelect_(0), beamspotSelect_(0)
710 {
711  // configure the preselection
712  edm::ParameterSet presel=cfg.getParameter<edm::ParameterSet>("preselection");
713  if( presel.existsAs<edm::ParameterSet>("trigger") ){
714  edm::ParameterSet trigger=presel.getParameter<edm::ParameterSet>("trigger");
715  triggerTable_= consumes< edm::TriggerResults >(trigger.getParameter<edm::InputTag>("src"));
716  triggerPaths_=trigger.getParameter<std::vector<std::string> >("select");
717  }
718  if( presel.existsAs<edm::ParameterSet>("vertex" ) ){
719  edm::ParameterSet vertex=presel.getParameter<edm::ParameterSet>("vertex");
720  vertex_= consumes< std::vector<reco::Vertex> >(vertex.getParameter<edm::InputTag>("src"));
722  }
723  if( presel.existsAs<edm::ParameterSet>("beamspot" ) ){
725  beamspot_= consumes< reco::BeamSpot >(beamspot.getParameter<edm::InputTag>("src"));
727  }
728 
729  // configure the selection
730  std::vector<edm::ParameterSet> sel=cfg.getParameter<std::vector<edm::ParameterSet> >("selection");
731  for(unsigned int i=0; i<sel.size(); ++i){
732  selectionOrder_.push_back(sel.at(i).getParameter<std::string>("label"));
734  }
735 
736  for (const std::string& s: selectionOrder_) {
738 
739  if (selection_.find(key) == selection_.end())
740  continue;
741 
742  if (type == "muons"){
744  }
745  if (type == "elecs"){
747  }
748  if (type == "jets"){
750  }
751  if (type == "jets/pf"){
753  }
754  if (type == "jets/calo"){
756  }
757  if (type == "met"){
759  }
760  }
761 }
762 
763  void
765 {
766  using namespace std;
767  using namespace edm;
768 
769  bool changed(true);
770  if (!hltConfig_.init(iRun,iSetup,"*",changed)) {
771  edm::LogWarning( "TopSingleLeptonHLTOfflineDQM" )
772  << "Config extraction failure with process name "
774  << "\n";
775  return;
776  }
777 }
778 
779  void
781 {
784  if( !event.getByToken(triggerTable_, triggerTable) ) return;
785  if(!acceptHLT(event, *triggerTable, triggerPaths_)) return;
786  }
787  if(!vertex_.isUninitialized()){
789  if( !event.getByToken(vertex_, vertex) ) return;
790  if(vertex->empty() || !(*vertexSelect_)(vertex->front())) return;
791  }
792  if(!beamspot_.isUninitialized()){
794  if( !event.getByToken(beamspot_, beamspot) ) return;
795  if(!(*beamspotSelect_)(*beamspot)) return;
796  }
797  // apply selection steps
798  for(std::vector<std::string>::const_iterator selIt=selectionOrder_.begin(); selIt!=selectionOrder_.end(); ++selIt){
799  std::string key = selectionStep(*selIt), type = objectType(*selIt);
800  if(selection_.find(key)!=selection_.end()){
801 
802  if(type=="empty"){
803  selection_[key].second->fill(event, setup, hltConfig_, triggerPaths_);
804  continue;
805  }
806  if(type=="Hlt" ){
807  selection_[key].second->fill(event, setup, hltConfig_, triggerPaths_);
808  continue;
809  }
810 
811  bool passSel = true;
812 
813  for(std::vector<std::string>::const_iterator selIt2=selectionOrder_.begin(); selIt2<=selIt; ++selIt2){
814  std::string key2 = selectionStep(*selIt2), type2 = objectType(*selIt2);
815  if(selection_.find(key2)==selection_.end()) continue;
816 
817  if(type2=="Hlt" || type2=="empty" ) continue;
818  if (!selectmap_[type2]->select(event)) passSel=false;
819 
820  } // end 2nd loop
821 
822  // Apply cumulative event selection
823  if ( !passSel ) continue;
824 
825  selection_[key].second->fill(event, setup, hltConfig_, triggerPaths_);
826 
827  }
828  }
829 }
830 
831  void
833 {
834  for (auto& sel: selection_) {
835  sel.second.second->book(i);
836  }
837 }
TopDiLeptonHLTOfflineDQM(const edm::ParameterSet &cfg)
default constructor
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
tuple cfg
Definition: looper.py:259
const std::string moduleType(const std::string &module) const
C++ class name of module.
double lowerEdge_
mass window upper and lower edge
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
Jets made from CaloTowers.
Definition: CaloJet.h:29
virtual void scaleEnergy(double fScale)
scale energy of the jet
StringCutObjectSelector< reco::Muon > * muonSelect_
extra selection on muons
virtual double et() const
transverse energy
edm::EDGetTokenT< reco::BeamSpot > beamspot_
beamspot
StringCutObjectSelector< reco::GsfElectron > * elecSelect_
extra selection on electrons
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
virtual double correction(const LorentzVector &fJet) const =0
get correction using Jet information only
Base class for all types of Jets.
Definition: Jet.h:20
RunNumber_t run() const
std::string selectionStep(const std::string &label)
void bookHistograms(DQMStore::IBooker &i, edm::Run const &, edm::EventSetup const &) override
int elecMuLogged_
number of logged interesting events
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
T eta() const
edm::EDGetTokenT< edm::View< reco::GsfElectron > > elecs_
input sources for monitoring
StringCutObjectSelector< reco::GsfElectron > * elecIso_
extra isolation criterion on electron
edm::EDGetTokenT< edm::View< reco::Jet > > jets_
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
Jets made from PFObjects.
Definition: PFJet.h:21
edm::EDGetTokenT< reco::JetIDValueMap > jetIDLabel_
jetID as an extra selection type
std::vector< std::string > triggerPaths_
trigger paths
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:90
std::vector< edm::EDGetTokenT< edm::View< reco::MET > > > mets_
considers a vector of METs
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
std::map< std::string, SelectionStepHLTBase * > selectmap_
std::vector< std::string > diMuonPaths_
trigger paths for di muon channel
StringCutObjectSelector< reco::BeamSpot > * beamspotSelect_
string cut selector
virtual void analyze(const edm::Event &event, const edm::EventSetup &setup)
unsigned int triggerIndex(std::string const &name) const
Definition: TriggerNames.cc:32
tuple corrector
Definition: mvaPFMET_cff.py:88
Definition: MET.h:42
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
vector< PseudoJet > jets
void loggerBinLabels(std::string hist)
set labels for event logging histograms
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
std::vector< std::string > diElecPaths_
trigger paths for di electron channel
int j
Definition: DBlmapReader.cc:9
virtual void dqmBeginRun(const edm::Run &r, const edm::EventSetup &c)
do this during the event loop
edm::EDGetTokenT< trigger::TriggerEventWithRefs > triggerEventWithRefsTag_
edm::EDGetTokenT< edm::TriggerResults > triggerTable_
trigger table
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::map< std::string, MonitorElement * > hists_
histogram container
void fill(const edm::Event &event, const edm::EventSetup &setup, const HLTConfigProvider &hltConfig, const std::vector< std::string > triggerPaths)
fill monitor histograms with electronId and jetCorrections
void triggerBinLabels(std::string channel, const std::vector< std::string > &labels)
set configurable labels for trigger monitoring histograms
const std::string & processName() const
process name
std::map< std::string, std::pair< edm::ParameterSet, HLTOfflineDQMTopDiLepton::MonitorDiLepton * > > selection_
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
EventAuxiliary const & eventAuxiliary() const
Definition: Event.h:69
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
bool acceptHLT(const edm::Event &event, const edm::TriggerResults &triggerTable, const std::string &triggerPath)
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
std::vector< std::string > selectionOrder_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
d&#39;tor
static const JetCorrector * getJetCorrector(const std::string &fName, const edm::EventSetup &fSetup)
retrieve corrector from the event setup. troughs exception if something is missing ...
Definition: JetCorrector.cc:50
void book(DQMStore::IBooker &store_)
book histograms in subdirectory directory
std::string objectType(const std::string &label)
std::vector< reco::RecoChargedCandidateRef > VRmuon
edm::EDGetTokenT< edm::ValueMap< float > > electronId_
electronId label
tuple muons
Definition: patZpeak.py:38
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
bool isUninitialized() const
Definition: EDGetToken.h:71
tuple process
Definition: LaserDQM_cfg.py:3
edm::EDGetTokenT< edm::View< reco::Muon > > muons_
edm::EDGetTokenT< std::vector< reco::Vertex > > vertex_
primary vertex
static std::string const triggerPaths
Definition: EdmProvDump.cc:41
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
tuple size
Write out results.
edm::EDGetTokenT< edm::TriggerResults > triggerTable_
trigger table
StringCutObjectSelector< reco::Muon > * muonIso_
extra isolation criterion on muon
Definition: Run.h:41
StringCutObjectSelector< reco::JetID > * jetIDSelect_
extra jetID selection on calo jets
StringCutObjectSelector< reco::Vertex > * vertexSelect_
string cut selector