Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4LevelManager.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: G4LevelManager.cc 88375 2015-02-16 17:31:21Z vnivanch $
27 //
28 // -------------------------------------------------------------------
29 //
30 // GEANT4 source file
31 //
32 // File name: G4LevelManager
33 //
34 // Author: V.Ivanchenko
35 //
36 // Creation date: 4 January 2012
37 //
38 // Modifications:
39 // 13.02.2015 Design change for gamma de-excitation
40 //
41 // -------------------------------------------------------------------
42 
43 #include "G4LevelManager.hh"
44 #include "G4HadronicException.hh"
45 
46 G4String G4LevelManager::fFloatingLevels[] = {
47  "-", "+X", "+Y", "+Z", "+U", "+V", "+W", "+R", "+S", "+T", "+A", "+B", "+C"};
48 
50  const std::vector<G4float>& energies,
51  const std::vector<G4int>& spin,
52  const std::vector<const G4NucLevel*>& levels)
53  : nTransitions(0)
54 {
55  if(0 < ntrans) {
56  nTransitions = ntrans - 1;
57  fLevelEnergy.reserve(ntrans);
58  fSpin.reserve(ntrans);
59  fLevels.reserve(ntrans);
60  for(size_t i=0; i<ntrans; ++i) {
61  fLevelEnergy.push_back(energies[i]);
62  fSpin.push_back(spin[i]);
63  fLevels.push_back(levels[i]);
64  }
65  //G4cout << "New G4LevelManager N= " << nTransitions << " "
66  //<< fLevelEnergy.size() << " <" << this << ">" << G4endl;
67  }
68 }
69 
71 {
72  for(size_t i=0; i<=nTransitions; ++i) { delete fLevels[i]; }
73 }
74 
75 size_t
77 {
78  //G4cout<< "index= " << index << " max= " << nTransitions << " exc= " << ener
79  // << " Emax= " << fLevelEnergy[nTransitions] << G4endl;
80  size_t idx = std::min(index, nTransitions);
81  G4float energy = (G4float)ener;
82  static const G4float tolerance = 1.0f-6;
83  if(0 == nTransitions || std::fabs(energy - fLevelEnergy[idx]) <= tolerance) {
84  return idx;
85  }
86  // ground state
87  if(energy <= fLevelEnergy[1]*0.5f)
88  { idx = 0; }
89  // take top level
90  else if((fLevelEnergy[nTransitions] + fLevelEnergy[nTransitions-1])*0.5f <= energy)
91  { idx = nTransitions; }
92 
93  // if shortcuts are not working, make binary search
94  else {
95  idx = std::lower_bound(fLevelEnergy.begin(), fLevelEnergy.end(), energy)
96  - fLevelEnergy.begin() - 1;
97  if(energy - fLevelEnergy[idx] > fLevelEnergy[idx+1] - energy) { ++idx; }
98  //G4cout << "E= " << energy << " " << fLevelEnergy[idx-1]
99  //<< " " << fLevelEnergy[idx] << G4endl;
100  }
101  return idx;
102 }
103 
105 {
106 #ifdef G4VERBOSE
107  if(i > nTransitions) { PrintError(i, "Meta"); }
108 #endif
109  return fFloatingLevels[fSpin[i]/100000];
110  // return fFloatingLevels[fFloating[i]];
111 }
112 
113 #ifdef G4VERBOSE
114 void G4LevelManager::PrintError(size_t idx, const G4String& ss) const
115 {
116  G4String sss = "G4LevelManager::"+ss+"()";
118  ed << "Index of a level " << idx << " > "
119  << nTransitions << " (number of levels)";
120  G4Exception(sss,"had061",JustWarning,ed,"");
121  throw G4HadronicException(__FILE__, __LINE__,"FATAL Hadronic Exception");
122 }
123 #endif
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
float G4float
Definition: G4Types.hh:77
size_t NearestLevelIndex(G4double energy, size_t index=0) const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static const char sss[MAX_N_PAR+2]
Definition: Evaluator.cc:64
G4double energy(const ThreeVector &p, const G4double m)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
G4LevelManager(size_t ntrans, const std::vector< G4float > &energies, const std::vector< G4int > &spin, const std::vector< const G4NucLevel * > &levels)
double G4double
Definition: G4Types.hh:76
const G4String & FloatingType(size_t i) const