make_fc_surfaces_nersc_2018_stats.C
Go to the documentation of this file.
1 //#include <iostream>
2 #include <fstream>
3 
5 #include "CAFAna/Core/Spectrum.h"
7 
10 
13 
14 #include "CAFAna/Vars/FitVars.h"
15 
16 #include "CAFAna/FC/FCPoint.h"
17 #include "CAFAna/FC/FCCollection.h"
18 #include "CAFAna/FC/FCSurface.h"
19 
23 
25 
26 #include "CAFAna/Analysis/Calcs.h"
27 #include "OscLib/IOscCalc.h"
28 
29 #include "TRandom3.h"
30 #include "TH1.h"
31 
32 using namespace ana;
33 // Testing commit
34 // Needed for running on the OSG in a tag prior to r20638
35 
36 void SetSeeds(osc::IOscCalcAdjustable* calc, double delta, double th23, double dmsq)
37 {
39  kFitDeltaInPiUnits.SetValue(calc, delta);
40  kFitSinSqTheta23.SetValue(calc, th23);
41  kFitDmSq32.SetValue(calc, dmsq);
42 }
43 
44 void make_fc_surfaces_nersc_2018_stats(int NPts, int startidx, int endidx, bool nh,
45  int N, int jid, int npts_flush = 0,
46  std::string plot = "deltassth23" ,
47  TString beam = "both", bool corrSysts = false,
48  bool readFromFile = false)
49 {
50  assert(plot == "deltath13" || plot=="ssth23dmsq32"
51  || plot == "deltassth23" && "Plot must be ssth23dmsq32 or deltassth23");
52 
53  assert(beam == "FHCOnly" || beam == "RHCOnly" || beam == "both");
54 
55  bool RHCOnly = beam.Contains("RHCOnly");
56  bool FHCOnly = beam.Contains("FHCOnly");
57  bool both = beam.Contains("both");
58  // ssth23dmsq32 has 400 total bins while deltassth23 has 900
59  int TotBins = 0;
60  TotBins = (plot == "deltassth23") ? 900 : 400;
61  int bins[TotBins];
62  std::memset(bins, 0, TotBins);
63  std::string hier = nh? "_NH_" : "_IH_";
64 
65 
66  // If we don't want to run full corrections, we'll read from a text file which holds
67  // a list of bins to be corrected based on deltachisq in each bin. This list is
68  // generated by generate_fc_binlists.C
69 
70  for(int i = 0; i < TotBins; i++) bins[i]= i;
71 
72  /*
73  ifstream binlist;
74  std::string path = getenv("FCHELPERANA2018_LIB_PATH");
75  path += "/binlists/";
76  binlist.open(path+plot+hier+"binlist.txt");
77  int j = 0;
78  if(readFromFile){
79  do
80  {
81  binlist >> bins[j];
82  j++;
83  }while(!binlist.eof());
84  binlist.close();
85  }
86  else for (int i = 0; i < TotBins; i++) bins[i]=i; */
87 
88  int ibin = bins[startidx];
89  int fbin = bins[endidx];
90 
91  std::string binname = "bins_"+std::to_string(ibin) + "_to_" + std::to_string(fbin);
92  std::string number = std::to_string(N);
93  std::string fcout = "FCCol_"+plot+"_"+hier+"_";
94  if(both) fcout+="both";
95  else fcout += RHCOnly? "RHCOnly":"FHCOnly";
96  fcout += corrSysts? "_systs_":"_stats_";
97  fcout += binname+"_v"+number+'_'+std::to_string(jid)+".root";
98 
99  std::string hierStr = nh ? "NH" : "IH";
100 
101  FCCollection fccol;
103 
104  // Relevant exposures, to be used later
105  double thisPOT;
106  double thisLivetime;
107 
108  // bools to make the function calls a little more readable
109  bool nueOnly = true;
110  bool numuOnly = true;
111  bool isFHC = true;
112  bool isRHC = true;
113  bool NERSC = true;
114 
115  // Grab the systs
116  std::vector<const ISyst*> systs = {};
117  if(corrSysts) systs = GetJointFitSystematicList(true, !nueOnly,
118  !numuOnly, isFHC, isRHC);
119  // need to grab different systs for nue rhc and fhc
120  std::vector<const ISyst*> snue_fhc = {};
121  if(corrSysts) snue_fhc = getAllAna2018Systs(kNueAna2018, true, kFHC);
122  std::vector<const ISyst*> snue_rhc = {};
123  if(corrSysts) snue_rhc = getAllAna2018Systs(kNueAna2018, true, kRHC);
124 
125  // numu systs are independent of beam mode
126  std::vector<const ISyst*> snumu = {};
127  if(corrSysts) snumu = GetJointFitSystematicList(true, !nueOnly,
128  numuOnly,
129  isFHC,
130  isRHC);
131 
132  std::vector <const IPrediction*> nue_preds;
133  std::vector <std::pair <TH1D*, double > > nue_cosmics;
134  std::vector <Spectrum> nue_cosmics_spectra;
135 
136 
137  // We're setting up the requisite inputs to the nue experiment
138 
139  //////////////////////////////////////////////////////////////
140  // Nue Predictions
141  /////////////////////////////////////////////////////////////
142  if(!RHCOnly)
143  nue_preds.push_back(GetNuePrediction2018("combo", calc, corrSysts, "fhc",
144  false, false, true, true));
145  if(!FHCOnly)
146  nue_preds.push_back(GetNuePrediction2018("prop", calc, corrSysts, "rhc",
147  false, false, true, true));
148  std::cout << "\n------------------Done Getting nue preds ---------------------\n";
149  if(!RHCOnly){
150  nue_cosmics.push_back(GetNueCosmics2018("fhc", false, true));
151  nue_cosmics_spectra.push_back(Spectrum(nue_cosmics.back().first,
153  }
154  if(!FHCOnly) {
155  nue_cosmics.push_back(GetNueCosmics2018("rhc", false, true));
156  nue_cosmics_spectra.push_back(Spectrum(nue_cosmics.back().first,
158  }
159 
160  ///////////////////////////////////////////////////////////////
161  // Numu predictions
162  //////////////////////////////////////////////////////////////
163 
164  // Construct numu inputs
165  std::vector < const IPrediction*> numu_preds;
166  std::vector < std::pair < TH1D*, double > > numu_cosmics;
167  std::vector <Spectrum> numu_cosmics_spectra;
168 
169  std::vector <const IPrediction*> this_numu_preds;
170  std::vector <std::pair<TH1D*, double > > this_numu_cosmics;
171 
172  std::vector<std::string> beams;
173  if(!RHCOnly) beams.push_back("fhc");
174  if(!FHCOnly) beams.push_back("rhc");
175  // Collect the eight numu preds/cosmics, 4 per beam mode
176  for(std::string beam : beams ) {
177  this_numu_preds = GetNumuPredictions2018(4, corrSysts, beam, false, kNuMu, true, true);
178  this_numu_cosmics = GetNumuCosmics2018(4, beam, false, true);
179  numu_preds.insert(numu_preds.end(),
180  this_numu_preds.begin(),
181  this_numu_preds.end());
182  numu_cosmics.insert(numu_cosmics.end(),
183  this_numu_cosmics.begin(),
184  this_numu_cosmics.end());
185  // Again, FHC and RHC have different pot and livetimes so
186  // cosmic hists need to be scaled appropriately
187  for(std::pair <TH1D*, double> h : this_numu_cosmics) {
188  thisPOT = kAna2018FHCPOT;
189  thisLivetime = kAna2018FHCLivetime;
190  if(beam == "rhc") {
191  thisPOT = kAna2018RHCPOT;
192  thisLivetime = kAna2018RHCLivetime;
193  }
194  numu_cosmics_spectra.push_back(Spectrum(h.first, thisPOT, thisLivetime));
195  }
196  }
197 
198  // Grab analysis contours to find bin center
199  std::string p = ""; //delta && !corrSysts
200  if(plot == "ssth23dmsq32" && corrSysts) p = "ssth23dmsq32_";
201  if(plot == "deltassth23" && corrSysts) p = "deltassth23_";
202  if(plot == "ssth23dmsq32" && !corrSysts) p = "dmsq_";
203  if(plot == "deltath13" && !corrSysts) p = "th13_";
204 
205  std::string helperupsname = std::string(getenv("FCHELPERANA2018_LIB_PATH"));
206  TString anasurfname = helperupsname
207  + "/contours/hist_contours_2018_joint_realData_"+beam+"_only";
208  anasurfname += nh? "NHcombo_" : "IHcombo_";
209  anasurfname += p;
210  anasurfname += corrSysts? "systs.root": "stats.root";
211 
212  TFile *anasurffile = TFile::Open(anasurfname);
213  anasurffile->cd();
214  std::string plotShortName="delta_th23";
215  if(plot == "ssth23dmsq32") plotShortName = "th23_dm32";
216  if(nh) plotShortName += "_NH";
217  else plotShortName += "_IH";
218  TH2* anasurf = (TH2F*)anasurffile->Get(plotShortName.c_str());
219 
220  // Grab the FCHelper2018 file
221  //std::string helperupsname = std::string(getenv("FCHELPERANA2017_LIB_PATH"));
222  TString helpername =
223  helperupsname+"FCInput/contours_FCInput_2018_joint_realData_"+beam+"_only";
224  helpername += nh? "NHcombo_" : "IHcombo_";
225  helpername += p;
226  helpername += corrSysts? "systs.root":"stats.root";
227 
228  TFile *fchelp = TFile::Open(helpername);
229 
230  // Find the bin center for this job, probably should be arguments
231  // dCP / pi
232 
233  // The surfaces are made with ana::ExpandedHistrogram() which sets the bin edges so that
234  // the input min/max x and y fall in the center of the bins. Grab these boundaries.
235  int NX = anasurf->GetXaxis()->GetNbins();
236  int NY = anasurf->GetYaxis()->GetNbins();
237  double minX = anasurf->GetXaxis()->GetBinCenter(1); // root bins start at 1
238  double maxX = anasurf->GetXaxis()->GetBinCenter(NX);
239  double minY = anasurf->GetYaxis()->GetBinCenter(1);
240  double maxY = anasurf->GetYaxis()->GetBinCenter(NY);
241 
242  double widthX = anasurf->GetXaxis()->GetBinWidth(1);
243  double widthY = anasurf->GetYaxis()->GetBinWidth(1);
244  std::cout << "widthX = " << widthX << endl;
245  std::cout << "widthY = " << widthY << endl;
246  assert(fbin < NX*NY && "Invalid bin number");
247 
248  int bin = 0;
249  for (int i = startidx; i <= endidx; i++) {
250  bin = bins[i];
251  std::cout<<"- "<<i<<std::endl;
252  std::cout << "bin " << bin << endl;
253  // Once we run out of important bins, get out.
254  if(bins[i] == 0 && i != 0) continue;
255 
256  // bin = bins[i];
257 
258  int binY = bin/NX;
259  int binX = bin - NX*binY;
260 
261  anasurffile->cd();
262  double centerX = anasurf->GetXaxis()->GetBinCenter(binX+1);
263  double centerY = anasurf->GetYaxis()->GetBinCenter(binY+1);
264  std::cout << "centerX = " << centerX << endl;
265  std::cout << "centerY = " << centerY << endl;
266  fchelp->cd();
267 
268  // Pull out hists and get values at current bin
269  double seedssth23 = 0;
270  if(plot == "deltath13"){
271  TH2* hssth23 = (TH2F*) fchelp->Get((hierStr+"_SinSqTheta23").c_str());
272  seedssth23 = hssth23->GetBinContent(binX+1,binY+1);
273  delete hssth23;
274  }
275  double seeddmsq32 = 0;
276  if (plot == "deltassth23"){
277  TH2* hdmsq = (TH2F*)fchelp->Get((hierStr+"_DmSq32").c_str());
278  seeddmsq32 = hdmsq->GetBinContent(binX+1,binY+1); // root bins off-by-one
279  delete hdmsq;
280  }
281  double seeddelta = 0;
282  if (plot == "ssth23dmsq32"){
283  TH2* hdelta = (TH2F*)fchelp->Get((hierStr+"_DeltaCPpi").c_str());
284  seeddelta = hdelta->GetBinContent(binX+1,binY+1);
285  delete hdelta;
286  }
287  TH2* hss2th13 = (TH2F*)fchelp->Get((hierStr+"_SinSq2Theta13").c_str());
288  double seedss2th13 = hss2th13->GetBinContent(binX+1,binY+1);
289  delete hss2th13;
290 
291  // Get current syst shifts
292  std::map<std::string,double> seedsyst;
293  for (const ISyst* syst : systs){
294  TH2* h = (TH2F*)fchelp->Get((hierStr+"_"+syst->ShortName()).c_str());
295  if (!h){
296  std::cout << "Don't see a prof hist for " << syst->ShortName() << ". Continuing, but check your ups version." << std::endl;
297  continue;
298  }
299  double seedval = h->GetBinContent(binX+1,binY+1);
300  seedsyst.insert(std::pair<std::string,double>(syst->ShortName(),seedval));
301  }
302 
303  std::cout << "Parameters from anasurf " << endl;
304  std::cout << "ssth23 = " << seedssth23 << endl;
305  std::cout << "dmsq = " << seeddmsq32 << endl;
306  std::cout << "delta = " << seeddelta << endl;
307  std::cout << "th13 = " << seedss2th13 << endl;
308 
309  // Need random numbers to sample the bin
310  TRandom3 rnd(0);
311 
312  for (int i = 0; i < NPts; i++){
313  ResetOscCalcToDefault(calc);
314 
315  const IFitVar* dmsq_var;
316  if(nh) dmsq_var = &kFitDmSq32ScaledNH;
317  else dmsq_var = &kFitDmSq32ScaledIH;
318 
319  // backwards compatability
320  double trueX = centerX;
321  double trueY = centerY;
322  std::cout << "trueX: " << trueX << endl;
323  std::cout << "trueY: " << trueY << endl;
324  // Plot = deltassth23: x=delta, y=ssth23
325  // Plot = ssth23dmsq: x=ssth23, y=dmsq32
326  // Plot = deltassth13: x=th13, y=delta
327  if(plot != "deltath13"){
328  kFitDeltaInPiUnits.SetValue(calc, plot=="deltassth23"?trueX:seeddelta);
329  kFitSinSqTheta23.SetValue(calc, plot=="deltassth23"?trueY:trueX);
330  dmsq_var->SetValue(calc, plot=="deltassth23"?seeddmsq32:trueY);
331  kFitSinSq2Theta13.SetValue(calc, seedss2th13);
332  }
333  else{
334  kFitDeltaInPiUnits.SetValue(calc, trueY);
335  kFitSinSqTheta23.SetValue(calc, seedssth23);
336  dmsq_var->SetValue(calc, seeddmsq32);
337  kFitSinSq2Theta13.SetValue(calc, trueX);
338  }
339 
340  // Need to seed psuedo-experiments at profiled syst shifts read from
341  // FCInput
342  SystShifts seednue_fhc;
343  for (const ISyst *syst : snue_fhc){
344  if (seedsyst.find(syst->ShortName()) == seedsyst.end()) continue;
345  seednue_fhc.SetShift(syst,seedsyst[syst->ShortName()]);
346  }
347  SystShifts seednue_rhc;
348  for (const ISyst *syst : snue_rhc) {
349  if (seedsyst.find(syst->ShortName()) == seedsyst.end()) continue;
350  seednue_rhc.SetShift(syst, seedsyst[syst->ShortName()]);
351 
352  }
353  SystShifts seednumu;
354  for (const ISyst *syst : snumu){
355  if (seedsyst.find(syst->ShortName()) == seedsyst.end()) continue;
356  seednumu.SetShift(syst,seedsyst[syst->ShortName()]);
357  }
358 
359 
360  // Make a mock data spectrum for nue
361  // Use mock data + cosmic as predictions
362 
363  std::cout << "----------Making mock data at-----------------\n";
364  std::cout << "ssth23 = " << kFitSinSqTheta23.GetValue(calc);
365  std::cout << ", delta = " << kFitDeltaInPiUnits.GetValue(calc);
366  std::cout << ", dmsq = " << dmsq_var->GetValue(calc);
367  std::cout << ", th13 = " << kFitSinSq2Theta13.GetValue(calc);
368  std::cout << endl;
369 
370  std::vector<Spectrum> mocknue;
371  SystShifts this_seednue;
372  int mock_integral = 0;
373  for(int j = 0; j < (int) nue_preds.size(); j++) {
374  if(j == 0 && !RHCOnly){
375  this_seednue = seednue_fhc;
376  thisPOT = kAna2018FHCPOT;
377  }
378  else{
379  this_seednue = seednue_rhc;
380  thisPOT = kAna2018RHCPOT;
381  }
382  Spectrum fakenue = nue_preds[j]->Predict(calc);
383  if(corrSysts) fakenue = nue_preds[j]->PredictSyst(calc, this_seednue);
384  fakenue += nue_cosmics_spectra[j];
385  mocknue.push_back(fakenue.MockData(thisPOT));
386  // Save this for posterity's sake
387  mock_integral += mocknue[j].Integral(thisPOT);
388  }
389  std::cout << "------------Made "
390  << nue_preds.size()
391  << " mock nue data spectra ---------------\n";
392 
393  // Make a mock data spectrum for numu
394  std::vector<Spectrum> mocknumu;
395  for (int j = 0; j < (int) numu_preds.size(); j++){
396 
397  if(j < 3 && !RHCOnly)
398  thisPOT = kAna2018FHCPOT;
399  else
400  thisPOT = kAna2018RHCPOT;
401 
402  Spectrum fakenm = numu_preds[j]->Predict(calc);
403  if(corrSysts) numu_preds[j]->PredictSyst(calc,seednumu);
404  fakenm += numu_cosmics_spectra[j];
405  mocknumu.push_back(fakenm.MockData(thisPOT));
406  }
407 
408  std::cout << "------------Made "
409  << numu_preds.size()
410  << " mock numu data spectra ----------------\n";
411 
412  // Set up experiment, nova nue + nova numu + 2017 reactor
413  // Get true chi-square before fit
414 
415  //TODO experiments
416  std::vector<const IExperiment*> expts;
417  std::vector<const IExperiment*> numu_expts;
418  for(int j = 0; j < (int)nue_preds.size(); j++) {
419  expts.push_back(new SingleSampleExperiment(nue_preds[j], mocknue[j],
420  nue_cosmics[j].first,
421  nue_cosmics[j].second)); // Nue
422  }
423  for (int j = 0; j < (int)numu_preds.size(); j++) {
424  expts.push_back(new SingleSampleExperiment(numu_preds[j], mocknumu[j],
425  numu_cosmics[j].first,
426  numu_cosmics[j].second));
427  numu_expts.push_back(new SingleSampleExperiment(numu_preds[j], mocknumu[j],
428  numu_cosmics[j].first,
429  numu_cosmics[j].second));
430  }
431  if(plot != "deltath13") {
432  expts.push_back( WorldReactorConstraint2017() );
433  numu_expts.push_back( WorldReactorConstraint2017() );
434  }
435  std::cout << "Creating multiexperiment from " << expts.size() << " experiments" << endl;
436  MultiExperiment expt(expts);
437  MultiExperiment numu_expt(numu_expts);
438  // Correlate your systs
439  // TODO GetCorrelation function calls are different
440  for(int j = 0 ; j < (int)nue_preds.size(); j++){
441  if(j==0 && !RHCOnly)
442  expt.SetSystCorrelations(j, GetCorrelations(true, true)); // nue FHC
443  else
444  expt.SetSystCorrelations(j, GetCorrelations(true, false)); // nue RHC
445  auto notfornumu = GetCorrelations(false, false); // numu not dependent on beam
446  for(int j = 0; j < (int)numu_preds.size(); ++j)
447  expt.SetSystCorrelations(j+nue_preds.size(), notfornumu);
448  }
449 
450 
451  /////////////////////////////////////////////////////////////////
452  // Numu only fit to figure out dmsq seeds
453  // (may be able to do without this for contours)
454  /////////////////////////////////////////////////////////////////
455  std::cout << "Fitting numu to find pre seeds" << endl;
456 
457  double maxmixing = .514;
459  SystShifts auxShifts = SystShifts::Nominal();
460 
461  MinuitFitter fitnumu_only(&numu_expt, {&kFitSinSqTheta23, &kFitDmSq32});
462 
463  double minchi_numu = fitnumu_only.Fit(numu_calc, auxShifts,
464  {{&kFitSinSqTheta23, {0.4}},
465  {&kFitDmSq32, {nh? 2.35e-3 : -2.35e-3}}},
466  {},
467  IFitter::kQuiet)->EvalMetricVal();
468 
469  double pre_seed_dmsq = dmsq_var->GetValue(numu_calc);
470  double pre_seed_th23 = kFitSinSqTheta23.GetValue(numu_calc);
471 
472  double pre_seed_th23_LO = ( pre_seed_th23 > maxmixing ) ?
473  (2*maxmixing - pre_seed_th23) : pre_seed_th23;
474  double pre_seed_th23_UO = ( pre_seed_th23 > maxmixing ) ?
475  pre_seed_th23 : (2*maxmixing - pre_seed_th23);
476  if(pre_seed_th23_LO > .5) pre_seed_th23_LO = .45;
477 
478  std::cout << "Preseeds ---> ssth23_LO = " << pre_seed_th23_LO;
479  std::cout << "\tdmsq_NH = " << fabs(pre_seed_dmsq) << endl;
480  // done getting pre seeds
481  // --------------------------------------------------------------
482  ////////////////////////////////////////////////////////////////////
483  // True fit
484  ////////////////////////////////////////////////////////////////////
485 
486  std::vector<const IFitVar*> trueVars;
487  if (plot=="deltassth23"){
488  trueVars.push_back(dmsq_var);
489  trueVars.push_back(&kFitSinSq2Theta13);
490  }
491  if (plot=="ssth23dmsq32"){
492  trueVars.push_back(&kFitDeltaInPiUnits);
493  trueVars.push_back(&kFitSinSq2Theta13);
494  }
495 
496 
497  MinuitFitter fittrue(&expt, trueVars, systs);
498  double tb_th13 = 0;
499  double tb_dmsq = 0;
500  double tb_ssth23 = 0;
501  double tb_delta = 0;
502  SystShifts systshift = {};
503  // if not correcting deltassth23, then put one element in this
504  // vector so the following loop will run
505  std::vector <double> tf_delta_seeds = {0, .5, 1., 1.5};
506  std::vector <double> tf_ssth23_seeds = {pre_seed_th23_LO,
507  maxmixing,
508  pre_seed_th23_UO};
509 
510  // make a map of all of the seeds for the true fit
511  std::map<const IFitVar*, std::vector<double>> tf_seedPts;
512  if(plot == "deltassth23")
513  tf_seedPts = {{dmsq_var, {nh? fabs(pre_seed_dmsq) : -1*fabs(pre_seed_dmsq)}},
514  {&kFitSinSq2Theta13, {0.082}}};
515  else if(plot == "ssth23dmsq32")
516  tf_seedPts = {{&kFitDeltaInPiUnits, tf_delta_seeds},
517  {&kFitSinSq2Theta13, {0.082}}};
518  else if(plot == "deltath13")
519  tf_seedPts = {{dmsq_var, {nh? fabs(pre_seed_dmsq) : -1*fabs(pre_seed_dmsq)}},
520  {&kFitSinSqTheta23, tf_ssth23_seeds}};
521 
522  std::cout << "True fit parameters (pre fit): ssth23 = " << kFitSinSqTheta23.GetValue(calc);
523  std::cout << ", delta = " << kFitDeltaInPiUnits.GetValue(calc);
524  std::cout << ", ss2th13 = " << kFitSinSq2Theta13.GetValue(calc);
525  std::cout << ", dmsq = " << dmsq_var->GetValue(calc) << " x10^-3 eV" << endl;
526 
527 
528  std::cout << "Starting true fit --->" << endl;
529  auxShifts.ResetToNominal();
530  double trueChi = fittrue.Fit(calc,
531  auxShifts,
532  tf_seedPts,
533  {},
534  IFitter::kQuiet)->EvalMetricVal();
535 
536  // save best parameters for posterity
537  tb_delta = kFitDeltaInPiUnits.GetValue(calc);
538  tb_ssth23 = kFitSinSqTheta23.GetValue(calc);
539  tb_dmsq = dmsq_var->GetValue(calc);
540  tb_th13 = kFitSinSq2Theta13.GetValue(calc);
541 
542  std::cout << "True fit parameters (post fit): ssth23 = " << tb_ssth23;
543  std::cout << ", delta = " << tb_delta;
544  std::cout << ", ss2th13 = " << tb_th13;
545  std::cout << ", dmsq = " << tb_dmsq << " x10^-3 eV" << endl;
546 
547  // Set up best fitter
548  MinuitFitter fit(&expt,
551  systs);
552 
553  std::vector <double> bf_dmsq_seeds = {fabs(pre_seed_dmsq),
554  -1*fabs(pre_seed_dmsq)};
555  std::vector <double> bf_delta_seeds = {0., 0.5, 1., 1.5};
556  std::vector <double> bf_th23_seeds = {pre_seed_th23_LO, pre_seed_th23_UO,
557  maxmixing};
558  std::map <const IFitVar*, std::vector<double>> bf_seedPts =
559  {{&kFitDeltaInPiUnits, bf_delta_seeds},
560  {&kFitSinSqTheta23, bf_th23_seeds},
561  {&kFitSinSq2Theta13, bf_th13_seeds},
562  {&kFitDmSq32Scaled, bf_dmsq_seeds}};
563 
564  double bestdelta = 0;
565  double bestssth23 = 0;
566  double bestth13 = 0;
567  double bestdmsq = 0;
568  std::cout << "Starting best fit ----> " << endl;
569  ResetOscCalcToDefault(calc);
570  auxShifts.ResetToNominal();
571  double bestChi = fit.Fit(calc,
572  auxShifts,
573  bf_seedPts,
574  {},
575  IFitter::kQuiet)->EvalMetricVal();
576 
577  bestdelta = kFitDeltaInPiUnits.GetValue(calc);
578  bestssth23 = kFitSinSqTheta23.GetValue(calc);
579  bestth13 = kFitSinSq2Theta13.GetValue(calc);
580  bestdmsq = kFitDmSq32Scaled.GetValue(calc);
581  std::cout << "Best fit parameters: ssth23 = " << bestssth23;
582  std::cout << ", delta = " << bestdelta;
583  std::cout << ", ss2th13 = " << bestth13;
584  std::cout << ", dmsq = " << bestdmsq << " x10^-3 eV"<< endl;
585 
586 
587  // Make pseudoexperiment dst
588  // with FCPoint in its current state (r31771) the names of the branches are
589  // not correct. We want to save best fit information
590  FCPoint pt(seeddelta, seedssth23, seedss2th13, seeddmsq32,
591  pre_seed_th23, pre_seed_dmsq,
592  tb_delta, tb_ssth23, tb_th13, tb_dmsq,
593  trueChi,
594  bestdelta, bestssth23, bestth13, bestdmsq,
595  bestChi);
596 
597  fccol.AddPoint(pt);
598 
599  unsigned int nfc_pts = fccol.NPoints();
600  if(npts_flush != 0) {
601  if(nfc_pts % npts_flush == 0) {
602  std::cout << "Saving " + std::to_string(nfc_pts) + "th point to " << fcout << endl;
603  fccol.SaveToFile(fcout);
604  }
605  }
606  }
607  }// end loop over bins
608  // Save to file
609  fccol.SaveToFile(fcout);
610 }
double minY
Definition: plot_hist.C:9
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
std::vector< SystGroupDef > systs
Definition: syst_header.h:385
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
double GetValue(const osc::IOscCalcAdjustable *osc) const override
double th23
Definition: runWimpSim.h:98
double delta
Definition: runWimpSim.h:98
double GetValue(const osc::IOscCalcAdjustable *osc) const override
Forward to wrapped Var&#39;s GetValue()
const FitDmSq32 kFitDmSq32
Definition: FitVars.cxx:18
const FitDmSq32ScaledNH kFitDmSq32ScaledNH
Definition: FitVars.cxx:21
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
void SetSeeds(osc::IOscCalcAdjustable *calc, double delta, double th23, double dmsq)
const char * p
Definition: xmltok.h:285
void AddPoint(const FCPoint &p)
Definition: FCCollection.h:17
double maxY
Definition: plot_hist.C:10
void SetValue(osc::IOscCalcAdjustable *osc, double val) const override
Forward to wrapped Var&#39;s SetValue()
std::vector< const IPrediction * > GetNumuPredictions2018(const int nq=4, bool useSysts=true, std::string beam="fhc", bool GetFromUPS=false, ENu2018ExtrapType numuExtrap=kNuMu, bool minimizeMemory=false, bool NERSC=false)
void make_fc_surfaces_nersc_2018_stats(int NPts, int startidx, int endidx, bool nh, int N, int jid, int npts_flush=0, std::string plot="deltassth23", TString beam="both", bool corrSysts=false, bool readFromFile=false)
double Integral(double exposure, double *err=0, EExposureType expotype=kPOT) const
Return total number of events scaled to pot.
Definition: Spectrum.cxx:249
void SetValue(osc::IOscCalcAdjustable *osc, double val) const override
Definition: FitVars.cxx:48
static SystShifts Nominal()
Definition: SystShifts.h:34
double GetValue(const osc::IOscCalcAdjustable *osc) const override
Definition: FitVars.cxx:42
osc::OscCalcDumb calc
osc::IOscCalcAdjustable * DefaultOscCalc()
Create a new calculator with default assumptions for all parameters.
Definition: Calcs.cxx:49
Encapsulate code to systematically shift a caf::SRProxy.
Definition: ISyst.h:14
Spectrum MockData(double pot, int seed=0) const
Mock data is FakeData with Poisson fluctuations applied.
Definition: Spectrum.cxx:300
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
const double kAna2018RHCPOT
Definition: Exposures.h:208
unsigned int NPoints() const
Definition: FCCollection.h:26
Represents the results of a single Feldman-Cousins pseudo-experiment.
Definition: FCPoint.h:8
std::vector< const ISyst * > getAllAna2018Systs(const EAnaType2018 ana, const bool smallgenie, const BeamType2018 beam, bool isFit)
expt
Definition: demo5.py:34
void SetValue(osc::IOscCalcAdjustable *osc, double val) const override
std::string getenv(std::string const &name)
virtual std::unique_ptr< IFitSummary > Fit(osc::IOscCalcAdjustable *seed, SystShifts &bestSysts=junkShifts, const SeedList &seedPts=SeedList(), const std::vector< SystShifts > &systSeedPts={}, Verbosity verb=kVerbose) const
Master fitting method. Depends on FitHelper and FitHelperSeeded.
Definition: IFitter.cxx:69
const ReactorExperiment * WorldReactorConstraint2017()
Reactor constraint from PDG 2017.
const double j
Definition: BetheBloch.cxx:29
const ConstrainedFitVarWithPrior fitDmSq32Scaled_UniformPrior & kFitDmSq32Scaled
float bin[41]
Definition: plottest35.C:14
std::vector< float > Spectrum
Definition: Constants.h:610
std::vector< std::pair< TH1D *, double > > GetNumuCosmics2018(const int nq=4, std::string beam="fhc", bool GetFromUPS=false, bool NERSC=false)
static bool isFHC
OStream cout
Definition: OStream.cxx:6
const Binning bins
Definition: NumuCC_CPiBin.h:8
Combine multiple component experiments.
const FitDmSq32ScaledIH kFitDmSq32ScaledIH
Definition: FitVars.cxx:22
std::pair< TH1D *, double > GetNueCosmics2018(std::string beam, bool GetFromUPS=false, bool NERSC=false)
virtual void SetValue(osc::IOscCalcAdjustable *osc, double val) const =0
void ResetToNominal()
Definition: SystShifts.cxx:143
const ConstrainedFitVarWithPrior fitSsqTh23_UniformPriorSsqTh23 & kFitSinSqTheta23
assert(nhit_max >=nhit_nbins)
Interface definition for fittable variables.
Definition: IFitVar.h:16
std::vector< std::pair< const ISyst *, const ISyst * > > GetCorrelations(bool isNue, bool isFHC, bool ptExtrap)
const FitSinSq2Theta13 kFitSinSq2Theta13
Definition: FitVars.cxx:13
const IPrediction * GetNuePrediction2018(std::string decomp, osc::IOscCalc *calc, bool corrSysts, std::string beam, bool isFakeData, bool GetFromUPS=false, bool minimizeMemory=false, bool NERSC=false)
const double kAna2018FHCPOT
Definition: Exposures.h:207
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
void SaveToFile(const std::string &fname) const
const FitVarWithPrior fitDeltaInPiUnits_UniformPriordCP & kFitDeltaInPiUnits
std::vector< const ISyst * > GetJointFitSystematicList(bool corrSysts, bool nueExclusive=false, bool numuExclusive=false, bool isFHC=true, bool isRHC=true, bool intersection=true, bool ptExtrap=true)
void SetShift(const ISyst *syst, double shift, bool force=false)
Definition: SystShifts.cxx:80
const double kAna2018FHCLivetime
Definition: Exposures.h:213
void SetSystCorrelations(int idx, const std::vector< std::pair< const ISyst *, const ISyst * >> &corrs)
const double kAna2018RHCLivetime
Definition: Exposures.h:214
Compare a single data spectrum to the MC + cosmics expectation.
void plot(std::string label, std::map< std::string, std::map< std::string, Spectrum * >> &plots, bool log)
Collection of FCPoint. Serializable to/from a file.
Definition: FCCollection.h:12
virtual double GetValue(const osc::IOscCalcAdjustable *osc) const =0
Perform MINUIT fits in one or two dimensions.
Definition: MinuitFitter.h:17
enum BeamMode string