26 for (
int i = 0;
i < 4;
i++)
28 for (
int k = 0;
k < 4;
k++)
29 state.push_back(
true);
54 cout <<
"WARNING - incompatible cfg options: nevtsample = " <<
m_nevtsample <<
", pedValflag = " << m_pedValflag
56 cout <<
"Setting pedValflag = 0" << endl;
68 castorHists.ALLPEDS =
new TH1F(
"Castor All Pedestals",
"HF All Peds", 10, 0, 9);
69 castorHists.PEDRMS =
new TH1F(
"Castor All Pedestal Widths",
"HF All Pedestal RMS", 100, 0, 3);
70 castorHists.PEDMEAN =
new TH1F(
"Castor All Pedestal Means",
"HF All Pedestal Means", 100, 0, 9);
71 castorHists.CHI2 =
new TH1F(
"Castor Chi2/ndf for whole range Gauss fit",
"HF Chi2/ndf Gauss", 200, 0., 50.);
77 for (
int i = 0;
i < 16;
i++)
78 _meot->second[
i].first->Delete();
90 m_file =
new TFile(m_outputFileROOT.c_str(),
"RECREATE");
111 throw(
int) castor.
size();
154 static const int bins = 10;
155 static const int bins2 = 100;
158 map<int, PEDBUNCH> _mei;
159 static map<HcalDetId, map<int, float> > QieCalibMap;
160 string type =
"Castor";
175 _meot = toolT.find(detid);
178 if (
_meot == toolT.end()) {
179 map<int, PEDBUNCH>
insert;
180 map<int, float> qiecalib;
182 for (
int i = 0;
i < 4;
i++) {
191 name,
"%s Pedestal, eta=%d phi=%d d=%d cap=%d", type.c_str(), detid.
ieta(), detid.
iphi(), detid.
depth(),
i);
192 insert[
i].first =
new TH1F(name, name, bins, lo, hi);
194 "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
201 insert[4 +
i].first =
new TH1F(name, name, bins2, 0., 100.);
203 "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
210 insert[8 +
i].first =
new TH1F(name, name, bins2, 0., 100.);
212 "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
219 insert[12 +
i].first =
new TH1F(name, name, bins2, 0., 100.);
221 sprintf(name,
"%s Signal in TS 4+5, eta=%d phi=%d d=%d", type.c_str(), detid.
ieta(), detid.
iphi(), detid.
depth());
222 insert[16].first =
new TH1F(name, name, 21, -0.5, 20.5);
224 name,
"%s Signal in TS 4+5-2-3, eta=%d phi=%d d=%d", type.c_str(), detid.
ieta(), detid.
iphi(), detid.
depth());
225 insert[17].first =
new TH1F(name, name, 21, -10.5, 10.5);
227 "%s Signal in TS 4+5-(0+1+2+3)/2., eta=%d phi=%d d=%d",
232 insert[18].first =
new TH1F(name, name, 21, -10.5, 10.5);
234 _meot = toolT.find(detid);
236 QieCalibMap[detid] = qiecalib;
239 _mei =
_meot->second;
251 _mei[qie1.
capid()].first->Reset();
252 _mei[qie1.
capid() + 4].first->Reset();
253 _mei[qie1.
capid() + 8].first->Reset();
254 _mei[qie1.
capid() + 12].first->Reset();
259 _mei[qie1.
capid()].first->Fill(qie1.
adc());
261 _mei[qie1.
capid()].first->Fill(charge1);
262 }
else if (qie1.
adc() >=
bins) {
263 _mei[qie1.
capid()].first->AddBinContent(bins + 1, 1);
269 map<int, float> qiecalib = QieCalibMap[detid];
272 if (charge1 * charge2 < bins2) {
273 _mei[qie1.
capid() + 4 *
flag].first->Fill(charge1 * charge2);
275 _mei[qie1.
capid() + 4 *
flag].first->Fill(bins2);
298 _meot = toolT.find(detid);
299 map<int, PEDBUNCH> _mei =
_meot->second;
300 _mei[16].first->Fill(qie4.
adc() + qie5.
adc() - 1.);
301 _mei[17].first->Fill(qie4.
adc() + qie5.
adc() - qie2.
adc() - qie3.
adc());
302 _mei[18].first->Fill(qie4.
adc() + qie5.
adc() - (qie0.
adc() + qie1.
adc() + qie2.
adc() + qie3.
adc()) / 2.);
308 char PedSampleNum[20];
311 sprintf(PedSampleNum,
"Castor_Sample%d",
sample);
313 m_file->mkdir(PedSampleNum);
333 for (
int i = 0;
i < 4;
i++) {
334 TF1*
fit =
_meot->second[
i].first->GetFunction(
"gaus");
336 if (fit->GetNDF() != 0)
337 chi2[
i] = fit->GetChisquare() / fit->GetNDF();
338 cap[
i] = fit->GetParameter(1);
339 sig[
i][
i] = fit->GetParameter(2);
340 dcap[
i] = fit->GetParError(1);
341 dsig[
i][
i] = fit->GetParError(2);
344 for (
int i = 0;
i < 4;
i++) {
345 cap[
i] =
_meot->second[
i].first->GetMean();
346 sig[
i][
i] =
_meot->second[
i].first->GetRMS();
359 for (
int i = 0;
i < 4;
i++) {
362 _meot->second[
i].first->GetXaxis()->SetTitle(
"ADC");
364 _meot->second[
i].first->GetXaxis()->SetTitle(
"Charge, fC");
365 _meot->second[
i].first->GetYaxis()->SetTitle(
"CapID samplings");
366 _meot->second[
i].first->Write();
369 _meot->second[
i].second.first[0].push_back(cap[
i]);
370 _meot->second[
i].second.first[1].push_back(dcap[i]);
371 _meot->second[
i].second.first[2].push_back(sig[i][i]);
372 _meot->second[
i].second.first[3].push_back(dsig[i][i]);
373 _meot->second[
i].second.first[4].push_back(chi2[i]);
375 PedMeans->Fill(cap[
i]);
376 PedWidths->Fill(sig[i][i]);
381 for (
int i = 16;
i < 19;
i++) {
383 _meot->second[
i].first->GetXaxis()->SetTitle(
"ADC");
385 _meot->second[
i].first->GetXaxis()->SetTitle(
"Charge, fC");
386 _meot->second[
i].first->GetYaxis()->SetTitle(
"Events");
387 _meot->second[
i].first->Write();
392 sig[0][0] = sig[0][0] * sig[0][0];
393 sig[1][1] = sig[1][1] * sig[1][1];
394 sig[2][2] = sig[2][2] * sig[2][2];
395 sig[3][3] = sig[3][3] * sig[3][3];
399 sig[0][1] =
_meot->second[4].first->GetMean() - cap[0] * cap[1];
400 sig[0][2] =
_meot->second[8].first->GetMean() - cap[0] * cap[2];
401 sig[1][2] =
_meot->second[5].first->GetMean() - cap[1] * cap[2];
402 sig[1][3] =
_meot->second[9].first->GetMean() - cap[1] * cap[3];
403 sig[2][3] =
_meot->second[6].first->GetMean() - cap[2] * cap[3];
404 sig[0][3] =
_meot->second[12].first->GetMean() - cap[0] * cap[3];
405 sig[1][0] =
_meot->second[13].first->GetMean() - cap[1] * cap[0];
406 sig[2][0] =
_meot->second[10].first->GetMean() - cap[2] * cap[0];
407 sig[2][1] =
_meot->second[14].first->GetMean() - cap[2] * cap[1];
408 sig[3][1] =
_meot->second[11].first->GetMean() - cap[3] * cap[1];
409 sig[3][2] =
_meot->second[15].first->GetMean() - cap[3] * cap[2];
410 sig[3][0] =
_meot->second[7].first->GetMean() - cap[3] * cap[0];
413 for (
int i = 0;
i < 4;
i++) {
415 _meot->second[
i].second.first[5].push_back(sig[
i][(
i + 1) % 4]);
416 _meot->second[
i].second.first[6].push_back(2 * sig[
i][
i] * dsig[
i][
i]);
417 _meot->second[
i].second.first[7].push_back(sig[i][(i + 2) % 4]);
418 _meot->second[
i].second.first[8].push_back(2 * sig[i][i] * dsig[i][i]);
419 _meot->second[
i].second.first[9].push_back(sig[i][(i + 3) % 4]);
420 _meot->second[
i].second.first[10].push_back(2 * sig[i][i] * dsig[i][i]);
425 _meot->second[
i + 4].first->GetXaxis()->SetTitle(
"ADC^2");
427 _meot->second[
i + 4].first->GetXaxis()->SetTitle(
"Charge^2, fC^2");
428 _meot->second[
i + 4].first->GetYaxis()->SetTitle(
"2-CapID samplings");
429 _meot->second[
i + 4].first->Write();
431 _meot->second[
i + 8].first->GetXaxis()->SetTitle(
"ADC^2");
433 _meot->second[
i + 8].first->GetXaxis()->SetTitle(
"Charge^2, fC^2");
434 _meot->second[
i + 8].first->GetYaxis()->SetTitle(
"2-CapID samplings");
435 _meot->second[
i + 8].first->Write();
437 _meot->second[
i + 12].first->GetXaxis()->SetTitle(
"ADC^2");
439 _meot->second[
i + 12].first->GetXaxis()->SetTitle(
"Charge^2, fC^2");
440 _meot->second[
i + 12].first->GetYaxis()->SetTitle(
"2-CapID samplings");
441 _meot->second[
i + 12].first->Write();
448 sig[1][0] = sig[0][1];
449 sig[2][0] = sig[0][2];
450 sig[2][1] = sig[1][2];
451 sig[3][1] = sig[1][3];
452 sig[3][2] = sig[2][3];
453 sig[0][3] = sig[3][0];
523 for (
int i = 0;
i < 4;
i++)
561 map<int, std::vector<double> > AverageValues;
564 for (
int i = 0;
i < 4;
i++) {
567 sprintf(name,
"Pedestal trend, eta=%d phi=%d d=%d cap=%d", detid.
ieta(), detid.
iphi(), detid.
depth(),
i);
568 int bins =
_meot->second[
i].second.first[0].size();
571 _meot->second[
i].second.second.push_back(
new TH1F(name, name, bins, lo, hi));
572 sprintf(name,
"Width trend, eta=%d phi=%d d=%d cap=%d", detid.
ieta(), detid.
iphi(), detid.
depth(),
i);
573 bins =
_meot->second[
i].second.first[2].size();
574 hi = (
float)bins + 0.5;
575 _meot->second[
i].second.second.push_back(
new TH1F(name, name, bins, lo, hi));
577 "Correlation trend, eta=%d phi=%d d=%d caps=%d*%d",
583 bins =
_meot->second[
i].second.first[5].size();
584 hi = (
float)bins + 0.5;
585 _meot->second[
i].second.second.push_back(
new TH1F(name, name, bins, lo, hi));
595 std::vector<double>::iterator sample_it;
598 for (sample_it =
_meot->second[
i].second.first[0].begin(); sample_it !=
_meot->second[
i].second.first[0].end();
600 _meot->second[
i].second.second[0]->SetBinContent(++j, *sample_it);
603 for (sample_it =
_meot->second[
i].second.first[1].begin(); sample_it !=
_meot->second[
i].second.first[1].end();
605 _meot->second[
i].second.second[0]->SetBinError(++j, *sample_it);
608 _meot->second[
i].second.second[0]->Fit(
"pol0",
"Q");
609 TF1*
fit =
_meot->second[
i].second.second[0]->GetFunction(
"pol0");
610 AverageValues[0].push_back(fit->GetParameter(0));
611 AverageValues[1].push_back(fit->GetParError(0));
613 AverageValues[2].push_back(fit->GetChisquare() / fit->GetNDF());
615 AverageValues[2].push_back(fit->GetChisquare());
617 _meot->second[
i].second.second[0]->GetXaxis()->SetTitle(name);
618 _meot->second[
i].second.second[0]->GetYaxis()->SetTitle(
"Pedestal value");
619 _meot->second[
i].second.second[0]->Write();
622 for (sample_it =
_meot->second[
i].second.first[2].begin(); sample_it !=
_meot->second[
i].second.first[2].end();
624 _meot->second[
i].second.second[1]->SetBinContent(++j, *sample_it);
627 for (sample_it =
_meot->second[
i].second.first[3].begin(); sample_it !=
_meot->second[
i].second.first[3].end();
629 _meot->second[
i].second.second[1]->SetBinError(++j, *sample_it);
631 _meot->second[
i].second.second[1]->GetXaxis()->SetTitle(name);
632 _meot->second[
i].second.second[1]->GetYaxis()->SetTitle(
"Pedestal width");
633 _meot->second[
i].second.second[1]->Write();
636 for (sample_it =
_meot->second[
i].second.first[5].begin(); sample_it !=
_meot->second[
i].second.first[5].end();
638 _meot->second[
i].second.second[2]->SetBinContent(++j, *sample_it);
641 for (sample_it =
_meot->second[
i].second.first[6].begin(); sample_it !=
_meot->second[
i].second.first[6].end();
643 _meot->second[
i].second.second[2]->SetBinError(++j, *sample_it);
645 _meot->second[
i].second.second[2]->GetXaxis()->SetTitle(name);
646 _meot->second[
i].second.second[2]->GetYaxis()->SetTitle(
"Close correlation");
647 _meot->second[
i].second.second[2]->Write();
676 for (sample_it =
_meot->second[
i].second.first[4].begin(); sample_it !=
_meot->second[
i].second.first[4].end();
678 Chi2->Fill(*sample_it);
682 CapidAverage =
new TH1F(
"Constant fit: Pedestal Values",
683 "Constant fit: Pedestal Values",
684 AverageValues[0].
size(),
686 AverageValues[0].
size());
687 std::vector<double>::iterator sample_it;
689 for (sample_it = AverageValues[0].
begin(); sample_it != AverageValues[0].end(); ++sample_it) {
690 CapidAverage->SetBinContent(++j, *sample_it);
693 for (sample_it = AverageValues[1].
begin(); sample_it != AverageValues[1].end(); ++sample_it) {
694 CapidAverage->SetBinError(++j, *sample_it);
696 CapidChi2 =
new TH1F(
697 "Constant fit: Chi2/ndf",
"Constant fit: Chi2/ndf", AverageValues[2].
size(), 0., AverageValues[2].
size());
699 for (sample_it = AverageValues[2].
begin(); sample_it != AverageValues[2].end(); ++sample_it) {
700 CapidChi2->SetBinContent(++j, *sample_it);
703 Chi2->GetXaxis()->SetTitle(
"Chi2/ndf");
704 Chi2->GetYaxis()->SetTitle(
"50 x [(16+2) x 4 x 4] `events`");
706 CapidAverage->GetYaxis()->SetTitle(
"Pedestal value");
707 CapidAverage->GetXaxis()->SetTitle(
"(16+2) x 4 x 4 `events`");
708 CapidAverage->Write();
709 CapidChi2->GetYaxis()->SetTitle(
"Chi2/ndf");
710 CapidChi2->GetXaxis()->SetTitle(
"(16+2) x 4 x 4 `events`");
727 float RefPedSigs[4][4];
729 float RawPedSigs[4][4];
730 map<HcalDetId, bool> isinRaw;
731 map<HcalDetId, bool> isinRef;
734 std::ofstream PedValLog;
735 PedValLog.open(
"CastorPedVal.log");
737 if (nstat[0] + nstat[1] + nstat[2] + nstat[3] < 2500)
738 PedValLog <<
"CastorPedVal: warning - low statistics" << std::endl;
740 for (
int i = 0;
i < (
int)RawChanns.size();
i++) {
743 for (
int i = 0;
i < (
int)RefChanns.size();
i++) {
745 isinRaw[detid] =
false;
746 isinRef[detid] =
true;
748 for (
int i = 0;
i < (
int)RawChanns.size();
i++) {
750 isinRaw[detid] =
true;
751 if (isinRef[detid] ==
false) {
752 PedValLog <<
"CastorPedVal: channel " << detid <<
" not found in reference set" << std::endl;
753 std::cerr <<
"CastorPedVal: channel " << detid <<
" not found in reference set" << std::endl;
759 for (
int i = 0;
i < (
int)RefChanns.size();
i++) {
761 for (
int icap = 0; icap < 4; icap++) {
763 for (
int icap2 = icap; icap2 < 4; icap2++) {
764 RefPedSigs[icap][icap2] = fRefPedestalWidths->
getValues(detid)->
getSigma(icap, icap2);
766 RefPedSigs[icap2][icap] = RefPedSigs[icap][icap2];
771 if (isinRaw[detid]) {
772 for (
int icap = 0; icap < 4; icap++) {
774 for (
int icap2 = icap; icap2 < 4; icap2++) {
775 RawPedSigs[icap][icap2] = fRawPedestalWidths->
getValues(detid)->
getSigma(icap, icap2);
777 RawPedSigs[icap2][icap] = RawPedSigs[icap][icap2];
782 for (
int icap = 0; icap < 4; icap++) {
783 if (RawPedVals[icap] < 1. || RawPedSigs[icap][icap] < 0.01)
784 isinRaw[detid] =
false;
785 for (
int icap2 = icap; icap2 < 4; icap2++) {
786 if (fabs(RawPedSigs[icap][icap2] /
sqrt(RawPedSigs[icap][icap] * RawPedSigs[icap2][icap2])) > 1.)
787 isinRaw[detid] =
false;
793 if (isinRaw[detid]) {
794 for (
int icap = 0; icap < 4; icap++) {
795 int icap2 = (icap + 1) % 4;
796 float width =
sqrt(RawPedSigs[icap][icap]);
797 float erof1 = width /
sqrt((
float)nstat[icap]);
798 float erof2 =
sqrt(erof1 * erof1 + RawPedSigs[icap][icap] / (
float)nstat[icap]);
799 float erofwidth = width /
sqrt(2. * nstat[icap]);
800 float diffof1 = RawPedVals[icap] - RefPedVals[icap];
801 float diffof2 = RawPedVals[icap] + RawPedVals[icap2] - RefPedVals[icap] - RefPedVals[icap2];
802 float diffofw = width -
sqrt(RefPedSigs[icap][icap]);
808 if (nTS == 1 && fabs(diffof1) > 0.5 + erof1) {
810 PedValLog <<
"HcalPedVal: drift in channel " << detid <<
" cap " << icap <<
": " << RawPedVals[icap] <<
" - " 811 << RefPedVals[icap] <<
" = " << diffof1 << std::endl;
813 if (nTS == 2 && fabs(diffof2) > 0.5 + erof2) {
815 PedValLog <<
"HcalPedVal: drift in channel " << detid <<
" caps " << icap <<
"+" << icap2 <<
": " 816 << RawPedVals[icap] <<
"+" << RawPedVals[icap2] <<
" - " << RefPedVals[icap] <<
"+" 817 << RefPedVals[icap2] <<
" = " << diffof2 << std::endl;
819 if (fabs(diffofw) > 0.15 * width + erofwidth) {
821 PedValLog <<
"HcalPedVal: width changed in channel " << detid <<
" cap " << icap <<
": " << width <<
" - " 822 <<
sqrt(RefPedSigs[icap][icap]) <<
" = " << diffofw << std::endl;
829 PedValLog <<
"HcalPedVal: no valid data from channel " << detid << std::endl;
831 CastorPedestal item(detid, RefPedVals[0], RefPedVals[1], RefPedVals[2], RefPedVals[3]);
834 for (
int icap = 0; icap < 4; icap++) {
835 for (
int icap2 = icap; icap2 < 4; icap2++)
836 widthsp.
setSigma(icap2, icap, RefPedSigs[icap2][icap]);
845 PedValLog <<
"HcalPedVal: all pedestals checked OK" << std::endl;
849 if (erflag % 100000 == 0) {
850 for (
int i = 0;
i < (
int)RefChanns.size();
i++) {
852 if (isinRaw[detid]) {
854 for (
int icap = 0; icap < 4; icap++) {
856 for (
int icap2 = icap; icap2 < 4; icap2++) {
857 RefPedSigs[icap][icap2] = fRefPedestalWidths->
getValues(detid)->
getSigma(icap, icap2);
859 RefPedSigs[icap2][icap] = RefPedSigs[icap][icap2];
860 widthsp.
setSigma(icap2, icap, RefPedSigs[icap2][icap]);
864 CastorPedestal item(detid, RefPedVals[0], RefPedVals[1], RefPedVals[2], RefPedVals[3]);
872 for (
int i = 0;
i < (
int)RawChanns.size();
i++) {
874 if (isinRaw[detid]) {
876 for (
int icap = 0; icap < 4; icap++) {
878 for (
int icap2 = icap; icap2 < 4; icap2++) {
879 RawPedSigs[icap][icap2] = fRawPedestalWidths->
getValues(detid)->
getSigma(icap, icap2);
881 RawPedSigs[icap2][icap] = RawPedSigs[icap][icap2];
882 widthsp.
setSigma(icap2, icap, RawPedSigs[icap2][icap]);
886 CastorPedestal item(detid, RawPedVals[0], RawPedVals[1], RawPedVals[2], RawPedVals[3]);
T getUntrackedParameter(std::string const &, T const &) const
float getValue(int fCapId) const
get value for capId = 0..3
void setSigma(int fCapId1, int fCapId2, float fSigma)
CastorPedestalWidths * fRawPedestalWidths
struct CastorPedestalAnalysis::@41 castorHists
const CastorQIECoder * m_coder
const HcalQIESample & sample(int i) const
access a sample
std::vector< T >::const_iterator const_iterator
CastorPedestals * fRawPedestals
std::vector< DetId > getAllChannels() const
~CastorPedestalAnalysis()
Destructor.
static int CastorPedVal(int nstat[4], const CastorPedestals *fRefPedestals, const CastorPedestalWidths *fRefPedestalWidths, CastorPedestals *fRawPedestals, CastorPedestalWidths *fRawPedestalWidths, CastorPedestals *fValPedestals, CastorPedestalWidths *fValPedestalWidths)
const Item * getValues(DetId fId, bool throwOnFail=true) const
void setup(const std::string &m_outputFileROOT)
void processEvent(const CastorDigiCollection &castor, const CastorDbService &cond)
std::vector< bool > state
int depth() const
get the tower depth
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)
std::map< HcalDetId, std::map< int, PEDBUNCH > >::iterator _meot
float getSigma(int fCapId1, int fCapId2) const
get correlation element for capId1/2 = 0..3
const CastorQIEShape * getCastorShape() const
int ieta() const
get the cell ieta
float charge(const CastorQIEShape &fShape, unsigned fAdc, unsigned fCapId) const
ADC [0..127] + capid [0..3] -> fC conversion.
std::string m_outputFileMean
CastorPedestals * fValPedestals
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
constexpr int adc() const
get the ADC sample
const_iterator end() const
int iphi() const
get the cell iphi
std::string m_outputFileWidth
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
const CastorPedestalWidths * fRefPedestalWidths
CastorPedestalAnalysis(const edm::ParameterSet &ps)
Constructor.
std::string m_outputFileROOT
void GetPedConst(std::map< HcalDetId, std::map< int, PEDBUNCH > > &toolT, TH1F *PedMeans, TH1F *PedWidths)
const HcalCastorDetId & id() const
int size() const
total number of samples in the digi
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_iterator begin() const
const CastorQIECoder * getCastorCoder(const HcalGenericDetId &fId) const
const CastorPedestals * fRefPedestals