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,
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  srcToken_(consumes<InputCollection>(cfg.template getParameter<edm::InputTag>("src"))),
47  fitter_(reco::modules::make<Fitter>(cfg)) {
48  produces<OutputCollection>();
49  std::string alias( cfg.getParameter<std::string>("@module_label"));
50  const std::string setLongLived("setLongLived");
51  std::vector<std::string> vBoolParams = cfg.template getParameterNamesForType<bool>();
52  bool found = find(vBoolParams.begin(), vBoolParams.end(), setLongLived) != vBoolParams.end();
53  if(found) setLongLived_ = cfg.template getParameter<bool>("setLongLived");
54  const std::string setMassConstraint("setMassConstraint");
55  found = find(vBoolParams.begin(), vBoolParams.end(), setMassConstraint) != vBoolParams.end();
56  if(found) setMassConstraint_ = cfg.template getParameter<bool>("setMassConstraint");
57  const std::string setPdgId("setPdgId");
58  std::vector<std::string> vIntParams = cfg.getParameterNamesForType<int>();
59  found = find(vIntParams.begin(), vIntParams.end(), setPdgId) != vIntParams.end();
60  if(found) { setPdgId_ = true; pdgId_ = cfg.getParameter<int>("setPdgId"); }
61 }
62 
63 namespace reco {
64  namespace fitHelper {
65  template<typename C>
66  struct Adder {
67  static void add(C* c, std::unique_ptr<reco::VertexCompositeCandidate> t) { c->push_back(*t); }
68  };
69 
70  template<typename T>
71  struct Adder<edm::OwnVector<T> > {
72  static void add(edm::OwnVector<T>* c, std::unique_ptr<reco::VertexCompositeCandidate> t) { c->push_back(std::move(t)); }
73  };
74 
75  template<typename C>
76  inline void add(C* c, std::unique_ptr<reco::VertexCompositeCandidate> t) {
77  Adder<C>::add(c, std::move(t));
78  }
79  }
80 }
81 
82 template<typename Fitter, typename InputCollection, typename OutputCollection, typename Init>
84  Init::init(fitter_, evt, es);
86  evt.getByToken(srcToken_, cands);
87  auto fitted = std::make_unique<OutputCollection>();
88  fitted->reserve(cands->size());
89  for(typename InputCollection::const_iterator c = cands->begin(); c != cands->end(); ++ c) {
90  auto clone = std::make_unique<reco::VertexCompositeCandidate>(*c);
91  fitter_.set(*clone);
92  if(setLongLived_) clone->setLongLived();
93  if(setMassConstraint_) clone->setMassConstraint();
94  if(setPdgId_) clone->setPdgId(pdgId_);
95  reco::fitHelper::add(fitted.get(), std::move(clone));
96  }
97  evt.put(std::move(fitted));
98 }
99 
100 #endif
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
edm::EDGetTokenT< InputCollection > srcToken_
int init
Definition: HydjetWrapper.h:67
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:20
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:193
void push_back(D *&d)
Definition: OwnVector.h:290
static void add(C *c, std::unique_ptr< reco::VertexCompositeCandidate > t)
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:520
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