Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4GIDI.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
27#include <G4GIDI.hh>
28
30static bool G4GIDI_pops_initialized = false;
31
32/* *********************************************************************************************************//**
33 * Returns the familiar name for the projectile for *a_ip*.
34 *
35 * @param a_ip [in] One of the following ids for the projectile (0:photon, 1:neutron, 2:proton, 3:deutron, 4:triton, 5:helion or 6:alpha).
36 ***********************************************************************************************************/
37
38static std::string projectileStringFromID( int a_ip ) {
39
40 switch( a_ip ) {
41 case 0:
42 return( PoPI::IDs::photon );
43 case 1:
44 return( PoPI::IDs::neutron );
45 case 2:
46 return( PoPI::IDs::proton );
47 case 3:
49 case 4:
51 case 5:
53 case 6:
55 default:
56 throw LUPI::Exception( "Invalid projectile id " + std::to_string( a_ip ) );
57 }
58
59 return( "" );
60}
61
62/* *********************************************************************************************************//**
63 * Initialize the G4GIDI stuff.
64 ***********************************************************************************************************/
65
66void G4GIDI_initialize( std::string const &a_dataPath ) {
67
68 if( G4GIDI_pops_initialized ) return;
69
70 G4GIDI_pops_initialized = true;
71 G4GIDI_pops.addFile( a_dataPath + "/" + "pops.xml", false );
72 G4GIDI_pops.addFile( a_dataPath + "/" + "metastables_alias.xml", false );
73}
74
75/*! \class G4GIDI
76 * A class to store map files for a particular projectile.
77 */
78
79/* *********************************************************************************************************//**
80 * @param a_ip [in] One of the following ids for the projectile (0:photon, 1:neutron, 2:proton, 3:deutron, 4:triton, 5:helion or 6:alpha).
81 * @param a_dataDirectory [in] A path to a map file to load.
82 ***********************************************************************************************************/
83
84G4GIDI::G4GIDI( int a_ip, std::string const &a_dataDirectory ) :
85 m_projectileIP( a_ip ),
86 m_projectile( projectileStringFromID( a_ip ) ) {
87
88 addDataDirectory( a_dataDirectory );
89}
90
91/* *********************************************************************************************************//**
92 *
93 * @param a_id [in] This argument is ignored but needed for backwards compatibility.
94 * @param a_dataDirectories [in] A list of paths to a map files to load.
95 ***********************************************************************************************************/
96
97G4GIDI::G4GIDI( int a_ip, std::list<std::string> const &a_dataDirectories ) :
98 m_projectileIP( a_ip ),
99 m_projectile( projectileStringFromID( a_ip ) ) {
100
101 for( auto mapIter = a_dataDirectories.begin( ); mapIter != a_dataDirectories.end( ); ++mapIter ) {
102 addDataDirectory( *mapIter );
103 }
104}
105
106/* *********************************************************************************************************//**
107 ***********************************************************************************************************/
108
110
111 for( auto mapIter = m_maps.begin( ); mapIter != m_maps.end( ); ++mapIter ) delete *mapIter;
112 for( auto protareIter = m_protares.begin( ); protareIter != m_protares.end( ); ++protareIter ) delete *protareIter;
113}
114
115/* *********************************************************************************************************//**
116 * Adds the map file *a_dataDirectory* to *this*.
117 *
118 * @param a_dataDirectory [in] A path to a map file to load.
119 ***********************************************************************************************************/
120
121int G4GIDI::addDataDirectory( std::string const &a_dataDirectory ) {
122
123 for( auto mapIter = m_maps.begin( ); mapIter != m_maps.end( ); ++mapIter ) {
124 if( (*mapIter)->fileName( ) == a_dataDirectory ) return( 0 );
125 }
126
127 m_maps.push_back( new GIDI::Map::Map( a_dataDirectory, G4GIDI_pops ) );
128
129 return( 0 );
130}
131
132/* *********************************************************************************************************//**
133 * Removes the map file with path *a_dataDirectory* from *this*.
134 *
135 * @param a_dataDirectory [in] A path to a map file to unload.
136 ***********************************************************************************************************/
137
138int G4GIDI::removeDataDirectory( std::string const &a_dataDirectory ) {
139
140 std::size_t index = 0;
141
142 for( auto mapIter = m_maps.begin( ); mapIter!= m_maps.end( ); ++mapIter, ++index ) {
143 if( a_dataDirectory == (*mapIter)->fileName( ) ) {
144 delete *mapIter;
145
146 ++index;
147 for( ; index < m_maps.size( ); ++index ) m_maps[index-1] = m_maps[index];
148 m_maps[index-1] = nullptr;
149 m_maps.resize( m_maps.size( ) - 1 );
150 }
151 }
152
153 return( 0 );
154}
155
156/* *********************************************************************************************************//**
157 * Removes the map file with path *a_dataDirectory* from *this*.
158 *
159 * @param a_dataDirectory [in] A path to a map file to unload.
160 ***********************************************************************************************************/
161
162std::string const G4GIDI::getDataDirectoryAtIndex( int a_index ) const {
163
164 std::string nullString;
165
166 if( ( a_index < 0 ) || ( a_index >= static_cast<int>( m_maps.size( ) ) ) ) return( nullString );
167
168 return( m_maps[a_index]->fileName( ) );
169}
170
171/* *********************************************************************************************************//**
172 * Returns a list of paths to all loaded map files.
173 *
174 * @return Returns a pointer that the user owns (i.e., the user is responsible for free-ing).
175 ***********************************************************************************************************/
176
177std::vector<std::string> *G4GIDI::getDataDirectories( ) const {
178
179 std::vector<std::string> *list = new std::vector<std::string>( );
180
181 for( auto mapIter = m_maps.begin( ); mapIter!= m_maps.end( ); ++mapIter ) {
182 list->push_back( (*mapIter)->fileName( ) );
183 }
184
185 return( list );
186}
187
188/* *********************************************************************************************************//**
189 * Returns **true** if the specified target exists in a map file and **false** otherwise.
190 *
191 * @param a_lib_name [in] The evaluation. Call be an empty string.
192 * @param a_Z [in] The atomic number of the target.
193 * @param a_A [in] The mass number of the taret.
194 * @param a_M [in] The meta-stable index of the target.
195 *
196 * @return Boolean value.
197 ***********************************************************************************************************/
198
199bool G4GIDI::isThisDataAvailable( std::string const &a_lib_name, int a_Z, int a_A, int a_M ) const {
200
201 return( isThisDataAvailable( a_lib_name, G4GIDI_Misc_Z_A_m_ToName( a_Z, a_A, a_M ) ) );
202}
203
204/* *********************************************************************************************************//**
205 * Returns **true** if the specified target exists in a map file and **false** otherwise.
206 *
207 * @param a_lib_name [in] The evaluation. Call be an empty string.
208 * @param a_targetName [in] The target PoPs id.
209 *
210 * @return Boolean value.
211 ***********************************************************************************************************/
212
213bool G4GIDI::isThisDataAvailable( std::string const &a_lib_name, std::string const &a_targetName ) const {
214
215 for( auto mapIter = m_maps.begin( ); mapIter!= m_maps.end( ); ++mapIter ) {
216 if( (*mapIter)->isProtareAvailable( m_projectile, a_targetName, "", a_lib_name ) ) return( true );
217 }
218
219 return( false );
220}
221
222/* *********************************************************************************************************//**
223 * Returns the file path to the specified target or **nullptr** if the target does not exists.
224 *
225 * @param a_lib_name [in] The evaluation. Call be an empty string.
226 * @param a_Z [in] The atomic number of the target.
227 * @param a_A [in] The mass number of the taret.
228 * @param a_M [in] The meta-stable index of the target.
229 *
230 * @return A std::string of the protare's path.
231 ***********************************************************************************************************/
232
233std::string G4GIDI::dataFilename( std::string const &a_lib_name, int a_Z, int a_A, int a_M ) const {
234
235 return( dataFilename( a_lib_name, G4GIDI_Misc_Z_A_m_ToName( a_Z, a_A, a_M ) ) );
236}
237
238/* *********************************************************************************************************//**
239 * Returns the file path to the specified target or **nullptr** if the target does not exists.
240 *
241 * @param a_lib_name [in] The evaluation. Call be an empty string.
242 * @param a_targetName [in] The target PoPs id.
243 *
244 * @return Boolean value.
245 ***********************************************************************************************************/
246
247std::string G4GIDI::dataFilename( std::string const &a_lib_name, std::string const &a_targetName ) const {
248
249 for( auto mapIter = m_maps.begin( ); mapIter!= m_maps.end( ); ++mapIter ) {
250 std::string path = (*mapIter)->protareFilename( m_projectile, a_targetName, "", a_lib_name );
251 if( path != "" ) return( path );
252 }
253
254 return( "" );
255}
256
257/* *********************************************************************************************************//**
258 * Determines target name from *a_Z*, *a_A* and *a_M* and calls **getNamesOfAvailableLibraries** with target's name, and returns
259 * its return value.
260 *
261 * @param a_Z [in] The atomic number of the target.
262 * @param a_A [in] The mass number of the taret.
263 * @param a_M [in] The meta-stable index of the target.
264 *
265 * @return Pointer to vector<string>.
266 ***********************************************************************************************************/
267
268std::vector<std::string> *G4GIDI::getNamesOfAvailableLibraries( G4int a_Z, G4int a_A, G4int a_M ) const {
269
270 return( getNamesOfAvailableLibraries( G4GIDI_Misc_Z_A_m_ToName( a_Z, a_A, a_M ) ) );
271}
272
273/* *********************************************************************************************************//**
274 * Returns the list of all evaluations that have a target named *a_targetName*. User is responsible for freeing the returned list.
275 *
276 * @return Pointer to vector<string>.
277 ***********************************************************************************************************/
278
279std::vector<std::string> *G4GIDI::getNamesOfAvailableLibraries( std::string const &a_targetName ) const {
280
281 std::vector<std::string> *listOfLibraries = new std::vector<std::string>( );
282
283 for( auto mapIter = m_maps.cbegin( ); mapIter != m_maps.cend( ); ++mapIter ) {
284 std::vector<GIDI::Map::ProtareBase const *> entries;
285 (*mapIter)->findProtareEntries( entries, std::regex( m_projectile ), std::regex( a_targetName ) );
286 for( auto entryIter = entries.begin( ); entryIter != entries.end( ); ++entryIter ) {
287 listOfLibraries->push_back( (*entryIter)->evaluation( ) );
288 }
289 }
290
291 return( listOfLibraries );
292}
293
294/* *********************************************************************************************************//**
295 * Returns the list of available targets for *this*.
296 *
297 * @return Returns a pointer that the user owns (i.e., the user is responsible for free-ing).
298 ***********************************************************************************************************/
299
300std::vector<std::string> *G4GIDI::getNamesOfAvailableTargets( ) const {
301
302 std::vector<std::string> *list = new std::vector<std::string>( );
303 std::set<std::string> targetIDs;
304
305 for( auto mapIter = m_maps.begin( ); mapIter!= m_maps.end( ); ++mapIter ) {
306 auto protareBases = (*mapIter)->directory( m_projectile );
307
308 for( auto protareBaseIter = protareBases.begin( ); protareBaseIter != protareBases.end( ); ++protareBaseIter ) {
309 targetIDs.insert( (*protareBaseIter)->targetID( ) );
310 }
311 }
312
313 for( auto targetIter = targetIDs.begin( ); targetIter != targetIDs.end( ); ++targetIter ) {
314 (*list).push_back( (*targetIter) );
315 }
316
317 return( list );
318}
319
320/* *********************************************************************************************************//**
321 * Returns the specified target or **nullptr** if the target does not exists.
322 *
323 * @param a_lib_name [in] The evaluation. Call be an empty string.
324 * @param a_Z [in] The atomic number of the target.
325 * @param a_A [in] The mass number of the taret.
326 * @param a_M [in] The meta-stable index of the target.
327 *
328 * @return Boolean value.
329 ***********************************************************************************************************/
330
331G4GIDI_target *G4GIDI::readTarget( std::string const &a_lib_name, int a_Z, int a_A, int a_M, bool bind ) {
332
333 return( readTarget( a_lib_name, G4GIDI_Misc_Z_A_m_ToName( a_Z, a_A, a_M ), bind ) );
334}
335
336/* *********************************************************************************************************//**
337 * Returns the protare specified by *a_targetName* and the projectile for *this*.
338 *
339 * @param a_lib_name [in] The evaluation. Call be an empty std::string.
340 * @param a_targetName [in] The target PoPs id.
341 * @param a_bind [in] If *true*, read target is added to member *m_protares*.
342 *
343 * @return Boolean value.
344 ***********************************************************************************************************/
345
346G4GIDI_target *G4GIDI::readTarget( std::string const &a_lib_name, std::string const &a_targetName, bool a_bind ) {
347
348 for( auto iter_protare = m_protares.cbegin( ); iter_protare != m_protares.cend( ); ++iter_protare ) {
349 if( *(*iter_protare)->getName( ) == a_targetName ) return( nullptr );
350 }
351
353 construction.setGRIN_continuumGammas( true );
354
355 for( auto mapIter = m_maps.begin( ); mapIter!= m_maps.end( ); ++mapIter ) {
356 GIDI::Protare *GIDI_protare = (*mapIter)->protare( construction, G4GIDI_pops, m_projectile, a_targetName, "", a_lib_name );
357 if( GIDI_protare != nullptr ) {
359 GIDI::Styles::TemperatureInfos temperatures = GIDI_protare->temperatures( );
360 std::string label( temperatures[0].griddedCrossSection( ) );
361 MCGIDI::Transporting::MC MC( G4GIDI_pops, m_projectile, &GIDI_protare->styles( ), label, GIDI::Transporting::DelayedNeutrons::off, 20 ); // FIXME: 20
362 MC.setThrowOnError( false );
364 MCGIDI::DomainHash domainHash( 4000, 1e-8, 10 );
365 std::set<size_t> reactionsToExclude;
366
369 particles.add( neutron );
370
371 GIDI::Styles::TemperatureInfos temperatures1;
372 temperatures1.push_back( temperatures[0] );
373 MCGIDI::Protare *MCGIDI_protare = MCGIDI::protareFromGIDIProtare( smr, *GIDI_protare, G4GIDI_pops, MC, particles, domainHash,
374 temperatures1, reactionsToExclude );
375 //if( !smr.isOk( ) ) throw LUPI::Exception( smr.constructFullMessage( "G4GIDI::readTarget:" ) );
376
377 G4GIDI_target *protare = new G4GIDI_target( G4GIDI_pops, domainHash, *GIDI_protare, MCGIDI_protare );
378 delete GIDI_protare;
379 if( a_bind ) m_protares.push_back( protare );
380 return( protare );
381 }
382 }
383
384 return( nullptr );
385}
386
387/* *********************************************************************************************************//**
388 * Determines target name from *a_Z*, *a_A* and *a_M* and calls **getAlreadyReadTarget** with target's name, and returns
389 * its return value.
390 *
391 * @param a_Z [in] The atomic number of the target.
392 * @param a_A [in] The mass number of the taret.
393 * @param a_M [in] The meta-stable index of the target.
394 *
395 * @return Pointer to an **G4GIDI_target** instance of **nullptr**.
396 ***********************************************************************************************************/
397
399
400 return( getAlreadyReadTarget( G4GIDI_Misc_Z_A_m_ToName( a_Z, a_A, a_M ) ) );
401}
402
403/* *********************************************************************************************************//**
404 * Returns the pointer to the **G4GIDI_target** with name *a_targetName* in member *m_protares* or **nullptr** if one
405 * does not exists in *m_protares*.
406 *
407 * @param a_targetName [in] The name of the target.
408 *
409 * @return Pointer to an **G4GIDI_target** instance of **nullptr**.
410 ***********************************************************************************************************/
411
412G4GIDI_target *G4GIDI::getAlreadyReadTarget( std::string const &a_targetName ) {
413
414 for( auto iter_protare = m_protares.cbegin( ); iter_protare != m_protares.cend( ); ++iter_protare ) {
415 if( *(*iter_protare)->getName( ) == a_targetName ) return( *iter_protare );
416 }
417
418 return( nullptr );
419}
420
421/* *********************************************************************************************************//**
422 * If *a_target* is in member *m_protares*, removed it from *m_protares*, delete it and return 0. Otherwise,
423 * do nothing and return 1.
424 *
425 * @param a_target [in] The evaluation. Call be an empty std::string.
426 *
427 * @return Integer value.
428 ***********************************************************************************************************/
429
431
432 for( auto iter_protare = m_protares.cbegin( ); iter_protare != m_protares.cend( ); ++iter_protare ) {
433 if( *iter_protare == a_target ) {
434 m_protares.erase( iter_protare );
435 delete a_target;
436 return( 0 );
437 }
438 }
439 return( 1 );
440}
441
442/* *********************************************************************************************************//**
443 * Determines target name from *a_Z*, *a_A* and *a_M* and calls **freeTarget** with target's name, and returns
444 * its return value.
445 *
446 * @param a_Z [in] The atomic number of the target.
447 * @param a_A [in] The mass number of the taret.
448 * @param a_M [in] The meta-stable index of the target.
449 *
450 * @return Integer value.
451 ***********************************************************************************************************/
452
454
455 return( freeTarget( G4GIDI_Misc_Z_A_m_ToName( a_Z, a_A, a_M ) ) );
456}
457
458/* *********************************************************************************************************//**
459 * If target with name *targetSymbol* is in member *m_protares*, call **freeTarget** with target's pointer and return **freeTarget**'s return value.
460 * Otherwise, return 1.
461 *
462 * @return Integer value.
463 ***********************************************************************************************************/
464
465G4int G4GIDI::freeTarget( std::string const &targetSymbol ) {
466
467 for( auto iter_protare = m_protares.cbegin( ); iter_protare != m_protares.cend( ); ++iter_protare ) {
468 if( *(*iter_protare)->getName( ) == targetSymbol ) return( freeTarget( *iter_protare ) );
469 }
470 return( 1 );
471}
472
473/* *********************************************************************************************************//**
474 * If target with name *targetSymbol* is in member *m_protares*, call **freeTarget** with target's pointer and return **freeTarget**'s return value.
475 * Otherwise, return 1.
476 *
477 * @return Integer value.
478 ***********************************************************************************************************/
479
480std::vector<std::string> *G4GIDI::getListOfReadTargetsNames( void ) {
481
482 std::vector<std::string> *listOfTargets = new std::vector<std::string>( );
483
484 for( auto iter_protare = m_protares.cbegin( ); iter_protare != m_protares.cend( ); ++iter_protare ) {
485 listOfTargets->push_back( *(*iter_protare)->getName( ) );
486 }
487
488 return( listOfTargets );
489}
void G4GIDI_initialize(std::string const &a_dataPath)
Definition G4GIDI.cc:66
std::string G4GIDI_Misc_Z_A_m_ToName(int a_Z, int a_A, int a_M)
PoPI::Database G4GIDI_pops
Definition G4GIDI.cc:29
int G4int
Definition G4Types.hh:85
G4GIDI(G4int a_ip, std::string const &a_dataDirectory)
Definition G4GIDI.cc:84
std::vector< std::string > * getListOfReadTargetsNames()
Definition G4GIDI.cc:480
std::vector< std::string > * getDataDirectories() const
Definition G4GIDI.cc:177
std::vector< std::string > * getNamesOfAvailableLibraries(G4int a_Z, G4int a_A, G4int a_M=0) const
Definition G4GIDI.cc:268
G4int addDataDirectory(std::string const &a_dataDirectory)
Definition G4GIDI.cc:121
G4GIDI_target * readTarget(std::string const &lib_name, G4int a_Z, G4int a_A, G4int a_M=0, bool a_bind=true)
Definition G4GIDI.cc:331
std::vector< std::string > * getNamesOfAvailableTargets() const
Definition G4GIDI.cc:300
std::string const getDataDirectoryAtIndex(G4int a_index) const
Definition G4GIDI.cc:162
G4int removeDataDirectory(std::string const &a_dataDirectory)
Definition G4GIDI.cc:138
~G4GIDI()
Definition G4GIDI.cc:109
G4int freeTarget(G4int a_Z, G4int a_A, G4int a_M=0)
Definition G4GIDI.cc:453
G4GIDI_target * getAlreadyReadTarget(G4int a_Z, G4int a_A, G4int a_M=0)
Definition G4GIDI.cc:398
std::string dataFilename(std::string const &lib_name, G4int a_Z, G4int a_A, G4int a_M=0) const
Definition G4GIDI.cc:233
bool isThisDataAvailable(std::string const &a_lib_name, G4int a_Z, G4int a_A, G4int a_M=0) const
Definition G4GIDI.cc:199
void setGRIN_continuumGammas(bool a_GRIN_continuumGammas)
Definition GIDI.hpp:576
virtual Styles::TemperatureInfos temperatures() const =0
virtual Styles::Suite & styles()=0
virtual ProtareSingle * protare(std::size_t a_index)=0
bool add(Particle const &a_particle)
void setThrowOnError(bool a_throwOnError)
Definition GIDI.hpp:3739
LUPI_HOST void setSampleNonTransportingParticles(bool a_sampleNonTransportingParticles)
Definition MCGIDI.hpp:149
std::vector< Styles::TemperatureInfo > TemperatureInfos
Definition GIDI.hpp:3440
LUPI_HOST Protare * protareFromGIDIProtare(LUPI::StatusMessageReporting &a_smr, GIDI::Protare const &a_protare, PoPI::Database const &a_pops, Transporting::MC &a_settings, GIDI::Transporting::Particles const &a_particles, DomainHash const &a_domainHash, GIDI::Styles::TemperatureInfos const &a_temperatureInfos, GIDI::ExcludeReactionsSet const &a_reactionsToExclude, std::size_t a_reactionsToExcludeOffset=0, bool a_allowFixedGrid=true)
std::string to_string(G4FermiAtomicMass mass)
static std::string const photon
Definition PoPI.hpp:162
static std::string const neutron
Definition PoPI.hpp:164
static std::string const familiarTriton
Definition PoPI.hpp:168
static std::string const familiarHelion
Definition PoPI.hpp:169
static std::string const proton
Definition PoPI.hpp:165
static std::string const familiarAlpha
Definition PoPI.hpp:170
static std::string const familiarDeuteron
Definition PoPI.hpp:167