CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
NewTrackAction.cc
Go to the documentation of this file.
5 
7 
8 #include "G4Track.hh"
9 
10 //#define DebugLog
11 
13 
14 void NewTrackAction::primary(const G4Track *aTrack) const { primary(const_cast<G4Track *>(aTrack)); }
15 
16 void NewTrackAction::primary(G4Track *aTrack) const { addUserInfoToPrimary(aTrack); }
17 
18 void NewTrackAction::secondary(const G4Track *aSecondary, const G4Track &mother, int flag) const {
19  secondary(const_cast<G4Track *>(aSecondary), mother, flag);
20 }
21 
22 void NewTrackAction::secondary(G4Track *aSecondary, const G4Track &mother, int flag) const {
23  if (aSecondary->GetParentID() != mother.GetTrackID())
24  throw SimG4Exception("NewTrackAction: secondary parent ID does not match mother id");
25  TrackInformationExtractor extractor;
26  const TrackInformation &motherInfo(extractor(mother));
27  addUserInfoToSecondary(aSecondary, motherInfo, flag);
28 #ifdef DebugLog
29  LogDebug("SimTrackManager") << "NewTrackAction: Add track " << aSecondary->GetTrackID() << " from mother "
30  << mother.GetTrackID();
31 #endif
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  // ralf.ulrich@kit.edu: it is more efficient to use the constructor to copy all data and modify later only when needed
46 
47  TrackInformation *trkInfo = new TrackInformation();
48  // LogDebug("SimG4CoreApplication") << "NewTrackAction called for "
49  // << aTrack->GetTrackID()
50  // << " mother " << motherInfo.isPrimary()
51  // << " flag " << flag;
52 
53  // Take care of cascade decays
54  if (flag == 1) {
55  trkInfo->isPrimary(true);
56  trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
57  trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
58  } else {
59  trkInfo->setGenParticlePID(motherInfo.genParticlePID());
60  trkInfo->setGenParticleP(motherInfo.genParticleP());
61  }
62 
63  // Store if decay or conversion
64  if (flag > 0) {
65  trkInfo->storeTrack(true);
66  trkInfo->putInHistory();
67  trkInfo->setIDonCaloSurface(aTrack->GetTrackID(),
68  motherInfo.getIDCaloVolume(),
69  motherInfo.getIDLastVolume(),
70  aTrack->GetDefinition()->GetPDGEncoding(),
71  aTrack->GetMomentum().mag());
72  } else {
73  // transfer calo ID from mother (to be checked in TrackingAction)
74  trkInfo->setIDonCaloSurface(motherInfo.getIDonCaloSurface(),
75  motherInfo.getIDCaloVolume(),
76  motherInfo.getIDLastVolume(),
77  motherInfo.caloSurfaceParticlePID(),
78  motherInfo.caloSurfaceParticleP());
79  }
80 
81  if (motherInfo.hasCastorHit()) {
82  trkInfo->setCastorHitPID(motherInfo.getCastorHitPID());
83  }
84 
85  aTrack->SetUserInformation(trkInfo);
86 }
void primary(const G4Track *aSecondary) const
int getCastorHitPID() const
void addUserInfoToPrimary(G4Track *aTrack) const
bool storeTrack() const
int getIDonCaloSurface() const
double genParticleP() const
void setGenParticlePID(int id)
void setCastorHitPID(const int pid)
int getIDCaloVolume() const
int genParticlePID() const
void secondary(const G4Track *aSecondary, const G4Track &mother, int) const
int caloSurfaceParticlePID() const
int getIDLastVolume() const
bool hasCastorHit() const
void addUserInfoToSecondary(G4Track *aTrack, const TrackInformation &motherInfo, int) const
void setGenParticleP(double p)
bool isPrimary() const
void setIDonCaloSurface(int id, int ical, int last, int pdgID, double p)
double caloSurfaceParticleP() const
#define LogDebug(id)