BayesianAnalysisToolkit  0.9.3
Private Member Functions | Private Attributes | List of all members
BCModelOutput Class Reference

A class for creating an (ROOT) output file. More...

#include <BCModelOutput.h>

Collaboration diagram for BCModelOutput:
Collaboration graph
[legend]

Public Member Functions

Constructors and destructors
 BCModelOutput ()
 
 BCModelOutput (BCModel *model, const char *filenname)
 
 BCModelOutput (const BCModelOutput &modeloutput)
 
virtual ~BCModelOutput ()
 
Assignment operators
BCModelOutputoperator= (const BCModelOutput &modeloutput)
 
Getters
TTree * GetAnalysisTree ()
 
TFile * GetFile ()
 
Setters
void SetModel (BCModel *model)
 
void SetFile (const char *filename)
 
Member functions (miscellaneous methods)
void WriteMarkovChain (bool flag=true)
 
void FillAnalysisTree ()
 
void WriteMarginalizedDistributions ()
 
void Write (TObject *o)
 
void Close ()
 

Private Member Functions

void Init ()
 
void Copy (BCModelOutput &modeloutput) const
 
void InitializeAnalysisTree ()
 
void InitializeSATree ()
 

Private Attributes

TTree * fAnalysisTree
 
std::vector< TTree * > fMarkovChainTrees
 
TTree * fTreeSA
 
char * fFileName
 
TFile * fOutputFile
 
BCModelfModel
 
int fIndex
 
unsigned int fNParameters
 
double fProbability_apriori
 
double fProbability_aposteriori
 
double fMode_global [MAXNPARAMETERS]
 
double fMode_marginalized [MAXNPARAMETERS]
 
double fMean_marginalized [MAXNPARAMETERS]
 
double fMedian_marginalized [MAXNPARAMETERS]
 
double fQuantile_05 [MAXNPARAMETERS]
 
double fQuantile_10 [MAXNPARAMETERS]
 
double fQuantile_16 [MAXNPARAMETERS]
 
double fQuantile_84 [MAXNPARAMETERS]
 
double fQuantile_90 [MAXNPARAMETERS]
 
double fQuantile_95 [MAXNPARAMETERS]
 

Detailed Description

A class for creating an (ROOT) output file.

Author
Daniel Kollar
Kevin Kröninger
Version
1.0
Date
08.2008 This class defines an output interface for the analysis. It creates a ROOT file which can contain summary information, histograms and Markov chains.

Definition at line 40 of file BCModelOutput.h.

Constructor & Destructor Documentation

BCModelOutput::BCModelOutput ( )

The default constructor.

Definition at line 30 of file BCModelOutput.cxx.

31 {
32  Init();
33 }
BCModelOutput::BCModelOutput ( BCModel model,
const char *  filenname 
)

A constructor.

Parameters
modelThe model to which this output class is assigned.
filenameName of the output file.

Definition at line 36 of file BCModelOutput.cxx.

37 {
38  Init();
39  SetModel(model);
40  SetFile(filename);
41 }
BCModelOutput::BCModelOutput ( const BCModelOutput modeloutput)

The default copy constructor.

Definition at line 53 of file BCModelOutput.cxx.

54 {
55  modeloutput.Copy(* this);
56 }
BCModelOutput::~BCModelOutput ( )
virtual

The default destructor.

Definition at line 44 of file BCModelOutput.cxx.

45 {
46  if (fOutputFile) {
47  Close();
48  delete fOutputFile;
49  }
50 }

Member Function Documentation

void BCModelOutput::Close ( )

Closes the TFile.

Definition at line 227 of file BCModelOutput.cxx.

228 {
229  if (!fOutputFile)
230  return;
231 
232  if (!fOutputFile->IsOpen())
233  return;
234 
235  // remember current directory
236  TDirectory * dir = gDirectory;
237 
238  // change to file
239  fOutputFile->cd();
240 
241  // write analysis tree to file
242  if (fAnalysisTree)
243  if (fAnalysisTree->GetEntries() > 0)
244  fAnalysisTree->Write();
245 
246  // write markov chain tree to file
247  if (fModel) {
248  for (unsigned i = 0; i < fModel->MCMCGetNChains(); ++i) {
250  if (fModel->MCMCGetMarkovChainTree(i)->GetEntries() > 0) {
251  fModel->MCMCGetMarkovChainTree(i)->Write();
252  }
253  }
254  }
255  }
256 
257  // write SA tree to file
258  if (fModel)
259  if (fModel->GetSATree()->GetEntries() > 0)
260  fModel->GetSATree()->Write();
261 
262  // close file
263  fOutputFile->Close();
264 
265  // return to old directory
266  gDirectory = dir;
267 }
void BCModelOutput::Copy ( BCModelOutput modeloutput) const
private

Copies this BCModelOutput into another one

Definition at line 293 of file BCModelOutput.cxx.

294 {
295  // don't copy the content
296  modeloutput.fModel = fModel;
297  modeloutput.fAnalysisTree = fAnalysisTree;
298 }
void BCModelOutput::FillAnalysisTree ( )

Fill the output TTree with the current information.

Definition at line 124 of file BCModelOutput.cxx.

125 {
126  if(!fOutputFile) {
127  BCLog::OutError("BCModelOutput::FillAnalysisTree : No file to write to.");
128  return;
129  }
130 
131  // get output values from model
135 
136  // loop over parameters
137  int nparameters = fModel->GetNParameters();
138  for (int i = 0; i < nparameters; ++i) {
139  const BCParameter * parameter = fModel->GetParameter(i);
140  if (fModel->GetBestFitParameters().size() > 0)
142  if (fModel->GetMarginalized(parameter->GetName().data())) {
143  fMode_marginalized[i] = fModel->GetMarginalized(parameter->GetName().data())->GetMode();
144  fMean_marginalized[i] = fModel->GetMarginalized(parameter->GetName().data())->GetMean();
145  fMedian_marginalized[i] = fModel->GetMarginalized(parameter->GetName().data())->GetMedian();
146  fQuantile_05[i] = fModel->GetMarginalized(parameter->GetName().data())->GetQuantile(0.05);
147  fQuantile_10[i] = fModel->GetMarginalized(parameter->GetName().data())->GetQuantile(0.10);
148  fQuantile_16[i] = fModel->GetMarginalized(parameter->GetName().data())->GetQuantile(0.16);
149  fQuantile_84[i] = fModel->GetMarginalized(parameter->GetName().data())->GetQuantile(0.84);
150  fQuantile_90[i] = fModel->GetMarginalized(parameter->GetName().data())->GetQuantile(0.90);
151  fQuantile_95[i] = fModel->GetMarginalized(parameter->GetName().data())->GetQuantile(0.95);
152  }
153  }
154 
155  // fill tree
156  fAnalysisTree->Fill();
157 
158  // increase index
159  fIndex++;
160 }
TTree* BCModelOutput::GetAnalysisTree ( )
inline

Returns the output TTree tree.

Returns
The pointer to the output TTree

Definition at line 82 of file BCModelOutput.h.

83  { return fAnalysisTree; };
TFile* BCModelOutput::GetFile ( )
inline

Returns the output TFile.

Returns
The pointer to the output TFile

Definition at line 88 of file BCModelOutput.h.

89  { return fOutputFile; };
void BCModelOutput::Init ( )
private

Initialize the variables

Definition at line 68 of file BCModelOutput.cxx.

69 {
70  fIndex = 0;
71  fOutputFile = 0;
72  fAnalysisTree = 0;
73  fTreeSA = 0;
74  fModel = 0;
75  fFileName = 0;
76 }
void BCModelOutput::InitializeAnalysisTree ( )
private

Initialize the output TTree.

Definition at line 270 of file BCModelOutput.cxx.

271 {
272  // create new tree
273  fAnalysisTree = new TTree("AnalysisTree", "AnalysisTree");
274 
275  // set branch addresses
276  fAnalysisTree->Branch("fIndex", &fIndex, "index/I");
277  fAnalysisTree->Branch("fNParameters", &fNParameters, "parameters/I");
278  fAnalysisTree->Branch("fProbability_apriori" , &fProbability_apriori, "apriori probability/D");
279  fAnalysisTree->Branch("fProbability_aposteriori", &fProbability_aposteriori, "aposteriori probability/D");
280  fAnalysisTree->Branch("fMode_global", fMode_global, "mode (global) [parameters]/D");
281  fAnalysisTree->Branch("fMode_marginalized", fMode_marginalized, "mode (marginalized) [parameters]/D");
282  fAnalysisTree->Branch("fMean_marginalized", fMean_marginalized, "mean (marginalized)[parameters]/D");
283  fAnalysisTree->Branch("fMedian_marginalized", fMedian_marginalized, "median (marginalized)[parameters]/D");
284  fAnalysisTree->Branch("fQuantile_05" , fQuantile_05, "quantile 5% [parameters]/D");
285  fAnalysisTree->Branch("fQuantile_10" , fQuantile_10, "quantile 10% [parameters]/D");
286  fAnalysisTree->Branch("fQuantile_16" , fQuantile_16, "quantile 16% [parameters]/D");
287  fAnalysisTree->Branch("fQuantile_84" , fQuantile_84, "quantile 84% [parameters]/D");
288  fAnalysisTree->Branch("fQuantile_90" , fQuantile_90, "quantile 90% [parameters]/D");
289  fAnalysisTree->Branch("fQuantile_95" , fQuantile_95, "quantile 95% [parameters]/D");
290 }
void BCModelOutput::InitializeSATree ( )
private

Initialize SA TTree.

BCModelOutput & BCModelOutput::operator= ( const BCModelOutput modeloutput)

The defaut assignment operator

Definition at line 59 of file BCModelOutput.cxx.

60 {
61  if (this != &modeloutput)
62  modeloutput.Copy(* this);
63 
64  return * this;
65 }
void BCModelOutput::SetFile ( const char *  filename)

Sets the output filename.

Parameters
filenameThe filename

Definition at line 87 of file BCModelOutput.cxx.

88 {
89  if(!fModel) {
90  BCLog::OutError("BCModelOutput::SetFile : Cannot set file if model is not set.");
91  return;
92  }
93 
94  // delete the old file
95  if (fOutputFile) {
96  fOutputFile->Close();
97  delete fOutputFile;
98  }
99 
100  // remember current directory
101  TDirectory * dir = gDirectory;
102 
103  // create a new file
104  fFileName = const_cast<char *>(filename);
105  fOutputFile = TFile::Open(fFileName, "RECREATE");
106 
107  // initialize trees
111 
112  // change back to the old directory
113  gDirectory = dir;
114 }
void BCModelOutput::SetModel ( BCModel model)

Assign a BCModel to this output class.

Parameters
modelA pointer to the BCModel

Definition at line 79 of file BCModelOutput.cxx.

80 {
81  fModel = model;
84 }
void BCModelOutput::Write ( TObject *  o)

Writes any object derived from TObject to TFile.

Definition at line 207 of file BCModelOutput.cxx.

208 {
209  if(!fOutputFile) {
210  BCLog::OutError("BCModelOutput::Write : No file to write to.");
211  return;
212  }
213 
214  // remember current directory
215  TDirectory * dir = gDirectory;
216 
217  // change to file
218  fOutputFile->cd();
219 
220  o->Write();
221 
222  // return to old directory
223  gDirectory = dir;
224 }
void BCModelOutput::WriteMarginalizedDistributions ( )

Writes the marginalized histograms to the TFile.

Definition at line 163 of file BCModelOutput.cxx.

164 {
165  if(!fOutputFile) {
166  BCLog::OutError("BCModelOutput::WriteMarginalizedDistributions : No file to write to.");
167  return;
168  }
169 
170  if (!fOutputFile->IsOpen())
171  return;
172 
173  // remember current directory
174  TDirectory * dir = gDirectory;
175 
176  // change to file
177  fOutputFile->cd();
178 
179  int nparameters = fModel->GetNParameters();
180  for (int i = 0; i < nparameters; ++i) {
182  if (bchist) {
183  TH1D* hist = bchist->GetHistogram();
184  if (hist)
185  hist->Write();
186  }
187  }
188 
189  if (nparameters > 1)
190  for (int i = 0; i < nparameters - 1; ++i) {
191  for (int j = i + 1; j < nparameters; ++j) {
193  fModel->GetParameter(j));
194  if (bchist) {
195  TH2D* hist = bchist->GetHistogram();
196  if (hist)
197  hist->Write();
198  }
199  }
200  }
201 
202  // return to old directory
203  gDirectory = dir;
204 }
void BCModelOutput::WriteMarkovChain ( bool  flag = true)

Flag for writing Markov chain to file

Parameters
flagWrites (true) or does not write (false) the Markov chain

Definition at line 117 of file BCModelOutput.cxx.

118 {
119  if (fModel)
120  fModel->WriteMarkovChain(flag);
121 }

Member Data Documentation

TTree* BCModelOutput::fAnalysisTree
private

Pointer to the TTree containing the summary output information.

Definition at line 155 of file BCModelOutput.h.

char* BCModelOutput::fFileName
private

The output filename

Definition at line 168 of file BCModelOutput.h.

int BCModelOutput::fIndex
private

The analysis tree variables

Definition at line 180 of file BCModelOutput.h.

std::vector<TTree *> BCModelOutput::fMarkovChainTrees
private

The trees containing the Markov chains. The length of the vector is fMCMCNChains.

Definition at line 160 of file BCModelOutput.h.

double BCModelOutput::fMean_marginalized[MAXNPARAMETERS]
private

Definition at line 186 of file BCModelOutput.h.

double BCModelOutput::fMedian_marginalized[MAXNPARAMETERS]
private

Definition at line 187 of file BCModelOutput.h.

double BCModelOutput::fMode_global[MAXNPARAMETERS]
private

Definition at line 184 of file BCModelOutput.h.

double BCModelOutput::fMode_marginalized[MAXNPARAMETERS]
private

Definition at line 185 of file BCModelOutput.h.

BCModel* BCModelOutput::fModel
private

Pointer to the model this output class is assigned to

Definition at line 176 of file BCModelOutput.h.

unsigned int BCModelOutput::fNParameters
private

Definition at line 181 of file BCModelOutput.h.

TFile* BCModelOutput::fOutputFile
private

Pointer to the output TFile.

Definition at line 172 of file BCModelOutput.h.

double BCModelOutput::fProbability_aposteriori
private

Definition at line 183 of file BCModelOutput.h.

double BCModelOutput::fProbability_apriori
private

Definition at line 182 of file BCModelOutput.h.

double BCModelOutput::fQuantile_05[MAXNPARAMETERS]
private

Definition at line 188 of file BCModelOutput.h.

double BCModelOutput::fQuantile_10[MAXNPARAMETERS]
private

Definition at line 189 of file BCModelOutput.h.

double BCModelOutput::fQuantile_16[MAXNPARAMETERS]
private

Definition at line 190 of file BCModelOutput.h.

double BCModelOutput::fQuantile_84[MAXNPARAMETERS]
private

Definition at line 191 of file BCModelOutput.h.

double BCModelOutput::fQuantile_90[MAXNPARAMETERS]
private

Definition at line 192 of file BCModelOutput.h.

double BCModelOutput::fQuantile_95[MAXNPARAMETERS]
private

Definition at line 193 of file BCModelOutput.h.

TTree* BCModelOutput::fTreeSA
private

The tree for the simulated annealing.

Definition at line 164 of file BCModelOutput.h.


The documentation for this class was generated from the following files: