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" 18 #include "G4LossTableManager.hh" 21 : trackAction(trka), steppingVerbose(
sv) {
25 kmaxGamma =
p.getParameter<
double>(
"GammaThreshold") * CLHEP::MeV;
26 kmaxIon =
p.getParameter<
double>(
"IonThreshold") * CLHEP::MeV;
27 kmaxProton =
p.getParameter<
double>(
"ProtonThreshold") * CLHEP::MeV;
28 kmaxNeutron =
p.getParameter<
double>(
"NeutronThreshold") * CLHEP::MeV;
34 maxTrackTimes =
p.getParameter<std::vector<double> >(
"MaxTrackTimes");
35 maxTimeNames =
p.getParameter<std::vector<std::string> >(
"MaxTimeNames");
37 savePDandCinAll =
p.getUntrackedParameter<
bool>(
"SaveAllPrimaryDecayProductsAndConversions",
true);
38 savePDandCinTracker =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInTracker",
false);
39 savePDandCinCalo =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInCalo",
false);
40 savePDandCinMuon =
p.getUntrackedParameter<
bool>(
"SavePrimaryDecayProductsAndConversionsInMuon",
false);
43 gRusRoEnerLim =
p.getParameter<
double>(
"RusRoGammaEnergyLimit") * CLHEP::MeV;
44 nRusRoEnerLim =
p.getParameter<
double>(
"RusRoNeutronEnergyLimit") * CLHEP::MeV;
46 gRusRoEcal =
p.getParameter<
double>(
"RusRoEcalGamma");
47 gRusRoHcal =
p.getParameter<
double>(
"RusRoHcalGamma");
53 nRusRoEcal =
p.getParameter<
double>(
"RusRoEcalNeutron");
54 nRusRoHcal =
p.getParameter<
double>(
"RusRoHcalNeutron");
58 nRusRoWorld =
p.getParameter<
double>(
"RusRoWorldNeutron");
69 if (
p.exists(
"TestKillingOptions")) {
73 <<
" *** Activating special test killing options in StackingAction \n" 74 <<
" *** Kill secondaries in Calorimetetrs volume = " <<
killInCalo <<
"\n" 75 <<
" *** Kill electromagnetic secondaries from hadrons in Calorimeters volume= " <<
killInCaloEfH;
82 <<
"StackingAction initiated with" 83 <<
" flag for saving decay products in " 93 <<
" MeV, neutrons below " <<
kmaxNeutron / CLHEP::MeV <<
" MeV and ions" 94 <<
" below " <<
kmaxIon / CLHEP::MeV <<
" MeV";
98 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction kill tracks with " 99 <<
"time larger than " <<
maxTrackTime / CLHEP::ns <<
" ns ";
110 <<
"StackingAction LowDensity regions - kill if E < " <<
limitEnergyForVacuum / CLHEP::MeV <<
" MeV";
114 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Dead regions - kill all secondaries ";
119 <<
"StackingAction: " 120 <<
"Russian Roulette for gamma Elimit(MeV)= " <<
gRusRoEnerLim / CLHEP::MeV <<
"\n" 130 <<
"StackingAction: " 131 <<
"Russian Roulette for neutron Elimit(MeV)= " <<
nRusRoEnerLim / CLHEP::MeV <<
"\n" 141 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Tracker regions: ";
145 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Calo regions: ";
149 edm::LogVerbatim(
"SimG4CoreApplication") <<
"StackingAction Muon regions: ";
152 worldSolid = G4TransportationManager::GetTransportationManager()
153 ->GetNavigatorForTracking()
163 G4ClassificationOfNewTrack classification = fUrgent;
164 const int pdg = aTrack->GetDefinition()->GetPDGEncoding();
166 auto track =
const_cast<G4Track*
>(aTrack);
167 const G4VProcess* creatorProc = aTrack->GetCreatorProcess();
169 if (creatorProc ==
nullptr && aTrack->GetParentID() != 0) {
171 <<
" TrackID=" << aTrack->GetTrackID() <<
" ParentID=" << aTrack->GetParentID() <<
" " 172 << aTrack->GetDefinition()->GetParticleName() <<
" Ekin(MeV)=" << aTrack->GetKineticEnergy();
174 if (aTrack->GetKineticEnergy() < 0.0) {
176 <<
" TrackID=" << aTrack->GetTrackID() <<
" ParentID=" << aTrack->GetParentID() <<
" " 177 << aTrack->GetDefinition()->GetParticleName() <<
" Ekin(MeV)=" << aTrack->GetKineticEnergy() <<
" creator " 178 << creatorProc->GetProcessName();
181 if (creatorProc ==
nullptr || aTrack->GetParentID() == 0) {
182 if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
183 classification = fKill;
184 }
else if (
worldSolid->Inside(aTrack->GetPosition()) == kOutside) {
185 classification = fKill;
191 const G4Region* reg = aTrack->GetVolume()->GetLogicalVolume()->GetRegion();
192 const double time = aTrack->GetGlobalTime();
195 if (aTrack->GetTrackStatus() == fStopAndKill) {
196 classification = fKill;
197 }
else if (!
trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
198 classification = fKill;
203 classification = fKill;
211 classification = fKill;
215 const double ke = aTrack->GetKineticEnergy();
216 G4int subType = (
nullptr != creatorProc) ? creatorProc->GetProcessSubType() : 0;
220 if (
nullptr != ptr) {
221 creatorProc = ptr->GetSelectedProcess();
222 if (
nullptr == creatorProc) {
224 auto vp = G4LossTableManager::Instance()->GetEmProcessVector();
226 if (fComptonScattering ==
p->GetProcessSubType()) {
234 subType = creatorProc->GetProcessSubType();
235 track->SetCreatorProcess(creatorProc);
237 if (creatorProc ==
nullptr) {
239 <<
" SubType=16 and no creatorProc; TrackID=" << aTrack->GetTrackID()
240 <<
" ParentID=" << aTrack->GetParentID() <<
" " << aTrack->GetDefinition()->GetParticleName()
241 <<
" Ekin(MeV)=" << ke <<
" SubType=" << subType;
245 LogDebug(
"SimG4CoreApplication") <<
"##StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " 246 << aTrack->GetParentID() <<
" " << aTrack->GetDefinition()->GetParticleName()
247 <<
" Ekin(MeV)=" << ke / CLHEP::MeV <<
" subType=" << subType <<
" ";
251 classification = fKill;
254 classification = fKill;
256 }
else if (classification != fKill) {
259 classification = fKill;
263 if (
killExtra && classification != fKill) {
264 if (
killHeavy && classification != fKill) {
265 if (((
pdg / 1000000000 == 1) && (((
pdg / 10000) % 100) > 0) && (((
pdg / 10) % 100) > 0) &&
268 classification = fKill;
272 if (
killDeltaRay && classification != fKill && subType == fIonisation) {
273 classification = fKill;
276 classification = fKill;
281 classification = fKill;
287 if (classification != fKill) {
304 if (2112 ==
pdg || 22 ==
pdg) {
305 double currentWeight = aTrack->GetWeight();
307 if (1.0 >= currentWeight) {
351 if (prob < 1.0 && aTrack->GetKineticEnergy() < elim) {
352 if (G4UniformRand() <
prob) {
355 classification = fKill;
360 if (classification != fKill) {
364 <<
"StackingAction:Classify Track " << aTrack->GetTrackID() <<
" Parent " << aTrack->GetParentID()
365 <<
" Type " << aTrack->GetDefinition()->GetParticleName() <<
" Ekin=" << ke / CLHEP::MeV
366 <<
" MeV from process subType=" << subType <<
" as " << classification <<
" Flag: " <<
flag;
374 return classification;
387 const std::vector<G4Region*>* rs = G4RegionStore::GetInstance();
389 for (
auto& reg : *rs) {
390 const G4String&
rname = reg->GetName();
411 for (
unsigned int i = 0;
i <
num; ++
i) {
419 (
rname ==
"BeamPipe" ||
rname ==
"BeamPipeVacuum" ||
rname ==
"TrackerPixelSensRegion" ||
420 rname ==
"TrackerPixelDeadRegion" ||
rname ==
"TrackerDeadRegion" ||
rname ==
"TrackerSensRegion" ||
421 rname ==
"FastTimerRegion" ||
rname ==
"FastTimerRegionSensBTL" ||
rname ==
"FastTimerRegionSensETL")) {
425 rname ==
"PreshowerRegion" ||
rname ==
"APDRegion" ||
rname ==
"HGCalRegion")) {
429 rname ==
"Muon" ||
rname ==
"MuonSensitive_DT-CSC")) {
432 if (
rname ==
"BeamPipeOutside" ||
rname ==
"BeamPipeVacuum") {
436 if (
rname == (G4String)(dead)) {
461 }
else if (stype == fGammaConversion) {
473 return (22 != genID && 11 !=
std::abs(genID));
499 for (
unsigned int i = 0;
i < reg.size(); ++
i) {
501 <<
" 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 G4VProcess * m_Compton
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
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
int isItPrimaryDecayProductOrConversion(const int subtype, const G4Track &) const
std::vector< const G4Region * > caloRegions
double limitEnergyForVacuum
const G4Region * regionWorld