Geant4  10.02.p02
G4HadronicProcess.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 // $Id: G4HadronicProcess.cc 93817 2015-11-02 11:33:26Z gcosmo $
27 //
28 // -------------------------------------------------------------------
29 //
30 // GEANT4 Class source file
31 //
32 // G4HadronicProcess
33 //
34 // original by H.P.Wellisch
35 // J.L. Chuma, TRIUMF, 10-Mar-1997
36 //
37 // Modifications:
38 // 05-Jul-2010 V.Ivanchenko cleanup commented lines
39 // 20-Jul-2011 M.Kelsey -- null-pointer checks in DumpState()
40 // 24-Sep-2011 M.Kelsey -- Use envvar G4HADRONIC_RANDOM_FILE to save random
41 // engine state before each model call
42 // 18-Oct-2011 M.Kelsey -- Handle final-state cases in conservation checks.
43 // 14-Mar-2012 G.Folger -- enhance checks for conservation of energy, etc.
44 // 28-Jul-2012 M.Maire -- add function GetTargetDefinition()
45 // 14-Sep-2012 Inherit from RestDiscrete, use subtype code (now in ctor) to
46 // configure base-class
47 // 28-Sep-2012 Restore inheritance from G4VDiscreteProcess, remove enable-flag
48 // changing, remove warning message from original ctor.
49 
50 #include "G4HadronicProcess.hh"
51 
52 #include "G4Types.hh"
53 #include "G4SystemOfUnits.hh"
54 #include "G4HadProjectile.hh"
55 #include "G4ElementVector.hh"
56 #include "G4Track.hh"
57 #include "G4Step.hh"
58 #include "G4Element.hh"
59 #include "G4ParticleChange.hh"
61 #include "G4Navigator.hh"
62 #include "G4ProcessVector.hh"
63 #include "G4ProcessManager.hh"
64 #include "G4StableIsotopes.hh"
65 #include "G4HadTmpUtil.hh"
66 #include "G4NucleiProperties.hh"
67 
68 #include "G4HadronicException.hh"
70 
71 #include "G4AutoLock.hh"
72 #include "G4NistManager.hh"
73 
74 #include <typeinfo>
75 #include <sstream>
76 #include <iostream>
77 
78 #include <stdlib.h>
79 
80 // File-scope variable to capture environment variable at startup
81 
82 static const char* G4Hadronic_Random_File = getenv("G4HADRONIC_RANDOM_FILE");
83 
85 
87  G4ProcessType procType)
88  : G4VDiscreteProcess(processName, procType)
89 {
90  SetProcessSubType(fHadronInelastic); // Default unless subclass changes
91 
94  theInteraction = 0;
99  aScaleFactor = 1;
100  xBiasOn = false;
101  theLastCrossSection = 0.0;
104 }
105 
107 
109  G4HadronicProcessType aHadSubType)
110  : G4VDiscreteProcess(processName, fHadronic)
111 {
112  SetProcessSubType(aHadSubType);
113 
116  theInteraction = 0;
119  theProcessStore->Register(this);
121  aScaleFactor = 1;
122  xBiasOn = false;
123  theLastCrossSection = 0.0;
126 }
127 
128 
130 {
132  delete theTotalResult;
134 }
135 
137  levelsSetByProcess = false;
138 
139  epReportLevel = getenv("G4Hadronic_epReportLevel") ?
140  strtol(getenv("G4Hadronic_epReportLevel"),0,10) : 0;
141 
142  epCheckLevels.first = getenv("G4Hadronic_epCheckRelativeLevel") ?
143  strtod(getenv("G4Hadronic_epCheckRelativeLevel"),0) : DBL_MAX;
144 
145  epCheckLevels.second = getenv("G4Hadronic_epCheckAbsoluteLevel") ?
146  strtod(getenv("G4Hadronic_epCheckAbsoluteLevel"),0) : DBL_MAX;
147 }
148 
150 {
151  if(!a) { return; }
152  try{ theEnergyRangeManager.RegisterMe( a ); }
153  catch(G4HadronicException & aE)
154  {
156  aE.Report(ed);
157  ed << "Unrecoverable error in " << GetProcessName()
158  << " to register " << a->GetModelName() << G4endl;
159  G4Exception("G4HadronicProcess::RegisterMe", "had001", FatalException,
160  ed);
161  }
163 }
164 
166  const G4Element * elm,
167  const G4Material* mat)
168 {
169  G4Material* aMaterial = const_cast<G4Material*>(mat);
170  if(! mat)
171  {
172  // Because NeutronHP needs a material pointer (for instance to get the
173  // temperature), we ask the Nist manager to build or find a simple material
174  // from the (integer) Z of the element.
175  // Note that repeated calls to this method are not producing multiple copies
176  // of the same material. But it needs to be protected against race conditions
177  // between different threads.
178  aMaterial = InitialiseMaterial(G4int(elm->GetZ()));
179  }
180  G4double x = theCrossSectionDataStore->GetCrossSection(part, elm, aMaterial);
181  if(x < 0.0) { x = 0.0; }
182  return x;
183 }
184 
185 
186 namespace { G4Mutex hadronicProcessMutex = G4MUTEX_INITIALIZER; }
188 {
189  G4AutoLock l(&hadronicProcessMutex);
191 }
192 
193 
195 {
196  if(getenv("G4HadronicProcess_debug")) {
198  }
200 }
201 
203 {
204  try
205  {
208  }
209  catch(G4HadronicException aR)
210  {
212  aR.Report(ed);
213  ed << " hadronic initialisation fails" << G4endl;
214  G4Exception("G4HadronicProcess::BuildPhysicsTable", "had000",
215  FatalException,ed);
216  }
218 }
219 
222 {
223  //G4cout << "GetMeanFreePath " << aTrack.GetDefinition()->GetParticleName()
224  // << " Ekin= " << aTrack.GetKineticEnergy() << G4endl;
225  try
226  {
229  aTrack.GetMaterial());
230  }
231  catch(G4HadronicException aR)
232  {
234  aR.Report(ed);
235  DumpState(aTrack,"GetMeanFreePath",ed);
236  ed << " Cross section is not available" << G4endl;
237  G4Exception("G4HadronicProcess::GetMeanFreePath", "had002", FatalException,
238  ed);
239  }
240  G4double res = DBL_MAX;
241  if( theLastCrossSection > 0.0 ) { res = 1.0/theLastCrossSection; }
242  //G4cout << " xsection= " << res << G4endl;
243  return res;
244 }
245 
248 {
249  //G4cout << "PostStepDoIt " << aTrack.GetDefinition()->GetParticleName()
250  // << " Ekin= " << aTrack.GetKineticEnergy() << G4endl;
251  // if primary is not Alive then do nothing
253  theTotalResult->Initialize(aTrack);
255  if(aTrack.GetTrackStatus() != fAlive) { return theTotalResult; }
256 
257  // Find cross section at end of step and check if <= 0
258  //
259  const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
260  G4Material* aMaterial = aTrack.GetMaterial();
261 
262  G4Element* anElement = 0;
263  try
264  {
265  anElement = theCrossSectionDataStore->SampleZandA(aParticle,
266  aMaterial,
267  targetNucleus);
268  }
269  catch(G4HadronicException & aR)
270  {
272  aR.Report(ed);
273  DumpState(aTrack,"SampleZandA",ed);
274  ed << " PostStepDoIt failed on element selection" << G4endl;
275  G4Exception("G4HadronicProcess::PostStepDoIt", "had003", FatalException,
276  ed);
277  }
278 
279  // check only for charged particles
280  if(aParticle->GetDefinition()->GetPDGCharge() != 0.0) {
281  if (GetElementCrossSection(aParticle, anElement, aMaterial) <= 0.0) {
282  // No interaction
283  return theTotalResult;
284  }
285  }
286 
287  // Next check for illegal track status
288  //
289  if (aTrack.GetTrackStatus() != fAlive &&
290  aTrack.GetTrackStatus() != fSuspend) {
291  if (aTrack.GetTrackStatus() == fStopAndKill ||
293  aTrack.GetTrackStatus() == fPostponeToNextEvent) {
295  ed << "G4HadronicProcess: track in unusable state - "
296  << aTrack.GetTrackStatus() << G4endl;
297  ed << "G4HadronicProcess: returning unchanged track " << G4endl;
298  DumpState(aTrack,"PostStepDoIt",ed);
299  G4Exception("G4HadronicProcess::PostStepDoIt", "had004", JustWarning, ed);
300  }
301  // No warning for fStopButAlive which is a legal status here
302  return theTotalResult;
303  }
304 
305  // Initialize the hadronic projectile from the track
306  thePro.Initialise(aTrack);
307 
308  try
309  {
311  ChooseHadronicInteraction( thePro, targetNucleus, aMaterial, anElement );
312  }
313  catch(G4HadronicException & aE)
314  {
316  aE.Report(ed);
317  ed << "Target element "<<anElement->GetName()<<" Z= "
318  << targetNucleus.GetZ_asInt() << " A= "
320  DumpState(aTrack,"ChooseHadronicInteraction",ed);
321  ed << " No HadronicInteraction found out" << G4endl;
322  G4Exception("G4HadronicProcess::PostStepDoIt", "had005", FatalException,
323  ed);
324  }
325 
326  G4HadFinalState* result = 0;
327  G4int reentryCount = 0;
328 
329  do
330  {
331  try
332  {
333  // Save random engine if requested for debugging
335  CLHEP::HepRandom::saveEngineStatus(G4Hadronic_Random_File);
336  }
337  // Call the interaction
339  ++reentryCount;
340  }
341  catch(G4HadronicException aR)
342  {
344  aR.Report(ed);
345  ed << "Call for " << theInteraction->GetModelName() << G4endl;
346  ed << "Target element "<<anElement->GetName()<<" Z= "
348  << " A= " << targetNucleus.GetA_asInt() << G4endl;
349  DumpState(aTrack,"ApplyYourself",ed);
350  ed << " ApplyYourself failed" << G4endl;
351  G4Exception("G4HadronicProcess::PostStepDoIt", "had006", FatalException,
352  ed);
353  }
354 
355  // Check the result for catastrophic energy non-conservation
356  CheckResult(thePro, targetNucleus, result);
357 
358  if(reentryCount>100) {
360  ed << "Call for " << theInteraction->GetModelName() << G4endl;
361  ed << "Target element "<<anElement->GetName()<<" Z= "
363  << " A= " << targetNucleus.GetA_asInt() << G4endl;
364  DumpState(aTrack,"ApplyYourself",ed);
365  ed << " ApplyYourself does not completed after 100 attempts" << G4endl;
366  G4Exception("G4HadronicProcess::PostStepDoIt", "had006", FatalException,
367  ed);
368  }
369  }
370  while(!result); /* Loop checking, 30-Oct-2015, G.Folger */
371 
373 
375 
376  FillResult(result, aTrack);
377 
378  if (epReportLevel != 0) {
380  }
381  //G4cout << "PostStepDoIt done " << G4endl;
382  return theTotalResult;
383 }
384 
385 
386 void G4HadronicProcess::ProcessDescription(std::ostream& outFile) const
387 {
388  outFile << "The description for this process has not been written yet.\n";
389 }
390 
391 
393 {
394  G4double result = 0;
396  G4double biasedProbability = 1.-std::exp(-nLTraversed);
397  G4double realProbability = 1-std::exp(-nLTraversed/aScaleFactor);
398  result = (biasedProbability-realProbability)/biasedProbability;
399  return result;
400 }
401 
403 {
404  G4double result = 0;
406  result =
407  1./aScaleFactor*std::exp(-nLTraversed/aScaleFactor*(1-1./aScaleFactor));
408  return result;
409 }
410 
411 void
413 {
415 
416  G4double rotation = CLHEP::twopi*G4UniformRand();
417  G4ThreeVector it(0., 0., 1.);
418 
419  G4double efinal = aR->GetEnergyChange();
420  if(efinal < 0.0) { efinal = 0.0; }
421 
422  // check status of primary
423  if(aR->GetStatusChange() == stopAndKill) {
426 
427  // check its final energy
428  } else if(0.0 == efinal) {
431  ->GetAtRestProcessVector()->size() > 0)
434 
435  // primary is not killed apply rotation and Lorentz transformation
436  } else {
439  G4double newE = efinal + mass;
440  G4double newP = std::sqrt(efinal*(efinal + 2*mass));
441  G4ThreeVector newPV = newP*aR->GetMomentumChange();
442  G4LorentzVector newP4(newE, newPV);
443  newP4.rotate(rotation, it);
444  newP4 *= aR->GetTrafoToLab();
445  theTotalResult->ProposeMomentumDirection(newP4.vect().unit());
446  newE = newP4.e() - mass;
447  if(G4HadronicProcess_debug_flag && newE <= 0.0) {
449  DumpState(aT,"Primary has zero energy after interaction",ed);
450  G4Exception("G4HadronicProcess::FillResults", "had011", JustWarning, ed);
451  }
452  if(newE < 0.0) { newE = 0.0; }
453  theTotalResult->ProposeEnergy( newE );
454  }
455  //G4cout << "FillResult: Efinal= " << efinal << " status= "
456  // << theTotalResult->GetTrackStatus()
457  // << " fKill= " << fStopAndKill << G4endl;
458 
459  // check secondaries: apply rotation and Lorentz transformation
460  G4int nSec = aR->GetNumberOfSecondaries();
462  G4double weight = aT.GetWeight();
463 
464  if (nSec > 0) {
465  G4double time0 = aT.GetGlobalTime();
466  for (G4int i = 0; i < nSec; ++i) {
468  theM.rotate(rotation, it);
469  theM *= aR->GetTrafoToLab();
470  aR->GetSecondary(i)->GetParticle()->Set4Momentum(theM);
471 
472  // time of interaction starts from zero
473  G4double time = aR->GetSecondary(i)->GetTime();
474  if (time < 0.0) { time = 0.0; }
475 
476  // take into account global time
477  time += time0;
478 
479  G4Track* track = new G4Track(aR->GetSecondary(i)->GetParticle(),
480  time, aT.GetPosition());
482  G4double newWeight = weight*aR->GetSecondary(i)->GetWeight();
483  // G4cout << "#### ParticleDebug "
484  // <<GetProcessName()<<" "
485  //<<aR->GetSecondary(i)->GetParticle()->GetDefinition()->GetParticleName()<<" "
486  // <<aScaleFactor<<" "
487  // <<XBiasSurvivalProbability()<<" "
488  // <<XBiasSecondaryWeight()<<" "
489  // <<aT.GetWeight()<<" "
490  // <<aR->GetSecondary(i)->GetWeight()<<" "
491  // <<aR->GetSecondary(i)->GetParticle()->Get4Momentum()<<" "
492  // <<G4endl;
493  track->SetWeight(newWeight);
497  G4double e = track->GetKineticEnergy();
498  if (e <= 0.0) {
500  DumpState(aT,"Secondary has zero energy",ed);
501  ed << "Secondary " << track->GetDefinition()->GetParticleName()
502  << G4endl;
503  G4Exception("G4HadronicProcess::FillResults", "had011",
504  JustWarning,ed);
505  }
506  }
507  }
508  }
509 
510  aR->Clear();
511 }
512 
514 {
515  xBiasOn = true;
516  aScaleFactor = aScale;
517  G4String it = GetProcessName();
518  if ((it != "photonNuclear") &&
519  (it != "electronNuclear") &&
520  (it != "positronNuclear") ) {
522  G4Exception("G4HadronicProcess::BiasCrossSectionByFactor", "had009",
523  FatalException, ed,
524  "Cross-section biasing available only for gamma and electro nuclear reactions.");
525  }
526 
527  if (aScale < 100) {
529  G4Exception("G4HadronicProcess::BiasCrossSectionByFactor", "had010", JustWarning,ed,
530  "Cross-section bias readjusted to be above safe limit. New value is 100");
531  aScaleFactor = 100.;
532  }
533 }
534 
536  const G4Nucleus &aNucleus,
537  G4HadFinalState * result)
538 {
539  // check for catastrophic energy non-conservation
540  // to re-sample the interaction
541 
543  G4double nuclearMass(0);
544  if (theModel) {
545 
546  // Compute final-state total energy
547  G4double finalE(0.);
548  G4int nSec = result->GetNumberOfSecondaries();
549 
550  nuclearMass = G4NucleiProperties::GetNuclearMass(aNucleus.GetA_asInt(),
551  aNucleus.GetZ_asInt());
552  if (result->GetStatusChange() != stopAndKill) {
553  // Interaction didn't complete, returned "do nothing" state
554  // and reset nucleus or the primary survived the interaction
555  // (e.g. electro-nuclear ) => keep nucleus
556  finalE=result->GetLocalEnergyDeposit() +
557  aPro.GetDefinition()->GetPDGMass() + result->GetEnergyChange();
558  if( nSec == 0 ){
559  // Since there are no secondaries, there is no recoil nucleus.
560  // To check energy balance we must neglect the initial nucleus too.
561  nuclearMass=0.0;
562  }
563  }
564  for (G4int i = 0; i < nSec; i++) {
565  G4DynamicParticle *pdyn=result->GetSecondary(i)->GetParticle();
566  finalE += pdyn->GetTotalEnergy();
567  G4double mass_pdg=pdyn->GetDefinition()->GetPDGMass();
568  G4double mass_dyn=pdyn->GetMass();
569  if ( std::abs(mass_pdg - mass_dyn) > 0.1*mass_pdg + 1.*MeV){
570  result->Clear();
571  result = 0;
573  desc << "Warning: Secondary with off-shell dynamic mass detected: " << G4endl
574  << " " << pdyn->GetDefinition()->GetParticleName()
575  << ", PDG mass: " << mass_pdg << ", dynamic mass: "<< mass_dyn << G4endl
576  << (epReportLevel<0 ? "abort the event" : "re-sample the interaction") << G4endl
577  << " Process / Model: " << GetProcessName()<< " / "
578  << theModel->GetModelName() << G4endl
579  << " Primary: " << aPro.GetDefinition()->GetParticleName()
580  << " (" << aPro.GetDefinition()->GetPDGEncoding() << "), "
581  << " E= " << aPro.Get4Momentum().e()
582  << ", target nucleus (" << aNucleus.GetZ_asInt() << ", "
583  << aNucleus.GetA_asInt() << ")" << G4endl;
584  G4Exception("G4HadronicProcess:CheckResult()", "had012",
586  // must return here.....
587  return result;
588  }
589  }
590  G4double deltaE= nuclearMass + aPro.GetTotalEnergy() - finalE;
591 
592  std::pair<G4double, G4double> checkLevels =
593  theModel->GetFatalEnergyCheckLevels(); // (relative, absolute)
594  if (std::abs(deltaE) > checkLevels.second &&
595  std::abs(deltaE) > checkLevels.first*aPro.GetKineticEnergy()){
596  // do not delete result, this is a pointer to a data member;
597  result->Clear();
598  result = 0;
600  desc << "Warning: Bad energy non-conservation detected, will "
601  << (epReportLevel<0 ? "abort the event" : "re-sample the interaction") << G4endl
602  << " Process / Model: " << GetProcessName()<< " / "
603  << theModel->GetModelName() << G4endl
604  << " Primary: " << aPro.GetDefinition()->GetParticleName()
605  << " (" << aPro.GetDefinition()->GetPDGEncoding() << "), "
606  << " E= " << aPro.Get4Momentum().e()
607  << ", target nucleus (" << aNucleus.GetZ_asInt() << ", "
608  << aNucleus.GetA_asInt() << ")" << G4endl
609  << " E(initial - final) = " << deltaE << " MeV." << G4endl;
610  G4Exception("G4HadronicProcess:CheckResult()", "had012",
612  }
613  }
614  return result;
615 }
616 
617 void
619  const G4Nucleus& aNucleus)
620 {
621  G4int target_A=aNucleus.GetA_asInt();
622  G4int target_Z=aNucleus.GetZ_asInt();
623  G4double targetMass = G4NucleiProperties::GetNuclearMass(target_A,target_Z);
624  G4LorentzVector target4mom(0, 0, 0, targetMass);
625 
626  G4LorentzVector projectile4mom = aTrack.GetDynamicParticle()->Get4Momentum();
627  G4int track_A = aTrack.GetDefinition()->GetBaryonNumber();
628  G4int track_Z = G4lrint(aTrack.GetDefinition()->GetPDGCharge());
629 
630  G4int initial_A = target_A + track_A;
631  G4int initial_Z = target_Z + track_Z;
632 
633  G4LorentzVector initial4mom = projectile4mom + target4mom;
634 
635  // Compute final-state momentum for scattering and "do nothing" results
636  G4LorentzVector final4mom;
637  G4int final_A(0), final_Z(0);
638 
640  if (theTotalResult->GetTrackStatus() != fStopAndKill) { // If it is Alive
641  // Either interaction didn't complete, returned "do nothing" state
642  // or the primary survived the interaction (e.g. electro-nucleus )
643  G4Track temp(aTrack);
644 
645  // Use the final energy / momentum
648 
649  if( nSec == 0 ){
650  // Interaction didn't complete, returned "do nothing" state
651  // - or suppressed recoil (e.g. Neutron elastic )
652  final4mom = temp.GetDynamicParticle()->Get4Momentum() + target4mom;
653  final_A = initial_A;
654  final_Z = initial_Z;
655  }else{
656  // The primary remains in final state (e.g. electro-nucleus )
657  final4mom = temp.GetDynamicParticle()->Get4Momentum();
658  final_A = track_A;
659  final_Z = track_Z;
660  // Expect that the target nucleus will have interacted,
661  // and its products, including recoil, will be included in secondaries.
662  }
663  }
664  if( nSec > 0 ) {
665  G4Track* sec;
666 
667  for (G4int i = 0; i < nSec; i++) {
668  sec = theTotalResult->GetSecondary(i);
669  final4mom += sec->GetDynamicParticle()->Get4Momentum();
670  final_A += sec->GetDefinition()->GetBaryonNumber();
671  final_Z += G4lrint(sec->GetDefinition()->GetPDGCharge());
672  }
673  }
674 
675  // Get level-checking information (used to cut-off relative checks)
676  G4String processName = GetProcessName();
678  G4String modelName("none");
679  if (theModel) modelName = theModel->GetModelName();
680  std::pair<G4double, G4double> checkLevels = epCheckLevels;
681  if (!levelsSetByProcess) {
682  if (theModel) checkLevels = theModel->GetEnergyMomentumCheckLevels();
683  checkLevels.first= std::min(checkLevels.first, epCheckLevels.first);
684  checkLevels.second=std::min(checkLevels.second, epCheckLevels.second);
685  }
686 
687  // Compute absolute total-energy difference, and relative kinetic-energy
688  G4bool checkRelative = (aTrack.GetKineticEnergy() > checkLevels.second);
689 
690  G4LorentzVector diff = initial4mom - final4mom;
691  G4double absolute = diff.e();
692  G4double relative = checkRelative ? absolute/aTrack.GetKineticEnergy() : 0.;
693 
694  G4double absolute_mom = diff.vect().mag();
695  G4double relative_mom = checkRelative ? absolute_mom/aTrack.GetMomentum().mag() : 0.;
696 
697  // Evaluate relative and absolute conservation
698  G4bool relPass = true;
699  G4String relResult = "pass";
700  if ( std::abs(relative) > checkLevels.first
701  || std::abs(relative_mom) > checkLevels.first) {
702  relPass = false;
703  relResult = checkRelative ? "fail" : "N/A";
704  }
705 
706  G4bool absPass = true;
707  G4String absResult = "pass";
708  if ( std::abs(absolute) > checkLevels.second
709  || std::abs(absolute_mom) > checkLevels.second ) {
710  absPass = false ;
711  absResult = "fail";
712  }
713 
714  G4bool chargePass = true;
715  G4String chargeResult = "pass";
716  if ( (initial_A-final_A)!=0
717  || (initial_Z-final_Z)!=0 ) {
718  chargePass = checkLevels.second < DBL_MAX ? false : true;
719  chargeResult = "fail";
720  }
721 
722  G4bool conservationPass = (relPass || absPass) && chargePass;
723 
724  std::stringstream Myout;
725  G4bool Myout_notempty(false);
726  // Options for level of reporting detail:
727  // 0. off
728  // 1. report only when E/p not conserved
729  // 2. report regardless of E/p conservation
730  // 3. report only when E/p not conserved, with model names, process names, and limits
731  // 4. report regardless of E/p conservation, with model names, process names, and limits
732  // negative -1.., as above, but send output to stderr
733 
734  if( std::abs(epReportLevel) == 4
735  || ( std::abs(epReportLevel) == 3 && ! conservationPass ) ){
736  Myout << " Process: " << processName << " , Model: " << modelName << G4endl;
737  Myout << " Primary: " << aTrack.GetParticleDefinition()->GetParticleName()
738  << " (" << aTrack.GetParticleDefinition()->GetPDGEncoding() << "),"
739  << " E= " << aTrack.GetDynamicParticle()->Get4Momentum().e()
740  << ", target nucleus (" << aNucleus.GetZ_asInt() << ","
741  << aNucleus.GetA_asInt() << ")" << G4endl;
742  Myout_notempty=true;
743  }
744  if ( std::abs(epReportLevel) == 4
745  || std::abs(epReportLevel) == 2
746  || ! conservationPass ){
747 
748  Myout << " "<< relResult <<" relative, limit " << checkLevels.first << ", values E/T(0) = "
749  << relative << " p/p(0)= " << relative_mom << G4endl;
750  Myout << " "<< absResult << " absolute, limit (MeV) " << checkLevels.second/MeV << ", values E / p (MeV) = "
751  << absolute/MeV << " / " << absolute_mom/MeV << " 3mom: " << (diff.vect())*1./MeV << G4endl;
752  Myout << " "<< chargeResult << " charge/baryon number balance " << (initial_Z-final_Z) << " / " << (initial_A-final_A) << " "<< G4endl;
753  Myout_notempty=true;
754 
755  }
756  Myout.flush();
757  if ( Myout_notempty ) {
758  if (epReportLevel > 0) G4cout << Myout.str()<< G4endl;
759  else if (epReportLevel < 0) G4cerr << Myout.str()<< G4endl;
760  }
761 }
762 
763 
765  const G4String& method,
767 {
768  ed << "Unrecoverable error in the method " << method << " of "
769  << GetProcessName() << G4endl;
770  ed << "TrackID= "<< aTrack.GetTrackID() << " ParentID= "
771  << aTrack.GetParentID()
772  << " " << aTrack.GetParticleDefinition()->GetParticleName()
773  << G4endl;
774  ed << "Ekin(GeV)= " << aTrack.GetKineticEnergy()/CLHEP::GeV
775  << "; direction= " << aTrack.GetMomentumDirection() << G4endl;
776  ed << "Position(mm)= " << aTrack.GetPosition()/CLHEP::mm << ";";
777 
778  if (aTrack.GetMaterial()) {
779  ed << " material " << aTrack.GetMaterial()->GetName();
780  }
781  ed << G4endl;
782 
783  if (aTrack.GetVolume()) {
784  ed << "PhysicalVolume <" << aTrack.GetVolume()->GetName()
785  << ">" << G4endl;
786  }
787 }
G4ParticleDefinition * GetDefinition() const
G4int GetA_asInt() const
Definition: G4Nucleus.hh:109
G4int GetParentID() const
static const double MeV
Definition: G4SIunits.hh:211
static G4double GetNuclearMass(const G4double A, const G4double Z)
G4int GetNumberOfSecondaries() const
void RegisterMe(G4HadronicInteraction *a)
G4Track * GetSecondary(G4int anIndex) const
void RegisterInteraction(G4HadronicProcess *, G4HadronicInteraction *)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4HadSecondary * GetSecondary(size_t i)
CLHEP::Hep3Vector G4ThreeVector
G4double GetTotalEnergy() const
G4LorentzRotation & GetTrafoToLab()
void BiasCrossSectionByFactor(G4double aScale)
static G4HadronicProcessStore * Instance()
G4Material * FindOrBuildSimpleMaterial(G4int Z, G4bool warning=false)
const G4DynamicParticle * GetDynamicParticle() const
G4int first(char) const
virtual const std::pair< G4double, G4double > GetFatalEnergyCheckLevels() const
const G4String & GetName() const
Definition: G4Material.hh:178
G4HadronicInteraction * theInteraction
const G4ThreeVector & GetMomentumChange() const
const G4ThreeVector & GetPosition() const
G4double GetZ() const
Definition: G4Element.hh:131
G4TrackStatus GetTrackStatus() const
G4EnergyRangeManager theEnergyRangeManager
virtual void PreparePhysicsTable(const G4ParticleDefinition &)
void SetTouchableHandle(const G4TouchableHandle &apValue)
G4HadProjectile thePro
G4double GetEnergyChange() const
G4ParticleDefinition * GetDefinition() const
G4double a
Definition: TRTMaterials.hh:39
const G4ThreeVector * GetMomentumDirection() const
void CheckEnergyMomentumConservation(const G4Track &, const G4Nucleus &)
const G4String & GetModelName() const
G4double GetTime() const
void ClearNumberOfInteractionLengthLeft()
Definition: G4VProcess.hh:447
G4ProcessManager * GetProcessManager() const
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
G4HadronicProcessType
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
const G4String & GetParticleName() const
std::pair< G4double, G4double > epCheckLevels
G4int GetCreatorModelType() const
void SetWeight(G4double aValue)
void ProposeLocalEnergyDeposit(G4double anEnergyPart)
void GetEnergyMomentumCheckEnvvars()
void SetCreatorModelIndex(G4int idx)
void RegisterMe(G4HadronicInteraction *a)
void ProposeWeight(G4double finalWeight)
virtual void BuildPhysicsTable(const G4ParticleDefinition &)
const G4LorentzRotation & GetTrafoToLab() const
void SetSecondaryWeightByProcess(G4bool)
G4CrossSectionDataStore * theCrossSectionDataStore
void DumpState(const G4Track &, const G4String &, G4ExceptionDescription &)
void SetTrafoToLab(const G4LorentzRotation &aT)
G4ProcessVector * GetAtRestProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
G4double GetKineticEnergy() const
void FillResult(G4HadFinalState *aR, const G4Track &aT)
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
G4double GetTotalNumberOfInteractionLengthTraversed() const
Definition: G4VProcess.hh:458
G4ParticleChange * theTotalResult
const G4ParticleDefinition * GetDefinition() const
void Register(G4HadronicProcess *)
const G4String & GetName() const
G4double GetMeanFreePath(const G4Track &aTrack, G4double, G4ForceCondition *)
G4double GetMass() const
G4double XBiasSurvivalProbability()
bool G4bool
Definition: G4Types.hh:79
virtual std::pair< G4double, G4double > GetEnergyMomentumCheckLevels() const
G4double GetKineticEnergy() const
static const double twopi
Definition: G4SIunits.hh:75
G4double theInitialNumberOfInteractionLength
G4double GetCrossSection(const G4DynamicParticle *, const G4Material *)
const G4ParticleDefinition * GetParticleDefinition() const
void SetProcessSubType(G4int)
Definition: G4VProcess.hh:432
static const double GeV
Definition: G4SIunits.hh:214
Definition: G4Step.hh:76
G4int GetTrackID() const
virtual void ProcessDescription(std::ostream &outFile) const
G4double GetGlobalTime() const
static const char * G4Hadronic_Random_File
void RegisterParticle(G4HadronicProcess *, const G4ParticleDefinition *)
G4HadronicProcessStore * theProcessStore
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
const G4LorentzVector & Get4Momentum() const
void DeRegister(G4HadronicProcess *)
const G4TouchableHandle & GetTouchableHandle() const
G4LorentzVector Get4Momentum() const
G4Material * GetMaterial() const
void Initialise(const G4Track &aT)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4Material * InitialiseMaterial(G4int Z)
void Set4Momentum(const G4LorentzVector &momentum)
G4int size() const
void BuildPhysicsTable(const G4ParticleDefinition &)
G4ThreeVector GetMomentum() const
virtual void Initialize(const G4Track &)
G4int G4Mutex
Definition: G4Threading.hh:173
G4double GetElementCrossSection(const G4DynamicParticle *part, const G4Element *elm, const G4Material *mat=0)
const G4ThreeVector & GetMomentumDirection() const
G4HadronicInteraction * GetHadronicInteraction() const
G4double GetPDGMass() const
G4double XBiasSecondaryWeight()
int G4lrint(double ad)
Definition: templates.hh:163
void SetNumberOfSecondaries(G4int totSecondaries)
G4DynamicParticle * GetParticle()
void BuildPhysicsTable(const G4ParticleDefinition &)
const G4double x[NPOINTSGL]
G4int GetZ_asInt() const
Definition: G4Nucleus.hh:115
void ProposeEnergy(G4double finalEnergy)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4VPhysicalVolume * GetVolume() const
void AddSecondary(G4Track *aSecondary)
G4double GetWeight() const
G4HadronicInteraction * ChooseHadronicInteraction(const G4HadProjectile &aHadProjectile, G4Nucleus &aTargetNucleus, G4Material *aMaterial, G4Element *anElement)
G4double GetEnergy() const
#define G4endl
Definition: G4ios.hh:61
G4HadronicProcess(const G4String &processName="Hadronic", G4ProcessType procType=fHadronic)
G4TrackStatus GetTrackStatus() const
void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz)
G4Element * SampleZandA(const G4DynamicParticle *, const G4Material *, G4Nucleus &target)
void SetKineticEnergy(const G4double aValue)
double G4double
Definition: G4Types.hh:76
void ProposeTrackStatus(G4TrackStatus status)
const G4String & GetName() const
Definition: G4Element.hh:127
virtual G4VParticleChange * PostStepDoIt(const G4Track &aTrack, const G4Step &aStep)
G4ForceCondition
G4double GetPDGCharge() const
#define DBL_MAX
Definition: templates.hh:83
static const double mm
Definition: G4SIunits.hh:114
void Report(std::ostream &aS)
G4int GetNumberOfSecondaries() const
virtual G4HadFinalState * ApplyYourself(const G4HadProjectile &aTrack, G4Nucleus &targetNucleus)=0
G4double GetLocalEnergyDeposit() const
void SetMomentumDirection(const G4ThreeVector &aValue)
G4HadFinalState * CheckResult(const G4HadProjectile &thePro, const G4Nucleus &targetNucleus, G4HadFinalState *result)
G4GLOB_DLL std::ostream G4cerr
G4HadFinalStateStatus GetStatusChange() const
void PrintInfo(const G4ParticleDefinition *)
G4double GetTotalEnergy() const
CLHEP::HepLorentzVector G4LorentzVector
G4ProcessType
G4double GetWeight() const