3 // ------------------------------------------------------
5 // Class to handle corrections.
7 // ------------------------------------------------------
16 #include "AliCorrectionMatrix.h"
18 //____________________________________________________________________
19 ClassImp(AliCorrectionMatrix)
21 //____________________________________________________________________
22 AliCorrectionMatrix::AliCorrectionMatrix() : TNamed(),
27 // default constructor
30 //____________________________________________________________________
31 AliCorrectionMatrix::AliCorrectionMatrix(const Char_t* name, const Char_t* title) : TNamed(name, title),
36 // constructor initializing tnamed
39 //____________________________________________________________________
40 AliCorrectionMatrix::AliCorrectionMatrix(const AliCorrectionMatrix& c) : TNamed(c),
46 ((AliCorrectionMatrix &)c).Copy(*this);
49 //____________________________________________________________________
50 AliCorrectionMatrix::~AliCorrectionMatrix()
75 //____________________________________________________________________
76 AliCorrectionMatrix &AliCorrectionMatrix::operator=(const AliCorrectionMatrix &c)
81 ((AliCorrectionMatrix &) c).Copy(*this);
86 //____________________________________________________________________
87 void AliCorrectionMatrix::Copy(TObject& c) const
91 AliCorrectionMatrix& target = (AliCorrectionMatrix &) c;
94 target.fhMeas = dynamic_cast<TH1*> (fhMeas->Clone());
97 target.fhGene = dynamic_cast<TH1*> (fhGene->Clone());
100 target.fhCorr = dynamic_cast<TH1*> (fhCorr->Clone());
103 //________________________________________________________________________
104 void AliCorrectionMatrix::SetAxisTitles(const Char_t* titleX, const Char_t* titleY, const Char_t* titleZ)
107 // method for setting the axis titles of the histograms
110 fhMeas ->SetXTitle(titleX); fhMeas ->SetYTitle(titleY); fhMeas ->SetZTitle(titleZ);
111 fhGene ->SetXTitle(titleX); fhGene ->SetYTitle(titleY); fhGene ->SetZTitle(titleZ);
112 fhCorr ->SetXTitle(titleX); fhCorr ->SetYTitle(titleY); fhCorr ->SetZTitle(titleZ);
115 //____________________________________________________________________
116 Long64_t AliCorrectionMatrix::Merge(TCollection* list)
118 // Merge a list of AliCorrectionMatrix objects with this (needed for
120 // Returns the number of merged objects (including this).
128 TIterator* iter = list->MakeIterator();
131 // collections of measured and generated histograms
132 TList* collectionMeas = new TList;
133 TList* collectionGene = new TList;
136 while ((obj = iter->Next())) {
138 AliCorrectionMatrix* entry = dynamic_cast<AliCorrectionMatrix*> (obj);
142 collectionMeas->Add(entry->GetMeasuredHistogram());
143 collectionGene->Add(entry->GetGeneratedHistogram());
147 fhMeas->Merge(collectionMeas);
148 fhGene->Merge(collectionGene);
150 delete collectionMeas;
151 delete collectionGene;
156 //____________________________________________________________________
157 void AliCorrectionMatrix::Divide()
160 // divide the histograms to get the correction
163 if (!fhMeas || !fhGene)
166 fhCorr->Divide(fhGene, fhMeas, 1, 1, "B");
169 for (Int_t x=1; x<=fhCorr->GetNbinsX(); ++x)
170 for (Int_t y=1; y<=fhCorr->GetNbinsY(); ++y)
171 for (Int_t z=1; z<=fhCorr->GetNbinsZ(); ++z)
172 if (fhCorr->GetBinContent(x, y, z) == 0)
176 printf("INFO: In %s we have %d empty bins (of %d) in the correction map\n", GetName(), emptyBins, fhCorr->GetNbinsX() * fhCorr->GetNbinsY() * fhCorr->GetNbinsZ());
179 //____________________________________________________________________
180 Bool_t AliCorrectionMatrix::LoadHistograms(const Char_t* fileName, const Char_t* dir)
183 // loads the histograms from a file
186 TFile* fin = TFile::Open(fileName);
189 //Info("LoadHistograms",Form(" %s file does not exist",fileName));
193 if(fhGene) {delete fhGene; fhGene=0;}
194 if(fhCorr) {delete fhCorr; fhCorr=0;}
195 if(fhMeas) {delete fhMeas; fhMeas=0;}
197 fhMeas = dynamic_cast<TH1*> (fin->Get(Form("%s/meas_%s", dir,GetName())));
198 if(!fhMeas) Info("LoadHistograms","No meas. (%s) hist available",Form("%s/meas_%s", dir,GetName()));
200 fhGene = dynamic_cast<TH1*> (fin->Get(Form("%s/gene_%s",dir, GetName())));
201 if(!fhGene) Info("LoadHistograms","No gene. (%s) hist available",Form("%s/gene_%s",dir, GetName()));
203 fhCorr = dynamic_cast<TH1*> (fin->Get(Form("%s/corr_%s",dir, GetName())));
205 Info("LoadHistograms","No corr.(%s) hist available",Form("%s/corr_%s",dir, GetName()));
212 //____________________________________________________________________
213 void AliCorrectionMatrix::SaveHistograms()
216 // saves the histograms
229 //____________________________________________________________________
230 void AliCorrectionMatrix::DrawHistograms()
233 // draws all the four histograms on one TCanvas
236 TCanvas* canvas = new TCanvas(Form("correction_%s",fName.Data()),
237 Form("correction_%s",fName.Data()), 800, 800);
238 canvas->Divide(2, 2);
242 fhMeas->Draw("COLZ");
246 fhGene->Draw("COLZ");
250 fhCorr->Draw("COLZ");
254 // add: draw here the stat. errors of the correction histogram
257 //____________________________________________________________________
258 void AliCorrectionMatrix::ReduceInformation()
260 // this function deletes the measured and generated histograms to reduce the amount of data
276 //____________________________________________________________________
277 void AliCorrectionMatrix::Reset(Option_t* option)
279 // resets the histograms
282 fhGene->Reset(option);
285 fhMeas->Reset(option);
288 fhCorr->Reset(option);