/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/MdcPatRec/MdcxReco/MdcxReco-00-01-59/src/MdcxMergeDups.cxx

Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: MdcxMergeDups.cxx,v 1.9 2011/12/08 06:52:29 zhangy Exp $
00004 //
00005 // Description: 
00006 //      Class Implementation for K0s finding
00007 //
00008 // Environment:
00009 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00010 //
00011 // Author List:
00012 //      S.  Wagner
00013 //
00014 // Copyright Information:
00015 //      Copyright (C) 1997      BEPCII
00016 // 
00017 // History:
00018 //      Migration for BESIII MDC
00019 //
00020 //------------------------------------------------------------------------
00021 #include <math.h>
00022 #include "MdcxReco/MdcxMergeDups.h"
00023 #include "MdcxReco/MdcxHel.h"
00024 #include "CLHEP/Alist/AIterator.h"
00025 #include "MdcxReco/MdcxHit.h"
00026 #include "MdcxReco/MdcxParameters.h"
00027 using std::cout;
00028 using std::endl;
00029 
00030 MdcxMergeDups::MdcxMergeDups(HepAList<MdcxFittedHel> &trkl, int debug) {
00031   m_debug = (debug == 10);
00032   int iprt = 0;
00033   int ntracks = trkl.length();
00034   if (iprt) cout << "MdcxMergeDups called with " << ntracks << " tracks" << endl;
00035   double m_2pi = 2.0*M_PI;
00036   int k = 0;
00037   while(trkl[k]) trkl[k++]->SetUsedOnHel(0);
00038 
00039   if (ntracks > 1) {
00040     for (int i = 0; i < ntracks-1; i++) {
00041       MdcxFittedHel* iptr = trkl[i];
00042       int already_merged = 0;
00043       if (iptr->GetUsedOnHel()) {
00044         already_merged = trkl[i]->GetUsedOnHel();
00045         iptr = NewTrklist[already_merged-1];
00046       }
00047       for (int j = i+1; j < ntracks; j++) {
00048         if (trkl[j]->GetUsedOnHel()) continue;
00049         double omega1 = iptr->Omega();
00050         double omega2 = trkl[j]->Omega();
00051         double phi01  = iptr->Phi0();
00052         double phi02  = trkl[j]->Phi0();
00053         double d01    = iptr->D0();
00054         double d02    = trkl[j]->D0();
00055         double prodo  = omega1*omega2;
00056         if (m_debug) cout << "Try track [" << i << "] and [" << j << "],  prodo = " << prodo << endl;
00057         //  Try to merge pair that looks like duplicates (same charge)
00058         if (prodo > 0.0) {
00059           if(m_debug) std::cout << "  fabs(d01 - d02)  " << fabs(d01 - d02) << std::endl;
00060           if (fabs(d01 - d02) < MdcxParameters::maxDd0InMerge) {
00061             if(m_debug) std::cout << "  fabs(phi01-phi02)  " << fabs(phi01-phi02) << std::endl;
00062             if (fabs(phi01-phi02) < MdcxParameters::maxDphi0InMerge) {
00063               double r1=100000.;
00064               if (fabs(omega1)>0.00001) r1 = 1.0/fabs(omega1);
00065               double r2=100000.;
00066               if (fabs(omega2)>0.00001) r2 = 1.0/fabs(omega2); //FIXME
00067               double pdrad = fabs((r1-r2)/(r1+r2)) ;
00068               if (m_debug) {
00069                 std::cout << "omega1,r1 " << omega1 << " " << r1
00070                           << " omega2,r2 " << omega2 << " " << r2
00071                           << " pdrad " << pdrad << std::endl;
00072               }
00073               if (pdrad < MdcxParameters::maxPdradInMerge) {
00074                 if (iprt)
00075                   cout << "MdcxMD i j dif " << i << " " << j << " " << d01-d02 << " "
00076                        << phi01-phi02 << " " << r1 << " " << r2 << " " << pdrad << endl;
00077                 HepAList<MdcxHit> dcxhlist = iptr->XHitList();
00078                 if (iprt) cout << "MdcxMD " << dcxhlist.length() << " " << iptr->Chisq();
00079                 const HepAList<MdcxHit>& dcxh2 = trkl[j]->XHitList();
00080                 if (iprt) cout << " " << dcxh2.length() << " " << trkl[j]->Chisq();
00081                 dcxhlist.append(dcxh2);
00082                 dcxhlist.purge();
00083                 if (iprt) cout << " " << dcxhlist.length() << endl;
00084                 MdcxFittedHel fit1(dcxhlist, *iptr); // fit1.FitPrint(); fit1.print();
00085                 MdcxFittedHel fit2(dcxhlist, *trkl[j]); // fit2.FitPrint(); fit2.print();
00086                 int uf = 0; 
00087                 if ( !fit1.Fail() && (fit1.Rcs()<MdcxParameters::maxRcsInMerge) ) uf = 1; 
00088                 if ( !fit2.Fail() && (fit2.Rcs()<fit1.Rcs()) ) uf = 2;
00089                 if (m_debug) {
00090                   std::cout << "fit1.Fail() " << fit1.Fail() << " fit1.Rcs " << fit1.Rcs()
00091                             << " fit2.Fail() " << fit2.Fail() << " fit2.Rcs " << fit2.Rcs()
00092                             << std::endl;
00093                 }
00094                 if (uf) {
00095                   MdcxHel fitme = (uf == 1) ? fit1 : fit2;
00096                   MdcxFittedHel* finehel = new MdcxFittedHel(dcxhlist, fitme);
00097                   if (!finehel->Fail()) {
00098                     if (already_merged) {
00099                       NewTrklist.replace(iptr, finehel);
00100                       delete iptr;
00101                       iptr = finehel;
00102                       trkl[j]->SetUsedOnHel(already_merged);
00103                     } else {
00104                       NewTrklist.append(finehel);
00105                       already_merged = NewTrklist.length();
00106                       iptr->SetUsedOnHel(already_merged);
00107                       iptr = finehel; 
00108                       trkl[j]->SetUsedOnHel(already_merged);
00109                     }
00110                   } else {
00111                     delete finehel;
00112                   }
00113                 }
00114               }
00115             }
00116           }
00117         }
00118 
00119         //  Try to merge pair that looks like albedo (opp charge, large d0)
00120         if (prodo < 0.0) {
00121           if ((fabs(d01+d02) < 4.0) && (fabs(d01-d02) > 47.0)) {  
00122             double deltap = fabs( fabs(phi01-phi02) - M_PI );
00123             if (deltap < MdcxParameters::maxDphi0InMerge) {
00124               double r1=100000.;
00125               if (fabs(omega1) > 0.00001) r1 = 1.0/fabs(omega1);
00126               double r2=100000.;
00127               if (fabs(omega2) > 0.00001) r2 = 1.0/fabs(omega2);
00128               double pdrad = fabs((r1-r2)/(r1+r2)) ;
00129               if (pdrad < MdcxParameters::maxPdradInMerge) {
00130                 if (iprt)
00131                   cout << "MdcxMD i j sum " << i << " " << j << " " << d01+d02 << " "
00132                        << deltap << " " << r1 << " " << r2 << " " << pdrad << endl;
00133                 MdcxHel temp1 = *iptr;
00134                 //zoujh?: temp1.SetTurnFlag(1);
00135                 MdcxHel temp2 = *trkl[j];
00136                 temp2.SetTurnFlag(1);
00137                 HepAList<MdcxHit> dcxhlist = iptr->XHitList();
00138                 if (iprt) cout << "MdcxMD " << dcxhlist.length() << " " << iptr->Chisq();
00139                 const HepAList<MdcxHit>& dcxh2 = trkl[j]->XHitList();
00140                 if (iprt) cout << " " << dcxh2.length() << " " << trkl[j]->Chisq();
00141                 dcxhlist.append(dcxh2);
00142                 dcxhlist.purge();
00143                 if (iprt) cout << " " << dcxhlist.length() << endl;
00144                 MdcxFittedHel fit1(dcxhlist, temp1); // fit1.FitPrint(); fit1.print();
00145                 MdcxFittedHel fit2(dcxhlist, temp2); // fit2.FitPrint(); fit2.print();
00146                 int uf = 0; 
00147                 if ( !fit1.Fail() && (fit1.Rcs()<MdcxParameters::maxRcsInMerge) ) uf = 1; 
00148                 if ( !fit2.Fail() && (fit2.Rcs()<fit1.Rcs()) ) uf = 2;
00149                 if (uf) {
00150                   MdcxHel fitme = (1 == uf) ? fit1 : fit2;
00151                   MdcxFittedHel* finehel = new MdcxFittedHel(dcxhlist, fitme);
00152                   if (!finehel->Fail()) {
00153                     if (already_merged) {
00154                       NewTrklist.replace(iptr, finehel);
00155                       delete iptr;
00156                       iptr = finehel;
00157                       trkl[j]->SetUsedOnHel(already_merged);
00158                     } else {
00159                       NewTrklist.append(finehel);
00160                       already_merged = NewTrklist.length();
00161                       iptr->SetUsedOnHel(already_merged);
00162                       iptr = finehel; 
00163                       trkl[j]->SetUsedOnHel(already_merged);
00164                     }
00165                   } else {
00166                     delete finehel;
00167                   }
00168                 } 
00169               }
00170             }
00171           }
00172         }
00173       }//end j loop
00174     }//end i loop
00175   }
00176 
00177   k = 0;
00178   while (trkl[k]) {
00179     if (iprt)cout << "In MdcxMD, trk is used on " << k << " " << trkl[k]->GetUsedOnHel() << endl;
00180     if (!trkl[k]->GetUsedOnHel()) CleanTrklist.append(trkl[k]); 
00181     k++;
00182   }
00183 
00184   k=0;
00185   while (NewTrklist[k]) {
00186     if (iprt && m_debug) {
00187       NewTrklist[k]->FitPrint();
00188       NewTrklist[k]->print();
00189     } 
00190 
00191     CleanTrklist.append(NewTrklist[k++]);
00192   }
00193 
00194   if (iprt) cout << "MdcxMD leaves with " << CleanTrklist.length() << " tracks" << endl;
00195 }
00196 
00197 MdcxMergeDups::~MdcxMergeDups() {
00198   KillList();
00199 }
00200 

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