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