CMS 3D CMS Logo

PixelCPEBase.h
Go to the documentation of this file.
1 #ifndef RecoLocalTracker_SiPixelRecHits_PixelCPEBase_H
2 #define RecoLocalTracker_SiPixelRecHits_PixelCPEBase_H 1
3 
4 //-----------------------------------------------------------------------------
5 // \class PixelCPEBase
6 // \description Base class for pixel CPE's, with all the common code.
7 // Perform the position and error evaluation of pixel hits using
8 // the Det angle to estimate the track impact angle.
9 // Move geomCorrection to the concrete class. d.k. 06/06.
10 // change to use Lorentz angle from DB Lotte Wilke, Jan. 31st, 2008
11 // Change to use Generic error & Template calibration from DB - D.Fehling 11/08
12 //-----------------------------------------------------------------------------
13 
14 #include <utility>
15 #include <vector>
16 #include "TMath.h"
17 
20 
27 
28 //--- For the configuration:
31 
35 
37 
38 // new errors
40 // old errors
41 //#include "CondFormats/SiPixelObjects/interface/SiPixelCPEGenericErrorParm.h"
42 
44 
45 #include <unordered_map>
46 
47 #include <iostream>
48 #ifdef EDM_ML_DEBUG
49 #include <atomic>
50 #endif
51 
53 class MagneticField;
55 public:
56  struct DetParam {
57  DetParam() {}
59  // gavril : replace RectangularPixelTopology with PixelTopology
62 
65  float theThickness;
66  float thePitchX;
67  float thePitchY;
68 
69  float bz; // local Bz
70  float bx; // local Bx
72  float widthLAFractionX; // Width-LA to Offset-LA in X
73  float widthLAFractionY; // same in Y
74  float lorentzShiftInCmX; // a FULL shift, in cm
75  float lorentzShiftInCmY; // a FULL shift, in cm
76  int detTemplateId; // det if for templates & generic errors
77  int detTemplateId2D; // det if for 2D templates
78  };
79 
80  struct ClusterParam {
81  ClusterParam(const SiPixelCluster& cl) : theCluster(&cl) {}
82 
83  virtual ~ClusterParam() = default;
84 
86 
87  //--- Cluster-level quantities (filled in computeAnglesFrom....)
88  float cotalpha;
89  float cotbeta;
90 
91  // G.Giurgiu (05/14/08) track local coordinates
92  // filled in computeAnglesFrom....
93  float trk_lp_x;
94  float trk_lp_y;
95 
96  // ggiurgiu@jhu.edu (12/01/2010) : Needed for calling topology methods
97  // with track angles to handle surface deformations (bows/kinks)
98  // filled in computeAnglesFrom.... (btw redundant with the 4 above)
100 
101  //--- Probability (protected by hasFilledProb_)
105  int qBin_; // always filled by qbin
106 
107  bool isOnEdge_; // filled in setTheClu
108  bool hasBadPixels_ = false; // (never used in current code)
109  bool spansTwoROCs_; // filled in setTheClu
110  bool hasFilledProb_ = false;
111  // ggiurgiu@jhu.edu (10/18/2008)
112  bool with_track_angle; // filled in computeAnglesFrom....
113  bool filled_from_2d = false; //
114 
115  // More detailed edge information (for CPE ClusterRepair, and elsewhere...)
116  int edgeTypeX_ = 0; // 0: not on edge, 1: low end on edge, 2: high end
117  int edgeTypeY_ = 0; // 0: not on edge, 1: low end on edge, 2: high end
118  };
119 
120 public:
121  PixelCPEBase(edm::ParameterSet const& conf,
122  const MagneticField* mag,
123  const TrackerGeometry& geom,
124  const TrackerTopology& ttopo,
125  const SiPixelLorentzAngle* lorentzAngle,
126  const SiPixelGenErrorDBObject* genErrorDBObject,
127  const SiPixelTemplateDBObject* templateDBobject,
128  const SiPixelLorentzAngle* lorentzAngleWidth,
129  int flag = 0 // flag=0 for generic, =1 for templates
130  ); // NEW
131 
133 
134  //--------------------------------------------------------------------------
135  // Allow the magnetic field to be set/updated later.
136  //--------------------------------------------------------------------------
137  //inline void setMagField(const MagneticField *mag) const { magfield_ = mag; } // Not used, AH
138 
139  //--------------------------------------------------------------------------
140  // Obtain the angles from the position of the DetUnit.
141  //--------------------------------------------------------------------------
142 
143  inline ReturnType getParameters(const SiPixelCluster& cl, const GeomDetUnit& det) const override {
144 #ifdef EDM_ML_DEBUG
145  nRecHitsTotal_++;
146  //std::cout<<" in PixelCPEBase:localParameters(all) - "<<nRecHitsTotal_<<std::endl; //dk
147 #endif
148 
149  DetParam const& theDetParam = detParam(det);
150  ClusterParam* theClusterParam = createClusterParam(cl);
151  setTheClu(theDetParam, *theClusterParam);
152  computeAnglesFromDetPosition(theDetParam, *theClusterParam);
153 
154  // localPosition( cl, det ) must be called before localError( cl, det ) !!!
155  LocalPoint lp = localPosition(theDetParam, *theClusterParam);
156  LocalError le = localError(theDetParam, *theClusterParam);
157  SiPixelRecHitQuality::QualWordType rqw = rawQualityWord(*theClusterParam);
158  auto tuple = std::make_tuple(lp, le, rqw);
159  delete theClusterParam;
160 
161  //std::cout<<" in PixelCPEBase:localParameters(all) - "<<lp.x()<<" "<<lp.y()<<std::endl; //dk
162  return tuple;
163  }
164 
165  //--------------------------------------------------------------------------
166  // In principle we could use the track too to obtain alpha and beta.
167  //--------------------------------------------------------------------------
169  const GeomDetUnit& det,
170  const LocalTrajectoryParameters& ltp) const override {
171 #ifdef EDM_ML_DEBUG
172  nRecHitsTotal_++;
173  //std::cout<<" in PixelCPEBase:localParameters(on track) - "<<nRecHitsTotal_<<std::endl; //dk
174 #endif
175 
176  DetParam const& theDetParam = detParam(det);
177  ClusterParam* theClusterParam = createClusterParam(cl);
178  setTheClu(theDetParam, *theClusterParam);
179  computeAnglesFromTrajectory(theDetParam, *theClusterParam, ltp);
180 
181  // localPosition( cl, det ) must be called before localError( cl, det ) !!!
182  LocalPoint lp = localPosition(theDetParam, *theClusterParam);
183  LocalError le = localError(theDetParam, *theClusterParam);
184  SiPixelRecHitQuality::QualWordType rqw = rawQualityWord(*theClusterParam);
185  auto tuple = std::make_tuple(lp, le, rqw);
186  delete theClusterParam;
187 
188  //std::cout<<" in PixelCPEBase:localParameters(on track) - "<<lp.x()<<" "<<lp.y()<<std::endl; //dk
189  return tuple;
190  }
191 
192 private:
193  virtual ClusterParam* createClusterParam(const SiPixelCluster& cl) const = 0;
194 
195  //--------------------------------------------------------------------------
196  // This is where the action happens.
197  //--------------------------------------------------------------------------
198  virtual LocalPoint localPosition(DetParam const& theDetParam, ClusterParam& theClusterParam) const = 0;
199  virtual LocalError localError(DetParam const& theDetParam, ClusterParam& theClusterParam) const = 0;
200 
201  void fillDetParams();
202 
203  //-----------------------------------------------------------------------------
208  //-----------------------------------------------------------------------------
210 
211 protected:
212  //--- All methods and data members are protected to facilitate (for now)
213  //--- access from derived classes.
214 
216 
217  //---------------------------------------------------------------------------
218  // Data members
219  //---------------------------------------------------------------------------
220 
221  //--- Counters
222 #ifdef EDM_ML_DEBUG
223  mutable std::atomic<int> nRecHitsTotal_; //for debugging only
224  mutable std::atomic<int> nRecHitsUsedEdge_; //for debugging only
225 #endif
226 
227  // Added new members
228  float lAOffset_; // la used to calculate the offset from configuration (for testing)
229  float lAWidthBPix_; // la used to calculate the cluster width from conf.
230  float lAWidthFPix_; // la used to calculate the cluster width from conf.
231  //bool useLAAlignmentOffsets_; // lorentz angle offsets detrmined by alignment
232  bool useLAOffsetFromConfig_; // lorentz angle used to calculate the offset
233  bool useLAWidthFromConfig_; // lorentz angle used to calculate the cluster width
234  bool useLAWidthFromDB_; // lorentz angle used to calculate the cluster width
235 
236  //--- Global quantities
237  int theVerboseLevel; // algorithm's verbosity
238  int theFlag_; // flag to recognice if we are in generic or templates
239 
240  const MagneticField* magfield_; // magnetic field
241  const TrackerGeometry& geom_; // geometry
242  const TrackerTopology& ttopo_; // Tracker Topology
243 
245  const SiPixelLorentzAngle* lorentzAngleWidth_; // for the charge width (generic)
246 
248  //const SiPixelCPEGenericErrorParm * genErrorParm_; // OLD
249 
251  bool alpha2Order; // switch on/off E.B effect.
252 
255 
256  //---------------------------------------------------------------------------
257  // Geometrical services to subclasses.
258  //---------------------------------------------------------------------------
259 protected:
260  void computeAnglesFromDetPosition(DetParam const& theDetParam, ClusterParam& theClusterParam) const;
261 
262  void computeAnglesFromTrajectory(DetParam const& theDetParam,
263  ClusterParam& theClusterParam,
264  const LocalTrajectoryParameters& ltp) const;
265 
266  void setTheClu(DetParam const&, ClusterParam& theClusterParam) const;
267 
268  LocalVector driftDirection(DetParam& theDetParam, GlobalVector bfield) const;
269  LocalVector driftDirection(DetParam& theDetParam, LocalVector bfield) const;
270  void computeLorentzShifts(DetParam&) const;
271 
272  //---------------------------------------------------------------------------
273  // Cluster-level services.
274  //---------------------------------------------------------------------------
275 
276  DetParam const& detParam(const GeomDetUnit& det) const;
277 
278  using DetParams = std::vector<DetParam>;
279 
281 };
282 
283 #endif
Local3DPoint theOrigin
Definition: PixelCPEBase.h:64
const SiPixelLorentzAngle * lorentzAngleWidth_
Definition: PixelCPEBase.h:245
ReturnType getParameters(const SiPixelCluster &cl, const GeomDetUnit &det) const override
Definition: PixelCPEBase.h:143
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const SiPixelCluster * theCluster
Definition: PixelCPEBase.h:85
ClusterParam(const SiPixelCluster &cl)
Definition: PixelCPEBase.h:81
DetParams m_DetParams
Definition: PixelCPEBase.h:280
static void fillPSetDescription(edm::ParameterSetDescription &desc)
void fillDetParams()
const PixelGeomDetUnit * theDet
Definition: PixelCPEBase.h:58
GeomDetType::SubDetector thePart
Definition: PixelCPEBase.h:63
const RectangularPixelTopology * theRecTopol
Definition: PixelCPEBase.h:61
bool useLAWidthFromDB_
Definition: PixelCPEBase.h:234
float lAWidthBPix_
Definition: PixelCPEBase.h:229
bool useLAWidthFromConfig_
Definition: PixelCPEBase.h:233
const PixelTopology * theTopol
Definition: PixelCPEBase.h:60
bool LoadTemplatesFromDB_
Definition: PixelCPEBase.h:254
void computeAnglesFromTrajectory(DetParam const &theDetParam, ClusterParam &theClusterParam, const LocalTrajectoryParameters &ltp) const
virtual ClusterParam * createClusterParam(const SiPixelCluster &cl) const =0
void computeLorentzShifts(DetParam &) const
const SiPixelTemplateDBObject * templateDBobject_
Definition: PixelCPEBase.h:250
const MagneticField * magfield_
Definition: PixelCPEBase.h:240
void computeAnglesFromDetPosition(DetParam const &theDetParam, ClusterParam &theClusterParam) const
SiPixelRecHitQuality::QualWordType rawQualityWord(ClusterParam &theClusterParam) const
Topology::LocalTrackPred loc_trk_pred
Definition: PixelCPEBase.h:99
std::vector< DetParam > DetParams
Definition: PixelCPEBase.h:278
const TrackerTopology & ttopo_
Definition: PixelCPEBase.h:242
const SiPixelLorentzAngle * lorentzAngle_
Definition: PixelCPEBase.h:244
const SiPixelGenErrorDBObject * genErrorDBObject_
Definition: PixelCPEBase.h:247
void setTheClu(DetParam const &, ClusterParam &theClusterParam) const
bool useLAOffsetFromConfig_
Definition: PixelCPEBase.h:232
GloballyPositioned< double > Frame
Definition: PixelCPEBase.h:215
Pixel cluster – collection of neighboring pixels above threshold.
const TrackerGeometry & geom_
Definition: PixelCPEBase.h:241
PixelCPEBase(edm::ParameterSet const &conf, const MagneticField *mag, const TrackerGeometry &geom, const TrackerTopology &ttopo, const SiPixelLorentzAngle *lorentzAngle, const SiPixelGenErrorDBObject *genErrorDBObject, const SiPixelTemplateDBObject *templateDBobject, const SiPixelLorentzAngle *lorentzAngleWidth, int flag=0)
Definition: PixelCPEBase.cc:30
LocalVector driftDirection
Definition: PixelCPEBase.h:71
ReturnType getParameters(const SiPixelCluster &cl, const GeomDetUnit &det, const LocalTrajectoryParameters &ltp) const override
Definition: PixelCPEBase.h:168
virtual LocalError localError(DetParam const &theDetParam, ClusterParam &theClusterParam) const =0
std::tuple< LocalPoint, LocalError, SiPixelRecHitQuality::QualWordType > ReturnType
virtual LocalPoint localPosition(DetParam const &theDetParam, ClusterParam &theClusterParam) const =0
float lAWidthFPix_
Definition: PixelCPEBase.h:230
DetParam const & detParam(const GeomDetUnit &det) const