Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-12-18 09:22:11

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