Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
RHadronsPhysicsTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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* pythiaDecayProcess = new G4Decay();
76  pythiaDecayProcess->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  // Look for native G4Decay process
97  G4ProcessVector *fullProcessList = processMgr->GetProcessList(); // NB G4ProcessVector does not support range-based for loops in G4 10.6....
98  std::vector< G4VProcess * > existingDecayProcesses; existingDecayProcesses.reserve(2);
99  for (unsigned int i=0; i<fullProcessList->size(); ++i) {
100  G4VProcess* process = (*fullProcessList)[i];
101  if (process->GetProcessType() == fDecay) {
102  ATH_MSG_VERBOSE ( "Found a pre-existing decay process for " <<particle->GetParticleName() << " (" << pid << "). Will remove in favour of using RHadronPythiaDecayer." );
103  existingDecayProcesses.push_back(process);
104  }
105  }
106  // Actually remove the existing decay processes
107  for (G4VProcess* process : existingDecayProcesses) {
108  processMgr->RemoveProcess(process);
109  }
110  // Cross-check
111  for (unsigned int i=0; i<fullProcessList->size(); ++i) {
112  G4VProcess* process = (*fullProcessList)[i];
113  if (process->GetProcessType() == fDecay) {
114  ATH_MSG_WARNING ( "There is another decay process for " <<particle->GetParticleName() << " (" << pid << ") already defined!" );
115  processMgr->DumpInfo();
116  }
117  }
118  ATH_MSG_VERBOSE ( "Adding decay process for " <<particle->GetParticleName() << " (" << pid << ") using RHadronPythiaDecayer." );
119  processMgr->AddProcess(pythiaDecayProcess);
120  processMgr->SetProcessOrdering(pythiaDecayProcess, idxPostStep); processMgr->SetProcessOrdering(pythiaDecayProcess, idxAtRest);
121  //processMgr->DumpInfo();
122  } else {
123  ATH_MSG_WARNING ( "Particle with pdgid "<<pid<<" has no definition in G4?" );
124  }
125  } // Loop over all particles that we need to define
126 
127  // Now add RHadrons... Keep a vector of those we've already dealt with
128  std::vector<int> handled;
129  // Use the G4 particle iterator
130  while ((*particleIterator)()) {
131  G4ParticleDefinition *particle = particleIterator->value();
133  const int pid = particle->GetPDGEncoding();
134  if (find(handled.begin(), handled.end(), pid) == handled.end()) {
135  handled.push_back(pid);
136  ATH_MSG_VERBOSE ( particle->GetParticleName() << " (" << particle->GetPDGEncoding() << ") " << " is a Custom Particle. Attempting to add a decay process." );
137  G4ProcessManager *processMgr = particle->GetProcessManager();
138  // Look for native G4Decay process
139  G4ProcessVector *fullProcessList = processMgr->GetProcessList(); // NB G4ProcessVector does not support range-based for loops in G4 10.6....
140  std::vector< G4VProcess * > existingDecayProcesses; existingDecayProcesses.reserve(2);
141  for (unsigned int i=0; i<fullProcessList->size(); ++i) {
142  G4VProcess* process = (*fullProcessList)[i];
143  if (process->GetProcessType() == fDecay) {
144  ATH_MSG_VERBOSE ( "Found a pre-existing decay process for " <<particle->GetParticleName() << " (" << pid << "). Will remove in favour of using RHadronPythiaDecayer." );
145  existingDecayProcesses.push_back(process);
146  }
147  }
148  // Actually remove the existing decay process(es)
149  for (G4VProcess* process : existingDecayProcesses) {
150  processMgr->RemoveProcess(process);
151  }
152  // Cross-check
153  for (unsigned int i=0; i<fullProcessList->size(); ++i) {
154  G4VProcess* process = (*fullProcessList)[i];
155  if (process->GetProcessType() == fDecay) {
156  ATH_MSG_WARNING ( "There is another decay process for " <<particle->GetParticleName() << " (" << pid << ") already defined!" );
157  processMgr->DumpInfo();
158  }
159  }
160  if (particle->GetParticleType()=="rhadron" ) {
161  processMgr->AddDiscreteProcess(new FullModelHadronicProcess());
162  if (pythiaDecayProcess->IsApplicable(*particle)) {
163  ATH_MSG_VERBOSE ( "Adding decay..." );
164  processMgr->AddProcess(pythiaDecayProcess);
165  // set ordering for PostStepDoIt and AtRestDoIt
166  processMgr->SetProcessOrdering(pythiaDecayProcess, idxPostStep);
167  processMgr->SetProcessOrdering(pythiaDecayProcess, idxAtRest);
168  } else {
169  ATH_MSG_WARNING ( "No decay allowed for " << particle->GetParticleName() );
170  if (!particle->GetPDGStable() && particle->GetPDGLifeTime()<0.1*CLHEP::ns) {
171  ATH_MSG_WARNING ( "Gonna decay it anyway!!!" );
172  processMgr->AddProcess(pythiaDecayProcess);
173  // set ordering for PostStepDoIt and AtRestDoIt
174  processMgr->SetProcessOrdering(pythiaDecayProcess, idxPostStep);
175  processMgr->SetProcessOrdering(pythiaDecayProcess, idxAtRest);
176  }
177  }
178  }
179  if (particle->GetPDGCharge()/CLHEP::eplus != 0) {
180  processMgr->AddProcess(new G4hMultipleScattering, -1, 1, 1);
181  processMgr->AddProcess(new G4hIonisation, -1, 2, 2);
182  ATH_MSG_VERBOSE ( "Processes for charged particle added." );
183  } else {
184  ATH_MSG_VERBOSE ( "It is neutral!!" );
185  }
186  processMgr->DumpInfo();
187  } else {
188  ATH_MSG_VERBOSE ( "Skipping already handled particle: "<<particle->GetParticleName() );
189  } // If it has not been handled yet
190  } // If this is one of our custom particles (RHadrons)
191  } // End of the particle iterator
192  ATH_MSG_DEBUG("RHadronsPhysicsTool::ConstructProcess() - list of handled RHadrons = " << handled);
193  ATH_MSG_DEBUG("RHadronsPhysicsTool::ConstructProcess() - end");
194 }
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:32
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
SUSY_SimplifiedModel_PostInclude.process
string process
Definition: SUSY_SimplifiedModel_PostInclude.py:42
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
RHadronsPhysicsTool::ConstructParticle
virtual void ConstructParticle()
Definition: RHadronsPhysicsTool.cxx:66
lumiFormat.i
int i
Definition: lumiFormat.py:85
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:18
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:22
CustomParticleFactory::isCustomParticle
static bool isCustomParticle(G4ParticleDefinition *particle)
Definition: CustomParticleFactory.cxx:26
RHadronsPhysicsTool::GetPhysicsOption
virtual RHadronsPhysicsTool * GetPhysicsOption()
Implements.
Definition: RHadronsPhysicsTool.cxx:60
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
RHadronsPhysicsTool::~RHadronsPhysicsTool
virtual ~RHadronsPhysicsTool()
Destructor.
Definition: RHadronsPhysicsTool.cxx:46
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
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:76