BOSS 8.0.0
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 : yoshihito.iwasaki@kek.jp
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 "TrkReco/TMDCUtil.h"
32#include "TrkReco/TMDCWireHitMC.h"
33#include "TrkReco/TTrack.h"
34#include "TrkReco/TTrackHEP.h"
35#include "TrkReco/TTrackMC.h"
36// #include "TrkReco/TrkReco.h"
37#include <cfloat>
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
63
64void TTrackMC::update( void ) {
65 _state = 0;
66 _quality = 0;
67 /*
68 //...Prepare counters...
69 unsigned nHep = TTrackHEP::list().length();
70 unsigned nTrk = TrkReco::getTrkReco()->tracks().length();
71 unsigned * N1 = (unsigned *) malloc(nHep * sizeof(unsigned));
72 float * F1 = (float *) malloc(nHep * sizeof(float));
73 unsigned N2 = 0;
74 for (unsigned i = 0; i < nHep; i++) {
75 N1[i] = 0;
76 F1[i] = 0.;
77 }
78
79 //...Prepare for fraction F1...
80 // const AList<TMLink> & cores = _t.cores();
81 const AList<TMLink> & cores = _t.finalHits();
82 unsigned nCores = cores.length();
83 for (unsigned i = 0; i < nCores; i++) {
84 TMLink * t = cores[i];
85 int hepID = t->hit()->mc()->hep()->id();
86 ++N1[hepID];
87 }
88
89 //...Calculate fraction F1 and find the best HEP...
90 int bestHep = -1;
91 TTrackHEP * hep = 0;
92 float bestF1 = 0.;
93 for (unsigned i = 0; i < nHep; i++) {
94 if (nCores) F1[i] = (float) N1[i] / (float) nCores;
95 if (F1[i] > bestF1) {
96 bestHep = i;
97 bestF1 = F1[i];
98 }
99 }
100
101 //...Check HEP...
102 float F2 = 0.;
103 if (bestHep != -1) {
104 hep = TTrackHEP::list()[bestHep];
105 unsigned nAll = 0;
106 for (unsigned i = 0; i < hep->hits().length(); i++) {
107 const TMDCWireHit * hit = hep->hits()[i]->hit();
108 if (! hit) continue;
109 if (hit->state() & WireHitInvalidForFit) continue;
110
111 ++nAll;
112 if (hit->track() == & _t) ++N2;
113 }
114
115 //...Calculate fraction F2...
116 if (nAll) F2 = (float) N2 / (float) nAll;
117 }
118
119 //...Store results...
120 _hepID = bestHep;
121 _hep = hep;
122 _wireFraction = bestF1;
123 _wireFractionHEP = F2;
124
125 //...Compare charge and momentum...
126 compare();
127
128 //...Classification...
129 classify();
130
131 //...Termination...
132 free(N1);
133 free(F1);
134 */
135}
136
137void TTrackMC::dump( const std::string& msg, const std::string& pre ) const {
138 std::cout << msg;
139 std::cout << _t.name() << ":";
140 std::cout << "state=" << _state << ":";
141 if ( _quality & TTrackGood ) std::cout << "good :";
142 else if ( _quality & TTrackGhost ) std::cout << "ghost :";
143 else if ( _quality & TTrackBad ) std::cout << "bad :";
144 else if ( _quality & TTrackCharge ) std::cout << "bad :";
145 else if ( _quality & TTrackGarbage ) std::cout << "garbage:";
146 else std::cout << "classification error:";
147 bitDisplay( _quality, 23, 15 );
148 std::cout << ":";
149 std::cout << _hepID << ":";
150 std::cout << _wireFraction << "," << _wireFractionHEP << ":";
151 std::cout << _ptFraction << "," << _pzFraction;
152 std::cout << std::endl;
153}
154
155void TTrackMC::compare( void ) {
156 if ( !_hep ) return;
157
158 //...Get charge of HEP particle(This part should be done by LUCHARGE)...
159 int id = _hep->pType();
160 int aId = abs( id );
161 if ( aId == 11 || aId == 13 || aId == 15 ) id *= -1;
162
163 //...Compare charge...
164 if ( (int)_t.charge() * id > 0 ) _charge = true;
165
166 //...Get hep mom. at the inner-most hit...
167 // AList<TMLink> list = _t.cores();
168 AList<TMLink> list = _t.finalHits();
169 unsigned n = list.length();
170 bool found = false;
171 Vector3 pHep;
172 Vector3 vHep;
173 for ( unsigned i = 0; i < n; i++ )
174 {
175 TMLink* inner = InnerMost( list );
176 if ( inner->hit()->mc()->hep() == _hep )
177 {
178 pHep = inner->hit()->mc()->momentum();
179 vHep = inner->hit()->mc()->entrance();
180 found = true;
181 break;
182 }
183 list.remove( inner );
184 }
185 Helix hHep = Helix( vHep, pHep, copysign( 1., id ) );
186 hHep.pivot( _t.helix().pivot() );
187 pHep = hHep.momentum();
188
189 //...For debug...
190 if ( !found )
191 {
192 std::cout << "TTrackMC::compare !!! something wrong with mc hits" << std::endl;
193
194 //...For debug...
195 // list = _t.cores();
196 // for (unsigned i = 0; i < list.length(); i++) {
197 // TMLink * inner = innerMost(list);
198 // std::cout << i << " " << inner << ":" << inner->hit()->mc()->hep();
199 // std::cout << " " << _hep << std::endl;
200 // if (inner->hit()->mc()->hep() == _hep) {
201 // pHep = inner->hit()->mc()->momentum();
202 // break;
203 // }
204 // list.remove(inner);
205 // }
206 // TMLink * t = 0;
207 // t->hit();
208 //...For debug end...
209
210 return;
211 }
212
213 //...Fill caches...
214 _residual = _t.p() - pHep;
215 _cosOpen = pHep.unit().dot( _t.p().unit() );
216
217 //...Compare pt...
218 double pt = _t.pt();
219 double ptHep = sqrt( pHep.x() * pHep.x() + pHep.y() * pHep.y() );
220 _ptResidual = pt - ptHep;
221 const Helix& h = _t.helix();
222 Vector dPt( 5, 0 );
223 dPt[2] = -1. / ( h.kappa() * h.kappa() );
224 double ptError2 = h.Ea().similarity( dPt );
225 if ( ptError2 < 0.0 )
226 { std::cout << h.kappa() << " " << h.Ea() << " dPt=" << dPt << std::endl; }
227 double ptError = ( ptError2 > 0. ) ? sqrt( ptError2 ) : ( DBL_MIN );
228 _ptPull = ( ptError2 > 0. ) ? ( _ptResidual ) / ptError : ( FLT_MAX );
229 _ptFraction = ( fabs( ptHep ) > ( FLT_MIN ) ) ? _ptResidual / ptHep : 0.0;
230
231 //...Compare pz...
232 double pz = _t.pz();
233 double pzHep = pHep.z();
234 _pzResidual = pz - pzHep;
235 Vector dPz( 5, 0 );
236 dPz[2] = -h.tanl() / ( h.kappa() * h.kappa() );
237 dPz[4] = 1. / h.kappa();
238 double pzError2 = h.Ea().similarity( dPz );
239 if ( pzError2 < 0.0 )
240 { std::cout << h.kappa() << " " << h.Ea() << " dPz=" << dPz << std::endl; }
241 double pzError = ( pzError2 > 0. ) ? sqrt( pzError2 ) : ( DBL_MIN );
242 _pzPull = ( pzError2 > 0. ) ? ( _pzResidual ) / pzError : ( FLT_MAX );
243 _pzFraction = ( abs( pzHep ) > FLT_MIN ) ? ( _pzResidual / pzHep ) : ( FLT_MAX );
244}
245
246void TTrackMC::classify( void ) {
247 _state |= TTrackClassified;
248 _quality = TTrackGarbage;
249
250 //...HEP matching...
251 if ( !_hep ) return;
252 _quality |= TTrackHep;
253 if ( fabs( _ptFraction ) < .1 ) _quality |= TTrackPt;
254 if ( fabs( _pzFraction ) < .1 ) _quality |= TTrackPz;
255 float momResidual = sqrt( _ptResidual * _ptResidual + _pzResidual * _pzResidual );
256
257 if ( ( momResidual < 0.100 ) && ( _cosOpen > 0.99 ) ) _quality |= TTrackMatchingLoose;
258 if ( ( momResidual < 0.020 ) && ( _cosOpen > 0.998 ) ) _quality |= TTrackMatchingTight;
259
260 //...Wire fraction...
261 if ( _wireFraction < 0.8 ) return;
262 _quality |= TTrackWire;
263 _quality |= TTrackCharge;
264
265 //...Charge matching...
266 if ( !_charge ) return;
267 _quality |= TTrackBad;
268
269 //...Momentum matching...
270 if ( _quality & TTrackMatchingLoose ) _quality |= TTrackGhost;
271
272 //...TTrackGood is set by TrkReco after checking uniqueness...
273}
274
275std::string TTrackMC::qualityString( void ) const { return TrackMCQualityString( _quality ); }
276
277std::string TrackMCStatus( unsigned quality ) {
278 //...This is a local function to hide from user...
279
280 std::string matching;
281 if ( quality & TTrackHep )
282 {
283 if ( quality & TTrackMatchingTight ) matching += "tight";
284 else if ( quality & TTrackMatchingLoose ) matching += "loose";
285 else matching = "bad";
286 }
287 return TrackMCQualityString( quality ) + " " + matching;
288}
289
290std::string TrackMCStatus( const TTrackMC& m ) { return TrackMCStatus( m.quality() ); }
291
292std::string TrackMCStatus( const MdcRec_mctrk& m ) { return TrackMCStatus( m.quality ); }
293
294std::string TrackMCQualityString( unsigned quality ) {
295 if ( quality & TTrackGood ) return std::string( "Good" );
296 else if ( quality & TTrackGhost ) return std::string( "Ghost" );
297 else if ( quality & TTrackBad ) return std::string( "Bad" );
298 else if ( quality & TTrackCharge ) return std::string( "Charge" );
299 else if ( quality & TTrackGarbage ) return std::string( "Garbage" );
300 return std::string( "Unknown" );
301}
const Int_t n
void bitDisplay(unsigned)
Definition TMDCUtil.cxx:82
std::string TrackMCQualityString(unsigned quality)
Definition TTrackMC.cxx:294
std::string TrackMCQualityString(unsigned quality)
Definition TTrackMC.cxx:294
std::string TrackMCStatus(unsigned quality)
Definition TTrackMC.cxx:277
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:62
void update(void)
updates information.
Definition TTrackMC.cxx:64
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:137
std::string qualityString(void) const
returns quality.
Definition TTrackMC.cxx:275
A class to represent a track in tracking.
const AList< TMLink > & finalHits(void) const
finds cathode hits associated to this track.
double charge(void) const
returns charge.
int t()
Definition t.c:1