1 /**************************************************************************
2 * Copyright(c) 1998-2002, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
19 // This is a set of histogram
20 // utilities for the EMCAL
21 // to make some common
24 //*-- Authors: J.L. Klay (LLNL) & Aleksei Pavlinov (WSU)
26 #include "AliEMCALHistoUtilities.h"
32 #include <TObjArray.h>
33 #include <TObjString.h>
38 ClassImp(AliEMCALHistoUtilities)
40 AliEMCALHistoUtilities::AliEMCALHistoUtilities(const char *name, const char *tit) : TNamed(name,tit)
45 AliEMCALHistoUtilities::~AliEMCALHistoUtilities()
50 TList* AliEMCALHistoUtilities::MoveHistsToList(const char* name, Bool_t putToBrowser)
54 TIter nextHist(gDirectory->GetList());
55 TList *list = new TList;
58 while((objHist=nextHist())){
59 if (!objHist->InheritsFrom("TH1")) continue;
60 ((TH1*)objHist)->SetDirectory(0); // Remove from gROOT
63 if(putToBrowser) gROOT->GetListOfBrowsables()->Add((TObject*)list);
67 void AliEMCALHistoUtilities::FillH1(TList *l, Int_t ind, Double_t x, Double_t w)
72 if(ind < l->GetSize()){
73 hid = (TH1*)l->At(ind);
78 void AliEMCALHistoUtilities::FillH2(TList *l, Int_t ind, Double_t x, Double_t y, Double_t w)
83 if(ind < l->GetSize()){
84 hid = (TH2*)l->At(ind);
89 int AliEMCALHistoUtilities::SaveListOfHists(TList *mylist,const char* name,Bool_t kSingleKey,const char* opt)
91 //write histograms to file
92 printf(" Name of out file |%s|\n", name);
94 if(mylist && mylist->GetSize() && strlen(name)){
96 if(nf.Contains(".root") == kFALSE) nf += ".root";
97 TFile file(nf.Data(),opt);
98 TIter nextHist(mylist);
103 mylist->Write(mylist->GetName(),TObject::kSingleKey);
107 while((objHist=nextHist())) { // loop over list
108 if(objHist->InheritsFrom("TH1")) {
109 TH1* hid = (TH1*)objHist;
113 printf("Save hist. %s \n",hid ->GetName());
116 printf("%i hists. save to file -> %s\n", nh,file.GetName());
121 printf("AliEMCALHistoUtilities::SaveListOfHists : N O S A V I N G \n");
126 void AliEMCALHistoUtilities::AddToNameAndTitle(TH1 *h, const char *name, const char *title)
129 if(name && strlen(name)) h->SetName(Form("%s%s",h->GetName(),name));
130 if(title && strlen(title)) h->SetTitle(Form("%s%s",h->GetTitle(),title));
133 void AliEMCALHistoUtilities::AddToNameAndTitleToList(TList *l, const char *name, const char *title)
137 for(int i=0; i<l->GetSize(); i++) {
138 TObject *o = l->At(i);
139 if(o->InheritsFrom("TH1")) {
141 AddToNameAndTitle(h, name, title);
147 int AliEMCALHistoUtilities::ParseString(const TString &topt, TObjArray &Opt)
149 // Moved from AliEMCALGeometry
151 Ssiz_t begin, index, end, end2;
152 begin = index = end = end2 = 0;
153 TRegexp separator("[^ ;,\\t\\s/]+");
154 while ( (begin < topt.Length()) && (index != kNPOS) ) {
155 // loop over given options
156 index = topt.Index(separator,&end,begin);
157 if (index >= 0 && end >= 1) {
158 TString substring(topt(index,end));
159 Opt.Add(new TObjString(substring.Data()));
163 return Opt.GetEntries();