CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTriggerEfficiencyTest.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author C. Battilana - CIEMAT
5  *
6  * threadsafe version (//-) oct/nov 2014 - WATWanAbdullah -ncpp-um-my
7  *
8  */
9 
10 
11 // This class header
13 
14 // Framework headers
19 
20 // Geometry
23 
24 // Trigger
26 
27 // Root
28 #include "TF1.h"
29 #include "TProfile.h"
30 
31 
32 //C++ headers
33 #include <iostream>
34 #include <sstream>
35 
36 using namespace edm;
37 using namespace std;
38 
39 
41 
42  setConfig(ps,"DTTriggerEfficiency");
43  baseFolderDCC = "DT/03-LocalTrigger-DCC/";
44  baseFolderDDU = "DT/04-LocalTrigger-DDU/";
45  detailedPlots = ps.getUntrackedParameter<bool>("detailedAnalysis",true);
46 
47  bookingdone = 0;
48 }
49 
50 
52 
53 }
54 
55 
57 
59  trigGeomUtils = new DTTrigGeomUtils(muonGeom);
60 
61 }
62 
64  edm::LuminosityBlock const & lumiSeg, edm::EventSetup const & c) {
65 }
66 
68 
69  // Loop over Trig & Hw sources
70  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
71  trigSource = (*iTr);
72  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
73  hwSource = (*iHw);
74  // Loop over the TriggerUnits
75  if( globalEffDistr.find(fullName("TrigEffPhi")) == globalEffDistr.end() ){
76 
77  bookHistos(ibooker,"TrigEffPhi","");
78  bookHistos(ibooker,"TrigEffCorrPhi","");
79  }
80  for (int wh=-2; wh<=2; ++wh){
81 
82  TH2F * TrigEffDenum = getHisto<TH2F>(igetter.get(getMEName("TrigEffDenum","Task",wh)));
83  TH2F * TrigEffNum = getHisto<TH2F>(igetter.get(getMEName("TrigEffNum","Task",wh)));
84  TH2F * TrigEffCorrNum = getHisto<TH2F>(igetter.get(getMEName("TrigEffCorrNum","Task",wh)));
85 
86  if (TrigEffDenum && TrigEffNum && TrigEffCorrNum && TrigEffDenum->GetEntries()>1) {
87 
88  if( whME[wh].find(fullName("TrigEffPhi")) == whME[wh].end() ){
89 
90  bookWheelHistos(ibooker,wh,"TrigEffPhi","");
91  bookWheelHistos(ibooker,wh,"TrigEffCorrPhi","");
92  }
93 
94  MonitorElement* Eff1DAll_TrigEffPhi = (&globalEffDistr)->find(fullName("TrigEffPhi"))->second;
95  MonitorElement* Eff1DAll_TrigEffCorrPhi = (&globalEffDistr)->find(fullName("TrigEffCorrPhi"))->second;
96 
97  MonitorElement* Eff1DWh_TrigEffPhi = (&(EffDistrPerWh[wh]))->find(fullName("TrigEffPhi"))->second;
98  MonitorElement* Eff1DWh_TrigEffCorrPhi = (&(EffDistrPerWh[wh]))->find(fullName("TrigEffCorrPhi"))->second;
99 
100  MonitorElement* Eff2DWh_TrigEffPhi = (&(whME[wh]))->find(fullName("TrigEffPhi"))->second;
101  MonitorElement* Eff2DWh_TrigEffCorrPhi = (&(whME[wh]))->find(fullName("TrigEffCorrPhi"))->second;
102 
103  makeEfficiencyME(TrigEffNum,TrigEffDenum,Eff2DWh_TrigEffPhi,Eff1DWh_TrigEffPhi,Eff1DAll_TrigEffPhi);
104  makeEfficiencyME(TrigEffCorrNum,TrigEffDenum,Eff2DWh_TrigEffCorrPhi,Eff1DWh_TrigEffCorrPhi,Eff1DAll_TrigEffCorrPhi);
105 
106  }
107 
108  if (detailedPlots) {
109  for (int stat=1; stat<=4; ++stat){
110  for (int sect=1; sect<=12; ++sect){
111  DTChamberId chId(wh,stat,sect);
112  uint32_t indexCh = chId.rawId();
113 
114  // Perform Efficiency analysis (Phi+Segments 2D)
115 
116  TH2F * TrackPosvsAngle = getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngle","Segment", chId)));
117  TH2F * TrackPosvsAngleAnyQual = getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngleAnyQual","Segment", chId)));
118  TH2F * TrackPosvsAngleCorr = getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngleCorr","Segment", chId)));
119 
120  if (TrackPosvsAngle && TrackPosvsAngleAnyQual && TrackPosvsAngleCorr && TrackPosvsAngle->GetEntries()>1) {
121 
122  if( chambME[indexCh].find(fullName("TrigEffAnglePhi")) == chambME[indexCh].end()){
123  bookChambHistos(ibooker,chId,"TrigEffPosvsAnglePhi","Segment");
124  bookChambHistos(ibooker,chId,"TrigEffPosvsAngleCorrPhi","Segment");
125  }
126 
127  std::map<std::string,MonitorElement*> *innerME = &(chambME[indexCh]);
128  makeEfficiencyME(TrackPosvsAngleAnyQual,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAnglePhi"))->second);
129  makeEfficiencyME(TrackPosvsAngleCorr,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAngleCorrPhi"))->second);
130 
131  }
132  }
133  }
134  }
135  }
136 
137  }
138  }
139 
140 }
141 
143 
144  TH2F* efficiency = result2DWh->getTH2F();
145  efficiency->Divide(numerator,denominator,1,1,"");
146 
147  int nbinsx = efficiency->GetNbinsX();
148  int nbinsy = efficiency->GetNbinsY();
149  for (int binx=1; binx<=nbinsx; ++binx){
150  for (int biny=1; biny<=nbinsy; ++biny){
151  float error = 0;
152  float bineff = efficiency->GetBinContent(binx,biny);
153 
154  result1DWh->Fill(bineff);
155  result1D->Fill(bineff);
156 
157  if (denominator->GetBinContent(binx,biny)){
158  error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(binx,biny));
159  }
160  else {
161  error = 1;
162  efficiency->SetBinContent(binx,biny,0.);
163  }
164 
165  efficiency->SetBinError(binx,biny,error);
166  }
167  }
168 
169 }
170 
172 
173  TH2F* efficiency = result2DWh->getTH2F();
174  efficiency->Divide(numerator,denominator,1,1,"");
175 
176  int nbinsx = efficiency->GetNbinsX();
177  int nbinsy = efficiency->GetNbinsY();
178  for (int binx=1; binx<=nbinsx; ++binx){
179  for (int biny=1; biny<=nbinsy; ++biny){
180  float error = 0;
181  float bineff = efficiency->GetBinContent(binx,biny);
182 
183  if (denominator->GetBinContent(binx,biny)){
184  error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(binx,biny));
185  }
186  else {
187  error = 1;
188  efficiency->SetBinContent(binx,biny,0.);
189  }
190 
191  efficiency->SetBinError(binx,biny,error);
192  }
193  }
194 
195 }
196 
197 string DTTriggerEfficiencyTest::getMEName(string histoTag, string folder, int wh) {
198 
199  stringstream wheel; wheel << wh;
200 
201  string folderName = topFolder(hwSource=="DCC") + folder + "/";
202 
203  string histoname = sourceFolder + folderName
204  + fullName(histoTag) + "_W" + wheel.str();
205 
206  return histoname;
207 
208 }
209 
210 void DTTriggerEfficiencyTest::bookHistos(DQMStore::IBooker & ibooker,string hTag,string folder) {
211 
212  string basedir;
213  bool isDCC = hwSource=="DCC" ;
214  basedir = topFolder(isDCC); //Book summary histo outside Task directory
215 
216  if (folder != "") {
217  basedir += folder +"/" ;
218  }
219 
220  ibooker.setCurrentFolder(basedir);
221 
222  string fullTag = fullName(hTag);
223  string hname = fullTag + "_All";
224 
225  globalEffDistr[fullTag] = ibooker.book1D(hname.c_str(),hname.c_str(),51,0.,1.02);
226  globalEffDistr[fullTag] ->setAxisTitle("Trig Eff",1);
227 
228 }
229 
230 void DTTriggerEfficiencyTest::bookWheelHistos(DQMStore::IBooker & ibooker,int wheel,string hTag,string folder) {
231 
232  stringstream wh; wh << wheel;
233  string basedir;
234  bool isDCC = hwSource=="DCC" ;
235  if (hTag.find("Summary") != string::npos) {
236  basedir = topFolder(isDCC); //Book summary histo outside wheel directories
237  } else {
238  basedir = topFolder(isDCC) + "Wheel" + wh.str() + "/" ;
239 
240  }
241  if (folder != "") {
242  basedir += folder +"/" ;
243  }
244 
245  ibooker.setCurrentFolder(basedir);
246 
247  string fullTag = fullName(hTag);
248  string hname = fullTag+ "_W" + wh.str();
249 
250  string hnameAll = fullTag+ "_All_W" + wh.str();
251 
252  LogTrace(category()) << "[" << testName << "Test]: booking "<< basedir << hname;
253 
254  (EffDistrPerWh[wheel])[fullTag] = ibooker.book1D(hnameAll.c_str(),hnameAll.c_str(),51,0.,1.02);
255 
256  if (hTag.find("Phi")!= string::npos ||
257  hTag.find("Summary") != string::npos ){
258 
259  MonitorElement* me = ibooker.book2D(hname.c_str(),hname.c_str(),12,1,13,4,1,5);
260 
261  // setLabelPh(me);
262  me->setBinLabel(1,"MB1",2);
263  me->setBinLabel(2,"MB2",2);
264  me->setBinLabel(3,"MB3",2);
265  me->setBinLabel(4,"MB4",2);
266  me->setAxisTitle("Sector",1);
267 
268  whME[wheel][fullTag] = me;
269  return;
270  }
271 
272  if (hTag.find("Theta") != string::npos){
273 
274  MonitorElement* me =ibooker.book2D(hname.c_str(),hname.c_str(),12,1,13,3,1,4);
275 
276  // setLabelTh(me);
277  me->setBinLabel(1,"MB1",2);
278  me->setBinLabel(2,"MB2",2);
279  me->setBinLabel(3,"MB3",2);
280  me->setAxisTitle("Sector",1);
281 
282  whME[wheel][fullTag] = me;
283  return;
284  }
285 
286 }
287 
289  string htype, string folder) {
290 
291  stringstream wheel; wheel << chambId.wheel();
292  stringstream station; station << chambId.station();
293  stringstream sector; sector << chambId.sector();
294 
295  string fullType = fullName(htype);
296  bool isDCC = hwSource=="DCC" ;
297  string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
298 
299  ibooker.setCurrentFolder(topFolder(isDCC) +
300  "Wheel" + wheel.str() +
301  "/Sector" + sector.str() +
302  "/Station" + station.str() +
303  "/" + folder + "/");
304 
305  LogTrace(category()) << "[" << testName << "Test]: booking " + topFolder(isDCC) + "Wheel" << wheel.str()
306  <<"/Sector" << sector.str() << "/Station" << station.str() << "/" + folder + "/" << HistoName;
307 
308 
309  uint32_t indexChId = chambId.rawId();
310  float min, max;
311  int nbins;
312  trigGeomUtils->phiRange(chambId,min,max,nbins,20);
313  if (htype.find("TrigEffPosvsAnglePhi") == 0 ){
314 
315  chambME[indexChId][fullType] = ibooker.book2D(HistoName.c_str(),"Trigger efficiency (any qual.) position vs angle (Phi)",12,-30.,30.,nbins,min,max);
316  return;
317  }
318  if (htype.find("TrigEffPosvsAngleCorrPhi") == 0 ){
319 
320  chambME[indexChId][fullType] = ibooker.book2D(HistoName.c_str(),"Trigger efficiency (correlated) pos vs angle (Phi)",12,-30.,30.,nbins,min,max);
321  return;
322  }
323 
324 }
325 
326 
328 
329 
330  vector<string>::const_iterator iTr = trigSources.begin();
331  vector<string>::const_iterator trEnd = trigSources.end();
332  vector<string>::const_iterator iHw = hwSources.begin();
333  vector<string>::const_iterator hwEnd = hwSources.end();
334 
335 
336  //Booking
337  if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
338  for (; iTr != trEnd; ++iTr){
339  trigSource = (*iTr);
340  for (; iHw != hwEnd; ++iHw){
341  hwSource = (*iHw);
342  // Loop over the TriggerUnits
343 
344  bookHistos(ibooker,"TrigEffPhi","");
345  bookHistos(ibooker,"TrigEffCorrPhi","");
346  for (int wh=-2; wh<=2; ++wh){
347  if (detailedPlots) {
348  for (int sect=1; sect<=12; ++sect){
349  for (int stat=1; stat<=4; ++stat){
350  DTChamberId chId(wh,stat,sect);
351 
352  bookChambHistos(ibooker,chId,"TrigEffPosvsAnglePhi","Segment");
353  bookChambHistos(ibooker,chId,"TrigEffPosvsAngleCorrPhi","Segment");
354  }
355  }
356  }
357 
358  bookWheelHistos(ibooker,wh,"TrigEffPhi","");
359  bookWheelHistos(ibooker,wh,"TrigEffCorrPhi","");
360  }
361  }
362  }
363  }
364  bookingdone = 1;
365 }
366 
367 
368 
void makeEfficiencyME(TH2F *numerator, TH2F *denominator, MonitorElement *result2DWh, MonitorElement *result1DWh, MonitorElement *result1D)
Compute 1D/2D efficiency plots.
T getUntrackedParameter(std::string const &, T const &) const
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &)
dictionary parameters
Definition: Parameters.py:2
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &)
Perform client diagnostic in online.
list numerator
Definition: cuy.py:483
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:302
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
void beginRun(edm::Run const &run, edm::EventSetup const &context)
BeginRun.
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
DTTriggerEfficiencyTest(const edm::ParameterSet &ps)
Constructor.
void bookWheelHistos(DQMStore::IBooker &ibooker, int wheel, std::string hTag, std::string folder)
Book the new MEs (for each wheel)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
void runClientDiagnostic(DQMStore::IBooker &, DQMStore::IGetter &)
DQM Client Diagnostic.
virtual ~DTTriggerEfficiencyTest()
Destructor.
void Fill(long long x)
void bookHistos()
Definition: Histogram.h:33
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
list denominator
Definition: cuy.py:484
T sqrt(T t)
Definition: SSEVec.h:48
void bookChambHistos(DQMStore::IBooker &ibooker, DTChamberId chambId, std::string htype, std::string folder="")
Book the new MEs (for each chamber)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
std::string getMEName(std::string histoTag, std::string folder, int wh)
Get the ME name (by wheel)
EventID const & min(EventID const &lh, EventID const &rh)
Definition: EventID.h:137
#define LogTrace(id)
string fullName
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
std::string HistoName
int sector() const
Definition: DTChamberId.h:61
int station() const
Return the station number.
Definition: DTChamberId.h:51
TH2F * getTH2F(void) const
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void bookHistos(DQMStore::IBooker &ibooker, std::string hTag, std::string folder)
Book the new MEs (global)
Definition: Run.h:41
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:142