3 // ------------------------------------------------------
5 // Class to handle corrections.
7 // ------------------------------------------------------
16 #include "AliCorrectionMatrix.h"
18 //____________________________________________________________________
19 ClassImp(AliCorrectionMatrix)
21 //____________________________________________________________________
22 AliCorrectionMatrix::AliCorrectionMatrix() : TNamed(),
27 // default constructor
30 AliCorrectionMatrix::AliCorrectionMatrix(const Char_t* name, const Char_t* title) : TNamed(name, title),
35 // constructor initializing tnamed
38 //____________________________________________________________________
39 AliCorrectionMatrix::AliCorrectionMatrix(const AliCorrectionMatrix& c)
43 ((AliCorrectionMatrix &)c).Copy(*this);
46 //____________________________________________________________________
47 AliCorrectionMatrix::~AliCorrectionMatrix()
72 //____________________________________________________________________
73 AliCorrectionMatrix &AliCorrectionMatrix::operator=(const AliCorrectionMatrix &c)
78 ((AliCorrectionMatrix &) c).Copy(*this);
83 //____________________________________________________________________
84 void AliCorrectionMatrix::Copy(TObject& c) const
88 AliCorrectionMatrix& target = (AliCorrectionMatrix &) c;
91 target.fhMeas = dynamic_cast<TH1*> (fhMeas->Clone());
94 target.fhGene = dynamic_cast<TH1*> (fhGene->Clone());
97 target.fhCorr = dynamic_cast<TH1*> (fhCorr->Clone());
100 //________________________________________________________________________
101 void AliCorrectionMatrix::SetAxisTitles(const Char_t* titleX, const Char_t* titleY, const Char_t* titleZ)
104 // method for setting the axis titles of the histograms
107 fhMeas ->SetXTitle(titleX); fhMeas ->SetYTitle(titleY); fhMeas ->SetZTitle(titleZ);
108 fhGene ->SetXTitle(titleX); fhGene ->SetYTitle(titleY); fhGene ->SetZTitle(titleZ);
109 fhCorr ->SetXTitle(titleX); fhCorr ->SetYTitle(titleY); fhCorr ->SetZTitle(titleZ);
112 //____________________________________________________________________
113 Long64_t AliCorrectionMatrix::Merge(TCollection* list)
115 // Merge a list of AliCorrectionMatrix objects with this (needed for
117 // Returns the number of merged objects (including this).
125 TIterator* iter = list->MakeIterator();
128 // collections of measured and generated histograms
129 TList* collectionMeas = new TList;
130 TList* collectionGene = new TList;
133 while ((obj = iter->Next())) {
135 AliCorrectionMatrix* entry = dynamic_cast<AliCorrectionMatrix*> (obj);
139 collectionMeas->Add(entry->GetMeasuredHistogram());
140 collectionGene->Add(entry->GetGeneratedHistogram());
144 fhMeas->Merge(collectionMeas);
145 fhGene->Merge(collectionGene);
147 delete collectionMeas;
148 delete collectionGene;
153 //____________________________________________________________________
154 void AliCorrectionMatrix::Divide()
157 // divide the histograms to get the correction
160 if (!fhMeas || !fhGene)
163 fhCorr->Divide(fhGene, fhMeas, 1, 1, "B");
166 for (Int_t x=1; x<=fhCorr->GetNbinsX(); ++x)
167 for (Int_t y=1; y<=fhCorr->GetNbinsY(); ++y)
168 for (Int_t z=1; z<=fhCorr->GetNbinsZ(); ++z)
169 if (fhCorr->GetBinContent(x, y, z) == 0)
173 printf("INFO: In %s we have %d empty bins (of %d) in the correction map\n", GetName(), emptyBins, fhCorr->GetNbinsX() * fhCorr->GetNbinsY() * fhCorr->GetNbinsZ());
176 //____________________________________________________________________
177 Bool_t AliCorrectionMatrix::LoadHistograms(Char_t* fileName, Char_t* dir)
180 // loads the histograms from a file
183 TFile* fin = TFile::Open(fileName);
186 //Info("LoadHistograms",Form(" %s file does not exist",fileName));
190 if(fhGene) {delete fhGene; fhGene=0;}
191 if(fhCorr) {delete fhCorr; fhCorr=0;}
192 if(fhMeas) {delete fhMeas; fhMeas=0;}
194 fhMeas = (TH2F*)fin->Get(Form("%s/meas_%s", dir,GetName()));
195 if(!fhMeas) Info("LoadHistograms","No meas hist available");
197 fhGene = (TH2F*)fin->Get(Form("%s/gene_%s",dir, GetName()));
198 if(!fhGene) Info("LoadHistograms","No gene hist available");
200 fhCorr = (TH2F*)fin->Get(Form("%s/corr_%s",dir, GetName()));
203 Info("LoadHistograms","No corr hist available");
210 //____________________________________________________________________
211 void AliCorrectionMatrix::SaveHistograms()
214 // saves the histograms
224 //____________________________________________________________________
225 void AliCorrectionMatrix::DrawHistograms()
228 // draws all the four histograms on one TCanvas
231 TCanvas* canvas = new TCanvas(Form("correction_%s",fName.Data()),
232 Form("correction_%s",fName.Data()), 800, 800);
233 canvas->Divide(2, 2);
237 fhMeas->Draw("COLZ");
241 fhGene->Draw("COLZ");
245 fhCorr->Draw("COLZ");
249 // add: draw here the stat. errors of the correction histogram