Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:23:59

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Io/Root/RootMuonSpacePointReader.hpp"
0010 
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "Acts/Utilities/UnitVectors.hpp"
0013 #include "ActsExamples/Io/Root/RootUtility.hpp"
0014 using namespace Acts;
0015 using namespace Acts::UnitLiterals;
0016 
0017 namespace ActsExamples {
0018 
0019 RootMuonSpacePointReader::RootMuonSpacePointReader(const Config& config,
0020                                                    Acts::Logging::Level level)
0021     : m_cfg{config},
0022       m_logger{getDefaultLogger("RootMuonSpacePointReader", level)} {
0023   if (m_cfg.outputSpacePoints.empty()) {
0024     throw std::invalid_argument(
0025         "RootMuonSpacePointReader() - Space points must not be empty");
0026   }
0027   m_outputContainer.initialize(m_cfg.outputSpacePoints);
0028   if (!m_file || m_file->IsZombie()) {
0029     throw std::invalid_argument(
0030         "RootMuonSpacePointReader() - Failed to open '" + m_cfg.filePath + "'");
0031   }
0032   if (m_reader.GetTree() == nullptr) {
0033     throw std::invalid_argument("Failed to load TTree '" + m_cfg.treeName +
0034                                 "'");
0035   }
0036 
0037   // Sort the entry numbers of the events
0038   {
0039     // necessary to guarantee that m_inputChain->GetV1() is valid for the
0040     // entire range
0041     m_eventRanges.resize(m_reader.GetEntries());
0042     m_reader.GetTree()->SetEstimate(m_eventRanges.size() + 1);
0043 
0044     m_reader.GetTree()->Draw("event_id", "", "goff");
0045     const auto nEntries = static_cast<std::uint32_t>(m_eventRanges.size());
0046     RootUtility::stableSort(nEntries, m_reader.GetTree()->GetV1(),
0047                             m_eventRanges.data(), false);
0048   }
0049 }
0050 
0051 RootMuonSpacePointReader::~RootMuonSpacePointReader() = default;
0052 
0053 std::pair<std::size_t, std::size_t> RootMuonSpacePointReader::availableEvents()
0054     const {
0055   return std::make_pair(0u, m_reader.GetEntries());
0056 }
0057 
0058 ProcessCode RootMuonSpacePointReader::read(
0059     const ActsExamples::AlgorithmContext& context) {
0060   std::lock_guard guard{m_mutex};
0061 
0062   MuonSpacePointContainer outSpacePoints{};
0063 
0064   auto entry = m_eventRanges.at(context.eventNumber);
0065   m_reader.SetEntry(entry);
0066   for (std::size_t spIdx = 0; spIdx < m_bucketId->size(); ++spIdx) {
0067     auto bucketIdx = static_cast<std::size_t>(m_bucketId->at(spIdx));
0068     // The space point buckets are ordered sequentially
0069     if (bucketIdx + 1 != outSpacePoints.size()) {
0070       outSpacePoints.emplace_back();
0071     }
0072     MuonSpacePoint& newSp{outSpacePoints.back().emplace_back()};
0073     newSp.setGeometryId(GeometryIdentifier{m_geometryId->at(spIdx)});
0074     newSp.setId(MuonSpacePoint::MuonId{m_muonId->at(spIdx)});
0075 
0076     Vector3 position{m_localPositionX->at(spIdx), m_localPositionY->at(spIdx),
0077                      m_localPositionZ->at(spIdx)};
0078     Vector3 sensorDir{makeDirectionFromPhiTheta<double>(
0079         m_sensorDirectionPhi->at(spIdx) * 1._degree,
0080         m_sensorDirectionTheta->at(spIdx) * 1._degree)};
0081     Vector3 toNext{makeDirectionFromPhiTheta<double>(
0082         m_toNextSensorPhi->at(spIdx) * 1._degree,
0083         m_toNextSensorTheta->at(spIdx) * 1._degree)};
0084 
0085     newSp.defineCoordinates(std::move(position), std::move(sensorDir),
0086                             std::move(toNext));
0087 
0088     newSp.setRadius(m_driftR->at(spIdx));
0089     newSp.setTime(m_time->at(spIdx));
0090     newSp.setCovariance(m_covLoc0->at(spIdx), m_covLoc1->at(spIdx),
0091                         m_covT->at(spIdx));
0092     ACTS_VERBOSE("Loaded new space point " << newSp);
0093   }
0094 
0095   m_outputContainer(context, std::move(outSpacePoints));
0096 
0097   return ProcessCode::SUCCESS;
0098 }
0099 
0100 }  // namespace ActsExamples