ATLAS Offline Software
Loading...
Searching...
No Matches
TRTCalibrationMgr.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/* *******************************************************************
6
7 TRTCalibrationMgr.cxx : Manager for TRT calibration
8
9 * ***************************************************************** */
10
12
13#include "TrkTrack/Track.h"
14
22#include "TrkTrack/Track.h"
25#include "TROOT.h"
27
28TRTCalibrationMgr::TRTCalibrationMgr(const std::string& name, ISvcLocator* pSvcLocator) :
29 AthAlgorithm (name, pSvcLocator){}
30
31//---------------------------------------------------------------------
32
35
36//--------------------------------------------------------------------------
37
39 ATH_MSG_DEBUG("initialize()");
40
41 if (m_docalibrate){
42 if (!m_TRTCalibTools.size() || m_TRTCalibTools.retrieve().isFailure())
43 {
44 ATH_MSG_FATAL("Cannot get Calibration tool " << m_TRTCalibTools);
45 return StatusCode::FAILURE;
46 }
47 }
48 else{
49 if (!m_TrackInfoTools.size() || m_TrackInfoTools.retrieve().isFailure())
50 {
51 ATH_MSG_FATAL("Cannot get TrackInfo filler tool " << m_TrackInfoTools);
52 return StatusCode::FAILURE;
53 }
54 }
55
56 if (!m_FitTools.size() || m_FitTools.retrieve().isFailure()){
57 ATH_MSG_FATAL("Cannot get Fit tools " << m_FitTools);
58 return StatusCode::FAILURE;
59 }
60
61 if (m_trackFitter.retrieve().isFailure()){
62 ATH_MSG_FATAL("Failed to retrieve tool " << m_trackFitter);
63 return StatusCode::FAILURE;
64 }
65
67 ATH_CHECK(m_streamer.retrieve());
68 }
69
70
71 // Initialize ReadHandles and ReadHandleKeys
72 ATH_CHECK(m_verticesKey.initialize());
73 ATH_CHECK(m_EventInfoKey.initialize());
74 ATH_CHECK(m_TrkCollection.initialize());
75
76 ATH_MSG_INFO("Tracks from Trk::Track collection:");
78
79 // Get the Track Selector Tool
80 if (!m_trackSelector.empty())
81 {
82 StatusCode sc = m_trackSelector.retrieve();
83 if (sc.isFailure())
84 {
85 ATH_MSG_FATAL("Could not retrieve " << m_trackSelector << " (to select the tracks which are written to the ntuple) ");
86 ATH_MSG_INFO("Set the ToolHandle to None if track selection is supposed to be disabled");
87 return sc;
88 }
89 }
90
91 ATH_MSG_INFO("Track Selector retrieved");
92
93 m_ntrk = 0;
94
95 return StatusCode::SUCCESS;
96}
97
98//---------------------------------------------------------------------
99
101
102 if (m_docalibrate){
103 ATH_MSG_INFO("skipping execute() calibrating instead");
104 bool CalibOK = m_TRTCalibTools[0]->calibrate();
105 if (CalibOK)
106 {
107 return StatusCode::SUCCESS;
108 }
109 else
110 {
111 return StatusCode::FAILURE;
112 }
113 }
114
116 {
117 StatusCode sc = streamOutCalibObjects();
118 return sc;
119 }
120
121 // Get Primary vertices. Skip events without three good tracks on vertex.
122
124 if (not vertices.isValid())
125 {
126 ATH_MSG_DEBUG("Couldn't retrieve VertexContainer with key: PrimaryVertices");
127 return StatusCode::SUCCESS; // just skip to next event in case of no vertexcontainer
128 }
129
130 int countVertices(0);
131 for (const xAOD::Vertex *vx : *(vertices.cptr()))
132 {
133 if (vx->vertexType() == xAOD::VxType::PriVtx)
134 {
135 if (vx->nTrackParticles() >= 3)
136 countVertices++;
137 }
138 }
139 if (countVertices < 1)
140 {
141 ATH_MSG_INFO("no vertices found");
142 return StatusCode::SUCCESS;
143 }
144
145 // get event info pointer
147 if (not EventInfo.isValid())
148 {
149 ATH_MSG_FATAL("skipping event, could not get EventInfo");
150 return StatusCode::FAILURE;
151 }
152
153 // Loop over tracks; get track info and accumulate it
154 const Trk::Track *aTrack;
155
157 // retrieve all tracks, but only from one collection (CombinedInDetTracks)
158
159 if (trks.isValid())
160 {
161
162 if (trks->size() < 3)
163 {
164 ATH_MSG_INFO("skipping event, it contains only " << trks->size() << " tracks (less than 3)");
165 return StatusCode::SUCCESS;
166 }
167
168 if (trks->size() > m_max_ntrk)
169 {
170 ATH_MSG_INFO("skipping event, it contains " << trks->size() << " tracks, more than max: " << m_max_ntrk);
171 return StatusCode::SUCCESS;
172 }
173 for (TrackCollection::const_iterator t = trks->begin(); t != trks->end(); ++t)
174 {
175
176 if (m_trackSelector->decision(*(*t), nullptr))
177 {
178
179 m_ntrk++;
180 aTrack = *t;
181
182 if (m_dorefit)
183 {
184 // Refit Track with new ROT creator
185 Trk::RunOutlierRemoval runOutlier = true;
186 aTrack = m_trackFitter->fit(Gaudi::Hive::currentContext(), *aTrack, runOutlier, aTrack->info().particleHypothesis()).release();
187 }
188 // Check selection if requested
189 if (aTrack)
190 {
191 // fill track info
193 // Run, event, track id
194 at[TRT::Track::run] = EventInfo->runNumber();
195 at[TRT::Track::event] = EventInfo->eventNumber();
197 ATH_MSG_DEBUG(" Track " << m_ntrk << " accepted Info: run="
198 << at[TRT::Track::run] << " event=" << at[TRT::Track::event]);
199 for (unsigned int j = 0; j < m_TrackInfoTools.size(); j++)
200
201 if (!m_TrackInfoTools[j]->fill(aTrack, &at, *EventInfo, *vertices))
202 break;
203 if (m_dorefit)
204 delete aTrack;
205 }
206 }
207 }
208 }
209 return StatusCode::SUCCESS;
210}
211
212//---------------------------------------------------------------------
213
215 ATH_MSG_INFO( "CALIBSTAT CM_TRKS: " << m_ntrk);
216
217 gROOT->SetMustClean(false);
218
219 // Accumulators to finalize
220 std::vector<IdentifierProfileHistogram*> histograms;
221 for (unsigned int j=0;j<m_TrackInfoTools.size();j++)
222 if ((m_TrackInfoTools[j]->finalize()).isFailure()){
223 ATH_MSG_FATAL( "Error calling TrackInfo tool finalize ");
224 return StatusCode::FAILURE;
225 }
226
227 return StatusCode::SUCCESS;
228}
229
231{
232 ATH_MSG_INFO( "entering streamOutCalibObjects " );
233 StatusCode sc = m_streamer->connectOutput();
234 if (sc.isFailure()) {
235 ATH_MSG_ERROR("Could not connect stream to output");
236 return( StatusCode::FAILURE);
237 }
238
242
243 sc = m_streamer->streamObjects(typeKeys);
244 if (sc.isFailure()) {
245 ATH_MSG_ERROR("Could not stream out Containers ");
246 return( StatusCode::FAILURE);
247 }
248
249 sc = m_streamer->commitOutput();
250 if (sc.isFailure()) {
251 ATH_MSG_ERROR("Could not commit output stream");
252 return( StatusCode::FAILURE);
253 }
254
255 ATH_MSG_INFO( " Streamed out and committed " << typeKeys.size() << " objects " );
256 return StatusCode::SUCCESS;
257}
258
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
Handle class for reading from StoreGate.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
std::pair< std::string, std::string > TypeKeyPair
Stream out objects.
std::vector< TypeKeyPair > TypeKeyPairs
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
ToolHandle< Trk::ITrackSelectorTool > m_trackSelector
ToolHandleArray< IFitTool > m_FitTools
PublicToolHandleArray< ITRTCalibrator > m_TRTCalibTools
Gaudi::Property< std::string > m_par_t0containerkey
Gaudi::Property< bool > m_docalibrate
virtual StatusCode initialize(void) override
ToolHandleArray< IFillAlignTrkInfo > m_TrackInfoTools
Gaudi::Property< std::string > m_par_rtcontainerkey
ToolHandle< Trk::ITrackFitter > m_trackFitter
virtual StatusCode finalize(void) override
TRTCalibrationMgr(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< unsigned int > m_max_ntrk
virtual StatusCode execute(void) override
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
SG::ReadHandleKey< xAOD::VertexContainer > m_verticesKey
Gaudi::Property< bool > m_writeConstants
Gaudi::Property< bool > m_dorefit
ToolHandle< IAthenaOutputStreamTool > m_streamer
SG::ReadHandleKey< TrackCollection > m_TrkCollection
StatusCode streamOutCalibObjects()
static const char * classname()
classname used to talk to iovservice
static const char * classname()
classname used to talk to iovservice
ParticleHypothesis particleHypothesis() const
Returns the particle hypothesis used for Track fitting.
const TrackInfo & info() const
Returns a const ref to info of a const tracks.
bool RunOutlierRemoval
switch to toggle quality processing after fit
Definition FitterTypes.h:22
@ PriVtx
Primary vertex.
Vertex_v1 Vertex
Define the latest version of the vertex class.
void fill(H5::Group &out_file, size_t iterations)