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
DistortedPFCandProducer Class Reference
Inheritance diagram for DistortedPFCandProducer:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

 DistortedPFCandProducer (const edm::ParameterSet &)
 
 ~DistortedPFCandProducer ()
 
- 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_
 
edm::InputTag pfTag_
 
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 12 of file DistortedPFCandProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 50 of file DistortedPFCandProducer.cc.

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

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

Definition at line 112 of file DistortedPFCandProducer.cc.

112  {
113 }

Member Function Documentation

void DistortedPFCandProducer::beginJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 116 of file DistortedPFCandProducer.cc.

116  {
117 }
void DistortedPFCandProducer::endJob ( void  )
privatevirtual

Reimplemented from edm::EDProducer.

Definition at line 120 of file DistortedPFCandProducer.cc.

120  {
121 }
void DistortedPFCandProducer::produce ( edm::Event ev,
const edm::EventSetup iSetup 
)
privatevirtual

Implements edm::EDProducer.

Definition at line 124 of file DistortedPFCandProducer.cc.

References reco::LeafCandidate::charge(), reco::PFCandidate::clone(), efficiencyRatioOverMC_, reco::LeafCandidate::eta(), etaBinEdges_, funct::false, genMatchMapTag_, edm::Event::getByLabel(), i, reco::Muon::isGlobalMuon(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::isNull(), edm::EventBase::isRealData(), reco::Muon::isStandAloneMuon(), reco::Muon::isTrackerMuon(), j, edm::RefToBase< T >::key(), edm::Ref< C, T, F >::key(), LogTrace, reco::LeafCandidate::mass(), reco::PFCandidate::mu, reco::PFCandidate::muonRef(), muonTag_, RecoTauCommonJetSelections_cfi::nbins, reco::PFCandidate::particleId(), pfTag_, reco::LeafCandidate::phi(), reco::LeafCandidate::pt(), edm::Event::put(), relativeShiftOnPt_, relativeUncertaintyOnPt_, reco::LeafCandidate::setP4(), shiftOnOneOverPt_, reco::Muon::track(), and uncertaintyOnOneOverPt_.

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

124  {
125 
126  if (ev.isRealData()) return;
127 
128  // Muon collection
129  edm::Handle<edm::View<reco::Muon> > muonCollection;
130  if (!ev.getByLabel(muonTag_, muonCollection)) {
131  edm::LogError("") << ">>> Muon collection does not exist !!!";
132  return;
133  }
134 
136  if (!ev.getByLabel(genMatchMapTag_, genMatchMap)) {
137  edm::LogError("") << ">>> Muon-GenParticle match map does not exist !!!";
138  return;
139  }
140 
141 
142  // Get PFCandidate collection
144  if (!ev.getByLabel(pfTag_, pfCollection)) {
145  edm::LogError("") << ">>> PFCandidate collection does not exist !!!";
146  return;
147  }
148 
149  unsigned int muonCollectionSize = muonCollection->size();
150  unsigned int pfCollectionSize = pfCollection->size();
151 
152  if (pfCollectionSize<1) return;
153 
154 
155  // Ask for PfMuon consistency
156  bool pfMuonFound = false;
157 
158 
159 
160  std::auto_ptr<reco::PFCandidateCollection> newmuons (new reco::PFCandidateCollection);
161 
162 
163  // Loop on all PF candidates
164  for (unsigned int j=0; j<pfCollectionSize; j++) {
165  edm::RefToBase<reco::PFCandidate> pf = pfCollection->refAt(j);
166 
167 
168  // New PF muon
169  double ptmu = pf->pt();
170 
171 
172  for (unsigned int i=0; i<muonCollectionSize; i++) {
173  edm::RefToBase<reco::Muon> mu = muonCollection->refAt(i);
174 
175 
176  // Check the muon is in the PF collection
177  if (pf->particleId()==reco::PFCandidate::mu) {
178  reco::MuonRef muref = pf->muonRef();
179  if (muref.isNonnull()) {
180  if (muref.key()==mu.key()) {
181  if ( mu->isStandAloneMuon() && ptmu == muref->standAloneMuon()->pt() && (
182  ( !mu->isGlobalMuon() || ( mu->isGlobalMuon() && ptmu != muref->combinedMuon()->pt() ) ) &&
183  ( !mu->isTrackerMuon() || ( mu->isTrackerMuon() && ptmu != mu->track()->pt() ) ) )
184  ) {
185  pfMuonFound = false;
186  }
187  else if ( !mu->isTrackerMuon() ){
188  pfMuonFound = false;
189  }
190  else{
191  pfMuonFound = true;}
192  }
193  else {pfMuonFound = false; }
194 
195  }
196  }
197 
198  // do nothing if StandAlone muon
199  //const reco::Track& track = *trackRef;
200 
201  if ( !pfMuonFound) continue;
202 
203  double ptgen = pf->pt();
204  double etagen = pf->eta();
205  double phigen = pf->phi();
206  int chrgen = pf->charge();
207 
208 
209  reco::GenParticleRef gen = (*genMatchMap)[mu];
210  if( !gen.isNull()) {
211  ptgen = gen->pt();
212  etagen = gen->eta();
213  phigen = gen->phi();
214  chrgen = gen->charge();
215  LogTrace("") << ">>> Muon-GenParticle match found; ptmu= " << pf->pt() << ", ptgen= " << ptgen;
216  } else {
217  LogTrace("") << ">>> MUON-GENPARTICLE MATCH NOT FOUND!!!";
218  }
219 
220 
221  // Initialize parameters
222  double effRatio = 0.;
223  double shift1 = 0.;
224  double shift2 = 0.;
225  double sigma1 = 0.;
226  double sigma2 = 0.;
227 
228  // Find out which eta bin should be used
229  unsigned int nbins = etaBinEdges_.size()-1;
230  unsigned int etaBin = nbins;
231  if (etagen>etaBinEdges_[0] && etagen<etaBinEdges_[nbins]) {
232  for (unsigned int j=1; j<=nbins; ++j) {
233  if (etagen>etaBinEdges_[j]) continue;
234  etaBin = j-1;
235  break;
236  }
237  }
238  if (etaBin<nbins) {
239  LogTrace("") << ">>> etaBin: " << etaBin << ", for etagen =" << etagen;
240  } else {
241  // Muon is rejected if outside the considered eta range
242  LogTrace("") << ">>> Muon outside eta range: reject it; etagen = " << etagen;
243  pfMuonFound = false;
244  continue;
245  }
246 
247  if (!pfMuonFound) continue;
248 
249  // Set shifts
250  shift1 = shiftOnOneOverPt_[etaBin];
251  shift2 = relativeShiftOnPt_[etaBin];
252  LogTrace("") << "\tshiftOnOneOverPt= " << shift1*100 << " [%]";
253  LogTrace("") << "\trelativeShiftOnPt= " << shift2*100 << " [%]";
254 
255  // Set resolutions
256  sigma1 = uncertaintyOnOneOverPt_[etaBin];
257  sigma2 = relativeUncertaintyOnPt_[etaBin];
258  LogTrace("") << "\tuncertaintyOnOneOverPt= " << sigma1 << " [1/GeV]";
259  LogTrace("") << "\trelativeUncertaintyOnPt= " << sigma2*100 << " [%]";
260 
261  // Set efficiency ratio
262  effRatio = efficiencyRatioOverMC_[etaBin];
263  LogTrace("") << "\tefficiencyRatioOverMC= " << effRatio;
264 
265  // Reject muons according to efficiency ratio
266  double rndf = CLHEP::RandFlat::shoot();
267  if (rndf>effRatio) continue;
268 
269  // Gaussian Random numbers for smearing
270  double rndg1 = CLHEP::RandGauss::shoot();
271  double rndg2 = CLHEP::RandGauss::shoot();
272 
273 
274  // change here the pt of the candidate, if it is a muon
275 
276  ptmu += ptgen * ( shift1*ptgen + shift2 + sigma1*rndg1*ptgen + sigma2*rndg2);
277  pfMuonFound = false ;
278 
279  }
280 
281  reco::PFCandidate* newmu = pf->clone();
282  newmu->setP4 (
284  ptmu, pf->eta(), pf->phi(), pf->mass()
285  )
286  );
287 
288  newmuons->push_back(*newmu);
289  }
290 
291 
292  ev.put(newmuons);
293 
294 
295 }
int i
Definition: DBlmapReader.cc:9
std::vector< double > relativeUncertaintyOnPt_
virtual PFCandidate * clone() const
return a clone
Definition: PFCandidate.cc:114
bool isTrackerMuon() const
Definition: Muon.h:149
virtual TrackRef track() const
reference to a Track
Definition: Muon.h:39
bool isGlobalMuon() const
Definition: Muon.h:148
virtual void setP4(const LorentzVector &p4)
set 4-momentum
bool isStandAloneMuon() const
Definition: Muon.h:150
bool isRealData() const
Definition: EventBase.h:60
virtual double eta() const
momentum pseudorapidity
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:249
virtual double mass() const
mass
bool isNull() const
Checks for null.
Definition: Ref.h:246
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
std::vector< double > uncertaintyOnOneOverPt_
virtual int charge() const
electric charge
int j
Definition: DBlmapReader.cc:9
size_t key() const
Definition: RefToBase.h:228
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
#define LogTrace(id)
reco::MuonRef muonRef() const
Definition: PFCandidate.cc:347
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
virtual double pt() const
transverse momentum
std::vector< double > efficiencyRatioOverMC_
key_type key() const
Accessor for product key.
Definition: Ref.h:265
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:33
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:28
virtual ParticleType particleId() const
Definition: PFCandidate.h:314
std::vector< double > relativeShiftOnPt_
std::vector< double > shiftOnOneOverPt_
virtual double phi() const
momentum azimuthal angle
std::vector< double > etaBinEdges_

Member Data Documentation

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

Definition at line 32 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 25 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

edm::InputTag DistortedPFCandProducer::genMatchMapTag_
private

Definition at line 24 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

edm::InputTag DistortedPFCandProducer::muonTag_
private

Definition at line 22 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

edm::InputTag DistortedPFCandProducer::pfTag_
private

Definition at line 23 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 28 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 30 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 27 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().

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

Definition at line 29 of file DistortedPFCandProducer.cc.

Referenced by DistortedPFCandProducer(), and produce().