Geant4  10.02.p01
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 92918 2015-09-21 15:04:01Z 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 
312 //-- No longer needed to access to G4IonTable.
313 //-- Method GetIonLifeTime() itself is kept for compatibility
314 //-- but moved to icc file as an inlined method.
315 //G4double G4ParticleDefinition::GetIonLifeTime() const
316 //{
317 // if(!isGeneralIon) return thePDGLifeTime;
318 //
319 // G4IonTable* ionTable = G4IonTable::GetIonTable();
320 // return ionTable->GetLifeTime(this);
321 //}
322 
324 {
325  G4cout << G4endl;
326  G4cout << "--- G4ParticleDefinition ---" << G4endl;
327  G4cout << " Particle Name : " << theParticleName << G4endl;
328  G4cout << " PDG particle code : " << thePDGEncoding;
329  G4cout << " [PDG anti-particle code: " << this->GetAntiPDGEncoding() << "]"<< G4endl;
330  G4cout << " Mass [GeV/c2] : " << thePDGMass/GeV ;
331  G4cout << " Width : " << thePDGWidth/GeV << G4endl;
332  G4cout << " Lifetime [nsec] : " << thePDGLifeTime/ns << G4endl;
333  G4cout << " Charge [e]: " << thePDGCharge/eplus << G4endl;
334  G4cout << " Spin : " << thePDGiSpin << "/2" << G4endl;
335  G4cout << " Parity : " << thePDGiParity << G4endl;
336  G4cout << " Charge conjugation : " << thePDGiConjugation << G4endl;
337  G4cout << " Isospin : (I,Iz): (" << thePDGiIsospin <<"/2";
338  G4cout << " , " << thePDGiIsospin3 << "/2 ) " << G4endl;
339  G4cout << " GParity : " << thePDGiGParity << G4endl;
340  if (thePDGMagneticMoment != 0.0) {
341  G4cout << " MagneticMoment [MeV/T] : " << thePDGMagneticMoment/MeV*tesla << G4endl;
342  }
343  G4cout << " Quark contents (d,u,s,c,b,t) : " << theQuarkContent[0];
344  G4cout << ", " << theQuarkContent[1];
345  G4cout << ", " << theQuarkContent[2];
346  G4cout << ", " << theQuarkContent[3];
347  G4cout << ", " << theQuarkContent[4];
348  G4cout << ", " << theQuarkContent[5] << G4endl;
349  G4cout << " AntiQuark contents : " << theAntiQuarkContent[0];
350  G4cout << ", " << theAntiQuarkContent[1];
351  G4cout << ", " << theAntiQuarkContent[2];
352  G4cout << ", " << theAntiQuarkContent[3];
353  G4cout << ", " << theAntiQuarkContent[4];
354  G4cout << ", " << theAntiQuarkContent[5] << G4endl;
355  G4cout << " Lepton number : " << theLeptonNumber;
356  G4cout << " Baryon number : " << theBaryonNumber << G4endl;
357  G4cout << " Particle type : " << theParticleType ;
358  G4cout << " [" << theParticleSubType << "]" << G4endl;
359 
360  if ( (theParticleTable->GetIonTable()->IsIon(this))
361  || (theParticleTable->GetIonTable()->IsAntiIon(this)) ) {
362  G4cout << " Atomic Number : " << GetAtomicNumber();
363  G4cout << " Atomic Mass : " << GetAtomicMass() << G4endl;
364  }
365  if ( fShortLivedFlag ){
366  G4cout << " ShortLived : ON" << G4endl;
367  }
368 
369  if ( IsGeneralIon() ) {
370  G4double lftm = GetIonLifeTime();
371  if(lftm<-1000.)
372  { G4cout << " Stable : No data found -- unknown" << G4endl; }
373  else if(lftm<0.)
374  { G4cout << " Stable : stable" << G4endl; }
375  else
376  {
377  G4cout << " Stable : unstable -- lifetime = " << G4BestUnit(lftm,"Time")
378  << "\n Decay table should be consulted to G4RadioactiveDecayProcess."
379  << G4endl;
380  }
381  }
382  else
383  {
384  if ( thePDGStable ){
385  G4cout << " Stable : stable" << G4endl;
386  } else {
387  if( theDecayTable != 0 ){
389  } else {
390  G4cout << "Decay Table is not defined !!" <<G4endl;
391  }
392  }
393  }
394 }
395 
397 {
398  if(theParticleName=="gamma"
399  || theParticleName=="e-"
400  || theParticleName=="e+"
401  || theParticleName=="proton")
402  { fApplyCutsFlag = flg; }
403  else
404  {
405  G4cout
406  << "G4ParticleDefinition::SetApplyCutsFlag() for " << theParticleName
407  << G4endl;
408  G4cout
409  << "becomes obsolete. Production threshold is applied only for "
410  << "gamma, e- ,e+ and proton." << G4endl;
411  }
412 }
413 
415 {
416  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
417  "PART114", JustWarning,
418  "CalculateAnomaly() method will be removed in next release");
419 
420  // gives the anomaly of magnetic moment for spin 1/2 particles
421  if (thePDGiSpin==1) {
422  G4double muB = 0.5*CLHEP::eplus*CLHEP::hbar_Planck/(thePDGMass/CLHEP::c_squared);
423  return 0.5*std::fabs(thePDGMagneticMoment/muB - 2.*thePDGCharge/CLHEP::eplus);
424  } else {
425  return 0.0;
426  }
427 }
428 
430 {
431  if(id<0)
432  {
434  G4MT_pmanager = 0;
435  }
436  else
437  {
438  if(isGeneralIon)
440  else
441  {
443  ed << "ParticleDefinitionID should not be set for the particles <"
444  << theParticleName << ">.";
445  G4Exception( "G4ParticleDefintion::SetParticleDefinitionID","PART10114",
446  FatalException,ed);
447  }
448  }
449 }
450 
451 #include "G4Threading.hh"
452 
454 {
456  {
457  if(G4Threading::G4GetThreadId() >= 0)
458  {
460  ed << "ProcessManager is being set to " << theParticleName
461  << " without proper initialization of TLS pointer vector.\n"
462  << "This operation is thread-unsafe.";
463  G4Exception( "G4ParticleDefintion::SetProcessManager","PART10116",
464  JustWarning,ed);
465  }
467  }
468  G4MT_pmanager = aProcessManager;
469 }
G4ParticleTable * theParticleTable
static const double MeV
Definition: G4SIunits.hh:211
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:1091
G4int GetSpin() const
static G4PART_DLL G4PDefManager subInstanceManager
#define width
static G4bool IsAntiIon(const G4ParticleDefinition *)
Definition: G4IonTable.cc:1116
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:214
G4int GetAntiQuarkContent(G4int flavor) const
G4ApplicationState GetCurrentState() const
#define encoding
Definition: xmlparse.cc:605
G4int GetAtomicMass() const
G4int operator==(const G4ParticleDefinition &right) const
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
static const double tesla
Definition: G4SIunits.hh:265
double G4double
Definition: G4Types.hh:76
static const double eplus
Definition: G4SIunits.hh:196
G4double GetPDGCharge() const
G4int GetVerboseLevel() const
#define ns
Definition: xmlparse.cc:614
G4int CreateSubInstance()
G4ApplicationState
G4int G4GetThreadId()
Definition: G4Threading.cc:128
void SetAtomicMass(G4int)
const G4ParticleDefinition & operator=(const G4ParticleDefinition &r)
#define G4MT_pmanager