LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
evgen::FileMuons Class Reference

module to produce single or multiple specified particles in the detector More...

Inheritance diagram for evgen::FileMuons:
art::EDProducer art::detail::Producer art::detail::LegacyModule art::Modifier art::ModuleBase art::ProductRegistryHelper

Public Types

using ModuleType = EDProducer
 
template<typename UserConfig , typename KeysToIgnore = void>
using Table = Modifier::Table< UserConfig, KeysToIgnore >
 

Public Member Functions

 FileMuons (fhicl::ParameterSet const &pset)
 
void produce (art::Event &evt)
 
void beginJob ()
 
void beginRun (art::Run &run)
 
void endJob ()
 
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)
 
void fillProductDescriptions ()
 
void registerProducts (ProductDescriptions &productsToRegister)
 
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)
 
std::unique_ptr< Worker > makeWorker (WorkerParams const &wp)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Protected Member Functions

ConsumesCollector & consumesCollector ()
 
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 ()
 

Private Member Functions

void ReadEvents (simb::MCTruth &mct)
 

Private Attributes

int fEventNumberOffset
 
std::vector< int > fPDG
 
std::vector< double > fXYZ_Off
 
std::string fFileName
 
std::string fMuonsFileType
 
std::string fTreeName
 
std::vector< std::string > fBranchNames
 
std::ifstream * fMuonFile
 
TFile * fMuonFileR
 
TTree * TNtuple
 
unsigned int countFile
 
Float_t xtmp
 
Float_t ytmp
 
Float_t ztmp
 
Float_t pxtmp
 
Float_t pytmp
 
Float_t pztmp
 
Float_t charge
 
Float_t E
 
Float_t costheta
 
Float_t phi
 
Float_t xdet
 
Float_t ydet
 
Float_t zdet
 
TBranch * b_x
 
TBranch * b_y
 
TBranch * b_z
 
TBranch * b_E
 
TBranch * b_costheta
 
TBranch * b_phi
 
TBranch * b_xdet
 
TBranch * b_ydet
 
TBranch * b_zdet
 
TBranch * b_px
 
TBranch * b_py
 
TBranch * b_pz
 
TBranch * b_charge
 

Detailed Description

module to produce single or multiple specified particles in the detector

Definition at line 44 of file FileMuons_module.cc.

Member Typedef Documentation

Definition at line 17 of file EDProducer.h.

template<typename UserConfig , typename KeysToIgnore = void>
using art::detail::Producer::Table = Modifier::Table<UserConfig, KeysToIgnore>
inherited

Definition at line 26 of file Producer.h.

Constructor & Destructor Documentation

evgen::FileMuons::FileMuons ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 100 of file FileMuons_module.cc.

References fBranchNames, fEventNumberOffset, fFileName, fMuonsFileType, fPDG, fTreeName, and fXYZ_Off.

101  : EDProducer{pset}
102  , fEventNumberOffset(pset.get<int>("EventNumberOffset"))
103  , fPDG(pset.get<std::vector<int>>("PDG"))
104  , fXYZ_Off(pset.get<std::vector<double>>("InitialXYZOffsets"))
105  , fFileName(pset.get<std::string>("FileName"))
106  , fMuonsFileType(pset.get<std::string>("MuonsFileType"))
107  , fTreeName(pset.get<std::string>("TreeName"))
108  , fBranchNames(pset.get<std::vector<std::string>>("BranchNames"))
109  {
110 
111  produces<std::vector<simb::MCTruth>>();
112  produces<sumdata::RunData, art::InRun>();
113  }
std::vector< double > fXYZ_Off
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
std::string fMuonsFileType
std::vector< std::string > fBranchNames
std::string fFileName
std::vector< int > fPDG
std::string fTreeName

Member Function Documentation

void evgen::FileMuons::beginJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 116 of file FileMuons_module.cc.

References b_charge, b_costheta, b_E, b_phi, b_px, b_py, b_pz, b_x, b_xdet, b_y, b_ydet, b_z, b_zdet, util::begin(), charge, costheta, countFile, E, util::end(), fEventNumberOffset, fFileName, fMuonFile, fMuonFileR, fMuonsFileType, fTreeName, phi, pxtmp, pytmp, pztmp, TNtuple, xdet, xtmp, ydet, ytmp, zdet, and ztmp.

117  {
119  mf::LogInfo("FileMuons : starting at event ") << countFile << std::endl;
120 
121  if (fMuonsFileType.compare("source") == 0) {
122  std::cout << "FileMuons: Not yet equipped to walk through muons with TFS mojo." << std::endl;
123  }
124  else if (fMuonsFileType.compare("root") == 0) {
125  std::cout << "FileMuons: You have chosen to read muons from Root File " << fFileName
126  << std::endl;
127  }
128  else if (fMuonsFileType.compare("text") == 0) {
129  std::cout << "FileMuons: You have chosen to read muons from " << fFileName << "."
130  << std::endl;
131  }
132  else {
133  std::cout << "FileMuons: You must specify one of source/text/root file to read for muons."
134  << std::endl;
135  }
136 
137  if (fMuonsFileType.compare("text") == 0) {
138  fMuonFile = new std::ifstream(fFileName.c_str());
139  long begin = fMuonFile->tellg();
140  fMuonFile->seekg(0, std::ios::end);
141  long end = fMuonFile->tellg();
142  std::cout << "FileMuons: " << fFileName << " size is: " << (end - begin) << " bytes.\n";
143  fMuonFile->seekg(0, std::ios::beg);
144 
145  for (unsigned int header = 0; header < 3 && fMuonFile->good(); ++header) {
146  std::string line;
147  getline(*fMuonFile, line);
148  }
149  if (!fMuonFile->good()) {
150  std::cout << "FileMuons: Problem reading muon file header." << std::endl;
151  }
152  } // fMuonsFileType is a text file.
153  else if (fMuonsFileType.compare("root") == 0) {
154  fMuonFileR = new TFile(fFileName.c_str(), "READ");
155  TNtuple = (TTree*)(fMuonFileR->Get(fTreeName.c_str()));
156 
157  TNtuple->SetBranchAddress("x", &xtmp, &b_x);
158  TNtuple->SetBranchAddress("y", &ytmp, &b_y);
159  TNtuple->SetBranchAddress("z", &ztmp, &b_z);
160  TNtuple->SetBranchAddress("E", &E, &b_E);
161  TNtuple->SetBranchAddress("costheta", &costheta, &b_costheta);
162  TNtuple->SetBranchAddress("phi", &phi, &b_phi);
163  TNtuple->SetBranchAddress("xdet", &xdet, &b_xdet);
164  TNtuple->SetBranchAddress("ydet", &ydet, &b_ydet);
165  TNtuple->SetBranchAddress("zdet", &zdet, &b_zdet);
166  TNtuple->SetBranchAddress("px", &pxtmp, &b_px);
167  TNtuple->SetBranchAddress("py", &pytmp, &b_py);
168  TNtuple->SetBranchAddress("pz", &pztmp, &b_pz);
169  TNtuple->SetBranchAddress("charge", &charge, &b_charge);
170 
171  } // fMuonsFileType is a root file.
172  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::string fMuonsFileType
std::ifstream * fMuonFile
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
unsigned int countFile
std::string fFileName
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
std::string fTreeName
void evgen::FileMuons::beginRun ( art::Run run)
virtual

Reimplemented from art::EDProducer.

Definition at line 182 of file FileMuons_module.cc.

References geo::GeometryCore::DetectorName(), art::fullRun(), and art::Run::put().

183  {
185  run.put(std::make_unique<sumdata::RunData>(geo->DetectorName()), art::fullRun());
186  }
constexpr auto fullRun()
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Run.h:121
std::string const & DetectorName() const
Returns a string with the name of the detector, as configured.
Definition: GeometryCore.h:203
Namespace collecting geometry-related classes utilities.
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::consumes ( InputTag const &  tag)
protectedinherited

Definition at line 61 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumes().

62  {
63  return collector_.consumes<T, BT>(tag);
64  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ProductToken< T > consumes(InputTag const &)
ConsumesCollector & art::ModuleBase::consumesCollector ( )
protectedinherited

Definition at line 57 of file ModuleBase.cc.

References art::ModuleBase::collector_.

58  {
59  return collector_;
60  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename T , BranchType BT>
void art::ModuleBase::consumesMany ( )
protectedinherited

Definition at line 75 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumesMany().

76  {
77  collector_.consumesMany<T, BT>();
78  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::consumesView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::consumesView ( InputTag const &  tag)
inherited

Definition at line 68 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::consumesView().

69  {
70  return collector_.consumesView<T, BT>(tag);
71  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ViewToken< Element > consumesView(InputTag const &)
void art::detail::Producer::doBeginJob ( SharedResources const &  resources)
inherited

Definition at line 22 of file Producer.cc.

References art::detail::Producer::beginJobWithFrame(), and art::detail::Producer::setupQueues().

23  {
24  setupQueues(resources);
25  ProcessingFrame const frame{ScheduleID{}};
26  beginJobWithFrame(frame);
27  }
virtual void setupQueues(SharedResources const &)=0
virtual void beginJobWithFrame(ProcessingFrame const &)=0
bool art::detail::Producer::doBeginRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited

Definition at line 65 of file Producer.cc.

References art::detail::Producer::beginRunWithFrame(), art::RangeSet::forRun(), art::RunPrincipal::makeRun(), r, art::RunPrincipal::runID(), and art::ModuleContext::scheduleID().

66  {
67  auto r = rp.makeRun(mc, RangeSet::forRun(rp.runID()));
68  ProcessingFrame const frame{mc.scheduleID()};
69  beginRunWithFrame(r, frame);
70  r.commitProducts();
71  return true;
72  }
TRandom r
Definition: spectrum.C:23
virtual void beginRunWithFrame(Run &, ProcessingFrame const &)=0
static RangeSet forRun(RunID)
Definition: RangeSet.cc:51
bool art::detail::Producer::doBeginSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited

Definition at line 85 of file Producer.cc.

References art::detail::Producer::beginSubRunWithFrame(), art::RangeSet::forSubRun(), art::SubRunPrincipal::makeSubRun(), art::ModuleContext::scheduleID(), and art::SubRunPrincipal::subRunID().

86  {
87  auto sr = srp.makeSubRun(mc, RangeSet::forSubRun(srp.subRunID()));
88  ProcessingFrame const frame{mc.scheduleID()};
89  beginSubRunWithFrame(sr, frame);
90  sr.commitProducts();
91  return true;
92  }
virtual void beginSubRunWithFrame(SubRun &, ProcessingFrame const &)=0
static RangeSet forSubRun(SubRunID)
Definition: RangeSet.cc:57
void art::detail::Producer::doEndJob ( )
inherited

Definition at line 30 of file Producer.cc.

References art::detail::Producer::endJobWithFrame().

31  {
32  ProcessingFrame const frame{ScheduleID{}};
33  endJobWithFrame(frame);
34  }
virtual void endJobWithFrame(ProcessingFrame const &)=0
bool art::detail::Producer::doEndRun ( RunPrincipal rp,
ModuleContext const &  mc 
)
inherited

Definition at line 75 of file Producer.cc.

References art::detail::Producer::endRunWithFrame(), art::RunPrincipal::makeRun(), r, art::ModuleContext::scheduleID(), and art::Principal::seenRanges().

76  {
77  auto r = rp.makeRun(mc, rp.seenRanges());
78  ProcessingFrame const frame{mc.scheduleID()};
79  endRunWithFrame(r, frame);
80  r.commitProducts();
81  return true;
82  }
TRandom r
Definition: spectrum.C:23
virtual void endRunWithFrame(Run &, ProcessingFrame const &)=0
bool art::detail::Producer::doEndSubRun ( SubRunPrincipal srp,
ModuleContext const &  mc 
)
inherited

Definition at line 95 of file Producer.cc.

References art::detail::Producer::endSubRunWithFrame(), art::SubRunPrincipal::makeSubRun(), art::ModuleContext::scheduleID(), and art::Principal::seenRanges().

96  {
97  auto sr = srp.makeSubRun(mc, srp.seenRanges());
98  ProcessingFrame const frame{mc.scheduleID()};
99  endSubRunWithFrame(sr, frame);
100  sr.commitProducts();
101  return true;
102  }
virtual void endSubRunWithFrame(SubRun &, ProcessingFrame const &)=0
bool art::detail::Producer::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 
)
inherited

Definition at line 105 of file Producer.cc.

References art::detail::Producer::checkPutProducts_, e, art::EventPrincipal::makeEvent(), art::detail::Producer::produceWithFrame(), and art::ModuleContext::scheduleID().

110  {
111  auto e = ep.makeEvent(mc);
112  ++counts_run;
113  ProcessingFrame const frame{mc.scheduleID()};
114  produceWithFrame(e, frame);
115  e.commitProducts(checkPutProducts_, &expectedProducts<InEvent>());
116  ++counts_passed;
117  return true;
118  }
bool const checkPutProducts_
Definition: Producer.h:70
Float_t e
Definition: plot.C:35
virtual void produceWithFrame(Event &, ProcessingFrame const &)=0
void art::detail::Producer::doRespondToCloseInputFile ( FileBlock const &  fb)
inherited

Definition at line 44 of file Producer.cc.

References art::detail::Producer::respondToCloseInputFileWithFrame().

45  {
46  ProcessingFrame const frame{ScheduleID{}};
48  }
virtual void respondToCloseInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToCloseOutputFiles ( FileBlock const &  fb)
inherited

Definition at line 58 of file Producer.cc.

References art::detail::Producer::respondToCloseOutputFilesWithFrame().

59  {
60  ProcessingFrame const frame{ScheduleID{}};
62  }
virtual void respondToCloseOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToOpenInputFile ( FileBlock const &  fb)
inherited

Definition at line 37 of file Producer.cc.

References art::detail::Producer::respondToOpenInputFileWithFrame().

38  {
39  ProcessingFrame const frame{ScheduleID{}};
41  }
virtual void respondToOpenInputFileWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void art::detail::Producer::doRespondToOpenOutputFiles ( FileBlock const &  fb)
inherited

Definition at line 51 of file Producer.cc.

References art::detail::Producer::respondToOpenOutputFilesWithFrame().

52  {
53  ProcessingFrame const frame{ScheduleID{}};
55  }
virtual void respondToOpenOutputFilesWithFrame(FileBlock const &, ProcessingFrame const &)=0
TFile fb("Li6.root")
void evgen::FileMuons::endJob ( )
virtual

Reimplemented from art::EDProducer.

Definition at line 175 of file FileMuons_module.cc.

References fMuonFile, fMuonFileR, and fMuonsFileType.

176  {
177  if (fMuonsFileType.compare("text") == 0) fMuonFile->close();
178  if (fMuonsFileType.compare("root") == 0) fMuonFileR->Close();
179  }
std::string fMuonsFileType
std::ifstream * fMuonFile
void art::Modifier::fillProductDescriptions ( )
inherited

Definition at line 10 of file Modifier.cc.

References art::ProductRegistryHelper::fillDescriptions(), and art::ModuleBase::moduleDescription().

11  {
13  }
void fillDescriptions(ModuleDescription const &md)
ModuleDescription const & moduleDescription() const
Definition: ModuleBase.cc:13
std::array< std::vector< ProductInfo >, NumBranchTypes > const & art::ModuleBase::getConsumables ( ) const
inherited

Definition at line 43 of file ModuleBase.cc.

References art::ModuleBase::collector_, and art::ConsumesCollector::getConsumables().

44  {
45  return collector_.getConsumables();
46  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables() const
std::unique_ptr< Worker > art::ModuleBase::makeWorker ( WorkerParams const &  wp)
inherited

Definition at line 37 of file ModuleBase.cc.

References art::ModuleBase::doMakeWorker(), and art::NumBranchTypes.

38  {
39  return doMakeWorker(wp);
40  }
virtual std::unique_ptr< Worker > doMakeWorker(WorkerParams const &wp)=0
template<typename T , BranchType BT>
ProductToken< T > art::ModuleBase::mayConsume ( InputTag const &  tag)
protectedinherited

Definition at line 82 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsume().

83  {
84  return collector_.mayConsume<T, BT>(tag);
85  }
ProductToken< T > mayConsume(InputTag const &)
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename T , BranchType BT>
void art::ModuleBase::mayConsumeMany ( )
protectedinherited

Definition at line 96 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsumeMany().

97  {
98  collector_.mayConsumeMany<T, BT>();
99  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
template<typename Element , BranchType = InEvent>
ViewToken<Element> art::ModuleBase::mayConsumeView ( InputTag const &  )
protectedinherited
template<typename T , BranchType BT>
ViewToken<T> art::ModuleBase::mayConsumeView ( InputTag const &  tag)
inherited

Definition at line 89 of file ModuleBase.h.

References art::ModuleBase::collector_, and art::ConsumesCollector::mayConsumeView().

90  {
91  return collector_.mayConsumeView<T, BT>(tag);
92  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
ViewToken< Element > mayConsumeView(InputTag const &)
ModuleDescription const & art::ModuleBase::moduleDescription ( ) const
inherited

Definition at line 13 of file ModuleBase.cc.

References art::errors::LogicError.

Referenced by art::OutputModule::doRespondToOpenInputFile(), art::OutputModule::doWriteEvent(), art::Modifier::fillProductDescriptions(), art::OutputModule::makePlugins_(), art::OutputWorker::OutputWorker(), reco::shower::LArPandoraModularShowerCreation::produce(), art::Modifier::registerProducts(), and art::OutputModule::registerProducts().

14  {
15  if (md_.has_value()) {
16  return *md_;
17  }
18 
20  "There was an error while calling moduleDescription().\n"}
21  << "The moduleDescription() base-class member function cannot be called\n"
22  "during module construction. To determine which module is "
23  "responsible\n"
24  "for calling it, find the '<module type>:<module "
25  "label>@Construction'\n"
26  "tag in the message prefix above. Please contact artists@fnal.gov\n"
27  "for guidance.\n";
28  }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::optional< ModuleDescription > md_
Definition: ModuleBase.h:55
void evgen::FileMuons::produce ( art::Event evt)
virtual

unique_ptr allows ownership to be transferred to the art::Event after the put statement

Implements art::EDProducer.

Definition at line 189 of file FileMuons_module.cc.

References simb::kSingleParticle, art::Event::put(), ReadEvents(), and simb::MCTruth::SetOrigin().

190  {
191 
193  std::unique_ptr<std::vector<simb::MCTruth>> truthcol(new std::vector<simb::MCTruth>);
194 
195  simb::MCTruth truth;
197  ReadEvents(truth);
198 
199  // std::cout << "put mctruth into the vector" << std::endl;
200  truthcol->push_back(truth);
201 
202  // std::cout << "add vector to the event " << truthcol->size() << std::endl;
203  evt.put(std::move(truthcol));
204 
205  return;
206  }
void SetOrigin(simb::Origin_t origin)
Definition: MCTruth.h:82
void ReadEvents(simb::MCTruth &mct)
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
single particles thrown at the detector
Definition: MCTruth.h:26
Event generator information.
Definition: MCTruth.h:32
void evgen::FileMuons::ReadEvents ( simb::MCTruth mct)
private

every event will have one of each particle species in the fPDG array

Definition at line 209 of file FileMuons_module.cc.

References simb::MCTruth::Add(), simb::MCParticle::AddTrajectoryPoint(), charge, countFile, geo::GeometryCore::CryostatHalfHeight(), geo::GeometryCore::CryostatHalfWidth(), geo::GeometryCore::CryostatLength(), DEFINE_ART_MODULE, fFileName, fMuonFile, fMuonsFileType, fPDG, fXYZ_Off, MF_LOG_DEBUG, part, pxtmp, pytmp, pztmp, TNtuple, x, xdet, ydet, and zdet.

Referenced by produce().

210  {
211 
212  // std::cout << "size of particle vector is " << fPDG.size() << std::endl;
213 
215  for (unsigned int i = 0; i < fPDG.size(); ++i) {
216 
217  // Choose momentum
218  //double p = 0.0;
219  double m(0.108);
220 
221  TVector3 x;
222  TVector3 p;
223  Double_t q = 0.;
224  Int_t pdgLocal;
225 
226  if (fMuonsFileType.compare("text") == 0) {
227 
228  std::string line;
229  getline(*fMuonFile, line);
230  if (!fMuonFile->good()) {
231  std::cout << "FileMuons: Problem reading muon file line ...." << countFile
232  << ". Perhaps you've exhausted the events in " << fFileName << std::endl;
233  exit(0);
234  }
235  else {
236  // std::cout << "FileMuons: getline() gives "<< line << " for event " << countFile << std::endl;
237  }
238  countFile++;
239 
240  MF_LOG_DEBUG("FileMuons: countFile is ") << countFile << std::endl;
241  char *cstr, *ptok;
242 
243  // Split this line into tokens
244  cstr = new char[line.size() + 1];
245  strcpy(cstr, line.c_str());
246  // cstr now contains a c-string copy of str
247  ptok = strtok(cstr, "*");
248  unsigned int fieldCount = 0;
249  unsigned int posIndex = 0;
250  unsigned int pIndex = 0;
251  while (ptok != NULL) {
252  // std::cout << ptok << std::endl;
253  ptok = strtok(NULL, "*");
254  if (fieldCount == 9 || fieldCount == 10 || fieldCount == 11) {
255  p[pIndex] = atof(ptok);
256  pIndex++;
257  // std::cout << ptok << std::endl;
258  }
259  if (fieldCount == 6 || fieldCount == 7 || fieldCount == 8) {
260  x[posIndex] = atof(ptok);
261  // make the z axis point up for x, as with p
262  if (posIndex == 2) { x[posIndex] = -1.0 * x[posIndex]; }
263  posIndex++;
264  }
265  if (fieldCount == 12) { q = atof(ptok); }
266  fieldCount++;
267  }
268 
269  delete[] cstr;
270  }
271  else if (fMuonsFileType.compare("root") == 0) // from root file
272  {
273  /*
274  // Don't use this yet. Keep the specific branch-by-branch identification.
275  for (unsigned int ii=0;ii<fBranchNames.size();ii++)
276  {
277  TNtuple->SetBranchAddress(fBranchNames[ii], x+ii);
278  }
279  */
280  // TNtuple->ResetBranchAddresses();
281  TNtuple->GetEntry(countFile);
282  //TNtuple->Show(countFile);
283 
284  x.SetXYZ(xdet, ydet, -zdet); // as with txt file, make z point up.
285  // Watch for units change to mm in Modern JdJ files!!
286  // This is for pre Spring-2012 JdJ Ntuples.
287  p.SetXYZ(pxtmp, pytmp, pztmp);
288  q = charge;
289 
290  countFile++;
291 
292  } // End read.
293 
294  static TDatabasePDG pdgt;
295  pdgLocal = -q * fPDG[i];
296 
297  TParticlePDG* pdgp = pdgt.GetParticle(pdgLocal);
298  if (pdgp) m = pdgp->Mass();
299 
300  // std::cout << "set the position "<<std::endl;
301  // This gives coordinates at the center of the 300mx300m plate that is 3m above top of
302  // cavern. Got these by histogramming deJong's xdet,ydet,zdet.
303  const double cryoGap = 15.0;
304  x[0] -= fXYZ_Off[0];
305  x[1] -= fXYZ_Off[1];
306  x[2] -= fXYZ_Off[2]; // 3 for plate height above top of cryostat.
307  // Now, must rotate to TPC coordinates. Let's orient TPC axis along z axis,
308  // Cosmics, mostly going along deJong's +z axis must be going along TPC -y axis.
309  x.RotateX(-M_PI / 2);
310  p.RotateX(-M_PI / 2);
311  //add vector of the position of the center of the point between Cryostats
312  // level with top. (To which I've added 3m - in above code - in height.)
313  // This is referenced from origin at center-right of first cryostat.
315  TVector3 off3(geom->CryostatHalfWidth() * 0.01,
316  geom->CryostatHalfHeight() * 0.01,
317  geom->CryostatLength() * 0.01 + cryoGap * 0.01 / 2.0);
318  x += off3;
319 
320  TLorentzVector pos(x[0] * 100.0, x[1] * 100.0, x[2] * 100.0, 0.0);
321  TLorentzVector pvec(
322  p[0] * 1000.0, p[1] * 1000.0, p[2] * 1000.0, std::sqrt(p.Mag2() * 1000.0 * 1000.0 + m * m));
323  std::cout << "x[m] and p [TeV] are " << std::endl;
324  x.Print();
325  p.Print();
326 
327  int trackid =
328  -1 * (i + 1); // set track id to -i as these are all primary particles and have id <= 0
329  std::string primary("primary");
330  simb::MCParticle part(trackid, pdgLocal, primary);
331  part.AddTrajectoryPoint(pos, pvec);
332 
333  // std::cout << "add the particle to the primary" << std::endl;
334 
335  mct.Add(part);
336 
337  } //end loop over particles
338 
339  return;
340  }
Float_t x
Definition: compare.C:6
std::vector< double > fXYZ_Off
Length_t CryostatHalfWidth(CryostatID const &cid=cryostat_zero) const
Returns the half width of the cryostat (x direction)
std::string fMuonsFileType
std::ifstream * fMuonFile
Length_t CryostatHalfHeight(CryostatID const &cid=cryostat_zero) const
Returns the height of the cryostat (y direction)
TString part[npart]
Definition: Style.C:32
unsigned int countFile
std::string fFileName
void Add(simb::MCParticle const &part)
Definition: MCTruth.h:80
Length_t CryostatLength(CryostatID const &cid=cryostat_zero) const
Returns the length of the cryostat (z direction)
#define MF_LOG_DEBUG(id)
std::vector< int > fPDG
void art::Modifier::registerProducts ( ProductDescriptions productsToRegister)
inherited

Definition at line 16 of file Modifier.cc.

References art::ModuleBase::moduleDescription(), and art::ProductRegistryHelper::registerProducts().

17  {
18  ProductRegistryHelper::registerProducts(productsToRegister,
20  }
void registerProducts(ProductDescriptions &productsToRegister, ModuleDescription const &md)
ModuleDescription const & moduleDescription() const
Definition: ModuleBase.cc:13
void art::ModuleBase::setModuleDescription ( ModuleDescription const &  md)
inherited

Definition at line 31 of file ModuleBase.cc.

References art::ModuleBase::md_.

32  {
33  md_ = md;
34  }
std::optional< ModuleDescription > md_
Definition: ModuleBase.h:55
void art::ModuleBase::sortConsumables ( std::string const &  current_process_name)
inherited

Definition at line 49 of file ModuleBase.cc.

References art::ModuleBase::collector_, and art::ConsumesCollector::sortConsumables().

50  {
51  // Now that we know we have seen all the consumes declarations,
52  // sort the results for fast lookup later.
53  collector_.sortConsumables(current_process_name);
54  }
ConsumesCollector collector_
Definition: ModuleBase.h:56
void sortConsumables(std::string const &current_process_name)

Member Data Documentation

TBranch* evgen::FileMuons::b_charge
private

Definition at line 93 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_costheta
private

Definition at line 85 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_E
private

Definition at line 84 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_phi
private

Definition at line 86 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_px
private

Definition at line 90 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_py
private

Definition at line 91 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_pz
private

Definition at line 92 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_x
private

Definition at line 81 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_xdet
private

Definition at line 87 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_y
private

Definition at line 82 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_ydet
private

Definition at line 88 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_z
private

Definition at line 83 of file FileMuons_module.cc.

Referenced by beginJob().

TBranch* evgen::FileMuons::b_zdet
private

Definition at line 89 of file FileMuons_module.cc.

Referenced by beginJob().

Float_t evgen::FileMuons::charge
private

Definition at line 73 of file FileMuons_module.cc.

Referenced by beginJob(), and ReadEvents().

Float_t evgen::FileMuons::costheta
private

Definition at line 75 of file FileMuons_module.cc.

Referenced by beginJob().

unsigned int evgen::FileMuons::countFile
private

Definition at line 69 of file FileMuons_module.cc.

Referenced by beginJob(), and ReadEvents().

Float_t evgen::FileMuons::E
private

Definition at line 74 of file FileMuons_module.cc.

Referenced by beginJob().

std::vector<std::string> evgen::FileMuons::fBranchNames
private

Definition at line 64 of file FileMuons_module.cc.

Referenced by FileMuons().

int evgen::FileMuons::fEventNumberOffset
private

Definition at line 58 of file FileMuons_module.cc.

Referenced by beginJob(), and FileMuons().

std::string evgen::FileMuons::fFileName
private

Definition at line 61 of file FileMuons_module.cc.

Referenced by beginJob(), FileMuons(), and ReadEvents().

std::ifstream* evgen::FileMuons::fMuonFile
private

Definition at line 66 of file FileMuons_module.cc.

Referenced by beginJob(), endJob(), and ReadEvents().

TFile* evgen::FileMuons::fMuonFileR
private

Definition at line 67 of file FileMuons_module.cc.

Referenced by beginJob(), and endJob().

std::string evgen::FileMuons::fMuonsFileType
private

Definition at line 62 of file FileMuons_module.cc.

Referenced by beginJob(), endJob(), FileMuons(), and ReadEvents().

std::vector<int> evgen::FileMuons::fPDG
private

Definition at line 59 of file FileMuons_module.cc.

Referenced by FileMuons(), and ReadEvents().

std::string evgen::FileMuons::fTreeName
private

Definition at line 63 of file FileMuons_module.cc.

Referenced by beginJob(), and FileMuons().

std::vector<double> evgen::FileMuons::fXYZ_Off
private

Definition at line 60 of file FileMuons_module.cc.

Referenced by FileMuons(), and ReadEvents().

Float_t evgen::FileMuons::phi
private

Definition at line 76 of file FileMuons_module.cc.

Referenced by beginJob().

Float_t evgen::FileMuons::pxtmp
private

Definition at line 72 of file FileMuons_module.cc.

Referenced by beginJob(), and ReadEvents().

Float_t evgen::FileMuons::pytmp
private

Definition at line 72 of file FileMuons_module.cc.

Referenced by beginJob(), and ReadEvents().

Float_t evgen::FileMuons::pztmp
private

Definition at line 72 of file FileMuons_module.cc.

Referenced by beginJob(), and ReadEvents().

TTree* evgen::FileMuons::TNtuple
private

Definition at line 68 of file FileMuons_module.cc.

Referenced by beginJob(), and ReadEvents().

Float_t evgen::FileMuons::xdet
private

Definition at line 77 of file FileMuons_module.cc.

Referenced by beginJob(), and ReadEvents().

Float_t evgen::FileMuons::xtmp
private

Definition at line 71 of file FileMuons_module.cc.

Referenced by beginJob().

Float_t evgen::FileMuons::ydet
private

Definition at line 78 of file FileMuons_module.cc.

Referenced by beginJob(), and ReadEvents().

Float_t evgen::FileMuons::ytmp
private

Definition at line 71 of file FileMuons_module.cc.

Referenced by beginJob().

Float_t evgen::FileMuons::zdet
private

Definition at line 79 of file FileMuons_module.cc.

Referenced by beginJob(), and ReadEvents().

Float_t evgen::FileMuons::ztmp
private

Definition at line 71 of file FileMuons_module.cc.

Referenced by beginJob().


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