G4StationSteppingAction.cc
Go to the documentation of this file.
3 #include "G4StationEventAction.h"
4 #include "G4StationSimulator.h"
6 #include "G4Utils.h"
7 
8 #include <det/Detector.h>
9 #include <sdet/SDetector.h>
10 #include <sdet/Station.h>
11 #include <sevt/PMT.h>
12 #include <sevt/PMTSimData.h>
13 #include <sevt/SEvent.h>
14 #include <sevt/Station.h>
15 #include <sevt/StationSimData.h>
16 #include <utl/config.h>
17 #include <utl/ErrorLogger.h>
18 #include <utl/Particle.h>
19 #include <utl/Trace.h>
20 #include <utl/AugerCoordinateSystem.h>
21 #include <fwk/RunController.h>
22 
23 #include <G4Step.hh>
24 #include <G4VProcess.hh>
25 #include <G4SteppingManager.hh>
26 #include <G4Track.hh>
27 #include <G4TrackVector.hh>
28 #include <G4Trajectory.hh>
29 #include <G4TrajectoryContainer.hh>
30 
31 #include <sstream>
32 #include <vector>
33 
34 using namespace std;
35 
36 
37 namespace G4StationSimulatorOG {
38 
39  G4StationSteppingAction::RPCTrackIDListMap G4StationSteppingAction::fgRPCTrackIDListMap;
40  G4StationSteppingAction::RPCParticleListMap G4StationSteppingAction::fgRPCParticleListMap;
41 
42  int G4StationSteppingAction::fgParticleId = 0;
43 
44 
45  void
46  G4StationSteppingAction::UserSteppingAction(const G4Step* const step)
47  {
48  const auto& track = *step->GetTrack();
49  fgParticleId = track.GetDefinition()->GetPDGEncoding();
50 
51  if (!fgParticleId && track.GetNextVolume()) {
52  const auto& next = track.GetNextVolume()->GetName();
53  if (next == "top" || next == "side" || next == "bottom")
54  ++G4StationTrackingAction::fNumBounces;
55  }
56 
57  if (!fMARTAEnabled)
58  return;
59 
60  const auto& currentVolume = track.GetVolume()->GetName();
61  if (currentVolume != "rpc_gas")
62  return;
63 
64  const auto& mother = *track.GetTouchable()->GetVolume(1);
65  const auto& grandmother = *track.GetTouchable()->GetVolume(2);
66 
67  if (mother.GetName() != "rpc_glass" || grandmother.GetName() != "rpc") {
68  ostringstream err;
69  err << "RPC gas not found where expected : mother is "
70  << mother.GetName() << " (should be rpc_glass) and grandmother is "
71  << grandmother.GetName() << " (should be rpc)";
72  throw utl::InvalidConfigurationException(err.str());
73  }
74 
75  const G4int rpcId = grandmother.GetCopyNo();
76 
77  const int particleID = track.GetDefinition()->GetPDGEncoding();
78  const int trackID = track.GetTrackID();
79 
80  const auto& prePoint = *step->GetPreStepPoint();
81  const double ke1 = prePoint.GetKineticEnergy() / CLHEP::MeV * utl::MeV;
82  const double dedx = step->GetTotalEnergyDeposit() / CLHEP::MeV * utl::MeV;
83  const double enDepNonIoni = step->GetNonIonizingEnergyDeposit() / CLHEP::MeV * utl::MeV;
84  const double enDepIoni = dedx - enDepNonIoni;
85 
86  const double w = track.GetWeight();
87  const bool isSec = w < 0;
88 
89  auto& secondary = *G4UserSteppingAction::fpSteppingManager->GetfSecondary();
90 
91  for (const auto sp : secondary) {
92  auto& s = *sp;
93  if (s.GetVolume()->GetName() != "rpc_gas")
94  continue;
95  if (!isSec)
96  s.SetWeight(-trackID);
97  }
98 
99  bool trackSave = true;
100  auto& trackId = fgRPCTrackIDListMap[rpcId];
101  auto& particleList = fgRPCParticleListMap[rpcId];
102 
103  if (isSec) { // Particle it is a secondary, add dEdX to primary
104 
105  for (unsigned int t = 0, n = trackId.size(); t < n; ++t) {
106  if (trackId[t] != -w) // find trackID of the primary using W of secondary
107  continue;
108  if (enDepIoni > 0) {
109  auto& p = particleList[t];
110  const double enLoss = p.GetWeight();
111  p.SetWeight(enDepIoni + enLoss);
112  }
113  trackSave = false;
114  }
115 
116  } else {
117 
118  for (unsigned int t = 0, n = trackId.size(); t < n; ++t) {
119  if (trackId[t] != trackID) // find trackID of the primary
120  continue;
121  if (enDepIoni > 0) {
122  auto& p = particleList[t];
123  const double enLoss = p.GetWeight();
124  p.SetWeight(enDepIoni + enLoss);
125  }
126  trackSave = false;
127  }
128 
129  }
130 
131  // Save a new primary track which is not secondary!
132  if (trackSave && !isSec) {
133 
134  trackId.push_back(trackID);
135 
136  const sdet::Station& station = G4StationSimulator::fgCurrent.GetDetectorStation();
137  const auto cs = station.GetLocalCoordinateSystem();
138 
139  // Position in Tank CS (centered in center of tank)
140  const G4ThreeVector pos = prePoint.GetPosition() - G4StationConstruction::fgTankCenter; // <-- this is not right
141  const double time = prePoint.GetGlobalTime() / CLHEP::ns * utl::ns;
142  const auto position = To<utl::Point>(pos, cs, utl::meter/CLHEP::meter);
143  const auto direction = To<utl::Vector>(prePoint.GetMomentumDirection(), cs, 1);
144  const auto particleType = utl::Particle::Type(particleID);
145 
146  utl::Particle& currentParticle = G4StationSimulator::fgCurrent.GetParticle();
147 
148  const utl::Particle::Source source = currentParticle.GetSource();
149  utl::Particle newParticle(particleType, source, position, direction, time, enDepIoni, ke1);
150 
151  // Set parent particle (i.e. the particle entering the tank)
152 
153  if (track.GetParentID())
154  newParticle.SetParent(currentParticle);
155 
156  // Copy production point
157  if (currentParticle.HasProductionPoint()) {
158  const auto& pProd = currentParticle.GetProductionPoint();
159  newParticle.SetProductionPoint(pProd);
160  }
161 
162  particleList.push_back(newParticle);
163 
164  }
165  }
166 
167 }
const utl::Point & GetProductionPoint() const
Definition: Particle.h:153
Detector description interface for Station-related data.
bool HasProductionPoint() const
Definition: Particle.h:152
Describes a particle for Simulation.
Definition: Particle.h:26
Base class for exceptions arising because configuration data are not valid.
const double meter
Definition: GalacticUnits.h:29
Type
Particle types.
Definition: Particle.h:48
void SetProductionPoint(const utl::Point &point)
Definition: Particle.h:154
constexpr double MeV
Definition: AugerUnits.h:184
Iterator next(Iterator it)
constexpr double s
Definition: AugerUnits.h:163
const double ns
constexpr double meter
Definition: AugerUnits.h:81
utl::CoordinateSystemPtr GetLocalCoordinateSystem() const
Get the Auger reference system centered on the tank.
Source GetSource() const
Source of the particle (eg. shower or background)
Definition: Particle.h:107
constexpr double ns
Definition: AugerUnits.h:162
void SetParent(Particle &parent)
Definition: Particle.h:150

, generated on Tue Sep 26 2023.