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

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/CAFAna/Analysis/CSVMaker.h"

Inheritance diagram for ana::CSVMaker:
ana::SpectrumLoader ana::SpectrumLoaderBase

Public Types

typedef std::pair< std::string, VarNamedVar
 
typedef std::pair< std::string, MultiVarNamedMultiVar
 

Public Member Functions

 CSVMaker (const std::string &input, const std::string &output)
 
void setPrecision (int precision)
 
void addVar (const std::string &name, const Var &var)
 
void addMultiVar (const std::string &name, const MultiVar &multiVar)
 
void addVars (const std::vector< NamedVar > &vars)
 
void addMultiVars (const std::vector< NamedMultiVar > &multiVars)
 
void setCut (const Cut &cut)
 
void Go () override
 Load all the registered spectra. More...
 
void SetSpillCut (const SpillCut &cut)
 
virtual void AddSpectrum (Spectrum &spect, const Var &var, const Cut &cut, const SystShifts &shift, const Var &wei=kUnweighted)
 For use by the Spectrum constructor. More...
 
virtual void AddSpectrum (Spectrum &spect, const MultiVar &var, const Cut &cut, const SystShifts &shift, const Var &wei=kUnweighted)
 For use by the Spectrum constructor. More...
 
virtual void AddSpectrum (Spectrum &spect, const NuTruthVar &var, const NuTruthCut &cut, const SystShifts &shift, const NuTruthVar &wei=kNuTruthUnweighted)
 For use by the Spectrum constructor. More...
 
virtual void AddSpectrum (Spectrum &spect, const NuTruthMultiVar &var, const NuTruthCut &cut, const SystShifts &shift, const NuTruthVar &wei=kNuTruthUnweighted)
 
virtual void AddReweightableSpectrum (ReweightableSpectrum &spect, const Var &xvar, const Var &yvar, const Cut &cut, const SystShifts &shift, const Var &wei)
 For use by the constructors of ReweightableSpectrum subclasses. More...
 
virtual void AddSpillHistogram (TH1 *h, const SpillVar &var, const SpillCut &cut, const SpillVar &wei=kSpillUnweighted)
 Uses include counting the total POT or spills in a run. More...
 
virtual bool Gone () const
 Indicate whether or not Go has been called. More...
 
double GetWeightedPOT ()
 

Static Public Member Functions

static SpectrumLoader FromSAMProject (const std::string &proj, int fileLimit=-1)
 Named constructor for SAM projects. More...
 

Protected Member Functions

void printHeader ()
 
void printRow (caf::SRProxy *sr)
 
void HandleRecord (caf::SRProxy *sr) override
 
void AccumulateExposures (const caf::SRSpillProxy *spill) override
 
virtual void HandleFile (TFile *f, Progress *prog=0)
 
IFileSourceWildcardOrSAMQuery (const std::string &str) const
 Figure out if str is a wildcard or SAM query and return a source. More...
 
int NFiles () const
 Forwards to fFileSource. More...
 
TFile * GetNextFile ()
 Forwards to fFileSource but also accumulates POT and livetime. More...
 
WeightApplierGetSinkSCW (const SystShifts &shift, const Cut &cut, const Var &wei)
 

Protected Attributes

std::unique_ptr< Cutcut
 
std::ofstream ofile
 
std::vector< NamedVarvars
 
std::vector< NamedMultiVarmultiVars
 
std::string fWildcard
 
std::unique_ptr< IFileSourcefFileSource
 
bool fGone
 Has Go() been called? Can't add more histograms after that. More...
 
double fPOT
 Accumulated by calls to GetNextFile. More...
 
double fRunPOT
 Crude measure, not including spill cuts. More...
 
double fSinglePOT
 
double fBeamNue
 
double fSingleNue
 
double fWeightedPOT
 
std::set< IRecordSink * > fSpectrumSinks
 
std::unordered_map< std::tuple< int, int, int >, WeightApplier * > fSinksSCW
 
std::unordered_map< std::pair< int, int >, CutApplier * > fSinksSC
 
std::unordered_map< int, SystApplier * > fSinksS
 
RecordMultiSink fSink
 
ExposureSource fExposureSource
 
std::list< SpillHistDeffSpillHistDefs
 
std::list< NuHistDeffNuHistDefs
 
std::unique_ptr< SpillCutfSpillCut
 Cut applied to the spill branch for every event. More...
 

Detailed Description

Definition at line 13 of file CSVMaker.h.

Member Typedef Documentation

Definition at line 17 of file CSVMaker.h.

Definition at line 16 of file CSVMaker.h.

Constructor & Destructor Documentation

ana::CSVMaker::CSVMaker ( const std::string input,
const std::string output 
)

Definition at line 48 of file CSVMaker.cxx.

References ofile.

49  : SpectrumLoader(input), cut(nullptr), ofile(output)
50 {
51  if (! ofile) {
52  throw std::runtime_error("Failed to open output file");
53  }
54 
55  ofile << std::setprecision(std::numeric_limits<double>::max_digits10);
56 }
ofstream output
std::ofstream ofile
Definition: CSVMaker.h:21
std::unique_ptr< Cut > cut
Definition: CSVMaker.h:20

Member Function Documentation

void ana::SpectrumLoader::AccumulateExposures ( const caf::SRSpillProxy spill)
overrideprotectedvirtualinherited

Implements ana::SpectrumLoaderBase.

Reimplemented in ana::SpectrumLoaderNuTreeSpillCuts.

Definition at line 191 of file SpectrumLoader.cxx.

References ana::SpectrumLoaderBase::fExposureSource, and ana::ExposureSource::HandleSpill().

Referenced by ana::SpectrumLoaderNuTreeSpillCuts::AccumulateExposures().

192  {
194  }
void HandleSpill(const caf::SRSpillProxy *spill) override
void ana::CSVMaker::addMultiVar ( const std::string name,
const MultiVar multiVar 
)

Definition at line 115 of file CSVMaker.cxx.

References make_pair(), and multiVars.

116 {
117  multiVars.emplace_back(std::make_pair(name, multiVar));
118 }
const XML_Char * name
Definition: expat.h:151
std::vector< NamedMultiVar > multiVars
Definition: CSVMaker.h:24
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
void ana::CSVMaker::addMultiVars ( const std::vector< NamedMultiVar > &  multiVars)

Definition at line 125 of file CSVMaker.cxx.

126 {
127  this->multiVars.insert(
128  this->multiVars.end(), multiVars.begin(), multiVars.end()
129  );
130 }
std::vector< NamedMultiVar > multiVars
Definition: CSVMaker.h:24
void ana::SpectrumLoaderBase::AddReweightableSpectrum ( ReweightableSpectrum spect,
const Var xvar,
const Var yvar,
const Cut cut,
const SystShifts shift,
const Var wei 
)
virtualinherited

For use by the constructors of ReweightableSpectrum subclasses.

Reimplemented in ana::NullLoader.

Definition at line 212 of file SpectrumLoaderBase.cxx.

References ana::RecordMultiSink::AddSink(), ana::ExposureSource::AddSink(), om::cerr, allTimeWatchdog::endl, ana::SpectrumLoaderBase::fExposureSource, ana::SpectrumLoaderBase::fGone, ana::SpectrumLoaderBase::fSpectrumSinks, and ana::SpectrumLoaderBase::GetSinkSCW().

Referenced by ana::FluxReweight::FluxReweight(), ana::NoReweight::NoReweight(), and ana::RecoReweight::RecoReweight().

218  {
219  if(fGone){
220  std::cerr << "Error: can't add Spectra after the call to Go()" << std::endl;
221  abort();
222  }
223 
224  ReweightableSpectrumSink* sink = new ReweightableSpectrumSink(xvar, yvar, &spect);
225  fSpectrumSinks.insert(sink);
226  GetSinkSCW(shift, cut, wei)->AddSink(sink);
227  fExposureSource.AddSink(cut, sink);
228  }
bool fGone
Has Go() been called? Can&#39;t add more histograms after that.
OStream cerr
Definition: OStream.cxx:7
void AddSink(const Cut &cut, IExposureSink *s)
std::set< IRecordSink * > fSpectrumSinks
void AddSink(IRecordSink *s)
WeightApplier * GetSinkSCW(const SystShifts &shift, const Cut &cut, const Var &wei)
const Cut cut
Definition: exporter_fd.C:30
void ana::SpectrumLoaderBase::AddSpectrum ( Spectrum spect,
const Var var,
const Cut cut,
const SystShifts shift,
const Var wei = kUnweighted 
)
virtualinherited

For use by the Spectrum constructor.

Reimplemented in ana::NullLoader, and ana::SpectrumLoaderNuTreeSpillCuts.

Definition at line 154 of file SpectrumLoaderBase.cxx.

References ana::RecordMultiSink::AddSink(), ana::ExposureSource::AddSink(), om::cerr, allTimeWatchdog::endl, ana::SpectrumLoaderBase::fExposureSource, ana::SpectrumLoaderBase::fGone, ana::SpectrumLoaderBase::fSpectrumSinks, and ana::SpectrumLoaderBase::GetSinkSCW().

Referenced by ana::SpectrumLoaderNuTreeSpillCuts::AddSpectrum(), and ana::TrivialExtrap::TrivialExtrap().

159  {
160  if(fGone){
161  std::cerr << "Error: can't add Spectra after the call to Go()" << std::endl;
162  abort();
163  }
164 
165  SpectrumSink* sink = new SpectrumSink(var, &spect);
166  fSpectrumSinks.insert(sink);
167  GetSinkSCW(shift, cut, wei)->AddSink(sink);
168  fExposureSource.AddSink(cut, sink);
169  }
bool fGone
Has Go() been called? Can&#39;t add more histograms after that.
OStream cerr
Definition: OStream.cxx:7
void AddSink(const Cut &cut, IExposureSink *s)
std::set< IRecordSink * > fSpectrumSinks
void AddSink(IRecordSink *s)
WeightApplier * GetSinkSCW(const SystShifts &shift, const Cut &cut, const Var &wei)
const Cut cut
Definition: exporter_fd.C:30
void ana::SpectrumLoaderBase::AddSpectrum ( Spectrum spect,
const MultiVar var,
const Cut cut,
const SystShifts shift,
const Var wei = kUnweighted 
)
virtualinherited

For use by the Spectrum constructor.

Reimplemented in ana::NullLoader, and ana::SpectrumLoaderNuTreeSpillCuts.

Definition at line 172 of file SpectrumLoaderBase.cxx.

References ana::RecordMultiSink::AddSink(), ana::ExposureSource::AddSink(), om::cerr, allTimeWatchdog::endl, ana::SpectrumLoaderBase::fExposureSource, ana::SpectrumLoaderBase::fGone, ana::SpectrumLoaderBase::fSpectrumSinks, and ana::SpectrumLoaderBase::GetSinkSCW().

177  {
178  if(fGone){
179  std::cerr << "Error: can't add Spectra after the call to Go()" << std::endl;
180  abort();
181  }
182 
183  MultiVarSpectrumSink* sink = new MultiVarSpectrumSink(var, &spect);
184  fSpectrumSinks.insert(sink);
185  GetSinkSCW(shift, cut, wei)->AddSink(sink);
186  fExposureSource.AddSink(cut, sink);
187  }
bool fGone
Has Go() been called? Can&#39;t add more histograms after that.
OStream cerr
Definition: OStream.cxx:7
void AddSink(const Cut &cut, IExposureSink *s)
std::set< IRecordSink * > fSpectrumSinks
void AddSink(IRecordSink *s)
WeightApplier * GetSinkSCW(const SystShifts &shift, const Cut &cut, const Var &wei)
const Cut cut
Definition: exporter_fd.C:30
void ana::SpectrumLoaderBase::AddSpectrum ( Spectrum spect,
const NuTruthVar var,
const NuTruthCut cut,
const SystShifts shift,
const NuTruthVar wei = kNuTruthUnweighted 
)
virtualinherited

For use by the Spectrum constructor.

Reimplemented in ana::NullLoader, and ana::SpectrumLoaderNuTreeSpillCuts.

Definition at line 190 of file SpectrumLoaderBase.cxx.

References ana::SpectrumLoaderBase::fNuHistDefs.

195  {
196  // TODO - implement with the same source/sink deal as regular spectra
197  fNuHistDefs.emplace_back(spect, var, cut, shift, wei);
198  }
const Cut cut
Definition: exporter_fd.C:30
std::list< NuHistDef > fNuHistDefs
void ana::SpectrumLoaderBase::AddSpectrum ( Spectrum spect,
const NuTruthMultiVar var,
const NuTruthCut cut,
const SystShifts shift,
const NuTruthVar wei = kNuTruthUnweighted 
)
virtualinherited

Reimplemented in ana::NullLoader, and ana::SpectrumLoaderNuTreeSpillCuts.

Definition at line 201 of file SpectrumLoaderBase.cxx.

References ana::SpectrumLoaderBase::fNuHistDefs.

206  {
207  // TODO - implement with the same source/sink deal as regular spectra
208  fNuHistDefs.emplace_back(spect, multivar, cut, shift, wei);
209  }
const Cut cut
Definition: exporter_fd.C:30
std::list< NuHistDef > fNuHistDefs
void ana::SpectrumLoaderBase::AddSpillHistogram ( TH1 *  h,
const SpillVar var,
const SpillCut cut,
const SpillVar wei = kSpillUnweighted 
)
virtualinherited
void ana::CSVMaker::addVar ( const std::string name,
const Var var 
)

Definition at line 110 of file CSVMaker.cxx.

References make_pair(), and vars.

Referenced by exporter_fd(), and exporter_nd().

111 {
112  vars.emplace_back(std::make_pair(name, var));
113 }
const XML_Char * name
Definition: expat.h:151
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
std::vector< NamedVar > vars
Definition: CSVMaker.h:23
void ana::CSVMaker::addVars ( const std::vector< NamedVar > &  vars)

Definition at line 120 of file CSVMaker.cxx.

Referenced by exporter_fd(), and exporter_nd().

121 {
122  this->vars.insert(this->vars.end(), vars.begin(), vars.end());
123 }
std::vector< NamedVar > vars
Definition: CSVMaker.h:23
SpectrumLoader ana::SpectrumLoader::FromSAMProject ( const std::string proj,
int  fileLimit = -1 
)
staticinherited

Named constructor for SAM projects.

Definition at line 43 of file SpectrumLoader.cxx.

References ana::SpectrumLoaderBase::fFileSource, ana::SpectrumLoaderBase::fWildcard, proj, and runNovaSAM::ret.

Referenced by test_sam_project().

45  {
47  ret.fWildcard = "project "+proj;
48  ret.fFileSource = std::unique_ptr<IFileSource>(new SAMProjectSource(proj, fileLimit));
49  return ret;
50  }
fileLimit
Definition: ProjMan.py:109
Float_t proj
Definition: plot.C:35
TFile * ana::SpectrumLoaderBase::GetNextFile ( )
protectedinherited

Forwards to fFileSource but also accumulates POT and livetime.

Definition at line 247 of file SpectrumLoaderBase.cxx.

References ana::SpectrumLoaderBase::AccumulateExposures(), ana::assert(), caf::SRProxySystController::BeginTransaction(), om::cout, fillBadChanDBTables::det, caf::Proxy< caf::SRNeutrino >::det, caf::Proxy< caf::SRSpill >::det, allTimeWatchdog::endl, MakeMiniprodValidationCuts::f, ana::SpectrumLoaderBase::fBeamNue, ana::SpectrumLoaderBase::fFileSource, ana::SpectrumLoaderBase::fNuHistDefs, genie::utils::style::Format(), ana::SpectrumLoaderBase::fPOT, ana::SpectrumLoaderBase::fRunPOT, ana::SpectrumLoaderBase::fSingleNue, ana::SpectrumLoaderBase::fSinglePOT, ana::SpectrumLoaderBase::fSpillCut, ana::SpectrumLoaderBase::fSpillHistDefs, ana::SpectrumLoaderBase::fWildcard, hd, caf::Proxy< caf::SRNeutrino >::is0HC, caf::Proxy< caf::SRSpill >::is0HC, isFHC, caf::Proxy< caf::SRNeutrino >::isFHC, caf::Proxy< caf::SRSpill >::isFHC, make_mec_shifts_plots::isRHC, caf::Proxy< caf::SRNeutrino >::isRHC, caf::Proxy< caf::SRSpill >::isRHC, findDuplicateFiles::key, caf::kUNKNOWN, getGoodRuns4SAM::n, cacheDefinitionData::prog, caf::SRProxySystController::Rollback(), ana::Progress::SetProgress(), caf_analysis::spill, caf::Proxy< caf::SRSpill >::spillpot, string, and febshutoff_auto::val.

Referenced by ana::SpectrumLoader::Go(), and ana::FileReducer::Go().

248  {
249  TFile* f = fFileSource->GetNextFile();
250  if(!f) return 0; // out of files
251 
252  if(f->IsZombie()){
253  std::cout << "Bad file (zombie): " << f->GetName() << std::endl;
254  abort();
255  }
256 
257  // Crude way to count POT, at a file level without referring to spill cuts
258  TH1* hPOT = (TH1*)f->Get("TotalPOT");
259 
260  if(!hPOT){
261  std::cout << "Bad file (no POT tree): " << f->GetName() << std::endl;
262  abort();
263  }
264 
265  fRunPOT += hPOT->Integral();
266 
267  TKey *key = f->FindKey("TotalSinglePOT");
268 
269  // Initialise and only fill these histos if they exist
270  // We know they exist for nue overlay files
271  TH1* hSinglePOT = 0;
272  TH1* hTotalTrueSingleNue = 0;
273  TH1* hTotalTrueNonswapNue = 0;
274  if(key != 0){
275  hSinglePOT = (TH1*)f->Get("TotalSinglePOT");
276  assert(hSinglePOT);
277  fSinglePOT = hSinglePOT->Integral();
278 
279  hTotalTrueNonswapNue = (TH1*)f->Get("TotalTrueNonswapNue");
280  assert(hTotalTrueNonswapNue);
281  fBeamNue = hTotalTrueNonswapNue->Integral();
282 
283  hTotalTrueSingleNue = (TH1*)f->Get("TotalTrueSingleNue");
284  assert(hTotalTrueSingleNue);
285  fSingleNue = hTotalTrueSingleNue->Integral();
286  }
287  else{
288  delete hSinglePOT;
289  delete hTotalTrueSingleNue;
290  delete hTotalTrueNonswapNue;
291  }
292 
293  // Test for flat (trees are inside a directory) or nested (tree is at top
294  // level) cases.
295  TDirectory* spillDir = 0;
296  TTree* spillTree = 0;
297 
298  TObject* obj = f->Get("spillTree");
299  assert(obj); // Must exist in one form or the other
300 
301  // It might seem like you could use GetObject() to do the type-checking
302  // directly, but that method seems to have a memory leak in the case that
303  // the types don't match.
304  if(obj->ClassName() == std::string("TTree")){
305  // nested case
306  spillTree = (TTree*)obj;
307  }
308  else{
309  // FlatCAF case
310  spillDir = (TDirectory*)obj;
311  spillTree = (TTree*)spillDir->Get("spill");
312  assert(spillTree);
313  }
314 
315  // These aren't set in SRNeutrino, but we need them for flux systs, so
316  // learn them from SRSpill and copy them over.
317  //
318  // TODO TODO - remove this hack (and the equivalent in SpectrumLoader.cxx
319  // once they're available in the CAFs
320  bool isFHC = false, is0HC = false, isRHC = false;
322 
323  long n = 0;
324  caf::SRSpillProxy spill(spillDir, spillTree, "spill", n, 0);
325 
326  // FloatingExceptionOnNaN fpnan;
327 
328  // With multiple files exposure counting alternates with histogram filling,
329  // but with one file they deserve to be reported as two separate steps.
330  Progress* prog = 0;
331  if(fFileSource->NFiles() == 1)
332  prog = new Progress(TString::Format("Counting exposure from 1 file matching '%s'", fWildcard.c_str()).Data());
333 
334  const int Nentries = spillTree->GetEntries();
335 
336  double totFilePOT = 0;
337 
338  for(n = 0; n < Nentries; ++n){
339  if(!spillDir) spillTree->LoadTree(n); // nested mode
340 
341  if(!fSpillCut || (*fSpillCut)(&spill)){
343 
344  totFilePOT += spill.spillpot;
345 
346  // Only learn from good spills (bad spill could have bad beam?), and
347  // only once (efficiency)
348  if(!isFHC && !is0HC && !isRHC){
349  isFHC = spill.isFHC;
350  is0HC = spill.is0HC;
351  isRHC = spill.isRHC;
352  }
353  if (det == caf::kUNKNOWN)
354  det = spill.det;
355 
356  for(const SpillHistDef& hd: fSpillHistDefs){
357  // No cut, or cut passes
358  if(hd.cut(&spill)){
359  const double wei = hd.wei(&spill);
360  if(wei){
361  const double val = hd.var(&spill);
362  hd.h->Fill(val, wei);
363  }
364  } // end if(cut passes)
365  } // end for hd
366  }
367 
368  if(prog && n%100 == 0) prog->SetProgress(double(n)/Nentries);
369  } // end for n
370 
371  // The POT we want to use is either the singles POT in case of overlay files
372  // i.e the singlepot histo exists, or the standard after spill cuts
373  // Note: must be sure to run spill cuts for the overlays otherwise this gets
374  // reset to the fRunPOT
375  if(key != 0) fPOT += fSinglePOT;
376  else fPOT += totFilePOT;
377 
378  delete prog;
379  prog = 0;
380 
381  if(!fNuHistDefs.empty()){
382  // Test for flat (trees are inside a directory) or nested (tree is at top
383  // level) cases.
384 
385  TDirectory* nuDir = 0;
386  TTree* nuTree = 0;
387 
388  TObject* obj = f->Get("nuTree");
389  assert(obj); // Must exist in one form or the other
390 
391  // It might seem like you could use GetObject() to do the type-checking
392  // directly, but that method seems to have a memory leak in the case that
393  // the types don't match.
394  if(obj->ClassName() == std::string("TTree")){
395  // nested case
396  nuTree = (TTree*)obj;
397  }
398  else{
399  // FlatCAF case
400  nuDir = (TDirectory*)obj;
401  nuTree = (TTree*)spillDir->Get("nu");
402  assert(nuTree);
403  }
404 
405  const int NNuEntries = nuTree->GetEntries();
406 
407  long n = 0;
408  caf::SRNeutrinoProxy nu(nuDir, nuTree, nuDir ? "nu" : "mc.nu", n, 0);
409 
410  if(fFileSource->NFiles() == 1)
411  prog = new Progress(TString::Format("Filling from nuTree from 1 file matching '%s'", fWildcard.c_str()).Data());
412 
413 
414  for(n = 0; n < NNuEntries; ++n){
415  if(!nuDir) nuTree->LoadTree(n); // nested mode
416 
417  nu.isFHC = isFHC;
418  nu.is0HC = is0HC;
419  nu.isRHC = isRHC;
420  nu.det = det;
421 
422  for(const NuHistDef& hd: fNuHistDefs){
424 
425  double systWeight = 1;
426  // Can special-case nominal to not pay cost of Shift()
427  if(!hd.shift.IsNominal()){
428  hd.shift.Shift(&nu, systWeight);
429  }
430 
431  if(hd.cut(&nu)){
432  const double wei = hd.wei(&nu)*systWeight;
433  if(wei){
434  if(hd.var){
435  const double val = (*hd.var)(&nu);
436  hd.spect.Fill(val, wei);
437  }
438  else{
439  for(double val: (*hd.multivar)(&nu)) hd.spect.Fill(val, wei);
440  }
441  }
442  }
443 
444  // Return SRNeutrino to its unshifted form ready for the next
445  // histogram.
447  } // end for hd
448 
449  if(prog && n%10000 == 0) prog->SetProgress(double(n)/NNuEntries);
450  } // end for n
451 
452  for(const NuHistDef& hd: fNuHistDefs) hd.spect.fPOT += totFilePOT;
453 
454  delete prog;
455  } // end if NuHistDefs
456 
457  return f;
458  }
Unknown detector.
Definition: SREnums.h:9
Det_t
Which NOvA detector?
Definition: SREnums.h:7
Proxy for caf::SRNeutrino.
Definition: SRProxy.h:510
double fRunPOT
Crude measure, not including spill cuts.
std::unique_ptr< SpillCut > fSpillCut
Cut applied to the spill branch for every event.
virtual void AccumulateExposures(const caf::SRSpillProxy *spill)=0
std::list< SpillHistDef > fSpillHistDefs
static bool isFHC
Proxy for caf::SRSpill.
Definition: SRProxy.h:1346
OStream cout
Definition: OStream.cxx:6
std::unique_ptr< IFileSource > fFileSource
assert(nhit_max >=nhit_nbins)
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
double fPOT
Accumulated by calls to GetNextFile.
std::list< NuHistDef > fNuHistDefs
TH1F * hd
Definition: Xdiff_gwt.C:57
enum BeamMode string
WeightApplier * ana::SpectrumLoaderBase::GetSinkSCW ( const SystShifts shift,
const Cut cut,
const Var wei 
)
protectedinherited

Definition at line 123 of file SpectrumLoaderBase.cxx.

References ana::RecordMultiSink::AddSink(), PandAna.Demos.tute_pid_validation::cid, ana::SpectrumLoaderBase::fSink, ana::SpectrumLoaderBase::fSinksS, ana::SpectrumLoaderBase::fSinksSC, ana::SpectrumLoaderBase::fSinksSCW, ana::SystShifts::ID(), ana::_Var< T >::ID(), and ana::_Cut< T >::ID().

Referenced by ana::SpectrumLoaderBase::AddReweightableSpectrum(), and ana::SpectrumLoaderBase::AddSpectrum().

126  {
127  const int sid = shift.ID();
128  const int cid = cut.ID();
129  const int wid = wei.ID();
130 
131  const std::pair<int, int> sc(sid, cid);
132  const std::tuple<int, int, int> scw(sid, cid, wid);
133 
134  if(fSinksS.find(sid) == fSinksS.end()){
135  SystApplier* sa = new SystApplier(shift);
136  fSinksS[sid] = sa;
137  fSink.AddSink(sa);
138  }
139  if(fSinksSC.find(sc) == fSinksSC.end()){
140  CutApplier* ca = new CutApplier(cut);
141  fSinksS[sid]->AddSink(ca);
142  fSinksSC[sc] = ca;
143  }
144  if(fSinksSCW.find(scw) == fSinksSCW.end()){
145  WeightApplier* wa = new WeightApplier(wei);
146  fSinksSC[sc]->AddSink(wa);
147  fSinksSCW[scw] = wa;
148  }
149 
150  return fSinksSCW[scw];
151  }
void AddSink(IRecordSink *s)
std::unordered_map< int, SystApplier * > fSinksS
std::unordered_map< std::pair< int, int >, CutApplier * > fSinksSC
const Cut cut
Definition: exporter_fd.C:30
std::unordered_map< std::tuple< int, int, int >, WeightApplier * > fSinksSCW
double ana::SpectrumLoaderBase::GetWeightedPOT ( )
inherited
void ana::CSVMaker::Go ( )
overridevirtual

Load all the registered spectra.

Reimplemented from ana::SpectrumLoader.

Definition at line 150 of file CSVMaker.cxx.

References ana::SpectrumLoader::Go(), ana::SpectrumLoaderBase::Gone(), ofile, and printHeader().

Referenced by exporter_fd(), and exporter_nd().

151 {
152  if (! Gone()) {
153  printHeader();
154  }
155 
157 
158  ofile.close();
159 }
void printHeader()
Definition: CSVMaker.cxx:63
std::ofstream ofile
Definition: CSVMaker.h:21
virtual void Go() override
Load all the registered spectra.
virtual bool Gone() const
Indicate whether or not Go has been called.
virtual bool ana::SpectrumLoaderBase::Gone ( ) const
inlinevirtualinherited

Indicate whether or not Go has been called.

Definition at line 124 of file SpectrumLoaderBase.h.

References caf_analysis::spill, submit_syst::str, string, and wildcard().

Referenced by ana::TwoSampleDecomp::Decomp(), Go(), and ana::SpectrumHandler::Go().

124 {return fGone;}
bool fGone
Has Go() been called? Can&#39;t add more histograms after that.
void ana::SpectrumLoader::HandleFile ( TFile *  f,
Progress prog = 0 
)
protectedvirtualinherited

Definition at line 128 of file SpectrumLoader.cxx.

References ana::assert(), dir, ana::SpectrumLoader::HandleRecord(), getGoodRuns4SAM::n, ana::Progress::SetProgress(), sr, string, and make_root_from_grid_output::tr.

Referenced by ana::SpectrumLoader::Go(), ProducingSA(), tree_maker_simple(), and useBDTG().

129  {
130  assert(!f->IsZombie());
131 
132  // Test for flat (trees are inside a directory) or nested (tree is at top
133  // level) cases.
134  TDirectory* dir = 0;
135  TTree* tr = 0;
136 
137  TObject* obj = f->Get("recTree");
138  assert(obj); // Must exist in one form or the other
139 
140  // It might seem like you could use GetObject() to do the type-checking
141  // directly, but that method seems to have a memory leak in the case that
142  // the types don't match.
143  if(obj->ClassName() == std::string("TTree")){
144  // nested case
145  tr = (TTree*)obj;
146  }
147  else{
148  // FlatCAF case
149  dir = (TDirectory*)obj;
150  tr = (TTree*)dir->Get("rec");
151  assert(tr);
152  }
153 
154  long n;
155  caf::SRProxy sr(dir, tr, "rec", n, 0);
156 
157  // FloatingExceptionOnNaN fpnan;
158 
159  const long Nentries = tr->GetEntries();
160  for(n = 0; n < Nentries; ++n){
161  if(!dir) tr->LoadTree(n); // nested mode
162 
163  HandleRecord(&sr);
164 
165  if(prog && n%100 == 0) prog->SetProgress(double(n)/Nentries);
166  } // end for n
167  }
Proxy for caf::StandardRecord.
Definition: SRProxy.h:2126
caf::StandardRecord * sr
TDirectory * dir
Definition: macro.C:5
virtual void HandleRecord(caf::SRProxy *sr)
assert(nhit_max >=nhit_nbins)
enum BeamMode string
void ana::CSVMaker::HandleRecord ( caf::SRProxy sr)
overrideprotectedvirtual

Reimplemented from ana::SpectrumLoader.

Definition at line 137 of file CSVMaker.cxx.

References cut, ana::SpectrumLoaderBase::fSpillCut, printRow(), and caf::Proxy< caf::StandardRecord >::spill.

138 {
139  if ((fSpillCut != nullptr) && !(*fSpillCut)(&sr->spill)) {
140  return;
141  }
142 
143  if ((cut != nullptr) && !(*cut)(sr)) {
144  return;
145  }
146 
147  printRow(sr);
148 }
caf::Proxy< caf::SRSpill > spill
Definition: SRProxy.h:2143
std::unique_ptr< SpillCut > fSpillCut
Cut applied to the spill branch for every event.
std::unique_ptr< Cut > cut
Definition: CSVMaker.h:20
void printRow(caf::SRProxy *sr)
Definition: CSVMaker.cxx:81
int ana::SpectrumLoaderBase::NFiles ( ) const
protectedinherited

Forwards to fFileSource.

Definition at line 241 of file SpectrumLoaderBase.cxx.

References ana::SpectrumLoaderBase::fFileSource.

Referenced by ana::SpectrumLoader::Go(), and ana::FileReducer::Go().

242  {
243  return fFileSource->NFiles();
244  }
std::unique_ptr< IFileSource > fFileSource
void ana::CSVMaker::printHeader ( )
protected

Definition at line 63 of file CSVMaker.cxx.

References allTimeWatchdog::endl, multiVars, ofile, output, and vars.

Referenced by Go().

64 {
65  bool firstValuePrinted = false;
66 
67  firstValuePrinted = printSeparatedValues<NamedVar, char>(
68  ofile, vars, firstValuePrinted, ',',
69  [this] (auto &output, auto &namedVar) { output << namedVar.first; }
70  );
71 
72  printSeparatedValues<NamedMultiVar, char>(
73  ofile, multiVars, firstValuePrinted, ',',
74  [this] (auto &output, auto &namedMultiVar)
75  { output << namedMultiVar.first; }
76  );
77 
78  ofile << std::endl;
79 }
ofstream output
std::vector< NamedMultiVar > multiVars
Definition: CSVMaker.h:24
std::ofstream ofile
Definition: CSVMaker.h:21
std::vector< NamedVar > vars
Definition: CSVMaker.h:23
void ana::CSVMaker::printRow ( caf::SRProxy sr)
protected

Definition at line 81 of file CSVMaker.cxx.

References allTimeWatchdog::endl, multiVars, ofile, output, sr, train_latest_snapshot::values, vars, and submit_syst::x.

Referenced by HandleRecord().

82 {
83  bool firstValuePrinted = false;
84 
85  firstValuePrinted = printSeparatedValues<NamedVar, char>(
86  ofile, vars, firstValuePrinted, ',',
87  [sr,this] (auto &output, auto &namedVar) { output << namedVar.second(sr); }
88  );
89 
90  printSeparatedValues<NamedMultiVar, char>(
91  ofile, multiVars, firstValuePrinted, ',',
92  [sr,this] (auto &output, auto &namedMultiVar)
93  {
94  std::vector<double> values = namedMultiVar.second(sr);
95 
96  output << '"';
97 
98  printSeparatedValues<double, char>(
99  output, values, false, ',',
100  [this] (auto &output, auto &x) { output << x; }
101  );
102 
103  output << '"';
104  }
105  );
106 
107  ofile << std::endl;
108 }
ofstream output
std::vector< NamedMultiVar > multiVars
Definition: CSVMaker.h:24
std::ofstream ofile
Definition: CSVMaker.h:21
std::vector< NamedVar > vars
Definition: CSVMaker.h:23
caf::StandardRecord * sr
void ana::CSVMaker::setCut ( const Cut cut)

Definition at line 132 of file CSVMaker.cxx.

References cut.

Referenced by exporter_fd(), and exporter_nd().

133 {
134  this->cut = std::make_unique<Cut>(cut);
135 }
std::unique_ptr< Cut > cut
Definition: CSVMaker.h:20
void ana::CSVMaker::setPrecision ( int  precision)

Definition at line 58 of file CSVMaker.cxx.

References ofile.

59 {
60  ofile << std::setprecision(precision);
61 }
std::ofstream ofile
Definition: CSVMaker.h:21
void ana::SpectrumLoaderBase::SetSpillCut ( const SpillCut cut)
inherited

Definition at line 64 of file SpectrumLoaderBase.cxx.

References ana::assert(), cut, ana::SpectrumLoaderBase::fGone, ana::SpectrumLoaderBase::fSpillCut, and ana::SpectrumLoaderBase::WildcardOrSAMQuery().

Referenced by Ana2017_box_opening_macro(), Ana2017_sb_opening_macro(), Ana2018_box_opening_macro(), AnaResultsLoad(), BlessedPlotsLoad(), caf_nue_data_mc(), caf_numu_fd_validation_data(), caf_numu_fd_validation_MC(), caf_numu_fd_validation_MC_no_tau(), caf_numu_nd_cutflow(), caf_numu_nuenergy_vs_xy(), caf_numu_reco_minus_true(), caf_numu_sensitivity(), caf_numu_sensitivity_no_tau(), caf_numu_validation(), caf_numu_vars(), CalcCutVals(), compare_cos_numi(), Compare_Spectra(), ComparisonPlots_Data(), CosmicPred(), CreateAndFillSpectra(), CutFlow_Cosmic(), CutFlow_Data(), CutFlow_NearDet(), CutTableLoad(), datamc_ND_numu_kinematics(), datamc_ND_numu_kinematics_FHC(), datamc_ND_numu_kinematics_FHC_pTBins(), datamc_ND_numu_kinematics_FHC_REW(), datamc_ND_numu_kinematics_FHC_REW_pTBins(), datamc_ND_numu_kinematics_REW(), datamc_ND_numu_kinematics_RHC(), datamc_ND_numu_kinematics_RHC_pTBins(), datamc_ND_numu_kinematics_RHC_REW(), datamc_ND_numu_kinematics_RHC_REW_pTBins(), dataprocess_numuccinc(), DataVtxDistributionLoad(), demo_trivial_xsec_analysis(), drawIntensityEffect_2019(), drawLongTerm(), drawLongTerm_2019(), drawShortTerm_2019(), drawTimePlots(), drawVsPOT(), EnergyCont_macro(), energyResolution(), estimate_energy(), Evaluate_BDTMLP_Algs_Spectra(), ExampleCode(), exporter_fd(), exporter_nd(), ExtendedAxesLoad(), FD_Data_PosComp(), FDDataMC(), FDDataMCSystBandLoad(), FillSpectra(), FitSystEffectsLoad(), genie_syst_make(), get_cosmic_sample(), get_cosmic_spectra(), get_data_and_cosmic(), get_data_histogram(), get_fd_dataspectrum(), get_numi_data_histogram(), get_numu_data_histogram(), get_spectra_2dplots(), getCrossSectionAnalysis_Spectra(), getCrossSectionAnalysis_Spectra_systematics(), getCrossSectionAnalysisSpectra(), getData(), getFitTemplates(), GetHistsFD(), GetHistsND(), getSpectra_ForFitting(), getStabilitySpectra(), hadEFrac_nd_data_mc_systs(), hyperon_nom_macro(), make_DataMCComp_numu(), make_decomp(), make_michel(), make_nue_ana2018_pot(), make_nue_ana2019_epoch7d_pot(), make_nue_ana2019_epoch8b_pot(), make_nue_ana2019_fhc_ub_pot(), make_nue_ana2019_rhc_ub_pot(), make_nue_thirdana_pot(), make_numu_thirdana_pot(), make_nus17_pot(), make_pi0_xcheck(), make_pid(), make_quantiles_histogram_2020(), make_RHC_WrongSign_Nue(), make_RHC_WrongSign_Numu_MC(), make_RHC_WrongSign_Numu_Pd4_6Data(), make_RHC_WrongSign_Numu_Pd7dData(), make_RHC_WrongSign_Numu_Pd8Data(), make_RHC_WrongSign_NumuQ1(), make_RHC_WrongSign_NumuQ2(), make_RHC_WrongSign_NumuQ3(), make_RHC_WrongSign_NumuQ4(), make_rhcpred_2017(), make_rockpred_2017(), make_xsec_tuning_hists_mp5(), make_xsec_wgts_2018_hists(), MakeCosmics(), MakeNus17CosBkgd(), MakeNus17Prediction(), MakeNus18CosBkgd(), MakeNus18ExtrapPred(), MakeNus18SidebandPred(), MakeNusPrediction(), ana::MakeQuantileHistogram(), ana::MakeTextListFileHelper(), MakeUnoscPlots(), mrbrem_get_initial_spectra(), mrbrem_get_reweighted_spectra(), MRDiFStudy_FHC_Step1(), MRDiFStudy_FHC_Step2(), MRDiFStudy_RHC_Step1(), MRDiFStudy_RHC_Step2(), mre_blessed(), mre_comp_split(), ND_DataMC(), ND_DataMC_Comp_Systs(), NDDataMC(), NDDataMCSystBandLoad(), neutKEsyst(), neutronE_macro(), nue_data_mc_validation(), nue_decomp_scales(), nue_fd_mc_validation(), nue_michelDataMC(), NuMu2019_BasicPIDPlots_ND(), NuMu2019_BasicPIDPlots_Spectrum(), NuMu2020_BasicPIDPlots_FD(), NuMu2020_BasicPIDPlots_ND(), NuMu2020_BasicPIDPlots_Spectrum(), NuMu2020_TrimCAFs(), numu_cut_flow(), numu_data_mc_validation(), numu_validation_numuvars(), NumuCosmic(), nus17_box_opening(), nus17_fd_cut_tables(), nus17_fd_cut_tables2D(), nus17_fiducial_accounting(), nus18_box_opening(), nus_ana01_box_opening(), nus_ana01_sideband_box_opening(), pi0_xcheck(), PositionComparison(), ppfx_make_systs(), ppfx_smooth_weights_save(), preselection_cutflow(), resolutionscript(), resolutionspectrums(), rock(), saveSpectraForUnf(), sidebandfittest(), SideBandLoad(), signal_count(), specprod_numuccinc(), specprod_systematics(), Syst(), SystematicComp(), SystsBirksLoad(), SystsCalibAbsLoad(), SystsCalibAbsLoad17(), SystsCalibAbsMethod17(), SystsCalibRelLoad(), SystsCalibRelLoad17(), SystsNoiseLoad(), SystsPPFXLoad17(), test_genieweights(), test_predictionscalecomp(), test_xsecanalysis(), TrimCAFs(), uncertainty1png(), uncertainty2png(), and validation_numu_nd().

65  {
66  assert(!fGone);
67  fSpillCut = std::make_unique<SpillCut>(cut);
68  }
bool fGone
Has Go() been called? Can&#39;t add more histograms after that.
std::unique_ptr< SpillCut > fSpillCut
Cut applied to the spill branch for every event.
const Cut cut
Definition: exporter_fd.C:30
assert(nhit_max >=nhit_nbins)
IFileSource * ana::SpectrumLoaderBase::WildcardOrSAMQuery ( const std::string str) const
protectedinherited

Figure out if str is a wildcard or SAM query and return a source.

Definition at line 72 of file SpectrumLoaderBase.cxx.

References e, cet::getenv(), MECModelEnuComparisons::i, ProjMan::ifdh, PandAna.Demos.demo_prong::limit, ana::FileListSource::NFiles(), PandAna.reco_validation.add_data::offset, runNovaSAM::ret, and update_sam_good_runs_metadata::stride.

Referenced by ProducingSA(), ana::SpectrumLoaderBase::SetSpillCut(), ana::SpectrumLoaderBase::SpectrumLoaderBase(), and useBDTG().

73  {
74  int stride = -1;
75  int offset = -1;
76  int limit = -1;
77  if(getenv("CAFANA_STRIDE")){
78  stride = atoi(getenv("CAFANA_STRIDE"));
79  if(stride > 1 && getenv("CAFANA_OFFSET")){
80  offset = atoi(getenv("CAFANA_OFFSET"));
81  }
82  }
83  if(getenv("CAFANA_LIMIT")){
84  limit = atoi(getenv("CAFANA_LIMIT"));
85  }
86 
87  // stat() blows up on strings with spaces
88  if(str.find(' ') == std::string::npos){
89  WildcardSource* ret = new WildcardSource(str, stride, offset, limit);
90  if(ret->NFiles() > 0) return ret;
91  delete ret;
92  }
93 
94  // Maybe this the name of a SAM project?
95  {
96  IFDHSilent silent; // the usual case is for this to fail
98 
99  // findProject always gives back an address just by gluing bits together.
100  // (a tad annoying, because it _does_ go and look for the project,
101  // and even would print its 'didn't-find-this-project' error out to stderr
102  // if not for the IFDHSilent, but without scraping its stderr
103  // there's no way to know whether the project is there or not--
104  // you still get the URL.)
105  // however, the WebAPI call looking for the /status will return a 404 if
106  // the project doesn't exist. (suggested by Robert I. in INC000000925362.)
107  try
108  {
109  ifdh_util_ns::WebAPI webapi(i.findProject(str, getenv("SAM_STATION")) + "/status");
110  return new SAMProjectSource(str);
111  }
112  catch (ifdh_util_ns::WebAPIException &e)
113  {
114  ;
115  }
116  }
117 
118  // Maybe this is a SAM dataset or query?
119  return new SAMQuerySource(str, stride, offset, limit);
120  }
std::string getenv(std::string const &name)
ifdh
Definition: ProjMan.py:8
Float_t e
Definition: plot.C:35

Member Data Documentation

std::unique_ptr<Cut> ana::CSVMaker::cut
protected

Definition at line 20 of file CSVMaker.h.

Referenced by HandleRecord(), and setCut().

double ana::SpectrumLoaderBase::fBeamNue
protectedinherited
ExposureSource ana::SpectrumLoaderBase::fExposureSource
protectedinherited
std::unique_ptr<IFileSource> ana::SpectrumLoaderBase::fFileSource
protectedinherited
bool ana::SpectrumLoaderBase::fGone
protectedinherited
std::list<NuHistDef> ana::SpectrumLoaderBase::fNuHistDefs
protectedinherited
double ana::SpectrumLoaderBase::fPOT
protectedinherited

Accumulated by calls to GetNextFile.

Definition at line 160 of file SpectrumLoaderBase.h.

Referenced by ana::SpectrumLoaderBase::GetNextFile(), and ana::SpectrumLoaderBase::GetWeightedPOT().

double ana::SpectrumLoaderBase::fRunPOT
protectedinherited

Crude measure, not including spill cuts.

Definition at line 161 of file SpectrumLoaderBase.h.

Referenced by ana::SpectrumLoaderBase::GetNextFile(), ana::SpectrumLoader::Go(), and DecTreeLoader::HandlePOT().

double ana::SpectrumLoaderBase::fSingleNue
protectedinherited
double ana::SpectrumLoaderBase::fSinglePOT
protectedinherited
RecordMultiSink ana::SpectrumLoaderBase::fSink
protectedinherited
std::unordered_map<int, SystApplier*> ana::SpectrumLoaderBase::fSinksS
protectedinherited
std::unordered_map<std::pair<int, int>, CutApplier*> ana::SpectrumLoaderBase::fSinksSC
protectedinherited
std::unordered_map<std::tuple<int, int, int>, WeightApplier*> ana::SpectrumLoaderBase::fSinksSCW
protectedinherited
std::set<IRecordSink*> ana::SpectrumLoaderBase::fSpectrumSinks
protectedinherited
std::unique_ptr<SpillCut> ana::SpectrumLoaderBase::fSpillCut
protectedinherited
std::list<SpillHistDef> ana::SpectrumLoaderBase::fSpillHistDefs
protectedinherited
double ana::SpectrumLoaderBase::fWeightedPOT
protectedinherited

Definition at line 166 of file SpectrumLoaderBase.h.

Referenced by ana::SpectrumLoaderBase::GetWeightedPOT().

std::string ana::SpectrumLoaderBase::fWildcard
protectedinherited
std::vector<NamedMultiVar> ana::CSVMaker::multiVars
protected

Definition at line 24 of file CSVMaker.h.

Referenced by addMultiVar(), printHeader(), and printRow().

std::ofstream ana::CSVMaker::ofile
protected

Definition at line 21 of file CSVMaker.h.

Referenced by CSVMaker(), Go(), printHeader(), printRow(), and setPrecision().

std::vector<NamedVar> ana::CSVMaker::vars
protected

Definition at line 23 of file CSVMaker.h.

Referenced by addVar(), printHeader(), and printRow().


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