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