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:
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 {
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);
126  } else {
128  iEvent.getByToken(theRecoMuonToken_, 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
MuScleFitMuonProducer::dbObjectCacheId_
unsigned long long dbObjectCacheId_
Definition: MuScleFitMuonProducer.cc:65
MuScleFitDBobjectRcd.h
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
CompositeCandidate.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
Muon.h
MomentumScaleCorrector
Definition: MomentumScaleCorrector.h:25
EDProducer.h
ESHandle.h
muon
Definition: MuonCocktails.h:17
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
edm::EDGetTokenT< pat::MuonCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
Muon.h
MuScleFitDBobjectRcd
Definition: MuScleFitDBobjectRcd.h:6
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HLT_2018_cff.muon
muon
Definition: HLT_2018_cff.py:10349
edm::Handle
Definition: AssociativeIterator.h:50
MuScleFitMuonProducer
Definition: MuScleFitMuonProducer.cc:47
MuScleFitMuonProducer::dbObjectLabel_
std::string dbObjectLabel_
Definition: MuScleFitMuonProducer.cc:64
MakerMacros.h
MuScleFitMuonProducer::patMuons_
bool patMuons_
Definition: MuScleFitMuonProducer.cc:62
Track.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
MuScleFitDBobject.h
PVValHelper::eta
Definition: PVValidationHelpers.h:69
MuonFwd.h
reco::MuonCollection
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
MuScleFitMuonProducer::theMuonLabel_
edm::InputTag theMuonLabel_
Definition: MuScleFitMuonProducer.cc:59
edm::ESHandle< MuScleFitDBobject >
LeafCandidate.h
MuScleFitMuonProducer::corrector_
std::shared_ptr< MomentumScaleCorrector > corrector_
Definition: MuScleFitMuonProducer.cc:66
reco::Particle::PolarLorentzVector
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
allMuons_cfi.allMuons
allMuons
Definition: allMuons_cfi.py:3
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
MuScleFitMuonProducer::endJob
void endJob() override
Definition: MuScleFitMuonProducer.cc:157
MuScleFitMuonProducer::MuScleFitMuonProducer
MuScleFitMuonProducer(const edm::ParameterSet &)
Definition: MuScleFitMuonProducer.cc:69
MuScleFitMuonProducer::dbObject_
edm::ESHandle< MuScleFitDBobject > dbObject_
Definition: MuScleFitMuonProducer.cc:63
MuScleFitMuonProducer::beginJob
void beginJob() override
Definition: MuScleFitMuonProducer.cc:154
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
pat
Definition: HeavyIon.h:7
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
get
#define get
MuScleFitMuonProducer::applyCorrection
std::unique_ptr< T > applyCorrection(const edm::Handle< T > &allMuons)
Definition: MuScleFitMuonProducer.cc:86
InputTag.h
DDAxes::phi
std
Definition: JetResolutionObject.h:76
Frameworkfwd.h
T
long double T
Definition: Basic3DVectorLD.h:48
EventSetup.h
edm::EDProducer
Definition: EDProducer.h:36
Functions.h
ParameterSet.h
edm::Event
Definition: Event.h:73
MuScleFitMuonProducer::theRecoMuonToken_
edm::EDGetTokenT< reco::MuonCollection > theRecoMuonToken_
Definition: MuScleFitMuonProducer.cc:61
MomentumScaleCorrector.h
MuScleFitMuonProducer::thePatMuonToken_
edm::EDGetTokenT< pat::MuonCollection > thePatMuonToken_
Definition: MuScleFitMuonProducer.cc:60
edm::InputTag
Definition: InputTag.h:15
MuScleFitMuonProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: MuScleFitMuonProducer.cc:106
MuScleFitMuonProducer::~MuScleFitMuonProducer
~MuScleFitMuonProducer() override
Definition: MuScleFitMuonProducer.cc:83