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