#include <MdcSegFinder.h>
Public Member Functions | |
int | createSegs (const MdcDetector *gm, MdcSegList &segs, const MdcMap< const MdcHit *, MdcSegUsage * > &usedHits, const MdcHitMap *map, double tbunch) |
int | createSegs (const MdcDetector *gm, MdcSegList &segs, const MdcMap< const MdcHit *, MdcSegUsage * > &usedHits, const MdcHitMap *map, double tbunch) |
MdcSegFinder (int useAllAmbig) | |
MdcSegFinder (int useAllAmbig) | |
MdcSegPatterns * | thePattList () |
MdcSegPatterns * | thePattList () |
~MdcSegFinder () | |
~MdcSegFinder () | |
Private Member Functions | |
MdcSegFinder (const MdcSegFinder &) | |
MdcSegFinder (const MdcSegFinder &) | |
MdcSegFinder & | operator= (const MdcSegFinder &) |
MdcSegFinder & | operator= (const MdcSegFinder &) |
int | tryPatterns (MdcHit *groupHits[8], unsigned groupWord, int nhit, int lPrevHit, int npatt, int *allowedPatt, const MdcSuperLayer *slayer, MdcSegList &segs, const MdcMap< const MdcHit *, MdcSegUsage * > &usedHits, const MdcHitMap *, double bunchTime) |
int | tryPatterns (MdcHit *groupHits[8], unsigned groupWord, int nhit, int lPrevHit, int npatt, int *allowedPatt, const MdcSuperLayer *slayer, MdcSegList &segs, const MdcMap< const MdcHit *, MdcSegUsage * > &usedHits, const MdcHitMap *, double bunchTime) |
Private Attributes | |
bool | _addHits |
MdcSegPatterns | patternList |
|
00047 : 00048 patternList(useAllAmbig) { 00049 //------------------------------------------------------------------------- 00050 00051 } //-------------------------------------------------------------------------
|
|
00040 { };
|
|
|
|
|
|
00040 { };
|
|
|
|
|
|
00056 { 00057 //------------------------------------------------------------------------- 00058 // Forms all possible Segs of hits to act as candidate tracks 00059 // Construct group of 8 hits; translate hit wires into bit-mapped word 00060 // and look up valid patterns (if any) for this group. 00061 00062 _addHits = segs.segPar()->addHits; 00063 int nSegs = 0; 00064 int newSegs; 00065 unsigned int groupWord; 00066 MdcHit *groupHits[8]; 00067 int lPrevHit = 0; // flags that 2nd layer was hit in last group 00068 //which layer/wire to look at for each hit in group 00069 static const int layerWire[8][2] = 00070 { { 0, -1}, { 0, 0}, { 1, 0}, { 2, -1}, 00071 { 2, 0}, { 3, -1}, { 3, 0}, { 3, 1} }; 00072 00073 // Loop through the superlayers 00074 const MdcSuperLayer *slayer = gm->firstSlay(); 00075 while (slayer != 0) { 00076 const MdcLayer *layArray[4]; 00077 int wireIndex[4]; 00078 00079 00080 // layArray[0] = slayer->firstLayer(); 00081 // for (int i = 1; i < 4; i++) layArray[i] = gm->nextLayer(layArray[i-1]); 00082 int nslay = slayer->nLayers(); 00083 for (int i = 0; i < nslay; i++) layArray[i] = slayer->layer(i); 00084 if(nslay != 4) layArray[3] = 0; 00085 00086 00087 // std::cout<<"-------------super layer----- "<<slayer->Id() << " nlayer "<<nslay<<std::endl; 00088 //for (int i = 0; i < nslay; i++) std::cerr<<layArray[i]->Id()<<" "<<layArray[i]->nWires()<<"\n"; 00089 //slayer = slayer->next();continue; 00090 00091 00092 00093 // Loop over cells (index refers to cells in 2nd layer of superlayer) 00094 for (int cellIndex = 0; cellIndex < layArray[1]->nWires(); cellIndex++) { 00095 //yzhang change FIXME 00096 double phi = layArray[1]->getWire(cellIndex)->phiE(); 00097 for(int i = 0; i < 4; i++ ) { 00098 wireIndex[i] = cellIndex; 00099 if ( slayer->slayNum() > 4) continue;//nWires over No.4 slayer is uniform 00100 if ( (slayer->slayNum() > 9) && (i==3) ) break;//stop when get last layer 00101 if ( i == 1 ) continue; 00102 if ( i == 3 ) phi = layArray[2]->getWire(wireIndex[2])->phiE(); 00103 BesAngle tmp(phi - layArray[i]->phiEPOffset()); 00104 int wlow = (int)floor(layArray[i]->nWires() * tmp.rad() / twopi ); 00105 int wbig = (int)ceil(layArray[i]->nWires() * tmp.rad() / twopi ); 00106 if (tmp == 0 ){ 00107 wlow = -1; 00108 wbig = 1; 00109 } 00110 if ( i!=3 ) { 00111 wireIndex[i]=wbig; 00112 }else{ 00113 wireIndex[i]= wlow; 00114 } 00115 //zhangy change 00116 wireIndex[i] = mdcWrapWire(wireIndex[i], layArray[i]->nWires()); 00117 } 00118 // Form group of 8 wires 00119 groupWord = 0u; 00120 unsigned bitWord = 1u; 00121 int nGroup = 0; 00122 for (int ii = 0; ii < 8; ii++) { 00123 groupHits[ii] = 0; 00124 //----------------------------- 00125 if(layArray[ layerWire[ii][0] ] == 0) continue; 00126 //----------------------------- 00127 int laynum = layArray[ layerWire[ii][0] ]->layNum(); 00128 int wire = wireIndex[ layerWire[ii][0] ] + layerWire[ii][1]; 00129 wire = mdcWrapWire(wire, layArray[ layerWire[ii][0] ]->nWires()); //handle wrap-around 00130 MdcHit* thisHit = map->hitWire(laynum, wire); 00131 if (thisHit != 0) { 00132 if ( !usedHits.get(thisHit)->deadHit() ) { 00133 groupHits[ii] = thisHit; 00134 groupWord |= bitWord; 00135 nGroup++; 00136 } else { 00137 // cout << "Skipping hit " << endl; 00138 } 00139 } 00140 // Quit if no hits in 1st 2 layers or 1 hit in 3 layers 00141 if ( (ii == 2 && nGroup < 1) || (ii == 4 && nGroup < 2) ) break; 00142 bitWord <<= 1; 00143 } 00144 if (nGroup < 3) continue; 00145 00146 int lastWire = mdcWrapWire(cellIndex - 1, layArray[0]->nWires()); 00147 if (map->hitWire(layArray[1]->layNum(), lastWire) != 0) lPrevHit = 1; 00148 // if (layArray[1]->hitWire(lastWire) != 0) lPrevHit = 1; 00149 else lPrevHit = 0; 00150 00151 // Try all allowed 4-hit patterns for this group (if any) 00152 int nPatt = patternList.npatt4[groupWord]; 00153 00154 if ((layArray[1]->layNum()==5) && (cellIndex ==46)) { 00155 for(int i=0;i<4;i++){ 00156 //std::cout<<__FILE__<<" "<<__LINE__<<"====("<<layArray[i]->layNum()<<","<< wireIndex[i]<<")" << std::endl; 00157 } 00158 //std::cout<<__FILE__<<" "<<__LINE__<< " groupWord:"<<groupWord<<" nPatt:"<<nPatt<< std::endl; 00159 } 00160 00161 if (nPatt > 0) { 00162 newSegs = tryPatterns(groupHits, groupWord, 4, lPrevHit, nPatt, 00163 patternList.allowedPatt4[groupWord], slayer, segs, usedHits, map, 00164 bunchTime); 00165 nSegs += newSegs; 00166 } 00167 00168 00169 // If unsuccessful, try 3-hit patterns ???? may want to try 2nd pass here 00170 if (!segs.segPar()->find3) continue; 00171 int nUnused = 0; 00172 for (int i = 0; i < 8; i++) { 00173 if (groupHits[i] != 0) { 00174 if (usedHits.get(groupHits[i])->usedSeg() == 0) nUnused++; 00175 } 00176 } 00177 if (nUnused > 0) { 00178 nPatt = patternList.npatt3[groupWord]; 00179 if (nPatt > 0) { 00180 00181 newSegs = tryPatterns(groupHits, groupWord, 3, lPrevHit, nPatt, 00182 patternList.allowedPatt3[groupWord], slayer, segs, usedHits, map, 00183 bunchTime); 00184 nSegs += newSegs; 00185 } 00186 } 00187 } // cellIndex loop 00188 00189 slayer = slayer->next(); 00190 } //superlayer loop 00191 00192 if (nSegs > 0) { 00193 segs.massageSegs(); 00194 segs.resetSeed(gm); 00195 } 00196 00197 nSegs = segs.count(); 00198 00199 if (5 == segs.segPar()->lPrint){ 00200 cout << "Number of Segs found: " << nSegs << "\n"; 00201 } 00202 00203 return nSegs; 00204 }
|
|
|
|
|
|
00043 {return &patternList;}
|
|
00043 {return &patternList;}
|
|
|
|
00211 { 00212 //--------------------------------------------------------------------------- 00213 int nSegs = 0; 00214 int nbit = 8; 00215 00216 unsigned *patterns; 00217 int **ambigPatt; 00218 if (nInPatt == 3) { 00219 patterns = patternList.patt3; 00220 ambigPatt = patternList.ambigPatt3; 00221 } else { 00222 patterns = patternList.patt4; 00223 ambigPatt = patternList.ambigPatt4; 00224 } 00225 00226 MdcSeg *trialSeg = new MdcSeg(t0); // start w/ 1 seg active 00227 00228 // Create temporary array of hit structures for fitting segment 00229 MdcLine span(12); 00230 int spanAmbig[12]; 00231 MdcHit *spanHits[12]; 00232 MdcHit *ahit; 00233 00234 // *** Loop over the allowed pattern for this group 00235 for (int iPatt = 0; iPatt < npatt; iPatt++) { 00236 unsigned thisPat = patterns[ allowedPat[iPatt] ]; 00237 unsigned testWord = thisPat & groupWord; 00238 00239 if (countbits(testWord) < nInPatt) continue; 00240 if (lPrevHit && nInPatt == 3 && (thisPat == 051 || thisPat == 0111)) 00241 continue; 00242 00243 // *** Load the hits into hit structure (radius only at this point) 00244 // radius is rel. to avg. for superlayer; resolution is converted to delphi 00245 unsigned bitadd = 1u; 00246 int nhit = 0; 00247 for (int ibit = 0; ibit < nbit; ibit++) { 00248 // Is this cell in the pattern? 00249 if (bitadd & thisPat) { 00250 //groupHits[ibit]->print(std::cout); 00251 const MdcLayer *layer = groupHits[ibit]->layer(); 00252 if (layer == 0) cout << "huh?" << endl; 00253 span.x[nhit] = layer->rMid() - slay->rad0(); 00254 spanHits[nhit] = groupHits[ibit]; 00255 nhit++; 00256 if (nhit == nInPatt) break; 00257 } 00258 bitadd <<= 1; 00259 } 00260 00261 // *** Loop through all ambiguity combinations; the loop counter also 00262 // serves as a bit-mapped pattern of ambiguities 00263 // Discard combo if all hits have been used w/ this ambig before 00264 00265 //yzhang add temp 00266 MdcSeg& bestTrialSeg = *trialSeg;//segment with min chi2 00267 00268 bool isBest = false; 00269 //zhangy add temp 00270 00271 int namb = 1 << nInPatt; 00272 for (int iamb = 0; iamb < namb; iamb++) { 00273 00274 // Skip all but allowed ambiguity patterns 00275 if (ambigPatt[ allowedPat[iPatt] ][iamb] != 1) continue; 00276 00277 // Convert loop counter into physical ambiguity (0=> -1; 1=>+1) 00278 int nUsed = 0; 00279 int ihit; 00280 for (ihit = 0; ihit < nInPatt; ihit++) { 00281 spanAmbig[ihit] = ( (1u<<ihit) &iamb) ? 1: -1; 00282 nUsed += usedHits.get(spanHits[ihit])->usedAmbig( spanAmbig[ihit] ); 00283 } 00284 if (nUsed >= nInPatt) continue; 00285 00286 // ***Calculate phi for each hit, correcting approx. for angle of track 00287 /* First calculate a correction factor for the drift distance (since 00288 we're treating hits as being at radius of wire). This may slow 00289 things down.*/ 00290 /* corr = 1/cos(theta), where theta = del(d)/del(r), taken over the 00291 span. Use 1/cos = sqrt(1+tan**2) for calculating correction. */ 00292 00293 double rIn = slay->firstLayer()->rMid(); 00294 double rOut = slay->lastLayer()->rMid(); 00295 double phiIn = mdcWrapAng(spanHits[nInPatt-1]->phi(),spanHits[0]->phi()); 00296 double dphidr = ( (spanHits[nInPatt-1]->phi() + spanAmbig[nhit-1] * 00297 spanHits[nInPatt-1]->driftDist(t0,spanAmbig[nhit-1]) / 00298 rOut) - (phiIn+ spanAmbig[0] * spanHits[0]->driftDist(t0,spanAmbig[0]) / rIn)) / (rOut - rIn);//yzhang temp FIXME 00299 00300 //yzhang add temp 00301 //double dphidr = (spanHits[nInPatt-1]->phi() - phiIn) / (rOut - rIn); 00302 //zhangy add temp 00303 00304 double corr = sqrt( 1 + slay->rad0() * slay->rad0() * dphidr * dphidr ); 00305 00306 if(5 == segs.segPar()->lPrint) { 00307 std::cout<<__FILE__<<" "<<__LINE__<< " corr" <<corr<< " phi_n " 00308 <<spanHits[nInPatt-1]->phi()<<" dd_n "<< spanAmbig[nhit-1] * 00309 spanHits[nInPatt-1]->driftDist(t0,spanAmbig[nhit-1]) 00310 <<" phiIn " <<phiIn 00311 <<" dd_in "<< spanAmbig[0] * spanHits[0]->driftDist(t0,spanAmbig[0]) << std::endl; 00312 00313 } 00314 //yzhang add fix phi accross -x axis 00315 bool crossAxis=false; 00316 double yOld = 0; 00317 //zhangy add 00318 double sigmaSum= 0.; 00319 double driftSum= 0.; 00320 double driftHit[12]; 00321 // Actual phi calc 00322 for (ihit = 0; ihit < nInPatt; ihit++) { 00323 ahit = spanHits[ihit]; 00324 double rinv = 1. / ahit->layer()->rMid(); 00325 double drift = ahit->driftDist(t0,spanAmbig[ihit]); 00326 span.y[ihit] = ahit->phi() + spanAmbig[ihit] * 00327 drift * (corr * rinv);//yzhang temp FIXME 00328 00329 if (5 == segs.segPar()->lPrint) { 00330 std::cout<<__FILE__<<" "<<__LINE__<<"("<<ahit->layernumber()<<","<<ahit->wirenumber()<<")"<<" |driftDist| "<< fabs(drift)<< " ambig "<<spanAmbig[ihit]<< " corr "<<corr<<" rinv "<<rinv<<" sigma "<<ahit->sigma(drift,spanAmbig[ihit])<<std::endl; 00331 } 00332 //span.sigma[ihit] = ahit->sigma(fabs(drift), spanAmbig[ihit]); 00333 //yzhang 2010-05-20 , FIXME 00334 span.sigma[ihit] = ahit->sigma(fabs(drift), spanAmbig[ihit]) * (corr * rinv); 00335 00336 //yzhang add temp FIXME 00337 sigmaSum+= span.sigma[ihit]; 00338 driftSum+=drift; 00339 driftHit[ihit]=drift; 00340 //zhangy add temp FIXME 00341 00342 //yzhang add fix phi accross -x axis,set flag 00343 if ( (span.y[ihit]!=0) && (!crossAxis)){ 00344 if ( (yOld / span.y[ihit]) < 0) crossAxis = true; 00345 yOld = span.y[ihit]; 00346 } 00347 //zhangy add 00348 } 00349 00350 //yzhang add temp FIXME 00351 //for (ihit = 0; ihit < nInPatt; ihit++) { 00352 //span.sigma[ihit] = sigmaSum/nInPatt* 00353 //( fabs(driftHit[ihit]-(driftSum/nInPatt))/(driftSum/nInPatt) ); 00354 //} 00355 //zhangy add temp FIXME 00356 00357 //--yzhang add, fix phi accross -x axis , if cross +twopi 00358 if ( crossAxis ){ 00359 for (int ihit=0 ; ihit < nInPatt; ihit++){ 00360 //Approx,for max phi of a cell is 2*pi/40, max cross 4 cell=0.628<0.7 00361 if (abs(span.y[ihit]) < 0.7) break; 00362 if (span.y[ihit] < 0)span.y[ihit]+=twopi; 00363 } 00364 } 00365 //zhangy add 00366 00367 00368 00369 // Fit the segment 00370 for(int ii=0;ii<nInPatt;ii++){ 00371 if (5 == segs.segPar()->lPrint) { 00372 std::cout<<__FILE__<<" "<<__LINE__<<" "<<ii <<" span.x "<<setw(10)<<span.x[ii]<<" y "<<setw(10)<<span.y[ii]<<" sigma "<<setw(10)<<span.sigma[ii]<< std::endl; 00373 } 00374 } 00375 span.fit( nInPatt ); 00376 BesAngle temp = span.intercept; 00377 span.intercept = temp.posRad(); 00378 double t_segchi2 = span.chisq / (nInPatt - 2) ; 00379 00380 00381 if ( g_segChi2) {g_segChi2->fill( t_segchi2 );}//yzhang hist cut 00382 if (4==nInPatt && g_segChi2SlayPat4[slay->slayNum()]) {g_segChi2SlayPat4[slay->slayNum()]->fill( t_segchi2 );}//yzhang hist cut 00383 if (3==nInPatt && g_segChi2SlayPat3[slay->slayNum()]) {g_segChi2SlayPat3[slay->slayNum()]->fill( t_segchi2 );}//yzhang hist cut 00384 if(5 == segs.segPar()->lPrint) { 00385 std::cout<<__FILE__<<" "<<__LINE__<< " pattern "<< thisPat 00386 <<" nHit "<<nInPatt <<" chi2/dof " << t_segchi2 00387 <<" chisq "<<span.chisq <<" maxChisq="<<segs.segPar()->maxChisq <<std::endl; 00388 for(int jj=0; jj<nInPatt; jj++){ 00389 std::cout << "resid["<<jj<<"] "<<span.resid[jj]<<" sigma "<<span.sigma[jj]<<" chisq add "<<span.resid[jj] * span.resid[jj] / (span.sigma[jj] * span.sigma[jj]) << std::endl;//yzhang debug 00390 } 00391 00392 } 00393 if (span.chisq / (nInPatt - 2) > segs.segPar()->maxChisq) { 00394 if (5 == segs.segPar()->lPrint) { 00395 std::cout<<__FILE__<<" "<<__LINE__<<"CUT! chi2/(N-2) " 00396 <<span.chisq / (nInPatt - 2) 00397 <<" > "<< segs.segPar()->maxChisq<< std::endl; 00398 std::cout<<__FILE__<<" "<<__LINE__<<" bestTrialSeg nHit " 00399 << bestTrialSeg.nHit() <<std::endl; 00400 } 00401 continue; 00402 } 00403 int nInSeg = nInPatt; 00404 00405 // *** Pick up adjacent hits and refit 00406 // Recalculate correction factor (optional) 00407 if (segs.segPar()->segRefit) { 00408 dphidr = span.slope; 00409 corr = sqrt( 1 + slay->rad0() * slay->rad0() * dphidr * dphidr ); 00410 crossAxis = false; 00411 for (ihit = 0; ihit < nInSeg; ihit++) { 00412 ahit = spanHits[ihit]; 00413 double rinv = 1. / ahit->layer()->rMid(); 00414 double drift = ahit->driftDist(t0,spanAmbig[ihit]); 00415 span.y[ihit] = ahit->phi() + spanAmbig[ihit] * 00416 drift * (corr * rinv);//yzhang temp FIXME 00417 //yzhang add 00418 //span.y[ihit] = ahit->phi(); 00419 //zhangy add 00420 00421 //yzhang 2010-05-20 , FIXME 00422 //span.sigma[ihit] = ahit->sigma(fabs(drift), spanAmbig[ihit]); 00423 span.sigma[ihit] = ahit->sigma(fabs(drift), spanAmbig[ihit]) * (corr * rinv); 00424 //yzhang add fix phi accross -x axis,set flag 00425 if ( (span.y[ihit]!=0) && (!crossAxis)){ 00426 if ( (yOld / span.y[ihit]) < 0) crossAxis = true; 00427 yOld = span.y[ihit]; 00428 } 00429 //zhangy add 00430 } 00431 //yzhang add, fix phi accross -x axis , if cross +twopi 00432 if ( crossAxis ){ 00433 for (int ihit=0 ; ihit < nInPatt; ihit++){ 00434 //Approx,for max phi of a cell is 2*pi/40, max cross 4 cell=0.628<0.7 00435 if (abs(span.y[ihit]) < 0.7) break; 00436 if (span.y[ihit] < 0)span.y[ihit]+=twopi; 00437 } 00438 } 00439 //zhangy add 00440 span.fit( nInSeg); 00441 BesAngle temp = span.intercept; 00442 span.intercept = temp.posRad(); 00443 } 00444 00445 trialSeg->setValues(nInPatt, nInSeg, spanHits, &span, slay, spanAmbig); 00446 00447 if (_addHits) { 00448 // Look for adjacent hits 00449 nInSeg = trialSeg->addHits(&span, spanHits, map, corr); 00450 } 00451 00452 if (5 == segs.segPar()->lPrint) { 00453 std::cout<<trialSeg->chisq()<<" best chi2 " 00454 <<bestTrialSeg.chisq() << std::endl; 00455 cout << "seg: " << " phi: " << 00456 trialSeg->phi() << " slope: " << trialSeg->slope() << 00457 " nhit: " << trialSeg->nHit() << endl; 00458 //cout << "layer, wire, ambig, used, drift: " << endl; 00459 for (int i = 0; i < trialSeg->nHit(); i++) { 00460 int ambi = trialSeg->hit(i)->ambig(); 00461 const MdcHit* theHit = trialSeg->hit(i)->mdcHit(); 00462 theHit->print(cout); 00463 cout << " ambig " <<ambi; 00464 } 00465 cout << endl; 00466 } 00467 trialSeg->setPattern(iPatt); 00468 trialSeg->markHits(usedHits); 00469 if (nInPatt == 4) trialSeg->setFull(); 00470 00471 //yzhang changed temp 00472 //--keep only one segment for ambig 00473 if(3 == nInPatt){ 00474 segs.append(trialSeg); // Add to list of Segs 00475 nSegs++; 00476 }else{ 00477 if(bestTrialSeg.chisq() < trialSeg->chisq()){ 00478 bestTrialSeg = *trialSeg; 00479 }else{ 00480 isBest = true; 00481 } 00482 } 00483 //--mark best trialSeg 00484 00485 //zhangy add temp 00486 00487 trialSeg = new MdcSeg(t0); 00488 }// end ambiguity loop 00489 00490 00491 //--keep only one segment for ambig 00492 if((4 == nInPatt) && isBest){ 00493 if (5 == segs.segPar()->lPrint) { 00494 std::cout<<" append bestTrialSeg nHit " 00495 << bestTrialSeg.nHit() <<std::endl; 00496 } 00497 00498 segs.append(&bestTrialSeg); // Add to list of Segs 00499 nSegs++; 00500 } 00501 00502 }// end pattern loop 00503 00504 if (5 == segs.segPar()->lPrint) { 00505 std::cout << " Found segs:"<< std::endl; 00506 trialSeg->plotSeg(); 00507 } 00508 00509 delete trialSeg; 00510 return nSegs; 00511 }
|
|
|
|
|