diff --git a/Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py b/Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py index 77f6f90e9db9c5f2048cbc40b9a219e03ff0ea38..4a7abc45a5075236e1e4a1d0151d08736cefb2ec 100644 --- a/Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py +++ b/Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py @@ -13,29 +13,17 @@ def CaloCellPedestalCorrDefault(name='CaloCellPedestalCorr'): except: mlog.error("could not get handle to CaloCellPedestalCorr Quit") print traceback.format_exc() - ToolSvc += theCaloCellPedestalCorr - - try: - from CaloRec.CaloRecConf import CaloCellContainerCorrectorTool - from CaloIdentifier import SUBCALO - thePedestalTool = CaloCellContainerCorrectorTool("PedestalTool", - CaloNums = [ SUBCALO.NSUBCALO], - CellCorrectionToolNames = [theCaloCellPedestalCorr] ) - except: - mlog.error("could not get handle to CaloCellContainerCorrectorTool Quit") - print traceback.format_exc() - return False - + #ToolSvc += theCaloCellPedestalCorr if globalflags.DataSource()=='data' : from IOVDbSvc.CondDB import conddb if conddb.isOnline: folder = '/CALO/Pedestal/CellPedestal' - conddb.addFolder('CALO_ONL',folder) + conddb.addFolder('CALO_ONL',folder,className="CondAttrListCollection") else: folder= '/CALO/Ofl/Pedestal/CellPedestal' - conddb.addFolder('CALO_OFL',folder) - theCaloCellPedestalCorr.FolderName = folder + conddb.addFolder('CALO_OFL',folder,className="CondAttrListCollection") + theCaloCellPedestalCorr.PedestalShiftFolder = folder theCaloCellPedestalCorr.isMC=False else: theCaloCellPedestalCorr.isMC=True @@ -44,15 +32,16 @@ def CaloCellPedestalCorrDefault(name='CaloCellPedestalCorr'): from CaloRec.CaloCellFlags import jobproperties if globalflags.DataSource()=='data' and (not jobproperties.CaloCellFlags.doPileupOffsetBCIDCorr()) and (not athenaCommonFlags.isOnline()): lumiFolder = '/TRIGGER/LUMI/LBLESTONL' - conddb.addFolder('TRIGGER_ONL',lumiFolder); + conddb.addFolder('TRIGGER_ONL',lumiFolder,className="CondAttrListCollection"); theCaloCellPedestalCorr.Luminosity = -1 theCaloCellPedestalCorr.LumiFolderName = lumiFolder if jobproperties.CaloCellFlags.doPileupOffsetBCIDCorr() and (not athenaCommonFlags.isOnline()): - from CaloTools.CaloLumiBCIDToolDefault import CaloLumiBCIDToolDefault - theCaloLumiBCIDTool = CaloLumiBCIDToolDefault() - ToolSvc += theCaloLumiBCIDTool - theCaloCellPedestalCorr.LumiBCIDTool = theCaloLumiBCIDTool - + from CaloRec.CaloBCIDAvgAlgDefault import CaloBCIDAvgAlgDefault + CaloBCIDAvgAlgDefault() + theCaloCellPedestalCorr.CaloBCIDAverageKey="CaloBCIDAverage" + else: + theCaloCellPedestalCorr.CaloBCIDAverageKey="" + - return thePedestalTool + return theCaloCellPedestalCorr diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx index dff34577162070668c1eca7c7919c892f9beb259..482ce9e722f6d76a7be68f005d8d9550f74d5c21 100755 --- a/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx +++ b/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx @@ -13,7 +13,7 @@ #include "CaloCellPedestalCorr.h" -#include "CaloEvent/CaloCell.h" +#include "CaloEvent/CaloCellContainer.h" #include "CaloDetDescr/CaloDetDescrElement.h" //=== AttributeList @@ -32,19 +32,15 @@ CaloCellPedestalCorr::CaloCellPedestalCorr( const std::string& type, const std::string& name, const IInterface* parent) - : CaloCellCorrection(type, name, parent), - m_caloCoolIdTool("CaloCoolIdTool"), + : AthAlgTool(type, name, parent), + m_caloCoolIdTool("CaloCoolIdTool",this), m_cellId(nullptr), - m_caloLumiBCIDTool(""), - m_isMC(false) -{ - declareInterface<CaloCellCorrection>(this); - declareProperty("Luminosity",m_lumi0=0,"Luminosity in 10**33 units"); - declareProperty("CaloCoolIdTool",m_caloCoolIdTool,"Tool for Calo cool Id"); - declareProperty("FolderName",m_folderName="/CALO/Pedestal/CellPedestal"); - declareProperty("LumiFolderName",m_lumiFolderName="/TRIGGER/LUMI/LBLESTONL"); - declareProperty("LumiBCIDTool",m_caloLumiBCIDTool,"Tool for BCID pileup offset average correction"); - declareProperty("isMC",m_isMC,"Data/MC flag"); + //m_caloLumiBCIDTool(""), + m_isMC(false){ + declareInterface<ICaloCellMakerTool>(this); + declareProperty("Luminosity",m_lumi0=0,"Luminosity in 10**33 units"); + declareProperty("CaloCoolIdTool",m_caloCoolIdTool,"Tool for Calo cool Id"); + declareProperty("isMC",m_isMC,"Data/MC flag"); } //======================================================== @@ -56,133 +52,84 @@ StatusCode CaloCellPedestalCorr::initialize() ATH_CHECK(detStore()->retrieve(m_cellId, "CaloCell_ID")); - if (m_lumi0<0) { - if (detStore()->contains<CondAttrListCollection>(m_lumiFolderName)) { - const DataHandle<CondAttrListCollection> lumiData; - ATH_CHECK( detStore()->regFcn(&CaloCellPedestalCorr::updateLumi, this , lumiData, m_lumiFolderName, true) ); - ATH_MSG_INFO( " Registered a callback for " << m_lumiFolderName << " Cool folder " ); - } - m_lumi0=0; + if (m_lumi0<0 && !m_isMC) { + ATH_CHECK(m_lumiFolderName.initialize()); } - - if (!m_isMC) { - //=== Register callback for this data handle - ATH_CHECK( detStore()->regFcn(&CaloCellPedestalCorr::updateMap, this, m_noiseAttrListColl, m_folderName) ); - ATH_MSG_INFO( " registered a callback for " << m_folderName << " folder " ); - + ATH_CHECK(m_pedShiftFolder.initialize()); ATH_CHECK(m_caloCoolIdTool.retrieve()); } - if (!m_caloLumiBCIDTool.empty() ) { - ATH_CHECK(m_caloLumiBCIDTool.retrieve()); + if (!m_caloBCIDAvg.key().empty()) { + ATH_CHECK(m_caloBCIDAvg.initialize()); } ATH_MSG_INFO( "CaloCellPedestalCorr initialize() end" ); - return StatusCode::SUCCESS; - } - -//______________________________________________________________________________________ -StatusCode -CaloCellPedestalCorr::updateLumi( IOVSVC_CALLBACK_ARGS ) -{ - ATH_MSG_INFO( " in updateLumi() " ); - - const CondAttrListCollection* attrListColl = 0; - ATH_CHECK(detStore()->retrieve(attrListColl, m_lumiFolderName)); - // Loop over collection - CondAttrListCollection::const_iterator first = attrListColl->begin(); - CondAttrListCollection::const_iterator last = attrListColl->end(); - for (; first != last; ++first) { - if ((*first).first == 0) { - if (msgLvl(MSG::DEBUG)) { - std::ostringstream attrStr1; - (*first).second.toOutputStream( attrStr1 ); - ATH_MSG_DEBUG( "ChanNum " << (*first).first << " Attribute list " << attrStr1.str() ); - } - const coral::AttributeList& attrList = (*first).second; - if (attrList["LBAvInstLumi"].isNull()) { - ATH_MSG_WARNING( " NULL Luminosity information in database ... set it to 0 " ); - m_lumi0 = 0.; - } else { - m_lumi0 = attrList["LBAvInstLumi"].data<float>() *1e-3; // luminosity (from 10**30 units in db to 10*33 units) - } - break; - } - } - if ( !(m_lumi0 == m_lumi0) ) { - ATH_MSG_WARNING( " Luminosity not a number ? m_lumi0 " << m_lumi0 << " ... set it to 0 " ); - m_lumi0 = 0.; - } - ATH_MSG_INFO( " Luminosity " << m_lumi0 ); - return StatusCode::SUCCESS; +StatusCode CaloCellPedestalCorr::process( CaloCellContainer * theCellContainer) { + //This function is a stopgap solution until all CaloCellCorrector tools are const + const EventContext& ctx = Gaudi::Hive::currentContext(); + return this->process(theCellContainer,ctx); } +StatusCode CaloCellPedestalCorr::process( CaloCellContainer * theCellContainer, const EventContext& ctx) const { - -// =============================================================================== - -StatusCode CaloCellPedestalCorr::updateMap(IOVSVC_CALLBACK_ARGS_K(keys) ) -{ - msg(MSG::INFO) << " in updateMap "; - std::list<std::string>::const_iterator itr; - for (itr=keys.begin(); itr!=keys.end(); ++itr) { - msg() << *itr << " "; - } - msg() << endmsg; - - //=== loop over collection (all cool channels) - CondAttrListCollection::const_iterator iColl = m_noiseAttrListColl->begin(); - CondAttrListCollection::const_iterator last = m_noiseAttrListColl->end(); - for (; iColl != last; ++iColl) { - - //=== COOL channel number is system id - unsigned int sysId = static_cast<unsigned int>(iColl->first); - - //=== delete old CaloCondBlobFlt (which does not own the blob) - NoiseBlobMap_t::iterator iOld = m_noiseBlobMap.find(sysId); - if(iOld != m_noiseBlobMap.end()){ - delete iOld->second; + const CondAttrListCollection* pedShiftColl=nullptr; + float lumi=m_lumi0; + if (!m_isMC) { + // Get Luminosity estimate + if (lumi<0) { + SG::ReadCondHandle<CondAttrListCollection> lumiHdl(m_lumiFolderName,ctx); + const CondAttrListCollection* attrListColl=(*lumiHdl); + const coral::AttributeList& attrList=attrListColl->attributeList(0); //Get channel number 0 + if (attrList["LBAvInstLumi"].isNull()) { + ATH_MSG_WARNING("No valid luminosity information in folder " << m_lumiFolderName.key() << ", attribute LBAvInstLumi"); + lumi=0; + } + else { + lumi=attrList["LBAvInstLumi"].data<float>() *1e-3; // luminosity (from 10**30 units in db to 10*33 units) + } } - - //=== Get new CaloCondBlobFlt instance, interpreting current BLOB - const coral::Blob& blob = (iColl->second)["CaloCondBlob16M"].data<coral::Blob>(); - const CaloCondBlobFlt* flt = CaloCondBlobFlt::getInstance(blob); - - //=== store new pointer in map - m_noiseBlobMap[sysId] = flt; - - }//end iColl - return StatusCode::SUCCESS; -} -// ============================================================================ + //Get Pedestal shifts + SG::ReadCondHandle<CondAttrListCollection> pedShiftHdl(m_pedShiftFolder,ctx); + pedShiftColl=(*pedShiftHdl); + } -void CaloCellPedestalCorr::MakeCorrection (CaloCell* theCell, - const EventContext& /*ctx*/) const -{ + const CaloBCIDAverage* bcidavgshift=nullptr; + if (!(m_caloBCIDAvg.key().empty())) { + SG::ReadHandle<CaloBCIDAverage> bcidavgshiftHdl(m_caloBCIDAvg,ctx); + bcidavgshift=&(*bcidavgshiftHdl); + } - float pedestal=0.; + std::pair<unsigned,const CaloCondBlobFlt*> blobCache{999999,nullptr}; + + for (CaloCell* theCell : *theCellContainer) { + float pedestal=0; + if (!m_isMC) { + const unsigned int cellHash=theCell->caloDDE()->calo_hash(); + unsigned int subHash; + const unsigned int iCool = m_caloCoolIdTool->getCoolChannelId(cellHash,subHash); + if (iCool!=blobCache.first) { + const coral::AttributeList& attrList=pedShiftColl->attributeList(iCool); + const coral::Blob& blob = attrList["CaloCondBlob16M"].data<coral::Blob>(); + //std::unique_ptr<const CaloCondBlobFlt> flt(CaloCondBlobFlt::getInstance(blob)); + blobCache.first=iCool; + delete blobCache.second; + blobCache.second=CaloCondBlobFlt::getInstance(blob); + } + + const unsigned int dbGain = CaloCondUtils::getDbCaloGain(theCell->gain()); + pedestal = blobCache.second->getCalib(subHash, dbGain, lumi); + } - if (!m_isMC) { - const unsigned int cellHash=theCell->caloDDE()->calo_hash(); - unsigned int subHash; - const unsigned int iCool = m_caloCoolIdTool->getCoolChannelId(cellHash,subHash); - //std::cout << "Got iCool=" << iCool << " subhash=" << subHash << std::endl; - NoiseBlobMap_t::const_iterator it = m_noiseBlobMap.find (iCool); - //The following checks would make sense but were omitted to speed up execution: - //1. it!=m_noiseBlobMap.end() eg, if iCool exists - //2. subHash < flt->getNChans() - const CaloCondBlobFlt* const flt = it->second; - const unsigned int dbGain = CaloCondUtils::getDbCaloGain(theCell->gain()); - pedestal = flt->getCalib(subHash, dbGain, m_lumi0); - } + if (bcidavgshift) { + pedestal = pedestal + bcidavgshift->average(theCell->ID()); + } - if (!m_caloLumiBCIDTool.empty() ) { - pedestal = pedestal + m_caloLumiBCIDTool->average(theCell,0); - } + theCell->addEnergy(-pedestal); + }//end loop over cell-container - theCell->addEnergy(-pedestal); + return StatusCode::SUCCESS; } diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.h b/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.h index bc022c07ddd981337120559cbdd033349acb9b7e..f36b1e87559ebf50972b40619423d276b20224ee 100644 --- a/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.h +++ b/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.h @@ -1,25 +1,25 @@ +//Dear emacs, this is -*-c++-*- /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration */ #ifndef CALOCELLCORRECTION_CALOCELLPEDESTALCORR_H #define CALOCELLCORRECTION_CALOCELLPEDESTALCORR_H -#include "CaloUtils/CaloCellCorrection.h" -#include "CaloIdentifier/CaloGain.h" -#include "AthenaKernel/IOVSvcDefs.h" -#include "StoreGate/DataHandle.h" +#include "CaloInterface/ICaloCellMakerTool.h" +#include "AthenaBaseComps/AthAlgTool.h" +#include "GaudiKernel/ToolHandle.h" #include "CaloCondBlobObjs/ICaloCoolIdTool.h" -#include "CaloInterface/ICaloLumiBCIDTool.h" #include "AthenaPoolUtilities/CondAttrListCollection.h" -#include "GaudiKernel/ToolHandle.h" -#include <unordered_map> +#include "StoreGate/ReadHandle.h" +#include "CaloEvent/CaloBCIDAverage.h" class CaloCondBlobFlt; class CaloCell; class CaloCell_ID; -class CaloCellPedestalCorr : public CaloCellCorrection +class CaloCellPedestalCorr : public AthAlgTool, + virtual public ICaloCellMakerTool { @@ -33,29 +33,25 @@ public: virtual StatusCode initialize() override; - void MakeCorrection (CaloCell* theCell, - const EventContext& ctx) const override; + StatusCode process( CaloCellContainer * theCellContainer) override; -private: - //=== callback function for luminosity storate - virtual StatusCode updateLumi(IOVSVC_CALLBACK_ARGS); + StatusCode process( CaloCellContainer * theCellContainer, + const EventContext& ctx) const; //override; + +private: + // const DataHandle<CondAttrListCollection> m_noiseAttrListColl; - virtual StatusCode updateMap(IOVSVC_CALLBACK_ARGS); - //=== blob storage - const DataHandle<CondAttrListCollection> m_noiseAttrListColl; - typedef std::unordered_map<unsigned int, const CaloCondBlobFlt*> NoiseBlobMap_t; - NoiseBlobMap_t m_noiseBlobMap; ToolHandle<ICaloCoolIdTool> m_caloCoolIdTool; float m_lumi0; - std::string m_folderName; - std::string m_lumiFolderName; - + + SG::ReadCondHandleKey<CondAttrListCollection> m_pedShiftFolder{this,"PedestalShiftFolder","/CALO/Pedestal/CellPedestal","SG Key of Attr list containing pedestal shifts"}; + SG::ReadCondHandleKey<CondAttrListCollection> m_lumiFolderName{this,"LumiFolderName","/TRIGGER/LUMI/LBLESTONL","SG Key of Attr list for Luminosity estimate"}; const CaloCell_ID* m_cellId; - ToolHandle<ICaloLumiBCIDTool> m_caloLumiBCIDTool; - + SG::ReadHandleKey<CaloBCIDAverage> m_caloBCIDAvg{this,"CaloBCIDAverageKey","","SG Key of CaloBCIDAverage object"}; + bool m_isMC; }; diff --git a/Calorimeter/CaloEvent/CMakeLists.txt b/Calorimeter/CaloEvent/CMakeLists.txt index f746fe7a8346f70286fe4c129296fc2a0c820f96..5697e61a0ba279d4bc67a6ec5e474bb96f165e48 100644 --- a/Calorimeter/CaloEvent/CMakeLists.txt +++ b/Calorimeter/CaloEvent/CMakeLists.txt @@ -24,6 +24,7 @@ atlas_depends_on_subdirs( Event/EventKernel Event/FourMom Event/NavFourMom + LArCalorimeter/LArRawConditions #not ideal .. LAr should depend on Calo. PRIVATE AtlasTest/TestTools Control/AthenaKernel diff --git a/Calorimeter/CaloEvent/CaloEvent/CaloBCIDAverage.h b/Calorimeter/CaloEvent/CaloEvent/CaloBCIDAverage.h index f50f74f5a70282f01fc012c490a8f401249a3489..6ed1c136e7290de23e62c8c07e3e49238ff7768a 100644 --- a/Calorimeter/CaloEvent/CaloEvent/CaloBCIDAverage.h +++ b/Calorimeter/CaloEvent/CaloEvent/CaloBCIDAverage.h @@ -15,9 +15,12 @@ class CaloBCIDAverage { float average(const Identifier id) const { const HWIdentifier hwid=m_mcSym->ZPhiSymOfl(id); + if (!hwid.is_valid()) return 0; //Catches the tile-case const unsigned id32=hwid.get_identifier32().get_compact(); const auto it=m_avg.find(id32); - if (it==m_avg.end()) std::abort(); + if (it==m_avg.end()) { + std::abort(); + } return it->second; } diff --git a/Calorimeter/CaloRec/python/CaloBCIDAvgAlgDefault.py b/Calorimeter/CaloRec/python/CaloBCIDAvgAlgDefault.py index 33a3e23dbaf66d48b106543f4421103e0c1a3ae8..3f0b24063d3a50d53a20aae75d54a18095f1003a 100644 --- a/Calorimeter/CaloRec/python/CaloBCIDAvgAlgDefault.py +++ b/Calorimeter/CaloRec/python/CaloBCIDAvgAlgDefault.py @@ -24,10 +24,14 @@ def CaloBCIDAvgAlgDefault(): conddb.addFolder("LAR_OFL","/LAR/ElecCalibOfl/LArPileupShape<key>LArShape32</key>",className="LArShape32MC") conddb.addFolder("LAR_OFL","/LAR/ElecCalibOfl/LArPileupAverage",className="LArMinBiasAverageMC") - #condSequence+=LArCondAlgShapeFlat(ReadKey= - topSequence+=CaloBCIDAvgAlg(isMC=False,LumiTool=theLumiTool,ShapeKey="LArShape32") else: #MC case + from LArRecUtils.LArOFCCondAlgDefault import LArOFCCondAlgDefault + from LArRecUtils.LArAutoCorrTotalCondAlgDefault import LArAutoCorrTotalCondAlgDefault + from LArRecUtils.LArADC2MeVCondAlgDefault import LArADC2MeVCondAlgDefault + LArADC2MeVCondAlgDefault() + LArAutoCorrTotalCondAlgDefault() + LArOFCCondAlgDefault() from TrigBunchCrossingTool.BunchCrossingTool import BunchCrossingTool theBunchCrossingTool = BunchCrossingTool() conddb.addFolder("LAR_OFL","/LAR/ElecCalibMC/Shape",className="LArShape32MC") diff --git a/Calorimeter/CaloRec/python/CaloCellGetter.py b/Calorimeter/CaloRec/python/CaloCellGetter.py index 701f4d03b162b0255713e5341d33f2b3b5b8c8bd..68c1f66bb87f8b016e85f022ef20726b2c9da8f7 100644 --- a/Calorimeter/CaloRec/python/CaloCellGetter.py +++ b/Calorimeter/CaloRec/python/CaloCellGetter.py @@ -7,6 +7,7 @@ from AthenaCommon.Constants import * from RecExConfig.Configured import Configured from AthenaCommon.AthenaCommonFlags import athenaCommonFlags from RecExConfig.RecFlags import rec +import traceback class CaloCellGetter (Configured) : _outputType = "CaloCellContainer" diff --git a/LArCalorimeter/LArRawConditions/LArRawConditions/LArMCSym.h b/LArCalorimeter/LArRawConditions/LArRawConditions/LArMCSym.h index 584f6aac5f144f6f5c48366e8fec86da4848593d..913b55deefb1a4ae591b5325dc91746af2fca686 100755 --- a/LArCalorimeter/LArRawConditions/LArRawConditions/LArMCSym.h +++ b/LArCalorimeter/LArRawConditions/LArRawConditions/LArMCSym.h @@ -26,6 +26,7 @@ class LArMCSym { ); HWIdentifier ZPhiSymOfl(const Identifier notSymOffId) const { + if (m_caloCellID->is_tile(notSymOffId)) return HWIdentifier(); const IdentifierHash h=m_caloCellID->calo_cell_hash(notSymOffId); return ZPhiSymOfl(h); }