7 #include "GaudiKernel/Bootstrap.h"
8 #include "GaudiKernel/ISvcLocator.h"
18 #include "G4Electron.hh"
20 #include "G4Positron.hh"
21 #include "G4Neutron.hh"
22 #include "G4PionPlus.hh"
23 #include "G4PionMinus.hh"
24 #include "G4VSensitiveDetector.hh"
25 #include "G4EventManager.hh"
29 #include "GaudiKernel/ConcurrencyFlags.h"
33 #undef _TRACE_POSITION_
39 G4VFastSimulationModel(
name),
41 m_fastSimDedicatedSD(fastSimDedicatedSD),
42 m_showerLibSvc(nullptr),
43 m_generate_starting_points(false),
44 m_starting_points_file(),
60 auto threadId = std::this_thread::get_id();
63 hepmcFileName +=
"."+
ss.str();
73 FCAL3=500000, HECLOC=600000,
HEC=700000 };
87 throw std::runtime_error(
"LArFastShower: no pointer to IFastSimDedicatedSD!");
97 if ( smartShowerLibSvc ) {
m_showerLibSvc = smartShowerLibSvc.get(); }
99 throw std::runtime_error(
"LArFastShower: cannot retrieve LArG4ShowerLibSvc");
109 G4cout <<
"LArFastShower::IsApplicable" << G4endl;
139 G4cout <<
"LArFastShower::commonTrigger" << G4endl;
145 G4double particleEnergy = fastTrack.GetPrimaryTrack()->GetKineticEnergy();
146 const G4ParticleDefinition&
particleType = *(fastTrack.GetPrimaryTrack()->GetDefinition());
153 G4cout <<
"Particle has energy (" << particleEnergy <<
") for shower lib and shower lib is on! Accept particle!" << G4endl;
158 G4cout <<
"Particle has energy (" << particleEnergy <<
") outside killing, shower lib and parametrisation "
159 <<
"or some features are switched off ... returning it to Geant " << G4endl;
170 G4cout <<
"LArFastShower::ModelTrigger() particle failed CheckContainment()... will not be parameterised: " << G4endl;
176 G4cout <<
"LArFastShower::ModelTrigger() direction: " << fastTrack.GetPrimaryTrackLocalDirection() << G4endl;
177 G4cout <<
"LArFastShower::ModelTrigger() mom dir: " << fastTrack.GetPrimaryTrack()->GetMomentumDirection() << G4endl;
187 G4cout <<
"LArFastShower::Doit()" << G4endl;
192 std::unique_ptr<const HepMC::GenEvent> ge =
GetGenEvent(fastTrack);
201 G4cout <<
"LArFastShower::Doit() done" << G4endl;
214 G4cout <<
"Low energy particle is being killed: " << fastTrack.GetPrimaryTrack()->GetKineticEnergy() << G4endl;
218 fastStep.KillPrimaryTrack();
219 fastStep.SetPrimaryTrackPathLength(0.0);
228 G4cout <<
"LArFastShower::UseShowerLib()" << G4endl;
237 const std::vector<EnergySpot> shower =
241 G4cout <<
"Got shower (" << shower.size() <<
") from shower lib" << G4endl;
245 for (
const auto& a_spot : shower) {
248 G4cout <<
"Make Spot: " << a_spot.GetPosition().x() <<
" "
249 << a_spot.GetPosition().y() <<
" " << a_spot.GetPosition().z()
250 <<
" " << a_spot.GetEnergy() <<
" " << a_spot.GetTime() << G4endl;
255 G4cout <<
"Made Spot" << G4endl;
261 G4cout <<
"LArFastShower::UseShowerLib() Done" << G4endl;
269 G4cout <<
"FastShower::UseShowerLib ERROR Handling an exception in LArFastShower::" <<
e.what() << G4endl;
278 G4ThreeVector showerDirection = fastTrack.GetPrimaryTrack()->GetMomentumDirection();
279 G4ThreeVector initialShowerPosition = fastTrack.GetPrimaryTrack()->GetPosition();
280 G4ThreeVector orthoShower = showerDirection.orthogonal();
281 G4ThreeVector crossShower = showerDirection.cross(orthoShower);
284 G4cout <<
"LArFastShower::CheckContainment() orthoShower: " << orthoShower << G4endl;
285 G4cout <<
"LArFastShower::CheckContainment() crossShower: " << crossShower << G4endl;
305 if (
Z == 0.0 &&
R == 0.0) {
312 G4double Zmx =
Z / 3;
314 G4int cosPhi[4] = {1,0,-1,0};
315 G4int sinPhi[4] = {0,1,0,-1};
318 G4cout <<
"LArFastShower::CheckContainment() R = " <<
R << G4endl;
319 G4cout <<
"LArFastShower::CheckContainment() Z = " <<
Z << G4endl;
322 G4ThreeVector position;
324 G4VSolid* caloSolid = fastTrack.GetEnvelopeSolid();
325 const G4AffineTransform* affineTransformation = fastTrack.GetAffineTransformation();
328 position = initialShowerPosition;
329 affineTransformation->ApplyPointTransform(position);
330 if(caloSolid->Inside(position) == kOutside)
334 position = initialShowerPosition +
Z*showerDirection;
335 affineTransformation->ApplyPointTransform(position);
336 if(caloSolid->Inside(position) == kOutside)
340 for(
int i=0;
i<4 ;
i++)
342 position = initialShowerPosition + Zmx*showerDirection +
343 R*cosPhi[
i]*orthoShower +
R*sinPhi[
i]*crossShower;
344 affineTransformation->ApplyPointTransform(position);
345 if(caloSolid->Inside(position) == kOutside)
350 G4cout <<
"LArFastShower::CheckContainment() Shower is contained " << G4endl;
359 const G4ThreeVector showerPos = fastTrack.GetPrimaryTrack()->GetPosition();
360 const G4ThreeVector showerMom = fastTrack.GetPrimaryTrack()->GetMomentum();
361 const G4double
energy = fastTrack.GetPrimaryTrack()->GetKineticEnergy();
363 G4int pdgcode = fastTrack.GetPrimaryTrack()->GetDefinition()->GetPDGEncoding();
364 if (pdgcode < 0) pdgcode = -pdgcode;
367 HepMC3::Units::MomentumUnit momentumUnit = HepMC3::Units::MEV;
370 HepMC::Units::MomentumUnit momentumUnit = HepMC::Units::MEV;
374 std::unique_ptr<HepMC::GenEvent> ge = std::make_unique<HepMC::GenEvent>(momentumUnit,lengthUnit);
380 HepMC::FourVector(showerPos.x(), showerPos.y(), showerPos.z(), 0) );
386 HepMC::FourVector(0.,0.,0.,0.),
388 gv->add_particle_in(gpi);
392 HepMC::FourVector(showerMom.x(), showerMom.y(), showerMom.z(),
energy),
394 gv->add_particle_out(gpo);
403 if ( &
particleType == G4Electron::ElectronDefinition() ||
406 }
else if ( &
particleType == G4Gamma::GammaDefinition() ) {
408 }
else if ( &
particleType == G4Neutron::NeutronDefinition() ) {
410 }
else if ( &
particleType == G4PionPlus::PionPlusDefinition() ||
418 if ( &
particleType == G4Electron::ElectronDefinition() ||
421 }
else if ( &
particleType == G4Gamma::GammaDefinition() ) {
423 }
else if ( &
particleType == G4Neutron::NeutronDefinition() ) {
425 }
else if ( &
particleType == G4PionPlus::PionPlusDefinition() ||
434 if ( &
particleType == G4Electron::ElectronDefinition() ||
437 }
else if ( &
particleType == G4Gamma::GammaDefinition() ) {
439 }
else if ( &
particleType == G4Neutron::NeutronDefinition() ) {
441 }
else if ( &
particleType == G4PionPlus::PionPlusDefinition() ||
460 G4ThreeVector initialShowerPosition = fastTrack.GetPrimaryTrack()->GetPosition();