CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 &);
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"))),
46  setLongLived_(false), setMassConstraint_(false), setPdgId_(false),
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(std::auto_ptr<C> & c, std::auto_ptr<reco::VertexCompositeCandidate> t) { c->push_back(*t); }
68  };
69 
70  template<typename T>
71  struct Adder<edm::OwnVector<T> > {
72  static void add(std::auto_ptr<edm::OwnVector<T> > & c, std::auto_ptr<reco::VertexCompositeCandidate> t) { c->push_back(t); }
73  };
74 
75  template<typename C>
76  inline void add(std::auto_ptr<C> & c, std::auto_ptr<reco::VertexCompositeCandidate> t) {
77  Adder<C>::add(c, 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  std::auto_ptr<OutputCollection> fitted(new OutputCollection);
88  fitted->reserve(cands->size());
89  for(typename InputCollection::const_iterator c = cands->begin(); c != cands->end(); ++ c) {
90  std::auto_ptr<reco::VertexCompositeCandidate> clone(new 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, clone);
96  }
97  evt.put(fitted);
98 }
99 
100 #endif
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
tuple cfg
Definition: looper.py:293
void produce(edm::Event &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
edm::EDGetTokenT< InputCollection > srcToken_
int init
Definition: HydjetWrapper.h:67
S make(const edm::ParameterSet &cfg)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:194
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
pdgId_(cfg.getParameter< std::vector< int > >("matchPDGId"))
ConstrainedFitCandProducer(const edm::ParameterSet &)
tuple InputCollection
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
static void add(std::auto_ptr< C > &c, std::auto_ptr< reco::VertexCompositeCandidate > t)
void add(std::auto_ptr< C > &c, std::auto_ptr< reco::VertexCompositeCandidate > t)
volatile std::atomic< bool > shutdown_flag false
edm::OwnVector< Candidate > CandidateCollection
collection of Candidate objects
Definition: CandidateFwd.h:21
def template
Definition: svgfig.py:520
static void add(std::auto_ptr< edm::OwnVector< T > > &c, std::auto_ptr< reco::VertexCompositeCandidate > t)