CMS 3D CMS Logo

NewTrackAction.cc
Go to the documentation of this file.
4 
6 
7 #include "G4Track.hh"
8 
10 
11 void NewTrackAction::primary(const G4Track *aTrack) const { primary(const_cast<G4Track *>(aTrack)); }
12 
13 void NewTrackAction::primary(G4Track *aTrack) const { addUserInfoToPrimary(aTrack); }
14 
15 void NewTrackAction::secondary(const G4Track *aSecondary, const G4Track &mother, int flag) const {
16  secondary(const_cast<G4Track *>(aSecondary), mother, flag);
17 }
18 
19 void NewTrackAction::secondary(G4Track *aSecondary, const G4Track &mother, int flag) const {
20  if (aSecondary->GetParentID() != mother.GetTrackID()) {
21  G4Exception("SimG4Core/Notification",
22  "mc001",
23  FatalException,
24  "NewTrackAction: secondary parent ID does not match mother id");
25  } else {
26  TrackInformationExtractor extractor;
27  const TrackInformation &motherInfo(extractor(mother));
28  addUserInfoToSecondary(aSecondary, motherInfo, flag);
29  LogDebug("SimTrackManager") << "NewTrackAction: Add track " << aSecondary->GetTrackID() << " from mother "
30  << mother.GetTrackID();
31  }
32 }
33 
34 void NewTrackAction::addUserInfoToPrimary(G4Track *aTrack) const {
35  TrackInformation *trkInfo = new TrackInformation();
36  trkInfo->isPrimary(true);
37  trkInfo->storeTrack(true);
38  trkInfo->putInHistory();
39  trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
40  trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
41  aTrack->SetUserInformation(trkInfo);
42 }
43 
44 void NewTrackAction::addUserInfoToSecondary(G4Track *aTrack, const TrackInformation &motherInfo, int flag) const {
45  TrackInformation *trkInfo = new TrackInformation();
46  LogDebug("SimG4CoreApplication") << "NewTrackAction called for " << aTrack->GetTrackID() << " mother "
47  << motherInfo.isPrimary() << " flag " << flag;
48 
49  // Take care of cascade decays
50  if (flag == 1) {
51  trkInfo->isPrimary(true);
52  trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
53  trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
54  } else {
55  trkInfo->setGenParticlePID(motherInfo.genParticlePID());
56  trkInfo->setGenParticleP(motherInfo.genParticleP());
57  }
58 
59  // Store if decay or conversion
60  if (flag > 0) {
61  trkInfo->storeTrack(true);
62  trkInfo->putInHistory();
63  trkInfo->setIDonCaloSurface(aTrack->GetTrackID(),
64  motherInfo.getIDCaloVolume(),
65  motherInfo.getIDLastVolume(),
66  aTrack->GetDefinition()->GetPDGEncoding(),
67  aTrack->GetMomentum().mag());
68  } else {
69  // transfer calo ID from mother (to be checked in TrackingAction)
70  trkInfo->setIDonCaloSurface(motherInfo.getIDonCaloSurface(),
71  motherInfo.getIDCaloVolume(),
72  motherInfo.getIDLastVolume(),
73  motherInfo.caloSurfaceParticlePID(),
74  motherInfo.caloSurfaceParticleP());
75  }
76 
77  if (motherInfo.hasCastorHit()) {
78  trkInfo->setCastorHitPID(motherInfo.getCastorHitPID());
79  }
80 
81  aTrack->SetUserInformation(trkInfo);
82 }
bool storeTrack() const
double genParticleP() const
bool isPrimary() const
int getIDCaloVolume() const
int getCastorHitPID() const
void addUserInfoToSecondary(G4Track *aTrack, const TrackInformation &motherInfo, int) const
bool hasCastorHit() const
void addUserInfoToPrimary(G4Track *aTrack) const
void setGenParticlePID(int id)
void setCastorHitPID(const int pid)
double caloSurfaceParticleP() const
int caloSurfaceParticlePID() const
void secondary(const G4Track *aSecondary, const G4Track &mother, int) const
int getIDonCaloSurface() const
int getIDLastVolume() const
int genParticlePID() const
void setGenParticleP(double p)
void primary(const G4Track *aSecondary) const
void setIDonCaloSurface(int id, int ical, int last, int pdgID, double p)
#define LogDebug(id)