CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
DistortedMuonProducer Class Reference
Inheritance diagram for DistortedMuonProducer:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

 DistortedMuonProducer (const edm::ParameterSet &)
 
 ~DistortedMuonProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Member Functions

virtual void beginJob ()
 
virtual void endJob ()
 
virtual void produce (edm::Event &, const edm::EventSetup &)
 

Private Attributes

std::vector< double > efficiencyRatioOverMC_
 
std::vector< double > etaBinEdges_
 
edm::InputTag genMatchMapTag_
 
edm::InputTag muonTag_
 
std::vector< double > relativeShiftOnPt_
 
std::vector< double > relativeUncertaintyOnPt_
 
std::vector< double > shiftOnOneOverPt_
 
std::vector< double > uncertaintyOnOneOverPt_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

Definition at line 13 of file DistortedMuonProducer.cc.

Constructor & Destructor Documentation

DistortedMuonProducer::DistortedMuonProducer ( const edm::ParameterSet pset)
explicit

Definition at line 47 of file DistortedMuonProducer.cc.

References efficiencyRatioOverMC_, etaBinEdges_, genMatchMapTag_, edm::ParameterSet::getUntrackedParameter(), i, muonTag_, relativeShiftOnPt_, relativeUncertaintyOnPt_, shiftOnOneOverPt_, and uncertaintyOnOneOverPt_.

47  {
48 
49  // What is being produced
50  produces<std::vector<reco::Muon> >();
51 
52  // Input products
53  muonTag_ = pset.getUntrackedParameter<edm::InputTag> ("MuonTag", edm::InputTag("muons"));
54  genMatchMapTag_ = pset.getUntrackedParameter<edm::InputTag> ("GenMatchMapTag", edm::InputTag("genMatchMap"));
55 
56  // Eta edges
57  std::vector<double> defEtaEdges;
58  defEtaEdges.push_back(-999999.);
59  defEtaEdges.push_back(999999.);
60  etaBinEdges_ = pset.getUntrackedParameter<std::vector<double> > ("EtaBinEdges",defEtaEdges);
61  unsigned int ninputs_expected = etaBinEdges_.size()-1;
62 
63  // Distortions in muon momentum
64  std::vector<double> defDistortion;
65  defDistortion.push_back(0.);
66 
67  shiftOnOneOverPt_ = pset.getUntrackedParameter<std::vector<double> > ("ShiftOnOneOverPt",defDistortion); // in [1/GeV]
68  if (shiftOnOneOverPt_.size()==1 && ninputs_expected>1) {
69  for (unsigned int i=1; i<ninputs_expected; i++){ shiftOnOneOverPt_.push_back(shiftOnOneOverPt_[0]);}
70  }
71 
72  relativeShiftOnPt_ = pset.getUntrackedParameter<std::vector<double> > ("RelativeShiftOnPt",defDistortion);
73  if (relativeShiftOnPt_.size()==1 && ninputs_expected>1) {
74  for (unsigned int i=1; i<ninputs_expected; i++){ relativeShiftOnPt_.push_back(relativeShiftOnPt_[0]);}
75  }
76 
77  uncertaintyOnOneOverPt_ = pset.getUntrackedParameter<std::vector<double> > ("UncertaintyOnOneOverPt",defDistortion); // in [1/GeV]
78  if (uncertaintyOnOneOverPt_.size()==1 && ninputs_expected>1) {
79  for (unsigned int i=1; i<ninputs_expected; i++){ uncertaintyOnOneOverPt_.push_back(uncertaintyOnOneOverPt_[0]);}
80  }
81 
82  relativeUncertaintyOnPt_ = pset.getUntrackedParameter<std::vector<double> > ("RelativeUncertaintyOnPt",defDistortion);
83  if (relativeUncertaintyOnPt_.size()==1 && ninputs_expected>1) {
84  for (unsigned int i=1; i<ninputs_expected; i++){ relativeUncertaintyOnPt_.push_back(relativeUncertaintyOnPt_[0]);}
85  }
86 
87  // Data/MC efficiency ratios
88  std::vector<double> defEfficiencyRatio;
89  defEfficiencyRatio.push_back(1.);
90  efficiencyRatioOverMC_ = pset.getUntrackedParameter<std::vector<double> > ("EfficiencyRatioOverMC",defEfficiencyRatio);
91  if (efficiencyRatioOverMC_.size()==1 && ninputs_expected>1) {
92  for (unsigned int i=1; i<ninputs_expected; i++){ efficiencyRatioOverMC_.push_back(efficiencyRatioOverMC_[0]);}
93  }
94 
95  // Send a warning if there are inconsistencies in vector sizes !!
96  bool effWrong = efficiencyRatioOverMC_.size()!=ninputs_expected;
97  bool momWrong = shiftOnOneOverPt_.size()!=ninputs_expected
98  || relativeShiftOnPt_.size()!=ninputs_expected
99  || uncertaintyOnOneOverPt_.size()!=ninputs_expected
100  || relativeUncertaintyOnPt_.size()!=ninputs_expected;
101  if ( effWrong and momWrong) {
102  edm::LogError("") << "WARNING: DistortedMuonProducer : Size of some parameters do not match the EtaBinEdges vector!!";
103  }
104 
105 }
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< double > etaBinEdges_
std::vector< double > efficiencyRatioOverMC_
std::vector< double > shiftOnOneOverPt_
std::vector< double > relativeUncertaintyOnPt_
std::vector< double > relativeShiftOnPt_
std::vector< double > uncertaintyOnOneOverPt_
DistortedMuonProducer::~DistortedMuonProducer ( )

Definition at line 108 of file DistortedMuonProducer.cc.

108  {
109 }

Member Function Documentation

void DistortedMuonProducer::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 112 of file DistortedMuonProducer.cc.

112  {
113 }
void DistortedMuonProducer::endJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 116 of file DistortedMuonProducer.cc.

116  {
117 }
void DistortedMuonProducer::produce ( edm::Event ev,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDProducer.

Definition at line 120 of file DistortedMuonProducer.cc.

References reco::LeafCandidate::charge(), reco::Muon::clone(), efficiencyRatioOverMC_, reco::LeafCandidate::eta(), ExpressReco_HICollisions_FallBack::etaBin, etaBinEdges_, genMatchMapTag_, edm::Event::getByLabel(), i, edm::Ref< C, T, F >::isNull(), edm::EventBase::isRealData(), j, LogTrace, reco::LeafCandidate::mass(), ExpressReco_HICollisions_FallBack::muonCollection, muonTag_, ExpressReco_HICollisions_FallBack::nbins, reco::LeafCandidate::phi(), reco::LeafCandidate::pt(), edm::Event::put(), relativeShiftOnPt_, relativeUncertaintyOnPt_, reco::LeafCandidate::setP4(), shiftOnOneOverPt_, and uncertaintyOnOneOverPt_.

Referenced by python.JSONExport.JsonExport::export(), and python.HTMLExport.HTMLExport::export().

120  {
121 
122  if (ev.isRealData()) return;
123 
124  // Muon collection
126  if (!ev.getByLabel(muonTag_, muonCollection)) {
127  edm::LogError("") << ">>> Muon collection does not exist !!!";
128  return;
129  }
130 
132  if (!ev.getByLabel(genMatchMapTag_, genMatchMap)) {
133  edm::LogError("") << ">>> Muon-GenParticle match map does not exist !!!";
134  return;
135  }
136 
137  unsigned int muonCollectionSize = muonCollection->size();
138 
139  std::auto_ptr<reco::MuonCollection> newmuons (new reco::MuonCollection);
140 
141  for (unsigned int i=0; i<muonCollectionSize; i++) {
142  edm::RefToBase<reco::Muon> mu = muonCollection->refAt(i);
143 
144  double ptgen = mu->pt();
145  double etagen = mu->eta();
146  double phigen = mu->phi();
147  int chrgen = mu->charge();
148  reco::GenParticleRef gen = (*genMatchMap)[mu];
149  if( !gen.isNull()) {
150  ptgen = gen->pt();
151  etagen = gen->eta();
152  phigen = gen->phi();
153  chrgen = gen->charge();
154  LogTrace("") << ">>> Muon-GenParticle match found; ptmu= " << mu->pt() << ", ptgen= " << ptgen;
155  } else {
156  LogTrace("") << ">>> MUON-GENPARTICLE MATCH NOT FOUND!!!";
157  }
158 
159  // Initialize parameters
160  double effRatio = 0.;
161  double shift1 = 0.;
162  double shift2 = 0.;
163  double sigma1 = 0.;
164  double sigma2 = 0.;
165 
166  // Find out which eta bin should be used
167  unsigned int nbins = etaBinEdges_.size()-1;
168  unsigned int etaBin = nbins;
169  if (etagen>etaBinEdges_[0] && etagen<etaBinEdges_[nbins]) {
170  for (unsigned int j=1; j<=nbins; ++j) {
171  if (etagen>etaBinEdges_[j]) continue;
172  etaBin = j-1;
173  break;
174  }
175  }
176  if (etaBin<nbins) {
177  LogTrace("") << ">>> etaBin: " << etaBin << ", for etagen =" << etagen;
178  } else {
179  // Muon is rejected if outside the considered eta range
180  LogTrace("") << ">>> Muon outside eta range: reject it; etagen = " << etagen;
181  continue;
182  }
183 
184  // Set shifts
185  shift1 = shiftOnOneOverPt_[etaBin];
186  shift2 = relativeShiftOnPt_[etaBin];
187  LogTrace("") << "\tshiftOnOneOverPt= " << shift1*100 << " [%]";
188  LogTrace("") << "\trelativeShiftOnPt= " << shift2*100 << " [%]";
189 
190  // Set resolutions
193  LogTrace("") << "\tuncertaintyOnOneOverPt= " << sigma1 << " [1/GeV]";
194  LogTrace("") << "\trelativeUncertaintyOnPt= " << sigma2*100 << " [%]";
195 
196  // Set efficiency ratio
197  effRatio = efficiencyRatioOverMC_[etaBin];
198  LogTrace("") << "\tefficiencyRatioOverMC= " << effRatio;
199 
200  // Reject muons according to efficiency ratio
201  double rndf = CLHEP::RandFlat::shoot();
202  if (rndf>effRatio) continue;
203 
204  // Gaussian Random numbers for smearing
205  double rndg1 = CLHEP::RandGauss::shoot();
206  double rndg2 = CLHEP::RandGauss::shoot();
207 
208  // New muon
209  double ptmu = mu->pt();
210  ptmu += ptgen * ( shift1*ptgen + shift2 + sigma1*rndg1*ptgen + sigma2*rndg2);
211  reco::Muon* newmu = mu->clone();
212  newmu->setP4 (
214  ptmu, mu->eta(), mu->phi(), mu->mass()
215  )
216  );
217  newmuons->push_back(*newmu);
218 
219  }
220 
221  ev.put(newmuons);
222 }
int i
Definition: DBlmapReader.cc:9
std::vector< double > etaBinEdges_
virtual void setP4(const LorentzVector &p4)
set 4-momentum
std::vector< double > efficiencyRatioOverMC_
bool isRealData() const
Definition: EventBase.h:60
virtual double eta() const
momentum pseudorapidity
std::vector< Muon > MuonCollection
collection of Muon objects
Definition: MuonFwd.h:9
virtual double mass() const
mass
bool isNull() const
Checks for null.
Definition: Ref.h:244
std::vector< double > shiftOnOneOverPt_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
virtual int charge() const
electric charge
int j
Definition: DBlmapReader.cc:9
std::vector< double > relativeUncertaintyOnPt_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
#define LogTrace(id)
Muon * clone() const
create a clone
Definition: Muon.cc:36
virtual double pt() const
transverse momentum
std::vector< double > relativeShiftOnPt_
std::vector< double > uncertaintyOnOneOverPt_
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:28
virtual double phi() const
momentum azimuthal angle

Member Data Documentation

std::vector<double> DistortedMuonProducer::efficiencyRatioOverMC_
private

Definition at line 32 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

std::vector<double> DistortedMuonProducer::etaBinEdges_
private

Definition at line 25 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

edm::InputTag DistortedMuonProducer::genMatchMapTag_
private

Definition at line 24 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

edm::InputTag DistortedMuonProducer::muonTag_
private

Definition at line 23 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

std::vector<double> DistortedMuonProducer::relativeShiftOnPt_
private

Definition at line 28 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

std::vector<double> DistortedMuonProducer::relativeUncertaintyOnPt_
private

Definition at line 30 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

std::vector<double> DistortedMuonProducer::shiftOnOneOverPt_
private

Definition at line 27 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().

std::vector<double> DistortedMuonProducer::uncertaintyOnOneOverPt_
private

Definition at line 29 of file DistortedMuonProducer.cc.

Referenced by DistortedMuonProducer(), and produce().