CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TrackingAction.cc
Go to the documentation of this file.
10 
12 
13 #include "G4UImanager.hh"
14 #include "G4TrackingManager.hh"
15 #include "G4SystemOfUnits.hh"
16 
17 //#define EDM_ML_DEBUG
18 
20  : eventAction_(e),
21  currentTrack_(nullptr),
22  steppingVerbose_(sv),
23  g4Track_(nullptr),
24  checkTrack_(p.getUntrackedParameter<bool>("CheckTrack", false)),
25  doFineCalo_(p.getParameter<bool>("DoFineCalo")),
26  saveCaloBoundaryInformation_(p.getParameter<bool>("SaveCaloBoundaryInformation")),
27  eMinFine_(p.getParameter<double>("EminFineTrack") * CLHEP::MeV) {}
28 
30 
31 void TrackingAction::PreUserTrackingAction(const G4Track* aTrack) {
32  g4Track_ = aTrack;
33  currentTrack_ = new TrackWithHistory(aTrack);
34 
35  BeginOfTrack bt(aTrack);
37 
38  TrackInformation* trkInfo = (TrackInformation*)aTrack->GetUserInformation();
39  if (trkInfo && trkInfo->isPrimary()) {
41  }
42  if (nullptr != steppingVerbose_) {
43  steppingVerbose_->TrackStarted(aTrack, false);
44  }
45 
46  if (doFineCalo_) {
47 #ifdef EDM_ML_DEBUG
48  edm::LogVerbatim("DoFineCalo") << "PreUserTrackingAction: Start processing track " << aTrack->GetTrackID()
49  << " pdgid=" << aTrack->GetDefinition()->GetPDGEncoding()
50  << " ekin[GeV]=" << aTrack->GetKineticEnergy() / CLHEP::GeV << " vertex[cm]=("
51  << aTrack->GetVertexPosition().x() / CLHEP::cm << ","
52  << aTrack->GetVertexPosition().y() / CLHEP::cm << ","
53  << aTrack->GetVertexPosition().z() / CLHEP::cm << ")"
54  << " parentid=" << aTrack->GetParentID();
55 #endif
56  // It is impossible to tell whether daughter tracks if this track may need to be saved at
57  // this point; Therefore, *every* track is put in history, so that it can potentially be saved
58  // later.
59  trkInfo->putInHistory();
60  // Always save primaries
61  // Decays from primaries are marked as primaries (see NewTrackAction), but are not saved by
62  // default. The primary is the earliest ancestor, and it must be saved.
63  if (trkInfo->isPrimary())
65  }
66 }
67 
68 void TrackingAction::PostUserTrackingAction(const G4Track* aTrack) {
69  if (eventAction_->trackContainer() != nullptr) {
70  uint32_t id = aTrack->GetTrackID();
71  math::XYZVectorD pos(aTrack->GetStep()->GetPostStepPoint()->GetPosition().x(),
72  aTrack->GetStep()->GetPostStepPoint()->GetPosition().y(),
73  aTrack->GetStep()->GetPostStepPoint()->GetPosition().z());
75  std::pair<math::XYZVectorD, math::XYZTLorentzVectorD> p(pos, mom);
76 
77 #ifdef EDM_ML_DEBUG
78  edm::LogVerbatim("DoFineCalo") << "PostUserTrackingAction:"
79  << " aTrack->GetTrackID()=" << aTrack->GetTrackID()
80  << " currentTrack_->saved()=" << currentTrack_->saved() << " PostStepPosition=("
81  << pos.x() << "," << pos.y() << "," << pos.z() << ")";
82 #endif
83 
84  if (doFineCalo_) {
85  TrackInformation* trkInfo = (TrackInformation*)aTrack->GetUserInformation();
86  // Add the post-step position for _every_ track
87  // in history to the TrackManager. Tracks in history _may_ be upgraded to stored
88  // tracks, at which point the post-step position is needed again.
90  if (trkInfo->crossedBoundary()) {
93 #ifdef EDM_ML_DEBUG
94  edm::LogVerbatim("DoFineCalo") << "PostUserTrackingAction:"
95  << " Track " << aTrack->GetTrackID() << " crossed boundary; pos=("
96  << trkInfo->getPositionAtBoundary().x() << ","
97  << trkInfo->getPositionAtBoundary().y() << ","
98  << trkInfo->getPositionAtBoundary().z() << ")"
99  << " mom[GeV]=(" << trkInfo->getMomentumAtBoundary().x() << ","
100  << trkInfo->getMomentumAtBoundary().y() << ","
101  << trkInfo->getMomentumAtBoundary().z() << ","
102  << trkInfo->getMomentumAtBoundary().e() << ")";
103 #endif
104  }
105  }
106 
107  TrackInformation* trkInfo = (TrackInformation*)aTrack->GetUserInformation();
108  if (extractor_(aTrack).storeTrack() || currentTrack_->saved() ||
110  if (trkInfo->crossedBoundary()) {
112  }
113  currentTrack_->save();
114 
116 #ifdef EDM_ML_DEBUG
117  edm::LogVerbatim("SimTrackManager")
118  << "TrackingAction addTkCaloStateInfo " << id << " of momentum " << mom << " at " << pos;
119 #endif
120  }
121 
122  bool withAncestor =
123  ((extractor_(aTrack).getIDonCaloSurface() == aTrack->GetTrackID()) || (extractor_(aTrack).isAncestor()));
124 
125  if (extractor_(aTrack).isInHistory()) {
126  // check with end-of-track information
127  if (checkTrack_) {
128  currentTrack_->checkAtEnd(aTrack);
129  }
130 
131  eventAction_->addTrack(currentTrack_, true, withAncestor);
132 
133 #ifdef EDM_ML_DEBUG
134  edm::LogVerbatim("SimTrackManager")
135  << "TrackingAction addTrack " << currentTrack_->trackID() << " E(GeV)= " << aTrack->GetKineticEnergy() << " "
136  << aTrack->GetDefinition()->GetParticleName() << " added= " << withAncestor << " at "
137  << aTrack->GetPosition();
138  edm::LogVerbatim("SimTrackManager") << "TrackingAction addTrack " << currentTrack_->trackID() << " added with "
139  << true << " and " << withAncestor << " at " << pos;
140 #endif
141 
142  } else {
143  eventAction_->addTrack(currentTrack_, false, false);
144 
145 #ifdef EDM_ML_DEBUG
146  edm::LogVerbatim("SimTrackManager")
147  << "TrackingAction addTrack " << currentTrack_->trackID() << " added with " << false << " and " << false;
148 #endif
149 
150  delete currentTrack_;
151  }
152  }
153  if (nullptr != steppingVerbose_) {
154  steppingVerbose_->TrackEnded(aTrack);
155  }
156 
157  EndOfTrack et(aTrack);
158  m_endOfTrackSignal(&et);
159 
160  currentTrack_ = nullptr; // reset for next track
161 }
Log< level::Info, true > LogVerbatim
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
bool saved() const
const G4Track * g4Track_
TrackInformationExtractor extractor_
void setCrossedBoundaryPosMom(int id, const math::XYZTLorentzVectorF position, const math::XYZTLorentzVectorF momentum)
CMSSteppingVerbose * steppingVerbose_
TrackWithHistory * currentTrack_
const math::XYZTLorentzVectorF & getPositionAtBoundary() const
void TrackEnded(const G4Track *) const
void prepareForNewPrimary()
Definition: EventAction.h:44
~TrackingAction() override
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
bool crossedBoundary() const
EventAction * eventAction_
unsigned int trackID() const
TrackingAction(EventAction *ea, const edm::ParameterSet &ps, CMSSteppingVerbose *)
void checkAtEnd(const G4Track *)
bool saveCaloBoundaryInformation_
void PreUserTrackingAction(const G4Track *aTrack) override
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal
const TrackContainer * trackContainer() const
Definition: EventAction.h:33
const math::XYZTLorentzVectorF & getMomentumAtBoundary() const
bool isPrimary() const
void addTkCaloStateInfo(uint32_t t, const std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > &p)
Definition: EventAction.cc:72
void PostUserTrackingAction(const G4Track *aTrack) override
void TrackStarted(const G4Track *, bool isKilled)
void addTrack(TrackWithHistory *iTrack, bool inHistory, bool withAncestor)
Definition: EventAction.h:35
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal