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