Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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//
27// -------------------------------------------------------------------
28//
29// GEANT4 Class source file
30//
31// G4HadronicProcess
32//
33// original by H.P.Wellisch
34// J.L. Chuma, TRIUMF, 10-Mar-1997
35//
36// Modifications:
37// 05-Jul-2010 V.Ivanchenko cleanup commented lines
38// 20-Jul-2011 M.Kelsey -- null-pointer checks in DumpState()
39// 24-Sep-2011 M.Kelsey -- Use envvar G4HADRONIC_RANDOM_FILE to save random
40// engine state before each model call
41// 18-Oct-2011 M.Kelsey -- Handle final-state cases in conservation checks.
42// 14-Mar-2012 G.Folger -- enhance checks for conservation of energy, etc.
43// 28-Jul-2012 M.Maire -- add function GetTargetDefinition()
44// 14-Sep-2012 Inherit from RestDiscrete, use subtype code (now in ctor) to
45// configure base-class
46// 28-Sep-2012 Restore inheritance from G4VDiscreteProcess, remove enable-flag
47// changing, remove warning message from original ctor.
48// 21-Aug-2019 V.Ivanchenko leave try/catch only for ApplyYourself(..), cleanup
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"
60#include "G4ProcessVector.hh"
61#include "G4ProcessManager.hh"
62#include "G4NucleiProperties.hh"
63
68
69#include "G4NistManager.hh"
71#include "G4HadXSHelper.hh"
72#include "G4Threading.hh"
73#include "G4Exp.hh"
74
75#include <typeinfo>
76#include <sstream>
77#include <iostream>
78
79namespace
80{
81 constexpr G4double lambdaFactor = 0.8;
82 constexpr G4double invLambdaFactor = 1.0/lambdaFactor;
83}
84
85//////////////////////////////////////////////////////////////////
86
88 G4ProcessType procType)
89 : G4VDiscreteProcess(processName, procType)
90{
91 SetProcessSubType(fHadronInelastic); // Default unless subclass changes
92 InitialiseLocal();
93}
94
96 G4HadronicProcessType aHadSubType)
97 : G4VDiscreteProcess(processName, fHadronic)
98{
99 SetProcessSubType(aHadSubType);
100 InitialiseLocal();
101}
102
104{
105 theProcessStore->DeRegister(this);
106 delete theTotalResult;
108 if(isMaster) {
109 if (fXSpeaks != nullptr) {
110 for (auto const& e : *fXSpeaks ) {
111 delete e;
112 }
113 }
114 delete fXSpeaks;
115 delete theEnergyOfCrossSectionMax;
116 }
117}
118
119void G4HadronicProcess::InitialiseLocal() {
123 theProcessStore = G4HadronicProcessStore::Instance();
124 theProcessStore->Register(this);
125 minKinEnergy = 1*CLHEP::MeV;
126
129 epCheckLevels.first = param->GetEPRelativeLevel();
130 epCheckLevels.second = param->GetEPAbsoluteLevel();
131
132 unitVector.set(0.0, 0.0, 0.1);
133 if(G4Threading::IsWorkerThread()) { isMaster = false; }
134}
135
137{
138 if(nullptr == a) { return; }
139 theEnergyRangeManager.RegisterMe( a );
141}
142
145 const G4Element * elm,
146 const G4Material* mat)
147{
148 if(nullptr == mat)
149 {
150 static const G4int nmax = 5;
151 if(nMatWarn < nmax) {
152 ++nMatWarn;
154 ed << "Cannot compute Element x-section for " << GetProcessName()
155 << " because no material defined \n"
156 << " Please, specify material pointer or define simple material"
157 << " for Z= " << elm->GetZasInt();
158 G4Exception("G4HadronicProcess::GetElementCrossSection", "had066",
159 JustWarning, ed);
160 }
161 }
162 return theCrossSectionDataStore->GetCrossSection(dp, elm, mat);
163}
164
166{
167 if(nullptr == firstParticle) { firstParticle = &p; }
168 theProcessStore->RegisterParticle(this, &p);
169}
170
172{
173 if(firstParticle != &p) { return; }
174
175 theCrossSectionDataStore->BuildPhysicsTable(p);
176 theEnergyRangeManager.BuildPhysicsTable(p);
178
179 G4int subtype = GetProcessSubType();
180 if(useIntegralXS) {
181 if(subtype == fHadronInelastic) {
182 useIntegralXS = param->EnableIntegralInelasticXS();
183 } else if(subtype == fHadronElastic) {
184 useIntegralXS = param->EnableIntegralElasticXS();
185 }
186 }
188
189 if(nullptr == masterProcess) {
190 masterProcess = dynamic_cast<const G4HadronicProcess*>(GetMasterProcess());
191 }
192
193 // check particle for integral method
194 if(isMaster || nullptr == masterProcess) {
195 G4double charge = p.GetPDGCharge()/eplus;
196
197 // select cross section shape
198 if(charge != 0.0 && useIntegralXS) {
199 G4double tmax = param->GetMaxEnergy();
200 currentParticle = firstParticle;
201 // initialisation in the master thread
202 G4int pdg = p.GetPDGEncoding();
203 if (std::abs(pdg) == 211) {
205 } else if (pdg == 321) {
207 } else if (pdg == -321) {
209 } else if (pdg == 2212) {
211 } else if (pdg == -2212 || pdg == -1000010020 || pdg == -1000010030 ||
212 pdg == -1000020030 || pdg == -1000020040) {
214 } else if (charge > 0.0 || pdg == 11 || pdg == 13) {
216 }
217
218 delete theEnergyOfCrossSectionMax;
219 theEnergyOfCrossSectionMax = nullptr;
220 if(fXSType == fHadTwoPeaks) {
221 if (fXSpeaks != nullptr) {
222 for (auto const& e : *fXSpeaks ) {
223 delete e;
224 }
225 }
226 delete fXSpeaks;
227 fXSpeaks =
228 G4HadXSHelper::FillPeaksStructure(this, &p, minKinEnergy, tmax);
229 if(nullptr == fXSpeaks) {
231 }
232 }
233 if(fXSType == fHadOnePeak) {
234 theEnergyOfCrossSectionMax =
235 G4HadXSHelper::FindCrossSectionMax(this, &p, minKinEnergy, tmax);
236 if(nullptr == theEnergyOfCrossSectionMax) {
238 }
239 }
240 }
241 } else {
242 // initialisation in worker threads
243 fXSType = masterProcess->CrossSectionType();
244 fXSpeaks = masterProcess->TwoPeaksXS();
245 theEnergyOfCrossSectionMax = masterProcess->EnergyOfCrossSectionMax();
246 }
247 if(isMaster && 1 < param->GetVerboseLevel()) {
248 G4cout << "G4HadronicProcess::BuildPhysicsTable: for "
249 << GetProcessName() << " and " << p.GetParticleName()
250 << " typeXS=" << fXSType << G4endl;
251 }
253}
254
256{
257 currentMat = nullptr;
258 currentParticle = track->GetDefinition();
259 fDynParticle = track->GetDynamicParticle();
261}
262
264 const G4Track& track,
265 G4double previousStepSize,
267{
269
270 const G4Material* mat = track.GetMaterial();
271 if(mat != currentMat) {
272 currentMat = mat;
274 matIdx = (G4int)track.GetMaterial()->GetIndex();
275 }
276 UpdateCrossSectionAndMFP(track.GetKineticEnergy());
277
278 // zero cross section
279 if(theLastCrossSection <= 0.0) {
282 return DBL_MAX;
283 }
284
285 // non-zero cross section
289 } else {
291 previousStepSize/currentInteractionLength;
294 }
297}
298
300 const G4Track &aTrack, G4double,
302{
304 ->ComputeCrossSection(aTrack.GetDynamicParticle(),aTrack.GetMaterial());
305 return (xs > 0.0) ? 1.0/xs : DBL_MAX;
306}
307
310{
312
313 //G4cout << "PostStepDoIt " << aTrack.GetDefinition()->GetParticleName()
314 // << " Ekin= " << aTrack.GetKineticEnergy() << G4endl;
315 // if primary is not Alive then do nothing
316 theTotalResult->Clear();
317 theTotalResult->Initialize(aTrack);
318 fWeight = aTrack.GetWeight();
319 theTotalResult->ProposeWeight(fWeight);
320 if(aTrack.GetTrackStatus() != fAlive) { return theTotalResult; }
321
322 // Find cross section at end of step and check if <= 0
323 //
324 const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle();
325 const G4Material* aMaterial = aTrack.GetMaterial();
326
327 // check only for charged particles
328 if(fXSType != fHadNoIntegral) {
331 theCrossSectionDataStore->ComputeCrossSection(aParticle,aMaterial);
332 //G4cout << "xs=" << xs << " xs0=" << theLastCrossSection
333 // << " " << aMaterial->GetName() << G4endl;
335 // No interaction
336 return theTotalResult;
337 }
338 }
339
340 const G4Element* anElement =
341 theCrossSectionDataStore->SampleZandA(aParticle,aMaterial,targetNucleus);
342
343 // Next check for illegal track status
344 //
345 if (aTrack.GetTrackStatus() != fAlive &&
346 aTrack.GetTrackStatus() != fSuspend) {
347 if (aTrack.GetTrackStatus() == fStopAndKill ||
351 ed << "G4HadronicProcess: track in unusable state - "
352 << aTrack.GetTrackStatus() << G4endl;
353 ed << "G4HadronicProcess: returning unchanged track " << G4endl;
354 DumpState(aTrack,"PostStepDoIt",ed);
355 G4Exception("G4HadronicProcess::PostStepDoIt", "had004", JustWarning, ed);
356 }
357 // No warning for fStopButAlive which is a legal status here
358 return theTotalResult;
359 }
360
361 // Initialize the hadronic projectile from the track
362 thePro.Initialise(aTrack);
363
364 theInteraction = ChooseHadronicInteraction(thePro, targetNucleus,
365 aMaterial, anElement);
366 if(nullptr == theInteraction) {
368 ed << "Target element "<<anElement->GetName()<<" Z= "
369 << targetNucleus.GetZ_asInt() << " A= "
370 << targetNucleus.GetA_asInt() << G4endl;
371 DumpState(aTrack,"ChooseHadronicInteraction",ed);
372 ed << " No HadronicInteraction found out" << G4endl;
373 G4Exception("G4HadronicProcess::PostStepDoIt", "had005",
374 FatalException, ed);
375 return theTotalResult;
376 }
377
378 G4HadFinalState* result = nullptr;
379 G4int reentryCount = 0;
380 /*
381 G4cout << "### " << aParticle->GetDefinition()->GetParticleName()
382 << " Ekin(MeV)= " << aParticle->GetKineticEnergy()
383 << " Z= " << targetNucleus.GetZ_asInt()
384 << " A= " << targetNucleus.GetA_asInt()
385 << " by " << theInteraction->GetModelName()
386 << G4endl;
387 */
388 do
389 {
390 try
391 {
392 // Call the interaction
393 result = theInteraction->ApplyYourself( thePro, targetNucleus);
394 ++reentryCount;
395 }
396 catch(G4HadronicException & aR)
397 {
399 aR.Report(ed);
400 ed << "Call for " << theInteraction->GetModelName() << G4endl;
401 ed << "Target element "<<anElement->GetName()<<" Z= "
402 << targetNucleus.GetZ_asInt()
403 << " A= " << targetNucleus.GetA_asInt() << G4endl;
404 DumpState(aTrack,"ApplyYourself",ed);
405 ed << " ApplyYourself failed" << G4endl;
406 G4Exception("G4HadronicProcess::PostStepDoIt", "had006", FatalException,
407 ed);
408 }
409
410 // Check the result for catastrophic energy non-conservation
411 result = CheckResult(thePro, targetNucleus, result);
412
413 if(reentryCount>100) {
415 ed << "Call for " << theInteraction->GetModelName() << G4endl;
416 ed << "Target element "<<anElement->GetName()<<" Z= "
417 << targetNucleus.GetZ_asInt()
418 << " A= " << targetNucleus.GetA_asInt() << G4endl;
419 DumpState(aTrack,"ApplyYourself",ed);
420 ed << " ApplyYourself does not completed after 100 attempts" << G4endl;
421 G4Exception("G4HadronicProcess::PostStepDoIt", "had006", FatalException,
422 ed);
423 }
424 }
425 while(!result); /* Loop checking, 30-Oct-2015, G.Folger */
426
427 // Check whether kaon0 or anti_kaon0 are present between the secondaries:
428 // if this is the case, transform them into either kaon0S or kaon0L,
429 // with equal, 50% probability, keeping their dynamical masses (and
430 // the other kinematical properties).
431 // When this happens - very rarely - a "JustWarning" exception is thrown.
432 // Because Fluka-Cern produces kaon0 and anti_kaon0, we reduce the number
433 // of warnings to max 1 per thread.
434 G4int nSec = (G4int)result->GetNumberOfSecondaries();
435 if ( nSec > 0 ) {
436 for ( G4int i = 0; i < nSec; ++i ) {
437 auto dynamicParticle = result->GetSecondary(i)->GetParticle();
438 auto part = dynamicParticle->GetParticleDefinition();
439 if ( part == G4KaonZero::Definition() ||
440 part == G4AntiKaonZero::Definition() ) {
441 G4ParticleDefinition* newPart;
442 if ( G4UniformRand() > 0.5 ) { newPart = G4KaonZeroShort::Definition(); }
443 else { newPart = G4KaonZeroLong::Definition(); }
444 dynamicParticle->SetDefinition( newPart );
445 }
446 }
447 }
448
449 result->SetTrafoToLab(thePro.GetTrafoToLab());
450 FillResult(result, aTrack);
451
452 if (epReportLevel != 0) {
453 CheckEnergyMomentumConservation(aTrack, targetNucleus);
454 }
455 //G4cout << "PostStepDoIt done nICelectrons= " << nICelectrons << G4endl;
456 return theTotalResult;
457}
458
459void G4HadronicProcess::ProcessDescription(std::ostream& outFile) const
460{
461 outFile << "The description for this process has not been written yet.\n";
462}
463
464G4double G4HadronicProcess::XBiasSurvivalProbability()
465{
467 G4double biasedProbability = 1.-G4Exp(-nLTraversed);
468 G4double realProbability = 1-G4Exp(-nLTraversed/aScaleFactor);
469 G4double result = (biasedProbability-realProbability)/biasedProbability;
470 return result;
471}
472
473G4double G4HadronicProcess::XBiasSecondaryWeight()
474{
476 G4double result =
477 1./aScaleFactor*G4Exp(-nLTraversed/aScaleFactor*(1-1./aScaleFactor));
478 return result;
479}
480
481void
483{
484 theTotalResult->ProposeLocalEnergyDeposit(aR->GetLocalEnergyDeposit());
485 const G4ThreeVector& dir = aT.GetMomentumDirection();
486
487 G4double efinal = std::max(aR->GetEnergyChange(), 0.0);
488
489 // check status of primary
490 if(aR->GetStatusChange() == stopAndKill) {
491 theTotalResult->ProposeTrackStatus(fStopAndKill);
492 theTotalResult->ProposeEnergy( 0.0 );
493
494 // check its final energy
495 } else if(0.0 == efinal) {
496 theTotalResult->ProposeEnergy( 0.0 );
498 ->GetAtRestProcessVector()->size() > 0)
499 { theTotalResult->ProposeTrackStatus(fStopButAlive); }
500 else { theTotalResult->ProposeTrackStatus(fStopAndKill); }
501
502 // primary is not killed apply rotation and Lorentz transformation
503 } else {
504 theTotalResult->ProposeTrackStatus(fAlive);
505 G4ThreeVector newDir = aR->GetMomentumChange();
506 newDir.rotateUz(dir);
507 theTotalResult->ProposeMomentumDirection(newDir);
508 theTotalResult->ProposeEnergy(efinal);
509 }
510 //G4cout << "FillResult: Efinal= " << efinal << " status= "
511 // << theTotalResult->GetTrackStatus()
512 // << " fKill= " << fStopAndKill << G4endl;
513
514 // check secondaries
515 nICelectrons = 0;
516 G4int nSec = (G4int)aR->GetNumberOfSecondaries();
517 theTotalResult->SetNumberOfSecondaries(nSec);
518 G4double time0 = aT.GetGlobalTime();
519
520 for (G4int i = 0; i < nSec; ++i) {
521 G4DynamicParticle* dynParticle = aR->GetSecondary(i)->GetParticle();
522
523 // apply rotation
524 G4ThreeVector newDir = dynParticle->GetMomentumDirection();
525 newDir.rotateUz(dir);
526 dynParticle->SetMomentumDirection(newDir);
527
528 // check if secondary is on the mass shell
529 const G4ParticleDefinition* part = dynParticle->GetDefinition();
530 G4double mass = part->GetPDGMass();
531 G4double dmass= dynParticle->GetMass();
532 const G4double delta_mass_lim = 1.0*CLHEP::keV;
533 const G4double delta_ekin = 0.001*CLHEP::eV;
534 if(std::abs(dmass - mass) > delta_mass_lim) {
535 G4double e =
536 std::max(dynParticle->GetKineticEnergy() + dmass - mass, delta_ekin);
537 if(verboseLevel > 1) {
539 ed << "TrackID= "<< aT.GetTrackID()
540 << " " << aT.GetParticleDefinition()->GetParticleName()
541 << " Target Z= " << targetNucleus.GetZ_asInt() << " A= "
542 << targetNucleus.GetA_asInt()
543 << " Ekin(GeV)= " << aT.GetKineticEnergy()/CLHEP::GeV
544 << "\n Secondary is out of mass shell: " << part->GetParticleName()
545 << " EkinNew(MeV)= " << e
546 << " DeltaMass(MeV)= " << dmass - mass << G4endl;
547 G4Exception("G4HadronicProcess::FillResults", "had012", JustWarning, ed);
548 }
549 dynParticle->SetKineticEnergy(e);
550 dynParticle->SetMass(mass);
551 }
552 G4int idModel = aR->GetSecondary(i)->GetCreatorModelID();
553 if(part->GetPDGEncoding() == 11) { ++nICelectrons; }
554
555 // time of interaction starts from zero + global time
556 G4double time = std::max(aR->GetSecondary(i)->GetTime(), 0.0) + time0;
557
558 G4Track* track = new G4Track(dynParticle, time, aT.GetPosition());
559 track->SetCreatorModelID(idModel);
562 G4double newWeight = fWeight*aR->GetSecondary(i)->GetWeight();
563 track->SetWeight(newWeight);
565 theTotalResult->AddSecondary(track);
566 }
567 aR->Clear();
568 // G4cout << "FillResults done nICe= " << nICelectrons << G4endl;
569}
570
575
577{
578 if (aScale <= 0.0) {
580 ed << " Wrong biasing factor " << aScale << " for " << GetProcessName();
581 G4Exception("G4HadronicProcess::BiasCrossSectionByFactor", "had010",
582 JustWarning, ed, "Cross-section bias is ignored");
583 } else {
584 aScaleFactor = aScale;
585 }
586}
587
589 const G4Nucleus &aNucleus,
590 G4HadFinalState * result)
591{
592 // check for catastrophic energy non-conservation
593 // to re-sample the interaction
595 G4double nuclearMass(0);
596 if (nullptr != theModel) {
597
598 // Compute final-state total energy
599 G4double finalE(0.);
600 G4int nSec = (G4int)result->GetNumberOfSecondaries();
601
602 nuclearMass = G4NucleiProperties::GetNuclearMass(aNucleus.GetA_asInt(),
603 aNucleus.GetZ_asInt());
604 if (result->GetStatusChange() != stopAndKill) {
605 // Interaction didn't complete, returned "do nothing" state
606 // and reset nucleus or the primary survived the interaction
607 // (e.g. electro-nuclear ) => keep nucleus
608 finalE=result->GetLocalEnergyDeposit() +
609 aPro.GetDefinition()->GetPDGMass() + result->GetEnergyChange();
610 if( nSec == 0 ){
611 // Since there are no secondaries, there is no recoil nucleus.
612 // To check energy balance we must neglect the initial nucleus too.
613 nuclearMass=0.0;
614 }
615 }
616 for (G4int i = 0; i < nSec; ++i) {
617 G4DynamicParticle *pdyn=result->GetSecondary(i)->GetParticle();
618 finalE += pdyn->GetTotalEnergy();
619 G4double mass_pdg=pdyn->GetDefinition()->GetPDGMass();
620 G4double mass_dyn=pdyn->GetMass();
621 if ( std::abs(mass_pdg - mass_dyn) > 0.1*mass_pdg + 1.*MeV ) {
622 // If it is shortlived, then a difference less than 3 times the width is acceptable
623 if ( pdyn->GetDefinition()->IsShortLived() &&
624 std::abs(mass_pdg - mass_dyn) < 3.0*pdyn->GetDefinition()->GetPDGWidth() ) {
625 continue;
626 }
627 result->Clear();
628 result = nullptr;
630 desc << "Warning: Secondary with off-shell dynamic mass detected: "
631 << G4endl
632 << " " << pdyn->GetDefinition()->GetParticleName()
633 << ", PDG mass: " << mass_pdg << ", dynamic mass: "
634 << mass_dyn << G4endl
635 << (epReportLevel<0 ? "abort the event"
636 : "re-sample the interaction") << G4endl
637 << " Process / Model: " << GetProcessName()<< " / "
638 << theModel->GetModelName() << G4endl
639 << " Primary: " << aPro.GetDefinition()->GetParticleName()
640 << " (" << aPro.GetDefinition()->GetPDGEncoding() << "), "
641 << " E= " << aPro.Get4Momentum().e()
642 << ", target nucleus (" << aNucleus.GetZ_asInt() << ", "
643 << aNucleus.GetA_asInt() << ")" << G4endl;
644 G4Exception("G4HadronicProcess:CheckResult()", "had012",
646 // must return here.....
647 return result;
648 }
649 }
650 G4double deltaE= nuclearMass + aPro.GetTotalEnergy() - finalE;
651
652 std::pair<G4double, G4double> checkLevels =
653 theModel->GetFatalEnergyCheckLevels(); // (relative, absolute)
654 if (std::abs(deltaE) > checkLevels.second &&
655 std::abs(deltaE) > checkLevels.first*aPro.GetKineticEnergy()){
656 // do not delete result, this is a pointer to a data member;
657 result->Clear();
658 result = nullptr;
660 desc << "Warning: Bad energy non-conservation detected, will "
661 << (epReportLevel<0 ? "abort the event"
662 : "re-sample the interaction") << G4endl
663 << " Process / Model: " << GetProcessName()<< " / "
664 << theModel->GetModelName() << G4endl
665 << " Primary: " << aPro.GetDefinition()->GetParticleName()
666 << " (" << aPro.GetDefinition()->GetPDGEncoding() << "), "
667 << " E= " << aPro.Get4Momentum().e()
668 << ", target nucleus (" << aNucleus.GetZ_asInt() << ", "
669 << aNucleus.GetA_asInt() << ")" << G4endl
670 << " E(initial - final) = " << deltaE << " MeV." << G4endl;
671 G4Exception("G4HadronicProcess:CheckResult()", "had012",
673 }
674 }
675 return result;
676}
677
678void
680 const G4Nucleus& aNucleus)
681{
682 G4int target_A=aNucleus.GetA_asInt();
683 G4int target_Z=aNucleus.GetZ_asInt();
684 G4double targetMass = G4NucleiProperties::GetNuclearMass(target_A,target_Z);
685 G4LorentzVector target4mom(0, 0, 0, targetMass
686 + nICelectrons*CLHEP::electron_mass_c2);
687
688 G4LorentzVector projectile4mom = aTrack.GetDynamicParticle()->Get4Momentum();
689 G4int track_A = aTrack.GetDefinition()->GetBaryonNumber();
690 G4int track_Z = G4lrint(aTrack.GetDefinition()->GetPDGCharge());
691
692 G4int initial_A = target_A + track_A;
693 G4int initial_Z = target_Z + track_Z - nICelectrons;
694
695 G4LorentzVector initial4mom = projectile4mom + target4mom;
696
697 // Compute final-state momentum for scattering and "do nothing" results
698 G4LorentzVector final4mom;
699 G4int final_A(0), final_Z(0);
700
701 G4int nSec = theTotalResult->GetNumberOfSecondaries();
702 if (theTotalResult->GetTrackStatus() != fStopAndKill) { // If it is Alive
703 // Either interaction didn't complete, returned "do nothing" state
704 // or the primary survived the interaction (e.g. electro-nucleus )
705
706 // Interaction didn't complete, returned "do nothing" state
707 // - or suppressed recoil (e.g. Neutron elastic )
708 final4mom = initial4mom;
709 final_A = initial_A;
710 final_Z = initial_Z;
711 if (nSec > 0) {
712 // The primary remains in final state (e.g. electro-nucleus )
713 // Use the final energy / momentum
714 const G4ThreeVector& v = *theTotalResult->GetMomentumDirection();
715 G4double ekin = theTotalResult->GetEnergy();
716 G4double mass = aTrack.GetDefinition()->GetPDGMass();
717 G4double ptot = std::sqrt(ekin*(ekin + 2*mass));
718 final4mom.set(ptot*v.x(), ptot*v.y(), ptot*v.z(), mass + ekin);
719 final_A = track_A;
720 final_Z = track_Z;
721 // Expect that the target nucleus will have interacted,
722 // and its products, including recoil, will be included in secondaries.
723 }
724 }
725 if( nSec > 0 ) {
726 G4Track* sec;
727
728 for (G4int i = 0; i < nSec; i++) {
729 sec = theTotalResult->GetSecondary(i);
730 final4mom += sec->GetDynamicParticle()->Get4Momentum();
731 final_A += sec->GetDefinition()->GetBaryonNumber();
732 final_Z += G4lrint(sec->GetDefinition()->GetPDGCharge());
733 }
734 }
735
736 // Get level-checking information (used to cut-off relative checks)
737 G4String processName = GetProcessName();
739 G4String modelName("none");
740 if (theModel) modelName = theModel->GetModelName();
741 std::pair<G4double, G4double> checkLevels = epCheckLevels;
742 if (!levelsSetByProcess) {
743 if (theModel) checkLevels = theModel->GetEnergyMomentumCheckLevels();
744 checkLevels.first= std::min(checkLevels.first, epCheckLevels.first);
745 checkLevels.second=std::min(checkLevels.second, epCheckLevels.second);
746 }
747
748 // Compute absolute total-energy difference, and relative kinetic-energy
749 G4bool checkRelative = (aTrack.GetKineticEnergy() > checkLevels.second);
750
751 G4LorentzVector diff = initial4mom - final4mom;
752 G4double absolute = diff.e();
753 G4double relative = checkRelative ? absolute/aTrack.GetKineticEnergy() : 0.;
754
755 G4double absolute_mom = diff.vect().mag();
756 G4double relative_mom = checkRelative ? absolute_mom/aTrack.GetMomentum().mag() : 0.;
757
758 // Evaluate relative and absolute conservation
759 G4bool relPass = true;
760 G4String relResult = "pass";
761 if ( std::abs(relative) > checkLevels.first
762 || std::abs(relative_mom) > checkLevels.first) {
763 relPass = false;
764 relResult = checkRelative ? "fail" : "N/A";
765 }
766
767 G4bool absPass = true;
768 G4String absResult = "pass";
769 if ( std::abs(absolute) > checkLevels.second
770 || std::abs(absolute_mom) > checkLevels.second ) {
771 absPass = false ;
772 absResult = "fail";
773 }
774
775 G4bool chargePass = true;
776 G4String chargeResult = "pass";
777 if ( (initial_A-final_A)!=0
778 || (initial_Z-final_Z)!=0 ) {
779 chargePass = checkLevels.second < DBL_MAX ? false : true;
780 chargeResult = "fail";
781 }
782
783 G4bool conservationPass = (relPass || absPass) && chargePass;
784
785 std::stringstream Myout;
786 G4bool Myout_notempty(false);
787 // Options for level of reporting detail:
788 // 0. off
789 // 1. report only when E/p not conserved
790 // 2. report regardless of E/p conservation
791 // 3. report only when E/p not conserved, with model names, process names, and limits
792 // 4. report regardless of E/p conservation, with model names, process names, and limits
793 // negative -1.., as above, but send output to stderr
794
795 if( std::abs(epReportLevel) == 4
796 || ( std::abs(epReportLevel) == 3 && ! conservationPass ) ){
797 Myout << " Process: " << processName << " , Model: " << modelName << G4endl;
798 Myout << " Primary: " << aTrack.GetParticleDefinition()->GetParticleName()
799 << " (" << aTrack.GetParticleDefinition()->GetPDGEncoding() << "),"
800 << " E= " << aTrack.GetDynamicParticle()->Get4Momentum().e()
801 << ", target nucleus (" << aNucleus.GetZ_asInt() << ","
802 << aNucleus.GetA_asInt() << ")" << G4endl;
803 Myout_notempty=true;
804 }
805 if ( std::abs(epReportLevel) == 4
806 || std::abs(epReportLevel) == 2
807 || ! conservationPass ){
808
809 Myout << " "<< relResult <<" relative, limit " << checkLevels.first << ", values E/T(0) = "
810 << relative << " p/p(0)= " << relative_mom << G4endl;
811 Myout << " "<< absResult << " absolute, limit (MeV) " << checkLevels.second/MeV << ", values E / p (MeV) = "
812 << absolute/MeV << " / " << absolute_mom/MeV << " 3mom: " << (diff.vect())*1./MeV << G4endl;
813 Myout << " "<< chargeResult << " charge/baryon number balance " << (initial_Z-final_Z) << " / " << (initial_A-final_A) << " "<< G4endl;
814 Myout_notempty=true;
815
816 }
817 Myout.flush();
818 if ( Myout_notempty ) {
819 if (epReportLevel > 0) G4cout << Myout.str()<< G4endl;
820 else if (epReportLevel < 0) G4cerr << Myout.str()<< G4endl;
821 }
822}
823
825 const G4String& method,
827{
828 ed << "Unrecoverable error in the method " << method << " of "
829 << GetProcessName() << G4endl;
830 ed << "TrackID= "<< aTrack.GetTrackID() << " ParentID= "
831 << aTrack.GetParentID()
832 << " " << aTrack.GetParticleDefinition()->GetParticleName()
833 << G4endl;
834 ed << "Ekin(GeV)= " << aTrack.GetKineticEnergy()/CLHEP::GeV
835 << "; direction= " << aTrack.GetMomentumDirection() << G4endl;
836 ed << "Position(mm)= " << aTrack.GetPosition()/CLHEP::mm << ";";
837
838 if (aTrack.GetMaterial()) {
839 ed << " material " << aTrack.GetMaterial()->GetName();
840 }
841 ed << G4endl;
842
843 if (aTrack.GetVolume()) {
844 ed << "PhysicalVolume <" << aTrack.GetVolume()->GetName()
845 << ">" << G4endl;
846 }
847}
848
853
855{
856 theCrossSectionDataStore->AddDataSet(aDataSet);
857}
858
859std::vector<G4HadronicInteraction*>&
861{
862 return theEnergyRangeManager.GetHadronicInteractionList();
863}
864
867{
868 std::vector<G4HadronicInteraction*>& list
869 = theEnergyRangeManager.GetHadronicInteractionList();
870 for (auto & mod : list) {
871 if (mod->GetModelName() == modelName) return mod;
872 }
873 return nullptr;
874}
875
878 const G4Material* mat,
879 const G4double kinEnergy)
880{
881 auto dp = new G4DynamicParticle(part, unitVector, kinEnergy);
882 G4double xs = theCrossSectionDataStore->ComputeCrossSection(dp, mat);
883 delete dp;
884 return xs;
885}
886
887void G4HadronicProcess::RecomputeXSandMFP(const G4double kinEnergy)
888{
889 auto dp = new G4DynamicParticle(currentParticle, unitVector, kinEnergy);
892 theMFP = (theLastCrossSection > 0.0) ? 1.0/theLastCrossSection : DBL_MAX;
893 delete dp;
894}
895
896void G4HadronicProcess::UpdateCrossSectionAndMFP(const G4double e)
897{
898 if(fXSType == fHadNoIntegral) {
899 DefineXSandMFP();
900
901 } else if(fXSType == fHadIncreasing) {
902 if(e*invLambdaFactor < mfpKinEnergy) {
903 mfpKinEnergy = e;
904 ComputeXSandMFP();
905 }
906
907 } else if(fXSType == fHadDecreasing) {
908 if(e < mfpKinEnergy && mfpKinEnergy > minKinEnergy) {
909 G4double e1 = std::max(e*lambdaFactor, minKinEnergy);
910 mfpKinEnergy = e1;
911 RecomputeXSandMFP(e1);
912 }
913
914 } else if(fXSType == fHadOnePeak) {
915 G4double epeak = (*theEnergyOfCrossSectionMax)[matIdx];
916 if(e <= epeak) {
917 if(e*invLambdaFactor < mfpKinEnergy) {
918 mfpKinEnergy = e;
919 ComputeXSandMFP();
920 }
921 } else if(e < mfpKinEnergy) {
922 G4double e1 = std::max(epeak, e*lambdaFactor);
923 mfpKinEnergy = e1;
924 RecomputeXSandMFP(e1);
925 }
926
927 } else if(fXSType == fHadTwoPeaks) {
928 G4TwoPeaksHadXS* xs = (*fXSpeaks)[matIdx];
929 const G4double e1peak = xs->e1peak;
930
931 // below the 1st peak
932 if(e <= e1peak) {
933 if(e*invLambdaFactor < mfpKinEnergy) {
934 mfpKinEnergy = e;
935 ComputeXSandMFP();
936 }
937 return;
938 }
939 const G4double e1deep = xs->e1deep;
940 // above the 1st peak, below the deep
941 if(e <= e1deep) {
942 if(mfpKinEnergy >= e1deep || e <= mfpKinEnergy) {
943 const G4double e1 = std::max(e1peak, e*lambdaFactor);
944 mfpKinEnergy = e1;
945 RecomputeXSandMFP(e1);
946 }
947 return;
948 }
949 const G4double e2peak = xs->e2peak;
950 // above the deep, below 2nd peak
951 if(e <= e2peak) {
952 if(e*invLambdaFactor < mfpKinEnergy) {
953 mfpKinEnergy = e;
954 ComputeXSandMFP();
955 }
956 return;
957 }
958 const G4double e2deep = xs->e2deep;
959 // above the 2nd peak, below the deep
960 if(e <= e2deep) {
961 if(mfpKinEnergy >= e2deep || e <= mfpKinEnergy) {
962 const G4double e1 = std::max(e2peak, e*lambdaFactor);
963 mfpKinEnergy = e1;
964 RecomputeXSandMFP(e1);
965 }
966 return;
967 }
968 const G4double e3peak = xs->e3peak;
969 // above the deep, below 3d peak
970 if(e <= e3peak) {
971 if(e*invLambdaFactor < mfpKinEnergy) {
972 mfpKinEnergy = e;
973 ComputeXSandMFP();
974 }
975 return;
976 }
977 // above 3d peak
978 if(e <= mfpKinEnergy) {
979 const G4double e1 = std::max(e3peak, e*lambdaFactor);
980 mfpKinEnergy = e1;
981 RecomputeXSandMFP(e1);
982 }
983
984 } else {
985 DefineXSandMFP();
986 }
987}
G4double condition(const G4ErrorSymMatrix &m)
@ JustWarning
@ FatalException
@ EventMustBeAborted
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition G4Exp.hh:132
G4ForceCondition
@ NotForced
@ stopAndKill
@ fHadTwoPeaks
@ fHadIncreasing
@ fHadDecreasing
@ fHadNoIntegral
@ fHadOnePeak
G4HadronicProcessType
@ fHadronInelastic
G4double G4Log(G4double x)
Definition G4Log.hh:169
CLHEP::HepLorentzVector G4LorentzVector
G4ProcessType
@ fHadronic
CLHEP::Hep3Vector G4ThreeVector
@ fKillTrackAndSecondaries
@ fSuspend
@ fAlive
@ fStopAndKill
@ fStopButAlive
@ fPostponeToNextEvent
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
#define G4UniformRand()
Definition Randomize.hh:52
double z() const
double x() const
double y() const
double mag() const
void set(double x, double y, double z)
Hep3Vector & rotateUz(const Hep3Vector &)
Hep3Vector vect() const
void set(double x, double y, double z, double t)
static G4AntiKaonZero * Definition()
G4double ComputeCrossSection(const G4DynamicParticle *, const G4Material *)
G4double GetMass() const
void SetMomentumDirection(const G4ThreeVector &aDirection)
const G4ThreeVector & GetMomentumDirection() const
void SetMass(G4double mass)
const G4ParticleDefinition * GetParticleDefinition() const
G4ParticleDefinition * GetDefinition() const
G4LorentzVector Get4Momentum() const
G4double GetKineticEnergy() const
G4double GetTotalEnergy() const
void SetKineticEnergy(G4double aEnergy)
const G4String & GetName() const
Definition G4Element.hh:115
G4int GetZasInt() const
Definition G4Element.hh:120
G4double GetEnergyChange() const
G4HadFinalStateStatus GetStatusChange() const
void SetTrafoToLab(const G4LorentzRotation &aT)
G4double GetLocalEnergyDeposit() const
const G4ThreeVector & GetMomentumChange() const
std::size_t GetNumberOfSecondaries() const
G4HadSecondary * GetSecondary(size_t i)
const G4ParticleDefinition * GetDefinition() const
G4double GetKineticEnergy() const
const G4LorentzVector & Get4Momentum() const
G4double GetTotalEnergy() const
G4DynamicParticle * GetParticle()
G4int GetParentResonanceID() const
G4double GetWeight() const
const G4ParticleDefinition * GetParentResonanceDef() const
G4double GetTime() const
G4int GetCreatorModelID() const
static std::vector< G4TwoPeaksHadXS * > * FillPeaksStructure(G4HadronicProcess *, const G4ParticleDefinition *, const G4double tmin, const G4double tmax)
static std::vector< G4double > * FindCrossSectionMax(G4HadronicProcess *, const G4ParticleDefinition *, const G4double tmin, const G4double tmax)
void Report(std::ostream &aS) const
virtual const std::pair< G4double, G4double > GetFatalEnergyCheckLevels() const
virtual std::pair< G4double, G4double > GetEnergyMomentumCheckLevels() const
const G4String & GetModelName() const
G4bool EnableIntegralInelasticXS() const
static G4HadronicParameters * Instance()
G4double GetEPRelativeLevel() const
G4double GetEPAbsoluteLevel() const
G4bool EnableIntegralElasticXS() const
static G4HadronicProcessStore * Instance()
void RegisterInteraction(G4HadronicProcess *, G4HadronicInteraction *)
void Register(G4HadronicProcess *)
void PrintInfo(const G4ParticleDefinition *)
void FillResult(G4HadFinalState *aR, const G4Track &aT)
G4HadProjectile thePro
G4VParticleChange * PostStepDoIt(const G4Track &aTrack, const G4Step &aStep) override
void ProcessDescription(std::ostream &outFile) const override
G4double ComputeCrossSection(const G4ParticleDefinition *, const G4Material *, const G4double kinEnergy)
void BiasCrossSectionByFactor(G4double aScale)
void StartTracking(G4Track *track) override
G4HadFinalState * CheckResult(const G4HadProjectile &thePro, const G4Nucleus &targetNucleus, G4HadFinalState *result)
G4double GetMeanFreePath(const G4Track &aTrack, G4double, G4ForceCondition *) override
G4HadronicInteraction * GetHadronicInteraction() const
G4ParticleChange * theTotalResult
void AddDataSet(G4VCrossSectionDataSet *aDataSet)
G4double GetElementCrossSection(const G4DynamicParticle *part, const G4Element *elm, const G4Material *mat=nullptr)
std::vector< G4HadronicInteraction * > & GetHadronicInteractionList()
void PreparePhysicsTable(const G4ParticleDefinition &) override
G4HadronicProcess(const G4String &processName="Hadronic", G4ProcessType procType=fHadronic)
G4HadronicInteraction * ChooseHadronicInteraction(const G4HadProjectile &aHadProjectile, G4Nucleus &aTargetNucleus, const G4Material *aMaterial, const G4Element *anElement)
void BuildPhysicsTable(const G4ParticleDefinition &) override
G4CrossSectionDataStore * theCrossSectionDataStore
void CheckEnergyMomentumConservation(const G4Track &, const G4Nucleus &)
G4HadronicInteraction * GetHadronicModel(const G4String &)
void DumpState(const G4Track &, const G4String &, G4ExceptionDescription &)
void DumpPhysicsTable(const G4ParticleDefinition &p)
void MultiplyCrossSectionBy(G4double factor)
G4double PostStepGetPhysicalInteractionLength(const G4Track &track, G4double, G4ForceCondition *) override
void RegisterMe(G4HadronicInteraction *a)
static G4KaonZeroLong * Definition()
static G4KaonZeroShort * Definition()
static G4KaonZero * Definition()
Definition G4KaonZero.cc:48
std::size_t GetIndex() const
const G4String & GetName() const
static G4double GetNuclearMass(const G4double A, const G4double Z)
G4int GetA_asInt() const
Definition G4Nucleus.hh:78
G4int GetZ_asInt() const
Definition G4Nucleus.hh:84
G4ProcessManager * GetProcessManager() const
const G4String & GetParticleName() const
G4ProcessVector * GetAtRestProcessVector(G4ProcessVectorTypeIndex typ=typeGPIL) const
std::size_t size() const
G4TrackStatus GetTrackStatus() const
G4int GetTrackID() const
const G4ParticleDefinition * GetParticleDefinition() const
G4VPhysicalVolume * GetVolume() const
G4double GetWeight() const
void SetWeight(G4double aValue)
void SetParentResonanceID(const G4int parentID)
const G4ThreeVector & GetPosition() const
void SetTouchableHandle(const G4TouchableHandle &apValue)
G4double GetGlobalTime() const
G4ThreeVector GetMomentum() const
G4Material * GetMaterial() const
G4ParticleDefinition * GetDefinition() const
const G4DynamicParticle * GetDynamicParticle() const
const G4TouchableHandle & GetTouchableHandle() const
const G4ThreeVector & GetMomentumDirection() const
G4double GetKineticEnergy() const
void SetCreatorModelID(const G4int id)
G4int GetParentID() const
void SetParentResonanceDef(const G4ParticleDefinition *parent)
G4VDiscreteProcess(const G4String &aName, G4ProcessType aType=fNotDefined)
void SetSecondaryWeightByProcess(G4bool)
const G4String & GetName() const
G4double currentInteractionLength
G4double theInitialNumberOfInteractionLength
const G4VProcess * GetMasterProcess() const
G4int verboseLevel
G4double theNumberOfInteractionLengthLeft
void SetProcessSubType(G4int)
G4double GetTotalNumberOfInteractionLengthTraversed() const
G4int GetProcessSubType() const
const G4String & GetProcessName() const
G4bool IsWorkerThread()
int G4lrint(double ad)
Definition templates.hh:134
#define DBL_MAX
Definition templates.hh:62