GFAbsRecoHit.h
Go to the documentation of this file.
1 /* Copyright 2008-2010, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert
3 
4  This file is part of GENFIT.
5 
6  GENFIT is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  GENFIT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18 */
19 /** @addtogroup genfit */
20 /* @{ */
21 
22 
23 
24 #ifndef GFABSRECOHIT_H
25 #define GFABSRECOHIT_H
26 
27 #include<stdexcept> // std::logic_error
28 #include<iostream>
29 
30 #include "TMatrixT.h"
31 #include "TObject.h"
32 
33 #include "larreco/Genfit/GFException.h" // PrintROOTobject()
35 #include<cmath>
36 
37 namespace genf { class GFAbsTrackRep; }
38 
39 /** @brief Base Class for representing a Hit in GENFIT
40  *
41  * @author Christian H&ouml;ppner (Technische Universit&auml;t M&uuml;nchen, original author)
42  * @author Sebastian Neubert (Technische Universit&auml;t M&uuml;nchen, original author)
43  *
44  * A hit is defined as a single measurement of a detector. Each detector can
45  * define it's own hit representation (geometry) by inherting from GFAbsRecoHit.
46  * We call such a child object a "RecoHit" to make clear that
47  * it inherits from GFAbsRecoHit.
48  * All detector specific information is handled inside the RecoHit objects.
49  * The idea behind this is that the fitting algorithms can work on different
50  * detectors simultanously.
51  *
52  * GFAbsRecoHit defines the basic interface that is used by all genfit algorithms
53  * to access hit-measurement information. It provides:
54  * - the matrices to store hit coordinates and covariances
55  * - defines methods to access these data
56  * - the interface to access a hit's detector plane object
57  *
58  * All hits have to inherit from this base class.
59  * Inheritance can be direct or through template class
60  * RecoHitIfc<GeometryPolicy>.
61  * These interface classes (defined with a specific policy)
62  * provide additional functionality for specific hit geometries,
63  * such as space points, wires, etc. For details look
64  * at the RecoHitIfc documentation.
65  *
66  * A simple example is given in VirtSpacePointRecoHit
67  *
68  * Background information: The main feature here is
69  * that coordinates and covariances are available as general
70  * TMatrixT<Double_t> objects. By using these general algebraic
71  * objects it is possible to abstract from the concrete measurement and
72  * thus define a unified framework to handle the data. This is a key ingredient
73  * for the separation of data and algorithms which in turn enables us
74  * to elegantly combine information from different detectors.
75  */
76 namespace genf {
77 
78 class GFAbsRecoHit : public TObject{
79 protected:
80  /// Vector of raw coordinates of hit
81  TMatrixT<Double_t> fHitCoord;
82 
83  /// Covariance of raw hit coordinates
84  TMatrixT<Double_t> fHitCov;
85 
86  private:
87  int fNparHit;
88 
89 public:
90  virtual ~GFAbsRecoHit();
91 
92  /** @brief Constructor specifying dimension of coordinate vector
93  *
94  * One hit is generally represented by a vector of coordinates.
95  * @param NparHit specifies the dimension of this vector.
96  * (e.g. 3 for a spacepoint, 2 for a pixel, 1 for a strip)
97  */
98  GFAbsRecoHit(int NparHit);
99 
100  /** @brief Default constructor needed for compatibility with ROOT
101  */
102  GFAbsRecoHit();
103 
104  /** @brief Get transformation matrix. Transformation between hit
105  * coordinates and track representation coordinates.
106  *
107  * This is a virtual abstract method which has to be implemented in the child
108  * classes.
109  *
110  * In general there is a linear transformation between the coordinate system
111  * of the hit (which is defined by the detector plane) and the coordinates of
112  * the track representation in that plane. In the most simple case the track
113  * representation has 5 parameters (space + momentum)
114  * while a hit usually has less (one to three space coordinates).
115  *
116  * The transformation matrix is then simply projecting out the
117  * space-components of the track representation.
118  *
119  * Its dimensions are NxM. Where N is the number of dimensions of the
120  * hit in the detector plane (usually 2 or 1) and M is the dimension of the
121  * track representation.
122  *
123  * In this method a hit has to define with which track representations it can
124  * work together. It should be the only point where this explicit
125  * coordination is necessary.
126  *
127  * For example code see implementing classes below:
128  */
129  virtual TMatrixT<Double_t> getHMatrix(const GFAbsTrackRep* stateVector)=0;
130  virtual TMatrixT<Double_t> getHMatrix(const GFAbsTrackRep* stateVector, const Double_t&, const Double_t&)=0;
131 
132 
133  /** @brief Calculate residual with respect to a track representation.
134  *
135  * Returns the N-dimensional residual of this vector to a given
136  * track representation.
137  *
138  * This method is not doing any extrapolation. But it
139  * creates the necessary detector plane object. See GFAbsRecoHit::getGFDetPlane
140  *
141  * @param stateVector pointer to track representation - used to synchronize
142  * with the track repesentation
143  * @param state parameter vector of the track representation
144  *
145  * @sa setHMatrix
146  * @sa getGFDetPlane
147  */
148  virtual TMatrixT<Double_t> residualVector(const GFAbsTrackRep* stateVector,
149  const TMatrixT<Double_t>& state,
150  const GFDetPlane& d) {
151  std::cout << "GFAbsRecoHit::residualVector(3args) Not correctly Using theta -- multiple scattering -- information !!! Fix this if you really want to use getChi2Hit" << std::endl;
152  TMatrixT<Double_t> H = getHMatrix(stateVector);
153  return ( getHitCoord(d) - (H*state ));
154  }
155 
156  virtual TMatrixT<Double_t> residualVector(const GFAbsTrackRep* stateVector,
157  const TMatrixT<Double_t>& state,
158  const GFDetPlane& d,
159  const GFDetPlane& dPrev,
160  const double &mass
161  )
162  {
163  Double_t dist = (d.getO()-dPrev.getO()).Mag();
164  // Double_t mass = 0.104; // close enough for muons, pions, I think.
165  Double_t mom = fabs(1.0/state[0][0]);
166  Double_t beta = mom/sqrt(mass*mass+mom*mom);
167  if (std::isnan(dist) || dist<0.2) dist=0.2; // don't allow 0s here.
168  if (std::isnan(beta) || beta<0.04) beta=0.04;
169 
170  TMatrixT<Double_t> H = getHMatrix(stateVector,beta,dist);
171  return ( getHitCoord(d,dPrev) - (H*state ));
172  }
173 
174 
175  /** @brief Get raw hit covariances.
176  *
177  */
178  TMatrixT<Double_t> getRawHitCov() const {return fHitCov;}
179 
180  /** @brief Get raw hit coordinates.
181  *
182  */
183  TMatrixT<Double_t> getRawHitCoord() const {return fHitCoord;}
184 
185  /** @brief Get hit covariances in a specific detector plane
186  *
187  * Virtual abstract method has to be implemented by inherting classes.
188  * Implementation involves transformation from raw coordinates in detector
189  * coordinate system to detector plane coordinate system.
190  * @sa getGFDetPlane
191  */
192  virtual TMatrixT<Double_t> getHitCov(const GFDetPlane&)=0;
193  virtual TMatrixT<Double_t> getHitCov(const GFDetPlane&, const GFDetPlane&, const TMatrixT<Double_t>&, const Double_t&)=0;
194 
195  /** @brief Get hit coordinates in a specific detector plane
196  *
197  * Virtual abstract method has to be implemented by inherting classes.
198  * Implementation involves transformation from raw coordinates in detector
199  * coordinate system to detector plane coordinate system.
200  * @sa getDetPlane
201  */
202  virtual TMatrixT<Double_t> getHitCoord(const GFDetPlane&,const GFDetPlane&)=0;
203  virtual TMatrixT<Double_t> getHitCoord(const GFDetPlane&)=0;
204 
205 
206  /** @brief Get detector plane for a given track representation.
207  *
208  * Virtual abstract method has to be implemented by inherting classes.
209  *
210  * In general the detector plane can depend both on the detector/hit geometry
211  * as well as the track geometry. E.g. for a space point one usually chooses
212  * a plane that is perpendicular to the current track, since in that case no
213  * other plane is predefined.
214  *
215  * There are several implementations for this method in the HitPolicies.
216  * In the most simple case (a planar detector) the method just returns a
217  * fixed (detector module specific) plane. This behaviour for example is
218  * implemented in PlanarHitPolicy.
219  */
220  virtual const GFDetPlane& getDetPlane(GFAbsTrackRep*) = 0;
221 
222 
223 
224  /** @brief Get clone of this object.
225  *
226  * Virtual abstract method. Has to be implemented by inherting classes.
227  * Creates a deep copy of this object.
228  * Ownership is trandsferred to the caller!
229  */
230  virtual GFAbsRecoHit* clone() = 0;
231 
232  /** @brief Print raw hit coordinates.
233  */
234  virtual void Print(std::ostream& out = std::cout) const
235  { PrintROOTobject(out, fHitCoord); }
236 
237  virtual const std::string& getPolicyName();
238 
239  int getNparHit(){return fNparHit;}
240 
241  // public:
242  //ClassDef(GFAbsRecoHit,3)
243 
244  private:
245  virtual void Print(Option_t*) const
246  { throw std::logic_error(std::string(__func__) + "::Print(Option_t*) not available"); }
247 
248 };
249 } // namespace
250 
251 #endif //FITTER_ABSHIT_H
252 
253 /** @} */
virtual TMatrixT< Double_t > getHitCoord(const GFDetPlane &, const GFDetPlane &)=0
Get hit coordinates in a specific detector plane.
double beta(double KE, const simb::MCParticle *part)
virtual ~GFAbsRecoHit()
TMatrixT< Double_t > fHitCoord
Vector of raw coordinates of hit.
Definition: GFAbsRecoHit.h:81
std::string string
Definition: nybbler.cc:12
virtual const std::string & getPolicyName()
Generic Interface to magnetic fields in GENFIT.
Definition: GFAbsBField.h:35
virtual TMatrixT< Double_t > getHMatrix(const GFAbsTrackRep *stateVector)=0
Get transformation matrix. Transformation between hit coordinates and track representation coordinate...
virtual const GFDetPlane & getDetPlane(GFAbsTrackRep *)=0
Get detector plane for a given track representation.
TMatrixT< Double_t > getRawHitCoord() const
Get raw hit coordinates.
Definition: GFAbsRecoHit.h:183
Base Class for genfit track representations. Defines interface for track parameterizations.
Definition: GFAbsTrackRep.h:83
TVector3 getO() const
Definition: GFDetPlane.h:81
virtual void Print(Option_t *) const
Definition: GFAbsRecoHit.h:245
virtual TMatrixT< Double_t > residualVector(const GFAbsTrackRep *stateVector, const TMatrixT< Double_t > &state, const GFDetPlane &d, const GFDetPlane &dPrev, const double &mass)
Definition: GFAbsRecoHit.h:156
virtual TMatrixT< Double_t > getHitCov(const GFDetPlane &)=0
Get hit covariances in a specific detector plane.
virtual void Print(std::ostream &out=std::cout) const
Print raw hit coordinates.
Definition: GFAbsRecoHit.h:234
GFAbsRecoHit()
Default constructor needed for compatibility with ROOT.
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
void PrintROOTobject(std::ostream &, const ROOTOBJ &)
Small utility functions which print some ROOT objects into an output stream.
Definition: GFException.h:127
TMatrixT< Double_t > getRawHitCov() const
Get raw hit covariances.
Definition: GFAbsRecoHit.h:178
virtual TMatrixT< Double_t > residualVector(const GFAbsTrackRep *stateVector, const TMatrixT< Double_t > &state, const GFDetPlane &d)
Calculate residual with respect to a track representation.
Definition: GFAbsRecoHit.h:148
TMatrixT< Double_t > fHitCov
Covariance of raw hit coordinates.
Definition: GFAbsRecoHit.h:84
virtual GFAbsRecoHit * clone()=0
Get clone of this object.
QTextStream & endl(QTextStream &s)