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 #include <cdbobjects/CDBTTree.h> // for CDBTTree
2 #include <litecaloeval/LiteCaloEval.h>
3 
4 #include <cdbobjects/CDBTTree.h> // for CDBTTree
5 #include "TowerInfoDefs.h"
6 
7 
8 R__LOAD_LIBRARY(libLiteCaloEvalTowSlope.so)
9 R__LOAD_LIBRARY(libcdbobjects)
10 
11 
12 void TSCtoCDBTTree(const char * infile, const char * outputfile);
13 void mergeCDBTTrees(const char * infile1, const char * infile2, const char * outputfile);
14 
15 void doTscFit(const std::string &hist_fname = "base/combine_out/out1.root", const std::string &calib_fname = "base/local_calib_copy.root")
16 {
17  //Fun4AllServer *se = Fun4AllServer::instance();
18 
19  string fitoutfile = "tsc_fitout.root";
20 
21  LiteCaloEval modlce;
23  modlce.Get_Histos(hist_fname.c_str(),fitoutfile.c_str());
24  modlce.m_myminbin = 8;
25  modlce.m_mymaxbin = 95 + 1 ;
26  modlce.setFitMin(0.12);
27  modlce.setFitMax(0.7);
28  modlce.FitRelativeShifts(&modlce,110);
29 
30  // create the cdbttree from tsc output andd multiply the corrections
31  // into the base calibration to pickup for pi0 first iteration
32  TSCtoCDBTTree(fitoutfile.c_str(),"tsc_output_cdb.root");
33  mergeCDBTTrees("tsc_output_cdb.root",calib_fname.c_str(),calib_fname.c_str());
34 
35  size_t pos = calib_fname.find_last_of('.');
36  string f_calib_save_name = calib_fname;
37  f_calib_save_name.insert(pos,"_postTSC");
38 
39  TFile* f_calib_mod = new TFile(calib_fname.c_str());
40  f_calib_mod->Cp(f_calib_save_name.c_str());
41 
42  gSystem->Exit(0);
43 }
44 
45 
46 void mergeCDBTTrees(const char * infile1, const char * infile2, const char * outputfile)
47 {
48 
49  CDBTTree *cdbttree1 = new CDBTTree(infile1);
50  CDBTTree *cdbttree2 = new CDBTTree(infile2);
51  CDBTTree *cdbttreeOut = new CDBTTree(outputfile);
52 
53  string m_fieldname = "Femc_datadriven_qm1_correction";
54 
55  for(int i = 0; i < 96 ; i++)
56  {
57  for(int j = 0; j < 256; j++)
58  {
59  unsigned int key = TowerInfoDefs::encode_emcal(i,j);
60  float val1 = cdbttree1->GetFloatValue(key, m_fieldname);
61  float val2 = cdbttree2->GetFloatValue(key, m_fieldname);
62  cdbttreeOut->SetFloatValue(key,m_fieldname,val1*val2);
63  }
64  }
65 
66  cdbttreeOut->Commit();
67  cdbttreeOut->WriteCDBTTree();
68  delete cdbttreeOut;
69  delete cdbttree1;
70  delete cdbttree2;
71 
72 }//end macro
73 
74 
75 void TSCtoCDBTTree(const char * infile, const char * outputfile)
76 {
77 
78  bool chk4file = gSystem->AccessPathName(infile);
79  TFile *f = nullptr;
80 
81  if(!chk4file)
82  {
83  f = new TFile(infile,"READ");
84  }
85  else
86  {
87  std::cout << "File " << infile << " cant be found in current directory." << std::endl;
88  exit(0);
89  }
90 
91  //write to cdb tree
92  CDBTTree *cdbttree = new CDBTTree(outputfile);
93 
94  //gain values lie in the 2d histogram called corrPat
95  TH2F *cp = (TH2F *)f->Get("corrPat");
96 
97  for(int i = 0; i < 96 ; i++)
98  {
99  for(int j = 0; j < 256; j++)
100  {
101  unsigned int key = TowerInfoDefs::encode_emcal(i,j);
102  float gain = (1.0 / cp->GetBinContent(i+1,j+1) );
103  if (cp->GetBinContent(i+1,j+1)==0) gain = 0;
104  if (isnan(cp->GetBinContent(i+1,j+1))) {gain = 0; cout << i << "," << j << endl;}
105  cdbttree->SetFloatValue(key,"Femc_datadriven_qm1_correction",gain);
106  }
107  }
108 
109  cdbttree->Commit();
110  cdbttree->WriteCDBTTree();
111  //cdbttree->Print();
112  f->Close();
113  delete f;
114  delete cdbttree;
115 
116 }