G4LevelReader.cc

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 // $Id$
00027 //
00028 // -------------------------------------------------------------------
00029 //
00030 //      GEANT4 header file 
00031 //
00032 //      File name:     G4NucLevel
00033 //
00034 //      Author:        V.Ivanchenko (M.Kelsey reading method is used)
00035 // 
00036 //      Creation date: 4 January 2012
00037 //
00038 //      Modifications:
00039 //      
00040 // -------------------------------------------------------------------
00041 
00042 #include "G4LevelReader.hh"
00043 #include "G4NucLevel.hh"
00044 #include "G4SystemOfUnits.hh"
00045 
00046 G4LevelReader::G4LevelReader() 
00047   : nLevels(0),nLevelMax(50),fVerbose(0),fMinProbability(1.e-10)
00048 {
00049   fLevelEnergy = fNewEnergy = fDeltaEnergy = fNewTime 
00050     = fHalfLifeTime = fProbability = fICC = fx = 0.0;
00051   eGamma.resize(nLevelMax,0.0);
00052   wGamma.resize(nLevelMax,0.0);
00053   kICC.resize(nLevelMax,0.0);
00054   for(G4int i=0; i<30; ++i) { buffer[i] = 0; }
00055 }
00056 
00057 G4LevelReader::~G4LevelReader() 
00058 {}
00059 
00060 void G4LevelReader::FillLevels(G4int Z, G4int A,
00061                                std::vector<G4NucLevel*>* levels,
00062                                const G4String& filename) 
00063 { 
00064   std::ifstream inFile(filename);
00065   if (!inFile.is_open()) {
00066     if (fVerbose > 0) {
00067       G4cout << " G4LevelReader: nuclide (" 
00068              << Z << "," << A 
00069              << ") does not have a gamma levels file" << G4endl;
00070     }
00071     return;
00072   }
00073 
00074   // Read file with gamma data and fill levels
00075   fLevelEnergy = 0.0;
00076   nLevels = 0;
00077      
00078   // read next line
00079   while(Read(inFile)) {
00080 
00081     // create new level and start fill the next
00082     if(fNewEnergy != fLevelEnergy) {
00083       if(0 < nLevels) { MakeNewLevel(levels); }
00084       fLevelEnergy = fNewEnergy;
00085       fHalfLifeTime = fNewTime;
00086       nLevels = 0;
00087     }
00088 
00089     // fill data on a new daughter level
00090     eGamma[nLevels] = fDeltaEnergy*keV;
00091     wGamma[nLevels] = std::max(fProbability*0.01,fMinProbability);
00092     kICC[nLevels]   = fICC;
00093     ++nLevels;
00094 
00095     // check buffer size - should never happen
00096     if(nLevels > nLevelMax) {
00097       nLevelMax += 10;
00098       eGamma.resize(nLevelMax);
00099       wGamma.resize(nLevelMax);
00100       kICC.resize(nLevelMax);
00101     }
00102   }
00103   // end of reading
00104   if(0 < nLevels) {
00105     MakeNewLevel(levels);
00106     inFile.close();
00107   }
00108 }
00109 
00110 G4bool G4LevelReader::Read(std::ifstream& dataFile) 
00111 {  
00112   // Each item will return iostream status
00113   return (ReadDataItem(dataFile, fNewEnergy) &&
00114           ReadDataItem(dataFile, fDeltaEnergy) &&
00115           ReadDataItem(dataFile, fProbability) &&
00116           ReadDataItem(dataFile, fx) &&
00117           ReadDataItem(dataFile, fNewTime) &&
00118           ReadDataItem(dataFile, fx) &&
00119           ReadDataItem(dataFile, fICC) &&
00120           ReadDataItem(dataFile, fx) &&
00121           ReadDataItem(dataFile, fx) &&
00122           ReadDataItem(dataFile, fx) &&
00123           ReadDataItem(dataFile, fx) &&
00124           ReadDataItem(dataFile, fx) &&
00125           ReadDataItem(dataFile, fx) &&
00126           ReadDataItem(dataFile, fx) &&
00127           ReadDataItem(dataFile, fx) &&
00128           ReadDataItem(dataFile, fx) &&
00129           ReadDataItem(dataFile, fx) );
00130 }
00131 
00132 G4bool 
00133 G4LevelReader::ReadDataItem(std::istream& dataFile, G4double& x) 
00134 {
00135   G4bool okay = (dataFile >> buffer);           // Get next token
00136   if (okay) x = strtod(buffer, NULL);
00137 
00138   return okay;
00139 }
00140 
00141 void G4LevelReader::MakeNewLevel(std::vector<G4NucLevel*>* levels)
00142 {
00143   // first normalize probabilities
00144   G4double norm = 0.0;
00145   for(size_t i=0; i<nLevels; ++i) { norm +=  wGamma[i]; }
00146 
00147   // should never happen
00148   if(norm <= 0.0) { return; }
00149 
00150   norm = 1.0/norm;
00151   for(size_t i=0; i<nLevels; ++i) { wGamma[i] *= norm; }
00152 
00153   // correct probabilities on ICC factor
00154   norm = 0.0;
00155   for(size_t i=0; i<nLevels; ++i) { 
00156     wGamma[i] /= (1.0 + kICC[i]);
00157     norm += wGamma[i]; 
00158   }
00159   norm = 1.0/norm;
00160   fHalfLifeTime *= norm*second;
00161 
00162   // cumulative sum
00163   if(1 == nLevels) {
00164     wGamma[0] = 1.0;
00165   } else if(2 == nLevels) {
00166     wGamma[0] *= norm;
00167     wGamma[1] = 1.0;
00168   } else {
00169     wGamma[0] *= norm;
00170     for(size_t i=1; i<nLevels-1; ++i) { 
00171       wGamma[i] = wGamma[i]*norm + wGamma[i-1];
00172     }
00173     wGamma[nLevels-1] = 1.0;
00174   }
00175   G4NucLevel* p = new G4NucLevel(fLevelEnergy, fHalfLifeTime,
00176                                  eGamma, wGamma);
00177   levels->push_back(p);
00178   return;
00179 }
00180 

Generated on Mon May 27 17:48:46 2013 for Geant4 by  doxygen 1.4.7