Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4CascadeCheckBalance.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$
27//
28// Verify and report four-momentum conservation for collision output; uses
29// same interface as collision generators.
30//
31// 20100624 M. Kelsey -- Add baryon number, charge, and kinetic energy
32// 20100624 M. Kelsey -- Bug fix: All checks should be |delta| !
33// 20100627 M. Kelsey -- Always report violations on cerr, regardless of
34// verbosity.
35// 20100628 M. Kelsey -- Add interface to take list of particles directly,
36// bug fix reporting of charge conservation error.
37// 20100630 M. Kelsey -- for nuclei, include excitation energies in total.
38// 20100701 M. Kelsey -- Undo previous change, handled by G4InuclNuclei.
39// 20100711 M. Kelsey -- Use name of parent collider for reporting messages
40// 20100713 M. kelsey -- Hide conservation errors behind verbosity
41// 20100715 M. Kelsey -- Use new G4CollisionOutput totals instead of loops,
42// move temporary buffer to be data member
43// 20100719 M. Kelsey -- Change zero tolerance to 10 keV instead of 1 keV.
44// 20100909 M. Kelsey -- Add interface for both kinds of particle lists
45// 20101019 M. Kelsey -- CoVerity report: unitialized constructor
46// 20110328 M. Kelsey -- Add default ctor and explicit limit setting
47// 20110722 M. Kelsey -- For IntraNucleiCascader, take G4CollOut as argument
48// 20120525 M. Kelsey -- Follow process-level checking: allow _either_ rel.
49// or abs. to pass (instead of requiring both)
50// 20121002 M. Kelsey -- Add strangeness check (useful for Omega- beam)
51
53#include "globals.hh"
54#include "G4CascadParticle.hh"
56#include "G4InuclNuclei.hh"
57#include "G4InuclParticle.hh"
58#include "G4CollisionOutput.hh"
59#include "G4LorentzVector.hh"
60#include <vector>
61
62
63// Constructor sets acceptance limits
64
65const G4double G4CascadeCheckBalance::tolerance = 1e-6; // How small is zero?
66
68 : G4VCascadeCollider(owner), relativeLimit(G4CascadeCheckBalance::tolerance),
69 absoluteLimit(G4CascadeCheckBalance::tolerance), initialBaryon(0),
70 finalBaryon(0), initialCharge(0), finalCharge(0), initialStrange(0),
71 finalStrange(0) {}
72
74 G4double absolute,
75 const char* owner)
76 : G4VCascadeCollider(owner), relativeLimit(relative),
77 absoluteLimit(absolute), initialBaryon(0), finalBaryon(0),
78 initialCharge(0), finalCharge(0), initialStrange(0),
79 finalStrange(0) {}
80
81
82// Pseudo-collision just computes input and output four-vectors
83
85 G4InuclParticle* target,
86 G4CollisionOutput& output) {
87 if (verboseLevel)
88 G4cout << " >>> G4CascadeCheckBalance(" << theName << ")::collide"
89 << G4endl;
90
91 initial *= 0.; // Fast reset; some colliders only have one pointer
92 if (bullet) initial += bullet->getMomentum();
93 if (target) initial += target->getMomentum();
94
95 // Baryon number, charge and strangeness must be computed "by hand"
96 initialCharge = 0;
97 if (bullet) initialCharge += G4int(bullet->getCharge());
98 if (target) initialCharge += G4int(target->getCharge());
99
101 dynamic_cast<G4InuclElementaryParticle*>(bullet);
103 dynamic_cast<G4InuclElementaryParticle*>(target);
104
105 G4InuclNuclei* nbullet = dynamic_cast<G4InuclNuclei*>(bullet);
106 G4InuclNuclei* ntarget = dynamic_cast<G4InuclNuclei*>(target);
107
108 initialBaryon =
109 ((pbullet ? pbullet->baryon() : nbullet ? nbullet->getA() : 0) +
110 (ptarget ? ptarget->baryon() : ntarget ? ntarget->getA() : 0) );
111
112 // NOTE: Currently we ignore possibility of hypernucleus target
113 initialStrange = 0;
114 if (pbullet) initialStrange += pbullet->getStrangeness();
115 if (ptarget) initialStrange += ptarget->getStrangeness();
116
117 // Final state totals are computed for us
118 final = output.getTotalOutputMomentum();
119 finalBaryon = output.getTotalBaryonNumber();
120 finalCharge = output.getTotalCharge();
121 finalStrange = output.getTotalStrangeness();
122
123 // Report results
124 if (verboseLevel) {
125 G4cout << " initial px " << initial.px() << " py " << initial.py()
126 << " pz " << initial.pz() << " E " << initial.e()
127 << " baryon " << initialBaryon << " charge " << initialCharge
128 << " strange " << initialStrange << G4endl
129 << " final px " << final.px() << " py " << final.py()
130 << " pz " << final.pz() << " E " << final.e()
131 << " baryon " << finalBaryon << " charge " << finalCharge
132 << " strange " << finalStrange << G4endl;
133 }
134}
135
136// Take list of output particles directly (e.g., from G4EPCollider internals)
137
139 G4InuclParticle* target,
140 const std::vector<G4InuclElementaryParticle>& particles) {
141 if (verboseLevel)
142 G4cout << " >>> G4CascadeCheckBalance(" << theName << ")::collide(<vector>)"
143 << G4endl;
144
145 tempOutput.reset(); // Buffer for processing
146 tempOutput.addOutgoingParticles(particles);
147 collide(bullet, target, tempOutput);
148}
149
150
151// Take list of nuclear fragments directly (e.g., from G4Fissioner internals)
152
154 G4InuclParticle* target,
155 const std::vector<G4InuclNuclei>& fragments) {
156 if (verboseLevel)
157 G4cout << " >>> G4CascadeCheckBalance(" << theName << ")::collide(<vector>)"
158 << G4endl;
159
160 tempOutput.reset(); // Buffer for processing
161 tempOutput.addOutgoingNuclei(fragments);
162 collide(bullet, target, tempOutput);
163}
164
165
166// Take list of "cparticles" (e.g., from G4NucleiModel internals)
167
169 G4InuclParticle* target,
170 const std::vector<G4CascadParticle>& particles) {
171 if (verboseLevel)
172 G4cout << " >>> G4CascadeCheckBalance(" << theName
173 << ")::collide(<cparticles>)" << G4endl;
174
175 tempOutput.reset(); // Buffer for processing
176 tempOutput.addOutgoingParticles(particles);
177 collide(bullet, target, tempOutput);
178}
179
180
181// Take lists of both G4InuclEP & G4CP (e.g., from G4IntraNucleiCascader)
182
184 G4InuclParticle* target,
185 G4CollisionOutput& output,
186 const std::vector<G4CascadParticle>& cparticles) {
187 if (verboseLevel)
188 G4cout << " >>> G4CascadeCheckBalance(" << theName
189 << ")::collide(<EP>,<CP>)" << G4endl;
190
191 tempOutput.reset(); // Buffer for processing
192 tempOutput.add(output);
193 tempOutput.addOutgoingParticles(cparticles);
194 collide(bullet, target, tempOutput);
195}
196
197
198// Compare relative and absolute violations to limits, and report
199
201 G4bool relokay = (std::abs(relativeE()) < relativeLimit);
202 G4bool absokay = (std::abs(deltaE()) < absoluteLimit);
203
204 if (verboseLevel && !(relokay || absokay)) {
205 G4cerr << theName << ": Energy conservation: relative " << relativeE()
206 << (relokay ? " conserved" : " VIOLATED")
207 << " absolute " << deltaE()
208 << (absokay ? " conserved" : " VIOLATED") << G4endl;
209 } else if (verboseLevel > 1) {
210 G4cout << theName << ": Energy conservation: relative " << relativeE()
211 << " conserved absolute " << deltaE() << " conserved" << G4endl;
212 }
213
214 return (relokay && absokay);
215}
216
218 G4bool relokay = (std::abs(relativeKE()) < relativeLimit);
219 G4bool absokay = (std::abs(deltaKE()) < absoluteLimit);
220
221 if (verboseLevel && !(relokay || absokay)) {
222 G4cerr << theName << ": Kinetic energy balance: relative "
223 << relativeKE() << (relokay ? " conserved" : " VIOLATED")
224 << " absolute " << deltaKE()
225 << (absokay ? " conserved" : " VIOLATED") << G4endl;
226 } else if (verboseLevel > 1) {
227 G4cout << theName << ": Kinetic energy balance: relative "
228 << relativeKE() << " conserved absolute " << deltaKE()
229 << " conserved" << G4endl;
230 }
231
232 return (relokay && absokay);
233}
234
236 G4bool relokay = (std::abs(relativeP()) < relativeLimit);
237 G4bool absokay = (std::abs(deltaP()) < absoluteLimit);
238
239 if (verboseLevel && !(relokay || absokay)) {
240 G4cerr << theName << ": Momentum conservation: relative " << relativeP()
241 << (relokay ? " conserved" : " VIOLATED")
242 << " absolute " << deltaP()
243 << (absokay ? " conserved" : " VIOLATED") << G4endl;
244 } else if (verboseLevel > 1) {
245 G4cout << theName << ": Momentum conservation: relative " << relativeP()
246 << " conserved absolute " << deltaP() << " conserved" << G4endl;
247 }
248
249 return (relokay && absokay);
250}
251
253 G4bool bokay = (deltaB() == 0); // Must be perfect!
254
255 if (verboseLevel && !bokay)
256 G4cerr << theName << ": Baryon number VIOLATED " << deltaB() << G4endl;
257
258 return bokay;
259}
260
262 G4bool qokay = (deltaQ() == 0); // Must be perfect!
263
264 if (verboseLevel && !qokay)
265 G4cerr << theName << ": Charge conservation VIOLATED " << deltaQ()
266 << G4endl;
267
268 return qokay;
269}
270
272 G4bool sokay = (deltaS() == 0); // Must be perfect!
273
274 if (verboseLevel && !sokay)
275 G4cerr << theName << ": Strangeness conservation VIOLATED " << deltaS()
276 << G4endl;
277
278 return sokay;
279}
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
void collide(G4InuclParticle *bullet, G4InuclParticle *target, G4CollisionOutput &output)
static const G4double tolerance
G4CascadeCheckBalance(const char *owner="G4CascadeCheckBalance")
G4int getTotalStrangeness() const
G4LorentzVector getTotalOutputMomentum() const
G4int getTotalBaryonNumber() const
G4int getTotalCharge() const
void add(const G4CollisionOutput &right)
void addOutgoingNuclei(const std::vector< G4InuclNuclei > &nuclea)
void addOutgoingParticles(const std::vector< G4InuclElementaryParticle > &particles)
G4int getA() const
G4LorentzVector getMomentum() const
G4double getCharge() const