19#include "BDSOutputROOTEventSampler.hh"
20#include "BDSOutputROOTParticleData.hh"
27#include "BDSHitSampler.hh"
28#include "BDSParticleCoordsFull.hh"
29#include "BDSPhysicalConstants.hh"
30#include "BDSPrimaryVertexInformationV.hh"
33#include "CLHEP/Units/SystemOfUnits.h"
41 samplerName(
"sampler")
48 samplerName(samplerNameIn)
62 G4bool storePolarCoords,
63 G4bool storeElectrons,
65 G4bool storeKineticEnergy)
69 z = (U) (hit->coords.z / CLHEP::m);
70 S = (U) (hit->coords.
s / CLHEP::m);
72 energy.push_back((U) (hit->coords.totalEnergy / CLHEP::GeV));
73 x.push_back((U) (hit->coords.x / CLHEP::m));
74 y.push_back((U) (hit->coords.y / CLHEP::m));
76 xp.push_back((U) (hit->coords.xp));
77 yp.push_back((U) (hit->coords.yp));
78 zp.push_back((U) (hit->coords.zp));
79 p.push_back((U) (hit->momentum / CLHEP::GeV));
80 T.push_back((U) (hit->coords.T / CLHEP::ns));
82 modelID = hit->beamlineIndex;
84 weight.push_back((U) (hit->coords.weight));
85 partID.push_back(hit->pdgID);
86 parentID.push_back(hit->parentID);
87 trackID.push_back(hit->trackID);
88 turnNumber.push_back(hit->turnsTaken);
91 {mass.push_back((U)(hit->mass / CLHEP::GeV));}
94 {charge.push_back((
int)(hit->
charge / (G4double)CLHEP::eplus));}
96 if (storeKineticEnergy)
97 {kineticEnergy.push_back((U)(hit->coords.totalEnergy - hit->mass) / CLHEP::GeV);}
100 {rigidity.push_back((U)hit->rigidity/(CLHEP::tesla*CLHEP::m));}
102 if (storePolarCoords)
103 {FillPolarCoords(hit->coords);}
124 trackID.push_back(n);
126 energy.push_back((U) (coords.totalEnergy / CLHEP::GeV));
127 x.push_back((U) (coords.x / CLHEP::m));
128 y.push_back((U) (coords.y / CLHEP::m));
129 z = (U) (coords.z / CLHEP::m);
130 xp.push_back((U) (coords.xp));
131 yp.push_back((U) (coords.yp));
132 zp.push_back((U) (coords.zp));
133 p.push_back((U) (momentumIn / CLHEP::GeV));
134 T.push_back((U) (coords.T / CLHEP::ns));
135 weight.push_back((U) coords.weight);
136 partID.push_back(pdgID);
137 parentID.push_back(0);
138 modelID = beamlineIndex;
139 turnNumber.push_back(turnsTaken);
140 S = (U) (coords.
s / CLHEP::GeV);
143 charge.push_back((
int)(chargeIn / (G4double)CLHEP::eplus));
144 mass.push_back((U)(massIn / CLHEP::GeV));
145 rigidity.push_back((U)rigidityIn /(CLHEP::tesla*CLHEP::m));
146 nElectrons.push_back((
int)nElectronsIn);
147 kineticEnergy.push_back((U)(coords.totalEnergy - massIn) / CLHEP::GeV);
148 FillPolarCoords(coords);
149 if (isIonIn && ionAIn && ionZIn)
151 isIon.push_back((
int) *isIonIn);
152 ionA.push_back((
int) *ionAIn);
153 ionZ.push_back((
int) *ionZIn);
162 double xCoord = coords.x / CLHEP::m;
163 double yCoord = coords.y / CLHEP::m;
164 double xpCoord = coords.xp;
165 double ypCoord = coords.yp;
166 double zpCoord = coords.zp;
169 auto isntSafe = [](
double a){
return std::isnan(a) || std::isinf(a);};
171 double rValue = std::hypot(xCoord, yCoord);
172 if (isntSafe(rValue))
174 r.push_back(
static_cast<U
>(rValue));
176 double rpValue = std::hypot(xpCoord, ypCoord);
177 if (isntSafe(rpValue))
179 rp.push_back(
static_cast<U
>(rpValue));
181 double thetapValue = std::atan2(rpValue, zpCoord);
182 if (isntSafe(thetapValue))
184 theta.push_back(
static_cast<U
>(thetapValue));
186 double phiValue = std::atan2(xCoord, yCoord);
187 if (isntSafe(phiValue))
189 phi.push_back(
static_cast<U
>(phiValue));
191 double phipValue = std::atan2(xpCoord, ypCoord);
192 if (isntSafe(phipValue))
194 phip.push_back(
static_cast<U
>(phipValue));
199 const G4int turnsTaken)
201 for (
const auto& vertexInfo : vertexInfos->
vertices)
203 Fill(vertexInfo.primaryVertex.local,
208 vertexInfo.primaryVertex.beamlineIndex,
209 vertexInfo.nElectrons,
224 energy = other->energy;
234 weight = other->weight;
235 partID = other->partID;
236 parentID = other->parentID;
237 trackID = other->trackID;
238 modelID = other->modelID;
239 turnNumber = other->turnNumber;
246 theta = other->theta;
253 isIon = other->
isIon;
293 kineticEnergy.clear();
305 std::vector<U> result((
unsigned long)n);
308 for (
int i = 0; i < n; ++i)
309 {result[i] = (U)particleTable->KineticEnergy(partID[i], energy[i]);}
316 std::vector<U> result((
unsigned long)n);
319 for (
int i = 0; i < n; ++i)
320 {result[i] = (U)particleTable->Mass(partID[i]);}
327 std::vector<U> result((
unsigned long)n);
330 for (
int i = 0; i < n; ++i)
331 {result[i] = (U)particleTable->Rigidity(partID[i], energy[i]);}
338 bool useNElectrons = !nElectrons.empty();
339 std::vector<bool> result((
unsigned long)n);
342 for (
int i = 0; i < n; ++i)
344 result[i] = particleTable->IsIon(partID[i]);
346 {result[i] = result[i] || nElectrons[i] > 0;}
354 std::vector<int> result((
unsigned long)n);
357 for (
int i = 0; i < n; ++i)
358 {result[i] = (int)particleTable->IonA(partID[i]);}
365 std::vector<int> result((
unsigned long)n);
368 for (
int i = 0; i < n; ++i)
369 {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.