CMS 3D CMS Logo

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