ATLAS Offline Software
RHadronsPhysicsTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // class header
6 #include "RHadronsPhysicsTool.h"
7 // package headers
9 #include "FullModelHadronicProcess.hh"
10 #include "RHadronPythiaDecayer.h"
11 // Geant4 headers
12 #include "globals.hh"
13 #include "G4ParticleTable.hh"
14 #include "G4VProcess.hh"
15 #include "G4Transportation.hh"
16 #include "G4hMultipleScattering.hh"
17 #include "G4hIonisation.hh"
18 #include "G4ProcessManager.hh"
19 #include "G4Decay.hh"
20 #include "G4BaryonConstructor.hh"
21 
22 // STL headers
23 #include <string>
24 
25 
26 //-----------------------------------------------------------------------------
27 // Implementation file for class : RHadronsPhysicsTool
28 //
29 // 2015-05-14 Edoardo Farina
30 //-----------------------------------------------------------------------------
31 
32 //=============================================================================
33 // Standard constructor, initializes variables
34 //=============================================================================
36  const std::string& nam,const IInterface* parent )
37  : base_class ( type, nam , parent )
38 {
39  m_physicsOptionType = G4AtlasPhysicsOption::Type::BSMPhysics;
40 }
41 
42 //=============================================================================
43 // Destructor
44 //=============================================================================
45 
47 {
48 }
49 
50 //=============================================================================
51 // Initialize
52 //=============================================================================
54 {
55  ATH_MSG_DEBUG("RHadronsPhysicsTool::initialize()");
56  this->SetPhysicsName(name());
57  return StatusCode::SUCCESS;
58 }
59 
61 {
62  return this;
63 }
64 
65 
67 {
68  ATH_MSG_DEBUG("RHadronsPhysicsTool::ConstructParticle() - start");
70  ATH_MSG_DEBUG("RHadronsPhysicsTool::ConstructParticle() - end");
71 }
73 {
74  ATH_MSG_DEBUG("RHadronsPhysicsTool::ConstructProcess() - start");
75  G4Decay* theDecayProcess = new G4Decay();
76  theDecayProcess->SetExtDecayer( new RHadronPythiaDecayer("RHadronPythiaDecayer") );
77  G4ParticleTable::G4PTblDicIterator* particleIterator = G4ParticleTable::GetParticleTable()->GetIterator();
78  particleIterator->reset();
79 
80  //First deal with the standard particles that G4 doesn't know about...
81  //G4Etac::Definition();
82  G4BaryonConstructor::ConstructParticle();
83  ATH_MSG_DEBUG("RHadronsPhysicsTool::ConstructProcess() - m_standardpdgidtodecay = " << m_standardpdgidtodecay);
84  G4ProcessManager *templateProcessMgr = G4ParticleTable::GetParticleTable()->FindParticle(4122)->GetProcessManager();
85  for (const int pid : m_standardpdgidtodecay.value()) {
86  ATH_MSG_VERBOSE ( "Adding decay for "<<pid );
87  G4ParticleDefinition *particle = G4ParticleTable::GetParticleTable()->FindParticle( pid );
88  if (particle) {
89  ATH_MSG_VERBOSE ( particle->GetParticleName()<<" is standard for Pythia, lifetime is "<<particle->GetPDGLifeTime() );
90  G4ProcessManager *processMgr = particle->GetProcessManager();
91  if (!processMgr) {
92  ATH_MSG_VERBOSE ( "No process manager found for " << particle->GetParticleName() << " (" << pid << "). Copying process manager from 4122 (one we know works) to this particle" );
93  particle->SetProcessManager(new G4ProcessManager(*templateProcessMgr));
94  processMgr = particle->GetProcessManager();
95  }
96  G4ProcessVector *pros = processMgr->GetProcessList();
97  for (unsigned int pi=0; pi<pros->size(); ++pi) {
98  if ((*pros)[pi]->GetProcessType()==fDecay) {
99  ATH_MSG_VERBOSE ( "Found a pre-existing decay process for " <<particle->GetParticleName() << " (" << pid << "). Will remove in favour of using RHadronPythiaDecayer." );
100  processMgr->RemoveProcess(pi);
101  break;
102  }
103  }
104  for (unsigned int pi=0; pi<pros->size(); ++pi) {
105  if ((*pros)[pi]->GetProcessType()==fDecay) {
106  ATH_MSG_WARNING ( "There is another decay process for " <<particle->GetParticleName() << " (" << pid << ") already defined!" );
107  processMgr ->DumpInfo();
108  }
109  }
110  ATH_MSG_VERBOSE ( "Adding decay process for " <<particle->GetParticleName() << " (" << pid << ") using RHadronPythiaDecayer." );
111  processMgr ->AddProcess(theDecayProcess);
112  processMgr ->SetProcessOrdering(theDecayProcess, idxPostStep); processMgr ->SetProcessOrdering(theDecayProcess, idxAtRest);
113  //processMgr ->DumpInfo();
114  } else {
115  ATH_MSG_WARNING ( "Particle with pdgid "<<pid<<" has no definition in G4?" );
116  }
117  } // Loop over all particles that we need to define
118 
119  // Now add RHadrons... Keep a vector of those we've already dealt with
120  std::vector<int> handled;
121  // Use the G4 particle iterator
122  while ((*particleIterator)()) {
123  G4ParticleDefinition *particle = particleIterator->value();
125  if (find(handled.begin(),handled.end(),particle->GetPDGEncoding())==handled.end()) {
126  handled.push_back(particle->GetPDGEncoding());
127  ATH_MSG_VERBOSE ( particle->GetParticleName() << " (" << particle->GetPDGEncoding() << ") " << " is a Custom Particle. Attempting to add a decay process." );
128  G4ProcessManager *processMgr = particle->GetProcessManager();
129  if (particle->GetParticleType()=="rhadron" ||
130  particle->GetParticleType()=="mesonino" ||
131  particle->GetParticleType()=="sbaryon" ) {
132  processMgr->AddDiscreteProcess(new FullModelHadronicProcess());
133  if (theDecayProcess->IsApplicable(*particle)) {
134  ATH_MSG_VERBOSE ( "Adding decay..." );
135  processMgr ->AddProcess(theDecayProcess);
136  // set ordering for PostStepDoIt and AtRestDoIt
137  processMgr->SetProcessOrdering(theDecayProcess, idxPostStep);
138  processMgr->SetProcessOrdering(theDecayProcess, idxAtRest);
139  } else {
140  ATH_MSG_WARNING ( "No decay allowed for " << particle->GetParticleName() );
141  if (!particle->GetPDGStable() && particle->GetPDGLifeTime()<0.1*CLHEP::ns) {
142  ATH_MSG_WARNING ( "Gonna decay it anyway!!!" );
143  processMgr->AddProcess(theDecayProcess);
144  // set ordering for PostStepDoIt and AtRestDoIt
145  processMgr->SetProcessOrdering(theDecayProcess, idxPostStep);
146  processMgr->SetProcessOrdering(theDecayProcess, idxAtRest);
147  }
148  }
149  }
150  if (particle->GetPDGCharge()/CLHEP::eplus != 0) {
151  processMgr->AddProcess(new G4hMultipleScattering, -1, 1, 1);
152  processMgr->AddProcess(new G4hIonisation, -1, 2, 2);
153  ATH_MSG_VERBOSE ( "Processes for charged particle added." );
154  } else {
155  ATH_MSG_VERBOSE ( "It is neutral!!" );
156  }
157  processMgr->DumpInfo();
158  } else {
159  ATH_MSG_VERBOSE ( "Skipping already handled particle: "<<particle->GetParticleName() );
160  } // If it has not been handled yet
161  } // If this is one of our custom particles (RHadrons)
162  } // End of the particle iterator
163  ATH_MSG_DEBUG("RHadronsPhysicsTool::ConstructProcess() - list of handled RHadrons = " << handled);
164  ATH_MSG_DEBUG("RHadronsPhysicsTool::ConstructProcess() - end");
165 }
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
RHadronPythiaDecayer.h
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
RHadronsPhysicsTool::ConstructProcess
virtual void ConstructProcess()
Definition: RHadronsPhysicsTool.cxx:72
CustomParticleFactory::loadCustomParticles
static void loadCustomParticles()
Definition: CustomParticleFactory.cxx:27
RHadronsPhysicsTool::initialize
virtual StatusCode initialize()
Initialize method.
Definition: RHadronsPhysicsTool.cxx:53
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
RHadronsPhysicsTool::RHadronsPhysicsTool
RHadronsPhysicsTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: RHadronsPhysicsTool.cxx:35
RHadronsPhysicsTool::ConstructParticle
virtual void ConstructParticle()
Definition: RHadronsPhysicsTool.cxx:66
pi
#define pi
Definition: TileMuonFitter.cxx:65
RHadronsPhysicsTool.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
RHadronPythiaDecayer
Definition: RHadronPythiaDecayer.h:17
CustomParticleFactory.h
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
test_pyathena.parent
parent
Definition: test_pyathena.py:15
RHadronsPhysicsTool
Definition: RHadronsPhysicsTool.h:21
CustomParticleFactory::isCustomParticle
static bool isCustomParticle(G4ParticleDefinition *particle)
Definition: CustomParticleFactory.cxx:21
RHadronsPhysicsTool::GetPhysicsOption
virtual RHadronsPhysicsTool * GetPhysicsOption()
Implements.
Definition: RHadronsPhysicsTool.cxx:60
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
RHadronsPhysicsTool::~RHadronsPhysicsTool
virtual ~RHadronsPhysicsTool()
Destructor.
Definition: RHadronsPhysicsTool.cxx:46
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
python.SystemOfUnits.ns
int ns
Definition: SystemOfUnits.py:130
python.SystemOfUnits.eplus
int eplus
Definition: SystemOfUnits.py:137
G4AtlasPhysicsOption::BSMPhysics
@ BSMPhysics
Definition: IPhysicsOptionTool.h:22
RHadronsPhysicsTool::m_standardpdgidtodecay
IntegerArrayProperty m_standardpdgidtodecay
Definition: RHadronsPhysicsTool.h:75