]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGJE/EMCALJetTasks/UserTasks/AliEMCalHistoContainer.cxx
- Set Sumw2 for all histos in the histo container
[u/mrichter/AliRoot.git] / PWGJE / EMCALJetTasks / UserTasks / AliEMCalHistoContainer.cxx
CommitLineData
46f589c2 1/**************************************************************************
2 * Copyright(c) 1998-2007, 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 * Container class for histogram objects. Currenly can handle
18 * TH1
19 * TH2
20 * TH3
21 * THnSparse
22 * Histograms can be stored in groups. For this the parent group is
23 * included inside the histogram name, i.e. /base/inheriting/histogram.
24 * In case just the histogram name is given, it is assumed that the
25 * histogram is stored at the top level.
26 *
27 * Author: Markus Fasel
28 */
29
30#include <cstring>
31#include <vector>
32#include <TArrayD.h>
33#include <TAxis.h>
34#include <TH1.h>
35#include <TH2.h>
36#include <TH3.h>
37#include <THnSparse.h>
38#include <THashList.h>
39#include <TObjArray.h>
40#include <TObjString.h>
41#include <TString.h>
42
43#include "AliLog.h"
44
45#include "AliEMCalHistoContainer.h"
46
47ClassImp(EMCalTriggerPtAnalysis::AliEMCalHistoContainer)
48
49namespace EMCalTriggerPtAnalysis {
50
9f248f6f 51 //______________________________________________________________________________
52 AliEMCalHistoContainer::AliEMCalHistoContainer():
53 TNamed(),
54 fHistos(NULL),
55 fIsOwner(true)
56 {
57 /*
58 * Default constructor, only initialising pointers with 0
59 */
60 }
61
62 //______________________________________________________________________________
63 AliEMCalHistoContainer::AliEMCalHistoContainer(const char *name):
64 TNamed(name, Form("Histogram container %s", name)),
65 fHistos(NULL),
66 fIsOwner(true)
67 {
68 /*
69 * Main constructor, creating also a list for the histograms
70 *
71 * @param name: Name of the object (list named accordingly)
72 */
73 fHistos = new THashList();
74 fHistos->SetName(Form("histos%s", name));
75 fHistos->SetOwner();
76 }
77
78 //______________________________________________________________________________
79 AliEMCalHistoContainer::~AliEMCalHistoContainer(){
80 /*
81 * Destructor, deletes the list of histograms if it is the owner
82 */
83 if(fHistos && fIsOwner) delete fHistos;
84 }
85
86 //______________________________________________________________________________
87 void AliEMCalHistoContainer::CreateHistoGroup(const char *groupname, const char *parent) throw(HistoContainerContentException) {
88 /*
89 * Create a new group of histograms within a parent group. Groups are represented as list. The default parent is
90 * always the top list. List name structure accouding to unix paths (i.e. top list /, hirarchies separated by /).
91 *
92 * @param groupname: Name of the new group
93 * @param parent (@default "/"): Name of the parent group
94 * @throw HistoContainerContentException
95 */
96 THashList *parentgroup = FindGroup(parent);
97 if(!parentgroup) throw HistoContainerContentException(NULL, parent, HistoContainerContentException::kGroupException);
98 THashList *childgroup = new THashList();
99 childgroup->SetName(groupname);
100 parentgroup->Add(childgroup);
101 }
102
103 //______________________________________________________________________________
104 void AliEMCalHistoContainer::CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax) throw(HistoContainerContentException){
105 /*
106 * Create a new TH1 within the container. The histogram name also contains the parent group(s) according to the common
107 * group notation.
108 *
109 * @param name: Name of the histogram
110 * @param title: Title of the histogram
111 * @param nbins: number of bins
112 * @param xmin: min. value of the range
113 * @param xmax: max. value of the range
114 * @throw HistoContainerContentException
115 */
116 TString dirname(basename(name)), hname(histname(name));
117 THashList *parent(FindGroup(dirname.Data()));
118 if(!parent)
119 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
120 if(parent->FindObject(hname.Data()))
121 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
122 TH1 *hist = new TH1D(hname.Data(), title, nbins, xmin, xmax);
123 hist->Sumw2();
124 parent->Add(hist);
125 }
126
127 //______________________________________________________________________________
128 void AliEMCalHistoContainer::CreateTH1(const char *name, const char *title, int nbins, const double *xbins) throw(HistoContainerContentException){
129 /*
130 * Create a new TH1 within the container. The histogram name also contains the parent group(s) according to the common
131 * group notation.
132 *
133 * @param name: Name of the histogram
134 * @param title: Title of the histogram
135 * @param nbins: number of bins
136 * @param xbins: array of bin limits
137 * @throw HistoContainerContentException
138 */
139 TString dirname(basename(name)), hname(histname(name));
140 THashList *parent(FindGroup(dirname));
141 if(!parent)
142 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
143 if(parent->FindObject(hname.Data()))
144 throw HistoContainerContentException(hname, dirname.Data(), HistoContainerContentException::kHistDuplicationException);
145 TH1 *hist = new TH1D(hname.Data(), title, nbins, xbins);
146 hist->Sumw2();
147 parent->Add(hist);
148 }
149
150 //______________________________________________________________________________
151 void AliEMCalHistoContainer::CreateTH1(const char *name, const char *title, const TArrayD &xbins) throw(HistoContainerContentException){
152 /*
153 * Create a new TH1 within the container. The histogram name also contains the parent group(s) according to the common
154 * group notation.
155 *
156 * @param name: Name of the histogram
157 * @param title: Title of the histogram
158 * @param xbins: array of bin limits (contains also number of bins)
159 * @throw HistoContainerContentException
160 */
161 TString dirname(basename(name)), hname(histname(name));
162 THashList *parent(FindGroup(dirname));
163 if(!parent)
164 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
165 if(parent->FindObject(hname.Data()))
166 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
167 TH1 *hist = new TH1D(hname.Data(), title, xbins.GetSize()-1, xbins.GetArray());
168 hist->Sumw2();
169 parent->Add(hist);
170 }
171
172 //______________________________________________________________________________
173 void AliEMCalHistoContainer::CreateTH2(const char *name, const char *title,
174 int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax) throw(HistoContainerContentException){
175 /*
176 * Create a new TH2 within the container. The histogram name also contains the parent group(s) according to the common
177 * group notation.
178 *
179 * @param name: Name of the histogram
180 * @param title: Title of the histogram
181 * @param nbinsx: number of bins in x-direction
182 * @param xmin: min. value of the range in x-direction
183 * @param xmax: max. value of the range in x-direction
184 * @param nbinsy: number of bins in y-direction
185 * @param ymin: min. value of the range in y-direction
186 * @param ymax: max. value of the range in y-direction
187 * @throw HistoContainerContentException
188 */
189 TString dirname(basename(name)), hname(histname(name));
190 THashList *parent(FindGroup(dirname.Data()));
191 if(!parent)
192 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
193 if(parent->FindObject(hname.Data()))
194 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
195 TH2 *hist = new TH2D(hname.Data(), title, nbinsx, xmin, xmax, nbinsy, ymin, ymax);
196 parent->Add(hist);
197 }
198
199 //______________________________________________________________________________
200 void AliEMCalHistoContainer::CreateTH2(const char *name, const char *title,
201 int nbinsx, const double *xbins, int nbinsy, const double *ybins) throw(HistoContainerContentException){
202 /*
203 * Create a new TH2 within the container. The histogram name also contains the parent group(s) according to the common
204 * group notation.
205 *
206 * @param name: Name of the histogram
207 * @param title: Title of the histogram
208 * @param nbinsx: number of bins in x-direction
209 * @param xbins: array of bin limits in x-direction
210 * @param nbinsy: number of bins in y-direction
211 * @param ybins: array of bin limits in y-direction
212 * @throw HistoContainerContentException
213 */
214 TString dirname(basename(name)), hname(histname(name));
215 THashList *parent(FindGroup(dirname.Data()));
216 if(!parent)
217 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
218 if(parent->FindObject(hname.Data()))
219 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
220 TH2 *hist = new TH2D(hname.Data(), title, nbinsx, xbins, nbinsy, ybins);
221 hist->Sumw2();
222 parent->Add(hist);
223 }
224
225 //______________________________________________________________________________
226 void AliEMCalHistoContainer::CreateTH2(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins) throw(HistoContainerContentException){
227 /*
228 * Create a new TH2 within the container. The histogram name also contains the parent group(s) according to the common
229 * group notation.
230 *
231 * @param name: Name of the histogram
232 * @param title: Title of the histogram
233 * @param xbins: array of bin limits in x-direction (contains also the number of bins)
234 * @param ybins: array of bin limits in y-direction (contains also the number of bins)
235 * @throw HistoContainerContentException
236 */
237 TString dirname(basename(name)), hname(histname(name));
238 THashList *parent(FindGroup(dirname.Data()));
239 if(!parent)
240 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
241 if(parent->FindObject(hname.Data()))
242 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
243 TH2 *hist = new TH2D(hname.Data(), title, xbins.GetSize() - 1, xbins.GetArray(), ybins.GetSize() - 1, ybins.GetArray());
244 hist->Sumw2();
245 parent->Add(hist);
246 }
247
248 //______________________________________________________________________________
249 void AliEMCalHistoContainer::CreateTH3(const char* name, const char* title, int nbinsx, double xmin, double xmax,
250 int nbinsy, double ymin, double ymax, int nbinsz, double zmin, double zmax) throw (HistoContainerContentException) {
251 /*
252 * Create a new TH3 within the container. The histogram name also contains the parent group(s) according to the common
253 * group notation.
254 *
255 * @param nbinsx: number of bins in x-direction
256 * @param xmin: min. value of the range in x-direction
257 * @param xmax: max. value of the range in x-direction
258 * @param nbinsy: number of bins in y-direction
259 * @param ymin: min. value of the range in y-direction
260 * @param ymax: max. value of the range in y-direction
261 * @param nbinsz: number of bins in z-direction
262 * @param zmin: min. value of the range in z-direction
263 * @param zmax: max. value of the range in z-direction
264 * @throw HistoContainerContentException
265 */
266 TString dirname(basename(name)), hname(histname(name));
267 THashList *parent(FindGroup(dirname.Data()));
268 if(!parent)
269 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
270 if(parent->FindObject(hname.Data()))
271 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
272 TH3 *hist = new TH3D(hname.Data(), title, nbinsx, xmin, xmax, nbinsy, ymin, ymax, nbinsz, zmin, zmax);
273 hist->Sumw2();
274 parent->Add(hist);
275 }
276
277 //______________________________________________________________________________
278 void AliEMCalHistoContainer::CreateTH3(const char* name, const char* title, int nbinsx, const double* xbins,
279 int nbinsy, const double* ybins, int nbinsz, const double* zbins) throw (HistoContainerContentException) {
280 /*
281 * Create a new TH3 within the container. The histogram name also contains the parent group(s) according to the common
282 * group notation.
283 *
284 * @param name: Name of the histogram
285 * @param title: Title of the histogram
286 * @param nbinsx: number of bins in x-direction
287 * @param xbins: array of bin limits in x-direction
288 * @param nbinsy: number of bins in y-direction
289 * @param ybins: array of bin limits in y-direction
290 * @param nbinsz: number of bins in z-direction
291 * @param zbins: array of bin limits in z-direction
292 * @throw HistoContainerContentException
293 */
294 TString dirname(basename(name)), hname(histname(name));
295 THashList *parent(FindGroup(dirname.Data()));
296 if(!parent)
297 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
298 if(parent->FindObject(hname.Data()))
299 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
300 TH3 *hist = new TH3D(hname.Data(), title, nbinsx, xbins, nbinsy, ybins, nbinsz, zbins);
301 hist->Sumw2();
302 parent->Add(hist);
303 }
304
305 //______________________________________________________________________________
306 void AliEMCalHistoContainer::CreateTH3(const char* name, const char* title, const TArrayD& xbins, const TArrayD& ybins,
307 const TArrayD& zbins) throw (HistoContainerContentException) {
308 /*
309 * Create a new TH3 within the container. The histogram name also contains the parent group(s) according to the common
310 * group notation.
311 *
312 * @param name: Name of the histogram
313 * @param title: Title of the histogram
314 * @param xbins: array of bin limits in x-direction (contains also the number of bins)
315 * @param ybins: array of bin limits in y-direction (contains also the number of bins)
316 * @param zbins: array of bin limits in z-direction (contains also the number of bins)
317 * @throw HistoContainerContentException
318 */
319 TString dirname(basename(name)), hname(histname(name));
320 THashList *parent(FindGroup(dirname.Data()));
321 if(!parent)
322 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
323 if(parent->FindObject(hname.Data()))
324 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
325 TH3 *hist = new TH3D(hname.Data(), title, xbins.GetSize()-1, xbins.GetArray(), ybins.GetSize()-1, ybins.GetArray(), zbins.GetSize()-1, zbins.GetArray());
326 hist->Sumw2();
327 parent->Add(hist);
328 }
329
330 //______________________________________________________________________________
331 void AliEMCalHistoContainer::CreateTHnSparse(const char *name, const char *title,
332 int ndim, const int *nbins, const double *min, const double *max) throw(HistoContainerContentException){
333 /*
334 * Create a new THnSparse within the container. The histogram name also contains the parent group(s) according to the common
335 * group notation.
336 *
337 * @param name: Name of the histogram
338 * @param title: Title of the histogram
339 * @param ndim: Number of dimensions
340 * @param nbins: Number of bins per dimension
341 * @param min: min. value of the range for each dimension
342 * @param max: max. value of the range for each dimension
343 * @throw HistoContainerContentException
344 */
345 TString dirname(basename(name)), hname(histname(name));
346 THashList *parent(FindGroup(dirname.Data()));
347 if(!parent)
348 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
349 if(parent->FindObject(hname.Data()))
350 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
351 THnSparseD *hist = new THnSparseD(hname.Data(), title, ndim, nbins, min, max);
352 hist->Sumw2();
353 parent->Add(hist);
354 }
355
356 //______________________________________________________________________________
357 void AliEMCalHistoContainer::CreateTHnSparse(const char *name, const char *title, int ndim, const TAxis **axes) throw(HistoContainerContentException){
358 /*
359 * Create a new THnSparse within the container. The histogram name also contains the parent group(s) according to the common
360 * group notation.
361 *
362 * @param name: Name of the histogram
363 * @param title: Title of the histogram
364 * @param ndim: Number of dimensions
365 * @param axes: Array of pointers to TAxis for containing the axis definition for each dimension
366 * @throw HistoContainerContentException
367 */
368 TString dirname(basename(name)), hname(histname(name));
369 THashList *parent(FindGroup(dirname.Data()));
370 if(!parent)
371 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
372 if(parent->FindObject(hname))
373 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistDuplicationException);
374 TArrayD xmin(ndim), xmax(ndim);
375 TArrayI nbins(ndim);
376 for(int idim = 0; idim < ndim; ++idim){
377 const TAxis &myaxis = *(axes[idim]);
378 nbins[idim] = myaxis.GetNbins();
379 xmin[idim] = myaxis.GetXmin();
380 xmax[idim] = myaxis.GetXmax();
381 }
382 THnSparseD *hsparse = new THnSparseD(hname.Data(), title, ndim, nbins.GetArray(), xmin.GetArray(), xmax.GetArray());
383 for(int id = 0; id < ndim; ++id)
384 *(hsparse->GetAxis(id)) = *(axes[id]);
385 hsparse->Sumw2();
386 parent->Add(hsparse);
387 }
388
389 //______________________________________________________________________________
390 void AliEMCalHistoContainer::SetObject(TObject * const o, const char *group) throw(HistoContainerContentException){
391 /*
392 * Set a new group into the container into the parent group
393 *
394 * @param o: the object ot be included
395
396 */
397 THashList *parent(FindGroup(group));
398 if(!parent)
399 throw HistoContainerContentException(NULL, strcmp(group, "/") ? group : "", HistoContainerContentException::kGroupException);
400 if(parent->FindObject(o->GetName()))
401 throw HistoContainerContentException(o->GetName(), strcmp(group, "/") ? group : "", HistoContainerContentException::kHistDuplicationException);
402 if(!(dynamic_cast<THnBase *>(o) || dynamic_cast<TH1 *>(o)))
403 throw HistoContainerContentException(o->GetName(), strcmp(group, "/") ? group : "", HistoContainerContentException::kTypeException);
404 fHistos->Add(o);
405 }
406
407 //______________________________________________________________________________
408 void AliEMCalHistoContainer::FillTH1(const char *name, double x, double weight) throw(HistoContainerContentException){
409 /*
410 * Fill a 1D histogram within the container. The histogram name also contains the parent group(s) according to the common
411 * group notation.
412 *
413 * @param name: Name of the histogram
414 * @param x: x-coordinate
415 * @param weight (@default 1): optional weight of the entry
416 * @throw HistoContainerContentException
417 */
418 TString dirname(basename(name)), hname(histname(name));
419 THashList *parent(FindGroup(dirname.Data()));
420 if(!parent)
421 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
422 TH1 *hist = dynamic_cast<TH1 *>(parent->FindObject(hname.Data()));
423 if(!hist)
424 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
425 hist->Fill(x, weight);
426 }
427
428 //______________________________________________________________________________
429 void AliEMCalHistoContainer::FillTH2(const char *name, double x, double y, double weight) throw(HistoContainerContentException){
430 /*
431 * Fill a 2D histogram within the container. The histogram name also contains the parent group(s) according to the common
432 * group notation.
433 *
434 * @param name: Name of the histogram
435 * @param x: x-coordinate
436 * @param y: y-coordinate
437 * @param weight (@default 1): optional weight of the entry
438 * @throw HistoContainerContentException
439 */
440 TString dirname(basename(name)), hname(histname(name));
441 THashList *parent(FindGroup(dirname.Data()));
442 if(!parent)
443 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
444 TH2 *hist = dynamic_cast<TH2 *>(parent->FindObject(hname.Data()));
445 if(!hist)
446 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
447 hist->Fill(x, y, weight);
448 }
449
450 //______________________________________________________________________________
451 void AliEMCalHistoContainer::FillTH2(const char *name, double *point, double weight) throw(HistoContainerContentException){
452 /*
453 * Fill a 2D histogram within the container. The histogram name also contains the parent group(s) according to the common
454 * group notation.
455 *
456 * @param name: Name of the histogram
457 * @param point: coordinates of the data
458 * @param weight (@default 1): optional weight of the entry
459 * @throw HistoContainerContentException
460 */
461 TString dirname(basename(name)), hname(histname(name));
462 THashList *parent(FindGroup(dirname.Data()));
463 if(!parent)
464 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
465 TH2 *hist = dynamic_cast<TH2 *>(parent->FindObject(hname.Data()));
466 if(!hist)
467 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
468 hist->Fill(point[0], point[1], weight);
469 }
470
471 //______________________________________________________________________________
472 void AliEMCalHistoContainer::FillTH3(const char* name, double x, double y, double z, double weight) throw (HistoContainerContentException) {
473 /*
474 * Fill a 3D histogram within the container. The histogram name also contains the parent group(s) according to the common
475 * group notation.
476 *
477 * @param name: Name of the histogram
478 * @param x: x-coordinate
479 * @param y: y-coordinate
480 * @param z: z-coordinate
481 * @param weight (@default 1): optional weight of the entry
482 * @throw HistoContainerContentException
483 */
484 TString dirname(basename(name)), hname(histname(name));
485 THashList *parent(FindGroup(dirname.Data()));
486 if(!parent)
487 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
488 TH3 *hist = dynamic_cast<TH3 *>(parent->FindObject(hname.Data()));
489 if(!hist)
490 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
491 hist->Fill(x, y, z, weight);
492 }
493
494 //______________________________________________________________________________
495 void AliEMCalHistoContainer::FillTH3(const char* name, const double* point, double weight) throw (HistoContainerContentException) {
496 TString dirname(basename(name)), hname(histname(name));
497 THashList *parent(FindGroup(dirname.Data()));
498 if(!parent)
499 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
500 TH3 *hist = dynamic_cast<TH3 *>(parent->FindObject(hname.Data()));
501 if(!hist)
502 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
503 hist->Fill(point[0], point[1], point[2], weight);
504 }
505
506
507 //______________________________________________________________________________
508 void AliEMCalHistoContainer::FillTHnSparse(const char *name, const double *x, double weight) throw(HistoContainerContentException){
509 /*
510 * Fill a nD histogram within the container. The histogram name also contains the parent group(s) according to the common
511 * group notation.
512 *
513 * @param name: Name of the histogram
514 * @param x: coordinates of the data
515 * @param weight (@default 1): optional weight of the entry
516 * @throw HistoContainerContentException
517 */
518 TString dirname(basename(name)), hname(histname(name));
519 THashList *parent(FindGroup(dirname.Data()));
520 if(!parent)
521 throw HistoContainerContentException(NULL, dirname.Data(), HistoContainerContentException::kGroupException);
522 THnSparseD *hist = dynamic_cast<THnSparseD *>(parent->FindObject(hname.Data()));
523 if(!hist)
524 throw HistoContainerContentException(hname.Data(), dirname.Data(), HistoContainerContentException::kHistNotFoundException);
525 hist->Fill(x, weight);
526 }
527
528 //______________________________________________________________________________
529 TObject *AliEMCalHistoContainer::FindObject(const char *name) const {
530 /*
531 * Find an object inside the container. The object can also be within a
532 * histogram group. For this the name has to follow the common notation
533 *
534 * @param name: Name of the object to find inside the container
535 * @return: pointer to the object (NULL if not found)
536 */
537 TString dirname(basename(name)), hname(histname(name));
538 THashList *parent(FindGroup(dirname.Data()));
539 if(!parent) return NULL;
540 return parent->FindObject(hname);
541 }
542
543 //______________________________________________________________________________
544 TObject* AliEMCalHistoContainer::FindObject(const TObject* obj) const {
545 /*
546 * Find and object inside the container. The object name is expected to contain the
547 * full path of the histogram object, including parent groups
548 *
549 * @param obj: the object to find
550 * @return: pointer to the object (NULL if not found)
551 */
552 TString dirname(basename(obj->GetName())), hname(histname(obj->GetName()));
553 THashList *parent(FindGroup(dirname.Data()));
554 if(!parent) return NULL;
555 return parent->FindObject(hname);
556 }
557
558 //______________________________________________________________________________
559 THashList *AliEMCalHistoContainer::FindGroup(const char *dirname) const {
560 /*
561 * Find histogram group. Name is using common notation
562 *
563 * @param dirname: Path of the group (treat empty path as top node
564 * @return: TList of objects (NULL if group does not exist)
565 */
566 if(!strlen(dirname) || !strcmp(dirname, "/")) return fHistos;
567 std::vector<std::string> tokens;
568 TokenizeFilename(dirname, "/", tokens);
569 THashList *currentdir(fHistos);
570 for(std::vector<std::string>::iterator it = tokens.begin(); it != tokens.end(); ++it){
571 currentdir = dynamic_cast<THashList *>(currentdir->FindObject(it->c_str()));
572 if(!currentdir) break;
573 }
574 return currentdir;
575 }
576
577 //______________________________________________________________________________
578 void AliEMCalHistoContainer::TokenizeFilename(const char *name, const char *delim, std::vector<std::string> &listoftokens) const {
579 /*
580 * Tokenizes a string. Results are stored inside the vector listoftokens
581 *
582 * @ param name: string to be tokenised
583 * @ param delim: delimiter string
584 * @ param listoftokens: list of tokens (C++ strings)
585 */
586 TString s(name);
587 TObjArray *arr = s.Tokenize(delim);
588 TObjString *ostr(NULL);
589 TIter toks(arr);
590 while((ostr = dynamic_cast<TObjString *>(toks()))){
591 listoftokens.push_back(std::string(ostr->String().Data()));
592 }
593 delete arr;
594 }
595
596 //______________________________________________________________________________
597 const char *AliEMCalHistoContainer::basename(const char *path) const {
598 /*
599 * Helper function extracting the basename from a given histogram path.
600 *
601 * @param path: histogram path
602 * @return: basename extracted
603 */
604 TString s(path);
605 int index = s.Last('/');
606 if(index < 0) return ""; // no directory structure
607 return TString(s(0, index)).Data();
608 }
609
610 //______________________________________________________________________________
611 const char *AliEMCalHistoContainer::histname(const char *path) const {
612 /*
613 * Helper function extracting the histogram name from a given histogram path.
614 *
615 * @param path: histogram path
616 * @return: basename extracted
617 */
618 TString s(path);
619 int index = s.Last('/');
620 if(index < 0) return path; // no directory structure
621 return TString(s(index+1, s.Length() - (index+1))).Data();
622 }
46f589c2 623}