G4FluoData.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 //
00027 //
00028 // Author: Elena Guardincerri (Elena.Guardincerri@ge.infn.it)
00029 //
00030 // History:
00031 // -----------
00032 // 16 Sept 2001  First committed to cvs
00033 //
00034 // -------------------------------------------------------------------
00035 
00036 #include <fstream>
00037 #include <sstream>
00038 
00039 #include "G4FluoData.hh"
00040 #include "G4SystemOfUnits.hh"
00041 #include "G4DataVector.hh"
00042 #include "G4FluoTransition.hh"
00043 
00044 G4FluoData::G4FluoData()
00045 {
00046   numberOfVacancies=0; 
00047 }
00048 
00049 G4FluoData::~G4FluoData()
00050 { 
00051  std::map<G4int,G4DataVector*,std::less<G4int> >::iterator pos;
00052 
00053   for (pos = idMap.begin(); pos != idMap.end(); ++pos)
00054     {
00055       G4DataVector* dataSet = (*pos).second;
00056       delete dataSet;
00057     }
00058   for (pos = energyMap.begin(); pos != energyMap.end(); ++pos)
00059     {
00060       G4DataVector* dataSet = (*pos).second;
00061       delete dataSet;
00062     }
00063  for (pos = probabilityMap.begin(); pos != probabilityMap.end(); ++pos)
00064     {
00065       G4DataVector* dataSet = (*pos).second;
00066       delete dataSet;
00067     }
00068 }
00069 
00070 size_t G4FluoData::NumberOfVacancies() const
00071 {
00072   return numberOfVacancies;
00073 }
00074 
00075 G4int G4FluoData::VacancyId(G4int vacancyIndex) const
00076 {
00077   G4int n = -1;
00078   if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies)
00079     {G4Exception("G4FluoData::vacancyId()","de0002",FatalErrorInArgument,"vacancyIndex outside boundaries");}
00080   else
00081     {
00082       std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator pos;
00083       pos = idMap.find(vacancyIndex);
00084       if (pos!= idMap.end())
00085         { G4DataVector dataSet = (*(*pos).second);
00086         n = (G4int) dataSet[0];
00087         
00088         }
00089     }
00090   return n;
00091 }
00092 
00093 size_t G4FluoData::NumberOfTransitions(G4int vacancyIndex) const
00094 {
00095   G4int n = 0;
00096   if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies)
00097     {
00098       G4Exception("G4FluoData::NumberOfTransitions()","de0002",JustWarning,"vacancyIndex outside boundaries, energy deposited locally");
00099       return 0;
00100     }
00101   else
00102     {
00103       n = nInitShells[vacancyIndex]-1;
00104       //-1 is necessary because the elements of the vector nInitShells
00105       //include also the vacancy shell:
00106       // -1 subtracts this last one
00107   }
00108  return n;
00109 }
00110 G4int G4FluoData::StartShellId(G4int initIndex, G4int vacancyIndex) const
00111 {
00112  G4int n = -1;
00113 
00114  if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies)
00115     {G4Exception("G4FluoData::StartShellId()","de0002",FatalErrorInArgument,"vacancyIndex outside boundaries");
00116     }
00117  else
00118    {
00119      std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator pos;
00120     
00121      pos = idMap.find(vacancyIndex);
00122      
00123      G4DataVector dataSet = *((*pos).second);
00124    
00125      G4int nData = dataSet.size();
00126      //The first Element of idMap's dataSets is the original shell of the vacancy, 
00127      //so we must start from the first element of dataSet
00128  if (initIndex >= 0 && initIndex < nData)
00129             {
00130               n =  (G4int) dataSet[initIndex+1];
00131             
00132             }
00133    }
00134  return n;
00135 }
00136  
00137 G4double G4FluoData::StartShellEnergy(G4int initIndex, G4int vacancyIndex) const
00138 {
00139   G4double n = -1;
00140   
00141   if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies)
00142     {G4Exception("G4FluoData::StartShellEnergy()","de0002",FatalErrorInArgument,"vacancyIndex outside boundaries");}
00143  else
00144    {
00145      std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator pos;
00146      
00147      pos = energyMap.find(vacancyIndex);
00148      
00149      G4DataVector dataSet = *((*pos).second);
00150      
00151      G4int nData = dataSet.size();
00152      if (initIndex >= 0 && initIndex < nData)
00153        {
00154          n =  dataSet[initIndex];
00155          
00156        }
00157    }
00158   return n;
00159 }
00160 
00161 G4double G4FluoData::StartShellProb(G4int initIndex, G4int vacancyIndex) const
00162 {
00163   G4double n = -1;
00164 
00165   if (vacancyIndex<0 || vacancyIndex>=numberOfVacancies)
00166     {
00167       G4Exception("G4FluoData::StartShellEnergy()","de0002",JustWarning,"vacancyIndex outside boundaries, energy deposited locally");
00168       return 0;
00169 }
00170   else
00171     {
00172      std::map<G4int,G4DataVector*,std::less<G4int> >::const_iterator pos;
00173      
00174      pos = probabilityMap.find(vacancyIndex);
00175      
00176      G4DataVector dataSet = *((*pos).second);
00177      
00178      G4int nData = dataSet.size();
00179      if (initIndex >= 0 && initIndex < nData)
00180        {
00181          n =  dataSet[initIndex];
00182          
00183        }
00184     }
00185   return n;
00186 }
00187 
00188 void G4FluoData::LoadData(G4int Z)
00189 { 
00190   // Build the complete string identifying the file with the data set
00191   
00192   std::ostringstream ost;
00193   if(Z != 0){
00194     ost << "fl-tr-pr-"<< Z << ".dat";
00195   }
00196   else{
00197     ost << "fl-tr-pr-"<<".dat"; 
00198   }
00199   G4String name(ost.str());
00200   
00201   char* path = getenv("G4LEDATA");
00202   if (!path)
00203     { 
00204       G4String excep("G4FluoData::LoadData()");
00205       G4Exception(excep,"em0006",FatalException,"Please set G4LEDATA");
00206       return;
00207     }
00208   
00209   G4String pathString(path);
00210   G4String fluor("/fluor/");
00211   G4String dirFile = pathString + fluor + name;
00212   std::ifstream file(dirFile);
00213   std::filebuf* lsdp = file.rdbuf();
00214   
00215   if (! (lsdp->is_open()) )
00216     {
00217       G4String excep = "G4FluoData::LoadData()";
00218       G4String msg = "data file: " + dirFile + " not found";
00219       G4Exception(excep, "em0003",FatalException, msg );
00220       return;
00221     }
00222   
00223   G4double a = 0;
00224   G4int k = 1;
00225   G4int sLocal = 0;
00226   
00227   G4int vacIndex = 0;
00228   G4DataVector* initIds = new G4DataVector;
00229   G4DataVector* transEnergies = new G4DataVector;
00230   G4DataVector* transProbabilities = new G4DataVector;
00231   
00232   do {
00233     file >> a;
00234     G4int nColumns = 3;
00235     if (a == -1)
00236       {
00237         if (sLocal == 0)
00238           {
00239             // End of a shell data set
00240             idMap[vacIndex] = initIds;
00241             energyMap[vacIndex] = transEnergies;
00242             probabilityMap[vacIndex] = transProbabilities;
00243             //      G4double size=transProbabilities->size();
00244             G4int n = initIds->size();
00245             
00246             nInitShells.push_back(n);
00247             numberOfVacancies++;
00248             // Start of new shell data set
00249             initIds = new G4DataVector;
00250             transEnergies = new G4DataVector;
00251             transProbabilities = new G4DataVector;
00252             vacIndex++; 
00253           }      
00254         sLocal++;
00255         if (sLocal == nColumns)
00256           {
00257             sLocal = 0;
00258           }
00259       }
00260     // moved to the end in order to avoid possible leak
00261     /*    else if (a == -2)
00262       {
00263         // End of file; delete the empty vectors created 
00264         //when encountering the last -1 -1 row
00265         delete initIds;
00266         delete transEnergies;
00267         delete transProbabilities;
00268         }*/ 
00269     else
00270       {
00271         
00272         if(k%nColumns == 2)
00273           {      
00274             // 2nd column is transition  probabilities
00275 
00276            if (a != -1) transProbabilities->push_back(a);
00277             
00278             k++;
00279           }
00280         else if (k%nColumns == 1)
00281           {
00282             // 1st column is shell id
00283             // if this is the first data of the shell, all the colums are equal 
00284             // to the shell Id; so we skip the next colums ang go to the next row
00285             if(initIds->size() == 0) {
00286               if (a != -1) initIds->push_back((G4int)a);
00287               file >> a;
00288               file >> a;
00289               k=k+2;
00290             } 
00291             else{ 
00292               if (a != -1) initIds->push_back(a);
00293             }
00294             k++;    
00295           }
00296         else if (k%nColumns == 0)
00297 
00298           {//third column is transition energies
00299 
00300             if (a != -1) 
00301               {G4double e = a * MeV;
00302               transEnergies->push_back(e);}
00303            
00304             k=1;
00305           }
00306       }
00307   } 
00308   while (a != -2); // end of file
00309   file.close();    
00310   delete initIds;
00311   delete transEnergies;
00312   delete transProbabilities;
00313 }
00314 
00315 
00316 void G4FluoData::PrintData() 
00317 {
00318   
00319   for (G4int i = 0; i <numberOfVacancies; i++)
00320     {
00321       G4cout << "---- TransitionData for the vacancy nb "
00322              <<i
00323              <<" ----- "
00324              <<G4endl;
00325       
00326       for (size_t k = 0; k<NumberOfTransitions(i); k++)
00327         { 
00328           G4int id = StartShellId(k,i);
00329         // let's start from 1 because the first (index = 0) element of the vector
00330         // is the id of the intial vacancy
00331           G4double e = StartShellEnergy(k,i) /MeV;
00332           G4double p = StartShellProb(k,i); 
00333           G4cout << k <<") Shell id: " << id <<G4endl;
00334           G4cout << " - Transition energy = " << e << " MeV "<<G4endl;
00335           G4cout   << " - Transition probability = " << p <<G4endl;
00336           
00337         }
00338       G4cout << "-------------------------------------------------" 
00339              << G4endl;
00340     }
00341 }
00342 
00343 
00344 
00345 
00346 
00347 
00348 
00349 
00350 
00351 
00352 
00353 
00354 
00355 
00356 
00357 
00358 
00359 
00360 
00361 
00362 
00363 
00364 
00365 
00366 
00367 
00368 
00369 
00370 
00371 
00372 
00373 
00374 
00375 
00376 
00377 
00378 
00379 
00380 

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