lsst.jointcal  16.0-17-g0bdc215+8
TwoTransfoMapping.cc
Go to the documentation of this file.
2 #include "lsst/pex/exceptions.h"
3 
5 
6 namespace lsst {
7 namespace jointcal {
8 
11  : _m1(chipMapping), _m2(visitMapping) {
12  /* Allocate the record of temporary variables, so that they are not
13  allocated at every call. This is hidden behind a pointer in order
14  to be allowed to alter them in a const routine. */
15  tmp = std::unique_ptr<tmpVars>(new tmpVars);
16  setWhatToFit(true, true);
17 }
18 
19 unsigned TwoTransfoMapping::getNpar() const { return _nPar1 + _nPar2; }
20 
22  unsigned npar = getNpar();
23  if (indices.size() < npar) indices.resize(npar);
24  // in case we are only fitting one of the two transfos
25  if (_nPar1)
26  _m1->getMappingIndices(indices);
27  else if (_nPar2) {
28  _m2->getMappingIndices(indices);
29  return;
30  }
31  // if we get here we are fitting both
32  // there is probably a more elegant way to feed a subpart of a std::vector
33  std::vector<unsigned> ind2(_nPar2);
34  _m2->getMappingIndices(ind2);
35  for (unsigned k = 0; k < _nPar2; ++k) indices.at(k + _nPar1) = ind2.at(k);
36 }
37 
39  Eigen::MatrixX2d &H) const {
40  // not true in general. Will crash if H is too small.
41  // assert(H.cols()==Npar());
42 
43  FatPoint pMid;
44  // don't need errors there but no Mapping::Transform() routine.
45 
46  if (_nPar1) {
47  _m1->computeTransformAndDerivatives(where, pMid, tmp->h1);
48  // the last argument is epsilon and is not used for polynomials
49  _m2->positionDerivative(pMid, tmp->dt2dx, 1e-4);
50  H.block(0, 0, _nPar1, 2) = tmp->h1 * tmp->dt2dx;
51  } else
52  _m1->transformPosAndErrors(where, pMid);
53  if (_nPar2) {
54  _m2->computeTransformAndDerivatives(pMid, outPoint, tmp->h2);
55  H.block(_nPar1, 0, _nPar2, 2) = tmp->h2;
56  } else
57  _m2->transformPosAndErrors(pMid, outPoint);
58 }
59 
64 void TwoTransfoMapping::setWhatToFit(const bool fittingT1, const bool fittingT2) {
65  if (fittingT1) {
66  _nPar1 = _m1->getNpar();
67  tmp->h1 = Eigen::MatrixX2d(_nPar1, 2);
68  } else
69  _nPar1 = 0;
70  if (fittingT2) {
71  _nPar2 = _m2->getNpar();
72  tmp->h2 = Eigen::MatrixX2d(_nPar2, 2);
73  } else
74  _nPar2 = 0;
75 }
76 
77 void TwoTransfoMapping::transformPosAndErrors(const FatPoint &where, FatPoint &outPoint) const {
78  FatPoint pMid;
79  _m1->transformPosAndErrors(where, pMid);
80  _m2->transformPosAndErrors(pMid, outPoint);
81 }
82 
83 void TwoTransfoMapping::positionDerivative(Point const &where, Eigen::Matrix2d &derivative,
84  double epsilon) const {
85  Eigen::Matrix2d d1, d2; // seems that it does not trigger dynamic allocation
86  _m1->positionDerivative(where, d1, 1e-4);
87  FatPoint pMid;
88  _m1->transformPosAndErrors(where, pMid);
89  _m2->positionDerivative(pMid, d2, 1e-4);
90  /* The following line is not a mistake. It is a consequence
91  of chosing derivative(0,1) = d(y_out)/d x_in. */
92  derivative = d1 * d2;
93 }
94 
96  throw LSST_EXCEPT(
98  " The routine TwoTransfoMapping::freezeErrorTransform() was thought to be useless and is "
99  "not implemented (yet)");
100 }
101 } // namespace jointcal
102 } // namespace lsst
void positionDerivative(Point const &where, Eigen::Matrix2d &derivative, double epsilon) const
Currently not implemented.
A point in a plane.
Definition: Point.h:13
void computeTransformAndDerivatives(FatPoint const &where, FatPoint &outPoint, Eigen::MatrixX2d &H) const
Actually applies the AstrometryMapping and evaluates the derivatives w.r.t the fitted parameters...
A Point with uncertainties.
Definition: FatPoint.h:11
unsigned getNpar() const
Number of parameters in total.
T resize(T... args)
T at(T... args)
Class for a simple mapping implementing a generic Gtransfo.
TwoTransfoMapping(std::shared_ptr< SimpleGtransfoMapping > chipMapping, std::shared_ptr< SimpleGtransfoMapping > visitMapping)
Eigen::Matrix< double, Eigen::Dynamic, 2 > MatrixX2d
Definition: Eigenstuff.h:10
void freezeErrorTransform()
Currently not implemented.
T size(T... args)
#define LSST_EXCEPT(type,...)
void getMappingIndices(std::vector< unsigned > &indices) const
Sets how this set of parameters (of length Npar()) map into the "grand" fit Expects that indices has ...
void transformPosAndErrors(FatPoint const &where, FatPoint &outPoint) const
The same as above but without the parameter derivatives (used to evaluate chi^2)