12 #include <G4EventManager.hh> 14 #include <G4VTrajectory.hh> 15 #include <G4VTrajectoryPoint.hh> 16 #include <G4TrajectoryContainer.hh> 17 #include <G4TouchableHandle.hh> 20 #include <G4UnitsTable.hh> 21 #include <G4VisAttributes.hh> 22 #include <G4VVisManager.hh> 23 #include <G4Polyline.hh> 26 #include <G4SystemOfUnits.hh> 27 #include <G4PhysicalConstants.hh> 37 : fMaxSagitta(maxSagitta), fMaxLength(maxLength),
38 fPrimaryId(0), fEnergyDeposit(0), fSecondaryDeposit(0), fTrackLength(0),
39 fStart(0,0,0,0), fStop(0,0,0,0) {
57 G4TouchableHandle touchable
58 = theStep->GetPreStepPoint()->GetTouchableHandle();
63 int trackId = theStep->GetTrack()->GetTrackID();
67 = (theStep->GetPostStepPoint()->GetPosition() -
fPath.front()).
mag();
72 const double epsilon = 0.01;
73 double deltaT =
std::abs(theStep->GetPostStepPoint()->GetGlobalTime()
105 G4TouchableHandle touchable
106 = theStep->GetPreStepPoint()->GetTouchableHandle();
107 G4ThreeVector prePos = theStep->GetPreStepPoint()->GetPosition();
108 G4ThreeVector postPos = theStep->GetPostStepPoint()->GetPosition();
109 G4StepStatus stepStatus = theStep->GetPostStepPoint()->GetStepStatus();
110 G4ParticleDefinition* particle = theStep->GetTrack()->GetDefinition();
111 double energyDeposit = theStep->GetTotalEnergyDeposit();
112 double stepLength = (prePos-postPos).
mag();
113 double trackLength = theStep->GetStepLength();
114 double nonIonizingDeposit = theStep->GetNonIonizingEnergyDeposit();
116 if (trackLength < 0.75*stepLength || trackLength < stepLength - 1*
mm) {
118 << trackLength/
mm <<
" mm " 119 <<
"<" << stepLength/
mm <<
" mm");
121 << theStep->GetTrack()->GetVolume()->GetName());
122 EDepSimWarn(
" Particle: " << particle->GetParticleName()
123 <<
" Depositing " << energyDeposit/
MeV <<
" MeV");
125 << theStep->GetTrack()->GetTotalEnergy());
128 trackLength =
std::max(trackLength,stepLength);
131 <<
" in " << theStep->GetTrack()->GetVolume()->GetName());
133 if (energyDeposit <= 0.) {
134 EDepSimWarn(
"EDepSim::HitSegment:: No energy deposited: " << energyDeposit);
137 if (trackLength <= 0.) {
138 EDepSimWarn(
"EDepSim::HitSegment:: No track length: " << trackLength);
144 if (stepStatus == fPostStepDoItProc
145 &&
std::abs(particle->GetPDGCharge()) < 0.1) {
146 double origStep = stepLength;
147 G4ThreeVector
dir = (postPos - prePos).unit();
148 stepLength = trackLength =
std::min(0.5*
mm,0.8*origStep);
149 prePos = postPos - stepLength*
mm*
dir;
150 EDepSimDebug(
"EDepSim::HitSegment:: " << particle->GetParticleName()
151 <<
" Deposited " << energyDeposit/
MeV <<
" MeV");
157 G4Track*
trk = theStep->GetTrack();
159 << trk->GetVolume()->GetName());
162 <<
" mm and track length is " 163 << trackLength/
mm <<
" mm");
165 EDepSimWarn(
" PID: " << particle->GetParticleName()
166 <<
" E: " << trk->GetTotalEnergy()/
MeV <<
" MeV" 167 <<
" (kin: " << trk->GetKineticEnergy()/
MeV <<
" MeV" 169 << energyDeposit/
MeV <<
"MeV" 170 <<
" Status: " << theStep->GetPreStepPoint()->GetStepStatus()
171 <<
" -> " << theStep->GetPostStepPoint()->GetStepStatus());
173 const G4VProcess* proc = theStep->GetPostStepPoint()
174 ->GetProcessDefinedStep();
180 <<
"/"<< proc->GetProcessTypeName(proc->GetProcessType()));
188 fStart.set(prePos.x(),prePos.y(),prePos.z(),
189 theStep->GetPreStepPoint()->GetGlobalTime());
191 fStop.set(postPos.x(),postPos.y(),postPos.z(),
192 theStep->GetPostStepPoint()->GetGlobalTime());
198 int trackId = theStep->GetTrack()->GetTrackID();
204 fStop.set(postPos.x(),postPos.y(),postPos.z(),
205 theStep->GetPostStepPoint()->GetGlobalTime());
214 EDepSimDebug(
"EDepSim::HitSegment:: Deposit " << particle->GetParticleName()
215 <<
" adds " << energyDeposit/
MeV <<
" MeV" 218 <<
" L " << trackLength
223 const G4ThreeVector& point =
fPath.back();
224 const G4ThreeVector& preStep = theStep->GetPreStepPoint()->GetPosition();
228 if ((point-preStep).
mag()>0.01*
mm)
return 10*
m;
230 const G4ThreeVector& postStep = theStep->GetPostStepPoint()->GetPosition();
232 G4ThreeVector newDir = (postStep-point).unit();
235 double maxSagitta = 0.0;
237 G4ThreeVector& front =
fPath.front();
244 G4ThreeVector delta = ((*p)-front);
245 double dist = (delta*newDir);
246 maxSagitta =
std::max(maxSagitta,(delta - dist*newDir).
mag());
254 G4ThreeVector& front =
fPath.front();
255 const G4ThreeVector& back =
fPath.back();
256 const G4ThreeVector& preStep = theStep->GetPreStepPoint()->GetPosition();
257 const G4ThreeVector& postStep = theStep->GetPostStepPoint()->GetPosition();
258 G4ThreeVector
dir = (back-front).unit();
262 if ((preStep-back)*dir>0.0)
return 1000*
m;
266 G4ThreeVector frontDelta = preStep-front;
267 double cosDelta = frontDelta*
dir;
268 if (cosDelta<0.0)
return 1000*
m;
272 double s1 = (frontDelta - cosDelta*
dir).
mag();
277 G4ThreeVector rearDelta = postStep-front;
278 cosDelta = rearDelta*
dir;
279 double s2 = (rearDelta - cosDelta*
dir).
mag();
285 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
290 G4Color
color(1.,0.,1.);
291 G4VisAttributes attribs(color);
292 line.SetVisAttributes(attribs);
293 pVVisManager->Draw(line);
298 std::cout <<
"Hit Energy Deposit: " G4Allocator< EDepSim::HitSegment > edepHitSegmentAllocator
double fEnergyDeposit
The total energy deposit in this hit.
HitSegment(double maxSagitta=1 *CLHEP::mm, double maxLength=5 *CLHEP::mm)
virtual double GetLength() const
static int FindPrimaryId(int trackId)
int fPrimaryId
The track id of the primary particle.
static constexpr double MeV
std::vector< int > fContributors
virtual bool SameHit(G4Step *theStep)
G4LorentzVector fStart
The starting position of the segment.
double fMaxSagitta
The sagitta tolerance for the segment.
std::vector< G4ThreeVector > fPath
double fMaxLength
The maximum length between the start and stop points of the segment.
#define EDepSimTrace(outStream)
#define EDepSimDebug(outStream)
static int max(int a, int b)
double FindSeparation(G4Step *theStep)
int FindPrimaryId(G4Track *theTrack)
std::size_t color(std::string const &procname)
G4LorentzVector fStop
The stopping position of the segment.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
#define EDepSimWarn(outStream)
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
void line(double t, double *p, double &x, double &y, double &z)
static constexpr double mm
EDepSim::VolumeId fHitVolume
The G4 physical volume that contains the hit.
double FindSagitta(G4Step *theStep)
QTextStream & endl(QTextStream &s)
virtual void AddStep(G4Step *theStep)
Add the effects of a part of a step to this hit.