17#include "GaudiKernel/TypeNameString.h"
55 return StatusCode::FAILURE;
62 return StatusCode::FAILURE;
70 return StatusCode::FAILURE;
83 return StatusCode::FAILURE;
101 for(
unsigned int i=0; i<
m_errorRPhi.size(); i++) {
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;
128 return StatusCode::FAILURE;
133 if (!sdoCollection.
isValid()) {
135 return StatusCode::FAILURE;
142 return StatusCode::FAILURE;
146 std::vector<std::unique_ptr<Trk::Track> > newtracks;
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);
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; }
184 int uniqueIdToMatch =
HepMC::uniqueID(&(found->second.particleLink()));
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.");
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);
233 double maxEnergyDeposit(-1);
236 if ( !hasSDOMatch ) {
241 if( matchedSiHits.empty() ) {
242 if( !
m_rejNoiseHits ) { measurementSet.push_back( measurement ); }
246 for(
const auto& siHit : matchedSiHits ) {
247 if (siHit.energyLoss() > maxEnergyDeposit) {
248 maxEnergyDeposit = siHit.energyLoss();
249 maxEDepSiHit = siHit;
253 measurementSet.push_back( measurement );
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) {
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;
345 catch(
const std::exception& e) {
346 ATH_MSG_ERROR (
"Refit Logic Error. No new track. Message: " << e.what());
357 const Trk::Perigee* aMeasPer = newtrack->perigeeParameters();
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 ) {
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));
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);
449 std::vector<const SiHit* >::iterator siHitIter = multiMatchingHits.begin();
450 std::vector<const SiHit* >::iterator siHitIter2 = multiMatchingHits.begin();
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());
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-1e-6);
590 }
else if (smeared.y()<-design->
width()/2) {
591 smeared.setY(-design->
width()/2+1e-6);
593 if (smeared.z()>design->
length()/2) {
594 smeared.setZ(design->
length()/2-1e-6);
595 }
else if (smeared.z()<-design->
length()/2) {
596 smeared.setZ(-design->
width()/2+1e-6);
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
bool msgLvl(const MSG::Level lvl) const
DataModel_detail::const_iterator< DataVector > const_iterator
ElementLink implementation for ROOT usage.
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 double length() const =0
Method to calculate length of a module.
virtual double width() const =0
Method to calculate average width of a module.
Base class for the detector design classes for Pixel and SCT.
Class to hold geometrical description of a silicon detector element.
virtual const SiDetectorDesign & design() const override final
access to the local description (inline):
Class to represent a position in the natural frame of a silicon sensor, for Pixel and SCT For Pixel: ...
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.
Specific class to represent the pixel measurements.
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...
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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 std::vector< Identifier > & rdoList() const
return the List of rdo identifiers (pointers)
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
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
Gaudi::Property< std::vector< float > > m_resolutionRPhi
Gaudi::Property< std::vector< float > > m_resolutionZ
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
boost::thread_specific_ptr< TRandom3 > m_random
smear away!
virtual StatusCode initialize() override
ReFitTrackWithTruth(const std::string &name, ISvcLocator *pSvcLocator)
standard Algorithm constructor
Trk::ParticleHypothesis m_ParticleHypothesis
Gaudi::Property< std::vector< float > > m_errorZ
ToolHandle< Trk::IExtendedTrackSummaryTool > m_trkSummaryTool
the track summary tool
SG::ReadHandleKey< SiHitCollection > m_siHitCollectionName
SG::ReadHandleKey< TrackCollection > m_inputTrackColName
Gaudi::Property< std::vector< float > > m_errorRPhi
virtual StatusCode execute() override
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
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 3, 1 > Vector3D
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ loc2
generic first and second local coordinate
ParametersBase< TrackParametersDim, Charged > TrackParameters