Belle II Software  release-05-01-25
CircleFitter.cc
1 //-----------------------------------------------------------------------------
2 // $Id$
3 //-----------------------------------------------------------------------------
4 // Filename : CircleFitter.cc
5 // Section : TRG CDC
6 // Owner : Yoshihito Iwasaki
7 // Email : yoshihito.iwasaki@kek.jp
8 //-----------------------------------------------------------------------------
9 // Description : A class to fit a TTrackBase object.
10 //-----------------------------------------------------------------------------
11 // $Log$
12 //-----------------------------------------------------------------------------
13 
14 #define TRGCDC_SHORT_NAMES
15 
16 #include "trg/trg/Debug.h"
17 #include "trg/cdc/CircleFitter.h"
18 #include "trg/cdc/TrackBase.h"
19 #include "trg/cdc/Circle.h"
20 #include "trg/cdc/Link.h"
21 #include "trg/cdc/Lpav.h"
22 
23 using namespace std;
24 
25 namespace Belle2 {
31  TCCFitter::TCCFitter(const std::string& name)
32  : TCFitter(name), _charge(0.), _radius(0.), _center(Point3D(0., 0., 0.))
33  {
34  }
35 
36  TCCFitter::~TCCFitter()
37  {
38  }
39 
40  int
41  TCCFitter::fit(TCTBase& t) const
42  {
43 
44  TRGDebug::enterStage("TCCFitter::fit");
45 // int oldLevel = TRGDebug::level();
46 // TRGDebug::level(10);
47 
48  //...Already fitted ?...
49  if (t.fitted()) {
50  if (TRGDebug::level() > 1)
51  cout << TRGDebug::tab() << "Circle is fitted already" << endl;
52  TRGDebug::leaveStage("TCCFitter::fit");
54  }
55 
56  //...Check # of hits...
57  if (t.links().size() < 3) {
58  if (TRGDebug::level() > 1)
59  cout << TRGDebug::tab() << "#links is less than 3" << endl;
60  TRGDebug::leaveStage("TCCFitter::fit");
61  return TRGCDCFitErrorFewHits;
62  }
63 
64  //...Hit loop...
65  TCLpav circle;
66  const unsigned n = t.links().size();
67  for (unsigned i = 0; i < n; i++) {
68  const TCLink* l = t.links()[i];
69  const Belle2::TRGCDCCellHit* h = l->hit();
70 
71  //...Check next hit...
72  Point3D point;
73  if (h->state() & CellHitPatternLeft)
74  point = h->position(CellHitLeft);
75  else if (h->state() & CellHitPatternRight)
76  point = h->position(CellHitRight);
77  else
78  point = h->xyPosition();
79 
80  //...Presently weight is not used.
81  // float weight = 1. / (h->distance() * h->distance());
82  // float weight = 1. / h->distance();
83 
84  circle.add_point(point.x(), point.y()); //, weight);
85 
86  if (TRGDebug::level() > 2) {
87  cout << TRGDebug::tab() << "point " << i;
88  cout << point << endl;
89  }
90  }
91 
92  if (circle.fit() < 0.0 || circle.kappa() == 0.0) {
93  if (TRGDebug::level() > 1)
94  cout << TRGDebug::tab() << "fit failed" << endl;
95  TRGDebug::leaveStage("TCCFitter::fit");
96  return TRGCDCFitFailed;
97  }
98  CLHEP::HepVector v(circle.center());
99  _center.setX(v(1));
100  _center.setY(v(2));
101  _radius = circle.radius();
102 
103  //...Determine charge...Better way???
104  int qSum = 0;
105  for (unsigned i = 0; i < n; i++) {
106  const TCLink* l = t.links()[i];
107  if (l == 0) continue;
108 
109  const Belle2::TRGCDCCellHit* h = l->hit();
110  if (h == 0) continue;
111 
112  float q = (_center.cross(h->xyPosition())).z();
113  if (q > 0.) qSum += 1;
114  else qSum -= 1;
115  }
116  if (qSum >= 0) _charge = +1.;
117  else _charge = -1.;
118  _radius *= _charge;
119 
120  if (t.objectType() == TRGCDCCircleType)
121  ((TRGCDCCircle&) t).property(_charge, _radius, _center);
122  fitDone(t);
123 
124  //...Update link information...
125  for (unsigned i = 0; i < n; i++) {
126  TCLink* l = t.links()[i];
127  if (l == 0) continue;
128 
129  t.approach2D(* l);
130  }
131 
132  if (TRGDebug::level() > 1) {
133  cout << TRGDebug::tab() << "fitted successfully" << endl;
134  cout << TRGDebug::tab() << " charge=" << _charge
135  << ",radius=" << _radius << ",center=" << _center << endl;
136  }
137  TRGDebug::leaveStage("TCCFitter::fit");
138 
139  return 0;
140  }
141 
143 } // namespace Belle
144 
TRGCDCFitAlreadyFitted
#define TRGCDCFitAlreadyFitted
parameter to identify fit result
Definition: Fitter.h:32
Belle2::TRGDebug::level
static int level(void)
returns the debug level.
Definition: Debug.cc:72
Belle2::TRGCDCCellHit
A class to represent a wire hit in CDC.
Definition: CellHit.h:75
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
TRGCDCFitErrorFewHits
#define TRGCDCFitErrorFewHits
parameter to identify fit result
Definition: Fitter.h:34
Belle2::TRGDebug::tab
static std::string tab(void)
returns tab spaces.
Definition: Debug.cc:52
TRGCDCFitFailed
#define TRGCDCFitFailed
parameter to identify fit result
Definition: Fitter.h:36
Belle2::TRGDebug::leaveStage
static void leaveStage(const std::string &stageName)
Declare that you leave a stage.
Definition: Debug.cc:39
Belle2::TRGDebug::enterStage
static void enterStage(const std::string &stageName)
Declare that you enter new stage.
Definition: Debug.cc:29
Belle2::Point3D
HepGeom::Point3D< double > Point3D
3D point
Definition: Cell.h:33