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"
19 : trackAction(trka), steppingVerbose(sv) {
70 if (
gRusRoEnerLim > 0.0 && (gRusRoEcal < 1.0 || gRusRoHcal < 1.0 || gRusRoMuonIron < 1.0 || gRusRoPreShower < 1.0 ||
71 gRusRoCastor < 1.0 || gRusRoWorld < 1.0)) {
74 if (nRusRoEnerLim > 0.0 && (nRusRoEcal < 1.0 || nRusRoHcal < 1.0 || nRusRoMuonIron < 1.0 || nRusRoPreShower < 1.0 ||
75 nRusRoCastor < 1.0 || nRusRoWorld < 1.0)) {
79 if (p.
exists(
"TestKillingOptions")) {
83 <<
" *** Activating special test killing options in StackingAction \n"
84 <<
" *** Kill secondaries in Calorimetetrs volume = " << killInCalo <<
"\n"
85 <<
" *** Kill electromagnetic secondaries from hadrons in Calorimeters volume= " <<
killInCaloEfH;
92 <<
"StackingAction initiated with"
93 <<
" flag for saving decay products in "
94 <<
" Tracker: " << savePDandCinTracker <<
" in Calo: " << savePDandCinCalo <<
" in Muon: " << savePDandCinMuon
95 <<
" everywhere: " << savePDandCinAll <<
"\n saveFirstSecondary"
96 <<
": " << saveFirstSecondary <<
" Tracking neutrino flag: " <<
trackNeutrino
97 <<
" Kill Delta Ray flag: " << killDeltaRay <<
" Kill hadrons/ions flag: " << killHeavy
98 <<
" MaxZCentralCMS = " << maxZCentralCMS /
CLHEP::m <<
" m"
99 <<
" MaxTrackTimeForward = " << maxTrackTimeForward / CLHEP::ns <<
" ns";
102 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction kill protons below " << kmaxProton / CLHEP::MeV
103 <<
" MeV, neutrons below " << kmaxNeutron / CLHEP::MeV <<
" MeV and ions"
104 <<
" below " << kmaxIon / CLHEP::MeV <<
" MeV";
108 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction kill tracks with "
109 <<
"time larger than " << maxTrackTime / CLHEP::ns <<
" ns ";
114 <<
" MaxTrackTime for " << maxTimeNames[
i] <<
" is " << maxTrackTimes[
i] <<
" ns ";
115 maxTrackTimes[
i] *= CLHEP::ns;
118 if (limitEnergyForVacuum > 0.0) {
120 <<
"StackingAction LowDensity regions - kill if E < " << limitEnergyForVacuum / CLHEP::MeV <<
" MeV";
124 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Dead regions - kill all secondaries ";
129 <<
"StackingAction: "
130 <<
"Russian Roulette for gamma Elimit(MeV)= " <<
gRusRoEnerLim / CLHEP::MeV <<
"\n"
131 <<
" ECAL Prob= " << gRusRoEcal <<
"\n"
132 <<
" HCAL Prob= " << gRusRoHcal <<
"\n"
133 <<
" MuonIron Prob= " << gRusRoMuonIron <<
"\n"
134 <<
" PreShower Prob= " << gRusRoPreShower <<
"\n"
135 <<
" CASTOR Prob= " << gRusRoCastor <<
"\n"
140 <<
"StackingAction: "
141 <<
"Russian Roulette for neutron Elimit(MeV)= " << nRusRoEnerLim / CLHEP::MeV <<
"\n"
142 <<
" ECAL Prob= " << nRusRoEcal <<
"\n"
143 <<
" HCAL Prob= " << nRusRoHcal <<
"\n"
144 <<
" MuonIron Prob= " << nRusRoMuonIron <<
"\n"
145 <<
" PreShower Prob= " << nRusRoPreShower <<
"\n"
146 <<
" CASTOR Prob= " << nRusRoCastor <<
"\n"
150 if (savePDandCinTracker) {
151 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Tracker regions: ";
154 if (savePDandCinCalo) {
155 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Calo regions: ";
158 if (savePDandCinMuon) {
159 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Muon regions: ";
162 worldSolid = G4TransportationManager::GetTransportationManager()
163 ->GetNavigatorForTracking()
173 G4ClassificationOfNewTrack classification = fUrgent;
174 const int pdg = aTrack->GetDefinition()->GetPDGEncoding();
178 if (aTrack->GetCreatorProcess() ==
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();
216 classification = fKill;
219 classification = fKill;
221 }
else if (classification != fKill) {
224 classification = fKill;
228 if (
killExtra && classification != fKill) {
229 if (
killHeavy && classification != fKill) {
230 if (((pdg / 1000000000 == 1) && (((pdg / 10000) % 100) > 0) && (((pdg / 10) % 100) > 0) &&
233 classification = fKill;
238 aTrack->GetCreatorProcess()->GetProcessSubType() == fIonisation) {
239 classification = fKill;
242 classification = fKill;
247 classification = fKill;
253 if (classification != fKill) {
270 if (2112 == pdg || 22 == pdg) {
271 double currentWeight = aTrack->GetWeight();
273 if (1.0 >= currentWeight) {
317 if (prob < 1.0 && aTrack->GetKineticEnergy() < elim) {
318 if (G4UniformRand() < prob) {
319 const_cast<G4Track*
>(aTrack)->SetWeight(currentWeight / prob);
321 classification = fKill;
326 if (classification != fKill) {
330 <<
"StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " << aTrack->GetParentID()
331 <<
" Type " << aTrack->GetDefinition()->GetParticleName() <<
" K.E. " << aTrack->GetKineticEnergy() / MeV
332 <<
" MeV from process/subprocess " << aTrack->GetCreatorProcess()->GetProcessType() <<
"|"
333 << aTrack->GetCreatorProcess()->GetProcessSubType() <<
" as " << classification <<
" Flag " << flag;
341 return classification;
354 const std::vector<G4Region*>* rs = G4RegionStore::GetInstance();
356 for (
auto& reg : *rs) {
357 const G4String&
rname = reg->GetName();
378 for (
unsigned int i = 0;
i <
num; ++
i) {
386 (rname ==
"BeamPipe" || rname ==
"BeamPipeVacuum" || rname ==
"TrackerPixelSensRegion" ||
387 rname ==
"TrackerPixelDeadRegion" || rname ==
"TrackerDeadRegion" || rname ==
"TrackerSensRegion" ||
388 rname ==
"FastTimerRegion" || rname ==
"FastTimerRegionSensBTL" || rname ==
"FastTimerRegionSensETL")) {
391 if (
savePDandCinCalo && (rname ==
"HcalRegion" || rname ==
"EcalRegion" || rname ==
"PreshowerSensRegion" ||
392 rname ==
"PreshowerRegion" || rname ==
"APDRegion" || rname ==
"HGCalRegion")) {
395 if (
savePDandCinMuon && (rname ==
"MuonChamber" || rname ==
"MuonSensitive_RPC" || rname ==
"MuonIron" ||
396 rname ==
"Muon" || rname ==
"MuonSensitive_DT-CSC")) {
399 if (rname ==
"BeamPipeOutside" || rname ==
"BeamPipeVacuum") {
403 if (rname == (G4String)(dead)) {
412 for (
auto&
region : regions) {
426 if (aTrack->GetCreatorProcess()->GetProcessType() == fDecay) {
428 }
else if (aTrack->GetCreatorProcess()->GetProcessSubType() == fGammaConversion) {
440 return (22 != genID && 11 !=
std::abs(genID));
466 for (
unsigned int i = 0;
i < reg.size(); ++
i) {
468 <<
" StackingAction: " << word <<
"Region " <<
i <<
". " << reg[
i]->GetName();
void primary(const G4Track *aSecondary) const
Log< level::Info, true > LogVerbatim
T getUntrackedParameter(std::string const &, T const &) const
G4ClassificationOfNewTrack ClassifyNewTrack(const G4Track *aTrack) final
StackingAction(const TrackingAction *, const edm::ParameterSet &ps, const CMSSteppingVerbose *)
std::vector< const G4Region * > lowdensRegions
void PrepareNewEvent() override
void StackFilled(const G4Track *, bool isKilled) const
std::vector< double > maxTrackTimes
TrackInformationExtractor extractor
bool exists(std::string const ¶meterName) const
checks if a parameter exists
const G4Region * regionCastor
const G4Region * regionMuonIron
bool rrApplicable(const G4Track *, const G4Track &) const
int isItPrimaryDecayProductOrConversion(const G4Track *, const G4Track &) 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
void secondary(const G4Track *aSecondary, const G4Track &mother, int) const
Abs< T >::type abs(const T &t)
bool isItOutOfTimeWindow(const G4Region *, const double &) const
bool isThisRegion(const G4Region *, std::vector< const G4Region * > &) const
T getParameter(std::string const &) const
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
int isItFromPrimary(const G4Track &, int) const
Log< level::Warning, false > LogWarning
std::vector< const G4Region * > trackerRegions
std::vector< const G4Region * > caloRegions
double limitEnergyForVacuum
const G4Region * regionWorld
const G4Track * geant4Track() const