CMS 3D CMS Logo

METMonitor.cc
Go to the documentation of this file.
2 
4 
6 
8 
9 
10 double MAX_PHI = 3.2;
11 int N_PHI = 64;
13  N_PHI, -MAX_PHI, MAX_PHI
14 };
15 // -----------------------------
16 // constructors and destructor
17 // -----------------------------
18 
20  folderName_ ( iConfig.getParameter<std::string>("FolderName") )
21  , metToken_ ( consumes<reco::PFMETCollection> (iConfig.getParameter<edm::InputTag>("met") ) )
22  , jetToken_ ( mayConsume<reco::PFJetCollection> (iConfig.getParameter<edm::InputTag>("jets") ) )
23  , eleToken_ ( mayConsume<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons") ) )
24  , muoToken_ ( mayConsume<reco::MuonCollection> (iConfig.getParameter<edm::InputTag>("muons") ) )
25  , met_variable_binning_ ( iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("metBinning") )
26  , met_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("metPSet") ) )
27  , ls_binning_ ( getHistoLSPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("lsPSet") ) )
28  , num_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"),consumesCollector(), *this))
29  , den_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"),consumesCollector(), *this))
30  , metSelection_ ( iConfig.getParameter<std::string>("metSelection") )
31  , jetSelection_ ( iConfig.getParameter<std::string>("jetSelection") )
32  , eleSelection_ ( iConfig.getParameter<std::string>("eleSelection") )
33  , muoSelection_ ( iConfig.getParameter<std::string>("muoSelection") )
34  , njets_ ( iConfig.getParameter<int>("njets" ) )
35  , nelectrons_ ( iConfig.getParameter<int>("nelectrons" ) )
36  , nmuons_ ( iConfig.getParameter<int>("nmuons" ) )
37 {
38 
39  metME_.numerator = nullptr;
40  metME_.denominator = nullptr;
43  metVsLS_.numerator = nullptr;
44  metVsLS_.denominator = nullptr;
45  metPhiME_.numerator = nullptr;
46  metPhiME_.denominator = nullptr;
47 
48 }
49 
51 {
54 }
55 
57 {
58  return MEbinning{
59  pset.getParameter<int32_t>("nbins"),
60  pset.getParameter<double>("xmin"),
61  pset.getParameter<double>("xmax"),
62  };
63 }
64 
66 {
67  return MEbinning{
68  pset.getParameter<int32_t>("nbins"),
69  0.,
70  double(pset.getParameter<int32_t>("nbins"))
71  };
72 }
73 
75 {
76  me.numerator->setAxisTitle(titleX,1);
77  me.numerator->setAxisTitle(titleY,2);
78  me.denominator->setAxisTitle(titleX,1);
79  me.denominator->setAxisTitle(titleY,2);
80 
81 }
82 
83 void METMonitor::bookME(DQMStore::IBooker &ibooker, METME& me, std::string& histname, std::string& histtitle, int& nbins, double& min, double& max)
84 {
85  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, min, max);
86  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, min, max);
87 }
88 void METMonitor::bookME(DQMStore::IBooker &ibooker, METME& me, std::string& histname, std::string& histtitle, std::vector<double> binning)
89 {
90  int nbins = binning.size()-1;
91  std::vector<float> fbinning(binning.begin(),binning.end());
92  float* arr = &fbinning[0];
93  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, arr);
94  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, arr);
95 }
96 void METMonitor::bookME(DQMStore::IBooker &ibooker, METME& me, std::string& histname, std::string& histtitle, int& nbinsX, double& xmin, double& xmax, double& ymin, double& ymax)
97 {
98  me.numerator = ibooker.bookProfile(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, ymin, ymax);
99  me.denominator = ibooker.bookProfile(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, ymin, ymax);
100 }
101 void METMonitor::bookME(DQMStore::IBooker &ibooker, METME& me, std::string& histname, std::string& histtitle, int& nbinsX, double& xmin, double& xmax, int& nbinsY, double& ymin, double& ymax)
102 {
103  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
104  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
105 }
106 void METMonitor::bookME(DQMStore::IBooker &ibooker, METME& me, std::string& histname, std::string& histtitle, std::vector<double> binningX, std::vector<double> binningY)
107 {
108  int nbinsX = binningX.size()-1;
109  std::vector<float> fbinningX(binningX.begin(),binningX.end());
110  float* arrX = &fbinningX[0];
111  int nbinsY = binningY.size()-1;
112  std::vector<float> fbinningY(binningY.begin(),binningY.end());
113  float* arrY = &fbinningY[0];
114 
115  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, arrX, nbinsY, arrY);
116  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, arrX, nbinsY, arrY);
117 }
118 
120  edm::Run const & iRun,
121  edm::EventSetup const & iSetup)
122 {
123 
124  std::string histname, histtitle;
125 
126  std::string currentFolder = folderName_ ;
127  ibooker.setCurrentFolder(currentFolder.c_str());
128 
129  histname = "met"; histtitle = "PFMET";
130  bookME(ibooker,metME_,histname,histtitle,met_binning_.nbins,met_binning_.xmin, met_binning_.xmax);
131  setMETitle(metME_,"PF MET [GeV]","events / [GeV]");
132 
133  histname = "met_variable"; histtitle = "PFMET";
134  bookME(ibooker,metME_variableBinning_,histname,histtitle,met_variable_binning_);
135  setMETitle(metME_variableBinning_,"PF MET [GeV]","events / [GeV]");
136 
137  histname = "metVsLS"; histtitle = "PFMET vs LS";
139  setMETitle(metVsLS_,"LS","PF MET [GeV]");
140 
141  histname = "metPhi"; histtitle = "PFMET phi";
142  bookME(ibooker,metPhiME_,histname,histtitle, phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
143  setMETitle(metPhiME_,"PF MET #phi","events / 0.1 rad");
144 
145  // Initialize the GenericTriggerEventFlag
148 
149 }
150 
156 
157  // Filter out events if Trigger Filtering is requested
158  if (den_genTriggerEventFlag_->on() && ! den_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
159 
161  iEvent.getByToken( metToken_, metHandle );
162  reco::PFMET pfmet = metHandle->front();
163  if ( ! metSelection_( pfmet ) ) return;
164 
165  float met = pfmet.pt();
166  float phi = pfmet.phi();
167 
169  iEvent.getByToken( jetToken_, jetHandle );
170  std::vector<reco::PFJet> jets;
171  if ( int(jetHandle->size()) < njets_ ) return;
172  for ( auto const & j : *jetHandle ) {
173  if ( jetSelection_( j ) ) jets.push_back(j);
174  }
175  if ( int(jets.size()) < njets_ ) return;
176 
178  iEvent.getByToken( eleToken_, eleHandle );
179  std::vector<reco::GsfElectron> electrons;
180  if ( int(eleHandle->size()) < nelectrons_ ) return;
181  for ( auto const & e : *eleHandle ) {
182  if ( eleSelection_( e ) ) electrons.push_back(e);
183  }
184  if ( int(electrons.size()) < nelectrons_ ) return;
185 
187  iEvent.getByToken( muoToken_, muoHandle );
188  if ( int(muoHandle->size()) < nmuons_ ) return;
189  std::vector<reco::Muon> muons;
190  for ( auto const & m : *muoHandle ) {
191  if ( muoSelection_( m ) ) muons.push_back(m);
192  }
193  if ( int(muons.size()) < nmuons_ ) return;
194 
195  // filling histograms (denominator)
196  metME_.denominator -> Fill(met);
198  metPhiME_.denominator -> Fill(phi);
199 
200  int ls = iEvent.id().luminosityBlock();
201  metVsLS_.denominator -> Fill(ls, met);
202 
203  // applying selection for numerator
204  if (num_genTriggerEventFlag_->on() && ! num_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
205 
206  // filling histograms (num_genTriggerEventFlag_)
207  metME_.numerator -> Fill(met);
209  metPhiME_.numerator -> Fill(phi);
210  metVsLS_.numerator -> Fill(ls, met);
211 
212 }
213 
215 {
216  pset.add<int> ( "nbins");
217  pset.add<double>( "xmin" );
218  pset.add<double>( "xmax" );
219 }
220 
222 {
223  pset.add<int> ( "nbins", 2500);
224 }
225 
227 {
229  desc.add<std::string> ( "FolderName", "HLT/MET" );
230 
231  desc.add<edm::InputTag>( "met", edm::InputTag("pfMet") );
232  desc.add<edm::InputTag>( "jets", edm::InputTag("ak4PFJetsCHS") );
233  desc.add<edm::InputTag>( "electrons",edm::InputTag("gedGsfElectrons") );
234  desc.add<edm::InputTag>( "muons", edm::InputTag("muons") );
235  desc.add<std::string>("metSelection", "pt > 0");
236  desc.add<std::string>("jetSelection", "pt > 0");
237  desc.add<std::string>("eleSelection", "pt > 0");
238  desc.add<std::string>("muoSelection", "pt > 0");
239  desc.add<int>("njets", 0);
240  desc.add<int>("nelectrons", 0);
241  desc.add<int>("nmuons", 0);
242 
243  edm::ParameterSetDescription genericTriggerEventPSet;
244  genericTriggerEventPSet.add<bool>("andOr");
245  genericTriggerEventPSet.add<edm::InputTag>("dcsInputTag", edm::InputTag("scalersRawToDigi") );
246  genericTriggerEventPSet.add<std::vector<int> >("dcsPartitions",{});
247  genericTriggerEventPSet.add<bool>("andOrDcs", false);
248  genericTriggerEventPSet.add<bool>("errorReplyDcs", true);
249  genericTriggerEventPSet.add<std::string>("dbLabel","");
250  genericTriggerEventPSet.add<bool>("andOrHlt", true);
251  genericTriggerEventPSet.add<edm::InputTag>("hltInputTag", edm::InputTag("TriggerResults::HLT") );
252  genericTriggerEventPSet.add<std::vector<std::string> >("hltPaths",{});
253  genericTriggerEventPSet.add<std::string>("hltDBKey","");
254  genericTriggerEventPSet.add<bool>("errorReplyHlt",false);
255  genericTriggerEventPSet.add<unsigned int>("verbosityLevel",1);
256 
257  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
258  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
259 
262  fillHistoPSetDescription(metPSet);
263  histoPSet.add<edm::ParameterSetDescription>("metPSet", metPSet);
264  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.};
265  histoPSet.add<std::vector<double> >("metBinning", bins);
266 
269  histoPSet.add<edm::ParameterSetDescription>("lsPSet", lsPSet);
270 
271  desc.add<edm::ParameterSetDescription>("histoPSet",histoPSet);
272 
273  descriptions.add("metMonitoring", desc);
274 }
275 
276 // Define this as a plug-in
MonitorElement * numerator
Definition: METMonitor.h:49
T getParameter(std::string const &) const
virtual double pt() const final
transverse momentum
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:157
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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:104
GenericTriggerEventFlag * den_genTriggerEventFlag_
Definition: METMonitor.h:99
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
StringCutObjectSelector< reco::GsfElectron, true > eleSelection_
Definition: METMonitor.h:103
METME metME_variableBinning_
Definition: METMonitor.h:94
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
Definition: METMonitor.cc:214
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
std::string folderName_
Definition: METMonitor.h:81
virtual double phi() const final
momentum azimuthal angle
StringCutObjectSelector< reco::PFJet, true > jetSelection_
Definition: METMonitor.h:102
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
Definition: METMonitor.cc:221
int iEvent
Definition: GenABIO.cc:230
static MEbinning getHistoPSet(edm::ParameterSet pset)
Definition: METMonitor.cc:56
edm::EDGetTokenT< reco::GsfElectronCollection > eleToken_
Definition: METMonitor.h:86
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
bool accept(const edm::Event &event, const edm::EventSetup &setup)
To be called from analyze/filter() methods.
MEbinning met_binning_
Definition: METMonitor.h:90
edm::EDGetTokenT< reco::PFJetCollection > jetToken_
Definition: METMonitor.h:85
vector< PseudoJet > jets
double xmin
Definition: LumiMonitor.h:30
static MEbinning getHistoLSPSet(edm::ParameterSet pset)
Definition: METMonitor.cc:65
edm::EDGetTokenT< reco::PFMETCollection > metToken_
Definition: METMonitor.h:84
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
int j
Definition: DBlmapReader.cc:9
MonitorElement * denominator
Definition: METMonitor.h:50
GenericTriggerEventFlag * num_genTriggerEventFlag_
Definition: METMonitor.h:98
edm::EDGetTokenT< reco::MuonCollection > muoToken_
Definition: METMonitor.h:87
T min(T a, T b)
Definition: MathUtil.h:58
void setMETitle(METME &me, std::string titleX, std::string titleY)
Definition: METMonitor.cc:74
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void bookME(DQMStore::IBooker &, METME &me, std::string &histname, std::string &histtitle, int &nbins, double &xmin, double &xmax)
Definition: METMonitor.cc:83
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: METMonitor.cc:155
def ls(path, rec=False)
Definition: eostools.py:348
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
met
===> hadronic RAZOR
std::vector< double > met_variable_binning_
Definition: METMonitor.h:89
METME metPhiME_
Definition: METMonitor.h:96
void add(std::string const &label, ParameterSetDescription const &psetDescription)
METME metVsLS_
Definition: METMonitor.h:95
edm::EventID id() const
Definition: EventBase.h:58
std::vector< PFJet > PFJetCollection
collection of PFJet objects
fixed size matrix
HLT enums.
int N_PHI
Definition: METMonitor.cc:11
MEbinning ls_binning_
Definition: METMonitor.h:91
StringCutObjectSelector< reco::MET, true > metSelection_
Definition: METMonitor.h:101
MEbinning phi_binning_
Definition: METMonitor.cc:12
METMonitor(const edm::ParameterSet &)
Definition: METMonitor.cc:19
int nelectrons_
Definition: METMonitor.h:106
void initRun(const edm::Run &run, const edm::EventSetup &setup)
To be called from beginRun() methods.
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: METMonitor.cc:119
METME metME_
Definition: METMonitor.h:93
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:226
double MAX_PHI
Definition: METMonitor.cc:10
Definition: Run.h:42
double xmax
Definition: LumiMonitor.h:31
Collection of PF MET.