CMS 3D CMS Logo

CastorPedestalAnalysis.cc
Go to the documentation of this file.
8 
11 #include <TFile.h>
12 #include <cmath>
13 
15  : fRefPedestals(nullptr),
16  fRefPedestalWidths(nullptr),
17  fRawPedestals(nullptr),
18  fRawPedestalWidths(nullptr),
19  fValPedestals(nullptr),
20  fValPedestalWidths(nullptr) {
21  evt = 0;
22  sample = 0;
23  m_file = nullptr;
24  m_AllPedsOK = 0;
25  for (int i = 0; i < 4; i++)
26  m_stat[i] = 0;
27  for (int k = 0; k < 4; k++)
28  state.push_back(true);
29 
30  // user cfg parameters
31  m_outputFileMean = ps.getUntrackedParameter<std::string>("outputFileMeans", "");
32  if (!m_outputFileMean.empty()) {
33  edm::LogWarning("Castor") << "Castor pedestal means will be saved to " << m_outputFileMean.c_str();
34  }
35  m_outputFileWidth = ps.getUntrackedParameter<std::string>("outputFileWidths", "");
36  if (!m_outputFileWidth.empty()) {
37  edm::LogWarning("Castor") << "Castor pedestal widths will be saved to " << m_outputFileWidth.c_str();
38  }
39  m_outputFileROOT = ps.getUntrackedParameter<std::string>("outputFileHist", "");
40  if (!m_outputFileROOT.empty()) {
41  edm::LogWarning("Castor") << "Castor pedestal histograms will be saved to " << m_outputFileROOT.c_str();
42  }
43  m_nevtsample = ps.getUntrackedParameter<int>("nevtsample", 0);
44  // for compatibility with previous versions
45  if (m_nevtsample == 9999999)
46  m_nevtsample = 0;
47  m_pedsinADC = ps.getUntrackedParameter<int>("pedsinADC", 0);
48  m_hiSaveflag = ps.getUntrackedParameter<int>("hiSaveflag", 0);
49  m_pedValflag = ps.getUntrackedParameter<int>("pedValflag", 0);
50  if (m_pedValflag < 0)
51  m_pedValflag = 0;
52  if (m_nevtsample > 0 && m_pedValflag > 0) {
53  edm::LogWarning("Castor") << "WARNING - incompatible cfg options: nevtsample = " << m_nevtsample
54  << ", pedValflag = " << m_pedValflag;
55  edm::LogWarning("Castor") << "Setting pedValflag = 0";
56  m_pedValflag = 0;
57  }
58  if (m_pedValflag > 1)
59  m_pedValflag = 1;
60  m_startTS = ps.getUntrackedParameter<int>("firstTS", 0);
61  if (m_startTS < 0)
62  m_startTS = 0;
63  m_endTS = ps.getUntrackedParameter<int>("lastTS", 9);
64 
65  // m_logFile.open("CastorPedestalAnalysis.log");
66 
67  castorHists.ALLPEDS = new TH1F("Castor All Pedestals", "HF All Peds", 10, 0, 9);
68  castorHists.PEDRMS = new TH1F("Castor All Pedestal Widths", "HF All Pedestal RMS", 100, 0, 3);
69  castorHists.PEDMEAN = new TH1F("Castor All Pedestal Means", "HF All Pedestal Means", 100, 0, 9);
70  castorHists.CHI2 = new TH1F("Castor Chi2/ndf for whole range Gauss fit", "HF Chi2/ndf Gauss", 200, 0., 50.);
71 }
72 
73 //-----------------------------------------------------------------------------
75  for (_meot = castorHists.PEDTRENDS.begin(); _meot != castorHists.PEDTRENDS.end(); _meot++) {
76  for (int i = 0; i < 16; i++)
77  _meot->second[i].first->Delete();
78  }
79 
80  castorHists.ALLPEDS->Delete();
81  castorHists.PEDRMS->Delete();
82  castorHists.PEDMEAN->Delete();
83  castorHists.CHI2->Delete();
84 }
85 
86 //-----------------------------------------------------------------------------
87 void CastorPedestalAnalysis::setup(const std::string& m_outputFileROOT) {
88  // open the histogram file, create directories within
89  m_file = new TFile(m_outputFileROOT.c_str(), "RECREATE");
90  m_file->mkdir("Castor");
91  m_file->cd();
92 }
93 
94 //-----------------------------------------------------------------------------
96  evt++;
97  sample = 1;
98  evt_curr = evt;
99  if (m_nevtsample > 0) {
100  sample = (evt - 1) / m_nevtsample + 1;
102  if (evt_curr == 0)
104  }
105 
106  m_shape = cond.getCastorShape();
107  // HF
108  try {
109  if (castor.empty())
110  throw (int)castor.size();
111  for (CastorDigiCollection::const_iterator j = castor.begin(); j != castor.end(); ++j) {
112  const CastorDataFrame digi = (const CastorDataFrame)(*j);
113  m_coder = cond.getCastorCoder(digi.id());
114  for (int i = m_startTS; i < digi.size() && i <= m_endTS; i++) {
115  for (int flag = 0; flag < 4; flag++) {
116  if (i + flag < digi.size() && i + flag <= m_endTS) {
117  per2CapsHists(flag, 2, digi.id(), digi.sample(i), digi.sample(i + flag), castorHists.PEDTRENDS, cond);
118  }
119  }
120  }
121  if (m_startTS == 0 && m_endTS > 4) {
122  AllChanHists(digi.id(),
123  digi.sample(0),
124  digi.sample(1),
125  digi.sample(2),
126  digi.sample(3),
127  digi.sample(4),
128  digi.sample(5),
129  castorHists.PEDTRENDS);
130  }
131  }
132  } catch (int i) {
133  // m_logFile << "Event with " << i<<" Castor Digis passed." << std::endl;
134  }
135  // Call the function every m_nevtsample events
136  if (m_nevtsample > 0) {
137  if (evt % m_nevtsample == 0)
138  SampleAnalysis();
139  }
140 }
141 
142 //-----------------------------------------------------------------------------
144  int id,
145  const HcalDetId detid,
146  const HcalQIESample& qie1,
147  const HcalQIESample& qie2,
148  std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT,
149  const CastorDbService& cond) {
150  // this function is due to be called for every time slice, it fills either a charge
151  // histo for a single capID (flag=0) or a product histo for two capIDs (flag>0)
152 
153  static const int bins = 10;
154  static const int bins2 = 100;
155  float lo = -0.5;
156  float hi = 9.5;
157  std::map<int, PEDBUNCH> _mei;
158  static std::map<HcalDetId, std::map<int, float> > QieCalibMap;
159  std::string type = "Castor";
160 
161  /*
162  if(id==0){
163  if(detid.ieta()<16) type = "HB";
164  if(detid.ieta()>16) type = "HE";
165  if(detid.ieta()==16){
166  if(detid.depth()<3) type = "HB";
167  if(detid.depth()==3) type = "HE";
168  }
169  }
170  else if(id==1) type = "HO";
171  else if(id==2) type = "HF";
172  */
173 
174  _meot = toolT.find(detid);
175 
176  // if histos for the current channel do not exist, first create them,
177  if (_meot == toolT.end()) {
178  std::map<int, PEDBUNCH> insert;
179  std::map<int, float> qiecalib;
180  char name[1024];
181  for (int i = 0; i < 4; i++) {
182  lo = -0.5;
183  // fix from Andy: if you convert to fC and then bin in units of 1, you may 'skip' a bin while
184  // filling, since the ADCs are quantized
185  if (m_pedsinADC)
186  hi = 9.5;
187  else
188  hi = 11.5;
189  sprintf(
190  name, "%s Pedestal, eta=%d phi=%d d=%d cap=%d", type.c_str(), detid.ieta(), detid.iphi(), detid.depth(), i);
191  insert[i].first = new TH1F(name, name, bins, lo, hi);
192  sprintf(name,
193  "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
194  type.c_str(),
195  detid.ieta(),
196  detid.iphi(),
197  detid.depth(),
198  i,
199  (i + 1) % 4);
200  insert[4 + i].first = new TH1F(name, name, bins2, 0., 100.);
201  sprintf(name,
202  "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
203  type.c_str(),
204  detid.ieta(),
205  detid.iphi(),
206  detid.depth(),
207  i,
208  (i + 2) % 4);
209  insert[8 + i].first = new TH1F(name, name, bins2, 0., 100.);
210  sprintf(name,
211  "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
212  type.c_str(),
213  detid.ieta(),
214  detid.iphi(),
215  detid.depth(),
216  i,
217  (i + 3) % 4);
218  insert[12 + i].first = new TH1F(name, name, bins2, 0., 100.);
219  }
220  sprintf(name, "%s Signal in TS 4+5, eta=%d phi=%d d=%d", type.c_str(), detid.ieta(), detid.iphi(), detid.depth());
221  insert[16].first = new TH1F(name, name, 21, -0.5, 20.5);
222  sprintf(
223  name, "%s Signal in TS 4+5-2-3, eta=%d phi=%d d=%d", type.c_str(), detid.ieta(), detid.iphi(), detid.depth());
224  insert[17].first = new TH1F(name, name, 21, -10.5, 10.5);
225  sprintf(name,
226  "%s Signal in TS 4+5-(0+1+2+3)/2., eta=%d phi=%d d=%d",
227  type.c_str(),
228  detid.ieta(),
229  detid.iphi(),
230  detid.depth());
231  insert[18].first = new TH1F(name, name, 21, -10.5, 10.5);
232  toolT[detid] = insert;
233  _meot = toolT.find(detid);
234  // store QIE calibrations in a map for later reuse
235  QieCalibMap[detid] = qiecalib;
236  }
237 
238  _mei = _meot->second;
239 
240  const CastorQIECoder* coder = cond.getCastorCoder(detid);
241  const CastorQIEShape* shape = cond.getCastorShape();
242  float charge1 = coder->charge(*shape, qie1.adc(), qie1.capid());
243  float charge2 = coder->charge(*shape, qie2.adc(), qie2.capid());
244 
245  // fill single capID histo
246  if (flag == 0) {
247  if (m_nevtsample > 0) {
248  if ((evt - 1) % m_nevtsample == 0 && state[qie1.capid()]) {
249  state[qie1.capid()] = false;
250  _mei[qie1.capid()].first->Reset();
251  _mei[qie1.capid() + 4].first->Reset();
252  _mei[qie1.capid() + 8].first->Reset();
253  _mei[qie1.capid() + 12].first->Reset();
254  }
255  }
256  if (qie1.adc() < bins) {
257  if (m_pedsinADC)
258  _mei[qie1.capid()].first->Fill(qie1.adc());
259  else
260  _mei[qie1.capid()].first->Fill(charge1);
261  } else if (qie1.adc() >= bins) {
262  _mei[qie1.capid()].first->AddBinContent(bins + 1, 1);
263  }
264  }
265 
266  // fill 2 capID histo
267  if (flag > 0) {
268  std::map<int, float> qiecalib = QieCalibMap[detid];
269  //float charge1=(qie1.adc()-qiecalib[qie1.capid()+4])/qiecalib[qie1.capid()];
270  //float charge2=(qie2.adc()-qiecalib[qie2.capid()+4])/qiecalib[qie2.capid()];
271  if (charge1 * charge2 < bins2) {
272  _mei[qie1.capid() + 4 * flag].first->Fill(charge1 * charge2);
273  } else {
274  _mei[qie1.capid() + 4 * flag].first->Fill(bins2);
275  }
276  }
277 
278  if (flag == 0) {
279  // if(id==0) hbHists.ALLPEDS->Fill(qie1.adc());
280  // else if(id==1) hoHists.ALLPEDS->Fill(qie1.adc());
281  // else if(id==2) castorHists.ALLPEDS->Fill(qie1.adc());
282  castorHists.ALLPEDS->Fill(qie1.adc());
283  }
284 }
285 
286 //-----------------------------------------------------------------------------
288  const HcalQIESample& qie0,
289  const HcalQIESample& qie1,
290  const HcalQIESample& qie2,
291  const HcalQIESample& qie3,
292  const HcalQIESample& qie4,
293  const HcalQIESample& qie5,
294  std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT) {
295  // this function is due to be called for every channel
296 
297  _meot = toolT.find(detid);
298  std::map<int, PEDBUNCH> _mei = _meot->second;
299  _mei[16].first->Fill(qie4.adc() + qie5.adc() - 1.);
300  _mei[17].first->Fill(qie4.adc() + qie5.adc() - qie2.adc() - qie3.adc());
301  _mei[18].first->Fill(qie4.adc() + qie5.adc() - (qie0.adc() + qie1.adc() + qie2.adc() + qie3.adc()) / 2.);
302 }
303 
304 //-----------------------------------------------------------------------------
306  // it is called every m_nevtsample events (a sample) and the end of run
307  char PedSampleNum[20];
308 
309  // Compute pedestal constants for each HBHE, HO, HF
310  sprintf(PedSampleNum, "Castor_Sample%d", sample);
311  m_file->cd();
312  m_file->mkdir(PedSampleNum);
313  m_file->cd(PedSampleNum);
314  GetPedConst(castorHists.PEDTRENDS, castorHists.PEDMEAN, castorHists.PEDRMS);
315 }
316 
317 //-----------------------------------------------------------------------------
318 void CastorPedestalAnalysis::GetPedConst(std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT,
319  TH1F* PedMeans,
320  TH1F* PedWidths) {
321  // Completely rewritten version oct 2006
322  // Compute pedestal constants and fill into CastorPedestals and CastorPedestalWidths objects
323  float cap[4];
324  float sig[4][4];
325  float dcap[4];
326  float dsig[4][4];
327  float chi2[4];
328 
329  for (_meot = toolT.begin(); _meot != toolT.end(); _meot++) {
330  HcalDetId detid = _meot->first;
331 
332  // take mean and width from a Gaussian fit or directly from the histo
333  if (fitflag > 0) {
334  for (int i = 0; i < 4; i++) {
335  TF1* fit = _meot->second[i].first->GetFunction("gaus");
336  chi2[i] = 0;
337  if (fit->GetNDF() != 0)
338  chi2[i] = fit->GetChisquare() / fit->GetNDF();
339  cap[i] = fit->GetParameter(1);
340  sig[i][i] = fit->GetParameter(2);
341  dcap[i] = fit->GetParError(1);
342  dsig[i][i] = fit->GetParError(2);
343  }
344  } else {
345  for (int i = 0; i < 4; i++) {
346  cap[i] = _meot->second[i].first->GetMean();
347  sig[i][i] = _meot->second[i].first->GetRMS();
348  m_stat[i] = 0;
349 
350  for (int j = m_startTS; j < m_endTS + 1; j++) {
351  m_stat[i] += _meot->second[i].first->GetBinContent(j + 1);
352  }
353  dcap[i] = sig[i][i] / sqrt(m_stat[i]);
354  // dsig[i][i] = dcap[i]*sig[i][i]/cap[i];
355  dsig[i][i] = sig[i][i] / sqrt(2. * m_stat[i]);
356  chi2[i] = 0.;
357  }
358  }
359 
360  for (int i = 0; i < 4; i++) {
361  if (m_hiSaveflag > 0) {
362  if (m_pedsinADC)
363  _meot->second[i].first->GetXaxis()->SetTitle("ADC");
364  else
365  _meot->second[i].first->GetXaxis()->SetTitle("Charge, fC");
366  _meot->second[i].first->GetYaxis()->SetTitle("CapID samplings");
367  _meot->second[i].first->Write();
368  }
369  if (m_nevtsample > 0) {
370  _meot->second[i].second.first[0].push_back(cap[i]);
371  _meot->second[i].second.first[1].push_back(dcap[i]);
372  _meot->second[i].second.first[2].push_back(sig[i][i]);
373  _meot->second[i].second.first[3].push_back(dsig[i][i]);
374  _meot->second[i].second.first[4].push_back(chi2[i]);
375  }
376  PedMeans->Fill(cap[i]);
377  PedWidths->Fill(sig[i][i]);
378  }
379 
380  // special histos for Shuichi
381  if (m_hiSaveflag == -100) {
382  for (int i = 16; i < 19; i++) {
383  if (m_pedsinADC)
384  _meot->second[i].first->GetXaxis()->SetTitle("ADC");
385  else
386  _meot->second[i].first->GetXaxis()->SetTitle("Charge, fC");
387  _meot->second[i].first->GetYaxis()->SetTitle("Events");
388  _meot->second[i].first->Write();
389  }
390  }
391 
392  // diagonal sigma is width squared
393  sig[0][0] = sig[0][0] * sig[0][0];
394  sig[1][1] = sig[1][1] * sig[1][1];
395  sig[2][2] = sig[2][2] * sig[2][2];
396  sig[3][3] = sig[3][3] * sig[3][3];
397 
398  // off diagonal sigmas (correlations) are computed from 3 histograms
399  // here we still have all 4*3=12 combinations
400  sig[0][1] = _meot->second[4].first->GetMean() - cap[0] * cap[1];
401  sig[0][2] = _meot->second[8].first->GetMean() - cap[0] * cap[2];
402  sig[1][2] = _meot->second[5].first->GetMean() - cap[1] * cap[2];
403  sig[1][3] = _meot->second[9].first->GetMean() - cap[1] * cap[3];
404  sig[2][3] = _meot->second[6].first->GetMean() - cap[2] * cap[3];
405  sig[0][3] = _meot->second[12].first->GetMean() - cap[0] * cap[3];
406  sig[1][0] = _meot->second[13].first->GetMean() - cap[1] * cap[0];
407  sig[2][0] = _meot->second[10].first->GetMean() - cap[2] * cap[0];
408  sig[2][1] = _meot->second[14].first->GetMean() - cap[2] * cap[1];
409  sig[3][1] = _meot->second[11].first->GetMean() - cap[3] * cap[1];
410  sig[3][2] = _meot->second[15].first->GetMean() - cap[3] * cap[2];
411  sig[3][0] = _meot->second[7].first->GetMean() - cap[3] * cap[0];
412 
413  // there is no proper error calculation for the correlation coefficients
414  for (int i = 0; i < 4; i++) {
415  if (m_nevtsample > 0) {
416  _meot->second[i].second.first[5].push_back(sig[i][(i + 1) % 4]);
417  _meot->second[i].second.first[6].push_back(2 * sig[i][i] * dsig[i][i]);
418  _meot->second[i].second.first[7].push_back(sig[i][(i + 2) % 4]);
419  _meot->second[i].second.first[8].push_back(2 * sig[i][i] * dsig[i][i]);
420  _meot->second[i].second.first[9].push_back(sig[i][(i + 3) % 4]);
421  _meot->second[i].second.first[10].push_back(2 * sig[i][i] * dsig[i][i]);
422  }
423  // save product histos if desired
424  if (m_hiSaveflag > 10) {
425  if (m_pedsinADC)
426  _meot->second[i + 4].first->GetXaxis()->SetTitle("ADC^2");
427  else
428  _meot->second[i + 4].first->GetXaxis()->SetTitle("Charge^2, fC^2");
429  _meot->second[i + 4].first->GetYaxis()->SetTitle("2-CapID samplings");
430  _meot->second[i + 4].first->Write();
431  if (m_pedsinADC)
432  _meot->second[i + 8].first->GetXaxis()->SetTitle("ADC^2");
433  else
434  _meot->second[i + 8].first->GetXaxis()->SetTitle("Charge^2, fC^2");
435  _meot->second[i + 8].first->GetYaxis()->SetTitle("2-CapID samplings");
436  _meot->second[i + 8].first->Write();
437  if (m_pedsinADC)
438  _meot->second[i + 12].first->GetXaxis()->SetTitle("ADC^2");
439  else
440  _meot->second[i + 12].first->GetXaxis()->SetTitle("Charge^2, fC^2");
441  _meot->second[i + 12].first->GetYaxis()->SetTitle("2-CapID samplings");
442  _meot->second[i + 12].first->Write();
443  }
444  }
445 
446  // fill the objects - at this point only close and medium correlations are stored
447  // and the matrix is assumed symmetric
448  if (m_nevtsample < 1) {
449  sig[1][0] = sig[0][1];
450  sig[2][0] = sig[0][2];
451  sig[2][1] = sig[1][2];
452  sig[3][1] = sig[1][3];
453  sig[3][2] = sig[2][3];
454  sig[0][3] = sig[3][0];
455  if (fRawPedestals) {
456  CastorPedestal item(detid, cap[0], cap[1], cap[2], cap[3]);
458  }
459  if (fRawPedestalWidths) {
460  CastorPedestalWidth widthsp(detid);
461  widthsp.setSigma(0, 0, sig[0][0]);
462  widthsp.setSigma(0, 1, sig[0][1]);
463  widthsp.setSigma(0, 2, sig[0][2]);
464  widthsp.setSigma(1, 1, sig[1][1]);
465  widthsp.setSigma(1, 2, sig[1][2]);
466  widthsp.setSigma(1, 3, sig[1][3]);
467  widthsp.setSigma(2, 2, sig[2][2]);
468  widthsp.setSigma(2, 3, sig[2][3]);
469  widthsp.setSigma(3, 3, sig[3][3]);
470  widthsp.setSigma(3, 0, sig[0][3]);
471  fRawPedestalWidths->addValues(widthsp);
472  }
473  }
474  }
475 }
476 
477 //-----------------------------------------------------------------------------
479  const CastorPedestalWidths* fInputPedestalWidths,
480  CastorPedestals* fOutputPedestals,
481  CastorPedestalWidths* fOutputPedestalWidths) {
482  int nstat[4];
483 
484  // Pedestal objects
485  // inputs...
486  fRefPedestals = fInputPedestals;
487  fRefPedestalWidths = fInputPedestalWidths;
488 
489  // outputs...
490  if (m_pedValflag > 0) {
491  fValPedestals = fOutputPedestals;
492  fValPedestalWidths = fOutputPedestalWidths;
495  } else {
496  fRawPedestals = fOutputPedestals;
497  fRawPedestalWidths = fOutputPedestalWidths;
500  }
501 
502  // compute pedestal constants
503  if (m_nevtsample < 1)
504  SampleAnalysis();
505  if (m_nevtsample > 0) {
506  if (evt % m_nevtsample != 0)
507  SampleAnalysis();
508  }
509 
510  // trending histos
511  if (m_nevtsample > 0) {
512  m_file->cd();
513  m_file->cd("Castor");
514  Trendings(castorHists.PEDTRENDS, castorHists.CHI2, castorHists.CAPID_AVERAGE, castorHists.CAPID_CHI2);
515  }
516 
517  if (m_nevtsample < 1) {
518  // pedestal validation: m_AllPedsOK=-1 means not validated,
519  // 0 everything OK,
520  // N>0 : mod(N,100000) drifts + width changes
521  // int(N/100000) missing channels
522  m_AllPedsOK = -1;
523  if (m_pedValflag > 0) {
524  for (int i = 0; i < 4; i++)
525  nstat[i] = (int)m_stat[i];
526  int NPedErrors = CastorPedVal(nstat,
533  m_AllPedsOK = NPedErrors;
534  }
535  // setting m_AllPedsOK=-2 will inhibit writing pedestals out
536  // if(m_pedValflag==1){
537  // if(evt<100)m_AllPedsOK=-2;
538  // }
539  }
540 
541  // Write other histograms.
542 
543  // Castor
544  m_file->cd();
545  m_file->cd("Castor");
546  castorHists.ALLPEDS->Write();
547  castorHists.PEDRMS->Write();
548  castorHists.PEDMEAN->Write();
549 
550  m_file->Close();
551  edm::LogWarning("Castor") << "Hcal/Castor histograms written to " << m_outputFileROOT.c_str();
552  return (int)m_AllPedsOK;
553 }
554 
555 //-----------------------------------------------------------------------------
556 void CastorPedestalAnalysis::Trendings(std::map<HcalDetId, std::map<int, PEDBUNCH> >& toolT,
557  TH1F* Chi2,
558  TH1F* CapidAverage,
559  TH1F* CapidChi2) {
560  // check stability of pedestal constants in a single long run
561 
562  std::map<int, std::vector<double> > AverageValues;
563 
564  for (_meot = toolT.begin(); _meot != toolT.end(); _meot++) {
565  for (int i = 0; i < 4; i++) {
566  char name[1024];
567  HcalDetId detid = _meot->first;
568  sprintf(name, "Pedestal trend, eta=%d phi=%d d=%d cap=%d", detid.ieta(), detid.iphi(), detid.depth(), i);
569  int bins = _meot->second[i].second.first[0].size();
570  float lo = 0.5;
571  float hi = (float)bins + 0.5;
572  _meot->second[i].second.second.push_back(new TH1F(name, name, bins, lo, hi));
573  sprintf(name, "Width trend, eta=%d phi=%d d=%d cap=%d", detid.ieta(), detid.iphi(), detid.depth(), i);
574  bins = _meot->second[i].second.first[2].size();
575  hi = (float)bins + 0.5;
576  _meot->second[i].second.second.push_back(new TH1F(name, name, bins, lo, hi));
577  sprintf(name,
578  "Correlation trend, eta=%d phi=%d d=%d caps=%d*%d",
579  detid.ieta(),
580  detid.iphi(),
581  detid.depth(),
582  i,
583  (i + 1) % 4);
584  bins = _meot->second[i].second.first[5].size();
585  hi = (float)bins + 0.5;
586  _meot->second[i].second.second.push_back(new TH1F(name, name, bins, lo, hi));
587  /* sprintf(name,"Correlation trend, eta=%d phi=%d d=%d caps=%d*%d",detid.ieta(),detid.iphi(),detid.depth(),i,(i+2)%4);
588  bins = _meot->second[i].second.first[7].size();
589  hi = (float)bins+0.5;
590  _meot->second[i].second.second.push_back(new TH1F(name,name,bins,lo,hi));
591  sprintf(name,"Correlation trend, eta=%d phi=%d d=%d caps=%d*%d",detid.ieta(),detid.iphi(),detid.depth(),i,(i+3)%4);
592  bins = _meot->second[i].second.first[9].size();
593  hi = (float)bins+0.5;
594  _meot->second[i].second.second.push_back(new TH1F(name,name,bins,lo,hi)); */
595 
596  std::vector<double>::iterator sample_it;
597  // Pedestal mean - put content and errors
598  int j = 0;
599  for (sample_it = _meot->second[i].second.first[0].begin(); sample_it != _meot->second[i].second.first[0].end();
600  ++sample_it) {
601  _meot->second[i].second.second[0]->SetBinContent(++j, *sample_it);
602  }
603  j = 0;
604  for (sample_it = _meot->second[i].second.first[1].begin(); sample_it != _meot->second[i].second.first[1].end();
605  ++sample_it) {
606  _meot->second[i].second.second[0]->SetBinError(++j, *sample_it);
607  }
608  // fit with a constant - extract parameters
609  _meot->second[i].second.second[0]->Fit("pol0", "Q");
610  TF1* fit = _meot->second[i].second.second[0]->GetFunction("pol0");
611  AverageValues[0].push_back(fit->GetParameter(0));
612  AverageValues[1].push_back(fit->GetParError(0));
613  if (sample > 1)
614  AverageValues[2].push_back(fit->GetChisquare() / fit->GetNDF());
615  else
616  AverageValues[2].push_back(fit->GetChisquare());
617  sprintf(name, "Sample (%d events)", m_nevtsample);
618  _meot->second[i].second.second[0]->GetXaxis()->SetTitle(name);
619  _meot->second[i].second.second[0]->GetYaxis()->SetTitle("Pedestal value");
620  _meot->second[i].second.second[0]->Write();
621  // Pedestal width - put content and errors
622  j = 0;
623  for (sample_it = _meot->second[i].second.first[2].begin(); sample_it != _meot->second[i].second.first[2].end();
624  ++sample_it) {
625  _meot->second[i].second.second[1]->SetBinContent(++j, *sample_it);
626  }
627  j = 0;
628  for (sample_it = _meot->second[i].second.first[3].begin(); sample_it != _meot->second[i].second.first[3].end();
629  ++sample_it) {
630  _meot->second[i].second.second[1]->SetBinError(++j, *sample_it);
631  }
632  _meot->second[i].second.second[1]->GetXaxis()->SetTitle(name);
633  _meot->second[i].second.second[1]->GetYaxis()->SetTitle("Pedestal width");
634  _meot->second[i].second.second[1]->Write();
635  // Correlation coeffs - put contents and errors
636  j = 0;
637  for (sample_it = _meot->second[i].second.first[5].begin(); sample_it != _meot->second[i].second.first[5].end();
638  ++sample_it) {
639  _meot->second[i].second.second[2]->SetBinContent(++j, *sample_it);
640  }
641  j = 0;
642  for (sample_it = _meot->second[i].second.first[6].begin(); sample_it != _meot->second[i].second.first[6].end();
643  ++sample_it) {
644  _meot->second[i].second.second[2]->SetBinError(++j, *sample_it);
645  }
646  _meot->second[i].second.second[2]->GetXaxis()->SetTitle(name);
647  _meot->second[i].second.second[2]->GetYaxis()->SetTitle("Close correlation");
648  _meot->second[i].second.second[2]->Write();
649  /* j=0;
650  for(sample_it=_meot->second[i].second.first[7].begin();
651  sample_it!=_meot->second[i].second.first[7].end();sample_it++){
652  _meot->second[i].second.second[3]->SetBinContent(++j,*sample_it);
653  }
654  j=0;
655  for(sample_it=_meot->second[i].second.first[8].begin();
656  sample_it!=_meot->second[i].second.first[8].end();sample_it++){
657  _meot->second[i].second.second[3]->SetBinError(++j,*sample_it);
658  }
659  _meot->second[i].second.second[3]->GetXaxis()->SetTitle(name);
660  _meot->second[i].second.second[3]->GetYaxis()->SetTitle("Intermediate correlation");
661  _meot->second[i].second.second[3]->Write();
662  j=0;
663  for(sample_it=_meot->second[i].second.first[9].begin();
664  sample_it!=_meot->second[i].second.first[9].end();sample_it++){
665  _meot->second[i].second.second[4]->SetBinContent(++j,*sample_it);
666  }
667  j=0;
668  for(sample_it=_meot->second[i].second.first[10].begin();
669  sample_it!=_meot->second[i].second.first[10].end();sample_it++){
670  _meot->second[i].second.second[4]->SetBinError(++j,*sample_it);
671  }
672  _meot->second[i].second.second[4]->GetXaxis()->SetTitle(name);
673  _meot->second[i].second.second[4]->GetYaxis()->SetTitle("Distant correlation");
674  _meot->second[i].second.second[4]->Write(); */
675  // chi2
676  j = 0;
677  for (sample_it = _meot->second[i].second.first[4].begin(); sample_it != _meot->second[i].second.first[4].end();
678  ++sample_it) {
679  Chi2->Fill(*sample_it);
680  }
681  }
682  }
683  CapidAverage = new TH1F("Constant fit: Pedestal Values",
684  "Constant fit: Pedestal Values",
685  AverageValues[0].size(),
686  0.,
687  AverageValues[0].size());
688  std::vector<double>::iterator sample_it;
689  int j = 0;
690  for (sample_it = AverageValues[0].begin(); sample_it != AverageValues[0].end(); ++sample_it) {
691  CapidAverage->SetBinContent(++j, *sample_it);
692  }
693  j = 0;
694  for (sample_it = AverageValues[1].begin(); sample_it != AverageValues[1].end(); ++sample_it) {
695  CapidAverage->SetBinError(++j, *sample_it);
696  }
697  CapidChi2 = new TH1F(
698  "Constant fit: Chi2/ndf", "Constant fit: Chi2/ndf", AverageValues[2].size(), 0., AverageValues[2].size());
699  j = 0;
700  for (sample_it = AverageValues[2].begin(); sample_it != AverageValues[2].end(); ++sample_it) {
701  CapidChi2->SetBinContent(++j, *sample_it);
702  //CapidChi2->SetBinError(++j,0);
703  }
704  Chi2->GetXaxis()->SetTitle("Chi2/ndf");
705  Chi2->GetYaxis()->SetTitle("50 x [(16+2) x 4 x 4] `events`");
706  Chi2->Write();
707  CapidAverage->GetYaxis()->SetTitle("Pedestal value");
708  CapidAverage->GetXaxis()->SetTitle("(16+2) x 4 x 4 `events`");
709  CapidAverage->Write();
710  CapidChi2->GetYaxis()->SetTitle("Chi2/ndf");
711  CapidChi2->GetXaxis()->SetTitle("(16+2) x 4 x 4 `events`");
712  CapidChi2->Write();
713 }
714 
715 //-----------------------------------------------------------------------------
717  const CastorPedestals* fRefPedestals,
718  const CastorPedestalWidths* fRefPedestalWidths,
719  CastorPedestals* fRawPedestals,
720  CastorPedestalWidths* fRawPedestalWidths,
721  CastorPedestals* fValPedestals,
722  CastorPedestalWidths* fValPedestalWidths) {
723  // new version of pedestal validation - it is designed to be as independent of
724  // all the rest as possible - you only need to provide valid pedestal objects
725  // and a vector of statistics per capID to use this as standalone code
726  HcalDetId detid;
727  float RefPedVals[4];
728  float RefPedSigs[4][4];
729  float RawPedVals[4];
730  float RawPedSigs[4][4];
731  std::map<HcalDetId, bool> isinRaw;
732  std::map<HcalDetId, bool> isinRef;
733  std::vector<DetId> RefChanns = fRefPedestals->getAllChannels();
734  std::vector<DetId> RawChanns = fRawPedestals->getAllChannels();
735  std::ofstream PedValLog;
736  PedValLog.open("CastorPedVal.log");
737 
738  if (nstat[0] + nstat[1] + nstat[2] + nstat[3] < 2500)
739  PedValLog << "CastorPedVal: warning - low statistics" << std::endl;
740  // find complete list of channels in current data and reference
741  for (int i = 0; i < (int)RawChanns.size(); i++) {
742  isinRef[HcalDetId(RawChanns[i])] = false;
743  }
744  for (int i = 0; i < (int)RefChanns.size(); i++) {
745  detid = HcalDetId(RefChanns[i]);
746  isinRaw[detid] = false;
747  isinRef[detid] = true;
748  }
749  for (int i = 0; i < (int)RawChanns.size(); i++) {
750  detid = HcalDetId(RawChanns[i]);
751  isinRaw[detid] = true;
752  if (isinRef[detid] == false) {
753  PedValLog << "CastorPedVal: channel " << detid << " not found in reference set" << std::endl;
754  std::cerr << "CastorPedVal: channel " << detid << " not found in reference set" << std::endl;
755  }
756  }
757 
758  // main loop over channels
759  int erflag = 0;
760  for (int i = 0; i < (int)RefChanns.size(); i++) {
761  detid = HcalDetId(RefChanns[i]);
762  for (int icap = 0; icap < 4; icap++) {
763  RefPedVals[icap] = fRefPedestals->getValues(detid)->getValue(icap);
764  for (int icap2 = icap; icap2 < 4; icap2++) {
765  RefPedSigs[icap][icap2] = fRefPedestalWidths->getValues(detid)->getSigma(icap, icap2);
766  if (icap2 != icap)
767  RefPedSigs[icap2][icap] = RefPedSigs[icap][icap2];
768  }
769  }
770 
771  // read new raw values
772  if (isinRaw[detid]) {
773  for (int icap = 0; icap < 4; icap++) {
774  RawPedVals[icap] = fRawPedestals->getValues(detid)->getValue(icap);
775  for (int icap2 = icap; icap2 < 4; icap2++) {
776  RawPedSigs[icap][icap2] = fRawPedestalWidths->getValues(detid)->getSigma(icap, icap2);
777  if (icap2 != icap)
778  RawPedSigs[icap2][icap] = RawPedSigs[icap][icap2];
779  }
780  }
781 
782  // first quick check if raw values make sense: if not, the channel is treated like absent
783  for (int icap = 0; icap < 4; icap++) {
784  if (RawPedVals[icap] < 1. || RawPedSigs[icap][icap] < 0.01)
785  isinRaw[detid] = false;
786  for (int icap2 = icap; icap2 < 4; icap2++) {
787  if (fabs(RawPedSigs[icap][icap2] / sqrt(RawPedSigs[icap][icap] * RawPedSigs[icap2][icap2])) > 1.)
788  isinRaw[detid] = false;
789  }
790  }
791  }
792 
793  // check raw values against reference
794  if (isinRaw[detid]) {
795  for (int icap = 0; icap < 4; icap++) {
796  int icap2 = (icap + 1) % 4;
797  float width = sqrt(RawPedSigs[icap][icap]);
798  float erof1 = width / sqrt((float)nstat[icap]);
799  float erof2 = sqrt(erof1 * erof1 + RawPedSigs[icap][icap] / (float)nstat[icap]);
800  float erofwidth = width / sqrt(2. * nstat[icap]);
801  float diffof1 = RawPedVals[icap] - RefPedVals[icap];
802  float diffof2 = RawPedVals[icap] + RawPedVals[icap2] - RefPedVals[icap] - RefPedVals[icap2];
803  float diffofw = width - sqrt(RefPedSigs[icap][icap]);
804 
805  // validation in 2 TS for HB, HE, HO, in 1 TS for HF
806  int nTS = 2;
807  if (detid.subdet() == HcalForward)
808  nTS = 1;
809  if (nTS == 1 && fabs(diffof1) > 0.5 + erof1) {
810  erflag += 1;
811  PedValLog << "HcalPedVal: drift in channel " << detid << " cap " << icap << ": " << RawPedVals[icap] << " - "
812  << RefPedVals[icap] << " = " << diffof1 << std::endl;
813  }
814  if (nTS == 2 && fabs(diffof2) > 0.5 + erof2) {
815  erflag += 1;
816  PedValLog << "HcalPedVal: drift in channel " << detid << " caps " << icap << "+" << icap2 << ": "
817  << RawPedVals[icap] << "+" << RawPedVals[icap2] << " - " << RefPedVals[icap] << "+"
818  << RefPedVals[icap2] << " = " << diffof2 << std::endl;
819  }
820  if (fabs(diffofw) > 0.15 * width + erofwidth) {
821  erflag += 1;
822  PedValLog << "HcalPedVal: width changed in channel " << detid << " cap " << icap << ": " << width << " - "
823  << sqrt(RefPedSigs[icap][icap]) << " = " << diffofw << std::endl;
824  }
825  }
826  }
827 
828  // for disconnected/bad channels restore reference values
829  else {
830  PedValLog << "HcalPedVal: no valid data from channel " << detid << std::endl;
831  erflag += 100000;
832  CastorPedestal item(detid, RefPedVals[0], RefPedVals[1], RefPedVals[2], RefPedVals[3]);
834  CastorPedestalWidth widthsp(detid);
835  for (int icap = 0; icap < 4; icap++) {
836  for (int icap2 = icap; icap2 < 4; icap2++)
837  widthsp.setSigma(icap2, icap, RefPedSigs[icap2][icap]);
838  }
839  fValPedestalWidths->addValues(widthsp);
840  }
841 
842  // end of channel loop
843  }
844 
845  if (erflag == 0)
846  PedValLog << "HcalPedVal: all pedestals checked OK" << std::endl;
847 
848  // now construct the remaining part of the validated objects
849  // if nothing changed outside tolerance, validated set = reference set
850  if (erflag % 100000 == 0) {
851  for (int i = 0; i < (int)RefChanns.size(); i++) {
852  detid = HcalDetId(RefChanns[i]);
853  if (isinRaw[detid]) {
854  CastorPedestalWidth widthsp(detid);
855  for (int icap = 0; icap < 4; icap++) {
856  RefPedVals[icap] = fRefPedestals->getValues(detid)->getValue(icap);
857  for (int icap2 = icap; icap2 < 4; icap2++) {
858  RefPedSigs[icap][icap2] = fRefPedestalWidths->getValues(detid)->getSigma(icap, icap2);
859  if (icap2 != icap)
860  RefPedSigs[icap2][icap] = RefPedSigs[icap][icap2];
861  widthsp.setSigma(icap2, icap, RefPedSigs[icap2][icap]);
862  }
863  }
864  fValPedestalWidths->addValues(widthsp);
865  CastorPedestal item(detid, RefPedVals[0], RefPedVals[1], RefPedVals[2], RefPedVals[3]);
867  }
868  }
869  }
870 
871  // if anything changed, validated set = raw set + reference for missing/bad channels
872  else {
873  for (int i = 0; i < (int)RawChanns.size(); i++) {
874  detid = HcalDetId(RawChanns[i]);
875  if (isinRaw[detid]) {
876  CastorPedestalWidth widthsp(detid);
877  for (int icap = 0; icap < 4; icap++) {
878  RawPedVals[icap] = fRawPedestals->getValues(detid)->getValue(icap);
879  for (int icap2 = icap; icap2 < 4; icap2++) {
880  RawPedSigs[icap][icap2] = fRawPedestalWidths->getValues(detid)->getSigma(icap, icap2);
881  if (icap2 != icap)
882  RawPedSigs[icap2][icap] = RawPedSigs[icap][icap2];
883  widthsp.setSigma(icap2, icap, RawPedSigs[icap2][icap]);
884  }
885  }
886  fValPedestalWidths->addValues(widthsp);
887  CastorPedestal item(detid, RawPedVals[0], RawPedVals[1], RawPedVals[2], RawPedVals[3]);
889  }
890  }
891  }
892  return erflag;
893 }
size
Write out results.
float charge(const CastorQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -> fC conversion.
const Item * getValues(DetId fId, bool throwOnFail=true) const
void setSigma(int fCapId1, int fCapId2, float fSigma)
CastorPedestalWidths * fRawPedestalWidths
const HcalQIESample & sample(int i) const
access a sample
const CastorQIECoder * m_coder
std::vector< T >::const_iterator const_iterator
static int CastorPedVal(int nstat[4], const CastorPedestals *fRefPedestals, const CastorPedestalWidths *fRefPedestalWidths, CastorPedestals *fRawPedestals, CastorPedestalWidths *fRawPedestalWidths, CastorPedestals *fValPedestals, CastorPedestalWidths *fValPedestalWidths)
void setup(const std::string &m_outputFileROOT)
std::vector< DetId > getAllChannels() const
T getUntrackedParameter(std::string const &, T const &) const
float getSigma(int fCapId1, int fCapId2) const
get correlation element for capId1/2 = 0..3
void processEvent(const CastorDigiCollection &castor, const CastorDbService &cond)
int size() const
total number of samples in the digi
void Trendings(std::map< HcalDetId, std::map< int, PEDBUNCH > > &toolT, TH1F *Chi2, TH1F *CapidAverage, TH1F *CapidChi2)
CastorPedestalWidths * fValPedestalWidths
void AllChanHists(const HcalDetId detid, const HcalQIESample &qie0, const HcalQIESample &qie1, const HcalQIESample &qie2, const HcalQIESample &qie3, const HcalQIESample &qie4, const HcalQIESample &qie5, std::map< HcalDetId, std::map< int, PEDBUNCH > > &toolT)
Definition: EPCuts.h:4
std::map< HcalDetId, std::map< int, PEDBUNCH > >::iterator _meot
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
T sqrt(T t)
Definition: SSEVec.h:19
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:50
const HcalCastorDetId & id() const
const CastorQIEShape * m_shape
int done(const CastorPedestals *fInputPedestals, const CastorPedestalWidths *fInputWidths, CastorPedestals *fOutputPedestals, CastorPedestalWidths *fOutputWidths)
bool addValues(const Item &myItem)
constexpr int capid() const
get the Capacitor id
Definition: HcalQIESample.h:47
struct CastorPedestalAnalysis::@44 castorHists
const CastorPedestalWidths * fRefPedestalWidths
CastorPedestalAnalysis(const edm::ParameterSet &ps)
Constructor.
constexpr int adc() const
get the ADC sample
Definition: HcalQIESample.h:43
void GetPedConst(std::map< HcalDetId, std::map< int, PEDBUNCH > > &toolT, TH1F *PedMeans, TH1F *PedWidths)
float getValue(int fCapId) const
get value for capId = 0..3
Log< level::Warning, false > LogWarning
Definition: Chi2.h:15
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
void per2CapsHists(int flag, int id, const HcalDetId detid, const HcalQIESample &qie1, const HcalQIESample &qie2, std::map< HcalDetId, std::map< int, PEDBUNCH > > &toolT, const CastorDbService &cond)
const CastorPedestals * fRefPedestals
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164