From bfaa94ae9dcc6295495ee0270f466667fca1ddd6 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Thu, 7 Nov 2024 15:03:00 +0100 Subject: [PATCH 1/8] SurfaceArrayCreator --- .../Acts/Geometry/SurfaceArrayCreator.hpp | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp b/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp index bc52d700c72..fd91a26a66b 100644 --- a/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp +++ b/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp @@ -130,23 +130,7 @@ class SurfaceArrayCreator { std::size_t binsZ, std::optional protoLayerOpt = std::nullopt, const Transform3& transform = Transform3::Identity()) const; - /// SurfaceArrayCreator interface method - /// - /// - create an array in a cylinder, binned in phi, z when extremas and bin - /// numbers are unknown - this method goes through the surfaces and finds out - /// the needed information - /// @warning This function requires the cylinder aligned with the z-axis - /// @param surfaces is the vector of pointers to sensitive surfaces - /// to be ordered on the cylinder - /// @pre the pointers to the sensitive surfaces in the surfaces vectors all - /// need to be valid, since no check is performed - /// @param [in] gctx The gometry context for this building call - /// @param protoLayerOpt The proto layer containing the layer size - /// @param bTypePhi the binning type in phi direction (equidistant/arbitrary) - /// @param bTypeZ the binning type in z direction (equidistant/arbitrary) - /// @param transform is the (optional) additional transform applied - /// - /// @return a unique pointer a new SurfaceArray + /// SurfaceArrayCreator interface methonew SurfaceArray std::unique_ptr surfaceArrayOnCylinder( const GeometryContext& gctx, std::vector> surfaces, @@ -380,8 +364,8 @@ class SurfaceArrayCreator { Axis axisB(pAxisB.min, pAxisB.max, pAxisB.nBins); using SGL = SurfaceArray::SurfaceGridLookup; - ptr = std::unique_ptr(static_cast( - new SGL(globalToLocal, localToGlobal, std::make_tuple(axisA, axisB), {pAxisA.bValue, pAxisB.bValue}))); + ptr = std::make_unique( + globalToLocal, localToGlobal, std::pair{axisA, axisB}, std::vector{pAxisA.bValue, pAxisB.bValue}); } else if (pAxisA.bType == equidistant && pAxisB.bType == arbitrary) { @@ -389,8 +373,8 @@ class SurfaceArrayCreator { Axis axisB(pAxisB.binEdges); using SGL = SurfaceArray::SurfaceGridLookup; - ptr = std::unique_ptr(static_cast( - new SGL(globalToLocal, localToGlobal, std::make_tuple(axisA, axisB), {pAxisA.bValue, pAxisB.bValue}))); + ptr = std::make_unique( + globalToLocal, localToGlobal, std::pair{axisA, axisB}, std::vector{pAxisA.bValue, pAxisB.bValue}); } else if (pAxisA.bType == arbitrary && pAxisB.bType == equidistant) { @@ -398,8 +382,8 @@ class SurfaceArrayCreator { Axis axisB(pAxisB.min, pAxisB.max, pAxisB.nBins); using SGL = SurfaceArray::SurfaceGridLookup; - ptr = std::unique_ptr(static_cast( - new SGL(globalToLocal, localToGlobal, std::make_tuple(axisA, axisB), {pAxisA.bValue, pAxisB.bValue}))); + ptr = std::make_unique( + globalToLocal, localToGlobal, std::pair{axisA, axisB}, std::vector{pAxisA.bValue, pAxisB.bValue}); } else /*if (pAxisA.bType == arbitrary && pAxisB.bType == arbitrary)*/ { @@ -407,8 +391,8 @@ class SurfaceArrayCreator { Axis axisB(pAxisB.binEdges); using SGL = SurfaceArray::SurfaceGridLookup; - ptr = std::unique_ptr(static_cast( - new SGL(globalToLocal, localToGlobal, std::make_tuple(axisA, axisB), {pAxisA.bValue, pAxisB.bValue}))); + ptr = std::make_unique( + globalToLocal, localToGlobal, std::pair{axisA, axisB}, std::vector{pAxisA.bValue, pAxisB.bValue}); } // clang-format on From 61cb843346ac51bd7acd886d8182dc923473bcd5 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Thu, 7 Nov 2024 15:08:28 +0100 Subject: [PATCH 2/8] GBTS --- Core/include/Acts/Seeding/GbtsDataStorage.hpp | 54 +++++++------------ Core/include/Acts/Seeding/GbtsGeometry.hpp | 37 ++++--------- Core/include/Acts/Seeding/SeedFinderGbts.ipp | 28 ++++------ .../Acts/TrackFinding/GbtsConnector.hpp | 7 +-- Core/src/TrackFinding/GbtsConnector.cpp | 18 ++----- 5 files changed, 47 insertions(+), 97 deletions(-) diff --git a/Core/include/Acts/Seeding/GbtsDataStorage.hpp b/Core/include/Acts/Seeding/GbtsDataStorage.hpp index 64ba0bff1b9..ac56778d6f5 100644 --- a/Core/include/Acts/Seeding/GbtsDataStorage.hpp +++ b/Core/include/Acts/Seeding/GbtsDataStorage.hpp @@ -46,13 +46,6 @@ struct GbtsSP { template class GbtsNode { public: - struct CompareByPhi { - bool operator()(const GbtsNode *n1, - const GbtsNode *n2) { - return (n1->m_spGbts.phi() < n2->m_spGbts.phi()); - } - }; - GbtsNode(const GbtsSP &spGbts, float minT = -100.0, float maxT = 100.0) : m_spGbts(spGbts), m_minCutOnTau(minT), m_maxCutOnTau(maxT) {} @@ -96,27 +89,20 @@ class GbtsEtaBin { public: GbtsEtaBin() { m_vn.clear(); } - ~GbtsEtaBin() { - for (typename std::vector *>::iterator it = - m_vn.begin(); - it != m_vn.end(); ++it) { - delete (*it); - } - } - void sortByPhi() { - std::ranges::sort(m_vn, - typename Acts::GbtsNode::CompareByPhi()); + std::ranges::sort(m_vn, [](const auto &n1, const auto &n2) { + return (n1->m_spGbts.phi() < n2->m_spGbts.phi()); + }); } bool empty() const { return m_vn.empty(); } void generatePhiIndexing(float dphi) { for (unsigned int nIdx = 0; nIdx < m_vn.size(); nIdx++) { - GbtsNode *pN = m_vn.at(nIdx); + GbtsNode &pN = *m_vn.at(nIdx); // float phi = pN->m_sp.phi(); // float phi = (std::atan(pN->m_sp.x() / pN->m_sp.y())); - float phi = pN->m_spGbts.phi(); + float phi = pN.m_spGbts.phi(); if (phi <= M_PI - dphi) { continue; } @@ -126,14 +112,14 @@ class GbtsEtaBin { } for (unsigned int nIdx = 0; nIdx < m_vn.size(); nIdx++) { - GbtsNode *pN = m_vn.at(nIdx); - float phi = pN->m_spGbts.phi(); + GbtsNode &pN = *m_vn.at(nIdx); + float phi = pN.m_spGbts.phi(); m_vPhiNodes.push_back(std::pair(phi, nIdx)); } for (unsigned int nIdx = 0; nIdx < m_vn.size(); nIdx++) { - GbtsNode *pN = m_vn.at(nIdx); - float phi = pN->m_spGbts.phi(); + GbtsNode &pN = *m_vn.at(nIdx); + float phi = pN.m_spGbts.phi(); if (phi >= -M_PI + dphi) { break; } @@ -142,9 +128,7 @@ class GbtsEtaBin { } } - std::vector *> m_vn; - // TODO change to - // std::vector>> m_vn; + std::vector>> m_vn; std::vector> m_vPhiNodes; }; @@ -185,8 +169,9 @@ class GbtsDataStorage { 1.6 + 0.15 / (cluster_width + 0.2) + 6.1 * (cluster_width - 0.2); } - m_etaBins.at(binIndex).m_vn.push_back(new GbtsNode( - sp, min_tau, max_tau)); // adding ftf member to nodes + m_etaBins.at(binIndex).m_vn.push_back( + std::make_unique>( + sp, min_tau, max_tau)); // adding ftf member to nodes } else { if (useClusterWidth) { float cluster_width = 1; // temporary while cluster width not available @@ -194,7 +179,8 @@ class GbtsDataStorage { return -3; } } - m_etaBins.at(binIndex).m_vn.push_back(new GbtsNode(sp)); + m_etaBins.at(binIndex).m_vn.push_back( + std::make_unique>(sp)); } return 0; @@ -217,16 +203,14 @@ class GbtsDataStorage { vn.clear(); vn.reserve(numberOfNodes()); for (const auto &b : m_etaBins) { - for (typename std::vector *>::const_iterator nIt = - b.m_vn.begin(); - nIt != b.m_vn.end(); ++nIt) { - if ((*nIt)->m_in.empty()) { + for (const auto &n : b.m_vn) { + if (n->m_in.empty()) { continue; } - if ((*nIt)->m_out.empty()) { + if (n->m_out.empty()) { continue; } - vn.push_back(*nIt); + vn.push_back(n.get()); } } } diff --git a/Core/include/Acts/Seeding/GbtsGeometry.hpp b/Core/include/Acts/Seeding/GbtsGeometry.hpp index 54931b200b8..36d20cc3b62 100644 --- a/Core/include/Acts/Seeding/GbtsGeometry.hpp +++ b/Core/include/Acts/Seeding/GbtsGeometry.hpp @@ -277,15 +277,10 @@ class GbtsGeometry { // calculating bin tables in the connector... - for (std::map>::const_iterator it = - m_connector->m_connMap.begin(); - it != m_connector->m_connMap.end(); ++it) { - const std::vector &vConn = (*it).second; - - for (std::vector::const_iterator cIt = vConn.begin(); - cIt != vConn.end(); ++cIt) { - unsigned int src = (*cIt)->m_src; // n2 : the new connectors - unsigned int dst = (*cIt)->m_dst; // n1 + for (auto &[_, vConn] : m_connector->m_connMap) { + for (auto &c : vConn) { + unsigned int src = c->m_src; // n2 : the new connectors + unsigned int dst = c->m_dst; // n1 const GbtsLayer *pL1 = getGbtsLayerByKey(dst); const GbtsLayer *pL2 = getGbtsLayerByKey(src); @@ -301,7 +296,7 @@ class GbtsGeometry { int nSrcBins = pL2->m_bins.size(); int nDstBins = pL1->m_bins.size(); - (*cIt)->m_binTable.resize(nSrcBins * nDstBins, 0); + c->m_binTable.resize(nSrcBins * nDstBins, 0); for (int b1 = 0; b1 < nDstBins; b1++) { // loop over bins in Layer 1 for (int b2 = 0; b2 < nSrcBins; b2++) { // loop over bins in Layer 2 @@ -309,7 +304,7 @@ class GbtsGeometry { continue; } int address = b1 + b2 * nDstBins; - (*cIt)->m_binTable.at(address) = 1; + c->m_binTable.at(address) = 1; } } } @@ -322,17 +317,6 @@ class GbtsGeometry { GbtsGeometry(const GbtsGeometry &) = delete; GbtsGeometry &operator=(const GbtsGeometry &) = delete; - ~GbtsGeometry() { - for (typename std::vector *>::iterator it = - m_layArray.begin(); - it != m_layArray.end(); ++it) { - delete (*it); - } - - m_layMap.clear(); - m_layArray.clear(); - } - const GbtsLayer *getGbtsLayerByKey(unsigned int key) const { typename std::map *>::const_iterator it = m_layMap.find(key); @@ -344,7 +328,7 @@ class GbtsGeometry { } const GbtsLayer *getGbtsLayerByIndex(int idx) const { - return m_layArray.at(idx); + return m_layArray.at(idx).get(); } int num_bins() const { return m_nEtaBins; } @@ -357,18 +341,19 @@ class GbtsGeometry { unsigned int layerKey = l.m_subdet; // this should be combined ID float ew = m_etaBinWidth; - GbtsLayer *pHL = new GbtsLayer(l, ew, bin0); + auto upHL = std::make_unique>(l, ew, bin0); + auto *pHL = upHL.get(); m_layMap.insert( std::pair *>(layerKey, pHL)); - m_layArray.push_back(pHL); + m_layArray.push_back(std::move(upHL)); return pHL; } float m_etaBinWidth{}; std::map *> m_layMap; - std::vector *> m_layArray; + std::vector>> m_layArray; int m_nEtaBins{0}; diff --git a/Core/include/Acts/Seeding/SeedFinderGbts.ipp b/Core/include/Acts/Seeding/SeedFinderGbts.ipp index ab557d86977..1a3e0422782 100644 --- a/Core/include/Acts/Seeding/SeedFinderGbts.ipp +++ b/Core/include/Acts/Seeding/SeedFinderGbts.ipp @@ -160,12 +160,7 @@ void SeedFinderGbts::runGbts_TrackFinder( } unsigned int first_it = 0; - for (typename std::vector< - GbtsNode*>::const_iterator n1It = - B1.m_vn.begin(); - n1It != B1.m_vn.end(); ++n1It) { // loop over nodes in Layer 1 - - GbtsNode* n1 = (*n1It); + for (const auto& n1 : B1.m_vn) { // loop over nodes in Layer 1 if (n1->m_in.size() >= MAX_SEG_PER_NODE) { continue; @@ -195,7 +190,7 @@ void SeedFinderGbts::runGbts_TrackFinder( } GbtsNode* n2 = - B2.m_vn.at(B2.m_vPhiNodes.at(n2PhiIdx).second); + B2.m_vn.at(B2.m_vPhiNodes.at(n2PhiIdx).second).get(); if (n2->m_out.size() >= MAX_SEG_PER_NODE) { continue; @@ -304,8 +299,8 @@ void SeedFinderGbts::runGbts_TrackFinder( float dPhi1 = std::asin(curv * r1); if (nEdges < m_config.MaxEdges) { - edgeStorage.emplace_back(n1, n2, exp_eta, curv, phi1 + dPhi1, - phi2 + dPhi2); + edgeStorage.emplace_back(n1.get(), n2, exp_eta, curv, + phi1 + dPhi1, phi2 + dPhi2); n1->addIn(nEdges); n2->addOut(nEdges); @@ -332,21 +327,20 @@ void SeedFinderGbts::runGbts_TrackFinder( int nNodes = vNodes.size(); for (int nodeIdx = 0; nodeIdx < nNodes; nodeIdx++) { - const GbtsNode* pN = vNodes.at(nodeIdx); + const GbtsNode& pN = *vNodes.at(nodeIdx); std::vector> in_sort, out_sort; - in_sort.resize(pN->m_in.size()); - out_sort.resize(pN->m_out.size()); + in_sort.resize(pN.m_in.size()); + out_sort.resize(pN.m_out.size()); - for (int inIdx = 0; inIdx < static_cast(pN->m_in.size()); inIdx++) { - int inEdgeIdx = pN->m_in.at(inIdx); + for (int inIdx = 0; inIdx < static_cast(pN.m_in.size()); inIdx++) { + int inEdgeIdx = pN.m_in.at(inIdx); Acts::GbtsEdge* pS = &(edgeStorage.at(inEdgeIdx)); in_sort[inIdx].second = inEdgeIdx; in_sort[inIdx].first = pS->m_p[0]; } - for (int outIdx = 0; outIdx < static_cast(pN->m_out.size()); - outIdx++) { - int outEdgeIdx = pN->m_out.at(outIdx); + for (int outIdx = 0; outIdx < static_cast(pN.m_out.size()); outIdx++) { + int outEdgeIdx = pN.m_out.at(outIdx); Acts::GbtsEdge* pS = &(edgeStorage.at(outEdgeIdx)); out_sort[outIdx].second = outEdgeIdx; out_sort[outIdx].first = pS->m_p[0]; diff --git a/Core/include/Acts/TrackFinding/GbtsConnector.hpp b/Core/include/Acts/TrackFinding/GbtsConnector.hpp index f4cddd2527b..f368f876b94 100644 --- a/Core/include/Acts/TrackFinding/GbtsConnector.hpp +++ b/Core/include/Acts/TrackFinding/GbtsConnector.hpp @@ -39,15 +39,10 @@ class GbtsConnector { GbtsConnector(std::ifstream &inFile); - ~GbtsConnector(); - float m_etaBin{}; std::map> m_layerGroups; - std::map> m_connMap; - // TODO: change to std::map > - // m_connMap; or std::map> > m_connMap; + std::map>> m_connMap; }; } // namespace Acts diff --git a/Core/src/TrackFinding/GbtsConnector.cpp b/Core/src/TrackFinding/GbtsConnector.cpp index d947894871c..ff6945849ce 100644 --- a/Core/src/TrackFinding/GbtsConnector.cpp +++ b/Core/src/TrackFinding/GbtsConnector.cpp @@ -34,7 +34,7 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) { inFile >> lIdx >> stage >> src >> dst >> height >> width >> nEntries; - GbtsConnection *pC = new GbtsConnection(src, dst); + auto pC = std::make_unique(src, dst); int dummy{}; @@ -47,19 +47,17 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) { int vol_id = src / 1000; if (vol_id == 13 || vol_id == 12 || vol_id == 14) { - delete pC; continue; } vol_id = dst / 1000; if (vol_id == 13 || vol_id == 12 || vol_id == 14) { - delete pC; continue; } auto &connections = m_connMap[stage]; - connections.push_back(pC); + connections.push_back(std::move(pC)); } // re-arrange the connection stages @@ -69,7 +67,9 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) { std::map> newConnMap; for (const auto &[_, value] : m_connMap) { - std::ranges::copy(value, std::back_inserter(lConns)); + for (const auto &conn : value) { + lConns.push_back(conn.get()); + } } int stageCounter = 0; @@ -172,12 +172,4 @@ GbtsConnector::GbtsConnector(std::ifstream &inFile) { newConnMap.clear(); } -GbtsConnector::~GbtsConnector() { - m_layerGroups.clear(); - for (const auto &[_, connections] : m_connMap) { - for (auto *conn : connections) { - delete conn; - } - } -} } // namespace Acts From 0852e57f5d4a009fc1114ab91a8726f441949546 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Thu, 7 Nov 2024 16:01:49 +0100 Subject: [PATCH 3/8] ProtoLayerCreatorT --- .../GenericDetector/ProtoLayerCreatorT.hpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/ProtoLayerCreatorT.hpp b/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/ProtoLayerCreatorT.hpp index fc4fa4c1459..977c11d9121 100644 --- a/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/ProtoLayerCreatorT.hpp +++ b/Examples/Detectors/GenericDetector/include/ActsExamples/GenericDetector/ProtoLayerCreatorT.hpp @@ -218,8 +218,8 @@ ProtoLayerCreatorT::centralProtoLayers( double moduleHalfY = m_cfg.centralModuleHalfY.at(icl); double moduleThickness = m_cfg.centralModuleThickness.at(icl); // create the shared module - std::shared_ptr moduleBounds( - new Acts::RectangleBounds(moduleHalfX, moduleHalfY)); + auto moduleBounds = + std::make_shared(moduleHalfX, moduleHalfY); std::size_t nCentralModules = m_cfg.centralModuleBinningSchema.at(icl).first * m_cfg.centralModuleBinningSchema.at(icl).second; @@ -414,15 +414,14 @@ ProtoLayerCreatorT::createProtoLayers( double moduleHalfY = m_cfg.posnegModuleHalfY.at(ipnl).at(ipnR); // (1) module bounds // create the bounds - Acts::PlanarBounds* pBounds = nullptr; + std::shared_ptr moduleBounds; if (moduleMaxHalfX != 0. && moduleMinHalfX != moduleMaxHalfX) { - pBounds = new Acts::TrapezoidBounds(moduleMinHalfX, moduleMaxHalfX, - moduleHalfY); + moduleBounds = std::make_shared( + moduleMinHalfX, moduleMaxHalfX, moduleHalfY); } else { - pBounds = new Acts::RectangleBounds(moduleMinHalfX, moduleHalfY); + moduleBounds = std::make_shared(moduleMinHalfX, + moduleHalfY); } - // now create the shared bounds from it - std::shared_ptr moduleBounds(pBounds); // (2)) module material // create the Module material from input std::shared_ptr moduleMaterialPtr = From 9501894d4be6f5e01d57aea8d801f4700248deae Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Thu, 7 Nov 2024 16:02:08 +0100 Subject: [PATCH 4/8] ROOT IO --- .../Detectors/MagneticField/src/FieldMapRootIo.cpp | 6 ++---- .../ActsExamples/Io/Root/RootAthenaNTupleReader.hpp | 4 +++- .../Io/Root/RootMaterialTrackReader.hpp | 2 +- .../ActsExamples/Io/Root/RootParticleReader.hpp | 2 +- .../ActsExamples/Io/Root/RootSimHitReader.hpp | 4 +++- .../ActsExamples/Io/Root/RootTrackSummaryReader.hpp | 2 +- .../ActsExamples/Io/Root/RootVertexReader.hpp | 2 +- Examples/Io/Root/src/RootAthenaNTupleReader.cpp | 4 +++- Examples/Io/Root/src/RootBFieldWriter.cpp | 7 +++---- Examples/Io/Root/src/RootMaterialTrackReader.cpp | 4 +--- Examples/Io/Root/src/RootParticleReader.cpp | 2 +- Examples/Io/Root/src/RootSimHitReader.cpp | 4 +++- Examples/Io/Root/src/RootTrackSummaryReader.cpp | 2 +- Examples/Io/Root/src/RootVertexReader.cpp | 2 +- .../detail/NuclearInteractionParametrisation.cpp | 13 +++++++++---- 15 files changed, 34 insertions(+), 26 deletions(-) diff --git a/Examples/Detectors/MagneticField/src/FieldMapRootIo.cpp b/Examples/Detectors/MagneticField/src/FieldMapRootIo.cpp index bcc93238364..48e2e634d65 100644 --- a/Examples/Detectors/MagneticField/src/FieldMapRootIo.cpp +++ b/Examples/Detectors/MagneticField/src/FieldMapRootIo.cpp @@ -32,7 +32,7 @@ ActsExamples::makeMagneticFieldMapRzFromRoot( // components of magnetic field on grid points std::vector bField; // [1] Read in file and fill values - TFile* inputFile = TFile::Open(fieldMapFile.c_str()); + std::unique_ptr inputFile(TFile::Open(fieldMapFile.c_str())); if (inputFile == nullptr) { throw std::runtime_error("file does not exist"); } @@ -62,7 +62,6 @@ ActsExamples::makeMagneticFieldMapRzFromRoot( zPos.push_back(z); bField.push_back(Acts::Vector2(Br, Bz)); } - delete inputFile; /// [2] use helper function in core return Acts::fieldMapRZ(localToGlobalBin, rPos, zPos, bField, lengthUnit, BFieldUnit, firstQuadrant); @@ -84,7 +83,7 @@ ActsExamples::makeMagneticFieldMapXyzFromRoot( // components of magnetic field on grid points std::vector bField; // [1] Read in file and fill values - TFile* inputFile = TFile::Open(fieldMapFile.c_str()); + std::unique_ptr inputFile(TFile::Open(fieldMapFile.c_str())); if (inputFile == nullptr) { throw std::runtime_error("file does not exist"); } @@ -118,7 +117,6 @@ ActsExamples::makeMagneticFieldMapXyzFromRoot( zPos.push_back(z); bField.push_back(Acts::Vector3(Bx, By, Bz)); } - delete inputFile; return Acts::fieldMapXYZ(localToGlobalBin, xPos, yPos, zPos, bField, lengthUnit, BFieldUnit, firstOctant); diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootAthenaNTupleReader.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootAthenaNTupleReader.hpp index 7f4d6f7bc73..e6bba0782eb 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootAthenaNTupleReader.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootAthenaNTupleReader.hpp @@ -178,6 +178,8 @@ class RootAthenaNTupleReader : public ActsExamples::IReader { /// @param config The Configuration struct RootAthenaNTupleReader(const Config &config, Acts::Logging::Level level); + ~RootAthenaNTupleReader() override; + /// Framework name() method std::string name() const final { return "RootAthenaNTupleReader"; } @@ -214,7 +216,7 @@ class RootAthenaNTupleReader : public ActsExamples::IReader { std::size_t m_events = 0; /// The input tree name - TChain *m_inputChain = nullptr; + std::unique_ptr m_inputChain; /// The handle to branches in current event BranchPointerWrapper m_branches; diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp index 3c3bf2aece3..4c95c7e8d1d 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootMaterialTrackReader.hpp @@ -94,7 +94,7 @@ class RootMaterialTrackReader : public IReader { std::size_t m_batchSize = 0; /// The input tree name - TChain* m_inputChain = nullptr; + std::unique_ptr m_inputChain; /// Event identifier. std::uint32_t m_eventId = 0; diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootParticleReader.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootParticleReader.hpp index a58e84c1978..72536091f55 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootParticleReader.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootParticleReader.hpp @@ -83,7 +83,7 @@ class RootParticleReader : public IReader { std::size_t m_events = 0; /// The input tree name - TChain* m_inputChain = nullptr; + std::unique_ptr m_inputChain; /// Event identifier. std::uint32_t m_eventId = 0; diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootSimHitReader.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootSimHitReader.hpp index ade13f060a3..f2ba72af302 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootSimHitReader.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootSimHitReader.hpp @@ -51,6 +51,8 @@ class RootSimHitReader : public IReader { /// @param config The Configuration struct RootSimHitReader(const Config &config, Acts::Logging::Level level); + ~RootSimHitReader() override; + /// Framework name() method std::string name() const override { return "RootSimHitReader"; } @@ -82,7 +84,7 @@ class RootSimHitReader : public IReader { std::vector> m_eventMap; /// The input tree name - TChain *m_inputChain = nullptr; + std::unique_ptr m_inputChain; /// The keys we have in the ROOT file constexpr static std::array m_floatKeys = { diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootTrackSummaryReader.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootTrackSummaryReader.hpp index 3ad5a7eda35..bba1fa191c3 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootTrackSummaryReader.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootTrackSummaryReader.hpp @@ -93,7 +93,7 @@ class RootTrackSummaryReader : public IReader { std::size_t m_events = 0; /// The input tree name - TChain* m_inputChain = nullptr; + std::unique_ptr m_inputChain; /// the event number std::uint32_t m_eventNr{0}; diff --git a/Examples/Io/Root/include/ActsExamples/Io/Root/RootVertexReader.hpp b/Examples/Io/Root/include/ActsExamples/Io/Root/RootVertexReader.hpp index 46afe962bdb..b40c0b9ba6b 100644 --- a/Examples/Io/Root/include/ActsExamples/Io/Root/RootVertexReader.hpp +++ b/Examples/Io/Root/include/ActsExamples/Io/Root/RootVertexReader.hpp @@ -82,7 +82,7 @@ class RootVertexReader : public IReader { std::size_t m_events = 0; /// The input tree name - TChain* m_inputChain = nullptr; + std::unique_ptr m_inputChain; /// Event identifier. std::uint32_t m_eventId = 0; diff --git a/Examples/Io/Root/src/RootAthenaNTupleReader.cpp b/Examples/Io/Root/src/RootAthenaNTupleReader.cpp index ac06349c595..bf61b919c5b 100644 --- a/Examples/Io/Root/src/RootAthenaNTupleReader.cpp +++ b/Examples/Io/Root/src/RootAthenaNTupleReader.cpp @@ -43,7 +43,7 @@ ActsExamples::RootAthenaNTupleReader::RootAthenaNTupleReader( m_outputRecoVtxParameters.initialize(m_cfg.outputRecoVtxParameters); m_outputBeamspotConstraint.initialize(m_cfg.outputBeamspotConstraint); - m_inputChain = new TChain(m_cfg.inputTreeName.c_str()); + m_inputChain = std::make_unique(m_cfg.inputTreeName.c_str()); // unused event identifier std::int32_t eventNumber = 0; @@ -116,6 +116,8 @@ ActsExamples::RootAthenaNTupleReader::RootAthenaNTupleReader( ACTS_DEBUG("The full chain has " << m_events << " entries."); } +ActsExamples::RootAthenaNTupleReader::~RootAthenaNTupleReader() = default; + ActsExamples::ProcessCode ActsExamples::RootAthenaNTupleReader::read( const ActsExamples::AlgorithmContext& context) { ACTS_DEBUG("Trying to read track parameters from ntuple."); diff --git a/Examples/Io/Root/src/RootBFieldWriter.cpp b/Examples/Io/Root/src/RootBFieldWriter.cpp index b8cb8b6c104..894636d61c9 100644 --- a/Examples/Io/Root/src/RootBFieldWriter.cpp +++ b/Examples/Io/Root/src/RootBFieldWriter.cpp @@ -48,13 +48,13 @@ void RootBFieldWriter::run(const Config& config, // Setup ROOT I/O ACTS_INFO("Registering new ROOT output File : " << config.fileName); - TFile* outputFile = - TFile::Open(config.fileName.c_str(), config.fileMode.c_str()); + std::unique_ptr outputFile( + TFile::Open(config.fileName.c_str(), config.fileMode.c_str())); if (outputFile == nullptr) { throw std::ios_base::failure("Could not open '" + config.fileName + "'"); } TTree* outputTree = new TTree(config.treeName.c_str(), - config.treeName.c_str(), 99, outputFile); + config.treeName.c_str(), 99, outputFile.get()); if (outputTree == nullptr) { throw std::bad_alloc(); } @@ -277,6 +277,5 @@ void RootBFieldWriter::run(const Config& config, // Tear down ROOT I/O ACTS_INFO("Closing and Writing ROOT output File : " << config.fileName); outputTree->Write(); - delete outputFile; } } // namespace ActsExamples diff --git a/Examples/Io/Root/src/RootMaterialTrackReader.cpp b/Examples/Io/Root/src/RootMaterialTrackReader.cpp index 8781b134559..d6c40583f88 100644 --- a/Examples/Io/Root/src/RootMaterialTrackReader.cpp +++ b/Examples/Io/Root/src/RootMaterialTrackReader.cpp @@ -34,7 +34,7 @@ RootMaterialTrackReader::RootMaterialTrackReader(const Config& config, throw std::invalid_argument{"No input files given"}; } - m_inputChain = new TChain(m_cfg.treeName.c_str()); + m_inputChain = std::make_unique(m_cfg.treeName.c_str()); // loop over the input files for (const auto& inputFile : m_cfg.fileList) { @@ -99,8 +99,6 @@ RootMaterialTrackReader::RootMaterialTrackReader(const Config& config, } RootMaterialTrackReader::~RootMaterialTrackReader() { - delete m_inputChain; - delete m_step_x; delete m_step_y; delete m_step_z; diff --git a/Examples/Io/Root/src/RootParticleReader.cpp b/Examples/Io/Root/src/RootParticleReader.cpp index 973986d6704..a5e63d8e8cc 100644 --- a/Examples/Io/Root/src/RootParticleReader.cpp +++ b/Examples/Io/Root/src/RootParticleReader.cpp @@ -29,7 +29,7 @@ RootParticleReader::RootParticleReader(const RootParticleReader::Config& config, : IReader(), m_cfg(config), m_logger(Acts::getDefaultLogger(name(), level)) { - m_inputChain = new TChain(m_cfg.treeName.c_str()); + m_inputChain = std::make_unique(m_cfg.treeName.c_str()); if (m_cfg.filePath.empty()) { throw std::invalid_argument("Missing input filename"); diff --git a/Examples/Io/Root/src/RootSimHitReader.cpp b/Examples/Io/Root/src/RootSimHitReader.cpp index 4f0d805dc7e..407c70c5dea 100644 --- a/Examples/Io/Root/src/RootSimHitReader.cpp +++ b/Examples/Io/Root/src/RootSimHitReader.cpp @@ -29,7 +29,7 @@ RootSimHitReader::RootSimHitReader(const RootSimHitReader::Config& config, : IReader(), m_cfg(config), m_logger(Acts::getDefaultLogger(name(), level)) { - m_inputChain = new TChain(m_cfg.treeName.c_str()); + m_inputChain = std::make_unique(m_cfg.treeName.c_str()); if (m_cfg.filePath.empty()) { throw std::invalid_argument("Missing input filename"); @@ -103,6 +103,8 @@ RootSimHitReader::RootSimHitReader(const RootSimHitReader::Config& config, << availableEvents().second); } +RootSimHitReader::~RootSimHitReader() = default; + std::pair RootSimHitReader::availableEvents() const { return {std::get<0>(m_eventMap.front()), std::get<0>(m_eventMap.back()) + 1}; } diff --git a/Examples/Io/Root/src/RootTrackSummaryReader.cpp b/Examples/Io/Root/src/RootTrackSummaryReader.cpp index 3a4f206c927..c87b9f0a1e0 100644 --- a/Examples/Io/Root/src/RootTrackSummaryReader.cpp +++ b/Examples/Io/Root/src/RootTrackSummaryReader.cpp @@ -31,7 +31,7 @@ RootTrackSummaryReader::RootTrackSummaryReader( : IReader(), m_logger{Acts::getDefaultLogger(name(), level)}, m_cfg(config) { - m_inputChain = new TChain(m_cfg.treeName.c_str()); + m_inputChain = std::make_unique(m_cfg.treeName.c_str()); if (m_cfg.filePath.empty()) { throw std::invalid_argument("Missing input filename"); diff --git a/Examples/Io/Root/src/RootVertexReader.cpp b/Examples/Io/Root/src/RootVertexReader.cpp index 336e0364f9b..a2aadb5f54d 100644 --- a/Examples/Io/Root/src/RootVertexReader.cpp +++ b/Examples/Io/Root/src/RootVertexReader.cpp @@ -29,7 +29,7 @@ RootVertexReader::RootVertexReader(const RootVertexReader::Config& config, : IReader(), m_cfg(config), m_logger(Acts::getDefaultLogger(name(), level)) { - m_inputChain = new TChain(m_cfg.treeName.c_str()); + m_inputChain = std::make_unique(m_cfg.treeName.c_str()); if (m_cfg.filePath.empty()) { throw std::invalid_argument("Missing input filename"); diff --git a/Examples/Io/Root/src/detail/NuclearInteractionParametrisation.cpp b/Examples/Io/Root/src/detail/NuclearInteractionParametrisation.cpp index 91f59c56648..41fb6c193e7 100644 --- a/Examples/Io/Root/src/detail/NuclearInteractionParametrisation.cpp +++ b/Examples/Io/Root/src/detail/NuclearInteractionParametrisation.cpp @@ -34,15 +34,20 @@ namespace { /// @return The location in a standard normal distribution float gaussianValue(TH1F const* histo, const float mom) { // Get the cumulative probability distribution - TH1F* normalised = static_cast(histo->DrawNormalized()); - TH1F* cumulative = static_cast(normalised->GetCumulative()); + + // DrawNormalized and GetCumulative return pointers to histograms where ROOT + // transfers ownership to the caller. + std::unique_ptr normalised( + dynamic_cast(histo->DrawNormalized())); + std::unique_ptr cumulative( + dynamic_cast(normalised->GetCumulative())); + assert(cumulative); + assert(normalised); // Find the cumulative probability const float binContent = cumulative->GetBinContent(cumulative->FindBin(mom)); // Transform the probability to an entry in a standard normal distribution const float value = TMath::ErfInverse(2. * binContent - 1.); - delete (normalised); - delete (cumulative); return value; } From 8f7b4c5ee209c88c72ed1518e0be0e0e3d58a430 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Thu, 7 Nov 2024 16:02:17 +0100 Subject: [PATCH 5/8] LayerCreator --- Core/src/Geometry/LayerCreator.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/src/Geometry/LayerCreator.cpp b/Core/src/Geometry/LayerCreator.cpp index 632274c671f..e24ff8e0661 100644 --- a/Core/src/Geometry/LayerCreator.cpp +++ b/Core/src/Geometry/LayerCreator.cpp @@ -407,8 +407,7 @@ Acts::MutableLayerPtr Acts::LayerCreator::planeLayer( } // create the layer and push it back - std::shared_ptr pBounds( - new RectangleBounds(layerHalf1, layerHalf2)); + auto pBounds = std::make_shared(layerHalf1, layerHalf2); // create the layer MutableLayerPtr pLayer = From 337979f102f99bc0c9d18ce000125ea38d93497e Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Mon, 11 Nov 2024 18:29:50 +0100 Subject: [PATCH 6/8] fix compilation --- Core/include/Acts/TrackFinding/GbtsConnector.hpp | 2 +- Core/src/TrackFinding/GbtsConnector.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/include/Acts/TrackFinding/GbtsConnector.hpp b/Core/include/Acts/TrackFinding/GbtsConnector.hpp index f368f876b94..d4724929ac2 100644 --- a/Core/include/Acts/TrackFinding/GbtsConnector.hpp +++ b/Core/include/Acts/TrackFinding/GbtsConnector.hpp @@ -11,8 +11,8 @@ // TODO: update to C++17 style // Consider to moving to detail subdirectory #include -#include #include +#include #include namespace Acts { diff --git a/Core/src/TrackFinding/GbtsConnector.cpp b/Core/src/TrackFinding/GbtsConnector.cpp index ff6945849ce..69e0f7919e5 100644 --- a/Core/src/TrackFinding/GbtsConnector.cpp +++ b/Core/src/TrackFinding/GbtsConnector.cpp @@ -9,7 +9,6 @@ // TODO: update to C++17 style #include "Acts/TrackFinding/GbtsConnector.hpp" -#include #include #include #include From d1f3a22668fc4225bc10744cbc193d46d7fdb1c0 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Tue, 12 Nov 2024 09:50:16 +0100 Subject: [PATCH 7/8] revert doc comment change --- .../Acts/Geometry/SurfaceArrayCreator.hpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp b/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp index fd91a26a66b..cf210812444 100644 --- a/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp +++ b/Core/include/Acts/Geometry/SurfaceArrayCreator.hpp @@ -130,7 +130,23 @@ class SurfaceArrayCreator { std::size_t binsZ, std::optional protoLayerOpt = std::nullopt, const Transform3& transform = Transform3::Identity()) const; - /// SurfaceArrayCreator interface methonew SurfaceArray + /// SurfaceArrayCreator interface method + /// + /// - create an array in a cylinder, binned in phi, z when extremas and bin + /// numbers are unknown - this method goes through the surfaces and finds out + /// the needed information + /// @warning This function requires the cylinder aligned with the z-axis + /// @param surfaces is the vector of pointers to sensitive surfaces + /// to be ordered on the cylinder + /// @pre the pointers to the sensitive surfaces in the surfaces vectors all + /// need to be valid, since no check is performed + /// @param [in] gctx The gometry context for this building call + /// @param protoLayerOpt The proto layer containing the layer size + /// @param bTypePhi the binning type in phi direction (equidistant/arbitrary) + /// @param bTypeZ the binning type in z direction (equidistant/arbitrary) + /// @param transform is the (optional) additional transform applied + /// + /// @return a unique pointer a new SurfaceArray std::unique_ptr surfaceArrayOnCylinder( const GeometryContext& gctx, std::vector> surfaces, From b48d00f9db6197b1fccbb07a2a844c86e7686016 Mon Sep 17 00:00:00 2001 From: Paul Gessinger Date: Tue, 12 Nov 2024 13:09:11 +0100 Subject: [PATCH 8/8] fix another compile issue --- Core/include/Acts/Seeding/GbtsDataStorage.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/include/Acts/Seeding/GbtsDataStorage.hpp b/Core/include/Acts/Seeding/GbtsDataStorage.hpp index c41e5755c42..ba065b6a8e8 100644 --- a/Core/include/Acts/Seeding/GbtsDataStorage.hpp +++ b/Core/include/Acts/Seeding/GbtsDataStorage.hpp @@ -120,7 +120,7 @@ class GbtsEtaBin { for (unsigned int nIdx = 0; nIdx < m_vn.size(); nIdx++) { GbtsNode &pN = *m_vn.at(nIdx); - float phi = pN->m_spGbts.phi(); + float phi = pN.m_spGbts.phi(); if (phi >= -std::numbers::pi_v + dphi) { break; }