CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTRunConditionVarClient.cc
Go to the documentation of this file.
1 /******* \class DTRunConditionVarClient *******
2  *
3  * Description:
4  *
5  * detailed description
6  *
7  * \author : Paolo Bellan, Antonio Branca
8  * $date : 23/09/2011 15:42:04 CET $
9  *
10  * Modification:
11  *
12  *********************************/
13 
17 
20 
24 
25 #include <stdio.h>
26 #include <sstream>
27 #include <math.h>
28 
29 using namespace edm;
30 using namespace std;
31 
33 {
34 
35  LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
36  << "DTRunConditionVarClient: Constructor called";
37 
38 
39  minRangeVDrift = pSet.getUntrackedParameter<double>("minRangeVDrift");
40  maxRangeVDrift = pSet.getUntrackedParameter<double>("maxRangeVDrift");
41  minRangeT0 = pSet.getUntrackedParameter<double>("minRangeT0");
42  maxRangeT0 = pSet.getUntrackedParameter<double>("maxRangeT0");
43 
44  maxGoodVDriftDev = pSet.getUntrackedParameter<double>("maxGoodVDriftDev");
45  minBadVDriftDev = pSet.getUntrackedParameter<double>("minBadVDriftDev");
46  maxGoodT0 = pSet.getUntrackedParameter<double>("maxGoodT0");
47  minBadT0 = pSet.getUntrackedParameter<double>("minBadT0");
48 
49  maxGoodVDriftSigma = pSet.getUntrackedParameter<double>("maxGoodVDriftSigma");
50  minBadVDriftSigma = pSet.getUntrackedParameter<double>("minBadVDriftSigma");
51  maxGoodT0Sigma = pSet.getUntrackedParameter<double>("maxGoodT0Sigma");
52  minBadT0Sigma = pSet.getUntrackedParameter<double>("minBadT0Sigma");
53 
54  theDbe = Service<DQMStore>().operator->();
55 
56 }
57 
59 {
60  LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
61  << "DTRunConditionVarClient: Destructor called";
62 }
63 
65 {
66  LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
67  << "DTRunConditionVarClient: BeginJob";
68 
69  nevents = 0;
70 
71  theDbe -> setCurrentFolder("DT/02-Segments");
72 
73  glbVDriftSummary = theDbe->book2D("VDriftGlbSummary", "# of MBs with good mean and good sigma of vDrift",12,1,13,5,-2,3);
74  glbT0Summary = theDbe->book2D("T0GlbSummary", "# of MBs with good mean and good sigma of t0",12,1,13,5,-2,3);
75 
76  theDbe -> setCurrentFolder("DT/02-Segments/02-MeanVDrift");
77 
78  summaryHistos["MeanVDriftGlbSummary"] = theDbe -> book2D("MeanVDriftGlbSummary","mean VDrift average per sector",12,1.,13.,5,-2.,3.);
79  allwheelHistos["allMeanVDrift"] = theDbe -> book1D("VDriftMeanAllWheels","mean VDrift for all chambers",60,0.0048,0.006);
80 
81  theDbe -> setCurrentFolder("DT/02-Segments/02-SigmaVDrift");
82 
83  summaryHistos["SigmaVDriftGlbSummary"] = theDbe -> book2D("SigmaVDriftGlbSummary","# of Chambers with good sigma VDrift",12,1.,13.,5,-2.,3.);
84  allwheelHistos["allSigmaVDrift"] = theDbe -> book1D("VDriftSigmaAllWheels","sigma VDrift for all chambers",30,0.,0.0006);
85 
86  theDbe -> setCurrentFolder("DT/02-Segments/03-MeanT0");
87 
88  summaryHistos["MeanT0GlbSummary"] = theDbe -> book2D("MeanT0GlbSummary","mean T0 average per sector",12,1.,13.,5,-2.,3.);
89  allwheelHistos["allMeanT0"] = theDbe -> book1D("T0MeanAllWheels","mean T0 for all chambers",100,-25.,25.);
90 
91  theDbe -> setCurrentFolder("DT/02-Segments/03-SigmaT0");
92 
93  summaryHistos["SigmaT0GlbSummary"] = theDbe -> book2D("SigmaT0GlbSummary","# of Chambers with good sigma T0",12,1.,13.,5,-2.,3.);
94  allwheelHistos["allSigmaT0"] = theDbe -> book1D("T0SigmaAllWheels","sigma T0 for alla chambers",50,0,25);
95 
96  for(int wh=-2; wh<=2; wh++) {
97  bookWheelHistos("MeanVDrift","02-MeanVDrift",wh,60,0.0048,0.006,true);
98  bookWheelHistos("SigmaVDrift","02-SigmaVDrift",wh,30,0.,0.0006);
99  bookWheelHistos("MeanT0","03-MeanT0",wh,100,-25.,25.);
100  bookWheelHistos("SigmaT0","03-SigmaT0",wh,50,0,25);
101  }
102 
103  return;
104 }
105 
107 {
108  LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
109  << "[DTRunConditionVarClient]: Begin of LS transition";
110 
111  return;
112 }
113 
115 {
116  LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
117  << "DTRunConditionVarClient: beginRun";
118 
119  return;
120 }
121 
123 {
124 
125  nevents++;
126  LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
127  << "[DTRunConditionVarClient]: " << nevents << " events";
128  return;
129 }
130 
132 {
133  LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
134  << "DTRunConditionVarClient: endluminosityBlock";
135 }
136 
137 
138 void DTRunConditionVarClient::endRun(Run const& run, EventSetup const& context)
139 {
140  LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
141  << "DTRunConditionVarClient: endRun";
142 
143  // Get the map of vdrift from the setup
144  context.get<DTMtimeRcd>().get(mTime);
145  mTimeMap_ = &*mTime;
146 
147  for(int wheel=-2;wheel<=2;wheel++){
148  for(int sec=1; sec<=14; sec++) {
149  for(int stat=1; stat<=4; stat++) {
150 
151  if( (sec == 13 || sec == 14) && stat != 4 ) continue;
152 
153  // Get the ME produced by DTRunConditionVar Source
154  MonitorElement* VDriftME = getChamberHistos(DTChamberId(wheel,stat,sec),"VDrift_FromSegm");
155  MonitorElement* T0ME = getChamberHistos(DTChamberId(wheel,stat,sec),"T0_FromSegm");
156 
157  if (!VDriftME || !T0ME) {
158  edm::LogWarning("DTRunConditionVarClient") << "ME not available" << std::endl;
159  return;
160  }
161 
162 
163  // Get the means per chamber
164  float vDriftMean = VDriftME->getMean();
165  float t0Mean = T0ME->getMean();
166 
167  // Get the sigma per chamber
168  float vDriftSigma = VDriftME->getRMS();
169  float t0Sigma = T0ME->getRMS();
170 
171  if( VDriftME->getEntries() != 0 ) {
172 
173  allwheelHistos["allMeanVDrift"] -> Fill(vDriftMean);
174  allwheelHistos["allSigmaVDrift"] -> Fill(vDriftSigma);
175 
176  (wheelHistos[wheel])["MeanVDrift"] -> Fill(vDriftMean);
177  (wheelHistos[wheel])["SigmaVDrift"] -> Fill(vDriftSigma);
178 
179  }
180 
181 
182  if( T0ME->getEntries() != 0 ) {
183 
184  allwheelHistos["allMeanT0"] -> Fill(t0Mean);
185  allwheelHistos["allSigmaT0"] -> Fill(t0Sigma);
186 
187  (wheelHistos[wheel])["MeanT0"] -> Fill(t0Mean);
188  (wheelHistos[wheel])["SigmaT0"] -> Fill(t0Sigma);
189 
190  }
191 
192  //
193  DTChamberId indexCh(wheel,stat,sec);
194 
195  float vDriftDev(0.), errvDriftDev(0.);
196  percDevVDrift(indexCh, vDriftMean, vDriftSigma, vDriftDev, errvDriftDev);
197 
198  int sec_ = sec;
199  if( sec == 13 || sec == 14 ) sec_ = ( sec == 13 ) ? 4 : 10;
200 
201  float fillvDriftDev = max(min(vDriftDev,maxRangeVDrift),minRangeVDrift);
202  float fillT0Mean = max(min(t0Mean,maxRangeT0),minRangeT0);
203 
204  float vDriftDevQ = varQuality(fabs(vDriftDev),maxGoodVDriftDev,minBadVDriftDev);
205  float t0MeanQ = varQuality(fabs(t0Mean),maxGoodT0,minBadT0);
206 
207  float vDriftSigmQ = varQuality(vDriftSigma,maxGoodVDriftSigma,minBadVDriftSigma);
208  float t0SigmQ = varQuality(t0Sigma,maxGoodT0Sigma,minBadT0Sigma);
209 
210  if( sec == 13 || sec == 14 ) {
211 
212  float binVDriftDev = (wheelHistos[wheel])["MeanVDriftSummary"]->getBinContent(sec_,stat);
213  binVDriftDev = (fabs(binVDriftDev) > fabs(fillvDriftDev)) ? binVDriftDev : fillvDriftDev;
214  (wheelHistos[wheel])["MeanVDriftSummary"] -> setBinContent(sec_,stat,binVDriftDev);
215 
216  float binT0MeanVal = (wheelHistos[wheel])["MeanT0Summary"] -> getBinContent(sec_,stat);
217  binT0MeanVal = (fabs(binT0MeanVal) > fabs(fillT0Mean)) ? binT0MeanVal : fillT0Mean;
218  (wheelHistos[wheel])["MeanT0Summary"] -> setBinContent(sec_,stat,binT0MeanVal);
219 
220  float binVDriftSigmVal = (wheelHistos[wheel])["SigmaVDriftSummary"] -> getBinContent(sec_,stat);
221  binVDriftSigmVal = (binVDriftSigmVal > 0. && binVDriftSigmVal < vDriftSigmQ) ? binVDriftSigmVal : vDriftSigmQ;
222  (wheelHistos[wheel])["SigmaVDriftSummary"] -> setBinContent(sec_,stat,binVDriftSigmVal);
223 
224  float binT0SigmVal = (wheelHistos[wheel])["SigmaT0Summary"] -> getBinContent(sec_,stat);
225  binT0SigmVal = (binT0SigmVal > 0. && binT0SigmVal < t0SigmQ) ? binT0SigmVal : t0SigmQ;
226  (wheelHistos[wheel])["SigmaT0Summary"] -> setBinContent(sec_,stat,binT0SigmVal);
227 
228  } else {
229 
230  (wheelHistos[wheel])["MeanVDriftSummary"] -> setBinContent(sec_,stat,fillvDriftDev);
231  (wheelHistos[wheel])["MeanT0Summary"] -> setBinContent(sec_,stat,fillT0Mean);
232  (wheelHistos[wheel])["SigmaVDriftSummary"] -> setBinContent(sec_,stat,vDriftSigmQ);
233  (wheelHistos[wheel])["SigmaT0Summary"] -> setBinContent(sec_,stat,t0SigmQ);
234 
235  }
236 
237  double weight = 1/4.;
238  if(( sec_ == 4 || sec_ == 10) && stat == 4) weight = 1/8.;
239 
240  if( vDriftDevQ > 0.85 && vDriftSigmQ > 0.85 ) {
241  glbVDriftSummary -> Fill(sec_,wheel,weight);
242  summaryHistos["MeanVDriftGlbSummary"] -> Fill(sec_,wheel,weight);
243  summaryHistos["SigmaVDriftGlbSummary"] -> Fill(sec_,wheel,weight);
244 
245  } else {
246  if( vDriftDevQ > 0.85 && vDriftSigmQ < 0.85 ) {
247  summaryHistos["MeanVDriftGlbSummary"] -> Fill(sec_,wheel,weight);
248  }
249  if( vDriftDevQ < 0.85 && vDriftSigmQ > 0.85 ) {
250  summaryHistos["SigmaVDriftGlbSummary"] -> Fill(sec_,wheel,weight);
251  }
252  }
253 
254  if( t0MeanQ > 0.85 && t0SigmQ > 0.85 ) {
255  glbT0Summary -> Fill(sec_,wheel,weight);
256  summaryHistos["MeanT0GlbSummary"] -> Fill(sec_,wheel,weight);
257  summaryHistos["SigmaT0GlbSummary"] -> Fill(sec_,wheel,weight);
258  } else {
259  if( t0MeanQ > 0.85 && t0SigmQ < 0.85 ) {
260  summaryHistos["MeanT0GlbSummary"] -> Fill(sec_,wheel,weight);
261 
262  }
263  if( t0MeanQ < 0.85 && t0SigmQ > 0.85 ) {
264  summaryHistos["SigmaT0GlbSummary"] -> Fill(sec_,wheel,weight);
265  }
266  }
267 
268 
269  }// end loop on stations
270  }// end loop on sectors
271  }//end loop on wheels
272 
273  return;
274 }
275 
277 {
278  LogVerbatim ("DTDQM|DTMonitorClient|DTRunConditionVarClient")
279  << "DTRunConditionVarClient: endJob";
280  return;
281 }
282 
283 float DTRunConditionVarClient::varQuality(float var, float maxGood, float minBad) {
284 
285  float qual(0);
286  if( var <= maxGood ) {qual = 1.;}
287  else if( var > maxGood && var < minBad ) {qual = 0.9;}
288  else if( var >= minBad ) {qual = 0.1;}
289 
290  return qual;
291 }
292 
293 void DTRunConditionVarClient::percDevVDrift(DTChamberId indexCh, float meanVD, float sigmaVD, float& devVD, float& errdevVD) {
294 
295  DTSuperLayerId indexSLPhi1(indexCh,1);
296  DTSuperLayerId indexSLPhi2(indexCh,3);
297 
298  float vDriftPhi1(0.), vDriftPhi2(0.);
299  float ResPhi1(0.), ResPhi2(0.);
300  int status1 = mTimeMap_->get(indexSLPhi1,vDriftPhi1,ResPhi1,DTVelocityUnits::cm_per_ns);
301  int status2 = mTimeMap_->get(indexSLPhi2,vDriftPhi2,ResPhi2,DTVelocityUnits::cm_per_ns);
302 
303  if(status1 != 0 || status2 != 0) {
304  DTSuperLayerId sl = (status1 != 0) ? indexSLPhi1 : indexSLPhi2;
305  throw cms::Exception("DTRunConditionVarClient") << "Could not find vDrift entry in DB for"
306  << sl << endl;
307  }
308 
309  float vDriftMed = (vDriftPhi1 + vDriftPhi2) / 2.;
310 
311  devVD = (meanVD - vDriftMed) / vDriftMed;
312  devVD = devVD < 1. ? devVD : 1.;
313 
314  errdevVD = sigmaVD/vDriftMed;
315 
316  return;
317 }
318 
319 void DTRunConditionVarClient::bookWheelHistos(string histoType, string subfolder, int wh, int nbins, float min, float max, bool isVDCorr )
320 {
321  stringstream wheel; wheel << wh;
322 
323  string folder = "DT/02-Segments/" + subfolder;
324 
325  theDbe->setCurrentFolder(folder);
326 
327  string histoName = histoType + "_W" + wheel.str();
328  string histoLabel = histoType;
329 
330  (wheelHistos[wh])[histoType] = theDbe -> book1D(histoName, histoLabel, nbins, min, max);
331 
332 
333  if( isVDCorr ) {
334  histoLabel = "Summary of corrections to VDrift DB values";
335  histoName = "CorrTo" + histoType + "Summary_W" + wheel.str();
336  } else {
337  histoLabel = histoType + "Summary";
338  histoName = histoType + "Summary_W" + wheel.str();
339  }
340 
341  MonitorElement* me = theDbe -> book2D(histoName, histoLabel,12,1,13,4,1,5);
342 
343  me->setBinLabel(1,"MB1",2);
344  me->setBinLabel(2,"MB2",2);
345  me->setBinLabel(3,"MB3",2);
346  me->setBinLabel(4,"MB4",2);
347  me->setAxisTitle("Sector",1);
348 
349  (wheelHistos[wh])[histoType + "Summary"] = me;
350 
351  return;
352 }
353 
355 
356  int wh = dtCh.wheel();
357  int sc = dtCh.sector();
358  int st = dtCh.station();
359  stringstream wheel; wheel << wh;
360  stringstream station; station << st;
361  stringstream sector; sector << sc;
362 
363  string folder = "DT/02-Segments/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str();
364  string histoTag = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
365  string MEpath = folder + "/" + histoType + histoTag;
366 
367  theDbe->setCurrentFolder(folder);
368 
369  LogTrace ("DTDQM|DTMonitorModule|DTRunConditionVar")
370  << "[DTRunConditionVar]: getting ME from " << folder << endl;
371 
372  MonitorElement* ME = theDbe -> get(MEpath);
373 
374  return ME;
375 }
T getUntrackedParameter(std::string const &, T const &) const
virtual ~DTRunConditionVarClient()
Destructor.
void beginRun(const edm::Run &run, const edm::EventSetup &setup)
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
void bookWheelHistos(std::string histoType, std::string subfolder, int wh, int nbins, float min, float max, bool isVDCorr=false)
book the report summary
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)
double getEntries(void) const
get # of entries
double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
float varQuality(float var, float maxGood, float minBad)
MonitorElement * getChamberHistos(const DTChamberId &, std::string)
Definition: ME.h:11
void endRun(edm::Run const &run, edm::EventSetup const &c)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void percDevVDrift(DTChamberId indexCh, float meanVD, float sigmaVD, float &devVD, float &errdevVD)
int nevents
EventID const & min(EventID const &lh, EventID const &rh)
Definition: EventID.h:129
DTRunConditionVarClient(const edm::ParameterSet &ps)
Constructor.
#define LogTrace(id)
const T & get() const
Definition: EventSetup.h:55
MonitorElement ME
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:61
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
DQM Client Diagnostic.
void analyze(const edm::Event &e, const edm::EventSetup &c)
int weight
Definition: histoStyle.py:50
int station() const
Return the station number.
Definition: DTChamberId.h:51
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:45
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:41
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:134