GammaWare  Head Version for release 0.9
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CorrelatedSpaceTree2F.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_CorrelatedSpaceTree2F
24 #include "CorrelatedSpaceTree2F.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() = "CorrelatedSpaceTree2F";
55 }
56 
57 //__________________________________________________________
59 {
60  // default destructor
61 }
62 
63 //__________________________________________________________
65 {
66  fTree->Branch(fBranchName.Data(), &fCounts, "fCounts/F");
67 }
68 
69 //__________________________________________________________
71 {
72  TBranch* b = fTree->GetBranch(fBranchName.Data());
73  if (b == 0x0) {
74  fLog << warning << "Branch not find in tree" << dolog;
75  return 0x0;
76  }
77 
78  b->SetAddress(&fCounts);
79 
80  return b;
81 }
82 
83 
84 //__________________________________________________________
85 void CorrelatedSpaceTree2F::SetCounts(Double_t weight)
86 {
87  fCounts = weight;
88 }
89 
90 //__________________________________________________________
91 void CorrelatedSpaceTree2F::FillCounts(Int_t i, Int_t j, TH2* h2)
92 {
93 
94  fCounts = (Float_t)(h2->GetBinContent(h2->GetBin(i,j)));
95  GetHistoTot("x")->Fill(j, fCounts);
96 }
97 
98 //__________________________________________________________
99 void CorrelatedSpaceTree2F::FillCounts(Int_t i, Int_t j, Int_t dimX, const Double_t* Xn, const Double_t weight)
100 {
101  fCounts = Float_t(Xn[i*dimX + j]*weight);
102  GetHistoTot("x")->Fill(j, fCounts);
103 }
104 
105 //__________________________________________________________
107 {
108  fCounts = (Float_t)(gRandom->Uniform(0, 10));
109  GetHistoTot("x")->Fill(j, fCounts);
110 }
111 
112 //__________________________________________________________
113 void CorrelatedSpaceTree2F::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+(Double_t)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.
header file for all type of CorrelatedSpaceTree2F
CorrelatedSpaceTree2F class that manages a 2D symmetrical correlated space of floats store in a tree...
TString fBranchName
tree that contains the matrix
void CheckH2InTree(TH2 *h2)
Check if h2 already in tree.
void FillCounts(Int_t i, Int_t j, TH2 *h2)
fill counts
LogMessage & dolog(LogMessage &)
void FillHisto(Int_t j, TH1 *h)
Fill histo.
virtual TH1D * GetHistoTot(Option_t *axis="x")
Get histo total projection.
TBranch * SetAddress()
Set address.
void DeleteTree(Option_t *opt="")
Reset Tree.
ClassImp(CorrelatedSpaceTree2F) CorrelatedSpaceTree2F