]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/AliCorrection.cxx
adding class AliCorrection that comprises a correction on the event-level and on...
[u/mrichter/AliRoot.git] / PWG0 / AliCorrection.cxx
1 /* $Id$ */
2
3 // ------------------------------------------------------
4 //
5 // Class to handle corrections.
6 //
7 // ------------------------------------------------------
8 //
9
10 #include <TFile.h>
11 #include <TCanvas.h>
12 #include <TH2F.h>
13
14 #include <AliLog.h>
15 #include "AliCorrectionMatrix2D.h"
16 #include "AliCorrectionMatrix3D.h"
17
18 #include "AliCorrection.h"
19
20 //____________________________________________________________________
21 ClassImp(AliCorrection)
22
23 //____________________________________________________________________
24 AliCorrection::AliCorrection() : TNamed(),
25   fEventCorr(0),
26   fTrackCorr(0)
27 {
28   // default constructor
29 }
30
31 //____________________________________________________________________
32 AliCorrection::AliCorrection(const Char_t* name, const Char_t* title) : TNamed(name, title),
33   fEventCorr(0),
34   fTrackCorr(0)
35 {
36   // constructor initializing tnamed
37
38   Float_t binLimitsPt[] = {0.0, 0.05, 0.1, 0.125, 0.15, 0.175, 0.2, 0.225, 0.25, 0.275, 0.3, 0.325, 0.35, 0.375, 0.4, 0.425, 0.45, 0.475, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.5, 2.0, 5.0, 10.0, 100.0};
39   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, 10.5, 12.5, 14.5, 16.5, 18.5, 20.5, 25.5, 30.5, 40.5, 50.5, 100.5, 300.5};
40   //Float_t binLimitsVtx[] = {-20,-15,-10,-6,-3,0,3,6,10,15,20};
41   Float_t binLimitsVtx[] = {-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
42
43   fEventCorr = new AliCorrectionMatrix2D("EventCorrection", Form("%s EventCorrection", title), 40, binLimitsVtx, 22, binLimitsN);
44   fTrackCorr = new AliCorrectionMatrix3D("TrackCorrection", Form("%s TrackCorrection", title), 40, -20, 20, 20, -2, 2, 28, binLimitsPt);
45
46   fEventCorr->SetAxisTitles("vtx z [cm]", "Ntracks");
47   fTrackCorr->SetAxisTitles("vtx z [cm]", "#eta", "p_{T} [GeV/c]");
48 }
49
50 //____________________________________________________________________
51 AliCorrection::AliCorrection(const AliCorrection& c) : TNamed(c),
52   fEventCorr(0),
53   fTrackCorr(0)
54 {
55   // copy constructor
56   ((AliCorrection &)c).Copy(*this);
57 }
58
59 //____________________________________________________________________
60 AliCorrection::~AliCorrection()
61 {
62   //
63   // destructor
64   //
65
66   if (fEventCorr)
67   {
68     delete fEventCorr;
69     fEventCorr = 0;
70   }
71
72   if (fTrackCorr)
73   {
74     delete fTrackCorr;
75     fTrackCorr = 0;
76   }
77 }
78
79 //____________________________________________________________________
80 AliCorrection &AliCorrection::operator=(const AliCorrection &c)
81 {
82   // assigment operator
83
84   if (this != &c)
85     ((AliCorrection &) c).Copy(*this);
86
87   return *this;
88 }
89
90 //____________________________________________________________________
91 void AliCorrection::Copy(TObject& c) const
92 {
93   // copy function
94
95   AliCorrection& target = (AliCorrection &) c;
96
97   if (fEventCorr)
98     target.fEventCorr = dynamic_cast<AliCorrectionMatrix2D*> (fEventCorr->Clone());
99
100   if (fTrackCorr)
101     target.fTrackCorr = dynamic_cast<AliCorrectionMatrix3D*> (fTrackCorr->Clone());
102 }
103
104 //____________________________________________________________________
105 Long64_t AliCorrection::Merge(TCollection* list)
106 {
107   // Merge a list of AliCorrection objects with this (needed for
108   // PROOF). 
109   // Returns the number of merged objects (including this).
110
111   if (!list)
112     return 0;
113   
114   if (list->IsEmpty())
115     return 1;
116
117   TIterator* iter = list->MakeIterator();
118   TObject* obj;
119
120   // collections of measured and generated histograms
121   TList* collectionEvent = new TList;
122   TList* collectionTrack = new TList;
123   
124   Int_t count = 0;
125   while ((obj = iter->Next())) {
126     
127     AliCorrection* entry = dynamic_cast<AliCorrection*> (obj);
128     if (entry == 0) 
129       continue;
130
131     collectionEvent->Add(entry->fEventCorr);
132     collectionTrack->Add(entry->fTrackCorr);
133
134     count++;
135   }
136   fEventCorr->Merge(collectionEvent);
137   fTrackCorr->Merge(collectionTrack);
138
139   delete collectionEvent;
140   delete collectionTrack;
141
142   return count+1;
143 }
144
145 //____________________________________________________________________
146 void AliCorrection::Divide()
147 {
148   //
149   // divide the histograms to get the correction
150   //
151   
152   if (!fEventCorr || !fTrackCorr)
153     return;
154     
155   fEventCorr->Divide();
156   fTrackCorr->Divide();
157
158   Int_t emptyBins = fTrackCorr->CheckEmptyBins(-9.99, 9.99, -0.79, 0.79, 0.3, 9.9);
159   printf("INFO: In the central region the track correction of %s has %d empty bins\n", GetName(), emptyBins);
160 }
161
162 //____________________________________________________________________
163 Bool_t AliCorrection::LoadHistograms(const Char_t* dir)
164 {
165   //
166   // loads the histograms from a file
167   // if dir is empty a directory with the name of this object is taken (like in SaveHistogram)
168   //
169
170   if (!fEventCorr || !fTrackCorr)
171     return kFALSE;
172
173   if (!dir)
174     dir = GetName();
175
176   if (!gDirectory->cd(dir))
177     return kFALSE;
178
179   Bool_t success = fEventCorr->LoadHistograms();
180   success &= fTrackCorr->LoadHistograms();
181
182   gDirectory->cd("..");
183
184   return success;
185 }
186
187 //____________________________________________________________________
188 void AliCorrection::SaveHistograms()
189 {
190   //
191   // saves the histograms in a directory with the name of this object (GetName)
192   //
193   
194   gDirectory->mkdir(GetName());
195   gDirectory->cd(GetName());
196
197   if (fEventCorr)
198     fEventCorr->SaveHistograms();
199
200   if (fTrackCorr)
201     fTrackCorr->SaveHistograms();
202     
203   gDirectory->cd("..");
204 }
205
206 //____________________________________________________________________
207 void AliCorrection::ReduceInformation()
208 {
209   // this function deletes the measured and generated histograms to reduce the amount of data
210   // in memory
211
212   if (!fEventCorr || !fTrackCorr)
213     return;
214
215   fEventCorr->ReduceInformation();
216   fTrackCorr->ReduceInformation();
217 }
218
219 //____________________________________________________________________
220 void AliCorrection::Reset(Option_t* option)
221 {
222   // resets the histograms
223
224   if (fEventCorr)
225     fEventCorr->Reset(option);
226
227   if (fTrackCorr)
228     fTrackCorr->Reset(option);
229 }
230
231 //____________________________________________________________________
232 void AliCorrection::DrawHistograms(const Char_t* name)
233 {
234   // draws the corrections
235
236   if (!name)
237     name = GetName();
238
239   if (fEventCorr)
240     fEventCorr->DrawHistograms(Form("%s event", name));
241
242   if (fTrackCorr)
243     fTrackCorr->DrawHistograms(Form("%s track", name));
244 }
245
246 //____________________________________________________________________
247 void AliCorrection::SetCorrectionToUnity()
248 {
249   // set the corrections to unity
250
251   if (fEventCorr)
252     fEventCorr->SetCorrectionToUnity();
253
254   if (fTrackCorr)
255     fTrackCorr->SetCorrectionToUnity();
256 }
257
258 //____________________________________________________________________
259 void AliCorrection::Multiply()
260 {
261   // call Multiply
262
263   if (fEventCorr)
264   {
265     fEventCorr->Multiply();
266     // now we manually copy the overflow bin of the y axis (multiplicity) over. This is important to get the event count correct
267     TH2F* hist = fEventCorr->GetMeasuredHistogram();
268     for (Int_t x = 1; x <= hist->GetNbinsX(); ++x)
269       fEventCorr->GetGeneratedHistogram()->SetBinContent(x, hist->GetNbinsY() + 1, hist->GetBinContent(x, hist->GetNbinsY() + 1));
270   }
271
272   if (fTrackCorr)
273     fTrackCorr->Multiply();
274 }