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  struct RoleNames {
41  explicit RoleNames(const edm::ParameterSet& cfg) {
42  if (cfg.exists("name"))
43  name_ = cfg.getParameter<std::string>("name");
44  else
45  name_ = "";
46  if (cfg.exists("roles"))
47  roles_ = cfg.getParameter<std::vector<std::string> >("roles");
48  else
49  roles_ = std::vector<std::string>();
50  }
51  const std::vector<std::string> roles() const { return roles_; }
53  c.setName(name_);
54  c.setRoles(roles_);
55  c.applyRoles();
56  }
57 
58  private:
61  // Name of the roles
62  std::vector<std::string> roles_;
63  };
64 
68  using namespace cand::parser;
69  using namespace std;
70  string decay(cfg.getParameter<string>("decay"));
72  for (vector<ConjInfo>::iterator label = labels_.begin(); label != labels_.end(); ++label)
73  if (label->mode_ == ConjInfo::kPlus)
74  dauCharge_.push_back(1);
75  else if (label->mode_ == ConjInfo::kMinus)
76  dauCharge_.push_back(-1);
77  else
78  dauCharge_.push_back(0);
79  else
80  throw edm::Exception(edm::errors::Configuration, "failed to parse \"" + decay + "\"");
81 
82  int lists = labels_.size();
83  if (lists != 2 && lists != 3)
84  throw edm::Exception(edm::errors::LogicError, "invalid number of collections");
85  bool found;
86  const string setLongLived("setLongLived");
87  vector<string> vBoolParams = cfg.getParameterNamesForType<bool>();
88  found = find(vBoolParams.begin(), vBoolParams.end(), setLongLived) != vBoolParams.end();
89  if (found)
90  setLongLived_ = cfg.getParameter<bool>("setLongLived");
91  const string setMassConstraint("setMassConstraint");
92  found = find(vBoolParams.begin(), vBoolParams.end(), setMassConstraint) != vBoolParams.end();
93  if (found)
94  setMassConstraint_ = cfg.getParameter<bool>("setMassConstraint");
95  const string setPdgId("setPdgId");
96  vector<string> vIntParams = cfg.getParameterNamesForType<int>();
97  found = find(vIntParams.begin(), vIntParams.end(), setPdgId) != vIntParams.end();
98  if (found) {
99  setPdgId_ = true;
100  pdgId_ = cfg.getParameter<int>("setPdgId");
101  }
102  tokens_ =
103  edm::vector_transform(labels_, [this](ConjInfo const& cI) { return consumes<CandidateView>(cI.tag_); });
104  }
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,
126  typename Setup = AddFourMomenta,
129  public:
133  combiner_(reco::modules::make<Selector>(cfg, consumesCollector()),
135  Setup(cfg),
136  cfg.existsAs<bool>("checkCharge") ? cfg.getParameter<bool>("checkCharge") : true,
137  cfg.existsAs<bool>("checkOverlap") ? cfg.getParameter<bool>("checkOverlap") : true,
138  dauCharge_),
139  names_(cfg) {
140  produces<OutputCollection>();
141  }
143  ~CandCombiner() override {}
144 
145  private:
147  void produce(edm::Event& evt, const edm::EventSetup& es) override {
148  Init::init(combiner_.setup(), evt, es);
149  int n = labels_.size();
150  std::vector<edm::Handle<CandidateView> > colls(n);
151  for (int i = 0; i < n; ++i)
152  evt.getByToken(tokens_[i], colls[i]);
153 
154  std::unique_ptr<OutputCollection> out = combiner_.combine(colls, names_.roles());
156  typename OutputCollection::iterator i = out->begin(), e = out->end();
157  for (; i != e; ++i) {
158  names_.set(*i);
159  if (setLongLived_)
160  i->setLongLived();
161  if (setMassConstraint_)
162  i->setMassConstraint();
163  if (setPdgId_)
164  i->setPdgId(pdgId_);
165  }
166  }
167  evt.put(std::move(out));
168  }
171 
173  };
174 
175  } // namespace modules
176 } // namespace reco
177 
178 #endif
Handle.h
Selector
Functor that operates on <T>
Definition: Selector.h:22
init
int init
Definition: HydjetWrapper.h:64
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
reco::ParticleMasses::kPlus
const double kPlus
Definition: ParticleMasses.h:8
cand::parser
Definition: decayParser.h:35
funct::false
false
Definition: Factorize.h:34
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
reco::modules::CandCombinerBase::setMassConstraint_
bool setMassConstraint_
set mass constraint flag
Definition: CandCombiner.h:115
reco::modules::CandCombiner::produce
void produce(edm::Event &evt, const edm::EventSetup &es) override
process an event
Definition: CandCombiner.h:147
edm::errors::LogicError
Definition: EDMException.h:37
reco::modules::CandCombinerBase::setPdgId_
bool setPdgId_
set pdgId flag
Definition: CandCombiner.h:117
modules
Definition: ZHLTMatchFilter.cc:17
edm
HLT enums.
Definition: AlignableModifier.h:19
bmtfDigis_cfi.Setup
Setup
Definition: bmtfDigis_cfi.py:5
EDProducer.h
cand::parser::ConjInfo
Definition: decayParser.h:36
reco::modules::CandCombinerBase
Definition: CandCombiner.h:65
decayParser.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
reco::modules::CandCombinerBase::labels_
std::vector< cand::parser::ConjInfo > labels_
label vector
Definition: CandCombiner.h:108
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
EventSetupInitTrait.h
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
EDMException.h
reco::CompositeCandidateCollection
std::vector< CompositeCandidate > CompositeCandidateCollection
collection of Candidate objects
Definition: CompositeCandidateFwd.h:19
reco::modules::RoleNames::name_
std::string name_
Name of this candidate.
Definition: CandCombiner.h:60
reco::modules::RoleNames::set
void set(reco::CompositeCandidate &c) const
Definition: CandCombiner.h:52
reco::modules::CandCombinerBase::CandCombinerBase
CandCombinerBase(const edm::ParameterSet &cfg)
Definition: CandCombiner.h:66
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
reco::modules::CandCombinerBase::pdgId_
int pdgId_
which pdgId to set
Definition: CandCombiner.h:119
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::vector_transform
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
funct::true
true
Definition: Factorize.h:173
combiner::helpers::NormalClone
Definition: CandCombiner.h:19
edm::ParameterSet
Definition: ParameterSet.h:36
cand::parser::decayParser
bool decayParser(const std::string &iValue, std::vector< ConjInfo > &oStrings)
Event.h
ParameterSet
Definition: Functions.h:16
reco::modules::CandCombinerBase::dauCharge_
std::vector< int > dauCharge_
daughter charges
Definition: CandCombiner.h:111
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:132
edm::stream::EDProducer
Definition: EDProducer.h:38
reco::modules::RoleNames::RoleNames
RoleNames(const edm::ParameterSet &cfg)
Definition: CandCombiner.h:41
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
reco::modules::make
S make(const edm::ParameterSet &cfg)
Definition: ParameterAdapter.h:21
cand::parser::ConjInfo::tag_
edm::InputTag tag_
Definition: decayParser.h:38
looper.cfg
cfg
Definition: looper.py:297
cutParser.h
PA_ZEESkim_cff.decay
decay
Definition: PA_ZEESkim_cff.py:26
type
type
Definition: HCALResponse.h:21
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
ALCARECOPromptCalibProdSiPixelAli0T_cff.Selector
Selector
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:81
StringCutObjectSelector.h
CandCombiner.h
Frameworkfwd.h
transform.h
reco::modules::CandCombiner::combiner_
::CandCombiner< Selector, PairSelector, Cloner, OutputCollection, Setup > combiner_
combiner utility
Definition: CandCombiner.h:170
Exception
Definition: hltDiff.cc:246
PairSelector
Definition: PairSelector.h:11
reco::modules::CandCombinerBase::setLongLived_
bool setLongLived_
set long lived flag
Definition: CandCombiner.h:113
reco::modules::CandCombiner
Definition: CandCombiner.h:128
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ParameterAdapter.h
reco::modules::CandCombiner::CandCombiner
CandCombiner(const edm::ParameterSet &cfg)
constructor from parameter settypedef
Definition: CandCombiner.h:131
AddFourMomenta
Definition: AddFourMomenta.h:18
Candidate.h
ParameterSet.h
reco::modules::RoleNames::roles
const std::vector< std::string > roles() const
Definition: CandCombiner.h:51
reco::modules::RoleNames::roles_
std::vector< std::string > roles_
Definition: CandCombiner.h:62
edm::Event
Definition: Event.h:73
HLTTauReferences_cfi.OutputCollection
OutputCollection
Definition: HLTTauReferences_cfi.py:92
reco::modules::RoleNames
Definition: CandCombiner.h:40
edm::errors::Configuration
Definition: EDMException.h:36
label
const char * label
Definition: PFTauDecayModeTools.cc:11
reco::modules::CandCombiner::names_
RoleNames names_
Definition: CandCombiner.h:172
reco::CompositeCandidate
Definition: CompositeCandidate.h:21
AnyPairSelector
Definition: AnyPairSelector.h:10
reco::modules::CandCombiner::~CandCombiner
~CandCombiner() override
destructor
Definition: CandCombiner.h:143
reco::modules::CandCombinerBase::tokens_
std::vector< edm::EDGetTokenT< CandidateView > > tokens_
Definition: CandCombiner.h:109
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37