CMS 3D CMS Logo

CastorDigiMonitor.cc
Go to the documentation of this file.
1 //****************************************************//
2 //********** CastorDigiMonitor: ******************//
3 //********** Author: Dmytro Volyanskyy *************//
4 //********** Date : 29.08.2008 (first version) ******//
8 //****************************************************//
9 //---- critical revision 26.06.2014 (Vladimir Popov)
10 // add rms check, DB 15.04.2015 (Vladimir Popov)
11 //==================================================================//
12 
21 
22 #include <string>
23 
24 using namespace std;
25 using namespace edm;
26 
27 namespace {
28  vector<std::string> HltPaths_;
29  int StatusBadChannel = 1;
30  int ChannelStatus[14][16]{};
31  int N_GoodChannels = 224;
32  int EtowerLastModule = 5;
33  int TrigIndexMax = 0;
34 } // namespace
35 
37  : castorChannelQualityToken_{
39  fVerbosity = ps.getUntrackedParameter<int>("debug", 0);
40  subsystemname_ = ps.getUntrackedParameter<std::string>("subSystemFolder", "Castor");
41  EtowerLastModule = ps.getUntrackedParameter<int>("towerLastModule", 6);
42  RatioThresh1 = ps.getUntrackedParameter<double>("ratioThreshold", 0.9);
43  Qrms_DEAD = ps.getUntrackedParameter<double>("QrmsDead", 0.01); // fC
44  HltPaths_ = ps.getParameter<vector<string>>("HltPaths");
45 
46  Qrms_DEAD = Qrms_DEAD * Qrms_DEAD;
47  TS_MAX = ps.getUntrackedParameter<double>("qieTSmax", 6);
48  StatusBadChannel = CastorChannelStatus::StatusBit::BAD;
49  if (fVerbosity > 0)
50  LogPrint("CastorDigi") << "enum CastorChannelStatus::StatusBit::BAD=" << StatusBadChannel
51  << "EtowerLastModule = " << EtowerLastModule << endl;
52 }
53 
55 
57  const edm::Run &iRun,
58  const edm::EventSetup &iSetup) {
59  char s[60];
60  string st;
61  if (fVerbosity > 0)
62  LogPrint("CastorMonitorModule") << "Digi bookHist(start)";
63 
64  getDbData(iSetup);
65 
66  char sTileIndex[50];
67  sprintf(sTileIndex, "Cell(=moduleZ*16+sector#phi)");
68 
69  ievt_ = 0;
70 
72  hBX = ibooker.bookProfile(
73  "average E(digi) in BX", "Castor average E (digi);Event.BX;fC", 3601, -0.5, 3600.5, 0., 1.e10, "");
74  hBX->getTProfile()->SetOption("hist");
75 
76  string trname = HltPaths_[0];
77  hpBXtrig = ibooker.bookProfile("average E(digi) in BXtrig",
78  "Castor average E (digi) trigger:'" + trname + "';Event.BX;fC",
79  3601,
80  -0.5,
81  3600.5,
82  0.,
83  1.e10,
84  "");
85  hpBXtrig->getTProfile()->SetOption("hist");
86 
87  hpTrigRes = ibooker.bookProfile(
88  "E(digi)vsTriggerIndex", "Castor average E(digi) by triggerIndex;triggerIndex;fC", 512, 0., 512, 0., 1.e10, "");
89  hpTrigRes->getTProfile()->SetOption("hist");
90 
91  ibooker.setCurrentFolder(subsystemname_ + "/CastorDigiMonitor");
92 
93  std::string s2 = "CASTOR QIE_capID+er+dv";
94  h2digierr = ibooker.bookProfile2D(s2, s2, 14, 0., 14., 16, 0., 16., 100, 0, 1.e10, "");
95  h2digierr->getTProfile2D()->GetXaxis()->SetTitle("Module Z");
96  h2digierr->getTProfile2D()->GetYaxis()->SetTitle("Sector #phi");
97  h2digierr->getTProfile2D()->SetMaximum(1.);
98  h2digierr->getTProfile2D()->SetMinimum(QIEerrThreshold);
99  h2digierr->getTProfile2D()->SetOption("colz");
100 
101  sprintf(s, "CASTORreportSummaryMap");
102  h2repsum = ibooker.bookProfile2D(s, s, 14, 0., 14., 16, 0., 16., 100, 0, 1.e10, "");
103  h2repsum->getTProfile2D()->GetXaxis()->SetTitle("Module Z");
104  h2repsum->getTProfile2D()->GetYaxis()->SetTitle("Sector #phi");
105  h2repsum->getTProfile2D()->SetMaximum(1.);
106  h2repsum->getTProfile2D()->SetMinimum(QIEerrThreshold);
107  h2repsum->getTProfile2D()->SetOption("colz");
108 
109  sprintf(s, "CASTOR BadChannelsMap");
110  h2status = ibooker.book2D(s, s, 14, 0., 14., 16, 0., 16.);
111  h2status->setAxisTitle("Module Z");
112  h2status->setAxisTitle("Sector #phi", /* axis */ 2);
113  h2status->setOption("colz");
114 
115  sprintf(s, "CASTOR TSmax Significance Map");
116  h2TSratio = ibooker.book2D(s, s, 14, 0., 14., 16, 0., 16.);
117  h2TSratio->setAxisTitle("Module Z");
118  h2TSratio->setAxisTitle("Sector #phi", /* axis */ 2);
119  h2TSratio->setOption("colz");
120 
121  sprintf(s, "CASTOR TSmax Significance All chan");
122  hTSratio = ibooker.book1D(s, s, 105, 0., 1.05);
123 
124  sprintf(s, "DigiSize");
125  hdigisize = ibooker.book1DD(s, s, 20, 0., 20.);
126  sprintf(s, "ModuleZ(fC)_allTS");
127  hModule = ibooker.book1D(s, s, 14, 0., 14.);
128  hModule->setAxisTitle("ModuleZ");
129  hModule->setAxisTitle("QIE(fC)", /* axis */ 2);
130  sprintf(s, "Sector #phi(fC)_allTS");
131  hSector = ibooker.book1D(s, s, 16, 0., 16.);
132  hSector->setAxisTitle("Sector #phi");
133  hSector->setAxisTitle("QIE(fC)", /* axis */ 2);
134 
135  st = "Castor cells avr digi(fC) per event Map TS vs Channel";
136  h2QmeantsvsCh =
137  ibooker.bookProfile2D(st, st + ";" + string(sTileIndex) + ";TS", 224, 0., 224., 10, 0., 10., 0., 1.e10, "");
138  h2QmeantsvsCh->getTProfile2D()->SetOption("colz");
139 
140  st = "Castor cells avr digiRMS(fC) per event Map TS vs Channel";
141  h2QrmsTSvsCh = ibooker.book2D(st, st + ";" + string(sTileIndex) + ";TS", 224, 0., 224., 10, 0., 10.);
142  h2QrmsTSvsCh->setOption("colz");
143 
144  sprintf(s, "CASTOR data quality");
145  h2qualityMap = ibooker.book2D(s, s, 14, 0, 14, 16, 0, 16);
146  h2qualityMap->setAxisTitle("module Z");
147  h2qualityMap->setAxisTitle("Sector #phi", /* axis */ 2);
148  h2qualityMap->setOption("colz");
149 
150  hReport = ibooker.bookFloat("CASTOR reportSummary");
151 
152  sprintf(s, "QmeanfC_map(allTS)");
153  h2QmeanMap = ibooker.book2D(s, s, 14, 0., 14., 16, 0., 16.);
154  h2QmeanMap->setAxisTitle("Module Z");
155  h2QmeanMap->setAxisTitle("Sector #phi", /* axis */ 2);
156  h2QmeanMap->setOption("textcolz");
157 
158  const int NEtow = 20;
159  float EhadTow[NEtow + 1];
160  float EMTow[NEtow + 1];
161  float ETower[NEtow + 2];
162  double E0tow = 500. / 1024.;
163  EMTow[0] = 0.;
164  EMTow[1] = E0tow;
165  EhadTow[0] = 0.;
166  EhadTow[1] = E0tow;
167  ETower[0] = 0.;
168  ETower[1] = E0tow;
169  double lnBtow = log(1.8); // 2.
170  for (int j = 1; j < NEtow; j++)
171  EMTow[j + 1] = E0tow * exp(j * lnBtow);
172  for (int j = 1; j < NEtow; j++)
173  EhadTow[j + 1] = E0tow * exp(j * lnBtow);
174  for (int j = 1; j <= NEtow; j++)
175  ETower[j + 1] = E0tow * exp(j * lnBtow);
176 
177  sprintf(s, "CASTOR_Tower_EMvsEhad(fC)");
178  h2towEMvsHAD = ibooker.book2D(s, s, NEtow, EhadTow, NEtow, EMTow);
179  h2towEMvsHAD->setAxisTitle("Ehad [fC]");
180  h2towEMvsHAD->setAxisTitle("EM [fC]", /* axis */ 2);
181  h2towEMvsHAD->setOption("colz");
182 
183  sprintf(s, "CASTOR_TowerTotalEnergy(fC)");
184  htowE = ibooker.book1D(s, s, NEtow + 1, ETower);
185  htowE->setAxisTitle("fC");
186 
187  for (int ts = 0; ts <= 1; ts++) {
188  sprintf(s, "QIErms_TS=%d", ts);
189  hQIErms[ts] = ibooker.book1D(s, s, 1000, 0., 100.);
190  hQIErms[ts]->setAxisTitle("QIErms(fC)");
191  }
192 
193  for (int ind = 0; ind < 224; ind++)
194  for (int ts = 0; ts < 10; ts++)
195  QrmsTS[ind][ts] = QmeanTS[ind][ts] = 0.;
196 
197  return;
198 }
199 
203  const CastorDbService &cond) {
204  if (fVerbosity > 1)
205  LogPrint("CastorDigiMonitor") << "processEvent(begin)";
206 
207  if (castorDigis.empty()) {
208  for (int mod = 0; mod < 14; mod++)
209  for (int sec = 0; sec < 16; sec++)
210  h2repsum->Fill(mod, sec, 0.);
211  hBX->Fill(event.bunchCrossing(), 0.);
213  return;
214  }
215 
216  float Ecell[14][16]{};
217  for (CastorDigiCollection::const_iterator j = castorDigis.begin(); j != castorDigis.end(); j++) {
218  const CastorDataFrame digi = (const CastorDataFrame)(*j);
219 
220  int module = digi.id().module() - 1;
221  int sector = digi.id().sector() - 1;
222  if (ChannelStatus[module][sector] == StatusBadChannel)
223  continue;
224 
225  int capid1 = digi.sample(0).capid();
226  hdigisize->Fill(digi.size());
227  int err = 0, err2 = 0;
228  for (int i = 0; i < digi.size(); i++) {
229  int capid = digi.sample(i).capid();
230  int dv = digi.sample(i).dv();
231  int er = digi.sample(i).er();
232  int rawd = digi.sample(i).adc();
233  rawd = rawd & 0x7F;
234  err |= (capid != capid1) | er << 1 | (!dv) << 2; // =0
235  err2 += (capid != capid1) | er | (!dv); // =0
236  // if(err !=0) continue;
237  int ind = ModSecToIndex(module, sector);
238  h2QmeantsvsCh->Fill(ind, i, LedMonAdc2fc[rawd]);
239  float q = LedMonAdc2fc[rawd];
240  Ecell[module][sector] = q;
241  QrmsTS[ind][i] += (q * q);
242  QmeanTS[ind][i] += q;
243  if (err != 0 && fVerbosity > 0)
244  LogPrint("CastorDigiMonitor") << "event/idigi=" << ievt_ << "/" << i << " cap=cap1_dv_er_err: " << capid << "="
245  << capid1 << " " << dv << " " << er << " " << err;
246  if (capid1 < 3)
247  capid1 = capid + 1;
248  else
249  capid1 = 0;
250  }
252  h2repsum->Fill(module, sector, 1. - err2 / digi.size());
253  } // end for(CastorDigiCollection::const_iterator ...
254 
255  ievt_++;
256 
257  double Etotal = 0.;
258  for (int sec = 0; sec < 16; sec++)
259  for (int mod = 0; mod < 14; mod++)
260  Etotal = Ecell[mod][sec];
261  hBX->Fill(event.bunchCrossing(), Etotal);
262  fillTrigRes(event, TrigResults, Etotal);
263 
264  for (int sec = 0; sec < 16; sec++) {
265  float em = Ecell[0][sec] + Ecell[1][sec];
266  double ehad = 0.;
267  for (int mod = 2; mod < EtowerLastModule; mod++)
268  ehad += Ecell[mod][sec];
269  h2towEMvsHAD->Fill(em, ehad);
270  htowE->Fill(em + ehad);
271  }
272 
273  const float repChanBAD = 0.9;
274  const float repChanWarning = 0.95;
275  if (ievt_ % 100 != 0)
276  return;
277 
278  float ModuleSum[14], SectorSum[16];
279  for (int m = 0; m < 14; m++)
280  ModuleSum[m] = 0.;
281  for (int s = 0; s < 16; s++)
282  SectorSum[s] = 0.;
283  for (int mod = 0; mod < 14; mod++)
284  for (int sec = 0; sec < 16; sec++) {
285  for (int ts = 0; ts <= 1; ts++) {
286  int ind = ModSecToIndex(mod, sec);
287  double Qmean = QmeanTS[ind][ts] / ievt_;
288  double Qrms = sqrt(QrmsTS[ind][ts] / ievt_ - Qmean * Qmean);
289  hQIErms[ts]->Fill(Qrms);
290  }
291 
292  double sum = 0.;
293  for (int ts = 1; ts <= TS_MAX; ts++) {
294  int ind = ModSecToIndex(mod, sec) + 1;
295  double a = //(1) h2QtsvsCh->getTH2D()->GetBinContent(ind,ts);
296  h2QmeantsvsCh->getTProfile2D()->GetBinContent(ind, ts);
297  sum += a;
298  double Qmean = QmeanTS[ind - 1][ts - 1] / ievt_;
299  double Qrms = QrmsTS[ind - 1][ts - 1] / ievt_ - Qmean * Qmean;
300  h2QrmsTSvsCh->setBinContent(ind, ts, sqrt(Qrms));
301  }
302  ModuleSum[mod] += sum;
303  SectorSum[sec] += sum;
304  float isum = float(int(sum * 10. + 0.5)) / 10.;
305  if (ChannelStatus[mod][sec] != StatusBadChannel)
306  h2QmeanMap->setBinContent(mod + 1, sec + 1, isum);
307  } // end for(int mod=0; mod<14; mod++) for(int sec=0;...
308 
309  for (int mod = 0; mod < 14; mod++)
310  hModule->setBinContent(mod + 1, ModuleSum[mod]);
311  for (int sec = 0; sec < 16; sec++)
312  hSector->setBinContent(sec + 1, SectorSum[sec]);
313 
314  int nGoodCh = 0;
315  hTSratio->Reset();
316  for (int mod = 0; mod < 14; mod++)
317  for (int sec = 0; sec < 16; sec++) {
318  if (ChannelStatus[mod][sec] == StatusBadChannel)
319  continue;
320  int ind = ModSecToIndex(mod, sec);
321  double Qmean = QmeanTS[ind][TSped] / ievt_;
322  double Qrms = QrmsTS[ind][TSped] / ievt_ - Qmean * Qmean;
323  float ChanStatus = 0.;
324  if (Qrms < Qrms_DEAD)
325  ChanStatus = 1.;
326  h2status->setBinContent(mod + 1, sec + 1, ChanStatus);
327 
328  float am = 0.;
329  for (int ts = 0; ts < TS_MAX - 1; ts++) {
330  float a = h2QmeantsvsCh->getTProfile2D()->GetBinContent(ind + 1, ts + 1) +
331  h2QmeantsvsCh->getTProfile2D()->GetBinContent(ind + 1, ts + 2);
332  if (am < a)
333  am = a;
334  }
335 
336  double sum = 0.;
337  for (int ts = 0; ts < TS_MAX; ts++)
338  sum += h2QmeantsvsCh->getTProfile2D()->GetBinContent(ind + 1, ts + 1);
339 
340  float r = 0.; // worth case - no peak
341  if (am > 0.)
342  r = 1. - (sum - am) / (TS_MAX - 2) / am * 2.;
343  // if(r<0.|| r>1.) cout<<"ievt="<<ievt<<" r="<<r<<" amax= "<<am<<"
344  // sum="<<sum<<endl;
345  h2TSratio->setBinContent(mod + 1, sec + 1, r);
346  hTSratio->Fill(r);
347 
348  float statusTS = 1.0;
349  if (r > RatioThresh1)
350  statusTS = repChanWarning;
351  else if (r > 0.99)
352  statusTS = repChanBAD;
353  float gChanStatus = statusTS;
354  if (ChanStatus > 0.)
355  gChanStatus = repChanBAD; // RMS
356  h2qualityMap->setBinContent(mod + 1, sec + 1, gChanStatus);
357  if (gChanStatus > repChanBAD)
358  ++nGoodCh;
359  }
360  hReport->Fill(float(nGoodCh) / N_GoodChannels);
361  return;
362 }
363 
365  if (fVerbosity > 0)
366  LogPrint("CastorDigiMonitor") << "DigiMonitor::endRun: trigger max index = " << TrigIndexMax
367  << " TriggerIndexies(N):" << endl;
368  for (int i = 1; i < hpTrigRes->getTProfile()->GetNbinsX(); i++)
369  if (hpTrigRes->getTProfile()->GetBinContent(i) > 0)
370  LogPrint("CastorDigiMonitor") << i - 1 << "(" << hpTrigRes->getTProfile()->GetBinContent(i) << ") ";
371 }
372 
374  int nTriggers = TrigResults.size();
375  const edm::TriggerNames &trigName = event.triggerNames(TrigResults);
376  bool event_triggered = false;
377  if (nTriggers > 0)
378  for (int iTrig = 0; iTrig < nTriggers; ++iTrig) {
379  if (TrigResults.accept(iTrig)) {
380  int index = trigName.triggerIndex(trigName.triggerName(iTrig));
381  if (TrigIndexMax < index)
382  TrigIndexMax = index;
383  if (fVerbosity > 0)
384  LogPrint("CastorDigi") << "trigger[" << iTrig << "] name:" << trigName.triggerName(iTrig)
385  << " index= " << index << endl;
386  hpTrigRes->Fill(index, Etotal);
387  for (int n = 0; n < int(HltPaths_.size()); n++) {
388  if (trigName.triggerName(iTrig).find(HltPaths_[n]) != std::string::npos)
389  event_triggered = true;
390  }
391  } // end if(TrigResults.accept(iTrig)
392  }
393 
394  if (event_triggered)
395  hpBXtrig->Fill(event.bunchCrossing(), Etotal);
396  return;
397 }
398 
401  if (fVerbosity > 0) {
402  LogPrint("CastorDigiMonitor") << " CastorChQuality in CondDB=" << dbChQuality.isValid() << endl;
403  }
404 
405  int chInd = 0;
406  for (int mod = 0; mod < 14; mod++)
407  for (int sec = 0; sec < 16; sec++)
408  ChannelStatus[mod][sec] = 0;
409  std::vector<DetId> channels = dbChQuality->getAllChannels();
410  N_GoodChannels = 224 - channels.size();
411  if (fVerbosity > 0)
412  LogPrint("CastorDigiMonitor") << "CastorDigiMonitor::getDBData: QualityRcdSize=" << channels.size();
413  for (std::vector<DetId>::iterator ch = channels.begin(); ch != channels.end(); ch++) {
414  const CastorChannelStatus *quality = dbChQuality->getValues(*ch);
415  int value = quality->getValue();
416  int rawId = quality->rawId();
417  chInd++;
418  int mod = HcalCastorDetId(*ch).module() - 1;
419  int sec = HcalCastorDetId(*ch).sector() - 1;
420  if (mod > 0 && mod < 16 && sec > 0 && sec < 16)
422  if (fVerbosity > 0)
423  LogPrint("CastorDigiMonitor") << chInd << " module=" << mod << " sec=" << sec << " rawId=" << rawId
424  << " value=" << value << endl;
425  } // end for(std::vector<DetId>::it...
426  return;
427 }
428 
430  int ind = sector + module * 16;
431  if (ind > 223)
432  ind = 223;
433  return (ind);
434 }
MonitorElement * h2towEMvsHAD
MonitorElement * h2TSratio
MonitorElement * bookFloat(TString const &name, FUNC onbooking=NOOP())
Definition: DQMStore.h:80
MonitorElement * bookProfile2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:476
double QrmsTS[224][10]
virtual TProfile * getTProfile() const
const Item * getValues(DetId fId, bool throwOnFail=true) const
MonitorElement * h2qualityMap
const HcalQIESample & sample(int i) const
access a sample
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
MonitorElement * hTSratio
virtual void setOption(const char *option)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, const edm::EventSetup &)
constexpr bool dv() const
is the Data Valid bit set?
Definition: HcalQIESample.h:49
std::vector< T >::const_iterator const_iterator
MonitorElement * hpTrigRes
double isum
std::vector< DetId > getAllChannels() const
void processEvent(edm::Event const &event, const CastorDigiCollection &cast, const edm::TriggerResults &trig, const CastorDbService &cond)
MonitorElement * h2status
void Fill(long long x)
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
MonitorElement * h2digierr
MonitorElement * hModule
string quality
int size() const
total number of samples in the digi
MonitorElement * book1DD(TString const &name, TString const &title, int nchX, double lowX, double highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:155
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
T sqrt(T t)
Definition: SSEVec.h:19
int module() const
get the module (1-2 for EM, 1-12 for HAD)
MonitorElement * h2QmeanMap
edm::ESGetToken< CastorChannelQuality, CastorChannelQualityRcd > castorChannelQualityToken_
Definition: value.py:1
int sector() const
get the sector (1-16)
Log< level::Warning, true > LogPrint
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
void fillTrigRes(edm::Event const &event, const edm::TriggerResults &TrigResults, double Etot)
std::string subsystemname_
bool isValid() const
Definition: ESHandle.h:44
MonitorElement * h2QrmsTSvsCh
const HcalCastorDetId & id() const
double const BAD
Definition: Constants.h:15
static const float LedMonAdc2fc[128]
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
MonitorElement * hBX
int ModSecToIndex(int module, int sector)
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
CastorDigiMonitor(const edm::ParameterSet &ps, edm::ConsumesCollector &&)
MonitorElement * hdigisize
MonitorElement * hSector
constexpr int capid() const
get the Capacitor id
Definition: HcalQIESample.h:47
constexpr bool er() const
is the error bit set?
Definition: HcalQIESample.h:51
HLT enums.
constexpr int adc() const
get the ADC sample
Definition: HcalQIESample.h:43
double a
Definition: hdecay.h:121
virtual TProfile2D * getTProfile2D() const
double QmeanTS[224][10]
MonitorElement * h2repsum
void getDbData(const edm::EventSetup &)
MonitorElement * hQIErms[10]
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
MonitorElement * hReport
Definition: event.py:1
Definition: Run.h:45
MonitorElement * htowE
MonitorElement * h2QmeantsvsCh
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
MonitorElement * hpBXtrig