CMS 3D CMS Logo

CandCombiner.h
Go to the documentation of this file.
1 #ifndef CandAlgos_CandCombiner_h
2 #define CandAlgos_CandCombiner_h
3 
30 #include <string>
31 #include <vector>
32 #include <algorithm>
33 
34 namespace edm {
35  class ParameterSet;
36 }
37 
38 namespace reco {
39  namespace modules {
40 
41  struct RoleNames {
42  explicit RoleNames(const edm::ParameterSet& cfg) {
43  if (cfg.exists("name"))
44  name_ = cfg.getParameter<std::string>("name");
45  else
46  name_ = "";
47  if (cfg.exists("roles"))
48  roles_ = cfg.getParameter<std::vector<std::string> >("roles");
49  else
50  roles_ = std::vector<std::string>();
51  }
52  const std::vector<std::string> roles() const { return roles_; }
54  c.setName(name_);
55  c.setRoles(roles_);
56  c.applyRoles();
57  }
58 
59  private:
62  // Name of the roles
63  std::vector<std::string> roles_;
64  };
65 
69  using namespace cand::parser;
70  using namespace std;
71  string decay(cfg.getParameter<string>("decay"));
73  for (vector<ConjInfo>::iterator label = labels_.begin(); label != labels_.end(); ++label)
74  if (label->mode_ == ConjInfo::kPlus)
75  dauCharge_.push_back(1);
76  else if (label->mode_ == ConjInfo::kMinus)
77  dauCharge_.push_back(-1);
78  else
79  dauCharge_.push_back(0);
80  else
81  throw edm::Exception(edm::errors::Configuration, "failed to parse \"" + decay + "\"");
82 
83  int lists = labels_.size();
84  if (lists != 2 && lists != 3)
85  throw edm::Exception(edm::errors::LogicError, "invalid number of collections");
86  bool found;
87  const string setLongLived("setLongLived");
88  vector<string> vBoolParams = cfg.getParameterNamesForType<bool>();
89  found = find(vBoolParams.begin(), vBoolParams.end(), setLongLived) != vBoolParams.end();
90  if (found)
91  setLongLived_ = cfg.getParameter<bool>("setLongLived");
92  const string setMassConstraint("setMassConstraint");
93  found = find(vBoolParams.begin(), vBoolParams.end(), setMassConstraint) != vBoolParams.end();
94  if (found)
95  setMassConstraint_ = cfg.getParameter<bool>("setMassConstraint");
96  const string setPdgId("setPdgId");
97  vector<string> vIntParams = cfg.getParameterNamesForType<int>();
98  found = find(vIntParams.begin(), vIntParams.end(), setPdgId) != vIntParams.end();
99  if (found) {
100  setPdgId_ = true;
101  pdgId_ = cfg.getParameter<int>("setPdgId");
102  }
103  tokens_ =
104  edm::vector_transform(labels_, [this](ConjInfo const& cI) { return consumes<CandidateView>(cI.tag_); });
105  }
106 
107  protected:
109  std::vector<cand::parser::ConjInfo> labels_;
110  std::vector<edm::EDGetTokenT<CandidateView> > tokens_;
112  std::vector<int> dauCharge_;
118  bool setPdgId_;
120  int pdgId_;
121  };
122 
123  template <typename Selector,
124  typename PairSelector = AnyPairSelector,
125  typename Cloner = ::combiner::helpers::NormalClone,
127  typename Setup = AddFourMomenta,
130  public:
134  combiner_(reco::modules::make<Selector>(cfg, consumesCollector()),
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());
157  typename OutputCollection::iterator i = out->begin(), e = out->end();
158  for (; i != e; ++i) {
159  names_.set(*i);
160  if (setLongLived_)
161  i->setLongLived();
162  if (setMassConstraint_)
163  i->setMassConstraint();
164  if (setPdgId_)
165  i->setPdgId(pdgId_);
166  }
167  }
168  evt.put(std::move(out));
169  }
172 
174  };
175 
176  } // namespace modules
177 } // namespace reco
178 
179 #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:366
mps_fire.i
i
Definition: mps_fire.py:428
reco::ParticleMasses::kPlus
const double kPlus
Definition: ParticleMasses.h:8
cand::parser
Definition: decayParser.h:33
funct::false
false
Definition: Factorize.h:29
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
reco::modules::CandCombinerBase::setMassConstraint_
bool setMassConstraint_
set mass constraint flag
Definition: CandCombiner.h:116
reco::modules::CandCombiner::produce
void produce(edm::Event &evt, const edm::EventSetup &es) override
process an event
Definition: CandCombiner.h:148
edm::errors::LogicError
Definition: EDMException.h:37
reco::modules::CandCombinerBase::setPdgId_
bool setPdgId_
set pdgId flag
Definition: CandCombiner.h:118
modules
Definition: MuonCleanerBySegments.cc:35
edm
HLT enums.
Definition: AlignableModifier.h:19
bmtfDigis_cfi.Setup
Setup
Definition: bmtfDigis_cfi.py:5
EDProducer.h
cand::parser::ConjInfo
Definition: decayParser.h:34
reco::modules::CandCombinerBase
Definition: CandCombiner.h:66
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:109
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:61
reco::modules::RoleNames::set
void set(reco::CompositeCandidate &c) const
Definition: CandCombiner.h:53
reco::modules::CandCombinerBase::CandCombinerBase
CandCombinerBase(const edm::ParameterSet &cfg)
Definition: CandCombiner.h:67
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:535
reco::modules::CandCombinerBase::pdgId_
int pdgId_
which pdgId to set
Definition: CandCombiner.h:120
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:47
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:112
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
AddFourMomenta.h
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::stream::EDProducer
Definition: EDProducer.h:38
reco::modules::RoleNames::RoleNames
RoleNames(const edm::ParameterSet &cfg)
Definition: CandCombiner.h:42
edm::EventSetup
Definition: EventSetup.h:58
reco::modules::make
S make(const edm::ParameterSet &cfg)
Definition: ParameterAdapter.h:21
cand::parser::ConjInfo::tag_
edm::InputTag tag_
Definition: decayParser.h:36
looper.cfg
cfg
Definition: looper.py:297
cutParser.h
PA_ZEESkim_cff.decay
decay
Definition: PA_ZEESkim_cff.py:26
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:171
Exception
Definition: hltDiff.cc:245
PairSelector
Definition: PairSelector.h:11
reco::modules::CandCombinerBase::setLongLived_
bool setLongLived_
set long lived flag
Definition: CandCombiner.h:114
reco::modules::CandCombiner
Definition: CandCombiner.h:129
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:132
AddFourMomenta
Definition: AddFourMomenta.h:18
Candidate.h
ParameterSet.h
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
reco::modules::RoleNames::roles
const std::vector< std::string > roles() const
Definition: CandCombiner.h:52
reco::modules::RoleNames::roles_
std::vector< std::string > roles_
Definition: CandCombiner.h:63
edm::Event
Definition: Event.h:73
HLTTauReferences_cfi.OutputCollection
OutputCollection
Definition: HLTTauReferences_cfi.py:92
reco::modules::RoleNames
Definition: CandCombiner.h:41
edm::errors::Configuration
Definition: EDMException.h:36
label
const char * label
Definition: PFTauDecayModeTools.cc:11
reco::modules::CandCombiner::names_
RoleNames names_
Definition: CandCombiner.h:173
reco::CompositeCandidate
Definition: CompositeCandidate.h:21
AnyPairSelector
Definition: AnyPairSelector.h:10
reco::modules::CandCombiner::~CandCombiner
~CandCombiner() override
destructor
Definition: CandCombiner.h:144
reco::modules::CandCombinerBase::tokens_
std::vector< edm::EDGetTokenT< CandidateView > > tokens_
Definition: CandCombiner.h:110
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37