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