Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-10 02:21:23

0001 #include "SimG4Core/Application/interface/StackingAction.h"
0002 #include "SimG4Core/Application/interface/TrackingAction.h"
0003 #include "SimG4Core/Notification/interface/MCTruthUtil.h"
0004 #include "SimG4Core/Notification/interface/TrackInformation.h"
0005 #include "SimG4Core/Notification/interface/CMSSteppingVerbose.h"
0006 #include "SimG4Core/Notification/interface/G4TrackToParticleID.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 
0010 #include "G4VProcess.hh"
0011 #include "G4EmProcessSubType.hh"
0012 #include "G4LogicalVolumeStore.hh"
0013 #include "G4RegionStore.hh"
0014 #include "Randomize.hh"
0015 #include <CLHEP/Units/SystemOfUnits.h>
0016 #include "G4VSolid.hh"
0017 #include "G4TransportationManager.hh"
0018 #include "G4GammaGeneralProcess.hh"
0019 #include "G4LossTableManager.hh"
0020 
0021 StackingAction::StackingAction(const TrackingAction* trka, const edm::ParameterSet& p, const CMSSteppingVerbose* sv)
0022     : trackAction(trka), steppingVerbose(sv) {
0023   trackNeutrino = p.getParameter<bool>("TrackNeutrino");
0024   killHeavy = p.getParameter<bool>("KillHeavy");
0025   killGamma = p.getParameter<bool>("KillGamma");
0026   kmaxGamma = p.getParameter<double>("GammaThreshold") * CLHEP::MeV;
0027   kmaxIon = p.getParameter<double>("IonThreshold") * CLHEP::MeV;
0028   kmaxProton = p.getParameter<double>("ProtonThreshold") * CLHEP::MeV;
0029   kmaxNeutron = p.getParameter<double>("NeutronThreshold") * CLHEP::MeV;
0030   killDeltaRay = p.getParameter<bool>("KillDeltaRay");
0031   limitEnergyForVacuum = p.getParameter<double>("CriticalEnergyForVacuum") * CLHEP::MeV;
0032   maxTrackTime = p.getParameter<double>("MaxTrackTime") * CLHEP::ns;
0033   maxTrackTimeForward = p.getParameter<double>("MaxTrackTimeForward") * CLHEP::ns;
0034   maxZCentralCMS = p.getParameter<double>("MaxZCentralCMS") * CLHEP::m;
0035   maxTrackTimes = p.getParameter<std::vector<double> >("MaxTrackTimes");
0036   maxTimeNames = p.getParameter<std::vector<std::string> >("MaxTimeNames");
0037   deadRegionNames = p.getParameter<std::vector<std::string> >("DeadRegions");
0038   savePDandCinAll = p.getUntrackedParameter<bool>("SaveAllPrimaryDecayProductsAndConversions", true);
0039   savePDandCinTracker = p.getUntrackedParameter<bool>("SavePrimaryDecayProductsAndConversionsInTracker", false);
0040   savePDandCinCalo = p.getUntrackedParameter<bool>("SavePrimaryDecayProductsAndConversionsInCalo", false);
0041   savePDandCinMuon = p.getUntrackedParameter<bool>("SavePrimaryDecayProductsAndConversionsInMuon", false);
0042   saveFirstSecondary = p.getUntrackedParameter<bool>("SaveFirstLevelSecondary", false);
0043 
0044   gRusRoEnerLim = p.getParameter<double>("RusRoGammaEnergyLimit") * CLHEP::MeV;
0045   nRusRoEnerLim = p.getParameter<double>("RusRoNeutronEnergyLimit") * CLHEP::MeV;
0046 
0047   gRusRoEcal = p.getParameter<double>("RusRoEcalGamma");
0048   gRusRoHcal = p.getParameter<double>("RusRoHcalGamma");
0049   gRusRoMuonIron = p.getParameter<double>("RusRoMuonIronGamma");
0050   gRusRoPreShower = p.getParameter<double>("RusRoPreShowerGamma");
0051   gRusRoCastor = p.getParameter<double>("RusRoCastorGamma");
0052   gRusRoWorld = p.getParameter<double>("RusRoWorldGamma");
0053 
0054   nRusRoEcal = p.getParameter<double>("RusRoEcalNeutron");
0055   nRusRoHcal = p.getParameter<double>("RusRoHcalNeutron");
0056   nRusRoMuonIron = p.getParameter<double>("RusRoMuonIronNeutron");
0057   nRusRoPreShower = p.getParameter<double>("RusRoPreShowerNeutron");
0058   nRusRoCastor = p.getParameter<double>("RusRoCastorNeutron");
0059   nRusRoWorld = p.getParameter<double>("RusRoWorldNeutron");
0060 
0061   gRusRoZDC = p.getParameter<double>("RusRoZDCGamma");
0062   gRusRoHGcal = p.getParameter<double>("RusRoHGcalGamma");
0063   nRusRoZDC = p.getParameter<double>("RusRoZDCNeutron");
0064   nRusRoHGcal = p.getParameter<double>("RusRoHGcalNeutron");
0065 
0066   if (gRusRoEnerLim > 0.0 && (gRusRoEcal < 1.0 || gRusRoHcal < 1.0 || gRusRoMuonIron < 1.0 || gRusRoPreShower < 1.0 ||
0067                               gRusRoCastor < 1.0 || gRusRoWorld < 1.0)) {
0068     gRRactive = true;
0069   }
0070   if (nRusRoEnerLim > 0.0 && (nRusRoEcal < 1.0 || nRusRoHcal < 1.0 || nRusRoMuonIron < 1.0 || nRusRoPreShower < 1.0 ||
0071                               nRusRoCastor < 1.0 || nRusRoWorld < 1.0)) {
0072     nRRactive = true;
0073   }
0074 
0075   if (p.exists("TestKillingOptions")) {
0076     killInCalo = (p.getParameter<edm::ParameterSet>("TestKillingOptions")).getParameter<bool>("KillInCalo");
0077     killInCaloEfH = (p.getParameter<edm::ParameterSet>("TestKillingOptions")).getParameter<bool>("KillInCaloEfH");
0078     edm::LogWarning("SimG4CoreApplication")
0079         << " *** Activating special test killing options in StackingAction \n"
0080         << " *** Kill secondaries in Calorimetetrs volume = " << killInCalo << "\n"
0081         << " *** Kill electromagnetic secondaries from hadrons in Calorimeters volume= " << killInCaloEfH;
0082   }
0083 
0084   initPointer();
0085 
0086   edm::LogVerbatim("SimG4CoreApplication")
0087       << "StackingAction initiated with"
0088       << " flag for saving decay products in "
0089       << " Tracker: " << savePDandCinTracker << " in Calo: " << savePDandCinCalo << " in Muon: " << savePDandCinMuon
0090       << " everywhere: " << savePDandCinAll << "\n  saveFirstSecondary"
0091       << ": " << saveFirstSecondary << " Tracking neutrino flag: " << trackNeutrino
0092       << " Kill Delta Ray flag: " << killDeltaRay << " Kill hadrons/ions flag: " << killHeavy
0093       << " MaxZCentralCMS = " << maxZCentralCMS / CLHEP::m << " m"
0094       << " MaxTrackTimeForward = " << maxTrackTimeForward / CLHEP::ns << " ns";
0095 
0096   if (killHeavy) {
0097     edm::LogVerbatim("SimG4CoreApplication") << "StackingAction kill protons below " << kmaxProton / CLHEP::MeV
0098                                              << " MeV, neutrons below " << kmaxNeutron / CLHEP::MeV << " MeV and ions"
0099                                              << " below " << kmaxIon / CLHEP::MeV << " MeV";
0100   }
0101   killExtra = killDeltaRay || killHeavy || killInCalo || killInCaloEfH;
0102 
0103   edm::LogVerbatim("SimG4CoreApplication") << "StackingAction kill tracks with "
0104                                            << "time larger than " << maxTrackTime / CLHEP::ns << " ns ";
0105   numberTimes = maxTimeNames.size();
0106   if (0 < numberTimes) {
0107     for (unsigned int i = 0; i < numberTimes; ++i) {
0108       edm::LogVerbatim("SimG4CoreApplication")
0109           << "          MaxTrackTime for " << maxTimeNames[i] << " is " << maxTrackTimes[i] << " ns ";
0110       maxTrackTimes[i] *= CLHEP::ns;
0111     }
0112   }
0113   if (limitEnergyForVacuum > 0.0) {
0114     edm::LogVerbatim("SimG4CoreApplication")
0115         << "StackingAction LowDensity regions - kill if E < " << limitEnergyForVacuum / CLHEP::MeV << " MeV";
0116     printRegions(lowdensRegions, "LowDensity");
0117   }
0118   if (deadRegions.size() > 0.0) {
0119     edm::LogVerbatim("SimG4CoreApplication") << "StackingAction Dead regions - kill all secondaries ";
0120     printRegions(deadRegions, "Dead");
0121   }
0122   if (gRRactive) {
0123     edm::LogVerbatim("SimG4CoreApplication")
0124         << "StackingAction: "
0125         << "Russian Roulette for gamma Elimit(MeV)= " << gRusRoEnerLim / CLHEP::MeV << "\n"
0126         << "                 ECAL Prob= " << gRusRoEcal << "\n"
0127         << "                 HCAL Prob= " << gRusRoHcal << "\n"
0128         << "             MuonIron Prob= " << gRusRoMuonIron << "\n"
0129         << "            PreShower Prob= " << gRusRoPreShower << "\n"
0130         << "                HGCAL Prob= " << gRusRoHGcal << "\n"
0131         << "                  ZDC Prob= " << gRusRoZDC << "\n"
0132         << "               CASTOR Prob= " << gRusRoCastor << "\n"
0133         << "                World Prob= " << gRusRoWorld;
0134   }
0135   if (nRRactive) {
0136     edm::LogVerbatim("SimG4CoreApplication")
0137         << "StackingAction: "
0138         << "Russian Roulette for neutron Elimit(MeV)= " << nRusRoEnerLim / CLHEP::MeV << "\n"
0139         << "                 ECAL Prob= " << nRusRoEcal << "\n"
0140         << "                 HCAL Prob= " << nRusRoHcal << "\n"
0141         << "             MuonIron Prob= " << nRusRoMuonIron << "\n"
0142         << "            PreShower Prob= " << nRusRoPreShower << "\n"
0143         << "                HGCAL Prob= " << nRusRoHGcal << "\n"
0144         << "                  ZDC Prob= " << nRusRoZDC << "\n"
0145         << "               CASTOR Prob= " << nRusRoCastor << "\n"
0146         << "                World Prob= " << nRusRoWorld;
0147   }
0148 
0149   if (savePDandCinTracker) {
0150     edm::LogVerbatim("SimG4CoreApplication") << "StackingAction Tracker regions: ";
0151     printRegions(trackerRegions, "Tracker");
0152   }
0153   if (savePDandCinCalo) {
0154     edm::LogVerbatim("SimG4CoreApplication") << "StackingAction Calo regions: ";
0155     printRegions(caloRegions, "Calo");
0156   }
0157   if (savePDandCinMuon) {
0158     edm::LogVerbatim("SimG4CoreApplication") << "StackingAction Muon regions: ";
0159     printRegions(muonRegions, "Muon");
0160   }
0161   worldSolid = G4TransportationManager::GetTransportationManager()
0162                    ->GetNavigatorForTracking()
0163                    ->GetWorldVolume()
0164                    ->GetLogicalVolume()
0165                    ->GetSolid();
0166 }
0167 
0168 G4ClassificationOfNewTrack StackingAction::ClassifyNewTrack(const G4Track* aTrack) {
0169   // G4 interface part
0170   G4ClassificationOfNewTrack classification = fUrgent;
0171   const int pdg = aTrack->GetDefinition()->GetPDGEncoding();
0172   const int abspdg = std::abs(pdg);
0173   auto track = const_cast<G4Track*>(aTrack);
0174   const G4VProcess* creatorProc = aTrack->GetCreatorProcess();
0175 
0176   if (creatorProc == nullptr && aTrack->GetParentID() != 0) {
0177     edm::LogWarning("StackingAction::ClassifyNewTrack")
0178         << " TrackID=" << aTrack->GetTrackID() << " ParentID=" << aTrack->GetParentID() << " "
0179         << aTrack->GetDefinition()->GetParticleName() << " Ekin(MeV)=" << aTrack->GetKineticEnergy();
0180   }
0181   if (aTrack->GetKineticEnergy() < 0.0) {
0182     edm::LogWarning("StackingAction::ClassifyNewTrack")
0183         << " TrackID=" << aTrack->GetTrackID() << " ParentID=" << aTrack->GetParentID() << " "
0184         << aTrack->GetDefinition()->GetParticleName() << " Ekin(MeV)=" << aTrack->GetKineticEnergy() << " creator "
0185         << creatorProc->GetProcessName();
0186   }
0187   // primary
0188   if (creatorProc == nullptr || aTrack->GetParentID() == 0) {
0189     if (!trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
0190       classification = fKill;
0191     } else if (worldSolid->Inside(aTrack->GetPosition()) == kOutside) {
0192       classification = fKill;
0193     } else {
0194       MCTruthUtil::primary(track);
0195     }
0196   } else {
0197     // secondary
0198     const G4Region* reg = aTrack->GetVolume()->GetLogicalVolume()->GetRegion();
0199     const double time = aTrack->GetGlobalTime();
0200 
0201     // definetly killed tracks
0202     if (aTrack->GetTrackStatus() == fStopAndKill) {
0203       classification = fKill;
0204     } else if (!trackNeutrino && (abspdg == 12 || abspdg == 14 || abspdg == 16 || abspdg == 18)) {
0205       classification = fKill;
0206 
0207     } else if (std::abs(aTrack->GetPosition().z()) >= maxZCentralCMS) {
0208       // very forward secondary
0209       if (time > maxTrackTimeForward) {
0210         classification = fKill;
0211       } else {
0212         const G4Track* mother = trackAction->geant4Track();
0213         MCTruthUtil::secondary(track, *mother, 0);
0214       }
0215 
0216     } else if (isItOutOfTimeWindow(reg, time)) {
0217       // time window check
0218       classification = fKill;
0219 
0220     } else {
0221       // potentially good for tracking
0222       const double ke = aTrack->GetKineticEnergy();
0223       G4int subType = (nullptr != creatorProc) ? creatorProc->GetProcessSubType() : 0;
0224 
0225       LogDebug("SimG4CoreApplication") << "##StackingAction:Classify Track " << aTrack->GetTrackID() << " Parent "
0226                                        << aTrack->GetParentID() << " " << aTrack->GetDefinition()->GetParticleName()
0227                                        << " Ekin(MeV)=" << ke / CLHEP::MeV << " subType=" << subType << " ";
0228 
0229       // kill tracks in specific regions
0230       if (isThisRegion(reg, deadRegions)) {
0231         classification = fKill;
0232       }
0233       if (classification != fKill && ke <= limitEnergyForVacuum && isThisRegion(reg, lowdensRegions)) {
0234         classification = fKill;
0235 
0236       } else if (classification != fKill) {
0237         // very low-energy gamma
0238         if (pdg == 22 && killGamma && ke < kmaxGamma) {
0239           classification = fKill;
0240         }
0241 
0242         // specific track killing - not for production
0243         if (killExtra && classification != fKill) {
0244           if (killHeavy && classification != fKill) {
0245             if (((pdg / 1000000000 == 1) && (((pdg / 10000) % 100) > 0) && (((pdg / 10) % 100) > 0) &&
0246                  (ke < kmaxIon)) ||
0247                 ((pdg == 2212) && (ke < kmaxProton)) || ((pdg == 2112) && (ke < kmaxNeutron))) {
0248               classification = fKill;
0249             }
0250           }
0251 
0252           if (killDeltaRay && classification != fKill && aTrack->GetParentID() > 0 &&
0253               G4TrackToParticleID::isGammaElectronPositron(aTrack)) {
0254             classification = fKill;
0255           }
0256 
0257           if (killInCalo && classification != fKill && isThisRegion(reg, caloRegions)) {
0258             classification = fKill;
0259           }
0260           if (killInCaloEfH && classification != fKill) {
0261             int pdgMother = std::abs(trackAction->geant4Track()->GetDefinition()->GetPDGEncoding());
0262             if ((pdg == 22 || abspdg == 11) && pdgMother != 11 && pdgMother != 22 && isThisRegion(reg, caloRegions)) {
0263               classification = fKill;
0264             }
0265           }
0266         }
0267 
0268         // Russian roulette && MC truth
0269         if (classification != fKill) {
0270           const G4Track* mother = trackAction->geant4Track();
0271           int flag = 0;
0272           if (savePDandCinAll) {
0273             flag = isItPrimaryDecayProductOrConversion(subType, *mother);
0274           } else {
0275             if ((savePDandCinTracker && isThisRegion(reg, trackerRegions)) ||
0276                 (savePDandCinCalo && isThisRegion(reg, caloRegions)) ||
0277                 (savePDandCinMuon && isThisRegion(reg, muonRegions))) {
0278               flag = isItPrimaryDecayProductOrConversion(subType, *mother);
0279             }
0280           }
0281           if (saveFirstSecondary && 0 == flag) {
0282             flag = isItFromPrimary(*mother, flag);
0283           }
0284 
0285           // Russian roulette
0286           if (2112 == pdg || 22 == pdg) {
0287             double currentWeight = aTrack->GetWeight();
0288 
0289             if (1.0 >= currentWeight) {
0290               double prob = 1.001;
0291               double elim = 0.0;
0292 
0293               // neutron
0294               if (nRRactive && pdg == 2112) {
0295                 elim = nRusRoEnerLim;
0296                 if (reg == regionEcal) {
0297                   prob = nRusRoEcal;
0298                 } else if (reg == regionHcal) {
0299                   prob = nRusRoHcal;
0300                 } else if (reg == regionMuonIron) {
0301                   prob = nRusRoMuonIron;
0302                 } else if (reg == regionPreShower) {
0303                   prob = nRusRoPreShower;
0304                 } else if (reg == regionHGcal) {
0305                   prob = nRusRoHGcal;
0306                 } else if (reg == regionZDC) {
0307                   prob = nRusRoZDC;
0308                 } else if (reg == regionCastor) {
0309                   prob = nRusRoCastor;
0310                 } else if (reg == regionWorld) {
0311                   prob = nRusRoWorld;
0312                 }
0313 
0314                 // gamma
0315               } else if (gRRactive && pdg == 22) {
0316                 elim = gRusRoEnerLim;
0317                 if (reg == regionEcal || reg == regionPreShower) {
0318                   if (rrApplicable(aTrack, *mother)) {
0319                     if (reg == regionEcal) {
0320                       prob = gRusRoEcal;
0321                     } else {
0322                       prob = gRusRoPreShower;
0323                     }
0324                   }
0325                 } else {
0326                   if (reg == regionHcal) {
0327                     prob = gRusRoHcal;
0328                   } else if (reg == regionMuonIron) {
0329                     prob = gRusRoMuonIron;
0330                   } else if (reg == regionHGcal) {
0331                     prob = gRusRoHGcal;
0332                   } else if (reg == regionZDC) {
0333                     prob = gRusRoZDC;
0334                   } else if (reg == regionCastor) {
0335                     prob = gRusRoCastor;
0336                   } else if (reg == regionWorld) {
0337                     prob = gRusRoWorld;
0338                   }
0339                 }
0340               }
0341               if (prob < 1.0 && aTrack->GetKineticEnergy() < elim) {
0342                 if (G4UniformRand() < prob) {
0343                   track->SetWeight(currentWeight / prob);
0344                 } else {
0345                   classification = fKill;
0346                 }
0347               }
0348             }
0349           }
0350           if (classification != fKill) {
0351             MCTruthUtil::secondary(track, *mother, flag);
0352           }
0353           LogDebug("SimG4CoreApplication")
0354               << "StackingAction:Classify Track " << aTrack->GetTrackID() << " Parent " << aTrack->GetParentID()
0355               << " Type " << aTrack->GetDefinition()->GetParticleName() << " Ekin=" << ke / CLHEP::MeV
0356               << " MeV from process subType=" << subType << " as " << classification << " Flag: " << flag;
0357         }
0358       }
0359     }
0360   }
0361   if (nullptr != steppingVerbose) {
0362     steppingVerbose->stackFilled(aTrack, (classification == fKill));
0363   }
0364   return classification;
0365 }
0366 
0367 void StackingAction::NewStage() {}
0368 
0369 void StackingAction::PrepareNewEvent() {}
0370 
0371 void StackingAction::initPointer() {
0372   // prepare region vector
0373   const unsigned int num = maxTimeNames.size();
0374   maxTimeRegions.resize(num, nullptr);
0375 
0376   // Russian roulette
0377   const std::vector<G4Region*>* rs = G4RegionStore::GetInstance();
0378 
0379   for (auto& reg : *rs) {
0380     const G4String& rname = reg->GetName();
0381     if ((gRusRoEcal < 1.0 || nRusRoEcal < 1.0) && rname == "EcalRegion") {
0382       regionEcal = reg;
0383     }
0384     if ((gRusRoHcal < 1.0 || nRusRoHcal < 1.0) && rname == "HcalRegion") {
0385       regionHcal = reg;
0386     }
0387     if ((gRusRoMuonIron < 1.0 || nRusRoMuonIron < 1.0) && rname == "MuonIron") {
0388       regionMuonIron = reg;
0389     }
0390     if ((gRusRoPreShower < 1.0 || nRusRoPreShower < 1.0) && rname == "PreshowerRegion") {
0391       regionPreShower = reg;
0392     }
0393     if ((gRusRoCastor < 1.0 || nRusRoCastor < 1.0) && rname == "CastorRegion") {
0394       regionCastor = reg;
0395     }
0396     if ((gRusRoZDC < 1.0 || nRusRoZDC < 1.0) && rname == "ZDCRegion") {
0397       regionZDC = reg;
0398     }
0399     if ((gRusRoHGcal < 1.0 || nRusRoHGcal < 1.0) && rname == "HGCalRegion") {
0400       regionHGcal = reg;
0401     }
0402     if ((gRusRoWorld < 1.0 || nRusRoWorld < 1.0) && rname == "DefaultRegionForTheWorld") {
0403       regionWorld = reg;
0404     }
0405 
0406     // time limits
0407     for (unsigned int i = 0; i < num; ++i) {
0408       if (rname == (G4String)(maxTimeNames[i])) {
0409         maxTimeRegions[i] = reg;
0410         break;
0411       }
0412     }
0413     //
0414     if (savePDandCinTracker &&
0415         (rname == "BeamPipe" || rname == "BeamPipeVacuum" || rname == "TrackerPixelSensRegion" ||
0416          rname == "TrackerPixelDeadRegion" || rname == "TrackerDeadRegion" || rname == "TrackerSensRegion" ||
0417          rname == "FastTimerRegionBTL" || rname == "FastTimerRegionETL" || rname == "FastTimerRegionSensBTL" ||
0418          rname == "FastTimerRegionSensETL")) {
0419       trackerRegions.push_back(reg);
0420     }
0421     if (savePDandCinCalo && (rname == "HcalRegion" || rname == "EcalRegion" || rname == "PreshowerSensRegion" ||
0422                              rname == "PreshowerRegion" || rname == "APDRegion" || rname == "HGCalRegion")) {
0423       caloRegions.push_back(reg);
0424     }
0425     if (savePDandCinMuon && (rname == "MuonChamber" || rname == "MuonSensitive_RPC" || rname == "MuonIron" ||
0426                              rname == "Muon" || rname == "MuonSensitive_DT-CSC")) {
0427       muonRegions.push_back(reg);
0428     }
0429     if (rname == "BeamPipeOutside" || rname == "BeamPipeVacuum") {
0430       lowdensRegions.push_back(reg);
0431     }
0432     for (auto& dead : deadRegionNames) {
0433       if (rname == (G4String)(dead)) {
0434         deadRegions.push_back(reg);
0435       }
0436     }
0437   }
0438 }
0439 
0440 bool StackingAction::isThisRegion(const G4Region* reg, std::vector<const G4Region*>& regions) const {
0441   bool flag = false;
0442   for (auto& region : regions) {
0443     if (reg == region) {
0444       flag = true;
0445       break;
0446     }
0447   }
0448   return flag;
0449 }
0450 
0451 int StackingAction::isItPrimaryDecayProductOrConversion(const int stype, const G4Track& mother) const {
0452   int flag = 0;
0453   auto motherInfo = static_cast<const TrackInformation*>(mother.GetUserInformation());
0454   // Check whether mother is a primary
0455   if (motherInfo->isPrimary()) {
0456     if (stype == fDecay) {
0457       flag = 1;
0458     } else if (stype == fGammaConversion) {
0459       flag = 2;
0460     }
0461   }
0462   return flag;
0463 }
0464 
0465 bool StackingAction::rrApplicable(const G4Track* aTrack, const G4Track& mother) const {
0466   auto motherInfo = static_cast<const TrackInformation*>(mother.GetUserInformation());
0467 
0468   // Check whether mother is gamma, e+, e-
0469   const int genID = motherInfo->genParticlePID();
0470   return (22 != genID && 11 != std::abs(genID));
0471 }
0472 
0473 int StackingAction::isItFromPrimary(const G4Track& mother, int flagIn) const {
0474   int flag = flagIn;
0475   if (flag != 1) {
0476     auto ptr = static_cast<const TrackInformation*>(mother.GetUserInformation());
0477     if (ptr->isPrimary()) {
0478       flag = 3;
0479     }
0480   }
0481   return flag;
0482 }
0483 
0484 bool StackingAction::isItOutOfTimeWindow(const G4Region* reg, const double& t) const {
0485   double tofM = maxTrackTime;
0486   for (unsigned int i = 0; i < numberTimes; ++i) {
0487     if (reg == maxTimeRegions[i]) {
0488       tofM = maxTrackTimes[i];
0489       break;
0490     }
0491   }
0492   return (t > tofM);
0493 }
0494 
0495 void StackingAction::printRegions(const std::vector<const G4Region*>& reg, const std::string& word) const {
0496   for (unsigned int i = 0; i < reg.size(); ++i) {
0497     edm::LogVerbatim("SimG4CoreApplication")
0498         << " StackingAction: " << word << "Region " << i << ". " << reg[i]->GetName();
0499   }
0500 }