]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGDQ/dielectron/AliDielectronHistos.cxx
Add event selection depending on high energy clusters existance in EMCal to speed...
[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>
5720c765 29#include <TProfile.h>
30#include <TProfile2D.h>
31#include <TProfile3D.h>
b2a297fa 32#include <TCollection.h>
33#include <THashList.h>
34#include <TString.h>
61d106d3 35#include <TObjString.h>
b2a297fa 36#include <TObjArray.h>
37#include <TFile.h>
38#include <TError.h>
39#include <TCanvas.h>
40#include <TMath.h>
41#include <TROOT.h>
42#include <TLegend.h>
43#include <TKey.h>
572b0139 44#include <TAxis.h>
45#include <TVirtualPS.h>
ffbede40 46#include <TVectorD.h>
b2a297fa 47
ffbede40 48#include "AliDielectronHelper.h"
07480df6 49#include "AliDielectronVarManager.h"
b2a297fa 50#include "AliDielectronHistos.h"
51
52
53ClassImp(AliDielectronHistos)
54
55
56AliDielectronHistos::AliDielectronHistos() :
57// TCollection(),
58 TNamed("AliDielectronHistos","Dielectron Histogram Container"),
59 fHistoList(),
164bfb53 60 fList(0x0),
b2a297fa 61 fReservedWords(new TString)
62{
63 //
64 // Default constructor
65 //
66 fHistoList.SetOwner(kTRUE);
67 fHistoList.SetName("Dielectron_Histos");
68}
69
70//_____________________________________________________________________________
71AliDielectronHistos::AliDielectronHistos(const char* name, const char* title) :
72// TCollection(),
73 TNamed(name, title),
74 fHistoList(),
164bfb53 75 fList(0x0),
b2a297fa 76 fReservedWords(new TString)
77{
78 //
79 // TNamed constructor
80 //
81 fHistoList.SetOwner(kTRUE);
82 fHistoList.SetName(name);
83}
84
85//_____________________________________________________________________________
86AliDielectronHistos::~AliDielectronHistos()
87{
88 //
89 // Destructor
90 //
61d106d3 91 fHistoList.Clear();
48609e3d 92 if (fList) fList->Clear();
b2a297fa 93 delete fReservedWords;
94}
95
96//_____________________________________________________________________________
5720c765 97void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
98 UInt_t valTypeP,
99 Int_t nbinsX, Double_t xmin, Double_t xmax,
e4339752 100 UInt_t valTypeX, Bool_t logBinX, TString option)
b2a297fa 101{
102 //
103 // Default histogram creation 1D case
104 //
572b0139 105
ffbede40 106 TVectorD *binLimX=0x0;
572b0139 107
108 if (logBinX) {
ffbede40 109 binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
572b0139 110 } else {
ffbede40 111 binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
572b0139 112 }
e4339752 113 UserProfile(histClass,name,title,valTypeP,binLimX,valTypeX,option);
b2a297fa 114}
115
116//_____________________________________________________________________________
5720c765 117void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
118 UInt_t valTypeP,
119 Int_t nbinsX, Double_t xmin, Double_t xmax,
120 Int_t nbinsY, Double_t ymin, Double_t ymax,
121 UInt_t valTypeX, UInt_t valTypeY,
e4339752 122 Bool_t logBinX, Bool_t logBinY, TString option)
b2a297fa 123{
124 //
125 // Default histogram creation 2D case
126 //
127 if (!IsHistogramOk(histClass,name)) return;
128
ffbede40 129 TVectorD *binLimX=0x0;
130 TVectorD *binLimY=0x0;
572b0139 131
132 if (logBinX) {
ffbede40 133 binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
572b0139 134 } else {
ffbede40 135 binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
572b0139 136 }
137 if (logBinY) {
ffbede40 138 binLimY=AliDielectronHelper::MakeLogBinning(nbinsY, ymin, ymax);
572b0139 139 } else {
ffbede40 140 binLimY=AliDielectronHelper::MakeLinBinning(nbinsY, ymin, ymax);
572b0139 141 }
e4339752 142 UserProfile(histClass,name,title,valTypeP,binLimX,binLimY,valTypeX,valTypeY,option);
b2a297fa 143}
144
145
146//_____________________________________________________________________________
5720c765 147void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
148 UInt_t valTypeP,
149 Int_t nbinsX, Double_t xmin, Double_t xmax,
150 Int_t nbinsY, Double_t ymin, Double_t ymax,
151 Int_t nbinsZ, Double_t zmin, Double_t zmax,
152 UInt_t valTypeX, UInt_t valTypeY, UInt_t valTypeZ,
e4339752 153 Bool_t logBinX, Bool_t logBinY, Bool_t logBinZ, TString option)
b2a297fa 154{
155 //
156 // Default histogram creation 3D case
157 //
158 if (!IsHistogramOk(histClass,name)) return;
159
ffbede40 160 TVectorD *binLimX=0x0;
161 TVectorD *binLimY=0x0;
162 TVectorD *binLimZ=0x0;
572b0139 163
164 if (logBinX) {
ffbede40 165 binLimX=AliDielectronHelper::MakeLogBinning(nbinsX, xmin, xmax);
572b0139 166 } else {
ffbede40 167 binLimX=AliDielectronHelper::MakeLinBinning(nbinsX, xmin, xmax);
572b0139 168 }
169
170 if (logBinY) {
ffbede40 171 binLimY=AliDielectronHelper::MakeLogBinning(nbinsY, ymin, ymax);
572b0139 172 } else {
ffbede40 173 binLimY=AliDielectronHelper::MakeLinBinning(nbinsY, ymin, ymax);
572b0139 174 }
175
176 if (logBinZ) {
ffbede40 177 binLimZ=AliDielectronHelper::MakeLogBinning(nbinsZ, zmin, zmax);
572b0139 178 } else {
ffbede40 179 binLimZ=AliDielectronHelper::MakeLinBinning(nbinsZ, zmin, zmax);
180 }
181
e4339752 182 UserProfile(histClass,name,title,valTypeP,binLimX,binLimY,binLimZ,valTypeX,valTypeY,valTypeZ,option);
ffbede40 183}
184
185//_____________________________________________________________________________
5720c765 186void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
187 UInt_t valTypeP,
188 const char* binning,
e4339752 189 UInt_t valTypeX, TString option)
ffbede40 190{
191 //
192 // Histogram creation 1D case with arbitraty binning
193 //
194
195 TVectorD *binLimX=AliDielectronHelper::MakeArbitraryBinning(binning);
e4339752 196 UserProfile(histClass,name,title,valTypeP,binLimX,valTypeX,option);
ffbede40 197}
198
199//_____________________________________________________________________________
5720c765 200void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
201 UInt_t valTypeP,
202 const TVectorD * const binsX,
e4339752 203 UInt_t valTypeX/*=kNoAutoFill*/, TString option)
ffbede40 204{
205 //
206 // Histogram creation 1D case with arbitraty binning X
207 // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
208 //
209
34107494 210 // set automatic histo name if needed
211 if(!strlen(name)) name=Form("%s%s%s", (strcmp(histClass,"Pair")==0?"p":""), AliDielectronVarManager::GetValueName(valTypeX),
212 (valTypeP!=999? Form("-%s%s",(option.Contains("s",TString::kIgnoreCase)?"rms":"avg"),AliDielectronVarManager::GetValueName(valTypeP)) : "") );
213
ffbede40 214 Bool_t isOk=kTRUE;
215 isOk&=IsHistogramOk(histClass,name);
216 isOk&=(binsX!=0x0);
5720c765 217 TH1 *hist=0x0;
ffbede40 218
07480df6 219 // set axis titles if not specified
34107494 220 if(!strlen(title)) title=Form(";%s;%s", AliDielectronVarManager::GetValueName(valTypeX),
221 (valTypeP!=999 ?
222 (option.Contains("s",TString::kIgnoreCase) ?
223 Form("RMS(%s)",AliDielectronVarManager::GetValueName(valTypeP)) :
224 Form("#LT%s#GT",AliDielectronVarManager::GetValueName(valTypeP)) ) :
225 Form("#%ss",histClass)) );
07480df6 226
5720c765 227 if (isOk){
228 if(valTypeP==999)
229 hist=new TH1F(name,title,binsX->GetNrows()-1,binsX->GetMatrixArray());
230 else {
e4339752 231 TString opt=""; Double_t pmin=0., pmax=0.;
232 if(!option.IsNull()) {
233 TObjArray *arr=option.Tokenize(";");
234 arr->SetOwner();
235 opt=((TObjString*)arr->At(0))->GetString();
236 if(arr->GetEntriesFast()>1) pmin=(((TObjString*)arr->At(1))->GetString()).Atof();
237 if(arr->GetEntriesFast()>2) pmax=(((TObjString*)arr->At(2))->GetString()).Atof();
238 delete arr;
239 }
5720c765 240 hist=new TProfile(name,title,binsX->GetNrows()-1,binsX->GetMatrixArray());
e4339752 241 ((TProfile*)hist)->BuildOptions(pmin,pmax,opt.Data());
242 // printf(" name %s PROFILE options: pmin %.1f pmax %.1f err %s \n",name,((TProfile*)hist)->GetYmin(),((TProfile*)hist)->GetYmax(),((TProfile*)hist)->GetErrorOption() );
5720c765 243 }
244
245 // store var for profile in fBits
246 StoreVarForProfile(hist,valTypeP);
247
ffbede40 248 Bool_t isReserved=fReservedWords->Contains(histClass);
5720c765 249 UInt_t uniqueID = valTypeX;
250 if(valTypeP!=999) uniqueID |= 0x80000000; // set last bit to 1 (for profiles only)
ffbede40 251 if (isReserved)
5720c765 252 UserHistogramReservedWords(histClass, hist, uniqueID);
ffbede40 253 else
5720c765 254 UserHistogram(histClass, hist, uniqueID);
ffbede40 255 }
256
257 delete binsX;
258}
259
260//_____________________________________________________________________________
5720c765 261void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
262 UInt_t valTypeP,
263 const TVectorD * const binsX, const TVectorD * const binsY,
e4339752 264 UInt_t valTypeX/*=kNoAutoFill*/, UInt_t valTypeY/*=0*/, TString option)
ffbede40 265{
266 //
5720c765 267 // Histogram creation 2D case with arbitraty binning X
ffbede40 268 // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
269 //
270
34107494 271 // set automatic histo name if needed
272 if(!strlen(name)) name=Form("%s%s_%s%s", (strcmp(histClass,"Pair")==0?"p":""), AliDielectronVarManager::GetValueName(valTypeX), AliDielectronVarManager::GetValueName(valTypeY),
273 (valTypeP!=999? Form("-%s%s",(option.Contains("s",TString::kIgnoreCase)?"rms":"avg"),AliDielectronVarManager::GetValueName(valTypeP)) : "") );
274
275
ffbede40 276 Bool_t isOk=kTRUE;
277 isOk&=IsHistogramOk(histClass,name);
278 isOk&=(binsX!=0x0);
279 isOk&=(binsY!=0x0);
5720c765 280 TH1 *hist=0x0;
ffbede40 281
07480df6 282 // set axis titles if not specified
34107494 283 if(!strlen(title)) title=Form(";%s;%s;%s", AliDielectronVarManager::GetValueName(valTypeX), AliDielectronVarManager::GetValueName(valTypeY),
284 (valTypeP!=999 ?
285 (option.Contains("s",TString::kIgnoreCase) ?
286 Form("RMS(%s)",AliDielectronVarManager::GetValueName(valTypeP)) :
287 Form("#LT%s#GT",AliDielectronVarManager::GetValueName(valTypeP)) ) :
288 Form("#%ss",histClass)) );
07480df6 289
ffbede40 290 if (isOk){
5720c765 291 if(valTypeP==999) {
292 hist=new TH2F(name,title,
293 binsX->GetNrows()-1,binsX->GetMatrixArray(),
294 binsY->GetNrows()-1,binsY->GetMatrixArray());
295 }
e4339752 296 else {
297 TString opt=""; Double_t pmin=0., pmax=0.;
298 if(!option.IsNull()) {
299 TObjArray *arr=option.Tokenize(";");
300 arr->SetOwner();
301 opt=((TObjString*)arr->At(0))->GetString();
302 if(arr->GetEntriesFast()>1) pmin=(((TObjString*)arr->At(1))->GetString()).Atof();
303 if(arr->GetEntriesFast()>2) pmax=(((TObjString*)arr->At(2))->GetString()).Atof();
304 delete arr;
305 }
5720c765 306 hist=new TProfile2D(name,title,
307 binsX->GetNrows()-1,binsX->GetMatrixArray(),
308 binsY->GetNrows()-1,binsY->GetMatrixArray());
e4339752 309 ((TProfile2D*)hist)->BuildOptions(pmin,pmax,opt.Data());
310 // printf(" name %s PROFILE options: pmin %.1f pmax %.1f err %s \n",name,((TProfile*)hist)->GetYmin(),((TProfile*)hist)->GetYmax(),((TProfile*)hist)->GetErrorOption() );
311 }
312
5720c765 313 // store var for profile in fBits
314 StoreVarForProfile(hist,valTypeP);
315
ffbede40 316 Bool_t isReserved=fReservedWords->Contains(histClass);
5720c765 317 // switched from 2 digits encoding to 3 digits
318 UInt_t uniqueID = valTypeX+1000*valTypeY;
319 if(valTypeP!=999) uniqueID |= 0x80000000; // set last bit to 1 (for profiles only)
320
ffbede40 321 if (isReserved)
5720c765 322 UserHistogramReservedWords(histClass, hist, uniqueID);
ffbede40 323 else
5720c765 324 UserHistogram(histClass, hist, uniqueID);
572b0139 325 }
326
ffbede40 327 delete binsX;
328 delete binsY;
329
330}
331
332//_____________________________________________________________________________
5720c765 333void AliDielectronHistos::UserProfile(const char* histClass,const char *name, const char* title,
334 UInt_t valTypeP,
335 const TVectorD * const binsX, const TVectorD * const binsY, const TVectorD * const binsZ,
e4339752 336 UInt_t valTypeX/*=kNoAutoFill*/, UInt_t valTypeY/*=0*/, UInt_t valTypeZ/*=0*/, TString option)
ffbede40 337{
338 //
5720c765 339 // Histogram creation 3D case with arbitraty binning X
ffbede40 340 // the TVectorD is assumed to be surplus after the creation and will be deleted!!!
341 //
342
34107494 343 // set automatic histo name if needed
344 if(!strlen(name)) name=Form("%s%s_%s_%s%s", (strcmp(histClass,"Pair")==0?"p":""), AliDielectronVarManager::GetValueName(valTypeX), AliDielectronVarManager::GetValueName(valTypeY), AliDielectronVarManager::GetValueName(valTypeZ),
345 (valTypeP!=999? Form("-%s%s",(option.Contains("s",TString::kIgnoreCase)?"rms":"avg"),AliDielectronVarManager::GetValueName(valTypeP)) : "") );
346
347
ffbede40 348 Bool_t isOk=kTRUE;
349 isOk&=IsHistogramOk(histClass,name);
350 isOk&=(binsX!=0x0);
351 isOk&=(binsY!=0x0);
352 isOk&=(binsZ!=0x0);
5720c765 353 TH1 *hist=0x0;
07480df6 354
34107494 355 // set axis titles if not specified
356 if(!strlen(title)) title=Form(";%s;%s;%s", AliDielectronVarManager::GetValueName(valTypeX), AliDielectronVarManager::GetValueName(valTypeY), AliDielectronVarManager::GetValueName(valTypeZ));
07480df6 357
ffbede40 358 if (isOk){
5720c765 359 if(valTypeP==999)
360 hist=new TH3F(name,title,
361 binsX->GetNrows()-1,binsX->GetMatrixArray(),
362 binsY->GetNrows()-1,binsY->GetMatrixArray(),
363 binsZ->GetNrows()-1,binsZ->GetMatrixArray());
e4339752 364 else {
365 TString opt=""; Double_t pmin=0., pmax=0.;
366 if(!option.IsNull()) {
367 TObjArray *arr=option.Tokenize(";");
368 arr->SetOwner();
369 opt=((TObjString*)arr->At(0))->GetString();
370 if(arr->GetEntriesFast()>1) pmin=(((TObjString*)arr->At(1))->GetString()).Atof();
371 if(arr->GetEntriesFast()>2) pmax=(((TObjString*)arr->At(2))->GetString()).Atof();
372 delete arr;
373 }
5720c765 374 hist=new TProfile3D(name,title,
375 binsX->GetNrows()-1,binsX->GetMatrixArray(),
376 binsY->GetNrows()-1,binsY->GetMatrixArray(),
377 binsZ->GetNrows()-1,binsZ->GetMatrixArray());
e4339752 378 ((TProfile3D*)hist)->BuildOptions(pmin,pmax,opt.Data());
379 // printf(" name %s PROFILE options: pmin %.1f pmax %.1f err %s \n",name,((TProfile*)hist)->GetYmin(),((TProfile*)hist)->GetYmax(),((TProfile*)hist)->GetErrorOption() );
380 }
381
5720c765 382 // store var for profile in fBits
383 StoreVarForProfile(hist,valTypeP);
384
ffbede40 385 Bool_t isReserved=fReservedWords->Contains(histClass);
5720c765 386 // switched from 2 digits encoding to 3 digits
387 UInt_t uniqueID = valTypeX+1000*valTypeY+1000000*valTypeZ;
388 if(valTypeP!=999) uniqueID |= 0x80000000; // set last bit to 1 (for profiles only)
389
ffbede40 390 if (isReserved)
5720c765 391 UserHistogramReservedWords(histClass, hist, uniqueID);
ffbede40 392 else
5720c765 393 UserHistogram(histClass, hist, uniqueID);
ffbede40 394 }
572b0139 395
ffbede40 396 delete binsX;
397 delete binsY;
398 delete binsZ;
b2a297fa 399}
400
401//_____________________________________________________________________________
402void AliDielectronHistos::UserHistogram(const char* histClass, TH1* hist, UInt_t valTypes)
403{
404 //
405 // Add any type of user histogram
406 //
407
408 //special case for the calss Pair. where histograms will be created for all pair classes
409 Bool_t isReserved=fReservedWords->Contains(histClass);
410 if (isReserved) {
411 UserHistogramReservedWords(histClass, hist, valTypes);
412 return;
413 }
414
415 if (!IsHistogramOk(histClass,hist->GetName())) return;
b2a297fa 416 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
417 hist->SetDirectory(0);
418 hist->SetUniqueID(valTypes);
5720c765 419
b2a297fa 420 classTable->Add(hist);
421}
422
423//_____________________________________________________________________________
424void AliDielectronHistos::AddClass(const char* histClass)
425{
426 //
427 // Add a class of histograms
428 // Several classes can be added by separating them by a ';' e.g. 'class1;class2;class3'
429 //
430 TString hists(histClass);
431 TObjArray *arr=hists.Tokenize(";");
432 TIter next(arr);
433 TObject *o=0;
434 while ( (o=next()) ){
435 if (fHistoList.FindObject(o->GetName())){
436 Warning("AddClass","Cannot create class '%s' it already exists.",histClass);
437 continue;
438 }
439 if (fReservedWords->Contains(o->GetName())){
440 Error("AddClass","Pair is a reserved word, please use another name");
441 continue;
442 }
443 THashList *table=new THashList;
444 table->SetOwner(kTRUE);
445 table->SetName(o->GetName());
446 fHistoList.Add(table);
447 }
448 delete arr;
449}
450
451//_____________________________________________________________________________
452void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval)
453{
454 //
455 // Fill function 1D case
456 //
457 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
458 TH1* hist=0;
459 if (!classTable || !(hist=(TH1*)classTable->FindObject(name)) ){
460 Warning("Fill","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
461 return;
462 }
463 hist->Fill(xval);
464}
465
466//_____________________________________________________________________________
467void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval, Double_t yval)
468{
469 //
470 // Fill function 2D case
471 //
472 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
473 TH2* hist=0;
474 if (!classTable || !(hist=(TH2*)classTable->FindObject(name)) ){
475 Warning("UserHistogram","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
476 return;
477 }
478 hist->Fill(xval,yval);
479}
480
481//_____________________________________________________________________________
482void AliDielectronHistos::Fill(const char* histClass, const char* name, Double_t xval, Double_t yval, Double_t zval)
483{
484 //
485 // Fill function 3D case
486 //
487 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
488 TH3* hist=0;
489 if (!classTable || !(hist=(TH3*)classTable->FindObject(name)) ){
490 Warning("UserHistogram","Cannot fill histogram. Either class '%s' or histogram '%s' not existing.",histClass,name);
491 return;
492 }
493 hist->Fill(xval,yval,zval);
494}
495
496//_____________________________________________________________________________
497void AliDielectronHistos::FillClass(const char* histClass, Int_t nValues, const Double_t *values)
498{
499 //
500 // Fill class 'histClass' (by name)
5720c765 501 //
b2a297fa 502
503 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
504 if (!classTable){
505 Warning("FillClass","Cannot fill class '%s' its not defined.",histClass);
506 return;
507 }
508
509 TIter nextHist(classTable);
510 TH1 *hist=0;
511 while ( (hist=(TH1*)nextHist()) ){
5720c765 512 UInt_t value4=hist->TestBits(0x00ffffff)>>14; // get profile var stored in fBits
513 UInt_t valueTypes=hist->GetUniqueID()&0x7fffffff; // ignore "boolean" bit for profiles
514
b2a297fa 515 if (valueTypes==(UInt_t)kNoAutoFill) continue;
5720c765 516 UInt_t value1=valueTypes%1000; //last three digits
517 UInt_t value2=valueTypes/1000%1000; //second last three digits
518 UInt_t value3=valueTypes/1000000%1000; //third last three digits
519
520 if (value1>=(UInt_t)nValues||value2>=(UInt_t)nValues||value3>=(UInt_t)nValues||(value4>=(UInt_t)nValues && value4!=999)) {
521 Warning("FillClass","One of the values is out of range. Not filling Histogram '%s/%s'.", histClass, hist->GetName());
b2a297fa 522 continue;
523 }
524 switch (hist->GetDimension()){
525 case 1:
5720c765 526 if(value4==999) hist->Fill(values[value1]); // histograms
527 else ((TProfile*)hist)->Fill(values[value1],values[value4]); // profiles
b2a297fa 528 break;
529 case 2:
5720c765 530 if(value4==999) ((TH2*)hist)->Fill(values[value1],values[value2]);
531 else ((TProfile2D*)hist)->Fill(values[value1],values[value2],values[value4]);
b2a297fa 532 break;
533 case 3:
5720c765 534 if(value4==999) ((TH3*)hist)->Fill(values[value1],values[value2],values[value3]);
535 else ((TProfile3D*)hist)->Fill(values[value1],values[value2],values[value3],values[value4]);
b2a297fa 536 break;
537 }
538 }
539}
540
541//_____________________________________________________________________________
542// void AliDielectronHistos::FillClass(const char* histClass, const TVectorD &vals)
543// {
544// //
545// //
546// //
547// FillClass(histClass, vals.GetNrows(), vals.GetMatrixArray());
548// }
549
550//_____________________________________________________________________________
ffbede40 551void AliDielectronHistos::UserHistogramReservedWords(const char* histClass, const TH1 *hist, UInt_t valTypes)
b2a297fa 552{
553 //
554 // Creation of histogram for all pair types
555 //
556 TString title(hist->GetTitle());
557 // Same Event Like Sign
558 TIter nextClass(&fHistoList);
559 THashList *l=0;
560 while ( (l=static_cast<THashList*>(nextClass())) ){
561 TString name(l->GetName());
562 if (name.Contains(histClass)){
563 TH1 *h=static_cast<TH1*>(hist->Clone());
564 h->SetDirectory(0);
565 h->SetTitle(Form("%s %s",title.Data(),l->GetName()));
5720c765 566
b2a297fa 567 UserHistogram(l->GetName(),h,valTypes);
568 }
569 }
570 delete hist;
571}
572
573//_____________________________________________________________________________
574void AliDielectronHistos::DumpToFile(const char* file)
575{
576 //
577 // Dump the histogram list to a newly created root file
578 //
579 TFile f(file,"recreate");
580 fHistoList.Write(fHistoList.GetName(),TObject::kSingleKey);
581 f.Close();
582}
583
584//_____________________________________________________________________________
585TH1* AliDielectronHistos::GetHistogram(const char* histClass, const char* name) const
586{
587 //
588 // return histogram 'name' in 'histClass'
589 //
590 THashList *classTable=(THashList*)fHistoList.FindObject(histClass);
591 if (!classTable) return 0x0;
592 return (TH1*)classTable->FindObject(name);
593}
594
164bfb53 595//_____________________________________________________________________________
596TH1* AliDielectronHistos::GetHistogram(const char* cutClass, const char* histClass, const char* name) const
597{
598 //
599 // return histogram from list of list of histograms
600 // this function is thought for retrieving histograms if a list of AliDielectronHistos is set
601 //
602
603 if (!fList) return 0x0;
604 THashList *h=dynamic_cast<THashList*>(fList->FindObject(cutClass));
605 if (!h)return 0x0;
606 THashList *classTable=dynamic_cast<THashList*>(h->FindObject(histClass));
607 if (!classTable) return 0x0;
608 return (TH1*)classTable->FindObject(name);
609}
610
b2a297fa 611//_____________________________________________________________________________
612void AliDielectronHistos::Draw(const Option_t* option)
613{
614 //
615 // Draw histograms
616 //
617
37e9382d 618 TString drawStr(option);
61d106d3 619 TObjArray *arr=drawStr.Tokenize(";");
620 arr->SetOwner();
621 TIter nextOpt(arr);
622
623 TString drawClasses;
624 TObjString *ostr=0x0;
625
626 TString currentOpt;
627 TString testOpt;
628 while ( (ostr=(TObjString*)nextOpt()) ){
629 currentOpt=ostr->GetString();
630 currentOpt.Remove(TString::kBoth,'\t');
631 currentOpt.Remove(TString::kBoth,' ');
632
633 testOpt="classes=";
634 if ( currentOpt.Contains(testOpt.Data()) ){
635 drawClasses=currentOpt(testOpt.Length(),currentOpt.Length());
636 }
637 }
638
639 delete arr;
37e9382d 640 drawStr.ToLower();
164bfb53 641 //optionsfList
b2a297fa 642// Bool_t same=drawOpt.Contains("same"); //FIXME not yet implemented
572b0139 643
644 TCanvas *c=0x0;
645 if (gVirtualPS) {
646 if (!gPad){
647 Error("Draw","When writing to a file you have to create a canvas before opening the file!!!");
648 return;
649 }
650 c=gPad->GetCanvas();
61d106d3 651 c->cd();
572b0139 652// c=new TCanvas;
653 }
b2a297fa 654
655 TIter nextClass(&fHistoList);
656 THashList *classTable=0;
61d106d3 657// Bool_t first=kTRUE;
b2a297fa 658 while ( (classTable=(THashList*)nextClass()) ){
61d106d3 659 //test classes option
660 if (!drawClasses.IsNull() && !drawClasses.Contains(classTable->GetName())) continue;
b2a297fa 661 //optimised division
662 Int_t nPads = classTable->GetEntries();
663 Int_t nCols = (Int_t)TMath::Ceil( TMath::Sqrt(nPads) );
664 Int_t nRows = (Int_t)TMath::Ceil( (Double_t)nPads/(Double_t)nCols );
665
666 //create canvas
572b0139 667 if (!gVirtualPS){
668 TString canvasName;
669 canvasName.Form("c%s_%s",GetName(),classTable->GetName());
670 c=(TCanvas*)gROOT->FindObject(canvasName.Data());
671 if (!c) c=new TCanvas(canvasName.Data(),Form("%s: %s",GetName(),classTable->GetName()));
672 c->Clear();
673 } else {
61d106d3 674// if (first){
675// first=kFALSE;
676// if (nPads>1) gVirtualPS->NewPage();
677// } else {
678 if (nPads>1) c->Clear();
679// }
572b0139 680 }
681 if (nCols>1||nRows>1) c->Divide(nCols,nRows);
682
b2a297fa 683 //loop over histograms and draw them
684 TIter nextHist(classTable);
685 Int_t iPad=0;
686 TH1 *h=0;
687 while ( (h=(TH1*)nextHist()) ){
688 TString drawOpt;
689 if ( (h->InheritsFrom(TH2::Class())) ) drawOpt="colz";
572b0139 690 if (nCols>1||nRows>1) c->cd(++iPad);
691 if ( TMath::Abs(h->GetXaxis()->GetBinWidth(1)-h->GetXaxis()->GetBinWidth(2))>1e-10 ) gPad->SetLogx();
692 if ( TMath::Abs(h->GetYaxis()->GetBinWidth(1)-h->GetYaxis()->GetBinWidth(2))>1e-10 ) gPad->SetLogy();
693 if ( TMath::Abs(h->GetZaxis()->GetBinWidth(1)-h->GetZaxis()->GetBinWidth(2))>1e-10 ) gPad->SetLogz();
8df8e382 694 TString histOpt=h->GetOption();
695 histOpt.ToLower();
696 if (histOpt.Contains("logx")) gPad->SetLogx();
697 if (histOpt.Contains("logy")) gPad->SetLogy();
698 if (histOpt.Contains("logz")) gPad->SetLogz();
699 histOpt.ReplaceAll("logx","");
700 histOpt.ReplaceAll("logy","");
701 histOpt.ReplaceAll("logz","");
b2a297fa 702 h->Draw(drawOpt.Data());
703 }
61d106d3 704 if (gVirtualPS) {
705 c->Update();
706 }
707
b2a297fa 708 }
572b0139 709// if (gVirtualPS) delete c;
b2a297fa 710}
711
712//_____________________________________________________________________________
713void AliDielectronHistos::Print(const Option_t* option) const
714{
715 //
716 // Print classes and histograms
717 //
718 TString optString(option);
719
720 if (optString.IsNull()) PrintStructure();
721
722
723
724}
725
726//_____________________________________________________________________________
727void AliDielectronHistos::PrintStructure() const
728{
729 //
730 // Print classes and histograms in the class to stdout
731 //
164bfb53 732 if (!fList){
733 TIter nextClass(&fHistoList);
734 THashList *classTable=0;
735 while ( (classTable=(THashList*)nextClass()) ){
736 TIter nextHist(classTable);
737 TObject *o=0;
738 printf("+ %s\n",classTable->GetName());
739 while ( (o=nextHist()) )
740 printf("| ->%s\n",o->GetName());
741 }
742 } else {
743 TIter nextCutClass(fList);
744 THashList *cutClass=0x0;
745 while ( (cutClass=(THashList*)nextCutClass()) ) {
746 printf("+ %s\n",cutClass->GetName());
747 TIter nextClass(cutClass);
748 THashList *classTable=0;
749 while ( (classTable=(THashList*)nextClass()) ){
750 TIter nextHist(classTable);
751 TObject *o=0;
752 printf("| + %s\n",classTable->GetName());
753 while ( (o=nextHist()) )
754 printf("| | ->%s\n",o->GetName());
755 }
756
757 }
b2a297fa 758 }
b2a297fa 759}
760
761//_____________________________________________________________________________
164bfb53 762void AliDielectronHistos::SetHistogramList(THashList &list, Bool_t setOwner/*=kTRUE*/)
b2a297fa 763{
764 //
765 // set histogram classes and histograms to this instance. It will take onwnership!
766 //
572b0139 767 ResetHistogramList();
61d106d3 768 TString name(GetName());
769 if (name == "AliDielectronHistos") SetName(list.GetName());
b2a297fa 770 TIter next(&list);
771 TObject *o;
772 while ( (o=next()) ){
773 fHistoList.Add(o);
774 }
164bfb53 775 if (setOwner){
776 list.SetOwner(kFALSE);
777 fHistoList.SetOwner(kTRUE);
ffbede40 778 } else {
779 fHistoList.SetOwner(kFALSE);
164bfb53 780 }
781}
782
783//_____________________________________________________________________________
784Bool_t AliDielectronHistos::SetCutClass(const char* cutClass)
785{
786 //
787 // Assign histogram list according to cutClass
788 //
789
790 if (!fList) return kFALSE;
791 ResetHistogramList();
792 THashList *h=dynamic_cast<THashList*>(fList->FindObject(cutClass));
793 if (!h) {
794 Warning("SetCutClass","cutClass '%s' not found", cutClass);
795 return kFALSE;
796 }
797 SetHistogramList(*h,kFALSE);
798 return kTRUE;
b2a297fa 799}
800
801//_____________________________________________________________________________
802Bool_t AliDielectronHistos::IsHistogramOk(const char* histClass, const char* name)
803{
804 //
805 // check whether the histogram class exists and the histogram itself does not exist yet
806 //
807 Bool_t isReserved=fReservedWords->Contains(histClass);
808 if (!fHistoList.FindObject(histClass)&&!isReserved){
809 Warning("IsHistogramOk","Cannot create histogram. Class '%s' not defined. Please create it using AddClass before.",histClass);
810 return kFALSE;
811 }
812 if (GetHistogram(histClass,name)){
813 Warning("IsHistogramOk","Cannot create histogram '%s' in class '%s': It already exists!",name,histClass);
814 return kFALSE;
815 }
816 return kTRUE;
817}
818
819// //_____________________________________________________________________________
820// TIterator* AliDielectronHistos::MakeIterator(Bool_t dir) const
821// {
822// //
823// //
824// //
825// return new TListIter(&fHistoList, dir);
826// }
827
828//_____________________________________________________________________________
829void AliDielectronHistos::ReadFromFile(const char* file)
830{
831 //
832 // Read histos from file
833 //
834 TFile f(file);
835 TIter nextKey(f.GetListOfKeys());
836 TKey *key=0;
837 while ( (key=(TKey*)nextKey()) ){
838 TObject *o=f.Get(key->GetName());
839 THashList *list=dynamic_cast<THashList*>(o);
840 if (!list) continue;
841 SetHistogramList(*list);
842 break;
843 }
844 f.Close();
845}
846
572b0139 847//_____________________________________________________________________________
b2a297fa 848void AliDielectronHistos::DrawSame(const char* histName, const Option_t *opt)
849{
850 //
851 // Draw all histograms with the same name into one canvas
852 // if option contains 'leg' a legend will be created with the class name as caption
853 // if option contains 'can' a new canvas is created
854 //
855
856 TString optString(opt);
857 optString.ToLower();
858 Bool_t optLeg=optString.Contains("leg");
859 Bool_t optCan=optString.Contains("can");
860
861 TLegend *leg=0;
862 TCanvas *c=0;
863 if (optCan){
864 c=(TCanvas*)gROOT->FindObject(Form("c%s",histName));
865 if (!c) c=new TCanvas(Form("c%s",histName),Form("All '%s' histograms",histName));
866 c->Clear();
867 c->cd();
868 }
869
870 if (optLeg) leg=new TLegend(.8,.3,.99,.9);
871
872 Int_t i=0;
873 TIter next(&fHistoList);
874 THashList *classTable=0;
875 Double_t max=-1e10;
876 TH1 *hFirst=0x0;
877 while ( (classTable=(THashList*)next()) ){
878 if ( TH1 *h=(TH1*)classTable->FindObject(histName) ){
879 if (i==0) hFirst=h;
880 h->SetLineColor(i+1);
881 h->SetMarkerColor(i+1);
882 h->Draw(i>0?"same":"");
883 if (leg) leg->AddEntry(h,classTable->GetName(),"lp");
884 ++i;
885 max=TMath::Max(max,h->GetMaximum());
886 }
887 }
888 if (leg){
889 leg->SetFillColor(10);
890 leg->SetY1(.9-i*.05);
891 leg->Draw();
892 }
893 if (hFirst&&(hFirst->GetYaxis()->GetXmax()<max)){
894 hFirst->SetMaximum(max);
895 }
896}
897
898//_____________________________________________________________________________
899void AliDielectronHistos::SetReservedWords(const char* words)
900{
901 //
902 // set reserved words
903 //
904
905 (*fReservedWords)=words;
906}
5720c765 907
908//_____________________________________________________________________________
909void AliDielectronHistos::StoreVarForProfile(TObject *obj, UInt_t valType)
910{
911 //
912 // store var for TProfiles in TObject::fBits [14-23]
913 //
914
915 for(UInt_t i=14; i < sizeof(UInt_t)*8; i++) {
916 if(TESTBIT(valType,i-14)) {
917 obj->SetBit(1<<i,kTRUE);
918 }
919 }
920
921 return;
922}
923
924