Geant4_10
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 73598 2013-09-02 09:18:28Z 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 
63 // This static member is thread local. For each thread, it holds the array
64 // size of G4PDefData instances.
65 //
66 template <class G4PDefData> G4ThreadLocal
68 
69 // This static member is thread local. For each thread, it points to the
70 // array of G4PDefData instances.
71 //
72 template <class G4PDefData> G4ThreadLocal
74 
75 // This new field helps to use the class G4PDefManager.
76 //
77 G4PDefManager G4ParticleDefinition::subInstanceManager;
78 
79 // Returns the private data instance manager.
80 //
82 {
83  return subInstanceManager;
84 }
85 
87  const G4String& aName,
88  G4double mass,
90  G4double charge,
91  G4int iSpin,
92  G4int iParity,
93  G4int iConjugation,
94  G4int iIsospin,
95  G4int iIsospin3,
96  G4int gParity,
97  const G4String& pType,
98  G4int lepton,
99  G4int baryon,
100  G4int encoding,
101  G4bool stable,
102  G4double lifetime,
103  G4DecayTable *decaytable,
104  G4bool shortlived,
105  const G4String& subType,
106  G4int anti_encoding,
107  G4double magneticMoment)
108 
109  : theParticleName(aName),
110  thePDGMass(mass),
111  thePDGWidth(width),
112  thePDGCharge(charge),
113  thePDGiSpin(iSpin),
114  thePDGSpin(iSpin*0.5),
115  thePDGiParity(iParity),
116  thePDGiConjugation(iConjugation),
117  thePDGiGParity(gParity),
118  thePDGiIsospin(iIsospin),
119  thePDGiIsospin3(iIsospin3),
120  thePDGIsospin(iIsospin*0.5),
121  thePDGIsospin3(iIsospin3*0.5),
122  thePDGMagneticMoment(magneticMoment),
123  theLeptonNumber(lepton),
124  theBaryonNumber(baryon),
125  theParticleType(pType),
126  theParticleSubType(subType),
127  thePDGEncoding(encoding),
128  theAntiPDGEncoding(-1*encoding),
129  fShortLivedFlag(shortlived),
130  thePDGStable(stable),
131  thePDGLifeTime(lifetime),
132  theDecayTable(decaytable),
133  theAtomicNumber(0),
134  theAtomicMass(0),
135  verboseLevel(1),
136  fApplyCutsFlag(false),
137  isGeneralIon(false)
138 {
139  static G4String nucleus("nucleus");
140 
141  g4particleDefinitionInstanceID = -1;
142  theProcessManagerShadow = 0;
143 
144  theParticleTable = G4ParticleTable::GetParticleTable();
145 
146  //set verboseLevel equal to ParticleTable
147  verboseLevel = theParticleTable->GetVerboseLevel();
148 
149  if (anti_encoding !=0) theAntiPDGEncoding = anti_encoding;
150 
151  // check quark contents
152  if (this->FillQuarkContents() != thePDGEncoding) {
153 #ifdef G4VERBOSE
154  if (verboseLevel>0) {
155  // Using G4cout expecting that it is available in construction of static objects
156  G4cout << "Particle " << aName << " has a strange PDGEncoding " <<G4endl;
157  }
158 #endif
159  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
160  "PART102", JustWarning,
161  "Strange PDGEncoding ");
162  }
163 
164  // check initialization is in Pre_Init state except for ions
166 
167  if ( !fShortLivedFlag && (theParticleType!=nucleus) && (currentState!=G4State_PreInit)){
168 #ifdef G4VERBOSE
169  if (GetVerboseLevel()>0) {
170  G4cout << "G4ParticleDefintion (other than ions and shortlived) should be created in Pre_Init state "
171  << aName << G4endl;
172  }
173 #endif
174  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
175  "PART101", JustWarning,
176  "G4ParticleDefinition should be created in PreInit state");
177  }
178 
179 
180  if (theParticleTable->GetIonTable()->IsIon(this)) {
183  }
184 
185  if (theParticleTable->GetIonTable()->IsAntiIon(this)) {
186  SetAtomicNumber( std::abs(G4int(GetPDGCharge()/eplus)) );
187  SetAtomicMass( std::abs(GetBaryonNumber()) );
188  }
189 
190  // check name and register this particle into ParticleTable
191  theParticleTable->Insert(this);
192 
193 }
194 
196 {
197  G4Exception("G4ParticleDefinition::G4ParticleDefinition()",
198  "PART001", FatalException,
199  "Illegal call of copy Constructor for G4ParticleDefinition ");
200 }
201 
203 {
204  G4Exception("G4ParticleDefinition::G4ParticleDefinition()",
205  "PART001", FatalException,
206  "Illegal call of default Constructor for G4ParticleDefinition ");
207 }
208 
209 
211 {
212  if (G4ParticleTable::GetParticleTable()->GetReadiness()) {
214  G4ApplicationState currentState = pStateManager->GetCurrentState();
215  if (currentState != G4State_PreInit) {
216  G4String msg = "Request of deletion for ";
217  msg += GetParticleName();
218  msg += " has No effects because readyToUse is true.";
219  G4Exception("G4ParticleDefinition::~G4ParticleDefinition()",
220  "PART117", JustWarning, msg);
221  return ;
222  } else {
223 #ifdef G4VERBOSE
224  if (verboseLevel>0){
226  << " will be deleted " << G4endl;
227  }
228 #endif
229  }
230  }
231 
232  if (theDecayTable!= 0) delete theDecayTable;
233 }
234 
235 
236 const G4ParticleDefinition & G4ParticleDefinition::operator=(const G4ParticleDefinition &right)
237 {
238  if (this != &right) {
239  }
240  return *this;
241 }
242 
244 {
245  return (this->theParticleName == right.theParticleName);
246 }
247 
249 {
250  return (this->theParticleName != right.theParticleName);
251 }
252 
253 
254 
256  // calculate quark and anti-quark contents
257  // return value is PDG encoding for this particle.
258  // It means error if the return value is differnt from
259  // this->thePDGEncoding.
260 {
261  G4int flavor;
262  for (flavor= 0; flavor<NumberOfQuarkFlavor; flavor++){
263  theQuarkContent[flavor] = 0;
264  theAntiQuarkContent[flavor] = 0;
265  }
266 
267  G4PDGCodeChecker checker;
268  checker.SetVerboseLevel(verboseLevel);
269 
270  G4int temp = checker.CheckPDGCode(thePDGEncoding, theParticleType);
271 
272  if ( temp != 0) {
273  for (flavor= 0; flavor<NumberOfQuarkFlavor; flavor++){
274  theQuarkContent[flavor] = checker.GetQuarkContent(flavor);
275  theAntiQuarkContent[flavor] = checker.GetAntiQuarkContent(flavor);
276  }
277  if ((theParticleType == "meson")||(theParticleType == "baryon")) {
278  // check charge
279  if (!checker.CheckCharge(thePDGCharge) ){
280  temp = 0;
281  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
282  "PART103", JustWarning,
283  "Inconsistent charge against PDG code ");
284 #ifdef G4VERBOSE
285  if (verboseLevel>0) {
286  G4cout << "G4ParticleDefinition::FillQuarkContents : "
287  << " illegal charge (" << thePDGCharge/eplus
288  << " PDG code=" << thePDGEncoding <<G4endl;
289  }
290 #endif
291  }
292  // check spin
293  if (checker.GetSpin() != thePDGiSpin) {
294  temp=0;
295  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
296  "PART104", JustWarning,
297  "Inconsistent spin against PDG code ");
298 #ifdef G4VERBOSE
299  if (verboseLevel>0) {
300  G4cout << "G4ParticleDefinition::FillQuarkContents : "
301  << " illegal SPIN (" << thePDGiSpin << "/2"
302  << " PDG code=" << thePDGEncoding <<G4endl;
303  }
304 #endif
305  }
306  }
307  }
308  return temp;
309 }
310 
312 {
313  G4cout << G4endl;
314  G4cout << "--- G4ParticleDefinition ---" << G4endl;
315  G4cout << " Particle Name : " << theParticleName << G4endl;
316  G4cout << " PDG particle code : " << thePDGEncoding;
317  G4cout << " [PDG anti-particle code: " << this->GetAntiPDGEncoding() << "]"<< G4endl;
318  G4cout << " Mass [GeV/c2] : " << thePDGMass/GeV ;
319  G4cout << " Width : " << thePDGWidth/GeV << G4endl;
320  G4cout << " Lifetime [nsec] : " << thePDGLifeTime/ns << G4endl;
321  G4cout << " Charge [e]: " << thePDGCharge/eplus << G4endl;
322  G4cout << " Spin : " << thePDGiSpin << "/2" << G4endl;
323  G4cout << " Parity : " << thePDGiParity << G4endl;
324  G4cout << " Charge conjugation : " << thePDGiConjugation << G4endl;
325  G4cout << " Isospin : (I,Iz): (" << thePDGiIsospin <<"/2";
326  G4cout << " , " << thePDGiIsospin3 << "/2 ) " << G4endl;
327  G4cout << " GParity : " << thePDGiGParity << G4endl;
328  if (thePDGMagneticMoment != 0.0) {
329  G4cout << " MagneticMoment [MeV/T] : " << thePDGMagneticMoment/MeV*tesla << G4endl;
330  }
331  G4cout << " Quark contents (d,u,s,c,b,t) : " << theQuarkContent[0];
332  G4cout << ", " << theQuarkContent[1];
333  G4cout << ", " << theQuarkContent[2];
334  G4cout << ", " << theQuarkContent[3];
335  G4cout << ", " << theQuarkContent[4];
336  G4cout << ", " << theQuarkContent[5] << G4endl;
337  G4cout << " AntiQuark contents : " << theAntiQuarkContent[0];
338  G4cout << ", " << theAntiQuarkContent[1];
339  G4cout << ", " << theAntiQuarkContent[2];
340  G4cout << ", " << theAntiQuarkContent[3];
341  G4cout << ", " << theAntiQuarkContent[4];
342  G4cout << ", " << theAntiQuarkContent[5] << G4endl;
343  G4cout << " Lepton number : " << theLeptonNumber;
344  G4cout << " Baryon number : " << theBaryonNumber << G4endl;
345  G4cout << " Particle type : " << theParticleType ;
346  G4cout << " [" << theParticleSubType << "]" << G4endl;
347 
348  if ( (theParticleTable->GetIonTable()->IsIon(this))
349  || (theParticleTable->GetIonTable()->IsAntiIon(this)) ) {
350  G4cout << " Atomic Number : " << GetAtomicNumber();
351  G4cout << " Atomic Mass : " << GetAtomicMass() << G4endl;
352  }
353  if ( fShortLivedFlag ){
354  G4cout << " ShortLived : ON" << G4endl;
355  }
356 
357  if ( thePDGStable ){
358  G4cout << " Stable : stable" << G4endl;
359  } else {
360  if( theDecayTable != 0 ){
361  theDecayTable->DumpInfo();
362  } else {
363  G4cout << "Decay Table is not defined !!" <<G4endl;
364  }
365  }
366 
367 }
368 
370 {
371  if(theParticleName=="gamma"
372  || theParticleName=="e-"
373  || theParticleName=="e+"
374  || theParticleName=="proton")
375  { fApplyCutsFlag = flg; }
376  else
377  {
378  G4cout
379  << "G4ParticleDefinition::SetApplyCutsFlag() for " << theParticleName
380  << G4endl;
381  G4cout
382  << "becomes obsolete. Production threshold is applied only for "
383  << "gamma, e- ,e+ and proton." << G4endl;
384  }
385 }
386 
388 {
389  G4Exception( "G4ParticleDefintion::G4ParticleDefintion",
390  "PART114", JustWarning,
391  "CalculateAnomaly() method will be removed in next release");
392 
393  // gives the anomaly of magnetic moment for spin 1/2 particles
394  if (thePDGiSpin==1) {
395  G4double muB = 0.5*CLHEP::eplus*CLHEP::hbar_Planck/(thePDGMass/CLHEP::c_squared);
396  return 0.5*std::fabs(thePDGMagneticMoment/muB - 2.*thePDGCharge/CLHEP::eplus);
397  } else {
398  return 0.0;
399  }
400 }
401 
403 {
404  if(id<0)
405  {
406  g4particleDefinitionInstanceID = subInstanceManager.CreateSubInstance();
407  G4MT_pmanager = 0;
408  }
409  else
410  {
411  if(isGeneralIon)
412  { g4particleDefinitionInstanceID = id; }
413  else
414  {
416  ed << "ParticleDefinitionID should not be set for the particles <"
417  << theParticleName << ">.";
418  G4Exception( "G4ParticleDefintion::SetParticleDefinitionID","PART10114",
419  FatalException,ed);
420  }
421  }
422 }
423 
424 #include "G4Threading.hh"
425 
427 {
428  if(g4particleDefinitionInstanceID<0 && !isGeneralIon)
429  {
430  if(G4Threading::G4GetThreadId() >= 0)
431  {
433  ed << "ProcessManager is being set to " << theParticleName
434  << " without proper initialization of TLS pointer vector.\n"
435  << "This operation is thread-unsafe.";
436  G4Exception( "G4ParticleDefintion::SetProcessManager","PART10116",
437  JustWarning,ed);
438  }
440  }
441  G4MT_pmanager = aProcessManager;
442 }
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:1044
G4int GetSpin() const
#define width
static G4bool IsAntiIon(const G4ParticleDefinition *)
Definition: G4IonTable.cc:1069
#define G4ThreadLocal
Definition: tls.hh:52
static const G4PDefManager & GetSubInstanceManager()
int G4int
Definition: G4Types.hh:78
const G4String & GetParticleName() const
G4int GetAtomicNumber() const
G4int CheckPDGCode(G4int code, G4String type)
G4int GetAntiPDGEncoding() 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
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
G4int theAntiQuarkContent[NumberOfQuarkFlavor]
static G4ParticleTable * GetParticleTable()
void SetVerboseLevel(G4int verbose)
G4int theQuarkContent[NumberOfQuarkFlavor]
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4double GetPDGCharge() const
G4int GetVerboseLevel() const
#define ns
Definition: xmlparse.cc:597
G4int CreateSubInstance()
G4ApplicationState
G4int G4GetThreadId()
Definition: G4Threading.cc:103
void SetAtomicMass(G4int)
#define G4MT_pmanager