CMS 3D CMS Logo

CandCombiner.h
Go to the documentation of this file.
1 #ifndef CandAlgos_CandCombiner_h
2 #define CandAlgos_CandCombiner_h
3 
29 #include <string>
30 #include <vector>
31 #include <algorithm>
32 
33 namespace edm {
34  class ParameterSet;
35 }
36 
37 namespace reco {
38  namespace modules {
39 
40 
41  struct RoleNames {
42  explicit RoleNames(const edm::ParameterSet & cfg) {
43 
44  if ( cfg.exists("name") )
45  name_ = cfg.getParameter<std::string>("name");
46  else
47  name_ = "";
48  if ( cfg.exists("roles") )
49  roles_ = cfg.getParameter<std::vector<std::string> >("roles");
50  else
51  roles_ = std::vector<std::string>();
52  }
53  const std::vector<std::string> roles() const { return roles_; }
54  void set(reco::CompositeCandidate &c) const {
55  c.setName(name_);
56  c.setRoles(roles_);
57  c.applyRoles();
58  }
59  private:
62  // Name of the roles
63  std::vector<std::string> roles_;
64  };
65 
66 
69  setLongLived_(false),
70  setMassConstraint_(false),
71  setPdgId_(false) {
72  using namespace cand::parser;
73  using namespace std;
74  string decay(cfg.getParameter<string>("decay"));
75  if(decayParser(decay, labels_))
76  for(vector<ConjInfo>::iterator label = labels_.begin();
77  label != labels_.end(); ++label)
78  if(label->mode_ == ConjInfo::kPlus)
79  dauCharge_.push_back(1);
80  else if (label->mode_ == ConjInfo::kMinus)
81  dauCharge_.push_back(-1);
82  else
83  dauCharge_.push_back(0);
84  else
86  "failed to parse \"" + decay + "\"");
87 
88  int lists = labels_.size();
89  if(lists != 2 && lists != 3)
91  "invalid number of collections");
92  bool found;
93  const string setLongLived("setLongLived");
94  vector<string> vBoolParams = cfg.getParameterNamesForType<bool>();
95  found = find(vBoolParams.begin(), vBoolParams.end(), setLongLived) != vBoolParams.end();
96  if(found) setLongLived_ = cfg.getParameter<bool>("setLongLived");
97  const string setMassConstraint("setMassConstraint");
98  found = find(vBoolParams.begin(), vBoolParams.end(), setMassConstraint) != vBoolParams.end();
99  if(found) setMassConstraint_ = cfg.getParameter<bool>("setMassConstraint");
100  const string setPdgId("setPdgId");
101  vector<string> vIntParams = cfg.getParameterNamesForType<int>();
102  found = find(vIntParams.begin(), vIntParams.end(), setPdgId) != vIntParams.end();
103  if(found) { setPdgId_ = true; pdgId_ = cfg.getParameter<int>("setPdgId"); }
104  tokens_ = edm::vector_transform( labels_, [this](ConjInfo const & cI){return consumes<CandidateView>(cI.tag_);} );
105  }
106  protected:
108  std::vector<cand::parser::ConjInfo> labels_;
109  std::vector<edm::EDGetTokenT<CandidateView> > tokens_;
111  std::vector<int> dauCharge_;
117  bool setPdgId_;
119  int pdgId_;
120  };
121 
122  template<typename Selector,
123  typename PairSelector = AnyPairSelector,
124  typename Cloner = ::combiner::helpers::NormalClone,
125  typename OutputCollection = reco::CompositeCandidateCollection,
126  typename Setup = AddFourMomenta,
128  >
130  public:
132  explicit CandCombiner(const edm::ParameterSet & cfg) :
133  CandCombinerBase(cfg),
134  combiner_(reco::modules::make<Selector>(cfg, consumesCollector()),
135  reco::modules::make<PairSelector>(cfg),
136  Setup(cfg),
137  cfg.existsAs<bool>("checkCharge") ? cfg.getParameter<bool>("checkCharge") : true,
138  cfg.existsAs<bool>("checkOverlap") ? cfg.getParameter<bool>("checkOverlap") : true,
139  dauCharge_),
140  names_(cfg) {
141  produces<OutputCollection>();
142  }
144  ~CandCombiner() override { }
145 
146  private:
148  void produce(edm::Event& evt, const edm::EventSetup& es) override {
149  Init::init(combiner_.setup(), evt, es);
150  int n = labels_.size();
151  std::vector<edm::Handle<CandidateView> > colls(n);
152  for(int i = 0; i < n; ++i)
153  evt.getByToken(tokens_[i], colls[i]);
154 
155  std::unique_ptr<OutputCollection> out = combiner_.combine(colls, names_.roles());
156  if(setLongLived_ || setMassConstraint_ || setPdgId_) {
157  typename OutputCollection::iterator i = out->begin(), e = out->end();
158  for(; i != e; ++i) {
159  names_.set(*i);
160  if(setLongLived_) i->setLongLived();
161  if(setMassConstraint_) i->setMassConstraint();
162  if(setPdgId_) i->setPdgId(pdgId_);
163  }
164  }
165  evt.put(std::move(out));
166  }
169 
171  };
172 
173  }
174 }
175 
176 #endif
type
Definition: HCALResponse.h:21
~CandCombiner() override
destructor
Definition: CandCombiner.h:144
T getParameter(std::string const &) const
const std::vector< std::string > roles() const
Definition: CandCombiner.h:53
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
std::vector< CompositeCandidate > CompositeCandidateCollection
collection of Candidate objects
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
const double kPlus
Definition: ParticleMasses.h:8
int init
Definition: HydjetWrapper.h:67
S make(const edm::ParameterSet &cfg)
bool exists(std::string const &parameterName) const
checks if a parameter exists
int pdgId_
which pdgId to set
Definition: CandCombiner.h:119
void produce(edm::Event &evt, const edm::EventSetup &es) override
process an event
Definition: CandCombiner.h:148
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
edm::InputTag tag_
Definition: decayParser.h:38
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:193
std::vector< std::string > roles_
Definition: CandCombiner.h:63
std::vector< edm::EDGetTokenT< CandidateView > > tokens_
Definition: CandCombiner.h:109
RoleNames(const edm::ParameterSet &cfg)
Definition: CandCombiner.h:42
CandCombiner(const edm::ParameterSet &cfg)
constructor from parameter settypedef
Definition: CandCombiner.h:132
std::vector< edm::EDGetTokenT< int > > tokens_
std::string name_
Name of this candidate.
Definition: CandCombiner.h:61
bool decayParser(const std::string &iValue, std::vector< ConjInfo > &oStrings)
bool setPdgId_
set pdgId flag
Definition: CandCombiner.h:117
bool setLongLived_
set long lived flag
Definition: CandCombiner.h:113
fixed size matrix
HLT enums.
std::vector< cand::parser::ConjInfo > labels_
label vector
Definition: CandCombiner.h:108
::CandCombiner< Selector, PairSelector, Cloner, OutputCollection, Setup > combiner_
combiner utility
Definition: CandCombiner.h:168
std::vector< int > dauCharge_
daughter charges
Definition: CandCombiner.h:111
def move(src, dest)
Definition: eostools.py:511
CandCombinerBase(const edm::ParameterSet &cfg)
Definition: CandCombiner.h:68
bool setMassConstraint_
set mass constraint flag
Definition: CandCombiner.h:115