Back to home page

sPhenix code displayed by LXR

 
 

    


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

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   //cdbttree->Print();
0045   delete cdbttree;
0046 }
0047 
0048 
0049 TH2F* CaloCDBTreeToHist(string inputfile, string fieldName, int icalo){
0050 
0051   CDBTTree* cdbttree = new CDBTTree(inputfile);
0052 
0053   int neta,nphi;
0054 
0055   if (icalo != 0 && icalo != 1) return nullptr;
0056 
0057   if (icalo==0){
0058     neta = 96;
0059     nphi = 256;
0060   }
0061   if (icalo==1){
0062     neta = 24;
0063     nphi = 64;
0064   }
0065 
0066   TH2F* h2 = new TH2F("h_temp","",neta,0,neta,nphi,0,nphi);
0067   h_temp->SetDirectory(nullptr);
0068 
0069   for(int ie = 0; ie < neta ; ie++)
0070   {
0071     for(int ip= 0; ip< nphi; ip++)
0072     {
0073       unsigned int key;
0074       if (icalo==0) key = TowerInfoDefs::encode_emcal(ie,ip);
0075       if (icalo==1) key = TowerInfoDefs::encode_hcal(ie,ip);
0076 
0077       float val = cdbttree->GetFloatValue(key, fieldName);
0078       h2->SetBinContent(ie+1,ip+1,val);
0079     }
0080   }
0081 
0082   return h2;
0083 }