Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:49:56

0001 // $Id: testMakeCompositeCandidate.cc,v 1.1 2009/02/26 09:17:35 llista Exp $

0002 #include <cppunit/extensions/HelperMacros.h>
0003 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0004 #include "CommonTools/CandUtils/interface/makeCompositeCandidate.h"
0005 #include "CommonTools/CandUtils/interface/AddFourMomenta.h"
0006 using namespace reco;
0007 using namespace std;
0008 
0009 namespace test {
0010   class DummyCandidate : public reco::LeafCandidate {
0011   public:
0012     DummyCandidate(const LorentzVector& p, Charge q = 0) : reco::LeafCandidate(q, p) {}
0013     virtual DummyCandidate* clone() const { return new DummyCandidate(*this); }
0014   };
0015 }  // namespace test

0016 
0017 class testMakeCompositeCandidate : public CppUnit::TestFixture {
0018   CPPUNIT_TEST_SUITE(testMakeCompositeCandidate);
0019   CPPUNIT_TEST(checkAll);
0020   CPPUNIT_TEST_SUITE_END();
0021 
0022 public:
0023   void setUp() {}
0024   void tearDown() {}
0025   void checkAll();
0026 };
0027 
0028 CPPUNIT_TEST_SUITE_REGISTRATION(testMakeCompositeCandidate);
0029 
0030 void testMakeCompositeCandidate::checkAll() {
0031   reco::Particle::LorentzVector p1(1.0, 2.0, 3.0, 4.0), p2(1.5, 2.5, 3.5, 4.5);
0032   reco::Particle::Charge q1(1), q2(-1);
0033   test::DummyCandidate t1(p1, q1);
0034   test::DummyCandidate t2(p2, q2);
0035 
0036   unique_ptr<Candidate> cmp = makeCompositeCandidate(t1, t2)[AddFourMomenta()];
0037   CPPUNIT_ASSERT(cmp->numberOfDaughters() == 2);
0038   const reco::Candidate* d[2];
0039   d[0] = cmp->daughter(0);
0040   d[1] = cmp->daughter(1);
0041   const double epsilon = 1.e-5;
0042   CPPUNIT_ASSERT(d[0]->charge() == q1);
0043   CPPUNIT_ASSERT(fabs(d[0]->p4().pt() - p1.pt()) < epsilon);
0044   CPPUNIT_ASSERT(fabs(d[0]->p4().eta() - p1.eta()) < epsilon);
0045   CPPUNIT_ASSERT(fabs(d[0]->p4().phi() - p1.phi()) < epsilon);
0046   CPPUNIT_ASSERT(d[1]->charge() == q2);
0047   CPPUNIT_ASSERT(fabs(d[1]->p4().pt() - p2.pt()) < epsilon);
0048   CPPUNIT_ASSERT(fabs(d[1]->p4().eta() - p2.eta()) < epsilon);
0049   CPPUNIT_ASSERT(fabs(d[1]->p4().phi() - p2.phi()) < epsilon);
0050 
0051   reco::Particle::LorentzVector ptot = p1 + p2;
0052   CPPUNIT_ASSERT(fabs(cmp->pt() - ptot.pt()) < epsilon);
0053   CPPUNIT_ASSERT(fabs(cmp->eta() - ptot.eta()) < epsilon);
0054   CPPUNIT_ASSERT(fabs(cmp->phi() - ptot.phi()) < epsilon);
0055 
0056   unique_ptr<Candidate> cmp3 = makeCompositeCandidate(t1, t2, t1)[AddFourMomenta()];
0057   unique_ptr<Candidate> cmp4 = makeCompositeCandidate(t1, t2, t1, t2)[AddFourMomenta()];
0058 }