CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoPixelVertexing/PixelLowPtUtilities/src/LowPtClusterShapeSeedComparitor.cc

Go to the documentation of this file.
00001 #include "RecoPixelVertexing/PixelLowPtUtilities/interface/LowPtClusterShapeSeedComparitor.h"
00002 
00003 #include "RecoPixelVertexing/PixelTrackFitting/src/CircleFromThreePoints.h"
00004 #include "RecoPixelVertexing/PixelLowPtUtilities/interface/HitInfo.h"
00005 #include "RecoPixelVertexing/PixelLowPtUtilities/interface/ClusterShapeHitFilter.h"
00006 
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 
00012 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHit.h"
00013 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
00014 #include "RecoTracker/TkSeedingLayers/interface/SeedingHitSet.h"
00015 
00016 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
00017 
00018 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00019 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00020 #include "DataFormats/GeometryVector/interface/Basic2DVector.h"
00021 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00022 
00023 #include<cmath>
00024 
00025 
00026 
00027 namespace {
00028   typedef Basic2DVector<float>   Vector2D;
00029 
00030   inline float sqr(float x) { return x*x; }
00031 
00032   /*****************************************************************************/
00033   inline
00034   float areaParallelogram
00035   (const Vector2D& a, const Vector2D& b)
00036   {  
00037     return a.x() * b.y() - a.y() * b.x();
00038   }
00039   
00040   /*****************************************************************************/
00041 
00042   inline 
00043   bool getGlobalDirs(GlobalPoint const * g, GlobalVector * globalDirs)
00044   {
00045     
00046     
00047     // Determine circle
00048     CircleFromThreePoints circle(g[0],g[1],g[2]);
00049     
00050     float curvature = circle.curvature();
00051     if(0.f == curvature) {
00052       LogDebug("LowPtClusterShapeSeedComparitor")<<"the curvature is null:"
00053                                                  <<"\n point1: "<<g[0]
00054                                                  <<"\n point2: "<<g[1]
00055                                                  <<"\n point3: "<<g[2];
00056       return false;
00057     }
00058 
00059    // Get 2d points
00060     Vector2D p[3];
00061     Vector2D c  = circle.center();
00062     for(int i=0; i!=3; i++)
00063       p[i] =  g[i].basicVector().xy() -c;
00064  
00065 
00066     float area = std::abs(areaParallelogram(p[1] - p[0], p[1]));
00067     
00068     float a12 = std::asin(std::min(area*curvature*curvature,1.f));
00069     
00070     float slope = (g[1].z() - g[0].z()) / a12;
00071  
00072     // Calculate globalDirs
00073    
00074     float cotTheta = slope * curvature; 
00075     float sinTheta = 1.f/std::sqrt(1.f + sqr(cotTheta));
00076     float cosTheta = cotTheta*sinTheta;
00077     
00078     if (areaParallelogram(p[0], p[1] ) < 0)  sinTheta = - sinTheta;
00079         
00080     for(int i = 0; i!=3;  i++) {
00081       Vector2D vl = p[i]*(curvature*sinTheta);
00082       globalDirs[i] = GlobalVector(-vl.y(),
00083                                     vl.x(),
00084                                     cosTheta
00085                                     );
00086     }
00087     return true;
00088   }
00089 
00090   /*****************************************************************************/
00091 
00092   
00093   inline
00094   void getGlobalPos(const SeedingHitSet &hits, GlobalPoint * globalPoss)
00095   {
00096     
00097     for(unsigned int i=0; i!=hits.size(); ++i)
00098         globalPoss[i] = hits[i]->globalPosition();
00099   }
00100 
00101 } // namespace
00102 
00103 /*****************************************************************************/
00104 void LowPtClusterShapeSeedComparitor::init(const edm::EventSetup& es) {
00105   es.get<CkfComponentsRecord>().get("ClusterShapeHitFilter", theShapeFilter);
00106   es.get<IdealGeometryRecord>().get(theTTopo);
00107 }
00108 
00109 bool LowPtClusterShapeSeedComparitor::compatible(const SeedingHitSet &hits, const TrackingRegion &) const
00110 //(const reco::Track* track, const vector<const TrackingRecHit *> & recHits) const
00111 {
00112   assert(hits.size()==3);
00113 
00114   const ClusterShapeHitFilter * filter = theShapeFilter.product();
00115   assert(filter != 0 && "LowPtClusterShapeSeedComparitor: init(EventSetup) method was not called");
00116 
00117    // Get global positions
00118    GlobalPoint  globalPoss[3];
00119    getGlobalPos(hits, globalPoss);
00120 
00121   // Get global directions
00122   GlobalVector globalDirs[3]; 
00123 
00124   bool ok = getGlobalDirs(globalPoss,globalDirs);
00125 
00126   // Check whether shape of pixel cluster is compatible
00127   // with local track direction
00128 
00129   if (!ok)
00130     {
00131       LogDebug("LowPtClusterShapeSeedComparitor")<<"curvarture 0:"
00132                                                  <<"\nnHits: "<<hits.size()
00133                                                  <<" will say the seed is good anyway.";
00134       return true;
00135     }
00136 
00137   for(int i = 0; i < 3; i++)
00138   {
00139     const SiPixelRecHit* pixelRecHit =
00140       dynamic_cast<const SiPixelRecHit *>(hits[i]->hit());
00141 
00142     if (!pixelRecHit){
00143       edm::LogError("LowPtClusterShapeSeedComparitor")<<"this is not a pixel cluster";
00144       ok = false; break;
00145     }
00146 
00147     if(!pixelRecHit->isValid())
00148     { 
00149       ok = false; break; 
00150     }
00151     
00152     LogDebug("LowPtClusterShapeSeedComparitor")<<"about to compute compatibility."
00153                                                <<"hit ptr: "<<pixelRecHit
00154                                                <<"global direction:"<< globalDirs[i];
00155 
00156 
00157     if(! filter->isCompatible(*pixelRecHit, globalDirs[i]) )
00158     {
00159       LogTrace("LowPtClusterShapeSeedComparitor")
00160          << " clusShape is not compatible"
00161          << HitInfo::getInfo(*hits[i]->hit(),theTTopo.product());
00162 
00163       ok = false; break;
00164     }
00165   }
00166 
00167   return ok;
00168 }
00169