CMS 3D CMS Logo

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