]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGDQ/dielectron/AliDielectronHistos.cxx
- remove printouts
[u/mrichter/AliRoot.git] / PWGDQ / dielectron / AliDielectronHistos.cxx
CommitLineData
b2a297fa 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>
5720c765 22// Julian Book <Julian.Book@cern.ch>
b2a297fa 23//
24
25#include <TH1.h>
26#include <TH1F.h>
27#include <TH2.h>
28#include <TH3.h>
849a30fc 29#include <THnBase.h>
80c1dcac 30#include <THn.h>
849a30fc 31#include <THnSparse.h>
5720c765 32#include <TProfile.h>
33#include <TProfile2D.h>
34#include <TProfile3D.h>
b2a297fa 35#include <TCollection.h>
36#include <THashList.h>
37#include <TString.h>
61d106d3 38#include <TObjString.h>
b2a297fa 39#include <TObjArray.h>
40#include <TFile.h>
41#include <TError.h>
42#include <TCanvas.h>
43#include <TMath.h>
44#include <TROOT.h>
45#include <TLegend.h>
46#include <TKey.h>
572b0139 47#include <TAxis.h>
48#include <TVirtualPS.h>
ffbede40 49#include <TVectorD.h>
b2a297fa 50
ffbede40 51#include "AliDielectronHelper.h"
07480df6 52#include "AliDielectronVarManager.h"
b2a297fa 53#include "AliDielectronHistos.h"
54
b2a297fa 55ClassImp(AliDielectronHistos)
56
57
58AliDielectronHistos::AliDielectronHistos() :
59// TCollection(),
60 TNamed("AliDielectronHistos","Dielectron Histogram Container"),
61 fHistoList(),
164bfb53 62 fList(0x0),
b2a297fa 63 fReservedWords(new TString)
64{
65 //
66 // Default constructor
67 //
68 fHistoList.SetOwner(kTRUE);
69 fHistoList.SetName("Dielectron_Histos");
70}
71
72//_____________________________________________________________________________
73AliDielectronHistos::AliDielectronHistos(const char* name, const char* title) :
74// TCollection(),
75 TNamed(name, title),
76 fHistoList(),
164bfb53 77 fList(0x0),
b2a297fa 78 fReservedWords(new TString)
79{
80 //
81 // TNamed constructor
82 //
83 fHistoList.SetOwner(kTRUE);
84 fHistoList.SetName(name);
85}
86
87//_____________________________________________________________________________
88AliDielectronHistos::~AliDielectronHistos()
89{
90 //
91 // Destructor
92 //
61d106d3 93 fHistoList.Clear();
48609e3d 94 if (fList) fList->Clear();
b2a297fa 95 delete fReservedWords;
96}
97
98//_____________________________________________________________________________
5720c765 99void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
100 UInt_t valTypeP,
101 Int_t nbinsX, Double_t xmin, Double_t xmax,
e4339752 102 UInt_t valTypeX, Bool_t logBinX, TString option)
b2a297fa 103{
104 //
105 // Default histogram creation 1D case
106 //
572b0139 107
ffbede40 108 TVectorD *binLimX=0x0;
572b0139 109
110 if (logBinX) {
ffbede40 111 binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
572b0139 112 } else {
ffbede40 113 binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
572b0139 114 }
e4339752 115 UserProfile(histClass,name,title,valTypeP,binLimX,valTypeX,option);
b2a297fa 116}
117
118//_____________________________________________________________________________
5720c765 119void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
120 UInt_t valTypeP,
121 Int_t nbinsX, Double_t xmin, Double_t xmax,
122 Int_t nbinsY, Double_t ymin, Double_t ymax,
123 UInt_t valTypeX, UInt_t valTypeY,
e4339752 124 Bool_t logBinX, Bool_t logBinY, TString option)
b2a297fa 125{
126 //
127 // Default histogram creation 2D case
128 //
129 if (!IsHistogramOk(histClass,name)) return;
130
ffbede40 131 TVectorD *binLimX=0x0;
132 TVectorD *binLimY=0x0;
572b0139 133
134 if (logBinX) {
ffbede40 135 binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
572b0139 136 } else {
ffbede40 137 binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
572b0139 138 }
139 if (logBinY) {
ffbede40 140 binLimY=AliDielectronHelper::MakeLogBinning(nbinsY, ymin, ymax);
572b0139 141 } else {
ffbede40 142 binLimY=AliDielectronHelper::MakeLinBinning(nbinsY, ymin, ymax);
572b0139 143 }
e4339752 144 UserProfile(histClass,name,title,valTypeP,binLimX,binLimY,valTypeX,valTypeY,option);
b2a297fa 145}
146
147
148//_____________________________________________________________________________
5720c765 149void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
150 UInt_t valTypeP,
151 Int_t nbinsX, Double_t xmin, Double_t xmax,
152 Int_t nbinsY, Double_t ymin, Double_t ymax,
153 Int_t nbinsZ, Double_t zmin, Double_t zmax,
154 UInt_t valTypeX, UInt_t valTypeY, UInt_t valTypeZ,
e4339752 155 Bool_t logBinX, Bool_t logBinY, Bool_t logBinZ, TString option)
b2a297fa 156{
157 //
158 // Default histogram creation 3D case
159 //
160 if (!IsHistogramOk(histClass,name)) return;
161
ffbede40 162 TVectorD *binLimX=0x0;
163 TVectorD *binLimY=0x0;
164 TVectorD *binLimZ=0x0;
572b0139 165
166 if (logBinX) {
ffbede40 167 binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
572b0139 168 } else {
ffbede40 169 binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
572b0139 170 }
171
172 if (logBinY) {
ffbede40 173 binLimY=AliDielectronHelper::MakeLogBinning(nbinsY, ymin, ymax);
572b0139 174 } else {
ffbede40 175 binLimY=AliDielectronHelper::MakeLinBinning(nbinsY, ymin, ymax);
572b0139 176 }
177
178 if (logBinZ) {
ffbede40 179 binLimZ=AliDielectronHelper::MakeLogBinning(nbinsZ, zmin, zmax);
572b0139 180 } else {
ffbede40 181 binLimZ=AliDielectronHelper::MakeLinBinning(nbinsZ, zmin, zmax);
182 }
183
e4339752 184 UserProfile(histClass,name,title,valTypeP,binLimX,binLimY,binLimZ,valTypeX,valTypeY,valTypeZ,option);
ffbede40 185}
186
187//_____________________________________________________________________________
5720c765 188void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
189 UInt_t valTypeP,
190 const char* binning,
e4339752 191 UInt_t valTypeX, TString option)
ffbede40 192{
193 //
194 // Histogram creation 1D case with arbitraty binning
195 //
196
197 TVectorD *binLimX=AliDielectronHelper::MakeArbitraryBinning(binning);
e4339752 198 UserProfile(histClass,name,title,valTypeP,binLimX,valTypeX,option);
ffbede40 199}
200
201//_____________________________________________________________________________
5720c765 202void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
203 UInt_t valTypeP,
204 const TVectorD * const binsX,
e4339752 205 UInt_t valTypeX/*=kNoAutoFill*/, TString option)
ffbede40 206{
207 //
208 // Histogram creation 1D case with arbitraty binning X
209 // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
210 //
211
212 Bool_t isOk=kTRUE;
213 isOk&=IsHistogramOk(histClass,name);
214 isOk&=(binsX!=0x0);
5720c765 215 TH1 *hist=0x0;
07480df6 216
5720c765 217 if (isOk){
218 if(valTypeP==999)
219 hist=new TH1F(name,title,binsX->GetNrows()-1,binsX->GetMatrixArray());
220 else {
e4339752 221 TString opt=""; Double_t pmin=0., pmax=0.;
222 if(!option.IsNull()) {
223 TObjArray *arr=option.Tokenize(";");
224 arr->SetOwner();
225 opt=((TObjString*)arr->At(0))->GetString();
226 if(arr->GetEntriesFast()>1) pmin=(((TObjString*)arr->At(1))->GetString()).Atof();
227 if(arr->GetEntriesFast()>2) pmax=(((TObjString*)arr->At(2))->GetString()).Atof();
228 delete arr;
229 }
5720c765 230 hist=new TProfile(name,title,binsX->GetNrows()-1,binsX->GetMatrixArray());
e4339752 231 ((TProfile*)hist)->BuildOptions(pmin,pmax,opt.Data());
232 // printf(" name %s PROFILE options: pmin %.1f pmax %.1f err %s \n",name,((TProfile*)hist)->GetYmin(),((TProfile*)hist)->GetYmax(),((TProfile*)hist)->GetErrorOption() );
5720c765 233 }
234
80c1dcac 235 // store variales in axes
236 UInt_t valType[20] = {0};
237 valType[0]=valTypeX; valType[1]=valTypeP;
238 StoreVariables(hist, valType);
239
240 // adapt the name and title of the histogram in case they are empty
241 AdaptNameTitle(hist, histClass);
5720c765 242
ffbede40 243 Bool_t isReserved=fReservedWords->Contains(histClass);
80c1dcac 244 if(valTypeX==kNoAutoFill) hist->SetUniqueID(valTypeX);
ffbede40 245 if (isReserved)
80c1dcac 246 UserHistogramReservedWords(histClass, hist, 999);
ffbede40 247 else
80c1dcac 248 UserHistogram(histClass, hist, 999);
ffbede40 249 }
250
251 delete binsX;
252}
253
254//_____________________________________________________________________________
5720c765 255void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
256 UInt_t valTypeP,
257 const TVectorD * const binsX, const TVectorD * const binsY,
e4339752 258 UInt_t valTypeX/*=kNoAutoFill*/, UInt_t valTypeY/*=0*/, TString option)
ffbede40 259{
260 //
5720c765 261 // Histogram creation 2D case with arbitraty binning X
ffbede40 262 // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
263 //
264
265 Bool_t isOk=kTRUE;
266 isOk&=IsHistogramOk(histClass,name);
267 isOk&=(binsX!=0x0);
268 isOk&=(binsY!=0x0);
5720c765 269 TH1 *hist=0x0;
ffbede40 270
271 if (isOk){
5720c765 272 if(valTypeP==999) {
273 hist=new TH2F(name,title,
274 binsX->GetNrows()-1,binsX->GetMatrixArray(),
275 binsY->GetNrows()-1,binsY->GetMatrixArray());
276 }
e4339752 277 else {
278 TString opt=""; Double_t pmin=0., pmax=0.;
279 if(!option.IsNull()) {
280 TObjArray *arr=option.Tokenize(";");
281 arr->SetOwner();
282 opt=((TObjString*)arr->At(0))->GetString();
283 if(arr->GetEntriesFast()>1) pmin=(((TObjString*)arr->At(1))->GetString()).Atof();
284 if(arr->GetEntriesFast()>2) pmax=(((TObjString*)arr->At(2))->GetString()).Atof();
285 delete arr;
286 }
5720c765 287 hist=new TProfile2D(name,title,
288 binsX->GetNrows()-1,binsX->GetMatrixArray(),
289 binsY->GetNrows()-1,binsY->GetMatrixArray());
e4339752 290 ((TProfile2D*)hist)->BuildOptions(pmin,pmax,opt.Data());
291 // printf(" name %s PROFILE options: pmin %.1f pmax %.1f err %s \n",name,((TProfile*)hist)->GetYmin(),((TProfile*)hist)->GetYmax(),((TProfile*)hist)->GetErrorOption() );
292 }
293
80c1dcac 294 // store variales in axes
295 UInt_t valType[20] = {0};
296 valType[0]=valTypeX; valType[1]=valTypeY; valType[2]=valTypeP;
297 StoreVariables(hist, valType);
5720c765 298
80c1dcac 299 // adapt the name and title of the histogram in case they are empty
300 AdaptNameTitle(hist, histClass);
5720c765 301
80c1dcac 302 Bool_t isReserved=fReservedWords->Contains(histClass);
303 if(valTypeX==kNoAutoFill) hist->SetUniqueID(valTypeX);
ffbede40 304 if (isReserved)
80c1dcac 305 UserHistogramReservedWords(histClass, hist, 999);
ffbede40 306 else
80c1dcac 307 UserHistogram(histClass, hist, 999);
572b0139 308 }
309
ffbede40 310 delete binsX;
311 delete binsY;
312
313}
314
315//_____________________________________________________________________________
5720c765 316void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
317 UInt_t valTypeP,
318 const TVectorD * const binsX, const TVectorD * const binsY, const TVectorD * const binsZ,
e4339752 319 UInt_t valTypeX/*=kNoAutoFill*/, UInt_t valTypeY/*=0*/, UInt_t valTypeZ/*=0*/, TString option)
ffbede40 320{
321 //
5720c765 322 // Histogram creation 3D case with arbitraty binning X
ffbede40 323 // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
324 //
325
326 Bool_t isOk=kTRUE;
327 isOk&=IsHistogramOk(histClass,name);
328 isOk&=(binsX!=0x0);
329 isOk&=(binsY!=0x0);
330 isOk&=(binsZ!=0x0);
5720c765 331 TH1 *hist=0x0;
07480df6 332
80c1dcac 333 if (isOk) {
334 if(valTypeP==999) {
5720c765 335 hist=new TH3F(name,title,
336 binsX->GetNrows()-1,binsX->GetMatrixArray(),
337 binsY->GetNrows()-1,binsY->GetMatrixArray(),
338 binsZ->GetNrows()-1,binsZ->GetMatrixArray());
80c1dcac 339 }
e4339752 340 else {
341 TString opt=""; Double_t pmin=0., pmax=0.;
342 if(!option.IsNull()) {
343 TObjArray *arr=option.Tokenize(";");
344 arr->SetOwner();
345 opt=((TObjString*)arr->At(0))->GetString();
346 if(arr->GetEntriesFast()>1) pmin=(((TObjString*)arr->At(1))->GetString()).Atof();
347 if(arr->GetEntriesFast()>2) pmax=(((TObjString*)arr->At(2))->GetString()).Atof();
348 delete arr;
349 }
5720c765 350 hist=new TProfile3D(name,title,
351 binsX->GetNrows()-1,binsX->GetMatrixArray(),
352 binsY->GetNrows()-1,binsY->GetMatrixArray(),
353 binsZ->GetNrows()-1,binsZ->GetMatrixArray());
e4339752 354 ((TProfile3D*)hist)->BuildOptions(pmin,pmax,opt.Data());
355 // printf(" name %s PROFILE options: pmin %.1f pmax %.1f err %s \n",name,((TProfile*)hist)->GetYmin(),((TProfile*)hist)->GetYmax(),((TProfile*)hist)->GetErrorOption() );
356 }
357
80c1dcac 358 // store variales in axes
359 UInt_t valType[20] = {0};
360 valType[0]=valTypeX; valType[1]=valTypeY; valType[2]=valTypeZ; valType[3]=valTypeP;
361 StoreVariables(hist, valType);
5720c765 362
80c1dcac 363 // adapt the name and title of the histogram in case they are empty
364 AdaptNameTitle(hist, histClass);
365
366 Bool_t isReserved=fReservedWords->Contains(histClass);
367 if(valTypeX==kNoAutoFill) hist->SetUniqueID(valTypeX);
ffbede40 368 if (isReserved)
80c1dcac 369 UserHistogramReservedWords(histClass, hist, 999);
ffbede40 370 else
80c1dcac 371 UserHistogram(histClass, hist, 999);
ffbede40 372 }
572b0139 373
ffbede40 374 delete binsX;
375 delete binsY;
376 delete binsZ;
b2a297fa 377}
378
379//_____________________________________________________________________________
80c1dcac 380void AliDielectronHistos::UserHistogram(const char* histClass, Int_t ndim, Int_t *bins, Double_t *mins, Double_t *maxs, UInt_t *vars)
381{
382 //
383 // Histogram creation 4-n dimension only with linear binning
384 //
385
386 Bool_t isOk=kTRUE;
387 isOk&=(ndim<21 && ndim>3);
388 if(!isOk) { Warning("UserHistogram","Array sizes should be between 3 and 20. Not adding Histogram to '%s'.", histClass); return; }
389
390 // set automatic histo name
391 TString name;
392 for(Int_t iv=0; iv < ndim; iv++)
393 name+=Form("%s_",AliDielectronVarManager::GetValueName(vars[iv]));
394 name.Resize(name.Length()-1);
395
80c1dcac 396 isOk&=IsHistogramOk(histClass,name);
397
398 THnD *hist;
399 if (isOk) {
400 hist=new THnD(name.Data(),"", ndim, bins, mins, maxs);
401
402 // store variales in axes
403 StoreVariables(hist, vars);
404
405 Bool_t isReserved=fReservedWords->Contains(histClass);
406 if (isReserved)
407 UserHistogramReservedWords(histClass, hist, 999);
408 else
409 UserHistogram(histClass, hist, 999);
410
80c1dcac 411 }
412}
413
7a1ddc4b 414//_____________________________________________________________________________
415void AliDielectronHistos::UserHistogram(const char* histClass, Int_t ndim, TObjArray *limits, UInt_t *vars)
416{
417 //
418 // Histogram creation n>3 dimension only with non-linear binning
419 //
420
421 Bool_t isOk=kTRUE;
422 isOk&=(ndim<21 && ndim>3);
423 if(!isOk) { Warning("UserHistogram","Array sizes should be between 3 and 20. Not adding Histogram to '%s'.", histClass); return; }
424 isOk&=(ndim==limits->GetEntriesFast());
425 if(!isOk) return;
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 isOk&=IsHistogramOk(histClass,name);
434
435 THnD *hist;
436 Int_t bins[ndim];
437 if (isOk) {
438 // get number of bins
439 for(Int_t idim=0 ;idim<ndim; idim++) {
440 TVectorD *vec = (TVectorD*) limits->At(idim);
441 bins[idim]=vec->GetNrows()-1;
442 }
443
444 hist=new THnD(name.Data(),"", ndim, bins, 0x0, 0x0);
445
446 // set binning
447 for(Int_t idim=0 ;idim<ndim; idim++) {
448 TVectorD *vec = (TVectorD*) limits->At(idim);
449 hist->SetBinEdges(idim,vec->GetMatrixArray());
450 }
451
452 // store variales in axes
453 StoreVariables(hist, vars);
454
455 Bool_t isReserved=fReservedWords->Contains(histClass);
456 if (isReserved)
457 UserHistogramReservedWords(histClass, hist, 999);
458 else
459 UserHistogram(histClass, hist, 999);
460
461 }
462}
463
80c1dcac 464//_____________________________________________________________________________
465void AliDielectronHistos::UserSparse(const char* histClass, Int_t ndim, Int_t *bins, Double_t *mins, Double_t *maxs, UInt_t *vars)
466{
467 //
468 // THnSparse creation with linear binning
469 //
470
471 Bool_t isOk=kTRUE;
472
473 // set automatic histo name
474 TString name;
475 for(Int_t iv=0; iv < ndim; iv++)
476 name+=Form("%s_",AliDielectronVarManager::GetValueName(vars[iv]));
477 name.Resize(name.Length()-1);
478
80c1dcac 479 isOk&=IsHistogramOk(histClass,name);
480
481 THnSparseD *hist;
482 if (isOk) {
483 hist=new THnSparseD(name.Data(),"", ndim, bins, mins, maxs);
484
485 // store variales in axes
486 StoreVariables(hist, vars);
487
488 Bool_t isReserved=fReservedWords->Contains(histClass);
489 if (isReserved)
490 UserHistogramReservedWords(histClass, hist, 999);
491 else
492 UserHistogram(histClass, hist, 999);
493
494 }
495}
496
7a1ddc4b 497//_____________________________________________________________________________
498void AliDielectronHistos::UserSparse(const char* histClass, Int_t ndim, TObjArray *limits, UInt_t *vars)
499{
500 //
501 // THnSparse creation with non-linear binning
502 //
503
504 Bool_t isOk=kTRUE;
505 isOk&=(ndim==limits->GetEntriesFast());
506 if(!isOk) return;
507
508 // set automatic histo name
509 TString name;
510 for(Int_t iv=0; iv < ndim; iv++)
511 name+=Form("%s_",AliDielectronVarManager::GetValueName(vars[iv]));
512 name.Resize(name.Length()-1);
513
514 isOk&=IsHistogramOk(histClass,name);
515
516 THnSparseD *hist;
517 Int_t bins[ndim];
518 if (isOk) {
519 // get number of bins
520 for(Int_t idim=0 ;idim<ndim; idim++) {
521 TVectorD *vec = (TVectorD*) limits->At(idim);
522 bins[idim]=vec->GetNrows()-1;
523 }
524
525 hist=new THnSparseD(name.Data(),"", ndim, bins, 0x0, 0x0);
526
527 // set binning
528 for(Int_t idim=0 ;idim<ndim; idim++) {
529 TVectorD *vec = (TVectorD*) limits->At(idim);
530 hist->SetBinEdges(idim,vec->GetMatrixArray());
531 }
532
533 // store variales in axes
534 StoreVariables(hist, vars);
535
536 Bool_t isReserved=fReservedWords->Contains(histClass);
537 if (isReserved)
538 UserHistogramReservedWords(histClass, hist, 999);
539 else
540 UserHistogram(histClass, hist, 999);
541
542 }
543}
544
80c1dcac 545//_____________________________________________________________________________
546void AliDielectronHistos::UserHistogram(const char* histClass, TObject* hist, UInt_t valTypes)
b2a297fa 547{
548 //
549 // Add any type of user histogram
550 //
551
552 //special case for the calss Pair. where histograms will be created for all pair classes
553 Bool_t isReserved=fReservedWords->Contains(histClass);
554 if (isReserved) {
555 UserHistogramReservedWords(histClass, hist, valTypes);
556 return;
557 }
80c1dcac 558
b2a297fa 559 if (!IsHistogramOk(histClass,hist->GetName())) return;
b2a297fa 560 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
80c1dcac 561 // hist->SetDirectory(0);
562
563 // store variables axis
564 UInt_t valType[20] = {0};
565 // incase valTypes is given old way of extracting variables
566 if(valTypes!=999) {
567 valType[0]=valTypes%1000; //last three digits
568 valType[1]=valTypes/1000%1000; //second last three digits
569 valType[2]=valTypes/1000000%1000; //third last three digits
570 hist->SetUniqueID(valTypes);
571 }
572 else {
573 // extract variables from axis
574 FillVarArray(hist, valType);
575 }
576 StoreVariables(hist, valType);
5720c765 577
b2a297fa 578 classTable->Add(hist);
579}
580
581//_____________________________________________________________________________
582void AliDielectronHistos::AddClass(const char* histClass)
583{
584 //
585 // Add a class of histograms
586 // Several classes can be added by separating them by a ';' e.g. 'class1;class2;class3'
587 //
588 TString hists(histClass);
589 TObjArray *arr=hists.Tokenize(";");
590 TIter next(arr);
591 TObject *o=0;
592 while ( (o=next()) ){
593 if (fHistoList.FindObject(o->GetName())){
594 Warning("AddClass","Cannot create class '%s' it already exists.",histClass);
595 continue;
596 }
597 if (fReservedWords->Contains(o->GetName())){
598 Error("AddClass","Pair is a reserved word, please use another name");
599 continue;
600 }
601 THashList *table=new THashList;
602 table->SetOwner(kTRUE);
603 table->SetName(o->GetName());
604 fHistoList.Add(table);
605 }
606 delete arr;
607}
608
609//_____________________________________________________________________________
610void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval)
611{
612 //
613 // Fill function 1D case
614 //
615 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
616 TH1* hist=0;
617 if (!classTable || !(hist=(TH1*)classTable->FindObject(name)) ){
618 Warning("Fill","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
619 return;
620 }
621 hist->Fill(xval);
622}
623
624//_____________________________________________________________________________
625void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval, Double_t yval)
626{
627 //
628 // Fill function 2D case
629 //
630 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
631 TH2* hist=0;
632 if (!classTable || !(hist=(TH2*)classTable->FindObject(name)) ){
633 Warning("UserHistogram","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
634 return;
635 }
636 hist->Fill(xval,yval);
637}
638
639//_____________________________________________________________________________
640void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval, Double_t yval, Double_t zval)
641{
642 //
643 // Fill function 3D case
644 //
645 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
646 TH3* hist=0;
647 if (!classTable || !(hist=(TH3*)classTable->FindObject(name)) ){
648 Warning("UserHistogram","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
649 return;
650 }
651 hist->Fill(xval,yval,zval);
652}
653
654//_____________________________________________________________________________
655void AliDielectronHistos::FillClass(const char* histClass, Int_t nValues, const Double_t *values)
656{
657 //
658 // Fill class 'histClass' (by name)
80c1dcac 659 //
660
b2a297fa 661 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
662 if (!classTable){
80c1dcac 663 Warning("FillClass","Cannot fill class '%s' its not defined. nValues %d",histClass,nValues);
b2a297fa 664 return;
665 }
80c1dcac 666
b2a297fa 667 TIter nextHist(classTable);
80c1dcac 668 TObject *obj=0;
669 while ( (obj=(TObject*)nextHist()) ) FillValues(obj, values);
670
671 return;
b2a297fa 672}
673
674//_____________________________________________________________________________
675// void AliDielectronHistos::FillClass(const char* histClass, const TVectorD &vals)
676// {
677// //
678// //
679// //
680// FillClass(histClass, vals.GetNrows(), vals.GetMatrixArray());
681// }
682
683//_____________________________________________________________________________
80c1dcac 684void AliDielectronHistos::UserHistogramReservedWords(const char* histClass, const TObject *hist, UInt_t valTypes)
b2a297fa 685{
686 //
687 // Creation of histogram for all pair types
688 //
689 TString title(hist->GetTitle());
690 // Same Event Like Sign
691 TIter nextClass(&fHistoList);
692 THashList *l=0;
693 while ( (l=static_cast<THashList*>(nextClass())) ){
694 TString name(l->GetName());
695 if (name.Contains(histClass)){
80c1dcac 696 TObject *h=hist->Clone();
697 // Tobject has no function SetDirectory, didn't we need this???
698 // h->SetDirectory(0);
699 ((TH1*)h)->SetTitle(Form("%s %s",title.Data(),l->GetName()));
5720c765 700
b2a297fa 701 UserHistogram(l->GetName(),h,valTypes);
702 }
703 }
704 delete hist;
705}
706
707//_____________________________________________________________________________
708void AliDielectronHistos::DumpToFile(const char* file)
709{
710 //
711 // Dump the histogram list to a newly created root file
712 //
713 TFile f(file,"recreate");
714 fHistoList.Write(fHistoList.GetName(),TObject::kSingleKey);
715 f.Close();
716}
717
718//_____________________________________________________________________________
80c1dcac 719TObject* AliDielectronHistos::GetHist(const char* histClass, const char* name) const
b2a297fa 720{
721 //
80c1dcac 722 // return object 'name' in 'histClass'
b2a297fa 723 //
724 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
725 if (!classTable) return 0x0;
80c1dcac 726 return classTable->FindObject(name);
b2a297fa 727}
728
164bfb53 729//_____________________________________________________________________________
80c1dcac 730TH1* AliDielectronHistos::GetHistogram(const char* histClass, const char* name) const
164bfb53 731{
732 //
80c1dcac 733 // return histogram 'name' in 'histClass'
734 //
735 return ((TH1*) GetHist(histClass, name));
736}
737
738//_____________________________________________________________________________
739TObject* AliDielectronHistos::GetHist(const char* cutClass, const char* histClass, const char* name) const
740{
741 //
742 // return object from list of list of histograms
164bfb53 743 // this function is thought for retrieving histograms if a list of AliDielectronHistos is set
744 //
745
746 if (!fList) return 0x0;
747 THashList *h=dynamic_cast<THashList*>(fList->FindObject(cutClass));
748 if (!h)return 0x0;
749 THashList *classTable=dynamic_cast<THashList*>(h->FindObject(histClass));
750 if (!classTable) return 0x0;
80c1dcac 751 return classTable->FindObject(name);
752}
753
754//_____________________________________________________________________________
755TH1* AliDielectronHistos::GetHistogram(const char* cutClass, const char* histClass, const char* name) const
756{
757 //
758 // return histogram from list of list of histograms
759 // this function is thought for retrieving histograms if a list of AliDielectronHistos is set
760 //
761 return ((TH1*) GetHist(cutClass, histClass, name));
164bfb53 762}
763
b2a297fa 764//_____________________________________________________________________________
765void AliDielectronHistos::Draw(const Option_t* option)
766{
767 //
768 // Draw histograms
769 //
770
37e9382d 771 TString drawStr(option);
61d106d3 772 TObjArray *arr=drawStr.Tokenize(";");
773 arr->SetOwner();
774 TIter nextOpt(arr);
775
776 TString drawClasses;
777 TObjString *ostr=0x0;
778
779 TString currentOpt;
780 TString testOpt;
781 while ( (ostr=(TObjString*)nextOpt()) ){
782 currentOpt=ostr->GetString();
783 currentOpt.Remove(TString::kBoth,'\t');
784 currentOpt.Remove(TString::kBoth,' ');
785
786 testOpt="classes=";
787 if ( currentOpt.Contains(testOpt.Data()) ){
788 drawClasses=currentOpt(testOpt.Length(),currentOpt.Length());
789 }
790 }
791
792 delete arr;
37e9382d 793 drawStr.ToLower();
164bfb53 794 //optionsfList
b2a297fa 795// Bool_t same=drawOpt.Contains("same"); //FIXME not yet implemented
572b0139 796
797 TCanvas *c=0x0;
798 if (gVirtualPS) {
799 if (!gPad){
800 Error("Draw","When writing to a file you have to create a canvas before opening the file!!!");
801 return;
802 }
803 c=gPad->GetCanvas();
61d106d3 804 c->cd();
572b0139 805// c=new TCanvas;
806 }
b2a297fa 807
808 TIter nextClass(&fHistoList);
809 THashList *classTable=0;
61d106d3 810// Bool_t first=kTRUE;
b2a297fa 811 while ( (classTable=(THashList*)nextClass()) ){
61d106d3 812 //test classes option
813 if (!drawClasses.IsNull() && !drawClasses.Contains(classTable->GetName())) continue;
b2a297fa 814 //optimised division
815 Int_t nPads = classTable->GetEntries();
816 Int_t nCols = (Int_t)TMath::Ceil( TMath::Sqrt(nPads) );
817 Int_t nRows = (Int_t)TMath::Ceil( (Double_t)nPads/(Double_t)nCols );
818
819 //create canvas
572b0139 820 if (!gVirtualPS){
821 TString canvasName;
822 canvasName.Form("c%s_%s",GetName(),classTable->GetName());
823 c=(TCanvas*)gROOT->FindObject(canvasName.Data());
824 if (!c) c=new TCanvas(canvasName.Data(),Form("%s: %s",GetName(),classTable->GetName()));
825 c->Clear();
826 } else {
61d106d3 827// if (first){
828// first=kFALSE;
829// if (nPads>1) gVirtualPS->NewPage();
830// } else {
831 if (nPads>1) c->Clear();
832// }
572b0139 833 }
834 if (nCols>1||nRows>1) c->Divide(nCols,nRows);
835
b2a297fa 836 //loop over histograms and draw them
837 TIter nextHist(classTable);
838 Int_t iPad=0;
839 TH1 *h=0;
840 while ( (h=(TH1*)nextHist()) ){
841 TString drawOpt;
842 if ( (h->InheritsFrom(TH2::Class())) ) drawOpt="colz";
572b0139 843 if (nCols>1||nRows>1) c->cd(++iPad);
844 if ( TMath::Abs(h->GetXaxis()->GetBinWidth(1)-h->GetXaxis()->GetBinWidth(2))>1e-10 ) gPad->SetLogx();
845 if ( TMath::Abs(h->GetYaxis()->GetBinWidth(1)-h->GetYaxis()->GetBinWidth(2))>1e-10 ) gPad->SetLogy();
846 if ( TMath::Abs(h->GetZaxis()->GetBinWidth(1)-h->GetZaxis()->GetBinWidth(2))>1e-10 ) gPad->SetLogz();
8df8e382 847 TString histOpt=h->GetOption();
848 histOpt.ToLower();
849 if (histOpt.Contains("logx")) gPad->SetLogx();
850 if (histOpt.Contains("logy")) gPad->SetLogy();
851 if (histOpt.Contains("logz")) gPad->SetLogz();
852 histOpt.ReplaceAll("logx","");
853 histOpt.ReplaceAll("logy","");
854 histOpt.ReplaceAll("logz","");
b2a297fa 855 h->Draw(drawOpt.Data());
856 }
61d106d3 857 if (gVirtualPS) {
858 c->Update();
859 }
860
b2a297fa 861 }
572b0139 862// if (gVirtualPS) delete c;
b2a297fa 863}
864
865//_____________________________________________________________________________
866void AliDielectronHistos::Print(const Option_t* option) const
867{
868 //
869 // Print classes and histograms
870 //
871 TString optString(option);
872
873 if (optString.IsNull()) PrintStructure();
874
875
876
877}
878
879//_____________________________________________________________________________
880void AliDielectronHistos::PrintStructure() const
881{
882 //
883 // Print classes and histograms in the class to stdout
884 //
164bfb53 885 if (!fList){
886 TIter nextClass(&fHistoList);
887 THashList *classTable=0;
888 while ( (classTable=(THashList*)nextClass()) ){
889 TIter nextHist(classTable);
890 TObject *o=0;
891 printf("+ %s\n",classTable->GetName());
892 while ( (o=nextHist()) )
893 printf("| ->%s\n",o->GetName());
894 }
895 } else {
896 TIter nextCutClass(fList);
897 THashList *cutClass=0x0;
898 while ( (cutClass=(THashList*)nextCutClass()) ) {
899 printf("+ %s\n",cutClass->GetName());
900 TIter nextClass(cutClass);
901 THashList *classTable=0;
902 while ( (classTable=(THashList*)nextClass()) ){
903 TIter nextHist(classTable);
904 TObject *o=0;
905 printf("| + %s\n",classTable->GetName());
906 while ( (o=nextHist()) )
907 printf("| | ->%s\n",o->GetName());
908 }
909
910 }
b2a297fa 911 }
b2a297fa 912}
913
914//_____________________________________________________________________________
164bfb53 915void AliDielectronHistos::SetHistogramList(THashList &list, Bool_t setOwner/*=kTRUE*/)
b2a297fa 916{
917 //
918 // set histogram classes and histograms to this instance. It will take onwnership!
919 //
572b0139 920 ResetHistogramList();
61d106d3 921 TString name(GetName());
922 if (name == "AliDielectronHistos") SetName(list.GetName());
b2a297fa 923 TIter next(&list);
924 TObject *o;
925 while ( (o=next()) ){
926 fHistoList.Add(o);
927 }
164bfb53 928 if (setOwner){
929 list.SetOwner(kFALSE);
930 fHistoList.SetOwner(kTRUE);
ffbede40 931 } else {
932 fHistoList.SetOwner(kFALSE);
164bfb53 933 }
934}
935
936//_____________________________________________________________________________
937Bool_t AliDielectronHistos::SetCutClass(const char* cutClass)
938{
939 //
940 // Assign histogram list according to cutClass
941 //
942
943 if (!fList) return kFALSE;
944 ResetHistogramList();
945 THashList *h=dynamic_cast<THashList*>(fList->FindObject(cutClass));
946 if (!h) {
947 Warning("SetCutClass","cutClass '%s' not found", cutClass);
948 return kFALSE;
949 }
950 SetHistogramList(*h,kFALSE);
951 return kTRUE;
b2a297fa 952}
953
954//_____________________________________________________________________________
955Bool_t AliDielectronHistos::IsHistogramOk(const char* histClass, const char* name)
956{
957 //
958 // check whether the histogram class exists and the histogram itself does not exist yet
959 //
960 Bool_t isReserved=fReservedWords->Contains(histClass);
961 if (!fHistoList.FindObject(histClass)&&!isReserved){
962 Warning("IsHistogramOk","Cannot create histogram. Class '%s' not defined. Please create it using AddClass before.",histClass);
963 return kFALSE;
964 }
80c1dcac 965 if (GetHist(histClass,name)){
b2a297fa 966 Warning("IsHistogramOk","Cannot create histogram '%s' in class '%s': It already exists!",name,histClass);
967 return kFALSE;
968 }
969 return kTRUE;
970}
971
972// //_____________________________________________________________________________
973// TIterator* AliDielectronHistos::MakeIterator(Bool_t dir) const
974// {
975// //
976// //
977// //
978// return new TListIter(&fHistoList, dir);
979// }
980
981//_____________________________________________________________________________
982void AliDielectronHistos::ReadFromFile(const char* file)
983{
984 //
985 // Read histos from file
986 //
987 TFile f(file);
988 TIter nextKey(f.GetListOfKeys());
989 TKey *key=0;
990 while ( (key=(TKey*)nextKey()) ){
991 TObject *o=f.Get(key->GetName());
992 THashList *list=dynamic_cast<THashList*>(o);
993 if (!list) continue;
994 SetHistogramList(*list);
995 break;
996 }
997 f.Close();
998}
999
572b0139 1000//_____________________________________________________________________________
b2a297fa 1001void AliDielectronHistos::DrawSame(const char* histName, const Option_t *opt)
1002{
1003 //
1004 // Draw all histograms with the same name into one canvas
1005 // if option contains 'leg' a legend will be created with the class name as caption
1006 // if option contains 'can' a new canvas is created
1007 //
1008
1009 TString optString(opt);
1010 optString.ToLower();
1011 Bool_t optLeg=optString.Contains("leg");
1012 Bool_t optCan=optString.Contains("can");
1013
1014 TLegend *leg=0;
1015 TCanvas *c=0;
1016 if (optCan){
1017 c=(TCanvas*)gROOT->FindObject(Form("c%s",histName));
1018 if (!c) c=new TCanvas(Form("c%s",histName),Form("All '%s' histograms",histName));
1019 c->Clear();
1020 c->cd();
1021 }
1022
1023 if (optLeg) leg=new TLegend(.8,.3,.99,.9);
1024
1025 Int_t i=0;
1026 TIter next(&fHistoList);
1027 THashList *classTable=0;
1028 Double_t max=-1e10;
1029 TH1 *hFirst=0x0;
1030 while ( (classTable=(THashList*)next()) ){
1031 if ( TH1 *h=(TH1*)classTable->FindObject(histName) ){
1032 if (i==0) hFirst=h;
1033 h->SetLineColor(i+1);
1034 h->SetMarkerColor(i+1);
1035 h->Draw(i>0?"same":"");
1036 if (leg) leg->AddEntry(h,classTable->GetName(),"lp");
1037 ++i;
1038 max=TMath::Max(max,h->GetMaximum());
1039 }
1040 }
1041 if (leg){
1042 leg->SetFillColor(10);
1043 leg->SetY1(.9-i*.05);
1044 leg->Draw();
1045 }
1046 if (hFirst&&(hFirst->GetYaxis()->GetXmax()<max)){
1047 hFirst->SetMaximum(max);
1048 }
1049}
1050
1051//_____________________________________________________________________________
1052void AliDielectronHistos::SetReservedWords(const char* words)
1053{
1054 //
1055 // set reserved words
1056 //
80c1dcac 1057
b2a297fa 1058 (*fReservedWords)=words;
1059}
5720c765 1060
1061//_____________________________________________________________________________
80c1dcac 1062void AliDielectronHistos::StoreVariables(TObject *obj, UInt_t valType[20])
1063{
1064 //
1065 //
1066 //
1067 if (!obj) return;
1068 if (obj->InheritsFrom(TH1::Class())) StoreVariables(static_cast<TH1*>(obj), valType);
0caf5fbb 1069 else if (obj->InheritsFrom(THnBase::Class())) StoreVariables(static_cast<THnBase*>(obj), valType);
80c1dcac 1070
1071 return;
1072
1073}
1074
1075
1076//_____________________________________________________________________________
1077void AliDielectronHistos::StoreVariables(TH1 *obj, UInt_t valType[20])
1078{
1079 //
1080 // store variables in the axis (special for TProfile3D)
1081 //
1082
1083 Int_t dim = obj->GetDimension();
80c1dcac 1084
1085 // dimension correction for profiles
1086 if(obj->IsA() == TProfile::Class() || obj->IsA() == TProfile2D::Class() || obj->IsA() == TProfile3D::Class()) {
80c1dcac 1087 dim++;
1088 }
1089
80c1dcac 1090 switch( dim ) {
1091 case 4:
1092 obj->SetUniqueID(valType[3]); // Tprofile3D variable
1093 case 3:
1094 obj->GetZaxis()->SetUniqueID(valType[2]);
80c1dcac 1095 case 2:
1096 obj->GetYaxis()->SetUniqueID(valType[1]);
80c1dcac 1097 case 1:
1098 obj->GetXaxis()->SetUniqueID(valType[0]);
80c1dcac 1099 }
1100
1101 return;
1102}
1103
1104//_____________________________________________________________________________
849a30fc 1105void AliDielectronHistos::StoreVariables(THnBase *obj, UInt_t valType[20])
80c1dcac 1106{
1107 //
1108 // store variables in the axis
1109 //
1110
1111 Int_t dim = obj->GetNdimensions();
1112
1113 for(Int_t it=0; it<dim; it++) {
1114 obj->GetAxis(it)->SetUniqueID(valType[it]);
f3d19103 1115 obj->GetAxis(it)->SetName(Form("%s", AliDielectronVarManager::GetValueName(valType[it])));
80c1dcac 1116 obj->GetAxis(it)->SetTitle(Form("%s %s", AliDielectronVarManager::GetValueLabel(valType[it]), AliDielectronVarManager::GetValueUnit(valType[it])));
1117 }
1118 obj->Sumw2();
1119 return;
1120}
1121
1122//_____________________________________________________________________________
1123void AliDielectronHistos::FillValues(TObject *obj, const Double_t *values)
1124{
1125 //
1126 //
1127 //
1128 if (!obj) return;
0caf5fbb 1129 if (obj->InheritsFrom(TH1::Class())) FillValues(static_cast<TH1*>(obj), values);
1130 else if (obj->InheritsFrom(THnBase::Class())) FillValues(static_cast<THnBase*>(obj), values);
80c1dcac 1131
1132 return;
1133
1134}
1135
1136//_____________________________________________________________________________
1137void AliDielectronHistos::FillValues(TH1 *obj, const Double_t *values)
5720c765 1138{
1139 //
80c1dcac 1140 // fill values for TH1 inherted classes
5720c765 1141 //
80c1dcac 1142
1143 Int_t dim = obj->GetDimension();
1144 Bool_t bprf = kFALSE;
1145 // UInt_t nValues = (UInt_t) AliDielectronVarManager::kNMaxValues;
1146
1147 UInt_t valueTypes=obj->GetUniqueID();
35363fb9 1148 if (valueTypes==(UInt_t)AliDielectronHistos::kNoAutoFill) return;
80c1dcac 1149
1150 if(obj->IsA() == TProfile::Class() || obj->IsA() == TProfile2D::Class() || obj->IsA() == TProfile3D::Class())
1151 bprf=kTRUE;
0caf5fbb 1152
80c1dcac 1153 UInt_t value1=obj->GetXaxis()->GetUniqueID();
1154 UInt_t value2=obj->GetYaxis()->GetUniqueID();
1155 UInt_t value3=obj->GetZaxis()->GetUniqueID();
1156 UInt_t value4=obj->GetUniqueID(); // get profile var stored in the unique ID
1157
80c1dcac 1158 switch ( dim ) {
1159 case 1:
1160 if(!bprf) obj->Fill(values[value1]); // histograms
1161 else ((TProfile*)obj)->Fill(values[value1],values[value2]); // profiles
1162 break;
1163 case 2:
1164 if(!bprf) ((TH2*)obj)->Fill(values[value1],values[value2]);
1165 else ((TProfile2D*)obj)->Fill(values[value1],values[value2],values[value3]);
1166 break;
1167 case 3:
1168 if(!bprf) ((TH3*)obj)->Fill(values[value1],values[value2],values[value3]);
1169 else ((TProfile3D*)obj)->Fill(values[value1],values[value2],values[value3],values[value4]);
1170 break;
5720c765 1171 }
80c1dcac 1172
1173 return;
1174}
1175
1176//_____________________________________________________________________________
849a30fc 1177void AliDielectronHistos::FillValues(THnBase *obj, const Double_t *values)
80c1dcac 1178{
1179 //
1180 // fill values for THn inherted classes
1181 //
1182
1183 const Int_t dim = obj->GetNdimensions();
1184
1185 UInt_t valueTypes=obj->GetUniqueID();
35363fb9 1186 if (valueTypes==(UInt_t)AliDielectronHistos::kNoAutoFill) return;
80c1dcac 1187
1188 Double_t fill[dim];
1189 for(Int_t it=0; it<dim; it++) fill[it] = values[obj->GetAxis(it)->GetUniqueID()];
1190 obj->Fill(fill);
1191
1192 return;
1193}
1194
80c1dcac 1195//_____________________________________________________________________________
1196void AliDielectronHistos::FillVarArray(TObject *obj, UInt_t *valType)
1197{
1198 //
1199 // extract variables stored in the axis (special for TProfile3D)
1200 //
1201
1202
1203 if (!obj) return;
1204 // printf(" fillvararray %s \n",obj->GetName());
1205
1206 if (obj->InheritsFrom(TH1::Class())) {
1207 valType[0]=((TH1*)obj)->GetXaxis()->GetUniqueID();
1208 valType[1]=((TH1*)obj)->GetYaxis()->GetUniqueID();
1209 valType[2]=((TH1*)obj)->GetZaxis()->GetUniqueID();
1210 valType[3]=((TH1*)obj)->GetUniqueID(); // tprofile var stored in unique ID
1211 }
849a30fc 1212 else if (obj->InheritsFrom(THnBase::Class())) {
80c1dcac 1213 for(Int_t it=0; it<((THn*)obj)->GetNdimensions(); it++)
1214 valType[it]=((THn*)obj)->GetAxis(it)->GetUniqueID();
1215 }
80c1dcac 1216 return;
1217}
1218
1219//_____________________________________________________________________________
1220void AliDielectronHistos::AdaptNameTitle(TH1 *hist, const char* histClass) {
1221
1222 //
1223 // adapt name and title of the histogram
1224 //
1225
1226 Int_t dim = hist->GetDimension();
1227 TString currentName = hist->GetName();
1228 TString currentTitle = hist->GetTitle();
1229
1230
1231 Bool_t bname = (currentName.IsNull());
1232 Bool_t btitle = (currentTitle.IsNull());
1233 Bool_t bprf = kFALSE;
1234 if(hist->IsA() == TProfile::Class() || hist->IsA() == TProfile2D::Class() || hist->IsA() == TProfile3D::Class())
1235 bprf=kTRUE;
1236
849a30fc 1237 // tprofile options
1238 Double_t pmin=0., pmax=0.;
1239 TString option = "", calcrange="";
1240 Bool_t bStdOpt=kTRUE;
1241 if(bprf) {
1242 switch( dim ) {
1243 case 3:
1244 option = ((TProfile3D*)hist)->GetErrorOption();
1245 pmin = ((TProfile3D*)hist)->GetTmin();
1246 pmax = ((TProfile3D*)hist)->GetTmax();
1247 break;
1248 case 2:
1249 option = ((TProfile2D*)hist)->GetErrorOption();
1250 pmin = ((TProfile2D*)hist)->GetZmin();
1251 pmax = ((TProfile2D*)hist)->GetZmax();
1252 break;
1253 case 1:
1254 option = ((TProfile*)hist)->GetErrorOption();
1255 pmin = ((TProfile*)hist)->GetYmin();
1256 pmax = ((TProfile*)hist)->GetYmax();
1257 break;
1258 }
1259 if(option.Contains("s",TString::kIgnoreCase)) bStdOpt=kFALSE;
1260 if(pmin!=pmax) calcrange=Form("#cbar_{%+.*f}^{%+.*f}",GetPrecision(pmin),pmin,GetPrecision(pmax),pmax);
849a30fc 1261 }
1262
80c1dcac 1263 UInt_t varx = hist->GetXaxis()->GetUniqueID();
1264 UInt_t vary = hist->GetYaxis()->GetUniqueID();
1265 UInt_t varz = hist->GetZaxis()->GetUniqueID();
1266 UInt_t varp = hist->GetUniqueID();
1267
1268 // store titles in the axis
1269 if(btitle) {
1270 switch( dim ) {
1271 case 3:
f3d19103 1272 hist->GetXaxis()->SetNameTitle(AliDielectronVarManager::GetValueName(varx),
1273 Form("%s %s",
1274 AliDielectronVarManager::GetValueLabel(varx),
80c1dcac 1275 AliDielectronVarManager::GetValueUnit(varx))
1276 );
f3d19103 1277 hist->GetYaxis()->SetNameTitle(AliDielectronVarManager::GetValueName(vary),
1278 Form("%s %s",
1279 AliDielectronVarManager::GetValueLabel(vary),
80c1dcac 1280 AliDielectronVarManager::GetValueUnit(vary))
1281 );
f3d19103 1282 hist->GetZaxis()->SetNameTitle(AliDielectronVarManager::GetValueName(varz),
1283 Form("%s %s",
1284 AliDielectronVarManager::GetValueLabel(varz),
80c1dcac 1285 AliDielectronVarManager::GetValueUnit(varz))
1286 );
849a30fc 1287 if(bprf)
f3d19103 1288 hist->SetNameTitle(AliDielectronVarManager::GetValueName(varp),
1289 Form("%s %s%s%s%s %s",
849a30fc 1290 hist->GetTitle(),
1291 (bStdOpt ? "#LT" : "RMS("),
f3d19103 1292 AliDielectronVarManager::GetValueLabel(varp),
849a30fc 1293 (bStdOpt ? "#GT" : ")"),
1294 calcrange.Data(),
1295 AliDielectronVarManager::GetValueUnit(varp))
1296 );
ffe8b396 1297 break;
80c1dcac 1298 case 2:
f3d19103 1299 hist->GetXaxis()->SetNameTitle(AliDielectronVarManager::GetValueName(varx),
1300 Form("%s %s",
1301 AliDielectronVarManager::GetValueLabel(varx),
80c1dcac 1302 AliDielectronVarManager::GetValueUnit(varx))
1303 );
f3d19103 1304 hist->GetYaxis()->SetNameTitle(AliDielectronVarManager::GetValueName(vary),
1305 Form("%s %s",
1306 AliDielectronVarManager::GetValueLabel(vary),
80c1dcac 1307 AliDielectronVarManager::GetValueUnit(vary))
1308 );
1309 hist->GetZaxis()->SetTitle(Form("#%ss",histClass));
1310 if(bprf)
f3d19103 1311 hist->GetZaxis()->SetNameTitle(AliDielectronVarManager::GetValueName(varz),
1312 Form("%s%s%s%s %s",
849a30fc 1313 (bStdOpt ? "#LT" : "RMS("),
f3d19103 1314 AliDielectronVarManager::GetValueLabel(varz),
849a30fc 1315 (bStdOpt ? "#GT" : ")"),
1316 calcrange.Data(),
80c1dcac 1317 AliDielectronVarManager::GetValueUnit(varz))
1318 );
ffe8b396 1319 break;
80c1dcac 1320 case 1:
f3d19103 1321 hist->GetXaxis()->SetNameTitle(AliDielectronVarManager::GetValueName(varx),
1322 Form("%s %s",
1323 AliDielectronVarManager::GetValueLabel(varx),
80c1dcac 1324 AliDielectronVarManager::GetValueUnit(varx))
1325 );
1326 hist->GetYaxis()->SetTitle(Form("#%ss",histClass));
1327 if(bprf)
f3d19103 1328 hist->GetYaxis()->SetNameTitle(AliDielectronVarManager::GetValueName(vary),
1329 Form("%s%s%s%s %s",
849a30fc 1330 (bStdOpt ? "#LT" : "RMS("),
80c1dcac 1331 AliDielectronVarManager::GetValueLabel(vary),
849a30fc 1332 (bStdOpt ? "#GT" : ")"),
1333 calcrange.Data(),
80c1dcac 1334 AliDielectronVarManager::GetValueUnit(vary))
1335 );
ffe8b396 1336 break;
80c1dcac 1337 }
1338
1339 // create an unique name
1340 if(bname)
1341 switch(dim) {
1342 case 3:
1343 currentName+=Form("%s_",AliDielectronVarManager::GetValueName(varx));
1344 currentName+=Form("%s_",AliDielectronVarManager::GetValueName(vary));
1345 currentName+=Form("%s",AliDielectronVarManager::GetValueName(varz));
7a1ddc4b 1346 if(bprf) currentName+=Form("-%s%s",AliDielectronVarManager::GetValueName(varp),(bStdOpt ? "avg" : "rms"));
80c1dcac 1347 break;
1348 case 2:
1349 currentName+=Form("%s_",AliDielectronVarManager::GetValueName(varx));
1350 currentName+=Form("%s",AliDielectronVarManager::GetValueName(vary));
7a1ddc4b 1351 if(bprf) currentName+=Form("-%s%s",AliDielectronVarManager::GetValueName(varz),(bStdOpt ? "avg" : "rms"));
80c1dcac 1352 break;
1353 case 1:
1354 currentName+=Form("%s",AliDielectronVarManager::GetValueName(varx));
7a1ddc4b 1355 if(bprf) currentName+=Form("-%s%s",AliDielectronVarManager::GetValueName(vary),(bStdOpt ? "avg" : "rms"));
80c1dcac 1356 break;
1357 }
1358 // to differentiate btw. leg and pair histos
1359 if(!strcmp(histClass,"Pair")) currentName.Prepend("p");
1360 hist->SetName(currentName.Data());
1361 }
1362
849a30fc 1363}
1364
1365Int_t AliDielectronHistos::GetPrecision(Double_t value) {
1366
1367 //
1368 // computes the precision of a double
1369 // usefull for axis ranges etc
1370 //
1371
1372 Bool_t bfnd = kFALSE;
1373 Int_t precision = 0;
1374
1375 while(!bfnd) {
1376 // printf(" value %f precision %d bfnd %d \n",TMath::Abs(value*TMath::Power(10,precision)), precision, bfnd);
1377 bfnd = (TMath::Abs(value*TMath::Power(10,precision)) - TMath::Floor(TMath::Abs(value*TMath::Power(10,precision))) != 0.0
1378 ? kFALSE
1379 : kTRUE);
1380 if(!bfnd) precision++;
1381 }
1382
1383 // printf("precision for %f found to be %d \n", value, precision);
1384 return precision;
80c1dcac 1385
1386}
1387
1388
5720c765 1389