test_nue2018_fitter.C
Go to the documentation of this file.
1 #include "OscLib/OscCalcDumb.h"
4 
6 
7 #include "CAFAna/Core/Spectrum.h"
9 
10 #include "CAFAna/Vars/FitVars.h"
11 
17 
19 
20 #include "Utilities/func/MathUtil.h"
21 
22 #include "TCanvas.h"
23 #include "TH1.h"
24 #include "TFile.h"
25 
26 #include <iostream>
27 #include <cmath>
28 
29 using namespace ana;
30 
32 {
33  double pot = 9.48e20; // From Nitish
34 
35  std::string dirName = "./";
36 
37  double dCP = 1.5;
38  double ssth23 = 0.402;
39  double dmsq32 = 0.0027;
40 
41  // random testing calc
43 
44  kFitDeltaInPiUnits.SetValue(calc,dCP);
45  kFitDmSq32.SetValue(calc,dmsq32);
46  kFitSinSqTheta23.SetValue(calc,ssth23);
47 
48  std::vector<const IFitVar*> fitvar = {&kFitDmSq32, &kFitDeltaInPiUnits, &kFitSinSqTheta23};
49 
51  false, true, "", // isfakedata, mergePeripheral,
52  false, {}); //mini memo, summingsys
53 
54  Spectrum data = pred->Predict(calc).FakeData(pot);
55  std::string anaDir = "/nova/ana/nu_e_ana/Ana2018/Predictions/cosmic/cosmic_prediction_real_data.root";
56  Spectrum* cosmic = LoadFromFile<Spectrum>(anaDir, "cosmic_spect_fhc" ).release();
57  TH1D* hcosmic = cosmic->ToTH1( 1, kLivetime);
58  hcosmic->Reset();
59  std::cout<<"sanity check:"<<hcosmic->Integral()<<std::endl;
60  const SingleSampleExperiment* exp = new SingleSampleExperiment( pred, data, hcosmic);
61 
62  MinuitFitter fitter(exp, fitvar, {});
63  SystShifts bestSysts;
64 
65  double counter, chi;
66 
67  MinuitFitter::FitOpts prec[4] = {MinuitFitter::FitOpts::kFast, MinuitFitter::FitOpts::kNormal, MinuitFitter::FitOpts::kCareful, MinuitFitter::FitOpts::kGradDesc};
68  std::cout<<"Fake data: dcp = "<<calc->GetdCP()<<"; ssth23 = "<<calc->GetTh23()<<"; dmsq32 = "<<calc->GetDmsq32()<<std::endl;
69  std::cout<<"Starting the loop..."<<std::endl;
70 
71  for(auto& p: prec){
73  clock_t begin = clock();
74  fitter.SetFitOpts(p);
75  chi = fitter.Fit(calc, bestSysts, {}, {})->EvalMetricVal();
76  clock_t end = clock();
77  counter = (double)(end - begin)/CLOCKS_PER_SEC;
78  std::cout<<"Timer: "<<counter<<std::endl;
79  }
80 
81 }
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
void ResetOscCalcToDefault(osc::IOscCalcAdjustable *calc)
Reset calculator to default assumptions for all parameters.
Definition: Calcs.cxx:23
double ssth23
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
Loads shifted spectra from files.
const FitDmSq32 kFitDmSq32
Definition: FitVars.cxx:18
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
void SetValue(osc::IOscCalcAdjustable *osc, double val) const override
Definition: FitVars.cxx:177
const char * p
Definition: xmltok.h:285
virtual T GetTh23() const
Definition: IOscCalc.h:94
void SetValue(osc::IOscCalcAdjustable *osc, double val) const override
Forward to wrapped Var&#39;s SetValue()
osc::OscCalcDumb calc
osc::IOscCalcAdjustable * DefaultOscCalc()
Create a new calculator with default assumptions for all parameters.
Definition: Calcs.cxx:49
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const XML_Char const XML_Char * data
Definition: expat.h:268
Sum up livetimes from individual cosmic triggers.
void test_nue2018_fitter()
void SetValue(osc::IOscCalcAdjustable *osc, double val) const override
double dCP
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
#define pot
virtual T GetDmsq32() const
Definition: IOscCalc.h:91
virtual T GetdCP() const
Definition: IOscCalc.h:95
std::vector< const ISyst * > getAna2018LargeXsecSysts(const EAnaType2018 ana)
OStream cout
Definition: OStream.cxx:6
std::string dirName
Definition: PlotSpectra.h:47
double dmsq32
const ConstrainedFitVarWithPrior fitSsqTh23_UniformPriorSsqTh23 & kFitSinSqTheta23
const FitVarWithPrior fitDeltaInPiUnits_UniformPriordCP & kFitDeltaInPiUnits
Compare a single data spectrum to the MC + cosmics expectation.
Perform MINUIT fits in one or two dimensions.
Definition: MinuitFitter.h:17
enum BeamMode string