CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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_; }
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 
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  virtual ~CandCombiner() { }
145 
146  private:
148  void produce(edm::Event& evt, const edm::EventSetup& es) {
149  using namespace std;
150  using namespace reco;
151  Init::init(combiner_.setup(), evt, es);
152  int n = labels_.size();
153  vector<edm::Handle<CandidateView> > colls(n);
154  for(int i = 0; i < n; ++i)
155  evt.getByToken(tokens_[i], colls[i]);
156 
157  auto_ptr<OutputCollection> out = combiner_.combine(colls, names_.roles());
159  typename OutputCollection::iterator i = out->begin(), e = out->end();
160  for(; i != e; ++i) {
161  names_.set(*i);
162  if(setLongLived_) i->setLongLived();
163  if(setMassConstraint_) i->setMassConstraint();
164  if(setPdgId_) i->setPdgId(pdgId_);
165  }
166  }
167  evt.put(out);
168  }
171 
173  };
174 
175  }
176 }
177 
178 #endif
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
const std::vector< std::string > roles() const
Definition: CandCombiner.h:53
int i
Definition: DBlmapReader.cc:9
tuple cfg
Definition: looper.py:293
std::vector< CompositeCandidate > CompositeCandidateCollection
collection of Candidate objects
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
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 setRoles(const role_collection &roles)
set the roles
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:7
edm::InputTag tag_
Definition: decayParser.h:38
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:194
void set(reco::CompositeCandidate &c) const
Definition: CandCombiner.h:54
std::vector< std::string > roles_
Definition: CandCombiner.h:63
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
virtual ~CandCombiner()
destructor
Definition: CandCombiner.h:144
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
std::vector< edm::EDGetTokenT< CandidateView > > tokens_
Definition: CandCombiner.h:109
RoleNames(const edm::ParameterSet &cfg)
Definition: CandCombiner.h:42
tuple out
Definition: dbtoconf.py:99
CandCombiner(const edm::ParameterSet &cfg)
constructor from parameter settypedef
Definition: CandCombiner.h:132
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
void setName(std::string name)
set the name of the candidate
bool setLongLived_
set long lived flag
Definition: CandCombiner.h:113
void produce(edm::Event &evt, const edm::EventSetup &es)
process an event
Definition: CandCombiner.h:148
std::vector< cand::parser::ConjInfo > labels_
label vector
Definition: CandCombiner.h:108
::CandCombiner< Selector, PairSelector, Cloner, OutputCollection, Setup > combiner_
combiner utility
Definition: CandCombiner.h:170
volatile std::atomic< bool > shutdown_flag false
std::vector< int > dauCharge_
daughter charges
Definition: CandCombiner.h:111
CandCombinerBase(const edm::ParameterSet &cfg)
Definition: CandCombiner.h:68
bool setMassConstraint_
set mass constraint flag
Definition: CandCombiner.h:115