CMS 3D CMS Logo

HTMonitor.cc
Go to the documentation of this file.
2 
4 
6 
7 // -----------------------------
8 // constructors and destructor
9 // -----------------------------
10 
12  folderName_ ( iConfig.getParameter<std::string>("FolderName") )
13  , metToken_ ( consumes<reco::PFMETCollection> (iConfig.getParameter<edm::InputTag>("met") ) )
14  , jetToken_ ( mayConsume<reco::PFJetCollection> (iConfig.getParameter<edm::InputTag>("jets") ) )
15  , eleToken_ ( mayConsume<reco::GsfElectronCollection>(iConfig.getParameter<edm::InputTag>("electrons") ) )
16  , muoToken_ ( mayConsume<reco::MuonCollection> (iConfig.getParameter<edm::InputTag>("muons") ) )
17  , vtxToken_ ( mayConsume<reco::VertexCollection> (iConfig.getParameter<edm::InputTag>("vertices") ) )
18  , ht_variable_binning_ ( iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<std::vector<double> >("htBinning") )
19  , ht_binning_ ( getHistoPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("htPSet") ) )
20  , ls_binning_ ( getHistoLSPSet (iConfig.getParameter<edm::ParameterSet>("histoPSet").getParameter<edm::ParameterSet> ("lsPSet") ) )
21  , num_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("numGenericTriggerEventPSet"),consumesCollector(), *this))
22  , den_genTriggerEventFlag_(new GenericTriggerEventFlag(iConfig.getParameter<edm::ParameterSet>("denGenericTriggerEventPSet"),consumesCollector(), *this))
23  , metSelection_ ( iConfig.getParameter<std::string>("metSelection") )
24  , jetSelection_ ( iConfig.getParameter<std::string>("jetSelection") )
25  , eleSelection_ ( iConfig.getParameter<std::string>("eleSelection") )
26  , muoSelection_ ( iConfig.getParameter<std::string>("muoSelection") )
27  , jetSelection_HT_ ( iConfig.getParameter<std::string>("jetSelection_HT") )
28  , njets_ ( iConfig.getParameter<unsigned>("njets" ) )
29  , nelectrons_ ( iConfig.getParameter<unsigned>("nelectrons" ) )
30  , nmuons_ ( iConfig.getParameter<unsigned>("nmuons" ) )
31 {
32 }
33 
34 HTMonitor::~HTMonitor() = default;
35 
37 {
39  pset.getParameter<unsigned>("nbins"),
40  pset.getParameter<double>("xmin"),
41  pset.getParameter<double>("xmax"),
42  };
43 }
44 
46 {
48  pset.getParameter<unsigned>("nbins"),
49  0.,
50  double(pset.getParameter<unsigned>("nbins"))
51  };
52 }
53 
54 void HTMonitor::setHTitle(HTME& me, const std::string& titleX, const std::string& titleY)
55 {
56  me.numerator->setAxisTitle(titleX,1);
57  me.numerator->setAxisTitle(titleY,2);
58  me.denominator->setAxisTitle(titleX,1);
59  me.denominator->setAxisTitle(titleY,2);
60 
61 }
62 
63 void HTMonitor::bookME(DQMStore::IBooker &ibooker, HTME& me, const std::string& histname, const std::string& histtitle, int nbins, double min, double max)
64 {
65  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, min, max);
66  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, min, max);
67 }
68 void HTMonitor::bookME(DQMStore::IBooker &ibooker, HTME& me, const std::string& histname, const std::string& histtitle, const std::vector<double>& binning)
69 {
70  int nbins = binning.size()-1;
71  std::vector<float> fbinning(binning.begin(),binning.end());
72  float* arr = &fbinning[0];
73  me.numerator = ibooker.book1D(histname+"_numerator", histtitle+" (numerator)", nbins, arr);
74  me.denominator = ibooker.book1D(histname+"_denominator", histtitle+" (denominator)", nbins, arr);
75 }
76 void HTMonitor::bookME(DQMStore::IBooker &ibooker, HTME& me, const std::string& histname, const std::string& histtitle, int nbinsX, double xmin, double xmax, double ymin, double ymax)
77 {
78  me.numerator = ibooker.bookProfile(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, ymin, ymax);
79  me.denominator = ibooker.bookProfile(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, ymin, ymax);
80 }
81 void HTMonitor::bookME(DQMStore::IBooker &ibooker, HTME& me, const std::string& histname, const std::string& histtitle, int nbinsX, double xmin, double xmax, int nbinsY, double ymin, double ymax)
82 {
83  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
84  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, xmin, xmax, nbinsY, ymin, ymax);
85 }
86 void HTMonitor::bookME(DQMStore::IBooker &ibooker, HTME& me, const std::string& histname, const std::string& histtitle, const std::vector<double>& binningX, const std::vector<double>& binningY)
87 {
88  int nbinsX = binningX.size()-1;
89  std::vector<float> fbinningX(binningX.begin(),binningX.end());
90  float* arrX = &fbinningX[0];
91  int nbinsY = binningY.size()-1;
92  std::vector<float> fbinningY(binningY.begin(),binningY.end());
93  float* arrY = &fbinningY[0];
94 
95  me.numerator = ibooker.book2D(histname+"_numerator", histtitle+" (numerator)", nbinsX, arrX, nbinsY, arrY);
96  me.denominator = ibooker.book2D(histname+"_denominator", histtitle+" (denominator)", nbinsX, arrX, nbinsY, arrY);
97 }
98 
100  edm::Run const & iRun,
101  edm::EventSetup const & iSetup)
102 {
103 
104  std::string histname, histtitle;
105 
106  std::string currentFolder = folderName_ ;
107  ibooker.setCurrentFolder(currentFolder.c_str());
108 
109  histname = "ht_variable"; histtitle = "HT";
110  bookME(ibooker,htME_variableBinning_,histname,histtitle,ht_variable_binning_);
111  setHTitle(htME_variableBinning_,"HT [GeV]","events / [GeV]");
112 
113  histname = "htVsLS"; histtitle = "HT vs LS";
115  setHTitle(htVsLS_,"LS","HT [GeV]");
116 
117  histname = "deltaphi_metjet1"; histtitle = "DPHI_METJ1";
119  setHTitle(deltaphimetj1ME_,"delta phi (met, j1)","events / 0.1 rad");
120 
121  histname = "deltaphi_jet1jet2"; histtitle = "DPHI_J1J2";
123  setHTitle(deltaphij1j2ME_,"delta phi (j1, j2)","events / 0.1 rad");
124 
125  // Initialize the GenericTriggerEventFlag
126  if ( num_genTriggerEventFlag_ && num_genTriggerEventFlag_->on() ) num_genTriggerEventFlag_->initRun( iRun, iSetup );
127  if ( den_genTriggerEventFlag_ && den_genTriggerEventFlag_->on() ) den_genTriggerEventFlag_->initRun( iRun, iSetup );
128 
129 }
130 
136 
137  // Filter out events if Trigger Filtering is requested
138  if (den_genTriggerEventFlag_->on() && ! den_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
139 
141  iEvent.getByToken( metToken_, metHandle );
142  reco::PFMET pfmet = metHandle->front();
143  if ( ! metSelection_( pfmet ) ) return;
144 
145  float ht = 0.0;
146 
147  edm::Handle<reco::PFJetCollection> jetHandle; //add a configurable jet collection & jet pt selection
148  iEvent.getByToken( jetToken_, jetHandle );
149  std::vector<reco::PFJet> jets;
150  if ( jetHandle->size() < njets_ ) return;
151  for ( auto const & j : *jetHandle ) {
152  if ( jetSelection_( j ) ) {
153  jets.push_back(j);
154  }
155  }
156  for ( auto const & j : *jetHandle ) {
157  if ( jetSelection_HT_(j)) ht += j.pt();
158  }
159  if ( jets.size() < njets_ ) return;
160 
161  float deltaPhi_met_j1 = 10.0;
162  float deltaPhi_j1_j2 = 10.0;
163 
164  if (jets.size() >= 1) deltaPhi_met_j1 = fabs( deltaPhi( pfmet.phi(), jets[0].phi() ));
165  if (jets.size() >= 2) deltaPhi_j1_j2 = fabs( deltaPhi( jets[0].phi(), jets[1].phi() ));
166 
168  iEvent.getByToken( eleToken_, eleHandle );
169  std::vector<reco::GsfElectron> electrons;
170  if ( eleHandle->size() < nelectrons_ ) return;
171  for ( auto const & e : *eleHandle ) {
172  if ( eleSelection_( e ) ) electrons.push_back(e);
173  }
174  if ( electrons.size() < nelectrons_ ) return;
175 
177  iEvent.getByToken(vtxToken_, vtxHandle);
178 
180  for (auto const & v : *vtxHandle) {
181  bool isFake = v.isFake() ;
182 
183  if (!isFake) {
184  vtx = v;
185  break;
186  }
187  }
188 
190  iEvent.getByToken( muoToken_, muoHandle );
191  if ( muoHandle->size() < nmuons_ ) return;
192  std::vector<reco::Muon> muons;
193  for ( auto const & m : *muoHandle ) {
194  if ( muoSelection_( m ) && 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 ) muons.push_back(m);
195  }
196  if ( muons.size() < nmuons_ ) return;
197 
198  // filling histograms (denominator)
200  deltaphimetj1ME_.denominator -> Fill(deltaPhi_met_j1);
201  deltaphij1j2ME_.denominator -> Fill(deltaPhi_j1_j2);
202 
203  int ls = iEvent.id().luminosityBlock();
204  htVsLS_.denominator -> Fill(ls, ht);
205 
206  // applying selection for numerator
207  if (num_genTriggerEventFlag_->on() && ! num_genTriggerEventFlag_->accept( iEvent, iSetup) ) return;
208 
209  // filling histograms (num_genTriggerEventFlag_)
211  htVsLS_.numerator -> Fill(ls, ht);
212  deltaphimetj1ME_.numerator -> Fill(deltaPhi_met_j1);
213  deltaphij1j2ME_.numerator -> Fill(deltaPhi_j1_j2);
214 
215 }
216 
218 {
219  pset.add<unsigned> ( "nbins");
220  pset.add<double>( "xmin" );
221  pset.add<double>( "xmax" );
222 }
223 
225 {
226  pset.add<unsigned> ( "nbins", 2500);
227 }
228 
230 {
232  desc.add<std::string> ( "FolderName", "HLT/HT" );
233 
234  desc.add<edm::InputTag>( "met", edm::InputTag("pfMet") );
235  desc.add<edm::InputTag>( "jets", edm::InputTag("ak4PFJetsCHS") );
236  desc.add<edm::InputTag>( "electrons",edm::InputTag("gedGsfElectrons") );
237  desc.add<edm::InputTag>( "muons", edm::InputTag("muons") );
238  desc.add<edm::InputTag>( "vertices",edm::InputTag("offlinePrimaryVertices") );
239  desc.add<std::string>("metSelection", "pt > 0");
240  desc.add<std::string>("jetSelection", "pt > 0");
241  desc.add<std::string>("eleSelection", "pt > 0");
242  desc.add<std::string>("muoSelection", "pt > 0");
243  desc.add<std::string>("jetSelection_HT", "pt > 30 && eta < 2.5");
244  desc.add<unsigned>("njets", 0);
245  desc.add<unsigned>("nelectrons", 0);
246  desc.add<unsigned>("nmuons", 0);
247 
248  edm::ParameterSetDescription genericTriggerEventPSet;
249  genericTriggerEventPSet.add<bool>("andOr");
250  genericTriggerEventPSet.add<edm::InputTag>("dcsInputTag", edm::InputTag("scalersRawToDigi") );
251  genericTriggerEventPSet.add<std::vector<int> >("dcsPartitions",{});
252  genericTriggerEventPSet.add<bool>("andOrDcs", false);
253  genericTriggerEventPSet.add<bool>("errorReplyDcs", true);
254  genericTriggerEventPSet.add<std::string>("dbLabel","");
255  genericTriggerEventPSet.add<bool>("andOrHlt", true);
256  genericTriggerEventPSet.add<edm::InputTag>("hltInputTag", edm::InputTag("TriggerResults::HLT") );
257  genericTriggerEventPSet.add<std::vector<std::string> >("hltPaths",{});
258  genericTriggerEventPSet.add<std::string>("hltDBKey","");
259  genericTriggerEventPSet.add<bool>("errorReplyHlt",false);
260  genericTriggerEventPSet.add<unsigned int>("verbosityLevel",1);
261 
262  desc.add<edm::ParameterSetDescription>("numGenericTriggerEventPSet", genericTriggerEventPSet);
263  desc.add<edm::ParameterSetDescription>("denGenericTriggerEventPSet", genericTriggerEventPSet);
264 
267  fillHistoPSetDescription(htPSet);
268  histoPSet.add<edm::ParameterSetDescription>("htPSet", htPSet);
269  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.,500.,550.,600.,650.,700.,750.,800.,850.,900.,950.,1000.,1050.,1100.,1200.,1300.,1400.,1500.,2000.,2500.};
270  histoPSet.add<std::vector<double> >("htBinning", bins);
271 
274  histoPSet.add<edm::ParameterSetDescription>("lsPSet", lsPSet);
275 
276  desc.add<edm::ParameterSetDescription>("histoPSet",histoPSet);
277 
278  descriptions.add("htMonitoring", desc);
279 }
280 
281 // Define this as a plug-in
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::MuonCollection > muoToken_
Definition: HTMonitor.h:94
edm::EDGetTokenT< reco::PFJetCollection > jetToken_
Definition: HTMonitor.h:92
HTME htME_variableBinning_
Definition: HTMonitor.h:101
MonitorElement * denominator
Definition: HTMonitor.h:62
void setHTitle(HTME &me, const std::string &titleX, const std::string &titleY)
Definition: HTMonitor.cc:54
void bookME(DQMStore::IBooker &, HTME &me, const std::string &histname, const std::string &histtitle, int nbins, double xmin, double xmax)
Definition: HTMonitor.cc:63
MonitorElement * bookProfile(Args &&...args)
Definition: DQMStore.h:157
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
StringCutObjectSelector< reco::Muon, true > muoSelection_
Definition: HTMonitor.h:112
~HTMonitor() override
std::vector< double > ht_variable_binning_
Definition: HTMonitor.h:97
std::vector< Vertex > VertexCollection
collection of Vertex objects
Definition: VertexFwd.h:9
unsigned njets_
Definition: HTMonitor.h:114
Provides a code based selection for trigger and DCS information in order to have no failing filters i...
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
Definition: HTMonitor.h:95
static MEHTbinning getHistoPSet(const edm::ParameterSet &pset)
Definition: HTMonitor.cc:36
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
const Point & position() const
position
Definition: Vertex.h:109
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
std::unique_ptr< GenericTriggerEventFlag > den_genTriggerEventFlag_
Definition: HTMonitor.h:107
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
StringCutObjectSelector< reco::MET, true > metSelection_
Definition: HTMonitor.h:109
virtual double phi() const final
momentum azimuthal angle
int iEvent
Definition: GenABIO.cc:230
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
vector< PseudoJet > jets
static void fillHistoLSPSetDescription(edm::ParameterSetDescription &pset)
Definition: HTMonitor.cc:224
MonitorElement * numerator
Definition: HTMonitor.h:61
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
HTMonitor(const edm::ParameterSet &)
Definition: HTMonitor.cc:11
T min(T a, T b)
Definition: MathUtil.h:58
static void fillHistoPSetDescription(edm::ParameterSetDescription &pset)
Definition: HTMonitor.cc:217
ParameterDescriptionBase * add(U const &iLabel, T const &value)
MEHTbinning ht_binning_
Definition: HTMonitor.h:98
edm::EDGetTokenT< reco::GsfElectronCollection > eleToken_
Definition: HTMonitor.h:93
MEHTbinning ls_binning_
Definition: HTMonitor.h:99
def ls(path, rec=False)
Definition: eostools.py:348
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:277
unsigned nelectrons_
Definition: HTMonitor.h:115
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
StringCutObjectSelector< reco::GsfElectron, true > eleSelection_
Definition: HTMonitor.h:111
StringCutObjectSelector< reco::PFJet, true > jetSelection_
Definition: HTMonitor.h:110
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void analyze(edm::Event const &iEvent, edm::EventSetup const &iSetup) override
Definition: HTMonitor.cc:135
std::string folderName_
Definition: HTMonitor.h:88
HTME deltaphimetj1ME_
Definition: HTMonitor.h:103
edm::EventID id() const
Definition: EventBase.h:60
std::vector< PFJet > PFJetCollection
collection of PFJet objects
fixed size matrix
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: HTMonitor.cc:229
StringCutObjectSelector< reco::PFJet, true > jetSelection_HT_
Definition: HTMonitor.h:113
static MEHTbinning getHistoLSPSet(const edm::ParameterSet &pset)
Definition: HTMonitor.cc:45
HTME deltaphij1j2ME_
Definition: HTMonitor.h:104
edm::EDGetTokenT< reco::PFMETCollection > metToken_
Definition: HTMonitor.h:91
HTME htVsLS_
Definition: HTMonitor.h:102
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: HTMonitor.cc:99
unsigned nmuons_
Definition: HTMonitor.h:116
static MEHTbinning phi_binning_
Definition: HTMonitor.h:120
Definition: Run.h:42
Collection of PF MET.
std::unique_ptr< GenericTriggerEventFlag > num_genTriggerEventFlag_
Definition: HTMonitor.h:106