CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DataFormats/PatCandidates/src/CandKinResolution.cc

Go to the documentation of this file.
00001 #include <DataFormats/PatCandidates/interface/CandKinResolution.h>
00002 #include <DataFormats/PatCandidates/interface/ResolutionHelper.h>
00003 #include <DataFormats/PatCandidates/interface/ParametrizationHelper.h>
00004 
00005 
00006 pat::CandKinResolution::CandKinResolution() : 
00007     parametrization_(Invalid), 
00008     covariances_(),
00009     constraints_(),
00010     hasMatrix_(false), covmatrix_() 
00011 { 
00012 }
00013 
00014 pat::CandKinResolution::CandKinResolution(Parametrization parametrization, const std::vector<Scalar> &covariances, const std::vector<Scalar> &constraints) :
00015     parametrization_(parametrization),
00016     covariances_(covariances), 
00017     constraints_(constraints),
00018     hasMatrix_(true),
00019     covmatrix_()
00020 {
00021     fillMatrix();
00022 }
00023 
00024 pat::CandKinResolution::CandKinResolution(Parametrization parametrization, const AlgebraicSymMatrix44 &covariance, const std::vector<Scalar> &constraints) :
00025     parametrization_(parametrization),
00026     covariances_(), 
00027     constraints_(constraints),
00028     hasMatrix_(true),
00029     covmatrix_(covariance)
00030 {
00031     fillVector();
00032     if (sizeof(double) != sizeof(Scalar)) { // should become boost::mpl::if_c
00033         fillMatrix(); // forcing double => float => double conversion 
00034     }
00035 }
00036 
00037 pat::CandKinResolution::~CandKinResolution() {
00038 }
00039 
00040 double pat::CandKinResolution::resolEta(const pat::CandKinResolution::LorentzVector &p4)   const
00041 {
00042     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00043     return pat::helper::ResolutionHelper::getResolEta(parametrization_, covmatrix_, p4);
00044 }
00045 double pat::CandKinResolution::resolTheta(const pat::CandKinResolution::LorentzVector &p4) const
00046 {
00047     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00048     return pat::helper::ResolutionHelper::getResolTheta(parametrization_, covmatrix_, p4);
00049 }
00050 double pat::CandKinResolution::resolPhi(const pat::CandKinResolution::LorentzVector &p4)   const
00051 {
00052     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00053     return pat::helper::ResolutionHelper::getResolPhi(parametrization_, covmatrix_, p4);
00054 }
00055 double pat::CandKinResolution::resolE(const pat::CandKinResolution::LorentzVector &p4)     const
00056 {
00057     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00058     return pat::helper::ResolutionHelper::getResolE(parametrization_, covmatrix_, p4);
00059 }
00060 double pat::CandKinResolution::resolEt(const pat::CandKinResolution::LorentzVector &p4)    const
00061 {
00062     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00063     return pat::helper::ResolutionHelper::getResolEt(parametrization_, covmatrix_, p4);
00064 }
00065 double pat::CandKinResolution::resolM(const pat::CandKinResolution::LorentzVector &p4)     const
00066 {
00067     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00068     return pat::helper::ResolutionHelper::getResolM(parametrization_, covmatrix_, p4);
00069 }
00070 double pat::CandKinResolution::resolP(const pat::CandKinResolution::LorentzVector &p4)     const
00071 {
00072     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00073     return pat::helper::ResolutionHelper::getResolP(parametrization_, covmatrix_, p4);
00074 }
00075 double pat::CandKinResolution::resolPt(const pat::CandKinResolution::LorentzVector &p4)    const
00076 {
00077     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00078     return pat::helper::ResolutionHelper::getResolPt(parametrization_, covmatrix_, p4);
00079 }
00080 double pat::CandKinResolution::resolPInv(const pat::CandKinResolution::LorentzVector &p4)  const
00081 {
00082     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00083     return pat::helper::ResolutionHelper::getResolPInv(parametrization_, covmatrix_, p4);
00084 }
00085 double pat::CandKinResolution::resolPx(const pat::CandKinResolution::LorentzVector &p4)    const
00086 {
00087     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00088     return pat::helper::ResolutionHelper::getResolPx(parametrization_, covmatrix_, p4);
00089 }
00090 double pat::CandKinResolution::resolPy(const pat::CandKinResolution::LorentzVector &p4)    const
00091 {
00092     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00093     return pat::helper::ResolutionHelper::getResolPy(parametrization_, covmatrix_, p4);
00094 }
00095 double pat::CandKinResolution::resolPz(const pat::CandKinResolution::LorentzVector &p4)    const
00096 {
00097     if (!hasMatrix_) { fillMatrix(); hasMatrix_ = true; }
00098     return pat::helper::ResolutionHelper::getResolPz(parametrization_, covmatrix_, p4);
00099 }
00100 
00101 void pat::CandKinResolution::fillVector() { 
00102     if (dimension() == 3) {
00103         AlgebraicSymMatrix33 sub = covmatrix_.Sub<AlgebraicSymMatrix33>(0,0);
00104         covariances_.insert(covariances_.end(), sub.begin(), sub.end());
00105     } else {
00106         covariances_.insert(covariances_.end(), covmatrix_.begin(), covmatrix_.end());
00107     }
00108 }
00109 void pat::CandKinResolution::fillMatrix() const { 
00110     if (dimension() == 3) {
00111         if (covariances_.size() == 3) {
00112             for (int i = 0; i < 3; ++i) covmatrix_(i,i) = covariances_[i];
00113         } else {
00114             covmatrix_.Place_at(AlgebraicSymMatrix33(covariances_.begin(), covariances_.end()), 0, 0);
00115         }
00116     } else if (dimension() == 4) {
00117         if (covariances_.size() == 4) {
00118             for (int i = 0; i < 4; ++i) covmatrix_(i,i) = covariances_[i];
00119         } else {
00120             covmatrix_ = AlgebraicSymMatrix44(covariances_.begin(), covariances_.end());
00121         }
00122     }
00123 }