BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
TBuilderCosmic.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TBuilderCosmic.cxx,v 1.6 2010/03/31 09:58:59 liucy Exp $
3//-----------------------------------------------------------------------------
4// Filename : TBuilderCosmic.cc
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : [email protected]
8//-----------------------------------------------------------------------------
9// Description : A class to build a cosmic track.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13#ifdef TRKRECO_DEBUG_DETAIL
14#ifndef TRKRECO_DEBUG
15#define TRKRECO_DEBUG
16#endif
17#endif
18#include "TrkReco/TBuilderCosmic.h"
19#include "TrkReco/TMLink.h"
20#include "TrkReco/TTrack.h"
21#include "TrkReco/TLine0.h"
22#include "TrkReco/T3DLine.h"
23
24TBuilderCosmic::TBuilderCosmic(const std::string & name, float salvageLevel)
25: TBuilder0(name, salvageLevel), _fitter("TBuilderCosmic Fitter") {
26}
27
29}
30
31TTrack *
32TBuilderCosmic::buildStereo(TTrack & track, const AList<TMLink> & list) const {
33#ifdef TRKRECO_DEBUG_DETAIL
34 std::cout << name() << "(stereo) ... dump of stereo candidate hits" << std::endl;
35 AList<TMLink> tmp = list;
36 tmp.sort(SortByWireId);
37 std::cout << " ";
38 for (unsigned i = 0; i < tmp.length(); i++) {
39 TMLink * l = tmp[i];
40 std::cout << l->wire()->layerId() << "-";
41 std::cout << l->wire()->localId() << ",";
42 }
43 std::cout << std::endl;
44#endif
45
46 //...Check # of links...
47 if (list.length() < _lineSelector.nLinksStereo()) {
48#ifdef TRKRECO_DEBUG_DETAIL
49 std::cout << name() << "(stereo) ... rejected by nLinks(";
50 std::cout << list.length() << ") < ";
51 std::cout << _lineSelector.nLinks() << std::endl;
52#endif
53 return NULL;
54 }
55
56 //...Calculate s and z for every links...
57 unsigned n = list.length();
58 AList<TMLink> forLine;
59 for (unsigned i = 0; i < n; i++) {
60 TMLink * l = list[i];
61
62 //... Require Fitting vaildation
63 if(!(l->hit()->state()& WireHitFittingValid)) continue;
64
65 TMLink * t = new TMLink(* l);
66
67 //...Assuming wire position...
68 t->leftRight(2);
69 int err = track.szPosition(* t);
70 if (err) {
71 delete t;
72 continue;
73 }
74
75 //...Store the sz link...
76 t->link(l);
77 forLine.append(t);
78 }
79
80#ifdef TRKRECO_DEBUG_DETAIL
81 std::cout << name() << "(stereo) ... dump of sz links" << std::endl;
82 std::cout << " ";
83 tmp = forLine;
84 tmp.sort(SortByWireId);
85 for (unsigned i = 0; i < tmp.length(); i++) {
86 TMLink * l = tmp[i];
87 std::cout << l->wire()->layerId() << "-";
88 std::cout << l->wire()->localId() << ",";
89 }
90 std::cout << std::endl;
91#endif
92
93 //...Check # of sz links...
94 if (forLine.length() < _lineSelector.nLinksStereo()) {
95#ifdef TRKRECO_DEBUG_DETAIL
96 std::cout << name() << "(stereo) ... rejected by sz nLinks(";
97 std::cout << forLine.length() << ") < ";
98 std::cout << _lineSelector.nLinks() << std::endl;
99#endif
100 HepAListDeleteAll(forLine);
101 return NULL;
102 }
103
104 //...Make a line...
105 unsigned nLine = forLine.length();
106 TLine0 line(forLine);
107 int err = line.fit();
108
109 //...Linear fit...
110 if (err < 0) {
111#ifdef TRKRECO_DEBUG_DETAIL
112 std::cout << name() << "(stereo) ... linear fit failure. nLinks(";
113 std::cout << forLine.length() << ")" << std::endl;
114#endif
115 HepAListDeleteAll(forLine);
116 return NULL;
117 }
118
119#ifdef TRKRECO_DEBUG_DETAIL
120 std::cout << name() << "(stereo) ... dump of left-right" << std::endl;
121#endif
122
123 //...Decide Left or Right...
124 AList<TMLink> forNewLine;
125 for (unsigned i = 0; i < nLine; i++) {
126 TMLink * t = forLine[i];
127 TMLink * tl = new TMLink(* t);
128 TMLink * tr = new TMLink(* t);
129
131 tr->leftRight(WireHitRight);
132
133 int err = track.szPosition(* tl);
134 if (err) {
135 delete tl;
136 tl = NULL;
137 }
138 err = track.szPosition(* tr);
139 if (err) {
140 delete tr;
141 tr = NULL;
142 }
143 if ((tl == NULL) && (tr == NULL)) continue;
144
145 TMLink * best;
146 if (tl == NULL) best = tr;
147 else if (tr == NULL) best = tl;
148 else {
149 if (line.distance(* tl) < line.distance(* tr)) {
150 best = tl;
151 delete tr;
152 }
153 else {
154 best = tr;
155 delete tl;
156 }
157 }
158
159#ifdef TRKRECO_DEBUG_DETAIL
160 std::cout << " ";
161 std::cout << t->wire()->layerId() << "-";
162 std::cout << t->wire()->localId();
163 if (tl != NULL)
164 std::cout << ",left " << tl->position() << "," << line.distance(* tl);
165 if (tr != NULL)
166 std::cout << ",right " << tr->position() << "," << line.distance(* tr);
167 std::cout << std::endl;
168#endif
169
170 best->link(t->link());
171 forNewLine.append(best);
172 }
173
174 //...Check # of sz links...
175 if (forNewLine.length() < _lineSelector.nLinksStereo()) {
176#ifdef TRKRECO_DEBUG_DETAIL
177 std::cout << name() << "(stereo) ... rejected by lr nLinks(";
178 std::cout << forNewLine.length() << ") < ";
179 std::cout << _lineSelector.nLinks() << std::endl;
180#endif
181 HepAListDeleteAll(forLine);
182 HepAListDeleteAll(forNewLine);
183 return NULL;
184 }
185
186 //...Create new line...
187#ifdef TRKRECO_DEBUG_DETAIL
188 std::cout << name() << "(stereo) ... creating a new line" << std::endl;
189#endif
190 unsigned nNewLine = forNewLine.length();
191 TLine0 newLine(forNewLine);
192
193 //...Make a seed track again
194 err = newLine.fit();
195
196 //...Linear fit...
197 if (err < 0) {
198#ifdef TRKRECO_DEBUG_DETAIL
199 std::cout << name() << "(stereo) ... 2nd linear fit failure. nLinks(";
200 std::cout << forNewLine.length() << ")" << std::endl;
201#endif
202 HepAListDeleteAll(forLine);
203 HepAListDeleteAll(forNewLine);
204 return NULL;
205 }
206
207 //...Remove bad points...
208 AList<TMLink> bad;
209// newLine.refine(bad, 40.); //Liuqg, meaningless while without magnetic field
210// err = newLine.fit();
211// newLine.refine(bad, 20.);
212// err = newLine.fit();
213// newLine.refine(bad, 10.);
214// err = newLine.fit();
215
216 //...Linear fit again...
217 if (err < 0) {
218 HepAListDeleteAll(forLine);
219 HepAListDeleteAll(forNewLine);
220#ifdef TRKRECO_DEBUG_DETAIL
221 std::cout << " appendStereo cut ... new line 2nd linear fit failure. ";
222 std::cout << "# of links = " << n << "," << nLine;
223 std::cout << "," << nNewLine << std::endl;
224#endif
225 return NULL;
226 }
227
228 //...3D fit...
229 const AList<TMLink> & good = newLine.links();
230 unsigned nn = good.length();
231 for (unsigned i = 0; i < nn; i++) {
232 track.append(* good[i]->link());
233 }
234 Vector a(5);
235 a = track.helix().a();
236 a[3] = newLine.b();
237 a[4] = track.charge() * newLine.a();
238 track._helix->a(a);
239
240#ifdef LINE_COSMIC
241 T3DLine * Ltrack = new T3DLine(track);
242
243 //...Refine...
244 err = _fitter.fit(*Ltrack);
245 Ltrack->refine(bad, _trackSelector.maxSigma() * 30.);
246 err = _fitter.fit(*Ltrack);
247 Ltrack->refine(bad, _trackSelector.maxSigma() * 3.);
248 err = _fitter.fit(*Ltrack);
249// Ltrack->refine(bad, _trackSelector.maxSigma() * 0.21); //liuqg, for prelimilary test
250 track.refine(bad, _trackSelector.maxSigma());
251 err = _fitter.fit(*Ltrack);
252
253 //...Test it...
254/* if (! _trackSelector.select(*Ltrack)) {
255 HepAListDeleteAll(forLine);
256 HepAListDeleteAll(forNewLine);
257 delete Ltrack;
258 return NULL;
259 }
260*/
261 //...Termination...
262 HepAListDeleteAll(forLine);
263 HepAListDeleteAll(forNewLine);
264 track.removeLinks();
265 track.append(Ltrack->links());
266 Vector a1(5);
267 a1 = Ltrack->helix().a();
268 track._helix->a(a1);
269 delete Ltrack;
270 return & track;
271#endif
272
273 //...Refine...
274 err = _fitter.fit(track);
275 track.refine(bad, _trackSelector.maxSigma() * 30.);
276 err = _fitter.fit(track);
277 track.refine(bad, _trackSelector.maxSigma() * 3.);
278 err = _fitter.fit(track);
279 track.refine(bad, _trackSelector.maxSigma()); //liuqg, for prelimilary test
280// track.refine(bad, _trackSelector.maxSigma() * 0.21);
281 err = _fitter.fit(track);
282 //...Test it...
283 if (! _trackSelector.select(track)) {
284 HepAListDeleteAll(forLine);
285 HepAListDeleteAll(forNewLine);
286 return NULL;
287 }
288
289 //...Termination...
290 HepAListDeleteAll(forLine);
291 HepAListDeleteAll(forNewLine);
292 return & track;
293}
const Int_t n
DOUBLE_PRECISION tr[2]
const HepVector & a(void) const
returns helix parameters.
A class to represent a track in tracking.
Helix helix(void) const
approximated helix class
Definition: T3DLine.cxx:120
const std::string & name(void) const
returns name.
virtual ~TBuilderCosmic()
Destructor.
TTrack * buildStereo(TTrack &track, const AList< TMLink > &) const
appends stereo hits to a track.
TBuilderCosmic(const std::string &name, float salvageLevel)
Constructor.
int fit(TTrackBase &) const
A class to represent a track in tracking.
double distance(const TMLink &) const
returns distance to a position of TMLink itself. (not to a wire)
double b(void) const
returns coefficient b.
double a(void) const
returns coefficient a.
unsigned state(void) const
returns state.
unsigned localId(void) const
returns local id in a wire layer.
unsigned layerId(void) const
returns layer id.
unsigned nLinks(void) const
returns min. # of hits(TMLinks) requried.
double maxSigma(void) const
returns max. sigma for each TMLink.
unsigned nLinksStereo(void) const
returns min. # of stereo hits(TMLinks) requried.
bool select(TTrackBase &) const
returns true if given track satisfys criteria after fitting.
Definition: TMSelector.cxx:53
virtual int fit(void)
fits itself by a default fitter. Error was happened if return value is not zero.
Definition: TTrackBase.cxx:357
virtual void refine(AList< TMLink > &list, double maxSigma)
removes bad points by pull. The bad points are removed from the track, and are returned in 'list'.
Definition: TTrackBase.cxx:170
virtual void removeLinks(void)
Definition: TTrackBase.cxx:189
void append(TMLink &)
appends a TMLink.
Definition: TTrackBase.cxx:362
const AList< TMLink > & links(unsigned mask=0) const
returns a list of masked TMLinks assigned to this track. 'mask' will be applied if mask is not 0.
Definition: TTrackBase.cxx:297
A class to represent a track in tracking.
const Helix & helix(void) const
returns helix parameter.
int szPosition(TMLink &link) const
calculates arc length and z for a stereo hit.
Definition: TTrack.cxx:3372
double charge(void) const
returns charge.
int t()
Definition: t.c:1