Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:00

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 #ifndef G4CASCADE_CHECK_BALANCE_HH
0027 #define G4CASCADE_CHECK_BALANCE_HH
0028 //
0029 // Verify and report four-momentum conservation for collision output; uses
0030 // same interface as collision generators.
0031 //
0032 // 20100624  M. Kelsey -- Add baryon conservation check and kinetic energy
0033 // 20100628  M. Kelsey -- Add interface to take list of particles directly
0034 // 20100711  M. Kelsey -- Add name of parent Collider for reporting messages,
0035 //      allow changing parent name, add interface for nuclear fragments
0036 // 20100713  M. Kelsey -- Add (publicly adjustable) tolerance for zeroes
0037 // 20100715  M. Kelsey -- FPE!  Need to check initial values before computing
0038 //      relative error.
0039 // 20100715  M. Kelsey -- Add G4CascadParticle interface for G4NucleiModel;
0040 //      do momentum check on direction, not just magnitude.  Move
0041 //      temporary G4CollisionOutput buffer here, for thread-safety
0042 // 20100909  M. Kelsey -- Add interface to get four-vector difference, and
0043 //      to supply both kinds of particle lists (G4IntraNucleiCascader)
0044 // 20100923  M. Kelsey -- Baryon and charge deltas should have been integer
0045 // 20110328  M. Kelsey -- Add default ctor and explicit limit setting
0046 // 20110722  M. Kelsey -- For IntraNucleiCascader, take G4CollOut as argument
0047 // 20121002  M. Kelsey -- Add strangeness check (useful for Omega- beam)
0048 // 20130620  Address Coverity complaint about missing copy actions
0049 // 20130621  Add interface to take G4Fragment input instead of G4InuclNuclei.
0050 // 20140930  Change name from "const char*" to "const G4String"
0051 
0052 #include "G4VCascadeCollider.hh"
0053 #include "globals.hh"
0054 #include "G4CollisionOutput.hh"
0055 #include "G4LorentzVector.hh"
0056 #include <cmath>
0057 #include <vector>
0058 
0059 class G4CascadParticle;
0060 class G4InuclElementaryParticle;
0061 class G4InuclNuclei;
0062 class G4InuclParticle;
0063 
0064 class G4CascadeCheckBalance : public G4VCascadeCollider {
0065 public:
0066   static const G4double tolerance;  // Don't do floating zero!
0067 
0068   explicit G4CascadeCheckBalance(const G4String& owner="G4CascadeCheckBalance");
0069 
0070   G4CascadeCheckBalance(G4double relative, G4double absolute,
0071             const G4String& owner="G4CascadeCheckBalance");
0072   virtual ~G4CascadeCheckBalance() {};
0073 
0074   void setOwner(const G4String& owner) { setName(owner); }
0075 
0076   void setLimits(G4double relative, G4double absolute) {
0077     setRelativeLimit(relative);
0078     setAbsoluteLimit(absolute);
0079   }
0080 
0081   void setRelativeLimit(G4double limit) { relativeLimit = limit; }
0082   void setAbsoluteLimit(G4double limit) { absoluteLimit = limit; }
0083 
0084   void collide(G4InuclParticle* bullet, G4InuclParticle* target,
0085            G4CollisionOutput& output);
0086 
0087   // This is for use with G4VCascadeDeexcitation modules
0088   void collide(const G4Fragment& fragment, G4CollisionOutput& output);
0089 
0090   // This is for use with G4EPCollider internal checks
0091   void collide(G4InuclParticle* bullet, G4InuclParticle* target,
0092            const std::vector<G4InuclElementaryParticle>& particles);
0093 
0094   // This is for use with G4NucleiModel internal checks
0095   void collide(G4InuclParticle* bullet, G4InuclParticle* target,
0096            const std::vector<G4CascadParticle>& particles);
0097 
0098   // This is for use with G4IntraNucleiCascader
0099   void collide(G4InuclParticle* bullet, G4InuclParticle* target,
0100            G4CollisionOutput& output,
0101            const std::vector<G4CascadParticle>& cparticles);
0102 
0103   // This is for use with G4BigBanger internal checks
0104   void collide(const G4Fragment& target,
0105            const std::vector<G4InuclElementaryParticle>& particles);
0106 
0107   // This is for use with G4Fissioner internal checks
0108   void collide(const G4Fragment& target,
0109            const std::vector<G4InuclNuclei>& fragments);
0110 
0111   // Checks on conservation laws (kinematics, baryon number, charge, hyperons)
0112   G4bool energyOkay() const;
0113   G4bool ekinOkay() const;
0114   G4bool momentumOkay() const;
0115   G4bool baryonOkay() const;
0116   G4bool chargeOkay() const;
0117   G4bool strangeOkay() const;
0118 
0119   // Global check, used by G4CascadeInterface validation loop
0120   // NOTE:  Strangeness is not required to be conserved in final state
0121   G4bool okay() const { return (energyOkay() && momentumOkay() &&
0122                 baryonOkay() && chargeOkay()); }
0123 
0124   // Calculations of conserved quantities from initial and final state
0125   // FIXME:  Relative comparisons don't work for zero!
0126   G4double deltaE() const { return (final.e() - initial.e()); }
0127   G4double relativeE() const {
0128     return ( (std::abs(deltaE())<tolerance) ? 0. : 
0129          (initial.e()<tolerance) ? 1. : deltaE()/initial.e() );
0130   }
0131 
0132   G4double deltaKE() const { return (ekin(final) - ekin(initial)); }
0133   G4double relativeKE() const {
0134     return ( (std::abs(deltaKE())<tolerance) ? 0. : 
0135          (ekin(initial)<tolerance) ? 1. : deltaKE()/ekin(initial) );
0136   }
0137 
0138   G4double deltaP() const { return deltaLV().rho(); }
0139   G4double relativeP() const {
0140     return ( (std::abs(deltaP())<tolerance) ? 0. : 
0141          (initial.rho()<tolerance) ? 1. : deltaP()/initial.rho() );
0142   }
0143 
0144   G4LorentzVector deltaLV() const { return final - initial; }
0145 
0146   // Baryon number, charge, S are discrete; no bounds and no "relative" scale
0147   G4int deltaB() const { return (finalBaryon - initialBaryon); }
0148   G4int deltaQ() const { return (finalCharge - initialCharge); }
0149   G4int deltaS() const { return (finalStrange- initialStrange); }
0150 
0151 protected:
0152   // Utility function for kinetic energy
0153   G4double ekin(const G4LorentzVector& p) const { return (p.e() - p.m()); }
0154 
0155 private:
0156   G4double relativeLimit;   // Fractional bound on conservation
0157   G4double absoluteLimit;   // Absolute (GeV) bound on conservation
0158 
0159   G4LorentzVector initial;  // Four-vectors for computing violations
0160   G4LorentzVector final;
0161 
0162   G4int initialBaryon;      // Total baryon number
0163   G4int finalBaryon;
0164 
0165   G4int initialCharge;      // Total charge
0166   G4int finalCharge;
0167 
0168   G4int initialStrange;     // Total strangeness (s-quark content)
0169   G4int finalStrange;
0170 
0171   G4CollisionOutput tempOutput;     // Buffer for direct-list interfaces
0172 
0173 private:
0174   // Copying of modules is forbidden
0175   G4CascadeCheckBalance(const G4CascadeCheckBalance&);
0176   G4CascadeCheckBalance& operator=(const G4CascadeCheckBalance&);
0177 };
0178 
0179 #endif  /* G4CASCADE_CHECK_BALANCE_HH */