ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4CRMCModel.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4CRMCModel.cc
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 // * *
21 // * Parts of this code which have been developed by Abdel-Waged *
22 // * et al under contract (31-465) to the King Abdul-Aziz City for *
23 // * Science and Technology (KACST), the National Centre of *
24 // * Mathematics and Physics (NCMP), Saudi Arabia. *
25 // * *
26 // * By using, copying, modifying or distributing the software (or *
27 // * any work based on the software) you agree to acknowledge its *
28 // * use in resulting scientific publications, and indicate your *
29 // * acceptance of all terms of the Geant4 Software license. *
30 // ********************************************************************
31 //
34 //
35 //
36 //---------------------------------------------------------------------------
37 //
38 // ClassName: CRMCNeutronBuilder
39 //
40 // Author: 2018 Alberto Ribon
41 //
42 // Modified:
43 //
44 //----------------------------------------------------------------------------
45 //
46 #ifdef G4_USE_CRMC
47 
48 #include "G4CRMCModel.hh"
49 #include "globals.hh"
50 #include "G4DynamicParticle.hh"
51 #include "G4IonTable.hh"
52 #include "G4CollisionOutput.hh"
53 #include "G4V3DNucleus.hh"
54 #include "G4Track.hh"
55 #include "G4Nucleus.hh"
56 #include "G4LorentzRotation.hh"
57 #include "G4ParticleDefinition.hh"
58 #include "G4ParticleTable.hh"
59 #include "G4PhysicalConstants.hh"
60 #include "G4SystemOfUnits.hh"
61 #include "G4Version.hh"
62 #include "G4AntiHe3.hh"
63 #include "G4AntiDeuteron.hh"
64 #include "G4AntiTriton.hh"
65 #include "G4AntiAlpha.hh"
66 #include <fstream>
67 #include <string>
68 #include "G4HadronicParameters.hh"
69 
70 
71 G4CRMCModel::G4CRMCModel( const int model ) : G4HadronicInteraction( "CRMC" ), verbose( 0 ),
72  fModel( model ) {
73  if (verbose > 3) {
74  G4cout << " >>> G4CRMCModel default constructor" << G4endl;
75  }
76  WelcomeMessage();
77  CurrentEvent = 0;
78 
79  G4int ranseed = 1234567;
80  G4cout << "\n seed: " << ranseed << G4endl;
81 
82  const char* crmc_param = "crmc.param"; // CRMC default, see CRMCoptions.cc in the CRMC package
83 
84  fInterface = new CRMCinterface;
85  fInterface->init( model );
86 
87  // Open FORTRAN IO at first call.
88  // Notice that the energy unit must be GeV.
89  fInterface->crmc_init( G4HadronicParameters::Instance()->GetMaxEnergy()/GeV,
90  ranseed, model, 0, 0, crmc_param, "", 0 );
91 
92  fParticleTable = G4ParticleTable::GetParticleTable();
93  fIonTable = fParticleTable->GetIonTable();
94 }
95 
96 
98 
99 
100 /*
101 const std::pair< G4double, G4double > G4CRMCModel::GetFatalEnergyCheckLevels() const {
102  // The default in the base class, G4HadronicInteraction, is 2% and 1 GeV .
103  // Note that when both relative and absolute need fail the final-state is rejected
104  // and the interaction is re-sampled.
105  return std::pair< G4double, G4double >( 10.0*perCent, DBL_MAX );
106 }
107 */
108 
109 
111  G4Nucleus &theTarget ) {
112 
113  // Clean up data vectors
114  gCRMC_data.Clean();
115 
116  // The original track will always be discontinued and secondaries followed.
117  fFinalState.Clear();
119 
120  // Get relevant information about the projectile and target (A, Z, energy/nuc, momentum, etc)
121  const G4ParticleDefinition* definitionP = theProjectile.GetDefinition();
122  G4int AP = G4lrint( definitionP->GetBaryonNumber() );
123  G4int ZP = G4lrint( definitionP->GetPDGCharge() );
124  G4int AT = theTarget.GetA_asInt();
125  G4int ZT = theTarget.GetZ_asInt();
126  G4int idProj = definitionP->GetPDGEncoding();
127  G4int idTarg = ZT*10000 + AT*10;
128  G4ThreeVector pBefore = theProjectile.Get4Momentum().vect();
129  G4double E = theProjectile.GetTotalEnergy();
130  G4double totalEbefore = E*AP + theTarget.AtomicMass( AT, ZT ) + theTarget.GetEnergyDeposit();
131 
132  // Note: because of the rotation of the projectile along the z-axis (made by
133  // the calling method G4HadronicProcess::PostStepDoIt), it is equivalent
134  // to take the momentum component along the z-axis or the whole momentum.
135  G4double pProj = theProjectile.Get4Momentum().vect().mag() / GeV; // Energy unit must be GeV
136 
137  // Note: from my understanding of the CRMC interface, it seems that in the case
138  // of nucleus projectile, the energy per nucleon (instead of the energy of
139  // the whole projectile) should be provided.
140  // We consider the absolute value of the baryon number to cover also the
141  // case of anti-nuclei.
142  if ( std::abs( AP ) > 1 ) pProj /= static_cast< G4double >( std::abs( AP ) ); // Energy per nucleon
143 
144  G4double pTarg = 0.0;
145 
146  fInterface->crmc_set( 1, // fNCollision,
147  pProj, // fCfg.fProjectileMomentum,
148  pTarg, // fCfg.fTargetMomentum,
149  idProj, // fCfg.fProjectileId,
150  idTarg ); // fCfg.fTargetId);
151 
152  // Sample 1 interaction
153  fInterface->crmc_generate( 0, // fCfg.fTypoaut,
154  1, // iColl+1,
155  gCRMC_data.fNParticles,
156  gCRMC_data.fImpactParameter,
157  gCRMC_data.fPartId[0],
158  gCRMC_data.fPartPx[0],
159  gCRMC_data.fPartPy[0],
160  gCRMC_data.fPartPz[0],
161  gCRMC_data.fPartEnergy[0],
162  gCRMC_data.fPartMass[0],
163  gCRMC_data.fPartStatus[0] );
164 
165  // Save secondary particles for output
166  for ( G4int i = 0; i < gCRMC_data.fNParticles; i++ ) {
167  // Keep only final state particles
168  // (-9 is the beam, 2 is a particle which decayed and 1 is final)
169  if ( gCRMC_data.fPartStatus[i] != 1 ) continue;
170  G4ParticleDefinition* pdef = GetParticleDefinition( gCRMC_data.fPartId[i] );
172  G4ThreeVector( gCRMC_data.fPartPx[i]*GeV,
173  gCRMC_data.fPartPy[i]*GeV,
174  gCRMC_data.fPartPz[i]*GeV ) );
175  fFinalState.AddSecondary( part );
176  }
177 
178  if ( verbose >= 3 ) {
179  G4double totalEafter = 0.0;
180  G4ThreeVector totalPafter;
181  G4double charge = 0.0;
182  G4int baryon = 0;
183  G4int nSecondaries = fFinalState.GetNumberOfSecondaries();
184  for ( G4int j = 0; j < nSecondaries; j++ ) {
185  totalEafter += fFinalState.GetSecondary(j)->GetParticle()->GetTotalEnergy();
186  totalPafter += fFinalState.GetSecondary(j)->GetParticle()->GetMomentum();
188  charge += pd->GetPDGCharge();
189  baryon += pd->GetBaryonNumber();
190  }
191  G4cout << "----------------------------------------" << G4endl
192  << "Total energy before collision = " << totalEbefore << " MeV" << G4endl
193  << "Total energy after collision = " << totalEafter << " MeV" << G4endl
194  << "Total momentum before collision = " << pBefore << " MeV/c" << G4endl
195  << "Total momentum after collision = " << totalPafter << " MeV/c" << G4endl;
196  if ( verbose >= 4 ) {
197  G4cout << "Total charge before collision = " << (ZP + ZT)*eplus << G4endl
198  << "Total charge after collision = " << charge <<G4endl
199  << "Total baryon number before collision = " << (AP + AT) << G4endl
200  << "Total baryon number after collision = "<< baryon << G4endl;
201  }
202  G4cout << "----------------------------------------" << G4endl;
203  }
204 
205  return &fFinalState;
206 }
207 
208 
209 void G4CRMCModel::WelcomeMessage () const {
210  G4cout << G4endl
211  << " *****************************************************************" << G4endl;
212  if ( fModel == 0 ) {
213  G4cout << " CRMC - EPOS LHC " << G4endl;
214  } else if ( fModel == 1 ) {
215  G4cout << " CRMC - EPOS 1.99" << G4endl;
216  } else if ( fModel == 6 ) {
217  G4cout << " CRMC - SIBYLL 2.3c" << G4endl;
218  } else if ( fModel == 12 ) {
219  G4cout << " CRMC - DPMJET 3" << G4endl;
220  }
221  G4cout << " *****************************************************************" << G4endl
222  << G4endl;
223  return;
224 }
225 
226 
228  // CRMC ion definition : id = crmc_ion_coef_0 + crmc_ion_coef_z*Z + crmc_ion_coef_a*A
229  const G4int crmc_ion_coef_0 = 1000000000;
230  const G4int crmc_ion_coef_z = 10000;
231  const G4int crmc_ion_coef_a = 10;
232  G4ParticleDefinition* pdef = fParticleTable->FindParticle( particle_id );
233  if ( ! pdef && particle_id > crmc_ion_coef_0 ) {
234  int Z = ( particle_id - crmc_ion_coef_0 ) / crmc_ion_coef_z;
235  int A = ( particle_id - crmc_ion_coef_0 - crmc_ion_coef_z*Z ) / crmc_ion_coef_a;
236  pdef = fIonTable->GetIon( Z, A );
237  }
238  return pdef;
239 }
240 
241 #endif //G4_USE_CRMC
242