ATLAS Offline Software
Loading...
Searching...
No Matches
QuirkWatcher.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "G4TrackStatus.hh"
6#include "G4LorentzVector.hh"
7
8#include "Quirk.h"
9#include "InfracolorForce.h"
10#include "QuirkWatcher.h"
11
13
14QuirkWatcher::QuirkWatcher() : G4VProcess(G4String("QuirkWatcher")) {
15 enableAtRestDoIt = false;
16 enableAlongStepDoIt = false;
17}
18
20
22 const G4Track&, //track
23 G4double, //previousStepSize
24 G4ForceCondition* condition
25) {
26 *condition = StronglyForced;
27 return DBL_MAX;
28}
29
30G4VParticleChange* QuirkWatcher::PostStepDoIt(
31 const G4Track& track,
32 const G4Step& //stepData
33) {
34 // Get infracolor string
35 auto part_nc ATLAS_THREAD_SAFE = // track should really be non-const in Geant4 interface
36 const_cast<G4ParticleDefinition*>(track.GetParticleDefinition());
37 Quirk* quirkDef = dynamic_cast<Quirk*>(part_nc);
38 if (quirkDef == 0) {
39 G4Exception("QuirkWatcher::PostStepDoIt", "NonQuirk", FatalErrorInArgument, "QuirkWatcher run on non-quirk particle");
40 std::abort();
41 }
42 InfracolorForce& string = quirkDef->GetStringIn();
43
44 if (track.GetCurrentStepNumber() > 1 && !string.IsSourceInitialized()) {
45 // if the partner quirk is still alive, clear its string state too so that it
46 // doesn't try to push a string vector to the orphan quirk and crash
47 // leave as just a warning so that the event can continue and the hits recorded so far are kept, like for looperKiller'd tracks
48 string.Clear();
49 string.GetReactionForce()->Clear();
50 G4Exception(
51 "QuirkWatcher::PostStepDoIt",
52 "QuirkMissingPartner",
53 JustWarning,
54 "QuirkWatcher: missing partner for quirk; killing orphan track"
55 );
56 m_particleChange.Initialize(track);
57 m_particleChange.ProposeTrackStatus(fStopAndKill);
58 return &m_particleChange;
59 }
60
61 // Update track status
62 G4TrackStatus stat = track.GetTrackStatus();
63 if (stat == fStopButAlive) {
64 stat = fAlive;
65 }
66 if (stat == fAlive || stat == fSuspend) {
67 G4bool passControl = !string.HasNextStringVector();
68 //G4bool passControl = !string.HasNextStringVector() || (string.GetSumStrings().t() < string.GetReactionForce()->GetSumStrings().t());
69 if (passControl) {
70 if (string.IsSourceAlive()) {
71 stat = fSuspend;
72 } else {
73 stat = fStopAndKill;
74 }
75 }
76 }
77 if (stat == fStopAndKill || stat == fKillTrackAndSecondaries) {
78 string.TrackKilled();
79 }
80
81 m_particleChange.Initialize(track);
82 m_particleChange.ProposeTrackStatus(stat);
83 return &m_particleChange;
84}
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
virtual G4double PostStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)
G4VParticleChange m_particleChange
virtual ~QuirkWatcher()
virtual G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &)
Definition Quirk.h:12
const InfracolorForce & GetStringIn() const
Definition Quirk.h:29