CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DTLocalTriggerEfficiencyTest.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author C. Battilana S. Marcellini - INFN Bologna
5  *
6  * threadsafe version (//-) oct/nov 2014 - WATWanAbdullah ncpp-um-my
7  *
8  */
9 
10 // This class header
12 
13 // Framework headers
17 
18 // Geometry
22 
23 // Root
24 #include "TF1.h"
25 #include "TProfile.h"
26 
27 //C++ headers
28 #include <iostream>
29 #include <sstream>
30 
31 using namespace edm;
32 using namespace std;
33 
35  setConfig(ps, "DTLocalTriggerEfficiency");
36  baseFolderTM = "DT/03-LocalTrigger-TM/";
37 
38  bookingdone = false;
39 }
40 
42  if (trigGeomUtils) {
43  delete trigGeomUtils;
44  }
45 }
46 
50 }
51 
53  vector<string>::const_iterator iTr = trigSources.begin();
54  vector<string>::const_iterator trEnd = trigSources.end();
55  vector<string>::const_iterator iHw = hwSources.begin();
56  vector<string>::const_iterator hwEnd = hwSources.end();
57 
58  //Booking
59  if (parameters.getUntrackedParameter<bool>("staticBooking", true)) {
60  for (; iTr != trEnd; ++iTr) {
61  trigSource = (*iTr);
62  for (; iHw != hwEnd; ++iHw) {
63  hwSource = (*iHw);
64  // Loop over the TriggerUnits
65  for (int wh = -2; wh <= 2; ++wh) {
66  for (int sect = 1; sect <= 12; ++sect) {
67  for (int stat = 1; stat <= 4; ++stat) {
68  DTChamberId chId(wh, stat, sect);
69  bookChambHistos(ibooker, chId, "TrigEffPosvsAnglePhi");
70  bookChambHistos(ibooker, chId, "TrigEffPosvsAngleHHHLPhi");
71  bookChambHistos(ibooker, chId, "TrigEffPosPhi");
72  bookChambHistos(ibooker, chId, "TrigEffPosHHHLPhi");
73  bookChambHistos(ibooker, chId, "TrigEffAnglePhi");
74  bookChambHistos(ibooker, chId, "TrigEffAngleHHHLPhi");
75  if (stat <= 3) {
76  bookChambHistos(ibooker, chId, "TrigEffPosvsAngleTheta");
77  bookChambHistos(ibooker, chId, "TrigEffPosvsAngleHTheta");
78  bookChambHistos(ibooker, chId, "TrigEffPosTheta");
79  bookChambHistos(ibooker, chId, "TrigEffPosHTheta");
80  bookChambHistos(ibooker, chId, "TrigEffAngleTheta");
81  bookChambHistos(ibooker, chId, "TrigEffAngleHTheta");
82  }
83  }
84 
85  bookSectorHistos(ibooker, wh, sect, "TrigEffPhi");
86  bookSectorHistos(ibooker, wh, sect, "TrigEffTheta");
87  }
88 
89  bookWheelHistos(ibooker, wh, "TrigEffPhi");
90  bookWheelHistos(ibooker, wh, "TrigEffHHHLPhi");
91  bookWheelHistos(ibooker, wh, "TrigEffTheta");
92  bookWheelHistos(ibooker, wh, "TrigEffHTheta");
93  }
94  }
95  }
96  }
97 
98  bookingdone = true;
99 }
100 
102  if (!bookingdone)
103  Bookings(ibooker, igetter);
104 
105  // Loop over Trig & Hw sources
106  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr) {
107  trigSource = (*iTr);
108  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw) {
109  hwSource = (*iHw);
110  // Loop over the TriggerUnits
111  for (int stat = 1; stat <= 4; ++stat) {
112  for (int wh = -2; wh <= 2; ++wh) {
113  for (int sect = 1; sect <= 12; ++sect) {
114  DTChamberId chId(wh, stat, sect);
115  int sector_id = (wh + wheelArrayShift) + (sect - 1) * 5;
116  uint32_t indexCh = chId.rawId();
117 
118  TH2F* TrackPosvsAngle = getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngle", "Segment", chId)));
119  TH2F* TrackPosvsAngleandTrig =
120  getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngleandTrig", "Segment", chId)));
121  TH2F* TrackPosvsAngleandTrigHHHL =
122  getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngleandTrigHHHL", "Segment", chId)));
123 
124  if (TrackPosvsAngle && TrackPosvsAngleandTrig && TrackPosvsAngleandTrigHHHL &&
125  TrackPosvsAngle->GetEntries() > 1) {
126  if (chambME[indexCh].find(fullName("TrigEffAnglePhi")) == chambME[indexCh].end()) {
127  bookChambHistos(ibooker, chId, "TrigEffPosvsAnglePhi");
128  bookChambHistos(ibooker, chId, "TrigEffPosvsAngleHHHLPhi");
129  bookChambHistos(ibooker, chId, "TrigEffPosPhi");
130  bookChambHistos(ibooker, chId, "TrigEffPosHHHLPhi");
131  bookChambHistos(ibooker, chId, "TrigEffAnglePhi");
132  bookChambHistos(ibooker, chId, "TrigEffAngleHHHLPhi");
133  }
134  if (secME[sector_id].find(fullName("TrigEffPhi")) == secME[sector_id].end()) {
135  bookSectorHistos(ibooker, wh, sect, "TrigEffPhi");
136  }
137  if (whME[wh].find(fullName("TrigEffPhi")) == whME[wh].end()) {
138  bookWheelHistos(ibooker, wh, "TrigEffPhi");
139  bookWheelHistos(ibooker, wh, "TrigEffHHHLPhi");
140  }
141 
142  std::map<std::string, MonitorElement*>* innerME = &(secME[sector_id]);
143  TH1D* TrackPos = TrackPosvsAngle->ProjectionY();
144  TH1D* TrackAngle = TrackPosvsAngle->ProjectionX();
145  TH1D* TrackPosandTrig = TrackPosvsAngleandTrig->ProjectionY();
146  TH1D* TrackAngleandTrig = TrackPosvsAngleandTrig->ProjectionX();
147  TH1D* TrackPosandTrigHHHL = TrackPosvsAngleandTrigHHHL->ProjectionY();
148  TH1D* TrackAngleandTrigHHHL = TrackPosvsAngleandTrigHHHL->ProjectionX();
149  float binEff = float(TrackPosandTrig->GetEntries()) / TrackPos->GetEntries();
150  float binEffHHHL = float(TrackPosandTrigHHHL->GetEntries()) / TrackPos->GetEntries();
151  float binErr = sqrt(binEff * (1 - binEff) / TrackPos->GetEntries());
152  float binErrHHHL = sqrt(binEffHHHL * (1 - binEffHHHL) / TrackPos->GetEntries());
153 
154  MonitorElement* globalEff = innerME->find(fullName("TrigEffPhi"))->second;
155  globalEff->setBinContent(stat, binEff);
156  globalEff->setBinError(stat, binErr);
157 
158  innerME = &(whME[wh]);
159  globalEff = innerME->find(fullName("TrigEffPhi"))->second;
160  globalEff->setBinContent(sect, stat, binEff);
161  globalEff->setBinError(sect, stat, binErr);
162  globalEff = innerME->find(fullName("TrigEffHHHLPhi"))->second;
163  globalEff->setBinContent(sect, stat, binEffHHHL);
164  globalEff->setBinError(sect, stat, binErrHHHL);
165 
166  innerME = &(chambME[indexCh]);
167  makeEfficiencyME(TrackPosandTrig, TrackPos, innerME->find(fullName("TrigEffPosPhi"))->second);
168  makeEfficiencyME(TrackPosandTrigHHHL, TrackPos, innerME->find(fullName("TrigEffPosHHHLPhi"))->second);
169  makeEfficiencyME(TrackAngleandTrig, TrackAngle, innerME->find(fullName("TrigEffAnglePhi"))->second);
171  TrackAngleandTrigHHHL, TrackAngle, innerME->find(fullName("TrigEffAngleHHHLPhi"))->second);
173  TrackPosvsAngleandTrig, TrackPosvsAngle, innerME->find(fullName("TrigEffPosvsAnglePhi"))->second);
174  makeEfficiencyME2D(TrackPosvsAngleandTrigHHHL,
175  TrackPosvsAngle,
176  innerME->find(fullName("TrigEffPosvsAngleHHHLPhi"))->second);
177  }
178 
179  // Perform Efficiency analysis (Theta+Segments) CB FIXME -> no TM theta qual info
180  TH2F* TrackThetaPosvsAngle =
181  getHisto<TH2F>(igetter.get(getMEName("TrackThetaPosvsAngle", "Segment", chId)));
182  TH2F* TrackThetaPosvsAngleandTrig =
183  getHisto<TH2F>(igetter.get(getMEName("TrackThetaPosvsAngleandTrig", "Segment", chId)));
184  TH2F* TrackThetaPosvsAngleandTrigH =
185  getHisto<TH2F>(igetter.get(getMEName("TrackThetaPosvsAngleandTrigH", "Segment", chId)));
186 
187  if (TrackThetaPosvsAngle && TrackThetaPosvsAngleandTrig && TrackThetaPosvsAngleandTrigH &&
188  TrackThetaPosvsAngle->GetEntries() > 1) {
189  if (chambME[indexCh].find(fullName("TrigEffAngleTheta")) == chambME[indexCh].end()) {
190  bookChambHistos(ibooker, chId, "TrigEffPosvsAngleTheta");
191  bookChambHistos(ibooker, chId, "TrigEffPosvsAngleHTheta");
192  bookChambHistos(ibooker, chId, "TrigEffPosTheta");
193  bookChambHistos(ibooker, chId, "TrigEffPosHTheta");
194  bookChambHistos(ibooker, chId, "TrigEffAngleTheta");
195  bookChambHistos(ibooker, chId, "TrigEffAngleHTheta");
196  }
197  if (secME[sector_id].find(fullName("TrigEffTheta")) == secME[sector_id].end()) {
198  bookSectorHistos(ibooker, wh, sect, "TrigEffTheta");
199  }
200  if (whME[wh].find(fullName("TrigEffTheta")) == whME[wh].end()) {
201  bookWheelHistos(ibooker, wh, "TrigEffTheta");
202  bookWheelHistos(ibooker, wh, "TrigEffHTheta");
203  }
204 
205  std::map<std::string, MonitorElement*>* innerME = &(secME[sector_id]);
206  TH1D* TrackThetaPos = TrackThetaPosvsAngle->ProjectionY();
207  TH1D* TrackThetaAngle = TrackThetaPosvsAngle->ProjectionX();
208  TH1D* TrackThetaPosandTrig = TrackThetaPosvsAngleandTrig->ProjectionY();
209  TH1D* TrackThetaAngleandTrig = TrackThetaPosvsAngleandTrig->ProjectionX();
210  TH1D* TrackThetaPosandTrigH = TrackThetaPosvsAngleandTrigH->ProjectionY();
211  TH1D* TrackThetaAngleandTrigH = TrackThetaPosvsAngleandTrigH->ProjectionX();
212  float binEff = float(TrackThetaPosandTrig->GetEntries()) / TrackThetaPos->GetEntries();
213  float binErr = sqrt(binEff * (1 - binEff) / TrackThetaPos->GetEntries());
214  float binEffH = float(TrackThetaPosandTrigH->GetEntries()) / TrackThetaPos->GetEntries();
215  float binErrH = sqrt(binEffH * (1 - binEffH) / TrackThetaPos->GetEntries());
216 
217  MonitorElement* globalEff = innerME->find(fullName("TrigEffTheta"))->second;
218  globalEff->setBinContent(stat, binEff);
219  globalEff->setBinError(stat, binErr);
220 
221  innerME = &(whME[wh]);
222  globalEff = innerME->find(fullName("TrigEffTheta"))->second;
223  globalEff->setBinContent(sect, stat, binEff);
224  globalEff->setBinError(sect, stat, binErr);
225  globalEff = innerME->find(fullName("TrigEffHTheta"))->second;
226  globalEff->setBinContent(sect, stat, binEffH);
227  globalEff->setBinError(sect, stat, binErrH);
228 
229  innerME = &(chambME[indexCh]);
230  makeEfficiencyME(TrackThetaPosandTrig, TrackThetaPos, innerME->find(fullName("TrigEffPosTheta"))->second);
232  TrackThetaPosandTrigH, TrackThetaPos, innerME->find(fullName("TrigEffPosHTheta"))->second);
234  TrackThetaAngleandTrig, TrackThetaAngle, innerME->find(fullName("TrigEffAngleTheta"))->second);
236  TrackThetaAngleandTrigH, TrackThetaAngle, innerME->find(fullName("TrigEffAngleHTheta"))->second);
237  makeEfficiencyME2D(TrackThetaPosvsAngleandTrig,
238  TrackThetaPosvsAngle,
239  innerME->find(fullName("TrigEffPosvsAngleTheta"))->second);
240  makeEfficiencyME2D(TrackThetaPosvsAngleandTrigH,
241  TrackThetaPosvsAngle,
242  innerME->find(fullName("TrigEffPosvsAngleHTheta"))->second);
243  }
244  }
245  }
246  }
247  }
248  }
249 }
250 
252  TH1F* efficiency = result->getTH1F();
253  efficiency->Divide(numerator, denominator, 1, 1, "");
254 
255  int nbins = efficiency->GetNbinsX();
256  for (int bin = 1; bin <= nbins; ++bin) {
257  float error = 0;
258  float bineff = efficiency->GetBinContent(bin);
259 
260  if (denominator->GetBinContent(bin)) {
261  error = sqrt(bineff * (1 - bineff) / denominator->GetBinContent(bin));
262  } else {
263  error = 1;
264  efficiency->SetBinContent(bin, 1.);
265  }
266 
267  efficiency->SetBinError(bin, error);
268  }
269 }
270 
272  TH2F* efficiency = result->getTH2F();
273  efficiency->Divide(numerator, denominator, 1, 1, "");
274 
275  int nbinsx = efficiency->GetNbinsX();
276  int nbinsy = efficiency->GetNbinsY();
277  for (int binx = 1; binx <= nbinsx; ++binx) {
278  for (int biny = 1; biny <= nbinsy; ++biny) {
279  float error = 0;
280  float bineff = efficiency->GetBinContent(binx, biny);
281 
282  if (denominator->GetBinContent(binx, biny)) {
283  error = sqrt(bineff * (1 - bineff) / denominator->GetBinContent(binx, biny));
284  } else {
285  error = 1;
286  efficiency->SetBinContent(binx, biny, 0.);
287  }
288 
289  efficiency->SetBinError(binx, biny, error);
290  }
291  }
292 }
293 
295  stringstream wheel;
296  wheel << chambId.wheel();
297  stringstream station;
298  station << chambId.station();
299  stringstream sector;
300  sector << chambId.sector();
301 
302  string fullType = fullName(htype);
303  string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
304 
305  ibooker.setCurrentFolder(topFolder() + "Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str() +
306  "/Segment");
307 
308  LogTrace(category()) << "[" << testName << "Test]: booking " + topFolder() + "Wheel" << wheel.str() << "/Sector"
309  << sector.str() << "/Station" << station.str() << "/Segment/" << HistoName;
310 
311  uint32_t indexChId = chambId.rawId();
312  if (htype.find("TrigEffAnglePhi") == 0) {
313  chambME[indexChId][fullType] =
314  ibooker.book1D(HistoName.c_str(), "Trigger efficiency vs angle of incidence (Phi)", 16, -40., 40.);
315  } else if (htype.find("TrigEffAngleHHHLPhi") == 0) {
316  chambME[indexChId][fullType] =
317  ibooker.book1D(HistoName.c_str(), "Trigger efficiency (HH/HL) vs angle of incidence (Phi)", 16, -40., 40.);
318  } else if (htype.find("TrigEffAngleTheta") == 0) {
319  chambME[indexChId][fullType] =
320  ibooker.book1D(HistoName.c_str(), "Trigger efficiency vs angle of incidence (Theta)", 16, -40., 40.);
321  } else if (htype.find("TrigEffAngleHTheta") == 0) {
322  chambME[indexChId][fullType] =
323  ibooker.book1D(HistoName.c_str(), "Trigger efficiency (H) vs angle of incidence (Theta)", 16, -40., 40.);
324  } else if (htype.find("TrigEffPosPhi") == 0) {
325  float min, max;
326  int nbins;
327  trigGeomUtils->phiRange(chambId, min, max, nbins);
328  chambME[indexChId][fullType] =
329  ibooker.book1D(HistoName.c_str(), "Trigger efficiency vs position (Phi)", nbins, min, max);
330  } else if (htype.find("TrigEffPosvsAnglePhi") == 0) {
331  float min, max;
332  int nbins;
333  trigGeomUtils->phiRange(chambId, min, max, nbins);
334  chambME[indexChId][fullType] =
335  ibooker.book2D(HistoName.c_str(), "Trigger efficiency position vs angle (Phi)", 16, -40., 40., nbins, min, max);
336  } else if (htype.find("TrigEffPosvsAngleHHHLPhi") == 0) {
337  float min, max;
338  int nbins;
339  trigGeomUtils->phiRange(chambId, min, max, nbins);
340  chambME[indexChId][fullType] = ibooker.book2D(
341  HistoName.c_str(), "Trigger efficiency (HH/HL) pos vs angle (Phi)", 16, -40., 40., nbins, min, max);
342  } else if (htype.find("TrigEffPosHHHLPhi") == 0) {
343  float min, max;
344  int nbins;
345  trigGeomUtils->phiRange(chambId, min, max, nbins);
346  chambME[indexChId][fullType] =
347  ibooker.book1D(HistoName.c_str(), "Trigger efficiency (HH/HL) vs position (Phi)", nbins, min, max);
348  } else if (htype.find("TrigEffPosTheta") == 0) {
349  float min, max;
350  int nbins;
351  trigGeomUtils->thetaRange(chambId, min, max, nbins);
352  chambME[indexChId][fullType] =
353  ibooker.book1D(HistoName.c_str(), "Trigger efficiency vs position (Theta)", nbins, min, max);
354  } else if (htype.find("TrigEffPosHTheta") == 0) {
355  float min, max;
356  int nbins;
357  trigGeomUtils->thetaRange(chambId, min, max, nbins);
358  chambME[indexChId][fullType] =
359  ibooker.book1D(HistoName.c_str(), "Trigger efficiency (H) vs position (Theta)", nbins, min, max);
360  } else if (htype.find("TrigEffPosvsAngleTheta") == 0) {
361  float min, max;
362  int nbins;
363  trigGeomUtils->thetaRange(chambId, min, max, nbins);
364  chambME[indexChId][fullType] =
365  ibooker.book2D(HistoName.c_str(), "Trigger efficiency pos vs angle (Theta)", 16, -40., 40., nbins, min, max);
366  } else if (htype.find("TrigEffPosvsAngleHTheta") == 0) {
367  float min, max;
368  int nbins;
369  trigGeomUtils->thetaRange(chambId, min, max, nbins);
370  chambME[indexChId][fullType] = ibooker.book2D(
371  HistoName.c_str(), "Trigger efficiency (H) pos vs angle (Theta)", 16, -40., 40., nbins, min, max);
372  }
373 }
std::map< uint32_t, std::map< std::string, MonitorElement * > > chambME
T getUntrackedParameter(std::string const &, T const &) const
std::vector< std::string > trigSources
virtual TH2F * getTH2F() const
const edm::EventSetup & c
void thetaRange(const DTChamberId &id, float &min, float &max, int &nbins, float step=15)
Compute theta range in local chamber coordinates.
std::string & topFolder()
Get top folder name.
list numerator
Definition: cuy.py:484
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
void makeEfficiencyME(TH1D *numerator, TH1D *denominator, MonitorElement *result)
Compute efficiency plots.
void Bookings(DQMStore::IBooker &, DQMStore::IGetter &)
virtual TH1F * getTH1F() const
void makeEfficiencyME2D(TH2F *numerator, TH2F *denominator, MonitorElement *result)
Compute 2D efficiency plots.
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
#define LogTrace(id)
tuple result
Definition: mps_fire.py:311
std::map< int, std::map< std::string, MonitorElement * > > whME
list denominator
Definition: cuy.py:485
~DTLocalTriggerEfficiencyTest() override
Destructor.
void bookChambHistos(DQMStore::IBooker &, DTChamberId chambId, std::string htype)
Book the new MEs (for each chamber)
T sqrt(T t)
Definition: SSEVec.h:19
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:673
T min(T a, T b)
Definition: MathUtil.h:58
void runClientDiagnostic(DQMStore::IBooker &, DQMStore::IGetter &) override
DQM Client Diagnostic.
DTLocalTriggerEfficiencyTest(const edm::ParameterSet &ps)
Constructor.
std::string category()
Get message logger name.
void phiRange(const DTChamberId &id, float &min, float &max, int &nbins, float step=15)
Compute phi range in local chamber coordinates.
void beginRun(edm::Run const &run, edm::EventSetup const &context) override
BeginRun.
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
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:177
std::string HistoName
std::string getMEName(std::string histoTag, std::string subfolder, const DTChamberId &chambid)
Get the ME name (by chamber)
void bookSectorHistos(DQMStore::IBooker &, int wheel, int sector, std::string hTag, std::string folder="")
Book the new MEs (for each sector)
int sector() const
Definition: DTChamberId.h:49
string end
Definition: dataset.py:937
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
BeginRun.
void setConfig(const edm::ParameterSet &ps, std::string name)
Set configuration variables.
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
int station() const
Return the station number.
Definition: DTChamberId.h:42
std::vector< std::string > hwSources
std::map< int, std::map< std::string, MonitorElement * > > secME
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
void bookWheelHistos(DQMStore::IBooker &, int wheel, std::string hTag, std::string folder="")
Book the new MEs (for each wheel)
std::string fullName(std::string htype)
Create fullname from histo partial name.
Definition: Run.h:45