BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TrkReco.cxx
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// $Id: TrkReco.cxx,v 1.103 2022/01/28 22:14:13 maqm Exp $
3//-----------------------------------------------------------------------------
4// Filename : TrkReco.cc
5// Section : Tracking
6// Owner : Yoshi Iwasaki
7// Email : yoshihito.iwasaki@kek.jp
8//-----------------------------------------------------------------------------
9// Description : A tracking module.
10// See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
11// http://belle.kek.jp/~yiwasaki/tracking/
12//-----------------------------------------------------------------------------
13
14// #include "CLHEP/String/Strings.h"
15#include <math.h>
16
17#include "MdcGeomSvc/IMdcGeomSvc.h"
18#include "MdcTables/MdcTables.h"
19
20#include "TrkReco.h"
21#include "TrkReco/TConformalFinder.h"
22#include "TrkReco/TConformalFinder0.h"
23#include "TrkReco/TCurlFinder.h"
24#include "TrkReco/TFastFinder.h"
25#include "TrkReco/TMDC.h"
26#include "TrkReco/TMDCWire.h"
27#include "TrkReco/TMDCWireHit.h"
28#include "TrkReco/TMLink.h"
29#include "TrkReco/TPerfectFinder.h"
30#include "TrkReco/TTrack.h"
31#include "TrkReco/TTrackBase.h"
32#include "TrkReco/TTrackHEP.h"
33#include "TrkReco/TTrackMC.h"
34
35#include "EvTimeEvent/RecEsTime.h"
36#include "MdcCalibFunSvc/IMdcCalibFunSvc.h"
37// #include "MdcCalibFunSvc/MdcCalibFunSvc.h"
38
39#include "GaudiKernel/Bootstrap.h"
40#include "GaudiKernel/IDataManagerSvc.h"
41#include "GaudiKernel/IDataProviderSvc.h"
42#include "GaudiKernel/IMessageSvc.h"
43#include "GaudiKernel/ISvcLocator.h"
44#include "GaudiKernel/MsgStream.h"
45#include "GaudiKernel/PropertyMgr.h"
46#include "GaudiKernel/SmartDataPtr.h"
47#include "GaudiKernel/StatusCode.h"
48
49#include "EventModel/EventHeader.h"
50#include "Identifier/Identifier.h"
51#include "Identifier/MdcID.h"
52#include "McTruth/McParticle.h"
53#include "McTruth/MdcMcHit.h"
54#include "MdcRawEvent/MdcDigi.h"
55#include "RawDataProviderSvc/IRawDataProviderSvc.h"
56#include "RawEvent/RawDataUtil.h"
57#include "ReconEvent/ReconEvent.h"
58
59#include "RawDataProviderSvc/MdcRawDataProvider.h" //jialk 20090624
60
61#include <fstream>
62#include <iostream>
63#include <vector>
64
65#include "BesTimerSvc/IBesTimerSvc.h"
66// #include "BesTimerSvc/BesTimerSvc.h"
67#include "BesTimerSvc/BesTimer.h"
68
69using namespace std;
70using namespace Event;
71
75TrkReco::TrkReco( const std::string& name, ISvcLocator* pSvcLocator )
76 : Algorithm( name, pSvcLocator )
77 , _cdc( 0 )
78 , _perfectFinder( 0 )
79 , _rkfitter( "range fitter", false, 0, true )
80 // , _rkfitter( 0 )
81 , _confFinder( 0 )
82 , _curlFinder( 0 )
83 , _nEvents( 0 ) {
84
85 std::cout << std::fixed << std::setprecision( 3 ); // yzhang debug for 720
86 /// Initiate Parameters for TrkReco
87 initPara();
88
90}
91
92//************************************************************************Initialize
93StatusCode TrkReco::initialize() {
94 MsgStream log( msgSvc(), name() );
95 log << MSG::INFO << "in initialize()" << endmsg;
96
97 _rkfitter.setBesFromGdml();
98
99 StatusCode sc;
100
101 /// Get RawDataProviderSvc
102 IRawDataProviderSvc* irawDataProviderSvc;
103 sc = service( "RawDataProviderSvc", irawDataProviderSvc );
104 _rawDataProviderSvc = irawDataProviderSvc;
105 if ( sc.isFailure() )
106 {
107 log << MSG::FATAL << "Could not load RawDataProviderSvc!" << endmsg;
108 return StatusCode::FAILURE;
109 }
110
111 /// Get MdcGeomSvc
112 // IMdcGeomSvc* imdcGeomSvc;
113 // sc = service("MdcGeomSvc", imdcGeomSvc);
114 // _mdcGeomSvc = dynamic_cast<MdcGeomSvc*> (imdcGeomSvc);
115 // if (sc.isFailure()) {
116 // return( StatusCode::FAILURE);
117 // }
118
119 /// Get MdcCalibFunSvc
120 IMdcCalibFunSvc* imdcCalibSvc;
121 sc = service( "MdcCalibFunSvc", imdcCalibSvc );
122 _mdcCalibFunSvc = imdcCalibSvc;
123 if ( sc.isFailure() ) { log << MSG::FATAL << "Could not load MdcCalibFunSvc!" << endmsg; }
124
125 /// Initialize NTuple
126 if ( b_tuple ) InitTuple();
127
128#ifdef TRKRECO_DEBUG
129 b_debugLevel = 2;
130#endif
131
132 //...Create TMDC...
133 // _cdc = cdcInit();
134
135 //...TrkReco...
137
138 //...Create rphi finder...
139 /* _perfectFinder = new TPerfectFinder(b_perfectFitting,
140 b_conformalMaxSigma,
141 b_conformalStereoMaxSigma,
142 b_conformalFittingCorrections);
143 */
144 if ( ( !_confFinder ) && ( b_conformalFinder == 0 ) )
145 {
146 _confFinder = new TConformalFinder0(
150 }
151 else if ( !_confFinder )
152 {
153 _confFinder = new TConformalFinder(
160 }
161 _confFinder->debugLevel( b_debugLevel );
162 _confFinder->doStereo( b_doConformalFinderStereo );
163
164 //...Salvage flag is ignored in new conf. finder...
165 if ( b_doSalvage == 2 ) _confFinder->doSalvage( true );
166
167 //...Create curl finder...
168 if ( !_curlFinder )
169 _curlFinder = new TCurlFinder(
181 (unsigned)output_2dtracks, (unsigned)curl_version,
182 // jialk
186 _curlFinder->debugLevel( b_debugLevel );
187
188 //...Track manager setup...
189 _trackManager.maxMomentum( b_momentumCut );
190 _trackManager.debugLevel( b_debugLevel );
191 _trackManager.fittingFlag( b_fittingFlag );
192
193 //...Initialize...
194 // zsl TUpdater::initialize();
195
196 //...For debug...
197 // dump("parameter");
198
200
201 if ( b_timeTest && b_tuple )
202 {
203 StatusCode sc = service( "BesTimerSvc", m_timersvc );
204 if ( sc.isFailure() )
205 {
206 log << MSG::WARNING << " Unable to locate BesTimerSvc" << endmsg;
207 return StatusCode::FAILURE;
208 }
209 m_timer[1] = m_timersvc->addItem( "Execution" );
210 m_timer[1]->propName( "nExecution" );
211 }
212
213 return StatusCode::SUCCESS;
214}
215//************************************************************************MDCInit
216TMDC* TrkReco::cdcInit( void ) {
217 _cdcVersion = std::to_string( b_cdcVersion );
218 if ( !_cdc ) _cdc = TMDC::getTMDC( _cdcVersion );
219 _cdc->debugLevel( b_debugLevel );
220
221 //...Obtain fudge factor...
222 float fudgeFactor = b_fudgeFactor;
223
224 /* if (fudgeFactor == 0.) {
225 const calcdc_const4 & c = * (calcdc_const4 *) BsGetEnt(CALMDC_CONST4,
226 1,
227 BBS_No_Index);
228 if (!(& c)) fudgeFactor = 1.;
229 else fudgeFactor = c.m_fudge;
230 }*/
231
232 //...Turn off fudge factor before checking performance...
233 fudgeFactor = 1.0;
234
235 _cdc->fudgeFactor( fudgeFactor );
236 return _cdc;
237}
238
239//************************************************************************Finalize
240StatusCode TrkReco::finalize() {
241
242 if ( b_timeTest && b_tuple ) m_timersvc->print();
243
244 //...Clear TrkReco objects...
245 if ( _cdc ) _cdc->fastClear();
246 if ( b_doConformalFinder && _confFinder ) _confFinder->clear();
247 if ( b_doCurlFinder && _curlFinder ) _curlFinder->clear();
248
249 //...Summary...
250 // dump("summary");
251
252 //...Delete TrkReco objects...
253 if ( _confFinder ) delete _confFinder;
254 if ( _curlFinder ) delete _curlFinder;
255
256 return StatusCode::SUCCESS;
257}
258StatusCode TrkReco::beginRun() {
259 /// Get MdcGeomSvc
260 IMdcGeomSvc* imdcGeomSvc;
261 StatusCode sc1 = Gaudi::svcLocator()->service( "MdcGeomSvc", imdcGeomSvc );
262 _mdcGeomSvc = imdcGeomSvc;
263 if ( sc1.isFailure() ) { return ( StatusCode::FAILURE ); }
264 _cdc = cdcInit();
265
266 return StatusCode::SUCCESS;
267}
268void TrkReco::disp_stat( const char* m ) {
269 std::string msg = m;
270 // dump(msg);
271}
272
273//************************************************************************Execute
274StatusCode TrkReco::execute() {
275 if ( !m_beginRun )
276 {
277 StatusCode sc = beginRun();
278 if ( sc.isFailure() )
279 {
280 error() << "beginRun failed" << endmsg;
281 return StatusCode::FAILURE;
282 }
283 m_beginRun = true;
284 }
285
286 MsgStream log( msgSvc(), name() );
287 log << MSG::INFO << "in execute()" << endmsg;
288
289 StatusCode sc;
290 if ( b_timeTest && b_tuple ) m_timer[1]->start();
291
292 // Initiate state of all sense wire
293 if ( b_goodTrk && b_tuple )
294 for ( int ii = 0; ii < 43; ii++ )
295 {
296 for ( int jj = 0; jj < 288; jj++ )
297 {
298 havedigi[ii][jj] = -99; // no hit/noise
299 }
300 }
301
302 //------------------------------------
303 // Initialize track collection in TDS
304 //------------------------------------
305 // yzhang add 2010-04-30
306 // Clear TDS tracks and hits
308 {
309 IDataManagerSvc* dataManSvc;
310 DataObject* aTrackCol;
311 DataObject* aRecHitCol;
312
313 if ( !m_combineTracking )
314 {
315 dataManSvc = dynamic_cast<IDataManagerSvc*>( eventSvc().get() );
316 eventSvc()->findObject( "/Event/Recon/RecMdcTrackCol", aTrackCol );
317 if ( nullptr != aTrackCol )
318 {
319 dataManSvc->clearSubTree( "/Event/Recon/RecMdcTrackCol" );
320 eventSvc()->unregisterObject( "/Event/Recon/RecMdcTrackCol" );
321 }
322 eventSvc()->findObject( "/Event/Recon/RecMdcHitCol", aRecHitCol );
323 if ( nullptr != aRecHitCol )
324 {
325 dataManSvc->clearSubTree( "/Event/Recon/RecMdcHitCol" );
326 eventSvc()->unregisterObject( "/Event/Recon/RecMdcHitCol" );
327 }
328 }
329 DataObject* aReconEvent;
330 eventSvc()->findObject( "/Event/Recon", aReconEvent );
331 if ( !aReconEvent )
332 {
333 ReconEvent* recevt = new ReconEvent;
334 StatusCode sc = eventSvc()->registerObject( "/Event/Recon", recevt );
335 if ( sc != StatusCode::SUCCESS )
336 {
337 log << MSG::FATAL << "Could not register ReconEvent" << endmsg;
338 return ( StatusCode::FAILURE );
339 }
340 }
341 RecMdcTrackCol* trkcol;
342 eventSvc()->findObject( "/Event/Recon/RecMdcTrackCol", aTrackCol );
343 if ( aTrackCol ) { trkcol = dynamic_cast<RecMdcTrackCol*>( aTrackCol ); }
344 else
345 {
346 trkcol = new RecMdcTrackCol;
347 sc = eventSvc()->registerObject( EventModel::Recon::RecMdcTrackCol, trkcol );
348 if ( !sc.isSuccess() )
349 {
350 log << MSG::FATAL << " Could not register RecMdcTrack collection" << endmsg;
351 return StatusCode::FAILURE;
352 }
353 }
354 RecMdcHitCol* hitcol;
355 eventSvc()->findObject( "/Event/Recon/RecMdcHitCol", aRecHitCol );
356 if ( aRecHitCol ) { hitcol = dynamic_cast<RecMdcHitCol*>( aRecHitCol ); }
357 else
358 {
359 hitcol = new RecMdcHitCol;
360 sc = eventSvc()->registerObject( EventModel::Recon::RecMdcHitCol, hitcol );
361 if ( !sc.isSuccess() )
362 {
363 log << MSG::FATAL << " Could not register RecMdcHit collection" << endmsg;
364 return StatusCode::FAILURE;
365 }
366 }
367 // Part 1: Get Tev
368 t0_bes = 0.;
369 t0Sta = -1;
370 if ( useESTime )
371 {
372 SmartDataPtr<RecEsTimeCol> aevtimeCol( eventSvc(), "/Event/Recon/RecEsTimeCol" );
373 // bugcheck jialk
374 if ( aevtimeCol && aevtimeCol->size() )
375 {
376 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
377 t0_bes = ( *iter_evt )->getTest();
378 t0Sta = ( *iter_evt )->getStat();
379 }
380 else
381 {
382 log << MSG::WARNING << "Could not find EsTimeCol" << endmsg;
383 return StatusCode::SUCCESS;
384 }
385 }
386
387 // Part 2: Get the event header
388 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
389 if ( !eventHeader )
390 {
391 log << MSG::FATAL << "Could not find Event Header" << endmsg;
392 return ( StatusCode::FAILURE );
393 }
394 _nEvents = eventHeader->eventNumber();
395 if ( b_tuple ) std::cout << "TrkReco ... processing ev# " << _nEvents << std::endl;
396
397 // Part 3: Retrieve MDC digi
398 int digiId;
399 uint32_t getDigiFlag = 0;
403 MdcDigiVec mdcDigiVec = _rawDataProviderSvc->getMdcDigiVec( getDigiFlag );
404 if ( 0 == mdcDigiVec.size() )
405 {
406 log << MSG::WARNING << " No hits in MdcDigiVec" << endmsg;
407 return StatusCode::SUCCESS;
408 }
409 /* //jialk in order to reject events with exceeding # of total hits 2009/03/31
410 if (mdcDigiVec.size() > 2000){
411 log << MSG::WARNING << " Too many hits in MdcDigiVec" << endmsg;
412 return StatusCode::SUCCESS;
413 }*/
414 MdcDigiVec::iterator iter1 = mdcDigiVec.begin();
415 MC_DIGI_SIZE = mdcDigiVec.size();
416
417 digiId = 0;
418 Identifier mdcId;
419 int layerId;
420 int wireId;
421
422 // Clear the old MdcRec_wirhit tables and create the hits' info for the new event.
423 unsigned nt = MdcRecWirhitCol::getMdcRecWirhitCol()->size();
424 // cout<<"Col size of last Event's WirHit = "<<nt<<endl;
426
427 for ( ; iter1 != mdcDigiVec.end(); iter1++, digiId++ )
428 {
429 // log << MSG::INFO << "MDC digit No: " << digiId << endmsg;
430 mdcId = ( *iter1 )->identify();
431 layerId = MdcID::layer( mdcId );
432 wireId = MdcID::wire( mdcId );
433 /*log << MSG::INFO
434 << " time_channel = " << (*iter1)->getTimeChannel()
435 <<" time = "<<(*iter1)->getTimeChannel()* 40./10000/1000000
436 << " charge_channel = " << (*iter1)->getChargeChannel()
437 << " layerId = " << layerId
438 << " wireId = " << wireId
439 << endmsg;*/
440
441 if ( b_goodTrk && b_tuple )
442 havedigi[layerId][wireId] = ( *iter1 )->getTrackIndex(); //-1:noise 0-n:tracks
443
444 MdcRec_wirhit mhit;
445
446 mhit.id = digiId;
447 mhit.geo = _mdcGeomSvc->Wire( layerId, wireId );
448 // Apply crude TOF, Belle: tof=1.074*radius/c, here we use 1.28 instead of 1.074.
449 double tof;
450 tof = 1.28 * mhit.geo->Lyr()->Radius() / 299.8; // unit of Radius is mm.
451 mhit.tdc = RawDataUtil::MdcTime( ( *iter1 )->getTimeChannel() );
452
453 // cout<<" .. mhit.tdc = "<<mhit.tdc<<" t0_bes = "<<t0_bes<<endl;
454 mhit.tdc -= t0_bes;
455
456 // jialk
457 _trackManager.sett0bes( t0_bes );
458 // mhit.adc = RawDataUtil::MdcCharge((*iter1)->getChargeChannel());
459 // mhit.tdc = (*iter1)->getTimeChannel();
460 mhit.adc = ( *iter1 )->getChargeChannel();
461 // cout<<"raw tdc(ns): "<<mhit.tdc<<"; tof(ns): "<<tof<<endl;
462 // double dist2 = _mdcCalibFunSvc->rawTimeNoTOFToDist(mhit.tdc-tof, layerId,
463 // wireId, 2, 0.0);
464 // mhit.erddl = _mdcCalibFunSvc->getSigma(layerId, 2, dist2, 0.0);
465 double timewalk = _mdcCalibFunSvc->getTimeWalk( layerId, mhit.adc );
466 double T0 = _mdcCalibFunSvc->getT0( layerId, wireId );
467 double drifttime = mhit.tdc - tof - timewalk - T0;
468 double dist2 = _mdcCalibFunSvc->driftTimeToDist( drifttime, layerId, wireId, 2,
469 0 ); // by liucy 2010/05/12
470 mhit.erddl = _mdcCalibFunSvc->getSigma( layerId, 2, dist2, 0.0, 0.0, 0.0, mhit.adc );
471 // cout<<"getSigma: "<<mhit.erddl<<endl;
472 mhit.ddl = dist2 / 10.; // mm->cm
473 mhit.ddr = mhit.ddl;
474 mhit.erddl = mhit.erddl / 10.; // mm->cm
475 mhit.erddr = mhit.erddl;
476
477 mhit.lr = 2;
478 mhit.stat = 0;
479 mhit.stat = mhit.stat |= 1048576; // bit20 WireHitTimeValid
480 mhit.stat = mhit.stat |= 2097152; // bit21 WireHitChargeValid
481 mhit.stat = mhit.stat |= 4194304; // bit22 WireHitFindingValid
482 mhit.stat = mhit.stat |= 1073741824; // bit30
483 // cout<<"layerNo = "<<mhit.geo->Layer()<<"; "<<mdigi.digi[i].layerNo<<endl;
484 // cout<<"cellNo = "<<mhit.geo->Cell()<<"; "<<mdigi.digi[i].cellNo<<endl;
485 // cout<<"NCell of this layer = "<<mhit.geo->Lyr()->NCell()<<endl;
486 // cout<<"NCell of this layer = "<<mhit.geo->Lyr()->NCell()<<endl;
487 MdcRecWirhitCol::getMdcRecWirhitCol()->push_back( mhit );
488
489 if ( b_tuple )
490 {
491 t10_tdc = mhit.tdc;
492 t10_adc = mhit.adc;
493 t10_drift = mhit.ddl;
494 t10_dDrift = mhit.erddl;
495 t10_lyrId = layerId;
496 t10_localId = wireId;
497 m_tuple10->write();
498 }
499 }
500
501 unsigned nT0Reset = 0;
502
503 //...Starting point...
504 TrkReco_start:
505
506 //...Clear myself...
507 clear();
508
509 // jialk in order to reject events with exceeding # of total hits 2009/03/31
510 if ( mdcDigiVec.size() > 2000 )
511 {
512 log << MSG::WARNING << " Too many hits in MdcDigiVec" << endmsg;
513 return StatusCode::SUCCESS;
514 }
515
516 //...Update TMDC...
517 _cdc->update( b_doMCAnalysis );
518
519 //...Get lists of hits...
520 unsigned mask = 0;
521 if ( !b_useAllHits ) mask = WireHitFindingValid;
522 const AList<TMDCWireHit>& axialHits = _cdc->axialHits( mask );
523 const AList<TMDCWireHit>& stereoHits = _cdc->stereoHits( mask );
524 const AList<TMDCWireHit>& allHits = _cdc->hits( mask );
525 // cout<<"axial: "<<axialHits.length()<<" stereo: "<<stereoHits.length()<<endl;
526
527 //...Storage for tracks...
529 AList<TTrack> tracks2D;
530
531 //...Perfect finder...
532 if ( b_doPerfectFinder )
533 {
534 _perfectFinder->doit( axialHits, stereoHits, tracks, tracks2D );
535 _trackManager.append( tracks );
536 }
537
538 else
539 {
540 //...Conformal finder...
542 {
543
544 //...T0 reset option...
545 if ( b_doT0Reset )
546 {
547 if ( b_nT0ResetMax > nT0Reset )
548 ( (TConformalFinder*)_confFinder )->doT0Reset( true );
549 else ( (TConformalFinder*)_confFinder )->doT0Reset( false );
550 }
551
552 _confFinder->doit( axialHits, stereoHits, tracks, tracks2D );
553
554 //...T0 reset...
555 if ( b_doT0Reset )
556 {
557 ++nT0Reset;
558 if ( ( (TConformalFinder*)_confFinder )->T0ResetDone() ) goto TrkReco_start;
559 }
560
561 // cout<<"tracks: "<<tracks.length()<<endl;
562
563 //...Stores tracks...
564 _trackManager.append( tracks );
565 _trackManager.append2D( tracks2D );
566 if ( b_conformalFinder == 0 )
567 {
568 if ( b_doSalvage == 1 ) _trackManager.salvage( allHits );
569 if ( b_doSalvage ) _trackManager.mask();
570 }
571 }
572
573 //...Curl finder...
574 if ( b_doCurlFinder )
575 {
576 if ( ( !b_doSalvage ) && ( b_conformalFinder == 0 ) )
577 _trackManager.maskCurlHits( axialHits, stereoHits, _trackManager.tracks() );
578 AList<TTrack> confTracks = _trackManager.tracks();
579 tracks.append( confTracks );
580 _curlFinder->doit( axialHits, stereoHits, tracks, tracks2D );
581 tracks.remove( confTracks );
582 //_trackManager.append(tracks);
583 }
584
585 //...Finishes tracks...
586 // if ((b_doSalvage) && (b_conformalFinder == 0)) _trackManager.refit();
587
588 //...Appends tracks which are reconstructed by CurlFinder...
589 if ( b_doCurlFinder )
590 {
591 _trackManager.append( tracks );
592 _trackManager.append2D( tracks2D );
593 }
594
595 //...Merge & Mask ...
596 // if ((b_doMerge) && (b_conformalFinder == 0)) _trackManager.merge();
597 _trackManager.merge(); // Liuqg
598 // if (b_conformalFinder != 0) _trackManager.setCurlerFlags();
599
600 //...Salvage for dE/dx...
601 // if (b_doAssociation)
602 // _trackManager.salvageAssociateHits(allHits, b_associateSigma);
603 }
604
605 //...Move a pivot... //move to the innermost hit, remove this step now 2005/10/17 zang
606 // shilei _trackManager.movePivot();
607
608 //...Save Panther tables...
609 // _trackManager.checkNumberOfHits();
610 // if (b_sortMode == 0) _trackManager.sortTracksByQuality();
611 // else _trackManager.sortTracksByPt();
612 /*if (b_doMCAnalysis) {
613 if (mcEvent()) {
614 mcInformation();
615 _trackManager.saveMCTables();
616 }
617 }*/
618
619 if ( b_tuple ) FillTuple();
620
621 // write Tds
622 int t_tkStat = 2;
623 if ( !b_doConformalFinder && b_doCurlFinder ) t_tkStat = 3; // FIXME
624 StatusCode scTds =
625 _trackManager.makeTds( trkcol, hitcol, t_tkStat, b_RungeKuttaCorrection, m_CalibFlag );
626 if ( scTds != StatusCode::SUCCESS ) return ( StatusCode::FAILURE );
627
628 //...T0 correction...
630 {
631 _trackManager.determineT0( b_doT0Determination, b_nTracksForT0 );
632 if ( b_tuple ) t3_t0Rec = _trackManager.paraT0();
633 }
634 }
635 else if ( b_RungeKuttaCorrection == 1 )
636 {
637 if ( useESTime )
638 {
639 SmartDataPtr<RecEsTimeCol> aevtimeCol( eventSvc(), "/Event/Recon/RecEsTimeCol" );
640 if ( aevtimeCol && aevtimeCol->size() )
641 {
642 RecEsTimeCol::iterator iter_evt = aevtimeCol->begin();
643 t0_bes = ( *iter_evt )->getTest();
644 t0Sta = ( *iter_evt )->getStat();
645 }
646 else
647 {
648 log << MSG::WARNING << "Could not find EsTimeCol" << endmsg;
649 return StatusCode::SUCCESS;
650 }
651 }
652
653 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
654 if ( !eventHeader )
655 {
656 log << MSG::FATAL << "Could not find Event Header" << endmsg;
657 return ( StatusCode::FAILURE );
658 }
659 _nEvents = eventHeader->eventNumber();
660 if ( b_tuple ) std::cout << "TrkReco ... processing ev# " << _nEvents << std::endl;
661 AList<TTrack> rktracks;
662 int digiId;
663 uint32_t getDigiFlag = 0;
667 MdcDigiVec mdcDigiVec = _rawDataProviderSvc->getMdcDigiVec( getDigiFlag );
668 if ( 0 == mdcDigiVec.size() )
669 {
670 log << MSG::WARNING << " No hits in MdcDigiVec" << endmsg;
671 return StatusCode::SUCCESS;
672 }
673 MdcDigiVec::iterator iter1 = mdcDigiVec.begin();
674 MC_DIGI_SIZE = mdcDigiVec.size();
675
676 digiId = 0;
677 Identifier mdcId;
678 int layerId;
679 int wireId;
680
681 unsigned nt = MdcRecWirhitCol::getMdcRecWirhitCol()->size();
683
684 for ( ; iter1 != mdcDigiVec.end(); iter1++, digiId++ )
685 {
686 mdcId = ( *iter1 )->identify();
687 layerId = MdcID::layer( mdcId );
688 wireId = MdcID::wire( mdcId );
689 if ( b_goodTrk && b_tuple ) havedigi[layerId][wireId] = ( *iter1 )->getTrackIndex();
690
691 MdcRec_wirhit mhit;
692
693 mhit.id = digiId;
694 mhit.geo = _mdcGeomSvc->Wire( layerId, wireId );
695 double tof;
696 tof = 1.28 * mhit.geo->Lyr()->Radius() / 299.8;
697 mhit.tdc = RawDataUtil::MdcTime( ( *iter1 )->getTimeChannel() );
698 mhit.timechannel = ( *iter1 )->getTimeChannel();
699 mhit.tdc -= t0_bes;
700
701 _trackManager.sett0bes( t0_bes );
702 mhit.adc = ( *iter1 )->getChargeChannel();
703 double timewalk = _mdcCalibFunSvc->getTimeWalk( layerId, mhit.adc );
704 double T0 = _mdcCalibFunSvc->getT0( layerId, wireId );
705 double drifttime = mhit.tdc - tof - timewalk - T0;
706 double dist2 = _mdcCalibFunSvc->driftTimeToDist( drifttime, layerId, wireId, 2, 0 );
707 mhit.erddl = _mdcCalibFunSvc->getSigma( layerId, 2, dist2, 0.0, 0.0, 0.0, mhit.adc );
708 mhit.ddl = dist2 / 10.;
709 mhit.ddr = mhit.ddl;
710 mhit.erddl = mhit.erddl / 10.;
711 mhit.erddr = mhit.erddl;
712
713 mhit.lr = 2;
714 mhit.stat = 0;
715 mhit.stat = mhit.stat |= 1048576;
716 mhit.stat = mhit.stat |= 2097152;
717 mhit.stat = mhit.stat |= 4194304;
718 mhit.stat = mhit.stat |= 1073741824;
719 MdcRecWirhitCol::getMdcRecWirhitCol()->push_back( mhit );
720
721 if ( b_tuple )
722 {
723 t10_tdc = mhit.tdc;
724 t10_adc = mhit.adc;
725 t10_drift = mhit.ddl;
726 t10_dDrift = mhit.erddl;
727 t10_lyrId = layerId;
728 t10_localId = wireId;
729 m_tuple10->write();
730 }
731 }
732
733 unsigned nT0Reset = 0;
734
735 clear();
736 if ( mdcDigiVec.size() > 2000 )
737 {
738 log << MSG::WARNING << " Too many hits in MdcDigiVec" << endmsg;
739 return StatusCode::SUCCESS;
740 }
741 int counter = 0;
742 _cdc->update( b_doMCAnalysis );
743
744 unsigned mask = 0;
745 if ( !b_useAllHits ) mask = WireHitFindingValid;
746 const AList<TMDCWireHit>& axialHits = _cdc->axialHits( mask );
747 const AList<TMDCWireHit>& stereoHits = _cdc->stereoHits( mask );
748 const AList<TMDCWireHit>& allHits = _cdc->hits( mask );
749 AList<TMLink> _allHits[3];
752 _allHits[2].append( _allHits[0] );
753 _allHits[2].append( _allHits[1] );
754
755 SmartDataPtr<RecMdcTrackCol> mdcTracks( eventSvc(), EventModel::Recon::RecMdcTrackCol );
756 if ( !mdcTracks )
757 {
758 log << MSG::ERROR << "Unable to retrieve RecMdcTrackCol" << endmsg;
759 return StatusCode::FAILURE;
760 }
761 else
762 {
763 log << MSG::DEBUG << "RecMdcTrackCol retrieved of size " << mdcTracks->size() << endmsg;
764 int ntrk = 0;
765 for ( RecMdcTrackCol::iterator it = mdcTracks->begin(); it != mdcTracks->end(); it++ )
766 {
767 ntrk++;
768 TRunge* r = new TRunge( **it );
769 TTrack* t1 = new TTrack( *r );
770 HitRefVec gothits = ( *it )->getVecHits();
771 HitRefVec::iterator it_gothit = gothits.begin();
772 unsigned stat = ( *it )->stat();
773 int nhit = 0;
774 for ( ; it_gothit != gothits.end(); it_gothit++ )
775 {
776 for ( int i = 0; i < _allHits[2].length(); i++ )
777 {
778 int lyrraw = _allHits[2][i]->wire()->layerId();
779 int wireraw = _allHits[2][i]->wire()->localId();
780 int g_layer = MdcID::layer( ( *it_gothit )->getMdcId() );
781 int g_wire = MdcID::wire( ( *it_gothit )->getMdcId() );
782 if ( lyrraw == g_layer && g_wire == wireraw )
783 {
784 nhit++;
785 t1->append( *_allHits[2][i] );
786 }
787 }
788 }
789 TRunge* rr = new TRunge( *t1 );
790 TRunge* tt = new TRunge( *t1 );
791 int err = _rkfitter.fit( *rr );
792 int nhits = rr->links().length();
793 int ndrop = 0;
794 int nmax = 0;
795 if ( nhits <= 10 ) nmax = 0;
796 if ( nhits > 10 ) nmax = (int)nhit * 0.3;
797 for ( int ii = 0; ii < nmax; ii++ )
798 {
799
800 ndrop = rr->DropWorst();
801 if ( ndrop ) err = _rkfitter.fit( *rr );
802 if ( err ) break;
803 }
804 if ( err == -2 ) counter++;
805 if ( m_CalibFlag == 1 )
806 { // This is for Calibration
807 tt->removeLinks();
808 tt->append( rr->links() );
809 for ( int i = 0; i < 43; i++ ) { err = _rkfitter.fit( *tt, 0, i ); }
810 rr->removeLinks();
811 rr->append( tt->links() );
812 TTrack* t = new TTrack( *rr );
813 if ( err == 0 )
814 {
815 rktracks.append( *t );
816 t->setFinderType( 100 + stat );
817 }
818 }
819 if ( m_CalibFlag == 0 )
820 {
821 TTrack* t = new TTrack( *rr );
822 if ( err == 0 )
823 {
824
825 t->setFinderType( 100 + stat );
826 rktracks.append( *t );
827 }
828 }
829 delete r;
830 delete t1;
831 delete rr;
832 delete tt;
833 }
834 }
835
836 _trackManager.append( rktracks );
837 IDataManagerSvc* dataManSvc;
838 DataObject* aTrackCol;
839 DataObject* aRecHitCol;
840 if ( !m_combineTracking )
841 {
842 dataManSvc = dynamic_cast<IDataManagerSvc*>( eventSvc().get() );
843 eventSvc()->findObject( "/Event/Recon/RecMdcTrackCol", aTrackCol );
844 if ( aTrackCol )
845 {
846 dataManSvc->clearSubTree( "/Event/Recon/RecMdcTrackCol" );
847 eventSvc()->unregisterObject( "/Event/Recon/RecMdcTrackCol" );
848 }
849 eventSvc()->findObject( "/Event/Recon/RecMdcHitCol", aRecHitCol );
850 if ( aRecHitCol )
851 {
852 dataManSvc->clearSubTree( "/Event/Recon/RecMdcHitCol" );
853 eventSvc()->unregisterObject( "/Event/Recon/RecMdcHitCol" );
854 }
855 }
856 DataObject* aReconEvent;
857 eventSvc()->findObject( "/Event/Recon", aReconEvent );
858 if ( !aReconEvent )
859 {
860 ReconEvent* recevt = new ReconEvent;
861 StatusCode sc = eventSvc()->registerObject( "/Event/Recon", recevt );
862 if ( sc != StatusCode::SUCCESS )
863 {
864 log << MSG::FATAL << "Could not register ReconEvent" << endmsg;
865 return ( StatusCode::FAILURE );
866 }
867 }
868 RecMdcTrackCol* trkcol;
869 eventSvc()->findObject( "/Event/Recon/RecMdcTrackCol", aTrackCol );
870 if ( aTrackCol ) { trkcol = dynamic_cast<RecMdcTrackCol*>( aTrackCol ); }
871 else
872 {
873 trkcol = new RecMdcTrackCol;
874 sc = eventSvc()->registerObject( EventModel::Recon::RecMdcTrackCol, trkcol );
875 if ( !sc.isSuccess() )
876 {
877 log << MSG::FATAL << " Could not register RecMdcTrack collection" << endmsg;
878 return StatusCode::FAILURE;
879 }
880 }
881 RecMdcHitCol* hitcol;
882 eventSvc()->findObject( "/Event/Recon/RecMdcHitCol", aRecHitCol );
883 if ( aRecHitCol ) { hitcol = dynamic_cast<RecMdcHitCol*>( aRecHitCol ); }
884 else
885 {
886 hitcol = new RecMdcHitCol;
887 sc = eventSvc()->registerObject( EventModel::Recon::RecMdcHitCol, hitcol );
888 if ( !sc.isSuccess() )
889 {
890 log << MSG::FATAL << " Could not register RecMdcHit collection" << endmsg;
891 return StatusCode::FAILURE;
892 }
893 }
894 if ( b_tuple ) FillTuple();
895
896 int t_tkStat = 2;
897 if ( !b_doConformalFinder && b_doCurlFinder ) t_tkStat = 3; // FIXME
898 StatusCode scTds =
899 _trackManager.makeTds( trkcol, hitcol, t_tkStat, b_RungeKuttaCorrection, m_CalibFlag );
901 {
902 _trackManager.determineT0( b_doT0Determination, b_nTracksForT0 );
903 if ( b_tuple ) t3_t0Rec = _trackManager.paraT0();
904 }
905 for ( unsigned i = 0; i < 3; i++ )
906 {
907 if ( i == 2 ) HepAListDeleteAll( _allHits[i] );
908 else _allHits[i].removeAll();
909 }
910
911 rktracks.removeAll();
912 }
913 //...For debug...
914 /*if (b_debugLevel) {
915 std::cout << "TrkReco ... ev# " << _nEvents << " processed,"
916 << " #tracks found=" << _trackManager.allTracks().length()
917 << ", #good tracks=" << _trackManager.tracks().length()
918 << ", #2D tracks=" << _trackManager.tracks2D().length()
919 << std::endl;
920 if (b_debugLevel > 1) _trackManager.dump("eventSummary hits");
921 else _trackManager.dump("eventSummary");
922 }*/
923
924 // TUpdater::update();
925
926 return StatusCode::SUCCESS;
927}
928
929void TrkReco::mcInformation( void ) {
930
931 //...Preparation...
932 // const AList<TTrack> & allTracks = _trackManager.allTracks();
933 const AList<TTrack>& allTracks = _trackManager.tracksFinal();
934
935 unsigned nHep = TTrackHEP::list().length();
936 unsigned nTrk = allTracks.length();
937 unsigned* N = (unsigned*)malloc( nHep * sizeof( unsigned ) );
938 for ( unsigned i = 0; i < nHep; i++ ) N[i] = 0;
939
940 //...Loop over all tracks...
941 for ( unsigned i = 0; i < nTrk; i++ )
942 {
943 TTrackMC* mc = allTracks[i]->_mc;
944 if ( !mc )
945 {
946 mc = new TTrackMC( *allTracks[i] );
947 _mcTracks.append( mc );
948 allTracks[i]->_mc = mc;
949 }
950
951 mc->update();
952 if ( mc->hepId() != -1 )
953 if ( mc->charge() ) ++N[mc->hepId()];
954 }
955
956 //...Check uniqueness...
957 for ( unsigned i = 0; i < nHep; i++ )
958 {
959 if ( N[i] < 2 )
960 {
961 for ( unsigned j = 0; j < nTrk; j++ )
962 if ( allTracks[j]->_mc->hepId() == i ) allTracks[j]->_mc->_quality += TTrackUnique;
963 }
964 }
965
966 //...Good tracks...
967 for ( unsigned i = 0; i < nTrk; i++ )
968 {
969 unsigned& quality = allTracks[i]->_mc->_quality;
970 if ( ( quality & TTrackGhost ) && ( quality & TTrackUnique ) ) quality += TTrackGood;
971 }
972
973 //...Termination...
974 free( N );
975}
976
977void TrkReco::clear( void ) {
978
979 //...Clear track candidates of the last event...
980 HepAListDeleteAll( _mcTracks );
981
982 //...Clear finders...
983 if ( b_doPerfectFinder ) _perfectFinder->clear();
984 if ( b_doConformalFinder ) _confFinder->clear();
985 if ( b_doCurlFinder ) _curlFinder->clear();
986 _trackManager.clear();
987 _trackManager.clearTables();
988}
989
990void TrkReco::fastClear( void ) { clear(); }
991
992bool TrkReco::mcEvent( void ) const {
993 // struct belle_event * ev =
994 // (struct belle_event *) BsGetEnt(BELLE_EVENT, 1, BBS_No_Index);
995
996 //...No BELLE_EVENT ???...
997 // if (! ev) return false;
998 // if (ev->m_ExpMC == 2) return true;
999 // return false;
1000 return true;
1001}
1002
1003// std::string
1004// TrkReco::version(void) const {
1005// return "TrkReco-00-00-04";
1006// }
1007
1008void TrkReco::initPara( void ) {
1009 /// Initiate Parameters for TrkReco
1010 // _rkfitter = new TRungeFitter( "range fitter", false, 0, true );
1011
1012 declareProperty( "mcPar", b_mcPar = 0 );
1013 declareProperty( "mcHit", b_mcHit = 0 );
1014 declareProperty( "tuple", b_tuple = 0 );
1015 declareProperty( "goodTrk", b_goodTrk = 0 );
1016 declareProperty( "timeTest", b_timeTest = 0 );
1017
1018 declareProperty( "cdcVersion", b_cdcVersion = 1.0 );
1019 declareProperty( "fudgeFactor", b_fudgeFactor = 1.0 );
1020
1021 declareProperty( "useESTime", useESTime = 1.0 );
1022
1023 declareProperty( "debugLevel", b_debugLevel = 0 );
1024 declareProperty( "useAllHits", b_useAllHits = 0 );
1025 declareProperty( "doT0Reset", b_doT0Reset = 0 );
1026 declareProperty( "nT0ResetMax", b_nT0ResetMax = 1 );
1027 declareProperty( "doMCAnalysis", b_doMCAnalysis = 1 );
1028 declareProperty( "helixFitterChisqMax", b_helixFitterChisqMax = 0. );
1029
1030 declareProperty( "RungeKuttaCorrection", b_RungeKuttaCorrection = 0 );
1031 declareProperty( "doPerfectFinder", b_doPerfectFinder = 0 );
1032 declareProperty( "perfectFitting", b_perfectFitting = 0 );
1033
1034 declareProperty( "conformalFinder", b_conformalFinder = 1 );
1035 declareProperty( "doConformalFinder", b_doConformalFinder = 0 );
1036 declareProperty( "doConformalFastFinder", b_doConformalFastFinder = 1 );
1037 declareProperty( "doConformalSlowFinder", b_doConformalSlowFinder = 1 );
1038 declareProperty( "conformalPerfectSegmentFinding", b_conformalPerfectSegmentFinding = 0 );
1039 declareProperty( "conformalFittingFlag",
1040 b_conformalFittingFlag = 4 ); // 1: sag 2: propagation 4: tof 8: freeT0
1041 declareProperty( "conformalMaxSigma", b_conformalMaxSigma = 30. );
1042 declareProperty( "conformalMinNLinksForSegment", b_conformalMinNLinksForSegment = 2 );
1043 declareProperty( "conformalMinNCores", b_conformalMinNCores = 2 ); // min core for a seg
1044 declareProperty( "conformalMinNSegments",
1045 b_conformalMinNSegments = 2 ); // min seg for trk, default: 3
1046 declareProperty( "salvageLevel", b_salvageLevel = 30. );
1047 declareProperty( "conformalSalvageLoadWidth", b_conformalSalvageLoadWidth = 1 );
1048 declareProperty( "conformalStereoMode", b_conformalStereoMode = 1 );
1049 declareProperty( "conformalStereoLoadWidth", b_conformalStereoLoadWidth = 5 );
1050 declareProperty( "conformalStereoMaxSigma", b_conformalStereoMaxSigma = 30. );
1051 declareProperty( "conformalStereoSzSegmentDistance",
1053 declareProperty( "conformalStereoSzLinkDistance", b_conformalStereoSzLinkDistance = 15. );
1054
1055 declareProperty( "doConformalFinderStereo",
1056 b_doConformalFinderStereo = 1 ); // cosmic, use stereo
1057 declareProperty( "doConformalFinderCosmic", b_doConformalFinderCosmic = 0 );
1058 declareProperty( "conformalFraction", b_conformalFraction = 0.7 ); // cores fraction in trk
1059 declareProperty( "conformalStereoZ3", b_conformalStereoZ3 = 20. );
1060 declareProperty( "conformalStereoZ4", b_conformalStereoZ4 = 20. );
1061 declareProperty( "conformalStereoChisq3", b_conformalStereoChisq3 = 30. );
1062 declareProperty( "conformalStereoChisq4", b_conformalStereoChisq4 = 30. );
1063 declareProperty( "conformalFittingCorrections", b_conformalFittingCorrections = 0 );
1064
1065 declareProperty( "doCurlFinder", b_doCurlFinder = 1 ); // CurlFinder on: 1 off: 0
1066 declareProperty( "doSalvage", b_doSalvage = 2 );
1067 declareProperty( "doMerge", b_doMerge = 0 );
1068 declareProperty( "momentumCut", b_momentumCut = 0.0 );
1069 declareProperty( "doT0Determination", b_doT0Determination = 7 );
1070 declareProperty( "nTracksForT0", b_nTracksForT0 = 2 );
1071 declareProperty( "sortMode", b_sortMode = 0 );
1072 declareProperty( "test", b_test = 0 );
1073 declareProperty( "fittingFlag", b_fittingFlag = 0 );
1074 declareProperty( "doAssociation", b_doAssociation = 1 );
1075 declareProperty( "associateSigma", b_associateSigma = 60 );
1076
1077 declareProperty( "dropHot", m_dropHot = 0 ); // jialk 20090624
1078 declareProperty( "combineTracking", m_combineTracking = 0 );
1079 declareProperty( "keepBadTdc", m_keepBadTdc = 0 );
1080 declareProperty( "keepUnmatch", m_keepUnmatch = 0 );
1081
1082 declareProperty( "CalibFlag", m_CalibFlag = 0 );
1083 // For Curl Finder -->
1084 declareProperty( "min_segment", min_segment = 5 ); // min links for a segment
1085 declareProperty( "min_salvage", min_salvage = 10 ); // salvage while trk.links < min
1086 declareProperty( "bad_distance_for_salvage", bad_distance_for_salvage = 1.0 );
1087 declareProperty( "good_distance_for_salvage", good_distance_for_salvage = 0.2 );
1088 declareProperty( "min_sequence", min_sequence = 6 );
1089 declareProperty( "min_fullwire", min_fullwire = 5 ); // Belle: 7
1090 declareProperty( "range_for_axial_search", range_for_axial_search = 1.5 );
1091 declareProperty( "range_for_stereo_search", range_for_stereo_search = 2.5 );
1092 declareProperty( "superlayer_for_stereo_search", superlayer_for_stereo_search = 3 );
1093 declareProperty( "range_for_axial_last2d_search", range_for_axial_last2d_search = 1.5 );
1094 declareProperty( "range_for_stereo_last2d_search", range_for_stereo_last2d_search = 2.0 );
1095 declareProperty( "trace2d_distance", trace2d_distance = 35.0 );
1096 declareProperty( "trace2d_first_distance", trace2d_first_distance = 0.5 );
1097 declareProperty( "trace3d_distance", trace3d_distance = 30.0 );
1098 declareProperty( "determine_one_track", determine_one_track = 0 );
1099 declareProperty( "selector_max_impact", selector_max_impact = 4.0 );
1100 declareProperty( "selector_max_sigma", selector_max_sigma = 36.0 );
1101 declareProperty( "selector_strange_pz", selector_strange_pz = 10.0 );
1102 declareProperty( "selector_replace_dz", selector_replace_dz = 15.0 );
1103 declareProperty( "stereo_2dfind", stereo_2dfind = 0 );
1104 declareProperty( "merge_exe", merge_exe = 1 );
1105 declareProperty( "merge_ratio", merge_ratio = 0.1 );
1106 declareProperty( "merge_z_diff", merge_z_diff = 10.0 );
1107 declareProperty( "mask_distance", mask_distance = 0.5 );
1108 declareProperty( "ratio_used_wire", ratio_used_wire = 0.3 );
1109 declareProperty( "range_for_stereo1", range_for_stereo1 = 2.4 );
1110 declareProperty( "range_for_stereo2", range_for_stereo2 = 2.7 );
1111 declareProperty( "range_for_stereo3", range_for_stereo3 = 2.9 );
1112 declareProperty( "range_for_stereo4", range_for_stereo4 = 3.4 );
1113 declareProperty( "range_for_stereo5", range_for_stereo5 = 4.1 );
1114 declareProperty( "range_for_stereo6", range_for_stereo6 = 5.0 ); // Liuqg
1115 declareProperty( "z_cut", z_cut = 50.0 );
1116 declareProperty( "z_diff_for_last_attend", z_diff_for_last_attend = 1.5 );
1117 declareProperty( "on_correction", on_correction = 4 ); // 1 sag, 2 propagation, 4 tof.
1118 // definition changed in BES
1119 declareProperty( "output_2dtracks", output_2dtracks = 1 ); // fill 2D track
1120 declareProperty( "curl_version", curl_version = 0 );
1121 // jialk
1122 declareProperty( "minimum_seedLength", minimum_seedLength = 5 );
1123 declareProperty( "minimum_2DTrackLength", minimum_2DTrackLength = 7 );
1124 declareProperty( "minimum_3DTrackLength", minimum_3DTrackLength = 10 );
1125 declareProperty( "minimum_closeHitsLength", minimum_closeHitsLength = 5 );
1126 declareProperty( "MIN_RADIUS_OF_STRANGE_TRACK", MIN_RADIUS_OF_STRANGE_TRACK = 50 );
1127 declareProperty( "ULTIMATE_MIN_RADIUS_OF_STRANGE_TRACK",
1129 // <-- For Curl Finder
1130}
1131
1132void TrkReco::InitTuple( void ) {
1133 m_tuple = ntupleSvc()->book( "FILE101/rec3D", CLID_ColumnWiseTuple, "MdcRecEvent" );
1134 m_tuple->addItem( "mc_phi", t_mcphi );
1135 m_tuple->addItem( "mc_theta", t_mctheta );
1136 m_tuple->addItem( "mc_ptot", t_mcptot );
1137 m_tuple->addItem( "mc_pt", t_mcpt );
1138 m_tuple->addItem( "mc_pz", t_mcpz );
1139 m_tuple->addItem( "mc_t0", t_mct0 );
1140 m_tuple->addItem( "nDigi", t_nDigi );
1141
1142 m_tuple->addItem( "dr", t_dr );
1143 m_tuple->addItem( "dz", t_dz );
1144 m_tuple->addItem( "pt", t_pt );
1145 m_tuple->addItem( "ptot", t_ptot );
1146 m_tuple->addItem( "tanlmd", t_tanlmd );
1147 m_tuple->addItem( "phi", t_phi );
1148 m_tuple->addItem( "radius", t_radius );
1149 m_tuple->addItem( "chi2", t_chi2 );
1150 m_tuple->addItem( "nHits", t_nHits );
1151 m_tuple->addItem( "nCores", t_nCores );
1152 m_tuple->addItem( "nSegs", t_nSegs );
1153 m_tuple->addItem( "ndf", t_ndf );
1154
1155 m_tuple->addItem( "dpt", t_dpt );
1156 m_tuple->addItem( "dptot", t_dptot );
1157 m_tuple->addItem( "dlmd", t_dlmd );
1158 m_tuple->addItem( "dphi", t_dphi );
1159
1160 m_tuple->addItem( "t0", t_t0 );
1161 m_tuple->addItem( "t0_sta", t0_sta ); // mdc, tof
1162
1163 m_tuple->addItem( "evtNo", t_evtNo );
1164 m_tuple->addItem( "length", t_length );
1165 m_tuple->addItem( "length2", t_length2 );
1166
1167 m_tuple->addItem( "gd_theta", t_good_theta );
1168 m_tuple->addItem( "gd_nLayers", t_gdNLayers );
1169 m_tuple->addItem( "mc_nLayers", t_mcNLayers );
1170 m_tuple->addItem( "best_nLayers", t_bestNLayers );
1171 m_tuple->addItem( "best_mc_nLayers", t_bestMcNLayers );
1172
1173 m_tuple3 = ntupleSvc()->book( "FILE101/raw", CLID_ColumnWiseTuple, "Raw Data" );
1174 m_tuple3->addItem( "mc_t0", t3_mct0 );
1175 m_tuple3->addItem( "mc_theta", t3_mctheta );
1176 m_tuple3->addItem( "mc_phi", t3_mcphi );
1177 m_tuple3->addItem( "mc_ptot", t3_mcptot );
1178 m_tuple3->addItem( "mc_pt", t3_mcpt );
1179 m_tuple3->addItem( "mc_pid", t3_mcpid );
1180 m_tuple3->addItem( "evtNo", t3_evtNo );
1181
1182 m_tuple31 = ntupleSvc()->book( "FILE101/rawEvt", CLID_ColumnWiseTuple, "Raw Data" );
1183 m_tuple31->addItem( "nDigi", t3_nDigi );
1184 m_tuple31->addItem( "goodLength", t3_goodLength );
1185 m_tuple31->addItem( "length", t3_length );
1186 m_tuple31->addItem( "t0_rec", t3_t0Rec );
1187 m_tuple31->addItem( "t0", t3_t0 );
1188 m_tuple31->addItem( "t0_sta", t3_t0Sta );
1189 m_tuple31->addItem( "finalLength", t3_finalLength );
1190
1191 m_tuple31->addItem( "mc_theta", t3_mctheta );
1192 m_tuple31->addItem( "mc_ptot", t3_mcptot );
1193 m_tuple31->addItem( "mc_pt", t3_mcpt );
1194 m_tuple31->addItem( "evtNo", t3_evtNo );
1195
1196 m_tuple2 = ntupleSvc()->book( "FILE101/rec2D", CLID_ColumnWiseTuple, "MdcRecEvent 2D" );
1197 m_tuple2->addItem( "mc_theta", t2_mctheta );
1198 m_tuple2->addItem( "mc_pt", t2_mcpt );
1199 m_tuple2->addItem( "nDigi", t2_nDigi );
1200 m_tuple2->addItem( "nHits", t2_nHits );
1201 m_tuple2->addItem( "nSegs", t2_nSegs );
1202 m_tuple2->addItem( "chi2", t2_chi2 );
1203 m_tuple2->addItem( "evtNo", t2_evtNo );
1204 m_tuple2->addItem( "ndf", t2_ndf );
1205 m_tuple2->addItem( "length", t2_length );
1206 m_tuple2->addItem( "length2", t2_length2 );
1207 m_tuple2->addItem( "radius", t2_radius );
1208
1209 m_tuple4 = ntupleSvc()->book( "FILE101/hit", CLID_ColumnWiseTuple, "MdcRecEvent Hits" );
1210 m_tuple4->addItem( "d_cal", t4_Dist );
1211 m_tuple4->addItem( "d_meas", t4_drift ); // d_cal-d_meas
1212 m_tuple4->addItem( "e_meas", t4_dDrift ); // error measure
1213 m_tuple4->addItem( "mc_drift", t4_mcDrift );
1214 m_tuple4->addItem( "mcLR", t4_mcLR );
1215 m_tuple4->addItem( "pull", t4_pull );
1216 m_tuple4->addItem( "lyrId", t4_lyrId );
1217 m_tuple4->addItem( "localId", t4_localId );
1218 m_tuple4->addItem( "LR", t4_LR );
1219 m_tuple4->addItem( "tdc", t4_tdc );
1220 m_tuple4->addItem( "z", t4_z );
1221 m_tuple4->addItem( "bz", t4_bz ); // backward
1222 m_tuple4->addItem( "fz", t4_fz ); // forward
1223 m_tuple4->addItem( "fy", t4_fy ); // forward
1224 m_tuple4->addItem( "phi", t4_phi );
1225 m_tuple4->addItem( "nHits", t4_nHits );
1226
1227 m_tuple5 = ntupleSvc()->book( "FILE101/char", CLID_ColumnWiseTuple, "MdcRecEvent Charge" );
1228 m_tuple5->addItem( "ptotPos", t5_ptotPos );
1229 m_tuple5->addItem( "ptotNeg", t5_ptotNeg );
1230 m_tuple5->addItem( "drPos", t5_drPos );
1231 m_tuple5->addItem( "drNeg", t5_drNeg );
1232 m_tuple5->addItem( "dzPos", t5_dzPos );
1233 m_tuple5->addItem( "dzNeg", t5_dzNeg );
1234
1235 m_tuple6 = ntupleSvc()->book( "FILE101/urec", CLID_ColumnWiseTuple, "MdcRecEvent urec" );
1236 m_tuple6->addItem( "length2", u_length2 );
1237 m_tuple6->addItem( "mc_ptot", u_mcptot );
1238 m_tuple6->addItem( "mc_pt", u_mcpt );
1239 m_tuple6->addItem( "mc_theta", u_mctheta );
1240 m_tuple6->addItem( "nDigi", u_nDigi );
1241 m_tuple6->addItem( "evtNo", u_evtNo );
1242 m_tuple6->addItem( "mc_t0", u_mct0 );
1243 m_tuple6->addItem( "t0", ut_t0 );
1244 m_tuple6->addItem( "t0_sta", ut0_sta );
1245
1246 if ( b_timeTest && b_tuple )
1247 {
1248 m_tuple7 = ntupleSvc()->book( "FILE101/time", CLID_ColumnWiseTuple, "MdcRecEvent time" );
1249 m_tuple7->addItem( "time", ti_eventTime ); // total time in a event.
1250 m_tuple7->addItem( "recNum", ti_recTrkNum ); // total raw-tracks, include decayed tracks!
1251 m_tuple7->addItem( "evtNo", ti_evtNo );
1252 m_tuple7->addItem( "nHits", ti_nHits ); // total hits of rec-tracks
1253 m_tuple7->addItem( "nDigi", ti_nDigi ); // total hits in rawdata
1254 }
1255
1256 m_tuple9 = ntupleSvc()->book( "FILE101/seg", CLID_ColumnWiseTuple, "MdcRecEvent segments" );
1257 m_tuple9->addItem( "times", t9_times );
1258 m_tuple9->addItem( "nLinks", t9_nLinks );
1259 m_tuple9->addItem( "nUsed", t9_nUsed );
1260 m_tuple9->addItem( "nSL", t9_nSL );
1261 m_tuple9->addItem( "mctheta", t9_mctheta );
1262
1263 m_tuple10 =
1264 ntupleSvc()->book( "FILE101/rawHit", CLID_ColumnWiseTuple, "MdcRecEvent mchitCOL" );
1265 m_tuple10->addItem( "tdc", t10_tdc );
1266 m_tuple10->addItem( "adc", t10_adc );
1267 m_tuple10->addItem( "Drift", t10_drift );
1268 m_tuple10->addItem( "dDrift", t10_dDrift );
1269 m_tuple10->addItem( "lyrId", t10_lyrId );
1270 m_tuple10->addItem( "localId", t10_localId );
1271}
1272
1273void TrkReco::FillTuple( void ) {
1274 MsgStream log( msgSvc(), name() );
1275 log << MSG::INFO << "fill Tuple()" << endmsg;
1276
1277 /// Get Tracks
1278 AList<TTrack> tracks;
1279 AList<TTrack> tracks2D;
1280 tracks = _trackManager.tracks();
1281 tracks2D = _trackManager.tracks2D();
1282 // if(t3_t0Rec!=999. && fabs(t3_t0Rec + t0_bes - MC_EVENT_TIME) > 4)
1283 // cout<<"3Dtrack in manager: "<<tracks.length()<<endl;
1284 if ( tracks.length() == 0 )
1285 cout << "zslength: 3D length=0, and the 2D length is" << tracks2D.length() << endl;
1286
1287 /// Run Time Calculation
1288 if ( b_timeTest && b_tuple )
1289 {
1290 m_timer[1]->stop();
1291 ti_eventTime = m_timer[1]->elapsed();
1292 ti_nDigi = MC_DIGI_SIZE;
1293 ti_recTrkNum = tracks.length();
1294 ti_evtNo = _nEvents;
1295 for ( unsigned i = 0; i < ti_recTrkNum; ++i ) ti_nHits += tracks[i]->nLinks();
1296 m_tuple7->write();
1297 }
1298
1299 /// Retrieve MC
1300 CLHEP::Hep3Vector MC_TRACK_VEC;
1301 CLHEP::HepLorentzVector MC_TRACK_LRZVEC;
1302 float MC_TRACK_NUM;
1303 double MC_EVENT_TIME;
1304
1305 int digiId;
1306 int num_par = 0;
1307 MC_EVENT_TIME = -1;
1308 if ( b_mcPar )
1309 {
1310 SmartDataPtr<Event::McParticleCol> mcParticleCol( eventSvc(), "/Event/MC/McParticleCol" );
1311 if ( mcParticleCol )
1312 {
1313 Event::McParticleCol::iterator iter_mc = mcParticleCol->begin();
1314 digiId = 0;
1315 for ( ; iter_mc != mcParticleCol->end(); iter_mc++, digiId++ )
1316 {
1317 if ( ( *iter_mc )->statusFlags() == 8320 || ( *iter_mc )->statusFlags() == 128 )
1318 {
1319 MC_EVENT_TIME = ( *iter_mc )->initialFourMomentum().t();
1320 break;
1321 }
1322 }
1323 // jialk bugcheck
1324 iter_mc = mcParticleCol->begin();
1325 MC_TRACK_LRZVEC = ( *iter_mc )->initialFourMomentum(); // particularly for 1 track
1326 // events.
1327 MC_TRACK_VEC = ( *iter_mc )->initialFourMomentum().vect();
1328 MC_TRACK_NUM = mcParticleCol->size();
1329
1330#ifdef TRKRECO_DEBUG
1331 iter_mc = mcParticleCol->begin();
1332 digiId = 0;
1333 for ( ; iter_mc != mcParticleCol->end(); iter_mc++, digiId++ )
1334 {
1335 log << MSG::INFO << "MDC digit No: " << digiId << endmsg;
1336 log << MSG::INFO << " particleId = " << ( *iter_mc )->particleProperty()
1337 << " theta = " << ( *iter_mc )->initialFourMomentum().theta()
1338 << " phi= " << ( *iter_mc )->initialFourMomentum().phi()
1339 << " px= " << ( *iter_mc )->initialFourMomentum().px()
1340 << " py= " << ( *iter_mc )->initialFourMomentum().py()
1341 << " pz= " << ( *iter_mc )->initialFourMomentum().pz() << endmsg;
1342 }
1343#endif
1344 digiId = 0;
1345 iter_mc = mcParticleCol->begin();
1346 for ( ; iter_mc != mcParticleCol->end(); iter_mc++, digiId++ )
1347 {
1348 CLHEP::HepLorentzVector LRZVEC = ( *iter_mc )->initialFourMomentum();
1349 CLHEP::Hep3Vector VEC = ( *iter_mc )->initialFourMomentum().vect();
1350 // staFlag = (*iter_mc)->statusFlags();
1351
1352 t3_mctheta = LRZVEC.theta();
1353 t3_mcphi = VEC.phi();
1354 t3_mcptot = VEC.mag() / 1000.;
1355 t3_mcpt = VEC.perp() / 1000.;
1356 t3_mct0 = ( *iter_mc )->initialFourMomentum().t();
1357 t3_mcpid = ( *iter_mc )->particleProperty();
1358 t3_evtNo = _nEvents;
1359 if ( ( t3_mcpid == 211 || t3_mcpid == -211 || t3_mcpid == 321 ) &&
1360 fabs( cos( t3_mctheta ) ) < 0.93 )
1361 ++num_par;
1362 m_tuple3->write();
1363 }
1364 }
1365 }
1366
1367 /// Fill Tuple
1368 if ( tracks.length() == 0 )
1369 {
1370 u_length2 = tracks2D.length();
1371 u_mct0 = MC_EVENT_TIME;
1372 u_mcptot = MC_TRACK_VEC.mag() / 1000.;
1373 u_mcpt = MC_TRACK_VEC.perp() / 1000.;
1374 u_mctheta = MC_TRACK_LRZVEC.theta();
1375 u_nDigi = MC_DIGI_SIZE;
1376 u_evtNo = _nEvents;
1377 ut0_sta = -1;
1378 ut_t0 = t0_bes;
1379 ut0_sta = t0Sta;
1380 m_tuple6->write(); // unrec...tracks
1381 }
1382
1383 //---Pos and Neg
1384 float dDot = 2;
1385 int flagi = -1, flagj = -1;
1386 HepVector3D ppp1, ppp2;
1387 float pppdDot = 2;
1388 for ( unsigned i = 0; i < tracks.length(); i++ )
1389 {
1390 if ( tracks.length() < 2 ) break;
1391 if ( tracks[i]->charge() > 0 )
1392 {
1393 ppp1 = tracks[i]->p().unit();
1394 for ( unsigned j = 0; j < tracks.length(); j++ )
1395 {
1396 if ( tracks[j]->charge() < 0 )
1397 {
1398 ppp2 = tracks[j]->p().unit();
1399 pppdDot = ppp1.dot( ppp2 );
1400 if ( pppdDot < dDot )
1401 {
1402 flagi = i;
1403 flagj = j;
1404 dDot = pppdDot;
1405 }
1406 }
1407 }
1408 }
1409 }
1410 if ( flagi != -1 && flagj != -1 && dDot < 0 )
1411 {
1412 t5_ptotPos = tracks[flagi]->ptot();
1413 t5_ptotNeg = tracks[flagj]->ptot();
1414 t5_drPos = tracks[flagi]->helix().dr();
1415 t5_drNeg = tracks[flagj]->helix().dr();
1416 t5_dzPos = tracks[flagi]->helix().dz();
1417 t5_dzNeg = tracks[flagj]->helix().dz();
1418 m_tuple5->write();
1419 } // Pos and Neg...back on back
1420
1421 unsigned nGood = 0;
1422 for ( unsigned i = 0; i < tracks.length(); i++ )
1423 {
1424 for ( unsigned k = 0; k < tracks[i]->links().length(); k++ )
1425 {
1426 t4_Dist = tracks[i]->links()[k]->distance(); //_onTrack - _onWire
1427 t4_drift = tracks[i]->links()[k]->drift(); // drift updated in THelixFitter.
1428 t4_dDrift = tracks[i]->links()[k]->dDrift(); // dDrift updated in THelixFitter.
1429 t4_pull = tracks[i]->links()[k]->pull();
1430 t4_LR = 2; // initial
1431 t4_LR = tracks[i]->links()[k]->leftRight();
1432 if ( t4_LR == 0 ) t4_LR = -1;
1433 t4_lyrId = tracks[i]->links()[k]->wire()->layerId();
1434 t4_localId = tracks[i]->links()[k]->wire()->localId();
1435 t4_tdc = tracks[i]->links()[k]->hit()->reccdc()->tdc;
1436 t4_z = tracks[i]->links()[k]->positionOnTrack().z();
1437 t4_bz = tracks[i]->links()[k]->wire()->backwardPosition().z();
1438 t4_fz = tracks[i]->links()[k]->wire()->forwardPosition().z();
1439 t4_fy = tracks[i]->links()[k]->wire()->forwardPosition().y();
1440 t4_nHits = tracks[i]->links().length();
1441 unsigned lyrID = tracks[i]->links()[k]->wire()->layerId();
1442 float phi0 = _cdc->layer( lyrID )->offset();
1443 int nWir = (int)_cdc->layer( lyrID )->nWires();
1444 t4_phi = phi0 + t4_localId * 2 * pi / nWir;
1445 if ( t4_phi < 0 ) t4_phi += 2 * pi;
1446
1447 if ( b_mcHit )
1448 {
1449 SmartDataPtr<Event::MdcMcHitCol> mcMdcMcHitCol( eventSvc(), "/Event/MC/MdcMcHitCol" );
1450 if ( mcMdcMcHitCol )
1451 {
1452 Event::MdcMcHitCol::iterator iter_mchit1 = mcMdcMcHitCol->begin();
1453 digiId = 0;
1454 for ( ; iter_mchit1 != mcMdcMcHitCol->end(); iter_mchit1++, digiId++ )
1455 {
1456 const Identifier ident = ( *iter_mchit1 )->identify();
1457 if ( MdcID::layer( ident ) != t4_lyrId ) continue;
1458 if ( MdcID::wire( ident ) == t4_localId )
1459 {
1460 t4_mcDrift = ( *iter_mchit1 )->getDriftDistance(); // drift in MC.
1461 t4_mcLR = ( *iter_mchit1 )->getPositionFlag();
1462 if ( t4_mcLR == 0 ) t4_mcLR = -1;
1463 break;
1464 }
1465 }
1466 }
1467 }
1468 // cout<<" lyrId, localId: "<<t4_lyrId<<" "<<t4_localId<<endl;
1469 // cout<<" tdc: "<<t4_tdc<<" mcDrift: " << t4_mcDrift<<" Drift: "<<t4_drift<<" t4_Dist:
1470 // "<<t4_Dist<<endl;
1471 m_tuple4->write(); // rec Hits
1472 }
1473
1474 unsigned segSize = tracks[i]->segments().length();
1475 for ( unsigned kk = 0; kk < segSize; ++kk )
1476 {
1477 unsigned segLength = tracks[i]->segments()[kk]->links().length();
1478 AList<TMLink> ll = tracks[i]->segments()[kk]->links();
1479 int nSmall = 0;
1480 for ( unsigned nn = 0; nn < segLength; ++nn )
1481 {
1482 double tmpX = ll[nn]->positionD().x();
1483 double tmpY = ll[nn]->positionD().y();
1484 double tmpA = tracks[i]->segments()[kk]->lineTsf().x();
1485 double tmpB = tracks[i]->segments()[kk]->lineTsf().y();
1486 double tmpC = tracks[i]->segments()[kk]->lineTsf().z();
1487 double dis =
1488 fabs( tmpA * tmpX + tmpB * tmpY + tmpC ) / sqrt( tmpA * tmpA + tmpB * tmpB );
1489 double idealDis = maxdDistance( ll[nn] );
1490 if ( fabs( dis - ll[nn]->cDrift() ) / idealDis < 0.001 && nSmall < 2 )
1491 {
1492 ++nSmall;
1493 continue;
1494 }
1495 t9_times += fabs( dis - ll[nn]->cDrift() ) / idealDis;
1496 }
1497 t9_nSL = ll[0]->wire()->superLayerId();
1498 t9_nLinks = segLength;
1499 t9_mctheta = MC_TRACK_LRZVEC.theta();
1500 t9_times = t9_times / ( t9_nLinks - nSmall );
1501 m_tuple9->write(); // seg info
1502 }
1503
1504 t_mcphi = MC_TRACK_VEC.phi();
1505 t_mctheta = MC_TRACK_LRZVEC.theta();
1506 t_mcptot = MC_TRACK_VEC.mag() / 1000.;
1507 t_mcpt = MC_TRACK_VEC.perp() / 1000.;
1508 t_mcpz = MC_TRACK_LRZVEC.pz() / 1000.;
1509 t_mct0 = MC_EVENT_TIME;
1510 t_nDigi = MC_DIGI_SIZE;
1511
1512 t_dr = tracks[i]->helix().dr();
1513 t_dz = tracks[i]->helix().dz();
1514 t_pt = tracks[i]->pt();
1515 t_ptot = tracks[i]->ptot();
1516 t_tanlmd = tracks[i]->helix().tanl();
1517 t_phi = tracks[i]->helix().phi0();
1518 t_chi2 = tracks[i]->chi2();
1519 t_nHits = tracks[i]->nLinks();
1520 t_nCores = tracks[i]->nCores();
1521 t_nSegs = tracks[i]->segments().length();
1522 t_ndf = tracks[i]->ndf();
1523 t_radius = tracks[i]->radius();
1524 t_evtNo = _nEvents;
1525 t_length = tracks.length();
1526 t_length2 = tracks2D.length();
1527
1528 t_dpt = tracks[i]->pt() - t_mcpt;
1529 t_dptot = tracks[i]->ptot() - t_mcptot;
1530 t_dlmd = atan( tracks[i]->helix().tanl() ) - ( pi / 2 - t_mctheta );
1531 t_dphi = tracks[i]->helix().phi0() - t_mcphi;
1532
1533 t_t0 = t0_bes;
1534 t0_sta = t0Sta;
1535
1536 if ( b_mcPar )
1537 {
1538 if ( b_goodTrk && b_tuple )
1539 {
1540 unsigned mcTrackSize = MC_TRACK_NUM;
1541 unsigned recTrackSize = tracks.length();
1542 const unsigned matchSize = 20;
1543 // if(recTrackSize>40 || mcTrackSize>40) matchSize = 50;
1544
1545 int mLayers[matchSize];
1546 for ( int ii = 0; ii < matchSize; ii++ ) mLayers[ii] = 0;
1547 for ( int jj = 0; jj < 43; ++jj )
1548 {
1549 int tmp[matchSize];
1550 for ( unsigned kk = 0; kk < matchSize; ++kk ) tmp[kk] = 0;
1551 for ( int kk = 0; kk < 288; ++kk )
1552 {
1553 if ( havedigi[jj][kk] < 0 ) continue;
1554 tmp[havedigi[jj][kk]] = 1;
1555 }
1556 for ( int kk = 0; kk < matchSize; ++kk )
1557 if ( tmp[kk] == 1 ) ++mLayers[kk];
1558 }
1559
1560 unsigned trackSize = tracks[i]->nLinks();
1561 int trkIndex[43];
1562 int nLayers[matchSize];
1563 for ( int j = 0; j < 43; ++j ) trkIndex[j] = -99;
1564 for ( int j = 0; j < matchSize; ++j ) nLayers[j] = 0;
1565
1566 for ( int j = 0; j < trackSize; ++j )
1567 {
1568 unsigned lId = tracks[i]->links()[j]->wire()->layerId();
1569 unsigned loId = tracks[i]->links()[j]->wire()->localId();
1570 if ( havedigi[lId][loId] >= 0 ) trkIndex[lId] = havedigi[lId][loId];
1571 }
1572 for ( int j = 0; j < 43; ++j )
1573 if ( trkIndex[j] >= 0 ) ++nLayers[trkIndex[j]];
1574
1575 for ( int j = 0; j < matchSize; ++j )
1576 {
1577 // cout<<"nLayers: "<<nLayers[j]<<" mLayers:"<<mLayers[j]<<endl;
1578 if ( nLayers[j] == 0 ) continue;
1579 if ( (float)nLayers[j] / (float)mLayers[j] > 0.51 )
1580 {
1581 t_gdNLayers = nLayers[j];
1582 t_mcNLayers = mLayers[j];
1583 t_good_theta = MC_TRACK_LRZVEC.theta();
1584 ++nGood;
1585 break;
1586 }
1587 }
1588 if ( t_good_theta == 0. )
1589 {
1590 int tmpLayers = 0;
1591 int tmpi = -1;
1592 for ( int j = 0; j < matchSize; ++j )
1593 {
1594 if ( nLayers[j] == 0 ) continue;
1595 if ( nLayers[j] > tmpLayers )
1596 {
1597 tmpLayers = nLayers[j];
1598 tmpi = j;
1599 }
1600 }
1601 if ( tmpi != -1 )
1602 {
1603 t_bestNLayers = nLayers[tmpi];
1604 t_bestMcNLayers = mLayers[tmpi];
1605 }
1606 else
1607 {
1608 t_bestNLayers = -1;
1609 t_bestMcNLayers = -1;
1610 }
1611 }
1612 else
1613 {
1614 t_bestNLayers = -2;
1615 t_bestMcNLayers = -2;
1616 }
1617 } // if b_goodTrk
1618 }
1619 m_tuple->write(); // rec track
1620 }
1621
1622 t3_mctheta = MC_TRACK_LRZVEC.theta();
1623 t3_mcptot = MC_TRACK_VEC.mag() / 1000.;
1624 t3_mcpt = MC_TRACK_VEC.perp() / 1000.;
1625
1626 t3_nDigi = MC_DIGI_SIZE;
1627 t3_t0 = t0_bes;
1628 t3_t0Sta = t0Sta;
1629 t3_goodLength = nGood;
1630 t3_length = tracks.length();
1631 t3_finalLength = num_par;
1632 m_tuple31->write(); // raw...
1633
1634 for ( unsigned i = 0; i < tracks2D.length(); i++ )
1635 {
1636 t2_mctheta = MC_TRACK_LRZVEC.theta();
1637 t2_mcpt = MC_TRACK_VEC.perp() / 1000.;
1638
1639 t2_nDigi = MC_DIGI_SIZE;
1640 t2_nHits = tracks2D[i]->nLinks();
1641 t2_nSegs = tracks2D[i]->segments().length();
1642 t2_chi2 = tracks2D[i]->chi2();
1643 t2_ndf = tracks2D[i]->ndf();
1644 t2_radius = tracks2D[i]->radius();
1645 t2_evtNo = _nEvents;
1646 t2_length = tracks.length();
1647 t2_length2 = tracks2D.length();
1648 m_tuple2->write(); // unused 2D tracks
1649 }
1650}
1651
1652double TrkReco::maxdDistance( TMLink* l ) const {
1653 unsigned sl = l->wire()->superLayerId();
1654 unsigned lId = l->wire()->layerId();
1655 double _averR[11] = { 9.7, 14.5, 22.14, 28.62, 35.1, 42.39,
1656 48.87, 55.35, 61.83, 69.12, 74.79 };
1657 double _averR2[43] = {
1658 7.885, 9.07, 10.29, 11.525, 12.72, 13.875, 15.01, 16.16, 19.7, 21.3, 22.955,
1659 24.555, 26.215, 27.82, 29.465, 31.06, 32.69, 34.265, 35.875, 37.455, 39.975, 41.52,
1660 43.12, 44.76, 46.415, 48.02, 49.685, 51.37, 53.035, 54.595, 56.215, 57.855, 59.475,
1661 60.995, 62.565, 64.165, 66.68, 68.285, 69.915, 71.57, 73.21, 74.76, 76.345 };
1662 double radius = _averR2[lId];
1663 const double singleSigma = l->dDrift();
1664 return 2 * singleSigma / ( radius * radius );
1665}
1666
1667/*void
1668 TrkReco::dump(const std::string & msg, const std::string & pre) const {
1669 bool def = (msg == "") ? true : false;
1670
1671 if (msg.find("summary") != -1 || msg.find("detail") != -1) {
1672 std::cout << "TrkReco Summary (" << version() << ")" << std::endl;
1673 std::cout << " Track Manager Summary" << std::endl;
1674 _trackManager.dump("summary", " ");
1675 if (_confFinder) {
1676 std::cout << " Conformal Finder Summary" << std::endl;
1677 _confFinder->dump("summary", " ");
1678 }
1679 }
1680 if (def || msg.find("parameter") != std::string::npos || msg.find("detail") !=
1681std::string::npos) { std::string t0 = pre; std::string t1 = pre + " "; std::string t2 = pre
1682+ " ";
1683
1684 std::cout << t0 << name() << "(" << version() << ")";
1685 std::cout << " : debug level = " << b_debugLevel << std::endl;
1686 if (b_doPerfectFinder != 0) {
1687 std::cout << t1 << "Perfect finder is active. ";
1688 std::cout << "Other finders will not called." << std::endl;
1689 }
1690 if (b_conformalFinder == 1) {
1691 std::cout << t1 << "New TrkReco(new conf. finder) is active.";
1692 std::cout << std::endl;
1693 }
1694
1695 std::cout << t1 << _cdc->name() << "(" << _cdc->version() << ")"
1696 << std::endl;
1697 std::cout << t2 << "cdc version : " << _cdc->cdcVersion()
1698 << std::endl;
1699 std::cout << t2 << "fudge factor : " << _cdc->fudgeFactor()
1700 << std::endl;
1701
1702// if (_cdccat)
1703// std::cout << t1 << _cdccat->name() << "("
1704// << _cdccat->version() << ")" << std::endl;
1705
1706std::cout << t1 << "ignore hit quality : " << b_useAllHits
1707<< std::endl;
1708std::cout << t1 << "do T0 reset : " << b_doT0Reset
1709<< std::endl;
1710std::cout << t1 << " max number of reset : " << b_nT0ResetMax
1711<< std::endl;
1712std::cout << t1 << "MC analysis : " << b_doMCAnalysis
1713<< std::endl;
1714std::cout << t1 << "helix fitter chisq max : "
1715<< b_helixFitterChisqMax << std::endl;
1716std::cout << t1 << "test flag : " << b_test << std::endl;
1717
1718
1719std::cout << t1 << _trackManager.name();
1720std::cout << "(" << _trackManager.version() << ") options"
1721<< std::endl;
1722std::cout << t2 << "T0 determination : " << b_doT0Determination
1723<<std::endl;
1724std::cout << t2 << " # of tracks : " << b_nTracksForT0
1725<< std::endl;
1726std::cout << t2 << "bank sort : " << b_sortMode
1727<< std::endl;
1728std::cout << t2 << "max. momentum allowed : " << b_momentumCut
1729<< " GeV/c";
1730std::cout << std::endl;
1731std::cout << t2 << "salvage : " << b_doSalvage
1732<< std::endl;
1733std::cout << t2 << "salvage level : " << b_salvageLevel
1734<< std::endl;
1735
1736std::cout << t1 << _perfectFinder->name();
1737std::cout << "(" << _perfectFinder->version() << ") options";
1738std::cout << std::endl;
1739std::cout << t2 << "do finding : " << b_doPerfectFinder;
1740std::cout << std::endl;
1741std::cout << t2 << "perfect fitting : " << b_perfectFitting;
1742std::cout << std::endl;
1743
1744std::cout << t1 << _confFinder->name();
1745std::cout << "(" << _confFinder->version() << ") options" << std::endl;
1746std::cout << t2 << "do finding : " << b_doConformalFinder;
1747std::cout << std::endl;
1748if (b_conformalFinder == 1) {
1749 std::cout << t2 << "fast finder : ";
1750 std::cout << b_doConformalFastFinder << std::endl;
1751 std::cout << t2 << "slow finder : ";
1752 std::cout << b_doConformalSlowFinder << std::endl;
1753 std::cout << t2 << "perfect segment find : ";
1754 std::cout << b_conformalPerfectSegmentFinding << std::endl;
1755 std::cout << t2 << "max sigma : ";
1756 std::cout << b_conformalMaxSigma << std::endl;
1757 std::cout << t2 << "min # hits for segment: ";
1758 std::cout << b_conformalMinNLinksForSegment << std::endl;
1759 std::cout << t2 << "min # cores in segment: ";
1760 std::cout << b_conformalMinNCores << std::endl;
1761 std::cout << t2 << "min # segments : ";
1762 std::cout << b_conformalMinNSegments << std::endl;
1763 std::cout << t2 << "salvage level : " << b_salvageLevel
1764 << std::endl;
1765 std::cout << t2 << "salvage load width : ";
1766 std::cout << b_conformalSalvageLoadWidth << std::endl;
1767 std::cout << t2 << "stereo mode : "
1768 << b_conformalStereoMode << std::endl;
1769 std::cout << t2 << "stereo load width : ";
1770 std::cout << b_conformalStereoLoadWidth << std::endl;
1771 std::cout << t2 << "stereo max sigma : ";
1772 std::cout << b_conformalStereoMaxSigma << std::endl;
1773 std::cout << t2 << "stereo segment dist. : ";
1774 std::cout << b_conformalStereoSzSegmentDistance << std::endl;
1775 std::cout << t2 << "stereo link distance : ";
1776 std::cout << b_conformalStereoSzLinkDistance << std::endl;
1777}
1778else {
1779 std::cout << t2 << "Old TrkReco(old conf. finder) is active."
1780 << std::endl;
1781 std::cout << t2 << "do stereo finding : ";
1782 std::cout << b_doConformalFinderStereo;
1783 std::cout << std::endl;
1784 std::cout << t2 << "use cosmic builder : ";
1785 std::cout << b_doConformalFinderCosmic;
1786 std::cout << std::endl;
1787 std::cout << t2 << "max sigma : ";
1788 std::cout << b_conformalMaxSigma <<std::endl;
1789 std::cout << t2 << "fraction : ";
1790 std::cout << b_conformalFraction <<std::endl;
1791 std::cout << t2 << "fitting corrections : ";
1792 std::cout << b_conformalFittingCorrections << std::endl;
1793 std::cout << t2 << "stereo max sigma : ";
1794 std::cout << b_conformalStereoMaxSigma;
1795 std::cout << std::endl;
1796 std::cout << t2 << "stereo z3 : ";
1797 std::cout << b_conformalStereoZ3 <<std::endl;
1798 std::cout << t2 << "stereo z4 : ";
1799 std::cout << b_conformalStereoZ4 <<std::endl;
1800 std::cout << t2 << "stereo chisq 3 : ";
1801 std::cout << b_conformalStereoChisq3;
1802 std::cout << std::endl;
1803 std::cout << t2 << "stereo chisq 4 : ";
1804 std::cout << b_conformalStereoChisq4;
1805 std::cout << std::endl;
1806}
1807std::cout << t1 << _curlFinder->name();
1808std::cout << "(" << _curlFinder->version() << ") options" << std::endl;
1809std::cout << t2 << "do finding : " << b_doCurlFinder
1810<< std::endl;
1811
1812if (_clustFinder) {
1813 std::cout << t1 << _clustFinder->name();
1814 std::cout << "(" << _clustFinder->version() << ") options"
1815 << std::endl;
1816 std::cout << t2 << "do finding : " << b_doClustFinder
1817 << std::endl;
1818 std::cout << t2 << "cathode window : " << b_cathodeWindow
1819 << std::endl;
1820 std::cout << t2 << "systematic correction : "
1821 << b_cathodeSystematics<<std::endl;
1822 std::cout << t2 << "cathode cosmic switch : " << b_cathodeCosmic
1823 << std::endl;
1824}
1825
1826std::cout << t1 << "Patten Matching CurlFinder"
1827<< "(0.2beta) options" << std::endl;
1828std::cout << t2 << "do finding : "
1829<< b_doPMCurlFinder << std::endl;
1830std::cout << t2 << "mode(1=rec, 2=map, 3=plot) : "
1831 << b_pmCurlFinder << std::endl;
1832 std::cout << t2 << "min electrons of svd clusters : "
1833 << min_svd_electrons_in_pmc << std::endl;
1834 std::cout << t1 << "SVD Associator" << "(0.2beta) options"
1835 << std::endl;
1836 std::cout << t2 << "doing : " << b_doSvdAssociator << std::endl;
1837
1838 }
1839if (def || msg.find("tracks") != std::string::npos || msg.find("detail") != std::string::npos)
1840{ _trackManager.dump("eventSummary");
1841}
1842
1843if (msg.find("cathode") != std::string::npos || msg.find("detail") != std::string::npos) {
1844 if (b_doClustFinder && _cdccat) {
1845 _cdccat->dump("hit");
1846 _clustFinder->dump("");
1847 }
1848}
1849}*/
HepGeom::Vector3D< double > HepVector3D
DECLARE_COMPONENT(BesBdkRc)
double pi
const HepPoint3D ORIGIN
Constants.
Definition TMDCUtil.cxx:47
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
float TrkRecoHelixFitterChisqMax
Definition TrkReco.cxx:73
int TrkRecoTest
Definition TrkReco.cxx:72
float TrkRecoHelixFitterChisqMax
Definition TrkReco.cxx:73
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_wirhit > * getMdcRecWirhitCol(void)
static double MdcTime(int timeChannel)
A class to find tracks with the conformal method.
static void conformalTransformationDriftCircle(const HepPoint3D &center, const AList< TMDCWireHit > &hits, AList< TMLink > &links)
A class to find tracks with the conformal method.
unsigned layerId(void) const
returns layer id.
unsigned superLayerId(void) const
returns super layer id.
void fastClear(void)
clears TMDC information.
Definition TMDC.cxx:261
float fudgeFactor(void) const
returns fudge factor for drift time error.
static TMDC * getTMDC(void)
Definition TMDC.cxx:84
int debugLevel(void) const
returns debug level.
A class to represent a track in tracking.
virtual void removeLinks(void)
virtual int DropWorst()
void append(TMLink &)
appends a TMLink.
const AList< TMLink > & links(unsigned mask=0) const
static const AList< TTrackHEP > & list(void)
returns a list of TTrackHEP's.
Definition TTrackHEP.cxx:70
A class to have MC information of TTrack.
void update(void)
updates information.
Definition TTrackMC.cxx:64
bool charge(void) const
returns charge matching.
const AList< TTrack > & tracksFinal(void) const
returns a list of tracks writen to MdcRec_trk.
A class to represent a track in tracking.
A tracking module.
Definition TrkReco.h:46
int b_conformalSalvageLoadWidth
Definition TrkReco.h:166
int b_doSalvage
Definition TrkReco.h:187
float b_conformalStereoZ3
Definition TrkReco.h:177
double selector_replace_dz
Definition TrkReco.h:216
int b_doAssociation
Definition TrkReco.h:192
double range_for_stereo3
Definition TrkReco.h:225
double good_distance_for_salvage
Definition TrkReco.h:201
int b_doConformalFastFinder
Definition TrkReco.h:157
double range_for_stereo_last2d_search
Definition TrkReco.h:208
int on_correction
Definition TrkReco.h:233
int b_conformalMinNCores
Definition TrkReco.h:163
int b_conformalFittingFlag
Definition TrkReco.h:160
double range_for_stereo4
Definition TrkReco.h:226
int b_doConformalFinderStereo
Definition TrkReco.h:174
double MIN_RADIUS_OF_STRANGE_TRACK
Definition TrkReco.h:242
int b_sortMode
Definition TrkReco.h:191
int superlayer_for_stereo_search
Definition TrkReco.h:206
int output_2dtracks
Definition TrkReco.h:234
int b_perfectFitting
Definition TrkReco.h:152
double z_diff_for_last_attend
Definition TrkReco.h:230
int min_salvage
Definition TrkReco.h:199
double range_for_stereo1
Definition TrkReco.h:223
int b_useAllHits
Definition TrkReco.h:144
int stereo_2dfind
Definition TrkReco.h:217
float b_conformalStereoSzLinkDistance
Definition TrkReco.h:171
int b_conformalFittingCorrections
Definition TrkReco.h:181
int b_doT0Reset
Definition TrkReco.h:145
float b_helixFitterChisqMax
Definition TrkReco.h:148
double range_for_stereo6
Definition TrkReco.h:228
int b_doT0Determination
Definition TrkReco.h:189
bool m_keepUnmatch
Definition TrkReco.h:132
StatusCode execute()
Definition TrkReco.cxx:274
bool m_combineTracking
Definition TrkReco.h:130
int curl_version
Definition TrkReco.h:235
double bad_distance_for_salvage
Definition TrkReco.h:200
int b_conformalMinNLinksForSegment
Definition TrkReco.h:162
std::string _cdcVersion
Definition TrkReco.h:136
double range_for_stereo_search
Definition TrkReco.h:205
float b_conformalStereoZ4
Definition TrkReco.h:178
double trace3d_distance
Definition TrkReco.h:211
double merge_ratio
Definition TrkReco.h:219
float b_salvageLevel
Definition TrkReco.h:165
double range_for_stereo2
Definition TrkReco.h:224
double selector_max_sigma
Definition TrkReco.h:214
double minimum_2DTrackLength
Definition TrkReco.h:239
int useESTime
Definition TrkReco.h:140
double merge_z_diff
Definition TrkReco.h:220
float b_conformalMaxSigma
Definition TrkReco.h:161
StatusCode beginRun()
Definition TrkReco.cxx:258
int m_CalibFlag
Definition TrkReco.h:182
double minimum_closeHitsLength
Definition TrkReco.h:241
float b_conformalStereoChisq3
Definition TrkReco.h:179
double ULTIMATE_MIN_RADIUS_OF_STRANGE_TRACK
Definition TrkReco.h:243
double minimum_seedLength
Definition TrkReco.h:238
int b_doCurlFinder
Definition TrkReco.h:197
double ratio_used_wire
Definition TrkReco.h:222
int min_sequence
Definition TrkReco.h:202
void fastClear(void)
clears TMDC information.
Definition TrkReco.cxx:990
float b_fudgeFactor
Definition TrkReco.h:137
int b_conformalFinder
Definition TrkReco.h:155
int b_conformalStereoMode
Definition TrkReco.h:167
double selector_strange_pz
Definition TrkReco.h:215
TrkReco(const std::string &name, ISvcLocator *pSvcLocator)
returns TrkReco.
Definition TrkReco.cxx:75
int b_tuple
Definition TrkReco.h:126
bool m_dropHot
Definition TrkReco.h:129
int b_conformalMinNSegments
Definition TrkReco.h:164
int min_fullwire
Definition TrkReco.h:203
const AList< TTrack > & tracks(void) const
returns a list of reconstructed tracks.
Definition TrkReco.h:328
void clear(void)
clears all TMDC information.
Definition TrkReco.cxx:977
int b_doMCAnalysis
Definition TrkReco.h:147
int b_goodTrk
Definition TrkReco.h:127
double trace2d_first_distance
Definition TrkReco.h:210
double range_for_stereo5
Definition TrkReco.h:227
int b_mcHit
Definition TrkReco.h:125
int b_doConformalFinder
Definition TrkReco.h:156
float b_cdcVersion
Definition TrkReco.h:135
int b_test
Definition TrkReco.h:194
double mask_distance
Definition TrkReco.h:221
int b_debugLevel
Definition TrkReco.h:143
int b_doPerfectFinder
Definition TrkReco.h:151
double min_svd_electrons
Definition TrkReco.h:232
float b_associateSigma
Definition TrkReco.h:193
int b_mcPar
Definition TrkReco.h:124
int b_nTracksForT0
Definition TrkReco.h:190
int b_conformalStereoLoadWidth
Definition TrkReco.h:168
float b_conformalStereoSzSegmentDistance
Definition TrkReco.h:170
int min_segment
Definition TrkReco.h:198
double minimum_3DTrackLength
Definition TrkReco.h:240
int b_doConformalSlowFinder
Definition TrkReco.h:158
bool m_keepBadTdc
Definition TrkReco.h:131
double trace2d_distance
Definition TrkReco.h:209
float b_conformalFraction
Definition TrkReco.h:176
double b_momentumCut
Definition TrkReco.h:185
int b_nT0ResetMax
Definition TrkReco.h:146
StatusCode initialize()
Definition TrkReco.cxx:93
int b_doMerge
Definition TrkReco.h:188
int b_RungeKuttaCorrection
Definition TrkReco.h:133
int svd_reconstruction
Definition TrkReco.h:231
double range_for_axial_last2d_search
Definition TrkReco.h:207
int b_timeTest
Definition TrkReco.h:128
float b_conformalStereoMaxSigma
Definition TrkReco.h:169
int b_conformalPerfectSegmentFinding
Definition TrkReco.h:159
double range_for_axial_search
Definition TrkReco.h:204
float b_conformalStereoChisq4
Definition TrkReco.h:180
int b_fittingFlag
Definition TrkReco.h:186
StatusCode finalize()
Definition TrkReco.cxx:240
void disp_stat(const char *)
initializes TrkReco.
Definition TrkReco.cxx:268
double selector_max_impact
Definition TrkReco.h:213
int determine_one_track
Definition TrkReco.h:212
double z_cut
Definition TrkReco.h:229
int merge_exe
Definition TrkReco.h:218
int b_doConformalFinderCosmic
Definition TrkReco.h:175
int t()
Definition t.c:1