Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:18

0001 #ifndef CommonTools_Utils_PdgIdSelector_h
0002 #define CommonTools_Utils_PdgIdSelector_h
0003 /* \class PdgIdSelector
0004  *
0005  * \author Luca Lista, INFN
0006  *
0007  * $Id: PdgIdSelector.h,v 1.4 2007/11/14 10:14:21 llista Exp $
0008  */
0009 #include <vector>
0010 #include <algorithm>
0011 
0012 struct PdgIdSelector {
0013   PdgIdSelector(const std::vector<int>& pdgId) {
0014     for (std::vector<int>::const_iterator i = pdgId.begin(); i != pdgId.end(); ++i)
0015       pdgId_.push_back(abs(*i));
0016     begin_ = pdgId_.begin();
0017     end_ = pdgId_.end();
0018   }
0019   PdgIdSelector(const PdgIdSelector& o) : pdgId_(o.pdgId_), begin_(pdgId_.begin()), end_(pdgId_.end()) {}
0020   PdgIdSelector& operator=(const PdgIdSelector& o) = default;
0021   PdgIdSelector& operator==(const PdgIdSelector& o) {
0022     *this = o;
0023     return *this;
0024   }
0025   template <typename T>
0026   bool operator()(const T& t) const {
0027     return std::find(begin_, end_, abs(t.pdgId())) != end_;
0028   }
0029 
0030 private:
0031   std::vector<int> pdgId_;
0032   std::vector<int>::const_iterator begin_, end_;
0033 };
0034 
0035 #endif