From 1cf0fee0c60079a561c3f4095367173bd9a4df7e Mon Sep 17 00:00:00 2001
From: Sven Menke <Sven.Menke@cern.ch>
Date: Mon, 30 Jan 2017 15:52:47 +0100
Subject: [PATCH] added cell-based mass as cluster moment MASS
 (CaloRec-03-01-04)

	* New ClusterMoment MASS
	* src/CaloClusterMomentsMaker.cxx
	* python/CaloClusterTopoGetter.py
	* tag CaloRec-03-01-04

2017-01-25  scott snyder  <snyder@bnl.gov>

	* Tagging CaloRec-03-01-03.
	* python/CaloClusterTopoCoolFolder.py: Use addFolder to declare
	folders to CondInputLoader.

	* Tagging CaloRec-03-01-02.
	* python/CaloClusterTopoCoolFolder.py: Declaring more
	CaloLocalHadCoeff folders to CondInputLoader.
	* CMakeLists.txt: Another pattern to ignore.

2017-01-19  Charles Leggett
	* remove #ifdef ATHENAHIVE to use DataPool in AthenaMT
	* tag CaloRec-03-01-01

...
(Long ChangeLog diff - truncated)


Former-commit-id: bad99dc96d7e7caba62b3b0c691311044a67d12d
---
 Calorimeter/CaloRec/CMakeLists.txt            |  4 +--
 .../python/CaloClusterTopoCoolFolder.py       | 19 +++++---------
 .../CaloRec/python/CaloClusterTopoGetter.py   |  1 +
 .../CaloRec/src/CaloCell2ClusterMapper.cxx    | 11 --------
 .../CaloRec/src/CaloClusterMomentsMaker.cxx   | 26 ++++++++++++++++++-
 5 files changed, 34 insertions(+), 27 deletions(-)

diff --git a/Calorimeter/CaloRec/CMakeLists.txt b/Calorimeter/CaloRec/CMakeLists.txt
index b761ca51335..69aef9b0abf 100644
--- a/Calorimeter/CaloRec/CMakeLists.txt
+++ b/Calorimeter/CaloRec/CMakeLists.txt
@@ -1,4 +1,4 @@
-# $Id: CMakeLists.txt 773817 2016-09-19 09:17:19Z krasznaa $
+# $Id: CMakeLists.txt 793768 2017-01-25 03:44:30Z ssnyder $
 ################################################################################
 # Package: CaloRec
 ################################################################################
@@ -73,7 +73,7 @@ atlas_add_test( CaloCellFastCopyTool_test
    SOURCES test/CaloCellFastCopyTool_test.cxx
    LINK_LIBRARIES CaloRecLib CaloEvent CaloDetDescrLib CaloIdentifier
    IdDictParser AthenaBaseComps StoreGateLib CxxUtils GaudiKernel
-   EXTRA_PATTERNS "Retrieved const handle|Service base class initialized|DEBUG Property update for OutputLevel" )
+   EXTRA_PATTERNS "Retrieved const handle|Service base class initialized|DEBUG Property update for OutputLevel|object not modifiable" )
 
 # Install files from the package:
 atlas_install_python_modules( python/*.py )
diff --git a/Calorimeter/CaloRec/python/CaloClusterTopoCoolFolder.py b/Calorimeter/CaloRec/python/CaloClusterTopoCoolFolder.py
index 0d88b9a4e4f..c0b1992b334 100644
--- a/Calorimeter/CaloRec/python/CaloClusterTopoCoolFolder.py
+++ b/Calorimeter/CaloRec/python/CaloClusterTopoCoolFolder.py
@@ -6,9 +6,6 @@ def _setupCaloClusterTopoCoolFolder():
     from CaloRec.CaloTopoClusterFlags import jobproperties
     from IOVDbSvc.CondDB import conddb
 
-    from AthenaCommon.AlgSequence import AlgSequence
-    topSequence = AlgSequence()
-
     doOverride=False
     TagSuffix=""
 
@@ -32,22 +29,18 @@ def _setupCaloClusterTopoCoolFolder():
     # rely on global tag for both MC and data; do not specify folder tags
     # use CALO_OFL only for GEO>=18
     if globalflags.DataSource()=='data' or doOverride:
-        conddb.addFolder("CALO","/CALO/HadCalibration2/CaloEMFrac")
+        conddb.addFolder("CALO","/CALO/HadCalibration2/CaloEMFrac", className='CaloLocalHadCoeff')
         conddb.addFolder("CALO","/CALO/HadCalibration2/H1ClusterCellWeights")
-        conddb.addFolder("CALO","/CALO/HadCalibration2/CaloOutOfCluster")
-        conddb.addFolder("CALO","/CALO/HadCalibration2/CaloOutOfClusterPi0")
+        conddb.addFolder("CALO","/CALO/HadCalibration2/CaloOutOfCluster", className='CaloLocalHadCoeff')
+        conddb.addFolder("CALO","/CALO/HadCalibration2/CaloOutOfClusterPi0", className='CaloLocalHadCoeff')
         conddb.addFolder("CALO","/CALO/HadCalibration2/CaloDMCorr2")
-
-        topSequence.CondInputLoader.Load += [ ('CaloLocalHadCoeff', '/CALO/HadCalibration2/CaloEMFrac') ]
     else:    
-        conddb.addFolder("CALO_OFL","/CALO/Ofl/HadCalibration2/CaloEMFrac")
+        conddb.addFolder("CALO_OFL","/CALO/Ofl/HadCalibration2/CaloEMFrac", className='CaloLocalHadCoeff')
         conddb.addFolder("CALO_OFL","/CALO/Ofl/HadCalibration2/H1ClusterCellWeights")
-        conddb.addFolder("CALO_OFL","/CALO/Ofl/HadCalibration2/CaloOutOfCluster")
-        conddb.addFolder("CALO_OFL","/CALO/Ofl/HadCalibration2/CaloOutOfClusterPi0")
+        conddb.addFolder("CALO_OFL","/CALO/Ofl/HadCalibration2/CaloOutOfCluster", className='CaloLocalHadCoeff')
+        conddb.addFolder("CALO_OFL","/CALO/Ofl/HadCalibration2/CaloOutOfClusterPi0", className='CaloLocalHadCoeff')
         conddb.addFolder("CALO_OFL","/CALO/Ofl/HadCalibration2/CaloDMCorr2")
 
-        topSequence.CondInputLoader.Load += [ ('CaloLocalHadCoeff', '/CALO/Ofl/HadCalibration2/CaloEMFrac') ]
-
 
     if doOverride:
 
diff --git a/Calorimeter/CaloRec/python/CaloClusterTopoGetter.py b/Calorimeter/CaloRec/python/CaloClusterTopoGetter.py
index f4eef6d4d5a..cfa8b074770 100644
--- a/Calorimeter/CaloRec/python/CaloClusterTopoGetter.py
+++ b/Calorimeter/CaloRec/python/CaloClusterTopoGetter.py
@@ -240,6 +240,7 @@ class CaloClusterTopoGetter ( Configured )  :
                                     ,"AVG_LAR_Q"
                                     ,"AVG_TILE_Q"
                                     ,"PTD"
+                                    ,"MASS"
                                     ]
 
 
diff --git a/Calorimeter/CaloRec/src/CaloCell2ClusterMapper.cxx b/Calorimeter/CaloRec/src/CaloCell2ClusterMapper.cxx
index 9e891633510..bcc4dac92c1 100644
--- a/Calorimeter/CaloRec/src/CaloCell2ClusterMapper.cxx
+++ b/Calorimeter/CaloRec/src/CaloCell2ClusterMapper.cxx
@@ -109,13 +109,8 @@ StatusCode CaloCell2ClusterMapper::execute_r(const EventContext& ctx) const {
   ATH_MSG_DEBUG(" Recording Cell2Cluster Map " << m_mapOutputKey.key());
 
   SG::WriteHandle<CaloCell2ClusterMap> cell2ClusterMap ( m_mapOutputKey, ctx );
-#ifndef ATHENAHIVE
   ATH_CHECK( cell2ClusterMap.record(std::make_unique<CaloCell2ClusterMap>
                                     (SG::VIEW_ELEMENTS)) );
-#else
-  ATH_CHECK( cell2ClusterMap.record(std::make_unique<CaloCell2ClusterMap>
-                                    (SG::OWN_ELEMENTS)) );
-#endif
 
   // resize it to total range of IdentifierHash for all calos
   Identifier::size_type maxRange = m_calo_id->calo_cell_hash_max();
@@ -133,9 +128,7 @@ StatusCode CaloCell2ClusterMapper::execute_r(const EventContext& ctx) const {
   std::vector<int> numberOfCells;
   numberOfCells.resize(clusColl->size());
 
-#ifndef ATHENAHIVE
   DataPool<Navigable<CaloClusterContainer> > navPool(maxRange);
-#endif
 
   // loop over cluster collection and add each cluster to the map for 
   // each member cell
@@ -151,11 +144,7 @@ StatusCode CaloCell2ClusterMapper::execute_r(const EventContext& ctx) const {
       Navigable<CaloClusterContainer> *theNav = (*cell2ClusterMap)[myHashId];
       if (!theNav) {
         // create a new Navigable if it doesn't exist
-#ifndef ATHENAHIVE	
         theNav = navPool.nextElementPtr();
-#else
-        theNav = new Navigable<CaloClusterContainer>();
-#endif
         theNav->removeAll();
         // and store it in the vector
         (*cell2ClusterMap)[myHashId] = theNav;
diff --git a/Calorimeter/CaloRec/src/CaloClusterMomentsMaker.cxx b/Calorimeter/CaloRec/src/CaloClusterMomentsMaker.cxx
index cf8c6108905..0b3bfea6faa 100644
--- a/Calorimeter/CaloRec/src/CaloClusterMomentsMaker.cxx
+++ b/Calorimeter/CaloRec/src/CaloClusterMomentsMaker.cxx
@@ -87,6 +87,7 @@ MomentName moment_names[] = {
   { "ISOLATION",         xAOD::CaloCluster::ISOLATION },
   { "LATERAL",           xAOD::CaloCluster::LATERAL },
   { "LONGITUDINAL",      xAOD::CaloCluster::LONGITUDINAL },
+  { "MASS",              xAOD::CaloCluster::MASS },
   { "N_BAD_CELLS",       xAOD::CaloCluster::N_BAD_CELLS },
   { "N_BAD_HV_CELLS",    xAOD::CaloCluster::N_BAD_HV_CELLS },
   { "N_BAD_CELLS_CORR",  xAOD::CaloCluster::N_BAD_CELLS_CORR },
@@ -413,7 +414,7 @@ CaloClusterMomentsMaker::execute(const EventContext& /*ctx*/,
   for( ;clusIter!=clusIterEnd;clusIter++,iClus++) {
     xAOD::CaloCluster * theCluster = *clusIter;
 
-    double w(0),xc(0),yc(0),zc(0);
+    double w(0),xc(0),yc(0),zc(0),mx(0),my(0),mz(0),mass(0);
     double eBad(0),ebad_dac(0),ePos(0),eBadLArQ(0),sumSig2(0),maxAbsSig(0);
     double eLAr2(0),eLAr2Q(0);
     double eTile2(0),eTile2Q(0);
@@ -571,6 +572,17 @@ CaloClusterMomentsMaker::execute(const EventContext& /*ctx*/,
 	  xc += ci.energy*ci.x;
 	  yc += ci.energy*ci.y;
 	  zc += ci.energy*ci.z;
+
+	  double dir = ci.x*ci.x+ci.y*ci.y+ci.z*ci.z;
+
+          if ( dir > 0) {
+	    dir = sqrt(dir);
+	    dir = 1./dir;
+	  }
+	  mx += ci.energy*ci.x*dir;
+	  my += ci.energy*ci.y*dir;
+	  mz += ci.energy*ci.z*dir;
+
 	  w  += ci.energy;
 	 
 	  ncell++;
@@ -578,6 +590,15 @@ CaloClusterMomentsMaker::execute(const EventContext& /*ctx*/,
       } //end of loop over all cells
 
       if ( w > 0 ) {
+	mass = w*w - mx*mx - my*my - mz*mz;
+	if ( mass > 0) {
+	  mass = sqrt(mass);
+	}
+	else {
+	  // make mass negative if m^2 was negative
+	  mass = -sqrt(-mass);
+	}
+
 	xc/=w;
 	yc/=w;
 	zc/=w;
@@ -953,6 +974,9 @@ CaloClusterMomentsMaker::execute(const EventContext& /*ctx*/,
 	  case xAOD::CaloCluster::PTD:
 	    myMoments[iMoment] = sqrt(myMoments[iMoment]);
             break;
+	  case xAOD::CaloCluster::MASS:
+	    myMoments[iMoment] = mass;
+	    break;
 	  default:
 	    // nothing to be done for other moments
 	    break;
-- 
GitLab