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