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