CMS 3D CMS Logo

MuonMonitor.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 
23 
24 class MuonMonitor : public DQMEDAnalyzer, public TriggerDQMBase {
25 public:
28 
30  ~MuonMonitor() throw() override;
31 
32  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
33 
34 protected:
36  void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
37 
38 private:
40 
43 
47  edm::EDGetTokenT<edm::View<reco::GsfElectron>> eleToken_;
48 
49  static constexpr double MAX_PHI = 3.2;
50  static constexpr int N_PHI = 64;
52 
53  static constexpr double MAX_dxy = 2.5;
54  static constexpr int N_dxy = 50;
56 
57  static constexpr double MAX_ETA = 2.4;
58  static constexpr int N_ETA = 68;
60 
61  std::vector<double> muon_variable_binning_;
62  std::vector<double> muoneta_variable_binning_;
65  std::vector<double> muPt_variable_binning_2D_;
66  std::vector<double> elePt_variable_binning_2D_;
67  std::vector<double> muEta_variable_binning_2D_;
68  std::vector<double> eleEta_variable_binning_2D_;
69 
70  ObjME muonME_;
71  ObjME muonEtaME_;
72  ObjME muonPhiME_;
74  ObjME muonVsLS_;
76  ObjME muondxy_;
77  ObjME muondz_;
80  ObjME eleEtaME_;
82  ObjME elePt_muPt_;
83 
84  std::unique_ptr<GenericTriggerEventFlag> num_genTriggerEventFlag_;
85  std::unique_ptr<GenericTriggerEventFlag> den_genTriggerEventFlag_;
86 
90 
91  unsigned int nmuons_;
92  unsigned int nelectrons_;
93 };
94 
96  : folderName_(iConfig.getParameter<std::string>("FolderName")),
97  requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
98  hltPathsAreValid_(false),
99  metToken_(consumes<reco::PFMETCollection>(iConfig.getParameter<edm::InputTag>("met"))),
100  muonToken_(mayConsume<reco::MuonCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
101  vtxToken_(mayConsume<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"))),
102  eleToken_(mayConsume<edm::View<reco::GsfElectron>>(iConfig.getParameter<edm::InputTag>("electrons"))),
103  muon_variable_binning_(
104  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double>>("muonBinning")),
105  muoneta_variable_binning_(
106  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double>>("muonetaBinning")),
107  muon_binning_(getHistoPSet(
108  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("muonPSet"))),
109  ls_binning_(
110  getHistoPSet(iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("lsPSet"))),
111  muPt_variable_binning_2D_(
112  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double>>("muPtBinning2D")),
113  elePt_variable_binning_2D_(
114  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double>>("elePtBinning2D")),
115  muEta_variable_binning_2D_(
116  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double>>("muEtaBinning2D")),
117  eleEta_variable_binning_2D_(
118  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double>>("eleEtaBinning2D")),
119  num_genTriggerEventFlag_(new GenericTriggerEventFlag(
120  iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"), consumesCollector(), *this)),
121  den_genTriggerEventFlag_(new GenericTriggerEventFlag(
122  iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"), consumesCollector(), *this)),
123  metSelection_(iConfig.getParameter<std::string>("metSelection")),
124  muonSelection_(iConfig.getParameter<std::string>("muonSelection")),
125  eleSelection_(iConfig.getParameter<std::string>("eleSelection")),
126  nmuons_(iConfig.getParameter<unsigned int>("nmuons")),
127  nelectrons_(iConfig.getParameter<unsigned int>("nelectrons")) {}
128 
131  num_genTriggerEventFlag_.reset();
132  }
134  den_genTriggerEventFlag_.reset();
135  }
136 }
137 
138 void MuonMonitor::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) {
139  // Initialize the GenericTriggerEventFlag
141  num_genTriggerEventFlag_->initRun(iRun, iSetup);
142  }
144  den_genTriggerEventFlag_->initRun(iRun, iSetup);
145  }
146 
147  // check if every HLT path specified in numerator and denominator has a valid match in the HLT Menu
149  den_genTriggerEventFlag_->on() && num_genTriggerEventFlag_->allHLTPathsAreValid() &&
150  den_genTriggerEventFlag_->allHLTPathsAreValid());
151 
152  // if valid HLT paths are required,
153  // create DQM outputs only if all paths are valid
155  return;
156  }
157 
158  std::string histname, histtitle;
159 
160  ibooker.setCurrentFolder(folderName_);
161 
162  histname = "muon_pt";
163  histtitle = "muon PT";
164  bookME(ibooker, muonME_, histname, histtitle, muon_binning_.nbins, muon_binning_.xmin, muon_binning_.xmax);
165  setMETitle(muonME_, "Muon pT [GeV]", "events / [GeV]");
166 
167  histname = "muon_pt_variable";
168  histtitle = "muon PT";
169  bookME(ibooker, muonME_variableBinning_, histname, histtitle, muon_variable_binning_);
170  setMETitle(muonME_variableBinning_, "Muon pT [GeV]", "events / [GeV]");
171 
172  histname = "muonVsLS";
173  histtitle = "muon pt vs LS";
174  bookME(ibooker,
175  muonVsLS_,
176  histname,
177  histtitle,
183  setMETitle(muonVsLS_, "LS", "Muon pT [GeV]");
184 
185  histname = "muon_phi";
186  histtitle = "Muon phi";
187  bookME(ibooker, muonPhiME_, histname, histtitle, phi_binning_.nbins, phi_binning_.xmin, phi_binning_.xmax);
188  setMETitle(muonPhiME_, "Muon #phi", "events / 0.1 rad");
189 
190  histname = "muon_eta";
191  histtitle = "Muon eta";
192  bookME(ibooker, muonEtaME_, histname, histtitle, eta_binning_.nbins, eta_binning_.xmin, eta_binning_.xmax);
193  setMETitle(muonEtaME_, "Muon #eta", "events");
194 
195  histname = "muon_eta_variablebinning";
196  histtitle = "Muon eta";
197  bookME(ibooker, muonEtaME_variableBinning_, histname, histtitle, muoneta_variable_binning_);
198  setMETitle(muonEtaME_variableBinning_, "Muon #eta", "events");
199 
200  histname = "muon_dxy";
201  histtitle = "Muon dxy";
202  bookME(ibooker, muondxy_, histname, histtitle, dxy_binning_.nbins, dxy_binning_.xmin, dxy_binning_.xmax);
203  setMETitle(muondxy_, "Muon #dxy", "events");
204 
205  histname = "muon_dz";
206  histtitle = "Muon dz";
207  bookME(ibooker, muondz_, histname, histtitle, dxy_binning_.nbins, dxy_binning_.xmin, dxy_binning_.xmax);
208  setMETitle(muondz_, "Muon #dz", "events");
209 
210  histname = "muon_etaphi";
211  histtitle = "Muon eta-phi";
212  bookME(ibooker,
214  histname,
215  histtitle,
222  setMETitle(muonEtaPhiME_, "#eta", "#phi");
223 
224  histname = "electron_pt_variable";
225  histtitle = "electron PT";
226  bookME(ibooker, eleME_variableBinning_, histname, histtitle, muon_variable_binning_);
227  setMETitle(eleME_variableBinning_, "Electron pT [GeV]", "events / [GeV]");
228 
229  histname = "electron_eta";
230  histtitle = "electron eta";
231  bookME(ibooker, eleEtaME_, histname, histtitle, eta_binning_.nbins, eta_binning_.xmin, eta_binning_.xmax);
232  setMETitle(eleEtaME_, "Electron #eta", "events");
233 
234  histname = "elePt_muPt";
235  histtitle = "electron pt vs muon pt";
237  setMETitle(elePt_muPt_, "electron pt [GeV]", "muon pt [GeV]");
238 
239  histname = "eleEta_muEta";
240  histtitle = "electron #eta vs muon #eta";
242  setMETitle(eleEta_muEta_, "electron #eta", "muon #eta");
243 }
244 
246  // if valid HLT paths are required,
247  // analyze event only if all paths are valid
249  return;
250  }
251 
252  // Filter out events if Trigger Filtering is requested
253  if (den_genTriggerEventFlag_->on() && !den_genTriggerEventFlag_->accept(iEvent, iSetup)) {
254  return;
255  }
256 
258  iEvent.getByToken(metToken_, metHandle);
259  reco::PFMET pfmet = metHandle->front();
260  if (!metSelection_(pfmet)) {
261  return;
262  }
263 
265  iEvent.getByToken(vtxToken_, vtxHandle);
266 
267  math::XYZPoint pv(0, 0, 0);
268  for (reco::Vertex const& v : *vtxHandle) {
269  if (not v.isFake()) {
270  pv.SetXYZ(v.x(), v.y(), v.z());
271  break;
272  }
273  }
274 
276  iEvent.getByToken(muonToken_, muonHandle);
277  std::vector<reco::Muon> muons;
278  if (muonHandle->size() < nmuons_)
279  return;
280  for (auto const& p : *muonHandle) {
281  if (muonSelection_(p))
282  muons.push_back(p);
283  }
284  if (muons.size() < nmuons_)
285  return;
286 
288  iEvent.getByToken(eleToken_, eleHandle);
289  std::vector<reco::GsfElectron> electrons;
290  if (eleHandle->size() < nelectrons_)
291  return;
292  for (auto const& e : *eleHandle) {
293  if (eleSelection_(e))
294  electrons.push_back(e);
295  }
296  if (electrons.size() < nelectrons_)
297  return;
298 
299  // filling histograms (denominator)
300  const int ls = iEvent.id().luminosityBlock();
301 
302  if (!muons.empty()) {
309  muondxy_.denominator->Fill(muons[0].muonBestTrack()->dxy(pv));
310  muondz_.denominator->Fill(muons[0].muonBestTrack()->dz(pv));
311  if (!electrons.empty()) {
316  }
317  }
318 
319  // applying selection for numerator
320  if (num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup))
321  return;
322 
323  // filling histograms (num_genTriggerEventFlag_)
324  if (!muons.empty()) {
325  muonME_.numerator->Fill(muons[0].pt());
329  muonVsLS_.numerator->Fill(ls, muons[0].pt());
331  muondxy_.numerator->Fill(muons[0].muonBestTrack()->dxy(pv));
332  muondz_.numerator->Fill(muons[0].muonBestTrack()->dz(pv));
333  if (!electrons.empty()) {
338  }
339  }
340 }
341 
344  desc.add<std::string>("FolderName", "HLT/Muon");
345  desc.add<bool>("requireValidHLTPaths", true);
346 
347  desc.add<edm::InputTag>("met", edm::InputTag("pfMet"));
348  desc.add<edm::InputTag>("muons", edm::InputTag("muons"));
349  desc.add<edm::InputTag>("vertices", edm::InputTag("offlinePrimaryVertices"));
350  desc.add<edm::InputTag>("electrons", edm::InputTag("gedGsfElectrons"));
351  desc.add<std::string>("metSelection", "pt > 0");
352  desc.add<std::string>("muonSelection", "pt > 6 && eta<2.4");
353  desc.add<std::string>("eleSelection", "pt > 0");
354  desc.add<unsigned int>("nmuons", 0);
355  desc.add<unsigned int>("nelectrons", 0);
356 
359  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
360  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
361 
366  std::vector<double> bins = {0., 20., 40., 60., 80., 90., 100., 110., 120., 130., 140., 150., 160.,
367  170., 180., 190., 200., 220., 240., 260., 280., 300., 350., 400., 450., 1000.};
368  histoPSet.add<std::vector<double>>("muonBinning", bins);
369 
370  std::vector<double> etabins = {-3., -2.5, -2., -1.5, -1., -.5, 0., .5, 1., 1.5, 2., 2.5, 3.};
371  histoPSet.add<std::vector<double>>("muonetaBinning", etabins);
372 
373  std::vector<double> bins_2D = {0., 40., 80., 100., 120., 140., 160., 180., 200., 240., 280., 350., 450., 1000.};
374  std::vector<double> eta_bins_2D = {-3., -2., -1., 0., 1., 2., 3.};
375  std::vector<double> phi_bins_2D = {
376  -3.1415, -2.5132, -1.8849, -1.2566, -0.6283, 0, 0.6283, 1.2566, 1.8849, 2.5132, 3.1415};
377  histoPSet.add<std::vector<double>>("elePtBinning2D", bins_2D);
378  histoPSet.add<std::vector<double>>("muPtBinning2D", bins_2D);
379  histoPSet.add<std::vector<double>>("eleEtaBinning2D", eta_bins_2D);
380  histoPSet.add<std::vector<double>>("muEtaBinning2D", eta_bins_2D);
381 
385 
386  desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
387 
388  descriptions.add("muonMonitoring", desc);
389 }
390 
static constexpr double MAX_PHI
Definition: MuonMonitor.cc:49
std::vector< double > muPt_variable_binning_2D_
Definition: MuonMonitor.cc:65
StringCutObjectSelector< reco::MET, true > metSelection_
Definition: MuonMonitor.cc:87
dqm::reco::DQMStore DQMStore
Definition: MuonMonitor.cc:27
static constexpr double MAX_dxy
Definition: MuonMonitor.cc:53
edm::EDGetTokenT< reco::PFMETCollection > metToken_
Definition: MuonMonitor.cc:44
ObjME muonEtaME_variableBinning_
Definition: MuonMonitor.cc:78
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
const bool requireValidHLTPaths_
Definition: MuonMonitor.cc:41
unsigned int nelectrons_
Definition: MuonMonitor.cc:92
ObjME elePt_muPt_
Definition: MuonMonitor.cc:82
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ObjME muondxy_
Definition: MuonMonitor.cc:76
MuonMonitor(const edm::ParameterSet &)
Definition: MuonMonitor.cc:95
std::vector< double > muoneta_variable_binning_
Definition: MuonMonitor.cc:62
const MEbinning dxy_binning_
Definition: MuonMonitor.cc:55
static constexpr int N_ETA
Definition: MuonMonitor.cc:58
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
Definition: MuonMonitor.cc:84
ObjME muonVsLS_
Definition: MuonMonitor.cc:74
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: MuonMonitor.cc:46
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
ObjME muonEtaPhiME_
Definition: MuonMonitor.cc:75
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
ObjME eleME_variableBinning_
Definition: MuonMonitor.cc:79
std::vector< Vertex > VertexCollection
Definition: Vertex.h:31
void setMETitle(ObjME &me, const std::string &titleX, const std::string &titleY)
const MEbinning phi_binning_
Definition: MuonMonitor.cc:51
std::vector< double > muEta_variable_binning_2D_
Definition: MuonMonitor.cc:67
ObjME muonEtaME_
Definition: MuonMonitor.cc:71
ObjME muondz_
Definition: MuonMonitor.cc:77
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
StringCutObjectSelector< reco::GsfElectron, true > eleSelection_
Definition: MuonMonitor.cc:89
ObjME muonME_variableBinning_
Definition: MuonMonitor.cc:73
MEbinning ls_binning_
Definition: MuonMonitor.cc:64
ObjME eleEta_muEta_
Definition: MuonMonitor.cc:81
void Fill(long long x)
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: MuonMonitor.cc:245
MEbinning muon_binning_
Definition: MuonMonitor.cc:63
ObjME muonPhiME_
Definition: MuonMonitor.cc:72
edm::EDGetTokenT< edm::View< reco::GsfElectron > > eleToken_
Definition: MuonMonitor.cc:47
int iEvent
Definition: GenABIO.cc:224
static constexpr int N_dxy
Definition: MuonMonitor.cc:54
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
Definition: MuonMonitor.cc:85
static constexpr double MAX_ETA
Definition: MuonMonitor.cc:57
const std::string folderName_
Definition: MuonMonitor.cc:39
MonitorElement * denominator
MonitorElement * numerator
def pv(vc)
Definition: MetAnalyzer.py:7
edm::EDGetTokenT< reco::MuonCollection > muonToken_
Definition: MuonMonitor.cc:45
std::vector< double > elePt_variable_binning_2D_
Definition: MuonMonitor.cc:66
std::vector< double > muon_variable_binning_
Definition: MuonMonitor.cc:61
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: MuonMonitor.cc:138
def ls(path, rec=False)
Definition: eostools.py:349
unsigned int nmuons_
Definition: MuonMonitor.cc:91
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
bool hltPathsAreValid_
Definition: MuonMonitor.cc:42
void add(std::string const &label, ParameterSetDescription const &psetDescription)
ObjME eleEtaME_
Definition: MuonMonitor.cc:80
void bookME(DQMStore::IBooker &, ObjME &me, const std::string &histname, const std::string &histtitle, const uint nbins, const double xmin, const double xmax, const bool bookDen=true)
fixed size matrix
HLT enums.
ObjME muonME_
Definition: MuonMonitor.cc:70
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: MuonMonitor.cc:342
dqm::reco::MonitorElement MonitorElement
Definition: MuonMonitor.cc:26
static constexpr int N_PHI
Definition: MuonMonitor.cc:50
~MuonMonitor() override
Definition: MuonMonitor.cc:129
const MEbinning eta_binning_
Definition: MuonMonitor.cc:59
static void fillPSetDescription(edm::ParameterSetDescription &desc)
std::vector< double > eleEta_variable_binning_2D_
Definition: MuonMonitor.cc:68
Definition: Run.h:45
Collection of PF MET.
StringCutObjectSelector< reco::Muon, true > muonSelection_
Definition: MuonMonitor.cc:88