ATLAS Offline Software
AddPhysicsDecayTool.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 // Include files
6 
7 // local
9 
10 #include <sstream>
11 
12 // Geant4 physics lists
13 
14 
15 #include "G4ProcessManager.hh"
16 #include "G4ParticleTable.hh"
17 #include "G4DecayTable.hh"
18 #include "G4VDecayChannel.hh"
19 #include "G4PhaseSpaceDecayChannel.hh"
20 //-----------------------------------------------------------------------------
21 // Implementation file for class : AddPhysicsDecayTool
22 //
23 // 15-05-2015 : Edoardo Farina
24 //-----------------------------------------------------------------------------
25 #include "G4Version.hh"
26 #if G4VERSION_NUMBER > 1029
27 #define PARTICLEITERATOR (this->GetParticleIterator())
28 #elif G4VERSION_NUMBER > 1009
29 #define PARTICLEITERATOR aParticleIterator
30 #else
31 #define PARTICLEITERATOR theParticleIterator
32 #endif
33 
34 //=============================================================================
35 // Standard constructor, initializes variables
36 //=============================================================================
38  const std::string& nam,const IInterface* parent )
39  : base_class ( type, nam , parent )
40 {
41  m_physicsOptionType = G4AtlasPhysicsOption::Type::GlobalProcesses;
42 }
43 
44 //=============================================================================
45 // Destructor
46 //=============================================================================
47 
49 {
50 }
51 
52 //=============================================================================
53 // Initialize
54 //=============================================================================
56 {
57  ATH_MSG_DEBUG("AddPhysicsDecayTool initialize( )");
58  ATH_MSG_DEBUG("Add Decay to the particle: "<<m_ParticleName);
59 
60  std::istringstream ss(m_Daughters);
61  std::string token;
62 
63  while(std::getline(ss, token, ','))
64  {
65  m_Daughters_vec.push_back(token);
66  }
67 
68  return StatusCode::SUCCESS;
69 }
70 
72 {
73  PARTICLEITERATOR->reset();
74  while( (*PARTICLEITERATOR)() )
75  {
76  G4ParticleDefinition *particle = PARTICLEITERATOR->value();
77  if (m_ParticleName.value()== static_cast<const std::string&>(particle->GetParticleName()))
78  {
79 
80  G4DecayTable *table = particle->GetDecayTable();
81  if (!table)
82  {
83  table = new G4DecayTable();
84  }
85 
86  G4VDecayChannel *mode_vec(nullptr);
87 
88  if (m_Daughters_vec.size()==2)
89  {
90  mode_vec = new G4PhaseSpaceDecayChannel(m_ParticleName.value(),m_BR,2,m_Daughters_vec[0],m_Daughters_vec[1]);
91  }
92  else if (m_Daughters_vec.size()==3)
93  {
94  mode_vec = new G4PhaseSpaceDecayChannel(m_ParticleName.value(),m_BR,3,m_Daughters_vec[0],m_Daughters_vec[1],m_Daughters_vec[2]);
95  }
96  else if (m_Daughters_vec.size()==4)
97  {
98  mode_vec = new G4PhaseSpaceDecayChannel(m_ParticleName.value(),m_BR,4,m_Daughters_vec[0],m_Daughters_vec[1],m_Daughters_vec[2],m_Daughters_vec[3]);
99  }
100  else
101  {
102  //This could be checked during initialize also
103  ATH_MSG_FATAL("No decay in more than 4 particles allowed");
104  throw "Decay with more than four particles";
105  }
106  /*
107  for (int i=0; i<table->entries(); i++)
108  {
109  if(*(table->GetDecayChannel(i))==*mode_vec)
110  {
111  ATH_MSG_FATAL("Trying to Add a decay already present" );
112  throw "FailedAddDecay";
113  }
114  }
115  */
116 
117  table->Insert(mode_vec);
118 
119  ATH_MSG_DEBUG( "Adding decay to "<<m_ParticleName.value() );
120  particle->SetDecayTable(table);
121  }
122  }
123 }
124 
125 
127 {
128 
129  return this;
130 }
131 
132 
133 
135 {
136  //This should remain empty
137 }
AddPhysicsDecayTool::m_ParticleName
Gaudi::Property< std::string > m_ParticleName
Definition: AddPhysicsDecayTool.h:41
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
AddPhysicsDecayTool
Definition: AddPhysicsDecayTool.h:24
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
PARTICLEITERATOR
#define PARTICLEITERATOR
Definition: AddPhysicsDecayTool.cxx:31
AddPhysicsDecayTool::initialize
virtual StatusCode initialize() override
Initialize method.
Definition: AddPhysicsDecayTool.cxx:55
AddPhysicsDecayTool::m_Daughters_vec
std::vector< std::string > m_Daughters_vec
Definition: AddPhysicsDecayTool.h:44
AddPhysicsDecayTool.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
AddPhysicsDecayTool::GetPhysicsOption
virtual AddPhysicsDecayTool * GetPhysicsOption() override
Definition: AddPhysicsDecayTool.cxx:126
test_pyathena.parent
parent
Definition: test_pyathena.py:15
python.ext.table_printer.table
list table
Definition: table_printer.py:81
G4AtlasPhysicsOption::GlobalProcesses
@ GlobalProcesses
Definition: IPhysicsOptionTool.h:25
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AddPhysicsDecayTool::~AddPhysicsDecayTool
virtual ~AddPhysicsDecayTool()
Destructor.
Definition: AddPhysicsDecayTool.cxx:48
AddPhysicsDecayTool::ConstructParticle
virtual void ConstructParticle() override
Definition: AddPhysicsDecayTool.cxx:134
AddPhysicsDecayTool::AddPhysicsDecayTool
AddPhysicsDecayTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: AddPhysicsDecayTool.cxx:37
AddPhysicsDecayTool::ConstructProcess
virtual void ConstructProcess() override
Definition: AddPhysicsDecayTool.cxx:71
AddPhysicsDecayTool::m_Daughters
Gaudi::Property< std::string > m_Daughters
Definition: AddPhysicsDecayTool.h:43
AddPhysicsDecayTool::m_BR
Gaudi::Property< double > m_BR
Definition: AddPhysicsDecayTool.h:42