// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // // $Id: G4DNATotalCrossSectionFromFilePolicy.icc,v 1.4 2006/06/29 19:35:29 gunter Exp $ // GEANT4 tag $Name: geant4-09-00 $ // #ifdef G4DNATOTALCROSSSECTIONFROMFILEPOLICY_HH #include "G4Electron.hh" #include "Randomize.hh" template G4DNATotalCrossSectionFromFilePolicy :: G4DNATotalCrossSectionFromFilePolicy() : dataset(0), valuesBuffer(0) { } template G4DNATotalCrossSectionFromFilePolicy :: ~G4DNATotalCrossSectionFromFilePolicy() { Free(); } template G4double G4DNATotalCrossSectionFromFilePolicy :: TotalCrossSection(G4double k, G4int /* z */) const { if (!dataset) { G4Exception("G4DNATotalCrossSectionFromFilePolicy<>::TotalCrossSection: dataset not loaded"); return 0; } if (k < dataFilePolicy.lowEnergyLimit) { if (dataFilePolicy.zeroBelowLowEnergyLimit) return 0; k=dataFilePolicy.lowEnergyLimit; } else if (k > dataFilePolicy.highEnergyLimit) { if (dataFilePolicy.zeroAboveHighEnergyLimit) return 0; k=dataFilePolicy.highEnergyLimit; } return dataset->FindValue(k); } template G4int G4DNATotalCrossSectionFromFilePolicy :: RandomizePartialCrossSection(G4double k, G4int /* z */) { if (!dataset) { G4Exception("G4DNATotalCrossSectionFromFilePolicy<>::RandomizePartialCrossSection: dataset not loaded"); return 0; } const size_t n(dataset->NumberOfComponents()); size_t i(n); G4double value(0); while (i>0) { i--; valuesBuffer[i]=dataset->GetComponent(i)->FindValue(k); value+=valuesBuffer[i]; } value*=G4UniformRand(); i=n; while (i>0) { i--; if (valuesBuffer[i]>value) return i; value-=valuesBuffer[i]; } return 0; } template G4int G4DNATotalCrossSectionFromFilePolicy :: NumberOfPartialCrossSections(void) { if (!dataset) { G4Exception("G4DNATotalCrossSectionFromFilePolicy<>::NumberOfPartialCrossSections: dataset not loaded"); return 0; } return dataset->NumberOfComponents(); } template void G4DNATotalCrossSectionFromFilePolicy :: BuildTotalCrossSection(void) { Free(); dataset=new G4DNACrossSectionDataSet(new InterpolationAlgorithmPolicy, dataFilePolicy.dataFileEnergyUnit, dataFilePolicy.dataFileCrossSectionUnit); dataset->LoadData(dataFilePolicy.dataFileName); valuesBuffer=new G4double[dataset->NumberOfComponents()]; } template void G4DNATotalCrossSectionFromFilePolicy :: Free(void) { if (dataset) delete dataset; if (valuesBuffer) delete[] valuesBuffer; } #endif /* G4DNATOTALCROSSSECTIONFROMFILEPOLICY_HH */