Go to the documentation of this file.00001 #ifndef RecoAlgos_ConstrainedFitCandProducer_h
00002 #define RecoAlgos_ConstrainedFitCandProducer_h
00003
00004
00005
00006
00007
00008 #include "FWCore/Framework/interface/EDProducer.h"
00009 #include "FWCore/Utilities/interface/InputTag.h"
00010 #include "CommonTools/UtilAlgos/interface/ParameterAdapter.h"
00011 #include "CommonTools/UtilAlgos/interface/EventSetupInitTrait.h"
00012 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00013 #include "SimGeneral/HepPDTRecord/interface/PdtEntry.h"
00014 #include <vector>
00015
00016 template<typename Fitter,
00017 typename InputCollection = reco::CandidateCollection,
00018 typename OutputCollection = InputCollection,
00019 typename Init = typename ::reco::modules::EventSetupInit<Fitter>::type>
00020 class ConstrainedFitCandProducer : public edm::EDProducer {
00021 public:
00022 explicit ConstrainedFitCandProducer(const edm::ParameterSet &);
00023
00024 private:
00025 edm::InputTag src_;
00026 bool setLongLived_;
00027 bool setMassConstraint_;
00028 bool setPdgId_;
00029 int pdgId_;
00030 Fitter fitter_;
00031 void produce(edm::Event &, const edm::EventSetup &);
00032 };
00033
00034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00035 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00036 #include "DataFormats/Common/interface/Handle.h"
00037 #include "FWCore/Framework/interface/ESHandle.h"
00038 #include "FWCore/Framework/interface/Event.h"
00039 #include "DataFormats/Candidate/interface/VertexCompositeCandidate.h"
00040 #include "FWCore/Framework/interface/EventSetup.h"
00041 #include <algorithm>
00042
00043 template<typename Fitter, typename InputCollection, typename OutputCollection, typename Init>
00044 ConstrainedFitCandProducer<Fitter, InputCollection, OutputCollection, Init>::ConstrainedFitCandProducer(const edm::ParameterSet & cfg) :
00045 src_(cfg.template getParameter<edm::InputTag>("src")),
00046 setLongLived_(false), setMassConstraint_(false), setPdgId_(false),
00047 fitter_(reco::modules::make<Fitter>(cfg)) {
00048 produces<OutputCollection>();
00049 std::string alias( cfg.getParameter<std::string>("@module_label"));
00050 const std::string setLongLived("setLongLived");
00051 std::vector<std::string> vBoolParams = cfg.template getParameterNamesForType<bool>();
00052 bool found = find(vBoolParams.begin(), vBoolParams.end(), setLongLived) != vBoolParams.end();
00053 if(found) setLongLived_ = cfg.template getParameter<bool>("setLongLived");
00054 const std::string setMassConstraint("setMassConstraint");
00055 found = find(vBoolParams.begin(), vBoolParams.end(), setMassConstraint) != vBoolParams.end();
00056 if(found) setMassConstraint_ = cfg.template getParameter<bool>("setMassConstraint");
00057 const std::string setPdgId("setPdgId");
00058 std::vector<std::string> vIntParams = cfg.getParameterNamesForType<int>();
00059 found = find(vIntParams.begin(), vIntParams.end(), setPdgId) != vIntParams.end();
00060 if(found) { setPdgId_ = true; pdgId_ = cfg.getParameter<int>("setPdgId"); }
00061 }
00062
00063 namespace reco {
00064 namespace fitHelper {
00065 template<typename C>
00066 struct Adder {
00067 static void add(std::auto_ptr<C> & c, std::auto_ptr<reco::VertexCompositeCandidate> t) { c->push_back(*t); }
00068 };
00069
00070 template<typename T>
00071 struct Adder<edm::OwnVector<T> > {
00072 static void add(std::auto_ptr<edm::OwnVector<T> > & c, std::auto_ptr<reco::VertexCompositeCandidate> t) { c->push_back(t); }
00073 };
00074
00075 template<typename C>
00076 inline void add(std::auto_ptr<C> & c, std::auto_ptr<reco::VertexCompositeCandidate> t) {
00077 Adder<C>::add(c, t);
00078 }
00079 }
00080 }
00081
00082 template<typename Fitter, typename InputCollection, typename OutputCollection, typename Init>
00083 void ConstrainedFitCandProducer<Fitter, InputCollection, OutputCollection, Init>::produce(edm::Event & evt, const edm::EventSetup & es) {
00084 Init::init(fitter_, evt, es);
00085 edm::Handle<InputCollection> cands;
00086 evt.getByLabel(src_, cands);
00087 std::auto_ptr<OutputCollection> fitted(new OutputCollection);
00088 fitted->reserve(cands->size());
00089 for(typename InputCollection::const_iterator c = cands->begin(); c != cands->end(); ++ c) {
00090 std::auto_ptr<reco::VertexCompositeCandidate> clone(new reco::VertexCompositeCandidate(*c));
00091 fitter_.set(*clone);
00092 if(setLongLived_) clone->setLongLived();
00093 if(setMassConstraint_) clone->setMassConstraint();
00094 if(setPdgId_) clone->setPdgId(pdgId_);
00095 reco::fitHelper::add(fitted, clone);
00096 }
00097 evt.put(fitted);
00098 }
00099
00100 #endif