CMS 3D CMS Logo

FourVectorHLT.cc
Go to the documentation of this file.
8 
9 // see header file for information.
10 #include "FourVectorHLT.h"
11 
12 using namespace edm;
13 
15  LogDebug("FourVectorHLT") << "constructor....";
16 
17  usesResource("DQMStore");
18  dbe_ = Service<DQMStore>().operator->();
19  if (!dbe_) {
20  LogWarning("Status") << "unable to get DQMStore service?";
21  }
22 
23  dirname_ = "HLT/FourVectorHLT";
24 
25  if (dbe_ != nullptr) {
26  LogDebug("Status") << "Setting current directory to " << dirname_;
27  dbe_->setCurrentFolder(dirname_);
28  }
29 
30  // plotting paramters
31  ptMin_ = iConfig.getUntrackedParameter<double>("ptMin", 0.);
32  ptMax_ = iConfig.getUntrackedParameter<double>("ptMax", 200.);
33  nBins_ = iConfig.getUntrackedParameter<unsigned int>("Nbins", 50);
34 
35  plotAll_ = iConfig.getUntrackedParameter<bool>("plotAll", false);
36 
37  // this is the list of paths to look at.
38  std::vector<edm::ParameterSet> filters = iConfig.getParameter<std::vector<edm::ParameterSet> >("filters");
39  for (std::vector<edm::ParameterSet>::iterator filterconf = filters.begin(); filterconf != filters.end();
40  filterconf++) {
41  std::string me = filterconf->getParameter<std::string>("name");
42  int objectType = filterconf->getParameter<unsigned int>("type");
43  float ptMin = filterconf->getUntrackedParameter<double>("ptMin");
44  float ptMax = filterconf->getUntrackedParameter<double>("ptMax");
45  hltPaths_.push_back(PathInfo(me, objectType, ptMin, ptMax));
46  }
47  if (!hltPaths_.empty() && plotAll_) {
48  // these two ought to be mutually exclusive....
49  LogWarning("Configuration") << "Using both plotAll and a list. "
50  "list will be ignored.";
51  hltPaths_.clear();
52  }
53  triggerSummaryLabel_ = iConfig.getParameter<edm::InputTag>("triggerSummaryLabel");
54 
55  //set Token(-s)
56  triggerSummaryToken_ = consumes<trigger::TriggerEvent>(iConfig.getParameter<edm::InputTag>("triggerSummaryLabel"));
57 }
58 
60  // do anything here that needs to be done at desctruction time
61  // (e.g. close files, deallocate resources etc.)
62 }
63 
64 //
65 // member functions
66 //
67 
68 // ------------ method called to for each event ------------
70  using namespace edm;
71  using namespace trigger;
72  ++nev_;
73  LogDebug("Status") << "analyze";
74 
75  edm::Handle<TriggerEvent> triggerObj;
76  iEvent.getByToken(triggerSummaryToken_, triggerObj);
77  if (!triggerObj.isValid()) {
78  edm::LogInfo("Status") << "Summary HLT object (TriggerEvent) not found, "
79  "skipping event";
80  return;
81  }
82 
83  const trigger::TriggerObjectCollection& toc(triggerObj->getObjects());
84 
85  if (plotAll_) {
86  for (size_t ia = 0; ia < triggerObj->sizeFilters(); ++ia) {
87  std::string fullname = triggerObj->filterTag(ia).encode();
88  // the name can have in it the module label as well as the process and
89  // other labels - strip 'em
91  size_t p = fullname.find_first_of(':');
92  if (p != std::string::npos) {
93  name = fullname.substr(0, p);
94  } else {
95  name = fullname;
96  }
97 
98  LogDebug("Parameter") << "filter " << ia << ", full name = " << fullname << ", p = " << p
99  << ", abbreviated = " << name;
100 
101  PathInfoCollection::iterator pic = hltPaths_.find(name);
102  if (pic == hltPaths_.end()) {
103  // doesn't exist - add it
104  MonitorElement *et(nullptr), *eta(nullptr), *phi(nullptr), *etavsphi(nullptr);
105 
106  std::string histoname(name + "_et");
107  LogDebug("Status") << "new histo with name " << histoname;
108  dbe_->setCurrentFolder(dirname_);
109  std::string title(name + " E_{T}");
110  et = dbe_->book1D(histoname.c_str(), title.c_str(), nBins_, 0, 100);
111 
112  histoname = name + "_eta";
113  title = name + " #eta";
114  eta = dbe_->book1D(histoname.c_str(), title.c_str(), nBins_, -2.7, 2.7);
115 
116  histoname = name + "_phi";
117  title = name + " #phi";
118  phi = dbe_->book1D(histoname.c_str(), title.c_str(), nBins_, -3.14, 3.14);
119 
120  histoname = name + "_etaphi";
121  title = name + " #eta vs #phi";
122  etavsphi = dbe_->book2D(histoname.c_str(), title.c_str(), nBins_, -2.7, 2.7, nBins_, -3.14, 3.14);
123 
124  // no idea how to get the bin boundries in this mode
125  PathInfo e(name, 0, et, eta, phi, etavsphi, ptMin_, ptMax_);
126  hltPaths_.push_back(e);
127  pic = hltPaths_.begin() + hltPaths_.size() - 1;
128  }
129  const trigger::Keys& k = triggerObj->filterKeys(ia);
130  for (trigger::Keys::const_iterator ki = k.begin(); ki != k.end(); ++ki) {
131  LogDebug("Parameters") << "pt, eta, phi = " << toc[*ki].pt() << ", " << toc[*ki].eta() << ", "
132  << toc[*ki].phi();
133  pic->getEtHisto()->Fill(toc[*ki].pt());
134  pic->getEtaHisto()->Fill(toc[*ki].eta());
135  pic->getPhiHisto()->Fill(toc[*ki].phi());
136  pic->getEtaVsPhiHisto()->Fill(toc[*ki].eta(), toc[*ki].phi());
137  }
138  }
139 
140  } else { // not plotAll_
141  for (PathInfoCollection::iterator v = hltPaths_.begin(); v != hltPaths_.end(); ++v) {
142  const int index = triggerObj->filterIndex(v->getName());
143  if (index >= triggerObj->sizeFilters()) {
144  continue; // not in this event
145  }
146  LogDebug("Status") << "filling ... ";
147  const trigger::Keys& k = triggerObj->filterKeys(index);
148  for (trigger::Keys::const_iterator ki = k.begin(); ki != k.end(); ++ki) {
149  v->getEtHisto()->Fill(toc[*ki].pt());
150  v->getEtaHisto()->Fill(toc[*ki].eta());
151  v->getPhiHisto()->Fill(toc[*ki].phi());
152  v->getEtaVsPhiHisto()->Fill(toc[*ki].eta(), toc[*ki].phi());
153  }
154  }
155  }
156 }
157 
158 // -- method called once each job just before starting event loop --------
160  nev_ = 0;
161  DQMStore* dbe = nullptr;
162  dbe = Service<DQMStore>().operator->();
163 
164  if (dbe) {
165  dbe->setCurrentFolder(dirname_);
166 
167  if (!plotAll_) {
168  for (PathInfoCollection::iterator v = hltPaths_.begin(); v != hltPaths_.end(); ++v) {
169  MonitorElement *et, *eta, *phi, *etavsphi = nullptr;
170  std::string histoname(v->getName() + "_et");
171  std::string title(v->getName() + " E_t");
172  et = dbe->book1D(histoname.c_str(), title.c_str(), nBins_, v->getPtMin(), v->getPtMax());
173 
174  histoname = v->getName() + "_eta";
175  title = v->getName() + " #eta";
176  eta = dbe->book1D(histoname.c_str(), title.c_str(), nBins_, -2.7, 2.7);
177 
178  histoname = v->getName() + "_phi";
179  title = v->getName() + " #phi";
180  phi = dbe->book1D(histoname.c_str(), histoname.c_str(), nBins_, -3.14, 3.14);
181 
182  histoname = v->getName() + "_etaphi";
183  title = v->getName() + " #eta vs #phi";
184  etavsphi = dbe->book2D(histoname.c_str(), title.c_str(), nBins_, -2.7, 2.7, nBins_, -3.14, 3.14);
185 
186  v->setHistos(et, eta, phi, etavsphi);
187  }
188  } // ! plotAll_ - for plotAll we discover it during the event
189  }
190 }
191 
192 // - method called once each job just after ending the event loop ------------
194  LogInfo("Status") << "endJob: analyzed " << nev_ << " events";
195  return;
196 }
197 
198 // BeginRun
200  LogDebug("Status") << "beginRun, run " << run.id();
201 }
202 
205  LogDebug("Status") << "endRun, run " << run.id();
206 }
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:119
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
~FourVectorHLT() override
std::string encode() const
Definition: InputTag.cc:159
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:147
void setCurrentFolder(std::string const &fullpath) override
Definition: DQMStore.h:646
constexpr float ptMin
void endRun(const edm::Run &run, const edm::EventSetup &c) override
EndRun.
FourVectorHLT(const edm::ParameterSet &)
const edm::InputTag filterTag(trigger::size_type index) const
Definition: TriggerEvent.h:109
std::vector< TPRegexp > filters
Definition: eve_filter.cc:22
T getUntrackedParameter(std::string const &, T const &) const
int iEvent
Definition: GenABIO.cc:224
void analyze(const edm::Event &, const edm::EventSetup &) override
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:102
void beginJob() override
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:75
Log< level::Info, false > LogInfo
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:133
std::vector< size_type > Keys
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
bool isValid() const
Definition: HandleBase.h:70
void endJob() override
HLT enums.
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
void beginRun(const edm::Run &run, const edm::EventSetup &c) override
Definition: Run.h:45
#define LogDebug(id)