From 2cdac95def99870b97fda51a58a0a5cf01244f6a Mon Sep 17 00:00:00 2001 From: Scott Snyder <scott.snyder@cern.ch> Date: Thu, 12 Jun 2014 18:45:34 +0200 Subject: [PATCH] Const fix. (CaloCellCorrection-00-00-33) --- .../CaloCellEnergyRescaler.h | 45 +++ .../CaloCellMBAverageCorr.h | 37 +++ .../CaloCellNeighborsAverageCorr.h | 60 ++++ .../CaloCellCorrection/CaloCellPedestalCorr.h | 60 ++++ .../CaloCellCorrection/CaloCellRandomizer.h | 55 ++++ .../CaloCellCorrection/CaloCellRescaler.h | 49 +++ .../CaloCellCorrection/CaloCellTimeCorrTool.h | 44 +++ .../CaloCellCorrection/cmt/requirements | 29 ++ .../python/CaloCellPedestalCorrDefault.py | 58 ++++ .../src/CaloCellEnergyRescaler.cxx | 74 +++++ .../src/CaloCellMBAverageCorr.cxx | 58 ++++ .../src/CaloCellNeighborsAverageCorr.cxx | 310 ++++++++++++++++++ .../src/CaloCellPedestalCorr.cxx | 235 +++++++++++++ .../src/CaloCellRandomizer.cxx | 175 ++++++++++ .../src/CaloCellRescaler.cxx | 60 ++++ .../src/CaloCellTimeCorrTool.cxx | 67 ++++ .../components/CaloCellCorrection_entries.cxx | 28 ++ .../components/CaloCellCorrection_load.cxx | 4 + 18 files changed, 1448 insertions(+) create mode 100644 Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellEnergyRescaler.h create mode 100755 Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellMBAverageCorr.h create mode 100755 Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellNeighborsAverageCorr.h create mode 100755 Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellPedestalCorr.h create mode 100644 Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRandomizer.h create mode 100755 Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRescaler.h create mode 100644 Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellTimeCorrTool.h create mode 100644 Calorimeter/CaloCellCorrection/cmt/requirements create mode 100644 Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py create mode 100644 Calorimeter/CaloCellCorrection/src/CaloCellEnergyRescaler.cxx create mode 100755 Calorimeter/CaloCellCorrection/src/CaloCellMBAverageCorr.cxx create mode 100755 Calorimeter/CaloCellCorrection/src/CaloCellNeighborsAverageCorr.cxx create mode 100755 Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx create mode 100644 Calorimeter/CaloCellCorrection/src/CaloCellRandomizer.cxx create mode 100755 Calorimeter/CaloCellCorrection/src/CaloCellRescaler.cxx create mode 100644 Calorimeter/CaloCellCorrection/src/CaloCellTimeCorrTool.cxx create mode 100755 Calorimeter/CaloCellCorrection/src/components/CaloCellCorrection_entries.cxx create mode 100755 Calorimeter/CaloCellCorrection/src/components/CaloCellCorrection_load.cxx diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellEnergyRescaler.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellEnergyRescaler.h new file mode 100644 index 00000000000..f432e4ddade --- /dev/null +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellEnergyRescaler.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//Dear emacs, this is -*-c++-*- + +#ifndef CALOCELLENERGYRESCALER_H +#define CALOCELLENERGYRESCALER_H + +#include "AthenaBaseComps/AthAlgTool.h" +#include "CaloInterface/ICaloCellMakerTool.h" +#include "AthenaPoolUtilities/AthenaAttributeList.h" +#include "StoreGate/DataHandle.h" +#include "AthenaKernel/IOVSvcDefs.h" +#include <string> + +class CaloCellContainer; +class CaloCondBlobFlt; + +/** @class CaloCellEnergyRescaler + @brief CaloCellMakerTool to re-scale cell energies. +*/ + +class CaloCellEnergyRescaler : public AthAlgTool, virtual public ICaloCellMakerTool { +public: + + CaloCellEnergyRescaler (const std::string& type, const std::string& name, + const IInterface* parent); + + ~CaloCellEnergyRescaler(); + virtual StatusCode initialize(); + + virtual StatusCode process( CaloCellContainer * theCellContainer) ; + + private: + /// IOV callback method + StatusCode load(IOVSVC_CALLBACK_ARGS); + + const DataHandle<AthenaAttributeList> m_attrList; + const CaloCondBlobFlt* m_corrValues; + + std::string m_key; +}; + +#endif diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellMBAverageCorr.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellMBAverageCorr.h new file mode 100755 index 00000000000..96745584839 --- /dev/null +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellMBAverageCorr.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CALOREC_CaloCellMBAverageCorr_H +#define CALOREC_CaloCellMBAverageCorr_H + +#include "CaloUtils/CaloCellCorrection.h" +#include "CaloInterface/ICaloMBAverageTool.h" +#include "StoreGate/DataHandle.h" +#include "GaudiKernel/ToolHandle.h" + +class CaloCell; + +class CaloCellMBAverageCorr : public CaloCellCorrection + +{ + +public: + + CaloCellMBAverageCorr(const std::string& type, + const std::string& name, + const IInterface* parent); + + virtual ~CaloCellMBAverageCorr() {}; + + virtual StatusCode initialize(); + + void MakeCorrection(CaloCell* theCell); + +private: + + ToolHandle<ICaloMBAverageTool> m_caloMBAverageTool; + +}; + +#endif diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellNeighborsAverageCorr.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellNeighborsAverageCorr.h new file mode 100755 index 00000000000..170806e33de --- /dev/null +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellNeighborsAverageCorr.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CALOREC_CALOCELLNEIGHBORSAVERAGECORR_H +#define CALOREC_CALOCELLNEIGHBORSAVERAGECORR_H + +#include "GaudiKernel/AlgTool.h" +#include "CaloInterface/ICaloCellMakerTool.h" +#include "AthenaKernel/IOVSvcDefs.h" + +#include <string> + +class CaloCellContainer; +class CaloDetDescrManager; +class CaloCell_ID; +class TileID; + +//inspiration from http://alxr.usatlas.bnl.gov/lxr-stb3/source/atlas/Calorimeter/CaloRec/CaloRec/CaloCellCopyTool.h#032 +class CaloCellNeighborsAverageCorr : public AlgTool, + virtual public ICaloCellMakerTool + +{ + +public: + + CaloCellNeighborsAverageCorr(const std::string& type, + const std::string& name, + const IInterface* parent); + + virtual ~CaloCellNeighborsAverageCorr() {}; + + /** initialize method + */ + virtual StatusCode initialize(); + + /** process calo cell collection to apply corrections + */ + StatusCode process( CaloCellContainer * theCellContainer); + + /** Callback added to handle Data-driven GeoModel initialisation + */ + virtual StatusCode geoInit(IOVSVC_CALLBACK_ARGS); + + + +private: + + const CaloDetDescrManager* m_calo_dd_man; + const CaloCell_ID* m_calo_id; + const TileID* m_tile_id; + bool m_testMode; + bool m_skipDeadFeb; + bool m_skipDeadLAr; + bool m_skipDeadDrawer; + bool m_skipDeadTile; + +}; + +#endif diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellPedestalCorr.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellPedestalCorr.h new file mode 100755 index 00000000000..c7dff91fe1b --- /dev/null +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellPedestalCorr.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CALOREC_CALOCELLPEDESTALCORR_H +#define CALOREC_CALOCELLPEDESTALCORR_H + +#include "CaloUtils/CaloCellCorrection.h" +#include "CaloIdentifier/CaloGain.h" +#include "AthenaKernel/IOVSvcDefs.h" +#include "StoreGate/DataHandle.h" +#include "CaloCondBlobObjs/ICaloCoolIdTool.h" +#include "CaloInterface/ICaloLumiBCIDTool.h" +#include "AthenaPoolUtilities/CondAttrListCollection.h" +#include "GaudiKernel/ToolHandle.h" + +class CaloCondBlobFlt; +class CaloCell; +class CaloCell_ID; + +class CaloCellPedestalCorr : public CaloCellCorrection + +{ + +public: + + CaloCellPedestalCorr(const std::string& type, + const std::string& name, + const IInterface* parent); + + virtual ~CaloCellPedestalCorr() {}; + + virtual StatusCode initialize(); + + void MakeCorrection(CaloCell* theCell); + +private: + + //=== callback function for luminosity storate + virtual StatusCode updateLumi(IOVSVC_CALLBACK_ARGS); + + virtual StatusCode updateMap(IOVSVC_CALLBACK_ARGS); + //=== blob storage + const DataHandle<CondAttrListCollection> m_noiseAttrListColl; + std::map<unsigned int, const CaloCondBlobFlt*> m_noiseBlobMap; + std::map<unsigned int, const CaloCondBlobFlt*>::const_iterator m_lastIt; + + ToolHandle<ICaloCoolIdTool> m_caloCoolIdTool; + float m_lumi0; + std::string m_folderName; + std::string m_lumiFolderName; + + const CaloCell_ID* m_cellId; + + ToolHandle<ICaloLumiBCIDTool> m_caloLumiBCIDTool; + + bool m_isMC; +}; + +#endif diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRandomizer.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRandomizer.h new file mode 100644 index 00000000000..d18dadb47d4 --- /dev/null +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRandomizer.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef CALOCELLCORRECTION_CALOCELLRANDOMIZER_H +#define CALOCELLCORRECTION_CALOCELLRANDOMIZER_H + +#include "CaloUtils/CaloCellCorrection.h" + +#include "CaloInterface/ICalorimeterNoiseTool.h" +#include "GaudiKernel/ToolHandle.h" + +//class CaloCell; +//class ICalorimeterNoiseTool; + +class CaloCellRandomizer : public CaloCellCorrection + +{ + +public: + + CaloCellRandomizer(const std::string& type, + const std::string& name, + const IInterface* parent); + + virtual ~CaloCellRandomizer() {}; + + virtual StatusCode initialize(); + + void MakeCorrection(CaloCell* theCell); + + +private: + + + ToolHandle<ICalorimeterNoiseTool> m_noiseTool; + + int m_corrSampleMin; + int m_corrSampleMax; + float m_fractionSigma; + bool m_GaussRand; + bool m_GaussRandGroupedSamples; + bool m_GaussRandShifted; + bool m_GaussRandShifted_Custom; + float m_shift_EMB; + float m_shift_EMEC; + float m_shift_HEC; + float m_shift_TileBar; + float m_shift_TileGap; + float m_shift_TileExt; + float m_shift_FCAL; + +}; + +#endif diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRescaler.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRescaler.h new file mode 100755 index 00000000000..a8e1ab8b536 --- /dev/null +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRescaler.h @@ -0,0 +1,49 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//Dear emacs, this is -*-c++-*- + +#ifndef CALOREC_CaloCellRescaler_H +#define CALOREC_CaloCellRescaler_H + + +#include "CaloUtils/CaloCellCorrection.h" +#include "CaloIdentifier/CaloCell_ID.h" + +class CaloCell; + +//Tool to re-scale cell energies. Factors to be given by jobOptions + +//To invoke this tool: +//CaloCellMaker.CaloCellMakerToolNames+=["CaloCellContainerCorrectorTool"] +//ToolSvc.CaloCellContainerCorrectorTool.CellCorrectionToolNames+=["CaloCellRescaler"] +//ToolSvc.CaloCellContainerCorrectorTool.CaloNums=[0,3] #LAr EM and Tile +//ToolSvc.CaloCellRescaler.FactorToCellsEMB0=1.5 +//ToolSvc.CaloCellRescaler.FactorToCellsEMB1=1.5 +//ToolSvc.CaloCellRescaler.FactorToCellsEMB2=1.5 +//ToolSvc.CaloCellRescaler.FactorToCellsEMB3=1.5 +//ToolSvc.CaloCellRescaler.FactorToCellsTILEB0=1.5 +//ToolSvc.CaloCellRescaler.FactorToCellsTILEB1=1.5 +//ToolSvc.CaloCellRescaler.FactorToCellsTILEB2=1.5 + +class CaloCellRescaler : public CaloCellCorrection { + +public: + + CaloCellRescaler (const std::string& type, const std::string& name, + const IInterface* parent); + + ~CaloCellRescaler(); + virtual StatusCode initialize(); + + void MakeCorrection(CaloCell* theCell); + + private: + + float m_factorToCells[CaloCell_ID::Unknown+1]; + +}; + +#endif + diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellTimeCorrTool.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellTimeCorrTool.h new file mode 100644 index 00000000000..197b69fd84d --- /dev/null +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellTimeCorrTool.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//Dear emacs, this is -*-c++-*- + +#ifndef CALOCELLTIMECORRTOOL +#define CALOCELLTIMECORRTOOL + +#include "CaloUtils/CaloCellCorrection.h" +#include "AthenaPoolUtilities/AthenaAttributeList.h" +#include "StoreGate/DataHandle.h" +#include "AthenaKernel/IOVSvcDefs.h" +#include <string> + +class CaloCell; +class CaloCondBlobFlt; + +/** @class CaloCellTimeCorrTool + @brief Tool to shift cell time values +*/ + +class CaloCellTimeCorrTool : public CaloCellCorrection { +public: + + CaloCellTimeCorrTool (const std::string& type, const std::string& name, + const IInterface* parent); + + ~CaloCellTimeCorrTool(); + virtual StatusCode initialize(); + + void MakeCorrection(CaloCell* theCell); + + private: + /// IOV callback method + StatusCode load(IOVSVC_CALLBACK_ARGS); + + const DataHandle<AthenaAttributeList> m_attrList; + const CaloCondBlobFlt* m_corrValues; + + std::string m_key; +}; + +#endif diff --git a/Calorimeter/CaloCellCorrection/cmt/requirements b/Calorimeter/CaloCellCorrection/cmt/requirements new file mode 100644 index 00000000000..d064149f1c8 --- /dev/null +++ b/Calorimeter/CaloCellCorrection/cmt/requirements @@ -0,0 +1,29 @@ +package CaloCellCorrection + +author Guillaume Unal + +public +use AtlasPolicy AtlasPolicy-* +use StoreGate StoreGate-* Control +use AthenaKernel AthenaKernel-* Control +use AthenaBaseComps AthenaBaseComps-* Control +use GaudiInterface GaudiInterface-* External +use CaloInterface CaloInterface-* Calorimeter +use CaloIdentifier CaloIdentifier-* Calorimeter +use CaloUtils CaloUtils-* Calorimeter +use CaloCondBlobObjs CaloCondBlobObjs-* Calorimeter +use AthenaPoolUtilities AthenaPoolUtilities-* Database/AthenaPOOL +private +use Identifier Identifier-* DetectorDescription +use GeoModelInterfaces GeoModelInterfaces-* DetectorDescription/GeoModel +use CaloEvent CaloEvent-* Calorimeter +use CaloDetDescr CaloDetDescr-* Calorimeter +use AtlasCORAL AtlasCORAL-* External +use AtlasCLHEP AtlasCLHEP-* External +public + +library CaloCellCorrection *.cxx -s=components *.cxx +#apply_pattern declare_joboptions files="*.py" + +apply_pattern component_library +apply_pattern declare_python_modules files="*.py" diff --git a/Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py b/Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py new file mode 100644 index 00000000000..77f6f90e9db --- /dev/null +++ b/Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py @@ -0,0 +1,58 @@ +# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + +def CaloCellPedestalCorrDefault(name='CaloCellPedestalCorr'): + import traceback + from AthenaCommon.Logging import logging + mlog = logging.getLogger( 'CaloCellPedestalCorrDefault' ) + from AthenaCommon.AppMgr import ToolSvc + from AthenaCommon.GlobalFlags import globalflags + + try: + from CaloCellCorrection.CaloCellCorrectionConf import CaloCellPedestalCorr + theCaloCellPedestalCorr = CaloCellPedestalCorr("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 + + + if globalflags.DataSource()=='data' : + from IOVDbSvc.CondDB import conddb + if conddb.isOnline: + folder = '/CALO/Pedestal/CellPedestal' + conddb.addFolder('CALO_ONL',folder) + else: + folder= '/CALO/Ofl/Pedestal/CellPedestal' + conddb.addFolder('CALO_OFL',folder) + theCaloCellPedestalCorr.FolderName = folder + theCaloCellPedestalCorr.isMC=False + else: + theCaloCellPedestalCorr.isMC=True + + from AthenaCommon.AthenaCommonFlags import athenaCommonFlags + 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); + 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 + + + return thePedestalTool diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellEnergyRescaler.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellEnergyRescaler.cxx new file mode 100644 index 00000000000..9fe0c0416e0 --- /dev/null +++ b/Calorimeter/CaloCellCorrection/src/CaloCellEnergyRescaler.cxx @@ -0,0 +1,74 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "CaloCellCorrection/CaloCellEnergyRescaler.h" +#include "CaloEvent/CaloCellContainer.h" +#include "CaloCondBlobObjs/CaloCondBlobFlt.h" + + +CaloCellEnergyRescaler::CaloCellEnergyRescaler (const std::string& type, + const std::string& name, + const IInterface* parent) : + AthAlgTool(type, name, parent), + m_corrValues(0) { + declareInterface<ICaloCellMakerTool>(this); + declareProperty("Folder",m_key="/CALO/Ofl/CellEnergyCorr", + "Key (=foldername) of AttrListCollection"); +} + + +CaloCellEnergyRescaler::~CaloCellEnergyRescaler() {} + + +StatusCode CaloCellEnergyRescaler::initialize() { + + StatusCode sc=detStore()->regFcn(&CaloCellEnergyRescaler::load, + dynamic_cast<CaloCellEnergyRescaler*>(this), + m_attrList,m_key); + if (sc.isFailure()) { + msg(MSG::ERROR) << "Cound not register Callback function for AthenaAttributeList with key " << m_key << endreq; + return sc; + } + + return StatusCode::SUCCESS; +} + + +StatusCode CaloCellEnergyRescaler::load(IOVSVC_CALLBACK_ARGS) { + + ATH_MSG_INFO("in IOV callback function"); + if (m_corrValues) { + ATH_MSG_INFO("Delete previously loaded correction values"); + delete m_corrValues; + m_corrValues=0; + } + + const coral::Blob& blob = (*m_attrList)["CaloCondBlob16M"].data<coral::Blob>(); + if (blob.size()<3) { + ATH_MSG_INFO("Found empty blob, no corretion needed :-)"); + } + else { + m_corrValues=CaloCondBlobFlt::getInstance(blob); + ATH_MSG_INFO("Database folder has values for " << m_corrValues->getNChans() << " channels and " << m_corrValues->getNGains() << " gains."); + } + + return StatusCode::SUCCESS; +} + + +StatusCode CaloCellEnergyRescaler::process(CaloCellContainer* theCaloCellContainer) { + if (m_corrValues) { + CaloCellContainer::iterator it=theCaloCellContainer->begin(); + CaloCellContainer::iterator it_e=theCaloCellContainer->end(); + for(;it!=it_e;++it) { + CaloCell* theCell=(*it); + const IdentifierHash& hash_id=theCell->caloDDE()->calo_hash(); + if (hash_id<m_corrValues->getNChans()) { + const float& scale= m_corrValues->getData(hash_id,0,0); + theCell->setEnergy(theCell->energy()*scale); + }//end if hash_id<NChans + }//end loop over cells + }//end if have correction values + return StatusCode::SUCCESS; +} diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellMBAverageCorr.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellMBAverageCorr.cxx new file mode 100755 index 00000000000..f8143800e00 --- /dev/null +++ b/Calorimeter/CaloCellCorrection/src/CaloCellMBAverageCorr.cxx @@ -0,0 +1,58 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// **************************************************************************************** +// +// To correct average energy per cell, computed from CaloMBAverageCorrTool +// this is aimed for MC where pileup effects are computed on the fly +// and is relevant only for bunch spacing not equal to 25 ns +// +// G.Unal 19 novembre 2008 .... first version +// +// **************************************************************************************** + +#include "CaloCellCorrection/CaloCellMBAverageCorr.h" +#include "CaloEvent/CaloCell.h" +#include "GaudiKernel/MsgStream.h" + + +// ====================================================== +// Constructor + +CaloCellMBAverageCorr::CaloCellMBAverageCorr( + const std::string& type, + const std::string& name, + const IInterface* parent) + : CaloCellCorrection(type, name, parent), + m_caloMBAverageTool("CaloMBAverageTool") +{ + declareInterface<CaloCellCorrection>(this); + declareProperty("CaloMBAverageTool",m_caloMBAverageTool,"Tool to compute shift from MB average"); +} + +//======================================================== +// Initialize + +StatusCode CaloCellMBAverageCorr::initialize() +{ + MsgStream log(msgSvc(),name()); + log << MSG::INFO << " in CaloCellMBAverageCorr::initialize() " << endreq; + + if (m_caloMBAverageTool.retrieve().isFailure()) { + log << MSG::ERROR << " cannot retrieve m_caloMBAverageTool"; + return StatusCode::FAILURE; + } + + return StatusCode::SUCCESS; + +} + + +// ============================================================================ + +void CaloCellMBAverageCorr::MakeCorrection(CaloCell* theCell) +{ + float pedestal = m_caloMBAverageTool->average(theCell); + theCell->addEnergy(-pedestal); +} diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellNeighborsAverageCorr.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellNeighborsAverageCorr.cxx new file mode 100755 index 00000000000..488da3fe3bf --- /dev/null +++ b/Calorimeter/CaloCellCorrection/src/CaloCellNeighborsAverageCorr.cxx @@ -0,0 +1,310 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// **************************************************************************************** +// +// Assign as energy the average energy of the surrounding cells (i.e. the neibhgors). +// +// Georgios Choudalakis & Guillaume Unal, January 2009. +// +// **************************************************************************************** + +#include "CaloCellCorrection/CaloCellNeighborsAverageCorr.h" + +#include "CaloEvent/CaloCell.h" +#include "CaloEvent/CaloCellContainer.h" + +#include "CaloIdentifier/CaloCell_ID.h" +#include "CaloIdentifier/TileID.h" +#include "CaloIdentifier/CaloIdManager.h" +#include "CaloDetDescr/CaloDetDescrManager.h" +#include "CaloDetDescr/CaloDetDescrElement.h" +#include "Identifier/Identifier.h" +#include "Identifier/IdentifierHash.h" +#include "GeoModelInterfaces/IGeoModelSvc.h" +#include "StoreGate/StoreGateSvc.h" +#include "GaudiKernel/MsgStream.h" +#include <map> //useful in testMode + +// ====================================================== +// Constructor + +CaloCellNeighborsAverageCorr::CaloCellNeighborsAverageCorr( + const std::string& type, + const std::string& name, + const IInterface* parent) + :AlgTool(type, name, parent) +{ + declareInterface<ICaloCellMakerTool>(this); + declareProperty("testMode",m_testMode=false,"test mode"); + declareProperty("skipDeadFeb", m_skipDeadFeb=true, "Skip dead LAr Febs (default = true)"); + declareProperty("skipDeadLAr", m_skipDeadLAr=false, "Skip all dead LAr cells (default = false)"); + declareProperty("skipDeadDrawer", m_skipDeadDrawer=false, "Skip dead Tile drawers (default = false)"); + declareProperty("skipDeadTile", m_skipDeadTile=true, "Skip all dead Tile cells (default = true)"); +} + +//======================================================== +// Initialize + +StatusCode CaloCellNeighborsAverageCorr::initialize() +{ + MsgStream log(msgSvc(),name()); + log << MSG::INFO << " in CaloCellNeighborsAverageCorr::initialize() " << endreq; + + if (m_testMode) + log << MSG::DEBUG << " Running in Test Mode. " << endreq; + + // don't need to check status of the drawer if all dead cells are ignored + if (m_skipDeadTile && m_skipDeadDrawer) { + log << MSG::WARNING << "Please, don't set skipDeadDrawer and skipDeadTile to True at the same time" << endreq; + log << MSG::WARNING << "Setting skipDeadDrawer=False" << endreq; + m_skipDeadDrawer=false; + } + + log << MSG::INFO << "Skip Dead Feb = " << ((m_skipDeadFeb)?"true":"false") << endreq; + log << MSG::INFO << "Skip Dead LAr = " << ((m_skipDeadLAr)?"true":"false") << endreq; + log << MSG::INFO << "Skip Dead Drawer = " << ((m_skipDeadDrawer)?"true":"false") << endreq; + log << MSG::INFO << "Skip Dead Tile = " << ((m_skipDeadTile)?"true":"false") << endreq; + + + StoreGateSvc* detStore; + if (service("DetectorStore", detStore).isFailure()) { + log << MSG::ERROR << "Unable to access DetectoreStore" << endreq ; + return StatusCode::FAILURE; + } + + + const IGeoModelSvc *geoModel=0; + StatusCode sc = service("GeoModelSvc", geoModel); + if(sc.isFailure()) + { + log << MSG::ERROR << "Could not locate GeoModelSvc" << endreq; + return sc; + } + + // dummy parameters for the callback: + int dummyInt=0; + std::list<std::string> dummyList; + + if (geoModel->geoInitialized()) + { + return geoInit(dummyInt,dummyList); + } + else + { + sc = detStore->regFcn(&IGeoModelSvc::geoInit, + geoModel, + &CaloCellNeighborsAverageCorr::geoInit,this); + if(sc.isFailure()) + { + log << MSG::ERROR << "Could not register geoInit callback" << endreq; + return sc; + } + } + + + log << MSG::INFO << "CaloCellNeighborsAverageCorr initialize() end" << endreq; + + return StatusCode::SUCCESS; +} + +// ============================================================================ + +StatusCode +CaloCellNeighborsAverageCorr::geoInit(IOVSVC_CALLBACK_ARGS) +{ + MsgStream log(msgSvc(),name()); + log << MSG::INFO << " in geoInit " << endreq; + m_calo_dd_man = CaloDetDescrManager::instance(); + m_calo_id = m_calo_dd_man->getCaloCell_ID(); + m_tile_id = m_calo_id->tile_idHelper(); + + return StatusCode::SUCCESS; +} + +// ============================================================================ + +StatusCode CaloCellNeighborsAverageCorr::process(CaloCellContainer* theCont) +{ + MsgStream log(msgSvc(),name()); + bool lVerbose = (log.level()<=MSG::VERBOSE); + if (lVerbose) log << MSG::VERBOSE << " in process " << endreq; + + //inspired from Calorimeter/CaloRec/src/CaloTopoClusterMaker.cxx + // (to be moved such that can be jobOptions configurable ) + + //one could use various families of neighbors: + LArNeighbours::neighbourOption m_nOption; + // m_nOption = LArNeighbours::all3D; + m_nOption = LArNeighbours::all2D; //gives less bias than all3D + //m_nOption = LArNeighbours::super3D; + + std::vector<IdentifierHash> theNeighbors; + theNeighbors.reserve(22); + + std::map<const CaloCell*,float> cannedUncorrectedEnergies; + if (m_testMode) { //fill in the map of uncorrected energies, to preserve it for later use. + CaloCellContainer::const_iterator itrCell_test=theCont->begin(); + for (; itrCell_test!=theCont->end();++itrCell_test){ + const CaloCell* pointerToCell=*itrCell_test; //yes, this is an iterator that when dereferenced returns a pointer, not a CaloCell directly. + cannedUncorrectedEnergies[pointerToCell] = pointerToCell->energy(); + //std::cout << "GEORGIOS DEBUGGING For CaloCell* = " << pointerToCell << " we have energy = " << cannedUncorrectedEnergies[pointerToCell] << std::endl; + } + } + + int nGoodCellsPerDrawer[4][64]; + + if (m_skipDeadDrawer) { + memset(nGoodCellsPerDrawer,0,sizeof(nGoodCellsPerDrawer)); + + size_t cellItr = theCont->indexFirstCellCalo(CaloCell_ID::TILE); + size_t lastCell = theCont->indexLastCellCalo(CaloCell_ID::TILE); + + for (; cellItr <= lastCell; ++cellItr) { + const CaloCell* CCell = (*theCont)[cellItr]; + if (CCell && ! CCell->badcell() ) { + Identifier id = CCell->ID(); + int part = std::min(m_tile_id->section(id),2)+m_tile_id->side(id); + int module = m_tile_id->module(id); + ++nGoodCellsPerDrawer[part][module]; + } + } + if (lVerbose) { + // 1-1 2-1 1+1 2+1 + const char * name[4] = {"LBC","EBC","LBA","EBA"}; + for (int part=0; part<4; ++part) { + for (int module=0; module<64; ++module) { + //log << MSG::VERBOSE << name[part] << module+1 << " nCells " + // << nGoodCellsPerDrawer[part][module] + // << ( ( nGoodCellsPerDrawer[part][module] < 2 ) ? " bad drawer" : "") + // << endreq; + if ( nGoodCellsPerDrawer[part][module] < 2 ) { + log << MSG::VERBOSE << "Bad drawer " << name[part] << module+1 << endreq; + } + } + } + } + } + + CaloCellContainer::iterator itrCell=theCont->begin(); + for (; itrCell!=theCont->end();++itrCell){ + CaloCell * aCell=*itrCell; + + if (aCell->badcell() || m_testMode) { + + const CaloDetDescrElement* caloDDE = aCell->caloDDE(); + if (!caloDDE) continue; + int theCellSubCalo = caloDDE->getSubCalo(); + + bool isTile = (theCellSubCalo == CaloCell_ID::TILE); + + if (isTile) { + + if (m_skipDeadTile) { + if (lVerbose) log << MSG::VERBOSE << " skipping Tile hash " << m_calo_id->calo_cell_hash(aCell->ID()) << endreq; + continue; + } else if (m_skipDeadDrawer) { + + Identifier id = aCell->ID(); + int part = std::min(m_tile_id->section(id),2)+m_tile_id->side(id); + int module = m_tile_id->module(id); + if ( nGoodCellsPerDrawer[part][module] < 2 ) { + if (lVerbose) log << MSG::VERBOSE << " skipping Tile drawer hash " << m_calo_id->calo_cell_hash(aCell->ID()) << endreq; + continue; + } + } + + } else { + + if (m_skipDeadLAr) { + if (lVerbose) log << MSG::VERBOSE << " skipping LAr hash " << m_calo_id->calo_cell_hash(aCell->ID()) << endreq; + continue; + } else if (m_skipDeadFeb && ((aCell->provenance() & 0x0200) == 0x0200) ) { + if (lVerbose) log << MSG::VERBOSE << " skipping LAr Feb hash " << m_calo_id->calo_cell_hash(aCell->ID()) << endreq; + continue; + } + } + + //inspired from http://alxr.usatlas.bnl.gov/lxr-stb3/source/atlas/Calorimeter/CaloRec/src/CaloTopoClusterMaker.cxx#585 + //We need a IdentifierHash to pass as input to the get_neighbors(). + // IdentifierHash theCellHashID = theCell->getID(); //this doesn't work (any more?) + Identifier theCellID = aCell->ID(); + IdentifierHash theCellHashID = m_calo_id->calo_cell_hash(theCellID); + + if (lVerbose) log << MSG::VERBOSE << " correcting " << ((isTile)?"Tile":"LAr") << " hash " << theCellHashID << endreq; + + //Find now the neighbors around theCell, and store them in theNeighbors vector. + m_calo_id->get_neighbours(theCellHashID,m_nOption,theNeighbors); + + //std::cout << "Found " << theNeighbors.size() << " neighbors." << std::endl; + + //first let's find the volume of theCell we are correcting. + float volumeOfTheCell=0; + if (caloDDE) volumeOfTheCell = caloDDE->volume(); + // std::cout << " volumeOfTheCell " << volumeOfTheCell << std::endl; + if (volumeOfTheCell==0) continue; + int theCellSampling = caloDDE->getSampling(); + // if (theCellSubCalo == CaloCell_ID::TILE) { + // std::cout << "theCell = " << theCellSubCalo << " " << theCellSampling << " is at eta=" << aCell->eta() << " phi=" << aCell->phi() << " E=" << aCell->energy() << " V=" << volumeOfTheCell*1e-6 << "D=" << aCell->energy() / volumeOfTheCell * 1e6 << std::endl; + // } + + //loop through neighbors, and calculate average energy density of guys who have a legitimate volume (namely >0). + float totalEnergyDensity=0; + float legitimateNeighbors=0; + for (unsigned int iN=0;iN<theNeighbors.size();iN++) { + const CaloCell* thisNeighbor = theCont->findCell(theNeighbors[iN]); + //if there is a hardware problem in real data, then the above pointer may be NULL. In that case the geometric neighbor is absent from the container, so we should move on to the next geometric neighbor. + if (!thisNeighbor) continue; + const CaloDetDescrElement* thisNeighborDDE = (thisNeighbor)->caloDDE(); + float thisEnergy = thisNeighbor->energy(); + if (m_testMode) { + thisEnergy = cannedUncorrectedEnergies[thisNeighbor]; + // std::cout << "GEORGIOS DEBUGGING Retrieving cannedUncorrectedEnergies[" << thisNeighbor << "] = " << cannedUncorrectedEnergies[thisNeighbor] << std::endl; + } + if (thisNeighbor->badcell()) continue; + int thisNeighborSubCalo = thisNeighborDDE->getSubCalo(); + int thisNeighborSampling = thisNeighborDDE->getSampling(); + if (thisNeighborSubCalo != theCellSubCalo) continue; + if (thisNeighborSampling != theCellSampling) continue; //if the quality of the cell is very different, it's a wrong idea that dE/dV would be similar. + float thisVolume = thisNeighborDDE->volume(); + if (thisVolume <= 0) continue; + + legitimateNeighbors++; + float thisEnergyDensity= thisEnergy / thisVolume; + totalEnergyDensity += thisEnergyDensity; + + // if (theCellSubCalo == CaloCell_ID::TILE && theCellSampling == CaloCell_ID::TileBar0) + // std::cout << "Neighbor " << iN << " : " << thisNeighborSubCalo << " , " << thisNeighborSampling << " : " << thisNeighbor->eta() << " , " << thisNeighbor->phi() << " E=" << thisNeighbor->energy() << " V=" << thisVolume*1e-6 << " D=" << thisEnergyDensity*1e6 << std::endl; + + } + float averageEnergyDensity=0; + if(legitimateNeighbors <= 0) continue; + averageEnergyDensity = totalEnergyDensity / legitimateNeighbors; + + //now use the average energy density to make a prediction for the energy of theCell + float predictedEnergy = averageEnergyDensity * volumeOfTheCell; + aCell->setEnergy(predictedEnergy); + + } // end of if(badcell) + } // end loop over cells + return StatusCode::SUCCESS; +} + +//memo: + /** From CaloCell_ID.h: + //enumeration of sub calorimeters + enum SUBCALO { LAREM = 0, LARHEC = 1, LARFCAL = 2, TILE = 3, NSUBCALO = 4, NOT_VALID=999999 }; + + //enumeration of samplings (i.e.layers) separately for various sub calorimeters + enum CaloSample { + PreSamplerB=0, EMB1, EMB2, EMB3, // LAr barrel + PreSamplerE, EME1, EME2, EME3, // LAr EM endcap + HEC0, HEC1, HEC2, HEC3, // Hadronic end cap cal. + TileBar0, TileBar1, TileBar2, // Tile barrel + TileGap1, TileGap2, TileGap3, // Tile gap (ITC & scint) + TileExt0, TileExt1, TileExt2, // Tile extended barrel + FCAL0, FCAL1, FCAL2, // Forward EM endcap + Unknown + }; + */ diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx new file mode 100755 index 00000000000..ddb1e14db79 --- /dev/null +++ b/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx @@ -0,0 +1,235 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// **************************************************************************************** +// +// To perform cell per cell pedestal shift correction +// taking the pedestal shift in MeV from the database /CALO/Pedestal/CellPedestal folder +// +// G.Unal 9 may 2008 .... first version +// +// **************************************************************************************** + +#include "CaloCellCorrection/CaloCellPedestalCorr.h" + +#include "CaloEvent/CaloCell.h" +#include "CaloDetDescr/CaloDetDescrElement.h" + +//=== AttributeList +#include "CoralBase/Blob.h" +#include "AthenaPoolUtilities/CondAttrListCollection.h" +//=== CaloCondBlod +#include "CaloCondBlobObjs/CaloCondBlobFlt.h" +#include "CaloCondBlobObjs/CaloCondUtils.h" + +#include "GaudiKernel/MsgStream.h" +#include "StoreGate/StoreGateSvc.h" + + +#include "CaloIdentifier/CaloCell_ID.h" + +// ====================================================== +// Constructor + +CaloCellPedestalCorr::CaloCellPedestalCorr( + const std::string& type, + const std::string& name, + const IInterface* parent) + : CaloCellCorrection(type, name, parent), + m_caloCoolIdTool("CaloCoolIdTool"),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_lastIt=m_noiseBlobMap.begin(); +} + +//======================================================== +// Initialize + +StatusCode CaloCellPedestalCorr::initialize() +{ + MsgStream log(msgSvc(),name()); + log << MSG::INFO << " in CaloCellPedestalCorr::initialize() " << endreq; + + StoreGateSvc* detStore; + StatusCode sc = service ( "DetectorStore" , detStore ) ; + if (sc.isFailure()) { + log << MSG::ERROR << " Unable to get DetectorStore " << endreq; + return StatusCode::FAILURE; + } + + sc=detStore->retrieve(m_cellId, "CaloCell_ID"); + if (sc.isFailure()) { + log << MSG::ERROR << " Unable to get CaloCell_ID" << endreq; + return StatusCode::FAILURE; + } + + + if (m_lumi0<0) { + if (detStore->contains<CondAttrListCollection>(m_lumiFolderName)) { + const DataHandle<CondAttrListCollection> lumiData; + sc = detStore->regFcn(&CaloCellPedestalCorr::updateLumi, this , lumiData, m_lumiFolderName, true); + if (sc.isFailure()) { + log << MSG::ERROR << " cannot register callback for luminosity " << endreq; + return StatusCode::FAILURE; + } + log << MSG::INFO << " Registered a callback for " << m_lumiFolderName << " Cool folder " << endreq; + } + m_lumi0=0; + } + + + if (!m_isMC) { + //=== Register callback for this data handle + sc=detStore->regFcn(&CaloCellPedestalCorr::updateMap, this, m_noiseAttrListColl, m_folderName); + if (sc.isFailure()) { + log << MSG::ERROR << " cannot register callback " << endreq; + return StatusCode::FAILURE; + } + log << MSG::INFO << " registered a callback for " << m_folderName << " folder " << endreq; + + sc = m_caloCoolIdTool.retrieve(); + if (sc.isFailure()) { + log << MSG::ERROR << " cannot retrieve CaloCoolIdTool" << endreq; + return StatusCode::FAILURE; + } + } + + if (!m_caloLumiBCIDTool.empty() ) { + sc = m_caloLumiBCIDTool.retrieve(); + if (sc.isFailure()) { + log <<MSG::ERROR << " cannot retrieve LumiBCIDTool" << endreq; + return StatusCode::FAILURE; + } + } + + log << MSG::INFO << "CaloCellPedestalCorr initialize() end" << endreq; + + return StatusCode::SUCCESS; + +} + +//______________________________________________________________________________________ +StatusCode +CaloCellPedestalCorr::updateLumi( IOVSVC_CALLBACK_ARGS ) +{ + MsgStream log(msgSvc(), name()); + log << MSG::INFO << " in updateLumi() " << endreq; + + StoreGateSvc* detStore; + StatusCode sc = service ( "DetectorStore" , detStore ) ; + if (sc.isFailure()) { + log << MSG::ERROR << " Unable to get DetectorStore " << endreq; + return StatusCode::FAILURE; + } + + const CondAttrListCollection* attrListColl = 0; + sc = detStore->retrieve(attrListColl, m_lumiFolderName); + if (sc.isFailure() || !attrListColl) { + log << MSG::WARNING << "attrrListColl not found for " << m_lumiFolderName << endreq; + return StatusCode::SUCCESS; + } + // Loop over collection + CondAttrListCollection::const_iterator first = attrListColl->begin(); + CondAttrListCollection::const_iterator last = attrListColl->end(); + for (; first != last; ++first) { + if ((*first).first == 0) { + std::ostringstream attrStr1; + (*first).second.toOutputStream( attrStr1 ); + log << MSG::DEBUG << "ChanNum " << (*first).first << + " Attribute list " << attrStr1.str() << endreq; + const coral::AttributeList& attrList = (*first).second; + if (attrList["LBAvInstLumi"].isNull()) { + log << MSG::WARNING << " NULL Luminosity information in database ... set it to 0 " << endreq; + 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) ) { + log << MSG::WARNING << " Luminosity not a number ? m_lumi0 " << m_lumi0 << " ... set it to 0 " << endreq; + m_lumi0 = 0.; + } + log << MSG::INFO << " Luminosity " << m_lumi0 << endreq; + return StatusCode::SUCCESS; +} + + + +// =============================================================================== + +StatusCode CaloCellPedestalCorr::updateMap(IOVSVC_CALLBACK_ARGS_K(keys) ) +{ + + MsgStream log(msgSvc(),name()); + + log << MSG::INFO << " in updateMap "; + std::list<std::string>::const_iterator itr; + for (itr=keys.begin(); itr!=keys.end(); ++itr) { + log << *itr << " "; + } + log << endreq; + + //=== 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) + std::map<unsigned int, const CaloCondBlobFlt*>::iterator iOld = m_noiseBlobMap.find(sysId); + if(iOld != m_noiseBlobMap.end()){ + delete iOld->second; + } + + //=== 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 + m_lastIt=m_noiseBlobMap.begin(); + return StatusCode::SUCCESS; +} + +// ============================================================================ + +void CaloCellPedestalCorr::MakeCorrection(CaloCell* theCell) +{ + const unsigned int cellHash=m_cellId->calo_cell_hash(theCell->ID()); + + float pedestal=0.; + + if (!m_isMC) { + unsigned int subHash; + const unsigned int iCool = m_caloCoolIdTool->getCoolChannelId(cellHash,subHash); + //std::cout << "Got iCool=" << iCool << " subhash=" << subHash << std::endl; + if (m_lastIt->first!=iCool) { + m_lastIt=m_noiseBlobMap.find(iCool); + } + //The following checks would make sense but were obmitted to speed up execution: + //1. m_lastIt!=m_noiseBlobMap.end() eg, if iCool exists + //2. subHash < flt->getNChans() + const CaloCondBlobFlt* const flt = m_lastIt->second; + const unsigned int dbGain = CaloCondUtils::getDbCaloGain(theCell->gain()); + pedestal = flt->getCalib(subHash, dbGain, m_lumi0); + } + + if (!m_caloLumiBCIDTool.empty() ) { + pedestal = pedestal + m_caloLumiBCIDTool->average(theCell,0); + } + + theCell->addEnergy(-pedestal); +} diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellRandomizer.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellRandomizer.cxx new file mode 100644 index 00000000000..9c48f31e82f --- /dev/null +++ b/Calorimeter/CaloCellCorrection/src/CaloCellRandomizer.cxx @@ -0,0 +1,175 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +// **************************************************************************************** +// Randomize calo cell energy according to CaloNoiseTool +// +// D. Varouchas +// +// **************************************************************************************** + +#include "CaloCellCorrection/CaloCellRandomizer.h" + +#include "GaudiKernel/RndmGenerators.h" +#include "GaudiKernel/IRndmGenSvc.h" + + +#include "CaloEvent/CaloCell.h" +#include "CaloDetDescr/CaloDetDescrElement.h" +//#include "CaloUtils/ICaloNoiseTool.h" +#include "CaloInterface/ICalorimeterNoiseTool.h" + +#include <CLHEP/Random/Randomize.h> + +#include "GaudiKernel/MsgStream.h" + + +using CLHEP::RandGauss; + + +// ====================================================== +// Constructor + +CaloCellRandomizer::CaloCellRandomizer( + const std::string& type, + const std::string& name, + const IInterface* parent) + : CaloCellCorrection(type, name, parent), + m_noiseTool("undefined"), m_corrSampleMin(0),m_corrSampleMax(0),m_fractionSigma(1),m_GaussRand(false),m_GaussRandGroupedSamples(false),m_GaussRandShifted(false),m_GaussRandShifted_Custom(false), m_shift_EMB(1),m_shift_EMEC(1),m_shift_HEC(1),m_shift_TileBar(1),m_shift_TileGap(1),m_shift_TileExt(1),m_shift_FCAL(1) + +{ + declareInterface<CaloCellCorrection>(this); + declareProperty("noiseTool",m_noiseTool,"Tool Handle for noise tool"); + // declareProperty("SampleNums",m_sampleNums); + declareProperty("DoRandomSampleMin",m_corrSampleMin); + declareProperty("DoRandomSampleMax",m_corrSampleMax); + declareProperty("RandomiseGroupedSampleCells",m_GaussRandGroupedSamples); + declareProperty("DoGaussRandomization",m_GaussRand); + declareProperty("DoShiftedGaussRandomization",m_GaussRandShifted); + declareProperty("FractionOfSigmaNoiseInShifting",m_fractionSigma); + + declareProperty("DoShiftedGaussRandomizationCustomisedInCalo",m_GaussRandShifted_Custom); + declareProperty("CustomShiftEMB",m_shift_EMB); + declareProperty("CustomShiftEMEC",m_shift_EMEC); + declareProperty("CustomShiftHEC",m_shift_HEC); + declareProperty("CustomShiftTileBar",m_shift_TileBar); + declareProperty("CustomShiftTileGap",m_shift_TileGap); + declareProperty("CustomShiftTileExt",m_shift_TileExt); + declareProperty("CustomShiftFCAL",m_shift_FCAL); + +} + +//======================================================== +// Initialize + +StatusCode CaloCellRandomizer::initialize() +{ + MsgStream log(msgSvc(),name()); + log << MSG::INFO << " in CaloCellRandomizer::initialize() " << endreq; + + + + if(m_noiseTool.retrieve().isFailure()){ + log << MSG::INFO + << "Unable to find tool for CaloNoiseTool" + << endreq; + return StatusCode::FAILURE; + } + else { + log << MSG::INFO << "Noise Tool retrieved" << endreq; + } + + log << MSG::INFO << "CaloCellRandomizer initialize() end" << endreq; + + + return StatusCode::SUCCESS; + +} + + +// ============================================================================ + +void CaloCellRandomizer::MakeCorrection(CaloCell* theCell) +{ + + int sampl = 0; + float Gauss = 0; + float GaussShifted = 0; + + const CaloDetDescrElement* caloDDE = theCell->caloDDE(); + sampl=caloDDE->getSampling(); + + //CaloNoiseTool + double SigmaNoise = m_noiseTool->getNoise(theCell,ICalorimeterNoiseTool::ELECTRONICNOISE); + + + Gauss = RandGauss::shoot(0.,1.); + + GaussShifted = Gauss+m_fractionSigma; + + + MsgStream log(msgSvc(),name()); + + + + if( m_GaussRand ){ + setenergy(theCell,(Gauss*SigmaNoise)); + } + + + if(m_GaussRandShifted){ + // setenergy(theCell,(GaussShifted)); + setenergy(theCell,(GaussShifted*SigmaNoise)); + } + + + if(m_GaussRandShifted_Custom){//var + if (sampl<4){ + GaussShifted = RandGauss::shoot(m_shift_EMB*SigmaNoise,SigmaNoise); + setenergy(theCell,(GaussShifted)); + } + if (sampl>3 && sampl<8){ + GaussShifted = RandGauss::shoot(m_shift_EMEC*SigmaNoise,SigmaNoise); + setenergy(theCell,(GaussShifted)); + } + if (sampl>7 && sampl<12){ + GaussShifted = RandGauss::shoot(m_shift_HEC*SigmaNoise,SigmaNoise); + setenergy(theCell,(GaussShifted)); + } + if (sampl>11 && sampl<15){ + GaussShifted = RandGauss::shoot(m_shift_TileBar*SigmaNoise,SigmaNoise); + setenergy(theCell,(GaussShifted)); + } + if (sampl>14 && sampl<18){ + GaussShifted = RandGauss::shoot(m_shift_TileGap*SigmaNoise,SigmaNoise); + setenergy(theCell,(GaussShifted)); + } + if (sampl>17 && sampl<21){ + GaussShifted = RandGauss::shoot(m_shift_TileExt*SigmaNoise,SigmaNoise); + setenergy(theCell,(GaussShifted)); + } + if (sampl>20 && sampl<24){ + GaussShifted = RandGauss::shoot(m_shift_FCAL*SigmaNoise,SigmaNoise); + setenergy(theCell,(GaussShifted)); + } + + } + + + if(m_GaussRandGroupedSamples){ + if(sampl>m_corrSampleMin && sampl<m_corrSampleMax){ + setenergy(theCell,(Gauss*SigmaNoise)); + } + } + + + //check if cells were masked before from tile reco alg, so to remove them, Tile Case only + // const TileCell* aTileCell = dynamic_cast<const TileCell*> (theCell); + //if CaloNoiseTool big values means we have bad cells (for tile when badcell is not applicalble). get ride of these cells + if ( (sampl>11 && sampl<21) && SigmaNoise>999){ + setenergy(theCell,0); + } + + +} diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellRescaler.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellRescaler.cxx new file mode 100755 index 00000000000..dbaa510753e --- /dev/null +++ b/Calorimeter/CaloCellCorrection/src/CaloCellRescaler.cxx @@ -0,0 +1,60 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "CaloCellCorrection/CaloCellRescaler.h" +#include "GaudiKernel/MsgStream.h" +#include "CaloEvent/CaloCell.h" +#include "CaloDetDescr/CaloDetDescrElement.h" + +CaloCellRescaler::CaloCellRescaler (const std::string& type, + const std::string& name, + const IInterface* parent) : + CaloCellCorrection(type, name, parent) { + declareInterface<CaloCellCorrection>(this); + declareProperty("FactorToCellsEMB0", m_factorToCells[CaloCell_ID::PreSamplerB] = 1.0, "cells in emb0 are scaled by FactorToCellsEMB0"); + declareProperty("FactorToCellsEMB1", m_factorToCells[CaloCell_ID::EMB1] = 1.0, "cells in emb1 are scaled by FactorToCellsEMB1"); + declareProperty("FactorToCellsEMB2", m_factorToCells[CaloCell_ID::EMB2] = 1.0, "cells in emb2 are scaled by FactorToCellsEMB2"); + declareProperty("FactorToCellsEMB3", m_factorToCells[CaloCell_ID::EMB3] = 1.0, "cells in emb3 are scaled by FactorToCellsEMB3"); + declareProperty("FactorToCellsEME0", m_factorToCells[CaloCell_ID::PreSamplerE] = 1.0, "cells in eme0 are scaled by FactorToCellsEME0"); + declareProperty("FactorToCellsEME1", m_factorToCells[CaloCell_ID::EME1] = 1.0, "cells in eme1 are scaled by FactorToCellsEME1"); + declareProperty("FactorToCellsEME2", m_factorToCells[CaloCell_ID::EME2] = 1.0, "cells in eme2 are scaled by FactorToCellsEME2"); + declareProperty("FactorToCellsEME3", m_factorToCells[CaloCell_ID::EME3] = 1.0, "cells in eme3 are scaled by FactorToCellsEME3"); + declareProperty("FactorToCellsHEC0", m_factorToCells[CaloCell_ID::HEC0] = 1.0, "cells in hec0 are scaled by FactorToCellsHEC0"); + declareProperty("FactorToCellsHEC1", m_factorToCells[CaloCell_ID::HEC1] = 1.0, "cells in hec1 are scaled by FactorToCellsHEC1"); + declareProperty("FactorToCellsHEC2", m_factorToCells[CaloCell_ID::HEC2] = 1.0, "cells in hec2 are scaled by FactorToCellsHEC2"); + declareProperty("FactorToCellsHEC3", m_factorToCells[CaloCell_ID::HEC3] = 1.0, "cells in hec3 are scaled by FactorToCellsHEC3"); + declareProperty("FactorToCellsTILEB0",m_factorToCells[CaloCell_ID::TileBar0] = 1.0,"cells in tilebar0 are scaled by FactorToCellsTILEB0"); + declareProperty("FactorToCellsTILEB1",m_factorToCells[CaloCell_ID::TileBar1] = 1.0,"cells in tilebar1 are scaled by FactorToCellsTILEB1"); + declareProperty("FactorToCellsTILEB2",m_factorToCells[CaloCell_ID::TileBar2] = 1.0,"cells in tilebar2 are scaled by FactorToCellsTILEB2"); + declareProperty("FactorToCellsTILEG1",m_factorToCells[CaloCell_ID::TileGap1] = 1.0,"cells in tilegap1 are scaled by FactorToCellsTILEG1"); + declareProperty("FactorToCellsTILEG2",m_factorToCells[CaloCell_ID::TileGap2] = 1.0,"cells in tilegap2 are scaled by FactorToCellsTILEG2"); + declareProperty("FactorToCellsTILEG3",m_factorToCells[CaloCell_ID::TileGap3] = 1.0,"cells in tilegap3 are scaled by FactorToCellsTILEG3"); + declareProperty("FactorToCellsTILEE0",m_factorToCells[CaloCell_ID::TileExt0] = 1.0,"cells in tileext0 are scaled by FactorToCellsTILEE0"); + declareProperty("FactorToCellsTILEE1",m_factorToCells[CaloCell_ID::TileExt1] = 1.0,"cells in tileext1 are scaled by FactorToCellsTILEE1"); + declareProperty("FactorToCellsTILEE2",m_factorToCells[CaloCell_ID::TileExt2] = 1.0,"cells in tileext2 are scaled by FactorToCellsTILEE2"); + declareProperty("FactorToCellsFCAL0", m_factorToCells[CaloCell_ID::FCAL0] = 1.0, "cells in fcal0 are scaled by FactorToCellsFCAL0"); + declareProperty("FactorToCellsFCAL1", m_factorToCells[CaloCell_ID::FCAL1] = 1.0, "cells in fcal1 are scaled by FactorToCellsFCAL1"); + declareProperty("FactorToCellsFCAL2", m_factorToCells[CaloCell_ID::FCAL2] = 1.0, "cells in fcal2 are scaled by FactorToCellsFCAl2"); + declareProperty("FactorToCellsMBTS", m_factorToCells[CaloCell_ID::Unknown] = 1.0, "cells in MBTS are scaled by FactorToCellsMBTS"); +} + + +CaloCellRescaler::~CaloCellRescaler() {} + + +StatusCode CaloCellRescaler::initialize() { + MsgStream log(msgSvc(), name()); + log << MSG::INFO << " initialization " << endreq; + return StatusCode::SUCCESS; +} + + +void CaloCellRescaler::MakeCorrection(CaloCell* theCell) { + + const CaloDetDescrElement* caloDDE = theCell->caloDDE(); + if (caloDDE) { + theCell->scaleEnergy( m_factorToCells[caloDDE->getSampling()] ); + } + return; +} diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellTimeCorrTool.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellTimeCorrTool.cxx new file mode 100644 index 00000000000..603f0270d08 --- /dev/null +++ b/Calorimeter/CaloCellCorrection/src/CaloCellTimeCorrTool.cxx @@ -0,0 +1,67 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "CaloCellCorrection/CaloCellTimeCorrTool.h" +#include "CaloEvent/CaloCell.h" +#include "CaloCondBlobObjs/CaloCondBlobFlt.h" + + +CaloCellTimeCorrTool::CaloCellTimeCorrTool (const std::string& type, + const std::string& name, + const IInterface* parent) : + CaloCellCorrection(type, name, parent), + m_corrValues(0) { + declareInterface<CaloCellCorrection>(this); + declareProperty("Folder",m_key="/CALO/Ofl/CellTimeCorr", + "Key (=foldername) of AttrListCollection"); +} + + +CaloCellTimeCorrTool::~CaloCellTimeCorrTool() {} + + +StatusCode CaloCellTimeCorrTool::initialize() { + StatusCode sc=detStore()->regFcn(&CaloCellTimeCorrTool::load, + dynamic_cast<CaloCellTimeCorrTool*>(this), + m_attrList,m_key); + if (sc.isFailure()) { + msg(MSG::ERROR) << "Cound not register Callback function for AthenaAttributeList with key " << m_key << endreq; + return sc; + } + return StatusCode::SUCCESS; +} + + +StatusCode CaloCellTimeCorrTool::load(IOVSVC_CALLBACK_ARGS) { + + ATH_MSG_INFO("in IOV callback function"); + if (m_corrValues) { + ATH_MSG_INFO("Delete previously loaded correction values"); + delete m_corrValues; + m_corrValues=0; + } + + + const coral::Blob& blob = (*m_attrList)["CaloCondBlob16M"].data<coral::Blob>(); + if (blob.size()<3) { + ATH_MSG_INFO("Found empty blob, no corretion needed :-)"); + } + else { + m_corrValues=CaloCondBlobFlt::getInstance(blob); + ATH_MSG_INFO("Database folder has vaues for " << m_corrValues->getNChans() << " channels and " << m_corrValues->getNGains() << " gains."); + } + return StatusCode::SUCCESS; +} + + +void CaloCellTimeCorrTool::MakeCorrection(CaloCell* theCell) { + if (m_corrValues) { + const IdentifierHash& hash_id=theCell->caloDDE()->calo_hash(); + if (hash_id<m_corrValues->getNChans()) { + const float& shift= m_corrValues->getData(hash_id,0,0); + theCell->setTime(theCell->time()+shift); + } + } + return; +} diff --git a/Calorimeter/CaloCellCorrection/src/components/CaloCellCorrection_entries.cxx b/Calorimeter/CaloCellCorrection/src/components/CaloCellCorrection_entries.cxx new file mode 100755 index 00000000000..ed80fa95b18 --- /dev/null +++ b/Calorimeter/CaloCellCorrection/src/components/CaloCellCorrection_entries.cxx @@ -0,0 +1,28 @@ +#include "CaloCellCorrection/CaloCellPedestalCorr.h" +#include "CaloCellCorrection/CaloCellMBAverageCorr.h" +#include "CaloCellCorrection/CaloCellNeighborsAverageCorr.h" +#include "CaloCellCorrection/CaloCellRandomizer.h" +#include "CaloCellCorrection/CaloCellRescaler.h" +#include "CaloCellCorrection/CaloCellEnergyRescaler.h" +#include "CaloCellCorrection/CaloCellTimeCorrTool.h" + +#include "GaudiKernel/DeclareFactoryEntries.h" + +DECLARE_TOOL_FACTORY( CaloCellPedestalCorr ) +DECLARE_TOOL_FACTORY( CaloCellMBAverageCorr ) +DECLARE_TOOL_FACTORY( CaloCellNeighborsAverageCorr ) +DECLARE_TOOL_FACTORY( CaloCellRandomizer ) +DECLARE_TOOL_FACTORY( CaloCellRescaler ) +DECLARE_TOOL_FACTORY( CaloCellEnergyRescaler ) +DECLARE_TOOL_FACTORY ( CaloCellTimeCorrTool ) + + +DECLARE_FACTORY_ENTRIES(CaloCellCorrection) { + DECLARE_TOOL( CaloCellPedestalCorr ) + DECLARE_TOOL( CaloCellMBAverageCorr ) + DECLARE_TOOL( CaloCellNeighborsAverageCorr ) + DECLARE_TOOL( CalloCellRandomizer ) + DECLARE_TOOL( CaloCellRescaler ) + DECLARE_TOOL( CaloCellEnergyRescaler ) + DECLARE_TOOL ( CaloCellTimeCorrTool ) +} diff --git a/Calorimeter/CaloCellCorrection/src/components/CaloCellCorrection_load.cxx b/Calorimeter/CaloCellCorrection/src/components/CaloCellCorrection_load.cxx new file mode 100755 index 00000000000..792d08ed79e --- /dev/null +++ b/Calorimeter/CaloCellCorrection/src/components/CaloCellCorrection_load.cxx @@ -0,0 +1,4 @@ +#include "GaudiKernel/LoadFactoryEntries.h" + +LOAD_FACTORY_ENTRIES(CaloCellCorrection) + -- GitLab