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