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