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 // divides generated by measured to get the correction
163 if (!fhMeas || !fhGene || !fhCorr) {
164 AliDebug(AliLog::kError, "measured or generated histograms not available");
168 fhCorr->Divide(fhGene, fhMeas, 1, 1, "B");
171 for (Int_t x=1; x<=fhCorr->GetNbinsX(); ++x)
172 for (Int_t y=1; y<=fhCorr->GetNbinsY(); ++y)
173 for (Int_t z=1; z<=fhCorr->GetNbinsZ(); ++z)
174 if (fhCorr->GetBinContent(x, y, z) == 0)
178 printf("INFO: In %s we have %d empty bins (of %d) in the correction map\n", GetTitle(), emptyBins, fhCorr->GetNbinsX() * fhCorr->GetNbinsY() * fhCorr->GetNbinsZ());
181 //____________________________________________________________________
182 void AliCorrectionMatrix::Multiply()
185 // multiplies measured with correction to get the generated
188 if (!fhMeas || !fhGene || !fhCorr)
191 fhGene->Multiply(fhMeas, fhCorr, 1, 1, "B");
194 //____________________________________________________________________
195 void AliCorrectionMatrix::Add(AliCorrectionMatrix* aMatrixToAdd, Float_t c) {
197 // adds the measured and generated of aMatrixToAdd to measured and generated of this
199 // NB: the correction will naturally stay the same
201 fhMeas->Add(aMatrixToAdd->GetMeasuredHistogram(), c);
202 fhGene->Add(aMatrixToAdd->GetGeneratedHistogram(), c);
206 //____________________________________________________________________
207 Bool_t AliCorrectionMatrix::LoadHistograms(const Char_t* dir)
210 // loads the histograms from a file
211 // if dir is empty a directory with the name of this object is taken (like in SaveHistogram)
217 if (!gDirectory->cd(dir))
238 fhMeas = dynamic_cast<TH1*> (gDirectory->Get("measured"));
240 Info("LoadHistograms", "No measured hist available");
242 fhGene = dynamic_cast<TH1*> (gDirectory->Get("generated"));
244 Info("LoadHistograms", "No generated hist available");
246 fhCorr = dynamic_cast<TH1*> (gDirectory->Get("correction"));
248 Bool_t success = kTRUE;
251 Info("LoadHistograms", "No correction hist available");
255 gDirectory->cd("..");
260 //____________________________________________________________________
261 void AliCorrectionMatrix::SaveHistograms()
264 // saves the histograms
267 gDirectory->mkdir(GetName());
268 gDirectory->cd(GetName());
279 gDirectory->cd("..");
282 //____________________________________________________________________
283 void AliCorrectionMatrix::DrawHistograms(const Char_t* canvasName)
286 // draws all histograms on one TCanvas
287 // if canvasName is 0 the name of this object is taken
291 canvasName = Form("%s_canvas", GetName());
293 TCanvas* canvas = new TCanvas(canvasName, GetTitle(), 1200, 400);
294 canvas->Divide(3, 1);
298 fhMeas->Draw("COLZ");
303 // work around ROOT bug #22011
304 if (fhGene->GetEntries() == 0)
305 fhGene->SetEntries(1);
306 fhGene->Draw("COLZ");
311 fhCorr->Draw("COLZ");
314 //____________________________________________________________________
315 void AliCorrectionMatrix::ReduceInformation()
317 // this function deletes the measured and generated histograms to reduce the amount of data
333 //____________________________________________________________________
334 void AliCorrectionMatrix::Reset(Option_t* option)
336 // resets the histograms
339 fhGene->Reset(option);
342 fhMeas->Reset(option);
345 fhCorr->Reset(option);
348 //____________________________________________________________________
349 void AliCorrectionMatrix::SetCorrectionToUnity()
351 // sets the correction matrix to unity
356 for (Int_t x=0; x<=fhCorr->GetNbinsX()+1; ++x)
357 for (Int_t y=0; y<=fhCorr->GetNbinsY()+1; ++y)
358 for (Int_t z=0; z<=fhCorr->GetNbinsZ()+1; ++z)
360 fhCorr->SetBinContent(x, y, z, 1);
361 fhCorr->SetBinError(x, y, z, 0);
365 //____________________________________________________________________
366 void AliCorrectionMatrix::Scale(Double_t factor)
368 // scales the generated and measured histogram with the given factor
370 Printf("Scaling histograms with %f", factor);
372 fhMeas->Scale(factor);
373 fhGene->Scale(factor);