Class Reference for E1039 Core & Analysis Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GFMeasurement.cxx
Go to the documentation of this file.
1 #include "GFMeasurement.h"
2 
3 #include <iostream>
4 #include <iomanip>
5 #include <cmath>
6 #include <TVectorD.h>
7 #include <TMatrixDSym.h>
8 #include <TVector3.h>
9 
10 #include <GenFit/KalmanFitterInfo.h>
11 #include <GenFit/MeasuredStateOnPlane.h>
12 #include <GenFit/MeasurementOnPlane.h>
13 #include <GenFit/TrackPoint.h>
14 #include <GenFit/AbsHMatrix.h>
15 
16 #include <geom_svc/GeomSvc.h>
17 
18 namespace SQGenFit
19 {
20 
21 GFMeasurement::GFMeasurement(const SignedHit& rawHit, bool en): _bfHit(rawHit)
22 {
23  GeomSvc* p_geomSvc = GeomSvc::instance();
24 
25  TVectorD ep1(3), ep2(3), hitcoord(7);
26  int detID = _bfHit.hit.detectorID;
27  p_geomSvc->getEndPoints(detID, _bfHit.hit.elementID, ep1, ep2);
28  hitcoord[0] = ep1[0];
29  hitcoord[1] = ep1[1];
30  hitcoord[2] = ep1[2];
31  hitcoord[3] = ep2[0];
32  hitcoord[4] = ep2[1];
33  hitcoord[5] = ep2[2];
34  hitcoord[6] = fabs(_bfHit.hit.driftDistance);
35 
36  TMatrixDSym hitcov(7);
37  double resol = p_geomSvc->getPlaneResolution(detID);
38  hitcov.Zero();
39  hitcov(6, 6) = resol*resol;
40 
41  //Base AbsMeasurement data
42  setRawHitCoords(hitcoord);
43  setRawHitCov(hitcov);
44  setDetId(detID);
45  setHitId(_bfHit.hit.index);
46  setTrackPoint(nullptr);
47 
48  //WireMeasurement data
49  setMaxDistance(0.5*p_geomSvc->getCellWidth(detID));
50  setLeftRightResolution(0);
51 
52  //Own data
53  _z = p_geomSvc->getPlanePosition(detID);
54  _enableInFit = _bfHit.hit.index < 0 ? false : en;
55  _proj = 0.;
56  _driftSign = 0;
57  _track = nullptr;
58 }
59 
61 {
62  _track = trackPtr;
63 }
64 
66 {
67  if(!_enableInFit) return; //Needs extrapolation, not implemented for now
68 
69  genfit::KalmanFitterInfo* fitinfo = getTrackPoint()->getKalmanFitterInfo();
70  const genfit::MeasuredStateOnPlane& state = fitinfo->getFittedState(false); //biased = false since residual needs unbiased measured state
71  genfit::MeasurementOnPlane* mstate = fitinfo->getClosestMeasurementOnPlane(&state);
72  const genfit::AbsHMatrix* H = mstate->getHMatrix();
73 
74  _driftSign = mstate->getState()[0] > 0 ? 1 : -1;
75  _proj = H->Hv(state.getState())[0];
76 }
77 
78 void GFMeasurement::print(unsigned int debugLvl)
79 {
80  std::cout << " ................................................" << std::endl;
81  std::cout << "Hit " << _bfHit.hit.index << ", detID = " << _bfHit.hit.detectorID << ", eleID = " << _bfHit.hit.elementID
82  << ", pos = " << _bfHit.hit.pos << ", driftD = " << _bfHit.hit.driftDistance << ", pre-fit sign = " << _bfHit.sign
83  << ", post-fit sign = " << _driftSign << ", projection = " << _proj << ", residual = " << _proj - _driftSign*_bfHit.hit.driftDistance << std::endl;
84 
85  if(debugLvl < 1) return;
86 
87  GeomSvc* p_geomSvc = GeomSvc::instance();
88  TVector3 pos, mom;
89  double w;
90 
91  genfit::KalmanFitterInfo* fitinfo = getTrackPoint()->getKalmanFitterInfo();
92  const genfit::MeasuredStateOnPlane& fitstate = fitinfo->getFittedState(true); //this time we need the biased/smoothed result
93  fitstate.getPosMom(pos, mom);
94  w = p_geomSvc->getInterceptionFast(_bfHit.hit.detectorID, pos.X(), pos.Y());
95  printHelper(w, pos, mom, "Fitted ");
96  if(debugLvl > 10) fitstate.get6DCov().Print();
97 
98  if(debugLvl > 1 && fitinfo->hasReferenceState())
99  {
100  genfit::StateOnPlane* state = static_cast<genfit::StateOnPlane*>(fitinfo->getReferenceState());
101 
102  state->getPosMom(pos, mom);
103  w = p_geomSvc->getInterceptionFast(_bfHit.hit.detectorID, pos.X(), pos.Y());
104  printHelper(w, pos, mom, "Reference ");
105  }
106 
107  if(debugLvl > 2 && fitinfo->hasForwardPrediction())
108  {
109  genfit::MeasuredStateOnPlane* state = static_cast<genfit::MeasuredStateOnPlane*>(fitinfo->getForwardPrediction());
110 
111  state->getPosMom(pos, mom);
112  w = p_geomSvc->getInterceptionFast(_bfHit.hit.detectorID, pos.X(), pos.Y());
113  printHelper(w, pos, mom, "F-prediction ");
114  if(debugLvl > 10) state->get6DCov().Print();
115  }
116 
117  if(debugLvl > 2 && fitinfo->hasForwardUpdate())
118  {
119  genfit::MeasuredStateOnPlane* state = static_cast<genfit::MeasuredStateOnPlane*>(fitinfo->getForwardUpdate());
120 
121  state->getPosMom(pos, mom);
122  w = p_geomSvc->getInterceptionFast(_bfHit.hit.detectorID, pos.X(), pos.Y());
123  printHelper(w, pos, mom, "F-update ");
124  if(debugLvl > 10) state->get6DCov().Print();
125  }
126 
127  if(debugLvl > 3 && fitinfo->hasBackwardPrediction())
128  {
129  genfit::MeasuredStateOnPlane* state = static_cast<genfit::MeasuredStateOnPlane*>(fitinfo->getBackwardPrediction());
130 
131  state->getPosMom(pos, mom);
132  w = p_geomSvc->getInterceptionFast(_bfHit.hit.detectorID, pos.X(), pos.Y());
133  printHelper(w, pos, mom, "B-prediction ");
134  if(debugLvl > 10) state->get6DCov().Print();
135  }
136 
137  if(debugLvl > 3 && fitinfo->hasBackwardUpdate())
138  {
139  genfit::MeasuredStateOnPlane* state = static_cast<genfit::MeasuredStateOnPlane*>(fitinfo->getBackwardUpdate());
140 
141  state->getPosMom(pos, mom);
142  w = p_geomSvc->getInterceptionFast(_bfHit.hit.detectorID, pos.X(), pos.Y());
143  printHelper(w, pos, mom, "B-update ");
144  if(debugLvl > 10) state->get6DCov().Print();
145  }
146 }
147 
148 void GFMeasurement::printHelper(double w, TVector3& pos, TVector3& mom, TString name)
149 {
150  std::cout << " -- " << name.Data() << ": ";
151  std::cout << "pos (X,Y,Z,W) = " << std::setprecision(6) << pos.X() << " " << pos.Y() << " " << pos.Z() << " " << w;
152  std::cout << " - mom(Px,Py,Pz) = " << mom.X() << " " << mom.Y() << " " << mom.Z();
153  std::cout << " - rep(tx,ty,x0,y0) = " << mom.X()/mom.Z() << " " << mom.Y()/mom.Z() << " " << pos.X()-mom.X()/mom.Z()*pos.Z();
154  std::cout << " " << pos.Y()-mom.Y()/mom.Z()*pos.Z();
155  std::cout << std::endl;
156 }
157 
158 }
Float_t driftDistance
Definition: SRawEvent.h:81
void setTrackPtr(GFTrack *trackPtr)
double getCellWidth(int detectorID)
Definition: GeomSvc.h:200
Short_t detectorID
Definition: SRawEvent.h:78
void printHelper(double w, TVector3 &pos, TVector3 &mom, TString name="none")
double getPlaneResolution(int detectorID) const
Definition: GeomSvc.h:209
void print(unsigned int debugLvl=0)
Int_t index
Definition: SRawEvent.h:77
double getInterceptionFast(int detectorID, double tx, double ty, double x0, double y0) const
Definition: GeomSvc.cxx:935
static GeomSvc * instance()
singlton instance
Definition: GeomSvc.cxx:211
Short_t elementID
Definition: SRawEvent.h:79
Float_t pos
Definition: SRawEvent.h:82
void getEndPoints(int detectorID, int elementID, TVectorD &ep1, TVectorD &ep2)
Definition: GeomSvc.cxx:792
double getPlanePosition(int detectorID) const
Definition: GeomSvc.h:197
GFMeasurement(const SignedHit &rawHit, bool en=true)