CMS 3D CMS Logo

NamedCandCombiner.h
Go to the documentation of this file.
1 #ifndef CandAlgos_NamedCandCombiner_h
2 #define CandAlgos_NamedCandCombiner_h
3 
25 #include "CommonTools/Utilities/interface/cutParser.h"
31 #include <string>
32 #include <vector>
33 #include <algorithm>
34 
35 namespace edm {
36  class ParameterSet;
37 }
38 
39 namespace reco {
40  namespace modules {
41 
44  setLongLived_(false),
45  setMassConstraint_(false),
46  setPdgId_(false) {
47  using namespace cand::parser;
48  using namespace std;
49  string decay(cfg.getParameter<string>("decay"));
50  if(decayParser(decay, labels_))
51  for(vector<ConjInfo>::iterator label = labels_.begin();
52  label != labels_.end(); ++label)
53  if(label->mode_ == ConjInfo::kPlus)
54  dauCharge_.push_back( 1 );
55  else if (label->mode_ == ConjInfo::kMinus)
56  dauCharge_.push_back(-1);
57  else
58  dauCharge_.push_back(0);
59  else
61  "failed to parse \"" + decay + "\"");
62 
63  int lists = labels_.size();
64  if(lists != 2 && lists != 3)
66  "invalid number of collections");
67  bool found;
68  const string setLongLived("setLongLived");
69  vector<string> vBoolParams = cfg.getParameterNamesForType<bool>();
70  found = find(vBoolParams.begin(), vBoolParams.end(), setLongLived) != vBoolParams.end();
71  if(found) setLongLived_ = cfg.getParameter<bool>("setLongLived");
72  const string setMassConstraint("setMassConstraint");
73  found = find(vBoolParams.begin(), vBoolParams.end(), setMassConstraint) != vBoolParams.end();
74  if(found) setMassConstraint_ = cfg.getParameter<bool>("setMassConstraint");
75  const string setPdgId("setPdgId");
76  vector<string> vIntParams = cfg.getParameterNamesForType<int>();
77  found = find(vIntParams.begin(), vIntParams.end(), setPdgId) != vIntParams.end();
78  if(found) { setPdgId_ = true; pdgId_ = cfg.getParameter<int>("setPdgId"); }
79  tokens_ = edm::vector_transform( labels_, [this](ConjInfo const & cI){return consumes<CandidateView>(cI.tag_);} );
80 
81  name_ = cfg.getParameter<std::string>( "name" );
82  roles_= cfg.getParameter<std::vector<std::string> > ( "roles" );
83  }
84  protected:
86  std::vector<cand::parser::ConjInfo> labels_;
87  std::vector<EDGetTokenT<CandidateView> > tokens_;
89  std::vector<int> dauCharge_;
95  bool setPdgId_;
97  int pdgId_;
100  // Name of the roles
101  std::vector<std::string> roles_;
102  };
103 
104  template<typename Selector,
105  typename PairSelector = AnyPairSelector,
106  typename Cloner = ::combiner::helpers::NormalClone,
107  typename Setup = AddFourMomenta,
109  >
111  public:
114  NamedCandCombinerBase( cfg ),
115  combiner_( name_,
116  reco::modules::make<Selector>( cfg ),
117  reco::modules::make<PairSelector>( cfg ),
118  Setup( cfg ),
119  cfg.existsAs<bool>("checkCharge") ? cfg.getParameter<bool>("checkCharge") : true,
120  cfg.existsAs<bool>("checkOverlap") ? cfg.getParameter<bool>("checkOverlap") : true,
121  dauCharge_ ) {
122  produces<reco::NamedCompositeCandidateCollection>();
123  }
125  virtual ~NamedCandCombiner() { }
126 
127  private:
129  void produce(edm::Event& evt, const edm::EventSetup& es) {
130  using namespace std;
131  using namespace reco;
132  Init::init(combiner_.setup(), evt, es);
133  int n = labels_.size();
134  std::vector<edm::Handle<CandidateView> > colls(n);
135  for(int i = 0; i < n; ++i) {
136  evt.getByToken(tokens_[i], colls[i]);
137  }
138  std::vector<CandidatePtrVector> cv;
139  for(typename std::vector<edm::Handle<CandidateView> >::const_iterator c = colls.begin();
140  c != colls.end(); ++ c) {
142  CandidateView::size_type n_view = (*c)->size();
143  for ( CandidateView::size_type iview = 0; iview < n_view; ++iview ) {
144  CandidatePtr ri( *c, iview );
145  r.push_back( ri );
146  }
147  cv.push_back(r);
148  }
149  std::auto_ptr<NamedCompositeCandidateCollection> out = combiner_.combine(cv, roles_);
150  if(setLongLived_ || setMassConstraint_ || setPdgId_) {
151  typename NamedCompositeCandidateCollection::iterator i = out->begin(), e = out->end();
152  for(; i != e; ++i) {
153  i->setName( name_ );
154  i->setRoles( roles_ );
155  i->applyRoles();
156  if(setLongLived_) i->setLongLived();
157  if(setMassConstraint_) i->setMassConstraint();
158  if(setPdgId_) i->setPdgId(pdgId_);
159  }
160  }
161  evt.put(out);
162  }
165  };
166 
167  }
168 }
169 
170 #endif
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
unsigned int size_type
Definition: View.h:90
std::string name_
Name of this candidate.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
NamedCandCombinerBase(const edm::ParameterSet &cfg)
bool setMassConstraint_
set mass constraint flag
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
void push_back(Ptr< T > const &iPtr)
Definition: PtrVector.h:140
const double kPlus
Definition: ParticleMasses.h:8
int init
Definition: HydjetWrapper.h:67
S make(const edm::ParameterSet &cfg)
cv
Definition: cuy.py:362
std::vector< int > dauCharge_
daughter charges
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
std::vector< std::string > roles_
virtual ~NamedCandCombiner()
destructor
edm::InputTag tag_
Definition: decayParser.h:38
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:194
std::vector< cand::parser::ConjInfo > labels_
label vector
bool decayParser(const std::string &iValue, std::vector< ConjInfo > &oStrings)
NamedCandCombiner(const edm::ParameterSet &cfg)
constructor from parameter settypedef
void produce(edm::Event &evt, const edm::EventSetup &es)
process an event
bool setLongLived_
set long lived flag
fixed size matrix
HLT enums.
::NamedCandCombiner< Selector, PairSelector, Cloner, Setup > combiner_
combiner utility
std::vector< EDGetTokenT< CandidateView > > tokens_