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_;
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) {
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
ConstrainedFitCandProducer::fitter_
Fitter fitter_
Definition: ConstrainedFitCandProducer.h:30
Handle.h
init
int init
Definition: HydjetWrapper.h:64
ConstrainedFitCandProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ConstrainedFitCandProducer.h:93
reco::fitHelper::Adder< edm::OwnVector< T > >::add
static void add(edm::OwnVector< T > *c, std::unique_ptr< reco::VertexCompositeCandidate > t)
Definition: ConstrainedFitCandProducer.h:80
reco::fitHelper::Adder
Definition: ConstrainedFitCandProducer.h:74
funct::false
false
Definition: Factorize.h:29
EDProducer.h
ESHandle.h
modules
Definition: ZHLTMatchFilter.cc:17
edm::EDGetTokenT< InputCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
HLTSiStripMonitoring_cff.Fitter
Fitter
Definition: HLTSiStripMonitoring_cff.py:207
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
ConstrainedFitCandProducer::srcToken_
edm::EDGetTokenT< InputCollection > srcToken_
Definition: ConstrainedFitCandProducer.h:25
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
EventSetupInitTrait.h
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
ConstrainedFitCandProducer::setPdgId_
bool setPdgId_
Definition: ConstrainedFitCandProducer.h:28
CandidateFwd.h
ConstrainedFitCandProducer::setMassConstraint_
bool setMassConstraint_
Definition: ConstrainedFitCandProducer.h:27
ConstrainedFitCandProducer::pdgId_
int pdgId_
Definition: ConstrainedFitCandProducer.h:29
VertexCompositeCandidate.h
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
ConstrainedFitCandProducer::ConstrainedFitCandProducer
ConstrainedFitCandProducer(const edm::ParameterSet &)
Definition: ConstrainedFitCandProducer.h:44
reco::fitHelper::Adder::add
static void add(C *c, std::unique_ptr< reco::VertexCompositeCandidate > t)
Definition: ConstrainedFitCandProducer.h:75
IdealMagneticFieldRecord.h
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
ConstrainedFitCandProducer
Definition: ConstrainedFitCandProducer.h:20
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_FULL_cff.cands
cands
Definition: HLT_FULL_cff.py:15142
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:39
PdtEntry.h
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EventSetup
Definition: EventSetup.h:57
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
reco::modules::make
S make(const edm::ParameterSet &cfg)
Definition: ParameterAdapter.h:21
InputTag.h
looper.cfg
cfg
Definition: looper.py:297
eostools.move
def move(src, dest)
Definition: eostools.py:511
gen::C
C
Definition: PomwigHadronizer.cc:78
reco::CandidateCollection
edm::OwnVector< Candidate > CandidateCollection
collection of Candidate objects
Definition: CandidateFwd.h:21
SiStripOfflineCRack_cfg.alias
alias
Definition: SiStripOfflineCRack_cfg.py:128
ConstrainedFitCandProducer::setLongLived_
bool setLongLived_
Definition: ConstrainedFitCandProducer.h:26
reco::fitHelper::add
void add(C *c, std::unique_ptr< reco::VertexCompositeCandidate > t)
Definition: ConstrainedFitCandProducer.h:86
EventSetup.h
edm::EDProducer
Definition: EDProducer.h:35
SimL1EmulatorRepack_GT2_cff.InputCollection
InputCollection
Definition: SimL1EmulatorRepack_GT2_cff.py:16
ParameterAdapter.h
ParameterSet.h
edm::Event
Definition: Event.h:73
HLTTauReferences_cfi.OutputCollection
OutputCollection
Definition: HLTTauReferences_cfi.py:92
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::OwnVector
Definition: OwnVector.h:24