diff --git a/InnerDetector/InDetRecTools/SiClusterizationTool/SiClusterizationTool/TruthClusterizationFactory.h b/InnerDetector/InDetRecTools/SiClusterizationTool/SiClusterizationTool/TruthClusterizationFactory.h index f69758d9c7c545a66283cf1f768d5a698cba2a37..7869912dbdc06a4d095bc2eee11b227ed5a4b425 100644 --- a/InnerDetector/InDetRecTools/SiClusterizationTool/SiClusterizationTool/TruthClusterizationFactory.h +++ b/InnerDetector/InDetRecTools/SiClusterizationTool/SiClusterizationTool/TruthClusterizationFactory.h @@ -30,9 +30,17 @@ #include "TrkParameters/TrackParameters.h" #include "GeoPrimitives/GeoPrimitives.h" #include "EventPrimitives/EventPrimitives.h" +#include "CLHEP/Random/RandomEngine.h" +#include "AthenaKernel/IAtRndmGenSvc.h" +#include "StoreGate/ReadHandleKey.h" +#include "InDetSimData/InDetSimDataCollection.h" + +//class InDetSimDataCollection; + +namespace CLHEP{ + class HepRandomEngine; +} - class InDetSimDataCollection; - namespace InDet { class PixelCluster; @@ -63,12 +71,17 @@ namespace InDet { private: /** IncidentSvc to catch begining of event and end of event */ - ServiceHandle<IIncidentSvc> m_incidentSvc; - - std::string m_simDataCollectionName; //!< sim data collection name - mutable const InDetSimDataCollection* m_simDataCollection; //!< sim data collection - refreshed at BeginEvent incident + ServiceHandle<IIncidentSvc> m_incidentSvc; + SG::ReadHandleKey<InDetSimDataCollection> m_simDataCollectionName {this, "InputSDOMap", "PixelSDO_Map", "sim data collection name"}; + mutable const InDetSimDataCollection* m_simDataCollection; //!< sim data collection - refreshed at BeginEvent incident + + protected: + ServiceHandle<IAtRndmGenSvc> m_rndmSvc; + Gaudi::Property<std::string> m_rndmEngineName {this, "RndmEngine", "TruthClustering", "Random Engine Name"}; + CLHEP::HepRandomEngine* m_rndmEngine; + }; - }//end InDet namespace +}//end InDet namespace #endif diff --git a/InnerDetector/InDetRecTools/SiClusterizationTool/src/TruthClusterizationFactory.cxx b/InnerDetector/InDetRecTools/SiClusterizationTool/src/TruthClusterizationFactory.cxx index 9c40cfee851b8a81a9a9d0b7caa27061465f522f..a992b1a8eb2f797d35ada17d78abfb9fd7bc20ec 100644 --- a/InnerDetector/InDetRecTools/SiClusterizationTool/src/TruthClusterizationFactory.cxx +++ b/InnerDetector/InDetRecTools/SiClusterizationTool/src/TruthClusterizationFactory.cxx @@ -22,28 +22,29 @@ #include "GaudiKernel/ServiceHandle.h" #include "GaudiKernel/Incident.h" -#include "InDetSimData/InDetSimDataCollection.h" #include "InDetSimData/InDetSimData.h" #include "HepMC/GenParticle.h" #include "TrkEventPrimitives/ParamDefs.h" -#include "TRandom.h" +#include "CLHEP/Random/RandFlat.h" namespace InDet { TruthClusterizationFactory::TruthClusterizationFactory(const std::string& name, const std::string& n, const IInterface* p): AthAlgTool(name, n,p), - m_incidentSvc("IncidentSvc", n), - m_simDataCollectionName("PixelSDO_Map"), - m_simDataCollection(0) - { - // further properties - declareProperty("IncidentService" , m_incidentSvc ); - - declareInterface<TruthClusterizationFactory>(this); - } + m_incidentSvc("IncidentSvc", n), + m_simDataCollection(0), + m_rndmSvc("AtDSFMTGenSvc",name), + m_rndmEngine(0) +{ + // further properties + declareProperty("IncidentService", m_incidentSvc ); + declareProperty("RndmSvc", m_rndmSvc, "Random Number Service used in TruthClusterizationFactory"); + + declareInterface<TruthClusterizationFactory>(this); + } ///////////////////////////////////////////////////////////////////////////////////// /// Destructor - check up memory allocation @@ -60,7 +61,25 @@ namespace InDet { // register to the incident service m_incidentSvc->addListener( this, "BeginEvent"); - msg(MSG::INFO) << "initialize() successful in " << name() << endmsg; + msg(MSG::INFO) << "initialize() successful in " << name() << endmsg; + + // random svc + CHECK(m_rndmSvc.retrieve()); + + // get the random stream + ATH_MSG_DEBUG ( "Getting random number engine : <" << m_rndmEngineName << ">" ); + m_rndmEngine = m_rndmSvc->GetEngine(m_rndmEngineName); + if (!m_rndmEngine) { + ATH_MSG_ERROR("Could not find RndmEngine : " << m_rndmEngineName); + return StatusCode::FAILURE; + } + else { + ATH_MSG_DEBUG("Found RndmEngine : " << m_rndmEngineName); + } + + ATH_CHECK( m_simDataCollectionName.initialize() ); + + return StatusCode::SUCCESS; } @@ -68,12 +87,16 @@ namespace InDet { { if ( inc.type() == IncidentType::BeginEvent ){ // record the SDO collection - if (evtStore()->retrieve(m_simDataCollection,m_simDataCollectionName).isFailure()){ - ATH_MSG_WARNING("Could not retrieve the InDetSimDataCollection with name " << m_simDataCollectionName); - m_simDataCollection = 0; - } else { - ATH_MSG_VERBOSE("Successfully retrieved the InDetSimDataCollection with name " << m_simDataCollectionName); - } + + SG::ReadHandle<InDetSimDataCollection> pixSdoColl(m_simDataCollectionName); + + if (!pixSdoColl.isValid()){ + ATH_MSG_WARNING("Could not retrieve the InDetSimDataCollection with name " << m_simDataCollectionName); + m_simDataCollection = 0; + } else { + ATH_MSG_VERBOSE("Successfully retrieved the InDetSimDataCollection with name " << m_simDataCollectionName); + m_simDataCollection = &(*pixSdoColl); + } } } @@ -117,8 +140,6 @@ namespace InDet { //barcodes in the cluster, each corresponding to a truth particle nPartContributing = barcodes.size(); ATH_MSG_VERBOSE("n Part Contributing: " << nPartContributing); - //Set random seed for smearing NN efficiency - gRandom->SetSeed(0); ATH_MSG_VERBOSE("Smearing TruthClusterizationFactory probability output for TIDE studies"); //If only 1 truth particles found if (nPartContributing==1) { @@ -128,14 +149,14 @@ namespace InDet { //If two unique truth particles found in cluster else if (nPartContributing==2) { //90% chance NN returns high probability of there being 2 particles - if (gRandom->Uniform(0,1) < 0.9) probabilities[1] = 1.0; + if (CLHEP::RandFlat::shoot( m_rndmEngine, 0, 1 ) < 0.9) probabilities[1] = 1.0; //Other 10% NN returns high probability of there being 1 particle else probabilities[0] = 1.0; } //If greater than 2 unique truth particles in cluster else if (nPartContributing>2) { //90% chance NN returns high probability of there being >2 particles - if (gRandom->Uniform(0,1) < 0.9) probabilities[2] = 1.0; + if (CLHEP::RandFlat::shoot( m_rndmEngine, 0, 1 ) < 0.9) probabilities[2] = 1.0; //Other 10% NN returns high probability of there being 1 particle else probabilities[0] = 1.0; }