]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/dNdEta/dNdEtaAnalysis.cxx
- chi2ndf part of constructor (but what should be put there ??)
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / dNdEtaAnalysis.cxx
CommitLineData
dc740de4 1/* $Id$ */
2
75ec0f41 3#include "dNdEtaAnalysis.h"
4
ceb5d1b5 5#include <TFile.h>
45e97e28 6#include <TH3F.h>
74fd10b3 7#include <TH2F.h>
8#include <TH1F.h>
ceb5d1b5 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>
74fd10b3 15#include <TLine.h>
745d6088 16#include <TParameter.h>
fcf2fb36 17
45e97e28 18#include "AlidNdEtaCorrection.h"
74fd10b3 19#include <AliCorrection.h>
20#include <AliPWG0Helper.h>
21#include <AliCorrectionMatrix2D.h>
22#include <AliCorrectionMatrix3D.h>
ceb5d1b5 23
75ec0f41 24//____________________________________________________________________
b7f4a1fd 25ClassImp(dNdEtaAnalysis)
75ec0f41 26
1afae8ff 27//____________________________________________________________________
28dNdEtaAnalysis::dNdEtaAnalysis() :
29 TNamed(),
30 fData(0),
7307d52c 31 fMult(0),
745d6088 32 fPtDist(0),
33 fAnalysisMode(AliPWG0Helper::kInvalid),
34 fTag()
1afae8ff 35{
36 // default constructor
37
38 for (Int_t i=0; i<kVertexBinning; ++i)
39 {
40 fdNdEta[i] = 0;
41 fdNdEtaPtCutOffCorrected[i] = 0;
42 }
43}
44
75ec0f41 45//____________________________________________________________________
770a1f1d 46dNdEtaAnalysis::dNdEtaAnalysis(Char_t* name, Char_t* title, AliPWG0Helper::AnalysisMode analysisMode) :
16e24ca3 47 TNamed(name, title),
45e97e28 48 fData(0),
7307d52c 49 fMult(0),
745d6088 50 fPtDist(0),
51 fAnalysisMode(analysisMode),
52 fTag()
7029240a 53{
6bf0714d 54 // constructor
4dd2ad81 55
770a1f1d 56 fData = new AliCorrection("Analysis", Form("%s Analysis", title), analysisMode);
45e97e28 57
74fd10b3 58 // do not add this hists to the directory
59 Bool_t oldStatus = TH1::AddDirectoryStatus();
60 TH1::AddDirectory(kFALSE);
1afae8ff 61
7307d52c 62 fMult = new TH1F("TriggeredMultiplicity", "Triggered Events;raw multiplicity;entries", 1000, -0.5, 999.5);
63
567160d6 64 TH1* histForBinning = fData->GetTrackCorrection()->GetGeneratedHistogram();
65 fdNdEta[0] = new TH1F("dNdEta", "dN_{ch}/d#eta;#eta;dN_{ch}/d#eta", histForBinning->GetNbinsY(), histForBinning->GetYaxis()->GetXbins()->GetArray());
74fd10b3 66
67 fdNdEtaPtCutOffCorrected[0] = dynamic_cast<TH1F*> (fdNdEta[0]->Clone(Form("%s_corrected", fdNdEta[0]->GetName())));
1afae8ff 68
45e97e28 69 for (Int_t i=1; i<kVertexBinning; ++i)
7029240a 70 {
74fd10b3 71 fdNdEta[i] = dynamic_cast<TH1F*> (fdNdEta[0]->Clone(Form("%s_%d", fdNdEta[0]->GetName(), i)));
72 fdNdEtaPtCutOffCorrected[i] = dynamic_cast<TH1F*> (fdNdEtaPtCutOffCorrected[0]->Clone(Form("%s_%d", fdNdEtaPtCutOffCorrected[0]->GetName(), i)));
7029240a 73 }
75ec0f41 74
567160d6 75 fPtDist = new TH1F("Pt", "p_{T} distribution;p_{T} [GeV/c];#frac{dN}{d#eta dp_{T}} [c/GeV]", histForBinning->GetNbinsZ(), histForBinning->GetZaxis()->GetXbins()->GetArray());
74fd10b3 76
77 TH1::AddDirectory(oldStatus);
75ec0f41 78}
79
16e24ca3 80//____________________________________________________________________
81dNdEtaAnalysis::~dNdEtaAnalysis()
82{
83 // destructor
84
0ab29cfa 85 if (fData)
86 {
87 delete fData;
88 fData = 0;
89 }
16e24ca3 90
7307d52c 91 if (fMult)
92 {
93 delete fMult;
94 fMult = 0;
95 }
96
16e24ca3 97 for (Int_t i=0; i<kVertexBinning; ++i)
98 {
0ab29cfa 99 if (fdNdEta[i])
100 {
101 delete fdNdEta[i];
102 fdNdEta[i] = 0;
103 }
104 if (fdNdEtaPtCutOffCorrected[i])
105 {
106 delete fdNdEtaPtCutOffCorrected[i];
107 fdNdEtaPtCutOffCorrected[i] = 0;
108 }
16e24ca3 109 }
1afae8ff 110
0ab29cfa 111 if (fPtDist)
112 {
113 delete fPtDist;
114 fPtDist = 0;
115 }
16e24ca3 116}
117
118//_____________________________________________________________________________
119dNdEtaAnalysis::dNdEtaAnalysis(const dNdEtaAnalysis &c) :
120 TNamed(c),
45e97e28 121 fData(0),
c61a7285 122 fMult(0),
745d6088 123 fPtDist(0),
124 fAnalysisMode(AliPWG0Helper::kInvalid),
125 fTag()
16e24ca3 126{
127 //
128 // dNdEtaAnalysis copy constructor
129 //
130
131 ((dNdEtaAnalysis &) c).Copy(*this);
132}
133
134//_____________________________________________________________________________
135dNdEtaAnalysis &dNdEtaAnalysis::operator=(const dNdEtaAnalysis &c)
136{
137 //
138 // Assignment operator
139 //
140
141 if (this != &c) ((dNdEtaAnalysis &) c).Copy(*this);
142 return *this;
143}
144
145//_____________________________________________________________________________
146void dNdEtaAnalysis::Copy(TObject &c) const
147{
148 //
149 // Copy function
150 //
151
152 dNdEtaAnalysis& target = (dNdEtaAnalysis &) c;
153
74fd10b3 154 target.fData = dynamic_cast<AliCorrection*> (fData->Clone());
7307d52c 155 target.fMult = dynamic_cast<TH1F*> (fMult->Clone());
16e24ca3 156
157 for (Int_t i=0; i<kVertexBinning; ++i)
1afae8ff 158 {
74fd10b3 159 target.fdNdEta[i] = dynamic_cast<TH1F*> (fdNdEta[i]->Clone());
160 target.fdNdEtaPtCutOffCorrected[i] = dynamic_cast<TH1F*> (fdNdEtaPtCutOffCorrected[i]->Clone());
1afae8ff 161 }
16e24ca3 162
74fd10b3 163 target.fPtDist = dynamic_cast<TH1F*> (fPtDist->Clone());
45e97e28 164
745d6088 165 target.fAnalysisMode = fAnalysisMode;
166 target.fTag = fTag;
167
16e24ca3 168 TNamed::Copy((TNamed &) c);
169}
170
75ec0f41 171//____________________________________________________________________
74fd10b3 172void dNdEtaAnalysis::FillTrack(Float_t vtx, Float_t eta, Float_t pt)
6bf0714d 173{
174 // fills a track into the histograms
175
74fd10b3 176 fData->GetTrackCorrection()->FillMeas(vtx, eta, pt);
75ec0f41 177}
178
179//____________________________________________________________________
74fd10b3 180void dNdEtaAnalysis::FillEvent(Float_t vtx, Float_t n)
6bf0714d 181{
182 // fills an event into the histograms
183
74fd10b3 184 fData->GetEventCorrection()->FillMeas(vtx, n);
75ec0f41 185}
186
7307d52c 187//____________________________________________________________________
188void dNdEtaAnalysis::FillTriggeredEvent(Float_t n)
189{
190 // fills a triggered event into the histograms
191
192 fMult->Fill(n);
193}
194
75ec0f41 195//____________________________________________________________________
0fc41645 196void dNdEtaAnalysis::Finish(AlidNdEtaCorrection* correction, Float_t ptCut, AlidNdEtaCorrection::CorrectionType correctionType, const char* tag)
fcf2fb36 197{
74fd10b3 198 //
199 // correct with the given correction values and calculate dNdEta and pT distribution
200 // the corrections that are applied can be steered by the flag correctionType
3dfa46a4 201 // the measured result is not used up to a multiplicity of multCut (the bin at multCut is the first that is used!)
74fd10b3 202 //
203
745d6088 204 fTag.Form("Correcting dN/deta spectrum >>> %s <<<. Correction type: %d, pt cut: %.2f.", tag, (Int_t) correctionType, ptCut);
205 Printf("\n\n%s", fTag.Data());
3dfa46a4 206
74fd10b3 207 // set corrections to 1
208 fData->SetCorrectionToUnity();
209
210 if (correction && correctionType != AlidNdEtaCorrection::kNone)
211 {
212 TH3F* trackCorr = fData->GetTrackCorrection()->GetCorrectionHistogram();
213 TH2F* eventCorr = fData->GetEventCorrection()->GetCorrectionHistogram();
214
215 if (correctionType >= AlidNdEtaCorrection::kTrack2Particle)
216 trackCorr->Multiply(correction->GetTrack2ParticleCorrection()->GetTrackCorrection()->GetCorrectionHistogram());
6bf0714d 217
dd367a14 218 if (correctionType >= AlidNdEtaCorrection::kVertexReco)
74fd10b3 219 {
220 trackCorr->Multiply(correction->GetVertexRecoCorrection()->GetTrackCorrection()->GetCorrectionHistogram());
221 eventCorr->Multiply(correction->GetVertexRecoCorrection()->GetEventCorrection()->GetCorrectionHistogram());
7307d52c 222
0fc41645 223 // set bin with multiplicity 0 to unity (correction has no meaning in this bin)
7307d52c 224 for (Int_t i=0; i<=eventCorr->GetNbinsX()+1; i++)
225 eventCorr->SetBinContent(i, 1, 1);
dd367a14 226 }
74fd10b3 227
228 switch (correctionType)
229 {
230 case AlidNdEtaCorrection::kINEL :
231 {
232 trackCorr->Multiply(correction->GetTriggerBiasCorrectionINEL()->GetTrackCorrection()->GetCorrectionHistogram());
233 eventCorr->Multiply(correction->GetTriggerBiasCorrectionINEL()->GetEventCorrection()->GetCorrectionHistogram());
234 break;
235 }
236 case AlidNdEtaCorrection::kNSD :
237 {
238 trackCorr->Multiply(correction->GetTriggerBiasCorrectionNSD()->GetTrackCorrection()->GetCorrectionHistogram());
239 eventCorr->Multiply(correction->GetTriggerBiasCorrectionNSD()->GetEventCorrection()->GetCorrectionHistogram());
240 break;
241 }
242 case AlidNdEtaCorrection::kND :
243 {
244 trackCorr->Multiply(correction->GetTriggerBiasCorrectionND()->GetTrackCorrection()->GetCorrectionHistogram());
245 eventCorr->Multiply(correction->GetTriggerBiasCorrectionND()->GetEventCorrection()->GetCorrectionHistogram());
246 break;
247 }
248 default : break;
249 }
250 }
251 else
fcf2fb36 252 printf("INFO: No correction applied\n");
253
567160d6 254 TH2F* rawMeasured = (TH2F*) fData->GetEventCorrection()->GetMeasuredHistogram()->Clone("rawMeasured");
255
74fd10b3 256 fData->Multiply();
7307d52c 257
258 if (correctionType >= AlidNdEtaCorrection::kVertexReco)
259 {
260 // There are no events with vertex that have 0 multiplicity, therefore
261 // populate bin with 0 multiplicity with the following idea:
262 // alpha = triggered events with vertex at a given vertex position / all triggered events with vertex
263 // triggered events without vertex and 0 multiplicity at a given vertex position = alpha * all triggered events with 0 multiplicity
264 // afterwards we still correct for the trigger efficiency
265
567160d6 266 //TH2* measuredEvents = fData->GetEventCorrection()->GetMeasuredHistogram();
7307d52c 267 TH2* correctedEvents = fData->GetEventCorrection()->GetGeneratedHistogram();
268
567160d6 269 TH2* eTrig = correction->GetVertexRecoCorrection()->GetEventCorrection()->GetGeneratedHistogram();
270 TH2* eTrigVtx = correction->GetVertexRecoCorrection()->GetEventCorrection()->GetMeasuredHistogram();
271 TH1* eTrigVtx_projx = eTrigVtx->ProjectionX("eTrigVtx_projx", 2, rawMeasured->GetNbinsY()+1);
272
7307d52c 273 //new TCanvas; correctedEvents->DrawCopy("TEXT");
274
275 // start above 0 mult. bin with integration
567160d6 276 TH1* vertexDist = rawMeasured->ProjectionX("vertexdist_measured", 2, rawMeasured->GetNbinsY()+1);
7307d52c 277 //new TCanvas; vertexDist->DrawCopy();
278
279 Int_t allEventsWithVertex = (Int_t) vertexDist->Integral(0, vertexDist->GetNbinsX()+1); // include under/overflow!
280 Int_t triggeredEventsWith0Mult = (Int_t) fMult->GetBinContent(1);
281
282 Printf("%d triggered events with 0 mult. -- %d triggered events with vertex", triggeredEventsWith0Mult, allEventsWithVertex);
283
567160d6 284 for (Int_t i = 1; i <= rawMeasured->GetNbinsX(); i++)
7307d52c 285 {
745d6088 286 Double_t alpha = (Double_t) vertexDist->GetBinContent(i) / allEventsWithVertex;
7307d52c 287 Double_t events = alpha * triggeredEventsWith0Mult;
288
567160d6 289 if (eTrigVtx_projx->GetBinContent(i) == 0)
290 continue;
291
292 Double_t fZ = eTrigVtx_projx->Integral(0, eTrigVtx_projx->GetNbinsX()+1) / eTrigVtx_projx->GetBinContent(i) *
293 eTrig->GetBinContent(i, 1) / eTrig->Integral(0, eTrig->GetNbinsX()+1, 1, 1);
294
295 events *= fZ;
296
7307d52c 297 // multiply with trigger correction if set above
298 events *= fData->GetEventCorrection()->GetCorrectionHistogram()->GetBinContent(i, 1);
299
567160d6 300 Printf("Bin %d, alpha is %.2f, fZ is %.3f, number of events with 0 mult.: %.2f", i, alpha * 100., fZ, events);
7307d52c 301
302 correctedEvents->SetBinContent(i, 1, events);
303 }
304
305 //new TCanvas; correctedEvents->DrawCopy("TEXT");
306 }
307
3dfa46a4 308 fData->PrintInfo(ptCut);
74fd10b3 309
310 TH3F* dataHist = fData->GetTrackCorrection()->GetGeneratedHistogram();
311
312 // integrate multiplicity axis out (include under/overflow bins!!!)
313 TH2F* tmp = fData->GetEventCorrection()->GetGeneratedHistogram();
3dfa46a4 314
7307d52c 315 TH1D* vertexHist = (TH1D*) tmp->ProjectionX("_px", 0, tmp->GetNbinsY() + 1, "e");
fcf2fb36 316
1afae8ff 317 // create pt hist
318 {
319 // reset all ranges
74fd10b3 320 dataHist->GetXaxis()->SetRange(0, 0);
321 dataHist->GetYaxis()->SetRange(0, 0);
322 dataHist->GetZaxis()->SetRange(0, 0);
1afae8ff 323
324 // vtx cut
74fd10b3 325 Int_t vertexBinBegin = dataHist->GetXaxis()->FindBin(-5);
326 Int_t vertexBinEnd = dataHist->GetXaxis()->FindBin(5);
327 dataHist->GetXaxis()->SetRange(vertexBinBegin, vertexBinEnd);
328 Float_t nEvents = vertexHist->Integral(vertexBinBegin, vertexBinEnd);
1afae8ff 329
74fd10b3 330 if (nEvents > 0)
331 {
332 // eta cut
333 dataHist->GetYaxis()->SetRange(dataHist->GetYaxis()->FindBin(-0.8), dataHist->GetYaxis()->FindBin(0.8));
334 Float_t etaWidth = 1.6;
1afae8ff 335
74fd10b3 336 TH1D* ptHist = dynamic_cast<TH1D*> (dataHist->Project3D("ze"));
1afae8ff 337
74fd10b3 338 for (Int_t i=1; i<=fPtDist->GetNbinsX(); ++i)
339 {
340 Float_t binSize = fPtDist->GetBinWidth(i);
341 fPtDist->SetBinContent(i, ptHist->GetBinContent(i) / binSize / nEvents / etaWidth);
342 fPtDist->SetBinError(i, ptHist->GetBinError(i) / binSize / nEvents / etaWidth);
343 }
1afae8ff 344
74fd10b3 345 delete ptHist;
346 }
347 else
348 printf("ERROR: nEvents is 0!\n");
1afae8ff 349 }
350
351 // reset all ranges
74fd10b3 352 dataHist->GetXaxis()->SetRange(0, 0);
353 dataHist->GetYaxis()->SetRange(0, 0);
354 dataHist->GetZaxis()->SetRange(0, 0);
1afae8ff 355
847489f7 356 // integrate over pt (with pt cut)
1afae8ff 357 Int_t ptLowBin = 1;
358 if (ptCut > 0)
74fd10b3 359 ptLowBin = dataHist->GetZaxis()->FindBin(ptCut);
1afae8ff 360
7307d52c 361 dataHist->GetZaxis()->SetRange(ptLowBin, dataHist->GetZaxis()->GetNbins()+1);
362 printf("pt range %d %d\n", ptLowBin, dataHist->GetZaxis()->GetNbins()+1);
74fd10b3 363 TH2D* vtxVsEta = dynamic_cast<TH2D*> (dataHist->Project3D("yx2e"));
364
365 dataHist->GetZaxis()->SetRange(0, 0);
366 vtxVsEta->GetXaxis()->SetTitle(dataHist->GetXaxis()->GetTitle());
367 vtxVsEta->GetYaxis()->SetTitle(dataHist->GetYaxis()->GetTitle());
1afae8ff 368
847489f7 369 if (vtxVsEta == 0)
370 {
371 printf("ERROR: pt integration failed\n");
372 return;
fcf2fb36 373 }
374
567160d6 375 // clear result histograms
376 for (Int_t vertexPos=0; vertexPos<kVertexBinning; ++vertexPos)
377 {
378 fdNdEta[vertexPos]->Reset();
379 fdNdEtaPtCutOffCorrected[vertexPos]->Reset();
380 }
144ff489 381
567160d6 382 const Float_t vertexRangeBegin[kVertexBinning] = { -9.99, -9.99, 0.01 };
383 const Float_t vertexRangeEnd[kVertexBinning] = { 9.99, -0.01, 9.99 };
b4b9cacc 384
74fd10b3 385 for (Int_t iEta=1; iEta<=vtxVsEta->GetNbinsY(); iEta++)
5af55649 386 {
745d6088 387 // loop over vertex ranges
7029240a 388 for (Int_t vertexPos=0; vertexPos<kVertexBinning; ++vertexPos)
389 {
745d6088 390 Int_t vertexBinBegin = vertexHist->GetXaxis()->FindBin(vertexRangeBegin[vertexPos]);
391 Int_t vertexBinEnd = vertexHist->GetXaxis()->FindBin(vertexRangeEnd[vertexPos]);
fcf2fb36 392
ea441adf 393 const Int_t *binBegin = 0;
567160d6 394 // adjust acceptance range for SPD
745d6088 395 if (fAnalysisMode == AliPWG0Helper::kSPD)
fcf2fb36 396 {
1cbdb1a6 397 //const Int_t binBegin[30] = { 18, 16, 15, 14, 13, 13, 12, 11, 9, 7, 6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 1 };
ea441adf 398 const Int_t binBeginSPD[30] = { -1, -1, -1, -1, 16, 14, 12, 10, 9, 7, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, -1, -1, -1, -1}; // limit in correction map is 5
1cbdb1a6 399 //const Int_t binBegin[30] = { -1, -1, -1, 17, 15, 14, 12, 10, 8, 7, 6, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, -1, -1, -1}; // limit in correction map is 10
ea441adf 400 binBegin = binBeginSPD;
567160d6 401
fcf2fb36 402 }
ea441adf 403 else if (fAnalysisMode == AliPWG0Helper::kTPC)
404 {
405// const Int_t binBegin[30] = { -1, -1, -1, -1, 16, 14, 12, 10, 9, 7, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2, 2, 2, -1, -1, -1, -1}; // limit in correction map is 5
406 const Int_t binBeginTPC[30] = {-1, -1, -1, -1, -1, -1, -1, -1, 9, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1};
407 binBegin = binBeginTPC;
408 }
409 else if (fAnalysisMode == AliPWG0Helper::kTPCITS)
410 {
411 // TODO create map
412 }
413
414 Int_t vtxBegin = binBegin[iEta - 1];
415 Int_t vtxEnd = 18 + 1 - binBegin[30 - iEta];
416
417 // eta range not accessible
418 if (vtxBegin == -1)
419 continue;
420
421 //Float_t eta = vtxVsEta->GetYaxis()->GetBinCenter(iEta);
422 //Printf("%d %d | %d %d", vtxBegin, vertexHist->GetXaxis()->FindBin(GetVtxMin(eta)), vtxEnd, vertexHist->GetXaxis()->FindBin(-GetVtxMin(-eta)));
423 //vtxBegin = vertexHist->GetXaxis()->FindBin(GetVtxMin(eta));
424 //vtxEnd = vertexHist->GetXaxis()->FindBin(-GetVtxMin(-eta));
425 //printf("Eta bin: %d (%f) Vertex range: %d; before: %d %d ", iEta, eta, vertexPos, vertexBinBegin, vertexBinEnd);
426 vertexBinBegin = TMath::Max(vertexBinBegin, vtxBegin);
427 vertexBinEnd = TMath::Min(vertexBinEnd, vtxEnd);
428 //Printf("after: %d %d", vertexBinBegin, vertexBinEnd);
7029240a 429
745d6088 430 // no data for this bin
431 if (vertexBinBegin > vertexBinEnd)
567160d6 432 {
433 //Printf("Bin empty. Skipped");
745d6088 434 continue;
567160d6 435 }
b4b9cacc 436
745d6088 437 Float_t totalEvents = vertexHist->Integral(vertexBinBegin, vertexBinEnd);
5af55649 438 if (totalEvents == 0)
439 {
440 printf("WARNING: No events for hist %d %d %d\n", vertexPos, vertexBinBegin, vertexBinEnd);
441 continue;
7029240a 442 }
7029240a 443
5af55649 444 Float_t sum = 0;
445 Float_t sumError2 = 0;
745d6088 446 for (Int_t iVtx = vertexBinBegin; iVtx <= vertexBinEnd; iVtx++)
567160d6 447 {
144ff489 448 if (vtxVsEta->GetBinContent(iVtx, iEta) != 0)
5af55649 449 {
847489f7 450 sum = sum + vtxVsEta->GetBinContent(iVtx, iEta);
2e88424e 451
745d6088 452 if (sumError2 > 10e30)
453 Printf("WARNING: sum of error2 is dangerously large - be prepared for crash... ");
2e88424e 454
847489f7 455 sumError2 = sumError2 + TMath::Power(vtxVsEta->GetBinError(iVtx, iEta),2);
5af55649 456 }
457 }
7029240a 458
1afae8ff 459 Float_t ptCutOffCorrection = 1;
74fd10b3 460 if (correction && ptCut > 0)
461 ptCutOffCorrection = correction->GetMeasuredFraction(correctionType, ptCut, vtxVsEta->GetYaxis()->GetBinCenter(iEta));
1afae8ff 462
847489f7 463 if (ptCutOffCorrection <= 0)
464 {
465 printf("UNEXPECTED: ptCutOffCorrection is %f for hist %d %d %d\n", ptCutOffCorrection, vertexPos, vertexBinBegin, vertexBinEnd);
466 continue;
467 }
468
9e952c39 469 //printf("Eta: %d Vertex Range: %d %d, Event Count %f, Track Sum: %f, Track Sum corrected: %f\n", iEta, vertexBinBegin, vertexBinEnd, totalEvents, sum, sum / ptCutOffCorrection);
470
144ff489 471 Int_t bin = fdNdEta[vertexPos]->FindBin(vtxVsEta->GetYaxis()->GetBinCenter(iEta));
745d6088 472 if (bin > 0 && bin <= fdNdEta[vertexPos]->GetNbinsX())
144ff489 473 {
7307d52c 474 Float_t dndeta = sum / totalEvents;
475 Float_t error = TMath::Sqrt(sumError2) / totalEvents;
7029240a 476
144ff489 477 dndeta = dndeta / fdNdEta[vertexPos]->GetBinWidth(bin);
478 error = error / fdNdEta[vertexPos]->GetBinWidth(bin);
7029240a 479
144ff489 480 fdNdEta[vertexPos]->SetBinContent(bin, dndeta);
481 fdNdEta[vertexPos]->SetBinError(bin, error);
1afae8ff 482
144ff489 483 dndeta /= ptCutOffCorrection;
484 error /= ptCutOffCorrection;
1afae8ff 485
144ff489 486 fdNdEtaPtCutOffCorrected[vertexPos]->SetBinContent(bin, dndeta);
487 fdNdEtaPtCutOffCorrected[vertexPos]->SetBinError(bin, error);
2e88424e 488
567160d6 489 //Printf("Bin %d has dN/deta = %f +- %f; %f +- %f", bin, dndeta, error, fdNdEta[vertexPos]->GetBinContent(bin), fdNdEta[vertexPos]->GetBinError(bin));
144ff489 490 }
75ec0f41 491 }
847489f7 492 }
75ec0f41 493}
494
567160d6 495//____________________________________________________________________
496Float_t dNdEtaAnalysis::GetVtxMin(Float_t eta)
497{
498 // helper function for the SPD acceptance
499 // the function returns the beginning of the acceptance window in z vertex position as function of eta
500 // to get the maximum: -GetVtxMin(-eta)
501
502 Float_t a[2] = { -15, 0 };
503 Float_t b[2] = { 0, -1.4 };
504 Float_t c[2] = { 15, -2.2 };
505
506 Float_t meanAB[2];
507 meanAB[0] = (b[0] + a[0]) / 2;
508 meanAB[1] = (b[1] + a[1]) / 2;
509
510 Float_t meanBC[2];
511 meanBC[0] = (c[0] + b[0]) / 2;
512 meanBC[1] = (c[1] + b[1]) / 2;
513
514 Float_t mAB = (b[1] - a[1]) / (b[0] - a[0]);
515 Float_t mBC = (c[1] - b[1]) / (c[0] - b[0]);
516
517 Float_t bAB = meanAB[1] - mAB * meanAB[0];
518 Float_t bBC = meanBC[1] - mBC * meanBC[0];
519
520 if (eta > b[1])
521 return 1.0 / mAB * eta - bAB / mAB;
522
523 return 1.0 / mBC * eta - bBC / mBC;
524}
525
75ec0f41 526//____________________________________________________________________
6bf0714d 527void dNdEtaAnalysis::SaveHistograms()
528{
529 // save the histograms to a directory with the name of this class (retrieved from TNamed)
75ec0f41 530
7029240a 531 gDirectory->mkdir(GetName());
532 gDirectory->cd(GetName());
5fbd0b17 533
1afae8ff 534 if (fData)
535 {
74fd10b3 536 fData->SaveHistograms();
1afae8ff 537 }
538 else
539 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fData is 0\n");
540
7307d52c 541 if (fMult)
542 {
543 fMult->Write();
544 }
545 else
546 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fMult is 0\n");
547
d09fb536 548 if (fPtDist)
549 fPtDist ->Write();
550 else
551 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fPtDist is 0\n");
552
7029240a 553 for (Int_t i=0; i<kVertexBinning; ++i)
1afae8ff 554 {
555 if (fdNdEta[i])
556 fdNdEta[i]->Write();
557 else
558 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fdNdEta[%d] is 0\n", i);
559
560 if (fdNdEtaPtCutOffCorrected[i])
561 fdNdEtaPtCutOffCorrected[i]->Write();
562 else
563 printf("dNdEtaAnalysis::SaveHistograms: UNEXPECTED: fdNdEtaPtCutOffCorrected[%d] is 0\n", i);
564 }
75ec0f41 565
745d6088 566 TNamed named("fTag", fTag.Data());
567 named.Write();
568
569 TParameter<Int_t> param("fAnalysisMode", fAnalysisMode);
570 param.Write();
571
75ec0f41 572 gDirectory->cd("../");
573}
574
74fd10b3 575void dNdEtaAnalysis::LoadHistograms(const Char_t* dir)
5fbd0b17 576{
6bf0714d 577 // loads the histograms from a directory with the name of this class (retrieved from TNamed)
578
74fd10b3 579 if (!dir)
580 dir = GetName();
5fbd0b17 581
74fd10b3 582 gDirectory->cd(dir);
5fbd0b17 583
74fd10b3 584 fData->LoadHistograms();
7307d52c 585 fMult = dynamic_cast<TH1F*> (gDirectory->Get(fMult->GetName()));
5fbd0b17 586
587 for (Int_t i=0; i<kVertexBinning; ++i)
1afae8ff 588 {
74fd10b3 589 fdNdEta[i] = dynamic_cast<TH1F*> (gDirectory->Get(fdNdEta[i]->GetName()));
590 fdNdEtaPtCutOffCorrected[i] = dynamic_cast<TH1F*> (gDirectory->Get(fdNdEtaPtCutOffCorrected[i]->GetName()));
1afae8ff 591 }
5fbd0b17 592
74fd10b3 593 fPtDist = dynamic_cast<TH1F*> (gDirectory->Get(fPtDist->GetName()));
0ab29cfa 594
745d6088 595 if (dynamic_cast<TNamed*> (gFile->Get("fTag")))
596 fTag = (dynamic_cast<TNamed*> (gFile->Get("fTag")))->GetTitle();
597
598 if (dynamic_cast<TParameter<Int_t>*> (gFile->Get("fAnalysisMode")))
599 fAnalysisMode = (AliPWG0Helper::AnalysisMode) (dynamic_cast<TParameter<Int_t>*> (gFile->Get("fAnalysisMode")))->GetVal();
600
5fbd0b17 601 gDirectory->cd("../");
602}
603
ceb5d1b5 604//____________________________________________________________________
74fd10b3 605void dNdEtaAnalysis::DrawHistograms(Bool_t simple)
ceb5d1b5 606{
6bf0714d 607 // draws the histograms
7307d52c 608
74fd10b3 609 if (!simple)
610 {
611 if (fData)
612 fData->DrawHistograms(GetName());
6bf0714d 613
74fd10b3 614 TCanvas* canvas = new TCanvas(Form("%s_dNdEtaAnalysis", GetName()), Form("%s_dNdEtaAnalysis", GetName()), 800, 400);
615 canvas->Divide(2, 1);
ceb5d1b5 616
74fd10b3 617 canvas->cd(1);
618 if (fdNdEtaPtCutOffCorrected[0])
144ff489 619 fdNdEtaPtCutOffCorrected[0]->DrawCopy();
ceb5d1b5 620
74fd10b3 621 if (fdNdEta[0])
622 {
623 fdNdEta[0]->SetLineColor(kRed);
144ff489 624 fdNdEta[0]->DrawCopy("SAME");
74fd10b3 625 }
1afae8ff 626
74fd10b3 627 canvas->cd(2);
628 if (fPtDist)
144ff489 629 fPtDist->DrawCopy();
1afae8ff 630 }
631
fcf2fb36 632 // histograms for different vertices?
633 if (kVertexBinning > 0)
634 {
635 // doesnt work, but i dont get it, giving up...
74fd10b3 636 TCanvas* canvas2 = new TCanvas(Form("%s_dNdEtaAnalysisVtx", GetName()), Form("%s_dNdEtaAnalysisVtx", GetName()), 450, 450);
637 TCanvas* canvas3 = 0;
638 if (!simple)
639 canvas3 = new TCanvas(Form("%s_dNdEtaAnalysisVtx_noptcutoff", GetName()), Form("%s_dNdEtaAnalysisVtx_noptcutoff", GetName()), 450, 450);
640
fcf2fb36 641 //Int_t yPads = (Int_t) TMath::Ceil(((Double_t) kVertexBinning - 1) / 2);
642 //printf("%d\n", yPads);
643 //canvas2->Divide(2, yPads);
644
0448e811 645 TLegend* legend = new TLegend(0.4, 0.2, 0.6, 0.4);
fcf2fb36 646
5af55649 647 for (Int_t i=0; i<kVertexBinning; ++i)
fcf2fb36 648 {
1afae8ff 649 if (fdNdEtaPtCutOffCorrected[i])
fcf2fb36 650 {
74fd10b3 651 canvas2->cd();
652
1afae8ff 653 fdNdEtaPtCutOffCorrected[i]->SetLineColor(i+1);
144ff489 654 fdNdEtaPtCutOffCorrected[i]->DrawCopy((i == 0) ? "" : "SAME");
1afae8ff 655 legend->AddEntry(fdNdEtaPtCutOffCorrected[i], (i == 0) ? "Vtx All" : Form("Vtx Bin %d", i-1));
fcf2fb36 656 }
74fd10b3 657 if (canvas3 && fdNdEta[i])
658 {
659 canvas3->cd();
660
661 fdNdEta[i]->SetLineColor(i+1);
144ff489 662 fdNdEta[i]->DrawCopy((i == 0) ? "" : "SAME");
74fd10b3 663 }
fcf2fb36 664 }
665
74fd10b3 666 canvas2->cd();
fcf2fb36 667 legend->Draw();
74fd10b3 668 canvas2->SaveAs(Form("%s_%s.gif", canvas2->GetName(), GetName()));
669
670 if (canvas3)
671 {
672 canvas3->cd();
673 legend->Draw();
674 }
fcf2fb36 675 }
7307d52c 676
74fd10b3 677 if (kVertexBinning == 3)
678 {
679 TH1* clone = dynamic_cast<TH1*> (fdNdEtaPtCutOffCorrected[1]->Clone("clone"));
680 TH1* clone2 = dynamic_cast<TH1*> (fdNdEtaPtCutOffCorrected[2]->Clone("clone2"));
7307d52c 681
74fd10b3 682 if (clone && clone2)
683 {
684 TCanvas* canvas4 = new TCanvas(Form("%s_dNdEtaAnalysisVtxRatios", GetName()), Form("%s_dNdEtaAnalysisVtxRatios", GetName()), 450, 450);
7307d52c 685
74fd10b3 686 clone->Divide(fdNdEtaPtCutOffCorrected[0]);
687 clone->GetYaxis()->SetRangeUser(0.95, 1.05);
144ff489 688 clone->DrawCopy();
7307d52c 689
74fd10b3 690 clone2->Divide(fdNdEtaPtCutOffCorrected[0]);
144ff489 691 clone2->DrawCopy("SAME");
74fd10b3 692
693 TLine* line = new TLine(-1, 1, 1, 1);
694 line->Draw();
695
696 canvas4->SaveAs(Form("%s_%s.gif", canvas4->GetName(), GetName()));
697 }
698 }
7029240a 699}
700
701Long64_t dNdEtaAnalysis::Merge(TCollection* list)
702{
703 // Merges a list of dNdEtaAnalysis objects with this one.
704 // This is needed for PROOF.
705 // Returns the number of merged objects (including this)
706
707 if (!list)
708 return 0;
709
710 if (list->IsEmpty())
711 return 1;
712
713 TIterator* iter = list->MakeIterator();
714 TObject* obj;
715
716 // sub collections
7307d52c 717 const Int_t nCollections = 2 * kVertexBinning + 3; // 3 standalone hists, 3 arrays of size kVertexBinning
7029240a 718 TList* collections[nCollections];
719 for (Int_t i=0; i<nCollections; ++i)
720 collections[i] = new TList;
721
722 Int_t count = 0;
723 while ((obj = iter->Next()))
724 {
725 dNdEtaAnalysis* entry = dynamic_cast<dNdEtaAnalysis*> (obj);
726 if (entry == 0)
727 continue;
728
45e97e28 729 collections[0]->Add(entry->fData);
0fc41645 730 collections[1]->Add(entry->fMult);
731 collections[2]->Add(entry->fPtDist);
7029240a 732
733 for (Int_t i=0; i<kVertexBinning; ++i)
1afae8ff 734 {
7307d52c 735 collections[3+i]->Add(entry->fdNdEta[i]);
736 collections[3+kVertexBinning+i]->Add(entry->fdNdEtaPtCutOffCorrected[i]);
1afae8ff 737 }
7029240a 738
739 ++count;
740 }
741
45e97e28 742 fData->Merge(collections[0]);
7307d52c 743 fMult->Merge(collections[1]);
744 fPtDist->Merge(collections[2]);
745
7029240a 746 for (Int_t i=0; i<kVertexBinning; ++i)
1afae8ff 747 {
7307d52c 748 fdNdEta[i]->Merge(collections[3+i]);
749 fdNdEtaPtCutOffCorrected[i]->Merge(collections[3+kVertexBinning+i]);
1afae8ff 750 }
7029240a 751
752 for (Int_t i=0; i<nCollections; ++i)
753 delete collections[i];
754
755 return count+1;
ceb5d1b5 756}
567160d6 757
758