PredictionWriter.h
Go to the documentation of this file.
1 #ifndef ANA_PREDICTIONWRITER_H
2 #define ANA_PREDICTIONWRITER_H
3 
5 
6 #include "TString.h"
7 #include "TFile.h"
8 #include "TDirectory.h"
9 
10 #pragma once
11 
12 namespace ana
13 {
15  {
16  public:
17  /// Create writer
18  ///
19  /// \param[in] filename - ROOT file to read/write predictions
20  /// \param[in] mode - Mode for opening file, default is RECREATE!
21  explicit PredictionWriter(TString filename, TString mode="RECREATE");
23 
24  /// Method to write a single prediction to prediction ROOT file.
25  ///
26  /// Ensures all predictions are written to an output file, using the
27  /// same directory structure and naming conventions. This ensures we
28  /// can combine systematic root files together, in a single file and,
29  /// that we can easily load predictions from the root file, for
30  /// plotting.
31  ///
32  /// \param[in] prediction - Prediction object to write to file
33  /// \param[in] analysisName - Name of analysis including prediction
34  /// type (string)
35  /// \param[in] systName - Name of systematic (string)
36  /// \param[in] sigma - Number of sigma (int)
37  /// \param[in] extrap - Set to true if writing extrap predictions
38  /// \param[in] energyVar - Energy variable used for prediction
39  /// (string)
40  /// \param[in] weight - Name of weight applied (string)
41  void WritePrediction(const IPrediction* prediction,
42  const TString &analysisName,
43  const TString &systName,
44  const int &sigma, const bool &extrap=true,
45  const TString &energyVar="EnergyCVN2D",
46  const TString &weight="kXSecCVWgt2017");
47 
48  /// Method to read a single prediction from prediction ROOT file.
49  ///
50  /// Since we have written the predictions to the prediction ROOT
51  /// file using a unified structure and naming conventions, we can
52  /// now retrieve prediction objects easily from within that
53  /// structure, for plotting
54  ///
55  /// \param[in] analysisName - Name of analysis including prediction
56  /// type (string)
57  /// \param[in] systName - Name of systematic (string)
58  /// \param[in] sigma - Number of sigma (int)
59  /// \param[in] extrap - Set to true if writing extrap predictions
60  /// \param[in] energyVar - Energy variable used for prediction
61  /// (string)
62  /// \param[in] weight - Name of weight applied (string)
63  /// \param[out] predDir - TString for directory
64  const TString ReadPrediction(const TString &analysisName,
65  const TString &systName,
66  const int &sigma, const bool &extrap=true,
67  const TString &energyVar="EnergyCVN2D",
68  const TString &weight="kXSecCVWgt2017");
69 
70  /// \param[out] filename - Filename of prediction ROOT file
71  const TString GetFilename() const { return fPredFileName; };
72 
73  /// Convert number of sigma to shiftName string
74  ///
75  /// \param[in] sigma - Integer to specify number of sigma
76  /// \param[out] shiftName - String describing the shift
77  const TString GetSystString(const int sigma) const;
78 
79  /// Get string for directory name
80  ///
81  /// \param[in] analysisName - Name of analysis including prediction
82  /// type (string)
83  /// \param[in] extrap - Set to true if writing extrap predictions
84  /// \param[in] energyVar - Energy variable used for prediction
85  /// (string)
86  /// \param[in] weight - Name of weight applied (string)
87  const TString MakeDirectoryName(
88  const TString &analysisName,
89  const bool &extrap,
90  const TString &energyVar,
91  const TString &weight);
92 
93  const TString GetShiftName(const int sigma);
94 
95  /// \param[out] fPredFile - ROOT (TFile) to which we read/write
96  /// predictions
97  TFile* GetfPredFile() { return fPredFile; };
98 
99  private:
100  const TString fPredFileName; ///<filename of prediction ROOT file
101  TFile* fPredFile; ///<ROOT file to which we write/read predictions
102  };
103 }
104 
105 #endif
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.
const TString GetFilename() const
string filename
Definition: shutoffs.py:106
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)
const TString fPredFileName
filename of prediction ROOT file
PredictionWriter(TString filename, TString mode="RECREATE")
const TString GetSystString(const int sigma) const
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)