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