CMS 3D CMS Logo

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);
159 
160  currentTrack_ = nullptr; // reset for next track
161 }
electrons_cff.bool
bool
Definition: electrons_cff.py:366
TrackingAction.h
EventAction::trackContainer
const TrackContainer * trackContainer() const
Definition: EventAction.h:33
MessageLogger.h
EventAction
Definition: EventAction.h:23
funct::false
false
Definition: Factorize.h:29
TrackingAction::TrackingAction
TrackingAction(EventAction *ea, const edm::ParameterSet &ps, CMSSteppingVerbose *)
Definition: TrackingAction.cc:19
TrackingAction::~TrackingAction
~TrackingAction() override
Definition: TrackingAction.cc:29
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
TrackingAction::PostUserTrackingAction
void PostUserTrackingAction(const G4Track *aTrack) override
Definition: TrackingAction.cc:68
math::XYZTLorentzVectorD
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:14
TrackWithHistory
Definition: TrackWithHistory.h:16
pos
Definition: PixelAliasList.h:18
EventAction::prepareForNewPrimary
void prepareForNewPrimary()
Definition: EventAction.h:44
TrackingAction::g4Track_
const G4Track * g4Track_
Definition: TrackingAction.h:36
EventAction.h
MeV
const double MeV
EndOfTrack.h
CurrentG4Track.h
CMSSteppingVerbose
Definition: CMSSteppingVerbose.h:25
TrackingAction::extractor_
TrackInformationExtractor extractor_
Definition: TrackingAction.h:32
TrackInformation::putInHistory
void putInHistory()
Definition: TrackInformation.h:37
TrackInformation::getMomentumAtBoundary
const math::XYZTLorentzVectorF & getMomentumAtBoundary() const
Definition: TrackInformation.h:75
TrackWithHistory::checkAtEnd
void checkAtEnd(const G4Track *)
Definition: TrackWithHistory.cc:57
TrackWithHistory::setCrossedBoundaryPosMom
void setCrossedBoundaryPosMom(int id, const math::XYZTLorentzVectorF position, const math::XYZTLorentzVectorF momentum)
Definition: TrackWithHistory.h:47
EndOfTrack
Definition: EndOfTrack.h:6
BeginOfTrack.h
NewTrackAction.h
TrackingAction::currentTrack_
TrackWithHistory * currentTrack_
Definition: TrackingAction.h:34
TrackInformation::isPrimary
bool isPrimary() const
Definition: TrackInformation.h:27
pfDeepBoostedJetPreprocessParams_cfi.sv
sv
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:352
TrackingAction::m_endOfTrackSignal
SimActivityRegistry::EndOfTrackSignal m_endOfTrackSignal
Definition: TrackingAction.h:29
BeginOfTrack
Definition: BeginOfTrack.h:6
TrackWithHistory::save
void save()
Definition: TrackWithHistory.h:27
CLHEP
Definition: CocoaGlobals.h:27
math::XYZVectorD
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
Definition: Vector3D.h:8
TrackInformation::getPositionAtBoundary
const math::XYZTLorentzVectorF & getPositionAtBoundary() const
Definition: TrackInformation.h:74
edm::ParameterSet
Definition: ParameterSet.h:47
GeV
const double GeV
Definition: MathUtil.h:16
TrackingAction::eventAction_
EventAction * eventAction_
Definition: TrackingAction.h:33
TrackingAction::saveCaloBoundaryInformation_
bool saveCaloBoundaryInformation_
Definition: TrackingAction.h:39
CMSSteppingVerbose::TrackStarted
void TrackStarted(const G4Track *, bool isKilled)
Definition: CMSSteppingVerbose.cc:62
TrackInformation
Definition: TrackInformation.h:12
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
TrackInformation.h
TrackInformation::crossedBoundary
bool crossedBoundary() const
Definition: TrackInformation.h:73
TrackingAction::m_beginOfTrackSignal
SimActivityRegistry::BeginOfTrackSignal m_beginOfTrackSignal
Definition: TrackingAction.h:28
TrackWithHistory::trackID
unsigned int trackID() const
Definition: TrackWithHistory.h:28
CMSSteppingVerbose::TrackEnded
void TrackEnded(const G4Track *) const
Definition: CMSSteppingVerbose.cc:130
TrackWithHistory::saved
bool saved() const
Definition: TrackWithHistory.h:44
CMSSteppingVerbose.h
EventAction::addTkCaloStateInfo
void addTkCaloStateInfo(uint32_t t, const std::pair< math::XYZVectorD, math::XYZTLorentzVectorD > &p)
Definition: EventAction.cc:72
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
TrackingAction::doFineCalo_
bool doFineCalo_
Definition: TrackingAction.h:38
TrackingAction::checkTrack_
bool checkTrack_
Definition: TrackingAction.h:37
TrackingAction::steppingVerbose_
CMSSteppingVerbose * steppingVerbose_
Definition: TrackingAction.h:35
TrackingAction::PreUserTrackingAction
void PreUserTrackingAction(const G4Track *aTrack) override
Definition: TrackingAction.cc:31
EventAction::addTrack
void addTrack(TrackWithHistory *iTrack, bool inHistory, bool withAncestor)
Definition: EventAction.h:35
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
TrackWithHistory.h