Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CorrelationHisto.cxx
1/*
2 * CorrHisto.cxx
3 *
4 * Created on: 11 kwi 2024
5 * Author: daniel
6 */
7
8#include "CorrelationHisto.h"
9
10#include "Cout.h"
11#include "Std.h"
12
13#include <TAxis.h>
14#include <TCanvas.h>
15#include <TH2D.h>
16#include <TVirtualPad.h>
17
18#include <iostream>
19
20namespace Hal {
21 CorrelationHisto::CorrelationHisto(Int_t nParams, Int_t nTest) :
22 fNParams(nParams), fNTest(TMath::Abs(nTest)), fAutoFill(kTRUE) {}
23
24 void CorrelationHisto::ConfigParam(Int_t par, Int_t bins, Double_t min, Double_t max, TString name) {
25 fAxesConf.insert(fAxesConf.begin() + par, Hal::HistogramAxisConf(name, bins, min, max));
26 fAutoFill = kFALSE;
27 fNTest = -1;
28 }
29
30 CorrelationHisto::CorrelationHisto(std::initializer_list<std::initializer_list<Double_t>> vals, Int_t nTest) {
31 for (auto i : vals) {
32 fNParams++;
33 auto vec = Hal::Std::GetVector(i);
34 fAxesConf.push_back(Hal::HistogramAxisConf(Form("par %i", fNParams - 1), vec[0], vec[1], vec[2]));
35 }
36 fNTest = -1;
37 fAutoFill = kFALSE;
38 }
39
40 void CorrelationHisto::Fill(std::vector<Double_t> params) {
41 if (params.size() != fNParams) return;
42 // HalCoutDebug();
43 if (fAutoFill) {
44 // HalCoutDebug();
45 if (fTestValues.size() < fNTest) {
46
47 fTestValues.push_back(params);
48 return;
49 } else {
50 fAutoFill = kFALSE;
51 AutoInitialize();
52 }
53 } else {
54 if (fNTest == -1) {
55 Initialize();
56 fNTest = 0;
57 }
58 }
59 // HalCoutDebug();
60 int count = 0;
61 for (int i = 0; i < fNParams; i++) {
62 double x = params[i];
63 for (int j = i; j < fNParams; j++) {
64 double y = params[j];
65 fHistograms[count++]->Fill(x, y);
66 }
67 }
68 }
69
70 void CorrelationHisto::Initialize() {
71 fNHistograms = (fNParams + 1) * fNParams / 2;
72 fHistograms = new TH2D*[fNHistograms];
73 int count = 0;
74 for (int i = 0; i < fNParams; i++) {
75 for (int j = i; j < fNParams; j++) {
76 count++;
77 TString title = Form("SB_%i", count);
78 fHistograms[count - 1] = new TH2D(title,
79 title,
80 fAxesConf[i].GetNBins(),
81 fAxesConf[i].GetMin(),
82 fAxesConf[i].GetMax(),
83 fAxesConf[j].GetNBins(),
84 fAxesConf[j].GetMin(),
85 fAxesConf[j].GetMax());
86 fHistograms[count - 1]->GetXaxis()->SetTitle(fAxesConf[i].GetName());
87 fHistograms[count - 1]->GetYaxis()->SetTitle(fAxesConf[j].GetName());
88 fHistograms[count - 1]->GetXaxis()->CenterTitle();
89 fHistograms[count - 1]->GetYaxis()->CenterTitle();
90 }
91 }
92 }
93
94 void CorrelationHisto::AutoInitialize() {
95 int count = 0;
96 for (int par = 0; par < fNParams; par++) {
97 double mini = 1E+9, maxi = 1E-9, av, sum = 0;
98 double n = fNTest;
99 for (unsigned int ent = 0; ent < fNTest; ent++) {
100 double j = fTestValues[ent][par];
101 sum += j;
102 mini = TMath::Min(mini, j);
103 maxi = TMath::Max(maxi, j);
104 }
105 av = sum / n;
106 double rms = 0;
107 for (unsigned int ent = 0; ent < fNTest; ent++) {
108 double j = fTestValues[ent][par];
109 rms += (av - j) * (av - j);
110 }
111 rms = TMath::Sqrt(rms / n);
112 mini = TMath::Min(mini, av - rms * 4.0);
113 maxi = TMath::Max(maxi, av + rms * 4.0);
114 fAxesConf.push_back(Hal::HistogramAxisConf(Form("%i", count++), 200, mini, maxi));
115 }
116
117 Initialize();
118 for (auto i : fTestValues) {
119 FillUnchecked(i);
120 }
121 fTestValues.clear();
122 }
123
124 void CorrelationHisto::FillUnchecked(std::vector<Double_t> params) {
125 int count = 0;
126 for (int i = 0; i < fNParams; i++) {
127 double x = params[i];
128 for (int j = i; j < fNParams; j++) {
129 double y = params[j];
130 fHistograms[count++]->Fill(x, y);
131 }
132 }
133 }
134
135 void CorrelationHisto::Draw(Option_t* /*opt*/) {
136 TCanvas* c = new TCanvas();
137 auto pads = Hal::Std::GetGridPad(fNParams, fNParams, 0.124, 0.124);
138 int count = 0;
139 for (int i = 0; i < fNParams; i++) {
140 for (int j = i; j < fNParams; j++) {
141 pads[i][j]->cd();
142 fHistograms[count++]->Draw("col");
143 }
144 }
145 }
146
147 CorrelationHisto::~CorrelationHisto() {
148 if (fHistograms) {
149 for (int i = 0; i < fNHistograms; i++) {
150 delete fHistograms[i];
151 }
152 delete[] fHistograms;
153 }
154 }
155
156} // namespace Hal
CorrelationHisto(Int_t nParams=1, Int_t nTest=1000)