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