fixed error of Geant3 parameters initialisation
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALHistoUtilities.cxx
CommitLineData
315d1c64 1/**************************************************************************
2 * Copyright(c) 1998-2002, 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
9edefa04 16/* $Id$ */
315d1c64 17
d434833b 18//_________________________________________________________________________
14ce0a6e 19// This is a set of histogram
20// utilities for the EMCAL
21// to make some common
22// functions easier
d434833b 23//
315d1c64 24//*-- Authors: J.L. Klay (LLNL) & Aleksei Pavlinov (WSU)
25
d434833b 26#include "AliEMCALHistoUtilities.h"
315d1c64 27
315d1c64 28#include <TFile.h>
315d1c64 29#include <TH1.h>
30#include <TH2.h>
9edefa04 31#include <TList.h>
32#include <TObjArray.h>
d434833b 33#include <TObjString.h>
9edefa04 34#include <TROOT.h>
d434833b 35#include <TRegexp.h>
9edefa04 36#include <TString.h>
315d1c64 37
38ClassImp(AliEMCALHistoUtilities)
39
40AliEMCALHistoUtilities::AliEMCALHistoUtilities(const char *name, const char *tit) : TNamed(name,tit)
41{
d434833b 42 // constructor
315d1c64 43}
44
45AliEMCALHistoUtilities::~AliEMCALHistoUtilities()
46{
47 //destructor
48}
49
315d1c64 50TList* AliEMCALHistoUtilities::MoveHistsToList(const char* name, Bool_t putToBrowser)
51{
52 // Move HIST to list
53 gROOT->cd();
54 TIter nextHist(gDirectory->GetList());
55 TList *list = new TList;
56 list->SetName(name);
57 TObject *objHist;
58 while((objHist=nextHist())){
59 if (!objHist->InheritsFrom("TH1")) continue;
60 ((TH1*)objHist)->SetDirectory(0); // Remove from gROOT
61 list->Add(objHist);
62 }
63 if(putToBrowser) gROOT->GetListOfBrowsables()->Add((TObject*)list);
64 return list;
65}
66
67void AliEMCALHistoUtilities::FillH1(TList *l, Int_t ind, Double_t x, Double_t w)
68{
14ce0a6e 69 //fill 1d histogram
315d1c64 70 static TH1* hid=0;
71 if(l == 0) return;
72 if(ind < l->GetSize()){
73 hid = (TH1*)l->At(ind);
74 hid->Fill(x,w);
75 }
76}
77
78void AliEMCALHistoUtilities::FillH2(TList *l, Int_t ind, Double_t x, Double_t y, Double_t w)
79{
14ce0a6e 80 //fill 2d histogram
315d1c64 81 static TH2* hid=0;
82 if(l == 0) return;
83 if(ind < l->GetSize()){
84 hid = (TH2*)l->At(ind);
85 hid->Fill(x,y,w);
86 }
87}
88
4800667c 89int AliEMCALHistoUtilities::SaveListOfHists(TList *mylist,const char* name,Bool_t kSingleKey,const char* opt)
315d1c64 90{
14ce0a6e 91 //write histograms to file
315d1c64 92 printf(" Name of out file |%s|\n", name);
93 int save = 0;
4800667c 94 if(mylist && mylist->GetSize() && strlen(name)){
315d1c64 95 TString nf(name);
96 if(nf.Contains(".root") == kFALSE) nf += ".root";
97 TFile file(nf.Data(),opt);
4800667c 98 TIter nextHist(mylist);
315d1c64 99 TObject* objHist=0;
100 int nh=0;
101 if(kSingleKey) {
102 file.cd();
4800667c 103 mylist->Write(mylist->GetName(),TObject::kSingleKey);
104 mylist->ls();
315d1c64 105 save = 1;
106 } else {
107 while((objHist=nextHist())) { // loop over list
108 if(objHist->InheritsFrom("TH1")) {
109 TH1* hid = (TH1*)objHist;
110 file.cd();
111 hid->Write();
112 nh++;
113 printf("Save hist. %s \n",hid ->GetName());
114 }
115 }
116 printf("%i hists. save to file -> %s\n", nh,file.GetName());
117 if(nh>0) save = 1;
118 }
119 file.Close();
120 } else {
121 printf("AliEMCALHistoUtilities::SaveListOfHists : N O S A V I N G \n");
315d1c64 122 }
123 return save;
124}
d434833b 125
d434833b 126int AliEMCALHistoUtilities::ParseString(const TString &topt, TObjArray &Opt)
14ce0a6e 127{
128 // Moved from AliEMCALGeometry
129 // Feb 06, 2006
d434833b 130 Ssiz_t begin, index, end, end2;
131 begin = index = end = end2 = 0;
132 TRegexp separator("[^ ;,\\t\\s/]+");
133 while ( (begin < topt.Length()) && (index != kNPOS) ) {
134 // loop over given options
135 index = topt.Index(separator,&end,begin);
136 if (index >= 0 && end >= 1) {
137 TString substring(topt(index,end));
138 Opt.Add(new TObjString(substring.Data()));
139 }
140 begin += end+1;
141 }
142 return Opt.GetEntries();
143}