PredictionWriter.cxx
Go to the documentation of this file.
2 #include "TMath.h"
3 
4 namespace ana
5 {
7  : fPredFileName(filename)
8  {
9  // Open prediction file for reading and writing
10  // Create if it doesn't exist
11  fPredFile = new TFile(filename, mode);
12  }
13 
15  {
16  // Delete pointer to prediction root file
17  delete fPredFile;
18  fPredFile = NULL;
19  }
20 
22  const IPrediction* prediction,
23  const TString &analysisName,
24  const TString &systName,
25  const int &sigma, const bool &extrap,
26  const TString &energyVar,
27  const TString &weight)
28  {
29  // Make analysis directory
30  TDirectory* analysisDir = fPredFile->GetDirectory(analysisName);
31  if (!analysisDir) // make directory
32  {
33  std::cout << "Making directory " << analysisName << std::endl;
34  analysisDir = fPredFile->mkdir(analysisName);
35  }
36 
37  // Make syst directory
38  TDirectory* systDir = analysisDir->GetDirectory(systName);
39  if (!systDir) // make directory
40  {
41  std::cout << "Making directory " << systName << std::endl;
42  systDir = analysisDir->mkdir(systName);
43  }
44 
45  // Get shift name from sigma and make directory
46  const TString shiftName = GetShiftName(sigma);
47  TDirectory* shiftDir = systDir->GetDirectory(shiftName);
48  if (!shiftDir) // make directory
49  {
50  std::cout << "Making directory " << shiftName << std::endl;
51  shiftDir = systDir->mkdir(shiftName);
52  }
53 
54  // Get inner directory name and make directory
55  TString directoryName = MakeDirectoryName(
56  analysisName, extrap, energyVar, weight);
57  std::cout << "[PredictionWriter::WritePrediction] writing to "
58  << directoryName << std::endl;
59  prediction->SaveTo(shiftDir->mkdir(directoryName));
60  }
61 
63  const TString &analysisName,
64  const TString &systName,
65  const int &sigma, const bool &extrap,
66  const TString &energyVar,
67  const TString &weight)
68  {
69  // Get shift name from sigma
70  const TString shiftName = this->GetShiftName(sigma);
71 
72  TString directory = analysisName + "/" + systName + "/" + shiftName + "/";
73  TString directoryName = this->MakeDirectoryName(
74  analysisName, extrap, energyVar, weight);
75  directory += directoryName;
76  //TDirectory* predDir = fPredFile->GetDirectory(directory);
77 
78  std::cout << "[PredictionWriter::ReadPrediction] reading from "
79  << directory << std::endl;
80  return directory;
81  }
82 
84  const TString &analysisName,
85  const bool &extrap,
86  const TString &energyVar,
87  const TString &weight)
88  {
89  TString directory = analysisName + "_";
90  if (extrap)
91  directory += "extrap_";
92  else
93  directory += "no_extrap_";
94  directory += energyVar + "_";
95  directory += weight;
96 
97  return directory;
98  }
99 
100  const TString PredictionWriter::GetShiftName(const int sigma)
101  {
102  TString shiftName;
103 
104  // Deal with nominal first
105  if (sigma == 0)
106  {
107  shiftName = "NoShift";
108  return shiftName;
109  }
110 
111  // Then deal with -ve shifts
112  if (sigma < 0)
113  shiftName = "minus";
114  else // sigma > 0 --> already dealt with 0
115  shiftName = "plus";
116 
117  if (abs(sigma) == 1)
118  shiftName = shiftName + "One";
119  else if (abs(sigma) == 2)
120  shiftName = shiftName + "Two";
121  else if (abs(sigma) == 3)
122  shiftName = shiftName + "Three";
123  else
124  throw "Out of range. Only valid for |sigma| >= 3.";
125 
126  return shiftName;
127  }
128 }
const TString GetShiftName(const int sigma)
Oscillation analysis framework, runs over CAF files outside of ART.
virtual void SaveTo(TDirectory *dir) const
const Var weight
TFile * fPredFile
ROOT file to which we write/read predictions.
string directory
projection from multiple chains
string filename
Definition: shutoffs.py:106
float abs(float number)
Definition: d0nt_math.hpp:39
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")
OStream cout
Definition: OStream.cxx:6
PredictionWriter(TString filename, TString mode="RECREATE")
const TString ReadPrediction(const TString &analysisName, const TString &systName, const int &sigma, const bool &extrap=true, const TString &energyVar="EnergyCVN2D", const TString &weight="kXSecCVWgt2017")
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
const TString MakeDirectoryName(const TString &analysisName, const bool &extrap, const TString &energyVar, const TString &weight)