14#include "GaudiKernel/SmartDataPtr.h"
36 const std::string & name,
37 const IInterface * parent)
41 declareInterface<IAlignTrackPreProcessor>(
this);
51 ATH_MSG_INFO(
"BeamspotVertexPreProcessor::initialize()");
65 return StatusCode::FAILURE;
73 return StatusCode::FAILURE;
81 return StatusCode::FAILURE;
89 return StatusCode::FAILURE;
101 ATH_MSG_FATAL(
"Requested BeamSpot track selection but Track Selector not configured");
102 return StatusCode::FAILURE;
106 return StatusCode::FAILURE;
114 ATH_MSG_FATAL(
"Requested beam-spot constraint but RefitTracks is False.");
115 return StatusCode::FAILURE;
121 return StatusCode::FAILURE;
126 ATH_MSG_INFO(
"************************************************************************");
128 ATH_MSG_INFO(
"* You have requested the Full Vertex Constraint option. *");
129 ATH_MSG_INFO(
"* It is your duty to assure that all detector elements *");
130 ATH_MSG_INFO(
"* used for track fitting are also loaded in the alignment framework!!! *");
132 ATH_MSG_INFO(
"* Also make sure the accurate track covariance matrix *");
133 ATH_MSG_INFO(
"* is returned by the GlobalChi2Fitter! *");
135 ATH_MSG_INFO(
"************************************************************************");
139 return StatusCode::SUCCESS;
147 if(!linkToTrackParticle)
return false;
154 if(
m_method.find(
"compareAddress") != std::string::npos){
155 if (
m_track == originalTrk) equal =
true;
159 if(
m_method.find(
"comparePerigee") != std::string::npos){
162 if(! (measPer1 && measPer2 )) equal =
false;
164 float diff = std::abs(std::numeric_limits<float>::epsilon());
165 if( ( std::abs(measPer1->parameters()[
Trk::d0] - measPer2->parameters()[
Trk::d0]) >
diff)
166 || ( std::abs(measPer1->parameters()[
Trk::z0] - measPer2->parameters()[
Trk::z0]) >
diff)
181 ATH_MSG_DEBUG(
"this primary vertex has been rejected as type dummy");
185 ATH_MSG_WARNING(
" VERY STRANGE!!!, this primary vertex has been rejected as non-positive DoF "<< vtx->
numberDoF() <<
" the type of this vertex: "<< vtx->
vertexType() );
199 ATH_MSG_WARNING(
" VERY STRANGE!!! , the updated vertex has been rejected as non-positive DoF: "<< vtx->
numberDoF() <<
" the type of this vertex:"<< vtx->
vertexType() );
208 if ((vtx->covariancePosition())(0,0)<=0 ||
209 (vtx->covariancePosition())(1,1)<=0 ||
210 (vtx->covariancePosition())(2,2)<=0){
211 ATH_MSG_WARNING(
" VERY STRANGE!!! , this updated vertex has been rejected as negative diagonal error matrix ");
220 if(!vertices)
return false;
223 if (vtx->vertexType() != 1)
break;
236 std::vector<VxTrackAtVertex > vertexTracks =
vertex->vxTrackAtVertex();
239 std::vector<VxTrackAtVertex >::const_iterator iVxTrackBegin = vertexTracks.begin();
240 std::vector<VxTrackAtVertex >::const_iterator iVxTrackEnd = vertexTracks.end();
242 std::vector<VxTrackAtVertex>::const_iterator findResult = std::find_if(iVxTrackBegin, iVxTrackEnd, thisCompare);
244 return findResult != iVxTrackEnd;
253 const EventContext& ctx = Gaudi::Hive::currentContext();
258 ATH_MSG_DEBUG(
"this vertex did not pass the primary vertex selection...");
261 if (vtx->vxTrackAtVertexAvailable()){
262 std::vector<VxTrackAtVertex> vtxTracks = vtx->vxTrackAtVertex();
266 ATH_MSG_DEBUG(
"this vertex did not pass the vxTrackAtVertexAvailable() call...");
280 auto iVxTrackBegin = thisPair.second.begin();
281 auto iVxTrackEnd = thisPair.second.end();
284 auto findResult = std::find_if(iVxTrackBegin, iVxTrackEnd, thisCompare);
286 if(findResult != iVxTrackEnd){
288 findVxCandidate = thisPair.first;
293 return findVxCandidate;
299 const EventContext& ctx = Gaudi::Hive::currentContext();
308 if (!(
nullptr==findVtx) ) {
325 ATH_MSG_DEBUG(
" updated Vertex by KalmanVertexUpdator: "<<updatedVtx);
330 const Perigee* perigee =
nullptr;
331 std::unique_ptr<const Trk::TrackParameters> tmp =
335 perigee =
static_cast<const Perigee*
> (tmp.release());
338 const Perigee * trackPerigee = track->perigeeParameters();
340 perigee = trackPerigee->
clone();
345 if (updatedVtx!= tmpVtx)
delete updatedVtx;
357 double ptInv = 1./perigee->
momentum().perp();
358 Jacobian(0,0) = -ptInv*perigee->
momentum().y();
359 Jacobian(0,1) = ptInv*perigee->
momentum().x();
362 ATH_MSG_DEBUG(
" Jacobian matrix from Cartesian to Perigee: "<< Jacobian);
364 AmgSymMatrix(3) vtxCov = updatedVtx->covariancePosition();
371 tmpCov(0,0) = 1.e-10 ;
372 tmpCov(1,1) = 1.e-10;
373 tmpCov(2,2) = 1.e-10;
374 errorMatrix =
Amg::MatrixX( tmpCov.similarity(Jacobian) );
376 errorMatrix =
Amg::MatrixX( vtxCov.similarity(Jacobian) );
384 if (tmpVtx != updatedVtx){
394 vot =
new VertexOnTrack(std::move(localParams), std::move(errorMatrix), surface);
395 ATH_MSG_DEBUG(
"the VertexOnTrack created from vertex: "<<*vot);
406 const EventContext& ctx = Gaudi::Hive::currentContext();
411 float beamSpotX = bpos.x();
412 float beamSpotY = bpos.y();
413 float beamSpotZ = bpos.z();
414 float beamTiltX = beamSpotHandle->beamTilt(0);
415 float beamTiltY = beamSpotHandle->beamTilt(1);
421 float z0 = track->perigeeParameters()->parameters()[
Trk::z0];
422 float beamX = beamSpotX + std::tan(beamTiltX) * (
z0-beamSpotZ);
423 float beamY = beamSpotY + std::tan(beamTiltY) * (
z0-beamSpotZ);
425 ATH_MSG_DEBUG(
"constructing beam point (x,y,z) = ( "<<beamX<<
" , "<<beamY<<
" , "<<
z0<<
" )");
426 std::optional<PerigeeSurface> surface = std::nullopt;
432 beamSpotCov.setZero();
433 beamSpotCov(0,0) = beamSigmaX * beamSigmaX;
434 beamSpotCov(1,1) = beamSigmaY * beamSigmaY;
439 surface.emplace(globPos);
446 const Perigee* perigee =
nullptr;
447 std::unique_ptr<const Trk::TrackParameters> tmp =
451 perigee =
static_cast<const Perigee*
>(tmp.release());
455 const Perigee * trackPerigee = track->perigeeParameters();
457 perigee = trackPerigee->
clone();
464 Eigen::Matrix<double,1,2> jacobian;
467 double ptInv = 1./perigee->
momentum().perp();
468 jacobian(0,0) = -ptInv * perigee->
momentum().y();
469 jacobian(0,1) = ptInv * perigee->
momentum().x();
471 errorMatrix =
Amg::MatrixX( jacobian*(beamSpotCov*jacobian.transpose()));
472 if( errorMatrix.cols() != 1 )
478 std::move(errorMatrix),
484 ATH_MSG_DEBUG(
" the VertexOnTrack objects created from BeamSpot are " << *vot);
496 float beamSpotX = bpos.x();
497 float beamSpotY = bpos.y();
498 float beamSpotZ = bpos.z();
499 float beamTiltX = beamSpotHandle->beamTilt(0);
500 float beamTiltY = beamSpotHandle->beamTilt(1);
505 float z0 = b->originalPosition()->z();
506 (*v)(0) = beamSpotX + std::tan(beamTiltX) * (
z0-beamSpotZ);
507 (*v)(1) = beamSpotY + std::tan(beamTiltY) * (
z0-beamSpotZ);
509 (*q)(0,0) = beamSigmaX*beamSigmaX;
510 (*q)(1,1) = beamSigmaY*beamSigmaY;
511 (*q)(2,2) = beamSigmaZ*beamSigmaZ;
513 ATH_MSG_DEBUG(
"VTX constraint point (x,y,z) = ( "<< (*
v)[0] <<
" , "<< (*
v)[1] <<
" , "<< (*
v)[2] <<
" )");
514 ATH_MSG_DEBUG(
"VTX constraint size (x,y,z) = ( "<< beamSigmaX <<
" , "<< beamSigmaY <<
" , "<< beamSigmaZ <<
" )");
519 ToolHandle<Trk::IGlobalTrackFitter>& fitter,
524 const EventContext& ctx = Gaudi::Hive::currentContext();
525 const Track* newTrack =
nullptr;
529 std::vector<const MeasurementBase *> measurementCollection;
530 measurementCollection.push_back(vot);
532 const auto &measurements = *(track->measurementsOnTrack());
534 measurementCollection.push_back(meas);
539 ATH_MSG_DEBUG(
" Track reference surface will be: " << surface);
543 newTrack = (fitter->
fit(ctx, measurementCollection,
547 newTrack = (fitter->
fit(ctx,
548 measurementCollection, *(track->trackParameters()->front()),
560 bool haveVertex =
false;
565 const EventContext& ctx = Gaudi::Hive::currentContext();
571 vertices = vtxReadHandle.
cptr();
574 ATH_MSG_DEBUG(
"Primary vertex collection for this event has "<<vertices->
size()<<
" vertices");
575 if (vertices->
size()<2){
576 ATH_MSG_DEBUG(
"Only Dummy vertex present, no Primary vertices.");
583 ATH_MSG_DEBUG(
"Could not retrieve primary vertex collection from the StoreGate");
593 const Trk::Perigee* perigee = track->perigeeParameters();
598 const double qoverP = perigee->parameters()[
Trk::qOverP] * 1000.;
601 pt = std::abs(1.0/qoverP)*sin(perigee->parameters()[
Trk::theta]);
607 ATH_MSG_DEBUG(
"this track passes the beamspot track selection, will do beamspot constraint on it ");
617 const Track* newTrack =
nullptr;
635 if( !vot )
ATH_MSG_INFO(
"VoT not found for this track! ");
636 if( !vtx )
ATH_MSG_INFO(
"VTX pointer not found for this track! ");
724 if( (ivtx->originalVertex())==vtx ) {
734 ATH_MSG_DEBUG(
" The Beam Spot constraint will be added to the vertex.." );
738 (qtemp)(2,2) = 1000000.0;
763 ATH_MSG_DEBUG(
"BeamspotVertexPreProcessor::processTrackCollection()");
765 if( !tracks || (tracks->
empty()) )
781 for (
const auto* track : *tracks){
785 if (not track)
continue;
800 alignTrack->
setTrackSummary( std::make_unique<Trk::TrackSummary> (*track->trackSummary()) );
802 if( !(alignTrack->
getVtx()) ) {
811 ATH_MSG_DEBUG(
"No Track refit for track " <<
index <<
" --> building new aligntrack");
817 if (alignTrack) newTrks->
push_back(alignTrack);
820 ATH_MSG_INFO(
"Processing of input track collection completed (size: " << tracks->
size() <<
"). Size of the alignTrack collection: " << newTrks->
size() );
822 if (newTrks->
empty()) {
839 ATH_MSG_DEBUG(
"This alignTrack is not associated to any vertex -> return. ");
847 const std::vector<AlignModuleDerivatives> * ptrDerivs = alignTrack->
derivatives();
850 if (!ptrWeights || !ptrWeightsFD || !ptrResiduals || !ptrDerivs) {
853 if (!ptrWeightsFD)
ATH_MSG_ERROR(
"no weights for first deriv!");
861 std::vector<AlignModuleDerivatives> derivatives = *ptrDerivs;
870 ATH_MSG_DEBUG(
"accumulateVTX: The derivative vector size is " << derivatives.size() );
872 std::vector<const Amg::VectorX*> allDerivatives[3];
874 const int WSize(
weights.cols());
876 std::vector<AlignModuleVertexDerivatives> derivX;
878 for (
const auto& deriv : derivatives) {
885 const std::vector<Amg::VectorX>& deriv_vec = deriv.second;
886 ATH_MSG_VERBOSE(
"accumulateVTX: The deriv_vec size is " << deriv_vec.size() );
888 int nModPars = alignPars->
size();
889 if ((nModPars+3) != std::ssize(deriv_vec)) {
890 ATH_MSG_ERROR(
"accumulateVTX: Derivatives w.r.t. the vertex seem to be missing");
893 for (
int i=0;i<3;i++) {
894 allDerivatives[i].push_back(&deriv_vec[nModPars+i]);
895 for (
int j=0;j<WSize;j++) {
896 F(i,j) = deriv_vec[nModPars+i][j];
904 ATH_MSG_ERROR(
"accumulateVTX: Derivatives do not have a valid pointer to the module.");
911 for (
const auto& deriv : derivatives) {
917 const std::vector<Amg::VectorX>& deriv_vec = deriv.second;
918 std::vector<Amg::VectorX> drdaWF;
920 << deriv_vec.size());
922 int nModPars = alignPars->
size();
923 if ((nModPars + 3) != std::ssize(deriv_vec)) {
925 "accumulateVTX: Derivatives w.r.t. the vertex seem to be missing");
928 drdaWF.reserve(nModPars);
929 for (
int i = 0; i < nModPars; i++) {
930 drdaWF.emplace_back(2.0 * WF * deriv_vec[i]);
932 ATH_MSG_DEBUG(
"accumulateVTX: derivX incremented by: " << drdaWF);
934 derivX.emplace_back(module,std::move(drdaWF));
937 ATH_MSG_ERROR(
"accumulateVTX: Derivatives do not have a valid pointer to the module.");
943 int nmodules = allDerivatives[0].size();
944 ATH_MSG_DEBUG(
"accumulateVTX: allDerivatives size is " << nmodules);
945 for(
int ii=0; ii<3; ++ii ) {
946 VTXDerivatives[ii] = (*(allDerivatives[ii])[0]);
947 for(
int jj=1; jj<nmodules; ++jj ) {
948 VTXDerivatives[ii] += (*(allDerivatives[ii])[jj]);
958 for (
int ipar=0;ipar<3;ipar++) {
961 Amg::MatrixX derivativesT = (VTXDerivatives[ipar]).transpose();
962 ATH_MSG_DEBUG(
"derivativesT (size "<<derivativesT.cols()<<
"): "<<derivativesT);
965 vtxV[ipar] = tempV(0,0);
967 for (
int jpar=ipar;jpar<3;jpar++) {
973 vtxM(ipar,jpar) = tempM(0,0);
995 if( ivtx->Ntracks()>1 ) {
998 ATH_MSG_WARNING(
"This vertex contains " << ivtx->Ntracks() <<
" tracks. No solution possible.");
1001 ATH_MSG_DEBUG(
"This vertex contains " << ivtx->Ntracks() <<
" tracks.");
1002 if(
msgLvl(MSG::DEBUG) ) ivtx->dump(
msg(MSG::DEBUG));
1012 *
m_logStream<<
"*************************************************************"<<std::endl;
1013 *
m_logStream<<
"****** BeamspotVertexPreProcessor summary ******"<<std::endl;
1017 *
m_logStream<<
"* --------------------------------------------"<<std::endl;
1034 ATH_MSG_INFO(
"BeamspotVertexPreProcessor::finalize()");
1036 return StatusCode::SUCCESS;
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
An STL vector of pointers that by default owns its pointed-to elements.
#define AmgSymMatrix(dim)
#define AmgMatrix(rows, cols)
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
bool msgLvl(const MSG::Level lvl) const
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.
bool empty() const noexcept
Returns true if the collection is empty.
ElementConstPointer cptr() const
Return a pointer to the referenced element.
bool fit(const LArSamples::AbsShape &data, const AbsShape &reference, double &k, double &deltaT, double &chi2, const ScaledErrorData *sed=0) const
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
const std::vector< AlignModuleDerivatives > * derivatives() const
The Amg::VectorX is a vector of first-derivatives of the alignTSOS on the alignTrack w....
void setOriginalTrack(const Track *track)
set pointer to original track
@ NTrackTypes
total number of track types
@ NormalRefitted
normally refitted, without adding any pseudo-measurement
@ Original
not refitted, just copy constructed from original Track
@ BeamspotConstrained
refitted with beamspot constraint
@ VertexConstrained
refitted with vertex constraint
const Amg::VectorX * residualVector() const
Vector of residuals of the alignTSOS on the alignTrack, to be set by AlignTrackDresser.
static void dumpLessTrackInfo(const Track &track, MsgStream &msg)
dump less track information
void doFindPerigee() const
For the AlignTrack, if there is pseudo-measurement in the TSOS collection, the perigee will not alway...
void setType(AlignTrackType type)
const Amg::SymMatrixX * weightMatrixFirstDeriv() const
First deriv weight matrix can be either W from Si alignment (see Eqn.
void setDerivativeMatrix(const Amg::MatrixX *matrix)
const AlignVertex * getVtx() const
set and get pointer to the associated vertex
const Amg::SymMatrixX * weightMatrix() const
Weight matrix is W from Si alignment (see Eqn.
void setFullCovarianceMatrix(const Amg::SymMatrixX *matrix)
bool isSLTrack() const
method to determine whether a straight line track or not
void addDerivatives(std::vector< AlignModuleVertexDerivatives > *vec)
void incrementMatrix(const AmgSymMatrix(3) vtxM)
void setConstraint(AmgSymMatrix(3) *, Amg::Vector3D *)
set and get the constraint on VTX position
void incrementVector(const Amg::Vector3D &vtxV)
increment algebra objects for this verterx:
bool doBeamspotConstraintTrackSelection(const Track *track)
PublicToolHandle< IAlignModuleTool > m_alignModuleTool
Pointer to AlignModuleTool.
IntegerProperty m_minTrksInVtx
SG::ReadHandleKey< xAOD::VertexContainer > m_PVContainerName
void accumulateVTX(AlignTrack *alignTrack) override
methods added for the full VTX fit:
BooleanProperty m_doTrkSelection
const VertexOnTrack * provideVotFromVertex(const Track *track, const xAOD::Vertex *&vtx) const
bool selectVertices(const xAOD::Vertex *vtx) const
virtual ~BeamspotVertexPreProcessor()
DoubleProperty m_BSScalingFactor
BooleanProperty m_doNormalRefit
BooleanProperty m_storeFitMatrices
BooleanProperty m_doFullVertexConstraint
bool isAssociatedToVertex(const Track *track, const xAOD::Vertex *vertex)
std::vector< int > m_trackTypeCounter
ToolHandle< InDet::IInDetTrackSelectionTool > m_trkSelector
bool isAssociatedToPV(const Track *track, const xAOD::VertexContainer *vertices)
ToolHandle< IGlobalTrackFitter > m_trackFitter
int m_nFailedNormalRefits
void prepareAllTracksVector()
const xAOD::Vertex * findVertexCandidate(const Track *track) const
AlignTrack * doTrackRefit(const Track *track)
virtual DataVector< Track > * processTrackCollection(const DataVector< Track > *trks) override
Main processing of track collection.
IntegerProperty m_particleNumber
void provideVtxBeamspot(const AlignVertex *b, AmgSymMatrix(3) *q, Amg::Vector3D *v) const
UnsignedIntegerProperty m_constraintMode
ToolHandle< IExtrapolator > m_extrapolator
DataVector< AlignVertex > m_AlignVertices
collection of AlignVertices used in FullVertex constraint option
std::vector< std::pair< const xAOD::Vertex *, std::vector< VxTrackAtVertex > > > m_allTracksVector
DoubleProperty m_PVScalingFactor
const Track * doConstraintRefit(ToolHandle< IGlobalTrackFitter > &fitter, const Track *track, const VertexOnTrack *vot, const ParticleHypothesis &particleHypothesis) const
BooleanProperty m_useSingleFitter
virtual StatusCode finalize() override
BooleanProperty m_runOutlierRemoval
ToolHandle< IGlobalTrackFitter > m_SLTrackFitter
virtual StatusCode initialize() override
SG::ReadCondHandleKey< InDet::BeamSpotData > m_beamSpotKey
ToolHandle< InDet::IInDetTrackSelectionTool > m_BSTrackSelector
ToolHandle< ITrackToVertexIPEstimator > m_trackToVertexIPEstimatorTool
BooleanProperty m_refitTracks
BooleanProperty m_doBeamspotConstraint
BooleanProperty m_doBSTrackSelection
virtual void printSummary() override
Print processing summary to logfile.
bool selectUpdatedVertices(const xAOD::Vertex *updatedVtx) const
BooleanProperty m_doPrimaryVertexConstraint
BeamspotVertexPreProcessor(const std::string &type, const std::string &name, const IInterface *parent)
const VertexOnTrack * provideVotFromBeamspot(const Track *track) const
BooleanProperty m_doAssociatedToPVSelection
bool operator()(VxTrackAtVertex vtxTrk)
std::ostream * m_logStream
logfile output stream
An abstract class which is meant to represent an element link to the Trk::Track or Trk::TrackParticle...
This class is the pure abstract base class for all fittable tracking measurements.
const Amg::Vector3D & momentum() const
Access method for the momentum.
virtual ParametersT< DIM, T, S > * clone() const override final
Virtual clone.
virtual const S & associatedSurface() const override final
Access to the Surface method.
Class describing the Line to which the Perigee refers to.
const Track * originalTrack() const
Return pointer to associated track.
void setTrackSummary(std::unique_ptr< Trk::TrackSummary > input)
Set the track summary.
const Perigee * perigeeParameters() const
return Perigee.
Class to handle Vertex On Tracks, it inherits from the common MeasurementBase.
virtual const PerigeeSurface & associatedSurface() const override final
returns the surface for the local to global transformation
The VxTrackAtVertex is a common class for all present TrkVertexFitters The VxTrackAtVertex is designe...
const ITrackLink * trackOrParticleLink(void) const
float numberDoF() const
Returns the number of degrees of freedom of the vertex fit as float.
VxType::VertexType vertexType() const
The type of the vertex.
std::vector< Trk::VxTrackAtVertex > & vxTrackAtVertex()
Non-const access to the VxTrackAtVertex vector.
const Amg::Vector3D & position() const
Returns the 3-pos.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Eigen::Matrix< double, 2, 1 > Vector2D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Matrix< double, Eigen::Dynamic, 1 > VectorX
Dynamic Vector - dynamic allocation.
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Ensure that the ATLAS eigen extensions are properly loaded.
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ u
Enums for curvilinear frames.
std::pair< double, ParamDefs > DefinedParameter
Typedef to of a std::pair<double, ParamDefs> to identify a passed-through double as a specific type o...
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.
ParametersBase< TrackParametersDim, Charged > TrackParameters
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
Amg::MatrixX * m_derivMatrix
access to the matrix of derivatives used during the latest global-chi2 track fit.
Amg::MatrixX * m_fullCovarianceMatrix
access to the global fitter's full covariance matrix.