All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProcessorBase.cxx
Go to the documentation of this file.
1 #include <algorithm>
2 #include <TBranch.h>
3 #include <TFile.h>
4 #include <TLeaf.h>
5 #include <TTree.h>
6 #include <TParameter.h>
7 #include <unordered_map>
8 #include "gallery/ValidHandle.h"
9 #include "gallery/Handle.h"
10 #include "canvas/Utilities/InputTag.h"
11 #include "canvas/Persistency/Provenance/SubRunAuxiliary.h"
12 #include "nusimdata/SimulationBase/MCFlux.h"
13 #include "nusimdata/SimulationBase/MCTruth.h"
14 #include "nusimdata/SimulationBase/MCNeutrino.h"
15 #include "nusimdata/SimulationBase/GTruth.h"
17 #include "canvas/Persistency/Common/FindManyP.h"
19 
20 #include "fhiclcpp/ParameterSet.h"
21 #include "fhiclcpp/ParameterSetID.h"
22 #include "fhiclcpp/make_ParameterSet.h"
23 #include "fhiclcpp/ParameterSetRegistry.h"
24 
25 #include "cetlib/sqlite/query_result.h"
26 #include "cetlib/sqlite/select.h"
27 
28 #include "canvas/Persistency/Provenance/ParameterSetBlob.h"
29 #include "canvas/Persistency/Provenance/ParameterSetMap.h"
30 #include "art_root_io/RootDB/SQLite3Wrapper.h"
31 #include "art_root_io/RootDB/tkeyvfs.h"
32 
38 #include "Event.hh"
39 #include "SubRun.hh"
40 #include "Loader.hh"
41 #include "util/Interaction.hh"
42 #include "ProcessorBase.hh"
43 #include "ProviderManager.hh"
44 
48 
49 namespace core {
50 
52  : fEventIndex(0), fOutputFilename("output.root"), fProviderManager(NULL) {}
53 
54 
56 
57 
59  fTree->Fill();
60  fEventIndex++;
61 }
62 
63 
65  fRecoTree->Fill();
66 }
67 
68 
71  fEvent->metadata.Init();
72  fEvent->truth.clear();
73  fEvent->reco.clear();
74 }
75 
76 
77 void ProcessorBase::Initialize(char* config) {
78  fhicl::ParameterSet* cfg = LoadConfig(config);
79  Initialize(cfg);
80 }
81 
82 
83 void ProcessorBase::Setup(char* config) {
84  fhicl::ParameterSet* cfg = LoadConfig(config);
85  Setup(cfg);
86 }
87 
88 
89 void ProcessorBase::Setup(fhicl::ParameterSet* config) {
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()) {
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 }
194 
195 void ProcessorBase::UpdateSubRuns(gallery::Event& ev) {
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 }
240 
241 void ProcessorBase::UpdateFileMeta(gallery::Event& ev) {
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 }
295 
296 
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 }
311 
312 void ProcessorBase::SetupServices(gallery::Event& ev) {
313  if (fProviderManager != NULL) {
315  }
316 }
317 
318 const simb::MCParticle *Genie2G4MCParticle(
319  const simb::MCParticle &genie_part,
320  const simb::MCTruth &mctruth,
321  const std::vector<art::Ptr<simb::MCParticle>> &g4_mcparticles,
322  const std::vector<const sim::GeneratedParticleInfo *> infos) {
323 
324  const simb::MCParticle *ret = NULL;
325  for (int iparticle = 0; iparticle < g4_mcparticles.size(); iparticle++) {
326  if (infos[iparticle]->hasGeneratedParticleIndex() &&
327  infos[iparticle]->generatedParticleIndex() < mctruth.NParticles() && // TODO: why is this number sometimes bigger than the number of particles?
328  mctruth.GetParticle(infos[iparticle]->generatedParticleIndex()).TrackId() == genie_part.TrackId() &&
329  g4_mcparticles[iparticle]->Process() == "primary" /* TODO: will have to remove this restriction to include secondary particles*/) {
330 
331  // if a genie particle re-scatters in g4 and makes more particles, then multiple g4 particles can match to a
332  // genie particle. Thus, we also check that the start location of the associated genie particle matches the g4
333  // and that the pdgid matches (to be on the safe side)
334  //
335  // Note that this should be accounted for by requiring the process to be primary. This is a bit of redundancy.
336  const simb::MCParticle& matched_genie_particle = mctruth.GetParticle(infos[iparticle]->generatedParticleIndex());
337  if ((matched_genie_particle.Position().Vect() - g4_mcparticles[iparticle]->Position().Vect()).Mag() < 1e-4 &&
338  matched_genie_particle.PdgCode() == g4_mcparticles[iparticle]->PdgCode()) {
339 
340  // this should only be true for one particle
341  assert(ret == NULL);
342  ret = g4_mcparticles[iparticle].get();
343  }
344  }
345  }
346  return ret;
347 }
348 
349 void ProcessorBase::BuildEventTree(gallery::Event& ev) {
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 }
581 
582 } // namespace core
583 
TVector3 momentum
Neutrino three-momentum.
Definition: Event.hh:91
void Init()
Definition: Event.hh:44
TTree * fSubRunTree
Subrun output tree.
Metadata metadata
Event metadata.
Definition: Event.hh:230
Experiment
Definition: Experiment.hh:13
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
TParameter< int > * fExperimentParameter
Saves value of experiment enum.
void SetupServices(gallery::Event &ev)
int pdg
PDG Code.
Definition: Event.hh:127
Encapsulate the construction of a single cyostat.
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.
std::vector< event::RecoInteraction > * fReco
Reco interaction list.
TFile * fOutputFile
The output ROOT file.
Neutrino neutrino
The neutrino.
Definition: Event.hh:152
Contains data associated to particles from detector simulation.
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
The reconstructed event data definition.
Definition: Event.hh:208
size_t ntruth
Size of truth.
Definition: Event.hh:231
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.
Access the description of auxiliary detector geometry.
event::RecoEvent * fRecoEvent
The standard output reco 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
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
Access the description of detector geometry.
Interface to LArSoft services.
int fileEntry
Index of of file.
Definition: Event.hh:53
void UpdateSubRuns(gallery::Event &ev)
virtual void Initialize(char *config=NULL)
int eventID
Event ID.
Definition: Event.hh:52
std::string fProviderConfig
A custom provider config fcl file.
float bjorkenX
Bjorken x.
Definition: Event.hh:80
float eccqe
CCQE energy.
Definition: Event.hh:89
unsigned long fEventIndex
An incrementing index.
bool fWriteTree
Enable writing of the main tree.
int targetPDG
PDG code of struck target.
Definition: Event.hh:78
SubRun * fSubRun
Standard output subrun structure.
bool is_primary
Whether the process producing the particle was &quot;primary&quot;.
Definition: Event.hh:141
virtual void EventCleanup()
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
FileMeta * fFileMeta
standard output file metadata structure
std::vector< RecoInteraction > reco
Reconstructed interactions.
Definition: Event.hh:234
back track the reconstruction to the simulation
art::InputTag fMCShowerTag
art tag for MCShower
The standard subrun data definition.
Definition: SubRun.hh:23
virtual void FillTree()
float inelasticityY
Inelasticity y.
Definition: Event.hh:81
float w
Hadronic invariant mass W.
Definition: Event.hh:87
virtual void FillRecoTree()
Metadata metadata
Event metadata.
Definition: Event.hh:214
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
void BuildEventTree(gallery::Event &ev)
The standard event data definition.
Definition: Event.hh:228
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
IteratorBox< cryostat_iterator,&GeometryCore::begin_cryostat,&GeometryCore::end_cryostat > IterateCryostats() const
Enables ranged-for loops on all cryostats of the detector.
size_t nfinalstate
Size of finalstate.
Definition: Event.hh:155
fhicl::ParameterSet * LoadConfig(char *configfile)
Definition: Loader.cxx:80
virtual void Teardown()
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::string fGeneratorProcess
process_name of process used to run genie. Used to extract subrun/POT information ...
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
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
TTree * fRecoTree
The output reco ROOT tree.
TVector3 position
Neutrino interaction position.
Definition: Event.hh:92
static std::vector< Experiment > GetValidExperiments()
ProviderManager * fProviderManager
Interface for provider access.
bool fWriteRecoTree
Enable writing of the reco tree.
do i e
art::InputTag fMCParticleTag
art tag for MCParticle
std::string fOutputFilename
The output filename.
TTree * fFileMetaTree
File metadata output tree.
void SetupServices(gallery::Event &ev)
int pdg
PDG code of probe neutrino.
Definition: Event.hh:77
height to which particles are projected pnfs larsoft persistent physics cosmics Fermilab CORSIKA standard He_showers_ * db
Forward iterator browsing all geometry elements in the detector.
Definition: GeometryCore.h:727
art::InputTag fMCTrackTag
art tag for MCTrack
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
BEGIN_PROLOG could also be cout
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
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.
Encapsulate the construction of a single detector plane.
void UpdateFileMeta(gallery::Event &ev)
virtual void Setup(char *config=NULL)
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