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

Public Member Functions

 TextFileGen (fhicl::ParameterSet const &p)
 
virtual ~TextFileGen ()
 
void produce (::art::Event &e) override
 
void beginJob () override
 
void beginRun (::art::Run &run) override
 
void reconfigure (fhicl::ParameterSet const &p)
 
- 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
 pointer to input text file More...
 
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

Definition at line 83 of file TextFileGen_module.cc.

Constructor & Destructor Documentation

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

Definition at line 101 of file TextFileGen_module.cc.

102  : EDProducer{p}, fInputFile(0)
103  {
104  this->reconfigure(p);
105 
106  produces< std::vector<simb::MCTruth> >();
107  produces< sumdata::RunData, ::art::InRun >();
108  }
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.h:20
void reconfigure(fhicl::ParameterSet const &p)
std::ifstream * fInputFile
pointer to input text file
p
Definition: test.py:223
gar::evgen::TextFileGen::~TextFileGen ( )
virtual

Definition at line 111 of file TextFileGen_module.cc.

112  {
113  }

Member Function Documentation

void gar::evgen::TextFileGen::beginJob ( )
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 116 of file TextFileGen_module.cc.

117  {
118  fInputFile = new std::ifstream(fInputFileName.c_str());
119 
120  // check that the file is a good one
121  if( !fInputFile->good() )
122  throw cet::exception("TextFileGen")
123  << "input text file "
124  << fInputFileName
125  << " cannot be read.";
126 
127  return;
128  }
std::string fInputFileName
Name of text file containing events to simulate.
std::ifstream * fInputFile
pointer to input text file
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void gar::evgen::TextFileGen::beginRun ( ::art::Run run)
override

Definition at line 131 of file TextFileGen_module.cc.

132  {
133 
134  // grab the geometry object to see what geometry we are using
135  auto geo = gar::providerFrom<geo::GeometryGAr>();
136  std::unique_ptr<gar::sumdata::RunData> runcol(new gar::sumdata::RunData(geo->DetectorName()));
137 
138  run.put(std::move(runcol));
139 
140  return;
141  }
def move(depos, offset)
Definition: depos.py:107
ProductID put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: DataViewImpl.h:686
LArSoft geometry interface.
Definition: ChannelGeo.h:16
void gar::evgen::TextFileGen::produce ( ::art::Event e)
override

Definition at line 144 of file TextFileGen_module.cc.

145  {
146  // check that the file is still good
147  if( !fInputFile->good() )
148  throw cet::exception("TextFileGen")
149  << "input text file "
150  << fInputFileName
151  << " cannot be read in produce().";
152 
153 
154  std::unique_ptr< std::vector<simb::MCTruth> > truthcol(new std::vector<simb::MCTruth>);
155  simb::MCTruth truth;
156 
157  // declare the variables for reading in the event record
158  int event = 0;
159  unsigned short nParticles = 0;
160  int status = 0;
161  int pdg = 0;
162  int firstMother = 0;
163  int secondMother = 0;
164  int firstDaughter = 0;
165  int secondDaughter = 0;
166  double xMomentum = 0.;
167  double yMomentum = 0.;
168  double zMomentum = 0.;
169  double energy = 0.;
170  double mass = 0.;
171  double xPosition = 0.;
172  double yPosition = 0.;
173  double zPosition = 0.;
174  double time = 0.;
175 
176  // read in line to get event number and number of particles
177  std::string oneLine;
178  std::getline(*fInputFile, oneLine);
179  std::istringstream inputLine;
180  inputLine.str(oneLine);
181 
182  inputLine >> event >> nParticles;
183 
184  // now read in all the lines for the particles
185  // in this interaction. only particles with
186  // status = 1 get tracked in Geant4.
187  for(unsigned short i = 0; i < nParticles; ++i){
188  std::getline(*fInputFile, oneLine);
189  inputLine.clear();
190  inputLine.str(oneLine);
191 
192  inputLine >> status >> pdg
193  >> firstMother >> secondMother >> firstDaughter >> secondDaughter
194  >> xMomentum >> yMomentum >> zMomentum >> energy >> mass
195  >> xPosition >> yPosition >> zPosition >> time;
196 
197  //Project the particle to a new y plane
198  if (fMoveY>-1e8){
199  double totmom = sqrt(pow(xMomentum,2)+pow(yMomentum,2)+pow(zMomentum,2));
200  double kx = xMomentum/totmom;
201  double ky = yMomentum/totmom;
202  double kz = zMomentum/totmom;
203  if (ky){
204  double l = (fMoveY-yPosition)/ky;
205  xPosition += kx*l;
206  yPosition += ky*l;
207  zPosition += kz*l;
208  }
209  }
210 
211  TLorentzVector pos(xPosition, yPosition, zPosition, time);
212  TLorentzVector mom(xMomentum, yMomentum, zMomentum, energy);
213 
214  simb::MCParticle part(i, pdg, "primary", firstMother, mass, status);
215  part.AddTrajectoryPoint(pos, mom);
216 
217  truth.Add(part);
218  }
219 
220  truthcol->push_back(truth);
221 
222  e.put(std::move(truthcol));
223 
224  return;
225  }
std::string string
Definition: nybbler.cc:12
double fMoveY
Project particles to a new y plane.
constexpr T pow(T x)
Definition: pow.h:72
std::string fInputFileName
Name of text file containing events to simulate.
static QStrList * l
Definition: config.cpp:1044
std::ifstream * fInputFile
pointer to input text file
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
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
void gar::evgen::TextFileGen::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 228 of file TextFileGen_module.cc.

229  {
230  fInputFileName = p.get<std::string>("InputFileName");
231  fMoveY = p.get<double>("MoveY", -1e9);
232  if (fMoveY>-1e8){
233  MF_LOG_WARNING("TextFileGen")
234  << "Particles will be moved to a new plane y = "
235  << fMoveY
236  << " cm.";
237  }
238  return;
239  }
std::string string
Definition: nybbler.cc:12
double fMoveY
Project particles to a new y plane.
std::string fInputFileName
Name of text file containing events to simulate.
p
Definition: test.py:223
#define MF_LOG_WARNING(category)

Member Data Documentation

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

pointer to input text file

Definition at line 95 of file TextFileGen_module.cc.

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

Name of text file containing events to simulate.

Definition at line 96 of file TextFileGen_module.cc.

double gar::evgen::TextFileGen::fMoveY
private

Project particles to a new y plane.

Definition at line 97 of file TextFileGen_module.cc.


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