diff --git a/TileCalorimeter/TileRecAlgs/share/TileCellCorrection_jobOptions.py b/TileCalorimeter/TileRecAlgs/share/TileCellCorrection_jobOptions.py index 1f1140bcce9b6919b29d038e7d071c0d8a3a8e53..b4448f563ddd9a6b3ff90a1f28b50c33060d1409 100644 --- a/TileCalorimeter/TileRecAlgs/share/TileCellCorrection_jobOptions.py +++ b/TileCalorimeter/TileRecAlgs/share/TileCellCorrection_jobOptions.py @@ -6,14 +6,8 @@ TccName = "TileCellCorrection" -from AthenaCommon.AppMgr import ToolSvc -from CaloTools.CaloNoiseToolDefault import CaloNoiseToolDefault -theNoiseTool = CaloNoiseToolDefault() -ToolSvc += theNoiseTool - from TileRecUtils.TileRecUtilsConf import TileCellNoiseFilter theTileCellNoiseFilter = TileCellNoiseFilter() -theTileCellNoiseFilter.CaloNoiseTool = theNoiseTool theTileCellNoiseFilter.UseTwoGaussNoise = False ToolSvc += theTileCellNoiseFilter diff --git a/TileCalorimeter/TileRecUtils/TileRecUtils/TileCellBuilderFromHit.h b/TileCalorimeter/TileRecUtils/TileRecUtils/TileCellBuilderFromHit.h index 78ae5c0e77cd61b3be9811f24b96d926dbbda10c..407de78581d72616b2a8b4262db80692fd08e95d 100644 --- a/TileCalorimeter/TileRecUtils/TileRecUtils/TileCellBuilderFromHit.h +++ b/TileCalorimeter/TileRecUtils/TileRecUtils/TileCellBuilderFromHit.h @@ -35,6 +35,7 @@ // Calo includes #include "CaloInterface/ICaloCellMakerTool.h" #include "CaloConditions/CaloAffectedRegionInfo.h" +#include "CaloConditions/CaloNoise.h" // Atlas includes #include "AthenaBaseComps/AthAlgTool.h" @@ -42,6 +43,7 @@ #include "Identifier/HWIdentifier.h" #include "AthenaKernel/IOVSvcDefs.h" #include "StoreGate/ReadHandleKey.h" +#include "StoreGate/ReadCondHandleKey.h" #include "StoreGate/WriteHandleKey.h" // Gaudi includes @@ -65,7 +67,6 @@ class TileDetDescrManager; class TileCellCollection; class CaloCellContainer; class TileCablingService; -class ICalorimeterNoiseTool; class IAtRndmGenSvc; @@ -99,6 +100,9 @@ class TileCellBuilderFromHit typedef TileDrawerEvtStatus TileDrawerEvtStatusArray[5][64]; // properties + SG::ReadCondHandleKey<CaloNoise> m_caloNoiseKey{this, "CaloNoise", + "electronicNoise", + "CaloNoise object to read"}; SG::ReadHandleKey<TileHitContainer> m_hitContainerKey{this, "TileHitContainer", "TileHitCnt", "Input Tile hit container key"}; @@ -127,8 +131,7 @@ class TileCellBuilderFromHit float m_maxTime; //!< maximum time for the PMTs in the cels float m_minTime; //!< minimum time for the PMTs in the cels bool m_maskBadChannels; //!< if true=> bad channels are masked - bool m_useNoiseTool; //!< if true=> add noise to all cells - float m_noiseSigma; //!< cell electroing noise if the CaloNoiseTool is switched off + float m_noiseSigma; //!< cell electronic noise if CaloNoise is switched off const TileID* m_tileID; //!< Pointer to TileID const TileTBID* m_tileTBID; //!< Pointer to TileTBID @@ -145,8 +148,6 @@ class TileCellBuilderFromHit ToolHandle<TileCondToolEmscale> m_tileToolEmscale{this, "TileCondToolEmscale", "TileCondToolEmscale", "Tile EM scale calibration tool"}; - ToolHandle<ICalorimeterNoiseTool> m_noiseTool; //!< Calo Noise tool with noise values - const TileDetDescrManager* m_tileMgr; //!< Pointer to TileDetDescrManager const MbtsDetDescrManager* m_mbtsMgr; //!< Pointer to MbtsDetDescrManager @@ -165,7 +166,8 @@ class TileCellBuilderFromHit //!< method to process raw channels from a given vector and store them in collection template<class ITERATOR, class COLLECTION> - void build(TileDrawerEvtStatusArray& drawerEvtStatus, + void build(const CaloNoise* caloNoise, + TileDrawerEvtStatusArray& drawerEvtStatus, const ITERATOR & begin, const ITERATOR & end, COLLECTION * coll, diff --git a/TileCalorimeter/TileRecUtils/TileRecUtils/TileCellNoiseFilter.h b/TileCalorimeter/TileRecUtils/TileRecUtils/TileCellNoiseFilter.h index ab4c9b757ae87d7c98d9c77b72c90f8baa5a7f08..b9d5e62d4ecaa5a1b43354fe6bc25a513c6f3d69 100644 --- a/TileCalorimeter/TileRecUtils/TileRecUtils/TileCellNoiseFilter.h +++ b/TileCalorimeter/TileRecUtils/TileRecUtils/TileCellNoiseFilter.h @@ -16,10 +16,11 @@ // Calo includes #include "CaloIdentifier/CaloCell_ID.h" #include "CaloInterface/ICaloCellMakerTool.h" -#include "CaloInterface/ICalorimeterNoiseTool.h" +#include "CaloConditions/CaloNoise.h" // Atlas includes #include "AthenaBaseComps/AthAlgTool.h" +#include "StoreGate/ReadCondHandleKey.h" #include "GaudiKernel/ToolHandle.h" #include "GaudiKernel/ServiceHandle.h" @@ -70,7 +71,8 @@ class TileCellNoiseFilter: public extends<AthAlgTool, ICaloCellMakerTool> { void setCMSEnergy(const cmdata_t& commonMode, TileCell *cell) const; // calculate common-mode for all the motherboards - int calcCM(const CaloCellContainer *cellcoll, cmdata_t& commonMode) const; + int calcCM(const CaloNoise* caloNoise, + const CaloCellContainer *cellcoll, cmdata_t& commonMode) const; // derive a value of common-mode shift float getCMShift(const cmdata_t& commonMode, @@ -88,7 +90,9 @@ class TileCellNoiseFilter: public extends<AthAlgTool, ICaloCellMakerTool> { ToolHandle<TileCondToolNoiseSample> m_tileToolNoiseSample{this, "TileCondToolNoiseSample", "TileCondToolNoiseSample", "Tile noise sample tool"}; - ToolHandle<ICalorimeterNoiseTool> m_noiseTool; //!< Calo Noise tool + SG::ReadCondHandleKey<CaloNoise> m_caloNoiseKey{this, "CaloNoise", + "", + "CaloNoise object to read, or null to use the DB directly"}; ToolHandle<ITileBadChanTool> m_tileBadChanTool{this, "TileBadChanTool", "TileBadChanTool", "Tile bad channel tool"}; @@ -97,7 +101,6 @@ class TileCellNoiseFilter: public extends<AthAlgTool, ICaloCellMakerTool> { float m_truncationThresholdOnAbsEinSigma; float m_minimumNumberOfTruncatedChannels; bool m_useTwoGaussNoise; - bool m_useTileNoiseDB; static const CaloCell_ID::SUBCALO s_caloIndex = CaloCell_ID::TILE; diff --git a/TileCalorimeter/TileRecUtils/share/TileCellBuilderFromHit_test.py b/TileCalorimeter/TileRecUtils/share/TileCellBuilderFromHit_test.py index e4877c92132277f5596c74f6f38f585e17cc8bb7..52d11f141db9b8bd0b2d754f707f577ff038ea0a 100644 --- a/TileCalorimeter/TileRecUtils/share/TileCellBuilderFromHit_test.py +++ b/TileCalorimeter/TileRecUtils/share/TileCellBuilderFromHit_test.py @@ -421,7 +421,7 @@ from TileRecUtils.TileRecUtilsConf import TileCellBuilderFromHit def maketool (name, bct, noise=0, **kw): return TileCellBuilderFromHit (name, TileBadChanTool = bct, - UseCaloNoiseTool = False, + CaloNoise = '', TileHitContainer = 'TileHitCnt', NoiseSigma = noise, **kw) diff --git a/TileCalorimeter/TileRecUtils/src/TileCellBuilderFromHit.cxx b/TileCalorimeter/TileRecUtils/src/TileCellBuilderFromHit.cxx index b13782bc94cb25a53b07c061812994989c3a4c27..4a33195784630414619f1e825c82ae720d1ae8f8 100644 --- a/TileCalorimeter/TileRecUtils/src/TileCellBuilderFromHit.cxx +++ b/TileCalorimeter/TileRecUtils/src/TileCellBuilderFromHit.cxx @@ -22,7 +22,6 @@ #include "CaloIdentifier/CaloCell_ID.h" #include "CaloEvent/CaloCellContainer.h" #include "CaloDetDescr/CaloDetDescrElement.h" -#include "CaloInterface/ICalorimeterNoiseTool.h" #include "CaloConditions/CaloAffectedRegionInfoVec.h" #include "Identifier/IdentifierHash.h" @@ -30,6 +29,7 @@ #include "AthAllocators/DataPool.h" #include "StoreGate/ReadHandle.h" #include "StoreGate/WriteHandle.h" +#include "StoreGate/ReadCondHandle.h" // access all Hits inside container #include "EventContainers/SelectAllObject.h" @@ -78,7 +78,6 @@ TileCellBuilderFromHit::TileCellBuilderFromHit(const std::string& type, const st , m_maxTime (25.) , m_minTime(-25.) , m_maskBadChannels(false) - , m_useNoiseTool(true) , m_noiseSigma(20.*MeV) , m_tileID(0) , m_tileTBID(0) @@ -86,7 +85,6 @@ TileCellBuilderFromHit::TileCellBuilderFromHit(const std::string& type, const st , m_tileInfo(0) , m_pHRengine(0) , m_rndmSvc ("AtRndmGenSvc", name) - , m_noiseTool("CaloNoiseTool") , m_tileMgr(0) , m_mbtsMgr(0) , m_RChType(TileFragHash::Default) @@ -109,10 +107,6 @@ TileCellBuilderFromHit::TileCellBuilderFromHit(const std::string& type, const st // Noise Sigma declareProperty("NoiseSigma",m_noiseSigma); - // NoiseTool - declareProperty("UseCaloNoiseTool",m_useNoiseTool); - declareProperty("CaloNoiseTool",m_noiseTool,"Tool Handle for noise tool"); - // Maximum and minimum time for a cell to be included: declareProperty("MaxTime", m_maxTime); declareProperty("MinTime", m_minTime); @@ -142,7 +136,7 @@ StatusCode TileCellBuilderFromHit::initialize() { // retrieve MBTS and Tile detector manager, TileID helper and TileIfno from det store // retrieve MBTS and Tile detector manager, TileID helper and TileIfno from det store - if (m_MBTSContainerKey.key().empty()) { + if (m_MBTSContainerKey.empty()) { m_mbtsMgr = nullptr; } else { @@ -170,13 +164,12 @@ StatusCode TileCellBuilderFromHit::initialize() { //=== get TileCondToolEmscale ATH_CHECK( m_tileToolEmscale.retrieve() ); - //---- retrieve the noise tool ---------------- - if (m_useNoiseTool) { + //---- retrieve the noise ---------------- + if (!m_caloNoiseKey.empty()) { + ATH_CHECK( m_caloNoiseKey.initialize() ); ATH_MSG_INFO( "Reading electronic noise from DB" ); - ATH_CHECK( m_noiseTool.retrieve() ); } else { ATH_MSG_INFO( "Noise Sigma " << m_noiseSigma << " MeV is selected!" ); - m_noiseTool.disable(); } ATH_CHECK( m_rndmSvc.retrieve()); @@ -193,7 +186,7 @@ StatusCode TileCellBuilderFromHit::initialize() { m_RUN2 = (m_cabling->getCablingType() == TileCablingService::RUN2Cabling); m_RUN2plus = m_cabling->isRun2PlusCabling(); - if (m_RUN2 && !m_E4prContainerKey.key().empty()) { + if (m_RUN2 && !m_E4prContainerKey.empty()) { ATH_CHECK( m_E4prContainerKey.initialize() ); ATH_MSG_INFO( "Storing E4' cells in " << m_E4prContainerKey.key() ); } else { @@ -234,12 +227,12 @@ StatusCode TileCellBuilderFromHit::process (CaloCellContainer * theCellContainer ATH_MSG_DEBUG( "Container " << m_hitContainerKey.key() << " with TileHits found "); std::unique_ptr<TileCellContainer> MBTSCells; - if (!m_MBTSContainerKey.key().empty()) { + if (!m_MBTSContainerKey.empty()) { MBTSCells = std::make_unique<TileCellContainer>(SG::VIEW_ELEMENTS); } std::unique_ptr<TileCellContainer> E4prCells; - if (!m_E4prContainerKey.key().empty()) { + if (!m_E4prContainerKey.empty()) { E4prCells = std::make_unique<TileCellContainer>(SG::VIEW_ELEMENTS); } @@ -247,18 +240,24 @@ StatusCode TileCellBuilderFromHit::process (CaloCellContainer * theCellContainer SelectAllObject<TileHitContainer>::const_iterator begin = selAll.begin(); SelectAllObject<TileHitContainer>::const_iterator end = selAll.end(); + const CaloNoise* caloNoise = nullptr; + if (!m_caloNoiseKey.empty()) { + SG::ReadCondHandle<CaloNoise> noiseH (m_caloNoiseKey, ctx); + caloNoise = noiseH.cptr(); + } + if (begin != end) { ATH_MSG_DEBUG( " Calling build() method for hits from " << m_hitContainerKey.key() ); - build (drawerEvtStatus, begin, end, theCellContainer, + build (caloNoise, drawerEvtStatus, begin, end, theCellContainer, MBTSCells.get(), E4prCells.get()); } - if (!m_MBTSContainerKey.key().empty()) { + if (!m_MBTSContainerKey.empty()) { SG::WriteHandle<TileCellContainer> MBTSContainer(m_MBTSContainerKey, ctx); ATH_CHECK( MBTSContainer.record(std::move(MBTSCells)) ); } - if (!m_E4prContainerKey.key().empty()) { + if (!m_E4prContainerKey.empty()) { SG::WriteHandle<TileCellContainer> E4prContainer(m_E4prContainerKey, ctx); ATH_CHECK( E4prContainer.record(std::move(E4prCells)) ); } @@ -740,7 +739,8 @@ TileCellBuilderFromHit::maskBadChannels (TileDrawerEvtStatusArray& drawerEvtStat template<class ITERATOR, class COLLECTION> -void TileCellBuilderFromHit::build(TileDrawerEvtStatusArray& drawerEvtStatus, +void TileCellBuilderFromHit::build(const CaloNoise* caloNoise, + TileDrawerEvtStatusArray& drawerEvtStatus, const ITERATOR & begin, const ITERATOR & end, COLLECTION * coll, TileCellContainer* MBTSCells, TileCellContainer* E4prCells) const @@ -769,7 +769,7 @@ void TileCellBuilderFromHit::build(TileDrawerEvtStatusArray& drawerEvtStatus, bool overflow = false; bool underflow = false; bool overfit = false; - float ener_min = (m_useNoiseTool) ? 1.0E-30F : 0.0; + float ener_min = (!m_caloNoiseKey.empty()) ? 1.0E-30F : 0.0; std::vector<TileCell*> allCells (m_tileID->cell_hash_max(), nullptr); std::vector<TileCell*> MBTSVec; //!< vector to of pointers to MBTS cells @@ -1079,9 +1079,10 @@ void TileCellBuilderFromHit::build(TileDrawerEvtStatusArray& drawerEvtStatus, if (! (bad1 && bad2) ) { - float noiseSigma = (m_useNoiseTool) - ? m_noiseTool->getEffectiveSigma(pCell,ICalorimeterNoiseTool::MAXSYMMETRYHANDLING,ICalorimeterNoiseTool::ELECTRONICNOISE) - : m_noiseSigma; + float noiseSigma = m_noiseSigma; + if (caloNoise) { + noiseSigma = caloNoise->getEffectiveSigma (pCell->ID(), pCell->gain(), pCell->energy()); + } if (bad1 || bad2 || single_PMT) { diff --git a/TileCalorimeter/TileRecUtils/src/TileCellNoiseFilter.cxx b/TileCalorimeter/TileRecUtils/src/TileCellNoiseFilter.cxx index 540d09f94c55cc0649011c0b56fbc95888c11bb9..5b0b5442f805d606e2287d087def3795721f52d1 100644 --- a/TileCalorimeter/TileRecUtils/src/TileCellNoiseFilter.cxx +++ b/TileCalorimeter/TileRecUtils/src/TileCellNoiseFilter.cxx @@ -15,6 +15,7 @@ #include "CaloDetDescr/CaloDetDescrElement.h" // Atlas includes +#include "StoreGate/ReadCondHandle.h" #include "AthenaKernel/errorcheck.h" #include "Identifier/Identifier.h" #include "Identifier/IdentifierHash.h" @@ -36,19 +37,14 @@ TileCellNoiseFilter::TileCellNoiseFilter(const std::string& type, : base_class(type, name, parent) , m_tileID(0) , m_tileHWID(0) - , m_noiseTool("CaloNoiseTool") , m_truncationThresholdOnAbsEinSigma(4.0) // 4 sigma of ADC HF noise by default , m_minimumNumberOfTruncatedChannels(0.6) // at least 60% of channels should be below threshold , m_useTwoGaussNoise(false) // do not use 2G - has no sense for ADC HF noise for the moment - , m_useTileNoiseDB(true) // Tile DB with ADC HF noise by defaul { declareInterface<TileCellNoiseFilter>(this); - declareProperty("CaloNoiseTool", m_noiseTool); - declareProperty("UseTwoGaussNoise", m_useTwoGaussNoise); - declareProperty("UseTileNoiseDB", m_useTileNoiseDB); declareProperty("TruncationThresholdOnAbsEinSigma", m_truncationThresholdOnAbsEinSigma); declareProperty("MinimumNumberOfTruncatedChannels", m_minimumNumberOfTruncatedChannels); declareProperty("MaxNoiseSigma", m_maxNoiseSigma = 5.0, "Channels with noise more than that value are igonred in calculation of correction"); @@ -65,18 +61,15 @@ StatusCode TileCellNoiseFilter::initialize() { //=== get TileCondToolEmscale ATH_CHECK( m_tileToolEmscale.retrieve() ); - if (m_useTileNoiseDB) { + if (m_caloNoiseKey.empty()) { //=== get TileCondToolNoiseSample ATH_CHECK( m_tileToolNoiseSample.retrieve()); //=== get TileBadChanTool ATH_CHECK( m_tileBadChanTool.retrieve() ); - m_noiseTool.disable(); - } else { - //=== CaloNoiseTool - ATH_CHECK( m_noiseTool.retrieve()); + ATH_CHECK( m_caloNoiseKey.initialize()); m_tileToolNoiseSample.disable(); m_tileBadChanTool.disable(); @@ -88,7 +81,7 @@ StatusCode TileCellNoiseFilter::initialize() { // ============================================================================ // process container StatusCode TileCellNoiseFilter::process (CaloCellContainer* cellcoll, - const EventContext& /*ctx*/) const + const EventContext& ctx) const { ATH_MSG_DEBUG("in process()"); @@ -98,10 +91,16 @@ StatusCode TileCellNoiseFilter::process (CaloCellContainer* cellcoll, return StatusCode::SUCCESS; } + const CaloNoise* caloNoise = nullptr; + if (!m_caloNoiseKey.empty()) { + SG::ReadCondHandle<CaloNoise> noiseH (m_caloNoiseKey, ctx); + caloNoise = noiseH.cptr(); + } + // common-mode shift calculation ATH_MSG_DEBUG("Calculating common-mode shift..."); cmdata_t commonMode = {{{0}}}; - int ncorr = this->calcCM(cellcoll, commonMode); + int ncorr = this->calcCM(caloNoise, cellcoll, commonMode); if (ncorr <= 0) { ATH_MSG_DEBUG( "Failed to calculate common-mode shift - no corrections applied"); return StatusCode::SUCCESS; @@ -190,11 +189,10 @@ void TileCellNoiseFilter::setCMSEnergy(const cmdata_t& commonMode, // ============================================================================ // calculate correction -int TileCellNoiseFilter::calcCM(const CaloCellContainer* cellcoll, +int TileCellNoiseFilter::calcCM(const CaloNoise* caloNoise, + const CaloCellContainer* cellcoll, cmdata_t& commonMode) const { - bool useCaloNoise = (!m_useTileNoiseDB); - int nEmptyChan[s_maxPartition][s_maxDrawer][s_maxMOB] = {{{0}}}; int nGoodChan[s_maxPartition][s_maxDrawer][s_maxMOB] = {{{0}}}; @@ -209,14 +207,12 @@ int TileCellNoiseFilter::calcCM(const CaloCellContainer* cellcoll, float noise_sigma = 1.5, significance = 0.0; - if (useCaloNoise) { + if (caloNoise) { if (m_useTwoGaussNoise) { - noise_sigma = m_noiseTool->getEffectiveSigma(cell - , ICalorimeterNoiseTool::MAXSYMMETRYHANDLING - , ICalorimeterNoiseTool::ELECTRONICNOISE); + noise_sigma = caloNoise->getEffectiveSigma(cell->ID(), cell->gain(), cell->energy()); } else { - noise_sigma = m_noiseTool->getNoise(cell, ICalorimeterNoiseTool::ELECTRONICNOISE); + noise_sigma = caloNoise->getNoise(cell->ID(), cell->gain()); } significance = (noise_sigma != 0.0) ? fabs(cell->energy() / noise_sigma) : 999.999; @@ -259,7 +255,7 @@ int TileCellNoiseFilter::calcCM(const CaloCellContainer* cellcoll, amp = tilecell->ene1() / chanCalMeV; } - if (m_useTileNoiseDB) { + if (!caloNoise) { if (m_useTwoGaussNoise) { // nothing for the moment - keep 1.5 ADC counts } else { @@ -312,7 +308,7 @@ int TileCellNoiseFilter::calcCM(const CaloCellContainer* cellcoll, amp = tilecell->ene2() / chanCalMeV; } - if (m_useTileNoiseDB) { + if (!caloNoise) { if (m_useTwoGaussNoise) { // nothing for the moment - keep 1.5 ADC counts } else {