All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
core::ProcessorBase Class Referenceabstract

A generic tree-writing event-by-event processor. More...

#include <ProcessorBase.hh>

Inheritance diagram for core::ProcessorBase:
core::SelectionBase ana::ExampleAnalysis::ExampleSelection ana::SBNOsc::AuxDetSimChannelPrinter ana::SBNOsc::CaloPrinter ana::SBNOsc::CosmicArrivalTimes ana::SBNOsc::CRTHitTiming ana::SBNOsc::CRTSimHitViewer ana::SBNOsc::GetFV ana::SBNOsc::MCParticleTreePrinter ana::SBNOsc::NueSelection ana::SBNOsc::NumuReco ana::SBNOsc::NumuSelection ana::SBNOsc::OpDetBackTrackerPrinter ana::SBNOsc::OpDetWaveformMaker ana::SBNOsc::OpSimHitPrinter ana::SBNOsc::PandoraIDPrinter ana::SBNOsc::PandoraMetadataPrinter ana::SBNOsc::SimPhotonPrinter sbnana::TrackReducer

Public Member Functions

 ProcessorBase ()
 
virtual ~ProcessorBase ()
 
virtual void FillTree ()
 
virtual void FillRecoTree ()
 
virtual void EventCleanup ()
 
template<class T >
TBranch * AddBranch (std::string name, T *obj)
 
template<class T >
TBranch * AddRecoBranch (std::string name, T *obj)
 
virtual bool ProcessEvent (const gallery::Event &ev, const std::vector< event::Interaction > &truth, std::vector< event::RecoInteraction > &reco)=0
 

Public Attributes

std::vector
< event::RecoInteraction > * 
fReco
 Reco interaction list. More...
 

Protected Member Functions

virtual void Initialize (char *config=NULL)
 
virtual void Initialize (fhicl::ParameterSet *config=NULL)=0
 
virtual void Finalize ()=0
 
virtual void Setup (char *config=NULL)
 
virtual void Setup (fhicl::ParameterSet *config=NULL)
 
virtual void Teardown ()
 
void BuildEventTree (gallery::Event &ev)
 
void SetupServices (gallery::Event &ev)
 
void UpdateSubRuns (gallery::Event &ev)
 
void UpdateFileMeta (gallery::Event &ev)
 

Protected Attributes

unsigned long fEventIndex
 An incrementing index. More...
 
Experiment fExperimentID
 Experiment identifier. More...
 
ProviderManagerfProviderManager
 Interface for provider access. More...
 
std::string fOutputFilename
 The output filename. More...
 
std::string fProviderConfig
 A custom provider config fcl file. More...
 
std::vector< geo::BoxBoundedGeofActiveVolumes
 List of active volumes in configured detector. More...
 
bool fWriteTree
 Enable writing of the main tree. More...
 
TFile * fOutputFile
 The output ROOT file. More...
 
TTree * fTree
 The output ROOT tree. More...
 
event::EventfEvent
 The standard output event data structure. More...
 
bool fWriteRecoTree
 Enable writing of the reco tree. More...
 
TTree * fRecoTree
 The output reco ROOT tree. More...
 
event::RecoEventfRecoEvent
 The standard output reco event data structure. More...
 
TTree * fSubRunTree
 Subrun output tree. More...
 
SubRunfSubRun
 Standard output subrun structure. More...
 
TTree * fFileMetaTree
 File metadata output tree. More...
 
FileMetafFileMeta
 standard output file metadata structure More...
 
TParameter< int > * fExperimentParameter
 Saves value of experiment enum. More...
 
std::set< std::pair< int, int > > fSubRunCache
 Cache stored subruns. More...
 
art::InputTag fTruthTag
 art tag for MCTruth information More...
 
art::InputTag fFluxTag
 art tag for MCFlux information More...
 
std::vector< art::InputTag > fWeightTags
 art tag(s) for MCEventWeight information More...
 
art::InputTag fMCTrackTag
 art tag for MCTrack More...
 
art::InputTag fMCShowerTag
 art tag for MCShower More...
 
art::InputTag fMCParticleTag
 art tag for MCParticle More...
 
std::string fGeneratorProcess
 process_name of process used to run genie. Used to extract subrun/POT information More...
 

Friends

class ProcessorBlock
 

Detailed Description

A generic tree-writing event-by-event processor.

Definition at line 47 of file ProcessorBase.hh.

Constructor & Destructor Documentation

core::ProcessorBase::ProcessorBase ( )

Constructor

Definition at line 51 of file ProcessorBase.cxx.

52  : fEventIndex(0), fOutputFilename("output.root"), fProviderManager(NULL) {}
unsigned long fEventIndex
An incrementing index.
ProviderManager * fProviderManager
Interface for provider access.
std::string fOutputFilename
The output filename.
core::ProcessorBase::~ProcessorBase ( )
virtual

Destructor

Definition at line 55 of file ProcessorBase.cxx.

55 {}

Member Function Documentation

template<class T >
TBranch* core::ProcessorBase::AddBranch ( std::string  name,
T *  obj 
)
inline

Add a branch to the output tree.

Called in user subclasses to augment the default event tree. This mirrors the TTree::Branch API.

Parameters
nameThe branch name
objA pointer to the object
Returns
A pointer to the created TBranch (we retain ownership)

Definition at line 82 of file ProcessorBase.hh.

82  {
83  return fTree->Branch(name.c_str(), obj);
84  }
TTree * fTree
The output ROOT tree.
then echo fcl name
template<class T >
TBranch* core::ProcessorBase::AddRecoBranch ( std::string  name,
T *  obj 
)
inline

Add a branch to the output reco tree.

Called in user subclasses to augment the default event tree. This mirrors the TTree::Branch API.

Parameters
nameThe branch name
objA pointer to the object
Returns
A pointer to the created TBranch (we retain ownership)

Definition at line 97 of file ProcessorBase.hh.

97  {
98  return fRecoTree->Branch(name.c_str(), obj);
99  }
TTree * fRecoTree
The output reco ROOT tree.
then echo fcl name
void core::ProcessorBase::BuildEventTree ( gallery::Event &  ev)
protected

Populate the default event tree variables.

Parameters
evThe current gallery event

Definition at line 349 of file ProcessorBase.cxx.

349  {
350  // Add any new subruns to the subrun tree
351  UpdateSubRuns(ev);
352  UpdateFileMeta(ev);
353 
354  // Get MC truth information
355  gallery::Handle<std::vector<simb::MCTruth>> mctruths_handle;
356  bool mctruth_is_valid = ev.getByLabel(fTruthTag, mctruths_handle);
357 
358  gallery::Handle<std::vector<simb::MCParticle> > mcparticle_list;
359  ev.getByLabel(fMCParticleTag, mcparticle_list);
360  bool mcparticles_is_valid = mcparticle_list.isValid();
361 
362  gallery::Handle<std::vector<simb::GTruth> > gtruths_handle;
363  ev.getByLabel(fTruthTag, gtruths_handle);
364  bool genie_truth_is_valid = gtruths_handle.isValid();
365 
366  // Get MCEventWeight information
367  std::vector<gallery::Handle<std::vector<evwgh::MCEventWeight> > > wghs;
368 
369  if (!fWeightTags.empty()) {
370  for (auto const &weightTag: fWeightTags) {
371  gallery::Handle<std::vector<evwgh::MCEventWeight> > this_wgh;
372  bool hasWeights = ev.getByLabel(weightTag, this_wgh);
373  // coherence check
374  if (hasWeights && mctruth_is_valid) {
375  assert(this_wgh->size() == mctruths_handle->size());
376  }
377  // store the weights
378  wghs.push_back(this_wgh);
379  }
380  }
381 
382  // Get MCFlux information
383  gallery::Handle<std::vector<simb::MCFlux> > mcflux_handle;
384  bool flux_is_valid = ev.getByLabel(fFluxTag, mcflux_handle);
385  // Check MCFlux information
386  if (flux_is_valid && mctruth_is_valid) {
387  assert(mctruths_handle->size() == mcflux_handle->size());
388  }
389 
390 
391  fTree->GetEntry(fEventIndex);
392 
393  // Populate event tree
395 
396  auto const& evaux = ev.eventAuxiliary();
397  fEvent->metadata.run = evaux.run();
398  fEvent->metadata.subrun = evaux.subRun();
399  fEvent->metadata.eventID = evaux.event();
400  fEvent->metadata.fileEntry = ev.fileEntry();
401 
402  if (mctruth_is_valid) {
403  // get associations from MCTruth information to truth
404  art::FindManyP<simb::MCParticle, sim::GeneratedParticleInfo> truth_to_particles(mctruths_handle, ev, fMCParticleTag);
405  unsigned n_truth = mctruths_handle->size();
406  for (size_t i=0; i<n_truth; i++) {
407 
408  event::Interaction interaction;
409  interaction.index = i;
410 
411  auto const& mctruth = mctruths_handle->at(i);
412 
413  // TODO: What to do with cosmic MC?
414  // For now, ignore them
415  if (!mctruth.NeutrinoSet()) continue;
416 
417  // Combine Weights
418  if (!wghs.empty()) {
419  size_t wgh_idx = 0;
420  // Loop through weight generators, which have a list of weights per truth
421  //
422  // NOTE: The code allows for multiple different weight generators to produce weights with the same name.
423  // What will happen is that the same-named weights from differetn producers will be placed in the same
424  // vector in the "weights" map below. The order in which weights from different producers are combined
425  // should be consistent from event to event so that correlations are preserved between events. This
426  // is ensured in the current implementation by making sure that the different weight tags in "wghs"
427  // are always ordered in the same way.
428  for (auto const& wgh : wghs) {
429  for (const std::pair<std::string, std::vector<double> >& this_wgh : wgh->at(i).fWeight) {
430  // If we haven't seen this name before, make a new vector with the name
431  if (interaction.weights.count(this_wgh.first) == 0) {
432  interaction.weights.insert({
433  this_wgh.first,
434  std::vector<float>(this_wgh.second.begin(), this_wgh.second.end())
435  });
436  }
437  // If we have seen the name before, append this instance to the last one
438  else {
439  interaction.weights.at(this_wgh.first).insert(
440  interaction.weights.at(this_wgh.first).end(),
441  this_wgh.second.begin(),
442  this_wgh.second.end());
443  }
444  }
445  }
446  }
447 
448  if (mcflux_handle.isValid()) {
449  const simb::MCFlux& flux = mcflux_handle->at(i);
450  interaction.neutrino.parentPDG = flux.fptype;
451  interaction.neutrino.parentDecayMode = flux.fndecay;
452  interaction.neutrino.parentDecayVtx = \
453  TVector3(flux.fvx, flux.fvy, flux.fvz);
454  interaction.neutrino.baseline = flux.fdk2gen + flux.fgen2vtx;
455  interaction.neutrino.initpdg = flux.fntype;
456  }
457 
458  TLorentzVector q_labframe;
459 
460  // get the list of MCParticles to be considered for this interaction
461  std::vector<art::Ptr<simb::MCParticle>> this_mcparticle_list;
462  std::vector<const sim::GeneratedParticleInfo *> this_mcparticle_assns;
463  if (mcparticles_is_valid) {
464  this_mcparticle_list = truth_to_particles.at(i);
465  this_mcparticle_assns = truth_to_particles.data(i);
466  }
467 
468  if (mctruth.NeutrinoSet()) {
469  // Neutrino
470  const simb::MCNeutrino& nu = mctruth.GetNeutrino();
471  interaction.neutrino.isnc = nu.CCNC() && (nu.Mode() != simb::kWeakMix);
472  interaction.neutrino.iscc = (!nu.CCNC()) && (nu.Mode() != simb::kWeakMix);
473  interaction.neutrino.pdg = nu.Nu().PdgCode();
474  interaction.neutrino.targetPDG = nu.Target();
475  interaction.neutrino.genie_intcode = nu.Mode();
476  interaction.neutrino.bjorkenX = nu.X();
477  interaction.neutrino.inelasticityY = nu.Y();
478  interaction.neutrino.Q2 = nu.QSqr();
479  interaction.neutrino.w = nu.W();
480  interaction.neutrino.energy = nu.Nu().EndMomentum().Energy();
481  interaction.neutrino.momentum = nu.Nu().EndMomentum().Vect();
482  interaction.neutrino.position = nu.Nu().Position().Vect();
483 
484  // Primary lepton
485  const simb::MCParticle& lepton = nu.Lepton();
486  interaction.lepton.pdg = lepton.PdgCode();
487  interaction.lepton.energy = lepton.Momentum(0).Energy();
488  interaction.lepton.momentum = lepton.Momentum(0).Vect();
489  interaction.lepton.start = lepton.Position(0).Vect();
490  interaction.lepton.status_code = lepton.StatusCode();
491  interaction.lepton.is_primary = (lepton.Process() == "primary");
492 
493  // match the MCTruth particle to the MCParticle list -- only the list has trajectory information
494  const simb::MCParticle* lepton_traj = Genie2G4MCParticle(lepton, mctruth, this_mcparticle_list, this_mcparticle_assns);
495 
496  // TODO: why aren't there matches sometimes?
497  if (lepton_traj != NULL) {
498  interaction.lepton.length = util::MCParticleLength(*lepton_traj);
499  if (fProviderManager != NULL) {
501  }
502  else {
504  }
505  // also get the end point from the trajectory
506  interaction.lepton.end = lepton_traj->EndPosition().Vect();
507  }
508  else {
509  interaction.lepton.contained_length = 0;
510  interaction.lepton.length = 0;
511  // if we couldn't find a trajectory, set end to start
512  interaction.lepton.end = interaction.lepton.start;
513  }
514 
515  q_labframe = nu.Nu().EndMomentum() - lepton.Momentum(0);
516  interaction.neutrino.q0_lab = q_labframe.E();
517  interaction.neutrino.modq_lab = q_labframe.P();
518  }
519 
520  // Get CCQE energy from lepton info
521  interaction.neutrino.eccqe = \
522  util::ECCQE(interaction.lepton.momentum, interaction.lepton.energy);
523 
524  // Hadronic system
525  //
526  // We need to look at the Genie MCParticles because we may want
527  // to look at truth information like (e.g.) intermeidate-state pions
528  // which are re-absorbed in the nucleus.
529  //
530  // Whenever we can though, try to match the true "gen" information to g4
531  // information
532  for (int iparticle=0; iparticle<mctruth.NParticles(); iparticle++) {
533  const simb::MCParticle& particle = mctruth.GetParticle(iparticle);
535  if (particle.Process() != "primary") {
536  continue;
537  }
538  fsp.pdg = particle.PdgCode();
539  fsp.energy = particle.Momentum(0).Energy();
540  fsp.momentum = particle.Momentum(0).Vect();
541  fsp.start = particle.Position(0).Vect();
542  fsp.status_code = particle.StatusCode();
543  fsp.is_primary = (particle.Process() == "primary");
544 
545  fsp.length = 0;
546  fsp.contained_length = 0;
547  // length information needs G4
548  const simb::MCParticle *traj = Genie2G4MCParticle(particle, mctruth, this_mcparticle_list, this_mcparticle_assns);
549  if (traj != NULL) {
550  fsp.length = util::MCParticleLength(*traj);
551  if (fProviderManager != NULL) {
553  }
554  else {
556  }
557  }
558  interaction.finalstate.push_back(fsp);
559  }
560  interaction.nfinalstate = interaction.finalstate.size();
561 
562  // GENIE specific
563  if (genie_truth_is_valid) {
564  auto const& gtruth = gtruths_handle->at(i);
565  TLorentzVector q_nucframe(q_labframe);
566  // This nucleon momentum should be added to MCNeutrino so we don't
567  // have to rely on GTruth
568  const TLorentzVector& nucP4 = gtruth.fHitNucP4;
569  TVector3 nuc_boost(nucP4.BoostVector());
570  q_nucframe.Boost(nuc_boost);
571  interaction.neutrino.modq = q_nucframe.P();
572  interaction.neutrino.q0 = q_nucframe.E();
573  }
574 
575  fEvent->truth.push_back(interaction);
576  }
577  }
578 
579  fEvent->ntruth = fEvent->truth.size();
580 }
TVector3 momentum
Neutrino three-momentum.
Definition: Event.hh:91
Metadata metadata
Event metadata.
Definition: Event.hh:230
double MCParticleLength(const simb::MCParticle &particle)
Definition: Interaction.cxx:65
TVector3 momentum
Three-momentum.
Definition: Event.hh:129
float energy
Energy.
Definition: Event.hh:128
int pdg
PDG Code.
Definition: Event.hh:127
Final state particle information.
Definition: Event.hh:104
art::InputTag fTruthTag
art tag for MCTruth information
FinalStateParticle lepton
The primary final state lepton.
Definition: Event.hh:153
int parentDecayMode
Parent hadron/muon decay mode.
Definition: Event.hh:94
TTree * fTree
The output ROOT tree.
Neutrino neutrino
The neutrino.
Definition: Event.hh:152
float Q2
Q squared.
Definition: Event.hh:82
std::vector< geo::BoxBoundedGeo > fActiveVolumes
List of active volumes in configured detector.
TVector3 start
Start position in detector coords [cm].
Definition: Event.hh:130
int parentPDG
Parent hadron/muon PDG.
Definition: Event.hh:93
std::vector< art::InputTag > fWeightTags
art tag(s) for MCEventWeight information
bool iscc
CC (true) or NC/interference (false)
Definition: Event.hh:75
float length
Total length of the energy depositions [cm].
Definition: Event.hh:140
size_t ntruth
Size of truth.
Definition: Event.hh:231
event::Event * fEvent
The standard output event data structure.
int status_code
Status code returned by GENIE (see GenieStatus enum)
Definition: Event.hh:142
float modq_lab
|q|, lab frame
Definition: Event.hh:86
TVector3 end
End position in detector coords (may be outside of AV) [cm].
Definition: Event.hh:131
int fileEntry
Index of of file.
Definition: Event.hh:53
void UpdateSubRuns(gallery::Event &ev)
int eventID
Event ID.
Definition: Event.hh:52
float bjorkenX
Bjorken x.
Definition: Event.hh:80
float eccqe
CCQE energy.
Definition: Event.hh:89
unsigned long fEventIndex
An incrementing index.
int targetPDG
PDG code of struck target.
Definition: Event.hh:78
bool is_primary
Whether the process producing the particle was &quot;primary&quot;.
Definition: Event.hh:141
double MCParticleContainedLength(const simb::MCParticle &particle, const std::vector< geo::BoxBoundedGeo > &active_volumes)
Definition: Interaction.cxx:77
Experiment fExperimentID
Experiment identifier.
art::InputTag fFluxTag
art tag for MCFlux information
float inelasticityY
Inelasticity y.
Definition: Event.hh:81
float w
Hadronic invariant mass W.
Definition: Event.hh:87
size_t index
Index in the MCTruth.
Definition: Event.hh:169
float baseline
Distance from decay to interaction.
Definition: Event.hh:96
Experiment experiment
Experiment identifier.
Definition: Event.hh:235
size_t nfinalstate
Size of finalstate.
Definition: Event.hh:155
const simb::MCParticle * Genie2G4MCParticle(const simb::MCParticle &genie_part, const simb::MCTruth &mctruth, const std::vector< art::Ptr< simb::MCParticle >> &g4_mcparticles, const std::vector< const sim::GeneratedParticleInfo * > infos)
float q0
q0, struck nucleon rest frame
Definition: Event.hh:83
float modq
|q|, struck nucleon rest frame
Definition: Event.hh:84
std::vector< FinalStateParticle > finalstate
Other final state particles.
Definition: Event.hh:154
float q0_lab
q0, lab frame
Definition: Event.hh:85
double ECCQE(const TVector3 &l_momentum, double l_energy, double energy_distortion, double angle_distortion)
float energy
Neutrino energy (GeV)
Definition: Event.hh:90
TVector3 position
Neutrino interaction position.
Definition: Event.hh:92
ProviderManager * fProviderManager
Interface for provider access.
art::InputTag fMCParticleTag
art tag for MCParticle
int pdg
PDG code of probe neutrino.
Definition: Event.hh:77
BEGIN_PROLOG SN nu
int subrun
Subrun ID.
Definition: Event.hh:51
int initpdg
Initial PDG code of probe neutrino.
Definition: Event.hh:76
All truth information associated with one neutrino interaction.
Definition: Event.hh:150
static const int kUnfilled
Value for unfilled variables.
Definition: Event.hh:32
int genie_intcode
Interaction mode (as for LArSoft MCNeutrino::Mode() )
Definition: Event.hh:79
void UpdateFileMeta(gallery::Event &ev)
TVector3 parentDecayVtx
Parent hadron/muon decay vertex.
Definition: Event.hh:95
bool isnc
same as LArSoft &quot;ccnc&quot; - 0=CC, 1=NC
Definition: Event.hh:74
std::map< std::string, std::vector< float > > weights
Definition: Event.hh:164
std::vector< Interaction > truth
All truth interactions.
Definition: Event.hh:232
int run
Run ID.
Definition: Event.hh:50
void core::ProcessorBase::EventCleanup ( )
virtual

Cleanup any objects that were filled per event

Definition at line 69 of file ProcessorBase.cxx.

69  {
71  fEvent->metadata.Init();
72  fEvent->truth.clear();
73  fEvent->reco.clear();
74 }
void Init()
Definition: Event.hh:44
Metadata metadata
Event metadata.
Definition: Event.hh:230
event::Event * fEvent
The standard output event data structure.
event::RecoEvent * fRecoEvent
The standard output reco event data structure.
std::vector< RecoInteraction > reco
Reconstructed interactions.
Definition: Event.hh:234
Metadata metadata
Event metadata.
Definition: Event.hh:214
std::vector< Interaction > truth
All truth interactions.
Definition: Event.hh:232
void core::ProcessorBase::FillRecoTree ( )
virtual

Fill the reco tree.

Definition at line 64 of file ProcessorBase.cxx.

64  {
65  fRecoTree->Fill();
66 }
TTree * fRecoTree
The output reco ROOT tree.
void core::ProcessorBase::FillTree ( )
virtual

Fill the tree and increment the event index.

Definition at line 58 of file ProcessorBase.cxx.

58  {
59  fTree->Fill();
60  fEventIndex++;
61 }
TTree * fTree
The output ROOT tree.
unsigned long fEventIndex
An incrementing index.
virtual void core::ProcessorBase::Finalize ( )
protectedpure virtual
void core::ProcessorBase::Initialize ( char *  config = NULL)
protectedvirtual

Perform user-level initialization.

Parameters
configA configuration, as a JSON filename.

Definition at line 77 of file ProcessorBase.cxx.

77  {
78  fhicl::ParameterSet* cfg = LoadConfig(config);
79  Initialize(cfg);
80 }
virtual void Initialize(char *config=NULL)
fhicl::ParameterSet * LoadConfig(char *configfile)
Definition: Loader.cxx:80
virtual void core::ProcessorBase::Initialize ( fhicl::ParameterSet *  config = NULL)
protectedpure virtual
virtual bool core::ProcessorBase::ProcessEvent ( const gallery::Event &  ev,
const std::vector< event::Interaction > &  truth,
std::vector< event::RecoInteraction > &  reco 
)
pure virtual
void core::ProcessorBase::Setup ( char *  config = NULL)
protectedvirtual

Perform framework-level initialization.

Parameters
configA configuration as a JSON filename.

Definition at line 83 of file ProcessorBase.cxx.

83  {
84  fhicl::ParameterSet* cfg = LoadConfig(config);
85  Setup(cfg);
86 }
fhicl::ParameterSet * LoadConfig(char *configfile)
Definition: Loader.cxx:80
virtual void Setup(char *config=NULL)
void core::ProcessorBase::Setup ( fhicl::ParameterSet *  config = NULL)
protectedvirtual

Perform framework-level initialization.

Parameters
configA configuration as a JSON object

Definition at line 89 of file ProcessorBase.cxx.

89  {
90  // Load configuration file
91  if (config) {
92  fExperimentID = \
93  static_cast<Experiment>(config->get<int>("ExperimentID", kExpOther));
94  fTruthTag = { config->get<std::string>("MCTruthTag", "generator") };
95  fGeneratorProcess = config->get<std::string>("GeneratorProcess", "GenieGen");
96  fFluxTag = { config->get<std::string>("MCFluxTag", "generator") };
97  fMCTrackTag = { config->get<std::string>("MCTrackTag", "mcreco") };
98  fMCShowerTag = { config->get<std::string>("MCShowerTag", "mcreco") };
99  fMCParticleTag = { config->get<std::string>("MCParticleTag", "largeant") };
100  fOutputFilename = config->get<std::string>("OutputFile", "output.root");
101  fProviderConfig = config->get<std::string>("ProviderConfigFile", "");
102 
103  fWriteTree = config->get<bool>("WriteTree", true);
104  fWriteRecoTree = config->get<bool>("WriteRecoTree", true);
105 
106  // Get the event weight tags (can supply multiple producers)
107  fWeightTags = {};
108  if (config->has_key("MCWeightTags")) {
109  if (config->is_key_to_atom("MCWeightTags")) {
110  std::string weight_tag = config->get<std::string>("MCWeightTags");
111  fWeightTags = { { weight_tag } };
112  }
113  else if (config->is_key_to_sequence("MCWeightTags")) {
114  std::vector<std::string> weight_tags = \
115  config->get<std::vector<std::string> >("MCWeightTags");
116  for (size_t i=0; i<weight_tags.size(); i++) {
117  fWeightTags.emplace_back(weight_tags[i]);
118  }
119  }
120  }
121  }
122  // Default -- no config file provided
123  else {
125  fTruthTag = { "generator" };
126  fGeneratorProcess = "GenieGen";
127  fFluxTag = { "generator" };
128  fWeightTags = {};
129  fMCTrackTag = { "mcreco" };
130  fMCShowerTag = { "mcreco" };
131  fMCParticleTag = { "largeant" };
132  fOutputFilename = "output.root";
133  }
134 
135  // Set up the provider manager for known experiments
136  std::vector<Experiment> exps = ProviderManager::GetValidExperiments();
137  if (std::find(exps.begin(), exps.end(), fExperimentID) != exps.end()) {
138  fProviderManager = new ProviderManager(fExperimentID, fProviderConfig);
139 
140  // setup the volumes for keeping track of length
141  for (auto const &cryo: fProviderManager->GetGeometryProvider()->IterateCryostats()) {
143  tend = fProviderManager->GetGeometryProvider()->end_TPC(cryo.ID());
144 
145  // make each cryostat volume a box enclosing all tpc volumes
146  double XMin = std::min_element(iTPC, tend, [](auto &lhs, auto &rhs) { return lhs.MinX() < rhs.MinX(); })->MinX();
147  double YMin = std::min_element(iTPC, tend, [](auto &lhs, auto &rhs) { return lhs.MinY() < rhs.MinY(); })->MinY();
148  double ZMin = std::min_element(iTPC, tend, [](auto &lhs, auto &rhs) { return lhs.MinZ() < rhs.MinZ(); })->MinZ();
149 
150  double XMax = std::max_element(iTPC, tend, [](auto &lhs, auto &rhs) { return lhs.MaxX() < rhs.MaxX(); })->MaxX();
151  double YMax = std::max_element(iTPC, tend, [](auto &lhs, auto &rhs) { return lhs.MaxY() < rhs.MaxY(); })->MaxY();
152  double ZMax = std::max_element(iTPC, tend, [](auto &lhs, auto &rhs) { return lhs.MaxZ() < rhs.MaxZ(); })->MaxZ();
153 
154  fActiveVolumes.emplace_back(XMin, XMax, YMin, YMax, ZMin, ZMax);
155  }
156 
157  }
158  else {
159  std::cout << "ProcessorBase::Setup: "
160  << "Unknown experiment, no ProviderManager is available."
161  << std::endl;
162  }
163 
164  // Open the output file and create the standard event trees
165  fOutputFile = TFile::Open(fOutputFilename.c_str(), "recreate");
166 
167  fTree = new TTree("sbnana", "SBN Analysis Tree");
168  fEvent = new event::Event();
169  fTree->Branch("events", &fEvent);
170  fReco = &fEvent->reco;
171 
172  fRecoTree = new TTree("sbnreco", "SBN Reco Event Tree");
174  fRecoTree->Branch("reco_events", &fRecoEvent);
175 
176  // Create the output subrun tree
177  fSubRunTree = new TTree("sbnsubrun", "SBN Analysis Subrun Tree");
178  fSubRunTree->AutoSave("overwrite");
179  fSubRun = new SubRun();
180  fSubRunTree->Branch("subruns", &fSubRun);
181 
182  // Create the file metadata tree
183  fFileMetaTree = new TTree("sbnfilemeta", "SBN Analysis File Metadata Tree");
184  fFileMeta = new FileMeta();
185  fFileMetaTree->Branch("filemeta", &fFileMeta);
186 
187  // save the experiment ID
189  fExperimentParameter->Write();
190 
191  // setup the connection to the sqlite database
192  tkeyvfs_init();
193 }
TTree * fSubRunTree
Subrun output tree.
Experiment
Definition: Experiment.hh:13
TParameter< int > * fExperimentParameter
Saves value of experiment enum.
art::InputTag fTruthTag
art tag for MCTruth information
TTree * fTree
The output ROOT tree.
std::vector< event::RecoInteraction > * fReco
Reco interaction list.
TFile * fOutputFile
The output ROOT file.
std::vector< geo::BoxBoundedGeo > fActiveVolumes
List of active volumes in configured detector.
std::vector< art::InputTag > fWeightTags
art tag(s) for MCEventWeight information
The reconstructed event data definition.
Definition: Event.hh:208
const geo::GeometryCore * GetGeometryProvider() const
event::Event * fEvent
The standard output event data structure.
TPC_iterator begin_TPC() const
Returns an iterator pointing to the first TPC in the detector.
event::RecoEvent * fRecoEvent
The standard output reco event data structure.
std::string fProviderConfig
A custom provider config fcl file.
bool fWriteTree
Enable writing of the main tree.
SubRun * fSubRun
Standard output subrun structure.
Experiment fExperimentID
Experiment identifier.
art::InputTag fFluxTag
art tag for MCFlux information
FileMeta * fFileMeta
standard output file metadata structure
std::vector< RecoInteraction > reco
Reconstructed interactions.
Definition: Event.hh:234
art::InputTag fMCShowerTag
art tag for MCShower
The standard subrun data definition.
Definition: SubRun.hh:23
The standard event data definition.
Definition: Event.hh:228
IteratorBox< cryostat_iterator,&GeometryCore::begin_cryostat,&GeometryCore::end_cryostat > IterateCryostats() const
Enables ranged-for loops on all cryostats of the detector.
std::string fGeneratorProcess
process_name of process used to run genie. Used to extract subrun/POT information ...
TTree * fRecoTree
The output reco ROOT tree.
static std::vector< Experiment > GetValidExperiments()
ProviderManager * fProviderManager
Interface for provider access.
bool fWriteRecoTree
Enable writing of the reco tree.
art::InputTag fMCParticleTag
art tag for MCParticle
std::string fOutputFilename
The output filename.
TTree * fFileMetaTree
File metadata output tree.
Forward iterator browsing all geometry elements in the detector.
Definition: GeometryCore.h:727
art::InputTag fMCTrackTag
art tag for MCTrack
BEGIN_PROLOG could also be cout
Metadata for each input file.
Definition: FileMeta.hh:16
TPC_iterator end_TPC() const
Returns an iterator pointing after the last TPC in the detector.
void core::ProcessorBase::SetupServices ( gallery::Event &  ev)
protected

Definition at line 312 of file ProcessorBase.cxx.

312  {
313  if (fProviderManager != NULL) {
315  }
316 }
ProviderManager * fProviderManager
Interface for provider access.
void SetupServices(gallery::Event &ev)
void core::ProcessorBase::Teardown ( )
protectedvirtual

Perform framework-level finalization.

Definition at line 297 of file ProcessorBase.cxx.

297  {
298  // Write the standard tree and close the output file
299  fOutputFile->cd();
300  if (fWriteTree) {
301  fTree->Write("sbnana", TObject::kOverwrite);
302  }
303  if (fWriteRecoTree) {
304  fRecoTree->Write("sbnreco", TObject::kOverwrite);
305  }
306  fSubRunTree->Write("sbnsubrun", TObject::kOverwrite);
307  fFileMetaTree->Write("sbnfilemeta", TObject::kOverwrite);
308  fOutputFile->Purge();
309  fOutputFile->Close();
310 }
TTree * fSubRunTree
Subrun output tree.
TTree * fTree
The output ROOT tree.
TFile * fOutputFile
The output ROOT file.
bool fWriteTree
Enable writing of the main tree.
TTree * fRecoTree
The output reco ROOT tree.
bool fWriteRecoTree
Enable writing of the reco tree.
TTree * fFileMetaTree
File metadata output tree.
void core::ProcessorBase::UpdateFileMeta ( gallery::Event &  ev)
protected

Definition at line 241 of file ProcessorBase.cxx.

241  {
242  // FIXME: this is also a bit of a hack
243  static TFile *last_tfile = NULL; // only set at initialization
244 
245  TFile *this_file = ev.getTFile();
246  // it's a new file!
247  if (this_file != last_tfile) {
248  unsigned n_gen_event = 0;
249  unsigned n_event = 0;
250 
251  // get the SQLite thingy
252  art::SQLite3Wrapper sqliteDB(this_file, "RootFileDB", SQLITE_OPEN_READONLY);
253  sqlite3 *db = sqliteDB;
254  // add to the registry and parse yourself
255  fhicl::ParameterSetRegistry::importFrom(db);
256  fhicl::ParameterSetRegistry::stageIn();
257 
258  // TODO: make this better
259  //
260  std::unordered_map<fhicl::ParameterSetID, fhicl::ParameterSet, fhicl::detail::HashParameterSetID> registry;
261  using namespace cet::sqlite;
262  query_result<std::string, std::string> entriesToStageIn;
263  entriesToStageIn << select("*").from(db, "ParameterSets");
264 
265  cet::transform_all(entriesToStageIn,
266  std::inserter(registry, std::begin(registry)),
267  [](auto const& row) {
268  auto const& [idString, psBlob] = row;
269  fhicl::ParameterSet pset;
270  fhicl::make_ParameterSet(psBlob, pset);
271  return std::make_pair(fhicl::ParameterSetID{idString}, pset);
272  });
273 
274  for (auto const& pr: registry) {
275  const fhicl::ParameterSet pset = pr.second;
276  if (pset.has_key("source") && pset.has_key("source.maxEvents") && pset.has_key("source.module_type")) {
277  int max_events = pset.get<int>("source.maxEvents");
278  std::string module_type = pset.get<std::string>("source.module_type");
279  // this will show up once for every input file
280  if (module_type == "EmptyEvent") {
281  n_gen_event += max_events;
282  std::cout << "FILEMETA: " << max_events << std::endl;
283  }
284  }
285  }
286  n_event = ev.numberOfEventsInFile();
287  std::cout << "FILEMETA nevent: " << n_event << std::endl;
288  std::cout << "FILEMETA ngenevent: " << n_gen_event << std::endl;
289  *fFileMeta = {n_event, n_gen_event};
290  fFileMetaTree->Fill();
291  }
292  // set the file for next time
293  last_tfile = ev.getTFile();
294 }
FileMeta * fFileMeta
standard output file metadata structure
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
BEGIN_PROLOG triggeremu_data_config_icarus settings PMTADCthresholds sequence::icarus_stage0_multiTPC_TPC physics sequence::icarus_stage0_EastHits_TPC physics sequence::icarus_stage0_WestHits_TPC physics producers purityana0 module_type
TTree * fFileMetaTree
File metadata output tree.
height to which particles are projected pnfs larsoft persistent physics cosmics Fermilab CORSIKA standard He_showers_ * db
BEGIN_PROLOG could also be cout
void core::ProcessorBase::UpdateSubRuns ( gallery::Event &  ev)
protected

Update subrun list to include subruns for this event's file.

Parameters
evThe current gallery event

Definition at line 195 of file ProcessorBase.cxx.

195  {
196  // FIXME: HACK
197  static TFile *last_tfile = NULL; // only set at initialization
198 
199  TFile *this_file = ev.getTFile();
200  // it's a new file!
201  if (this_file != last_tfile) {
202  // FIXME: This should use official gallery subrun access once available.
203  // N.B. Implementation is fragile and depends on the naming of the subrun
204  // producer (generator__GenieGen), can be made a fcl parameter.
205  TTree* srtree = (TTree*) ev.getTFile()->Get("SubRuns");
206 
207  art::SubRunAuxiliary* sraux = new art::SubRunAuxiliary;
208  srtree->SetBranchAddress("SubRunAuxiliary", &sraux);
209 
210  for (long i=0; i<srtree->GetEntries(); i++) {
211  srtree->GetEntry(i);
212 
213  int runid = sraux->run();
214  int subrunid = sraux->subRun();
215 
216  std::string totpot_str = "sumdata::POTSummary_generator__" + fGeneratorProcess + ".obj.totpot";
217  std::string totgoodpot_str = "sumdata::POTSummary_generator__" + fGeneratorProcess + ".obj.totgoodpot";
218  std::string totspills_str = "sumdata::POTSummary_generator__" + fGeneratorProcess + ".obj.totspills";
219  std::string goodspills_str = "sumdata::POTSummary_generator__" + fGeneratorProcess + ".obj.goodspills";
220 
221  TLeaf* potLeaf = srtree->GetLeaf(totpot_str.c_str());
222  float pot = potLeaf ? potLeaf->GetValue() : -1;
223  TLeaf* goodpotLeaf = srtree->GetLeaf(totgoodpot_str.c_str());
224  float goodpot = goodpotLeaf ? goodpotLeaf->GetValue() : -1;
225  TLeaf* spillsLeaf = srtree->GetLeaf(totspills_str.c_str());
226  int spills = spillsLeaf ? spillsLeaf->GetValue() : -1;
227  TLeaf* goodspillsLeaf = srtree->GetLeaf(goodspills_str.c_str());
228  int goodspills = goodspillsLeaf ? goodspillsLeaf->GetValue() : -1;
229 
230  std::cout << "Subrun " << runid << "/" << subrunid << " added "
231  << "(good POT = " << goodpot << ")"
232  << std::endl;
233  *fSubRun = { runid, subrunid, pot, goodpot, spills, goodspills };
234  fSubRunTree->Fill();
235  }
236  }
237  // set the file for next time
238  last_tfile = ev.getTFile();
239 }
TTree * fSubRunTree
Subrun output tree.
SubRun * fSubRun
Standard output subrun structure.
std::string fGeneratorProcess
process_name of process used to run genie. Used to extract subrun/POT information ...
BEGIN_PROLOG could also be cout

Friends And Related Function Documentation

friend class ProcessorBlock
friend

Definition at line 48 of file ProcessorBase.hh.

Member Data Documentation

std::vector<geo::BoxBoundedGeo> core::ProcessorBase::fActiveVolumes
protected

List of active volumes in configured detector.

Definition at line 176 of file ProcessorBase.hh.

event::Event* core::ProcessorBase::fEvent
protected

The standard output event data structure.

Definition at line 180 of file ProcessorBase.hh.

unsigned long core::ProcessorBase::fEventIndex
protected

An incrementing index.

Definition at line 171 of file ProcessorBase.hh.

Experiment core::ProcessorBase::fExperimentID
protected

Experiment identifier.

Definition at line 172 of file ProcessorBase.hh.

TParameter<int>* core::ProcessorBase::fExperimentParameter
protected

Saves value of experiment enum.

Definition at line 188 of file ProcessorBase.hh.

FileMeta* core::ProcessorBase::fFileMeta
protected

standard output file metadata structure

Definition at line 187 of file ProcessorBase.hh.

TTree* core::ProcessorBase::fFileMetaTree
protected

File metadata output tree.

Definition at line 186 of file ProcessorBase.hh.

art::InputTag core::ProcessorBase::fFluxTag
protected

art tag for MCFlux information

Definition at line 191 of file ProcessorBase.hh.

std::string core::ProcessorBase::fGeneratorProcess
protected

process_name of process used to run genie. Used to extract subrun/POT information

Definition at line 196 of file ProcessorBase.hh.

art::InputTag core::ProcessorBase::fMCParticleTag
protected

art tag for MCParticle

Definition at line 195 of file ProcessorBase.hh.

art::InputTag core::ProcessorBase::fMCShowerTag
protected

art tag for MCShower

Definition at line 194 of file ProcessorBase.hh.

art::InputTag core::ProcessorBase::fMCTrackTag
protected

art tag for MCTrack

Definition at line 193 of file ProcessorBase.hh.

TFile* core::ProcessorBase::fOutputFile
protected

The output ROOT file.

Definition at line 178 of file ProcessorBase.hh.

std::string core::ProcessorBase::fOutputFilename
protected

The output filename.

Definition at line 174 of file ProcessorBase.hh.

std::string core::ProcessorBase::fProviderConfig
protected

A custom provider config fcl file.

Definition at line 175 of file ProcessorBase.hh.

ProviderManager* core::ProcessorBase::fProviderManager
protected

Interface for provider access.

Definition at line 173 of file ProcessorBase.hh.

std::vector<event::RecoInteraction>* core::ProcessorBase::fReco

Reco interaction list.

Pointer to reco event information

Definition at line 116 of file ProcessorBase.hh.

event::RecoEvent* core::ProcessorBase::fRecoEvent
protected

The standard output reco event data structure.

Definition at line 183 of file ProcessorBase.hh.

TTree* core::ProcessorBase::fRecoTree
protected

The output reco ROOT tree.

Definition at line 182 of file ProcessorBase.hh.

SubRun* core::ProcessorBase::fSubRun
protected

Standard output subrun structure.

Definition at line 185 of file ProcessorBase.hh.

std::set<std::pair<int, int> > core::ProcessorBase::fSubRunCache
protected

Cache stored subruns.

Definition at line 189 of file ProcessorBase.hh.

TTree* core::ProcessorBase::fSubRunTree
protected

Subrun output tree.

Definition at line 184 of file ProcessorBase.hh.

TTree* core::ProcessorBase::fTree
protected

The output ROOT tree.

Definition at line 179 of file ProcessorBase.hh.

art::InputTag core::ProcessorBase::fTruthTag
protected

art tag for MCTruth information

Definition at line 190 of file ProcessorBase.hh.

std::vector<art::InputTag> core::ProcessorBase::fWeightTags
protected

art tag(s) for MCEventWeight information

Definition at line 192 of file ProcessorBase.hh.

bool core::ProcessorBase::fWriteRecoTree
protected

Enable writing of the reco tree.

Definition at line 181 of file ProcessorBase.hh.

bool core::ProcessorBase::fWriteTree
protected

Enable writing of the main tree.

Definition at line 177 of file ProcessorBase.hh.


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