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

AlgClusterSRList Class Reference

#include <AlgClusterSRList.h>

Inheritance diagram for AlgClusterSRList:

AlgBase List of all members.

Public Member Functions

 AlgClusterSRList ()
virtual ~AlgClusterSRList ()
virtual void RunAlg (AlgConfig &ac, CandHandle &ch, CandContext &cx)
virtual void Trace (const char *c) const
void GenNeighborMap (AlgConfig &ac, CandSliceHandle &csh)

Static Public Member Functions

NavKey StripKeyFromPlane (const CandStripHandle *)

Private Attributes

std::map< const CandStripHandle *,
Int_t > 
fNNeighbors

Constructor & Destructor Documentation

AlgClusterSRList::AlgClusterSRList  ) 
 

Definition at line 46 of file AlgClusterSRList.cxx.

00047 {
00048 }

AlgClusterSRList::~AlgClusterSRList  )  [virtual]
 

Definition at line 51 of file AlgClusterSRList.cxx.

00052 {
00053 }


Member Function Documentation

void AlgClusterSRList::GenNeighborMap AlgConfig ac,
CandSliceHandle csh
 

Generate a neighbor map which holds for each CandStrip in the CandSlice the number of neighbor CandStrips, defined to be the number of CandStrips on the same plane having times within StripNeighborTimeDiff, and which lie within StripNeighborStripDiff strips.

Definition at line 278 of file AlgClusterSRList.cxx.

References abs(), fNNeighbors, CandStripHandle::GetBegTime(), CandHandle::GetDaughterIterator(), Registry::GetDouble(), Registry::GetInt(), CandStripHandle::GetPlane(), CandStripHandle::GetStrip(), and StripKeyFromPlane().

Referenced by RunAlg().

00278                                                                         {
00279   CandStripHandleItr strip1Itr(csh.GetDaughterIterator());
00280   CandStripHandleItr strip2Itr(csh.GetDaughterIterator());
00281   CandStripHandleKeyFunc *strip1Kf = strip1Itr.CreateKeyFunc();
00282   CandStripHandleKeyFunc *strip2Kf = strip2Itr.CreateKeyFunc();
00283   strip1Kf->SetFun(AlgClusterSRList::StripKeyFromPlane);
00284   strip2Kf->SetFun(AlgClusterSRList::StripKeyFromPlane);
00285   strip1Itr.GetSet()->AdoptSortKeyFunc(strip1Kf);
00286   strip2Itr.GetSet()->AdoptSortKeyFunc(strip2Kf);
00287   strip1Kf = 0;
00288   strip2Kf = 0;
00289 
00290   Double_t timediff = ac.GetDouble("StripNeighborTimeDiff");
00291   Int_t stripdiff = ac.GetInt("StripNeighborStripDiff");
00292 
00293   while (CandStripHandle *strip1 = strip1Itr()) {
00294     Int_t neighbor = 0;
00295     Int_t dstrip;
00296     Double_t dtime;
00297     //    strip2Itr.GetSet()->ClearSlice();
00298     //   strip2Itr.GetSet()->Slice(strip1->GetPlane());
00299     strip2Itr.Reset();
00300     while (CandStripHandle *strip2 = strip2Itr() )  {
00301       if(strip2->GetPlane()>strip1->GetPlane()) break;
00302       if ((strip1 != strip2) && (strip1->GetPlane()==strip2->GetPlane()) ) {
00303         dtime = strip2->GetBegTime()-strip1->GetBegTime();
00304         dstrip = strip2->GetStrip()-strip1->GetStrip();
00305         if (fabs(dtime)<=timediff && abs(dstrip)<=stripdiff) {
00306           neighbor++;
00307         }
00308       }
00309     }
00310     fNNeighbors[strip1] = neighbor;
00311   }
00312 }

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

The first action taken in AlgClusterSRList::RunAlg is to generate a neighbor map, which holds for each CandStrip in the CandSlice the number of neighbor CandStrips, defined to be the number of CandStrips on the same plane having times within StripNeighborTimeDiff, and which lie within StripNeighborStripDiff strips. Having determined the number of neighbors for each CandStrip, we loop over views. For each view, the following clustering algorithm is applied to all non-spectrometer planes (or all planes in the far detector). We first iterate over all CandStrips in the view satisfying this plane cut. For each CandStrip, we iterate over previously constructed CandClusters, determining whether the strip should be added to an existing cluster. For each CandCluster, we select CandStrips which lie within +/- StripNeighborPlaneDiff of the primary CandStrip. In the far detector, this interval is extended by SMPlaneFirst-SMPlaneLast-1 (3) planes on the low plane side if the CandStrip plane is StripNeighborPlaneDiff or more lower than the first plane in SM2 (SMPlaneFirst) or by the same number of planes on the high plane side if the CandStrip plane is StripNeighborPlaneDiff or more higher than the last plane in SM1 (SMPlaneLast). We now iterate over this CandStrip set within the CandCluster. If a CandStrip in this set lies in the same plane as the primary CandStrip, we compare the timing and strip difference using the same criteria employed to define strip neighbors. If a CandStrip in this set lies in a different plane from the primary CandStrip, we use these criteria, and in addition require that the CandStrip lie within a transverse distance of StripNeighborTPosDiffShower if the primary CandStrip was found to have neighbors in the initial step, or within StripNeighborTPosDiffTrack if the CandStrip was found to be isolated. If these criteria are met for any CandStrip in the selected set, the primary CandStrip is added to this CandCluster. If a match is found for multiple CandClusters, these clusters are merged. If, after iterating over existing CandClusters, no match is found, a new CandCluster is created with a single daughter - the primary CandStrip. If the primary CandStrip has strip neighbors, the new CandCluster is labeled 'showerlike'. If not, it is labeled 'tracklike'.

Implements AlgBase.

Definition at line 60 of file AlgClusterSRList.cxx.

References abs(), CandHandle::AddDaughterLink(), fNNeighbors, GenNeighborMap(), AlgFactory::GetAlgHandle(), CandClusterHandle::GetBegPlane(), CandSliceHandle::GetBegPlane(), CandStripHandle::GetBegTime(), CandClusterHandle::GetCharge(), CandStripHandle::GetCharge(), CandContext::GetDataIn(), CandHandle::GetDaughterIterator(), VldContext::GetDetector(), Registry::GetDouble(), CandClusterHandle::GetEndPlane(), CandSliceHandle::GetEndPlane(), AlgFactory::GetInstance(), Registry::GetInt(), CandContext::GetMom(), CandHandle::GetNDaughters(), CandStripHandle::GetPlane(), CandClusterHandle::GetPlaneView(), CandStripHandle::GetPlaneView(), CandStripHandle::GetStrip(), CandStripHandle::GetTPos(), CandHandle::GetUidInt(), CandHandle::GetVldContext(), CandClusterHandle::IsShowerLike(), CandClusterHandle::IsTrackLike(), CandCluster::MakeCandidate(), max(), min(), CandHandle::RemoveDaughter(), and CandClusterHandle::SetCandSlice().

00061 {
00062 
00063   Double_t timediff = ac.GetDouble("StripNeighborTimeDiff");
00064   Int_t stripdiff = ac.GetInt("StripNeighborStripDiff");
00065   Double_t tposdiffshower = ac.GetDouble("StripNeighborTPosDiffShower");
00066   Double_t tposdifftrack = ac.GetDouble("StripNeighborTPosDiffTrack");
00067   Int_t planediff = ac.GetInt("StripNeighborPlaneDiff");
00068   Double_t minpulseheight = ac.GetDouble("MinPulseHeight");
00069   Double_t minshwstripPE = ac.GetDouble("MinShwStripPE");
00070   Int_t minplanecoverageshower = ac.GetInt("MinPlaneCoverageShower");
00071   Int_t minplanecoveragetrack = ac.GetInt("MinPlaneCoverageTrack");
00072   Int_t minplaneneighbor = ac.GetInt("MinPlaneNeighbor");
00073   Int_t sm1LastPlane = ac.GetInt("SMPlaneLast");
00074   Int_t sm2FirstPlane = ac.GetInt("SMPlaneFirst");
00075   assert(cx.GetDataIn());
00076 
00077 // Check for CandSliceListHandle input
00078   if (!(cx.GetDataIn()->InheritsFrom("CandSliceListHandle"))) {
00079     return;
00080   }
00081 
00082   const CandSliceListHandle *cslh =
00083         dynamic_cast<const CandSliceListHandle*>(cx.GetDataIn());
00084 
00085   CandContext cxx(this,cx.GetMom());
00086   AlgFactory &af = AlgFactory::GetInstance();
00087   AlgHandle ah = af.GetAlgHandle("AlgClusterSR","default");
00088 
00089   CandSliceHandleItr sliceItr(cslh->GetDaughterIterator());
00090   while (CandSliceHandle *slice = sliceItr()) {
00091 
00092     Int_t planeExtent = slice->GetEndPlane()-slice->GetBegPlane()+1;
00093 
00094     /* Generate the neighbor map, which for each CandStrip in the CandSlice holds the number of neighbor CandStrips, defined to be the number of CandStrips on the same plane having times within StripNeighborTimeDiff, and which lie within StripNeighborStripDiff strips.*/
00095 
00096     GenNeighborMap(ac,*slice);
00097 
00098     // loop over views
00099 
00100     for (Int_t view=PlaneView::kU; view<=PlaneView::kV; view++) {
00101 
00102       /* For each non-spectrometer CandStrip, we iterate over previously constructed CandClusters, determining whether the strip should be added to an existing cluster. To be added, the strip must have neighbors, and the cluster must be showerlike. . */
00103 
00104       CandStripHandleItr stripItr(slice->GetDaughterIterator());
00105       while (CandStripHandle *strip = stripItr()) {
00106 
00107         // don't cluster in muon spectrometer
00108         if (strip->GetPlaneView()==view &&
00109             (cslh->GetVldContext()->GetDetector()!=DetectorType::kNear ||
00110             strip->GetPlane()<=121)) {
00111           Int_t striphasneighbors(0);
00112           if (fNNeighbors[strip]>=minplaneneighbor) {
00113             striphasneighbors = 1;
00114           }
00115           // iterate over clusters
00116           Int_t nfound = 0;
00117           CandClusterHandle *foundcluster = 0;
00118           CandClusterHandleItr clusterItr(ch.GetDaughterIterator());
00119           CandClusterHandleKeyFunc *clusterKf = clusterItr.CreateKeyFunc();
00120           clusterKf->SetFun(CandClusterHandle::KeyFromSlice);
00121           clusterItr.GetSet()->AdoptSortKeyFunc(clusterKf);
00122           clusterKf = 0;
00123           clusterItr.GetSet()->Slice(static_cast<Int_t>(slice->GetUidInt()));
00124           while (CandClusterHandle *cluster = clusterItr()) {
00125             if (cluster->GetPlaneView()==view &&
00126                 ((striphasneighbors && 
00127                  cluster->IsShowerLike()) ||
00128                   planeExtent<minplanecoveragetrack)) {
00129 
00130               /*  For each CandCluster, we select daughter CandStrips which lie within +/- StripNeighborPlaneDiff of the outer loop CandStrip.  In the far detector, this interval is extended by SMPlaneFirst-SMPlaneLast-1 (3) planes on the low plane side if the CandStrip plane is StripNeighborPlaneDiff or more lower than the first plane in SM2 (SMPlaneFirst) or by the same number of planes on the high plane side if the CandStrip plane is StripNeighborPlaneDiff or more higher than the last plane in SM1 (SMPlaneLast). */
00131               CandStripHandleItr clsstripItr(cluster->GetDaughterIterator());
00132               CandStripHandleKeyFunc *clsstripKf = clsstripItr.CreateKeyFunc();
00133               clsstripKf->SetFun(CandStripHandle::KeyFromPlane);
00134               clsstripItr.GetSet()->AdoptSortKeyFunc(clsstripKf);
00135               clsstripKf = 0;
00136 
00137               if (cslh->GetVldContext()->GetDetector()==DetectorType::kFar &&
00138                   strip->GetPlane()-planediff<sm2FirstPlane) {
00139                 Int_t dgap = sm2FirstPlane-sm1LastPlane-1;
00140                 clsstripItr.GetSet()->Slice(strip->GetPlane()-planediff-dgap,
00141                                             strip->GetPlane()+planediff);
00142               }
00143               else if (cslh->GetVldContext()->GetDetector()==DetectorType::kFar &&
00144                 strip->GetPlane()+planediff>sm1LastPlane) {
00145                 Int_t dgap = sm2FirstPlane-sm1LastPlane-1;
00146                 clsstripItr.GetSet()->Slice(strip->GetPlane()-planediff,
00147                                             strip->GetPlane()+planediff+dgap);
00148               }
00149               else {
00150                 clsstripItr.GetSet()->Slice(strip->GetPlane()-planediff,
00151                                             strip->GetPlane()+planediff);
00152               }
00153 
00154               /* We now iterate over this CandStrip set within the CandCluster.  If a CandStrip in this set lies in the same plane as the primary CandStrip, we compare the timing and strip difference  */
00155 
00156               Bool_t lfound(0);
00157               for (CandStripHandle *clsstrip = clsstripItr();
00158                    !lfound && clsstrip; clsstrip = clsstripItr()) {
00159                 Double_t dtime = clsstrip->GetBegTime()-strip->GetBegTime();
00160                 if (clsstrip->GetPlane() == strip->GetPlane()) {
00161                   Int_t dstrip = clsstrip->GetStrip()-strip->GetStrip();
00162                   if (fabs(dtime)<=timediff && 
00163                       abs(dstrip)<=stripdiff) {
00164                     lfound = 1;
00165                   }
00166                 }
00167 
00168                 /*  If a CandStrip in this set lies in a different plane from the primary CandStrip, we use these criteria, and in addition require that the CandStrip lie within a transverse distance of StripNeighborTPosDiffShower if the primary CandStrip was found to have neighbors in the initial step, or within StripNeighborTPosDiffTrack if the CandStrip was found to be isolated. */
00169 
00170                 else {
00171                   Int_t dplane = clsstrip->GetPlane()-strip->GetPlane();
00172                   Double_t dtpos = strip->GetTPos()-clsstrip->GetTPos();
00173                   Int_t planediffcorr = planediff;
00174                   // if cluster crossed SM boundary, increase allowable plane separation
00175                   if (cslh->GetVldContext()->GetDetector()==DetectorType::kFar &&
00176                       min(clsstrip->GetPlane(),strip->GetPlane())<=
00177                       sm1LastPlane &&
00178                       max(clsstrip->GetPlane(),strip->GetPlane())>=
00179                       sm2FirstPlane) {
00180                     planediffcorr += sm2FirstPlane-sm1LastPlane-1;
00181                   }
00182 
00183                   if (fabs(dtime)<=timediff && 
00184                       abs(dplane)<=planediffcorr &&
00185                       ((striphasneighbors && fabs(dtpos)<=tposdiffshower) ||
00186                        (!striphasneighbors && fabs(dtpos)<=tposdifftrack))) {
00187                     lfound = 1;
00188                   }
00189                 }
00190               }
00191               if (lfound) {
00192                 if (!nfound) {            
00193                   // this is the first cluster match - add strip to daughter list
00194                   cluster->AddDaughterLink(*strip);
00195                   foundcluster = cluster;
00196                 }
00197                 else {
00198                   // multiple matchs were found - merge this one with the first
00199                   TObjArray trashbin;
00200                   CandStripHandleItr
00201                     newstripItr(cluster->GetDaughterIterator());
00202                   while (CandStripHandle *newstrip = newstripItr()) {
00203                     foundcluster->AddDaughterLink(*newstrip);
00204                     trashbin.Add(newstrip);
00205                   }
00206                   for (Int_t i=0; i<=trashbin.GetLast(); i++) {
00207                     CandStripHandle *trashstrip =
00208                       dynamic_cast<CandStripHandle*>(trashbin.At(i));
00209                     cluster->RemoveDaughter(trashstrip);
00210                   }
00211                 }
00212                 nfound++;
00213               }
00214             }
00215           }
00216 // remove merged clusters here for efficiency
00217           TObjArray trashbin;
00218           clusterItr.Reset();
00219           while (CandClusterHandle *cluster = clusterItr()) {
00220             if (cluster->GetNDaughters()==0) {
00221               trashbin.Add(cluster);
00222             }
00223           }
00224           for (Int_t i=0; i<=trashbin.GetLast(); i++) {
00225             CandClusterHandle *trashcluster =
00226               dynamic_cast<CandClusterHandle*>(trashbin.At(i));
00227             ch.RemoveDaughter(trashcluster);
00228           }
00229           // no match was found - start a new cluster
00230           //If the primary CandStrip has strip neighbors, the new CandCluster is labeled 'showerlike'.  If not, it is labeled 'tracklike'.
00231           if (!nfound) {
00232             TObjArray striparray;
00233             striparray.Add(strip);
00234             cxx.SetDataIn(&striparray);
00235             CandClusterHandle clusterhandle = 
00236               CandCluster::MakeCandidate(ah,cxx);
00237             clusterhandle.SetCandSlice(slice);
00238             if (striphasneighbors || 
00239                 (planeExtent<minplanecoveragetrack && strip->GetCharge()>minshwstripPE)) {
00240               clusterhandle.IsShowerLike(1);
00241               clusterhandle.IsTrackLike(0);
00242             }
00243             else {
00244               clusterhandle.IsShowerLike(0);
00245               clusterhandle.IsTrackLike(1);
00246             }
00247             ch.AddDaughterLink(clusterhandle);
00248           }
00249         }
00250       }
00251     }
00252   }
00253 
00254   // remove clusters which are below threshold
00255   TObjArray trashbin;
00256   CandClusterHandleItr clusterItr(ch.GetDaughterIterator());
00257   while (CandClusterHandle *cluster = clusterItr()) {
00258     Int_t dplane = cluster->GetEndPlane()-cluster->GetBegPlane()+1;
00259     if (cluster->GetNDaughters()==0 || cluster->GetCharge()<minpulseheight ||
00260         (cluster->IsShowerLike() && dplane<minplanecoverageshower) ||
00261         (cluster->IsTrackLike() && dplane<minplanecoveragetrack)) {
00262       trashbin.Add(cluster);
00263     }
00264   }
00265   for (Int_t i=0; i<=trashbin.GetLast(); i++) {
00266     CandClusterHandle *trashcluster =
00267       dynamic_cast<CandClusterHandle*>(trashbin.At(i));
00268     ch.RemoveDaughter(trashcluster);
00269   }
00270 
00271 
00272 }

NavKey AlgClusterSRList::StripKeyFromPlane const CandStripHandle  )  [static]
 

Definition at line 314 of file AlgClusterSRList.cxx.

Referenced by GenNeighborMap().

00315 {
00316   return const_cast<CandStripHandle *>(strip)->GetPlane();
00317 }

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

Reimplemented from AlgBase.

Definition at line 322 of file AlgClusterSRList.cxx.

00323 {
00324 }


Member Data Documentation

std::map<const CandStripHandle*, Int_t> AlgClusterSRList::fNNeighbors [private]
 

Definition at line 33 of file AlgClusterSRList.h.

Referenced by GenNeighborMap(), and RunAlg().


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