CMS 3D CMS Logo

DiDispStaMuonMonitor.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 
12 
15 
17 public:
20 
22  ~DiDispStaMuonMonitor() throw() override;
23  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
24 
25 protected:
27  void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
28 
29 private:
31 
34 
36 
43 
56 
59 
63 
64  unsigned int nmuons_;
65 };
66 
68  : folderName_(iConfig.getParameter<std::string>("FolderName")),
69  requireValidHLTPaths_(iConfig.getParameter<bool>("requireValidHLTPaths")),
71  muonToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("muons"))),
73  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double>>("muonPtBinning")),
75  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("muonPtPSet"))),
77  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("muonEtaPSet"))),
79  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("muonPhiPSet"))),
81  iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("muonDxyPSet"))),
83  getHistoPSet(iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet>("lsPSet"))),
85  iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"), consumesCollector(), *this)),
87  iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"), consumesCollector(), *this)),
89  iConfig.getParameter<edm::ParameterSet>("muonSelection").getParameter<std::string>("general")),
90  muonSelectionPt_(iConfig.getParameter<edm::ParameterSet>("muonSelection").getParameter<std::string>("pt")),
91  muonSelectionDxy_(iConfig.getParameter<edm::ParameterSet>("muonSelection").getParameter<std::string>("dxy")),
92  nmuons_(iConfig.getParameter<unsigned int>("nmuons")) {}
93 
97  }
100  }
101 }
102 
104  edm::Run const& iRun,
105  edm::EventSetup const& iSetup) {
106  // Initialize the GenericTriggerEventFlag
108  num_genTriggerEventFlag_->initRun(iRun, iSetup);
109  }
111  den_genTriggerEventFlag_->initRun(iRun, iSetup);
112  }
113 
114  // check if every HLT path specified in numerator and denominator has a valid match in the HLT Menu
116  den_genTriggerEventFlag_->on() && num_genTriggerEventFlag_->allHLTPathsAreValid() &&
117  den_genTriggerEventFlag_->allHLTPathsAreValid());
118 
119  // if valid HLT paths are required,
120  // create DQM outputs only if all paths are valid
122  return;
123  }
124 
125  std::string histname, histtitle;
126 
127  std::string currentFolder = folderName_;
128  ibooker.setCurrentFolder(currentFolder);
129 
130  histname = "muonPt";
131  histtitle = "muonPt";
132 
133  bookME(ibooker, muonPtME_, histname, histtitle, muonPt_binning_.nbins, muonPt_binning_.xmin, muonPt_binning_.xmax);
134  setMETitle(muonPtME_, "DisplacedStandAlone Muon p_{T} [GeV]", "Events / [GeV]");
135 
136  histname = "muonPtNoDxyCut";
137  histtitle = "muonPtNoDxyCut";
138  bookME(ibooker,
140  histname,
141  histtitle,
145  setMETitle(muonPtNoDxyCutME_, "DisplacedStandAlone Muon p_{T} [GeV] without Dxy cut", "Events / [GeV]");
146 
147  histname = "muonPt_variable";
148  histtitle = "muonPt";
149  bookME(ibooker, muonPtME_variableBinning_, histname, histtitle, muonPt_variable_binning_);
150  setMETitle(muonPtME_variableBinning_, "DisplacedStandAlone Muon p_{T} [GeV]", "Events / [GeV]");
151 
152  histname = "muonPtVsLS";
153  histtitle = "muonPt vs LS";
154  bookME(ibooker,
155  muonPtVsLS_,
156  histname,
157  histtitle,
163  setMETitle(muonPtVsLS_, "LS", "DisplacedStandAlone Muon p_{T} [GeV]");
164 
165  histname = "muonEta";
166  histtitle = "muonEta";
167  bookME(
168  ibooker, muonEtaME_, histname, histtitle, muonEta_binning_.nbins, muonEta_binning_.xmin, muonEta_binning_.xmax);
169  setMETitle(muonEtaME_, "DisplacedStandAlone Muon #eta", "Events");
170 
171  histname = "muonPhi";
172  histtitle = "muonPhi";
173  bookME(
174  ibooker, muonPhiME_, histname, histtitle, muonPhi_binning_.nbins, muonPhi_binning_.xmin, muonPhi_binning_.xmax);
175  setMETitle(muonPhiME_, "DisplacedStandAlone Muon #phi", "Events");
176 
177  histname = "muonDxy";
178  histtitle = "muonDxy";
179  bookME(
180  ibooker, muonDxyME_, histname, histtitle, muonDxy_binning_.nbins, muonDxy_binning_.xmin, muonDxy_binning_.xmax);
181  setMETitle(muonDxyME_, "DisplacedStandAlone Muon #dxy", "Events");
182 
183  if (nmuons_ > 1) {
184  histname = "subMuonPt";
185  histtitle = "subMuonPt";
186  bookME(
187  ibooker, subMuonPtME_, histname, histtitle, muonPt_binning_.nbins, muonPt_binning_.xmin, muonPt_binning_.xmax);
188  setMETitle(subMuonPtME_, "Subleading DisplacedStandAlone Muon p_{T} [GeV]", "Events / [GeV]");
189 
190  histname = "subMuonPt_variable";
191  histtitle = "subMuonPt";
192  bookME(ibooker, subMuonPtME_variableBinning_, histname, histtitle, muonPt_variable_binning_);
193  setMETitle(subMuonPtME_variableBinning_, "Subleading DisplacedStandAlone Muon p_{T} [GeV]", "Events / [GeV]");
194 
195  histname = "subMuonEta";
196  histtitle = "subMuonEta";
197  bookME(ibooker,
199  histname,
200  histtitle,
204  setMETitle(subMuonEtaME_, "Subleading DisplacedStandAlone Muon #eta", "Events");
205 
206  histname = "subMuonPhi";
207  histtitle = "subMuonPhi";
208  bookME(ibooker,
210  histname,
211  histtitle,
215  setMETitle(subMuonPhiME_, "Subleading DisplacedStandAlone Muon #phi", "Events");
216 
217  histname = "subMuonDxy";
218  histtitle = "subMuonDxy";
219  bookME(ibooker,
221  histname,
222  histtitle,
226  setMETitle(subMuonDxyME_, "Subleading DisplacedStandAlone Muon #dxy", "Events");
227  }
228 }
229 
231  // if valid HLT paths are required,
232  // analyze event only if all paths are valid
234  return;
235  }
236 
237  // Filter out events if Trigger Filtering is requested
238  if (den_genTriggerEventFlag_->on() && !den_genTriggerEventFlag_->accept(iEvent, iSetup))
239  return;
240 
241  const int ls = iEvent.id().luminosityBlock();
242 
244  iEvent.getByToken(muonToken_, DSAHandle);
245  if ((unsigned int)(DSAHandle->size()) < nmuons_)
246  return;
247  std::vector<edm::Ptr<reco::Track>> dsaMuonPtrs_{}; // = DSAHandle->ptrs();
248  for (size_t i(0); i != DSAHandle->size(); ++i) {
249  dsaMuonPtrs_.emplace_back(DSAHandle, i);
250  }
251  std::vector<edm::Ptr<reco::Track>> muons{}, muonsCutOnPt{}, muonsCutOnDxy{}, muonsCutOnPtAndDxy{};
252 
253  // general selection
254  auto selectGeneral_([this](edm::Ptr<reco::Track> const& m) -> bool { return muonSelectionGeneral_(*m); });
255  std::copy_if(dsaMuonPtrs_.begin(), dsaMuonPtrs_.end(), back_inserter(muons), selectGeneral_);
256  if ((unsigned int)(muons.size()) < nmuons_)
257  return;
258 
259  // sort by pt
260  auto ptSorter_ = [](edm::Ptr<reco::Track> const& lhs, edm::Ptr<reco::Track> const& rhs) -> bool {
261  return lhs->pt() > rhs->pt();
262  };
263  std::sort(muons.begin(), muons.end(), ptSorter_);
264 
265  // cut on pt
266  auto selectOnPt_([this](edm::Ptr<reco::Track> const& m) -> bool { return muonSelectionPt_(*m); });
267  std::copy_if(muons.begin(), muons.end(), back_inserter(muonsCutOnPt), selectOnPt_);
268  // cut on dxy
269  auto selectOnDxy_([this](edm::Ptr<reco::Track> const& m) -> bool { return muonSelectionDxy_(*m); });
270  std::copy_if(muons.begin(), muons.end(), back_inserter(muonsCutOnDxy), selectOnDxy_);
271  // cut on pt and dxy
272  auto selectOnPtAndDxy_(
273  [this](edm::Ptr<reco::Track> const& m) -> bool { return muonSelectionPt_(*m) && muonSelectionDxy_(*m); });
274  std::copy_if(muons.begin(), muons.end(), back_inserter(muonsCutOnPtAndDxy), selectOnPtAndDxy_);
275 
276  std::sort(muonsCutOnPt.begin(), muonsCutOnPt.end(), ptSorter_);
277  std::sort(muonsCutOnDxy.begin(), muonsCutOnDxy.end(), ptSorter_);
278  std::sort(muonsCutOnPtAndDxy.begin(), muonsCutOnPtAndDxy.end(), ptSorter_);
279 
280  // --------------------------------
281  // filling histograms (denominator)
282  // --------------------------------
283  if (muonsCutOnDxy.size() >= nmuons_) {
284  // pt has cut on dxy
285  muonPtME_.denominator->Fill(muonsCutOnDxy[0]->pt());
287  muonPtME_variableBinning_.denominator->Fill(muonsCutOnDxy[0]->pt());
288  muonPtVsLS_.denominator->Fill(ls, muonsCutOnDxy[0]->pt());
289  if (nmuons_ > 1) {
290  subMuonPtME_.denominator->Fill(muonsCutOnDxy[1]->pt());
291  subMuonPtME_variableBinning_.denominator->Fill(muonsCutOnDxy[1]->pt());
292  }
293  }
294  if (muonsCutOnPtAndDxy.size() >= nmuons_) {
295  // eta, phi have cut on pt and dxy
296  muonEtaME_.denominator->Fill(muonsCutOnPtAndDxy[0]->eta());
297  muonPhiME_.denominator->Fill(muonsCutOnPtAndDxy[0]->phi());
298  if (nmuons_ > 1) {
299  subMuonEtaME_.denominator->Fill(muonsCutOnPtAndDxy[1]->eta());
300  subMuonPhiME_.denominator->Fill(muonsCutOnPtAndDxy[1]->phi());
301  }
302  }
303  if (muonsCutOnPt.size() >= nmuons_) {
304  // dxy has cut on pt
305  muonDxyME_.denominator->Fill(muonsCutOnPt[0]->dxy());
306  if (nmuons_ > 1) {
307  subMuonDxyME_.denominator->Fill(muonsCutOnPt[1]->dxy());
308  }
309  }
310 
311  // --------------------------------
312  // filling histograms (numerator)
313  // --------------------------------
314  if (num_genTriggerEventFlag_->on() && !num_genTriggerEventFlag_->accept(iEvent, iSetup))
315  return;
316 
317  if (muonsCutOnDxy.size() >= nmuons_) {
318  // pt has cut on dxy
319  muonPtME_.numerator->Fill(muonsCutOnDxy[0]->pt());
321  muonPtME_variableBinning_.numerator->Fill(muonsCutOnDxy[0]->pt());
322  muonPtVsLS_.numerator->Fill(ls, muonsCutOnDxy[0]->pt());
323  if (nmuons_ > 1) {
324  subMuonPtME_.numerator->Fill(muonsCutOnDxy[1]->pt());
325  subMuonPtME_variableBinning_.numerator->Fill(muonsCutOnDxy[1]->pt());
326  }
327  }
328  if (muonsCutOnPtAndDxy.size() >= nmuons_) {
329  // eta, phi have cut on pt and dxy
330  muonEtaME_.numerator->Fill(muonsCutOnPtAndDxy[0]->eta());
331  muonPhiME_.numerator->Fill(muonsCutOnPtAndDxy[0]->phi());
332  if (nmuons_ > 1) {
333  subMuonEtaME_.numerator->Fill(muonsCutOnPtAndDxy[1]->eta());
334  subMuonPhiME_.numerator->Fill(muonsCutOnPtAndDxy[1]->phi());
335  }
336  }
337  if (muonsCutOnPt.size() >= nmuons_) {
338  // dxy has cut on pt
339  muonDxyME_.numerator->Fill(muonsCutOnPt[0]->dxy());
340  if (nmuons_ > 1) {
341  subMuonDxyME_.numerator->Fill(muonsCutOnPt[1]->dxy());
342  }
343  }
344 }
345 
348  desc.add<std::string>("FolderName", "HLT/EXO/DiDispStaMuon");
349  desc.add<bool>("requireValidHLTPaths", true);
350 
351  desc.add<edm::InputTag>("muons", edm::InputTag("displacedStandAloneMuons"));
352  desc.add<unsigned int>("nmuons", 2);
353 
355  muonSelection.add<std::string>("general", "pt > 0");
356  muonSelection.add<std::string>("pt", "");
357  muonSelection.add<std::string>("dxy", "pt > 0");
358  desc.add<edm::ParameterSetDescription>("muonSelection", muonSelection);
359 
362  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
363  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
364 
381  std::vector<double> bins = {0., 20., 40., 60., 80., 90., 100., 110., 120., 130., 140., 150., 160.,
382  170., 180., 190., 200., 220., 240., 260., 280., 300., 350., 400., 450., 1000.};
383  histoPSet.add<std::vector<double>>("muonPtBinning", bins);
384 
385  desc.add<edm::ParameterSetDescription>("histoPSet", histoPSet);
386 
387  descriptions.add("DiDispStaMuonMonitoring", desc);
388 }
389 
muonSelection
MU SELECTION #########################.
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::vector< double > muonPt_variable_binning_
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
const std::string folderName_
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
void setMETitle(ObjME &me, const std::string &titleX, const std::string &titleY)
dqm::reco::MonitorElement MonitorElement
void Fill(long long x)
double pt() const
track transverse momentum
Definition: TrackBase.h:637
static MEbinning getHistoPSet(const edm::ParameterSet &pset)
int iEvent
Definition: GenABIO.cc:224
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
StringCutObjectSelector< reco::Track, true > muonSelectionDxy_
StringCutObjectSelector< reco::Track, true > muonSelectionGeneral_
MonitorElement * denominator
DiDispStaMuonMonitor(const edm::ParameterSet &)
MonitorElement * numerator
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
def ls(path, rec=False)
Definition: eostools.py:349
dqm::reco::DQMStore DQMStore
void add(std::string const &label, ParameterSetDescription const &psetDescription)
StringCutObjectSelector< reco::Track, true > muonSelectionPt_
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)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
fixed size matrix
HLT enums.
edm::EDGetTokenT< reco::TrackCollection > muonToken_
static void fillPSetDescription(edm::ParameterSetDescription &desc)
Definition: Run.h:45