Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 100425 2016-10-21 12:57:06Z 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 new field helps to use the class G4PDefManager.
65 //
66 G4PDefManager G4ParticleDefinition::subInstanceManager;
67 
68 // This macro changes the references to fields that are now encapsulated
69 // in the class G4PDefData.
70 //
71 #define G4MT_pmanager ((subInstanceManager.offset[g4particleDefinitionInstanceID]).theProcessManager)
72 
73 // Returns the private data instance manager.
74 //
76 {
77  return subInstanceManager;
78 }
79 
81  const G4String& aName,
82  G4double mass,
83  G4double width,
84  G4double charge,
85  G4int iSpin,
86  G4int iParity,
87  G4int iConjugation,
88  G4int iIsospin,
89  G4int iIsospin3,
90  G4int gParity,
91  const G4String& pType,
92  G4int lepton,
93  G4int baryon,
95  G4bool stable,
96  G4double lifetime,
97  G4DecayTable *decaytable,
98  G4bool shortlived,
99  const G4String& subType,
100  G4int anti_encoding,
101  G4double magneticMoment)
102 
103  : theParticleName(aName),
104  thePDGMass(mass),
105  thePDGWidth(width),
106  thePDGCharge(charge),
107  thePDGiSpin(iSpin),
108  thePDGSpin(iSpin*0.5),
109  thePDGiParity(iParity),
110  thePDGiConjugation(iConjugation),
111  thePDGiGParity(gParity),
112  thePDGiIsospin(iIsospin),
113  thePDGiIsospin3(iIsospin3),
114  thePDGIsospin(iIsospin*0.5),
115  thePDGIsospin3(iIsospin3*0.5),
116  thePDGMagneticMoment(magneticMoment),
117  theLeptonNumber(lepton),
118  theBaryonNumber(baryon),
119  theParticleType(pType),
120  theParticleSubType(subType),
121  thePDGEncoding(encoding),
122  theAntiPDGEncoding(-1*encoding),
123  fShortLivedFlag(shortlived),
124  thePDGStable(stable),
125  thePDGLifeTime(lifetime),
126  theDecayTable(decaytable),
127  theAtomicNumber(0),
128  theAtomicMass(0),
129  verboseLevel(1),
130  fApplyCutsFlag(false),
131  isGeneralIon(false)
132 {
133  static G4String nucleus("nucleus");
134 
135  g4particleDefinitionInstanceID = -1;
136  theProcessManagerShadow = 0;
137 
138  theParticleTable = G4ParticleTable::GetParticleTable();
139 
140  //set verboseLevel equal to ParticleTable
141  verboseLevel = theParticleTable->GetVerboseLevel();
142 
143  if (anti_encoding !=0) theAntiPDGEncoding = anti_encoding;
144 
145  // check quark contents
146  if (this->FillQuarkContents() != thePDGEncoding) {
147 #ifdef G4VERBOSE
148  if (verboseLevel>0) {
149  // Using G4cout expecting that it is available in construction of static objects
150  G4cout << "Particle " << aName << " has a strange PDGEncoding " <<G4endl;
151  }
152 #endif
153  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
154  "PART102", JustWarning,
155  "Strange PDGEncoding ");
156  }
157 
158  // check initialization is in Pre_Init state except for ions
160 
161  if ( !fShortLivedFlag && (theParticleType!=nucleus) && (currentState!=G4State_PreInit)){
162 #ifdef G4VERBOSE
163  if (GetVerboseLevel()>0) {
164  G4cout << "G4ParticleDefintion (other than ions and shortlived) should be created in Pre_Init state "
165  << aName << G4endl;
166  }
167 #endif
168  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
169  "PART101", JustWarning,
170  "G4ParticleDefinition should be created in PreInit state");
171  }
172 
173 
174  if (theParticleTable->GetIonTable()->IsIon(this)) {
177  }
178 
179  if (theParticleTable->GetIonTable()->IsAntiIon(this)) {
180  SetAtomicNumber( std::abs(G4int(GetPDGCharge()/eplus)) );
181  SetAtomicMass( std::abs(GetBaryonNumber()) );
182  }
183 
184  // check name and register this particle into ParticleTable
185  theParticleTable->Insert(this);
186 
187 }
188 
190 {
191  G4Exception("G4ParticleDefinition::G4ParticleDefinition()",
192  "PART001", FatalException,
193  "Illegal call of copy Constructor for G4ParticleDefinition ");
194 }
195 
197 {
198  G4Exception("G4ParticleDefinition::G4ParticleDefinition()",
199  "PART001", FatalException,
200  "Illegal call of default Constructor for G4ParticleDefinition ");
201 }
202 
203 
205 {
206  if (G4ParticleTable::GetParticleTable()->GetReadiness()) {
208  G4ApplicationState currentState = pStateManager->GetCurrentState();
209  if (currentState != G4State_PreInit) {
210  G4String msg = "Request of deletion for ";
211  msg += GetParticleName();
212  msg += " has No effects because readyToUse is true.";
213  G4Exception("G4ParticleDefinition::~G4ParticleDefinition()",
214  "PART117", JustWarning, msg);
215  return ;
216  } else {
217 #ifdef G4VERBOSE
218  if (verboseLevel>0){
220  << " will be deleted " << G4endl;
221  }
222 #endif
223  }
224  }
225 
226  if (theDecayTable!= 0) delete theDecayTable;
227 }
228 
229 
230 const G4ParticleDefinition & G4ParticleDefinition::operator=(const G4ParticleDefinition &right)
231 {
232  if (this != &right) {
233  }
234  return *this;
235 }
236 
238 {
239  return (this->theParticleName == right.theParticleName);
240 }
241 
243 {
244  return (this->theParticleName != right.theParticleName);
245 }
246 
248 {
249  if(g4particleDefinitionInstanceID<0) return 0;
250  return G4MT_pmanager;
251 }
252 
254  // calculate quark and anti-quark contents
255  // return value is PDG encoding for this particle.
256  // It means error if the return value is differnt from
257  // this->thePDGEncoding.
258 {
259  G4int flavor;
260  for (flavor= 0; flavor<NumberOfQuarkFlavor; flavor++){
261  theQuarkContent[flavor] = 0;
262  theAntiQuarkContent[flavor] = 0;
263  }
264 
265  G4PDGCodeChecker checker;
266  checker.SetVerboseLevel(verboseLevel);
267 
268  G4int temp = checker.CheckPDGCode(thePDGEncoding, theParticleType);
269 
270  if ( temp != 0) {
271  for (flavor= 0; flavor<NumberOfQuarkFlavor; flavor++){
272  theQuarkContent[flavor] = checker.GetQuarkContent(flavor);
273  theAntiQuarkContent[flavor] = checker.GetAntiQuarkContent(flavor);
274  }
275  if ((theParticleType == "meson")||(theParticleType == "baryon")) {
276  // check charge
277  if (!checker.CheckCharge(thePDGCharge) ){
278  temp = 0;
279  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
280  "PART103", JustWarning,
281  "Inconsistent charge against PDG code ");
282 #ifdef G4VERBOSE
283  if (verboseLevel>0) {
284  G4cout << "G4ParticleDefinition::FillQuarkContents : "
285  << " illegal charge (" << thePDGCharge/eplus
286  << " PDG code=" << thePDGEncoding <<G4endl;
287  }
288 #endif
289  }
290  // check spin
291  if (checker.GetSpin() != thePDGiSpin) {
292  temp=0;
293  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
294  "PART104", JustWarning,
295  "Inconsistent spin against PDG code ");
296 #ifdef G4VERBOSE
297  if (verboseLevel>0) {
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 //-- No longer needed to access to G4IonTable.
310 //-- Method GetIonLifeTime() itself is kept for compatibility
311 //-- but moved to icc file as an inlined method.
312 //G4double G4ParticleDefinition::GetIonLifeTime() const
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 ){
385  theDecayTable->DumpInfo();
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) {
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  {
430  g4particleDefinitionInstanceID = subInstanceManager.CreateSubInstance();
431  G4MT_pmanager = 0;
432  }
433  else
434  {
435  if(isGeneralIon)
436  { g4particleDefinitionInstanceID = id; }
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 {
452  if(g4particleDefinitionInstanceID<0 && !isGeneralIon)
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 }
static constexpr double tesla
Definition: G4SIunits.hh:268
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:1147
G4int GetSpin() const
static G4bool IsAntiIon(const G4ParticleDefinition *)
Definition: G4IonTable.cc:1172
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
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 constexpr double eplus
Definition: G4SIunits.hh:199
static constexpr double eplus
G4int GetAntiQuarkContent(G4int flavor) const
G4ApplicationState GetCurrentState() const
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
static constexpr double c_squared
G4int theAntiQuarkContent[NumberOfQuarkFlavor]
static G4ParticleTable * GetParticleTable()
G4ProcessManager * GetProcessManager() const
void SetVerboseLevel(G4int verbose)
G4int theQuarkContent[NumberOfQuarkFlavor]
static constexpr double GeV
Definition: G4SIunits.hh:217
G4int CreateSubInstance()
#define G4endl
Definition: G4ios.hh:61
static constexpr double MeV
Definition: G4SIunits.hh:214
double G4double
Definition: G4Types.hh:76
G4double GetPDGCharge() const
static constexpr double hbar_Planck
#define G4MT_pmanager
G4int GetVerboseLevel() const
#define ns
Definition: xmlparse.cc:614
G4ApplicationState
G4int G4GetThreadId()
Definition: G4Threading.cc:144
void SetAtomicMass(G4int)