CMS 3D CMS Logo

ConstrainedFitCandProducer.h
Go to the documentation of this file.
1 #ifndef RecoAlgos_ConstrainedFitCandProducer_h
2 #define RecoAlgos_ConstrainedFitCandProducer_h
3 /* \class ConstrainedFitCandProducer
4  *
5  * \author Luca Lista, INFN
6  *
7  */
14 #include <vector>
15 
16 template <typename Fitter,
21 public:
23 
24 private:
28  bool setPdgId_;
29  int pdgId_;
32  void produce(edm::Event&, const edm::EventSetup&) override;
33 };
34 
42 #include <algorithm>
43 
44 template <typename Fitter, typename InputCollection, typename OutputCollection, typename Init>
46  const edm::ParameterSet& cfg)
47  : srcToken_(consumes<InputCollection>(cfg.template getParameter<edm::InputTag>("src"))),
48  setLongLived_(false),
49  setMassConstraint_(false),
50  setPdgId_(false),
51  fitterInit_(consumesCollector()),
52  fitter_(reco::modules::make<Fitter>(cfg)) {
53  produces<OutputCollection>();
54  std::string alias(cfg.getParameter<std::string>("@module_label"));
55  const std::string setLongLived("setLongLived");
56  std::vector<std::string> vBoolParams = cfg.template getParameterNamesForType<bool>();
57  bool found = find(vBoolParams.begin(), vBoolParams.end(), setLongLived) != vBoolParams.end();
58  if (found)
59  setLongLived_ = cfg.template getParameter<bool>("setLongLived");
60  const std::string setMassConstraint("setMassConstraint");
61  found = find(vBoolParams.begin(), vBoolParams.end(), setMassConstraint) != vBoolParams.end();
62  if (found)
63  setMassConstraint_ = cfg.template getParameter<bool>("setMassConstraint");
64  const std::string setPdgId("setPdgId");
65  std::vector<std::string> vIntParams = cfg.getParameterNamesForType<int>();
66  found = find(vIntParams.begin(), vIntParams.end(), setPdgId) != vIntParams.end();
67  if (found) {
68  setPdgId_ = true;
69  pdgId_ = cfg.getParameter<int>("setPdgId");
70  }
71 }
72 
73 namespace reco {
74  namespace fitHelper {
75  template <typename C>
76  struct Adder {
77  static void add(C* c, std::unique_ptr<reco::VertexCompositeCandidate> t) { c->push_back(*t); }
78  };
79 
80  template <typename T>
81  struct Adder<edm::OwnVector<T> > {
82  static void add(edm::OwnVector<T>* c, std::unique_ptr<reco::VertexCompositeCandidate> t) {
83  c->push_back(std::move(t));
84  }
85  };
86 
87  template <typename C>
88  inline void add(C* c, std::unique_ptr<reco::VertexCompositeCandidate> t) {
90  }
91  } // namespace fitHelper
92 } // namespace reco
93 
94 template <typename Fitter, typename InputCollection, typename OutputCollection, typename Init>
96  const edm::EventSetup& es) {
97  fitterInit_.init(fitter_, evt, es);
99  evt.getByToken(srcToken_, cands);
100  auto fitted = std::make_unique<OutputCollection>();
101  fitted->reserve(cands->size());
102  for (typename InputCollection::const_iterator c = cands->begin(); c != cands->end(); ++c) {
103  auto clone = std::make_unique<reco::VertexCompositeCandidate>(*c);
104  fitter_.set(*clone);
105  if (setLongLived_)
106  clone->setLongLived();
107  if (setMassConstraint_)
108  clone->setMassConstraint();
109  if (setPdgId_)
110  clone->setPdgId(pdgId_);
111  reco::fitHelper::add(fitted.get(), std::move(clone));
112  }
113  evt.put(std::move(fitted));
114 }
115 
116 #endif
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EDGetTokenT< InputCollection > srcToken_
S make(const edm::ParameterSet &cfg)
static void add(edm::OwnVector< T > *c, std::unique_ptr< reco::VertexCompositeCandidate > t)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:528
void add(C *c, std::unique_ptr< reco::VertexCompositeCandidate > t)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
static void add(C *c, std::unique_ptr< reco::VertexCompositeCandidate > t)
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
ConstrainedFitCandProducer(const edm::ParameterSet &)
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
fixed size matrix
HLT enums.
void produce(edm::Event &, const edm::EventSetup &) override
edm::OwnVector< Candidate > CandidateCollection
collection of Candidate objects
Definition: CandidateFwd.h:21
def move(src, dest)
Definition: eostools.py:511