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 <CLHEP/Units/SystemOfUnits.h>
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  ekinMin_(p.getParameter<double>("PersistencyEmin") * CLHEP::GeV),
27  ekinMinRegion_(p.getParameter<std::vector<double>>("RegionEmin")) {
28  double eth = p.getParameter<double>("EminFineTrack") * CLHEP::MeV;
29  if (doFineCalo_ && eth < ekinMin_) {
30  ekinMin_ = eth;
31  }
32  edm::LogVerbatim("SimG4CoreApplication") << "TrackingAction: boundary: " << saveCaloBoundaryInformation_
33  << "; DoFineCalo: " << doFineCalo_ << "; ekinMin(MeV)=" << ekinMin_;
34  if (!ekinMinRegion_.empty()) {
35  ptrRegion_.resize(ekinMinRegion_.size(), nullptr);
36  }
37 }
38 
39 void TrackingAction::PreUserTrackingAction(const G4Track* aTrack) {
40  g4Track_ = aTrack;
41  currentTrack_ = new TrackWithHistory(aTrack, aTrack->GetParentID());
42 
43  BeginOfTrack bt(aTrack);
45 
46  trkInfo_ = static_cast<TrackInformation*>(aTrack->GetUserInformation());
47 
48  // Always save primaries
49  if (trkInfo_->isPrimary()) {
52  }
53 
54  if (nullptr != steppingVerbose_) {
55  steppingVerbose_->trackStarted(aTrack, false);
56  if (aTrack->GetTrackID() == endPrintTrackID_) {
58  }
59  }
60  double ekin = aTrack->GetKineticEnergy();
61 
62 #ifdef EDM_ML_DEBUG
63  edm::LogVerbatim("DoFineCalo") << "PreUserTrackingAction: Start processing track " << aTrack->GetTrackID()
64  << " pdgid=" << aTrack->GetDefinition()->GetPDGEncoding()
65  << " ekin[GeV]=" << ekin / CLHEP::GeV << " vertex[cm]=("
66  << aTrack->GetVertexPosition().x() / CLHEP::cm << ","
67  << aTrack->GetVertexPosition().y() / CLHEP::cm << ","
68  << aTrack->GetVertexPosition().z() / CLHEP::cm << ")"
69  << " parentid=" << aTrack->GetParentID();
70 #endif
71  if (ekin > ekinMin_) {
72  // Each track with energy above the threshold should be saved
74  }
75 }
76 
77 void TrackingAction::PostUserTrackingAction(const G4Track* aTrack) {
78  // Tracks in history may be upgraded to stored secondary tracks,
79  // which cross the boundary between Tracker and Calo
80  int id = aTrack->GetTrackID();
81  bool ok = (trkInfo_->storeTrack() || currentTrack_->saved());
82  if (trkInfo_->crossedBoundary()) {
85  }
86  if (ok) {
88  }
89 
90  bool withAncestor = (trkInfo_->getIDonCaloSurface() == id || trkInfo_->isAncestor());
91  bool isInHistory = trkInfo_->isInHistory();
92 
93  trackManager_->addTrack(currentTrack_, aTrack, isInHistory, withAncestor);
94 
95 #ifdef EDM_ML_DEBUG
96  edm::LogVerbatim("TrackingAction") << "TrackingAction end track=" << id << " "
97  << aTrack->GetDefinition()->GetParticleName() << " proposed to be saved= " << ok
98  << " end point " << aTrack->GetPosition();
99 #endif
100 
101  if (!isInHistory) {
102  delete currentTrack_;
103  }
104 
105  EndOfTrack et(aTrack);
107 }
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
std::vector< double > ekinMinRegion_
int getIDonCaloSurface() const
void addTrack(TrackWithHistory *iTrack, const G4Track *track, bool inHistory, bool withAncestor)
bool saved() const
std::vector< G4Region * > ptrRegion_
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