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();
109 edm::LogError(
"CastorLedAnalysis") <<
"Event with " << (
int)
castor.size() <<
"Castor Digis passed." << std::endl;
152 static const int bins = 10;
153 static const int bins2 = 100;
156 std::map<int, PEDBUNCH> _mei;
157 static std::map<HcalDetId, std::map<int, float> > QieCalibMap;
173 _meot = toolT.find(detid);
176 if (
_meot == toolT.end()) {
177 std::map<int, PEDBUNCH>
insert;
178 std::map<int, float> qiecalib;
180 for (
int i = 0;
i < 4;
i++) {
189 name,
"%s Pedestal, eta=%d phi=%d d=%d cap=%d",
type.c_str(), detid.
ieta(), detid.
iphi(), detid.
depth(),
i);
192 "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
201 "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
210 "%s Product, eta=%d phi=%d d=%d caps=%d*%d",
219 sprintf(
name,
"%s Signal in TS 4+5, eta=%d phi=%d d=%d",
type.c_str(), detid.
ieta(), detid.
iphi(), detid.
depth());
222 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 "%s Signal in TS 4+5-(0+1+2+3)/2., eta=%d phi=%d d=%d",
232 _meot = toolT.find(detid);
234 QieCalibMap[detid] = qiecalib;
237 _mei =
_meot->second;
249 _mei[qie1.
capid()].first->Reset();
250 _mei[qie1.
capid() + 4].first->Reset();
251 _mei[qie1.
capid() + 8].first->Reset();
252 _mei[qie1.
capid() + 12].first->Reset();
257 _mei[qie1.
capid()].first->Fill(qie1.
adc());
259 _mei[qie1.
capid()].first->Fill(charge1);
260 }
else if (qie1.
adc() >=
bins) {
261 _mei[qie1.
capid()].first->AddBinContent(
bins + 1, 1);
267 std::map<int, float> qiecalib = QieCalibMap[detid];
270 if (charge1 * charge2 < bins2) {
271 _mei[qie1.
capid() + 4 *
flag].first->Fill(charge1 * charge2);
273 _mei[qie1.
capid() + 4 *
flag].first->Fill(bins2);
296 _meot = toolT.find(detid);
297 std::map<int, PEDBUNCH> _mei =
_meot->second;
298 _mei[16].first->Fill(qie4.
adc() + qie5.
adc() - 1.);
299 _mei[17].first->Fill(qie4.
adc() + qie5.
adc() - qie2.
adc() - qie3.
adc());
300 _mei[18].first->Fill(qie4.
adc() + qie5.
adc() - (qie0.
adc() + qie1.
adc() + qie2.
adc() + qie3.
adc()) / 2.);
306 char PedSampleNum[20];
309 sprintf(PedSampleNum,
"Castor_Sample%d",
sample);
311 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)
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++) {
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 std::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();
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();
577 "Correlation trend, eta=%d phi=%d d=%d caps=%d*%d",
583 bins =
_meot->second[
i].second.first[5].size();
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 std::map<HcalDetId, bool> isinRaw;
731 std::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++) {
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++) {
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++) {
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++) {
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]);
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
CastorPedestals * fRawPedestals
~CastorPedestalAnalysis()
Destructor.
static int CastorPedVal(int nstat[4], const CastorPedestals *fRefPedestals, const CastorPedestalWidths *fRefPedestalWidths, CastorPedestals *fRawPedestals, CastorPedestalWidths *fRawPedestalWidths, CastorPedestals *fValPedestals, CastorPedestalWidths *fValPedestalWidths)
Log< level::Error, false > LogError
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
std::vector< bool > state
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
constexpr int ieta() const
get the cell ieta
std::string m_outputFileMean
CastorPedestals * fValPedestals
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
const HcalCastorDetId & id() const
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
struct CastorPedestalAnalysis::@44 castorHists
const CastorPedestalWidths * fRefPedestalWidths
CastorPedestalAnalysis(const edm::ParameterSet &ps)
Constructor.
constexpr int adc() const
get the ADC sample
std::string m_outputFileROOT
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
constexpr int iphi() const
get the cell iphi
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