00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "TrkReco/TPerfectFinder.h"
00014 #include "TrkReco/TMDCWireHitMC.h"
00015 #include "TrkReco/TTrackHEP.h"
00016 #include "TrkReco/TTrack.h"
00017
00018
00019 #include "TrackUtil/Helix.h"
00020
00021 TPerfectFinder::TPerfectFinder(int perfectFitting,
00022 float maxSigma,
00023 float maxSigmaStereo,
00024 unsigned fittingFlag)
00025 : _perfectFitting(perfectFitting),
00026 _builder("conformal builder",
00027 maxSigma,
00028 maxSigmaStereo,
00029 0,
00030 0,
00031 0,
00032 fittingFlag),
00033 _fitter("helix fitter") {
00034 }
00035
00036 TPerfectFinder::~TPerfectFinder() {
00037 }
00038
00039 std::string
00040 TPerfectFinder::version(void) const {
00041 return "2.04";
00042 }
00043
00044 void
00045 TPerfectFinder::dump(const std::string & msg, const std::string & pre) const {
00046 std::cout << pre;
00047 TFinderBase::dump(msg);
00048 }
00049
00050 int
00051 TPerfectFinder::doit(const AList<TMDCWireHit> & axialHits,
00052 const AList<TMDCWireHit> & stereoHits,
00053 AList<TTrack> & tracks,
00054 AList<TTrack> & tracks2D) {
00055
00056
00057 static const HepPoint3D dummy(0, 0, 0);
00058 CAList<TMDCWireHit> hits;
00059 hits.append(axialHits);
00060 hits.append(stereoHits);
00061
00062
00063 CAList<TTrackHEP> heps;
00064 const unsigned nHits = hits.length();
00065 for (unsigned i = 0; i < nHits; i++) {
00066 const TMDCWireHitMC * const mc = hits[i]->mc();
00067 if (! mc) continue;
00068 const TTrackHEP * const hep = mc->hep();
00069
00070 if (! hep) continue;
00071 heps.append(hep);
00072 }
00073 heps.purge();
00074
00075
00076 const AList<TMDCWireHitMC> & mcHits = TMDC::getTMDC()->hitsMC();
00077 const unsigned nHitsMC = mcHits.length();
00078 const unsigned nHeps = heps.length();
00079 for (unsigned i = 0; i < nHeps; i++) {
00080 const TTrackHEP & hep = * heps[i];
00081 const float chg = charge(hep.pType());
00082 AList<TMLink> hepLinks;
00083 HepPoint3D posIn, posOut;
00084 HepVector3D momIn, momOut;
00085 float rMin = 99999;
00086 float rMax = 0.;
00087 TMLink * linkIn;
00088 unsigned lastLayer = 0;
00089 for (unsigned j = 0; j < mcHits.length(); j++) {
00090 const TMDCWireHitMC * const mc = mcHits[j];
00091 if (! mc) continue;
00092 if (! mc->hit()) continue;
00093 if (& hep != mc->hep()) continue;
00094 if (! hits.hasMember(mc->hit())) continue;
00095
00096
00097 if (mc->wire()->layerId() < lastLayer) break;
00098 lastLayer = mc->wire()->layerId();
00099 HepPoint3D ent = mc->entrance();
00100 HepVector3D dir = mc->direction();
00101 ent.setZ(0.);
00102 dir.setZ(0.);
00103 if ((ent.unit()).dot(dir.unit()) < 0.5) continue;
00104
00105
00106 TMLink * l = new TMLink(0, mc->hit(), dummy);
00107 l->leftRight(mc->leftRight());
00108 hepLinks.append(l);
00109 _links.append(l);
00110
00111
00112 const float r = ent.mag();
00113 if (r < rMin) {
00114 posIn = mc->entrance();
00115 momIn = mc->momentum();
00116 rMin = r;
00117 linkIn = l;
00118 }
00119 if (r > rMax) {
00120 posOut = mc->entrance();
00121 momOut = mc->momentum();
00122 rMax = r;
00123 }
00124 }
00125 if (_links.length() == 0) continue;
00126
00127
00128 TTrack * t = 0;
00129
00130 Helix h(posOut, momOut, chg);
00131
00132 h.pivot(linkIn->wire()->xyPosition());
00133 t = new TTrack(h);
00134 t->append(hepLinks);
00135 t->assign(0);
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 if (_perfectFitting == 0) {
00152 std::cout << "special test in perfect finder" << std::endl;
00153 AList<TMLink> tmp;
00154 for (unsigned i = 0; i < t->nLinks(); i++) {
00155 bool rem = false;
00156 if (t->links()[i]->wire()->name() == "0-56")
00157 rem = true;
00158 else if (t->links()[i]->wire()->name() == "2-56")
00159 rem = true;
00160 else if (t->links()[i]->wire()->name() == "5-57")
00161 rem = true;
00162 else if (t->links()[i]->wire()->name() == "6=68")
00163 rem = true;
00164 else if (t->links()[i]->wire()->name() == "7=69")
00165 rem = true;
00166 else if (t->links()[i]->wire()->name() == "8=68")
00167 rem = true;
00168 else if (t->links()[i]->wire()->name() == "10-85")
00169 rem = true;
00170 else if (t->links()[i]->wire()->name() == "20-126")
00171 rem = true;
00172 else if (t->links()[i]->wire()->name() == "39-210")
00173 rem = true;
00174 else if (t->links()[i]->wire()->name() == "41=221")
00175 rem = true;
00176 else if (t->links()[i]->wire()->name() == "43=221")
00177 rem = true;
00178 else if (t->links()[i]->wire()->name() == "46-251")
00179 rem = true;
00180 else if (t->links()[i]->wire()->name() == "48-251")
00181 rem = true;
00182 if (rem) {
00183 std::cout << t->links()[i]->wire()->name() << " removed" << std::endl;
00184 tmp.append(* t->links()[i]);
00185 }
00186 }
00187 t->remove(tmp);
00188 t->dump("detail","@lastHit");
00189 Helix & h = (Helix &) t->helix();
00190 h.pivot(HepVector3D(0., 0., 0.));
00191 t->dump("detail","@origin ");
00192 _fitter.fit(* t);
00193 t->dump("detail","fitted ");
00194 static const HepVector3D p0(1.226, -1.025, 0.120);
00195 std::cout << "Pdif mag=" << (t->p() - p0).mag() << std::endl;
00196 }
00197
00198 tracks.append(t);
00199 }
00200 return 0;
00201 }
00202
00203 void
00204 TPerfectFinder::clear(void) {
00205 HepAListDeleteAll(_links);
00206 }
00207
00208 float
00209 TPerfectFinder::charge(int pType) const {
00210 float chg;
00211
00212 if (pType == 11) chg = -1;
00213 else if (pType == -11) chg = 1;
00214 else if (pType == 13) chg = -1;
00215 else if (pType == -13) chg = 1;
00216 else if (pType == 211) chg = 1;
00217 else if (pType == -211) chg = -1;
00218 else if (pType == 321) chg = 1;
00219 else if (pType == -321) chg = -1;
00220 else if (pType == 2212) chg = 1;
00221 else if (pType == -2212) chg = -1;
00222 else {
00223 std::cout << "TPerfectFinder !!! charge of particle type=";
00224 std::cout << pType << " is unknown" << std::endl;
00225 }
00226
00227 return chg;
00228 }