1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
16 // Collection class for histograms
17 // Stores either histograms or vectors of histograms
20 // Matus Kalisky <matus.kalisky@cern.ch>
27 #include <THnSparse.h>
34 #include "AliHFEcollection.h"
39 ClassImp(AliHFEcollection)
41 //___________________________________________________________________
42 AliHFEcollection::AliHFEcollection():
48 // default constructor
51 fList = new THashList();
53 AliError("Initialization of the list failed");
56 // list is owner of the objects. Once list is deleted, the objects
57 // it contains will be deleted too
58 //fList->SetOwner(kTRUE);
60 //Printf("%s:%d,%p",(char*)__FILE__,__LINE__,fInstance);
63 //___________________________________________________________________
64 AliHFEcollection::AliHFEcollection(char* name, char* title):
73 fList = new THashList();
75 AliError("Initialization of the list failed");
78 // list is owner of the objects. Once list is deleted, the objects
79 // it contains will be deleted too
80 // fList->SetOwner(kTRUE);
83 //___________________________________________________________________
84 AliHFEcollection::AliHFEcollection(const AliHFEcollection &c) :
95 //___________________________________________________________________
96 AliHFEcollection &AliHFEcollection::operator=(const AliHFEcollection &ref)
99 // Assignment operator
107 //___________________________________________________________________
108 void AliHFEcollection::Copy(TObject &ref) const {
111 // Performs the copying of the object
114 AliHFEcollection &target = dynamic_cast<AliHFEcollection &>(ref);
116 // Clone List Content
117 target.fList = new THashList();
118 for(Int_t ien = 0; ien < fList->GetEntries(); ien++)
119 target.fList->Add(fList->At(ien)->Clone());
121 //___________________________________________________________________
122 AliHFEcollection::~AliHFEcollection(){
130 AliInfo("DESTRUCTOR");
132 //___________________________________________________________________
133 Bool_t AliHFEcollection::CreateTH1F(const char* name, const char* title, Int_t nBin, Float_t nMin, Float_t nMax){
136 // Creates a TH1F histogram for the collection
140 AliError("No TList pointer ! ");
144 fList->Add(new TH1F(name, title, nBin, nMin, nMax));
145 return CheckObject(name);
148 //___________________________________________________________________
149 Bool_t AliHFEcollection::CreateTH2F(const char* name, const char* title, Int_t nBinX, Float_t nMinX, Float_t nMaxX, Int_t nBinY, Float_t nMinY, Float_t nMaxY){
152 // Creates a TH2F histogram for the collection
156 AliError("No TList pointer ! ");
159 fList->Add(new TH2F(name, title, nBinX, nMinX, nMaxX, nBinY, nMinY, nMaxY));
160 return CheckObject(name);
162 //___________________________________________________________________
163 Bool_t AliHFEcollection::CreateTH1Fvector1(Int_t X, const char* name, const char* title, Int_t nBin, Float_t nMin, Float_t nMax){
166 // create a 1 dimensional array of size [X]
170 AliError("No TList pointer ! ");
174 AliError("can not create array with negative or zero size ");
178 for(Int_t i=0; i<X; ++i){
180 hname.Append(Form("%s_[%d]", name, i));
181 //cout<<" -D: name: "<<name.str().c_str()<<endl;
182 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
183 CreateTH1F(hname.Data(), title, nBin, nMin, nMax);
184 if(!CheckObject(hname.Data())){
185 AliError(Form("Not possible to create object: %s", hname.Data()));
191 //___________________________________________________________________
192 Bool_t AliHFEcollection::CreateTH2Fvector1(Int_t X, const char* name, const char* title, Int_t nBinX, Float_t nMinX, Float_t nMaxX, Int_t nBinY, Float_t nMinY, Float_t nMaxY){
195 // create a 1 dimensinal array of TH2F histograms with size [X]
199 AliError("No TList pointer !");
203 AliError("can not create array with negative or zero size ");
207 for(Int_t i=0; i<X; ++i){
209 hname.Append(Form("%s_[%d]", name, i));
210 //cout<<" -D: name: "<<name<<endl;
211 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
212 CreateTH2F(hname.Data(), title, nBinX, nMinX, nMaxX, nBinY, nMinY, nMaxY);
213 if(!CheckObject(hname.Data())){
214 AliError(Form("Not possible to create object: %s", hname.Data()));
220 //___________________________________________________________________
221 Bool_t AliHFEcollection::CreateTH1Fvector2(Int_t X, Int_t Y, const char* name, const char* title, Int_t nBin, Float_t nMin, Float_t nMax){
224 // create a 2 dimensional array of histograms of size [X, Y]
228 AliError("No TList pointer ! ");
232 AliError("can not create array with negative or zero size ");
236 for(Int_t i=0; i<X; ++i){
237 for(Int_t j=0; j<Y; ++j){
239 hname.Append(Form("%s_[%d][%d]", name, i, j));
240 //cout<<" -D: name: "<<name.str().c_str()<<endl;
241 //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl;
242 CreateTH1F(hname.Data(), title, nBin, nMin, nMax);
243 if(!CheckObject(hname.Data())){
244 AliError(Form("Not possible to create object: %s", hname.Data()));
251 //___________________________________________________________________
252 Bool_t AliHFEcollection::CreateProfile(const char* name, const char* title, Int_t nbins, Double_t xmin, Double_t xmax){
255 // create a simple TProfile
259 AliError("No TList pointer ! ");
262 fList->Add(new TProfile(name, title, nbins, xmin, xmax));
263 return CheckObject(name);
266 //___________________________________________________________________
267 Bool_t AliHFEcollection::CreateTHnSparse(const char* name, const char* title, Int_t dim, Int_t* nbins, Double_t* xmin, Double_t* xmax){
270 // create 'dim' dimensional THnSparse
274 AliError("No TList pointer ! ");
277 fList->Add(new THnSparseF(name, title, dim, nbins, xmin, xmax));
278 return CheckObject(name);
281 //___________________________________________________________________
282 TObject* AliHFEcollection::Get(const char* name){
285 // Get histogram with the required name
289 if(!CheckObject(name)){
290 AliWarning(Form("Not possible to return pointer to the object '%s'\n", name));
294 return fList->FindObject(name);
297 //___________________________________________________________________
298 Bool_t AliHFEcollection::Fill(const char* name, Double_t v){
301 // fill function for one TH1 histograms
304 if(!CheckObject(name)){
305 AliError(Form("Not possible to return pointer to the object '%s'\n", name));
309 // chack the possible object types
310 if(fList->FindObject(name)->InheritsFrom("TH1")){
311 (dynamic_cast<TH1F*>(fList->FindObject(name)))->Fill(v);
318 //___________________________________________________________________
319 Bool_t AliHFEcollection::Fill(const char* name, Int_t X, Double_t v){
322 // fill function for one dimension arrays of TH1
325 const char* n = Form("%s_[%d]", name, X);
330 Fill(o->GetName(), v);
333 //___________________________________________________________________
334 Bool_t AliHFEcollection::Fill(const char* name, Int_t X, Int_t Y, Double_t v){
337 // Fill function fir 2 dimensional TH1 arrays
340 const char* n = Form("%s_[%d][%d]", name, X, Y);
345 Fill(o->GetName(), v);
348 //___________________________________________________________________
349 Bool_t AliHFEcollection::Fill(const char* name, Int_t X, Double_t v1, Double_t v2){
352 // fill function for one dimension array of TH2
355 const char* n = Form("%s_[%d]", name, X);
360 Fill(o->GetName(), v1, v2);
364 //___________________________________________________________________
365 Bool_t AliHFEcollection::Fill(const char* name, Double_t v1, Double_t v2){
368 // fill function for TH2 objects
371 if(!CheckObject(name)){
372 AliError(Form("Not possible to return pointer to the object '%s'\n", name));
376 // chack the possible object types
377 if(fList->FindObject(name)->InheritsFrom("TH2")){
378 (dynamic_cast<TH2F*>(fList->FindObject(name)))->Fill(v1, v2);
381 if(fList->FindObject(name)->InheritsFrom("TProfile")){
382 (dynamic_cast<TProfile*>(fList->FindObject(name)))->Fill(v1, v2);
390 //___________________________________________________________________
391 Bool_t AliHFEcollection::CheckObject(const char* name){
394 // check wheter the creation of the histogram was succesfull
398 AliError("No TList pointer ! ");
402 if(!fList->FindObject(name)){
403 AliWarning(Form("Creating or Finding the object '%s' failed\n", name));
408 //___________________________________________________________________
409 Bool_t AliHFEcollection::Sumw2(const char* name){
411 // Set Sumw2 for the given object
413 if(!CheckObject(name)){
417 TObject *o = Get(name);
418 if(o->InheritsFrom("THnSparse")){
419 (dynamic_cast<THnSparse*>(o))->Sumw2();
423 //___________________________________________________________________
424 Bool_t AliHFEcollection::BinLogAxis(const char* name, Int_t dim){
427 // converts the axis (defined by the dimension) of THx or THnSparse
428 // object to Log scale. Number of bins and bin min and bin max are preserved
432 if(!CheckObject(name)){
436 TObject *o = Get(name);
438 if(o->InheritsFrom("TH1")){
439 axis = (dynamic_cast<TH1F*>(o))->GetXaxis();
441 if(o->InheritsFrom("TH2")){
443 axis = (dynamic_cast<TH2F*>(o))->GetXaxis();
446 axis = (dynamic_cast<TH2F*>(o))->GetYaxis();
449 AliError("Only dim = 0 or 1 possible for TH2F");
452 if(o->InheritsFrom("THnSparse")){
453 axis = (dynamic_cast<THnSparse*>(o))->GetAxis(dim);
457 AliError(Form("Axis '%d' could not be identified in the object '%s'\n", dim, name));
461 Int_t bins = axis->GetNbins();
463 Double_t from = axis->GetXmin();
464 Double_t to = axis->GetXmax();
465 Double_t *newBins = new Double_t[bins+1];
467 Double_t factor = TMath::Power(to/from, 1./bins);
468 for(Int_t i=1; i<=bins; ++i){
469 newBins[i] = factor * newBins[i-1];
471 axis->Set(bins, newBins);
478 //___________________________________________________________________
479 Long64_t AliHFEcollection::Merge(TCollection *list){
482 // Merge the collections
489 TIterator *iter = list->MakeIterator();
492 while((o = iter->Next())){
493 AliHFEcollection *coll = dynamic_cast<AliHFEcollection *>(o);
495 TList templist; // Create temporary list containing all the lists to merge
496 templist.Add(coll->fList);
497 fList->Merge(&templist);
503 //____________________________________________________________________
504 void AliHFEcollection::Browse(TBrowser *b)
508 // Browse the content of the directory.
515 //Add objects that are only in memory
516 while ((obj = nextin())) {
517 b->Add(obj, obj->GetName());