Skip to content

Commit 92606d3

Browse files
author
Emil Gorm Nielsen
committed
clang-format and whitespace
1 parent 648525b commit 92606d3

6 files changed

Lines changed: 662 additions & 516 deletions

File tree

PWGCF/GenericFramework/Core/BootstrapProfile.cxx

Lines changed: 171 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -10,165 +10,230 @@
1010
// or submit itself to any jurisdiction.
1111

1212
#include "BootstrapProfile.h"
13-
BootstrapProfile::BootstrapProfile():
14-
TProfile(),
15-
fListOfEntries(0),
16-
fProfInitialized(kFALSE),
17-
fNSubs(0),
18-
fMultiRebin(0),
19-
fMultiRebinEdges(0),
20-
fPresetWeights(0)
13+
BootstrapProfile::BootstrapProfile() : TProfile(),
14+
fListOfEntries(0),
15+
fProfInitialized(kFALSE),
16+
fNSubs(0),
17+
fMultiRebin(0),
18+
fMultiRebinEdges(0),
19+
fPresetWeights(0){};
20+
BootstrapProfile::~BootstrapProfile()
2121
{
22-
};
23-
BootstrapProfile::~BootstrapProfile() {
2422
delete fListOfEntries;
2523
};
26-
BootstrapProfile::BootstrapProfile(const char* name, const char* title, Int_t nbinsx, const Double_t* xbins):
27-
TProfile(name,title,nbinsx,xbins),
28-
fListOfEntries(0),
29-
fProfInitialized(kTRUE),
30-
fNSubs(0),
31-
fMultiRebin(0),
32-
fMultiRebinEdges(0),
33-
fPresetWeights(0)
34-
{};
35-
BootstrapProfile::BootstrapProfile(const char* name, const char* title, Int_t nbinsx, Double_t xlow, Double_t xup):
36-
TProfile(name,title,nbinsx,xlow,xup),
37-
fListOfEntries(0),
38-
fProfInitialized(kFALSE),
39-
fNSubs(0),
40-
fMultiRebin(0),
41-
fMultiRebinEdges(0),
42-
fPresetWeights(0)
43-
{};
44-
void BootstrapProfile::InitializeSubsamples(Int_t nSub) {
45-
if(nSub<1) {printf("Number of subprofiles has to be > 0!\n"); return; };
46-
if(fListOfEntries) delete fListOfEntries;
24+
BootstrapProfile::BootstrapProfile(const char* name, const char* title, Int_t nbinsx, const Double_t* xbins) : TProfile(name, title, nbinsx, xbins),
25+
fListOfEntries(0),
26+
fProfInitialized(kTRUE),
27+
fNSubs(0),
28+
fMultiRebin(0),
29+
fMultiRebinEdges(0),
30+
fPresetWeights(0){};
31+
BootstrapProfile::BootstrapProfile(const char* name, const char* title, Int_t nbinsx, Double_t xlow, Double_t xup) : TProfile(name, title, nbinsx, xlow, xup),
32+
fListOfEntries(0),
33+
fProfInitialized(kFALSE),
34+
fNSubs(0),
35+
fMultiRebin(0),
36+
fMultiRebinEdges(0),
37+
fPresetWeights(0){};
38+
void BootstrapProfile::InitializeSubsamples(Int_t nSub)
39+
{
40+
if (nSub < 1) {
41+
printf("Number of subprofiles has to be > 0!\n");
42+
return;
43+
};
44+
if (fListOfEntries)
45+
delete fListOfEntries;
4746
fListOfEntries = new TList();
4847
fListOfEntries->SetOwner(kTRUE);
49-
TProfile *dummyPF = (TProfile*)this;
50-
for(Int_t i=0;i<nSub;i++) {
51-
fListOfEntries->Add((TProfile*)dummyPF->Clone(Form("%s_Subpf%i",dummyPF->GetName(),i)));
48+
TProfile* dummyPF = (TProfile*)this;
49+
for (Int_t i = 0; i < nSub; i++) {
50+
fListOfEntries->Add((TProfile*)dummyPF->Clone(Form("%s_Subpf%i", dummyPF->GetName(), i)));
5251
((TProfile*)fListOfEntries->At(i))->Reset();
5352
}
5453
fNSubs = nSub;
5554
}
56-
void BootstrapProfile::FillProfile(const Double_t &xv, const Double_t& yv, const Double_t &w, const Double_t &rn) {
57-
TProfile::Fill(xv,yv,w);
58-
if(!fNSubs) return;
59-
Int_t targetInd = rn*fNSubs;
60-
if(targetInd>=fNSubs) targetInd = 0;
61-
((TProfile*)fListOfEntries->At(targetInd))->Fill(xv,yv,w);
55+
void BootstrapProfile::FillProfile(const Double_t& xv, const Double_t& yv, const Double_t& w, const Double_t& rn)
56+
{
57+
TProfile::Fill(xv, yv, w);
58+
if (!fNSubs)
59+
return;
60+
Int_t targetInd = rn * fNSubs;
61+
if (targetInd >= fNSubs)
62+
targetInd = 0;
63+
((TProfile*)fListOfEntries->At(targetInd))->Fill(xv, yv, w);
6264
}
63-
void BootstrapProfile::FillProfile(const Double_t &xv, const Double_t &yv, const Double_t &w) {
64-
TProfile::Fill(xv,yv,w);
65+
void BootstrapProfile::FillProfile(const Double_t& xv, const Double_t& yv, const Double_t& w)
66+
{
67+
TProfile::Fill(xv, yv, w);
6568
}
66-
void BootstrapProfile::RebinMulti(Int_t nbins) {
69+
void BootstrapProfile::RebinMulti(Int_t nbins)
70+
{
6771
this->RebinX(nbins);
68-
if(!fListOfEntries) return;
69-
for(Int_t i=0;i<fListOfEntries->GetEntries();i++)
72+
if (!fListOfEntries)
73+
return;
74+
for (Int_t i = 0; i < fListOfEntries->GetEntries(); i++)
7075
((TProfile*)fListOfEntries->At(i))->RebinX(nbins);
7176
}
72-
TH1 *BootstrapProfile::getHist(Int_t ind) {
73-
if(fPresetWeights && fMultiRebin>0) return getWeightBasedRebin(ind);
74-
if(ind<0) {
75-
if((TProfile*)this) return getHistRebinned((TProfile*)this);//((TProfile*)this)->ProjectionX(Form("%s_hist",this->GetName()));
76-
else { printf("Empty BootstrapProfile addressed, cannot get a histogram\n"); return 0; };
77+
TH1* BootstrapProfile::getHist(Int_t ind)
78+
{
79+
if (fPresetWeights && fMultiRebin > 0)
80+
return getWeightBasedRebin(ind);
81+
if (ind < 0) {
82+
if ((TProfile*)this)
83+
return getHistRebinned((TProfile*)this); //((TProfile*)this)->ProjectionX(Form("%s_hist",this->GetName()));
84+
else {
85+
printf("Empty BootstrapProfile addressed, cannot get a histogram\n");
86+
return 0;
87+
};
7788
} else {
78-
if(!fListOfEntries) { printf("No subprofiles exist!\n"); return 0; };
79-
if(ind<fNSubs) return getHistRebinned((TProfile*)fListOfEntries->At(ind));////((TProfile*)fListOfEntries->At(ind))->ProjectionX(Form("%s_sub%i",((TProfile*)fListOfEntries->At(ind))->GetName(),ind));
80-
else { printf("Trying to fetch subprofile no %i out of %i, not possible\n",ind,fNSubs); return 0;};
89+
if (!fListOfEntries) {
90+
printf("No subprofiles exist!\n");
91+
return 0;
92+
};
93+
if (ind < fNSubs)
94+
return getHistRebinned((TProfile*)fListOfEntries->At(ind)); ////((TProfile*)fListOfEntries->At(ind))->ProjectionX(Form("%s_sub%i",((TProfile*)fListOfEntries->At(ind))->GetName(),ind));
95+
else {
96+
printf("Trying to fetch subprofile no %i out of %i, not possible\n", ind, fNSubs);
97+
return 0;
98+
};
8199
}
82100
return 0;
83101
}
84-
TProfile *BootstrapProfile::getProfile(Int_t ind) {
85-
if(ind<0) {
86-
if((TProfile*)this) return (TProfile*)this;
87-
else { printf("Empty BootstrapProfile addressed, cannot get a histogram\n"); return 0; };
102+
TProfile* BootstrapProfile::getProfile(Int_t ind)
103+
{
104+
if (ind < 0) {
105+
if ((TProfile*)this)
106+
return (TProfile*)this;
107+
else {
108+
printf("Empty BootstrapProfile addressed, cannot get a histogram\n");
109+
return 0;
110+
};
88111
} else {
89-
if(!fListOfEntries) { printf("No subprofiles exist!\n"); return 0; };
90-
if(ind<fNSubs) return (TProfile*)fListOfEntries->At(ind);
91-
else { printf("Trying to fetch subprofile no %i out of %i, not possible\n",ind,fNSubs); return 0;};
112+
if (!fListOfEntries) {
113+
printf("No subprofiles exist!\n");
114+
return 0;
115+
};
116+
if (ind < fNSubs)
117+
return (TProfile*)fListOfEntries->At(ind);
118+
else {
119+
printf("Trying to fetch subprofile no %i out of %i, not possible\n", ind, fNSubs);
120+
return 0;
121+
};
92122
}
93123
}
94-
Long64_t BootstrapProfile::Merge(TCollection *collist) {
124+
Long64_t BootstrapProfile::Merge(TCollection* collist)
125+
{
95126
Long64_t nmergedpf = TProfile::Merge(collist);
96-
Long64_t nmerged=0;
97-
BootstrapProfile *l_PBS = 0;
127+
Long64_t nmerged = 0;
128+
BootstrapProfile* l_PBS = 0;
98129
TIter all_PBS(collist);
99-
while ((l_PBS = ((BootstrapProfile*) all_PBS()))) {
130+
while ((l_PBS = ((BootstrapProfile*)all_PBS()))) {
100131
(TProfile*)this->Add((TProfile*)l_PBS);
101-
TList *tarL = l_PBS->fListOfEntries;
102-
if(!tarL) continue;
103-
if(!fListOfEntries) {
132+
TList* tarL = l_PBS->fListOfEntries;
133+
if (!tarL)
134+
continue;
135+
if (!fListOfEntries) {
104136
fListOfEntries = (TList*)tarL->Clone();
105-
for(Int_t i=0; i<fListOfEntries->GetEntries(); i++) ((TProfile*)fListOfEntries->At(i))->Reset();
137+
for (Int_t i = 0; i < fListOfEntries->GetEntries(); i++)
138+
((TProfile*)fListOfEntries->At(i))->Reset();
106139
};
107-
for(Int_t i=0; i<fListOfEntries->GetEntries(); i++) ((TProfile*)fListOfEntries->At(i))->Add((TProfile*)tarL->At(i));
140+
for (Int_t i = 0; i < fListOfEntries->GetEntries(); i++)
141+
((TProfile*)fListOfEntries->At(i))->Add((TProfile*)tarL->At(i));
108142
nmerged++;
109143
};
110144
return nmergedpf;
111145
};
112-
void BootstrapProfile::RebinMulti(Int_t nbins, Double_t *binedges) {
113-
if(fMultiRebinEdges) {delete [] fMultiRebinEdges; fMultiRebinEdges=0;};
114-
if(nbins<=0) { fMultiRebin=0; return; };
146+
void BootstrapProfile::RebinMulti(Int_t nbins, Double_t* binedges)
147+
{
148+
if (fMultiRebinEdges) {
149+
delete[] fMultiRebinEdges;
150+
fMultiRebinEdges = 0;
151+
};
152+
if (nbins <= 0) {
153+
fMultiRebin = 0;
154+
return;
155+
};
115156
fMultiRebin = nbins;
116-
fMultiRebinEdges = new Double_t[nbins+1];
117-
for(Int_t i=0;i<=fMultiRebin;i++) fMultiRebinEdges[i] = binedges[i];
157+
fMultiRebinEdges = new Double_t[nbins + 1];
158+
for (Int_t i = 0; i <= fMultiRebin; i++)
159+
fMultiRebinEdges[i] = binedges[i];
118160
}
119-
TH1 *BootstrapProfile::getHistRebinned(TProfile *inpf) {
120-
if(!inpf) return 0;
121-
if(fMultiRebin<=0) return ((TProfile*)inpf)->ProjectionX(Form("%s_hist",inpf->GetName()));
122-
TProfile *temppf = (TProfile*)inpf->Rebin(fMultiRebin,"tempProfile",fMultiRebinEdges);
123-
TH1 *reth = (TH1*)temppf->ProjectionX(Form("%s_hist",inpf->GetName()));
161+
TH1* BootstrapProfile::getHistRebinned(TProfile* inpf)
162+
{
163+
if (!inpf)
164+
return 0;
165+
if (fMultiRebin <= 0)
166+
return ((TProfile*)inpf)->ProjectionX(Form("%s_hist", inpf->GetName()));
167+
TProfile* temppf = (TProfile*)inpf->Rebin(fMultiRebin, "tempProfile", fMultiRebinEdges);
168+
TH1* reth = (TH1*)temppf->ProjectionX(Form("%s_hist", inpf->GetName()));
124169
delete temppf;
125170
return reth;
126171
}
127-
TH1 *BootstrapProfile::getWeightBasedRebin(Int_t ind) {
128-
if(!fPresetWeights) { printf("Weights are not preset!\n"); return 0; };
129-
TProfile *lProf = getProfile(ind);
130-
TH1 *reth = getHistRebinned(lProf);
172+
TH1* BootstrapProfile::getWeightBasedRebin(Int_t ind)
173+
{
174+
if (!fPresetWeights) {
175+
printf("Weights are not preset!\n");
176+
return 0;
177+
};
178+
TProfile* lProf = getProfile(ind);
179+
TH1* reth = getHistRebinned(lProf);
131180
reth->Reset();
132-
TProfile *lW = fPresetWeights->getProfile(ind);
133-
if(!lW) {printf("Weight profile could not be found!\n"); return 0; };
134-
for(Int_t i=1;i<=lW->GetNbinsX();i++) {
181+
TProfile* lW = fPresetWeights->getProfile(ind);
182+
if (!lW) {
183+
printf("Weight profile could not be found!\n");
184+
return 0;
185+
};
186+
for (Int_t i = 1; i <= lW->GetNbinsX(); i++) {
135187
Int_t i_n = reth->FindBin(lW->GetBinCenter(i));
136188
Double_t bc2 = lProf->GetBinContent(i);
137189
Double_t be2 = lW->GetBinEntries(i);
138190
Double_t bc1 = reth->GetBinContent(i_n);
139191
Double_t be1 = reth->GetBinError(i_n);
140-
if(be2==0) continue;
141-
reth->SetBinContent(i_n,bc1+bc2*be2);
142-
reth->SetBinError(i_n,be1+be2);
192+
if (be2 == 0)
193+
continue;
194+
reth->SetBinContent(i_n, bc1 + bc2 * be2);
195+
reth->SetBinError(i_n, be1 + be2);
143196
};
144-
for(Int_t i=1;i<=reth->GetNbinsX();i++) {
197+
for (Int_t i = 1; i <= reth->GetNbinsX(); i++) {
145198
Double_t bc1 = reth->GetBinContent(i);
146199
Double_t be1 = reth->GetBinError(i);
147-
if(be1==0) continue;
148-
reth->SetBinContent(i,bc1/be1);
149-
reth->SetBinError(i,1./TMath::Sqrt(be1));
200+
if (be1 == 0)
201+
continue;
202+
reth->SetBinContent(i, bc1 / be1);
203+
reth->SetBinError(i, 1. / TMath::Sqrt(be1));
150204
};
151205
return reth;
152206
}
153-
void BootstrapProfile::MergeBS(BootstrapProfile *target) {
207+
void BootstrapProfile::MergeBS(BootstrapProfile* target)
208+
{
154209
this->Add(target);
155-
TList *tarL = target->fListOfEntries;
156-
if(!fListOfEntries) {
157-
if(!target->fListOfEntries) return;
210+
TList* tarL = target->fListOfEntries;
211+
if (!fListOfEntries) {
212+
if (!target->fListOfEntries)
213+
return;
158214
fListOfEntries = (TList*)tarL->Clone();
159-
for(Int_t i=0; i<fListOfEntries->GetEntries(); i++) ((TProfile*)fListOfEntries->At(i))->Reset();
215+
for (Int_t i = 0; i < fListOfEntries->GetEntries(); i++)
216+
((TProfile*)fListOfEntries->At(i))->Reset();
160217
}
161-
for(Int_t i=0; i<fListOfEntries->GetEntries(); i++) ((TProfile*)fListOfEntries->At(i))->Add((TProfile*)tarL->At(i));
218+
for (Int_t i = 0; i < fListOfEntries->GetEntries(); i++)
219+
((TProfile*)fListOfEntries->At(i))->Add((TProfile*)tarL->At(i));
162220
}
163-
TProfile *BootstrapProfile::getSummedProfiles() {
164-
if(!fListOfEntries || !fListOfEntries->GetEntries()) {printf("No subprofiles initialized for the BootstrapProfile.\n"); return 0; };
165-
TProfile *retpf = (TProfile*)fListOfEntries->At(0)->Clone("SummedProfile");
166-
for(Int_t i=1;i<fListOfEntries->GetEntries();i++) retpf->Add((TProfile*)fListOfEntries->At(i));
221+
TProfile* BootstrapProfile::getSummedProfiles()
222+
{
223+
if (!fListOfEntries || !fListOfEntries->GetEntries()) {
224+
printf("No subprofiles initialized for the BootstrapProfile.\n");
225+
return 0;
226+
};
227+
TProfile* retpf = (TProfile*)fListOfEntries->At(0)->Clone("SummedProfile");
228+
for (Int_t i = 1; i < fListOfEntries->GetEntries(); i++)
229+
retpf->Add((TProfile*)fListOfEntries->At(i));
167230
return retpf;
168231
}
169-
void BootstrapProfile::OverrideMainWithSub() {
170-
TProfile *sum = getSummedProfiles();
171-
if(!sum) return;
232+
void BootstrapProfile::OverrideMainWithSub()
233+
{
234+
TProfile* sum = getSummedProfiles();
235+
if (!sum)
236+
return;
172237
((TProfile*)this)->Reset();
173238
((TProfile*)this)->Add(sum);
174239
delete sum;

0 commit comments

Comments
 (0)