G4CascadeCheckBalance.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 #ifndef G4CASCADE_CHECK_BALANCE_HH
00027 #define G4CASCADE_CHECK_BALANCE_HH
00028 // $Id$
00029 //
00030 // Verify and report four-momentum conservation for collision output; uses
00031 // same interface as collision generators.
00032 //
00033 // 20100624  M. Kelsey -- Add baryon conservation check and kinetic energy
00034 // 20100628  M. Kelsey -- Add interface to take list of particles directly
00035 // 20100711  M. Kelsey -- Add name of parent Collider for reporting messages,
00036 //              allow changing parent name, add interface for nuclear fragments
00037 // 20100713  M. Kelsey -- Add (publicly adjustable) tolerance for zeroes
00038 // 20100715  M. Kelsey -- FPE!  Need to check initial values before computing
00039 //              relative error.
00040 // 20100715  M. Kelsey -- Add G4CascadParticle interface for G4NucleiModel;
00041 //              do momentum check on direction, not just magnitude.  Move
00042 //              temporary G4CollisionOutput buffer here, for thread-safety
00043 // 20100909  M. Kelsey -- Add interface to get four-vector difference, and
00044 //              to supply both kinds of particle lists (G4IntraNucleiCascader)
00045 // 20100923  M. Kelsey -- Baryon and charge deltas should have been integer
00046 // 20110328  M. Kelsey -- Add default ctor and explicit limit setting
00047 // 20110722  M. Kelsey -- For IntraNucleiCascader, take G4CollOut as argument
00048 // 20121002  M. Kelsey -- Add strangeness check (useful for Omega- beam)
00049 
00050 #include "G4VCascadeCollider.hh"
00051 #include "globals.hh"
00052 #include "G4CollisionOutput.hh"
00053 #include "G4LorentzVector.hh"
00054 #include <cmath>
00055 #include <vector>
00056 
00057 class G4CascadParticle;
00058 class G4InuclElementaryParticle;
00059 class G4InuclNuclei;
00060 class G4InuclParticle;
00061 
00062 class G4CascadeCheckBalance : public G4VCascadeCollider {
00063 public:
00064   static const G4double tolerance;      // Don't do floating zero!
00065 
00066   explicit G4CascadeCheckBalance(const char* owner="G4CascadeCheckBalance");
00067 
00068   G4CascadeCheckBalance(G4double relative, G4double absolute,
00069                         const char* owner="G4CascadeCheckBalance");
00070   virtual ~G4CascadeCheckBalance() {};
00071 
00072   void setOwner(const char* owner) { setName(owner); }
00073 
00074   void setLimits(G4double relative, G4double absolute) {
00075     setRelativeLimit(relative);
00076     setAbsoluteLimit(absolute);
00077   }
00078 
00079   void setRelativeLimit(G4double limit) { relativeLimit = limit; }
00080   void setAbsoluteLimit(G4double limit) { absoluteLimit = limit; }
00081 
00082   void collide(G4InuclParticle* bullet, G4InuclParticle* target,
00083                G4CollisionOutput& output);
00084 
00085   // This is for use with G4EPCollider internal checks
00086   void collide(G4InuclParticle* bullet, G4InuclParticle* target,
00087                const std::vector<G4InuclElementaryParticle>& particles);
00088 
00089   // This is for use with G4Fissioner internal checks
00090   void collide(G4InuclParticle* bullet, G4InuclParticle* target,
00091                const std::vector<G4InuclNuclei>& fragments);
00092 
00093   // This is for use with G4NucleiModel internal checks
00094   void collide(G4InuclParticle* bullet, G4InuclParticle* target,
00095                const std::vector<G4CascadParticle>& particles);
00096 
00097   // This is for use with G4IntraNucleiCascader
00098   void collide(G4InuclParticle* bullet, G4InuclParticle* target,
00099                G4CollisionOutput& output,
00100                const std::vector<G4CascadParticle>& cparticles);
00101 
00102   // Checks on conservation laws (kinematics, baryon number, charge, hyperons)
00103   G4bool energyOkay() const;
00104   G4bool ekinOkay() const;
00105   G4bool momentumOkay() const;
00106   G4bool baryonOkay() const;
00107   G4bool chargeOkay() const;
00108   G4bool strangeOkay() const;
00109 
00110   // Global check, used by G4CascadeInterface validation loop
00111   // NOTE:  Strangeness is not required to be conserved in final state
00112   G4bool okay() const { return (energyOkay() && momentumOkay() &&
00113                                 baryonOkay() && chargeOkay()); }
00114 
00115   // Calculations of conserved quantities from initial and final state
00116   // FIXME:  Relative comparisons don't work for zero!
00117   G4double deltaE() const { return (final.e() - initial.e()); }
00118   G4double relativeE() const {
00119     return ( (std::abs(deltaE())<tolerance) ? 0. : 
00120              (initial.e()<tolerance) ? 1. : deltaE()/initial.e() );
00121   }
00122 
00123   G4double deltaKE() const { return (ekin(final) - ekin(initial)); }
00124   G4double relativeKE() const {
00125     return ( (std::abs(deltaKE())<tolerance) ? 0. : 
00126              (ekin(initial)<tolerance) ? 1. : deltaKE()/ekin(initial) );
00127   }
00128 
00129   G4double deltaP() const { return deltaLV().rho(); }
00130   G4double relativeP() const {
00131     return ( (std::abs(deltaP())<tolerance) ? 0. : 
00132              (initial.rho()<tolerance) ? 1. : deltaP()/initial.rho() );
00133   }
00134 
00135   G4LorentzVector deltaLV() const { return final - initial; }
00136 
00137   // Baryon number, charge, S are discrete; no bounds and no "relative" scale
00138   G4int deltaB() const { return (finalBaryon - initialBaryon); }
00139   G4int deltaQ() const { return (finalCharge - initialCharge); }
00140   G4int deltaS() const { return (finalStrange- initialStrange); }
00141 
00142 protected:
00143   // Utility function for kinetic energy
00144   G4double ekin(const G4LorentzVector& p) const { return (p.e() - p.m()); }
00145 
00146 private:
00147   G4double relativeLimit;       // Fractional bound on conservation
00148   G4double absoluteLimit;       // Absolute (GeV) bound on conservation
00149 
00150   G4LorentzVector initial;      // Four-vectors for computing violations
00151   G4LorentzVector final;
00152 
00153   G4int initialBaryon;          // Total baryon number
00154   G4int finalBaryon;
00155 
00156   G4int initialCharge;          // Total charge
00157   G4int finalCharge;
00158 
00159   G4int initialStrange;         // Total strangeness (s-quark content)
00160   G4int finalStrange;
00161 
00162   G4CollisionOutput tempOutput;         // Buffer for direct-list interfaces
00163 };
00164 
00165 #endif  /* G4CASCADE_CHECK_BALANCE_HH */

Generated on Mon May 27 17:47:49 2013 for Geant4 by  doxygen 1.4.7