Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:49:17

0001 #ifndef Candidate_CompositeCandidate_h
0002 #define Candidate_CompositeCandidate_h
0003 #include "DataFormats/Candidate/interface/LeafCandidate.h"
0004 #include <memory>
0005 /** \class reco::CompositeCandidate
0006  *
0007  * A Candidate composed of daughters. 
0008  * The daughters are owned by the composite candidate.
0009  *
0010  * \author Luca Lista, INFN
0011  *
0012  *
0013  */
0014 
0015 #include "DataFormats/Candidate/interface/CompositeCandidateFwd.h"
0016 #include <string>
0017 #include <vector>
0018 
0019 namespace reco {
0020 
0021   class CompositeCandidate : public LeafCandidate {
0022   public:
0023     /// collection of daughters
0024     typedef CandidateCollection daughters;
0025     typedef std::vector<std::string> role_collection;
0026     /// default constructor
0027     CompositeCandidate(std::string name = "") : LeafCandidate(), name_(name) {}
0028     /// constructor from values
0029     template <typename P4>
0030     CompositeCandidate(Charge q,
0031                        const P4& p4,
0032                        const Point& vtx = Point(0, 0, 0),
0033                        int pdgId = 0,
0034                        int status = 0,
0035                        bool integerCharge = true,
0036                        std::string name = "")
0037         : LeafCandidate(q, p4, vtx, pdgId, status, integerCharge), name_(name) {}
0038     /// constructor from values
0039     explicit CompositeCandidate(const Candidate& p, const std::string& name = "");
0040     /// constructor from values
0041     explicit CompositeCandidate(const Candidate& p, const std::string& name, role_collection const& roles);
0042     /// destructor
0043     ~CompositeCandidate() override;
0044     /// get the name of the candidate
0045     std::string name() const { return name_; }
0046     /// set the name of the candidate
0047     void setName(std::string name) { name_ = name; }
0048     /// get the roles
0049     role_collection const& roles() const { return roles_; }
0050     /// set the roles
0051     void setRoles(const role_collection& roles) {
0052       roles_.clear();
0053       roles_ = roles;
0054     }
0055     /// returns a clone of the candidate
0056     CompositeCandidate* clone() const override;
0057     /// number of daughters
0058     size_type numberOfDaughters() const override;
0059     /// return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode)
0060     const Candidate* daughter(size_type) const override;
0061     /// return daughter at a given position, i = 0, ... numberOfDaughters() - 1
0062     Candidate* daughter(size_type) override;
0063     // Get candidate based on role
0064     Candidate* daughter(const std::string& s) override;
0065     const Candidate* daughter(const std::string& s) const override;
0066     /// add a clone of the passed candidate as daughter
0067     void addDaughter(const Candidate&, const std::string& s = "");
0068     /// add a clone of the passed candidate as daughter
0069     void addDaughter(std::unique_ptr<Candidate>, const std::string& s = "");
0070     /// clear daughters
0071     void clearDaughters() { dau.clear(); }
0072     // clear roles
0073     void clearRoles() { roles_.clear(); }
0074     // Apply the roles to the objects
0075     void applyRoles();
0076     /// number of mothers (zero or one in most of but not all the cases)
0077     size_type numberOfMothers() const override;
0078     /// return pointer to mother
0079     const Candidate* mother(size_type i = 0) const override;
0080 
0081   private:
0082     /// collection of daughters
0083     daughters dau;
0084     /// check overlap with another daughter
0085     bool overlap(const Candidate&) const override;
0086     /// candidate name
0087     std::string name_;
0088     /// candidate roles
0089     role_collection roles_;
0090   };
0091 
0092 }  // namespace reco
0093 
0094 #endif