Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
ana::TwoSampleDecomp Class Reference

Class for data driven decomposition of signal and background using two different samples with slightly different spectra. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-25/CAFAna/Decomp/TwoSampleDecomp.h"

Inheritance diagram for ana::TwoSampleDecomp:
ana::IDecomp

Public Member Functions

 TwoSampleDecomp (SpectrumLoaderBase &loaderMC, SpectrumLoaderBase &loaderData, std::string label, const Binning &bins, const Var &var, const Cut &firstSample, const Cut &isSignal=kNoCut, const Cut &anaCut=kNoCut, const SystShifts &shift=kNoShift, const Var &weight=kUnweighted)
 Constructor for creating spectra from a SpectrumLoader. Must supply cuts to define samples, first or second. For instance first: left side, second: right side. Also must define cut to specefiy signal/background. Analysis cuts are optional, but likely necessary. More...
 
 TwoSampleDecomp (SpectrumLoaderBase &loaderMC, SpectrumLoaderBase &loaderData, const HistAxis &axis, const Cut &firstSample, const Cut &isSignal=kNoCut, const Cut &anaCut=kNoCut, const SystShifts &shift=kNoShift, const Var &weight=kUnweighted)
 
virtual ~TwoSampleDecomp ()
 
virtual Spectrum NCTotalComponent () const override
 Returns the decomposed NC component. More...
 
virtual Spectrum NCComponent () const override
 
virtual Spectrum NCAntiComponent () const override
 
virtual Spectrum NumuComponent () const override
 Returns the decomposed numu CC component. More...
 
virtual Spectrum NueComponent () const override
 Could return the nue CC component, but not implemented for two sample decomposition. More...
 
virtual Spectrum AntiNumuComponent () const override
 
virtual Spectrum AntiNueComponent () const override
 
void Decomp () const
 Preform the decomposition using the ratios in the MC sample. More...
 
void RatioCalc () const
 Calculate the ratios for the signal and background, second/first. More...
 
void SaveTo (TDirectory *dir, const std::string &name) const override
 
void DrawSigBkgOverlay ()
 
void DrawTwoSamplesWithRatios ()
 
void DrawRatios ()
 
virtual Spectrum Data_Component () const
 
virtual Spectrum MC_NCTotalComponent () const
 
virtual Spectrum MC_NCComponent () const
 
virtual Spectrum MC_NCAntiComponent () const
 
virtual Spectrum MC_NumuComponent () const
 
virtual Spectrum MC_AntiNumuComponent () const
 
virtual Spectrum MC_NueComponent () const
 
virtual Spectrum MC_AntiNueComponent () const
 

Static Public Member Functions

static std::unique_ptr< TwoSampleDecompLoadFrom (TDirectory *dir, const std::string &name)
 

Public Attributes

const SpectrumLoaderBasefLoaderMC
 
const SpectrumLoaderBasefLoaderData
 
const HistAxisfAxis
 Axis used for spectra. More...
 
Spectrum fFirstSig
 Spectrum for first sample, signal. More...
 
Spectrum fSecondSig
 Spectrum for second sample, signal. More...
 
Spectrum fFirstBkg
 Spectrum for first sample, background. More...
 
Spectrum fSecondBkg
 Spectrum for second sample, background. More...
 
Spectrum fTrueSig
 True signal spectrum. More...
 
Spectrum fTrueBkg
 True backgroundh spectrum. More...
 
Spectrum fFirst
 Spectrum of events that pass the firstSample cut. More...
 
Spectrum fSecond
 Spectrum of events that fail the firstSample cut. More...
 
Spectrum fSig
 Decomposed spectrum of signal events. More...
 
Spectrum fBkg
 Decomposed spectrum of signal events. More...
 
TH1D * fSigRatio
 Ratio of second/first spectra for signal. More...
 
TH1D * fBkgRatio
 Ratio of second/first spectra for bkg. More...
 
bool fDecomposed
 Indicates whether decomposition was done. More...
 

Protected Member Functions

 TwoSampleDecomp ()
 

Detailed Description

Class for data driven decomposition of signal and background using two different samples with slightly different spectra.

Definition at line 21 of file TwoSampleDecomp.h.

Constructor & Destructor Documentation

ana::TwoSampleDecomp::TwoSampleDecomp ( SpectrumLoaderBase loaderMC,
SpectrumLoaderBase loaderData,
std::string  label,
const Binning bins,
const Var var,
const Cut firstSample,
const Cut isSignal = kNoCut,
const Cut anaCut = kNoCut,
const SystShifts shift = kNoShift,
const Var weight = kUnweighted 
)

Constructor for creating spectra from a SpectrumLoader. Must supply cuts to define samples, first or second. For instance first: left side, second: right side. Also must define cut to specefiy signal/background. Analysis cuts are optional, but likely necessary.

Detailed description starts here.

Parameters
loaderMCSpectrum loader for MC
loaderDataSpectrum loader for data
labelName of the thing
binsDesired binning for spectra
varVariable to be plotted in spectra
firstSampleCut to define samples, true: first, false: second
isSignalSignal or not? true: sig, false: bkg
anaCutCut to define selection(e.g. numu CC)
weightWeight for events in spectrum

Definition at line 24 of file TwoSampleDecomp.cxx.

36  :TwoSampleDecomp(loaderMC, loaderData, HistAxis(label, bins, var),
37  firstSample, isSignal, anaCut, shift, weight)
38  {}
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
const Var weight
const char * label
const Binning bins
Definition: NumuCC_CPiBin.h:8
ana::TwoSampleDecomp::TwoSampleDecomp ( SpectrumLoaderBase loaderMC,
SpectrumLoaderBase loaderData,
const HistAxis axis,
const Cut firstSample,
const Cut isSignal = kNoCut,
const Cut anaCut = kNoCut,
const SystShifts shift = kNoShift,
const Var weight = kUnweighted 
)
Parameters
loaderMCSpectrum loader for MC
loaderDataSpectrum loader for data
axisVariable to be plotted in spectra
firstSampleCut to define samples, true: first, false: second
isSignalSignal or not? true: sig, false: bkg
anaCutCut to define selection(e.g. numu CC)
weightWeight for events in spectrum

Definition at line 42 of file TwoSampleDecomp.cxx.

References om::cout, allTimeWatchdog::endl, and ana::LabelsAndBins::NDimensions().

52  :
53  fLoaderMC (loaderMC),
54  fLoaderData(loaderData),
55  fAxis(&axis),
56  fFirstSig (loaderMC, axis, firstSample && isSignal && anaCut,
57  shift, weight),
58  fSecondSig(loaderMC, axis, !firstSample && isSignal && anaCut,
59  shift, weight),
60  fFirstBkg (loaderMC, axis, firstSample && !isSignal && anaCut,
61  shift, weight),
62  fSecondBkg(loaderMC, axis, !firstSample && !isSignal && anaCut,
63  shift, weight),
64  fTrueSig (loaderMC, axis, isSignal && anaCut,
65  shift, weight),
66  fTrueBkg (loaderMC, axis, !isSignal && anaCut,
67  shift, weight),
68  fFirst (loaderData, axis, firstSample && anaCut,
69  shift, weight),
70  fSecond (loaderData, axis, !firstSample && anaCut,
71  shift, weight),
74  fSigRatio (0),
75  fBkgRatio (0),
76  fDecomposed(false)
77  {
78  if(axis.NDimensions() != 1){
79  std::cout << "Error: TwoSampleDecomp not equipped to handle multi-dimensional axis." << std::endl;
80  abort();
81  }
82  }
Spectrum fSig
Decomposed spectrum of signal events.
Spectrum fBkg
Decomposed spectrum of signal events.
const Var weight
Spectrum fTrueSig
True signal spectrum.
TH1D * fBkgRatio
Ratio of second/first spectra for bkg.
Spectrum fFirstSig
Spectrum for first sample, signal.
bool fDecomposed
Indicates whether decomposition was done.
Spectrum fSecondSig
Spectrum for second sample, signal.
TH1D * fSigRatio
Ratio of second/first spectra for signal.
static Spectrum Uninitialized()
Definition: Spectrum.h:145
const SpectrumLoaderBase & fLoaderData
Spectrum fFirst
Spectrum of events that pass the firstSample cut.
const HistAxis * fAxis
Axis used for spectra.
Spectrum fTrueBkg
True backgroundh spectrum.
OStream cout
Definition: OStream.cxx:6
const SpectrumLoaderBase & fLoaderMC
Spectrum fSecond
Spectrum of events that fail the firstSample cut.
Spectrum fFirstBkg
Spectrum for first sample, background.
Spectrum fSecondBkg
Spectrum for second sample, background.
virtual ana::TwoSampleDecomp::~TwoSampleDecomp ( )
inlinevirtual

Definition at line 57 of file TwoSampleDecomp.h.

57 {};
ana::TwoSampleDecomp::TwoSampleDecomp ( )
protected

Definition at line 86 of file TwoSampleDecomp.cxx.

86  :
99  fSigRatio (0),
100  fBkgRatio (0),
101  fDecomposed(false)
102  { }
Spectrum fSig
Decomposed spectrum of signal events.
Spectrum fBkg
Decomposed spectrum of signal events.
Spectrum fTrueSig
True signal spectrum.
TH1D * fBkgRatio
Ratio of second/first spectra for bkg.
Spectrum fFirstSig
Spectrum for first sample, signal.
bool fDecomposed
Indicates whether decomposition was done.
Spectrum fSecondSig
Spectrum for second sample, signal.
TH1D * fSigRatio
Ratio of second/first spectra for signal.
static Spectrum Uninitialized()
Definition: Spectrum.h:145
const SpectrumLoaderBase & fLoaderData
Spectrum fFirst
Spectrum of events that pass the firstSample cut.
Spectrum fTrueBkg
True backgroundh spectrum.
const SpectrumLoaderBase & fLoaderMC
Spectrum fSecond
Spectrum of events that fail the firstSample cut.
Spectrum fFirstBkg
Spectrum for first sample, background.
Spectrum fSecondBkg
Spectrum for second sample, background.
static NullLoader kNullLoader
Dummy loader that doesn&#39;t load any files.

Member Function Documentation

virtual Spectrum ana::TwoSampleDecomp::AntiNueComponent ( ) const
inlineoverridevirtual

Implements ana::IDecomp.

Definition at line 75 of file TwoSampleDecomp.h.

References Decomp(), dir, DrawRatios(), DrawSigBkgOverlay(), DrawTwoSamplesWithRatios(), fBkg, LoadFrom(), RatioCalc(), SaveTo(), and string.

75 {Decomp(); return fBkg;}
Spectrum fBkg
Decomposed spectrum of signal events.
void Decomp() const
Preform the decomposition using the ratios in the MC sample.
virtual Spectrum ana::TwoSampleDecomp::AntiNumuComponent ( ) const
inlineoverridevirtual

Implements ana::IDecomp.

Definition at line 74 of file TwoSampleDecomp.h.

References Decomp(), and fBkg.

74 {Decomp(); return fBkg;}
Spectrum fBkg
Decomposed spectrum of signal events.
void Decomp() const
Preform the decomposition using the ratios in the MC sample.
Spectrum ana::IDecomp::Data_Component ( ) const
virtualinherited

Reimplemented in ana::BENDecomp, ana::MichelDecomp, ana::FluxDecomp, ana::ProportionalDecomp, ana::FakeDecomp, ana::NumuDecomp, ana::NueDecomp, and ana::NCDecomp.

Definition at line 16 of file IDecomp.cxx.

References om::cout, and allTimeWatchdog::endl.

Referenced by ana::GetNDComponents(), ana::GetNDCompsFromDecomp(), ana::GetNDDecompsFromDecomp(), and ana::IDecomp::NCTotalComponent().

17  {
18  std::cout<<"IDecomp::Data_Componet() is not implemented for this class, check your Decomp"<<std::endl;
19  abort();
20  }
OStream cout
Definition: OStream.cxx:6
void ana::TwoSampleDecomp::Decomp ( ) const

Preform the decomposition using the ratios in the MC sample.

Definition at line 160 of file TwoSampleDecomp.cxx.

References ana::assert(), fBkg, fBkgRatio, fDecomposed, fFirst, fLoaderData, fLoaderMC, fSecond, fSig, fSigRatio, ana::Spectrum::GetBinnings(), ana::Spectrum::GetLabels(), ana::SpectrumLoaderBase::Gone(), MECModelEnuComparisons::i, ana::Spectrum::Livetime(), plotROC::nBins, ana::Spectrum::POT(), RatioCalc(), util::sqr(), std::sqrt(), string, plotROC::title, and ana::Spectrum::ToTH1().

Referenced by AntiNueComponent(), AntiNumuComponent(), DrawSigBkgOverlay(), DrawTwoSamplesWithRatios(), NCTotalComponent(), NueComponent(), and NumuComponent().

160  {
161  if(fDecomposed) return;
162 
164  && "Call Go() on MC SpectrumLoader before TwoSampleDecomp::Decomp");
166  && "Call Go() on Data SpectrumLoader before TwoSampleDecomp::Decomp");
167 
168  RatioCalc();
169 
170  TH1D* hFirst = fFirst.ToTH1(fFirst.POT());
171  TH1D* hSecond = fSecond.ToTH1(fSecond.POT());
172 
173  // Get the number of bins from the axis
174  int nBins = hFirst->GetNbinsX();
175 
176  // Make sure the histogram binning is sane
177  assert(hFirst->GetNbinsX() == nBins &&
178  "Inconsistent binning across spectra.");
179  assert(hSecond->GetNbinsX() == nBins &&
180  "Inconsistent binning across spectra.");
181  assert(fSigRatio->GetNbinsX() == nBins &&
182  "MC and data have different numbers of bins.");
183  assert(fBkgRatio->GetNbinsX() == nBins &&
184  "MC and data have different numbers of bins.");
185 
186  std::stringstream title;
187  title << std::string(";") << hFirst->GetXaxis()->GetTitle()
188  << std::string(";Events");
189 
190 
191  float axisMin = hFirst->GetBinLowEdge(1);
192  float axisMax = hFirst->GetBinLowEdge(nBins+1);
193 
194  TH1D* hSig = new TH1D("Sig", title.str().c_str(), nBins, axisMin, axisMax);
195  TH1D* hBkg = new TH1D("Bkg", title.str().c_str(), nBins, axisMin, axisMax);
196 
197  for(int i = 1; i <= nBins; ++i)
198  {
199  //These guys are what we're after, signal and background. Initialize them.
200  double nSig = 0;
201  double nBkg = 0;
202  double errSig = 0;
203  double errBkg = 0;
204 
205 
206  // Grab all of the things out of the histograms and store them so that
207  // the math looks a bit nicer.
208  double rSig = fSigRatio->GetBinContent(i);
209  double rSigErr = fSigRatio->GetBinError(i);
210  double rBkg = fBkgRatio->GetBinContent(i);
211  double rBkgErr = fBkgRatio->GetBinError(i);
212  double nFirst = hFirst->GetBinContent(i);
213  double nSecond = hSecond->GetBinContent(i);
214 
215  // d2 is the square of the determinant of the matrix we're inverting.
216  // It shows up in the math a lot, so we'll store it for neatness.
217  double d2 = util::sqr(rSig - rBkg);
218 
219 
220  //We're about to divide by d2 until the cows come home, so make sure it's
221  //not zero. When it is zero, it's probably because those bins were empty.
222  if (d2 != 0)
223  {
224 
225  //Do the math in a way that stores the common terms in the error formula
226  double sSig = (1+rSig);
227  double sBkg = (1+rBkg);
228  nSig = sSig * (nSecond - rBkg*nFirst) / (rSig - rBkg);
229  nBkg = sBkg * (nFirst*rSig - nSecond) / (rSig - rBkg);
230 
231  // Here's the error formula
232  errSig = sqrt((nSecond * util::sqr(sSig))/d2 +
233  (nFirst*util::sqr(sSig) *util::sqr(rBkg))/d2 +
234  util::sqr(rSigErr) * (-((sSig*(nSecond - nFirst*rBkg))/d2) +
235  util::sqr(nSecond - nFirst*rBkg)/(rSig - rBkg)) +
236  util::sqr(-((nFirst*(sSig))/(rSig - rBkg)) +
237  (sSig*(nSecond - nFirst*rBkg))/d2) * util::sqr(rBkgErr));
238  errBkg = sqrt((nSecond * util::sqr(sBkg))/d2 +
239  (nFirst*util::sqr(rSig) * util::sqr(sBkg))/d2 +
240  util::sqr(rSigErr)*util::sqr(-(((-nSecond + nFirst*rSig)*sBkg)/
241  (rSig - rBkg)*2) +
242  (nFirst*sBkg)/(rSig - rBkg)) +
243  util::sqr((-nSecond + nFirst*rSig)/(rSig - rBkg) +
244  ((-nSecond + nFirst*rSig) *sBkg)/d2)*util::sqr(rBkgErr));
245  }
246 
247  // Set the values in the resultant histograms, signal and background.
248  hSig->SetBinContent(i, nSig);
249  hBkg->SetBinContent(i, nBkg);
250  hSig->SetBinError(i, errSig);
251  hBkg->SetBinError(i, errBkg);
252  }
253 
254  fSig = Spectrum(Eigen::ArrayXd(Eigen::Map<Eigen::ArrayXd>(hSig->GetArray(), hSig->GetNbinsX()+2)),
256  fFirst.POT(), fFirst.Livetime());
257  fBkg = Spectrum(Eigen::ArrayXd(Eigen::Map<Eigen::ArrayXd>(hBkg->GetArray(), hBkg->GetNbinsX()+2)),
259  fFirst.POT(), fFirst.Livetime());
260 
261  fDecomposed = true;
262  }
Spectrum fSig
Decomposed spectrum of signal events.
Spectrum fBkg
Decomposed spectrum of signal events.
const std::vector< Binning > & GetBinnings() const
Definition: Spectrum.h:264
int nBins
Definition: plotROC.py:16
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
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
T sqrt(T number)
Definition: d0nt_math.hpp:156
TH1D * fBkgRatio
Ratio of second/first spectra for bkg.
bool fDecomposed
Indicates whether decomposition was done.
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
TH1D * fSigRatio
Ratio of second/first spectra for signal.
const SpectrumLoaderBase & fLoaderData
Spectrum fFirst
Spectrum of events that pass the firstSample cut.
std::vector< float > Spectrum
Definition: Constants.h:610
double POT() const
Definition: Spectrum.h:227
const SpectrumLoaderBase & fLoaderMC
assert(nhit_max >=nhit_nbins)
void RatioCalc() const
Calculate the ratios for the signal and background, second/first.
Spectrum fSecond
Spectrum of events that fail the firstSample cut.
const std::vector< std::string > & GetLabels() const
Definition: Spectrum.h:263
virtual bool Gone() const
Indicate whether or not Go has been called.
double Livetime() const
Seconds. For informational purposes only. No calculations use this.
Definition: Spectrum.h:230
enum BeamMode string
void ana::TwoSampleDecomp::DrawRatios ( )

Definition at line 408 of file TwoSampleDecomp.cxx.

References fBkgRatio, and fSigRatio.

Referenced by AntiNueComponent(), and runTwoSampleDecomp().

409  {
410  fSigRatio->Draw("");
411  fBkgRatio->SetLineStyle(2);
412  fBkgRatio->Draw("same");
413  }
TH1D * fBkgRatio
Ratio of second/first spectra for bkg.
TH1D * fSigRatio
Ratio of second/first spectra for signal.
void ana::TwoSampleDecomp::DrawSigBkgOverlay ( )

Definition at line 333 of file TwoSampleDecomp.cxx.

References Decomp(), fBkg, fFirst, fSecond, fSig, fTrueBkg, fTrueSig, kBlue, kGreen, kRed, ana::Spectrum::POT(), and ana::Spectrum::ToTH1().

Referenced by AntiNueComponent(), and runTwoSampleDecomp().

334  {
335  Decomp();
336 
338 
339  TH1D* hData = data.ToTH1(data.POT());
340  hData->Draw();
341 
342  TH1D* hSig = fSig.ToTH1(data.POT());
343  TH1D* hBkg = fBkg.ToTH1(data.POT());
344 
345  hSig->SetLineColor(kGreen+2);
346  hBkg->SetLineColor(kBlue-4);
347  hSig->SetMarkerColor(kGreen+2);
348  hBkg->SetMarkerColor(kBlue-4);
349 
350  hSig->Draw("same");
351  hBkg->Draw("same");
352 
353 
354  TH1D* hTrueSig = fTrueSig.ToTH1(data.POT());
355  TH1D* hTrueBkg = fTrueBkg.ToTH1(data.POT());
356 
357  hTrueSig->SetLineColor(kGreen+2);
358  hTrueBkg->SetLineColor(kBlue-4);
359 
360  hTrueSig->Draw("hist same");
361  hTrueBkg->Draw("hist same");
362 
363  TH1D* hTrueTotal = (fTrueSig + fTrueBkg).ToTH1(data.POT());
364 
365  hTrueTotal->SetLineColor(kRed);
366  hTrueTotal->Draw("hist same");
367 
368 
369  }
Spectrum fSig
Decomposed spectrum of signal events.
Spectrum fBkg
Decomposed spectrum of signal events.
enum BeamMode kRed
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
Spectrum fTrueSig
True signal spectrum.
const XML_Char const XML_Char * data
Definition: expat.h:268
void Decomp() const
Preform the decomposition using the ratios in the MC sample.
Spectrum fFirst
Spectrum of events that pass the firstSample cut.
Spectrum fTrueBkg
True backgroundh spectrum.
std::vector< float > Spectrum
Definition: Constants.h:610
Spectrum fSecond
Spectrum of events that fail the firstSample cut.
enum BeamMode kGreen
enum BeamMode kBlue
void ana::TwoSampleDecomp::DrawTwoSamplesWithRatios ( )

Definition at line 372 of file TwoSampleDecomp.cxx.

References Decomp(), fFirst, fFirstBkg, fFirstSig, fSecondBkg, fSecondSig, make_syst_table_plots::h, hists, kBlue, kRed, m, cet::sqlite::max(), ana::Spectrum::POT(), and ana::Spectrum::ToTH1().

Referenced by AntiNueComponent(), and runTwoSampleDecomp().

373  {
374  Decomp();
375 
376  TH1D* hFirstSig = fFirstSig.ToTH1(fFirst.POT());
377  TH1D* hSecondSig = fSecondSig.ToTH1(fFirst.POT());
378  TH1D* hFirstBkg = fFirstBkg.ToTH1(fFirst.POT());
379  TH1D* hSecondBkg = fSecondBkg.ToTH1(fFirst.POT());
380 
381 
382  std::vector<TH1D*> hists = {hFirstSig, hSecondSig, hFirstBkg, hSecondBkg};
383 
384  float max = 0;
385  for(const auto& h:hists){
386  float m = h->GetBinContent(h->GetMaximumBin());
387  if(m > max) max = m;
388  }
389 
390  for(const auto& h:hists) h->SetMaximum(1.2*max);
391 
392  hFirstSig->SetLineColor(kRed);
393  hSecondSig->SetLineColor(kBlue-4);
394  hFirstBkg->SetLineColor(kRed);
395  hSecondBkg->SetLineColor(kBlue-4);
396 
397  hFirstBkg->SetLineStyle(2);
398  hSecondBkg->SetLineStyle(2);
399 
400  hFirstSig->Draw("hist");
401  hSecondSig->Draw("hist same");
402  hFirstBkg->Draw("hist same");
403  hSecondBkg->Draw("hist same");
404 
405 
406  }
enum BeamMode kRed
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
Spectrum fFirstSig
Spectrum for first sample, signal.
TString hists[nhists]
Definition: bdt_com.C:3
Spectrum fSecondSig
Spectrum for second sample, signal.
void Decomp() const
Preform the decomposition using the ratios in the MC sample.
Spectrum fFirst
Spectrum of events that pass the firstSample cut.
double POT() const
Definition: Spectrum.h:227
Spectrum fFirstBkg
Spectrum for first sample, background.
Spectrum fSecondBkg
Spectrum for second sample, background.
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
enum BeamMode kBlue
std::unique_ptr< TwoSampleDecomp > ana::TwoSampleDecomp::LoadFrom ( TDirectory *  dir,
const std::string name 
)
static

Definition at line 133 of file TwoSampleDecomp.cxx.

References ana::assert(), dir, ana::Spectrum::LoadFrom(), and runNovaSAM::ret.

Referenced by AntiNueComponent().

134  {
135  dir = dir->GetDirectory(name.c_str()); // switch to subdir
136  assert(dir);
137 
138  std::unique_ptr<TwoSampleDecomp> ret(new TwoSampleDecomp);
139 
140  ret->fFirstSig = *Spectrum::LoadFrom(dir, "FirstSig");
141  ret->fSecondSig = *Spectrum::LoadFrom(dir, "SecondSig");
142  ret->fFirstBkg = *Spectrum::LoadFrom(dir, "FirstBkg");
143  ret->fSecondBkg = *Spectrum::LoadFrom(dir, "SecondBkg");
144  ret->fTrueSig = *Spectrum::LoadFrom(dir, "TrueSig");
145  ret->fTrueBkg = *Spectrum::LoadFrom(dir, "TrueBkg");
146  ret->fFirst = *Spectrum::LoadFrom(dir, "First");
147  ret->fSecond = *Spectrum::LoadFrom(dir, "Second");
148  ret->fSig = *Spectrum::LoadFrom(dir, "Sig");
149  ret->fBkg = *Spectrum::LoadFrom(dir, "Bkg");
150 
151  delete dir;
152 
153  return ret;
154  }
const XML_Char * name
Definition: expat.h:151
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:535
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
Spectrum ana::IDecomp::MC_AntiNueComponent ( ) const
virtualinherited

Reimplemented in ana::BENDecomp, ana::MichelDecomp, ana::FluxDecomp, ana::ProportionalDecomp, and ana::NumuDecomp.

Definition at line 46 of file IDecomp.cxx.

References om::cout, and allTimeWatchdog::endl.

Referenced by ana::GetNDCompsFromDecomp(), and ana::IDecomp::NCTotalComponent().

47  {
48  std::cout << "IDecomp: not implemented" << std::endl; abort();
49  }
OStream cout
Definition: OStream.cxx:6
Spectrum ana::IDecomp::MC_AntiNumuComponent ( ) const
virtualinherited

Reimplemented in ana::BENDecomp, ana::MichelDecomp, ana::FluxDecomp, ana::ProportionalDecomp, and ana::NumuDecomp.

Definition at line 38 of file IDecomp.cxx.

References om::cout, and allTimeWatchdog::endl.

Referenced by ana::GetNDCompsFromDecomp(), and ana::IDecomp::NCTotalComponent().

39  {
40  std::cout << "IDecomp: not implemented" << std::endl; abort();
41  }
OStream cout
Definition: OStream.cxx:6
Spectrum ana::IDecomp::MC_NCAntiComponent ( ) const
virtualinherited

Reimplemented in ana::MichelDecomp, ana::FluxDecomp, and ana::ProportionalDecomp.

Definition at line 30 of file IDecomp.cxx.

References om::cout, and allTimeWatchdog::endl.

Referenced by ana::IDecomp::NCTotalComponent().

31  {
32  std::cout << "IDecomp: not implemented" << std::endl; abort();
33  }
OStream cout
Definition: OStream.cxx:6
Spectrum ana::IDecomp::MC_NCComponent ( ) const
virtualinherited

Reimplemented in ana::MichelDecomp, ana::FluxDecomp, and ana::ProportionalDecomp.

Definition at line 26 of file IDecomp.cxx.

References om::cout, and allTimeWatchdog::endl.

Referenced by ana::IDecomp::NCTotalComponent().

27  {
28  std::cout << "IDecomp: not implemented" << std::endl; abort();
29  }
OStream cout
Definition: OStream.cxx:6
Spectrum ana::IDecomp::MC_NCTotalComponent ( ) const
virtualinherited

Reimplemented in ana::BENDecomp, ana::MichelDecomp, ana::FluxDecomp, ana::ProportionalDecomp, and ana::NumuDecomp.

Definition at line 22 of file IDecomp.cxx.

References om::cout, and allTimeWatchdog::endl.

Referenced by ana::GetNDCompsFromDecomp(), and ana::IDecomp::NCTotalComponent().

23  {
24  std::cout << "IDecomp: not implemented" << std::endl; abort();
25  }
OStream cout
Definition: OStream.cxx:6
Spectrum ana::IDecomp::MC_NueComponent ( ) const
virtualinherited

Reimplemented in ana::BENDecomp, ana::MichelDecomp, ana::FluxDecomp, ana::ProportionalDecomp, and ana::NumuDecomp.

Definition at line 42 of file IDecomp.cxx.

References om::cout, and allTimeWatchdog::endl.

Referenced by ana::GetNDCompsFromDecomp(), and ana::IDecomp::NCTotalComponent().

43  {
44  std::cout << "IDecomp: not implemented" << std::endl; abort();
45  }
OStream cout
Definition: OStream.cxx:6
Spectrum ana::IDecomp::MC_NumuComponent ( ) const
virtualinherited

Reimplemented in ana::BENDecomp, ana::MichelDecomp, ana::FluxDecomp, ana::ProportionalDecomp, and ana::NumuDecomp.

Definition at line 34 of file IDecomp.cxx.

References om::cout, and allTimeWatchdog::endl.

Referenced by ana::GetNDCompsFromDecomp(), and ana::IDecomp::NCTotalComponent().

35  {
36  std::cout << "IDecomp: not implemented" << std::endl; abort();
37  }
OStream cout
Definition: OStream.cxx:6
Spectrum ana::TwoSampleDecomp::NCAntiComponent ( ) const
overridevirtual

Implements ana::IDecomp.

Definition at line 158 of file TwoSampleDecomp.cxx.

References om::cout, and allTimeWatchdog::endl.

Referenced by NCTotalComponent().

158 {std::cout << "TwoSampleDecomp::NCAntiComponent() not implemented" << std::endl; abort();}
OStream cout
Definition: OStream.cxx:6
Spectrum ana::TwoSampleDecomp::NCComponent ( ) const
overridevirtual

Implements ana::IDecomp.

Definition at line 156 of file TwoSampleDecomp.cxx.

References om::cout, and allTimeWatchdog::endl.

Referenced by NCTotalComponent().

156 {std::cout << "TwoSampleDecomp::NCComponent() not implemented" << std::endl; abort();}
OStream cout
Definition: OStream.cxx:6
virtual Spectrum ana::TwoSampleDecomp::NCTotalComponent ( ) const
inlineoverridevirtual

Returns the decomposed NC component.

Reimplemented from ana::IDecomp.

Definition at line 62 of file TwoSampleDecomp.h.

References Decomp(), fBkg, NCAntiComponent(), and NCComponent().

62 {Decomp(); return fBkg;};
Spectrum fBkg
Decomposed spectrum of signal events.
void Decomp() const
Preform the decomposition using the ratios in the MC sample.
virtual Spectrum ana::TwoSampleDecomp::NueComponent ( ) const
inlineoverridevirtual

Could return the nue CC component, but not implemented for two sample decomposition.

Implements ana::IDecomp.

Definition at line 72 of file TwoSampleDecomp.h.

References Decomp(), and fBkg.

72 {Decomp(); return fBkg;};
Spectrum fBkg
Decomposed spectrum of signal events.
void Decomp() const
Preform the decomposition using the ratios in the MC sample.
virtual Spectrum ana::TwoSampleDecomp::NumuComponent ( ) const
inlineoverridevirtual

Returns the decomposed numu CC component.

Implements ana::IDecomp.

Definition at line 68 of file TwoSampleDecomp.h.

References Decomp(), and fSig.

68 {Decomp(); return fSig;};
Spectrum fSig
Decomposed spectrum of signal events.
void Decomp() const
Preform the decomposition using the ratios in the MC sample.
void ana::TwoSampleDecomp::RatioCalc ( ) const

Calculate the ratios for the signal and background, second/first.

Definition at line 266 of file TwoSampleDecomp.cxx.

References ana::assert(), ana::bins, fAxis, fBkgRatio, fFirstBkg, fFirstSig, fSecondBkg, fSecondSig, fSigRatio, ana::LabelsAndBins::GetBinnings(), MECModelEnuComparisons::i, plotROC::nBins, ana::Spectrum::POT(), string, plotROC::title, and ana::Spectrum::ToTH1().

Referenced by AntiNueComponent(), and Decomp().

267  {
268 
269 
270  // Check to make sure we haven't already computed ratios
271  // histogram pointers should be null
272  assert(!fSigRatio && "Ratio histograms already constructed.");
273  assert(!fBkgRatio && "Ratio histograms already constructed.");
274 
275  // Pull histograms out of the required Spectrum object
276  TH1D* hFirstSig = fFirstSig .ToTH1(fFirstSig.POT());
277  TH1D* hSecondSig = fSecondSig.ToTH1(fSecondSig.POT());
278  TH1D* hFirstBkg = fFirstBkg .ToTH1(fFirstBkg.POT());
279  TH1D* hSecondBkg = fSecondBkg.ToTH1(fSecondBkg.POT());
280 
281  // Make the axis labels for the ratio histograms out of the
282  std::stringstream title;
283  title << std::string(";") << hFirstSig->GetXaxis()->GetTitle()
284  << std::string(";Ratio");
285 
286  // Get the number of bins from the axis
287  int nBins = hFirstSig->GetNbinsX();
288 
289  // Make sure the histogram binning is sane
290  assert(hFirstSig->GetNbinsX() == nBins &&
291  "Inconsistent binning across spectra.");
292  assert(hSecondSig->GetNbinsX() == nBins &&
293  "Inconsistent binning across spectra.");
294  assert(hFirstBkg->GetNbinsX() == nBins &&
295  "Inconsistent binning across spectra.");
296  assert(hSecondBkg->GetNbinsX() == nBins &&
297  "Inconsistent binning across spectra.");
298 
299  const Binning bins = fAxis->GetBinnings()[0];
300 
301  // Construct the ratio histogram objects
302  fSigRatio = new TH1D("SigRatio", title.str().c_str(), nBins,
303  bins.Min(), bins.Max());
304  fBkgRatio = new TH1D("BkgRatio", title.str().c_str(), nBins,
305  bins.Min(), bins.Max());
306 
307 
308  // Loop over the bins in the histograms to compute the ratios bin-by-bin
309  for (int i = 1; i <= nBins; ++i)
310  {
311  // Ratios for signal
312  if(hFirstSig->GetBinContent(i) != 0 and hSecondSig->GetBinContent(i) != 0)
313  {
314  // if non zero, make an object that does the math
315  RatioError ratioError(hSecondSig->GetBinContent(i),
316  hFirstSig->GetBinContent(i));
317  // Set the bins
318  fSigRatio->SetBinContent(i, ratioError.fRatio);
319  fSigRatio->SetBinError (i, ratioError.fError);
320  }
321  // Repeat for background
322  if(hFirstBkg->GetBinContent(i) != 0 and hSecondBkg->GetBinContent(i) != 0)
323  {
324  RatioError ratioError(hSecondBkg->GetBinContent(i),
325  hFirstBkg->GetBinContent(i));
326  fBkgRatio->SetBinContent(i, ratioError.fRatio);
327  fBkgRatio->SetBinError (i, ratioError.fError);
328  }
329  }
330  }
int nBins
Definition: plotROC.py:16
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
TH1D * fBkgRatio
Ratio of second/first spectra for bkg.
Spectrum fFirstSig
Spectrum for first sample, signal.
Spectrum fSecondSig
Spectrum for second sample, signal.
TH1D * fSigRatio
Ratio of second/first spectra for signal.
const HistAxis * fAxis
Axis used for spectra.
double POT() const
Definition: Spectrum.h:227
const std::vector< Binning > & GetBinnings() const
Definition: LabelsAndBins.h:69
const Binning bins
Definition: NumuCC_CPiBin.h:8
assert(nhit_max >=nhit_nbins)
Spectrum fFirstBkg
Spectrum for first sample, background.
Spectrum fSecondBkg
Spectrum for second sample, background.
enum BeamMode string
void ana::TwoSampleDecomp::SaveTo ( TDirectory *  dir,
const std::string name 
) const
overridevirtual

Implements ana::IDecomp.

Definition at line 106 of file TwoSampleDecomp.cxx.

References dir, fBkg, fFirst, fFirstBkg, fFirstSig, fSecond, fSecondBkg, fSecondSig, fSig, fTrueBkg, fTrueSig, ana::Spectrum::SaveTo(), and tmp.

Referenced by AntiNueComponent(), and runTwoSampleDecomp().

107  {
108  TDirectory* tmp = gDirectory;
109 
110  dir = dir->mkdir(name.c_str()); // switch to subdir
111  dir->cd();
112 
113  TObjString("TwoSampleDecomp").Write("type");
114 
115  fFirstSig.SaveTo(dir, "FirstSig");
116  fSecondSig.SaveTo(dir, "SecondSig");
117  fFirstBkg.SaveTo(dir, "FirstBkg");
118  fSecondBkg.SaveTo(dir, "SecondBkg");
119  fTrueSig.SaveTo(dir, "TrueSig");
120  fTrueBkg.SaveTo(dir, "TrueBkg");
121  fFirst.SaveTo(dir, "First");
122  fSecond.SaveTo(dir, "Second");
123  fSig.SaveTo(dir, "Sig");
124  fBkg.SaveTo(dir, "Bkg");
125 
126  dir->Write();
127  delete dir;
128 
129  tmp->cd();
130  }
Spectrum fSig
Decomposed spectrum of signal events.
Spectrum fBkg
Decomposed spectrum of signal events.
const XML_Char * name
Definition: expat.h:151
Spectrum fTrueSig
True signal spectrum.
Spectrum fFirstSig
Spectrum for first sample, signal.
Float_t tmp
Definition: plot.C:36
Spectrum fSecondSig
Spectrum for second sample, signal.
Spectrum fFirst
Spectrum of events that pass the firstSample cut.
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:506
Spectrum fTrueBkg
True backgroundh spectrum.
TDirectory * dir
Definition: macro.C:5
Spectrum fSecond
Spectrum of events that fail the firstSample cut.
Spectrum fFirstBkg
Spectrum for first sample, background.
Spectrum fSecondBkg
Spectrum for second sample, background.

Member Data Documentation

const HistAxis* ana::TwoSampleDecomp::fAxis

Axis used for spectra.

Definition at line 95 of file TwoSampleDecomp.h.

Referenced by RatioCalc().

Spectrum ana::TwoSampleDecomp::fBkg
mutable

Decomposed spectrum of signal events.

Definition at line 108 of file TwoSampleDecomp.h.

Referenced by AntiNueComponent(), AntiNumuComponent(), Decomp(), DrawSigBkgOverlay(), NCTotalComponent(), NueComponent(), and SaveTo().

TH1D* ana::TwoSampleDecomp::fBkgRatio
mutable

Ratio of second/first spectra for bkg.

Definition at line 112 of file TwoSampleDecomp.h.

Referenced by Decomp(), DrawRatios(), and RatioCalc().

bool ana::TwoSampleDecomp::fDecomposed
mutable

Indicates whether decomposition was done.

Definition at line 113 of file TwoSampleDecomp.h.

Referenced by Decomp().

Spectrum ana::TwoSampleDecomp::fFirst

Spectrum of events that pass the firstSample cut.

Definition at line 104 of file TwoSampleDecomp.h.

Referenced by Decomp(), DrawSigBkgOverlay(), DrawTwoSamplesWithRatios(), and SaveTo().

Spectrum ana::TwoSampleDecomp::fFirstBkg

Spectrum for first sample, background.

Definition at line 98 of file TwoSampleDecomp.h.

Referenced by DrawTwoSamplesWithRatios(), RatioCalc(), and SaveTo().

Spectrum ana::TwoSampleDecomp::fFirstSig

Spectrum for first sample, signal.

Definition at line 96 of file TwoSampleDecomp.h.

Referenced by DrawTwoSamplesWithRatios(), RatioCalc(), and SaveTo().

const SpectrumLoaderBase& ana::TwoSampleDecomp::fLoaderData

Definition at line 93 of file TwoSampleDecomp.h.

Referenced by Decomp().

const SpectrumLoaderBase& ana::TwoSampleDecomp::fLoaderMC

Definition at line 92 of file TwoSampleDecomp.h.

Referenced by Decomp().

Spectrum ana::TwoSampleDecomp::fSecond

Spectrum of events that fail the firstSample cut.

Definition at line 105 of file TwoSampleDecomp.h.

Referenced by Decomp(), DrawSigBkgOverlay(), and SaveTo().

Spectrum ana::TwoSampleDecomp::fSecondBkg

Spectrum for second sample, background.

Definition at line 99 of file TwoSampleDecomp.h.

Referenced by DrawTwoSamplesWithRatios(), RatioCalc(), and SaveTo().

Spectrum ana::TwoSampleDecomp::fSecondSig

Spectrum for second sample, signal.

Definition at line 97 of file TwoSampleDecomp.h.

Referenced by DrawTwoSamplesWithRatios(), RatioCalc(), and SaveTo().

Spectrum ana::TwoSampleDecomp::fSig
mutable

Decomposed spectrum of signal events.

Definition at line 107 of file TwoSampleDecomp.h.

Referenced by Decomp(), DrawSigBkgOverlay(), NumuComponent(), and SaveTo().

TH1D* ana::TwoSampleDecomp::fSigRatio
mutable

Ratio of second/first spectra for signal.

Definition at line 111 of file TwoSampleDecomp.h.

Referenced by Decomp(), DrawRatios(), and RatioCalc().

Spectrum ana::TwoSampleDecomp::fTrueBkg

True backgroundh spectrum.

Definition at line 102 of file TwoSampleDecomp.h.

Referenced by DrawSigBkgOverlay(), and SaveTo().

Spectrum ana::TwoSampleDecomp::fTrueSig

True signal spectrum.

Definition at line 101 of file TwoSampleDecomp.h.

Referenced by DrawSigBkgOverlay(), and SaveTo().


The documentation for this class was generated from the following files: