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