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) {
68 if (
gRusRoEnerLim > 0.0 && (gRusRoEcal < 1.0 || gRusRoHcal < 1.0 || gRusRoMuonIron < 1.0 || gRusRoPreShower < 1.0 ||
69 gRusRoCastor < 1.0 || gRusRoWorld < 1.0)) {
72 if (nRusRoEnerLim > 0.0 && (nRusRoEcal < 1.0 || nRusRoHcal < 1.0 || nRusRoMuonIron < 1.0 || nRusRoPreShower < 1.0 ||
73 nRusRoCastor < 1.0 || nRusRoWorld < 1.0)) {
77 if (p.
exists(
"TestKillingOptions")) {
81 <<
" *** Activating special test killing options in StackingAction \n" 82 <<
" *** Kill secondaries in Calorimetetrs volume = " << killInCalo <<
"\n" 83 <<
" *** Kill electromagnetic secondaries from hadrons in Calorimeters volume= " <<
killInCaloEfH;
90 <<
"StackingAction initiated with" 91 <<
" flag for saving decay products in " 92 <<
" Tracker: " << savePDandCinTracker <<
" in Calo: " << savePDandCinCalo <<
" in Muon: " << savePDandCinMuon
93 <<
" everywhere: " << savePDandCinAll <<
"\n saveFirstSecondary" 94 <<
": " << saveFirstSecondary <<
" Tracking neutrino flag: " <<
trackNeutrino 95 <<
" Kill Delta Ray flag: " << killDeltaRay <<
" Kill hadrons/ions flag: " <<
killHeavy;
98 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction kill protons below " << kmaxProton /
MeV 99 <<
" MeV, neutrons below " << kmaxNeutron /
MeV <<
" MeV and ions" 100 <<
" below " << kmaxIon /
MeV <<
" MeV";
104 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction kill tracks with " 105 <<
"time larger than " << maxTrackTime / ns <<
" ns ";
110 <<
"StackingAction MaxTrackTime for " << maxTimeNames[
i] <<
" is " << maxTrackTimes[
i] <<
" ns ";
111 maxTrackTimes[
i] *= ns;
114 if (limitEnergyForVacuum > 0.0) {
116 <<
"StackingAction LowDensity regions - kill if E < " << limitEnergyForVacuum /
MeV <<
" MeV";
120 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Dead regions - kill all secondaries ";
125 <<
"StackingAction: " 126 <<
"Russian Roulette for gamma Elimit(MeV)= " <<
gRusRoEnerLim /
MeV <<
"\n" 127 <<
" ECAL Prob= " << gRusRoEcal <<
"\n" 128 <<
" HCAL Prob= " << gRusRoHcal <<
"\n" 129 <<
" MuonIron Prob= " << gRusRoMuonIron <<
"\n" 130 <<
" PreShower Prob= " << gRusRoPreShower <<
"\n" 131 <<
" CASTOR Prob= " << gRusRoCastor <<
"\n" 136 <<
"StackingAction: " 137 <<
"Russian Roulette for neutron Elimit(MeV)= " << nRusRoEnerLim /
MeV <<
"\n" 138 <<
" ECAL Prob= " << nRusRoEcal <<
"\n" 139 <<
" HCAL Prob= " << nRusRoHcal <<
"\n" 140 <<
" MuonIron Prob= " << nRusRoMuonIron <<
"\n" 141 <<
" PreShower Prob= " << nRusRoPreShower <<
"\n" 142 <<
" CASTOR Prob= " << nRusRoCastor <<
"\n" 146 if (savePDandCinTracker) {
147 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Tracker regions: ";
150 if (savePDandCinCalo) {
151 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Calo regions: ";
154 if (savePDandCinMuon) {
155 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Muon regions: ";
158 worldSolid = G4TransportationManager::GetTransportationManager()
159 ->GetNavigatorForTracking()
169 G4ClassificationOfNewTrack classification = fUrgent;
170 int pdg = aTrack->GetDefinition()->GetPDGEncoding();
174 if (aTrack->GetCreatorProcess() ==
nullptr || aTrack->GetParentID() == 0) {
175 if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
176 classification = fKill;
177 }
else if (
worldSolid->Inside(aTrack->GetPosition()) == kOutside) {
178 classification = fKill;
184 const G4Region* reg = aTrack->GetVolume()->GetLogicalVolume()->GetRegion();
186 if (aTrack->GetTrackStatus() == fStopAndKill) {
187 classification = fKill;
188 }
else if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
189 classification = fKill;
191 classification = fKill;
196 double ke = aTrack->GetKineticEnergy();
200 classification = fKill;
203 classification = fKill;
208 classification = fKill;
212 if (
killExtra && classification != fKill) {
213 if (
killHeavy && classification != fKill) {
214 if (((pdg / 1000000000 == 1) && (((pdg / 10000) % 100) > 0) && (((pdg / 10) % 100) > 0) &&
217 classification = fKill;
222 aTrack->GetCreatorProcess()->GetProcessSubType() == fIonisation) {
223 classification = fKill;
226 classification = fKill;
231 classification = fKill;
237 if (classification != fKill) {
254 if (2112 == pdg || 22 == pdg) {
255 double currentWeight = aTrack->GetWeight();
257 if (1.0 >= currentWeight) {
301 if (prob < 1.0 && aTrack->GetKineticEnergy() < elim) {
302 if (G4UniformRand() < prob) {
303 const_cast<G4Track*
>(aTrack)->SetWeight(currentWeight / prob);
305 classification = fKill;
310 if (classification != fKill) {
314 <<
"StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " << aTrack->GetParentID()
315 <<
" Type " << aTrack->GetDefinition()->GetParticleName() <<
" K.E. " << aTrack->GetKineticEnergy() /
MeV 316 <<
" MeV from process/subprocess " << aTrack->GetCreatorProcess()->GetProcessType() <<
"|" 317 << aTrack->GetCreatorProcess()->GetProcessSubType() <<
" as " << classification <<
" Flag " <<
flag;
325 return classification;
338 std::vector<G4Region*>* rs = G4RegionStore::GetInstance();
340 for (
auto& reg : *rs) {
341 G4String
rname = reg->GetName();
362 for (
unsigned int i = 0;
i <
num; ++
i) {
370 (rname ==
"BeamPipe" || rname ==
"BeamPipeVacuum" || rname ==
"TrackerPixelSensRegion" ||
371 rname ==
"TrackerPixelDeadRegion" || rname ==
"TrackerDeadRegion" || rname ==
"TrackerSensRegion")) {
374 if (
savePDandCinCalo && (rname ==
"HcalRegion" || rname ==
"EcalRegion" || rname ==
"PreshowerSensRegion" ||
375 rname ==
"PreshowerRegion")) {
378 if (
savePDandCinMuon && (rname ==
"MuonChamber" || rname ==
"MuonSensitive_RPC" || rname ==
"MuonIron" ||
379 rname ==
"Muon" || rname ==
"MuonSensitive_DT-CSC")) {
382 if (rname ==
"BeamPipeOutside" || rname ==
"BeamPipeVacuum") {
386 if (rname == (G4String)(dead)) {
395 for (
auto&
region : regions) {
409 if (aTrack->GetCreatorProcess()->GetProcessType() ==
fDecay) {
411 }
else if (aTrack->GetCreatorProcess()->GetProcessSubType() == fGammaConversion) {
423 return (22 == genID || 11 == genID || -11 == genID) ?
false :
true;
445 return (aTrack->GetGlobalTime() > tofM) ?
true :
false;
449 for (
unsigned int i = 0;
i < reg.size(); ++
i) {
451 <<
" StackingAction: " << word <<
"Region " <<
i <<
". " << reg[
i]->GetName();
void primary(const G4Track *aSecondary) const
T getParameter(std::string const &) const
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 isThisRegion(const G4Region *, std::vector< const G4Region * > &) const
std::vector< std::string > deadRegionNames
const G4Region * regionHcal
bool isItOutOfTimeWindow(const G4Region *, const G4Track *) const
std::vector< const G4Region * > maxTimeRegions
const G4String rname[NREG]
const G4Region * regionPreShower
const TrackingAction * trackAction
int isItFromPrimary(const G4Track &, int) const
std::vector< const G4Region * > trackerRegions
std::vector< const G4Region * > caloRegions
double limitEnergyForVacuum
const G4Region * regionWorld
const G4Track * geant4Track() const