Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ParticleKillAction.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ParticleKillAction.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
13 #include "Acts/Geometry/Volume.hpp"
14 
15 #include <ostream>
16 #include <utility>
17 
18 #include <G4RunManager.hh>
19 #include <G4Step.hh>
20 #include <G4StepPoint.hh>
21 #include <G4Track.hh>
22 #include <G4UnitsTable.hh>
23 #include <G4VPhysicalVolume.hh>
24 
26  const Config& cfg, std::unique_ptr<const Acts::Logger> logger)
27  : G4UserSteppingAction(), m_cfg(cfg), m_logger(std::move(logger)) {}
28 
30  constexpr double convertLength = Acts::UnitConstants::mm / CLHEP::mm;
31  constexpr double convertTime = Acts::UnitConstants::ns / CLHEP::ns;
32 
33  G4Track* track = step->GetTrack();
34 
35  const auto pos = convertLength * track->GetPosition();
36  const auto time = convertTime * track->GetGlobalTime();
37  const bool isSecondary =
38  track->GetDynamicParticle()->GetPrimaryParticle() == nullptr;
39 
40  const bool outOfVolume =
41  m_cfg.volume and
42  not m_cfg.volume->inside(Acts::Vector3{pos.x(), pos.y(), pos.z()});
43  const bool outOfTime = time > m_cfg.maxTime;
44  const bool invalidSecondary = m_cfg.secondaries && isSecondary;
45 
46  if (outOfVolume or outOfTime or invalidSecondary) {
47  ACTS_DEBUG("Kill track with internal track ID "
48  << track->GetTrackID() << " at " << pos << " and global time "
49  << time / Acts::UnitConstants::ns << "ns and isSecondary "
50  << isSecondary);
51  track->SetTrackStatus(G4TrackStatus::fStopAndKill);
52  }
53 }