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 
65  if (!bookingdone) Bookings(ibooker,igetter);
66 
67  // Loop over Trig & Hw sources
68  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
69  trigSource = (*iTr);
70  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
71  hwSource = (*iHw);
72  // Loop over the TriggerUnits
73  if( globalEffDistr.find(fullName("TrigEffPhi")) == globalEffDistr.end() ){
74 
75  bookHistos(ibooker,"TrigEffPhi","");
76  bookHistos(ibooker,"TrigEffCorrPhi","");
77  }
78  for (int wh=-2; wh<=2; ++wh){
79 
80  TH2F * TrigEffDenum = getHisto<TH2F>(igetter.get(getMEName("TrigEffDenum","Task",wh)));
81  TH2F * TrigEffNum = getHisto<TH2F>(igetter.get(getMEName("TrigEffNum","Task",wh)));
82  TH2F * TrigEffCorrNum = getHisto<TH2F>(igetter.get(getMEName("TrigEffCorrNum","Task",wh)));
83 
84  if (TrigEffDenum && TrigEffNum && TrigEffCorrNum && TrigEffDenum->GetEntries()>1) {
85 
86  if( whME[wh].find(fullName("TrigEffPhi")) == whME[wh].end() ){
87 
88  bookWheelHistos(ibooker,wh,"TrigEffPhi","");
89  bookWheelHistos(ibooker,wh,"TrigEffCorrPhi","");
90  }
91 
92  MonitorElement* Eff1DAll_TrigEffPhi = (&globalEffDistr)->find(fullName("TrigEffPhi"))->second;
93  MonitorElement* Eff1DAll_TrigEffCorrPhi = (&globalEffDistr)->find(fullName("TrigEffCorrPhi"))->second;
94 
95  MonitorElement* Eff1DWh_TrigEffPhi = (&(EffDistrPerWh[wh]))->find(fullName("TrigEffPhi"))->second;
96  MonitorElement* Eff1DWh_TrigEffCorrPhi = (&(EffDistrPerWh[wh]))->find(fullName("TrigEffCorrPhi"))->second;
97 
98  MonitorElement* Eff2DWh_TrigEffPhi = (&(whME[wh]))->find(fullName("TrigEffPhi"))->second;
99  MonitorElement* Eff2DWh_TrigEffCorrPhi = (&(whME[wh]))->find(fullName("TrigEffCorrPhi"))->second;
100 
101  makeEfficiencyME(TrigEffNum,TrigEffDenum,Eff2DWh_TrigEffPhi,Eff1DWh_TrigEffPhi,Eff1DAll_TrigEffPhi);
102  makeEfficiencyME(TrigEffCorrNum,TrigEffDenum,Eff2DWh_TrigEffCorrPhi,Eff1DWh_TrigEffCorrPhi,Eff1DAll_TrigEffCorrPhi);
103 
104  }
105 
106  if (detailedPlots) {
107  for (int stat=1; stat<=4; ++stat){
108  for (int sect=1; sect<=12; ++sect){
109  DTChamberId chId(wh,stat,sect);
110  uint32_t indexCh = chId.rawId();
111 
112  // Perform Efficiency analysis (Phi+Segments 2D)
113 
114  TH2F * TrackPosvsAngle = getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngle","Segment", chId)));
115  TH2F * TrackPosvsAngleAnyQual = getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngleAnyQual","Segment", chId)));
116  TH2F * TrackPosvsAngleCorr = getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngleCorr","Segment", chId)));
117 
118  if (TrackPosvsAngle && TrackPosvsAngleAnyQual && TrackPosvsAngleCorr && TrackPosvsAngle->GetEntries()>1) {
119 
120  if( chambME[indexCh].find(fullName("TrigEffAnglePhi")) == chambME[indexCh].end()){
121  bookChambHistos(ibooker,chId,"TrigEffPosvsAnglePhi","Segment");
122  bookChambHistos(ibooker,chId,"TrigEffPosvsAngleCorrPhi","Segment");
123  }
124 
125  std::map<std::string,MonitorElement*> *innerME = &(chambME[indexCh]);
126  makeEfficiencyME(TrackPosvsAngleAnyQual,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAnglePhi"))->second);
127  makeEfficiencyME(TrackPosvsAngleCorr,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAngleCorrPhi"))->second);
128 
129  }
130  }
131  }
132  }
133  }
134 
135  }
136  }
137 
138 }
139 
141 
142  TH2F* efficiency = result2DWh->getTH2F();
143  efficiency->Divide(numerator,denominator,1,1,"");
144 
145  int nbinsx = efficiency->GetNbinsX();
146  int nbinsy = efficiency->GetNbinsY();
147  for (int binx=1; binx<=nbinsx; ++binx){
148  for (int biny=1; biny<=nbinsy; ++biny){
149  float error = 0;
150  float bineff = efficiency->GetBinContent(binx,biny);
151 
152  result1DWh->Fill(bineff);
153  result1D->Fill(bineff);
154 
155  if (denominator->GetBinContent(binx,biny)){
156  error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(binx,biny));
157  }
158  else {
159  error = 1;
160  efficiency->SetBinContent(binx,biny,0.);
161  }
162 
163  efficiency->SetBinError(binx,biny,error);
164  }
165  }
166 
167 }
168 
170 
171  TH2F* efficiency = result2DWh->getTH2F();
172  efficiency->Divide(numerator,denominator,1,1,"");
173 
174  int nbinsx = efficiency->GetNbinsX();
175  int nbinsy = efficiency->GetNbinsY();
176  for (int binx=1; binx<=nbinsx; ++binx){
177  for (int biny=1; biny<=nbinsy; ++biny){
178  float error = 0;
179  float bineff = efficiency->GetBinContent(binx,biny);
180 
181  if (denominator->GetBinContent(binx,biny)){
182  error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(binx,biny));
183  }
184  else {
185  error = 1;
186  efficiency->SetBinContent(binx,biny,0.);
187  }
188 
189  efficiency->SetBinError(binx,biny,error);
190  }
191  }
192 
193 }
194 
195 string DTTriggerEfficiencyTest::getMEName(string histoTag, string folder, int wh) {
196 
197  stringstream wheel; wheel << wh;
198 
199  string folderName = topFolder(hwSource=="DCC") + folder + "/";
200 
201  string histoname = sourceFolder + folderName
202  + fullName(histoTag) + "_W" + wheel.str();
203 
204  return histoname;
205 
206 }
207 
208 void DTTriggerEfficiencyTest::bookHistos(DQMStore::IBooker & ibooker,string hTag,string folder) {
209 
210  string basedir;
211  bool isDCC = hwSource=="DCC" ;
212  basedir = topFolder(isDCC); //Book summary histo outside Task directory
213 
214  if (folder != "") {
215  basedir += folder +"/" ;
216  }
217 
218  ibooker.setCurrentFolder(basedir);
219 
220  string fullTag = fullName(hTag);
221  string hname = fullTag + "_All";
222 
223  globalEffDistr[fullTag] = ibooker.book1D(hname.c_str(),hname.c_str(),51,0.,1.02);
224  globalEffDistr[fullTag] ->setAxisTitle("Trig Eff",1);
225 
226 }
227 
228 void DTTriggerEfficiencyTest::bookWheelHistos(DQMStore::IBooker & ibooker,int wheel,string hTag,string folder) {
229 
230  stringstream wh; wh << wheel;
231  string basedir;
232  bool isDCC = hwSource=="DCC" ;
233  if (hTag.find("Summary") != string::npos) {
234  basedir = topFolder(isDCC); //Book summary histo outside wheel directories
235  } else {
236  basedir = topFolder(isDCC) + "Wheel" + wh.str() + "/" ;
237 
238  }
239  if (folder != "") {
240  basedir += folder +"/" ;
241  }
242 
243  ibooker.setCurrentFolder(basedir);
244 
245  string fullTag = fullName(hTag);
246  string hname = fullTag+ "_W" + wh.str();
247 
248  string hnameAll = fullTag+ "_All_W" + wh.str();
249 
250  LogTrace(category()) << "[" << testName << "Test]: booking "<< basedir << hname;
251 
252  (EffDistrPerWh[wheel])[fullTag] = ibooker.book1D(hnameAll.c_str(),hnameAll.c_str(),51,0.,1.02);
253 
254  if (hTag.find("Phi")!= string::npos ||
255  hTag.find("Summary") != string::npos ){
256 
257  MonitorElement* me = ibooker.book2D(hname.c_str(),hname.c_str(),12,1,13,4,1,5);
258 
259  // setLabelPh(me);
260  me->setBinLabel(1,"MB1",2);
261  me->setBinLabel(2,"MB2",2);
262  me->setBinLabel(3,"MB3",2);
263  me->setBinLabel(4,"MB4",2);
264  me->setAxisTitle("Sector",1);
265 
266  whME[wheel][fullTag] = me;
267  return;
268  }
269 
270  if (hTag.find("Theta") != string::npos){
271 
272  MonitorElement* me =ibooker.book2D(hname.c_str(),hname.c_str(),12,1,13,3,1,4);
273 
274  // setLabelTh(me);
275  me->setBinLabel(1,"MB1",2);
276  me->setBinLabel(2,"MB2",2);
277  me->setBinLabel(3,"MB3",2);
278  me->setAxisTitle("Sector",1);
279 
280  whME[wheel][fullTag] = me;
281  return;
282  }
283 
284 }
285 
287  string htype, string folder) {
288 
289  stringstream wheel; wheel << chambId.wheel();
290  stringstream station; station << chambId.station();
291  stringstream sector; sector << chambId.sector();
292 
293  string fullType = fullName(htype);
294  bool isDCC = hwSource=="DCC" ;
295  string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
296 
297  ibooker.setCurrentFolder(topFolder(isDCC) +
298  "Wheel" + wheel.str() +
299  "/Sector" + sector.str() +
300  "/Station" + station.str() +
301  "/" + folder + "/");
302 
303  LogTrace(category()) << "[" << testName << "Test]: booking " + topFolder(isDCC) + "Wheel" << wheel.str()
304  <<"/Sector" << sector.str() << "/Station" << station.str() << "/" + folder + "/" << HistoName;
305 
306 
307  uint32_t indexChId = chambId.rawId();
308  float min, max;
309  int nbins;
310  trigGeomUtils->phiRange(chambId,min,max,nbins,20);
311  if (htype.find("TrigEffPosvsAnglePhi") == 0 ){
312 
313  chambME[indexChId][fullType] = ibooker.book2D(HistoName.c_str(),"Trigger efficiency (any qual.) position vs angle (Phi)",12,-30.,30.,nbins,min,max);
314  return;
315  }
316  if (htype.find("TrigEffPosvsAngleCorrPhi") == 0 ){
317 
318  chambME[indexChId][fullType] = ibooker.book2D(HistoName.c_str(),"Trigger efficiency (correlated) pos vs angle (Phi)",12,-30.,30.,nbins,min,max);
319  return;
320  }
321 
322 }
323 
324 
326 
327 
328  vector<string>::const_iterator iTr = trigSources.begin();
329  vector<string>::const_iterator trEnd = trigSources.end();
330  vector<string>::const_iterator iHw = hwSources.begin();
331  vector<string>::const_iterator hwEnd = hwSources.end();
332 
333 
334  //Booking
335  if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
336  for (; iTr != trEnd; ++iTr){
337  trigSource = (*iTr);
338  for (; iHw != hwEnd; ++iHw){
339  hwSource = (*iHw);
340  // Loop over the TriggerUnits
341 
342  bookHistos(ibooker,"TrigEffPhi","");
343  bookHistos(ibooker,"TrigEffCorrPhi","");
344  for (int wh=-2; wh<=2; ++wh){
345  if (detailedPlots) {
346  for (int sect=1; sect<=12; ++sect){
347  for (int stat=1; stat<=4; ++stat){
348  DTChamberId chId(wh,stat,sect);
349 
350  bookChambHistos(ibooker,chId,"TrigEffPosvsAnglePhi","Segment");
351  bookChambHistos(ibooker,chId,"TrigEffPosvsAngleCorrPhi","Segment");
352  }
353  }
354  }
355 
356  bookWheelHistos(ibooker,wh,"TrigEffPhi","");
357  bookWheelHistos(ibooker,wh,"TrigEffCorrPhi","");
358  }
359  }
360  }
361  }
362  bookingdone = 1;
363 }
364 
365 
366 
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
dictionary parameters
Definition: Parameters.py:2
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 Bookings(DQMStore::IBooker &, DQMStore::IGetter &)
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