Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
Femto3DCF.cxx
1/*
2 * Femto3DCF.cpp
3 *
4 * Created on: 12-03-2015
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "Femto3DCF.h"
11
12#include "Cout.h"
13#include "FemtoPair.h"
14#include "FemtoSerializationInterface3D.h"
15#include "StdString.h"
16
17#include <TAttLine.h>
18#include <TAxis.h>
19#include <TBrowser.h>
20#include <TCanvas.h>
21#include <TCollection.h>
22#include <TH1.h>
23#include <TH3.h>
24#include <TList.h>
25#include <TMath.h>
26#include <TMathBase.h>
27#include <TNamed.h>
28#include <TROOT.h>
29#include <TRegexp.h>
30#include <TSystem.h>
31#include <iostream>
32
33#include "CorrFit3DCF.h"
34#include "Femto3DCFPainter.h"
35#include "StdString.h"
36
37namespace Hal {
38 Femto3DCF::Femto3DCF(TString name, Femto::EKinematics frame) : DividedHisto3D(name), fFrame(frame) {
39 SetName(name);
40 AddLabel(Femto::KinematicsToLabel(fFrame));
41 }
42
43 void Femto3DCF::FillNumObj(TObject* obj) {
44 FemtoPair* pair = (FemtoPair*) obj;
45 if (pair->IsAbs()) {
46 ((TH3*) fNum)->Fill(TMath::Abs(pair->GetX()), TMath::Abs(pair->GetY()), TMath::Abs(pair->GetZ()), pair->GetWeight());
47 } else {
48 ((TH3*) fNum)->Fill(pair->GetX(), pair->GetY(), pair->GetZ(), pair->GetWeight());
49 }
50 }
51
52 void Femto3DCF::FillDenObj(TObject* obj) {
53 FemtoPair* pair = (FemtoPair*) obj;
54 if (pair->IsAbs()) {
55 ((TH3*) fDen)->Fill(TMath::Abs(pair->GetX()), TMath::Abs(pair->GetY()), TMath::Abs(pair->GetZ()), pair->GetWeight());
56 } else {
57 ((TH3*) fDen)->Fill(pair->GetX(), pair->GetY(), pair->GetZ(), pair->GetWeight());
58 }
59 }
60
61 Femto3DCF::Femto3DCF(const Femto3DCF& other) : DividedHisto3D(other), fFrame(other.fFrame) {}
62
63 Femto3DCF::~Femto3DCF() {}
64
65 TString Femto3DCF::HTMLExtract(Int_t counter, TString dir) const {
66 TString path = Form("%s/divided_%i", dir.Data(), counter);
67 gSystem->MakeDirectory(path);
68 Bool_t batch = gROOT->IsBatch();
69 gROOT->SetBatch(kTRUE);
70
71 Int_t middle_x = fNum->GetXaxis()->FindBin(0.0);
72 Int_t middle_y = fNum->GetYaxis()->FindBin(0.0);
73 Int_t middle_z = fNum->GetZaxis()->FindBin(0.0);
74 TString names[] = {"out", "side", "long"};
75 TString dirs[] = {"x", "y", "z"};
76 TString titles[] = {"cf", "num", "den"};
77 Color_t colz[] = {kRed, kGreen, kBlue};
78 Int_t mxx[] = {middle_y, middle_x, middle_x};
79 Int_t myy[] = {middle_z, middle_z, middle_y};
80 TCanvas* c1 = new TCanvas("canvas", "canvas", 0, 0, 1000, 1500);
81 c1->Divide(3, 3);
82 TH1D** histos = new TH1D*[9];
83 for (int padId = 0; padId < 9; padId++) {
84 c1->cd(padId + 1);
85 int optId = padId % 3;
86 int flagDir = (padId - optId) / 3;
87 TString opt = titles[optId] + "+" + dirs[flagDir] + "+scale+bins";
88 histos[padId] = GetProjection1D(mxx[flagDir], mxx[flagDir], myy[flagDir], myy[flagDir], opt);
89 histos[padId]->SetLineColor(colz[flagDir]);
90 histos[padId]->SetTitle(Form("%s %s", names[flagDir].Data(), titles[optId].Data()));
91 histos[padId]->SetMinimum(0);
92 histos[padId]->Draw();
93 }
94 c1->Update();
95 c1->SaveAs(Form("%s/divided.root", path.Data()));
96 gROOT->SetBatch(batch);
97
98 delete c1;
99 for (int i = 0; i < 9; i++) {
100 delete histos[i];
101 }
102 delete[] histos;
103 TString page = CommonExtract(counter, dir);
104 return page;
105 }
106
107 void Femto3DCF::AddNum(TH1* h, Option_t* opt) {
108 h->GetXaxis()->SetTitle(Femto::KinematicsToAxisLabel(fFrame, 0, 3));
109 h->GetYaxis()->SetTitle(Femto::KinematicsToAxisLabel(fFrame, 1, 3));
110 h->GetZaxis()->SetTitle(Femto::KinematicsToAxisLabel(fFrame, 2, 3));
111 SetAxisName(Femto::KinematicsToAxisLabel(fFrame, 3, 3));
113 }
114
115 void Femto3DCF::AddDen(TH1* h, Option_t* opt) {
116 h->GetXaxis()->SetTitle(Femto::KinematicsToAxisLabel(fFrame, 0, 3));
117 h->GetYaxis()->SetTitle(Femto::KinematicsToAxisLabel(fFrame, 1, 3));
118 h->GetZaxis()->SetTitle(Femto::KinematicsToAxisLabel(fFrame, 2, 3));
119 SetAxisName(Femto::KinematicsToAxisLabel(fFrame, 3, 3));
121 }
122
123 void Femto3DCF::Fit(CorrFit3DCF* fit) { fit->Fit(this); }
124
125 void Femto3DCF::FitDummy(CorrFit3DCF* fit) { fit->FitDummy(this); }
126
127 void Femto3DCF::Browse(TBrowser* b) {
128 TVirtualPad* c1 = gPad;
129 if (gPad == nullptr) { new TCanvas(); }
130 gPad->Clear();
131 Draw("all");
132 gPad = c1;
133 b->Add(fNum);
134 b->Add(fDen);
135 }
136
137 void Femto3DCF::Draw(Option_t* opt) {
138 TString options = opt;
139 if (fPainter) {
140 fPainter->SetOption(options);
141 fPainter->Paint();
142 } else {
143 fPainter = new Hal::Femto3DCFPainter(this);
144 fPainter->SetOption(options);
145 fPainter->Paint();
146 }
147 }
148
149 void Femto3DCF::DrawScaled(Double_t /*scale*/, Option_t* opt) {
150 TString option = opt;
151 TString name = "Divided 1D";
152 Int_t middle_x[2];
153 Int_t middle_y[2];
154 Int_t middle_z[2];
155 middle_x[0] = middle_x[1] = fNum->GetXaxis()->FindBin(0.0);
156 middle_y[0] = middle_y[1] = fNum->GetYaxis()->FindBin(0.0);
157 middle_z[0] = middle_z[1] = fNum->GetZaxis()->FindBin(0.0);
158 if (fFrame == Femto::EKinematics::kSH_LCMS || fFrame == Femto::EKinematics::kSH_PRF) {
159 middle_x[0] = middle_y[0] = middle_z[0] = 1;
160 middle_x[1] = fNum->GetXaxis()->GetNbins();
161 middle_y[1] = fNum->GetYaxis()->GetNbins();
162 middle_z[1] = fNum->GetZaxis()->GetNbins();
163 }
164 if (fNum->GetXaxis()->GetBinLowEdge(middle_x[0]) == 0.0 && middle_x[0] > 1) --middle_x[0];
165 if (fNum->GetYaxis()->GetBinLowEdge(middle_y[0]) == 0.0 && middle_y[0] > 1) --middle_y[0];
166 if (fNum->GetZaxis()->GetBinLowEdge(middle_z[0]) == 0.0 && middle_z[0] > 1) --middle_z[0];
167 TVirtualPad* c1 = gPad;
168 if (c1->GetListOfPrimitives()->GetEntries() < 4) c1->Divide(2, 2);
169 c1->cd(1);
170 TH1D* out_func = GetProjection1D(middle_y[0], middle_y[1], middle_z[0], middle_z[1], "x+scale+bins+autoname");
171 out_func->SetLineColor(kRed);
172 out_func->SetTitle("out function");
173 out_func->SetMinimum(0);
174 out_func->Draw(option);
175 c1->cd(2);
176 TH1D* side_func = GetProjection1D(middle_x[0], middle_x[1], middle_z[0], middle_z[1], "y+scale+bins+autoname");
177 side_func->SetLineColor(kBlue);
178 side_func->SetTitle("side function");
179 side_func->SetMinimum(0);
180 side_func->Draw(option);
181 c1->cd(3);
182 TH1D* long_func = GetProjection1D(middle_x[0], middle_x[1], middle_y[0], middle_y[1], "z+scale+bins+autoname");
183 long_func->SetMinimum(0);
184 long_func->SetLineColor(kGreen);
185 long_func->SetTitle("long function");
186 long_func->Draw(option);
187 c1->cd(4);
188 gPad = c1;
189 }
190
191 Femto3DCF::Femto3DCF(TString name,
192 Int_t binsX,
193 Double_t minX,
194 Double_t maxX,
195 Int_t binsY,
196 Double_t minY,
197 Double_t maxY,
198 Int_t binsZ,
199 Double_t minZ,
200 Double_t maxZ,
201 Femto::EKinematics frame) :
202 DividedHisto3D(name, binsX, minX, maxX, binsY, minY, maxY, binsZ, minZ, maxZ, 'D'), fFrame(frame) {
203 fNum->Sumw2();
204 fDen->Sumw2();
205 if (fFrame == Femto::EKinematics::kSH_PRF || fFrame == Femto::EKinematics::kSH_LCMS) {
206 TH3* old_num = (TH3*) fNum;
207 TH3* old_den = (TH3*) fDen;
208 TString old_name = old_num->GetName();
209 name = old_name(0, old_name.Length() - 4);
210 fNum = new TH3D(name + "_Num",
211 name + "_Num",
212 binsX,
213 0,
214 maxX,
215 binsY,
216 -TMath::Pi(),
217 TMath::Pi(),
218 binsZ,
219 -TMath::Pi() * 0.5,
220 TMath::Pi() * 0.5);
221 fDen = new TH3D(name + "_Den",
222 name + "_Den",
223 binsX,
224 0,
225 maxX,
226 binsY,
227 -TMath::Pi(),
228 TMath::Pi(),
229 binsZ,
230 -TMath::Pi() * 0.5,
231 TMath::Pi() * 0.5);
232 delete old_num;
233 delete old_den;
234 }
235 SetAxisNames(fNum);
236 SetAxisNames(fDen);
237 AddLabel(Femto::KinematicsToLabel(fFrame));
238 }
239
240 Femto3DCF::Femto3DCF(TString name, Int_t binsX, Double_t minX, Double_t maxX, Femto::EKinematics frame) :
241 Femto3DCF(name, binsX, minX, maxX, binsX, minX, maxX, binsX, minX, maxX, frame) {}
242
243 void Femto3DCF::SetAxisNames(TH1* h) {
244 if (h == NULL) return;
245 h->GetXaxis()->SetTitle(Femto::KinematicsToAxisLabel(fFrame, 0, 3));
246 h->GetYaxis()->SetTitle(Femto::KinematicsToAxisLabel(fFrame, 1, 3));
247 h->GetZaxis()->SetTitle(Femto::KinematicsToAxisLabel(fFrame, 2, 3));
248 SetAxisName(Femto::KinematicsToAxisLabel(fFrame, 3, 3));
249 }
250
251 void Femto3DCF::Print(Option_t* opt) const {
252 DividedHisto1D::Print(opt);
253 TString text = Form("Frame : %s", Femto::KinematicsToLabel(fFrame).Data());
254 Cout::Text(text, "L", kWhite);
255 }
256
257 TH1D** Femto3DCF::GetDiagProj(Option_t* opt, Bool_t normalized) const {
258 TString option = opt;
259 if (Hal::Std::FindParam(option, "cf", kTRUE)) {
260 TH3D* h = (TH3D*) GetHist(normalized);
261 TString options[3] = {"x", "y", "z"};
262 TString titles[3] = {"out", "side", "long"};
263 TH1D** array = new TH1D*[3];
264 Bool_t rgb = kFALSE;
265 Color_t colors[3] = {kRed, kBlue, kGreen};
266 if (Hal::Std::FindParam(option, "rgb", kTRUE)) rgb = kTRUE;
267 for (int i = 0; i < 3; i++) {
268 array[i] = Hal::Std::GetDiagonalProjection1D(h, options[i], 0, 0);
269 array[i]->SetTitle(titles[i]);
270 array[i]->SetStats(0);
271 TString xTitle = array[i]->GetXaxis()->GetTitle();
272 xTitle = xTitle.ReplaceAll("[GeV/c]", "");
273 array[i]->SetYTitle(Form("C(%s)", xTitle.Data()));
274 array[i]->SetXTitle(Form("%s [GeV/c]", xTitle.Data()));
275 if (rgb) {
276 array[i]->SetMarkerColor(colors[i]);
277 array[i]->SetLineColor(colors[i]);
278 }
279 }
280 delete h;
281 return array;
282 } else if (option.EqualTo("diag1")) {
283 TH3D* h = (TH3D*) GetHist(normalized);
284 TString options[7] = {"x", "y", "z", "xy++", "yz++", "xz++", "xyz+++"};
285 TString titles[7] = {
286 "out",
287 "side",
288 "long",
289 "out+side+",
290 "side+long+",
291 "out+long+",
292 "out+side+long+",
293 };
294 TH1D** array = new TH1D*[7];
295 for (int i = 0; i < 7; i++) {
296 array[i] = Hal::Std::GetDiagonalProjection1D(h, options[i], 0, 0);
297 array[i]->SetTitle(titles[i]);
298 array[i]->SetStats(0);
299 TString xTitle = array[i]->GetXaxis()->GetTitle();
300 xTitle = xTitle.ReplaceAll("[GeV/c]", "");
301 array[i]->SetYTitle(Form("C(%s)", xTitle.Data()));
302 array[i]->SetXTitle(Form("%s [GeV/c]", xTitle.Data()));
303 }
304 delete h;
305 return array;
306
307 } else if (option.EqualTo("diag2")) {
308 TString drawOpt = option;
309 TH3D* h = (TH3D*) GetHist(normalized);
310 TString options[13] = {
311 "x", "y", "z", "xy++", "xy+-", "yz++", "yz+-", "xz++", "xz+-", "xyz+++", "xyz+-+", "xyz+--", "xyz++-"};
312 TString titles[13] = {"out",
313 "side",
314 "long",
315 "out+side+",
316 "out+side-",
317 "side+long+",
318 "side+long-",
319 "out+long+",
320 "out+long-",
321 "out+side+long+",
322 "out+side-long+",
323 "out+side-long-",
324 "out+side+long-"};
325 TH1D** array = new TH1D*[13];
326 for (int i = 0; i < 13; i++) {
327 array[i] = Hal::Std::GetDiagonalProjection1D(h, options[i], 0, 0);
328 array[i]->SetTitle(titles[i]);
329 array[i]->SetStats(0);
330 TString xTitle = array[i]->GetXaxis()->GetTitle();
331 xTitle = xTitle.ReplaceAll("[GeV/c]", "");
332 array[i]->SetYTitle(Form("C(%s)", xTitle.Data()));
333 array[i]->SetXTitle(Form("%s [GeV/c]", xTitle.Data()));
334 }
335 delete h;
336 return array;
337 }
338 return nullptr;
339 }
340
341 TObject* Femto3DCF::GetSpecial(TString opt) const {
342 if (opt == "serialization") return new FemtoSerializationInterface3D();
343 if (opt == "painter") return fPainter;
344 return nullptr;
345 }
346
347} // namespace Hal
virtual void FitDummy(TObject *histo)
virtual void Fit(TObject *histo)
static void Text(TString text, TString option="L", Color_t color=-1)
Definition Cout.cxx:92
void SetAxisName(TString name)
virtual TString CommonExtract(Int_t counter, TString dir) const
virtual void AddNum(TH1 *num, Option_t *opt="")
void AddLabel(TString label)
TH1 * GetHist(Bool_t normalized=kTRUE) const
virtual void AddDen(TH1 *den, Option_t *opt="")
TH1D * GetProjection1D(Double_t min1, Double_t max1, Double_t min2, Double_t max2, Option_t *opt) const
virtual void FillNumObj(TObject *ob)
Definition Femto3DCF.cxx:43
virtual void FillDenObj(TObject *obj)
Definition Femto3DCF.cxx:52
virtual TString HTMLExtract(Int_t counter=0, TString dir=" ") const
Definition Femto3DCF.cxx:65
virtual void Browse(TBrowser *b)
virtual void AddDen(TH1 *h, Option_t *opt="")
virtual void AddNum(TH1 *h, Option_t *opt="")
virtual void DrawScaled(Double_t scale, Option_t *opt)
virtual void Draw(Option_t *opt="cf+rgb+norm")
void Fit(CorrFit3DCF *fit)
virtual TObject * GetSpecial(TString opt) const
void FitDummy(CorrFit3DCF *fit)
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
void Paint()
Definition Painter.cxx:42
virtual void SetOption(TString option)
Definition Painter.cxx:124