Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4CascadeInterface.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// 20100114 M. Kelsey -- Remove G4CascadeMomentum, use G4LorentzVector directly
28// 20100413 M. Kelsey -- Pass G4CollisionOutput by ref to ::collide()
29// 20100414 M. Kelsey -- Check for K0L/K0S before using G4InuclElemPart::type
30// 20100418 M. Kelsey -- Reference output particle lists via const-ref, use
31// const_iterator for both.
32// 20100428 M. Kelsey -- Use G4InuclParticleNames enum
33// 20100429 M. Kelsey -- Change "case gamma:" to "case photon:"
34// 20100517 M. Kelsey -- Follow new ctors for G4*Collider family.
35// 20100520 M. Kelsey -- Simplify collision loop, move momentum rotations to
36// G4CollisionOutput, copy G4DynamicParticle directly from
37// G4InuclParticle, no switch-block required.
38// 20100615 M. Kelsey -- Bug fix: For K0's need ekin in GEANT4 units
39// 20100617 M. Kelsey -- Rename "debug_" preprocessor flag to G4CASCADE_DEBUG,
40// and "BERTDEV" to "G4CASCADE_COULOMB_DEV"
41// 20100617 M. Kelsey -- Make G4InuclCollider a local data member
42// 20100618 M. Kelsey -- Deploy energy-conservation test on final state, with
43// preprocessor flag G4CASCADE_SKIP_ECONS to skip test.
44// 20100620 M. Kelsey -- Use new energy-conservation pseudo-collider
45// 20100621 M. Kelsey -- Fix compiler warning from GCC 4.5
46// 20100624 M. Kelsey -- Fix cascade loop to check nTries every time (had
47// allowed for infinite loop on E-violation); dump event data
48// to output if E-violation exceeds maxTries; use CheckBalance
49// for baryon and charge conservation.
50// 20100701 M. Kelsey -- Pass verbosity through to G4CollisionOutput
51// 20100714 M. Kelsey -- Report number of iterations before success
52// 20100720 M. Kelsey -- Use G4CASCADE_SKIP_ECONS flag for reporting
53// 20100723 M. Kelsey -- Move G4CollisionOutput to .hh file for reuse
54// 20100914 M. Kelsey -- Migrate to integer A and Z
55// 20100916 M. Kelsey -- Simplify ApplyYourself() by encapsulating code blocks
56// into numerous functions; make data-member colliders pointers;
57// provide support for projectile nucleus
58// 20100919 M. Kelsey -- Fix incorrect logic in retryInelasticNucleus()
59// 20100922 M. Kelsey -- Add functions to select de-excitation method
60// 20100924 M. Kelsey -- Migrate to "OutgoingNuclei" names in CollisionOutput
61// 20110224 M. Kelsey -- Add createTarget() for use with Propagate(); split
62// conservation law messages to separate function; begin to add
63// infrastructure code to Propagate. Move verbose
64// setting to .cc file, and apply to all member objects.
65// 20110301 M. Kelsey -- Add copyPreviousCascade() for use with Propagate()
66// along with new buffers and related particle-conversion
67// functions. Encapulate buffer deletion in clear(). Add some
68// diagnostic messages.
69// 20110302 M. Kelsey -- Redo diagnostics inside G4CASCADE_DEBUG_INTERFACE
70// 20110304 M. Kelsey -- Drop conversion of Propagate() arguments; pass
71// directly to collider for processing. Rename makeReactionProduct
72// to makeDynamicParticle.
73// 20110316 M. Kelsey -- Move kaon-mixing for type-code into G4InuclParticle;
74// add placeholders to capture and use bullet in Propagte
75// 20110327 G. Folger -- Set up for E/p checking by G4HadronicProcess in ctor
76// 20110328 M. Kelsey -- Modify balance() initialization to match Gunter's
77// 20110404 M. Kelsey -- Get primary projectile from base class (ref-03)
78// 20110502 M. Kelsey -- Add interface to capture random seeds for user
79// 20110719 M. Kelsey -- Use trivialise() in case maximum retries are reached
80// 20110720 M. Kelsey -- Discard elastic-cut array (no longer needed),
81// discard local "theFinalState" (in base as "theParticleChange"),
82// Modify createBullet() to set null pointer if bullet unusable,
83// return empty final-state on failures.
84// Fix charge violation report before throwing exception.
85// 20110722 M. Kelsey -- In makeDynamicParticle(), allow invalid type codes
86// in order to process, e.g., resonances from Propagate() input
87// 20110728 M. Kelsey -- Per V.Ivantchenko, change NoInteraction to return
88// zero particles, but set kinetic energy from projectile.
89// 20110801 M. Kelsey -- Make bullet, target point to local buffers, no delete
90// 20110802 M. Kelsey -- Use new decay handler for Propagate interface
91// 20110922 M. Kelsey -- Follow migration of G4InuclParticle::print(), use
92// G4ExceptionDescription for reporting before throwing exception
93// 20120125 M. Kelsey -- In retryInelasticProton() check for empty output
94// 20120525 M. Kelsey -- In NoInteraction, check for Ekin<0., set to zero;
95// use SetEnergyChange(0.) explicitly for good final states.
96// 20120822 M. Kelsey -- Move envvars to G4CascadeParameters.
97// 20130508 D. Wright -- Add support for muon capture
98// 20130804 M. Kelsey -- Fix bug #1513 -- "(Z=1)" in boolean expression
99// 20140116 M. Kelsey -- Move statics to const data members to avoid weird
100// interactions with MT.
101// 20140929 M. Kelsey -- Explicitly call useCascadeDeexcitation() in ctor
102// 20150506 M. Kelsey -- Call Initialize() in ctor for master thread only
103// 20150608 M. Kelsey -- Label all while loops as terminating.
104
105#include <cmath>
106#include <iostream>
107
108#include "G4CascadeInterface.hh"
109#include "globals.hh"
110#include "G4SystemOfUnits.hh"
113#include "G4CascadeParameters.hh"
114#include "G4CollisionOutput.hh"
116#include "G4DynamicParticle.hh"
117#include "G4HadronicException.hh"
118#include "G4InuclCollider.hh"
121#include "G4InuclNuclei.hh"
122#include "G4InuclParticle.hh"
124#include "G4KaonZeroLong.hh"
125#include "G4KaonZeroShort.hh"
126#include "G4KineticTrack.hh"
128#include "G4Nucleus.hh"
131#include "G4Threading.hh"
132#include "G4Track.hh"
133#include "G4V3DNucleus.hh"
134#include "G4UnboundPN.hh"
135#include "G4Dineutron.hh"
136#include "G4Diproton.hh"
138
139using namespace G4InuclParticleNames;
140
141typedef std::vector<G4InuclElementaryParticle>::const_iterator particleIterator;
142typedef std::vector<G4InuclNuclei>::const_iterator nucleiIterator;
143
144
145// Constructor and destrutor
146
149 randomFile(G4CascadeParameters::randomFile()),
150 maximumTries(20), numberOfTries(0),
151 collider(new G4InuclCollider), balance(new G4CascadeCheckBalance(name)),
152 ltcollider(new G4LightTargetCollider),
153 bullet(0), target(0), output(new G4CollisionOutput), secID(-1)
154{
155 // Set up global objects for master thread or sequential build
157
158 SetEnergyMomentumCheckLevels(5*perCent, 10*MeV);
159 balance->setLimits(5*perCent, 10*MeV/GeV); // Bertini internal units
161
164 } else if ( G4CascadeParameters::useAbla() ) {
166 } else {
168 }
169
170 secID = G4PhysicsModelCatalog::GetModelID( "model_BertiniCascade" );
171}
172
174 clear();
175 delete collider; collider=0;
176 delete ltcollider; ltcollider = 0;
177 delete balance; balance=0;
178 delete output; output=0;
179}
180
181void G4CascadeInterface::ModelDescription(std::ostream& outFile) const
182{
183 outFile << "The Bertini-style cascade implements the inelastic scattering\n"
184 << "of hadrons by nuclei. Nucleons, pions, kaons and hyperons\n"
185 << "from 0 to 15 GeV may be used as projectiles in this model.\n"
186 << "Final state hadrons are produced by a classical cascade\n"
187 << "consisting of individual hadron-nucleon scatterings which use\n"
188 << "free-space partial cross sections, corrected for various\n"
189 << "nuclear medium effects. The target nucleus is modeled as a\n"
190 << "set of 1, 3 or 6 spherical shells, in which scattered hadrons\n"
191 << "travel in straight lines until they are reflected from or\n"
192 << "transmitted through shell boundaries.\n";
193}
194
195void G4CascadeInterface::DumpConfiguration(std::ostream& outFile) const {
197}
198
200 bullet=0;
201 target=0;
202}
203
204
205// Initialize shared objects for use across multiple threads
206
214
215
216// Select post-cascade processing (default will be CascadeDeexcitation)
217// NOTE: Currently just calls through to Collider, in future will do something
218
222
226
230
231
232// Apply verbosity to all member objects (overrides base class version)
233
236 collider->setVerboseLevel(verbose);
237 balance->setVerboseLevel(verbose);
238 output->setVerboseLevel(verbose);
239}
240
241
242// Test whether inputs are valid for this model
243
245 G4Nucleus& /* theNucleus */) {
246 return IsApplicable(aTrack.GetDefinition());
247}
248
250 if (aPD->GetAtomicMass() > 1) return true; // Nuclei are okay
251
252 // Valid particle and have interactions available
255}
256
257
258// Main Actions
259
262 G4Nucleus& theNucleus) {
263 if (verboseLevel)
264 G4cout << " >>> G4CascadeInterface::ApplyYourself" << G4endl;
265
266 if (aTrack.GetKineticEnergy() < 0.) {
267 G4cerr << " >>> G4CascadeInterface got negative-energy track: "
268 << aTrack.GetDefinition()->GetParticleName() << " Ekin = "
269 << aTrack.GetKineticEnergy() << G4endl;
270 }
271
272#ifdef G4CASCADE_DEBUG_INTERFACE
273 static G4int counter(0);
274 counter++;
275 G4cerr << "Reaction number "<< counter << " "
276 << aTrack.GetDefinition()->GetParticleName() << " "
277 << aTrack.GetKineticEnergy() << " MeV" << G4endl;
278#endif
279
280 if (!randomFile.empty()) { // User requested random-seed capture
281 if (verboseLevel>1)
282 G4cout << " Saving random engine state to " << randomFile << G4endl;
284 }
285
287 clear();
288
289 // Abort processing if no interaction is possible
290 if (!IsApplicable(aTrack, theNucleus)) {
291 if (verboseLevel) G4cerr << " No interaction possible " << G4endl;
292 return NoInteraction(aTrack, theNucleus);
293 }
294
295 // If target A < 3 skip all cascade machinery and do scattering on
296 // nucleons
297
298 if (aTrack.GetDefinition() == G4Gamma::Gamma() &&
299 theNucleus.GetA_asInt() < 3) {
300 output->reset();
301 createBullet(aTrack);
302 createTarget(theNucleus);
303 // Due to binning, gamma-p cross sections between 130 MeV and the inelastic threshold
304 // (144 for pi0 p, 152 for pi+ n) are non-zero, causing energy non-conservation
305 // So, if Egamma is between 144 and 152, only pi0 p is allowed.
306
307 // Also, inelastic gamma-p cross section from G4PhotoNuclearCrossSection seems to be
308 // non-zero below between pi0 mass (135 MeV) and threshold (144 MeV)
309 ltcollider->collide(bullet, target, *output);
310
311 } else {
312
313 // Make conversion between native Geant4 and Bertini cascade classes.
314 if (!createBullet(aTrack)) {
315 if (verboseLevel) G4cerr << " Unable to create usable bullet" << G4endl;
316 return NoInteraction(aTrack, theNucleus);
317 }
318
319 if (!createTarget(theNucleus)) {
320 if (verboseLevel) G4cerr << " Unable to create usable target" << G4endl;
321 return NoInteraction(aTrack, theNucleus);
322 }
323
324 // Different retry conditions for proton target vs. nucleus
325 const G4bool isHydrogen = (theNucleus.GetA_asInt() == 1);
326
327 numberOfTries = 0;
328 do { // we try to create inelastic interaction
329 if (verboseLevel > 1)
330 G4cout << " Generating cascade attempt " << numberOfTries << G4endl;
331
332 output->reset();
333 collider->collide(bullet, target, *output);
334 balance->collide(bullet, target, *output);
335
336 numberOfTries++;
337 /* Loop checking 08.06.2015 MHK */
338 } while ( isHydrogen ? retryInelasticProton() : retryInelasticNucleus() );
339
340 // Null event if unsuccessful
341 if (numberOfTries >= maximumTries) {
342 if (verboseLevel)
343 G4cout << " Cascade aborted after trials " << numberOfTries << G4endl;
344 return NoInteraction(aTrack, theNucleus);
345 }
346
347 // Abort job if energy or momentum are not conserved
348 if (!balance->okay()) {
350 return NoInteraction(aTrack, theNucleus);
351 }
352
353 // Successful cascade -- clean up and return
354 if (verboseLevel) {
355 G4cout << " Cascade output after trials " << numberOfTries << G4endl;
356 if (verboseLevel > 1) output->printCollisionOutput();
357 }
358
359 } // end cascade-style collisions
360
362
363 // Report violations of conservation laws in original frame
365
366 // Clean up and return final result;
367 clear();
368/*
369 G4int nSec = theParticleChange.GetNumberOfSecondaries();
370 for (G4int i = 0; i < nSec; i++) {
371 G4HadSecondary* sec = theParticleChange.GetSecondary(i);
372 G4DynamicParticle* dp = sec->GetParticle();
373 if (dp->GetDefinition()->GetParticleName() == "neutron")
374 G4cout << dp->GetDefinition()->GetParticleName() << " has "
375 << dp->GetKineticEnergy()/MeV << " MeV " << G4endl;
376 }
377*/
378 return &theParticleChange;
379}
380
383 G4V3DNucleus* theNucleus) {
384 if (verboseLevel) G4cout << " >>> G4CascadeInterface::Propagate" << G4endl;
385
386#ifdef G4CASCADE_DEBUG_INTERFACE
387 if (verboseLevel>1) {
388 G4cout << " G4V3DNucleus A " << theNucleus->GetMassNumber()
389 << " Z " << theNucleus->GetCharge()
390 << "\n " << theSecondaries->size() << " secondaries:" << G4endl;
391 for (size_t i=0; i<theSecondaries->size(); i++) {
392 G4KineticTrack* kt = (*theSecondaries)[i];
393 G4cout << " " << i << ": " << kt->GetDefinition()->GetParticleName()
394 << " p " << kt->Get4Momentum() << " @ " << kt->GetPosition()
395 << " t " << kt->GetFormationTime() << G4endl;
396 }
397 }
398#endif
399
400 if (!randomFile.empty()) { // User requested random-seed capture
401 if (verboseLevel>1)
402 G4cout << " Saving random engine state to " << randomFile << G4endl;
404 }
405
407 clear();
408
409 // Process input secondaries list to eliminate resonances
410 G4DecayKineticTracks decay(theSecondaries);
411
412 // NOTE: Requires 9.4-ref-03 mods to base class and G4TheoFSGenerator
413 const G4HadProjectile* projectile = GetPrimaryProjectile();
414 if (projectile) createBullet(*projectile);
415
416 if (!createTarget(theNucleus)) {
417 if (verboseLevel) G4cerr << " Unable to create usable target" << G4endl;
418 return 0; // FIXME: This will cause a segfault later
419 }
420
421 numberOfTries = 0;
422 do {
423 if (verboseLevel > 1)
424 G4cout << " Generating rescatter attempt " << numberOfTries << G4endl;
425
426 output->reset();
427 collider->rescatter(bullet, theSecondaries, theNucleus, *output);
428 balance->collide(bullet, target, *output);
429
430 numberOfTries++;
431 // FIXME: retry checks will SEGFAULT until we can define the bullet!
432 } while (retryInelasticNucleus()); /* Loop checking 08.06.2015 MHK */
433
434 // Check whether repeated attempts have all failed; report and exit
435 if (numberOfTries >= maximumTries && !balance->okay()) {
436 throwNonConservationFailure(); // This terminates the job
437 }
438
439 // Successful cascade -- clean up and return
440 if (verboseLevel) {
441 G4cout << " Cascade rescatter after trials " << numberOfTries << G4endl;
442 if (verboseLevel > 1) output->printCollisionOutput();
443 }
444
445 // Does calling code take ownership? I hope so!
447
448 // Clean up and and return final result
449 clear();
450 return propResult;
451}
452
453
454// Replicate input particles onto output
455
458 G4Nucleus& /*theNucleus*/) {
459 if (verboseLevel)
460 G4cout << " >>> G4CascadeInterface::NoInteraction" << G4endl;
461
464
465 G4double ekin = aTrack.GetKineticEnergy()>0. ? aTrack.GetKineticEnergy() : 0.;
466 theParticleChange.SetEnergyChange(ekin); // Protect against rounding
467
468 return &theParticleChange;
469}
470
471
472// Convert input projectile to Bertini internal object
473
475 const G4ParticleDefinition* trkDef = aTrack.GetDefinition();
476 G4int bulletType = 0; // For elementary particles
477 G4int bulletA = 0, bulletZ = 0; // For nucleus projectile
478
479 if (trkDef->GetAtomicMass() <= 1) {
480 bulletType = G4InuclElementaryParticle::type(trkDef);
481 } else {
482 bulletA = trkDef->GetAtomicMass();
483 bulletZ = trkDef->GetAtomicNumber();
484 }
485
486 if (0 == bulletType && 0 == bulletA*bulletZ) {
487 if (verboseLevel) {
488 G4cerr << " G4CascadeInterface: " << trkDef->GetParticleName()
489 << " not usable as bullet." << G4endl;
490 }
491 bullet = 0;
492 return false;
493 }
494
495 // Code momentum and energy -- Bertini wants z-axis and GeV units
496 G4LorentzVector projectileMomentum = aTrack.Get4Momentum()/GeV;
497
498 // Rotation/boost to get from z-axis back to original frame
499 // According to bug report #1990 this rotation is unnecessary and causes
500 // irreproducibility. Verifed and fixed by DHW 27 Nov 2017
501 // bulletInLabFrame = G4LorentzRotation::IDENTITY; // Initialize
502 // bulletInLabFrame.rotateZ(-projectileMomentum.phi());
503 // bulletInLabFrame.rotateY(-projectileMomentum.theta());
504 // bulletInLabFrame.invert();
505
506 G4LorentzVector momentumBullet(0., 0., projectileMomentum.rho(),
507 projectileMomentum.e());
508
509 if (G4InuclElementaryParticle::valid(bulletType)) {
510 hadronBullet.fill(momentumBullet, bulletType);
511 bullet = &hadronBullet;
512 } else {
513 nucleusBullet.fill(momentumBullet, bulletA, bulletZ);
514 bullet = &nucleusBullet;
515 }
516
517 if (verboseLevel > 2) G4cout << "Bullet: \n" << *bullet << G4endl;
518
519 return true;
520}
521
522
523// Convert input nuclear target to Bertini internal object
524
526 return createTarget(theNucleus.GetA_asInt(), theNucleus.GetZ_asInt());
527}
528
530 return createTarget(theNucleus->GetMassNumber(), theNucleus->GetCharge());
531}
532
534 if (A > 1) {
535 nucleusTarget.fill(A, Z);
536 target = &nucleusTarget;
537 } else {
538 hadronTarget.fill(0., (Z==1?proton:neutron));
539 target = &hadronTarget;
540 }
541
542 if (verboseLevel > 2) G4cout << "Target: \n" << *target << G4endl;
543
544 return true; // Right now, target never fails
545}
546
547
548// Convert Bertini particle to output (G4DynamicParticle)
549
552 G4int outgoingType = iep.type();
553
554 if (iep.quasi_deutron()) {
555 G4cerr << " ERROR: G4CascadeInterface incompatible particle type "
556 << outgoingType << G4endl;
557 return 0;
558 }
559
560 // Copy local G4DynPart to public output (handle kaon mixing specially)
561 if (outgoingType == kaonZero || outgoingType == kaonZeroBar) {
562 G4ThreeVector momDir = iep.getMomentum().vect().unit();
563 G4double ekin = iep.getKineticEnergy()*GeV; // Bertini -> G4 units
564
566 if (G4UniformRand() > 0.5) pd = G4KaonZeroLong::Definition();
567
568 return new G4DynamicParticle(pd, momDir, ekin);
569 } else {
570 return new G4DynamicParticle(iep.getDynamicParticle());
571 }
572
573 return 0; // Should never get here!
574}
575
578 if (verboseLevel > 2) {
579 G4cout << " Nuclei fragment: \n" << inuc << G4endl;
580 }
581
582 // Copy local G4DynPart to public output
583 return new G4DynamicParticle(inuc.getDynamicParticle());
584}
585
586
587// Transfer Bertini internal final state to hadronics interface
588
590 if (verboseLevel > 1)
591 G4cout << " >>> G4CascadeInterface::copyOutputToHadronicResult" << G4endl;
592
593 const std::vector<G4InuclNuclei>& outgoingNuclei = output->getOutgoingNuclei();
594 const std::vector<G4InuclElementaryParticle>& particles = output->getOutgoingParticles();
595
598
599 // Get outcoming particles
600 if (!particles.empty()) {
601 particleIterator ipart = particles.begin();
602 for (; ipart != particles.end(); ipart++) {
604 }
605 }
606
607 // get nuclei fragments
608 if (!outgoingNuclei.empty()) {
609 nucleiIterator ifrag = outgoingNuclei.begin();
610 for (; ifrag != outgoingNuclei.end(); ifrag++) {
612 }
613 }
614}
615
617 if (verboseLevel > 1)
618 G4cout << " >>> G4CascadeInterface::copyOutputToReactionProducts" << G4endl;
619
620 const std::vector<G4InuclElementaryParticle>& particles = output->getOutgoingParticles();
621 const std::vector<G4InuclNuclei>& fragments = output->getOutgoingNuclei();
622
624
625 G4ReactionProduct* rp = 0; // Buffers to create outgoing tracks
626 G4DynamicParticle* dp = 0;
627
628 // Get outcoming particles
629 if (!particles.empty()) {
630 particleIterator ipart = particles.begin();
631 for (; ipart != particles.end(); ipart++) {
632 rp = new G4ReactionProduct;
633 dp = makeDynamicParticle(*ipart);
634 (*rp) = (*dp); // This does all the necessary copying
635 rp->SetCreatorModelID(secID);
636 propResult->push_back(rp);
637 delete dp;
638 }
639 }
640
641 // get nuclei fragments
642 if (!fragments.empty()) {
643 nucleiIterator ifrag = fragments.begin();
644 for (; ifrag != fragments.end(); ifrag++) {
645 rp = new G4ReactionProduct;
646 dp = makeDynamicParticle(*ifrag);
647 (*rp) = (*dp); // This does all the necessary copying
648 rp->SetCreatorModelID(secID);
649 propResult->push_back(rp);
650 delete dp;
651 }
652 }
653
654 return propResult;
655}
656
657
658// Report violations of conservation laws in original frame
659
661 balance->collide(bullet, target, *output);
662
663 if (verboseLevel > 2) {
664 if (!balance->baryonOkay()) {
665 G4cerr << "ERROR: no baryon number conservation, sum of baryons = "
666 << balance->deltaB() << G4endl;
667 }
668
669 if (!balance->chargeOkay()) {
670 G4cerr << "ERROR: no charge conservation, sum of charges = "
671 << balance->deltaQ() << G4endl;
672 }
673
674 if (std::abs(balance->deltaKE()) > 0.01 ) { // GeV
675 G4cerr << "Kinetic energy conservation violated by "
676 << balance->deltaKE() << " GeV" << G4endl;
677 }
678
679 G4double eInit = bullet->getEnergy() + target->getEnergy();
680 G4double eFinal = eInit + balance->deltaE();
681
682 G4cout << "Initial energy " << eInit << " final energy " << eFinal
683 << "\nTotal energy conservation at level "
684 << balance->deltaE() * GeV << " MeV" << G4endl;
685
686 if (balance->deltaKE() > 5.0e-5 ) { // 0.05 MeV
687 G4cerr << "FATAL ERROR: kinetic energy created "
688 << balance->deltaKE() * GeV << " MeV" << G4endl;
689 }
690 }
691}
692
693
694// Evaluate whether any outgoing particles penetrated Coulomb barrier
695
697 G4bool violated = false; // by default coulomb analysis is OK
698
699 const G4double coulumbBarrier = 8.7 * MeV/GeV; // Bertini uses GeV
700
701 const std::vector<G4InuclElementaryParticle>& p =
702 output->getOutgoingParticles();
703
704 for (particleIterator ipart=p.begin(); ipart != p.end(); ipart++) {
705 if (ipart->type() == proton) {
706 violated |= (ipart->getKineticEnergy() < coulumbBarrier);
707 }
708 }
709
710 return violated;
711}
712
713// Check whether inelastic collision on proton failed
714
716 const std::vector<G4InuclElementaryParticle>& out =
717 output->getOutgoingParticles();
718
719#ifdef G4CASCADE_DEBUG_INTERFACE
720 // Report on all retry conditions, in order of return logic
721 G4cout << " retryInelasticProton: number of Tries "
722 << ((numberOfTries < maximumTries) ? "RETRY (t)" : "EXIT (f)")
723 << "\n retryInelasticProton: AND collision type ";
724 if (out.empty()) G4cout << "FAILED" << G4endl;
725 else {
726 G4cout << (out.size() == 2 ? "ELASTIC (t)" : "INELASTIC (f)")
727 << "\n retryInelasticProton: AND Leading particles bullet "
728 << (out.size() >= 2 &&
729 (out[0].getDefinition() == bullet->getDefinition() ||
730 out[1].getDefinition() == bullet->getDefinition())
731 ? "YES (t)" : "NO (f)")
732 << G4endl;
733 }
734#endif
735
736 return ( (numberOfTries < maximumTries) &&
737 (out.empty() ||
738 (out.size() == 2 &&
739 (out[0].getDefinition() == bullet->getDefinition() ||
740 out[1].getDefinition() == bullet->getDefinition())))
741 );
742}
743
744// Check whether generic inelastic collision failed
745// NOTE: some conditions are set by compiler flags
746
748 // Quantities necessary for conditional block below
749 G4int npart = output->numberOfOutgoingParticles();
750 G4int nfrag = output->numberOfOutgoingNuclei();
751
752 const G4ParticleDefinition* firstOut = (npart == 0) ? 0 :
753 output->getOutgoingParticles().begin()->getDefinition();
754
755#ifdef G4CASCADE_DEBUG_INTERFACE
756 // Report on all retry conditions, in order of return logic
757 G4cout << " retryInelasticNucleus: numberOfTries "
758 << ((numberOfTries < maximumTries) ? "RETRY (t)" : "EXIT (f)")
759 << "\n retryInelasticNucleus: AND outputParticles "
760 << ((npart != 0) ? "NON-ZERO (t)" : "EMPTY (f)")
761#ifdef G4CASCADE_COULOMB_DEV
762 << "\n retryInelasticNucleus: AND coulombBarrier (COULOMB_DEV) "
763 << (coulombBarrierViolation() ? "VIOLATED (t)" : "PASSED (f)")
764 << "\n retryInelasticNucleus: AND collision type (COULOMB_DEV) "
765 << ((npart+nfrag > 2) ? "INELASTIC (t)" : "ELASTIC (f)")
766#else
767 << "\n retryInelasticNucleus: AND collision type "
768 << ((npart+nfrag < 3) ? "ELASTIC (t)" : "INELASTIC (f)")
769 << "\n retryInelasticNucleus: AND Leading particle bullet "
770 << ((firstOut == bullet->getDefinition()) ? "YES (t)" : "NO (f)")
771#endif
772 << "\n retryInelasticNucleus: OR conservation "
773 << (!balance->okay() ? "FAILED (t)" : "PASSED (f)")
774 << G4endl;
775#endif
776
777 return ( (numberOfTries < maximumTries) &&
778 ( ((npart != 0) &&
779#ifdef G4CASCADE_COULOMB_DEV
780 (coulombBarrierViolation() && npart+nfrag > 2)
781#else
782 (npart+nfrag < 3 && firstOut == bullet->getDefinition())
783#endif
784 )
785#ifndef G4CASCADE_SKIP_ECONS
786 || (!balance->okay())
787#endif
788 )
789 );
790}
791
792
793// Terminate job in case of persistent non-conservation
794// FIXME: Need to migrate to G4ExceptionDescription
795
797 // NOTE: Once G4HadronicException is changed, use the following line!
798 // G4ExceptionDescription errInfo;
799 std::ostream& errInfo = G4cerr;
800
801 errInfo << " >>> G4CascadeInterface has non-conserving"
802 << " cascade after " << numberOfTries << " attempts." << G4endl;
803
804 G4String throwMsg = "G4CascadeInterface - ";
805 if (!balance->energyOkay()) {
806 throwMsg += "Energy";
807 errInfo << " Energy conservation violated by " << balance->deltaE()
808 << " GeV (" << balance->relativeE() << ")" << G4endl;
809 }
810
811 if (!balance->momentumOkay()) {
812 throwMsg += "Momentum";
813 errInfo << " Momentum conservation violated by " << balance->deltaP()
814 << " GeV/c (" << balance->relativeP() << ")" << G4endl;
815 }
816
817 if (!balance->baryonOkay()) {
818 throwMsg += "Baryon number";
819 errInfo << " Baryon number violated by " << balance->deltaB() << G4endl;
820 }
821
822 if (!balance->chargeOkay()) {
823 throwMsg += "Charge";
824 errInfo << " Charge conservation violated by " << balance->deltaQ()
825 << G4endl;
826 }
827
828 errInfo << " Final event output, for debugging:\n"
829 << " Bullet: \n" << *bullet << G4endl
830 << " Target: \n" << *target << G4endl;
831 output->printCollisionOutput(errInfo);
832
833 throwMsg += " non-conservation. More info in output.";
834 throw G4HadronicException(__FILE__, __LINE__, throwMsg); // Job ends here!
835}
std::vector< G4InuclElementaryParticle >::iterator particleIterator
std::vector< G4InuclElementaryParticle >::const_iterator particleIterator
std::vector< G4InuclNuclei >::const_iterator nucleiIterator
@ isAlive
@ stopAndKill
std::vector< G4ReactionProduct * > G4ReactionProductVector
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
const G4double A[17]
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
#define G4UniformRand()
Definition Randomize.hh:52
Hep3Vector unit() const
Hep3Vector vect() const
static void saveEngineStatus(const char filename[]="Config.conf")
Definition Random.cc:278
static const G4CascadeChannel * GetTable(G4int initialState)
void setLimits(G4double relative, G4double absolute)
void collide(G4InuclParticle *bullet, G4InuclParticle *target, G4CollisionOutput &output)
virtual void ModelDescription(std::ostream &outFile) const
G4bool coulombBarrierViolation() const
G4bool retryInelasticNucleus() const
G4HadFinalState * ApplyYourself(const G4HadProjectile &aTrack, G4Nucleus &theNucleus)
G4bool IsApplicable(const G4HadProjectile &aTrack, G4Nucleus &theNucleus)
G4HadFinalState * NoInteraction(const G4HadProjectile &aTrack, G4Nucleus &theNucleus)
G4bool createBullet(const G4HadProjectile &aTrack)
G4bool createTarget(G4Nucleus &theNucleus)
G4ReactionProductVector * copyOutputToReactionProducts()
virtual void DumpConfiguration(std::ostream &outFile) const
void SetVerboseLevel(G4int verbose)
G4ReactionProductVector * Propagate(G4KineticTrackVector *theSecondaries, G4V3DNucleus *theNucleus)
G4bool retryInelasticProton() const
G4DynamicParticle * makeDynamicParticle(const G4InuclElementaryParticle &iep) const
G4CascadeInterface(const G4String &name="BertiniCascade")
static void DumpConfiguration(std::ostream &os)
static G4bool usePreCompound()
G4int numberOfOutgoingParticles() const
const std::vector< G4InuclNuclei > & getOutgoingNuclei() const
void printCollisionOutput(std::ostream &os=G4cout) const
const std::vector< G4InuclElementaryParticle > & getOutgoingParticles() const
void setVerboseLevel(G4int verbose)
G4int numberOfOutgoingNuclei() const
static G4Dineutron * Definition()
static G4Diproton * Definition()
Definition G4Diproton.cc:67
static G4Gamma * Gamma()
Definition G4Gamma.cc:81
void SetStatusChange(G4HadFinalStateStatus aS)
void AddSecondary(G4DynamicParticle *aP, G4int mod=-1)
void SetEnergyChange(G4double anEnergy)
const G4ParticleDefinition * GetDefinition() const
G4double GetKineticEnergy() const
const G4LorentzVector & Get4Momentum() const
void SetVerboseLevel(G4int value)
void SetEnergyMomentumCheckLevels(G4double relativeLevel, G4double absoluteLevel)
void usePreCompoundDeexcitation()
void collide(G4InuclParticle *bullet, G4InuclParticle *target, G4CollisionOutput &globalOutput)
void rescatter(G4InuclParticle *bullet, G4KineticTrackVector *theSecondaries, G4V3DNucleus *theNucleus, G4CollisionOutput &globalOutput)
void setVerboseLevel(G4int verbose=0)
void fill(G4int ityp, Model model=DefaultModel)
void fill(G4int a, G4int z, G4double exc=0., Model model=DefaultModel)
const G4ParticleDefinition * getDefinition() const
G4double getKineticEnergy() const
G4LorentzVector getMomentum() const
G4double getEnergy() const
const G4DynamicParticle & getDynamicParticle() const
static G4KaonZeroLong * Definition()
static G4KaonZeroShort * Definition()
G4double GetFormationTime() const
const G4ThreeVector & GetPosition() const
const G4ParticleDefinition * GetDefinition() const
const G4LorentzVector & Get4Momentum() const
void collide(G4InuclParticle *bullet, G4InuclParticle *target, G4CollisionOutput &globalOutput)
G4int GetA_asInt() const
Definition G4Nucleus.hh:99
G4int GetZ_asInt() const
Definition G4Nucleus.hh:105
G4int GetAtomicNumber() const
G4int GetAtomicMass() const
const G4String & GetParticleName() const
static G4int GetModelID(const G4int modelIndex)
void SetCreatorModelID(const G4int mod)
static G4UnboundPN * Definition()
virtual G4int GetCharge()=0
virtual G4int GetMassNumber()=0
virtual void setVerboseLevel(G4int verbose=0)
const G4HadProjectile * GetPrimaryProjectile() const
const char * name(G4int ptype)
G4bool IsMasterThread()