All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
evgen::TextFileGen Class Reference
Inheritance diagram for evgen::TextFileGen:

Public Member Functions

 TextFileGen (fhicl::ParameterSet const &p)
 
void produce (art::Event &e) override
 
void beginJob () override
 
void beginRun (art::Run &run) override
 

Private Member Functions

std::pair< unsigned, unsigned > readEventInfo (std::istream &is)
 
simb::MCTruth readNextHepEvt ()
 

Private Attributes

unsigned long int fOffset
 
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...
 

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 83 of file TextFileGen_module.cc.

Constructor & Destructor Documentation

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

Definition at line 102 of file TextFileGen_module.cc.

103  : EDProducer{p}
104  , fOffset{p.get<unsigned long int>("Offset")}
105  , fInputFile(0)
106  , fInputFileName{p.get<std::string>("InputFileName")}
107  , fMoveY{p.get<double>("MoveY", -1e9)}
108 {
109  if (fMoveY>-1e8){
110  mf::LogWarning("TextFileGen")<<"Particles will be moved to a new plane y = "<<fMoveY<<" cm.\n";
111  }
112 
113  produces< std::vector<simb::MCTruth> >();
115 
116 
117 }
unsigned long int fOffset
pdgs p
Definition: selectors.fcl:22
produces< sumdata::RunData, art::InRun >()
std::string fInputFileName
Name of text file containing events to simulate.
std::ifstream * fInputFile
double fMoveY
Project particles to a new y plane.

Member Function Documentation

void evgen::TextFileGen::beginJob ( )
override

Definition at line 120 of file TextFileGen_module.cc.

121 {
122  fInputFile = new std::ifstream(fInputFileName.c_str());
123 
124  // check that the file is a good one
125  if( !fInputFile->good() )
126  throw cet::exception("TextFileGen") << "input text file "
127  << fInputFileName
128  << " cannot be read.\n";
129 
130 
131  for (unsigned i = 0; i != fOffset; ++i) {
132  auto const [eventNo, nparticles] = readEventInfo(*fInputFile);
133  for (unsigned p = 0; p != nparticles; ++p) {
134  constexpr auto all_chars_until = std::numeric_limits<unsigned>::max();
135  fInputFile->ignore(all_chars_until, '\n');
136  }
137  }
138 
139 
140 }
std::pair< unsigned, unsigned > readEventInfo(std::istream &is)
unsigned long int fOffset
pdgs p
Definition: selectors.fcl:22
std::string fInputFileName
Name of text file containing events to simulate.
std::ifstream * fInputFile
void evgen::TextFileGen::beginRun ( art::Run &  run)
override

Definition at line 143 of file TextFileGen_module.cc.

144 {
145  art::ServiceHandle<geo::Geometry const> geo;
146  run.put(std::make_unique<sumdata::RunData>(geo->DetectorName()));
147  }
void evgen::TextFileGen::produce ( art::Event &  e)
override

Definition at line 150 of file TextFileGen_module.cc.

151 {
152  // check that the file is still good
153  if( !fInputFile->good() )
154  throw cet::exception("TextFileGen") << "input text file "
155  << fInputFileName
156  << " cannot be read in produce().\n";
157 
158 
159 
160 
161 //Now, read the Event to be used.
162 
163 
164 
165 // check that the file is still good
166  if( !fInputFile->good() )
167  throw cet::exception("TextFileGen") << "input text file "
168  << fInputFileName
169  << " cannot be read in produce().\n";
170  auto truthcol = std::make_unique<std::vector<simb::MCTruth>>();
171  truthcol->push_back(readNextHepEvt());
172 
173 
174  e.put(std::move(truthcol));
175 }
std::string fInputFileName
Name of text file containing events to simulate.
std::ifstream * fInputFile
do i e
simb::MCTruth readNextHepEvt()
std::pair< unsigned, unsigned > evgen::TextFileGen::readEventInfo ( std::istream &  is)
private

Definition at line 254 of file TextFileGen_module.cc.

255 {
256  std::string line;
257  getline(iss, line);
258  std::istringstream buffer{line};
259 
260  // Parse read line for the event number and particles per event
261  unsigned event, nparticles;
262  buffer >> event >> nparticles;
263  return {event, nparticles};
264 }
simb::MCTruth evgen::TextFileGen::readNextHepEvt ( )
private

Definition at line 180 of file TextFileGen_module.cc.

181 {
182 
183  // declare the variables for reading in the event record
184  int status = 0;
185  int pdg = 0;
186  int firstMother = 0;
187  int secondMother = 0;
188  int firstDaughter = 0;
189  int secondDaughter = 0;
190  double xMomentum = 0.;
191  double yMomentum = 0.;
192  double zMomentum = 0.;
193  double energy = 0.;
194  double mass = 0.;
195  double xPosition = 0.;
196  double yPosition = 0.;
197  double zPosition = 0.;
198  double time = 0.;
199 
200 
201 
202  // read in line to get event number and number of particles
203  std::string oneLine;
204  std::istringstream inputLine;
205  simb::MCTruth nextEvent;
206  auto const [eventNo, nParticles] = readEventInfo(*fInputFile);
207 
208 
209 
210  // now read in all the lines for the particles
211  // in this interaction. only particles with
212  // status = 1 get tracked in Geant4.
213  for(unsigned short i = 0; i < nParticles; ++i){
214  std::getline(*fInputFile, oneLine);
215  inputLine.clear();
216  inputLine.str(oneLine);
217 
218  inputLine >> status >> pdg
219  >> firstMother >> secondMother >> firstDaughter >> secondDaughter
220  >> xMomentum >> yMomentum >> zMomentum >> energy >> mass
221  >> xPosition >> yPosition >> zPosition >> time;
222 
223 
224 
225  //Project the particle to a new y plane
226  if (fMoveY>-1e8){
227  double totmom = sqrt(pow(xMomentum,2)+pow(yMomentum,2)+pow(zMomentum,2));
228  double kx = xMomentum/totmom;
229  double ky = yMomentum/totmom;
230  double kz = zMomentum/totmom;
231  if (ky){
232  double l = (fMoveY-yPosition)/ky;
233  xPosition += kx*l;
234  yPosition += ky*l;
235  zPosition += kz*l;
236  }
237  }
238 
239  TLorentzVector pos(xPosition, yPosition, zPosition, time);
240  TLorentzVector mom(xMomentum, yMomentum, zMomentum, energy);
241 
242  simb::MCParticle part(i, pdg, "primary", firstMother, mass, status);
243  part.AddTrajectoryPoint(pos, mom);
244 
245  nextEvent.Add(part);
246 
247  } // end loop on particles.
248 
249 return nextEvent;
250 }
std::pair< unsigned, unsigned > readEventInfo(std::istream &is)
var pdg
Definition: selectors.fcl:14
std::ifstream * fInputFile
float mass
Definition: dedx.py:47
double fMoveY
Project particles to a new y plane.

Member Data Documentation

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

Definition at line 96 of file TextFileGen_module.cc.

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

Name of text file containing events to simulate.

Definition at line 97 of file TextFileGen_module.cc.

double evgen::TextFileGen::fMoveY
private

Project particles to a new y plane.

Definition at line 98 of file TextFileGen_module.cc.

unsigned long int evgen::TextFileGen::fOffset
private

Definition at line 95 of file TextFileGen_module.cc.


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