BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
MdcSegGrouper.cxx
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: MdcSegGrouper.cxx,v 1.18 2017/02/22 05:53:33 zhangy Exp $
4//
5// Description:
6//
7//
8// Environment:
9// Software developed for the BaBar Detector at the SLAC B-Factory.
10//
11// Authors:
12// Zhang Yao(zhangyao@ihep.ac.cn) Migrate to BESIII
13//
14// Copyright (C) 1996 The Board of Trustees of
15// The Leland Stanford Junior University. All Rights Reserved.
16//------------------------------------------------------------------------
17#include "MdcTrkRecon/MdcSegGrouper.h"
18#include "CLHEP/Alist/AList.h"
19#include "MdcData/MdcHit.h"
20#include "MdcData/MdcHitUse.h"
21#include "MdcGeom/Constants.h"
22#include "MdcGeom/MdcDetector.h"
23#include "MdcTrkRecon/MdcLine.h" //yzhang 2011-05-09
24#include "MdcTrkRecon/MdcSeg.h"
25#include "MdcTrkRecon/MdcSegInfo.h"
26#include "MdcTrkRecon/MdcSegInfoSterO.h" //yzhang 2011-05-09
27#include "MdcTrkRecon/MdcTrack.h"
28#include "MdcTrkRecon/mdcTwoInv.h"
29#include "MdcTrkRecon/mdcTwoVec.h"
30#include "MdcTrkRecon/mdcWrapAng.h"
31#include "PatBField/BField.h" //yzhang 2011-05-09
32#include "TrkBase/TrkExchangePar.h"
33#include "TrkBase/TrkRecoTrk.h"
34#include "TrkBase/TrkRep.h"
35
36// yzhang hist cut
37#include "AIDA/IHistogram1D.h"
38extern AIDA::IHistogram1D* g_maxSegChisqAx;
39extern AIDA::IHistogram1D* g_maxSegChisqSt;
40// yzhang hist cut
42using std::cout;
43using std::endl;
44
45//------------------------------------------------------------------------
47 //------------------------------------------------------------------------
48 delete[] segList;
49 delete[] combList;
50 delete[] currentSeg;
51 delete[] leaveGap;
52 delete[] gapCounter;
53 delete[] firstGood;
54 delete[] firstBad;
55 if ( isValid != 0 )
56 {
57 for ( int i = 0; i < nDeep; i++ ) { delete[] isValid[i]; }
58 delete[] isValid;
59 }
60}
61//------------------------------------------------------------------------
62MdcSegGrouper::MdcSegGrouper( const MdcDetector* gm, int nd, int debug ) {
63 //------------------------------------------------------------------------
64 nDeep = nd;
65 int nsuper = gm->nSuper();
66 segList = new HepAList<MdcSeg>[nsuper];
67 currentSeg = new int[nDeep];
68 leaveGap = new bool[nDeep];
69 gapCounter = new int[nDeep];
71 _gm = gm;
72 firstGood = new int[nDeep];
73 firstBad = new int[nDeep];
74 lTestGroup = false;
75 lTestSingle = false;
76 _debug = debug;
77 _noInner = false;
78}
79
80//------------------------------------------------------------------------
81int MdcSegGrouper::nextGroup( MdcSeg** segGroup, bool printit ) {
82 //------------------------------------------------------------------------
83
84 // Loop over the superlayers, moving to next valid seg for each if necessary
85 // First, loop over the slayers w/o good segs, filling segGroup w/ 0
86 int iply;
87 for ( iply = nPlyFilled; iply < nDeep; iply++ ) { segGroup[iply] = 0; }
88
89restart:
90 if ( printit )
91 cout << endl
92 << "MdcSegGrouper::nextGroup starting group finder, nply = " << nPlyFilled << endl;
93 int nFound = 0;
94 bool incrementNext = true;
95 // int nSegUsed;//yzhang 2010-05-21
96 for ( iply = 0; iply < nPlyFilled; iply++ )
97 {
98 segGroup[iply] = 0;
99 if ( !incrementNext && currentSeg[iply] >= firstGood[iply] )
100 {
101 if ( printit ) std::cout << " reach end of list, break." << iply << std::endl;
102 break;
103 }
104 // if (nSegUsed > segPar.nSegUsedNextGroup) break;
105 if ( leaveGap[iply] )
106 {
107 if ( printit ) std::cout << " leaveGap " << std::endl;
108 // This ply is currently a gap; move on.
109 if ( iply == nPlyFilled - 1 && incrementNext )
110 {
111 // we've exhausted this gap group; start another
112 iply = -1;
114 int lDone = updateGap();
115 if ( lDone )
116 {
117 // all gap groups for nNull exhausted; increment nNull
118 nNull++;
119 if ( nNull > maxNull ) return 0; // All done
120 resetGap( nNull );
121 updateGap();
122 } // end if lDone
123 } // end if exhausted gap group
124 continue;
125 }
126 incrementNext = false;
127
128 // Loop through the segs in this ply until valid one found
129 while ( 1 )
130 {
131 currentSeg[iply]++;
132 if ( currentSeg[iply] == firstBad[iply] )
133 { // reached end of segs
134 incrementNext = true;
135 currentSeg[iply] = firstGood[iply];
136 if ( printit ) { std::cout << "reach end of segs " << std::endl; }
137 if ( iply == nPlyFilled - 1 )
138 {
139 // we've exhausted this gap group; start another
140 iply = -1;
142 int lDone = updateGap();
143 if ( lDone )
144 {
145 // all gap groups for nNull exhausted; increment nNull
146 nNull++;
147 if ( nNull > maxNull )
148 {
149 if ( printit ) { std::cout << endl << " All done! " << std::endl; }
150 return 0; // All done
151 }
152 resetGap( nNull );
153 updateGap();
154 } // end if lDone
155 } // end if exhausted gap group
156 break;
157 } // end reached end of segs
158
159 if ( printit )
160 {
161 std::cout << "ply " << iply << " seg " << currentSeg[iply] << ": ";
162 ( *combList[iply] )[currentSeg[iply]]->plotSeg();
163 if ( ( *combList[iply] )[currentSeg[iply]]->superlayer()->whichView() != 0 )
164 {
165 MdcSegInfoSterO* info =
166 (MdcSegInfoSterO*)( *combList[iply] )[currentSeg[iply]]->info();
167 std::cout << " ct " << info->ct();
168 }
169 }
170
171 // yzhang 09-09-28 delete
172 if ( ( *combList[iply] )[currentSeg[iply]]->segUsed() )
173 {
174 if ( printit )
175 {
176 std::cout << std::endl << " Used??";
177 ( *combList[iply] )[currentSeg[iply]]->plotSeg();
178 }
179 if ( printit ) { std::cout << " segUsed! SKIP " << std::endl; }
180 continue; // yzhang 2010-05-21 add
181 // nSegUsed++;
182 }
183
184 // Test this seg for validity
185 if ( lTestSingle )
186 {
187 assert( isValid != 0 );
188 assert( isValid[iply] != 0 );
189 int invalid = ( isValid[iply][currentSeg[iply]] == false );
190 if ( printit )
191 {
192 if ( invalid ) { std::cout << " invalid " << std::endl; }
193 else { std::cout << " KEEP 1 " << std::endl; }
194 }
195 if ( invalid ) continue;
196 }
197 else
198 {
199 if ( printit ) std::cout << " KEEP 2 " << std::endl;
200 }
201
202 // Whew. We successfully incremented.
203 break;
204
205 } // end seg loop
206 } // end ply loop
207
208 // Fill segGroup with appropriate segs
209 for ( iply = 0; iply < nPlyFilled; iply++ )
210 {
211 if ( leaveGap[iply] ) { segGroup[iply] = 0; }
212 else
213 {
214 segGroup[iply] = ( *combList[iply] )[currentSeg[iply]];
215 if ( lTestGroup && nFound > 1 )
216 {
217 int lBad = incompWithGroup( segGroup, segGroup[iply], iply );
218 if ( printit )
219 {
220 if ( lBad ) std::cout << " incompWithGroup Bad! restart" << std::endl;
221 // else std::cout<<" incompWithGroup Bad! restart" << std::endl;
222 }
223 if ( lBad ) goto restart;
224 }
225 nFound++;
226 }
227 }
228
229 if ( printit ) std::cout << "nextGoup() found " << nFound << " segment(s)" << std::endl;
230 return nFound;
231}
232
233//**************************************************************************
234void MdcSegGrouper::resetGap( int nGap ) {
235 //**************************************************************************
236
237 for ( int i = 0; i < nPlyFilled; i++ ) { gapCounter[i] = nGap - 1 - i; }
238 gapCounter[0]--; // so 1st increment will put 1st counter in right place
239
240 return;
241}
242
243//**************************************************************************
245 //**************************************************************************
246 if ( nNull == 0 ) return 1;
247
248 for ( int i = 0; i < nPlyFilled; i++ ) { leaveGap[i] = false; }
249 for ( int igap = 0; igap < nNull; igap++ )
250 {
251 gapCounter[igap]++;
252 if ( gapCounter[igap] == nPlyFilled - igap )
253 {
254 // End of loop for this counter; look at the other counters to
255 // decide where this one should be reset to.
256 int inext = igap + 1;
257 while ( 1 )
258 {
259 if ( inext >= nNull ) return 1; // done with all combos
260 if ( gapCounter[inext] + inext + 1 < nPlyFilled )
261 {
262 // This is the right spot to reset to
263 gapCounter[igap] = gapCounter[inext] + inext + 1 - igap;
264 break;
265 }
266 inext++;
267 }
268 }
269 else
270 {
271 // We successfully incremented. Quit looping and return.
272 break;
273 }
274 } // end loop over igap
275
276 for ( int j = 0; j < nNull; j++ ) { leaveGap[gapCounter[j]] = true; }
277 return 0;
278}
279//-------------------------------------------------------------------------
281 //-------------------------------------------------------------------------
282 for ( int i = 0; i < nPlyFilled; i++ ) { currentSeg[i] = firstGood[i] - 1; }
283}
284
285//************************************************************************/
286int MdcSegGrouper::combineSegs( MdcTrack*& trk, MdcSeg* seed, TrkContext& context, double t0,
287 double maxSegChisqO, int combineByFitHits ) {
288 //************************************************************************/
289 // forms track from list of segs; does 2-param fit (either r-phi from origin
290 // or s-z) and picks best combination.
291 if ( 3 == _debug )
292 std::cout << std::endl << "=====MdcSegGrouper::combineSegs=====" << std::endl;
293 bool lSeed = ( seed != 0 ); // no seed for stereo group
294
295 int success = 0;
296 double qual;
297 double qualBest = -1000.;
298 int nSegFit = 0;
299 int nSegBest = 0;
300 // int nHitBest = 0;
301 double param[2];
302 double paramBest[2];
303 double chiBest = 9999.;
304 int nToUse = nPly();
305 if ( lSeed ) nToUse++; // seed isn't included in the segs list
306 MdcSeg** segGroup;
307 MdcSeg** segGroupBest;
308 segGroup = new MdcSeg*[nToUse];
309 segGroupBest = new MdcSeg*[nToUse];
310 // static int counter = 0;
311 // counter++;
312 // cout << counter << endl;
313
314 // bool is3d = (seed==NULL);//zhange TEMP test 2011-05-06
315
316 // Loop over all combinations of segs consistent with seed (including gaps)
317 if ( ( 3 == _debug ) && lSeed )
318 {
319 std::cout << "seed segment: ";
320 seed->plotSegAll();
321 std::cout << std::endl;
322 }
323 resetComb( seed );
324
325 // Save seed params (if angles) for later use as reference angle in
326 // mdcWrapAng (don't really have to test whether it's an angle, but I do)
327 double seedAngle[2] = { 0., 0. };
328 if ( lSeed )
329 {
330 if ( seed->info()->parIsAngle( 0 ) ) seedAngle[0] = seed->info()->par( 0 );
331 if ( seed->info()->parIsAngle( 1 ) ) seedAngle[1] = seed->info()->par( 1 );
332 }
333
334 int iprint = ( 3 == _debug );
335 int nInGroup = 0;
336 while ( ( nInGroup = nextGroup( segGroup, iprint ) ) != 0 )
337 {
338
339 if ( lSeed )
340 {
341 segGroup[nToUse - 1] = seed;
342 nInGroup++;
343 }
344 if ( nInGroup < 0 ) continue;
345 if ( !_noInner && nInGroup < 2 ) break;
346 if ( nInGroup < nSegBest ) break;
347
348 if ( 3 == _debug || 11 == _debug )
349 {
350 cout << endl
351 << "-----found a segment group by nextGroup()----- nInGroup " << nInGroup
352 << " nToUse " << nToUse << endl;
353 for ( int ii = 0; ii < nToUse; ii++ )
354 {
355 if ( segGroup[ii] )
356 {
357 segGroup[ii]->plotSegAll();
358 cout << endl;
359 }
360 }
361 // cout << endl <<"--calc. parameters of this segment group"<<endl;
362 }
363
364 double chisq = -999.;
365 nSegFit = 0;
366
367 if ( lSeed )
368 {
369 // 2d
370 chisq = calcParBySegs( segGroup, seedAngle, nToUse, qual, nSegFit, param );
371 }
372 else
373 {
374 if ( combineByFitHits == 0 )
375 { chisq = calcParBySegs( segGroup, seedAngle, nToUse, qual, nSegFit, param ); }
376 else
377 {
378 // 3d
379 const TrkFit* tkFit = trk->track().fitResult();
380 double Bz = trk->track().bField().bFieldZ(); //??
381 TrkExchangePar par = tkFit->helix( 0.0 );
382 // par.print(std::cout);
383 if ( tkFit != 0 )
384 chisq = calcParByHits( segGroup, nToUse, par, qual, nSegFit, param, Bz );
385 // std::cout<< __FILE__ << " " << __LINE__ << " calcParByHits"<<std::endl;
386 if ( chisq <= 0 )
387 {
388 // std::cout<< "calcParByHits failed! calc. by seg" <<std::endl;
389 chisq = calcParBySegs( segGroup, seedAngle, nToUse, qual, nSegFit, param );
390 }
391 }
392 }
393
394 if ( chisq < 0. ) continue; // yzhang add
395 // yzhang 2016-10-12
396 // double chiDof = chisq/(2.*nSegFit - 2.);
397 double chiDof;
398 if ( _noInner ) chiDof = chisq;
399 else chiDof = chisq / ( 2. * nSegFit - 2. );
400
401 if ( g_maxSegChisqAx && lSeed ) { g_maxSegChisqAx->fill( chiDof ); } // yzhang hist cut
402 if ( g_maxSegChisqSt && !lSeed ) { g_maxSegChisqSt->fill( chiDof ); } // yzhang hist cut
403
404 // std::cout<< " chisq " << chisq<< " chi2dof "<<chiDof<<std::endl;
405
406 if ( 3 == _debug || 11 == _debug )
407 {
408 std::cout << setprecision( 2 );
409 if ( _noInner ) std::cout << endl << " no inner chiDof = chisq " << endl;
410 std::cout << endl
411 << "chisq " << chisq << " nSegFit " << nSegFit << " chiDof " << chiDof
412 << std::endl;
413 if ( chiDof > maxSegChisqO )
414 {
415 cout << "***** DROP this group by chiDof " << chiDof
416 << " > maxSegChisqO:" << maxSegChisqO << endl;
417 }
418 else
419 {
420 cout << "***** KEEP this group by chiDof " << chiDof
421 << " <= maxSegChisqO:" << maxSegChisqO << endl;
422 }
423 }
424 // Chisq test
425 if ( chiDof > maxSegChisqO ) continue;
426
427 success = 1;
428 if ( qual > qualBest )
429 {
430 qualBest = qual;
431 nSegBest = nSegFit;
432 // nHitBest = nhit;
433 paramBest[0] = param[0];
434 paramBest[1] = param[1];
435 chiBest = chisq;
436 for ( int i = 0; i < nToUse; i++ ) { segGroupBest[i] = segGroup[i]; }
437 if ( 3 == _debug && 11 == _debug )
438 std::cout << "Keep as best group. param: phi0/z0 " << paramBest[0] << " cpa/ct "
439 << paramBest[1] << std::endl;
440 } // end test on qual
441 }
442
443 if ( success == 1 )
444 {
445 if ( 3 == _debug || 11 == _debug )
446 {
447 std::cout << endl << "-----Parameter best group----- " << std::endl;
448 std::cout << "paramBest " << paramBest[0] << " " << paramBest[1] << " chiBest "
449 << chiBest << std::endl;
450 }
451 // Store the results in a track, possibly creating it in the process
452 trk = storePar( trk, paramBest, chiBest, context, t0 );
453 transferHits( trk, nToUse, segGroupBest ); // Store hits with track
454 }
455
456 std::cout << std::defaultfloat;
457 delete[] segGroupBest;
458 delete[] segGroup;
459 return success;
460}
461
462//************************************************************************
463void MdcSegGrouper::transferHits( MdcTrack* trk, int nSegs, MdcSeg** segGroup ) {
464 //************************************************************************/
465 // Move hits from segments to track hitlist
466 // Also note first and last layers in list
467 // Only handles Mdc segments
468 double smallRad = 1000.;
469 if ( trk->firstLayer() != 0 ) smallRad = trk->firstLayer()->rMid();
470 double bigRad = 0.;
471 if ( trk->lastLayer() != 0 ) bigRad = trk->lastLayer()->rMid();
472
473 // yzhang 2011-05-04
474 // bool maintainAmbiguity = (trk->track().status()->is2d() == 0) ? false: true;
475 // bool maintainAmbiguity = false;
476 // std::cout<< __FILE__ << " " << __LINE__ << " maintainAmbiguity
477 // "<<maintainAmbiguity<<std::endl;
478
479 if ( 3 == _debug )
480 std::cout << endl << "-----transferHits for this segGroup----- " << std::endl;
481 for ( int i = 0; i < nSegs; i++ )
482 {
483 if ( segGroup[i] == 0 ) continue; // skipping this slayer
484 if ( 3 == _debug )
485 {
486 cout << i << " ";
487 segGroup[i]->plotSegAll();
488 cout << endl;
489 }
490 segGroup[i]->setUsed(); // mark seg as used
491 for ( int ihit = 0; ihit < segGroup[i]->nHit(); ihit++ )
492 {
493 MdcHitUse* aHit = segGroup[i]->hit( ihit );
494 const MdcLayer* layer = aHit->mdcHit()->layer();
495 double radius = layer->rMid();
496 if ( radius < smallRad )
497 {
498 smallRad = radius;
499 trk->setFirstLayer( layer );
500 }
501
502 // Assume that segs aren't added to backside of curler
503 if ( radius > bigRad && !trk->hasCurled() )
504 {
505 bigRad = radius;
506 trk->setLastLayer( layer );
507 }
508 // Provide very crude starting guess of flightlength
509 double flt = radius;
510 flt += 0.000001 * ( aHit->mdcHit()->x() + aHit->mdcHit()->y() );
511
512 aHit->setFltLen( flt );
513
514 TrkHitList* theHits = trk->track().hits();
515
516 if ( theHits == 0 ) return;
517
518 // theHits->appendHit(*aHit, maintainAmbiguity);
519 theHits->appendHit( *aHit );
520 // zhangy
521
522 // std::cout<<"in MdcSegGrouper append ok"<<std::endl;//yzhang debug
523 }
524 } // end loop over slayers
525}
526
527//************************************************************************
529 //************************************************************************
530 for ( int islayer = 0; islayer < 11; islayer++ )
531 {
532 for ( int i = 0; i < segList[islayer].length(); i++ )
533 {
534 segList[islayer][i]->plotSegAll();
535 std::cout << std::endl;
536 }
537 }
538}
539
540//************************************************************************
541double MdcSegGrouper::calcParBySegs( MdcSeg** segGroup, double seedAngle[2], int nToUse,
542 double& qual, int& nSegFit, double param[2] ) {
543 //************************************************************************
544 if ( 11 == _debug )
545 std::cout << "-----calculate group param by segment param-----" << std::endl;
546 double wgtmat[3], wgtinv[3];
547 double wgtpar[2];
548 double temvec[2], diff[2];
549 // Calculate track & chisq for this group
550 int nhit = 0;
551 wgtmat[0] = wgtmat[1] = wgtmat[2] = wgtpar[0] = wgtpar[1] = 0.0;
552 temvec[0] = temvec[1] = diff[0] = diff[1] = 0.0;// add initialize 25-05-15
553
554 int iPly;
555 for ( iPly = 0; iPly < nToUse; iPly++ )
556 {
557 if ( 11 == _debug )
558 {
559 // if (!lSeed) //if (segGroup[iPly] == 0) cout << "ply empty: " << iPly << "\n";
560 }
561 if ( segGroup[iPly] == 0 ) continue; // skipping this slayer
562 nSegFit++;
563 MdcSegInfo* segInfo = segGroup[iPly]->info();
564 // Accumulate sums
565 for ( int i = 0; i < 3; i++ ) wgtmat[i] += ( segInfo->inverr() )[i];
566 for ( int k = 0; k < 2; k++ )
567 {
568 param[k] = segInfo->par( k );
569 // zhangy add
570 if ( segInfo->parIsAngle( k ) ) { param[k] = mdcWrapAng( seedAngle[k], param[k] ); }
571 }
572 // Multiply by weight matrix.
573 mdcTwoVec( segInfo->inverr(), param, temvec );
574 wgtpar[0] += temvec[0];
575 wgtpar[1] += temvec[1];
576 if ( 11 == _debug )
577 {
578 std::cout << 0 << ": param " << param[0] << " inverr " << segInfo->inverr()[0]
579 << " par*W " << temvec[0] << std::endl;
580 std::cout << 1 << ": param " << param[1] << " " << 1 / param[1] << " inverr "
581 << segInfo->inverr()[1] << " par*W " << temvec[1] << std::endl;
582 std::cout << " " << std::endl;
583 }
584 nhit += segGroup[iPly]->nHit();
585 }
586
587 // And the fitted parameters are . . .
588 int error = mdcTwoInv( wgtmat, wgtinv );
589 if ( error && ( 11 == _debug ) )
590 {
591 cout << "ErrMsg(warning) "
592 << "failed matrix inversion in MdcTrackList::combineSegs" << endl;
593 // continue;
594 return -999.;
595 }
596 mdcTwoVec( wgtinv, wgtpar, param );
597 if ( 11 == _debug )
598 {
599 std::cout << " param of wgtinv * wgtpar" << std::endl;
600 std::cout << 0 << ": param " << param[0] << std::endl;
601 std::cout << 1 << ": param " << param[1] << " " << 1 / param[1] << std::endl;
602 std::cout << " " << std::endl;
603 }
604
605 // param[0]= 5.312286;
606 // param[1]= -0.006;
607 // std::cout<< "set param " <<param[0]<< " "<<param[1]<<std::endl;
608 if ( 11 == _debug ) cout << endl << "-- Calculate track & chisq for this group " << endl;
609
610 // Calc. chisq. = sum( (Vi - V0) * W * (Vi - V0) )
611 // W = weight, Vi = measurement, V0 = fitted param.
612 double chisq = 0.0;
613 for ( iPly = 0; iPly < nToUse; iPly++ )
614 {
615 if ( segGroup[iPly] == 0 ) continue; // skipping this slayer
616 MdcSegInfo* segInfo = segGroup[iPly]->info();
617 for ( int j = 0; j < 2; j++ )
618 {
619 double temPar;
620 if ( segInfo->parIsAngle( j ) )
621 { temPar = mdcWrapAng( seedAngle[j], segInfo->par( j ) ); }
622 else { temPar = segInfo->par( j ); }
623 if ( 11 == _debug ) { std::cout << " segPar" << j << " " << temPar << std::endl; }
624 diff[j] = temPar - param[j];
625 }
626
627 if ( 11 == _debug )
628 {
629 std::cout << "inverr " << segInfo->inverr()[0] << " " << segInfo->inverr()[1] << " "
630 << segInfo->inverr()[2] << std::endl;
631 std::cout << "errmat " << segInfo->errmat()[0] << " " << segInfo->errmat()[1] << " "
632 << segInfo->errmat()[2] << std::endl;
633 std::cout << "diff " << diff[0] << " " << diff[1] << " temvec " << temvec[0] << " "
634 << temvec[1] << std::endl;
635 std::cout << std::endl;
636 }
637 mdcTwoVec( segInfo->inverr(), diff, temvec );
638
639 chisq += diff[0] * temvec[0] + diff[1] * temvec[1];
640
641 if ( 11 == _debug )
642 {
643 std::cout << iPly << " chi2Add:" << diff[0] * temvec[0] + diff[1] * temvec[1]
644 << " diff0 " << diff[0] << " vec0 " << temvec[0] << " diff1 " << diff[1]
645 << " vec1 " << temvec[1] << std::endl;
646 }
647 }
648
649 // yzhang 2016-10-12
650 double chiDof;
651 if ( _noInner ) chiDof = chisq;
652 else chiDof = chisq / ( 2. * nSegFit - 2. );
653
654 if ( 11 == _debug )
655 {
656 if ( _noInner ) cout << " no inner chiDof = chisq" << endl;
657 cout << "segment:" << endl
658 << " chiDof " << chiDof << " chisq " << chisq << " nhit " << nhit << " phi0/z0 "
659 << param[0] << " cpa/cot " << param[1] << " qual " << ( 2. * nhit - chiDof ) << endl;
660 }
661
662 qual = 2. * nhit - chiDof;
663
664 // if(is3d) std::cout<< __FILE__ << " " << " z0 "<<param[0] << " ct "<<param[0]
665 // <<std::endl;//zhange TEMP test 2011-05-06
666 return chisq;
667}
668
669//************************************************************************
670double MdcSegGrouper::calcParByHits( MdcSeg** segGroup, int nToUse, const TrkExchangePar& par,
671 double& qual, int& nSegFit, double param[2], double Bz ) {
672 //************************************************************************
673 //*** Calc. z and cot(theta) for stereo
674 int debug = false;
675 if ( 11 == _debug ) debug = true;
676 if ( debug ) std::cout << "-----calculate group param by hit-----" << std::endl;
677 MdcLine span( 50 );
678 MdcLine spanFit( 50 );
679
680 int nHit = 0;
681 if ( debug ) std::cout << "nToUse=" << nToUse << std::endl;
682 for ( int iPly = 0; iPly < nToUse; iPly++ )
683 {
684 if ( segGroup[iPly] == 0 ) continue; // skipping this slayer
685 nSegFit++;
686 MdcSegInfoSterO* segInfo = dynamic_cast<MdcSegInfoSterO*>( segGroup[iPly]->info() );
687
688 if ( debug ) std::cout << "nHit in segment=" << segGroup[iPly]->nHit() << std::endl;
689 for ( int ii = 0, iHit = 0; ii < segGroup[iPly]->nHit(); ii++ )
690 {
691
692 if ( debug )
693 std::cout << " calcParByHits (" << segGroup[iPly]->hit( iHit )->mdcHit()->layernumber()
694 << "," << segGroup[iPly]->hit( iHit )->mdcHit()->wirenumber() << ")";
695 // if(segGroup[iPly]->hit(iHit)->mdcHit()->layernumber()<4) continue;//yzhang TEMP TEST
696 // 2011-08-01
697
698 int szCode = segInfo->zPosition( *( segGroup[iPly]->hit( iHit ) ), par, &span, iHit,
699 segGroup[iPly]->bunchTime(), Bz );
700 if ( debug ) std::cout << " szCode " << szCode;
701 if ( szCode > 0 && debug )
702 std::cout << iHit << " s " << span.x[iHit] << " z " << span.y[iHit] << " sigma "
703 << span.sigma[iHit];
704 if ( debug ) std::cout << std::endl;
705
706 spanFit.x[nHit] = span.x[iHit];
707 spanFit.y[nHit] = span.y[iHit];
708 // spanFit.sigma[nHit]=span.sigma[iHit];
709 spanFit.sigma[nHit] = 1.;
710 if ( debug ) std::cout << std::endl;
711 iHit++;
712 if ( szCode > 0 ) nHit++;
713 }
714 }
715
716 if ( debug ) std::cout << __FILE__ << " " << __LINE__ << " nHit " << nHit << std::endl;
717 if ( nHit > 0 ) spanFit.fit( nHit );
718 else return -999;
719
720 param[0] = spanFit.intercept;
721 param[1] = spanFit.slope;
722 if ( debug )
723 std::cout << "nHit " << nHit << " intercept(z0) " << param[0] << " slope(ct) " << param[1]
724 << std::endl;
725
726 qual = 2. * nHit - spanFit.chisq / ( spanFit.nPoint - 2 );
727 if ( debug ) std::cout << "chisq " << spanFit.chisq << " qual " << qual << std::endl;
728
729 return spanFit.chisq;
730}
Double_t x[10]
int iprint
AIDA::IHistogram1D * g_maxSegChisqSt
AIDA::IHistogram1D * g_maxSegChisqAx
int mdcTwoInv(double matrix[3], double invmat[3])
void mdcTwoVec(const double matrix[3], const double invect[2], double outvect[2])
double mdcWrapAng(double phi1, double phi2)
const MdcHit * mdcHit() const
Definition MdcHitUse.cxx:62
int fit(int nUse)
Definition MdcLine.cxx:10
int combineSegs(MdcTrack *&, MdcSeg *seed, TrkContext &, double trackT0, double maxSegChisqO, int combineByFitHits=0)
virtual void resetComb(const MdcSeg *seed)=0
MdcSegGrouper(const MdcDetector *gm, int nDeep, int debug)
void resetGap(int nGap)
virtual ~MdcSegGrouper()
virtual int incompWithGroup(MdcSeg **segGroup, const MdcSeg *testSeg, int iply)=0
int nextGroup(MdcSeg **segGroup, bool printit)
double calcParBySegs(MdcSeg **segGroup, double seedAngle[2], int nToUse, double &qual, int &nSegFit, double param[2])
void transferHits(MdcTrack *track, int nSegs, MdcSeg **segGroup)
double calcParByHits(MdcSeg **segGroup, int nToUse, const TrkExchangePar &par, double &qual, int &nSegFit, double param[2], double Bz)
virtual MdcTrack * storePar(MdcTrack *trk, double parms[2], double chisq, TrkContext &, double trackT0)=0
int zPosition(MdcHitUse &hitUse, const TrkRecoTrk &track, MdcLine *span, int hitFit, double t0) const
virtual bool parIsAngle(int i) const =0
int nHit() const
Definition MdcSeg.cxx:372
void plotSegAll() const
Definition MdcSeg.cxx:157
virtual TrkExchangePar helix(double fltL) const =0
TrkHitOnTrk * appendHit(const TrkHitUse &theHit)
const TrkFit * fitResult() const