From b97a77aa7018a010724af7ea1077c9cb76fcd375 Mon Sep 17 00:00:00 2001
From: scott snyder <sss@karma>
Date: Fri, 10 May 2019 14:23:03 +0200
Subject: [PATCH] CaloUtils: Remove LocalNoiseSuppressionTool.

LocalNoiseSuppressionTool isn't used from anywhere and was relying on the
old CaloNoiseTool via a mutable declaration.  Remove it.
---
 .../CaloUtils/LocalNoiseSuppressionTool.h     | 142 -------
 .../src/LocalNoiseSuppressionTool.cxx         | 346 ------------------
 .../src/components/CaloUtils_entries.cxx      |   2 -
 3 files changed, 490 deletions(-)
 delete mode 100644 Calorimeter/CaloUtils/CaloUtils/LocalNoiseSuppressionTool.h
 delete mode 100644 Calorimeter/CaloUtils/src/LocalNoiseSuppressionTool.cxx

diff --git a/Calorimeter/CaloUtils/CaloUtils/LocalNoiseSuppressionTool.h b/Calorimeter/CaloUtils/CaloUtils/LocalNoiseSuppressionTool.h
deleted file mode 100644
index a74007faf7b..00000000000
--- a/Calorimeter/CaloUtils/CaloUtils/LocalNoiseSuppressionTool.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
-  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
-*/
-
-#ifndef CALOUTILS_LOCALNOISESUPPRESSIONTOOL_H
-#define CALOUTILS_LOCALNOISESUPPRESSIONTOOL_H
-
-
-/********************************************************************
-
-NAME:     LocalNoiseSuppressionTool.h 
-PACKAGE:  offline/Calorimeter/CaloUtils
-
-AUTHORS:  Kyle Cranmer <cranmer@cern.ch>
-CREATED:  Feb 8, 2005
-
-PURPOSE: Performs Local Noise Suppression CaloCell objects Inherits
-          from ICellWeightTool, which is the base class for
-          individual cell correction classes.
-
-********************************************************************/
-
-class CaloCell;
-class CaloCellContainer;
-
-#include "CaloInterface/ICellWeightTool.h"
-#include "CaloInterface/ICaloNoiseTool.h"
-#include "CaloIdentifier/CaloCell_ID.h"
-#include "GaudiKernel/ToolHandle.h" 
-#include "AthenaBaseComps/AthAlgTool.h"
-#include "AthenaKernel/IOVSvcDefs.h"
-
-#include "StoreGate/StoreGateSvc.h"
-
-class CaloDetDescrManager; 
-
-class LocalNoiseSuppressionTool : public AthAlgTool, virtual public ICellWeightTool
-{
-
- public:
-
-  LocalNoiseSuppressionTool(const std::string& type, const std::string& name,
-		    const IInterface* parent);
-  virtual ~LocalNoiseSuppressionTool();
-
-  // Main access method: Correct cells in cellCollection:
-  virtual StatusCode initialize() override;
-
-  /// Implementation for ICellWeightTool.
-  virtual double wtCell(const CaloCell*) const override;
-
-  // special functions for this tool (hide interface)
-  ///Sets the calocell container used for finding neighbors. 
-  virtual void   setCaloCellContainer(const CaloCellContainer* ); 
-
-  /// Test if the cell should be cut based on neighbors and the cell's energy.
-  virtual bool   cutCell(const CaloCell*) const;
-
-  /// Get the prior probability that this cell is noise based on the neighbors and a given test statistic.
-  virtual double getPrior(const CaloCell*) const;
-
-  /// Get the test statistic (which is based on neighbors) used to distinguish noisy cells from energetic cells.
-  virtual double getTestStatistic(const CaloCell*, int& nNeighbors) const;
-
-  /* ----------versions which explicitly expose the interface--------------*/
-  /** returns the weight that should be used to scale this cells
-   energy.  This is not a calibration, but the weighted average
-   between the measured energy in the cell and 0 (the true energy
-   of a noisy cell).*/
-  virtual double wtCell(const CaloCellContainer*, const CaloCell*); 
-
-  /// Test if the cell should be cut based on neighbors and the cell's energy.
-  virtual bool   cutCell(const CaloCellContainer*, const CaloCell*); 
-
-  /// Get the prior probability that this cell is noise based on the neighbors and a given test statistic.
-  virtual double getPrior(const CaloCellContainer*, const CaloCell*); 
-
-  /// Get the test statistic (which is based on neighbors) used to distinguish noisy cells from energetic cells.
-  virtual double getTestStatistic(const CaloCellContainer*, const CaloCell*,
-                                  int& nNeighbors); 
-
- private:
-
-  // properties
-
-  /** The maximum prior returned by getPrior(). If the getPrior()
-      returns 1, then wtCell() will return 0 even if the cell is very
-      energetic.  This is meaningful in terms of Bayes theorem, but
-      probably not the desired behavior.  In order to avoid this, set
-      maxPrior (via job options) to something less than 1.  If
-      maxPrior=.99 a cell with 5sigma will have weight = 1.
-   */
-  double m_maxPrior;
-
-  /** The cut on getPrior() used to remove noisy cells.  This tool can
-      either be used to re-weight cells or to cut on them.  Cuts on
-      cells are controlled by *both* the prior (based on neighbors)
-      and the cell itself.  If the prior is large, then the cell is
-      probably noisy; however, it will not be cut unless it also fails
-      the cut on energy in terms of sigma.
-     
-  */
-  double m_cutThresholdOnPrior;
-
-  /** The cut on the cell's energy in sigma to remove noisy cells.  If
-      a cell has a prior greater than m_cutThresholdOnPrior AND E <
-      m_cutInsigma then it will be cut.
-   */	
-  double m_cutInSigma;  
-
-  /** Toggle for symmetric / asymmetric cut.  If m_symmetricCut==true
-      then a cell will be kept even if it's energy is < 0.  If
-      m_symmetricCut==false, then it will be kept only if it's energy
-      is > 0.
-   */
-  bool m_symmetricCut;
-
-  /// setup for CaloNoiseTool
-  bool m_usePileUp;  
-  /// setup for CaloNoiseTool
-  //int m_nMinBias;
-  
-  std::string m_caloCellContainerName;
-  std::string m_testStatistic;
-  std::string m_neighborOption;
-
-  double m_s0, m_s1, m_o0, m_o1;  
-
-  // used internally
-  double cellSigma(const CaloCell* theCell) const;
-  double scale (int nNeighbors) const;
-  double offset (int nNeighbors) const;
-
-  mutable ToolHandle<ICalorimeterNoiseTool> m_noiseTool;
-
-  const CaloDetDescrManager* m_calo_dd_man; 
-  const CaloCell_ID* m_calo_id;
-
-  const CaloCellContainer* m_caloCellContainer;
-};
-
-#endif
diff --git a/Calorimeter/CaloUtils/src/LocalNoiseSuppressionTool.cxx b/Calorimeter/CaloUtils/src/LocalNoiseSuppressionTool.cxx
deleted file mode 100644
index 1ee8cdd68c6..00000000000
--- a/Calorimeter/CaloUtils/src/LocalNoiseSuppressionTool.cxx
+++ /dev/null
@@ -1,346 +0,0 @@
-/*
-  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
-*/
-
-/********************************************************************
-
-NAME:     LocalNoiseSuppressionTool.h
-PACKAGE:  offline/Calorimeter/CaloUtils
-
-AUTHORS:  Kyle Cranmer <cranmer@cern.ch>
-CREATED:  Feb 8, 2005
-
-PURPOSE: Performs Local Noise Suppression CaloCell objects Inherits
-          from CaloCellCorrection, which is the base class for
-          individual cell correction classes.
-       
-********************************************************************/
-
-// Calo Header files:
-
-#include "CaloUtils/LocalNoiseSuppressionTool.h"
-#include "CaloEvent/CaloCellContainer.h"
-#include "CaloEvent/CaloCell.h"
-#include "CaloDetDescr/CaloDetDescrManager.h"
-
-// For Gaudi
-#include "GaudiKernel/ListItem.h"
-#include "GaudiKernel/IService.h"
-
-// CONSTRUCTOR:
-
-LocalNoiseSuppressionTool::LocalNoiseSuppressionTool(const std::string& type, 
-				     const std::string& name, 
-				     const IInterface* parent) 
-  : AthAlgTool(type, name, parent),
-    m_maxPrior(.999), m_cutThresholdOnPrior(999.),
-    m_cutInSigma(3.), m_symmetricCut(true),
-    m_usePileUp(false),
-    m_caloCellContainerName(""), 
-    m_testStatistic("max"), m_neighborOption("super3D"),
-    m_s0(1.05), m_s1(0.017), m_o0(1.1), m_o1(0.035),
-    m_noiseTool("CaloNoiseTool/CaloNoiseToolDefault"),
-    m_calo_dd_man(nullptr),
-    m_calo_id(nullptr),
-    m_caloCellContainer(nullptr)
-{
-
-  declareInterface<ICellWeightTool>(this);
-
-  declareProperty( "maxPrior", m_maxPrior);
-  declareProperty( "cutThresholdOnPrior", m_cutThresholdOnPrior);
-  declareProperty( "cutInSigma", m_cutInSigma);
-  declareProperty( "symmetricCut", m_symmetricCut);
-
-  declareProperty( "usePileUp", m_usePileUp);  
-  
-  declareProperty("CaloCellContainerName",m_caloCellContainerName);
-
-  declareProperty("CaloNoiseTool", m_noiseTool);  
-  declareProperty("testStatisticOption",m_testStatistic);
-  declareProperty("neighborOption",m_neighborOption);
-
-  declareProperty("scaleConst", m_s0);
-  declareProperty("scaleSlope", m_s1);
-  declareProperty("offsetConst",m_o0);
-  declareProperty("offsetSlope",m_o1);
-
-
- }
-
-// DESTRUCTOR:
-
-LocalNoiseSuppressionTool::~LocalNoiseSuppressionTool()
-{ 
-
-  m_caloCellContainer = 0;
-  
-}
-
-//////////////////////////////////////////////////////////////
-// Gaudi INITIALIZE method
-//////////////////////////////////////////////////////////////
-
-StatusCode LocalNoiseSuppressionTool::initialize() {
-
-//---- retrieve the noisetool ----------------
-
-  ATH_CHECK( m_noiseTool.retrieve() );
-  ATH_MSG_INFO( "Noise Tool retrieved"  );
-
-  // pointer to detector manager:
-  ATH_CHECK( detStore()->retrieve (m_calo_dd_man, "CaloMgr") );
-  m_calo_id   = m_calo_dd_man->getCaloCell_ID();
-
-
-  ATH_MSG_INFO( "The tool " << name() << " has been initialized with the following settings: " <<
-                "\n\tmaxPrior = " << m_maxPrior<<
-                "\n\tcutThresholdOnPrior = " << m_cutThresholdOnPrior<<
-                "\n\tcutInSigma = " << m_cutInSigma<<
-                "\n\tsymmetricCut = " << m_symmetricCut<<
-                "\n\tusePileUp = " << m_usePileUp<<  
-                "\n\tCaloCellContainerName = " <<m_caloCellContainerName<<
-                "\n\ttestStatisticOption = " <<m_testStatistic<<
-                "\n\tneighborOption = " <<m_neighborOption<<
-                "\n\tscaleConst = " << m_s0<<
-                "\n\tscaleSlope = " << m_s1<<
-                "\n\toffsetConst = " <<m_o0<<
-                "\n\toffsetSlope = " <<m_o1 );
-
-  // Return status code.
-  return StatusCode::SUCCESS;
-}
-
-
-
-void LocalNoiseSuppressionTool::setCaloCellContainer(const CaloCellContainer* cellColl ){
-  m_caloCellContainer = cellColl;
-  
-}
-
-double LocalNoiseSuppressionTool::wtCell( const CaloCellContainer* cellColl, 
-					  const CaloCell* theCell){
-  m_caloCellContainer = cellColl;
-  
-  return this->wtCell(theCell);
-}
-
-double LocalNoiseSuppressionTool::wtCell( const CaloCell* theCell ) const
-{
-  
-  double prior = this->getPrior( theCell );
-  double Em = theCell->e();
-
-  double rmsNoise = cellSigma(theCell);
-  double weight = (1-prior) / ( (1.-prior) + prior*exp(-Em*Em/(2.*rmsNoise*rmsNoise)) ); 
-
-  if ( this->cutCell(theCell) )    weight = 0;
-
-  return weight;
-  
-}
-
-bool LocalNoiseSuppressionTool::cutCell( const CaloCellContainer* cellColl, 
-					 const CaloCell* theCell){
-  m_caloCellContainer = cellColl;
-  
-  return this->cutCell(theCell);
-}
-
-bool LocalNoiseSuppressionTool::cutCell( const CaloCell* theCell) const {
-
-  double prior = this->getPrior( theCell );
-  double Em = theCell->e();
-  double rmsNoise = cellSigma(theCell);
-
-  if (Em < 0 && !m_symmetricCut) 
-    return true;
-
-  else if (prior > m_cutThresholdOnPrior && ( m_symmetricCut && fabs(Em) < m_cutInSigma*rmsNoise ) )
-    return true	;
-  
-  else if (prior > m_cutThresholdOnPrior && (!m_symmetricCut &&      Em  < m_cutInSigma*rmsNoise)  )
-    return true	;
-
-  else
-    return false;
-  
-  
-}
-
-
-double LocalNoiseSuppressionTool::getPrior( const CaloCellContainer* cellColl, 
-					    const CaloCell* theCell){
-  m_caloCellContainer = cellColl;
-  
-  return this->getPrior(theCell);
-}
-
-double LocalNoiseSuppressionTool::getPrior( const CaloCell* theCell) const {
-  
-  double ret =0;
-
-  int nNeighbors = 0;
-  double testStat = this->getTestStatistic(theCell, nNeighbors);
-  
-  if ( m_testStatistic == "sum" )        // For sum E/sigma
-    ret = erfc(testStat / sqrt(2. * nNeighbors ) );
-
-  else if ( m_testStatistic == "max" ) { // For max E/sigma
-    ret = .5*( 1. - erf( this->scale(nNeighbors) * (testStat - this->offset(nNeighbors)) ) );
-    
-  }
-  else{
-    
-    ATH_MSG_ERROR( "TestStatistic not set correctly.  Value = " << 
-                   m_testStatistic  );
-
-    ret  = 0;
-  }
-  
-  
-  if (ret > m_maxPrior ) ret = m_maxPrior;
-  
-  return ret;
-
-}
-
-
-
-
-double LocalNoiseSuppressionTool::getTestStatistic(const CaloCellContainer* cellColl,
-						   const CaloCell* theCell,
-                                                   int& nNeighbors){
-
-  m_caloCellContainer = cellColl;
-  return this->getTestStatistic(theCell, nNeighbors);
-  
-  
-}
-
-double
-LocalNoiseSuppressionTool::getTestStatistic( const CaloCell* theCell,
-                                             int& nNeighbors) const
-{
-  const CaloCellContainer* caloCellContainer = m_caloCellContainer;
-  
-  // this tool needs access to the neighboring cells via the container
-  // The interface of ICellWeightTool does not support that, so until
-  // a better solution is found, we will retrieve the container in
-  // initialize if the caloCellContainerName is specified.
-  if (m_caloCellContainerName != "" ) {
-    StatusCode sc = evtStore()->retrieve(caloCellContainer, m_caloCellContainerName);
-
-    if(sc.isFailure()  ||  !caloCellContainer) {
-      ATH_MSG_WARNING( "the CaloCellContainer " << m_caloCellContainerName 
-                     << "was not found in TDS" );
-      return -9999.;
-    }    
-  }
-
-
-  LArNeighbours::neighbourOption nOption;
-  
-  if (m_neighborOption == "all2D") 
-    nOption = LArNeighbours::all2D;
-  else if (m_neighborOption == "all3D") 
-    nOption = LArNeighbours::all3D;
-  else// (m_neighborOption == "super3D") 
-    nOption = LArNeighbours::super3D;
-
-  std::vector<IdentifierHash> theNNeighbors;
-  Identifier myId = theCell->ID();
-  IdentifierHash myHashId;
-  int otherSubDet;
-  myHashId = m_calo_id->subcalo_cell_hash(myId,otherSubDet);
-  m_calo_id->get_neighbours(myHashId,nOption,theNNeighbors);
-
-  double ret = 0;
-  
-  if ( m_testStatistic == "sum" ) {      // For sum E/sigma
-    double sumEoverSigma = 0;
-    nNeighbors = 0;
-    for (unsigned int i=0; i<theNNeighbors.size(); i++) {
-      const CaloCell* aNeighbor = caloCellContainer->findCell(theNNeighbors[i]);
-
-      if (aNeighbor != 0) {
-	nNeighbors++;  // needed in getPrior
-	sumEoverSigma  += aNeighbor->e()
-	  / this->cellSigma(aNeighbor);
-      }
-    }
-    ret = sumEoverSigma;    
-  } 
-
-
-  else if ( m_testStatistic == "max" ) {   //	 For max E/sigma
-    double maxEoverSigma = -9999.;
-    double thisEoverSigma = -9999.;
-  
-    nNeighbors = 0;
-    for (unsigned int i=0; i<theNNeighbors.size(); i++) {
-      const CaloCell* aNeighbor = caloCellContainer->findCell(theNNeighbors[i]);
-
-      if (aNeighbor != 0) {      
-	nNeighbors++; // needed in getPrior
-	thisEoverSigma = aNeighbor->e() 
-	  / this->cellSigma(aNeighbor);
-
-	if ( thisEoverSigma > maxEoverSigma )
-	  maxEoverSigma = thisEoverSigma;
-      }    	
-    }
-    ret = maxEoverSigma;
-  }
-
-  else {
-    nNeighbors = 0;
-  
-    // log oops
-    
-  }
-
-  return ret;
-  
-}
-
-
-double LocalNoiseSuppressionTool::cellSigma( const CaloCell* theCell) const {
-
-  double ret = 0;
-  
-  if (m_usePileUp == false) 
-    //    ret = m_noiseTool->elecNoiseRMSHighestGain(theCell);  
-    ret = m_noiseTool->getNoise(theCell,ICalorimeterNoiseTool::ELECTRONICNOISE_HIGHESTGAIN);  
-  //  else if (m_usePileUp == true && m_nMinBias >0 ) 
-  //    ret = m_noiseTool->totalNoiseRMSHighestGain(theCell,m_nMinBias);  
-  //    ret = m_noiseTool->getNoise(theCell,ICalorimeterNoiseTool::TOTALNOISE_HIGHESTGAIN);  
-  else 
-    // use noise tool's configuration
-    //    ret = m_noiseTool->totalNoiseRMSHighestGain(theCell, -1);  
-    ret = m_noiseTool->getNoise(theCell,ICalorimeterNoiseTool::TOTALNOISE_HIGHESTGAIN);  
-    
-  return ret;  
-}
-
-
-double LocalNoiseSuppressionTool::scale (int nNeighbors) const {
-  // the distribution of the "max" test statistic is complicated, 
-  //  but has been from Toy MC so to linear functions. 
-  //  The scale() and offset() methods are used in the transformation 
-  //  of the test statistic to a prior.
-  return m_s0 + m_s1*nNeighbors;  
-}
-
-double LocalNoiseSuppressionTool::offset (int nNeighbors) const {
-  // the distribution of the "max" test statistic is complicated, 
-  //  but has been from Toy MC so to linear functions. 
-  //  The scale() and offset() methods are used in the transformation 
-  //  of the test statistic to a prior.
-
-  return m_o0 + m_o1*nNeighbors;  
-}
-
-
-
-
diff --git a/Calorimeter/CaloUtils/src/components/CaloUtils_entries.cxx b/Calorimeter/CaloUtils/src/components/CaloUtils_entries.cxx
index c275736584f..bcbef33f5ff 100644
--- a/Calorimeter/CaloUtils/src/components/CaloUtils_entries.cxx
+++ b/Calorimeter/CaloUtils/src/components/CaloUtils_entries.cxx
@@ -1,4 +1,3 @@
-#include "CaloUtils/LocalNoiseSuppressionTool.h"
 #include "CaloUtils/CaloCellWeightCorrection.h"
 #include "CaloUtils/CaloLCClassificationTool.h"
 #include "CaloUtils/EstimEMClusterClassificationTool.h"
@@ -13,7 +12,6 @@
 
 
 DECLARE_COMPONENT( CaloCellWeightCorrection )
-DECLARE_COMPONENT( LocalNoiseSuppressionTool )
 DECLARE_COMPONENT( CaloLCClassificationTool )
 DECLARE_COMPONENT( EstimEMClusterClassificationTool )
 DECLARE_COMPONENT( CaloLCWeightTool )
-- 
GitLab