CMS 3D CMS Logo

METMonitor.cc
Go to the documentation of this file.
2 
4 
6 
8 
10 
11 // -----------------------------
12 // constructors and destructor
13 // -----------------------------
14 
16  folderName_ ( iConfig.getParameter<std::string>("FolderName") )
17  , metInputTag_ ( iConfig.getParameter<edm::InputTag> ("met") )
18  , jetInputTag_ ( iConfig.getParameter<edm::InputTag> ("jets") )
19  , eleInputTag_ ( iConfig.getParameter<edm::InputTag> ("electrons") )
20  , muoInputTag_ ( iConfig.getParameter<edm::InputTag> ("muons") )
21  , vtxInputTag_ ( iConfig.getParameter<edm::InputTag> ("vertices") )
22  , metToken_ ( consumes<reco::PFMETCollection> ( metInputTag_ ) )
23  , jetToken_ ( mayConsume<reco::PFJetCollection> ( jetInputTag_ ) )
24  , eleToken_ ( mayConsume<reco::GsfElectronCollection>( eleInputTag_ ) )
25  , muoToken_ ( mayConsume<reco::MuonCollection> ( muoInputTag_ ) )
26  , vtxToken_ ( mayConsume<reco::VertexCollection> ( vtxInputTag_ ) )
27  , met_variable_binning_ ( iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("metBinning") )
28  , met_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("metPSet") ) )
29  , ls_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("lsPSet") ) )
30  , num_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"),consumesCollector(), *this))
31  , den_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"),consumesCollector(), *this))
32  , metSelection_ ( iConfig.getParameter<std::string>("metSelection") )
33  , jetSelection_ ( iConfig.getParameter<std::string>("jetSelection") )
34  , eleSelection_ ( iConfig.getParameter<std::string>("eleSelection") )
35  , muoSelection_ ( iConfig.getParameter<std::string>("muoSelection") )
36  , njets_ ( iConfig.getParameter<unsigned>("njets" ) )
37  , nelectrons_ ( iConfig.getParameter<unsigned>("nelectrons" ) )
38  , nmuons_ ( iConfig.getParameter<unsigned>("nmuons" ) )
39 {
40  // this vector has to be alligned to the the number of Tokens accessed by this module
41  warningPrinted4token_.push_back(false); // PFMETCollection
42  warningPrinted4token_.push_back(false); // JetCollection
43  warningPrinted4token_.push_back(false); // GsfElectronCollection
44  warningPrinted4token_.push_back(false); // MuonCollection
45  warningPrinted4token_.push_back(false); // VertexCollection
46 }
47 
48 METMonitor::~METMonitor() = default;
49 
51 {
52  return METMonitor::MEbinning{
53  pset.getParameter<unsigned>("nbins"),
54  pset.getParameter<double>("xmin"),
55  pset.getParameter<double>("xmax"),
56  };
57 }
58 
60 {
61  return METMonitor::MEbinning{
62  pset.getParameter<unsigned>("nbins"),
63  0.,
64  double(pset.getParameter<unsigned>("nbins"))
65  };
66 }
67 
68 void METMonitor::setMETitle(METME& me, const std::string& titleX, const std::string& titleY)
69 {
70  me.numerator->setAxisTitle(titleX,1);
71  me.numerator->setAxisTitle(titleY,2);
72  me.denominator->setAxisTitle(titleX,1);
73  me.denominator->setAxisTitle(titleY,2);
74 
75 }
76 
77 void METMonitor::bookME(DQMStore::IBooker &ibooker, METME& me, const std::string& histname, const std::string& histtitle, int nbins, double min, double max)
78 {
79  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, min, max);
80  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, min, max);
81 }
82 void METMonitor::bookME(DQMStore::IBooker &ibooker, METME& me, const std::string& histname, const std::string& histtitle, const std::vector<double>& binning)
83 {
84  int nbins = binning.size()-1;
85  std::vector<float> fbinning(binning.begin(),binning.end());
86  float* arr = &fbinning[0];
87  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, arr);
88  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, arr);
89 }
90 void METMonitor::bookME(DQMStore::IBooker &ibooker, METME& me, const std::string& histname, const std::string& histtitle, int nbinsX, double xmin, double xmax, double ymin, double ymax)
91 {
92  me.numerator = ibooker.bookProfile(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, ymin, ymax);
93  me.denominator = ibooker.bookProfile(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, ymin, ymax);
94 }
95 void METMonitor::bookME(DQMStore::IBooker &ibooker, METME& me, const std::string& histname, const std::string& histtitle, int nbinsX, double xmin, double xmax, int nbinsY, double ymin, double ymax)
96 {
97  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
98  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
99 }
100 void METMonitor::bookME(DQMStore::IBooker &ibooker, METME& me, const std::string& histname, const std::string& histtitle, const std::vector<double>& binningX, const std::vector<double>& binningY)
101 {
102  int nbinsX = binningX.size()-1;
103  std::vector<float> fbinningX(binningX.begin(),binningX.end());
104  float* arrX = &fbinningX[0];
105  int nbinsY = binningY.size()-1;
106  std::vector<float> fbinningY(binningY.begin(),binningY.end());
107  float* arrY = &fbinningY[0];
108 
109  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, arrX, nbinsY, arrY);
110  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, arrX, nbinsY, arrY);
111 }
112 
114  edm::Run const & iRun,
115  edm::EventSetup const & iSetup)
116 {
117 
118  std::string histname, histtitle;
119 
120  std::string currentFolder = folderName_ ;
121  ibooker.setCurrentFolder(currentFolder);
122 
123  histname = "deltaphi_metjet1"; histtitle = "DPHI_METJ1";
125  setMETitle(deltaphimetj1ME_,"delta phi (met, j1)","events / 0.1 rad");
126 
127  histname = "deltaphi_jet1jet2"; histtitle = "DPHI_J1J2";
129  setMETitle(deltaphij1j2ME_,"delta phi (j1, j2)","events / 0.1 rad");
130 
131  histname = "met"; histtitle = "PFMET";
132  bookME(ibooker,metME_,histname,histtitle,met_binning_.nbins,met_binning_.xmin, met_binning_.xmax);
133  setMETitle(metME_,"PF MET [GeV]","events / [GeV]");
134 
135  histname = "met_variable"; histtitle = "PFMET";
136  bookME(ibooker,metME_variableBinning_,histname,histtitle,met_variable_binning_);
137  setMETitle(metME_variableBinning_,"PF MET [GeV]","events / [GeV]");
138 
139  histname = "metVsLS"; histtitle = "PFMET vs LS";
141  setMETitle(metVsLS_,"LS","PF MET [GeV]");
142 
143  histname = "metPhi"; histtitle = "PFMET phi";
144  bookME(ibooker,metPhiME_,histname,histtitle, phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
145  setMETitle(metPhiME_,"PF MET #phi","events / 0.1 rad");
146 
147  // Initialize the GenericTriggerEventFlag
148  if ( num_genTriggerEventFlag_ && num_genTriggerEventFlag_->on() ) num_genTriggerEventFlag_->initRun( iRun, iSetup );
149  if ( den_genTriggerEventFlag_ && den_genTriggerEventFlag_->on() ) den_genTriggerEventFlag_->initRun( iRun, iSetup );
150 
151 }
152 
158  // Filter out events if Trigger Filtering is requested
159  if (den_genTriggerEventFlag_->on() && ! den_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
161  iEvent.getByToken( metToken_, metHandle );
162  if ( !metHandle.isValid() ) {
163  if (!warningPrinted4token_[0]) {
164  edm::LogWarning("METMonitor") << "skipping events because the collection " << metInputTag_.label().c_str() << " is not available";
165  warningPrinted4token_[0] = true;
166  }
167  return;
168  }
169  reco::PFMET pfmet = metHandle->front();
170  if ( ! metSelection_( pfmet ) ) return;
171 
172  float met = pfmet.pt();
173  float phi = pfmet.phi();
174 
175  std::vector<reco::PFJet> jets;
177  iEvent.getByToken( jetToken_, jetHandle );
178  if ( jetHandle.isValid() ) {
179  if ( jetHandle->size() < njets_ ) return;
180  for ( auto const & j : *jetHandle ) {
181  if ( jetSelection_(j) ) {
182  jets.push_back(j);
183  }
184  }
185  } else {
186  if (!warningPrinted4token_[1]) {
187  if ( jetInputTag_.label().empty() )
188  edm::LogWarning("METMonitor") << "JetCollection not set";
189  else
190  edm::LogWarning("METMonitor") << "skipping events because the collection " << jetInputTag_.label().c_str() << " is not available";
191  warningPrinted4token_[1] = true;
192  }
193  // if Handle is not valid, because the InputTag has been mis-configured, then skip the event
194  if ( !jetInputTag_.label().empty() ) return;
195  }
196  float deltaPhi_met_j1= 10.0;
197  float deltaPhi_j1_j2 = 10.0;
198 
199  if (!jets.empty() ) deltaPhi_met_j1 = fabs( deltaPhi( pfmet.phi(), jets[0].phi() ));
200  if (jets.size() >= 2) deltaPhi_j1_j2 = fabs( deltaPhi( jets[0].phi(), jets[1].phi() ));
201 
202  std::vector<reco::GsfElectron> electrons;
204  iEvent.getByToken( eleToken_, eleHandle );
205  if ( eleHandle.isValid() ) {
206  if ( eleHandle->size() < nelectrons_ ) return;
207  for ( auto const & e : *eleHandle ) {
208  if ( eleSelection_( e ) ) electrons.push_back(e);
209  }
210  if (electrons.size() < nelectrons_ ) return;
211  } else {
212  if (!warningPrinted4token_[2]) {
213  warningPrinted4token_[2] = true;
214  if ( eleInputTag_.label().empty() )
215  edm::LogWarning("METMonitor") << "GsfElectronCollection not set";
216  else
217  edm::LogWarning("METMonitor") << "skipping events because the collection " << eleInputTag_.label().c_str() << " is not available";
218  }
219  if ( !eleInputTag_.label().empty() ) return;
220  }
221 
224  iEvent.getByToken(vtxToken_, vtxHandle);
225  if ( vtxHandle.isValid() ) {
226  for (auto const & v : *vtxHandle) {
227  bool isFake = v.isFake() ;
228 
229  if (!isFake) {
230  vtx = v;
231  break;
232  }
233  }
234  } else {
235  if (!warningPrinted4token_[3]) {
236  warningPrinted4token_[3] = true;
237  if ( vtxInputTag_.label().empty() )
238  edm::LogWarning("METMonitor") << "VertexCollection is not set";
239  else
240  edm::LogWarning("METMonitor") << "skipping events because the collection " << vtxInputTag_.label().c_str() << " is not available";
241  }
242  if ( !vtxInputTag_.label().empty() ) return;
243  }
244 
245 
246  std::vector<reco::Muon> muons;
248  iEvent.getByToken( muoToken_, muoHandle );
249  if ( muoHandle.isValid() ) {
250  if ( muoHandle->size() < nmuons_ ) return;
251  for ( auto const & m : *muoHandle ) {
252  bool pass = 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;
253  if ( muoSelection_( m ) && pass ) muons.push_back(m);
254  }
255  if ( muons.size() < nmuons_ ) return;
256  } else {
257  if (!warningPrinted4token_[4]) {
258  warningPrinted4token_[4] = true;
259  if ( muoInputTag_.label().empty() )
260  edm::LogWarning("METMonitor") << "MuonCollection not set";
261  else
262  edm::LogWarning("METMonitor") << "skipping events because the collection " << muoInputTag_.label().c_str() << " is not available";
263  }
264  if ( !muoInputTag_.label().empty() ) return;
265  }
266 
267  // filling histograms (denominator)
268  metME_.denominator -> Fill(met);
270  metPhiME_.denominator -> Fill(phi);
271  deltaphimetj1ME_.denominator -> Fill(deltaPhi_met_j1);
272  deltaphij1j2ME_.denominator -> Fill(deltaPhi_j1_j2);
273 
274  int ls = iEvent.id().luminosityBlock();
275  metVsLS_.denominator -> Fill(ls, met);
276  // applying selection for numerator
277  if (num_genTriggerEventFlag_->on() && ! num_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
278 
279  // filling histograms (num_genTriggerEventFlag_)
280  metME_.numerator -> Fill(met);
282  metPhiME_.numerator -> Fill(phi);
283  metVsLS_.numerator -> Fill(ls, met);
284  deltaphimetj1ME_.numerator -> Fill(deltaPhi_met_j1);
285  deltaphij1j2ME_.numerator -> Fill(deltaPhi_j1_j2);
286 }
287 
289 {
290  pset.add<unsigned> ( "nbins");
291  pset.add<double>( "xmin" );
292  pset.add<double>( "xmax" );
293 }
294 
296 {
297  pset.add<unsigned int> ( "nbins", 2500 );
298  pset.add<double> ( "xmin", 0.);
299  pset.add<double> ( "xmax", 2500.);
300 }
301 
303 {
305  desc.add<std::string> ( "FolderName", "HLT/MET" );
306 
307  desc.add<edm::InputTag>( "met", edm::InputTag("pfMet") );
308  desc.add<edm::InputTag>( "jets", edm::InputTag("ak4PFJetsCHS") );
309  desc.add<edm::InputTag>( "electrons",edm::InputTag("gedGsfElectrons") );
310  desc.add<edm::InputTag>( "muons", edm::InputTag("muons") );
311  desc.add<edm::InputTag>( "vertices",edm::InputTag("offlinePrimaryVertices") );
312  desc.add<std::string>("metSelection", "pt > 0");
313  desc.add<std::string>("jetSelection", "pt > 0");
314  desc.add<std::string>("eleSelection", "pt > 0");
315  desc.add<std::string>("muoSelection", "pt > 0");
316  desc.add<unsigned>("njets", 0);
317  desc.add<unsigned>("nelectrons", 0);
318  desc.add<unsigned>("nmuons", 0);
319 
320  edm::ParameterSetDescription genericTriggerEventPSet;
321  genericTriggerEventPSet.add<bool>("andOr");
322  genericTriggerEventPSet.add<edm::InputTag>("dcsInputTag", edm::InputTag("scalersRawToDigi") );
323  genericTriggerEventPSet.add<std::vector<int> >("dcsPartitions",{});
324  genericTriggerEventPSet.add<bool>("andOrDcs", false);
325  genericTriggerEventPSet.add<bool>("errorReplyDcs", true);
326  genericTriggerEventPSet.add<std::string>("dbLabel","");
327  genericTriggerEventPSet.add<bool>("andOrHlt", true);
328  genericTriggerEventPSet.add<edm::InputTag>("hltInputTag", edm::InputTag("TriggerResults::HLT") );
329  genericTriggerEventPSet.add<std::vector<std::string> >("hltPaths",{});
330  genericTriggerEventPSet.add<std::string>("hltDBKey","");
331  genericTriggerEventPSet.add<bool>("errorReplyHlt",false);
332  genericTriggerEventPSet.add<unsigned int>("verbosityLevel",1);
333 
334  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
335  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
336 
339  fillHistoPSetDescription(metPSet);
340  histoPSet.add<edm::ParameterSetDescription>("metPSet", metPSet);
341  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.,1000.};
342  histoPSet.add<std::vector<double> >("metBinning", bins);
343 
346  histoPSet.add<edm::ParameterSetDescription>("lsPSet", lsPSet);
347 
348  desc.add<edm::ParameterSetDescription>("histoPSet",histoPSet);
349 
350  descriptions.add("metMonitoring", desc);
351 }
352 
353 // Define this as a plug-in
void setMETitle(METME &me, const std::string &titleX, const std::string &titleY)
Definition: METMonitor.cc:68
T getParameter(std::string const &) const
unsigned nmuons_
Definition: METMonitor.h:124
edm::InputTag vtxInputTag_
Definition: METMonitor.h:95
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
Definition: METMonitor.h:115
MonitorElement * numerator
Definition: METMonitor.h:60
static MEbinning getHistoPSet(const edm::ParameterSet &pset)
Definition: METMonitor.cc:50
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::InputTag muoInputTag_
Definition: METMonitor.h:94
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: METMonitor.h:101
double pt() const final
transverse momentum
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
StringCutObjectSelector< reco::Muon, true > muoSelection_
Definition: METMonitor.h:120
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
Definition: METMonitor.h:114
edm::InputTag eleInputTag_
Definition: METMonitor.h:93
static MEbinning getHistoLSPSet(const edm::ParameterSet &pset)
Definition: METMonitor.cc:59
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
StringCutObjectSelector< reco::GsfElectron, true > eleSelection_
Definition: METMonitor.h:119
METME metME_variableBinning_
Definition: METMonitor.h:108
const Point & position() const
position
Definition: Vertex.h:109
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
~METMonitor() override
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
Definition: METMonitor.cc:288
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::string folderName_
Definition: METMonitor.h:88
unsigned njets_
Definition: METMonitor.h:122
StringCutObjectSelector< reco::PFJet, true > jetSelection_
Definition: METMonitor.h:118
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
Definition: METMonitor.cc:295
int iEvent
Definition: GenABIO.cc:230
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
edm::EDGetTokenT< reco::GsfElectronCollection > eleToken_
Definition: METMonitor.h:99
MonitorElement * denominator
Definition: METMonitor.h:61
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
MEbinning met_binning_
Definition: METMonitor.h:104
edm::EDGetTokenT< reco::PFJetCollection > jetToken_
Definition: METMonitor.h:98
vector< PseudoJet > jets
edm::EDGetTokenT< reco::PFMETCollection > metToken_
Definition: METMonitor.h:97
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
edm::EDGetTokenT< reco::MuonCollection > muoToken_
Definition: METMonitor.h:100
METME deltaphij1j2ME_
Definition: METMonitor.h:112
T min(T a, T b)
Definition: MathUtil.h:58
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool isValid() const
Definition: HandleBase.h:74
void bookME(DQMStore::IBooker &, METME &me, const std::string &histname, const std::string &histtitle, int nbins, double xmin, double xmax)
Definition: METMonitor.cc:77
static MEbinning phi_binning_
Definition: METMonitor.h:128
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: METMonitor.cc:157
def ls(path, rec=False)
Definition: eostools.py:349
unsigned nelectrons_
Definition: METMonitor.h:123
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
met
===> hadronic RAZOR
std::vector< double > met_variable_binning_
Definition: METMonitor.h:103
METME metPhiME_
Definition: METMonitor.h:110
void add(std::string const &label, ParameterSetDescription const &psetDescription)
METME metVsLS_
Definition: METMonitor.h:109
std::string const & label() const
Definition: InputTag.h:36
edm::InputTag metInputTag_
Definition: METMonitor.h:91
edm::EventID id() const
Definition: EventBase.h:60
std::vector< PFJet > PFJetCollection
collection of PFJet objects
fixed size matrix
HLT enums.
MEbinning ls_binning_
Definition: METMonitor.h:105
StringCutObjectSelector< reco::MET, true > metSelection_
Definition: METMonitor.h:117
edm::InputTag jetInputTag_
Definition: METMonitor.h:92
METMonitor(const edm::ParameterSet &)
Definition: METMonitor.cc:15
METME deltaphimetj1ME_
Definition: METMonitor.h:111
std::vector< bool > warningPrinted4token_
Definition: METMonitor.h:132
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: METMonitor.cc:113
METME metME_
Definition: METMonitor.h:107
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)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: METMonitor.cc:302
Definition: Run.h:44
Collection of PF MET.