/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Reconstruction/TrkReco/TrkReco-00-08-59-patch4-slc6tag/src/TTrackMC.cxx

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // $Id: TTrackMC.cxx,v 1.5 2010/03/31 09:58:59 liucy Exp $
00003 //-----------------------------------------------------------------------------
00004 // Filename : TTrackMC.cc
00005 // Section  : Tracking
00006 // Owner    : Yoshi Iwasaki
00007 // Email    : yoshihito.iwasaki@kek.jp
00008 //-----------------------------------------------------------------------------
00009 // Description : A class to have MC information of TTrack.
00010 //               See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
00011 //-----------------------------------------------------------------------------
00012 
00013 /* for copysign */
00014 #if defined(__sparc)
00015 #  if defined(__EXTENSIONS__)
00016 #    include <cmath>
00017 #  else
00018 #    define __EXTENSIONS__
00019 #    include <cmath>
00020 #    undef __EXTENSIONS__
00021 #  endif
00022 #elif defined(__GNUC__)
00023 #  if defined(_XOPEN_SOURCE)
00024 #    include <cmath>
00025 #  else
00026 #    define _XOPEN_SOURCE
00027 #    include <cmath>
00028 #    undef _XOPEN_SOURCE
00029 #  endif
00030 #endif
00031 #include <cfloat>
00032 #include "TrkReco/TMDCUtil.h"
00033 #include "TrkReco/TMDCWireHitMC.h"
00034 #include "TrkReco/TrkReco.h"
00035 #include "TrkReco/TTrack.h"
00036 #include "TrkReco/TTrackMC.h"
00037 #include "TrkReco/TTrackHEP.h"
00038 //#include "tables/cdc.h"
00039 #include "MdcTables/MdcTables.h"
00040 
00041 #if defined(__alpha)
00042 #define DBL_MIN 2.2250738585072014E-308 
00043 #define FLT_MIN 1.175494351E-38F
00044 #endif
00045 
00046 TTrackMC::TTrackMC(const TTrack & t)
00047 : _t(t),
00048   _hep(0),
00049   _hepID(-1),
00050   _wireFraction(-999.),
00051   _wireFractionHEP(-999.),
00052   _charge(false),
00053   _ptFraction(-999.),
00054   _pzFraction(-999.),
00055   _ptResidual(-999.),
00056   _pzResidual(-999.),
00057   _ptPull(-999.),
00058   _pzPull(-999.),
00059   _state(0),
00060   _quality(0) {
00061 }
00062 
00063 TTrackMC::~TTrackMC() {
00064 }
00065 
00066 void
00067 TTrackMC::update(void) {
00068     _state = 0;
00069     _quality = 0;
00070 /*
00071     //...Prepare counters...
00072     unsigned nHep = TTrackHEP::list().length();
00073     unsigned nTrk = TrkReco::getTrkReco()->tracks().length();
00074     unsigned * N1 = (unsigned *) malloc(nHep * sizeof(unsigned));
00075     float * F1 = (float *) malloc(nHep * sizeof(float));
00076     unsigned N2 = 0;
00077     for (unsigned i = 0; i < nHep; i++) {
00078         N1[i] = 0;
00079         F1[i] = 0.;
00080     }
00081     
00082     //...Prepare for fraction F1...
00083 //  const AList<TMLink> & cores = _t.cores();
00084     const AList<TMLink> & cores = _t.finalHits();
00085     unsigned nCores = cores.length();
00086     for (unsigned i = 0; i < nCores; i++) {
00087         TMLink * t = cores[i];
00088         int hepID = t->hit()->mc()->hep()->id();
00089         ++N1[hepID];
00090     }
00091 
00092     //...Calculate fraction F1 and find the best HEP...
00093     int bestHep = -1;
00094     TTrackHEP * hep = 0;
00095     float bestF1 = 0.;
00096     for (unsigned i = 0; i < nHep; i++) {
00097         if (nCores) F1[i] = (float) N1[i] / (float) nCores;
00098         if (F1[i] > bestF1) {
00099             bestHep = i;
00100             bestF1 = F1[i];
00101         }
00102     }
00103 
00104     //...Check HEP...
00105     float F2 = 0.;
00106     if (bestHep != -1) {
00107         hep = TTrackHEP::list()[bestHep];
00108         unsigned nAll = 0;
00109         for (unsigned i = 0; i < hep->hits().length(); i++) {
00110             const TMDCWireHit * hit = hep->hits()[i]->hit();
00111             if (! hit) continue;
00112             if (hit->state() & WireHitInvalidForFit) continue;
00113             
00114             ++nAll;
00115             if (hit->track() == & _t) ++N2;
00116         }
00117 
00118         //...Calculate fraction F2...
00119         if (nAll) F2 = (float) N2 / (float) nAll;
00120     }
00121 
00122     //...Store results...
00123     _hepID = bestHep;
00124     _hep = hep;
00125     _wireFraction = bestF1;
00126     _wireFractionHEP = F2;
00127 
00128     //...Compare charge and momentum...
00129     compare();
00130 
00131     //...Classification...
00132     classify();
00133 
00134     //...Termination...
00135     free(N1);
00136     free(F1);
00137 */
00138 }
00139 
00140 void
00141 TTrackMC::dump(const std::string & msg, const std::string & pre) const {
00142     std::cout << msg;
00143     std::cout << _t.name() << ":";
00144     std::cout << "state=" << _state << ":";
00145     if (_quality & TTrackGood) std::cout << "good   :";
00146     else if (_quality & TTrackGhost) std::cout << "ghost  :";
00147     else if (_quality & TTrackBad) std::cout << "bad    :";
00148     else if (_quality & TTrackCharge) std::cout << "bad    :";
00149     else if (_quality & TTrackGarbage) std::cout << "garbage:";
00150     else std::cout << "classification error:";
00151     bitDisplay(_quality, 23, 15); std::cout << ":";
00152     std::cout << _hepID << ":";
00153     std::cout << _wireFraction << "," << _wireFractionHEP << ":";
00154     std::cout << _ptFraction << "," << _pzFraction;
00155     std::cout << std::endl;
00156 }
00157 
00158 void
00159 TTrackMC::compare(void) {
00160     if (! _hep) return;
00161 
00162     //...Get charge of HEP particle(This part should be done by LUCHARGE)...
00163     int id = _hep->pType();
00164     int aId = abs(id);
00165     if (aId == 11 || aId == 13 || aId == 15) id *= -1;
00166 
00167     //...Compare charge...
00168     if ((int) _t.charge() * id > 0) _charge = true;
00169 
00170     //...Get hep mom. at the inner-most hit...
00171 //  AList<TMLink> list = _t.cores();
00172     AList<TMLink> list = _t.finalHits();
00173     unsigned n = list.length();
00174     bool found = false;
00175     Vector3 pHep;
00176     Vector3 vHep;
00177     for (unsigned i = 0; i < n; i++) {
00178         TMLink * inner = InnerMost(list);
00179         if (inner->hit()->mc()->hep() == _hep) {
00180             pHep = inner->hit()->mc()->momentum();
00181             vHep = inner->hit()->mc()->entrance();
00182             found = true;
00183             break;
00184         }
00185         list.remove(inner);
00186     }
00187     Helix hHep = Helix(vHep, pHep, copysign(1., id));
00188     hHep.pivot(_t.helix().pivot());
00189     pHep = hHep.momentum();
00190 
00191     //...For debug...
00192     if (! found) {
00193         std::cout << "TTrackMC::compare !!! something wrong with mc hits"
00194                   << std::endl;
00195 
00196         //...For debug...
00197 //      list = _t.cores();
00198 //      for (unsigned i = 0; i < list.length(); i++) {
00199 //          TMLink * inner = innerMost(list);
00200 //          std::cout << i << " " << inner << ":" << inner->hit()->mc()->hep();
00201 //          std::cout << " " << _hep << std::endl;
00202 //          if (inner->hit()->mc()->hep() == _hep) {
00203 //              pHep = inner->hit()->mc()->momentum();
00204 //              break;
00205 //          }
00206 //          list.remove(inner);
00207 //      }
00208 //      TMLink * t = 0;
00209 //      t->hit();
00210         //...For debug end...
00211 
00212         return;
00213     }
00214 
00215     //...Fill caches...
00216     _residual = _t.p() - pHep;
00217     _cosOpen = pHep.unit().dot(_t.p().unit());
00218 
00219     //...Compare pt...
00220     double pt = _t.pt();
00221     double ptHep = sqrt(pHep.x() * pHep.x() + pHep.y() * pHep.y());
00222     _ptResidual = pt - ptHep;
00223     const Helix & h = _t.helix();
00224     Vector dPt(5, 0);
00225     dPt[2] = - 1. / (h.kappa() * h.kappa());
00226     double ptError2 = h.Ea().similarity(dPt);
00227     if(ptError2<0.0) {
00228       std::cout << h.kappa() << " " << h.Ea() << " dPt=" << dPt << std::endl;
00229     }
00230     double ptError = (ptError2 > 0.) ? sqrt(ptError2) : (DBL_MIN);
00231     _ptPull = (ptError2 > 0.) ? (_ptResidual) / ptError : (FLT_MAX);
00232     _ptFraction = (fabs(ptHep)>(FLT_MIN)) ? _ptResidual / ptHep : 0.0;
00233 
00234     //...Compare pz...
00235     double pz = _t.pz();
00236     double pzHep = pHep.z();
00237     _pzResidual = pz - pzHep;
00238     Vector dPz(5, 0);
00239     dPz[2] = - h.tanl() / (h.kappa() * h.kappa());
00240     dPz[4] = 1. / h.kappa();
00241     double pzError2 = h.Ea().similarity(dPz);
00242     if(pzError2<0.0) {
00243       std::cout << h.kappa() << " " << h.Ea() << " dPz=" << dPz << std::endl;
00244     }
00245     double pzError = (pzError2 > 0.) ? sqrt(pzError2) : (DBL_MIN);
00246     _pzPull = (pzError2 > 0.) ? (_pzResidual) / pzError : (FLT_MAX);
00247     _pzFraction = (abs(pzHep)>FLT_MIN) ? (_pzResidual / pzHep) : (FLT_MAX);
00248 }
00249 
00250 void
00251 TTrackMC::classify(void) {
00252     _state |= TTrackClassified;
00253     _quality = TTrackGarbage;
00254 
00255     //...HEP matching...
00256     if (! _hep) return;
00257     _quality |= TTrackHep;
00258     if (fabs(_ptFraction) < .1) _quality |= TTrackPt;
00259     if (fabs(_pzFraction) < .1) _quality |= TTrackPz;
00260     float momResidual = sqrt(_ptResidual * _ptResidual +
00261                               _pzResidual * _pzResidual);
00262 
00263     if ((momResidual < 0.100) && (_cosOpen > 0.99)) 
00264         _quality |= TTrackMatchingLoose;
00265     if ((momResidual < 0.020) && (_cosOpen > 0.998))
00266         _quality |= TTrackMatchingTight;
00267 
00268     //...Wire fraction...
00269     if (_wireFraction < 0.8) return;
00270     _quality |= TTrackWire;
00271     _quality |= TTrackCharge;
00272 
00273     //...Charge matching...
00274     if (! _charge) return;
00275     _quality |= TTrackBad;
00276 
00277     //...Momentum matching...
00278     if (_quality & TTrackMatchingLoose)
00279         _quality |= TTrackGhost;
00280 
00281     //...TTrackGood is set by TrkReco after checking uniqueness...
00282 }
00283 
00284 std::string
00285 TTrackMC::qualityString(void) const {
00286     return TrackMCQualityString(_quality);
00287 }
00288 
00289 std::string
00290 TrackMCStatus(unsigned quality) {
00291     //...This is a local function to hide from user...
00292 
00293     std::string matching;
00294     if (quality & TTrackHep) {
00295         if (quality & TTrackMatchingTight) matching += "tight";
00296         else if (quality & TTrackMatchingLoose) matching += "loose";
00297         else matching = "bad";
00298     }
00299     return TrackMCQualityString(quality) + " " + matching;
00300 }
00301 
00302 std::string
00303 TrackMCStatus(const TTrackMC & m) {
00304     return TrackMCStatus(m.quality());
00305 }
00306 
00307 std::string
00308 TrackMCStatus(const MdcRec_mctrk & m) {
00309     return TrackMCStatus(m.quality);
00310 }
00311 
00312 std::string
00313 TrackMCQualityString(unsigned quality) {
00314     if (quality & TTrackGood) return std::string("Good");
00315     else if (quality & TTrackGhost) return std::string("Ghost");
00316     else if (quality & TTrackBad) return std::string("Bad");
00317     else if (quality & TTrackCharge) return std::string("Charge");
00318     else if (quality & TTrackGarbage) return std::string("Garbage");
00319     return std::string("Unknown");
00320 }

Generated on Tue Nov 29 23:14:17 2016 for BOSS_7.0.2 by  doxygen 1.4.7