Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ParticleDefinition.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4ParticleDefinition class implementation
27//
28// Authors: G.Cosmo, 2 December 1995 - Design, based on object model
29// M.Asai, 29 January 1996 - First implementation
30// History:
31// - 1996-2003, H.Kurashige - Revisions
32// - 11.03.2003, H.Kurashige - Restructuring for Cuts per Region
33// - 25.01.2013, G.Cosmo, A.Dotti - Introduced thread-safety for MT
34// - 15.06.2017, K.L.Genser - Added support for MuonicAtom
35// --------------------------------------------------------------------
36
39#include "G4SystemOfUnits.hh"
40#include "G4ParticleTable.hh"
41#include "G4IonTable.hh"
42#include "G4DecayTable.hh"
43#include "G4PDGCodeChecker.hh"
44#include "G4StateManager.hh"
45#include "G4UnitsTable.hh"
46#include "G4Threading.hh"
47
48// This new field helps to use the class G4PDefManager.
49//
50G4PDefManager G4ParticleDefinition::subInstanceManager;
51
52// This macro changes the references to fields that are now encapsulated
53// in the class G4PDefData.
54//
55#define G4MT_pmanager ((subInstanceManager.offset()[g4particleDefinitionInstanceID]).theProcessManager)
56
57// --------------------------------------------------------------------
59 const G4String& aName,
60 G4double mass,
61 G4double width,
62 G4double charge,
63 G4int iSpin,
64 G4int iParity,
65 G4int iConjugation,
66 G4int iIsospin,
67 G4int iIsospin3,
68 G4int gParity,
69 const G4String& pType,
70 G4int lepton,
71 G4int baryon,
73 G4bool stable,
74 G4double lifetime,
75 G4DecayTable* decaytable,
76 G4bool shortlived,
77 const G4String& subType,
78 G4int anti_encoding,
79 G4double magneticMoment)
80
81 : theParticleName(aName),
82 thePDGMass(mass),
83 thePDGWidth(width),
84 thePDGCharge(charge),
85 thePDGiSpin(iSpin),
86 thePDGSpin(iSpin*0.5),
87 thePDGiParity(iParity),
88 thePDGiConjugation(iConjugation),
89 thePDGiGParity(gParity),
90 thePDGiIsospin(iIsospin),
91 thePDGiIsospin3(iIsospin3),
92 thePDGIsospin(iIsospin*0.5),
93 thePDGIsospin3(iIsospin3*0.5),
94 thePDGMagneticMoment(magneticMoment),
95 theLeptonNumber(lepton),
96 theBaryonNumber(baryon),
97 theParticleType(pType),
98 theParticleSubType(subType),
99 thePDGEncoding(encoding),
100 theAntiPDGEncoding(-1*encoding),
101 fShortLivedFlag(shortlived),
102 thePDGStable(stable),
103 thePDGLifeTime(lifetime),
104 theDecayTable(decaytable)
105{
106 static const G4String nucleus("nucleus");
107 static const G4String muAtom("MuonicAtom");
108
109 g4particleDefinitionInstanceID = -1;
110 theProcessManagerShadow = 0;
111
112 theParticleTable = G4ParticleTable::GetParticleTable();
113
114 //set verboseLevel equal to ParticleTable
115 verboseLevel = theParticleTable->GetVerboseLevel();
116
117 if (anti_encoding !=0) theAntiPDGEncoding = anti_encoding;
118
119 // check quark contents
120 if (this->FillQuarkContents() != thePDGEncoding)
121 {
122#ifdef G4VERBOSE
123 if (verboseLevel>0)
124 {
125 // Using G4cout expecting that it is available
126 // in construction of static objects
127 G4cout << "Particle " << aName
128 << " has a strange PDGEncoding " << G4endl;
129 }
130#endif
131 G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
132 "PART102", JustWarning,
133 "Strange PDGEncoding ");
134 }
135
136 // check initialization is in Pre_Init state except for ions
137 G4ApplicationState currentState
139
140 if ( !fShortLivedFlag && (theParticleType!=nucleus)
141 && (theParticleType!=muAtom) && (currentState!=G4State_PreInit))
142 {
143#ifdef G4VERBOSE
144 if (GetVerboseLevel()>0)
145 {
146 G4cout << "G4ParticleDefinition (other than ions and shortlived)"
147 << " should be created in Pre_Init state - "
148 << aName << G4endl;
149 }
150#endif
151 G4Exception("G4ParticleDefintion::G4ParticleDefinition()",
152 "PART101", JustWarning,
153 "G4ParticleDefinition should be created in PreInit state");
154 }
155
156
157 if (theParticleTable->GetIonTable()->IsIon(this))
158 {
161 }
162
163 if (theParticleTable->GetIonTable()->IsAntiIon(this))
164 {
165 SetAtomicNumber( std::abs(G4int(GetPDGCharge()/eplus)) );
166 SetAtomicMass( std::abs(GetBaryonNumber()) );
167 }
168
169 // check name and register this particle into ParticleTable
170 theParticleTable->Insert(this);
171}
172
173// --------------------------------------------------------------------
175{
176 G4Exception("G4ParticleDefinition::G4ParticleDefinition()",
177 "PART001", FatalException,
178 "Illegal call of default constructor for G4ParticleDefinition!");
179}
180
181// --------------------------------------------------------------------
183{
184 if (G4ParticleTable::GetParticleTable()->GetReadiness())
185 {
187 G4ApplicationState currentState = pStateManager->GetCurrentState();
188 if (currentState != G4State_PreInit)
189 {
190 G4String msg = "Request of deletion for ";
191 msg += GetParticleName();
192 msg += " has No effects because readyToUse is true.";
193 G4Exception("G4ParticleDefinition::~G4ParticleDefinition()",
194 "PART117", JustWarning, msg);
195 return ;
196 }
197 else
198 {
199#ifdef G4VERBOSE
200 if (verboseLevel>0)
201 {
202 G4cout << GetParticleName() << " will be deleted..." << G4endl;
203 }
204#endif
205 }
206 }
207 delete theDecayTable;
208}
209
210// --------------------------------------------------------------------
212{
213 return (this->theParticleName == right.theParticleName);
214}
215
216// --------------------------------------------------------------------
218{
219 return (this->theParticleName != right.theParticleName);
220}
221
222// --------------------------------------------------------------------
224{
225 // Returns the private data instance manager
226 return subInstanceManager;
227}
228
229// --------------------------------------------------------------------
231{
232 // Clears memory allocated by sub-instance manager
233 subInstanceManager.FreeSlave();
234}
235
236// --------------------------------------------------------------------
238{
239 if(g4particleDefinitionInstanceID<0) return nullptr;
240 return G4MT_pmanager;
241}
242
243// --------------------------------------------------------------------
245{
246 // Calculate quark and anti-quark contents
247 // Returned value is the PDG encoding for this particle.
248 // It means error if the return value is different from
249 // this->thePDGEncoding
250
251 G4int flavor;
252 for (flavor= 0; flavor<NumberOfQuarkFlavor; ++flavor)
253 {
254 theQuarkContent[flavor] = 0;
255 theAntiQuarkContent[flavor] = 0;
256 }
257
258 G4PDGCodeChecker checker;
259 checker.SetVerboseLevel(verboseLevel);
260
261 G4int temp = checker.CheckPDGCode(thePDGEncoding, theParticleType);
262
263 if ( temp != 0)
264 {
265 for (flavor= 0; flavor<NumberOfQuarkFlavor; ++flavor)
266 {
267 theQuarkContent[flavor] = checker.GetQuarkContent(flavor);
268 theAntiQuarkContent[flavor] = checker.GetAntiQuarkContent(flavor);
269 }
270 if ((theParticleType == "meson")||(theParticleType == "baryon"))
271 {
272 // check charge
273 if ( !checker.CheckCharge(thePDGCharge) )
274 {
275 temp = 0;
276 G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
277 "PART103", JustWarning,
278 "Inconsistent charge against PDG code ");
279#ifdef G4VERBOSE
280 if (verboseLevel>0)
281 {
282 G4cout << "G4ParticleDefinition::FillQuarkContents : "
283 << " illegal charge (" << thePDGCharge/eplus
284 << " PDG code=" << thePDGEncoding << G4endl;
285 }
286#endif
287 }
288 // check spin
289 if (checker.GetSpin() != thePDGiSpin)
290 {
291 temp = 0;
292 G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
293 "PART104", JustWarning,
294 "Inconsistent spin against PDG code ");
295#ifdef G4VERBOSE
296 if (verboseLevel>0)
297 {
298 G4cout << "G4ParticleDefinition::FillQuarkContents : "
299 << " illegal SPIN (" << thePDGiSpin << "/2"
300 << " PDG code=" << thePDGEncoding <<G4endl;
301 }
302#endif
303 }
304 }
305 }
306 return temp;
307}
308
309// --------------------------------------------------------------------
311{
312 G4cout << G4endl;
313 G4cout << "--- G4ParticleDefinition ---" << G4endl;
314 G4cout << " Particle Name : " << theParticleName << G4endl;
315 G4cout << " PDG particle code : " << thePDGEncoding;
316 G4cout << " [PDG anti-particle code: " << this->GetAntiPDGEncoding() << "]"<< G4endl;
317 G4cout << " Mass [GeV/c2] : " << thePDGMass/GeV ;
318 G4cout << " Width : " << thePDGWidth/GeV << G4endl;
319 G4cout << " Lifetime [nsec] : " << thePDGLifeTime/ns << G4endl;
320 G4cout << " Charge [e]: " << thePDGCharge/eplus << G4endl;
321 G4cout << " Spin : " << thePDGiSpin << "/2" << G4endl;
322 G4cout << " Parity : " << thePDGiParity << G4endl;
323 G4cout << " Charge conjugation : " << thePDGiConjugation << G4endl;
324 G4cout << " Isospin : (I,Iz): (" << thePDGiIsospin <<"/2";
325 G4cout << " , " << thePDGiIsospin3 << "/2 ) " << G4endl;
326 G4cout << " GParity : " << thePDGiGParity << G4endl;
327 if (thePDGMagneticMoment != 0.0)
328 {
329 G4cout << " MagneticMoment [MeV/T] : "
330 << thePDGMagneticMoment/MeV*tesla << G4endl;
331 }
332 G4cout << " Quark contents (d,u,s,c,b,t) : " << theQuarkContent[0];
333 G4cout << ", " << theQuarkContent[1];
334 G4cout << ", " << theQuarkContent[2];
335 G4cout << ", " << theQuarkContent[3];
336 G4cout << ", " << theQuarkContent[4];
337 G4cout << ", " << theQuarkContent[5] << G4endl;
338 G4cout << " AntiQuark contents : " << theAntiQuarkContent[0];
339 G4cout << ", " << theAntiQuarkContent[1];
340 G4cout << ", " << theAntiQuarkContent[2];
341 G4cout << ", " << theAntiQuarkContent[3];
342 G4cout << ", " << theAntiQuarkContent[4];
343 G4cout << ", " << theAntiQuarkContent[5] << G4endl;
344 G4cout << " Lepton number : " << theLeptonNumber;
345 G4cout << " Baryon number : " << theBaryonNumber << G4endl;
346 G4cout << " Particle type : " << theParticleType ;
347 G4cout << " [" << theParticleSubType << "]" << G4endl;
348
349 if ( (theParticleTable->GetIonTable()->IsIon(this))
350 || (theParticleTable->GetIonTable()->IsAntiIon(this)) )
351 {
352 G4cout << " Atomic Number : " << GetAtomicNumber();
353 G4cout << " Atomic Mass : " << GetAtomicMass() << G4endl;
354 }
355 if ( fShortLivedFlag )
356 {
357 G4cout << " ShortLived : ON" << G4endl;
358 }
359
360 if ( IsGeneralIon() )
361 {
362 G4double lftm = GetIonLifeTime();
363 if(lftm<-1000.)
364 { G4cout << " Stable : No data found -- unknown" << G4endl; }
365 else if(lftm<0.)
366 { G4cout << " Stable : stable" << G4endl; }
367 else
368 {
369 G4cout << " Stable : unstable -- lifetime = " << G4BestUnit(lftm,"Time")
370 << "\n Decay table should be consulted to G4RadioactiveDecayProcess."
371 << G4endl;
372 }
373 }
374 else
375 {
376 if ( thePDGStable )
377 {
378 G4cout << " Stable : stable" << G4endl;
379 }
380 else
381 {
382 if( theDecayTable != nullptr )
383 {
384 theDecayTable->DumpInfo();
385 }
386 else
387 {
388 G4cout << "Decay Table is not defined !!" <<G4endl;
389 }
390 }
391 }
392}
393
394// --------------------------------------------------------------------
396{
397 if (theParticleName=="gamma"
398 || theParticleName=="e-"
399 || theParticleName=="e+"
400 || theParticleName=="proton")
401 {
402 fApplyCutsFlag = flg;
403 }
404 else
405 {
406 G4cout
407 << "G4ParticleDefinition::SetApplyCutsFlag() for " << theParticleName
408 << G4endl;
409 G4cout
410 << "becomes obsolete. Production threshold is applied only for "
411 << "gamma, e- ,e+ and proton." << G4endl;
412 }
413}
414
415// --------------------------------------------------------------------
417{
418 G4Exception("G4ParticleDefinition::G4ParticleDefinition",
419 "PART114", JustWarning,
420 "CalculateAnomaly() method will be removed in future releases");
421
422 // gives the anomaly of magnetic moment for spin 1/2 particles
423 if (thePDGiSpin==1)
424 {
425 G4double muB = 0.5*CLHEP::eplus*CLHEP::hbar_Planck
426 / (thePDGMass/CLHEP::c_squared);
427 return 0.5*std::fabs(thePDGMagneticMoment/muB
428 - 2.*thePDGCharge/CLHEP::eplus);
429 }
430 else
431 {
432 return 0.0;
433 }
434}
435
436// --------------------------------------------------------------------
438{
439 if(id<0)
440 {
441 g4particleDefinitionInstanceID = subInstanceManager.CreateSubInstance();
442 G4MT_pmanager = nullptr;
443 }
444 else
445 {
447 { g4particleDefinitionInstanceID = id; }
448 else
449 {
451 ed << "ParticleDefinitionID should not be set for the particles <"
452 << theParticleName << ">.";
453 G4Exception("G4ParticleDefintion::SetParticleDefinitionID",
454 "PART10114", FatalException, ed);
455 }
456 }
457}
458
459// --------------------------------------------------------------------
461{
462 if(g4particleDefinitionInstanceID<0 && !isGeneralIon)
463 {
465 {
467 ed << "ProcessManager is being set to " << theParticleName
468 << " without proper initialization of TLS pointer vector.\n"
469 << "This operation is thread-unsafe.";
470 G4Exception("G4ParticleDefintion::SetProcessManager",
471 "PART10116", JustWarning, ed);
472 }
474 }
475 G4MT_pmanager = aProcessManager;
476}
G4ApplicationState
@ G4State_PreInit
@ JustWarning
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
#define G4MT_pmanager
#define G4BestUnit(a, b)
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void DumpInfo() const
static G4bool IsIon(const G4ParticleDefinition *)
Definition: G4IonTable.cc:1302
static G4bool IsAntiIon(const G4ParticleDefinition *)
Definition: G4IonTable.cc:1328
G4int GetSpin() const
G4int CheckPDGCode(G4int code, const G4String &type)
G4int GetQuarkContent(G4int flavor) const
G4bool CheckCharge(G4double charge) const
G4int GetAntiQuarkContent(G4int flavor) const
void SetVerboseLevel(G4int verbose)
G4int CreateSubInstance()
G4ProcessManager * GetProcessManager() const
G4int GetAtomicNumber() const
static const G4PDefManager & GetSubInstanceManager()
G4bool IsGeneralIon() const
G4int theAntiQuarkContent[NumberOfQuarkFlavor]
G4int GetVerboseLevel() const
void SetParticleDefinitionID(G4int id=-1)
G4int GetAtomicMass() const
G4double GetPDGCharge() const
G4bool operator==(const G4ParticleDefinition &right) const
G4int theQuarkContent[NumberOfQuarkFlavor]
void SetAtomicMass(G4int)
G4double GetIonLifeTime() const
G4bool operator!=(const G4ParticleDefinition &right) const
G4double CalculateAnomaly() const
const G4String & GetParticleName() const
void SetProcessManager(G4ProcessManager *aProcessManager)
void SetAtomicNumber(G4int)
G4IonTable * GetIonTable() const
G4int GetVerboseLevel() const
static G4ParticleTable * GetParticleTable()
G4ParticleDefinition * Insert(G4ParticleDefinition *particle)
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4int G4GetThreadId()
Definition: G4Threading.cc:122
#define ns
Definition: xmlparse.cc:614