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] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 // V. Ivanchenko, July-2023 Basic revision of particle HP classes
 32 //
 33 #include "G4ParticleHPManager.hh"
 34 
 35 #include "G4Exception.hh"
 36 #include "G4HadronicException.hh"
 37 #include "G4ParticleHPMessenger.hh"
 38 #include "G4ParticleDefinition.hh"
 39 #include "G4HadronicParameters.hh"
 40 #include "G4ParticleHPThreadLocalManager.hh"
 41 #include "G4SystemOfUnits.hh"
 42 
 43 #include <zlib.h>
 44 #include <fstream>
 45 
 46 G4ParticleHPManager* G4ParticleHPManager::instance = nullptr;
 47 
 48 G4ParticleHPManager::G4ParticleHPManager()
 49   : theMinEnergyDBRC(0.1 * CLHEP::eV),
 50     theMaxEnergyDBRC(210. * CLHEP::eV),
 51     theMaxEnergyDoppler(30. * CLHEP::keV)
 52 {
 53   messenger = new G4ParticleHPMessenger(this);
 54   verboseLevel = G4HadronicParameters::Instance()->GetVerboseLevel();
 55   const char* ss = G4FindDataDir("NeutronHPNames");
 56   if (nullptr != ss) { CHECK_HP_NAMES = true; }
 57   ss = G4FindDataDir("G4PHP_DO_NOT_CHECK_DIFF_COEFF_REPR");
 58   if (nullptr != ss) { PHP_CHECK = false; }
 59   ss = G4FindDataDir("G4PHP_MULTIPLICITY_METHOD");
 60   if (nullptr != ss && "BetweenInts" == G4String(ss)) { PHP_USE_POISSON = false; }
 61   ss = G4FindDataDir("G4ParticleHPDebug");
 62   if (nullptr != ss) { DEBUG = true; }
 63 
 64   // identify and check data path once - it should exist
 65   const char* nch = G4FindDataDir("G4NEUTRONHPDATA");
 66   if (nullptr == nch) {
 67     G4Exception("G4ParticleHPManager::G4ParticleHPManager()","hadhp01",
 68                 FatalException, "G4NEUTRONXSDATA is not defined - check path");
 69   } else {
 70     fDataPath[0] = G4String(nch);
 71   }
 72   // path may be defined by two environment variables
 73   // it is not mandatory to access PHP data - path may be not defined
 74   const char* ttp = G4FindDataDir("G4PARTICLEHPDATA");
 75   G4String tendl = (nullptr == ttp) ? G4String("") : G4String(ttp);
 76   const char* ssp = G4FindDataDir("G4PROTONHPDATA");
 77   fDataPath[1] = (nullptr == ssp) ? tendl + "/Proton" : G4String(ssp);
 78 
 79   ssp = G4FindDataDir("G4DEUTERONHPDATA");
 80   fDataPath[2] = (nullptr == ssp) ? tendl + "/Deuteron" : G4String(ssp);
 81 
 82   ssp = G4FindDataDir("G4TRITONHPDATA");
 83   fDataPath[3] = (nullptr == ssp) ? tendl + "/Triton" : G4String(ssp);
 84 
 85   ssp = G4FindDataDir("G4HE3HPDATA");
 86   fDataPath[4] = (nullptr == ssp) ? tendl + "/He3" : G4String(ssp);
 87 
 88   ssp = G4FindDataDir("G4ALPHAHPDATA");
 89   fDataPath[5] = (nullptr == ssp) ? tendl + "/Alpha" : G4String(ssp);
 90 }
 91 
 92 G4ParticleHPManager::~G4ParticleHPManager()
 93 {
 94   delete messenger;
 95 }
 96 
 97 G4ParticleHPManager* G4ParticleHPManager::GetInstance()
 98 {
 99   static G4ParticleHPManager manager;
100   if (instance == nullptr) {
101     instance = &manager;
102   }
103   return instance;
104 }
105 
106 G4int G4ParticleHPManager::GetPHPIndex(const G4ParticleDefinition* part) const {
107   G4int pdg = part->GetPDGEncoding();
108   G4int idx;
109   if (pdg == 2112) { idx = 0; }
110   else if (pdg == 2212) { idx = 1; }
111   else if (pdg == 1000010020) { idx = 2; }
112   else if (pdg == 1000010030) { idx = 3; }
113   else if (pdg == 1000020030) { idx = 4; }
114   else if (pdg == 1000020040) { idx = 5; }
115   else {
116     idx = 0;
117     G4ExceptionDescription ed;
118     ed << "Particle " << part->GetParticleName()
119        << " cannot be handled by the ParticleHP sub-library";
120     G4Exception("G4ParticleHPManager::G4ParticleHPManager()","hadhp01",
121                 FatalException, ed, "");
122   }
123   return idx;
124 }
125 
126 const G4String&
127 G4ParticleHPManager::GetParticleHPPath(const G4ParticleDefinition* part) const {
128   return fDataPath[GetPHPIndex(part)];
129 }
130 
131 void G4ParticleHPManager::OpenReactionWhiteBoard()
132 {
133   G4ParticleHPThreadLocalManager::GetInstance()->OpenReactionWhiteBoard();
134 }
135 
136 G4ParticleHPReactionWhiteBoard* G4ParticleHPManager::GetReactionWhiteBoard()
137 {
138   return G4ParticleHPThreadLocalManager::GetInstance()->GetReactionWhiteBoard();
139 }
140 
141 void G4ParticleHPManager::CloseReactionWhiteBoard()
142 {
143   G4ParticleHPThreadLocalManager::GetInstance()->CloseReactionWhiteBoard();
144 }
145 
146 void G4ParticleHPManager::GetDataStream(const G4String& filename, std::istringstream& iss)
147 {
148   G4String* data = nullptr;
149   G4String compfilename(filename);
150   compfilename += ".z";
151   auto in = new std::ifstream(compfilename, std::ios::binary | std::ios::ate);
152   if (in->good()) {
153     // Use the compressed file
154     std::streamoff file_size = in->tellg();
155     in->seekg(0, std::ios::beg);
156     auto compdata = new Bytef[file_size];
157 
158     while (*in) {  // Loop checking, 11.05.2015, T. Koi
159       in->read((char*)compdata, file_size);
160     }
161 
162     auto complen = (uLongf)(file_size * 4);
163     auto uncompdata = new Bytef[complen];
164 
165     while (Z_OK != uncompress(uncompdata, &complen, compdata, file_size))
166     {  // Loop checking, 11.05.2015, T. Koi
167       delete[] uncompdata;
168       complen *= 2;
169       uncompdata = new Bytef[complen];
170     }
171     delete[] compdata;
172     // Now "complen" has uncomplessed size
173     data = new G4String((char*)uncompdata, (G4long)complen);
174     delete[] uncompdata;
175   }
176   else {
177     // Use regular text file
178     std::ifstream thefData(filename, std::ios::in | std::ios::ate);
179     if (thefData.good()) {
180       std::streamoff file_size = thefData.tellg();
181       thefData.seekg(0, std::ios::beg);
182       auto filedata = new char[file_size];
183       while (thefData) {  // Loop checking, 11.05.2015, T. Koi
184         thefData.read(filedata, file_size);
185       }
186       thefData.close();
187       data = new G4String(filedata, file_size);
188       delete[] filedata;
189     }
190     else {
191       // found no data file
192       // set error bit to the stream
193       iss.setstate(std::ios::badbit);
194     }
195   }
196   if (data != nullptr) {
197     iss.str(*data);
198     G4String id;
199     iss >> id;
200     if (id == "G4NDL") {
201       // Register information of file
202       G4String source;
203       iss >> source;
204       register_data_file(filename, source);
205     }
206     else {
207       iss.seekg(0, std::ios::beg);
208     }
209   }
210   in->close();
211   delete in;
212   delete data;
213 }
214 
215 void G4ParticleHPManager::GetDataStream2(const G4String& filename, std::istringstream& iss)
216 {
217   // Checking existance of data file
218 
219   G4String compfilename(filename);
220   compfilename += ".z";
221   auto in = new std::ifstream(compfilename, std::ios::binary | std::ios::ate);
222   if (in->good()) {
223     // Compressed file is exist
224     in->close();
225   }
226   else {
227     std::ifstream thefData(filename, std::ios::in | std::ios::ate);
228     if (thefData.good()) {
229       // Regular text file is exist
230       thefData.close();
231     }
232     else {
233       // found no data file
234       // set error bit to the stream
235       iss.setstate(std::ios::badbit);
236     }
237   }
238   delete in;
239 }
240 
241 void G4ParticleHPManager::SetVerboseLevel(G4int newValue)
242 {
243   G4cout << "You are setting a new verbose level for Particle HP package." << G4endl;
244   G4cout << "the new value will be used in whole of the Particle HP package, i.e., models and "
245             "cross sections for Capture, Elastic, Fission and Inelastic interaction."
246          << G4endl;
247   verboseLevel = newValue;
248 }
249 
250 void G4ParticleHPManager::register_data_file(const G4String& filename, const G4String& source)
251 {
252   mDataEvaluation.insert(std::pair<G4String, G4String>(filename, source));
253 }
254 
255 void G4ParticleHPManager::DumpDataSource() const
256 {
257   G4cout << "Data source of this Partile HP calculation are " << G4endl;
258   for (const auto& it : mDataEvaluation) {
259     G4cout << it.first << " " << it.second << G4endl;
260   }
261   G4cout << G4endl;
262 }
263 
264 void G4ParticleHPManager::DumpSetting()
265 {
266   if(isPrinted) { return; }
267   G4cout << G4endl
268          << "=======================================================" << G4endl
269          << "======       ParticleHP Physics Parameters     ========" << G4endl
270          << "=======================================================" << G4endl
271          << " Use only photo-evaporation      " << USE_ONLY_PHOTONEVAPORATION << G4endl
272          << " Skip missing isotopes           " << SKIP_MISSING_ISOTOPES << G4endl
273          << " Neglect Doppler                 " << NEGLECT_DOPPLER << G4endl
274          << " Do not adjust final state       " << DO_NOT_ADJUST_FINAL_STATE << G4endl
275          << " Produce fission fragments       " << PRODUCE_FISSION_FRAGMENTS << G4endl
276          << " Use WendtFissionModel           " << USE_WENDT_FISSION_MODEL << G4endl
277          << " Use NRESP71Model                " << USE_NRESP71_MODEL << G4endl
278          << " Use DBRC                        " << USE_DBRC << G4endl
279          << " PHP use Poisson                 " << PHP_USE_POISSON << G4endl
280          << " PHP check                       " << PHP_CHECK << G4endl
281          << " CHECK HP NAMES                  " << CHECK_HP_NAMES << G4endl
282          << " Enable DEBUG                    " << DEBUG << G4endl
283          << " Use probability tables from     " << G4HadronicParameters::Instance()->GetTypeTablePT() << G4endl
284          << "=======================================================" << G4endl << G4endl;
285   isPrinted = true;
286 }
287