Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:53

0001 #include <cppunit/extensions/HelperMacros.h>
0002 #include "DataFormats/TrackReco/interface/Track.h"
0003 
0004 class testTrack : public CppUnit::TestFixture {
0005   CPPUNIT_TEST_SUITE(testTrack);
0006   CPPUNIT_TEST(checkAll);
0007   CPPUNIT_TEST_SUITE_END();
0008 
0009 public:
0010   void setUp() {}
0011   void tearDown() {}
0012   void checkAll();
0013 };
0014 
0015 CPPUNIT_TEST_SUITE_REGISTRATION(testTrack);
0016 
0017 void testTrack::checkAll() {
0018   const double chi2 = 20.0;
0019   const int ndof = 10;
0020   reco::Track::Point v(1, 2, 3);
0021   reco::Track::Vector p(10.1, 20.2, 30.3);
0022   double e[] = {1.1, 1.2, 2.2, 1.3, 2.3, 3.3, 1.4, 2.4, 3.4, 4.4, 1.5, 2.5, 3.5, 4.5, 5.5};
0023 
0024   reco::TrackBase::CovarianceMatrix cov(e, e + 15);
0025   reco::Track t(chi2, ndof, v, p, +1, cov);
0026   CPPUNIT_ASSERT(t.chi2() == chi2);
0027   CPPUNIT_ASSERT(t.ndof() == ndof);
0028   CPPUNIT_ASSERT(t.normalizedChi2() == chi2 / ndof);
0029   CPPUNIT_ASSERT(t.vertex() == v);
0030   CPPUNIT_ASSERT(t.momentum() == p);
0031   //CPPUNIT_ASSERT( t.covariance() == cov );
0032 
0033   int k = 0;
0034   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(0, 0), e[k++], 1e-6);
0035   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(1, 0), e[k++], 1e-6);
0036   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(1, 1), e[k++], 1e-6);
0037   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(2, 0), e[k++], 1e-6);
0038   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(2, 1), e[k++], 1e-6);
0039   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(2, 2), e[k++], 1e-6);
0040   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(3, 0), e[k++], 1e-6);
0041   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(3, 1), e[k++], 1e-6);
0042   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(3, 2), e[k++], 1e-6);
0043   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(3, 3), e[k++], 1e-6);
0044   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(4, 0), e[k++], 1e-6);
0045   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(4, 1), e[k++], 1e-6);
0046   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(4, 2), e[k++], 1e-6);
0047   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(4, 3), e[k++], 1e-6);
0048   CPPUNIT_ASSERT_DOUBLES_EQUAL(cov(4, 4), e[k++], 1e-6);
0049 
0050   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(0, 0), cov(0, 0), 1e-6);
0051   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(0, 1), cov(0, 1), 1e-6);
0052   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(0, 2), cov(0, 2), 1e-6);
0053   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(0, 3), cov(0, 3), 1e-6);
0054   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(0, 4), cov(0, 4), 1e-6);
0055   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(1, 1), cov(1, 1), 1e-6);
0056   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(1, 2), cov(1, 2), 1e-6);
0057   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(1, 3), cov(1, 3), 1e-6);
0058   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(1, 4), cov(1, 4), 1e-6);
0059   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(2, 2), cov(2, 2), 1e-6);
0060   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(2, 3), cov(2, 3), 1e-6);
0061   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(2, 4), cov(2, 4), 1e-6);
0062   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(3, 3), cov(3, 3), 1e-6);
0063   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(3, 4), cov(3, 4), 1e-6);
0064   CPPUNIT_ASSERT_DOUBLES_EQUAL(t.covariance(4, 4), cov(4, 4), 1e-6);
0065 
0066   auto qual = reco::TrackBase::qualityByName("highPurity");
0067   CPPUNIT_ASSERT(qual == reco::TrackBase::highPurity);
0068   t.setQuality(reco::TrackBase::loose);
0069   CPPUNIT_ASSERT(t.quality(reco::TrackBase::loose) == true);
0070   CPPUNIT_ASSERT(t.quality(reco::TrackBase::highPurity) == false);
0071   CPPUNIT_ASSERT(t.quality(reco::TrackBase::confirmed) == false);
0072   CPPUNIT_ASSERT(t.quality(reco::TrackBase::goodIterative) == false);
0073   t.setQuality(reco::TrackBase::highPurity);
0074   CPPUNIT_ASSERT(t.quality(reco::TrackBase::loose) == true);
0075   CPPUNIT_ASSERT(t.quality(reco::TrackBase::highPurity) == true);
0076   CPPUNIT_ASSERT(t.quality(reco::TrackBase::confirmed) == false);
0077   CPPUNIT_ASSERT(t.quality(reco::TrackBase::goodIterative) == true);
0078   t.setQuality(reco::TrackBase::confirmed);
0079   CPPUNIT_ASSERT(t.quality(reco::TrackBase::loose) == true);
0080   CPPUNIT_ASSERT(t.quality(reco::TrackBase::highPurity) == true);
0081   CPPUNIT_ASSERT(t.quality(reco::TrackBase::confirmed) == true);
0082   CPPUNIT_ASSERT(t.quality(reco::TrackBase::goodIterative) == true);
0083   t.setQuality(reco::TrackBase::undefQuality);
0084   CPPUNIT_ASSERT(t.quality(reco::TrackBase::loose) == false);
0085   CPPUNIT_ASSERT(t.quality(reco::TrackBase::highPurity) == false);
0086   CPPUNIT_ASSERT(t.quality(reco::TrackBase::confirmed) == false);
0087   CPPUNIT_ASSERT(t.quality(reco::TrackBase::goodIterative) == false);
0088   t.setQuality(reco::TrackBase::loose);
0089   t.setQuality(reco::TrackBase::confirmed);
0090   CPPUNIT_ASSERT(t.quality(reco::TrackBase::loose) == true);
0091   CPPUNIT_ASSERT(t.quality(reco::TrackBase::highPurity) == false);
0092   CPPUNIT_ASSERT(t.quality(reco::TrackBase::confirmed) == true);
0093   CPPUNIT_ASSERT(t.quality(reco::TrackBase::goodIterative) == false);
0094 
0095   reco::TrackBase::AlgoMask am;
0096   t.setAlgorithm(reco::TrackBase::ctf);
0097   am.set(reco::TrackBase::ctf);
0098   CPPUNIT_ASSERT(t.algo() == reco::TrackBase::ctf);
0099   CPPUNIT_ASSERT(t.algoMask() == am);
0100   am.set(reco::TrackBase::cosmics);
0101   t.setOriginalAlgorithm(reco::TrackBase::cosmics);
0102   CPPUNIT_ASSERT(t.algo() == reco::TrackBase::ctf);
0103   CPPUNIT_ASSERT(t.originalAlgo() == reco::TrackBase::cosmics);
0104   CPPUNIT_ASSERT(t.algoMask() == am);
0105 }