Geant4  10.02.p01
G4LevelManager.hh
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.hh 88516 2015-02-25 11:00:16Z vnivanch $
27 //
28 // -------------------------------------------------------------------
29 //
30 // GEANT4 header 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 // Nuclear level manager for photon de-excitation process
44 //
45 
46 #ifndef G4LEVELMANAGER_HH
47 #define G4LEVELMANAGER_HH 1
48 
49 #include "globals.hh"
50 #include "G4NucLevel.hh"
51 #include <assert.h>
52 #include <vector>
53 
54 static const G4float tolerance = 0.0001f;
55 
57 {
58 
59 public:
60  // levels - vector of nuclear level objects, ground state
61  // level has NULL pointer
62  // energies - list of excitation energies of nuclear levels starting
63  // from the ground state with energy zero
64  G4LevelManager(const std::vector<G4float>& energies,
65  const std::vector<G4float>& lifetime,
66  const std::vector<G4float>& lifetimegamma,
67  const std::vector<G4int>& spin,
68  const std::vector<const G4NucLevel*>& levels);
69 
71 
72  //===================================================================
73  // run time inlined const functions
74  //===================================================================
75 
76  inline size_t NumberOfTransitions() const;
77 
78  inline const G4NucLevel* GetLevel(size_t i) const;
79 
80  inline G4float LevelEnergy(size_t i) const;
81 
82  inline G4float MaxLevelEnergy() const;
83 
84  inline size_t NearestLevelIndex(G4double energy, size_t index=0) const;
85 
86  inline const G4NucLevel* NearestLevel(G4double energy, size_t index=0) const;
87 
88  inline G4float NearestLevelEnergy(G4double energy, size_t index=0) const;
89 
90  inline G4float LifeTime(size_t i) const;
91 
92  inline G4float LifeTimeGamma(size_t i) const;
93 
94  inline G4int Spin(size_t i) const;
95 
96 private:
97 
99  const G4LevelManager& operator=(const G4LevelManager &right);
100  G4bool operator==(const G4LevelManager &right) const;
101  G4bool operator!=(const G4LevelManager &right) const;
102 
103  const std::vector<G4float> fLevelEnergy;
104  const std::vector<G4float> fLifeTime;
105  const std::vector<G4float> fLifeTimeGamma;
106  const std::vector<G4int> fSpin;
107  const std::vector<const G4NucLevel*> fLevels;
108  size_t nTransitions;
109 
110 };
111 
113 {
114  return nTransitions;
115 }
116 
117 inline const G4NucLevel* G4LevelManager::GetLevel(size_t i) const
118 {
119  assert(i <= nTransitions);
120  return fLevels[i];
121 }
122 
123 inline G4float G4LevelManager::LevelEnergy(size_t i) const
124 {
125  assert(i <= nTransitions);
126  return fLevelEnergy[i];
127 }
128 
130 {
131  return fLevelEnergy[nTransitions];
132 }
133 
134 inline size_t
136 {
137  //G4cout << "index= " << index << " max= " << nTransitions << " exc= " << ener
138  // << " Emax= " << fLevelEnergy[nTransitions] << G4endl;
139  size_t idx = std::min(index, nTransitions);
140  G4float energy = (G4float)ener;
141  if(std::fabs(energy - fLevelEnergy[idx]) > tolerance) {
142  // ground state
143  if(energy <= tolerance)
144  { idx = 0; }
145  else if(energy <= fLevelEnergy[1])
146  { idx = 1; }
147  else if((fLevelEnergy[nTransitions] + fLevelEnergy[nTransitions-1])*0.5f <= energy)
148  { idx = nTransitions; }
149 
150  // if shortcuts are not working, make binary search
151  else {
152  idx = std::lower_bound(fLevelEnergy.begin(), fLevelEnergy.end(), energy)
153  - fLevelEnergy.begin() - 1;
154  if(energy - fLevelEnergy[idx] > fLevelEnergy[idx+1] - energy) { ++idx; }
155  //G4cout << "E= " << energy << " " << fLevelEnergy[idx-1]
156  //<< " " << fLevelEnergy[idx] << G4endl;
157  }
158  }
159  return idx;
160 }
161 
162 inline const G4NucLevel*
164 {
165  return GetLevel(NearestLevelIndex(energy, index));
166 }
167 
168 inline G4float
170 {
171  return LevelEnergy(NearestLevelIndex(energy, index));
172 }
173 
174 inline G4float G4LevelManager::LifeTime(size_t i) const
175 {
176  assert(i <= nTransitions);
177  return fLifeTime[i];
178 }
179 
181 {
182  assert(i <= nTransitions);
183  return fLifeTimeGamma[i];
184 }
185 
186 inline G4int G4LevelManager::Spin(size_t i) const
187 {
188  assert(i <= nTransitions);
189  return fSpin[i];
190 }
191 
192 #endif
static const G4float tolerance
const std::vector< G4float > fLevelEnergy
G4bool operator!=(const G4LevelManager &right) const
G4float LifeTime(size_t i) const
float G4float
Definition: G4Types.hh:77
const G4NucLevel * NearestLevel(G4double energy, size_t index=0) const
const std::vector< G4float > fLifeTime
int G4int
Definition: G4Types.hh:78
const G4NucLevel * GetLevel(size_t i) const
G4LevelManager(const std::vector< G4float > &energies, const std::vector< G4float > &lifetime, const std::vector< G4float > &lifetimegamma, const std::vector< G4int > &spin, const std::vector< const G4NucLevel * > &levels)
G4float LevelEnergy(size_t i) const
const G4LevelManager & operator=(const G4LevelManager &right)
const std::vector< G4int > fSpin
bool G4bool
Definition: G4Types.hh:79
size_t NumberOfTransitions() const
G4bool operator==(const G4LevelManager &right) const
G4float NearestLevelEnergy(G4double energy, size_t index=0) const
const std::vector< G4float > fLifeTimeGamma
size_t NearestLevelIndex(G4double energy, size_t index=0) const
const std::vector< const G4NucLevel * > fLevels
G4double energy(const ThreeVector &p, const G4double m)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
double G4double
Definition: G4Types.hh:76
G4float LifeTimeGamma(size_t i) const
G4int Spin(size_t i) const
G4float MaxLevelEnergy() const