CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTResolutionAnalysisTest.cc
Go to the documentation of this file.
1 
2 
3 /*
4  * See header file for a description of this class.
5  *
6  * $Date: 2010/01/05 10:15:46 $
7  * $Revision: 1.20 $
8  * \author G. Mila - INFN Torino
9  */
10 
11 
13 
14 // Framework
18 
19 
20 // Geometry
23 
28 
29 #include <string>
30 #include <sstream>
31 #include <math.h>
32 
33 
34 using namespace edm;
35 using namespace std;
36 
37 
39 
40  LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") << "[DTResolutionAnalysisTest]: Constructor";
41 
42  dbe = Service<DQMStore>().operator->();
43 
44  prescaleFactor = ps.getUntrackedParameter<int>("diagnosticPrescale", 1);
45  // permitted test range
46  permittedMeanRange = ps.getUntrackedParameter<double>("permittedMeanRange",0.005);
47  permittedSigmaRange = ps.getUntrackedParameter<double>("permittedSigmaRange",0.01);
48  // top folder for the histograms in DQMStore
49  topHistoFolder = ps.getUntrackedParameter<string>("topHistoFolder","DT/02-Segments");
50 
51  doCalibAnalysis = ps.getUntrackedParameter<bool>("doCalibAnalysis",false);
52 }
53 
54 
56  LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") << "DTResolutionAnalysisTest: analyzed " << nevents << " events";
57 
58 }
59 
60 
62 
63  LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") <<"[DTResolutionAnalysisTest]: BeginJob";
64 
65  nevents = 0;
66 
67  // global residual summary
68  dbe->setCurrentFolder(topHistoFolder);
69  globalResSummary = dbe->book2D("ResidualsGlbSummary", "Summary residuals",12,1,13,5,-2,3);
70 
71 
72 
73  // book summaries for mean and sigma
74  dbe->setCurrentFolder(topHistoFolder + "/00-MeanRes");
75  meanDistr[-2] = dbe->book1D("MeanDistr","Mean value of the residuals all (cm)",
76  100,-0.1,0.1);
77  meanDistr[-1] = dbe->book1D("MeanDistr_Phi","Mean value of the residuals #phi SL (cm)",
78  100,-0.1,0.1);
79  meanDistr[0] = dbe->book1D("MeanDistr_ThetaWh0","Mean values of the residuals #theta SL Wh 0 (cm)",
80  100,-0.1,0.1);
81  meanDistr[1] = dbe->book1D("MeanDistr_ThetaWh1","Mean value of the residuals #theta SL Wh +/-1 (cm)",
82  100,-0.1,0.1);
83  meanDistr[2] = dbe->book1D("MeanDistr_ThetaWh2","Mean value of the residuals #theta SL Wh +/-2 (cm)",
84  100,-0.1,0.1);
85 
86 
87  stringstream meanRange; meanRange << (permittedMeanRange*10000);
88  string histoTitle = "Fraction of SLs with |mean of res.| > " + meanRange.str() + "#mum";
89  wheelMeanHistos[3] = dbe->book2D("MeanResGlbSummary",histoTitle.c_str(),12,1,13,5,-2,3);
90  wheelMeanHistos[3]->setAxisTitle("Sector",1);
91  wheelMeanHistos[3]->setAxisTitle("Wheel",2);
92 
93 
94  dbe->setCurrentFolder(topHistoFolder + "/01-SigmaRes");
95  sigmaDistr[-2] = dbe->book1D("SigmaDistr","Sigma value of the residuals all (cm)",
96  50,0.0,0.2);
97  sigmaDistr[-1] = dbe->book1D("SigmaDistr_Phi","Sigma value of the residuals #phi SL (cm)",
98  50,0.0,0.2);
99  sigmaDistr[0] = dbe->book1D("SigmaDistr_ThetaWh0","Sigma value of the residuals #theta SL Wh 0 (cm)",
100  50,0.0,0.2);
101  sigmaDistr[1] = dbe->book1D("SigmaDistr_ThetaWh1","Sigma value of the residuals #theta SL Wh +/-1 (cm)",
102  50,0.0,0.2);
103  sigmaDistr[2] = dbe->book1D("SigmaDistr_ThetaWh2","Sigma value of the residuals #theta SL Wh +/-2 (cm)",
104  50,0.0,0.2);
105 
106  stringstream sigmaRange; sigmaRange << (permittedSigmaRange*10000);
107  histoTitle = "Fraction of SLs with #sigma res. > " + sigmaRange.str() + "#mum";
108  wheelSigmaHistos[3] = dbe->book2D("SigmaResGlbSummary",histoTitle.c_str(),12,1,13,5,-2,3);
109  wheelSigmaHistos[3]->setAxisTitle("Sector",1);
110  wheelSigmaHistos[3]->setAxisTitle("Wheel",2);
111 
112 
113  // loop over all the CMS wheels, sectors & book the summary histos
114  for (int wheel=-2; wheel<=2; wheel++){
115  bookHistos(wheel);
116  for (int sector=1; sector<=12; sector++){
117  bookHistos(wheel, sector);
118  }
119  }
120 
121 }
122 
124 
125  LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") <<"[DTResolutionAnalysisTest]: BeginRun";
126 
127  // Get the geometry
128  context.get<MuonGeometryRecord>().get(muonGeom);
129 
130 }
131 
132 
134 
135  LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") <<"[DTResolutionAnalysisTest]: Begin of LS transition";
136 
137  // Get the run number
138  run = lumiSeg.run();
139 
140 
141 }
142 
143 
144 
146 
147  nevents++;
148 
149 }
150 
151 
152 
154 }
155 
156 
157 void DTResolutionAnalysisTest::endRun(Run const& run, EventSetup const& context) {
158 
159 
160  LogTrace ("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") <<"[DTResolutionAnalysisTest]: End of Run transition, performing the DQM client operation";
161 
162 // // counts number of lumiSegs
163 // nLumiSegs = lumiSeg.id().luminosityBlock();
164 
165 // // prescale factor
166 // if ( nLumiSegs%prescaleFactor != 0 ) return;
167 
168  // reset the ME with fixed scale
169  resetMEs();
170 
171  for (vector<DTChamber*>::const_iterator ch_it = muonGeom->chambers().begin();
172  ch_it != muonGeom->chambers().end(); ++ch_it) { // loop over the chambers
173 
174  DTChamberId chID = (*ch_it)->id();
175 
176  // Fill the test histos
177  for(vector<const DTSuperLayer*>::const_iterator sl_it = (*ch_it)->superLayers().begin();
178  sl_it != (*ch_it)->superLayers().end(); ++sl_it) { // loop over SLs
179 
180 
181  DTSuperLayerId slID = (*sl_it)->id();
182  MonitorElement * res_histo = dbe->get(getMEName(slID));
183 
184  if(res_histo) { // Gaussian Fit
185  float statMean = res_histo->getMean(1);
186  float statSigma = res_histo->getRMS(1);
187  double mean = -1;
188  double sigma = -1;
189  TH1F * histo_root = res_histo->getTH1F();
190 
191  // fill the summaries
192  int entry= (chID.station() - 1) * 3;
193  int binSect = slID.sector();
194  if(slID.sector() == 13) binSect = 4;
195  else if(slID.sector() == 14) binSect = 10;
196  int binSL = entry+slID.superLayer();
197  if(chID.station() == 4 && slID.superLayer() == 3) binSL--;
198  if((slID.sector()==13 || slID.sector()==14) && slID.superLayer()==1) binSL=12;
199  if((slID.sector()==13 || slID.sector()==14) && slID.superLayer()==3) binSL=13;
200 
201  if(histo_root->GetEntries()>20) {
202  TF1 *gfit = new TF1("Gaussian","gaus",(statMean-(2*statSigma)),(statMean+(2*statSigma)));
203  try {
204  histo_root->Fit(gfit, "Q0", "", -0.1, 0.1);
205  } catch (...) {
206  LogWarning ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
207  << "[DTResolutionAnalysisTask]: Exception when fitting SL : " << slID;
208  // FIXME: the SL is set as OK in the summary
209  double weight = 1/11.;
210  if((binSect == 4 || binSect == 10) && slID.station() == 4) weight = 1/22.;
211  globalResSummary->Fill(binSect, slID.wheel(), weight);
212  continue;
213  }
214 
215  if(gfit){
216  // get the mean and the sigma of the distribution
217  mean = gfit->GetParameter(1);
218  sigma = gfit->GetParameter(2);
219 
220  // fill the distributions
221  meanDistr[-2]->Fill(mean);
222  sigmaDistr[-2]->Fill(sigma);
223  if(slID.superlayer() == 2) {
224  meanDistr[abs(slID.wheel())]->Fill(mean);
225  sigmaDistr[abs(slID.wheel())]->Fill(sigma);
226  } else {
227  meanDistr[-1]->Fill(mean);
228  sigmaDistr[-1]->Fill(sigma);
229  }
230 
231 
232 
233  // sector summaries
234  MeanHistos[make_pair(slID.wheel(),binSect)]->setBinContent(binSL, mean);
235  SigmaHistos[make_pair(slID.wheel(),binSect)]->setBinContent(binSL, sigma);
236 
237  // set the weight
238  double weight = 1/11.;
239  if((binSect == 4 || binSect == 10) && slID.station() == 4) weight = 1/22.;
240 
241  // test the values of mean and sigma
242  if(meanInRange(mean) && sigmaInRange(sigma)) { // sigma and mean ok
243  globalResSummary->Fill(binSect, slID.wheel(), weight);
244  wheelMeanHistos[3]->Fill(binSect,slID.wheel(),weight);
245  wheelSigmaHistos[3]->Fill(binSect,slID.wheel(),weight);
246  } else {
247  if(!meanInRange(mean)) { // only sigma ok
248  wheelMeanHistos[slID.wheel()]->Fill(binSect,binSL);
249  } else {
250  wheelMeanHistos[3]->Fill(binSect,slID.wheel(),weight);
251  }
252  if(!sigmaInRange(sigma)) { // only mean ok
253  wheelSigmaHistos[slID.wheel()]->Fill(binSect,binSL);
254  } else {
255  wheelSigmaHistos[3]->Fill(binSect,slID.wheel(),weight);
256  }
257  }
258  }
259  delete gfit;
260  }
261  else{
262  LogVerbatim ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
263  << "[DTResolutionAnalysisTask] Fit of " << slID
264  << " not performed because # entries < 20 ";
265  // FIXME: the SL is set as OK in the summary
266  double weight = 1/11.;
267  if((binSect == 4 || binSect == 10) && slID.station() == 4) weight = 1/22.;
268  globalResSummary->Fill(binSect, slID.wheel(), weight);
269  wheelMeanHistos[3]->Fill(binSect,slID.wheel(),weight);
270  wheelSigmaHistos[3]->Fill(binSect,slID.wheel(),weight);
271  }
272  } else {
273  LogWarning ("DTDQM|DTMonitorModule|DTResolutionAnalysisTask")
274  << "[DTResolutionAnalysisTask] Histo: " << getMEName(slID) << " not found" << endl;
275  }
276  } // loop on SLs
277  } // Loop on Stations
278 
279 }
280 
281 
282 
284 
285  stringstream wheel; wheel <<wh;
286 
287  dbe->setCurrentFolder(topHistoFolder + "/00-MeanRes");
288  string histoName = "MeanSummaryRes_W" + wheel.str();
289  stringstream meanRange; meanRange << (permittedMeanRange*10000);
290  string histoTitle = "# of SL with |mean of res.| > " + meanRange.str() + "#mum (Wheel " + wheel.str() + ")";
291  wheelMeanHistos[wh] = dbe->book2D(histoName.c_str(),histoTitle.c_str(),12,1,13,11,1,12);
292  wheelMeanHistos[wh]->setAxisTitle("Sector",1);
293  wheelMeanHistos[wh]->setBinLabel(1,"MB1_SL1",2);
294  wheelMeanHistos[wh]->setBinLabel(2,"MB1_SL2",2);
295  wheelMeanHistos[wh]->setBinLabel(3,"MB1_SL3",2);
296  wheelMeanHistos[wh]->setBinLabel(4,"MB2_SL1",2);
297  wheelMeanHistos[wh]->setBinLabel(5,"MB2_SL2",2);
298  wheelMeanHistos[wh]->setBinLabel(6,"MB2_SL3",2);
299  wheelMeanHistos[wh]->setBinLabel(7,"MB3_SL1",2);
300  wheelMeanHistos[wh]->setBinLabel(8,"MB3_SL2",2);
301  wheelMeanHistos[wh]->setBinLabel(9,"MB3_SL3",2);
302  wheelMeanHistos[wh]->setBinLabel(10,"MB4_SL1",2);
303  wheelMeanHistos[wh]->setBinLabel(11,"MB4_SL3",2);
304 // wheelMeanHistos[wh]->setBinLabel(12,"MB4_SL1",2);
305 // wheelMeanHistos[wh]->setBinLabel(13,"MB4_SL3",2);
306 
307 
308 
309  dbe->setCurrentFolder(topHistoFolder + "/01-SigmaRes");
310  histoName = "SigmaSummaryRes_W" + wheel.str();
311  stringstream sigmaRange; sigmaRange << (permittedSigmaRange*10000);
312  histoTitle = "# of SL with #sigma res. > " + sigmaRange.str() + "#mum (Wheel " + wheel.str() + ")";
313  wheelSigmaHistos[wh] = dbe->book2D(histoName.c_str(),histoTitle.c_str(),12,1,13,11,1,12);
314  wheelSigmaHistos[wh]->setAxisTitle("Sector",1);
315  wheelSigmaHistos[wh]->setBinLabel(1,"MB1_SL1",2);
316  wheelSigmaHistos[wh]->setBinLabel(2,"MB1_SL2",2);
317  wheelSigmaHistos[wh]->setBinLabel(3,"MB1_SL3",2);
318  wheelSigmaHistos[wh]->setBinLabel(4,"MB2_SL1",2);
319  wheelSigmaHistos[wh]->setBinLabel(5,"MB2_SL2",2);
320  wheelSigmaHistos[wh]->setBinLabel(6,"MB2_SL3",2);
321  wheelSigmaHistos[wh]->setBinLabel(7,"MB3_SL1",2);
322  wheelSigmaHistos[wh]->setBinLabel(8,"MB3_SL2",2);
323  wheelSigmaHistos[wh]->setBinLabel(9,"MB3_SL3",2);
324  wheelSigmaHistos[wh]->setBinLabel(10,"MB4_SL1",2);
325  wheelSigmaHistos[wh]->setBinLabel(11,"MB4_SL3",2);
326 // wheelSigmaHistos[wh]->setBinLabel(12,"MB4_SL1",2);
327 // wheelSigmaHistos[wh]->setBinLabel(13,"MB4_SL3",2);
328 
329 }
330 
331 
332 void DTResolutionAnalysisTest::bookHistos(int wh, int sect) {
333 
334  stringstream wheel; wheel << wh;
335  stringstream sector; sector << sect;
336 
337 
338  string MeanHistoName = "MeanTest_W" + wheel.str() + "_Sec" + sector.str();
339  string SigmaHistoName = "SigmaTest_W" + wheel.str() + "_Sec" + sector.str();
340 
341  string folder = topHistoFolder + "/Wheel" + wheel.str() + "/Sector" + sector.str();
342  dbe->setCurrentFolder(folder);
343 
344  if(sect!=4 && sect!=10) {
345  MeanHistos[make_pair(wh,sect)] =
346  dbe->book1D(MeanHistoName.c_str(),"Mean (from gaussian fit) of the residuals distribution",11,1,12);
347  } else {
348  MeanHistos[make_pair(wh,sect)] =
349  dbe->book1D(MeanHistoName.c_str(),"Mean (from gaussian fit) of the residuals distribution",13,1,14);
350  }
351  (MeanHistos[make_pair(wh,sect)])->setBinLabel(1,"MB1_SL1",1);
352  (MeanHistos[make_pair(wh,sect)])->setBinLabel(2,"MB1_SL2",1);
353  (MeanHistos[make_pair(wh,sect)])->setBinLabel(3,"MB1_SL3",1);
354  (MeanHistos[make_pair(wh,sect)])->setBinLabel(4,"MB2_SL1",1);
355  (MeanHistos[make_pair(wh,sect)])->setBinLabel(5,"MB2_SL2",1);
356  (MeanHistos[make_pair(wh,sect)])->setBinLabel(6,"MB2_SL3",1);
357  (MeanHistos[make_pair(wh,sect)])->setBinLabel(7,"MB3_SL1",1);
358  (MeanHistos[make_pair(wh,sect)])->setBinLabel(8,"MB3_SL2",1);
359  (MeanHistos[make_pair(wh,sect)])->setBinLabel(9,"MB3_SL3",1);
360  (MeanHistos[make_pair(wh,sect)])->setBinLabel(10,"MB4_SL1",1);
361  (MeanHistos[make_pair(wh,sect)])->setBinLabel(11,"MB4_SL3",1);
362  if(sect==4){
363  (MeanHistos[make_pair(wh,sect)])->setBinLabel(12,"MB4S4_SL1",1);
364  (MeanHistos[make_pair(wh,sect)])->setBinLabel(13,"MB4S4_SL3",1);
365  }
366  if(sect==10){
367  (MeanHistos[make_pair(wh,sect)])->setBinLabel(12,"MB4S10_SL1",1);
368  (MeanHistos[make_pair(wh,sect)])->setBinLabel(13,"MB4S10_SL3",1);
369  }
370 
371  if(sect!=4 && sect!=10) {
372  SigmaHistos[make_pair(wh,sect)] =
373  dbe->book1D(SigmaHistoName.c_str(),"Sigma (from gaussian fit) of the residuals distribution",11,1,12);
374  } else {
375  SigmaHistos[make_pair(wh,sect)] =
376  dbe->book1D(SigmaHistoName.c_str(),"Sigma (from gaussian fit) of the residuals distribution",13,1,14);
377  }
378  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(1,"MB1_SL1",1);
379  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(2,"MB1_SL2",1);
380  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(3,"MB1_SL3",1);
381  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(4,"MB2_SL1",1);
382  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(5,"MB2_SL2",1);
383  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(6,"MB2_SL3",1);
384  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(7,"MB3_SL1",1);
385  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(8,"MB3_SL2",1);
386  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(9,"MB3_SL3",1);
387  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(10,"MB4_SL1",1);
388  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(11,"MB4_SL3",1);
389  if(sect==4){
390  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(12,"MB4S13_SL1",1);
391  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(13,"MB4S13_SL3",1);
392  }
393  if(sect==10){
394  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(12,"MB4S14_SL1",1);
395  (SigmaHistos[make_pair(wh,sect)])->setBinLabel(13,"MB4S14_SL3",1);
396  }
397 
398 
399 }
400 
401 
403 
404  stringstream wheel; wheel << slID.wheel();
405  stringstream station; station << slID.station();
406  stringstream sector; sector << slID.sector();
407  stringstream superLayer; superLayer << slID.superlayer();
408 
409  string folderName =
410  topHistoFolder + "/Wheel" + wheel.str() +
411  "/Sector" + sector.str() +
412  "/Station" + station.str() + "/";
413 
414  if(doCalibAnalysis) folderName =
415  "DT/DTCalibValidation/Wheel" + wheel.str() +
416  "/Station" + station.str() + "/Sector" + sector.str() + "/";
417 
418  string histoname = folderName + "hResDist"
419  + "_W" + wheel.str()
420  + "_St" + station.str()
421  + "_Sec" + sector.str()
422  + "_SL" + superLayer.str();
423 
424  if(doCalibAnalysis) histoname = folderName + "hResDist_STEP3"
425  + "_W" + wheel.str()
426  + "_St" + station.str()
427  + "_Sec" + sector.str()
428  + "_SL" + superLayer.str();
429 
430  return histoname;
431 
432 }
433 
434 
435 
437  return (int) (bin /3.1)+1;
438 }
439 
440 
442  int ret = bin%3;
443  if(ret == 0 || bin == 11) ret = 3;
444 
445  return ret;
446 }
447 
448 
450  return fabs(mean) < permittedMeanRange;
451 }
452 
453 
455  return sigma < permittedSigmaRange;
456 }
457 
458 
460  globalResSummary->Reset();
461  // Reset the summary histo
462  for(map<int, MonitorElement*> ::const_iterator histo = wheelMeanHistos.begin();
463  histo != wheelMeanHistos.end();
464  histo++) {
465  (*histo).second->Reset();
466  }
467  for(map<int, MonitorElement*> ::const_iterator histo = wheelSigmaHistos.begin();
468  histo != wheelSigmaHistos.end();
469  histo++) {
470  (*histo).second->Reset();
471  }
472 
473  for(int indx = -2; indx != 3; ++indx) {
474  meanDistr[indx]->Reset();
475  sigmaDistr[indx]->Reset();
476  }
477 }
478 
T getUntrackedParameter(std::string const &, T const &) const
DTResolutionAnalysisTest(const edm::ParameterSet &ps)
Constructor.
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
DQM Client Diagnostic.
#define abs(x)
Definition: mlp_lapack.h:159
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
std::string getMEName(const DTSuperLayerId &slID)
Get the ME name.
tuple histo
Definition: trackerHits.py:12
virtual ~DTResolutionAnalysisTest()
Destructor.
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
void bookHistos()
Definition: Histogram.h:33
bool meanInRange(double mean) const
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
int superLayer() const
Return the superlayer number.
RunNumber_t run() const
int nevents
#define LogTrace(id)
int superlayer() const
Return the superlayer number (deprecated method name)
const T & get() const
Definition: EventSetup.h:55
TH1F * getTH1F(void) const
double getRMS(int axis=1) const
get RMS of histogram along x, y or z axis (axis=1, 2, 3 respectively)
int sector() const
Definition: DTChamberId.h:63
void bookHistos(int wh)
book the summary histograms
int station() const
Return the station number.
Definition: DTChamberId.h:53
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
bool sigmaInRange(double sigma) const
Definition: Run.h:31
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
void endRun(edm::Run const &run, edm::EventSetup const &c)