Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
evgen::TextFileGen Class Reference
Inheritance diagram for evgen::TextFileGen:
art::EDProducer art::ProducerBase art::Consumer art::EngineCreator art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
using WorkerType = WorkerT< EDProducer >
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = ProducerBase::Table< UserConfig, KeysToIgnore >
 

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)
 
void endSubRun (art::SubRun &sr) override
 
template<typename PROD , BranchType B = InEvent>
ProductID getProductID (std::string const &instanceName={}) const
 
template<typename PROD , BranchType B>
ProductID getProductID (ModuleDescription const &moduleDescription, std::string const &instanceName) const
 
bool modifiesEvent () const
 
template<typename T , BranchType = InEvent>
ProductToken< Tconsumes (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< Tconsumes (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TconsumesView (InputTag const &it)
 
template<typename T , BranchType = InEvent>
ProductToken< TmayConsume (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ProductToken< TmayConsume (InputTag const &it)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , art::BranchType BT>
art::ViewToken< TmayConsumeView (InputTag const &it)
 
base_engine_tcreateEngine (seed_t seed)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make)
 
base_engine_tcreateEngine (seed_t seed, std::string const &kind_of_engine_to_make, label_t const &engine_label)
 
seed_t get_seed_value (fhicl::ParameterSet const &pset, char const key[]="seed", seed_t const implicit_seed=-1)
 

Static Public Member Functions

static cet::exempt_ptr< Consumernon_module_context ()
 

Protected Member Functions

CurrentProcessingContext const * currentContext () const
 
void validateConsumedProduct (BranchType const bt, ProductInfo const &pi)
 
void prepareForJob (fhicl::ParameterSet const &pset)
 
void showMissingConsumes () const
 

Private Member Functions

bool readHeader (uint64_t &event, uint64_t &nParticles)
 
bool readParticle (hepevtpart &hpart)
 

Private Attributes

std::ifstream * fInputFile
 
std::string fInputFileName
 Name of text file containing events to simulate. More...
 
int fCycle
 MC production cycle. More...
 

Static Private Attributes

static constexpr const char *const modname = "TextFileGen"
 

Detailed Description

Definition at line 125 of file TextFileGen_module.cc.

Member Typedef Documentation

using art::EDProducer::ModuleType = EDProducer
inherited

Definition at line 34 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::EDProducer::Table = ProducerBase::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 43 of file EDProducer.h.

using art::EDProducer::WorkerType = WorkerT<EDProducer>
inherited

Definition at line 35 of file EDProducer.h.

Constructor & Destructor Documentation

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

Definition at line 153 of file TextFileGen_module.cc.

References reconfigure().

154 : fInputFile(NULL)
155 , fCycle (p.get<int>("Cycle", 0))
156 {
157  this->reconfigure(p);
158 
159  produces< std::vector<simb::MCTruth> >();
160  produces< sumdata::RunData, art::InRun >();
161  produces< sumdata::SubRunData, art::InSubRun >();
162 }
const char * p
Definition: xmltok.h:285
int fCycle
MC production cycle.
std::ifstream * fInputFile
void reconfigure(fhicl::ParameterSet const &p)
evgen::TextFileGen::~TextFileGen ( )
virtual

Definition at line 165 of file TextFileGen_module.cc.

166 {
167 }

Member Function Documentation

void evgen::TextFileGen::beginJob ( )
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 170 of file TextFileGen_module.cc.

References fInputFile, fInputFileName, MECModelEnuComparisons::i, LogInfo, cet::sqlite::max(), modname, readHeader(), and readParticle().

171 {
172  fInputFile = new std::ifstream(fInputFileName.c_str());
173 
174  // check that the file is a good one
175  if( !fInputFile->good() )
176  throw cet::exception(modname) << "input text file " << fInputFileName
177  << " cannot be read.\n";
178 
179  // Count input events and particles just so we can print it below.
180  uint64_t ntotevent = 0, ntotpart = 0;
181 
182  // Read the whole file to see if it is properly formatted before starting the
183  // simulation. We do *not* want to waste hours of time simulating events
184  // only to bomb out on a bad line in this file.
185  while(!fInputFile->eof()){
186  // Use this as a magic number to test for EOF. NOEVENT NOEVENT is
187  // theoretically a valid header line, but has more particles than
188  // could be simulated in the age of the Universe.
189  const uint64_t NOEVENT = std::numeric_limits<uint64_t>::max();
190 
191  uint64_t event = NOEVENT, nParticles = NOEVENT;
192  if(!readHeader(event, nParticles))
193  throw cet::exception(modname) << "Bad input file " << fInputFileName
194  << "\nSee error above\n";
195 
196  if(event == NOEVENT && nParticles == NOEVENT) break; // Found end of file
197 
198  for(unsigned short i = 0; i < nParticles; ++i){
199  hepevtpart hpart;
200  if(!readParticle(hpart))
201  throw cet::exception(modname) << "Bad input file " << fInputFileName
202  << "\nSee error above\n";
203  ntotpart++;
204  }
205 
206  ntotevent++;
207  }
208 
209  LogInfo(modname) << "Input text file is validated. "
210  << ntotevent << " events with " << ntotpart << " total particles";
211 
212  fInputFile->clear(); // rewinding doesn't work without clearing eof error
213  fInputFile->seekg(0); // rewind to beginning of file
214 }
bool readHeader(uint64_t &event, uint64_t &nParticles)
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
std::string fInputFileName
Name of text file containing events to simulate.
std::ifstream * fInputFile
bool readParticle(hepevtpart &hpart)
static constexpr const char *const modname
T max(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:68
void evgen::TextFileGen::beginRun ( art::Run run)
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 217 of file TextFileGen_module.cc.

References geo::GeometryBase::DetId(), geo::GeometryBase::FileBaseName(), and art::Run::put().

218 {
219  // grab the geometry object to see what geometry we are using
221 
222  novadaq::cnv::DetId detid = geo->DetId();
223 
224  std::unique_ptr<sumdata::RunData> runcol(new sumdata::RunData(detid, geo->FileBaseName()));
225 
226  run.put(std::move(runcol));
227 }
art::ProductID put(std::unique_ptr< PROD > &&)
Definition: Run.h:149
novadaq::cnv::DetId DetId() const
Prefer ds::DetectorService::DetId() instead.
Definition: GeometryBase.h:243
Helper for AttenCurve.
Definition: Path.h:10
std::string FileBaseName() const
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::consumes ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::consumes ( InputTag const &  it)
inherited

Definition at line 146 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

147 {
148  if (!moduleContext_)
149  return ProductToken<T>::invalid();
150 
151  consumables_[BT].emplace_back(ConsumableType::Product,
152  TypeID{typeid(T)},
153  it.label(),
154  it.instance(),
155  it.process());
156  return ProductToken<T>{it};
157 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::consumesMany ( )
inherited

Definition at line 161 of file Consumer.h.

References T.

162 {
163  if (!moduleContext_)
164  return;
165 
166  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
167 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::consumesView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::consumesView ( InputTag const &  it)
inherited

Definition at line 171 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

172 {
173  if (!moduleContext_)
174  return ViewToken<T>::invalid();
175 
176  consumables_[BT].emplace_back(ConsumableType::ViewElement,
177  TypeID{typeid(T)},
178  it.label(),
179  it.instance(),
180  it.process());
181  return ViewToken<T>{it};
182 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make 
)
inherited
base_engine_t& art::EngineCreator::createEngine ( seed_t  seed,
std::string const &  kind_of_engine_to_make,
label_t const &  engine_label 
)
inherited
CurrentProcessingContext const* art::EDProducer::currentContext ( ) const
protectedinherited
void evgen::TextFileGen::endSubRun ( art::SubRun sr)
overridevirtual

Reimplemented from art::EDProducer.

Definition at line 230 of file TextFileGen_module.cc.

References fCycle, art::SubRun::put(), and sd().

231 {
232  // store the cycle information
234  std::unique_ptr< sumdata::SubRunData > sd(new sumdata::SubRunData(fCycle));
235  sr.put(std::move(sd));
236 }
int fCycle
MC production cycle.
double sd(Eigen::VectorXd x)
ProductID put(std::unique_ptr< PROD > &&)
Helper for AttenCurve.
Definition: Path.h:10
seed_t art::EngineCreator::get_seed_value ( fhicl::ParameterSet const &  pset,
char const  key[] = "seed",
seed_t const  implicit_seed = -1 
)
inherited
template<typename PROD , BranchType B>
ProductID art::EDProducer::getProductID ( std::string const &  instanceName = {}) const
inlineinherited

Definition at line 123 of file EDProducer.h.

References art::EDProducer::moduleDescription_.

Referenced by skim::NueSkimmer::CopyMichelSlice(), and skim::NueSkimmer::CopyMichelTrack().

124  {
125  return ProducerBase::getProductID<PROD, B>(moduleDescription_,
126  instanceName);
127  }
ModuleDescription moduleDescription_
Definition: EDProducer.h:115
template<typename PROD , BranchType B>
ProductID art::ProducerBase::getProductID ( ModuleDescription const &  moduleDescription,
std::string const &  instanceName 
) const
inherited

Definition at line 56 of file ProducerBase.h.

References art::ModuleDescription::moduleLabel().

Referenced by art::ProducerBase::modifiesEvent().

58  {
59  auto const& pd =
60  get_ProductDescription<PROD>(B, md.moduleLabel(), instanceName);
61  return pd.productID();
62  }
template<typename T , BranchType = InEvent>
ProductToken<T> art::Consumer::mayConsume ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ProductToken<T> art::Consumer::mayConsume ( InputTag const &  it)
inherited

Definition at line 189 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

190 {
191  if (!moduleContext_)
192  return ProductToken<T>::invalid();
193 
194  consumables_[BT].emplace_back(ConsumableType::Product,
195  TypeID{typeid(T)},
196  it.label(),
197  it.instance(),
198  it.process());
199  return ProductToken<T>{it};
200 }
set< int >::iterator it
static ProductToken< T > invalid()
Definition: ProductToken.h:47
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename T , art::BranchType BT>
void art::Consumer::mayConsumeMany ( )
inherited

Definition at line 204 of file Consumer.h.

References T.

205 {
206  if (!moduleContext_)
207  return;
208 
209  consumables_[BT].emplace_back(ConsumableType::Many, TypeID{typeid(T)});
210 }
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::Consumer::mayConsumeView ( InputTag const &  )
inherited
template<typename T , art::BranchType BT>
art::ViewToken<T> art::Consumer::mayConsumeView ( InputTag const &  it)
inherited

Definition at line 214 of file Consumer.h.

References art::InputTag::instance(), PandAna.reco_validation.prod5_pid_validation::invalid, art::InputTag::label(), art::InputTag::process(), and T.

215 {
216  if (!moduleContext_)
217  return ViewToken<T>::invalid();
218 
219  consumables_[BT].emplace_back(ConsumableType::ViewElement,
220  TypeID{typeid(T)},
221  it.label(),
222  it.instance(),
223  it.process());
224  return ViewToken<T>{it};
225 }
set< int >::iterator it
static ViewToken< Element > invalid()
Definition: ProductToken.h:75
ConsumableProducts consumables_
Definition: Consumer.h:137
double T
Definition: Xdiff_gwt.C:5
bool moduleContext_
Definition: Consumer.h:135
bool art::ProducerBase::modifiesEvent ( ) const
inlineinherited

Definition at line 40 of file ProducerBase.h.

References art::ProducerBase::getProductID(), and string.

41  {
42  return true;
43  }
static cet::exempt_ptr<Consumer> art::Consumer::non_module_context ( )
staticinherited
void art::Consumer::prepareForJob ( fhicl::ParameterSet const &  pset)
protectedinherited
void evgen::TextFileGen::produce ( art::Event e)
overridevirtual

Implements art::EDProducer.

Definition at line 299 of file TextFileGen_module.cc.

References simb::MCTruth::Add(), simb::MCParticle::AddTrajectoryPoint(), evgen::hepevtpart::energy, fInputFile, fInputFileName, evgen::hepevtpart::firstMother, MECModelEnuComparisons::i, LogDebug, LogError, LogWarning, evgen::hepevtpart::mass, modname, part, evgen::hepevtpart::pdg, elec2geo::pos, art::Event::put(), readHeader(), readParticle(), evgen::hepevtpart::status, evgen::hepevtpart::time, evgen::hepevtpart::xMomentum, evgen::hepevtpart::xPosition, evgen::hepevtpart::yMomentum, evgen::hepevtpart::yPosition, evgen::hepevtpart::zMomentum, and evgen::hepevtpart::zPosition.

300 {
301  std::unique_ptr< std::vector<simb::MCTruth> > truthcol(new std::vector<simb::MCTruth>);
302  simb::MCTruth truth;
303 
304  if( !fInputFile->good() ){
305  LogWarning(modname) << "input file " << fInputFileName
306  << " cannot be read in produce(). Probably it is exhausted. Making empty event.";
307  }
308  else{
309  uint64_t event = 0, nParticles = 0;
310 
311  if(!readHeader(event, nParticles)){
312  LogError(modname) << "Bad event header, even though I validated it before!\n"
313  "Did you change the file? Making empty event.";
314  nParticles = 0;
315  }
316 
317  // Now read in all the lines for the particles. In this interaction. only
318  // particles with status = 1 get tracked in Geant4.
319  for(unsigned short i = 0; i < nParticles; ++i){
320  hepevtpart hpart;
321  if(!readParticle(hpart)){
322  LogError(modname) << "Bad particle line, even though I validated it before!\n"
323  "Did you change the file? Skipping!";
324  continue;
325  }
326 
327  TLorentzVector pos(hpart.xPosition, hpart.yPosition, hpart.zPosition, hpart.time);
328  TLorentzVector mom(hpart.xMomentum, hpart.yMomentum, hpart.zMomentum, hpart.energy);
329 
330  simb::MCParticle part(i, hpart.pdg, "primary", hpart.firstMother, hpart.mass, hpart.status);
331  part.AddTrajectoryPoint(pos, mom);
332 
333  LogDebug(modname) << "created particle\n" << part;
334 
335  truth.Add(part);
336  }
337  }
338 
339  truthcol->push_back(truth);
340  e.put(std::move(truthcol));
341 }
bool readHeader(uint64_t &event, uint64_t &nParticles)
void Add(simb::MCParticle &part)
Definition: MCTruth.h:79
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
std::string fInputFileName
Name of text file containing events to simulate.
std::ifstream * fInputFile
TString part[npart]
Definition: Style.C:32
bool readParticle(hepevtpart &hpart)
static constexpr const char *const modname
Event generator information.
Definition: MCTruth.h:32
bool evgen::TextFileGen::readHeader ( uint64_t &  event,
uint64_t &  nParticles 
)
private

Definition at line 238 of file TextFileGen_module.cc.

References fInputFile, LogDebug, LogError, modname, and string.

Referenced by beginJob(), and produce().

239 {
240  // Read in line to get event number and number of particles. Skip over blank
241  // lines and comments (comments with '#' are not part of the HEPEVT standard,
242  // but are used in NOvA).
243  std::string oneLine;
244  do std::getline(*fInputFile, oneLine);
245  while(fInputFile->good() && (oneLine.size() < 1 || oneLine[0] == '#'));
246 
247  // It is *not* an error if the file has no more lines on it
248  if(oneLine.empty()) return true;
249 
250  char extra;
251 
252  // It *is* an error if this line exists and has junk on it.
253  if(2 != sscanf(oneLine.c_str(), "%lu %lu %c", &event, &nParticles, &extra)){
254  LogError(modname) << "Event header line misformatted: \"" << oneLine
255  << "\"\nShould be two unsigned integers.";
256  return false;
257  }
258 
259  LogDebug(modname) << "Got event " << event << " with " << nParticles << " particles";
260 
261  return true;
262 }
std::ifstream * fInputFile
static constexpr const char *const modname
enum BeamMode string
bool evgen::TextFileGen::readParticle ( hepevtpart hpart)
private

Definition at line 264 of file TextFileGen_module.cc.

References evgen::hepevtpart::energy, fInputFile, evgen::hepevtpart::firstDaughter, evgen::hepevtpart::firstMother, LogError, evgen::hepevtpart::mass, modname, evgen::hepevtpart::pdg, evgen::hepevtpart::secondDaughter, evgen::hepevtpart::secondMother, evgen::hepevtpart::status, string, evgen::hepevtpart::time, evgen::hepevtpart::xMomentum, evgen::hepevtpart::xPosition, evgen::hepevtpart::yMomentum, evgen::hepevtpart::yPosition, evgen::hepevtpart::zMomentum, and evgen::hepevtpart::zPosition.

Referenced by beginJob(), and produce().

265 {
266  std::string oneLine;
267  do std::getline(*fInputFile, oneLine);
268  while(fInputFile->good() && (oneLine.size() < 1 || oneLine[0] == '#'));
269 
270  char extra;
271 
272  // The line noise here enforces that each number has a non-zero length of
273  // white-space between it and the next. Otherwise, if the first number on
274  // the line is missing, the integer part of the first float will match
275  // for secondDaughter, and the fractional part will match for xMomentum,
276  // and it will test as correct! Other pathologies like this are probably
277  // possible.
278  if(15 != sscanf(oneLine.c_str(),
279  "%d%*[ \t]%d%*[ \t]%d%*[ \t]%d%*[ \t]%d%*[ \t]%d%*[ \t]"
280  "%lf%*[ \t]%lf%*[ \t]%lf%*[ \t]%lf%*[ \t]"
281  "%lf%*[ \t]%lf%*[ \t]%lf%*[ \t]%lf%*[ \t]%lf"
282  "%c",
283  &hpart.status, &hpart.pdg,
284  &hpart.firstMother, &hpart.secondMother,
285  &hpart.firstDaughter, &hpart.secondDaughter,
286  &hpart.xMomentum, &hpart.yMomentum, &hpart.zMomentum,
287  &hpart.energy, &hpart.mass,
288  &hpart.xPosition, &hpart.yPosition, &hpart.zPosition,
289  &hpart.time, &extra)){
290  LogError(modname) << "Wrong format while reading particle: \"" << oneLine
291  << "\"\nShould be six integers and nine floats.";
292  return false;
293  }
294 
295  return true;
296 }
std::ifstream * fInputFile
static constexpr const char *const modname
enum BeamMode string
void evgen::TextFileGen::reconfigure ( fhicl::ParameterSet const &  p)

Definition at line 344 of file TextFileGen_module.cc.

References DEFINE_ART_MODULE(), fInputFileName, fhicl::ParameterSet::get(), and string.

Referenced by TextFileGen().

345 {
346  fInputFileName = p.get<std::string>("InputFileName");
347 }
const char * p
Definition: xmltok.h:285
std::string fInputFileName
Name of text file containing events to simulate.
enum BeamMode string
void art::Consumer::showMissingConsumes ( ) const
protectedinherited

Referenced by art::RootOutput::endJob().

void art::Consumer::validateConsumedProduct ( BranchType const  bt,
ProductInfo const &  pi 
)
protectedinherited

Member Data Documentation

int evgen::TextFileGen::fCycle
private

MC production cycle.

Definition at line 139 of file TextFileGen_module.cc.

Referenced by endSubRun().

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

Definition at line 137 of file TextFileGen_module.cc.

Referenced by beginJob(), produce(), readHeader(), and readParticle().

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

Name of text file containing events to simulate.

Definition at line 138 of file TextFileGen_module.cc.

Referenced by beginJob(), produce(), and reconfigure().

constexpr const char* const evgen::TextFileGen::modname = "TextFileGen"
staticprivate

Definition at line 149 of file TextFileGen_module.cc.

Referenced by beginJob(), produce(), readHeader(), and readParticle().


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