LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
MARLEYGen_module.cc
Go to the documentation of this file.
1 
9 // standard library includes
10 #include <memory>
11 #include <string>
12 #include <vector>
13 
14 // framework includes
21 #include "fhiclcpp/ParameterSet.h"
22 #include "fhiclcpp/types/Table.h"
23 #include "cetlib_except/exception.h"
25 
26 // art extensions
28 
29 // LArSoft includes
36 
37 // ROOT includes
38 #include "TFile.h"
39 #include "TTree.h"
40 
41 namespace evgen {
42  class MarleyGen;
43 }
44 
46 
47  public:
48 
49  using Name = fhicl::Name;
51 
53  struct Config {
54 
56  Name("vertex"),
57  Comment("Configuration for selecting the vertex location(s)")
58  };
59 
61  Name("marley_parameters"),
62  Comment("Configuration for the MARLEY generator")
63  };
64 
66  Name("module_type"),
67  Comment(""),
68  "MARLEYGen" // default value
69  };
70 
71  }; // struct Config
72 
73  // Type to enable FHiCL parameter validation by art
75 
76  // Configuration-checking constructors
77  explicit MarleyGen(const Parameters& p);
78 
79  virtual ~MarleyGen();
80 
81  virtual void produce(art::Event& e) override;
82  virtual void beginRun(art::Run& run) override;
83 
84  virtual void reconfigure(const Parameters& p);
85 
86  protected:
87 
88  // Object that provides an interface to the MARLEY event generator
89  std::unique_ptr<evgen::MARLEYHelper> fMarleyHelper;
90 
91  // Algorithm that allows us to sample vertex locations within the active
92  // volume(s) of the detector
93  std::unique_ptr<evgen::ActiveVolumeVertexSampler> fVertexSampler;
94 
95  // unique_ptr to the current event created by MARLEY
96  std::unique_ptr<marley::Event> fEvent;
97 
98  // the MARLEY event TTree
99  TTree* fEventTree;
100 
101  // Run, subrun, and event numbers from the art::Event being processed
102  uint_fast32_t fRunNumber;
103  uint_fast32_t fSubRunNumber;
104  uint_fast32_t fEventNumber;
105 };
106 
107 //------------------------------------------------------------------------------
109  : fEvent(new marley::Event), fRunNumber(0), fSubRunNumber(0), fEventNumber(0)
110 {
111  // Configure the module (including MARLEY itself) using the FHiCL parameters
112  this->reconfigure(p);
113 
114  // Create a ROOT TTree using the TFileService that will store the MARLEY
115  // event objects (useful for debugging purposes)
117  fEventTree = tfs->make<TTree>("MARLEY_event_tree",
118  "Neutrino events generated by MARLEY");
119  fEventTree->Branch("event", "marley::Event", fEvent.get());
120 
121  // Add branches that give the art::Event run, subrun, and event numbers for
122  // easy match-ups between the MARLEY and art TTrees. All three are recorded
123  // as 32-bit unsigned integers.
124  fEventTree->Branch("run_number", &fRunNumber, "run_number/i");
125  fEventTree->Branch("subrun_number", &fSubRunNumber, "subrun_number/i");
126  fEventTree->Branch("event_number", &fEventNumber, "event_number/i");
127 
128  produces< std::vector<simb::MCTruth> >();
129  produces< sumdata::RunData, art::InRun >();
130 }
131 
132 //------------------------------------------------------------------------------
134 {
135 }
136 
137 //------------------------------------------------------------------------------
139 {
140  // grab the geometry object to see what geometry we are using
142  std::unique_ptr<sumdata::RunData>
143  runcol(new sumdata::RunData(geo->DetectorName()));
144 
145  run.put(std::move(runcol));
146 }
147 
148 //------------------------------------------------------------------------------
150 {
151  // Get the run, subrun, and event numbers from the current art::Event
152  fRunNumber = e.run();
153  fSubRunNumber = e.subRun();
154  fEventNumber = e.event();
155 
156  std::unique_ptr< std::vector<simb::MCTruth> >
157  truthcol(new std::vector<simb::MCTruth>);
158 
159  // Get the primary vertex location for this event
161  TLorentzVector vertex_pos = fVertexSampler->sample_vertex_pos(*geo);
162 
163  // Create the MCTruth object, and retrieve the marley::Event object
164  // that was generated as it was created
165  simb::MCTruth truth = fMarleyHelper->create_MCTruth(vertex_pos,
166  fEvent.get());
167 
168  // Write the marley::Event object to the event tree
169  fEventTree->Fill();
170 
171  truthcol->push_back(truth);
172 
173  e.put(std::move(truthcol));
174 }
175 
176 //------------------------------------------------------------------------------
178 {
179  const auto& seed_service = art::ServiceHandle<rndm::NuRandomService>();
180  const auto& geom_service = art::ServiceHandle<geo::Geometry>();
181 
182  // Create a new evgen::ActiveVolumeVertexSampler object based on the current
183  // configuration
184  fVertexSampler = std::make_unique<evgen::ActiveVolumeVertexSampler>(
185  p().vertex_, *seed_service, *geom_service, "MARLEY_Vertex_Sampler");
186 
187  // Create a new marley::Generator object based on the current configuration
188  fMarleyHelper = std::make_unique<MARLEYHelper>(p().marley_parameters_,
189  *seed_service, "MARLEY");
190 }
191 
virtual void reconfigure(const Parameters &p)
fhicl::Atom< std::string > module_type_
SubRunNumber_t subRun() const
Definition: Event.h:72
fhicl::Comment Comment
LArSoft interface to the MARLEY (Model of Argon Reaction Low Energy Yields) supernova neutrino event ...
virtual void beginRun(art::Run &run) override
art::ProductID put(std::unique_ptr< PROD > &&)
Definition: Run.h:148
Particle class.
std::unique_ptr< evgen::MARLEYHelper > fMarleyHelper
Definition: Run.h:30
fhicl::Table< evgen::ActiveVolumeVertexSampler::Config > vertex_
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
Algorithm that samples vertex locations uniformly within the active volume of a detector. It is fully experiment-agnostic and multi-TPC aware.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:42
uint_fast32_t fRunNumber
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
uint_fast32_t fSubRunNumber
std::unique_ptr< evgen::ActiveVolumeVertexSampler > fVertexSampler
Collection of configuration parameters for the module.
EventNumber_t event() const
Definition: Event.h:67
virtual void produce(art::Event &e) override
An art service to assist in the distribution of guaranteed unique seeds to all engines within an art ...
fhicl::Table< evgen::MARLEYHelper::Config > marley_parameters_
T * make(ARGS...args) const
uint_fast32_t fEventNumber
Event generator information.
Definition: MCTruth.h:30
Float_t e
Definition: plot.C:34
MarleyGen(const Parameters &p)
RunNumber_t run() const
Definition: Event.h:77
Namespace collecting geometry-related classes utilities.
Event Generation using GENIE, cosmics or single particles.
std::unique_ptr< marley::Event > fEvent
art framework interface to geometry description