ATLAS Offline Software
Loading...
Searching...
No Matches
AFPTDBasicTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11
12// FrameWork includes
13#include "GaudiKernel/IToolSvc.h"
14#include "CLHEP/Units/SystemOfUnits.h"
15
16// AFP_LocReco includes
18
20 const std::string& name,
21 const IInterface* parent ) :
22 base_class ( type, name, parent )
23{
24
25}
26
28{
29 // print information about initialised stations
30 ATH_MSG_DEBUG("AFPTDBasicTool::initialize()");
31 ATH_MSG_INFO("Station with ID="<<m_stationID <<" will have minimum number of "<<m_minHitsNumber <<" bars.");
32 ATH_MSG_INFO("Maximal length of signal at which bar can be joined to the track m_maxAllowedLength = "<<m_maxAllowedLength);
33
34 CHECK( m_tofLocParamDBTool.retrieve() );
35 CHECK( m_hitContainerKey.initialize( SG::AllowEmpty ) );
36
37 return StatusCode::SUCCESS;
38}
39
40
42{
43 ATH_MSG_DEBUG("AFPTDBasicTool::finalize()");
44 return StatusCode::SUCCESS;
45}
46
47
48void AFPTDBasicTool::fillTrainWithBars(std::vector<const xAOD::AFPToFHit*> my_trainBars[4], SG::ReadHandle<xAOD::AFPToFHitContainer>& hitContainer) const
49{
50 ATH_MSG_DEBUG("AFPTDBasicTool::fillTrainWithBars");
51 ATH_MSG_DEBUG("Total number of AFP ToF hits read in = " << hitContainer->size());
52 // retrieve ToF bars
53 try {
54 // fill station with ToF hits
55 for (const xAOD::AFPToFHit* theHit : *hitContainer)
56 if (theHit->stationID() == m_stationID) // check if hit is from the correct station
57 my_trainBars[theHit->trainID()].push_back(theHit);
58 }
59 catch (const std::out_of_range& outOfRange) {
60 ATH_MSG_WARNING("Bar with station outside expected range. Aborting track reconstruction.");
61 clearTrains(my_trainBars);
62 }
63}
64
65StatusCode AFPTDBasicTool::reconstructTracks(std::unique_ptr<xAOD::AFPToFTrackContainer>& outputContainer, const EventContext& ctx) const
66{
67
68 if (m_hitContainerKey.empty()) {
69 // this is allowed, there might be no AFP data in the input
70 return StatusCode::SUCCESS;
71 }
72
74 if(!hitContainer.isValid())
75 {
76 // this is allowed, there might be no AFP data in the input
77 return StatusCode::SUCCESS;
78 }
79
80 // prepare list for storing reconstructed ToF tracks
81 std::list<AFPTDBasicToolTrack> reconstructedTracks;
82
83 std::vector<const xAOD::AFPToFHit*> my_trainBars[4];
84
85 clearTrains(my_trainBars);
86 fillTrainWithBars(my_trainBars, hitContainer);
87
88 ATH_MSG_DEBUG( "Number of AFP ToF hits in each train = " << my_trainBars[0].size()<<", "<<my_trainBars[1].size()<<", "<<my_trainBars[2].size()<<", "<<my_trainBars[3].size());
89
90 // ===== do tracks reconstruction =====
91
92 nlohmann::json dataTLP;
93 bool dataTLP_init{false};
94
95 for (int k=0; k<4; k++)
96 {
97 unsigned int TrSize = my_trainBars[k].size();
98 double TrTime = 0.;
99 double weight = 0;
100 unsigned int TrSat = 0;
101 if ( TrSize >= m_minHitsNumber )
102 {
103 for (unsigned int l=0; l<TrSize; l++)
104 {
105 // for l-th hit in the k-th train, not necessary l-th bar
106 if ( my_trainBars[k].at(l)->pulseLength() < m_maxAllowedLength)
107 {
108 if(!dataTLP_init)
109 {
110 // read from DB only if necessary
111 dataTLP=m_tofLocParamDBTool->parametersData(ctx);
112 dataTLP_init=true;
113 }
114
115 const AFP::ToFLocParamData TLP=m_tofLocParamDBTool->parameters(dataTLP, m_stationID, my_trainBars[k].at(l)->trainID(), my_trainBars[k].at(l)->barInTrainID());
116
117 TrTime += (my_trainBars[k].at(l)->time()-TLP.barTimeOffset())*TLP.barWeight();
118 weight += TLP.barWeight();
119 }
120 else
121 {
122 TrSat++;
123 }
124 }
125 if (weight == 0.){
126 ATH_MSG_ERROR("weight is zero in time average calculation");
127 return StatusCode::FAILURE;
128 }
129 // time average
130 if( TrSize!=TrSat) TrTime /= weight;
131
132 ATH_MSG_DEBUG("Track reconstruction complete: stationID = " + std::to_string(m_stationID) + ", train time = " + std::to_string(TrTime) + ", train size = " + std::to_string(TrSize));
133 reconstructedTracks.emplace_back(m_stationID,k,TrTime, TrSize, TrSat);
134 AFPTDBasicToolTrack& theTrack = reconstructedTracks.back();
135 for(unsigned int l=0; l<TrSize; l++) theTrack.addBar(my_trainBars[k].at(l));
136 }
137 }
138
139 // === Save result to xAOD ===
140 // save to xAOD
141
142 for (const AFPTDBasicToolTrack& track : reconstructedTracks)
143 saveToXAOD(track, outputContainer, hitContainer);
144 return StatusCode::SUCCESS;
145}
146
147void AFPTDBasicTool::saveToXAOD (const AFPTDBasicToolTrack& recoTrack, std::unique_ptr<xAOD::AFPToFTrackContainer>& containerToFill, SG::ReadHandle<xAOD::AFPToFHitContainer>& hitContainer) const
148{
149 ATH_MSG_DEBUG("AFPTDBasicTool::saveToXAOD");
150 auto *track = containerToFill->push_back(std::make_unique<xAOD::AFPToFTrack>());
151
152 track->setStationID(recoTrack.m_stationID);
153 track->setTrainID(recoTrack.m_trainID);
154 track->setTrainTime(recoTrack.m_trainTime);
155 track->setTrainSize(recoTrack.m_trainSize);
156 track->setTrainNSat(recoTrack.m_trainNSat);
157 track->setAlgID(0);
158// add links to bars
159 ATH_MSG_DEBUG("Track time: (time="<<track->trainTime()<<", size="<<track->trainSize()<<", train id="<<track->trainID()<<") station: (st="<<track->stationID()<<")");
160 for (const xAOD::AFPToFHit* theHit : recoTrack.barInTrain()) {
162 barLink.toContainedElement(*hitContainer, theHit);
163 track->addBar(barLink);
164
165 ATH_MSG_DEBUG("bar time="<<theHit->time()<<" bar in train ="<<theHit->barInTrainID()<<", trin id ="<<theHit->trainID()<<")");
166 }
167
168}
169
Header file for AFPTDBasicTool used in tracks reconstruction.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
size_t size() const
Number of registered mappings.
Class representing a reconstructed basic ToF track.
void addBar(const xAOD::AFPToFHit *bar)
Adds a new bar to the track.
const std::list< const xAOD::AFPToFHit * > & barInTrain() const
StatusCode reconstructTracks(std::unique_ptr< xAOD::AFPToFTrackContainer > &outputContainer, const EventContext &ctx) const override
Does actual tracks reconstruction.
virtual StatusCode finalize() override
Does nothing.
Gaudi::Property< unsigned int > m_minHitsNumber
Minimal number of bars in track. If there are less bars, track is rejected (Default = 3).
void fillTrainWithBars(std::vector< const xAOD::AFPToFHit * > my_trainBars[4], SG::ReadHandle< xAOD::AFPToFHitContainer > &hitContainer) const
Fills Station with ToF hits, dividing them into stations.
void saveToXAOD(const AFPTDBasicToolTrack &recoTrack, std::unique_ptr< xAOD::AFPToFTrackContainer > &containerToFill, SG::ReadHandle< xAOD::AFPToFHitContainer > &hitContainer) const
Save reconstructed track to the xAOD container.
Gaudi::Property< int > m_stationID
AFP station ID for which tracks will be reconstructed.
SG::ReadHandleKey< xAOD::AFPToFHitContainer > m_hitContainerKey
Name of the xAOD container with ToF hits to be used in track reconstruction.
virtual StatusCode initialize() override
Read parameters from job options and print tool configuration.
void clearTrains(std::vector< const xAOD::AFPToFHit * > my_trainBars[4]) const
clear station from bars saved in my_trainBars;
AFPTDBasicTool(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< double > m_maxAllowedLength
ToolHandle< AFP::IToFLocParamDBTool > m_tofLocParamDBTool
@ brief Tool for accessing DB to get the local ToF parameters
Class storing information about alignment.
double barTimeOffset() const
Time offset for this particular bar.
double barWeight() const
Weight for this particular bar.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
AFPToFHit_v1 AFPToFHit
Definition AFPToFHit.h:12