CMS 3D CMS Logo

MuScleFitMuonProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MuScleFitMuonProducer
4 // Class: MuScleFitMuonProducer
5 //
10 //
11 // Original Author: Marco De Mattia,40 3-B32,+41227671551,
12 // Created: Tue Jun 22 13:50:22 CEST 2010
13 //
14 //
15 
16 // system include files
17 #include <memory>
18 #include <string>
19 
20 // user include files
39 
41 public:
43  ~MuScleFitMuonProducer() override;
44 
45 private:
46  void produce(edm::Event&, const edm::EventSetup&) override;
47  template <class T>
48  std::unique_ptr<T> applyCorrection(const edm::Handle<T>& allMuons);
53  const bool patMuons_;
54 
56  unsigned long long dbObjectCacheId_;
57  std::shared_ptr<MomentumScaleCorrector> corrector_;
58 };
59 
61  : muToken_(esConsumes(edm::ESInputTag("", iConfig.getUntrackedParameter<std::string>("DbObjectLabel", "")))),
62  theMuonLabel_(iConfig.getParameter<edm::InputTag>("MuonLabel")),
63  thePatMuonToken_(mayConsume<pat::MuonCollection>(theMuonLabel_)),
64  theRecoMuonToken_(mayConsume<reco::MuonCollection>(theMuonLabel_)),
65  patMuons_(iConfig.getParameter<bool>("PatMuons")),
66  dbObjectCacheId_(0) {
67  if (patMuons_ == true) {
68  produces<pat::MuonCollection>();
69  } else {
70  produces<reco::MuonCollection>();
71  }
72 }
73 
75 
76 template <class T>
78  std::unique_ptr<T> pOut(new T);
79 
80  // Apply the correction and produce the new muons
81  for (typename T::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon) {
82  //std::cout << "Pt before correction = " << muon->pt() << std::endl;
83  double pt = (*corrector_)(*muon);
84  //std::cout << "Pt after correction = " << pt << std::endl;
85  double eta = muon->eta();
86  double phi = muon->phi();
87 
88  typename T::value_type* newMuon = muon->clone();
89  newMuon->setP4(reco::Particle::PolarLorentzVector(pt, eta, phi, muon->mass()));
90 
91  pOut->push_back(*newMuon);
92  }
93  return pOut;
94 }
95 
96 // ------------ method called to produce the data ------------
98  unsigned long long dbObjectCacheId = iSetup.get<MuScleFitDBobjectRcd>().cacheIdentifier();
99  if (dbObjectCacheId != dbObjectCacheId_) {
100  dbObject_ = iSetup.getHandle(muToken_);
101  }
102 
103  //std::cout << "identifiers size from dbObject = " << dbObject_->identifiers.size() << std::endl;
104  //std::cout << "parameters size from dbObject = " << dbObject_->parameters.size() << std::endl;;
105 
106  // Create the corrector and set the parameters
108 
109  if (patMuons_ == true) {
111  iEvent.getByToken(thePatMuonToken_, allMuons);
113  } else {
115  iEvent.getByToken(theRecoMuonToken_, allMuons);
117  }
118 
119  // put into the Event
120  // iEvent.put(std::move(pOut));
121  // iEvent.put(applyCorrection(allMuons);
122 
123  /* std::unique_ptr<reco::MuonCollection> pOut(new reco::MuonCollection);
124 
125  // Apply the correction and produce the new muons
126  for( std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
127 
128  double pt = (*corrector_)(*muon);
129  double eta = muon->eta();
130  double phi = muon->phi();
131 
132  reco::Muon * newMuon = muon->clone();
133  newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
134 
135  pOut->push_back(*newMuon);
136  }
137 */
138 }
139 
140 //define this as a plug-in
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
const edm::EDGetTokenT< reco::MuonCollection > theRecoMuonToken_
std::unique_ptr< T > applyCorrection(const edm::Handle< T > &allMuons)
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
Definition: HeavyIon.h:7
~MuScleFitMuonProducer() override
int iEvent
Definition: GenABIO.cc:224
T const * product() const
Definition: ESHandle.h:86
edm::ESHandle< MuScleFitDBobject > dbObject_
T get() const
Definition: EventSetup.h:79
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< pat::MuonCollection > thePatMuonToken_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const edm::InputTag theMuonLabel_
unsigned long long dbObjectCacheId_
std::shared_ptr< MomentumScaleCorrector > corrector_
fixed size matrix
HLT enums.
const edm::ESGetToken< MuScleFitDBobject, MuScleFitDBobjectRcd > muToken_
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
MuScleFitMuonProducer(const edm::ParameterSet &)
long double T