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

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

Inheritance diagram for g4n::ParticleListAction:

Public Member Functions

 ParticleListAction (double energythresh=0.0, bool manyParticles=false)
 
virtual ~ParticleListAction ()
 
void Config (fhicl::ParameterSet const &pset)
 
void PrintConfig (std::string const &opt)
 
void ResetAbortFlag ()
 
bool IsAborted ()
 
void BeginOfEventAction (const G4Event *)
 
void EndOfEventAction (const G4Event *)
 
void PreTrackingAction (const G4Track *)
 
void PostTrackingAction (const G4Track *)
 
void SteppingAction (const G4Step *)
 
void ResetTrackIDOffset (int offset=0)
 
std::vector< sim::ParticleGetList () const
 
std::map< int, size_t > TrackIDToMCTruthIndexMap () const
 

Static Public Member Functions

static const int GetCurrentTrackID ()
 

Static Public Attributes

static std::map< int, std::vector< float > > fTrueDepMap
 

Private Member Functions

int GetParentage (int trackid) const
 

Private Attributes

art::ServiceHandle< geo::Geometrygeom
 
bool fIsAborted
 Whether Geant4 was aborted while tracking a particle. More...
 
G4double fEnergyCut
 The minimum energy for a particle to be included in the list. More...
 
bool fManyParticles
 When true, includes track ids from processes like compt and brem. More...
 
bool fRecordFirstBrem
 When true, saves the gamma generated by the first Brem. More...
 
bool fRecordFirstPair
 When true, saves the electron generated by the first Pair production. More...
 
bool fStoreTrajOutsideBigBox
 Otherwise trajectory details outside the big box are thrown away to save space. More...
 
sim::ParticleNavigatorfParticleNav
 
std::map< int, intfParentIDMap
 key is current track ID, value is parent ID More...
 
std::map< int, size_t > fTrackIDToMCTruthIndex
 map track ID to index of MCTruth in input list More...
 
bool fisFirstBremRecorded
 
bool fisFirstPairRecorded
 
float fThisEDep
 The energy which this particle deposited in the active volume. More...
 
float fThisEnStart
 The energy which this particle has the first time in entered the active volume. More...
 
float fThisEnEscape
 The energy which this particle had the last time it left the active volume. More...
 
bool fEnteredDet
 Boolean to state whether the particle has entered the active volume before. More...
 
bool fLeftDet
 Boolean to state whether the particle has left the active volume before (after entering it). More...
 

Static Private Attributes

static sim::ParticlefParticle = 0
 
static int fCurrentTrackID = sim::kNoParticleId
 
static int fTrackIDOffset = 0
 offset added to track ids when running over More...
 

Detailed Description

Definition at line 38 of file ParticleListAction.h.

Constructor & Destructor Documentation

g4n::ParticleListAction::ParticleListAction ( double  energythresh = 0.0,
bool  manyParticles = false 
)

Definition at line 50 of file ParticleListAction.cxx.

References fParticleNav.

52  : fIsAborted (false)
53  , fEnergyCut (energythres*CLHEP::GeV)
54  , fManyParticles (manyParticles)
55  , fRecordFirstBrem (false)
56  , fRecordFirstPair (false)
58  , fisFirstBremRecorded (false)
59  , fisFirstPairRecorded (false)
60  {
61  // Create the particle list that we'll (re-)use during the course
62  // of the Geant4 simulation.
64  }
bool fIsAborted
Whether Geant4 was aborted while tracking a particle.
bool fRecordFirstPair
When true, saves the electron generated by the first Pair production.
G4double fEnergyCut
The minimum energy for a particle to be included in the list.
bool fRecordFirstBrem
When true, saves the gamma generated by the first Brem.
sim::ParticleNavigator * fParticleNav
bool fManyParticles
When true, includes track ids from processes like compt and brem.
bool fStoreTrajOutsideBigBox
Otherwise trajectory details outside the big box are thrown away to save space.
static constexpr double GeV
g4n::ParticleListAction::~ParticleListAction ( )
virtual

Definition at line 68 of file ParticleListAction.cxx.

References fParticleNav.

69  {
70  // Delete anything that we created with "new'.
71  delete fParticleNav;
72  }
sim::ParticleNavigator * fParticleNav

Member Function Documentation

void g4n::ParticleListAction::BeginOfEventAction ( const G4Event *  )

If it is configured to record the first of these interactions, then set the variable to false. Otherwise, treat it as if we already recorded it (even though we did not)

Definition at line 97 of file ParticleListAction.cxx.

References sim::ParticleNavigator::clear(), fCurrentTrackID, fisFirstBremRecorded, fisFirstPairRecorded, fParentIDMap, fParticle, fParticleNav, fRecordFirstBrem, fRecordFirstPair, fTrackIDToMCTruthIndex, and sim::kNoParticleId.

98  {
99  // Clear any previous particle information.
100  fParticle = 0;
101  fParentIDMap.clear();
102  fParticleNav->clear();
103  fTrackIDToMCTruthIndex.clear();
104 
106 
107  //Karl::Clear the map for TrueDepMap
109 
110  /// If it is configured to record the first of these
111  /// interactions, then set the variable to false.
112  /// Otherwise, treat it as if we already recorded it (even though we did not)
114  else fisFirstBremRecorded = true;
116  else fisFirstPairRecorded = true;
117  }
static sim::Particle * fParticle
static std::map< int, std::vector< float > > fTrueDepMap
static const int kNoParticleId
Definition: Simulation.h:14
std::map< int, size_t > fTrackIDToMCTruthIndex
map track ID to index of MCTruth in input list
bool fRecordFirstPair
When true, saves the electron generated by the first Pair production.
bool fRecordFirstBrem
When true, saves the gamma generated by the first Brem.
sim::ParticleNavigator * fParticleNav
std::map< int, int > fParentIDMap
key is current track ID, value is parent ID
void g4n::ParticleListAction::Config ( fhicl::ParameterSet const &  pset)

Definition at line 75 of file ParticleListAction.cxx.

References fEnergyCut, fManyParticles, fRecordFirstBrem, fRecordFirstPair, fStoreTrajOutsideBigBox, fhicl::ParameterSet::get(), and CLHEP::GeV.

Referenced by g4n::G4Alg::G4Alg().

76  {
77  fEnergyCut = pset.get< double >("G4EnergyThreshold")*CLHEP::GeV;
78  fManyParticles = pset.get< bool >("ManyParticles");
79  fRecordFirstBrem = pset.get< bool >("RecordFirstBrem");
80  fRecordFirstPair = pset.get< bool >("RecordFirstPair");
81  fStoreTrajOutsideBigBox = pset.get< bool >("StoreTrajectoriesOutsideBigBox");
82  }
bool fRecordFirstPair
When true, saves the electron generated by the first Pair production.
G4double fEnergyCut
The minimum energy for a particle to be included in the list.
bool fRecordFirstBrem
When true, saves the gamma generated by the first Brem.
bool fManyParticles
When true, includes track ids from processes like compt and brem.
bool fStoreTrajOutsideBigBox
Otherwise trajectory details outside the big box are thrown away to save space.
static constexpr double GeV
void g4n::ParticleListAction::EndOfEventAction ( const G4Event *  e)

Definition at line 564 of file ParticleListAction.cxx.

References sim::ParticleNavigator::begin(), sim::ParticleNavigator::end(), fIsAborted, fParticleNav, LOG_DEBUG, and g4n::UpdateDaughterInformation::SetParticleNav().

565  {
566  // If the event was aborted, we want to keep track of that fact
567  // by setting this flag
568  if (e->IsAborted()) fIsAborted = true;
569 
570  // Set up the utility class for the "for_each" algorithm. (We only
571  // need a separate set-up for the utility class because we need to
572  // give it the pointer to the particle list. We're using the STL
573  // "for_each" instead of the C++ "for loop" because it's supposed
574  // to be faster.
575  UpdateDaughterInformation updateDaughterInformation;
576  updateDaughterInformation.SetParticleNav( fParticleNav );
577 
578  // Update the daughter information for each particle in the list.
579  std::for_each(fParticleNav->begin(),
580  fParticleNav->end(),
581  updateDaughterInformation);
582 
583  LOG_DEBUG("ParticleListAction") << *fParticleNav;
584  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
bool fIsAborted
Whether Geant4 was aborted while tracking a particle.
sim::ParticleNavigator * fParticleNav
Float_t e
Definition: plot.C:35
static const int g4n::ParticleListAction::GetCurrentTrackID ( )
inlinestatic
std::vector< sim::Particle > g4n::ParticleListAction::GetList ( ) const

Definition at line 489 of file ParticleListAction.cxx.

References sim::ParticleNavigator::begin(), sim::ParticleNavigator::end(), fParticleNav, fTrackIDOffset, LOG_DEBUG, and msf_helper::plist.

490  {
491  // fill a vector<sim::Particle> using the sim::ParticleNavigator
492  std::vector<sim::Particle> plist;
493 
494  // make sure to set the fTrackIDOffset with the highest G4 track id + 100
495  // the 100 gives some cushion between lists
496  int highestID = 0;
497  for(sim::ParticleNavigator::iterator itr = fParticleNav->begin(); itr != fParticleNav->end(); ++itr){
498  plist.push_back(*((*itr).second));
499  if((*itr).first > highestID) highestID = (*itr).first;
500  }
501 
502  fTrackIDOffset = highestID + 100;
503 
504  LOG_DEBUG("ParticleListAction") << *fParticleNav << "\ntrack id offset is now " << fTrackIDOffset;
505 
506  return plist;
507  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
list_type::iterator iterator
sim::ParticleNavigator * fParticleNav
static int fTrackIDOffset
offset added to track ids when running over
int g4n::ParticleListAction::GetParentage ( int  trackid) const
private

Definition at line 124 of file ParticleListAction.cxx.

References fParentIDMap, sim::kNoParticleId, and LOG_DEBUG.

Referenced by PreTrackingAction().

125  {
126  int parentid = sim::kNoParticleId;
127 
128  // search the fParentIDMap recursively until we have the parent id
129  // of the first EM particle that led to this one
130  std::map<int,int>::const_iterator itr = fParentIDMap.find(trackid);
131  while( itr != fParentIDMap.end() ){
132  LOG_DEBUG("ParticleListAction") << "parentage for " << trackid
133  << " " << (*itr).second;
134  // set the parentid to the current parent ID, when the loop ends
135  // this id will be the first EM particle
136  parentid = (*itr).second;
137  itr = fParentIDMap.find(parentid);
138  }
139  LOG_DEBUG("ParticleListAction") << "final parent ID " << parentid;
140 
141  return parentid;
142  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
static const int kNoParticleId
Definition: Simulation.h:14
std::map< int, int > fParentIDMap
key is current track ID, value is parent ID
bool g4n::ParticleListAction::IsAborted ( )
inline

Definition at line 48 of file ParticleListAction.h.

48 { return fIsAborted; };
bool fIsAborted
Whether Geant4 was aborted while tracking a particle.
void g4n::ParticleListAction::PostTrackingAction ( const G4Track *  track)

Definition at line 323 of file ParticleListAction.cxx.

References simb::MCParticle::AddTrajectoryPoint(), CLHEP::cm, confusionMatrixTree::count, sim::ParticleNavigator::end(), energy, fCurrentTrackID, fEnteredDet, sim::ParticleNavigator::find(), fParticle, fParticleNav, fStoreTrajOutsideBigBox, fThisEDep, fThisEnEscape, fThisEnStart, geom, CLHEP::GeV, geo::GeometryBase::isInsideDetectorBigBox(), make_training::momentum, simb::MCParticle::Mother(), CLHEP::ns, and simb::MCParticle::TrackId().

324  {
325  // Karl::Pushback new numbers for the containment variables
326  // --- I want loop through all of the parentage for this particle, and add the EDeps to them...
327  // --- Make an iterator to go through fParticleNav
329  while( ParItr != fParticleNav->end() ) {
330  sim::Particle TempPar = *((*ParItr).second);
331  int TempTrID = TempPar.TrackId();
332  // --- See if we already have an entry for this stored TrackID
333  if ( ParticleListAction::fTrueDepMap.count(TempTrID) == 0 ) {
334  std::vector<float> TempVec = { 0., 0., 0., 0. };
335  ParticleListAction::fTrueDepMap[TempTrID] = TempVec;
336  }
337  // --- Now check whether this particle entered the detector. If it did, change this parents vector!
338  if ( fEnteredDet ) {
339  // --- If looking at the actual particle, I want to set Entering & Leaving energy.
340  if ( TempTrID == track->GetTrackID() ) {
343  }
344  // --- Increment the count for energy deposited in the detector
345  ParticleListAction::fTrueDepMap[ TempTrID ][2] += fThisEDep;
346  // --- Increment the count for escaping energy.
348  } else {
349  // If particle didn't enter the detector...Do I event care about them then?
350  }
351  // Finally, lets see if I have a parent to this particle!
352  ParItr = fParticleNav->find( TempPar.Mother() );
353  }
354  // Karl::Pushback new numbers for the containment variables
355 
356  if( !fParticle ) return;
357  // particle final position now saved in SteppingAction when
358  // filling the TrajectoryPoint, filled using the post step point.
359 
360  //RUN_ON_PARTICLELISTACTION_DEBUG(DEBUG_POSTTRACKING, track);
361 
362  const G4ThreeVector position = track->GetPosition();
363 
364  // If the final position wasn't inside the big box, then we wouldn't have
365  // written it as a trajectory point. But we are interested in where
366  // particles stop, so do it here.
368  !geom->isInsideDetectorBigBox(position.x() / CLHEP::cm,
369  position.y() / CLHEP::cm,
370  position.z() / CLHEP::cm)){
371  G4double time = track->GetGlobalTime();
372 
373  TLorentzVector fourPos(position.x() / CLHEP::cm,
374  position.y() / CLHEP::cm,
375  position.z() / CLHEP::cm,
376  time / CLHEP::ns);
377 
378  const G4ThreeVector momentum = track->GetMomentum();
379  const G4double energy = track->GetTotalEnergy();
380  TLorentzVector fourMom(momentum.x() / CLHEP::GeV,
381  momentum.y() / CLHEP::GeV,
382  momentum.z() / CLHEP::GeV,
383  energy / CLHEP::GeV);
384 
385  fParticle->AddTrajectoryPoint( fourPos, fourMom );
386  }
387  }
static sim::Particle * fParticle
float fThisEnStart
The energy which this particle has the first time in entered the active volume.
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
Definition: MCParticle.h:256
float fThisEDep
The energy which this particle deposited in the active volume.
int Mother() const
Definition: MCParticle.h:212
Definition: event.h:19
static constexpr double ns
static std::map< int, std::vector< float > > fTrueDepMap
list_type::iterator iterator
int TrackId() const
Definition: MCParticle.h:209
static constexpr double cm
Definition: SystemOfUnits.h:99
double energy
Definition: plottest35.C:25
bool isInsideDetectorBigBox(const double x_cm, const double y_cm, const double z_cm) const
Is the particle inside the detector Big Box?
sim::ParticleNavigator * fParticleNav
bool fStoreTrajOutsideBigBox
Otherwise trajectory details outside the big box are thrown away to save space.
bool fEnteredDet
Boolean to state whether the particle has entered the active volume before.
static constexpr double GeV
iterator find(const key_type &key)
float fThisEnEscape
The energy which this particle had the last time it left the active volume.
art::ServiceHandle< geo::Geometry > geom
void g4n::ParticleListAction::PreTrackingAction ( const G4Track *  track)

Definition at line 146 of file ParticleListAction.cxx.

References sim::ParticleNavigator::Add(), sim::ParticleNavigator::end(), energy, fCurrentTrackID, fEnergyCut, fEnteredDet, sim::ParticleNavigator::find(), fisFirstBremRecorded, fisFirstPairRecorded, fLeftDet, fManyParticles, fParentIDMap, fParticle, fParticleNav, fThisEDep, fThisEnEscape, fThisEnStart, fTrackIDOffset, fTrackIDToMCTruthIndex, GetParentage(), CLHEP::GeV, sim::kNoParticleId, LOG_DEBUG, LOG_WARNING, parentID, make_root_from_grid_output::pdg, BlessedPlots::pid, simb::MCParticle::SetPolarization(), string, and trackID.

147  {
148  // Karl::Reset the containment variables
150  fEnteredDet = fLeftDet = false;
151 
152  // get the track ID for this particle
153  const G4int trackID = track->GetTrackID() + fTrackIDOffset;
155  size_t mcTruthIndex = 0;
156 
157  // get the parent id from Geant for the current track:
158  G4int parentID = track->GetParentID() + fTrackIDOffset;
159 
160  // Is there an MCTruth object associated with this G4Track? We
161  // have to go up a "chain" of information to find out:
162  const G4ParticleDefinition* partdef = track->GetDefinition();
163  const G4int pdg = partdef->GetPDGEncoding();
164  const G4DynamicParticle* dp = track->GetDynamicParticle();
165  const G4PrimaryParticle* pp = dp->GetPrimaryParticle();
166 
167  LOG_DEBUG("ParticleListAction") << "preparing to track " << fCurrentTrackID
168  << " pdg " << pdg
169  << " with parent " << parentID;
170 
171  std::string process_name;
172  if ( pp != 0 ){
173  const G4VUserPrimaryParticleInformation* gppi = pp->GetUserInformation();
174  const g4b::PrimaryParticleInformation* ppi = dynamic_cast<const g4b::PrimaryParticleInformation*>(gppi);
175 
176  if ( ppi != 0 ){
177  // If we've made it this far, a PrimaryParticleInformation
178  // object exists and we are using a primary particle, set the
179  // process name accordingly.
180  process_name = "Primary";
181 
182  // primary particles should still have parentID = 0, even
183  // if there are multiple MCTruths for this event
184  parentID = 0;
185 
186  mcTruthIndex = ppi->MCTruthIndex();
187  }
188 
189  } // Is there a G4PrimaryParticle?
190  else{
191 
192  // figure out what process is making this track - skip it if it is
193  // one of pair production, compton scattering, photoelectric effect
194  // bremstrahlung, annihilation, any ionization - who wants to save
195  // a buttload of electrons that arent from a CC interaction?
196  process_name = track->GetCreatorProcess()->GetProcessName();
197  if( !fManyParticles && (process_name.find("conv") != std::string::npos
198  || process_name.find("LowEnConversion") != std::string::npos
199  ||(process_name.find("Pair") != std::string::npos && fisFirstPairRecorded)
200  || process_name.find("compt") != std::string::npos
201  || process_name.find("Compt") != std::string::npos
202  ||(process_name.find("Brem") != std::string::npos && fisFirstBremRecorded)
203  || process_name.find("phot") != std::string::npos
204  || process_name.find("Photo") != std::string::npos
205  || process_name.find("Ion") != std::string::npos
206  || process_name.find("annihil") != std::string::npos)){
207 
208  // find the ultimate parent of this particle that was not a secondary
209  // of the EM shower
210  // first add this track id and its parent to the fParentIDMap
212 
214 
215  LOG_DEBUG("ParticleListAction") << "current track ID " << fCurrentTrackID;
216 
217  // check that fCurrentTrackID is in the particle list - it is possible
218  // that this particle's parent is a particle that did not get tracked.
219  // An example is a parent that was made due to muMinusCaptureAtRest
220  // and the daughter was made by the phot process. The parent likely
221  // isn't saved in the particle list because it is below the energy cut
222  // which will put a bogus track id value into the sim::IDE object for
223  // the sim::SimChannel if we don't check it.
225 
227 
228  // set fParticle to 0 as we are not stepping this particle
229  // and adding trajectory points to it
230  fParticle = 0;
231 
232  LOG_DEBUG("ParticleListAction") << "killing TrackID: " << trackID << " bc EM daughter, "
233  << process_name << " " << pdg
234  << ", use track id " << fCurrentTrackID;
235 
236  return;
237  }// end if part of EM shower, but not primary particle
238 
239  // Check the energy of the particle. If it falls below the energy
240  // cut, don't add it to our list.
241  const G4double energy = track->GetKineticEnergy();
242  if ( energy < fEnergyCut ){
243  fParticle = 0;
244  LOG_DEBUG("ParticleListAction") << "killing TrackID: " << fCurrentTrackID << " energy/fEnergyCut";
245 
246  // do add the particle to the parent id map though
247  // and set the current track id to be it's ultimate parent
249 
251  return;
252  }
253 
254  // check to see if the parent particle has been stored in the particle navigator
255  // if not, then see if it is possible to walk up the fParentIDMap to find the
256  // ultimate parent of this particle. Use that ID as the parent ID for this
257  // particle
258  if( fParticleNav->find(parentID) == fParticleNav->end() ){
259  // do add the particle to the parent id map
260  // just in case it makes a daughter that we have to track as well
262  const int pid = this->GetParentage(parentID);
263 
264  // if we still can't find the parent in the particle navigator,
265  // we have to give up
266  if( fParticleNav->find(pid) == fParticleNav->end() ){
267  mf::LogWarning("ParticleListAction") << "can't find parent id: "
268  << parentID
269  << " in the particle navigator, or fParentIDMap."
270  << " Make " << parentID << " the mother ID for"
271  << " track ID " << fCurrentTrackID
272  << " in the hope that it will aid debugging.";
273  }
274  else
275  parentID = pid;
276  }
277 
278  // Attempt to find the MCTruth index corresponding to the
279  // current particle. If the fCurrentTrackID is not in the
280  // map try the parent ID, if that is not there, throw an
281  // exception
283  mcTruthIndex = fTrackIDToMCTruthIndex.at(fCurrentTrackID);
284  else if(fTrackIDToMCTruthIndex.count(parentID) > 0 )
285  mcTruthIndex = fTrackIDToMCTruthIndex.at(parentID);
286  else
287  throw cet::exception("ParticleListAction") << "Cannot find MCTruth index for track id "
288  << fCurrentTrackID << " or " << parentID;
289  }// end of if/else
290 
291 
292  // protect against potentially empty process names.
293  if ( process_name.empty() ) { process_name = "unknown";}
294  // if it's the brem photon, update the variable
295  else if( process_name.find("Brem") != std::string::npos){ fisFirstBremRecorded = true;}
296  else if( process_name.find("Pair") != std::string::npos){ fisFirstPairRecorded = true;}
297 
298 
299  // Create the sim::Particle object
300  fParticle = new sim::Particle(fCurrentTrackID, pdg, process_name,
301  parentID, dp->GetMass()/CLHEP::GeV);
302  //part.Print();
303 
304  // Polarization.
305  const G4ThreeVector& polarization = track->GetPolarization();
306  fParticle->SetPolarization( TVector3(polarization.x(),
307  polarization.y(),
308  polarization.z() ) );
309 
311 
313  LOG_WARNING("ParticleListAction") << "attempting to put " << fCurrentTrackID
314  << " into fTrackIDToMCTruthIndex map "
315  << " particle is\n" << *fParticle;
316 
317  fTrackIDToMCTruthIndex[fCurrentTrackID] = mcTruthIndex;
318 
319  return;
320  }
#define LOG_DEBUG(stream)
Definition: Messenger.h:149
static sim::Particle * fParticle
float fThisEnStart
The energy which this particle has the first time in entered the active volume.
float fThisEDep
The energy which this particle deposited in the active volume.
Definition: event.h:19
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
int GetParentage(int trackid) const
bool fLeftDet
Boolean to state whether the particle has left the active volume before (after entering it)...
static const int kNoParticleId
Definition: Simulation.h:14
std::map< int, size_t > fTrackIDToMCTruthIndex
map track ID to index of MCTruth in input list
void SetPolarization(const TVector3 &p)
Definition: MCParticle.h:265
double energy
Definition: plottest35.C:25
G4double fEnergyCut
The minimum energy for a particle to be included in the list.
#define LOG_WARNING(category)
Int_t parentID
Definition: plot.C:85
sim::ParticleNavigator * fParticleNav
bool fManyParticles
When true, includes track ids from processes like compt and brem.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
static int fTrackIDOffset
offset added to track ids when running over
ParticleNavigator Add(const int &offset) const
Int_t trackID
Definition: plot.C:84
std::map< int, int > fParentIDMap
key is current track ID, value is parent ID
bool fEnteredDet
Boolean to state whether the particle has entered the active volume before.
static constexpr double GeV
iterator find(const key_type &key)
float fThisEnEscape
The energy which this particle had the last time it left the active volume.
enum BeamMode string
void g4n::ParticleListAction::PrintConfig ( std::string const &  opt)

Definition at line 85 of file ParticleListAction.cxx.

References fEnergyCut, fManyParticles, fRecordFirstBrem, fRecordFirstPair, and fStoreTrajOutsideBigBox.

86  {
87  mf::LogInfo("ParticleListAction")
88  << "ParticleListAction::PrintConfig"
89  << "\n EnergyCut " << fEnergyCut
90  << "\n ManyParticles " << (fManyParticles?"true":"false")
91  << "\n RecordFirstBrem " << (fRecordFirstBrem?"true":"false")
92  << "\n RecordFirstPair " << (fRecordFirstPair?"true":"false")
93  << "\n StoreTrajOutsideBigBox " << (fStoreTrajOutsideBigBox?"true":"false");
94  }
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
bool fRecordFirstPair
When true, saves the electron generated by the first Pair production.
G4double fEnergyCut
The minimum energy for a particle to be included in the list.
bool fRecordFirstBrem
When true, saves the gamma generated by the first Brem.
bool fManyParticles
When true, includes track ids from processes like compt and brem.
bool fStoreTrajOutsideBigBox
Otherwise trajectory details outside the big box are thrown away to save space.
void g4n::ParticleListAction::ResetAbortFlag ( )
inline

Definition at line 47 of file ParticleListAction.h.

47 { fIsAborted = false; };
bool fIsAborted
Whether Geant4 was aborted while tracking a particle.
void g4n::ParticleListAction::ResetTrackIDOffset ( int  offset = 0)
inline

Definition at line 60 of file ParticleListAction.h.

References PandAna.reco_validation.add_data::offset.

Referenced by g4n::G4Alg::RunGeant().

static int fTrackIDOffset
offset added to track ids when running over
void g4n::ParticleListAction::SteppingAction ( const G4Step *  step)

Definition at line 392 of file ParticleListAction.cxx.

References simb::MCParticle::AddTrajectoryPoint(), CLHEP::cm, energy, fEnteredDet, fLeftDet, fParticle, fStoreTrajOutsideBigBox, fThisEDep, fThisEnEscape, fThisEnStart, geom, CLHEP::GeV, geo::GeometryBase::isInsideDetectorBigBox(), make_training::momentum, CLHEP::ns, and simb::MCParticle::NumberTrajectoryPoints().

392  {
393 
394  // Karl::Containment outputs
395  // --- Work out if PreStep point was in the detector volume.
396  bool PreStepInDet = geom->isInsideDetectorBigBox( step->GetPreStepPoint()->GetPosition().x()/CLHEP::cm,
397  step->GetPreStepPoint()->GetPosition().y()/CLHEP::cm,
398  step->GetPreStepPoint()->GetPosition().z()/CLHEP::cm
399  );
400  // --- Work out if the PostStep point was in the detector volume.
401  bool PosStepInDet = geom->isInsideDetectorBigBox( step->GetPostStepPoint()->GetPosition().x()/CLHEP::cm,
402  step->GetPostStepPoint()->GetPosition().y()/CLHEP::cm,
403  step->GetPostStepPoint()->GetPosition().z()/CLHEP::cm
404  );
405  // --- If this step took/kept the particle in the detector.
406  if ( PosStepInDet ) {
407  fThisEDep += step->GetTotalEnergyDeposit()/CLHEP::GeV;
408  // --- If the particle has entered the detector for the first time with this step.
409  if ( !fEnteredDet ) {
410  fEnteredDet = true;
411  // --- Take PreStepPoint, as this is the energy it had AS it entered.
412  fThisEnStart = step->GetPreStepPoint()->GetKineticEnergy()/CLHEP::GeV; // Do I want GetTotalEnergy() or GetKineticEnergy()??
413  }
414  // --- If the particle has left the detector before, and now come back into the detector I want to subtract this EDep
415  // --- from the amount of energy which I thought was not deposited in the detector.
416  if ( fLeftDet ) {
417  fThisEnEscape -= step->GetTotalEnergyDeposit()/CLHEP::GeV;
418  }
419  } else {
420  // --- If this is the first time the particle has left the detector with this step.
421  if ( PreStepInDet && !fLeftDet ) {
422  fLeftDet = true;
423  // --- Take PreStepPoint, as this is the energy it had AS it left.
424  fThisEnEscape = step->GetPreStepPoint()->GetKineticEnergy()/CLHEP::GeV; // Do I want GetTotalEnergy() or GetKineticEnergy??
425  }
426  }
427  // Karl::Containment outputs
428 
429  if ( !fParticle ) return;
430 
431  // For the most part, we just want to add the post-step
432  // information to the particle's trajectory. There's one
433  // exception: In PreTrackingAction, the correct time information
434  // is not available. So add the correct vertex information here.
435 
436  if ( fParticle->NumberTrajectoryPoints() == 0 ){
437  // Get the pre-step information from the G4Step.
438  const G4StepPoint* preStepPoint = step->GetPreStepPoint();
439 
440  const G4ThreeVector position = preStepPoint->GetPosition();
441  G4double time = preStepPoint->GetGlobalTime();
442 
443  // Remember that LArSoft uses cm, ns, GeV.
444  TLorentzVector fourPos(position.x() / CLHEP::cm,
445  position.y() / CLHEP::cm,
446  position.z() / CLHEP::cm,
447  time / CLHEP::ns);
448 
449  const G4ThreeVector momentum = preStepPoint->GetMomentum();
450  const G4double energy = preStepPoint->GetTotalEnergy();
451  TLorentzVector fourMom(momentum.x() / CLHEP::GeV,
452  momentum.y() / CLHEP::GeV,
453  momentum.z() / CLHEP::GeV,
454  energy / CLHEP::GeV);
455 
456  // Add the first point in the trajectory.
457  fParticle->AddTrajectoryPoint( fourPos, fourMom );
458  }
459 
460  // Get the post-step information from the G4Step.
461  const G4StepPoint* postStepPoint = step->GetPostStepPoint();
462 
463  const G4ThreeVector position = postStepPoint->GetPosition();
464  G4double time = postStepPoint->GetGlobalTime();
465 
466  // Remember that LArSoft uses cm, ns, GeV.
467  TLorentzVector fourPos(position.x() / CLHEP::cm,
468  position.y() / CLHEP::cm,
469  position.z() / CLHEP::cm,
470  time / CLHEP::ns );
471 
472  const G4ThreeVector momentum = postStepPoint->GetMomentum();
473  const G4double energy = postStepPoint->GetTotalEnergy();
474  TLorentzVector fourMom(momentum.x() / CLHEP::GeV,
475  momentum.y() / CLHEP::GeV,
476  momentum.z() / CLHEP::GeV,
477  energy / CLHEP::GeV );
478 
479  // Add another point in the trajectory.
481  geom->isInsideDetectorBigBox(position.x() / CLHEP::cm,
482  position.y() / CLHEP::cm,
483  position.z() / CLHEP::cm)){
484  fParticle->AddTrajectoryPoint( fourPos, fourMom );
485  }
486  }
static sim::Particle * fParticle
unsigned int NumberTrajectoryPoints() const
Definition: MCParticle.h:217
float fThisEnStart
The energy which this particle has the first time in entered the active volume.
void AddTrajectoryPoint(TLorentzVector const &position, TLorentzVector const &momentum)
Definition: MCParticle.h:256
float fThisEDep
The energy which this particle deposited in the active volume.
static constexpr double ns
bool fLeftDet
Boolean to state whether the particle has left the active volume before (after entering it)...
static constexpr double cm
Definition: SystemOfUnits.h:99
double energy
Definition: plottest35.C:25
bool isInsideDetectorBigBox(const double x_cm, const double y_cm, const double z_cm) const
Is the particle inside the detector Big Box?
bool fStoreTrajOutsideBigBox
Otherwise trajectory details outside the big box are thrown away to save space.
bool fEnteredDet
Boolean to state whether the particle has entered the active volume before.
static constexpr double GeV
float fThisEnEscape
The energy which this particle had the last time it left the active volume.
art::ServiceHandle< geo::Geometry > geom
std::map< int, size_t > g4n::ParticleListAction::TrackIDToMCTruthIndexMap ( ) const

Definition at line 510 of file ParticleListAction.cxx.

References fTrackIDToMCTruthIndex.

Referenced by g4n::G4Alg::RunGeant().

511  {
512  return fTrackIDToMCTruthIndex;
513  }
std::map< int, size_t > fTrackIDToMCTruthIndex
map track ID to index of MCTruth in input list

Member Data Documentation

int g4n::ParticleListAction::fCurrentTrackID = sim::kNoParticleId
staticprivate

track ID of the current particle, set to eve ID

Definition at line 92 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), PostTrackingAction(), and PreTrackingAction().

G4double g4n::ParticleListAction::fEnergyCut
private

The minimum energy for a particle to be included in the list.

Definition at line 80 of file ParticleListAction.h.

Referenced by Config(), PreTrackingAction(), and PrintConfig().

bool g4n::ParticleListAction::fEnteredDet
private

Boolean to state whether the particle has entered the active volume before.

Definition at line 105 of file ParticleListAction.h.

Referenced by PostTrackingAction(), PreTrackingAction(), and SteppingAction().

bool g4n::ParticleListAction::fIsAborted
private

Whether Geant4 was aborted while tracking a particle.

Definition at line 78 of file ParticleListAction.h.

Referenced by EndOfEventAction().

bool g4n::ParticleListAction::fisFirstBremRecorded
private

Is the first bremstralung photon recorded? We want to record at least the first bremstralung photon in the event.

Definition at line 95 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), and PreTrackingAction().

bool g4n::ParticleListAction::fisFirstPairRecorded
private

Is the first pair production electron recorded? Useful for gammas

Definition at line 98 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), and PreTrackingAction().

bool g4n::ParticleListAction::fLeftDet
private

Boolean to state whether the particle has left the active volume before (after entering it).

Definition at line 106 of file ParticleListAction.h.

Referenced by PreTrackingAction(), and SteppingAction().

bool g4n::ParticleListAction::fManyParticles
private

When true, includes track ids from processes like compt and brem.

Definition at line 81 of file ParticleListAction.h.

Referenced by Config(), PreTrackingAction(), and PrintConfig().

std::map<int, int> g4n::ParticleListAction::fParentIDMap
private

key is current track ID, value is parent ID

Definition at line 90 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), GetParentage(), and PreTrackingAction().

sim::Particle * g4n::ParticleListAction::fParticle = 0
staticprivate

The particle and trajectory information for a single particle.

Definition at line 86 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), PostTrackingAction(), PreTrackingAction(), and SteppingAction().

sim::ParticleNavigator* g4n::ParticleListAction::fParticleNav
private

The accumulated particle trajectory information for all particles in the event.

Definition at line 88 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), EndOfEventAction(), GetList(), ParticleListAction(), PostTrackingAction(), PreTrackingAction(), and ~ParticleListAction().

bool g4n::ParticleListAction::fRecordFirstBrem
private

When true, saves the gamma generated by the first Brem.

Definition at line 82 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), Config(), and PrintConfig().

bool g4n::ParticleListAction::fRecordFirstPair
private

When true, saves the electron generated by the first Pair production.

Definition at line 83 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), Config(), and PrintConfig().

bool g4n::ParticleListAction::fStoreTrajOutsideBigBox
private

Otherwise trajectory details outside the big box are thrown away to save space.

Definition at line 84 of file ParticleListAction.h.

Referenced by Config(), PostTrackingAction(), PrintConfig(), and SteppingAction().

float g4n::ParticleListAction::fThisEDep
private

The energy which this particle deposited in the active volume.

Definition at line 102 of file ParticleListAction.h.

Referenced by PostTrackingAction(), PreTrackingAction(), and SteppingAction().

float g4n::ParticleListAction::fThisEnEscape
private

The energy which this particle had the last time it left the active volume.

Definition at line 104 of file ParticleListAction.h.

Referenced by PostTrackingAction(), PreTrackingAction(), and SteppingAction().

float g4n::ParticleListAction::fThisEnStart
private

The energy which this particle has the first time in entered the active volume.

Definition at line 103 of file ParticleListAction.h.

Referenced by PostTrackingAction(), PreTrackingAction(), and SteppingAction().

int g4n::ParticleListAction::fTrackIDOffset = 0
staticprivate

offset added to track ids when running over

Definition at line 94 of file ParticleListAction.h.

Referenced by GetList(), and PreTrackingAction().

std::map<int, size_t> g4n::ParticleListAction::fTrackIDToMCTruthIndex
private

map track ID to index of MCTruth in input list

Definition at line 91 of file ParticleListAction.h.

Referenced by BeginOfEventAction(), PreTrackingAction(), and TrackIDToMCTruthIndexMap().

std::map< int, std::vector< float > > g4n::ParticleListAction::fTrueDepMap
static

The True energy deposition map, with TrackID as key. The Vector has elements { EnterEnergy, LeaveEnergy, TotalDepositedEnergy, TotalEscapingEnergy } The energies calculated are Kinetic energy. The first two variables are for the specific GEANT4 particle, ie the KE it had when it entered the detector. The second two variables are summed over all GEANT4 daughters, including ones which are saved.

Definition at line 67 of file ParticleListAction.h.

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

art::ServiceHandle<geo::Geometry> g4n::ParticleListAction::geom
private

Definition at line 76 of file ParticleListAction.h.

Referenced by PostTrackingAction(), and SteppingAction().


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