CMS 3D CMS Logo

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  trkInfo->setIDfineCalo(motherInfo.getIDfineCalo());
73  } else {
74  // transfer calo ID from mother (to be checked in TrackingAction)
75  trkInfo->setIDonCaloSurface(motherInfo.getIDonCaloSurface(),
76  motherInfo.getIDCaloVolume(),
77  motherInfo.getIDLastVolume(),
78  motherInfo.caloSurfaceParticlePID(),
79  motherInfo.caloSurfaceParticleP());
80  trkInfo->setIDfineCalo(motherInfo.getIDfineCalo());
81  }
82 
83  if (motherInfo.hasCastorHit()) {
84  trkInfo->setCastorHitPID(motherInfo.getCastorHitPID());
85  }
86 
87  aTrack->SetUserInformation(trkInfo);
88 }
TrackInformation::caloSurfaceParticleP
double caloSurfaceParticleP() const
Definition: TrackInformation.h:53
NewTrackAction::NewTrackAction
NewTrackAction()
Definition: NewTrackAction.cc:12
NewTrackAction::addUserInfoToPrimary
void addUserInfoToPrimary(G4Track *aTrack) const
Definition: NewTrackAction.cc:34
TrackInformation::getIDonCaloSurface
int getIDonCaloSurface() const
Definition: TrackInformation.h:39
MessageLogger.h
NewTrackAction::addUserInfoToSecondary
void addUserInfoToSecondary(G4Track *aTrack, const TrackInformation &motherInfo, int) const
Definition: NewTrackAction.cc:44
TrackInformation::getIDLastVolume
int getIDLastVolume() const
Definition: TrackInformation.h:48
SimG4Exception
Definition: SimG4Exception.h:13
TrackInformation::setIDonCaloSurface
void setIDonCaloSurface(int id, int ical, int last, int pdgID, double p)
Definition: TrackInformation.h:40
TrackInformation::putInHistory
void putInHistory()
Definition: TrackInformation.h:33
TrackInformation::genParticlePID
int genParticlePID() const
Definition: TrackInformation.h:59
NewTrackAction.h
TrackInformation::setIDfineCalo
void setIDfineCalo(int id)
Definition: TrackInformation.h:56
TrackInformation::setGenParticleP
void setGenParticleP(double p)
Definition: TrackInformation.h:62
TrackInformationExtractor
Definition: TrackInformationExtractor.h:20
TrackInformation::isPrimary
bool isPrimary() const
Definition: TrackInformation.h:23
NewTrackAction::secondary
void secondary(const G4Track *aSecondary, const G4Track &mother, int) const
Definition: NewTrackAction.cc:18
TrackInformation::getIDCaloVolume
int getIDCaloVolume() const
Definition: TrackInformation.h:47
SimG4Exception.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
TrackInformation::getCastorHitPID
int getCastorHitPID() const
Definition: TrackInformation.h:71
TrackInformation::getIDfineCalo
int getIDfineCalo() const
Definition: TrackInformation.h:55
TrackInformation::setGenParticlePID
void setGenParticlePID(int id)
Definition: TrackInformation.h:60
TrackInformation
Definition: TrackInformation.h:8
TrackInformation::storeTrack
bool storeTrack() const
Definition: TrackInformation.h:14
TrackInformation.h
TrackInformation::genParticleP
double genParticleP() const
Definition: TrackInformation.h:61
TrackInformation::hasCastorHit
bool hasCastorHit() const
Definition: TrackInformation.h:66
TrackInformation::caloSurfaceParticlePID
int caloSurfaceParticlePID() const
Definition: TrackInformation.h:51
TrackInformationExtractor.h
TrackInformation::setCastorHitPID
void setCastorHitPID(const int pid)
Definition: TrackInformation.h:67
NewTrackAction::primary
void primary(const G4Track *aSecondary) const
Definition: NewTrackAction.cc:14
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116