BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
TTrackMC.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TTrackMC.cxx,v 1.5 2010/03/31 09:58:59 liucy Exp $
3//-----------------------------------------------------------------------------
4// Filename : TTrackMC.cc
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : [email protected]
8//-----------------------------------------------------------------------------
9// Description : A class to have MC information of TTrack.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13/* for copysign */
14#if defined(__sparc)
15# if defined(__EXTENSIONS__)
16# include <cmath>
17# else
18# define __EXTENSIONS__
19# include <cmath>
20# undef __EXTENSIONS__
21# endif
22#elif defined(__GNUC__)
23# if defined(_XOPEN_SOURCE)
24# include <cmath>
25# else
26# define _XOPEN_SOURCE
27# include <cmath>
28# undef _XOPEN_SOURCE
29# endif
30#endif
31#include <cfloat>
32#include "TrkReco/TMDCUtil.h"
33#include "TrkReco/TMDCWireHitMC.h"
34#include "TrkReco/TrkReco.h"
35#include "TrkReco/TTrack.h"
36#include "TrkReco/TTrackMC.h"
37#include "TrkReco/TTrackHEP.h"
38//#include "tables/cdc.h"
39#include "MdcTables/MdcTables.h"
40
41#if defined(__alpha)
42#define DBL_MIN 2.2250738585072014E-308
43#define FLT_MIN 1.175494351E-38F
44#endif
45
46TTrackMC::TTrackMC(const TTrack & t)
47: _t(t),
48 _hep(0),
49 _hepID(-1),
50 _wireFraction(-999.),
51 _wireFractionHEP(-999.),
52 _charge(false),
53 _ptFraction(-999.),
54 _pzFraction(-999.),
55 _ptResidual(-999.),
56 _pzResidual(-999.),
57 _ptPull(-999.),
58 _pzPull(-999.),
59 _state(0),
60 _quality(0) {
61}
62
64}
65
66void
68 _state = 0;
69 _quality = 0;
70/*
71 //...Prepare counters...
72 unsigned nHep = TTrackHEP::list().length();
73 unsigned nTrk = TrkReco::getTrkReco()->tracks().length();
74 unsigned * N1 = (unsigned *) malloc(nHep * sizeof(unsigned));
75 float * F1 = (float *) malloc(nHep * sizeof(float));
76 unsigned N2 = 0;
77 for (unsigned i = 0; i < nHep; i++) {
78 N1[i] = 0;
79 F1[i] = 0.;
80 }
81
82 //...Prepare for fraction F1...
83// const AList<TMLink> & cores = _t.cores();
84 const AList<TMLink> & cores = _t.finalHits();
85 unsigned nCores = cores.length();
86 for (unsigned i = 0; i < nCores; i++) {
87 TMLink * t = cores[i];
88 int hepID = t->hit()->mc()->hep()->id();
89 ++N1[hepID];
90 }
91
92 //...Calculate fraction F1 and find the best HEP...
93 int bestHep = -1;
94 TTrackHEP * hep = 0;
95 float bestF1 = 0.;
96 for (unsigned i = 0; i < nHep; i++) {
97 if (nCores) F1[i] = (float) N1[i] / (float) nCores;
98 if (F1[i] > bestF1) {
99 bestHep = i;
100 bestF1 = F1[i];
101 }
102 }
103
104 //...Check HEP...
105 float F2 = 0.;
106 if (bestHep != -1) {
107 hep = TTrackHEP::list()[bestHep];
108 unsigned nAll = 0;
109 for (unsigned i = 0; i < hep->hits().length(); i++) {
110 const TMDCWireHit * hit = hep->hits()[i]->hit();
111 if (! hit) continue;
112 if (hit->state() & WireHitInvalidForFit) continue;
113
114 ++nAll;
115 if (hit->track() == & _t) ++N2;
116 }
117
118 //...Calculate fraction F2...
119 if (nAll) F2 = (float) N2 / (float) nAll;
120 }
121
122 //...Store results...
123 _hepID = bestHep;
124 _hep = hep;
125 _wireFraction = bestF1;
126 _wireFractionHEP = F2;
127
128 //...Compare charge and momentum...
129 compare();
130
131 //...Classification...
132 classify();
133
134 //...Termination...
135 free(N1);
136 free(F1);
137*/
138}
139
140void
141TTrackMC::dump(const std::string & msg, const std::string & pre) const {
142 std::cout << msg;
143 std::cout << _t.name() << ":";
144 std::cout << "state=" << _state << ":";
145 if (_quality & TTrackGood) std::cout << "good :";
146 else if (_quality & TTrackGhost) std::cout << "ghost :";
147 else if (_quality & TTrackBad) std::cout << "bad :";
148 else if (_quality & TTrackCharge) std::cout << "bad :";
149 else if (_quality & TTrackGarbage) std::cout << "garbage:";
150 else std::cout << "classification error:";
151 bitDisplay(_quality, 23, 15); std::cout << ":";
152 std::cout << _hepID << ":";
153 std::cout << _wireFraction << "," << _wireFractionHEP << ":";
154 std::cout << _ptFraction << "," << _pzFraction;
155 std::cout << std::endl;
156}
157
158void
159TTrackMC::compare(void) {
160 if (! _hep) return;
161
162 //...Get charge of HEP particle(This part should be done by LUCHARGE)...
163 int id = _hep->pType();
164 int aId = abs(id);
165 if (aId == 11 || aId == 13 || aId == 15) id *= -1;
166
167 //...Compare charge...
168 if ((int) _t.charge() * id > 0) _charge = true;
169
170 //...Get hep mom. at the inner-most hit...
171// AList<TMLink> list = _t.cores();
172 AList<TMLink> list = _t.finalHits();
173 unsigned n = list.length();
174 bool found = false;
175 Vector3 pHep;
176 Vector3 vHep;
177 for (unsigned i = 0; i < n; i++) {
178 TMLink * inner = InnerMost(list);
179 if (inner->hit()->mc()->hep() == _hep) {
180 pHep = inner->hit()->mc()->momentum();
181 vHep = inner->hit()->mc()->entrance();
182 found = true;
183 break;
184 }
185 list.remove(inner);
186 }
187 Helix hHep = Helix(vHep, pHep, copysign(1., id));
188 hHep.pivot(_t.helix().pivot());
189 pHep = hHep.momentum();
190
191 //...For debug...
192 if (! found) {
193 std::cout << "TTrackMC::compare !!! something wrong with mc hits"
194 << std::endl;
195
196 //...For debug...
197// list = _t.cores();
198// for (unsigned i = 0; i < list.length(); i++) {
199// TMLink * inner = innerMost(list);
200// std::cout << i << " " << inner << ":" << inner->hit()->mc()->hep();
201// std::cout << " " << _hep << std::endl;
202// if (inner->hit()->mc()->hep() == _hep) {
203// pHep = inner->hit()->mc()->momentum();
204// break;
205// }
206// list.remove(inner);
207// }
208// TMLink * t = 0;
209// t->hit();
210 //...For debug end...
211
212 return;
213 }
214
215 //...Fill caches...
216 _residual = _t.p() - pHep;
217 _cosOpen = pHep.unit().dot(_t.p().unit());
218
219 //...Compare pt...
220 double pt = _t.pt();
221 double ptHep = sqrt(pHep.x() * pHep.x() + pHep.y() * pHep.y());
222 _ptResidual = pt - ptHep;
223 const Helix & h = _t.helix();
224 Vector dPt(5, 0);
225 dPt[2] = - 1. / (h.kappa() * h.kappa());
226 double ptError2 = h.Ea().similarity(dPt);
227 if(ptError2<0.0) {
228 std::cout << h.kappa() << " " << h.Ea() << " dPt=" << dPt << std::endl;
229 }
230 double ptError = (ptError2 > 0.) ? sqrt(ptError2) : (DBL_MIN);
231 _ptPull = (ptError2 > 0.) ? (_ptResidual) / ptError : (FLT_MAX);
232 _ptFraction = (fabs(ptHep)>(FLT_MIN)) ? _ptResidual / ptHep : 0.0;
233
234 //...Compare pz...
235 double pz = _t.pz();
236 double pzHep = pHep.z();
237 _pzResidual = pz - pzHep;
238 Vector dPz(5, 0);
239 dPz[2] = - h.tanl() / (h.kappa() * h.kappa());
240 dPz[4] = 1. / h.kappa();
241 double pzError2 = h.Ea().similarity(dPz);
242 if(pzError2<0.0) {
243 std::cout << h.kappa() << " " << h.Ea() << " dPz=" << dPz << std::endl;
244 }
245 double pzError = (pzError2 > 0.) ? sqrt(pzError2) : (DBL_MIN);
246 _pzPull = (pzError2 > 0.) ? (_pzResidual) / pzError : (FLT_MAX);
247 _pzFraction = (abs(pzHep)>FLT_MIN) ? (_pzResidual / pzHep) : (FLT_MAX);
248}
249
250void
251TTrackMC::classify(void) {
252 _state |= TTrackClassified;
253 _quality = TTrackGarbage;
254
255 //...HEP matching...
256 if (! _hep) return;
257 _quality |= TTrackHep;
258 if (fabs(_ptFraction) < .1) _quality |= TTrackPt;
259 if (fabs(_pzFraction) < .1) _quality |= TTrackPz;
260 float momResidual = sqrt(_ptResidual * _ptResidual +
261 _pzResidual * _pzResidual);
262
263 if ((momResidual < 0.100) && (_cosOpen > 0.99))
264 _quality |= TTrackMatchingLoose;
265 if ((momResidual < 0.020) && (_cosOpen > 0.998))
266 _quality |= TTrackMatchingTight;
267
268 //...Wire fraction...
269 if (_wireFraction < 0.8) return;
270 _quality |= TTrackWire;
271 _quality |= TTrackCharge;
272
273 //...Charge matching...
274 if (! _charge) return;
275 _quality |= TTrackBad;
276
277 //...Momentum matching...
278 if (_quality & TTrackMatchingLoose)
279 _quality |= TTrackGhost;
280
281 //...TTrackGood is set by TrkReco after checking uniqueness...
282}
283
284std::string
286 return TrackMCQualityString(_quality);
287}
288
289std::string
290TrackMCStatus(unsigned quality) {
291 //...This is a local function to hide from user...
292
293 std::string matching;
294 if (quality & TTrackHep) {
295 if (quality & TTrackMatchingTight) matching += "tight";
296 else if (quality & TTrackMatchingLoose) matching += "loose";
297 else matching = "bad";
298 }
299 return TrackMCQualityString(quality) + " " + matching;
300}
301
302std::string
304 return TrackMCStatus(m.quality());
305}
306
307std::string
309 return TrackMCStatus(m.quality);
310}
311
312std::string
313TrackMCQualityString(unsigned quality) {
314 if (quality & TTrackGood) return std::string("Good");
315 else if (quality & TTrackGhost) return std::string("Ghost");
316 else if (quality & TTrackBad) return std::string("Bad");
317 else if (quality & TTrackCharge) return std::string("Charge");
318 else if (quality & TTrackGarbage) return std::string("Garbage");
319 return std::string("Unknown");
320}
const Int_t n
void bitDisplay(unsigned)
Definition: TMDCUtil.cxx:85
std::string TrackMCQualityString(unsigned quality)
Definition: TTrackMC.cxx:313
std::string TrackMCQualityString(unsigned quality)
Definition: TTrackMC.cxx:313
std::string TrackMCStatus(unsigned quality)
Definition: TTrackMC.cxx:290
Hep3Vector momentum(double dPhi=0.) const
returns momentum vector after rotating angle dPhi in phi direction.
const HepSymMatrix & Ea(void) const
returns error matrix.
const HepPoint3D & pivot(void) const
returns pivot position.
const Hep3Vector & momentum(void) const
returns momentum vector at the entrance.
const TTrackHEP *const hep(void) const
returns a pointer to a GEN_HEPEVT.
const HepPoint3D & entrance(void) const
returns an entrance point.
const TMDCWireHitMC *const mc(void) const
returns a pointer to TMDCWireHitMC.
int pType(void) const
returns particle type.
A class to have MC information of TTrack.
virtual ~TTrackMC()
Destructor.
Definition: TTrackMC.cxx:63
void update(void)
updates information.
Definition: TTrackMC.cxx:67
unsigned quality(void) const
returns quality.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
Definition: TTrackMC.cxx:141
std::string qualityString(void) const
returns quality.
Definition: TTrackMC.cxx:285
A class to represent a track in tracking.
const Helix & helix(void) const
returns helix parameter.
const std::string & name(void) const
returns/sets name.
double pt(void) const
returns Pt.
double pz(void) const
returns Pz.
const AList< TMLink > & finalHits(void) const
finds cathode hits associated to this track.
double charge(void) const
returns charge.
Hep3Vector p(void) const
returns momentum.
int t()
Definition: t.c:1