Public Member Functions | Private Attributes | List of all members
ana::PredictionWriter Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-10-28/CAFAna/Analysis/PredictionWriter.h"

Public Member Functions

 PredictionWriter (TString filename, TString mode="RECREATE")
 
 ~PredictionWriter ()
 
void WritePrediction (const IPrediction *prediction, const TString &analysisName, const TString &systName, const int &sigma, const bool &extrap=true, const TString &energyVar="EnergyCVN2D", const TString &weight="kXSecCVWgt2017")
 
const TString ReadPrediction (const TString &analysisName, const TString &systName, const int &sigma, const bool &extrap=true, const TString &energyVar="EnergyCVN2D", const TString &weight="kXSecCVWgt2017")
 
const TString GetFilename () const
 
const TString GetSystString (const int sigma) const
 
const TString MakeDirectoryName (const TString &analysisName, const bool &extrap, const TString &energyVar, const TString &weight)
 
const TString GetShiftName (const int sigma)
 
TFile * GetfPredFile ()
 

Private Attributes

const TString fPredFileName
 filename of prediction ROOT file More...
 
TFile * fPredFile
 ROOT file to which we write/read predictions. More...
 

Detailed Description

Definition at line 14 of file PredictionWriter.h.

Constructor & Destructor Documentation

ana::PredictionWriter::PredictionWriter ( TString  filename,
TString  mode = "RECREATE" 
)
explicit

Create writer

Parameters
[in]filename- ROOT file to read/write predictions
[in]mode- Mode for opening file, default is RECREATE!

Definition at line 9 of file PredictionWriter.cxx.

References fPredFile.

11  {
12  // Open prediction file for reading and writing
13  // Create if it doesn't exist
14  fPredFile = new TFile(filename, mode);
15  }
TFile * fPredFile
ROOT file to which we write/read predictions.
string filename
Definition: shutoffs.py:106
const TString fPredFileName
filename of prediction ROOT file
ana::PredictionWriter::~PredictionWriter ( )

Definition at line 17 of file PredictionWriter.cxx.

References fPredFile.

18  {
19  // Delete pointer to prediction root file
20  delete fPredFile;
21  fPredFile = NULL;
22  }
TFile * fPredFile
ROOT file to which we write/read predictions.

Member Function Documentation

const TString ana::PredictionWriter::GetFilename ( ) const
inline
Parameters
[out]filename- Filename of prediction ROOT file

Definition at line 71 of file PredictionWriter.h.

References fPredFileName, GetShiftName(), GetSystString(), MakeDirectoryName(), and ana::weight.

Referenced by plot_nue_xsec_pred().

71 { return fPredFileName; };
const TString fPredFileName
filename of prediction ROOT file
TFile* ana::PredictionWriter::GetfPredFile ( )
inline
Parameters
[out]fPredFile- ROOT (TFile) to which we read/write predictions

Definition at line 97 of file PredictionWriter.h.

References fPredFile, and fPredFileName.

97 { return fPredFile; };
TFile * fPredFile
ROOT file to which we write/read predictions.
const TString ana::PredictionWriter::GetShiftName ( const int  sigma)

Definition at line 103 of file PredictionWriter.cxx.

References abs().

Referenced by GetFilename(), ReadPrediction(), and WritePrediction().

104  {
105  TString shiftName;
106 
107  // Deal with nominal first
108  if (sigma == 0)
109  {
110  shiftName = "NoShift";
111  return shiftName;
112  }
113 
114  // Then deal with -ve shifts
115  if (sigma < 0)
116  shiftName = "minus";
117  else // sigma > 0 --> already dealt with 0
118  shiftName = "plus";
119 
120  if (abs(sigma) == 1)
121  shiftName = shiftName + "One";
122  else if (abs(sigma) == 2)
123  shiftName = shiftName + "Two";
124  else if (abs(sigma) == 3)
125  shiftName = shiftName + "Three";
126  else
127  throw "Out of range. Only valid for |sigma| >= 3.";
128 
129  return shiftName;
130  }
void abs(TH1 *hist)
double sigma(TH1F *hist, double percentile)
const TString ana::PredictionWriter::GetSystString ( const int  sigma) const

Convert number of sigma to shiftName string

Parameters
[in]sigma- Integer to specify number of sigma
[out]shiftName- String describing the shift

Referenced by GetFilename().

const TString ana::PredictionWriter::MakeDirectoryName ( const TString &  analysisName,
const bool &  extrap,
const TString &  energyVar,
const TString &  weight 
)

Get string for directory name

Parameters
[in]analysisName- Name of analysis including prediction type (string)
[in]extrap- Set to true if writing extrap predictions
[in]energyVar- Energy variable used for prediction (string)
[in]weight- Name of weight applied (string)

Definition at line 86 of file PredictionWriter.cxx.

References test_ViewGoogleCharts::directory, and ana::weight.

Referenced by GetFilename(), ReadPrediction(), and WritePrediction().

91  {
92  TString directory = analysisName + "_";
93  if (extrap)
94  directory += "extrap_";
95  else
96  directory += "no_extrap_";
97  directory += energyVar + "_";
98  directory += weight;
99 
100  return directory;
101  }
const Var weight
string directory
projection from multiple chains
const TString ana::PredictionWriter::ReadPrediction ( const TString &  analysisName,
const TString &  systName,
const int sigma,
const bool &  extrap = true,
const TString &  energyVar = "EnergyCVN2D",
const TString &  weight = "kXSecCVWgt2017" 
)

Method to read a single prediction from prediction ROOT file.

Since we have written the predictions to the prediction ROOT file using a unified structure and naming conventions, we can now retrieve prediction objects easily from within that structure, for plotting

Parameters
[in]analysisName- Name of analysis including prediction type (string)
[in]systName- Name of systematic (string)
[in]sigma- Number of sigma (int)
[in]extrap- Set to true if writing extrap predictions
[in]energyVar- Energy variable used for prediction (string)
[in]weight- Name of weight applied (string)
[out]predDir- TString for directory

Definition at line 65 of file PredictionWriter.cxx.

References om::cout, test_ViewGoogleCharts::directory, allTimeWatchdog::endl, GetShiftName(), and MakeDirectoryName().

Referenced by make_nue_xsec_pred(), and plot_nue_xsec_pred().

71  {
72  // Get shift name from sigma
73  const TString shiftName = this->GetShiftName(sigma);
74 
75  TString directory = analysisName + "/" + systName + "/" + shiftName + "/";
76  TString directoryName = this->MakeDirectoryName(
77  analysisName, extrap, energyVar, weight);
78  directory += directoryName;
79  //TDirectory* predDir = fPredFile->GetDirectory(directory);
80 
81  std::cout << "[PredictionWriter::ReadPrediction] reading from "
82  << directory << std::endl;
83  return directory;
84  }
const TString GetShiftName(const int sigma)
const Var weight
string directory
projection from multiple chains
double sigma(TH1F *hist, double percentile)
OStream cout
Definition: OStream.cxx:6
const TString MakeDirectoryName(const TString &analysisName, const bool &extrap, const TString &energyVar, const TString &weight)
void ana::PredictionWriter::WritePrediction ( const IPrediction prediction,
const TString &  analysisName,
const TString &  systName,
const int sigma,
const bool &  extrap = true,
const TString &  energyVar = "EnergyCVN2D",
const TString &  weight = "kXSecCVWgt2017" 
)

Method to write a single prediction to prediction ROOT file.

Ensures all predictions are written to an output file, using the same directory structure and naming conventions. This ensures we can combine systematic root files together, in a single file and, that we can easily load predictions from the root file, for plotting.

Parameters
[in]prediction- Prediction object to write to file
[in]analysisName- Name of analysis including prediction type (string)
[in]systName- Name of systematic (string)
[in]sigma- Number of sigma (int)
[in]extrap- Set to true if writing extrap predictions
[in]energyVar- Energy variable used for prediction (string)
[in]weight- Name of weight applied (string)

Definition at line 24 of file PredictionWriter.cxx.

References om::cout, allTimeWatchdog::endl, fPredFile, GetShiftName(), MakeDirectoryName(), and ana::IPrediction::SaveTo().

Referenced by make_nue_xsec_pred().

31  {
32  // Make analysis directory
33  TDirectory* analysisDir = fPredFile->GetDirectory(analysisName);
34  if (!analysisDir) // make directory
35  {
36  std::cout << "Making directory " << analysisName << std::endl;
37  analysisDir = fPredFile->mkdir(analysisName);
38  }
39 
40  // Make syst directory
41  TDirectory* systDir = analysisDir->GetDirectory(systName);
42  if (!systDir) // make directory
43  {
44  std::cout << "Making directory " << systName << std::endl;
45  systDir = analysisDir->mkdir(systName);
46  }
47 
48  // Get shift name from sigma and make directory
49  const TString shiftName = GetShiftName(sigma);
50  TDirectory* shiftDir = systDir->GetDirectory(shiftName);
51  if (!shiftDir) // make directory
52  {
53  std::cout << "Making directory " << shiftName << std::endl;
54  shiftDir = systDir->mkdir(shiftName);
55  }
56 
57  // Get inner directory name and make directory
58  TString directoryName = MakeDirectoryName(
59  analysisName, extrap, energyVar, weight);
60  std::cout << "[PredictionWriter::WritePrediction] writing to "
61  << directoryName << std::endl;
62  prediction->SaveTo(shiftDir, directoryName.Data());
63  }
const TString GetShiftName(const int sigma)
const Var weight
TFile * fPredFile
ROOT file to which we write/read predictions.
double sigma(TH1F *hist, double percentile)
OStream cout
Definition: OStream.cxx:6
const TString MakeDirectoryName(const TString &analysisName, const bool &extrap, const TString &energyVar, const TString &weight)

Member Data Documentation

TFile* ana::PredictionWriter::fPredFile
private

ROOT file to which we write/read predictions.

Definition at line 101 of file PredictionWriter.h.

Referenced by GetfPredFile(), PredictionWriter(), WritePrediction(), and ~PredictionWriter().

const TString ana::PredictionWriter::fPredFileName
private

filename of prediction ROOT file

Definition at line 97 of file PredictionWriter.h.

Referenced by GetFilename(), and GetfPredFile().


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