Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
generateTruthIbfGainMap.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file generateTruthIbfGainMap.C
1 void generateTruthIbfGainMap(const char* adcFile, const char *adcName, const char* ionFile, const char* ibfName, const char* primName, const char* outputFile){
2 
3  //load the adc-per-bin data from the specified file.
4  TFile* adcInputFile = TFile::Open(adcFile, "READ");
5  TH3* hAdc=nullptr;
6  adcInputFile->GetObject(adcName, hAdc);
7  if (hAdc == nullptr) {
8  printf("ADC hist %s or file %s not found!\n",adcName, adcFile);
9  return false;
10  }
11 
12  //load the ions-per-bin data from the specified file
13  TFile* ibfInputFile = TFile::Open(ionFile, "READ");
14  TH3* hIbf=nullptr;
15  TH3* hPrimaries=nullptr;
16  ibfInputFile->GetObject(ibfName,hIbf);
17  ibfInputFile->GetObject(primName,hPrimaries);
18  if (hIbf == nullptr) {
19  printf("IBF hist %s or file %s not found!\n",ibfName, ionFile);
20  return false;
21  }
22  if (hPrimaries == nullptr) {
23  printf("IBF hist %s IN file %s not found!\n",primName, ionFile);
24  return false;
25  }
26 
27  TFile *output=TFile::Open(outputFile,"RECREATE");
28  //generate 2D histograms with the IBF, and IBF + Primaries, per side:
29 
30  int nSections=3;
31  TH2 *hFlatTotal[nSections],*hFlatIbf[nSections]; //flat charge sums in north and south
32  int zbins,neg,cm,pos;
33  zbins=hAdc->GetZaxis()->GetNbins();
34  neg=1;
35  cm=zbins/2;
36  pos=zbins;
37 
38  TString suffix[]={"","_negz","_posz"};
39  int low[]={neg,neg,cm+1};
40  int high[]={pos,cm,pos};
41 
42  for (int i=0;i<nSections;i++){
43  hPrimaries->GetZaxis()->SetRange(low[i],high[i]);
44  hFlatTotal[i]=(TH2*)hPrimaries->Project3D(Form("xy%s",suffix[i].Data()));
45  hIbf->GetZaxis()->SetRange(low[i],high[i]);
46  hFlatIbf[i]=(TH2*)hIbf->Project3D(Form("xy%s",suffix[i].Data()));
47  hFlatTotal[i]->Add(hFlatIbf[i]);
48  }
49 
50 
51  //sanity check that the bounds are the same
52 
53  TAxis* ax[3] = {nullptr, nullptr, nullptr};
54  ax[0] = hPrimaries->GetXaxis();
55  ax[1] = hPrimaries->GetYaxis();
56  ax[2] = hPrimaries->GetZaxis();
57 
58  TAxis* ax2[3] = {nullptr, nullptr, nullptr};
59  ax2[0] = hAdc->GetXaxis();
60  ax2[1] = hAdc->GetYaxis();
61  ax2[2] = hAdc->GetYaxis();
62 
63 
64  int nbins[3];
65  for (int i = 0; i < 3; i++)//note these are dimensions, not sections.
66  {
67  nbins[i] = ax[i]->GetNbins(); //number of bins, not counting under and overflow.
68  if (nbins[i]!=ax2[i]->GetNbins()){
69  printf("Primaries and Adc bins are different in axis %d. (%d vs %d). Aborting unless in z.\n",i,nbins[i],ax2[i]->GetNbins());
70  if (i!=2) return;
71  printf("this is a z difference, which we can recover.\n");
72  }
73  }
74 
75 
76  //project into 2D per rphi, and divide Ions by Adc to get the Ion/Adc gain.
77  TH2* hIonGain[nSections], *hIbfGain[nSections],*hFlatAdc[nSections];
78 
79  for (int i=0;i<nSections;i++){
80  hIonGain[i]=static_cast<TH2*>(hFlatTotal[i]->Clone(Form("hIonGain%s",suffix[i].Data())));//with primaries
81  hIbfGain[i]=static_cast<TH2*>(hFlatIbf[i]->Clone(Form("hIbfGain%s",suffix[i].Data())));//with only ibf
82  hAdc->GetZaxis()->SetRange(low[i],high[i]);
83  hFlatAdc[i]=static_cast<TH2*>(hAdc->Project3D(Form("xy%s",suffix[i].Data())));
84 
85  hIonGain[i]->Divide(hFlatAdc[i]);
86  hIbfGain[i]->Divide(hFlatAdc[i]);
87 
88  hIonGain[i]->Write();
89  hIbfGain[i]->Write();
90  }
91 
92  //
93  return;
94 }