|
10 | 10 | // or submit itself to any jurisdiction. |
11 | 11 |
|
12 | 12 | #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() |
21 | 21 | { |
22 | | -}; |
23 | | -BootstrapProfile::~BootstrapProfile() { |
24 | 22 | delete fListOfEntries; |
25 | 23 | }; |
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; |
47 | 46 | fListOfEntries = new TList(); |
48 | 47 | 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))); |
52 | 51 | ((TProfile*)fListOfEntries->At(i))->Reset(); |
53 | 52 | } |
54 | 53 | fNSubs = nSub; |
55 | 54 | } |
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); |
62 | 64 | } |
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); |
65 | 68 | } |
66 | | -void BootstrapProfile::RebinMulti(Int_t nbins) { |
| 69 | +void BootstrapProfile::RebinMulti(Int_t nbins) |
| 70 | +{ |
67 | 71 | 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++) |
70 | 75 | ((TProfile*)fListOfEntries->At(i))->RebinX(nbins); |
71 | 76 | } |
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 | + }; |
77 | 88 | } 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 | + }; |
81 | 99 | } |
82 | 100 | return 0; |
83 | 101 | } |
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 | + }; |
88 | 111 | } 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 | + }; |
92 | 122 | } |
93 | 123 | } |
94 | | -Long64_t BootstrapProfile::Merge(TCollection *collist) { |
| 124 | +Long64_t BootstrapProfile::Merge(TCollection* collist) |
| 125 | +{ |
95 | 126 | 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; |
98 | 129 | TIter all_PBS(collist); |
99 | | - while ((l_PBS = ((BootstrapProfile*) all_PBS()))) { |
| 130 | + while ((l_PBS = ((BootstrapProfile*)all_PBS()))) { |
100 | 131 | (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) { |
104 | 136 | 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(); |
106 | 139 | }; |
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)); |
108 | 142 | nmerged++; |
109 | 143 | }; |
110 | 144 | return nmergedpf; |
111 | 145 | }; |
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 | + }; |
115 | 156 | 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]; |
118 | 160 | } |
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())); |
124 | 169 | delete temppf; |
125 | 170 | return reth; |
126 | 171 | } |
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); |
131 | 180 | 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++) { |
135 | 187 | Int_t i_n = reth->FindBin(lW->GetBinCenter(i)); |
136 | 188 | Double_t bc2 = lProf->GetBinContent(i); |
137 | 189 | Double_t be2 = lW->GetBinEntries(i); |
138 | 190 | Double_t bc1 = reth->GetBinContent(i_n); |
139 | 191 | 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); |
143 | 196 | }; |
144 | | - for(Int_t i=1;i<=reth->GetNbinsX();i++) { |
| 197 | + for (Int_t i = 1; i <= reth->GetNbinsX(); i++) { |
145 | 198 | Double_t bc1 = reth->GetBinContent(i); |
146 | 199 | 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)); |
150 | 204 | }; |
151 | 205 | return reth; |
152 | 206 | } |
153 | | -void BootstrapProfile::MergeBS(BootstrapProfile *target) { |
| 207 | +void BootstrapProfile::MergeBS(BootstrapProfile* target) |
| 208 | +{ |
154 | 209 | 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; |
158 | 214 | 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(); |
160 | 217 | } |
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)); |
162 | 220 | } |
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)); |
167 | 230 | return retpf; |
168 | 231 | } |
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; |
172 | 237 | ((TProfile*)this)->Reset(); |
173 | 238 | ((TProfile*)this)->Add(sum); |
174 | 239 | delete sum; |
|
0 commit comments