Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
FemtoDoubleRatio1DCF.cxx
1/*
2 * FemtoDoubleRatio1DCF.cxx
3 *
4 * Created on: 21 mar 2018
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "FemtoDoubleRatio1DCF.h"
11
12#include "FemtoPair.h"
13#include "StdString.h"
14
15#include <TAttLine.h>
16#include <TAxis.h>
17#include <TBrowser.h>
18#include <TCanvas.h>
19#include <TCollection.h>
20#include <TH1.h>
21#include <TList.h>
22#include <TMathBase.h>
23#include <TNamed.h>
24#include <TROOT.h>
25#include <TString.h>
26#include <TSystem.h>
27#include <TVirtualPad.h>
28
29
30namespace Hal {
31 FemtoDoubleRatio1DCF::FemtoDoubleRatio1DCF(TString name, Femto::EKinematics kin) :
32 DividedHisto1D(name, 3), fFrame(kin), fNumSide(NULL), fDenSide(NULL), fNumLong(NULL), fDenLong(NULL) {}
33
34 FemtoDoubleRatio1DCF::FemtoDoubleRatio1DCF(TString name, Int_t bins, Double_t min, Double_t max, Femto::EKinematics kin) :
35 FemtoDoubleRatio1DCF(name, kin) {
36 SetName(name);
37
38 fNum = new TH1D(Form("%s_NumOut", name.Data()), Form("%s_NumOut", name.Data()), min, max);
39 fDen = new TH1D(Form("%s_DenOut", name.Data()), Form("%s_DenOut", name.Data()), min, max);
40 fNumSide = new TH1D(Form("%s_NumSide", name.Data()), Form("%s_NumSide", name.Data()), min, max);
41 fDenSide = new TH1D(Form("%s_DenSide", name.Data()), Form("%s_DenSide", name.Data()), min, max);
42 fNumLong = new TH1D(Form("%s_NumLong", name.Data()), Form("%s_NumLong", name.Data()), min, max);
43 fDenLong = new TH1D(Form("%s_DenLong", name.Data()), Form("%s_DenLong", name.Data()), min, max);
44 SetAxisNames(fNum, fDen, "out");
45 SetAxisNames(fNumSide, fDenSide, "out");
46 SetAxisNames(fNumLong, fDenLong, "long");
47 }
48
49 void FemtoDoubleRatio1DCF::Browse(TBrowser* b) {
50 gPad->Clear();
51 TVirtualPad* c1 = gPad;
52 Draw();
53 b->Add(fNum);
54 b->Add(fNumSide);
55 b->Add(fNumLong);
56 b->Add(fDen);
57 b->Add(fDenSide);
58 b->Add(fDenLong);
59 gPad = c1;
60 }
61
62 void FemtoDoubleRatio1DCF::Draw(Option_t* opt) {
63 if (gPad == NULL) new TCanvas();
64 TVirtualPad* c1 = gPad;
65 TVirtualPad* c2 = gPad;
66 TString option = opt;
67 TString same = "";
68 if (Hal::Std::FindParam(option, "same")) { same = "SAME"; }
69 if (option == "num") {
70 if (c1->GetListOfPrimitives()->GetEntries() < 3) c2->Divide(3, 1);
71 c2->cd(1);
72 GetOutNum()->Draw(same);
73 c2->cd(2);
74 GetSideNum()->Draw(same);
75 c2->cd(3);
76 GetLongNum()->Draw(same);
77
78 } else if (option == "den") {
79 if (c1->GetListOfPrimitives()->GetEntries() < 3) c2->Divide(3, 1);
80 c2->cd(1);
81 GetOutDen()->Draw(same);
82 c2->cd(2);
83 GetSideDen()->Draw(same);
84 c2->cd(3);
85 GetLongDen()->Draw(same);
86 } else {
87 if (c1->GetListOfPrimitives()->GetEntries() < 3) c2->Divide(3, 1);
88 TH1D* cfx = GetCFOut(kTRUE);
89 TH1D* cfy = GetCFOut(kTRUE);
90 TH1D* cfz = GetCFOut(kTRUE);
91 c2->cd(1);
92 cfx->Draw(same);
93 c2->cd(2);
94 cfy->Draw(same);
95 c2->cd(3);
96 cfz->Draw(same);
97 }
98 gPad = c1;
99 }
100
101 TString FemtoDoubleRatio1DCF::HTMLExtract(Int_t counter, TString dir) const {
102 Bool_t batch = gROOT->IsBatch();
103 TString path = Form("%s/divided_%i", dir.Data(), counter);
104 gSystem->MakeDirectory(path);
105 gROOT->SetBatch(kTRUE);
106 TCanvas* c1 = new TCanvas("canvas", "canvas", 0, 0, 1000, 1500);
107 c1->Divide(3, 3);
108 c1->cd(1);
109 TH1D* cf1 = GetCFOut(kTRUE);
110 cf1->SetObjectStat(kFALSE);
111 cf1->Draw();
112 c1->cd(2);
113 TH1D* cf2 = GetCFSide(kTRUE);
114 cf2->SetObjectStat(kFALSE);
115 cf2->Draw();
116 c1->cd(3);
117 TH1D* cf3 = GetCFLong(kTRUE);
118 cf3->SetObjectStat(kFALSE);
119 cf3->Draw();
120 TH1D** nums = new TH1D*[3];
121 TH1D** dens = new TH1D*[3];
122 nums[0] = (TH1D*) GetOutNum()->Clone();
123 nums[1] = (TH1D*) GetSideNum()->Clone();
124 nums[2] = (TH1D*) GetLongNum()->Clone();
125 dens[0] = (TH1D*) GetOutDen()->Clone();
126 dens[1] = (TH1D*) GetSideDen()->Clone();
127 dens[2] = (TH1D*) GetLongDen()->Clone();
128
129 for (int i = 0; i < 3; i++) {
130 c1->cd(3 + i);
131 nums[i]->SetLineColor(kGreen);
132 nums[i]->SetObjectStat(kFALSE);
133 nums[i]->Draw();
134 }
135 for (int i = 0; i < 3; i++) {
136 c1->cd(6 + i);
137 dens[i]->SetLineColor(kRed);
138 dens[i]->SetObjectStat(kFALSE);
139 dens[i]->Draw();
140 }
141 gSystem->mkdir(path);
142 c1->SaveAs(Form("%s/divided.root", path.Data()));
143 delete c1;
144 delete cf1;
145 delete cf2;
146 delete cf3;
147 for (int i = 0; i < 3; i++) {
148 delete nums[i];
149 delete dens[i];
150 }
151 delete[] nums;
152 delete[] dens;
153 gROOT->SetBatch(batch);
154 TString page = CommonExtract(counter, dir);
155 return page;
156 }
157
158 void FemtoDoubleRatio1DCF::Rebin(Int_t ngroup, Option_t* opt) {
159 TString option = opt;
160 if (option == "out") {
161 fNum->Rebin(ngroup);
162 fDen->Rebin(ngroup);
163 } else if (option == "side") {
164 fNumSide->Rebin(ngroup);
165 fDenSide->Rebin(ngroup);
166 } else if (option == "long") {
167 fNumLong->Rebin(ngroup);
168 fDenLong->Rebin(ngroup);
169 } else {
170 Rebin(ngroup, "out");
171 Rebin(ngroup, "side");
172 Rebin(ngroup, "long");
173 }
174 }
175
176 void FemtoDoubleRatio1DCF::SetAxisNames(TH1* h1, TH1* h2, TString label) {
177 if (h1 == NULL || h2 == NULL) return;
178 switch (fFrame) {
179 case Femto::EKinematics::kPRF:
180 h1->GetXaxis()->SetTitle(Form("k*^{%s} [GeV/c]", label.Data()));
181 h2->GetXaxis()->SetTitle(Form("k*^{%s} [GeV/c]", label.Data()));
182 SetAxisName("CF(k*)");
183 break;
184 case Femto::EKinematics::kLCMS:
185 h1->GetXaxis()->SetTitle(Form("q_{inv}^{%s} [GeV/c]", label.Data()));
186 h2->GetXaxis()->SetTitle(Form("q_{inv}^{%s} [GeV/c]", label.Data()));
187 SetAxisName("CF(q)");
188 break;
189 default: break;
190 }
191 }
192
193 void FemtoDoubleRatio1DCF::SetNum(TH1D* outnum, TH1D* sidenum, TH1D* longnum, Bool_t clone) {
194 fNum = outnum;
195 fNumSide = outnum;
196 fNumLong = longnum;
197 if (clone) {
198 fNumIsCloned = kTRUE;
199 fDenIsCloned = kTRUE;
200 fNum = (TH1D*) outnum->Clone();
201 fNumSide = (TH1D*) outnum->Clone();
202 fNumLong = (TH1D*) longnum->Clone();
203 } else {
204 fNumIsCloned = kFALSE;
205 fNum = outnum;
206 fNumSide = outnum;
207 fNumLong = longnum;
208 }
209 }
210
211 void FemtoDoubleRatio1DCF::SetDen(TH1D* outden, TH1D* sideden, TH1D* longden, Bool_t clone) {
212 if (clone) {
213 fDenIsCloned = kTRUE;
214 fDen = (TH1D*) outden->Clone();
215 fDenSide = (TH1D*) outden->Clone();
216 fDenLong = (TH1D*) longden->Clone();
217 } else {
218 fDenIsCloned = kFALSE;
219 fDen = outden;
220 fDenSide = outden;
221 fDenLong = longden;
222 }
223 }
224
225 TH1D* FemtoDoubleRatio1DCF::GetCFOut(Bool_t normalized) const { return GetCF(normalized, 0); }
226
227 TH1D* FemtoDoubleRatio1DCF::GetCFSide(Bool_t normalized) const { return GetCF(normalized, 1); }
228
229 TH1D* FemtoDoubleRatio1DCF::GetCFLong(Bool_t normalized) const { return GetCF(normalized, 2); }
230
231 void FemtoDoubleRatio1DCF::Normalize(TH1D* h, TH1D* num, TH1D* den, Int_t dir) const {
232 if (fScale != 0) h->Scale(fScale);
233 Int_t bin_min = h->GetXaxis()->FindBin(fNormMin[dir]);
234 Int_t bin_max = h->GetXaxis()->FindBin(fNormMax[dir]);
235 Double_t int_a = num->Integral(bin_min, bin_max);
236 Double_t int_b = den->Integral(bin_min, bin_max);
237 if (int_a != 0 && int_b != 0) { h->Scale(int_b / int_a); }
238 }
239
240 TH1D* FemtoDoubleRatio1DCF::GetCF(Bool_t normalized, Int_t dir) const {
241 TH1 *num, *den;
242 switch (dir) {
243 case 0:
244 num = fNum;
245 den = fDen;
246 break;
247 case 1:
248 num = fNumSide;
249 den = fDenSide;
250 break;
251 case 2:
252 num = fNumLong;
253 den = fDenLong;
254 break;
255 }
256 TString numname = num->GetName();
257 TString newname = numname.ReplaceAll("Num", "CF");
258 TString numtitle = num->GetTitle();
259 TString newtitle = numtitle.ReplaceAll("Num", "CF");
260 TH1D* cf = (TH1D) num->Clone(newname);
261 cf->SetTitle(newtitle);
262 cf->SetYTitle(GetAxisName());
263 if (normalized) Normalize(cf, (TH1D*) num, (TH1D*) den, dir);
264 return cf;
265 }
266
270 fNumLong->Add(other->fNumLong);
271 fDenLong->Add(other->fDenLong);
272 fNumSide->Add(other->fNumSide);
273 fDenSide->Add(other->fDenSide);
274 }
275
277 fNumSide = (TH1D*) other.fNumSide->Clone();
278 fDenSide = (TH1D*) other.fDenSide->Clone();
279 fNumLong = (TH1D*) other.fNumLong->Clone();
280 fDenLong = (TH1D*) other.fDenLong->Clone();
281 fFrame = other.fFrame;
282 }
283
285 FemtoPair* pair = (FemtoPair*) ob;
286 Double_t total = TMath::Abs(pair->GetT());
287 Double_t weight = pair->GetWeight();
288 if (pair->GetX() >= 0) {
289 fNum->Fill(total, weight);
290 } else {
291 fNum->Fill(-total, weight);
292 }
293 if (pair->GetY() >= 0) {
294 fNumSide->Fill(total, weight);
295 } else {
296 fNumSide->Fill(-total, weight);
297 }
298 if (pair->GetZ() >= 0) {
299 fNumLong->Fill(total, weight);
300 } else {
301 fNumLong->Fill(-total, weight);
302 }
303 }
304
306 FemtoPair* pair = (FemtoPair*) obj;
307 Double_t total = TMath::Abs(pair->GetT());
308 Double_t weight = pair->GetWeight();
309 if (pair->GetX() >= 0) {
310 fDen->Fill(total, weight);
311 } else {
312 fDen->Fill(-total, weight);
313 }
314 if (pair->GetY() >= 0) {
315 fDenSide->Fill(total, weight);
316 } else {
317 fDenSide->Fill(-total, weight);
318 }
319 if (pair->GetZ() >= 0) {
320 fDenLong->Fill(total, weight);
321 } else {
322 fDenLong->Fill(-total, weight);
323 }
324 }
325
328 fNumSide(nullptr),
329 fDenSide(nullptr),
330 fNumLong(nullptr),
331 fDenLong(nullptr),
332 fFrame(Femto::EKinematics::kLCMS) {}
333
334 FemtoDoubleRatio1DCF::~FemtoDoubleRatio1DCF() {
335 if (fNumIsCloned) {
336 delete fNumSide;
337 delete fNumLong;
338 }
339 if (fDenIsCloned) {
340 delete fDenSide;
341 delete fDenLong;
342 }
343 }
344} // namespace Hal
void SetAxisName(TString name)
virtual TString CommonExtract(Int_t counter, TString dir) const
virtual void Add(const Object *h)
TString GetAxisName() const
TH1D * GetCFSide(Bool_t normalized=kTRUE) const
virtual TString HTMLExtract(Int_t counter=0, TString dir=" ") const
virtual void Draw(Option_t *opt="all")
void SetDen(TH1D *outden, TH1D *sideden, TH1D *longden, Bool_t clone=kFALSE)
virtual void Add(const Object *h)
TH1D * GetCFOut(Bool_t normalized=kTRUE) const
TH1D * GetCFLong(Bool_t normalized=kTRUE) const
virtual void Browse(TBrowser *b)
void SetNum(TH1D *outnum, TH1D *sidenum, TH1D *longnum, Bool_t clone=kFALSE)
virtual void Rebin(Int_t ngroup, Option_t *opt)
Double_t GetT() const
Definition FemtoPair.h:322
Double_t GetY() const
Definition FemtoPair.h:312
Double_t GetWeight() const
Definition FemtoPair.h:282
Double_t GetZ() const
Definition FemtoPair.h:317
Double_t GetX() const
Definition FemtoPair.h:307