Functions | Variables
uncertainty1png.C File Reference
#include "CAFAna/Core/SpectrumLoader.h"
#include "CAFAna/Core/SpectrumLoaderBase.h"
#include "CAFAna/Core/HistAxis.h"
#include "CAFAna/Vars/Vars.h"
#include "CAFAna/Core/Binning.h"
#include "CAFAna/Core/Cut.h"
#include "CAFAna/Core/Ratio.h"
#include "CAFAna/Cuts/Cuts.h"
#include "CAFAna/Cuts/SpillCuts.h"
#include "3FlavorAna/Cuts/NumuCuts.h"
#include "CAFAna/Cuts/TruthCuts.h"
#include "CAFAna/Vars/GenieWeights.h"
#include "CAFAna/Vars/PPFXWeights.h"
#include "CAFAna/XSec/GenieMultiverseSyst.h"
#include "TFile.h"
#include "CAFAna/Core/Spectrum.h"
#include "TH1.h"
#include "TH2.h"
#include "3FlavorAna/Vars/NumuVars.h"
#include "/nova/app/users/rbowles/tag_releaseS18-01-19/NDAna/ncpi0/Headers/singleprongVars.h"
#include "CAFAna/Analysis/Plots.h"
#include "TLegend.h"
#include "TCanvas.h"
#include "TColor.h"
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Functions

TFile fout (fname.c_str(),"RECREATE")
 
std::vector< std::stringparse_as_vector (std::string s)
 
void uncertainty1png ()
 

Variables

std::string fname = "CVNphoton_optimizationGrid.root"
 

Function Documentation

TFile fout ( fname.  c_str(),
"RECREATE"   
)
std::vector<std::string> parse_as_vector ( std::string  s)

Definition at line 52 of file uncertainty1png.C.

References runNovaSAM::ret, and submit_hadd::u.

53 {
54  std::vector<std::string> ret;
55  char *pch;
56  char *cstr = &s[0u];
57  // strtok splits at delimiter, but input has to be char *
58  pch = strtok (cstr,",");
59 
60  while (pch != NULL)
61  {
62  // cout << pch << endl;
63  ret.push_back(pch);
64  pch = strtok (NULL, ",");
65  }
66  return ret;
67 }
const XML_Char * s
Definition: expat.h:262
void uncertainty1png ( )

Definition at line 71 of file uncertainty1png.C.

References ana::Bkg, om::cout, d, datasets, allTimeWatchdog::endl, fout(), ana::GetkPPFXFluxUnivWgt(), ana::kCVNphotonid(), ana::kNoShift, ana::kPPFXFluxCVWgt, ana::kStandardDQCuts, ana::kTightBeamQualityCuts, ana::kTrueFiducial, ana::kXSecCVWgt2017, demo0::loader, loaders, parse_as_vector(), ana::Preselection, ana::SpectrumLoaderBase::SetSpillCut(), ana::GenieMultiverseParameters::ShiftTables(), ana::Signal, ana::Binning::Simple(), string, art::to_string(), and ana::weight.

72 {
73  //Define the datasets and indices to be used.
74  const std::string& datasetString =
75  "dataset_def_name_newest_snapshot prod_caf_R17-03-01-prod3reco.d_nd_genie_nonswap_fhc_nova_v08_full_v1,"
76  "dataset_def_name_newest_snapshot prod_caf_R17-03-01-prod3reco.l_nd_genie_nonswap_fhc_nova_v08_full_lightmodel-lightdown-calibup_v1,"
77  "dataset_def_name_newest_snapshot prod_caf_R17-03-01-prod3reco.l_nd_genie_nonswap_fhc_nova_v08_full_lightmodel-lightup-calibdown_v1,"
78  "dataset_def_name_newest_snapshot prod_caf_R17-03-01-prod3reco.l_nd_genie_nonswap_fhc_nova_v08_full_ckv-proton-shift-down_v1,"
79  "dataset_def_name_newest_snapshot prod_caf_R17-03-01-prod3reco.h_nd_genie_nonswap_fhc_nova_v08_periods1235_calib-shift-nd-xyview-neg-offset_v1,"
80  "dataset_def_name_newest_snapshot prod_caf_R17-03-01-prod3reco.h_nd_genie_nonswap_fhc_nova_v08_periods1235_calib-shift-nd-xyview-pos-offset_v1,"
81  "dataset_def_name_newest_snapshot prod_caf_R17-03-01-prod3reco.j_nd_genie_nonswap_fhc_nova_v08_full_calib-shift-nd-func_v1";
82 
83  const int dataIdx = 0;
84  const int nominalIdx = 1;
85 
86  /*****************************************************************/
87 
88  //Label and load in the spectrum objects for each dataset.
89  std::vector<std::string> dataset_labels = {"nominal", "lightdown", "lightup", "ckv", "calibneg", "calibpos", "calibshape"};
90  std::vector<ana::SpectrumLoaderBase*> loaders;
91  std::vector<std::string> datasets = parse_as_vector(datasetString);
92 
93  // Print all the inputs for easy checking.
94  std::cout<<"\nDataset names:\n";
95  for(auto &id: datasets)
96  std::cout<<id<<"\n";
97 
98  /*****************************************************************/
99 
100  /*Define vectors of spectra of different variables for different loaders.*/
101 
102  //Total truth information.
103  std::vector<std::vector<ana::Spectrum*> > spec_totmc;
104 
105  //True signal with fiducial cuts only.
106  std::vector<std::vector<ana::Spectrum*> > spec_Nsig_fid_only;
107 
108  //True signal that passes preselection cuts.
109  std::vector<std::vector<ana::Spectrum*> > spec_NSel_Cuts;
110 
111  //Total background.
112  std::vector<std::vector<ana::Spectrum*> > spec_Nbkg_Cuts;
113 
114  /******************************************************************/
115 
116  /*Define vectors of spectra of different variables for
117  nominal loader but different flux universes.*/
118 
119  //Total flux truth information.
120  std::vector<std::vector<ana::Spectrum*> > spec_totmc_flux;
121 
122  //True signal with fiducial cuts only.
123  std::vector<std::vector<ana::Spectrum*> > spec_Nsig_fid_only_flux;
124 
125  //True signal that passes preselection cuts.
126  std::vector<std::vector<ana::Spectrum*> > spec_NSel_Cuts_flux;
127 
128  //True signal that passes all cuts (Total Background)
129  std::vector<std::vector<ana::Spectrum*> > spec_Nbkg_Cuts_flux;
130 
131  /*******************************************************************/
132 
133  /*Define vectors of spectra of different variables
134  for nominal loader, but different xsec universes.*/
135 
136  //Total MC Preselection.
137  std::vector<std::vector<ana::Spectrum*> > spec_totmc_xsec;
138 
139  //True signal with fiducial cuts only.
140  std::vector<std::vector<ana::Spectrum*> > spec_Nsig_fid_only_xsec;
141 
142  //Signal that passes preselection cuts.
143  std::vector<std::vector<ana::Spectrum*> > spec_NSel_Cuts_xsec;
144 
145  //True signal that passes all cuts (Total Background)
146  std::vector<std::vector<ana::Spectrum*> > spec_Nbkg_Cuts_xsec;
147 
148  /********************************************************************/
149 
150  //Set spill cuts on all spectra by looping over all loaders.
151  for(unsigned int idataset = 0; idataset < datasets.size(); ++idataset)
152  {
154  loader = new SpectrumLoader(datasets[idataset]);
156  loaders.push_back(loader);
157  }
158 
159  const int nvar = 1;
160 
161  const Binning BDTBins = Binning::Simple(162,-1-1/160.,1+1/160.);
162 
163  HistAxis taxes[nvar] =
164  {
165  HistAxis ("Single Prong CVN Photon ID", BDTBins, kCVNphotonid)
166  };
167 
168  /************************************************************************/
169 
170  //Begin filling spectra with multiverse parameters.
171  std::vector<std::string> taxes_labels = {"1Prong_CVN_Photon_ID"};
172  std::vector<ana::Var> ppfx_univ = ana::GetkPPFXFluxUnivWgt();
173  GenieMultiverseParameters verse(100, "/nova/app/users/rbowles/tag_releaseS18-01-19/CAFAna/XSec/Utilities/knob_config.txt");
174  std::vector<std::map<const ISyst*, double> > genie_shifts = verse.ShiftTables();
175 
176  //Loop over loaders and variables to fill spectra.
177  for(unsigned int iload = 0; iload < loaders.size(); ++iload)
178  {
180  // SpillTruthVar weightST = kXSecCVWgt2017ST * kPPFXFluxCVWgtST;
181  // one vector per loader for all the vars
182 
183  //Total Preselection.
184  std::vector<ana::Spectrum*> vspec_totmc;
185 
186  //Denominator: True signal fiducial.
187  std::vector<ana::Spectrum*> vspec_Nsig_fid_only;
188 
189  //Signal numerator: Signal cuts.
190  std::vector<ana::Spectrum*> vspec_NSel_Cuts;
191 
192  //Preselection + !Signal
193  std::vector<ana::Spectrum*> vspec_Nbkg_Cuts;
194 
195  //Loop over axes.
196  for(int ivar = 0; ivar < nvar; ivar++)
197  {
198  //Total Preselection including RemID.
199  vspec_totmc.push_back(new Spectrum(*loaders[iload],taxes[ivar],Preselection,kNoShift,weight));
200 
201  //Total signal.
202  vspec_NSel_Cuts.push_back(new Spectrum(*loaders[iload],taxes[ivar],Preselection && Signal,kNoShift,weight));
203 
204  //True Signal with only true fiducial (Fiducial, pi0, NCurrent)
205  vspec_Nsig_fid_only.push_back(new Spectrum(*loaders[iload],taxes[ivar], kTrueFiducial && Signal,kNoShift,weight));
206 
207  //Total Background
208  vspec_Nbkg_Cuts.push_back(new Spectrum(*loaders[iload],taxes[ivar],Preselection && Bkg,kNoShift,weight));
209 
210 
211  //Only build universes for the nominal loader.
212  if(iload == 0)
213  {
214  /*Define flux spectra.*/
215 
216  //Total flux.
217  std::vector<ana::Spectrum*> vspec_totmc_flux;
218 
219  //Total signal flux.
220  std::vector<ana::Spectrum*> vspec_Nsig_fid_only_flux;
221 
222  //Signal that passes preselection.
223  std::vector<ana::Spectrum*> vspec_NSel_Cuts_flux;
224 
225  //Total background.
226  std::vector<ana::Spectrum*> vspec_Nbkg_Cuts_flux;
227 
228  /*****************************************************************/
229  /*Define cross section spectra.*/
230 
231  //Total cross section.
232  std::vector<ana::Spectrum*> vspec_totmc_xsec;
233 
234  //Total signal cross section.
235  std::vector<ana::Spectrum*> vspec_Nsig_fid_only_xsec;
236 
237  //Signal that passes preselection.
238  std::vector<ana::Spectrum*> vspec_NSel_Cuts_xsec;
239 
240  //Total background.
241  std::vector<ana::Spectrum*> vspec_Nbkg_Cuts_xsec;
242 
243  //Loop over all 100 universes.
244  for(int iuniv = 0; iuniv < 100; iuniv++)
245  {
246  /**********Fill spectra from ppfx universes.***********/
247  vspec_totmc_flux.push_back(new Spectrum(*loaders[iload],taxes[ivar],Preselection,kNoShift,ppfx_univ[iuniv]));
248 
249  vspec_NSel_Cuts_flux.push_back(new Spectrum(*loaders[iload],taxes[ivar],Preselection && Signal,kNoShift,ppfx_univ[iuniv]));
250 
251  vspec_Nsig_fid_only_flux.push_back(new Spectrum(*loaders[iload],taxes[ivar],kTrueFiducial && Signal,kNoShift,ppfx_univ[iuniv]));
252 
253  vspec_Nbkg_Cuts_flux.push_back(new Spectrum(*loaders[iload],taxes[ivar],Preselection && Bkg,kNoShift,ppfx_univ[iuniv]));
254 
255  /**********Fill spectra from genie universes.**********/
256  vspec_totmc_xsec.push_back(new Spectrum(*loaders[iload],taxes[ivar],Preselection,genie_shifts[iuniv],weight));
257 
258  vspec_NSel_Cuts_xsec.push_back(new Spectrum(*loaders[iload],taxes[ivar],Preselection && Signal,genie_shifts[iuniv],weight) );
259 
260  vspec_Nsig_fid_only_xsec.push_back(new Spectrum(*loaders[iload],taxes[ivar],kTrueFiducial && Signal,genie_shifts[iuniv],weight));
261 
262  vspec_Nbkg_Cuts_xsec.push_back(new Spectrum(*loaders[iload],taxes[ivar],Preselection && Bkg,genie_shifts[iuniv],weight));
263  }
264  spec_totmc_xsec.push_back(vspec_totmc_xsec);
265  spec_Nsig_fid_only_xsec.push_back(vspec_Nsig_fid_only_xsec);
266  spec_NSel_Cuts_xsec.push_back(vspec_NSel_Cuts_xsec);
267  spec_Nbkg_Cuts_xsec.push_back(vspec_Nbkg_Cuts_xsec);
268 
269  spec_totmc_flux.push_back(vspec_totmc_flux);
270  spec_Nsig_fid_only_flux.push_back(vspec_Nsig_fid_only_flux);
271  spec_NSel_Cuts_flux.push_back(vspec_NSel_Cuts_flux);
272  spec_Nbkg_Cuts_flux.push_back(vspec_Nbkg_Cuts_flux);
273  }
274  }
275  spec_totmc.push_back(vspec_totmc);
276  spec_Nsig_fid_only.push_back(vspec_Nsig_fid_only);
277  spec_NSel_Cuts.push_back(vspec_NSel_Cuts);
278  spec_Nbkg_Cuts.push_back(vspec_Nbkg_Cuts);
279  }
280  /************************************************************************/
281 
282  for(unsigned int iload = 0; iload < loaders.size(); ++iload)
283  {
284  loaders[iload]->Go();
285  }
286 
287  //Loop over loaders
288  for(unsigned int iload = 0; iload < loaders.size(); ++iload)
289  {
290  TDirectory* d = fout.mkdir(dataset_labels[iload].c_str());
291 
292  //Loop over variables.
293  for(int ivar = 0; ivar < nvar; ++ivar)
294  {
295  std::cout<<"loader "<<dataset_labels[iload]<<" var "<<taxes_labels[ivar]<<"\n";
296  spec_totmc[iload][ivar]->SaveTo(d->mkdir( ("totmc_"+taxes_labels[ivar]).c_str()));
297  spec_Nsig_fid_only[iload][ivar]->SaveTo(d->mkdir( ("Nsig_fid_only_"+taxes_labels[ivar]).c_str()));
298  spec_NSel_Cuts[iload][ivar]->SaveTo(d->mkdir( ("NSel_Cuts_"+taxes_labels[ivar]).c_str()));
299  spec_Nbkg_Cuts[iload][ivar]->SaveTo(d->mkdir( ("Nbkg_Cuts_"+taxes_labels[ivar]).c_str()));
300 
301  if(iload == 0)
302  {
303  TDirectory* dftmc = fout.mkdir(("flux_totmc_"+taxes_labels[ivar]).c_str());
304  TDirectory* dft = fout.mkdir(("flux_Nsig_fid_only_"+taxes_labels[ivar]).c_str());
305  TDirectory* dfp = fout.mkdir(("flux_NSel_Cuts_"+taxes_labels[ivar]).c_str());
306  TDirectory* dfb = fout.mkdir(("flux_Nbkg_Cuts_"+taxes_labels[ivar]).c_str());
307 
308  TDirectory* dxtmc = fout.mkdir(("xsec_totmc_"+taxes_labels[ivar]).c_str());
309  TDirectory* dxt = fout.mkdir(("xsec_Nsig_fid_only_"+taxes_labels[ivar]).c_str());
310  TDirectory* dxp = fout.mkdir(("xsec_NSel_Cuts_"+taxes_labels[ivar]).c_str());
311  TDirectory* dxb = fout.mkdir(("xsec_Nbkg_Cuts_"+taxes_labels[ivar]).c_str());
312 
313  for(int iuniv = 0; iuniv < 100; iuniv++)
314  {
315  spec_totmc_flux[ivar][iuniv]->SaveTo(dftmc->mkdir( ("spec"+std::to_string(iuniv)).c_str()));
316  spec_Nsig_fid_only_flux[ivar][iuniv]->SaveTo(dft->mkdir( ("spec"+std::to_string(iuniv)).c_str()));
317  spec_NSel_Cuts_flux[ivar][iuniv]->SaveTo(dfp->mkdir( ("spec"+std::to_string(iuniv)).c_str()));
318  spec_Nbkg_Cuts_flux[ivar][iuniv]->SaveTo(dfb->mkdir( ("spec"+std::to_string(iuniv)).c_str()));
319  spec_totmc_xsec[ivar][iuniv]->SaveTo(dxtmc->mkdir( ("spec"+std::to_string(iuniv)).c_str()));
320  spec_Nsig_fid_only_xsec[ivar][iuniv]->SaveTo(dxt->mkdir( ("spec"+std::to_string(iuniv)).c_str()));
321  spec_NSel_Cuts_xsec[ivar][iuniv]->SaveTo(dxp->mkdir( ("spec"+std::to_string(iuniv)).c_str()));
322  spec_Nbkg_Cuts_xsec[ivar][iuniv]->SaveTo(dxb->mkdir( ("spec"+std::to_string(iuniv)).c_str()));
323  }
324  }
325  }
326  }
327  std::cout << "\nOutput saved to CVNphoton_optimization.root" <<std::endl;
328 }
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
const Var kPPFXFluxCVWgt
Definition: PPFXWeights.h:16
const Var weight
TFile fout(fname.c_str(),"RECREATE")
std::vector< Dataset > datasets
Definition: Periods.h:3
std::vector< double > Spectrum
Definition: Constants.h:743
const Var kCVNphotonid([](const caf::SRProxy *sr){if(sr->vtx.nelastic==0) return 0.f;if(sr->vtx.elastic[0].fuzzyk.npng >1) return float(-1);return float(sr->vtx.elastic[0].fuzzyk.png[0].cvnpart.photonid);})
void SetSpillCut(const SpillCut &cut)
const Cut Preselection
std::vector< Var > GetkPPFXFluxUnivWgt()
Definition: PPFXWeights.cxx:53
const SpillCut kTightBeamQualityCuts([](const caf::SRSpillProxy *s){if(s->ismc) return true; if(s->trigger==2) return true;if(s->spilltimesec==0 &&s->deltaspilltimensec==0 &&s->widthx==0) return bool(s->isgoodspill);if(std::abs(s->deltaspilltimensec) > 0.5e9) return false;if(s->spillpot< 2e12) return false;if(s->hornI< -202|| s->hornI >-198) return false;if(s->posx< -2.00|| s->posx >+2.00) return false;if(s->posy< -2.00|| s->posy >+2.00) return false;return kBeamWidthCut(s);})
Definition: SpillCuts.h:10
const SpillCut kStandardDQCuts([](const caf::SRSpillProxy *spill){if(spill->dcmedgematchfrac==0 &&spill->fracdcm3hits==0 &&spill->nmissingdcmslg==0) return bool(spill->isgoodspill); if(spill->det==caf::kNEARDET && (spill->fracdcm3hits > 0.45|| spill->nmissingdcms > 0)) return false; if(spill->eventincomplete) return false; if(spill->det==caf::kFARDET && spill->nmissingdcmslg > 0) return false; if(spill->det==caf::kFARDET && !spill->ismc && spill->dcmedgematchfrac<=0.2) return false;return true;})
Cut out events with a noisy detector or with parts missing.
Definition: SpillCuts.h:16
const Cut Bkg
Float_t d
Definition: plot.C:236
loader
Definition: demo0.py:10
const SystShifts kNoShift
Definition: SystShifts.cxx:22
OStream cout
Definition: OStream.cxx:6
Base class for the various types of spectrum loader.
Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.
std::vector< Loaders * > loaders
Definition: syst_header.h:386
const Var kXSecCVWgt2017
Definition: XsecTunes.h:36
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
std::vector< std::string > parse_as_vector(std::string s)
enum BeamMode string

Variable Documentation

std::string fname = "CVNphoton_optimizationGrid.root"

Definition at line 45 of file uncertainty1png.C.