Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19279469
D126.1759144973.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D126.1759144973.diff
View Options
diff --git a/EvtGenExternal/EvtPHOTOS.hh b/EvtGenExternal/EvtPHOTOS.hh
--- a/EvtGenExternal/EvtPHOTOS.hh
+++ b/EvtGenExternal/EvtPHOTOS.hh
@@ -67,14 +67,21 @@
int getNumberOfPhotons( const GenVertexPtr theVertex ) const;
+ // Use EvtGen's random number generator
+ bool m_useEvtGenRandom = true;
+
+ // Default settings for PHOTOS
+ // Minimum photon Energy (infrared cut-off).
+ double m_infraredCutOff = 1.0e-7;
+ // Maximum value of the interference weight
+ double m_maxWtInterference = 64.0;
+
// Default photon type, id, pdg number and mass
std::string m_photonType = "gamma";
EvtId m_gammaId = EvtId( -1, -1 );
- int m_gammaPDG = 22;
- double m_mPhoton = 0.0;
-
- bool m_initialised = false;
+ long int m_gammaPDG = 22;
+ static bool m_initialised;
static std::mutex m_photos_mutex;
};
diff --git a/EvtGenExternal/EvtSherpaPhotons.hh b/EvtGenExternal/EvtSherpaPhotons.hh
--- a/EvtGenExternal/EvtSherpaPhotons.hh
+++ b/EvtGenExternal/EvtSherpaPhotons.hh
@@ -55,9 +55,6 @@
// Updates the particle properties table of Sherpa
void updateParticleLists();
- // The Sherpa instance.
- std::unique_ptr<SHERPA::Sherpa> m_sherpaGen;
-
// Vector containing the configuration strings for Sherpa
// INIT_ONLY=6 intialises the Sherpa objects without launching simulation.
std::vector<std::string> m_configs{ "Sherpa", "INIT_ONLY=6" };
@@ -78,7 +75,11 @@
const std::string m_photonType = "gamma";
EvtId m_gammaId = EvtId( -1, -1 );
long int m_gammaPDG = 22;
- bool m_initialised = false;
+
+ // The Sherpa instance.
+ static std::unique_ptr<SHERPA::Sherpa> m_sherpaGen;
+ static bool m_initialised;
+ static std::mutex m_sherpa_mutex;
};
#endif
diff --git a/History.md b/History.md
--- a/History.md
+++ b/History.md
@@ -11,6 +11,13 @@
===
## R02-0X-00
+3 July 2024 Fernando Abudinen
+* D126: Fix FSR initialisation for thread safety.
+ - Modified PHOTOS and Sherpa instances to become global static members
+ and made sure that they are initialised only once.
+ - Made sure that calls to these instances are mutexed.
+ - Made sure that all interface class members are initialised for each thread.
+
1 July 2024 Fernando Abudinen
* D125: Removed `EventHandler` in `EvtSherpaPhotons` interface to reduce initialisation overhead.
diff --git a/src/EvtGenExternal/EvtPHOTOS.cpp b/src/EvtGenExternal/EvtPHOTOS.cpp
--- a/src/EvtGenExternal/EvtPHOTOS.cpp
+++ b/src/EvtGenExternal/EvtPHOTOS.cpp
@@ -35,18 +35,40 @@
using std::endl;
// Mutex PHOTOS as it is not thread safe.
+bool EvtPHOTOS::m_initialised = false;
std::mutex EvtPHOTOS::m_photos_mutex;
EvtPHOTOS::EvtPHOTOS( const std::string& photonType, const bool useEvtGenRandom,
const double infraredCutOff,
const double maxWtInterference ) :
+ m_useEvtGenRandom{ useEvtGenRandom },
+ m_infraredCutOff{ infraredCutOff },
+ m_maxWtInterference{ maxWtInterference },
m_photonType{ photonType }
{
+}
+
+void EvtPHOTOS::initialise()
+{
m_photos_mutex.lock();
+ m_gammaId = EvtPDL::getId( m_photonType );
+ if ( m_gammaId == EvtId( -1, -1 ) ) {
+ EvtGenReport( EVTGEN_INFO, "EvtGen" )
+ << "Error in EvtPHOTOS. Do not recognise the photon type "
+ << m_photonType << ". Setting this to \"gamma\". " << endl;
+ m_gammaId = EvtPDL::getId( "gamma" );
+ }
+ m_gammaPDG = EvtPDL::getStdHep( m_gammaId );
+
+ if ( m_initialised ) {
+ m_photos_mutex.unlock();
+ return;
+ }
+
EvtGenReport( EVTGEN_INFO, "EvtGen" ) << "Setting up PHOTOS." << endl;
- if ( useEvtGenRandom ) {
+ if ( m_useEvtGenRandom ) {
EvtGenReport( EVTGEN_INFO, "EvtGen" )
<< "Using EvtGen random number engine also for Photos++" << endl;
@@ -62,14 +84,14 @@
* This must be done after exponentiation! Keep the cut at 1e-7, i.e. 0.1 keV at the 1 GeV scale,
* which is appropriate for B decays
*/
- Photospp::Photos::setInfraredCutOff( infraredCutOff );
+ Photospp::Photos::setInfraredCutOff( m_infraredCutOff );
Photospp::Photos::setInterference( true );
/* Increase the maximum possible value of the interference weight
* corresponding to 2^n, where n = number of charges (+,-).
*/
- Photospp::Photos::maxWtInterference( maxWtInterference );
+ Photospp::Photos::maxWtInterference( m_maxWtInterference );
#ifdef EVTGEN_PHOTOS_NEWLIBS
// This turns off/on virtual photons splitting into l+l-
@@ -77,27 +99,9 @@
Photospp::Photos::setPairEmission( false );
#endif
- m_photos_mutex.unlock();
-}
-
-void EvtPHOTOS::initialise()
-{
- if ( m_initialised ) {
- return;
- }
- m_gammaId = EvtPDL::getId( m_photonType );
-
- if ( m_gammaId == EvtId( -1, -1 ) ) {
- EvtGenReport( EVTGEN_INFO, "EvtGen" )
- << "Error in EvtPHOTOS. Do not recognise the photon type "
- << m_photonType << ". Setting this to \"gamma\". " << endl;
- m_gammaId = EvtPDL::getId( "gamma" );
- }
-
- m_gammaPDG = EvtPDL::getStdHep( m_gammaId );
- m_mPhoton = EvtPDL::getMeanMass( m_gammaId );
-
m_initialised = true;
+
+ m_photos_mutex.unlock();
}
void EvtPHOTOS::doRadCorr( EvtParticle* theParticle )
diff --git a/src/EvtGenExternal/EvtSherpaPhotons.cpp b/src/EvtGenExternal/EvtSherpaPhotons.cpp
--- a/src/EvtGenExternal/EvtSherpaPhotons.cpp
+++ b/src/EvtGenExternal/EvtSherpaPhotons.cpp
@@ -38,6 +38,10 @@
using std::endl;
+std::unique_ptr<SHERPA::Sherpa> EvtSherpaPhotons::m_sherpaGen;
+bool EvtSherpaPhotons::m_initialised = false;
+std::mutex EvtSherpaPhotons::m_sherpa_mutex;
+
EvtSherpaPhotons::EvtSherpaPhotons( const bool useEvtGenRandom,
const double infraredCutOff, const int mode,
const int useME ) :
@@ -50,7 +54,13 @@
void EvtSherpaPhotons::initialise()
{
+ m_sherpa_mutex.lock();
+
+ m_gammaId = EvtPDL::getId( m_photonType );
+ m_gammaPDG = EvtPDL::getStdHep( m_gammaId );
+
if ( m_initialised ) {
+ m_sherpa_mutex.unlock();
return;
}
@@ -114,12 +124,11 @@
m_sherpaGen = std::make_unique<SHERPA::Sherpa>();
m_sherpaGen->InitializeTheRun( argv.size(), &argv[0] );
- m_gammaId = EvtPDL::getId( m_photonType );
- m_gammaPDG = EvtPDL::getStdHep( m_gammaId );
-
this->updateParticleLists();
m_initialised = true;
+
+ m_sherpa_mutex.unlock();
}
std::vector<char*> EvtSherpaPhotons::addParameters()
@@ -248,6 +257,8 @@
blob->AddToOutParticles( daughter_part );
}
+ m_sherpa_mutex.lock();
+
const SHERPA::Initialization_Handler* inithandler =
m_sherpaGen->GetInitHandler();
SHERPA::Soft_Photon_Handler* softphotonhandler =
@@ -256,6 +267,8 @@
// Simulate the radiation
softphotonhandler->AddRadiation( blob.get() );
+ m_sherpa_mutex.unlock();
+
// Get number of final-state particles
const int nFinal( blob->NOutP() );
@@ -286,8 +299,6 @@
}
}
}
-
- return;
}
#endif
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Sep 29, 12:22 PM (22 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6527519
Default Alt Text
D126.1759144973.diff (6 KB)
Attached To
Mode
D126: Fix FSR initialisation for thread safety
Attached
Detach File
Event Timeline
Log In to Comment