]>
Commit | Line | Data |
---|---|---|
dc740de4 | 1 | /* $Id$ */ |
2 | ||
75ec0f41 | 3 | #include "dNdEtaAnalysis.h" |
4 | ||
ceb5d1b5 | 5 | #include <TFile.h> |
6 | #include <TH2F.h> | |
7 | #include <TH1D.h> | |
8 | #include <TMath.h> | |
9 | #include <TCanvas.h> | |
7029240a | 10 | #include <TCollection.h> |
11 | #include <TIterator.h> | |
12 | #include <TList.h> | |
fcf2fb36 | 13 | #include <TLegend.h> |
14 | ||
15 | #include "dNdEtaCorrection.h" | |
ceb5d1b5 | 16 | |
75ec0f41 | 17 | //____________________________________________________________________ |
b7f4a1fd | 18 | ClassImp(dNdEtaAnalysis) |
75ec0f41 | 19 | |
20 | //____________________________________________________________________ | |
7029240a | 21 | dNdEtaAnalysis::dNdEtaAnalysis(Char_t* name, Char_t* title) : |
16e24ca3 | 22 | TNamed(name, title), |
23 | fEtaVsVtx(0), | |
24 | fEtaVsVtxUncorrected(0), | |
25 | fVtx(0) | |
7029240a | 26 | { |
6bf0714d | 27 | // constructor |
4dd2ad81 | 28 | |
6bf0714d | 29 | fEtaVsVtx = new TH2F(Form("%s_eta_vs_vtx", name),"",80,-20,20,120,-6,6); |
30 | fEtaVsVtx->SetXTitle("vtx z [cm]"); | |
31 | fEtaVsVtx->SetYTitle("#eta"); | |
32 | ||
33 | fEtaVsVtxUncorrected = dynamic_cast<TH2F*> (fEtaVsVtx->Clone(Form("%s_eta_vs_vtx_uncorrected", name))); | |
34 | fVtx = fEtaVsVtx->ProjectionX(Form("%s_vtx", name)); | |
7029240a | 35 | for (Int_t i=0; i<kVertexBinning; ++i) |
36 | { | |
6bf0714d | 37 | fdNdEta[i] = fEtaVsVtx->ProjectionY(Form("%s_dNdEta_%d", name, i)); |
38 | fdNdEta[i]->SetYTitle("dN/d#eta"); | |
7029240a | 39 | } |
75ec0f41 | 40 | |
6bf0714d | 41 | fEtaVsVtx->Sumw2(); |
42 | fVtx->Sumw2(); | |
75ec0f41 | 43 | } |
44 | ||
16e24ca3 | 45 | //____________________________________________________________________ |
46 | dNdEtaAnalysis::~dNdEtaAnalysis() | |
47 | { | |
48 | // destructor | |
49 | ||
50 | delete fEtaVsVtx; | |
51 | fEtaVsVtx = 0; | |
52 | ||
53 | delete fEtaVsVtxUncorrected; | |
54 | fEtaVsVtxUncorrected = 0; | |
55 | ||
56 | delete fVtx; | |
57 | fVtx = 0; | |
58 | ||
59 | for (Int_t i=0; i<kVertexBinning; ++i) | |
60 | { | |
61 | delete fdNdEta[i]; | |
62 | fdNdEta[i] = 0; | |
63 | } | |
64 | } | |
65 | ||
66 | //_____________________________________________________________________________ | |
67 | dNdEtaAnalysis::dNdEtaAnalysis(const dNdEtaAnalysis &c) : | |
68 | TNamed(c), | |
69 | fEtaVsVtx(0), | |
70 | fEtaVsVtxUncorrected(0), | |
71 | fVtx(0) | |
72 | { | |
73 | // | |
74 | // dNdEtaAnalysis copy constructor | |
75 | // | |
76 | ||
77 | ((dNdEtaAnalysis &) c).Copy(*this); | |
78 | } | |
79 | ||
80 | //_____________________________________________________________________________ | |
81 | dNdEtaAnalysis &dNdEtaAnalysis::operator=(const dNdEtaAnalysis &c) | |
82 | { | |
83 | // | |
84 | // Assignment operator | |
85 | // | |
86 | ||
87 | if (this != &c) ((dNdEtaAnalysis &) c).Copy(*this); | |
88 | return *this; | |
89 | } | |
90 | ||
91 | //_____________________________________________________________________________ | |
92 | void dNdEtaAnalysis::Copy(TObject &c) const | |
93 | { | |
94 | // | |
95 | // Copy function | |
96 | // | |
97 | ||
98 | dNdEtaAnalysis& target = (dNdEtaAnalysis &) c; | |
99 | ||
100 | target.fEtaVsVtx = dynamic_cast<TH2F*> (fEtaVsVtx->Clone()); | |
101 | target.fEtaVsVtxUncorrected = dynamic_cast<TH2F*> (fEtaVsVtxUncorrected->Clone()); | |
102 | target.fVtx = dynamic_cast<TH1D*> (fVtx->Clone()); | |
103 | ||
104 | for (Int_t i=0; i<kVertexBinning; ++i) | |
105 | target.fdNdEta[i] = dynamic_cast<TH1D*> (fdNdEta[i]->Clone()); | |
106 | ||
107 | TNamed::Copy((TNamed &) c); | |
108 | } | |
109 | ||
75ec0f41 | 110 | //____________________________________________________________________ |
6bf0714d | 111 | void dNdEtaAnalysis::FillTrack(Float_t vtx, Float_t eta) |
112 | { | |
113 | // fills a track into the histograms | |
114 | ||
115 | fEtaVsVtxUncorrected->Fill(vtx,eta); | |
75ec0f41 | 116 | } |
117 | ||
118 | //____________________________________________________________________ | |
6bf0714d | 119 | void dNdEtaAnalysis::FillEvent(Float_t vtx) |
120 | { | |
121 | // fills an event into the histograms | |
122 | ||
123 | fVtx->Fill(vtx); | |
75ec0f41 | 124 | } |
125 | ||
126 | //____________________________________________________________________ | |
fcf2fb36 | 127 | void dNdEtaAnalysis::Finish(dNdEtaCorrection* correction) |
128 | { | |
129 | // correct with correction values if available | |
6bf0714d | 130 | |
fcf2fb36 | 131 | // TODO what do we do with the error? |
132 | if (!correction) | |
133 | printf("INFO: No correction applied\n"); | |
134 | ||
135 | // this can be replaced by TH2F::Divide if we agree that the binning will be always the same | |
6bf0714d | 136 | for (Int_t iVtx=0; iVtx<=fEtaVsVtxUncorrected->GetNbinsX(); iVtx++) |
fcf2fb36 | 137 | { |
6bf0714d | 138 | for (Int_t iEta=0; iEta<=fEtaVsVtxUncorrected->GetNbinsY(); iEta++) |
fcf2fb36 | 139 | { |
140 | Float_t correctionValue = 1; | |
141 | if (correction) | |
6bf0714d | 142 | correctionValue = correction->GetCorrection(fEtaVsVtxUncorrected->GetXaxis()->GetBinCenter(iVtx), fEtaVsVtxUncorrected->GetYaxis()->GetBinCenter(iEta)); |
fcf2fb36 | 143 | |
6bf0714d | 144 | Float_t value = fEtaVsVtxUncorrected->GetBinContent(iVtx, iEta); |
145 | Float_t error = fEtaVsVtxUncorrected->GetBinError(iVtx, iEta); | |
fcf2fb36 | 146 | |
147 | Float_t correctedValue = value * correctionValue; | |
148 | Float_t correctedError = error * correctionValue; | |
149 | ||
150 | if (correctedValue != 0) | |
151 | { | |
6bf0714d | 152 | fEtaVsVtx->SetBinContent(iVtx, iEta, correctedValue); |
153 | fEtaVsVtx->SetBinError(iVtx, iEta, correctedError); | |
fcf2fb36 | 154 | } |
155 | } | |
156 | } | |
157 | ||
6bf0714d | 158 | for (Int_t iEta=0; iEta<=fEtaVsVtx->GetNbinsY(); iEta++) |
5af55649 | 159 | { |
7029240a | 160 | // do we have several histograms for different vertex positions? |
6bf0714d | 161 | Int_t vertexBinWidth = fVtx->GetNbinsX() / (kVertexBinning-1); |
7029240a | 162 | for (Int_t vertexPos=0; vertexPos<kVertexBinning; ++vertexPos) |
163 | { | |
5af55649 | 164 | Int_t vertexBinBegin = 1; |
6bf0714d | 165 | Int_t vertexBinEnd = fVtx->GetNbinsX() + 1; |
fcf2fb36 | 166 | |
167 | // the first histogram is always for the whole vertex range | |
168 | if (vertexPos > 0) | |
169 | { | |
5af55649 | 170 | vertexBinBegin = 1 + vertexBinWidth * (vertexPos-1); |
fcf2fb36 | 171 | vertexBinEnd = vertexBinBegin + vertexBinWidth; |
172 | } | |
7029240a | 173 | |
6bf0714d | 174 | Float_t totalEvents = fVtx->Integral(vertexBinBegin, vertexBinEnd - 1); |
5af55649 | 175 | if (totalEvents == 0) |
176 | { | |
177 | printf("WARNING: No events for hist %d %d %d\n", vertexPos, vertexBinBegin, vertexBinEnd); | |
178 | continue; | |
7029240a | 179 | } |
7029240a | 180 | |
5af55649 | 181 | Float_t sum = 0; |
182 | Float_t sumError2 = 0; | |
183 | for (Int_t iVtx = vertexBinBegin; iVtx < vertexBinEnd; iVtx++) | |
184 | { | |
6bf0714d | 185 | if (fEtaVsVtx->GetBinContent(iVtx, iEta) != 0) |
5af55649 | 186 | { |
6bf0714d | 187 | sum = sum + fEtaVsVtx->GetBinContent(iVtx, iEta); |
188 | sumError2 = sumError2 + TMath::Power(fEtaVsVtx->GetBinError(iVtx, iEta),2); | |
5af55649 | 189 | } |
190 | } | |
7029240a | 191 | |
5af55649 | 192 | Float_t dndeta = sum / totalEvents; |
193 | Float_t error = TMath::Sqrt(sumError2) / totalEvents; | |
7029240a | 194 | |
6bf0714d | 195 | dndeta = dndeta/fdNdEta[vertexPos]->GetBinWidth(iEta); |
196 | error = error/fdNdEta[vertexPos]->GetBinWidth(iEta); | |
7029240a | 197 | |
6bf0714d | 198 | fdNdEta[vertexPos]->SetBinContent(iEta, dndeta); |
199 | fdNdEta[vertexPos]->SetBinError(iEta, error); | |
75ec0f41 | 200 | } |
75ec0f41 | 201 | } |
202 | } | |
203 | ||
75ec0f41 | 204 | //____________________________________________________________________ |
6bf0714d | 205 | void dNdEtaAnalysis::SaveHistograms() |
206 | { | |
207 | // save the histograms to a directory with the name of this class (retrieved from TNamed) | |
75ec0f41 | 208 | |
7029240a | 209 | gDirectory->mkdir(GetName()); |
210 | gDirectory->cd(GetName()); | |
5fbd0b17 | 211 | |
6bf0714d | 212 | fEtaVsVtx ->Write(); |
213 | fEtaVsVtxUncorrected->Write(); | |
214 | fVtx ->Write(); | |
7029240a | 215 | for (Int_t i=0; i<kVertexBinning; ++i) |
6bf0714d | 216 | fdNdEta[i] ->Write(); |
75ec0f41 | 217 | |
218 | gDirectory->cd("../"); | |
219 | } | |
220 | ||
5fbd0b17 | 221 | void dNdEtaAnalysis::LoadHistograms() |
222 | { | |
6bf0714d | 223 | // loads the histograms from a directory with the name of this class (retrieved from TNamed) |
224 | ||
5fbd0b17 | 225 | gDirectory->cd(GetName()); |
226 | ||
6bf0714d | 227 | fEtaVsVtx = dynamic_cast<TH2F*> (gDirectory->Get(fEtaVsVtx->GetName())); |
228 | fEtaVsVtxUncorrected = dynamic_cast<TH2F*> (gDirectory->Get(fEtaVsVtxUncorrected->GetName())); | |
5fbd0b17 | 229 | |
6bf0714d | 230 | fVtx = dynamic_cast<TH1D*> (gDirectory->Get(fVtx->GetName())); |
5fbd0b17 | 231 | |
232 | for (Int_t i=0; i<kVertexBinning; ++i) | |
6bf0714d | 233 | fdNdEta[i] = dynamic_cast<TH1D*> (gDirectory->Get(fdNdEta[i]->GetName())); |
5fbd0b17 | 234 | |
235 | gDirectory->cd("../"); | |
236 | } | |
237 | ||
ceb5d1b5 | 238 | //____________________________________________________________________ |
239 | void dNdEtaAnalysis::DrawHistograms() | |
240 | { | |
6bf0714d | 241 | // draws the histograms |
242 | ||
5fbd0b17 | 243 | TCanvas* canvas = new TCanvas("dNdEtaAnalysis", "dNdEtaAnalysis", 800, 800); |
244 | canvas->Divide(2, 2); | |
ceb5d1b5 | 245 | |
246 | canvas->cd(1); | |
6bf0714d | 247 | if (fEtaVsVtx) |
248 | fEtaVsVtx->Draw("COLZ"); | |
ceb5d1b5 | 249 | |
250 | canvas->cd(2); | |
6bf0714d | 251 | if (fEtaVsVtxUncorrected) |
252 | fEtaVsVtxUncorrected->Draw("COLZ"); | |
ceb5d1b5 | 253 | |
5fbd0b17 | 254 | canvas->cd(3); |
6bf0714d | 255 | if (fVtx) |
256 | fVtx->Draw(); | |
ceb5d1b5 | 257 | |
5fbd0b17 | 258 | canvas->cd(4); |
6bf0714d | 259 | if (fdNdEta[0]) |
260 | fdNdEta[0]->Draw(); | |
fcf2fb36 | 261 | |
262 | // histograms for different vertices? | |
263 | if (kVertexBinning > 0) | |
264 | { | |
265 | // doesnt work, but i dont get it, giving up... | |
266 | /*TCanvas* canvas2 =*/ new TCanvas("dNdEtaAnalysisVtx", "dNdEtaAnalysisVtx", 450, 450); | |
267 | //Int_t yPads = (Int_t) TMath::Ceil(((Double_t) kVertexBinning - 1) / 2); | |
268 | //printf("%d\n", yPads); | |
269 | //canvas2->Divide(2, yPads); | |
270 | ||
271 | TLegend* legend = new TLegend(0.7, 0.7, 0.9, 0.9); | |
272 | ||
5af55649 | 273 | for (Int_t i=0; i<kVertexBinning; ++i) |
fcf2fb36 | 274 | { |
275 | //canvas2->cd(i-1); | |
276 | //printf("%d\n", i); | |
6bf0714d | 277 | if (fdNdEta[i]) |
fcf2fb36 | 278 | { |
6bf0714d | 279 | fdNdEta[i]->SetLineColor(i+1); |
280 | fdNdEta[i]->Draw((i == 0) ? "" : "SAME"); | |
281 | legend->AddEntry(fdNdEta[i], (i == 0) ? "Vtx All" : Form("Vtx Bin %d", i-1)); | |
fcf2fb36 | 282 | } |
283 | } | |
284 | ||
285 | legend->Draw(); | |
286 | } | |
7029240a | 287 | } |
288 | ||
289 | Long64_t dNdEtaAnalysis::Merge(TCollection* list) | |
290 | { | |
291 | // Merges a list of dNdEtaAnalysis objects with this one. | |
292 | // This is needed for PROOF. | |
293 | // Returns the number of merged objects (including this) | |
294 | ||
295 | if (!list) | |
296 | return 0; | |
297 | ||
298 | if (list->IsEmpty()) | |
299 | return 1; | |
300 | ||
301 | TIterator* iter = list->MakeIterator(); | |
302 | TObject* obj; | |
303 | ||
304 | // sub collections | |
305 | const Int_t nCollections = kVertexBinning + 3; | |
306 | TList* collections[nCollections]; | |
307 | for (Int_t i=0; i<nCollections; ++i) | |
308 | collections[i] = new TList; | |
309 | ||
310 | Int_t count = 0; | |
311 | while ((obj = iter->Next())) | |
312 | { | |
313 | dNdEtaAnalysis* entry = dynamic_cast<dNdEtaAnalysis*> (obj); | |
314 | if (entry == 0) | |
315 | continue; | |
316 | ||
6bf0714d | 317 | collections[0]->Add(entry->fEtaVsVtx); |
318 | collections[1]->Add(entry->fEtaVsVtxUncorrected); | |
319 | collections[2]->Add(entry->fVtx); | |
7029240a | 320 | |
321 | for (Int_t i=0; i<kVertexBinning; ++i) | |
6bf0714d | 322 | collections[3+i]->Add(entry->fdNdEta[i]); |
7029240a | 323 | |
324 | ++count; | |
325 | } | |
326 | ||
6bf0714d | 327 | fEtaVsVtx->Merge(collections[0]); |
328 | fEtaVsVtxUncorrected->Merge(collections[1]); | |
329 | fVtx->Merge(collections[2]); | |
7029240a | 330 | for (Int_t i=0; i<kVertexBinning; ++i) |
6bf0714d | 331 | fdNdEta[i]->Merge(collections[3+i]); |
7029240a | 332 | |
333 | for (Int_t i=0; i<nCollections; ++i) | |
334 | delete collections[i]; | |
335 | ||
336 | return count+1; | |
ceb5d1b5 | 337 | } |