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");
167 //____________________________________________________________________
168 Bool_t AliCorrectionMatrix::LoadHistograms(Char_t* fileName, Char_t* dir)
171 // loads the histograms from a file
174 TFile* fin = TFile::Open(fileName);
177 //Info("LoadHistograms",Form(" %s file does not exist",fileName));
181 if(fhGene) {delete fhGene; fhGene=0;}
182 if(fhCorr) {delete fhCorr; fhCorr=0;}
183 if(fhMeas) {delete fhMeas; fhMeas=0;}
185 fhMeas = (TH2F*)fin->Get(Form("%s/meas_%s", dir,GetName()));
186 if(!fhMeas) Info("LoadHistograms","No meas hist available");
188 fhGene = (TH2F*)fin->Get(Form("%s/gene_%s",dir, GetName()));
189 if(!fhGene) Info("LoadHistograms","No gene hist available");
191 fhCorr = (TH2F*)fin->Get(Form("%s/corr_%s",dir, GetName()));
194 Info("LoadHistograms","No corr hist available");
201 //____________________________________________________________________
202 void AliCorrectionMatrix::SaveHistograms()
205 // saves the histograms
215 //____________________________________________________________________
216 void AliCorrectionMatrix::DrawHistograms()
219 // draws all the four histograms on one TCanvas
222 TCanvas* canvas = new TCanvas(Form("correction_%s",fName.Data()),
223 Form("correction_%s",fName.Data()), 800, 800);
224 canvas->Divide(2, 2);
228 fhMeas->Draw("COLZ");
232 fhGene->Draw("COLZ");
236 fhCorr->Draw("COLZ");
240 // add: draw here the stat. errors of the correction histogram