Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
CombinatorialSeedSolver.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef MUONR4__MUONPATTERNHELPERS_COMBINATORIALSEEDSOLVER__H
6 #define MUONR4__MUONPATTERNHELPERS_COMBINATORIALSEEDSOLVER__H
7 
10 
11 #include<iostream>
12 #include <ranges>
13 #include <vector>
14 #include <concepts>
15 
16 namespace MuonR4{
17 
18  namespace CombinatorialSeedSolver{
19 
20 
21  //solve the layers equation to define the seed (M,DM) with the combinatoric hits
22  //***The layers equations for the four layers (Si,Di) can be */
23  // S1 + lamda*D1 = M
24  // S2 + alpha*D2 = M + A*Dm
25  // S3 + gamma*D3 = M + G*Dm
26  // S4 + kappa*D4 = M + K*Dm
27  // where {Si,Di} are the position and direction of the strip
28  // {M,Dm} the position and direction of the muon's trajectory on the 1st plane
29  // solving the system we can reduce it to a 2x2 system for kappa and gamma ---> //Johanes' documentation with analytical solution
30  // Bx1*kappa + Bx2*gamma = Y2x
31  // By1*kappa + By2*gamma = Y2y
32 
33  // check if the space points of the container satisfy the require to access to the position and direction in chamber's frame
34  template<typename Container>
35  concept hasPositionAndDirection = requires(typename Container::value_type& v){
36 
37  {v->directionInChamber()}->std::same_as<const Amg::Vector3D&>;
38  {v->positionInChamber()}->std::same_as<const Amg::Vector3D&>;
39 
40  };
41 
42  //check if they are raw pointers
43  template<typename Container>
45  typename Container::value_type;
46  requires std::is_pointer_v<typename Container::value_type>;
47  };
48 
49 
50  // check if the container is valid ( e.g std::array or std::vector)
51  template<typename Container>
53  {c.size()} ->std::same_as<std::size_t>;
54  requires hasPositionAndDirection<Container>;
55 
56  };
57 
58 
59 
64  template<typename spacePointContainer>
65  requires acceptedContainer<spacePointContainer> && hasPointerValues<spacePointContainer>
66  AmgSymMatrix(2) betaMatrix(const spacePointContainer& spacePoints){
67 
68  AmgSymMatrix(2) bMatrix{AmgSymMatrix(2)::Identity()};
69  Amg::Vector3D b1Aterm = (spacePoints[3]->directionInChamber().dot(spacePoints[1]->directionInChamber()))*spacePoints[1]->directionInChamber()-spacePoints[3]->directionInChamber();
70  Amg::Vector3D b1Gterm = (spacePoints[3]->directionInChamber().dot(spacePoints[0]->directionInChamber()))*spacePoints[0]->directionInChamber() - (spacePoints[3]->directionInChamber().dot(spacePoints[1]->directionInChamber()))*spacePoints[1]->directionInChamber();
71 
72  Amg::Vector3D b2Aterm = spacePoints[2]->directionInChamber()- (spacePoints[2]->directionInChamber().dot(spacePoints[1]->directionInChamber()))*spacePoints[1]->directionInChamber();
73  Amg::Vector3D b2Kterm = (spacePoints[2]->directionInChamber().dot(spacePoints[1]->directionInChamber()))*spacePoints[1]->directionInChamber() - (spacePoints[2]->directionInChamber().dot(spacePoints[0]->directionInChamber()))*spacePoints[0]->directionInChamber();
74 
75  //get the distances of the layers along z direction
76  double A = (spacePoints[0]->positionInChamber().z() - spacePoints[1]->positionInChamber().z());
77  double G = (spacePoints[0]->positionInChamber().z() - spacePoints[2]->positionInChamber().z());
78  double K = (spacePoints[0]->positionInChamber().z() - spacePoints[3]->positionInChamber().z());
79 
80  //define B matrix
81  Amg::Vector3D b1 = A*b1Aterm + G*b1Gterm;
82  Amg::Vector3D b2 = K*b2Kterm + A*b2Aterm;
83 
84  bMatrix.col(0) = Amg::Vector2D(b1.x(), b1.y());
85  bMatrix.col(1) = Amg::Vector2D(b2.x(), b2.y());
86 
87  return bMatrix;
88  };
89 
95  template<typename spacePointContainer>
96  requires acceptedContainer<spacePointContainer> && hasPointerValues<spacePointContainer>
97  std::array<double,4> defineParameters(AmgSymMatrix(2) betaMatrix, const spacePointContainer& spacePoints){
98 
99  double A = (spacePoints[0]->positionInChamber().z() - spacePoints[1]->positionInChamber().z());
100  double G = (spacePoints[0]->positionInChamber().z() - spacePoints[2]->positionInChamber().z());
101  double K = (spacePoints[0]->positionInChamber().z() - spacePoints[3]->positionInChamber().z());
102 
103  //Define y2 for the linear system
104  Amg::Vector3D y0 = K*(spacePoints[2]->positionInChamber()- spacePoints[0]->positionInChamber()) + G*(spacePoints[0]->positionInChamber()- spacePoints[3]->positionInChamber());
105  Amg::Vector3D y1 = A*(spacePoints[3]->positionInChamber() - spacePoints[2]->positionInChamber()) + G*(spacePoints[1]->positionInChamber() - spacePoints[3]->positionInChamber()) + K*(spacePoints[2]->positionInChamber()-spacePoints[1]->positionInChamber());
106  Amg::Vector3D y2 = (K-G)*(spacePoints[0]->positionInChamber()- spacePoints[1]->positionInChamber()) - (y1.dot(spacePoints[1]->directionInChamber()))*spacePoints[1]->directionInChamber() + (y0.dot(spacePoints[0]->directionInChamber()))*spacePoints[0]->directionInChamber() +A*(spacePoints[3]->positionInChamber()- spacePoints[2]->positionInChamber());
107 
108  Amg::Vector2D solution = betaMatrix.inverse()*y2.block<2,1>(0,0);
109  double kappa = solution.x();
110  double gamma = solution.y();
111 
112  double lamda = (y0.dot(spacePoints[0]->directionInChamber()) + K*gamma*(spacePoints[0]->directionInChamber().dot(spacePoints[2]->directionInChamber())) -G*kappa*(spacePoints[0]->directionInChamber().dot(spacePoints[3]->directionInChamber())))/(K-G);
113  double alpha = (y1.dot(spacePoints[1]->directionInChamber())+(A-G)*kappa*spacePoints[3]->directionInChamber().dot(spacePoints[1]->directionInChamber()) + (K-A)*gamma*spacePoints[2]->directionInChamber().dot(spacePoints[1]->directionInChamber()))/(K-G);
114 
115  return std::array<double,4>({lamda,alpha,gamma,kappa});
116 
117  };
118 
119  //Solve the equations for the seed position and direction (M,DM)
125  template<typename spacePointContainer>
126  requires acceptedContainer<spacePointContainer> && hasPointerValues<spacePointContainer>
127  std::pair<Amg::Vector3D, Amg::Vector3D> seedSolution(const spacePointContainer& spacePoints, const std::array<double,4>& parameters){
128 
129  //estimate the seed positionInChamber from the 1st equation of the system of the layer equations
130  Amg::Vector3D seedPosition = spacePoints[0]->positionInChamber() + parameters[0]*spacePoints[0]->directionInChamber();
131 
132  //estimate the seed direction from the 2nd equation of the system of the layer equations
133  Amg::Vector3D seedDirection = ((spacePoints[1]->positionInChamber() + parameters[1]*spacePoints[1]->directionInChamber() - seedPosition)).unit();
134 
135  Amg::Vector3D seedPositionZ0 = seedPosition + Amg::intersect<3>(seedPosition, seedDirection, Amg::Vector3D::UnitZ(), 0.).value_or(0.)*seedDirection;
136 
137 
138 
139  return std::make_pair(seedPositionZ0, seedDirection.z() > 0 ? seedDirection : -seedDirection);
140 
141  };
142 
143 
144  };
145 
146 }
147 
148 #endif
add-xsec-uncert-quadrature-N.alpha
alpha
Definition: add-xsec-uncert-quadrature-N.py:110
Amg::Vector2D
Eigen::Matrix< double, 2, 1 > Vector2D
Definition: GeoPrimitives.h:48
MuonR4::CombinatorialSeedSolver::AmgSymMatrix
requires acceptedContainer< spacePointContainer > &&hasPointerValues< spacePointContainer > AmgSymMatrix(2) betaMatrix(const spacePointContainer &spacePoints)
defines the betaMatrix calculated from the combinatoric hits
Definition: CombinatorialSeedSolver.h:66
requires
requires requires()
This specialization is used for classes deriving from DataObject.
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:68
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
makeTRTBarrelCans.y1
tuple y1
Definition: makeTRTBarrelCans.py:15
Container
storage of the time histories of all the cells
MuonR4::CombinatorialSeedSolver::hasPositionAndDirection
concept hasPositionAndDirection
Definition: CombinatorialSeedSolver.h:35
GeoPrimitives.h
A
TrigVtx::gamma
@ gamma
Definition: TrigParticleTable.h:26
xAOD::positionInChamber
Amg::Vector3D positionInChamber(const ActsGeometryContext &gctx, const UncalibratedMeasurement *meas)
Returns the position of the uncalibrated muon measurement in the attached Muon chamber frame.
Definition: MuonSpectrometer/MuonPhaseII/Event/xAOD/xAODMuonPrepData/Root/UtilFunctions.cxx:86
MuonR4::CombinatorialSeedSolver::hasPointerValues
concept hasPointerValues
Definition: CombinatorialSeedSolver.h:44
G
#define G(x, y, z)
Definition: MD5.cxx:113
makeTRTBarrelCans.y2
tuple y2
Definition: makeTRTBarrelCans.py:18
MuonR4::CombinatorialSeedSolver::seedSolution
requires acceptedContainer< spacePointContainer > &&hasPointerValues< spacePointContainer > std::pair< Amg::Vector3D, Amg::Vector3D > seedSolution(const spacePointContainer &spacePoints, const std::array< double, 4 > &parameters)
solves the equation system to calculate the seed
Definition: CombinatorialSeedSolver.h:127
MuonR4::SegmentFit::ParamDefs::y0
@ y0
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
python.PyAthena.v
v
Definition: PyAthena.py:154
MuonR4::CombinatorialSeedSolver::acceptedContainer
concept acceptedContainer
Definition: CombinatorialSeedSolver.h:52
MuonR4::CombinatorialSeedSolver::defineParameters
requires acceptedContainer< spacePointContainer > &&hasPointerValues< spacePointContainer > std::array< double, 4 > defineParameters(AmgSymMatrix(2) betaMatrix, const spacePointContainer &spacePoints)
calculates the parameters lamda,alpha,gamma,kappa of the system
Definition: CombinatorialSeedSolver.h:97
AthMessaging.h
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
python.FPGATrackSimAnalysisConfig.spacePoints
spacePoints
Definition: FPGATrackSimAnalysisConfig.py:584
python.compressB64.c
def c
Definition: compressB64.py:93