CMS 3D CMS Logo

HTMonitor.cc
Go to the documentation of this file.
2 
4 
6 
7 // -----------------------------
8 // constructors and destructor
9 // -----------------------------
10 
12  folderName_ ( iConfig.getParameter<std::string>("FolderName") )
13  , metToken_ ( consumes<reco::PFMETCollection> (iConfig.getParameter<edm::InputTag>("met") ) )
14  , jetToken_ ( mayConsume<reco::JetView> (iConfig.getParameter<edm::InputTag>("jets") ) )
15  , eleToken_ ( mayConsume<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons") ) )
16  , muoToken_ ( mayConsume<reco::MuonCollection> (iConfig.getParameter<edm::InputTag>("muons") ) )
17  , vtxToken_ ( mayConsume<reco::VertexCollection> (iConfig.getParameter<edm::InputTag>("vertices") ) )
18  , ht_variable_binning_ ( iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("htBinning") )
19  , ht_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("htPSet") ) )
20  , ls_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("lsPSet") ) )
21  , num_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"),consumesCollector(), *this))
22  , den_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"),consumesCollector(), *this))
23  , metSelection_ ( iConfig.getParameter<std::string>("metSelection") )
24  , jetSelection_ ( iConfig.getParameter<std::string>("jetSelection") )
25  , eleSelection_ ( iConfig.getParameter<std::string>("eleSelection") )
26  , muoSelection_ ( iConfig.getParameter<std::string>("muoSelection") )
27  , jetSelection_HT_ ( iConfig.getParameter<std::string>("jetSelection_HT") )
28  , njets_ ( iConfig.getParameter<unsigned>("njets" ) )
29  , nelectrons_ ( iConfig.getParameter<unsigned>("nelectrons" ) )
30  , nmuons_ ( iConfig.getParameter<unsigned>("nmuons" ) )
31  , dEtaCut_ ( iConfig.getParameter<double>("dEtaCut") )
32 {
33  string quantity = iConfig.getParameter<std::string>("quantity");
34  if(quantity == "HT")
35  {
36  quantity_ = HT;
37  }
38  else if(quantity == "Mjj")
39  {
40  quantity_ = MJJ;
41  }
42  else if(quantity == "softdrop")
43  {
45  }
46  else
47  {
48  throw cms::Exception("quantity not defined") << "the quantity '" << quantity << "' is undefined. Please check your config!" << std::endl;
49  }
50 }
51 
52 HTMonitor::~HTMonitor() = default;
53 
55 {
57  pset.getParameter<unsigned>("nbins"),
58  pset.getParameter<double>("xmin"),
59  pset.getParameter<double>("xmax"),
60  };
61 }
62 
64 {
66  pset.getParameter<unsigned>("nbins"),
67  0.,
68  double(pset.getParameter<unsigned>("nbins"))
69  };
70 }
71 
72 void HTMonitor::setHTitle(HTME& me, const std::string& titleX, const std::string& titleY)
73 {
74  me.numerator->setAxisTitle(titleX,1);
75  me.numerator->setAxisTitle(titleY,2);
76  me.denominator->setAxisTitle(titleX,1);
77  me.denominator->setAxisTitle(titleY,2);
78 
79 }
80 
81 void HTMonitor::bookME(DQMStore::IBooker &ibooker, HTME& me, const std::string& histname, const std::string& histtitle, int nbins, double min, double max)
82 {
83  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, min, max);
84  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, min, max);
85 }
86 void HTMonitor::bookME(DQMStore::IBooker &ibooker, HTME& me, const std::string& histname, const std::string& histtitle, const std::vector<double>& binning)
87 {
88  int nbins = binning.size()-1;
89  std::vector<float> fbinning(binning.begin(),binning.end());
90  float* arr = &fbinning[0];
91  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, arr);
92  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, arr);
93 }
94 void HTMonitor::bookME(DQMStore::IBooker &ibooker, HTME& me, const std::string& histname, const std::string& histtitle, int nbinsX, double xmin, double xmax, double ymin, double ymax)
95 {
96  me.numerator = ibooker.bookProfile(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, ymin, ymax);
97  me.denominator = ibooker.bookProfile(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, ymin, ymax);
98 }
99 void HTMonitor::bookME(DQMStore::IBooker &ibooker, HTME& me, const std::string& histname, const std::string& histtitle, int nbinsX, double xmin, double xmax, int nbinsY, double ymin, double ymax)
100 {
101  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
102  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
103 }
104 void HTMonitor::bookME(DQMStore::IBooker &ibooker, HTME& me, const std::string& histname, const std::string& histtitle, const std::vector<double>& binningX, const std::vector<double>& binningY)
105 {
106  int nbinsX = binningX.size()-1;
107  std::vector<float> fbinningX(binningX.begin(),binningX.end());
108  float* arrX = &fbinningX[0];
109  int nbinsY = binningY.size()-1;
110  std::vector<float> fbinningY(binningY.begin(),binningY.end());
111  float* arrY = &fbinningY[0];
112 
113  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, arrX, nbinsY, arrY);
114  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, arrX, nbinsY, arrY);
115 }
116 
118  edm::Run const & iRun,
119  edm::EventSetup const & iSetup)
120 {
121  std::string histname, histtitle;
122 
123  std::string currentFolder = folderName_ ;
124  ibooker.setCurrentFolder(currentFolder);
125 
126  switch(quantity_)
127  {
128  case HT:
129  {
130  histname = "ht_variable"; histtitle = "HT";
131  bookME(ibooker,qME_variableBinning_,histname,histtitle,ht_variable_binning_);
132  setHTitle(qME_variableBinning_,"HT [GeV]","events / [GeV]");
133 
134  histname = "htVsLS"; histtitle = "HT vs LS";
136  setHTitle(htVsLS_,"LS","HT [GeV]");
137 
138  histname = "deltaphi_metjet1"; histtitle = "DPHI_METJ1";
140  setHTitle(deltaphimetj1ME_,"delta phi (met, j1)","events / 0.1 rad");
141 
142  histname = "deltaphi_jet1jet2"; histtitle = "DPHI_J1J2";
144  setHTitle(deltaphij1j2ME_,"delta phi (j1, j2)","events / 0.1 rad");
145  break;
146  }
147 
148 
149  case MJJ:
150  {
151  histname = "mjj_variable"; histtitle = "Mjj";
152  bookME(ibooker,qME_variableBinning_,histname,histtitle, ht_variable_binning_);
153  setHTitle(qME_variableBinning_,"Mjj [GeV]","events / [GeV]");
154  break;
155  }
156 
157 
158  case SOFTDROP:
159  {
160  histname = "softdrop_variable"; histtitle = "softdropmass";
161  bookME(ibooker,qME_variableBinning_,histname,histtitle, ht_variable_binning_);
162  setHTitle(qME_variableBinning_,"leading jet softdropmass [GeV]","events / [GeV]");
163  break;
164  }
165  }
166 
167  // Initialize the GenericTriggerEventFlag
168  if ( num_genTriggerEventFlag_ && num_genTriggerEventFlag_->on() ) num_genTriggerEventFlag_->initRun( iRun, iSetup );
169  if ( den_genTriggerEventFlag_ && den_genTriggerEventFlag_->on() ) den_genTriggerEventFlag_->initRun( iRun, iSetup );
170 }
171 
177 
178  // Filter out events if Trigger Filtering is requested
179  if (den_genTriggerEventFlag_->on() && ! den_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
180 
182  iEvent.getByToken( metToken_, metHandle );
183  reco::PFMET pfmet = metHandle->front();
184  if ( ! metSelection_( pfmet ) ) return;
185 
186  edm::Handle<reco::JetView> jetHandle; //add a configurable jet collection & jet pt selection
187  iEvent.getByToken( jetToken_, jetHandle );
188  std::vector<reco::Jet> jets;
189  if ( jetHandle->size() < njets_ ) return;
190  for ( auto const & j : *jetHandle ) {
191  if ( jetSelection_( j ) ) {
192  jets.push_back(j);
193  }
194  }
195 
196  if ( jets.size() < njets_ ) return;
197 
198  float deltaPhi_met_j1 = 10.0;
199  float deltaPhi_j1_j2 = 10.0;
200 
201  if (!jets.empty()) deltaPhi_met_j1 = fabs( deltaPhi( pfmet.phi(), jets[0].phi() ));
202  if (jets.size() >= 2) deltaPhi_j1_j2 = fabs( deltaPhi( jets[0].phi(), jets[1].phi() ));
203 
205  iEvent.getByToken( eleToken_, eleHandle );
206  std::vector<reco::GsfElectron> electrons;
207  if ( eleHandle->size() < nelectrons_ ) return;
208  for ( auto const & e : *eleHandle ) {
209  if ( eleSelection_( e ) ) electrons.push_back(e);
210  }
211  if ( electrons.size() < nelectrons_ ) return;
212 
214  iEvent.getByToken(vtxToken_, vtxHandle);
215 
217  for (auto const & v : *vtxHandle) {
218  bool isFake = v.isFake() ;
219 
220  if (!isFake) {
221  vtx = v;
222  break;
223  }
224  }
225 
227  iEvent.getByToken( muoToken_, muoHandle );
228  if ( muoHandle->size() < nmuons_ ) return;
229  std::vector<reco::Muon> muons;
230  for ( auto const & m : *muoHandle ) {
231  if ( muoSelection_( m ) && m.isGlobalMuon() && m.isPFMuon() && m.globalTrack()->normalizedChi2() < 10. && m.globalTrack()->hitPattern().numberOfValidMuonHits() > 0 && m.numberOfMatchedStations() > 1 && fabs(m.muonBestTrack()->dxy(vtx.position())) < 0.2 && fabs(m.muonBestTrack()->dz(vtx.position())) < 0.5 && m.innerTrack()->hitPattern().numberOfValidPixelHits() > 0 && m.innerTrack()->hitPattern().trackerLayersWithMeasurement() > 5 ) muons.push_back(m);
232  }
233  if ( muons.size() < nmuons_ ) return;
234 
235  // fill histograms
236  switch(quantity_)
237  {
238  case HT:
239  {
240  float ht = 0.0;
241  for ( auto const & j : *jetHandle )
242  {
243  if ( jetSelection_HT_(j)) ht += j.pt();
244  }
245 
246  // filling histograms (denominator)
248 
249  deltaphimetj1ME_.denominator -> Fill(deltaPhi_met_j1);
250  deltaphij1j2ME_.denominator -> Fill(deltaPhi_j1_j2);
251 
252  int ls = iEvent.id().luminosityBlock();
253  htVsLS_.denominator -> Fill(ls, ht);
254 
255  // applying selection for numerator
256  if (num_genTriggerEventFlag_->on() && ! num_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
257 
258  // filling histograms (num_genTriggerEventFlag_)
260 
261  htVsLS_.numerator -> Fill(ls, ht);
262  deltaphimetj1ME_.numerator -> Fill(deltaPhi_met_j1);
263  deltaphij1j2ME_.numerator -> Fill(deltaPhi_j1_j2);
264  break;
265  }
266 
267  case MJJ:
268  {
269  if (jets.size() < 2) return;
270 
271  // deltaEta cut
272  if(fabs(jets[0].p4().Eta() - jets[1].p4().Eta()) >= dEtaCut_) return;
273  float mjj = (jets[0].p4() + jets[1].p4()).M();
274 
276 
277  // applying selection for numerator
278  if (num_genTriggerEventFlag_->on() && ! num_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
279 
281  break;
282  }
283 
284  case SOFTDROP:
285  {
286  if (jets.size() < 2) return;
287 
288  // deltaEta cut
289  if(fabs(jets[0].p4().Eta() - jets[1].p4().Eta()) >= dEtaCut_) return;
290 
291  float softdrop = jets[0].p4().M();
292 
294 
295  // applying selection for numerator
296  if (num_genTriggerEventFlag_->on() && ! num_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
297 
298  qME_variableBinning_.numerator -> Fill(softdrop);
299  break;
300  }
301  }
302 }
303 
305 {
306  pset.add<unsigned int> ( "nbins");
307  pset.add<double>( "xmin" );
308  pset.add<double>( "xmax" );
309 }
310 
312 {
313  pset.add<unsigned int> ( "nbins", 2500);
314  pset.add<double> ( "xmin", 0.);
315  pset.add<double> ( "xmax", 2500.);
316 }
317 
319 {
321  desc.add<std::string> ( "FolderName", "HLT/HT" );
322  desc.add<std::string> ( "quantity", "HT" );
323 
324 
325  desc.add<edm::InputTag>( "met", edm::InputTag("pfMet") );
326  desc.add<edm::InputTag>( "jets", edm::InputTag("ak4PFJetsCHS") );
327  desc.add<edm::InputTag>( "electrons",edm::InputTag("gedGsfElectrons") );
328  desc.add<edm::InputTag>( "muons", edm::InputTag("muons") );
329  desc.add<edm::InputTag>( "vertices",edm::InputTag("offlinePrimaryVertices") );
330  desc.add<std::string>("metSelection", "pt > 0");
331  desc.add<std::string>("jetSelection", "pt > 0");
332  desc.add<std::string>("eleSelection", "pt > 0");
333  desc.add<std::string>("muoSelection", "pt > 0");
334  desc.add<std::string>("jetSelection_HT", "pt > 30 && eta < 2.5");
335  desc.add<unsigned>("njets", 0);
336  desc.add<unsigned>("nelectrons", 0);
337  desc.add<unsigned>("nmuons", 0);
338  desc.add<double>("dEtaCut", 1.3);
339 
340  edm::ParameterSetDescription genericTriggerEventPSet;
341  genericTriggerEventPSet.add<bool>("andOr");
342  genericTriggerEventPSet.add<edm::InputTag>("dcsInputTag", edm::InputTag("scalersRawToDigi") );
343  genericTriggerEventPSet.add<std::vector<int> >("dcsPartitions",{});
344  genericTriggerEventPSet.add<bool>("andOrDcs", false);
345  genericTriggerEventPSet.add<bool>("errorReplyDcs", true);
346  genericTriggerEventPSet.add<std::string>("dbLabel","");
347  genericTriggerEventPSet.add<bool>("andOrHlt", true);
348  genericTriggerEventPSet.add<edm::InputTag>("hltInputTag", edm::InputTag("TriggerResults::HLT") );
349  genericTriggerEventPSet.add<std::vector<std::string> >("hltPaths",{});
350  genericTriggerEventPSet.add<std::string>("hltDBKey","");
351  genericTriggerEventPSet.add<bool>("errorReplyHlt",false);
352  genericTriggerEventPSet.add<unsigned int>("verbosityLevel",1);
353 
354  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
355  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
356 
359  fillHistoPSetDescription(htPSet);
360  histoPSet.add<edm::ParameterSetDescription>("htPSet", htPSet);
361  std::vector<double> bins = {0.,20.,40.,60.,80.,90.,100.,110.,120.,130.,140.,150.,160.,170.,180.,190.,200.,220.,240.,260.,280.,300.,350.,400.,450.,500.,550.,600.,650.,700.,750.,800.,850.,900.,950.,1000.,1050.,1100.,1200.,1300.,1400.,1500.,2000.,2500.};
362  histoPSet.add<std::vector<double> >("htBinning", bins);
363 
366  histoPSet.add<edm::ParameterSetDescription>("lsPSet", lsPSet);
367 
368  desc.add<edm::ParameterSetDescription>("histoPSet",histoPSet);
369 
370  descriptions.add("htMonitoring", desc);
371 }
372 
373 // Define this as a plug-in
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::MuonCollection > muoToken_
Definition: HTMonitor.h:96
edm::EDGetTokenT< reco::JetView > jetToken_
Definition: HTMonitor.h:94
double dEtaCut_
Definition: HTMonitor.h:119
MonitorElement * denominator
Definition: HTMonitor.h:63
quant quantity_
Definition: HTMonitor.h:91
void setHTitle(HTME &me, const std::string &titleX, const std::string &titleY)
Definition: HTMonitor.cc:72
void bookME(DQMStore::IBooker &, HTME &me, const std::string &histname, const std::string &histtitle, int nbins, double xmin, double xmax)
Definition: HTMonitor.cc:81
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:160
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
HTME qME_variableBinning_
Definition: HTMonitor.h:103
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
StringCutObjectSelector< reco::Muon, true > muoSelection_
Definition: HTMonitor.h:114
~HTMonitor() override
size_type size() const
std::vector< double > ht_variable_binning_
Definition: HTMonitor.h:99
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
unsigned njets_
Definition: HTMonitor.h:116
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: HTMonitor.h:97
static MEHTbinning getHistoPSet(const edm::ParameterSet &pset)
Definition: HTMonitor.cc:54
edm::View< Jet > JetView
edm references
Definition: JetCollection.h:12
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
const Point & position() const
position
Definition: Vertex.h:109
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
Definition: HTMonitor.h:109
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
StringCutObjectSelector< reco::MET, true > metSelection_
Definition: HTMonitor.h:111
Definition: HTMonitor.h:44
int iEvent
Definition: GenABIO.cc:230
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
double p4[4]
Definition: TauolaWrapper.h:92
vector< PseudoJet > jets
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
Definition: HTMonitor.cc:311
MonitorElement * numerator
Definition: HTMonitor.h:62
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
HTMonitor(const edm::ParameterSet &)
Definition: HTMonitor.cc:11
T min(T a, T b)
Definition: MathUtil.h:58
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
Definition: HTMonitor.cc:304
ParameterDescriptionBase * add(U const &iLabel, T const &value)
MEHTbinning ht_binning_
Definition: HTMonitor.h:100
edm::EDGetTokenT< reco::GsfElectronCollection > eleToken_
Definition: HTMonitor.h:95
MEHTbinning ls_binning_
Definition: HTMonitor.h:101
def ls(path, rec=False)
Definition: eostools.py:348
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
StringCutObjectSelector< reco::Jet, true > jetSelection_HT_
Definition: HTMonitor.h:115
unsigned nelectrons_
Definition: HTMonitor.h:117
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
StringCutObjectSelector< reco::GsfElectron, true > eleSelection_
Definition: HTMonitor.h:113
StringCutObjectSelector< reco::Jet, true > jetSelection_
Definition: HTMonitor.h:112
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: HTMonitor.cc:176
std::string folderName_
Definition: HTMonitor.h:89
HTME deltaphimetj1ME_
Definition: HTMonitor.h:105
edm::EventID id() const
Definition: EventBase.h:60
fixed size matrix
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HTMonitor.cc:318
static MEHTbinning getHistoLSPSet(const edm::ParameterSet &pset)
Definition: HTMonitor.cc:63
HTME deltaphij1j2ME_
Definition: HTMonitor.h:106
Definition: HTMonitor.h:44
edm::EDGetTokenT< reco::PFMETCollection > metToken_
Definition: HTMonitor.h:93
Definition: HT.h:21
HTME htVsLS_
Definition: HTMonitor.h:104
double phi() const final
momentum azimuthal angle
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: HTMonitor.cc:117
unsigned nmuons_
Definition: HTMonitor.h:118
static MEHTbinning phi_binning_
Definition: HTMonitor.h:123
Definition: Run.h:43
Collection of PF MET.
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
Definition: HTMonitor.h:108