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

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // $Id: TBuilderCosmic.cxx,v 1.6 2010/03/31 09:58:59 liucy Exp $
00003 //-----------------------------------------------------------------------------
00004 // Filename : TBuilderCosmic.cc
00005 // Section  : Tracking
00006 // Owner    : Yoshi Iwasaki
00007 // Email    : yoshihito.iwasaki@kek.jp
00008 //-----------------------------------------------------------------------------
00009 // Description : A class to build a cosmic track.
00010 //               See http://bsunsrv1.kek.jp/~yiwasaki/tracking/
00011 //-----------------------------------------------------------------------------
00012 
00013 #ifdef TRKRECO_DEBUG_DETAIL
00014 #ifndef TRKRECO_DEBUG
00015 #define TRKRECO_DEBUG
00016 #endif
00017 #endif
00018 #include "TrkReco/TBuilderCosmic.h"
00019 #include "TrkReco/TMLink.h"
00020 #include "TrkReco/TTrack.h"
00021 #include "TrkReco/TLine0.h"
00022 #include "TrkReco/T3DLine.h"
00023 
00024 TBuilderCosmic::TBuilderCosmic(const std::string & name, float salvageLevel)
00025 : TBuilder0(name, salvageLevel), _fitter("TBuilderCosmic Fitter") {
00026 }
00027 
00028 TBuilderCosmic::~TBuilderCosmic() {
00029 }
00030 
00031 TTrack *
00032 TBuilderCosmic::buildStereo(TTrack & track, const AList<TMLink> & list) const {
00033 #ifdef TRKRECO_DEBUG_DETAIL
00034     std::cout << name() << "(stereo) ... dump of stereo candidate hits" << std::endl;
00035     AList<TMLink> tmp = list;
00036     tmp.sort(SortByWireId);
00037     std::cout << "    ";
00038     for (unsigned i = 0; i < tmp.length(); i++) {
00039         TMLink * l = tmp[i];
00040         std::cout << l->wire()->layerId() << "-";
00041         std::cout << l->wire()->localId() << ",";
00042     }
00043     std::cout << std::endl;
00044 #endif
00045 
00046     //...Check # of links...
00047     if (list.length() < _lineSelector.nLinksStereo()) {
00048 #ifdef TRKRECO_DEBUG_DETAIL
00049         std::cout << name() << "(stereo) ... rejected by nLinks(";
00050         std::cout << list.length() << ") < ";
00051         std::cout << _lineSelector.nLinks() << std::endl;
00052 #endif  
00053         return NULL;
00054     }
00055 
00056     //...Calculate s and z for every links...
00057     unsigned n = list.length();
00058     AList<TMLink> forLine;
00059     for (unsigned i = 0; i < n; i++) {
00060         TMLink * l = list[i];
00061 
00062         //... Require Fitting vaildation 
00063         if(!(l->hit()->state()& WireHitFittingValid)) continue;
00064 
00065         TMLink * t = new TMLink(* l);
00066 
00067         //...Assuming wire position...
00068         t->leftRight(2);
00069         int err = track.szPosition(* t);
00070         if (err) {
00071             delete t;
00072             continue;
00073         }
00074 
00075         //...Store the sz link...
00076         t->link(l);
00077         forLine.append(t);
00078     }
00079 
00080 #ifdef TRKRECO_DEBUG_DETAIL
00081     std::cout << name() << "(stereo) ... dump of sz links" << std::endl;
00082     std::cout << "    ";
00083     tmp = forLine;
00084     tmp.sort(SortByWireId);
00085     for (unsigned i = 0; i < tmp.length(); i++) {
00086         TMLink * l = tmp[i];
00087         std::cout << l->wire()->layerId() << "-";
00088         std::cout << l->wire()->localId() << ",";
00089     }
00090     std::cout << std::endl;
00091 #endif  
00092     
00093     //...Check # of sz links...
00094     if (forLine.length() < _lineSelector.nLinksStereo()) {
00095 #ifdef TRKRECO_DEBUG_DETAIL
00096         std::cout << name() << "(stereo) ... rejected by sz nLinks(";
00097         std::cout << forLine.length() << ") < ";
00098         std::cout << _lineSelector.nLinks() << std::endl;
00099 #endif  
00100         HepAListDeleteAll(forLine);
00101         return NULL;
00102     }
00103 
00104     //...Make a line...
00105     unsigned nLine = forLine.length();
00106     TLine0 line(forLine);
00107     int err = line.fit();
00108 
00109     //...Linear fit...
00110     if (err < 0) {
00111 #ifdef TRKRECO_DEBUG_DETAIL
00112         std::cout << name() << "(stereo) ... linear fit failure. nLinks(";
00113         std::cout << forLine.length() << ")" << std::endl;
00114 #endif  
00115         HepAListDeleteAll(forLine);
00116         return NULL;
00117     }
00118 
00119 #ifdef TRKRECO_DEBUG_DETAIL
00120     std::cout << name() << "(stereo) ... dump of left-right" << std::endl;
00121 #endif
00122 
00123     //...Decide Left or Right...
00124     AList<TMLink> forNewLine;
00125     for (unsigned i = 0; i < nLine; i++) {
00126         TMLink * t = forLine[i];
00127         TMLink * tl = new TMLink(* t);
00128         TMLink * tr = new TMLink(* t);
00129 
00130         tl->leftRight(WireHitLeft);
00131         tr->leftRight(WireHitRight);
00132 
00133         int err = track.szPosition(* tl);
00134         if (err) {
00135             delete tl;
00136             tl = NULL;
00137         }
00138         err = track.szPosition(* tr);
00139         if (err) {
00140             delete tr;
00141             tr = NULL;
00142         }
00143         if ((tl == NULL) && (tr == NULL)) continue;
00144 
00145         TMLink * best;
00146         if (tl == NULL) best = tr;
00147         else if (tr == NULL) best = tl;
00148         else {
00149             if (line.distance(* tl) < line.distance(* tr)) {
00150                 best = tl;
00151                 delete tr;
00152             }
00153             else {
00154                 best = tr;
00155                 delete tl;
00156             }
00157         }
00158 
00159 #ifdef TRKRECO_DEBUG_DETAIL
00160         std::cout << "    ";
00161         std::cout << t->wire()->layerId() << "-";
00162         std::cout << t->wire()->localId();
00163         if (tl != NULL)
00164             std::cout << ",left " << tl->position() << "," << line.distance(* tl);
00165         if (tr != NULL)
00166             std::cout << ",right " << tr->position() << "," << line.distance(* tr);
00167         std::cout << std::endl;
00168 #endif
00169 
00170         best->link(t->link());
00171         forNewLine.append(best);
00172     }
00173 
00174     //...Check # of sz links...
00175     if (forNewLine.length() < _lineSelector.nLinksStereo()) {
00176 #ifdef TRKRECO_DEBUG_DETAIL
00177         std::cout << name() << "(stereo) ... rejected by lr nLinks(";
00178         std::cout << forNewLine.length() << ") < ";
00179         std::cout << _lineSelector.nLinks() << std::endl;
00180 #endif  
00181         HepAListDeleteAll(forLine);
00182         HepAListDeleteAll(forNewLine);
00183         return NULL;
00184     }
00185 
00186     //...Create new line...
00187 #ifdef TRKRECO_DEBUG_DETAIL
00188     std::cout << name() << "(stereo) ... creating a new line" << std::endl;
00189 #endif  
00190     unsigned nNewLine = forNewLine.length();
00191     TLine0 newLine(forNewLine);
00192 
00193     //...Make a seed track again
00194     err = newLine.fit();
00195 
00196     //...Linear fit...
00197     if (err < 0) {
00198 #ifdef TRKRECO_DEBUG_DETAIL
00199         std::cout << name() << "(stereo) ... 2nd linear fit failure. nLinks(";
00200         std::cout << forNewLine.length() << ")" << std::endl;
00201 #endif  
00202         HepAListDeleteAll(forLine);
00203         HepAListDeleteAll(forNewLine);
00204         return NULL;
00205     }
00206 
00207     //...Remove bad points...
00208     AList<TMLink> bad;
00209 //    newLine.refine(bad, 40.);  //Liuqg, meaningless while without magnetic field
00210 //    err = newLine.fit();
00211 //    newLine.refine(bad, 20.);
00212 //    err = newLine.fit();
00213 //    newLine.refine(bad, 10.);
00214 //    err = newLine.fit();
00215 
00216     //...Linear fit again...
00217     if (err < 0) {
00218         HepAListDeleteAll(forLine);
00219         HepAListDeleteAll(forNewLine);
00220 #ifdef TRKRECO_DEBUG_DETAIL
00221         std::cout << "    appendStereo cut ... new line 2nd linear fit failure. ";
00222         std::cout << "# of links = " << n << "," << nLine;
00223         std::cout << "," << nNewLine << std::endl;
00224 #endif  
00225         return NULL;
00226     }
00227 
00228     //...3D fit...
00229     const AList<TMLink> & good = newLine.links();
00230     unsigned nn = good.length();
00231     for (unsigned i = 0; i < nn; i++) {
00232         track.append(* good[i]->link());
00233     }
00234     Vector a(5);
00235     a = track.helix().a();
00236     a[3] = newLine.b();
00237     a[4] = track.charge() * newLine.a();
00238     track._helix->a(a);
00239 
00240 #ifdef LINE_COSMIC
00241     T3DLine * Ltrack = new T3DLine(track);
00242     
00243     //...Refine...
00244     err = _fitter.fit(*Ltrack);
00245     Ltrack->refine(bad, _trackSelector.maxSigma() * 30.);
00246     err = _fitter.fit(*Ltrack);
00247     Ltrack->refine(bad, _trackSelector.maxSigma() * 3.);
00248     err = _fitter.fit(*Ltrack);
00249 //    Ltrack->refine(bad, _trackSelector.maxSigma() * 0.21);  //liuqg, for prelimilary test
00250     track.refine(bad, _trackSelector.maxSigma()); 
00251     err = _fitter.fit(*Ltrack);
00252 
00253     //...Test it...
00254 /*    if (! _trackSelector.select(*Ltrack)) {
00255         HepAListDeleteAll(forLine);
00256         HepAListDeleteAll(forNewLine);
00257         delete Ltrack;
00258         return NULL;
00259     }
00260 */
00261     //...Termination...
00262     HepAListDeleteAll(forLine);
00263     HepAListDeleteAll(forNewLine);
00264     track.removeLinks();
00265     track.append(Ltrack->links());
00266     Vector a1(5);
00267     a1 = Ltrack->helix().a();
00268     track._helix->a(a1);
00269     delete Ltrack;
00270     return & track;
00271 #endif
00272 
00273     //...Refine...
00274     err = _fitter.fit(track);
00275     track.refine(bad, _trackSelector.maxSigma() * 30.);
00276     err = _fitter.fit(track);
00277     track.refine(bad, _trackSelector.maxSigma() * 3.);
00278     err = _fitter.fit(track);
00279     track.refine(bad, _trackSelector.maxSigma());  //liuqg, for prelimilary test
00280 //    track.refine(bad, _trackSelector.maxSigma() * 0.21); 
00281     err = _fitter.fit(track);
00282     //...Test it...
00283     if (! _trackSelector.select(track)) {
00284         HepAListDeleteAll(forLine);
00285         HepAListDeleteAll(forNewLine);
00286         return NULL;
00287     }
00288 
00289     //...Termination...
00290     HepAListDeleteAll(forLine);
00291     HepAListDeleteAll(forNewLine);
00292     return & track;
00293 }

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