ATLAS Offline Software
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 
19 AFPTDBasicTool::AFPTDBasicTool( const std::string& type,
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 
48 void 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 
65 StatusCode 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 
143 void 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 
AFPTDBasicToolTrack::m_trainSize
int m_trainSize
Definition: AFPTDBasicToolTrack.h:30
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
json
nlohmann::json json
Definition: HistogramDef.cxx:9
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AFPTDBasicTool.h
Header file for AFPTDBasicTool used in tracks reconstruction.
AFPTDBasicToolTrack::addBar
void addBar(const xAOD::AFPToFHit *bar)
Adds a new bar to the track.
Definition: AFPTDBasicToolTrack.h:38
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
xAOD::AFPToFHit_v1
Class representing a hit in ToF detector.
Definition: AFPToFHit_v1.h:20
AFPTDBasicTool::m_tofLocParamDBTool
ToolHandle< AFP::IToFLocParamDBTool > m_tofLocParamDBTool
@ brief Tool for accessing DB to get the local ToF parameters
Definition: AFPTDBasicTool.h:84
AFPTDBasicTool::finalize
virtual StatusCode finalize() override
Does nothing.
Definition: AFPTDBasicTool.cxx:41
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
AFPTDBasicToolTrack::m_trainID
int m_trainID
Definition: AFPTDBasicToolTrack.h:29
AFPTDBasicTool::saveToXAOD
void saveToXAOD(const AFPTDBasicToolTrack &recoTrack, std::unique_ptr< xAOD::AFPToFTrackContainer > &containerToFill, SG::ReadHandle< xAOD::AFPToFHitContainer > &hitContainer) const
Save reconstructed track to the xAOD container.
Definition: AFPTDBasicTool.cxx:143
AFPTDBasicToolTrack::barInTrain
const std::list< const xAOD::AFPToFHit * > & barInTrain() const
Definition: AFPTDBasicToolTrack.h:35
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AFPTDBasicTool::clearTrains
void clearTrains(std::vector< const xAOD::AFPToFHit * > my_trainBars[4]) const
clear station from bars saved in #my_trainBars;
Definition: AFPTDBasicTool.h:90
test_pyathena.parent
parent
Definition: test_pyathena.py:15
AFPTDBasicToolTrack::m_stationID
int m_stationID
Definition: AFPTDBasicToolTrack.h:28
AFPTDBasicToolTrack::m_trainNSat
int m_trainNSat
Definition: AFPTDBasicToolTrack.h:31
AFP::ToFLocParamData::barTimeOffset
double barTimeOffset() const
Time offset for this particular bar.
Definition: ToFLocParamData.h:44
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AFPTDBasicTool::reconstructTracks
StatusCode reconstructTracks(std::unique_ptr< xAOD::AFPToFTrackContainer > &outputContainer, const EventContext &ctx) const override
Does actual tracks reconstruction.
Definition: AFPTDBasicTool.cxx:65
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
AFPTDBasicTool::m_minHitsNumber
Gaudi::Property< unsigned int > m_minHitsNumber
Minimal number of bars in track. If there are less bars, track is rejected (Default = 3)
Definition: AFPTDBasicTool.h:79
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
AFPTDBasicToolTrack::m_trainTime
double m_trainTime
Definition: AFPTDBasicToolTrack.h:32
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AFPTDBasicTool::AFPTDBasicTool
AFPTDBasicTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: AFPTDBasicTool.cxx:19
AFP::ToFLocParamData::barWeight
double barWeight() const
Weight for this particular bar.
Definition: ToFLocParamData.h:41
AFPTDBasicTool::m_hitContainerKey
SG::ReadHandleKey< xAOD::AFPToFHitContainer > m_hitContainerKey
Name of the xAOD container with ToF hits to be used in track reconstruction.
Definition: AFPTDBasicTool.h:76
AFP::ToFLocParamData
Class storing information about alignment.
Definition: ToFLocParamData.h:24
AFPTDBasicTool::fillTrainWithBars
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.
Definition: AFPTDBasicTool.cxx:48
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
AFPTDBasicTool::m_stationID
Gaudi::Property< int > m_stationID
AFP station ID for which tracks will be reconstructed.
Definition: AFPTDBasicTool.h:73
AFPTDBasicTool::initialize
virtual StatusCode initialize() override
Read parameters from job options and print tool configuration.
Definition: AFPTDBasicTool.cxx:27
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
AFPTDBasicToolTrack
Class representing a reconstructed basic ToF track.
Definition: AFPTDBasicToolTrack.h:21
fitman.k
k
Definition: fitman.py:528
AFPTDBasicTool::m_maxAllowedLength
Gaudi::Property< double > m_maxAllowedLength
Definition: AFPTDBasicTool.h:81