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 iphi= 0; iphi< nphi; iphi++)
0030     {
0031       unsigned int key;
0032       if (icalo==0) key = TowerInfoDefs::encode_emcal(ie,iphi);
0033       if (icalo==1) key = TowerInfoDefs::encode_hcal(ie,iphi);
0034       float val = hist->GetBinContent(ie+1,iphi+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