BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TTrackManager.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TTrackManager.cxx,v 1.70 2022/01/28 22:04:42 maqm Exp $
3//-----------------------------------------------------------------------------
4// Filename : TTrackManager.cc
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : yoshihito.iwasaki@kek.jp
8//-----------------------------------------------------------------------------
9// Description : A manager of TTrack information to make outputs as Reccdc_trk.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11//-----------------------------------------------------------------------------
12
13/* for isnan */
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
32#define TTRACKMANAGER_INLINE_DEFINE_HERE
33#include <cstdlib>
34#include <cstring>
35#include <values.h>
36
37// #include "belle.h"
38// #include "CLHEP/String/Strings.h"
39// #include "basf/basfshm.h"
40#include "MdcTables/MdcTables.h"
41#include "MdcTables/TrkTables.h"
42#include "TrkReco/TMDCWireHit.h"
43#include "TrkReco/TMDCWireHitMC.h"
44#include "TrkReco/TTrack.h"
45#include "TrkReco/TTrackHEP.h"
46#include "TrkReco/TTrackMC.h"
47#include "TrkReco/TTrackManager.h"
48// #include "TrkReco/TrkReco.h"
49
50#include "GaudiKernel/Bootstrap.h"
51#include "GaudiKernel/IDataManagerSvc.h"
52#include "GaudiKernel/IDataProviderSvc.h"
53#include "GaudiKernel/IMessageSvc.h"
54#include "GaudiKernel/ISvcLocator.h"
55#include "GaudiKernel/MsgStream.h"
56#include "GaudiKernel/PropertyMgr.h"
57#include "GaudiKernel/SmartDataPtr.h"
58#include "GaudiKernel/StatusCode.h"
59
60#include "EventModel/EventModel.h"
61#include "GaudiKernel/ContainedObject.h"
62#include "GaudiKernel/ObjectVector.h"
63#include "GaudiKernel/SmartRef.h"
64#include "GaudiKernel/SmartRefVector.h"
65
66#include "EvTimeEvent/RecEsTime.h"
67
68#include "Identifier/Identifier.h"
69#include "Identifier/MdcID.h"
70
71// #include "TrkReco/TSvdAssociator.h" // jtanaka 000925
72
73// extern BasfSharedMem * BASF_Sharedmem;
74
76 : _maxMomentum( 10. )
77 , _sigmaCurlerMergeTest( sqrt( 100. ) )
78 , _nCurlerMergeTest( 4 )
79 , _debugLevel( 0 )
80 , _fitter( "TTrackManager Fitter" )
81 , _cFitter( "TTrackManager 2D Fitter" )
82 , _s( 0 )
83 , m_pmgnIMF( nullptr )
84 , m_rawDataProviderSvc( nullptr ) {}
85
87
88std::string TTrackManager::version( void ) const { return std::string( "2.27" ); }
89
90void TTrackManager::dump( const std::string& msg, const std::string& pre ) const {
91 bool def = ( msg == "" ) ? true : false;
92 /*
93 if (msg.find("summary") != std::string::npos || msg.find("detail") != std::string::npos)
94 { struct summary s;
95 // bzero((char*)& s, sizeof(struct summary));
96 memset((char*)& s, 0, sizeof(struct summary));
97 for (int i = 0; i < BASF_Sharedmem->nprocess(); i++) {
98 int size;
99 struct summary & r = * (struct summary *)
100 BASF_Sharedmem->get_pointer(i, "TrkMgrSum", & size);
101 s._nEvents += r._nEvents;
102 s._nTracks += r._nTracks;
103 s._nTracksAll += r._nTracksAll;
104 s._nTracks2D += r._nTracks2D;
105 s._nTracksFinal += r._nTracksFinal;
106 s._nSuperMoms += r._nSuperMoms;
107 s._nToBeMerged += r._nToBeMerged;
108 s._nToBeMergedMoreThanTwo += r._nToBeMergedMoreThanTwo;
109 }
110
111 std::cout << pre;
112 std::cout << "all events : " << s._nEvents << std::endl;
113 std::cout << pre;
114 std::cout << "all tracks : " << s._nTracksAll << std::endl;
115 std::cout << pre;
116 std::cout << " good tracks : " << s._nTracks << std::endl;
117 std::cout << pre;
118 std::cout << " 2D tracks : " << s._nTracks2D << std::endl;
119 std::cout << pre;
120 std::cout << " final tracks : " << s._nTracksFinal << std::endl;
121 std::cout << pre;
122 std::cout << " super mom. : " << s._nSuperMoms << std::endl;
123 std::cout << pre;
124 std::cout << " to be mreged : " << s._nToBeMerged << std::endl;
125 std::cout << pre;
126 std::cout << " to be mreged2: " << s._nToBeMergedMoreThanTwo
127 << std::endl;
128 }
129 */
130 if ( def || msg.find( "eventSummary" ) != std::string::npos ||
131 msg.find( "detail" ) != std::string::npos )
132 {
133 std::cout << pre << "tracks reconstructed : " << _tracksAll.length() << std::endl;
134 std::cout << pre << "good tracks : " << _tracks.length() << std::endl;
135 std::cout << pre << "2D tracks : " << _tracks2D.length() << std::endl;
136 std::cout << pre << "Track list:" << std::endl;
137
138 std::string tab = pre;
139 std::string spc = " ";
140 for ( unsigned i = 0; i < _tracksAll.length(); i++ )
141 {
142 std::cout << tab << TrackDump( *_tracksAll[i] ) << std::endl;
143 if ( msg.find( "hits" ) != std::string::npos ||
144 msg.find( "detail" ) != std::string::npos )
145 Dump( _tracksAll[i]->links(), "hits sort flag" );
146 }
147 }
148}
149
151 const AList<TMDCWireHit>& stereo,
152 const AList<TTrack>& tracks ) const {
153 //...Coded by jtanaka...
154
155 int i = 0;
156 while ( const TTrack* t = tracks[i++] )
157 {
158 int j = 0;
159 while ( TMDCWireHit* a = axial[j++] )
160 {
161 double x = t->helix().center().x() - a->xyPosition().x();
162 double y = t->helix().center().y() - a->xyPosition().y();
163 double r = sqrt( x * x + y * y );
164 double R = fabs( t->helix().radius() );
165 double q = t->helix().center().x() * a->xyPosition().y() -
166 t->helix().center().y() * a->xyPosition().x();
167 double qq = q * t->charge();
168 if ( R - 2. < r && r < R + 2. && qq > 0. ) { a->state( a->state() | WireHitUsed ); }
169 }
170 j = 0;
171 while ( TMDCWireHit* s = stereo[j++] )
172 {
173 double x = t->helix().center().x() - s->xyPosition().x();
174 double y = t->helix().center().y() - s->xyPosition().y();
175 double r = sqrt( x * x + y * y );
176 double R = fabs( t->helix().radius() );
177 double q = t->helix().center().x() * s->xyPosition().y() -
178 t->helix().center().y() * s->xyPosition().x();
179 double qq = q * t->charge();
180 if ( R - 2.5 < r && r < R + 2.5 && qq > 0. ) { s->state( s->state() | WireHitUsed ); }
181 }
182 }
183}
184
186
187#ifdef TRKRECO_DEBUG_DETAIL
188 std::cout << name() << " ... salvaging" << std::endl;
189 std::cout << " # of given hits=" << hits.length() << std::endl;
190#endif
191
192 //...Check arguments...
193 unsigned nTracks = _tracks.length();
194 if ( nTracks == 0 ) return;
195 unsigned nHits = hits.length();
196 if ( nHits == 0 ) return;
197
198 //...Hit loop...
199 for ( unsigned i = 0; i < nHits; i++ )
200 {
201 TMDCWireHit& h = *hits[i];
202
203 //...Already used?...
204 if ( h.state() & WireHitUsed ) continue;
205#ifdef TRKRECO_DEBUG_DETAIL
206 std::cout << " checking " << h.wire()->name() << std::endl;
207#endif
208
209 //...Select the closest track to a hit...
210 TTrack* best = closest( _tracks, h );
211#ifdef TRKRECO_DEBUG_DETAIL
212 if ( !best )
213 {
214 std::cout << " no track candidate returned";
215 std::cout << "by TTrackManager::closest" << std::endl;
216 }
217#endif
218 if ( !best ) continue;
219
220 //...Try to append this hit...
221 AList<TMLink> link;
222 link.append( new TMLink( 0, &h ) );
223 best->appendByApproach( link, 30. );
224 // best->assign(WireHitConformalFinder);
225 best->finder( TrackTrackManager );
226 }
227}
228
230
231 TMLink t;
232 t.hit( &hit );
233 unsigned n = tracks.length();
234 double minDistance = MAXDOUBLE;
235 TTrack* minTrk = NULL;
236
237 //...Loop over all tracks...
238 for ( unsigned i = 0; i < n; i++ )
239 {
240 TTrack& trk = *tracks[i];
241 int err = trk.approach( t );
242 if ( err < 0 ) continue;
243 if ( minDistance > t.distance() )
244 {
245 minDistance = t.distance();
246 minTrk = &trk;
247 }
248 }
249
250 return minTrk;
251}
252
253StatusCode
254// TTrackManager::makeTds(bool doClear, int tkStat) { //yzhang change interface
255TTrackManager::makeTds( RecMdcTrackCol* trkcol, RecMdcHitCol* hitcol, int tkStat, int brunge,
256 int cal ) { // yzhang change interface 2010-05-14
257 IMessageSvc* msgSvc;
258 Gaudi::svcLocator()->service( "MessageSvc", msgSvc );
259
260 MsgStream log( msgSvc, "TrkReco" );
261
262 IDataProviderSvc* eventSvc = NULL;
263 Gaudi::svcLocator()->service( "EventDataSvc", eventSvc );
264
265#ifdef TRKRECO_DEBUG
266 if ( eventSvc ) { log << MSG::INFO << "makeTds:event Svc has been found" << endmsg; }
267 else
268 {
269 log << MSG::FATAL << "makeTds:Could not find eventSvc" << endmsg;
270 return StatusCode::FAILURE;
271 }
272#endif
273 // check whether Recon already registered
274 // DataObject *aReconEvent;
275 // eventSvc->findObject("/Event/Recon",aReconEvent);
276 // if(!aReconEvent) {
277 // ReconEvent* recevt = new ReconEvent;
278 // StatusCode sc = eventSvc->registerObject("/Event/Recon",recevt );
279 // if(sc!=StatusCode::SUCCESS) {
280 // log << MSG::FATAL << "Could not register ReconEvent" <<endmsg;
281 // return( StatusCode::FAILURE);
282 // }
283 // }
284 //
285 // /// Unregister Tracks
286 // IDataManagerSvc *dataManSvc;
287 // if(doClear){//yzhang add, do NOT clear Tds when associate rec
288 // dataManSvc= dynamic_cast<IDataManagerSvc*>(eventSvc);
289 // DataObject *aTrackCol;
290 // eventSvc->findObject("/Event/Recon/RecMdcTrackCol",aTrackCol);
291 // if(aTrackCol != NULL) {
292 // dataManSvc->clearSubTree("/Event/Recon/RecMdcTrackCol");
293 // eventSvc->unregisterObject("/Event/Recon/RecMdcTrackCol");
294 // }
295 // DataObject *aRecHitCol;
296 // eventSvc->findObject("/Event/Recon/RecMdcHitCol",aRecHitCol);
297 // if(aRecHitCol != NULL) {
298 // dataManSvc->clearSubTree("/Event/Recon/RecMdcHitCol");
299 // eventSvc->unregisterObject("/Event/Recon/RecMdcHitCol");
300 // }
301 // }
302 // /// Writing
303 // RecMdcTrackCol* trkcol = new RecMdcTrackCol;
304 // RecMdcHitCol* hitcol = new RecMdcHitCol;
305
306 unsigned n = _tracks.length();
307 int nTdsTk = trkcol->size();
308 for ( int i = 0; i < n; i++ )
309 {
310 RecMdcTrack* trk = new RecMdcTrack;
311 TTrack* t = _tracks[i];
312 int trackindex = i + nTdsTk; // for combination
313
314 HitRefVec hitrefvec;
315 AList<TMLink> hits = t->links();
316 float chisq = 0;
317
318 HepPoint3D pos = t->helix().pivot();
319 int charge = -1;
320 HepVector m_a( 5, 0 );
321 m_a = t->helix().a();
322 int statfinder = t->getFinderType();
323 if ( abs( statfinder ) > 1000 && brunge ) statfinder = 103;
324 if ( abs( statfinder ) > 1000 && !brunge ) statfinder = 3;
325 // be cautious
326 if ( !brunge ) m_a[2] = -m_a[2];
327 if ( abs( m_a[1] ) > 999 ) m_a[1] = 0;
328 while ( m_a[1] < 0 ) { m_a[1] += 2 * pi; }
329 while ( m_a[1] > 2 * pi ) { m_a[1] -= 2 * pi; }
330 /// added by Jike Wang
331 const double x0 = t->helix().pivot().x();
332 const double y0 = t->helix().pivot().y();
333
334 const double dr = m_a[0];
335 const double phi0 = m_a[1];
336 const double kappa = m_a[2];
337 const double dz = m_a[3];
338 const double tanl = m_a[4];
339
340 const double Bz = -1000 * ( getPmgnIMF()->getReferField() );
341 const double alpha = 333.564095 / Bz;
342
343 const double cox = x0 + dr * cos( phi0 ) - alpha * cos( phi0 ) / kappa;
344 const double coy = y0 + dr * sin( phi0 ) - alpha * sin( phi0 ) / kappa;
345
346 unsigned nHits = t->links().length();
347 unsigned nStereos = 0;
348 unsigned firstLyr = 44;
349 unsigned lastLyr = 0;
350 for ( unsigned j = 0; j < nHits; j++ )
351 {
352
353 TMLink* l = hits[j];
354
355 HepPoint3D ontrack = l->positionOnTrack();
356 HepPoint3D onwire = l->positionOnWire();
357 HepPoint3D dir( ontrack.y() - coy, cox - ontrack.x(), 0 );
358 double pos_phi = onwire.phi();
359 double dir_phi = dir.phi();
360 while ( pos_phi > pi ) { pos_phi -= pi; }
361 while ( pos_phi < 0 ) { pos_phi += pi; }
362 while ( dir_phi > pi ) { dir_phi -= pi; }
363 while ( dir_phi < 0 ) { dir_phi += pi; }
364 double entrangle = dir_phi - pos_phi;
365 while ( entrangle > pi / 2 ) entrangle -= pi;
366 while ( entrangle < ( -1 ) * pi / 2 ) entrangle += pi;
367
368 // jialk setFltLen to tds
369 int imass = 3;
370 float tl = t->helix().a()[4];
371 float f = sqrt( 1. + tl * tl );
372 float s = fabs( t->helix().curv() ) * fabs( l->dPhi() ) * f;
373 float p = f / fabs( t->helix().a()[2] );
374 float Mass[5] = { 0.000511, 0.105, 0.140, 0.493677, 0.98327 };
375 double tof = s / 29.98 * sqrt( 1.0 + ( Mass[imass - 1] / p ) * ( Mass[imass - 1] / p ) );
376
377 RecMdcHit* hit = new RecMdcHit;
378 hit->setId( l->hit()->reccdc()->id );
379 // hit->setTrkId(i);
380 hit->setTrkId( trackindex ); // for combination
381 hit->setDriftDistLeft( l->drift( 0 ) );
382 hit->setDriftDistRight( l->drift( 1 ) );
383 hit->setErrDriftDistLeft( l->dDrift( 0 ) );
384 hit->setErrDriftDistRight( l->dDrift( 1 ) );
385 hit->setChisqAdd( l->pull() );
386 hit->setFlagLR( l->leftRight() );
387 // hit->setStat(l->hit()->state());
388 hit->setStat( 1 );
389 // std::cout<<"state :"<< l->hit()->state() << std::endl;
390 hit->setAdc( l->hit()->reccdc()->adc );
391 // hit->setTdc((l->hit()->reccdc()->tdc + t0bes)/0.09375); //jialk
392 hit->setTdc( l->hit()->reccdc()->timechannel );
393 hit->setFltLen( tof * 30 ); // jialk
394 // std::cout<<"tdc :"<< l->hit()->reccdc()->tdc <<" "<<"t0bes : "<< t0bes <<std::endl;
395 if ( cal ) { hit->setDoca( l->distancenew() ); }
396 else { hit->setDoca( l->distance() ); }
397 hit->setZhit( l->positionOnTrack().z() );
398
399 /// add by jialk: returns driftTime prop time correction & entra angle
400 hit->setEntra( entrangle );
401 hit->setDriftT( l->getDriftTime() );
402
403 Identifier hitIdf = MdcID::wire_id( l->wire()->layerId(), l->wire()->localId() );
404 hit->setMdcId( hitIdf );
405 hitcol->push_back( hit );
406
407 SmartRef<RecMdcHit> refhit( hit );
408 hitrefvec.push_back( refhit );
409 chisq += l->pull();
410 if ( l->wire()->stereo() ) ++nStereos;
411 if ( firstLyr > l->wire()->layerId() ) firstLyr = l->wire()->layerId();
412 if ( lastLyr < l->wire()->layerId() ) lastLyr = l->wire()->layerId();
413 }
414
415 HepSymMatrix m_ea = t->helix().Ea();
416 double errorMat[15];
417 int k = 0;
418 for ( int ie = 0; ie < 5; ie++ )
419 {
420 for ( int je = ie; je < 5; je++ )
421 {
422 errorMat[k] = m_ea[ie][je];
423 k++;
424 }
425 }
426
427 trk->setTrackId( trackindex );
428 trk->setHelix( m_a );
429 trk->setPxy( t->pt() );
430 trk->setPx( t->pt() * ( -sin( t->helix().phi0() ) ) );
431 trk->setPy( t->pt() * cos( t->helix().phi0() ) );
432 trk->setPz( t->pz() );
433 trk->setP( t->ptot() );
434
435 // jialk
436 double theta = acos( ( t->pz() ) / t->ptot() );
437 trk->setTheta( theta );
438
439 double poca_dr = t->helix().dr();
440 double poca_phi0 = t->helix().phi0();
441 trk->setPhi( poca_phi0 );
442 HepPoint3D poca( pos.x() + poca_dr * cos( poca_phi0 ),
443 pos.y() + poca_dr * sin( poca_phi0 ), pos.z() + t->helix().dz() );
444 trk->setPoca( poca );
445 trk->setX( poca.x() );
446 trk->setY( poca.y() );
447 trk->setZ( poca.z() );
448 trk->setR( sqrt( poca.x() * poca.x() + poca.y() * poca.y() ) );
449 trk->setPivot( pos );
450 trk->setVX0( pos.x() );
451 trk->setVY0( pos.y() );
452 trk->setVZ0( pos.z() );
453
454 trk->setError( m_ea );
455 // trk->setError(errorMat); //...............2
456
457 // double poca_dr = t->helix().dr();
458 // double poca_phi0 = t->helix().phi0();
459 // HepPoint3D poca(poca_dr*cos(poca_phi0),poca_dr*sin(poca_phi0),t->helix().dz());
460 // trk->setVX0(pos.x()+poca_dr*cos(poca_phi0));
461 // trk->setVY0(pos.y()+poca_dr*sin(poca_phi0));
462 // trk->setVZ0(pos.z()+t->helix().dz());
463 // cout<<"pivot:("<<pos.x()<<","<<pos.y()<<","<<pos.z()<<")"<<endl;
464 // cout<<"poca:("<<trk->getVX0()<<","<<trk->getVY0()<<","<<trk->getVZ0()<<")"<<endl;
465
466 trk->setChi2( chisq );
467 trk->setNdof( nHits - 5 );
468 if ( t->quality() & TrackQuality2D ) trk->setNdof( nHits - 3 );
469
470 TMLink* last = OuterMost( hits );
471 t->approach( *last );
472 trk->setFiTerm( last->dPhi() );
473
474 trk->setNhits( nHits );
475 trk->setNster( nStereos );
476 trk->setStat( statfinder ); // yzhang add stat: ConformalFinder=2, CurlFiner=3
477 // xuqn 2013-02-26
478 // trk->setCharge(int(t->charge())*(-1));
479 if ( !brunge ) trk->setCharge( int( t->charge() ) * ( -1 ) );
480 else trk->setCharge( t->charge() );
481 trk->setVecHits( hitrefvec );
482 trk->setFirstLayer( firstLyr );
483 trk->setLastLayer( lastLyr );
484 // cout<<"first: "<<firstLyr<<" last: "<<lastLyr<<endl;
485 trkcol->push_back( trk );
486 }
487
488 // StatusCode trksc;
489 // trksc = eventSvc->registerObject("/Event/Recon/RecMdcTrackCol", trkcol);
490 // if( trksc.isFailure() ) {
491 // log << MSG::FATAL << "Could not register MdcTrack" << endmsg;
492 // return trksc;
493 // }
494 //
495 // StatusCode hitsc = eventSvc->registerObject("/Event/Recon/RecMdcHitCol", hitcol);
496 // if ( hitsc.isFailure() ) {
497 // log << MSG::FATAL << "Could not register MdcRecHit" << endmsg;
498 // return hitsc;
499 // }
500 // log << MSG::INFO << "MdcTrackCol registered successfully!" <<endmsg;
501
502 /// check the result:MdcTrackCol
503#ifdef TRKRECO_DEBUG
504 SmartDataPtr<RecMdcTrackCol> newtrkCol( eventSvc, "/Event/Recon/RecMdcTrackCol" );
505 if ( !newtrkCol )
506 {
507 log << MSG::FATAL << "Could not find RecMdcTrackCol" << endmsg;
508 return ( StatusCode::FAILURE );
509 }
510 log << MSG::INFO << "Begin to check RecMdcTrackCol" << endmsg;
511 std::cout << std::fixed << std::setprecision( 6 ); // yzhang debug for 720
512 RecMdcTrackCol::iterator iter_trk = newtrkCol->begin();
513 for ( ; iter_trk != newtrkCol->end(); iter_trk++ )
514 {
515 const RecMdcTrack* tk = *iter_trk;
516 std::cout << "//==== " << name() << " print RecMdcTrack No." << tk->trackId() << " :"
517 << std::endl;
518 cout << " dr " << tk->helix( 0 ) << " phi0 " << tk->helix( 1 ) << " cpa " << tk->helix( 2 )
519 << " z0 " << tk->helix( 3 ) << " tanl " << tk->helix( 4 ) << endl;
520 bool printTrackDetail = true;
521 if ( printTrackDetail )
522 {
523 std::cout << " q " << tk->charge() << " theta " << tk->theta() << " phi " << tk->phi()
524 << " x0 " << tk->x() << " y0 " << tk->y() << " z0 " << tk->z() << " r0 "
525 << tk->r() << endl;
526 std::cout << " p " << tk->p() << " pt " << tk->pxy() << " pxyz(" << tk->px() << ","
527 << tk->py() << "," << tk->pz() << ")" << endl;
528 std::cout << " tkStat " << tk->stat() << " chi2 " << tk->chi2() << " ndof " << tk->ndof()
529 << " nhit " << tk->getNhits() << " nst " << tk->nster() << endl;
530 bool printErrMat = true;
531 if ( printErrMat )
532 {
533 std::cout << "errmat " << std::endl;
534 for ( int i = 0; i < 15; i++ ) { std::cout << " " << tk->err( i ); }
535 std::cout << " " << std::endl;
536 }
537 }
538
539 bool printHit = true;
540 if ( printHit )
541 {
542 int haveDigi[43][288];
543 bool printMcTk = true;
544 if ( printMcTk )
545 {
546 for ( int ii = 0; ii < 43; ii++ )
547 {
548 for ( int jj = 0; jj < 43; jj++ ) { haveDigi[ii][jj] = -9999; }
549 }
550 MdcDigiVec mdcDigiVec = getRawDataProviderSvc()->getMdcDigiVec();
551 MdcDigiCol::iterator iter = mdcDigiVec.begin();
552 std::cout << name() << "//==== " << name()
553 << " print MdcDigiVec, nDigi=" << mdcDigiVec.size() << " :" << std::endl;
554 for ( int iDigi = 0; iter != mdcDigiVec.end(); iter++, iDigi++ )
555 {
556 long l = MdcID::layer( ( *iter )->identify() );
557 long w = MdcID::wire( ( *iter )->identify() );
558 haveDigi[l][w] = ( *iter )->getTrackIndex();
559 }
560 }
561
562 int nhits = tk->getVecHits().size();
563 std::cout << "nHits=" << nhits << std::endl;
564 cout << "No. ";
565 if ( printMcTk ) cout << "mcTkId ";
566 cout << "(layer,wire,lr) stat z" << endl;
567 for ( int ii = 0; ii < nhits; ii++ )
568 {
569 Identifier id( tk->getVecHits()[ii]->getMdcId() );
570 int layer = MdcID::layer( id );
571 int wire = MdcID::wire( id );
572 cout << ii << ":";
573 if ( printMcTk ) { cout << haveDigi[layer][wire]; }
574 cout << " (" << layer << "," << wire << "," << tk->getVecHits()[ii]->getFlagLR()
575 << ") " << tk->getVecHits()[ii]->getStat() << " "
576 << tk->getVecHits()[ii]->getZhit() << " " << std::endl;
577 } // end of hit list
578 std::cout << " " << std::endl;
579 }
580 /*
581 std::cout << "retrieved MDC track:"
582 << "Track Id: " << (*iter_trk)->getTrkId()
583 << " Pivot: " << (*iter_trk)->getVX0() << " "
584 << (*iter_trk)->getVY0() << " " << (*iter_trk)->getVZ0()
585 << endl
586 << "Phi0: " << (*iter_trk)->getFi0() << " Error of Phi0 "
587 << (*iter_trk)->getError()(2,2) << endmsg
588 << "kappa: " << (*iter_trk)->getCpa() << " Error of kappa "
589 << (*iter_trk)->getError()(3,3) << endmsg
590 << "Tanl: " << (*iter_trk)->getTanl() << " Error of Tanl "
591 << (*iter_trk)->getError()(5,5) << endmsg
592 << "Chisq of fit: "<< (*iter_trk)->getChisq()
593 << " Phi terminal: "<< (*iter_trk)->getFiTerm()
594 << endl
595 << "Number of hits: "<< (*iter_trk)->getNhits()
596 << " Number of stereo hits " << (*iter_trk)->getNster()
597 << endmsg;
598
599 log << MSG::DEBUG << "hitList of this track:" << endmsg;
600 std::vector<MdcRecHit*> gothits = (*iter_trk)->getVecHits();
601 std::vector<MdcRecHit*>::iterator it_gothit = gothits.begin();
602 for( ; it_gothit != gothits.end(); it_gothit++){
603 log << MSG::DEBUG << "hits Id: "<<(*it_gothit)->getId()
604 << " hits DDL&DDR " <<(*it_gothit)->getDriftDistLeft()
605 << " hits MDC IDentifier " <<(*it_gothit)->getMdcId()
606 << endmsg
607 << " hits TDC " <<(*it_gothit)->getTdc()
608 << " hits ADC " <<(*it_gothit)->getAdc() << endmsg;
609 }
610 */
611 }
612 std::cout << std::defaultfloat;
613#endif
614 return StatusCode::SUCCESS;
615}
616
618#ifdef TRKRECO_DEBUG
619 std::cout << "TTrackManager::saveTables ... # 3D tracks=" << _tracks.length()
620 << ", # 2D tracks=" << _tracks2D.length() << ", all tracks=" << _tracksAll.length()
621 << std::endl;
622#endif
623
624 //...For 3D tracks...
625 AList<TTrack> badTracks;
626 unsigned n = _tracks.length();
627 unsigned* id = (unsigned*)malloc( n * sizeof( unsigned ) );
628 // bzero((char *) id, n * sizeof(unsigned));
629 memset( (char*)id, 0, n * sizeof( unsigned ) );
630 for ( unsigned i = 0; i < n; i++ )
631 {
632 TTrack& t = *_tracks[i];
633 if ( !t.nLinks() )
634 {
635 badTracks.append( (TTrack&)t );
636 continue;
637 }
638
639 //...Copy track parameters...
640 MdcRec_trk* r = 0;
641 MdcRec_trk_add* a = 0;
642 int err = copyTrack( t, &r, &a );
643 if ( err )
644 {
645 badTracks.append( t );
646 continue;
647 }
648 _tracksFinal.append( t );
649
650 //...Type and quality...
651 id[i] = r->id;
652 r->stat = t.state();
653 a->kind = t.type();
654 a->decision = t.finder();
655 a->stat = t.fitting();
656 // if (a->m_kind == TrackTypeCosmic) {
657 // a->m_quality = TrackQualityCosmic;
658 // }
659 // if (t.daughter() && (_tracks.index(t.daughter()) >= 0))
660 // a->m_daughter = _tracks.index(t.daughter()) + 1;
661 }
662
663 //...Daughter treatment...
664 for ( unsigned i = 0; i < n; i++ )
665 {
666
667#ifdef TRKRECO_DEBUG_DETAIL
668 std::cout << "id[" << i << "]=" << id[i] << std::endl;
669#endif
670 if ( !( id[i] ) ) continue;
671 if ( !( _tracks[i]->daughter() ) ) continue;
672
673 int dId = _tracks.index( _tracks[i]->daughter() );
674
675#ifdef TRKRECO_DEBUG_DETAIL
676 std::cout << " dId=" << dId;
677 if ( dId >= 0 ) std::cout << ", id[dId]=" << id[dId];
678 std::cout << std::endl;
679#endif
680
681 if ( dId >= 0 )
682 {
683 if ( id[dId] )
684 {
685 // reccdc_trk_add * a = (reccdc_trk_add *)
686 // BsGetEnt(RECMDC_TRK_ADD, id[i], BBS_No_Index);
687 // a->m_daughter = id[dId];
689 }
690 }
691 }
692 free( id );
693
694 //...Remove bad tracks...
695 _tracks.remove( badTracks );
696 badTracks.removeAll();
697
698 //...For 2D tracks...
699 n = _tracks2D.length();
700 for ( unsigned i = 0; i < n; i++ )
701 {
702 TTrack& t = *_tracks2D[i];
703
704 //...Copy track parameters...
705 MdcRec_trk* r = 0;
706 MdcRec_trk_add* a = 0;
707 int err = copyTrack( t, &r, &a );
708 if ( err )
709 {
710#ifdef TRKRECO_DEBUG
711 std::cout << "TTrackManager::saveTables !!! bad 2D tracks found"
712 << " : err=" << err << std::endl
713 << TrackDump( t ) << std::endl;
714#endif
715 badTracks.append( t );
716 continue;
717 }
718 _tracksFinal.append( t );
719
720 //...Reset helix parameter...
721 // r->m_helix[3] = 0.;
722 // r->m_helix[4] = 0.;
723 // r->m_nhits -= r->m_nster;
724 // r->m_nster = 0;
725
726 //...Table filling...
727 r->stat = t.state();
728 a->kind = t.type();
729 a->decision = t.finder();
730 // a->m_quality = t.quality();
732 a->stat = t.fitting();
733
734#ifdef TRKRECO_DEBUG
735 if ( ( r->ndf == 0 ) && ( r->chiSq > 0. ) )
736 {
737 std::cout << "TTrackManager::saveTables !!! chisq>0 with ndf=0." << std::endl
738 << " Here is a track dump"
739 << " " << TrackDump( t ) << std::endl;
740 t.dump( "detail" );
741 }
742 if ( ( r->ndf > 0 ) && ( r->chiSq == 0. ) )
743 {
744 std::cout << "TTrackManager::saveTables !!! chisq=0 with ndf>0." << std::endl
745 << " Here is a track dump"
746 << " " << TrackDump( t ) << std::endl;
747 t.dump( "detail" );
748 }
749
750 if ( r->ndf == 0 )
751 std::cout << "TTrackManager::saveTables ... ndf = 0" << std::endl
752 << " " << TrackDump( t ) << std::endl;
753 if ( r->chiSq == 0. )
754 std::cout << "TTrackManager::saveTables ... chisq = 0" << std::endl
755 << " " << TrackDump( t ) << std::endl;
756#endif
757 }
758 _tracks2D.remove( badTracks );
759
760 //...Statistics...
761 ++_s->_nEvents;
762 _s->_nTracks += _tracks.length();
763 _s->_nTracksAll += _tracksAll.length();
764 _s->_nTracks2D += _tracks2D.length();
765 _s->_nTracksFinal += _tracksFinal.length();
766}
767
768void TTrackManager::saveMCTables( void ) const {
769 unsigned n = _tracksFinal.length();
770 for ( unsigned i = 0; i < n; i++ )
771 {
772 const TTrack& t = *_tracksFinal[i];
773
774 // struct reccdc_trk * r;
775 // r = (struct reccdc_trk *) BsGetEnt(RECMDC_TRK, i + 1, BBS_No_Index);
777
778 //...Set type...
779
780 //...Hit loop...
781 const AList<TMLink>& hits = t.finalHits();
782 unsigned nHits = hits.length();
783 for ( unsigned j = 0; j < nHits; j++ )
784 {
785 TMLink* l = hits[j];
786 MdcRec_wirhit* h = l->hit()->reccdc();
787 MdcDat_mcwirhit* m = l->hit()->mc()->datcdc();
788 m->trk = r;
789 // struct reccdc_mctrk2hep * c;
790 // c = (struct reccdc_mctrk2hep *) BsNewEnt(RECMDC_MCTRK2HEP);
793 c->wir = h;
794 c->trk = r;
795 c->hep = l->hit()->mc()->hep()->gen();
796 }
797
798 const TTrackMC* const mc = t.mc();
799 // struct reccdc_mctrk * m;
800 // m = (struct reccdc_mctrk *) BsNewEnt(RECMDC_MCTRK);
801 // // MdcRec_mctrk* m = &(*MdcRecMctrkCol::getMdcRecMctrkCol())[0];
802 MdcRec_mctrk* m = new MdcRec_mctrk;
803 MdcRecMctrkCol::getMdcRecMctrkCol()->push_back( *m );
804 m->wirFrac = mc->wireFraction();
805 m->wirFracHep = mc->wireFractionHEP();
806 m->charge = mc->charge();
807 m->ptFrac = mc->ptFraction();
808 m->pzFrac = mc->pzFraction();
809 m->quality = mc->quality();
810 if ( mc->hep() ) m->hep = mc->hep()->gen();
811 else m->hep = 0;
812 }
813}
814
816 unsigned n = _tracksAll.length();
817 // unsigned n = _tracks.length();
818 for ( unsigned i = 0; i < n; i++ )
819 {
820 if ( _tracksAll[i]->nLinks() ) _tracksAll[i]->movePivot();
821 // if (_tracks[i]->nLinks()) _tracks[i]->movePivot();
822 }
823 nameTracks();
824}
825
827 HepAListDeleteAll( _tracksAll );
828 _tracks.removeAll();
829 _tracks2D.removeAll();
830 _tracksFinal.removeAll();
831 HepAListDeleteAll( _associateHits );
832 static bool first = true;
833 if ( first )
834 {
835 first = false;
836 int size;
837 // _s = (struct summary *)
838 // BASF_Sharedmem->get_pointer(BASF_Sharedmem->get_id(),
839 // "TrkMgrSum",
840 // & size);
841 }
842}
843
845 refit();
846 movePivot();
847 if ( _debugLevel > 1 )
848 {
849 std::cout << name() << " ... finishing" << std::endl;
850 // unsigned n = _tracksAll.length();
851 unsigned n = _tracks.length();
852 for ( unsigned i = 0; i < n; i++ )
853 {
854 // TTrack & t = * _tracksAll[i];
855 TTrack& t = *_tracks[i];
856 std::cout << " " << t.name() << std::endl;
857 t.dump( "hits mc track flag sort", " " );
858 }
859 }
860}
861
863 _tracksAll.append( list );
864 _tracks.append( selectGoodTracks( list ) );
865 list.removeAll();
866}
867
869 _tracksAll.append( list );
870 _tracks2D.append( selectGoodTracks( list, true ) );
871 _tracks2D.sort( SortByPt );
872 list.removeAll();
873}
874
876#ifdef TRKRECO_DEBUG_DETAIL
877 std::cout << name() << " ... refitting" << std::endl;
878#endif
879 unsigned n = _tracks.length();
880 AList<TTrack> bads;
881 for ( unsigned i = 0; i < n; i++ )
882 {
883 TTrack& t = *_tracks[i];
884 int err;
885 err = _fitter.fit( t );
886 if ( err < 0 )
887 {
888 bads.append( t );
889#ifdef TRKRECO_DEBUG_DETAIL
890 std::cout << " " << t.name();
891 std::cout << " rejected because of fitting failure" << std::endl;
892#endif
893 continue;
894 }
895 t.refine( 30. * 10. );
896 err = _fitter.fit( t );
897 if ( err < 0 )
898 {
899 bads.append( t );
900#ifdef TRKRECO_DEBUG_DETAIL
901 std::cout << " " << t.name();
902 std::cout << " rejected because of fitting failure" << std::endl;
903#endif
904 continue;
905 }
906 t.refine( 30. * 1. );
907 err = _fitter.fit( t );
908 if ( err < 0 )
909 {
910 bads.append( t );
911#ifdef TRKRECO_DEBUG_DETAIL
912 std::cout << " " << t.name();
913 std::cout << " rejected because of fitting failure" << std::endl;
914#endif
915 continue;
916 }
917 }
918 _tracks.remove( bads );
919}
920
921void TTrackManager::mask( void ) const {
922#ifdef TRKRECO_DEBUG_DETAIL
923 std::cout << name() << " ... masking" << std::endl;
924#endif
925
926 unsigned n = _tracks.length();
927 for ( unsigned i = 0; i < n; i++ )
928 {
929 TTrack& t = *_tracks[i];
930
931 //...Skip if no core...
932 // This should not be happend...
933 if ( !t.cores().length() ) continue;
934
935 //...Counts # of hits per layer...
936 unsigned nHits[43];
937 NHits( t.cores(), nHits );
938
939 //...Check each layer...
940 bool needMask = false;
941 for ( unsigned j = 0; j < 43; j++ )
942 {
943 if ( nHits[j] > 1 )
944 {
945 AList<TMLink> linksInLayer = SameLayer( t.links(), j );
946 if ( Width( linksInLayer ) > 2 )
947 {
948 needMask = true;
949
950#ifdef TRKRECO_DEBUG_DETAIL
951 Dump( linksInLayer, "sort", " -->" );
952#endif
953 break;
954 }
955 }
956 }
957 if ( !needMask ) continue;
958
959#ifdef TRKRECO_DEBUG_DETAIL
960 std::cout << " trk" << i << "(id is tmp) needs mask" << std::endl;
961 std::cout << " type = " << t.type() << std::endl;
962#endif
963
964 //...Switch by track type...
965 switch ( t.type() )
966 {
967 case TrackTypeNormal:
968 maskNormal( t );
969 maskMultiHits( t );
970 break;
971 case TrackTypeCurl:
972 maskCurl( t );
973 maskMultiHits( t );
974 break;
975 default: break;
976 }
977
978 //...Refit...
979 // refit() ???
980 _fitter.fit( t );
981
982#ifdef TRKRECO_DEBUG_DETAIL
983 std::cout << " masking result : ";
984 t.dump( "detail sort", " " );
985#endif
986 }
987}
988
989void TTrackManager::nameTracks( void ) {
990 unsigned n = _tracks.length();
991 for ( unsigned i = 0; i < n; i++ )
992 {
993 TTrack& t = *_tracks[i];
994 t._name = "trk" + std::to_string( i ) + "(" + t._name + ")";
995 }
996 AList<TTrack> tmp = _tracksAll;
997 tmp.remove( _tracks );
998 unsigned n1 = tmp.length();
999 for ( unsigned i = 0; i < n1; i++ )
1000 {
1001 TTrack& t = *tmp[i];
1002 t._name = "trk" + std::to_string( i + n ) + "(" + t._name + ")";
1003 }
1004}
1005
1007 TMLink& start = *OuterMost( t.links() );
1008 const HepPoint3D& center = t.helix().center();
1009 const HepVector3D a = start.positionOnTrack() - center;
1010 for ( unsigned j = 0; j < t.nLinks(); j++ )
1011 {
1012 if ( t[j] == &start ) continue;
1013 TMLink& k = *t[j];
1014 const HepVector3D b = k.positionOnTrack() - center;
1015 if ( a.cross( b ).z() >= 0. ) l[0].append( k );
1016 else l[1].append( k );
1017 }
1018
1019#ifdef TRKRECO_DEBUG_DETAIL
1020 std::cout << " outer link = " << start.hit()->wire()->name() << std::endl;
1021 std::cout << " nLinks of 0 = " << l[0].length() << std::endl;
1022 std::cout << " nLinks of 1 = " << l[1].length() << std::endl;
1023#endif
1024
1025 if ( l[0].length() == 0 || l[1].length() == 0 ) return divideByIp( t, l );
1026
1027 return start;
1028}
1029
1031 l[0].removeAll();
1032 l[1].removeAll();
1033
1034 const HepPoint3D& center = t.helix().center();
1035 const HepVector3D a = ORIGIN - center;
1036 for ( unsigned j = 0; j < t.nLinks(); j++ )
1037 {
1038 TMLink& k = *t[j];
1039 const HepVector3D b = k.positionOnTrack() - center;
1040 if ( a.cross( b ).z() >= 0. ) l[0].append( k );
1041 else l[1].append( k );
1042 }
1043
1044 //...This is a dummy...
1045 TMLink& start = *OuterMost( t.links() );
1046 return start;
1047}
1048
1050
1051 //...Calculate average phi...
1052 unsigned n = l.length();
1053 float phiSum = 0.;
1054 for ( unsigned i = 0; i < n; i++ )
1055 {
1056 const TMDCWire& w = *l[i]->hit()->wire();
1057 unsigned j = w.localId();
1058 unsigned nWire = w.layer()->nWires();
1059
1060 float phi = (float)j / (float)nWire;
1061 phiSum += phi;
1062 }
1063 float average = phiSum / (float)n;
1064
1066 for ( unsigned i = 0; i < n; i++ )
1067 {
1068 const TMDCWire& w = *l[i]->hit()->wire();
1069 unsigned j = w.localId();
1070 unsigned nWire = w.layer()->nWires();
1071
1072 float phi = (float)j / (float)nWire;
1073 float dif = fabs( phi - average );
1074 if ( dif > 0.5 ) dif = 1. - dif;
1075
1076 if ( dif > 0.3 ) cross.append( l[i] );
1077 }
1078 l.remove( cross );
1079
1080#ifdef TRKRECO_DEBUG_DETAIL
1081 std::cout << " Cross over IP reduction : ";
1082 for ( unsigned i = 0; i < cross.length(); i++ )
1083 { std::cout << cross[i]->wire()->name() << ","; }
1084 std::cout << std::endl;
1085#endif
1086}
1087
1088void TTrackManager::maskOut( TTrack& t, const AList<TMLink>& links ) const {
1089 unsigned n = links.length();
1090 if ( !n ) return;
1091 for ( unsigned i = 0; i < n; i++ )
1092 {
1093 const TMDCWireHit& hit = *links[i]->hit();
1094 hit.state( hit.state() | WireHitInvalidForFit );
1095 }
1096 t._fitted = false;
1097
1098#ifdef TRKRECO_DEBUG_DETAIL
1099 Dump( links, "detail", " TTrackManager::maskOut ... masking " );
1100#endif
1101}
1102
1104#ifdef TRKRECO_DEBUG_DETAIL
1105 std::cout << "... masking multi-hits" << std::endl;
1106#endif
1107
1108 if ( !t.cores().length() ) return;
1109 AList<TMLink> cores = t.cores();
1110 unsigned n = cores.length();
1111 bool layerLimited = false;
1112 AList<TMLink> bads;
1113
1114 cores.sort( SortByWireId );
1115 for ( unsigned i = 0; i < n; i++ )
1116 {
1117 if ( layerLimited )
1118 {
1119 bads.append( cores[i] );
1120 continue;
1121 }
1122 AList<TMLink> linksInLayer = SameLayer( cores, cores[i]->wire()->layerId() );
1123 if ( linksInLayer.length() > 3 )
1124 {
1125 bads.append( cores[i] );
1126 layerLimited = true;
1127 }
1128 }
1129 maskOut( t, bads );
1130}
1131
1133
1134 //...Divide into two tracks...
1135 AList<TMLink> l[2];
1136 TMLink& start = divideByIp( t, l );
1137
1138#ifdef TRKRECO_DEBUG_DETAIL
1139 std::cout << " normal : divided by IP" << std::endl;
1140 std::cout << " 0=";
1141 for ( unsigned j = 0; j < l[0].length(); j++ )
1142 { std::cout << "," << l[0][j]->wire()->name(); }
1143 std::cout << std::endl;
1144 std::cout << " 1=";
1145 for ( unsigned j = 0; j < l[1].length(); j++ )
1146 { std::cout << "," << l[1][j]->wire()->name(); }
1147 std::cout << std::endl;
1148#endif
1149
1150 //...Which should be masked out ?...
1151 unsigned maskSide = 2;
1152
1153 //...1. Check by # of super layers...
1154 if ( NSuperLayers( l[0] ) < NSuperLayers( l[1] ) ) maskSide = 0;
1155 else if ( NSuperLayers( l[0] ) > NSuperLayers( l[1] ) ) maskSide = 1;
1156#ifdef TRKRECO_DEBUG_DETAIL
1157 std::cout << " NSuperLayers 0, 1 = " << NSuperLayers( l[0] ) << ", ";
1158 std::cout << NSuperLayers( l[1] ) << std::endl;
1159#endif
1160 if ( maskSide != 2 )
1161 {
1162 maskOut( t, l[maskSide] );
1163 return;
1164 }
1165
1166 //...2. Check by the inner-most layer...
1167 unsigned i0 = InnerMost( l[0] )->wire()->layerId();
1168 unsigned i1 = InnerMost( l[1] )->wire()->layerId();
1169 if ( i0 < i1 ) maskSide = 1;
1170 else if ( i0 > i1 ) maskSide = 0;
1171#ifdef TRKRECO_DEBUG_DETAIL
1172 std::cout << " i0, i1 = " << i0 << ", " << i1 << std::endl;
1173#endif
1174 if ( maskSide != 2 )
1175 {
1176 maskOut( t, l[maskSide] );
1177 return;
1178 }
1179
1180 //...3. Check by # of layers...
1181 if ( NLayers( l[0] ) < NLayers( l[1] ) ) maskSide = 0;
1182 else if ( NLayers( l[0] ) > NLayers( l[1] ) ) maskSide = 1;
1183#ifdef TRKRECO_DEBUG_DETAIL
1184 std::cout << " NLayers 0, 1 = " << NLayers( l[0] ) << ", ";
1185 std::cout << NLayers( l[1] ) << std::endl;
1186#endif
1187 if ( maskSide != 2 )
1188 {
1189 maskOut( t, l[maskSide] );
1190 return;
1191 }
1192
1193 //...4. Check by pt...
1194 if ( maskSide == 2 )
1195 {
1196 TTrack* tt[2];
1197 for ( unsigned j = 0; j < 2; j++ )
1198 {
1199 tt[j] = new TTrack( t );
1200 tt[j]->remove( l[j] );
1201 _fitter.fit( *tt[j] );
1202 }
1203 if ( tt[1]->pt() > tt[0]->pt() ) maskSide = 1;
1204 else maskSide = 0;
1205#ifdef TRKRECO_DEBUG_DETAIL
1206 std::cout << " pt 0 = " << tt[1]->pt() << std::endl;
1207 std::cout << " pt 1 = " << tt[0]->pt() << std::endl;
1208#endif
1209 delete tt[0];
1210 delete tt[1];
1211 }
1212 maskOut( t, l[maskSide] );
1213 return;
1214}
1215
1217
1218 //...Divide into two tracks...
1219 AList<TMLink> l[2];
1220 TMLink& start = divideByIp( t, l );
1221 if ( l[0].length() == 0 ) return;
1222 if ( l[1].length() == 0 ) return;
1223
1224#ifdef TRKRECO_DEBUG_DETAIL
1225 std::cout << " curl : divided by IP" << std::endl;
1226 std::cout << " 0:";
1227 Dump( l[0], "flag sort" );
1228 std::cout << " 1:";
1229 Dump( l[1], "flag sort" );
1230 std::cout << std::endl;
1231#endif
1232
1233 //...Which should be masked out ?...
1234 unsigned maskSide = 2;
1235
1236 //...1. Check by # of super layers...
1237 if ( NSuperLayers( l[0] ) < NSuperLayers( l[1] ) ) maskSide = 0;
1238 else if ( NSuperLayers( l[0] ) > NSuperLayers( l[1] ) ) maskSide = 1;
1239#ifdef TRKRECO_DEBUG_DETAIL
1240 std::cout << " NSuperLayers 0, 1 = " << NSuperLayers( l[0] ) << ", ";
1241 std::cout << NSuperLayers( l[1] ) << std::endl;
1242#endif
1243 if ( maskSide != 2 )
1244 {
1245 maskOut( t, l[maskSide] );
1246 return;
1247 }
1248
1249 //...Make two tracks...
1250 TTrack* tt[2];
1251 tt[0] = new TTrack( t );
1252 tt[1] = new TTrack( t );
1253 tt[0]->remove( l[1] );
1254 tt[1]->remove( l[0] );
1255 _fitter.fit( *tt[0] );
1256 _fitter.fit( *tt[1] );
1257 Helix h0 = Helix( tt[0]->helix() );
1258 Helix h1 = Helix( tt[1]->helix() );
1259
1260 //...Check by z...
1261 h0.pivot( ORIGIN );
1262 h1.pivot( ORIGIN );
1263 if ( fabs( h0.dz() ) < fabs( h1.dz() ) ) maskSide = 1;
1264 else maskSide = 0;
1265
1266 delete tt[0];
1267 delete tt[1];
1268 maskOut( t, l[maskSide] );
1269 return;
1270}
1271
1272StatusCode TTrackManager::determineT0( unsigned level, unsigned nMax ) {
1273#ifdef TRKRECO_DEBUG_DETAIL
1274 if ( level == 0 )
1275 {
1276 std::cout << "TTrackManager::determineT0 !!! called with level = 0";
1277 std::cout << std::endl;
1278 }
1279#endif
1280
1281 IMessageSvc* msgSvc;
1282 Gaudi::svcLocator()->service( "MessageSvc", msgSvc );
1283 MsgStream log( msgSvc, "TTrackManager" );
1284
1285 IDataProviderSvc* eventSvc = NULL;
1286 Gaudi::svcLocator()->service( "EventDataSvc", eventSvc );
1287
1288 static bool first = true;
1289 static unsigned methode = 0;
1290 if ( first )
1291 {
1292 first = false;
1293
1294 if ( level == 1 ) { _cFitter.fit2D( true ); }
1295 else if ( level == 2 )
1296 {
1297 // default setting
1298 }
1299 else if ( level == 3 )
1300 {
1301 // _cFitter.sag(true); //Liuqg
1302 }
1303 else if ( level == 4 )
1304 {
1305 // _cFitter.sag(true); //Liuqg
1306 _cFitter.propagation( true );
1307 }
1308 else if ( level == 5 )
1309 {
1310 // _cFitter.sag(true); //Liuqg
1311 _cFitter.propagation( true );
1312 _cFitter.tof( true );
1313 }
1314 else if ( level == 6 )
1315 {
1316 methode = 1;
1317 // _cFitter.sag(true); //Liuqg
1318 _cFitter.propagation( true );
1319 _cFitter.tof( true );
1320 }
1321 else if ( level == 7 )
1322 {
1323 methode = 2;
1324 // _cFitter.sag(true); //Liuqg
1325 _cFitter.propagation( true );
1326 _cFitter.tof( true );
1327 }
1328 }
1329
1330 unsigned n = _tracks.length();
1331 if ( !n ) return StatusCode::SUCCESS;
1332
1333 if ( nMax == 0 ) nMax = n;
1334 if ( n > nMax ) n = nMax;
1335
1336 // float t0 = 0.;
1337 _t0 = 999.;
1338
1339 // read t0 from TDS
1340 float t0_sta = -1;
1341 float tev = 0;
1342 SmartDataPtr<RecEsTimeCol> aevtimeCol( eventSvc, "/Event/Recon/RecEsTimeCol" );
1343 if ( aevtimeCol )
1344 {
1345 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
1346 t0_sta = ( *iter_evt )->getStat();
1347 tev = ( *iter_evt )->getTest();
1348 // cout<<"t0_sta: "<<t0_sta<<" tev: "<<tev<<endl;
1349 }
1350 else { log << MSG::WARNING << "Could not find RecEsTimeCol" << endmsg; }
1351
1352 if ( methode == 0 ) _t0 = T0( n );
1353
1354 else if ( methode == 1 ) _t0 = T0Fit( n );
1355
1356 else if ( methode == 2 )
1357 { // revise method == 2 to BESIII environment. Liuqg
1358 if ( t0_sta != 1 )
1359 { // 1: tof 11:tof after reco //no tof
1360 _t0 = T0Fit( n );
1361 // cout<<"t0: "<<_t0<<endl;
1362 }
1363 }
1364
1365 // std::cout << "reccdc_timing=" << BsCouTab(RECMDC_TIMING) << std::endl;
1366 /* else if (methode == 2 && BsCouTab(RECMDC_TIMING) != 0) {
1367 struct reccdc_timing * r0 = (struct reccdc_timing *)
1368 BsGetEnt(RECMDC_TIMING, BsCouTab(RECMDC_TIMING), BBS_No_Index);
1369 if (r0->m_quality == 102) {
1370 if (BsCouTab(BELLE_EVENT)) {
1371 struct belle_event * b0 = (struct belle_event *)
1372 BsGetEnt(BELLE_EVENT, 1, BBS_No_Index);
1373 if(1==b0->m_ExpMC) t0 = T0Fit(n);
1374 if(2==b0->m_ExpMC && r0->m_time !=0.) t0 = T0Fit(n);
1375 }
1376 }
1377 else if (r0->m_quality == 100) t0 = T0Fit(n);
1378 // std::cout << "quality=" << r0->m_quality << std::endl;
1379 }
1380 */
1381
1382 //...For debug...
1383 if ( _debugLevel )
1384 {
1385 std::cout << "TTrackManager::determineT0 ... methode=" << methode;
1386 std::cout << ", T0 offset=" << -_t0;
1387 std::cout << ", # of tracks used=" << n << std::endl;
1388 }
1389
1390 //...store them... Liuqg
1391 float t0_rec = 999.;
1392 int t0_recSta = 8;
1393 if ( fabs( _t0 + tev ) < 4 ) t0_rec = 0;
1394 if ( fabs( _t0 + tev - 8 ) < 4 ) t0_rec = 8;
1395 if ( fabs( _t0 + tev - 16 ) < 4 ) t0_rec = 16;
1396 log << MSG::INFO << "beginning to make RecEsTimeCol" << endmsg;
1397 IDataManagerSvc* dataManSvc = dynamic_cast<IDataManagerSvc*>( eventSvc );
1398 DataObject* aEvTime;
1399 eventSvc->findObject( "/Event/Recon/RecEsTimeCol", aEvTime );
1400 if ( aEvTime != NULL && t0_rec < 25 )
1401 {
1402 dataManSvc->clearSubTree( "/Event/Recon/RecEsTimeCol" );
1403 eventSvc->unregisterObject( "/Event/Recon/RecEsTimeCol" );
1404 }
1405 if ( t0_rec < 25 )
1406 {
1407
1408 RecEsTimeCol* aEvTimeCol = new RecEsTimeCol;
1409 RecEsTime* aevtime = new RecEsTime;
1410 aevtime->setTest( t0_rec );
1411 aevtime->setStat( t0_recSta );
1412 aEvTimeCol->push_back( aevtime );
1413
1414 // register event time to TDS
1415 // check whether the t0 has been already registered
1416 StatusCode evtime = eventSvc->registerObject( "/Event/Recon/RecEsTimeCol", aEvTimeCol );
1417
1418 if ( evtime != StatusCode::SUCCESS )
1419 {
1420 log << MSG::FATAL << "Could not register Event Start Time" << endmsg;
1421 return ( StatusCode::FAILURE );
1422 }
1423 }
1424 return ( StatusCode::SUCCESS );
1425}
1426
1427float TTrackManager::T0( unsigned n ) {
1428
1429#define X0 -10.
1430#define X1 0.
1431#define X2 10.
1432#define STEP 10.
1433
1434 //...Determine T0 for each track...
1435 float t0Sum = 0.;
1436 for ( unsigned i = 0; i < n; i++ )
1437 {
1438 TTrack& t = *_tracks[i];
1439 float y[3];
1440 for ( unsigned j = 0; j < 3; j++ )
1441 {
1442 float offset = X0 + j * STEP;
1443 _cFitter.fit( t, offset );
1444 y[j] = t.chi2();
1445 }
1446 t0Sum += minimum( y[0], y[1], y[2] );
1447 }
1448 float t0 = t0Sum / (float)n;
1449 if ( isnan( t0 ) ) t0 = 0.;
1450
1451 //...Fit with T0 correction...
1452 n = _tracks.length();
1453 for ( unsigned i = 0; i < n; i++ )
1454 {
1455 TTrack& t = *_tracks[i];
1456 _cFitter.fit( t, t0 );
1457 }
1458
1459 //...Store it...
1460 // reccdc_timing * t = (reccdc_timing *) BsNewEnt(RECMDC_TIMING);
1461 /* MdcRec_timing* t = new MdcRec_timing;
1462 MdcRecTimingCol::getMdcRecTimingCol()->push_back(*t);
1463 t->time = - t0;
1464 t->quality = 11;
1465 */
1466 return -t0;
1467}
1468
1469float TTrackManager::T0Fit( unsigned n ) {
1470
1471 float tev_err;
1472 float tev_sum0 = 0.;
1473 float tev_sum = 0.;
1474 float tev_sum2 = 0.;
1475 float w_sum = 0.;
1476
1477 // sort in order of pt
1478 // std::cout << "length=" << _tracks.length() << std::endl;
1479 const int cn = _tracks.length();
1480 float* sort = new float[cn];
1481 float ptmax_pre = 1.e10;
1482 for ( unsigned i = 0; i < cn; i++ )
1483 {
1484 float ptmax = -999.;
1485 int jmax = 0; // add initialize 25-05-15
1486 for ( unsigned j = 0; j < cn; j++ )
1487 {
1488 TTrack& tj = *_tracks[j];
1489 float pt = fabs( 1. / tj.helix().a()[2] );
1490 if ( pt < ptmax_pre && pt > ptmax )
1491 {
1492 ptmax = pt;
1493 jmax = j;
1494 }
1495 sort[i] = jmax;
1496 }
1497 ptmax_pre = ptmax;
1498 }
1499
1500 for ( unsigned i = 0; i < n; i++ )
1501 {
1502 // srtbypt TTrack & t = * _tracks[i];
1503 TTrack& t = *_tracks[sort[i]];
1504 // float pt = fabs(1./t.helix().a()[2]);
1505 // std::cout << "pt=" << pt << endl;
1506 float tev = 0.;
1507 _cFitter.fit( t, tev, tev_err );
1508 // std::cout << "tev,tev_err=" <<tev<< " "<<tev_err<<endl;
1509 float w = 1. / tev_err / tev_err;
1510 tev_sum += w * tev;
1511 w_sum += w;
1512 // tev_sum0 += tev;
1513 // tev_sum2 += tev * tev;
1514 }
1515
1516 delete[] sort;
1517
1518 float tev_mean = tev_sum / w_sum;
1519 // float tev_err_a = 1. / sqrt(w_sum);
1520 // float tev_err_b = (tev_sum2 - tev_sum0 * tev_sum0 / (n + 1)) / n;
1521 // tev_err_b = sqrt(tev_err_b);
1522 // std::cout << "comp,t0,mean tev,err ="<<t0<<" "<<tev_mean<<" "<<tev_err_a<<"
1523 // "<<tev_err_b<<std::endl;
1524 if ( isnan( tev_mean ) ) tev_mean = 0.;
1525
1526 //...Store it...
1527 // reccdc_timing * tt = (reccdc_timing *) BsNewEnt(RECMDC_TIMING);
1528 // MdcRec_timing* tt = new MdcRec_timing;
1529 // MdcRecTimingCol::getMdcRecTimingCol()->push_back(*tt);
1530 // tt->time = tev_mean;
1531 // tt->quality = 151;
1532
1533 return -tev_mean;
1534}
1535
1536float TTrackManager::minimum( float y0, float y1, float y2 ) const {
1537 float xMin = X1 + 0.5 * STEP * ( y0 - y2 ) / ( y0 + y2 - 2. * y1 );
1538 return xMin;
1539}
1540
1541// added by matsu ( 1999/05/24 )
1543
1544 //...Merging...
1545 unsigned n = _tracks.length();
1546 // cout<<"tracks: "<<n<<endl;
1547 AList<TTrack> bads;
1548 unsigned* flagTrk = (unsigned*)malloc( n * sizeof( unsigned ) );
1549 for ( unsigned i = 0; i < n; i++ ) flagTrk[i] = 0;
1550
1551 //...Search a track to be merged...
1552 for ( unsigned i0 = 0; i0 < n; i0++ )
1553 {
1554
1555 if ( flagTrk[i0] != 0 ) continue;
1556 TTrack& t0 = *_tracks[i0];
1557 if ( !( t0.pt() < 0.13 ) ) continue;
1558
1559 unsigned Noverlap( 0 ), Nall( 0 );
1560 float OverlapRatioMax( -999. );
1561 unsigned MaxID( 0 );
1562
1563 for ( unsigned i1 = 0; i1 < n; i1++ )
1564 {
1565
1566 if ( i0 == i1 || flagTrk[i1] != 0 ) continue;
1567 TTrack& t1 = *_tracks[i1];
1568 if ( !( t1.pt() < 0.13 ) ) continue;
1569 Nall = t1.links().length();
1570 if ( !Nall ) continue;
1571
1572 Noverlap = 0;
1573 for ( unsigned j = 0; j < Nall; j++ )
1574 {
1575 TMLink& l = *t1.links()[j];
1576 const TMDCWireHit& whit = *l.hit();
1577 double load( 3. ); // jialk original is 2
1578 if ( whit.state() & WireHitStereo ) load = 4.; // jialk original is 3
1579
1580 double x = t0.helix().center().x() - l.positionOnTrack().x();
1581 double y = t0.helix().center().y() - l.positionOnTrack().y();
1582 double r = sqrt( x * x + y * y );
1583 double R = fabs( t0.helix().radius() );
1584
1585 if ( ( R - load ) < r && r < ( R + load ) ) Noverlap++;
1586 }
1587
1588 if ( !Noverlap ) continue;
1589 float tmpRatio = float( Noverlap ) / float( Nall );
1590
1591 if ( tmpRatio > OverlapRatioMax )
1592 {
1593 OverlapRatioMax = tmpRatio;
1594 MaxID = i1;
1595 }
1596 }
1597 // jialk caution original is 0.8
1598 if ( OverlapRatioMax < 0.7 ) continue;
1599
1600 //...Mask should be done...
1601 unsigned MaskID[2] = { MaxID, i0 };
1602 AList<TMLink> l[2];
1603
1604 for ( unsigned j0 = 0; j0 < 2; j0++ )
1605 {
1606 for ( unsigned j1 = 0; j1 < _tracks[MaskID[j0]]->nLinks(); j1++ )
1607 {
1608 TMLink& k = *_tracks[MaskID[j0]]->links()[j1];
1609 l[j0].append( k );
1610 }
1611 }
1612 // _tracks[i0]->links().append( _tracks[MaxID]->links() );
1613 // _tracks[MaxID]->links().append( _tracks[i0]->links ());
1614 _tracks[i0]->append( _tracks[MaxID]->links() );
1615 _tracks[MaxID]->append( _tracks[i0]->links() );
1616
1617#ifdef TRKRECO_DEBUG_DETAIL
1618 std::cout << " mask & merge " << std::endl;
1619 std::cout << " 0:";
1620 Dump( l[0], "flag sort" );
1621 std::cout << " 1:";
1622 Dump( l[1], "flag sort" );
1623 std::cout << std::endl;
1624#endif
1625
1626 //...Which should be masked out ?...
1627 unsigned maskSide = 2;
1628
1629#if 0
1630 //...0. Check by # of super layers... ( not applied now )
1631 unsigned super0 = NSuperLayers(l[0]);
1632 unsigned super1 = NSuperLayers(l[1]);
1633
1634 if( super0 < super1 ) maskSide = 0;
1635 else if ( super0 > super1 ) maskSide = 1;
1636
1637# ifdef TRKRECO_DEBUG_DETAIL
1638 std::cout << " NSuperLayers 0, 1 = " << NSuperLayers(l[0]) << ", ";
1639 std::cout << NSuperLayers(l[1]) << std::endl;
1640# endif
1641
1642 if (maskSide == 2) {
1643#endif
1644
1645 //...1. Check by the inner-most layer...
1646 unsigned inner0 = InnerMost( l[0] )->wire()->layerId();
1647 unsigned inner1 = InnerMost( l[1] )->wire()->layerId();
1648 if ( inner0 < inner1 ) maskSide = 1;
1649 else if ( inner0 > inner1 ) maskSide = 0;
1650
1651 if ( maskSide == 2 )
1652 {
1653
1654 //...2. Check by dz
1655
1656 //...Make two tracks...
1657 TTrack* tt[2];
1658 tt[0] = new TTrack( *( _tracks[MaskID[0]] ) );
1659 tt[1] = new TTrack( *( _tracks[MaskID[1]] ) );
1660 _fitter.fit( *tt[0] );
1661 _fitter.fit( *tt[1] );
1662 Helix h0 = Helix( tt[0]->helix() );
1663 Helix h1 = Helix( tt[1]->helix() );
1664
1665 //...Check dz...
1666 h0.pivot( ORIGIN );
1667 h1.pivot( ORIGIN );
1668 if ( fabs( h0.dz() ) < fabs( h1.dz() ) ) maskSide = 1;
1669 else maskSide = 0;
1670
1671 delete tt[0];
1672 delete tt[1];
1673 }
1674#if 0
1675 }
1676#endif
1677 bads.append( _tracks[MaskID[maskSide]] );
1678 flagTrk[MaskID[maskSide]] = 1;
1679 }
1680
1681 // cout<<"bads: "<<bads.length()<<endl;
1682 _tracks.remove( bads );
1683
1684 //***** Masking *****
1685 n = _tracks.length();
1686
1687 for ( unsigned i = 0; i < n; i++ )
1688 {
1689 TTrack& t = *_tracks[i];
1690 for ( unsigned j = 0; j < t.links().length(); j++ )
1691 {
1692 TMLink& l = *t.links()[j];
1693 const TMDCWireHit& whit = *l.hit();
1694
1695 if ( !( whit.state() & WireHitFittingValid ) ) continue;
1696
1697 // within half circle or not?
1698 double q = t.helix().center().x() * l.positionOnTrack().y() -
1699 t.helix().center().y() * l.positionOnTrack().x();
1700 double qq = q * t.charge();
1701
1702 if ( qq > 0 ) whit.state( whit.state() & ~WireHitInvalidForFit );
1703 else whit.state( whit.state() | WireHitInvalidForFit );
1704 }
1705 }
1706
1707 free( flagTrk );
1708}
1709// end of addition
1710
1711int TTrackManager::copyTrack( TTrack& t, MdcRec_trk** pr, MdcRec_trk_add** pra ) const {
1712
1713 static const unsigned GoodHitMask =
1715 int err = 0;
1716
1717 //...Hit loop...
1718#ifdef TRKRECO_DEBUG_DETAIL
1719 std::cout << " checking hits ... " << t.name() << " quality = " << t.quality();
1720 std::cout << " : " << t.cores().length() << ", " << t.ndf() << " : ";
1721 unsigned nnn = 0;
1722#endif
1723 unsigned j = 0;
1724 unsigned nClst = 0;
1725 unsigned nStereos = 0;
1726 unsigned nOccupied = 0;
1727 AList<TMLink> hits;
1728 AList<TMLink> badHits;
1729 unsigned n = t.links().length();
1730 for ( unsigned i = 0; i < n; i++ )
1731 {
1732 TMLink* l = t.links()[i];
1733 MdcRec_wirhit* h = l->hit()->reccdc();
1734
1735#ifdef TRKRECO_DEBUG_DETAIL
1736 if ( h->trk ) std::cout << l->wire()->name() << "(n/a),";
1737#endif
1738
1739 if ( h->trk )
1740 {
1741 ++nOccupied;
1742 if ( !( h->stat & WireHitInvalidForFit ) ) continue;
1743 }
1744 if ( ( l->hit()->state() & GoodHitMask ) == GoodHitMask )
1745 {
1746 if ( l->hit()->state() & WireHitInvalidForFit )
1747 {
1748 if ( !( h->stat & WireHitInvalidForFit ) ) badHits.append( l );
1749 }
1750 else
1751 {
1752 hits.append( l );
1753 if ( l->wire()->stereo() ) ++nStereos;
1754 }
1755 }
1756 }
1757 t.finalHits( hits );
1758#ifdef TRKRECO_DEBUG_DETAIL
1759 std::cout << std::endl;
1760#endif
1761
1762 //...Check # of hits...
1763 if ( t.quality() & TrackQuality2D )
1764 {
1765 if ( hits.length() < 3 ) err = 3;
1766 if ( nOccupied > 2 ) err = 4;
1767 }
1768 else
1769 {
1770 if ( hits.length() < 5 ) err = 1;
1771 if ( nStereos < 2 ) err = 2;
1772 }
1773 if ( err ) return err;
1774
1775 //...Create new tables...
1776 // * pr = (reccdc_trk *) BsNewEnt(RECMDC_TRK);
1777 // * pra = (reccdc_trk_add *) BsNewEnt(RECMDC_TRK_ADD);
1778 // reccdc_trk * r = * pr;
1779 // reccdc_trk_add * ra = * pra;
1780 *pr = new MdcRec_trk;
1781 *pra = new MdcRec_trk_add;
1782 MdcRec_trk* r = *pr;
1783 MdcRec_trk_add* ra = *pra;
1784
1785 //...Copy hit information...
1786 // const AList<TMLink> & cores = t.cores();
1787 // const AList<TMLink> & links = t.links();
1788 // unsigned allHits = cores.length();
1789 // unsigned stereoHits = NStereoHits(cores);
1790 // r.m_chiSq = t.chi2();
1791 // r.m_confl = t.confidenceLevel();
1792 // r.m_ndf = t.ndf();
1793 // r.m_nhits = allHits;
1794 // r.m_nster = stereoHits;
1795 float chisq = 0.;
1796 unsigned nHits = hits.length();
1797 for ( unsigned i = 0; i < nHits; i++ )
1798 {
1799 TMLink* l = hits[i];
1800 MdcRec_wirhit* h = hits[i]->hit()->reccdc();
1801 h->trk = r;
1802 h->pChiSq = l->pull();
1803 h->lr = l->leftRight();
1804 // zsl if (l->usecathode() == 4) ++nClst;
1805 chisq += h->pChiSq;
1806 }
1807 r->chiSq = chisq;
1808 r->nhits = nHits;
1809 r->nster = nStereos;
1810 r->ndf = nHits - 5;
1811 if ( t.quality() & TrackQuality2D ) r->ndf = nHits - 3;
1812
1813 //...Bad hits...
1814 n = badHits.length();
1815 for ( unsigned i = 0; i < n; i++ )
1816 {
1817 MdcRec_wirhit* h = badHits[i]->hit()->reccdc();
1818 h->trk = r;
1820 }
1821
1822 //...Cathode...
1823 r->nclus = nClst;
1824
1825 //...Helix parameter...
1826 const Vector& a = t.helix().a();
1827 const SymMatrix& ea = t.helix().Ea();
1828 const HepPoint3D& x = t.helix().pivot();
1829 r->helix[0] = a[0];
1830 r->helix[1] = a[1];
1831 r->helix[2] = a[2];
1832 r->helix[3] = a[3];
1833 r->helix[4] = a[4];
1834
1835 r->pivot[0] = x.x();
1836 r->pivot[1] = x.y();
1837 r->pivot[2] = x.z();
1838
1839 r->error[0] = ea[0][0];
1840 r->error[1] = ea[1][0];
1841 r->error[2] = ea[1][1];
1842 r->error[3] = ea[2][0];
1843 r->error[4] = ea[2][1];
1844 r->error[5] = ea[2][2];
1845 r->error[6] = ea[3][0];
1846 r->error[7] = ea[3][1];
1847 r->error[8] = ea[3][2];
1848 r->error[9] = ea[3][3];
1849 r->error[10] = ea[4][0];
1850 r->error[11] = ea[4][1];
1851 r->error[12] = ea[4][2];
1852 r->error[13] = ea[4][3];
1853 r->error[14] = ea[4][4];
1854
1855 //...Get outer most hit(=termination point)...
1856 TMLink* last = OuterMost( hits );
1857
1858 //...Calculate phi of the termination point...
1859 t.approach( *last );
1860 r->fiTerm = last->dPhi();
1861
1862 return err;
1863}
1864
1866 unsigned n = _tracks.length();
1867 if ( n < 2 ) return;
1868
1869 for ( unsigned i = 0; i < n - 1; i++ )
1870 {
1871 TTrack& t0 = *_tracks[i];
1872 float bestRChisq = HUGE_VAL;
1873 if ( t0.ndf() > 0 ) bestRChisq = t0.chi2() / t0.ndf();
1874 for ( unsigned j = i + 1; j < n; j++ )
1875 {
1876 TTrack& t1 = *_tracks[j];
1877 float rChisq = HUGE_VAL;
1878 if ( t1.ndf() > 0 ) rChisq = t1.chi2() / t1.ndf();
1879 if ( rChisq < bestRChisq )
1880 {
1881 bestRChisq = rChisq;
1882 _tracks.swap( i, j );
1883 }
1884 }
1885 }
1886}
1887
1889#ifdef TRKRECO_DEBUG_DETAIL
1890 std::cout << "trkmgr::sortTracksByPt : # of tracks=" << _tracks.length() << std::endl;
1891#endif
1892
1893 unsigned n = _tracks.length();
1894 if ( n < 2 ) return;
1895
1896 for ( unsigned i = 0; i < n - 1; i++ )
1897 {
1898 TTrack& t0 = *_tracks[i];
1899 float bestPt = t0.pt();
1900 for ( unsigned j = i + 1; j < n; j++ )
1901 {
1902 TTrack& t1 = *_tracks[j];
1903 float pt = t1.pt();
1904#ifdef TRKRECO_DEBUG_DETAIL
1905 std::cout << "i,j=" << i << "," << j << " : pt i,j=" << bestPt << "," << pt << std::endl;
1906#endif
1907 if ( pt > bestPt )
1908 {
1909 bestPt = pt;
1910 _tracks.swap( i, j );
1911 }
1912 }
1913 }
1914}
1915
1916void TTrackManager::treatCurler( MdcTrk& trk1, MdcRec_trk_add& cdc1, unsigned flag ) const {
1917 //...Originally coded by j.tanaka...
1918
1919 //...Check inputs...
1920 if ( trk1.zero[2] == 0 ) return;
1921 if ( cdc1.daughter == 0 ) return;
1922
1923 //...The other side...
1924 // reccdc_trk_add & cdc2 = * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
1925 // cdc1.m_daughter,
1926 // BBS_No_Index);
1927 // MdcRec_trk_add & cdc2 = (*MdcRecTrkAddCol::getMdcRecTrkAddCol())[cdc1.daughter.id];
1928 MdcRec_trk_add& cdc2 = *cdc1.daughter->add;
1929
1930 if ( cdc2.daughter == 0 ) return;
1931 if ( cdc2.rectrk == 0 ) return;
1932 // rectrk & trk2 = * (rectrk *) BsGetEnt(RECTRK, cdc2.m_rectrk, BBS_No_Index);
1933 MdcTrk& trk2 = *cdc2.rectrk;
1934
1935 if ( trk2.zero[2] == 0 ) return;
1936
1937 //...Obtain RECTRK_LOCALZ...
1938 // rectrk_localz & z1 = * (rectrk_localz *) BsGetEnt(RECTRK_LOCALZ,
1939 // trk1.m_zero[2],
1940 // BBS_No_Index);
1941 // rectrk_localz & z2 = * (rectrk_localz *) BsGetEnt(RECTRK_LOCALZ,
1942 // trk2.m_zero[2],
1943 // BBS_No_Index);
1944 MdcTrk_localz& z1 = *trk1.zero[2];
1945 MdcTrk_localz& z2 = *trk2.zero[2];
1946
1947 //...Pointer to mother and daughter...
1948 MdcRec_trk_add* mother = &cdc1;
1949 MdcRec_trk_add* daughter = &cdc2;
1950
1951 // //...By dr...
1952 // if (flag == 1) {
1953 // float dr1 = fabs(z1.m_helix[0]);
1954 // float dr2 = fabs(z2.m_helix[0]);
1955 // if (dr1 > dr2) {
1956 // mother = & cdc2;
1957 // daughter = & cdc1;
1958 // }
1959 // }
1960
1961 // //...By dz...
1962 // else {
1963 // float dz1 = fabs(z1.m_helix[3]);
1964 // float dz2 = fabs(z2.m_helix[3]);
1965 // if (dz1 > dz2) {
1966 // mother = & cdc2;
1967 // daughter = & cdc1;
1968 // }
1969 // }
1970
1971 //...By dz + dr...
1972 if ( flag == 3 )
1973 {
1974 float dz1 = fabs( z1.helix[3] );
1975 float dz2 = fabs( z2.helix[3] );
1976 if ( fabs( dz1 - dz2 ) < 2. ) flag = 1;
1977 else flag = 2;
1978 }
1979
1980 //...By dr...
1981 if ( flag == 1 )
1982 {
1983 float dr1 = fabs( z1.helix[0] );
1984 float dr2 = fabs( z2.helix[0] );
1985 if ( dr1 > dr2 )
1986 {
1987 mother = &cdc2;
1988 daughter = &cdc1;
1989 }
1990 }
1991
1992 //...By dz...
1993 else if ( flag == 2 )
1994 {
1995 float dz1 = fabs( z1.helix[3] );
1996 float dz2 = fabs( z2.helix[3] );
1997 if ( dz1 > dz2 )
1998 {
1999 mother = &cdc2;
2000 daughter = &cdc1;
2001 }
2002 }
2003
2004 //...Update information...
2005 mother->quality &= ( ~TrackQualityOutsideCurler );
2006 mother->likelihood[0] = 1.;
2007 mother->decision |= TrackTrackManager;
2008 // zsl
2009 mother->daughter = daughter->body;
2010 mother->mother = 0;
2011 // zsl end;
2013 daughter->likelihood[0] = 0.;
2014 daughter->mother = mother->body;
2015 daughter->daughter = 0;
2016 daughter->decision |= TrackTrackManager;
2017}
2018
2020#ifdef TRKRECO_DEBUG_DETAIL
2021 std::cout << "trkmgr::sortBanksByPt : # of tracks="
2022 // << BsCouTab(RECMDC_TRK_ADD) << std::endl;
2023 << MdcRecTrkAddCol::getMdcRecTrkAddCol()->size() << std::endl;
2024#endif
2025
2026 // unsigned n = BsCouTab(RECMDC_TRK_ADD);
2027 unsigned n = MdcRecTrkAddCol::getMdcRecTrkAddCol()->size();
2028 if ( n < 2 ) return;
2029
2030 //...Sort RECMDC...
2031 unsigned* id = (unsigned*)malloc( n * sizeof( unsigned ) );
2032 for ( unsigned i = 0; i < n; i++ ) id[i] = i;
2033 for ( unsigned i = 0; i < n - 1; i++ )
2034 {
2035 // reccdc_trk & cdc0 =
2036 // * (reccdc_trk *) BsGetEnt(RECMDC_TRK,
2037 // i + 1,
2038 // BBS_No_Index);
2039 // reccdc_trk_add & add0 =
2040 // * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2041 // i + 1,
2042 // BBS_No_Index);
2043 // reccdc_mctrk & mc0 =
2044 // * (reccdc_mctrk *) BsGetEnt(RECMDC_MCTRK,
2045 // i + 1,
2046 // BBS_No_Index);
2047 MdcRec_trk& cdc0 = ( *MdcRecTrkCol::getMdcRecTrkCol() )[i];
2050
2051 float bestPt = 1. / fabs( cdc0.helix[2] );
2052 unsigned bestQuality = add0.quality;
2053 for ( unsigned j = i + 1; j < n; j++ )
2054 {
2055 // reccdc_trk & cdc1 =
2056 // * (reccdc_trk *) BsGetEnt(RECMDC_TRK,
2057 // j + 1,
2058 // BBS_No_Index);
2059 // reccdc_trk_add & add1 =
2060 // * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2061 // j + 1,
2062 // BBS_No_Index);
2063 // reccdc_mctrk & mc1 =
2064 // * (reccdc_mctrk *) BsGetEnt(RECMDC_MCTRK,
2065 // j + 1,
2066 // BBS_No_Index);
2067 MdcRec_trk& cdc1 = ( *MdcRecTrkCol::getMdcRecTrkCol() )[j];
2070
2071 float pt = 1. / fabs( cdc1.helix[2] );
2072#ifdef TRKRECO_DEBUG_DETAIL
2073 std::cout << "i,j=" << i << "," << j << " : quality i,j=" << bestQuality << ","
2074 << add1.quality << std::endl;
2075#endif
2076 unsigned quality = add1.quality;
2077 if ( quality > bestQuality ) continue;
2078 else if ( quality < bestQuality )
2079 {
2080 bestQuality = quality;
2081 bestPt = pt;
2082 swapReccdc( cdc0, add0, mc0, cdc1, add1, mc1 );
2083 unsigned tmp = id[i];
2084 id[i] = id[j];
2085 id[j] = tmp;
2086#ifdef TRKRECO_DEBUG_DETAIL
2087 std::cout << "swapped" << std::endl;
2088#endif
2089 continue;
2090 }
2091#ifdef TRKRECO_DEBUG_DETAIL
2092 std::cout << "i,j=" << i << "," << j << " : pt i,j=" << bestPt << "," << pt << std::endl;
2093#endif
2094 if ( pt > bestPt )
2095 {
2096#ifdef TRKRECO_DEBUG_DETAIL
2097 std::cout << "swapping ... " << &cdc0 << "," << &add0 << "," << &mc0 << " <-> "
2098 << &cdc1 << "," << &add1 << "," << &mc1 << std::endl;
2099#endif
2100 bestQuality = quality;
2101 bestPt = pt;
2102 swapReccdc( cdc0, add0, mc0, cdc1, add1, mc1 );
2103 unsigned tmp = id[i];
2104 id[i] = id[j];
2105 id[j] = tmp;
2106#ifdef TRKRECO_DEBUG_DETAIL
2107 std::cout << "swapped" << std::endl;
2108#endif
2109 }
2110 }
2111 }
2112#ifdef TRKRECO_DEBUG_DETAIL
2113 std::cout << "trkmgr::sortBanksByPt : first phase finished" << std::endl;
2114#endif
2115
2116 tagReccdc( id, n );
2117 free( id );
2118
2119#ifdef TRKRECO_DEBUG_DETAIL
2120 std::cout << "trkmgr::sortBanksByPt : second phase finished" << std::endl;
2121#endif
2122
2123#if 0
2124 //...Sort RECTRK...
2125 n = BsCouTab(RECTRK);
2126 id = (unsigned *) malloc(n * sizeof(unsigned));
2127 for (unsigned i = 0; i < n; i++) id[i] = i;
2128 if (n > 1) {
2129 unsigned i = 0;
2130 while (i < n - 1) {
2131 rectrk & t = * (rectrk *) BsGetEnt(RECTRK, i + 1, BBS_No_Index);
2132 if (t.m_prekal == (i + 1)) {
2133 ++i;
2134 continue;
2135 }
2136
2137 rectrk & s = * (rectrk *) BsGetEnt(RECTRK,
2138 t.m_prekal,
2139 BBS_No_Index);
2140
2141 swapRectrk(t, s);
2142 unsigned tmp = id[i];
2143 id[i] = id[s.m_ID - 1];
2144 id[s.m_ID - 1] = tmp;
2145
2146 //std::cout << "swap " << i + 1 << " and " << s.m_ID << std::endl;
2147
2148 reccdc_trk_add & a =
2149 * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2150 t.m_prekal,
2151 BBS_No_Index);
2152 reccdc_trk_add & b =
2153 * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2154 s.m_prekal,
2155 BBS_No_Index);
2156 a.m_rectrk = t.m_ID;
2157 b.m_rectrk = s.m_ID;
2158 }
2159 }
2160#else
2161 /*
2162 // jtanaka 000925 -->
2163 n = BsCouTab(RECTRK);
2164 id = (unsigned *) malloc(n * sizeof(unsigned));
2165 for (unsigned i = 0; i < n; i++) id[i] = i;
2166 int foundId = 0;
2167 while(foundId != n){
2168 rectrk & t = * (rectrk *) BsGetEnt(RECTRK, foundId + 1, BBS_No_Index);
2169 int minPrekal = t.m_prekal;
2170 int exchangeId = foundId;
2171 for(int i=foundId+1;i<n;++i){
2172 rectrk & s = * (rectrk *) BsGetEnt(RECTRK, i + 1, BBS_No_Index);
2173 if(s.m_prekal < minPrekal){
2174 minPrekal = s.m_prekal;
2175 exchangeId = i;
2176 }
2177 }
2178 if(exchangeId != foundId){
2179 rectrk & s = * (rectrk *) BsGetEnt(RECTRK,
2180 exchangeId + 1,
2181 BBS_No_Index);
2182
2183 swapRectrk(t, s);
2184 unsigned tmp = id[t.m_ID - 1];
2185 id[t.m_ID - 1] = id[s.m_ID - 1];
2186 id[s.m_ID - 1] = tmp;
2187
2188 reccdc_trk_add & a =
2189 * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2190 t.m_prekal,
2191 BBS_No_Index);
2192 reccdc_trk_add & b =
2193 * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2194 s.m_prekal,
2195 BBS_No_Index);
2196 a.m_rectrk = t.m_ID;
2197 b.m_rectrk = s.m_ID;
2198 }
2199 ++foundId;
2200 }
2201 // <-- jtanaka 000925
2202 */
2203#endif
2204
2205 tagRectrk( id, n );
2206 free( id );
2207}
2208
2209void TTrackManager::swapReccdc( MdcRec_trk& cdc0, MdcRec_trk_add& add0, MdcRec_mctrk& mc0,
2210 MdcRec_trk& cdc1, MdcRec_trk_add& add1,
2211 MdcRec_mctrk& mc1 ) const {
2212#define RECMDC_ACTUAL_SIZE 124
2213#define RECMDCADD_ACTUAL_SIZE 40
2214#define RECMDCMC_ACTUAL_SIZE 28
2215
2216 static bool first = true;
2217 static void* swapRegion;
2218 if ( first )
2219 {
2220 first = false;
2221 swapRegion = malloc( RECMDC_ACTUAL_SIZE );
2222 }
2223
2224 void* s0 = &cdc0.helix[0];
2225 void* s1 = &cdc1.helix[0];
2226 memcpy( swapRegion, s0, RECMDC_ACTUAL_SIZE );
2227 memcpy( s0, s1, RECMDC_ACTUAL_SIZE );
2228 memcpy( s1, swapRegion, RECMDC_ACTUAL_SIZE );
2229
2230 s0 = &add0.quality;
2231 s1 = &add1.quality;
2232 memcpy( swapRegion, s0, RECMDCADD_ACTUAL_SIZE );
2233 memcpy( s0, s1, RECMDCADD_ACTUAL_SIZE );
2234 memcpy( s1, swapRegion, RECMDCADD_ACTUAL_SIZE );
2235
2236 if ( ( &mc0 ) && ( &mc1 ) )
2237 {
2238 s0 = &mc0.hep;
2239 s1 = &mc1.hep;
2240 memcpy( swapRegion, s0, RECMDCMC_ACTUAL_SIZE );
2241 memcpy( s0, s1, RECMDCMC_ACTUAL_SIZE );
2242 memcpy( s1, swapRegion, RECMDCMC_ACTUAL_SIZE );
2243 }
2244}
2245
2246void TTrackManager::swapRectrk( MdcTrk& rec0, MdcTrk& rec1 ) const {
2247#define RECTRK_ACTUAL_SIZE 84
2248
2249 static bool first = true;
2250 static void* swapRegion;
2251 if ( first )
2252 {
2253 first = false;
2254 swapRegion = malloc( RECTRK_ACTUAL_SIZE );
2255 }
2256
2257 void* s0 = &rec0.glob[0];
2258 void* s1 = &rec1.glob[0];
2259 memcpy( swapRegion, s0, RECTRK_ACTUAL_SIZE );
2260 memcpy( s0, s1, RECTRK_ACTUAL_SIZE );
2261 memcpy( s1, swapRegion, RECTRK_ACTUAL_SIZE );
2262}
2263
2264void TTrackManager::tagReccdc( unsigned* id0, unsigned nTrk ) const {
2265 /*
2266 unsigned * id = (unsigned *) malloc(nTrk * sizeof(unsigned));
2267 for (unsigned i = 0; i < nTrk; i++)
2268 id[id0[i]] = i;
2269
2270#ifdef TRKRECO_DEBUG_DETAIL
2271for (unsigned i = 0; i < nTrk; i++)
2272std::cout << "id0 " << i << " ... " << id0[i] << std::endl;
2273for (unsigned i = 0; i < nTrk; i++)
2274std::cout << "id " << i << " ... " << id[i] << std::endl;
2275#endif
2276 // unsigned n = BsCouTab(RECMDC_TRK_ADD);
2277 // unsigned n = MdcRecTrkAddCol::getMdcRecTrkAddCol()->size();
2278
2279 // for (unsigned i = 0; i < n; i++) {
2280 // reccdc_trk_add & w = * (reccdc_trk_add *) BsGetEnt(RECMDC_TRK_ADD,
2281 // i + 1,
2282 // BBS_No_Index);
2283 // MdcRec_trk_add & w = (* MdcRecTrkAddCol::getMdcRecTrkAddCol())[i];
2284 // if (w.mother) w.mother = id[w.mother - 1] + 1;
2285 // if (w.daughter) w.daughter = id[w.daughter - 1] + 1;
2286 // }
2287
2288#ifdef TRKRECO_DEBUG_DETAIL
2289std::cout << "TTrackManager::tagReccdc ... RECMDC_TRK_ADD done" << std::endl;
2290#endif
2291
2292n = BsCouTab(RECMDC_WIRHIT);
2293for (unsigned i = 0; i < n; i++) {
2294reccdc_wirhit & w = * (reccdc_wirhit *) BsGetEnt(RECMDC_WIRHIT,
2295i + 1,
2296BBS_No_Index);
2297if (w.m_trk == 0) continue;
2298w.m_trk = id[w.m_trk - 1] + 1;
2299}
2300
2301#ifdef TRKRECO_DEBUG_DETAIL
2302std::cout << "TTrackManager::tagReccdc ... RECMDC_WIRHIT done" << std::endl;
2303#endif
2304
2305n = BsCouTab(DATMDC_MCWIRHIT);
2306for (unsigned i = 0; i < n; i++) {
2307datcdc_mcwirhit & m =
2308 * (datcdc_mcwirhit *) BsGetEnt(DATMDC_MCWIRHIT,i + 1,BBS_No_Index);
2309 if (m.m_trk == 0) continue;
2310 m.m_trk = id[m.m_trk - 1] + 1;
2311 }
2312
2313#ifdef TRKRECO_DEBUG_DETAIL
2314std::cout << "TTrackManager::tagReccdc ... DATMDC_MCWIRHIT done" << std::endl;
2315#endif
2316
2317n = BsCouTab(RECTRK);
2318for (unsigned i = 0; i < n; i++) {
2319rectrk & r = * (rectrk *) BsGetEnt(RECTRK, i + 1, BBS_No_Index);
2320if (r.m_prekal == 0) continue;
2321r.m_prekal = id[r.m_prekal - 1] + 1;
2322}
2323
2324#ifdef TRKRECO_DEBUG_DETAIL
2325std::cout << "TTrackManager::tagReccdc ... RECTRK done" << std::endl;
2326#endif
2327
2328// jtanaka
2329n = BsCouTab(RECMDC_SVD_TRK);
2330for (unsigned i = 0; i < n; i++) {
2331reccdc_svd_trk & r = * (reccdc_svd_trk *) BsGetEnt(RECMDC_SVD_TRK, i + 1, BBS_No_Index);
2332if (r.m_cdc_trk == 0) continue;
2333r.m_cdc_trk = id[r.m_cdc_trk - 1] + 1;
2334}
2335
2336#ifdef TRKRECO_DEBUG_DETAIL
2337std::cout << "TTrackManager::tagReccdc ... RECMDC_SVD_TRK done" << std::endl;
2338#endif
2339
2340free(id);
2341*/
2342}
2343
2345 unsigned n = _tracks.length();
2346 if ( n < 2 ) return;
2347
2348 for ( unsigned i = 0; i < n - 1; i++ )
2349 {
2350 TTrack& t0 = *_tracks[i];
2351 if ( t0.type() != TrackTypeCurl ) continue;
2352 float c0 = t0.charge();
2353
2354 for ( unsigned j = i + 1; j < n; j++ )
2355 {
2356 TTrack& t1 = *_tracks[j];
2357 float c1 = t1.charge();
2358 if ( c0 * c1 > 0. ) continue;
2359 if ( t1.type() != TrackTypeCurl ) continue;
2360
2361 bool toBeMerged = false;
2362 unsigned n0 = t0.testByApproach( t1.cores(), _sigmaCurlerMergeTest );
2363 if ( n0 > _nCurlerMergeTest ) toBeMerged = true;
2364 if ( !toBeMerged )
2365 {
2366 unsigned n1 = t1.testByApproach( t0.cores(), _sigmaCurlerMergeTest );
2367 if ( n1 > _nCurlerMergeTest ) toBeMerged = true;
2368 }
2369
2370 if ( toBeMerged )
2371 {
2372 // ++_s->_nToBeMerged;
2373 if ( ( t0.daughter() ) || ( t1.daughter() ) ) ++_s->_nToBeMergedMoreThanTwo;
2374 t0.daughter( &t1 );
2375 t1.daughter( &t0 );
2376 }
2377 }
2378 }
2379}
2380
2381void TTrackManager::salvageAssociateHits( const AList<TMDCWireHit>& hits, float maxSigma2 ) {
2382 // #define TRKRECO_DEBUG
2383 // #define TRKRECO_DEBUG_DETAIL
2384
2385#ifdef TRKRECO_DEBUG
2386 std::cout << "... trkmgr::salvaging associate hits" << std::endl;
2387 std::cout << " # of given hits=" << hits.length() << std::endl;
2388#endif
2389
2390 //...Check arguments...
2391 unsigned nTracks = _tracks.length();
2392 if ( nTracks == 0 ) return;
2393 unsigned nHits = hits.length();
2394 if ( nHits == 0 ) return;
2395
2396 static const TPoint2D o( 0., 0. );
2397
2398 //...Hit loop...
2399 for ( unsigned i = 0; i < nHits; i++ )
2400 {
2401 TMDCWireHit& h = *hits[i];
2402
2403 //...Already used?...
2404 if ( h.state() & WireHitUsed ) continue;
2405#ifdef TRKRECO_DEBUG_DETAIL
2406 std::cout << " checking " << h.wire()->name();
2407#endif
2408
2409 //...Track loop...
2410 AList<TMLink> toBeDeleted;
2411 TMLink* best = NULL;
2412 TTrack* bestTrack = NULL;
2413 for ( unsigned j = 0; j < nTracks; j++ )
2414 {
2415 TTrack& t = *_tracks[j];
2416
2417 //...Pre-selection...
2418 TPoint2D c = t.center();
2419 TPoint2D co = -c;
2420 TPoint2D x = h.wire()->xyPosition();
2421
2422#ifdef TRKRECO_DEBUG_DETAIL
2423 std::cout << " : c= " << co.cross( x - c ) * t.charge();
2424 std::cout << ", d=" << fabs( ( x - c ).mag() - fabs( t.radius() ) );
2425#endif
2426
2427 if ( co.cross( x - c ) * t.charge() > 0. ) continue;
2428 if ( fabs( ( x - c ).mag() - fabs( t.radius() ) ) > 5. ) continue;
2429
2430 //...Try to append this hit...
2431 TMLink& link = *new TMLink( 0, &h );
2432 int err = t.approach( link );
2433 if ( err < 0 )
2434 {
2435#ifdef TRKRECO_DEBUG_DETAIL
2436 std::cout << " : " << t.name() << " approach failure";
2437#endif
2438 toBeDeleted.append( link );
2439 continue;
2440 }
2441
2442 //...Calculate sigma...
2443 float distance = link.distance();
2444 float diff = fabs( distance - link.hit()->drift() );
2445 float sigma = diff / link.hit()->dDrift();
2446 link.pull( sigma * sigma );
2447
2448#ifdef TRKRECO_DEBUG_DETAIL
2449 std::cout << " : " << t.name() << " pull = " << link.pull();
2450#endif
2451 if ( link.pull() > maxSigma2 )
2452 {
2453 toBeDeleted.append( link );
2454 continue;
2455 }
2456
2457 if ( best )
2458 {
2459 if ( best->pull() > link.pull() )
2460 {
2461 toBeDeleted.append( best );
2462 best = &link;
2463 bestTrack = &t;
2464 }
2465 else { toBeDeleted.append( link ); }
2466 }
2467 else
2468 {
2469 best = &link;
2470 bestTrack = &t;
2471 }
2472 }
2473
2474 if ( best )
2475 {
2476 bestTrack->append( *best );
2477 best->hit()->state( best->hit()->state() | WireHitInvalidForFit );
2478 _associateHits.append( best );
2479#ifdef TRKRECO_DEBUG
2480 std::cout << " " << best->hit()->wire()->name();
2481 std::cout << " -> " << bestTrack->name() << std::endl;
2482#endif
2483 }
2484 HepAListDeleteAll( toBeDeleted );
2485
2486#ifdef TRKRECO_DEBUG_DETAIL
2487 std::cout << std::endl;
2488#endif
2489 }
2490}
2491
2492void TTrackManager::maskBadHits( const AList<TTrack>& tracks, float maxSigma2 ) {
2493#ifdef TRKRECO_DEBUG
2494 std::cout << "... trkmgr::maskBadHits" << std::endl;
2495#endif
2496
2497 unsigned n = tracks.length();
2498 for ( unsigned i = 0; i < n; i++ )
2499 {
2500 TTrack& t = *tracks[i];
2501 bool toBeUpdated = false;
2502 const AList<TMLink> links = t.links();
2503 unsigned nHits = links.length();
2504 for ( unsigned j = 0; j < nHits; j++ )
2505 {
2506 if ( links[j]->pull() > maxSigma2 )
2507 {
2508 links[j]->hit()->state( links[j]->hit()->state() | WireHitInvalidForFit );
2509 toBeUpdated = true;
2510#ifdef TRKRECO_DEBUG
2511 std::cout << " " << t.name() << " : ";
2512 std::cout << links[j]->wire()->name() << "(pull=";
2513 std::cout << links[j]->pull() << ") is masked" << std::endl;
2514#endif
2515 }
2516 }
2517 if ( toBeUpdated ) t.update();
2518 }
2519}
2520
2521void TTrackManager::clearTables( void ) const {
2522 // BsDelEnt(RECMDC_TRK, BBS_ID_ALL);
2523 // BsDelEnt(RECMDC_TRK_ADD, BBS_ID_ALL);
2524 // BsDelEnt(RECMDC_MCTRK, BBS_ID_ALL);
2525 // BsDelEnt(RECMDC_MCTRK2HEP, BBS_ID_ALL);
2526 unsigned n = MdcRecTrkCol::getMdcRecTrkCol()->size();
2527 for ( unsigned i = 0; i < n; i++ ) delete &( *MdcRecTrkCol::getMdcRecTrkCol() )[i];
2528
2530 for ( unsigned i = 0; i < n; i++ ) delete &( *MdcRecTrkAddCol::getMdcRecTrkAddCol() )[i];
2531
2533 for ( unsigned i = 0; i < n; i++ ) delete &( *MdcRecMctrkCol::getMdcRecMctrkCol() )[i];
2534
2536 for ( unsigned i = 0; i < n; i++ )
2538
2539 //...Clear track association...
2540 // unsigned n = BsCouTab(RECMDC_WIRHIT);
2542 for ( unsigned i = 0; i < n; i++ )
2543 {
2544 // reccdc_wirhit & h = * (reccdc_wirhit *)
2545 // BsGetEnt(RECMDC_WIRHIT, i + 1, BBS_No_Index);
2546 // h.m_trk = 0;
2548 h.trk = 0;
2549 }
2550 // n = BsCouTab(DATMDC_MCWIRHIT);
2552 for ( unsigned i = 0; i < n; i++ )
2553 {
2554 // datcdc_mcwirhit & h = * (datcdc_mcwirhit *)
2555 // BsGetEnt(DATMDC_MCWIRHIT, i + 1, BBS_No_Index);
2556 // h.m_trk = 0;
2558 h.trk = 0;
2559 }
2560}
2561
2562AList<TTrack> TTrackManager::selectGoodTracks( const AList<TTrack>& list,
2563 bool track2D ) const {
2564 AList<TTrack> goodTracks;
2565 unsigned n = list.length();
2566 for ( unsigned i = 0; i < n; i++ )
2567 {
2568 const TTrack& t = *list[i];
2569 if ( !goodTrack( t, track2D ) ) continue;
2570
2571 //...Remove super momentum...
2572 if ( _maxMomentum > 0. )
2573 {
2574 if ( t.ptot() > _maxMomentum )
2575 {
2576 // ++_s->_nSuperMoms;
2577 continue;
2578 }
2579 }
2580
2581 goodTracks.append( (TTrack&)t );
2582 }
2583
2584 if ( _debugLevel )
2585 {
2586 if ( list.length() != goodTracks.length() )
2587 {
2588 std::cout << "TTrackManager::selectGoodTracks ... bad tracks found" << std::endl
2589 << " # of bad tracks = "
2590 << list.length() - goodTracks.length() << " : 2D flag = " << track2D
2591 << std::endl;
2592 AList<TTrack> tmp;
2593 tmp.append( list );
2594 tmp.remove( goodTracks );
2595 std::cout << " Track dump" << std::endl;
2596 for ( unsigned i = 0; i < tmp.length(); i++ )
2597 { std::cout << " " << TrackDump( *tmp[i] ) << std::endl; }
2598 }
2599 }
2600
2601 return goodTracks;
2602}
2603
2604bool TTrackManager::checkNumberOfHits( const TTrack& t, bool track2D ) {
2605 const AList<TMLink>& cores = t.cores();
2606
2607 if ( track2D )
2608 {
2609 unsigned axialHits = NAxialHits( cores );
2610 if ( axialHits < 3 ) return false;
2611 }
2612 else
2613 {
2614 unsigned allHits = cores.length();
2615 if ( allHits < 5 ) return false;
2616 unsigned stereoHits = NStereoHits( cores );
2617 if ( stereoHits < 2 ) return false;
2618 unsigned axialHits = allHits - stereoHits;
2619 if ( axialHits < 3 ) return false;
2620 }
2621 return true;
2622}
2623
2625 static const HepVector3D InitialVertex( 0., 0., 0. );
2626
2627 //...Track selection...
2628 // unsigned n = BsCouTab(RECTRK);
2629 unsigned n = MdcTrkCol::getMdcTrkCol()->size();
2631 for ( unsigned i = 0; i < n; i++ )
2632 {
2633 // const rectrk & t = * (rectrk *) BsGetEnt(RECTRK, i + 1, BBS_No_Index);
2634 const MdcTrk& t = ( *MdcTrkCol::getMdcTrkCol() )[i];
2635
2636 if ( t.prekal == 0 ) continue;
2637 // const reccdc_trk_add & c = * (reccdc_trk_add *)
2638 // BsGetEnt(RECMDC_TRK_ADD, t.m_prekal, BBS_No_Index);
2639 const MdcRec_trk_add& c = *t.prekal->add;
2640
2641 //...Only good tracks...
2642 if ( c.quality ) continue;
2643
2644 //...Require SVD hits...
2645 // const rectrk_global & g = * (rectrk_global *) BsGetEnt(RECTRK_GLOBAL,
2646 // t.m_glob[2],
2647 // BBS_No_Index);
2648 const MdcTrk_global& g = *t.glob[2];
2649
2650 if ( !&g ) continue;
2651 if ( g.nhits[3] < 2 ) continue;
2652 if ( g.nhits[4] < 2 ) continue;
2653
2654 //...OK...
2655 // const rectrk_localz & z = * (rectrk_localz *) BsGetEnt(RECTRK_LOCALZ,
2656 // t.m_zero[2],
2657 // BBS_No_Index);
2658 MdcTrk_localz& z = *t.zero[2];
2659
2660 if ( !&z ) continue;
2661 // zList.append((rectrk_localz &) z);
2662 zList.append( z );
2663 }
2664 unsigned nZ = zList.length();
2665 if ( nZ < 2 ) return;
2666
2667 //...Fitting...
2668 // kvertexfitter kvf;
2669 // kvf.initialVertex(initialVertex);
2670 // for (unsigned i = 0; i < nZ; i++) {
2671 // kvf.addTrack();
2672 // }
2673}
2674
2675void TTrackManager::tagRectrk( unsigned* id0, unsigned nTrk ) const {
2676 /*
2677 unsigned * id = (unsigned *) malloc(nTrk * sizeof(unsigned));
2678 for (unsigned i = 0; i < nTrk; i++)
2679 id[id0[i]] = i;
2680
2681 // for (unsigned i = 0; i < nTrk; i++)
2682 // std::cout << "id0 " << i << " ... " << id0[i] << std::endl;
2683 // for (unsigned i = 0; i < nTrk; i++)
2684 // std::cout << "id " << i << " ... " << id[i] << std::endl;
2685 // BsShwDat(RECTRK_TOF);
2686
2687 unsigned n = BsCouTab(RECTRK_TOF);
2688 for (unsigned i = 0; i < n; i++) {
2689 rectrk_tof & t = * (rectrk_tof *) BsGetEnt(RECTRK_TOF,
2690 i + 1,
2691 BBS_No_Index);
2692 if (t.m_rectrk) t.m_rectrk = id[t.m_rectrk - 1] + 1;
2693 }
2694
2695 // BsShwDat(RECTRK_TOF);
2696
2697 // jtanaka
2698 n = BsCouTab(RECSVD_HIT);
2699 for (unsigned i = 0; i < n; i++) {
2700 recsvd_hit & t = * (recsvd_hit *) BsGetEnt(RECSVD_HIT,
2701 i + 1,
2702 BBS_No_Index);
2703 if (t.m_trk) t.m_trk = id[t.m_trk - 1] + 1;
2704 }
2705
2706 free(id);
2707 */
2708}
2709
2710/*
2711// jtanaka 000925 -->
2712#define TRKRECO_REPLACE_TABLE 1
2713#if !(TRKRECO_REPLACE_TABLE)
2714void
2715copyRecMDC_trk_Table(const Reccdc_trk & org,
2716Reccdc_trk & copied)
2717{
2718copied.helix(0, org.helix(0));
2719copied.helix(1, org.helix(1));
2720copied.helix(2, org.helix(2));
2721copied.helix(3, org.helix(3));
2722copied.helix(4, org.helix(4));
2723copied.pivot(0, org.pivot(0));
2724copied.pivot(1, org.pivot(1));
2725copied.pivot(2, org.pivot(2));
2726copied.error(0, org.error(0));
2727copied.error(1, org.error(1));
2728copied.error(2, org.error(2));
2729copied.error(3, org.error(3));
2730copied.error(4, org.error(4));
2731copied.error(5, org.error(5));
2732copied.error(6, org.error(6));
2733copied.error(7, org.error(7));
2734copied.error(8, org.error(8));
2735copied.error(9, org.error(9));
2736copied.error(10, org.error(10));
2737copied.error(11, org.error(11));
2738copied.error(12, org.error(12));
2739copied.error(13, org.error(13));
2740copied.error(14, org.error(14));
2741copied.chiSq(org.chiSq());
2742copied.ndf(org.ndf());
2743copied.fiTerm(org.fiTerm());
2744copied.nhits(org.nhits());
2745copied.nster(org.nster());
2746copied.nclus(org.nclus());
2747copied.stat(org.stat());
2748copied.mass(org.mass());
2749}
2750
2751void
2752copyRecMDC_trk_add_Table(const Reccdc_trk_add & org,
2753Reccdc_trk_add & copied)
2754{
2755copied.quality(org.quality());
2756copied.kind(org.kind());
2757copied.mother(org.mother());
2758copied.daughter(org.daughter());
2759copied.decision(org.decision());
2760copied.likelihood(0, org.likelihood(0));
2761copied.likelihood(1, org.likelihood(1));
2762copied.likelihood(2, org.likelihood(2));
2763copied.stat(org.stat());
2764copied.rectrk(org.rectrk());
2765}
2766
2767void
2768copyRecMDC_MCtrk_Table(const Reccdc_mctrk & org,
2769Reccdc_mctrk & copied)
2770{
2771copied.hep(org.hep());
2772copied.wirFrac(org.wirFrac());
2773copied.wirFracHep(org.wirFracHep());
2774copied.charge(org.charge());
2775copied.ptFrac(org.ptFrac());
2776copied.pzFrac(org.pzFrac());
2777copied.quality(org.quality());
2778}
2779
2780void
2781copyRecMDC_MCtrk2hep_Table(const Reccdc_mctrk2hep & org,
2782 Reccdc_mctrk2hep & copied)
2783{
2784 copied.wir(org.wir());
2785 copied.clust(org.clust());
2786 copied.trk(org.trk());
2787 copied.hep(org.hep());
2788}
2789#endif
2790
2791void
2792TTrackManager::addSvd(const int mcFlag) const {
2793 TSvdAssociator svdA(-20000.,20000.);
2794 svdA.fillClusters();
2795
2796 //BsShwDat(RECTRK);
2797 //BsShwDat(RECMDC_TRK);
2798 //BsShwDat(RECMDC_MCTRK);
2799
2800 Reccdc_trk_Manager& trkMgr =
2801 Reccdc_trk_Manager::get_manager();
2802 Reccdc_trk_add_Manager& trkMgr2 =
2803 Reccdc_trk_add_Manager::get_manager();
2804 Reccdc_svd_trk_Manager& svdMgr =
2805 Reccdc_svd_trk_Manager::get_manager();
2806
2807#if !(TRKRECO_REPLACE_TABLE)
2808 Reccdc_wirhit_Manager& wirMgr =
2809 Reccdc_wirhit_Manager::get_manager();
2810 Reccdc_mctrk_Manager& mcMgr =
2811 Reccdc_mctrk_Manager::get_manager();
2812 Reccdc_mctrk2hep_Manager& mcMgr2 =
2813 Reccdc_mctrk2hep_Manager::get_manager();
2814 Datcdc_mcwirhit_Manager& mcMgr3 =
2815 Datcdc_mcwirhit_Manager::get_manager();
2816#endif
2817
2818 int nSize = trkMgr.count();
2819 for(int i=0;i<nSize;++i){
2820 //std::cout << "trk " << i << ": " << trkMgr[i].helix(0) << std::endl;
2821#if 1
2822 // Reconstruction Info --> SVD Recon.
2823 if(trkMgr2[i].decision() != TrackPMCurlFinder &&
2824 (trkMgr2[i].quality() & TrackQuality2D) != TrackQuality2D &&
2825 trkMgr[i].helix(2) != 0. && fabs(1./trkMgr[i].helix(2))<0.2){
2826 HepVector a(5);
2827 a[0] = trkMgr[i].helix(0);
2828 a[1] = trkMgr[i].helix(1);
2829 a[2] = trkMgr[i].helix(2);
2830 a[3] = trkMgr[i].helix(3);
2831 a[4] = trkMgr[i].helix(4);
2832 HepPoint3D p(trkMgr[i].pivot(0),
2833 trkMgr[i].pivot(1),
2834 trkMgr[i].pivot(2));
2835 Helix th(p,a);
2836 th.pivot(HepPoint3D(0.,0.,0.)); // pivot = (0,0,0)
2837 AList<TSvdHit> cand;
2838 double tz,tt;
2839 if(svdA.recTrk(th,tz,tt,0.5,50.0,cand,0.5)){
2840 //std::cout << "SVD in " << i << std::endl;
2841#if TRKRECO_REPLACE_TABLE
2842 Reccdc_svd_trk & newSvd = svdMgr.add();
2843#else
2844 Reccdc_trk & newTrk = trkMgr.add();
2845 Reccdc_trk_add & newTrk2 = trkMgr2.add();
2846 Reccdc_svd_trk & newSvd = svdMgr.add();
2847 // copy all information
2848 copyRecMDC_trk_Table(trkMgr[i],newTrk);
2849 copyRecMDC_trk_add_Table(trkMgr2[i],newTrk2);
2850#endif
2851 if(mcFlag){
2852#if TRKRECO_REPLACE_TABLE
2853 ;
2854#else
2855 Reccdc_mctrk & newMcTrk = mcMgr.add();
2856 copyRecMDC_MCtrk_Table(mcMgr[i],mcMgr[mcMgr.count()-1]);
2857 int nMCt2h = mcMgr2.count();
2858 for(int j=0;j<nMCt2h;++j){
2859 if(mcMgr2[j].trk() &&
2860 mcMgr2[j].trk().get_ID() == trkMgr[i].get_ID()){
2861 Reccdc_mctrk2hep & newMcTrk2Hep = mcMgr2.add();
2862 copyRecMDC_MCtrk2hep_Table(mcMgr2[j],newMcTrk2Hep);
2863 newMcTrk2Hep.trk(newTrk);
2864 }
2865 }
2866 int nMCwire = mcMgr3.count();
2867 for(int j=0;j<nMCwire;++j){
2868 if(mcMgr3[j].trk().get_ID() == trkMgr[i].get_ID()){
2869 mcMgr3[j].trk(newTrk);
2870 }
2871 }
2872#endif
2873 }
2874 HepVector ta = th.a(); // pivot = (0,0,0)
2875 ta[3] = tz;
2876 ta[4] = tt;
2877 th.a(ta);
2878 th.pivot(p); // pivot, (0,0,0) --> p
2879#if TRKRECO_REPLACE_TABLE
2880 trkMgr[i].helix(3, th.a()[3]);
2881 trkMgr[i].helix(4, th.a()[4]);
2882#else
2883 newTrk.helix(3, th.a()[3]);
2884 newTrk.helix(4, th.a()[4]);
2885#endif
2886
2887 newSvd.Helix(0, ta[0]);
2888 newSvd.Helix(1, ta[1]);
2889 newSvd.Helix(2, ta[2]);
2890 newSvd.Helix(3, ta[3]);
2891 newSvd.Helix(4, ta[4]);
2892#if TRKRECO_REPLACE_TABLE
2893 newSvd.cdc_trk(trkMgr2[i]);
2894#else
2895 newSvd.cdc_trk(newTrk2);
2896#endif
2897 newSvd.Status(0); // 0 is normal.
2898 int indexSvd = 0;
2899 for(int j=0;j<cand.length();++j){
2900 if(indexSvd >= 16)break;
2901 if((cand[j])->rphi() && (cand[j])->z()){
2902 newSvd.svd_cluster(indexSvd, *(cand[j]->rphi()));
2903 ++indexSvd;
2904 newSvd.svd_cluster(indexSvd, *(cand[j]->z()));
2905 ++indexSvd;
2906 }else{
2907 std::cerr << "[TTrackManager of TrkReco] Why ? no associated SVDhit ?" <<
2908std::endl;
2909 }
2910 }
2911#if TRKRECO_REPLACE_TABLE
2912 trkMgr2[i].quality(0); // set to 0 --> GOOD!
2913 trkMgr2[i].decision((trkMgr2[i].decision() | TrackSVDAssociator));
2914#else
2915 newTrk2.quality(1); // temporary
2916 newTrk2.decision((newTrk2.decision() | TrackSVDAssociator));
2917#endif
2918#if !(TRKRECO_REPLACE_TABLE)
2919 // MDC Wire information
2920 for(int j=0;j<wirMgr.count();++j){
2921 if(wirMgr[j].trk() &&
2922 wirMgr[j].trk().get_ID() == trkMgr[i].get_ID()){
2923 wirMgr[j].trk(newTrk);
2924 }
2925 }
2926#endif
2927 }else if(fabs(th.a()[3]) > 30.){
2928 if(svdA.recTrk(th,tz,tt,0.5,-1.0,cand,0.5)){
2929 //std::cout << "SVD in " << i << std::endl;
2930#if TRKRECO_REPLACE_TABLE
2931 Reccdc_svd_trk & newSvd = svdMgr.add();
2932#else
2933 Reccdc_trk & newTrk = trkMgr.add();
2934 Reccdc_trk_add & newTrk2 = trkMgr2.add();
2935 Reccdc_svd_trk & newSvd = svdMgr.add();
2936 // copy all information
2937 copyRecMDC_trk_Table(trkMgr[i],newTrk);
2938 copyRecMDC_trk_add_Table(trkMgr2[i],newTrk2);
2939#endif
2940 if(mcFlag){
2941#if TRKRECO_REPLACE_TABLE
2942 ;
2943#else
2944 Reccdc_mctrk & newMcTrk = mcMgr.add();
2945 copyRecMDC_MCtrk_Table(mcMgr[i],mcMgr[mcMgr.count()-1]);
2946 int nMCt2h = mcMgr2.count();
2947 for(int j=0;j<nMCt2h;++j){
2948 if(mcMgr2[j].trk() &&
2949 mcMgr2[j].trk().get_ID() == trkMgr[i].get_ID()){
2950 Reccdc_mctrk2hep & newMcTrk2Hep = mcMgr2.add();
2951 copyRecMDC_MCtrk2hep_Table(mcMgr2[j],newMcTrk2Hep);
2952 newMcTrk2Hep.trk(newTrk);
2953 }
2954 }
2955 int nMCwire = mcMgr3.count();
2956 for(int j=0;j<nMCwire;++j){
2957 if(mcMgr3[j].trk().get_ID() == trkMgr[i].get_ID()){
2958 mcMgr3[j].trk(newTrk);
2959 }
2960 }
2961#endif
2962 }
2963 HepVector ta = th.a(); // pivot = (0,0,0)
2964 ta[3] = tz;
2965 ta[4] = tt;
2966 th.a(ta);
2967 th.pivot(p); // pivot, (0,0,0) --> p
2968#if TRKRECO_REPLACE_TABLE
2969 trkMgr[i].helix(3, th.a()[3]);
2970 trkMgr[i].helix(4, th.a()[4]);
2971#else
2972 newTrk.helix(3, th.a()[3]);
2973 newTrk.helix(4, th.a()[4]);
2974#endif
2975
2976 newSvd.Helix(0, ta[0]);
2977 newSvd.Helix(1, ta[1]);
2978 newSvd.Helix(2, ta[2]);
2979 newSvd.Helix(3, ta[3]);
2980 newSvd.Helix(4, ta[4]);
2981#if TRKRECO_REPLACE_TABLE
2982 newSvd.cdc_trk(trkMgr2[i]);
2983#else
2984 newSvd.cdc_trk(newTrk2);
2985#endif
2986 newSvd.Status(0); // 0 is normal.
2987 int indexSvd = 0;
2988 for(int j=0;j<cand.length();++j){
2989 if(indexSvd >= 16)break;
2990 if((cand[j])->rphi() && (cand[j])->z()){
2991 newSvd.svd_cluster(indexSvd, *(cand[j]->rphi()));
2992 ++indexSvd;
2993 newSvd.svd_cluster(indexSvd, *(cand[j]->z()));
2994 ++indexSvd;
2995 }else{
2996 std::cerr << "[TTrackManager of TrkReco] Why ? no associated SVDhit ?" <<
2997std::endl;
2998 }
2999 }
3000#if TRKRECO_REPLACE_TABLE
3001 trkMgr2[i].quality(0); // set to 0 --> GOOD!
3002 trkMgr2[i].decision((trkMgr2[i].decision() | TrackSVDAssociator));
3003#else
3004 newTrk2.quality(1); // temporary
3005 newTrk2.decision((newTrk2.decision() | TrackSVDAssociator));
3006#endif
3007#if !(TRKRECO_REPLACE_TABLE)
3008 // MDC Wire information
3009 for(int j=0;j<wirMgr.count();++j){
3010 if(wirMgr[j].trk() &&
3011 wirMgr[j].trk().get_ID() == trkMgr[i].get_ID()){
3012 wirMgr[j].trk(newTrk);
3013 }
3014 }
3015#endif
3016 }
3017 }
3018 }
3019 }
3020#endif
3021}
3022// <-- jtanaka 000925
3023*/
3024
3025bool TTrackManager::goodTrack( const TTrack& t, bool track2D ) {
3026
3027 //...Check number of hits...
3028 if ( !checkNumberOfHits( t, track2D ) ) return false;
3029
3030 //...Check helix parameter...
3031 if ( HelixHasNan( t.helix() ) ) return false;
3032
3033 return true;
3034}
3035
3036IBesMagFieldSvc* TTrackManager::getPmgnIMF() const {
3037 if ( nullptr == m_pmgnIMF )
3038 {
3039 StatusCode sc = Gaudi::svcLocator()->service( "MagneticFieldSvc", m_pmgnIMF );
3040 if ( sc.isFailure() )
3041 { std::cout << "Unable to open Magnetic field service" << std::endl; }
3042 }
3043 if ( nullptr == m_pmgnIMF ) std::cout << " Unable to get IBesMagFieldSvc " << std::endl;
3044 return m_pmgnIMF;
3045}
3046
3047IRawDataProviderSvc* TTrackManager::getRawDataProviderSvc() const {
3048 if ( !m_rawDataProviderSvc )
3049 {
3050 StatusCode sc = Gaudi::svcLocator()->service( "RawDataProviderSvc", m_rawDataProviderSvc );
3051 if ( sc.isFailure() ) { std::cout << "Unable to open RawDataProviderSvc" << std::endl; }
3052 }
3053 return m_rawDataProviderSvc;
3054}
HepGeom::Vector3D< double > HepVector3D
#define STEP(pi, pj)
std::string cal
HepGeom::Point3D< double > HepPoint3D
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
const Int_t n
Double_t x[10]
ObjectVector< RecEsTime > RecEsTimeCol
double alpha
double pi
double w
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
EvtVector3R cross(const EvtVector3R &p1, const EvtVector3R &p2)
XmlRpcServer s
const HepPoint3D ORIGIN
Constants.
Definition TMDCUtil.cxx:47
bool HelixHasNan(const Helix &)
Helix parameter validity.
Definition TTrack.cxx:3939
std::string TrackDump(const TTrack &)
to dump a track.
int SortByPt(const void *a, const void *b)
Utility functions.
Definition TTrack.cxx:2514
****INTEGER imax DOUBLE PRECISION m_pi *DOUBLE PRECISION m_amfin DOUBLE PRECISION m_Chfin DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_sinw2 DOUBLE PRECISION m_GFermi DOUBLE PRECISION m_MfinMin DOUBLE PRECISION m_ta2 INTEGER m_out INTEGER m_KeyFSR INTEGER m_KeyQCD *COMMON c_Semalib $ !copy of input $ !CMS energy $ !beam mass $ !final mass $ !beam charge $ !final charge $ !smallest final mass $ !Z mass $ !Z width $ !EW mixing angle $ !Gmu Fermi $ alphaQED at q
Definition KKsem.h:33
int n1
Definition SD0Tag.cxx:58
IMessageSvc * msgSvc()
#define X1
#define RECMDCADD_ACTUAL_SIZE
#define X0
#define RECMDCMC_ACTUAL_SIZE
#define RECTRK_ACTUAL_SIZE
#define RECMDC_ACTUAL_SIZE
const HepSymMatrix err() const
void setError(double err[15])
void setHelix(double helix[5])
void setPoca(double poca[3])
const HepVector helix() const
......
const HepPoint3D & center(void) const
returns position of helix center(z = 0.);
double radius(void) const
returns radious of helix.
const HepVector & a(void) const
returns helix parameters.
const HepPoint3D & pivot(void) const
returns pivot position.
static vector< MdcDat_mcwirhit > * getMdcDatMcwirhitCol(void)
static Identifier wire_id(int wireType, int layer, int wire)
For a single wire.
Definition MdcID.cxx:69
static int layer(const Identifier &id)
Values of different levels (failure returns 0).
Definition MdcID.cxx:47
static int wire(const Identifier &id)
Definition MdcID.cxx:52
static vector< MdcRec_mctrk2hep > * getMdcRecMctrk2hepCol(void)
static vector< MdcRec_mctrk > * getMdcRecMctrkCol(void)
static vector< MdcRec_trk_add > * getMdcRecTrkAddCol(void)
static vector< MdcRec_trk > * getMdcRecTrkCol(void)
static vector< MdcRec_wirhit > * getMdcRecWirhitCol(void)
static vector< MdcTrk > * getMdcTrkCol(void)
Definition TrkTables.cxx:10
const TTrackHEP *const hep(void) const
returns a pointer to a GEN_HEPEVT.
MdcDat_mcwirhit * datcdc(void) const
returns a pointer to DATMDC_MCWIRHIT.
struct MdcRec_wirhit * reccdc(void) const
returns a pointer to RECMDC_WIRHIT.
float dDrift(unsigned) const
returns drift distance error.
float drift(unsigned) const
returns drift distance.
const TMDCWire *const wire(void) const
returns a pointer to a TMDCWire.
const TMDCWireHitMC *const mc(void) const
returns a pointer to TMDCWireHitMC.
unsigned localId(void) const
returns local id in a wire layer.
unsigned layerId(void) const
returns layer id.
const HepPoint3D & xyPosition(void) const
returns middle position of a wire. z componet is 0.
bool stereo(void) const
returns true if this wire is in a stereo layer.
std::string name(void) const
returns name.
unsigned testByApproach(const TMLink &list, double sigma) const
returns # of good hits to be appended.
void append(TMLink &)
appends a TMLink.
const AList< TMLink > & links(unsigned mask=0) const
void appendByApproach(AList< TMLink > &list, double maxSigma)
const AList< TMLink > & cores(unsigned mask=0) const
returns a list of masked TMLinks for fit. 'mask' will be applied if mask is not 0.
const Gen_hepevt * gen(void) const
returns a pointer to Gen_hepevt.
A class to have MC information of TTrack.
double wireFractionHEP(void) const
returns wire fraction(F2).
const TTrackHEP *const hep(void) const
returns a pointer to TTrackHEP.
unsigned quality(void) const
returns quality.
bool charge(void) const
returns charge matching.
double ptFraction(void) const
returns pt fraction.
double pzFraction(void) const
returns pz fraction.
double wireFraction(void) const
returns wire fraction(F1).
void movePivot(void)
moves pivot of tracks.
void append2D(AList< TTrack > &list)
void maskOut(TTrack &, const AList< TMLink > &) const
void removeHitsAcrossOverIp(AList< TMLink > &) const
static void maskBadHits(const AList< TTrack > &, float maxSigma2)
masks hits with large chisq as associated hits. Pull in TMLink is used.
void clearTables(void) const
clears tables.
void dump(const std::string &message=std::string(""), const std::string &prefix=std::string("")) const
dumps debug information.
void maskNormal(TTrack &) const
virtual ~TTrackManager()
Destructor.
void finish(void)
finishes tracks.
TTrack * closest(const AList< TTrack > &, const TMDCWireHit &) const
returns a track which is the closest to a hit.
void append(AList< TTrack > &list)
appends (2D) tracks. 'list' will be cleaned up.
void saveTables(void)
stores track info. into Panther table.
std::string version(void) const
returns version.
void salvageAssociateHits(const AList< TMDCWireHit > &, float maxSigma2)
salvages hits for dE/dx(not for track fitting).
void refit(void)
refits tracks.
TMLink & divide(const TTrack &t, AList< TMLink > *l) const
StatusCode makeTds(RecMdcTrackCol *trackList, RecMdcHitCol *hitList, int tkStat=1, int runge=0, int cal=0)
stores track info. into TDS. by Zang Shilei
void setCurlerFlags(void)
tests for curlers.
void maskMultiHits(TTrack &) const
void determineIP(void)
determines IP.
static bool goodTrack(const TTrack &, bool track2D=false)
checks goodness of a track.
const AList< TTrack > & tracks(void) const
returns a list of reconstructed tracks.
TTrackManager()
Constructor.
void maskCurl(TTrack &) const
void saveMCTables(void) const
stores MC track info. into Panther table.
void mask(void) const
masks hits out which are in tail of curly tracks.
TMLink & divideByIp(const TTrack &t, AList< TMLink > *l) const
void sortBanksByPt(void) const
sorts RECMDC_TRK tables.
void sortTracksByQuality(void)
sorts tracks.
void treatCurler(MdcTrk &curl, MdcRec_trk_add &cdc, unsigned flag) const
final decision for a curler.
void maskCurlHits(const AList< TMDCWireHit > &axial, const AList< TMDCWireHit > &stereo, const AList< TTrack > &tracks) const
masks hits on found curl tracks.
StatusCode determineT0(unsigned level, unsigned nMaxTracks)
determines T0 and refit all tracks.
void salvage(const AList< TMDCWireHit > &) const
salvages remaining hits.
void clear(void)
clears all internal information.
void sortTracksByPt(void)
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.
unsigned finder(void) const
sets/returns finder.
unsigned type(void) const
returns type. Definition is depending on an object type.
int approach(TMLink &) const
Definition TTrack.cxx:265
double charge(void) const
returns charge.
Index first(Pair i)
int t()
Definition t.c:1