CMS 3D CMS Logo

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  * threadsafe version (//-) oct/nov 2014 - WATWanAbdullah -ncpp-um-my
13  *
14  *
15  *********************************/
16 
19 
22 
25 
26 #include <cstdio>
27 #include <sstream>
28 #include <cmath>
29 
30 using namespace edm;
31 using namespace std;
32 
34  LogVerbatim("DTDQM|DTMonitorClient|DTRunConditionVarClient") << "DTRunConditionVarClient: Constructor called";
35 
36  minRangeVDrift = pSet.getUntrackedParameter<double>("minRangeVDrift");
37  maxRangeVDrift = pSet.getUntrackedParameter<double>("maxRangeVDrift");
38  minRangeT0 = pSet.getUntrackedParameter<double>("minRangeT0");
39  maxRangeT0 = pSet.getUntrackedParameter<double>("maxRangeT0");
40 
41  maxGoodVDriftDev = pSet.getUntrackedParameter<double>("maxGoodVDriftDev");
42  minBadVDriftDev = pSet.getUntrackedParameter<double>("minBadVDriftDev");
43  maxGoodT0 = pSet.getUntrackedParameter<double>("maxGoodT0");
44  minBadT0 = pSet.getUntrackedParameter<double>("minBadT0");
45 
46  maxGoodVDriftSigma = pSet.getUntrackedParameter<double>("maxGoodVDriftSigma");
47  minBadVDriftSigma = pSet.getUntrackedParameter<double>("minBadVDriftSigma");
48  maxGoodT0Sigma = pSet.getUntrackedParameter<double>("maxGoodT0Sigma");
49  minBadT0Sigma = pSet.getUntrackedParameter<double>("minBadT0Sigma");
50 
51  readLegacyVDriftDB = pSet.getParameter<bool>("readLegacyVDriftDB");
52 
53  nevents = 0;
54 
55  bookingdone = false;
56 
57  if (readLegacyVDriftDB) {
58  mTimeMapToken_ = esConsumes<edm::Transition::BeginRun>();
59  } else {
60  vDriftToken_ = esConsumes<edm::Transition::BeginRun>();
61  }
62 }
63 
65  LogVerbatim("DTDQM|DTMonitorClient|DTRunConditionVarClient") << "DTRunConditionVarClient: Destructor called";
66 }
67 
69  LogTrace("DTDQM|DTMonitorClient|DTResolutionAnalysisTest") << "[DTRunConditionVarClient]: BeginRun";
70  // Get the map of vdrift from the setup
71  if (readLegacyVDriftDB) {
72  mTimeMap_ = &context.getData(mTimeMapToken_);
73  vDriftMap_ = nullptr;
74  } else {
75  vDriftMap_ = &context.getData(vDriftToken_);
76  mTimeMap_ = nullptr;
77  // Consistency check: no parametrization is implemented for the time being
78  int version = vDriftMap_->version();
79  if (version != 1) {
80  throw cms::Exception("Configuration") << "only version 1 is presently supported for VDriftDB";
81  }
82  }
83 }
84 
86  DQMStore::IGetter& igetter,
87  edm::LuminosityBlock const& lumiSeg,
88  edm::EventSetup const& context) {}
89 
91  LogVerbatim("DTDQM|DTMonitorClient|DTRunConditionVarClient") << "DTRunConditionVarClient: end job";
92 
93  ibooker.setCurrentFolder("DT/02-Segments");
94 
95  glbVDriftSummary =
96  ibooker.book2D("VDriftGlbSummary", "# of MBs with good mean and good sigma of vDrift", 12, 1, 13, 5, -2, 3);
97  glbT0Summary = ibooker.book2D("T0GlbSummary", "# of MBs with good mean and good sigma of t0", 12, 1, 13, 5, -2, 3);
98 
99  ibooker.setCurrentFolder("DT/02-Segments/02-MeanVDrift");
100 
101  summaryHistos["MeanVDriftGlbSummary"] =
102  ibooker.book2D("MeanVDriftGlbSummary", "mean VDrift average per sector", 12, 1., 13., 5, -2., 3.);
103  allwheelHistos["allMeanVDrift"] =
104  ibooker.book1D("VDriftMeanAllWheels", "mean VDrift for all chambers", 60, 0.0048, 0.006);
105 
106  ibooker.setCurrentFolder("DT/02-Segments/02-SigmaVDrift");
107 
108  summaryHistos["SigmaVDriftGlbSummary"] =
109  ibooker.book2D("SigmaVDriftGlbSummary", "# of Chambers with good sigma VDrift", 12, 1., 13., 5, -2., 3.);
110  allwheelHistos["allSigmaVDrift"] =
111  ibooker.book1D("VDriftSigmaAllWheels", "sigma VDrift for all chambers", 30, 0., 0.0006);
112 
113  ibooker.setCurrentFolder("DT/02-Segments/03-MeanT0");
114 
115  summaryHistos["MeanT0GlbSummary"] =
116  ibooker.book2D("MeanT0GlbSummary", "mean T0 average per sector", 12, 1., 13., 5, -2., 3.);
117  allwheelHistos["allMeanT0"] = ibooker.book1D("T0MeanAllWheels", "mean T0 for all chambers", 100, -25., 25.);
118 
119  ibooker.setCurrentFolder("DT/02-Segments/03-SigmaT0");
120 
121  summaryHistos["SigmaT0GlbSummary"] =
122  ibooker.book2D("SigmaT0GlbSummary", "# of Chambers with good sigma T0", 12, 1., 13., 5, -2., 3.);
123  allwheelHistos["allSigmaT0"] = ibooker.book1D("T0SigmaAllWheels", "sigma T0 for all chambers", 50, 0, 25);
124 
125  for (int wh = -2; wh <= 2; wh++) {
126  bookWheelHistos(ibooker, "MeanVDrift", "02-MeanVDrift", wh, 60, 0.0048, 0.006, true);
127  bookWheelHistos(ibooker, "SigmaVDrift", "02-SigmaVDrift", wh, 30, 0., 0.0006);
128  bookWheelHistos(ibooker, "MeanT0", "03-MeanT0", wh, 100, -25., 25., false, true);
129  bookWheelHistos(ibooker, "SigmaT0", "03-SigmaT0", wh, 50, 0, 25, false, true);
130  }
131 
132  for (int wheel = -2; wheel <= 2; wheel++) {
133  for (int sec = 1; sec <= 14; sec++) {
134  for (int stat = 1; stat <= 4; stat++) {
135  if ((sec == 13 || sec == 14) && stat != 4)
136  continue;
137 
138  // Get the ME produced by DTRunConditionVar Source
139  MonitorElement* VDriftME = getChamberHistos(igetter, DTChamberId(wheel, stat, sec), "VDrift_FromSegm");
140  MonitorElement* T0ME = getChamberHistos(igetter, DTChamberId(wheel, stat, sec), "T0_FromSegm");
141 
142  if (!VDriftME || !T0ME) {
143  edm::LogWarning("DTRunConditionVarClient") << "ME not available" << std::endl;
144  return;
145  }
146 
147  // Get the means per chamber
148  float vDriftMean = VDriftME->getMean();
149  T0ME->setAxisRange(-15, 15);
150  float t0Mean = T0ME->getMean();
151 
152  // Get the sigma per chamber
153  float vDriftSigma = VDriftME->getRMS();
154  float t0Sigma = T0ME->getRMS();
155 
156  if (VDriftME->getEntries() != 0) {
157  allwheelHistos["allMeanVDrift"]->Fill(vDriftMean);
158  allwheelHistos["allSigmaVDrift"]->Fill(vDriftSigma);
159 
160  (wheelHistos[wheel])["MeanVDrift"]->Fill(vDriftMean);
161  (wheelHistos[wheel])["SigmaVDrift"]->Fill(vDriftSigma);
162  }
163 
164  if (T0ME->getEntries() != 0) {
165  allwheelHistos["allMeanT0"]->Fill(t0Mean);
166  allwheelHistos["allSigmaT0"]->Fill(t0Sigma);
167 
168  (wheelRingHistos[wheel][stat])["MeanT0"]->Fill(t0Mean);
169  (wheelRingHistos[wheel][stat])["SigmaT0"]->Fill(t0Sigma);
170  }
171 
172  DTChamberId indexCh(wheel, stat, sec);
173 
174  float vDriftDev(0.), errvDriftDev(0.);
175  percDevVDrift(indexCh, vDriftMean, vDriftSigma, vDriftDev, errvDriftDev);
176 
177  int sec_ = sec;
178  if (sec == 13 || sec == 14)
179  sec_ = (sec == 13) ? 4 : 10;
180 
181  float fillvDriftDev = max(min(vDriftDev, maxRangeVDrift), minRangeVDrift);
182  float fillT0Mean = max(min(t0Mean, maxRangeT0), minRangeT0);
183 
184  float vDriftDevQ = varQuality(fabs(vDriftDev), maxGoodVDriftDev, minBadVDriftDev);
185  float t0MeanQ = varQuality(fabs(t0Mean), maxGoodT0, minBadT0);
186 
187  float vDriftSigmQ = varQuality(vDriftSigma, maxGoodVDriftSigma, minBadVDriftSigma);
188  float t0SigmQ = varQuality(t0Sigma, maxGoodT0Sigma, minBadT0Sigma);
189 
190  if (sec == 13 || sec == 14) {
191  float binVDriftDev = (wheelHistos[wheel])["MeanVDriftSummary"]->getBinContent(sec_, stat);
192  binVDriftDev = (fabs(binVDriftDev) > fabs(fillvDriftDev)) ? binVDriftDev : fillvDriftDev;
193  (wheelHistos[wheel])["MeanVDriftSummary"]->setBinContent(sec_, stat, binVDriftDev);
194 
195  float binT0MeanVal = (wheelHistos[wheel])["MeanT0Summary"]->getBinContent(sec_, stat);
196  binT0MeanVal = (fabs(binT0MeanVal) > fabs(fillT0Mean)) ? binT0MeanVal : fillT0Mean;
197  (wheelHistos[wheel])["MeanT0Summary"]->setBinContent(sec_, stat, binT0MeanVal);
198 
199  float binVDriftSigmVal = (wheelHistos[wheel])["SigmaVDriftSummary"]->getBinContent(sec_, stat);
200  binVDriftSigmVal = (binVDriftSigmVal > 0. && binVDriftSigmVal < vDriftSigmQ) ? binVDriftSigmVal : vDriftSigmQ;
201  (wheelHistos[wheel])["SigmaVDriftSummary"]->setBinContent(sec_, stat, binVDriftSigmVal);
202 
203  float binT0SigmVal = (wheelHistos[wheel])["SigmaT0Summary"]->getBinContent(sec_, stat);
204  binT0SigmVal = (binT0SigmVal > 0. && binT0SigmVal < t0SigmQ) ? binT0SigmVal : t0SigmQ;
205  (wheelHistos[wheel])["SigmaT0Summary"]->setBinContent(sec_, stat, binT0SigmVal);
206 
207  } else {
208  (wheelHistos[wheel])["MeanVDriftSummary"]->setBinContent(sec_, stat, fillvDriftDev);
209  (wheelHistos[wheel])["MeanT0Summary"]->setBinContent(sec_, stat, fillT0Mean);
210  (wheelHistos[wheel])["SigmaVDriftSummary"]->setBinContent(sec_, stat, vDriftSigmQ);
211  (wheelHistos[wheel])["SigmaT0Summary"]->setBinContent(sec_, stat, t0SigmQ);
212  }
213 
214  double weight = 1 / 4.;
215  if ((sec_ == 4 || sec_ == 10) && stat == 4)
216  weight = 1 / 8.;
217 
218  if (vDriftDevQ > 0.85 && vDriftSigmQ > 0.85) {
219  glbVDriftSummary->Fill(sec_, wheel, weight);
220  summaryHistos["MeanVDriftGlbSummary"]->Fill(sec_, wheel, weight);
221  summaryHistos["SigmaVDriftGlbSummary"]->Fill(sec_, wheel, weight);
222 
223  } else {
224  if (vDriftDevQ > 0.85 && vDriftSigmQ < 0.85) {
225  summaryHistos["MeanVDriftGlbSummary"]->Fill(sec_, wheel, weight);
226  }
227  if (vDriftDevQ < 0.85 && vDriftSigmQ > 0.85) {
228  summaryHistos["SigmaVDriftGlbSummary"]->Fill(sec_, wheel, weight);
229  }
230  }
231 
232  if (t0MeanQ > 0.85 && t0SigmQ > 0.85) {
233  glbT0Summary->Fill(sec_, wheel, weight);
234  summaryHistos["MeanT0GlbSummary"]->Fill(sec_, wheel, weight);
235  summaryHistos["SigmaT0GlbSummary"]->Fill(sec_, wheel, weight);
236  } else {
237  if (t0MeanQ > 0.85 && t0SigmQ < 0.85) {
238  summaryHistos["MeanT0GlbSummary"]->Fill(sec_, wheel, weight);
239  }
240  if (t0MeanQ < 0.85 && t0SigmQ > 0.85) {
241  summaryHistos["SigmaT0GlbSummary"]->Fill(sec_, wheel, weight);
242  }
243  }
244 
245  } // end loop on stations
246  } // end loop on sectors
247  } //end loop on wheels
248 
249  return;
250 }
251 
252 float DTRunConditionVarClient::varQuality(float var, float maxGood, float minBad) {
253  float qual(0);
254  if (var <= maxGood) {
255  qual = 1.;
256  } else if (var > maxGood && var < minBad) {
257  qual = 0.9;
258  } else if (var >= minBad) {
259  qual = 0.1;
260  }
261 
262  return qual;
263 }
264 
266  DTChamberId indexCh, float meanVD, float sigmaVD, float& devVD, float& errdevVD) {
267  DTSuperLayerId indexSLPhi1(indexCh, 1);
268  DTSuperLayerId indexSLPhi2(indexCh, 3);
269 
270  float vDriftPhi1(0.), vDriftPhi2(0.);
271  float ResPhi1(0.), ResPhi2(0.);
272  if (readLegacyVDriftDB) { // Legacy format
273  int status1 = mTimeMap_->get(indexSLPhi1, vDriftPhi1, ResPhi1, DTVelocityUnits::cm_per_ns);
274  int status2 = mTimeMap_->get(indexSLPhi2, vDriftPhi2, ResPhi2, DTVelocityUnits::cm_per_ns);
275 
276  if (status1 != 0 || status2 != 0) {
277  DTSuperLayerId sl = (status1 != 0) ? indexSLPhi1 : indexSLPhi2;
278  throw cms::Exception("DTRunConditionVarClient") << "Could not find vDrift entry in DB for" << sl << endl;
279  }
280  } else {
281  vDriftPhi1 = vDriftMap_->get(DTWireId(indexSLPhi1.rawId()));
282  vDriftPhi2 = vDriftMap_->get(DTWireId(indexSLPhi2.rawId()));
283  }
284 
285  float vDriftMed = (vDriftPhi1 + vDriftPhi2) / 2.;
286 
287  devVD = (meanVD - vDriftMed) / vDriftMed;
288  devVD = devVD < 1. ? devVD : 1.;
289 
290  errdevVD = sigmaVD / vDriftMed;
291 
292  return;
293 }
294 
296  string histoType,
297  string subfolder,
298  int wh,
299  int nbins,
300  float min,
301  float max,
302  bool isVDCorr,
303  bool makeRings) {
304  stringstream wheel;
305  wheel << wh;
306 
307  string folder = "DT/02-Segments/" + subfolder;
308 
309  ibooker.setCurrentFolder(folder);
310 
311  string histoName;
312  string histoLabel;
313 
314  if (makeRings) {
315  ibooker.setCurrentFolder(folder + "/Wheel" + wheel.str());
316  for (int st = 1; st <= 4; st++) {
317  stringstream station;
318  station << st;
319 
320  histoName = histoType + "_W" + wheel.str() + "_MB" + station.str();
321  histoLabel = histoType;
322 
323  (wheelRingHistos[wh][st])[histoType] = ibooker.book1D(histoName, histoLabel, nbins, min, max);
324  }
325  } else {
326  histoName = histoType + "_W" + wheel.str();
327  histoLabel = histoType;
328 
329  (wheelHistos[wh])[histoType] = ibooker.book1D(histoName, histoLabel, nbins, min, max);
330  }
331 
332  ibooker.setCurrentFolder(folder);
333 
334  if (isVDCorr) {
335  histoLabel = "Summary of corrections to VDrift DB values";
336  histoName = "CorrTo" + histoType + "Summary_W" + wheel.str();
337  } else {
338  histoLabel = histoType + "Summary";
339  histoName = histoType + "Summary_W" + wheel.str();
340  }
341 
342  MonitorElement* me = ibooker.book2D(histoName, histoLabel, 12, 1, 13, 4, 1, 5);
343 
344  me->setBinLabel(1, "MB1", 2);
345  me->setBinLabel(2, "MB2", 2);
346  me->setBinLabel(3, "MB3", 2);
347  me->setBinLabel(4, "MB4", 2);
348  me->setAxisTitle("Sector", 1);
349 
350  (wheelHistos[wh])[histoType + "Summary"] = me;
351 
352  return;
353 }
354 
356  const DTChamberId& dtCh,
357  string histoType) {
358  int wh = dtCh.wheel();
359  int sc = dtCh.sector();
360  int st = dtCh.station();
361  stringstream wheel;
362  wheel << wh;
363  stringstream station;
364  station << st;
365  stringstream sector;
366  sector << sc;
367 
368  string folder = "DT/02-Segments/Wheel" + wheel.str() + "/Sector" + sector.str() + "/Station" + station.str();
369  string histoTag = "_W" + wheel.str() + "_Sec" + sector.str() + "_St" + station.str();
370  string MEpath = folder + "/" + histoType + histoTag;
371 
372  igetter.setCurrentFolder(folder);
373 
374  LogTrace("DTDQM|DTMonitorModule|DTRunConditionVar") << "[DTRunConditionVar]: getting ME from " << folder << endl;
375 
376  MonitorElement* ME = igetter.get(MEpath);
377 
378  return ME;
379 }
Log< level::Info, true > LogVerbatim
int station() const
Return the station number.
Definition: DTChamberId.h:42
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
void dqmEndLuminosityBlock(DQMStore::IBooker &, DQMStore::IGetter &, edm::LuminosityBlock const &, edm::EventSetup const &) override
DQM Client Diagnostic.
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
Definition: weight.py:1
MonitorElement * getChamberHistos(DQMStore::IGetter &, const DTChamberId &, std::string)
float varQuality(float var, float maxGood, float minBad)
#define LogTrace(id)
T getUntrackedParameter(std::string const &, T const &) const
Definition: ME.h:11
virtual double getRMS(int axis=1) const
get RMS of histogram along x, y or z axis (axis=1, 2, 3 respectively)
virtual void setAxisRange(double xmin, double xmax, int axis=1)
set x-, y- or z-axis range (axis=1, 2, 3 respectively)
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void percDevVDrift(DTChamberId indexCh, float meanVD, float sigmaVD, float &devVD, float &errdevVD)
EventID const & min(EventID const &lh, EventID const &rh)
Definition: EventID.h:116
virtual double getEntries() const
get # of entries
DTRunConditionVarClient(const edm::ParameterSet &ps)
Constructor.
void bookWheelHistos(DQMStore::IBooker &, std::string histoType, std::string subfolder, int wh, int nbins, float min, float max, bool isVDCorr=false, bool makeRings=false)
book the report summary
~DTRunConditionVarClient() override
Destructor.
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:212
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:680
void beginRun(const edm::Run &r, const edm::EventSetup &c) override
virtual double getMean(int axis=1) const
get mean value of histogram along x, y or z axis (axis=1, 2, 3 respectively)
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:39
HLT enums.
int sector() const
Definition: DTChamberId.h:49
dqm::harvesting::MonitorElement ME
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Definition: Run.h:45
EventID const & max(EventID const &lh, EventID const &rh)
Definition: EventID.h:118