CMS 3D CMS Logo

LayerHitMapLoop.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkHitPairs/interface/LayerHitMap.h"
00002 #include "RecoTracker/TkHitPairs/interface/LayerHitMapLoop.h"
00003 #include "RecoTracker/TkMSParametrization/interface/PixelRecoUtilities.h"
00004 
00005 using namespace std;
00006 
00007 LayerHitMapLoop::LayerHitMapLoop(const LayerHitMap & map)
00008   : theMap(map), safeBinRz(true), setStatus(0)
00009 {
00010   hitItr = theMap.theHits.begin();
00011   hitEnd = theMap.theHits.end();
00012   theNextPhi = skip;
00013 }
00014 
00015 LayerHitMapLoop::LayerHitMapLoop(
00016     const LayerHitMap & map, const RangeF & phiRange, const RangeF & rzRange)
00017   : theMap(map), 
00018     theRangeRz(rzRange), theRangeRzSafe(rzRange),
00019     theRangePhi(phiRange), setStatus(0)
00020 {
00021 
00022   hitItr = hitEnd = theMap.theHits.end();
00023   if (theMap.empty()) { theNextPhi = skip; return; } 
00024 
00025   int irz1 = theMap.idxRz(rzRange.min());
00026   int irz2 = theMap.idxRz(rzRange.max()); 
00027   theBinsRz     = RangeI( max( irz1,  0), min( irz2,  theMap.theNbinsRZ-1));
00028   theBinsRzSafe = RangeI( irz1+1, irz2-1); 
00029 
00030   if (theRangePhi.first >= -M_PI && theRangePhi.second < M_PI) {
00031     theNextPhi = inRange;
00032   } else {
00033     theNextPhi = firstEdge;
00034     while (theRangePhi.first <  -M_PI) theRangePhi.first  += 2*M_PI;
00035     while (theRangePhi.second >= M_PI) theRangePhi.second -= 2*M_PI;
00036   } 
00037 
00038   theBinsPhi  = RangeI (
00039       int ( (theRangePhi.min() + M_PI)/theMap.theCellDeltaPhi ),
00040       int ( (theRangePhi.max() + M_PI)/theMap.theCellDeltaPhi ));
00041 
00042   theBinRz = theBinsRz.min()-1; 
00043 
00044 }
00045 
00046 void LayerHitMapLoop::setSafeRzRange(const RangeF & rzSafe, bool * status)
00047 { 
00048 
00049   theRangeRzSafe = rzSafe;
00050   setStatus = status;
00051 
00052   theBinsRzSafe = 
00053       RangeI( theMap.idxRz(rzSafe.min())+1, theMap.idxRz(rzSafe.max())-1);
00054 
00055 } 
00056 
00057 
00058 const LayerHitMapLoop::TkHitPairsCachedHit * LayerHitMapLoop::getHit()
00059 {
00060 
00061 
00062 
00063   while (hitItr < hitEnd) {
00064 
00065     const TkHitPairsCachedHit * hit = &*hitItr++;
00066     if (safeBinRz)      return hit;
00067    
00068     else if (theRangeRzSafe.inside(hit->rOrZ()))
00069         return hit;
00070     else if (setStatus && theRangeRz.inside(hit->rOrZ())) {
00071       *setStatus = false;
00072       return hit;
00073     }
00074   }
00075 
00076   if (nextRange()) return getHit();
00077   else return 0;
00078 }
00079 
00080 bool LayerHitMapLoop::nextRange()
00081 {
00082 
00083   switch (theNextPhi) {
00084   case inRange:
00085     if (++theBinRz > theBinsRz.max()) return false; 
00086     safeBinRz = theBinsRzSafe.inside(theBinRz);
00087     hitItr = theMap.cell(theBinRz,theBinsPhi.min()).
00088                  range_from(theRangePhi.min()).min();
00089     hitEnd = theMap.cell(theBinRz,theBinsPhi.max()).
00090                  range_upto(theRangePhi.max()).max();
00091     return true;
00092   case firstEdge:
00093     if (++theBinRz > theBinsRz.max()) return false; 
00094     safeBinRz = theBinsRzSafe.inside(theBinRz);
00095     hitItr = theMap.cell(theBinRz,theBinsPhi.min()).
00096                  range_from(theRangePhi.min()).min();
00097     hitEnd = theMap.cell(theBinRz,theMap.theNbinsPhi-1).
00098                  range().max();
00099     theNextPhi = secondEdge;
00100     return true;
00101   case secondEdge:
00102     hitItr = theMap.cell(theBinRz,0).
00103                  range().min();
00104     hitEnd = theMap.cell(theBinRz,theBinsPhi.max()).
00105                  range_upto(theRangePhi.max()).max();
00106     theNextPhi = firstEdge;
00107  
00108     return true;
00109   default: 
00110     return false;
00111   }
00112 }

Generated on Tue Jun 9 17:45:51 2009 for CMSSW by  doxygen 1.5.4