Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/event/src/G4PrimaryTransformer.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /event/src/G4PrimaryTransformer.cc (Version 11.3.0) and /event/src/G4PrimaryTransformer.cc (Version 10.7.p3)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4PrimaryTransformer class implementation       26 // G4PrimaryTransformer class implementation
 27 //                                                 27 //
 28 // Author: Makoto Asai, 1999                       28 // Author: Makoto Asai, 1999
 29 // -------------------------------------------     29 // --------------------------------------------------------------------
 30                                                    30 
 31 #include "G4PrimaryTransformer.hh"                 31 #include "G4PrimaryTransformer.hh"
 32 #include "G4SystemOfUnits.hh"                      32 #include "G4SystemOfUnits.hh"
 33 #include "G4Event.hh"                              33 #include "G4Event.hh"
 34 #include "G4PrimaryVertex.hh"                      34 #include "G4PrimaryVertex.hh"
 35 #include "G4ParticleDefinition.hh"                 35 #include "G4ParticleDefinition.hh"
 36 #include "G4DynamicParticle.hh"                    36 #include "G4DynamicParticle.hh"
 37 #include "G4Track.hh"                              37 #include "G4Track.hh"
 38 #include "G4ThreeVector.hh"                        38 #include "G4ThreeVector.hh"
 39 #include "G4DecayProducts.hh"                      39 #include "G4DecayProducts.hh"
 40 #include "G4UnitsTable.hh"                         40 #include "G4UnitsTable.hh"
 41 #include "G4ios.hh"                                41 #include "G4ios.hh"
 42 #include "Randomize.hh"                            42 #include "Randomize.hh"
 43                                                    43 
 44 G4double G4PrimaryTransformer::kETolerance = 1 << 
 45 G4ExceptionSeverity G4PrimaryTransformer::kETS << 
 46                                                << 
 47 G4PrimaryTransformer::G4PrimaryTransformer()       44 G4PrimaryTransformer::G4PrimaryTransformer()
 48 {                                                  45 {
 49   particleTable = G4ParticleTable::GetParticle     46   particleTable = G4ParticleTable::GetParticleTable();
 50   CheckUnknown();                                  47   CheckUnknown();
 51 }                                                  48 }
 52                                                    49 
                                                   >>  50 G4PrimaryTransformer::~G4PrimaryTransformer()
                                                   >>  51 {
                                                   >>  52 }
                                                   >>  53 
 53 void G4PrimaryTransformer::CheckUnknown()          54 void G4PrimaryTransformer::CheckUnknown()
 54 {                                                  55 {
 55   unknown = particleTable->FindParticle("unkno     56   unknown = particleTable->FindParticle("unknown");
 56   unknownParticleDefined = unknown != nullptr; <<  57   if(unknown != nullptr) 
 57   chargedunknown = particleTable->FindParticle <<  58   { unknownParticleDefined = true; }
 58   chargedUnknownParticleDefined = chargedunkno <<  59   else
                                                   >>  60   { unknownParticleDefined = false; }
 59   opticalphoton = particleTable->FindParticle(     61   opticalphoton = particleTable->FindParticle("opticalphoton");
 60   opticalphotonDefined = opticalphoton != null <<  62   if(opticalphoton != nullptr) 
                                                   >>  63   { opticalphotonDefined = true; }
                                                   >>  64   else
                                                   >>  65   { opticalphotonDefined = false; }
 61 }                                                  66 }
 62                                                <<  67     
 63 G4TrackVector*                                     68 G4TrackVector*
 64 G4PrimaryTransformer::GimmePrimaries(G4Event*      69 G4PrimaryTransformer::GimmePrimaries(G4Event* anEvent, G4int trackIDCounter)
 65 {                                                  70 {
 66   trackID = trackIDCounter;                        71   trackID = trackIDCounter;
 67                                                    72 
 68   for(auto tr : TV) delete tr;                     73   for(auto tr : TV) delete tr;
 69   TV.clear();                                      74   TV.clear();
 70                                                    75 
 71   // Loop over vertices                            76   // Loop over vertices
 72   //                                               77   //
 73   G4PrimaryVertex* nextVertex = anEvent->GetPr     78   G4PrimaryVertex* nextVertex = anEvent->GetPrimaryVertex();
 74   while(nextVertex != nullptr) // Loop checkin     79   while(nextVertex != nullptr) // Loop checking 12.28.2015 M.Asai
 75   {                                                80   { 
 76     GenerateTracks(nextVertex);                    81     GenerateTracks(nextVertex);
 77     nextVertex = nextVertex->GetNext();            82     nextVertex = nextVertex->GetNext();
 78   }                                                83   }
 79   return &TV;                                      84   return &TV;
 80 }                                                  85 }
 81                                                    86 
 82 void G4PrimaryTransformer::GenerateTracks(G4Pr     87 void G4PrimaryTransformer::GenerateTracks(G4PrimaryVertex* primaryVertex)
 83 {                                                  88 {
 84   G4double X0 = primaryVertex->GetX0();            89   G4double X0 = primaryVertex->GetX0();
 85   G4double Y0 = primaryVertex->GetY0();            90   G4double Y0 = primaryVertex->GetY0();
 86   G4double Z0 = primaryVertex->GetZ0();            91   G4double Z0 = primaryVertex->GetZ0();
 87   G4double T0 = primaryVertex->GetT0();            92   G4double T0 = primaryVertex->GetT0();
 88   G4double WV = primaryVertex->GetWeight();        93   G4double WV = primaryVertex->GetWeight();
 89                                                    94 
 90 #ifdef G4VERBOSE                                   95 #ifdef G4VERBOSE
 91   if(verboseLevel>2)                               96   if(verboseLevel>2)
 92   {                                                97   { 
 93     primaryVertex->Print();                        98     primaryVertex->Print();
 94   }                                                99   }
 95   else if (verboseLevel==1)                       100   else if (verboseLevel==1)
 96   {                                               101   {
 97     G4cout << "G4PrimaryTransformer::PrimaryVe    102     G4cout << "G4PrimaryTransformer::PrimaryVertex ("
 98            << X0 / mm << "(mm),"                  103            << X0 / mm << "(mm),"
 99            << Y0 / mm << "(mm),"                  104            << Y0 / mm << "(mm),"
100            << Z0 / mm << "(mm),"                  105            << Z0 / mm << "(mm),"
101            << T0 / nanosecond << "(nsec))" <<     106            << T0 / nanosecond << "(nsec))" << G4endl;
102   }                                               107   }
103 #endif                                            108 #endif
104                                                   109 
105   G4PrimaryParticle* primaryParticle = primary    110   G4PrimaryParticle* primaryParticle = primaryVertex->GetPrimary();
106   while( primaryParticle != nullptr ) // Loop     111   while( primaryParticle != nullptr ) // Loop checking 12.28.2015 M.Asai
107   {                                               112   {
108     GenerateSingleTrack( primaryParticle, X0,     113     GenerateSingleTrack( primaryParticle, X0, Y0, Z0, T0, WV );
109     primaryParticle = primaryParticle->GetNext    114     primaryParticle = primaryParticle->GetNext();
110   }                                               115   }
111 }                                                 116 }
112                                                   117 
113 void G4PrimaryTransformer::                       118 void G4PrimaryTransformer::
114 GenerateSingleTrack( G4PrimaryParticle* primar    119 GenerateSingleTrack( G4PrimaryParticle* primaryParticle,
115                      G4double x0, G4double y0,    120                      G4double x0, G4double y0, G4double z0,
116                      G4double t0, G4double wv)    121                      G4double t0, G4double wv)
117 {                                                 122 {
118   G4ParticleDefinition* partDef = GetDefinitio    123   G4ParticleDefinition* partDef = GetDefinition(primaryParticle);
119   if(!IsGoodForTrack(partDef))                    124   if(!IsGoodForTrack(partDef))
120   {  // The particle cannot be converted to G4    125   {  // The particle cannot be converted to G4Track, check daughters
121 #ifdef G4VERBOSE                                  126 #ifdef G4VERBOSE
122     if(verboseLevel>1)                         << 127     if(verboseLevel>2)
123     {                                             128     {
124       G4cout << "Primary particle (PDGcode " <    129       G4cout << "Primary particle (PDGcode " << primaryParticle->GetPDGcode()
125              << ") --- Ignored" << G4endl;        130              << ") --- Ignored" << G4endl;
126     }                                             131     }
127 #endif                                            132 #endif 
128     G4PrimaryParticle* daughter = primaryParti    133     G4PrimaryParticle* daughter = primaryParticle->GetDaughter();
129     while(daughter != nullptr) // Loop checkin    134     while(daughter != nullptr) // Loop checking 12.28.2015 M.Asai
130     {                                             135     {
131       GenerateSingleTrack(daughter,x0,y0,z0,t0    136       GenerateSingleTrack(daughter,x0,y0,z0,t0,wv);
132       daughter = daughter->GetNext();             137       daughter = daughter->GetNext();
133     }                                             138     }
134   }                                               139   }
135   else  // The particle is defined in GEANT4      140   else  // The particle is defined in GEANT4
136   {                                               141   {
137     // Create G4DynamicParticle object            142     // Create G4DynamicParticle object
138 #ifdef G4VERBOSE                                  143 #ifdef G4VERBOSE
139     if(verboseLevel>1)                            144     if(verboseLevel>1)
140     {                                             145     {
141       G4cout << "Primary particle (" << partDe    146       G4cout << "Primary particle (" << partDef->GetParticleName()
142              << ") --- Transferred with moment    147              << ") --- Transferred with momentum "
143              << primaryParticle->GetMomentum()    148              << primaryParticle->GetMomentum()
144              << G4endl;                           149              << G4endl;
145     }                                             150     }
146 #endif                                            151 #endif
147     // Check the mass of the "real" particle   << 152     G4DynamicParticle* DP = 
148     // N.B. PDG code 0 is used for artificial  << 
149     if(primaryParticle->GetPDGcode() != 0 && k << 
150     {                                          << 
151       G4double pmas = partDef->GetPDGMass();   << 
152       if(std::abs(pmas - primaryParticle->GetM << 
153         G4ExceptionDescription ed;             << 
154         ed << "Primary particle PDG=" << prima << 
155            << " deltaMass(MeV)=" << (std::abs( << 
156            << " is larger than the tolerance(M << 
157            << "\n Specified mass(MeV)=" << (pr << 
158            << " while PDG mass(MEV)=" << pmas/ << 
159            << "\n To change the tolerance or t << 
160            << " use G4PrimaryTransformer::SetK << 
161         G4Exception("G4PrimaryParticle::Set4Mo << 
162       }                                        << 
163     }                                          << 
164     auto* DP =                                 << 
165       new G4DynamicParticle(partDef,              153       new G4DynamicParticle(partDef,
166                             primaryParticle->G    154                             primaryParticle->GetMomentumDirection(),
167                             primaryParticle->G    155                             primaryParticle->GetKineticEnergy());
168     if(opticalphotonDefined && partDef==optica    156     if(opticalphotonDefined && partDef==opticalphoton
169        && primaryParticle->GetPolarization().m    157        && primaryParticle->GetPolarization().mag2()==0.)
170     {                                             158     {
171       if(nWarn<10)                                159       if(nWarn<10)
172       {                                           160       {
173         G4Exception("G4PrimaryTransformer::Gen    161         G4Exception("G4PrimaryTransformer::GenerateSingleTrack",
174                     "ZeroPolarization", JustWa    162                     "ZeroPolarization", JustWarning,
175                     "Polarization of the optic    163                     "Polarization of the optical photon is null.\
176                      Random polarization is as    164                      Random polarization is assumed.");
177         G4cerr << "This warning message is iss    165         G4cerr << "This warning message is issued up to 10 times." << G4endl;
178         ++nWarn;                                  166         ++nWarn;
179       }                                           167       }
180                                                   168 
181       G4double angle = G4UniformRand() * 360.0    169       G4double angle = G4UniformRand() * 360.0*deg;
182       G4ThreeVector normal (1., 0., 0.);          170       G4ThreeVector normal (1., 0., 0.);
183       G4ThreeVector kphoton = DP->GetMomentumD    171       G4ThreeVector kphoton = DP->GetMomentumDirection();
184       G4ThreeVector product = normal.cross(kph    172       G4ThreeVector product = normal.cross(kphoton);
185       G4double modul2       = product*product;    173       G4double modul2       = product*product;
186                                                   174 
187       G4ThreeVector e_perpend (0., 0., 1.);       175       G4ThreeVector e_perpend (0., 0., 1.);
188       if (modul2 > 0.) e_perpend = (1./std::sq    176       if (modul2 > 0.) e_perpend = (1./std::sqrt(modul2))*product;
189       G4ThreeVector e_paralle    = e_perpend.c    177       G4ThreeVector e_paralle    = e_perpend.cross(kphoton);
190                                                   178 
191       G4ThreeVector polar = std::cos(angle)*e_    179       G4ThreeVector polar = std::cos(angle)*e_paralle
192                           + std::sin(angle)*e_    180                           + std::sin(angle)*e_perpend;
193       DP->SetPolarization(polar.x(),polar.y(),    181       DP->SetPolarization(polar.x(),polar.y(),polar.z());
194     }                                             182     }
195     else                                          183     else
196     {                                             184     {
197       DP->SetPolarization(primaryParticle->Get    185       DP->SetPolarization(primaryParticle->GetPolX(),
198                           primaryParticle->Get    186                           primaryParticle->GetPolY(),
199                           primaryParticle->Get    187                           primaryParticle->GetPolZ());
200     }                                             188     }
201     if(primaryParticle->GetProperTime()>=0.0)     189     if(primaryParticle->GetProperTime()>=0.0)
202     {                                             190     {
203       DP->SetPreAssignedDecayProperTime(primar    191       DP->SetPreAssignedDecayProperTime(primaryParticle->GetProperTime());
204     }                                             192     }
205                                                   193 
206     // Set Mass if it is specified                194     // Set Mass if it is specified
207     //                                            195     //
208     G4double pmas = primaryParticle->GetMass()    196     G4double pmas = primaryParticle->GetMass();
209     if(pmas>=0.) { DP->SetMass(pmas); }           197     if(pmas>=0.) { DP->SetMass(pmas); }
210                                                   198 
211     // Set Charge if it is specified              199     // Set Charge if it is specified
212     //                                            200     //
213     if (primaryParticle->GetCharge()<DBL_MAX)     201     if (primaryParticle->GetCharge()<DBL_MAX)
214     {                                             202     {
215       if (partDef->GetAtomicNumber() <0)          203       if (partDef->GetAtomicNumber() <0)
216       {                                           204       {
217         DP->SetCharge(primaryParticle->GetChar    205         DP->SetCharge(primaryParticle->GetCharge());
218       }                                           206       }
219       else  // ions                               207       else  // ions
220       {                                           208       {
221         G4int iz = partDef->GetAtomicNumber();    209         G4int iz = partDef->GetAtomicNumber();
222         auto  iq = static_cast<G4int>(primaryP << 210         G4int iq = static_cast<G4int>(primaryParticle->GetCharge()/eplus);
223         G4int n_e = iz - iq;                      211         G4int n_e = iz - iq;
224         if (n_e>0) DP->AddElectron(0,n_e);        212         if (n_e>0) DP->AddElectron(0,n_e);  
225       }                                           213       }
226     }                                             214     } 
227     // Set decay products to the DynamicPartic    215     // Set decay products to the DynamicParticle
228     //                                            216     //
229     SetDecayProducts( primaryParticle, DP );      217     SetDecayProducts( primaryParticle, DP );
230                                                   218 
231     // Set primary particle                       219     // Set primary particle
232     //                                            220     //
233     DP->SetPrimaryParticle(primaryParticle);      221     DP->SetPrimaryParticle(primaryParticle);
234                                                   222 
235     // Set PDG code if it is different from G4    223     // Set PDG code if it is different from G4ParticleDefinition
236     //                                            224     //
237     if(partDef->GetPDGEncoding()==0 && primary    225     if(partDef->GetPDGEncoding()==0 && primaryParticle->GetPDGcode()!=0)
238     {                                             226     {
239       DP->SetPDGcode(primaryParticle->GetPDGco    227       DP->SetPDGcode(primaryParticle->GetPDGcode());
240     }                                             228     }
241                                                   229 
242     // Check the particle is properly construc    230     // Check the particle is properly constructed
243     //                                            231     //
244     if(!CheckDynamicParticle(DP))                 232     if(!CheckDynamicParticle(DP))
245     {                                             233     {
246       delete DP;                                  234       delete DP;
247       return;                                     235       return;
248     }                                             236     }
249                                                   237 
250     // Create G4Track object                      238     // Create G4Track object
251     //                                            239     //
252     auto  track = new G4Track(DP,t0,G4ThreeVec << 240     G4Track* track = new G4Track(DP,t0,G4ThreeVector(x0,y0,z0));
253                                                   241 
254     // Set trackID and let primary particle kn    242     // Set trackID and let primary particle know it
255     //                                            243     //
256     ++trackID;                                    244     ++trackID;
257     track->SetTrackID(trackID);                   245     track->SetTrackID(trackID);
258     primaryParticle->SetTrackID(trackID);         246     primaryParticle->SetTrackID(trackID);
259                                                   247 
260     // Set parentID to 0 as a primary particle    248     // Set parentID to 0 as a primary particle
261     //                                            249     //
262     track->SetParentID(0);                        250     track->SetParentID(0);
263                                                   251 
264     // Set weight ( vertex weight * particle w    252     // Set weight ( vertex weight * particle weight )
265     //                                            253     //
266     track->SetWeight(wv*(primaryParticle->GetW    254     track->SetWeight(wv*(primaryParticle->GetWeight()));
267                                                   255 
268     // Store it to G4TrackVector                  256     // Store it to G4TrackVector
269     //                                            257     //
270     TV.push_back( track );                        258     TV.push_back( track );
271   }                                               259   }
272 }                                                 260 }
273                                                   261 
274 void G4PrimaryTransformer::                       262 void G4PrimaryTransformer::
275 SetDecayProducts(G4PrimaryParticle* mother, G4    263 SetDecayProducts(G4PrimaryParticle* mother, G4DynamicParticle* motherDP)
276 {                                                 264 {
277   G4PrimaryParticle* daughter = mother->GetDau    265   G4PrimaryParticle* daughter = mother->GetDaughter();
278   if(daughter == nullptr) return;                 266   if(daughter == nullptr) return;
279   auto* decayProducts                          << 267   G4DecayProducts* decayProducts
280     = (G4DecayProducts*)(motherDP->GetPreAssig    268     = (G4DecayProducts*)(motherDP->GetPreAssignedDecayProducts() );
281   if(decayProducts == nullptr)                    269   if(decayProducts == nullptr)
282   {                                               270   {
283     decayProducts = new G4DecayProducts(*mothe    271     decayProducts = new G4DecayProducts(*motherDP);
284     motherDP->SetPreAssignedDecayProducts(deca    272     motherDP->SetPreAssignedDecayProducts(decayProducts);
285   }                                               273   }
286   while(daughter != nullptr)                      274   while(daughter != nullptr)
287   {                                               275   {
288     G4ParticleDefinition* partDef = GetDefinit    276     G4ParticleDefinition* partDef = GetDefinition(daughter);
289     if(!IsGoodForTrack(partDef))                  277     if(!IsGoodForTrack(partDef))
290     {                                             278     { 
291 #ifdef G4VERBOSE                                  279 #ifdef G4VERBOSE
292       if(verboseLevel>2)                          280       if(verboseLevel>2)
293       {                                           281       {
294         G4cout << " >> Decay product (PDGcode     282         G4cout << " >> Decay product (PDGcode " << daughter->GetPDGcode()
295                << ") --- Ignored" << G4endl;      283                << ") --- Ignored" << G4endl;
296       }                                           284       }
297 #endif                                            285 #endif 
298       SetDecayProducts(daughter,motherDP);        286       SetDecayProducts(daughter,motherDP);
299     }                                             287     }
300     else                                          288     else
301     {                                             289     {
302 #ifdef G4VERBOSE                                  290 #ifdef G4VERBOSE
303       if(verboseLevel>1)                          291       if(verboseLevel>1)
304       {                                           292       {
305         G4cout << " >> Decay product (" << par    293         G4cout << " >> Decay product (" << partDef->GetParticleName()
306                << ") --- Attached with momentu    294                << ") --- Attached with momentum " << daughter->GetMomentum()
307                << G4endl;                         295                << G4endl;
308       }                                           296       }
309 #endif                                            297 #endif
310       auto* DP                                 << 298       G4DynamicParticle* DP 
311         = new G4DynamicParticle(partDef,daught    299         = new G4DynamicParticle(partDef,daughter->GetMomentum());
312       DP->SetPrimaryParticle(daughter);           300       DP->SetPrimaryParticle(daughter);
313                                                   301 
314       // Decay proper time for daughter           302       // Decay proper time for daughter
315       //                                          303       //
316       if(daughter->GetProperTime()>=0.0)          304       if(daughter->GetProperTime()>=0.0)
317       {                                           305       {
318         DP->SetPreAssignedDecayProperTime(daug    306         DP->SetPreAssignedDecayProperTime(daughter->GetProperTime());
319       }                                           307       }
320                                                   308 
321       // Set Charge and Mass is specified         309       // Set Charge and Mass is specified
322       //                                          310       //
323       if (daughter->GetCharge()<DBL_MAX)          311       if (daughter->GetCharge()<DBL_MAX)
324       {                                           312       {
325         DP->SetCharge(daughter->GetCharge());     313         DP->SetCharge(daughter->GetCharge());
326       }                                           314       } 
327       G4double pmas = daughter->GetMass();        315       G4double pmas = daughter->GetMass();
328       if(pmas>=0.)                                316       if(pmas>=0.)
329       {                                           317       {
330         DP->SetMass(pmas);                        318         DP->SetMass(pmas);
331       }                                           319       }
332                                                   320 
333       // Set Polarization                         321       // Set Polarization
334       //                                          322       //
335       DP->SetPolarization(daughter->GetPolX(),    323       DP->SetPolarization(daughter->GetPolX(),
336                           daughter->GetPolY(),    324                           daughter->GetPolY(),
337                           daughter->GetPolZ())    325                           daughter->GetPolZ());
338       decayProducts->PushProducts(DP);            326       decayProducts->PushProducts(DP);
339       SetDecayProducts(daughter,DP);              327       SetDecayProducts(daughter,DP);
340                                                   328 
341       // Check the particle is properly constr    329       // Check the particle is properly constructed
342       //                                          330       //
343       if(!CheckDynamicParticle(DP))               331       if(!CheckDynamicParticle(DP))
344       {                                           332       {
345         delete DP;                                333         delete DP;
346         return;                                   334         return;
347       }                                           335       }
348     }                                             336     }
349     daughter = daughter->GetNext();               337     daughter = daughter->GetNext();
350   }                                               338   }
351 }                                                 339 }
352                                                   340 
353 void G4PrimaryTransformer::SetUnknownParticleD << 341 void G4PrimaryTransformer::SetUnknnownParticleDefined(G4bool vl)
354 {                                                 342 {
355   unknownParticleDefined = vl;                    343   unknownParticleDefined = vl;
356   if(unknownParticleDefined && (unknown == nul << 344   if(unknownParticleDefined && !unknown)
357   {                                               345   {
358     G4cerr << "unknownParticleDefined cannot b    346     G4cerr << "unknownParticleDefined cannot be set true because" << G4endl
359            << "G4UnknownParticle is not define    347            << "G4UnknownParticle is not defined in the physics list." << G4endl
360            << "Command ignored." << G4endl;       348            << "Command ignored." << G4endl;
361     unknownParticleDefined = false;               349     unknownParticleDefined = false;
362   }                                               350   }
363 }                                                 351 }
364                                                   352 
365 void G4PrimaryTransformer::SetChargedUnknownPa << 
366 {                                              << 
367   chargedUnknownParticleDefined = vl;          << 
368   if(chargedUnknownParticleDefined && (charged << 
369   {                                            << 
370     G4cerr << "chargedUnknownParticleDefined c << 
371            << "G4ChargedUnknownParticle is not << 
372            << "Command ignored." << G4endl;    << 
373     chargedUnknownParticleDefined = false;     << 
374   }                                            << 
375 }                                              << 
376                                                << 
377 G4bool G4PrimaryTransformer::CheckDynamicParti    353 G4bool G4PrimaryTransformer::CheckDynamicParticle(G4DynamicParticle* DP)
378 {                                                 354 {
379   if(IsGoodForTrack(DP->GetDefinition())) retu    355   if(IsGoodForTrack(DP->GetDefinition())) return true;
380   auto* decayProducts                          << 356   G4DecayProducts* decayProducts
381     = (G4DecayProducts*)(DP->GetPreAssignedDec    357     = (G4DecayProducts*)(DP->GetPreAssignedDecayProducts());
382   if(decayProducts != nullptr && decayProducts    358   if(decayProducts != nullptr && decayProducts->entries()>0) return true;
383   G4cerr << G4endl                                359   G4cerr << G4endl
384          << "G4PrimaryTransformer: a shortlive    360          << "G4PrimaryTransformer: a shortlived primary particle is found"
385          << G4endl                                361          << G4endl
386          << " without any valid decay table no    362          << " without any valid decay table nor pre-assigned decay mode."
387          << G4endl;                               363          << G4endl;
388   G4Exception("G4PrimaryTransformer", "Invalid    364   G4Exception("G4PrimaryTransformer", "InvalidPrimary", JustWarning,
389               "This primary particle will be i    365               "This primary particle will be ignored.");
390   return false;                                   366   return false;
391 }                                                 367 }
392                                                   368 
393 G4ParticleDefinition*                             369 G4ParticleDefinition*
394 G4PrimaryTransformer::GetDefinition(G4PrimaryP    370 G4PrimaryTransformer::GetDefinition(G4PrimaryParticle* pp)
395 {                                                 371 {
396   G4ParticleDefinition* partDef = pp->GetG4cod    372   G4ParticleDefinition* partDef = pp->GetG4code();
397   if(partDef == nullptr)                          373   if(partDef == nullptr)
398   {                                               374   {
399     partDef = particleTable->FindParticle(pp->    375     partDef = particleTable->FindParticle(pp->GetPDGcode());
400   }                                               376   }
401   if((partDef == nullptr) || partDef->IsShortL << 377   if(unknownParticleDefined && ((!partDef)||partDef->IsShortLived()))
402   {                                               378   {
403     if (chargedUnknownParticleDefined && pp->G << 379     partDef = unknown;
404     {                                          << 
405       partDef = chargedunknown;                << 
406     }                                          << 
407     else if (unknownParticleDefined)           << 
408     {                                          << 
409       partDef = unknown;                       << 
410     }                                          << 
411   }                                               380   }
412   return partDef;                                 381   return partDef;
413 }                                                 382 }
414                                                   383 
415 G4bool G4PrimaryTransformer::IsGoodForTrack(G4    384 G4bool G4PrimaryTransformer::IsGoodForTrack(G4ParticleDefinition* pd)
416 {                                                 385 {
417   if(pd == nullptr)                               386   if(pd == nullptr)
418   { return false; }                               387   { return false; }
419   if(!(pd->IsShortLived()))                    << 388   else if(!(pd->IsShortLived()))
420   { return true; }                                389   { return true; }
421   //                                              390   //
422   // Following two lines should be removed if     391   // Following two lines should be removed if the user does not want to make
423   // shortlived primary particle with proper d    392   // shortlived primary particle with proper decay table to be converted into
424   // a track.                                     393   // a track.
425   //                                              394   //
426   if(pd->GetDecayTable() != nullptr)           << 395   else if(pd->GetDecayTable() != nullptr)
427   { return true; }                                396   { return true; }
428                                                   397 
429   return false;                                   398   return false;
430 }                                                 399 }
431                                                   400