]>
Commit | Line | Data |
---|---|---|
809a4336 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, 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 | **************************************************************************/ | |
50685501 | 15 | // |
16 | // Collection class for histograms | |
17 | // Stores either histograms or vectors of histograms | |
18 | // | |
19 | // Author: | |
20 | // Matus Kalisky <matus.kalisky@cern.ch> | |
21 | // | |
809a4336 | 22 | |
809a4336 | 23 | #include <TH1F.h> |
24 | #include <TH2F.h> | |
8c1c76e9 | 25 | #include <TH3F.h> |
9bcfd1ab | 26 | #include <THnSparse.h> |
27 | #include <TProfile.h> | |
809a4336 | 28 | #include <TString.h> |
29 | #include <TBrowser.h> | |
9bcfd1ab | 30 | #include <TMath.h> |
809a4336 | 31 | |
32 | #include "AliLog.h" | |
e156c3bb | 33 | |
809a4336 | 34 | #include "AliHFEcollection.h" |
35 | ||
36 | using namespace std; | |
37 | ||
38 | ||
39 | ClassImp(AliHFEcollection) | |
40 | ||
41 | //___________________________________________________________________ | |
42 | AliHFEcollection::AliHFEcollection(): | |
43 | TNamed() | |
69ac0e6f | 44 | , fList(NULL) |
809a4336 | 45 | { |
9bcfd1ab | 46 | |
809a4336 | 47 | // |
48 | // default constructor | |
49 | // | |
809a4336 | 50 | } |
51 | //___________________________________________________________________ | |
faee3b18 | 52 | AliHFEcollection::AliHFEcollection(const char* name, const char* title): |
809a4336 | 53 | TNamed(name, title) |
69ac0e6f | 54 | , fList(NULL) |
809a4336 | 55 | { |
56 | ||
57 | // | |
58 | // constructor | |
59 | // | |
60 | ||
70da6c5a | 61 | fList = new THashList(); |
bf892a6a | 62 | if(fList){ |
63 | fList->SetOwner(); | |
64 | fList->SetName(Form("list_%s", name)); | |
809a4336 | 65 | } |
66 | } | |
67 | //___________________________________________________________________ | |
68 | AliHFEcollection::AliHFEcollection(const AliHFEcollection &c) : | |
69 | TNamed(c) | |
69ac0e6f | 70 | , fList(NULL) |
809a4336 | 71 | { |
72 | ||
73 | // | |
74 | // copy operator | |
75 | // | |
76 | ||
77 | c.Copy(*this); | |
78 | } | |
79 | //___________________________________________________________________ | |
80 | AliHFEcollection &AliHFEcollection::operator=(const AliHFEcollection &ref) | |
81 | { | |
82 | // | |
83 | // Assignment operator | |
84 | // | |
85 | ||
86 | if(this != &ref){ | |
87 | ref.Copy(*this); | |
88 | } | |
89 | return *this; | |
90 | } | |
91 | //___________________________________________________________________ | |
92 | void AliHFEcollection::Copy(TObject &ref) const { | |
9bcfd1ab | 93 | |
809a4336 | 94 | // |
95 | // Performs the copying of the object | |
96 | // | |
9bcfd1ab | 97 | |
809a4336 | 98 | AliHFEcollection &target = dynamic_cast<AliHFEcollection &>(ref); |
99 | ||
70da6c5a | 100 | // Clone List Content |
101 | target.fList = new THashList(); | |
e156c3bb | 102 | target.fList->SetOwner(); |
70da6c5a | 103 | for(Int_t ien = 0; ien < fList->GetEntries(); ien++) |
104 | target.fList->Add(fList->At(ien)->Clone()); | |
809a4336 | 105 | } |
106 | //___________________________________________________________________ | |
107 | AliHFEcollection::~AliHFEcollection(){ | |
9bcfd1ab | 108 | |
50685501 | 109 | // |
110 | // Destructor | |
111 | // | |
70da6c5a | 112 | delete fList; |
3a72645a | 113 | AliDebug(1, "DESTRUCTOR"); |
809a4336 | 114 | } |
115 | //___________________________________________________________________ | |
faee3b18 | 116 | Bool_t AliHFEcollection::CreateTH1F(const char* name, const char* title, Int_t nBin, Float_t nMin, Float_t nMax, Int_t logAxis){ |
9bcfd1ab | 117 | |
50685501 | 118 | // |
119 | // Creates a TH1F histogram for the collection | |
120 | // | |
9bcfd1ab | 121 | |
122 | if(!fList){ | |
809a4336 | 123 | AliError("No TList pointer ! "); |
124 | return kFALSE; | |
125 | } | |
126 | else{ | |
9bcfd1ab | 127 | fList->Add(new TH1F(name, title, nBin, nMin, nMax)); |
faee3b18 | 128 | if(logAxis >= 0){ |
129 | BinLogAxis(name, logAxis); | |
130 | } | |
75d81601 | 131 | return CheckObject(name); |
809a4336 | 132 | } |
133 | } | |
c2690925 | 134 | |
135 | //___________________________________________________________________ | |
136 | Bool_t AliHFEcollection::CreateTH1Farray(const char* name, const char* title, Int_t nBin, const Double_t* xbins){ | |
137 | ||
138 | // | |
139 | // Creates a TH1F histogram for the collection 2nd version | |
140 | // | |
141 | ||
142 | if(!fList){ | |
143 | AliError("No TList pointer ! "); | |
144 | return kFALSE; | |
145 | } | |
146 | else{ | |
147 | fList->Add(new TH1F(name, title, nBin, xbins)); | |
148 | return CheckObject(name); | |
149 | } | |
150 | } | |
151 | ||
809a4336 | 152 | //___________________________________________________________________ |
faee3b18 | 153 | Bool_t AliHFEcollection::CreateTH2F(const char* name, const char* title, Int_t nBinX, Float_t nMinX, Float_t nMaxX, Int_t nBinY, Float_t nMinY, Float_t nMaxY, Int_t logAxis){ |
9bcfd1ab | 154 | |
50685501 | 155 | // |
156 | // Creates a TH2F histogram for the collection | |
157 | // | |
9bcfd1ab | 158 | |
159 | if(!fList){ | |
809a4336 | 160 | AliError("No TList pointer ! "); |
161 | return kFALSE; | |
162 | } | |
9bcfd1ab | 163 | fList->Add(new TH2F(name, title, nBinX, nMinX, nMaxX, nBinY, nMinY, nMaxY)); |
faee3b18 | 164 | if(logAxis >= 0){ |
165 | BinLogAxis(name, logAxis); | |
166 | } | |
75d81601 | 167 | return CheckObject(name); |
809a4336 | 168 | } |
169 | //___________________________________________________________________ | |
faee3b18 | 170 | Bool_t AliHFEcollection::CreateTH1Fvector1(Int_t X, const char* name, const char* title, Int_t nBin, Float_t nMin, Float_t nMax, Int_t logAxis){ |
9bcfd1ab | 171 | |
50685501 | 172 | // |
75d81601 | 173 | // create a 1 dimensional array of size [X] |
50685501 | 174 | // |
9bcfd1ab | 175 | |
176 | if(!fList){ | |
809a4336 | 177 | AliError("No TList pointer ! "); |
178 | return kFALSE; | |
179 | } | |
75d81601 | 180 | if(X <=0){ |
809a4336 | 181 | AliError("can not create array with negative or zero size "); |
182 | return kFALSE; | |
183 | } | |
75d81601 | 184 | TString hname; |
185 | for(Int_t i=0; i<X; ++i){ | |
186 | hname = ""; | |
187 | hname.Append(Form("%s_[%d]", name, i)); | |
809a4336 | 188 | //cout<<" -D: name: "<<name.str().c_str()<<endl; |
189 | //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl; | |
faee3b18 | 190 | CreateTH1F(hname.Data(), title, nBin, nMin, nMax, logAxis); |
75d81601 | 191 | if(!CheckObject(hname.Data())){ |
c1bd5735 | 192 | AliError(Form("Not possible to create object: %s", hname.Data())); |
809a4336 | 193 | return kFALSE; |
194 | } | |
195 | } | |
196 | return kTRUE; | |
197 | } | |
198 | //___________________________________________________________________ | |
faee3b18 | 199 | Bool_t AliHFEcollection::CreateTH2Fvector1(Int_t X, const char* name, const char* title, Int_t nBinX, Float_t nMinX, Float_t nMaxX, Int_t nBinY, Float_t nMinY, Float_t nMaxY, Int_t logAxis){ |
9bcfd1ab | 200 | |
50685501 | 201 | // |
75d81601 | 202 | // create a 1 dimensinal array of TH2F histograms with size [X] |
50685501 | 203 | // |
9bcfd1ab | 204 | |
205 | if(!fList){ | |
809a4336 | 206 | AliError("No TList pointer !"); |
207 | return kFALSE; | |
208 | } | |
75d81601 | 209 | if(X <=0){ |
809a4336 | 210 | AliError("can not create array with negative or zero size "); |
211 | return kFALSE; | |
212 | } | |
75d81601 | 213 | TString hname; |
214 | for(Int_t i=0; i<X; ++i){ | |
215 | hname = ""; | |
216 | hname.Append(Form("%s_[%d]", name, i)); | |
809a4336 | 217 | //cout<<" -D: name: "<<name<<endl; |
218 | //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl; | |
faee3b18 | 219 | CreateTH2F(hname.Data(), title, nBinX, nMinX, nMaxX, nBinY, nMinY, nMaxY, logAxis); |
75d81601 | 220 | if(!CheckObject(hname.Data())){ |
221 | AliError(Form("Not possible to create object: %s", hname.Data())); | |
809a4336 | 222 | return kFALSE; |
223 | } | |
224 | } | |
225 | return kTRUE; | |
226 | } | |
227 | //___________________________________________________________________ | |
faee3b18 | 228 | Bool_t AliHFEcollection::CreateTH1Fvector2(Int_t X, Int_t Y, const char* name, const char* title, Int_t nBin, Float_t nMin, Float_t nMax, Int_t logAxis){ |
9bcfd1ab | 229 | |
50685501 | 230 | // |
75d81601 | 231 | // create a 2 dimensional array of histograms of size [X, Y] |
50685501 | 232 | // |
9bcfd1ab | 233 | |
234 | if(!fList){ | |
809a4336 | 235 | AliError("No TList pointer ! "); |
236 | return kFALSE; | |
237 | } | |
75d81601 | 238 | if(X <=0 || Y <=0){ |
809a4336 | 239 | AliError("can not create array with negative or zero size "); |
240 | return kFALSE; | |
241 | } | |
75d81601 | 242 | TString hname; |
243 | for(Int_t i=0; i<X; ++i){ | |
244 | for(Int_t j=0; j<Y; ++j){ | |
245 | hname = ""; | |
246 | hname.Append(Form("%s_[%d][%d]", name, i, j)); | |
809a4336 | 247 | //cout<<" -D: name: "<<name.str().c_str()<<endl; |
248 | //cout<<" -D: nBin: "<<_nBin<<" ,Min: "<<_nMin<<" , Max: "<<_nMax<<endl; | |
faee3b18 | 249 | CreateTH1F(hname.Data(), title, nBin, nMin, nMax, logAxis); |
75d81601 | 250 | if(!CheckObject(hname.Data())){ |
251 | AliError(Form("Not possible to create object: %s", hname.Data())); | |
809a4336 | 252 | return kFALSE; |
253 | } | |
254 | } | |
255 | } | |
9bcfd1ab | 256 | return kTRUE; |
257 | } | |
258 | //___________________________________________________________________ | |
8c1c76e9 | 259 | Bool_t AliHFEcollection::CreateTH3F(const char* name, const char* title, Int_t nBinX, Float_t nMinX, Float_t nMaxX, Int_t nBinY, Float_t nMinY, Float_t nMaxY, Int_t nBinZ, Float_t nMinZ, Float_t nMaxZ, Int_t logAxis){ |
260 | ||
261 | // | |
262 | // Creates a TH2F histogram for the collection | |
263 | // | |
264 | ||
265 | if(!fList){ | |
266 | AliError("No TList pointer ! "); | |
267 | return kFALSE; | |
268 | } | |
269 | fList->Add(new TH3F(name, title, nBinX, nMinX, nMaxX, nBinY, nMinY, nMaxY, nBinZ, nMinZ, nMaxZ)); | |
270 | if(logAxis >= 0){ | |
271 | BinLogAxis(name, logAxis); | |
272 | } | |
273 | return CheckObject(name); | |
274 | } | |
275 | //___________________________________________________________________ | |
9bcfd1ab | 276 | Bool_t AliHFEcollection::CreateProfile(const char* name, const char* title, Int_t nbins, Double_t xmin, Double_t xmax){ |
277 | ||
278 | // | |
279 | // create a simple TProfile | |
280 | // | |
281 | ||
282 | if(!fList){ | |
283 | AliError("No TList pointer ! "); | |
284 | return kFALSE; | |
285 | } | |
286 | fList->Add(new TProfile(name, title, nbins, xmin, xmax)); | |
287 | return CheckObject(name); | |
288 | ||
289 | } | |
290 | //___________________________________________________________________ | |
8c1c76e9 | 291 | Bool_t AliHFEcollection::CreateTHnSparse(const char* name, const char* title, Int_t dim, const Int_t* nbins, const Double_t* xmin, const Double_t* xmax){ |
9bcfd1ab | 292 | |
293 | // | |
294 | // create 'dim' dimensional THnSparse | |
295 | // | |
296 | ||
297 | if(!fList){ | |
298 | AliError("No TList pointer ! "); | |
299 | return kFALSE; | |
300 | } | |
301 | fList->Add(new THnSparseF(name, title, dim, nbins, xmin, xmax)); | |
302 | return CheckObject(name); | |
303 | ||
304 | } | |
305 | //___________________________________________________________________ | |
306 | TObject* AliHFEcollection::Get(const char* name){ | |
307 | ||
308 | // | |
309 | // Get histogram with the required name | |
310 | // | |
809a4336 | 311 | |
9bcfd1ab | 312 | |
313 | if(!CheckObject(name)){ | |
70da6c5a | 314 | AliWarning(Form("Not possible to return pointer to the object '%s'\n", name)); |
9bcfd1ab | 315 | return 0; |
316 | } | |
317 | ||
318 | return fList->FindObject(name); | |
809a4336 | 319 | |
320 | } | |
321 | //___________________________________________________________________ | |
9bcfd1ab | 322 | Bool_t AliHFEcollection::Fill(const char* name, Double_t v){ |
323 | ||
50685501 | 324 | // |
9bcfd1ab | 325 | // fill function for one TH1 histograms |
50685501 | 326 | // |
9bcfd1ab | 327 | |
faee3b18 | 328 | if(!CheckObject(name)){ |
329 | AliError(Form("Not possible to fill the object '%s', the object does not exist\n", name)); | |
9bcfd1ab | 330 | return kFALSE; |
809a4336 | 331 | } |
9bcfd1ab | 332 | |
69ac0e6f | 333 | TH1 *htmp = dynamic_cast<TH1F*>(fList->FindObject(name)); |
9bcfd1ab | 334 | // chack the possible object types |
69ac0e6f | 335 | if(htmp){ |
336 | htmp->Fill(v); | |
9bcfd1ab | 337 | return kTRUE; |
338 | } | |
339 | ||
340 | return kFALSE; | |
341 | ||
342 | } | |
343 | //___________________________________________________________________ | |
faee3b18 | 344 | Bool_t AliHFEcollection::Fill(const char* name, Int_t v){ |
345 | ||
346 | // | |
347 | // fill function for one TH1 histograms for integer numbers | |
348 | // | |
349 | ||
350 | return Fill(name, v*1.0); | |
351 | } | |
352 | //___________________________________________________________________ | |
9bcfd1ab | 353 | Bool_t AliHFEcollection::Fill(const char* name, Int_t X, Double_t v){ |
354 | ||
355 | // | |
356 | // fill function for one dimension arrays of TH1 | |
357 | // | |
358 | ||
359 | const char* n = Form("%s_[%d]", name, X); | |
360 | TObject *o = Get(n); | |
361 | if(!o){ | |
362 | return kFALSE; | |
809a4336 | 363 | } |
9bcfd1ab | 364 | Fill(o->GetName(), v); |
365 | return kTRUE; | |
809a4336 | 366 | } |
367 | //___________________________________________________________________ | |
9bcfd1ab | 368 | Bool_t AliHFEcollection::Fill(const char* name, Int_t X, Int_t Y, Double_t v){ |
70da6c5a | 369 | |
370 | // | |
371 | // Fill function fir 2 dimensional TH1 arrays | |
372 | // | |
9bcfd1ab | 373 | |
374 | const char* n = Form("%s_[%d][%d]", name, X, Y); | |
375 | TObject *o = Get(n); | |
376 | if(!o){ | |
377 | return kFALSE; | |
378 | } | |
379 | Fill(o->GetName(), v); | |
380 | return kTRUE; | |
381 | } | |
382 | //___________________________________________________________________ | |
383 | Bool_t AliHFEcollection::Fill(const char* name, Int_t X, Double_t v1, Double_t v2){ | |
384 | ||
50685501 | 385 | // |
9bcfd1ab | 386 | // fill function for one dimension array of TH2 |
50685501 | 387 | // |
9bcfd1ab | 388 | |
389 | const char* n = Form("%s_[%d]", name, X); | |
390 | TObject *o = Get(n); | |
391 | if(!o){ | |
392 | return kFALSE; | |
809a4336 | 393 | } |
9bcfd1ab | 394 | Fill(o->GetName(), v1, v2); |
395 | ||
396 | return kTRUE; | |
397 | } | |
398 | //___________________________________________________________________ | |
399 | Bool_t AliHFEcollection::Fill(const char* name, Double_t v1, Double_t v2){ | |
400 | ||
401 | // | |
402 | // fill function for TH2 objects | |
403 | // | |
404 | ||
faee3b18 | 405 | if(!CheckObject(name)){ |
406 | AliError(Form("Not possible to fill the object '%s', the object does not exist\n", name)); | |
9bcfd1ab | 407 | return kFALSE; |
809a4336 | 408 | } |
9bcfd1ab | 409 | |
410 | // chack the possible object types | |
411 | if(fList->FindObject(name)->InheritsFrom("TH2")){ | |
69ac0e6f | 412 | TH2 *h2 = dynamic_cast<TH2F*>(fList->FindObject(name)); |
413 | if(h2) h2->Fill(v1, v2); | |
9bcfd1ab | 414 | return kTRUE; |
415 | } | |
416 | if(fList->FindObject(name)->InheritsFrom("TProfile")){ | |
bf892a6a | 417 | TProfile *pr = dynamic_cast<TProfile*>(fList->FindObject(name)); |
418 | if(pr) pr->Fill(v1, v2); | |
9bcfd1ab | 419 | return kTRUE; |
420 | } | |
421 | ||
422 | return kFALSE; | |
423 | ||
8c1c76e9 | 424 | } |
425 | //___________________________________________________________________ | |
426 | Bool_t AliHFEcollection::Fill(const char* name, Double_t v1, Double_t v2, Double_t v3){ | |
427 | ||
428 | // | |
429 | // fill function for TH3 objects | |
430 | // | |
431 | ||
432 | if(!CheckObject(name)){ | |
433 | AliError(Form("Not possible to fill the object '%s', the object does not exist\n", name)); | |
434 | return kFALSE; | |
435 | } | |
436 | ||
437 | // chack the possible object types | |
438 | TH3 *h3 = dynamic_cast<TH3F*>(fList->FindObject(name)); | |
439 | if(h3){ | |
440 | h3->Fill(v1, v2, v3); | |
441 | return kTRUE; | |
442 | } | |
443 | ||
444 | return kFALSE; | |
445 | ||
809a4336 | 446 | } |
faee3b18 | 447 | //___________________________________________________________________ |
448 | Bool_t AliHFEcollection::Fill(const char* name, Double_t* entry, Double_t weight){ | |
449 | // | |
450 | // Fill a THnSparse object | |
451 | // | |
452 | ||
453 | if(!CheckObject(name)){ | |
454 | AliError(Form("Not possible to fill the object '%s', the object does not exist\n", name)); | |
455 | return kFALSE; | |
456 | } | |
457 | ||
69ac0e6f | 458 | THnSparseF *htmp = dynamic_cast<THnSparseF*>(fList->FindObject(name)); |
459 | if(htmp){ | |
460 | htmp->Fill(entry, weight); | |
faee3b18 | 461 | return kTRUE; |
462 | } | |
463 | return kFALSE; | |
9bcfd1ab | 464 | |
faee3b18 | 465 | } |
809a4336 | 466 | //___________________________________________________________________ |
75d81601 | 467 | Bool_t AliHFEcollection::CheckObject(const char* name){ |
9bcfd1ab | 468 | |
50685501 | 469 | // |
809a4336 | 470 | // check wheter the creation of the histogram was succesfull |
50685501 | 471 | // |
809a4336 | 472 | |
9bcfd1ab | 473 | if(!fList){ |
809a4336 | 474 | AliError("No TList pointer ! "); |
475 | return kFALSE; | |
476 | } | |
477 | ||
9bcfd1ab | 478 | if(!fList->FindObject(name)){ |
70da6c5a | 479 | AliWarning(Form("Creating or Finding the object '%s' failed\n", name)); |
809a4336 | 480 | return kFALSE; |
481 | } | |
482 | return kTRUE; | |
483 | } | |
484 | //___________________________________________________________________ | |
70da6c5a | 485 | Bool_t AliHFEcollection::Sumw2(const char* name){ |
486 | // | |
487 | // Set Sumw2 for the given object | |
488 | // | |
489 | if(!CheckObject(name)){ | |
490 | return kFALSE; | |
491 | } | |
492 | ||
493 | TObject *o = Get(name); | |
69ac0e6f | 494 | THnSparse *htmp = dynamic_cast<THnSparse*>(o); |
495 | if(htmp){ | |
496 | htmp->Sumw2(); | |
70da6c5a | 497 | } |
498 | return kTRUE; | |
499 | } | |
500 | //___________________________________________________________________ | |
9bcfd1ab | 501 | Bool_t AliHFEcollection::BinLogAxis(const char* name, Int_t dim){ |
502 | ||
50685501 | 503 | // |
9bcfd1ab | 504 | // converts the axis (defined by the dimension) of THx or THnSparse |
505 | // object to Log scale. Number of bins and bin min and bin max are preserved | |
506 | // | |
507 | ||
508 | ||
509 | if(!CheckObject(name)){ | |
510 | return kFALSE; | |
511 | } | |
512 | ||
513 | TObject *o = Get(name); | |
69ac0e6f | 514 | TAxis *axis = NULL; |
8c1c76e9 | 515 | TString type(o->IsA()->GetName()); |
516 | if(type.Contains("TH1")){ // 1D histogram | |
69ac0e6f | 517 | TH1 *h1 = dynamic_cast<TH1F*>(o); |
518 | if(h1) axis = h1->GetXaxis(); | |
8c1c76e9 | 519 | } else if(type.Contains("TH2")){ |
69ac0e6f | 520 | TH2 *h2 = dynamic_cast<TH2F*>(o); |
521 | if(h2){ | |
522 | if(0 == dim){ | |
523 | axis = h2->GetXaxis(); | |
524 | } | |
525 | else if(1 == dim){ | |
526 | axis = h2->GetYaxis(); | |
527 | } | |
528 | else{ | |
529 | AliError("Only dim = 0 or 1 possible for TH2F"); | |
530 | } | |
9bcfd1ab | 531 | } |
8c1c76e9 | 532 | } else if(type.Contains("TH3")){ |
533 | TH3 *h3 = dynamic_cast<TH3F*>(o); | |
534 | if(h3){ | |
535 | if(0 == dim){ | |
536 | axis = h3->GetXaxis(); | |
537 | } | |
538 | else if(1 == dim){ | |
539 | axis = h3->GetYaxis(); | |
540 | } | |
541 | else if(2 == dim){ | |
542 | axis = h3->GetZaxis(); | |
543 | } | |
544 | else{ | |
545 | AliError("Only dim = 0, 1 or 2 possible for TH3F"); | |
546 | } | |
547 | } | |
548 | } else if(type.Contains("THnSparse")){ | |
69ac0e6f | 549 | THnSparse *hs = dynamic_cast<THnSparse*>(o); |
550 | if(hs) axis = hs->GetAxis(dim); | |
9bcfd1ab | 551 | } |
8c1c76e9 | 552 | |
9bcfd1ab | 553 | if(!axis){ |
554 | AliError(Form("Axis '%d' could not be identified in the object '%s'\n", dim, name)); | |
555 | return kFALSE; | |
556 | } | |
557 | ||
558 | Int_t bins = axis->GetNbins(); | |
559 | ||
560 | Double_t from = axis->GetXmin(); | |
faee3b18 | 561 | if(from <= 0){ |
562 | AliError(Form(" Log binning not possible for object '%s'because the '%d' axis starts from '%f\n'", name, dim, from)); | |
563 | return kFALSE; | |
564 | } | |
9bcfd1ab | 565 | Double_t to = axis->GetXmax(); |
566 | Double_t *newBins = new Double_t[bins+1]; | |
567 | newBins[0] = from; | |
568 | Double_t factor = TMath::Power(to/from, 1./bins); | |
569 | for(Int_t i=1; i<=bins; ++i){ | |
570 | newBins[i] = factor * newBins[i-1]; | |
571 | } | |
572 | axis->Set(bins, newBins); | |
69ac0e6f | 573 | delete[] newBins; |
9bcfd1ab | 574 | |
575 | return kTRUE; | |
576 | ||
577 | ||
809a4336 | 578 | } |
579 | //___________________________________________________________________ | |
8c1c76e9 | 580 | Long64_t AliHFEcollection::Merge(const TCollection *list){ |
9bcfd1ab | 581 | |
50685501 | 582 | // |
583 | // Merge the collections | |
584 | // | |
70da6c5a | 585 | if(!list) |
809a4336 | 586 | return 0; |
70da6c5a | 587 | if(list->IsEmpty()) |
588 | return 1; | |
809a4336 | 589 | |
bf892a6a | 590 | TIter it(list); |
70da6c5a | 591 | TObject *o = NULL; |
592 | Int_t index = 0; | |
bf892a6a | 593 | TList templist; // Create temporary list containing all the lists to merge |
594 | while((o = it())){ | |
70da6c5a | 595 | AliHFEcollection *coll = dynamic_cast<AliHFEcollection *>(o); |
596 | if(!coll) continue; | |
70da6c5a | 597 | templist.Add(coll->fList); |
70da6c5a | 598 | index++; |
599 | } | |
bf892a6a | 600 | fList->Merge(&templist); |
70da6c5a | 601 | return index + 1; |
809a4336 | 602 | } |
603 | //____________________________________________________________________ | |
604 | void AliHFEcollection::Browse(TBrowser *b) | |
605 | { | |
9bcfd1ab | 606 | |
50685501 | 607 | // |
608 | // Browse the content of the directory. | |
609 | // | |
809a4336 | 610 | |
611 | if (b) { | |
612 | TObject *obj = 0; | |
9bcfd1ab | 613 | TIter nextin(fList); |
809a4336 | 614 | |
615 | //Add objects that are only in memory | |
616 | while ((obj = nextin())) { | |
617 | b->Add(obj, obj->GetName()); | |
618 | } | |
619 | } | |
620 | } | |
e156c3bb | 621 | //____________________________________________________________________ |
622 | void AliHFEcollection::Print(Option_t *) const{ | |
623 | // | |
624 | // Print content of the collection | |
625 | // | |
626 | TIter histIter(fList); | |
627 | TObject *o = NULL; | |
628 | Int_t nHistos = 0; | |
629 | printf("Collection %s\n", GetName()); | |
630 | printf("Content of the collection:\n=========================================\n"); | |
631 | while((o = histIter())){ | |
632 | printf("Histo %s, Type %s\n", o->GetName(), o->IsA()->GetName()); | |
633 | nHistos++; | |
634 | } | |
635 | printf("Number of histos in the collection: %d\n", nHistos); | |
636 | printf("\n"); | |
637 | } | |
638 |