00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00016
00017 #include <cassert>
00018 #include <iostream>
00019 #include <cmath>
00020
00021 #include "CandTrackSR/CandTrackSRHandle.h"
00022 #include "CandTrackSR/CandTrackSR.h"
00023 #include "CandTrackSR/Track2DSR.h"
00024 #include "CandTrackSR/TrackClusterSR.h"
00025 #include "MessageService/MsgService.h"
00026 #include "MinosObjectMap/MomNavigator.h"
00027 #include "Navigation/NavKey.h"
00028 #include "Navigation/NavSet.h"
00029 #include "RawData/RawChannelId.h"
00030 #include "RawData/RawDigit.h"
00031 #include "RawData/RawDigitDataBlock.h"
00032 #include "RawData/RawRecord.h"
00033 #include "RecoBase/ArrivalTime.h"
00034 #include "RecoBase/CandClusterHandle.h"
00035 #include "RecoBase/CandTrackHandle.h"
00036 #include "RecoBase/CandStripHandle.h"
00037 #include "RecoBase/LinearFit.h"
00038
00039 ClassImp(CandTrackSRHandle)
00040
00041
00042 CVSID("$Id: CandTrackSRHandle.cxx,v 1.25 2007/01/15 20:02:44 rhatcher Exp $");
00043
00044
00045 CandTrackSRHandle::CandTrackSRHandle()
00046 {
00047 }
00048
00049
00050 CandTrackSRHandle::CandTrackSRHandle(const CandTrackSRHandle &cdh) :
00051 CandTrackHandle(cdh)
00052 {
00053 }
00054
00055
00056 CandTrackSRHandle::CandTrackSRHandle(CandTrackSR *cd) :
00057 CandTrackHandle(cd)
00058 {
00059 }
00060
00061
00062 CandTrackSRHandle::~CandTrackSRHandle()
00063 {
00064 }
00065
00066
00067 CandTrackSRHandle *CandTrackSRHandle::DupHandle() const
00068 {
00069 return (new CandTrackSRHandle(*this));
00070 }
00071
00072
00073
00074 void CandTrackSRHandle::Trace(const char *c) const
00075 {
00076 MSG("Cand", Msg::kDebug)
00077 << "**********Begin CandTrackSRHandle::Trace(\"" << c << "\")" << endl
00078 << "Information from CandTrackSRHandle's CandHandle: " << endl;
00079 CandHandle::Trace(c);
00080 MSG("Cand", Msg::kDebug)
00081 << "**********End CandTrackSRHandle::Trace(\"" << c << "\")" << endl;
00082 }
00083
00084 TObjArray *CandTrackSRHandle::GetClusterList()
00085 {
00086 return dynamic_cast<CandTrackSR *>(GetCandBase())->fClusterList;
00087 }
00088
00089 void CandTrackSRHandle::AddCluster(CandClusterHandle *cluster)
00090 {
00091 if (!cluster) return;
00092
00093 const TObjArray *clusterlist =
00094 (dynamic_cast<CandTrackSR*>(GetCandBase()))->fClusterList;
00095
00096 if (clusterlist) {
00097 Bool_t found(0);
00098 TIter cliter(clusterlist);
00099 CandClusterHandle *target;
00100 while (!found &&
00101 (target = dynamic_cast<CandClusterHandle*>(cliter()))) {
00102 if (*cluster == *target) found = 1;
00103 }
00104
00105 if (!found) {
00106 (dynamic_cast<CandTrackSR*>(GetOwnedCandBase()))->fClusterList->
00107 Add(cluster->DupHandle());
00108
00109 TIter striter(cluster->GetDaughterIterator());
00110 while (CandStripHandle *strip =
00111 dynamic_cast<CandStripHandle*>(striter())) {
00112 AddDaughterLink(*strip);
00113 }
00114 }
00115 }
00116 else {
00117 MSG("TrackSR",Msg::kError) << "Null fClusterList*. No action taken."
00118 << endl;
00119 }
00120 }
00121
00122 Track2DSR *CandTrackSRHandle::GetUTrack() const
00123 {
00124 return dynamic_cast<const CandTrackSR *>(GetCandBase())->fUTrack;
00125 }
00126
00127 Track2DSR *CandTrackSRHandle::GetVTrack() const
00128 {
00129 return dynamic_cast<const CandTrackSR *>(GetCandBase())->fVTrack;
00130 }
00131
00132
00133 void CandTrackSRHandle::SetUTrack(Track2DSR *track)
00134 {
00135 dynamic_cast<CandTrackSR *>(GetOwnedCandBase())->fUTrack = track;
00136 }
00137
00138 void CandTrackSRHandle::SetVTrack(Track2DSR *track)
00139 {
00140 dynamic_cast<CandTrackSR *>(GetOwnedCandBase())->fVTrack = track;
00141 }
00142
00143
00144 Double_t CandTrackSRHandle::GetDirCos(Int_t plane, Int_t iuvz) const
00145 {
00146
00147 if (iuvz<0 || iuvz>=3) {
00148 MSG("TrackSR",Msg::kError) << "iuvz out of range\n";
00149 return 0.;
00150 }
00151
00152 TIter stripItr(GetDaughterIterator());
00153 Double_t uzpos[1000],upos[1000],uph[1000];
00154 Int_t uplane[1000];
00155 Double_t vzpos[1000],vpos[1000],vph[1000];
00156 Int_t vplane[1000];
00157 for (int i=0; i<1000; i++) {
00158 uzpos[i] = 0.;
00159 upos[i] = 0.;
00160 uph[i] = 0.;
00161 uplane[i] = 0;
00162 vzpos[i] = 0.;
00163 vpos[i] = 0.;
00164 vph[i] = 0.;
00165 vplane[i] = 0;
00166 }
00167 while (CandStripHandle *strip = dynamic_cast<CandStripHandle*>(stripItr())) {
00168 Int_t iplane = strip->GetPlane();
00169 if (iplane<0 || iplane>=1000) {
00170 MSG("TrackSR",Msg::kError) << "plane out of range\n";
00171 }
00172 else {
00173 switch (strip->GetPlaneView()) {
00174 case PlaneView::kU:
00175 uph[iplane] += strip->GetCharge();
00176 upos[iplane] += strip->GetCharge()*strip->GetTPos();
00177 uzpos[iplane] = strip->GetZPos();
00178 uplane[iplane] = iplane;
00179 break;
00180 case PlaneView::kV:
00181 vph[iplane] += strip->GetCharge();
00182 vpos[iplane] += strip->GetCharge()*strip->GetTPos();
00183 vzpos[iplane] = strip->GetZPos();
00184 vplane[iplane] = iplane;
00185 break;
00186 default:
00187 break;
00188 }
00189 }
00190 }
00191 for (int i=0; i<1000; i++) {
00192 if (uph[i]>0) upos[i] /= uph[i];
00193 if (vph[i]>0) vpos[i] /= vph[i];
00194 }
00195 Double_t uzfit[5],ufit[5];
00196 Double_t uwfit[5] = {0.,0.,0.,0.,0.};
00197 Double_t vzfit[5],vfit[5];
00198 Double_t vwfit[5] = {0.,0.,0.,0.,0.};
00199 for (int i=0; i<5; i++) {
00200 uzfit[i] = ufit[i] = vzfit[i] = vfit[i] = 0.0;
00201 Int_t dplane[2]={-1,-1};
00202 Int_t jbest[2]={-1,-1};
00203 for (int j=0; j<1000; j++) {
00204 if (uph[j]>0. && (dplane[0]<0 || TMath::Abs(uplane[j]-plane)<dplane[0])) {
00205 dplane[0] = TMath::Abs(uplane[j]-plane);
00206 uzfit[i] = uzpos[j];
00207 ufit[i] = upos[j];
00208 uwfit[i] = 1.;
00209 jbest[0] = j;
00210 }
00211 if (vph[j]>0. && (dplane[1]<0 || TMath::Abs(vplane[j]-plane)<dplane[1])) {
00212 dplane[1] = TMath::Abs(vplane[j]-plane);
00213 vzfit[i] = vzpos[j];
00214 vfit[i] = vpos[j];
00215 vwfit[i] = 1.;
00216 jbest[1] = j;
00217 }
00218 }
00219 if (jbest[0]>=0) uph[jbest[0]] = 0.;
00220 if (jbest[1]>=0) vph[jbest[1]] = 0.;
00221 }
00222 Double_t uparm[2],ueparm[2];
00223 Double_t vparm[2],veparm[2];
00224 LinearFit::Weighted(5,uzfit,ufit,uwfit,uparm,ueparm);
00225 LinearFit::Weighted(5,vzfit,vfit,vwfit,vparm,veparm);
00226 Double_t dudz = uparm[1];
00227 Double_t dvdz = vparm[1];
00228 Double_t ddz[3] = {uparm[1],vparm[1],1.};
00229
00230
00231 Double_t dt = 1.;
00232 if (GetTimeSlope()<0.) dt = -1.;
00233
00234 return dt*ddz[iuvz]/sqrt(1.+dudz*dudz+dvdz*dvdz);
00235 }
00236
00237 Double_t CandTrackSRHandle::GetDirCosU(Int_t plane) const
00238 {
00239 return GetDirCos(plane,0);
00240 }
00241
00242 Double_t CandTrackSRHandle::GetDirCosV(Int_t plane) const
00243 {
00244 return GetDirCos(plane,1);
00245 }
00246
00247 Double_t CandTrackSRHandle::GetDirCosZ(Int_t plane) const
00248 {
00249 return GetDirCos(plane,2);
00250 }
00251
00252 Double_t CandTrackSRHandle::GetDirCosU() const
00253 {
00254 return CandRecoHandle::GetDirCosU();
00255 }
00256
00257 Double_t CandTrackSRHandle::GetDirCosV() const
00258 {
00259 return CandRecoHandle::GetDirCosV();
00260 }
00261
00262 Double_t CandTrackSRHandle::GetDirCosZ() const
00263 {
00264 return CandRecoHandle::GetDirCosZ();
00265 }
00266
00267 Double_t CandTrackSRHandle::GetScore() const
00268 {
00269
00270
00271
00272 Double_t score = (Double_t)(GetNDaughters());
00273
00274
00275
00276
00277
00278
00279
00280
00281 score += GetCharge()/10.;
00282 return score;
00283 }
00284
00285 Double_t CandTrackSRHandle::GetHoughDirCosU() const
00286 {
00287 Track2DSR *utrack = dynamic_cast<const CandTrackSR*>(GetCandBase())->fUTrack;
00288 Track2DSR *vtrack = dynamic_cast<const CandTrackSR*>(GetCandBase())->fVTrack;
00289 assert(utrack);
00290 assert(vtrack);
00291 Double_t dudz=0.;
00292 Double_t dvdz=0.;
00293 if (!utrack->GetHoughExist() || !vtrack->GetHoughExist()) {
00294 return -999.;
00295 }
00296 dudz = utrack->GetHoughSlope();
00297 dvdz = vtrack->GetHoughSlope();
00298 if (GetTimeSlope()>=0.) {
00299 return dudz/sqrt(1.+dudz*dudz+dvdz*dvdz);
00300 }
00301 else {
00302 return -1.*dudz/sqrt(1.+dudz*dudz+dvdz*dvdz);
00303 }
00304 }
00305
00306 Double_t CandTrackSRHandle::GetHoughDirCosV() const
00307 {
00308 Track2DSR *utrack = dynamic_cast<const CandTrackSR*>(GetCandBase())->fUTrack;
00309 Track2DSR *vtrack = dynamic_cast<const CandTrackSR*>(GetCandBase())->fVTrack;
00310 assert(utrack);
00311 assert(vtrack);
00312 Double_t dudz=0.;
00313 Double_t dvdz=0.;
00314 if (!utrack->GetHoughExist() || !vtrack->GetHoughExist()) {
00315 return -999.;
00316 }
00317 dudz = utrack->GetHoughSlope();
00318 dvdz = vtrack->GetHoughSlope();
00319 if (GetTimeSlope()>=0.) {
00320 return dvdz/sqrt(1.+dudz*dudz+dvdz*dvdz);
00321 }
00322 else {
00323 return -1.*dvdz/sqrt(1.+dudz*dudz+dvdz*dvdz);
00324 }
00325 }
00326
00327 Double_t CandTrackSRHandle::GetHoughDirCosZ() const
00328 {
00329 Track2DSR *utrack = dynamic_cast<const CandTrackSR*>(GetCandBase())->fUTrack;
00330 Track2DSR *vtrack = dynamic_cast<const CandTrackSR*>(GetCandBase())->fVTrack;
00331 assert(utrack);
00332 assert(vtrack);
00333 Double_t dudz=0.;
00334 Double_t dvdz=0.;
00335 if (!utrack->GetHoughExist() || !vtrack->GetHoughExist()) {
00336 return -999.;
00337 }
00338 dudz = utrack->GetHoughSlope();
00339 dvdz = vtrack->GetHoughSlope();
00340 if (GetTimeSlope()>=0.) {
00341 return 1./sqrt(1.+dudz*dudz+dvdz*dvdz);
00342 }
00343 else {
00344 return -1./sqrt(1.+dudz*dudz+dvdz*dvdz);
00345 }
00346 }
00347
00348 Double_t CandTrackSRHandle::GetHoughResid2() const
00349 {
00350 Track2DSR *utrack = dynamic_cast<const CandTrackSR*>(GetCandBase())->fUTrack;
00351 Track2DSR *vtrack = dynamic_cast<const CandTrackSR*>(GetCandBase())->fVTrack;
00352 assert(utrack);
00353 assert(vtrack);
00354 if (!utrack->GetHoughExist() || !vtrack->GetHoughExist()) {
00355 return -999.;
00356 }
00357 Double_t dudz = utrack->GetHoughSlope();
00358 Double_t dvdz = vtrack->GetHoughSlope();
00359 Double_t u0 = utrack->GetHoughIntercept();
00360 Double_t v0 = vtrack->GetHoughIntercept();
00361 Int_t begplane = GetBegPlane();
00362 Int_t endplane = GetEndPlane();
00363 Int_t nplane = TMath::Abs(endplane-begplane)+1;
00364 Float_t *tpos = new Float_t[nplane];
00365 Float_t *zpos = new Float_t[nplane];
00366 Float_t *ph = new Float_t[nplane];
00367 Int_t *planeview = new Int_t[nplane];
00368 TIter stripItr(GetDaughterIterator());
00369 Int_t idir=1;
00370 if (GetTimeSlope()<0.) {
00371 idir = -1;
00372 }
00373 Double_t resid2 = 0.;
00374 for (int i=0; i<nplane; i++) {
00375 stripItr.Reset();
00376 planeview[i] = -1;
00377 tpos[i] = 0.;
00378 zpos[i] = 0.;
00379 ph[i] = 0.;
00380 while (CandStripHandle *strip = dynamic_cast<CandStripHandle*>(stripItr())) {
00381 if (strip->GetPlane()==begplane+i*idir) {
00382 planeview[i] = strip->GetPlaneView();
00383 tpos[i] += strip->GetTPos()*strip->GetCharge();
00384 zpos[i] = strip->GetZPos();
00385 ph[i] += strip->GetCharge();
00386 }
00387 }
00388 if (ph[i]>0.) {
00389 tpos[i] /= ph[i];
00390 if (planeview[i]==PlaneView::kU) {
00391 Double_t dtpos = tpos[i]-(u0+dudz*zpos[i]);
00392 resid2 += dtpos*dtpos;
00393 }
00394 if (planeview[i]==PlaneView::kV) {
00395 Double_t dtpos = tpos[i]-(v0+dvdz*zpos[i]);
00396 resid2 += dtpos*dtpos;
00397 }
00398 }
00399 }
00400 delete [] tpos;
00401 delete [] zpos;
00402 delete [] ph;
00403 delete [] planeview;
00404 return resid2;
00405 }
00406
00407
00408 Double_t CandTrackSRHandle::GetTimeWeight(const CandDigitHandle *digit) const
00409 {
00410
00411
00412
00413
00414 Double_t npe = digit->GetCharge()/60.;
00415
00416 npe = max(npe,1.);
00417 ArrivalTime arrtime;
00418 return arrtime.Weight(npe);
00419
00420 }
00421
00422 Int_t CandTrackSRHandle::GetNTrackPlane(PlaneView::PlaneView_t planeview_t) const
00423 {
00424 CandStripHandleItr stripItr(GetDaughterIterator());
00425 CandStripHandleKeyFunc *stripKf = stripItr.CreateKeyFunc();
00426 stripKf->SetFun(CandStripHandle::KeyFromPlane);
00427 stripItr.GetSet()->AdoptSortKeyFunc(stripKf);
00428 stripKf = 0;
00429
00430 Int_t plane=0;
00431 Int_t oldplane=0;
00432 CandStripHandle *strip;
00433 while ((strip = dynamic_cast<CandStripHandle*>(stripItr()))) {
00434 TIter digitItr(strip->GetDaughterIterator());
00435 if (IsInShower(strip)<=1) {
00436 PlaneView::PlaneView_t planeview = strip->GetPlaneView();
00437 if (planeview!=PlaneView::kA && planeview!=PlaneView::kB &&
00438 (planeview_t==PlaneView::kUnknown || planeview==planeview_t)) {
00439 if (!plane || strip->GetPlane()!=oldplane) {
00440 plane++;
00441 }
00442 oldplane = strip->GetPlane();
00443 }
00444 }
00445 }
00446 return plane;
00447 }
00448
00449 void CandTrackSRHandle::SetNTrackStrip(Int_t n)
00450 {
00451 dynamic_cast<CandTrackSR *>(GetOwnedCandBase())->fNTrackStrip = n;
00452 }
00453
00454 void CandTrackSRHandle::SetNTrackDigit(Int_t n)
00455 {
00456 dynamic_cast<CandTrackSR *>(GetOwnedCandBase())->fNTrackDigit = n;
00457 }
00458
00459 void CandTrackSRHandle::SetNTimeFitDigit(Int_t n)
00460 {
00461 dynamic_cast<CandTrackSR *>(GetOwnedCandBase())->fNTimeFitDigit = n;
00462 }
00463
00464 void CandTrackSRHandle::SetTimeFitChi2(Double_t x)
00465 {
00466 dynamic_cast<CandTrackSR *>(GetOwnedCandBase())->fTimeFitChi2 = x;
00467 }
00468
00469 Int_t CandTrackSRHandle::GetNTrackStrip() const
00470 {
00471 return dynamic_cast<const CandTrackSR *>(GetCandBase())->fNTrackStrip;
00472 }
00473
00474 Int_t CandTrackSRHandle::GetNTrackDigit() const
00475 {
00476 return dynamic_cast<const CandTrackSR *>(GetCandBase())->fNTrackDigit;
00477 }
00478
00479 Int_t CandTrackSRHandle::GetNTimeFitDigit() const
00480 {
00481 return dynamic_cast<const CandTrackSR *>(GetCandBase())->fNTimeFitDigit;
00482 }
00483
00484 Double_t CandTrackSRHandle::GetTimeFitChi2() const
00485 {
00486 return dynamic_cast<const CandTrackSR *>(GetCandBase())->fTimeFitChi2;
00487 }
00488
00489
00490 XXXITRIMP(CandTrackSRHandle)