Back to home page

EIC code displayed by LXR

 
 

    


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

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 // INCL++ intra-nuclear cascade model
0027 // Alain Boudard, CEA-Saclay, France
0028 // Joseph Cugnon, University of Liege, Belgium
0029 // Jean-Christophe David, CEA-Saclay, France
0030 // Pekka Kaitaniemi, CEA-Saclay, France, and Helsinki Institute of Physics, Finland
0031 // Sylvie Leray, CEA-Saclay, France
0032 // Davide Mancusi, CEA-Saclay, France
0033 //
0034 #define INCLXX_IN_GEANT4_MODE 1
0035 
0036 #include "globals.hh"
0037 
0038 /** \file G4INCLHornerFormEvaluator.hh
0039  * \brief Template-metaprogramming-based evaluator for polynomials in Horner form
0040  *
0041  * \date 3rd March 2014
0042  * \author Davide Mancusi
0043  */
0044 
0045 #ifndef G4INCLHORNERFORMEVALUATOR_HH
0046 #define G4INCLHORNERFORMEVALUATOR_HH
0047 
0048 namespace G4INCL {
0049 
0050   template<G4int N>
0051     class HornerCoefficients {
0052       protected:
0053         G4double a[N];
0054       public:
0055         G4double &operator[](G4int i) { return a[i]; }
0056         const G4double &operator[](G4int i) const { return a[i]; }
0057     };
0058 
0059   struct HornerC1 : public HornerCoefficients<1> {
0060     HornerC1(
0061              const G4double a0
0062             ) {
0063       a[0] = a0;
0064     }
0065   };
0066 
0067   struct HornerC2 : public HornerCoefficients<2> {
0068     HornerC2(
0069              const G4double a0,
0070              const G4double a1
0071             ) {
0072       a[0] = a0;
0073       a[1] = a1;
0074     }
0075   };
0076 
0077   struct HornerC3 : public HornerCoefficients<3> {
0078     HornerC3(
0079              const G4double a0,
0080              const G4double a1,
0081              const G4double a2
0082             ) {
0083       a[0] = a0;
0084       a[1] = a1;
0085       a[2] = a2;
0086     }
0087   };
0088 
0089   struct HornerC4 : public HornerCoefficients<4> {
0090     HornerC4(
0091              const G4double a0,
0092              const G4double a1,
0093              const G4double a2,
0094              const G4double a3
0095             ) {
0096       a[0] = a0;
0097       a[1] = a1;
0098       a[2] = a2;
0099       a[3] = a3;
0100     }
0101   };
0102 
0103   struct HornerC5 : public HornerCoefficients<5> {
0104     HornerC5(
0105              const G4double a0,
0106              const G4double a1,
0107              const G4double a2,
0108              const G4double a3,
0109              const G4double a4
0110             ) {
0111       a[0] = a0;
0112       a[1] = a1;
0113       a[2] = a2;
0114       a[3] = a3;
0115       a[4] = a4;
0116     }
0117   };
0118 
0119   struct HornerC6 : public HornerCoefficients<6> {
0120     HornerC6(
0121              const G4double a0,
0122              const G4double a1,
0123              const G4double a2,
0124              const G4double a3,
0125              const G4double a4,
0126              const G4double a5
0127             ) {
0128       a[0] = a0;
0129       a[1] = a1;
0130       a[2] = a2;
0131       a[3] = a3;
0132       a[4] = a4;
0133       a[5] = a5;
0134     }
0135   };
0136 
0137   struct HornerC7 : public HornerCoefficients<7> {
0138     HornerC7(
0139              const G4double a0,
0140              const G4double a1,
0141              const G4double a2,
0142              const G4double a3,
0143              const G4double a4,
0144              const G4double a5,
0145              const G4double a6
0146             ) {
0147       a[0] = a0;
0148       a[1] = a1;
0149       a[2] = a2;
0150       a[3] = a3;
0151       a[4] = a4;
0152       a[5] = a5;
0153       a[6] = a6;
0154     }
0155   };
0156 
0157   struct HornerC8 : public HornerCoefficients<8> {
0158     HornerC8(
0159              const G4double a0,
0160              const G4double a1,
0161              const G4double a2,
0162              const G4double a3,
0163              const G4double a4,
0164              const G4double a5,
0165              const G4double a6,
0166              const G4double a7
0167             ) {
0168       a[0] = a0;
0169       a[1] = a1;
0170       a[2] = a2;
0171       a[3] = a3;
0172       a[4] = a4;
0173       a[5] = a5;
0174       a[6] = a6;
0175       a[7] = a7;
0176     }
0177   };
0178 
0179   template<G4int M>
0180     struct HornerEvaluator {
0181       template<G4int N>
0182         static G4double eval(const G4double x, HornerCoefficients<N> const &coeffs) {
0183           return coeffs[N-M] + x * HornerEvaluator<M-1>::eval(x, coeffs);
0184         }
0185     };
0186 
0187   template<>
0188     struct HornerEvaluator<1> {
0189       template<G4int N>
0190         static G4double eval(const G4double, HornerCoefficients<N> const &coeffs) {
0191           return coeffs[N-1];
0192         }
0193     };
0194 
0195 }
0196 
0197 #endif