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)
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", GetTitle(), emptyBins, fhCorr->GetNbinsX() * fhCorr->GetNbinsY() * fhCorr->GetNbinsZ());
179 //____________________________________________________________________
180 void AliCorrectionMatrix::Multiply()
183 // multiplies measured with correction to get the generated
186 if (!fhMeas || !fhGene || !fhCorr)
189 fhGene->Multiply(fhMeas, fhCorr, 1, 1, "B");
192 //____________________________________________________________________
193 Bool_t AliCorrectionMatrix::LoadHistograms(const Char_t* dir)
196 // loads the histograms from a file
197 // if dir is empty a directory with the name of this object is taken (like in SaveHistogram)
203 if (!gDirectory->cd(dir))
224 fhMeas = dynamic_cast<TH1*> (gDirectory->Get("measured"));
226 Info("LoadHistograms", "No measured hist available");
228 fhGene = dynamic_cast<TH1*> (gDirectory->Get("generated"));
230 Info("LoadHistograms", "No generated hist available");
232 fhCorr = dynamic_cast<TH1*> (gDirectory->Get("correction"));
234 Bool_t success = kTRUE;
237 Info("LoadHistograms", "No correction hist available");
241 gDirectory->cd("..");
246 //____________________________________________________________________
247 void AliCorrectionMatrix::SaveHistograms()
250 // saves the histograms
253 gDirectory->mkdir(GetName());
254 gDirectory->cd(GetName());
265 gDirectory->cd("..");
268 //____________________________________________________________________
269 void AliCorrectionMatrix::DrawHistograms(const Char_t* canvasName)
272 // draws all histograms on one TCanvas
273 // if canvasName is 0 the name of this object is taken
277 canvasName = Form("%s_canvas", GetName());
279 TCanvas* canvas = new TCanvas(canvasName, GetTitle(), 1200, 400);
280 canvas->Divide(3, 1);
284 fhMeas->Draw("COLZ");
289 // work around ROOT bug #22011
290 if (fhGene->GetEntries() == 0)
291 fhGene->SetEntries(1);
292 fhGene->Draw("COLZ");
297 fhCorr->Draw("COLZ");
300 //____________________________________________________________________
301 void AliCorrectionMatrix::ReduceInformation()
303 // this function deletes the measured and generated histograms to reduce the amount of data
319 //____________________________________________________________________
320 void AliCorrectionMatrix::Reset(Option_t* option)
322 // resets the histograms
325 fhGene->Reset(option);
328 fhMeas->Reset(option);
331 fhCorr->Reset(option);
334 //____________________________________________________________________
335 void AliCorrectionMatrix::SetCorrectionToUnity()
337 // sets the correction matrix to unity
342 for (Int_t x=1; x<=fhCorr->GetNbinsX(); ++x)
343 for (Int_t y=1; y<=fhCorr->GetNbinsY(); ++y)
344 for (Int_t z=1; z<=fhCorr->GetNbinsZ(); ++z)
345 fhCorr->SetBinContent(x, y, z, 1);