/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/MdcPatRec/MdcTrkRecon/MdcTrkRecon-00-03-45/src/MdcSegGrouperSt.cxx

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: MdcSegGrouperSt.cxx,v 1.14 2011/09/26 01:06:37 zhangy Exp $
00004 //
00005 // Description:
00006 //     
00007 //
00008 // Environment:
00009 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00010 //
00011 // Authors:
00012 //      Zhang Yao(zhangyao@ihep.ac.cn)  Migrate to BESIII
00013 //
00014 // Copyright (C)  1996  The Board of Trustees of  
00015 // The Leland Stanford Junior University.  All Rights Reserved.
00016 //------------------------------------------------------------------------
00017 #include "MdcGeom/BesAngle.h"
00018 #include "MdcData/MdcHit.h"
00019 #include "CLHEP/Alist/AList.h" 
00020 #include "MdcGeom/MdcDetector.h"
00021 #include "MdcGeom/MdcSuperLayer.h"
00022 #include "MdcTrkRecon/MdcSeg.h"
00023 #include "MdcTrkRecon/MdcSegGrouperSt.h"
00024 #include "MdcTrkRecon/MdcSegList.h"
00025 #include "MdcTrkRecon/MdcSegInfoSterO.h"
00026 #include "MdcTrkRecon/MdcSegWorks.h"
00027 #include "MdcTrkRecon/MdcSegUsage.h"
00028 #include "MdcTrkRecon/MdcTrack.h"
00029 #include "MdcTrkRecon/GmsList.h"
00030 #include "TrkBase/TrkExchangePar.h"
00031 #include "TrkBase/TrkRecoTrk.h"
00032 #include "TrkBase/TrkFit.h"
00033 #include "TrkFitter/TrkHelixMaker.h"
00034 
00035 //yzhang hist cut
00036 #include "AIDA/IHistogram1D.h"
00037 extern AIDA::IHistogram1D*  g_z0Cut;
00038 extern AIDA::IHistogram1D*  g_ctCut;
00039 extern AIDA::IHistogram1D*  g_delCt;
00040 extern AIDA::IHistogram1D*  g_delZ0;
00041 //zhangy hist cut
00042 
00043 //Constructor
00044 //------------------------------------------------------------------------
00045 MdcSegGrouperSt::MdcSegGrouperSt(const MdcDetector *gm, int debug) : 
00046   MdcSegGrouper(gm, gm->nStereoSuper(-1) + gm->nStereoSuper(1), debug) {
00047 //------------------------------------------------------------------------
00048 
00049     lTestGroup = true;
00050     lTestSingle = false;
00051 
00052     isValid = new bool * [nPly()];
00053     for (int j = 0; j < nPly(); j++) {
00054       isValid[j] = 0;
00055     }
00056   }
00057 
00058 //------------------------------------------------------------------------
00059 void MdcSegGrouperSt::resetList() {
00060 //------------------------------------------------------------------------
00061   // Clear existing lists for stereo finding
00062   int nsuper = _gm->nSuper();
00063   for (int i = 0; i < nsuper; i++) {
00064     segList[i].removeAll();
00065   }
00066 }
00067 
00068 //------------------------------------------------------------------------
00069 void MdcSegGrouperSt::fillWithSegs(const MdcSegList *inSegs, 
00070     const MdcTrack *track) {
00071   //------------------------------------------------------------------------
00072   // Prepare for stereo finding 
00073   // Load segments consistent with input track (already in phi order)
00074   //  Assuming from origin
00075   int nsuper = _gm->nSuper();
00076   resetList();    // Clear existing lists 
00077   if(3==_debug) std::cout<<std::endl<< "=====MdcSegGrouperSt::fillWithSegs====="<<std::endl;
00078 
00079   const TrkFit* tkFit = track->track().fitResult();
00080   if (tkFit == 0) return;
00081   TrkExchangePar par = tkFit->helix(0.0);
00082   double kap = 0.5 * par.omega();
00083   double phi0 = par.phi0();
00084   double d0 = par.d0();
00085   MdcSegWorks segStuff;   // holds some calculated values to pass to segInfo
00086 
00087   bool lStraight = false;
00088   if (fabs(kap) < 1.e-9) { lStraight = true; }
00089 
00090   double rCurl = 99999999.;
00091   if (!lStraight) {
00092     rCurl = fabs(d0 + 1./kap);
00093   }
00094 
00095   // Create an info object to store the info (will be owned by seg)
00096   MdcSegInfoSterO *info = new MdcSegInfoSterO;
00097 
00098   // Loop over superlayers
00099   for (int isuper = 0; isuper < nsuper; isuper++) {
00100     const GmsList *inList = inSegs->oneList(isuper);
00101 
00102     if (inList->count() == 0) continue;
00103 
00104     MdcSeg *inSeg = (MdcSeg *) inList->first();
00105     // Only load stereo segments
00106     if (inSeg->superlayer()->whichView() == 0) continue;
00107 
00108     // Calculate r & phi (approx) of axial track at slayer
00109     double radius = inSeg->superlayer()->rEnd();  
00110     if (radius >= rCurl) break;
00111     double phiArg = kap * radius;
00112     if (lStraight) phiArg = d0 / radius;
00113     if (phiArg < -1.0) phiArg = -1.0;
00114     else if (phiArg > 1.0) phiArg = 1.0;
00115     segStuff.phiArg = phiArg;
00116     segStuff.phiAx.setRad(phi0 + asin(phiArg));  // Approx??!!!!
00117     BesAngle delPhi( fabs(inSeg->superlayer()->delPhi()) );
00118     //BesAngle maxPhiA = segStuff.phiAx + delPhi + 0.05;  // allow a little slop
00119     //BesAngle minPhiA = segStuff.phiAx - delPhi - 0.05;
00120     BesAngle maxPhiA = segStuff.phiAx + delPhi + 0.1;  // allow a little slop yzhang 2011-06-15 
00121     BesAngle minPhiA = segStuff.phiAx - delPhi - 0.1;//yzhang TEMP 2011-06-15 
00122     //yzhang FIXME
00123     double maxPhi = maxPhiA;
00124     double minPhi = minPhiA;
00125     bool phitest = (maxPhi > minPhi);
00126     //phitest = false => the valid range straddles phi = 0, so skip 
00127     //checking against phimin and phimax
00128 
00129     //Calc some things needed in segInfo::calcStereo
00130     segStuff.wirLen2inv = 1./ (inSeg->superlayer()->zEnd() * 
00131         inSeg->superlayer()->zEnd() );
00132     // Loop over segs in superlayer
00133     if(_debug==3) std::cout<<std::endl<<"Pick segment by phi from " <<minPhi<< " to "<<maxPhi<<" phiAx="<<segStuff.phiAx<<" delPhi="<<delPhi<<std::endl;
00134     for ( ; inSeg != 0; inSeg = (MdcSeg *) inSeg->next()) {
00135       // Test if within allowed phi range
00136       BesAngle phiSeg(inSeg->phi()); 
00137 
00138       if(_debug==3){ inSeg->plotSeg(); }
00139       if (phitest) {
00140         if (phiSeg < minPhi){
00141           if (_debug ==3){std::cout << " CUT by phi "<<phiSeg
00142             << "<min "<<minPhi << std::endl;}//yzhang debug     
00143           continue;  // not up to candidates
00144         }
00145         else if(phiSeg > maxPhi) {
00146           if (_debug ==3){std::cout << " CUT by phi "<<phiSeg
00147             <<">max "<<maxPhi<< std::endl;}//yzhang debug       
00148           break;  // past candidates
00149         }
00150       } else { // !phitest
00151         if (phiSeg > maxPhi && phiSeg < minPhi) {
00152           if (_debug ==3){std::cout << "!phitest "<<phiSeg
00153             <<" max "<<maxPhi<< " min "<<minPhi << std::endl;}//yzhang debug    
00154           continue;
00155         }
00156       }
00157 
00158       if(_debug == 3) std::cout<<" **KEEP seg phi="<<phiSeg<<  std::endl;
00159 
00160       //std::cout<< __FILE__ << "   " << __LINE__ << " MdcSegGrouperSt::fillWithSegs call calcStereo "<<std::endl;
00161       int isBad = info->calcStereo(inSeg, track->track(), segStuff);  
00162 
00163       if (isBad) {
00164         if (_debug ==3){std::cout << " CUT by calcStereo isBad!"<<std::endl;}
00165         continue;
00166       }
00167       // Test for sensible values of ct and z0
00168       if (g_z0Cut) {g_z0Cut->fill(info->z0());}
00169       if (g_ctCut) {g_ctCut->fill(info->ct());}
00170       if (fabs(info->ct()) > inSeg->segPar()->ctcut) {
00171         if (_debug ==3){std::cout << " CUT by ctcut! "
00172           <<fabs(info->ct())<<" > cut:"<< inSeg->segPar()->ctcut<<" "<<phiSeg<<std::endl; }
00173         continue;
00174       }
00175       if (fabs(info->z0()) > inSeg->segPar()->z0cut){
00176         if (_debug ==3){std::cout << " CUT by z0cut! "
00177           <<fabs(info->z0())<<" >cut "<< inSeg->segPar()->z0cut<<" "<<phiSeg<<std::endl; }
00178         continue;
00179       }
00180       inSeg->setInfo(info);
00181       info = new MdcSegInfoSterO;      
00182       segList[isuper].append(inSeg);
00183       //if(_debug==3)std::cout<<" APPEND this stereo seg"<<  std::endl;
00184 
00185     }  // end loop over new segs
00186   }  //  end loop over superlayers
00187   delete info;
00188 }
00189 
00190 //-------------------------------------------------------------------------
00191 void MdcSegGrouperSt::plotStereo( ) const {
00192   //-------------------------------------------------------------------------
00193   int nsuper = _gm->nSuper();
00194   int isuper;
00195   /*
00196      for (isuper = 0; isuper < nsuper; isuper++) {
00197      if (segList[isuper].length() == 0) continue;
00198 
00199      MdcSeg *inSeg = (MdcSeg *) segList[isuper].first();
00200   // Only draw stereo segments
00201   if (inSeg->superlayer()->whichView() == 0) continue;
00202   for (int j = 0 ; j < (int) segList[isuper].length(); j++) {
00203   segList[isuper][j]->plotSeg(0,orange);
00204   }
00205   }
00206   */
00207   for (isuper = 0; isuper < nsuper; isuper++) {
00208     if (segList[isuper].length() == 0) continue;
00209 
00210     MdcSeg *inSeg = (MdcSeg *) segList[isuper].first();
00211     // Only draw stereo segments
00212     //if (inSeg->superlayer()->whichView() == 0) continue;
00213     for (int j = 0 ; j < (int) segList[isuper].length(); j++) {
00214       segList[isuper][j]->plotSeg();
00215     }
00216   }
00217 
00218 }
00219 //-------------------------------------------------------------------------
00220 int MdcSegGrouperSt::incompWithSeg(const MdcSeg *refSeg, 
00221     const MdcSeg *testSeg) {
00222   //-------------------------------------------------------------------------
00223 
00224   return 0;
00225 }
00226 
00227 //-------------------------------------------------------------------------
00228 int MdcSegGrouperSt::incompWithGroup(MdcSeg **segGroup, const MdcSeg *testSeg, 
00229     int iply) {
00230   //-------------------------------------------------------------------------
00231   // Test that the latest seg lies more or less in a line with the others
00232   //  Currently requiring line to point to IP; also require rough 
00233   //  agreement in ct.
00234   // iply = depth index of current seg (not yet in group)
00235 
00236   int i;
00237   // Find first segment already in group
00238   for (i = iply - 1; i > 0; i--) {
00239     if (!leaveGap[i]) break;
00240   }
00241   const MdcSeg *first = (*combList[i])[currentSeg[i]];
00242 
00243   // Test ct
00244   MdcSegInfoSterO* firstInfo = (MdcSegInfoSterO *) first->info(); 
00245   MdcSegInfoSterO* newInfo = (MdcSegInfoSterO *) testSeg->info(); 
00246 
00247   if (g_delCt) {g_delCt->fill( firstInfo->ct() - newInfo->ct());}//yzhang hist cut
00248   if (fabs( firstInfo->ct() - newInfo->ct() ) > 
00249       testSeg->segPar()->delCtCut) {
00250     if(_debug==3){
00251       cout << "---MdcSegGrouperSt Ct CUT!" << endl;//yzhang debug
00252       std::cout<<"first:"; first->plotSeg(); std::cout<<std::endl;
00253       std::cout<<"test:"; testSeg->plotSeg();std::cout<<std::endl;
00254       std::cout << "first.ct "<< firstInfo->ct()
00255         <<" test.ct "<<newInfo->ct()
00256         <<" delta ct "<<firstInfo->ct() - newInfo->ct()
00257         <<" Cut "<<testSeg->segPar()->delCtCut << std::endl;//yzhang debug
00258 
00259       std::cout<<"--- "<<  std::endl;
00260     } 
00261     return -1;
00262   }else{
00263   }
00264 
00265   double arcFirst = firstInfo->arc();
00266   double arcNew = newInfo->arc();
00267   double zFirst = firstInfo->z0() + firstInfo->ct() * arcFirst;
00268   double zNew = newInfo->z0() + newInfo->ct() * arcNew; 
00269   // project line from IP through 1st seg to new seg
00270   double zProj = zFirst / arcFirst * arcNew;
00271   if (g_delZ0) {g_delZ0->fill( zProj - zNew);}//yzhang hist cut
00272 
00273   if (fabs(zProj - zNew) > testSeg->segPar()->delZ0Cut) {
00274     if(3==_debug){
00275       cout << "MdcSegGrouperSt delZ0Cut  not incompWithGroup CUT!" << endl;//yzhang debug 
00276       testSeg->plotSeg(); 
00277       std::cout<<" zProj "<< zProj << " zNew "<< zNew<< " CUT! "
00278         << testSeg->segPar()->delZ0Cut <<  std::endl;
00279     }
00280     return -1;
00281   }
00282 
00283   /*
00284      double delZ = newInfo->z0() + newInfo->ct() * arcNew - zFirst;
00285      double z0 = zFirst - arcFirst * delZ / (arcNew - arcFirst);
00286      if (fabs(z0) > testSeg->segPar()->delZ0Cut)return -1;
00287 
00288      for (i = iply - 1; i > 0; i--) {
00289      if (segGroup[i] != 0) break;
00290      }
00291      const MdcSeg *last = segGroup[i];
00292      MdcSegInfoSterO* lastInfo = (MdcSegInfoSterO *) last->info(); 
00293 
00294   // Test that slope from last segment to new one is roughly = slope from 
00295   //   first seg to last
00296   double arcLast = lastInfo->arc();
00297   double arcFirst = firstInfo->arc();
00298   double arcNew = newInfo->arc();
00299 
00300   double delZold = lastInfo->z0() - firstInfo->z0() + 
00301   lastInfo->ct() * arcLast - firstInfo->ct() * arcFirst;
00302   double delArcold = arcLast - arcFirst;
00303   double delZnew = newInfo->z0() - lastInfo->z0() + 
00304   newInfo->ct() * arcNew - lastInfo->ct() * arcLast;
00305   double delArcnew = arcNew - arcLast;
00306   double p1 = delZold * delArcnew;
00307   double p2 = delZnew * delArcold;
00308 
00309   cout << " test: " << p1 << "  " << p2 << endl;
00310 
00311   if (fabs(p2 - p1) > 0.02) return -1;
00312 
00313 */
00314   return 0;
00315 }
00316 
00317 //**************************************************************************
00318 void MdcSegGrouperSt::resetComb(const MdcSeg *seed) {
00319   //**************************************************************************
00320 
00321   // Delete existing list of valid/invalid segs
00322   if (isValid != 0) {
00323     int i;
00324     for (i = 0; i < nDeep; i++) {
00325       delete [] isValid[i];
00326       isValid[i] = 0;
00327     }
00328   }
00329 
00330   //Grab the seglist for each slayer
00331   int islay = 0;
00332   int iply = 0;
00333   nPlyFilled = 0;
00334   nNull = 0;
00335 
00336 
00337   // Set up all sorts of stuff for fast grouping of segs in nextGroup()
00338   for (const MdcSuperLayer *thisSlay = _gm->firstSlay(); thisSlay != 0;
00339       thisSlay = thisSlay->next()) {
00340     //bool noGoodYet = true;
00341     islay++;
00342     if (thisSlay->whichView() == 0) continue;
00343     firstGood[iply] = 0;
00344     firstBad[iply] = segList[islay-1].length();
00345     if (firstGood[iply] > firstBad[iply]) firstGood[iply] = firstBad[iply];
00346     if (firstGood[iply] == firstBad[iply]) {
00347       // If there are no valid segs for this ply, skip it
00348       continue;
00349     }
00350     // Associate correct seglist with this ply
00351     combList[iply] = &segList[islay-1];
00352     leaveGap[iply] = false;
00353     iply++;
00354   }
00355 
00356   nPlyFilled = iply;
00357   resetSegCounters();
00358   maxNull = nPlyFilled - 2;
00359 }
00360 
00361 //---------------------------------------------------------------------
00362 MdcTrack* MdcSegGrouperSt::storePar(MdcTrack* trk, double parms[2], 
00363     double chisq, 
00364     TrkContext&, double) {
00365   //---------------------------------------------------------------------
00366   assert (trk != 0);
00367   TrkHelixMaker maker;
00368   if(3==_debug) std::cout<< "-----storePar z0 "<<parms[0]<<" ct "<<parms[1]<<std::endl;
00369   maker.addZValues(trk->track(), parms[0], parms[1], chisq);
00370   return trk;
00371 }
00372 

Generated on Tue Nov 29 23:13:34 2016 for BOSS_7.0.2 by  doxygen 1.4.7