Skip to content

Commit f3710d0

Browse files
committed
SIM: fixed simulation of hits in ZDC
1 parent 7d99d30 commit f3710d0

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

SimG4Core/Application/interface/SteppingAction.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class SteppingAction : public G4UserSteppingAction {
3737

3838
const G4VPhysicalVolume* tracker{nullptr};
3939
const G4VPhysicalVolume* calo{nullptr};
40-
const CMSSteppingVerbose* steppingVerbose;
40+
const CMSSteppingVerbose* steppingVerbose{nullptr};
41+
const G4LogicalVolume* m_CMStoZDC{nullptr};
4142
double theCriticalEnergyForVacuum;
4243
double theCriticalDensity;
4344
double maxTrackTime;
@@ -66,7 +67,7 @@ class SteppingAction : public G4UserSteppingAction {
6667

6768
inline bool SteppingAction::isInsideDeadRegion(const G4Region* reg) const {
6869
bool res = false;
69-
for (auto& region : deadRegions) {
70+
for (auto const& region : deadRegions) {
7071
if (reg == region) {
7172
res = true;
7273
break;

SimG4Core/Application/src/SteppingAction.cc

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,18 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) {
8888

8989
G4Track* theTrack = aStep->GetTrack();
9090
TrackStatus tstat = (theTrack->GetTrackStatus() == fAlive) ? sAlive : sKilledByProcess;
91+
const double ekin = theTrack->GetKineticEnergy();
9192

92-
if (theTrack->GetKineticEnergy() < 0.0) {
93+
if (ekin < 0.0) {
9394
if (nWarnings < 2) {
9495
++nWarnings;
9596
edm::LogWarning("SimG4CoreApplication")
9697
<< "SteppingAction::UserSteppingAction: Track #" << theTrack->GetTrackID() << " "
97-
<< theTrack->GetDefinition()->GetParticleName() << " Ekin(MeV)= " << theTrack->GetKineticEnergy() / MeV;
98+
<< theTrack->GetDefinition()->GetParticleName() << " Ekin(MeV)=" << ekin;
9899
}
99100
theTrack->SetKineticEnergy(0.0);
100101
}
101102

102-
const G4StepPoint* preStep = aStep->GetPreStepPoint();
103-
const G4StepPoint* postStep = aStep->GetPostStepPoint();
104-
105103
// the track is killed by the process
106104
if (tstat == sKilledByProcess) {
107105
if (nullptr != steppingVerbose) {
@@ -110,17 +108,20 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) {
110108
return;
111109
}
112110

111+
const G4StepPoint* preStep = aStep->GetPreStepPoint();
112+
const G4StepPoint* postStep = aStep->GetPostStepPoint();
113113
if (sAlive == tstat && theTrack->GetCurrentStepNumber() > maxNumberOfSteps) {
114114
tstat = sNumberOfSteps;
115115
if (nWarnings < 5) {
116116
++nWarnings;
117117
edm::LogWarning("SimG4CoreApplication")
118118
<< "Track #" << theTrack->GetTrackID() << " " << theTrack->GetDefinition()->GetParticleName()
119-
<< " E(MeV)= " << preStep->GetKineticEnergy() / MeV << " Nstep= " << theTrack->GetCurrentStepNumber()
120-
<< " is killed due to limit on number of steps;/n PV: " << preStep->GetPhysicalVolume()->GetName() << " at "
121-
<< theTrack->GetPosition() << " StepLen(mm)= " << aStep->GetStepLength();
119+
<< " E(MeV)=" << ekin << " Nstep=" << theTrack->GetCurrentStepNumber()
120+
<< " is killed due to limit on number of steps;/n PV:" << preStep->GetPhysicalVolume()->GetName() << " at "
121+
<< theTrack->GetPosition() << " StepLen(mm)=" << aStep->GetStepLength();
122122
}
123123
}
124+
124125
const double time = theTrack->GetGlobalTime();
125126

126127
// check Z-coordinate
@@ -129,13 +130,13 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) {
129130
}
130131

131132
// check G4Region
132-
if (sAlive == tstat) {
133+
if (sAlive == tstat || sVeryForward == tstat) {
133134
// next logical volume and next region
134135
const G4LogicalVolume* lv = postStep->GetPhysicalVolume()->GetLogicalVolume();
135136
const G4Region* theRegion = lv->GetRegion();
136137

137138
// kill in dead regions
138-
if (isInsideDeadRegion(theRegion))
139+
if (lv != m_CMStoZDC && isInsideDeadRegion(theRegion))
139140
tstat = sDeadRegion;
140141

141142
// kill out of time
@@ -152,8 +153,8 @@ void SteppingAction::UserSteppingAction(const G4Step* aStep) {
152153

153154
// kill low-energy in vacuum
154155
if (sAlive == tstat && killBeamPipe) {
155-
if (theTrack->GetKineticEnergy() < theCriticalEnergyForVacuum &&
156-
theTrack->GetDefinition()->GetPDGCharge() != 0.0 && lv->GetMaterial()->GetDensity() <= theCriticalDensity) {
156+
if (ekin < theCriticalEnergyForVacuum && theTrack->GetDefinition()->GetPDGCharge() != 0.0 &&
157+
lv->GetMaterial()->GetDensity() <= theCriticalDensity) {
157158
tstat = sLowEnergyInVacuum;
158159
}
159160
}
@@ -183,7 +184,7 @@ bool SteppingAction::isLowEnergy(const G4LogicalVolume* lv, const G4Track* theTr
183184
const double ekin = theTrack->GetKineticEnergy();
184185
int pCode = theTrack->GetDefinition()->GetPDGEncoding();
185186

186-
for (auto& vol : ekinVolumes) {
187+
for (auto const& vol : ekinVolumes) {
187188
if (lv == vol) {
188189
for (unsigned int i = 0; i < numberPart; ++i) {
189190
if (pCode == ekinPDG[i]) {
@@ -208,25 +209,27 @@ bool SteppingAction::initPointer() {
208209
if (tracker && calo)
209210
break;
210211
}
211-
edm::LogVerbatim("SimG4CoreApplication")
212-
<< "SteppingAction: pointer for Tracker " << tracker << " and for Calo " << calo;
213212

214213
const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
215-
if (numberEkins > 0) {
216-
ekinVolumes.resize(numberEkins, nullptr);
217-
for (auto const& lvcite : *lvs) {
218-
const G4String& lvname = lvcite->GetName();
219-
for (unsigned int i = 0; i < numberEkins; ++i) {
220-
if (lvname == (G4String)(ekinNames[i])) {
221-
ekinVolumes[i] = lvcite;
222-
break;
223-
}
224-
}
214+
215+
ekinVolumes.resize(numberEkins, nullptr);
216+
for (auto const& lvcite : *lvs) {
217+
const G4String& lvname = lvcite->GetName();
218+
if (lvname == "CMStoZDC") {
219+
m_CMStoZDC = lvcite;
225220
}
226221
for (unsigned int i = 0; i < numberEkins; ++i) {
227-
edm::LogVerbatim("SimG4CoreApplication") << ekinVolumes[i]->GetName() << " with pointer " << ekinVolumes[i];
222+
if (lvname == (G4String)(ekinNames[i])) {
223+
ekinVolumes[i] = lvcite;
224+
break;
225+
}
228226
}
229227
}
228+
edm::LogVerbatim("SimG4CoreApplication")
229+
<< "SteppingAction: pointer for Tracker: " << tracker << "; Calo: " << calo << "; to CMStoZDC: " << m_CMStoZDC;
230+
for (unsigned int i = 0; i < numberEkins; ++i) {
231+
edm::LogVerbatim("SimG4CoreApplication") << ekinVolumes[i]->GetName() << " with pointer " << ekinVolumes[i];
232+
}
230233

231234
if (numberPart > 0) {
232235
G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();

0 commit comments

Comments
 (0)