Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:21:02

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