Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4PrimaryTransformer Class Reference

#include <G4PrimaryTransformer.hh>

Collaboration diagram for G4PrimaryTransformer:

Public Member Functions

 G4PrimaryTransformer ()
 
virtual ~G4PrimaryTransformer ()
 
G4TrackVectorGimmePrimaries (G4Event *anEvent, G4int trackIDCounter=0)
 
void CheckUnknown ()
 
void SetVerboseLevel (G4int vl)
 
void SetUnknnownParticleDefined (G4bool vl)
 
G4bool GetUnknownParticleDefined () const
 

Protected Member Functions

void GenerateTracks (G4PrimaryVertex *primaryVertex)
 
void GenerateSingleTrack (G4PrimaryParticle *primaryParticle, G4double x0, G4double y0, G4double z0, G4double t0, G4double wv)
 
void SetDecayProducts (G4PrimaryParticle *mother, G4DynamicParticle *motherDP)
 
G4bool CheckDynamicParticle (G4DynamicParticle *DP)
 
virtual G4ParticleDefinitionGetDefinition (G4PrimaryParticle *pp)
 
virtual G4bool IsGoodForTrack (G4ParticleDefinition *pd)
 

Protected Attributes

G4TrackVector TV
 
G4ParticleTableparticleTable
 
G4int verboseLevel
 
G4int trackID
 
G4ParticleDefinitionunknown
 
G4bool unknownParticleDefined
 
G4ParticleDefinitionopticalphoton
 
G4bool opticalphotonDefined
 
G4int nWarn
 

Detailed Description

Definition at line 47 of file G4PrimaryTransformer.hh.

Constructor & Destructor Documentation

G4PrimaryTransformer::G4PrimaryTransformer ( )

Definition at line 43 of file G4PrimaryTransformer.cc.

Here is the call graph for this function:

G4PrimaryTransformer::~G4PrimaryTransformer ( )
virtual

Definition at line 53 of file G4PrimaryTransformer.cc.

54 {;}

Member Function Documentation

G4bool G4PrimaryTransformer::CheckDynamicParticle ( G4DynamicParticle DP)
protected

Definition at line 307 of file G4PrimaryTransformer.cc.

308 {
309  if(IsGoodForTrack(DP->GetDefinition())) return true;
311  if(decayProducts && decayProducts->entries()>0) return true;
312  G4cerr << G4endl
313  << "G4PrimaryTransformer: a shortlived primary particle is found" << G4endl
314  << " without any valid decay table nor pre-assigned decay mode." << G4endl;
315  G4Exception("G4PrimaryTransformer","InvalidPrimary",JustWarning,
316  "This primary particle will be ignored.");
317  return false;
318 }
const G4DecayProducts * GetPreAssignedDecayProducts() const
G4ParticleDefinition * GetDefinition() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual G4bool IsGoodForTrack(G4ParticleDefinition *pd)
#define G4endl
Definition: G4ios.hh:61
G4int entries() const
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

void G4PrimaryTransformer::CheckUnknown ( )

Definition at line 56 of file G4PrimaryTransformer.cc.

57 {
58  unknown = particleTable->FindParticle("unknown");
59  if(unknown)
60  { unknownParticleDefined = true; }
61  else
62  { unknownParticleDefined = false; }
63  opticalphoton = particleTable->FindParticle("opticalphoton");
64  if(opticalphoton)
65  { opticalphotonDefined = true; }
66  else
67  { opticalphotonDefined = false; }
68 }
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4ParticleDefinition * opticalphoton
G4ParticleTable * particleTable
G4ParticleDefinition * unknown

Here is the call graph for this function:

Here is the caller graph for this function:

void G4PrimaryTransformer::GenerateSingleTrack ( G4PrimaryParticle primaryParticle,
G4double  x0,
G4double  y0,
G4double  z0,
G4double  t0,
G4double  wv 
)
protected

Definition at line 117 of file G4PrimaryTransformer.cc.

119 {
120  G4ParticleDefinition* partDef = GetDefinition(primaryParticle);
121  if(!IsGoodForTrack(partDef))
122  // The particle cannot be converted to G4Track, check daughters
123  {
124 #ifdef G4VERBOSE
125  if(verboseLevel>2)
126  {
127  G4cout << "Primary particle (PDGcode " << primaryParticle->GetPDGcode()
128  << ") --- Ignored" << G4endl;
129  }
130 #endif
131  G4PrimaryParticle* daughter = primaryParticle->GetDaughter();
132  while(daughter) // Loop checking 12.28.2015 M.Asai
133  {
134  GenerateSingleTrack(daughter,x0,y0,z0,t0,wv);
135  daughter = daughter->GetNext();
136  }
137  }
138 
139  // The particle is defined in GEANT4
140  else
141  {
142  // Create G4DynamicParticle object
143 #ifdef G4VERBOSE
144  if(verboseLevel>1)
145  {
146  G4cout << "Primary particle (" << partDef->GetParticleName()
147  << ") --- Transfered with momentum " << primaryParticle->GetMomentum()
148  << G4endl;
149  }
150 #endif
151  G4DynamicParticle* DP =
152  new G4DynamicParticle(partDef,
153  primaryParticle->GetMomentumDirection(),
154  primaryParticle->GetKineticEnergy());
155  if(opticalphotonDefined && partDef==opticalphoton && primaryParticle->GetPolarization().mag2()==0.)
156  {
157  if(nWarn<10)
158  {
159  G4Exception("G4PrimaryTransformer::GenerateSingleTrack","ZeroPolarization",JustWarning,
160  "Polarization of the optical photon is null. Random polarization is assumed.");
161  G4cerr << "This warning message is issued up to 10 times." << G4endl;
162  nWarn++;
163  }
164 
165  G4double angle = G4UniformRand() * 360.0*deg;
166  G4ThreeVector normal (1., 0., 0.);
167  G4ThreeVector kphoton = DP->GetMomentumDirection();
168  G4ThreeVector product = normal.cross(kphoton);
169  G4double modul2 = product*product;
170 
171  G4ThreeVector e_perpend (0., 0., 1.);
172  if (modul2 > 0.) e_perpend = (1./std::sqrt(modul2))*product;
173  G4ThreeVector e_paralle = e_perpend.cross(kphoton);
174 
175  G4ThreeVector polar = std::cos(angle)*e_paralle + std::sin(angle)*e_perpend;
176  DP->SetPolarization(polar.x(),polar.y(),polar.z());
177  }
178  else
179  {
180  DP->SetPolarization(primaryParticle->GetPolX(),
181  primaryParticle->GetPolY(),
182  primaryParticle->GetPolZ());
183  }
184  if(primaryParticle->GetProperTime()>0.0)
185  { DP->SetPreAssignedDecayProperTime(primaryParticle->GetProperTime()); }
186 
187  // Set Mass if it is specified
188  G4double pmas = primaryParticle->GetMass();
189  if(pmas>=0.)
190  { DP->SetMass(pmas); }
191 
192  // Set Charge if it is specified
193  if (primaryParticle->GetCharge()<DBL_MAX) {
194  if (partDef->GetAtomicNumber() <0) {
195  DP->SetCharge(primaryParticle->GetCharge());
196  } else {
197  // ions
198  G4int iz = partDef->GetAtomicNumber();
199  G4int iq = static_cast<int>(primaryParticle->GetCharge()/eplus);
200  G4int n_e = iz - iq;
201  if (n_e>0) DP->AddElectron(0,n_e);
202  }
203  }
204  // Set decay products to the DynamicParticle
205  SetDecayProducts( primaryParticle, DP );
206  // Set primary particle
207  DP->SetPrimaryParticle(primaryParticle);
208  // Set PDG code if it is different from G4ParticleDefinition
209  if(partDef->GetPDGEncoding()==0 && primaryParticle->GetPDGcode()!=0)
210  {
211  DP->SetPDGcode(primaryParticle->GetPDGcode());
212  }
213  // Check the particle is properly constructed
214  if(!CheckDynamicParticle(DP))
215  {
216  delete DP;
217  return;
218  }
219  // Create G4Track object
220  G4Track* track = new G4Track(DP,t0,G4ThreeVector(x0,y0,z0));
221  // Set trackID and let primary particle know it
222  trackID++;
223  track->SetTrackID(trackID);
224  primaryParticle->SetTrackID(trackID);
225  // Set parentID to 0 as a primary particle
226  track->SetParentID(0);
227  // Set weight ( vertex weight * particle weight )
228  track->SetWeight(wv*(primaryParticle->GetWeight()));
229  // Store it to G4TrackVector
230  TV.push_back( track );
231 
232  }
233 }
G4double GetPolX() const
G4ThreeVector GetMomentum() const
void SetPreAssignedDecayProperTime(G4double)
CLHEP::Hep3Vector G4ThreeVector
double x() const
G4double GetKineticEnergy() const
G4ThreeVector GetPolarization() const
static G4double angle[DIM]
G4double GetPolZ() const
G4bool CheckDynamicParticle(G4DynamicParticle *DP)
G4double GetPolY() const
int G4int
Definition: G4Types.hh:78
const G4ThreeVector & GetMomentumDirection() const
G4ParticleDefinition * opticalphoton
const G4String & GetParticleName() const
double z() const
G4int GetAtomicNumber() const
void SetWeight(G4double aValue)
static double normal(HepRandomEngine *eptr)
Definition: RandPoisson.cc:77
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
G4double GetMass() const
const G4ThreeVector & GetMomentumDirection() const
G4PrimaryParticle * GetDaughter() const
static constexpr double eplus
Definition: G4SIunits.hh:199
void SetTrackID(G4int id)
void SetPrimaryParticle(G4PrimaryParticle *p)
void SetPolarization(G4double polX, G4double polY, G4double polZ)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4double GetProperTime() const
virtual G4bool IsGoodForTrack(G4ParticleDefinition *pd)
G4int GetPDGcode() const
G4double GetWeight() const
void AddElectron(G4int orbit, G4int number=1)
G4PrimaryParticle * GetNext() const
void GenerateSingleTrack(G4PrimaryParticle *primaryParticle, G4double x0, G4double y0, G4double z0, G4double t0, G4double wv)
void SetParentID(const G4int aValue)
double y() const
G4double GetCharge() const
double mag2() const
#define G4endl
Definition: G4ios.hh:61
virtual G4ParticleDefinition * GetDefinition(G4PrimaryParticle *pp)
Hep3Vector cross(const Hep3Vector &) const
void SetPDGcode(G4int c)
double G4double
Definition: G4Types.hh:76
static constexpr double deg
Definition: G4SIunits.hh:152
void SetCharge(G4double charge)
#define DBL_MAX
Definition: templates.hh:83
void SetMass(G4double mass)
void SetTrackID(const G4int aValue)
G4GLOB_DLL std::ostream G4cerr
void SetDecayProducts(G4PrimaryParticle *mother, G4DynamicParticle *motherDP)

Here is the call graph for this function:

Here is the caller graph for this function:

void G4PrimaryTransformer::GenerateTracks ( G4PrimaryVertex primaryVertex)
protected

Definition at line 88 of file G4PrimaryTransformer.cc.

89 {
90  G4double X0 = primaryVertex->GetX0();
91  G4double Y0 = primaryVertex->GetY0();
92  G4double Z0 = primaryVertex->GetZ0();
93  G4double T0 = primaryVertex->GetT0();
94  G4double WV = primaryVertex->GetWeight();
95 
96 #ifdef G4VERBOSE
97  if(verboseLevel>2) {
98  primaryVertex->Print();
99  } else if (verboseLevel==1) {
100  G4cout << "G4PrimaryTransformer::PrimaryVertex ("
101  << X0 / mm << "(mm),"
102  << Y0 / mm << "(mm),"
103  << Z0 / mm << "(mm),"
104  << T0 / nanosecond << "(nsec))" << G4endl;
105  }
106 #endif
107 
108  G4PrimaryParticle* primaryParticle = primaryVertex->GetPrimary();
109  while( primaryParticle != 0 ) // Loop checking 12.28.2015 M.Asai
110  {
111  GenerateSingleTrack( primaryParticle, X0, Y0, Z0, T0, WV );
112  primaryParticle = primaryParticle->GetNext();
113  }
114 }
G4double GetX0() const
static constexpr double mm
Definition: G4SIunits.hh:115
void Print() const
G4double GetT0() const
static constexpr double nanosecond
Definition: G4SIunits.hh:158
G4double GetWeight() const
G4PrimaryParticle * GetPrimary(G4int i=0) const
G4GLOB_DLL std::ostream G4cout
G4double GetZ0() const
G4PrimaryParticle * GetNext() const
void GenerateSingleTrack(G4PrimaryParticle *primaryParticle, G4double x0, G4double y0, G4double z0, G4double t0, G4double wv)
G4double GetY0() const
static const G4double T0[78]
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

G4ParticleDefinition * G4PrimaryTransformer::GetDefinition ( G4PrimaryParticle pp)
protectedvirtual

Definition at line 320 of file G4PrimaryTransformer.cc.

321 {
322  G4ParticleDefinition* partDef = pp->GetG4code();
323  if(!partDef) partDef = particleTable->FindParticle(pp->GetPDGcode());
324  if(unknownParticleDefined && ((!partDef)||partDef->IsShortLived())) partDef = unknown;
325  return partDef;
326 }
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4ParticleDefinition * GetG4code() const
G4int GetPDGcode() const
G4ParticleTable * particleTable
G4ParticleDefinition * unknown

Here is the call graph for this function:

G4bool G4PrimaryTransformer::GetUnknownParticleDefined ( ) const
inline

Definition at line 78 of file G4PrimaryTransformer.hh.

G4TrackVector * G4PrimaryTransformer::GimmePrimaries ( G4Event anEvent,
G4int  trackIDCounter = 0 
)

Definition at line 70 of file G4PrimaryTransformer.cc.

71 {
72  trackID = trackIDCounter;
73 
74  //TV.clearAndDestroy();
75  for(auto tr : TV) delete tr;
76  TV.clear();
77 
78  //Loop over vertices
79  G4PrimaryVertex* nextVertex = anEvent->GetPrimaryVertex();
80  while(nextVertex) // Loop checking 12.28.2015 M.Asai
81  {
82  GenerateTracks(nextVertex);
83  nextVertex = nextVertex->GetNext();
84  }
85  return &TV;
86 }
G4PrimaryVertex * GetPrimaryVertex(G4int i=0) const
Definition: G4Event.hh:167
G4PrimaryVertex * GetNext() const
void GenerateTracks(G4PrimaryVertex *primaryVertex)

Here is the call graph for this function:

G4bool G4PrimaryTransformer::IsGoodForTrack ( G4ParticleDefinition pd)
protectedvirtual

Definition at line 328 of file G4PrimaryTransformer.cc.

329 {
330  if(!pd)
331  { return false; }
332  else if(!(pd->IsShortLived()))
333  { return true; }
334 // Following two lines should be removed if the user does not want to make shortlived
335 // primary particle with proper decay table to be converted into a track.
336  else if(pd->GetDecayTable())
337  { return true; }
338  return false;
339 }
G4DecayTable * GetDecayTable() const

Here is the call graph for this function:

Here is the caller graph for this function:

void G4PrimaryTransformer::SetDecayProducts ( G4PrimaryParticle mother,
G4DynamicParticle motherDP 
)
protected

Definition at line 236 of file G4PrimaryTransformer.cc.

237 {
238  G4PrimaryParticle* daughter = mother->GetDaughter();
239  if(!daughter) return;
240  G4DecayProducts* decayProducts = (G4DecayProducts*)(motherDP->GetPreAssignedDecayProducts() );
241  if(!decayProducts)
242  {
243  decayProducts = new G4DecayProducts(*motherDP);
244  motherDP->SetPreAssignedDecayProducts(decayProducts);
245  }
246  while(daughter)
247  {
248  G4ParticleDefinition* partDef = GetDefinition(daughter);
249  if(!IsGoodForTrack(partDef))
250  {
251 #ifdef G4VERBOSE
252  if(verboseLevel>2)
253  {
254  G4cout << " >> Decay product (PDGcode " << daughter->GetPDGcode()
255  << ") --- Ignored" << G4endl;
256  }
257 #endif
258  SetDecayProducts(daughter,motherDP);
259  }
260  else
261  {
262 #ifdef G4VERBOSE
263  if(verboseLevel>1)
264  {
265  G4cout << " >> Decay product (" << partDef->GetParticleName()
266  << ") --- Attached with momentum " << daughter->GetMomentum()
267  << G4endl;
268  }
269 #endif
271  = new G4DynamicParticle(partDef,daughter->GetMomentum());
272  DP->SetPrimaryParticle(daughter);
273  // Decay proper time for daughter
274  if(daughter->GetProperTime()>0.0)
275  { DP->SetPreAssignedDecayProperTime(daughter->GetProperTime()); }
276  // Set Charge is specified
277  if (daughter->GetCharge()<DBL_MAX) {
278  DP->SetCharge(daughter->GetCharge());
279  }
280  G4double pmas = daughter->GetMass();
281  if(pmas>=0.)
282  { DP->SetMass(pmas); }
283  DP->SetPolarization(daughter->GetPolX(),daughter->GetPolY(),daughter->GetPolZ());
284  decayProducts->PushProducts(DP);
285  SetDecayProducts(daughter,DP);
286  // Check the particle is properly constructed
287  if(!CheckDynamicParticle(DP))
288  {
289  delete DP;
290  return;
291  }
292  }
293  daughter = daughter->GetNext();
294  }
295 }
G4double GetPolX() const
G4ThreeVector GetMomentum() const
void SetPreAssignedDecayProperTime(G4double)
G4int PushProducts(G4DynamicParticle *aParticle)
const G4DecayProducts * GetPreAssignedDecayProducts() const
G4double GetPolZ() const
G4bool CheckDynamicParticle(G4DynamicParticle *DP)
G4double GetPolY() const
const G4String & GetParticleName() const
G4GLOB_DLL std::ostream G4cout
G4double GetMass() const
G4PrimaryParticle * GetDaughter() const
void SetPrimaryParticle(G4PrimaryParticle *p)
void SetPolarization(G4double polX, G4double polY, G4double polZ)
G4double GetProperTime() const
virtual G4bool IsGoodForTrack(G4ParticleDefinition *pd)
G4int GetPDGcode() const
G4PrimaryParticle * GetNext() const
G4double GetCharge() const
#define G4endl
Definition: G4ios.hh:61
virtual G4ParticleDefinition * GetDefinition(G4PrimaryParticle *pp)
double G4double
Definition: G4Types.hh:76
void SetPreAssignedDecayProducts(G4DecayProducts *aDecayProducts)
void SetCharge(G4double charge)
#define DBL_MAX
Definition: templates.hh:83
void SetMass(G4double mass)
void SetDecayProducts(G4PrimaryParticle *mother, G4DynamicParticle *motherDP)

Here is the call graph for this function:

void G4PrimaryTransformer::SetUnknnownParticleDefined ( G4bool  vl)

Definition at line 297 of file G4PrimaryTransformer.cc.

298 {
301  { G4cerr << "unknownParticleDefined cannot be set true because G4UnknownParticle is not defined in the physics list."
302  << G4endl << "Command ignored." << G4endl;
303  unknownParticleDefined = false;
304  }
305 }
G4ParticleDefinition * unknown
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr
void G4PrimaryTransformer::SetVerboseLevel ( G4int  vl)
inline

Definition at line 70 of file G4PrimaryTransformer.hh.

71  { verboseLevel = vl; };

Here is the caller graph for this function:

Member Data Documentation

G4int G4PrimaryTransformer::nWarn
protected

Definition at line 67 of file G4PrimaryTransformer.hh.

G4ParticleDefinition* G4PrimaryTransformer::opticalphoton
protected

Definition at line 64 of file G4PrimaryTransformer.hh.

G4bool G4PrimaryTransformer::opticalphotonDefined
protected

Definition at line 65 of file G4PrimaryTransformer.hh.

G4ParticleTable* G4PrimaryTransformer::particleTable
protected

Definition at line 58 of file G4PrimaryTransformer.hh.

G4int G4PrimaryTransformer::trackID
protected

Definition at line 60 of file G4PrimaryTransformer.hh.

G4TrackVector G4PrimaryTransformer::TV
protected

Definition at line 57 of file G4PrimaryTransformer.hh.

G4ParticleDefinition* G4PrimaryTransformer::unknown
protected

Definition at line 62 of file G4PrimaryTransformer.hh.

G4bool G4PrimaryTransformer::unknownParticleDefined
protected

Definition at line 63 of file G4PrimaryTransformer.hh.

G4int G4PrimaryTransformer::verboseLevel
protected

Definition at line 59 of file G4PrimaryTransformer.hh.


The documentation for this class was generated from the following files: