18#include "BDSOutputROOTEventSampler.hh"
19#include "BDSOutputROOTParticleData.hh"
26#include "BDSHitSampler.hh"
27#include "BDSParticleCoordsFull.hh"
28#include "BDSPhysicalConstants.hh"
29#include "BDSPrimaryVertexInformationV.hh"
32#include "CLHEP/Units/SystemOfUnits.h"
40 samplerName(
"sampler")
47 samplerName(samplerNameIn)
61 G4bool storePolarCoords,
62 G4bool storeElectrons,
64 G4bool storeKineticEnergy)
68 z = (U) (hit->coords.z / CLHEP::m);
69 S = (U) (hit->coords.
s / CLHEP::m);
71 energy.push_back((U) (hit->coords.totalEnergy / CLHEP::GeV));
72 x.push_back((U) (hit->coords.x / CLHEP::m));
73 y.push_back((U) (hit->coords.y / CLHEP::m));
75 xp.push_back((U) (hit->coords.xp));
76 yp.push_back((U) (hit->coords.yp));
77 zp.push_back((U) (hit->coords.zp));
78 p.push_back((U) (hit->momentum / CLHEP::GeV));
79 T.push_back((U) (hit->coords.T / CLHEP::ns));
81 modelID = hit->beamlineIndex;
83 weight.push_back((U) (hit->coords.weight));
84 partID.push_back(hit->pdgID);
85 parentID.push_back(hit->parentID);
86 trackID.push_back(hit->trackID);
87 turnNumber.push_back(hit->turnsTaken);
90 {mass.push_back((U)(hit->mass / CLHEP::GeV));}
93 {charge.push_back((
int)(hit->
charge / (G4double)CLHEP::eplus));}
95 if (storeKineticEnergy)
96 {kineticEnergy.push_back((U)(hit->coords.totalEnergy - hit->mass) / CLHEP::GeV);}
99 {rigidity.push_back((U)hit->rigidity/(CLHEP::tesla*CLHEP::m));}
101 if (storePolarCoords)
102 {FillPolarCoords(hit->coords);}
123 trackID.push_back(n);
125 energy.push_back((U) (coords.totalEnergy / CLHEP::GeV));
126 x.push_back((U) (coords.x / CLHEP::m));
127 y.push_back((U) (coords.y / CLHEP::m));
128 z = (U) (coords.z / CLHEP::m);
129 xp.push_back((U) (coords.xp));
130 yp.push_back((U) (coords.yp));
131 zp.push_back((U) (coords.zp));
132 p.push_back((U) (momentumIn / CLHEP::GeV));
133 T.push_back((U) (coords.T / CLHEP::ns));
134 weight.push_back((U) coords.weight);
135 partID.push_back(pdgID);
136 parentID.push_back(0);
137 modelID = beamlineIndex;
138 turnNumber.push_back(turnsTaken);
139 S = (U) (coords.
s / CLHEP::GeV);
142 charge.push_back((
int)(chargeIn / (G4double)CLHEP::eplus));
143 mass.push_back((U)(massIn / CLHEP::GeV));
144 rigidity.push_back((U)rigidityIn /(CLHEP::tesla*CLHEP::m));
145 nElectrons.push_back((
int)nElectronsIn);
146 kineticEnergy.push_back((U)(coords.totalEnergy - massIn) / CLHEP::GeV);
147 FillPolarCoords(coords);
148 if (isIonIn && ionAIn && ionZIn)
150 isIon.push_back((
int) *isIonIn);
151 ionA.push_back((
int) *ionAIn);
152 ionZ.push_back((
int) *ionZIn);
161 double xCoord = coords.x / CLHEP::m;
162 double yCoord = coords.y / CLHEP::m;
163 double xpCoord = coords.xp;
164 double ypCoord = coords.yp;
165 double zpCoord = coords.zp;
168 auto isntSafe = [](
double a){
return std::isnan(a) || std::isinf(a);};
170 double rValue = std::hypot(xCoord, yCoord);
171 if (isntSafe(rValue))
173 r.push_back(
static_cast<U
>(rValue));
175 double rpValue = std::hypot(xpCoord, ypCoord);
176 if (isntSafe(rpValue))
178 rp.push_back(
static_cast<U
>(rpValue));
180 double thetapValue = std::atan2(rpValue, zpCoord);
181 if (isntSafe(thetapValue))
183 theta.push_back(
static_cast<U
>(thetapValue));
185 double phiValue = std::atan2(xCoord, yCoord);
186 if (isntSafe(phiValue))
188 phi.push_back(
static_cast<U
>(phiValue));
190 double phipValue = std::atan2(xpCoord, ypCoord);
191 if (isntSafe(phipValue))
193 phip.push_back(
static_cast<U
>(phipValue));
198 const G4int turnsTaken)
200 for (
const auto& vertexInfo : vertexInfos->
vertices)
202 Fill(vertexInfo.primaryVertex.local,
207 vertexInfo.primaryVertex.beamlineIndex,
208 vertexInfo.nElectrons,
223 energy = other->energy;
233 weight = other->weight;
234 partID = other->partID;
235 parentID = other->parentID;
236 trackID = other->trackID;
237 modelID = other->modelID;
238 turnNumber = other->turnNumber;
245 theta = other->theta;
252 isIon = other->
isIon;
292 kineticEnergy.clear();
304 std::vector<U> result((
unsigned long)n);
307 for (
int i = 0; i < n; ++i)
308 {result[i] = (U)particleTable->KineticEnergy(partID[i], energy[i]);}
315 std::vector<U> result((
unsigned long)n);
318 for (
int i = 0; i < n; ++i)
319 {result[i] = (U)particleTable->Mass(partID[i]);}
326 std::vector<U> result((
unsigned long)n);
329 for (
int i = 0; i < n; ++i)
330 {result[i] = (U)particleTable->Rigidity(partID[i], energy[i]);}
337 bool useNElectrons = !nElectrons.empty();
338 std::vector<bool> result((
unsigned long)n);
341 for (
int i = 0; i < n; ++i)
343 result[i] = particleTable->IsIon(partID[i]);
345 {result[i] = result[i] || nElectrons[i] > 0;}
353 std::vector<int> result((
unsigned long)n);
356 for (
int i = 0; i < n; ++i)
357 {result[i] = (int)particleTable->IonA(partID[i]);}
364 std::vector<int> result((
unsigned long)n);
367 for (
int i = 0; i < n; ++i)
368 {result[i] = (int)particleTable->IonZ(partID[i]);}
The information recorded from a particle impacting a sampler.
G4int nElectrons
Can only get this at inspection time so include here.
G4double charge
Double as g4 uses charge as a double.
Information stored per sampler per event.
std::vector< int > getIonA()
Function to calculate on the fly the parameters.
std::vector< bool > isIon
These are not filled by default.
std::vector< int > getIonZ()
Function to calculate on the fly the parameters.
std::vector< int > nElectrons
These are not filled by default.
std::vector< int > ionA
These are not filled by default.
void FlushLocal()
Actual flush that is non virtual function to use in constructor.
std::vector< U > getRigidity()
Function to calculate on the fly the parameters.
std::vector< U > getMass()
Function to calculate on the fly the parameters.
std::vector< U > rigidity
These are not filled by default.
std::vector< bool > getIsIon()
Function to calculate on the fly the parameters.
std::vector< int > charge
These are not filled by default.
virtual void Flush()
Clean Sampler.
std::vector< U > kineticEnergy
These are not filled by default.
void FillPolarCoords(const BDSParticleCoordsFull &coords)
Calculate polar coords and fill.
std::vector< U > mass
These are not filled by default.
std::vector< int > ionZ
These are not filled by default.
std::vector< U > getKineticEnergy()
Function to calculate on the fly the parameters.
Geant4 particle data for particles used in simulation.
void Fill(G4bool fillIons)
Fill maps of particle information from Geant4.
A set of particle coordinates including energy and weight.
G4double s
TODO - remove this. Unused. S (global) is calculated from S0 + z.