PredictionWriter.cxx
Go to the documentation of this file.
2 
3 #include "TMath.h"
4 
5 #include <iostream>
6 
7 namespace ana
8 {
10  : fPredFileName(filename)
11  {
12  // Open prediction file for reading and writing
13  // Create if it doesn't exist
14  fPredFile = new TFile(filename, mode);
15  }
16 
18  {
19  // Delete pointer to prediction root file
20  delete fPredFile;
21  fPredFile = NULL;
22  }
23 
25  const IPrediction* prediction,
26  const TString &analysisName,
27  const TString &systName,
28  const int &sigma, const bool &extrap,
29  const TString &energyVar,
30  const TString &weight)
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  }
64 
66  const TString &analysisName,
67  const TString &systName,
68  const int &sigma, const bool &extrap,
69  const TString &energyVar,
70  const TString &weight)
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  }
85 
87  const TString &analysisName,
88  const bool &extrap,
89  const TString &energyVar,
90  const TString &weight)
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  }
102 
103  const TString PredictionWriter::GetShiftName(const int sigma)
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  }
131 }
const TString GetShiftName(const int sigma)
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var weight
TFile * fPredFile
ROOT file to which we write/read predictions.
string directory
projection from multiple chains
void abs(TH1 *hist)
string filename
Definition: shutoffs.py:106
virtual void SaveTo(TDirectory *dir, const std::string &name) const
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")
double sigma(TH1F *hist, double percentile)
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)