1 /*************************************************************************
2 * Copyright(c) 1998-2009, 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 **************************************************************************/
17 // Generic Histogram container with support for groups and filling of groups by passing
21 // Jens Wiechula <Jens.Wiechula@cern.ch>
22 // Julian Book <Julian.Book@cern.ch>
31 #include <TProfile2D.h>
32 #include <TProfile3D.h>
33 #include <THnSparse.h>
34 #include <TCollection.h>
35 #include <THashList.h>
37 #include <TObjString.h>
38 #include <TObjArray.h>
47 #include <TVirtualPS.h>
50 #include "AliDielectronHelper.h"
51 #include "AliDielectronVarManager.h"
52 #include "AliDielectronHistos.h"
54 ClassImp(AliDielectronHistos)
57 AliDielectronHistos::AliDielectronHistos() :
59 TNamed("AliDielectronHistos","Dielectron Histogram Container"),
62 fReservedWords(new TString)
65 // Default constructor
67 fHistoList.SetOwner(kTRUE);
68 fHistoList.SetName("Dielectron_Histos");
71 //_____________________________________________________________________________
72 AliDielectronHistos::AliDielectronHistos(const char* name, const char* title) :
77 fReservedWords(new TString)
82 fHistoList.SetOwner(kTRUE);
83 fHistoList.SetName(name);
86 //_____________________________________________________________________________
87 AliDielectronHistos::~AliDielectronHistos()
93 if (fList) fList->Clear();
94 delete fReservedWords;
97 //_____________________________________________________________________________
98 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
100 Int_t nbinsX, Double_t xmin, Double_t xmax,
101 UInt_t valTypeX, Bool_t logBinX, TString option)
104 // Default histogram creation 1D case
107 TVectorD *binLimX=0x0;
110 binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
112 binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
114 UserProfile(histClass,name,title,valTypeP,binLimX,valTypeX,option);
117 //_____________________________________________________________________________
118 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
120 Int_t nbinsX, Double_t xmin, Double_t xmax,
121 Int_t nbinsY, Double_t ymin, Double_t ymax,
122 UInt_t valTypeX, UInt_t valTypeY,
123 Bool_t logBinX, Bool_t logBinY, TString option)
126 // Default histogram creation 2D case
128 if (!IsHistogramOk(histClass,name)) return;
130 TVectorD *binLimX=0x0;
131 TVectorD *binLimY=0x0;
134 binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
136 binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
139 binLimY=AliDielectronHelper::MakeLogBinning(nbinsY, ymin, ymax);
141 binLimY=AliDielectronHelper::MakeLinBinning(nbinsY, ymin, ymax);
143 UserProfile(histClass,name,title,valTypeP,binLimX,binLimY,valTypeX,valTypeY,option);
147 //_____________________________________________________________________________
148 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
150 Int_t nbinsX, Double_t xmin, Double_t xmax,
151 Int_t nbinsY, Double_t ymin, Double_t ymax,
152 Int_t nbinsZ, Double_t zmin, Double_t zmax,
153 UInt_t valTypeX, UInt_t valTypeY, UInt_t valTypeZ,
154 Bool_t logBinX, Bool_t logBinY, Bool_t logBinZ, TString option)
157 // Default histogram creation 3D case
159 if (!IsHistogramOk(histClass,name)) return;
161 TVectorD *binLimX=0x0;
162 TVectorD *binLimY=0x0;
163 TVectorD *binLimZ=0x0;
166 binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
168 binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
172 binLimY=AliDielectronHelper::MakeLogBinning(nbinsY, ymin, ymax);
174 binLimY=AliDielectronHelper::MakeLinBinning(nbinsY, ymin, ymax);
178 binLimZ=AliDielectronHelper::MakeLogBinning(nbinsZ, zmin, zmax);
180 binLimZ=AliDielectronHelper::MakeLinBinning(nbinsZ, zmin, zmax);
183 UserProfile(histClass,name,title,valTypeP,binLimX,binLimY,binLimZ,valTypeX,valTypeY,valTypeZ,option);
186 //_____________________________________________________________________________
187 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
190 UInt_t valTypeX, TString option)
193 // Histogram creation 1D case with arbitraty binning
196 TVectorD *binLimX=AliDielectronHelper::MakeArbitraryBinning(binning);
197 UserProfile(histClass,name,title,valTypeP,binLimX,valTypeX,option);
200 //_____________________________________________________________________________
201 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
203 const TVectorD * const binsX,
204 UInt_t valTypeX/*=kNoAutoFill*/, TString option)
207 // Histogram creation 1D case with arbitraty binning X
208 // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
212 isOk&=IsHistogramOk(histClass,name);
218 hist=new TH1F(name,title,binsX->GetNrows()-1,binsX->GetMatrixArray());
220 TString opt=""; Double_t pmin=0., pmax=0.;
221 if(!option.IsNull()) {
222 TObjArray *arr=option.Tokenize(";");
224 opt=((TObjString*)arr->At(0))->GetString();
225 if(arr->GetEntriesFast()>1) pmin=(((TObjString*)arr->At(1))->GetString()).Atof();
226 if(arr->GetEntriesFast()>2) pmax=(((TObjString*)arr->At(2))->GetString()).Atof();
229 hist=new TProfile(name,title,binsX->GetNrows()-1,binsX->GetMatrixArray());
230 ((TProfile*)hist)->BuildOptions(pmin,pmax,opt.Data());
231 // printf(" name %s PROFILE options: pmin %.1f pmax %.1f err %s \n",name,((TProfile*)hist)->GetYmin(),((TProfile*)hist)->GetYmax(),((TProfile*)hist)->GetErrorOption() );
234 // store variales in axes
235 UInt_t valType[20] = {0};
236 valType[0]=valTypeX; valType[1]=valTypeP;
237 StoreVariables(hist, valType);
239 // adapt the name and title of the histogram in case they are empty
240 AdaptNameTitle(hist, histClass);
242 Bool_t isReserved=fReservedWords->Contains(histClass);
243 if(valTypeX==kNoAutoFill) hist->SetUniqueID(valTypeX);
245 UserHistogramReservedWords(histClass, hist, 999);
247 UserHistogram(histClass, hist, 999);
253 //_____________________________________________________________________________
254 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
256 const TVectorD * const binsX, const TVectorD * const binsY,
257 UInt_t valTypeX/*=kNoAutoFill*/, UInt_t valTypeY/*=0*/, TString option)
260 // Histogram creation 2D case with arbitraty binning X
261 // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
265 isOk&=IsHistogramOk(histClass,name);
272 hist=new TH2F(name,title,
273 binsX->GetNrows()-1,binsX->GetMatrixArray(),
274 binsY->GetNrows()-1,binsY->GetMatrixArray());
277 TString opt=""; Double_t pmin=0., pmax=0.;
278 if(!option.IsNull()) {
279 TObjArray *arr=option.Tokenize(";");
281 opt=((TObjString*)arr->At(0))->GetString();
282 if(arr->GetEntriesFast()>1) pmin=(((TObjString*)arr->At(1))->GetString()).Atof();
283 if(arr->GetEntriesFast()>2) pmax=(((TObjString*)arr->At(2))->GetString()).Atof();
286 hist=new TProfile2D(name,title,
287 binsX->GetNrows()-1,binsX->GetMatrixArray(),
288 binsY->GetNrows()-1,binsY->GetMatrixArray());
289 ((TProfile2D*)hist)->BuildOptions(pmin,pmax,opt.Data());
290 // printf(" name %s PROFILE options: pmin %.1f pmax %.1f err %s \n",name,((TProfile*)hist)->GetYmin(),((TProfile*)hist)->GetYmax(),((TProfile*)hist)->GetErrorOption() );
293 // store variales in axes
294 UInt_t valType[20] = {0};
295 valType[0]=valTypeX; valType[1]=valTypeY; valType[2]=valTypeP;
296 StoreVariables(hist, valType);
298 // adapt the name and title of the histogram in case they are empty
299 AdaptNameTitle(hist, histClass);
301 Bool_t isReserved=fReservedWords->Contains(histClass);
302 if(valTypeX==kNoAutoFill) hist->SetUniqueID(valTypeX);
304 UserHistogramReservedWords(histClass, hist, 999);
306 UserHistogram(histClass, hist, 999);
314 //_____________________________________________________________________________
315 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
317 const TVectorD * const binsX, const TVectorD * const binsY, const TVectorD * const binsZ,
318 UInt_t valTypeX/*=kNoAutoFill*/, UInt_t valTypeY/*=0*/, UInt_t valTypeZ/*=0*/, TString option)
321 // Histogram creation 3D case with arbitraty binning X
322 // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
326 isOk&=IsHistogramOk(histClass,name);
334 hist=new TH3F(name,title,
335 binsX->GetNrows()-1,binsX->GetMatrixArray(),
336 binsY->GetNrows()-1,binsY->GetMatrixArray(),
337 binsZ->GetNrows()-1,binsZ->GetMatrixArray());
340 TString opt=""; Double_t pmin=0., pmax=0.;
341 if(!option.IsNull()) {
342 TObjArray *arr=option.Tokenize(";");
344 opt=((TObjString*)arr->At(0))->GetString();
345 if(arr->GetEntriesFast()>1) pmin=(((TObjString*)arr->At(1))->GetString()).Atof();
346 if(arr->GetEntriesFast()>2) pmax=(((TObjString*)arr->At(2))->GetString()).Atof();
349 hist=new TProfile3D(name,title,
350 binsX->GetNrows()-1,binsX->GetMatrixArray(),
351 binsY->GetNrows()-1,binsY->GetMatrixArray(),
352 binsZ->GetNrows()-1,binsZ->GetMatrixArray());
353 ((TProfile3D*)hist)->BuildOptions(pmin,pmax,opt.Data());
354 // printf(" name %s PROFILE options: pmin %.1f pmax %.1f err %s \n",name,((TProfile*)hist)->GetYmin(),((TProfile*)hist)->GetYmax(),((TProfile*)hist)->GetErrorOption() );
357 // store variales in axes
358 UInt_t valType[20] = {0};
359 valType[0]=valTypeX; valType[1]=valTypeY; valType[2]=valTypeZ; valType[3]=valTypeP;
360 StoreVariables(hist, valType);
362 // adapt the name and title of the histogram in case they are empty
363 AdaptNameTitle(hist, histClass);
365 Bool_t isReserved=fReservedWords->Contains(histClass);
366 if(valTypeX==kNoAutoFill) hist->SetUniqueID(valTypeX);
368 UserHistogramReservedWords(histClass, hist, 999);
370 UserHistogram(histClass, hist, 999);
378 //_____________________________________________________________________________
379 void AliDielectronHistos::UserHistogram(const char* histClass, Int_t ndim, Int_t *bins, Double_t *mins, Double_t *maxs, UInt_t *vars)
382 // Histogram creation 4-n dimension only with linear binning
386 isOk&=(ndim<21 && ndim>3);
387 if(!isOk) { Warning("UserHistogram","Array sizes should be between 3 and 20. Not adding Histogram to '%s'.", histClass); return; }
389 // set automatic histo name
391 for(Int_t iv=0; iv < ndim; iv++)
392 name+=Form("%s_",AliDielectronVarManager::GetValueName(vars[iv]));
393 name.Resize(name.Length()-1);
395 printf(" name %s \n",name.Data());
396 // name=Form("%s%s_%s_%s%s", (strcmp(histClass,"Pair")==0?"p":""), AliDielectronVarManager::GetValueName(valTypeX), AliDielectronVarManager::GetValueName(valTypeY), AliDielectronVarManager::GetValueName(valTypeZ),
397 // (valTypeP!=999? Form("-%s%s",(option.Contains("s",TString::kIgnoreCase)?"rms":"avg"),AliDielectronVarManager::GetValueName(valTypeP)) : "") );
399 isOk&=IsHistogramOk(histClass,name);
403 hist=new THnD(name.Data(),"", ndim, bins, mins, maxs);
405 // store variales in axes
406 StoreVariables(hist, vars);
408 Bool_t isReserved=fReservedWords->Contains(histClass);
410 UserHistogramReservedWords(histClass, hist, 999);
412 UserHistogram(histClass, hist, 999);
414 printf(" hist %p \n",hist);
418 //_____________________________________________________________________________
419 void AliDielectronHistos::UserSparse(const char* histClass, Int_t ndim, Int_t *bins, Double_t *mins, Double_t *maxs, UInt_t *vars)
422 // THnSparse creation with linear binning
427 // set automatic histo name
429 for(Int_t iv=0; iv < ndim; iv++)
430 name+=Form("%s_",AliDielectronVarManager::GetValueName(vars[iv]));
431 name.Resize(name.Length()-1);
433 printf(" name %s \n",name.Data());
434 // name=Form("%s%s_%s_%s%s", (strcmp(histClass,"Pair")==0?"p":""), AliDielectronVarManager::GetValueName(valTypeX), AliDielectronVarManager::GetValueName(valTypeY), AliDielectronVarManager::GetValueName(valTypeZ),
435 // (valTypeP!=999? Form("-%s%s",(option.Contains("s",TString::kIgnoreCase)?"rms":"avg"),AliDielectronVarManager::GetValueName(valTypeP)) : "") );
437 isOk&=IsHistogramOk(histClass,name);
441 hist=new THnSparseD(name.Data(),"", ndim, bins, mins, maxs);
443 // store variales in axes
444 StoreVariables(hist, vars);
446 Bool_t isReserved=fReservedWords->Contains(histClass);
448 UserHistogramReservedWords(histClass, hist, 999);
450 UserHistogram(histClass, hist, 999);
455 //_____________________________________________________________________________
456 void AliDielectronHistos::UserHistogram(const char* histClass, TObject* hist, UInt_t valTypes)
459 // Add any type of user histogram
462 //special case for the calss Pair. where histograms will be created for all pair classes
463 Bool_t isReserved=fReservedWords->Contains(histClass);
465 UserHistogramReservedWords(histClass, hist, valTypes);
469 if (!IsHistogramOk(histClass,hist->GetName())) return;
470 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
471 // hist->SetDirectory(0);
473 // store variables axis
474 UInt_t valType[20] = {0};
475 // incase valTypes is given old way of extracting variables
477 valType[0]=valTypes%1000; //last three digits
478 valType[1]=valTypes/1000%1000; //second last three digits
479 valType[2]=valTypes/1000000%1000; //third last three digits
480 hist->SetUniqueID(valTypes);
483 // extract variables from axis
484 FillVarArray(hist, valType);
486 StoreVariables(hist, valType);
488 classTable->Add(hist);
491 //_____________________________________________________________________________
492 void AliDielectronHistos::AddClass(const char* histClass)
495 // Add a class of histograms
496 // Several classes can be added by separating them by a ';' e.g. 'class1;class2;class3'
498 TString hists(histClass);
499 TObjArray *arr=hists.Tokenize(";");
502 while ( (o=next()) ){
503 if (fHistoList.FindObject(o->GetName())){
504 Warning("AddClass","Cannot create class '%s' it already exists.",histClass);
507 if (fReservedWords->Contains(o->GetName())){
508 Error("AddClass","Pair is a reserved word, please use another name");
511 THashList *table=new THashList;
512 table->SetOwner(kTRUE);
513 table->SetName(o->GetName());
514 fHistoList.Add(table);
519 //_____________________________________________________________________________
520 void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval)
523 // Fill function 1D case
525 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
527 if (!classTable || !(hist=(TH1*)classTable->FindObject(name)) ){
528 Warning("Fill","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
534 //_____________________________________________________________________________
535 void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval, Double_t yval)
538 // Fill function 2D case
540 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
542 if (!classTable || !(hist=(TH2*)classTable->FindObject(name)) ){
543 Warning("UserHistogram","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
546 hist->Fill(xval,yval);
549 //_____________________________________________________________________________
550 void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval, Double_t yval, Double_t zval)
553 // Fill function 3D case
555 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
557 if (!classTable || !(hist=(TH3*)classTable->FindObject(name)) ){
558 Warning("UserHistogram","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
561 hist->Fill(xval,yval,zval);
564 //_____________________________________________________________________________
565 void AliDielectronHistos::FillClass(const char* histClass, Int_t nValues, const Double_t *values)
568 // Fill class 'histClass' (by name)
571 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
573 Warning("FillClass","Cannot fill class '%s' its not defined. nValues %d",histClass,nValues);
577 TIter nextHist(classTable);
579 while ( (obj=(TObject*)nextHist()) ) FillValues(obj, values);
584 //_____________________________________________________________________________
585 // void AliDielectronHistos::FillClass(const char* histClass, const TVectorD &vals)
590 // FillClass(histClass, vals.GetNrows(), vals.GetMatrixArray());
593 //_____________________________________________________________________________
594 void AliDielectronHistos::UserHistogramReservedWords(const char* histClass, const TObject *hist, UInt_t valTypes)
597 // Creation of histogram for all pair types
599 TString title(hist->GetTitle());
600 // Same Event Like Sign
601 TIter nextClass(&fHistoList);
603 while ( (l=static_cast<THashList*>(nextClass())) ){
604 TString name(l->GetName());
605 if (name.Contains(histClass)){
606 TObject *h=hist->Clone();
607 // Tobject has no function SetDirectory, didn't we need this???
608 // h->SetDirectory(0);
609 ((TH1*)h)->SetTitle(Form("%s %s",title.Data(),l->GetName()));
611 UserHistogram(l->GetName(),h,valTypes);
617 //_____________________________________________________________________________
618 void AliDielectronHistos::DumpToFile(const char* file)
621 // Dump the histogram list to a newly created root file
623 TFile f(file,"recreate");
624 fHistoList.Write(fHistoList.GetName(),TObject::kSingleKey);
628 //_____________________________________________________________________________
629 TObject* AliDielectronHistos::GetHist(const char* histClass, const char* name) const
632 // return object 'name' in 'histClass'
634 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
635 if (!classTable) return 0x0;
636 return classTable->FindObject(name);
639 //_____________________________________________________________________________
640 TH1* AliDielectronHistos::GetHistogram(const char* histClass, const char* name) const
643 // return histogram 'name' in 'histClass'
645 return ((TH1*) GetHist(histClass, name));
648 //_____________________________________________________________________________
649 TObject* AliDielectronHistos::GetHist(const char* cutClass, const char* histClass, const char* name) const
652 // return object from list of list of histograms
653 // this function is thought for retrieving histograms if a list of AliDielectronHistos is set
656 if (!fList) return 0x0;
657 THashList *h=dynamic_cast<THashList*>(fList->FindObject(cutClass));
659 THashList *classTable=dynamic_cast<THashList*>(h->FindObject(histClass));
660 if (!classTable) return 0x0;
661 return classTable->FindObject(name);
664 //_____________________________________________________________________________
665 TH1* AliDielectronHistos::GetHistogram(const char* cutClass, const char* histClass, const char* name) const
668 // return histogram from list of list of histograms
669 // this function is thought for retrieving histograms if a list of AliDielectronHistos is set
671 return ((TH1*) GetHist(cutClass, histClass, name));
674 //_____________________________________________________________________________
675 void AliDielectronHistos::Draw(const Option_t* option)
681 TString drawStr(option);
682 TObjArray *arr=drawStr.Tokenize(";");
687 TObjString *ostr=0x0;
691 while ( (ostr=(TObjString*)nextOpt()) ){
692 currentOpt=ostr->GetString();
693 currentOpt.Remove(TString::kBoth,'\t');
694 currentOpt.Remove(TString::kBoth,' ');
697 if ( currentOpt.Contains(testOpt.Data()) ){
698 drawClasses=currentOpt(testOpt.Length(),currentOpt.Length());
705 // Bool_t same=drawOpt.Contains("same"); //FIXME not yet implemented
710 Error("Draw","When writing to a file you have to create a canvas before opening the file!!!");
718 TIter nextClass(&fHistoList);
719 THashList *classTable=0;
720 // Bool_t first=kTRUE;
721 while ( (classTable=(THashList*)nextClass()) ){
722 //test classes option
723 if (!drawClasses.IsNull() && !drawClasses.Contains(classTable->GetName())) continue;
725 Int_t nPads = classTable->GetEntries();
726 Int_t nCols = (Int_t)TMath::Ceil( TMath::Sqrt(nPads) );
727 Int_t nRows = (Int_t)TMath::Ceil( (Double_t)nPads/(Double_t)nCols );
732 canvasName.Form("c%s_%s",GetName(),classTable->GetName());
733 c=(TCanvas*)gROOT->FindObject(canvasName.Data());
734 if (!c) c=new TCanvas(canvasName.Data(),Form("%s: %s",GetName(),classTable->GetName()));
739 // if (nPads>1) gVirtualPS->NewPage();
741 if (nPads>1) c->Clear();
744 if (nCols>1||nRows>1) c->Divide(nCols,nRows);
746 //loop over histograms and draw them
747 TIter nextHist(classTable);
750 while ( (h=(TH1*)nextHist()) ){
752 if ( (h->InheritsFrom(TH2::Class())) ) drawOpt="colz";
753 if (nCols>1||nRows>1) c->cd(++iPad);
754 if ( TMath::Abs(h->GetXaxis()->GetBinWidth(1)-h->GetXaxis()->GetBinWidth(2))>1e-10 ) gPad->SetLogx();
755 if ( TMath::Abs(h->GetYaxis()->GetBinWidth(1)-h->GetYaxis()->GetBinWidth(2))>1e-10 ) gPad->SetLogy();
756 if ( TMath::Abs(h->GetZaxis()->GetBinWidth(1)-h->GetZaxis()->GetBinWidth(2))>1e-10 ) gPad->SetLogz();
757 TString histOpt=h->GetOption();
759 if (histOpt.Contains("logx")) gPad->SetLogx();
760 if (histOpt.Contains("logy")) gPad->SetLogy();
761 if (histOpt.Contains("logz")) gPad->SetLogz();
762 histOpt.ReplaceAll("logx","");
763 histOpt.ReplaceAll("logy","");
764 histOpt.ReplaceAll("logz","");
765 h->Draw(drawOpt.Data());
772 // if (gVirtualPS) delete c;
775 //_____________________________________________________________________________
776 void AliDielectronHistos::Print(const Option_t* option) const
779 // Print classes and histograms
781 TString optString(option);
783 if (optString.IsNull()) PrintStructure();
789 //_____________________________________________________________________________
790 void AliDielectronHistos::PrintStructure() const
793 // Print classes and histograms in the class to stdout
796 TIter nextClass(&fHistoList);
797 THashList *classTable=0;
798 while ( (classTable=(THashList*)nextClass()) ){
799 TIter nextHist(classTable);
801 printf("+ %s\n",classTable->GetName());
802 while ( (o=nextHist()) )
803 printf("| ->%s\n",o->GetName());
806 TIter nextCutClass(fList);
807 THashList *cutClass=0x0;
808 while ( (cutClass=(THashList*)nextCutClass()) ) {
809 printf("+ %s\n",cutClass->GetName());
810 TIter nextClass(cutClass);
811 THashList *classTable=0;
812 while ( (classTable=(THashList*)nextClass()) ){
813 TIter nextHist(classTable);
815 printf("| + %s\n",classTable->GetName());
816 while ( (o=nextHist()) )
817 printf("| | ->%s\n",o->GetName());
824 //_____________________________________________________________________________
825 void AliDielectronHistos::SetHistogramList(THashList &list, Bool_t setOwner/*=kTRUE*/)
828 // set histogram classes and histograms to this instance. It will take onwnership!
830 ResetHistogramList();
831 TString name(GetName());
832 if (name == "AliDielectronHistos") SetName(list.GetName());
835 while ( (o=next()) ){
839 list.SetOwner(kFALSE);
840 fHistoList.SetOwner(kTRUE);
842 fHistoList.SetOwner(kFALSE);
846 //_____________________________________________________________________________
847 Bool_t AliDielectronHistos::SetCutClass(const char* cutClass)
850 // Assign histogram list according to cutClass
853 if (!fList) return kFALSE;
854 ResetHistogramList();
855 THashList *h=dynamic_cast<THashList*>(fList->FindObject(cutClass));
857 Warning("SetCutClass","cutClass '%s' not found", cutClass);
860 SetHistogramList(*h,kFALSE);
864 //_____________________________________________________________________________
865 Bool_t AliDielectronHistos::IsHistogramOk(const char* histClass, const char* name)
868 // check whether the histogram class exists and the histogram itself does not exist yet
870 Bool_t isReserved=fReservedWords->Contains(histClass);
871 if (!fHistoList.FindObject(histClass)&&!isReserved){
872 Warning("IsHistogramOk","Cannot create histogram. Class '%s' not defined. Please create it using AddClass before.",histClass);
875 if (GetHist(histClass,name)){
876 Warning("IsHistogramOk","Cannot create histogram '%s' in class '%s': It already exists!",name,histClass);
882 // //_____________________________________________________________________________
883 // TIterator* AliDielectronHistos::MakeIterator(Bool_t dir) const
888 // return new TListIter(&fHistoList, dir);
891 //_____________________________________________________________________________
892 void AliDielectronHistos::ReadFromFile(const char* file)
895 // Read histos from file
898 TIter nextKey(f.GetListOfKeys());
900 while ( (key=(TKey*)nextKey()) ){
901 TObject *o=f.Get(key->GetName());
902 THashList *list=dynamic_cast<THashList*>(o);
904 SetHistogramList(*list);
910 //_____________________________________________________________________________
911 void AliDielectronHistos::DrawSame(const char* histName, const Option_t *opt)
914 // Draw all histograms with the same name into one canvas
915 // if option contains 'leg' a legend will be created with the class name as caption
916 // if option contains 'can' a new canvas is created
919 TString optString(opt);
921 Bool_t optLeg=optString.Contains("leg");
922 Bool_t optCan=optString.Contains("can");
927 c=(TCanvas*)gROOT->FindObject(Form("c%s",histName));
928 if (!c) c=new TCanvas(Form("c%s",histName),Form("All '%s' histograms",histName));
933 if (optLeg) leg=new TLegend(.8,.3,.99,.9);
936 TIter next(&fHistoList);
937 THashList *classTable=0;
940 while ( (classTable=(THashList*)next()) ){
941 if ( TH1 *h=(TH1*)classTable->FindObject(histName) ){
943 h->SetLineColor(i+1);
944 h->SetMarkerColor(i+1);
945 h->Draw(i>0?"same":"");
946 if (leg) leg->AddEntry(h,classTable->GetName(),"lp");
948 max=TMath::Max(max,h->GetMaximum());
952 leg->SetFillColor(10);
953 leg->SetY1(.9-i*.05);
956 if (hFirst&&(hFirst->GetYaxis()->GetXmax()<max)){
957 hFirst->SetMaximum(max);
961 //_____________________________________________________________________________
962 void AliDielectronHistos::SetReservedWords(const char* words)
965 // set reserved words
968 (*fReservedWords)=words;
971 //_____________________________________________________________________________
972 void AliDielectronHistos::StoreVariables(TObject *obj, UInt_t valType[20])
978 if (obj->InheritsFrom(TH1::Class())) StoreVariables(static_cast<TH1*>(obj), valType);
979 else if (obj->InheritsFrom(THn::Class())) StoreVariables(static_cast<THn*>(obj), valType);
980 else if (obj->InheritsFrom(THnSparse::Class())) StoreVariables(static_cast<THnSparse*>(obj), valType);
987 //_____________________________________________________________________________
988 void AliDielectronHistos::StoreVariables(TH1 *obj, UInt_t valType[20])
991 // store variables in the axis (special for TProfile3D)
994 Int_t dim = obj->GetDimension();
995 Bool_t bprf = kFALSE;
997 // dimension correction for profiles
998 if(obj->IsA() == TProfile::Class() || obj->IsA() == TProfile2D::Class() || obj->IsA() == TProfile3D::Class()) {
1003 // if( valTypeP!=999 && option.Contains("s",TString::kIgnoreCase) )
1004 // tit += Form(";RMS(%s) %s",AliDielectronVarManager::GetValueLabel(valTypeP), AliDielectronVarManager::GetValueUnit(valTypeP));
1005 // if( valTypeP==999 )
1006 // tit += Form(";#%ss",histClass);
1007 //if(!strlen(title)) title=tit.Data();
1012 obj->SetUniqueID(valType[3]); // Tprofile3D variable
1014 obj->GetZaxis()->SetUniqueID(valType[2]);
1015 obj->GetZaxis()->SetTitle(Form("%s %s",AliDielectronVarManager::GetValueLabel(valType[2]), AliDielectronVarManager::GetValueUnit(valType[2])));
1016 if(bprf && dim<4) obj->GetZaxis()->SetTitle(Form("#LT%s#GT %s",AliDielectronVarManager::GetValueLabel(valType[2]), AliDielectronVarManager::GetValueUnit(valType[2])));
1018 obj->GetYaxis()->SetUniqueID(valType[1]);
1019 obj->GetYaxis()->SetTitle(Form("%s %s", AliDielectronVarManager::GetValueLabel(valType[1]), AliDielectronVarManager::GetValueUnit(valType[1])));
1020 if(bprf && dim<3) obj->GetYaxis()->SetTitle(Form("#LT%s#GT %s",AliDielectronVarManager::GetValueLabel(valType[1]), AliDielectronVarManager::GetValueUnit(valType[1])));
1022 obj->GetXaxis()->SetUniqueID(valType[0]);
1023 obj->GetXaxis()->SetTitle(Form("%s %s", AliDielectronVarManager::GetValueLabel(valType[0]), AliDielectronVarManager::GetValueUnit(valType[0])));
1029 //_____________________________________________________________________________
1030 void AliDielectronHistos::StoreVariables(THn *obj, UInt_t valType[20])
1033 // store variables in the axis
1036 Int_t dim = obj->GetNdimensions();
1038 for(Int_t it=0; it<dim; it++) {
1039 obj->GetAxis(it)->SetUniqueID(valType[it]);
1040 obj->GetAxis(it)->SetTitle(Form("%s %s", AliDielectronVarManager::GetValueLabel(valType[it]), AliDielectronVarManager::GetValueUnit(valType[it])));
1046 //_____________________________________________________________________________
1047 void AliDielectronHistos::StoreVariables(THnSparse *obj, UInt_t valType[20])
1050 // store variables in the axis
1053 Int_t dim = obj->GetNdimensions();
1055 for(Int_t it=0; it<dim; it++) {
1056 obj->GetAxis(it)->SetUniqueID(valType[it]);
1057 obj->GetAxis(it)->SetTitle(Form("%s %s", AliDielectronVarManager::GetValueLabel(valType[it]), AliDielectronVarManager::GetValueUnit(valType[it])));
1063 //_____________________________________________________________________________
1064 void AliDielectronHistos::FillValues(TObject *obj, const Double_t *values)
1070 if (obj->InheritsFrom(TH1::Class())) FillValues(static_cast<TH1*>(obj), values);
1071 else if (obj->InheritsFrom(THn::Class())) FillValues(static_cast<THn*>(obj), values);
1072 else if (obj->InheritsFrom(THnSparse::Class())) FillValues(static_cast<THnSparse*>(obj), values);
1078 //_____________________________________________________________________________
1079 void AliDielectronHistos::FillValues(TH1 *obj, const Double_t *values)
1082 // fill values for TH1 inherted classes
1085 Int_t dim = obj->GetDimension();
1086 Bool_t bprf = kFALSE;
1087 // UInt_t nValues = (UInt_t) AliDielectronVarManager::kNMaxValues;
1089 UInt_t valueTypes=obj->GetUniqueID();
1090 if (valueTypes==(UInt_t)kNoAutoFill) return;
1092 if(obj->IsA() == TProfile::Class() || obj->IsA() == TProfile2D::Class() || obj->IsA() == TProfile3D::Class())
1095 UInt_t value1=obj->GetXaxis()->GetUniqueID();
1096 UInt_t value2=obj->GetYaxis()->GetUniqueID();
1097 UInt_t value3=obj->GetZaxis()->GetUniqueID();
1098 UInt_t value4=obj->GetUniqueID(); // get profile var stored in the unique ID
1100 // if (value1>=(UInt_t)nValues||value2>=(UInt_t)nValues||value3>=(UInt_t)nValues||(value4>=(UInt_t)nValues && value4!=999)) {
1101 // Warning("FillClass","One of the values is out of range. Not filling Histogram '%s/%s'.", histClass, obj->GetName());
1107 if(!bprf) obj->Fill(values[value1]); // histograms
1108 else ((TProfile*)obj)->Fill(values[value1],values[value2]); // profiles
1111 if(!bprf) ((TH2*)obj)->Fill(values[value1],values[value2]);
1112 else ((TProfile2D*)obj)->Fill(values[value1],values[value2],values[value3]);
1115 if(!bprf) ((TH3*)obj)->Fill(values[value1],values[value2],values[value3]);
1116 else ((TProfile3D*)obj)->Fill(values[value1],values[value2],values[value3],values[value4]);
1123 //_____________________________________________________________________________
1124 void AliDielectronHistos::FillValues(THn *obj, const Double_t *values)
1127 // fill values for THn inherted classes
1130 const Int_t dim = obj->GetNdimensions();
1132 UInt_t valueTypes=obj->GetUniqueID();
1133 if (valueTypes==(UInt_t)kNoAutoFill) return;
1136 for(Int_t it=0; it<dim; it++) fill[it] = values[obj->GetAxis(it)->GetUniqueID()];
1142 //_____________________________________________________________________________
1143 void AliDielectronHistos::FillValues(THnSparse *obj, const Double_t *values)
1146 // fill values for THnSparse inherted classes
1149 const Int_t dim = obj->GetNdimensions();
1151 UInt_t valueTypes=obj->GetUniqueID();
1152 if (valueTypes==(UInt_t)kNoAutoFill) return;
1155 for(Int_t it=0; it<dim; it++) {
1156 fill[it] = values[obj->GetAxis(it)->GetUniqueID()];
1163 //_____________________________________________________________________________
1164 void AliDielectronHistos::FillVarArray(TObject *obj, UInt_t *valType)
1167 // extract variables stored in the axis (special for TProfile3D)
1172 // printf(" fillvararray %s \n",obj->GetName());
1174 if (obj->InheritsFrom(TH1::Class())) {
1175 valType[0]=((TH1*)obj)->GetXaxis()->GetUniqueID();
1176 valType[1]=((TH1*)obj)->GetYaxis()->GetUniqueID();
1177 valType[2]=((TH1*)obj)->GetZaxis()->GetUniqueID();
1178 valType[3]=((TH1*)obj)->GetUniqueID(); // tprofile var stored in unique ID
1180 else if (obj->InheritsFrom(THn::Class())) {
1181 for(Int_t it=0; it<((THn*)obj)->GetNdimensions(); it++)
1182 valType[it]=((THn*)obj)->GetAxis(it)->GetUniqueID();
1184 else if (obj->InheritsFrom(THnSparse::Class())) {
1185 for(Int_t it=0; it<((THnSparse*)obj)->GetNdimensions(); it++)
1186 valType[it]=((THnSparse*)obj)->GetAxis(it)->GetUniqueID();
1192 //_____________________________________________________________________________
1193 void AliDielectronHistos::AdaptNameTitle(TH1 *hist, const char* histClass) {
1196 // adapt name and title of the histogram
1199 Int_t dim = hist->GetDimension();
1200 TString currentName = hist->GetName();
1201 TString currentTitle = hist->GetTitle();
1204 Bool_t bname = (currentName.IsNull());
1205 Bool_t btitle = (currentTitle.IsNull());
1206 Bool_t bprf = kFALSE;
1207 if(hist->IsA() == TProfile::Class() || hist->IsA() == TProfile2D::Class() || hist->IsA() == TProfile3D::Class())
1210 UInt_t varx = hist->GetXaxis()->GetUniqueID();
1211 UInt_t vary = hist->GetYaxis()->GetUniqueID();
1212 UInt_t varz = hist->GetZaxis()->GetUniqueID();
1213 UInt_t varp = hist->GetUniqueID();
1215 // store titles in the axis
1219 hist->GetXaxis()->SetTitle(Form("%s %s",
1220 AliDielectronVarManager::GetValueLabel(varx),
1221 AliDielectronVarManager::GetValueUnit(varx))
1223 hist->GetYaxis()->SetTitle(Form("%s %s",
1224 AliDielectronVarManager::GetValueLabel(vary),
1225 AliDielectronVarManager::GetValueUnit(vary))
1227 hist->GetZaxis()->SetTitle(Form("%s %s",
1228 AliDielectronVarManager::GetValueLabel(varz),
1229 AliDielectronVarManager::GetValueUnit(varz))
1232 hist->GetXaxis()->SetTitle(Form("%s %s",
1233 AliDielectronVarManager::GetValueLabel(varx),
1234 AliDielectronVarManager::GetValueUnit(varx))
1236 hist->GetYaxis()->SetTitle(Form("%s %s",
1237 AliDielectronVarManager::GetValueLabel(vary),
1238 AliDielectronVarManager::GetValueUnit(vary))
1240 hist->GetZaxis()->SetTitle(Form("#%ss",histClass));
1242 hist->GetZaxis()->SetTitle(Form("#LT%s#GT %s",
1243 AliDielectronVarManager::GetValueLabel(varz),
1244 AliDielectronVarManager::GetValueUnit(varz))
1247 hist->GetXaxis()->SetTitle(Form("%s %s",
1248 AliDielectronVarManager::GetValueLabel(varx),
1249 AliDielectronVarManager::GetValueUnit(varx))
1251 hist->GetYaxis()->SetTitle(Form("#%ss",histClass));
1253 hist->GetYaxis()->SetTitle(Form("#LT%s#GT %s",
1254 AliDielectronVarManager::GetValueLabel(vary),
1255 AliDielectronVarManager::GetValueUnit(vary))
1259 // create an unique name
1263 currentName+=Form("%s_",AliDielectronVarManager::GetValueName(varx));
1264 currentName+=Form("%s_",AliDielectronVarManager::GetValueName(vary));
1265 currentName+=Form("%s",AliDielectronVarManager::GetValueName(varz));
1266 if(bprf) currentName+=Form("-%savg",AliDielectronVarManager::GetValueName(varp));
1269 currentName+=Form("%s_",AliDielectronVarManager::GetValueName(varx));
1270 currentName+=Form("%s",AliDielectronVarManager::GetValueName(vary));
1271 if(bprf) currentName+=Form("-%savg",AliDielectronVarManager::GetValueName(varz));
1274 currentName+=Form("%s",AliDielectronVarManager::GetValueName(varx));
1275 if(bprf) currentName+=Form("-%savg",AliDielectronVarManager::GetValueName(vary));
1278 // to differentiate btw. leg and pair histos
1279 if(!strcmp(histClass,"Pair")) currentName.Prepend("p");
1280 hist->SetName(currentName.Data());
1283 // if( valTypeP!=999 && option.Contains("s",TString::kIgnoreCase) )
1284 // tit += Form(";RMS(%s) %s",AliDielectronVarManager::GetValueLabel(valTypeP), AliDielectronVarManager::GetValueUnit(valTypeP));
1285 //if(!strlen(title)) title=tit.Data();