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  } 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 }
TrackInformation::caloSurfaceParticleP
double caloSurfaceParticleP() const
Definition: TrackInformation.h:57
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:43
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:52
SimG4Exception
Definition: SimG4Exception.h:13
TrackInformation::setIDonCaloSurface
void setIDonCaloSurface(int id, int ical, int last, int pdgID, double p)
Definition: TrackInformation.h:44
TrackInformation::putInHistory
void putInHistory()
Definition: TrackInformation.h:37
TrackInformation::genParticlePID
int genParticlePID() const
Definition: TrackInformation.h:79
NewTrackAction.h
TrackInformation::setGenParticleP
void setGenParticleP(double p)
Definition: TrackInformation.h:82
TrackInformationExtractor
Definition: TrackInformationExtractor.h:20
TrackInformation::isPrimary
bool isPrimary() const
Definition: TrackInformation.h:27
NewTrackAction::secondary
void secondary(const G4Track *aSecondary, const G4Track &mother, int) const
Definition: NewTrackAction.cc:18
TrackInformation::getIDCaloVolume
int getIDCaloVolume() const
Definition: TrackInformation.h:51
SimG4Exception.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
TrackInformation::getCastorHitPID
int getCastorHitPID() const
Definition: TrackInformation.h:91
TrackInformation::setGenParticlePID
void setGenParticlePID(int id)
Definition: TrackInformation.h:80
TrackInformation
Definition: TrackInformation.h:12
TrackInformation::storeTrack
bool storeTrack() const
Definition: TrackInformation.h:18
TrackInformation.h
TrackInformation::genParticleP
double genParticleP() const
Definition: TrackInformation.h:81
TrackInformation::hasCastorHit
bool hasCastorHit() const
Definition: TrackInformation.h:86
TrackInformation::caloSurfaceParticlePID
int caloSurfaceParticlePID() const
Definition: TrackInformation.h:55
TrackInformationExtractor.h
TrackInformation::setCastorHitPID
void setCastorHitPID(const int pid)
Definition: TrackInformation.h:87
NewTrackAction::primary
void primary(const G4Track *aSecondary) const
Definition: NewTrackAction.cc:14
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116