Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef DataFormats_PatCandidates_CandKinResolution_h
0002 #define DataFormats_PatCandidates_CandKinResolution_h
0003 #include <vector>
0004 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
0005 #include "DataFormats/Math/interface/LorentzVector.h"
0006 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0007 #include "DataFormats/Common/interface/ValueMap.h"
0008 
0009 namespace pat {
0010   class CandKinResolution {
0011     /** 
0012           <h2>Parametrizations</h2>
0013                    (lowercase means values, uppercase means fixed parameters)<br />
0014            <b>Cart</b> = (px, py, pz, m)                KinFitter uses (px, py, pz, m/M0) with M0 = mass of the starting p4  <br />
0015            <b>ECart</b> = (px, py, pz, e)               as in KinFitter <br />
0016            <b>MCCart</b> = (px, py, pz, M)              as in KinFitter <br />
0017            <b>Spher</b> = (p, theta, phi, m)            KinFitter uses (p, theta, phi, m/M0) with M0 = mass of the starting p4  <br />
0018            <b>ESpher</b> = (p, theta, phi, e)           KinFitter uses (p, theta, phi, e/E0) with E0 = energy of the starting  <br />
0019                    <b>MCSpher</b> = (p, eta, phi, M)            as in KinFitter <br />
0020                    <b>MCPInvSpher</b> = (1/p, theta, phi, M)    as in KinFitter <br />
0021            <b>EtEtaPhi</b> = (et, eta, phi, M == 0)     as in KinFitter <br />
0022            <b>EtThetaPhi</b> = (et, theta, phi, M == 0) as in KinFitter <br />
0023                    <b>MomDev</b> = (p/P0, dp_theta, dp_phi, m/M0), so that P = [0]*|P0|*u_r + [1]*u_theta + [2]*u_phi <br />
0024                         the "u_<xyz>" are polar unit vectors around the initial momentum P0, their directions are: <br />
0025                         u_r ~ P0, u_phi ~ u_z x u_r, u_theta ~ u_r x u_phi  M0 is the mass of the initial 4-momentum.<br />
0026                    <b>EMomDev</b> = (p/P0, dp_theta, dp_phi, E/E0) with the P defined as for MomDev <br />
0027                    <b>MCMomDev</b> = (p/P0, dp_theta, dp_phi, M)   with the P defined as for MomDev <br />
0028                    <b>EScaledMomDev</b> = (p/P0, dp_theta, dp_phi,E/P=E0/P0) with the P defined as for MomDev, fixed E/p to E0/P0 <br />
0029                    <br />
0030         */
0031   public:
0032     typedef math::XYZTLorentzVector LorentzVector;
0033     typedef float Scalar;
0034 
0035     enum Parametrization {
0036       Invalid = 0,
0037       // 4D = 0xN4
0038       Cart = 0x04,
0039       ECart = 0x14,
0040       Spher = 0x24,
0041       ESpher = 0x34,
0042       MomDev = 0x44,
0043       EMomDev = 0x54,
0044       // 3D =0xN3
0045       MCCart = 0x03,
0046       MCSpher = 0x13,
0047       MCPInvSpher = 0x23,
0048       EtEtaPhi = 0x33,
0049       EtThetaPhi = 0x43,
0050       MCMomDev = 0x53,
0051       EScaledMomDev = 0x63
0052     };
0053     CandKinResolution();
0054 
0055     /// Create a resolution object given a parametrization code,
0056     /// a covariance matrix (streamed as a vector) and a vector of constraints.
0057     ///
0058     /// In the vector you can put either the full triangular block or just the diagonal terms
0059     ///
0060     /// The triangular block should be written in a way that the constructor
0061     ///  <code>AlgebraicSymMatrixNN(covariance.begin(), covariance.end())</code>
0062     /// works (N = 3 or 4)
0063     CandKinResolution(Parametrization parametrization,
0064                       const std::vector<Scalar> &covariances,
0065                       const std::vector<Scalar> &constraints = std::vector<Scalar>());
0066 
0067     /// Fill in a cresolution object given a parametrization code, a covariance matrix and a vector of constraints.
0068     CandKinResolution(Parametrization parametrization,
0069                       const AlgebraicSymMatrix44 &covariance,
0070                       const std::vector<Scalar> &constraints = std::vector<Scalar>());
0071     ~CandKinResolution();
0072 
0073     /// Return the code of the parametrization used in this object
0074     Parametrization parametrization() const { return parametrization_; }
0075 
0076     /// Returns the number of free parameters in this parametrization
0077     uint32_t dimension() const { return dimensionFrom(parametrization_); }
0078 
0079     /// Returns the full covariance matrix
0080     const AlgebraicSymMatrix44 &covariance() const { return covmatrix_; }
0081 
0082     /// The constraints associated with this parametrization
0083     const std::vector<Scalar> &constraints() const { return constraints_; }
0084 
0085     /// Resolution on eta, given the 4-momentum of the associated Candidate
0086     double resolEta(const LorentzVector &p4) const;
0087 
0088     /// Resolution on theta, given the 4-momentum of the associated Candidate
0089     double resolTheta(const LorentzVector &p4) const;
0090 
0091     /// Resolution on phi, given the 4-momentum of the associated Candidate
0092     double resolPhi(const LorentzVector &p4) const;
0093 
0094     /// Resolution on energy, given the 4-momentum of the associated Candidate
0095     double resolE(const LorentzVector &p4) const;
0096 
0097     /// Resolution on et, given the 4-momentum of the associated Candidate
0098     double resolEt(const LorentzVector &p4) const;
0099 
0100     /// Resolution on the invariant mass, given the 4-momentum of the associated Candidate
0101     /// Warning: returns 0 for mass-constrained parametrizations.
0102     double resolM(const LorentzVector &p4) const;
0103 
0104     /// Resolution on p, given the 4-momentum of the associated Candidate
0105     double resolP(const LorentzVector &p4) const;
0106 
0107     /// Resolution on pt, given the 4-momentum of the associated Candidate
0108     double resolPt(const LorentzVector &p4) const;
0109 
0110     /// Resolution on 1/p, given the 4-momentum of the associated Candidate
0111     double resolPInv(const LorentzVector &p4) const;
0112 
0113     /// Resolution on px, given the 4-momentum of the associated Candidate
0114     double resolPx(const LorentzVector &p4) const;
0115 
0116     /// Resolution on py, given the 4-momentum of the associated Candidate
0117     double resolPy(const LorentzVector &p4) const;
0118 
0119     /// Resolution on pz, given the 4-momentum of the associated Candidate
0120     double resolPz(const LorentzVector &p4) const;
0121 
0122     static int dimensionFrom(Parametrization parametrization) {
0123       return (static_cast<uint32_t>(parametrization) & 0x0F);
0124     }
0125 
0126     static void fillMatrixFrom(Parametrization parametrization,
0127                                const std::vector<Scalar> &covariances,
0128                                AlgebraicSymMatrix44 &covmatrix);
0129 
0130   private:
0131     // persistent
0132     /// Parametrization code
0133     Parametrization parametrization_;
0134     /// Matrix, streamed as a vector
0135     std::vector<Scalar> covariances_;
0136     /// Constraints
0137     std::vector<Scalar> constraints_;
0138 
0139     // transient
0140 
0141     /// Transient copy of the full 4x4 covariance matrix
0142     AlgebraicSymMatrix44 covmatrix_;
0143 
0144     //methods
0145 
0146     /// Fill matrix from vector
0147     void fillMatrix();
0148 
0149     /// Fill vectoor from matrix
0150     void fillVector();
0151   };
0152 
0153   typedef std::vector<CandKinResolution> CandKinResolutionCollection;
0154   typedef edm::ValueMap<CandKinResolution> CandKinResolutionValueMap;
0155 }  // namespace pat
0156 
0157 #endif