Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CorrFitPairGenerator.cxx
1/*
2 * CorrFitPairGenerator.cxx
3 *
4 * Created on: 27 lut 2024
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "CorrFitPairGenerator.h"
11
12#include "Cout.h"
13#include "DividedHisto.h"
14#include "FemtoCorrFunc.h"
15#include "StdHist.h"
16
17#include <vector>
18
19#include <RtypesCore.h>
20#include <TClonesArray.h>
21#include <TDatabasePDG.h>
22#include <TFile.h>
23#include <TH1.h>
24#include <TList.h>
25#include <TParticlePDG.h>
26#include <TString.h>
27#include <TTree.h>
28
29namespace Hal {
30
31 CorrFitPairGenerator::CorrFitPairGenerator() {}
32
33 Bool_t CorrFitPairGenerator::Init() {
34 if (!fCF) return kFALSE;
35 DividedHisto1D* dummy = fCF->GetCF(0);
36 Int_t bins;
37 Double_t min, max;
38
39 if (dummy->GetNum()->InheritsFrom("TH3")) { // 3d histo group by q-long/ k-long
40 fGrouping.SetGroupByKLong();
41 Std::GetAxisPar(*dummy->GetNum(), bins, min, max, "z");
42 fXaxis.Recalc(*dummy->GetNum()->GetXaxis());
43 fYaxis.Recalc(*dummy->GetNum()->GetYaxis());
44 fZaxis.Recalc(*dummy->GetNum()->GetZaxis());
45 if (fDebug) fDebugHisto = new TH1D("debug", "debug", bins, min, max);
46 auto d3 = (TH3*) dummy->GetNum();
47 fOutCut[0] = d3->GetXaxis()->GetBinLowEdge(1);
48 fOutCut[1] = d3->GetXaxis()->GetBinUpEdge(d3->GetNbinsX());
49 fSideCut[0] = d3->GetYaxis()->GetBinLowEdge(1);
50 fSideCut[1] = d3->GetYaxis()->GetBinUpEdge(d3->GetNbinsY());
51 fGroupingFlag = EGrouping::kThreeDim;
52 Int_t bins1, bins2, bins3;
53 Std::GetAxisPar(*dummy->GetNum(), bins2, min, max, "y");
54 Std::GetAxisPar(*dummy->GetNum(), bins1, min, max, "x");
55 Std::GetAxisPar(*dummy->GetNum(), bins3, min, max, "z");
56 fLimits3D.MakeBigger(bins1 + 1, bins2 + 1, bins3 + 1);
57
58 } else { // 1d histo group by k* qinv
59 Std::GetAxisPar(*dummy->GetNum(), bins, min, max, "x");
60 fLimitsN.MakeBigger(bins + 1);
61 fXaxis.Recalc(*dummy->GetNum()->GetXaxis());
62 fGrouping.GroupByKStar();
63 fGroupingFlag = EGrouping::kOneDim;
64 if (fDebug) fDebugHisto = new TH1D("debug", "debug", bins, min, max);
65 }
66 fXaxis.RoundToMinusOne();
67 fYaxis.RoundToMinusOne();
68 fZaxis.RoundToMinusOne();
69 fHi = max;
70 fLow = min;
71 fOverStep = (max - min) / ((double) bins);
72 fOverStep = 1.0 / fOverStep;
73 if (fLow == 0) fAbs = kTRUE; // enable abs, because function starts with zero
74 if (dummy->GetLabelsNo() > 0) {
75 TString label = dummy->GetLabel(0);
76 fFrame = Femto::LabelToKinematics(label);
77 }
78 fHbtPair = Hal::Femto::MakePair(fFrame, true);
79
80 TDatabasePDG* pid = TDatabasePDG::Instance();
81 TParticlePDG* pid1 = pid->GetParticle(fPid1);
82 TParticlePDG* pid2 = pid->GetParticle(fPid2);
83 fHbtPair->SetPdg1(fPid1);
84 fHbtPair->SetPdg2(fPid2);
85 fHbtPair->Init(-1);
86 if (!pid1) return kFALSE;
87 if (!pid2) return kFALSE;
88 fM1 = pid1->Mass();
89 fM2 = pid2->Mass();
90 fGrouping.SetFrame(fFrame);
91 fGrouping.SetAxis(bins, min, max);
92 fNBins = bins;
93
94 fOutFile = new TFile(fFileName, "recreate");
95 fOutTree = new TTree("HalTree", "Tree");
96 fOutFile->mkdir("HalInfo");
97 fOutFile->cd("HalInfo");
98 fGrouping.Write();
99 fOutFile->cd();
100
101 auto FillCenters = [&](Array_1<Double_t>& array, Int_t binsx, Double_t minx, Double_t maxx) {
102 Double_t step = (maxx - minx) / double(binsx);
103 array.MakeBigger(binsx);
104 for (int i = 0; i < binsx; i++) {
105 Double_t val = step * i + step * 0.5;
106 array[i] = val;
107 }
108 };
109
110
111 if (dummy->GetNum()->InheritsFrom("TH3")) {
112 Std::GetAxisPar(*dummy->GetNum(), bins, min, max, "x");
113 FillCenters(fCentersX, bins, min, max);
114 Std::GetAxisPar(*dummy->GetNum(), bins, min, max, "y");
115 FillCenters(fCentersY, bins, min, max);
116 Std::GetAxisPar(*dummy->GetNum(), bins, min, max, "z");
117 FillCenters(fCentersZ, bins, min, max);
118 } else {
119 Std::GetAxisPar(*dummy->GetNum(), bins, min, max, "x");
120 FillCenters(fCentersX, bins, min, max);
121 }
122
123 auto vec = fGrouping.GetBranchesByValue(0, 0, kTRUE); // 0,0 -> get all branches
124 int idx = 0;
125 for (auto branchName : vec) {
126 fSignalPairs.push_back(new TClonesArray("Hal::FemtoMicroPair", 100));
127 fOutTree->Branch(branchName, &*fSignalPairs[idx]);
128 idx++;
129 }
130 fInited = kTRUE;
131 return kTRUE;
132 }
133
134 void CorrFitPairGenerator::SetCorrFctn(const FemtoCorrFunc& cf) { fCF = (FemtoCorrFunc*) cf.Clone(); }
135
136 void CorrFitPairGenerator::Run(Int_t entries) {
137 if (!fInited || !fOutFile) return;
138 int percent = entries / 100;
139 if (percent == 0) percent = 1;
140 for (int i = 0; i < entries; i++) {
141 if (i % percent == 0) { Cout::ProgressBar(i, entries); }
142 if (fDebug) {
143 unsigned int count = 1;
144 for (auto data : fSignalPairs) {
145 fDebugHisto->SetBinContent(count, fDebugHisto->GetBinContent(count) + data->GetEntriesFast());
146 ++count;
147 }
148 }
149 for (auto data : fSignalPairs)
150 data->Clear();
151 GenerateEvent();
152 fOutTree->Fill();
153 }
154 fOutTree->Write();
155 fOutFile->Close();
156
157 delete fOutFile;
158 fOutFile = nullptr;
159 if (fDebug) {
160 TFile* f = new TFile(Form("%s_debug.root", ClassName()), "recreate");
161 fDebugHisto->Write();
162 // delete fDebugHisto;
163 fDebugHisto = nullptr;
164 f->Close();
165 delete f;
166 }
167 }
168
169 Int_t CorrFitPairGenerator::GetBin(Double_t val) const {
170 Int_t bin = 0;
171 if (fLow == 0) { // ignore sign automatically?
172 bin = TMath::Abs(val) * fOverStep;
173 } else {
174 bin = (val - fLow) * fOverStep;
175 }
176
177 if (bin >= fNBins) return -1;
178 return bin;
179 }
180
181 CorrFitPairGenerator::~CorrFitPairGenerator() {
182 if (fOutFile) { fOutFile->Close(); }
183 if (fCF) delete fCF;
184 }
185
186} /* namespace Hal */
void MakeBigger(Int_t new_dim)
Definition Array.cxx:5
void MakeBigger(Int_t sizeA, Int_t sizeB, Int_t sizeC)
Definition Array.cxx:263
void SetCorrFctn(const FemtoCorrFunc &cf)
static void ProgressBar(Double_t acutal, Double_t total)
Definition Cout.cxx:229
DividedHisto1D * GetCF(Int_t i) const
void SetPdg1(Int_t val)
Definition FemtoPair.h:387
void SetPdg2(Int_t val)
Definition FemtoPair.h:392