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());
120 return StatusCode::FAILURE;
127 return StatusCode::FAILURE;
132 if (!sdoCollection.
isValid()) {
134 return StatusCode::FAILURE;
141 return StatusCode::FAILURE;
145 std::vector<std::unique_ptr<Trk::Track> > newtracks;
161 else if (
msgLvl(MSG::DEBUG)) {
162 od0 = origPerigee->parameters()[
Trk::d0];
163 oz0 = origPerigee->parameters()[
Trk::z0];
164 ophi0 = origPerigee->parameters()[
Trk::phi0];
165 otheta = origPerigee->parameters()[
Trk::theta];
167 ATH_MSG_DEBUG (
"Original parameters " << od0 <<
" " << oz0 <<
" " << ophi0 <<
" " << otheta <<
" " << oqOverP);
179 TrackTruthCollection::const_iterator found = truthMap->find(tracklink2);
180 if ( found == truthMap->end() ) {
continue; }
181 if ( !found->second.particleLink().isValid() ) {
continue; }
182 if ( found->second.probability() < minProb ) {
continue; }
183 int uniqueIdToMatch =
HepMC::uniqueID(&(found->second.particleLink()));
187 std::vector<const Trk::MeasurementBase*> measurementSet;
188 std::vector<const Trk::MeasurementBase*> trash;
190 ATH_MSG_DEBUG (
"Loop over measurementsOnTrack " << (*itr)->measurementsOnTrack()->size() );
191 for (
const auto *measurement : *((*itr)->measurementsOnTrack())) {
196 if (rio ==
nullptr) {
197 ATH_MSG_WARNING(
"Cannot get RIO_OnTrack from measurement. Hit will NOT be included in track fit.");
204 measurementSet.push_back( measurement );
210 if (
pix ==
nullptr) {
219 int bec =
m_pixelID->barrel_ec(clusterId);
220 int layer_disk =
m_pixelID->layer_disk(clusterId);
232 double maxEnergyDeposit(-1);
235 if ( !hasSDOMatch ) {
240 if( matchedSiHits.empty() ) {
241 if( !
m_rejNoiseHits ) { measurementSet.push_back( measurement ); }
245 for(
const auto& siHit : matchedSiHits ) {
246 if (siHit.energyLoss() > maxEnergyDeposit) {
247 maxEnergyDeposit = siHit.energyLoss();
248 maxEDepSiHit = siHit;
252 measurementSet.push_back( measurement );
258 if( matchedSiHits.empty() ) {
262 ATH_MSG_DEBUG (
"N SiHit matching cluster: " << matchedSiHits.size());
266 for(
const auto& siHit : matchedSiHits ) {
267 if (siHit.energyLoss() > maxEnergyDeposit) {
268 maxEnergyDeposit = siHit.energyLoss();
269 maxEDepSiHit = siHit;
284 HepGeom::Point3D<double> smearedPosition =
smearTruthPosition( averagePosition, bec, layer_disk, design );
301 if(bec!=0) layer_disk++;
302 if(pixWidth.
phiR()>0) {
325 measurementSet.push_back( pcot);
326 trash.push_back(pcot);
335 ATH_MSG_DEBUG (
"Fit new tracks with measurementSet : " << measurementSet.size());
336 std::unique_ptr<Trk::Track> newtrack;
344 catch(
const std::exception& e) {
345 ATH_MSG_ERROR (
"Refit Logic Error. No new track. Message: " << e.what());
356 const Trk::Perigee* aMeasPer = newtrack->perigeeParameters();
357 if (aMeasPer==
nullptr){
360 double d0 = aMeasPer->parameters()[
Trk::d0];
361 double z0 = aMeasPer->parameters()[
Trk::z0];
366 << (od0-
d0)/od0 <<
" "
367 << (oz0-
z0)/oz0 <<
" "
368 << (ophi0-
phi0)/ophi0 <<
" "
369 << (otheta-
theta)/otheta <<
" "
370 << (oqOverP-
qOverP)/oqOverP );
375 if (newtrack) { newtracks.push_back(std::move(newtrack)); }
383 for(
const std::unique_ptr<Trk::Track> &new_track : newtracks ) {
389 std::unique_ptr<TrackCollection> new_track_collection = std::make_unique<TrackCollection>();
390 new_track_collection->reserve(newtracks.size());
391 for(std::unique_ptr<Trk::Track> &new_track : newtracks ) {
393 new_track_collection->push_back(std::move(new_track));
399 ATH_MSG_INFO (
"ReFitTrackWithTruth::execute() completed");
400 return StatusCode::SUCCESS;
409 ATH_MSG_VERBOSE(
" Have " << (*siHitCollection).size() <<
" SiHits to look through" );
410 std::vector<SiHit> matchingHits;
415 ATH_MSG_WARNING(
"Do not have detector element to find the local position of SiHits!");
422 std::vector<const SiHit* > multiMatchingHits;
425 for (
const auto& siHit : *siHitCollection) {
427 if ( uniqueIdToMatch > 0 ) {
428 if (
HepMC::uniqueID(&(siHit.particleLink())) != uniqueIdToMatch ) {
continue; }
432 if( !siHit.isPixel() ) {
continue; }
435 if(
m_pixelID->barrel_ec(clusterId) != siHit.getBarrelEndcap() ) {
continue; }
436 if(
m_pixelID->layer_disk(clusterId)!= siHit.getLayerDisk() ) {
continue; }
437 if(
m_pixelID->phi_module(clusterId)!= siHit.getPhiModule() ) {
continue; }
438 if(
m_pixelID->eta_module(clusterId)!= siHit.getEtaModule() ) {
continue; }
442 multiMatchingHits.push_back(&siHit);
448 std::vector<const SiHit* >::iterator siHitIter = multiMatchingHits.begin();
449 std::vector<const SiHit* >::iterator siHitIter2 = multiMatchingHits.begin();
450 ATH_MSG_DEBUG(
"Found " << multiMatchingHits.size() <<
" SiHit " );
455 for ( ; siHitIter != multiMatchingHits.end(); ++siHitIter) {
456 const SiHit* lowestXPos = *siHitIter;
457 const SiHit* highestXPos = *siHitIter;
461 std::vector<const SiHit* > ajoiningHits;
462 ajoiningHits.push_back( *siHitIter );
464 siHitIter2 = siHitIter+1;
465 while ( siHitIter2 != multiMatchingHits.end() ) {
475 if (std::abs((highestXPos->
localEndPosition().x()-(*siHitIter2)->localStartPosition().x()))<0.00005 &&
476 std::abs((highestXPos->
localEndPosition().y()-(*siHitIter2)->localStartPosition().y()))<0.00005 &&
477 std::abs((highestXPos->
localEndPosition().z()-(*siHitIter2)->localStartPosition().z()))<0.00005 )
479 highestXPos = *siHitIter2;
480 ajoiningHits.push_back( *siHitIter2 );
482 siHitIter2 = multiMatchingHits.erase( siHitIter2 );
484 }
else if (std::abs((lowestXPos->
localStartPosition().x()-(*siHitIter2)->localEndPosition().x()))<0.00005 &&
485 std::abs((lowestXPos->
localStartPosition().y()-(*siHitIter2)->localEndPosition().y()))<0.00005 &&
486 std::abs((lowestXPos->
localStartPosition().z()-(*siHitIter2)->localEndPosition().z()))<0.00005)
488 lowestXPos = *siHitIter2;
489 ajoiningHits.push_back( *siHitIter2 );
491 siHitIter2 = multiMatchingHits.erase( siHitIter2 );
498 if( ajoiningHits.empty()){
502 if(ajoiningHits.size() == 1){
504 matchingHits.push_back( *ajoiningHits[0] );
508 ATH_MSG_DEBUG(
"Merging " << ajoiningHits.size() <<
" SiHits together." );
513 for(
auto& siHit : ajoiningHits){
514 energyDep += siHit->energyLoss();
515 time += siHit->meanTime();
517 time /= (float)ajoiningHits.size();
525 (*siHitIter)->getBarrelEndcap(),
526 (*siHitIter)->getLayerDisk(),
527 (*siHitIter)->getEtaModule(),
528 (*siHitIter)->getPhiModule(),
529 (*siHitIter)->getSide() );
530 ATH_MSG_DEBUG(
"Finished Merging " << ajoiningHits.size() <<
" SiHits together." );
537 const int uniqueIdToMatch,
546 for(
const auto &hitIdentifier : pixClus->
rdoList() ) {
549 auto pos = sdoCollection.find(hitIdentifier);
550 if( pos == sdoCollection.end() ) {
continue; }
553 for(
const auto& deposit : pos->second.getdeposits() ){
554 if( !deposit.first ){
continue; }
555 if(
HepMC::uniqueID(&(deposit.first)) != uniqueIdToMatch ) {
continue; }
567 const int layer_disk,
570 HepGeom::Point3D<double> smeared(0,0,0);
572 smeared.setX(orig.x());
577 smeared.setY(orig.y() + smearLocY);
578 smeared.setZ(orig.z() + smearLocZ);
582 smeared.setY(orig.y());
583 smeared.setZ(orig.z());
587 if (smeared.y()>design->
width()/2) {
588 smeared.setY(design->
width()/2-1e-6);
589 }
else if (smeared.y()<-design->
width()/2) {
590 smeared.setY(-design->
width()/2+1e-6);
592 if (smeared.z()>design->
length()/2) {
593 smeared.setZ(design->
length()/2-1e-6);
594 }
else if (smeared.z()<-design->
length()/2) {
595 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.
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 link to point to an Element (slowest).
bool setStorableObject(BaseConstReference data, bool replace=false)
Set link storable to data object pointed by data (slower).
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
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
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
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