diff --git a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/CalibrationNtupleMakerTool.cxx b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/CalibrationNtupleMakerTool.cxx index 2928274daaef5f4e2a33f4df8e9bfd3a21da6b8d..96e928ebf57988473d1a75561cbc1e3fc7d1a558 100644 --- a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/CalibrationNtupleMakerTool.cxx +++ b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/CalibrationNtupleMakerTool.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ @@ -42,21 +42,21 @@ CalibrationNtupleMakerTool::CalibrationNtupleMakerTool(const std::string& name, m_trueIsoPtCut(100.*GeV), m_matchingCut(0.6), m_h_events(nullptr), - m_index(0), - m_etaCalo(0), - m_etaDetCalo(0), - m_phiCalo(0), - m_eCalo(0), - m_mCalo(0), - m_etaCorr(0), - m_etaDetCorr(0), - m_phiCorr(0), - m_eCorr(0), - m_mCorr(0), - m_etaTrue(0), - m_phiTrue(0), - m_eTrue(0), - m_mTrue(0) + m_index(nullptr), + m_etaCalo(nullptr), + m_etaDetCalo(nullptr), + m_phiCalo(nullptr), + m_eCalo(nullptr), + m_mCalo(nullptr), + m_etaCorr(nullptr), + m_etaDetCorr(nullptr), + m_phiCorr(nullptr), + m_eCorr(nullptr), + m_mCorr(nullptr), + m_etaTrue(nullptr), + m_phiTrue(nullptr), + m_eTrue(nullptr), + m_mTrue(nullptr) { declareProperty("FolderName" , m_treeFolder); declareProperty("Description", m_treeDescription); @@ -130,14 +130,14 @@ StatusCode CalibrationNtupleMakerTool::bookTree() } // now register the Tree - ITHistSvc* tHistSvc = 0; + ITHistSvc* tHistSvc = nullptr; if (service("THistSvc",tHistSvc).isFailure()) { ATH_MSG_ERROR( "initialize() Could not find Hist Service!" ); return StatusCode::FAILURE; } if (tHistSvc) { - for (auto name : m_collectionNames) { + for (const auto& name : m_collectionNames) { if((tHistSvc->regTree(m_treeFolder+name, m_trees.at(name))).isFailure()) { ATH_MSG_ERROR( "initialize() Could not register the validation Tree!" ); return StatusCode::FAILURE; @@ -169,10 +169,10 @@ StatusCode CalibrationNtupleMakerTool::execute() } float ev_weight = evt->mcEventWeight(); - const auto truths = getContainer<xAOD::JetContainer>(m_truthJetContainerName); + const auto *const truths = getContainer<xAOD::JetContainer>(m_truthJetContainerName); if (not truths) return StatusCode::FAILURE; - const auto vertices = getContainer<xAOD::VertexContainer>(m_vertexContainerName); + const auto *const vertices = getContainer<xAOD::VertexContainer>(m_vertexContainerName); if (not vertices) return StatusCode::FAILURE; // get mu @@ -187,7 +187,7 @@ StatusCode CalibrationNtupleMakerTool::execute() } for (auto& name : m_collectionNames) { - const auto jets = getContainer<xAOD::JetContainer>(name); + const auto *const jets = getContainer<xAOD::JetContainer>(name); m_etaCalo ->clear(); m_etaDetCalo ->clear(); @@ -263,7 +263,7 @@ StatusCode CalibrationNtupleMakerTool::execute() } -int CalibrationNtupleMakerTool::Matched(const xAOD::Jet* truth, const xAOD::JetContainer* jets, std::vector<const xAOD::Jet*>& matched, int& index) { +int CalibrationNtupleMakerTool::Matched(const xAOD::Jet* truth, const xAOD::JetContainer* jets, std::vector<const xAOD::Jet*>& matched, int& index) const { int Nmatches = 0; double drmin = 999.; diff --git a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/CalibrationNtupleMakerTool.h b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/CalibrationNtupleMakerTool.h index 8fcc0509407140248058c837c838095b87331dec..ee8708d2f31f9dcbe6c49b97a8f9744e218c7cc8 100644 --- a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/CalibrationNtupleMakerTool.h +++ b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/CalibrationNtupleMakerTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TRACKCALOCLUSTERREC_TRACKCALOCLUSTERRECVALIDATION_CALIBRATIONNTUPLEMAKERTOOL_H #define TRACKCALOCLUSTERREC_TRACKCALOCLUSTERRECVALIDATION_CALIBRATIONNTUPLEMAKERTOOL_H @@ -42,9 +42,9 @@ private: // Get a data container; implementation at end of this header file template<class T> const T* getContainer( const std::string & containerName); - int Matched(const xAOD::Jet* truth, const xAOD::JetContainer* jets, std::vector<const xAOD::Jet*>& matched, int& index); + int Matched(const xAOD::Jet* truth, const xAOD::JetContainer* jets, std::vector<const xAOD::Jet*>& matched, int& index) const; - double DRmin(const xAOD::Jet* myjet, const xAOD::JetContainer* jets, double PtMin); + static double DRmin(const xAOD::Jet* myjet, const xAOD::JetContainer* jets, double PtMin); float DetectorEta(const xAOD::Jet* jet); @@ -66,9 +66,9 @@ private: TH1* m_h_events; - float m_eventWeight; - float m_mu; - float m_npv; + float m_eventWeight = 0.0F; + float m_mu = 0.0F; + float m_npv = 0.0F; std::vector < int >* m_index; diff --git a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlots.cxx b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlots.cxx index 9b6048d03bf9437565f8e5bfbb2df86c7388cef3..e797c866515fe8058ed9fec78aab8109f5e343d4 100644 --- a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlots.cxx +++ b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlots.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "GaudiKernel/SystemOfUnits.h" @@ -548,7 +548,7 @@ void TCCPlots::setTrackProdRadiusBinning(const std::vector<float>& bins) { void TCCPlots::initializePlots() { - if (m_collectionType!="") + if (!m_collectionType.empty()) std::cout << "INFO: TCCPlots configured for " << m_collectionType << " type collection" << std::endl; if (m_collectionType == "jets") { @@ -2175,7 +2175,7 @@ void TCCPlots::fillTCC(const xAOD::TrackCaloCluster& tcc, std::vector<const xAOD static SG::AuxElement::Accessor< float > acc_unc( "ClusterUnc" ); - if (tcc.caloClusterLinks().size()) { + if (!tcc.caloClusterLinks().empty()) { int N = tcc.caloClusterLinks().size(); // std::cout << "N = " << N << std::endl; for (size_t c = 0; c < tcc.caloClusterLinks().size(); ++c) { @@ -2204,7 +2204,7 @@ void TCCPlots::fillTCC(const xAOD::TrackCaloCluster& tcc, std::vector<const xAOD } void TCCPlots::finalizePlots() { - if (m_collectionType!= "") + if (!m_collectionType.empty()) std::cout << "Finalising " << m_collectionType << " in folder " << m_folder << std::endl; if (m_collectionType == "jets") { @@ -2539,7 +2539,7 @@ void TCCPlots::resizeHistograms() { if (m_collectionType == "tracks") { - if (m_trackPtBins.size()>0) { + if (!m_trackPtBins.empty()) { const float* ptBins = m_trackPtBins.data(); int nBins = m_trackPtBins.size()-1; @@ -2627,7 +2627,7 @@ void TCCPlots::resizeHistograms() { } - if (m_trackProdRadiusBins.size()>0) { + if (!m_trackProdRadiusBins.empty()) { const float* radiusBins = m_trackProdRadiusBins.data(); int nBins = m_trackProdRadiusBins.size()-1; @@ -2648,7 +2648,7 @@ void TCCPlots::resizeHistograms() { } } else if (m_collectionType == "jets") { - if (m_jetPtBins.size()>0) { + if (!m_jetPtBins.empty()) { float* ptBins = m_jetPtBins.data(); int nBins = m_jetPtBins.size()-1; @@ -2683,7 +2683,7 @@ void TCCPlots::resizeHistograms() { m_jet_resolution_add_d2_subleading ->GetXaxis()->Set(nBins, ptBins); } - if (m_jetPtBins.size()>0 and m_jetMassOverPtBins.size()>0) { + if (!m_jetPtBins.empty() and !m_jetMassOverPtBins.empty()) { float* ptBins = m_jetPtBins.data(); int nBinsPt = m_jetPtBins.size()-1; @@ -2783,7 +2783,7 @@ void TCCPlots::resizeHistograms() { m_jet_resolution_mopt_pt_d2_subleading ->GetYaxis()->Set(nBinsMassOverPt, massOverPtBins); } } else if (m_collectionType == "tccs") { - if (m_trackPtBins.size()>0) { + if (!m_trackPtBins.empty()) { float* ptBins = m_trackPtBins.data(); int nBins = m_trackPtBins.size()-1; diff --git a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlots.h b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlots.h index f5ca7981093fbb9c05f0871ce474c459b5b6ebe6..ea9a348e220bf99405beff7e4d7d7f4a9d1f0109 100644 --- a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlots.h +++ b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlots.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TRACKCALOCLUSTERREC_TRACKCALOCLUSTERRECVALIDATION_TCCPLOTS_H @@ -67,9 +67,9 @@ public: void fillTCCptCut(const xAOD::TrackCaloCluster& tcc); void fillTCCetaCut(const xAOD::TrackCaloCluster& tcc); - void make_median(TH2* h2_response, TH1* h1_resolution, TH1* h1_median=nullptr); - void make_median_add(TH2* h2_response, TH1* h1_resolution); - void make_median(TH3* h3_response, TH2* h2_resolution); + static void make_median(TH2* h2_response, TH1* h1_resolution, TH1* h1_median=nullptr); + static void make_median_add(TH2* h2_response, TH1* h1_resolution); + static void make_median(TH3* h3_response, TH2* h2_resolution); void setEventWeight(const float& weight); void setJetPtBinning(const std::vector<float>& bins); diff --git a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlotsBase.cxx b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlotsBase.cxx index e56f44817d0f3fea8e04e389f4df710a2325c02f..911040b032a314768c25609b3d0b0f019ad8e6a8 100644 --- a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlotsBase.cxx +++ b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlotsBase.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "TCCPlotsBase.h" @@ -33,7 +33,7 @@ namespace { } } -TCCPlotsBase::TCCPlotsBase(PlotBase* pParent, std::string folder): +TCCPlotsBase::TCCPlotsBase(PlotBase* pParent, const std::string& folder): PlotBase(pParent, folder), m_folder(folder), m_histoDefSvc(nullptr) {} diff --git a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlotsBase.h b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlotsBase.h index d968a4379ce07f3305de5e112a9999703707d48d..938c3ec29c0e69715b5b9ee6eb4530923e7f7bf7 100644 --- a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlotsBase.h +++ b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TCCPlotsBase.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TRACKCALOCLUSTERREC_TRACKCALOCLUSTERRECVALIDATION_TCCPLOTSBASE_H @@ -14,7 +14,7 @@ class SingleHistogramDefinition; class TCCPlotsBase:public PlotBase { public: - TCCPlotsBase(PlotBase* pParent, std::string folder); + TCCPlotsBase(PlotBase* pParent, const std::string& folder); /// Retrieve a single histogram definition, given the unique string identifier SingleHistogramDefinition retrieveDefinition(const std::string& histoIdentifier, @@ -36,12 +36,12 @@ class TCCPlotsBase:public PlotBase { void book(TH3*& pHisto, const std::string& histoIdentifier, const std::string& folder = "default"); // - void fillHisto(TH1* pTh1, const float value); - void fillHisto(TH1* pTh1, const float value, const float weight); - void fillHisto(TH2* pTh2, const float xval, const float yval); - void fillHisto(TH2* pTh2, const float xval, const float yval, const float weight); - void fillHisto(TH3* pTh3, const float xval, const float yval, const float zval); - void fillHisto(TH3* pTh3, const float xval, const float yval, const float zval, const float weight); + static void fillHisto(TH1* pTh1, const float value); + static void fillHisto(TH1* pTh1, const float value, const float weight); + static void fillHisto(TH2* pTh2, const float xval, const float yval); + static void fillHisto(TH2* pTh2, const float xval, const float yval, const float weight); + static void fillHisto(TH3* pTh3, const float xval, const float yval, const float zval); + static void fillHisto(TH3* pTh3, const float xval, const float yval, const float zval, const float weight); std::string m_folder; diff --git a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TrackCaloClusterRecValidationTool.cxx b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TrackCaloClusterRecValidationTool.cxx index c02172aaac2d4244bcdcefd034d1cd986a082d61..2975c46f963974861aa649275eba1ad751de5a20 100644 --- a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TrackCaloClusterRecValidationTool.cxx +++ b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TrackCaloClusterRecValidationTool.cxx @@ -1,394 +1,422 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "TrackCaloClusterRecValidationTool.h" // #include "GaudiKernel/SystemOfUnits.h" -#include "xAODTruth/TruthParticle.h" #include "xAODJet/JetContainer.h" +#include "xAODTruth/TruthParticle.h" #include "xAODCaloEvent/CaloClusterContainer.h" #include "xAODCore/ShallowCopy.h" -#include "xAODParticleEvent/IParticleLink.h" #include "xAODPFlow/TrackCaloClusterContainer.h" +#include "xAODParticleEvent/IParticleLink.h" #include "JetCalibTools/JetCalibrationTool.h" #include "TCCPlots.h" // #include <algorithm> +#include <cmath> // to get std::isnan(), std::abs etc. +#include <cstdlib> // to getenv #include <limits> -#include <cmath> // to get std::isnan(), std::abs etc. #include <utility> -#include <cstdlib> // to getenv #include <vector> -///Parametrized constructor -TrackCaloClusterRecValidationTool::TrackCaloClusterRecValidationTool(const std::string& type, const std::string& name, - const IInterface* parent) : - ManagedMonitorToolBase(type, name, parent), - m_jetCalibrationTools() - { - declareProperty("JetCalibrationTools" , m_jetCalibrationTools); - declareProperty("ApplyCalibration" , m_applyCalibration = false); - declareProperty("CollectionsToCalibrate" , m_jetCalibrationCollections); - declareProperty("SaveJetInfo" , m_saveJetInfo = true); - declareProperty("JetTruthContainerName" , m_truthJetContainerName); +/// Parametrized constructor +TrackCaloClusterRecValidationTool::TrackCaloClusterRecValidationTool(const std::string& type, + const std::string& name, + const IInterface* parent) + : ManagedMonitorToolBase(type, name, parent) + , m_jetCalibrationTools() +{ + declareProperty("JetCalibrationTools", m_jetCalibrationTools); + declareProperty("ApplyCalibration", m_applyCalibration = false); + declareProperty("CollectionsToCalibrate", m_jetCalibrationCollections); + declareProperty("SaveJetInfo", m_saveJetInfo = true); + declareProperty("JetTruthContainerName", m_truthJetContainerName); declareProperty("JetTruthTrimmedContainerName", m_truthTrimmedJetContainerName); - declareProperty("JetContainerNames" , m_jetContainerNames); - declareProperty("PrimaryVertexContainerName" , m_vertexContainerName = "PrimaryVertices"); - declareProperty("TopoJetReferenceName" , m_topoJetReferenceName = "AntiKt10LCTopoJets"); - declareProperty("TopoTrimmedJetReferenceName" , m_topoTrimmedJetReferenceName = "AntiKt10LCTopoTrimmedJets"); - declareProperty("maxTrkJetDR" , m_maxJetDR = 0.75); - declareProperty("maxEta" , m_maxEta = 2.0); - declareProperty("minPt" , m_minPt = 200*Gaudi::Units::GeV); - declareProperty("minMass" , m_minMass = 50.*Gaudi::Units::GeV); - declareProperty("maxMass" , m_maxMass = 150.*Gaudi::Units::GeV); - declareProperty("DirName" , m_dirName = "TCCValidation/"); - declareProperty("SubFolder" , m_folder); - declareProperty("SaveTrackInfo" , m_saveTrackInfo = false); - declareProperty("SaveMatchingInfo" , m_saveMatchingInfo = false); - declareProperty("TrackCollectionName" , m_trackParticleCollectionName = "InDetTrackParticles"); - declareProperty("TrackPtMin" , m_trackPtMin = 20.*Gaudi::Units::GeV); - declareProperty("JetPtBins" , m_jetPtBins ); - declareProperty("JetMassOverPtBins" , m_jetMassOverPtBins ); - declareProperty("TrackPtBins" , m_trackPtBins ); - declareProperty("TrackProdRadiusBins" , m_trackProdRadiusBins ); - declareProperty("SaveClusterInfo" , m_saveClusterInfo = false); - declareProperty("ClusterCollectionName" , m_caloClusterCollectionName = "TimedCaloCalTopoClusters"); - declareProperty("ClusterEtaMax" , m_caloClusterEtaMax = 2.5); - declareProperty("SaveTrackCaloClusterInfo" , m_saveTCCInfo = false); - declareProperty("TCCCombinedCollectionNames" , m_TCCCombinedCollectionNames); - declareProperty("TCCptMin" , m_tccPtMin = 10.*Gaudi::Units::GeV); - declareProperty("TCCetaMax" , m_tccEtaMax = 2.5); - - } - -TrackCaloClusterRecValidationTool::~TrackCaloClusterRecValidationTool() { + declareProperty("JetContainerNames", m_jetContainerNames); + declareProperty("PrimaryVertexContainerName", m_vertexContainerName = "PrimaryVertices"); + declareProperty("TopoJetReferenceName", m_topoJetReferenceName = "AntiKt10LCTopoJets"); + declareProperty("TopoTrimmedJetReferenceName", m_topoTrimmedJetReferenceName = "AntiKt10LCTopoTrimmedJets"); + declareProperty("maxTrkJetDR", m_maxJetDR = 0.75); + declareProperty("maxEta", m_maxEta = 2.0); + declareProperty("minPt", m_minPt = 200 * Gaudi::Units::GeV); + declareProperty("minMass", m_minMass = 50. * Gaudi::Units::GeV); + declareProperty("maxMass", m_maxMass = 150. * Gaudi::Units::GeV); + declareProperty("DirName", m_dirName = "TCCValidation/"); + declareProperty("SubFolder", m_folder); + declareProperty("SaveTrackInfo", m_saveTrackInfo = false); + declareProperty("SaveMatchingInfo", m_saveMatchingInfo = false); + declareProperty("TrackCollectionName", m_trackParticleCollectionName = "InDetTrackParticles"); + declareProperty("TrackPtMin", m_trackPtMin = 20. * Gaudi::Units::GeV); + declareProperty("JetPtBins", m_jetPtBins); + declareProperty("JetMassOverPtBins", m_jetMassOverPtBins); + declareProperty("TrackPtBins", m_trackPtBins); + declareProperty("TrackProdRadiusBins", m_trackProdRadiusBins); + declareProperty("SaveClusterInfo", m_saveClusterInfo = false); + declareProperty("ClusterCollectionName", m_caloClusterCollectionName = "TimedCaloCalTopoClusters"); + declareProperty("ClusterEtaMax", m_caloClusterEtaMax = 2.5); + declareProperty("SaveTrackCaloClusterInfo", m_saveTCCInfo = false); + declareProperty("TCCCombinedCollectionNames", m_TCCCombinedCollectionNames); + declareProperty("TCCptMin", m_tccPtMin = 10. * Gaudi::Units::GeV); + declareProperty("TCCetaMax", m_tccEtaMax = 2.5); } +TrackCaloClusterRecValidationTool::~TrackCaloClusterRecValidationTool() {} + StatusCode -TrackCaloClusterRecValidationTool::initialize() { +TrackCaloClusterRecValidationTool::initialize() +{ ATH_MSG_DEBUG("Initializing " << name() << "..."); ATH_CHECK(ManagedMonitorToolBase::initialize()); - + // retrieve the jet calibration tool if (m_applyCalibration) { if (m_jetCalibrationCollections.size() != m_jetCalibrationTools.size()) { - ATH_MSG_WARNING("Number of collections to calibrate differs from the number of calibration tools... switching off calibration!"); - m_applyCalibration=false; + ATH_MSG_WARNING("Number of collections to calibrate differs from the number of calibration tools... switching " + "off calibration!"); + m_applyCalibration = false; } - CHECK( m_jetCalibrationTools.retrieve() ); + CHECK(m_jetCalibrationTools.retrieve()); } - + if (m_saveJetInfo) { - for (auto name : m_jetContainerNames) { + for (const auto& name : m_jetContainerNames) { ATH_MSG_INFO("Saving Plots for " << name << "..."); std::string myname = name; - if (name.find("AntiKt10LCTopo")!= std::string::npos and name.find("My")== std::string::npos) - myname = "My"+name; - + if (name.find("AntiKt10LCTopo") != std::string::npos and name.find("My") == std::string::npos) + myname = "My" + name; + if (name == "AntiKt10TrackCaloClustersChargedJets") - myname = "AntiKt10TrackCaloClustersCombinedJets"; + myname = "AntiKt10TrackCaloClustersCombinedJets"; if (name == "AntiKt10TrackCaloClustersChargedTrimmedJets") - myname = "AntiKt10TrackCaloClustersCombinedTrimmedJets"; - - m_tccPlots.insert(std::pair<std::string, TCCPlots*>(name, new TCCPlots(0, m_dirName + myname, "jets"))); + myname = "AntiKt10TrackCaloClustersCombinedTrimmedJets"; + + m_tccPlots.insert(std::pair<std::string, TCCPlots*>(name, new TCCPlots(nullptr, m_dirName + myname, "jets"))); m_tccPlots.at(name)->setJetPtBinning(m_jetPtBins); m_tccPlots.at(name)->setJetMassOverPtBinning(m_jetMassOverPtBins); } } - + if (m_saveTrackInfo) { - ATH_MSG_INFO("Saving Plots for " << m_trackParticleCollectionName << "..."); - m_tccPlots.insert(std::pair<std::string, TCCPlots*>(m_trackParticleCollectionName, new TCCPlots(0, m_dirName + m_trackParticleCollectionName, "tracks"))); + ATH_MSG_INFO("Saving Plots for " << m_trackParticleCollectionName << "..."); + m_tccPlots.insert(std::pair<std::string, TCCPlots*>( + m_trackParticleCollectionName, new TCCPlots(nullptr, m_dirName + m_trackParticleCollectionName, "tracks"))); m_tccPlots.at(m_trackParticleCollectionName)->setTrackPtBinning(m_trackPtBins); m_tccPlots.at(m_trackParticleCollectionName)->setTrackProdRadiusBinning(m_trackProdRadiusBins); } - + if (m_saveClusterInfo) { ATH_MSG_INFO("Saving Plots for " << m_caloClusterCollectionName << "..."); - m_tccPlots.insert(std::pair<std::string, TCCPlots*>(m_caloClusterCollectionName, new TCCPlots(0, m_dirName + m_caloClusterCollectionName, "clusters"))); + m_tccPlots.insert(std::pair<std::string, TCCPlots*>( + m_caloClusterCollectionName, new TCCPlots(nullptr, m_dirName + m_caloClusterCollectionName, "clusters"))); } - + if (m_saveTCCInfo) { - for (auto name : m_TCCCombinedCollectionNames) { + for (const auto& name : m_TCCCombinedCollectionNames) { ATH_MSG_INFO("Saving Plots for " << name << "..."); - m_tccPlots.insert(std::pair<std::string, TCCPlots*>(name, new TCCPlots(0, m_dirName + name, "tccs"))); + m_tccPlots.insert(std::pair<std::string, TCCPlots*>(name, new TCCPlots(nullptr, m_dirName + name, "tccs"))); m_tccPlots.at(name)->setTrackPtBinning(m_trackPtBins); } } - - ATH_CHECK( m_evt.initialize() ); + + ATH_CHECK(m_evt.initialize()); return StatusCode::SUCCESS; } StatusCode -TrackCaloClusterRecValidationTool::fillHistograms() { +TrackCaloClusterRecValidationTool::fillHistograms() +{ SG::ReadHandle<xAOD::EventInfo> evt(m_evt); - if(!evt.isValid()) { - ATH_MSG_FATAL( "Unable to retrieve Event Info" ); - } + if (!evt.isValid()) { + ATH_MSG_FATAL("Unable to retrieve Event Info"); + } float mcEventWeight = evt->mcEventWeight(); - + if (m_saveJetInfo) { ATH_MSG_DEBUG("Filling hists " << name() << "..."); - - const auto vertices = getContainer<xAOD::VertexContainer>(m_vertexContainerName); - + + const auto *const vertices = getContainer<xAOD::VertexContainer>(m_vertexContainerName); + // retrieve jet container - for (auto name : m_jetContainerNames) { - + for (const auto& name : m_jetContainerNames) { + m_tccPlots.at(name)->setEventWeight(mcEventWeight); ATH_MSG_DEBUG("Using Container " << name << "..."); ATH_MSG_DEBUG("-- weight = " << mcEventWeight << "..."); - - const auto jets_beforeCalib = getContainer<xAOD::JetContainer>(name); - if (not jets_beforeCalib) return StatusCode::FAILURE; - + + const auto *const jets_beforeCalib = getContainer<xAOD::JetContainer>(name); + if (not jets_beforeCalib) { + return StatusCode::FAILURE; + } + const xAOD::JetContainer* jets = jets_beforeCalib; - - if (m_applyCalibration and std::find(m_jetCalibrationCollections.begin(), m_jetCalibrationCollections.end(), name)!=m_jetCalibrationCollections.end()) { - /** Calibrate and record a shallow copy of the jet container */ - jets = calibrateAndRecordShallowCopyJetCollection(jets_beforeCalib, name); - if(!jets){ - ATH_MSG_WARNING( "Unable to create calibrated jet shallow copy container" ); - return StatusCode::SUCCESS; - } + + if (m_applyCalibration and + std::find(m_jetCalibrationCollections.begin(), m_jetCalibrationCollections.end(), name) != + m_jetCalibrationCollections.end()) { + /** Calibrate and record a shallow copy of the jet container */ + jets = calibrateAndRecordShallowCopyJetCollection(jets_beforeCalib, name); + if (!jets) { + ATH_MSG_WARNING("Unable to create calibrated jet shallow copy container"); + return StatusCode::SUCCESS; + } } - + // Getting the collections for the pseudo response - const auto caloclusters = (name.find("Trimmed")== std::string::npos) ? - getContainer<xAOD::JetContainer>(m_topoJetReferenceName) : - getContainer<xAOD::JetContainer>(m_topoTrimmedJetReferenceName); - const auto truths = (name.find("Trimmed")== std::string::npos) ? - getContainer<xAOD::JetContainer>(m_truthJetContainerName) : - getContainer<xAOD::JetContainer>(m_truthTrimmedJetContainerName); - - if (not truths) return StatusCode::FAILURE; - - if (not caloclusters) return StatusCode::FAILURE; - + const auto *const caloclusters = (name.find("Trimmed") == std::string::npos) + ? getContainer<xAOD::JetContainer>(m_topoJetReferenceName) + : getContainer<xAOD::JetContainer>(m_topoTrimmedJetReferenceName); + const auto *const truths = (name.find("Trimmed") == std::string::npos) + ? getContainer<xAOD::JetContainer>(m_truthJetContainerName) + : getContainer<xAOD::JetContainer>(m_truthTrimmedJetContainerName); + + if (not truths) { + return StatusCode::FAILURE; + } + + if (not caloclusters) { + return StatusCode::FAILURE; + } + m_tccPlots.at(name)->fill(*jets); - - for (const auto& jet: *jets) { - // conditions to be satisfied to select jets - if (fabs(jet->eta())>m_maxEta) continue; - - // get the truth matched - const xAOD::Jet* truth_matched_nocuts = ClusterMatched(jet,truths); - // if truth_matched exists, fill the response w/o pt and mass cuts - if (truth_matched_nocuts) - m_tccPlots.at(name)->fillResponseNoPtNoMassCuts(*jet,*truth_matched_nocuts); - - if (fabs(jet->pt())<m_minPt) continue; - - // fill all jets histograms - m_tccPlots.at(name)->fill(*jet); - m_tccPlots.at(name)->fillMoments(*jet); - - // fill all jets histograms + truth - for (const auto& truth: *truths) - m_tccPlots.at(name)->fill(*jet,*truth); - - // get the truth matched - const xAOD::Jet* truth_matched = ClusterMatched(jet,truths); - - // apply mass requirement on the truth jet once you have matched - if (not truth_matched or (truth_matched->m()<m_minMass or truth_matched->m()>m_maxMass)) - continue; - - // if truth_matched exists, fill the jet histograms + truth matched - m_tccPlots.at(name)->fillResponse(*jet,*truth_matched); - m_tccPlots.at(name)->fillMomentsWithMassCut(*jet); - - if (vertices) - m_tccPlots.at(name)->fillResponseNPV(*jet,*truth_matched,vertices->size()); - - // get the calo matched - const xAOD::Jet* calo_matched = ClusterMatched(jet,caloclusters); - // if calo_matched exists, fill the jet histograms + calo matched - if (calo_matched) - m_tccPlots.at(name)->fillPseudoResponse(*jet,*calo_matched); + + for (const auto& jet : *jets) { + // conditions to be satisfied to select jets + if (fabs(jet->eta()) > m_maxEta) + continue; + + // get the truth matched + const xAOD::Jet* truth_matched_nocuts = ClusterMatched(jet, truths); + // if truth_matched exists, fill the response w/o pt and mass cuts + if (truth_matched_nocuts) + m_tccPlots.at(name)->fillResponseNoPtNoMassCuts(*jet, *truth_matched_nocuts); + + if (fabs(jet->pt()) < m_minPt) + continue; + + // fill all jets histograms + m_tccPlots.at(name)->fill(*jet); + m_tccPlots.at(name)->fillMoments(*jet); + + // fill all jets histograms + truth + for (const auto& truth : *truths) + m_tccPlots.at(name)->fill(*jet, *truth); + + // get the truth matched + const xAOD::Jet* truth_matched = ClusterMatched(jet, truths); + + // apply mass requirement on the truth jet once you have matched + if (not truth_matched or (truth_matched->m() < m_minMass or truth_matched->m() > m_maxMass)) { + continue; + } + + // if truth_matched exists, fill the jet histograms + truth matched + m_tccPlots.at(name)->fillResponse(*jet, *truth_matched); + m_tccPlots.at(name)->fillMomentsWithMassCut(*jet); + + if (vertices) { + m_tccPlots.at(name)->fillResponseNPV(*jet, *truth_matched, vertices->size()); + } + + // get the calo matched + const xAOD::Jet* calo_matched = ClusterMatched(jet, caloclusters); + // if calo_matched exists, fill the jet histograms + calo matched + if (calo_matched) { + m_tccPlots.at(name)->fillPseudoResponse(*jet, *calo_matched); + } } - - + ATH_MSG_DEBUG("All jets histograms filled! ..."); - + // evaluate the leadings in mass of the leadings is pt - std::vector<const xAOD::Jet*> leadings = {nullptr, nullptr}; - std::vector<const xAOD::Jet*> leadings_nocuts = {nullptr, nullptr}; - + std::vector<const xAOD::Jet*> leadings = { nullptr, nullptr }; + std::vector<const xAOD::Jet*> leadings_nocuts = { nullptr, nullptr }; + std::vector<const xAOD::Jet*> tmp_leadings; - if (jets->size()>0) - tmp_leadings.push_back(jets->at(0)); - if (jets->size()>1) - tmp_leadings.push_back(jets->at(1)); - - if (tmp_leadings.size()>1 and tmp_leadings.at(0)->m()<tmp_leadings.at(1)->m()) std::swap(tmp_leadings.at(0), tmp_leadings.at(1)); - + if (!jets->empty()) { + tmp_leadings.push_back(jets->at(0)); + } + if (jets->size() > 1) { + tmp_leadings.push_back(jets->at(1)); + } + + if (tmp_leadings.size() > 1 and tmp_leadings.at(0)->m() < tmp_leadings.at(1)->m()) { + std::swap(tmp_leadings.at(0), tmp_leadings.at(1)); + } + // fill the leadings jets if they satisfy the eta requirement - if (tmp_leadings.size()>0 - and fabs(tmp_leadings.at(0)->eta())<m_maxEta) - leadings_nocuts.at(0) = tmp_leadings.at(0); - - if (tmp_leadings.size()>1 - and fabs(tmp_leadings.at(1)->eta())<m_maxEta) - leadings_nocuts.at(1) = tmp_leadings.at(1); - - std::vector<const xAOD::Jet*> truth_matches_nocuts = {nullptr, nullptr}; + if (!tmp_leadings.empty() and fabs(tmp_leadings.at(0)->eta()) < m_maxEta) { + leadings_nocuts.at(0) = tmp_leadings.at(0); + } + + if (tmp_leadings.size() > 1 and fabs(tmp_leadings.at(1)->eta()) < m_maxEta) { + leadings_nocuts.at(1) = tmp_leadings.at(1); + } + + std::vector<const xAOD::Jet*> truth_matches_nocuts = { nullptr, nullptr }; unsigned int pos = 0; - for (const auto& jet: leadings_nocuts) { - pos++; - if (not jet) continue; - const xAOD::Jet* truth_matched_nocuts = ClusterMatched(jet,truths); - if (truth_matched_nocuts) - truth_matches_nocuts.at(pos-1) = truth_matched_nocuts; + for (const auto& jet : leadings_nocuts) { + pos++; + if (not jet) + continue; + const xAOD::Jet* truth_matched_nocuts = ClusterMatched(jet, truths); + if (truth_matched_nocuts) + truth_matches_nocuts.at(pos - 1) = truth_matched_nocuts; } - + if (leadings_nocuts.at(0)) { - ATH_MSG_DEBUG(" ---> fillLeading w/o cuts ..."); - if (truth_matches_nocuts.at(0)) - m_tccPlots.at(name)->fillResponseNoPtNoMassCutsLeading(*leadings_nocuts.at(0),*truth_matches_nocuts.at(0)); - ATH_MSG_DEBUG("Leading jet w/o cuts histograms filled! ..."); - } - - if (leadings_nocuts.at(1)) { - ATH_MSG_DEBUG(" ---> fillSubLeading w/o cuts ..."); - if (truth_matches_nocuts.at(1)) - m_tccPlots.at(name)->fillResponseNoPtNoMassCutsSubLeading(*leadings_nocuts.at(1),*truth_matches_nocuts.at(1)); - ATH_MSG_DEBUG("SubLeading jet w/o cuts histograms filled! ..."); - } - + ATH_MSG_DEBUG(" ---> fillLeading w/o cuts ..."); + if (truth_matches_nocuts.at(0)) + m_tccPlots.at(name)->fillResponseNoPtNoMassCutsLeading(*leadings_nocuts.at(0), *truth_matches_nocuts.at(0)); + ATH_MSG_DEBUG("Leading jet w/o cuts histograms filled! ..."); + } + + if (leadings_nocuts.at(1)) { + ATH_MSG_DEBUG(" ---> fillSubLeading w/o cuts ..."); + if (truth_matches_nocuts.at(1)) + m_tccPlots.at(name)->fillResponseNoPtNoMassCutsSubLeading(*leadings_nocuts.at(1), + *truth_matches_nocuts.at(1)); + ATH_MSG_DEBUG("SubLeading jet w/o cuts histograms filled! ..."); + } + // fill the leadings jets if they satisfy the eta and pt requirements - if (tmp_leadings.size()>0 - and fabs(tmp_leadings.at(0)->eta())<m_maxEta - and tmp_leadings.at(0)->pt()>m_minPt) - leadings.at(0) = tmp_leadings.at(0); - - if (tmp_leadings.size()>1 - and fabs(tmp_leadings.at(1)->eta())<m_maxEta - and tmp_leadings.at(1)->pt()>m_minPt) - leadings.at(1) = tmp_leadings.at(1); - + if (!tmp_leadings.empty() and fabs(tmp_leadings.at(0)->eta()) < m_maxEta and tmp_leadings.at(0)->pt() > m_minPt) + leadings.at(0) = tmp_leadings.at(0); + + if (tmp_leadings.size() > 1 and fabs(tmp_leadings.at(1)->eta()) < m_maxEta and tmp_leadings.at(1)->pt() > m_minPt) + leadings.at(1) = tmp_leadings.at(1); + if (leadings.at(0)) { - m_tccPlots.at(name)->fillLeading(*leadings.at(0)); - m_tccPlots.at(name)->fillMomentsLeading(*leadings.at(0)); + m_tccPlots.at(name)->fillLeading(*leadings.at(0)); + m_tccPlots.at(name)->fillMomentsLeading(*leadings.at(0)); } - + if (leadings.at(1)) { - m_tccPlots.at(name)->fillSubLeading(*leadings.at(1)); - m_tccPlots.at(name)->fillMomentsSubLeading(*leadings.at(1)); + m_tccPlots.at(name)->fillSubLeading(*leadings.at(1)); + m_tccPlots.at(name)->fillMomentsSubLeading(*leadings.at(1)); } - - std::vector<const xAOD::Jet*> truth_matches = {nullptr, nullptr}; - std::vector<const xAOD::Jet*> calo_matches = {nullptr, nullptr}; + + std::vector<const xAOD::Jet*> truth_matches = { nullptr, nullptr }; + std::vector<const xAOD::Jet*> calo_matches = { nullptr, nullptr }; pos = 0; - for (const auto& jet: leadings) { - pos++; - if (not jet) continue; - const xAOD::Jet* truth_matched = ClusterMatched(jet,truths); - if (truth_matched) - truth_matches.at(pos-1) = truth_matched; - const xAOD::Jet* calo_matched = ClusterMatched(jet,caloclusters); - if (calo_matched) - calo_matches.at(pos-1) = calo_matched; + for (const auto& jet : leadings) { + pos++; + if (not jet) + continue; + const xAOD::Jet* truth_matched = ClusterMatched(jet, truths); + if (truth_matched) + truth_matches.at(pos - 1) = truth_matched; + const xAOD::Jet* calo_matched = ClusterMatched(jet, caloclusters); + if (calo_matched) + calo_matches.at(pos - 1) = calo_matched; } - + if (leadings.at(0)) { - ATH_MSG_DEBUG(" ---> fillLeading ..."); - if (truth_matches.at(0) and (truth_matches.at(0)->m()>m_minMass and truth_matches.at(0)->m()<m_maxMass)) { - m_tccPlots.at(name)->fillMomentsLeadingWithMassCut(*leadings.at(0)); - m_tccPlots.at(name)->fillResponseLeading(*leadings.at(0),*truth_matches.at(0)); - if (vertices) - m_tccPlots.at(name)->fillResponseLeadingNPV(*leadings.at(0),*truth_matches.at(0),vertices->size()); - if (calo_matches.at(0)) - m_tccPlots.at(name)->fillPseudoResponseLeading(*leadings.at(0),*calo_matches.at(0)); - } - ATH_MSG_DEBUG("Leading jet histograms filled! ..."); + ATH_MSG_DEBUG(" ---> fillLeading ..."); + if (truth_matches.at(0) and (truth_matches.at(0)->m() > m_minMass and truth_matches.at(0)->m() < m_maxMass)) { + m_tccPlots.at(name)->fillMomentsLeadingWithMassCut(*leadings.at(0)); + m_tccPlots.at(name)->fillResponseLeading(*leadings.at(0), *truth_matches.at(0)); + if (vertices) + m_tccPlots.at(name)->fillResponseLeadingNPV(*leadings.at(0), *truth_matches.at(0), vertices->size()); + if (calo_matches.at(0)) + m_tccPlots.at(name)->fillPseudoResponseLeading(*leadings.at(0), *calo_matches.at(0)); + } + ATH_MSG_DEBUG("Leading jet histograms filled! ..."); } - + if (leadings.at(1)) { - ATH_MSG_DEBUG(" ---> fillSubLeading ..."); - if (truth_matches.at(1) and (truth_matches.at(1)->m()>m_minMass and truth_matches.at(1)->m()<m_maxMass)) { - m_tccPlots.at(name)->fillMomentsSubLeadingWithMassCut(*leadings.at(1)); - m_tccPlots.at(name)->fillResponseSubLeading(*leadings.at(1),*truth_matches.at(1)); - if (vertices) - m_tccPlots.at(name)->fillResponseSubLeadingNPV(*leadings.at(1),*truth_matches.at(1),vertices->size()); - if (calo_matches.at(1)) - m_tccPlots.at(name)->fillPseudoResponseSubLeading(*leadings.at(1),*calo_matches.at(1)); - } - ATH_MSG_DEBUG("SubLeading jet histograms filled! ..."); - } + ATH_MSG_DEBUG(" ---> fillSubLeading ..."); + if (truth_matches.at(1) and (truth_matches.at(1)->m() > m_minMass and truth_matches.at(1)->m() < m_maxMass)) { + m_tccPlots.at(name)->fillMomentsSubLeadingWithMassCut(*leadings.at(1)); + m_tccPlots.at(name)->fillResponseSubLeading(*leadings.at(1), *truth_matches.at(1)); + if (vertices) + m_tccPlots.at(name)->fillResponseSubLeadingNPV(*leadings.at(1), *truth_matches.at(1), vertices->size()); + if (calo_matches.at(1)) + m_tccPlots.at(name)->fillPseudoResponseSubLeading(*leadings.at(1), *calo_matches.at(1)); + } + ATH_MSG_DEBUG("SubLeading jet histograms filled! ..."); + } } } - + // Getting the collections for TrackParticles if (m_saveTrackInfo) { - const auto tracks = getContainer<xAOD::TrackParticleContainer>(m_trackParticleCollectionName); - if (not tracks) return StatusCode::FAILURE; - for (const auto& track: *tracks) { + const auto *const tracks = getContainer<xAOD::TrackParticleContainer>(m_trackParticleCollectionName); + if (not tracks) + return StatusCode::FAILURE; + for (const auto& track : *tracks) { if (m_saveMatchingInfo) - m_tccPlots.at(m_trackParticleCollectionName)->fillMatching(*track); + m_tccPlots.at(m_trackParticleCollectionName)->fillMatching(*track); m_tccPlots.at(m_trackParticleCollectionName)->fillTrackParametersAllPt(*track); m_tccPlots.at(m_trackParticleCollectionName)->fillCaloEntryInfoAllPt(*track); m_tccPlots.at(m_trackParticleCollectionName)->fillPerigeeInfoAllPt(*track); m_tccPlots.at(m_trackParticleCollectionName)->fillPerigeeVsCaloEntryAllPt(*track); - if (track->pt()<m_trackPtMin) continue; + if (track->pt() < m_trackPtMin) + continue; m_tccPlots.at(m_trackParticleCollectionName)->fillTrackParameters(*track); m_tccPlots.at(m_trackParticleCollectionName)->fillCaloEntryInfo(*track); m_tccPlots.at(m_trackParticleCollectionName)->fillPerigeeInfo(*track); m_tccPlots.at(m_trackParticleCollectionName)->fillPerigeeVsCaloEntry(*track); - } + } } - + // Getting the collections for the CaloClusters if (m_saveClusterInfo) { - const auto clusters = getContainer<xAOD::CaloClusterContainer>(m_caloClusterCollectionName); - if (not clusters) return StatusCode::FAILURE; - for (const auto& cluster: *clusters) { - m_tccPlots.at(m_caloClusterCollectionName)->fillCluster(*cluster); - if (fabs(cluster->eta())<m_caloClusterEtaMax) - m_tccPlots.at(m_caloClusterCollectionName)->fillClusterEtaCut(*cluster); - } + const auto *const clusters = getContainer<xAOD::CaloClusterContainer>(m_caloClusterCollectionName); + if (not clusters) + return StatusCode::FAILURE; + for (const auto& cluster : *clusters) { + m_tccPlots.at(m_caloClusterCollectionName)->fillCluster(*cluster); + if (fabs(cluster->eta()) < m_caloClusterEtaMax) + m_tccPlots.at(m_caloClusterCollectionName)->fillClusterEtaCut(*cluster); + } } - + // Getting the collections for the TrackCaloClusters if (m_saveTCCInfo) { - for (auto name : m_TCCCombinedCollectionNames) { - const auto tccs = getContainer<xAOD::TrackCaloClusterContainer>(name); - if (not tccs) return StatusCode::FAILURE; + for (const auto& name : m_TCCCombinedCollectionNames) { + const auto *const tccs = getContainer<xAOD::TrackCaloClusterContainer>(name); + if (not tccs) + return StatusCode::FAILURE; // fill the map with all the tracks creating tcc (means from PV0) std::vector<const xAOD::TrackParticle*> allpv0tracks; - for (const auto& tcc: *tccs) { - allpv0tracks.push_back(*tcc->trackParticleLink()); + for (const auto& tcc : *tccs) { + allpv0tracks.push_back(*tcc->trackParticleLink()); } - - for (const auto& tcc: *tccs) { - m_tccPlots.at(name)->fillTCC(*tcc, allpv0tracks); - if (tcc->pt()>m_tccPtMin) - m_tccPlots.at(name)->fillTCCptCut(*tcc); - if (fabs(tcc->eta())<m_tccEtaMax) - m_tccPlots.at(name)->fillTCCetaCut(*tcc); + + for (const auto& tcc : *tccs) { + m_tccPlots.at(name)->fillTCC(*tcc, allpv0tracks); + if (tcc->pt() > m_tccPtMin) + m_tccPlots.at(name)->fillTCCptCut(*tcc); + if (fabs(tcc->eta()) < m_tccEtaMax) + m_tccPlots.at(name)->fillTCCetaCut(*tcc); } - } + } } - + return StatusCode::SUCCESS; } -const xAOD::Jet* TrackCaloClusterRecValidationTool::ClusterMatched(const xAOD::Jet* jet, const xAOD::JetContainer* jets) { +const xAOD::Jet* +TrackCaloClusterRecValidationTool::ClusterMatched(const xAOD::Jet* jet, const xAOD::JetContainer* jets) +{ std::vector<const xAOD::Jet*> myjets = {}; - for (const auto& tomatch: *jets) myjets.push_back(tomatch); + for (const auto& tomatch : *jets) + myjets.push_back(tomatch); return ClusterMatched(jet, myjets); } -const xAOD::Jet* TrackCaloClusterRecValidationTool::ClusterMatched(const xAOD::Jet* jet, std::vector<const xAOD::Jet*> jets) { +const xAOD::Jet* +TrackCaloClusterRecValidationTool::ClusterMatched(const xAOD::Jet* jet, const std::vector<const xAOD::Jet*>& jets) const +{ double minDeltaR = m_maxJetDR; - const xAOD::Jet* matched = 0; - for (const auto& tomatch: jets) { + const xAOD::Jet* matched = nullptr; + for (const auto& tomatch : jets) { if (jet->p4().DeltaR(tomatch->p4()) < minDeltaR) { minDeltaR = jet->p4().DeltaR(tomatch->p4()); matched = tomatch; @@ -398,72 +426,80 @@ const xAOD::Jet* TrackCaloClusterRecValidationTool::ClusterMatched(const xAOD::J } StatusCode -TrackCaloClusterRecValidationTool::bookHistograms() { +TrackCaloClusterRecValidationTool::bookHistograms() +{ ATH_MSG_INFO("Booking hists " << name() << "..."); for (auto& plots : m_tccPlots) { plots.second->setDetailLevel(100); // DEBUG, enable expert histograms plots.second->initialize(); std::vector<HistData> hists = plots.second->retrieveBookedHistograms(); - for (auto hist : hists) { - ATH_CHECK(regHist(hist.first, hist.second, all)); + for (const auto& hist : hists) { + ATH_CHECK(regHist(hist.first, hist.second, all)); } } - + return StatusCode::SUCCESS; } StatusCode -TrackCaloClusterRecValidationTool::procHistograms() { +TrackCaloClusterRecValidationTool::procHistograms() +{ ATH_MSG_INFO("Finalising hists " << name() << "..."); - + if (endOfRunFlag()) { - for (auto& plots : m_tccPlots) + for (auto& plots : m_tccPlots) plots.second->finalize(); } - + ATH_MSG_INFO("Successfully finalized hists"); return StatusCode::SUCCESS; } /**Calibrate and record a shallow copy of a given jet container */ -const xAOD::JetContainer* TrackCaloClusterRecValidationTool::calibrateAndRecordShallowCopyJetCollection(const xAOD::JetContainer * jetContainer, const std::string name) { - +const xAOD::JetContainer* +TrackCaloClusterRecValidationTool::calibrateAndRecordShallowCopyJetCollection(const xAOD::JetContainer* jetContainer, + const std::string& name) +{ + // create a shallow copy of the jet container - std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > shallowCopy = xAOD::shallowCopyContainer(*jetContainer); - xAOD::JetContainer *jetContainerShallowCopy = shallowCopy.first; - xAOD::ShallowAuxContainer *jetAuxContainerShallowCopy = shallowCopy.second; - - if( evtStore()->record(jetContainerShallowCopy, name+"_Calib").isFailure() ){ - ATH_MSG_WARNING("Unable to record JetCalibratedContainer: " << name+"_Calib"); - return 0; + std::pair<xAOD::JetContainer*, xAOD::ShallowAuxContainer*> shallowCopy = xAOD::shallowCopyContainer(*jetContainer); + xAOD::JetContainer* jetContainerShallowCopy = shallowCopy.first; + xAOD::ShallowAuxContainer* jetAuxContainerShallowCopy = shallowCopy.second; + + if (evtStore()->record(jetContainerShallowCopy, name + "_Calib").isFailure()) { + ATH_MSG_WARNING("Unable to record JetCalibratedContainer: " << name + "_Calib"); + return nullptr; } - if( evtStore()->record(jetAuxContainerShallowCopy, name+"_Calib"+"Aux.").isFailure() ){ - ATH_MSG_WARNING("Unable to record JetCalibratedAuxContainer: " << name+"_Calib"+"Aux."); - return 0; + if (evtStore()->record(jetAuxContainerShallowCopy, name + "_Calib" + "Aux.").isFailure()) { + ATH_MSG_WARNING("Unable to record JetCalibratedAuxContainer: " << name + "_Calib" + "Aux."); + return nullptr; } - - static SG::AuxElement::Accessor< xAOD::IParticleLink > accSetOriginLink ("originalObjectLink"); - static SG::AuxElement::Decorator< float > decJvt("JvtUpdate"); - - int pos = std::find(m_jetCalibrationCollections.begin(), m_jetCalibrationCollections.end(), name) - m_jetCalibrationCollections.begin(); - if( m_jetCalibrationTools[pos]->applyCalibration(*jetContainerShallowCopy).isFailure() ){ - ATH_MSG_WARNING( "Failed to apply calibration to the jet container"); - return 0; + + static SG::AuxElement::Accessor<xAOD::IParticleLink> accSetOriginLink("originalObjectLink"); + static SG::AuxElement::Decorator<float> decJvt("JvtUpdate"); + + int pos = std::find(m_jetCalibrationCollections.begin(), m_jetCalibrationCollections.end(), name) - + m_jetCalibrationCollections.begin(); + if (m_jetCalibrationTools[pos]->applyCalibration(*jetContainerShallowCopy).isFailure()) { + ATH_MSG_WARNING("Failed to apply calibration to the jet container"); + return nullptr; } - for ( xAOD::Jet *shallowCopyJet : * jetContainerShallowCopy ) { - const xAOD::IParticleLink originLink( *jetContainer, shallowCopyJet->index() ); + for (xAOD::Jet* shallowCopyJet : *jetContainerShallowCopy) { + const xAOD::IParticleLink originLink(*jetContainer, shallowCopyJet->index()); accSetOriginLink(*shallowCopyJet) = originLink; } - if( evtStore()->setConst(jetContainerShallowCopy ).isFailure() ){ - ATH_MSG_WARNING( "Failed to set jetcalibCollection (" << name+"_Calib"+"Aux." << ")const in StoreGate!"); - return 0; + if (evtStore()->setConst(jetContainerShallowCopy).isFailure()) { + ATH_MSG_WARNING("Failed to set jetcalibCollection (" << name + "_Calib" + "Aux." + << ")const in StoreGate!"); + return nullptr; } - if( evtStore()->setConst(jetAuxContainerShallowCopy ).isFailure() ){ - ATH_MSG_WARNING( "Failed to set jetcalibCollection (" << name+"_Calib"+"Aux." << ")const in StoreGate!"); - return 0; + if (evtStore()->setConst(jetAuxContainerShallowCopy).isFailure()) { + ATH_MSG_WARNING("Failed to set jetcalibCollection (" << name + "_Calib" + "Aux." + << ")const in StoreGate!"); + return nullptr; } - - return jetContainerShallowCopy; + + return jetContainerShallowCopy; } diff --git a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TrackCaloClusterRecValidationTool.h b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TrackCaloClusterRecValidationTool.h index 1d4ef2d27e04d9c9fda1dd6e7ee6c98e69773904..7f43f53507e1fec7f7df8bc5efbc2932f064a299 100644 --- a/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TrackCaloClusterRecValidationTool.h +++ b/Reconstruction/TrackCaloClusterRec/TrackCaloClusterRecValidation/src/TrackCaloClusterRecValidationTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TRACKCALOCLUSTERREC_TRACKCALOCLUSTERRECVALIDATION_TRACKCALOCLUSTERRECVALIDATIONTOOL_H #define TRACKCALOCLUSTERREC_TRACKCALOCLUSTERRECVALIDATION_TRACKCALOCLUSTERRECVALIDATIONTOOL_H @@ -57,11 +57,11 @@ private: bool m_applyCalibration; /**Calibrate and record a shallow copy of a given jet container */ - const xAOD::JetContainer* calibrateAndRecordShallowCopyJetCollection(const xAOD::JetContainer * jetContainer, const std::string name); + const xAOD::JetContainer* calibrateAndRecordShallowCopyJetCollection(const xAOD::JetContainer * jetContainer, const std::string& name); /// Get the matched jet const xAOD::Jet* ClusterMatched(const xAOD::Jet* jet, const xAOD::JetContainer* jets); - const xAOD::Jet* ClusterMatched(const xAOD::Jet* jet, std::vector<const xAOD::Jet*> jets); + const xAOD::Jet* ClusterMatched(const xAOD::Jet* jet, const std::vector<const xAOD::Jet*>& jets) const; // Get a data container; implementation at end of this header file template<class T> const T* getContainer( const std::string & containerName);