File indexing completed on 2025-12-18 09:22:11
0001 #include"cdbHistConv.C"
0002
0003 #include <TH2.h>
0004 #include <TFile.h>
0005
0006 void rescaleTSC(TH2* h_tsc,TH2* h_cos);
0007 void checkTsc(TH2* h);
0008 void checkCos(TH2* h);
0009
0010 void tsc_cos_merge(const std::string &tsc_file, const std::string &cos_cdb_file,const std::string &output_name, int isIHcal){
0011
0012
0013 std::string fieldName_in = "ohcal_cosmic_calibration";
0014 if (isIHcal ==1) fieldName_in = "ihcal_cosmic_calibration";
0015 TH2* h_ohcal = CaloCDBTreeToHist(cos_cdb_file,fieldName_in,1);
0016
0017
0018 TFile* ftsc_ohcal = new TFile(tsc_file.c_str());
0019 TH2* h_tsc_corr_ohcal {nullptr};
0020 ftsc_ohcal->GetObject("corrPat",h_tsc_corr_ohcal);
0021
0022 checkTsc(h_tsc_corr_ohcal);
0023 checkCos(h_ohcal);
0024 rescaleTSC(h_tsc_corr_ohcal,h_ohcal);
0025 h_ohcal->Divide(h_tsc_corr_ohcal);
0026
0027
0028 std::string fieldName = "HCALOUT_calib_ADC_to_ETower";
0029 if (isIHcal ==1) fieldName = "HCALIN_calib_ADC_to_ETower";
0030 histToCaloCDBTree( output_name, fieldName, 1, h_ohcal);
0031
0032 }
0033
0034
0035 void checkTsc(TH2* h){
0036
0037 for (int ie=0; ie<24; ie++)
0038 for (int ip=0; ip<64; ip++)
0039 if (h->GetBinContent(ie+1,ip+1) < 0.5 || h->GetBinContent(ie+1,ip+1) > 1.3)
0040 h->SetBinContent(ie+1,ip+1,1);
0041 }
0042
0043 void checkCos(TH2* h){
0044 float avg=0;
0045 int cc=0;
0046 for (int ie=0; ie<24; ie++){
0047 for (int ip=0; ip<64; ip++){
0048 avg += h->GetBinContent(ie+1,ip+1);
0049 cc++;
0050 }
0051 }
0052 avg/=cc;
0053 std::cout << "avg=" << avg << std::endl;
0054
0055 for (int ie=0; ie<24; ie++)
0056 for (int ip=0; ip<64; ip++)
0057 if (h->GetBinContent(ie+1,ip+1) < 0.3*avg || h->GetBinContent(ie+1,ip+1) > 2.3*avg)
0058 h->SetBinContent(ie+1,ip+1,avg);
0059
0060 }
0061
0062
0063 void rescaleTSC(TH2* h_tsc,TH2* h_cos){
0064
0065
0066
0067 int chimEtaLow = 0;
0068 int chimEtaHigh = 4;
0069 int chimPhiLow = 12;
0070 int chimPhiHigh= 20;
0071 int supportEtaLow = 21;
0072 int supportEtaHigh = 23;
0073 int supportPhiLow = 12;
0074 int supportPhiHigh = 20;
0075
0076
0077
0078 int bin1l = 26;
0079 int bin1h = 37;
0080 int bin2h = 58;
0081 int bin2l = 5;
0082 float etaAvg_tsc[24] = {0};
0083 float etaAvg_cos[24] = {0};
0084
0085 for (int ie=0; ie<24; ie++){
0086 int c = 0;
0087 for (int ip=0; ip<64; ip++){
0088 if ( ip <= bin2l || (ip >= bin1l && ip <= bin1h) || ip >= bin2h){
0089 etaAvg_tsc[ie] += h_tsc->GetBinContent(ie+1,ip+1);
0090 etaAvg_cos[ie] += h_cos->GetBinContent(ie+1,ip+1);
0091 c++;
0092 }
0093 }
0094 etaAvg_tsc[ie] /= c;
0095 std::cout << ie << " " << etaAvg_tsc[ie] << std::endl;
0096 etaAvg_cos[ie] /= c;
0097 for (int ip=0; ip<64; ip++){
0098 float val = h_tsc->GetBinContent(ie+1,ip+1);
0099 val /= etaAvg_tsc[ie];
0100 h_tsc->SetBinContent(ie+1,ip+1,val);
0101 }
0102 for (int ip=0; ip<64; ip++){
0103 bool isChim = ( ie >= chimEtaLow && ie <= chimEtaHigh && ip >= chimPhiLow && ip <= chimPhiHigh);
0104 bool isSupport = ( ie >= supportEtaLow && ie <= supportEtaHigh && ip >= supportPhiLow && ip <= supportPhiHigh);
0105 if(isChim || isSupport) h_tsc->SetBinContent(ie+1,ip+1,1);
0106 }
0107 }
0108
0109
0110
0111 }
0112
0113
0114 void genCdbCorr_HH(float corr, const std::string &cos_cdb_file,const std::string &output_name, int isIHcal,std::vector<std::vector<float>> halfhighs){
0115
0116
0117 std::string fieldName_in = "ohcal_abscalib_mip";
0118 if (isIHcal ==1) fieldName_in = "ihcal_cosmic_calibration";
0119 TH2* h_ohcal = CaloCDBTreeToHist(cos_cdb_file,fieldName_in,1);
0120
0121 if (!h_ohcal){
0122 std::cout << "cosmic hist not found exiting" << std::endl;
0123 return;
0124 }
0125 for(int ic=0; ic<halfhighs.size(); ic++)
0126 {
0127 float val = h_ohcal->GetBinContent(halfhighs[ic][0]+1,halfhighs[ic][1]+1);
0128 float new_val = val*halfhighs[ic][2];
0129 std::cout << "correct half height " << halfhighs[ic][0] << "," << halfhighs[ic][1] << " " << halfhighs[ic][2] << std::endl;
0130 h_ohcal->SetBinContent(halfhighs[ic][0]+1,halfhighs[ic][1]+1,new_val);
0131 }
0132
0133 h_ohcal->Scale(corr);
0134
0135
0136 std::string fieldName = "HCALOUT_calib_ADC_to_ETower";
0137 if (isIHcal ==1) fieldName = "HCALIN_calib_ADC_to_ETower";
0138 histToCaloCDBTree( output_name, fieldName, 1, h_ohcal);
0139 delete h_ohcal;
0140 }
0141
0142
0143
0144
0145 void genCdbCorr(float corr, const std::string &cos_cdb_file,const std::string &output_name, int isIHcal){
0146
0147 std::cout << "heeeelllloooooo" << std::endl;
0148
0149 std::string fieldName_in = "ohcal_abscalib_mip";
0150 if (isIHcal ==1) fieldName_in = "ihcal_cosmic_calibration";
0151 TH2* h_ohcal = CaloCDBTreeToHist(cos_cdb_file,fieldName_in,1);
0152
0153 if (!h_ohcal){
0154 std::cout << "cosmic hist not found exiting" << std::endl;
0155 return;
0156 }
0157
0158
0159 h_ohcal->Scale(corr);
0160
0161
0162 std::string fieldName = "ohcal_abscalib_mip";
0163 if (isIHcal ==1) fieldName = "ihcal_abscalib_mip";
0164 histToCaloCDBTree( output_name, fieldName, 1, h_ohcal);
0165 }