 |
ATLAS Offline Software
|
Go to the documentation of this file.
11 #include <Acts/Utilities/Enumerate.hpp>
13 #include <Acts/Utilities/Enumerate.hpp>
18 using namespace SegmentFit;
19 using namespace SegmentFitHelpers;
23 return std::visit([](
const auto&
cov) ->
double{
28 return cutRange[0] <=
value &&
value <= cutRange[1];
39 ostr<<
"two circle solution with ";
41 ostr<<
"y0: "<<Y0<<
" pm "<<dY0;
50 const Config& configuration):
53 m_segmentSeed{segmentSeed} {
55 if (m_hitLayers.mdtHits().empty())
return;
57 if (std::ranges::find_if(m_hitLayers.mdtHits(), [
this](
const HitVec&
vec){
58 return vec.size() > m_cfg.busyLayerLimit;
59 }) != m_hitLayers.mdtHits().end()) {
60 m_cfg.startWithPattern =
false;
63 m_upperLayer = m_hitLayers.mdtHits().size()-1;
66 while (m_lowerLayer < m_upperLayer && m_hitLayers.mdtHits()[m_lowerLayer].size() >m_cfg.busyLayerLimit){
70 while (m_lowerLayer < m_upperLayer && m_hitLayers.mdtHits()[m_upperLayer].size() > m_cfg.busyLayerLimit) {
75 std::stringstream sstr{};
76 for (
const auto [layCount,
layer] : Acts::enumerate(m_hitLayers.mdtHits())) {
77 sstr<<
"Mdt-hits in layer "<<layCount<<
": "<<
layer.size()<<std::endl;
79 sstr<<
" **** "<<hit->msSector()->idHelperSvc()->toString(hit->identify())<<
" "
80 <<
Amg::toString(hit->positionInChamber())<<
", driftRadius: "<<hit->driftRadius()<<std::endl;
83 for (
const auto [layCount,
layer] : Acts::enumerate(m_hitLayers.stripHits())) {
84 sstr<<
"Hits in layer "<<layCount<<
": "<<
layer.size()<<std::endl;
86 sstr<<
" **** "<<hit->msSector()->idHelperSvc()->toString(hit->identify())<<
" "
87 <<
Amg::toString(hit->positionInChamber())<<
", driftRadius: "<<hit->driftRadius()<<std::endl;
90 ATH_MSG_VERBOSE(
"SeedGenerator - sorting of hits done. Mdt layers: "<<m_hitLayers.mdtHits().size()
91 <<
", strip layers: "<<m_hitLayers.stripHits().size()<<std::endl<<sstr.str()<<std::endl<<std::endl);
135 std::optional<MdtSegmentSeedGenerator::DriftCircleSeed>
137 std::optional<DriftCircleSeed>
found = std::nullopt;
140 found = std::make_optional<DriftCircleSeed>();
149 return hit->type() == xAOD::UncalibMeasType::MdtDriftCircleType;
178 std::optional<MdtSegmentSeedGenerator::DriftCircleSeed>
194 const auto&[signTop, signBot] = signs;
200 const double thetaTubes = std::atan2(D.y(), D.z());
201 const double distTubes = std::hypot(D.y(), D.z());
203 <<
", driftRadius: "<<bottomHit->
driftRadius()<<
" - top tube "<<idHelperSvc->toString(topHit->
identify())
210 double theta{thetaTubes - std::asin(std::clamp(R / distTubes, -1., 1.))};
212 double Y0 = bottomPos.y()*seedDir.z() - bottomPos.z()*seedDir.y() + signBot*bottomHit->
driftRadius();
213 double combDriftUncert{std::sqrt(bottomPrd->driftRadiusCov() + topPrd->driftRadiusCov())};
214 std::unique_ptr<CalibratedSpacePoint> calibBottom{}, calibTop{};
220 const auto [linePos, lineDir] =
makeLine(candidateSeed.parameters);
225 R = signBot * calibBottom->driftRadius() - signTop * calibTop->driftRadius();
227 theta = thetaTubes - std::asin(std::clamp(R / distTubes, -1., 1.));
229 Y0 = bottomPos.y()*seedDir.z() - bottomPos.z()*seedDir.y() + signBot*bottomHit->
driftRadius();
241 const Amg::Vector3D seedPos = Y0 / seedDir.z() * Amg::Vector3D::UnitY();
243 assert(std::abs(topPos.y()*seedDir.z() - topPos.z() * seedDir.y() + signTop*topHit->
driftRadius() - Y0) < std::numeric_limits<float>::epsilon() );
244 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
": Candidate seed theta: "<<theta<<
", tanTheta: "<<(seedDir.y() / seedDir.z())<<
", y0: "<<Y0/seedDir.z());
248 solCandidate.theta = theta;
250 const double denomSquare = 1. -
std::pow(R / distTubes, 2);
251 if (denomSquare < std::numeric_limits<double>::epsilon()){
255 solCandidate.dTheta = combDriftUncert / std::sqrt(denomSquare) / distTubes;
256 solCandidate.dY0 = std::hypot(-bottomPos.y()*seedDir.y() + bottomPos.z()*seedDir.z(), 1.) * solCandidate.dTheta;
262 const double deltaY = std::abs(seen.
Y0 - solCandidate.Y0);
263 const double limitY = std::hypot(seen.
dY0, solCandidate.dY0);
264 const double dTheta = std::abs(seen.
theta - solCandidate.theta);
265 const double limitTh = std::hypot(seen.
dTheta, solCandidate.dTheta);
268 <<
std::format(
" delta theta: {:.2f} {:} {:.2f}", dTheta, dTheta < limitTh ?
'<' :
'>', limitTh) );
269 return deltaY < limitY && dTheta < limitTh;;
271 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
": Reject due to similarity");
276 ATH_MSG_VERBOSE( __func__<<
"() "<<__LINE__<<
": "<<hitsInLayer.size()<<
" hits in layer "<<(layerNr +1));
277 bool hadGoodHit{
false};
280 testMe->directionInChamber()));
281 const auto*
re =
static_cast<const xAOD::MdtDriftCircle*
>(testMe->primaryMeasurement())->readoutElement();
284 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
": Test hit "<<idHelperSvc->toString(testMe->identify())
288 solCandidate.seedHits.emplace_back(testMe);
291 else if (hadGoodHit) {
299 if (1.*candidateSeed.nMdt < hitCut) {
300 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
": Too few hits associated "<<candidateSeed.nMdt<<
", expect: "<<hitCut<<
" hits.");
305 solCandidate.solutionSigns =
driftSigns(seedPos, seedDir, solCandidate.seedHits,
msg());
306 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
": Circle solutions for seed "
307 <<idHelperSvc->toStringChamber(bottomHit->
identify())<<
" - "<<solCandidate);
311 unsigned int nOverlap{0};
313 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
": Test seed against accepted "<<accepted<<
", updated signs: "<<corridor);
315 for (
unsigned int l = 0;
l < accepted.
seedHits.size(); ++
l){
320 if (nOverlap == corridor.size() && accepted.
seedHits.size() >= solCandidate.seedHits.size()) {
321 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
": Same set of hits collected within the same corridor");
330 if (hit == bottomHit && calibBottom) {
331 candidateSeed.measurements.emplace_back(std::move(calibBottom));
335 else if (hit == topHit && calibTop) {
336 candidateSeed.measurements.emplace_back(std::move(calibTop));
349 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
": In event "<<ctx.eventID().event_number()<<
" found new seed solution "<<
toString(candidateSeed.parameters));
367 const auto [seedPos, seedDir] =
makeLine(candidateSeed.parameters);
373 / testMe->dimension();
374 ATH_MSG_VERBOSE(__func__<<
"() "<<__LINE__<<
": Test hit "<<idHelperSvc->toString(testMe->identify())
377 if (
pull <= bestPull) {
388 return candidateSeed;
400 aux.invCovs.reserve(seed.measurements.size());
401 aux.driftSigns.reserve(seed.measurements.size());
404 for (
const std::unique_ptr<CalibratedSpacePoint>& hit : seed.measurements) {
405 const double invCov = 1./
driftCov(*hit);
407 const int sign =
y0 -
pos.y() * seedDir.z() +
pos.z()* seedDir.y() > 0 ? 1 : -1;
409 aux.centerOfGrav+= invCov *
pos;
410 aux.invCovs.push_back(invCov);
411 aux.driftSigns.push_back(
sign);
416 aux.covNorm = 1./
norm;
417 aux.centerOfGrav *= aux.covNorm;
419 for (
const auto [covIdx, hit] : Acts::enumerate(seed.measurements)) {
420 const double& invCov = aux.invCovs[covIdx];
421 const int&
sign = aux.driftSigns[covIdx];
423 const double signedCov = invCov *
sign;
425 aux.T_yz += invCov *
pos.y()*
pos.z();
426 aux.T_rz += signedCov *
pos.z() * hit->driftRadius();
427 aux.T_ry += signedCov *
pos.y() * hit->driftRadius();
428 aux.fitY0 += signedCov * aux.covNorm * hit->driftRadius();
430 ATH_MSG_VERBOSE(
"Estimated T_zzyy: "<<aux.T_zzyy<<
", T_yz: "<<aux.T_yz<<
", T_rz: "<<aux.T_rz
431 <<
", T_ry: "<<aux.T_ry<<
", centre "<<
Amg::toString(aux.centerOfGrav)<<
", y0: "<<aux.fitY0
432 <<
", norm: "<<aux.covNorm<<
"/"<<
norm);
441 const double thetaGuess = std::atan2( 2.*(auxVars.
T_yz - auxVars.
T_rz), auxVars.
T_zzyy) / 2.;
443 ATH_MSG_VERBOSE(
"Start fast fit seed: "<<theta<<
", guess: "<<thetaGuess
449 bool converged{
false};
452 const double thetaPrime = 0.5*auxVars.
T_zzyy *twoTheta.sn - auxVars.
T_yz * twoTheta.cs
453 - auxVars.
T_rz * thetaCS.cs - auxVars.
T_ry * thetaCS.sn;
459 const double thetaTwoPrime = auxVars.
T_zzyy * twoTheta.cs + 2.* auxVars.
T_yz * twoTheta.sn
460 + auxVars.
T_rz * thetaCS.sn - auxVars.
T_ry * thetaCS.cs;
461 const double update = thetaPrime / thetaTwoPrime;
462 ATH_MSG_VERBOSE(
"Fit iteration #"<<inSeed.
nIter<<
" -- theta: "<<theta<<
", thetaPrime: "<<thetaPrime
463 <<
", thetaTwoPrime: "<<thetaTwoPrime<<
" -- "<<
std::format(
"{:.8f}", update)
464 <<
" --> next theta "<<(theta - thetaPrime / thetaTwoPrime));
487 for (
const auto [
idx, hit] : Acts::enumerate(seed.measurements)){
489 const double weight = aux.covNorm * signedCov;
493 aux.fitY0Prime+=
weight * velocity;
494 aux.fitY0TwoPrime+=
weight * acceleration;
496 aux.T_vz += signedCov *
pos.z()*velocity;
497 aux.T_vy += signedCov *
pos.y()*velocity;
498 aux.T_az += signedCov *
pos.z()*acceleration;
499 aux.T_ay += signedCov *
pos.y()*acceleration;
501 aux.R_vr += signedCov * hit->driftRadius() * velocity;
502 aux.R_va += signedCov * hit->driftRadius() * acceleration;
503 aux.R_vv += signedCov * velocity * velocity;
506 <<
", T_az: "<<aux.T_az<<
", T_ay: "<<aux.T_ay<<
" --- R_vr: "<<aux.R_vr
507 <<
", R_va: "<<aux.R_va<<
", R_vv: "<<aux.R_vv<<
" -- Y0^{'}: "<<aux.fitY0Prime
508 <<
", Y0^{''}: "<<aux.fitY0TwoPrime);
517 bool converged{
false};
529 cov(0,0) = auxVars.T_zzyy * twoTheta.cs + 2.* auxVars.T_yz * twoTheta.sn
530 + auxVars.T_rz * thetaCS.sn - auxVars.T_ry * thetaCS.cs;
533 cov(1,1) = - auxVars.fitY0Prime *auxVars.fitY0Prime - auxVars.fitY0Prime * auxVars.fitY0TwoPrime
534 - auxVars.T_az * thetaCS.sn - auxVars.T_ay * thetaCS.cs + auxVars.R_vv + auxVars.R_va;
536 grad[0] =0.5*auxVars.T_zzyy *twoTheta.sn - auxVars.T_yz * twoTheta.cs
537 - auxVars.T_rz * thetaCS.cs - auxVars.T_ry * thetaCS.sn;
538 grad[1] = auxVars.fitY0 * auxVars.fitY0Prime - auxVars.R_vr + auxVars.T_vz * thetaCS.sn - auxVars.T_vy * thetaCS.cs;
543 pars[1]<<
" gradient: ("<<(grad[0])<<
", "<<grad[1]<<
"), covariance:"
545 <<
", "<<update[1]<<
").");
std::size_t m_upperHitIndex
Explicit hit to pick in the selected top layer.
std::vector< int > driftSigns(const Amg::Vector3D &posInChamber, const Amg::Vector3D &dirInChamber, const std::vector< const SpacePoint * > &uncalibHits, MsgStream &msg)
Calculates whether a segment line travereses the tube measurements on the left (-1) or right (1) side...
double fitY0
Prediced y0 given as the expection value of the radii divided by the inverse covariance sum.
double T_rz
Expectation value of T_{z} * r
double dTheta
: Uncertainty on the slope
const SpacePointBucket * parentBucket() const
Returns the bucket out of which the seed was formed.
const MuonGMR4::SpectrometerSector * msSector() const
bool overlapCorridor
Check whether a new seed candidate shares the same left-right solution with already accepted ones Rej...
const HitLayVec & stripHits() const
Returns the sorted strip hits.
unsigned int numGenerated() const
Returns how many seeds have been generated.
SegmentFit::Parameters parameters
Seed parameters.
unsigned int nMdtHitCut
How many drift circle hits needs the seed to contain in order to be valid.
std::array< int, 2 > SignComboType
Sign combinations to draw the 4 lines tangent to 2 drift circles The first two are indicating whether...
unsigned int busyLayerLimit
How many drift circles may be on a layer to be used for seeding.
double T_ry
Expectation value of T_{y} * r
Muon::MdtDriftCircleStatus dcStatus(const SpacePoint &dc)
double tanPhi() const
Returns the angle from the phi extension.
std::vector< int > solutionSigns
Vector of radial signs of the valid hits.
double driftCov(const CalibratedSpacePoint &dcHit)
const Config & config() const
Returns the current seed configuration.
Helper to simultaneously calculate sin and cos of the same angle.
MdtSegmentSeedGenerator(const std::string &name, const SegmentSeed *segmentSeed, const Config &configuration)
Standard constructor taking the segmentSeed to start with and then few configuration tunes.
MdtDriftCircleStatus
Enum to represent the 'status' of Mdt measurements e.g.
Amg::Vector3D positionInChamber() const
Returns the position of the seed in the sector frame.
SpacePointPerLayerSplitter::HitVec HitVec
SeedFitAuxilliaries estimateAuxillaries(const DriftCircleSeed &seed) const
Helper function to estimate the auxillary variables that remain constant during the fit.
Cache of all solutions seen thus far.
bool fastSeedFit
Toggle whether the seed is rapidly refitted.
unsigned int m_nGenSeeds
Counter on how many seeds have been generated.
double nMdtLayHitCut
Hit cut based on the fraction of collected tube layers.
std::vector< size_t > vec
virtual CalibSpacePointPtr calibrate(const EventContext &ctx, const SpacePoint *spacePoint, const Amg::Vector3D &seedPosInChamb, const Amg::Vector3D &seedDirInChamb, const double timeDelay) const =0
Calibrates a single space point.
#define ATH_MSG_VERBOSE(x)
virtual double driftVelocity(const EventContext &ctx, const CalibratedSpacePoint &spacePoint) const =0
Returns the drift velocity for a given drift-circle space point.
bool recalibSeedCircles
Recalibrate the seed drift circles from the initial estimate
std::pair< Amg::Vector3D, Amg::Vector3D > makeLine(const Parameters &pars)
Returns the parsed parameters into an Eigen line parametrization.
std::vector< const SpacePoint * > HitVec
HoughMaximum::HitType HoughHitType
std::string toString(const CalibratedSpacePoint::Covariance_t &mat)
Returns the matrix in string.
@ MdtStatusDriftTime
The tube produced a vaild measurement.
bool startWithPattern
Try at the first time the pattern seed as candidate.
std::size_t m_lowerHitIndex
Explicit hit to pick in the selected bottom layer.
Auxillary struct to calculate fit constants.
const xAOD::UncalibratedMeasurement * primaryMeasurement() const
Amg::Vector3D dirFromTangents(const double tanPhi, const double tanTheta)
Constructs a direction vector from tanPhi & tanTheta.
double T_yz
Expectation value of T_{y} * T_{z}.
Configuration switches of the module
constexpr static std::array< SignComboType, 4 > s_signCombos
bool fastSegFitWithT0
Toggle whether an initial t0 fit shall be executed.
double chiSqTermStrip(const Amg::Vector3D &posInChamber, const Amg::Vector3D &dirInChamber, const SpacePoint &measurement, MsgStream &msg)
Calculates the chi2 contribuation to a linear segment line from an uncalibrated strip measurement.
double theta
: Theta of the line
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
virtual double driftAcceleration(const EventContext &ctx, const CalibratedSpacePoint &spacePoint) const =0
Returns the drift acceleration for a given drift-circle space point.
double tanTheta() const
Returns the angular coordinate of the eta transform.
unsigned int firstLayerFrom2ndMl() const
Returns the layer index with hits from the second multilayer
virtual xAOD::UncalibMeasType type() const =0
Returns the type of the measurement type as a simple enumeration.
double chiSqTermMdt(const Amg::Vector3D &posInChamber, const Amg::Vector3D &dirInChamber, const SpacePoint &measurement, MsgStream &msg)
Calculates the chi2 contribuation to a linear segment line from an uncalibrated Mdt measurement.
std::ostream & print(std::ostream &ostr) const
std::array< double, 2 > thetaRange
Cut on the theta angle.
std::optional< DriftCircleSeed > buildSeed(const EventContext &ctx, const HoughHitType &topHit, const HoughHitType &bottomHit, const SignComboType &signs)
Tries to build the seed from the two hits.
std::size_t m_upperLayer
Considered layer to pick the top drift circle from.
double interceptY() const
Returns the intercept coordinate of the eta transform.
const std::vector< HitType > & getHitsInMax() const
Returns the list of assigned hits.
Class to provide easy MsgStream access and capabilities.
HitVec seedHits
Used hits in the seed.
SpacePointPerLayerSplitter m_hitLayers
std::vector< int > driftSigns
Vector of drfit signs.
double dY0
: Uncertainty on the intercept
double hitPullCut
Upper cut on the hit chi2 w.r.t.
MsgStream & msg() const
The standard message stream.
void fitDriftCirclesWithT0(const EventContext &ctx, DriftCircleSeed &seed) const
Refine the seed by performing a fast Mdt segment fit with t0 constraint.
double T_zzyy
Expectation value of T_{z}^{2} - T_{y}^{2}.
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
~MdtSegmentSeedGenerator()
constexpr double sign(const double x)
Returns the sign of a number.
constexpr bool passRangeCut(const std::array< double, 2 > &cutRange, const double value)
const Muon::IMuonIdHelperSvc * idHelperSvc() const
Returns the IdHelpeSvc.
double error(const Amg::MatrixX &mat, int index)
return diagonal error of the matrix caller should ensure the matrix is symmetric and the index is in ...
constexpr int toInt(const ParamDefs p)
const HitLayVec & mdtHits() const
Returns the sorted Mdt hits.
SpacePointPerLayerSplitter::HitVec HitVec
void moveToNextCandidate()
Prepares the generator to generate the seed from the next pair of drift circles.
unsigned int nIter
Iterations to obtain the seed.
Eigen::Matrix< double, 3, 1 > Vector3D
Amg::Vector3D dirFromAngles(const double phi, const double theta)
Constructs a direction vector from the azimuthal & polar angles.
This header ties the generic definitions in this package.
unsigned int nMaxIter
Maximum number of iterations in the fast segment fit.
const Amg::Vector3D & positionInChamber() const
const SegmentSeed * m_segmentSeed
bool tightenHitCut
Once a seed with even more than initially required hits is found, reject all following seeds with les...
The calibrated Space point is created during the calibration process.
const boost::regex re(r_e)
Representation of a segment seed (a fully processed hough maximum) produced by the hough transform.
std::vector< SeedSolution > m_seenSolutions
Vector caching equivalent solutions to avoid double seeding.
std::array< double, 2 > interceptRange
Cut on the intercept range.
const Parameters & parameters() const
Returns the parameter array.
Helper to simultaneously calculate sin and cos of the same angle.
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Helper struct from a generated Mdt seed.
void fitDriftCircles(DriftCircleSeed &seed) const
Refine the seed by performing a fast Mdt segment fit.
std::size_t m_signComboIndex
Index of the left-right ambiguity between the circles.
double signedDistance(const Amg::Vector3D &posA, const Amg::Vector3D &dirA, const Amg::Vector3D &posB, const Amg::Vector3D &dirB)
Calculates the signed distance between two lines in 3D space.
@ MdtStatusUnDefined
Undefined.
double precCutOff
Precision cut off in the fast segment fit.
double driftRadius() const
: Returns the size of the drift radius
const Covariance_t & covariance() const
Amg::Vector3D directionInChamber() const
Returns the direction of the seed in the sector frame.
https://gitlab.cern.ch/atlas/athena/-/blob/master/MuonSpectrometer/MuonReconstruction/MuonRecEvent/Mu...
const ISpacePointCalibrator * calibrator
Pointer to the space point calibrator.
const AmgSymMatrix(2) &SpacePoint
constexpr int pow(int base, int exp) noexcept
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
std::size_t m_lowerLayer
Considered layer to pick the bottom drift circle from.
const Identifier & identify() const
: Identifier of the primary measurement
Amg::Vector3D centerOfGrav
Tube position center weigthed with inverse covariances.
std::optional< DriftCircleSeed > nextSeed(const EventContext &ctx)
returns the next seed in the row
double Y0
Intersecpt of the line.