File indexing completed on 2025-08-05 08:19:43
0001 #include <cdbobjects/CDBTTree.h>
0002 #include "TowerInfoDefs.h"
0003
0004 R__LOAD_LIBRARY(libcdbobjects)
0005 R__LOAD_LIBRARY(libcalo_io.so)
0006
0007 void histToCaloCDBTree(string outputfile, string fieldName, int icalo, TH2F* hist){
0008
0009 int neta,nphi;
0010
0011 if (icalo != 0 && icalo != 1) return;
0012
0013 if (icalo==0){
0014 neta = 96;
0015 nphi = 256;
0016 }
0017 if (icalo==1){
0018 neta = 24;
0019 nphi = 64;
0020 }
0021
0022 CDBTTree *cdbttree = new CDBTTree(outputfile);
0023
0024 float mean = 0;
0025 int count = 0;
0026
0027 for(int ie = 0; ie < neta ; ie++)
0028 {
0029 for(int ip= 0; ip< nphi; ip++)
0030 {
0031 unsigned int key;
0032 if (icalo==0) key = TowerInfoDefs::encode_emcal(ie,ip);
0033 if (icalo==1) key = TowerInfoDefs::encode_hcal(ie,ip);
0034 float val = hist->GetBinContent(ie+1,ip+1);
0035 cdbttree->SetFloatValue(key,fieldName,val);
0036 mean += val;
0037 count++;
0038 }
0039 }
0040
0041 cout << "Writing " << outputfile.c_str() << " with mean=" << mean/count << endl;
0042 cdbttree->Commit();
0043 cdbttree->WriteCDBTTree();
0044
0045 delete cdbttree;
0046 }
0047
0048
0049 TH2F* CaloCDBTreeToHist(string inputfile, string fieldName, int icalo){
0050
0051 CDBTTree* cdbttree = new CDBTTree(inputfile);
0052 if (!cdbttree){
0053 cout << "CaloCDBTreeToHist: could not get cdb tree" << endl;
0054 return nullptr;
0055 }
0056
0057 int neta,nphi;
0058
0059 if (icalo != 0 && icalo != 1) return nullptr;
0060
0061 if (icalo==0){
0062 neta = 96;
0063 nphi = 256;
0064 }
0065 if (icalo==1){
0066 neta = 24;
0067 nphi = 64;
0068 }
0069
0070 TH2F* h2 = new TH2F("h_temp","",neta,0,neta,nphi,0,nphi);
0071
0072 for(int ie = 0; ie < neta ; ie++)
0073 {
0074 for(int ip= 0; ip< nphi; ip++)
0075 {
0076 unsigned int key;
0077 if (icalo==0) key = TowerInfoDefs::encode_emcal(ie,ip);
0078 if (icalo==1) key = TowerInfoDefs::encode_hcal(ie,ip);
0079
0080 float val = cdbttree->GetFloatValue(key, fieldName);
0081 h2->SetBinContent(ie+1,ip+1,val);
0082 }
0083 }
0084
0085 return h2;
0086 }
0087
0088
0089 void swtichFieldName(string infile,string outfile,string infield,string outfield,int icalo){
0090
0091 TH2F* h = CaloCDBTreeToHist(infile, infield, icalo);
0092 histToCaloCDBTree(outfile, outfield, icalo, h);
0093
0094
0095 }
0096
0097
0098
0099 void makeDefaultCalib(string infile,string outfile,string infield,int icalo){
0100
0101 TH2F* h = CaloCDBTreeToHist(infile, infield, icalo);
0102
0103 int c = 0;
0104 float avg = 0;
0105 for(int ie=1; ie<h->GetXaxis()->GetNbins()+1; ie++){
0106 for(int ip=1; ip<h->GetYaxis()->GetNbins()+1; ip++){
0107 float val = h->GetBinContent(ie,ip);
0108 if (val != 0) {avg+=val; c++;}
0109 }
0110 }
0111 avg /= c;
0112 for(int ie=1; ie<h->GetXaxis()->GetNbins()+1; ie++){
0113 for(int ip=1; ip<h->GetYaxis()->GetNbins()+1; ip++){
0114 float val = h->GetBinContent(ie,ip);
0115 if (val == 0) h->SetBinContent(ie,ip,avg);
0116 }
0117 }
0118
0119 histToCaloCDBTree(outfile, infield, icalo, h);
0120 }