CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTMonSimpleBTag.cc
Go to the documentation of this file.
1 // $Id: HLTMonSimpleBTag.cc,v 1.4 2011/04/15 10:15:36 fblekman Exp $
2 // See header file for information.
7 
10 
13 
15 
18 
19 
20 using namespace edm;
21 
23  resetMe_(true), currentRun_(-99)
24 {
25  LogDebug("HLTMonSimpleBTag") << "constructor...." ;
26 
28  if ( ! dbe_ ) {
29  LogWarning("Status") << "unable to get DQMStore service?";
30  }
31  if (iConfig.getUntrackedParameter < bool > ("DQMStore", false)) {
32  dbe_->setVerbose(0);
33  }
34 
35 
36  dirname_="HLT/HLTMonSimpleBTag" ;
37 
38  if (dbe_ != 0 ) {
39  LogDebug("Status") << "Setting current directory to " << dirname_;
41  }
42 
43 
44  // plotting paramters
45  ptMin_ = iConfig.getUntrackedParameter<double>("ptMin",0.);
46  ptMax_ = iConfig.getUntrackedParameter<double>("ptMax",200.);
47  nBins_ = iConfig.getUntrackedParameter<unsigned int>("Nbins",50);
48  dRTrigObjMatch_ = iConfig.getUntrackedParameter<double>("dRMatch",0.3);
49  refresheff_ = iConfig.getUntrackedParameter<unsigned int>("Nrefresh",10);
50 
51 
52 
53  // this is the list of paths to look at.
54  std::vector<edm::ParameterSet> filters =
55  iConfig.getParameter<std::vector<edm::ParameterSet> >("filters");
56  for(std::vector<edm::ParameterSet>::iterator
57  filterconf = filters.begin() ; filterconf != filters.end();
58  filterconf++) {
59  std::string me = filterconf->getParameter<std::string>("name");
60  std::string denom = filterconf->getParameter<std::string>("refname");
61  // only fill if both triggers are not there yet.
62  if(hltPaths_.find(me)==hltPaths_.end())
63  hltPaths_.push_back(PathInfo(me,ptMin_, ptMax_));
64  if(hltPaths_.find(denom)==hltPaths_.end())
65  hltPaths_.push_back(PathInfo(denom, ptMin_, ptMax_));
66 
67  std::string effname = makeEffName(me,denom);
68  std::string numername=makeEffNumeratorName(me,denom);
69  std::pair<std::string,std::string> trigpair(me,denom);
70  if(find(triggerMap_.begin(),triggerMap_.end(),trigpair)==triggerMap_.end())
71  triggerMap_.push_back(trigpair);
72  if(hltEfficiencies_.find(effname)==hltEfficiencies_.end())
73  hltEfficiencies_.push_back(PathInfo(effname,ptMin_,ptMax_));
74  if(hltEfficiencies_.find(numername)==hltEfficiencies_.end())
75  hltEfficiencies_.push_back(PathInfo(numername,ptMin_,ptMax_));
76 
77  }
79  iConfig.getParameter<edm::InputTag>("triggerSummaryLabel");
80 }
81 
82 
84 {
85 
86  // do anything here that needs to be done at desctruction time
87  // (e.g. close files, deallocate resources etc.)
88 
89 }
90 
91 
92 //
93 // member functions
94 //
95 
96 // ------------ method called to for each event ------------
97 void
99 {
100  using namespace edm;
101  using namespace trigger;
102  ++nev_;
103  LogDebug("Status")<< "analyze" ;
104 
105  edm::Handle<TriggerEvent> triggerObj;
106  iEvent.getByLabel(triggerSummaryLabel_,triggerObj);
107  if(!triggerObj.isValid()) {
108  edm::LogInfo("Status") << "Summary HLT object (TriggerEvent) not found, "
109  "skipping event";
110  return;
111  }
112 
113  const trigger::TriggerObjectCollection & toc(triggerObj->getObjects());
114 
115  for ( size_t ia = 0; ia < triggerObj->sizeFilters(); ++ ia) {
116  std::string fullname = triggerObj->filterTag(ia).encode();
117  // the name can have in it the module label as well as the process and
118  // other labels - strip 'em
119  std::string name;
120  size_t p = fullname.find_first_of(':');
121  if ( p != std::string::npos) {
122  name = fullname.substr(0, p);
123  }
124  else {
125  name = fullname;
126  }
127 
128  LogDebug("Parameter") << "filter " << ia << ", full name = " << fullname
129  << ", p = " << p
130  << ", abbreviated = " << name ;
131  // std::cout << std::endl;
132  // check that trigger is in 'watch list'
133  PathInfoCollection::iterator pic = hltPaths_.find(name);
134  if(pic==hltPaths_.end())
135  continue;
136 
137  // find keys
138 
139  const trigger::Keys & k = triggerObj->filterKeys(ia);
140  for (trigger::Keys::const_iterator ki = k.begin(); ki !=k.end(); ++ki ) {
141  LogDebug("Parameters") << name << "(" << ki-k.begin() << "): pt, eta, phi = "
142  << toc[*ki].pt() << ", "
143  << toc[*ki].eta() << ", "
144  << toc[*ki].phi() <<","
145  << toc[*ki].id();
146  pic->getEtHisto()->Fill(toc[*ki].pt());
147  pic->getEtaHisto()->Fill(toc[*ki].eta());
148  pic->getPhiHisto()->Fill(toc[*ki].phi());
149  pic->getEtaVsPhiHisto()->Fill(toc[*ki].eta(), toc[*ki].phi());
150  }
151 
152  // check which trigger this trigger is reference to, fill those histograms separately:
153  for(std::vector<std::pair<std::string, std::string> >::iterator matchIter = triggerMap_.begin(); matchIter!=triggerMap_.end(); ++matchIter){
154  // only do anything if you actually have a match
155  if(matchIter->second!=name)
156  continue;
157  LogDebug("HLTMonSimpleBTag") << "found match! " << " " << matchIter->first << " " << matchIter->second ;
158  // now go find this one in the trigger collection... this is somewhat painful :(
159  for(size_t ib = 0; ib < triggerObj->sizeFilters(); ++ ib) {
160  if(ib==ia)
161  continue;
162  std::string fullname_b = triggerObj->filterTag(ib).encode();
163  // the name can have in it the module label as well as the process and
164  // other labels - strip 'em
165  std::string name_b;
166  size_t p_b = fullname_b.find_first_of(':');
167  if ( p_b != std::string::npos) {
168  name_b = fullname_b.substr(0, p_b);
169  }
170  else {
171  name_b = fullname_b;
172  }
173  // this is where the matching to the trigger array happens
174  if(name_b!=matchIter->first)
175  continue;
176 
177  // ok, now we have two matching triggers with indices ia and ib in the trigger index. Get the keys for ib.
178 
179  // find the correct monitoring element:
180  std::string numeratorname = makeEffNumeratorName(matchIter->first,matchIter->second);
181  PathInfoCollection::iterator pic_b = hltEfficiencies_.find(numeratorname);
182  if(pic_b==hltEfficiencies_.end())
183  continue;
184 
185  const trigger::Keys & k_b = triggerObj->filterKeys(ib);
186 
187  const trigger::Keys & k = triggerObj->filterKeys(ia);
188  for (trigger::Keys::const_iterator ki = k.begin(); ki !=k.end(); ++ki ) {
189  for (trigger::Keys::const_iterator ki_b = k_b.begin(); ki_b !=k_b.end(); ++ki_b ) {
190  // do cone match...
191  if(reco::deltaR(toc[*ki].eta(),toc[*ki_b].phi(),toc[*ki].eta(),toc[*ki_b].phi())>dRTrigObjMatch_)
192  continue;
193 
194  LogDebug("Parameters") << "matched pt, eta, phi = "
195  << toc[*ki].pt() << ", "
196  << toc[*ki].eta() << ", "
197  << toc[*ki].phi() << " to "
198  << toc[*ki_b].pt() << ", "
199  << toc[*ki_b].eta() << ", "
200  << toc[*ki_b].phi() << " (using the first to fill histo to avoid division problems...)";
201  // as these are going to be divided it is important to fill numerator and denominator with the same pT spectrum. So this is why these are filled with ki objects instead of ki_b objects...
202  pic_b->getEtHisto()->Fill(toc[*ki].pt());
203  pic_b->getEtaHisto()->Fill(toc[*ki].eta());
204  pic_b->getPhiHisto()->Fill(toc[*ki].phi());
205  pic_b->getEtaVsPhiHisto()->Fill(toc[*ki].eta(), toc[*ki].phi());
206  // for now just take the first match there are two keys within the same cone...
207  break;
208  }
209  }
210  }
211  }
212  }
213  // and calculate efficiencies, only if the number of events is the refresh rate:
214  if(nev_%refresheff_==0 && nev_!=1){
215  calcEff();
216  }
217 }
218 
219 
220 // -- method called once each job just before starting event loop --------
221 void
223 {
224  nev_ = 0;
225  DQMStore *dbe = 0;
226  dbe = Service<DQMStore>().operator->();
227 
228  if (dbe) {
230  dbe->rmdir(dirname_);
231  }
232 
233 
234  if (dbe) {
236 
237  for(PathInfoCollection::iterator v = hltPaths_.begin();
238  v!= hltPaths_.end(); ++v ) {
239  MonitorElement *et, *eta, *phi, *etavsphi=0;
240  std::string histoname(v->getName()+"_et");
241  std::string title(v->getName()+" E_t");
242  et = dbe->book1D(histoname.c_str(),
243  title.c_str(),nBins_,
244  v->getPtMin(),
245  v->getPtMax());
246 
247  histoname = v->getName()+"_eta";
248  title = v->getName()+" #eta";
249  eta = dbe->book1D(histoname.c_str(),
250  title.c_str(),nBins_/2,-2.7,2.7);
251 
252  histoname = v->getName()+"_phi";
253  title = v->getName()+" #phi";
254  phi = dbe->book1D(histoname.c_str(),
255  histoname.c_str(),nBins_/2,-3.14,3.14);
256 
257 
258  histoname = v->getName()+"_etaphi";
259  title = v->getName()+" #eta vs #phi";
260  etavsphi = dbe->book2D(histoname.c_str(),
261  title.c_str(),
262  nBins_/2,-2.7,2.7,
263  nBins_/2,-3.14, 3.14);
264 
265  v->setHistos( et, eta, phi, etavsphi);
266  }
267 
268  for(PathInfoCollection::iterator v = hltEfficiencies_.begin();
269  v!= hltEfficiencies_.end(); ++v ) {
270  MonitorElement *et, *eta, *phi, *etavsphi=0;
271  std::string histoname(v->getName()+"_et");
272  std::string title(v->getName()+" E_t");
273  et = dbe->book1D(histoname.c_str(),
274  title.c_str(),nBins_,
275  v->getPtMin(),
276  v->getPtMax());
277 
278  histoname = v->getName()+"_eta";
279  title = v->getName()+" #eta";
280  eta = dbe->book1D(histoname.c_str(),
281  title.c_str(),nBins_/2,-2.7,2.7);
282 
283  histoname = v->getName()+"_phi";
284  title = v->getName()+" #phi";
285  phi = dbe->book1D(histoname.c_str(),
286  histoname.c_str(),nBins_/2,-3.14,3.14);
287 
288 
289  histoname = v->getName()+"_etaphi";
290  title = v->getName()+" #eta vs #phi";
291  etavsphi = dbe->book2D(histoname.c_str(),
292  title.c_str(),
293  nBins_/2,-2.7,2.7,
294  nBins_/2,-3.14, 3.14);
295 
296  v->setHistos( et, eta, phi, etavsphi);
297  }
298  }
299 }
300 
301 // - method called once each job just after ending the event loop ------------
302 void
304 {
305  LogInfo("Status") << "endJob: analyzed " << nev_ << " events";
306  return;
307 }
308 
309 
310 // BeginRun
312 {
313  LogDebug("Status") << "beginRun, run " << run.id();
314 }
315 
318 {
319  LogDebug("Status") << "final re-calculation efficiencies!" ;
320  calcEff();
321  LogDebug("Status") << "endRun, run " << run.id();
322 
323 }
324 
325 
327 
328 void
330 
331  for( std::vector<std::pair<std::string,std::string> >::iterator iter = triggerMap_.begin(); iter!=triggerMap_.end(); iter++){
332  if(hltPaths_.find(iter->first)==hltPaths_.end())
333  continue;
334  if(hltPaths_.find(iter->second)==hltPaths_.end())
335  continue;
336 
337  std::string effname = makeEffName(iter->first,iter->second);
338  std::string numeratorname = makeEffNumeratorName(iter->first,iter->second);
339  LogDebug("HLTMonBTagSlim::calcEff") << "calculating efficiencies for histogram with effname=" << effname << " using also histogram " << numeratorname ;
340  PathInfoCollection::iterator effHists = hltEfficiencies_.find(effname);
341  if(effHists==hltEfficiencies_.end())
342  continue;
343  PathInfoCollection::iterator numerHists = hltEfficiencies_.find(numeratorname);
344  if(numerHists==hltEfficiencies_.end())
345  continue;
346  LogDebug("HLTMonBTagSlim::calcEff") << "found histo with name " << effname << " and " << numeratorname << "!" ;
347  // do the hists all separately:
348 
349  doEffCalc(effHists->getEtHisto(),numerHists->getEtHisto(),hltPaths_.find(iter->second)->getEtHisto());
350  doEffCalc(effHists->getEtaHisto(),numerHists->getEtaHisto(),hltPaths_.find(iter->second)->getEtaHisto());
351  doEffCalc(effHists->getPhiHisto(),numerHists->getPhiHisto(),hltPaths_.find(iter->second)->getPhiHisto());
352  doEffCalc(effHists->getEtaVsPhiHisto(),numerHists->getEtaVsPhiHisto(),hltPaths_.find(iter->second)->getEtaVsPhiHisto());
353 
354 
355  }
356  LogDebug("HLTMonBTagSlim::calcEff") << "done with efficiencies!" ;
357 }
358 
359 // function to actually do the efficiency calculation per-bin
360 void
362  double x,y,errx,erry;
363 
364  // presuming error propagation is non-quadratic (binominal):
365  // so: err!= Sqrt(errx^2/x^2+erry^2/y^2) but instead
366  //
367  // err=sqrt(errx^2/x^2+erry^2/y^2)* x/y*(1-x/y)
368  bool is1d=false;
369  bool is2d=false;
371  is1d=true;
373  is2d=true;
374 
375 
376  for(int ibin=0; ibin<=eff->getNbinsX() && ibin<=num->getNbinsX(); ibin++){
377  if(is1d){ // 1D histograms!
378  x=num->getBinContent(ibin);
379  errx=num->getBinError(ibin);
380  y=denom->getBinContent(ibin);
381  erry=denom->getBinError(ibin);
382  if(fabs(y)<0.00001 || fabs(x)<0.0001){// very stringent non-zero!
383  eff->setBinContent(ibin,0);
384  eff->setBinError(ibin,0);
385  continue;
386  }
387 
388  LogDebug("HLTMonSimpleBTag::calcEff()") << eff->getName() << " (" << ibin << ") " << x << " " << y;
389  eff->setBinContent(ibin,x/y);
390  eff->setBinError(ibin,sqrt((errx*errx)/(x*x)+(erry*erry)/(y*y))* (x/y)*(1-(x/y)));
391  }
392  else if(is2d){ // 2D histograms!
393  for(int jbin=0; jbin<=num->getNbinsY(); jbin++){
394  x=num->getBinContent(ibin,jbin);
395  errx=num->getBinError(ibin,jbin);
396  y=denom->getBinContent(ibin,jbin);
397  erry=denom->getBinError(ibin,jbin);
398  if(fabs(y)<0.0001 || fabs(x)<0.0001){ // very stringent non-zero!
399  eff->setBinContent(ibin,jbin,0.);
400  eff->setBinError(ibin,jbin,0.);
401  continue;
402  }
403  LogDebug("HLTMonSimpleBTag::calcEff()") << eff->getName() << " (" << ibin<< "," << jbin << ") " << x << " " << y ;
404 
405  eff->setBinContent(ibin,jbin,x/y);
406  eff->setBinError(ibin,jbin,sqrt((errx*errx)/(x*x)+(erry*erry)/(y*y))* (x/y)*(1-(x/y)));
407  }
408  }
409  }
410 }
411 
#define LogDebug(id)
std::string dirname_
virtual void beginJob()
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
void setBinContent(int binx, double content)
set content of bin (1-D)
static const uint32_t DQM_PROP_TYPE_TH1S
Definition: DQMNet.h:32
RunID const & id() const
Definition: RunBase.h:41
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:717
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:2530
static const uint32_t DQM_PROP_TYPE_TH2D
Definition: DQMNet.h:36
std::vector< PathInfo >::iterator find(std::string pathName)
std::vector< std::pair< std::string, std::string > > triggerMap_
unsigned int nBins_
void beginRun(const edm::Run &run, const edm::EventSetup &c)
static const uint32_t DQM_PROP_TYPE_TH1F
Definition: DQMNet.h:31
T eta() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< TPRegexp > filters
Definition: eve_filter.cc:25
edm::InputTag triggerSummaryLabel_
int getNbinsY(void) const
get # of bins in Y-axis
double deltaR(double eta1, double phi1, double eta2, double phi2)
Definition: deltaR.h:19
PathInfoCollection hltEfficiencies_
int iEvent
Definition: GenABIO.cc:243
virtual void analyze(const edm::Event &, const edm::EventSetup &)
T sqrt(T t)
Definition: SSEVec.h:46
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
void setVerbose(unsigned level)
Definition: DQMStore.cc:393
Kind kind(void) const
Get the type of the monitor element.
static const uint32_t DQM_PROP_TYPE_TH1D
Definition: DQMNet.h:33
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
virtual void endJob()
int k[5][pyjets_maxn]
HLTMonSimpleBTag(const edm::ParameterSet &)
std::vector< TriggerObject > TriggerObjectCollection
collection of trigger physics objects (e.g., all isolated muons)
Definition: TriggerObject.h:83
double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
std::vector< size_type > Keys
long long int num
Definition: procUtils.cc:71
std::string makeEffNumeratorName(std::string trig1, std::string trig2)
PathInfoCollection hltPaths_
double getBinContent(int binx) const
get content of bin (1-D)
static const uint32_t DQM_PROP_TYPE_TH2S
Definition: DQMNet.h:35
int getNbinsX(void) const
get # of bins in X-axis
void doEffCalc(MonitorElement *eff, MonitorElement *num, MonitorElement *denom)
void endRun(const edm::Run &run, const edm::EventSetup &c)
EndRun.
x
Definition: VDTMath.h:216
void calcEff(void)
calcEff: calculates efficiency using histograms booked in std::map&lt;std::string,std::string&gt; triggerMa...
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:845
mathSSE::Vec4< T > v
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:429
std::string makeEffName(std::string trig1, std::string trig2)
Definition: Run.h:33
static const uint32_t DQM_PROP_TYPE_TH2F
Definition: DQMNet.h:34
Definition: DDAxes.h:10