113{
115 std::unique_ptr<Trk::PRDtoTrackMap> prd_to_track_map(
m_assoTool->createPRDtoTrackMap());
116 const EventContext& ctx = Gaudi::Hive::currentContext();
117
119 if (!tracks.isValid()) {
121 return StatusCode::FAILURE;
122 }
123
124
126 if (!siHits.isValid()) {
128 return StatusCode::FAILURE;
129 }
130
131
133 if (!sdoCollection.isValid()) {
135 return StatusCode::FAILURE;
136 }
137
138
139 SG::ReadHandle<TrackTruthCollection> truthMap(
m_truthMapName, ctx);
140 if (!truthMap.isValid()) {
142 return StatusCode::FAILURE;
143 }
144
145
146 std::vector<std::unique_ptr<Trk::Track> > newtracks;
147
148
151
152
154 double od0(0);
155 double oz0(0);
156 double ophi0(0);
157 double otheta(0);
158 double oqOverP(0);
159 if (!origPerigee){
161 }
162 else if (
msgLvl(MSG::DEBUG)) {
163 od0 = origPerigee->parameters()[
Trk::d0];
164 oz0 = origPerigee->parameters()[
Trk::z0];
165 ophi0 = origPerigee->parameters()[
Trk::phi0];
166 otheta = origPerigee->parameters()[
Trk::theta];
168 ATH_MSG_DEBUG (
"Original parameters " << od0 <<
" " << oz0 <<
" " << ophi0 <<
" " << otheta <<
" " << oqOverP);
169 }
170
171
172 float minProb(0);
173
174
175 ElementLink<TrackCollection> tracklink;
176 tracklink.
setElement(
const_cast<Trk::Track*
>(*itr));
178 const ElementLink<TrackCollection> tracklink2=tracklink;
179
180 TrackTruthCollection::const_iterator
found = truthMap->find(tracklink2);
181 if ( found == truthMap->end() ) { continue; }
182 if ( !
found->second.particleLink().isValid() ) {
continue; }
183 if (
found->second.probability() < minProb ) {
continue; }
186
187
188 std::vector<const Trk::MeasurementBase*> measurementSet;
189 std::vector<const Trk::MeasurementBase*> trash;
190
191 ATH_MSG_DEBUG (
"Loop over measurementsOnTrack " << (*itr)->measurementsOnTrack()->size() );
192 for (const auto *measurement : *((*itr)->measurementsOnTrack())) {
194
195
196 const Trk::RIO_OnTrack* rio = dynamic_cast <const Trk::RIO_OnTrack*>( measurement );
197 if (rio == nullptr) {
198 ATH_MSG_WARNING(
"Cannot get RIO_OnTrack from measurement. Hit will NOT be included in track fit.");
199 continue;
200 }
201
202
203 const Identifier& surfaceID = (rio->
identify()) ;
205 measurementSet.push_back( measurement );
206 continue;
207 }
208
209
210 const InDet::PixelCluster* pix =
dynamic_cast<const InDet::PixelCluster*
>(rio->
prepRawData());
211 if (pix == nullptr) {
213 continue;
214 }
215
217 const InDetDD::SiDetectorDesign* design =
static_cast<const InDetDD::SiDetectorDesign*
>(&element->
design());
218
219 Identifier clusterId = pix->
identify();
221 int layer_disk =
m_pixelID->layer_disk(clusterId);
222
223
224
226
227
228
229
230
231
232
233 double maxEnergyDeposit(-1);
234 SiHit maxEDepSiHit;
235
236 if ( !hasSDOMatch ) {
238
241 if( matchedSiHits.empty() ) {
242 if( !
m_rejNoiseHits ) { measurementSet.push_back( measurement ); }
243 continue;
244 }
246 for( const auto& siHit : matchedSiHits ) {
247 if (siHit.energyLoss() > maxEnergyDeposit) {
248 maxEnergyDeposit = siHit.energyLoss();
249 maxEDepSiHit = siHit;
250 }
251 }
252 } else {
253 measurementSet.push_back( measurement );
254 continue;
255 }
256 } else {
257
259 if( matchedSiHits.empty() ) {
261 continue;
262 }
263 ATH_MSG_DEBUG (
"N SiHit matching cluster: " << matchedSiHits.size());
264
265
266
267 for( const auto& siHit : matchedSiHits ) {
268 if (siHit.energyLoss() > maxEnergyDeposit) {
269 maxEnergyDeposit = siHit.energyLoss();
270 maxEDepSiHit = siHit;
271 }
272 }
273 }
274
275
276
279
280
281
282
283
284
285 HepGeom::Point3D<double> smearedPosition =
smearTruthPosition( averagePosition, bec, layer_disk, design );
287
290
291 Trk::LocalParameters locpar = element->
hitLocalToLocal(smearedPosition.z(), smearedPosition.y());
293
296
297 InDet::SiWidth pixWidth = pix->
width();
299
300
301
302 if(bec!=0) layer_disk++;
303 if(pixWidth.
phiR()>0) {
307 } else {
309 }
310
315 } else {
317 }
318
320
321 InDet::PixelClusterOnTrack* pcot = new InDet::PixelClusterOnTrack(pix,std::move(locpar),std::move(cov),iH,globPos,
323 false);
324
325 if(pcot) {
326 measurementSet.push_back( pcot);
327 trash.push_back(pcot);
328 } else {
330 }
331
332 }
333
334
335
336 ATH_MSG_DEBUG (
"Fit new tracks with measurementSet : " << measurementSet.size());
337 std::unique_ptr<Trk::Track> newtrack;
338 try {
340 measurementSet,
341 *origPerigee,
344 }
345 catch(const std::exception& e) {
346 ATH_MSG_ERROR (
"Refit Logic Error. No new track. Message: " <<
e.what());
347 newtrack = nullptr;
348 }
349
351
354 else {
355
357 const Trk::Perigee* aMeasPer = newtrack->perigeeParameters();
358 if (aMeasPer==nullptr){
360 } else {
361 double d0 = aMeasPer->parameters()[
Trk::d0];
362 double z0 = aMeasPer->parameters()[
Trk::z0];
367 << (od0-
d0)/od0 <<
" "
368 << (oz0-
z0)/oz0 <<
" "
369 << (ophi0-
phi0)/ophi0 <<
" "
370 << (otheta-
theta)/otheta <<
" "
371 << (oqOverP-
qOverP)/oqOverP );
372 }
373 }
374 }
375
376 if (newtrack) { newtracks.push_back(std::move(newtrack)); }
378
379 }
380
382
383
384 for(const std::unique_ptr<Trk::Track> &new_track : newtracks ) {
386 }
387
389
390 std::unique_ptr<TrackCollection> new_track_collection = std::make_unique<TrackCollection>();
391 new_track_collection->reserve(newtracks.size());
392 for(std::unique_ptr<Trk::Track> &new_track : newtracks ) {
394 new_track_collection->push_back(std::move(new_track));
395 }
396
399
400 ATH_MSG_INFO (
"ReFitTrackWithTruth::execute() completed");
401 return StatusCode::SUCCESS;
402}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
bool msgLvl(const MSG::Level lvl) const
DataModel_detail::const_iterator< DataVector > const_iterator
bool setElement(ElementType element)
Set to point to an element.
bool setStorableObject(BaseConstReference data, bool replace=false, IProxyDict *sg=0)
Set link to point to a new container (storable).
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
virtual IdentifierHash identifyHash() const override final
identifier hash (inline)
HepGeom::Point3D< double > globalPosition(const HepGeom::Point3D< double > &localPos) const
transform a reconstruction local position into a global position (inline):
Amg::Vector2D hitLocalToLocal(double xEta, double xPhi) const
Simulation/Hit local frame to reconstruction local frame.
bool gangedPixel() const
return the flag of this cluster containing a gangedPixel
const InDet::SiWidth & width() const
return width class reference
virtual const InDetDD::SiDetectorElement * detectorElement() const override final
return the detector element corresponding to this PRD The pointer will be zero if the det el is not d...
HepGeom::Point3D< double > localStartPosition() const
HepGeom::Point3D< double > localEndPosition() const
double get(ParamDefs par) const
Retrieve specified parameter (const version).
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
Identifier identify() const
return the identifier
const Amg::MatrixX & localCovariance() const
return const ref to the error matrix
virtual const Trk::PrepRawData * prepRawData() const =0
returns the PrepRawData (also known as RIO) object to which this RIO_OnTrack is associated.
Identifier identify() const
return the identifier -extends MeasurementBase
Gaudi::Property< bool > m_rejNoiseHits
SG::ReadHandleKey< InDetSimDataCollection > m_SDOContainerName
Trk::RunOutlierRemoval m_runOutlier
double getEtaPosErrorFactor(int layer) const
static bool IsClusterFromTruth(const InDet::PixelCluster *pixClus, const int uniqueIdToMatch, const InDetSimDataCollection &sdoCollection)
Gaudi::Property< bool > m_fixWrongHits
SG::ReadHandleKey< TrackTruthCollection > m_truthMapName
const PixelID * m_pixelID
Pixel ID.
std::vector< SiHit > matchSiHitsToCluster(const int uniqueIdToMatch, const InDet::PixelCluster *pixClus, SG::ReadHandle< AtlasHitsVector< SiHit > > &siHitCollection) const
Trk::ParticleHypothesis m_ParticleHypothesis
ToolHandle< Trk::IExtendedTrackSummaryTool > m_trkSummaryTool
the track summary tool
SG::ReadHandleKey< SiHitCollection > m_siHitCollectionName
SG::ReadHandleKey< TrackCollection > m_inputTrackColName
const AtlasDetectorID * m_idHelper
Detector ID helper.
ToolHandle< Trk::IPRDtoTrackMapTool > m_assoTool
Tool to create and populate PRD to track.
double getEtaPosResolution(int layer) const
Gaudi::Property< bool > m_saveWrongHits
double getPhiPosResolution(int layer) const
SG::WriteHandleKey< TrackCollection > m_outputTrackCollectionName
double getPhiPosErrorFactor(int layer) const
HepGeom::Point3D< double > smearTruthPosition(const HepGeom::Point3D< double > &orig, const int bec, const int layer_disk, const InDetDD::SiDetectorDesign *design) const
ToolHandle< Trk::ITrackFitter > m_ITrackFitter
the refit tool
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 3, 1 > Vector3D
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ loc2
generic first and second local coordinate
ParametersBase< TrackParametersDim, Charged > TrackParameters