CMS 3D CMS Logo

DiDispStaMuonMonitor.cc
Go to the documentation of this file.
2 
3 // -----------------------------
4 // constructors and destructor
5 // -----------------------------
6 
8  folderName_ ( iConfig.getParameter<std::string>("FolderName") )
9  , muonToken_ ( consumes<reco::TrackCollection> (iConfig.getParameter<edm::InputTag>("muons") ) )
10  , muonPt_variable_binning_ ( iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("muonPtBinning") )
11  , muonPt_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("muonPtPSet") ) )
12  , muonEta_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("muonEtaPSet") ) )
13  , muonPhi_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("muonPhiPSet") ) )
14  , muonDxy_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("muonDxyPSet") ) )
15  , ls_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("lsPSet") ) )
16  , num_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"),consumesCollector(), *this))
17  , den_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"),consumesCollector(), *this))
18  , muonSelectionGeneral_ ( iConfig.getParameter<edm::ParameterSet>("muonSelection").getParameter<std::string>("general") )
19  , muonSelectionPt_ ( iConfig.getParameter<edm::ParameterSet>("muonSelection").getParameter<std::string>("pt") )
20  , muonSelectionDxy_ ( iConfig.getParameter<edm::ParameterSet>("muonSelection").getParameter<std::string>("dxy") )
21  , nmuons_ ( iConfig.getParameter<unsigned int>("nmuons" ) )
22 {
23 
24  muonPtME_.numerator = nullptr;
25  muonPtME_.denominator = nullptr;
26  muonPtNoDxyCutME_.numerator = nullptr;
30  muonPtVsLS_.numerator = nullptr;
31  muonPtVsLS_.denominator = nullptr;
32  muonEtaME_.numerator = nullptr;
33  muonEtaME_.denominator = nullptr;
34  muonPhiME_.numerator = nullptr;
35  muonPhiME_.denominator = nullptr;
36  muonDxyME_.numerator = nullptr;
37  muonDxyME_.denominator = nullptr;
38 
39 
40  subMuonPtME_.numerator = nullptr;
41  subMuonPtME_.denominator = nullptr;
44  subMuonEtaME_.numerator = nullptr;
45  subMuonEtaME_.denominator = nullptr;
46  subMuonPhiME_.numerator = nullptr;
47  subMuonPhiME_.denominator = nullptr;
48  subMuonDxyME_.numerator = nullptr;
49  subMuonDxyME_.denominator = nullptr;
50 
51 
52 }
53 
55 
57 {
58  return MEbinning{
59  pset.getParameter<unsigned int>("nbins"),
60  pset.getParameter<double>("xmin"),
61  pset.getParameter<double>("xmax"),
62  };
63 }
64 
66 {
67  return MEbinning{
68  pset.getParameter<unsigned int>("nbins"),
69  0.,
70  double(pset.getParameter<unsigned int>("nbins"))
71  };
72 }
73 
74 void DiDispStaMuonMonitor::setTitle(DiDispStaMuonME& me, const std::string& titleX, const std::string& titleY, bool bookDen)
75 {
76  me.numerator->setAxisTitle(titleX,1);
77  me.numerator->setAxisTitle(titleY,2);
78  if(bookDen) {
79  me.denominator->setAxisTitle(titleX,1);
80  me.denominator->setAxisTitle(titleY,2);
81  }
82 
83 }
84 
85 void DiDispStaMuonMonitor::bookME(DQMStore::IBooker &ibooker, DiDispStaMuonME& me, const std::string& histname, const std::string& histtitle, int nbins, double min, double max)
86 {
87  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, min, max);
88  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, min, max);
89 }
90 void DiDispStaMuonMonitor::bookME(DQMStore::IBooker &ibooker, DiDispStaMuonME& me, const std::string& histname, const std::string& histtitle, const std::vector<double>& binning)
91 {
92  int nbins = binning.size()-1;
93  std::vector<float> fbinning(binning.begin(),binning.end());
94  float* arr = &fbinning[0];
95  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, arr);
96  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, arr);
97 }
98 void DiDispStaMuonMonitor::bookME(DQMStore::IBooker &ibooker, DiDispStaMuonME& me, const std::string& histname, const std::string& histtitle, int nbinsX, double xmin, double xmax, double ymin, double ymax, bool bookDen)
99 {
100  me.numerator = ibooker.bookProfile(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, ymin, ymax);
101  if(bookDen) me.denominator = ibooker.bookProfile(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, ymin, ymax);
102 }
103 void DiDispStaMuonMonitor::bookME(DQMStore::IBooker &ibooker, DiDispStaMuonME& me, const std::string& histname, const std::string& histtitle, int nbinsX, double xmin, double xmax, int nbinsY, double ymin, double ymax)
104 {
105  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
106  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
107 }
108 void DiDispStaMuonMonitor::bookME(DQMStore::IBooker &ibooker, DiDispStaMuonME& me, const std::string& histname, const std::string& histtitle, const std::vector<double>& binningX, const std::vector<double>& binningY)
109 {
110  int nbinsX = binningX.size()-1;
111  std::vector<float> fbinningX(binningX.begin(),binningX.end());
112  float* arrX = &fbinningX[0];
113  int nbinsY = binningY.size()-1;
114  std::vector<float> fbinningY(binningY.begin(),binningY.end());
115  float* arrY = &fbinningY[0];
116 
117  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, arrX, nbinsY, arrY);
118  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, arrX, nbinsY, arrY);
119 }
120 
122  edm::Run const & iRun,
123  edm::EventSetup const & iSetup)
124 {
125 
126  std::string histname, histtitle;
127  bool bookDen;
128 
129  std::string currentFolder = folderName_ ;
130  ibooker.setCurrentFolder(currentFolder);
131 
132  histname = "muonPt"; histtitle = "muonPt";
133  bookDen = true;
135  setTitle(muonPtME_,"DisplacedStandAlone Muon p_{T} [GeV]","Events / [GeV]", bookDen);
136 
137  histname = "muonPtNoDxyCut"; histtitle = "muonPtNoDxyCut";
138  bookDen = true;
140  setTitle(muonPtNoDxyCutME_,"DisplacedStandAlone Muon p_{T} [GeV] without Dxy cut","Events / [GeV]", bookDen);
141 
142  histname = "muonPt_variable"; histtitle = "muonPt";
143  bookDen = true;
144  bookME(ibooker,muonPtME_variableBinning_,histname,histtitle,muonPt_variable_binning_);
145  setTitle(muonPtME_variableBinning_,"DisplacedStandAlone Muon p_{T} [GeV]","Events / [GeV]", bookDen);
146 
147  histname = "muonPtVsLS"; histtitle = "muonPt vs LS";
148  bookDen = true;
150  setTitle(muonPtVsLS_,"LS","DisplacedStandAlone Muon p_{T} [GeV]", bookDen);
151 
152  histname = "muonEta"; histtitle = "muonEta";
153  bookDen = true;
155  setTitle(muonEtaME_,"DisplacedStandAlone Muon #eta","Events", bookDen);
156 
157  histname = "muonPhi"; histtitle = "muonPhi";
158  bookDen = true;
160  setTitle(muonPhiME_,"DisplacedStandAlone Muon #phi","Events", bookDen);
161 
162  histname = "muonDxy"; histtitle = "muonDxy";
163  bookDen = true;
165  setTitle(muonDxyME_,"DisplacedStandAlone Muon #dxy","Events", bookDen);
166 
167 
168  //-----------------------
169  // |
170  //-----------------------
171 
172  if (nmuons_>1) {
173  histname = "subMuonPt"; histtitle = "subMuonPt";
174  bookDen = true;
176  setTitle(subMuonPtME_,"Subleading DisplacedStandAlone Muon p_{T} [GeV]","Events / [GeV]", bookDen);
177 
178  histname = "subMuonPt_variable"; histtitle = "subMuonPt";
179  bookDen = true;
181  setTitle(subMuonPtME_variableBinning_,"Subleading DisplacedStandAlone Muon p_{T} [GeV]","Events / [GeV]", bookDen);
182 
183  histname = "subMuonEta"; histtitle = "subMuonEta";
184  bookDen = true;
186  setTitle(subMuonEtaME_,"Subleading DisplacedStandAlone Muon #eta","Events", bookDen);
187 
188  histname = "subMuonPhi"; histtitle = "subMuonPhi";
189  bookDen = true;
191  setTitle(subMuonPhiME_,"Subleading DisplacedStandAlone Muon #phi","Events", bookDen);
192 
193  histname = "subMuonDxy"; histtitle = "subMuonDxy";
194  bookDen = true;
196  setTitle(subMuonDxyME_,"Subleading DisplacedStandAlone Muon #dxy","Events", bookDen);
197 
198  }
199 
200 
201  // Initialize the GenericTriggerEventFlag
202  if ( num_genTriggerEventFlag_ && num_genTriggerEventFlag_->on() ) num_genTriggerEventFlag_->initRun( iRun, iSetup );
203  if ( den_genTriggerEventFlag_ && den_genTriggerEventFlag_->on() ) den_genTriggerEventFlag_->initRun( iRun, iSetup );
204 
205 }
206 
208 
209  // Filter out events if Trigger Filtering is requested
210  if (den_genTriggerEventFlag_->on() && ! den_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
211 
212  int ls = iEvent.id().luminosityBlock();
213 
215  iEvent.getByToken( muonToken_, DSAHandle );
216  if ((unsigned int)(DSAHandle->size()) < nmuons_ ) return;
217  std::vector<edm::Ptr<reco::Track>> dsaMuonPtrs_{};// = DSAHandle->ptrs();
218  for (size_t i(0); i!=DSAHandle->size(); ++i) {
219  dsaMuonPtrs_.emplace_back(DSAHandle, i);
220  }
221  std::vector<edm::Ptr<reco::Track>> muons{}, muonsCutOnPt{}, muonsCutOnDxy{}, muonsCutOnPtAndDxy{};
222 
223  // general selection
224  auto selectGeneral_([this](edm::Ptr<reco::Track> const& m)->bool {return muonSelectionGeneral_(*m);});
225  std::copy_if(dsaMuonPtrs_.begin(), dsaMuonPtrs_.end(), back_inserter(muons), selectGeneral_);
226  if ((unsigned int)(muons.size()) < nmuons_ ) return;
227 
228  // sort by pt
229  auto ptSorter_ = [](edm::Ptr<reco::Track> const& lhs, edm::Ptr<reco::Track> const& rhs)->bool {return lhs->pt() > rhs->pt();};
230  std::sort(muons.begin(), muons.end(), ptSorter_);
231 
232  // cut on pt
233  auto selectOnPt_([this](edm::Ptr<reco::Track> const& m)->bool {return muonSelectionPt_(*m);});
234  std::copy_if(muons.begin(), muons.end(), back_inserter(muonsCutOnPt), selectOnPt_);
235  // cut on dxy
236  auto selectOnDxy_([this](edm::Ptr<reco::Track> const& m)->bool {return muonSelectionDxy_(*m);});
237  std::copy_if(muons.begin(), muons.end(), back_inserter(muonsCutOnDxy), selectOnDxy_);
238  // cut on pt and dxy
239  auto selectOnPtAndDxy_([this](edm::Ptr<reco::Track> const& m)->bool {return muonSelectionPt_(*m) && muonSelectionDxy_(*m);});
240  std::copy_if(muons.begin(), muons.end(), back_inserter(muonsCutOnPtAndDxy), selectOnPtAndDxy_);
241 
242  std::sort(muonsCutOnPt.begin(), muonsCutOnPt.end(), ptSorter_);
243  std::sort(muonsCutOnDxy.begin(), muonsCutOnDxy.end(), ptSorter_);
244  std::sort(muonsCutOnPtAndDxy.begin(), muonsCutOnPtAndDxy.end(), ptSorter_);
245 
246  // --------------------------------
247  // filling histograms (denominator)
248  // --------------------------------
249  if(muonsCutOnDxy.size() >= nmuons_) {
250  // pt has cut on dxy
251  muonPtME_.denominator->Fill( muonsCutOnDxy[0]->pt() );
253  muonPtME_variableBinning_.denominator->Fill( muonsCutOnDxy[0]->pt() );
254  muonPtVsLS_.denominator->Fill( ls, muonsCutOnDxy[0]->pt() );
255  if(nmuons_ > 1) {
256  subMuonPtME_.denominator->Fill( muonsCutOnDxy[1]->pt() );
257  subMuonPtME_variableBinning_.denominator->Fill( muonsCutOnDxy[1]->pt() );
258  }
259  }
260  if(muonsCutOnPtAndDxy.size() >= nmuons_) {
261  // eta, phi have cut on pt and dxy
262  muonEtaME_.denominator->Fill( muonsCutOnPtAndDxy[0]->eta() );
263  muonPhiME_.denominator->Fill( muonsCutOnPtAndDxy[0]->phi() );
264  if(nmuons_ > 1) {
265  subMuonEtaME_.denominator->Fill( muonsCutOnPtAndDxy[1]->eta() );
266  subMuonPhiME_.denominator->Fill( muonsCutOnPtAndDxy[1]->phi() );
267  }
268  }
269  if(muonsCutOnPt.size() >= nmuons_){
270  // dxy has cut on pt
271  muonDxyME_.denominator->Fill( muonsCutOnPt[0]->dxy() );
272  if (nmuons_ > 1) {
273  subMuonDxyME_.denominator->Fill( muonsCutOnPt[1]->dxy() );
274  }
275  }
276 
277 
278  // --------------------------------
279  // filling histograms (numerator)
280  // --------------------------------
281  if (num_genTriggerEventFlag_->on() && ! num_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
282 
283  if(muonsCutOnDxy.size() >= nmuons_) {
284  // pt has cut on dxy
285  muonPtME_.numerator->Fill( muonsCutOnDxy[0]->pt() );
287  muonPtME_variableBinning_.numerator->Fill( muonsCutOnDxy[0]->pt() );
288  muonPtVsLS_.numerator->Fill( ls, muonsCutOnDxy[0]->pt() );
289  if(nmuons_ > 1) {
290  subMuonPtME_.numerator->Fill( muonsCutOnDxy[1]->pt() );
291  subMuonPtME_variableBinning_.numerator->Fill( muonsCutOnDxy[1]->pt() );
292  }
293  }
294  if(muonsCutOnPtAndDxy.size() >= nmuons_) {
295  // eta, phi have cut on pt and dxy
296  muonEtaME_.numerator->Fill( muonsCutOnPtAndDxy[0]->eta() );
297  muonPhiME_.numerator->Fill( muonsCutOnPtAndDxy[0]->phi() );
298  if(nmuons_ > 1) {
299  subMuonEtaME_.numerator->Fill( muonsCutOnPtAndDxy[1]->eta() );
300  subMuonPhiME_.numerator->Fill( muonsCutOnPtAndDxy[1]->phi() );
301  }
302  }
303  if(muonsCutOnPt.size() >= nmuons_){
304  // dxy has cut on pt
305  muonDxyME_.numerator->Fill( muonsCutOnPt[0]->dxy() );
306  if (nmuons_ > 1) {
307  subMuonDxyME_.numerator->Fill( muonsCutOnPt[1]->dxy() );
308  }
309  }
310 
311 
312 }
313 
315 {
316  pset.add<unsigned int> ( "nbins", 200);
317  pset.add<double>( "xmin", -0.5 );
318  pset.add<double>( "xmax", 19999.5 );
319 }
320 
322 {
323  pset.add<unsigned int> ( "nbins", 2000);
324 }
325 
327 {
329  desc.add<std::string> ( "FolderName", "HLT/EXO/DiDispStaMuon" );
330 
331  desc.add<edm::InputTag>( "muons", edm::InputTag("displacedStandAloneMuons") );
332  desc.add<unsigned int>("nmuons", 2);
333 
335  muonSelection.add<std::string>("general", "pt > 0");
336  muonSelection.add<std::string>("pt", "");
337  muonSelection.add<std::string>("dxy", "pt > 0");
338  desc.add<edm::ParameterSetDescription>("muonSelection", muonSelection);
339 
340  edm::ParameterSetDescription genericTriggerEventPSet;
341  genericTriggerEventPSet.add<bool>("andOr");
342  genericTriggerEventPSet.add<edm::InputTag>("dcsInputTag", edm::InputTag("scalersRawToDigi") );
343  genericTriggerEventPSet.add<std::vector<int> >("dcsPartitions",{});
344  genericTriggerEventPSet.add<bool>("andOrDcs", false);
345  genericTriggerEventPSet.add<bool>("errorReplyDcs", true);
346  genericTriggerEventPSet.add<std::string>("dbLabel","");
347  genericTriggerEventPSet.add<bool>("andOrHlt", true);
348  genericTriggerEventPSet.add<edm::InputTag>("hltInputTag", edm::InputTag("TriggerResults::HLT") );
349  genericTriggerEventPSet.add<std::vector<std::string> >("hltPaths",{});
350  genericTriggerEventPSet.add<std::string>("hltDBKey","");
351  genericTriggerEventPSet.add<bool>("errorReplyHlt",false);
352  genericTriggerEventPSet.add<unsigned int>("verbosityLevel",1);
353 
354  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
355  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
356 
358  edm::ParameterSetDescription muonPtPSet;
359  edm::ParameterSetDescription muonEtaPSet;
360  edm::ParameterSetDescription muonPhiPSet;
361  edm::ParameterSetDescription muonDxyPSet;
363  fillHistoPSetDescription(muonPtPSet);
364  fillHistoPSetDescription(muonEtaPSet);
365  fillHistoPSetDescription(muonPhiPSet);
366  fillHistoPSetDescription(muonDxyPSet);
367  fillHistoPSetDescription(lsPSet);
368  histoPSet.add<edm::ParameterSetDescription>("muonPtPSet", muonPtPSet);
369  histoPSet.add<edm::ParameterSetDescription>("muonEtaPSet", muonEtaPSet);
370  histoPSet.add<edm::ParameterSetDescription>("muonPhiPSet", muonPhiPSet);
371  histoPSet.add<edm::ParameterSetDescription>("muonDxyPSet", muonDxyPSet);
372  histoPSet.add<edm::ParameterSetDescription>("lsPSet", lsPSet);
373  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.};
374  histoPSet.add<std::vector<double> >("muonPtBinning", bins);
375 
376  desc.add<edm::ParameterSetDescription>("histoPSet",histoPSet);
377 
378  descriptions.add("DiDispStaMuonMonitoring", desc);
379 }
380 
381 // Define this as a plug-in
DiDispStaMuonME subMuonPtME_
T getParameter(std::string const &) const
~DiDispStaMuonMonitor() override
void setTitle(DiDispStaMuonME &me, const std::string &titleX, const std::string &titleY, bool bookDen)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
DiDispStaMuonME subMuonEtaME_
std::vector< double > muonPt_variable_binning_
static MEbinning getHistoPSet(const edm::ParameterSet &pset)
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:113
DiDispStaMuonME muonPtNoDxyCutME_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
static MEbinning getHistoLSPSet(const edm::ParameterSet &pset)
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
DiDispStaMuonME muonPhiME_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
void Fill(long long x)
StringCutObjectSelector< reco::Track, true > muonSelectionGeneral_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
DiDispStaMuonME subMuonDxyME_
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
double pt() const
track transverse momentum
Definition: TrackBase.h:654
void bookME(DQMStore::IBooker &, DiDispStaMuonME &me, const std::string &histname, const std::string &histtitle, int nbins, double xmin, double xmax)
DiDispStaMuonMonitor(const edm::ParameterSet &)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
T min(T a, T b)
Definition: MathUtil.h:58
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
StringCutObjectSelector< reco::Track, true > muonSelectionPt_
def ls(path, rec=False)
Definition: eostools.py:349
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:109
DiDispStaMuonME muonEtaME_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
DiDispStaMuonME muonPtVsLS_
edm::EventID id() const
Definition: EventBase.h:59
fixed size matrix
HLT enums.
DiDispStaMuonME subMuonPtME_variableBinning_
edm::EDGetTokenT< reco::TrackCollection > muonToken_
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
DiDispStaMuonME muonDxyME_
DiDispStaMuonME subMuonPhiME_
StringCutObjectSelector< reco::Track, true > muonSelectionDxy_
Definition: Run.h:45
DiDispStaMuonME muonPtME_variableBinning_