10 #include "G4VProcess.hh" 11 #include "G4EmProcessSubType.hh" 12 #include "G4LogicalVolumeStore.hh" 13 #include "G4RegionStore.hh" 14 #include "Randomize.hh" 15 #include "G4SystemOfUnits.hh" 16 #include "G4VSolid.hh" 17 #include "G4TransportationManager.hh" 18 #include "G4GammaGeneralProcess.hh" 19 #include "G4LossTableManager.hh" 22 : trackAction(trka), steppingVerbose(
sv) {
26 kmaxGamma =
p.getParameter<
double>(
"GammaThreshold") * CLHEP::MeV;
27 kmaxIon =
p.getParameter<
double>(
"IonThreshold") * CLHEP::MeV;
28 kmaxProton =
p.getParameter<
double>(
"ProtonThreshold") * CLHEP::MeV;
29 kmaxNeutron =
p.getParameter<
double>(
"NeutronThreshold") * CLHEP::MeV;
35 maxTrackTimes =
p.getParameter<std::vector<double> >(
"MaxTrackTimes");
36 maxTimeNames =
p.getParameter<std::vector<std::string> >(
"MaxTimeNames");
38 savePDandCinAll =
p.getUntrackedParameter<
bool>(
"SaveAllPrimaryDecayProductsAndConversions",
true);
39 savePDandCinTracker =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInTracker",
false);
40 savePDandCinCalo =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInCalo",
false);
41 savePDandCinMuon =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInMuon",
false);
44 gRusRoEnerLim =
p.getParameter<
double>(
"RusRoGammaEnergyLimit") * CLHEP::MeV;
45 nRusRoEnerLim =
p.getParameter<
double>(
"RusRoNeutronEnergyLimit") * CLHEP::MeV;
47 gRusRoEcal =
p.getParameter<
double>(
"RusRoEcalGamma");
48 gRusRoHcal =
p.getParameter<
double>(
"RusRoHcalGamma");
54 nRusRoEcal =
p.getParameter<
double>(
"RusRoEcalNeutron");
55 nRusRoHcal =
p.getParameter<
double>(
"RusRoHcalNeutron");
59 nRusRoWorld =
p.getParameter<
double>(
"RusRoWorldNeutron");
61 gRusRoZDC =
p.getParameter<
double>(
"RusRoZDCGamma");
63 nRusRoZDC =
p.getParameter<
double>(
"RusRoZDCNeutron");
64 nRusRoHGcal =
p.getParameter<
double>(
"RusRoHGcalNeutron");
75 if (
p.exists(
"TestKillingOptions")) {
79 <<
" *** Activating special test killing options in StackingAction \n" 80 <<
" *** Kill secondaries in Calorimetetrs volume = " <<
killInCalo <<
"\n" 81 <<
" *** Kill electromagnetic secondaries from hadrons in Calorimeters volume= " <<
killInCaloEfH;
87 <<
"StackingAction initiated with" 88 <<
" flag for saving decay products in " 98 <<
" MeV, neutrons below " <<
kmaxNeutron / CLHEP::MeV <<
" MeV and ions" 99 <<
" below " <<
kmaxIon / CLHEP::MeV <<
" MeV";
103 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction kill tracks with " 104 <<
"time larger than " <<
maxTrackTime / CLHEP::ns <<
" ns ";
115 <<
"StackingAction LowDensity regions - kill if E < " <<
limitEnergyForVacuum / CLHEP::MeV <<
" MeV";
119 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Dead regions - kill all secondaries ";
124 <<
"StackingAction: " 125 <<
"Russian Roulette for gamma Elimit(MeV)= " <<
gRusRoEnerLim / CLHEP::MeV <<
"\n" 137 <<
"StackingAction: " 138 <<
"Russian Roulette for neutron Elimit(MeV)= " <<
nRusRoEnerLim / CLHEP::MeV <<
"\n" 150 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Tracker regions: ";
154 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Calo regions: ";
158 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Muon regions: ";
161 worldSolid = G4TransportationManager::GetTransportationManager()
162 ->GetNavigatorForTracking()
170 G4ClassificationOfNewTrack classification = fUrgent;
171 const int pdg = aTrack->GetDefinition()->GetPDGEncoding();
173 auto track =
const_cast<G4Track*
>(aTrack);
174 const G4VProcess* creatorProc = aTrack->GetCreatorProcess();
176 if (creatorProc ==
nullptr && aTrack->GetParentID() != 0) {
178 <<
" TrackID=" << aTrack->GetTrackID() <<
" ParentID=" << aTrack->GetParentID() <<
" " 179 << aTrack->GetDefinition()->GetParticleName() <<
" Ekin(MeV)=" << aTrack->GetKineticEnergy();
181 if (aTrack->GetKineticEnergy() < 0.0) {
183 <<
" TrackID=" << aTrack->GetTrackID() <<
" ParentID=" << aTrack->GetParentID() <<
" " 184 << aTrack->GetDefinition()->GetParticleName() <<
" Ekin(MeV)=" << aTrack->GetKineticEnergy() <<
" creator " 185 << creatorProc->GetProcessName();
188 if (creatorProc ==
nullptr || aTrack->GetParentID() == 0) {
189 if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
190 classification = fKill;
191 }
else if (
worldSolid->Inside(aTrack->GetPosition()) == kOutside) {
192 classification = fKill;
198 const G4Region* reg = aTrack->GetVolume()->GetLogicalVolume()->GetRegion();
199 const double time = aTrack->GetGlobalTime();
202 if (aTrack->GetTrackStatus() == fStopAndKill) {
203 classification = fKill;
204 }
else if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
205 classification = fKill;
210 classification = fKill;
218 classification = fKill;
222 const double ke = aTrack->GetKineticEnergy();
223 G4int subType = (
nullptr != creatorProc) ? creatorProc->GetProcessSubType() : 0;
225 LogDebug(
"SimG4CoreApplication") <<
"##StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " 226 << aTrack->GetParentID() <<
" " << aTrack->GetDefinition()->GetParticleName()
227 <<
" Ekin(MeV)=" << ke / CLHEP::MeV <<
" subType=" << subType <<
" ";
231 classification = fKill;
234 classification = fKill;
236 }
else if (classification != fKill) {
239 classification = fKill;
243 if (
killExtra && classification != fKill) {
244 if (
killHeavy && classification != fKill) {
245 if (((
pdg / 1000000000 == 1) && (((
pdg / 10000) % 100) > 0) && (((
pdg / 10) % 100) > 0) &&
248 classification = fKill;
252 if (
killDeltaRay && classification != fKill && aTrack->GetParentID() > 0 &&
254 classification = fKill;
258 classification = fKill;
263 classification = fKill;
269 if (classification != fKill) {
286 if (2112 ==
pdg || 22 ==
pdg) {
287 double currentWeight = aTrack->GetWeight();
289 if (1.0 >= currentWeight) {
341 if (prob < 1.0 && aTrack->GetKineticEnergy() < elim) {
342 if (G4UniformRand() <
prob) {
345 classification = fKill;
350 if (classification != fKill) {
354 <<
"StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " << aTrack->GetParentID()
355 <<
" Type " << aTrack->GetDefinition()->GetParticleName() <<
" Ekin=" << ke / CLHEP::MeV
356 <<
" MeV from process subType=" << subType <<
" as " << classification <<
" Flag: " <<
flag;
364 return classification;
377 const std::vector<G4Region*>* rs = G4RegionStore::GetInstance();
379 for (
auto& reg : *rs) {
380 const G4String&
rname = reg->GetName();
407 for (
unsigned int i = 0;
i <
num; ++
i) {
415 (
rname ==
"BeamPipe" ||
rname ==
"BeamPipeVacuum" ||
rname ==
"TrackerPixelSensRegion" ||
416 rname ==
"TrackerPixelDeadRegion" ||
rname ==
"TrackerDeadRegion" ||
rname ==
"TrackerSensRegion" ||
417 rname ==
"FastTimerRegionBTL" ||
rname ==
"FastTimerRegionETL" ||
rname ==
"FastTimerRegionSensBTL" ||
418 rname ==
"FastTimerRegionSensETL")) {
422 rname ==
"PreshowerRegion" ||
rname ==
"APDRegion" ||
rname ==
"HGCalRegion")) {
426 rname ==
"Muon" ||
rname ==
"MuonSensitive_DT-CSC")) {
429 if (
rname ==
"BeamPipeOutside" ||
rname ==
"BeamPipeVacuum") {
433 if (
rname == (G4String)(dead)) {
453 auto motherInfo =
static_cast<const TrackInformation*
>(mother.GetUserInformation());
455 if (motherInfo->isPrimary()) {
458 }
else if (stype == fGammaConversion) {
466 auto motherInfo =
static_cast<const TrackInformation*
>(mother.GetUserInformation());
470 return (22 != genID && 11 !=
std::abs(genID));
476 auto ptr =
static_cast<const TrackInformation*
>(mother.GetUserInformation());
477 if (ptr->isPrimary()) {
496 for (
unsigned int i = 0;
i < reg.size(); ++
i) {
498 <<
" 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
const G4Region * regionZDC
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
const G4Region * regionHGcal
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]
static bool isGammaElectronPositron(int pdgCode)
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