ATLAS Offline Software
Loading...
Searching...
No Matches
AFPTDBasicTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 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 // time average
126 if( TrSize!=TrSat) TrTime /= weight;
127
128 ATH_MSG_DEBUG("Track reconstruction complete: stationID = " + std::to_string(m_stationID) + ", train time = " + std::to_string(TrTime) + ", train size = " + std::to_string(TrSize));
129 reconstructedTracks.emplace_back(m_stationID,k,TrTime, TrSize, TrSat);
130 AFPTDBasicToolTrack& theTrack = reconstructedTracks.back();
131 for(unsigned int l=0; l<TrSize; l++) theTrack.addBar(my_trainBars[k].at(l));
132 }
133 }
134
135 // === Save result to xAOD ===
136 // save to xAOD
137
138 for (const AFPTDBasicToolTrack& track : reconstructedTracks)
139 saveToXAOD(track, outputContainer, hitContainer);
140 return StatusCode::SUCCESS;
141}
142
143void AFPTDBasicTool::saveToXAOD (const AFPTDBasicToolTrack& recoTrack, std::unique_ptr<xAOD::AFPToFTrackContainer>& containerToFill, SG::ReadHandle<xAOD::AFPToFHitContainer>& hitContainer) const
144{
145 ATH_MSG_DEBUG("AFPTDBasicTool::saveToXAOD");
146 auto *track = containerToFill->push_back(std::make_unique<xAOD::AFPToFTrack>());
147
148 track->setStationID(recoTrack.m_stationID);
149 track->setTrainID(recoTrack.m_trainID);
150 track->setTrainTime(recoTrack.m_trainTime);
151 track->setTrainSize(recoTrack.m_trainSize);
152 track->setTrainNSat(recoTrack.m_trainNSat);
153 track->setAlgID(0);
154// add links to bars
155 ATH_MSG_DEBUG("Track time: (time="<<track->trainTime()<<", size="<<track->trainSize()<<", train id="<<track->trainID()<<") station: (st="<<track->stationID()<<")");
156 for (const xAOD::AFPToFHit* theHit : recoTrack.barInTrain()) {
158 barLink.toContainedElement(*hitContainer, theHit);
159 track->addBar(barLink);
160
161 ATH_MSG_DEBUG("bar time="<<theHit->time()<<" bar in train ="<<theHit->barInTrainID()<<", trin id ="<<theHit->trainID()<<")");
162 }
163
164}
165
Header file for AFPTDBasicTool used in tracks reconstruction.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define CHECK(...)
Evaluate an expression and check for errors.
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