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

Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-08-04/CAFAna/Core/SpectrumLoader.h"

Inheritance diagram for ana::SpectrumLoader:
ana::SpectrumLoaderBase ana::ASCIIMaker ana::CSVMaker ana::SpectrumLoaderMockData ana::SpectrumLoaderNuTreeSpillCuts ana::TreeMaker CAFTreeMaker CAFTreeMaker DecTreeLoader

Public Member Functions

 SpectrumLoader (const std::string &wildcard, DataSource src=kBeam)
 
 SpectrumLoader (const std::vector< std::string > &fnames, DataSource src=kBeam)
 
 SpectrumLoader (SpectrumLoader &&)=default
 
SpectrumLoaderoperator= (SpectrumLoader &&)=default
 
virtual ~SpectrumLoader ()
 
virtual 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 AddReweightableSpectrum (ReweightableSpectrum &spect, const Var &var, 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, DataSource src=kBeam, int fileLimit=-1)
 Named constructor for SAM projects. More...
 

Public Attributes

friend Spectrum
 

Protected Member Functions

 SpectrumLoader (DataSource src=kBeam)
 
 SpectrumLoader (const SpectrumLoader &)=delete
 
SpectrumLoaderoperator= (const SpectrumLoader &)=delete
 
void AccumulateExposures (const caf::SRSpillProxy *spill) override
 
virtual void HandleFile (TFile *f, Progress *prog=0)
 
virtual void HandleRecord (caf::SRProxy *sr)
 
void StoreExposures ()
 Save results of AccumulateExposures into the individual spectra. More...
 
virtual void ReportExposures ()
 Prints POT/livetime info for all spectra. More...
 
IFileSourceWildcardOrSAMQuery (const std::string &str) const
 Figure out if str is a wildcard or SAM query and return a source. More...
 
virtual void RemoveSpectrum (Spectrum *)
 
virtual void RemoveReweightableSpectrum (ReweightableSpectrum *)
 
virtual void ReplaceSpectrum (Spectrum *oldspec, Spectrum *newspec)
 
int NFiles () const
 Forwards to fFileSource. More...
 
TFile * GetNextFile ()
 Forwards to fFileSource but also accumulates POT and livetime. More...
 

Protected Attributes

std::vector< CutfAllCuts
 All unique cuts contained in fHistDefs. More...
 
std::vector< double > fLivetimeByCut
 Indexing matches fAllCuts. More...
 
std::vector< double > fPOTByCut
 Indexing matches fAllCuts. More...
 
std::string fWildcard
 
std::unique_ptr< IFileSourcefFileSource
 
DataSource fSource
 
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
 
IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > fHistDefs
 All the spectra that need to be filled. More...
 
std::list< SpillHistDeffSpillHistDefs
 
std::list< NuHistDeffNuHistDefs
 
std::unique_ptr< SpillCutfSpillCut
 Cut applied to the spill branch for every event. More...
 

Detailed Description

Collaborates with Spectrum and OscillatableSpectrum to fill spectra from CAF files.

The outside user should just pass a filename, wildcard, SAM dataset name, or query to the constructor. Then construct all the spectra you need. They will register with this loader. Finally, calling Go will cause all the spectra to be filled at once. After this the loader may not be used again.

Definition at line 21 of file SpectrumLoader.h.

Constructor & Destructor Documentation

ana::SpectrumLoader::SpectrumLoader ( const std::string &  wildcard,
DataSource  src = kBeam 
)

Definition at line 22 of file SpectrumLoader.cxx.

Referenced by ana::SpectrumLoaderMockData::SpectrumLoaderMockData().

24  {
25  }
std::vector< std::string > wildcard(const std::string &wildcardString)
Definition: convert.C:9
SpectrumLoaderBase(DataSource src=kBeam)
Component of other constructors.
ana::SpectrumLoader::SpectrumLoader ( const std::vector< std::string > &  fnames,
DataSource  src = kBeam 
)

Definition at line 28 of file SpectrumLoader.cxx.

30  : SpectrumLoaderBase(fnames, src)
31  {
32  }
SpectrumLoaderBase(DataSource src=kBeam)
Component of other constructors.
ana::SpectrumLoader::SpectrumLoader ( SpectrumLoader &&  )
default
ana::SpectrumLoader::~SpectrumLoader ( )
virtual

Definition at line 53 of file SpectrumLoader.cxx.

54  {
55  }
ana::SpectrumLoader::SpectrumLoader ( DataSource  src = kBeam)
protected

Definition at line 35 of file SpectrumLoader.cxx.

36  : SpectrumLoaderBase(src)
37  {
38  }
SpectrumLoaderBase(DataSource src=kBeam)
Component of other constructors.
ana::SpectrumLoader::SpectrumLoader ( const SpectrumLoader )
protecteddelete

Member Function Documentation

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

Implements ana::SpectrumLoaderBase.

Reimplemented in ana::SpectrumLoaderNuTreeSpillCuts.

Definition at line 361 of file SpectrumLoader.cxx.

References ana::assert(), cut, fAllCuts, fLivetimeByCut, fPOTByCut, ana::SpectrumLoaderBase::fSource, MECModelEnuComparisons::i, ana::kCosmic, caf::kFARDET, livetime, ana::GenericCut< T >::Livetime(), ana::GenericCut< T >::POT(), and pot.

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

362  {
363  const unsigned int N = fAllCuts.size();
364  for(unsigned int i = 0; i < N; ++i){
365  const Cut& cut = fAllCuts[i];
366 
367  // FD MC is 1 neutrino-per-event, so the livetime count will be all
368  // screwed up there. Just go with 0, ie "unknown".
369  double livetime = 0;
370  if(spill->det != caf::kFARDET || !spill->ismc || fSource == kCosmic)
371  livetime = cut.Livetime(spill);
372 
373  // Not implemented -> no good way to count
374  if(livetime < 0){
375  if(spill->det == caf::kFARDET && !spill->ismc){
376  // People might well expect FD data to have a livetime, flag it
377  // so that we can make a warning about it at the end.
378  fLivetimeByCut[i] = -1;
379  }
380  // Otherwise the user probably doesn't care. Just don't sum it into the
381  // livetime
382  }
383  else{
384  // If a previous spill had no livetime and set the flag, and this one
385  // then does have good livetime, we're in big trouble.
386  assert(fLivetimeByCut[i] >= 0);
387 
388  // Livetime was fine, accumulate it
390  }
391 
392 
393  double pot = cut.POT(spill);
394  // Not implemented -> fall back to usual counting
395  if(pot < 0) pot = spill->spillpot;
396 
397  fPOTByCut[i] += pot;
398  }
399  }
std::vector< double > fLivetimeByCut
Indexing matches fAllCuts.
Far Detector at Ash River.
Definition: SREnums.h:11
GenericCut< caf::SRProxy > Cut
Representation of a cut (selection) to be applied to a caf::StandardRecord object.
Definition: Cut.h:96
std::vector< double > fPOTByCut
Indexing matches fAllCuts.
#define pot
const Cut cut
Definition: exporter_fd.C:30
double livetime
Definition: saveFDMCHists.C:21
assert(nhit_max >=nhit_nbins)
std::vector< Cut > fAllCuts
All unique cuts contained in fHistDefs.
void ana::SpectrumLoaderBase::AddReweightableSpectrum ( ReweightableSpectrum spect,
const Var var,
const Cut cut,
const SystShifts shift,
const Var wei 
)
virtualinherited

For use by the constructors of ReweightableSpectrum subclasses.

Definition at line 295 of file SpectrumLoaderBase.cxx.

References ana::ReweightableSpectrum::AddLoader(), om::cerr, cut, allTimeWatchdog::endl, ana::SpectrumLoaderBase::fGone, ana::SpectrumLoaderBase::fHistDefs, and PandAna.Demos.tute_pid_validation::var.

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

300  {
301  if(fGone){
302  std::cerr << "Error: can't add Spectra after the call to Go()" << std::endl;
303  abort();
304  }
305 
306  fHistDefs[shift][cut][wei][var].rwSpects.push_back(&spect);
307 
308  spect.AddLoader(this); // Remember we have a Go() pending
309  }
bool fGone
Has Go() been called? Can&#39;t add more histograms after that.
OStream cerr
Definition: OStream.cxx:7
IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > fHistDefs
All the spectra that need to be filled.
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.

Definition at line 239 of file SpectrumLoaderBase.cxx.

References ana::Spectrum::AddLoader(), om::cerr, cut, allTimeWatchdog::endl, ana::SpectrumLoaderBase::fGone, ana::SpectrumLoaderBase::fHistDefs, and PandAna.Demos.tute_pid_validation::var.

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

244  {
245  if(fGone){
246  std::cerr << "Error: can't add Spectra after the call to Go()" << std::endl;
247  abort();
248  }
249 
250  fHistDefs[shift][cut][wei][var].spects.push_back(&spect);
251 
252  spect.AddLoader(this); // Remember we have a Go() pending
253  }
bool fGone
Has Go() been called? Can&#39;t add more histograms after that.
OStream cerr
Definition: OStream.cxx:7
IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > fHistDefs
All the spectra that need to be filled.
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.

Definition at line 256 of file SpectrumLoaderBase.cxx.

References ana::Spectrum::AddLoader(), om::cerr, cut, allTimeWatchdog::endl, ana::SpectrumLoaderBase::fGone, ana::SpectrumLoaderBase::fHistDefs, and PandAna.Demos.tute_pid_validation::var.

261  {
262  if(fGone){
263  std::cerr << "Error: can't add Spectra after the call to Go()" << std::endl;
264  abort();
265  }
266 
267  fHistDefs[shift][cut][wei][var].spects.push_back(&spect);
268 
269  spect.AddLoader(this); // Remember we have a Go() pending
270  }
bool fGone
Has Go() been called? Can&#39;t add more histograms after that.
OStream cerr
Definition: OStream.cxx:7
IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > fHistDefs
All the spectra that need to be filled.
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, ana::SpectrumLoaderMockData, and ana::SpectrumLoaderNuTreeSpillCuts.

Definition at line 273 of file SpectrumLoaderBase.cxx.

References ana::SpectrumLoaderBase::fNuHistDefs.

278  {
279  fNuHistDefs.emplace_back(spect, var, cut, shift, wei);
280  }
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
SpectrumLoader ana::SpectrumLoader::FromSAMProject ( const std::string &  proj,
DataSource  src = kBeam,
int  fileLimit = -1 
)
static

Named constructor for SAM projects.

Definition at line 41 of file SpectrumLoader.cxx.

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

Referenced by test_sam_project().

44  {
46  ret.fSource = src;
47  ret.fWildcard = "project "+proj;
48  ret.fFileSource = std::unique_ptr<IFileSource>(new SAMProjectSource(proj, fileLimit));
49  return ret;
50  }
SpectrumLoader(const std::string &wildcard, DataSource src=kBeam)
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 334 of file SpectrumLoaderBase.cxx.

References ana::SpectrumLoaderBase::AccumulateExposures(), ana::assert(), om::cout, fillBadChanDBTables::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, isFHC, make_mec_shifts_plots::isRHC, findDuplicateFiles::key, caf::kUNKNOWN, getGoodRuns4SAM::n, cacheDefinitionData::prog, ana::Progress::SetProgress(), caf_analysis::spill, and febshutoff_auto::val.

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

335  {
336  TFile* f = fFileSource->GetNextFile();
337  if(!f) return 0; // out of files
338 
339  if(f->IsZombie()){
340  std::cout << "Bad file (zombie): " << f->GetName() << std::endl;
341  abort();
342  }
343 
344  // Crude way to count POT, at a file level without referring to spill cuts
345  TH1* hPOT = (TH1*)f->Get("TotalPOT");
346 
347  if(!hPOT){
348  std::cout << "Bad file (no POT tree): " << f->GetName() << std::endl;
349  abort();
350  }
351 
352  fRunPOT += hPOT->Integral();
353 
354  TKey *key = f->FindKey("TotalSinglePOT");
355 
356  // Initialise and only fill these histos if they exist
357  // We know they exist for nue overlay files
358  TH1* hSinglePOT = 0;
359  TH1* hTotalTrueSingleNue = 0;
360  TH1* hTotalTrueNonswapNue = 0;
361  if(key != 0){
362  hSinglePOT = (TH1*)f->Get("TotalSinglePOT");
363  assert(hSinglePOT);
364  fSinglePOT = hSinglePOT->Integral();
365 
366  hTotalTrueNonswapNue = (TH1*)f->Get("TotalTrueNonswapNue");
367  assert(hTotalTrueNonswapNue);
368  fBeamNue = hTotalTrueNonswapNue->Integral();
369 
370  hTotalTrueSingleNue = (TH1*)f->Get("TotalTrueSingleNue");
371  assert(hTotalTrueSingleNue);
372  fSingleNue = hTotalTrueSingleNue->Integral();
373  }
374  else{
375  delete hSinglePOT;
376  delete hTotalTrueSingleNue;
377  delete hTotalTrueNonswapNue;
378  }
379 
380  // Test for flat (trees are inside a directory) or nested (tree is at top
381  // level) cases.
382  TDirectory* spillDir = 0;
383  TTree* spillTree = 0;
384 
385  TObject* obj = f->Get("spillTree");
386  assert(obj); // Must exist in one form or the other
387 
388  // It might seem like you could use GetObject() to do the type-checking
389  // directly, but that method seems to have a memory leak in the case that
390  // the types don't match.
391  if(obj->ClassName() == std::string("TTree")){
392  // nested case
393  spillTree = (TTree*)obj;
394  }
395  else{
396  // FlatCAF case
397  spillDir = (TDirectory*)obj;
398  spillTree = (TTree*)spillDir->Get("spill");
399  assert(spillTree);
400  }
401 
402  // These aren't set in SRNeutrino, but we need them for flux systs, so
403  // learn them from SRSpill and copy them over.
404  //
405  // TODO TODO - remove this hack (and the equivalent in SpectrumLoader.cxx
406  // once they're available in the CAFs
407  bool isFHC = false, is0HC = false, isRHC = false;
409 
410  long n = 0;
411  caf::SRSpillProxy spill(spillDir, spillTree, "spill", n, 0);
412 
413  // FloatingExceptionOnNaN fpnan;
414 
415  // With multiple files exposure counting alternates with histogram filling,
416  // but with one file they deserve to be reported as two separate steps.
417  Progress* prog = 0;
418  if(fFileSource->NFiles() == 1)
419  prog = new Progress(TString::Format("Counting exposure from 1 file matching '%s'", fWildcard.c_str()).Data());
420 
421  const int Nentries = spillTree->GetEntries();
422 
423  double totFilePOT = 0;
424 
425  for(n = 0; n < Nentries; ++n){
426  if(!spillDir) spillTree->LoadTree(n); // nested mode
427 
428  if(!fSpillCut || (*fSpillCut)(&spill)){
430 
431  totFilePOT += spill.spillpot;
432 
433  // Only learn from good spills (bad spill could have bad beam?), and
434  // only once (efficiency)
435  if(!isFHC && !is0HC && !isRHC){
436  isFHC = spill.isFHC;
437  is0HC = spill.is0HC;
438  isRHC = spill.isRHC;
439  }
440  if (det == caf::kUNKNOWN)
441  det = spill.det;
442 
443  for(const SpillHistDef& hd: fSpillHistDefs){
444  // No cut, or cut passes
445  if(hd.cut(&spill)){
446  const double wei = hd.wei(&spill);
447  if(wei){
448  const double val = hd.var(&spill);
449  hd.h->Fill(val, wei);
450  }
451  } // end if(cut passes)
452  } // end for hd
453  }
454 
455  if(prog && n%100 == 0) prog->SetProgress(double(n)/Nentries);
456  } // end for n
457 
458  // The POT we want to use is either the singles POT in case of overlay files
459  // i.e the singlepot histo exists, or the standard after spill cuts
460  // Note: must be sure to run spill cuts for the overlays otherwise this gets
461  // reset to the fRunPOT
462  if(key != 0) fPOT += fSinglePOT;
463  else fPOT += totFilePOT;
464 
465  delete prog;
466  prog = 0;
467 
468  if(!fNuHistDefs.empty()){
469  // Test for flat (trees are inside a directory) or nested (tree is at top
470  // level) cases.
471 
472  TDirectory* nuDir = 0;
473  TTree* nuTree = 0;
474 
475  TObject* obj = f->Get("nuTree");
476  assert(obj); // Must exist in one form or the other
477 
478  // It might seem like you could use GetObject() to do the type-checking
479  // directly, but that method seems to have a memory leak in the case that
480  // the types don't match.
481  if(obj->ClassName() == std::string("TTree")){
482  // nested case
483  nuTree = (TTree*)obj;
484  }
485  else{
486  // FlatCAF case
487  nuDir = (TDirectory*)obj;
488  nuTree = (TTree*)spillDir->Get("nu");
489  assert(nuTree);
490  }
491 
492  const int NNuEntries = nuTree->GetEntries();
493 
494  long n = 0;
495  caf::SRNeutrinoProxy nu(nuDir, nuTree, nuDir ? "nu" : "mc.nu", n, 0);
496 
497  if(fFileSource->NFiles() == 1)
498  prog = new Progress(TString::Format("Filling from nuTree from 1 file matching '%s'", fWildcard.c_str()).Data());
499 
500 
501  for(n = 0; n < NNuEntries; ++n){
502  if(!nuDir) nuTree->LoadTree(n); // nested mode
503 
504  nu.isFHC = isFHC;
505  nu.is0HC = is0HC;
506  nu.isRHC = isRHC;
507  nu.det = det;
508 
509  for(const NuHistDef& hd: fNuHistDefs){
510  caf::SRProxySystController::BeginTransaction();
511 
512  double systWeight = 1;
513  // Can special-case nominal to not pay cost of Shift()
514  if(!hd.shift.IsNominal()){
515  hd.shift.Shift(&nu, systWeight);
516  }
517 
518  if(hd.cut(&nu)){
519  const double wei = hd.wei(&nu)*systWeight;
520  if(wei){
521  const double val = hd.var(&nu);
522  hd.spect.Fill(val, wei);
523  }
524  }
525 
526  // Return SRNeutrino to its unshifted form ready for the next
527  // histogram.
528  caf::SRProxySystController::Rollback();
529  } // end for hd
530 
531  if(prog && n%10000 == 0) prog->SetProgress(double(n)/NNuEntries);
532  } // end for n
533 
534  for(const NuHistDef& hd: fNuHistDefs) hd.spect.fPOT += totFilePOT;
535 
536  delete prog;
537  } // end if NuHistDefs
538 
539  return f;
540  }
Unknown detector.
Definition: SREnums.h:9
Det_t
Which NOvA detector?
Definition: SREnums.h:7
bool isFHC
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
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
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
double ana::SpectrumLoaderBase::GetWeightedPOT ( )
inherited
void ana::SpectrumLoader::Go ( )
overridevirtual

Load all the registered spectra.

Implements ana::SpectrumLoaderBase.

Reimplemented in ana::SpectrumLoaderMockData, and ana::CSVMaker.

Definition at line 66 of file SpectrumLoader.cxx.

References om::cerr, clear, cut, update_sam_good_runs_metadata::cuts, ana::Progress::Done(), allTimeWatchdog::endl, MakeMiniprodValidationCuts::f, fAllCuts, ana::SpectrumLoaderBase::fGone, ana::SpectrumLoaderBase::fHistDefs, fLivetimeByCut, ana::SpectrumLoaderBase::fNuHistDefs, genie::utils::style::Format(), fPOTByCut, ana::SpectrumLoaderBase::fSpillHistDefs, ana::SpectrumLoaderBase::fWildcard, ana::SpectrumLoaderBase::GetNextFile(), HandleFile(), ana::SpectrumLoaderBase::NFiles(), cacheDefinitionData::prog, ReportExposures(), ana::Progress::SetProgress(), StoreExposures(), and sum.

Referenced by Ana2017_box_opening_macro(), Ana2017_sb_opening_macro(), Ana2018_box_opening_macro(), AnaResultsLoad(), angle(), bdtstudyspectrums(), 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(), calculate_avg_nslcs(), ccpiinc_mc_studies(), compare_cos_numi(), Compare_Spectra(), ComparisonPlots_Data(), containmentstudy(), CosmicPred(), CreateAndFillSpectra(), CutFlow_Cosmic(), CutFlow_Data(), CutFlow_NearDet(), CutTableLoad(), CVNphoton(), CVNphotonSplit(), 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(), demo0(), demo1(), demo2(), demo2p5a(), demo3(), demo4(), demo5(), demo6(), demo_CPT(), demo_trivial_xsec_analysis(), drawIntensityEffect_2019(), drawLongTerm(), drawLongTerm_2019(), drawShortTerm_2019(), drawTimePlots(), drawVsPOT(), EnergyCont_macro(), energyResolution(), estimate_energy(), Evaluate_BDTMLP_Algs_Spectra(), event_reweighting_all_knobs(), ExtendedAxesLoad(), extract_resolution(), FD_Data_PosComp(), FDDataMCSystBandLoad(), FidOpt(), FidWShwCuts(), FillSpectra(), FitSystEffectsLoad(), genie_syst(), 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(), getBNBPlots(), getCrossSectionAnalysisSpectra(), getData(), GetHistsFD(), GetHistsND(), getSpectra_ForFitting(), getStabilitySpectra(), ana::CSVMaker::Go(), ana::SpectrumLoaderMockData::Go(), hadEFrac_nd_data_mc_systs(), hyperon_macro(), 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_quantiles_histogram_2020(), 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(), makeRealDataFluxes(), ana::MakeTextListFileHelper(), mcTruthPredictions(), MichelDecompTest(), modularextrap_demo_nue(), modularextrap_demo_numu(), 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(), mre_example_test(), multiverse_reweighting(), nc_bkgd_by_interaction_mode(), ncpi0HistoGrid2(), ND_DataMC(), ND_DataMC_Comp_Systs(), NDDataMCSystBandLoad(), neutKEsyst(), neutronE_macro(), nue_decomp_scales(), nue_fd_mc_validation(), nue_michelDataMC(), nue_pid_effs(), nue_pid_effs_miniprod(), nue_pid_effs_paper_numu_neweff(), NuMu2019_BasicPIDPlots_ND(), NuMu2019_BasicPIDPlots_Spectrum(), NuMu2020_BasicPIDPlots_ND(), NuMu2020_BasicPIDPlots_Spectrum(), NuMu2020_TrimCAFs(), numu_cut_flow(), numu_demo_split_plot(), numu_sig_nonmax(), 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(), pion_multiverse(), plot_kinematics_cafana(), PositionComparison(), ppfx_make_systs(), ppfx_smooth_weights_save(), PredictionInfo::PredictionInfo(), preselection_cutflow(), ReMId(), resolutionscript(), resolutionspectrums(), resolutionstudy(), rock(), runCheatDecomp(), runTwoSampleDecomp(), saveSpectraForUnf(), ShwZOpt(), sidebandfittest(), SideBandLoad(), signal_count(), specprod_numuccinc(), Syst(), SystematicComp(), SystsBirksLoad(), SystsCalibAbsLoad(), SystsCalibAbsLoad17(), SystsCalibAbsMethod17(), SystsCalibRelLoad(), SystsCalibRelLoad17(), SystsNoiseLoad(), SystsPPFXLoad17(), template_basic(), test_beam_errorband(), test_caf_validation_plots(), test_flux(), test_fluxhadr_prod_weights_Flux(), test_genie_systs(), test_genieweights(), test_mockdata(), test_multiverse_class(), test_nueextrapsyst(), test_nuwro(), test_predictionscalecomp(), test_sam(), test_sam_project(), test_systmultiverse(), timingPeak(), train_dectree_caf(), TrimCAFs(), twodstudyvtxcont(), validation_numu_nd(), and vertexstudy().

67  {
68  if(fGone){
69  std::cerr << "Error: can only call Go() once on a SpectrumLoader" << std::endl;
70  abort();
71  }
72  fGone = true;
73 
74  // Find all the unique cuts
75  std::set<Cut, CompareByID> cuts;
76  for(auto& shiftdef: fHistDefs)
77  for(auto& cutdef: shiftdef.second)
78  cuts.insert(cutdef.first);
79  for(const Cut& cut: cuts) fAllCuts.push_back(cut);
80 
81  fLivetimeByCut.resize(fAllCuts.size());
82  fPOTByCut.resize(fAllCuts.size());
83 
84 
85  const int Nfiles = NFiles();
86 
87  Progress* prog = 0;
88 
90 
91  int fileIdx = -1;
92  while(TFile* f = GetNextFile()){
93  ++fileIdx;
94 
95  if(Nfiles >= 0 && !prog){
96  std::string sum = TString::Format("Filling %lu spectra", fHistDefs.TotalSize()).Data();
97  if(Nfiles > 1){
98  if(!fSpillHistDefs.empty()){
99  sum += TString::Format(", %lu spillTree spectra", fSpillHistDefs.size()).Data();
100  }
101  if(!fNuHistDefs.empty()){
102  sum += TString::Format(", %lu nuTree spectra", fNuHistDefs.size()).Data();
103  }
104  }
105 
106  sum += TString::Format(" from %d files matching '%s'", Nfiles, fWildcard.c_str()).Data();
107  prog = new Progress(sum);
108  }
109 
110  HandleFile(f, Nfiles == 1 ? prog : 0);
111 
112  if(Nfiles > 1 && prog) prog->SetProgress((fileIdx+1.)/Nfiles);
113  } // end for fileIdx
114 
115  StoreExposures();
116 
117  if(prog){
118  prog->Done();
119  delete prog;
120  }
121 
122  ReportExposures();
123 
124  fHistDefs.RemoveLoader(this);
125  fHistDefs.Clear();
126  }
void StoreExposures()
Save results of AccumulateExposures into the individual spectra.
std::vector< double > fLivetimeByCut
Indexing matches fAllCuts.
TFile * GetNextFile()
Forwards to fFileSource but also accumulates POT and livetime.
bool fGone
Has Go() been called? Can&#39;t add more histograms after that.
vector< vector< double > > clear
OStream cerr
Definition: OStream.cxx:7
GenericCut< caf::SRProxy > Cut
Representation of a cut (selection) to be applied to a caf::StandardRecord object.
Definition: Cut.h:96
virtual void ReportExposures()
Prints POT/livetime info for all spectra.
std::vector< double > fPOTByCut
Indexing matches fAllCuts.
std::list< SpillHistDef > fSpillHistDefs
IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > fHistDefs
All the spectra that need to be filled.
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Cut cut
Definition: exporter_fd.C:30
virtual void HandleFile(TFile *f, Progress *prog=0)
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
int NFiles() const
Forwards to fFileSource.
std::vector< Cut > fAllCuts
All unique cuts contained in fHistDefs.
Double_t sum
Definition: plot.C:31
std::list< NuHistDef > fNuHistDefs
virtual bool ana::SpectrumLoaderBase::Gone ( ) const
inlinevirtualinherited
void ana::SpectrumLoader::HandleFile ( TFile *  f,
Progress prog = 0 
)
protectedvirtual

Definition at line 129 of file SpectrumLoader.cxx.

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

Referenced by Go(), ProducingSA(), tree_maker_simple(), and useBDTG().

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

Reimplemented in ana::TreeMaker, CAFTreeMaker, CAFTreeMaker, ana::ASCIIMaker, and ana::CSVMaker.

Definition at line 199 of file SpectrumLoader.cxx.

References om::cerr, om::cout, cut, caf::Proxy< caf::SRHeader >::det, allTimeWatchdog::endl, ana::ReweightableSpectrum::fHistD, ana::SpectrumLoaderBase::fHistDefs, ana::ReweightableSpectrum::fHistF, ana::Spectrum::Fill(), ana::SpectrumLoaderBase::fSpillCut, ana::CutVarCache< T, U >::Get(), caf::Proxy< caf::StandardRecord >::hdr, caf::Proxy< caf::SRSpill >::is0HC, caf::Proxy< caf::SRSpill >::isFHC, std::isinf(), std::isnan(), ana::SystShifts::IsNominal(), caf::Proxy< caf::SRSpill >::isRHC, caf::Proxy< caf::StandardRecord >::mc, caf::Proxy< caf::SRTruthBranch >::nnu, caf::Proxy< caf::SRTruthBranch >::nu, ana::ReweightableSpectrum::ReweightVar(), ana::SystShifts::Shift(), caf::Proxy< caf::StandardRecord >::spill, Munits::sr, febshutoff_auto::val, and PandAna.Demos.tute_pid_validation::var.

Referenced by HandleFile().

200  {
201  // First up, check this spill passes the global quality cuts
202  if(fSpillCut && !(*fSpillCut)(&sr->spill)) return;
203 
204  // Some shifts only adjust the weight, so they're effectively nominal, but
205  // aren't grouped with the other nominal histograms. Keep track of the
206  // results for nominals in these caches to speed those systs up.
207  CutVarCache<bool, Cut> nomCutCache;
208  CutVarCache<double, Var> nomWeiCache;
209  CutVarCache<double, Var> nomVarCache;
210 
211  // These aren't set in SRNeutrino, but we need them for flux systs, so copy
212  // them over from SRSpill.
213  //
214  // TODO TODO - remove this hack (and the equivalent in
215  // SpectrumLoaderBase.cxx) once they're available in the CAFs
216  if(sr->mc.nnu > 0){
217  sr->mc.nu[0].isFHC = bool(sr->spill.isFHC);
218  sr->mc.nu[0].is0HC = bool(sr->spill.is0HC);
219  sr->mc.nu[0].isRHC = bool(sr->spill.isRHC);
220  sr->mc.nu[0].det = caf::Det_t(sr->hdr.det);
221  }
222 
223  for(auto& shiftdef: fHistDefs){
224  caf::SRProxySystController::BeginTransaction();
225 
226  const SystShifts& shift = shiftdef.first;
227 
228  // Need to provide a clean slate for each new set of systematic shifts to
229  // work from. Copying the whole StandardRecord is pretty expensive, so
230  // modify it in place and revert it afterwards.
231 
232  bool shifted = false;
233 
234  double systWeight = 1;
235  // Can special-case nominal to not pay cost of Shift()
236  if(!shift.IsNominal()){
237  shift.Shift(sr, systWeight);
238  // If there were only weighting systs applied then the cached nominal
239  // values are still valid.
240  shifted = caf::SRProxySystController::AnyShifted();
241  }
242 
243  for(auto& cutdef: shiftdef.second){
244  const Cut& cut = cutdef.first;
245 
246  const bool pass = shifted ? cut(sr) : nomCutCache.Get(cut, sr);
247  // Cut failed, skip all the histograms that depended on it
248  if(!pass) continue;
249 
250  for(auto& weidef: cutdef.second){
251  const Var& weivar = weidef.first;
252 
253  double wei = shifted ? weivar(sr) : nomWeiCache.Get(weivar, sr);
254 
255  if(wei < 0){
256  std::cerr << "Negative weight " << wei
257  << " returned from Var";
258  std::cerr << std::endl;
259  abort();
260  }
261 
262  wei *= systWeight;
263  if(wei == 0) continue;
264 
265  for(auto& vardef: weidef.second){
266  if(vardef.first.IsMulti()){
267  for(double val: vardef.first.GetMultiVar()(sr)){
268  for(Spectrum* s: vardef.second.spects)
269  s->Fill(val, wei);
270  }
271  continue;
272  }
273 
274  const Var& var = vardef.first.GetVar();
275 
276  const double val = shifted ? var(sr) : nomVarCache.Get(var, sr);
277 
278  if(std::isnan(val) || std::isinf(val)){
279  std::cerr << "Warning: Bad value: " << val
280  << " returned from a Var. The input variable(s) could "
281  << "be NaN in the CAF, or perhaps your "
282  << "Var code computed 0/0?";
283  std::cout << ". Not filling into this histogram for this slice." << std::endl;
284  continue;
285  }
286 
287  for(Spectrum* s: vardef.second.spects) s->Fill(val, wei);
288 
289  for(ReweightableSpectrum* rw: vardef.second.rwSpects){
290  const double yval = rw->ReweightVar()(sr);
291 
292  if(std::isnan(yval) || std::isinf(yval)){
293  std::cerr << "Warning: Bad value: " << yval
294  << " for reweighting Var";
295  std::cout << ". Not filling into histogram." << std::endl;
296  continue;
297  }
298 
299  if(rw->fHistD) rw->fHistD->Fill(val, yval, wei);
300  if(rw->fHistF) rw->fHistF->Fill(val, yval, wei);
301  } // end for rw
302  } // end for vardef
303  } // end for weidef
304  } // end for cutdef
305 
306  // Return StandardRecord to its unshifted form ready for the next
307  // histogram.
308  caf::SRProxySystController::Rollback();
309  } // end for shiftdef
310  }
caf::Proxy< caf::SRSpill > spill
Definition: SRProxy.h:1986
Det_t
Which NOvA detector?
Definition: SREnums.h:7
int isinf(const stan::math::var &a)
Definition: std_isinf.hpp:16
caf::Proxy< bool > is0HC
Definition: SRProxy.h:1282
GenericVar< caf::SRProxy > Var
Representation of a variable to be retrieved from a caf::StandardRecord object.
Definition: Var.h:76
caf::Proxy< caf::SRHeader > hdr
Definition: SRProxy.h:1980
caf::Proxy< std::vector< caf::SRNeutrino > > nu
Definition: SRProxy.h:569
OStream cerr
Definition: OStream.cxx:7
GenericCut< caf::SRProxy > Cut
Representation of a cut (selection) to be applied to a caf::StandardRecord object.
Definition: Cut.h:96
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
caf::Proxy< short int > nnu
Definition: SRProxy.h:568
int isnan(const stan::math::var &a)
Definition: std_isnan.hpp:18
std::unique_ptr< SpillCut > fSpillCut
Cut applied to the spill branch for every event.
caf::Proxy< bool > isFHC
Definition: SRProxy.h:1283
const XML_Char * s
Definition: expat.h:262
OStream cout
Definition: OStream.cxx:6
IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > fHistDefs
All the spectra that need to be filled.
caf::Proxy< caf::SRTruthBranch > mc
Definition: SRProxy.h:1981
const Cut cut
Definition: exporter_fd.C:30
caf::Proxy< bool > isRHC
Definition: SRProxy.h:1284
static constexpr Double_t sr
Definition: Munits.h:164
caf::Proxy< caf::Det_t > det
Definition: SRProxy.h:226
int ana::SpectrumLoaderBase::NFiles ( ) const
protectedinherited

Forwards to fFileSource.

Definition at line 328 of file SpectrumLoaderBase.cxx.

References ana::SpectrumLoaderBase::fFileSource.

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

329  {
330  return fFileSource->NFiles();
331  }
std::unique_ptr< IFileSource > fFileSource
SpectrumLoader& ana::SpectrumLoader::operator= ( SpectrumLoader &&  )
default
SpectrumLoader& ana::SpectrumLoader::operator= ( const SpectrumLoader )
protecteddelete
void ana::SpectrumLoaderBase::RemoveReweightableSpectrum ( ReweightableSpectrum spect)
protectedvirtualinherited

Definition at line 322 of file SpectrumLoaderBase.cxx.

References ana::SpectrumLoaderBase::fHistDefs.

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

323  {
324  fHistDefs.Erase(spect);
325  }
IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > fHistDefs
All the spectra that need to be filled.
void ana::SpectrumLoaderBase::RemoveSpectrum ( Spectrum spect)
protectedvirtualinherited

Reimplemented in ana::SpectrumLoaderMockData.

Definition at line 283 of file SpectrumLoaderBase.cxx.

References ana::SpectrumLoaderBase::fHistDefs.

Referenced by ana::SpectrumLoaderMockData::RemoveSpectrum().

284  {
285  fHistDefs.Erase(spect);
286  }
IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > fHistDefs
All the spectra that need to be filled.
void ana::SpectrumLoaderBase::ReplaceSpectrum ( Spectrum oldspec,
Spectrum newspec 
)
protectedvirtualinherited

Definition at line 289 of file SpectrumLoaderBase.cxx.

References ana::SpectrumLoaderBase::fHistDefs.

290  {
291  fHistDefs.Replace(oldspec, newspec);
292  }
IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > fHistDefs
All the spectra that need to be filled.
void ana::SpectrumLoader::ReportExposures ( )
protectedvirtual

Prints POT/livetime info for all spectra.

Definition at line 313 of file SpectrumLoader.cxx.

References om::cout, allTimeWatchdog::endl, ana::SpectrumLoaderBase::fHistDefs, ana::SpectrumLoaderBase::fPOT, ana::SpectrumLoaderBase::fRunPOT, ana::SpectrumLoaderBase::fSpillCut, makeTrainCVSamples::int, it, and confusionMatrixTree::t.

Referenced by Go().

314  {
315  // The POT member variables we use here were filled as part of
316  // SpectrumLoaderBase::GetNextFile() as we looped through the input files.
317 
318  // Let's just assume no-one is using the Cut::POT() function yet, so this
319  // printout remains relevant...
320 
321  if(fSpillCut && fRunPOT > 0){
322  std::cout << "Total " << fRunPOT << " POT, of which "
323  << fPOT << " (" << int(100*fPOT/fRunPOT+.5)
324  << "%) passes quality cuts." << std::endl;
325  }
326  else{
327  std::cout << "Total " << fRunPOT << " POT." << std::endl;
328  fPOT = fRunPOT;
329  }
330 
331  std::vector<Spectrum*> spectra;
332  fHistDefs.GetSpectra(spectra);
333  std::vector<ReweightableSpectrum*> rwSpectra;
334  fHistDefs.GetReweightableSpectra(rwSpectra);
335  // Normally using a floating-point number as a key is a bad idea. But this
336  // seems to work, and if it goes wrong all it breaks is this printout.
337  std::map<double, int> livetimes;
338  for(Spectrum* s: spectra) ++livetimes[s->Livetime()];
339  for(ReweightableSpectrum* rs: rwSpectra) ++livetimes[rs->fLivetime];
340 
341  if(livetimes.size() == 1){
342  const double t = livetimes.begin()->first;
343  if(t > 0)
344  std::cout << "Total livetime " << t << " seconds." << std::endl;
345  else
346  std::cout << "Unknown livetime." << std::endl;
347  }
348  else{
349  std::cout << "Livetimes:" << std::endl;
350  for(auto it: livetimes){
351  std::cout << " " << it.second << " spectra: ";
352  if(it.first > 0)
353  std::cout << it.first << " seconds" << std::endl;
354  else
355  std::cout << "unknown" << std::endl;
356  }
357  }
358  }
set< int >::iterator it
double fRunPOT
Crude measure, not including spill cuts.
std::unique_ptr< SpillCut > fSpillCut
Cut applied to the spill branch for every event.
const XML_Char * s
Definition: expat.h:262
OStream cout
Definition: OStream.cxx:6
IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > fHistDefs
All the spectra that need to be filled.
double fPOT
Accumulated by calls to GetNextFile.
void ana::SpectrumLoaderBase::SetSpillCut ( const SpillCut cut)
inherited

Definition at line 180 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(), 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(), 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().

181  {
182  assert(!fGone);
183  fSpillCut = std::make_unique<SpillCut>(cut);
184  }
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)
void ana::SpectrumLoader::StoreExposures ( )
protected

Save results of AccumulateExposures into the individual spectra.

Definition at line 402 of file SpectrumLoader.cxx.

References om::cout, cut, allTimeWatchdog::endl, fAllCuts, ana::SpectrumLoaderBase::fHistDefs, ana::ReweightableSpectrum::fLivetime, ana::Spectrum::fLivetime, fLivetimeByCut, ana::ReweightableSpectrum::fPOT, ana::Spectrum::fPOT, fPOTByCut, MECModelEnuComparisons::i, ana::GenericCut< T >::ID(), livetime, and pot.

Referenced by Go().

403  {
404  std::map<int, double> livetime;
405  std::map<int, double> pot;
406 
407  for(unsigned int i = 0; i < fAllCuts.size(); ++i){
408  const int id = fAllCuts[i].ID();
409  if(fLivetimeByCut[i] < 0){
410  fLivetimeByCut[i] = 0;
411  std::cout << "WARNING: no way to compute livetime for FD data spectrum. If you want a livetime you need to be applying one of the cuts from TimingCuts.h or similar. You probably should be anyway to remove bad data near the spill ends." << std::endl;
412  }
413  livetime.emplace(id, fLivetimeByCut[i]);
414  pot.emplace(id, fPOTByCut[i]);
415  }
416 
417 
418  for(auto& shiftdef: fHistDefs){
419  for(auto& cutdef: shiftdef.second){
420  const Cut& cut = cutdef.first;
421  const int id = cut.ID();
422 
423  for(auto& weidef: cutdef.second){
424  for(auto& vardef: weidef.second){
425  for(Spectrum* s: vardef.second.spects){
426  s->fPOT += pot[id];
427  s->fLivetime += livetime[id];
428  }
429 
430  for(ReweightableSpectrum* rw: vardef.second.rwSpects){
431  rw->fPOT += pot[id];
432  rw->fLivetime += livetime[id];
433  }
434  }
435  }
436  }
437  }
438  }
::xsd::cxx::tree::id< char, ncname > id
Definition: Database.h:165
std::vector< double > fLivetimeByCut
Indexing matches fAllCuts.
GenericCut< caf::SRProxy > Cut
Representation of a cut (selection) to be applied to a caf::StandardRecord object.
Definition: Cut.h:96
std::vector< double > fPOTByCut
Indexing matches fAllCuts.
const XML_Char * s
Definition: expat.h:262
#define pot
OStream cout
Definition: OStream.cxx:6
IDMap< SystShifts, IDMap< Cut, IDMap< Var, IDMap< VarOrMultiVar, SpectList > > > > fHistDefs
All the spectra that need to be filled.
const Cut cut
Definition: exporter_fd.C:30
double livetime
Definition: saveFDMCHists.C:21
std::vector< Cut > fAllCuts
All unique cuts contained in fHistDefs.
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 188 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 ana::SpectrumLoaderBase::Gone(), ProducingSA(), ana::SpectrumLoaderBase::SetSpillCut(), ana::SpectrumLoaderBase::SpectrumLoaderBase(), and useBDTG().

189  {
190  int stride = -1;
191  int offset = -1;
192  int limit = -1;
193  if(getenv("CAFANA_STRIDE")){
194  stride = atoi(getenv("CAFANA_STRIDE"));
195  if(stride > 1 && getenv("CAFANA_OFFSET")){
196  offset = atoi(getenv("CAFANA_OFFSET"));
197  }
198  }
199  if(getenv("CAFANA_LIMIT")){
200  limit = atoi(getenv("CAFANA_LIMIT"));
201  }
202 
203  // stat() blows up on strings with spaces
204  if(str.find(' ') == std::string::npos){
205  WildcardSource* ret = new WildcardSource(str, stride, offset, limit);
206  if(ret->NFiles() > 0) return ret;
207  delete ret;
208  }
209 
210  // Maybe this the name of a SAM project?
211  {
212  IFDHSilent silent; // the usual case is for this to fail
214 
215  // findProject always gives back an address just by gluing bits together.
216  // (a tad annoying, because it _does_ go and look for the project,
217  // and even would print its 'didn't-find-this-project' error out to stderr
218  // if not for the IFDHSilent, but without scraping its stderr
219  // there's no way to know whether the project is there or not--
220  // you still get the URL.)
221  // however, the WebAPI call looking for the /status will return a 404 if
222  // the project doesn't exist. (suggested by Robert I. in INC000000925362.)
223  try
224  {
225  ifdh_util_ns::WebAPI webapi(i.findProject(str, getenv("SAM_STATION")) + "/status");
226  return new SAMProjectSource(str);
227  }
228  catch (ifdh_util_ns::WebAPIException &e)
229  {
230  ;
231  }
232  }
233 
234  // Maybe this is a SAM dataset or query?
235  return new SAMQuerySource(str, stride, offset, limit);
236  }
std::string getenv(std::string const &name)
ifdh
Definition: ProjMan.py:8
Float_t e
Definition: plot.C:35

Member Data Documentation

std::vector<Cut> ana::SpectrumLoader::fAllCuts
protected

All unique cuts contained in fHistDefs.

Definition at line 60 of file SpectrumLoader.h.

Referenced by AccumulateExposures(), Go(), and StoreExposures().

double ana::SpectrumLoaderBase::fBeamNue
protectedinherited
std::unique_ptr<IFileSource> ana::SpectrumLoaderBase::fFileSource
protectedinherited
bool ana::SpectrumLoaderBase::fGone
protectedinherited
IDMap<SystShifts, IDMap<Cut, IDMap<Var, IDMap<VarOrMultiVar, SpectList> > > > ana::SpectrumLoaderBase::fHistDefs
protectedinherited
std::vector<double> ana::SpectrumLoader::fLivetimeByCut
protected

Indexing matches fAllCuts.

Definition at line 61 of file SpectrumLoader.h.

Referenced by AccumulateExposures(), Go(), and StoreExposures().

std::list<NuHistDef> ana::SpectrumLoaderBase::fNuHistDefs
protectedinherited
double ana::SpectrumLoaderBase::fPOT
protectedinherited
std::vector<double> ana::SpectrumLoader::fPOTByCut
protected

Indexing matches fAllCuts.

Definition at line 62 of file SpectrumLoader.h.

Referenced by AccumulateExposures(), Go(), and StoreExposures().

double ana::SpectrumLoaderBase::fRunPOT
protectedinherited

Crude measure, not including spill cuts.

Definition at line 130 of file SpectrumLoaderBase.h.

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

double ana::SpectrumLoaderBase::fSingleNue
protectedinherited
double ana::SpectrumLoaderBase::fSinglePOT
protectedinherited
DataSource ana::SpectrumLoaderBase::fSource
protectedinherited

Definition at line 125 of file SpectrumLoaderBase.h.

Referenced by AccumulateExposures(), and FromSAMProject().

std::unique_ptr<SpillCut> ana::SpectrumLoaderBase::fSpillCut
protectedinherited
std::list<SpillHistDef> ana::SpectrumLoaderBase::fSpillHistDefs
protectedinherited
double ana::SpectrumLoaderBase::fWeightedPOT
protectedinherited

Definition at line 135 of file SpectrumLoaderBase.h.

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

std::string ana::SpectrumLoaderBase::fWildcard
protectedinherited
friend ana::SpectrumLoaderBase::Spectrum
inherited

Definition at line 41 of file SpectrumLoaderBase.h.

Referenced by ana::SpectrumLoaderMockData::AddSpectrum().


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