Back to home page

EIC code displayed by LXR

 
 

    


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

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 //
0027 //
0028 #ifndef G4InterpolationManager_h
0029 #define G4InterpolationManager_h 1
0030 
0031 #include "G4HadronicException.hh"
0032 #include "G4InterpolationScheme.hh"
0033 #include "G4ios.hh"
0034 #include "globals.hh"
0035 
0036 #include <fstream>
0037 
0038 class G4InterpolationManager
0039 {
0040   public:
0041     friend class G4InterpolationIterator;
0042 
0043     G4InterpolationManager()
0044     {
0045       nRanges = 1;
0046       start = new G4int[1];
0047       start[0] = 0;
0048       range = new G4int[1];
0049       range[0] = 100000;
0050       scheme = new G4InterpolationScheme[1];
0051       scheme[0] = LINLIN;
0052       nEntries = 0;
0053     }
0054 
0055     ~G4InterpolationManager()
0056     {
0057       delete[] start;
0058       delete[] range;
0059       delete[] scheme;
0060     }
0061 
0062     G4InterpolationManager& operator=(const G4InterpolationManager& aManager)
0063     {
0064       if (this != &aManager) {
0065         nRanges = aManager.nRanges;
0066         nEntries = aManager.nEntries;
0067         delete[] scheme;
0068         delete[] start;
0069         delete[] range;
0070         scheme = new G4InterpolationScheme[nRanges];
0071         start = new G4int[nRanges];
0072         range = new G4int[nRanges];
0073         for (G4int i = 0; i < nRanges; i++) {
0074           scheme[i] = aManager.scheme[i];
0075           start[i] = aManager.start[i];
0076           range[i] = aManager.range[i];
0077         }
0078       }
0079       return *this;
0080     }
0081 
0082     inline void Init(G4int aScheme, G4int aRange)
0083     {
0084       nRanges = 1;
0085       start[0] = 0;
0086       range[0] = aRange;
0087       scheme[0] = MakeScheme(aScheme);
0088       nEntries = aRange;
0089     }
0090     inline void Init(G4InterpolationScheme aScheme, G4int aRange)
0091     {
0092       nRanges = 1;
0093       start[0] = 0;
0094       range[0] = aRange;
0095       scheme[0] = aScheme;
0096       nEntries = aRange;
0097     }
0098 
0099     inline void Init(std::istream& aDataFile)
0100     {
0101       delete[] start;
0102       delete[] range;
0103       delete[] scheme;
0104       aDataFile >> nRanges;
0105       start = new G4int[nRanges];
0106       range = new G4int[nRanges];
0107       scheme = new G4InterpolationScheme[nRanges];
0108       start[0] = 0;
0109       G4int it;
0110       for (G4int i = 0; i < nRanges; i++) {
0111         aDataFile >> range[i];
0112         //***************************************************************
0113         // EMendoza -> there is a bug here.
0114         /*
0115         if(i!=0) start[i] = start[i-1]+range[i-1];
0116         */
0117         //***************************************************************
0118         if (i != 0) start[i] = range[i - 1];
0119         //***************************************************************
0120         aDataFile >> it;
0121         scheme[i] = MakeScheme(it);
0122       }
0123       nEntries = start[nRanges - 1] + range[nRanges - 1];
0124     }
0125 
0126     G4InterpolationScheme MakeScheme(G4int it);
0127 
0128     inline G4InterpolationScheme GetScheme(G4int index) const
0129     {
0130       G4int it = 0;
0131       for (G4int i = 1; i < nRanges; i++) {
0132         if (index < start[i]) break;
0133         it = i;
0134       }
0135       return scheme[it];
0136     }
0137 
0138     inline void CleanUp()
0139     {
0140       nRanges = 0;
0141       nEntries = 0;
0142     }
0143 
0144     inline G4InterpolationScheme GetInverseScheme(G4int index)
0145     {
0146       G4InterpolationScheme result = GetScheme(index);
0147       if (result == HISTO) {
0148         result = RANDOM;
0149       }
0150       else if (result == LINLOG) {
0151         result = LOGLIN;
0152       }
0153       else if (result == LOGLIN) {
0154         result = LINLOG;
0155       }
0156       else if (result == CHISTO) {
0157         result = CRANDOM;
0158       }
0159       else if (result == CLINLOG) {
0160         result = CLOGLIN;
0161       }
0162       else if (result == CLOGLIN) {
0163         result = CLINLOG;
0164       }
0165       else if (result == UHISTO) {
0166         result = URANDOM;
0167       }
0168       else if (result == ULINLOG) {
0169         result = ULOGLIN;
0170       }
0171       else if (result == ULOGLIN) {
0172         result = ULINLOG;
0173       }
0174       return result;
0175     }
0176 
0177     void AppendScheme(G4int aPoint, const G4InterpolationScheme& aScheme);
0178 
0179   private:
0180     G4int nRanges;
0181     G4InterpolationScheme* scheme;
0182     G4int* start;
0183     G4int* range;
0184     G4int nEntries;
0185 };
0186 #endif