ATLAS Offline Software
Loading...
Searching...
No Matches
FileRoISeedTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2020-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6// Implementation file for class FileRoISeedTool (get RoI for low-pt tracking from a file)
8// (c) ATLAS Detector software
10
11
13
14#include "TVector2.h"
15
16#include <map>
17#include <sstream>
18#include <fstream>
19#include <string>
20#include <filesystem>
21
23// Constructor
25
27(const std::string& t,const std::string& n,const IInterface* p)
28 : base_class(t,n,p)
29{
30}
31
33// Initialization
35
37{
38 StatusCode sc = AlgTool::initialize();
39
40 ATH_CHECK( m_eventInfoKey.initialize() );
41
42 if (not std::filesystem::exists(std::filesystem::path(m_filename.value()))) {
43 ATH_MSG_ERROR( "RoI File DOES NOT Exist!");
44 return StatusCode::FAILURE;
45 }
46
47 return sc;
48}
49
51// Compute RoI
53std::vector<InDet::IZWindowRoISeedTool::ZWindow> InDet::FileRoISeedTool::getRoIs(const EventContext& ctx) const
54{
55
56 // prepare output
57 std::vector<InDet::IZWindowRoISeedTool::ZWindow> listRoIs;
58 listRoIs.clear();
59
60 unsigned long long evtN = 0;
61 int runN = 0;
62
64 if ( eventInfo.isValid() ){
65 evtN = eventInfo->eventNumber();
66 runN = eventInfo->runNumber();
67 }
68
69 std::string line;
70 std::ifstream inFile(m_filename.value());
71 if (inFile.is_open()){
72
73 while (std::getline(inFile, line)){
74
75 std::istringstream iss(line);
76
77 int runnum;
78 unsigned long long eventnum;
79 float zref;
80
81 while( iss >> runnum >> eventnum >> zref){
82 //no need to go past the right line
83 if(runnum == runN && eventnum == evtN) break;
84 }
85
86 if(runnum == runN && eventnum == evtN){ //No need to fill if there isn't an ROI
88 readinref.zReference = zref;
89 readinref.zWindow[0] = zref -m_z0Window;
90 readinref.zWindow[1] = zref + m_z0Window;
91 listRoIs.push_back(readinref);
92 }
93
94 }
95 }
96
97 inFile.close();
98
99 return listRoIs;
100
101}
102
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
static Double_t sc
virtual std::vector< ZWindow > getRoIs(const EventContext &ctx) const override
Compute RoI.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoKey
virtual StatusCode initialize() override
StringProperty m_filename
virtual bool isValid() override final
Can the handle be successfully dereferenced?