AliPhysics  v5-07-15-01 (b3d7633)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
AliEMCalHistoContainer.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2014, 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 #include <cstring>
16 #include <vector>
17 #include <TArrayD.h>
18 #include <TAxis.h>
19 #include <TH1.h>
20 #include <TH2.h>
21 #include <TH3.h>
22 #include <THnSparse.h>
23 #include <THashList.h>
24 #include <TObjArray.h>
25 #include <TObjString.h>
26 #include <TProfile.h>
27 #include "AliEMCalHistoContainer.h"
28 #include <TString.h>
29 
30 #include "AliLog.h"
31 
35 
36 namespace EMCalTriggerPtAnalysis {
37 
41 AliEMCalHistoContainer::AliEMCalHistoContainer():
42  TNamed(),
43  fHistos(NULL),
44  fIsOwner(true)
45 {
46 }
47 
54  TNamed(name, Form("Histogram container %s", name)),
55  fHistos(NULL),
56  fIsOwner(true)
57 {
58  fHistos = new THashList();
59  fHistos->SetName(Form("histos%s", name));
60  fHistos->SetOwner();
61 }
62 
67  if(fHistos && fIsOwner) delete fHistos;
68 }
69 
78 void AliEMCalHistoContainer::CreateHistoGroup(const char *groupname, const char *parent) throw(HistoContainerContentException) {
79  THashList *parentgroup = FindGroup(parent);
81  THashList *childgroup = new THashList();
82  childgroup->SetName(groupname);
83  parentgroup->Add(childgroup);
84 }
85 
98 void AliEMCalHistoContainer::CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt) throw(HistoContainerContentException){
99  TString dirname(basename(name)), hname(histname(name));
100  THashList *parent(FindGroup(dirname.Data()));
101  if(!parent)
103  if(parent->FindObject(hname.Data()))
105  TH1 *hist = new TH1D(hname.Data(), title, nbins, xmin, xmax);
106  TString optionstring(opt);
107  optionstring.ToLower();
108  if(optionstring.Contains("s"))
109  hist->Sumw2();
110  parent->Add(hist);
111 }
112 
124 void AliEMCalHistoContainer::CreateTH1(const char *name, const char *title, int nbins, const double *xbins, Option_t *opt) throw(HistoContainerContentException){
125  TString dirname(basename(name)), hname(histname(name));
126  THashList *parent(FindGroup(dirname));
127  if(!parent)
129  if(parent->FindObject(hname.Data()))
131  TH1 *hist = new TH1D(hname.Data(), title, nbins, xbins);
132  TString optionstring(opt);
133  optionstring.ToLower();
134  if(optionstring.Contains("s"))
135  hist->Sumw2();
136  parent->Add(hist);
137 }
138 
149 void AliEMCalHistoContainer::CreateTH1(const char *name, const char *title, const TArrayD &xbins, Option_t *opt) throw(HistoContainerContentException){
150  TString dirname(basename(name)), hname(histname(name));
151  THashList *parent(FindGroup(dirname));
152  if(!parent)
154  if(parent->FindObject(hname.Data()))
156  TH1 *hist = new TH1D(hname.Data(), title, xbins.GetSize()-1, xbins.GetArray());
157  TString optionstring(opt);
158  optionstring.ToLower();
159  if(optionstring.Contains("s"))
160  hist->Sumw2();
161  parent->Add(hist);
162 }
163 
176 void AliEMCalHistoContainer::CreateTProfile(const char* name, const char* title, int nbinsX, double xmin, double xmax, Option_t *opt) throw (HistoContainerContentException) {
177  TString dirname(basename(name)), hname(histname(name));
178  THashList *parent(FindGroup(dirname));
179  if(!parent)
181  if(parent->FindObject(hname.Data()))
183  TProfile *hist = new TProfile(hname.Data(), title, nbinsX, xmin, xmax, opt);
184  TString optionstring(opt);
185  parent->Add(hist);
186 }
187 
199 void EMCalTriggerPtAnalysis::AliEMCalHistoContainer::CreateTProfile(const char* name, const char* title, int nbinsX, const double* xbins, Option_t *opt)
201  TString dirname(basename(name)), hname(histname(name));
202  THashList *parent(FindGroup(dirname));
203  if(!parent)
205  if(parent->FindObject(hname.Data()))
207  TProfile *hist = new TProfile(hname.Data(), title, nbinsX, xbins, opt);
208  TString optionstring(opt);
209  parent->Add(hist);
210 }
211 
223 void EMCalTriggerPtAnalysis::AliEMCalHistoContainer::CreateTProfile(const char* name, const char* title, const TArrayD& xbins, Option_t *opt)
225  TString dirname(basename(name)), hname(histname(name));
226  THashList *parent(FindGroup(dirname));
227  if(!parent)
229  if(parent->FindObject(hname.Data()))
231  TProfile *hist = new TProfile(hname.Data(), title, xbins.GetSize()-1, xbins.GetArray(), opt);
232  parent->Add(hist);
233 }
234 
249 void AliEMCalHistoContainer::CreateTH2(const char *name, const char *title,
250  int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt) throw(HistoContainerContentException){
251  TString dirname(basename(name)), hname(histname(name));
252  THashList *parent(FindGroup(dirname.Data()));
253  if(!parent)
255  if(parent->FindObject(hname.Data()))
257  TH2 *hist = new TH2D(hname.Data(), title, nbinsx, xmin, xmax, nbinsy, ymin, ymax);
258  TString optionstring(opt);
259  optionstring.ToLower();
260  if(optionstring.Contains("s"))
261  hist->Sumw2();
262  parent->Add(hist);
263 }
264 
277 void AliEMCalHistoContainer::CreateTH2(const char *name, const char *title,
278  int nbinsx, const double *xbins, int nbinsy, const double *ybins, Option_t *opt) throw(HistoContainerContentException){
279  TString dirname(basename(name)), hname(histname(name));
280  THashList *parent(FindGroup(dirname.Data()));
281  if(!parent)
283  if(parent->FindObject(hname.Data()))
285  TH2 *hist = new TH2D(hname.Data(), title, nbinsx, xbins, nbinsy, ybins);
286  TString optionstring(opt);
287  optionstring.ToLower();
288  if(optionstring.Contains("s"))
289  hist->Sumw2();
290  parent->Add(hist);
291 }
292 
303 void AliEMCalHistoContainer::CreateTH2(const char *name, const char *title, const TArrayD &xbins, const TArrayD &ybins, Option_t *opt) throw(HistoContainerContentException){
304  TString dirname(basename(name)), hname(histname(name));
305  THashList *parent(FindGroup(dirname.Data()));
306  if(!parent)
308  if(parent->FindObject(hname.Data()))
310  TH2 *hist = new TH2D(hname.Data(), title, xbins.GetSize() - 1, xbins.GetArray(), ybins.GetSize() - 1, ybins.GetArray());
311  TString optionstring(opt);
312  optionstring.ToLower();
313  if(optionstring.Contains("s"))
314  hist->Sumw2();
315  parent->Add(hist);
316 }
317 
333 void AliEMCalHistoContainer::CreateTH3(const char* name, const char* title, int nbinsx, double xmin, double xmax,
334  int nbinsy, double ymin, double ymax, int nbinsz, double zmin, double zmax, Option_t *opt) throw (HistoContainerContentException) {
335  TString dirname(basename(name)), hname(histname(name));
336  THashList *parent(FindGroup(dirname.Data()));
337  if(!parent)
339  if(parent->FindObject(hname.Data()))
341  TH3 *hist = new TH3D(hname.Data(), title, nbinsx, xmin, xmax, nbinsy, ymin, ymax, nbinsz, zmin, zmax);
342  TString optionstring(opt);
343  optionstring.ToLower();
344  if(optionstring.Contains("s"))
345  hist->Sumw2();
346  parent->Add(hist);
347 }
348 
363 void AliEMCalHistoContainer::CreateTH3(const char* name, const char* title, int nbinsx, const double* xbins,
364  int nbinsy, const double* ybins, int nbinsz, const double* zbins, Option_t *opt) throw (HistoContainerContentException) {
365  TString dirname(basename(name)), hname(histname(name));
366  THashList *parent(FindGroup(dirname.Data()));
367  if(!parent)
369  if(parent->FindObject(hname.Data()))
371  TH3 *hist = new TH3D(hname.Data(), title, nbinsx, xbins, nbinsy, ybins, nbinsz, zbins);
372  TString optionstring(opt);
373  optionstring.ToLower();
374  if(optionstring.Contains("s"))
375  hist->Sumw2();
376  parent->Add(hist);
377 }
378 
390 void AliEMCalHistoContainer::CreateTH3(const char* name, const char* title, const TArrayD& xbins, const TArrayD& ybins,
391  const TArrayD& zbins, Option_t *opt) throw (HistoContainerContentException) {
392  TString dirname(basename(name)), hname(histname(name));
393  THashList *parent(FindGroup(dirname.Data()));
394  if(!parent)
396  if(parent->FindObject(hname.Data()))
398  TH3 *hist = new TH3D(hname.Data(), title, xbins.GetSize()-1, xbins.GetArray(), ybins.GetSize()-1, ybins.GetArray(), zbins.GetSize()-1, zbins.GetArray());
399  TString optionstring(opt);
400  optionstring.ToLower();
401  if(optionstring.Contains("s"))
402  hist->Sumw2();
403  parent->Add(hist);
404 }
405 
418 void AliEMCalHistoContainer::CreateTHnSparse(const char *name, const char *title,
419  int ndim, const int *nbins, const double *min, const double *max, Option_t *opt) throw(HistoContainerContentException){
420  TString dirname(basename(name)), hname(histname(name));
421  THashList *parent(FindGroup(dirname.Data()));
422  if(!parent)
424  if(parent->FindObject(hname.Data()))
426  THnSparseD *hist = new THnSparseD(hname.Data(), title, ndim, nbins, min, max);
427  TString optionstring(opt);
428  optionstring.ToLower();
429  if(optionstring.Contains("s"))
430  hist->Sumw2();
431  parent->Add(hist);
432 }
433 
444 void AliEMCalHistoContainer::CreateTHnSparse(const char *name, const char *title, int ndim, const TAxis **axes, Option_t *opt) throw(HistoContainerContentException){
445  TString dirname(basename(name)), hname(histname(name));
446  THashList *parent(FindGroup(dirname.Data()));
447  if(!parent)
449  if(parent->FindObject(hname))
451  TArrayD xmin(ndim), xmax(ndim);
452  TArrayI nbins(ndim);
453  for(int idim = 0; idim < ndim; ++idim){
454  const TAxis &myaxis = *(axes[idim]);
455  nbins[idim] = myaxis.GetNbins();
456  xmin[idim] = myaxis.GetXmin();
457  xmax[idim] = myaxis.GetXmax();
458  }
459  THnSparseD *hsparse = new THnSparseD(hname.Data(), title, ndim, nbins.GetArray(), xmin.GetArray(), xmax.GetArray());
460  for(int id = 0; id < ndim; ++id)
461  *(hsparse->GetAxis(id)) = *(axes[id]);
462  TString optionstring(opt);
463  optionstring.ToLower();
464  if(optionstring.Contains("s"))
465  hsparse->Sumw2();
466  parent->Add(hsparse);
467 }
468 
474 void AliEMCalHistoContainer::SetObject(TObject * const o, const char *group) throw(HistoContainerContentException){
475  THashList *parent(FindGroup(group));
476  if(!parent)
477  throw HistoContainerContentException(NULL, strcmp(group, "/") ? group : "", HistoContainerContentException::kGroupException);
478  if(parent->FindObject(o->GetName()))
479  throw HistoContainerContentException(o->GetName(), strcmp(group, "/") ? group : "", HistoContainerContentException::kHistDuplicationException);
480  if(!(dynamic_cast<THnBase *>(o) || dynamic_cast<TH1 *>(o)))
481  throw HistoContainerContentException(o->GetName(), strcmp(group, "/") ? group : "", HistoContainerContentException::kTypeException);
482  fHistos->Add(o);
483 }
484 
494 void AliEMCalHistoContainer::FillTH1(const char *name, double x, double weight) throw(HistoContainerContentException){
495  TString dirname(basename(name)), hname(histname(name));
496  THashList *parent(FindGroup(dirname.Data()));
497  if(!parent)
499  TH1 *hist = dynamic_cast<TH1 *>(parent->FindObject(hname.Data()));
500  if(!hist)
502  hist->Fill(x, weight);
503 }
504 
515 void AliEMCalHistoContainer::FillProfile(const char* name, double x, double y, double weight) throw(HistoContainerContentException){
516  TString dirname(basename(name)), hname(histname(name));
517  THashList *parent(FindGroup(dirname.Data()));
518  if(!parent)
520  TProfile *hist = dynamic_cast<TProfile *>(parent->FindObject(hname.Data()));
521  if(!hist)
523  hist->Fill(x, y, weight);
524 }
525 
536 void AliEMCalHistoContainer::FillTH2(const char *name, double x, double y, double weight) throw(HistoContainerContentException){
537  TString dirname(basename(name)), hname(histname(name));
538  THashList *parent(FindGroup(dirname.Data()));
539  if(!parent)
541  TH2 *hist = dynamic_cast<TH2 *>(parent->FindObject(hname.Data()));
542  if(!hist)
544  hist->Fill(x, y, weight);
545 }
546 
556 void AliEMCalHistoContainer::FillTH2(const char *name, double *point, double weight) throw(HistoContainerContentException){
557  TString dirname(basename(name)), hname(histname(name));
558  THashList *parent(FindGroup(dirname.Data()));
559  if(!parent)
561  TH2 *hist = dynamic_cast<TH2 *>(parent->FindObject(hname.Data()));
562  if(!hist)
564  hist->Fill(point[0], point[1], weight);
565 }
566 
578 void AliEMCalHistoContainer::FillTH3(const char* name, double x, double y, double z, double weight) throw (HistoContainerContentException) {
579  TString dirname(basename(name)), hname(histname(name));
580  THashList *parent(FindGroup(dirname.Data()));
581  if(!parent)
583  TH3 *hist = dynamic_cast<TH3 *>(parent->FindObject(hname.Data()));
584  if(!hist)
586  hist->Fill(x, y, z, weight);
587 }
597 void AliEMCalHistoContainer::FillTH3(const char* name, const double* point, double weight) throw (HistoContainerContentException) {
598  TString dirname(basename(name)), hname(histname(name));
599  THashList *parent(FindGroup(dirname.Data()));
600  if(!parent)
602  TH3 *hist = dynamic_cast<TH3 *>(parent->FindObject(hname.Data()));
603  if(!hist)
605  hist->Fill(point[0], point[1], point[2], weight);
606 }
607 
617 void AliEMCalHistoContainer::FillTHnSparse(const char *name, const double *x, double weight) throw(HistoContainerContentException){
618  TString dirname(basename(name)), hname(histname(name));
619  THashList *parent(FindGroup(dirname.Data()));
620  if(!parent)
622  THnSparseD *hist = dynamic_cast<THnSparseD *>(parent->FindObject(hname.Data()));
623  if(!hist)
625  hist->Fill(x, weight);
626 }
627 
635 TObject *AliEMCalHistoContainer::FindObject(const char *name) const {
636  TString dirname(basename(name)), hname(histname(name));
637  THashList *parent(FindGroup(dirname.Data()));
638  if(!parent) return NULL;
639  return parent->FindObject(hname);
640 }
641 
649 TObject* AliEMCalHistoContainer::FindObject(const TObject* obj) const {
650  TString dirname(basename(obj->GetName())), hname(histname(obj->GetName()));
651  THashList *parent(FindGroup(dirname.Data()));
652  if(!parent) return NULL;
653  return parent->FindObject(hname);
654 }
655 
662 THashList *AliEMCalHistoContainer::FindGroup(const char *dirname) const {
663  if(!strlen(dirname) || !strcmp(dirname, "/")) return fHistos;
664  std::vector<std::string> tokens;
665  TokenizeFilename(dirname, "/", tokens);
666  THashList *currentdir(fHistos);
667  for(std::vector<std::string>::iterator it = tokens.begin(); it != tokens.end(); ++it){
668  currentdir = dynamic_cast<THashList *>(currentdir->FindObject(it->c_str()));
669  if(!currentdir) break;
670  }
671  return currentdir;
672 }
673 
681 void AliEMCalHistoContainer::TokenizeFilename(const char *name, const char *delim, std::vector<std::string> &listoftokens) const {
682  TString s(name);
683  TObjArray *arr = s.Tokenize(delim);
684  TObjString *ostr(NULL);
685  TIter toks(arr);
686  while((ostr = dynamic_cast<TObjString *>(toks()))){
687  listoftokens.push_back(std::string(ostr->String().Data()));
688  }
689  delete arr;
690 }
691 
698 const char *AliEMCalHistoContainer::basename(const char *path) const {
699  TString s(path);
700  int index = s.Last('/');
701  if(index < 0) return ""; // no directory structure
702  return TString(s(0, index)).Data();
703 }
704 
711 const char *AliEMCalHistoContainer::histname(const char *path) const {
712  TString s(path);
713  int index = s.Last('/');
714  if(index < 0) return path; // no directory structure
715  return TString(s(index+1, s.Length() - (index+1))).Data();
716 }
717 
718 }
719 
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
const Double_t ymax
Definition: AddTaskCFDStar.C:7
void FillTH2(const char *hname, double x, double y, double weight=1.)
const char * title
Definition: MakeQAPdf.C:26
Int_t nbinsy
void CreateTH3(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, int nbinsz, double zmin, double zmax, Option_t *opt="")
void SetObject(TObject *const o, const char *group="/")
void CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Container class for histograms for the high- charged particle analysis.
void FillTHnSparse(const char *name, const double *x, double weight=1.)
void FillTH3(const char *hname, double x, double y, double z, double weight=1.)
Exception thrown by the histogram container in case of problems.
virtual TObject * FindObject(const char *name) const
void CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt="")
Declarartion of class AliEMCalHistoContainer.
const Double_t zmin
void CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt="")
const char * basename(const char *path) const
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
void CreateTProfile(const char *name, const char *title, int nbinsX, double xmin, double xmax, Option_t *opt="")
Int_t nbinsx
void TokenizeFilename(const char *name, const char *delim, std::vector< std::string > &listoftokens) const
const char * histname(const char *path) const
const Double_t ymin
Definition: AddTaskCFDStar.C:6
THashList * FindGroup(const char *dirname) const
void FillTH1(const char *hname, double x, double weight=1.)
const Double_t zmax
void CreateHistoGroup(const char *groupname, const char *parent="/")
const Int_t nbins
void FillProfile(const char *name, double x, double y, double weight=1.)