ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
EFTracking
FPGATrackSim
FPGATrackSimInput
src
FPGATrackSimReadRawRandomHitsTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
FPGATrackSimInput/FPGATrackSimReadRawRandomHitsTool.h
"
6
#include "
FPGATrackSimObjects/FPGATrackSimEventInputHeader.h
"
7
8
9
FPGATrackSimReadRawRandomHitsTool::FPGATrackSimReadRawRandomHitsTool
(
const
std::string& algname,
const
std::string &name,
const
IInterface *ifc) :
10
base_class(algname,name,ifc) {}
11
12
13
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
14
StatusCode
FPGATrackSimReadRawRandomHitsTool::initialize
(){
15
16
// open input file
17
ATH_MSG_INFO
(
"Opening input file: "
<<
m_inpath
.value() );
18
m_infile = TFile::Open(
m_inpath
.value().c_str(),
"READ"
);
19
if
(m_infile ==
nullptr
){
20
ATH_MSG_FATAL
(
"Could not open input file: "
<<
m_inpath
.value() );
21
return
StatusCode::FAILURE;
22
}
23
24
//get the tree, try old and new versions for backwards compatability
25
m_EventTree = (TTree*) m_infile->Get(
"FPGATrackSimEventTree"
);
26
if
(m_EventTree ==
nullptr
|| m_EventTree->GetEntries() == -1 ){
27
ATH_MSG_FATAL
(
"Input file: "
<<
m_inpath
<<
" has no entries"
);
28
return
StatusCode::FAILURE;
29
}
30
31
std::string branchName=
"FPGATrackSimEventInputHeader"
;
32
if
(!m_EventTree->GetListOfBranches()->FindObject(branchName.c_str())){
33
ATH_MSG_FATAL
(
"Branch: "
<< branchName <<
" not found!"
);
34
return
StatusCode::FAILURE;
35
}
36
ATH_MSG_INFO
(
"Getting branch and set EventHeader"
);
37
TBranch *branch = m_EventTree->GetBranch(branchName.c_str());
38
branch->Print();
39
40
m_eventHeader =
new
FPGATrackSimEventInputHeader
();
41
branch->SetAddress(&m_eventHeader);
42
43
return
StatusCode::SUCCESS;
44
}
45
46
47
48
StatusCode
FPGATrackSimReadRawRandomHitsTool::readData
(
FPGATrackSimEventInputHeader
*
header
,
bool
&last)
const
49
{
50
return
readData
(
header
, last,
false
);
// by default with this tool don't reset data
51
}
52
53
StatusCode
FPGATrackSimReadRawRandomHitsTool::readData
(
FPGATrackSimEventInputHeader
*
header
,
bool
&last,
bool
doReset)
const
54
{
55
std::lock_guard<std::mutex>
lock
(
m_readMutex
);
56
57
last =
false
;
58
m_EventTree->GetEntry(
m_entry
++);
59
60
// Truth Info
61
FPGATrackSimOptionalEventInfo
optional;
62
unsigned
long
int
mbc = 0;
// to scale up barcodes!
63
64
// --- Copy old data
65
if
(doReset)
66
{
67
header
->reset();
//reset things!
68
}
69
else
// not resetting, start by copying over truth information from old header
70
{
71
for
(
const
auto
& truthtrack :
header
->optional().getTruthTracks())
72
{
73
if
(truthtrack.getBarcode() > mbc) mbc = truthtrack.getBarcode();
74
optional.
addTruthTrack
(truthtrack);
75
}
76
77
// now we got the max bar code, copy the offline tracks
78
for
(
const
auto
& offlinetrack :
header
->optional().getOfflineTracks())
79
{
80
optional.
addOfflineTrack
(offlinetrack);
81
}
82
}
83
84
// --- Copy new data
85
for
(
auto
truthtrack : m_eventHeader->optional().getTruthTracks())
86
{
87
truthtrack.setBarcode(truthtrack.getBarcode() + mbc);
88
optional.
addTruthTrack
(truthtrack);
89
}
90
for
(
auto
offlinetrack : m_eventHeader->optional().getOfflineTracks())
91
{
92
offlinetrack.setBarcode(offlinetrack.getBarcode() + mbc);
93
optional.
addOfflineTrack
(offlinetrack);
94
}
95
96
header
->setOptional(optional);
97
98
// copy Hits
99
for
(
auto
rawhit : m_eventHeader->hits())
100
{
101
FPGATrackSimMultiTruth
origtruth = rawhit.getTruth();
102
FPGATrackSimMultiTruth
mt;
103
FPGATrackSimMultiTruth::Barcode
uniquecode(rawhit.getEventIndex(),rawhit.getBarcode()+mbc);
104
mt.
maximize
(uniquecode, rawhit.getBarcodePt());
105
rawhit.setBarcode(rawhit.getBarcode() + mbc);
106
rawhit.setTruth(mt);
107
header
->addHit(rawhit);
108
}
109
110
return
StatusCode::SUCCESS;
111
}
112
113
114
StatusCode
FPGATrackSimReadRawRandomHitsTool::writeData
(
FPGATrackSimEventInputHeader
*
/*header*/
)
const
{
115
ATH_MSG_FATAL
(
"This tool is being forced to write things. But it is only designed to read things. Don't worry, everything is fine"
);
116
return
StatusCode::FAILURE;
// this tool is not designed to write things
117
}
118
119
120
StatusCode
FPGATrackSimReadRawRandomHitsTool::finalize
(){
121
delete
m_eventHeader;
122
return
StatusCode::SUCCESS;
123
}
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
FPGATrackSimEventInputHeader.h
FPGATrackSimReadRawRandomHitsTool.h
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
FPGATrackSimEventInputHeader
Definition
FPGATrackSimEventInputHeader.h:22
FPGATrackSimMultiTruth
Definition
FPGATrackSimMultiTruth.h:46
FPGATrackSimMultiTruth::maximize
void maximize(const FPGATrackSimMultiTruth::Barcode &code, const FPGATrackSimMultiTruth::Weight &weight)
Definition
FPGATrackSimMultiTruth.cxx:36
FPGATrackSimMultiTruth::Barcode
std::pair< unsigned long, unsigned long > Barcode
Definition
FPGATrackSimMultiTruth.h:49
FPGATrackSimOptionalEventInfo
Definition
FPGATrackSimOptionalEventInfo.h:17
FPGATrackSimOptionalEventInfo::addOfflineTrack
void addOfflineTrack(const FPGATrackSimOfflineTrack &t) const
Definition
FPGATrackSimOptionalEventInfo.h:34
FPGATrackSimOptionalEventInfo::addTruthTrack
void addTruthTrack(const FPGATrackSimTruthTrack &t) const
Definition
FPGATrackSimOptionalEventInfo.h:39
FPGATrackSimReadRawRandomHitsTool::m_inpath
StringProperty m_inpath
Definition
FPGATrackSimReadRawRandomHitsTool.h:27
FPGATrackSimReadRawRandomHitsTool::m_entry
std::atomic< unsigned > m_entry
Definition
FPGATrackSimReadRawRandomHitsTool.h:30
FPGATrackSimReadRawRandomHitsTool::FPGATrackSimReadRawRandomHitsTool
FPGATrackSimReadRawRandomHitsTool(const std::string &, const std::string &, const IInterface *)
Definition
FPGATrackSimReadRawRandomHitsTool.cxx:9
FPGATrackSimReadRawRandomHitsTool::m_readMutex
std::mutex m_readMutex
Definition
FPGATrackSimReadRawRandomHitsTool.h:31
FPGATrackSimReadRawRandomHitsTool::finalize
virtual StatusCode finalize() override
Definition
FPGATrackSimReadRawRandomHitsTool.cxx:120
FPGATrackSimReadRawRandomHitsTool::initialize
virtual StatusCode initialize() override
Definition
FPGATrackSimReadRawRandomHitsTool.cxx:14
FPGATrackSimReadRawRandomHitsTool::writeData
virtual StatusCode writeData(FPGATrackSimEventInputHeader *header) const override
Definition
FPGATrackSimReadRawRandomHitsTool.cxx:114
FPGATrackSimReadRawRandomHitsTool::readData
virtual StatusCode readData(FPGATrackSimEventInputHeader *header, bool &last) const override
Definition
FPGATrackSimReadRawRandomHitsTool.cxx:48
header
Definition
hcg.cxx:529
Generated on
for ATLAS Offline Software by
1.17.0