From dd6062b8bc4d9bb616325e437c0f3bb27df7de5f Mon Sep 17 00:00:00 2001 From: Tadej Novak <tadej.novak@cern.ch> Date: Wed, 24 Feb 2021 11:08:12 +0100 Subject: [PATCH 1/2] Use RandBinomialFixedP in TRT digi --- .../TRT_Digitization/CMakeLists.txt | 2 +- .../src/TRTProcessingOfStraw.cxx | 54 ++++++++++--------- .../src/TRTProcessingOfStraw.h | 15 +++--- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/InnerDetector/InDetDigitization/TRT_Digitization/CMakeLists.txt b/InnerDetector/InDetDigitization/TRT_Digitization/CMakeLists.txt index cbb2a16b6f06..bb1fb32c56f6 100644 --- a/InnerDetector/InDetDigitization/TRT_Digitization/CMakeLists.txt +++ b/InnerDetector/InDetDigitization/TRT_Digitization/CMakeLists.txt @@ -12,7 +12,7 @@ atlas_add_component( TRT_Digitization src/*.cxx src/components/*.cxx INCLUDE_DIRS ${HEPPDT_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} - LINK_LIBRARIES ${HEPPDT_LIBRARIES} ${CLHEP_LIBRARIES} GaudiKernel AthenaBaseComps AthenaKernel CxxUtils PileUpToolsLib AthenaPoolUtilities GeoModelInterfaces GeoModelUtilities GeoPrimitives Identifier GeneratorObjects TRT_ConditionsData TRT_ConditionsServicesLib InDetIdentifier TRT_ReadoutGeometry InDetRawData InDetSimData InDetSimEvent HitManagement MagFieldElements MagFieldConditions TRT_PAI_ProcessLib StoreGateLib xAODEventInfo ) + LINK_LIBRARIES ${HEPPDT_LIBRARIES} ${CLHEP_LIBRARIES} GaudiKernel AthenaBaseComps AthenaKernel CxxUtils PileUpToolsLib AthenaPoolUtilities GeoModelInterfaces GeoModelUtilities GeoPrimitives Identifier GeneratorObjects TRT_ConditionsData TRT_ConditionsServicesLib InDetIdentifier TRT_ReadoutGeometry InDetRawData InDetSimData InDetSimEvent HitManagement MagFieldElements MagFieldConditions TRT_PAI_ProcessLib StoreGateLib xAODEventInfo AtlasCLHEP_RandomGenerators ) # Install files from the package: atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8} ) diff --git a/InnerDetector/InDetDigitization/TRT_Digitization/src/TRTProcessingOfStraw.cxx b/InnerDetector/InDetDigitization/TRT_Digitization/src/TRTProcessingOfStraw.cxx index c94e2a6653e9..818c0fad2f6b 100644 --- a/InnerDetector/InDetDigitization/TRT_Digitization/src/TRTProcessingOfStraw.cxx +++ b/InnerDetector/InDetDigitization/TRT_Digitization/src/TRTProcessingOfStraw.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "TRTProcessingOfStraw.h" @@ -101,11 +101,6 @@ void TRTProcessingOfStraw::Initialize(const ITRT_CalDbTool* calDbTool) m_outerRadiusOfWire = m_settings->outerRadiusOfWire(); m_timeCorrection = m_settings->timeCorrection(); // false for beamType='cosmics' m_solenoidFieldStrength = m_settings->solenoidFieldStrength(); - m_ionisationPotential = m_settings->ionisationPotential(0); // strawGasType=0 here just to initialize - m_smearingFactor = m_settings->smearingFactor(0); // to keep coverity happy. Reset correctly later. - m_trEfficiencyBarrel = m_settings->trEfficiencyBarrel(0); // - m_trEfficiencyEndCapA = m_settings->trEfficiencyEndCapA(0); // - m_trEfficiencyEndCapB = m_settings->trEfficiencyEndCapB(0); // m_maxelectrons = 100; // 100 gives good Gaussian approximation @@ -202,6 +197,9 @@ void TRTProcessingOfStraw::Initialize(const ITRT_CalDbTool* calDbTool) } } + m_randBinomialXe = std::make_unique<CLHEP::RandBinomialFixedP>(nullptr, 1, m_settings->smearingFactor(0), m_maxelectrons); + m_randBinomialKr = std::make_unique<CLHEP::RandBinomialFixedP>(nullptr, 1, m_settings->smearingFactor(1), m_maxelectrons); + m_randBinomialAr = std::make_unique<CLHEP::RandBinomialFixedP>(nullptr, 1, m_settings->smearingFactor(2), m_maxelectrons); ATH_MSG_VERBOSE ( "Initialization done" ); @@ -369,31 +367,31 @@ void TRTProcessingOfStraw::ProcessStraw ( MagField::AtlasFieldCache& fieldCache, double KrEmulationScaling_ECB = 0.39; if (isBarrel) { // Barrel - m_trEfficiencyBarrel = m_settings->trEfficiencyBarrel(strawGasType); + double trEfficiencyBarrel = m_settings->trEfficiencyBarrel(strawGasType); double hitx = TRThitGlobalPos[0]; double hity = TRThitGlobalPos[1]; double hitz = TRThitGlobalPos[2]; double hitEta = fabs(log(tan(0.5*atan2(sqrt(hitx*hitx+hity*hity),hitz)))); - if ( hitEta < 0.5 ) { m_trEfficiencyBarrel *= ( 0.833333+0.6666667*hitEta*hitEta ); } + if ( hitEta < 0.5 ) { trEfficiencyBarrel *= ( 0.833333+0.6666667*hitEta*hitEta ); } // scale down the TR efficiency if we are emulating - if ( strawGasType == 0 && emulationArflag ) { m_trEfficiencyBarrel = m_trEfficiencyBarrel*ArEmulationScaling_BA; } - if ( strawGasType == 0 && emulationKrflag ) { m_trEfficiencyBarrel = m_trEfficiencyBarrel*KrEmulationScaling_BA; } - if ( CLHEP::RandFlat::shoot(rndmEngine) > m_trEfficiencyBarrel ) continue; // Skip this photon + if ( strawGasType == 0 && emulationArflag ) { trEfficiencyBarrel *= ArEmulationScaling_BA; } + if ( strawGasType == 0 && emulationKrflag ) { trEfficiencyBarrel *= KrEmulationScaling_BA; } + if ( CLHEP::RandFlat::shoot(rndmEngine) > trEfficiencyBarrel ) continue; // Skip this photon } // close if barrel else { // Endcap - no eta dependence here. if (isECA) { - m_trEfficiencyEndCapA = m_settings->trEfficiencyEndCapA(strawGasType); + double trEfficiencyEndCapA = m_settings->trEfficiencyEndCapA(strawGasType); // scale down the TR efficiency if we are emulating - if ( strawGasType == 0 && emulationArflag ) { m_trEfficiencyEndCapA = m_trEfficiencyEndCapA*ArEmulationScaling_ECA; } - if ( strawGasType == 0 && emulationKrflag ) { m_trEfficiencyEndCapA = m_trEfficiencyEndCapA*KrEmulationScaling_ECA; } - if ( CLHEP::RandFlat::shoot(rndmEngine) > m_trEfficiencyEndCapA ) continue; // Skip this photon + if ( strawGasType == 0 && emulationArflag ) { trEfficiencyEndCapA *= ArEmulationScaling_ECA; } + if ( strawGasType == 0 && emulationKrflag ) { trEfficiencyEndCapA *= KrEmulationScaling_ECA; } + if ( CLHEP::RandFlat::shoot(rndmEngine) > trEfficiencyEndCapA ) continue; // Skip this photon } if (isECB) { - m_trEfficiencyEndCapB = m_settings->trEfficiencyEndCapB(strawGasType); + double trEfficiencyEndCapB = m_settings->trEfficiencyEndCapB(strawGasType); // scale down the TR efficiency if we are emulating - if ( strawGasType == 0 && emulationArflag ) { m_trEfficiencyEndCapB = m_trEfficiencyEndCapB*ArEmulationScaling_ECB; } - if ( strawGasType == 0 && emulationKrflag ) { m_trEfficiencyEndCapB = m_trEfficiencyEndCapB*KrEmulationScaling_ECB; } - if ( CLHEP::RandFlat::shoot(rndmEngine) > m_trEfficiencyEndCapB ) continue; // Skip this photon + if ( strawGasType == 0 && emulationArflag ) { trEfficiencyEndCapB *= ArEmulationScaling_ECB; } + if ( strawGasType == 0 && emulationKrflag ) { trEfficiencyEndCapB *= KrEmulationScaling_ECB; } + if ( CLHEP::RandFlat::shoot(rndmEngine) > trEfficiencyEndCapB ) continue; // Skip this photon } } // close else (end caps) } // energyDeposit < 30.0 @@ -578,8 +576,14 @@ void TRTProcessingOfStraw::ClustersToDeposits (MagField::AtlasFieldCache& fieldC //const bool isECA (region==3); //const bool isECB (region==4); - m_ionisationPotential = m_settings->ionisationPotential(strawGasType); - m_smearingFactor = m_settings->smearingFactor(strawGasType); + CLHEP::RandBinomialFixedP *randBinomial{}; + if (strawGasType == 0) { randBinomial = m_randBinomialXe.get(); } + else if (strawGasType == 1) { randBinomial = m_randBinomialKr.get(); } + else if (strawGasType == 2) { randBinomial = m_randBinomialAr.get(); } + else { randBinomial = m_randBinomialXe.get(); } // should never happen + + double ionisationPotential = m_settings->ionisationPotential(strawGasType); + double smearingFactor = m_settings->smearingFactor(strawGasType); std::vector<cluster>::const_iterator currentClusterIter(clusters.begin()); const std::vector<cluster>::const_iterator endOfClusterList(clusters.end()); @@ -652,7 +656,7 @@ void TRTProcessingOfStraw::ClustersToDeposits (MagField::AtlasFieldCache& fieldC const double cluster_r(std::sqrt(cluster_r2)); // cluster radius const double cluster_E(currentClusterIter->energy); // cluster energy - const unsigned int nprimaryelectrons( static_cast<unsigned int>( cluster_E/m_ionisationPotential + 1.0 ) ); + const unsigned int nprimaryelectrons( static_cast<unsigned int>( cluster_E / ionisationPotential + 1.0 ) ); // Determine the number of surviving electrons and their energy sum. // If nprimaryelectrons > 100 then a Gaussian approximation is good (and much quicker) @@ -661,16 +665,16 @@ void TRTProcessingOfStraw::ClustersToDeposits (MagField::AtlasFieldCache& fieldC if (nprimaryelectrons<m_maxelectrons) // Use the detailed Binomial and Exponential treatment at this low energy. { - unsigned int nsurvivingprimaryelectrons = static_cast<unsigned int>(CLHEP::RandBinomial::shoot(rndmEngine,nprimaryelectrons,m_smearingFactor) + 0.5); + unsigned int nsurvivingprimaryelectrons = static_cast<unsigned int>(randBinomial->fire(rndmEngine,nprimaryelectrons) + 0.5); if (nsurvivingprimaryelectrons==0) continue; // no electrons survived; move on to the next cluster. - const double meanElectronEnergy(m_ionisationPotential/m_smearingFactor); + const double meanElectronEnergy(ionisationPotential / smearingFactor); for (unsigned int ielec(0); ielec<nsurvivingprimaryelectrons; ++ielec) { depositEnergy += CLHEP::RandExpZiggurat::shoot(rndmEngine, meanElectronEnergy); } } else // Use a Gaussian approximation { - const double fluctSigma(sqrt(cluster_E*m_ionisationPotential*(2-m_smearingFactor)/m_smearingFactor)); + const double fluctSigma(sqrt(cluster_E * ionisationPotential * (2 - smearingFactor) / smearingFactor)); do { depositEnergy = CLHEP::RandGaussZiggurat::shoot(rndmEngine, cluster_E, fluctSigma); } while(depositEnergy<0.0); // very rare. diff --git a/InnerDetector/InDetDigitization/TRT_Digitization/src/TRTProcessingOfStraw.h b/InnerDetector/InDetDigitization/TRT_Digitization/src/TRTProcessingOfStraw.h index 10832afee4e8..45d63b7f62f1 100644 --- a/InnerDetector/InDetDigitization/TRT_Digitization/src/TRTProcessingOfStraw.h +++ b/InnerDetector/InDetDigitization/TRT_Digitization/src/TRTProcessingOfStraw.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TRT_DIGITIZATION_TRTPROCESSINGOFSTRAW_H @@ -31,7 +31,9 @@ #include "GeoPrimitives/GeoPrimitives.h" #include "CLHEP/Random/RandomEngine.h" +#include "AtlasCLHEP_RandomGenerators/RandBinomialFixedP.h" +#include <memory> #include <vector> class TRTDigit; @@ -125,22 +127,15 @@ private: ITRT_PAITool* m_pPAItoolKr; ITRT_SimDriftTimeTool* m_pSimDriftTimeTool; - /** TR efficiency: this fraction of TR photons will be kept */ - double m_trEfficiencyBarrel; - double m_trEfficiencyEndCapA; - double m_trEfficiencyEndCapB; - /** Time to be corrected for flight and wire propagation delays false when beamType='cosmics' */ bool m_timeCorrection; - double m_ionisationPotential; double m_signalPropagationSpeed; double m_attenuationLength; bool m_useAttenuation; bool m_useMagneticFieldMap; - double m_smearingFactor; double m_maxCrossingTime; double m_minCrossingTime; double m_shiftOfZeroPoint; @@ -242,6 +237,10 @@ private: mutable Athena::MsgStreamMember m_msg ATLAS_THREAD_SAFE; + std::unique_ptr<CLHEP::RandBinomialFixedP> m_randBinomialXe{}; + std::unique_ptr<CLHEP::RandBinomialFixedP> m_randBinomialKr{}; + std::unique_ptr<CLHEP::RandBinomialFixedP> m_randBinomialAr{}; + protected: const TRT_ID* m_id_helper; -- GitLab From d9124e61c07fc0d0dc2b510d094d04cc2317eb11 Mon Sep 17 00:00:00 2001 From: Tadej Novak <tadej.novak@cern.ch> Date: Sat, 17 Apr 2021 10:55:59 +0200 Subject: [PATCH 2/2] Update test references due to random number changes --- Tools/PROCTools/data/master_q221_AOD_digest.ref | 16 ++++++++-------- Tools/PROCTools/python/RunTier0TestsTools.py | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Tools/PROCTools/data/master_q221_AOD_digest.ref b/Tools/PROCTools/data/master_q221_AOD_digest.ref index 3ad68adee478..e8142f43ba2e 100644 --- a/Tools/PROCTools/data/master_q221_AOD_digest.ref +++ b/Tools/PROCTools/data/master_q221_AOD_digest.ref @@ -3,22 +3,22 @@ 284500 87473014 83 79 6 0 10 1 9 7 5 2 284500 87473022 38 30 4 0 4 2 2 4 3 1 284500 87473032 30 33 4 1 10 4 6 6 3 3 - 284500 87473037 62 40 7 0 13 2 11 5 3 2 + 284500 87473037 62 41 7 0 13 2 11 5 3 2 284500 87473040 107 93 10 1 17 1 16 11 6 5 - 284500 87473051 140 111 11 1 16 1 15 23 16 7 + 284500 87473051 140 110 11 1 16 1 15 23 16 7 284500 87473063 62 76 5 2 7 1 6 6 4 2 284500 87473068 25 33 1 1 0 0 0 0 0 0 - 284500 87473075 60 87 6 1 5 0 5 6 5 1 + 284500 87473075 60 87 6 2 5 0 5 6 5 1 284500 87473084 78 86 7 2 14 1 13 9 3 6 284500 87473091 41 49 3 0 4 2 2 4 2 2 284500 87473096 66 75 3 2 3 0 3 4 3 1 284500 87473104 64 63 6 0 6 2 4 4 3 1 - 284500 87473114 89 79 7 2 12 1 11 9 6 3 - 284500 87473121 93 100 6 3 15 3 12 8 6 2 - 284500 87473132 84 56 9 1 12 0 12 3 3 0 + 284500 87473114 89 76 7 2 12 1 11 9 6 3 + 284500 87473121 93 100 6 3 15 4 11 8 6 2 + 284500 87473132 84 56 9 1 12 0 12 4 4 0 284500 87473137 94 71 8 3 15 0 15 9 9 0 - 284500 87473144 78 66 7 1 8 2 6 8 6 2 - 284500 87473154 86 88 7 0 14 3 11 9 4 5 + 284500 87473144 78 67 7 1 9 3 6 9 7 2 + 284500 87473154 86 88 7 0 13 2 11 9 4 5 284500 87473162 53 51 4 0 7 0 7 3 2 1 284500 87473167 77 54 6 3 14 2 12 13 8 5 284500 87473171 77 69 8 3 4 2 2 5 4 1 diff --git a/Tools/PROCTools/python/RunTier0TestsTools.py b/Tools/PROCTools/python/RunTier0TestsTools.py index 45d7900b2ecb..a1afee222fc3 100644 --- a/Tools/PROCTools/python/RunTier0TestsTools.py +++ b/Tools/PROCTools/python/RunTier0TestsTools.py @@ -31,10 +31,10 @@ ciRefFileMap = { # OverlayTier0Test_required-test 'overlay-d1498-21.0' : 'v2', 'overlay-d1498-22.0' : 'v38', - 'overlay-d1592-22.0' : 'v8', + 'overlay-d1592-22.0' : 'v9', 'overlay-bkg-21.0' : 'v1', 'overlay-bkg-22.0' : 'v4', - 'dataoverlay-d1590-22.0' : 'v11', + 'dataoverlay-d1590-22.0' : 'v12', 'dataoverlay-hits-22.0' : 'v1', } -- GitLab