DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
Geant4ExtraParticles.cpp
Go to the documentation of this file.
1 //
2 // Authors: Tomohiko Tanabe <tomohiko@icepp.s.u-tokyo.ac.jp>
3 // Taikan Suehara <suehara@icepp.s.u-tokyo.ac.jp>
4 // Ported from Mokka by A.Sailer (CERN )
5 //
6 
20 #include "Geant4ExtraParticles.h"
22 #include <DDG4/Geant4Kernel.h>
23 #include <DDG4/Factories.h>
24 
25 #include <G4ParticleTable.hh>
26 #include <G4ParticleDefinition.hh>
27 #include <G4PhysicalConstants.hh>
28 #include <G4Version.hh>
29 
30 #include <CLHEP/Units/SystemOfUnits.h>
31 #include <CLHEP/Units/PhysicalConstants.h>
32 
33 #include <fstream>
34 #include <sstream>
35 #include <string>
36 
37 using namespace dd4hep::sim;
38 
39 Geant4ExtraParticles::Geant4ExtraParticles(Geant4Context* ctxt, const std::string& nam)
40  : Geant4PhysicsConstructor(ctxt, nam)
41 {
42  declareProperty("pdgfile", m_pdgfile);
43 }
44 
46 
47 
48 void Geant4ExtraParticles::constructParticle(Constructor& ) {
49  if (m_pdgfile.empty()) return;
50 
51  info("pdgfile: %s",m_pdgfile.c_str());
52 
53  G4ParticleTable *theParticleTable = G4ParticleTable::GetParticleTable();
54  std::ifstream pdgFile( m_pdgfile.c_str(), std::ifstream::in );
55 
56  if (!pdgFile.is_open()) {
57  except("Could not open pdgfile: %s",m_pdgfile.c_str());
58  return;
59  }
60 
61  info("opened pdgfile: %s",m_pdgfile.c_str());
62 
63  while ( !pdgFile.eof() ) {
64  // read line
65  std::string linebuf;
66  getline( pdgFile, linebuf );
67 
68  // ignore comments
69  if (linebuf.substr(0,1) == "#") continue;
70  if (linebuf.substr(0,2) == "//") continue;
71 
72  // ignore empty lines
73  if (linebuf.empty()) continue;
74 
75  // parse line
76  int pdg;
77  std::string nam;
78  double charge;
79  double mass;
80  double width;
81  double lifetime;
82 
83  std::istringstream istr(linebuf);
84 
85  istr >> pdg >> nam >> charge >> mass >> width >> lifetime;
86 
87  // do add particles that don't fly
88  // if (lifetime == 0) continue;
89 
90  //unstable particles with too small lifetime have width -1
91  bool stable = (width > 0 or width < -0.5) ? false : true;
92 
93  if(width<0) width = 0;
94 
95  // normalize to G4 units
96  mass *= CLHEP::GeV;
97 
98  if (charge != 0) {
99  charge /= 3.;
100  }
101 
102  if (lifetime > 0) {
103  lifetime = lifetime*CLHEP::mm/CLHEP::c_light;
104  }
105 
106  if (width == 0 && lifetime > 0) {
107  width = CLHEP::hbar_Planck/lifetime;
108  }
109 
110  // don't add if the particle already exists
111  G4ParticleDefinition* p = theParticleTable->FindParticle(pdg);
112  if ( !p ) {
113 
114  if (abs(pdg)>80 && abs(pdg)<=100) {
115  // don't add generator-specific particles
116  } else {
117  /*
118  if (pdg==5122) {
119  G4cout << "Lambda_b0: " << "PDG=" << pdg << ", name=" << name << ", chrg=" << charge
120  << ", mass=" << mass << ", width=" << width << ", lifetime=" << lifetime << "\n";
121  G4cout << "debug: mass=" << 5.62 << ", width =" << 1.39e-12/6.582e-16 << ", lifetime=" << 1.39e-12 << "\n";
122  }
123  //*/
124  p = new G4ParticleDefinition(
125  nam, // name
126  mass, // mass
127  width, // width
128  charge, // charge
129  0, // 2*spin
130  0, // parity
131  0, // C-conjugation
132  0, // 2*isospin
133  0, // 2*isospin3
134  0, // G-parity
135  "extra", // type
136  0, // lepton number
137  0, // baryon number
138  pdg, // PDG encoding
139  stable, // stable
140  lifetime, // lifetime
141  NULL, // decay table
142  false); // short lived
143  }
144  }
145  }
146 
147  G4cout << "Loaded extra particles using file: " << m_pdgfile << G4endl;
148 }
149 
150 void Geant4ExtraParticles::constructProcess(Constructor& ctor) {
151  G4ParticleTable::G4PTblDicIterator* ParticleIterator = ctor.particleIterator();
152  while((*ParticleIterator)()) {
153  G4ParticleDefinition* pdef = ParticleIterator->value();
154  G4ProcessManager* pmgr = pdef->GetProcessManager();
155  if (pdef->GetParticleType() == "extra") {
156  if (pdef->GetPDGCharge() != 0) {
157  pmgr->AddProcess(new G4hMultipleScattering(), -1, 1, 1); //multiple scattering
158  pmgr->AddProcess(new G4hIonisation(), -1, 2, 2); // ionisation
159  } else {
160  //nothing to do
161  }
162  }
163  }
164 }
165 
Geant4PhysicsConstructor.h
Geant4ExtraParticles
PhysicsConstructor to add additional particles to geant.
dd4hep::sim::Geant4ExtraParticles::Geant4ExtraParticles
Geant4ExtraParticles(Geant4Context *ctxt, const std::string &nam)
Standard constructor with initailization parameters.
DECLARE_GEANT4ACTION
#define DECLARE_GEANT4ACTION(name)
Plugin defintion to create Geant4Action objects.
Definition: Factories.h:210
dd4hep::sim::Geant4ExtraParticles::constructProcess
virtual void constructProcess(Constructor &ctor)
Callback to construct processes (uses the G4 particle table)
dd4hep::sim::Geant4Action::info
void info(const char *fmt,...) const
Support of info messages.
Definition: Geant4Action.cpp:215
dd4hep::sim::Geant4Action::except
void except(const char *fmt,...) const
Support of exceptions: Print fatal message and throw runtime_error.
Definition: Geant4Action.cpp:256
dd4hep::sim::Geant4ExtraParticles::constructParticle
virtual void constructParticle(Constructor &ctor)
Callback to construct particles.
Factories.h
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition: Geant4Output2EDM4hep.cpp:49
dd4hep::sim::Geant4ExtraParticles::~Geant4ExtraParticles
virtual ~Geant4ExtraParticles()
Default destructor.
Geant4Kernel.h
dd4hep::sim::Geant4ExtraParticles::m_pdgfile
std::string m_pdgfile
Definition: Geant4ExtraParticles.h:42
dd4hep::sim::Geant4PhysicsConstructor
Implementation base of a Geant4 physics constructor.
Definition: Geant4PhysicsConstructor.h:49
Geant4ExtraParticles.h
dd4hep::sim::Geant4Context
Generic context to extend user, run and event information.
Definition: Geant4Context.h:201