BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcTrackList.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: MdcTrackList.cxx,v 1.25 2017/02/22 05:53:33 zhangy Exp $
4//
5// Environment:
6// Software developed for the BaBar Detector at the SLAC B-Factory.
7//
8// Author(s):
9// Steve Schaffner
10// Zhang Xueyao(zhangxy@hepg.sdu.edu.cn) Migration for BESIII
11// Zhang Yao(zhangyao@ihep.ac.cn)
12//
13//--------------------------------------------------------------------------
14#include "MdcTrkRecon/MdcTrackList.h"
15#include "CLHEP/Alist/AList.h"
16#include "MdcData/MdcHit.h"
17#include "MdcData/MdcHitMap.h"
18#include "MdcData/MdcRecoHitOnTrack.h"
19#include "MdcGeom/BesAngle.h"
20#include "MdcGeom/Constants.h"
21#include "MdcGeom/MdcDetector.h"
22#include "MdcRawEvent/MdcDigi.h"
23#include "MdcTrkRecon/GmsList.h"
24#include "MdcTrkRecon/MdcSeg.h"
25#include "MdcTrkRecon/MdcSegGrouperAx.h"
26#include "MdcTrkRecon/MdcSegGrouperSt.h"
27#include "MdcTrkRecon/MdcSegInfo.h"
28#include "MdcTrkRecon/MdcSegInfoAxialO.h"
29#include "MdcTrkRecon/MdcSegList.h"
30#include "MdcTrkRecon/MdcTrack.h"
31#include "MdcTrkRecon/MdcTrackParams.h"
32#include "MdcTrkRecon/mdcWrapWire.h"
33#include "PatBField/BField.h"
34#include "TrkBase/TrkErrCode.h"
35#include "TrkBase/TrkExchangePar.h"
36#include "TrkBase/TrkFit.h"
37#include "TrkBase/TrkFitStatus.h"
38#include "TrkBase/TrkHitOnTrk.h"
39#include "TrkBase/TrkHotList.h"
40#include "TrkBase/TrkRecoTrk.h"
41#include "TrkFitter/TrkCircleMaker.h"
42#include "TrkFitter/TrkHelixMaker.h"
43#include <iostream>
44#include <math.h>
45
46// yzhang hist cut
47#include "AIDA/IHistogram1D.h"
48#include "GaudiKernel/NTuple.h"
49#include "Rtypes.h"
50extern int haveDigiTk[43][288];
51extern double haveDigiDrift[43][288];
52extern AIDA::IHistogram1D* g_cirTkChi2;
53extern AIDA::IHistogram1D* g_3dTkChi2;
54extern AIDA::IHistogram1D* g_fitNAct;
55extern AIDA::IHistogram1D* g_pickHitWire;
56// extern AIDA::IHistogram2D* g_predDriftVsMcTk;
57extern NTuple::Tuple* m_tuplePick;
58extern NTuple::Item<long> m_pickIs2D;
59extern NTuple::Item<long> m_pickLayer;
60extern NTuple::Item<long> m_pickNCell;
61extern NTuple::Item<long> m_pickNCellWithDigi;
62extern NTuple::Array<long> m_pickWire;
63extern NTuple::Array<double> m_pickPredDrift;
64extern NTuple::Array<double> m_pickDrift;
65extern NTuple::Array<double> m_pickDriftTruth;
66extern NTuple::Array<int> m_pickPhizOk;
67extern NTuple::Array<double> m_pickZ;
68extern NTuple::Array<double> m_pickResid;
69extern NTuple::Array<double> m_pickSigma;
70extern NTuple::Array<double> m_pickPhiLowCut;
71extern NTuple::Array<double> m_pickPhiHighCut;
72extern NTuple::Array<double> m_pickDriftCut;
73extern NTuple::Array<long> m_pickMcTk;
74extern NTuple::Array<double> m_pickPt;
75extern NTuple::Array<double> m_pickCurv;
76
77// zhangy hist cut
78
79#ifdef MDCPATREC_TIMETEST
80// tau include
81# include <Profile/Profiler.h>
82# include <pthread.h>
83# include <sys/time.h>
84#endif
85// zhangy hist
87using std::cout;
88using std::endl;
89
90// *************************************************************************
92 // *************************************************************************
93 return;
94}
95
96//------------------------------------------------------------------------
98//------------------------------------------------------------------------
99
100// *************************************************************************
102 const MdcDetector* gm, TrkContext& context,
103 double bunchTime ) {
104 // *************************************************************************
105 // Forms tracks out of list of superlayer segments
106 int nTracks = 0;
107
108 m_debug = tkParam.lPrint; // yzhang debug
109
110 // Create empty list of stereo segs (to save time)
111 MdcSegGrouperSt stereoSegs( gm, tkParam.lPrint );
112 stereoSegs.setNoInner( m_noInner ); // yzhang add 2016-10-12
113
114 // *** Create r-phi track
115
116 // Create list of axial segments, treated as on tracks from origin
117#ifdef MDCPATREC_TIMETEST
118 TAU_PROFILE_TIMER( timer8, "fill ax seg", "int ()", TAU_DEFAULT );
119 TAU_PROFILE_START( timer8 );
120#endif
121 MdcSegGrouperAx origSegs( gm, tkParam.lPrint );
122 origSegs.fillWithSegs( segs );
123 // std::cout << "Plot segs after ax fillWithSegs " << std::endl;//yzhang debug
124 // segs->plot(0);//yzhang debug
125#ifdef MDCPATREC_TIMETEST
126 TAU_PROFILE_STOP( timer8 );
127#endif
128 MdcSeg* seed;
129 bool goodOnly = true;
130 bool useBad = ( segs->count() < 400 ); // if true, use non-good seeds
131 // bool useBad = false;
132 segs->resetSeed( gm );
133 MdcTrack* trialTrack = 0;
134
135 while ( 1 )
136 {
137 seed = segs->getSeed( 0, goodOnly );
138 if ( seed == 0 && goodOnly && useBad )
139 {
140 segs->resetSeed( gm );
141 goodOnly = false;
142 continue;
143 }
144 else if ( seed == 0 && ( !goodOnly || !useBad ) ) { break; }
145
146 if ( 3 == m_debug ) dumpSeed( seed, goodOnly ); // yzhang debug
147
148 // Pass through first superlayer of MDC required, Field layer No5 = 12.135 cm
149 if ( fabs( ( (MdcSegInfoAxialO*)seed->info() )->curv() ) > 0.0417 )
150 continue; // curv cut yzhang
151 delete trialTrack;
152 trialTrack = 0;
153
154 //---------Combine Ax segs--------
155#ifdef MDCPATREC_TIMETEST
156 TAU_PROFILE_TIMER( timer3, "combine ax seg", "int ()", TAU_DEFAULT );
157 TAU_PROFILE_START( timer3 );
158#endif
159 int success =
160 origSegs.combineSegs( trialTrack, seed, context, bunchTime, tkParam.maxSegChisqO );
161#ifdef MDCPATREC_TIMETEST
162 TAU_PROFILE_STOP( timer3 );
163#endif
164
165 if ( 3 <= m_debug )
166 {
167 cout << " ***** Ax.combineSegs success? " << success << "\n";
168 dumpAxCombine( trialTrack ); // yzhang debug
169 }
170 if ( !success ) continue;
171
172 //--------Finish circle--------
173#ifdef MDCPATREC_TIMETEST
174 TAU_PROFILE_TIMER( timer4, "circle fitting", "int ()", TAU_DEFAULT );
175 TAU_PROFILE_START( timer4 );
176#endif
177 success = finishCircle( *trialTrack, map, gm );
178#ifdef MDCPATREC_TIMETEST
179 TAU_PROFILE_STOP( timer4 );
180#endif
181
182 if ( 3 <= m_debug )
183 {
184 cout << "finishCircle success? " << success << "\n";
185 dumpCircle( trialTrack ); // yzhang debug
186 }
187
188 if ( !success ) continue;
189 //--------Make sure it really did come from origin--------
190 const TrkFit* tkFit = trialTrack->track().fitResult();
191 assert( tkFit != 0 );
192 TrkExchangePar par = tkFit->helix( 0.0 );
193 // dumpD0(par);
194
195 //------------------d0 cut-------------------
196 // 2010-03-31 , m_d0Cut from 0 to epsilon
197
198 // std::cout<< __FILE__ <<" d0 cut------------"<< fabs(par.d0())<<" d0cut "<< m_d0Cut <<
199 // std::endl;
200 if ( ( m_d0Cut > Constants::epsilon ) && ( fabs( par.d0() ) > m_d0Cut ) )
201 {
202 if ( tkParam.lPrint > 1 )
203 cout << __FILE__ << " Killing track by d0:" << par.d0() << ">" << m_d0Cut << endl;
204 continue;
205 }
206
207 //------------------pt cut-------------------
208 if ( ( fabs( m_ptCut ) > 0. ) && ( fabs( tkFit->pt( 0. ) ) < m_ptCut ) )
209 {
210 if ( tkParam.lPrint > 1 )
211 cout << __FILE__ << " Killing track by pt:" << tkFit->pt( 0. ) << "<" << m_ptCut
212 << endl;
213 continue;
214 }
215
216 // *** End r-phi track-finding
217 if ( 3 <= m_debug ) std::cout << " *** End r-phi track-finding " << std::endl;
218
219 //--------Add stereo to taste--------
220#ifdef MDCPATREC_TIMETEST
221 TAU_PROFILE_TIMER( timer5, "fill st seg", "int ()", TAU_DEFAULT );
222 TAU_PROFILE_START( timer5 );
223#endif
224 stereoSegs.fillWithSegs( segs, trialTrack );
225#ifdef MDCPATREC_TIMETEST
226 TAU_PROFILE_STOP( timer5 );
227#endif
228 if ( 3 <= m_debug )
229 {
230 // dumpStFill();//yzhang debug
231 std::cout << std::endl << "----------------------------------------" << std::endl;
232 std::cout << " Segment list after St.fillWithSegs " << std::endl;
233 stereoSegs.dumpSegList();
234 }
235
236#ifdef MDCPATREC_TIMETEST
237 TAU_PROFILE_TIMER( timer6, "combine st seg", "int ()", TAU_DEFAULT );
238 TAU_PROFILE_START( timer6 );
239#endif
240 success = stereoSegs.combineSegs( trialTrack, 0, context, bunchTime, tkParam.maxSegChisqO,
241 tkParam.combineByFitHits );
242#ifdef MDCPATREC_TIMETEST
243 TAU_PROFILE_STOP( timer6 );
244#endif
245
246 if ( 3 <= m_debug )
247 {
248 cout << " ***** St.combineSegs success? " << success << "\n";
249 dumpStCombine( trialTrack );
250 }
251
252 //--------Finish 3-d track--------
253 if ( success )
254 {
255#ifdef MDCPATREC_TIMETEST
256 TAU_PROFILE_TIMER( timer7, "helix fitting", "int ()", TAU_DEFAULT );
257 TAU_PROFILE_START( timer7 );
258#endif
259 success = finishHelix( *trialTrack, map, gm );
260#ifdef MDCPATREC_TIMETEST
261 TAU_PROFILE_STOP( timer7 );
262#endif
263 } // end if (success -- st)
264
265 if ( 3 == m_debug ) { dumpHelix( trialTrack ); }
266 if ( !success ) continue;
267
268 //------------------d0 cut after helix fitting-------------------
269 // yzhang add 2011-08-01
270 double d0par = trialTrack->track().fitResult()->helix( 0. ).d0();
271 if ( ( m_d0Cut > Constants::epsilon ) && ( fabs( d0par ) > m_d0Cut ) )
272 {
273 if ( tkParam.lPrint > 1 )
274 {
275 cout << __FILE__ << " Killing track by d0 after 3d fit:" << d0par << ">" << m_d0Cut
276 << endl;
277 }
278 continue;
279 }
280
281 double z0par = trialTrack->track().fitResult()->helix( 0. ).z0();
282 if ( ( m_z0Cut > Constants::epsilon ) && ( fabs( z0par ) > m_z0Cut ) )
283 {
284 if ( tkParam.lPrint > 1 )
285 { cout << __FILE__ << " Killing track by z0:" << z0par << ">" << m_z0Cut << endl; }
286 continue;
287 }
288
289 nTracks++;
290 append( trialTrack ); // Add to list of Tracks
291
292 trialTrack = 0;
293
294 if ( 3 == m_debug ) std::cout << " ***** End one track-finding *****" << std::endl;
295 } // end while(1)
296
297 delete trialTrack;
298 return nTracks;
299}
300
301/***************************************************************************/
303 bool pickAm ) {
304
305 /***************************************************************************/
306
307 // Selects candidate hits along track;
308 // sorts them into "active" (small residual) and "inactive" (large resid);
309 // throws away hits separated from main group by large gaps. //?? FIXME
310 // pickAm => pick the ambiguity for hits already on track
311 // Return # of active hits found
312
313 bool is2d = trk->track().status()->is2d();
314 if ( 6 == tkParam.lPrint )
315 {
316 cout << "Before pickHits";
317 if ( is2d ) cout << " 2d:";
318 else cout << " 3d:";
319 cout << endl;
320 }
321
322 int nFound = 0;
323 int nCand = 0; // cells tried
324 double rMin, rMax; // min & max search radii for this track
325 double rEnter, rExit; // radii at which track enters, exits layer
326 BesAngle phiEnter, phiExit; // yzhang change
327 int wireLow, wireHigh;
328 double phiLow, phiHigh;
329 int nCell;
330 MdcHit* thisHit;
331 HepAList<MdcHitOnTrack> localHistory; // temporary list of added hits
332 // until bogus hits are chucked
333 double cellWidth;
334 double goodDriftCut; // missing hits with predDrift > goodDriftCut don't count in figuring
335 // gaps
336 double aresid = 0.; // = abs(resid)
337 int firstInputHit = -1; // first hit in firstInputLayer/lastInputLayer region
338 int lCurl = 0; // reached curl point
339
340 //****************************************************/
341 const MdcLayer* firstInputLayer = trk->firstLayer();
342 const MdcLayer* lastInputLayer = trk->lastLayer();
343
344 double bunchTime = trk->track().trackT0();
345 const TrkFit* tkFit = trk->track().fitResult();
346 assert( tkFit != 0 );
347 const TrkFitStatus* tkStatus = trk->track().status();
348 assert( tkStatus != 0 );
349 TrkHitList* hitList = trk->track().hits();
350 assert( hitList != 0 );
351 TrkExchangePar par = tkFit->helix( 0.0 );
352 double d0 = par.d0();
353 double curv = 0.5 * par.omega(); //!!! change to using omega itself
354 double sinPhi0 = sin( par.phi0() );
355 double cosPhi0 = cos( par.phi0() );
356
357 // *** Set min and max radius for track
358 rMin = gm->firstLayer()->rIn();
359 double absd0 = fabs( d0 );
360 if ( absd0 > rMin ) rMin = absd0 + Constants::epsilon;
361
362 bool willCurl = false;
363 double rCurl = fabs( d0 + 1. / curv );
364 rMax = gm->lastLayer()->rOut();
365 // std::cout<< __FILE__ <<" "<< __LINE__<<" rCurl "<< rCurl <<" rMax "<< rMax << std::endl;
366 if ( rCurl < rMax )
367 {
368 willCurl = true;
369 rMax = rCurl - Constants::epsilon;
370 }
371 // std::cout<<" willCurl "<< willCurl << std::endl;
372 bool reachedLastInput = false;
373 bool hasCurled = false; // hit found past curl point
374
375 // yzhang add skip layer with hot, 2011-05-03
376 bool isHotOnLayer[43];
377 if ( tkParam.pickSkipExistLayer )
378 {
379 for ( int ii = 0; ii < 43; ii++ ) isHotOnLayer[ii] = false;
380 for ( TrkHitList::hot_iterator ihit( hitList->begin() ); ihit != hitList->end(); ++ihit )
381 { isHotOnLayer[ihit->layerNumber()] = true; }
382 }
383
384 // *** Loop through layers in view, looking for the hits
385 // assumes axial inner
386 for ( const MdcLayer* layer = gm->firstLayer(); layer != 0;
387 layer =
388 ( ( !lCurl ) ? ( ( hasCurled ) ? gm->prevLayer( layer ) : gm->nextLayer( layer ) )
389 : layer ) )
390 {
391
392 if ( lCurl )
393 {
394 lCurl = 0;
395 hasCurled = true;
396 }
397 if ( tkStatus->is2d() && layer->view() != 0 ) continue;
398
399 if ( tkParam.pickSkipExistLayer && isHotOnLayer[layer->layNum()] )
400 continue; // yzhang add 2011-05-03
401
402 // std::cout<< __FILE__ <<" "<< __LINE__ << " lCurl "<< lCurl
403 //<<" hasCurled "<< hasCurled <<" layer "<< layer->layNum() << std::endl;
404 bool lContinue = true;
405 if ( tkParam.pickUitlLastLayer )
406 { // yzhang change 2010-09-10
407 if ( layer == lastInputLayer ) reachedLastInput = true;
408 }
409
410 // *** Find enter and exit points
411 if ( hasCurled )
412 {
413 rEnter = layer->rOut();
414 if ( rEnter < rMin )
415 {
416 // std::cout<< __FILE__ <<" "<< __LINE__
417 //<<" rEnter<rMin "<<rEnter<<" "<<rMin<< std::endl;
418 break;
419 }
420 rExit = layer->rIn();
421 if ( rExit < rMin ) rExit = rMin;
422 if ( rEnter > rMax ) rEnter = rMax;
423
424 // std::cout<< __FILE__ <<" hasCurled: rEnter "<< rEnter
425 //<<" rExit " << rExit << " rMin "<<rMin<<" rMax "<<rMax<< std::endl;
426 }
427 else
428 {
429 rEnter = layer->rIn();
430 rExit = layer->rOut();
431 // std::cout<< __FILE__ <<" NOT hasCurled: rEnter "<< rEnter
432 //<<" rExit " << rExit << " rMin "<<rMin<<" rMax "<<rMax<< std::endl;
433 if ( rExit < rMin ) continue;
434
435 if ( willCurl )
436 {
437 if ( rEnter > rMax )
438 {
439 // std::cout<< __FILE__<<" Reached curl point before entering layer"<< std::endl;
440 // Reached curl point before entering layer
441 hasCurled = 1;
442 continue;
443 }
444 if ( rExit > rMax )
445 {
446 lCurl = 1;
447 rExit = rMax;
448 }
449 }
450 else
451 { // not a potential curler
452 // std::cout<< __FILE__ <<" "<< __LINE__ <<" not a potential curler"<< std::endl;
453 if ( rEnter > rMax )
454 {
455 // std::cout<< __FILE__ <<" rEnter> rMax "<< rEnter << std::endl;
456 break;
457 }
458 if ( rExit > rMax ) rExit = rMax;
459 }
460 } // end if curled already
461
462 nCell = layer->nWires();
463 cellWidth = Constants::twoPi * layer->rMid() / nCell; //??
464 // don't count outer xmm of cell
465 goodDriftCut = 0.5 * cellWidth * M_SQRT2 + tkParam.pickHitMargin;
466 // goodDriftCut = 0.5 * cellWidth - tkParam.pickHitMargin;//yzhang change 2012-08-17
467 double deltaPhiCellWidth = 0.5 * ( cellWidth * M_SQRT2 ) / layer->rMid();
468
469 //**** Find entrance and exit phi's
470 BesAngle phiTemp( 0.0 );
471 int ierror = trk->projectToR( rEnter, phiTemp, hasCurled );
472 phiEnter = phiTemp.posRad();
473 if ( ierror != 0 )
474 {
475 if ( 6 == tkParam.lPrint )
476 std::cout << " ErrMsg(warning) "
477 << "Error in MdcTrackList::pickHits projection, ierror " << ierror
478 << std::endl;
479 continue; // yzhang 2011-04-14
480 }
481 ierror = trk->projectToR( rExit, phiTemp, hasCurled );
482 phiExit = phiTemp.posRad();
483 if ( ierror != 0 )
484 {
485 if ( 6 == tkParam.lPrint )
486 std::cout << " ErrMsg(warning) "
487 << "Error in MdcTrackList::pickHits projection, ierror " << ierror
488 << std::endl;
489 continue; // yzhang 2011-04-14
490 }
491
492 if ( 6 == tkParam.lPrint )
493 {
494 std::cout << endl << "--pickHit of layer " << layer->layNum() << "--" << std::endl;
495 std::cout << " track phiEnter " << phiEnter.deg() << " phiExit " << phiExit.deg()
496 << " degree" << std::endl;
497 std::cout << " cell width " << 360. / layer->nWires() << " dPhiz "
498 << layer->dPhiz() * Constants::radToDegrees << " deltaPhiCellWidth "
499 << 0.5 * ( cellWidth * M_SQRT2 ) / layer->rMid() * Constants::radToDegrees
500 << std::endl;
501 std::cout << " maxInactiveResid " << tkParam.maxInactiveResid << " pickHitPhiFactor "
502 << tkParam.pickHitPhiFactor << std::endl;
503 std::cout << " goodDriftCut " << goodDriftCut << "=sqrt(2)*0.5*" << cellWidth << "+"
504 << tkParam.pickHitMargin << std::endl;
505 }
506
507 double Bz = trk->track().bField().bFieldZ();
508 // std::cout<< " facotr "<<tkParam.pickHitPhiFactor<< " dPhiz "<<layer->dPhiz()
509 //<< " factor*dPhiz "<<layer->dPhiz()*tkParam.pickHitPhiFactor<< std::endl;
510 double t_phiHit = -999.;
511 if ( curv * Bz <= 0.0 )
512 {
513 // positive track in minus Bz
514 phiLow = phiEnter;
515 phiHigh = phiExit;
516 // Allow some slop in phi
517 phiLow -= tkParam.maxInactiveResid / rEnter;
518 phiHigh += tkParam.maxInactiveResid / rExit;
519 }
520 else
521 {
522 phiLow = phiExit;
523 phiHigh = phiEnter;
524 phiLow -= tkParam.maxInactiveResid / rExit;
525 phiHigh += tkParam.maxInactiveResid / rEnter;
526 }
527 // yzhang fix cross x axis bug 2011-04-10
528 if ( ( phiHigh > 0 && phiLow < 0 ) ) { phiLow += Constants::twoPi; }
529 else if ( ( phiHigh < 0 && phiLow > 0 ) ) { phiHigh += Constants::twoPi; }
530
531 double lowFloat = nCell / Constants::twoPi * ( phiLow - layer->phiOffset() ) + 0.5;
532 double highFloat = nCell / Constants::twoPi * ( phiHigh - layer->phiOffset() ) + 0.5;
533 wireLow = ( lowFloat >= 0.0 ) ? int( lowFloat ) : int( floor( lowFloat ) );
534 wireHigh = ( highFloat >= 0.0 ) ? int( highFloat ) : int( floor( highFloat ) );
535
536 if ( 6 == tkParam.lPrint )
537 {
538 std::cout << " wireLow " << wireLow << " wireHigh " << wireHigh << " phiLow "
539 << phiLow * 180. / Constants::pi << " phiHigh "
540 << phiHigh * 180. / Constants::pi << std::endl;
541 }
542 // *** Loop through the predicted hit wires
543 int tempDiff = 0;
544 if ( g_pickHitWire )
545 {
546 int tempN = Constants::maxCell[layer->layNum()];
547 if ( wireLow > tempN / 2. && wireHigh < tempN / 2. )
548 {
549 g_pickHitWire->fill( wireHigh + tempN - wireLow );
550 tempDiff = wireHigh + tempN - wireLow + 1;
551 }
552 else
553 {
554 g_pickHitWire->fill( wireHigh - wireLow );
555 tempDiff = wireHigh - wireLow + 1;
556 }
557 } // yzhang hist cut
558
559 if ( wireLow > wireHigh ) wireLow -= nCell; // yzhang 2011-05-16
560 long t_iHit = 0;
561 for ( int thisWire = wireLow; thisWire <= wireHigh; thisWire++ )
562 {
563 int corrWire = mdcWrapWire( thisWire, nCell );
564 thisHit = map->hitWire( layer->layNum(), corrWire );
565
566 if ( 6 == tkParam.lPrint )
567 {
568 if ( thisHit != 0 )
569 {
570 cout << endl << "test hit ";
571 thisHit->print( std::cout );
572 }
573 else
574 std::cout << endl
575 << "test hit (" << layer->layNum() << "," << corrWire << ")" << std::endl;
576 }
577
578 double tof = 0.;
579 double z = 0.;
580 double driftDist = 0.;
581 // Calculate expected drift distance
582 double delx, dely;
583 double resid = 0., predDrift = 0.;
584 int ambig = 0;
585 const MdcHitOnTrack* alink = 0;
586 double mcTkId = -9999; // yzhang for tuple 2011-06-28
587 if ( thisHit == 0 )
588 {
589 delx = -d0 * sinPhi0 - layer->xWire( corrWire );
590 dely = d0 * cosPhi0 - layer->yWire( corrWire );
591 predDrift = cosPhi0 * dely - sinPhi0 * delx + curv * ( delx * delx + dely * dely );
592 if ( 6 == tkParam.lPrint ) cout << "No hit. predDrift=" << predDrift << endl;
593 continue;
594 }
595 else
596 {
597 if ( m_tuplePick ) mcTkId = thisHit->digi()->getTrackIndex();
598 // look for existing hit
599 if ( thisHit->getHitOnTrack( &( trk->track() ) ) == 0 )
600 {
601 alink = 0; // yzhang temp
602 }
603 else
604 {
605 alink = thisHit->getHitOnTrack( &( trk->track() ) )->mdcHitOnTrack(); // yzhang temp
606 if ( 6 == tkParam.lPrint ) { cout << " existing hot; "; }
607 }
608
609 if ( alink == 0 || pickAm )
610 {
611 if ( ( !tkStatus->is2d() ) && layer->view() != 0 )
612 {
613 double rc = 9999.;
614 if ( fabs( par.omega() ) > Constants::epsilon ) rc = 1. / fabs( par.omega() );
615 double rw = layer->rMid();
616 double alpha = acos( 1 - rw * rw / ( 2 * rc * rc ) );
617 double fltLen = rw;
618 if ( fabs( 1 - rw * rw / ( 2 * rc * rc ) ) < 1 ) fltLen = rc * alpha;
619 z = par.z0() + fltLen * par.tanDip();
620 tof = fltLen / Constants::c;
621 double x = layer->getWire( corrWire )->xWireDC( z );
622 double y = layer->getWire( corrWire )->yWireDC( z );
623 delx = -d0 * sinPhi0 - x;
624 dely = d0 * cosPhi0 - y;
625 if ( m_tuplePick ) t_phiHit = thisHit->phi( z );
626 }
627 else
628 {
629 delx = -d0 * sinPhi0 - thisHit->x();
630 dely = d0 * cosPhi0 - thisHit->y();
631 if ( m_tuplePick ) t_phiHit = thisHit->phi();
632 }
633 predDrift = cosPhi0 * dely - sinPhi0 * delx + curv * ( delx * delx + dely * dely );
634
635 // predDrift = predDrift * (1. - curv() * predDrift);
636 ambig = ( predDrift >= 0 ) ? 1 : -1;
637 if ( hasCurled ) ambig = -ambig;
638 double entranceAngle = 0.;
639 driftDist = thisHit->driftDist( tof + bunchTime, ambig, entranceAngle, 0., z );
640 if ( alink == 0 )
641 {
642 // FIXME: is this ambig here VVVVV OK for incoming tracks?
643 resid = ambig * fabs( driftDist ) - predDrift;
644 aresid = fabs( resid );
645 // if (aresid > tkParam.maxInactiveResid ) ambig = 0;//yzhang delete 2012-10-09
646 }
647 }
648 else
649 {
650 ambig = alink->ambig();
651 if ( 6 == tkParam.lPrint ) cout << " pick ambig for hot" << endl;
652 if ( m_tuplePick ) t_phiHit = par.phi0() + par.omega() * alink->fltLen();
653 }
654 }
655
656 // yzhang 2012-08-20 , guess phi of this hit on z
657 double zGuess = par.z0() + layer->rMid() * par.tanDip();
658 double phiDCz = layer->getWire( corrWire )->phiDC( zGuess );
659 BesAngle phiDCzMax( phiDCz + deltaPhiCellWidth );
660 BesAngle phiDCzMin( phiDCz - deltaPhiCellWidth );
661
662 if ( m_tuplePick && alink == 0 )
663 {
664 double sigma = 999.;
665 if ( thisHit != 0 && alink == 0 )
666 {
667 double entranceAngle = 0.;
668 sigma = thisHit->sigma( driftDist, ambig, entranceAngle, atan( par.tanDip() ), z );
669 }
670 m_pickPredDrift[t_iHit] = predDrift;
671 m_pickDrift[t_iHit] = driftDist;
672 m_pickDriftTruth[t_iHit] =
673 haveDigiDrift[thisHit->layernumber()][thisHit->wirenumber()];
674 if ( curv * Bz <= 0. )
675 {
676 // positive track under minus Bz
677 if ( ( phiDCzMin - phiExit > 0 ) || ( phiDCzMax - phiEnter < 0 ) )
678 m_pickPhizOk[t_iHit] = 0;
679 else m_pickPhizOk[t_iHit] = 1;
680 }
681 else
682 {
683 if ( ( phiDCzMin - phiEnter > 0 ) || ( phiDCzMax - phiExit < 0 ) )
684 m_pickPhizOk[t_iHit] = 0;
685 else m_pickPhizOk[t_iHit] = 1;
686 }
687 m_pickZ[t_iHit] = z;
688 m_pickWire[t_iHit] = thisHit->wirenumber();
689 m_pickResid[t_iHit] = aresid;
690 if ( abs( sigma ) > 0.000001 ) m_pickSigma[t_iHit] = sigma;
691 else m_pickSigma[t_iHit] = 999.;
692 double t_phiLowCut = -999.;
693 double t_phiHighCut = -999.;
694 if ( t_phiHit > -998. )
695 {
696 t_phiLowCut = ( phiEnter - t_phiHit ) * rEnter;
697 t_phiHighCut = ( phiExit - t_phiHit ) * rExit;
698 }
699 m_pickPhiLowCut[t_iHit] = t_phiLowCut;
700 m_pickPhiHighCut[t_iHit] = t_phiHighCut;
701 m_pickDriftCut[t_iHit] = goodDriftCut;
702 m_pickMcTk[t_iHit] = mcTkId;
703 m_pickPt[t_iHit] = tkFit->pt();
704 m_pickCurv[t_iHit] = curv;
705 t_iHit++;
706 }
707
708 if ( curv * Bz <= 0. )
709 {
710 // positive track
711 if ( ( phiDCzMin - phiExit > 0 ) || ( phiDCzMax - phiEnter < 0 ) )
712 {
713 if ( 6 == tkParam.lPrint )
714 { std::cout << " CUT by phiDCz not in phi En Ex range, curv>=0" << std::endl; }
715 continue;
716 }
717 }
718 else
719 {
720 // negtive track
721 if ( ( phiDCzMin - phiEnter > 0 ) || ( phiDCzMax - phiExit < 0 ) )
722 {
723 if ( 6 == tkParam.lPrint )
724 { std::cout << " CUT by phiDCz not in phi En Ex range, curv<0" << std::endl; }
725 continue;
726 }
727 }
728
729 // Cases
730 // (0) pred drift dist > goodDriftCut, drop Hit
731 if ( ambig != 0 && fabs( predDrift ) > goodDriftCut )
732 { // yzhang add 2012-08-17
733 if ( 6 == tkParam.lPrint )
734 { cout << " predDrift " << predDrift << ">goodDriftCut " << goodDriftCut << endl; }
735 continue;
736 }
737
738 // (1) No good hit, but track near cell-edge => do nothing and continue
739 if ( ambig == 0 && fabs( predDrift ) > goodDriftCut )
740 { // yzhang 2009-11-03 add 3factor, 2011-05-30 from 3 to 2,2012-08-17 from 2 to 1
741 if ( 6 == tkParam.lPrint )
742 {
743 cout << " ambig==0 && |predDirft| " << fabs( predDrift ) << "> goodDriftCut "
744 << goodDriftCut << endl;
745 cout << " No good hit, but track near cell-edge " << endl;
746 }
747 continue;
748 }
749
750 // (2) Hit found:
751 if ( ambig != 0 )
752 {
753 // yzhang changed 2009-10-19
754 // if resid> maxActiveSimga * sigma do not add hits to track
755 double entranceAngle = 0.;
756 double sigma =
757 thisHit->sigma( driftDist, ambig, entranceAngle, atan( par.tanDip() ), z );
758 double factor = tkParam.pickHitFactor;
759 // yzhang delete 2012-10-09
760 // if(!is2d fabs(par.tanDip())<2) factor = (2-par.tanDip())/2 * factor;
761 double residCut = tkParam.maxActiveSigma * factor * sigma; // yzhang 2012-08-21
762 // if(6==tkParam.lPrint){
763 // std::cout<< "aresid "<<aresid<<" residCut "<<residCut<<" sigma "<<sigma <<" tanDip
764 // "<< par.tanDip() <<" factor "<<factor <<" tkParam.maxActiveSigma
765 // "<<tkParam.maxActiveSigma<<std::endl;
766 //}
767
768 if ( alink == 0 && ( aresid <= residCut ) )
769 {
770 if ( 6 == tkParam.lPrint )
771 {
772 cout << " (2) New hit found " << endl; // yzhang debug
773 }
774 // yzhang 2012-08-17 delete
775 int isActive = 1;
776 // if (aresid > residCut) isActive = 0;
777 // if(6==tkParam.lPrint) {
778 // if (aresid > residCut)
779 // std::cout << "notACT, resid "<<aresid<<" >residCut " << residCut<< std::endl;
780 // }
781 MdcRecoHitOnTrack tempHot( *thisHit, ambig, bunchTime );
782 tempHot.setActivity( isActive );
783 // Don't add active hits if they're in use.
784 if ( thisHit->usedHit() )
785 {
786 tempHot.setUsability( false );
787 if ( 6 == tkParam.lPrint )
788 std::cout << " thisHit used, setUsability false " << std::endl;
789 }
790 // very crude starting point for flight length !!!! improve
791 double flt = layer->rMid();
792 if ( hasCurled ) flt = Constants::twoPi * rCurl - layer->rMid();
793 flt += 0.000001 * ( thisHit->x() + thisHit->y() );
794 tempHot.setFltLen( flt );
795 if ( 6 == tkParam.lPrint )
796 {
797 std::cout << " aresid " << aresid << "<=residCut " << residCut << " nSig "
798 << aresid / sigma << " nSigCut " << ( tkParam.maxActiveSigma * factor )
799 << " factor " << factor << " maxActiveSigma " << tkParam.maxActiveSigma
800 << " tanDip " << par.tanDip() << std::endl;
801 std::cout << " Append Hot " << std::endl;
802 }
803 alink = (MdcHitOnTrack*)hitList->appendHot( &tempHot );
804 }
805 else
806 {
807 if ( 6 == tkParam.lPrint )
808 {
809 if ( alink != 0 ) { std::cout << "Exist hot found" << std::endl; }
810 else if ( aresid > residCut )
811 {
812 thisHit->print( std::cout );
813 std::cout << " Drop hit. aresid " << aresid << ">residCut " << residCut
814 << " nSig " << aresid / sigma << " nSigCut "
815 << ( tkParam.maxActiveSigma * factor ) << " factor " << factor
816 << " maxActiveSigma " << tkParam.maxActiveSigma << " tanDip "
817 << par.tanDip() << std::endl;
818 }
819 }
820 }
821 if ( !localHistory.member( const_cast<MdcHitOnTrack*>( alink ) ) )
822 {
823 localHistory.append( const_cast<MdcHitOnTrack*>( alink ) );
824 if ( hasCurled ) trk->setHasCurled();
825 nFound++;
826 if ( 6 == tkParam.lPrint )
827 std::cout << " nFound=" << nFound << " nCand " << nCand << std::endl;
828 if ( layer == firstInputLayer && firstInputHit < 0 ) { firstInputHit = nCand; }
829 }
830 else
831 {
832 if ( 6 == tkParam.lPrint )
833 std::cout << "ErrMsg(warning) "
834 << "would have inserted identical HOT "
835 "twice in history buffer"
836 << std::endl;
837 }
838 }
839
840 // (3) No hit found; if beyond known good region, should we continue?
841 else if ( ambig == 0 && reachedLastInput )
842 {
843 if ( 6 == tkParam.lPrint ) std::cout << "ambig==0 " << std::endl;
844 lContinue = false;
845 int nSuccess = 0;
846 int last = 8;
847 if ( nCand < 8 ) last = nCand;
848 for ( int i = 0; i < last; i++ )
849 {
850 int j = nCand - 1 - i;
851 if ( localHistory[j] != 0 )
852 {
853 // std::cout<< __FILE__ <<" localHistory["<<j<<"]!=0 nSuccess++ "<< std::endl;
854 nSuccess++;
855 }
856 if ( i == 2 && nSuccess >= 2 ) lContinue = true;
857 if ( i == 4 && nSuccess >= 3 ) lContinue = true;
858 if ( i == 7 && nSuccess >= 5 ) lContinue = true;
859 if ( 6 == tkParam.lPrint )
860 cout << i << " (3) No hit found; if beyond known good region "
861 << endl; // yzhang debug
862 if ( lContinue )
863 {
864 if ( 6 == tkParam.lPrint )
865 std::cout << " pickHits break by lContinue. i=" << i << " nSuccess=" << nSuccess
866 << std::endl;
867 break;
868 }
869 }
870
871 if ( 6 == tkParam.lPrint )
872 cout << " (3) No hit found; if beyond known good region " << endl; // yzhang debug
873 // if lContinue == false => there's been a gap, so quit
874 if ( !lContinue )
875 {
876 // std::cout<< __FILE__ <<" "<< __LINE__ <<" break by !lContinue "<< std::endl;
877 break;
878 }
879 localHistory.append( 0 );
880 }
881
882 nCand++;
883 // Update last layer:
884 if ( ambig != 0 && reachedLastInput )
885 {
886 if ( trk->hasCurled() == 0 )
887 {
888 if ( thisHit->layer()->rEnd() > trk->lastLayer()->rEnd() )
889 { trk->setLastLayer( thisHit->layer() ); }
890 }
891 else
892 {
893 if ( thisHit->layer()->rEnd() < trk->lastLayer()->rEnd() )
894 { trk->setLastLayer( thisHit->layer() ); }
895 }
896 }
897
898 } // end loop over hit wires
899 if ( t_iHit > 0 && m_tuplePick )
900 {
901 m_pickNCell = tempDiff;
902 m_pickNCellWithDigi = t_iHit;
903 m_pickLayer = layer->layNum();
904 m_pickIs2D = is2d;
905 m_tuplePick->write();
906 }
907 if ( !lContinue && reachedLastInput )
908 {
909 // std::cout<< __FILE__ <<" break by !lContinue && reachedLastInput "<< std::endl;
910 break;
911 }
912 } // end loop over layers
913
914 // Now look back at hits in early layer and see if there are any to be thrown away there.
915 bool lContinue = true;
916 for ( int ihit = firstInputHit; ihit >= 0; ihit-- )
917 {
918 if ( localHistory[ihit] != 0 )
919 {
920 if ( lContinue )
921 {
922 // Update firstLayer
923 const MdcHitOnTrack* mdcHit = localHistory[ihit]->mdcHitOnTrack();
924 if ( mdcHit != 0 )
925 {
926 if ( mdcHit->layer()->rEnd() < trk->firstLayer()->rEnd() )
927 { trk->setFirstLayer( mdcHit->layer() ); }
928 }
929 continue; // no gap yet
930 }
931 else
932 {
933 // gap found; delete hits
934 if ( 6 == tkParam.lPrint ) { std::cout << " gap found; delete hits. "; }
935 if ( !localHistory[ihit]->isUsable() )
936 {
937 if ( 6 == tkParam.lPrint )
938 {
939 cout << "about to delete hit for unusable HOT:" << endl;
940 localHistory[ihit]->print( std::cout );
941 }
942 hitList->removeHit( localHistory[ihit]->hit() );
943 }
944 if ( 6 == tkParam.lPrint )
945 {
946 cout << " current contents of localHistory: " << localHistory.length() << "hot"
947 << endl;
948 // for (int i=0; i<localHistory.length();++i) {
949 // cout << " hit @ " << localHistory[i]->hit() << "; hot @ " << localHistory[i] <<
950 // endl;
951 // }
952 }
953 nFound--;
954 }
955 }
956 else if ( localHistory[ihit] == 0 )
957 {
958 if ( 6 == tkParam.lPrint ) { cout << " localHistory= 0 " << endl; }
959 int nSuccess = 0;
960 lContinue = false;
961 int last = 8;
962 if ( nCand < 8 ) last = nCand;
963 for ( int i = 0; i < last; i++ )
964 {
965 int j = ihit + 1 + i;
966 if ( localHistory[j] != 0 ) nSuccess++;
967 if ( i == 2 && nSuccess >= 2 ) lContinue = true;
968 if ( i == 4 && nSuccess >= 3 ) lContinue = true;
969 // if (i == 7 && nSuccess >= 5) lContinue = true;
970 if ( lContinue ) break;
971 }
972 }
973 }
974 if ( 6 == tkParam.lPrint )
975 {
976 std::cout << "nFound=" << nFound << " < " << tkParam.pickHitFract * nCand
977 << " pickHitFract? " << tkParam.pickHitFract << "*" << nCand << std::endl;
978 }
979 if ( nFound < tkParam.pickHitFract * nCand )
980 nFound = 0; // yzhang delete 2010-05-10 use pickHitFract=0.
981 if ( 6 == tkParam.lPrint ) { cout << " localHistory= 0 " << endl; }
982
983 if ( 6 == tkParam.lPrint || 3 == tkParam.lPrint )
984 {
985 cout << "After pickHits found " << nFound << " hit(s)" << endl;
986 hitList->hotList().print( std::cout );
987 std::cout << std::endl;
988 }
989
990 return nFound;
991}
992
993//************************************************************************
995 const MdcDetector* gm ) {
996 //***********************************************************************
997 int success = 1;
998
999 TrkRecoTrk& trk = mdcTrk.track();
1000 TrkErrCode fitResult;
1001 TrkHelixMaker helMaker;
1002 const TrkFit* tkFit = trk.fitResult();
1003 assert( tkFit != 0 );
1004 TrkHitList* hitList = trk.hits();
1005 assert( hitList != 0 );
1006 TrkExchangePar par = tkFit->helix( 0.0 );
1007
1008 helMaker.setFlipAndDrop( trk, true, true );
1009 fitResult = hitList->fit();
1010
1011 if ( !fitResult.success() && ( 3 == tkParam.lPrint ) )
1012 {
1013 cout << "Helix fit failure: " << endl;
1014 fitResult.print( cout );
1015 }
1016 helMaker.setFlipAndDrop( trk, false, false );
1017
1018 if ( !fitResult.success() ) return 0;
1019
1020 bool lcurler( fabs( tkFit->helix( 0 ).omega() ) > 3.4 ); // yzhang FIXME, ??
1021 pickHits( &mdcTrk, map, gm, lcurler ); // yzhang add 2010-05-10
1022
1023 if ( 3 == tkParam.lPrint )
1024 std::cout << __FILE__ << " " << __LINE__ << " nHit after pickHit " << hitList->nHit()
1025 << std::endl;
1026 if ( 3 == tkParam.lPrint ) hitList->hotList().printAll( std::cout );
1027 // if(hitList->nHit()<=0) return 0;
1028
1029 helMaker.setFlipAndDrop( trk, true, true );
1030 fitResult = hitList->fit();
1031 if ( fitResult.failure() )
1032 {
1033 if ( 3 == tkParam.lPrint )
1034 {
1035 cout << "Second helix fit failed: " << endl;
1036 fitResult.print( std::cout );
1037 }
1038 return 0;
1039 }
1040 if ( 3 == tkParam.lPrint ) { cout << "Final fit: " << endl << trk << endl; }
1041 helMaker.setFlipAndDrop( trk, false, false );
1042
1043 double chisqperDOF = 0.;
1044 int nACT = tkFit->nActive();
1045 int nDOF = nACT - 5;
1046 if ( nDOF > 5 ) { chisqperDOF = tkFit->chisq() / nDOF; }
1047 else { chisqperDOF = tkFit->chisq(); }
1048 if ( g_3dTkChi2 ) { g_3dTkChi2->fill( chisqperDOF ); } // yzhang hist cut
1049 if ( g_fitNAct ) { g_fitNAct->fill( nACT ); } // yzhang hist cut
1050
1051 int goodMatch = 1;
1052 if ( fitResult.failure() || chisqperDOF > tkParam.maxChisq || nACT < tkParam.minHits )
1053 {
1054 goodMatch = 0;
1055 if ( 3 == tkParam.lPrint )
1056 {
1057 std::cout << " goodMatch=0; chi2/dof " << chisqperDOF << " >?maxChisq"
1058 << tkParam.maxChisq << " nAct:" << nACT << "<?minHits" << tkParam.minHits
1059 << std::endl;
1060 }
1061 }
1062 // yzhang add
1063 ////yzhang FIXME
1064 // if (tkParam.lUseQualCuts) {
1065 // double tem2 = (float) trk.hits()->nHit() - nACT;
1066 // if (tem2 >= tkParam.maxNmissTrack) goodMatch = 0;
1067 // if (tem2 / float(trk.hits()->nHit()) > tkParam.maxNmissNorm)
1068 // goodMatch = 0;
1069 // }
1070 // zhangy add
1071
1072 if ( goodMatch )
1073 {
1074 if ( 3 <= m_debug ) { std::cout << " ***** finishHelix success!" << std::endl; }
1075 trk.fitResult()->positionErr( 0.0 );
1076 }
1077 else
1078 { // Not a good match
1079 success = 0;
1080 if ( 3 <= m_debug ) { std::cout << " ***** finishHelix failure!" << std::endl; }
1081 } // end if goodmatch
1082
1083 return success;
1084}
1085
1086//************************************************************************
1088 const MdcDetector* gm ) {
1089 //************************************************************************
1090 TrkRecoTrk& trk = mdcTrk.track();
1091 if ( 9 == tkParam.lPrint )
1092 {
1093 std::cout << " finishCircle " << std::endl;
1094 trk.print( std::cout );
1095 }
1096
1097 const TrkFit* tkFit = trk.fitResult();
1098 if ( 9 == tkParam.lPrint )
1099 { cout << "Before circle fit, nactive " << tkFit->nActive() << endl; }
1100 assert( tkFit != 0 );
1101 TrkHitList* hitList = trk.hits();
1102 assert( hitList != 0 );
1103 TrkCircleMaker circMaker;
1104 circMaker.setFlipAndDrop( trk, false, false ); // reset as a precaution
1105 // circMaker.setFactor(trk, 1.);//nSigma cut factor//yzhang FIXME 2010-09-13
1106
1107 TrkErrCode fitResult = hitList->fit();
1108 if ( fitResult.failure() )
1109 {
1110 trk.status()->addHistory( TrkErrCode( TrkErrCode::fail, 15, "finishCircle" ),
1111 "MdcTrkRecon" );
1112 if ( tkParam.lPrint > 1 )
1113 {
1114 cout << "First circle fit failed: " << endl;
1115 fitResult.print( std::cout );
1116 }
1117 return 0;
1118 }
1119 trk.status()->addHistory( TrkErrCode( TrkErrCode::succeed, 15, "finishCircle" ),
1120 "MdcTrkRecon" );
1121
1122 if ( 9 == tkParam.lPrint )
1123 { cout << "After circle fit, nactive " << tkFit->nActive() << endl; }
1124 double chisqperDOF;
1125 int nDOF = tkFit->nActive() - 3;
1126 if ( nDOF > 3 ) { chisqperDOF = tkFit->chisq() / nDOF; }
1127 else { chisqperDOF = tkFit->chisq(); }
1128
1129 if ( g_cirTkChi2 ) { g_cirTkChi2->fill( chisqperDOF ); } // yzhang hist cut
1130 int success = ( chisqperDOF <= tkParam.maxChisq && tkFit->nActive() >= 3 );
1131
1132 if ( 9 == tkParam.lPrint )
1133 {
1134 std::cout << __FILE__ << " " << __LINE__ << " success " << success << " chisqperDOF "
1135 << chisqperDOF << "<? maxChisq " << tkParam.maxChisq << " nAct "
1136 << tkFit->nActive() << ">=3 " << std::endl;
1137 mdcTrk.track().hots()->printAll( std::cout );
1138 }
1139 bool lcurler( fabs( tkFit->helix( 0 ).omega() ) > 3.4 ); // yzhang FIXME, ??
1140 pickHits( &mdcTrk, map, gm, lcurler );
1141
1142 if ( 9 == tkParam.lPrint )
1143 {
1144 std::cout << __FILE__ << " " << __LINE__ << " nHit after pickHit " << hitList->nHit()
1145 << std::endl;
1146 }
1147 // if(hitList->nHit()<=0) return 0;
1148
1149 circMaker.setFlipAndDrop( trk, true, true );
1150 fitResult = hitList->fit();
1151 if ( fitResult.failure() )
1152 {
1153 if ( 9 == tkParam.lPrint )
1154 {
1155 cout << "Second circle fit failed: " << endl;
1156 fitResult.print( std::cout );
1157 }
1158 return 0;
1159 }
1160 if ( 9 == tkParam.lPrint ) { cout << "Final fit: " << endl << trk << endl; }
1161 circMaker.setFlipAndDrop( trk, false, false );
1162
1163 nDOF = tkFit->nActive() - 3;
1164 if ( nDOF > 3 ) { chisqperDOF = tkFit->chisq() / nDOF; }
1165 else { chisqperDOF = tkFit->chisq(); }
1166 if ( g_cirTkChi2 ) { g_cirTkChi2->fill( chisqperDOF ); } // yzhang hist cut
1167 success = ( chisqperDOF <= tkParam.maxChisq ) && ( tkFit->nActive() >= 3 );
1168
1169 if ( 9 == tkParam.lPrint )
1170 {
1171 cout << "chisqperDOF " << chisqperDOF << "=?" << tkParam.maxChisq << endl;
1172 cout << "nActive " << tkFit->nActive() << ">= 3" << endl;
1173 }
1174
1175 if ( 9 == tkParam.lPrint ) { trk.printAll( cout ); }
1176
1177 return success;
1178}
1179
1180void MdcTrackList::dumpAxFill( const MdcTrack* trialTrack ) {
1181 std::cout << "ax fill: " << std::endl;
1182 if ( !trialTrack )
1183 {
1184 trialTrack->track().printAll( cout ); // yzhang debug
1185 }
1186}
1187
1188void MdcTrackList::dumpSeed( const MdcSeg* seed, bool goodOnly ) {
1189 std::cout << std::endl << "Dump seed segment goodOnly=" << goodOnly << " ";
1190 seed->plotSegAll();
1191 std::cout << std::endl;
1192}
1193
1194void MdcTrackList::dumpAxCombine( const MdcTrack* trialTrack ) {
1195 if ( NULL == trialTrack ) return;
1196 std::cout << std::endl << "-------------------------------------" << std::endl;
1197 std::cout << "Track and hitList after AxCombine " << std::endl;
1198 trialTrack->track().printAll( cout ); // yzhang debug
1199 TrkHotList::hot_iterator hotIter = trialTrack->track().hits()->hotList().begin();
1200 while ( hotIter != trialTrack->track().hits()->hotList().end() )
1201 {
1202 cout << "(" << ( (MdcHit*)( hotIter->hit() ) )->layernumber() << ","
1203 << ( (MdcHit*)( hotIter->hit() ) )->wirenumber() << ":" << hotIter->isActive()
1204 << ") ";
1205 hotIter++;
1206 }
1207 std::cout << std::endl;
1208 std::cout << "-------------------------------------" << std::endl;
1209}
1210
1211void MdcTrackList::dumpCircle( const MdcTrack* trialTrack ) {
1212 if ( NULL == trialTrack ) return;
1213 if ( !trialTrack->track().fitResult() ) return;
1214 /*
1215 double omega,r,pt;
1216 omega =trialTrack->track().fitResult()->helix(0.0).omega();
1217 if (omega == 0) pt = 0;
1218 else pt = (-1) * 1/(omega * 333.576 );
1219 std::cout<<"in MdcTrackList Circle Pt = "<< pt <<std::endl;//yzhang deubg
1220
1221 if (omega == 0) r=0;
1222 else r = 1/ omega;
1223 std::cout<<"in MdcTrackList Circle R = "<< r <<std::endl;//yzhang deubg
1224 */
1225 std::cout << std::endl << "-------------------------------------" << std::endl;
1226 std::cout << "Track and hitList after finishCircle" << std::endl;
1227 trialTrack->track().printAll( cout );
1228 TrkHotList::hot_iterator hotIter = trialTrack->track().hits()->hotList().begin();
1229 while ( hotIter != trialTrack->track().hits()->hotList().end() )
1230 {
1231 cout << "(" << ( (MdcHit*)( hotIter->hit() ) )->layernumber() << ","
1232 << ( (MdcHit*)( hotIter->hit() ) )->wirenumber() << ":" << hotIter->isActive()
1233 << ") ";
1234 hotIter++;
1235 }
1236 cout << endl;
1237 std::cout << "-------------------------------------" << std::endl;
1238}
1239
1241 // yzhang hist
1242 // m_hd0->fill(par.d0());
1243 // m_d0 = par.d0();
1244 // m_tuple1->write();//yzhang hist
1245 std::cout << std::endl << " Dump d0() " << par.d0() << "\n"; // yzhang debug
1246
1247 // zhangy hist
1248}
1250 std::cout << "Plot segs after st fillWithSegs " << std::endl;
1251 cout << endl;
1252}
1253
1254void MdcTrackList::dumpStCombine( const MdcTrack* trialTrack ) {
1255 std::cout << std::endl << "-------------------------------------" << std::endl;
1256 std::cout << "Track and hitList after StCombine " << std::endl;
1257 if ( trialTrack ) trialTrack->track().printAll( cout );
1258 TrkHotList::hot_iterator hotIter = trialTrack->track().hits()->hotList().begin();
1259 int tmplay = -1;
1260 while ( hotIter != trialTrack->track().hits()->hotList().end() )
1261 {
1262 int layer = ( (MdcHit*)( hotIter->hit() ) )->layernumber();
1263 if ( ( layer % 4 ) == 0 )
1264 {
1265 if ( tmplay != layer ) cout << endl;
1266 }
1267 cout << "(" << layer << "," << ( (MdcHit*)( hotIter->hit() ) )->wirenumber()
1268 << " act:" << hotIter->isActive() << " lr:" << hotIter->ambig() << ") ";
1269 hotIter++;
1270 tmplay = layer;
1271 }
1272 cout << endl;
1273 std::cout << "-------------------------------------" << std::endl;
1274}
1275void MdcTrackList::dumpHelix( const MdcTrack* trialTrack ) {
1276 std::cout << std::endl << "-------------------------------------" << std::endl;
1277 std::cout << "Track and hitList after finishHelix " << std::endl;
1278 trialTrack->track().printAll( cout );
1279 TrkHotList::hot_iterator hotIter = trialTrack->track().hits()->hotList().begin();
1280 int tmplay = -1;
1281 while ( hotIter != trialTrack->track().hits()->hotList().end() )
1282 {
1283 int layer = ( (MdcHit*)( hotIter->hit() ) )->layernumber();
1284 if ( ( layer % 4 ) == 0 )
1285 {
1286 if ( tmplay != layer ) cout << endl;
1287 }
1288 cout << "(" << layer << "," << ( (MdcHit*)( hotIter->hit() ) )->wirenumber() << ":"
1289 << hotIter->isActive() << ") ";
1290 hotIter++;
1291 tmplay = layer;
1292 }
1293 cout << endl;
1294 std::cout << "-------------------------------------" << std::endl;
1295}
1296
1298 double tdr[43];
1299 double tdr_wire[43];
1300 for ( int i = 0; i < 43; i++ ) { tdr[i] = 9999.; }
1301
1302 // make flag
1303 TrkHotList::hot_iterator hotIter = tk->track().hits()->hotList().begin();
1304 while ( hotIter != tk->track().hits()->hotList().end() )
1305 {
1306 MdcHitOnTrack* hot = const_cast<MdcHitOnTrack*>( &( *hotIter->mdcHitOnTrack() ) );
1307
1308 // driftTime(tof,z)
1309 double dt = hot->mdcHit()->driftTime( 0., 0. );
1310 int layer = hot->mdcHit()->layernumber();
1311 int wire = hot->mdcHit()->wirenumber();
1312 if ( dt < tdr[layer] )
1313 {
1314 tdr[layer] = dt;
1315 tdr_wire[layer] = wire;
1316 }
1317 hotIter++;
1318 }
1319
1320 std::cout << " tdr wire ";
1321 for ( int i = 0; i < 43; i++ ) { std::cout << i << " " << tdr[i] << " " << tdr_wire << " "; }
1322 std::cout << " " << std::endl;
1323 // inactive multi hit
1324 hotIter = tk->track().hits()->hotList().begin();
1325 while ( hotIter != tk->track().hits()->hotList().end() )
1326 {
1327 int layer = hotIter->mdcHitOnTrack()->mdcHit()->layernumber();
1328 int wire = hotIter->mdcHitOnTrack()->mdcHit()->wirenumber();
1329 double dt = hotIter->mdcHitOnTrack()->mdcHit()->driftTime( 0., 0. );
1330
1331 if ( ( tdr[layer] < 9998. ) && ( tdr_wire[layer] != wire ) )
1332 {
1333 MdcHitOnTrack* hot = const_cast<MdcHitOnTrack*>( &( *hotIter->mdcHitOnTrack() ) );
1334 hot->setActivity( false );
1335
1336 std::cout << __FILE__ << " inactive " << layer << " " << wire << " dt " << dt
1337 << std::endl;
1338 }
1339 hotIter++;
1340 }
1341}
double alpha
NTuple::Array< long > m_pickIs2D
NTuple::Array< double > m_pickPt
NTuple::Item< long > m_pickLayer
NTuple::Array< long > m_pickMcTk
AIDA::IHistogram1D * g_fitNAct
AIDA::IHistogram1D * g_pickHitWire
NTuple::Item< long > m_pickNCellWithDigi
NTuple::Array< double > m_pickPhiLowCut
int haveDigiTk[43][288]
double haveDigiDrift[43][288]
NTuple::Array< double > m_pickDriftCut
NTuple::Array< double > m_pickCurv
NTuple::Array< double > m_pickDrift
NTuple::Array< double > m_pickResid
NTuple::Array< int > m_pickPhizOk
AIDA::IHistogram1D * g_cirTkChi2
NTuple::Array< double > m_pickSigma
AIDA::IHistogram1D * g_3dTkChi2
NTuple::Array< long > m_pickWire
NTuple::Tuple * m_tuplePick
NTuple::Array< double > m_pickDriftTruth
NTuple::Array< double > m_pickZ
NTuple::Array< double > m_pickPredDrift
NTuple::Item< long > m_pickNCell
NTuple::Array< double > m_pickPhiHighCut
TrkSimpleMaker< TrkCircleRep > TrkCircleMaker
TGraph2DErrors * dt
Definition McCor.cxx:41
virtual const MdcHit * mdcHit() const
const MdcLayer * layer() const
void print(std::ostream &o) const
double driftTime(double tof, double z) const
Definition MdcHit.cxx:142
double sigma(double, int, double, double, double) const
Definition MdcHit.cxx:183
double driftDist(double, int, double, double, double) const
Definition MdcHit.cxx:157
void fillWithSegs(const MdcSegList *inSegs)
void fillWithSegs(const MdcSegList *inSegs, const MdcTrack *axialTrack)
int combineSegs(MdcTrack *&, MdcSeg *seed, TrkContext &, double trackT0, double maxSegChisqO, int combineByFitHits=0)
int count() const
MdcSeg * getSeed(int iview, int goodOnly)
void resetSeed(const MdcDetector *gm)
void plotSegAll() const
Definition MdcSeg.cxx:157
MdcTrackListBase(const MdcTrackParams &tkPar)
int createFromSegs(MdcSegList *segs, const MdcHitMap *, const MdcDetector *, TrkContext &, double bunchTime)
void dumpHelix(const MdcTrack *)
void dumpCircle(const MdcTrack *)
void dropMultiHotInLayer(const MdcTrack *tk)
MdcTrackList(const MdcTrackParams &tkPar)
int finishHelix(MdcTrack &track, const MdcHitMap *, const MdcDetector *)
int pickHits(MdcTrack *, const MdcHitMap *, const MdcDetector *, bool pickAmb=true)
void dumpAxFill(const MdcTrack *)
void dumpD0(const TrkExchangePar &)
void dumpAxCombine(const MdcTrack *)
void dumpSeed(const MdcSeg *seed, bool goodOnly)
int finishCircle(MdcTrack &track, const MdcHitMap *, const MdcDetector *)
void dumpStCombine(const MdcTrack *)
int projectToR(double radius, BesAngle &phiIntersect, int lCurl=0) const
Definition MdcTrack.cxx:64
int getTrackIndex() const
Definition RawData.cxx:38
virtual BesPointErr positionErr(double fltL) const =0
virtual double pt(double fltL=0.) const =0
virtual double chisq() const =0
void print(std::ostream &ostr) const
virtual void addHistory(const TrkErrCode &status, const char *modulename)
virtual int nActive() const =0
virtual TrkExchangePar helix(double fltL) const =0
const TrkHitOnTrk * getHitOnTrack(const TrkRecoTrk *trk) const
TrkErrCode fit()
TrkHitOnTrk * appendHot(const TrkHitOnTrk *theHot)
const TrkHotList & hotList() const
bool removeHit(const TrkFundHit *theHit)
void setActivity(bool turnOn)
void setUsability(int usability)
virtual const MdcHitOnTrack * mdcHitOnTrack() const
virtual int ambig() const
TrkHitOnTrkIter< TrkHotList::const_iterator_traits > hot_iterator
void print(std::ostream &o) const
void printAll(std::ostream &o) const
virtual void print(std::ostream &) const
double trackT0() const
const TrkFit * fitResult() const
virtual void printAll(std::ostream &) const
const TrkFitStatus * status() const
bool setFlipAndDrop(TrkRecoTrk &, bool allowFlips, bool allowDrops) const