CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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:
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::auto_ptr<T> applyCorrection(const edm::Handle<T> & allMuons);
57 
59  bool patMuons_;
62  unsigned long long dbObjectCacheId_;
63  boost::shared_ptr<MomentumScaleCorrector> corrector_;
64 };
65 
67  theMuonLabel_( iConfig.getParameter<edm::InputTag>( "MuonLabel" ) ),
68  patMuons_( iConfig.getParameter<bool>( "PatMuons" ) ),
69  dbObjectLabel_( iConfig.getUntrackedParameter<std::string>("DbObjectLabel", "") ),
70  dbObjectCacheId_(0)
71 {
72  if ( patMuons_ == true ) {
73  produces<pat::MuonCollection>();
74  } else {
75  produces<reco::MuonCollection>();
76  }
77 }
78 
79 
81 {
82 }
83 
84 
85 template<class T>
87 {
88  std::auto_ptr<T> pOut(new T);
89 
90  // Apply the correction and produce the new muons
91  for( typename T::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
92 
93  //std::cout << "Pt before correction = " << muon->pt() << std::endl;
94  double pt = (*corrector_)(*muon);
95  //std::cout << "Pt after correction = " << pt << std::endl;
96  double eta = muon->eta();
97  double phi = muon->phi();
98 
99  typename T::value_type * newMuon = muon->clone();
100  newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
101 
102  pOut->push_back(*newMuon);
103  }
104  return pOut;
105 }
106 
107 // ------------ method called to produce the data ------------
109 {
110  unsigned long long dbObjectCacheId = iSetup.get<MuScleFitDBobjectRcd>().cacheIdentifier();
111  if ( dbObjectCacheId != dbObjectCacheId_ ) {
112  if ( dbObjectLabel_ != "" ) {
114  } else {
115  iSetup.get<MuScleFitDBobjectRcd>().get(dbObject_);
116  }
117  }
118 
119  //std::cout << "identifiers size from dbObject = " << dbObject_->identifiers.size() << std::endl;
120  //std::cout << "parameters size from dbObject = " << dbObject_->parameters.size() << std::endl;;
121 
122  // Create the corrector and set the parameters
124 
125  if( patMuons_ == true ) {
127  iEvent.getByLabel (theMuonLabel_, allMuons);
128  iEvent.put(applyCorrection(allMuons));
129  }
130  else {
132  iEvent.getByLabel (theMuonLabel_, allMuons);
133  iEvent.put(applyCorrection(allMuons));
134  }
135 
136  // put into the Event
137  // iEvent.put(pOut);
138  // iEvent.put(applyCorrection(allMuons));
139 
140 /* std::auto_ptr<reco::MuonCollection> pOut(new reco::MuonCollection);
141 
142  // Apply the correction and produce the new muons
143  for( std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
144 
145  double pt = (*corrector_)(*muon);
146  double eta = muon->eta();
147  double phi = muon->phi();
148 
149  reco::Muon * newMuon = muon->clone();
150  newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
151 
152  pOut->push_back(*newMuon);
153  }
154 */
155 
156 }
157 
158 // ------------ method called once each job just before starting event loop ------------
159 void
161 {
162 }
163 
164 // ------------ method called once each job just after ending the event loop ------------
165 void
167 {
168 }
169 
170 //define this as a plug-in
virtual void endJob() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &) override
T eta() const
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
edm::ESHandle< MuScleFitDBobject > dbObject_
tuple allMuons
Definition: allMuons_cfi.py:3
Container::value_type value_type
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
std::auto_ptr< T > applyCorrection(const edm::Handle< T > &allMuons)
virtual void beginJob() override
boost::shared_ptr< MomentumScaleCorrector > corrector_
unsigned long long dbObjectCacheId_
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:29
MuScleFitMuonProducer(const edm::ParameterSet &)
long double T
Definition: DDAxes.h:10