makeFlatWeight.C
Go to the documentation of this file.
1 // I found that the energy estimator used by the nuebar oscillation analysis
2 // was not sufficient for this analysis due to training on a sample of
3 // neutrinos with energy less than 4.5 GeV.
4 //
5 // This script marks the first piece of training a new estimator.
6 // Following docdb-26696, we need to normalize the true energy distribution
7 // to avoid biasing the energy estimation toward our peak beam energy.
8 //
9 // Grab true energy distributions
10 // dddoyle@colostate.edu
11 
12 #include "CAFAna/Core/Spectrum.h"
13 
14 #include "TH1D.h"
15 #include "TVectorD.h"
16 
20 
21 using namespace ana;
22 
24 {
25  TFile* fTrueENominal = TFile::Open("/nova/ana/users/ddoyle/NuebarEnergyEstimatorFiles/flat_weight_energy_spectra.root");
26  Spectrum* sTrueENominal = Spectrum::LoadFrom(fTrueENominal, "trueE")).release(;
27  fTrueENominal->Close();
28 
29  double POT = sTrueENominal->POT();
30 
31  TH1D* hTrueEFlat = sTrueENominal->ToTH1(POT);
32  double width = hTrueEFlat->GetBinWidth(1);
33  // This weight is calculated by dividing the number of events in each bin
34  // bin the total number of events
35  // Get average of the bin contents
36  double sum = 0;
37  for(int i = 1; i < hTrueEFlat->GetNbinsX() + 1; i++) {
38  sum += hTrueEFlat->GetBinContent(i);
39  }
40  double avg = sum / hTrueEFlat->GetNbinsX();
41 
43  for(int i = 1; i < hTrueEFlat->GetNbinsX() + 1; i++) {
44  hTrueEFlat->SetBinContent(i, avg / hTrueEFlat->GetBinContent(i));
45  std::cout << hTrueEFlat->GetBinContent(i) << ", ";
46  }
48 
49  TFile* fout = new TFile("fFlatWeightNDSig.root", "recreate");
50  hTrueEFlat->Write("hFlatWeightNDSig");
51 
52  fout->Close();
53  std::cout << "bin width = " << width << std::endl;
54 }
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
Definition: Spectrum.cxx:148
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:535
void makeFlatWeight()
double POT() const
Definition: Spectrum.h:227
OStream cout
Definition: OStream.cxx:6
std::vector< double > POT
Double_t sum
Definition: plot.C:31