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