CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
23 
26 
29 
33 
37 
39 
42 
46 
48 public:
50  ~MuScleFitMuonProducer() override;
51 
52 private:
53  void beginJob() override;
54  void produce(edm::Event&, const edm::EventSetup&) override;
55  void endJob() override;
56  template <class T>
57  std::unique_ptr<T> applyCorrection(const edm::Handle<T>& allMuons);
58 
62  bool patMuons_;
65  unsigned long long dbObjectCacheId_;
66  std::shared_ptr<MomentumScaleCorrector> corrector_;
67 };
68 
70  : theMuonLabel_(iConfig.getParameter<edm::InputTag>("MuonLabel")),
71  thePatMuonToken_(mayConsume<pat::MuonCollection>(theMuonLabel_)),
72  theRecoMuonToken_(mayConsume<reco::MuonCollection>(theMuonLabel_)),
73  patMuons_(iConfig.getParameter<bool>("PatMuons")),
74  dbObjectLabel_(iConfig.getUntrackedParameter<std::string>("DbObjectLabel", "")),
75  dbObjectCacheId_(0) {
76  if (patMuons_ == true) {
77  produces<pat::MuonCollection>();
78  } else {
79  produces<reco::MuonCollection>();
80  }
81 }
82 
84 
85 template <class T>
87  std::unique_ptr<T> pOut(new T);
88 
89  // Apply the correction and produce the new muons
90  for (typename T::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon) {
91  //std::cout << "Pt before correction = " << muon->pt() << std::endl;
92  double pt = (*corrector_)(*muon);
93  //std::cout << "Pt after correction = " << pt << std::endl;
94  double eta = muon->eta();
95  double phi = muon->phi();
96 
97  typename T::value_type* newMuon = muon->clone();
98  newMuon->setP4(reco::Particle::PolarLorentzVector(pt, eta, phi, muon->mass()));
99 
100  pOut->push_back(*newMuon);
101  }
102  return pOut;
103 }
104 
105 // ------------ method called to produce the data ------------
107  unsigned long long dbObjectCacheId = iSetup.get<MuScleFitDBobjectRcd>().cacheIdentifier();
108  if (dbObjectCacheId != dbObjectCacheId_) {
109  if (!dbObjectLabel_.empty()) {
111  } else {
112  iSetup.get<MuScleFitDBobjectRcd>().get(dbObject_);
113  }
114  }
115 
116  //std::cout << "identifiers size from dbObject = " << dbObject_->identifiers.size() << std::endl;
117  //std::cout << "parameters size from dbObject = " << dbObject_->parameters.size() << std::endl;;
118 
119  // Create the corrector and set the parameters
121 
122  if (patMuons_ == true) {
124  iEvent.getByToken(thePatMuonToken_, allMuons);
125  iEvent.put(applyCorrection(allMuons));
126  } else {
128  iEvent.getByToken(theRecoMuonToken_, allMuons);
129  iEvent.put(applyCorrection(allMuons));
130  }
131 
132  // put into the Event
133  // iEvent.put(std::move(pOut));
134  // iEvent.put(applyCorrection(allMuons);
135 
136  /* std::unique_ptr<reco::MuonCollection> pOut(new reco::MuonCollection);
137 
138  // Apply the correction and produce the new muons
139  for( std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
140 
141  double pt = (*corrector_)(*muon);
142  double eta = muon->eta();
143  double phi = muon->phi();
144 
145  reco::Muon * newMuon = muon->clone();
146  newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
147 
148  pOut->push_back(*newMuon);
149  }
150 */
151 }
152 
153 // ------------ method called once each job just before starting event loop ------------
155 
156 // ------------ method called once each job just after ending the event loop ------------
158 
159 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
std::unique_ptr< T > applyCorrection(const edm::Handle< T > &allMuons)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
int iEvent
Definition: GenABIO.cc:224
edm::ESHandle< MuScleFitDBobject > dbObject_
tuple allMuons
Definition: allMuons_cfi.py:3
unsigned long long dbObjectCacheId_
edm::EDGetTokenT< reco::MuonCollection > theRecoMuonToken_
T const * product() const
Definition: ESHandle.h:86
std::shared_ptr< MomentumScaleCorrector > corrector_
T get() const
Definition: EventSetup.h:88
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
MuScleFitMuonProducer(const edm::ParameterSet &)
edm::EDGetTokenT< pat::MuonCollection > thePatMuonToken_
long double T