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 // $Id: MuScleFitMuonProducer.cc,v 1.8 2010/12/13 11:23:42 demattia Exp $
14 //
15 //
16 
17 // system include files
18 #include <memory>
19 #include <string>
20 
21 // user include files
24 
27 
30 
34 
38 
40 
43 
47 
49  public:
52 
53  private:
54  virtual void beginJob() ;
55  virtual void produce(edm::Event&, const edm::EventSetup&);
56  virtual void endJob() ;
57  template<class T> std::auto_ptr<T> applyCorrection(const edm::Handle<T> & allMuons);
58 
60  bool patMuons_;
62  std::string dbObjectLabel_;
63  unsigned long long dbObjectCacheId_;
64  boost::shared_ptr<MomentumScaleCorrector> corrector_;
65 };
66 
68  theMuonLabel_( iConfig.getParameter<edm::InputTag>( "MuonLabel" ) ),
69  patMuons_( iConfig.getParameter<bool>( "PatMuons" ) ),
70  dbObjectLabel_( iConfig.getUntrackedParameter<std::string>("DbObjectLabel", "") ),
71  dbObjectCacheId_(0)
72 {
73  if ( patMuons_ == true ) {
74  produces<pat::MuonCollection>();
75  } else {
76  produces<reco::MuonCollection>();
77  }
78 }
79 
80 
82 {
83 }
84 
85 
86 template<class T>
88 {
89  std::auto_ptr<T> pOut(new T);
90 
91  // Apply the correction and produce the new muons
92  for( typename T::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
93 
94  //std::cout << "Pt before correction = " << muon->pt() << std::endl;
95  double pt = (*corrector_)(*muon);
96  //std::cout << "Pt after correction = " << pt << std::endl;
97  double eta = muon->eta();
98  double phi = muon->phi();
99 
100  typename T::value_type * newMuon = muon->clone();
101  newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
102 
103  pOut->push_back(*newMuon);
104  }
105  return pOut;
106 }
107 
108 // ------------ method called to produce the data ------------
110 {
111  unsigned long long dbObjectCacheId = iSetup.get<MuScleFitDBobjectRcd>().cacheIdentifier();
112  if ( dbObjectCacheId != dbObjectCacheId_ ) {
113  if ( dbObjectLabel_ != "" ) {
115  } else {
116  iSetup.get<MuScleFitDBobjectRcd>().get(dbObject_);
117  }
118  }
119 
120  //std::cout << "identifiers size from dbObject = " << dbObject_->identifiers.size() << std::endl;
121  //std::cout << "parameters size from dbObject = " << dbObject_->parameters.size() << std::endl;;
122 
123  // Create the corrector and set the parameters
125 
126  if( patMuons_ == true ) {
128  iEvent.getByLabel (theMuonLabel_, allMuons);
129  iEvent.put(applyCorrection(allMuons));
130  }
131  else {
133  iEvent.getByLabel (theMuonLabel_, allMuons);
134  iEvent.put(applyCorrection(allMuons));
135  }
136 
137  // put into the Event
138  // iEvent.put(pOut);
139  // iEvent.put(applyCorrection(allMuons));
140 
141 /* std::auto_ptr<reco::MuonCollection> pOut(new reco::MuonCollection);
142 
143  // Apply the correction and produce the new muons
144  for( std::vector<reco::Muon>::const_iterator muon = allMuons->begin(); muon != allMuons->end(); ++muon ) {
145 
146  double pt = (*corrector_)(*muon);
147  double eta = muon->eta();
148  double phi = muon->phi();
149 
150  reco::Muon * newMuon = muon->clone();
151  newMuon->setP4( reco::Particle::PolarLorentzVector( pt, eta, phi, muon->mass() ) );
152 
153  pOut->push_back(*newMuon);
154  }
155 */
156 
157 }
158 
159 // ------------ method called once each job just before starting event loop ------------
160 void
162 {
163 }
164 
165 // ------------ method called once each job just after ending the event loop ------------
166 void
168 {
169 }
170 
171 //define this as a plug-in
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void produce(edm::Event &, const edm::EventSetup &)
T eta() const
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
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:356
std::auto_ptr< T > applyCorrection(const edm::Handle< T > &allMuons)
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:27
MuScleFitMuonProducer(const edm::ParameterSet &)
long double T
Definition: DDAxes.h:10