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
23 
26 
29 
33 
37 
39 
42 
46 
48  public:
51 
52  private:
53  virtual void beginJob() override ;
54  virtual void produce(edm::Event&, const edm::EventSetup&) override;
55  virtual void endJob() override ;
56  template<class T> std::unique_ptr<T> applyCorrection(const edm::Handle<T> & allMuons);
57 
61  bool patMuons_;
64  unsigned long long dbObjectCacheId_;
65  boost::shared_ptr<MomentumScaleCorrector> corrector_;
66 };
67 
69  theMuonLabel_( iConfig.getParameter<edm::InputTag>( "MuonLabel" ) ),
72  patMuons_( iConfig.getParameter<bool>( "PatMuons" ) ),
73  dbObjectLabel_( iConfig.getUntrackedParameter<std::string>("DbObjectLabel", "") ),
75 {
76  if ( patMuons_ == true ) {
77  produces<pat::MuonCollection>();
78  } else {
79  produces<reco::MuonCollection>();
80  }
81 }
82 
83 
85 {
86 }
87 
88 
89 template<class T>
91 {
92  std::unique_ptr<T> pOut(new T);
93 
94  // Apply the correction and produce the new muons
95  for( typename T::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
96 
97  //std::cout << "Pt before correction = " << muon->pt() << std::endl;
98  double pt = (*corrector_)(*muon);
99  //std::cout << "Pt after correction = " << pt << std::endl;
100  double eta = muon->eta();
101  double phi = muon->phi();
102 
103  typename T::value_type * newMuon = muon->clone();
104  newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
105 
106  pOut->push_back(*newMuon);
107  }
108  return pOut;
109 }
110 
111 // ------------ method called to produce the data ------------
113 {
114  unsigned long long dbObjectCacheId = iSetup.get<MuScleFitDBobjectRcd>().cacheIdentifier();
115  if ( dbObjectCacheId != dbObjectCacheId_ ) {
116  if ( dbObjectLabel_ != "" ) {
118  } else {
119  iSetup.get<MuScleFitDBobjectRcd>().get(dbObject_);
120  }
121  }
122 
123  //std::cout << "identifiers size from dbObject = " << dbObject_->identifiers.size() << std::endl;
124  //std::cout << "parameters size from dbObject = " << dbObject_->parameters.size() << std::endl;;
125 
126  // Create the corrector and set the parameters
128 
129  if( patMuons_ == true ) {
131  iEvent.getByToken(thePatMuonToken_, allMuons);
132  iEvent.put(applyCorrection(allMuons));
133  }
134  else {
136  iEvent.getByToken(theRecoMuonToken_, allMuons);
137  iEvent.put(applyCorrection(allMuons));
138  }
139 
140  // put into the Event
141  // iEvent.put(std::move(pOut));
142  // iEvent.put(applyCorrection(allMuons);
143 
144 /* std::unique_ptr<reco::MuonCollection> pOut(new reco::MuonCollection);
145 
146  // Apply the correction and produce the new muons
147  for( std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
148 
149  double pt = (*corrector_)(*muon);
150  double eta = muon->eta();
151  double phi = muon->phi();
152 
153  reco::Muon * newMuon = muon->clone();
154  newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
155 
156  pOut->push_back(*newMuon);
157  }
158 */
159 
160 }
161 
162 // ------------ method called once each job just before starting event loop ------------
163 void
165 {
166 }
167 
168 // ------------ method called once each job just after ending the event loop ------------
169 void
171 {
172 }
173 
174 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
virtual void endJob() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
std::unique_ptr< T > applyCorrection(const edm::Handle< T > &allMuons)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &) override
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
Definition: HeavyIon.h:7
int iEvent
Definition: GenABIO.cc:230
edm::ESHandle< MuScleFitDBobject > dbObject_
virtual void beginJob() override
boost::shared_ptr< MomentumScaleCorrector > corrector_
unsigned long long dbObjectCacheId_
edm::EDGetTokenT< reco::MuonCollection > theRecoMuonToken_
const T & get() const
Definition: EventSetup.h:56
fixed size matrix
HLT enums.
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
MuScleFitMuonProducer(const edm::ParameterSet &)
edm::EDGetTokenT< pat::MuonCollection > thePatMuonToken_
long double T
EDGetTokenT< ProductType > mayConsume(edm::InputTag const &tag)
T const * product() const
Definition: ESHandle.h:86