#include <BCModelOutput.h>
Collaboration diagram for BCModelOutput:
Definition at line 39 of file BCModelOutput.h.
BCModelOutput::BCModelOutput | ( | ) |
The default constructor.
Definition at line 29 of file BCModelOutput.cxx.
00030 { 00031 Init(); 00032 }
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 35 of file BCModelOutput.cxx.
BCModelOutput::BCModelOutput | ( | const BCModelOutput & | modeloutput | ) |
The default copy constructor.
Definition at line 52 of file BCModelOutput.cxx.
00053 { 00054 modeloutput.Copy(* this); 00055 }
BCModelOutput::~BCModelOutput | ( | ) | [virtual] |
The default destructor.
Definition at line 43 of file BCModelOutput.cxx.
00044 { 00045 if (fOutputFile) { 00046 fOutputFile -> Close(); 00047 delete fOutputFile; 00048 } 00049 }
BCModelOutput::BCModelOutput | ( | ) |
The default constructor.
Definition at line 29 of file BCModelOutput.cxx.
00030 { 00031 Init(); 00032 }
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 35 of file BCModelOutput.cxx.
BCModelOutput::BCModelOutput | ( | const BCModelOutput & | modeloutput | ) |
The default copy constructor.
Definition at line 52 of file BCModelOutput.cxx.
00053 { 00054 modeloutput.Copy(* this); 00055 }
BCModelOutput::~BCModelOutput | ( | ) | [virtual] |
The default destructor.
Definition at line 43 of file BCModelOutput.cxx.
00044 { 00045 if (fOutputFile) { 00046 fOutputFile -> Close(); 00047 delete fOutputFile; 00048 } 00049 }
BCModelOutput & BCModelOutput::operator= | ( | const BCModelOutput & | modeloutput | ) |
The defaut assignment operator
Definition at line 58 of file BCModelOutput.cxx.
00059 { 00060 if (this != &modeloutput) 00061 modeloutput.Copy(* this); 00062 00063 return * this; 00064 }
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::SetModel | ( | BCModel * | model | ) |
void BCModelOutput::SetFile | ( | const char * | filename | ) |
Sets the output filename.
filename | The filename |
Definition at line 86 of file BCModelOutput.cxx.
00087 { 00088 // delete the old file 00089 if (fOutputFile) 00090 { 00091 fOutputFile -> Close(); 00092 delete fOutputFile; 00093 } 00094 00095 // remember current directory 00096 TDirectory * dir = gDirectory; 00097 00098 // create a new file 00099 fFileName = const_cast<char *>(filename); 00100 fOutputFile = new TFile(fFileName, "RECREATE"); 00101 00102 // initialize trees 00103 InitializeAnalysisTree(); 00104 InitializeMarkovChainTrees(); 00105 InitializeSATree(); 00106 00107 // change back to the old directory 00108 gDirectory = dir; 00109 }
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 112 of file BCModelOutput.cxx.
00113 { 00114 if (fModel) 00115 fModel -> WriteMarkovChain(flag); 00116 }
void BCModelOutput::FillAnalysisTree | ( | ) |
Fill the output TTree with the current information.
Definition at line 119 of file BCModelOutput.cxx.
00120 { 00121 if(!fOutputFile) 00122 { 00123 BCLog::OutError("BCModelOutput::FillAnalysisTree : No file to write to."); 00124 return; 00125 } 00126 00127 // get output values from model 00128 fNParameters = fModel -> GetNParameters(); 00129 fProbability_apriori = fModel -> GetModelAPrioriProbability(); 00130 fProbability_aposteriori = fModel -> GetModelAPosterioriProbability(); 00131 00132 // loop over parameters 00133 int nparameters = fModel -> GetNParameters(); 00134 for (int i = 0; i < nparameters; ++i) 00135 { 00136 BCParameter * parameter = fModel -> GetParameter(i); 00137 if (fModel -> GetBestFitParameters().size() > 0) 00138 fMode_global[i] = fModel -> GetBestFitParameters().at(i); 00139 if (fModel -> GetMarginalized(parameter -> GetName().data())) 00140 { 00141 fMode_marginalized[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetMode(); 00142 fMean_marginalized[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetMean(); 00143 fMedian_marginalized[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetMedian(); 00144 fQuantile_05[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.05); 00145 fQuantile_10[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.10); 00146 fQuantile_16[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.16); 00147 fQuantile_84[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.84); 00148 fQuantile_90[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.90); 00149 fQuantile_95[i] = fModel -> GetMarginalized(parameter -> GetName().data()) -> GetQuantile(0.95); 00150 } 00151 } 00152 00153 // fill tree 00154 fAnalysisTree -> Fill(); 00155 00156 // increase index 00157 fIndex++; 00158 }
void BCModelOutput::WriteMarginalizedDistributions | ( | ) |
Writes the marginalized histograms to the TFile.
Definition at line 161 of file BCModelOutput.cxx.
00162 { 00163 if(!fOutputFile) 00164 { 00165 BCLog::OutError("BCModelOutput::WriteMarginalizedDistributions : No file to write to."); 00166 return; 00167 } 00168 00169 // remember current directory 00170 TDirectory * dir = gDirectory; 00171 00172 // change to file 00173 fOutputFile -> cd(); 00174 00175 int nparameters = fModel -> GetNParameters(); 00176 for (int i = 0; i < nparameters; ++i) 00177 fModel -> GetMarginalized(fModel -> GetParameter(i)) -> GetHistogram() -> Write(); 00178 00179 if (nparameters > 1) 00180 for (int i = 0; i < nparameters - 1; ++i) 00181 for (int j = i + 1; j < nparameters; ++j) 00182 fModel -> GetMarginalized(fModel -> GetParameter(i), 00183 fModel -> GetParameter(j)) -> GetHistogram() -> Write(); 00184 00185 // return to old directory 00186 gDirectory = dir; 00187 }
void BCModelOutput::WriteErrorBand | ( | ) |
Writes the error band histogram into the TFile.
Definition at line 190 of file BCModelOutput.cxx.
00191 { 00192 if(!fOutputFile) 00193 { 00194 BCLog::OutError("BCModelOutput::WriteErrorBand : No file to write to."); 00195 return; 00196 } 00197 00198 // remember current directory 00199 TDirectory * dir = gDirectory; 00200 00201 // change to file 00202 fOutputFile -> cd(); 00203 00204 TH2D * h0 = fModel -> GetErrorBandXY(); 00205 if (h0) 00206 { 00207 TH2D * h1 = (TH2D*)h0 -> Clone("errorbandxy"); 00208 h1 -> Write(); 00209 00210 double levels[] = { .68, .90, .95 }; 00211 int nlevels = sizeof(levels)/sizeof(double); 00212 for (int i=0;i<nlevels;i++) 00213 { 00214 TH2D * htmp = fModel -> GetErrorBandXY_yellow(levels[i]); 00215 htmp -> SetName(TString::Format("%s_sub_%f.2",h1->GetName(),levels[i])); 00216 htmp -> Write(); 00217 delete htmp; 00218 } 00219 00220 delete h1; 00221 } 00222 00223 // return to old directory 00224 gDirectory = dir; 00225 }
void BCModelOutput::Write | ( | TObject * | o | ) |
Writes any object derived from TObject to TFile.
Definition at line 228 of file BCModelOutput.cxx.
00229 { 00230 if(!fOutputFile) 00231 { 00232 BCLog::OutError("BCModelOutput::Write : No file to write to."); 00233 return; 00234 } 00235 00236 // remember current directory 00237 TDirectory * dir = gDirectory; 00238 00239 // change to file 00240 fOutputFile -> cd(); 00241 00242 o -> Write(); 00243 00244 // return to old directory 00245 gDirectory = dir; 00246 }
void BCModelOutput::Close | ( | ) |
Closes the TFile.
Definition at line 249 of file BCModelOutput.cxx.
00250 { 00251 // remember current directory 00252 TDirectory * dir = gDirectory; 00253 00254 // change to file 00255 fOutputFile -> cd(); 00256 00257 // write analysis tree to file 00258 if (fAnalysisTree -> GetEntries() > 0) 00259 fAnalysisTree -> Write(); 00260 00261 // write markov chain tree to file 00262 for (int i = 0; i < fModel -> MCMCGetNChains(); ++i) 00263 if (fMarkovChainTrees[i] -> GetEntries() > 0) 00264 fMarkovChainTrees[i] -> Write(); 00265 00266 // write SA tree to file 00267 if (fTreeSA -> GetEntries() > 0) 00268 fTreeSA -> Write(); 00269 00270 // close file 00271 fOutputFile -> Close(); 00272 00273 // return to old directory 00274 gDirectory = dir; 00275 }
void BCModelOutput::Init | ( | ) | [private] |
Initialize the variables
Definition at line 67 of file BCModelOutput.cxx.
00068 { 00069 fIndex = 0; 00070 fOutputFile = 0; 00071 fAnalysisTree = 0; 00072 fTreeSA = 0; 00073 fModel = 0; 00074 fFileName = 0; 00075 }
void BCModelOutput::Copy | ( | BCModelOutput & | modeloutput | ) | const [private] |
Definition at line 361 of file BCModelOutput.cxx.
00362 { 00363 // don't copy the content 00364 modeloutput.fModel = this -> fModel; 00365 modeloutput.fAnalysisTree = this -> fAnalysisTree; 00366 modeloutput.fMarkovChainTrees = this -> fMarkovChainTrees; 00367 }
void BCModelOutput::InitializeAnalysisTree | ( | ) | [private] |
Initialize the output TTree.
Definition at line 278 of file BCModelOutput.cxx.
00279 { 00280 // create new tree 00281 fAnalysisTree = new TTree("AnalysisTree", "AnalysisTree"); 00282 00283 // set branch addresses 00284 fAnalysisTree -> Branch("fIndex", &fIndex, "index/I"); 00285 fAnalysisTree -> Branch("fNParameters", &fNParameters, "parameters/I"); 00286 fAnalysisTree -> Branch("fProbability_apriori" , &fProbability_apriori, "apriori probability/D"); 00287 fAnalysisTree -> Branch("fProbability_aposteriori", &fProbability_aposteriori, "aposteriori probability/D"); 00288 fAnalysisTree -> Branch("fMode_global", fMode_global, "mode (global) [parameters]/D"); 00289 fAnalysisTree -> Branch("fMode_marginalized", fMode_marginalized, "mode (marginalized) [parameters]/D"); 00290 fAnalysisTree -> Branch("fMean_marginalized", fMean_marginalized, "mean (marginalized)[parameters]/D"); 00291 fAnalysisTree -> Branch("fMedian_marginalized", fMedian_marginalized, "median (marginalized)[parameters]/D"); 00292 fAnalysisTree -> Branch("fQuantile_05" , fQuantile_05, "quantile 5% [parameters]/D"); 00293 fAnalysisTree -> Branch("fQuantile_10" , fQuantile_10, "quantile 10% [parameters]/D"); 00294 fAnalysisTree -> Branch("fQuantile_16" , fQuantile_16, "quantile 16% [parameters]/D"); 00295 fAnalysisTree -> Branch("fQuantile_84" , fQuantile_84, "quantile 84% [parameters]/D"); 00296 fAnalysisTree -> Branch("fQuantile_90" , fQuantile_90, "quantile 90% [parameters]/D"); 00297 fAnalysisTree -> Branch("fQuantile_95" , fQuantile_95, "quantile 95% [parameters]/D"); 00298 }
void BCModelOutput::InitializeMarkovChainTrees | ( | ) | [private] |
Initialize the Markov Chain TTree.
Definition at line 301 of file BCModelOutput.cxx.
00302 { 00303 // create new tree 00304 fMarkovChainTrees.clear(); 00305 for (int i = 0; i < fModel -> MCMCGetNChains(); ++i) 00306 { 00307 TTree * tree = new TTree(TString::Format("MarkovChainTree_%i", i), "MarkovChainTree"); 00308 fMarkovChainTrees.push_back(tree); 00309 } 00310 00311 // connect pointer to parameter vectors 00312 fParameters = fModel -> MCMCGetP2x(); 00313 fIteration = fModel -> MCMCGetP2NIterations(); 00314 fLogLikelihood = fModel -> MCMCGetP2LogProbx(); 00315 fNParameters = fModel -> MCMCGetNParameters(); 00316 00317 for (int i = 0; i < fModel -> MCMCGetNChains(); ++i) 00318 { 00319 fMarkovChainTrees[i] -> Branch("fIteration", &(*fIteration)[i], "iteration/I"); 00320 fMarkovChainTrees[i] -> Branch("fNParameters", &fNParameters, "parameters/I"); 00321 fMarkovChainTrees[i] -> Branch("fLogLikelihood", &(*fLogLikelihood)[i], "log (likelihood)/D"); 00322 } 00323 00324 // loop over all parameters 00325 for (int i = 0; i < fModel -> MCMCGetNChains(); ++i) 00326 for (int j = 0; j < fModel -> MCMCGetNParameters(); ++j) 00327 { 00328 fMarkovChainTrees[i] -> Branch(TString::Format("fParameter%i", j), 00329 &(*fParameters)[i * fModel -> MCMCGetNParameters() + j], 00330 TString::Format("parameter %i/D", j)); 00331 } 00332 00333 fModel -> MCMCSetMarkovChainTrees(fMarkovChainTrees); 00334 }
void BCModelOutput::InitializeSATree | ( | ) | [private] |
Initialize SA TTree.
Definition at line 337 of file BCModelOutput.cxx.
00338 { 00339 fTreeSA = new TTree("SATree", "SATree"); 00340 00341 // connect pointer to parameter vectors 00342 fSAIteration = fModel -> GetSAP2NIterations(); 00343 fSATemperature = fModel -> GetSAP2Temperature(); 00344 fSALogProb = fModel -> GetSAP2LogProb(); 00345 fSAParameters = fModel -> GetSAP2x(); 00346 fSANParameters = fModel -> GetNParameters(); 00347 00348 fTreeSA -> Branch("Iteration", fSAIteration, "iteration/I"); 00349 fTreeSA -> Branch("NParameters", &fSANParameters, "parameters/I"); 00350 fTreeSA -> Branch("Temperature", fSATemperature, "temperature/D"); 00351 fTreeSA -> Branch("LogProb", fSALogProb, "log probability/D"); 00352 for (int j = 0; j < fModel -> MCMCGetNParameters(); ++j) 00353 fTreeSA -> Branch(TString::Format("Parameter%i", j), 00354 &(*fSAParameters)[j], 00355 TString::Format("parameter %i/D", j)); 00356 00357 fModel -> SetSATree(fTreeSA); 00358 }
TTree* BCModelOutput::fAnalysisTree [private] |
Pointer to the TTree containing the summary output information.
Definition at line 162 of file BCModelOutput.h.
std::vector<TTree *> BCModelOutput::fMarkovChainTrees [private] |
Definition at line 167 of file BCModelOutput.h.
TTree* BCModelOutput::fTreeSA [private] |
Definition at line 171 of file BCModelOutput.h.
char* BCModelOutput::fFileName [private] |
The output filename
Definition at line 175 of file BCModelOutput.h.
TFile* BCModelOutput::fOutputFile [private] |
Pointer to the output TFile.
Definition at line 179 of file BCModelOutput.h.
BCModel* BCModelOutput::fModel [private] |
Pointer to the model this output class is assigned to
Definition at line 183 of file BCModelOutput.h.
int BCModelOutput::fIndex [private] |
The analysis tree variables
Definition at line 187 of file BCModelOutput.h.
unsigned int BCModelOutput::fNParameters [private] |
Definition at line 188 of file BCModelOutput.h.
double BCModelOutput::fProbability_apriori [private] |
Definition at line 189 of file BCModelOutput.h.
double BCModelOutput::fProbability_aposteriori [private] |
Definition at line 190 of file BCModelOutput.h.
double BCModelOutput::fMode_global[MAXNPARAMETERS] [private] |
Definition at line 191 of file BCModelOutput.h.
double BCModelOutput::fMode_marginalized[MAXNPARAMETERS] [private] |
Definition at line 192 of file BCModelOutput.h.
double BCModelOutput::fMean_marginalized[MAXNPARAMETERS] [private] |
Definition at line 193 of file BCModelOutput.h.
double BCModelOutput::fMedian_marginalized[MAXNPARAMETERS] [private] |
Definition at line 194 of file BCModelOutput.h.
double BCModelOutput::fQuantile_05[MAXNPARAMETERS] [private] |
Definition at line 195 of file BCModelOutput.h.
double BCModelOutput::fQuantile_10[MAXNPARAMETERS] [private] |
Definition at line 196 of file BCModelOutput.h.
double BCModelOutput::fQuantile_16[MAXNPARAMETERS] [private] |
Definition at line 197 of file BCModelOutput.h.
double BCModelOutput::fQuantile_84[MAXNPARAMETERS] [private] |
Definition at line 198 of file BCModelOutput.h.
double BCModelOutput::fQuantile_90[MAXNPARAMETERS] [private] |
Definition at line 199 of file BCModelOutput.h.
double BCModelOutput::fQuantile_95[MAXNPARAMETERS] [private] |
Definition at line 200 of file BCModelOutput.h.
std::vector<double>* BCModelOutput::fParameters [private] |
The markov chain tree variables
Definition at line 204 of file BCModelOutput.h.
std::vector<double>* BCModelOutput::fLogLikelihood [private] |
Definition at line 205 of file BCModelOutput.h.
std::vector<int>* BCModelOutput::fIteration [private] |
Definition at line 206 of file BCModelOutput.h.
int* BCModelOutput::fSAIteration [private] |
The simulated annealing tree variables
Definition at line 210 of file BCModelOutput.h.
int BCModelOutput::fSANParameters [private] |
Definition at line 211 of file BCModelOutput.h.
double* BCModelOutput::fSATemperature [private] |
Definition at line 212 of file BCModelOutput.h.
double* BCModelOutput::fSALogProb [private] |
Definition at line 213 of file BCModelOutput.h.
std::vector<double>* BCModelOutput::fSAParameters [private] |
Definition at line 214 of file BCModelOutput.h.