CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTChamberEfficiencyClient.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author M. Pelliccioni - INFN Torino
5  */
6 
10 
13 
16 
17 #include <stdio.h>
18 #include <sstream>
19 #include <math.h>
20 
21 using namespace edm;
22 using namespace std;
23 
24 //two words about conventions: "All" histograms are those made for all segments
25 //while "Qual" histograms are those for segments with at least 12 hits
26 
28 {
29 
30  LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
31  << "DTChamberEfficiencyClient: Constructor called";
32 
33  dbe = Service<DQMStore>().operator->();
34 
35  prescaleFactor = pSet.getUntrackedParameter<int>("diagnosticPrescale", 1);
36 }
37 
39 {
40  LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
41  << "DTChamberEfficiencyClient: Destructor called";
42 }
43 
45 {
46  LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
47  << "DTChamberEfficiencyClient: BeginJob";
48 
49  nevents = 0;
50 
51  bookHistos();
52 
53  return;
54 }
55 
57 {
58  LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
59  << "[DTChamberEfficiencyClient]: Begin of LS transition";
60 
61  return;
62 }
63 
65 {
66  LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
67  << "DTChamberEfficiencyClient: beginRun";
68 
69  // Get the DT Geometry
70  setup.get<MuonGeometryRecord>().get(muonGeom);
71 
72  return;
73 }
74 
76 {
77 
78  nevents++;
79  LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
80  << "[DTChamberEfficiencyClient]: " << nevents << " events";
81  return;
82 }
83 
85 {
86  LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
87  << "DTChamberEfficiencyClient: endluminosityBlock";
88 }
89 
90 
92 {
93  LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
94  << "DTChamberEfficiencyClient: endRun";
95  // reset the global summary
96  globalEffSummary->Reset();
97 
98  //Loop over the wheels
99  for(int wheel=-2;wheel<=2;wheel++){
100  stringstream wheel_str; wheel_str << wheel;
101 
102  // Get the ME produced by EfficiencyTask Source
103  // All means no selection on segments, Qual means segments with at least 12 hits
104  MonitorElement* MECountAll = dbe->get("DT/05-ChamberEff/Task/hCountSectVsChamb_All_W" + wheel_str.str());
105  MonitorElement* MECountQual = dbe->get("DT/05-ChamberEff/Task/hCountSectVsChamb_Qual_W" + wheel_str.str());
106  MonitorElement* MEExtrap = dbe->get("DT/05-ChamberEff/Task/hExtrapSectVsChamb_W" + wheel_str.str());
107 
108  //get the TH2F
109  if(!MECountAll) cout<<"fucking ME is null"<<endl;
110  if(!(MECountAll->getTH2F())) cout<<"fucking puntator is null!"<<endl;
111  TH2F* hCountAll = MECountAll->getTH2F();
112  TH2F* hCountQual = MECountQual->getTH2F();
113  TH2F* hExtrap = MEExtrap->getTH2F();
114 
115 
116 
117  const int nBinX = summaryHistos[wheel+2][0]->getNbinsX();
118  const int nBinY = summaryHistos[wheel+2][0]->getNbinsY();
119 
120  for(int j=1;j<=nBinX;j++){
121  for(int k=1;k<=nBinY;k++){
122  summaryHistos[wheel+2][0]->setBinContent(j,k,0.);
123  summaryHistos[wheel+2][1]->setBinContent(j,k,0.);
124 
125  const float numerAll = hCountAll->GetBinContent(j,k);
126  const float numerQual = hCountQual->GetBinContent(j,k);
127  const float denom = hExtrap->GetBinContent(j,k);
128 
129  if(denom != 0.){
130  const float effAll= numerAll/denom;
131  const float eff_error_All = sqrt((effAll+effAll*effAll)/denom);
132 
133  const float effQual= numerQual/denom;
134  const float eff_error_Qual = sqrt((effQual+effQual*effQual)/denom);
135 
136  //if(wheel == 2 && k == 2 && j == 2) cout << "Eff ch " << effAll << " " << lumiSeg.id() << endl;
137 
138  summaryHistos[wheel+2][0]->setBinContent(j,k,effAll);
139  summaryHistos[wheel+2][0]->setBinError(j,k,eff_error_All);
140 
141  summaryHistos[wheel+2][1]->setBinContent(j,k,effQual);
142  summaryHistos[wheel+2][1]->setBinError(j,k,eff_error_Qual);
143 
144  // Fill 1D eff distributions
145  globalEffDistr -> Fill(effAll);
146  EffDistrPerWh[wheel+2] -> Fill(effAll);
147 
148  }
149  }
150  }
151  }
152 
153  // fill the global eff. summary
154  // problems at a granularity smaller than the chamber are ignored
155  for(int wheel=-2; wheel<=2; wheel++) { // loop over wheels
156  // retrieve the chamber efficiency summary
157  MonitorElement * segmentWheelSummary = summaryHistos[wheel+2][0];
158  if(segmentWheelSummary != 0) {
159 
160  for(int sector=1; sector<=12; sector++) { // loop over sectors
161  float nFailingChambers = 0.;
162 
163  double meaneff = 0.;
164  double errorsum = 0.;
165 
166  for(int station = 1; station != 5; ++station) { // loop over stations
167 
168  const double tmpefficiency = segmentWheelSummary->getBinContent(sector, station);
169  const double tmpvariance = pow(segmentWheelSummary->getBinError(sector, station),2);
170 
171  //if(wheel == 2 && sector == 9) cout << "ch " << station << " " << tmpefficiency << " " << tmpvariance << " " << lumiSeg.id() << endl;
172 
173  if(tmpefficiency < 0.2 || tmpvariance == 0){
174  nFailingChambers++;
175  continue;
176  }
177 
178  meaneff += tmpefficiency/tmpvariance;
179  errorsum += 1./tmpvariance;
180 
181  LogTrace("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
182  << "Wheel: " << wheel << " Stat: " << station
183  << " Sect: " << sector << " status: " << meaneff/errorsum << endl;
184  }
185 
186  if(sector == 4 || sector == 10) {
187  int whichSector = (sector == 4) ? 13 : 14;
188 
189  const double tmpefficiency = segmentWheelSummary->getBinContent(whichSector, 4);
190  const double tmpvariance = pow(segmentWheelSummary->getBinError(whichSector, 4),2);
191 
192  if(tmpefficiency > 0.2 && tmpvariance != 0) {
193  meaneff += tmpefficiency/tmpvariance;
194  errorsum += 1./tmpvariance;
195  }
196  else nFailingChambers++;
197 
198  }
199 
200  double eff_result = 0;
201  if(errorsum != 0) eff_result = meaneff/errorsum;
202 
203  if(nFailingChambers != 0) {
204  if(sector != 4 && sector != 10) eff_result = eff_result*(4.-nFailingChambers)/4.;
205  else eff_result = eff_result*(5.-nFailingChambers)/5.;
206  }
207 
208  if(eff_result > 0.7) globalEffSummary->Fill(sector,wheel,1.);
209  else if(eff_result < 0.7 && eff_result > 0.5) globalEffSummary->Fill(sector,wheel,0.6);
210  else if(eff_result < 0.5 && eff_result > 0.3) globalEffSummary->Fill(sector,wheel,0.4);
211  else if(eff_result < 0.3 && eff_result > 0.) globalEffSummary->Fill(sector,wheel,0.15);
212 
213  //if(wheel == 2 && sector == 9) cout << "eff_result " << eff_result << endl;
214  //if(wheel == 2 && sector == 9) cout << "nfail " << nFailingChambers++ << endl;
215 
216  }
217  }
218  }
219  return;
220 }
221 
223 {
224  LogVerbatim ("DTDQM|DTMonitorClient|DTChamberEfficiencyClient")
225  << "DTChamberEfficiencyClient: endJob";
226  return;
227 }
228 
230 {
231 
232  dbe->setCurrentFolder("DT/05-ChamberEff");
233  globalEffSummary = dbe->book2D("EfficiencyGlbSummary","Efficiency Summary",12,1,13,5,-2,3);
234  globalEffSummary->setAxisTitle("sector",1);
235  globalEffSummary->setAxisTitle("wheel",2);
236 
237  globalEffDistr = dbe->book1D("TotalEfficiency","Total efficiency",51,0.,1.02);
238  globalEffDistr -> setAxisTitle("Eff",1);
239 
240  for(int wh=-2; wh<=2; wh++){
241  stringstream wheel; wheel << wh;
242  string histoNameAll = "EfficiencyMap_All_W" + wheel.str();
243  string histoTitleAll = "Efficiency map for all segments for wheel " + wheel.str();
244 
245  string histoNameQual = "EfficiencyMap_Qual_W" + wheel.str();
246  string histoTitleQual = "Efficiency map for quality segments for wheel " + wheel.str();
247 
248  string histoNameEff = "Efficiency_W" + wheel.str();
249  string histoTitleEff = "Segment efficiency, wheel " + wheel.str();
250 
251  dbe->setCurrentFolder("DT/05-ChamberEff");
252 
253  summaryHistos[wh+2][0] = dbe->book2D(histoNameAll.c_str(),histoTitleAll.c_str(),14,1.,15.,4,1.,5.);
254  summaryHistos[wh+2][0]->setAxisTitle("Sector",1);
255  summaryHistos[wh+2][0]->setBinLabel(1,"MB1",2);
256  summaryHistos[wh+2][0]->setBinLabel(2,"MB2",2);
257  summaryHistos[wh+2][0]->setBinLabel(3,"MB3",2);
258  summaryHistos[wh+2][0]->setBinLabel(4,"MB4",2);
259 
260  EffDistrPerWh[wh+2] = dbe -> book1D(histoNameEff.c_str(),histoTitleEff.c_str(),51,0.,1.02);
261  EffDistrPerWh[wh+2] -> setAxisTitle("Eff",1);
262 
263  dbe->setCurrentFolder("DT/05-ChamberEff/HighQual");
264 
265  summaryHistos[wh+2][1] = dbe->book2D(histoNameQual.c_str(),histoTitleQual.c_str(),14,1.,15.,4,1.,5.);
266  summaryHistos[wh+2][1]->setAxisTitle("Sector",1);
267  summaryHistos[wh+2][1]->setBinLabel(1,"MB1",2);
268  summaryHistos[wh+2][1]->setBinLabel(2,"MB2",2);
269  summaryHistos[wh+2][1]->setBinLabel(3,"MB3",2);
270  summaryHistos[wh+2][1]->setBinLabel(4,"MB4",2);
271 
272  }
273 
274  return;
275 }
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
DQM Client Diagnostic.
void beginRun(const edm::Run &run, const edm::EventSetup &setup)
T getUntrackedParameter(std::string const &, T const &) const
void bookHistos()
Definition: Histogram.h:33
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
T sqrt(T t)
Definition: SSEVec.h:48
virtual ~DTChamberEfficiencyClient()
Destructor.
int j
Definition: DBlmapReader.cc:9
int nevents
void endRun(edm::Run const &run, edm::EventSetup const &c)
#define LogTrace(id)
int k[5][pyjets_maxn]
void analyze(const edm::Event &e, const edm::EventSetup &c)
void bookHistos()
book the report summary
double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
const T & get() const
Definition: EventSetup.h:55
double getBinContent(int binx) const
get content of bin (1-D)
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
tuple cout
Definition: gather_cfg.py:121
TH2F * getTH2F(void) const
DTChamberEfficiencyClient(const edm::ParameterSet &ps)
Constructor.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
Definition: Run.h:41