CMS 3D CMS Logo

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