Public Member Functions | Private Member Functions | Private Attributes | List of all members
g4n::G4Alg Class Reference

An algorithm to pass interaction information to Geant4 and create hits and particle lists. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-01/g4nova/G4Alg.h"

Public Member Functions

 G4Alg (fhicl::ParameterSet const &pset)
 
virtual ~G4Alg ()
 
void RunGeant (std::vector< art::Handle< std::vector< simb::MCTruth > > > &mclists, std::vector< sim::FLSHitList > &flshitlist, std::vector< sim::Particle > &particlelist, std::vector< std::vector< std::pair< size_t, size_t > > > &pListLimits)
 
void RunGeant (std::vector< const simb::MCTruth * > &mctruths, std::vector< sim::FLSHitList > &flshitlist, std::vector< sim::Particle > &particlelist, std::map< int, size_t > &trackIDToMCTruthIndex)
 
void RunGeant (art::Ptr< simb::MCTruth > mctruth, std::vector< sim::FLSHitList > &flshitlist, std::vector< sim::Particle > &particlelist, int trackIDOffset=-1)
 
void RunGeant (const simb::MCTruth *mctruth, std::vector< sim::FLSHitList > &flshitlist, std::vector< sim::Particle > &particlelist, int trackIDOffset=-1)
 
bool IsAborted ()
 

Private Member Functions

void CollectFLSHitsAndParticles (std::vector< sim::FLSHitList > &flshitlist, std::vector< sim::Particle > &particlelist)
 
void ConfigUserActionManager (std::vector< std::string > const &actionList, fhicl::ParameterSet const &pset)
 
void OverridePDGLifetimes ()
 

Private Attributes

g4b::G4Helper * fG4Help
 G4Helper object. More...
 
std::string fG4MacroPath
 path to G4 macro More...
 
std::string fG4PhysListName
 name of G4 physics list to use More...
 
double fEnergyThresh
 threshold for stopping the tracking of a particle in GeV More...
 
bool fManyParticles
 if true, keep individual track ids from processes like compt and brem More...
 
bool fSparseTrajectories
 if true, only save necessary points in particle trajectories More...
 
bool fIsRockVetoUsed
 Is RockVeto check used? More...
 
bool fSlimSimParticles
 if true, only save particles which lead to an FLS hit More...
 
std::string fGenModuleLabel
 < If a particle leaves the DetectorBigBox, stop tracking it More...
 
int fPlaIndex
 index of the ParticleListAction in the UserActionManager More...
 
int fFlsIndex
 index of the FLSHitListAction in the UserActionManager More...
 
std::vector< std::stringfUserActions
 UserAction classes. More...
 
std::vector< intfOverrideLifetimePDG
 list of pdg code to change More...
 
std::vector< double > fOverrideLifetimeNS
 new lifetime of PDG in ns More...
 
bool fPrintTables
 Print dE/dx tables and other info once per job for debugging etc.? More...
 

Detailed Description

An algorithm to pass interaction information to Geant4 and create hits and particle lists.

Definition at line 32 of file G4Alg.h.

Constructor & Destructor Documentation

g4n::G4Alg::G4Alg ( fhicl::ParameterSet const &  pset)
explicit

In principle the next two should just be always the start of the UserAction list, but for now handle these separately until they learn to config from Config()

dummy vector in case user didn't set "AddedUserActions" in fcl file

dummy vectors in case user didn't set "OverrideLifetimePDG" or "OverrideLifetimeNS"

Definition at line 47 of file G4Alg.cxx.

References g4n::ParticleListAction::Config(), g4n::FLSHitListAction::Config(), ConfigUserActionManager(), fEnergyThresh, fFlsIndex, fG4Help, fG4MacroPath, fG4PhysListName, cet::search_path::find_file(), fIsRockVetoUsed, fManyParticles, fOverrideLifetimeNS, fOverrideLifetimePDG, fPlaIndex, fUserActions, geo::GeometryBase::GDMLFile(), fhicl::ParameterSet::get(), calib::j, OverridePDGLifetimes(), std_candles::pl, g4n::NeutronSubstitutionPhysics::SetFatesFile(), g4n::NeutronSubstitutionPhysics::SetMaxKE(), g4n::NeutronSubstitutionPhysics::SetMinKE(), and string.

48  : fG4Help(0)
49  , fG4PhysListName (pset.get< std::string >("G4PhysListName", "QGSP_BERT" ) )
50  , fEnergyThresh (pset.get< double >("G4EnergyThreshold") )
51  , fManyParticles (pset.get< bool >("ManyParticles") )
52  , fSparseTrajectories (pset.get< bool >("SparseTrajectories") )
53  , fIsRockVetoUsed (pset.get< bool >("G4CheckRockVeto") )
54  , fSlimSimParticles (pset.get< bool >("SlimSimParticles") )
55  , fGenModuleLabel (pset.get< std::string >("GenModuleLabel") )
56  , fPlaIndex(0)
57  , fFlsIndex(0)
58  , fPrintTables (pset.get< bool >("PrintTables") )
59  {
60 
61  /// In principle the next two should just be always the start of the
62  /// UserAction list, but for now handle these separately until they
63  /// learn to config from Config()
64  // fUserActions.push_back("ParticleListAction");
65  // fUserActions.push_back("FLSHitListAction");
66 
67  /// dummy vector in case user didn't set "AddedUserActions" in fcl file
68  std::vector<std::string> nullstrvec; // empty vector of strings
69  const std::vector<std::string>& psetstrvec =
70  pset.get< std::vector<std::string> >("AddedUserActions",nullstrvec);
71 
72  for (size_t j=0; j < psetstrvec.size(); ++j) {
73  fUserActions.push_back(psetstrvec[j]); // append user entries to list of actions
74  }
75 
76  /// dummy vectors in case user didn't set "OverrideLifetimePDG"
77  /// or "OverrideLifetimeNS"
78  std::vector<int> nullintvec;
79  std::vector<double> nulldblvec;
80  fOverrideLifetimePDG = pset.get< std::vector<int> >("OverrideLifetimePDG",nullintvec);
81  fOverrideLifetimeNS = pset.get< std::vector<double> >("OverrideLifetimeNS",nulldblvec);
82  size_t npdg = fOverrideLifetimePDG.size();
83  size_t ntime = fOverrideLifetimeNS.size();
84 
85  if ( npdg != ntime ) {
86  mf::LogError("G4Alg")
87  << "Attempt to override PDG lifetime in Geant4 failed\n"
88  << "due to size mismatch: "
89  << npdg << " PDG vs. " << ntime << " times";
90 
91  fOverrideLifetimePDG.clear();
92  fOverrideLifetimeNS.clear();
93 
94  throw cet::exception("OverrideLifetimePairMismatch")
95  << "Can't override G4 particle lifetimes without matching set: "
96  << npdg << " PDG vs. " << ntime << " times" << "\n"
97  << __FILE__ << ":" << __LINE__ << "\n";
98  }
99 
100  // Configure neutron substitution. There doesn't seem to be any built in
101  // way to configure physics processes in geant?
102  if(fG4PhysListName.find("g4n::NeutronSubstitutionPhysics") != std::string::npos){
103  g4n::NeutronSubstitutionPhysics::SetMinKE(pset.get<double>("NeutronSubstitutionMinKE"));
104  g4n::NeutronSubstitutionPhysics::SetMaxKE(pset.get<double>("NeutronSubstitutionMaxKE"));
105  g4n::NeutronSubstitutionPhysics::SetFatesFile(pset.get<std::string>("NeutronSubstitutionFatesFile"));
106  }
107 
108  // Constructor decides if initialized value is a path or
109  // an environment variable
110  cet::search_path sp("FW_SEARCH_PATH");
111 
112  sp.find_file(pset.get< std::string >("G4MacroPath"), fG4MacroPath);
113  struct stat sb;
114  if ( fG4MacroPath.empty() || stat(fG4MacroPath.c_str(), &sb)!=0 ) {
115  // failed to resolve the file name
116  throw cet::exception("NoG4Macro")
117  << "G4 macro file " << fG4MacroPath << " not found!\n"
118  << __FILE__ << ":" << __LINE__ << "\n";
119  }
120 
121  // need to instantiate the G4Helper in order to make the
122  // G4RunManager and pass it the physics list - G4 really dislikes
123  // it if you try to make a G4UserRunAction (ie UserActionManager)
124  // before passing a physics list to the run manager
126  fG4Help = new g4b::G4Helper(fG4MacroPath,
128  geo->GDMLFile());
129 
130  // more control over GDML processing (before InitPhysics)
131  const bool dfltOverlap = false;
132  const bool dfltSchema = true;
133  bool overlapCheck = pset.get< bool >("G4OverlapCheck",dfltOverlap);
134  bool validateGDMLSchema = pset.get< bool >("G4ValidateGDMLSchema",dfltSchema);
135  if ( dfltOverlap != overlapCheck || dfltSchema != validateGDMLSchema ) {
136  mf::LogInfo("G4Alg") << "non-standard GDML processing: "
137  << std::boolalpha
138  << "overlapCheck " << overlapCheck
139  << " [" << dfltOverlap << "] "
140  << "validateGDMLSchema " << validateGDMLSchema
141  << " ]" << dfltSchema << "] "
142  << std::noboolalpha;
143  }
144  fG4Help->SetOverlapCheck(overlapCheck);
145  fG4Help->SetValidateGDMLSchema(validateGDMLSchema);
146 
147  // Initialize the helper (physics stage)
148  fG4Help->InitPhysics();
149 
150  G4Material * steel = G4Material::GetMaterial("Steel");
151 
152  if(steel != NULL){
153  if(steel->GetMaterialPropertiesTable() == NULL)
154  steel->SetMaterialPropertiesTable(new G4MaterialPropertiesTable);
155  steel->GetMaterialPropertiesTable()->AddConstProperty("conductor", 1);
156  }
157 
158  // Geant4 comes with "user hooks" that allows users to perform
159  // special tasks at the beginning and end of runs, events, tracks,
160  // steps. By using the UserActionManager, we've separated each
161  // set of user tasks into their own class; e.g., there can be one
162  // class for processing voxels, one class for processing
163  // particles, one class for histograms, etc.
164 
165  // All UserActions must be adopted after the InitMC call
166 
167  // Setup the user actions that we want to use.
168  g4b::UserActionManager* uam = g4b::UserActionManager::Instance();
169 
171  fls->SetName("g4n::FLSHitListAction");
172  fls->Config( pset );
173 
175  pl->SetName("g4n::ParticleListAction");
176  pl->Config( pset );
177 
178  // the ParticleListAction must be added to the UserActionManager
179  // first as it has to define the track ID in the case that the
180  // current particle to track is from an EM process that would cause
181  // it not to be added to the list and the track ID has to be
182  // reassigned to be the same as its mother.
183  uam->AddAndAdoptAction(pl);
184  fPlaIndex = uam->GetSize() - 1;
185  //if (false) std::cerr << "RWH: fPlaIndex " << fPlaIndex
186  // << " vs " << uam->GetIndex("g4n::ParticleListAction")
187  // << std::endl;
188 
189 
190  uam->AddAndAdoptAction(fls);
191  fFlsIndex = uam->GetSize() - 1;
192  //if (false) std::cerr << "RWH: fFlsIndex " << fFlsIndex
193  // << " vs " << uam->GetIndex("g4n::FLSHitListAction")
194  // << std::endl;
195 
197 
198  uam->PrintActionList("config");
199 
200  // Complete the initialize the helper (actions+finalize stage)
201  fG4Help->SetUserAction();
202 
203  // Allow user to adjust particle lifetimes
205 
206  return;
207  }// end of constructor
bool fIsRockVetoUsed
Is RockVeto check used?
Definition: G4Alg.h:74
int fPlaIndex
index of the ParticleListAction in the UserActionManager
Definition: G4Alg.h:82
void OverridePDGLifetimes()
Definition: G4Alg.cxx:503
std::vector< double > fOverrideLifetimeNS
new lifetime of PDG in ns
Definition: G4Alg.h:88
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
int fFlsIndex
index of the FLSHitListAction in the UserActionManager
Definition: G4Alg.h:83
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
double fEnergyThresh
threshold for stopping the tracking of a particle in GeV
Definition: G4Alg.h:71
void Config(fhicl::ParameterSet const &pset)
list of energy deposits from Geant4
std::string fG4MacroPath
path to G4 macro
Definition: G4Alg.h:69
std::string fGenModuleLabel
< If a particle leaves the DetectorBigBox, stop tracking it
Definition: G4Alg.h:80
void ConfigUserActionManager(std::vector< std::string > const &actionList, fhicl::ParameterSet const &pset)
Definition: G4Alg.cxx:217
const double j
Definition: BetheBloch.cxx:29
static void SetFatesFile(const std::string &s)
bool fPrintTables
Print dE/dx tables and other info once per job for debugging etc.?
Definition: G4Alg.h:90
std::vector< int > fOverrideLifetimePDG
list of pdg code to change
Definition: G4Alg.h:87
void Config(fhicl::ParameterSet const &pset)
std::string GDMLFile() const
Definition: GeometryBase.h:235
bool fSparseTrajectories
if true, only save necessary points in particle trajectories
Definition: G4Alg.h:73
std::vector< std::string > fUserActions
UserAction classes.
Definition: G4Alg.h:85
Helper for AttenCurve.
Definition: Path.h:10
bool fManyParticles
if true, keep individual track ids from processes like compt and brem
Definition: G4Alg.h:72
std::string fG4PhysListName
name of G4 physics list to use
Definition: G4Alg.h:70
g4b::G4Helper * fG4Help
G4Helper object.
Definition: G4Alg.h:68
bool fSlimSimParticles
if true, only save particles which lead to an FLS hit
Definition: G4Alg.h:75
enum BeamMode string
g4n::G4Alg::~G4Alg ( )
virtual

Definition at line 211 of file G4Alg.cxx.

References fG4Help.

212  {
213  if (fG4Help) delete fG4Help;
214  } // end of destructor
g4b::G4Helper * fG4Help
G4Helper object.
Definition: G4Alg.h:68

Member Function Documentation

void g4n::G4Alg::CollectFLSHitsAndParticles ( std::vector< sim::FLSHitList > &  flshitlist,
std::vector< sim::Particle > &  particlelist 
)
private

Definition at line 385 of file G4Alg.cxx.

References d, fFlsIndex, sim::FLSHitList::fHits, fPlaIndex, fSlimSimParticles, fSparseTrajectories, simb::MCParticle::GetGvtx(), make_syst_table_plots::h, MECModelEnuComparisons::i, makeTrainCVSamples::int, simb::MCTrajectory::Momentum(), simb::MCParticle::Mother(), getGoodRuns4SAM::n, part, std_candles::pl, simb::MCTrajectory::Position(), simb::MCTrajectory::push_back(), simb::MCParticle::SetPolarization(), simb::MCTrajectory::size(), confusionMatrixTree::t, and simb::MCParticle::TrackId().

Referenced by RunGeant().

387  {
388  // Make auto_pts of the lists.
389  g4b::UserActionManager* uam = g4b::UserActionManager::Instance();
390  sim::FLSHitList& flshl = *(dynamic_cast<FLSHitListAction *>(uam->GetAction(fFlsIndex))->GetList());
391  std::vector<sim::Particle> pl = dynamic_cast<ParticleListAction *>(uam->GetAction(fPlaIndex))->GetList();
392 
394  for(unsigned int n = 0; n < pl.size(); ++n){
395  pl[n].SparsifyTrajectory();
396  }
397  }
398 
399  /* If the list of FLS hits for this MCTruth is empty, then we
400  should not store any of the associated sim::Particle objects.
401  (Just be done at this point and return.) */
402  if(fSlimSimParticles){
403  if ( flshl.fHits.empty() ) return;
404  }
405 
406  // Push them to the total vector of FLSHitList
407  flshitlist.push_back(flshl);
408 
409  if ( fSlimSimParticles ) {
410  // Keep only particles associated with FLS hits, either directly
411  // or through an ancestor (e.g. if it entered or exited the detector)
412  std::set<int> IDsToStore;
413  // First start with IDs directly associated with FLS hits
414  for ( size_t h = 0; h < flshl.fHits.size(); ++h ) {
415  IDsToStore.insert(flshl.fHits[h].GetTrackID());
416  }
417  // Loop through particles to find descendants of FLS-hit-makers
418  std::set<sim::Particle> partsToStore;
419  for ( size_t p = 0; p < pl.size(); ++p ) {
420  sim::Particle *thisParticle = &pl[p];
421  bool assocWithFLS(false);
422  if ( IDsToStore.find( thisParticle->TrackId() ) != IDsToStore.end() ) {
423  // Directly associated with an FLS hit! Keep it.
424  assocWithFLS = true;
425  }
426  int motherTrkID = thisParticle->Mother();
427  while ( !assocWithFLS && motherTrkID != 0 ) {
428  // Is this ancestor associated with an FLS hit?
429  if ( IDsToStore.find( motherTrkID ) != IDsToStore.end() ) assocWithFLS = true;
430  for ( size_t i = 0; i < pl.size(); ++i ) {
431  if ( pl[i].TrackId() == motherTrkID ) motherTrkID = pl[i].Mother();
432  }
433  }
434  if ( assocWithFLS ) {
435  partsToStore.insert( *thisParticle );
436  IDsToStore.insert( thisParticle->TrackId() );
437  }
438  }
439  // Loop through selected particles to find and include all of their ancestors
440  for ( size_t p = 0; p < pl.size(); ++p ) {
441  if ( IDsToStore.find(pl[p].TrackId()) != IDsToStore.end() ) {
442  // Add this particle and its ancestors to the list of particles to keep
443  sim::Particle *thisParticle = &pl[p];
444  while ( thisParticle->Mother() != 0 ) {
445  // Get the mother
446  for ( size_t i = 0; i < pl.size(); ++i ) {
447  if ( pl[i].TrackId() == thisParticle->Mother() ) {
448  thisParticle = &pl[i];
449  }
450  }
451  partsToStore.insert( *thisParticle );
452  IDsToStore.insert( thisParticle->TrackId() );
453  }
454  }
455  }
456  // One more loop to keep all primaries (particles with Mother ID = 0)
457  for ( size_t p = 0; p < pl.size(); ++p ) {
458  sim::Particle *thisParticle = &pl[p];
459  if ( thisParticle->Mother() == 0 ) {
460  partsToStore.insert( *thisParticle );
461  IDsToStore.insert( thisParticle->TrackId() );
462  }
463  }
464  // Transfer the selected particles to the particle list
465  for( std::set<sim::Particle>::iterator p = partsToStore.begin();
466  p != partsToStore.end(); ++p ) {
467  // Recreate this particle in order to slim down the daughter list, too
468  sim::Particle newParticle(p->TrackId(),
469  p->PdgCode(),
470  p->Process(),
471  p->Mother(),
472  p->Mass(),
473  p->StatusCode() );
474  newParticle.SetPolarization( p->Polarization() );
475  sim::Particle part = *p; newParticle.SetGvtx( part.GetGvtx() );
476  newParticle.SetRescatter( p->Rescatter() );
477  newParticle.SetWeight( p->Weight() );
478  simb::MCTrajectory traj = p->Trajectory();
479  for ( int t = 0; t < (int)traj.size(); ++t ) {
480  newParticle.AddTrajectoryPoint( traj.Position(t), traj.Momentum(t) );
481  }
482  for ( int d = 0; d < p->NumberDaughters(); ++d ) {
483  int trkID = p->Daughter(d);
484  if ( IDsToStore.find( trkID ) != IDsToStore.end() ) {
485  newParticle.AddDaughter( trkID );
486  }
487  }
488  // Save it!
489  particlelist.push_back( newParticle );
490  }
491  } else {
492  // Keep all sim::Particles from this event
493  for(size_t p = 0; p < pl.size(); ++p){
494  particlelist.push_back(pl[p]);
495  }
496  }
497 
498  return;
499  }
std::vector< sim::FLSHit > fHits
Definition: FLSHitList.h:21
int fPlaIndex
index of the ParticleListAction in the UserActionManager
Definition: G4Alg.h:82
void push_back(value_type const &v)
int Mother() const
Definition: MCParticle.h:212
const char * p
Definition: xmltok.h:285
int fFlsIndex
index of the FLSHitListAction in the UserActionManager
Definition: G4Alg.h:83
TLorentzVector GetGvtx() const
Definition: MCParticle.h:244
int TrackId() const
Definition: MCParticle.h:209
TString part[npart]
Definition: Style.C:32
void SetPolarization(const TVector3 &p)
Definition: MCParticle.h:265
Float_t d
Definition: plot.C:236
const TLorentzVector & Position(const size_type) const
The accessor methods described above.
bool fSparseTrajectories
if true, only save necessary points in particle trajectories
Definition: G4Alg.h:73
size_type size() const
Definition: MCTrajectory.h:165
A vector of FLSHit from single neutrino interaction.
Definition: FLSHitList.h:13
const TLorentzVector & Momentum(const size_type) const
bool fSlimSimParticles
if true, only save particles which lead to an FLS hit
Definition: G4Alg.h:75
void g4n::G4Alg::ConfigUserActionManager ( std::vector< std::string > const &  actionList,
fhicl::ParameterSet const &  pset 
)
private

additional user supplied UserAction classes

Definition at line 217 of file G4Alg.cxx.

References allTimeWatchdog::endl, modifyFHiCL::found, fhicl::ParameterSet::get_if_present(), calib::j, LOG_VERBATIM, and string.

Referenced by G4Alg().

219  {
220 
221  /// additional user supplied UserAction classes
222 
223  // UserActionManager is a singleton, so get a handle
224  g4b::UserActionManager* uam = g4b::UserActionManager::Instance();
225 
226  // The factory is also a singleton
227  g4b::UserActionFactory& uafactory = g4b::UserActionFactory::Instance();
228 
229 
230  // given a list of classes, ask the factory for a copy and configure
231  // it before handing it to the manager
232 
233  for (size_t j = 0; j < actionList.size(); ++j ) {
234 
235  std::string uaname = actionList[j]; // will use name for finding pset too
236  g4b::UserAction* ua = uafactory.GetUserAction(uaname);
237 
238  if( ua ){
239  // factory constructed a UserAction, now configure it
240  // parameter set name can't have colons
241  // (ie not namespace qualified class used to create our object)
242  // take only the class name portion
243  size_t icolon = uaname.find_last_of(":");
244  if ( icolon == std::string::npos ) icolon = -1;
245  std::string psetname = uaname.substr(icolon+1); // don't include colon
246 
247  // check if there is a sub-pset with the same name as the
248  // (non-namespaced) class name we're trying to configure
249  fhicl::ParameterSet uapset; // for holding results of fetching sub-pset
250  bool found = pset.get_if_present< fhicl::ParameterSet >(psetname,uapset);
251 
252  mf::LogInfo("G4Alg") << "UserAction \"" << uaname << "\" to be Config() with "
253  << ( ( found ) ? "\"" : "G4AlgPSet, couldn't find \"" )
254  << psetname << "\" pset";
255 
256  // if no named sub-pset available, pass the one G4Alg got
257  fhicl::ParameterSet const& pset2pass = ( found ) ? uapset : pset;
258 
259  // configure using _some_ pset
260  ua->Config(pset2pass);
261  // add to the manager
262  uam->AddAndAdoptAction(ua);
263 
264  }
265  else {
266  // ooops, factory failed ... let someone know
267 
268  const std::vector<std::string>& availActions = uafactory.AvailableUserActions();
269  LOG_VERBATIM("G4Alg") << "g4n::G4Alg requested UserAction \"" << uaname << "\" from "
270  << "g4b::UserActionFactory" << std::endl
271  << "but it only knows about: ";
272  for(size_t k=0; k<availActions.size(); ++k)
273  LOG_VERBATIM("G4Alg") << " " << availActions[k];
274  LOG_VERBATIM("G4Alg") << "proceeding without this action";
275  }
276  }
277  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
const double j
Definition: BetheBloch.cxx:29
#define LOG_VERBATIM(category)
enum BeamMode string
bool g4n::G4Alg::IsAborted ( )

Definition at line 375 of file G4Alg.cxx.

References fPlaIndex.

Referenced by g4n::G4Gen::produce().

376  {
377  g4b::UserActionManager* uam = g4b::UserActionManager::Instance();
378  return dynamic_cast<g4n::ParticleListAction*>(uam->GetAction(fPlaIndex))->IsAborted();
379  } // Check whether Geant event was aborted
int fPlaIndex
index of the ParticleListAction in the UserActionManager
Definition: G4Alg.h:82
bool IsAborted()
Definition: G4Alg.cxx:375
void g4n::G4Alg::OverridePDGLifetimes ( )
private

Definition at line 503 of file G4Alg.cxx.

References fOverrideLifetimeNS, fOverrideLifetimePDG, LOG_ERROR, LOG_INFO, getGoodRuns4SAM::n, CLHEP::ns, and make_root_from_grid_output::pdg.

Referenced by G4Alg().

504  {
505  int n = fOverrideLifetimePDG.size();
506  for (int k=0; k<n; ++k) {
507  int pdg = fOverrideLifetimePDG[k];
508  double lifetime = fOverrideLifetimeNS[k];
509  G4ParticleDefinition* g4pdef =
510  G4ParticleTable::GetParticleTable()->FindParticle(pdg);
511  if ( ! g4pdef ) {
512  LOG_ERROR("G4Alg")
513  << "Attempt to override PDG lifetime in Geant4 failed "
514  << "to get a G4ParticleDefintions for PDG=" << pdg;
515  continue;
516  }
517  LOG_INFO("G4Alg")
518  << "Modifying the G4ParticleDefinition for PDG=" << pdg
519  << ", lifetime was " << g4pdef->GetPDGLifeTime()/CLHEP::ns << " (ns) to "
520  << lifetime;
521  g4pdef->SetPDGLifeTime(lifetime*CLHEP::ns);
522  }
523 
524  }
std::vector< double > fOverrideLifetimeNS
new lifetime of PDG in ns
Definition: G4Alg.h:88
static constexpr double ns
std::vector< int > fOverrideLifetimePDG
list of pdg code to change
Definition: G4Alg.h:87
#define LOG_INFO(stream)
Definition: Messenger.h:144
#define LOG_ERROR(stream)
Definition: Messenger.h:129
void g4n::G4Alg::RunGeant ( std::vector< art::Handle< std::vector< simb::MCTruth > > > &  mclists,
std::vector< sim::FLSHitList > &  flshitlist,
std::vector< sim::Particle > &  particlelist,
std::vector< std::vector< std::pair< size_t, size_t > > > &  pListLimits 
)

Definition at line 280 of file G4Alg.cxx.

References febshutoff_auto::end, fPlaIndex, MECModelEnuComparisons::i, and febshutoff_auto::start.

Referenced by murem::MRE::produce(), g4n::G4Gen::produce(), and RunGeant().

284  {
285  g4b::UserActionManager* uam = g4b::UserActionManager::Instance();
286  dynamic_cast<g4n::ParticleListAction*>(uam->GetAction(fPlaIndex))->ResetAbortFlag();
287  dynamic_cast<ParticleListAction *>(uam->GetAction(fPlaIndex))->ResetTrackIDOffset();
288 
289  particlelist.clear();
290  flshitlist .clear();
291 
292  // pListLimits keeps track of the index of first particle for a given MCTruth
293  // in the particlelist vector and the index beyond the last particle
294  pListLimits .clear();
295  pListLimits .resize(mclists.size());
296 
297  // Need to process Geant4 simulation for each interaction separately.
298  for(size_t mcl = 0; mcl < mclists.size(); ++mcl){
299 
300  art::Handle< std::vector<simb::MCTruth> > mclistHandle = mclists[mcl];
301 
302  for(size_t i = 0; i < mclistHandle->size(); ++i){
303  const simb::MCTruth* mct(&(*mclistHandle)[i]);
304 
305  size_t start = particlelist.size();
306  this->RunGeant(mct, flshitlist, particlelist);
307  size_t end = particlelist.size();
308 
309  pListLimits[mcl].push_back(std::pair<size_t, size_t>(start, end));
310 
311  }// end of loop over interactions in the current handle
312  }// end loop over handles
313 
314  return;
315  }// end of RunGeant
void RunGeant(std::vector< art::Handle< std::vector< simb::MCTruth > > > &mclists, std::vector< sim::FLSHitList > &flshitlist, std::vector< sim::Particle > &particlelist, std::vector< std::vector< std::pair< size_t, size_t > > > &pListLimits)
Definition: G4Alg.cxx:280
int fPlaIndex
index of the ParticleListAction in the UserActionManager
Definition: G4Alg.h:82
Event generator information.
Definition: MCTruth.h:32
void g4n::G4Alg::RunGeant ( std::vector< const simb::MCTruth * > &  mctruths,
std::vector< sim::FLSHitList > &  flshitlist,
std::vector< sim::Particle > &  particlelist,
std::map< int, size_t > &  trackIDToMCTruthIndex 
)

Definition at line 318 of file G4Alg.cxx.

References CollectFLSHitsAndParticles(), fG4Help, fPlaIndex, g4n::ParticleListAction::ResetTrackIDOffset(), and g4n::ParticleListAction::TrackIDToMCTruthIndexMap().

322  {
323  g4b::UserActionManager* uam = g4b::UserActionManager::Instance();
324  dynamic_cast<g4n::ParticleListAction*>(uam->GetAction(fPlaIndex))->ResetAbortFlag();
325  ParticleListAction* pla = dynamic_cast<ParticleListAction *>(uam->GetAction(fPlaIndex));
326  pla->ResetTrackIDOffset();
327 
328  particlelist.clear();
329  flshitlist .clear();
330 
331  // trackIDToMCTruthIndex keeps track of which trackIDs correspond to which MCTruth
332  // in mctruths
333  trackIDToMCTruthIndex.clear();
334 
335  fG4Help->G4Run(mctruths);
336 
337  this->CollectFLSHitsAndParticles(flshitlist, particlelist);
338  trackIDToMCTruthIndex = pla->TrackIDToMCTruthIndexMap();
339 
340  return;
341  }// end of RunGeant
int fPlaIndex
index of the ParticleListAction in the UserActionManager
Definition: G4Alg.h:82
void ResetTrackIDOffset(int offset=0)
void CollectFLSHitsAndParticles(std::vector< sim::FLSHitList > &flshitlist, std::vector< sim::Particle > &particlelist)
Definition: G4Alg.cxx:385
g4b::G4Helper * fG4Help
G4Helper object.
Definition: G4Alg.h:68
void g4n::G4Alg::RunGeant ( art::Ptr< simb::MCTruth mctruth,
std::vector< sim::FLSHitList > &  flshitlist,
std::vector< sim::Particle > &  particlelist,
int  trackIDOffset = -1 
)

Definition at line 344 of file G4Alg.cxx.

References art::Ptr< T >::get(), and RunGeant().

348  {
349  this->RunGeant(mctruth.get(), flshitlist, particlelist, trackIDOffset);
350  }
void RunGeant(std::vector< art::Handle< std::vector< simb::MCTruth > > > &mclists, std::vector< sim::FLSHitList > &flshitlist, std::vector< sim::Particle > &particlelist, std::vector< std::vector< std::pair< size_t, size_t > > > &pListLimits)
Definition: G4Alg.cxx:280
T const * get() const
Definition: Ptr.h:321
void g4n::G4Alg::RunGeant ( const simb::MCTruth mctruth,
std::vector< sim::FLSHitList > &  flshitlist,
std::vector< sim::Particle > &  particlelist,
int  trackIDOffset = -1 
)

Definition at line 353 of file G4Alg.cxx.

References CollectFLSHitsAndParticles(), fG4Help, fPlaIndex, and LOG_DEBUG.

357  {
358  g4b::UserActionManager* uam = g4b::UserActionManager::Instance();
359  dynamic_cast<g4n::ParticleListAction*>(uam->GetAction(fPlaIndex))->ResetAbortFlag();
360 
361  LOG_DEBUG("G4Alg") << *mctruth;
362 
363  if(trackIDOffset > 0){
364  dynamic_cast<ParticleListAction *>(uam->GetAction(fPlaIndex))->ResetTrackIDOffset(trackIDOffset);
365  }
366 
367  // The following tells Geant4 to track the particles in this interaction.
368  fG4Help->G4Run(mctruth);
369 
370  this->CollectFLSHitsAndParticles(flshitlist, particlelist);
371 
372  return;
373  }// end RunGeant for a single simb::MCTruth
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
int fPlaIndex
index of the ParticleListAction in the UserActionManager
Definition: G4Alg.h:82
void CollectFLSHitsAndParticles(std::vector< sim::FLSHitList > &flshitlist, std::vector< sim::Particle > &particlelist)
Definition: G4Alg.cxx:385
g4b::G4Helper * fG4Help
G4Helper object.
Definition: G4Alg.h:68

Member Data Documentation

double g4n::G4Alg::fEnergyThresh
private

threshold for stopping the tracking of a particle in GeV

Definition at line 71 of file G4Alg.h.

Referenced by G4Alg().

int g4n::G4Alg::fFlsIndex
private

index of the FLSHitListAction in the UserActionManager

Definition at line 83 of file G4Alg.h.

Referenced by CollectFLSHitsAndParticles(), and G4Alg().

g4b::G4Helper* g4n::G4Alg::fG4Help
private

G4Helper object.

Definition at line 68 of file G4Alg.h.

Referenced by G4Alg(), RunGeant(), and ~G4Alg().

std::string g4n::G4Alg::fG4MacroPath
private

path to G4 macro

Definition at line 69 of file G4Alg.h.

Referenced by G4Alg().

std::string g4n::G4Alg::fG4PhysListName
private

name of G4 physics list to use

Definition at line 70 of file G4Alg.h.

Referenced by G4Alg().

std::string g4n::G4Alg::fGenModuleLabel
private

< If a particle leaves the DetectorBigBox, stop tracking it

< to define the DetectorBigBox. label of module that made the particles to track

Definition at line 80 of file G4Alg.h.

bool g4n::G4Alg::fIsRockVetoUsed
private

Is RockVeto check used?

Definition at line 74 of file G4Alg.h.

Referenced by G4Alg().

bool g4n::G4Alg::fManyParticles
private

if true, keep individual track ids from processes like compt and brem

Definition at line 72 of file G4Alg.h.

Referenced by G4Alg().

std::vector<double> g4n::G4Alg::fOverrideLifetimeNS
private

new lifetime of PDG in ns

Definition at line 88 of file G4Alg.h.

Referenced by G4Alg(), and OverridePDGLifetimes().

std::vector<int> g4n::G4Alg::fOverrideLifetimePDG
private

list of pdg code to change

Definition at line 87 of file G4Alg.h.

Referenced by G4Alg(), and OverridePDGLifetimes().

int g4n::G4Alg::fPlaIndex
private

index of the ParticleListAction in the UserActionManager

Definition at line 82 of file G4Alg.h.

Referenced by CollectFLSHitsAndParticles(), G4Alg(), IsAborted(), and RunGeant().

bool g4n::G4Alg::fPrintTables
private

Print dE/dx tables and other info once per job for debugging etc.?

Definition at line 90 of file G4Alg.h.

bool g4n::G4Alg::fSlimSimParticles
private

if true, only save particles which lead to an FLS hit

Definition at line 75 of file G4Alg.h.

Referenced by CollectFLSHitsAndParticles().

bool g4n::G4Alg::fSparseTrajectories
private

if true, only save necessary points in particle trajectories

Definition at line 73 of file G4Alg.h.

Referenced by CollectFLSHitsAndParticles().

std::vector<std::string> g4n::G4Alg::fUserActions
private

UserAction classes.

Definition at line 85 of file G4Alg.h.

Referenced by G4Alg().


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