15 : fRefPedestals(nullptr),
16 fRefPedestalWidths(nullptr),
17 fRawPedestals(nullptr),
18 fRawPedestalWidths(nullptr),
19 fValPedestals(nullptr),
20 fValPedestalWidths(nullptr) {
25 for (
int i = 0;
i < 4;
i++)
27 for (
int k = 0;
k < 4;
k++)
28 state.push_back(
true);
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.);
76 for (
int i = 0;
i < 16;
i++)
77 _meot->second[
i].first->Delete();
153 static const int bins = 10;
154 static const int bins2 = 100;
157 std::map<int, PEDBUNCH> _mei;
158 static std::map<HcalDetId, std::map<int, float> > QieCalibMap;
174 _meot = toolT.find(detid);
177 if (
_meot == toolT.end()) {
178 std::map<int, PEDBUNCH>
insert;
179 std::map<int, float> qiecalib;
181 for (
int i = 0;
i < 4;
i++) {
190 name,
"%s Pedestal, eta=%d phi=%d d=%d cap=%d",
type.c_str(), detid.
ieta(), detid.
iphi(), detid.
depth(),
i);
193 "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
202 "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
211 "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
220 sprintf(
name,
"%s Signal in TS 4+5, eta=%d phi=%d d=%d",
type.c_str(), detid.
ieta(), detid.
iphi(), detid.
depth());
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());
226 "%s Signal in TS 4+5-(0+1+2+3)/2., eta=%d phi=%d d=%d",
233 _meot = toolT.find(detid);
235 QieCalibMap[detid] = qiecalib;
238 _mei =
_meot->second;
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();
258 _mei[qie1.
capid()].first->Fill(qie1.
adc());
260 _mei[qie1.
capid()].first->Fill(charge1);
261 }
else if (qie1.
adc() >=
bins) {
262 _mei[qie1.
capid()].first->AddBinContent(
bins + 1, 1);
268 std::map<int, float> qiecalib = QieCalibMap[detid];
271 if (charge1 * charge2 < bins2) {
272 _mei[qie1.
capid() + 4 *
flag].first->Fill(charge1 * charge2);
274 _mei[qie1.
capid() + 4 *
flag].first->Fill(bins2);
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.);
307 char PedSampleNum[20];
310 sprintf(PedSampleNum,
"Castor_Sample%d",
sample);
312 m_file->mkdir(PedSampleNum);
334 for (
int i = 0;
i < 4;
i++) {
335 TF1*
fit =
_meot->second[
i].first->GetFunction(
"gaus");
337 if (
fit->GetNDF() != 0)
340 sig[
i][
i] =
fit->GetParameter(2);
341 dcap[
i] =
fit->GetParError(1);
342 dsig[
i][
i] =
fit->GetParError(2);
345 for (
int i = 0;
i < 4;
i++) {
347 sig[
i][
i] =
_meot->second[
i].first->GetRMS();
360 for (
int i = 0;
i < 4;
i++) {
363 _meot->second[
i].first->GetXaxis()->SetTitle(
"ADC");
365 _meot->second[
i].first->GetXaxis()->SetTitle(
"Charge, fC");
366 _meot->second[
i].first->GetYaxis()->SetTitle(
"CapID samplings");
367 _meot->second[
i].first->Write();
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]);
376 PedMeans->Fill(
cap[
i]);
377 PedWidths->Fill(sig[
i][
i]);
382 for (
int i = 16;
i < 19;
i++) {
384 _meot->second[
i].first->GetXaxis()->SetTitle(
"ADC");
386 _meot->second[
i].first->GetXaxis()->SetTitle(
"Charge, fC");
387 _meot->second[
i].first->GetYaxis()->SetTitle(
"Events");
388 _meot->second[
i].first->Write();
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];
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];
414 for (
int i = 0;
i < 4;
i++) {
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]);
426 _meot->second[
i + 4].first->GetXaxis()->SetTitle(
"ADC^2");
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();
432 _meot->second[
i + 8].first->GetXaxis()->SetTitle(
"ADC^2");
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();
438 _meot->second[
i + 12].first->GetXaxis()->SetTitle(
"ADC^2");
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();
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];
524 for (
int i = 0;
i < 4;
i++)
562 std::map<int, std::vector<double> > AverageValues;
565 for (
int i = 0;
i < 4;
i++) {
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();
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();
578 "Correlation trend, eta=%d phi=%d d=%d caps=%d*%d",
584 bins =
_meot->second[
i].second.first[5].size();
596 std::vector<double>::iterator sample_it;
599 for (sample_it =
_meot->second[
i].second.first[0].begin(); sample_it !=
_meot->second[
i].second.first[0].end();
601 _meot->second[
i].second.second[0]->SetBinContent(++
j, *sample_it);
604 for (sample_it =
_meot->second[
i].second.first[1].begin(); sample_it !=
_meot->second[
i].second.first[1].end();
606 _meot->second[
i].second.second[0]->SetBinError(++
j, *sample_it);
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));
614 AverageValues[2].push_back(
fit->GetChisquare() /
fit->GetNDF());
616 AverageValues[2].push_back(
fit->GetChisquare());
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();
623 for (sample_it =
_meot->second[
i].second.first[2].begin(); sample_it !=
_meot->second[
i].second.first[2].end();
625 _meot->second[
i].second.second[1]->SetBinContent(++
j, *sample_it);
628 for (sample_it =
_meot->second[
i].second.first[3].begin(); sample_it !=
_meot->second[
i].second.first[3].end();
630 _meot->second[
i].second.second[1]->SetBinError(++
j, *sample_it);
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();
637 for (sample_it =
_meot->second[
i].second.first[5].begin(); sample_it !=
_meot->second[
i].second.first[5].end();
639 _meot->second[
i].second.second[2]->SetBinContent(++
j, *sample_it);
642 for (sample_it =
_meot->second[
i].second.first[6].begin(); sample_it !=
_meot->second[
i].second.first[6].end();
644 _meot->second[
i].second.second[2]->SetBinError(++
j, *sample_it);
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();
677 for (sample_it =
_meot->second[
i].second.first[4].begin(); sample_it !=
_meot->second[
i].second.first[4].end();
679 Chi2->Fill(*sample_it);
683 CapidAverage =
new TH1F(
"Constant fit: Pedestal Values",
684 "Constant fit: Pedestal Values",
685 AverageValues[0].
size(),
687 AverageValues[0].
size());
688 std::vector<double>::iterator sample_it;
690 for (sample_it = AverageValues[0].begin(); sample_it != AverageValues[0].end(); ++sample_it) {
691 CapidAverage->SetBinContent(++
j, *sample_it);
694 for (sample_it = AverageValues[1].begin(); sample_it != AverageValues[1].end(); ++sample_it) {
695 CapidAverage->SetBinError(++
j, *sample_it);
697 CapidChi2 =
new TH1F(
698 "Constant fit: Chi2/ndf",
"Constant fit: Chi2/ndf", AverageValues[2].
size(), 0., AverageValues[2].
size());
700 for (sample_it = AverageValues[2].begin(); sample_it != AverageValues[2].end(); ++sample_it) {
701 CapidChi2->SetBinContent(++
j, *sample_it);
704 Chi2->GetXaxis()->SetTitle(
"Chi2/ndf");
705 Chi2->GetYaxis()->SetTitle(
"50 x [(16+2) x 4 x 4] `events`");
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`");
728 float RefPedSigs[4][4];
730 float RawPedSigs[4][4];
731 std::map<HcalDetId, bool> isinRaw;
732 std::map<HcalDetId, bool> isinRef;
735 std::ofstream PedValLog;
736 PedValLog.open(
"CastorPedVal.log");
738 if (nstat[0] + nstat[1] + nstat[2] + nstat[3] < 2500)
739 PedValLog <<
"CastorPedVal: warning - low statistics" << std::endl;
741 for (
int i = 0;
i < (
int)RawChanns.size();
i++) {
744 for (
int i = 0;
i < (
int)RefChanns.size();
i++) {
746 isinRaw[detid] =
false;
747 isinRef[detid] =
true;
749 for (
int i = 0;
i < (
int)RawChanns.size();
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;
760 for (
int i = 0;
i < (
int)RefChanns.size();
i++) {
762 for (
int icap = 0; icap < 4; icap++) {
764 for (
int icap2 = icap; icap2 < 4; icap2++) {
767 RefPedSigs[icap2][icap] = RefPedSigs[icap][icap2];
772 if (isinRaw[detid]) {
773 for (
int icap = 0; icap < 4; icap++) {
775 for (
int icap2 = icap; icap2 < 4; icap2++) {
778 RawPedSigs[icap2][icap] = RawPedSigs[icap][icap2];
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;
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]);
809 if (nTS == 1 && fabs(diffof1) > 0.5 + erof1) {
811 PedValLog <<
"HcalPedVal: drift in channel " << detid <<
" cap " << icap <<
": " << RawPedVals[icap] <<
" - "
812 << RefPedVals[icap] <<
" = " << diffof1 << std::endl;
814 if (nTS == 2 && fabs(diffof2) > 0.5 + erof2) {
816 PedValLog <<
"HcalPedVal: drift in channel " << detid <<
" caps " << icap <<
"+" << icap2 <<
": "
817 << RawPedVals[icap] <<
"+" << RawPedVals[icap2] <<
" - " << RefPedVals[icap] <<
"+"
818 << RefPedVals[icap2] <<
" = " << diffof2 << std::endl;
820 if (fabs(diffofw) > 0.15 *
width + erofwidth) {
822 PedValLog <<
"HcalPedVal: width changed in channel " << detid <<
" cap " << icap <<
": " <<
width <<
" - "
823 <<
sqrt(RefPedSigs[icap][icap]) <<
" = " << diffofw << std::endl;
830 PedValLog <<
"HcalPedVal: no valid data from channel " << detid << std::endl;
832 CastorPedestal item(detid, RefPedVals[0], RefPedVals[1], RefPedVals[2], RefPedVals[3]);
835 for (
int icap = 0; icap < 4; icap++) {
836 for (
int icap2 = icap; icap2 < 4; icap2++)
837 widthsp.
setSigma(icap2, icap, RefPedSigs[icap2][icap]);
846 PedValLog <<
"HcalPedVal: all pedestals checked OK" << std::endl;
850 if (erflag % 100000 == 0) {
851 for (
int i = 0;
i < (
int)RefChanns.size();
i++) {
853 if (isinRaw[detid]) {
855 for (
int icap = 0; icap < 4; icap++) {
857 for (
int icap2 = icap; icap2 < 4; icap2++) {
860 RefPedSigs[icap2][icap] = RefPedSigs[icap][icap2];
861 widthsp.
setSigma(icap2, icap, RefPedSigs[icap2][icap]);
865 CastorPedestal item(detid, RefPedVals[0], RefPedVals[1], RefPedVals[2], RefPedVals[3]);
873 for (
int i = 0;
i < (
int)RawChanns.size();
i++) {
875 if (isinRaw[detid]) {
877 for (
int icap = 0; icap < 4; icap++) {
879 for (
int icap2 = icap; icap2 < 4; icap2++) {
882 RawPedSigs[icap2][icap] = RawPedSigs[icap][icap2];
883 widthsp.
setSigma(icap2, icap, RawPedSigs[icap2][icap]);
887 CastorPedestal item(detid, RawPedVals[0], RawPedVals[1], RawPedVals[2], RawPedVals[3]);