GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CorrelatedSpaceLightTree3.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_CorrelatedSpaceLightTree3
25 #endif
26 
27 #ifndef Gw_CSFilter
28 #include "CSFilter.h"
29 #endif
30 
31 #ifndef ROOT_TBrowser
32 #include "TBrowser.h"
33 #endif
34 
35 #ifndef ROOT_TFile
36 #include "TFile.h"
37 #endif
38 
39 #ifndef ROOT_TH3
40 #include "TH3.h"
41 #endif
42 
43 #ifndef ROOT_TRandom
44 #include "TRandom.h"
45 #endif
46 
47 #ifndef ROOT_TString
48 #include "TString.h"
49 #endif
50 
51 #ifndef ROOT_TTree
52 #include "TTree.h"
53 #endif
54 
55 
56 using namespace Gw;
57 
58 //
60 
61 //__________________________________________________________
62 CorrelatedSpaceLightTree3::CorrelatedSpaceLightTree3(const char* name, const char* title)
63  : SymCorrelatedSpace(name, title),
64  fTree(0x0),
65  fBranchName("cube"),
67 {
68  // default constructor
69 
70  SetDimension(3);
71 }
72 
73 //__________________________________________________________
75 {
76  // default destructor
77  delete fTree;
78 }
79 
80 //__________________________________________________________
82 {
83  return Form("%s_3D", GetName());
84 }
85 
86 //__________________________________________________________
88 {
89  return Form("%s_3D", GetTitle());
90 }
91 
92 //__________________________________________________________
94 {
95  fTree->Delete(opt);
96 }
97 
98 //__________________________________________________________
100 {
101 
102  if (fTree == 0x0) {
103  fTree = new TTree(GetTreeName(), GetTreeTitle());
104  }
105 }
106 
107 //__________________________________________________________
109 {
110  fTree->Branch(fBranchName.Data(), fX, "fX[3]/s");
111 }
112 
113 //__________________________________________________________
115 {
116  fLog.SetProcessMethod("SetAddress()");
117 
118  TBranch* b = fTree->GetBranch(fBranchName.Data());
119  if (b == 0x0) {
120  fLog << warning << "Branch not find in tree" << dolog;
121  return 0x0;
122  }
123 
124  b->SetAddress(&fX);
125 
126  return b;
127 }
128 
129 //__________________________________________________________
130 void CorrelatedSpaceLightTree3::Fill(const Double_t* Xn, const Double_t /*weight*/)
131 {
132 
133  static Bool_t first = false;
134 
135  if (first == false) {
136  AssertTree();
137  SetBranch();
138  Int_t dimX = GetHisto("x")->GetNbinsX();
139  SetBins(dimX, 0, dimX, 0);
140  first = true;
141  }
142 
143  fX[0] = Short_t(Xn[0]+0.5);
144  fX[1] = Short_t(Xn[1]+0.5);
145  fX[2] = Short_t(Xn[2]+0.5);
146 
147  fTree->Fill();
148  GetHistoTot("x")->Fill(fX[0]);
149  }
150 
151 //__________________________________________________________
153 {
154 
155  fLog.SetProcessMethod("FillFromH2(TH2* )");
156 
157 
158  if (gFile == 0x0) {
159  fLog << error << "No file exists to write" << dolog;
160  return;
161  }
162 
163  //CheckH2InTree(h2);
164 
165  AssertTree();
166 
167  Double_t count = 0;
168  Int_t nCells = 0;
169  Int_t dimX = h3->GetNbinsX();
170  SetBins(dimX, 0, dimX, 0);
171 
172  SetBranch();
173 
174  for (Int_t i = 0; i < dimX; ++i) {
175  fX[0] = i;
176  for (Int_t j = 0; j < dimX; ++j) {
177  fX[1] = j;
178  for (Int_t k = 0; k < dimX; ++k) {
179  fX[2] = k;
180  count = h3->GetBinContent(h3->GetBin(i,j,k));
181  for (Int_t l = 0; l < count; ++l) {
182  nCells++;
183  fTree->Fill();
184  }
185  }
186  }
187  }
188  TH1D* h = GetHistoTot("x");
189  fTree->Project(h->GetName(),"fX[0]", "");
190  SetNofCells(nCells);
191 
192  fLog << dolog;
193 }
194 
195 //__________________________________________________________
196 void CorrelatedSpaceLightTree3::FillRandom(TH1* h1, Int_t nEvents)
197 {
198  fLog.SetProcessMethod("FillRandom(TH1*, Int_t )");
199 
200  AssertTree();
201 
202  if (gFile == 0x0) {
203  fLog << error << "No file exists to write" << dolog;
204  return;
205  }
206 
207  SetNofCells(nEvents);
208 
209  Int_t dimX = h1->GetNbinsX();
210 
211  SetBins(dimX, 0, dimX, 0);
212 
213  SetBranch();
214  for (Int_t i = 0; i < nEvents; ++i) {
215 
216  fX[0] = (Short_t)h1->GetRandom();
217  fX[1] = (Short_t)h1->GetRandom();
218  fX[2] = (Short_t)h1->GetRandom();
219  fTree->Fill();
220  }
221 
222  TH1D* h = GetHistoTot("x");
223  fTree->Project(h->GetName(),"fX[0]", "fX[0]>0", "", nEvents, 0);
224  fLog << dolog;
225 }
226 
227 //__________________________________________________________
229 {
230  fTree->Browse(b);
231 }
232 
233 //__________________________________________________________
234 void CorrelatedSpaceLightTree3::Project(CSFilter* filter, Option_t* axis)
235 {
236  fLog.SetProcessMethod("Project(CSFilter*, Option_t* )");
237 
238  if (fStatus == kUndefined) {
239  fLog << error << "Tree not defined" << dolog;
240  return;
241  }
242 
243  if (filter == 0x0) {
244  fLog << error << "No filter definied yet" << dolog;
245  return;
246  }
247 
248  Int_t idx = GetAxisNumber(axis);
249 
250  if (idx != 0) {
251  fLog << warning << "Axis number out of range, set to zero cos symetrical CS" << dolog;
252  idx = 0;
253  }
254 
255  if (filter->IsCombined()) {
256  if (!filter->IsListFilled(0) && !filter->IsListFilled(1)) {
257  fLog << error << "Gate list must be filled on axis x and y" << dolog;
258  return;
259  }
260  ProjectCombined(filter, idx);
261  } else {
262  ProjectSimple(filter, idx);
263  }
264 }
265 
266 //__________________________________________________________
268 {
269  filter->SetCondition(2);
270  filter->SetDimension(fDimension-1);
271 
272  TH1D* h1 = 0x0;
273  if ( filter->IsForBkg() )
274  h1 = static_cast<TH1D*> ( fHistoBkgList->At(idx) );
275  else
276  h1 = static_cast<TH1D*> ( fHistoList->At(idx) );
277 
278  h1->Reset();
279  Int_t dim = GetHistoTot("x")->GetNbinsX();
280 
281  SetBins(dim, 0, dim, idx);
282 
283  TBranch* b = SetAddress();
284 
285  Int_t nofGates;
286  Int_t dimProj = fDimension;
287  Short_t inGate[dimProj];
288  Double_t energies[dimProj];
289 
290  Int_t nEntries = fTree->GetEntries();
291  for (Int_t i= 0; i < nEntries; ++i) {
292  b->GetEntry(i);
293 
294  energies[0] = fX[0];
295  energies[1] = fX[1];
296  energies[2] = fX[2];
297  nofGates = filter->IsInside(energies, dimProj, inGate);
298 
299  for (Int_t k= 0; k < fDimension; ++k) {
300  if (nofGates == 2) {
301  if (inGate[k] == 0) {
302  h1->Fill(fX[k]);
303  }
304  }
305  if (nofGates == 3) {
306  h1->Fill(fX[k]);
307  }
308 
309  }
310  }
311  fLog << dolog;
312 }
313 
314 
315 //__________________________________________________________
317 {
318  filter->SetCondition(1);
319  filter->SetDimension(fDimension-1);
320 
321  TH1D* h1 = 0x0;
322  if ( filter->IsForBkg() )
323  h1 = static_cast<TH1D*> ( fHistoBkgList->At(idx) );
324  else
325  h1 = static_cast<TH1D*> ( fHistoList->At(idx) );
326 
327  h1->Reset();
328  Int_t dim = GetHistoTot("x")->GetNbinsX();
329 
330  SetBins(dim, 0, dim, idx);
331 
332  TBranch* b = SetAddress();
333 
334 // Int_t nofGates;
335  Int_t dimProj = fDimension-1;
336  Short_t inGate1[dimProj];
337  Short_t inGate2[dimProj];
338  Double_t energies[dimProj+1];
339 
340  Int_t nEntries = fTree->GetEntries();
341  for (Int_t i= 0; i < nEntries; ++i) {
342  b->GetEntry(i);
343 
344  for (Int_t j = 0; j < fDimension; ++j) {
345  if (j == 0) {
346  energies[0] = fX[1];
347  energies[1] = fX[2];
348  energies[2] = fX[0];
349  } else if (j == 1) {
350  energies[0] = fX[0];
351  energies[1] = fX[1];
352  energies[2] = fX[2];
353  } else {
354  energies[0] = fX[0];
355  energies[1] = fX[2];
356  energies[2] = fX[1];
357  }
358 
359 // nofGates = filter->IsInside(energies, dimProj, inGate1, 0);
360 // nofGates = filter->IsInside(energies, dimProj, inGate2, 1);
361 
362  filter->IsInside(energies, dimProj, inGate1, 0);
363  filter->IsInside(energies, dimProj, inGate2, 1);
364 
365  if(inGate1[0]*inGate2[0] == 1)
366  h1->Fill(energies[2]);
367  }
368  }
369  fLog << dolog;
370 }
371 
372 //_____________________________________________________________________________
373 void CorrelatedSpaceLightTree3::Project(Option_t* axis, Option_t* gateName)
374 {
375  CorrelatedSpace::Project(axis, gateName);
376 }
377 
378 //_____________________________________________________________________________
379 Int_t CorrelatedSpaceLightTree3::GetNbin(Int_t axis) const
380 {
381  switch (axis) {
382  case 0:
383  case 1:
384  return GetHistoTot("x")->GetNbinsX();
385  default:
386  return -1;
387  }
388 }
389 
390 //__________________________________________________________
391 void CorrelatedSpaceLightTree3::SetCellContent(Int_t /*iCell*/, Double_t /*weight*/)
392 {
393  fLog.SetProcessMethod("GetCellContent(Int_t, Double_t)");
394  fLog << warning << "Method not yet available" << dolog;
395 
396 }
397 
398 //__________________________________________________________
400 {
401  fLog.SetProcessMethod("GetCellContent(Int_t )");
402  fLog << warning << "Method not yet available" << dolog;
403  return 0.;
404 }
405 
406 //_____________________________________________________________________________
407 void CorrelatedSpaceLightTree3::Streamer(TBuffer &R__b)
408 {
409  // Customized streamer
410  fLog.SetProcessMethod("Streamer(TBuffer& )");
411  if (R__b.IsReading()) {
412  CorrelatedSpaceLightTree3::Class()->ReadBuffer(R__b, this);
413  fTree = (TTree*)gFile->Get(GetTreeName());
414  if (fTree == 0x0) {
415  fLog << error << "Cannot file tree in file" << nline;
417  }
418  fStatus = kDefined;
419  } else {
420  fTree->Write("", kOverwrite);
421  CorrelatedSpaceLightTree3::Class()->WriteBuffer(R__b, this);
422  }
423  fLog << dolog;
424 }
425 
426 
427 
Int_t GetNbin(Int_t axis) const
Get Bin.
TBrowser * b
void FillRandom(TH1 *h1, Int_t nEvents)
fill random
Bool_t IsForBkg()
Is for bkg gates.
Definition: CSFilter.h:118
LogMessage & error(LogMessage &)
void SetCellContent(Int_t iCell, Double_t weight)
Set cell content.
LogMessage & warning(LogMessage &)
SymCorrelatedSpace base class that contains correlated informations.
virtual void SetBins(Int_t bin, Double_t min, Double_t max, Int_t axis=0)
Set bin for each axis.
virtual Int_t IsInside(Double_t *, Int_t, Short_t *, Int_t=0)
Get the pattern of energies inside the gates.
Definition: CSFilter.h:88
virtual Bool_t IsCombined()
Flag for combined.
Definition: CSFilter.h:91
const Char_t * GetTreeName() const
Get Tree name.
void DeleteTree(Option_t *opt="")
Reset Tree.
LogMessage fLog
array to store axis
const Char_t * GetTreeTitle() const
Get Tree title.
LogMessage & nline(LogMessage &)
void FillFromH3(TH3 *h3)
fill correlated space from H3
void SetNofCells(Int_t nCells)
Set number of cells.
void Fill(const Double_t *Xn, const Double_t weight=1.)
Check if h3 already in tree.
LogMessage & dolog(LogMessage &)
CSFilter base class for filter.
Definition: CSFilter.h:56
ClassImp(CorrelatedSpaceLightTree3) CorrelatedSpaceLightTree3
virtual Bool_t IsListFilled(Int_t)
Check if gate filled.
Definition: CSFilter.h:94
CorrelatedSpaceLightTree3 class that manages a 3D symmetrical correlated space stored in a tree Here ...
header file for all type of CorrelatedSpaceLightTree3
virtual TH1D * GetHistoTot(Option_t *axis="x")
Get histo total projection.
void SetCondition(Short_t cond)
Set dimension for gating.
Definition: CSFilter.h:109
Double_t GetCellContent(Int_t iCell)
Get cell content.
virtual void Project(CSFilter *, Option_t *)=0
project
void ProjectCombined(CSFilter *filter, Int_t idx)
virtual TBranch * SetAddress()
Set address.
virtual void SetProcessMethod(const char *)
To set the current method.
void SetDimension(Short_t dim)
Set dimension for projected space.
Definition: CSFilter.h:115
virtual void Browse(TBrowser *b)
Browser method.
virtual TH1D * GetHisto(Option_t *axis="x")
Get histo.
Int_t dim
Definition: ReadMiniTree3.C:34
TString fBranchName
tree that contains the matrix
void ProjectSimple(CSFilter *filter, Int_t idx)
log message
void Project(CSFilter *filter, Option_t *axis="X")
Project.
virtual Int_t GetAxisNumber(Option_t *name) const
list of Correlated spaces