3#include <Eigen/StdVector>
35 std::ifstream geocfile(fname);
36 if (not geocfile.is_open()) {
52 if (
sizeof(
float) * CHAR_BIT != 32)
53 ATH_MSG_WARNING(
"Floating points on this computer are not 32 bit. This may cause a problem for the hardware agreement. Be careful!");
69 for (
int i = 0; i < 5; ++i) getline(geocfile, key);
118 geocfile >> key >> ival;
119 if (ival != isec)
ATH_MSG_WARNING(
"Reached sector " << ival <<
" but expected sector " << isec);
122 for (
int ipar = 0; ipar <
m_npars; ++ipar)
126 for (
int icoord = 0; icoord <
m_ncoords; ++icoord)
130 ATH_MSG_WARNING(
"par loop (1) key=\"" << key <<
"\" ipar,icoord=" << ipar <<
"," << icoord);
139 assert(key==
"kaverages");
149 assert(key==
"kernel");
161 for (
int ipar=0;ipar<
m_npars;++ipar)
198 if (det == 0)
continue;
208 if (
m_maj_kk(isec, ix, ix) == 0)
continue;
225 for (
int ip=0;ip!=
m_npars;++ip)
227 thisMatrix(ip,ix)= (
m_fit_pars(isec, ip, ix));
241 bool foundrow =
false;
242 bool foundcolumn =
false;
245 if (abs(thisMatrix(iy,ix)) >
MTX_TOLERANCE) foundcolumn =
true;
247 if (foundrow && foundcolumn)
m_WCs(isec,ix) = 0;
251 size_t nDimToUse = 0;
for (
int ix=0;ix!=
m_ncoords;++ix)
if(!
m_WCs(isec,ix)) ++nDimToUse;
253 Eigen::MatrixXf tempMatrix(nDimToUse, nDimToUse);
255 size_t counteri = 0, counterj = 0;
258 if (!
m_WCs(isec,i)) {
260 if (!
m_WCs(isec,j)) {
261 tempMatrix(counteri,counterj) = thisMatrix(i,j);
314 int nmissing = track.getNMissing();
318 if (nmissing != guess_res)
return false;
336 std::vector<int> missid;
340 std::vector<int> missing_planes;
343 coordsmask[j] = (track.getHitMap()>>j) & 1;
344 if (!coordsmask[j]) {
345 int plane =
m_pmap->getCoordLayer(j);
346 if(missing_planes.size() == 0) {
347 missing_planes.push_back(plane);
350 for (
unsigned k = 0; k < missing_planes.size(); k++) {
351 if(plane == missing_planes[k])
break;
352 if(k == missing_planes.size() - 1) missing_planes.push_back(plane);
360 if(!doExtrapolation){
362 if(missing_planes.size() > 1){
363 ATH_MSG_WARNING(
"missing_point_guess() Can only guess 1 layer in the first stage");
367 ATH_MSG_WARNING(
"missing_point_guess() Cannot guess more than two coordinates in the first stage");
372 if(missing_planes.size() > 2){
373 ATH_MSG_WARNING(
"missing_point_guess() Can only guess 2 layers in the second stage");
377 ATH_MSG_WARNING(
"missing_point_guess() Cannot guess more than four coordinates in the second stage");
383 Eigen::MatrixXd coef(nmissing,nmissing);
384 Eigen::VectorXd
a(nmissing);
386 for (
int i=0; i<nmissing; ++i)
392 if (!coordsmask[col])
continue;
396 int layer =
m_pmap->getCoordLayer(col);
397 auto hit_ptr = track.getFPGATrackSimHitPtrs()[layer];
398 if (!hit_ptr)
throw std::runtime_error(
"Null hit pointer in FPGATrackSimFitConstantBank: tracks should not have unassigned layers");
402 a[i] -=
m_maj_kk(sector, col, missid[i])*(phishift+track.getPhiCoord(
m_pmap->getCoordLayer(col)));
405 a[i] -=
m_maj_kk(sector, col+1, missid[i])*track.getEtaCoord(
m_pmap->getCoordLayer(col));
410 for (
int j=0; j<nmissing; ++j)
413 coef(i,j) =
m_maj_kk(sector, missid[i], missid[j]);
417 if (coef.determinant()==0)
return -1;
418 Eigen::VectorXd missing_hits = coef.inverse()*
a;
420 for(
int m=0; m<nmissing; m++){
422 int missedplane =
m_pmap->getCoordLayer(missid[m]);
424 if(
m_pmap->getDim(
m_pmap->getCoordLayer(missid[m])) == 1){
436 double target_r = track.getIdealRadius(missedplane);
437 newhit.
setX(target_r*TMath::Cos(missing_hits[m]));
438 newhit.
setY(target_r*TMath::Sin(missing_hits[m]));
444 track.setFPGATrackSimHit(missedplane, std::make_shared<FPGATrackSimHit>(newhit));
446 else if (
m_pmap->getDim(
m_pmap->getCoordLayer(missid[m])) == 2){
458 double target_r = track.getIdealRadius(missedplane);
459 newhit.
setX(target_r*TMath::Cos(missing_hits[m]));
460 newhit.
setY(target_r*TMath::Sin(missing_hits[m]));
461 newhit.
setZ(missing_hits[m+1]);
469 track.setFPGATrackSimHit(missedplane, std::make_shared<FPGATrackSimHit>(newhit));
496 if (!hitPtr)
throw std::runtime_error(
"Null hit pointer in getAccumulatorTerm: tracks should not have unassigned layers");
497 if (((hitPtr->getPhysLayer() %2) == 1) && hitPtr->getHitType() ==
HitType::spacepoint) phishift = 0.0;
501 chi2 += chi_component * chi_component;
517 std::vector<float> pars(
m_npars);
519 for (
int ip = 0; ip <
m_npars; ip++)
529 if (!hitPtr)
throw std::runtime_error(
"Null hit pointer in getTrackPars: tracks should not have unassigned layers");
530 if (((hitPtr->getPhysLayer() %2) == 1) && hitPtr->getHitType() ==
HitType::spacepoint) phishift = 0.0;
562 for (
int ip = 0; ip <
m_npars; ++ip)
565 pars(ip) = track.getParameter(ip) -
m_fit_const(sector, ip);
583 int plane =
m_pmap->getCoordLayer(j);
602 track.setFPGATrackSimHit(plane, std::make_shared<FPGATrackSimHit>(std::move(hit)));
#define ATH_MSG_WARNING(x)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
vector2D< float > m_maj_a
void setIdealCoordFit(bool v)
std::vector< bool > m_sector_good
void linfit_pars_eval(sector_t sector, FPGATrackSimTrack &trk) const
vector3D< float > m_fit_pars
std::vector< Eigen::MatrixXf, Eigen::aligned_allocator< Eigen::MatrixXf > > m_invfit_consts
FPGATrackSimFitConstantBank(FPGATrackSimPlaneMap const *pmap, int ncoords, std::string const &fname, bool isFirstStage, float phishift, int missingPlane=-1)
vector3D< float > m_maj_kk
void readHeader(std::ifstream &geocfile)
vector3D< float > m_maj_invkk
void linfit_chisq(sector_t sector, FPGATrackSimTrack &trk) const
void prepareInvFitConstants()
void invlinfit(sector_t sector, FPGATrackSimTrack &track, double const *constr) const
This method uses the track parameters and additional constraints to use the constants to calculate th...
void readSectorInfo(std::ifstream &geocfile)
FPGATrackSimPlaneMap const * m_pmap
vector2D< float > m_fit_const
bool linfit(sector_t sector, FPGATrackSimTrack &track, bool isSecondStage) const
vector3D< float > m_kernel
int missing_point_guess(sector_t sector, FPGATrackSimTrack &track, bool isFirstStage, bool doExtrapolation) const
vector2D< float > m_kaverage
void setLayer(unsigned v)
void setEtaIndex(unsigned v)
void setPhiIndex(unsigned v)
void setHitType(HitType type)
unsigned getPhysLayer(bool old=false) const
void setSection(unsigned v)
HitType getHitType() const
void setDetType(SiliconTech detType)
float getEtaCoord(int ilayer) const
void setPhi(float v, bool ForceRange=true)
bool getDoDeltaGPhis() const
const std::vector< std::shared_ptr< const FPGATrackSimHit > > & getFPGATrackSimHitPtrs() const
float getPhiCoord(int ilayer) const
std::vector< std::string > remainder(const std::vector< std::string > &v1, const std::vector< std::string > &v2)
double chi2(TH1 *h0, TH1 *h1)