Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
WirePointMeasurement.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file WirePointMeasurement.cc
1 /* Copyright 2008-2010, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch
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 
20 #include "WirePointMeasurement.h"
21 
22 #include <Exception.h>
23 #include <RKTrackRep.h>
24 #include <HMatrixUV.h>
25 
26 #include <cassert>
27 #include <algorithm>
28 
29 
30 namespace genfit {
31 
33  : WireMeasurement(nDim)
34 {
35  assert(nDim >= 8);
36 }
37 
38 WirePointMeasurement::WirePointMeasurement(const TVectorD& rawHitCoords, const TMatrixDSym& rawHitCov, int detId, int hitId, TrackPoint* trackPoint)
39  : WireMeasurement(rawHitCoords, rawHitCov, detId, hitId, trackPoint)
40 {
41  assert(rawHitCoords_.GetNrows() >= 8);
42 }
43 
44 
46 
47  // copy state. Neglect covariance.
48  StateOnPlane st(state);
49 
50  TVector3 wire1(rawHitCoords_(0), rawHitCoords_(1), rawHitCoords_(2));
51  TVector3 wire2(rawHitCoords_(3), rawHitCoords_(4), rawHitCoords_(5));
52 
53  // unit vector along the wire (V)
54  TVector3 wireDirection = wire2 - wire1;
55  wireDirection.SetMag(1.);
56 
57  // point of closest approach
58  const AbsTrackRep* rep = state.getRep();
59  rep->extrapolateToLine(st, wire1, wireDirection);
60  //const TVector3& poca = rep->getPos(st);
61  TVector3 dirInPoca = rep->getMom(st);
62  dirInPoca.SetMag(1.);
63  //const TVector3& pocaOnWire = wire1 + wireDirection.Dot(poca - wire1)*wireDirection;
64 
65  // check if direction is parallel to wire
66  if (fabs(wireDirection.Angle(dirInPoca)) < 0.01){
67  Exception exc("WireMeasurement::detPlane(): Cannot construct detector plane, direction is parallel to wire", __LINE__,__FILE__);
68  throw exc;
69  }
70 
71  // construct orthogonal vector
72  TVector3 U = dirInPoca.Cross(wireDirection);
73  // U.SetMag(1.); automatically assured
74 
75  return SharedPlanePtr(new DetPlane(wire1, U, wireDirection));
76 }
77 
78 
79 std::vector<MeasurementOnPlane*> WirePointMeasurement::constructMeasurementsOnPlane(const StateOnPlane& state) const
80 {
81  MeasurementOnPlane* mopR = new MeasurementOnPlane(TVectorD(2),
82  TMatrixDSym(2),
83  state.getPlane(), state.getRep(), constructHMatrix(state.getRep()));
84 
85  mopR->getState()(0) = rawHitCoords_(6);
86  mopR->getState()(1) = rawHitCoords_(7);
87 
88  mopR->getCov()(0,0) = rawHitCov_(6,6);
89  mopR->getCov()(1,0) = rawHitCov_(7,6);
90  mopR->getCov()(0,1) = rawHitCov_(6,7);
91  mopR->getCov()(1,1) = rawHitCov_(7,7);
92 
93 
94  MeasurementOnPlane* mopL = new MeasurementOnPlane(*mopR);
95  mopL->getState()(0) *= -1;
96 
97  // set left/right weights
98  if (leftRight_ < 0) {
99  mopL->setWeight(1);
100  mopR->setWeight(0);
101  }
102  else if (leftRight_ > 0) {
103  mopL->setWeight(0);
104  mopR->setWeight(1);
105  }
106  else {
107  double val = 0.5 * pow(std::max(0., 1 - rawHitCoords_(6)/maxDistance_), 2.);
108  mopL->setWeight(val);
109  mopR->setWeight(val);
110  }
111 
112  std::vector<MeasurementOnPlane*> retVal;
113  retVal.push_back(mopL);
114  retVal.push_back(mopR);
115  return retVal;
116 }
117 
119  if (dynamic_cast<const RKTrackRep*>(rep) == nullptr) {
120  Exception exc("WirePointMeasurement default implementation can only handle state vectors of type RKTrackRep!", __LINE__,__FILE__);
121  throw exc;
122  }
123 
124  return new HMatrixUV();
125 }
126 
127 } /* End of namespace genfit */