CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoLocalTracker/SiPixelRecHits/plugins/PixelCPEBase.h

Go to the documentation of this file.
00001 #ifndef RecoLocalTracker_SiPixelRecHits_PixelCPEBase_H
00002 #define RecoLocalTracker_SiPixelRecHits_PixelCPEBase_H 1
00003 
00004 //-----------------------------------------------------------------------------
00005 // \class        PixelCPEBase
00006 // \description  Base class for pixel CPE's, with all the common code.
00007 // Perform the position and error evaluation of pixel hits using 
00008 // the Det angle to estimate the track impact angle.
00009 // Move geomCorrection to the concrete class. d.k. 06/06.
00010 // change to use Lorentz angle from DB Lotte Wilke, Jan. 31st, 2008
00011 // Change to use Generic error & Template calibration from DB - D.Fehling 11/08
00012 //-----------------------------------------------------------------------------
00013 
00014 #include <utility>
00015 #include <vector>
00016 #include "TMath.h"
00017 
00018 #include "RecoLocalTracker/ClusterParameterEstimator/interface/PixelClusterParameterEstimator.h"
00019 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitQuality.h"
00020 
00021 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00022 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00023 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00024 #include "Geometry/CommonTopologies/interface/Topology.h"
00025 
00026 //--- For the configuration:
00027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00028 
00029 //#define TP_OLD
00030 #ifdef TP_OLD
00031 #include "Geometry/CommonDetAlgo/interface/MeasurementPoint.h"
00032 #include "Geometry/CommonDetAlgo/interface/MeasurementError.h"
00033 #include "Geometry/Surface/interface/GloballyPositioned.h"
00034 #else  // new location
00035 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
00036 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h"
00037 #include "DataFormats/GeometrySurface/interface/GloballyPositioned.h"
00038 #endif
00039 
00040 #include "CondFormats/SiPixelObjects/interface/SiPixelLorentzAngle.h"
00041 #include "CondFormats/SiPixelObjects/interface/SiPixelCPEGenericErrorParm.h"
00042 #include "CondFormats/SiPixelObjects/interface/SiPixelTemplateDBObject.h"
00043 
00044 
00045 
00046 #include <ext/hash_map>
00047 
00048 #include <iostream>
00049 
00050 
00051 
00052 class MagneticField;
00053 class PixelCPEBase : public PixelClusterParameterEstimator 
00054 {
00055  public:
00056   // PixelCPEBase( const DetUnit& det );
00057   PixelCPEBase(edm::ParameterSet const& conf, const MagneticField * mag = 0, 
00058                const SiPixelLorentzAngle * lorentzAngle = 0, const SiPixelCPEGenericErrorParm * genErrorParm = 0, 
00059                const SiPixelTemplateDBObject * templateDBobject = 0);
00060   
00061   //--------------------------------------------------------------------------
00062   // Obtain the angles from the position of the DetUnit.
00063   // LocalValues is typedef for pair<LocalPoint,LocalError> 
00064   //--------------------------------------------------------------------------
00065   inline LocalValues localParameters( const SiPixelCluster & cl, 
00066                                       const GeomDetUnit    & det ) const 
00067     {
00068       nRecHitsTotal_++ ;
00069       setTheDet( det, cl );
00070       computeAnglesFromDetPosition(cl, det);
00071       
00072       // localPosition( cl, det ) must be called before localError( cl, det ) !!!
00073       LocalPoint lp = localPosition( cl, det );
00074       LocalError le = localError( cl, det );        
00075       
00076       return std::make_pair( lp, le );
00077     }
00078   
00079   //--------------------------------------------------------------------------
00080   // In principle we could use the track too to obtain alpha and beta.
00081   //--------------------------------------------------------------------------
00082   inline LocalValues localParameters( const SiPixelCluster & cl,
00083                                       const GeomDetUnit    & det, 
00084                                       const LocalTrajectoryParameters & ltp) const 
00085     {
00086       nRecHitsTotal_++ ;
00087       setTheDet( det, cl );
00088       computeAnglesFromTrajectory(cl, det, ltp);
00089       
00090       // localPosition( cl, det ) must be called before localError( cl, det ) !!!
00091       LocalPoint lp = localPosition( cl, det ); 
00092       LocalError le = localError( cl, det );        
00093       
00094       return std::make_pair( lp, le );
00095     } 
00096   
00097   //--------------------------------------------------------------------------
00098   // The third one, with the user-supplied alpha and beta
00099   //--------------------------------------------------------------------------
00100   inline LocalValues localParameters( const SiPixelCluster & cl,
00101                                       const GeomDetUnit    & det, 
00102                                       float alpha, float beta) const 
00103     {
00104       nRecHitsTotal_++ ;
00105       alpha_ = alpha;
00106       beta_  = beta;
00107       double HalfPi = 0.5*TMath::Pi();
00108       cotalpha_ = tan(HalfPi - alpha_);
00109       cotbeta_  = tan(HalfPi - beta_ );
00110       setTheDet( det, cl );
00111       
00112       // localPosition( cl, det ) must be called before localError( cl, det ) !!!
00113       LocalPoint lp = localPosition( cl, det ); 
00114       LocalError le = localError( cl, det );        
00115       
00116       return std::make_pair( lp, le );
00117     }
00118   
00119   
00120   //--------------------------------------------------------------------------
00121   // Allow the magnetic field to be set/updated later.
00122   //--------------------------------------------------------------------------
00123   inline void setMagField(const MagneticField *mag) const { magfield_ = mag; }
00124   
00125   //--------------------------------------------------------------------------
00126   // This is where the action happens.
00127   //--------------------------------------------------------------------------
00128   virtual LocalPoint localPosition(const SiPixelCluster& cl, const GeomDetUnit & det) const;  // = 0, take out dk 8/06
00129   virtual LocalError localError   (const SiPixelCluster& cl, const GeomDetUnit & det) const = 0;
00130   
00131   
00132   
00133   //--------------------------------------------------------------------------
00134   //--- Accessors of other auxiliary quantities
00135   inline float probabilityX()  const { return probabilityX_ ;  }
00136   inline float probabilityY()  const { return probabilityY_ ;  }
00137   inline float probabilityXY() const {
00138     if ( probabilityX_ !=0 && probabilityY_ !=0 ) 
00139       {
00140         return probabilityX_ * probabilityY_ * (1 - log(probabilityX_ * probabilityY_) ) ;
00141       }
00142     else 
00143       return 0;
00144   }
00145   
00146   inline float probabilityQ()  const { return probabilityQ_ ;  }
00147   inline float qBin()          const { return qBin_ ;          }
00148   inline bool  isOnEdge()      const { return isOnEdge_ ;      }
00149   inline bool  hasBadPixels()  const { return hasBadPixels_ ;  }
00150   inline bool  spansTwoRocks() const { return spansTwoROCs_ ;  }
00151   inline bool  hasFilledProb() const { return hasFilledProb_ ; }
00152   
00153   
00154   //-----------------------------------------------------------------------------
00159   //-----------------------------------------------------------------------------
00160   virtual SiPixelRecHitQuality::QualWordType rawQualityWord() const;
00161 
00162 
00163  protected:
00164   //--- All methods and data members are protected to facilitate (for now)
00165   //--- access from derived classes.
00166 
00167   typedef GloballyPositioned<double> Frame;
00168 
00169   //---------------------------------------------------------------------------
00170   //  Data members
00171   //---------------------------------------------------------------------------
00172   //--- Detector-level quantities
00173   mutable const PixelGeomDetUnit * theDet;
00174   
00175   // gavril : replace RectangularPixelTopology with PixelTopology
00176   //mutable const RectangularPixelTopology * theTopol;
00177   mutable const PixelTopology * theTopol;
00178   
00179 
00180   mutable GeomDetType::SubDetector thePart;
00181   //mutable EtaCorrection theEtaFunc;
00182   mutable float theThickness;
00183   mutable float thePitchX;
00184   mutable float thePitchY;
00185   //mutable float theOffsetX;
00186   //mutable float theOffsetY;
00187   mutable float theNumOfRow;
00188   mutable float theNumOfCol;
00189   mutable float theDetZ;
00190   mutable float theDetR;
00191   mutable float theLShiftX;
00192   mutable float theLShiftY;
00193   mutable float theSign;
00194 
00195   //--- Cluster-level quantities (may need more)
00196   mutable float alpha_;
00197   mutable float beta_;
00198 
00199   // G.Giurgiu (12/13/06)-----
00200   mutable float cotalpha_;
00201   mutable float cotbeta_;
00202 
00203   // G.Giurgiu (05/14/08) track local coordinates
00204   mutable float trk_lp_x;
00205   mutable float trk_lp_y;
00206 
00207   //--- Counters
00208   mutable int    nRecHitsTotal_ ;
00209   mutable int    nRecHitsUsedEdge_ ;
00210 
00211   // ggiurgiu@jhu.edu (10/18/2008)
00212   mutable bool with_track_angle; 
00213 
00214   //--- Probability
00215   mutable float probabilityX_ ; 
00216   mutable float probabilityY_ ; 
00217   mutable float probabilityQ_ ; 
00218   mutable float qBin_ ;
00219   mutable bool  isOnEdge_ ;
00220   mutable bool  hasBadPixels_ ;
00221   mutable bool  spansTwoROCs_ ;
00222   mutable bool  hasFilledProb_ ;
00223 
00224 
00225   //---------------------------
00226 
00227   // [Petar, 2/23/07]
00228   // Since the sign of the Lorentz shift appears to
00229   // be computed *incorrectly* (i.e. there's a bug) we add new variables
00230   // so that we can study the effect of the bug.
00231   mutable LocalVector driftDirection_;  // drift direction cached // &&&
00232   mutable double lorentzShiftX_;   // a FULL shift, not 1/2 like theLShiftX!
00233   mutable double lorentzShiftY_;   // a FULL shift, not 1/2 like theLShiftY!
00234   mutable double lorentzShiftInCmX_;   // a FULL shift, in cm
00235   mutable double lorentzShiftInCmY_;   // a FULL shift, in cm
00236 
00237 
00238   //--- Global quantities
00239 //   mutable float theTanLorentzAnglePerTesla;   // tan(Lorentz angle)/Tesla
00240   int     theVerboseLevel;                    // algorithm's verbosity
00241 
00242   mutable const MagneticField * magfield_;          // magnetic field
00243   
00244   mutable const SiPixelLorentzAngle * lorentzAngle_;
00245   
00246   mutable const SiPixelCPEGenericErrorParm * genErrorParm_;
00247   
00248   mutable const SiPixelTemplateDBObject * templateDBobject_;
00249   
00250   bool  alpha2Order;                          // switch on/off E.B effect.
00251   
00252   // ggiurgiu@jhu.edu (12/01/2010) : Needed for calling topology methods 
00253   // with track angles to handle surface deformations (bows/kinks)
00254   //mutable Topology::LocalTrackPred* loc_trk_pred;
00255   mutable Topology::LocalTrackPred loc_trk_pred_;
00256 
00257   mutable LocalTrajectoryParameters loc_traj_param_;
00258   
00259   //---------------------------------------------------------------------------
00260   //  Methods.
00261   //---------------------------------------------------------------------------
00262   void       setTheDet( const GeomDetUnit & det, const SiPixelCluster & cluster ) const ;
00263   //
00264   MeasurementPoint measurementPosition( const SiPixelCluster&, 
00265                                         const GeomDetUnit & det) const ;
00266   MeasurementError measurementError   ( const SiPixelCluster&, 
00267                                         const GeomDetUnit & det) const ;
00268 
00269   //---------------------------------------------------------------------------
00270   //  Geometrical services to subclasses.
00271   //---------------------------------------------------------------------------
00272 
00273   //--- Estimation of alpha_ and beta_
00274   //float estimatedAlphaForBarrel(float centerx) const;
00275   void computeAnglesFromDetPosition(const SiPixelCluster & cl, 
00276                                     const GeomDetUnit    & det ) const;
00277   void computeAnglesFromTrajectory (const SiPixelCluster & cl,
00278                                     const GeomDetUnit    & det, 
00279                                     const LocalTrajectoryParameters & ltp) const;
00280   LocalVector driftDirection       ( GlobalVector bfield ) const ; //wrong sign
00281   LocalVector driftDirectionCorrect( GlobalVector bfield ) const ;
00282   void computeLorentzShifts() const ;
00283 
00284   bool isFlipped() const;              // is the det flipped or not?
00285 
00286   //---------------------------------------------------------------------------
00287   //  Cluster-level services.
00288   //---------------------------------------------------------------------------
00289    
00290   //--- Charge on the first, last  and  inner pixels on x and y 
00291   void xCharge(const std::vector<SiPixelCluster::Pixel>&, 
00292                const int&, const int&, float& q1, float& q2) const; 
00293   void yCharge(const std::vector<SiPixelCluster::Pixel>&, 
00294                const int&, const int&, float& q1, float& q2) const; 
00295 
00296   // Temporary fix for older classes
00297   //std::vector<float> 
00298   //xCharge(const std::vector<SiPixelCluster::Pixel>& pixelsVec, 
00299   //    const float& xmin, const float& xmax) const {
00300   // return xCharge(pixelsVec, int(xmin), int(xmax)); 
00301   //}
00302   //std::vector<float> 
00303   // yCharge(const std::vector<SiPixelCluster::Pixel>& pixelsVec, 
00304   //    const float& xmin, const float& xmax) const {
00305   // return yCharge(pixelsVec, int(xmin), int(xmax)); 
00306   //}
00307 
00308 
00309 
00310   //---------------------------------------------------------------------------
00311   //  Various position corrections.
00312   //---------------------------------------------------------------------------
00313   //float geomCorrection()const;
00314 
00315   //--- The Lorentz shift correction
00316   virtual float lorentzShiftX() const;
00317   virtual float lorentzShiftY() const;
00318  
00319   //--- Position in X and Y
00320   virtual float xpos( const SiPixelCluster& ) const = 0;
00321   virtual float ypos( const SiPixelCluster& ) const = 0;
00322   
00323   
00324   
00325  public:
00326   struct Param 
00327   {
00328     Param() : topology(0), drift(0.0, 0.0, 0.0) {}
00329     
00330     // giurgiu@jhu.edu 12/09/2010: switch to PixelTopology
00331     //RectangularPixelTopology const * topology;
00332     PixelTopology const * topology;
00333 
00334     LocalVector drift;
00335   };
00336   
00337  private:
00338    typedef  __gnu_cxx::hash_map< unsigned int, Param> Params;
00339   
00340   Params m_Params;
00341   
00342 
00343 
00344 };
00345 
00346 #endif
00347 
00348