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  baseFolderDCC = "DT/03-LocalTrigger-DCC/";
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  edm::LuminosityBlock const & lumiSeg, edm::EventSetup const & context) {
68 
69  if (bookingdone) return;
70 
71  vector<string>::const_iterator iTr = trigSources.begin();
72  vector<string>::const_iterator trEnd = trigSources.end();
73  vector<string>::const_iterator iHw = hwSources.begin();
74  vector<string>::const_iterator hwEnd = hwSources.end();
75 
76 
77  //Booking
78  if(parameters.getUntrackedParameter<bool>("staticBooking", true)){
79  for (; iTr != trEnd; ++iTr){
80  trigSource = (*iTr);
81  for (; iHw != hwEnd; ++iHw){
82  hwSource = (*iHw);
83  // Loop over the TriggerUnits
84  for (int wh=-2; wh<=2; ++wh){
85  for (int sect=1; sect<=12; ++sect){
86  for (int stat=1; stat<=4; ++stat){
87  DTChamberId chId(wh,stat,sect);
88  bookChambHistos(ibooker,chId,"TrigEffPosvsAnglePhi");
89  bookChambHistos(ibooker,chId,"TrigEffPosvsAngleHHHLPhi");
90  bookChambHistos(ibooker,chId,"TrigEffPosPhi");
91  bookChambHistos(ibooker,chId,"TrigEffPosHHHLPhi");
92  bookChambHistos(ibooker,chId,"TrigEffAnglePhi");
93  bookChambHistos(ibooker,chId,"TrigEffAngleHHHLPhi");
94  if (stat<=3) {
95  bookChambHistos(ibooker,chId,"TrigEffPosvsAngleTheta");
96  bookChambHistos(ibooker,chId,"TrigEffPosvsAngleHTheta");
97  bookChambHistos(ibooker,chId,"TrigEffPosTheta");
98  bookChambHistos(ibooker,chId,"TrigEffPosHTheta");
99  bookChambHistos(ibooker,chId,"TrigEffAngleTheta");
100  bookChambHistos(ibooker,chId,"TrigEffAngleHTheta");
101  }
102  }
103 
104  bookSectorHistos(ibooker,wh,sect,"TrigEffPhi");
105  bookSectorHistos(ibooker,wh,sect,"TrigEffTheta");
106  }
107 
108  bookWheelHistos(ibooker,wh,"TrigEffPhi");
109  bookWheelHistos(ibooker,wh,"TrigEffHHHLPhi");
110  bookWheelHistos(ibooker,wh,"TrigEffTheta");
111  bookWheelHistos(ibooker,wh,"TrigEffHTheta");
112  }
113  }
114  }
115  }
116 
117  bookingdone = 1;
118 }
119 
121  DQMStore::IGetter & igetter) {
122 
123  // Loop over Trig & Hw sources
124  for (vector<string>::const_iterator iTr = trigSources.begin(); iTr != trigSources.end(); ++iTr){
125  trigSource = (*iTr);
126  for (vector<string>::const_iterator iHw = hwSources.begin(); iHw != hwSources.end(); ++iHw){
127  hwSource = (*iHw);
128  // Loop over the TriggerUnits
129  for (int stat=1; stat<=4; ++stat){
130  for (int wh=-2; wh<=2; ++wh){
131  for (int sect=1; sect<=12; ++sect){
132  DTChamberId chId(wh,stat,sect);
133  int sector_id = (wh+3)+(sect-1)*5;
134  uint32_t indexCh = chId.rawId();
135 
136 
137  TH2F * TrackPosvsAngle = getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngle","Segment", chId)));
138  TH2F * TrackPosvsAngleandTrig = getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngleandTrig","Segment", chId)));
139  TH2F * TrackPosvsAngleandTrigHHHL = getHisto<TH2F>(igetter.get(getMEName("TrackPosvsAngleandTrigHHHL","Segment", chId)));
140 
141  if (TrackPosvsAngle && TrackPosvsAngleandTrig && TrackPosvsAngleandTrigHHHL && TrackPosvsAngle->GetEntries()>1) {
142 
143  if( chambME[indexCh].find(fullName("TrigEffAnglePhi")) == chambME[indexCh].end()){
144 
145  bookChambHistos(ibooker,chId,"TrigEffPosvsAnglePhi");
146  bookChambHistos(ibooker,chId,"TrigEffPosvsAngleHHHLPhi");
147  bookChambHistos(ibooker,chId,"TrigEffPosPhi");
148  bookChambHistos(ibooker,chId,"TrigEffPosHHHLPhi");
149  bookChambHistos(ibooker,chId,"TrigEffAnglePhi");
150  bookChambHistos(ibooker,chId,"TrigEffAngleHHHLPhi");
151  }
152  if( secME[sector_id].find(fullName("TrigEffPhi")) == secME[sector_id].end() ){
153 
154  bookSectorHistos(ibooker,wh,sect,"TrigEffPhi");
155  }
156  if( whME[wh].find(fullName("TrigEffPhi")) == whME[wh].end() ){
157 
158  bookWheelHistos(ibooker,wh,"TrigEffPhi");
159  bookWheelHistos(ibooker,wh,"TrigEffHHHLPhi");
160  }
161 
162  std::map<std::string,MonitorElement*> *innerME = &(secME[sector_id]);
163  TH1D* TrackPos = TrackPosvsAngle->ProjectionY();
164  TH1D* TrackAngle = TrackPosvsAngle->ProjectionX();
165  TH1D* TrackPosandTrig = TrackPosvsAngleandTrig->ProjectionY();
166  TH1D* TrackAngleandTrig = TrackPosvsAngleandTrig->ProjectionX();
167  TH1D* TrackPosandTrigHHHL = TrackPosvsAngleandTrigHHHL->ProjectionY();
168  TH1D* TrackAngleandTrigHHHL = TrackPosvsAngleandTrigHHHL->ProjectionX();
169  float binEff = float(TrackPosandTrig->GetEntries())/TrackPos->GetEntries();
170  float binEffHHHL = float(TrackPosandTrigHHHL->GetEntries())/TrackPos->GetEntries();
171  float binErr = sqrt(binEff*(1-binEff)/TrackPos->GetEntries());
172  float binErrHHHL = sqrt(binEffHHHL*(1-binEffHHHL)/TrackPos->GetEntries());
173 
174  MonitorElement* globalEff = innerME->find(fullName("TrigEffPhi"))->second;
175  globalEff->setBinContent(stat,binEff);
176  globalEff->setBinError(stat,binErr);
177 
178  innerME = &(whME[wh]);
179  globalEff = innerME->find(fullName("TrigEffPhi"))->second;
180  globalEff->setBinContent(sect,stat,binEff);
181  globalEff->setBinError(sect,stat,binErr);
182  globalEff = innerME->find(fullName("TrigEffHHHLPhi"))->second;
183  globalEff->setBinContent(sect,stat,binEffHHHL);
184  globalEff->setBinError(sect,stat,binErrHHHL);
185 
186 
187  innerME = &(chambME[indexCh]);
188  makeEfficiencyME(TrackPosandTrig,TrackPos,innerME->find(fullName("TrigEffPosPhi"))->second);
189  makeEfficiencyME(TrackPosandTrigHHHL,TrackPos,innerME->find(fullName("TrigEffPosHHHLPhi"))->second);
190  makeEfficiencyME(TrackAngleandTrig,TrackAngle,innerME->find(fullName("TrigEffAnglePhi"))->second);
191  makeEfficiencyME(TrackAngleandTrigHHHL,TrackAngle,innerME->find(fullName("TrigEffAngleHHHLPhi"))->second);
192  makeEfficiencyME2D(TrackPosvsAngleandTrig,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAnglePhi"))->second);
193  makeEfficiencyME2D(TrackPosvsAngleandTrigHHHL,TrackPosvsAngle,innerME->find(fullName("TrigEffPosvsAngleHHHLPhi"))->second);
194 
195  }
196 
197  // Perform Efficiency analysis (Theta+Segments) CB FIXME -> no DCC theta qual info
198  TH2F * TrackThetaPosvsAngle = getHisto<TH2F>(igetter.get(getMEName("TrackThetaPosvsAngle","Segment", chId)));
199  TH2F * TrackThetaPosvsAngleandTrig = getHisto<TH2F>(igetter.get(getMEName("TrackThetaPosvsAngleandTrig","Segment", chId)));
200  TH2F * TrackThetaPosvsAngleandTrigH = getHisto<TH2F>(igetter.get(getMEName("TrackThetaPosvsAngleandTrigH","Segment", chId)));
201 
202  if (TrackThetaPosvsAngle && TrackThetaPosvsAngleandTrig && TrackThetaPosvsAngleandTrigH && TrackThetaPosvsAngle->GetEntries()>1) {
203 
204  if( chambME[indexCh].find(fullName("TrigEffAngleTheta")) == chambME[indexCh].end()){
205 
206  bookChambHistos(ibooker,chId,"TrigEffPosvsAngleTheta");
207  bookChambHistos(ibooker,chId,"TrigEffPosvsAngleHTheta");
208  bookChambHistos(ibooker,chId,"TrigEffPosTheta");
209  bookChambHistos(ibooker,chId,"TrigEffPosHTheta");
210  bookChambHistos(ibooker,chId,"TrigEffAngleTheta");
211  bookChambHistos(ibooker,chId,"TrigEffAngleHTheta");
212  }
213  if( secME[sector_id].find(fullName("TrigEffTheta")) == secME[sector_id].end() ){
214  bookSectorHistos(ibooker,wh,sect,"TrigEffTheta");
215  }
216  if( whME[wh].find(fullName("TrigEffTheta")) == whME[wh].end() ){
217  bookWheelHistos(ibooker,wh,"TrigEffTheta");
218  bookWheelHistos(ibooker,wh,"TrigEffHTheta");
219  }
220 
221 
222  std::map<std::string,MonitorElement*> *innerME = &(secME[sector_id]);
223  TH1D* TrackThetaPos = TrackThetaPosvsAngle->ProjectionY();
224  TH1D* TrackThetaAngle = TrackThetaPosvsAngle->ProjectionX();
225  TH1D* TrackThetaPosandTrig = TrackThetaPosvsAngleandTrig->ProjectionY();
226  TH1D* TrackThetaAngleandTrig = TrackThetaPosvsAngleandTrig->ProjectionX();
227  TH1D* TrackThetaPosandTrigH = TrackThetaPosvsAngleandTrigH->ProjectionY();
228  TH1D* TrackThetaAngleandTrigH = TrackThetaPosvsAngleandTrigH->ProjectionX();
229  float binEff = float(TrackThetaPosandTrig->GetEntries())/TrackThetaPos->GetEntries();
230  float binErr = sqrt(binEff*(1-binEff)/TrackThetaPos->GetEntries());
231  float binEffH = float(TrackThetaPosandTrigH->GetEntries())/TrackThetaPos->GetEntries();
232  float binErrH = sqrt(binEffH*(1-binEffH)/TrackThetaPos->GetEntries());
233 
234  MonitorElement* globalEff = innerME->find(fullName("TrigEffTheta"))->second;
235  globalEff->setBinContent(stat,binEff);
236  globalEff->setBinError(stat,binErr);
237 
238  innerME = &(whME[wh]);
239  globalEff = innerME->find(fullName("TrigEffTheta"))->second;
240  globalEff->setBinContent(sect,stat,binEff);
241  globalEff->setBinError(sect,stat,binErr);
242  globalEff = innerME->find(fullName("TrigEffHTheta"))->second;
243  globalEff->setBinContent(sect,stat,binEffH);
244  globalEff->setBinError(sect,stat,binErrH);
245 
246  innerME = &(chambME[indexCh]);
247  makeEfficiencyME(TrackThetaPosandTrig,TrackThetaPos,innerME->find(fullName("TrigEffPosTheta"))->second);
248  makeEfficiencyME(TrackThetaPosandTrigH,TrackThetaPos,innerME->find(fullName("TrigEffPosHTheta"))->second);
249  makeEfficiencyME(TrackThetaAngleandTrig,TrackThetaAngle,innerME->find(fullName("TrigEffAngleTheta"))->second);
250  makeEfficiencyME(TrackThetaAngleandTrigH,TrackThetaAngle,innerME->find(fullName("TrigEffAngleHTheta"))->second);
251  makeEfficiencyME2D(TrackThetaPosvsAngleandTrig,TrackThetaPosvsAngle,innerME->find(fullName("TrigEffPosvsAngleTheta"))->second);
252  makeEfficiencyME2D(TrackThetaPosvsAngleandTrigH,TrackThetaPosvsAngle,innerME->find(fullName("TrigEffPosvsAngleHTheta"))->second);
253  }
254 
255  }
256  }
257  }
258  }
259  }
260 
261 }
262 
263 
265 
266  TH1F* efficiency = result->getTH1F();
267  efficiency->Divide(numerator,denominator,1,1,"");
268 
269  int nbins = efficiency->GetNbinsX();
270  for (int bin=1; bin<=nbins; ++bin){
271  float error = 0;
272  float bineff = efficiency->GetBinContent(bin);
273 
274  if (denominator->GetBinContent(bin)){
275  error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(bin));
276  }
277  else {
278  error = 1;
279  efficiency->SetBinContent(bin,1.);
280  }
281 
282  efficiency->SetBinError(bin,error);
283  }
284 
285 }
286 
287 
289 
290  TH2F* efficiency = result->getTH2F();
291  efficiency->Divide(numerator,denominator,1,1,"");
292 
293  int nbinsx = efficiency->GetNbinsX();
294  int nbinsy = efficiency->GetNbinsY();
295  for (int binx=1; binx<=nbinsx; ++binx){
296  for (int biny=1; biny<=nbinsy; ++biny){
297  float error = 0;
298  float bineff = efficiency->GetBinContent(binx,biny);
299 
300  if (denominator->GetBinContent(binx,biny)){
301  error = sqrt(bineff*(1-bineff)/denominator->GetBinContent(binx,biny));
302  }
303  else {
304  error = 1;
305  efficiency->SetBinContent(binx,biny,0.);
306  }
307 
308  efficiency->SetBinError(binx,biny,error);
309  }
310  }
311 
312 }
313 
315 
316  stringstream wheel; wheel << chambId.wheel();
317  stringstream station; station << chambId.station();
318  stringstream sector; sector << chambId.sector();
319 
320  string fullType = fullName(htype);
321  bool isDCC = hwSource=="DCC" ;
322  string HistoName = fullType + "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
323 
324  ibooker.setCurrentFolder(topFolder(isDCC) + "Wheel" + wheel.str() +
325  "/Sector" + sector.str() +
326  "/Station" + station.str() + "/Segment");
327 
328  LogTrace(category()) << "[" << testName << "Test]: booking " + topFolder(isDCC) + "Wheel" << wheel.str()
329  <<"/Sector" << sector.str() << "/Station" << station.str() << "/Segment/" << HistoName;
330 
331 
332  uint32_t indexChId = chambId.rawId();
333  if (htype.find("TrigEffAnglePhi") == 0){
334  chambME[indexChId][fullType] = ibooker.book1D(HistoName.c_str(),"Trigger efficiency vs angle of incidence (Phi)",16,-40.,40.);
335  }
336  else if (htype.find("TrigEffAngleHHHLPhi") == 0){
337  chambME[indexChId][fullType] = ibooker.book1D(HistoName.c_str(),"Trigger efficiency (HH/HL) vs angle of incidence (Phi)",16,-40.,40.);
338  }
339  else if (htype.find("TrigEffAngleTheta") == 0){
340  chambME[indexChId][fullType] = ibooker.book1D(HistoName.c_str(),"Trigger efficiency vs angle of incidence (Theta)",16,-40.,40.);
341  }
342  else if (htype.find("TrigEffAngleHTheta") == 0){
343  chambME[indexChId][fullType] = ibooker.book1D(HistoName.c_str(),"Trigger efficiency (H) vs angle of incidence (Theta)",16,-40.,40.);
344  }
345  else if (htype.find("TrigEffPosPhi") == 0 ){
346  float min,max;
347  int nbins;
348  trigGeomUtils->phiRange(chambId,min,max,nbins);
349  chambME[indexChId][fullType] = ibooker.book1D(HistoName.c_str(),"Trigger efficiency vs position (Phi)",nbins,min,max);
350  }
351  else if (htype.find("TrigEffPosvsAnglePhi") == 0 ){
352  float min,max;
353  int nbins;
354  trigGeomUtils->phiRange(chambId,min,max,nbins);
355  chambME[indexChId][fullType] = ibooker.book2D(HistoName.c_str(),"Trigger efficiency position vs angle (Phi)",16,-40.,40.,nbins,min,max);
356  }
357  else if (htype.find("TrigEffPosvsAngleHHHLPhi") == 0 ){
358  float min,max;
359  int nbins;
360  trigGeomUtils->phiRange(chambId,min,max,nbins);
361  chambME[indexChId][fullType] = ibooker.book2D(HistoName.c_str(),"Trigger efficiency (HH/HL) pos vs angle (Phi)",16,-40.,40.,nbins,min,max);
362  }
363  else if (htype.find("TrigEffPosHHHLPhi") == 0 ){
364  float min,max;
365  int nbins;
366  trigGeomUtils->phiRange(chambId,min,max,nbins);
367  chambME[indexChId][fullType] = ibooker.book1D(HistoName.c_str(),"Trigger efficiency (HH/HL) vs position (Phi)",nbins,min,max);
368  }
369  else if (htype.find("TrigEffPosTheta") == 0){
370  float min,max;
371  int nbins;
372  trigGeomUtils->thetaRange(chambId,min,max,nbins);
373  chambME[indexChId][fullType] = ibooker.book1D(HistoName.c_str(),"Trigger efficiency vs position (Theta)",nbins,min,max);
374  }
375  else if (htype.find("TrigEffPosHTheta") == 0){
376  float min,max;
377  int nbins;
378  trigGeomUtils->thetaRange(chambId,min,max,nbins);
379  chambME[indexChId][fullType] = ibooker.book1D(HistoName.c_str(),"Trigger efficiency (H) vs position (Theta)",nbins,min,max);
380  }
381  else if (htype.find("TrigEffPosvsAngleTheta") == 0 ){
382  float min,max;
383  int nbins;
384  trigGeomUtils->thetaRange(chambId,min,max,nbins);
385  chambME[indexChId][fullType] = ibooker.book2D(HistoName.c_str(),"Trigger efficiency pos vs angle (Theta)",16,-40.,40.,nbins,min,max);
386  }
387  else if (htype.find("TrigEffPosvsAngleHTheta") == 0 ){
388  float min,max;
389  int nbins;
390  trigGeomUtils->thetaRange(chambId,min,max,nbins);
391  chambME[indexChId][fullType] = ibooker.book2D(HistoName.c_str(),"Trigger efficiency (H) pos vs angle (Theta)",16,-40.,40.,nbins,min,max);
392  }
393 
394 }
395 
396 
397 
399 
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.
MonitorElement * get(const std::string &path)
Definition: DQMStore.cc:302
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 dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &)
Perform client diagnostic in online.
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
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:48
tuple result
Definition: query.py:137
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:274
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)
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 dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &)
std::string & topFolder(bool isDCC)
Get top folder name.
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:41