Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
Femto3DCFPainter.cxx
1/*
2 * Femto3DCFPainter.cxx
3 *
4 * Created on: 22 lip 2024
5 * Author: daniel
6 */
7
8#include "Femto3DCFPainter.h"
9
10#include "Cout.h"
11#include "Femto3DCF.h"
12#include "Std.h"
13#include "StdHist.h"
14#include "StdString.h"
15
16#include <TH3D.h>
17#include <TVirtualPad.h>
18
19namespace Hal {
20 const int Femto3DCFPainter::kRgbBit = 16;
21 const int Femto3DCFPainter::kRawBit = 17;
22 const int Femto3DCFPainter::kDiag1Bit = 18;
23 const int Femto3DCFPainter::kDiag2Bit = 19;
24 const int Femto3DCFPainter::kTwoDimBit = 20;
25 const int Femto3DCFPainter::kTwoDimPlusBit = 21;
26 const int Femto3DCFPainter::kAngles = 22;
27 ULong64_t Femto3DCFPainter::SetOptionInternal(TString opt, ULong64_t newFlags) {
28 newFlags = FemtoCFPainter::SetOptionInternal(opt, newFlags);
29 auto cleanFlags = [&](int setbit) { ResetFewBits(newFlags, {kDiag1Bit, kDiag2Bit, kTwoDimBit, kTwoDimPlusBit}, setbit); };
30 if (Hal::Std::FindParam(opt, "diag1")) {
31 cleanFlags(kDiag1Bit);
32 fDefDrawFlag = "SAME+P";
33 };
34 if (Hal::Std::FindParam(opt, "diag2")) {
35 cleanFlags(kDiag2Bit);
36 fDefDrawFlag = "SAME+P";
37 };
38 if (Hal::Std::FindParam(opt, "2d")) {
39 cleanFlags(kTwoDimBit);
40 fDefDrawFlag = "SAME+colz";
41 };
42 if (Hal::Std::FindParam(opt, "3d")) {
43 cleanFlags(kTwoDimPlusBit);
44 fDefDrawFlag = "SAME+surf1";
45 auto bra = Hal::Std::FindBrackets(opt, kTRUE, kTRUE);
46 for (auto pat : bra) {
47 std::vector<Double_t> vals;
48 if (GetPatterns(pat, "ang", vals)) {
49 SETBIT(newFlags, kAngles);
50 if (vals.size() == 2) {
51 fThetaPad = vals[0];
52 fPhiPad = vals[0];
53 }
54 }
55 }
56 };
57
58 ContitionalPattern(opt, "hidetitles", newFlags, kHideTitles);
59 return newFlags;
60 }
61
62 void Femto3DCFPainter::MakeHistograms() {
63 TH3* h = nullptr;
64 bool clean = false;
65 if (CheckOpt(kNumBit)) {
66 h = (TH3*) fCF->GetNum()->Clone();
67 } else if (CheckOpt(kDenBit)) {
68 h = (TH3*) fCF->GetDen()->Clone();
69 } else { // cf
70 h = (TH3*) fCF->GetHist(kFALSE);
71 clean = true;
72 }
73 if (CheckOpt(kDiag1Bit)) {
74 PrepareDiagonal1(h);
75 } else if (CheckOpt(kDiag2Bit)) {
76 PrepareDiagonal2(h);
77 } else if (CheckOpt(kHtmlBit)) {
78 PrepareHtml(h);
79 } else if (CheckOpt(kTwoDimBit) || CheckOpt(kTwoDimPlusBit)) {
80 PrepareTwoDim(h);
81 } else { // standard
82 if (AreSimiliar(GetDrawFlags(), PrepBitTemplate({kNumBit, kDenBit, kCFBit}))) {
83 Prepare3DFull(h);
84 } else {
85 Prepare3D(h);
86 }
87 }
88 if (clean) delete h;
89 }
90
92 Int_t req = GetPadsRequired();
93 Int_t padsNo = GetPadsNo();
94 if (padsNo < req) return kFALSE;
95 return kTRUE;
96 };
97
98 Femto3DCFPainter::Femto3DCFPainter(Femto3DCF* cf) : fCF(cf) {}
99
100 void Femto3DCFPainter::Prepare3DFull(TH1* h) {
101 Int_t middle_x[2];
102 Int_t middle_y[2];
103 Int_t middle_z[2];
104 middle_x[0] = middle_x[1] = h->GetXaxis()->FindBin(0.0);
105 middle_y[0] = middle_y[1] = h->GetYaxis()->FindBin(0.0);
106 middle_z[0] = middle_z[1] = h->GetZaxis()->FindBin(0.0);
107 auto frame = fCF->GetFrame();
108 if (frame == Femto::EKinematics::kSH_LCMS || frame == Femto::EKinematics::kSH_PRF) {
109 middle_x[0] = middle_y[0] = middle_z[0] = 1;
110 middle_x[1] = h->GetXaxis()->GetNbins();
111 middle_y[1] = h->GetYaxis()->GetNbins();
112 middle_z[1] = h->GetZaxis()->GetNbins();
113 } else {
114 if (h->GetXaxis()->GetBinLowEdge(middle_x[0]) == 0.0 && middle_x[0] > 1) --middle_x[0];
115 if (h->GetYaxis()->GetBinLowEdge(middle_y[0]) == 0.0 && middle_y[0] > 1) --middle_y[0];
116 if (h->GetZaxis()->GetBinLowEdge(middle_z[0]) == 0.0 && middle_z[0] > 1) --middle_z[0];
117 }
118 TString names[] = {"out", "side", "long"};
119 TString dirs[] = {"x", "y", "z"};
120 TString titles[] = {"cf", "num", "den"};
121 Int_t mxxLow[] = {middle_y[0], middle_x[0], middle_x[0]};
122 Int_t myyLow[] = {middle_z[0], middle_z[0], middle_y[0]};
123 Int_t mxxHi[] = {middle_y[1], middle_x[1], middle_x[1]};
124 Int_t myyHi[] = {middle_z[1], middle_z[1], middle_y[1]};
125 for (int padId = 0; padId < 9; padId++) {
126 int optId = padId % 3;
127 int flagDir = (padId - optId) / 3;
128 TString optLoc = titles[optId] + "+" + dirs[flagDir] + "+scale+bins";
129 TH1* hx = nullptr;
130 switch (optId) {
131 case 0: hx = h; break;
132 case 1: hx = fCF->GetNum(); break;
133 case 2: hx = fCF->GetDen(); break;
134 default: break;
135 }
136 auto histo = GetProjection1D(h, mxxLow[flagDir], mxxHi[flagDir], myyLow[flagDir], myyHi[flagDir], optLoc);
137 histo->SetTitle(Form("%s %s", names[flagDir].Data(), titles[optId].Data()));
138 histo->SetMinimum(0);
139 if (fRangeY[0] != fRangeY[1]) {
140 histo->SetMaximum(fRangeY[1]);
141 histo->SetMinimum(fRangeY[0]);
142 }
143 if (fRangeX[0] != fRangeX[1]) { histo->GetXaxis()->SetRangeUser(fRangeX[0], fRangeX[1]); }
144 std::vector<TH1*> histVec;
145 histVec.push_back(histo);
146 fHistograms.push_back(histVec);
147 }
148 }
149
150 TH1D*
151 Femto3DCFPainter::GetProjection1D(TH1* h, Double_t min1, Double_t max1, Double_t min2, Double_t max2, Option_t* opt) const {
152 TString option = opt;
153 TH1D* num1d = Hal::Std::GetProjection1D((TH3*) h, min1, max1, min2, max2, option);
154 return num1d;
155 }
156
157 void Femto3DCFPainter::Prepare3D(TH1* h) {
158 Int_t middle_x[2];
159 Int_t middle_y[2];
160 Int_t middle_z[2];
161 middle_x[0] = middle_x[1] = h->GetXaxis()->FindBin(0.0);
162 middle_y[0] = middle_y[1] = h->GetYaxis()->FindBin(0.0);
163 middle_z[0] = middle_z[1] = h->GetZaxis()->FindBin(0.0);
164 auto frame = fCF->GetFrame();
165 if (frame == Femto::EKinematics::kSH_LCMS || frame == Femto::EKinematics::kSH_PRF) {
166 middle_x[0] = middle_y[0] = middle_z[0] = 1;
167 middle_x[1] = h->GetXaxis()->GetNbins();
168 middle_y[1] = h->GetYaxis()->GetNbins();
169 middle_z[1] = h->GetZaxis()->GetNbins();
170 } else {
171 if (h->GetXaxis()->GetBinLowEdge(middle_x[0]) == 0.0 && middle_x[0] > 1) --middle_x[0];
172 if (h->GetYaxis()->GetBinLowEdge(middle_y[0]) == 0.0 && middle_y[0] > 1) --middle_y[0];
173 if (h->GetZaxis()->GetBinLowEdge(middle_z[0]) == 0.0 && middle_z[0] > 1) --middle_z[0];
174 }
175 TString names[] = {"out", "side", "long"};
176 TString dirs[] = {"x", "y", "z"};
177 Int_t mxxLow[] = {middle_y[0], middle_x[0], middle_x[0]};
178 Int_t myyLow[] = {middle_z[0], middle_z[0], middle_y[0]};
179 Int_t mxxHi[] = {middle_y[1], middle_x[1], middle_x[1]};
180 Int_t myyHi[] = {middle_z[1], middle_z[1], middle_y[1]};
181 for (int i = 0; i < 3; i++) {
182 auto histo = GetProjection1D(h, mxxLow[i], mxxHi[i], myyLow[i], myyHi[i], dirs[i] + "+scale+bins");
183 histo->SetTitle(names[i]);
184 if (fRangeY[0] != fRangeY[1]) {
185 histo->SetMaximum(fRangeY[1]);
186 histo->SetMinimum(fRangeY[0]);
187 }
188 TString titleY = "";
189 if (CheckOpt(kNumBit) || CheckOpt(kDenBit)) {
190 titleY = "dN_{pairs}/d%s";
191 } else {
192 titleY = "CF(%s)";
193 }
194 TString axisTitle = Femto::KinematicsToAxisLabel(fCF->GetFrame(), i, 3);
195 axisTitle = Hal::Std::RemoveUnits(axisTitle);
196 axisTitle.ReplaceAll(" ", "");
197 titleY = Form(titleY.Data(), axisTitle.Data());
198 histo->GetYaxis()->SetTitle(titleY);
199 std::vector<TH1*> histVec;
200 histVec.push_back(histo);
201 fHistograms.push_back(histVec);
202 }
203 }
204
205 void Femto3DCFPainter::PrepareDiagonal1(TH1* h) {
206 TString options[7] = {"x", "y", "z", "xy++", "yz++", "xz++", "xyz+++"};
207 TString titles[7] = {
208 "out",
209 "side",
210 "long",
211 "out+side+",
212 "side+long+",
213 "out+long+",
214 "out+side+long+",
215 };
216 for (int i = 0; i < 7; i++) {
217 auto hist = Hal::Std::GetDiagonalProjection1D((TH3*) h, options[i], 0, 0);
218 hist->SetTitle(titles[i]);
219 hist->SetStats(0);
220 TString xTitle = hist->GetXaxis()->GetTitle();
221 xTitle = xTitle.ReplaceAll("[GeV/c]", "");
222 hist->SetYTitle(Form("C(%s)", xTitle.Data()));
223 hist->SetXTitle(Form("%s [GeV/c]", xTitle.Data()));
224 std::vector<TH1*> histVec;
225 histVec.push_back(hist);
226 if (fRangeY[0] != fRangeY[1]) {
227 hist->SetMaximum(fRangeY[1]);
228 hist->SetMinimum(fRangeY[0]);
229 }
230 if (fRangeX[0] != fRangeX[1]) { hist->GetXaxis()->SetRangeUser(fRangeX[0], fRangeX[1]); }
231 fHistograms.push_back(histVec);
232 }
233 }
234
235 void Femto3DCFPainter::PrepareDiagonal2(TH1* h) {
236 TString options[16] = {
237 "x", "y", "z", "", "xy++", "xy+-", "yz++", "", "yz+-", "xz++", "xz+-", "", "xyz+++", "xyz+-+", "xyz+--", "xyz++-"};
238 TString titles[16] = {"out",
239 "side",
240 "long",
241 "",
242 "out+side+",
243 "out+side-",
244 "side+long+",
245 "",
246 "side+long-",
247 "out+long+",
248 "out+long-",
249 "",
250 "out+side+long+",
251 "out+side-long+",
252 "out+side-long-",
253 "out+side+long-"};
254
255 for (int i = 0; i < 16; i++) {
256 std::vector<TH1*> histVec;
257 if (options[i] == "") {
258 histVec.push_back(nullptr);
259 } else {
260 auto histo = Hal::Std::GetDiagonalProjection1D((TH3*) h, options[i], 0, 0);
261 histo->SetTitle(titles[i]);
262 histo->SetStats(0);
263 TString xTitle = histo->GetXaxis()->GetTitle();
264 xTitle = xTitle.ReplaceAll("[GeV/c]", "");
265 histo->SetYTitle(Form("C(%s)", xTitle.Data()));
266 histo->SetXTitle(Form("%s [GeV/c]", xTitle.Data()));
267 if (fRangeY[0] != fRangeY[1]) {
268 histo->SetMaximum(fRangeY[1]);
269 histo->SetMinimum(fRangeY[0]);
270 }
271 if (fRangeX[0] != fRangeX[1]) { histo->GetXaxis()->SetRangeUser(fRangeX[0], fRangeX[1]); }
272 histVec.push_back(histo);
273 }
274 fHistograms.push_back(histVec);
275 }
276 }
277
278 void Femto3DCFPainter::PrepareTwoDim(TH1* h) {
279
280 TString opts[] = {"xy", "xz", "yz"};
281 for (int i = 0; i < 3; i++) {
282 auto out_side = Hal::Std::GetProjection2D((TH3*) h, 0, 0, opts[i]);
283 if (fRangeY[0] != fRangeY[1]) {
284 out_side->SetMaximum(fRangeY[1]);
285 out_side->SetMinimum(fRangeY[0]);
286 }
287 std::vector<TH1*> histVec;
288 histVec.push_back(out_side);
289 fHistograms.push_back(histVec);
290 }
291 }
292
293 Int_t Femto3DCFPainter::GetPadsRequired() const {
294 if (CheckOpt(kDiag1Bit)) {
295 return 9;
296 } else if (CheckOpt(kDiag2Bit)) {
297 return 16;
298 } else if (CheckOpt(kHtmlBit)) {
299 return 9;
300 } else if (CheckOpt(kTwoDimBit) || CheckOpt(kTwoDimPlusBit)) {
301 return 4;
302 } else { // standard
303 if (AreSimiliar(GetDrawFlags(), PrepBitTemplate({kNumBit, kDenBit, kCFBit}))) {
304 return 9;
305 } else {
306 return 4;
307 }
308 }
309 return 4;
310 }
311
312 void Femto3DCFPainter::PrepareHtml(TH1* h) {
313 Int_t middle_x[2];
314 Int_t middle_y[2];
315 Int_t middle_z[2];
316 middle_x[0] = middle_x[1] = h->GetXaxis()->FindBin(0.0);
317 middle_y[0] = middle_y[1] = h->GetYaxis()->FindBin(0.0);
318 middle_z[0] = middle_z[1] = h->GetZaxis()->FindBin(0.0);
319 auto frame = fCF->GetFrame();
320 if (frame == Femto::EKinematics::kSH_LCMS || frame == Femto::EKinematics::kSH_PRF) {
321 middle_x[0] = middle_y[0] = middle_z[0] = 1;
322 middle_x[1] = h->GetXaxis()->GetNbins();
323 middle_y[1] = h->GetYaxis()->GetNbins();
324 middle_z[1] = h->GetZaxis()->GetNbins();
325 } else {
326 if (h->GetXaxis()->GetBinLowEdge(middle_x[0]) == 0.0 && middle_x[0] > 1) --middle_x[0];
327 if (h->GetYaxis()->GetBinLowEdge(middle_y[0]) == 0.0 && middle_y[0] > 1) --middle_y[0];
328 if (h->GetZaxis()->GetBinLowEdge(middle_z[0]) == 0.0 && middle_z[0] > 1) --middle_z[0];
329 }
330 TString names[] = {"out", "side", "long"};
331 TString dirs[] = {"x", "y", "z"};
332 Int_t mxxLow[] = {middle_y[0], middle_x[0], middle_x[0]};
333 Int_t myyLow[] = {middle_z[0], middle_z[0], middle_y[0]};
334 Int_t mxxHi[] = {middle_y[1], middle_x[1], middle_x[1]};
335 Int_t myyHi[] = {middle_z[1], middle_z[1], middle_y[1]};
336 for (int i = 0; i < 3; i++) {
337 auto histo = GetProjection1D(h, mxxLow[i], mxxHi[i], myyLow[i], myyHi[i], dirs[i] + "+scale+bins");
338 histo->SetTitle(names[i]);
339 if (fRangeY[0] != fRangeY[1]) {
340 histo->SetMaximum(fRangeY[1]);
341 histo->SetMinimum(fRangeY[0]);
342 }
343 auto histoNum = GetProjection1D(fCF->GetNum(), mxxLow[i], mxxHi[i], myyLow[i], myyHi[i], dirs[i]);
344 histoNum->SetTitle("Numerator" + names[i]);
345 auto histoDen = GetProjection1D(fCF->GetDen(), mxxLow[i], mxxHi[i], myyLow[i], myyHi[i], dirs[i]);
346 histoDen->SetTitle("Numerator" + names[i]);
347 Hal::Std::SetColor(*histoNum, kGreen);
348 Hal::Std::SetColor(*histoDen, kRed);
349 Hal::Std::SetColor(*histo, kBlue);
350 std::vector<TH1*> histVec1;
351 histVec1.push_back(histo);
352 std::vector<TH1*> histVec2;
353 histVec2.push_back(histoNum);
354 std::vector<TH1*> histVec3;
355 histVec3.push_back(histoDen);
356 fHistograms.push_back(histVec1);
357 fHistograms.push_back(histVec2);
358 fHistograms.push_back(histVec3);
359 }
360 }
361
363 if (CheckOpt(kDiag1Bit)) {
364 HalCoutDebug("Diag1");
365 return "fit2";
366 }
367 if (CheckOpt(kDiag2Bit)) {
368 HalCoutDebug("Diag2");
369 return "fit3";
370 }
371 if (CheckOpt(kTwoDimBit)) return "fit4";
372 if (CheckOpt(kTwoDimPlusBit)) return "fit5";
373 return "fit1";
374 }
375
376 void Femto3DCFPainter::ScaleHistograms() {
377 FemtoCFPainter::ScaleHistograms();
378 if (fRangeY[0] != fRangeY[1])
379 for (auto& x : fHistograms) {
380 for (auto y : x) {
381 if (y) {
382 y->SetMinimum(fRangeY[0]);
383 y->SetMaximum(fRangeY[1]);
384 }
385 }
386 }
387 }
388
389 Femto3DCFPainter::~Femto3DCFPainter() {}
390
392 Int_t req = TMath::Sqrt(GetPadsRequired());
393 MakeCanvasPads(req, req, 0);
394 }
395
396 void Femto3DCFPainter::DrawHistograms() {
397 FemtoCFPainter::DrawHistograms();
398 if (!CheckOpt(kAngles)) return;
399 LockPad();
400 int count = 0;
401 for (auto i : fHistograms) {
402 GotoPad(++count);
403 gPad->SetTheta(fThetaPad);
404 gPad->SetPhi(fPhiPad);
405 }
406 UnlockPad();
407 }
408
409} /* namespace Hal */
TH1 * GetHist(Bool_t normalized=kTRUE) const
virtual Bool_t CheckPads() const
virtual TString GetOptionForCorrFit() const
virtual void MakePadsAndCanvases()
virtual ULong64_t SetOptionInternal(TString opt, ULong64_t prev=0)
Femto::EKinematics GetFrame() const
Definition Femto3DCF.h:67
Bool_t AreSimiliar(ULong64_t current, ULong64_t pattern) const
virtual ULong64_t SetOptionInternal(TString opt, ULong64_t prev=0)
ULong64_t GetDrawFlags() const
Definition Painter.h:84
void UnlockPad()
Definition Painter.cxx:182
void LockPad()
Definition Painter.cxx:180
Bool_t CheckOpt(Int_t opt) const
Definition Painter.h:79
void ResetFewBits(ULong64_t &flag, std::initializer_list< Int_t > bits, Int_t set=-1) const
Definition Painter.cxx:228
void MakeCanvasPads(Int_t x=1, Int_t y=1, Int_t canvasNo=0)
Definition Painter.cxx:70
Int_t GetPadsNo(Int_t canvasNo=0) const
Definition Painter.h:148
void ContitionalPattern(TString &option, TString pattern, ULong64_t &drawOpt, Int_t bit, Bool_t remove=kTRUE) const
Definition Painter.cxx:174
void GotoPad(Int_t no, Int_t canvasNo=0)
Definition Painter.cxx:187
Bool_t GetPatterns(TString opt, TString flag, std::vector< double > &vals) const
Definition Painter.cxx:161