MdcTrackList Class Reference

#include <MdcTrackList.h>

Inheritance diagram for MdcTrackList:

MdcTrackListBase List of all members.

Public Member Functions

 MdcTrackList (const MdcTrackParams &tkPar)
 ~MdcTrackList ()
int createFromSegs (MdcSegList *segs, const MdcHitMap *, const MdcDetector *, TrkContext &, double bunchTime)
int finishCircle (MdcTrack &track, const MdcHitMap *, const MdcDetector *)
int finishHelix (MdcTrack &track, const MdcHitMap *, const MdcDetector *)
int pickHits (MdcTrack *, const MdcHitMap *, const MdcDetector *, bool pickAmb=true)
void dumpSeed (const MdcSeg *seed, bool goodOnly)
void dumpCircle (const MdcTrack *)
void dumpAxFill (const MdcTrack *)
void dumpAxCombine (const MdcTrack *)
void dumpD0 (const TrkExchangePar &)
void dumpStFill ()
void dumpStCombine (const MdcTrack *)
void dumpHelix (const MdcTrack *)
void dropMultiHotInLayer (const MdcTrack *tk)
int nTrack () const
void setPlot (int plotFlag)
void newParams (const MdcTrackParams &tkPar)
void plot () const
void store (RecMdcTrackCol *, RecMdcHitCol *)
int arbitrateHits ()
void remove (MdcTrack *atrack)
void setD0Cut (double d0Cut)
void setZ0Cut (double z0Cut)
void setPtCut (double ptCut)

Static Public Attributes

static double m_d0Cut = -999.
static double m_z0Cut = -999.
static double m_ptCut = -999.

Protected Attributes

MdcTrackParams tkParam

Private Member Functions

MdcTrackListoperator= (const MdcTrackList &)
 MdcTrackList (const MdcTrackList &)

Private Attributes

int m_debug

Detailed Description

Definition at line 31 of file MdcTrackList.h.


Constructor & Destructor Documentation

MdcTrackList::MdcTrackList ( const MdcTrackParams tkPar  ) 

Definition at line 91 of file MdcTrackList.cxx.

00091                                                        : 
00092   MdcTrackListBase(tkPar) { 
00093     // *************************************************************************
00094     return;
00095   }

MdcTrackList::~MdcTrackList (  ) 

Definition at line 98 of file MdcTrackList.cxx.

00098 {}

MdcTrackList::MdcTrackList ( const MdcTrackList  )  [private]


Member Function Documentation

int MdcTrackListBase::arbitrateHits (  )  [inherited]

Definition at line 104 of file MdcTrackListBase.cxx.

References TrkHitList::begin(), TrkHitList::end(), TrkRecoTrk::fitResult(), for, MdcMap< K, V >::get(), TrkRecoTrk::hits(), genRecEmupikp::i, TrkRecoTrk::id(), MdcTrackParams::lPrint, MdcTrackParams::lRemoveInActive, MdcTrackListBase::nTrack(), MdcMap< K, V >::put(), q, TrkHitList::removeHit(), MdcTrackListBase::tkParam, and MdcTrack::track().

00104                                 {
00105   //*************************************************************************
00106   // Look at all hits used in two or more tracks.  Assign hits to the track
00107   // that gives the lower residual.  If, however, many hits are shared by
00108   // a pair of tracks, assign them all to one or the other.
00109   // Refit any tracks that have had hits dropped.
00110   // The implementation is very clumsy, since the arrays were originally
00111   // indexed by id # => there is an unneeded layer of indexing.
00112 
00113   // return # of tracks deleted
00114 
00115   if (8 == tkParam.lPrint){
00116     std::cout << "=======Print before arbitrateHits=======" << std::endl;
00117   }
00118 
00119   int nDeleted = 0;
00120   std::vector<MdcTrack*> trksToKill;
00121   trksToKill.reserve(4);
00122 
00123   MdcMap<long,long> idMap;
00124 
00125   //usedInTrackNum records how many shared hits track has with each other track
00126   int* usedInTrackNum = new int [nTrack()];
00127   // to navigate from track id # to track pointer:
00128   MdcTrack** trkXRef = new MdcTrack* [nTrack()];
00129   //refitTrack flags track id #s of tracks to be refit
00130   int *refitTrack = new int [nTrack()];
00131   for (int i = 0; i < nTrack(); i++) {
00132     refitTrack[i] = 0;
00133   }
00134 
00135   // Fill xref table
00136   int itrack;
00137   for (itrack = 0; itrack < nTrack(); itrack++) {
00138     MdcTrack *atrack = (*this)[itrack];
00139     if (atrack == 0) continue;  // I don't think it can be, but . . .
00140     idMap.put(atrack->track().id(), itrack);
00141     trkXRef[itrack] = atrack;
00142   }
00143   // Loop through the tracks
00144   for (itrack = 0; itrack < nTrack(); itrack++) {
00145 
00146     if (8 == tkParam.lPrint) std::cout<<"arbitrate track No."<<itrack<<  std::endl;
00147     MdcTrack *atrack = (*this)[itrack];
00148     if (atrack == 0) continue;
00149     TrkRecoTrk& aRecoTrk = atrack->track();
00150     int lRefit = 0;
00151     int trackOld = -1;
00152     const TrkFit* tkFit = aRecoTrk.fitResult();
00153     assert (tkFit != 0);
00154     TrkHitList* hitList = aRecoTrk.hits();
00155     assert (hitList != 0);
00156 restart:
00157     for (int ii = 0; ii < nTrack(); ii++) usedInTrackNum[ii] = 0;
00158 
00159     // Loop through hits on track, counting # used in other tracks
00160     int nPrev = 0;
00161     int nHitDeleted = 0;
00162     int maxGapLength = 0;//yzhang 2011-07-29 # of max continuous no hits layer for a track, Gap defined as missing layer >=2 
00163     int nGapGE2= 0;//yzhang 2011-07-29 # of no hits gap for a track 
00164     int nGapGE3= 0;//yzhang 2011-07-29 # of no hits gap for a track 
00165     int nHitInLayer[43];//yzhang 2010-09-20 for bad tracking testing
00166     int nDeleteInLayer[43];//yzhang 2010-09-20 
00167     for(int i=0;i<43;i++){
00168       nHitInLayer[i]=0;
00169       nDeleteInLayer[i]=0;
00170     }
00171     if(8 == tkParam.lPrint) std::cout<< "--arbitrate--"<<std::endl;
00172     for (TrkHitList::hot_iterator ihit(hitList->begin()); ihit != hitList->end(); ++ihit){
00173       int nUsed = ihit->hit()->nUsedHits();
00174       if (8 == tkParam.lPrint){
00175         std::cout<<"nUsed="<<nUsed<<":";
00176         ihit->hit()->printAll(std::cout);
00177       }
00178       if (8 == tkParam.lPrint) {
00179         double deltaChi = -999;
00180         ihit->getFitStuff(deltaChi);
00181         std::cout<< "deltaChi="<<deltaChi<<std::endl;
00182       }
00183       int layer = ihit->layerNumber();
00184       nHitInLayer[layer]++;
00185 
00186       if (!ihit->isActive()) {
00187         //-----------------------------------
00188         //yzhang delete not ACT hit 2010-05-14 
00189         //-----------------------------------
00190         if(tkParam.lRemoveInActive ) {//2010-05-16 
00191           nDeleteInLayer[layer]++;
00192           if (8 == tkParam.lPrint) {
00193             std::cout<< "=remove above inactive "<<std::endl;
00194           }
00195           TrkFundHit* hit = const_cast<TrkFundHit*> (ihit->hit());
00196           hitList->removeHit(hit);
00197           if(ihit == hitList->end()) break;
00198           --ihit;//be careful of the iterator, yzhang
00199         }
00200         continue;   // active hits only yzhang 2009-11-03 delete
00201       }
00202       if (nUsed > 1) {
00203         bool wasUsed = false;
00204         std::pair<TrkFundHit::hot_iterator,TrkFundHit::hot_iterator> q =
00205           ihit->hit()->getUsedHits();
00206         for (TrkFundHit::hot_iterator i = q.first; i != q.second; ++i) {
00207           if ( !i->isActive() ) continue; //yzhang 2009-11-03 delete
00208           TrkRecoTrk * recoTrk=i->parentTrack();
00209           int id = recoTrk->id();
00210           if (id == aRecoTrk.id()) continue; //skip same track
00211           long index = 0;
00212           idMap.get(id, index);
00213           assert(index >= 0);
00214           usedInTrackNum[index]++;
00215           if (8 == tkParam.lPrint){
00216             std::cout<<" track "<<itrack<<"&" <<index
00217               << " shared hits "<<usedInTrackNum[index]<<":";
00218             ihit->printAll(std::cout);
00219           }
00220           wasUsed = true;
00221         }
00222         if (wasUsed) nPrev++;
00223       }// end nUsed > 1
00224     } // end loop over hits
00225 
00226     int testGap = 0;
00227     //std::cout<< __FILE__ << "   " << itrack<< "   "<<std::endl;
00228     for (int i=0;i<43;i++){
00229       //std::cout<< __FILE__ << "   " << i<< " nHitInLayer  "<<nHitInLayer[i]<<" nDeleteInLayer "<<nDeleteInLayer[i]<<std::endl;
00230       if (8 == tkParam.lPrint) {
00231         std::cout<<i<<" nHitInLayer  "<<nHitInLayer[i]
00232           <<" nDeleteInLayer "<<nDeleteInLayer[i]<<std::endl;
00233       }
00234       //1.only hit in layer deleted; 2.no hits in layer; 3.got hits in layer;
00235       if(nHitInLayer[i]>0 && (nHitInLayer[i]-nDeleteInLayer[i])==0) {
00236         //only hit in layer i has been deleted
00237         nHitDeleted++;
00238         if (8 == tkParam.lPrint) { 
00239           cout << "rec hits have been deleted in this layer"<<std::endl; 
00240         }
00241         testGap++;
00242         //std::cout<< __FILE__ << "   " << __LINE__ << " testGap3  "<<testGap<<std::endl;
00243       }else if(nHitInLayer[i]==0){
00244         //no hits in this layer i
00245         testGap++;
00246         //std::cout<< __FILE__ << "   " << __LINE__ << " testGap3  "<<testGap<<std::endl;
00247       }else{
00248         //std::cout<< __FILE__ << "   " << __LINE__ << " testGap3  "<<testGap<<std::endl;
00249         //got hit in layer i
00250         if(testGap>=2){
00251           nGapGE2++;
00252           if(testGap>=3){ nGapGE3++; }
00253           if(testGap>maxGapLength) maxGapLength=testGap;
00254           //std::cout<< __FILE__ << "   " << __LINE__ << " maxGapLength  "<<maxGapLength<<std::endl;
00255         }
00256         testGap=0;
00257       }//end for layer 43
00258     }
00259 
00260     bool toBeDeleted = false;
00261 
00262     if(tkParam.lPrint>1) std::cout<< "arbitrateHits tkNo:"<<itrack<<" nGapGE2=  "<<nGapGE2 << " nGapGE3=  "<<nGapGE3 << " maxGapLength=  "<<maxGapLength<<std::endl;
00263     //yzhang add nHitDeleted cut 2010-09-13 
00264     // remove track if # not Active 
00265     if (nHitDeleted >= tkParam.nHitDeleted) {
00266       if (tkParam.lPrint>1) {
00267         cout << "arbitrateHits: nHitDeleted "<<nHitDeleted<<" >= "<<tkParam.nHitDeleted
00268           <<" Killing tkNo " << itrack << endl;
00269       }
00270       toBeDeleted = true;
00271     }
00272 
00273     //yzhang add nGap cut 2011-07-29 
00274     // remove track with gaps and big gap
00275     if (nGapGE2 >= tkParam.nGapGE2) {
00276       if (tkParam.lPrint>1) {
00277         cout << "arbitrateHits: nGapGE2 "<<nGapGE2<<" >= "<<tkParam.nGapGE2 <<" Killing tkNo " << itrack << endl;
00278       }
00279       toBeDeleted = true;
00280     } 
00281     if (nGapGE3 >= tkParam.nGapGE3) {
00282       if (tkParam.lPrint>1) {
00283         cout << "arbitrateHits: nGapGE3 "<<nGapGE3<<" >= "<<tkParam.nGapGE3 <<" Killing tkNo " << itrack << endl;
00284       }
00285       toBeDeleted = true;
00286     } 
00287     if (maxGapLength >= tkParam.maxGapLength) {
00288       if (tkParam.lPrint>1) {
00289         cout << "arbitrateHits: maxGapLength "<<maxGapLength<<" >= "<<tkParam.maxGapLength<<" Killing tkNo " << itrack << endl;
00290       }
00291       toBeDeleted = true;
00292     } 
00293 
00294     if(toBeDeleted){
00295       nDeleted++;
00296       delete &(atrack->track());    // Delete the RecoTrk inside atrack
00297       atrack->setTrack(0);
00298       trksToKill.push_back(atrack);
00299       continue;
00300     } 
00301 
00302     //*******
00303     // How many hits are shared with a single track?
00304     int nMost = 0;
00305     int trackMost = 0;
00306     for (int ii = 0; ii < nTrack(); ii++) {
00307       if (8 == tkParam.lPrint){
00308         std::cout<<"tk:"<<itrack<<"&"<<ii
00309           <<" shared "<<usedInTrackNum[ii]<<" hits "<<  std::endl;
00310       }
00311       if (usedInTrackNum[ii] > nMost) {
00312         nMost = usedInTrackNum[ii];
00313         trackMost = ii;  //index of track w/ most hits in common w/ current trk
00314       }
00315     }
00316 
00317     // A little precaution against infinite loops:
00318     if (trackMost == trackOld) {
00319       std::cout << "ErrMsg(error) MdcTrackListBase:"
00320         << "Something ghastly happened in MdcTrackListBase::arbitrateHits"
00321         << std::endl;
00322       return 0;
00323     }
00324     trackOld = trackMost;
00325 
00326 
00327     //******
00328     // Decide whether to handle hits individually or in group
00329     double groupDiff = 0.0;   // relative quality of grouped hits for the two
00330     // tracks; > 0. => current track worse
00331     int nFound = 0;    // # of grouped hits located so far
00332     TrkHitOnTrk **theseHits = 0;  // grouped hits as seen in current track
00333     TrkHitOnTrk **thoseHits = 0;  // grouped hits as seen in the other track
00334     int lGroupHits = 0;
00335 
00336     if (nMost >= tkParam.nOverlap) {
00337       if (8 == tkParam.lPrint){
00338         std::cout<<"track "<<trackMost<<" shared "<<nMost<<" hits > Cut nOverlap "
00339           <<tkParam.nOverlap<<", group hits!"<<std::endl;
00340       }
00341       lGroupHits = 1;
00342       theseHits = new TrkHitOnTrk*[nMost];
00343       thoseHits = new TrkHitOnTrk*[nMost];
00344     }
00345 
00346     //*********
00347     // Go back through hits on this track, looking up the overlap of each
00348     // if grouping hits, only deal with hits shared with trackMost on this pass
00349     // otherwise, deal with all shared hits as encountered
00350     if(8 == tkParam.lPrint) std::cout<<"Go back through hits, looking up overlap hits"<< std::endl;
00351     if (nMost > 0) {
00352       if (8 == tkParam.lPrint) std::cout<<" nHits= "<< hitList->nHit()<< std::endl;
00353       for (TrkHitList::hot_iterator ihit(hitList->begin()); ihit != hitList->end(); ++ihit) {
00354         int nUsed = ihit->hit()->nUsedHits();
00355 
00356         if (8 == tkParam.lPrint){
00357           std::cout<< "--hit go back, nUsed="<<nUsed<<":";
00358           ihit->hit()->printAll(std::cout);
00359         }
00360 
00361         // only shared hits 
00362         if (nUsed < 2) { continue; }
00363 
00364         // active hits only
00365         if (!ihit->isActive()) {
00366           if (8 == tkParam.lPrint){ std::cout<<"act=0 continue"<<std::endl; }
00367           continue;   
00368         }
00369 
00370         //*** look at all overlaps for this hit
00371         std::pair<TrkFundHit::hot_iterator,TrkFundHit::hot_iterator> q = ihit->hit()->getUsedHits();
00372         while (q.first!=q.second) { // nUsed > 0
00373           int dropThisHit = 0;
00374           TrkHitOnTrk *otherHot = const_cast<TrkHitOnTrk*>((--q.second).get());
00375           TrkRecoTrk *otherTrack = otherHot->parentTrack();
00376 
00377           if (!otherHot->isActive()) continue;
00378 
00379           // Again, skip "overlap" of track with itself
00380           if ( &aRecoTrk == otherTrack) continue;
00381           int otherId = otherTrack->id();
00382           long otherIndex = -1;
00383           idMap.get(otherId, otherIndex); assert(otherIndex >= 0);
00384 
00385           // if grouping hits, only look at hits shared with trackMost
00386           if (lGroupHits && otherIndex != trackMost) continue;
00387 
00388           if (lGroupHits) {
00389             if (8 == tkParam.lPrint) {
00390               std::cout<<"group hits "<<  std::endl;
00391             }
00392             // Calculate contribution of group to each chisq/dof
00393             //        groupDiff += fabs(ihit->resid(0)) -
00394             //          fabs(otherHot->resid(0));
00395             // Hack to handle tracks with 5 active hits:
00396             int aDof = tkFit->nActive() - 5;
00397             assert (otherTrack->fitResult() != 0);
00398             int otherDof = otherTrack->fitResult()->nActive() - 5;
00399             if (aDof <= 0) {groupDiff = 999;}
00400             else if (otherDof <= 0) {groupDiff = -999;}
00401             else {
00402               groupDiff += ihit->resid(0) * ihit->resid(0) * ihit->weight() /
00403                 aDof -
00404                 otherHot->resid(0) * otherHot->resid(0) * otherHot->weight() /
00405                 otherDof;
00406             }
00407             theseHits[nFound] = const_cast<TrkHitOnTrk*>(ihit.get());
00408             thoseHits[nFound] = otherHot;
00409             nFound++;
00410             dropThisHit = 1;
00411           } else {   // handle hits individually
00412 
00413             if (8 == tkParam.lPrint) {
00414               std::cout<<"handle hits individually"<<  std::endl;
00415             }
00416             nFound++;
00417             if (fabs(ihit->resid(0)) > fabs(otherHot->resid(0)) ) {
00418               // turn off (inactivate) hit on this track
00419               lRefit = 1;
00420               //              ihit->hit()->setUnusedHit(ihit.get());
00421               //Should I be setting inactive, or deleting the hit???????
00422               const_cast<TrkHitOnTrk*>(ihit.get())->setActivity(0);
00423               dropThisHit = 1;
00424               if (8 == tkParam.lPrint) {
00425                 std::cout<<"dorp hit ";
00426                 const_cast<TrkHitOnTrk*>(ihit.get())->print(std::cout);
00427               }
00428               break;      // found other hit, so quit loop
00429             } else {
00430               // inactivate hit on other track
00431               refitTrack[otherIndex] = 1;
00432               //              otherHot->hit()->setUnusedHit(otherHot);
00433               otherHot->setActivity(0);
00434               if (8 == tkParam.lPrint) {
00435                 std::cout<<"inactive hit on other track";
00436                 const_cast<TrkHitOnTrk*>(ihit.get())->print(std::cout);
00437               }
00438               break;      // found other hit, so quit loop
00439             }
00440           } // end grouped/individual treatment
00441 
00442           if (dropThisHit == 1) break; // don't look for other matches since
00443           // this hit is now turned off
00444         } // end loop over nUsed
00445 
00446         // Quit if we've found all of the shared hits on this track
00447         if (lGroupHits && nFound == nMost  ||  nFound == nPrev) {
00448           if (8 == tkParam.lPrint) {
00449             std::cout<<"we've found all of the shared hits on this track,Quit"<<std::endl;
00450           }
00451           break;
00452         }
00453 
00454       }  // end loop over hits
00455 
00456       // Decide which track grouped hits belong with and inactivate accordingly
00457       if (lGroupHits) {
00458         if (8 == tkParam.lPrint) {
00459           cout << "nGroup: " << nMost << "  groupDiff: " << groupDiff << endl;
00460           cout << "Track: " << aRecoTrk.id() << "  nHit: "
00461             << hitList->nHit() << "  nActive: "
00462             << tkFit->nActive() << " chisq/dof: " <<
00463             tkFit->chisq()/(tkFit->nActive() - 5) << endl;
00464           TrkRecoTrk& othTrack = trkXRef[trackMost]->track();
00465           cout << "Track: "<< othTrack.id() << "  nHit: " <<
00466             othTrack.hits()->nHit() << "  nActive: " <<
00467             othTrack.fitResult()->nActive() << " chisq/dof: " <<
00468             othTrack.fitResult()->chisq() /
00469             (othTrack.fitResult()->nActive() - 5) << endl;
00470         }
00471 
00472         if (groupDiff > 0.0) {
00473           // inactivate hits on this track
00474           lRefit = 1;
00475           for (int ii = 0; ii < nMost; ii++) {
00476             TrkHitOnTrk *alink = theseHits[ii];
00477             TrkFundHit* hit = const_cast<TrkFundHit*> (alink->hit());
00478             hitList->removeHit(hit);//yzhang 2011-02-12 
00479             //alink->setActivity(0);
00480           }
00481           if (8 == tkParam.lPrint) std::cout<<"inactive hits on this track, No."<<aRecoTrk.id()<<  std::endl;
00482         } else {
00483           // inactivate hits on other track
00484           refitTrack[trackMost] = 1;
00485           for (int ii = 0; ii < nMost; ii++) {
00486             TrkHitOnTrk *alink = thoseHits[ii];
00487             TrkFundHit* hit = const_cast<TrkFundHit*> (alink->hit());
00488             hitList->removeHit(hit);//yzhang 2011-02-12 
00489             //alink->setActivity(0);
00490           }
00491           if (8 == tkParam.lPrint) std::cout<<"inactive hits on other track "<<   std::endl;
00492         }
00493         delete [] theseHits;
00494         delete [] thoseHits;
00495 
00496       } // end if lGroupHits
00497 
00498     } // end if nMost > 0
00499 
00500     //*********
00501     // Refit this track, if any hits have been dropped
00502     TrkErrCode fitResult;
00503     long index = -1;
00504     idMap.get(aRecoTrk.id(), index); assert (index >= 0);
00505 
00506     if (lRefit || refitTrack[index] == 1) {
00507       if (8 == tkParam.lPrint) {
00508         std::cout<<"after group ,refit track"<<aRecoTrk.id()<<  std::endl;
00509       }
00510       fitResult = hitList->fit();
00511       aRecoTrk.status()->addHistory(
00512           TrkErrCode(fitResult.success()?TrkErrCode::succeed:TrkErrCode::fail,14,"Arbitrated"), "MdcTrkRecon");
00513       if (fitResult.failure() && (8 == tkParam.lPrint )) {
00514         fitResult.print(std::cerr);
00515       }
00516 
00517 
00518       double chisqperDOF;
00519       bool badFit = true;
00520       if (fitResult.success()) {
00521         badFit = false;
00522         int nDOF = tkFit->nActive() - 5;
00523         if (nDOF > 5){
00524           chisqperDOF = tkFit->chisq() / nDOF;
00525         }else{
00526           chisqperDOF = tkFit->chisq();
00527         }
00528 
00529         if (chisqperDOF > tkParam.maxChisq) badFit = true;
00530         if (tkFit->nActive() < tkParam.minHits) badFit = true;
00531         double tem2 = (float) hitList->nHit() - tkFit->nActive();
00532         if (tkParam.lUseQualCuts) {
00533           if (tem2 >= tkParam.maxNmissTrack) badFit = true;
00534           if (tem2 /float(hitList->nHit()) > tkParam.maxNmissNorm){
00535             badFit = true;
00536           }
00537         }
00538         if(8== tkParam.lPrint) std::cout<<"fit quality:"<<
00539           " chisqperDof "<<chisqperDOF<<"?>"<<tkParam.maxChisq<<
00540             " nActive "<<tkFit->nActive()<<"?<"<<tkParam.minHits<<
00541             " nHit "<<hitList->nHit()<<" nhit-act "<<tem2<<"?>= nMiss "<<tkParam.maxNmissTrack<<
00542             " hit-act/nhit "<<tem2/float(hitList->nHit())<<"?> MissNorm "<<tkParam.maxNmissNorm
00543             <<  std::endl;
00544 
00545 
00546       }
00547       if (8 == tkParam.lPrint)  {
00548         cout << "Refitting track " << aRecoTrk.id() << " success = "
00549           << fitResult.success() << "\n";
00550       }
00551       // If the track no longer passes cuts, delete it
00552       if (fitResult.failure() || badFit ) {
00553         nDeleted++;
00554         //  Don't change the track list while we're iterating through it!
00555         //      remove(atrack);
00556         //int id = aRecoTrk.id();
00557         if (8 == tkParam.lPrint) {
00558           cout << "fitResult.failure? "<<fitResult.failure()
00559             <<" badFit? "<<badFit <<" Killing tkNo " << itrack << endl;
00560         }
00561         delete &(atrack->track());    // Delete the RecoTrk inside atrack
00562         atrack->setTrack(0);
00563         trksToKill.push_back(atrack);
00564         continue;
00565       }
00566     } // end if lRefit
00567 
00568     if (lGroupHits) goto restart;
00569 
00570   } // end loop over tracks
00571   if (8 == tkParam.lPrint) std::cout<<"end of loop over tracks"<<  std::endl;
00572 
00573   // Remove dead track husks
00574   for (int itk = 0; itk < (int)trksToKill.size(); itk++) {
00575     remove(trksToKill[itk]);
00576     if (8 == tkParam.lPrint) std::cout<<"remode dead track No."<<itk<<  std::endl;
00577   }
00578   if (8 == tkParam.lPrint) std::cout<<"---end of arbitrateHits"<<  std::endl;
00579 
00580   delete [] usedInTrackNum;
00581   delete [] refitTrack;
00582   delete [] trkXRef;
00583   return nDeleted;
00584 }

int MdcTrackList::createFromSegs ( MdcSegList segs,
const MdcHitMap ,
const MdcDetector ,
TrkContext ,
double  bunchTime 
) [virtual]

Implements MdcTrackListBase.

Definition at line 103 of file MdcTrackList.cxx.

References EvtCyclic3::append(), MdcTrackParams::combineByFitHits, MdcSegGrouper::combineSegs(), MdcSegList::count(), TrkExchangePar::d0(), dumpAxCombine(), dumpCircle(), dumpHelix(), dumpSeed(), MdcSegGrouper::dumpSegList(), dumpStCombine(), Constants::epsilon, MdcSegGrouperSt::fillWithSegs(), MdcSegGrouperAx::fillWithSegs(), finishCircle(), finishHelix(), TrkRecoTrk::fitResult(), MdcSegList::getSeed(), TrkFit::helix(), MdcTrackParams::lPrint, MdcTrackListBase::m_d0Cut, m_debug, MdcTrackListBase::m_ptCut, MdcTrackListBase::m_z0Cut, MdcTrackParams::maxSegChisqO, TrkAbsFit::pt(), MdcSegList::resetSeed(), MdcTrackListBase::tkParam, MdcTrack::track(), and TrkExchangePar::z0().

00105                                            {
00106   // *************************************************************************
00107   //Forms tracks out of list of superlayer segments
00108   int nTracks = 0;
00109 
00110   m_debug = tkParam.lPrint;//yzhang debug
00111 
00112   // Create empty list of stereo segs (to save time)
00113   MdcSegGrouperSt stereoSegs(gm, tkParam.lPrint);
00114 
00115   // *** Create r-phi track
00116 
00117   // Create list of axial segments, treated as on tracks from origin
00118 #ifdef MDCPATREC_TIMETEST
00119   TAU_PROFILE_TIMER(timer8,"fill ax seg", "int ()", TAU_DEFAULT);
00120   TAU_PROFILE_START(timer8);
00121 #endif
00122   MdcSegGrouperAx origSegs(gm, tkParam.lPrint);
00123   origSegs.fillWithSegs(segs);
00124   //std::cout << "Plot segs after ax fillWithSegs " << std::endl;//yzhang debug 
00125   //segs->plot(0);//yzhang debug
00126 #ifdef MDCPATREC_TIMETEST
00127   TAU_PROFILE_STOP(timer8);
00128 #endif
00129   MdcSeg *seed;
00130   bool goodOnly = true;
00131   bool useBad = (segs->count() < 400);  // if true, use non-good seeds 
00132   //bool useBad = false;
00133   segs->resetSeed(gm); 
00134   MdcTrack *trialTrack = 0;
00135 
00136   while (1) {
00137     seed = segs->getSeed(0,goodOnly);
00138     if (seed == 0 && goodOnly && useBad) {
00139       segs->resetSeed(gm);
00140       goodOnly = false;
00141       continue;
00142     }
00143     else if (seed == 0 && (!goodOnly || !useBad)) {
00144       break;
00145     }
00146 
00147     if (3 == m_debug) dumpSeed(seed, goodOnly);//yzhang debug
00148 
00149     // Pass through first superlayer of MDC required, Field layer No5 = 12.135 cm
00150     if ( fabs( ((MdcSegInfoAxialO *) seed->info())->curv()) > 0.0417) continue;//curv cut yzhang 
00151     delete trialTrack;
00152     trialTrack = 0;
00153 
00154     //---------Combine Ax segs--------
00155 #ifdef MDCPATREC_TIMETEST
00156     TAU_PROFILE_TIMER(timer3,"combine ax seg", "int ()", TAU_DEFAULT);
00157     TAU_PROFILE_START(timer3);
00158 #endif
00159     int success = origSegs.combineSegs(trialTrack, seed, context, bunchTime, 
00160         tkParam.maxSegChisqO);
00161 #ifdef MDCPATREC_TIMETEST
00162     TAU_PROFILE_STOP(timer3);
00163 #endif
00164 
00165 
00166     if (3 <= m_debug){
00167       cout<<" ***** Ax.combineSegs success?  " << success<<"\n";
00168       dumpAxCombine(trialTrack);//yzhang debug
00169     }
00170     if (!success) continue;     
00171 
00172 
00173     //--------Finish circle-------- 
00174 #ifdef MDCPATREC_TIMETEST
00175     TAU_PROFILE_TIMER(timer4,"circle fitting", "int ()", TAU_DEFAULT);
00176     TAU_PROFILE_START(timer4);
00177 #endif
00178     success = finishCircle(*trialTrack, map, gm);
00179 #ifdef MDCPATREC_TIMETEST
00180     TAU_PROFILE_STOP(timer4);
00181 #endif
00182 
00183     if (3 <= m_debug){
00184       cout<<"finishCircle success?  " << success<<"\n";
00185       dumpCircle(trialTrack);//yzhang debug
00186     }
00187 
00188     if (!success) continue;
00189     //--------Make sure it really did come from origin--------
00190     const TrkFit* tkFit = trialTrack->track().fitResult();
00191     assert (tkFit != 0);
00192     TrkExchangePar par = tkFit->helix(0.0);
00193     //dumpD0(par);
00194 
00195     //------------------d0 cut-------------------
00196     // 2010-03-31 , m_d0Cut from 0 to epsilon
00197 
00198     //std::cout<<  __FILE__ <<"  d0 cut------------"<< fabs(par.d0())<<" d0cut "<< m_d0Cut << std::endl;
00199     if ( (m_d0Cut > Constants::epsilon) && (fabs(par.d0()) > m_d0Cut) ){
00200       if (tkParam.lPrint>1)cout<<__FILE__<<" Killing track by d0:" <<par.d0()<<">"<<m_d0Cut << endl;
00201       continue;
00202     }
00203 
00204     //------------------pt cut-------------------
00205     if ( (fabs(m_ptCut)>0.) && (fabs(tkFit->pt(0.)) < m_ptCut) ){
00206       if (tkParam.lPrint>1)cout<<__FILE__<<" Killing track by pt:" <<tkFit->pt(0.)<<"<"<<m_ptCut << endl;
00207       continue;
00208     }
00209 
00210     // *** End r-phi track-finding
00211     if (3 <= m_debug) std::cout << " *** End r-phi track-finding "<<std::endl;
00212 
00213     //--------Add stereo to taste--------
00214 #ifdef MDCPATREC_TIMETEST
00215     TAU_PROFILE_TIMER(timer5,"fill st seg", "int ()", TAU_DEFAULT);
00216     TAU_PROFILE_START(timer5);
00217 #endif
00218     stereoSegs.fillWithSegs(segs, trialTrack);
00219 #ifdef MDCPATREC_TIMETEST
00220     TAU_PROFILE_STOP(timer5);
00221 #endif
00222     if (3 <= m_debug){
00223       //dumpStFill();//yzhang debug
00224       std::cout<<std::endl<<"----------------------------------------"<<  std::endl;
00225       std::cout<<" Segment list after St.fillWithSegs "<<  std::endl;
00226       stereoSegs.dumpSegList();
00227     }
00228 
00229 #ifdef MDCPATREC_TIMETEST
00230     TAU_PROFILE_TIMER(timer6,"combine st seg", "int ()", TAU_DEFAULT);
00231     TAU_PROFILE_START(timer6);
00232 #endif
00233     success = stereoSegs.combineSegs(trialTrack, 0, context, bunchTime, 
00234         tkParam.maxSegChisqO, tkParam.combineByFitHits);
00235 #ifdef MDCPATREC_TIMETEST
00236     TAU_PROFILE_STOP(timer6);
00237 #endif
00238 
00239     if (3 <= m_debug){
00240       cout<<" ***** St.combineSegs success?  " << success<<"\n";
00241       dumpStCombine(trialTrack);
00242     }
00243 
00244 
00245     //--------Finish 3-d track--------
00246     if (success) {
00247 #ifdef MDCPATREC_TIMETEST
00248       TAU_PROFILE_TIMER(timer7,"helix fitting", "int ()", TAU_DEFAULT);
00249       TAU_PROFILE_START(timer7);
00250 #endif
00251       success = finishHelix(*trialTrack, map, gm);
00252 #ifdef MDCPATREC_TIMETEST
00253       TAU_PROFILE_STOP(timer7);
00254 #endif
00255     }  // end if (success -- st)
00256 
00257     if (3 == m_debug){
00258       dumpHelix(trialTrack);
00259     }
00260     if (!success) continue;
00261 
00262     //------------------d0 cut after helix fitting-------------------
00263     //yzhang add 2011-08-01 
00264     double d0par = trialTrack->track().fitResult()->helix(0.).d0();
00265     if ( (m_d0Cut > Constants::epsilon) && (fabs(d0par) > m_d0Cut) ){
00266       if (tkParam.lPrint>1) {cout<<__FILE__
00267         <<" Killing track by d0 after 3d fit:" <<d0par<<">"<<m_d0Cut << endl;}
00268       continue;
00269     }
00270 
00271     double z0par = trialTrack->track().fitResult()->helix(0.).z0();
00272     if ( (m_z0Cut > Constants::epsilon) && (fabs(z0par) > m_z0Cut) ){
00273       if (tkParam.lPrint>1) {cout<<__FILE__
00274         <<" Killing track by z0:" <<z0par<<">"<<m_z0Cut << endl;}
00275       continue;
00276     }
00277 
00278 
00279     nTracks++;
00280     append(trialTrack);    // Add to list of Tracks
00281 
00282     trialTrack = 0;
00283 
00284     if (3 == m_debug) std::cout << " ***** End one track-finding *****"<<std::endl;
00285   }  // end while(1)   
00286 
00287   delete trialTrack;
00288   return nTracks;
00289 
00290 }

void MdcTrackList::dropMultiHotInLayer ( const MdcTrack tk  ) 

Reimplemented from MdcTrackListBase.

Definition at line 1151 of file MdcTrackList.cxx.

References TrkHotList::begin(), dt, TrkHotList::end(), TrkRecoTrk::hits(), TrkHitList::hotList(), genRecEmupikp::i, TrkHitOnTrk::setActivity(), and MdcTrack::track().

01151                                                         {
01152   double tdr[43];
01153   double tdr_wire[43];
01154   for(int i=0; i<43; i++){tdr[i]=9999.;}
01155 
01156   // make flag
01157   TrkHotList::hot_iterator hotIter= tk->track().hits()->hotList().begin();
01158   while (hotIter!=tk->track().hits()->hotList().end()) {
01159     MdcHitOnTrack* hot = const_cast<MdcHitOnTrack*> (&(*hotIter->mdcHitOnTrack()));
01160 
01161     //driftTime(tof,z)
01162     double dt = hot->mdcHit()->driftTime(0.,0.);
01163     int layer = hot->mdcHit()->layernumber();
01164     int wire = hot->mdcHit()->wirenumber();
01165     if (dt < tdr[layer]) {
01166       tdr[layer] = dt;  
01167       tdr_wire[layer] = wire;  
01168     }
01169     hotIter++;
01170   }
01171 
01172   std::cout<<" tdr wire ";
01173   for(int i=0;i<43;i++){
01174     std::cout<<i<<" "<<tdr[i]<<" "<<tdr_wire<<" ";
01175   }
01176   std::cout<<" "<<  std::endl;
01177   // inactive multi hit 
01178   hotIter= tk->track().hits()->hotList().begin();
01179   while (hotIter!=tk->track().hits()->hotList().end()) {
01180     int layer = hotIter->mdcHitOnTrack()->mdcHit()->layernumber();
01181     int wire = hotIter->mdcHitOnTrack()->mdcHit()->wirenumber();
01182     double dt = hotIter->mdcHitOnTrack()->mdcHit()->driftTime(0.,0.);
01183 
01184     if ((tdr[layer] <9998.) && (tdr_wire[layer]!=wire)){
01185       MdcHitOnTrack* hot = const_cast<MdcHitOnTrack*> (&(*hotIter->mdcHitOnTrack()));
01186       hot->setActivity(false);
01187 
01188       std::cout<<__FILE__<<" inactive "<< layer<<" "<<wire<<" dt "<<dt <<  std::endl;
01189     }
01190     hotIter++;
01191   }
01192 }

void MdcTrackList::dumpAxCombine ( const MdcTrack  ) 

Definition at line 1057 of file MdcTrackList.cxx.

References TrkHotList::begin(), TrkHotList::end(), TrkRecoTrk::hits(), TrkHitList::hotList(), TrkRecoTrk::printAll(), and MdcTrack::track().

Referenced by createFromSegs().

01057                                                             {
01058   if (NULL == trialTrack) return;
01059   std::cout<<std::endl<< "-------------------------------------"<<std::endl;
01060   std::cout<<"Track and hitList after AxCombine "<<std::endl;
01061   trialTrack->track().printAll(cout);//yzhang debug
01062   TrkHotList::hot_iterator hotIter= trialTrack->track().hits()->hotList().begin();
01063   while (hotIter!=trialTrack->track().hits()->hotList().end()) {
01064     cout <<"(" <<((MdcHit*)(hotIter->hit()))->layernumber()
01065       <<","<<((MdcHit*)(hotIter->hit()))->wirenumber() 
01066       <<":"<<hotIter->isActive()<<")  ";
01067     hotIter++;
01068   }
01069   std::cout << std::endl;
01070   std::cout<< "-------------------------------------"<<std::endl;
01071 }

void MdcTrackList::dumpAxFill ( const MdcTrack  ) 

Definition at line 1044 of file MdcTrackList.cxx.

References TrkRecoTrk::printAll(), and MdcTrack::track().

01044                                                           {
01045   std::cout << "ax fill: "<<std::endl; 
01046   if(!trialTrack){
01047     trialTrack->track().printAll(cout);//yzhang debug
01048   }
01049 }

void MdcTrackList::dumpCircle ( const MdcTrack  ) 

Definition at line 1073 of file MdcTrackList.cxx.

References TrkHotList::begin(), TrkHotList::end(), TrkRecoTrk::fitResult(), TrkRecoTrk::hits(), TrkHitList::hotList(), TrkRecoTrk::printAll(), and MdcTrack::track().

Referenced by createFromSegs().

01073                                                         {
01074   if(NULL == trialTrack) return;
01075   if (!trialTrack->track().fitResult()) return;
01076   /*
01077      double omega,r,pt;
01078      omega =trialTrack->track().fitResult()->helix(0.0).omega();
01079      if (omega == 0) pt = 0;
01080      else pt = (-1) * 1/(omega * 333.576 );
01081      std::cout<<"in MdcTrackList Circle Pt = "<< pt <<std::endl;//yzhang deubg
01082 
01083      if (omega == 0) r=0;
01084      else r = 1/ omega;
01085      std::cout<<"in MdcTrackList Circle R = "<< r <<std::endl;//yzhang deubg 
01086      */
01087   std::cout<<std::endl<< "-------------------------------------"<<std::endl;
01088   std::cout << "Track and hitList after finishCircle" << std::endl;
01089   trialTrack->track().printAll(cout);
01090   TrkHotList::hot_iterator hotIter= trialTrack->track().hits()->hotList().begin();
01091   while (hotIter!=trialTrack->track().hits()->hotList().end()) {
01092     cout <<"(" <<((MdcHit*)(hotIter->hit()))->layernumber()
01093       <<","<<((MdcHit*)(hotIter->hit()))->wirenumber() 
01094       <<":"<<hotIter->isActive()<<")  ";
01095     hotIter++;
01096   }
01097   cout <<endl;
01098   std::cout<< "-------------------------------------"<<std::endl;
01099 }

void MdcTrackList::dumpD0 ( const TrkExchangePar  ) 

Definition at line 1101 of file MdcTrackList.cxx.

References TrkExchangePar::d0().

01101                                                     {
01102   //yzhang hist
01103   //m_hd0->fill(par.d0());
01104   //m_d0 = par.d0();
01105   //  m_tuple1->write();//yzhang hist
01106   std::cout <<std::endl<< " Dump d0()  " << par.d0()<<"\n";//yzhang debug
01107 
01108   //zhangy hist
01109 }

void MdcTrackList::dumpHelix ( const MdcTrack  ) 

Definition at line 1133 of file MdcTrackList.cxx.

References TrkHotList::begin(), TrkHotList::end(), TrkRecoTrk::hits(), TrkHitList::hotList(), TrkRecoTrk::printAll(), and MdcTrack::track().

Referenced by createFromSegs().

01133                                                        { 
01134   std::cout<< std::endl<<"-------------------------------------"<<std::endl;
01135   std::cout<< "Track and hitList after finishHelix " << std::endl;
01136   trialTrack->track().printAll(cout);
01137   TrkHotList::hot_iterator hotIter= trialTrack->track().hits()->hotList().begin();
01138   int tmplay = -1;
01139   while (hotIter!=trialTrack->track().hits()->hotList().end()) {
01140     int layer = ((MdcHit*)(hotIter->hit()))->layernumber();
01141     if( (layer%4) ==0 ) { if( tmplay != layer ) cout<<endl; }
01142     cout <<"(" <<layer <<","<<((MdcHit*)(hotIter->hit()))->wirenumber()
01143       <<":"<<hotIter->isActive() <<")  ";
01144     hotIter++;
01145     tmplay = layer;
01146   }
01147   cout <<endl;
01148   std::cout<< "-------------------------------------"<<std::endl;
01149 }

void MdcTrackList::dumpSeed ( const MdcSeg seed,
bool  goodOnly 
)

Definition at line 1051 of file MdcTrackList.cxx.

References MdcSeg::plotSegAll().

Referenced by createFromSegs().

01051                                                               {
01052   std::cout << std::endl<<"Dump seed segment goodOnly="<<goodOnly<<" ";
01053   seed->plotSegAll();
01054   std::cout<< std::endl;
01055 }

void MdcTrackList::dumpStCombine ( const MdcTrack  ) 

Definition at line 1116 of file MdcTrackList.cxx.

References TrkHotList::begin(), TrkHotList::end(), TrkRecoTrk::hits(), TrkHitList::hotList(), TrkRecoTrk::printAll(), and MdcTrack::track().

Referenced by createFromSegs().

01116                                                             {
01117   std::cout<<std::endl<< "-------------------------------------"<<std::endl;
01118   std::cout<<"Track and hitList after StCombine "<<std::endl;
01119   if(trialTrack)trialTrack->track().printAll(cout);
01120   TrkHotList::hot_iterator hotIter= trialTrack->track().hits()->hotList().begin();
01121   int tmplay = -1;
01122   while (hotIter!=trialTrack->track().hits()->hotList().end()) {
01123     int layer = ((MdcHit*)(hotIter->hit()))->layernumber();
01124     if( (layer%4) ==0 ) { if( tmplay != layer ) cout<<endl; }
01125     cout <<"(" <<layer <<","<<((MdcHit*)(hotIter->hit()))->wirenumber()
01126       <<" act:"<<hotIter->isActive() <<" lr:"<<hotIter->ambig() <<")  ";
01127     hotIter++;
01128     tmplay=layer;
01129   }
01130   cout <<endl;
01131   std::cout<< "-------------------------------------"<<std::endl;
01132 }

void MdcTrackList::dumpStFill (  ) 

Definition at line 1110 of file MdcTrackList.cxx.

01110                               {
01111   std::cout << "Plot segs after st fillWithSegs " << std::endl;
01112   cout <<endl;
01113 
01114 }

int MdcTrackList::finishCircle ( MdcTrack track,
const MdcHitMap ,
const MdcDetector  
)

Definition at line 951 of file MdcTrackList.cxx.

References TrkFitStatus::addHistory(), TrkAbsFit::chisq(), TrkErrCode::fail, TrkErrCode::failure(), TrkHitList::fit(), TrkRecoTrk::fitResult(), g_cirTkChi2, TrkFit::helix(), TrkRecoTrk::hits(), TrkRecoTrk::hots(), MdcTrackParams::lPrint, MdcTrackParams::maxChisq, TrkFit::nActive(), TrkHitList::nHit(), TrkExchangePar::omega(), pickHits(), TrkErrCode::print(), TrkRecoTrk::print(), TrkRecoTrk::printAll(), TrkHotList::printAll(), TrkSimpleMaker< T >::setFlipAndDrop(), TrkRecoTrk::status(), TrkErrCode::succeed, MdcTrackListBase::tkParam, and MdcTrack::track().

Referenced by createFromSegs().

00952                      {
00953   //************************************************************************
00954   TrkRecoTrk& trk = mdcTrk.track();
00955   if(9==tkParam.lPrint){
00956     std::cout << " finishCircle "<< std::endl;
00957     trk.print(std::cout);
00958   }
00959 
00960   const TrkFit* tkFit = trk.fitResult();
00961   if(9==tkParam.lPrint){  cout << "Before circle fit, nactive " << tkFit->nActive() << endl;}
00962   assert (tkFit != 0);
00963   TrkHitList* hitList = trk.hits();
00964   assert (hitList != 0);
00965   TrkCircleMaker circMaker;
00966   circMaker.setFlipAndDrop(trk, false, false);    // reset as a precaution
00967   //circMaker.setFactor(trk, 1.);//nSigma cut factor//yzhang FIXME 2010-09-13 
00968 
00969   TrkErrCode fitResult = hitList->fit();
00970   if (fitResult.failure()) {
00971     trk.status()->addHistory(TrkErrCode(TrkErrCode::fail,15,"finishCircle"),"MdcTrkRecon");
00972     if (tkParam.lPrint > 1) {
00973       cout << "First circle fit failed: " << endl;
00974       fitResult.print(std::cout); 
00975     }
00976     return 0;
00977   }
00978   trk.status()->addHistory(TrkErrCode(TrkErrCode::succeed,15,"finishCircle"),"MdcTrkRecon");
00979 
00980   if(9==tkParam.lPrint){ cout << "After circle fit, nactive " << tkFit->nActive() << endl;}
00981   double chisqperDOF;
00982   int nDOF = tkFit->nActive() - 3;
00983   if (nDOF > 3){
00984     chisqperDOF = tkFit->chisq() / nDOF;
00985   }else{
00986     chisqperDOF = tkFit->chisq();
00987   }
00988 
00989   if(g_cirTkChi2) { g_cirTkChi2->fill( chisqperDOF ); }//yzhang hist cut
00990   int success = (chisqperDOF <= tkParam.maxChisq && tkFit->nActive() >= 3);
00991 
00992   if(9==tkParam.lPrint){
00993     std::cout<<__FILE__<<" "<<__LINE__
00994       << " success "<<success
00995       << " chisqperDOF "<< chisqperDOF<<"<? maxChisq "<< tkParam.maxChisq
00996       << " nAct "<<tkFit->nActive()<<">=3 "
00997       << std::endl;
00998     mdcTrk.track().hots()->printAll(std::cout);
00999   }
01000   bool lcurler(fabs(tkFit->helix(0).omega()) > 3.4);//yzhang FIXME, ??
01001   pickHits(&mdcTrk, map, gm, lcurler);
01002 
01003   if(9==tkParam.lPrint){
01004     std::cout<< __FILE__ << "   " << __LINE__ << " nHit after pickHit  "<<hitList->nHit() <<std::endl;
01005   }
01006   //if(hitList->nHit()<=0) return 0;
01007 
01008   circMaker.setFlipAndDrop(trk, true, true); 
01009   fitResult = hitList->fit();
01010   if (fitResult.failure()) {
01011     if(9==tkParam.lPrint){
01012       cout << "Second circle fit failed: " << endl;
01013       fitResult.print(std::cout); 
01014     }
01015     return 0;
01016   }
01017   if(9==tkParam.lPrint){
01018     cout << "Final fit: " << endl << trk << endl;
01019   }
01020   circMaker.setFlipAndDrop(trk, false, false); 
01021 
01022   nDOF = tkFit->nActive() - 3;
01023   if (nDOF > 3) {
01024     chisqperDOF = tkFit->chisq() / nDOF;
01025   }
01026   else {
01027     chisqperDOF = tkFit->chisq();
01028   }
01029   if(g_cirTkChi2) { g_cirTkChi2->fill( chisqperDOF ); }//yzhang hist cut
01030   success = (chisqperDOF <= tkParam.maxChisq)  && (tkFit->nActive() >= 3);
01031 
01032   if(9==tkParam.lPrint){
01033     cout << "chisqperDOF "<<chisqperDOF<<"=?" << tkParam.maxChisq<< endl;
01034     cout << "nActive "<<tkFit->nActive()<<">= 3"<< endl;
01035   }
01036 
01037   if(9==tkParam.lPrint){
01038     trk.printAll(cout);
01039   }
01040 
01041   return success;
01042 }

int MdcTrackList::finishHelix ( MdcTrack track,
const MdcHitMap ,
const MdcDetector  
)

Definition at line 863 of file MdcTrackList.cxx.

References TrkAbsFit::chisq(), TrkErrCode::failure(), TrkHitList::fit(), TrkRecoTrk::fitResult(), g_3dTkChi2, g_fitNAct, TrkFit::helix(), TrkRecoTrk::hits(), TrkHitList::hotList(), MdcTrackParams::lPrint, m_debug, MdcTrackParams::maxChisq, MdcTrackParams::minHits, TrkFit::nActive(), TrkHitList::nHit(), TrkExchangePar::omega(), pickHits(), TrkAbsFit::positionErr(), TrkErrCode::print(), TrkHotList::printAll(), TrkSimpleMaker< T >::setFlipAndDrop(), TrkErrCode::success(), MdcTrackListBase::tkParam, and MdcTrack::track().

Referenced by createFromSegs().

00864                      {
00865   //***********************************************************************
00866   int success = 1;
00867 
00868   TrkRecoTrk& trk = mdcTrk.track();
00869   TrkErrCode fitResult;
00870   TrkHelixMaker helMaker;
00871   const TrkFit* tkFit = trk.fitResult();
00872   assert (tkFit != 0);
00873   TrkHitList* hitList = trk.hits();
00874   assert (hitList != 0);
00875   TrkExchangePar par = tkFit->helix(0.0);
00876 
00877 
00878   helMaker.setFlipAndDrop(trk, true, true);
00879   fitResult = hitList->fit();
00880 
00881   if (!fitResult.success() && (3 == tkParam.lPrint)) {
00882     cout << "Helix fit failure: " << endl;
00883     fitResult.print(cout); 
00884   }
00885   helMaker.setFlipAndDrop(trk, false, false);
00886 
00887   if (!fitResult.success()) return 0;
00888 
00889   bool lcurler(fabs(tkFit->helix(0).omega()) > 3.4);//yzhang FIXME, ??
00890   pickHits(&mdcTrk, map, gm, lcurler);//yzhang add 2010-05-10 
00891 
00892   if(3==tkParam.lPrint) std::cout<< __FILE__ << "   " << __LINE__ << " nHit after pickHit  "<<hitList->nHit() <<std::endl;
00893   if(3==tkParam.lPrint) hitList->hotList().printAll(std::cout);
00894   //if(hitList->nHit()<=0) return 0;
00895 
00896   helMaker.setFlipAndDrop(trk, true, true); 
00897   fitResult = hitList->fit();
00898   if (fitResult.failure()) {
00899     if(3==tkParam.lPrint){
00900       cout << "Second helix fit failed: " << endl;
00901       fitResult.print(std::cout); 
00902     }
00903     return 0;
00904   }
00905   if(3==tkParam.lPrint){ cout << "Final fit: " << endl << trk << endl; }
00906   helMaker.setFlipAndDrop(trk, false, false); 
00907 
00908   double chisqperDOF = 0.;
00909   int nACT = tkFit->nActive();
00910   int nDOF = nACT - 5;
00911   if (nDOF > 5) {
00912     chisqperDOF = tkFit->chisq() / nDOF;
00913   } else {
00914     chisqperDOF = tkFit->chisq();
00915   }
00916   if(g_3dTkChi2) { g_3dTkChi2->fill( chisqperDOF ); }//yzhang hist cut
00917   if(g_fitNAct) { g_fitNAct->fill(nACT ); }//yzhang hist cut
00918 
00919   int goodMatch = 1;
00920   if (fitResult.failure() || chisqperDOF > tkParam.maxChisq || nACT < tkParam.minHits ) {
00921     goodMatch = 0;
00922     if (3 == tkParam.lPrint) {
00923       std::cout<<" goodMatch=0; chi2/dof "<<chisqperDOF <<" >?maxChisq"<<tkParam.maxChisq 
00924         <<" nAct:"<<nACT <<"<?minHits"<<tkParam.minHits <<  std::endl;
00925     }
00926   }
00927   //yzhang add
00929   //if (tkParam.lUseQualCuts) {
00930   //double tem2 = (float) trk.hits()->nHit() - nACT;
00931   //if (tem2 >= tkParam.maxNmissTrack) goodMatch = 0;
00932   //if (tem2 / float(trk.hits()->nHit()) > tkParam.maxNmissNorm) 
00933   //goodMatch = 0;
00934   //}
00935   //zhangy add
00936 
00937   if (goodMatch) {
00938     if(3 <= m_debug){std::cout<<" ***** finishHelix success!"<<  std::endl;}
00939     trk.fitResult()->positionErr(0.0);
00940   } else { // Not a good match
00941     success = 0;
00942     if(3 <= m_debug){std::cout<<" ***** finishHelix failure!"<<  std::endl;}
00943   }  // end if goodmatch
00944 
00945   return success;
00946 }

void MdcTrackListBase::newParams ( const MdcTrackParams tkPar  )  [inherited]

Definition at line 588 of file MdcTrackListBase.cxx.

References MdcTrackListBase::tkParam.

00588                                                        {
00589   //**************************************************************************
00590   tkParam = tkPar;
00591 }

int MdcTrackListBase::nTrack (  )  const [inline, inherited]

Definition at line 39 of file MdcTrackListBase.h.

Referenced by MdcTrackListBase::arbitrateHits(), MdcTrackListBase::plot(), and MdcTrackListBase::store().

00039 {return length();}

MdcTrackList& MdcTrackList::operator= ( const MdcTrackList  )  [private]

int MdcTrackList::pickHits ( MdcTrack ,
const MdcHitMap ,
const MdcDetector ,
bool  pickAmb = true 
)

Definition at line 295 of file MdcTrackList.cxx.

References abs, alpha, MdcHitOnTrack::ambig(), TrkHitList::appendHot(), TrkHitList::begin(), TrkRecoTrk::bField(), BField::bFieldZ(), Constants::c, cos(), TrkExchangePar::d0(), BesAngle::deg(), MdcHit::digi(), MdcHit::driftDist(), TrkHitList::end(), Constants::epsilon, MdcDetector::firstLayer(), MdcTrack::firstLayer(), TrkRecoTrk::fitResult(), TrkHitOnTrk::fltLen(), g_pickHitWire, TrkFundHit::getHitOnTrack(), RawData::getTrackIndex(), MdcTrack::hasCurled(), haveDigiDrift, TrkFit::helix(), TrkRecoTrk::hits(), MdcHitMap::hitWire(), genRecEmupikp::i, if(), TrkFitStatus::is2d(), ganga-rec::j, MdcDetector::lastLayer(), MdcTrack::lastLayer(), MdcHit::layer(), MdcHit::layernumber(), MdcTrackParams::lPrint, m_pickCurv, m_pickDrift, m_pickDriftCut, m_pickDriftTruth, m_pickIs2D, m_pickLayer, m_pickMcTk, m_pickNCell, m_pickNCellWithDigi, m_pickPhiHighCut, m_pickPhiLowCut, m_pickPhizOk, m_pickPredDrift, m_pickPt, m_pickResid, m_pickSigma, m_pickWire, m_pickZ, m_tuplePick, MdcTrackParams::maxActiveSigma, Constants::maxCell, MdcTrackParams::maxInactiveResid, TrkHitOnTrk::mdcHitOnTrack(), mdcWrapWire(), MdcDetector::nextLayer(), TrkExchangePar::omega(), MdcHit::phi(), TrkExchangePar::phi0(), Constants::pi, MdcTrackParams::pickHitFactor, MdcTrackParams::pickHitFract, MdcTrackParams::pickHitMargin, MdcTrackParams::pickHitPhiFactor, MdcTrackParams::pickSkipExistLayer, MdcTrackParams::pickUitlLastLayer, BesAngle::posRad(), MdcDetector::prevLayer(), MdcHit::print(), MdcTrack::projectToR(), TrkAbsFit::pt(), Constants::radToDegrees, TrkHitList::removeHit(), MdcLayer::rEnd(), MdcLayer::rIn(), MdcLayer::rOut(), TrkHitOnTrk::setActivity(), MdcTrack::setFirstLayer(), TrkHitOnTrk::setFltLen(), MdcTrack::setHasCurled(), MdcTrack::setLastLayer(), TrkHitOnTrk::setUsability(), MdcHit::sigma(), sin(), TrkRecoTrk::status(), TrkExchangePar::tanDip(), MdcTrackListBase::tkParam, MdcTrack::track(), TrkRecoTrk::trackT0(), Constants::twoPi, TrkFundHit::usedHit(), MdcHit::wirenumber(), MdcHit::x(), x, MdcHit::y(), and TrkExchangePar::z0().

Referenced by finishCircle(), and finishHelix().

00296                                         {
00297 
00298   /***************************************************************************/
00299 
00300   // Selects candidate hits along track; 
00301   // sorts them into "active" (small residual) and "inactive" (large resid);
00302   // throws away hits separated from main group by large gaps. //?? FIXME
00303   // pickAm => pick the ambiguity for hits already on track
00304   // Return # of active hits found
00305 
00306   bool is2d = trk->track().status()->is2d();
00307   if(6==tkParam.lPrint){
00308     cout << "Before pickHits";
00309     if (is2d) cout<<" 2d:";
00310     else cout<<" 3d:";
00311     cout<< endl;
00312   }
00313 
00314   int nFound = 0;
00315   int nCand = 0;        // cells tried 
00316   double rMin, rMax;    // min & max search radii for this track
00317   double rEnter, rExit;    // radii at which track enters, exits layer
00318   BesAngle phiEnter, phiExit;//yzhang change
00319   int wireLow, wireHigh;
00320   double phiLow, phiHigh;
00321   int nCell;
00322   MdcHit *thisHit;
00323   HepAList<MdcHitOnTrack> localHistory;    //temporary list of added hits
00324   //until bogus hits are chucked
00325   double cellWidth;
00326   double goodDriftCut;  // missing hits with predDrift > goodDriftCut don't count in figuring gaps
00327   double aresid = 0.;    // = abs(resid)
00328   int firstInputHit = -1; //first hit in firstInputLayer/lastInputLayer region
00329   int lCurl = 0;   // reached curl point
00330 
00331   //****************************************************/
00332   const MdcLayer *firstInputLayer = trk->firstLayer();
00333   const MdcLayer *lastInputLayer = trk->lastLayer();
00334 
00335   double bunchTime = trk->track().trackT0();
00336   const TrkFit* tkFit = trk->track().fitResult();
00337   assert (tkFit != 0);
00338   const TrkFitStatus* tkStatus = trk->track().status();
00339   assert (tkStatus != 0);
00340   TrkHitList* hitList = trk->track().hits();
00341   assert (hitList != 0);
00342   TrkExchangePar par = tkFit->helix(0.0);
00343   double d0 = par.d0();
00344   double curv = 0.5 * par.omega();   
00345   double sinPhi0 = sin(par.phi0());
00346   double cosPhi0 = cos(par.phi0());
00347 
00348   // *** Set min and max radius for track
00349   rMin = gm->firstLayer()->rIn();   
00350   double absd0 = fabs(d0);
00351   if (absd0 > rMin) rMin = absd0 + Constants::epsilon;
00352 
00353   bool willCurl = false;
00354   double rCurl = fabs(d0 + 1./curv);
00355   rMax = gm->lastLayer()->rOut(); 
00356   //std::cout<<  __FILE__ <<"  "<< __LINE__<<" rCurl "<< rCurl <<" rMax "<< rMax << std::endl;
00357   if (rCurl < rMax) {
00358     willCurl = true;
00359     rMax = rCurl - Constants::epsilon;
00360   }
00361   //std::cout<<" willCurl "<< willCurl  << std::endl;
00362   bool reachedLastInput = false;
00363   bool hasCurled = false;  // hit found past curl point
00364 
00365   //yzhang add skip layer with hot, 2011-05-03 
00366   bool isHotOnLayer[43];
00367   if(tkParam.pickSkipExistLayer){
00368     for(int ii=0; ii<43; ii++) isHotOnLayer[ii]=false;
00369     for (TrkHitList::hot_iterator ihit(hitList->begin()); ihit != hitList->end(); ++ihit){
00370       isHotOnLayer[ihit->layerNumber()]=true;
00371     }
00372   }
00373 
00374   // *** Loop through layers in view, looking for the hits
00375   // assumes axial inner
00376   for (const MdcLayer *layer = gm->firstLayer(); layer != 0; 
00377       layer = ((!lCurl) ? ( (hasCurled) ? gm->prevLayer(layer) : 
00378           gm->nextLayer(layer)) : layer) ) {  
00379 
00380 
00381     if (lCurl) {
00382       lCurl = 0;
00383       hasCurled = true;
00384     }
00385     if (tkStatus->is2d() && layer->view() != 0) continue;
00386 
00387     if(tkParam.pickSkipExistLayer &&  isHotOnLayer[layer->layNum()]) continue;//yzhang add 2011-05-03 
00388 
00389     //std::cout<<  __FILE__ <<"  "<< __LINE__  << " lCurl "<< lCurl
00390     //<<" hasCurled "<< hasCurled <<" layer "<< layer->layNum() << std::endl;
00391     bool lContinue = true;
00392     if(tkParam.pickUitlLastLayer) {//yzhang change 2010-09-10 
00393       if (layer == lastInputLayer) reachedLastInput = true; 
00394     }
00395 
00396     // *** Find enter and exit points
00397     if (hasCurled) {
00398       rEnter = layer->rOut();
00399       if (rEnter < rMin) {
00400         //std::cout<<  __FILE__ <<"  "<< __LINE__  
00401         //<<" rEnter<rMin "<<rEnter<<" "<<rMin<< std::endl;
00402         break;
00403       }
00404       rExit = layer->rIn();
00405       if (rExit < rMin) rExit = rMin;
00406       if (rEnter > rMax) rEnter = rMax;
00407 
00408       //std::cout<<  __FILE__ <<" hasCurled: rEnter  "<< rEnter 
00409       //<<" rExit " << rExit << " rMin "<<rMin<<" rMax "<<rMax<< std::endl;
00410     } else {
00411       rEnter = layer->rIn();
00412       rExit = layer->rOut();
00413       //std::cout<<  __FILE__ <<" NOT hasCurled: rEnter  "<< rEnter 
00414       //<<" rExit " << rExit << " rMin "<<rMin<<" rMax "<<rMax<< std::endl;
00415       if (rExit < rMin) continue;
00416 
00417       if (willCurl) {
00418         if (rEnter > rMax) {
00419           //std::cout<<  __FILE__<<" Reached curl point before entering layer"<< std::endl;
00420           // Reached curl point before entering layer
00421           hasCurled = 1;
00422           continue;
00423         }
00424         if (rExit > rMax) {
00425           lCurl = 1;
00426           rExit = rMax;
00427         }
00428       } else {  // not a potential curler
00429         //std::cout<<  __FILE__ <<"  "<< __LINE__  <<" not a potential curler"<< std::endl;
00430         if (rEnter > rMax) {
00431           //std::cout<<  __FILE__ <<" rEnter> rMax "<< rEnter << std::endl;
00432           break;
00433         }
00434         if (rExit > rMax) rExit = rMax;
00435       }
00436     }  // end if curled already
00437 
00438     nCell = layer->nWires();
00439     cellWidth = Constants::twoPi * layer->rMid() / nCell;//??
00440     // don't count outer xmm of cell
00441     goodDriftCut = 0.5 * cellWidth * M_SQRT2 + tkParam.pickHitMargin;  
00442     //goodDriftCut = 0.5 * cellWidth - tkParam.pickHitMargin;//yzhang change 2012-08-17 
00443     double deltaPhiCellWidth = 0.5 * (cellWidth * M_SQRT2)/layer->rMid(); 
00444 
00445     //**** Find entrance and exit phi's
00446     BesAngle phiTemp(0.0);
00447     int ierror = trk->projectToR(rEnter, phiTemp, hasCurled);
00448     phiEnter = phiTemp.posRad();
00449     if (ierror != 0) {
00450       if(6==tkParam.lPrint) std::cout<< " ErrMsg(warning) " 
00451         << "Error in MdcTrackList::pickHits projection, ierror " <<ierror<< std::endl;
00452       continue;//yzhang 2011-04-14 
00453     }
00454     ierror = trk->projectToR(rExit, phiTemp, hasCurled);
00455     phiExit = phiTemp.posRad();
00456     if (ierror != 0) {
00457       if(6==tkParam.lPrint) std::cout<< " ErrMsg(warning) " 
00458         << "Error in MdcTrackList::pickHits projection, ierror "<<ierror << std::endl;
00459       continue;//yzhang 2011-04-14 
00460     }
00461 
00462 
00463     if(6==tkParam.lPrint){
00464       std::cout<< endl<<"--pickHit of layer "<<layer->layNum()<<"--"<<std::endl;
00465       std::cout<< "  track phiEnter "<< phiEnter.deg()<<" phiExit "<<phiExit.deg()<<" degree"<< std::endl;
00466       std::cout<< "  cell width "<< 360./layer->nWires()<<" dPhiz "<<layer->dPhiz()*Constants::radToDegrees <<" deltaPhiCellWidth "<<0.5 * (cellWidth * M_SQRT2)/layer->rMid() * Constants::radToDegrees<<std::endl;
00467       std::cout<< "  maxInactiveResid "<< tkParam.maxInactiveResid <<" pickHitPhiFactor "<<tkParam.pickHitPhiFactor<< std::endl;
00468       std::cout<< "  goodDriftCut "<< goodDriftCut <<"=sqrt(2)*0.5*"<<cellWidth<<"+"<<tkParam.pickHitMargin<< std::endl;
00469     }
00470 
00471     double Bz = trk->track().bField().bFieldZ();
00472     //std::cout<<  " facotr "<<tkParam.pickHitPhiFactor<< " dPhiz "<<layer->dPhiz()
00473     //<< " factor*dPhiz "<<layer->dPhiz()*tkParam.pickHitPhiFactor<< std::endl;
00474     double t_phiHit = -999.;
00475     if (curv*Bz <= 0.0) {
00476       //positive track in minus Bz
00477       phiLow = phiEnter;
00478       phiHigh = phiExit;
00479       // Allow some slop in phi
00480       phiLow -= tkParam.maxInactiveResid / rEnter;
00481       phiHigh += tkParam.maxInactiveResid / rExit;
00482     } else {
00483       phiLow = phiExit;
00484       phiHigh = phiEnter;
00485       phiLow -= tkParam.maxInactiveResid / rExit;
00486       phiHigh += tkParam.maxInactiveResid / rEnter;
00487     }   
00488     //yzhang fix cross x axis bug 2011-04-10 
00489     if((phiHigh>0 && phiLow<0)){
00490       phiLow += Constants::twoPi;
00491     }else if((phiHigh<0 && phiLow>0)){
00492       phiHigh += Constants::twoPi;
00493     }
00494 
00495     double lowFloat = nCell /Constants::twoPi * (phiLow - layer->phiOffset()) + 0.5;
00496     double highFloat = nCell /Constants::twoPi * (phiHigh  - layer->phiOffset()) + 0.5;
00497     wireLow = (lowFloat >= 0.0) ? int(lowFloat) : int(floor(lowFloat));
00498     wireHigh = (highFloat >= 0.0) ? int(highFloat) : int(floor(highFloat));
00499 
00500     if(6==tkParam.lPrint){
00501       std::cout << "  wireLow "<<wireLow << " wireHigh "<<wireHigh <<" phiLow "<<phiLow*180./Constants::pi << " phiHigh "<<phiHigh*180./Constants::pi <<  std::endl;
00502     }
00503     // *** Loop through the predicted hit wires
00504     int tempDiff = 0;
00505     if(g_pickHitWire) { 
00506       int tempN = Constants::maxCell[layer->layNum()];
00507       if(wireLow>tempN/2. && wireHigh<tempN/2.){
00508         g_pickHitWire->fill(wireHigh+tempN - wireLow); 
00509         tempDiff = wireHigh+tempN - wireLow +1;
00510       }else{
00511         g_pickHitWire->fill(wireHigh - wireLow); 
00512         tempDiff = wireHigh - wireLow +1;
00513       }
00514     }//yzhang hist cut
00515 
00516     if(wireLow>wireHigh) wireLow -= nCell;//yzhang 2011-05-16 
00517     long t_iHit = 0;
00518     for (int thisWire = wireLow; thisWire <= wireHigh; thisWire++) {
00519       int corrWire = mdcWrapWire(thisWire, nCell);
00520       thisHit = map->hitWire(layer->layNum(), corrWire);
00521 
00522       if(6==tkParam.lPrint){
00523         if(thisHit != 0) {cout<<endl<<"test hit "; thisHit->print(std::cout);}
00524         else std::cout << endl<<"test hit ("<<layer->layNum()<<","<<corrWire<<")"<< std::endl;
00525       }
00526 
00527       double tof = 0.;
00528       double z = 0.;
00529       double driftDist = 0.;
00530       // Calculate expected drift distance
00531       double delx, dely;
00532       double resid = 0., predDrift = 0.;
00533       int ambig = 0;
00534       const MdcHitOnTrack *alink = 0;
00535       double mcTkId = -9999; //yzhang for tuple 2011-06-28 
00536       if (thisHit == 0 ) {
00537         delx = -d0 * sinPhi0 - layer->xWire(corrWire);
00538         dely =  d0 * cosPhi0 - layer->yWire(corrWire);
00539         predDrift = cosPhi0 * dely - sinPhi0 * delx + 
00540           curv * (delx * delx + dely * dely);
00541         if(6==tkParam.lPrint) cout<<"No hit. predDrift="<<predDrift<<endl;
00542         continue;
00543       } else {  
00544         if(m_tuplePick) mcTkId = thisHit->digi()->getTrackIndex();
00545         // look for existing hit
00546         if(thisHit->getHitOnTrack(&(trk->track())) ==0){
00547           alink = 0;//yzhang temp
00548         }else{
00549           alink = thisHit->getHitOnTrack(&(trk->track()))->mdcHitOnTrack();//yzhang temp
00550           if(6==tkParam.lPrint) { cout << " existing hot; " ;}
00551         }
00552 
00553         if (alink == 0 || pickAm) {
00554           if ((!tkStatus->is2d()) && layer->view() != 0){
00555             double rc = 9999.;
00556             if(fabs(par.omega())>Constants::epsilon) rc = 1./fabs(par.omega());
00557             double rw = layer->rMid();
00558             double alpha = acos(1 - rw*rw/(2*rc*rc));
00559             double fltLen = rw;
00560             if(fabs(1 - rw*rw/(2*rc*rc))<1) fltLen = rc * alpha;
00561             z = par.z0() + fltLen* par.tanDip();
00562             tof = fltLen / Constants::c;
00563             double x = layer->getWire(corrWire)->xWireDC(z);
00564             double y = layer->getWire(corrWire)->yWireDC(z);
00565             delx = -d0 * sinPhi0 - x;
00566             dely =  d0 * cosPhi0 - y;
00567             if(m_tuplePick) t_phiHit = thisHit->phi(z);
00568           }else{
00569             delx = -d0 * sinPhi0 - thisHit->x();
00570             dely =  d0 * cosPhi0 - thisHit->y();
00571             if(m_tuplePick) t_phiHit = thisHit->phi();
00572           }
00573           predDrift = cosPhi0 * dely - sinPhi0 * delx + 
00574             curv * (delx * delx + dely * dely);
00575 
00576           // predDrift = predDrift * (1. - curv() * predDrift);
00577           ambig = (predDrift >= 0) ? 1 : -1;
00578           if (hasCurled) ambig = -ambig;
00579           double entranceAngle=0.;
00580           driftDist = thisHit->driftDist(tof+bunchTime,ambig,entranceAngle,0.,z);
00581           if (alink == 0) {
00582             // FIXME: is this ambig here VVVVV OK for incoming tracks?
00583             resid = ambig * fabs(driftDist) - predDrift;
00584             aresid = fabs(resid);
00585             //if (aresid > tkParam.maxInactiveResid ) ambig = 0;//yzhang delete 2012-10-09
00586           }
00587         } else {
00588           ambig = alink->ambig();
00589           if(6==tkParam.lPrint) cout << " pick ambig for hot"<<endl;
00590           if(m_tuplePick) t_phiHit = par.phi0()+par.omega()*alink->fltLen();
00591         }
00592       }
00593 
00594       //yzhang 2012-08-20 , guess phi of this hit on z
00595       double zGuess = par.z0() + layer->rMid() * par.tanDip();
00596       double phiDCz = layer->getWire(corrWire)->phiDC(zGuess);
00597       BesAngle phiDCzMax(phiDCz + deltaPhiCellWidth);
00598       BesAngle phiDCzMin(phiDCz - deltaPhiCellWidth);
00599 
00600       if(m_tuplePick && alink==0) {
00601         double sigma = 999.;
00602         if (thisHit != 0 &&alink==0) {
00603           double entranceAngle = 0.;
00604           sigma = thisHit->sigma(driftDist, ambig, entranceAngle, atan(par.tanDip()), z);
00605         }
00606         m_pickPredDrift[t_iHit] = predDrift;
00607         m_pickDrift[t_iHit] = driftDist;
00608         m_pickDriftTruth[t_iHit] = haveDigiDrift[thisHit->layernumber()][thisHit->wirenumber()];
00609         if(curv*Bz<=0.){
00610           //positive track under minus Bz
00611           if((phiDCzMin-phiExit>0) || (phiDCzMax-phiEnter<0)) m_pickPhizOk[t_iHit] = 0;
00612           else m_pickPhizOk[t_iHit] = 1;
00613         }else{
00614           if((phiDCzMin-phiEnter>0) || (phiDCzMax-phiExit<0)) m_pickPhizOk[t_iHit] = 0;
00615           else m_pickPhizOk[t_iHit] = 1;
00616         }
00617         m_pickZ[t_iHit] = z;
00618         m_pickWire[t_iHit]=thisHit->wirenumber();
00619         m_pickResid[t_iHit] = aresid;
00620         if(abs(sigma)>0.000001)  m_pickSigma[t_iHit] = sigma;
00621         else m_pickSigma[t_iHit] = 999.;
00622         double t_phiLowCut=-999.;
00623         double t_phiHighCut= -999.;
00624         if(t_phiHit > -998.){
00625           t_phiLowCut = (phiEnter-t_phiHit)*rEnter;
00626           t_phiHighCut = (phiExit-t_phiHit)*rExit;
00627         }
00628         m_pickPhiLowCut[t_iHit] = t_phiLowCut;
00629         m_pickPhiHighCut[t_iHit] = t_phiHighCut;
00630         m_pickDriftCut[t_iHit] = goodDriftCut;
00631         m_pickMcTk[t_iHit] = mcTkId;
00632         m_pickPt[t_iHit] = tkFit->pt();
00633         m_pickCurv[t_iHit] = curv;
00634         t_iHit++;
00635       }
00636 
00637       if(curv*Bz<=0.){
00638         //positive track
00639         if((phiDCzMin-phiExit>0) || (phiDCzMax-phiEnter<0)) {
00640           if(6==tkParam.lPrint){ std::cout<<" CUT by phiDCz not in phi En Ex range, curv>=0"<<std::endl; }
00641           continue;
00642         }
00643       }else{
00644         //negtive track
00645         if((phiDCzMin-phiEnter>0) || (phiDCzMax-phiExit<0)) {
00646           if(6==tkParam.lPrint){ std::cout<<" CUT by phiDCz not in phi En Ex range, curv<0"<<std::endl; }
00647           continue;
00648         }
00649       }
00650 
00651       // Cases
00652       // (0) pred drift dist > goodDriftCut, drop Hit
00653       if (ambig != 0 && fabs(predDrift) > goodDriftCut){//yzhang add 2012-08-17 
00654         if(6==tkParam.lPrint){cout<<" predDrift "<<predDrift<<">goodDriftCut "<<goodDriftCut<<endl;}
00655         continue;
00656       }
00657 
00658       // (1) No good hit, but track near cell-edge => do nothing and continue
00659       if (ambig == 0 && fabs(predDrift) > goodDriftCut){//yzhang 2009-11-03 add 3factor, 2011-05-30 from 3 to 2,2012-08-17 from 2 to 1
00660         if(6==tkParam.lPrint){
00661           cout<<"   ambig==0 && |predDirft| "<<fabs(predDrift) <<"> goodDriftCut "<< goodDriftCut<<endl;
00662           cout<<" No good hit, but track near cell-edge " <<  endl;
00663         }
00664         continue;
00665       }
00666 
00667 
00668       // (2) Hit found: 
00669       if (ambig != 0) {
00670         //yzhang changed 2009-10-19
00671         //if resid> maxActiveSimga * sigma do not add hits to track
00672         double entranceAngle = 0.;
00673         double sigma = thisHit->sigma(driftDist, ambig, entranceAngle, atan(par.tanDip()), z);
00674         double factor = tkParam.pickHitFactor;
00675         //yzhang delete 2012-10-09 
00676         //if(!is2d fabs(par.tanDip())<2) factor = (2-par.tanDip())/2 * factor;
00677         double residCut = tkParam.maxActiveSigma * factor * sigma;//yzhang 2012-08-21 
00678         //if(6==tkParam.lPrint){
00679           //std::cout<< "aresid "<<aresid<<" residCut "<<residCut<<" sigma "<<sigma <<" tanDip "<< par.tanDip() <<" factor "<<factor <<" tkParam.maxActiveSigma "<<tkParam.maxActiveSigma<<std::endl;
00680         //}
00681 
00682         if (alink == 0 && (aresid <= residCut) ) {
00683           if(6==tkParam.lPrint){
00684             cout << " (2) New hit found " <<  endl;//yzhang debug
00685           }
00686           //yzhang 2012-08-17 delete
00687           int isActive = 1;
00688           //if (aresid > residCut) isActive = 0;
00689           //if(6==tkParam.lPrint) {
00690           //  if (aresid > residCut)
00691           //    std::cout << "notACT, resid  "<<aresid<<" >residCut " << residCut<< std::endl;
00692           //}
00693           MdcRecoHitOnTrack tempHot(*thisHit, ambig, bunchTime);
00694           tempHot.setActivity(isActive);
00695           // Don't add active hits if they're in use.
00696           if (thisHit->usedHit()){
00697             tempHot.setUsability(false);
00698             if(6==tkParam.lPrint) std::cout<<   " thisHit used, setUsability false "   << std::endl;
00699           }
00700           // very crude starting point for flight length !!!! improve
00701           double flt = layer->rMid();
00702           if (hasCurled) flt = Constants::twoPi * rCurl - layer->rMid();
00703           flt += 0.000001 * (thisHit->x() + thisHit->y());
00704           tempHot.setFltLen(flt);
00705           if(6==tkParam.lPrint) {
00706             std::cout<< " aresid  "<<aresid<<"<=residCut " <<residCut<<" nSig "<<aresid/sigma<< " nSigCut "<<(tkParam.maxActiveSigma*factor)<<" factor "<<factor<<" maxActiveSigma "<<tkParam.maxActiveSigma<<" tanDip "<<par.tanDip()<<std::endl;
00707             std::cout<< " Append Hot  "   << std::endl;
00708           }
00709           alink = (MdcHitOnTrack*) hitList->appendHot(&tempHot);
00710         }else{
00711           if(6==tkParam.lPrint){
00712             if(alink!=0){  
00713               std::cout<< "Exist hot found"<<std::endl;
00714             }else if(aresid > residCut){
00715               thisHit->print(std::cout);
00716             std::cout<< " Drop hit. aresid  "<<aresid<<">residCut " <<residCut<<" nSig "<<aresid/sigma<< " nSigCut "<<(tkParam.maxActiveSigma*factor)<<" factor "<<factor<<" maxActiveSigma "<<tkParam.maxActiveSigma<<" tanDip "<<par.tanDip()<<std::endl;
00717             }
00718           }
00719         }
00720         if (!localHistory.member(const_cast<MdcHitOnTrack*>(alink))) {
00721           localHistory.append(const_cast<MdcHitOnTrack*>(alink));
00722           if (hasCurled) trk->setHasCurled();
00723           nFound++;
00724           if(6==tkParam.lPrint) std::cout<<" nFound="<<nFound<<" nCand "<<nCand<<std::endl;
00725           if (layer == firstInputLayer && firstInputHit < 0) {
00726             firstInputHit = nCand;      
00727           }
00728         } else {
00729           if(6==tkParam.lPrint) std::cout << "ErrMsg(warning) "<< "would have inserted identical HOT "
00730             "twice in history buffer" << std::endl;
00731         }
00732       }
00733 
00734       // (3) No hit found; if beyond known good region, should we continue?
00735       else if (ambig == 0 && reachedLastInput) {
00736         if(6==tkParam.lPrint) std::cout << "ambig==0 "<<std::endl;
00737         lContinue = false;
00738         int nSuccess = 0;
00739         int last = 8;
00740         if (nCand < 8) last = nCand;
00741         for (int i = 0; i < last; i++) {
00742           int j = nCand - 1 - i;
00743           if (localHistory[j] != 0) {
00744             //std::cout<<  __FILE__ <<" localHistory["<<j<<"]!=0 nSuccess++ "<<  std::endl;
00745             nSuccess++;
00746           }
00747           if (i == 2 && nSuccess >= 2) lContinue = true;
00748           if (i == 4 && nSuccess >= 3) lContinue = true;
00749           if (i == 7 && nSuccess >= 5) lContinue = true;
00750           if(6==tkParam.lPrint) cout <<i<< "  (3) No hit found; if beyond known good region " <<  endl;//yzhang debug
00751           if (lContinue) {
00752             if(6==tkParam.lPrint) std::cout<<" pickHits break by lContinue. i="<<i<<" nSuccess="<<nSuccess<< std::endl;
00753             break;
00754           }
00755         }  
00756 
00757         if(6==tkParam.lPrint) cout << "  (3) No hit found; if beyond known good region " <<  endl;//yzhang debug
00758         // if lContinue == false => there's been a gap, so quit
00759         if (!lContinue) {
00760           //std::cout<<  __FILE__ <<"  "<< __LINE__  <<" break by !lContinue "<< std::endl;
00761           break;
00762         }
00763         localHistory.append(0);
00764       } 
00765 
00766       nCand++;    
00767       // Update last layer:
00768       if (ambig != 0 && reachedLastInput) {
00769         if (trk->hasCurled() == 0) {
00770           if (thisHit->layer()->rEnd() > trk->lastLayer()->rEnd()) {
00771             trk->setLastLayer(thisHit->layer());
00772           }
00773         }
00774         else {
00775           if (thisHit->layer()->rEnd() < trk->lastLayer()->rEnd()) {
00776             trk->setLastLayer(thisHit->layer());
00777           }
00778         }
00779       }
00780 
00781     }  // end loop over hit wires
00782     if(t_iHit>0 && m_tuplePick) {
00783       m_pickNCell = tempDiff;
00784       m_pickNCellWithDigi = t_iHit;
00785       m_pickLayer = layer->layNum();
00786       m_pickIs2D = is2d;
00787       m_tuplePick->write();
00788     }
00789     if (!lContinue && reachedLastInput) {
00790       //std::cout<<  __FILE__ <<" break by !lContinue && reachedLastInput "<< std::endl;
00791       break;
00792     }
00793   }  // end loop over layers
00794 
00795   // Now look back at hits in early layer and see if there are any to be thrown away there.  
00796   bool lContinue = true;
00797   for (int ihit = firstInputHit; ihit >= 0; ihit--) {
00798     if (localHistory[ihit] != 0) {
00799       if (lContinue) {
00800         // Update firstLayer
00801         const MdcHitOnTrack *mdcHit = localHistory[ihit]->mdcHitOnTrack();
00802         if (mdcHit != 0) {
00803           if (mdcHit->layer()->rEnd() < trk->firstLayer()->rEnd()) {
00804             trk->setFirstLayer(mdcHit->layer());        
00805           }
00806         }
00807         continue;          // no gap yet
00808       } else { 
00809         // gap found; delete hits
00810         if(6==tkParam.lPrint){
00811           std::cout << " gap found; delete hits. ";
00812         }
00813         if (!localHistory[ihit]->isUsable()) {
00814           if(6==tkParam.lPrint){
00815             cout << "about to delete hit for unusable HOT:" << endl;
00816             localHistory[ihit]->print(std::cout);
00817           }
00818           hitList->removeHit(localHistory[ihit]->hit());   
00819         }
00820         if(6==tkParam.lPrint){
00821           cout << " current contents of localHistory: "
00822             <<localHistory.length()<<"hot" << endl;
00823           //for (int i=0; i<localHistory.length();++i) {
00824           //cout << " hit @ " << localHistory[i]->hit() << "; hot @ " << localHistory[i] << endl;
00825           //}
00826         }
00827         nFound--;
00828       }
00829     }
00830     else if (localHistory[ihit] == 0) {
00831       if(6==tkParam.lPrint){ cout << " localHistory= 0 " << endl; }
00832       int nSuccess = 0;
00833       lContinue = false;
00834       int last = 8;
00835       if (nCand < 8) last = nCand;
00836       for (int i = 0; i < last; i++) {
00837         int j = ihit + 1 + i;
00838         if (localHistory[j] != 0) nSuccess++;
00839         if (i == 2 && nSuccess >= 2) lContinue = true;
00840         if (i == 4 && nSuccess >= 3) lContinue = true;
00841         //      if (i == 7 && nSuccess >= 5) lContinue = true;
00842         if (lContinue) break;
00843       }
00844     }
00845   }
00846   if(6==tkParam.lPrint){ 
00847     std::cout<<  "nFound="<<nFound <<" < "<< tkParam.pickHitFract*nCand<<" pickHitFract? "<< tkParam.pickHitFract<<"*"<<nCand  << std::endl;
00848   }
00849   if (nFound < tkParam.pickHitFract * nCand) nFound = 0;//yzhang delete 2010-05-10 use pickHitFract=0.
00850   if(6==tkParam.lPrint){ cout << " localHistory= 0 " << endl; }
00851 
00852   if(6==tkParam.lPrint || 3==tkParam.lPrint){
00853     cout << "After pickHits found " << nFound <<" hit(s)"<< endl;
00854     hitList->hotList().print(std::cout);
00855     std::cout<< std::endl;
00856   }
00857 
00858   return nFound;
00859 }

void MdcTrackListBase::plot (  )  const [inherited]

Definition at line 92 of file MdcTrackListBase.cxx.

References MdcTrackListBase::nTrack().

00092                              {
00093   //*************************************************************************
00094   std::cout<< "nTrack   "<<nTrack() << std::endl;//yzhang debug
00095   for (int itrack = 0; itrack < nTrack(); itrack++) {
00096     MdcTrack *atrack = (*this)[itrack];
00097     if (atrack == NULL) continue;
00098     atrack->track().printAll(cout);
00099   }
00100 }

void MdcTrackListBase::remove ( MdcTrack atrack  )  [inherited]

Reimplemented in MdcTrackListCsmc.

Definition at line 595 of file MdcTrackListBase.cxx.

00595                                            {
00596   //--------------------------------------------------------------------
00597   if (atrack != 0) {
00598     HepAList<MdcTrack>::remove( atrack );
00599     delete atrack;
00600   }
00601 }

void MdcTrackListBase::setD0Cut ( double  d0Cut  )  [inline, inherited]

Definition at line 57 of file MdcTrackListBase.h.

References MdcTrackListBase::m_d0Cut.

00057 {m_d0Cut = d0Cut;}//yzhang add 

void MdcTrackListBase::setPlot ( int  plotFlag  )  [inline, inherited]

Definition at line 40 of file MdcTrackListBase.h.

References MdcTrackParams::lPlot, and MdcTrackListBase::tkParam.

00040 { tkParam.lPlot = plotFlag;};

void MdcTrackListBase::setPtCut ( double  ptCut  )  [inline, inherited]

Definition at line 59 of file MdcTrackListBase.h.

References MdcTrackListBase::m_ptCut.

00059 {m_ptCut = ptCut;}//yzhang add 2009-10-27

void MdcTrackListBase::setZ0Cut ( double  z0Cut  )  [inline, inherited]

Definition at line 58 of file MdcTrackListBase.h.

References MdcTrackListBase::m_z0Cut.

00058 {m_z0Cut = z0Cut;}//yzhang add 2010-05-21 

void MdcTrackListBase::store ( RecMdcTrackCol ,
RecMdcHitCol  
) [inherited]

Definition at line 75 of file MdcTrackListBase.cxx.

References MdcTrackListBase::nTrack().

00075                                                                         {
00076   // ***********************************************************************
00077   int trackId = 0;
00078   for (int itrack = 0; itrack < nTrack(); itrack++) {
00079     MdcTrack* track = (*this)[itrack];
00080     //tkStat:  0,PatRec 1,MdcxReco 2,Tsf 3,CurlFinder
00081     int tkStat = 0;
00082     track->storeTrack(trackId, trackList, hitList, tkStat);
00083     ++trackId;
00084   }
00085   HepAListDeleteAll(*this);   // Discard the husks
00086   removeAll(); 
00087   return;
00088 }


Member Data Documentation

double MdcTrackListBase::m_d0Cut = -999. [static, inherited]

Definition at line 60 of file MdcTrackListBase.h.

Referenced by createFromSegs(), MdcTrkRecon::initialize(), and MdcTrackListBase::setD0Cut().

int MdcTrackList::m_debug [private]

Definition at line 61 of file MdcTrackList.h.

Referenced by createFromSegs(), and finishHelix().

double MdcTrackListBase::m_ptCut = -999. [static, inherited]

Definition at line 62 of file MdcTrackListBase.h.

Referenced by createFromSegs(), MdcTrkRecon::initialize(), and MdcTrackListBase::setPtCut().

double MdcTrackListBase::m_z0Cut = -999. [static, inherited]

Definition at line 61 of file MdcTrackListBase.h.

Referenced by createFromSegs(), MdcTrkRecon::initialize(), and MdcTrackListBase::setZ0Cut().

MdcTrackParams MdcTrackListBase::tkParam [protected, inherited]

Definition at line 72 of file MdcTrackListBase.h.

Referenced by MdcTrackListBase::arbitrateHits(), MdcTrackListCsmc::createFromSegs(), createFromSegs(), MdcTrackListCsmc::finish3d(), finishCircle(), finishHelix(), MdcTrackListBase::MdcTrackListBase(), MdcTrackListBase::newParams(), pickHits(), and MdcTrackListBase::setPlot().


Generated on Tue Nov 29 23:20:18 2016 for BOSS_7.0.2 by  doxygen 1.4.7