17 #include "GaudiKernel/TypeNameString.h"
46 ATH_CHECK (m_siHitCollectionName.initialize());
47 ATH_CHECK (m_SDOContainerName.initialize());
51 ATH_CHECK( m_inputTrackColName.initialize() );
53 if (m_ITrackFitter.retrieve().isFailure()) {
54 ATH_MSG_FATAL (
"Failed to retrieve tool "<<m_ITrackFitter.typeAndName());
55 return StatusCode::FAILURE;
57 ATH_MSG_INFO (
"Retrieved general fitter " << m_ITrackFitter.typeAndName());
60 if (m_trkSummaryTool.retrieve().isFailure()) {
61 ATH_MSG_FATAL (
"Failed to retrieve tool " << m_trkSummaryTool);
62 return StatusCode::FAILURE;
64 ATH_MSG_INFO (
"Retrieved tool " << m_trkSummaryTool.typeAndName());
68 if ( m_assoTool.retrieve().isFailure() ) {
70 return StatusCode::FAILURE;
83 return StatusCode::FAILURE;
90 if( m_resolutionRPhi.size() < 4 ) { m_resolutionRPhi={0.,0.,0.,0.}; }
91 if( m_resolutionZ.size() < 4 ) { m_resolutionZ={0.,0.,0.,0.}; }
93 if( m_errorRPhi.size() < 4 ) { m_errorRPhi={1.,1.,1.,1.}; }
94 if( m_errorZ.size() < 4 ) { m_errorZ={1.,1.,1.,1.}; }
96 ATH_MSG_INFO (
" Resolutions " << m_resolutionRPhi.size() <<
" " << m_resolutionZ.size());
97 for(
unsigned int i=0;
i<m_resolutionRPhi.size();
i++) {
98 ATH_MSG_INFO (
" " <<
i <<
" " << m_resolutionRPhi[
i] <<
"\t" << m_resolutionZ[
i]);
100 ATH_MSG_INFO (
" Error SR " << m_errorRPhi.size() <<
" " << m_errorZ.size());
101 for(
unsigned int i=0;
i<m_errorRPhi.size();
i++) {
102 ATH_MSG_INFO (
" " <<
i <<
" " << m_errorRPhi[
i] <<
"\t" << m_errorZ[
i]);
105 ATH_CHECK(m_outputTrackCollectionName.initialize());
106 ATH_MSG_DEBUG(
"m_outputTrackCollectionName: " << m_outputTrackCollectionName);
108 return StatusCode::SUCCESS;
115 std::unique_ptr<Trk::PRDtoTrackMap> prd_to_track_map(m_assoTool->createPRDtoTrackMap());
116 const EventContext& ctx = Gaudi::Hive::currentContext();
121 return StatusCode::FAILURE;
127 ATH_MSG_WARNING(
"Error retrieving SiHitCollection " << m_siHitCollectionName);
128 return StatusCode::FAILURE;
133 if (!sdoCollection.
isValid()) {
134 ATH_MSG_WARNING(
"Error retrieving SDOCollection " << m_SDOContainerName );
135 return StatusCode::FAILURE;
142 return StatusCode::FAILURE;
146 std::vector<std::unique_ptr<Trk::Track> > newtracks;
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);
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; }
188 std::vector<const Trk::MeasurementBase*> measurementSet;
189 std::vector<const Trk::MeasurementBase*> trash;
191 ATH_MSG_DEBUG (
"Loop over measurementsOnTrack " << (*itr)->measurementsOnTrack()->size() );
192 for (
const auto *measurement : *((*itr)->measurementsOnTrack())) {
197 if (rio ==
nullptr) {
198 ATH_MSG_WARNING(
"Cannot get RIO_OnTrack from measurement. Hit will NOT be included in track fit.");
204 if( !m_idHelper->is_pixel(surfaceID) ) {
205 measurementSet.push_back( measurement );
211 if (
pix ==
nullptr) {
220 int bec = m_pixelID->barrel_ec(clusterId);
221 int layer_disk = m_pixelID->layer_disk(clusterId);
225 bool hasSDOMatch = IsClusterFromTruth(
pix, uniqueIdToMatch, *sdoCollection );
233 double maxEnergyDeposit(-1);
236 if ( !hasSDOMatch ) {
239 if (not m_saveWrongHits)
continue;
240 const std::vector<SiHit> matchedSiHits = matchSiHitsToCluster( -999 ,
pix, siHits );
241 if( matchedSiHits.empty() ) {
242 if( !m_rejNoiseHits ) { measurementSet.push_back( measurement ); }
245 if( m_fixWrongHits ) {
246 for(
const auto& siHit : matchedSiHits ) {
247 if (siHit.energyLoss() > maxEnergyDeposit) {
248 maxEnergyDeposit = siHit.energyLoss();
249 maxEDepSiHit = siHit;
253 measurementSet.push_back( measurement );
258 const std::vector<SiHit> matchedSiHits = matchSiHitsToCluster( uniqueIdToMatch,
pix, siHits );
259 if( matchedSiHits.empty() ) {
263 ATH_MSG_DEBUG (
"N SiHit matching cluster: " << matchedSiHits.size());
267 for(
const auto& siHit : matchedSiHits ) {
268 if (siHit.energyLoss() > maxEnergyDeposit) {
269 maxEnergyDeposit = siHit.energyLoss();
270 maxEDepSiHit = siHit;
285 HepGeom::Point3D<double> smearedPosition = smearTruthPosition( averagePosition,
bec, layer_disk, design );
302 if(
bec!=0) layer_disk++;
303 if(pixWidth.
phiR()>0) {
305 error = getPhiPosResolution(layer_disk)*getPhiPosErrorFactor(layer_disk);
313 error = getEtaPosResolution(layer_disk)*getEtaPosErrorFactor(layer_disk);
326 measurementSet.push_back( pcot);
327 trash.push_back(pcot);
336 ATH_MSG_DEBUG (
"Fit new tracks with measurementSet : " << measurementSet.size());
337 std::unique_ptr<Trk::Track> newtrack;
339 newtrack = m_ITrackFitter->fit(ctx,
343 m_ParticleHypothesis);
346 ATH_MSG_ERROR (
"Refit Logic Error. No new track. Message: " <<
e.what());
358 if (aMeasPer==
nullptr){
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 );
376 if (newtrack) { newtracks.push_back(std::move(newtrack)); }
384 for(
const std::unique_ptr<Trk::Track> &new_track : newtracks ) {
385 if((m_assoTool->addPRDs(*prd_to_track_map, *new_track)).isFailure()) {
ATH_MSG_WARNING(
"Failed to add PRDs to map");}
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 ) {
393 m_trkSummaryTool->computeAndReplaceTrackSummary(ctx, *new_track,
false );
394 new_track_collection->
push_back(std::move(new_track));
400 ATH_MSG_INFO (
"ReFitTrackWithTruth::execute() completed");
401 return StatusCode::SUCCESS;
410 ATH_MSG_VERBOSE(
" Have " << (*siHitCollection).size() <<
" SiHits to look through" );
411 std::vector<SiHit> matchingHits;
416 ATH_MSG_WARNING(
"Do not have detector element to find the local position of SiHits!");
423 std::vector<const SiHit* > multiMatchingHits;
426 for (
const auto& siHit : *siHitCollection) {
428 if ( uniqueIdToMatch > 0 ) {
429 if (
HepMC::uniqueID(&(siHit.particleLink())) != uniqueIdToMatch ) {
continue; }
433 if( !siHit.isPixel() ) {
continue; }
436 if( m_pixelID->barrel_ec(clusterId) != siHit.getBarrelEndcap() ) {
continue; }
437 if( m_pixelID->layer_disk(clusterId)!= siHit.getLayerDisk() ) {
continue; }
438 if( m_pixelID->phi_module(clusterId)!= siHit.getPhiModule() ) {
continue; }
439 if( m_pixelID->eta_module(clusterId)!= siHit.getEtaModule() ) {
continue; }
443 multiMatchingHits.push_back(&siHit);
451 ATH_MSG_DEBUG(
"Found " << multiMatchingHits.size() <<
" SiHit " );
456 for ( ; siHitIter != multiMatchingHits.end(); ++siHitIter) {
457 const SiHit* lowestXPos = *siHitIter;
458 const SiHit* highestXPos = *siHitIter;
462 std::vector<const SiHit* > ajoiningHits;
463 ajoiningHits.push_back( *siHitIter );
465 siHitIter2 = siHitIter+1;
466 while ( siHitIter2 != multiMatchingHits.end() ) {
476 if (std::abs((highestXPos->
localEndPosition().x()-(*siHitIter2)->localStartPosition().x()))<0.00005 &&
477 std::abs((highestXPos->
localEndPosition().y()-(*siHitIter2)->localStartPosition().y()))<0.00005 &&
478 std::abs((highestXPos->
localEndPosition().z()-(*siHitIter2)->localStartPosition().z()))<0.00005 )
480 highestXPos = *siHitIter2;
481 ajoiningHits.push_back( *siHitIter2 );
483 siHitIter2 = multiMatchingHits.erase( siHitIter2 );
485 }
else if (std::abs((lowestXPos->
localStartPosition().x()-(*siHitIter2)->localEndPosition().x()))<0.00005 &&
486 std::abs((lowestXPos->
localStartPosition().y()-(*siHitIter2)->localEndPosition().y()))<0.00005 &&
487 std::abs((lowestXPos->
localStartPosition().z()-(*siHitIter2)->localEndPosition().z()))<0.00005)
489 lowestXPos = *siHitIter2;
490 ajoiningHits.push_back( *siHitIter2 );
492 siHitIter2 = multiMatchingHits.erase( siHitIter2 );
499 if( ajoiningHits.empty()){
503 if(ajoiningHits.size() == 1){
505 matchingHits.push_back( *ajoiningHits[0] );
509 ATH_MSG_DEBUG(
"Merging " << ajoiningHits.size() <<
" SiHits together." );
514 for(
auto& siHit : ajoiningHits){
515 energyDep += siHit->energyLoss();
516 time += siHit->meanTime();
518 time /= (
float)ajoiningHits.size();
526 (*siHitIter)->getBarrelEndcap(),
527 (*siHitIter)->getLayerDisk(),
528 (*siHitIter)->getEtaModule(),
529 (*siHitIter)->getPhiModule(),
530 (*siHitIter)->getSide() );
531 ATH_MSG_DEBUG(
"Finished Merging " << ajoiningHits.size() <<
" SiHits together." );
538 const int uniqueIdToMatch,
547 for(
const auto &hitIdentifier : pixClus->
rdoList() ) {
550 auto pos = sdoCollection.find(hitIdentifier);
551 if(
pos == sdoCollection.end() ) {
continue; }
554 for(
const auto& deposit :
pos->second.getdeposits() ){
555 if( !deposit.first ){
continue; }
556 if(
HepMC::uniqueID(&(deposit.first)) != uniqueIdToMatch ) {
continue; }
568 const int layer_disk,
571 HepGeom::Point3D<double> smeared(0,0,0);
573 smeared.setX(orig.x());
576 double smearLocY = m_random->Gaus(0, getPhiPosResolution(layer_disk));
577 double smearLocZ = m_random->Gaus(0, getEtaPosResolution(layer_disk));
578 smeared.setY(orig.y() + smearLocY);
579 smeared.setZ(orig.z() + smearLocZ);
583 smeared.setY(orig.y());
584 smeared.setZ(orig.z());
588 if (smeared.y()>design->
width()/2) {
589 smeared.setY(design->
width()/2-1
e-6);
590 }
else if (smeared.y()<-design->
width()/2) {
591 smeared.setY(-design->
width()/2+1
e-6);
593 if (smeared.z()>design->
length()/2) {
594 smeared.setZ(design->
length()/2-1
e-6);
595 }
else if (smeared.z()<-design->
length()/2) {
596 smeared.setZ(-design->
width()/2+1
e-6);