CMS 3D CMS Logo

TrackingAction.cc
Go to the documentation of this file.
2 
10 
12 
13 #include "G4UImanager.hh"
14 #include "G4TrackingManager.hh"
15 #include "G4SystemOfUnits.hh"
16 
17 //#define EDM_ML_DEBUG
18 
20  : trackManager_(stm),
21  steppingVerbose_(sv),
22  endPrintTrackID_(p.getParameter<int>("EndPrintTrackID")),
23  checkTrack_(p.getUntrackedParameter<bool>("CheckTrack", false)),
24  doFineCalo_(p.getParameter<bool>("DoFineCalo")),
25  saveCaloBoundaryInformation_(p.getParameter<bool>("SaveCaloBoundaryInformation")),
26  eMinFine_(p.getParameter<double>("EminFineTrack") * CLHEP::MeV) {
27  if (!doFineCalo_) {
28  eMinFine_ = DBL_MAX;
29  }
30  edm::LogVerbatim("SimG4CoreApplication") << "TrackingAction: boundary: " << saveCaloBoundaryInformation_
31  << "; DoFineCalo: " << doFineCalo_ << "; EminFineTrack(MeV)=" << eMinFine_;
32 }
33 
34 void TrackingAction::PreUserTrackingAction(const G4Track* aTrack) {
35  g4Track_ = aTrack;
36  currentTrack_ = new TrackWithHistory(aTrack, aTrack->GetParentID());
37 
38  BeginOfTrack bt(aTrack);
40 
41  trkInfo_ = static_cast<TrackInformation*>(aTrack->GetUserInformation());
42 
43  // Always save primaries
44  // Decays from primaries are marked as primaries, but are not saved by
45  // default. The primary is the earliest ancestor, and it must be saved.
46  if (trkInfo_->isPrimary()) {
49  }
50  if (nullptr != steppingVerbose_) {
51  steppingVerbose_->trackStarted(aTrack, false);
52  if (aTrack->GetTrackID() == endPrintTrackID_) {
54  }
55  }
56  double ekin = aTrack->GetKineticEnergy();
57 
58 #ifdef EDM_ML_DEBUG
59  edm::LogVerbatim("DoFineCalo") << "PreUserTrackingAction: Start processing track " << aTrack->GetTrackID()
60  << " pdgid=" << aTrack->GetDefinition()->GetPDGEncoding()
61  << " ekin[GeV]=" << ekin / CLHEP::GeV << " vertex[cm]=("
62  << aTrack->GetVertexPosition().x() / CLHEP::cm << ","
63  << aTrack->GetVertexPosition().y() / CLHEP::cm << ","
64  << aTrack->GetVertexPosition().z() / CLHEP::cm << ")"
65  << " parentid=" << aTrack->GetParentID();
66 #endif
67  if (ekin > eMinFine_) {
68  // It is impossible to tell whether daughter tracks if this track may need to be saved at
69  // this point; Therefore, every track above the threshold is put in history,
70  // so that it can potentially be saved later.
72  }
73 }
74 
75 void TrackingAction::PostUserTrackingAction(const G4Track* aTrack) {
76  // Add the post-step position for every track in history to the TrackManager.
77  // Tracks in history may be upgraded to stored tracks, at which point
78  // the post-step position is needed again.
79  int id = aTrack->GetTrackID();
80  bool ok = (trkInfo_->storeTrack() || currentTrack_->saved());
81  if (trkInfo_->crossedBoundary()) {
84  }
85  if (ok) {
87  }
88 
89  bool withAncestor = (trkInfo_->getIDonCaloSurface() == id || trkInfo_->isAncestor());
90  bool isInHistory = trkInfo_->isInHistory();
91 
92  trackManager_->addTrack(currentTrack_, aTrack, isInHistory, withAncestor);
93 
94 #ifdef EDM_ML_DEBUG
95  edm::LogVerbatim("TrackingAction") << "TrackingAction end track=" << id << " "
96  << aTrack->GetDefinition()->GetParticleName() << " ansestor= " << withAncestor
97  << " saved= " << currentTrack_->saved() << " end point " << aTrack->GetPosition();
98 #endif
99  if (!isInHistory) {
100  delete currentTrack_;
101  }
102 
103  EndOfTrack et(aTrack);
105 }
bool storeTrack() const
Log< level::Info, true > LogVerbatim
bool isPrimary() const
bool crossedBoundary() const
SimTrackManager * trackManager_
bool isAncestor() const
const math::XYZTLorentzVectorF & getPositionAtBoundary() const
const G4Track * g4Track_
CMSSteppingVerbose * steppingVerbose_
TrackWithHistory * currentTrack_
bool isInHistory() const
TrackInformation * trkInfo_
TrackingAction(SimTrackManager *, CMSSteppingVerbose *, const edm::ParameterSet &ps)
bool saveCaloBoundaryInformation_
void PreUserTrackingAction(const G4Track *aTrack) override
void cleanTracksWithHistory()
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal
const math::XYZTLorentzVectorF & getMomentumAtBoundary() const
int getIDonCaloSurface() const
void addTrack(TrackWithHistory *iTrack, const G4Track *track, bool inHistory, bool withAncestor)
bool saved() const
void PostUserTrackingAction(const G4Track *aTrack) override
void trackStarted(const G4Track *, bool isKilled)
void setCrossedBoundaryPosMom(int id, const math::XYZTLorentzVectorF &position, const math::XYZTLorentzVectorF &momentum)
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal