Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // $Id: testMakeCompositePtrCandidate.cc,v 1.1 2009/09/29 14:13:28 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 #include "DataFormats/Common/interface/OrphanHandle.h"
0007 #include <iostream>
0008 using namespace reco;
0009 using namespace std;
0010 
0011 namespace test {
0012   class DummyCandidate : public reco::LeafCandidate {
0013   public:
0014     DummyCandidate(const LorentzVector& p, Charge q = 0) : reco::LeafCandidate(q, p) {}
0015     virtual DummyCandidate* clone() const { return new DummyCandidate(*this); }
0016   };
0017 
0018   typedef std::vector<DummyCandidate> DummyCandidateCollection;
0019 }  // namespace test

0020 
0021 class testMakePtrCompositeCandidate : public CppUnit::TestFixture {
0022   CPPUNIT_TEST_SUITE(testMakePtrCompositeCandidate);
0023   CPPUNIT_TEST(checkAll);
0024   CPPUNIT_TEST_SUITE_END();
0025 
0026 public:
0027   void setUp() {}
0028   void tearDown() {}
0029   void checkAll();
0030 };
0031 
0032 CPPUNIT_TEST_SUITE_REGISTRATION(testMakePtrCompositeCandidate);
0033 
0034 void testMakePtrCompositeCandidate::checkAll() {
0035   reco::Particle::LorentzVector p1(1.0, 2.0, 3.0, 4.0), p2(1.5, 2.5, 3.5, 4.5);
0036   reco::Particle::Charge q1(1), q2(-1);
0037   test::DummyCandidate t1(p1, q1);
0038   test::DummyCandidate t2(p2, q2);
0039   edm::ProductID const pid(1, 1);
0040   test::DummyCandidateCollection dcol;
0041   dcol.push_back(t1);
0042   dcol.push_back(t2);
0043   edm::OrphanHandle<test::DummyCandidateCollection> handle(&dcol, pid);
0044   reco::CandidatePtr ptr1(handle, 0), ptr2(handle, 1);
0045   unique_ptr<Candidate> cmp = makeCompositePtrCandidate(ptr1, ptr2)[AddFourMomenta()];
0046   CPPUNIT_ASSERT(cmp->numberOfDaughters() == 2);
0047   const reco::Candidate* d[2];
0048   const Candidate& cmp2 = *cmp;
0049   d[0] = cmp2.daughter(0);
0050   d[1] = cmp2.daughter(1);
0051   CPPUNIT_ASSERT(d[0] != 0);
0052   CPPUNIT_ASSERT(d[1] != 0);
0053   const double epsilon = 1.e-5;
0054   CPPUNIT_ASSERT(d[0]->charge() == q1);
0055   CPPUNIT_ASSERT(fabs(d[0]->p4().pt() - p1.pt()) < epsilon);
0056   CPPUNIT_ASSERT(fabs(d[0]->p4().eta() - p1.eta()) < epsilon);
0057   CPPUNIT_ASSERT(fabs(d[0]->p4().phi() - p1.phi()) < epsilon);
0058   CPPUNIT_ASSERT(d[1]->charge() == q2);
0059   CPPUNIT_ASSERT(fabs(d[1]->p4().pt() - p2.pt()) < epsilon);
0060   CPPUNIT_ASSERT(fabs(d[1]->p4().eta() - p2.eta()) < epsilon);
0061   CPPUNIT_ASSERT(fabs(d[1]->p4().phi() - p2.phi()) < epsilon);
0062 
0063   reco::Particle::LorentzVector ptot = p1 + p2;
0064   CPPUNIT_ASSERT(fabs(cmp->pt() - ptot.pt()) < epsilon);
0065   CPPUNIT_ASSERT(fabs(cmp->eta() - ptot.eta()) < epsilon);
0066   CPPUNIT_ASSERT(fabs(cmp->phi() - ptot.phi()) < epsilon);
0067 
0068   unique_ptr<Candidate> cmp3 = makeCompositePtrCandidate(ptr1, ptr2, ptr1)[AddFourMomenta()];
0069   unique_ptr<Candidate> cmp4 = makeCompositePtrCandidate(ptr1, ptr2, ptr1, ptr2)[AddFourMomenta()];
0070 }