A class for creating an (ROOT) output file. More...
#include <BCModelOutput.h>
A class for creating an (ROOT) output file.
Definition at line 39 of file BCModelOutput.h.
BCModelOutput::BCModelOutput | ( | ) |
The default constructor.
Definition at line 29 of file BCModelOutput.cxx.
00030 { 00031 fIndex = 0; 00032 00033 fOutputFile = 0; 00034 fAnalysisTree = 0; 00035 fTreeSA = 0; 00036 fModel = 0; 00037 fOutputFile = 0; 00038 }
BCModelOutput::BCModelOutput | ( | BCModel * | model, | |
const char * | filenname | |||
) |
A constructor.
model | The model to which this output class is assigned. | |
filename | Name of the output file. |
Definition at line 42 of file BCModelOutput.cxx.
00043 { 00044 BCModelOutput(); 00045 SetModel(model); 00046 SetFile(filename); 00047 }
BCModelOutput::BCModelOutput | ( | const BCModelOutput & | modeloutput | ) |
The default copy constructor.
Definition at line 61 of file BCModelOutput.cxx.
00062 { 00063 modeloutput.Copy(* this); 00064 }
BCModelOutput::~BCModelOutput | ( | ) | [virtual] |
The default destructor.
Definition at line 51 of file BCModelOutput.cxx.
00052 { 00053 if (fOutputFile) { 00054 fOutputFile -> Close(); 00055 delete fOutputFile; 00056 } 00057 }
void BCModelOutput::Close | ( | ) |
Closes the TFile.
Definition at line 232 of file BCModelOutput.cxx.
00233 { 00234 // remember current directory 00235 TDirectory * dir = gDirectory; 00236 00237 // change to file 00238 fOutputFile -> cd(); 00239 00240 // write analysis tree to file 00241 if (fAnalysisTree -> GetEntries() > 0) 00242 fAnalysisTree -> Write(); 00243 00244 // write markov chain tree to file 00245 for (int i = 0; i < fModel -> MCMCGetNChains(); ++i) 00246 if (fMarkovChainTrees[i] -> GetEntries() > 0) 00247 fMarkovChainTrees[i] -> Write(); 00248 00249 // write SA tree to file 00250 if (fTreeSA -> GetEntries() > 0) 00251 fTreeSA -> Write(); 00252 00253 // close file 00254 fOutputFile -> Close(); 00255 00256 // return to old directory 00257 gDirectory = dir; 00258 }
void BCModelOutput::Copy | ( | BCModelOutput & | modeloutput | ) | const [private] |
Definition at line 346 of file BCModelOutput.cxx.
00347 { 00348 // don't copy the content 00349 modeloutput.fModel = this -> fModel; 00350 modeloutput.fAnalysisTree = this -> fAnalysisTree; 00351 modeloutput.fMarkovChainTrees = this -> fMarkovChainTrees; 00352 }
void BCModelOutput::FillAnalysisTree | ( | ) |
Fill the output TTree with the current information.
Definition at line 122 of file BCModelOutput.cxx.
00123 { 00124 // get output values from model 00125 fNParameters = fModel -> GetNParameters(); 00126 fProbability_apriori = fModel -> GetModelAPrioriProbability(); 00127 fProbability_aposteriori = fModel -> GetModelAPosterioriProbability(); 00128 00129 // loop over parameters 00130 int nparameters = fModel -> GetNParameters(); 00131 for (int i = 0; i < nparameters; ++i) 00132 { 00133 BCParameter * parameter = fModel -> GetParameter(i); 00134 if (fModel -> GetBestFitParameters().size() > 0) 00135 fMode_global[i] = fModel -> GetBestFitParameters().at(i); 00136 if (fModel -> GetMarginalized(parameter -> GetName().data())) 00137 { 00138 fMode_marginalized[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetMode(); 00139 fMean_marginalized[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetMean(); 00140 fMedian_marginalized[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetMedian(); 00141 fQuantile_05[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.05); 00142 fQuantile_10[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.10); 00143 fQuantile_16[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.16); 00144 fQuantile_84[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.84); 00145 fQuantile_90[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.90); 00146 fQuantile_95[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.95); 00147 } 00148 } 00149 00150 // fill tree 00151 fAnalysisTree -> Fill(); 00152 00153 // increase index 00154 fIndex++; 00155 }
TTree* BCModelOutput::GetAnalysisTree | ( | ) | [inline] |
Returns the output TTree tree.
Definition at line 81 of file BCModelOutput.h.
00082 { return fAnalysisTree; };
TFile* BCModelOutput::GetFile | ( | ) | [inline] |
Returns the output TFile.
Definition at line 87 of file BCModelOutput.h.
00088 { return fOutputFile; };
void BCModelOutput::InitializeAnalysisTree | ( | ) | [private] |
Initialize the output TTree.
Definition at line 262 of file BCModelOutput.cxx.
00263 { 00264 // create new tree 00265 fAnalysisTree = new TTree("AnalysisTree", "AnalysisTree"); 00266 00267 // set branch addresses 00268 fAnalysisTree -> Branch("fIndex", &fIndex, "index/I"); 00269 fAnalysisTree -> Branch("fNParameters", &fNParameters, "parameters/I"); 00270 fAnalysisTree -> Branch("fProbability_apriori" , &fProbability_apriori, "apriori probability/D"); 00271 fAnalysisTree -> Branch("fProbability_aposteriori", &fProbability_aposteriori, "aposteriori probability/D"); 00272 fAnalysisTree -> Branch("fMode_global", fMode_global, "mode (global) [parameters]/D"); 00273 fAnalysisTree -> Branch("fMode_marginalized", fMode_marginalized, "mode (marginalized) [parameters]/D"); 00274 fAnalysisTree -> Branch("fMean_marginalized", fMean_marginalized, "mean (marginalized)[parameters]/D"); 00275 fAnalysisTree -> Branch("fMedian_marginalized", fMedian_marginalized, "median (marginalized)[parameters]/D"); 00276 fAnalysisTree -> Branch("fQuantile_05" , fQuantile_05, "quantile 5% [parameters]/D"); 00277 fAnalysisTree -> Branch("fQuantile_10" , fQuantile_10, "quantile 10% [parameters]/D"); 00278 fAnalysisTree -> Branch("fQuantile_16" , fQuantile_16, "quantile 16% [parameters]/D"); 00279 fAnalysisTree -> Branch("fQuantile_84" , fQuantile_84, "quantile 84% [parameters]/D"); 00280 fAnalysisTree -> Branch("fQuantile_90" , fQuantile_90, "quantile 90% [parameters]/D"); 00281 fAnalysisTree -> Branch("fQuantile_95" , fQuantile_95, "quantile 95% [parameters]/D"); 00282 }
void BCModelOutput::InitializeMarkovChainTrees | ( | ) | [private] |
Initialize the Markov Chain TTree.
Definition at line 286 of file BCModelOutput.cxx.
00287 { 00288 // create new tree 00289 fMarkovChainTrees.clear(); 00290 for (int i = 0; i < fModel -> MCMCGetNChains(); ++i) 00291 { 00292 TTree * tree = new TTree(TString::Format("MarkovChainTree_%i", i), "MarkovChainTree"); 00293 fMarkovChainTrees.push_back(tree); 00294 } 00295 00296 // connect pointer to parameter vectors 00297 fParameters = fModel -> MCMCGetP2x(); 00298 fIteration = fModel -> MCMCGetP2NIterations(); 00299 fLogLikelihood = fModel -> MCMCGetP2LogProbx(); 00300 fNParameters = fModel -> MCMCGetNParameters(); 00301 00302 for (int i = 0; i < fModel -> MCMCGetNChains(); ++i) 00303 { 00304 fMarkovChainTrees[i] -> Branch("fIteration", &(*fIteration)[i], "iteration/I"); 00305 fMarkovChainTrees[i] -> Branch("fNParameters", &fNParameters, "parameters/I"); 00306 fMarkovChainTrees[i] -> Branch("fLogLikelihood", &(*fLogLikelihood)[i], "log (likelihood)/D"); 00307 } 00308 00309 // loop over all parameters 00310 for (int i = 0; i < fModel -> MCMCGetNChains(); ++i) 00311 for (int j = 0; j < fModel -> MCMCGetNParameters(); ++j) 00312 { 00313 fMarkovChainTrees[i] -> Branch(TString::Format("fParameter%i", j), 00314 &(*fParameters)[i * fModel -> MCMCGetNParameters() + j], 00315 TString::Format("parameter %i/D", j)); 00316 } 00317 00318 fModel -> MCMCSetMarkovChainTrees(fMarkovChainTrees); 00319 }
void BCModelOutput::InitializeSATree | ( | ) | [private] |
Initialize SA TTree.
Definition at line 322 of file BCModelOutput.cxx.
00323 { 00324 fTreeSA = new TTree("SATree", "SATree"); 00325 00326 // connect pointer to parameter vectors 00327 fSAIteration = fModel -> GetSAP2NIterations(); 00328 fSATemperature = fModel -> GetSAP2Temperature(); 00329 fSALogProb = fModel -> GetSAP2LogProb(); 00330 fSAParameters = fModel -> GetSAP2x(); 00331 fSANParameters = fModel -> GetNParameters(); 00332 00333 fTreeSA -> Branch("Iteration", fSAIteration, "iteration/I"); 00334 fTreeSA -> Branch("NParameters", &fSANParameters, "parameters/I"); 00335 fTreeSA -> Branch("Temperature", fSATemperature, "temperature/D"); 00336 fTreeSA -> Branch("LogProb", fSALogProb, "log probability/D"); 00337 for (int j = 0; j < fModel -> MCMCGetNParameters(); ++j) 00338 fTreeSA -> Branch(TString::Format("Parameter%i", j), 00339 &(*fSAParameters)[j], 00340 TString::Format("parameter %i/D", j)); 00341 00342 fModel -> SetSATree(fTreeSA); 00343 }
BCModelOutput & BCModelOutput::operator= | ( | const BCModelOutput & | modeloutput | ) |
The defaut assignment operator
Definition at line 68 of file BCModelOutput.cxx.
00069 { 00070 if (this != &modeloutput) 00071 modeloutput.Copy(* this); 00072 00073 return * this; 00074 }
void BCModelOutput::SetFile | ( | const char * | filename | ) |
Sets the output filename.
filename | The filename |
Definition at line 87 of file BCModelOutput.cxx.
00088 { 00089 // delete the old file 00090 if (fOutputFile) 00091 { 00092 fOutputFile -> Close(); 00093 delete fOutputFile; 00094 } 00095 00096 // remember current directory 00097 TDirectory * dir = gDirectory; 00098 00099 // create a new file 00100 fFileName=filename; 00101 fOutputFile = new TFile(fFileName, "RECREATE"); 00102 00103 // initialize trees 00104 InitializeAnalysisTree(); 00105 InitializeMarkovChainTrees(); 00106 InitializeSATree(); 00107 00108 // change back to the old directory 00109 gDirectory = dir; 00110 }
void BCModelOutput::SetModel | ( | BCModel * | model | ) |
void BCModelOutput::Write | ( | TObject * | o | ) |
Writes any object derived from TObject to TFile.
Definition at line 216 of file BCModelOutput.cxx.
00217 { 00218 // remember current directory 00219 TDirectory * dir = gDirectory; 00220 00221 // change to file 00222 fOutputFile -> cd(); 00223 00224 o -> Write(); 00225 00226 // return to old directory 00227 gDirectory = dir; 00228 }
void BCModelOutput::WriteErrorBand | ( | ) |
Writes the error band histogram into the TFile.
Definition at line 183 of file BCModelOutput.cxx.
00184 { 00185 // remember current directory 00186 TDirectory * dir = gDirectory; 00187 00188 // change to file 00189 fOutputFile -> cd(); 00190 00191 TH2D * h0 = fModel -> GetErrorBandXY(); 00192 if (h0) 00193 { 00194 TH2D * h1 = (TH2D*)h0 -> Clone("errorbandxy"); 00195 h1 -> Write(); 00196 00197 double levels[] = { .68, .90, .95 }; 00198 int nlevels = sizeof(levels)/sizeof(double); 00199 for (int i=0;i<nlevels;i++) 00200 { 00201 TH2D * htmp = fModel -> GetErrorBandXY_yellow(levels[i]); 00202 htmp -> SetName(TString::Format("%s_sub_%f.2",h1->GetName(),levels[i])); 00203 htmp -> Write(); 00204 delete htmp; 00205 } 00206 00207 delete h1; 00208 } 00209 00210 // return to old directory 00211 gDirectory = dir; 00212 }
void BCModelOutput::WriteMarginalizedDistributions | ( | ) |
Writes the marginalized histograms to the TFile.
Definition at line 159 of file BCModelOutput.cxx.
00160 { 00161 // remember current directory 00162 TDirectory * dir = gDirectory; 00163 00164 // change to file 00165 fOutputFile -> cd(); 00166 00167 int nparameters = fModel -> GetNParameters(); 00168 for (int i = 0; i < nparameters; ++i) 00169 fModel -> GetMarginalized(fModel -> GetParameter(i)) -> GetHistogram() -> Write(); 00170 00171 if (nparameters > 1) 00172 for (int i = 0; i < nparameters - 1; ++i) 00173 for (int j = i + 1; j < nparameters; ++j) 00174 fModel -> GetMarginalized(fModel -> GetParameter(i), 00175 fModel -> GetParameter(j)) -> GetHistogram() -> Write(); 00176 00177 // return to old directory 00178 gDirectory = dir; 00179 }
void BCModelOutput::WriteMarkovChain | ( | bool | flag = true |
) |
Flag for writing Markov chain to file
flag | Writes (true) or does not write (false) the Markov chain |
Definition at line 114 of file BCModelOutput.cxx.
00115 { 00116 if (fModel) 00117 fModel -> WriteMarkovChain(flag); 00118 }
TTree* BCModelOutput::fAnalysisTree [private] |
Pointer to the TTree containing the summary output information.
Definition at line 158 of file BCModelOutput.h.
const char* BCModelOutput::fFileName [private] |
The output filename
Definition at line 171 of file BCModelOutput.h.
int BCModelOutput::fIndex [private] |
The analysis tree variables
Definition at line 183 of file BCModelOutput.h.
std::vector<int>* BCModelOutput::fIteration [private] |
Definition at line 202 of file BCModelOutput.h.
std::vector<double>* BCModelOutput::fLogLikelihood [private] |
Definition at line 201 of file BCModelOutput.h.
std::vector<TTree *> BCModelOutput::fMarkovChainTrees [private] |
Definition at line 163 of file BCModelOutput.h.
double BCModelOutput::fMean_marginalized[MAXNPARAMETERS] [private] |
Definition at line 189 of file BCModelOutput.h.
double BCModelOutput::fMedian_marginalized[MAXNPARAMETERS] [private] |
Definition at line 190 of file BCModelOutput.h.
double BCModelOutput::fMode_global[MAXNPARAMETERS] [private] |
Definition at line 187 of file BCModelOutput.h.
double BCModelOutput::fMode_marginalized[MAXNPARAMETERS] [private] |
Definition at line 188 of file BCModelOutput.h.
BCModel* BCModelOutput::fModel [private] |
Pointer to the model this output class is assigned to
Definition at line 179 of file BCModelOutput.h.
unsigned int BCModelOutput::fNParameters [private] |
Definition at line 184 of file BCModelOutput.h.
TFile* BCModelOutput::fOutputFile [private] |
Pointer to the output TFile.
Definition at line 175 of file BCModelOutput.h.
std::vector<double>* BCModelOutput::fParameters [private] |
The markov chain tree variables
Definition at line 200 of file BCModelOutput.h.
double BCModelOutput::fProbability_aposteriori [private] |
Definition at line 186 of file BCModelOutput.h.
double BCModelOutput::fProbability_apriori [private] |
Definition at line 185 of file BCModelOutput.h.
double BCModelOutput::fQuantile_05[MAXNPARAMETERS] [private] |
Definition at line 191 of file BCModelOutput.h.
double BCModelOutput::fQuantile_10[MAXNPARAMETERS] [private] |
Definition at line 192 of file BCModelOutput.h.
double BCModelOutput::fQuantile_16[MAXNPARAMETERS] [private] |
Definition at line 193 of file BCModelOutput.h.
double BCModelOutput::fQuantile_84[MAXNPARAMETERS] [private] |
Definition at line 194 of file BCModelOutput.h.
double BCModelOutput::fQuantile_90[MAXNPARAMETERS] [private] |
Definition at line 195 of file BCModelOutput.h.
double BCModelOutput::fQuantile_95[MAXNPARAMETERS] [private] |
Definition at line 196 of file BCModelOutput.h.
int* BCModelOutput::fSAIteration [private] |
The simulated annealing tree variables
Definition at line 206 of file BCModelOutput.h.
double* BCModelOutput::fSALogProb [private] |
Definition at line 209 of file BCModelOutput.h.
int BCModelOutput::fSANParameters [private] |
Definition at line 207 of file BCModelOutput.h.
std::vector<double>* BCModelOutput::fSAParameters [private] |
Definition at line 210 of file BCModelOutput.h.
double* BCModelOutput::fSATemperature [private] |
Definition at line 208 of file BCModelOutput.h.
TTree* BCModelOutput::fTreeSA [private] |
Definition at line 167 of file BCModelOutput.h.