Belle II Software development
TRGCDCTrack.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9//-----------------------------------------------------------------------------
10// Description : A class to represent a reconstructed charged track in TRGCDC.
11//-----------------------------------------------------------------------------
12
13#define TRGCDC_SHORT_NAMES
14
15#include "cdc/dataobjects/CDCSimHit.h"
16#include "trg/trg/Debug.h"
17#include "trg/trg/Constants.h"
18#include "trg/cdc/TRGCDCTrack.h"
19#include "trg/cdc/Circle.h"
20#include "trg/cdc/Wire.h"
21#include "trg/cdc/SegmentHit.h"
22#include "trg/cdc/Link.h"
23#include "trg/cdc/Helix.h"
24#include "trg/cdc/TRGCDC.h"
25
26using namespace std;
27
28namespace Belle2 {
34 vector<const TRGCDCTrack*>
35 TRGCDCTrack::_list = vector<const TRGCDCTrack*>();
36
38 : TCTBase("unknown", 0),
39 _helix(ORIGIN, CLHEP::HepVector(5, 0), CLHEP::HepSymMatrix(5, 0)), m_2DFitChi2(9999), m_3DFitChi2(9999), m_debugValue(0)
40 {
41 }
42
44 : TCTBase((const TCTBase&) c),
45 _helix(ORIGIN, CLHEP::HepVector(5, 0), CLHEP::HepSymMatrix(5, 0)), m_2DFitChi2(9999), m_3DFitChi2(9999), m_debugValue(0)
46 {
47
48 //...Basic stuff...
49// const string newName = "CopyOF" + c.name();
50 name("ConvFrom" + c.name());
51 charge(c.charge());
52
53 //...Set a defualt fitter...
54// fitter(& TTrack::_fitter);
55
56 //...Calculate helix parameters...
57 CLHEP::HepVector a(5);
58 a[1] = fmod(atan2(_charge * (c.center().y() - ORIGIN.y()),
59 _charge * (c.center().x() - ORIGIN.x()))
60 + 4. * M_PI,
61 2. * M_PI);
62 a[2] = TCHelix::ConstantAlpha / c.radius();
63 a[0] = (c.center().x() - ORIGIN.x()) / cos(a[1]) - c.radius();
64 a[3] = 0.;
65 a[4] = 0.;
66 _helix.a(a);
67
68 //...Update links...
69 unsigned n = _tsAll.size();
70 for (unsigned i = 0; i < n; i++)
71 _tsAll[i]->track(this);
72
73 _fitted = false;
74 }
75
77 {
78 if (_list.size()) {
79 for (unsigned i = 0; i < _list.size(); i++)
80 if (_list[i] == this)
81 _list.erase(_list.begin(), _list.begin() + i);
82 }
83 }
84
85 vector<const TRGCDCTrack*>
87 {
88 vector<const TRGCDCTrack*> t;
89 t.assign(_list.begin(), _list.end());
90 return t;
91 }
92
93 int
94 TRGCDCTrack::approach(TRGCDCLink& link, bool doSagCorrection) const
95 {
96
97 //...Cal. dPhi to rotate...
98 const Belle2::TRGCDCWire& w = * link.wire();
99 double wp[3]; w.xyPosition(wp);
100 double wb[3]; w.backwardPosition(wb);
101 double v[3];
102 v[0] = w.direction().x();
103 v[1] = w.direction().y();
104 v[2] = w.direction().z();
105
106 //...Sag correction...
107 if (doSagCorrection) {
108 std::cout << "TTrack::approach !!! sag correction is not implemented"
109 << std::endl;
110// Vector3D dir = w.direction();
111// Point3D xw(wp[0], wp[1], wp[2]);
112// Point3D wireBackwardPosition(wb[0], wb[1], wb[2]);
113// w.wirePosition(link.positionOnTrack().z(),
114// xw,
115// wireBackwardPosition,
116// dir);
117// v[0] = dir.x();
118// v[1] = dir.y();
119// v[2] = dir.z();
120// wp[0] = xw.x();
121// wp[1] = xw.y();
122// wp[2] = xw.z();
123// wb[0] = wireBackwardPosition.x();
124// wb[1] = wireBackwardPosition.y();
125// wb[2] = wireBackwardPosition.z();
126 }
127
128 //...Cal. dPhi to rotate...
129 double dPhi;
130 const HepGeom::Point3D<double>& xc = helix().center();
131 double xt[3]; _helix.x(0., xt);
132 double x0 = - xc.x();
133 double y0 = - xc.y();
134 double x1 = wp[0] + x0;
135 double y1 = wp[1] + y0;
136 x0 += xt[0];
137 y0 += xt[1];
138 dPhi = atan2(x0 * y1 - y0 * x1, x0 * x1 + y0 * y1);
139
140 //...Setup...
141 double kappa = _helix.kappa();
142 double phi0 = _helix.phi0();
143
144 //...Axial case...
145 if (w.axial()) {
146 link.positionOnTrack(_helix.x(dPhi));
147 Point3D x(wp[0], wp[1], wp[2]);
148 x.setZ(link.positionOnTrack().z());
149 link.positionOnWire(x);
150 link.dPhi(dPhi);
151 return 0;
152 }
153
154#ifdef TRASAN_DEBUG
155 double firstdfdphi = 0.;
156 static bool first = true;
157 if (first) {
158//cnv extern BelleTupleManager * BASF_Histogram;
159// BelleTupleManager * m = BASF_Histogram;
160// h_nTrial = m->histogram("TTrack::approach nTrial", 100, 0., 100.);
161 }
162#endif
163
164 //...Stereo case...
165 double rho = TCHelix::ConstantAlpha / kappa;
166 double tanLambda = _helix.tanl();
167 static CLHEP::HepVector x(3);
168 double t_x[3];
169 double t_dXdPhi[3];
170 const double convergence = 1.0e-5;
171 double l;
172 unsigned nTrial = 0;
173 while (nTrial < 100) {
174
175 x = link.positionOnTrack(_helix.x(dPhi));
176 t_x[0] = x[0];
177 t_x[1] = x[1];
178 t_x[2] = x[2];
179
180 l = v[0] * t_x[0] + v[1] * t_x[1] + v[2] * t_x[2]
181 - v[0] * wb[0] - v[1] * wb[1] - v[2] * wb[2];
182
183 double rcosPhi = rho * cos(phi0 + dPhi);
184 double rsinPhi = rho * sin(phi0 + dPhi);
185 t_dXdPhi[0] = rsinPhi;
186 t_dXdPhi[1] = - rcosPhi;
187 t_dXdPhi[2] = - rho * tanLambda;
188
189 //...f = d(Distance) / d phi...
190 double t_d2Xd2Phi[2];
191 t_d2Xd2Phi[0] = rcosPhi;
192 t_d2Xd2Phi[1] = rsinPhi;
193
194 //...iw new...
195 double n[3];
196 n[0] = t_x[0] - wb[0];
197 n[1] = t_x[1] - wb[1];
198 n[2] = t_x[2] - wb[2];
199
200 double a[3];
201 a[0] = n[0] - l * v[0];
202 a[1] = n[1] - l * v[1];
203 a[2] = n[2] - l * v[2];
204 double dfdphi = a[0] * t_dXdPhi[0]
205 + a[1] * t_dXdPhi[1]
206 + a[2] * t_dXdPhi[2];
207
208#ifdef TRASAN_DEBUG
209 if (nTrial == 0) {
210// break;
211 firstdfdphi = dfdphi;
212 }
213
214 //...Check bad case...
215 if (nTrial > 3) {
216 std::cout << Tab() << "TTrack::approach:" << w.name() << " "
217 << "dfdphi(0)=" << firstdfdphi
218 << ",(" << nTrial << ")=" << dfdphi << std::endl;
219 }
220#endif
221
222 //...Is it converged?...
223 if (fabs(dfdphi) < convergence)
224 break;
225
226 double dv = v[0] * t_dXdPhi[0]
227 + v[1] * t_dXdPhi[1]
228 + v[2] * t_dXdPhi[2];
229 double t0 = t_dXdPhi[0] * t_dXdPhi[0]
230 + t_dXdPhi[1] * t_dXdPhi[1]
231 + t_dXdPhi[2] * t_dXdPhi[2];
232 double d2fd2phi = t0 - dv * dv
233 + a[0] * t_d2Xd2Phi[0]
234 + a[1] * t_d2Xd2Phi[1];
235// + a[2] * t_d2Xd2Phi[2];
236
237 dPhi -= dfdphi / d2fd2phi;
238
239// std::cout<< "nTrial=" << nTrial << std::endl;
240// std::cout<< "iw f,df,dphi=" << dfdphi << "," << d2fd2phi << "," << dPhi << std::endl;
241
242 ++nTrial;
243 }
244
245 //...Cal. positions...
246 link.positionOnWire(Point3D(wb[0] + l * v[0],
247 wb[1] + l * v[1],
248 wb[2] + l * v[2]));
249 link.dPhi(dPhi);
250
251#ifdef TRASAN_DEBUG
252//cnv h_nTrial->accumulate((float) nTrial + .5);
253#endif
254
255 return nTrial;
256 }
257
258 std::vector<HepGeom::Point3D<double> >
260 {
261
262 //...CDC...
263 const TRGCDC& cdc = * TRGCDC::getTRGCDC();
264
265 //...Return value...
266 vector<HepGeom::Point3D<double> > posv;
267
268 //...Super layer loop...
269 for (unsigned i = 0; i < cdc.nSuperLayers(); i++) {
270
271 //...Check links to be one...
272 if ((links(i).size() == 0) || (links(i).size() > 1)) {
273 if (TRGDebug::level() > 1) {
274 cout << TRGDebug::tab() << "TRGCDCTrack::perfectPosition !!! #links in superlayer "
275 << i << " is " << links(i).size() << endl;
276 }
277 continue;
278 }
279
280 //...Track segment hit...
281 const TCSHit* h = dynamic_cast<const TCSHit*>(links(i)[0]->hit());
282 if (! h) {
283 cout << "TRGCDCTrack::perfectPosition !!! hit is not a TCSHit"
284 << endl;
285 continue;
286 }
287
288 //...CDCSimHit...
289 const CDCSimHit* s = h->simHit();
290 if (! s) {
291 cout << "TRGCDCTrack::perfectPosition !!! no CDCSimHit found"
292 << endl;
293 continue;
294 }
295
296 //...Position...
297 posv.push_back(HepGeom::Point3D<double>(s->getPosTrack().x(),
298 s->getPosTrack().y(),
299 s->getPosTrack().z()));
300
301 if (TRGDebug::level() > 1) {
302 cout << TRGDebug::tab() << "Perfect position TSLayer " << i
303 << " : " << posv.back() << endl;
304 }
305 }
306
307 return posv;
308 }
309
310
312} // namespace Belle2
Example Detector.
Definition: CDCSimHit.h:21
A class to represent a circle.
Definition: Circle.h:33
std::vector< TRGCDCLink * > _tsAll
Links for all super layers.
Definition: TrackBase.h:160
double _charge
Charge.
Definition: TrackBase.h:148
bool _fitted
Fitting status.
Definition: TrackBase.h:169
TRGCDCHelix _helix
Helix parameter.
Definition: TRGCDCTrack.h:110
A class to represent a wire in CDC.
Definition: Wire.h:56
The instance of TRGCDC is a singleton.
Definition: TRGCDC.h:69
const TRGCDCHelix & helix(void) const
returns helix parameter.
Definition: TRGCDCTrack.h:143
const TRGCDCWire * wire(void) const
returns a pointer to a wire.
Definition: Link.cc:833
HepGeom::Point3D< double > x(double dPhi=0.) const
returns position after rotating angle dPhi in phi direction.
Definition: Helix.cc:135
static std::string tab(void)
returns tab spaces.
Definition: Debug.cc:47
static TRGCDC * getTRGCDC(void)
returns TRGCDC object.
Definition: TRGCDC.cc:192
TRGCDCTrack()
Constructor.
Definition: TRGCDCTrack.cc:37
HepGeom::Point3D< double > Point3D
3D point
Definition: Cell.h:32
const HepGeom::Point3D< double > & center(void) const
returns position of helix center(z = 0.);
Definition: Helix.h:243
int approach(TRGCDCLink &, bool sagCorrection=false) const
calculates the closest approach to a wire in real space. Results are stored in TLink....
Definition: TRGCDCTrack.cc:94
double charge(void) const
returns charge.
Definition: TrackBase.h:248
static std::vector< const TRGCDCTrack * > _list
a vector to keep all TRGCDCTrack objects.
Definition: TRGCDCTrack.h:105
double tanl(void) const
returns tanl.
Definition: Helix.h:299
const HepGeom::Point3D< double > & positionOnTrack(void) const
returns the closest point on track to wire.
Definition: Link.h:482
std::vector< HepGeom::Point3D< double > > perfectPosition(void) const
returns perfect position from GEANT.
Definition: TRGCDCTrack.cc:259
double phi0(void) const
returns phi0.
Definition: Helix.h:278
const CLHEP::HepVector & a(void) const
returns helix parameters.
Definition: Helix.h:313
const HepGeom::Point3D< double > & positionOnWire(void) const
returns the closest point on wire to a track.
Definition: Link.h:475
virtual const CLHEP::Hep3Vector & x(void) const override
returns position vector.
Definition: TRGCDCTrack.h:173
double dPhi(void) const
returns dPhi to the closest point.
Definition: Link.h:537
std::string name(void) const
returns name.
Definition: TrackBase.h:185
static int level(void)
returns the debug level.
Definition: Debug.cc:67
const std::vector< TRGCDCLink * > & links(void) const
returns a vector to track segments.
Definition: TrackBase.cc:123
double kappa(void) const
returns kappa.
Definition: Helix.h:285
static std::vector< const TRGCDCTrack * > list(void)
returns a list of TRGCDCTrack's.
Definition: TRGCDCTrack.cc:86
const HepGeom::Point3D< double > ORIGIN
Origin 3D point.
virtual ~TRGCDCTrack()
Destructor.
Definition: TRGCDCTrack.cc:76
Abstract base class for different kinds of events.
STL namespace.