Geant4  10.01.p02
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 //
27 // $Id: G4ParticleDefinition.cc 79342 2014-02-24 11:42:42Z gcosmo $
28 //
29 //
30 // --------------------------------------------------------------
31 // GEANT 4 class implementation file
32 //
33 // History: first implementation, based on object model of
34 // 2nd December 1995, G.Cosmo
35 // ---------------- G4ParticleDefinition -----------------
36 // first implementation by Makoto Asai, 29 January 1996
37 // revised by G.Cosmo, 29 February 1996
38 // revised by H.Kurashige, 19 April 1996
39 // Code uses operators (+=, *=, ++, -> etc.) correctly, P. Urban, 26/6/96
40 // revised by H.Kurashige, 4 July 1996
41 // revised by H.Kurashige, 16 Feb 1997
42 // revised by H.Kurashige, 10 Nov 1997
43 // remove new/delete G4ProcessManager by H.Kurashige 06 June 1998
44 // added Resonance flag and ApplyCuts flag H.Kurashige 27 June 1998
45 // modify FillQuarkContents() for quarks/diquarks H.Kurashige 30 June 1998
46 // modify encoding rule H.Kurashige 23 Oct. 98
47 // modify FillQuarkContents() for deltas 25 Nov.,98 H.Kurashige
48 //
49 // modify FillQuarkContents() to use G4PDGCodeChecker 17 Aug. 99 H.Kurashige
50 // modified for thread-safety for MT - G.Cosmo, A.Dotti - January 2013
51 // --------------------------------------------------------------
52 
53 
54 #include "G4ParticleDefinition.hh"
55 #include "G4PhysicalConstants.hh"
56 #include "G4SystemOfUnits.hh"
57 #include "G4ParticleTable.hh"
58 #include "G4IonTable.hh"
59 #include "G4DecayTable.hh"
60 #include "G4PDGCodeChecker.hh"
61 #include "G4StateManager.hh"
62 #include "G4UnitsTable.hh"
63 
64 // This static member is thread local. For each thread, it holds the array
65 // size of G4PDefData instances.
66 //
67 template <class G4PDefData> G4ThreadLocal
69 
70 // This static member is thread local. For each thread, it points to the
71 // array of G4PDefData instances.
72 //
73 template <class G4PDefData> G4ThreadLocal
75 
76 // This new field helps to use the class G4PDefManager.
77 //
79 
80 // Returns the private data instance manager.
81 //
83 {
84  return subInstanceManager;
85 }
86 
88  const G4String& aName,
89  G4double mass,
91  G4double charge,
92  G4int iSpin,
93  G4int iParity,
94  G4int iConjugation,
95  G4int iIsospin,
96  G4int iIsospin3,
97  G4int gParity,
98  const G4String& pType,
99  G4int lepton,
100  G4int baryon,
101  G4int encoding,
102  G4bool stable,
103  G4double lifetime,
104  G4DecayTable *decaytable,
105  G4bool shortlived,
106  const G4String& subType,
107  G4int anti_encoding,
108  G4double magneticMoment)
109 
110  : theParticleName(aName),
111  thePDGMass(mass),
112  thePDGWidth(width),
113  thePDGCharge(charge),
114  thePDGiSpin(iSpin),
115  thePDGSpin(iSpin*0.5),
116  thePDGiParity(iParity),
117  thePDGiConjugation(iConjugation),
118  thePDGiGParity(gParity),
119  thePDGiIsospin(iIsospin),
120  thePDGiIsospin3(iIsospin3),
121  thePDGIsospin(iIsospin*0.5),
122  thePDGIsospin3(iIsospin3*0.5),
123  thePDGMagneticMoment(magneticMoment),
124  theLeptonNumber(lepton),
125  theBaryonNumber(baryon),
126  theParticleType(pType),
127  theParticleSubType(subType),
128  thePDGEncoding(encoding),
129  theAntiPDGEncoding(-1*encoding),
130  fShortLivedFlag(shortlived),
131  thePDGStable(stable),
132  thePDGLifeTime(lifetime),
133  theDecayTable(decaytable),
134  theAtomicNumber(0),
135  theAtomicMass(0),
136  verboseLevel(1),
137  fApplyCutsFlag(false),
138  isGeneralIon(false)
139 {
140  static G4String nucleus("nucleus");
141 
144 
146 
147  //set verboseLevel equal to ParticleTable
149 
150  if (anti_encoding !=0) theAntiPDGEncoding = anti_encoding;
151 
152  // check quark contents
153  if (this->FillQuarkContents() != thePDGEncoding) {
154 #ifdef G4VERBOSE
155  if (verboseLevel>0) {
156  // Using G4cout expecting that it is available in construction of static objects
157  G4cout << "Particle " << aName << " has a strange PDGEncoding " <<G4endl;
158  }
159 #endif
160  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
161  "PART102", JustWarning,
162  "Strange PDGEncoding ");
163  }
164 
165  // check initialization is in Pre_Init state except for ions
167 
168  if ( !fShortLivedFlag && (theParticleType!=nucleus) && (currentState!=G4State_PreInit)){
169 #ifdef G4VERBOSE
170  if (GetVerboseLevel()>0) {
171  G4cout << "G4ParticleDefintion (other than ions and shortlived) should be created in Pre_Init state "
172  << aName << G4endl;
173  }
174 #endif
175  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
176  "PART101", JustWarning,
177  "G4ParticleDefinition should be created in PreInit state");
178  }
179 
180 
181  if (theParticleTable->GetIonTable()->IsIon(this)) {
184  }
185 
186  if (theParticleTable->GetIonTable()->IsAntiIon(this)) {
187  SetAtomicNumber( std::abs(G4int(GetPDGCharge()/eplus)) );
188  SetAtomicMass( std::abs(GetBaryonNumber()) );
189  }
190 
191  // check name and register this particle into ParticleTable
192  theParticleTable->Insert(this);
193 
194 }
195 
197 {
198  G4Exception("G4ParticleDefinition::G4ParticleDefinition()",
199  "PART001", FatalException,
200  "Illegal call of copy Constructor for G4ParticleDefinition ");
201 }
202 
204 {
205  G4Exception("G4ParticleDefinition::G4ParticleDefinition()",
206  "PART001", FatalException,
207  "Illegal call of default Constructor for G4ParticleDefinition ");
208 }
209 
210 
212 {
213  if (G4ParticleTable::GetParticleTable()->GetReadiness()) {
215  G4ApplicationState currentState = pStateManager->GetCurrentState();
216  if (currentState != G4State_PreInit) {
217  G4String msg = "Request of deletion for ";
218  msg += GetParticleName();
219  msg += " has No effects because readyToUse is true.";
220  G4Exception("G4ParticleDefinition::~G4ParticleDefinition()",
221  "PART117", JustWarning, msg);
222  return ;
223  } else {
224 #ifdef G4VERBOSE
225  if (verboseLevel>0){
227  << " will be deleted " << G4endl;
228  }
229 #endif
230  }
231  }
232 
233  if (theDecayTable!= 0) delete theDecayTable;
234 }
235 
236 
238 {
239  if (this != &right) {
240  }
241  return *this;
242 }
243 
245 {
246  return (this->theParticleName == right.theParticleName);
247 }
248 
250 {
251  return (this->theParticleName != right.theParticleName);
252 }
253 
254 
255 
257  // calculate quark and anti-quark contents
258  // return value is PDG encoding for this particle.
259  // It means error if the return value is differnt from
260  // this->thePDGEncoding.
261 {
262  G4int flavor;
263  for (flavor= 0; flavor<NumberOfQuarkFlavor; flavor++){
264  theQuarkContent[flavor] = 0;
265  theAntiQuarkContent[flavor] = 0;
266  }
267 
268  G4PDGCodeChecker checker;
269  checker.SetVerboseLevel(verboseLevel);
270 
272 
273  if ( temp != 0) {
274  for (flavor= 0; flavor<NumberOfQuarkFlavor; flavor++){
275  theQuarkContent[flavor] = checker.GetQuarkContent(flavor);
276  theAntiQuarkContent[flavor] = checker.GetAntiQuarkContent(flavor);
277  }
278  if ((theParticleType == "meson")||(theParticleType == "baryon")) {
279  // check charge
280  if (!checker.CheckCharge(thePDGCharge) ){
281  temp = 0;
282  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
283  "PART103", JustWarning,
284  "Inconsistent charge against PDG code ");
285 #ifdef G4VERBOSE
286  if (verboseLevel>0) {
287  G4cout << "G4ParticleDefinition::FillQuarkContents : "
288  << " illegal charge (" << thePDGCharge/eplus
289  << " PDG code=" << thePDGEncoding <<G4endl;
290  }
291 #endif
292  }
293  // check spin
294  if (checker.GetSpin() != thePDGiSpin) {
295  temp=0;
296  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
297  "PART104", JustWarning,
298  "Inconsistent spin against PDG code ");
299 #ifdef G4VERBOSE
300  if (verboseLevel>0) {
301  G4cout << "G4ParticleDefinition::FillQuarkContents : "
302  << " illegal SPIN (" << thePDGiSpin << "/2"
303  << " PDG code=" << thePDGEncoding <<G4endl;
304  }
305 #endif
306  }
307  }
308  }
309  return temp;
310 }
311 
313 {
314  if(!isGeneralIon) return thePDGLifeTime;
315 
316  G4IonTable* ionTable = G4IonTable::GetIonTable();
317  return ionTable->GetLifeTime(this);
318 }
319 
321 {
322  G4cout << G4endl;
323  G4cout << "--- G4ParticleDefinition ---" << G4endl;
324  G4cout << " Particle Name : " << theParticleName << G4endl;
325  G4cout << " PDG particle code : " << thePDGEncoding;
326  G4cout << " [PDG anti-particle code: " << this->GetAntiPDGEncoding() << "]"<< G4endl;
327  G4cout << " Mass [GeV/c2] : " << thePDGMass/GeV ;
328  G4cout << " Width : " << thePDGWidth/GeV << G4endl;
329  G4cout << " Lifetime [nsec] : " << thePDGLifeTime/ns << G4endl;
330  G4cout << " Charge [e]: " << thePDGCharge/eplus << G4endl;
331  G4cout << " Spin : " << thePDGiSpin << "/2" << G4endl;
332  G4cout << " Parity : " << thePDGiParity << G4endl;
333  G4cout << " Charge conjugation : " << thePDGiConjugation << G4endl;
334  G4cout << " Isospin : (I,Iz): (" << thePDGiIsospin <<"/2";
335  G4cout << " , " << thePDGiIsospin3 << "/2 ) " << G4endl;
336  G4cout << " GParity : " << thePDGiGParity << G4endl;
337  if (thePDGMagneticMoment != 0.0) {
338  G4cout << " MagneticMoment [MeV/T] : " << thePDGMagneticMoment/MeV*tesla << G4endl;
339  }
340  G4cout << " Quark contents (d,u,s,c,b,t) : " << theQuarkContent[0];
341  G4cout << ", " << theQuarkContent[1];
342  G4cout << ", " << theQuarkContent[2];
343  G4cout << ", " << theQuarkContent[3];
344  G4cout << ", " << theQuarkContent[4];
345  G4cout << ", " << theQuarkContent[5] << G4endl;
346  G4cout << " AntiQuark contents : " << theAntiQuarkContent[0];
347  G4cout << ", " << theAntiQuarkContent[1];
348  G4cout << ", " << theAntiQuarkContent[2];
349  G4cout << ", " << theAntiQuarkContent[3];
350  G4cout << ", " << theAntiQuarkContent[4];
351  G4cout << ", " << theAntiQuarkContent[5] << G4endl;
352  G4cout << " Lepton number : " << theLeptonNumber;
353  G4cout << " Baryon number : " << theBaryonNumber << G4endl;
354  G4cout << " Particle type : " << theParticleType ;
355  G4cout << " [" << theParticleSubType << "]" << G4endl;
356 
357  if ( (theParticleTable->GetIonTable()->IsIon(this))
358  || (theParticleTable->GetIonTable()->IsAntiIon(this)) ) {
359  G4cout << " Atomic Number : " << GetAtomicNumber();
360  G4cout << " Atomic Mass : " << GetAtomicMass() << G4endl;
361  }
362  if ( fShortLivedFlag ){
363  G4cout << " ShortLived : ON" << G4endl;
364  }
365 
366  if ( IsGeneralIon() ) {
367  G4double lftm = GetIonLifeTime();
368  if(lftm<-1000.)
369  { G4cout << " Stable : No data found -- unknown" << G4endl; }
370  else if(lftm<0.)
371  { G4cout << " Stable : stable" << G4endl; }
372  else
373  {
374  G4cout << " Stable : unstable -- lifetime = " << G4BestUnit(lftm,"Time")
375  << "\n Decay table should be consulted to G4RadioactiveDecayProcess."
376  << G4endl;
377  }
378  }
379  else
380  {
381  if ( thePDGStable ){
382  G4cout << " Stable : stable" << G4endl;
383  } else {
384  if( theDecayTable != 0 ){
386  } else {
387  G4cout << "Decay Table is not defined !!" <<G4endl;
388  }
389  }
390  }
391 }
392 
394 {
395  if(theParticleName=="gamma"
396  || theParticleName=="e-"
397  || theParticleName=="e+"
398  || theParticleName=="proton")
399  { fApplyCutsFlag = flg; }
400  else
401  {
402  G4cout
403  << "G4ParticleDefinition::SetApplyCutsFlag() for " << theParticleName
404  << G4endl;
405  G4cout
406  << "becomes obsolete. Production threshold is applied only for "
407  << "gamma, e- ,e+ and proton." << G4endl;
408  }
409 }
410 
412 {
413  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
414  "PART114", JustWarning,
415  "CalculateAnomaly() method will be removed in next release");
416 
417  // gives the anomaly of magnetic moment for spin 1/2 particles
418  if (thePDGiSpin==1) {
419  G4double muB = 0.5*CLHEP::eplus*CLHEP::hbar_Planck/(thePDGMass/CLHEP::c_squared);
420  return 0.5*std::fabs(thePDGMagneticMoment/muB - 2.*thePDGCharge/CLHEP::eplus);
421  } else {
422  return 0.0;
423  }
424 }
425 
427 {
428  if(id<0)
429  {
431  G4MT_pmanager = 0;
432  }
433  else
434  {
435  if(isGeneralIon)
437  else
438  {
440  ed << "ParticleDefinitionID should not be set for the particles <"
441  << theParticleName << ">.";
442  G4Exception( "G4ParticleDefintion::SetParticleDefinitionID","PART10114",
443  FatalException,ed);
444  }
445  }
446 }
447 
448 #include "G4Threading.hh"
449 
451 {
453  {
454  if(G4Threading::G4GetThreadId() >= 0)
455  {
457  ed << "ProcessManager is being set to " << theParticleName
458  << " without proper initialization of TLS pointer vector.\n"
459  << "This operation is thread-unsafe.";
460  G4Exception( "G4ParticleDefintion::SetProcessManager","PART10116",
461  JustWarning,ed);
462  }
464  }
465  G4MT_pmanager = aProcessManager;
466 }
G4ParticleTable * theParticleTable
static const double MeV
Definition: G4SIunits.hh:193
void SetAtomicNumber(G4int)
void SetParticleDefinitionID(G4int id=-1)
void SetProcessManager(G4ProcessManager *aProcessManager)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4bool CheckCharge(G4double charge) const
G4int GetQuarkContent(G4int flavor) const
G4int operator!=(const G4ParticleDefinition &right) const
G4int GetVerboseLevel() const
static G4bool IsIon(const G4ParticleDefinition *)
Definition: G4IonTable.cc:1061
G4int GetSpin() const
static G4PART_DLL G4PDefManager subInstanceManager
#define width
static G4bool IsAntiIon(const G4ParticleDefinition *)
Definition: G4IonTable.cc:1086
G4ProcessManager * theProcessManagerShadow
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
#define G4ThreadLocal
Definition: tls.hh:89
static const G4PDefManager & GetSubInstanceManager()
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
G4int GetAtomicNumber() const
G4bool IsGeneralIon() const
G4int CheckPDGCode(G4int code, G4String type)
G4int GetAntiPDGEncoding() const
G4double GetIonLifeTime() const
static G4StateManager * GetStateManager()
G4ParticleDefinition * Insert(G4ParticleDefinition *particle)
G4IonTable * GetIonTable() const
G4GLOB_DLL std::ostream G4cout
G4double CalculateAnomaly() const
bool G4bool
Definition: G4Types.hh:79
void DumpInfo() const
static const double GeV
Definition: G4SIunits.hh:196
G4int GetAntiQuarkContent(G4int flavor) const
G4ApplicationState GetCurrentState() const
#define encoding
Definition: xmlparse.cc:588
G4int GetAtomicMass() const
G4int operator==(const G4ParticleDefinition &right) const
static G4IonTable * GetIonTable()
Definition: G4IonTable.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int theAntiQuarkContent[NumberOfQuarkFlavor]
static G4ParticleTable * GetParticleTable()
void SetVerboseLevel(G4int verbose)
G4int theQuarkContent[NumberOfQuarkFlavor]
#define G4endl
Definition: G4ios.hh:61
G4double GetLifeTime(const G4ParticleDefinition *) const
Definition: G4IonTable.cc:1738
static const double tesla
Definition: G4SIunits.hh:247
double G4double
Definition: G4Types.hh:76
static const double eplus
Definition: G4SIunits.hh:178
G4double GetPDGCharge() const
G4int GetVerboseLevel() const
#define ns
Definition: xmlparse.cc:597
G4int CreateSubInstance()
G4ApplicationState
G4int G4GetThreadId()
Definition: G4Threading.cc:127
void SetAtomicMass(G4int)
const G4ParticleDefinition & operator=(const G4ParticleDefinition &r)
#define G4MT_pmanager