Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

AlgFitThruMuonList Class Reference

#include <AlgFitThruMuonList.h>

Inheritance diagram for AlgFitThruMuonList:

AlgBase List of all members.

Public Member Functions

 AlgFitThruMuonList ()
virtual ~AlgFitThruMuonList ()
virtual void Trace (const char *c) const
virtual void RunAlg (AlgConfig &ac, CandHandle &ch, CandContext &cx)

Private Member Functions

void RunFindStraightTrackAlg (Float_t span, Int_t iterMax, const CandStraightClusterHandle &cch, TObjArray *&hay)

Constructor & Destructor Documentation

AlgFitThruMuonList::AlgFitThruMuonList  ) 
 

Definition at line 44 of file AlgFitThruMuonList.cxx.

00045 {
00046 //
00047 //  Purpose:    Default constructor.
00048 //
00049 //  Arguments:  n/a
00050 //
00051 //  Return:     n/a
00052 //
00053 }

AlgFitThruMuonList::~AlgFitThruMuonList  )  [virtual]
 

Definition at line 57 of file AlgFitThruMuonList.cxx.

00058 {
00059 //
00060 //  Purpose:    Default destructor.
00061 //
00062 //  Arguments:  n/a
00063 //
00064 //  Return:     n/a
00065 //
00066 }


Member Function Documentation

void AlgFitThruMuonList::RunAlg AlgConfig ac,
CandHandle ch,
CandContext cx
[virtual]
 

Implements AlgBase.

Definition at line 70 of file AlgFitThruMuonList.cxx.

References CandHandle::AddDaughterLink(), AlgFactory::GetAlgHandle(), CandContext::GetCandRecord(), CandThruMuonHandle::GetClusterU(), CandThruMuonHandle::GetClusterV(), CandContext::GetDataIn(), CandHandle::GetDaughterIterator(), Registry::GetDouble(), AlgFactory::GetInstance(), Registry::GetInt(), CandContext::GetMom(), CandStripHandle::GetPlaneView(), CandStripHandle::GetStripEndId(), PlexPlaneId::IsVetoShield(), CandThruMuon::MakeCandidate(), MSG, and RunFindStraightTrackAlg().

00072 {
00073 //
00074 //  Purpose:  Improve straight-line fit to a muon track by rejecting
00075 //            digits whose strips do not lie within a specified number
00076 //            of strip widths of the fitted track.
00077 //
00078 //  Arguments:
00079 //    ac        in    AlgConfig containing muon fit parameters.
00080 //    ch        in    Handle to the new CandThruMuonList to fill.
00081 //    cx        in    CandContext containing the CandThruMuonList whose
00082 //                    track fits are to be improved.
00083 //
00084 //  Return:   n/a
00085 //
00086 
00087    MSG("BubAlg", Msg::kVerbose)
00088       << "Starting AlgFitThruMuonList::RunAlg()" << endl;
00089 
00090 // Check for CandThruMuonListHandle input.
00091    assert(cx.GetDataIn());
00092    assert(cx.GetDataIn()->InheritsFrom("CandThruMuonListHandle"));
00093    const CandThruMuonListHandle *cmlh =
00094             dynamic_cast<const CandThruMuonListHandle*>(cx.GetDataIn());
00095 
00096 // Save config parameters for fit rejection.
00097    Float_t fspan = ac.GetDouble("FitSpan");
00098    Int_t   fimax = ac.GetInt("FitIterMax");
00099 
00100 // General setup for creating new CandThruMuons.
00101    MSG("BubAlg", Msg::kVerbose) << "Get AlgThruMuon instance from "
00102       << "AlgThruMuonFactory." << endl;
00103    AlgFactory &af = AlgFactory::GetInstance();
00104    AlgHandle ah = af.GetAlgHandle("AlgThruMuon", "default");
00105 
00106    MSG("BubAlg", Msg::kVerbose)
00107       << "Create CandContext instance." << endl;
00108    CandContext cxx(this, cx.GetMom());
00109    cxx.SetCandRecord(cx.GetCandRecord());
00110 
00111 // Iterate over muons.
00112    TIter cmhItr(cmlh->GetDaughterIterator());
00113    while (CandThruMuonHandle *cmh =
00114              dynamic_cast<CandThruMuonHandle *>(cmhItr())) {
00115       TObjArray mpair(3);
00116 
00117 // Fit cluster U.
00118       const CandStraightClusterHandle *cch = cmh->GetClusterU();
00119       TObjArray *hay;
00120       RunFindStraightTrackAlg(fspan, fimax, *cch, hay);
00121       if (!hay) continue;
00122       mpair.AddAt(hay, 0);
00123 
00124 // Fit cluster V.
00125       cch = cmh->GetClusterV();
00126       RunFindStraightTrackAlg(fspan, fimax, *cch, hay);
00127       if (!hay) {
00128          delete mpair.RemoveAt(0);
00129          continue;
00130       }
00131       mpair.AddAt(hay, 1);
00132 
00133 // Add veto shield/cosmic counter digits, if any.
00134       TObjArray *cosm = 0;
00135       TIter chhItr(cmh->GetDaughterIterator());
00136       while (CandDigiPairHandle *chh =
00137              dynamic_cast<CandDigiPairHandle *>(chhItr())) {
00138 
00139          // Veto shield
00140          if (chh->GetStripEndId().IsVetoShield()) {
00141             if (!cosm) cosm = new TObjArray();
00142             cosm->Add(chh);
00143             continue;
00144          }
00145 
00146          // Caldet cosmic counter
00147          PlaneView::PlaneView_t vw = chh->GetPlaneView();
00148          if ((vw == PlaneView::kA) || (vw == PlaneView::kB)) {
00149             if (!cosm) cosm = new TObjArray();
00150             cosm->Add(chh);
00151          }
00152       }
00153       if (cosm) mpair.AddAt(cosm, 2);
00154 /*
00155       if (cmh->GetNCosmics()) {
00156          TObjArray *cosm = new TObjArray();
00157          TIter chhItr(cmh->GetDaughterIterator());
00158          while (CandDigiPairHandle *chh =
00159                    dynamic_cast<CandDigiPairHandle *>(chhItr())) {
00160             PlaneView::PlaneView_t vw = chh->GetPlaneView();
00161             if ((vw == PlaneView::kA) || (vw == PlaneView::kB))
00162                cosm->Add(chh);
00163          }
00164          mpair.AddAt(cosm, 2);
00165       }
00166 */
00167 
00168 // Create CandThruMuon.
00169       cxx.SetDataIn(&mpair);
00170       CandThruMuonHandle cfh = CandThruMuon::MakeCandidate(ah, cxx);
00171       ch.AddDaughterLink(cfh);
00172       mpair.Delete();
00173    }
00174 }

void AlgFitThruMuonList::RunFindStraightTrackAlg Float_t  span,
Int_t  iterMax,
const CandStraightClusterHandle cch,
TObjArray *&  hay
[private]
 

Definition at line 178 of file AlgFitThruMuonList.cxx.

References CandDigiPairHandle::GetCharge(), CandHandle::GetDaughterIterator(), CandStraightClusterHandle::GetFitDet(), CandStraightClusterHandle::GetFitInter(), CandStraightClusterHandle::GetFitMode(), CandStraightClusterHandle::GetFitSlope(), UgliStripHandle::GetHalfWidth(), CandStripHandle::GetPlane(), CandStripHandle::GetStripEndId(), CandStraightClusterHandle::GetT2sum(), CandStripHandle::GetTPos(), CandStraightClusterHandle::GetTsum(), CandStraightClusterHandle::GetTZsum(), CandHandle::GetVldContext(), CandStraightClusterHandle::GetWtSum(), CandStraightClusterHandle::GetZ2sum(), CandStripHandle::GetZPos(), CandStraightClusterHandle::GetZsum(), UgliStripHandle::IsValid(), and MSG.

Referenced by RunAlg().

00180 {
00181 //
00182 //  Purpose:  Find a straight track from a cluster by iterating until
00183 //            all digits are within a specified number of strip widths
00184 //            of the fitted track.
00185 //
00186 //  Arguments:
00187 //    span      in    Number of strip widths for difference limit.
00188 //    iterMax   in    Maximum number of iterations for fit.
00189 //    cch       in    Handle to cluster from which straight track to be
00190 //                    found.
00191 //    hay       out   New array in which to store digits associated with
00192 //                    straight track.
00193 //
00194 //  Returns:  n/a
00195 //
00196 
00197 // Set default return value.
00198    hay = 0;
00199 
00200 // Set fit mode.
00201    int modeZT = cch.GetFitMode();
00202 
00203 // Initialize stats.
00204    Float_t xsum, x2sum, ysum;
00205    Float_t xysum = cch.GetTZsum();
00206    Float_t wtsum = cch.GetWtSum();
00207    if (modeZT) {
00208       xsum  = cch.GetTsum();
00209       x2sum = cch.GetT2sum();
00210       ysum  = cch.GetZsum();
00211    }
00212    else {
00213       xsum  = cch.GetZsum();
00214       x2sum = cch.GetZ2sum();
00215       ysum  = cch.GetTsum();
00216    }
00217 
00218 // Check for negative determinant.
00219    Float_t det = cch.GetFitDet();
00220    if (det < 0) {
00221       MSG("BubAlg", Msg::kWarning)
00222          << "Determinant of fit negative." << endl;
00223       return;
00224    }
00225 
00226 // Initialize fit parameters.
00227    Float_t intercept = cch.GetFitInter();
00228    Float_t slope = cch.GetFitSlope();
00229    Float_t slope2_1 = slope * slope + 1;
00230 
00231 // Find strip width using first digitized strip.
00232    Float_t cellwidth = 0;
00233    TIter chhItr(cch.GetDaughterIterator());
00234    while (const CandDigiPairHandle *chht =
00235              dynamic_cast<const CandDigiPairHandle *>(chhItr())) {
00236       UgliGeomHandle ugh(*chht->GetVldContext());
00237       UgliStripHandle ush = ugh.GetStripHandle(chht->GetStripEndId());
00238       if (ush.IsValid()) {
00239          cellwidth = ush.GetHalfWidth();
00240          cellwidth *= 2.0;
00241          break;
00242       }
00243    }
00244 
00245 // Set difference check limit.
00246    Float_t d2check = span * cellwidth;
00247    d2check *= d2check;
00248 
00249 // Create temporary clusters of good and bad digit pairs.
00250    TObjArray *fitCls = new TObjArray(40);
00251    TObjArray unfit;
00252 
00253 // Iterate over cluster digit pairs.
00254    chhItr.Reset();
00255    while (CandDigiPairHandle *chh =
00256              dynamic_cast<CandDigiPairHandle *>(chhItr())) {
00257 
00258 // Retrieve data.
00259       Float_t xdat, ydat;
00260       if (modeZT) {
00261          xdat = chh->GetTPos();
00262          ydat = chh->GetZPos();
00263       }
00264       else {
00265          xdat = chh->GetZPos();
00266          ydat = chh->GetTPos();
00267       }
00268 
00269 // Check fit.
00270       Float_t d2diff = ydat - intercept - slope * xdat;
00271       d2diff *= d2diff;
00272       d2diff /= slope2_1;
00273       if (d2diff <= d2check) {
00274 
00275 // Good fit, so add to fit cluster.
00276          fitCls->Add(chh);
00277       }
00278 
00279 // Bad fit, so add to unfit array and update stats.
00280       else {
00281          unfit.Add(chh);
00282          Float_t wt = chh->GetCharge();
00283          xsum  -= wt * xdat;
00284          ysum  -= wt * ydat;
00285          xysum -= wt * xdat * ydat;
00286          x2sum -= wt * xdat * xdat;
00287          wtsum -= wt;
00288       }
00289    }
00290 
00291 // Check that there are enough points included.
00292    if (fitCls->GetEntries() <= 1) {
00293       MSG("BubAlg", Msg::kWarning)
00294          << "Not enough points for fit." << endl;
00295       return;
00296    }
00297 
00298 // Loop until no digits added or removed.
00299    Bool_t changed;
00300    Int_t  numiter = 0;
00301    do {
00302       changed = kFALSE;
00303       numiter++;
00304 
00305 // Check for negative determinant.
00306       det = wtsum * x2sum - xsum * xsum;
00307       if (det < 0) {
00308          MSG("BubAlg", Msg::kWarning)
00309             << "Determinant of fit negative." << endl;
00310          return;
00311       }
00312 
00313 // Calculate fit parameters.
00314       if (det != 0) {
00315          intercept = (-xysum * xsum + ysum * x2sum) / det;
00316          slope = (-xsum * ysum + wtsum * xysum) / det;
00317          slope2_1 = slope * slope + 1;
00318       }
00319       else {
00320          intercept = ysum / wtsum;
00321          slope = 0;
00322          slope2_1 = 1;
00323       }
00324 
00325 // Iterate over digits in rejects to check for new additions.
00326       TIter unfhItr(&unfit);
00327       while (CandDigiPairHandle *unfh =
00328                 dynamic_cast<CandDigiPairHandle *>(unfhItr())) {
00329 
00330 // Retrieve data.
00331          Float_t xdat, ydat;
00332          if (modeZT) {
00333             xdat = unfh->GetTPos();
00334             ydat = unfh->GetZPos();
00335          }
00336          else {
00337             xdat = unfh->GetZPos();
00338             ydat = unfh->GetTPos();
00339          }
00340 
00341 // Check fit.
00342          Float_t d2diff = ydat - intercept - slope * xdat;
00343          d2diff *= d2diff;
00344          d2diff /= slope2_1;
00345          if (d2diff <= d2check) {
00346 
00347 // Good fit, so add to fit cluster and update stats.
00348             fitCls->Add(unfit.Remove(unfh));
00349             Float_t wt = unfh->GetCharge();
00350             xsum  += wt * xdat;
00351             ysum  += wt * ydat;
00352             xysum += wt * xdat * ydat;
00353             x2sum += wt * xdat * xdat;
00354             wtsum += wt;
00355             changed = kTRUE;
00356          }
00357       }
00358 
00359 // Iterate over digits in fit cluster to check for new rejects.
00360       TIter fithItr(fitCls);
00361       while (CandDigiPairHandle *fith =
00362                 dynamic_cast<CandDigiPairHandle *>(fithItr())) {
00363 
00364 // Retrieve data.
00365          Float_t xdat, ydat;
00366          if (modeZT) {
00367             xdat = fith->GetTPos();
00368             ydat = fith->GetZPos();
00369          }
00370          else {
00371             xdat = fith->GetZPos();
00372             ydat = fith->GetTPos();
00373          }
00374 
00375 // Check fit.
00376          Float_t d2diff = ydat - intercept - slope * xdat;
00377          d2diff *= d2diff;
00378          d2diff /= slope2_1;
00379          if (d2diff > d2check) {
00380 
00381 // Bad fit, so remove from fit cluster and update stats.
00382             unfit.Add(fitCls->Remove(fith));
00383             Float_t wt = fith->GetCharge();
00384             xsum  -= wt * xdat;
00385             ysum  -= wt * ydat;
00386             xysum -= wt * xdat * ydat;
00387             x2sum -= wt * xdat * xdat;
00388             wtsum -= wt;
00389             changed = kTRUE;
00390          }
00391       }
00392    } while (changed && (numiter <= iterMax));
00393 
00394 // Reject vertical clusters.
00395    TIter checkItr(fitCls->MakeIterator());
00396    CandDigiPairHandle *chh =
00397                        dynamic_cast<CandDigiPairHandle *>(checkItr());
00398    if(!chh) return;
00399    Int_t currpln = chh->GetPlane();
00400    while ( ( chh = dynamic_cast<CandDigiPairHandle *>(checkItr()) ) ) {
00401       if (chh->GetPlane() != currpln) {
00402 
00403 // Found straight non-vertical track.
00404          hay = fitCls;
00405          return;
00406       }
00407    }
00408 }

void AlgFitThruMuonList::Trace const char *  c  )  const [virtual]
 

Reimplemented from AlgBase.

Definition at line 412 of file AlgFitThruMuonList.cxx.

References MSG.

00413 {
00414 //
00415 //  Purpose:  Trace the AlgFitThruMuonList.
00416 //
00417 //  Arguments:
00418 //    c          in    String tag for the trace.
00419 //
00420 //  Return:   n/a
00421 //
00422 
00423   MSG("BubCand", Msg::kDebug)
00424     << "**********Begin AlgFitThruMuonList::Trace(\"" << c << "\")"
00425     << endl
00426     << "**********End AlgFitThruMuonList::Trace(\"" << c << "\")"
00427     << endl;
00428 }


The documentation for this class was generated from the following files:
Generated on Thu Nov 1 15:55:24 2007 for loon by  doxygen 1.3.9.1