1 void generateTruthIbfGainMap(
const char* adcFile,
const char *adcName,
const char* ionFile,
const char* ibfName,
const char* primName,
const char* outputFile){
4 TFile* adcInputFile = TFile::Open(adcFile,
"READ");
6 adcInputFile->GetObject(adcName, hAdc);
8 printf(
"ADC hist %s or file %s not found!\n",adcName, adcFile);
13 TFile* ibfInputFile = TFile::Open(ionFile,
"READ");
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);
22 if (hPrimaries ==
nullptr) {
23 printf(
"IBF hist %s IN file %s not found!\n",primName, ionFile);
27 TFile *
output=TFile::Open(outputFile,
"RECREATE");
31 TH2 *hFlatTotal[nSections],*hFlatIbf[nSections];
33 zbins=hAdc->GetZaxis()->GetNbins();
38 TString suffix[]={
"",
"_negz",
"_posz"};
39 int low[]={neg,neg,cm+1};
40 int high[]={
pos,
cm,pos};
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]);
53 TAxis*
ax[3] = {
nullptr,
nullptr,
nullptr};
54 ax[0] = hPrimaries->GetXaxis();
55 ax[1] = hPrimaries->GetYaxis();
56 ax[2] = hPrimaries->GetZaxis();
58 TAxis* ax2[3] = {
nullptr,
nullptr,
nullptr};
59 ax2[0] = hAdc->GetXaxis();
60 ax2[1] = hAdc->GetYaxis();
61 ax2[2] = hAdc->GetYaxis();
65 for (
int i = 0;
i < 3;
i++)
67 nbins[
i] = ax[
i]->GetNbins();
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());
71 printf(
"this is a z difference, which we can recover.\n");
77 TH2* hIonGain[nSections], *hIbfGain[nSections],*hFlatAdc[nSections];
79 for (
int i=0;
i<nSections;
i++){
80 hIonGain[
i]=
static_cast<TH2*
>(hFlatTotal[
i]->Clone(Form(
"hIonGain%s",suffix[
i].
Data())));
81 hIbfGain[
i]=
static_cast<TH2*
>(hFlatIbf[
i]->Clone(Form(
"hIbfGain%s",suffix[
i].
Data())));
82 hAdc->GetZaxis()->SetRange(low[
i],high[i]);
83 hFlatAdc[
i]=
static_cast<TH2*
>(hAdc->Project3D(Form(
"xy%s",suffix[i].
Data())));
85 hIonGain[
i]->Divide(hFlatAdc[i]);
86 hIbfGain[
i]->Divide(hFlatAdc[i]);