Public Member Functions | Private Attributes | List of all members
evgen::TextFileGen Class Reference
Inheritance diagram for evgen::TextFileGen:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Member Functions

 TextFileGen (fhicl::ParameterSet const &p)
 
void produce (art::Event &e) override
 
void beginJob () override
 
void beginRun (art::Run &run) override
 
- Public Member Functions inherited from art::EDProducer
 EDProducer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDProducer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Producer
virtual ~Producer () noexcept
 
 Producer (fhicl::ParameterSet const &)
 
 Producer (Producer const &)=delete
 
 Producer (Producer &&)=delete
 
Produceroperator= (Producer const &)=delete
 
Produceroperator= (Producer &&)=delete
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Modifier
 ~Modifier () noexcept
 
 Modifier ()
 
 Modifier (Modifier const &)=delete
 
 Modifier (Modifier &&)=delete
 
Modifieroperator= (Modifier const &)=delete
 
Modifieroperator= (Modifier &&)=delete
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Attributes

std::ifstream * fInputFile
 
std::string fInputFileName
 Name of text file containing events to simulate. More...
 
double fMoveY
 Project particles to a new y plane. More...
 

Additional Inherited Members

- Public Types inherited from art::EDProducer
using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
- Public Types inherited from art::detail::Producer
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 
- Public Types inherited from art::Modifier
template<typename UserConfig , typename UserKeysToIgnore = void>
using Table = ProducerTable< UserConfig, detail::ModuleConfig, UserKeysToIgnore >
 
- Static Public Member Functions inherited from art::EDProducer
static void commitEvent (EventPrincipal &ep, Event &e)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

This module assumes that the input file has the hepevt format for each event to be simulated. See

http://cepa.fnal.gov/psm/simulation/mcgen/lund/pythia_manual/pythia6.3/pythia6301/node39.html

for details on the format. In brief each event contains at least two lines. The first line contains two entries, the event number (which is ignored in ART/LArSoft) and the number of particles in the event. Each following line containes 15 entries to describe each particle. The entries are:

  1. status code (should be set to 1 for any particle to be tracked, others won't be tracked)
  2. the pdg code for the particle
  3. the entry of the first mother for this particle in the event, 0 means no mother
  4. the entry of the second mother for this particle in the event, 0 means no mother
  5. the entry of the first daughter for this particle in the event, 0 means no daughter
  6. the entry of the second daughter for this particle in the event, 0 means no daughter
  7. x component of the particle momentum
  8. y component of the particle momentum
  9. z component of the particle momentum
  10. energy of the particle
  11. mass of the particle
  12. x position of the particle initial position
  13. y position of the particle initial position
  14. z position of the particle initial position
  15. time of the particle production

For example, if you want to simulate a single muon with a 5 GeV energy moving only in the z direction, the entry would be

0 1
1 13 0 0 0 0 0. 0. 1.0 5.0011 0.105 1.0 1.0 1.0 0.0

There are some assumptions that go into using this format that may not be obvious. The first is that only particles with status code = 1 are tracked in the LArSoft/Geant4 combination making the mother daughter relations somewhat irrelevant. That also means that you should let Geant4 handle any decays.

The units in LArSoft are cm for distances and ns for time. The use of TLorentzVector below does not imply space and time have the same units (do not use TLorentzVector::Boost()).

Definition at line 79 of file TextFileGen_module.cc.

Constructor & Destructor Documentation

evgen::TextFileGen::TextFileGen ( fhicl::ParameterSet const &  p)
explicit

Definition at line 95 of file TextFileGen_module.cc.

96  : EDProducer{p}
97  , fInputFile(0)
98  , fInputFileName{p.get<std::string>("InputFileName")}
99  , fMoveY{p.get<double>("MoveY", -1e9)}
100 
101 {
102  if (fMoveY>-1e8){
103  mf::LogWarning("TextFileGen")<<"Particles will be moved to a new plane y = "<<fMoveY<<" cm.\n";
104  }
105 
106  produces< std::vector<simb::MCTruth> >();
107  produces< sumdata::RunData, art::InRun >();
108 }
std::string string
Definition: nybbler.cc:12
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
std::string fInputFileName
Name of text file containing events to simulate.
std::ifstream * fInputFile
p
Definition: test.py:223
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
double fMoveY
Project particles to a new y plane.

Member Function Documentation

void evgen::TextFileGen::beginJob ( )
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 111 of file TextFileGen_module.cc.

112 {
113  fInputFile = new std::ifstream(fInputFileName.c_str());
114 
115  // check that the file is a good one
116  if( !fInputFile->good() )
117  throw cet::exception("TextFileGen") << "input text file "
118  << fInputFileName
119  << " cannot be read.\n";
120 }
std::string fInputFileName
Name of text file containing events to simulate.
std::ifstream * fInputFile
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void evgen::TextFileGen::beginRun ( art::Run run)
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 123 of file TextFileGen_module.cc.

124 {
126  run.put(std::make_unique<sumdata::RunData>(geo->DetectorName()));
127  }
std::string DetectorName() const
Returns a string with the name of the detector, as configured.
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
LArSoft geometry interface.
Definition: ChannelGeo.h:16
void evgen::TextFileGen::produce ( art::Event e)
overridevirtual

Implements art::EDProducer.

Definition at line 130 of file TextFileGen_module.cc.

131 {
132  // check that the file is still good
133  if( !fInputFile->good() )
134  throw cet::exception("TextFileGen") << "input text file "
135  << fInputFileName
136  << " cannot be read in produce().\n";
137 
138 
139  std::unique_ptr< std::vector<simb::MCTruth> > truthcol(new std::vector<simb::MCTruth>);
140  simb::MCTruth truth;
141 
142  // declare the variables for reading in the event record
143  int event = 0;
144  unsigned short nParticles = 0;
145  int status = 0;
146  int pdg = 0;
147  int firstMother = 0;
148  int secondMother = 0;
149  int firstDaughter = 0;
150  int secondDaughter = 0;
151  double xMomentum = 0.;
152  double yMomentum = 0.;
153  double zMomentum = 0.;
154  double energy = 0.;
155  double mass = 0.;
156  double xPosition = 0.;
157  double yPosition = 0.;
158  double zPosition = 0.;
159  double time = 0.;
160 
161  // read in line to get event number and number of particles
162  std::string oneLine;
163  std::getline(*fInputFile, oneLine);
164  std::istringstream inputLine;
165  inputLine.str(oneLine);
166 
167  inputLine >> event >> nParticles;
168 
169  // now read in all the lines for the particles
170  // in this interaction. only particles with
171  // status = 1 get tracked in Geant4.
172  for(unsigned short i = 0; i < nParticles; ++i){
173  std::getline(*fInputFile, oneLine);
174  inputLine.clear();
175  inputLine.str(oneLine);
176 
177  inputLine >> status >> pdg
178  >> firstMother >> secondMother >> firstDaughter >> secondDaughter
179  >> xMomentum >> yMomentum >> zMomentum >> energy >> mass
180  >> xPosition >> yPosition >> zPosition >> time;
181 
182  //Project the particle to a new y plane
183  if (fMoveY>-1e8){
184  double totmom = sqrt(pow(xMomentum,2)+pow(yMomentum,2)+pow(zMomentum,2));
185  double kx = xMomentum/totmom;
186  double ky = yMomentum/totmom;
187  double kz = zMomentum/totmom;
188  if (ky){
189  double l = (fMoveY-yPosition)/ky;
190  xPosition += kx*l;
191  yPosition += ky*l;
192  zPosition += kz*l;
193  }
194  }
195 
196  TLorentzVector pos(xPosition, yPosition, zPosition, time);
197  TLorentzVector mom(xMomentum, yMomentum, zMomentum, energy);
198 
199  simb::MCParticle part(i, pdg, "primary", firstMother, mass, status);
200  part.AddTrajectoryPoint(pos, mom);
201 
202  truth.Add(part);
203  }
204 
205  truthcol->push_back(truth);
206 
207  e.put(std::move(truthcol));
208 }
std::string string
Definition: nybbler.cc:12
constexpr T pow(T x)
Definition: pow.h:72
static QStrList * l
Definition: config.cpp:1044
std::string fInputFileName
Name of text file containing events to simulate.
std::ifstream * fInputFile
def move(depos, offset)
Definition: depos.py:107
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
void Add(simb::MCParticle const &part)
Definition: MCTruth.h:80
Event generator information.
Definition: MCTruth.h:32
double fMoveY
Project particles to a new y plane.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Data Documentation

std::ifstream* evgen::TextFileGen::fInputFile
private

Definition at line 89 of file TextFileGen_module.cc.

std::string evgen::TextFileGen::fInputFileName
private

Name of text file containing events to simulate.

Definition at line 90 of file TextFileGen_module.cc.

double evgen::TextFileGen::fMoveY
private

Project particles to a new y plane.

Definition at line 91 of file TextFileGen_module.cc.


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