GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CorrelatedSpaceTree2D.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_CorrelatedSpaceTree2D
24 #include "CorrelatedSpaceTree2D.h"
25 #endif
26 
27 #ifndef ROOT_TFile
28 #include "TFile.h"
29 #endif
30 
31 #ifndef ROOT_TH2
32 #include "TH2.h"
33 #endif
34 
35 #ifndef ROOT_TRandom
36 #include "TRandom.h"
37 #endif
38 
39 #ifndef ROOT_TTree
40 #include "TTree.h"
41 #endif
42 
43 using namespace Gw;
44 
45 //
47 
48 //__________________________________________________________
51  fCounts(0)
52 {
53  // default constructor
54  fLog.GetProcessName() = "CorrelatedSpaceTree2D";
55 }
56 
57 //__________________________________________________________
59 {
60  // default destructor
61 }
62 
63 //__________________________________________________________
65 {
66  fTree->Branch(fBranchName.Data(), &fCounts, "fCounts/D");
67 }
68 
69 //__________________________________________________________
71 {
72  fLog.SetProcessMethod("SetAddress()");
73 
74  TBranch* b = fTree->GetBranch(fBranchName.Data());
75  if (b == 0x0) {
76  fLog << warning << "Branch not find in tree" << dolog;
77  return 0x0;
78  }
79 
80  b->SetAddress(&fCounts);
81 
82  return b;
83 }
84 
85 //__________________________________________________________
86 void CorrelatedSpaceTree2D::SetCounts(Double_t weight)
87 {
88  fCounts = weight;
89 }
90 
91 //__________________________________________________________
92 void CorrelatedSpaceTree2D::FillCounts(Int_t i, Int_t j, TH2* h2)
93 {
94  fCounts = h2->GetBinContent(h2->GetBin(i,j));
95  GetHistoTot("x")->Fill(j, fCounts);
96 }
97 
98 //__________________________________________________________
99 void CorrelatedSpaceTree2D::FillCounts(Int_t i, Int_t j, Int_t dimX, const Double_t* Xn, const Double_t weight)
100 {
101  fCounts = Xn[i*dimX + j]*weight;
102  GetHistoTot("x")->Fill(j, fCounts);
103 }
104 
105 //__________________________________________________________
107 {
108  fCounts = gRandom->Uniform(0, 10);
109  GetHistoTot("x")->Fill(j, fCounts);
110 }
111 
112 //__________________________________________________________
113 void CorrelatedSpaceTree2D::FillHisto(Int_t j, TH1* h1)
114 {
115  h1->Fill(j, fCounts);
116 }
117 
118 //__________________________________________________________
120 {
121 
122  if (fStatus == kDefined) {
123 
124  Int_t dimX = GetHistoTot("x")->GetNbinsX();
125  Int_t dimY = GetHistoTot("y")->GetNbinsX();
126 
127  if (fTree->GetEntries() == dimX*dimY) {
128 
129  for (Int_t i = 0; i < dimX; ++i) {
130  for (Int_t j = 0; j < dimY; ++j) {
131  fTree->GetEntry(i*dimX + j);
132  Double_t tmp = h2->GetBinContent(h2->GetBin(i,j));
133  h2->SetBinContent(h2->GetBin(i,j), tmp+fCounts);
134  }
135  }
136 
137  DeleteTree();
138  GetHistoTot("x")->Reset("ICE");
139  }
140  }
141 }
142 
143 
TBrowser * b
CorrelatedSpaceTree2 class that manages a 2D symmetrical correlated space stored in a tree In the ent...
LogMessage & warning(LogMessage &)
void SetCounts(Double_t weight)
Set counts.
TBranch * SetAddress()
Set address.
ClassImp(CorrelatedSpaceTree2D) CorrelatedSpaceTree2D
void FillCounts(Int_t i, Int_t j, TH2 *h2)
fill counts
TString fBranchName
tree that contains the matrix
LogMessage & dolog(LogMessage &)
CorrelatedSpaceTree2D class that manages a 2D symmetrical correlated space of doubles store in a tree...
void FillHisto(Int_t j, TH1 *h)
Fill histo.
void CheckH2InTree(TH2 *h2)
Check if h2 already in tree.
virtual TH1D * GetHistoTot(Option_t *axis="x")
Get histo total projection.
void DeleteTree(Option_t *opt="")
Reset Tree.
virtual void SetProcessMethod(const char *)
To set the current method.