ATLAS Offline Software
Loading...
Searching...
No Matches
AlignTrackCreator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6#include "GaudiKernel/MsgStream.h"
7
10
12
14#include "TrkTrack/Track.h"
19
24
26
27#include <fstream>
28
29namespace Trk {
30
31 //________________________________________________________________________
32 AlignTrackCreator::AlignTrackCreator(const std::string& type, const std::string& name,
33 const IInterface* parent)
35 , AthAlgTool(type,name,parent)
36 {
37 declareInterface<IAlignTrackCreator>(this);
38 }
39
40 //________________________________________________________________________
42 {
43 // Set up ATLAS ID helper
44 if (detStore()->retrieve(m_idHelper, "AtlasID").isFailure()) {
45 ATH_MSG_ERROR ("Could not get AtlasDetectorID helper" );
46 return StatusCode::FAILURE;
47 }
49
50 if (m_residualCalculator.retrieve().isFailure()) {
51 ATH_MSG_FATAL("Could not get " << m_residualCalculator);
52 return StatusCode::FAILURE;
53 }
54 ATH_MSG_INFO("Retrieved " << m_residualCalculator);
55
56 // get AlignModuleTool
57 if (m_alignModuleTool.retrieve().isFailure()) {
58 ATH_MSG_FATAL("Could not get " << m_alignModuleTool);
59 return StatusCode::FAILURE;
60 }
61 ATH_MSG_INFO("Retrieved " << m_alignModuleTool);
62
63 ATH_MSG_INFO("initialize() successful in " << name());
64
65 return StatusCode::SUCCESS;
66 }
67
68 //________________________________________________________________________
70 {
71 ATH_MSG_DEBUG("finalize() in AlignTrackCreator");
72
73 // write run/evt to ASCII file
74 if (m_writeEventList) {
75 std::ofstream output(m_eventListName.value().c_str());
76 for (std::vector<std::pair<int,int> >::iterator it=
77 m_goodEventList.begin(); it!=m_goodEventList.end(); ++it) {
78 int run=(*it).first;
79 int evt=(*it).second;
80 output << run << " " << evt << std::endl;
81 }
82
83 // if no events, output dummy run and event number so file isn't empty
84 if (m_goodEventList.empty()) output<<"0 0"<<std::endl;
85 output.close();
86 }
87
88 delete m_measTypeIdHelper;
89
90 return StatusCode::SUCCESS;
91 }
92
93 //________________________________________________________________________
95 {
96 DataVector<AlignTSOS>* alignTSOSCollection=new DataVector<AlignTSOS>;
97
98 bool goodtrack = false;
99 int ntsos(0);
100 double chi2(0.);
101
102 AlignModule * lastModule(nullptr);
103 bool overlapTrack(false);
104
105 ATH_MSG_DEBUG("nDoF: "<<at->fitQuality()->numberDoF()<<", tsos size: "<<at->trackStateOnSurfaces()->size());
106
107 for (const TrackStateOnSurface* tsos : *at->trackStateOnSurfaces()) {
108
109 AlignTSOS * atsos(nullptr);
110 AlignModule * module(nullptr);
111
112 if (tsos->type(TrackStateOnSurface::Outlier) ||
113 tsos->type(TrackStateOnSurface::Perigee) ||
114 tsos->type(TrackStateOnSurface::Hole))
115 continue;
116 else if (tsos->type(TrackStateOnSurface::Measurement)) {
117
118 ATH_MSG_DEBUG("checking ntsos: "<<ntsos);
119
120 const MeasurementBase * mesb = tsos->measurementOnTrack();
121 const TrackParameters * tparp = tsos->trackParameters();
122 const RIO_OnTrack * rio = dynamic_cast<const RIO_OnTrack *>(mesb);
123 const CompetingRIOsOnTrack * crio = dynamic_cast<const CompetingRIOsOnTrack *>(mesb);
124
125 if (!rio && crio) rio=&crio->rioOnTrack(0);
126
127 if (rio && tparp) {
128 //get detector type
129 AlignModule::DetectorType detType = m_alignModuleTool->getDetectorType(rio->detectorElement());
130 ATH_MSG_DEBUG("detType: "<<detType);
131
132 // see if track is good track
133 if (detType!=AlignModule::NDetectorTypes) {
134 ATH_MSG_DEBUG("calling findAlignModule");
135 module=m_alignModuleTool->findAlignModule(rio,detType);
136 }
137 if (module) {
138 ATH_MSG_DEBUG("found module");
139 goodtrack=true;
140 if (lastModule && module!=lastModule) {
141 overlapTrack=true;
142 ATH_MSG_DEBUG("have overlap track");
143 }
144 else
145 lastModule=module;
146 }
147 ATH_MSG_DEBUG("module not found");
148
149 // see what kind of TSOS
150 TrackState::MeasurementType measType = m_measTypeIdHelper->defineType(mesb);
151
152 // create AlignTSOS using CompetingRIOsOnTrack or RIO_OnTrack
153 if (crio)
154 atsos = new AlignTSOS(*tsos,module,crio,measType);
155 else
156 atsos = new AlignTSOS(*tsos,module,rio,measType);
157
158 if (module)
159 ATH_MSG_DEBUG("module id "<<module->identify());
160 else
161 ATH_MSG_VERBOSE("no module");
162
163 atsos->setValid(true);
164 }
165 }
166
167 // scatterer with no associated measurement
168 else if (tsos->type(TrackStateOnSurface::Scatterer) && m_includeScatterers) {
169 atsos=new AlignTSOS(*tsos,TrackState::unidentified);
170 atsos->setValid(true);
171 }
172
173 if (!atsos) {
174 continue;
175 }
176
177 if (m_removeATSOSNotInAlignModule && !module) {
178 delete atsos;
179 continue;
180 }
181
182 // set detector specific properties (if needed)
183 m_alignModuleTool->setMeasurementProperties(atsos);
184
185 alignTSOSCollection->push_back(atsos);
186 }
187
188 ATH_MSG_DEBUG("goodtrack="<<goodtrack<<", alignTSOSCollection size: "<<alignTSOSCollection->size());
189
190 if (goodtrack && (!m_requireOverlap||overlapTrack)) {
191
192 // store run/evt number in vector
193 if (m_writeEventList) {
194 const xAOD::EventInfo * eventInfo;
195 StatusCode sc=evtStore()->retrieve(eventInfo);
196 if (sc.isFailure())
197 ATH_MSG_ERROR("Couldn't retrieve event info");
198
199 int run=eventInfo->runNumber();
200 int evt=eventInfo->eventNumber();
201 m_goodEventList.emplace_back(run,evt);
202 }
203
204 // set residuals on ATSOS and get local chi2
205 ATH_MSG_DEBUG("calling setResiduals");
206 chi2=m_residualCalculator->setResiduals(alignTSOSCollection);
207 ATH_MSG_DEBUG("done with setResiduals");
208
209 // check that chi2 from fitter matches local chi2
210 if (std::fabs(chi2-at->fitQuality()->chiSquared())>.01) {
211 ATH_MSG_DEBUG("local chi2: "<<chi2<<", from fit: "<<at->fitQuality()->chiSquared());
212 }
213
214 ATH_MSG_DEBUG("setting alignTrack");
215 at->setAlignTSOSCollection(alignTSOSCollection);
216 at->setChi2(chi2);
217
218 if (msgLvl(MSG::DEBUG)) at->dump(msg());
219
220 return true;
221 }
222
223 ATH_MSG_DEBUG("failed to make AlignTrack");
224 delete alignTSOSCollection;
225 return false;
226 }
227
228} // end namespace
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
static Double_t sc
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
ServiceHandle< StoreGateSvc > & evtStore()
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
MsgStream & msg() const
Derived DataVector<T>.
Definition DataVector.h:795
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
void setValid(bool isvalid)
set and retrieve flag to indicate whether hit valid for alignment
Definition AlignTSOS.h:73
BooleanProperty m_includeScatterers
BooleanProperty m_removeATSOSNotInAlignModule
bool processAlignTrack(AlignTrack *track)
creates AlignTrack containing all TSOS on track
BooleanProperty m_requireOverlap
std::vector< std::pair< int, int > > m_goodEventList
AlignTrackCreator(const std::string &type, const std::string &name, const IInterface *parent)
StringProperty m_eventListName
PublicToolHandle< IAlignModuleTool > m_alignModuleTool
const AtlasDetectorID * m_idHelper
ToolHandle< IAlignResidualCalculator > m_residualCalculator
MeasurementTypeID * m_measTypeIdHelper
BooleanProperty m_writeEventList
void setChi2(double chi2)
Definition AlignTrack.h:166
void setAlignTSOSCollection(AlignTSOSCollection *atsosColl)
sets collection of AlignTSOS
void dump(MsgStream &msg)
dump align track information
Base class for all CompetingRIOsOnTack implementations, extends the common MeasurementBase.
virtual const RIO_OnTrack & rioOnTrack(unsigned int) const =0
returns the RIO_OnTrack (also known as ROT) objects depending on the integer.
int numberDoF() const
returns the number of degrees of freedom of the overall track or vertex fit as integer
Definition FitQuality.h:60
double chiSquared() const
returns the of the overall track fit
Definition FitQuality.h:56
This class is the pure abstract base class for all fittable tracking measurements.
classifies a MeasurementBase into one of the known inherited flavours or one of the detector types fo...
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
virtual const TrkDetElementBase * detectorElement() const =0
returns the detector element, assoicated with the PRD of this class
represents the track state (measurement, material, fit parameters and quality) at a surface.
@ Measurement
This is a measurement, and will at least contain a Trk::MeasurementBase.
@ Perigee
This represents a perigee, and so will contain a Perigee object only.
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
@ Scatterer
This represents a scattering point on the track, and so will contain TrackParameters and MaterialEffe...
@ Hole
A hole on the track - this is defined in the following way.
const Trk::TrackStates * trackStateOnSurfaces() const
return a pointer to a const DataVector of const TrackStateOnSurfaces.
const FitQuality * fitQuality() const
return a pointer to the fit quality const-overload
uint32_t runNumber() const
The current event's run number.
uint64_t eventNumber() const
The current event's event number.
double chi2(TH1 *h0, TH1 *h1)
MeasurementType
enum describing the flavour of MeasurementBase
Ensure that the ATLAS eigen extensions are properly loaded.
ParametersBase< TrackParametersDim, Charged > TrackParameters
Definition run.py:1
EventInfo_v1 EventInfo
Definition of the latest event info version.