]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGDQ/dielectron/AliDielectronHistos.cxx
396b87dd776a5cc8ae52137e6f8bdcb898b0e5fb
[u/mrichter/AliRoot.git] / PWGDQ / dielectron / AliDielectronHistos.cxx
1 /*************************************************************************
2 * Copyright(c) 1998-2009, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
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 **************************************************************************/
15
16 //
17 // Generic Histogram container with support for groups and filling of groups by passing
18 // a vector of data
19 //
20 // Authors: 
21 //   Jens Wiechula <Jens.Wiechula@cern.ch> 
22 //   Julian Book   <Julian.Book@cern.ch> 
23 // 
24
25 #include <TH1.h>
26 #include <TH1F.h>
27 #include <TH2.h>
28 #include <TH3.h>
29 #include <THn.h>
30 #include <TProfile.h>
31 #include <TProfile2D.h>
32 #include <TProfile3D.h>
33 #include <THnSparse.h>
34 #include <TCollection.h>
35 #include <THashList.h>
36 #include <TString.h>
37 #include <TObjString.h>
38 #include <TObjArray.h>
39 #include <TFile.h>
40 #include <TError.h>
41 #include <TCanvas.h>
42 #include <TMath.h>
43 #include <TROOT.h>
44 #include <TLegend.h>
45 #include <TKey.h>
46 #include <TAxis.h>
47 #include <TVirtualPS.h>
48 #include <TVectorD.h>
49
50 #include "AliDielectronHelper.h"
51 #include "AliDielectronVarManager.h"
52 #include "AliDielectronHistos.h"
53
54 ClassImp(AliDielectronHistos)
55
56
57 AliDielectronHistos::AliDielectronHistos() :
58 //   TCollection(),
59   TNamed("AliDielectronHistos","Dielectron Histogram Container"),
60   fHistoList(),
61   fList(0x0),
62   fReservedWords(new TString)
63 {
64   //
65   // Default constructor
66   //
67   fHistoList.SetOwner(kTRUE);
68   fHistoList.SetName("Dielectron_Histos");
69 }
70
71 //_____________________________________________________________________________
72 AliDielectronHistos::AliDielectronHistos(const char* name, const char* title) :
73 //   TCollection(),
74   TNamed(name, title),
75   fHistoList(),
76   fList(0x0),
77   fReservedWords(new TString)
78 {
79   //
80   // TNamed constructor
81   //
82   fHistoList.SetOwner(kTRUE);
83   fHistoList.SetName(name);
84 }
85
86 //_____________________________________________________________________________
87 AliDielectronHistos::~AliDielectronHistos()
88 {
89   //
90   // Destructor
91   //
92   fHistoList.Clear();
93   if (fList) fList->Clear();
94   delete fReservedWords;
95 }
96
97 //_____________________________________________________________________________
98 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
99                                       UInt_t valTypeP,
100                                       Int_t nbinsX, Double_t xmin, Double_t xmax,
101                                       UInt_t valTypeX, Bool_t logBinX, TString option)
102 {
103   //
104   // Default histogram creation 1D case
105   //
106
107   TVectorD *binLimX=0x0;
108   
109   if (logBinX) {
110     binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
111   } else {
112     binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
113   }
114   UserProfile(histClass,name,title,valTypeP,binLimX,valTypeX,option);
115 }
116
117 //_____________________________________________________________________________
118 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
119                                       UInt_t valTypeP,
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)
124 {
125   //
126   // Default histogram creation 2D case
127   //
128   if (!IsHistogramOk(histClass,name)) return;
129
130   TVectorD *binLimX=0x0;
131   TVectorD *binLimY=0x0;
132   
133   if (logBinX) {
134     binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
135   } else {
136     binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
137   }
138   if (logBinY) {
139     binLimY=AliDielectronHelper::MakeLogBinning(nbinsY, ymin, ymax);
140   } else {
141     binLimY=AliDielectronHelper::MakeLinBinning(nbinsY, ymin, ymax);
142   }
143   UserProfile(histClass,name,title,valTypeP,binLimX,binLimY,valTypeX,valTypeY,option);
144 }
145
146
147 //_____________________________________________________________________________
148 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
149                                       UInt_t valTypeP,
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)
155 {
156   //
157   // Default histogram creation 3D case
158   //
159   if (!IsHistogramOk(histClass,name)) return;
160
161   TVectorD *binLimX=0x0;
162   TVectorD *binLimY=0x0;
163   TVectorD *binLimZ=0x0;
164   
165   if (logBinX) {
166     binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
167   } else {
168     binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
169   }
170   
171   if (logBinY) {
172     binLimY=AliDielectronHelper::MakeLogBinning(nbinsY, ymin, ymax);
173   } else {
174     binLimY=AliDielectronHelper::MakeLinBinning(nbinsY, ymin, ymax);
175   }
176   
177   if (logBinZ) {
178     binLimZ=AliDielectronHelper::MakeLogBinning(nbinsZ, zmin, zmax);
179   } else {
180     binLimZ=AliDielectronHelper::MakeLinBinning(nbinsZ, zmin, zmax);
181   }
182
183   UserProfile(histClass,name,title,valTypeP,binLimX,binLimY,binLimZ,valTypeX,valTypeY,valTypeZ,option);
184 }
185
186 //_____________________________________________________________________________
187 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
188                                       UInt_t valTypeP,
189                                       const char* binning,
190                                       UInt_t valTypeX, TString option)
191 {
192   //
193   // Histogram creation 1D case with arbitraty binning
194   //
195
196   TVectorD *binLimX=AliDielectronHelper::MakeArbitraryBinning(binning);
197   UserProfile(histClass,name,title,valTypeP,binLimX,valTypeX,option);
198 }
199
200 //_____________________________________________________________________________
201 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
202                                       UInt_t valTypeP,
203                                       const TVectorD * const binsX,
204                                       UInt_t valTypeX/*=kNoAutoFill*/, TString option)
205 {
206   //
207   // Histogram creation 1D case with arbitraty binning X
208   // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
209   //
210
211   Bool_t isOk=kTRUE;
212   isOk&=IsHistogramOk(histClass,name);
213   isOk&=(binsX!=0x0);
214   TH1 *hist=0x0;
215
216   if (isOk){
217     if(valTypeP==999)
218       hist=new TH1F(name,title,binsX->GetNrows()-1,binsX->GetMatrixArray());
219     else {
220       TString opt=""; Double_t pmin=0., pmax=0.;
221       if(!option.IsNull()) {
222         TObjArray *arr=option.Tokenize(";");
223         arr->SetOwner();
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();
227         delete arr;
228       }
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() );
232     }
233
234     // store variales in axes
235     UInt_t valType[20] = {0};
236     valType[0]=valTypeX;     valType[1]=valTypeP;
237     StoreVariables(hist, valType);
238
239     // adapt the name and title of the histogram in case they are empty
240     AdaptNameTitle(hist, histClass);
241
242     Bool_t isReserved=fReservedWords->Contains(histClass);
243     if(valTypeX==kNoAutoFill) hist->SetUniqueID(valTypeX);
244     if (isReserved)
245       UserHistogramReservedWords(histClass, hist, 999);
246     else
247       UserHistogram(histClass, hist, 999);
248   }
249   
250   delete binsX;
251 }
252
253 //_____________________________________________________________________________
254 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
255                                       UInt_t valTypeP,
256                                       const TVectorD * const binsX, const TVectorD * const binsY,
257                                       UInt_t valTypeX/*=kNoAutoFill*/, UInt_t valTypeY/*=0*/, TString option)
258 {
259   //
260   // Histogram creation 2D case with arbitraty binning X
261   // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
262   //
263
264   Bool_t isOk=kTRUE;
265   isOk&=IsHistogramOk(histClass,name);
266   isOk&=(binsX!=0x0);
267   isOk&=(binsY!=0x0);
268   TH1 *hist=0x0;
269
270   if (isOk){
271     if(valTypeP==999) {
272       hist=new TH2F(name,title,
273                     binsX->GetNrows()-1,binsX->GetMatrixArray(),
274                     binsY->GetNrows()-1,binsY->GetMatrixArray()); 
275     }
276     else  {
277       TString opt=""; Double_t pmin=0., pmax=0.;
278       if(!option.IsNull()) {
279         TObjArray *arr=option.Tokenize(";");
280         arr->SetOwner();
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();
284         delete arr;
285       }
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() );
291     }
292
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);
297
298     // adapt the name and title of the histogram in case they are empty
299     AdaptNameTitle(hist, histClass);
300
301     Bool_t isReserved=fReservedWords->Contains(histClass);
302     if(valTypeX==kNoAutoFill) hist->SetUniqueID(valTypeX);
303     if (isReserved)
304       UserHistogramReservedWords(histClass, hist, 999);
305     else
306       UserHistogram(histClass, hist, 999);
307   }
308   
309   delete binsX;
310   delete binsY;
311   
312 }
313
314 //_____________________________________________________________________________
315 void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
316                                       UInt_t valTypeP,
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)
319 {
320   //
321   // Histogram creation 3D case with arbitraty binning X
322   // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
323   //
324
325   Bool_t isOk=kTRUE;
326   isOk&=IsHistogramOk(histClass,name);
327   isOk&=(binsX!=0x0);
328   isOk&=(binsY!=0x0);
329   isOk&=(binsZ!=0x0);
330   TH1 *hist=0x0;
331
332   if (isOk) {
333     if(valTypeP==999) {
334       hist=new TH3F(name,title,
335                     binsX->GetNrows()-1,binsX->GetMatrixArray(),
336                     binsY->GetNrows()-1,binsY->GetMatrixArray(),
337                     binsZ->GetNrows()-1,binsZ->GetMatrixArray());
338     }
339     else {
340       TString opt=""; Double_t pmin=0., pmax=0.;
341       if(!option.IsNull()) {
342         TObjArray *arr=option.Tokenize(";");
343         arr->SetOwner();
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();
347         delete arr;
348       }
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() );
355     }
356
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);
361
362     // adapt the name and title of the histogram in case they are empty
363     AdaptNameTitle(hist, histClass);
364
365     Bool_t isReserved=fReservedWords->Contains(histClass);
366     if(valTypeX==kNoAutoFill) hist->SetUniqueID(valTypeX);
367     if (isReserved)
368       UserHistogramReservedWords(histClass, hist, 999);
369     else
370       UserHistogram(histClass, hist, 999);
371   }
372   
373   delete binsX;
374   delete binsY;
375   delete binsZ;
376 }
377
378 //_____________________________________________________________________________
379 void AliDielectronHistos::UserHistogram(const char* histClass, Int_t ndim, Int_t *bins, Double_t *mins, Double_t *maxs, UInt_t *vars)
380 {
381   //
382   // Histogram creation 4-n dimension only with linear binning
383   //
384
385   Bool_t isOk=kTRUE;
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; }
388
389   // set automatic histo name
390   TString name;
391   for(Int_t iv=0; iv < ndim; iv++)
392     name+=Form("%s_",AliDielectronVarManager::GetValueName(vars[iv]));
393   name.Resize(name.Length()-1);
394
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)) : "") );
398
399   isOk&=IsHistogramOk(histClass,name);
400
401   THnD *hist;
402   if (isOk) {
403     hist=new THnD(name.Data(),"", ndim, bins, mins, maxs);
404
405     // store variales in axes
406     StoreVariables(hist, vars);
407
408     Bool_t isReserved=fReservedWords->Contains(histClass);
409     if (isReserved)
410       UserHistogramReservedWords(histClass, hist, 999);
411     else
412       UserHistogram(histClass, hist, 999);
413
414     printf(" hist %p \n",hist);
415   }
416 }
417
418 //_____________________________________________________________________________
419 void AliDielectronHistos::UserSparse(const char* histClass, Int_t ndim, Int_t *bins, Double_t *mins, Double_t *maxs, UInt_t *vars)
420 {
421   //
422   // THnSparse creation with linear binning
423   //
424
425   Bool_t isOk=kTRUE;
426
427   // set automatic histo name
428   TString name;
429   for(Int_t iv=0; iv < ndim; iv++)
430     name+=Form("%s_",AliDielectronVarManager::GetValueName(vars[iv]));
431   name.Resize(name.Length()-1);
432
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)) : "") );
436
437   isOk&=IsHistogramOk(histClass,name);
438
439   THnSparseD *hist;
440   if (isOk) {
441     hist=new THnSparseD(name.Data(),"", ndim, bins, mins, maxs);
442
443     // store variales in axes
444     StoreVariables(hist, vars);
445
446     Bool_t isReserved=fReservedWords->Contains(histClass);
447     if (isReserved)
448       UserHistogramReservedWords(histClass, hist, 999);
449     else
450       UserHistogram(histClass, hist, 999);
451
452   }
453 }
454
455 //_____________________________________________________________________________
456 void AliDielectronHistos::UserHistogram(const char* histClass, TObject* hist, UInt_t valTypes)
457 {
458   //
459   // Add any type of user histogram
460   //
461
462   //special case for the calss Pair. where histograms will be created for all pair classes
463   Bool_t isReserved=fReservedWords->Contains(histClass);
464   if (isReserved) {
465     UserHistogramReservedWords(histClass, hist, valTypes);
466     return;
467   }
468
469   if (!IsHistogramOk(histClass,hist->GetName())) return;
470   THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
471   //  hist->SetDirectory(0);
472
473   // store variables axis
474   UInt_t valType[20] = {0};
475   // incase valTypes is given old way of extracting variables
476   if(valTypes!=999) {
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);
481   }
482   else {
483     // extract variables from axis
484     FillVarArray(hist, valType);
485   }
486   StoreVariables(hist, valType);
487
488   classTable->Add(hist);
489 }
490
491 //_____________________________________________________________________________
492 void AliDielectronHistos::AddClass(const char* histClass)
493 {
494   //
495   // Add a class of histograms
496   // Several classes can be added by separating them by a ';' e.g. 'class1;class2;class3'
497   //
498   TString hists(histClass);
499   TObjArray *arr=hists.Tokenize(";");
500   TIter next(arr);
501   TObject *o=0;
502   while ( (o=next()) ){
503     if (fHistoList.FindObject(o->GetName())){
504       Warning("AddClass","Cannot create class '%s' it already exists.",histClass);
505       continue;
506     }
507     if (fReservedWords->Contains(o->GetName())){
508       Error("AddClass","Pair is a reserved word, please use another name");
509       continue;
510     }
511     THashList *table=new THashList;
512     table->SetOwner(kTRUE);
513     table->SetName(o->GetName());
514     fHistoList.Add(table);
515   }
516   delete arr;
517 }
518
519 //_____________________________________________________________________________
520 void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval)
521 {
522   //
523   // Fill function 1D case
524   //
525   THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
526   TH1* hist=0;
527   if (!classTable || !(hist=(TH1*)classTable->FindObject(name)) ){
528     Warning("Fill","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
529     return;
530   }
531   hist->Fill(xval);
532 }
533
534 //_____________________________________________________________________________
535 void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval, Double_t yval)
536 {
537   //
538   // Fill function 2D case
539   //
540   THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
541   TH2* hist=0;
542   if (!classTable || !(hist=(TH2*)classTable->FindObject(name)) ){
543     Warning("UserHistogram","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
544     return;
545   }
546   hist->Fill(xval,yval);
547 }
548
549 //_____________________________________________________________________________
550 void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval, Double_t yval, Double_t zval)
551 {
552   //
553   // Fill function 3D case
554   //
555   THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
556   TH3* hist=0;
557   if (!classTable || !(hist=(TH3*)classTable->FindObject(name)) ){
558     Warning("UserHistogram","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
559     return;
560   }
561   hist->Fill(xval,yval,zval);
562 }
563
564 //_____________________________________________________________________________
565 void AliDielectronHistos::FillClass(const char* histClass, Int_t nValues, const Double_t *values)
566 {
567   //
568   // Fill class 'histClass' (by name)
569   //
570
571   THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
572   if (!classTable){
573     Warning("FillClass","Cannot fill class '%s' its not defined. nValues %d",histClass,nValues);
574     return;
575   }
576
577   TIter nextHist(classTable);
578   TObject *obj=0;
579   while ( (obj=(TObject*)nextHist()) )  FillValues(obj, values);
580
581   return;
582 }
583
584 //_____________________________________________________________________________
585 // void AliDielectronHistos::FillClass(const char* histClass, const TVectorD &vals)
586 // {
587 //   //
588 //   //
589 //   //
590 //   FillClass(histClass, vals.GetNrows(), vals.GetMatrixArray());
591 // }
592
593 //_____________________________________________________________________________
594 void AliDielectronHistos::UserHistogramReservedWords(const char* histClass, const TObject *hist, UInt_t valTypes)
595 {
596   //
597   // Creation of histogram for all pair types
598   //
599   TString title(hist->GetTitle());
600   // Same Event Like Sign
601   TIter nextClass(&fHistoList);
602   THashList *l=0;
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()));
610
611       UserHistogram(l->GetName(),h,valTypes);
612     }
613   }
614   delete hist;
615 }
616
617 //_____________________________________________________________________________
618 void AliDielectronHistos::DumpToFile(const char* file)
619 {
620   //
621   // Dump the histogram list to a newly created root file
622   //
623   TFile f(file,"recreate");
624   fHistoList.Write(fHistoList.GetName(),TObject::kSingleKey);
625   f.Close();
626 }
627
628 //_____________________________________________________________________________
629 TObject* AliDielectronHistos::GetHist(const char* histClass, const char* name) const
630 {
631   //
632   // return object 'name' in 'histClass'
633   //
634   THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
635   if (!classTable) return 0x0;
636   return classTable->FindObject(name);
637 }
638
639 //_____________________________________________________________________________
640 TH1* AliDielectronHistos::GetHistogram(const char* histClass, const char* name) const
641 {
642   //
643   // return histogram 'name' in 'histClass'
644   //
645   return ((TH1*) GetHist(histClass, name));
646 }
647
648 //_____________________________________________________________________________
649 TObject* AliDielectronHistos::GetHist(const char* cutClass, const char* histClass, const char* name) const
650 {
651   //
652   // return object from list of list of histograms
653   // this function is thought for retrieving histograms if a list of AliDielectronHistos is set
654   //
655   
656   if (!fList) return 0x0;
657   THashList *h=dynamic_cast<THashList*>(fList->FindObject(cutClass));
658   if (!h)return 0x0;
659   THashList *classTable=dynamic_cast<THashList*>(h->FindObject(histClass));
660   if (!classTable) return 0x0;
661   return classTable->FindObject(name);
662 }
663
664 //_____________________________________________________________________________
665 TH1* AliDielectronHistos::GetHistogram(const char* cutClass, const char* histClass, const char* name) const
666 {
667   //
668   // return histogram from list of list of histograms
669   // this function is thought for retrieving histograms if a list of AliDielectronHistos is set
670   //
671   return ((TH1*) GetHist(cutClass, histClass, name));
672 }
673
674 //_____________________________________________________________________________
675 void AliDielectronHistos::Draw(const Option_t* option)
676 {
677   //
678   // Draw histograms
679   //
680
681   TString drawStr(option);
682   TObjArray *arr=drawStr.Tokenize(";");
683   arr->SetOwner();
684   TIter nextOpt(arr);
685
686   TString drawClasses;
687   TObjString *ostr=0x0;
688
689   TString currentOpt;
690   TString testOpt;
691   while ( (ostr=(TObjString*)nextOpt()) ){
692     currentOpt=ostr->GetString();
693     currentOpt.Remove(TString::kBoth,'\t');
694     currentOpt.Remove(TString::kBoth,' ');
695
696     testOpt="classes=";
697     if ( currentOpt.Contains(testOpt.Data()) ){
698       drawClasses=currentOpt(testOpt.Length(),currentOpt.Length());
699     }
700   }
701
702   delete arr;
703   drawStr.ToLower();
704   //optionsfList
705 //   Bool_t same=drawOpt.Contains("same"); //FIXME not yet implemented
706
707   TCanvas *c=0x0;
708   if (gVirtualPS) {
709     if (!gPad){
710       Error("Draw","When writing to a file you have to create a canvas before opening the file!!!");
711       return;
712     }
713     c=gPad->GetCanvas();
714     c->cd();
715 //     c=new TCanvas;
716   }
717   
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;
724     //optimised division
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 );
728
729     //create canvas
730     if (!gVirtualPS){
731       TString canvasName;
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()));
735       c->Clear();
736     } else {
737 //       if (first){
738 //         first=kFALSE;
739 //         if (nPads>1) gVirtualPS->NewPage();
740 //       } else {
741         if (nPads>1) c->Clear();
742 //       }
743     }
744     if (nCols>1||nRows>1) c->Divide(nCols,nRows);
745     
746     //loop over histograms and draw them
747     TIter nextHist(classTable);
748     Int_t iPad=0;
749     TH1 *h=0;
750     while ( (h=(TH1*)nextHist()) ){
751       TString drawOpt;
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();
758       histOpt.ToLower();
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());
766     }
767     if (gVirtualPS) {
768       c->Update();
769     }
770     
771   }
772 //   if (gVirtualPS) delete c;
773 }
774
775 //_____________________________________________________________________________
776 void AliDielectronHistos::Print(const Option_t* option) const
777 {
778   //
779   // Print classes and histograms
780   //
781   TString optString(option);
782
783   if (optString.IsNull()) PrintStructure();
784
785
786
787 }
788
789 //_____________________________________________________________________________
790 void AliDielectronHistos::PrintStructure() const
791 {
792   //
793   // Print classes and histograms in the class to stdout
794   //
795   if (!fList){
796     TIter nextClass(&fHistoList);
797     THashList *classTable=0;
798     while ( (classTable=(THashList*)nextClass()) ){
799       TIter nextHist(classTable);
800       TObject *o=0;
801       printf("+ %s\n",classTable->GetName());
802       while ( (o=nextHist()) )
803         printf("| ->%s\n",o->GetName());
804     }
805   } else {
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);
814         TObject *o=0;
815         printf("|  + %s\n",classTable->GetName());
816         while ( (o=nextHist()) )
817           printf("|  | ->%s\n",o->GetName());
818       }
819       
820     }
821   }
822 }
823
824 //_____________________________________________________________________________
825 void AliDielectronHistos::SetHistogramList(THashList &list, Bool_t setOwner/*=kTRUE*/)
826 {
827   //
828   // set histogram classes and histograms to this instance. It will take onwnership!
829   //
830   ResetHistogramList();
831   TString name(GetName());
832   if (name == "AliDielectronHistos") SetName(list.GetName());
833   TIter next(&list);
834   TObject *o;
835   while ( (o=next()) ){
836     fHistoList.Add(o);
837   }
838   if (setOwner){
839     list.SetOwner(kFALSE);
840     fHistoList.SetOwner(kTRUE);
841   } else {
842     fHistoList.SetOwner(kFALSE);
843   }
844 }
845
846 //_____________________________________________________________________________
847 Bool_t AliDielectronHistos::SetCutClass(const char* cutClass)
848 {
849   //
850   // Assign histogram list according to cutClass
851   //
852
853   if (!fList) return kFALSE;
854   ResetHistogramList();
855   THashList *h=dynamic_cast<THashList*>(fList->FindObject(cutClass));
856   if (!h) {
857     Warning("SetCutClass","cutClass '%s' not found", cutClass);
858     return kFALSE;
859   }
860   SetHistogramList(*h,kFALSE);
861   return kTRUE;
862 }
863
864 //_____________________________________________________________________________
865 Bool_t AliDielectronHistos::IsHistogramOk(const char* histClass, const char* name)
866 {
867   //
868   // check whether the histogram class exists and the histogram itself does not exist yet
869   //
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);
873     return kFALSE;
874   }
875   if (GetHist(histClass,name)){
876     Warning("IsHistogramOk","Cannot create histogram '%s' in class '%s': It already exists!",name,histClass);
877     return kFALSE;
878   }
879   return kTRUE;
880 }
881
882 // //_____________________________________________________________________________
883 // TIterator* AliDielectronHistos::MakeIterator(Bool_t dir) const
884 // {
885 //   //
886 //   //
887 //   //
888 //   return new TListIter(&fHistoList, dir);
889 // }
890
891 //_____________________________________________________________________________
892 void AliDielectronHistos::ReadFromFile(const char* file)
893 {
894   //
895   // Read histos from file
896   //
897   TFile f(file);
898   TIter nextKey(f.GetListOfKeys());
899   TKey *key=0;
900   while ( (key=(TKey*)nextKey()) ){
901     TObject *o=f.Get(key->GetName());
902     THashList *list=dynamic_cast<THashList*>(o);
903     if (!list) continue;
904     SetHistogramList(*list);
905     break;
906   }
907   f.Close();
908 }
909
910 //_____________________________________________________________________________
911 void AliDielectronHistos::DrawSame(const char* histName, const Option_t *opt)
912 {
913   //
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
917   //
918
919   TString optString(opt);
920   optString.ToLower();
921   Bool_t optLeg=optString.Contains("leg");
922   Bool_t optCan=optString.Contains("can");
923
924   TLegend *leg=0;
925   TCanvas *c=0;
926   if (optCan){
927     c=(TCanvas*)gROOT->FindObject(Form("c%s",histName));
928     if (!c) c=new TCanvas(Form("c%s",histName),Form("All '%s' histograms",histName));
929     c->Clear();
930     c->cd();
931   }
932
933   if (optLeg) leg=new TLegend(.8,.3,.99,.9);
934   
935   Int_t i=0;
936   TIter next(&fHistoList);
937   THashList *classTable=0;
938   Double_t max=-1e10;
939   TH1 *hFirst=0x0;
940   while ( (classTable=(THashList*)next()) ){
941     if ( TH1 *h=(TH1*)classTable->FindObject(histName) ){
942       if (i==0) hFirst=h;
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");
947       ++i;
948       max=TMath::Max(max,h->GetMaximum());
949     }
950   }
951   if (leg){
952     leg->SetFillColor(10);
953     leg->SetY1(.9-i*.05);
954     leg->Draw();
955   }
956   if (hFirst&&(hFirst->GetYaxis()->GetXmax()<max)){
957     hFirst->SetMaximum(max);
958   }
959 }
960
961 //_____________________________________________________________________________
962 void AliDielectronHistos::SetReservedWords(const char* words)
963 {
964   //
965   // set reserved words
966   //
967
968   (*fReservedWords)=words;
969 }
970
971 //_____________________________________________________________________________
972 void AliDielectronHistos::StoreVariables(TObject *obj, UInt_t valType[20])
973 {
974   //
975   //
976   //
977   if (!obj) return;
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);
981
982   return;
983
984 }
985
986
987 //_____________________________________________________________________________
988 void AliDielectronHistos::StoreVariables(TH1 *obj, UInt_t valType[20])
989 {
990   //
991   // store variables in the axis (special for TProfile3D)
992   //
993
994   Int_t dim   = obj->GetDimension();
995   Bool_t bprf = kFALSE;
996
997   // dimension correction for profiles
998   if(obj->IsA() == TProfile::Class() || obj->IsA() == TProfile2D::Class() || obj->IsA() == TProfile3D::Class()) {
999     bprf=kTRUE;
1000     dim++;
1001   }
1002
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();
1008
1009
1010   switch( dim ) {
1011   case 4:
1012     obj->SetUniqueID(valType[3]); // Tprofile3D variable
1013   case 3:
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])));
1017   case 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])));
1021   case 1:
1022     obj->GetXaxis()->SetUniqueID(valType[0]);
1023     obj->GetXaxis()->SetTitle(Form("%s %s", AliDielectronVarManager::GetValueLabel(valType[0]), AliDielectronVarManager::GetValueUnit(valType[0])));
1024   }
1025
1026   return;
1027 }
1028
1029 //_____________________________________________________________________________
1030 void AliDielectronHistos::StoreVariables(THn *obj, UInt_t valType[20])
1031 {
1032   //
1033   // store variables in the axis
1034   //
1035
1036   Int_t dim = obj->GetNdimensions();
1037
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])));
1041   }
1042   obj->Sumw2();
1043   return;
1044 }
1045
1046 //_____________________________________________________________________________
1047 void AliDielectronHistos::StoreVariables(THnSparse *obj, UInt_t valType[20])
1048 {
1049   //
1050   // store variables in the axis
1051   //
1052
1053   Int_t dim = obj->GetNdimensions();
1054
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])));
1058   }
1059   obj->Sumw2();
1060   return;
1061 }
1062
1063 //_____________________________________________________________________________
1064 void AliDielectronHistos::FillValues(TObject *obj, const Double_t *values)
1065 {
1066   //
1067   //
1068   //
1069   if (!obj) return;
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);
1073
1074   return;
1075
1076 }
1077
1078 //_____________________________________________________________________________
1079 void AliDielectronHistos::FillValues(TH1 *obj, const Double_t *values)
1080 {
1081   //
1082   // fill values for TH1 inherted classes
1083   //
1084
1085   Int_t dim   = obj->GetDimension();
1086   Bool_t bprf = kFALSE;
1087   //  UInt_t nValues = (UInt_t) AliDielectronVarManager::kNMaxValues;
1088
1089   UInt_t valueTypes=obj->GetUniqueID();
1090   if (valueTypes==(UInt_t)kNoAutoFill) return;
1091
1092   if(obj->IsA() == TProfile::Class() || obj->IsA() == TProfile2D::Class() || obj->IsA() == TProfile3D::Class())
1093     bprf=kTRUE;
1094   
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
1099
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());
1102   //  return;
1103   // }
1104
1105   switch ( dim ) {
1106   case 1:
1107     if(!bprf) obj->Fill(values[value1]);                    // histograms
1108     else ((TProfile*)obj)->Fill(values[value1],values[value2]);   // profiles
1109     break;
1110   case 2:
1111     if(!bprf) ((TH2*)obj)->Fill(values[value1],values[value2]);
1112     else ((TProfile2D*)obj)->Fill(values[value1],values[value2],values[value3]);
1113     break;
1114   case 3:
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]);
1117     break;
1118   }
1119   
1120   return;
1121 }
1122
1123 //_____________________________________________________________________________
1124 void AliDielectronHistos::FillValues(THn *obj, const Double_t *values)
1125 {
1126   //
1127   // fill values for THn inherted classes
1128   //
1129
1130   const Int_t dim   = obj->GetNdimensions();
1131
1132   UInt_t valueTypes=obj->GetUniqueID();
1133   if (valueTypes==(UInt_t)kNoAutoFill) return;
1134
1135   Double_t fill[dim];
1136   for(Int_t it=0; it<dim; it++)   fill[it] = values[obj->GetAxis(it)->GetUniqueID()];
1137   obj->Fill(fill);
1138
1139   return;
1140 }
1141
1142 //_____________________________________________________________________________
1143 void AliDielectronHistos::FillValues(THnSparse *obj, const Double_t *values)
1144 {
1145   //
1146   // fill values for THnSparse inherted classes
1147   //
1148
1149   const Int_t dim   = obj->GetNdimensions();
1150
1151   UInt_t valueTypes=obj->GetUniqueID();
1152   if (valueTypes==(UInt_t)kNoAutoFill) return;
1153
1154   Double_t fill[dim];
1155   for(Int_t it=0; it<dim; it++) {
1156     fill[it] = values[obj->GetAxis(it)->GetUniqueID()];
1157   }
1158   obj->Fill(fill);
1159
1160   return;
1161 }
1162
1163 //_____________________________________________________________________________
1164 void AliDielectronHistos::FillVarArray(TObject *obj, UInt_t *valType)
1165 {
1166   //
1167   // extract variables stored in the axis (special for TProfile3D)
1168   //
1169
1170
1171   if (!obj) return;
1172   //  printf(" fillvararray %s \n",obj->GetName());
1173
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
1179   }
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();
1183   }
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();
1187   }
1188
1189   return;
1190 }
1191
1192 //_____________________________________________________________________________
1193 void AliDielectronHistos::AdaptNameTitle(TH1 *hist, const char* histClass) {
1194
1195   //
1196   // adapt name and title of the histogram
1197   //
1198
1199   Int_t dim            = hist->GetDimension();
1200   TString currentName  = hist->GetName();
1201   TString currentTitle = hist->GetTitle();
1202
1203
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())
1208     bprf=kTRUE;
1209
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();
1214
1215   // store titles in the axis
1216   if(btitle) {
1217     switch( dim ) {
1218     case 3:
1219       hist->GetXaxis()->SetTitle(Form("%s %s",
1220                                       AliDielectronVarManager::GetValueLabel(varx), 
1221                                       AliDielectronVarManager::GetValueUnit(varx))
1222                                  );
1223       hist->GetYaxis()->SetTitle(Form("%s %s",
1224                                       AliDielectronVarManager::GetValueLabel(vary), 
1225                                       AliDielectronVarManager::GetValueUnit(vary))
1226                                  );
1227       hist->GetZaxis()->SetTitle(Form("%s %s",
1228                                       AliDielectronVarManager::GetValueLabel(varz), 
1229                                       AliDielectronVarManager::GetValueUnit(varz))
1230                                  );
1231     case 2:
1232       hist->GetXaxis()->SetTitle(Form("%s %s",
1233                                       AliDielectronVarManager::GetValueLabel(varx), 
1234                                       AliDielectronVarManager::GetValueUnit(varx))
1235                                  );
1236       hist->GetYaxis()->SetTitle(Form("%s %s",
1237                                       AliDielectronVarManager::GetValueLabel(vary), 
1238                                       AliDielectronVarManager::GetValueUnit(vary))
1239                                  );
1240       hist->GetZaxis()->SetTitle(Form("#%ss",histClass));
1241       if(bprf)
1242         hist->GetZaxis()->SetTitle(Form("#LT%s#GT %s",
1243                                         AliDielectronVarManager::GetValueLabel(varz), 
1244                                         AliDielectronVarManager::GetValueUnit(varz))
1245                                    );
1246     case 1:
1247       hist->GetXaxis()->SetTitle(Form("%s %s",
1248                                       AliDielectronVarManager::GetValueLabel(varx), 
1249                                       AliDielectronVarManager::GetValueUnit(varx))
1250                                  );
1251       hist->GetYaxis()->SetTitle(Form("#%ss",histClass));
1252       if(bprf)
1253         hist->GetYaxis()->SetTitle(Form("#LT%s#GT %s",
1254                                         AliDielectronVarManager::GetValueLabel(vary), 
1255                                         AliDielectronVarManager::GetValueUnit(vary))
1256                                    );
1257     }
1258
1259     // create an unique name
1260     if(bname)
1261       switch(dim) {
1262       case 3:
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));
1267         break;
1268       case 2:
1269         currentName+=Form("%s_",AliDielectronVarManager::GetValueName(varx));
1270         currentName+=Form("%s",AliDielectronVarManager::GetValueName(vary));
1271         if(bprf) currentName+=Form("-%savg",AliDielectronVarManager::GetValueName(varz));
1272         break;
1273       case 1:
1274         currentName+=Form("%s",AliDielectronVarManager::GetValueName(varx));
1275         if(bprf) currentName+=Form("-%savg",AliDielectronVarManager::GetValueName(vary));
1276         break;
1277       }
1278     // to differentiate btw. leg and pair histos
1279     if(!strcmp(histClass,"Pair")) currentName.Prepend("p");
1280     hist->SetName(currentName.Data());
1281   }
1282
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();
1286
1287 }
1288
1289
1290