CMS 3D CMS Logo

TrackingAction.cc
Go to the documentation of this file.
10 
12 
13 #include "G4UImanager.hh"
14 #include "G4TrackingManager.hh"
15 
16 //#define DebugLog
17 
20  : eventAction_(e),currentTrack_(nullptr),steppingVerbose_(sv),g4Track_(nullptr),
21  checkTrack_(p.getUntrackedParameter<bool>("CheckTrack",false))
22 {}
23 
25 
26 void TrackingAction::PreUserTrackingAction(const G4Track * aTrack)
27 {
28  g4Track_ = aTrack;
29  currentTrack_ = new TrackWithHistory(aTrack);
30 
31  BeginOfTrack bt(aTrack);
33 
34  TrackInformation * trkInfo = (TrackInformation *)aTrack->GetUserInformation();
35  if(trkInfo && trkInfo->isPrimary()) {
37  }
38  if(nullptr != steppingVerbose_) {
39  steppingVerbose_->TrackStarted(aTrack, false);
40  }
41 }
42 
43 void TrackingAction::PostUserTrackingAction(const G4Track * aTrack)
44 {
45  if (eventAction_->trackContainer() != nullptr) {
46 
47  if (extractor_(aTrack).storeTrack()) {
49 
50  math::XYZVectorD pos((aTrack->GetStep()->GetPostStepPoint()->GetPosition()).x(),
51  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).y(),
52  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).z());
54 
55  uint32_t id = aTrack->GetTrackID();
56 
57  std::pair<math::XYZVectorD,math::XYZTLorentzVectorD> p(pos,mom);
59 #ifdef DebugLog
60  LogDebug("SimTrackManager") << "TrackingAction addTkCaloStateInfo "
61  << id << " of momentum " << mom << " at " << pos;
62 #endif
63  }
64 
65  bool withAncestor =
66  ((extractor_(aTrack).getIDonCaloSurface() == aTrack->GetTrackID())
67  || (extractor_(aTrack).isAncestor()));
68 
69  if (extractor_(aTrack).isInHistory()) {
70 
71  // check with end-of-track information
72  if(checkTrack_) { currentTrack_->checkAtEnd(aTrack); }
73 
74  eventAction_->addTrack(currentTrack_, true, withAncestor);
75  /*
76  cout << "TrackingAction addTrack "
77  << currentTrack_->trackID() << " E(GeV)= " << aTrack->GetKineticEnergy()
78  << " " << aTrack->GetDefinition()->GetParticleName()
79  << " added= " << withAncestor
80  << " at " << aTrack->GetPosition() << endl;
81  */
82 #ifdef DebugLog
83  math::XYZVectorD pos((aTrack->GetStep()->GetPostStepPoint()->GetPosition()).x(),
84  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).y(),
85  (aTrack->GetStep()->GetPostStepPoint()->GetPosition()).z());
86  LogDebug("SimTrackManager") << "TrackingAction addTrack "
87  << currentTrack_->trackID()
88  << " added with " << true << " and " << withAncestor
89  << " at " << pos;
90 #endif
91 
92  } else {
93  eventAction_->addTrack(currentTrack_, false, false);
94 
95 #ifdef DebugLog
96  LogDebug("SimTrackManager") << "TrackingAction addTrack "
97  << currentTrack_->trackID() << " added with "
98  << false << " and " << false;
99 #endif
100 
101  delete currentTrack_;
102  }
103  }
104  if(nullptr != steppingVerbose_) { steppingVerbose_->TrackEnded(aTrack); }
105 
106  EndOfTrack et(aTrack);
107  m_endOfTrackSignal(&et);
108 
109  currentTrack_ = nullptr; // reset for next track
110 }
#define LogDebug(id)
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
const G4Track * g4Track_
TrackInformationExtractor extractor_
CMSSteppingVerbose * steppingVerbose_
TrackWithHistory * currentTrack_
#define nullptr
void TrackEnded(const G4Track *) const
void prepareForNewPrimary()
Definition: EventAction.h:48
~TrackingAction() override
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
EventAction * eventAction_
unsigned int trackID() const
TrackingAction(EventAction *ea, const edm::ParameterSet &ps, CMSSteppingVerbose *)
void checkAtEnd(const G4Track *)
void PreUserTrackingAction(const G4Track *aTrack) override
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal
const TrackContainer * trackContainer() const
Definition: EventAction.h:37
bool isPrimary() const
et
define resolution functions of each parameter
void addTkCaloStateInfo(uint32_t t, const std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > &p)
Definition: EventAction.cc:74
void PostUserTrackingAction(const G4Track *aTrack) override
void TrackStarted(const G4Track *, bool isKilled)
void addTrack(TrackWithHistory *iTrack, bool inHistory, bool withAncestor)
Definition: EventAction.h:41
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal