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" 20 : trackAction(trka), steppingVerbose(
sv) {
24 kmaxGamma =
p.getParameter<
double>(
"GammaThreshold") * CLHEP::MeV;
25 kmaxIon =
p.getParameter<
double>(
"IonThreshold") * CLHEP::MeV;
26 kmaxProton =
p.getParameter<
double>(
"ProtonThreshold") * CLHEP::MeV;
27 kmaxNeutron =
p.getParameter<
double>(
"NeutronThreshold") * CLHEP::MeV;
33 maxTrackTimes =
p.getParameter<std::vector<double> >(
"MaxTrackTimes");
34 maxTimeNames =
p.getParameter<std::vector<std::string> >(
"MaxTimeNames");
36 savePDandCinAll =
p.getUntrackedParameter<
bool>(
"SaveAllPrimaryDecayProductsAndConversions",
true);
37 savePDandCinTracker =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInTracker",
false);
38 savePDandCinCalo =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInCalo",
false);
39 savePDandCinMuon =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInMuon",
false);
52 gRusRoEnerLim =
p.getParameter<
double>(
"RusRoGammaEnergyLimit") * CLHEP::MeV;
53 nRusRoEnerLim =
p.getParameter<
double>(
"RusRoNeutronEnergyLimit") * CLHEP::MeV;
55 gRusRoEcal =
p.getParameter<
double>(
"RusRoEcalGamma");
56 gRusRoHcal =
p.getParameter<
double>(
"RusRoHcalGamma");
62 nRusRoEcal =
p.getParameter<
double>(
"RusRoEcalNeutron");
63 nRusRoHcal =
p.getParameter<
double>(
"RusRoHcalNeutron");
67 nRusRoWorld =
p.getParameter<
double>(
"RusRoWorldNeutron");
80 if (
p.exists(
"TestKillingOptions")) {
84 <<
" *** Activating special test killing options in StackingAction \n" 85 <<
" *** Kill secondaries in Calorimetetrs volume = " <<
killInCalo <<
"\n" 86 <<
" *** Kill electromagnetic secondaries from hadrons in Calorimeters volume= " <<
killInCaloEfH;
93 <<
"StackingAction initiated with" 94 <<
" flag for saving decay products in " 104 <<
" MeV, neutrons below " <<
kmaxNeutron / CLHEP::MeV <<
" MeV and ions" 105 <<
" below " <<
kmaxIon / CLHEP::MeV <<
" MeV";
109 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction kill tracks with " 110 <<
"time larger than " <<
maxTrackTime / CLHEP::ns <<
" ns ";
121 <<
"StackingAction LowDensity regions - kill if E < " <<
limitEnergyForVacuum / CLHEP::MeV <<
" MeV";
125 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Dead regions - kill all secondaries ";
130 <<
"StackingAction: " 131 <<
"Russian Roulette for gamma Elimit(MeV)= " <<
gRusRoEnerLim / CLHEP::MeV <<
"\n" 141 <<
"StackingAction: " 142 <<
"Russian Roulette for neutron Elimit(MeV)= " <<
nRusRoEnerLim / CLHEP::MeV <<
"\n" 152 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Tracker regions: ";
156 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Calo regions: ";
160 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Muon regions: ";
163 worldSolid = G4TransportationManager::GetTransportationManager()
164 ->GetNavigatorForTracking()
174 G4ClassificationOfNewTrack classification = fUrgent;
175 const int pdg = aTrack->GetDefinition()->GetPDGEncoding();
177 auto track =
const_cast<G4Track*
>(aTrack);
180 if (aTrack->GetCreatorProcess() ==
nullptr || aTrack->GetParentID() == 0) {
181 if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
182 classification = fKill;
183 }
else if (
worldSolid->Inside(aTrack->GetPosition()) == kOutside) {
184 classification = fKill;
190 const G4Region* reg = aTrack->GetVolume()->GetLogicalVolume()->GetRegion();
191 const double time = aTrack->GetGlobalTime();
194 if (aTrack->GetTrackStatus() == fStopAndKill) {
195 classification = fKill;
196 }
else if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
197 classification = fKill;
202 classification = fKill;
210 classification = fKill;
214 const double ke = aTrack->GetKineticEnergy();
215 auto proc = aTrack->GetCreatorProcess();
216 G4int subType =
proc->GetProcessSubType();
218 auto ptr =
static_cast<const G4GammaGeneralProcess*
>(
proc);
219 proc = ptr->GetSelectedProcess();
220 subType =
proc->GetProcessSubType();
223 LogDebug(
"SimG4CoreApplication") <<
"##StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " 224 << aTrack->GetParentID() <<
" " << aTrack->GetDefinition()->GetParticleName()
225 <<
" Ekin(MeV)=" << ke / CLHEP::MeV <<
" subType=" << subType <<
" " 226 <<
proc->GetProcessName();
230 classification = fKill;
233 classification = fKill;
235 }
else if (classification != fKill) {
238 classification = fKill;
242 if (
killExtra && classification != fKill) {
243 if (
killHeavy && classification != fKill) {
244 if (((
pdg / 1000000000 == 1) && (((
pdg / 10000) % 100) > 0) && (((
pdg / 10) % 100) > 0) &&
247 classification = fKill;
252 aTrack->GetCreatorProcess()->GetProcessSubType() == fIonisation) {
253 classification = fKill;
256 classification = fKill;
261 classification = fKill;
267 if (classification != fKill) {
284 if (2112 ==
pdg || 22 ==
pdg) {
285 double currentWeight = aTrack->GetWeight();
287 if (1.0 >= currentWeight) {
331 if (prob < 1.0 && aTrack->GetKineticEnergy() < elim) {
332 if (G4UniformRand() <
prob) {
335 classification = fKill;
340 if (classification != fKill) {
344 <<
"StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " << aTrack->GetParentID()
345 <<
" Type " << aTrack->GetDefinition()->GetParticleName() <<
" Ekin=" << ke / CLHEP::MeV
346 <<
" MeV from process " <<
proc->GetProcessName() <<
" subType=" << subType <<
" as " << classification
347 <<
" Flag: " <<
flag;
355 return classification;
368 const std::vector<G4Region*>* rs = G4RegionStore::GetInstance();
370 for (
auto& reg : *rs) {
371 const G4String&
rname = reg->GetName();
392 for (
unsigned int i = 0;
i <
num; ++
i) {
400 (
rname ==
"BeamPipe" ||
rname ==
"BeamPipeVacuum" ||
rname ==
"TrackerPixelSensRegion" ||
401 rname ==
"TrackerPixelDeadRegion" ||
rname ==
"TrackerDeadRegion" ||
rname ==
"TrackerSensRegion" ||
402 rname ==
"FastTimerRegion" ||
rname ==
"FastTimerRegionSensBTL" ||
rname ==
"FastTimerRegionSensETL")) {
406 rname ==
"PreshowerRegion" ||
rname ==
"APDRegion" ||
rname ==
"HGCalRegion")) {
410 rname ==
"Muon" ||
rname ==
"MuonSensitive_DT-CSC")) {
413 if (
rname ==
"BeamPipeOutside" ||
rname ==
"BeamPipeVacuum") {
417 if (
rname == (G4String)(dead)) {
440 if (aTrack->GetCreatorProcess()->GetProcessType() ==
fDecay) {
442 }
else if (aTrack->GetCreatorProcess()->GetProcessSubType() == fGammaConversion) {
454 return (22 != genID && 11 !=
std::abs(genID));
480 for (
unsigned int i = 0;
i < reg.size(); ++
i) {
482 <<
" 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
TrackInformationExtractor extractor
bool rrApplicable(const G4Track *, const G4Track &) const
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
~StackingAction() override
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 secondary(const G4Track *aSecondary, const G4Track &mother, int) const
int isItPrimaryDecayProductOrConversion(const G4Track *, const G4Track &) const
bool isThisRegion(const G4Region *, std::vector< const G4Region *> &) const
void primary(const G4Track *aSecondary) const
std::vector< std::string > deadRegionNames
const G4Region * regionHcal
std::vector< const G4Region * > maxTimeRegions
double maxTrackTimeForward
const G4String rname[NREG]
void StackFilled(const G4Track *, bool isKilled) const
const G4Region * regionPreShower
const TrackingAction * trackAction
Log< level::Warning, false > LogWarning
std::vector< const G4Region * > trackerRegions
std::vector< const G4Region * > caloRegions
double limitEnergyForVacuum
const G4Region * regionWorld