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();
179 if (aTrack->GetCreatorProcess() ==
nullptr || aTrack->GetParentID() == 0) {
180 if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
181 classification = fKill;
182 }
else if (
worldSolid->Inside(aTrack->GetPosition()) == kOutside) {
183 classification = fKill;
189 const G4Region* reg = aTrack->GetVolume()->GetLogicalVolume()->GetRegion();
190 const double time = aTrack->GetGlobalTime();
193 if (aTrack->GetTrackStatus() == fStopAndKill) {
194 classification = fKill;
195 }
else if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
196 classification = fKill;
201 classification = fKill;
209 classification = fKill;
213 const double ke = aTrack->GetKineticEnergy();
214 auto proc = aTrack->GetCreatorProcess();
215 G4int subType =
proc->GetProcessSubType();
217 auto ptr =
static_cast<const G4GammaGeneralProcess*
>(
proc);
218 proc = ptr->GetSelectedProcess();
219 subType =
proc->GetProcessSubType();
220 const_cast<G4Track*
>(aTrack)->SetCreatorProcess(
proc);
222 LogDebug(
"SimG4CoreApplication") <<
"##StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " 223 << aTrack->GetParentID() <<
" " << aTrack->GetDefinition()->GetParticleName()
224 <<
" Ekin(MeV)=" << ke / CLHEP::MeV <<
" subType=" << subType <<
" " 225 <<
proc->GetProcessName();
229 classification = fKill;
232 classification = fKill;
234 }
else if (classification != fKill) {
237 classification = fKill;
241 if (
killExtra && classification != fKill) {
242 if (
killHeavy && classification != fKill) {
243 if (((
pdg / 1000000000 == 1) && (((
pdg / 10000) % 100) > 0) && (((
pdg / 10) % 100) > 0) &&
246 classification = fKill;
251 aTrack->GetCreatorProcess()->GetProcessSubType() == fIonisation) {
252 classification = fKill;
255 classification = fKill;
260 classification = fKill;
266 if (classification != fKill) {
283 if (2112 ==
pdg || 22 ==
pdg) {
284 double currentWeight = aTrack->GetWeight();
286 if (1.0 >= currentWeight) {
330 if (prob < 1.0 && aTrack->GetKineticEnergy() < elim) {
331 if (G4UniformRand() <
prob) {
332 const_cast<G4Track*
>(aTrack)->SetWeight(currentWeight /
prob);
334 classification = fKill;
339 if (classification != fKill) {
343 <<
"StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " << aTrack->GetParentID()
344 <<
" Type " << aTrack->GetDefinition()->GetParticleName() <<
" Ekin=" << ke / CLHEP::MeV
345 <<
" MeV from process " <<
proc->GetProcessName() <<
" subType=" << subType <<
" as " << classification
346 <<
" Flag: " <<
flag;
354 return classification;
367 const std::vector<G4Region*>* rs = G4RegionStore::GetInstance();
369 for (
auto& reg : *rs) {
370 const G4String&
rname = reg->GetName();
391 for (
unsigned int i = 0;
i <
num; ++
i) {
399 (
rname ==
"BeamPipe" ||
rname ==
"BeamPipeVacuum" ||
rname ==
"TrackerPixelSensRegion" ||
400 rname ==
"TrackerPixelDeadRegion" ||
rname ==
"TrackerDeadRegion" ||
rname ==
"TrackerSensRegion" ||
401 rname ==
"FastTimerRegion" ||
rname ==
"FastTimerRegionSensBTL" ||
rname ==
"FastTimerRegionSensETL")) {
405 rname ==
"PreshowerRegion" ||
rname ==
"APDRegion" ||
rname ==
"HGCalRegion")) {
409 rname ==
"Muon" ||
rname ==
"MuonSensitive_DT-CSC")) {
412 if (
rname ==
"BeamPipeOutside" ||
rname ==
"BeamPipeVacuum") {
416 if (
rname == (G4String)(dead)) {
439 if (aTrack->GetCreatorProcess()->GetProcessType() ==
fDecay) {
441 }
else if (aTrack->GetCreatorProcess()->GetProcessSubType() == fGammaConversion) {
453 return (22 != genID && 11 !=
std::abs(genID));
479 for (
unsigned int i = 0;
i < reg.size(); ++
i) {
481 <<
" 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