From c7def61488ceece6ad6aa7705973c20bd50a48f4 Mon Sep 17 00:00:00 2001
From: Teng Jian Khoo <teng.jian.khoo@cern.ch>
Date: Mon, 12 Dec 2016 17:08:51 +0100
Subject: [PATCH] 'setup for R21 configs, cmake and cmt example compilation
 with POOLRootAccess' (JetCalibTools-00-04-76-01)

	JetCalibTools-00-04-76-01
	* Setting up a config for r21
	* CMake compilation for example including POOLRootAccess for athena releases

2016-12-09 J. Bossio <jbossios@cern.ch>
	JetCalibTools-00-04-76
	* Using CalibArea-00-04-76
	* Bugfix in 20.7 JMS small-R config (bug affecting only data)
	* Fatal error when EventShape/rho not available

2016-11-21 TJ Khoo <khoo@cern.ch>
	JetCalibTools-00-04-75
	* Remove default constructor

2016-11-30 J. Bossio <jbossios@cern.ch>
	JetCalibTools-00-04-74
	* Using CalibArea-00-04-74
	* Bugfix in p-flow config (bug in JetCalibTools-00-04-73)

	Reverted detector eta modification


Former-commit-id: ca6537b00888fada6557000b300876f6034694fc
---
 .../Jet/JetCalibTools/CMakeLists.txt          | 10 ++++++-
 .../JetCalibTools/JetCalibrationTool.h        |  3 ---
 .../JetCalibTools/Root/JetCalibrationTool.cxx | 26 +++++++------------
 .../Jet/JetCalibTools/cmt/requirements        | 18 ++++++++++---
 .../util/JetCalibTools_Example.cxx            | 26 ++++++++++---------
 5 files changed, 46 insertions(+), 37 deletions(-)

diff --git a/Reconstruction/Jet/JetCalibTools/CMakeLists.txt b/Reconstruction/Jet/JetCalibTools/CMakeLists.txt
index 1484263caad..d7b48371285 100644
--- a/Reconstruction/Jet/JetCalibTools/CMakeLists.txt
+++ b/Reconstruction/Jet/JetCalibTools/CMakeLists.txt
@@ -1,4 +1,4 @@
-# $Id: CMakeLists.txt 778391 2016-10-14 00:23:00Z krasznaa $
+# $Id: CMakeLists.txt 789330 2016-12-12 17:07:48Z khoo $
 ################################################################################
 # Package: JetCalibTools
 ################################################################################
@@ -27,6 +27,7 @@ atlas_depends_on_subdirs(
    PRIVATE
    Event/xAOD/xAODMuon
    Tools/PathResolver
+   PhysicsAnalysis/POOLRootAccess
    ${extra_deps} )
 
 # External dependencies:
@@ -59,4 +60,11 @@ if( XAOD_STANDALONE )
       INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
       LINK_LIBRARIES ${ROOT_LIBRARIES} AsgTools xAODEventInfo xAODJet
       xAODEventShape xAODCore xAODRootAccess JetCalibToolsLib )
+else()
+   atlas_add_executable( JetCalibTools_Example
+      util/JetCalibTools_Example.cxx
+      INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
+      LINK_LIBRARIES ${ROOT_LIBRARIES} AsgTools xAODEventInfo xAODJet
+      xAODEventShape xAODCore POOLRootAccess xAODRootAccess JetCalibToolsLib )
 endif()
+
diff --git a/Reconstruction/Jet/JetCalibTools/JetCalibTools/JetCalibrationTool.h b/Reconstruction/Jet/JetCalibTools/JetCalibTools/JetCalibrationTool.h
index 82bcc14d384..08b4277a807 100644
--- a/Reconstruction/Jet/JetCalibTools/JetCalibTools/JetCalibrationTool.h
+++ b/Reconstruction/Jet/JetCalibTools/JetCalibTools/JetCalibrationTool.h
@@ -46,9 +46,6 @@ class JetCalibrationTool
 
 public: 
 
-  // Default constructor: 
-  JetCalibrationTool();
-
   /// Constructor with parameters: 
   JetCalibrationTool(const std::string& name);
 
diff --git a/Reconstruction/Jet/JetCalibTools/Root/JetCalibrationTool.cxx b/Reconstruction/Jet/JetCalibTools/Root/JetCalibrationTool.cxx
index bfbd50d8e5a..9d377c10964 100644
--- a/Reconstruction/Jet/JetCalibTools/Root/JetCalibrationTool.cxx
+++ b/Reconstruction/Jet/JetCalibTools/Root/JetCalibrationTool.cxx
@@ -31,7 +31,6 @@ JetCalibrationTool::JetCalibrationTool(const std::string& name)
   declareProperty( "IsData", m_isData = true );
   declareProperty( "ConfigDir", m_dir = "JetCalibTools/CalibrationConfigs/" );
   declareProperty( "EventInfoName", m_eInfoName = "EventInfo");
-  declareProperty( "DoSetDetectorEta", m_doSetDetectorEta=true);
 
 }
 
@@ -83,7 +82,7 @@ StatusCode JetCalibrationTool::initializeTool(const std::string& name) {
   }
 
   if ( config.EqualTo("") || !config ) { ATH_MSG_FATAL("No configuration file specified."); return StatusCode::FAILURE; } 
-  m_calibAreaTag.insert(0,"CalibArea-00-04-73/"); // Hard-coding the CalibArea tag
+  m_calibAreaTag.insert(0,"CalibArea-00-04-76/"); // Hard-coding the CalibArea tag
   if(calibSeq.Contains("DEV")){
     m_devMode = true;
     ATH_MSG_WARNING("Dev Mode is ON!!! \n\n");
@@ -114,8 +113,9 @@ StatusCode JetCalibrationTool::initializeTool(const std::string& name) {
   //Set the default units to MeV, user can override by calling setUnitsGeV(true)
   setUnitsGeV(false);
 
-  // Origin-corrected clusters? (true for rel21 and/or 2.5.X)
+  // Settings for R21/2.5.X
   m_originCorrectedClusters = m_globalConfig->GetValue("OriginCorrectedClusters",false);
+  m_doSetDetectorEta = m_globalConfig->GetValue("SetDetectorEta",true);
 
   //Make sure the residual correction is turned on if requested, protect against applying it without the jet area subtraction                    
   if ( !calibSeq.Contains("JetArea") && !calibSeq.Contains("Residual") ) {
@@ -393,31 +393,23 @@ StatusCode JetCalibrationTool::initializeEvent(JetEventInfo& jetEventInfo) const
   //Should be determined using EventShape object, use hard coded values if EventShape doesn't exist
   double rho=0;
   const xAOD::EventShape * eventShape = 0;
-  //std::string rhoKey = m_jetScale == EM ? "Kt4EMTopoEventShape" : "Kt4LCTopoEventShape";
-  static unsigned int eventShapeWarnings = 0;
   if ( m_doJetArea && evtStore()->contains<xAOD::EventShape>(m_rhoKey) ) {
     ATH_MSG_VERBOSE("  Found event density container " << m_rhoKey);
     if ( evtStore()->retrieve(eventShape, m_rhoKey).isFailure() || !eventShape ) {
       ATH_MSG_VERBOSE("  Event shape container not found.");
-      ++eventShapeWarnings;
-      rho = ( m_jetScale == EM || m_jetScale == PFLOW ? 6000. : 12000.);
-      if ( eventShapeWarnings < 20 )
-        ATH_MSG_WARNING("Could not retrieve xAOD::EventShape from evtStore, using hard-coded value, rho = " << rho/m_GeV << " GeV.");
+      ATH_MSG_FATAL("Could not retrieve xAOD::EventShape from evtStore.");
+      return StatusCode::FAILURE;
     } else if ( !eventShape->getDensity( xAOD::EventShape::Density, rho ) ) {
       ATH_MSG_VERBOSE("  Event density not found in container.");
-      ++eventShapeWarnings;
-      rho = ( m_jetScale == EM || m_jetScale == PFLOW ? 6000. : 12000.);
-      if ( eventShapeWarnings < 20 )
-        ATH_MSG_WARNING("Could not retrieve xAOD::EventShape::Density from xAOD::EventShape, using hard-coded value, rho = " << rho/m_GeV << " GeV.");
+      ATH_MSG_FATAL("Could not retrieve xAOD::EventShape::Density from xAOD::EventShape.");
+      return StatusCode::FAILURE;
     } else {
       ATH_MSG_VERBOSE("  Event density retrieved.");
     }
   } else if ( m_doJetArea && !evtStore()->contains<xAOD::EventShape>(m_rhoKey) ) {
     ATH_MSG_VERBOSE("  Rho container not found: " << m_rhoKey);
-    ++eventShapeWarnings;
-    rho = ( m_jetScale == EM ? 6000. : 12000.);
-    if ( eventShapeWarnings < 20 )
-      ATH_MSG_WARNING("Could not retrieve xAOD::EventShape from evtStore, using hard-coded value, rho = " << rho/m_GeV << " GeV.");
+    ATH_MSG_FATAL("Could not retrieve xAOD::EventShape from evtStore.");
+    return StatusCode::FAILURE;
   }
   jetEventInfo.setRho(rho);
   ATH_MSG_VERBOSE("  Rho = " << 0.001*rho << " GeV");
diff --git a/Reconstruction/Jet/JetCalibTools/cmt/requirements b/Reconstruction/Jet/JetCalibTools/cmt/requirements
index 603fdf3f4a7..80bb8c7bfce 100644
--- a/Reconstruction/Jet/JetCalibTools/cmt/requirements
+++ b/Reconstruction/Jet/JetCalibTools/cmt/requirements
@@ -17,16 +17,26 @@ use JetInterface        JetInterface-*          Reconstruction/Jet
 private
 use GaudiInterface	GaudiInterface-*        External
 use xAODMuon            xAODMuon-*              Event/xAOD
-use  PathResolver       PathResolver-*          Tools
+use PathResolver        PathResolver-*          Tools
+use xAODRootAccess      xAODRootAccess-*        Control
 end_private
 
-library JetCalibTools *.cxx ../Root/*.cxx -s=components *.cxx
-apply_pattern component_library
+#library JetCalibTools *.cxx ../Root/*.cxx -s=components *.cxx
+#apply_pattern component_library
 
-#apply_pattern dual_use_library files="*.cxx ../Root/*.cxx"
+apply_pattern dual_use_library files="*.cxx ../Root/*.cxx"
 
 apply_pattern declare_calib files="-s=../share *"
 
+private
 apply_pattern generic_declare_for_link files="../data/CalibrationConfigs/*.config" kind=calib prefix=share/JetCalibTools/CalibrationConfigs name=CalibrationConfigs
 apply_pattern generic_declare_for_link files="../data/CalibrationFactors/*.config ../data/CalibrationFactors/*.root" kind=calib prefix=share/JetCalibTools/CalibrationFactors name=CalibrationFactors
 apply_pattern generic_declare_for_link files="../data/InsituCalibration/*.root" kind=calib prefix=share/JetCalibTools/InsituCalibration name=InsituCalibration
+
+use_if tag=AthAnalysisBase pkg=POOLRootAccess ver=POOLRootAccess-* root=PhysicsAnalysis
+use_if tag=AthAnalysisBase pkg=StoreGate ver=StoreGate-* root=Control
+use_if tag=AthAnalysisBase pkg=xAODCore ver=xAODCore-* root=Event/xAOD
+
+application JetCalibTools_Example ../util/JetCalibTools_Example.cxx
+macro_append JetCalibTools_Example_dependencies " JetCalibToolsLib "
+end_private
\ No newline at end of file
diff --git a/Reconstruction/Jet/JetCalibTools/util/JetCalibTools_Example.cxx b/Reconstruction/Jet/JetCalibTools/util/JetCalibTools_Example.cxx
index 2e7a31376ac..a076834f999 100644
--- a/Reconstruction/Jet/JetCalibTools/util/JetCalibTools_Example.cxx
+++ b/Reconstruction/Jet/JetCalibTools/util/JetCalibTools_Example.cxx
@@ -12,9 +12,6 @@
  *  1 14/03/16  First Version              J. Bossio (jbossios@cern.ch) * 
 \************************************************************************/
 
-// This will only run in RootCore
-#ifdef ROOTCORE
-
 // System include(s):
 #include <memory>
 
@@ -24,13 +21,19 @@
 // ROOT
 #include "TFile.h"
 
+#ifdef XAOD_STANDALONE
+#include "xAODRootAccess/Init.h"
+#include "xAODRootAccess/TEvent.h"
+#include "xAODRootAccess/TStore.h"
+#else
+#include "POOLRootAccess/TEvent.h"
+#include "StoreGate/StoreGateSvc.h"
+#endif
+
 //xAOD EDM classes
 #include "xAODEventInfo/EventInfo.h"
 #include "xAODJet/JetContainer.h"
 #include "xAODEventShape/EventShape.h"
-#include "xAODRootAccess/Init.h"
-#include "xAODRootAccess/TEvent.h"
-#include "xAODRootAccess/TStore.h"
 #include "xAODRootAccess/tools/Message.h"
 #include "xAODRootAccess/tools/ReturnCheck.h"
 #include "xAODCore/tools/IOStats.h"
@@ -124,7 +127,6 @@ int main(int argc, char* argv[]){
 
   // Set up the job for xAOD access:
   static const char* APP_NAME = "JetCalibTools_Example";
-  RETURN_CHECK( APP_NAME, xAOD::Init() );
  
   //--------------------
   // Opening input file
@@ -132,12 +134,14 @@ int main(int argc, char* argv[]){
   std::unique_ptr< TFile > ifile( TFile::Open( sample.c_str(), "READ" ) );
 
   // Create a TEvent object.
+#ifdef XAOD_STANDALONE
+  RETURN_CHECK( APP_NAME, xAOD::Init() );
   xAOD::TEvent event( xAOD::TEvent::kClassAccess );
+#else // Athena "Store" is the same StoreGate used by the TEvent
+  POOL::TEvent event( POOL::TEvent::kClassAccess );
+#endif
   RETURN_CHECK( APP_NAME, event.readFrom( ifile.get() ) );
 
-  // Create a transient object store. Needed for the tools.
-  xAOD::TStore store;
-
   //----------------------------------
   // Initialization of JetCalibTools
   //----------------------------------
@@ -201,5 +205,3 @@ int main(int argc, char* argv[]){
 
   return 0;
 }
-
-#endif
-- 
GitLab