CMS 3D CMS Logo

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