GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CorrelatedSpace.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004-2006 by Olivier Stezowski & Christian Finck *
3  * stezow(AT)ipnl.in2p3.fr, cfinck(AT)ires.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #ifndef Gw_CorrelatedSpace
24 #include "CorrelatedSpace.h"
25 #endif
26 
27 #ifndef Gw_CSFilter
28 #include "CSFilter.h"
29 #endif
30 
31 #ifndef Gw_CSManager
32 #include "CSManager.h"
33 #endif
34 
35 #ifndef ROOT_TFolder
36 #include "TFolder.h"
37 #endif
38 
39 #ifndef ROOT_TH1D
40 #include "TH1D.h"
41 #endif
42 
43 #ifndef ROOT_TList
44 #include "TList.h"
45 #endif
46 
47 #ifndef ROOT_TROOT
48 #include "TROOT.h"
49 #endif
50 
51 #ifndef ROOT_TString
52 #include "TString.h"
53 #endif
54 
55 using namespace Gw;
56 
57 //
59 
60 const Char_t* CorrelatedSpace::fgkDefaultName = "Correlated_Space";
61 const TString CorrelatedSpace::fgkFolderName = "CS";
62  TList* CorrelatedSpace::fgCorrSpaces = 0x0;
63 
64 //__________________________________________________________
66  : TNamed(),
67  fDimension(0), // has to be set
68  fHistoTotList(0x0),
69  fHistoList(0x0),
70  fHistoBkgList(0x0),
71  fStatus(kUndefined),
72  fLog("CorrelatedSpace")
73 {
74  // default constructor
75 }
76 
77 //__________________________________________________________
78 CorrelatedSpace::CorrelatedSpace(const char* name, const char* title)
79 : TNamed(name, title),
80  fDimension(0), // has to be set
81  fHistoTotList(new TList()),
82  fHistoList(new TList()),
83  fHistoBkgList(new TList()),
84  fStatus(kUndefined),
85  fLog("CorrelatedSpace")
86 {
87  // default constructor
88  fHistoList->SetOwner(true);
89  fHistoBkgList->SetOwner(true);
90  fHistoTotList->SetOwner(true);
91 
92  if (fgCorrSpaces == 0x0) {
93  fgCorrSpaces = new TList();
94  fgCorrSpaces->SetOwner(false);
95  }
96 
97  TString nameFolder = fgkFolderName;
98  nameFolder.Prepend("/");
99  TFolder* folder = (TFolder*)gROOT->FindObjectAny(nameFolder.Data());
100  if (folder == 0x0) {
101  folder = gROOT->GetRootFolder()->AddFolder(fgkFolderName,"Folder");
102  for (Int_t i = 0; i < GetCSList()->GetEntries(); ++i) {
103  folder->Add(GetCSList()->At(i));
104  }
105  }
106  folder->Add(this);
107  fgCorrSpaces->Add(this);
108 }
109 
110 //__________________________________________________________
112 {
113  // default destructor
114  delete fHistoTotList;
115  delete fHistoList;
116 
117  //remove for list and folder
118  GetCSList()->Remove(this);
119  TString nameFolder = fgkFolderName;
120  nameFolder.Prepend("/");
121  TFolder* folder = (TFolder*)gROOT->FindObjectAny(nameFolder.Data());
122  folder->Remove(this);
123 }
124 
125 //__________________________________________________________
126 TH1D* CorrelatedSpace::GetHisto(Option_t* axis)
127 {
128  Int_t idx = GetAxisNumber(axis);
129  if (idx < 0 || idx > fDimension) {
130  fLog.SetProcessMethod("GetHisto(Option_t* )");
131  fLog << warning << "Axis number out of range" << dolog;
132  return 0x0;
133  }
134 
135  TH1D* h1 = static_cast<TH1D*> ( fHistoList->At(idx) );
136 
137  return h1;
138 }
139 
140 //__________________________________________________________
141 TH1D* CorrelatedSpace::GetHistoBkg(Option_t* axis)
142 {
143  Int_t idx = GetAxisNumber(axis);
144  if (idx < 0 || idx > fDimension) {
145  fLog.SetProcessMethod("GetHistoBkg(Option_t* )");
146  fLog << warning << "Axis number out of range" << dolog;
147  return 0x0;
148  }
149 
150  TH1D* h1 = static_cast<TH1D*> ( fHistoBkgList->At(idx) );
151 
152  return h1;
153 }
154 
155 //__________________________________________________________
156 TH1D* CorrelatedSpace::GetHistoTot(Option_t* axis)
157 {
158 
159  Int_t idx = GetAxisNumber(axis);
160  if (idx < 0 || idx > fDimension) {
161  fLog.SetProcessMethod("GetHistoTot(Option_t* )");
162  fLog << warning << "Axis number out of range" << dolog;
163  return 0x0;
164  }
165 
166  TH1D* h1 = static_cast<TH1D*> ( fHistoTotList->At(idx) );
167 
168  return h1;
169 }
170 
171 //__________________________________________________________
172 TH1D* CorrelatedSpace::GetHistoTot(Option_t* axis) const
173 {
174 
175  Int_t idx = GetAxisNumber(axis);
176  if (idx < 0 || idx > fDimension) {
177  fLog.SetProcessMethod("GetHistoTot(Option_t* )");
178  fLog << warning << "Axis number out of range" << dolog;
179  return 0x0;
180  }
181 
182  TH1D* h1 = static_cast<TH1D*> ( fHistoTotList->At(idx) );
183 
184  return h1;
185 }
186 
187 //__________________________________________________________
188 void CorrelatedSpace::SetBins(Int_t bin, Double_t min, Double_t max, Int_t axis)
189 {
190  if (axis < 0 || axis > fDimension) {
191  fLog.SetProcessMethod("SetBins(Int_t, Double_t, Double_t, Int_t )");
192  fLog << warning << "Axis number out of range" << dolog;
193  return;
194  }
195 
196  TH1D* h1 = static_cast<TH1D*> ( fHistoList->At(axis) );
197 
198  if (h1)
199  h1->SetBins(bin, min, max);
200 
201  TH1D* h1t = static_cast<TH1D*> ( fHistoTotList->At(axis) );
202 
203  if (h1t)
204  h1t->SetBins(bin, min, max);
205 
206  TH1D* h1b = static_cast<TH1D*> ( fHistoBkgList->At(axis) );
207 
208  if (h1b)
209  h1b->SetBins(bin, min, max);
210 
211  fStatus = kDefined;
212 
213 }
214 
215 //__________________________________________________________
216 void CorrelatedSpace::Project(Option_t* axis, Option_t* gateName)
217 {
218  fLog.SetProcessMethod("Project(Option_t*, Option_t* )");
219 
220  TString name(CSFilter::GetFolderName());
221  name.Prepend("/");
222  name.Append("/");
223  name.Append(gateName);
224 
225  CSFilter* filter = (CSFilter*)gROOT->FindObjectAny(name.Data());
226 
227  if (filter == 0x0) {
228  fLog << error << Form("No filter %s defined", name.Data()) << dolog;
229  return;
230  }
231 
232  Project(filter, axis);
233 
234  fLog << dolog;
235 }
236 
237 //__________________________________________________________
239 {
240  // set dimension & # cells
241  fDimension = cs->GetDimension();
242  SetNofCells(cs->GetNofCells());
243 
244  // set bins
245  for (Int_t j = 0; j < fDimension; ++j) {
246  SetBins(cs->GetNbin(j), 0, cs->GetNbin(j), j);
247  }
248 
249  // set cells
250  for (Int_t i = 0; i < GetNofCells(); ++i) {
251  SetCellContent(i, cs->GetCellContent(i));
252  }
253 }
virtual Double_t GetCellContent(Int_t)=0
Get cell content.
LogMessage & error(LogMessage &)
LogMessage & warning(LogMessage &)
virtual void SetBins(Int_t bin, Double_t min, Double_t max, Int_t axis=0)
Set bin for each axis.
header file for all type of CSManager
static const Char_t * GetFolderName()
Get Folder name.
Definition: CSFilter.h:80
virtual TH1D * GetHistoBkg(Option_t *axis="x")
Get bkg histo.
void SetNofCells(Int_t nCells)
Set number of cells.
void Import(CorrelatedSpace *cs)
Import another CS.
static TList * GetCSList()
Get correlated space lsit.
virtual Int_t GetAxisNumber(Option_t *name) const =0
list of Correlated spaces
Int_t GetNofCells()
Get number of cells.
LogMessage & dolog(LogMessage &)
header file for all type of CorrelatedSpace
CSFilter base class for filter.
Definition: CSFilter.h:56
virtual Int_t GetDimension() const =0
Get dimension.
ClassImp(BaseNucleus)
virtual void SetCellContent(Int_t, Double_t)=0
Set cell content.
virtual TH1D * GetHistoTot(Option_t *axis="x")
Get histo total projection.
virtual void Project(CSFilter *, Option_t *)=0
project
virtual void SetProcessMethod(const char *)
To set the current method.
virtual TH1D * GetHisto(Option_t *axis="x")
Get histo.
virtual Int_t GetNbin(Int_t) const =0
Get Bin.
CorrelatedSpace base class that contains correlated informations.