implemented destructors
[u/mrichter/AliRoot.git] / PWG0 / dNdEta / AlidNdEtaCorrection.cxx
CommitLineData
55e05544 1/* $Id$ */
2
3#include "AlidNdEtaCorrection.h"
4
5#include <TCanvas.h>
847489f7 6#include <TH3F.h>
7#include <TH1D.h>
55e05544 8
9//____________________________________________________________________
10ClassImp(AlidNdEtaCorrection)
11
12//____________________________________________________________________
8b3563f4 13AlidNdEtaCorrection::AlidNdEtaCorrection()
14 : TNamed(),
15 fTrack2ParticleCorrection(0),
16 fVertexRecoCorrection(0),
17 fTriggerCorrection(0),
18 fTriggerBiasCorrection(0),
45e97e28 19 fNEvents(0),
20 fNTriggeredEvents(0)
8b3563f4 21{
22 // default constructor
23}
24
25//____________________________________________________________________
26AlidNdEtaCorrection::AlidNdEtaCorrection(const Char_t* name, const Char_t* title)
27 : TNamed(name, title),
38233af1 28 fTrack2ParticleCorrection(0),
29 fVertexRecoCorrection(0),
30 fTriggerCorrection(0),
31 fTriggerBiasCorrection(0),
8b3563f4 32 fNEvents(0),
33 fNTriggeredEvents(0)
34{
55e05544 35 // constructor
36 //
37
1afae8ff 38 Float_t binLimitsPt[] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.5, 2.0, 10.0, 100.0};
55e05544 39
1afae8ff 40 fTrack2ParticleCorrection = new AliCorrectionMatrix3D("nTrackToNPart", "nTrackToNPart", 40, -20, 20, 60, -6, 6, 14, binLimitsPt);
41
42 Float_t binLimitsN[] = {-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5,
55e05544 43 10.5, 12.5, 14.5, 16.5, 18.5, 20.5, 25.5, 30.5, 40.5, 50.5, 100.5, 300.5};
44 Float_t binLimitsVtx[] = {-20,-15,-10,-6,-3,0,3,6,10,15,20};
1afae8ff 45
45e97e28 46 fVertexRecoCorrection = new AliCorrectionMatrix2D("vtxReco", "vtxReco",10,binLimitsVtx ,22,binLimitsN);
1afae8ff 47 fTriggerCorrection = new AliCorrectionMatrix2D("trigger", "trigger",10,binLimitsVtx ,22,binLimitsN);
55e05544 48
45e97e28 49 fTriggerBiasCorrection = new AliCorrectionMatrix2D("triggerBias", "triggerBias",120,-6,6,100, 0, 10);
55e05544 50
92d2d8ad 51 fTrack2ParticleCorrection ->SetAxisTitles("vtx z [cm]", "#eta", "p_{T} [GeV/c]");
52 fVertexRecoCorrection ->SetAxisTitles("vtx z [cm]", "Ntracks");
53 fTriggerCorrection ->SetAxisTitles("vtx z [cm]", "Ntracks");
45e97e28 54
55e05544 55 fTriggerBiasCorrection ->SetAxisTitles("#eta", "p_{T} [GeV/c]");
56}
57
38233af1 58//____________________________________________________________________
59AlidNdEtaCorrection::~AlidNdEtaCorrection()
60{
61 // destructor
62
63 if (fTrack2ParticleCorrection)
64 {
65 delete fTrack2ParticleCorrection;
66 fTrack2ParticleCorrection = 0;
67 }
68
69 if (fVertexRecoCorrection)
70 {
71 delete fVertexRecoCorrection;
72 fVertexRecoCorrection = 0;
73 }
74
75 if (fTriggerCorrection)
76 {
77 delete fTriggerCorrection;
78 fTriggerCorrection = 0;
79 }
80
81 if (fTriggerBiasCorrection)
82 {
83 delete fTriggerBiasCorrection;
84 fTriggerBiasCorrection = 0;
85 }
86}
87
55e05544 88//____________________________________________________________________
89void
45e97e28 90AlidNdEtaCorrection::Finish() {
55e05544 91 //
92 // finish method
93 //
45e97e28 94 // divide the histograms in the AliCorrectionMatrix2D objects to get the corrections
55e05544 95
45e97e28 96 fTrack2ParticleCorrection->Divide();
55e05544 97
1afae8ff 98 TH3F* hist = fTrack2ParticleCorrection->GetCorrectionHistogram();
99 Int_t emptyBins = 0;
100 for (Int_t x=hist->GetXaxis()->FindBin(-10); x<=hist->GetXaxis()->FindBin(10); ++x)
101 for (Int_t y=hist->GetYaxis()->FindBin(-0.8); y<=hist->GetYaxis()->FindBin(0.8); ++y)
102 for (Int_t z=hist->GetZaxis()->FindBin(0.3); z<=hist->GetZaxis()->FindBin(9.9); ++z)
103 if (hist->GetBinContent(x, y, z) == 0)
104 {
105 printf("Empty bin in fTrack2ParticleCorrection at vtx = %f, eta = %f, pt = %f\n", hist->GetXaxis()->GetBinCenter(x), hist->GetYaxis()->GetBinCenter(y), hist->GetZaxis()->GetBinCenter(z));
106 ++emptyBins;
107 }
108
109 printf("INFO: In the central region fTrack2ParticleCorrection has %d empty bins\n", emptyBins);
110
55e05544 111 fVertexRecoCorrection->Divide();
1afae8ff 112 fTriggerCorrection->Divide();
55e05544 113
1afae8ff 114 if (fNEvents == 0)
115 {
116 printf("ERROR: fNEvents is empty. Cannot scale histogram. Skipping processing of fTriggerBiasCorrection\n");
117 return;
118 }
45e97e28 119 fTriggerBiasCorrection->GetMeasuredHistogram()->Scale(Double_t(fNTriggeredEvents)/Double_t(fNEvents));
55e05544 120 fTriggerBiasCorrection->Divide();
55e05544 121}
122
123//____________________________________________________________________
124Long64_t
125AlidNdEtaCorrection::Merge(TCollection* list) {
126 // Merge a list of dNdEtaCorrection objects with this (needed for
127 // PROOF).
128 // Returns the number of merged objects (including this).
129
130 if (!list)
131 return 0;
132
133 if (list->IsEmpty())
134 return 1;
135
136 TIterator* iter = list->MakeIterator();
137 TObject* obj;
138
139 // collections of measured and generated histograms
140 TList* collectionNtrackToNparticle = new TList;
141 TList* collectionVertexReco = new TList;
142 TList* collectionTriggerBias = new TList;
143
144 Int_t count = 0;
145 while ((obj = iter->Next())) {
146
147 AlidNdEtaCorrection* entry = dynamic_cast<AlidNdEtaCorrection*> (obj);
148 if (entry == 0)
149 continue;
150
45e97e28 151 collectionNtrackToNparticle ->Add(entry->GetTrack2ParticleCorrection());
55e05544 152 collectionVertexReco ->Add(entry->GetVertexRecoCorrection());
153 collectionTriggerBias ->Add(entry->GetTriggerBiasCorrection());
154
155 count++;
156 }
45e97e28 157 fTrack2ParticleCorrection ->Merge(collectionNtrackToNparticle);
55e05544 158 fVertexRecoCorrection ->Merge(collectionVertexReco);
159 fTriggerBiasCorrection ->Merge(collectionTriggerBias);
160
161 delete collectionNtrackToNparticle;
162 delete collectionVertexReco;
163 delete collectionTriggerBias;
164
165 return count+1;
166}
167
168
169//____________________________________________________________________
170Bool_t
0ab29cfa 171AlidNdEtaCorrection::LoadHistograms(const Char_t* fileName, const Char_t* dir) {
55e05544 172 //
173 // loads the histograms
174 //
175
45e97e28 176 fTrack2ParticleCorrection ->LoadHistograms(fileName, dir);
55e05544 177 fVertexRecoCorrection ->LoadHistograms(fileName, dir);
1afae8ff 178 fTriggerCorrection ->LoadHistograms(fileName, dir);
55e05544 179 fTriggerBiasCorrection ->LoadHistograms(fileName, dir);
1afae8ff 180
55e05544 181 return kTRUE;
182}
183
184
185//____________________________________________________________________
186void
187AlidNdEtaCorrection::SaveHistograms() {
188 //
189 // save the histograms
190 //
191
192 gDirectory->mkdir(fName.Data());
193 gDirectory->cd(fName.Data());
194
1afae8ff 195 fTrack2ParticleCorrection->SaveHistograms();
196 fVertexRecoCorrection->SaveHistograms();
197 fTriggerCorrection->SaveHistograms();
198 fTriggerBiasCorrection->SaveHistograms();
55e05544 199
200 gDirectory->cd("../");
201}
202
203//____________________________________________________________________
204void AlidNdEtaCorrection::DrawHistograms()
205{
206 //
45e97e28 207 // call the draw histogram method of the two AliCorrectionMatrix2D objects
55e05544 208
45e97e28 209 fTrack2ParticleCorrection ->DrawHistograms();
55e05544 210 fVertexRecoCorrection ->DrawHistograms();
1afae8ff 211 fTriggerCorrection ->DrawHistograms();
55e05544 212 fTriggerBiasCorrection ->DrawHistograms();
213
55e05544 214}
847489f7 215
216//____________________________________________________________________
217Float_t AlidNdEtaCorrection::GetMeasuredFraction(Float_t ptCutOff, Float_t eta, Bool_t debug)
218{
219 // calculates the fraction of particles measured (some are missed due to the pt cut off)
220 // uses the generated particle histogram from fTrack2ParticleCorrection
221
1afae8ff 222 const TH3F* generated = fTrack2ParticleCorrection->GetGeneratedHistogram();
847489f7 223
224 // find eta borders, if eta is negative assume -0.8 ... 0.8
225 Int_t etaBegin = 0;
226 Int_t etaEnd = 0;
227 if (eta < 0)
228 {
229 etaBegin = generated->GetYaxis()->FindBin(-0.8);
230 etaEnd = generated->GetYaxis()->FindBin(0.8);
231 }
232 else
233 {
234 etaBegin = generated->GetYaxis()->FindBin(eta);
235 etaEnd = etaBegin;
236 }
237
238 Int_t vertexBegin = generated->GetXaxis()->FindBin(-10);
239 Int_t vertexEnd = generated->GetXaxis()->FindBin(10);
240
92d2d8ad 241 TH1D* ptProj = dynamic_cast<TH1D*> (generated->ProjectionZ(Form("%s_pt", generated->GetName()), vertexBegin, vertexEnd, etaBegin, etaEnd));
1afae8ff 242 ptProj->GetXaxis()->SetTitle(generated->GetZaxis()->GetTitle());
847489f7 243
244 Int_t ptBin = ptProj->FindBin(ptCutOff);
245 Float_t abovePtCut = ptProj->Integral(ptBin, ptProj->GetNbinsX());
246 Float_t all = ptProj->Integral();
247
248 if (all == 0)
249 return -1;
250
251 Float_t fraction = abovePtCut / all;
252
253 if (debug)
254 {
255 new TCanvas;
256 ptProj->Draw();
257 }
92d2d8ad 258 else
259 delete ptProj;
847489f7 260
261 return fraction;
262}
263
0ab29cfa 264void AlidNdEtaCorrection::ReduceInformation()
265{
266 // this function deletes the measured and generated histograms from the corrections to reduce the amount of data
267 // in memory
268
269 // these are needed for GetMeasuredFraction(): fTrack2ParticleCorrection->ReduceInformation();
270 fVertexRecoCorrection->ReduceInformation();
271 fTriggerCorrection->ReduceInformation();
272 fTriggerBiasCorrection->ReduceInformation();
273}