ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticleHPManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ParticleHPManager.cc
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 // Class Description
27 // Manager of NetronHP
28 //
29 // 121031 First implementation done by T. Koi (SLAC/PPA)
30 // P. Arce, June-2014 Conversion neutron_hp to particle_hp
31 //
32 #include <zlib.h>
33 #include <fstream>
34 
35 #include "G4ParticleHPManager.hh"
37 #include "G4ParticleHPMessenger.hh"
38 #include "G4HadronicException.hh"
39 
41 
43 : verboseLevel(1)
44 ,USE_ONLY_PHOTONEVAPORATION(false)
45 ,SKIP_MISSING_ISOTOPES(false)
46 ,NEGLECT_DOPPLER(false)
47 ,DO_NOT_ADJUST_FINAL_STATE(false)
48 ,PRODUCE_FISSION_FRAGMENTS(false)
49 ,USE_NRESP71_MODEL(false)
50 ,theElasticCrossSections(0)
51 ,theCaptureCrossSections(0)
52 ,theFissionCrossSections(0)
53 ,theElasticFSs(0)
54 ,theCaptureFSs(0)
55 ,theFissionFSs(0)
56 ,theTSCoherentCrossSections(0)
57 ,theTSIncoherentCrossSections(0)
58 ,theTSInelasticCrossSections(0)
59 ,theTSCoherentFinalStates(0)
60 ,theTSIncoherentFinalStates(0)
61 ,theTSInelasticFinalStates(0)
62 {
63  messenger = new G4ParticleHPMessenger( this );
64  if ( std::getenv( "G4NEUTRONHP_DO_NOT_ADJUST_FINAL_STATE" ) || std::getenv("G4PHP_DO_NOT_ADJUST_FINAL_STATE") ) DO_NOT_ADJUST_FINAL_STATE = true;
65  if ( std::getenv( "G4NEUTRONHP_USE_ONLY_PHOTONEVAPORATION" ) ) USE_ONLY_PHOTONEVAPORATION = true;
66  if ( std::getenv( "G4NEUTRONHP_NEGLECT_DOPPLER" ) || std::getenv("G4PHP_NEGLECT_DOPPLER") ) NEGLECT_DOPPLER = true;
67  if ( std::getenv( "G4NEUTRONHP_SKIP_MISSING_ISOTOPES" ) ) SKIP_MISSING_ISOTOPES = true;
68  if ( std::getenv( "G4NEUTRONHP_PRODUCE_FISSION_FRAGMENTS" ) ) PRODUCE_FISSION_FRAGMENTS = true;
69  if ( std::getenv( "G4PHP_USE_NRESP71_MODEL" ) ) USE_NRESP71_MODEL = true;
70 }
71 
73 {
74  delete messenger;
75 }
76 
78 {
79  static G4ParticleHPManager manager;
80  if (!instance)
81  {
82  instance = &manager;
83  }
84  return instance;
85 }
86 
88 {
90 }
91 
93 {
95 }
96 
98 {
100 }
101 
102 void G4ParticleHPManager::GetDataStream( G4String filename , std::istringstream& iss )
103 {
104  G4String* data=0;
105  G4String compfilename(filename);
106  compfilename += ".z";
107  std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate );
108  if ( in->good() )
109  {
110  // Use the compressed file
111  G4int file_size = in->tellg();
112  in->seekg( 0 , std::ios::beg );
113  Bytef* compdata = new Bytef[ file_size ];
114 
115  while ( *in )
116  { // Loop checking, 11.05.2015, T. Koi
117  in->read( (char*)compdata , file_size );
118  }
119 
120  uLongf complen = (uLongf) ( file_size*4 );
121  Bytef* uncompdata = new Bytef[complen];
122 
123  while ( Z_OK != uncompress ( uncompdata , &complen , compdata , file_size ) )
124  { // Loop checking, 11.05.2015, T. Koi
125  delete[] uncompdata;
126  complen *= 2;
127  uncompdata = new Bytef[complen];
128  }
129  delete [] compdata;
130  // Now "complen" has uncomplessed size
131  data = new G4String ( (char*)uncompdata , (G4long)complen );
132  delete [] uncompdata;
133  }
134  else
135  {
136  // Use regular text file
137  std::ifstream thefData( filename , std::ios::in | std::ios::ate );
138  if ( thefData.good() )
139  {
140  G4int file_size = thefData.tellg();
141  thefData.seekg( 0 , std::ios::beg );
142  char* filedata = new char[ file_size ];
143  while ( thefData )
144  { // Loop checking, 11.05.2015, T. Koi
145  thefData.read( filedata , file_size );
146  }
147  thefData.close();
148  data = new G4String ( filedata , file_size );
149  delete [] filedata;
150  }
151  else
152  {
153  // found no data file
154  // set error bit to the stream
155  iss.setstate( std::ios::badbit );
156  }
157  }
158  if ( data != 0 )
159  {
160  iss.str(*data);
161  G4String id;
162  iss >> id;
163  if ( id == "G4NDL" )
164  {
165  //Register information of file
166  G4String source;
167  iss >> source;
168  register_data_file(filename,source);
169  }
170  else
171  {
172  iss.seekg( 0 , std::ios::beg );
173  }
174  }
175  in->close(); delete in;
176  delete data;
177 }
178 
179 void G4ParticleHPManager::GetDataStream2( G4String filename , std::istringstream& iss )
180 {
181  // Checking existance of data file
182 
183  G4String compfilename(filename);
184  compfilename += ".z";
185  std::ifstream* in = new std::ifstream ( compfilename , std::ios::binary | std::ios::ate );
186  if ( in->good() )
187  {
188  // Compressed file is exist
189  in->close();
190  }
191  else
192  {
193  std::ifstream thefData( filename , std::ios::in | std::ios::ate );
194  if ( thefData.good() )
195  {
196  // Regular text file is exist
197  thefData.close();
198  }
199  else
200  {
201  // found no data file
202  // set error bit to the stream
203  iss.setstate( std::ios::badbit );
204  }
205  }
206  delete in;
207 }
208 
210 {
211  G4cout << "You are setting a new verbose level for Particle HP package." << G4endl;
212  G4cout << "the new value will be used in whole of the Particle HP package, i.e., models and cross sections for Capture, Elastic, Fission and Inelastic interaction." << G4endl;
213  verboseLevel = newValue;
214 }
215 
217 {
218  mDataEvaluation.insert( std::pair < G4String , G4String > ( filename , source ) );
219 }
220 
222 {
223 
224  G4cout << "Data source of this Partile HP calculation are " << G4endl;
225  for ( std::map< G4String , G4String >::iterator
226  it = mDataEvaluation.begin() ; it != mDataEvaluation.end() ; it++ )
227  {
228  G4cout << it->first << " " << it->second << G4endl;
229  }
230  G4cout << G4endl;
231 }
232 
234 {
235  if ( theInelasticCrossSections.end() != theInelasticCrossSections.find( particle ) )
236  return theInelasticCrossSections.find( particle )->second;
237  else
238  return 0;
239 }
240 
242 {
243  theInelasticCrossSections.insert( std::pair<const G4ParticleDefinition* , G4PhysicsTable* >( particle , val ) );
244 }
245 
246 std::vector<G4ParticleHPChannelList*>* G4ParticleHPManager::GetInelasticFinalStates(const G4ParticleDefinition* particle)
247 {
248  if ( theInelasticFSs.end() != theInelasticFSs.find( particle ) )
249  return theInelasticFSs.find( particle )->second;
250  else
251  return 0;
252 }
253 
254 void G4ParticleHPManager::RegisterInelasticFinalStates( const G4ParticleDefinition* particle , std::vector<G4ParticleHPChannelList*>* val )
255 {
256  theInelasticFSs.insert ( std::pair<const G4ParticleDefinition*,std::vector<G4ParticleHPChannelList*>*>( particle , val ) );
257 }