CMS 3D CMS Logo

LowEnergyFastSimModel.cc
Go to the documentation of this file.
3 
6 
7 #include "G4VFastSimulationModel.hh"
8 #include "G4EventManager.hh"
9 #include "G4Electron.hh"
10 #include "GFlashHitMaker.hh"
11 #include "G4Region.hh"
12 #include "G4Positron.hh"
13 #include "G4ParticleDefinition.hh"
14 #include "G4PhysicalConstants.hh"
15 
16 constexpr G4double twomass = 2 * CLHEP::electron_mass_c2;
17 
19  : G4VFastSimulationModel(name, region),
20  fRegion(region),
21  fTrackingAction(nullptr),
22  fCheck(false),
23  fTailPos(0., 0., 0.) {
24  fEmax = parSet.getParameter<double>("LowEnergyGflashEcalEmax") * CLHEP::GeV;
25  fPositron = G4Positron::Positron();
26 }
27 
28 G4bool LowEnergyFastSimModel::IsApplicable(const G4ParticleDefinition& particle) {
29  return (11 == std::abs(particle.GetPDGEncoding()));
30 }
31 
32 G4bool LowEnergyFastSimModel::ModelTrigger(const G4FastTrack& fastTrack) {
33  const G4Track* track = fastTrack.GetPrimaryTrack();
34  if (fCheck) {
35  if (nullptr == fTrackingAction) {
36  fTrackingAction = static_cast<const TrackingAction*>(G4EventManager::GetEventManager()->GetUserTrackingAction());
37  }
38  int pdgMother = std::abs(fTrackingAction->geant4Track()->GetDefinition()->GetPDGEncoding());
39  if (pdgMother == 11 || pdgMother == 22)
40  return false;
41  }
42  G4double energy = track->GetKineticEnergy();
43  return (energy < fEmax && fRegion == fastTrack.GetEnvelope());
44 }
45 
46 void LowEnergyFastSimModel::DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep) {
47  fastStep.KillPrimaryTrack();
48  fastStep.SetPrimaryTrackPathLength(0.0);
49  auto track = fastTrack.GetPrimaryTrack();
50  G4double energy = track->GetKineticEnergy();
51 
52  const G4ThreeVector& pos = track->GetPosition();
53 
54  G4double inPointEnergy = fParam.GetInPointEnergyFraction(energy) * energy;
55 
56  // take into account positron annihilation (not included in in-point)
57  if (fPositron == track->GetDefinition())
58  energy += twomass;
59 
60  const G4ThreeVector& momDir = track->GetMomentumDirection();
61 
62  // in point energy deposition
63  GFlashEnergySpot spot;
64  spot.SetEnergy(inPointEnergy);
65  spot.SetPosition(pos);
66  fHitMaker.make(&spot, &fastTrack);
67 
68  // tail energy deposition
69  G4double etail = energy - inPointEnergy;
70  const G4int nspots = (G4int)(etail) + 1;
71  const G4double tailEnergy = etail / (G4double)nspots;
72  for (G4int i = 0; i < nspots; ++i) {
73  const G4double r = fParam.GetRadius(energy);
74  const G4double z = fParam.GetZ();
75 
76  const G4double phi = CLHEP::twopi * G4UniformRand();
77  fTailPos.set(r * std::cos(phi), r * std::sin(phi), z);
78  fTailPos.rotateUz(momDir);
79  fTailPos += pos;
80 
81  spot.SetEnergy(tailEnergy);
82  spot.SetPosition(fTailPos);
83  fHitMaker.make(&spot, &fastTrack);
84  }
85 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
const G4ParticleDefinition * fPositron
G4bool IsApplicable(const G4ParticleDefinition &particle) override
constexpr G4double twomass
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
const G4Envelope * fRegion
LowEnergyFastSimParam fParam
G4double GetInPointEnergyFraction(G4double energy) const
const G4Track * geant4Track() const
const TrackingAction * fTrackingAction
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
LowEnergyFastSimModel(const G4String &name, G4Region *region, const edm::ParameterSet &parSet)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void DoIt(const G4FastTrack &fastTrack, G4FastStep &fastStep) override
G4bool ModelTrigger(const G4FastTrack &fastTrack) override
G4double GetRadius(G4double energy) const