30 fBins = config.get<std::vector<double> >(
"binlims");
31 fName = config.get<std::string>(
"name",
"");
32 fScalePOT = config.get<
double>(
"ScalePOT", -1);
33 fScaleCC = config.get<
double>(
"ScaleCC", 1);
34 fScaleNC = config.get<
double>(
"ScaleNC", 1);
37 fEnergyBinScale = config.get<std::vector<double>>(
"energy_bin_scale", {});
44 std::string cv_title = fName +
" Central Value";
47 for (
unsigned var_i = 0; var_i < nVariations; var_i++) {
49 for (
unsigned i = 0; i < nUniverses; i++) {
52 new TH1D(uni_title.c_str(), uni_title.c_str(),
fBins.size() - 1, &
fBins[0])
61 std::vector <float>
GetUniWeights(
const std::map <std::string, std::vector <float> > &weights,
const std::vector<std::string> &keys,
int n_unis,
int uni_offset) {
62 std::vector <float> uweights;
63 for (
int u = 0; u < n_unis; u++) {
65 for (
auto const &key: keys) {
66 const std::vector<float>& this_weights = weights.at(key);
67 int wind = u + uni_offset;
68 weight *= this_weights.at(wind);
70 uweights.push_back(weight);
78 assert(config != NULL);
83 fhicl::ParameterSet pconfig = config->get<fhicl::ParameterSet>(
"Covariance");
85 fWeightKeys = pconfig.get<std::vector<std::vector<std::string>>>(
"WeightKey");
86 fWeightKeysCC = pconfig.get<std::vector<std::vector<std::string>>>(
"WeightKeyCC", {});
87 fWeightKeysNC = pconfig.get<std::vector<std::vector<std::string>>>(
"WeightKeyNC", {});
91 assert(fWeightKeysCC.size() == 0 || fWeightKeysCC.size() == fWeightKeys.size());
92 assert(fWeightKeysNC.size() == 0 || fWeightKeysNC.size() == fWeightKeys.size());
95 if (fWeightKeysCC.size() == 0) {
100 fWeightKeysCC[i].insert(fWeightKeysCC[i].
end(), fWeightKeys[i].
begin(), fWeightKeys[i].
end());
103 if (fWeightKeysNC.size() == 0) {
108 fWeightKeysNC[i].insert(fWeightKeysNC[i].
end(), fWeightKeys[i].
begin(), fWeightKeys[i].
end());
118 fEnergyType = pconfig.get<std::string>(
"EnergyType",
"Reco");
127 fWeightMax = pconfig.get<
double>(
"WeightMax", -1.);
130 std::vector<fhicl::ParameterSet> configEventSamples = \
131 config->get<std::vector<fhicl::ParameterSet> >(
"EventSamples");
132 for (
const fhicl::ParameterSet& sample : configEventSamples) {
137 fOutputFile = pconfig.get<std::string>(
"OutputFile",
"");
153 for (
int n = 0;
n <
event->reco.size();
n++) {
154 unsigned truth_ind =
event->reco[
n].truth_index;
157 int idx =
event->reco[
n].truth_index;
158 if (idx < 0 || idx > event->
truth.size()) {
161 double true_nuE =
event->truth[idx].neutrino.energy;
164 nuE =
event->truth[truth_ind].neutrino.eccqe;
168 nuE =
event->reco[
n].reco_energy;
173 int isCC =
event->truth[truth_ind].neutrino.iscc;
181 double wgt =
event->reco[
n].weight;
187 if (event->
truth[truth_ind].neutrino.iscc) {
194 std::vector<std::vector <float>> uweights;
213 double max_weight = 0;
214 for (std::vector<float> &weights: uweights) {
215 float this_max_weight = *std::max_element(weights.begin(), weights.end());
216 if (this_max_weight > max_weight) max_weight = this_max_weight;
229 for (
unsigned variation = 0; variation < uweights.size(); variation++) {
230 for (
int u = 0; u < uweights[variation].size(); u++) {
238 for (
int sample_i = 0; sample_i <
fEventSamples.size(); sample_i++) {
239 for (
int i = 1; i <
fEventSamples[sample_i].fCentralValue->GetNbinsX()+1; i++) {
245 for (
int variation = 0; variation <
fNVariations; variation++) {
247 for (
int i = 1; i <
fEventSamples[sample_i].fUniverses[variation][uni]->GetNbinsX(); i++) {
248 double content =
fEventSamples[sample_i].fUniverses[variation][uni]->GetBinContent(i);
271 std::cout << std::endl <<
"Getting covs..." << std::endl;
274 unsigned num_bins = 0;
276 num_bins += sample.fCentralValue->GetNbinsX();
280 std::string covariance_name =
"Covariance " +
std::to_string(variation);
281 std::string fractional_covariance_name =
"Fractional Covariance " +
std::to_string(variation);
283 cov.emplace_back(covariance_name.c_str(), covariance_name.c_str(), num_bins, 0, num_bins, num_bins, 0, num_bins);
284 fcov.emplace_back(fractional_covariance_name.c_str(), fractional_covariance_name.c_str(), num_bins, 0, num_bins, num_bins, 0, num_bins);
290 for (
auto const &sample_i: fEventSamples) {
291 for (
unsigned sample_i_bin_index = 0; sample_i_bin_index < sample_i.fCentralValue->GetNbinsX(); sample_i_bin_index++) {
293 float i_central = sample_i.fCentralValue->GetBinContent(sample_i_bin_index+1);
294 for (
auto const &sample_j: fEventSamples) {
295 for (
unsigned sample_j_bin_index = 0; sample_j_bin_index < sample_j.fCentralValue->GetNbinsX(); sample_j_bin_index++) {
297 float j_central = sample_j.fCentralValue->GetBinContent(sample_j_bin_index+1);
299 float cov_value = 0.;
302 float i_variation = sample_i.fUniverses[variation][u]->GetBinContent(sample_i_bin_index+1);
303 float j_variation = sample_j.fUniverses[variation][u]->GetBinContent(sample_j_bin_index+1);
304 cov_value += (i_central - i_variation) * (j_central - j_variation);
311 if (i_central * j_central < 1
e-6) {
315 fcov_value = cov_value / (i_central * j_central);
319 cov[variation].SetBinContent(cov_i + 1, cov_j + 1, cov_value);
320 fcov[variation].SetBinContent(cov_i + 1, cov_j + 1, fcov_value);
332 std::string correlation_name =
"Correlation " +
std::to_string(variation);
335 corr.emplace_back(correlation_name.c_str(), correlation_name.c_str(), num_bins, 0, num_bins, num_bins, 0, num_bins);
337 for (
int i = 0; i < num_bins; i++) {
338 float covii =
cov[variation].GetBinContent(i+1, i+1);
339 for (
int j = 0; j < num_bins; j++) {
340 float covjj =
cov[variation].GetBinContent(j+1, j+1);
341 float covij =
cov[variation].GetBinContent(i+1, j+1);
345 if (covii*covjj < 1
e-6) {
351 corr[variation].SetBinContent(i+1, j+1, corrij);
356 std::vector <TH2D*> hists = {&
cov[variation], &
fcov[variation], &
corr[variation]};
358 for (
auto const &sample: fEventSamples) {
360 for (TH2D* hist : hists) {
361 hist->GetXaxis()->SetBinLabel(1+bin, sample.fName.c_str());
362 hist->GetYaxis()->SetBinLabel(1+bin, sample.fName.c_str());
365 bin += sample.fBins.size() - 1;
369 for (TH2D* hist : hists) { hist->GetXaxis()->LabelsOption(
"h"); hist->GetYaxis()->LabelsOption(
"v"); }
371 std::cout << std::endl <<
" Got covs." << std::endl;
381 assert(output && output->IsOpen());
383 for (TH2D &
h:
cov)
h.Write();
384 for (TH2D &
h:
fcov)
h.Write();
385 for (TH2D &
h:
corr)
h.Write();
390 sample.fCentralValue->Write();
396 for (TH1D *
h: sample.fUniverses[i]) {
408 TMatrixDSym E_mat(
cov[0].GetNbinsX());
409 for (
int i = 0; i <
cov[0].GetNbinsX(); i++) {
410 for (
int j = 0; j <
cov[0].GetNbinsY(); j++) {
412 for (TH2D &cov_histo:
cov) E_mat[i][j] += cov_histo.GetBinContent(i+1, j+1);
415 unsigned stat_ind = i;
416 float stat_uncertainty;
419 if (stat_ind < sample.fCentralValue->GetNbinsX()) {
420 stat_uncertainty = sample.fCentralValue->GetBinContent(1+stat_ind);
423 else stat_ind -= sample.fCentralValue->GetNbinsX();
425 E_mat[i][i] += stat_uncertainty;
std::vector< TH2D > cov
Covariance Matrix per variation.
double fScalePOT
Factor for POT (etc.) scaling.
TH1D * fCentralValue
central value histogram
double fSelectionEfficiency
std::string fName
Name for the sample.
std::vector< std::vector< std::string > > fWeightKeysNC
TMatrixDSym CovarianceMatrix()
void Initialize(fhicl::ParameterSet *config)
std::vector< TH2D > fcov
Fractional Covariance Matrix per variation.
std::vector< std::vector< std::string > > fWeightKeysCC
process_name opflashCryoW ana
std::vector< std::vector< std::string > > fWeightKeys
std::vector< double > fEnergyBinScale
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
std::vector< std::vector< TH1D * > > fUniverses
List of histogram per systematic universe.
std::vector< TH2D > corr
Correlation Matrix per variation.
#define DECLARE_SBN_POSTPROCESSOR(classname)
auto end(FixedBins< T, C > const &) noexcept
The standard subrun data definition.
void GetCovPerVariation(unsigned variation)
void ProcessSubRun(const SubRun *subrun)
The standard event data definition.
auto begin(FixedBins< T, C > const &) noexcept
Var Sqrt(const Var &v)
Use to take sqrt of a var.
std::string to_string(WindowPattern const &pattern)
BEGIN_PROLOG sequence::SlidingWindowTriggerPatternsOppositeWindows END_PROLOG simSlidingORM6O6 effSlidingORW output
EventSample(const fhicl::ParameterSet &config, unsigned nUniverses, unsigned nVariations)
std::vector< EventSample > fEventSamples
double fBackgroundRejection
void FileCleanup(TTree *eventTree)
void ProcessEvent(const event::Event *event)
BEGIN_PROLOG could also be cout
std::vector< double > fBins
Energy bin limits.
std::vector< float > GetUniWeights(const std::map< std::string, std::vector< float > > &weights, const std::vector< std::string > &keys, int n_unis, int uni_offset)
std::vector< Interaction > truth
All truth interactions.