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  TrackInformation * trkInfo = new TrackInformation();
50 // LogDebug("SimG4CoreApplication") << "NewTrackAction called for "
51 // << aTrack->GetTrackID()
52 // << " mother " << motherInfo.isPrimary()
53 // << " flag " << flag;
54 
55  // Take care of cascade decays
56  if (flag == 1) {
57  trkInfo->isPrimary(true);
58  trkInfo->setGenParticlePID(aTrack->GetDefinition()->GetPDGEncoding());
59  trkInfo->setGenParticleP(aTrack->GetMomentum().mag());
60  } else {
61  trkInfo->setGenParticlePID(motherInfo.genParticlePID());
62  trkInfo->setGenParticleP(motherInfo.genParticleP());
63  }
64 
65  // Store if decay or conversion
66  if (flag > 0) {
67  trkInfo->storeTrack(true);
68  trkInfo->putInHistory();
69  trkInfo->setIDonCaloSurface(aTrack->GetTrackID(),
70  motherInfo.getIDCaloVolume(),
71  motherInfo.getIDLastVolume(),
72  aTrack->GetDefinition()->GetPDGEncoding(),
73  aTrack->GetMomentum().mag());
74  } else {
75  // transfer calo ID from mother (to be checked in TrackingAction)
76  trkInfo->setIDonCaloSurface(motherInfo.getIDonCaloSurface(),
77  motherInfo.getIDCaloVolume(),
78  motherInfo.getIDLastVolume(),
79  motherInfo.caloSurfaceParticlePID(),
80  motherInfo.caloSurfaceParticleP());
81  }
82  aTrack->SetUserInformation(trkInfo);
83 }
#define LogDebug(id)
void primary(const G4Track *aSecondary) const
long int flag
Definition: mlp_lapack.h:47
void addUserInfoToPrimary(G4Track *aTrack) const
bool storeTrack() const
int getIDonCaloSurface() const
double genParticleP() const
void setGenParticlePID(int id)
int getIDCaloVolume() const
int genParticlePID() const
void secondary(const G4Track *aSecondary, const G4Track &mother, int) const
int caloSurfaceParticlePID() const
int getIDLastVolume() 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