Geant4  10.03
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 
47  "-", "+X", "+Y", "+Z", "+U", "+V", "+W", "+R", "+S", "+T", "+A", "+B", "+C"};
48 
50  const std::vector<G4float>& energies,
51  const std::vector<G4float>& lifetime,
52  const std::vector<G4float>& lifetimegamma,
53  const std::vector<G4int>& spin,
54  const std::vector<G4int>& fll,
55  const std::vector<const G4NucLevel*>& levels)
56  : nTransitions(0)
57 {
58  if(0 < ntrans) {
59  nTransitions = ntrans - 1;
60  fLevelEnergy.reserve(ntrans);
61  fLifeTime.reserve(ntrans);
62  fLifeTimeGamma.reserve(ntrans);
63  fSpin.reserve(ntrans);
64  fFloating.reserve(ntrans);
65  fLevels.reserve(ntrans);
66  for(size_t i=0; i<ntrans; ++i) {
67  fLevelEnergy.push_back(energies[i]);
68  fLifeTime.push_back(lifetime[i]);
69  fLifeTimeGamma.push_back(lifetimegamma[i]);
70  fSpin.push_back(spin[i]);
71  fLevels.push_back(levels[i]);
72  fFloating.push_back(fll[i]);
73  }
74  //G4cout << "New G4LevelManager N= " << nTransitions << " " << fLevelEnergy.size()
75  // << " <" << this << ">" << G4endl;
76  }
77 }
78 
80 {
81  for(size_t i=0; i<=nTransitions; ++i) { delete fLevels[i]; }
82 }
83 
84 size_t
86 {
87  //G4cout<< "index= " << index << " max= " << nTransitions << " exc= " << ener
88  // << " Emax= " << fLevelEnergy[nTransitions] << G4endl;
89  size_t idx = std::min(index, nTransitions);
90  G4float energy = (G4float)ener;
91  static const G4float tolerance = 1.0f-6;
92  if(0 == nTransitions || std::fabs(energy - fLevelEnergy[idx]) <= tolerance) {
93  return idx;
94  }
95  // ground state
96  if(energy <= fLevelEnergy[1]*0.5f)
97  { idx = 0; }
98  // take top level
99  else if((fLevelEnergy[nTransitions] + fLevelEnergy[nTransitions-1])*0.5f <= energy)
100  { idx = nTransitions; }
101 
102  // if shortcuts are not working, make binary search
103  else {
104  idx = std::lower_bound(fLevelEnergy.begin(), fLevelEnergy.end(), energy)
105  - fLevelEnergy.begin() - 1;
106  if(energy - fLevelEnergy[idx] > fLevelEnergy[idx+1] - energy) { ++idx; }
107  //G4cout << "E= " << energy << " " << fLevelEnergy[idx-1]
108  //<< " " << fLevelEnergy[idx] << G4endl;
109  }
110  return idx;
111 }
112 
114 {
115 #ifdef G4VERBOSE
116  if(i > nTransitions) { PrintError(i, "Meta"); }
117 #endif
118  return fFloatingLevels[fFloating[i]];
119 }
120 
121 #ifdef G4VERBOSE
122 void G4LevelManager::PrintError(size_t idx, const G4String& ss) const
123 {
124  G4String sss = "G4LevelManager::"+ss+"()";
126  ed << "Index of a level " << idx << " > "
127  << nTransitions << " (number of levels)";
128  G4Exception(sss,"had061",JustWarning,ed,"");
129  throw G4HadronicException(__FILE__, __LINE__,"FATAL Hadronic Exception");
130 }
131 #endif
std::vector< G4int > fFloating
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
float G4float
Definition: G4Types.hh:77
std::vector< G4int > fSpin
std::vector< G4float > fLevelEnergy
std::vector< G4float > fLifeTime
std::vector< const G4NucLevel * > fLevels
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
std::vector< G4float > fLifeTimeGamma
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< G4float > &lifetime, const std::vector< G4float > &lifetimegamma, const std::vector< G4int > &spin, const std::vector< G4int > &meta, const std::vector< const G4NucLevel * > &levels)
double G4double
Definition: G4Types.hh:76
static G4String fFloatingLevels[nfloting]
const G4String & FloatingType(size_t i) const