ATLAS Offline Software
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"
23 #include "VxVertex/VxContainer.h"
25 #include "TROOT.h"
26 #include "StoreGate/ReadHandle.h"
27 
28 TRTCalibrationMgr::TRTCalibrationMgr(const std::string& name, ISvcLocator* pSvcLocator) :
29  AthAlgorithm (name, pSvcLocator){}
30 
31 //---------------------------------------------------------------------
32 
34 {}
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 
66  if (m_writeConstants){
67  ATH_CHECK(m_streamer.retrieve());
68  }
69 
70 
71  // Initialize ReadHandles and ReadHandleKeys
72  ATH_CHECK(m_verticesKey.initialize());
74  ATH_CHECK(m_TrkCollection.initialize());
75 
76  ATH_MSG_INFO("Tracks from Trk::Track collection:");
77  ATH_MSG_INFO("\n\t" << m_TrkCollection);
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 
115  if (m_writeConstants)
116  {
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
192  TRT::TrackInfo at;
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 
FloatArrayStore.h
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
TRTCalibrationMgr::m_verticesKey
SG::ReadHandleKey< xAOD::VertexContainer > m_verticesKey
Definition: TRTCalibrationMgr.h:97
IAthenaOutputStreamTool::TypeKeyPairs
std::vector< TypeKeyPair > TypeKeyPairs
Definition: IAthenaOutputStreamTool.h:99
covarianceTool.histograms
dictionary histograms
Definition: covarianceTool.py:53
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TRTCalibrationMgr::m_max_ntrk
Gaudi::Property< unsigned int > m_max_ntrk
Definition: TRTCalibrationMgr.h:88
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
TRTCond::RtRelationMultChanContainer::classname
static const char * classname()
classname used to talk to iovservice
Definition: RtRelationMultChanContainer.h:42
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
TRTCalibrationMgr::m_par_rtcontainerkey
Gaudi::Property< std::string > m_par_rtcontainerkey
Definition: TRTCalibrationMgr.h:90
Trk::Track::info
const TrackInfo & info() const
Returns a const ref to info of a const tracks.
TRTCalibrationMgr::m_TRTCalibTools
PublicToolHandleArray< ITRTCalibrator > m_TRTCalibTools
Definition: TRTCalibrationMgr.h:77
TRT::Track::event
@ event
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:74
EventInfo
EventInfo
Definition: EventTPCnv.cxx:47
TRTCalibrationMgr::m_dorefit
Gaudi::Property< bool > m_dorefit
Definition: TRTCalibrationMgr.h:84
TRTCalibrationMgr::m_trackFitter
ToolHandle< Trk::ITrackFitter > m_trackFitter
Definition: TRTCalibrationMgr.h:79
TRTCalibrationMgr::m_TrackInfoTools
ToolHandleArray< IFillAlignTrkInfo > m_TrackInfoTools
Definition: TRTCalibrationMgr.h:76
TRTCalibrationMgr.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
TRTCalibrationMgr::m_par_t0containerkey
Gaudi::Property< std::string > m_par_t0containerkey
Definition: TRTCalibrationMgr.h:91
TRTCalibrationMgr::initialize
virtual StatusCode initialize(void) override
Definition: TRTCalibrationMgr.cxx:38
TRTCalibrationMgr::m_writeConstants
Gaudi::Property< bool > m_writeConstants
Definition: TRTCalibrationMgr.h:86
TRT::TrackInfo
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:83
TRT::Track::run
@ run
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:73
TRTCalibrationMgr::~TRTCalibrationMgr
~TRTCalibrationMgr(void)
Definition: TRTCalibrationMgr.cxx:33
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Trk::RunOutlierRemoval
bool RunOutlierRemoval
switch to toggle quality processing after fit
Definition: FitterTypes.h:22
Track.h
TRTCalibrationMgr::finalize
virtual StatusCode finalize(void) override
Definition: TRTCalibrationMgr.cxx:214
TRTCalibrationMgr::execute
virtual StatusCode execute(void) override
Definition: TRTCalibrationMgr.cxx:100
TrackInfo.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
TRTCalibrationMgr::m_ntrk
int m_ntrk
Definition: TRTCalibrationMgr.h:94
IFitTool.h
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
TrackCollection.h
xAOD::VxType::PriVtx
@ PriVtx
Primary vertex.
Definition: TrackingPrimitives.h:571
IAthenaOutputStreamTool::TypeKeyPair
std::pair< std::string, std::string > TypeKeyPair
Stream out objects.
Definition: IAthenaOutputStreamTool.h:98
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
VxContainer.h
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
EventInfo
This class provides general information about an event. Event information is provided by the accessor...
Definition: EventInfo/EventInfo/EventInfo.h:42
TRTCond::StrawT0MultChanContainer::classname
static const char * classname()
classname used to talk to iovservice
Definition: StrawT0MultChanContainer.h:80
TRTCalibrationMgr::streamOutCalibObjects
StatusCode streamOutCalibObjects()
Definition: TRTCalibrationMgr.cxx:230
TRTCalibrationMgr::m_trackSelector
ToolHandle< Trk::ITrackSelectorTool > m_trackSelector
Definition: TRTCalibrationMgr.h:80
VertexContainer.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
lumiFormat.fill
fill
Definition: lumiFormat.py:111
TRT::Track::trackNumber
@ trackNumber
Definition: InnerDetector/InDetCalibEvent/TRT_CalibData/TRT_CalibData/TrackInfo.h:75
TRTCalibrationMgr::m_EventInfoKey
SG::ReadHandleKey< xAOD::EventInfo > m_EventInfoKey
Definition: TRTCalibrationMgr.h:98
TRTCalibrationMgr::m_TrkCollection
SG::ReadHandleKey< TrackCollection > m_TrkCollection
Definition: TRTCalibrationMgr.h:99
ReadHandle.h
Handle class for reading from StoreGate.
IFillAlignTrkInfo.h
ITrackSelectorTool.h
ITrackFitter.h
TRTCalibrationMgr::m_FitTools
ToolHandleArray< IFitTool > m_FitTools
Definition: TRTCalibrationMgr.h:78
TRTCalibrationMgr::m_docalibrate
Gaudi::Property< bool > m_docalibrate
Definition: TRTCalibrationMgr.h:85
Trk::TrackInfo::particleHypothesis
ParticleHypothesis particleHypothesis() const
Returns the particle hypothesis used for Track fitting.
TRTCalibrationMgr::TRTCalibrationMgr
TRTCalibrationMgr(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TRTCalibrationMgr.cxx:28
TRTCalibrationMgr::m_streamer
ToolHandle< IAthenaOutputStreamTool > m_streamer
Definition: TRTCalibrationMgr.h:81