Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
doTscFit.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file doTscFit.C
1 #pragma once
2 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,00,0)
3 #include <fun4all/SubsysReco.h>
8 //#include <rawwaveformtowerbuilder/RawWaveformTowerBuilder.h>
10 #include <fun4all/Fun4AllUtils.h>
11 
12 #include <cdbobjects/CDBTTree.h> // for CDBTTree
13 #include "TowerInfo.h"
14 #include "TowerInfoDefs.h"
15 
16 #include <litecaloeval/LiteCaloEval.h>
17 #include <caloreco/CaloTowerCalib.h>
18 #include <caloreco/RawClusterBuilderTemplate.h>
19 
20 #include <phool/recoConsts.h>
21 
22 #include "/sphenix/u/bseidlitz/work/macros/calibrations/calo/calib_nov23/towerslope/TSCtoCDBTTree.C"
23 
24 R__LOAD_LIBRARY(libfun4all.so)
25 R__LOAD_LIBRARY(libfun4allraw.so)
26 R__LOAD_LIBRARY(libcalo_reco.so)
27 R__LOAD_LIBRARY(libLiteCaloEvalTowSlope.so)
28 R__LOAD_LIBRARY(libcalo_io.so)
29 R__LOAD_LIBRARY(libcdbobjects)
30 
31 void mergeCDBTTrees(const char * infile1, const char * infile2, const char * outputfile);
32 
33 #endif
34 
35 //void doTscFit(int nevents = 0, const char *fname = "input.list", const char * outfile = "defout.root", const char * fitoutfile = "deffitout.root")
36 void doTscFit(const std::string &hist_fname = "parallel_test/combine_out/out1.root", const std::string &calib_fname = "parallel_test/local_cdb_copy.root")
37 {
38  //Fun4AllServer *se = Fun4AllServer::instance();
39 
40  string fitoutfile = "tsc_fitout.root";
41 
42  LiteCaloEval modlce;
44  modlce.Get_Histos(hist_fname.c_str(),fitoutfile.c_str());
45  modlce.m_myminbin = 8;
46  modlce.m_mymaxbin = 95 + 1 ;
47  modlce.setFitMin(0.12);
48  modlce.setFitMax(0.7);
49  modlce.FitRelativeShifts(&modlce,110);
50 
51  // create the cdbttree from tsc output andd multiply the corrections
52  // into the base calibration to pickup for pi0 first iteration
53  TSCtoCDBTTree(fitoutfile.c_str(),"tsc_output_cdb.root");
54  mergeCDBTTrees("tsc_output_cdb.root",calib_fname.c_str(),calib_fname.c_str());
55 
56  size_t pos = calib_fname.find_last_of('.');
57  string f_calib_save_name = calib_fname;
58  f_calib_save_name.insert(pos,"_postTSC");
59 
60  TFile* f_calib_mod = new TFile(calib_fname.c_str());
61  f_calib_mod->Cp(f_calib_save_name.c_str());
62 
63  gSystem->Exit(0);
64 }
65 
66 
67 void mergeCDBTTrees(const char * infile1, const char * infile2, const char * outputfile)
68 {
69 
70  CDBTTree *cdbttree1 = new CDBTTree(infile1);
71  CDBTTree *cdbttree2 = new CDBTTree(infile2);
72  CDBTTree *cdbttreeOut = new CDBTTree(outputfile);
73 
74  string m_fieldname = "Femc_datadriven_qm1_correction";
75 
76  for(int i = 0; i < 96 ; i++)
77  {
78  for(int j = 0; j < 256; j++)
79  {
80  unsigned int key = TowerInfoDefs::encode_emcal(i,j);
81  float val1 = cdbttree1->GetFloatValue(key, m_fieldname);
82  float val2 = cdbttree2->GetFloatValue(key, m_fieldname);
83  cdbttreeOut->SetFloatValue(key,m_fieldname,val1*val2);
84  }
85  }
86 
87  cdbttreeOut->Commit();
88  cdbttreeOut->WriteCDBTTree();
89  delete cdbttreeOut;
90  delete cdbttree1;
91  delete cdbttree2;
92 
93 }//end macro
94