9 #include "G4VProcess.hh" 10 #include "G4EmProcessSubType.hh" 11 #include "G4LogicalVolumeStore.hh" 12 #include "G4RegionStore.hh" 13 #include "Randomize.hh" 14 #include "G4SystemOfUnits.hh" 15 #include "G4VSolid.hh" 16 #include "G4TransportationManager.hh" 17 #include "G4GammaGeneralProcess.hh" 18 #include "G4LossTableManager.hh" 21 : trackAction(trka), steppingVerbose(
sv) {
25 kmaxGamma =
p.getParameter<
double>(
"GammaThreshold") * CLHEP::MeV;
26 kmaxIon =
p.getParameter<
double>(
"IonThreshold") * CLHEP::MeV;
27 kmaxProton =
p.getParameter<
double>(
"ProtonThreshold") * CLHEP::MeV;
28 kmaxNeutron =
p.getParameter<
double>(
"NeutronThreshold") * CLHEP::MeV;
34 maxTrackTimes =
p.getParameter<std::vector<double> >(
"MaxTrackTimes");
35 maxTimeNames =
p.getParameter<std::vector<std::string> >(
"MaxTimeNames");
37 savePDandCinAll =
p.getUntrackedParameter<
bool>(
"SaveAllPrimaryDecayProductsAndConversions",
true);
38 savePDandCinTracker =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInTracker",
false);
39 savePDandCinCalo =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInCalo",
false);
40 savePDandCinMuon =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInMuon",
false);
43 gRusRoEnerLim =
p.getParameter<
double>(
"RusRoGammaEnergyLimit") * CLHEP::MeV;
44 nRusRoEnerLim =
p.getParameter<
double>(
"RusRoNeutronEnergyLimit") * CLHEP::MeV;
46 gRusRoEcal =
p.getParameter<
double>(
"RusRoEcalGamma");
47 gRusRoHcal =
p.getParameter<
double>(
"RusRoHcalGamma");
53 nRusRoEcal =
p.getParameter<
double>(
"RusRoEcalNeutron");
54 nRusRoHcal =
p.getParameter<
double>(
"RusRoHcalNeutron");
58 nRusRoWorld =
p.getParameter<
double>(
"RusRoWorldNeutron");
69 if (
p.exists(
"TestKillingOptions")) {
73 <<
" *** Activating special test killing options in StackingAction \n" 74 <<
" *** Kill secondaries in Calorimetetrs volume = " <<
killInCalo <<
"\n" 75 <<
" *** Kill electromagnetic secondaries from hadrons in Calorimeters volume= " <<
killInCaloEfH;
81 <<
"StackingAction initiated with" 82 <<
" flag for saving decay products in " 92 <<
" MeV, neutrons below " <<
kmaxNeutron / CLHEP::MeV <<
" MeV and ions" 93 <<
" below " <<
kmaxIon / CLHEP::MeV <<
" MeV";
97 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction kill tracks with " 98 <<
"time larger than " <<
maxTrackTime / CLHEP::ns <<
" ns ";
109 <<
"StackingAction LowDensity regions - kill if E < " <<
limitEnergyForVacuum / CLHEP::MeV <<
" MeV";
113 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Dead regions - kill all secondaries ";
118 <<
"StackingAction: " 119 <<
"Russian Roulette for gamma Elimit(MeV)= " <<
gRusRoEnerLim / CLHEP::MeV <<
"\n" 129 <<
"StackingAction: " 130 <<
"Russian Roulette for neutron Elimit(MeV)= " <<
nRusRoEnerLim / CLHEP::MeV <<
"\n" 140 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Tracker regions: ";
144 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Calo regions: ";
148 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Muon regions: ";
151 worldSolid = G4TransportationManager::GetTransportationManager()
152 ->GetNavigatorForTracking()
160 G4ClassificationOfNewTrack classification = fUrgent;
161 const int pdg = aTrack->GetDefinition()->GetPDGEncoding();
163 auto track =
const_cast<G4Track*
>(aTrack);
164 const G4VProcess* creatorProc = aTrack->GetCreatorProcess();
166 if (creatorProc ==
nullptr && aTrack->GetParentID() != 0) {
168 <<
" TrackID=" << aTrack->GetTrackID() <<
" ParentID=" << aTrack->GetParentID() <<
" " 169 << aTrack->GetDefinition()->GetParticleName() <<
" Ekin(MeV)=" << aTrack->GetKineticEnergy();
171 if (aTrack->GetKineticEnergy() < 0.0) {
173 <<
" TrackID=" << aTrack->GetTrackID() <<
" ParentID=" << aTrack->GetParentID() <<
" " 174 << aTrack->GetDefinition()->GetParticleName() <<
" Ekin(MeV)=" << aTrack->GetKineticEnergy() <<
" creator " 175 << creatorProc->GetProcessName();
178 if (creatorProc ==
nullptr || aTrack->GetParentID() == 0) {
179 if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
180 classification = fKill;
181 }
else if (
worldSolid->Inside(aTrack->GetPosition()) == kOutside) {
182 classification = fKill;
188 const G4Region* reg = aTrack->GetVolume()->GetLogicalVolume()->GetRegion();
189 const double time = aTrack->GetGlobalTime();
192 if (aTrack->GetTrackStatus() == fStopAndKill) {
193 classification = fKill;
194 }
else if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
195 classification = fKill;
200 classification = fKill;
208 classification = fKill;
212 const double ke = aTrack->GetKineticEnergy();
213 G4int subType = (
nullptr != creatorProc) ? creatorProc->GetProcessSubType() : 0;
215 LogDebug(
"SimG4CoreApplication") <<
"##StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " 216 << aTrack->GetParentID() <<
" " << aTrack->GetDefinition()->GetParticleName()
217 <<
" Ekin(MeV)=" << ke / CLHEP::MeV <<
" subType=" << subType <<
" ";
221 classification = fKill;
224 classification = fKill;
226 }
else if (classification != fKill) {
229 classification = fKill;
233 if (
killExtra && classification != fKill) {
234 if (
killHeavy && classification != fKill) {
235 if (((
pdg / 1000000000 == 1) && (((
pdg / 10000) % 100) > 0) && (((
pdg / 10) % 100) > 0) &&
238 classification = fKill;
242 if (
killDeltaRay && classification != fKill && subType == fIonisation) {
243 classification = fKill;
246 classification = fKill;
251 classification = fKill;
257 if (classification != fKill) {
274 if (2112 ==
pdg || 22 ==
pdg) {
275 double currentWeight = aTrack->GetWeight();
277 if (1.0 >= currentWeight) {
321 if (prob < 1.0 && aTrack->GetKineticEnergy() < elim) {
322 if (G4UniformRand() <
prob) {
325 classification = fKill;
330 if (classification != fKill) {
334 <<
"StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " << aTrack->GetParentID()
335 <<
" Type " << aTrack->GetDefinition()->GetParticleName() <<
" Ekin=" << ke / CLHEP::MeV
336 <<
" MeV from process subType=" << subType <<
" as " << classification <<
" Flag: " <<
flag;
344 return classification;
357 const std::vector<G4Region*>* rs = G4RegionStore::GetInstance();
359 for (
auto& reg : *rs) {
360 const G4String&
rname = reg->GetName();
381 for (
unsigned int i = 0;
i <
num; ++
i) {
389 (
rname ==
"BeamPipe" ||
rname ==
"BeamPipeVacuum" ||
rname ==
"TrackerPixelSensRegion" ||
390 rname ==
"TrackerPixelDeadRegion" ||
rname ==
"TrackerDeadRegion" ||
rname ==
"TrackerSensRegion" ||
391 rname ==
"FastTimerRegionBTL" ||
rname ==
"FastTimerRegionETL" ||
rname ==
"FastTimerRegionSensBTL" ||
392 rname ==
"FastTimerRegionSensETL")) {
396 rname ==
"PreshowerRegion" ||
rname ==
"APDRegion" ||
rname ==
"HGCalRegion")) {
400 rname ==
"Muon" ||
rname ==
"MuonSensitive_DT-CSC")) {
403 if (
rname ==
"BeamPipeOutside" ||
rname ==
"BeamPipeVacuum") {
407 if (
rname == (G4String)(dead)) {
427 auto motherInfo =
static_cast<const TrackInformation*
>(mother.GetUserInformation());
429 if (motherInfo->isPrimary()) {
432 }
else if (stype == fGammaConversion) {
440 auto motherInfo =
static_cast<const TrackInformation*
>(mother.GetUserInformation());
444 return (22 != genID && 11 !=
std::abs(genID));
450 auto ptr =
static_cast<const TrackInformation*
>(mother.GetUserInformation());
451 if (ptr->isPrimary()) {
470 for (
unsigned int i = 0;
i < reg.size(); ++
i) {
472 <<
" StackingAction: " <<
word <<
"Region " <<
i <<
". " << reg[
i]->GetName();
Log< level::Info, true > LogVerbatim
G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack) final
StackingAction(const TrackingAction *, const edm::ParameterSet &ps, const CMSSteppingVerbose *)
std::vector< const G4Region * > lowdensRegions
void PrepareNewEvent() override
std::vector< double > maxTrackTimes
bool rrApplicable(const G4Track *, const G4Track &) const
static void secondary(G4Track *aSecondary, const G4Track &mother, int)
const G4Region * regionCastor
const G4Region * regionMuonIron
const G4Track * geant4Track() const
int isItFromPrimary(const G4Track &, int) const
std::vector< const G4Region * > deadRegions
const CMSSteppingVerbose * steppingVerbose
std::vector< const G4Region * > muonRegions
std::vector< std::string > maxTimeNames
const G4Region * regionEcal
void printRegions(const std::vector< const G4Region *> ®, const std::string &word) const
Abs< T >::type abs(const T &t)
bool isItOutOfTimeWindow(const G4Region *, const double &) const
void stackFilled(const G4Track *, bool isKilled) const
bool isThisRegion(const G4Region *, std::vector< const G4Region *> &) const
static void primary(G4Track *aPrimary)
std::vector< std::string > deadRegionNames
const G4Region * regionHcal
std::vector< const G4Region * > maxTimeRegions
double maxTrackTimeForward
const G4String rname[NREG]
const G4Region * regionPreShower
const TrackingAction * trackAction
Log< level::Warning, false > LogWarning
std::vector< const G4Region * > trackerRegions
int isItPrimaryDecayProductOrConversion(const int subtype, const G4Track &) const
std::vector< const G4Region * > caloRegions
double limitEnergyForVacuum
const G4Region * regionWorld