CMS 3D CMS Logo

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