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