ATLAS Offline Software
Loading...
Searching...
No Matches
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
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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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
49{
50 return readData(header, last, false); // by default with this tool don't reset data
51}
52
54{
55
56 last = false;
57 //unsigned entry = static_cast<unsigned>(CLHEP::RandFlat::shoot() * m_nEntries);
58 m_EventTree->GetEntry(m_entry++);
59
60 // Truth Info
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();
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
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
121 delete m_eventHeader;
122 return StatusCode::SUCCESS;
123}
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
void maximize(const FPGATrackSimMultiTruth::Barcode &code, const FPGATrackSimMultiTruth::Weight &weight)
std::pair< unsigned long, unsigned long > Barcode
void addTruthTrack(const FPGATrackSimTruthTrack &t)
void addOfflineTrack(const FPGATrackSimOfflineTrack &t)
virtual StatusCode writeData(FPGATrackSimEventInputHeader *header) override
FPGATrackSimReadRawRandomHitsTool(const std::string &, const std::string &, const IInterface *)
virtual StatusCode readData(FPGATrackSimEventInputHeader *header, bool &last) override