File indexing completed on 2025-12-18 09:22:10
0001 #include <calobase/TowerInfoDefs.h>
0002 #include <cdbobjects/CDBTTree.h>
0003
0004 #include <Rtypes.h>
0005 #include <TH2.h>
0006
0007 R__LOAD_LIBRARY(libcdbobjects)
0008 R__LOAD_LIBRARY(libcalo_io.so)
0009
0010 void histToCaloCDBTree(const std::string &outputfile, const std::string &fieldName, int icalo, TH2 *hist)
0011 {
0012 int neta;
0013 int nphi;
0014
0015 if (icalo != 0 && icalo != 1) return;
0016
0017 if (icalo == 0)
0018 {
0019 neta = 96;
0020 nphi = 256;
0021 }
0022 if (icalo == 1)
0023 {
0024 neta = 24;
0025 nphi = 64;
0026 }
0027
0028 CDBTTree *cdbttree = new CDBTTree(outputfile);
0029
0030 float mean = 0;
0031 int count = 0;
0032
0033 for (int ie = 0; ie < neta; ie++)
0034 {
0035 for (int ip = 0; ip < nphi; ip++)
0036 {
0037 unsigned int key;
0038 if (icalo == 0) key = TowerInfoDefs::encode_emcal(ie, ip);
0039 if (icalo == 1) key = TowerInfoDefs::encode_hcal(ie, ip);
0040 float val = hist->GetBinContent(ie + 1, ip + 1);
0041 cdbttree->SetFloatValue(key, fieldName, val);
0042 mean += val;
0043 count++;
0044 }
0045 }
0046
0047 std::cout << "Writing " << outputfile.c_str() << " with mean=" << mean / count << std::endl;
0048 cdbttree->Commit();
0049 cdbttree->WriteCDBTTree();
0050
0051 delete cdbttree;
0052 }
0053
0054 TH2 *CaloCDBTreeToHist(const std::string &inputfile, const std::string &fieldName, int icalo)
0055 {
0056 CDBTTree *cdbttree = new CDBTTree(inputfile);
0057
0058 int neta;
0059 int nphi;
0060
0061 if (icalo != 0 && icalo != 1) return nullptr;
0062
0063 if (icalo == 0)
0064 {
0065 neta = 96;
0066 nphi = 256;
0067 }
0068 if (icalo == 1)
0069 {
0070 neta = 24;
0071 nphi = 64;
0072 }
0073
0074 TH2 *h2 = new TH2F("h_temp", "", neta, 0, neta, nphi, 0, nphi);
0075
0076 for (int ie = 0; ie < neta; ie++)
0077 {
0078 for (int ip = 0; ip < nphi; ip++)
0079 {
0080 unsigned int key;
0081 if (icalo == 0) key = TowerInfoDefs::encode_emcal(ie, ip);
0082 if (icalo == 1) key = TowerInfoDefs::encode_hcal(ie, ip);
0083
0084 float val = cdbttree->GetFloatValue(key, fieldName);
0085 h2->SetBinContent(ie + 1, ip + 1, val);
0086 }
0087 }
0088
0089 return h2;
0090 }