Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:14

0001 #ifndef Geom_LocalError_H
0002 #define Geom_LocalError_H
0003 
0004 /** A very simple class for 2D error matrix components,
0005  *  used for the local frame.
0006  */
0007 
0008 #include "DataFormats/GeometrySurface/interface/TrivialError.h"
0009 #include <cmath>
0010 #include <iosfwd>
0011 
0012 class LocalError {
0013 public:
0014   LocalError() : thexx(0), thexy(0), theyy(0) {}
0015   LocalError(InvalidError) : thexx(-9999.e10f), thexy(0), theyy(-9999.e10f) {}
0016 
0017   LocalError(float xx, float xy, float yy) : thexx(xx), thexy(xy), theyy(yy) {}
0018 
0019   bool invalid() const { return thexx < -1.e10f; }
0020   bool valid() const { return !invalid(); }
0021 
0022   float xx() const { return thexx; }
0023   float xy() const { return thexy; }
0024   float yy() const { return theyy; }
0025 
0026   /** Return a new LocalError, scaled by a factor interpreted as a 
0027    *  number of sigmas (standard deviations).
0028    *  The error matrix components are actually multiplied with the square 
0029    *  of the factor.
0030    */
0031   LocalError scale(float s) const {
0032     float s2 = s * s;
0033     return LocalError(s2 * xx(), s2 * xy(), s2 * yy());
0034   }
0035 
0036   /// Return a new LocalError, rotated by an angle defined by the direction (x,y)
0037   LocalError rotate(float x, float y) const { return rotateCosSin(x, y, 1.f / (x * x + y * y)); }
0038 
0039   /// Return a new LocalError, rotated by an angle phi
0040   LocalError rotate(float phi) const { return rotateCosSin(cos(phi), sin(phi)); }
0041 
0042   /// Return a new LocalError, rotated by an angle defined by it's cosine and sine
0043   LocalError rotateCosSin(float c, float s, float mag2i = 1.f) const {
0044     return LocalError(mag2i * ((c * c) * xx() + (s * s) * yy() - 2.f * (c * s) * xy()),
0045                       mag2i * ((c * s) * (xx() - yy()) + (c * c - s * s) * xy()),
0046                       mag2i * ((s * s) * xx() + (c * c) * yy() + 2.f * (c * s) * xy()));
0047   }
0048 
0049 private:
0050   float thexx;
0051   float thexy;
0052   float theyy;
0053 };
0054 
0055 std::ostream& operator<<(std::ostream& s, const LocalError& err);
0056 
0057 #endif  // LocalError_H