CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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,
18  typename OutputCollection = InputCollection,
21 public:
23 
24 private:
28  bool setPdgId_;
29  int pdgId_;
31  void produce(edm::Event&, const edm::EventSetup&) override;
32 };
33 
41 #include <algorithm>
42 
43 template <typename Fitter, typename InputCollection, typename OutputCollection, typename Init>
45  const edm::ParameterSet& cfg)
46  : srcToken_(consumes<InputCollection>(cfg.template getParameter<edm::InputTag>("src"))),
47  setLongLived_(false),
48  setMassConstraint_(false),
49  setPdgId_(false),
50  fitter_(reco::modules::make<Fitter>(cfg)) {
51  produces<OutputCollection>();
52  std::string alias(cfg.getParameter<std::string>("@module_label"));
53  const std::string setLongLived("setLongLived");
54  std::vector<std::string> vBoolParams = cfg.template getParameterNamesForType<bool>();
55  bool found = find(vBoolParams.begin(), vBoolParams.end(), setLongLived) != vBoolParams.end();
56  if (found)
57  setLongLived_ = cfg.template getParameter<bool>("setLongLived");
58  const std::string setMassConstraint("setMassConstraint");
59  found = find(vBoolParams.begin(), vBoolParams.end(), setMassConstraint) != vBoolParams.end();
60  if (found)
61  setMassConstraint_ = cfg.template getParameter<bool>("setMassConstraint");
62  const std::string setPdgId("setPdgId");
63  std::vector<std::string> vIntParams = cfg.getParameterNamesForType<int>();
64  found = find(vIntParams.begin(), vIntParams.end(), setPdgId) != vIntParams.end();
65  if (found) {
66  setPdgId_ = true;
67  pdgId_ = cfg.getParameter<int>("setPdgId");
68  }
69 }
70 
71 namespace reco {
72  namespace fitHelper {
73  template <typename C>
74  struct Adder {
75  static void add(C* c, std::unique_ptr<reco::VertexCompositeCandidate> t) { c->push_back(*t); }
76  };
77 
78  template <typename T>
79  struct Adder<edm::OwnVector<T> > {
80  static void add(edm::OwnVector<T>* c, std::unique_ptr<reco::VertexCompositeCandidate> t) {
81  c->push_back(std::move(t));
82  }
83  };
84 
85  template <typename C>
86  inline void add(C* c, std::unique_ptr<reco::VertexCompositeCandidate> t) {
87  Adder<C>::add(c, std::move(t));
88  }
89  } // namespace fitHelper
90 } // namespace reco
91 
92 template <typename Fitter, typename InputCollection, typename OutputCollection, typename Init>
94  const edm::EventSetup& es) {
95  Init::init(fitter_, evt, es);
97  evt.getByToken(srcToken_, cands);
98  auto fitted = std::make_unique<OutputCollection>();
99  fitted->reserve(cands->size());
100  for (typename InputCollection::const_iterator c = cands->begin(); c != cands->end(); ++c) {
101  auto clone = std::make_unique<reco::VertexCompositeCandidate>(*c);
102  fitter_.set(*clone);
103  if (setLongLived_)
104  clone->setLongLived();
105  if (setMassConstraint_)
106  clone->setMassConstraint();
107  if (setPdgId_)
108  clone->setPdgId(pdgId_);
109  reco::fitHelper::add(fitted.get(), std::move(clone));
110  }
111  evt.put(std::move(fitted));
112 }
113 
114 #endif
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
const edm::EventSetup & c
tuple cfg
Definition: looper.py:296
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
edm::EDGetTokenT< InputCollection > srcToken_
int init
Definition: HydjetWrapper.h:64
S make(const edm::ParameterSet &cfg)
static void add(edm::OwnVector< T > *c, std::unique_ptr< reco::VertexCompositeCandidate > t)
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
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:179
void push_back(D *&d)
Definition: OwnVector.h:326
def move
Definition: eostools.py:511
pdgId_(cfg.getParameter< std::vector< int > >("matchPDGId"))
static void add(C *c, std::unique_ptr< reco::VertexCompositeCandidate > t)
ConstrainedFitCandProducer(const edm::ParameterSet &)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
void produce(edm::Event &, const edm::EventSetup &) override
edm::OwnVector< Candidate > CandidateCollection
collection of Candidate objects
Definition: CandidateFwd.h:21
def template
Definition: svgfig.py:521