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