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
164 // fhCorr = (TH1*)fhGene->Clone("correction");
165 // fhCorr->SetTitle(Form("%s correction",GetTitle()));
169 if (!fhMeas || !fhGene || !fhCorr) {
170 AliDebug(AliLog::kError, "measured or generated histograms not available");
174 fhCorr->Divide(fhGene, fhMeas, 1, 1, "B");
177 for (Int_t x=1; x<=fhCorr->GetNbinsX(); ++x)
178 for (Int_t y=1; y<=fhCorr->GetNbinsY(); ++y)
179 for (Int_t z=1; z<=fhCorr->GetNbinsZ(); ++z)
180 if (fhCorr->GetBinContent(x, y, z) == 0)
184 printf("INFO: In %s we have %d empty bins (of %d) in the correction map\n", GetTitle(), emptyBins, fhCorr->GetNbinsX() * fhCorr->GetNbinsY() * fhCorr->GetNbinsZ());
187 //____________________________________________________________________
188 void AliCorrectionMatrix::Multiply()
191 // multiplies measured with correction to get the generated
194 if (!fhMeas || !fhGene || !fhCorr)
197 fhGene->Multiply(fhMeas, fhCorr, 1, 1, "B");
200 //____________________________________________________________________
201 void AliCorrectionMatrix::Add(AliCorrectionMatrix* aMatrixToAdd, Float_t c) {
203 // adds the measured and generated of aMatrixToAdd to measured and generated of this
205 // NB: the correction will naturally stay the same
207 fhMeas->Add(aMatrixToAdd->GetMeasuredHistogram(), c);
208 fhGene->Add(aMatrixToAdd->GetGeneratedHistogram(), c);
212 //____________________________________________________________________
213 Bool_t AliCorrectionMatrix::LoadHistograms(const Char_t* dir)
216 // loads the histograms from a file
217 // if dir is empty a directory with the name of this object is taken (like in SaveHistogram)
223 if (!gDirectory->cd(dir))
244 fhMeas = dynamic_cast<TH1*> (gDirectory->Get("measured"));
246 Info("LoadHistograms", "No measured hist available");
248 fhGene = dynamic_cast<TH1*> (gDirectory->Get("generated"));
250 Info("LoadHistograms", "No generated hist available");
252 fhCorr = dynamic_cast<TH1*> (gDirectory->Get("correction"));
254 Bool_t success = kTRUE;
257 Info("LoadHistograms", "No correction hist available");
261 gDirectory->cd("..");
266 //____________________________________________________________________
267 void AliCorrectionMatrix::SaveHistograms()
270 // saves the histograms
273 gDirectory->mkdir(GetName());
274 gDirectory->cd(GetName());
285 gDirectory->cd("..");
288 //____________________________________________________________________
289 void AliCorrectionMatrix::DrawHistograms(const Char_t* canvasName)
292 // draws all histograms on one TCanvas
293 // if canvasName is 0 the name of this object is taken
297 canvasName = Form("%s_canvas", GetName());
299 TCanvas* canvas = new TCanvas(canvasName, GetTitle(), 1200, 400);
300 canvas->Divide(3, 1);
304 fhMeas->Draw("COLZ");
309 // work around ROOT bug #22011
310 if (fhGene->GetEntries() == 0)
311 fhGene->SetEntries(1);
312 fhGene->Draw("COLZ");
317 fhCorr->Draw("COLZ");
320 //____________________________________________________________________
321 void AliCorrectionMatrix::ReduceInformation()
323 // this function deletes the measured and generated histograms to reduce the amount of data
339 //____________________________________________________________________
340 void AliCorrectionMatrix::Reset(Option_t* option)
342 // resets the histograms
345 fhGene->Reset(option);
348 fhMeas->Reset(option);
351 fhCorr->Reset(option);
354 //____________________________________________________________________
355 void AliCorrectionMatrix::SetCorrectionToUnity()
357 // sets the correction matrix to unity
362 for (Int_t x=1; x<=fhCorr->GetNbinsX(); ++x)
363 for (Int_t y=1; y<=fhCorr->GetNbinsY(); ++y)
364 for (Int_t z=1; z<=fhCorr->GetNbinsZ(); ++z)
365 fhCorr->SetBinContent(x, y, z, 1);