-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTSCovariance.h
111 lines (91 loc) · 3.33 KB
/
TSCovariance.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <fstream>
#include <set>
#include <string>
#include <vector>
class TFile;
class TGraphErrors;
class TH1D;
class TH2D;
namespace galleryfmwk {
class TSCovariance {
public:
TSCovariance();
virtual ~TSCovariance() {}
void SetInputFile(std::string _f) { fInputFile = _f; }
void SetOutputFile(std::string _f) { fOutputFile = _f; }
void AddWeight(std::string w);
void SetScaleFactorE(double _sf) { fScaleFactorE = _sf; }
void SetScaleFactorMu(double _sf) { fScaleFactorMu = _sf; }
void SetSeed(int _seed) { fSeed = _seed; }
int WriteSystPlots(char* filename);
void setUseCCQE(bool);
void init();
void analyze();
/**
* Container for an event sample, e.g. nue/numu/etc.
*/
class EventSample {
public:
/**
* Constructor.
*
* Note: You can optionally specify the number of systematics
* universes up front with the nweights parameter. If this isn't
* known until runtime, call Resize() later.
*
* \param _name String name for the event sample
* \param nbins Number of energy bins
* \param elo Lower limit of energy spectrum
* \param ehi Upper limit of energy spectrum
* \param nweights Number of systematics universes (see note)
*/
EventSample(std::string _name="sample", size_t nbins=25,
double elo=0, double ehi=3000, size_t nweights=0);
/** Destructor. */
~EventSample();
/**
* Get the energy spectrum as a graph with error bars representing
* the systematic uncertainty.
*/
TGraphErrors* EnuCollapsed();
/** Set the number of universes. */
void Resize(size_t nweights);
/**
* Covariance Matrix
*
* i && j = energy bins
* n = number of weights
* N^cv_i = number of events in bin i for the central value
* N^syst_i,m = number of events in bin i for the systematic
* variation in universe "m"
* E_ij = the covariance (square of the uncertainty) for
* bins i,j
* E_ij = (1/n) Sum((N^cv_i - N^syst_i,m)*(N^cv_j - N^syst_j,m), m)
*/
static TH2D* CovarianceMatrix(TH1D* nom, std::vector<TH1D*> syst);
/** Covariance matrix using internal histograms */
TH2D* CovarianceMatrix();
/** Correlation matrix: Corr[ij] = Cov[ij]/Sqrt(Cov[ii]*Cov[jj]) */
static TH2D* CorrelationMatrix(TH2D* _cov);
/** Correlation matrix using internal histograms */
TH2D* CorrelationMatrix();
std::string name; //!< String name for this event sample
TH1D* enu; //!< "Nominal" energy spectrum
std::vector<TH1D*> enu_syst; //!< Spectra for each systematic universe
protected:
TH2D* cov; //!< Cached covariance matrix
};
private:
std::string fInputFile; //!< Input file
std::string fOutputFile; //!< Output file
std::set<std::string> use_weights; //!< Weight functions to use
std::vector<EventSample*> samples; //!< Event samples
TFile* fFile; //!< File for output
double fScaleFactorE; //!< POT scaling, etc.
double fScaleFactorMu; //!< POT scaling, etc.
int fSeed; //!< Random seed for ROOT
// whether to use the ccqe energy as the variable
// if set to false, uses the lepton + proton (shower + track) energy
bool _use_ccqe;
};
} // namespace galleryfmwk