CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/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 
00030 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
00031 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h"
00032 #include "DataFormats/GeometrySurface/interface/GloballyPositioned.h"
00033 
00034 #include "CondFormats/SiPixelObjects/interface/SiPixelLorentzAngle.h"
00035 #include "CondFormats/SiPixelObjects/interface/SiPixelCPEGenericErrorParm.h"
00036 #include "CondFormats/SiPixelObjects/interface/SiPixelTemplateDBObject.h"
00037 
00038 
00039 
00040 #include <unordered_map>
00041 
00042 #include <iostream>
00043 
00044 
00045 class RectangularPixelTopology;
00046 class MagneticField;
00047 class PixelCPEBase : public PixelClusterParameterEstimator 
00048 {
00049  public:
00050   struct Param 
00051   {
00052     Param() : bz(-9e10f) {}
00053     float bz; // local Bz
00054     LocalVector drift;
00055   };
00056 
00057 public:
00058   PixelCPEBase(edm::ParameterSet const& conf, const MagneticField * mag = 0, 
00059                const SiPixelLorentzAngle * lorentzAngle = 0, const SiPixelCPEGenericErrorParm * genErrorParm = 0, 
00060                const SiPixelTemplateDBObject * templateDBobject = 0);
00061   
00062   //--------------------------------------------------------------------------
00063   // Obtain the angles from the position of the DetUnit.
00064   // LocalValues is typedef for pair<LocalPoint,LocalError> 
00065   //--------------------------------------------------------------------------
00066   inline LocalValues localParameters( const SiPixelCluster & cl, 
00067                                       const GeomDetUnit    & det ) const 
00068     {
00069       nRecHitsTotal_++ ;
00070       setTheDet( det, cl );
00071       computeAnglesFromDetPosition(cl, det);
00072       
00073       // localPosition( cl, det ) must be called before localError( cl, det ) !!!
00074       LocalPoint lp = localPosition( cl, det );
00075       LocalError le = localError( cl, det );        
00076       
00077       return std::make_pair( lp, le );
00078     }
00079   
00080   //--------------------------------------------------------------------------
00081   // In principle we could use the track too to obtain alpha and beta.
00082   //--------------------------------------------------------------------------
00083   LocalValues localParameters( const SiPixelCluster & cl,
00084                                const GeomDetUnit    & det, 
00085                                const LocalTrajectoryParameters & ltp) const 
00086   {
00087     nRecHitsTotal_++ ;
00088     setTheDet( det, cl );
00089     computeAnglesFromTrajectory(cl, det, ltp);
00090     
00091     // localPosition( cl, det ) must be called before localError( cl, det ) !!!
00092     LocalPoint lp = localPosition( cl, det ); 
00093     LocalError le = localError( cl, det );        
00094     
00095     return std::make_pair( lp, le );
00096   } 
00097   
00098   //--------------------------------------------------------------------------
00099   // The third one, with the user-supplied alpha and beta
00100   //--------------------------------------------------------------------------
00101   LocalValues localParameters( const SiPixelCluster & cl,
00102                                const GeomDetUnit    & det, 
00103                                float alpha, float beta) const 
00104   {
00105     nRecHitsTotal_++ ;
00106     alpha_ = alpha;
00107     beta_  = beta;
00108     double HalfPi = 0.5*TMath::Pi();
00109     cotalpha_ = tan(HalfPi - alpha_);
00110     cotbeta_  = tan(HalfPi - beta_ );
00111       setTheDet( det, cl );
00112       
00113       // localPosition( cl, det ) must be called before localError( cl, det ) !!!
00114       LocalPoint lp = localPosition( cl, det ); 
00115       LocalError le = localError( cl, det );        
00116       
00117       return std::make_pair( lp, le );
00118   }
00119   
00120   
00121   void computeAnglesFromDetPosition(const SiPixelCluster & cl, 
00122                                     const GeomDetUnit    & det ) const;
00123   
00124   //--------------------------------------------------------------------------
00125   // Allow the magnetic field to be set/updated later.
00126   //--------------------------------------------------------------------------
00127   inline void setMagField(const MagneticField *mag) const { magfield_ = mag; }
00128   
00129   //--------------------------------------------------------------------------
00130   // This is where the action happens.
00131   //--------------------------------------------------------------------------
00132   virtual LocalPoint localPosition(const SiPixelCluster& cl, const GeomDetUnit & det) const;  // = 0, take out dk 8/06
00133   virtual LocalError localError   (const SiPixelCluster& cl, const GeomDetUnit & det) const = 0;
00134   
00135   
00136   
00137   //--------------------------------------------------------------------------
00138   //--- Accessors of other auxiliary quantities
00139   inline float probabilityX()  const { return probabilityX_ ;  }
00140   inline float probabilityY()  const { return probabilityY_ ;  }
00141   inline float probabilityXY() const {
00142     if ( probabilityX_ !=0 && probabilityY_ !=0 ) 
00143       {
00144         return probabilityX_ * probabilityY_ * (1.f - std::log(probabilityX_ * probabilityY_) ) ;
00145       }
00146     else 
00147       return 0;
00148   }
00149   
00150   inline float probabilityQ()  const { return probabilityQ_ ;  }
00151   inline float qBin()          const { return qBin_ ;          }
00152   inline bool  isOnEdge()      const { return isOnEdge_ ;      }
00153   inline bool  hasBadPixels()  const { return hasBadPixels_ ;  }
00154   inline bool  spansTwoRocks() const { return spansTwoROCs_ ;  }
00155   inline bool  hasFilledProb() const { return hasFilledProb_ ; }
00156   
00157   //--- Flag to control how SiPixelRecHits compute clusterProbability().
00158   //--- Note this is set via the configuration file, and it's simply passed
00159   //--- to each TSiPixelRecHit.
00160   inline unsigned int clusterProbComputationFlag() const 
00161     { 
00162       return clusterProbComputationFlag_ ; 
00163     }
00164   
00165   
00166   //-----------------------------------------------------------------------------
00171   //-----------------------------------------------------------------------------
00172   SiPixelRecHitQuality::QualWordType rawQualityWord() const;
00173 
00174 
00175  protected:
00176   //--- All methods and data members are protected to facilitate (for now)
00177   //--- access from derived classes.
00178 
00179   typedef GloballyPositioned<double> Frame;
00180 
00181   //---------------------------------------------------------------------------
00182   //  Data members
00183   //---------------------------------------------------------------------------
00184   //--- Detector-level quantities
00185   mutable const PixelGeomDetUnit * theDet;
00186   
00187   // gavril : replace RectangularPixelTopology with PixelTopology
00188   //mutable const RectangularPixelTopology * theTopol;
00189   mutable const PixelTopology * theTopol;
00190   mutable const RectangularPixelTopology * theRecTopol;
00191 
00192   mutable Param const * theParam;
00193 
00194   mutable GeomDetType::SubDetector thePart;
00195   //mutable EtaCorrection theEtaFunc;
00196   mutable float theThickness;
00197   mutable float thePitchX;
00198   mutable float thePitchY;
00199   //mutable float theOffsetX;
00200   //mutable float theOffsetY;
00201   mutable float theNumOfRow;
00202   mutable float theNumOfCol;
00203   mutable float theDetZ;
00204   mutable float theDetR;
00205   mutable float theLShiftX;
00206   mutable float theLShiftY;
00207   mutable float theSign;
00208 
00209   //--- Cluster-level quantities (may need more)
00210   mutable float alpha_;
00211   mutable float beta_;
00212 
00213   // G.Giurgiu (12/13/06)-----
00214   mutable float cotalpha_;
00215   mutable float cotbeta_;
00216 
00217   // G.Giurgiu (05/14/08) track local coordinates
00218   mutable float trk_lp_x;
00219   mutable float trk_lp_y;
00220 
00221   //--- Counters
00222   mutable int    nRecHitsTotal_ ;
00223   mutable int    nRecHitsUsedEdge_ ;
00224 
00225   // ggiurgiu@jhu.edu (10/18/2008)
00226   mutable bool with_track_angle; 
00227 
00228   //--- Probability
00229   mutable float probabilityX_ ; 
00230   mutable float probabilityY_ ; 
00231   mutable float probabilityQ_ ; 
00232   mutable float qBin_ ;
00233   mutable bool  isOnEdge_ ;
00234   mutable bool  hasBadPixels_ ;
00235   mutable bool  spansTwoROCs_ ;
00236   mutable bool  hasFilledProb_ ;
00237 
00238   //--- A flag that could be used to change the behavior of
00239   //--- clusterProbability() in TSiPixelRecHit (the *transient* one).  
00240   //--- The problem is that the transient hits are made after the CPE runs
00241   //--- and they don't get the access to the PSet, so we pass it via the
00242   //--- CPE itself...
00243   //
00244   unsigned int clusterProbComputationFlag_ ;
00245 
00246   //---------------------------
00247 
00248   // [Petar, 2/23/07]
00249   // Since the sign of the Lorentz shift appears to
00250   // be computed *incorrectly* (i.e. there's a bug) we add new variables
00251   // so that we can study the effect of the bug.
00252   mutable LocalVector driftDirection_;  // drift direction cached // &&&
00253   mutable double lorentzShiftX_;   // a FULL shift, not 1/2 like theLShiftX!
00254   mutable double lorentzShiftY_;   // a FULL shift, not 1/2 like theLShiftY!
00255   mutable double lorentzShiftInCmX_;   // a FULL shift, in cm
00256   mutable double lorentzShiftInCmY_;   // a FULL shift, in cm
00257 
00258 
00259   //--- Global quantities
00260 //   mutable float theTanLorentzAnglePerTesla;   // tan(Lorentz angle)/Tesla
00261   int     theVerboseLevel;                    // algorithm's verbosity
00262 
00263   mutable const MagneticField * magfield_;          // magnetic field
00264   
00265   mutable const SiPixelLorentzAngle * lorentzAngle_;
00266   
00267   mutable const SiPixelCPEGenericErrorParm * genErrorParm_;
00268   
00269   mutable const SiPixelTemplateDBObject * templateDBobject_;
00270   
00271   bool  alpha2Order;                          // switch on/off E.B effect.
00272   
00273   // ggiurgiu@jhu.edu (12/01/2010) : Needed for calling topology methods 
00274   // with track angles to handle surface deformations (bows/kinks)
00275   //mutable Topology::LocalTrackPred* loc_trk_pred;
00276   mutable Topology::LocalTrackPred loc_trk_pred_;
00277 
00278   mutable LocalTrajectoryParameters loc_traj_param_;
00279   
00280   //---------------------------------------------------------------------------
00281   //  Methods.
00282   //---------------------------------------------------------------------------
00283   void       setTheDet( const GeomDetUnit & det, const SiPixelCluster & cluster ) const ;
00284 
00285   MeasurementPoint measurementPosition( const SiPixelCluster& cluster, 
00286                                         const GeomDetUnit & det) const;
00287   MeasurementError measurementError   ( const SiPixelCluster&, 
00288                                         const GeomDetUnit & det) const ;
00289 
00290   //---------------------------------------------------------------------------
00291   //  Geometrical services to subclasses.
00292   //---------------------------------------------------------------------------
00293 
00294   void computeAnglesFromTrajectory (const SiPixelCluster & cl,
00295                                     const GeomDetUnit    & det, 
00296                                     const LocalTrajectoryParameters & ltp) const;
00297   LocalVector driftDirection       ( GlobalVector bfield ) const ; //wrong sign
00298   LocalVector driftDirection       ( LocalVector bfield ) const ; //wrong sign
00299   LocalVector driftDirectionCorrect( GlobalVector bfield ) const ;
00300   void computeLorentzShifts() const ;
00301 
00302   bool isFlipped() const;              // is the det flipped or not?
00303 
00304   //---------------------------------------------------------------------------
00305   //  Cluster-level services.
00306   //---------------------------------------------------------------------------
00307    
00308  
00309 
00310   //--- The Lorentz shift correction
00311   float lorentzShiftX() const;
00312   float lorentzShiftY() const;
00313  
00314   //--- Position in X and Y
00315   virtual float xpos( const SiPixelCluster& ) const = 0;
00316   virtual float ypos( const SiPixelCluster& ) const = 0;
00317   
00318   
00319   LocalVector const & getDrift() const {return  driftDirection_ ;}
00320  
00321 
00322  
00323   Param const & param() const;
00324  
00325  private:
00326   typedef  std::unordered_map< unsigned int, Param> Params;
00327   
00328   mutable Params m_Params;
00329   
00330 
00331 
00332 };
00333 
00334 #endif
00335 
00336