CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/RecoLocalTracker/SiPixelRecHits/interface/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   //--- Flag to control how SiPixelRecHits compute clusterProbability().
00154   //--- Note this is set via the configuration file, and it's simply passed
00155   //--- to each TSiPixelRecHit.
00156   inline unsigned int clusterProbComputationFlag() const 
00157     { 
00158       return clusterProbComputationFlag_ ; 
00159     }
00160   
00161   
00162   //-----------------------------------------------------------------------------
00167   //-----------------------------------------------------------------------------
00168   SiPixelRecHitQuality::QualWordType rawQualityWord() const;
00169 
00170 
00171  protected:
00172   //--- All methods and data members are protected to facilitate (for now)
00173   //--- access from derived classes.
00174 
00175   typedef GloballyPositioned<double> Frame;
00176 
00177   //---------------------------------------------------------------------------
00178   //  Data members
00179   //---------------------------------------------------------------------------
00180   //--- Detector-level quantities
00181   mutable const PixelGeomDetUnit * theDet;
00182   
00183   // gavril : replace RectangularPixelTopology with PixelTopology
00184   //mutable const RectangularPixelTopology * theTopol;
00185   mutable const PixelTopology * theTopol;
00186   
00187 
00188   mutable GeomDetType::SubDetector thePart;
00189   //mutable EtaCorrection theEtaFunc;
00190   mutable float theThickness;
00191   mutable float thePitchX;
00192   mutable float thePitchY;
00193   //mutable float theOffsetX;
00194   //mutable float theOffsetY;
00195   mutable float theNumOfRow;
00196   mutable float theNumOfCol;
00197   mutable float theDetZ;
00198   mutable float theDetR;
00199   mutable float theLShiftX;
00200   mutable float theLShiftY;
00201   mutable float theSign;
00202 
00203   //--- Cluster-level quantities (may need more)
00204   mutable float alpha_;
00205   mutable float beta_;
00206 
00207   // G.Giurgiu (12/13/06)-----
00208   mutable float cotalpha_;
00209   mutable float cotbeta_;
00210 
00211   // G.Giurgiu (05/14/08) track local coordinates
00212   mutable float trk_lp_x;
00213   mutable float trk_lp_y;
00214 
00215   //--- Counters
00216   mutable int    nRecHitsTotal_ ;
00217   mutable int    nRecHitsUsedEdge_ ;
00218 
00219   // ggiurgiu@jhu.edu (10/18/2008)
00220   mutable bool with_track_angle; 
00221 
00222   //--- Probability
00223   mutable float probabilityX_ ; 
00224   mutable float probabilityY_ ; 
00225   mutable float probabilityQ_ ; 
00226   mutable float qBin_ ;
00227   mutable bool  isOnEdge_ ;
00228   mutable bool  hasBadPixels_ ;
00229   mutable bool  spansTwoROCs_ ;
00230   mutable bool  hasFilledProb_ ;
00231 
00232   //--- A flag that could be used to change the behavior of
00233   //--- clusterProbability() in TSiPixelRecHit (the *transient* one).  
00234   //--- The problem is that the transient hits are made after the CPE runs
00235   //--- and they don't get the access to the PSet, so we pass it via the
00236   //--- CPE itself...
00237   //
00238   unsigned int clusterProbComputationFlag_ ;
00239 
00240   //---------------------------
00241 
00242   // [Petar, 2/23/07]
00243   // Since the sign of the Lorentz shift appears to
00244   // be computed *incorrectly* (i.e. there's a bug) we add new variables
00245   // so that we can study the effect of the bug.
00246   mutable LocalVector driftDirection_;  // drift direction cached // &&&
00247   mutable double lorentzShiftX_;   // a FULL shift, not 1/2 like theLShiftX!
00248   mutable double lorentzShiftY_;   // a FULL shift, not 1/2 like theLShiftY!
00249   mutable double lorentzShiftInCmX_;   // a FULL shift, in cm
00250   mutable double lorentzShiftInCmY_;   // a FULL shift, in cm
00251 
00252 
00253   //--- Global quantities
00254 //   mutable float theTanLorentzAnglePerTesla;   // tan(Lorentz angle)/Tesla
00255   int     theVerboseLevel;                    // algorithm's verbosity
00256 
00257   mutable const MagneticField * magfield_;          // magnetic field
00258   
00259   mutable const SiPixelLorentzAngle * lorentzAngle_;
00260   
00261   mutable const SiPixelCPEGenericErrorParm * genErrorParm_;
00262   
00263   mutable const SiPixelTemplateDBObject * templateDBobject_;
00264   
00265   bool  alpha2Order;                          // switch on/off E.B effect.
00266   
00267   // ggiurgiu@jhu.edu (12/01/2010) : Needed for calling topology methods 
00268   // with track angles to handle surface deformations (bows/kinks)
00269   //mutable Topology::LocalTrackPred* loc_trk_pred;
00270   mutable Topology::LocalTrackPred loc_trk_pred_;
00271 
00272   mutable LocalTrajectoryParameters loc_traj_param_;
00273   
00274   //---------------------------------------------------------------------------
00275   //  Methods.
00276   //---------------------------------------------------------------------------
00277   void       setTheDet( const GeomDetUnit & det, const SiPixelCluster & cluster ) const ;
00278   //
00279   MeasurementPoint measurementPosition( const SiPixelCluster&, 
00280                                         const GeomDetUnit & det) const ;
00281   MeasurementError measurementError   ( const SiPixelCluster&, 
00282                                         const GeomDetUnit & det) const ;
00283 
00284   //---------------------------------------------------------------------------
00285   //  Geometrical services to subclasses.
00286   //---------------------------------------------------------------------------
00287 
00288   //--- Estimation of alpha_ and beta_
00289   //float estimatedAlphaForBarrel(float centerx) const;
00290   void computeAnglesFromDetPosition(const SiPixelCluster & cl, 
00291                                     const GeomDetUnit    & det ) const;
00292   void computeAnglesFromTrajectory (const SiPixelCluster & cl,
00293                                     const GeomDetUnit    & det, 
00294                                     const LocalTrajectoryParameters & ltp) const;
00295   LocalVector driftDirection       ( GlobalVector bfield ) const ; //wrong sign
00296   LocalVector driftDirectionCorrect( GlobalVector bfield ) const ;
00297   void computeLorentzShifts() const ;
00298 
00299   bool isFlipped() const;              // is the det flipped or not?
00300 
00301   //---------------------------------------------------------------------------
00302   //  Cluster-level services.
00303   //---------------------------------------------------------------------------
00304    
00305   //--- Charge on the first, last  and  inner pixels on x and y 
00306   void xCharge(const std::vector<SiPixelCluster::Pixel>&, 
00307                const int&, const int&, float& q1, float& q2) const; 
00308   void yCharge(const std::vector<SiPixelCluster::Pixel>&, 
00309                const int&, const int&, float& q1, float& q2) const; 
00310 
00311   // Temporary fix for older classes
00312   //std::vector<float> 
00313   //xCharge(const std::vector<SiPixelCluster::Pixel>& pixelsVec, 
00314   //    const float& xmin, const float& xmax) const {
00315   // return xCharge(pixelsVec, int(xmin), int(xmax)); 
00316   //}
00317   //std::vector<float> 
00318   // yCharge(const std::vector<SiPixelCluster::Pixel>& pixelsVec, 
00319   //    const float& xmin, const float& xmax) const {
00320   // return yCharge(pixelsVec, int(xmin), int(xmax)); 
00321   //}
00322 
00323 
00324 
00325   //---------------------------------------------------------------------------
00326   //  Various position corrections.
00327   //---------------------------------------------------------------------------
00328   //float geomCorrection()const;
00329 
00330   //--- The Lorentz shift correction
00331   virtual float lorentzShiftX() const;
00332   virtual float lorentzShiftY() const;
00333  
00334   //--- Position in X and Y
00335   virtual float xpos( const SiPixelCluster& ) const = 0;
00336   virtual float ypos( const SiPixelCluster& ) const = 0;
00337   
00338   
00339   
00340  public:
00341   struct Param 
00342   {
00343     Param() : topology(0), drift(0.0, 0.0, 0.0) {}
00344     
00345     // giurgiu@jhu.edu 12/09/2010: switch to PixelTopology
00346     //RectangularPixelTopology const * topology;
00347     PixelTopology const * topology;
00348 
00349     LocalVector drift;
00350   };
00351   
00352  private:
00353    typedef  __gnu_cxx::hash_map< unsigned int, Param> Params;
00354   
00355   Params m_Params;
00356   
00357 
00358 
00359 };
00360 
00361 #endif
00362 
00363