diff --git a/RecCalorimeter/src/components/CaloTopoCluster.cpp b/RecCalorimeter/src/components/CaloTopoCluster.cpp index aba82a1f..602c1b39 100644 --- a/RecCalorimeter/src/components/CaloTopoCluster.cpp +++ b/RecCalorimeter/src/components/CaloTopoCluster.cpp @@ -15,8 +15,10 @@ #include "DD4hep/Detector.h" #include "DD4hep/Readout.h" +#include #include #include +#include #include #include #include @@ -93,7 +95,7 @@ StatusCode CaloTopoCluster::execute() { // Create output collections auto edmClusters = m_clusterCollection.createAndPut(); - edm4hep::CalorimeterHitCollection* edmClusterCells = new edm4hep::CalorimeterHitCollection(); + std::unique_ptr edmClusterCells(new edm4hep::CalorimeterHitCollection()); // Finds seeds CaloTopoCluster::findingSeeds(allCells, m_seedSigma, firstSeeds); @@ -106,8 +108,16 @@ StatusCode CaloTopoCluster::execute() { }); std::map>> preClusterCollection; - CaloTopoCluster::buildingProtoCluster(m_neighbourSigma, m_lastNeighbourSigma, firstSeeds, allCells, - preClusterCollection); + StatusCode sc = CaloTopoCluster::buildingProtoCluster(m_neighbourSigma, + m_lastNeighbourSigma, + firstSeeds, + allCells, + preClusterCollection); + if (sc.isFailure()) { + error() << "Unable to build protocluster!" << endmsg; + return sc; + } + // Build Clusters in edm debug() << "Building " << preClusterCollection.size() << " cluster." << endmsg; double checkTotEnergy = 0.; @@ -202,7 +212,7 @@ StatusCode CaloTopoCluster::execute() { } - m_clusterCellsCollection.put(edmClusterCells); + m_clusterCellsCollection.put(std::move(edmClusterCells)); debug() << "Number of clusters with cells in E and HCal: " << clusterWithMixedCells << endmsg; debug() << "Total energy of clusters: " << checkTotEnergy << endmsg; debug() << "Leftover cells : " << allCells.size() << endmsg; diff --git a/RecCalorimeter/src/components/CorrectCaloClusters.cpp b/RecCalorimeter/src/components/CorrectCaloClusters.cpp index 2890ae70..fb24e5c9 100644 --- a/RecCalorimeter/src/components/CorrectCaloClusters.cpp +++ b/RecCalorimeter/src/components/CorrectCaloClusters.cpp @@ -37,9 +37,11 @@ CorrectCaloClusters::CorrectCaloClusters(const std::string& name, } StatusCode CorrectCaloClusters::initialize() { - StatusCode sc = GaudiAlgorithm::initialize(); - if (sc.isFailure()) { - return sc; + { + StatusCode sc = GaudiAlgorithm::initialize(); + if (sc.isFailure()) { + return sc; + } } // Check if readouts exist @@ -88,8 +90,20 @@ StatusCode CorrectCaloClusters::initialize() { } // Prepare upstream and downstream correction functions - initializeCorrFunctions(m_upstreamFunctions, m_upstreamFormulas, m_upstreamParams, "upstream"); - initializeCorrFunctions(m_downstreamFunctions, m_downstreamFormulas, m_downstreamParams, "downstream"); + { + StatusCode sc = initializeCorrFunctions(m_upstreamFunctions, m_upstreamFormulas, m_upstreamParams, "upstream"); + if (sc.isFailure()) { + error() << "Initialization of upstream correction functions not successful!" << endmsg; + return sc; + } + } + { + StatusCode sc = initializeCorrFunctions(m_downstreamFunctions, m_downstreamFormulas, m_downstreamParams, "downstream"); + if (sc.isFailure()) { + error() << "Initialization of downstream correction functions not successful!" << endmsg; + return sc; + } + } info() << "Initialized following upstream correction functions:" << endmsg; for (size_t i = 0; i < m_upstreamFunctions.size(); ++i) { @@ -307,8 +321,8 @@ StatusCode CorrectCaloClusters::applyDownstreamCorr(const edm4hep::ClusterCollec double CorrectCaloClusters::getEnergyInLayer(edm4hep::Cluster cluster, const std::string& readoutName, - size_t systemID, - size_t layerID) { + int systemID, + int layerID) { dd4hep::DDSegmentation::BitFieldCoder* decoder = m_geoSvc->getDetector()->readout(readoutName).idSpec().decoder(); double energy = 0; diff --git a/RecCalorimeter/src/components/CorrectCaloClusters.h b/RecCalorimeter/src/components/CorrectCaloClusters.h index 3f253380..c5a29d2d 100644 --- a/RecCalorimeter/src/components/CorrectCaloClusters.h +++ b/RecCalorimeter/src/components/CorrectCaloClusters.h @@ -115,8 +115,8 @@ class CorrectCaloClusters : public GaudiAlgorithm { */ double getEnergyInLayer(edm4hep::Cluster cluster, const std::string& readoutName, - size_t systemID, - size_t layerID); + int systemID, + int layerID); /** * Get the theta angle of the specified cluster. @@ -144,7 +144,7 @@ class CorrectCaloClusters : public GaudiAlgorithm { std::vector> m_downstreamFunctions; /// IDs of the detectors - Gaudi::Property> m_systemIDs { + Gaudi::Property> m_systemIDs { this, "systemIDs", {4}, "IDs of systems" }; /// Names of the detector readouts, corresponding to system IDs @@ -156,11 +156,11 @@ class CorrectCaloClusters : public GaudiAlgorithm { Gaudi::Property> m_numLayers { this, "numLayers", {12}, "Numbers of layers of the systems"}; /// IDs of the first layers of the detectors - Gaudi::Property> m_firstLayerIDs { + Gaudi::Property> m_firstLayerIDs { this, "firstLayerIDs", {0}, "IDs of first layers in the systems" }; /// IDs of the last layers of the detectors - Gaudi::Property> m_lastLayerIDs { + Gaudi::Property> m_lastLayerIDs { this, "lastLayerIDs", {7}, "IDs of last layers in the systems" }; diff --git a/RecCalorimeter/src/components/CorrectECalBarrelSliWinCluster.cpp b/RecCalorimeter/src/components/CorrectECalBarrelSliWinCluster.cpp index 1d0e9c43..66cb5c03 100644 --- a/RecCalorimeter/src/components/CorrectECalBarrelSliWinCluster.cpp +++ b/RecCalorimeter/src/components/CorrectECalBarrelSliWinCluster.cpp @@ -22,6 +22,7 @@ #include "TLorentzVector.h" #include "TFitResult.h" #include "TGraphErrors.h" +#include DECLARE_COMPONENT(CorrectECalBarrelSliWinCluster) @@ -40,8 +41,10 @@ CorrectECalBarrelSliWinCluster::CorrectECalBarrelSliWinCluster(const std::string } StatusCode CorrectECalBarrelSliWinCluster::initialize() { - StatusCode sc = GaudiAlgorithm::initialize(); - if (sc.isFailure()) return sc; + { + StatusCode sc = GaudiAlgorithm::initialize(); + if (sc.isFailure()) return sc; + } int energyStart = 0; int energyEnd = 0; @@ -159,7 +162,12 @@ StatusCode CorrectECalBarrelSliWinCluster::initialize() { error() << "Couldn't get RndmGenSvc!!!!" << endmsg; return StatusCode::FAILURE; } - m_gauss.initialize(m_randSvc, Rndm::Gauss(0., 1.)); + { + StatusCode sc = m_gauss.initialize(m_randSvc, Rndm::Gauss(0., 1.)); + if (sc.isFailure()) { + error() << "Unable to initialize gaussian random number generator!" << endmsg; + } + } // open and check file, read the histograms with noise constants if (initNoiseFromFile().isFailure()) { diff --git a/RecCalorimeter/src/components/MassInv.cpp b/RecCalorimeter/src/components/MassInv.cpp index a4f8ab2c..98974e5f 100644 --- a/RecCalorimeter/src/components/MassInv.cpp +++ b/RecCalorimeter/src/components/MassInv.cpp @@ -43,8 +43,10 @@ MassInv::MassInv(const std::string& name, ISvcLocator* svcLoc) } StatusCode MassInv::initialize() { - StatusCode sc = GaudiAlgorithm::initialize(); - if (sc.isFailure()) return sc; + { + StatusCode sc = GaudiAlgorithm::initialize(); + if (sc.isFailure()) return sc; + } int energyStart = 0; int energyEnd = 0; @@ -321,7 +323,12 @@ StatusCode MassInv::initialize() { error() << "Couldn't get RndmGenSvc!!!!" << endmsg; return StatusCode::FAILURE; } - m_gauss.initialize(m_randSvc, Rndm::Gauss(0., 1.)); + { + StatusCode sc = m_gauss.initialize(m_randSvc, Rndm::Gauss(0., 1.)); + if (sc.isFailure()) { + error() << "Failed to initialize Gaussian random number generator!" << endmsg; + } + } // open and check file, read the histograms with noise constants if (initNoiseFromFile().isFailure()) { @@ -385,14 +392,12 @@ StatusCode MassInv::execute() { double phiVertex = 0; double etaVertex = 0; double thetaVertex = 0; - double zVertex = 0; const auto particle = m_particle.get(); if (particle->size() == 1) { for(const auto& part : *particle) { momentum = TVector3(part.getMomentum().x, part.getMomentum().y, part.getMomentum().z); etaVertex = momentum.Eta(); phiVertex = momentum.Phi(); - zVertex = part.getVertex().z; thetaVertex = 2 * atan( exp( - etaVertex ) ); verbose() << " vertex eta " << etaVertex << " phi = " << phiVertex << " theta = " << thetaVertex << endmsg; } @@ -612,8 +617,8 @@ StatusCode MassInv::execute() { } debug() << "Number of ALL candidates: " << inClusters->size() << endmsg; - for (const auto candidate1: clustersMassInv) { - for (const auto candidate2: clustersMassInv) { + for (const auto& candidate1: clustersMassInv) { + for (const auto& candidate2: clustersMassInv) { if ( candidate1 != candidate2) { m_hMassInv->Fill((candidate1 + candidate2).Mag() * m_massInvCorrection); m_hDiPT->Fill((candidate1 + candidate2).Pt()); @@ -655,8 +660,8 @@ StatusCode MassInv::execute() { uint photonIdPhi = m_towerTool->idPhi(photonCandidate->Phi()); // LOOK AROUND double sumWindow = 0; - for (int iEtaWindow = photonIdEta - halfEtaWin; iEtaWindow <= photonIdEta + halfEtaWin; iEtaWindow++) { - for (int iPhiWindow = photonIdPhi - halfPhiWin; iPhiWindow <= photonIdPhi + halfPhiWin; iPhiWindow++) { + for (size_t iEtaWindow = photonIdEta - halfEtaWin; iEtaWindow <= photonIdEta + halfEtaWin; iEtaWindow++) { + for (size_t iPhiWindow = photonIdPhi - halfPhiWin; iPhiWindow <= photonIdPhi + halfPhiWin; iPhiWindow++) { sumWindow += m_towers[iEtaWindow][phiNeighbour(iPhiWindow, m_nPhiTower)]; } } @@ -671,8 +676,8 @@ StatusCode MassInv::execute() { uint photonIdPhi = m_towerTool->idPhi(photonCandidate->Phi()); // LOOK AROUND double sumWindow = 0; - for (int iEtaWindow = photonIdEta - halfEtaWin; iEtaWindow <= photonIdEta + halfEtaWin; iEtaWindow++) { - for (int iPhiWindow = photonIdPhi - halfPhiWin; iPhiWindow <= photonIdPhi + halfPhiWin; iPhiWindow++) { + for (size_t iEtaWindow = photonIdEta - halfEtaWin; iEtaWindow <= photonIdEta + halfEtaWin; iEtaWindow++) { + for (size_t iPhiWindow = photonIdPhi - halfPhiWin; iPhiWindow <= photonIdPhi + halfPhiWin; iPhiWindow++) { sumWindow += m_towers[iEtaWindow][phiNeighbour(iPhiWindow, m_nPhiTower)]; } } @@ -687,8 +692,8 @@ StatusCode MassInv::execute() { uint photonIdPhi = m_towerTool->idPhi(photonCandidate->Phi()); // LOOK AROUND double sumWindow = 0; - for (int iEtaWindow = photonIdEta - halfEtaWin; iEtaWindow <= photonIdEta + halfEtaWin; iEtaWindow++) { - for (int iPhiWindow = photonIdPhi - halfPhiWin; iPhiWindow <= photonIdPhi + halfPhiWin; iPhiWindow++) { + for (size_t iEtaWindow = photonIdEta - halfEtaWin; iEtaWindow <= photonIdEta + halfEtaWin; iEtaWindow++) { + for (size_t iPhiWindow = photonIdPhi - halfPhiWin; iPhiWindow <= photonIdPhi + halfPhiWin; iPhiWindow++) { sumWindow += m_towers[iEtaWindow][phiNeighbour(iPhiWindow, m_nPhiTower)]; } } @@ -703,8 +708,8 @@ StatusCode MassInv::execute() { uint photonIdPhi = m_towerTool->idPhi(photonCandidate->Phi()); // LOOK AROUND double sumWindow = 0; - for (int iEtaWindow = photonIdEta - halfEtaWin; iEtaWindow <= photonIdEta + halfEtaWin; iEtaWindow++) { - for (int iPhiWindow = photonIdPhi - halfPhiWin; iPhiWindow <= photonIdPhi + halfPhiWin; iPhiWindow++) { + for (size_t iEtaWindow = photonIdEta - halfEtaWin; iEtaWindow <= photonIdEta + halfEtaWin; iEtaWindow++) { + for (size_t iPhiWindow = photonIdPhi - halfPhiWin; iPhiWindow <= photonIdPhi + halfPhiWin; iPhiWindow++) { sumWindow += m_towers[iEtaWindow][phiNeighbour(iPhiWindow, m_nPhiTower)]; } } @@ -719,8 +724,8 @@ StatusCode MassInv::execute() { uint photonIdPhi = m_towerTool->idPhi(photonCandidate->Phi()); // LOOK AROUND double sumWindow = 0; - for (int iEtaWindow = photonIdEta - halfEtaWin; iEtaWindow <= photonIdEta + halfEtaWin; iEtaWindow++) { - for (int iPhiWindow = photonIdPhi - halfPhiWin; iPhiWindow <= photonIdPhi + halfPhiWin; iPhiWindow++) { + for (size_t iEtaWindow = photonIdEta - halfEtaWin; iEtaWindow <= photonIdEta + halfEtaWin; iEtaWindow++) { + for (size_t iPhiWindow = photonIdPhi - halfPhiWin; iPhiWindow <= photonIdPhi + halfPhiWin; iPhiWindow++) { sumWindow += m_towers[iEtaWindow][phiNeighbour(iPhiWindow, m_nPhiTower)]; } } diff --git a/RecCalorimeter/src/components/NoiseCaloCellsFlatTool.cpp b/RecCalorimeter/src/components/NoiseCaloCellsFlatTool.cpp index 1e7fea02..ea36f23a 100644 --- a/RecCalorimeter/src/components/NoiseCaloCellsFlatTool.cpp +++ b/RecCalorimeter/src/components/NoiseCaloCellsFlatTool.cpp @@ -1,4 +1,5 @@ #include "NoiseCaloCellsFlatTool.h" +#include DECLARE_COMPONENT(NoiseCaloCellsFlatTool) @@ -9,19 +10,26 @@ NoiseCaloCellsFlatTool::NoiseCaloCellsFlatTool(const std::string& type, const st } StatusCode NoiseCaloCellsFlatTool::initialize() { - StatusCode sc = GaudiTool::initialize(); - if (sc.isFailure()) return sc; + { + StatusCode sc = GaudiTool::initialize(); + if (sc.isFailure()) return sc; + } // Initialize random service if (service("RndmGenSvc", m_randSvc).isFailure()) { error() << "Couldn't get RndmGenSvc" << endmsg; return StatusCode::FAILURE; } - m_gauss.initialize(m_randSvc, Rndm::Gauss(0., 1.)); + { + StatusCode sc = m_gauss.initialize(m_randSvc, Rndm::Gauss(0., 1.)); + if (sc.isFailure()) { + error() << "Failed to initialize Gaussian random number generator!" << endmsg; + } + } info() << "Sigma of the cell noise: " << m_cellNoise * 1.e3 << " MeV" << endmsg; info() << "Filter noise threshold: " << m_filterThreshold << "*sigma" << endmsg; - return sc; + return StatusCode::SUCCESS; } void NoiseCaloCellsFlatTool::addRandomCellNoise(std::unordered_map& aCells) { diff --git a/RecCalorimeter/src/components/PreparePileup.cpp b/RecCalorimeter/src/components/PreparePileup.cpp index cdc40dfb..884c5dd0 100644 --- a/RecCalorimeter/src/components/PreparePileup.cpp +++ b/RecCalorimeter/src/components/PreparePileup.cpp @@ -176,8 +176,8 @@ StatusCode PreparePileup::execute() { m_energyVsAbsEta[layerId]->Fill(fabs(cellEta), cellEnergy); // add energy of this cell to any optimised cluster where it is included if (!(m_nEtaFinal.size() == 0 && m_nPhiFinal.size() == 0) ) { - uint etaId = m_decoder->get(cID, "eta"); - uint phiId = m_decoder->get(cID, "phi"); + int etaId = m_decoder->get(cID, "eta"); + int phiId = m_decoder->get(cID, "phi"); for (int iEta = etaId - m_halfEtaFin[layerId]; iEta < etaId + m_halfEtaFin[layerId] + 1; iEta++) { for (int iPhi = phiId - m_halfPhiFin[layerId]; iPhi < phiId + m_halfPhiFin[layerId] + 1; iPhi++) { if (iEta > 0 && iEta < m_nEtaTower ) { @@ -210,7 +210,7 @@ StatusCode PreparePileup::execute() { << endmsg; // calculate the sum of first m_nEtaWindow bins in eta, for each phi tower std::vector sumOverEta(m_nPhiTower, 0); - for (int iEta = 0; iEta < m_etaSizes[iCluster]; iEta++) { + for (size_t iEta = 0; iEta < m_etaSizes[iCluster]; iEta++) { std::transform(sumOverEta.begin(), sumOverEta.end(), m_towers[iEta].begin(), sumOverEta.begin(), std::plus()); } diff --git a/RecFCCeeCalorimeter/src/components/CaloTopoClusterFCCee.cpp b/RecFCCeeCalorimeter/src/components/CaloTopoClusterFCCee.cpp index 7e4669d5..ebeb9d8e 100644 --- a/RecFCCeeCalorimeter/src/components/CaloTopoClusterFCCee.cpp +++ b/RecFCCeeCalorimeter/src/components/CaloTopoClusterFCCee.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -104,7 +105,7 @@ StatusCode CaloTopoClusterFCCee::execute() { // Create output collections auto edmClusters = m_clusterCollection.createAndPut(); - edm4hep::CalorimeterHitCollection* edmClusterCells = new edm4hep::CalorimeterHitCollection(); + std::unique_ptr edmClusterCells(new edm4hep::CalorimeterHitCollection()); // Finds seeds CaloTopoClusterFCCee::findingSeeds(m_allCells, m_seedSigma, firstSeeds); @@ -117,10 +118,10 @@ StatusCode CaloTopoClusterFCCee::execute() { }); std::map>> preClusterCollection; - StatusCode sc_buildProtoClusters = CaloTopoClusterFCCee::buildingProtoCluster(m_neighbourSigma, - m_lastNeighbourSigma, - firstSeeds, m_allCells, - preClusterCollection); + StatusCode sc_buildProtoClusters = CaloTopoClusterFCCee::buildingProtoCluster(m_neighbourSigma, + m_lastNeighbourSigma, + firstSeeds, m_allCells, + preClusterCollection); if (sc_buildProtoClusters.isFailure()) { error() << "Unable to build the protoclusters!" << endmsg; return StatusCode::FAILURE; @@ -220,7 +221,7 @@ StatusCode CaloTopoClusterFCCee::execute() { } - m_clusterCellsCollection.put(edmClusterCells); + m_clusterCellsCollection.put(std::move(edmClusterCells)); debug() << "Number of clusters with cells in E and HCal: " << clusterWithMixedCells << endmsg; debug() << "Total energy of clusters: " << checkTotEnergy << endmsg; debug() << "Leftover cells : " << m_allCells.size() << endmsg;