CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ShiftedPFCandidateProducerByMatchedObject.cc
Go to the documentation of this file.
2 
3 #include <TMath.h>
4 
6  : moduleLabel_(cfg.getParameter<std::string>("@module_label"))
7 {
8  srcPFCandidates_ = consumes<edm::Handle<reco::PFCandidateCollection> >(cfg.getParameter<edm::InputTag>("srcPFCandidates"));
9  srcUnshiftedObjects_ = consumes<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("srcUnshiftedObjects"));
10  srcShiftedObjects_ = consumes<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("srcShiftedObjects"));
11 
12  dRmatch_PFCandidate_ = cfg.getParameter<double>("dRmatch_PFCandidate");
14  dRmatch_Object_ = cfg.exists("dRmatch_Object") ?
15  cfg.getParameter<double>("dRmatch_Object") : 0.1;
17  produces<reco::PFCandidateCollection>();
18 }
19 
21 {
22 // nothing to be done yet...
23 }
24 
26 {
27  edm::Handle<reco::PFCandidateCollection> originalPFCandidates;
28  evt.getByToken(srcPFCandidates_, originalPFCandidates);
29 
31 
32  edm::Handle<CandidateView> unshiftedObjects;
33  evt.getByToken(srcUnshiftedObjects_, unshiftedObjects);
34 
35  edm::Handle<CandidateView> shiftedObjects;
36  evt.getByToken(srcShiftedObjects_, shiftedObjects);
37 
38  objects_.clear();
39 
40  CandidateView::const_iterator shiftedObjectP4_matched;
41  bool isMatched_Object = false;
42  double dR2bestMatch_Object = 1.e+3;
43  for ( CandidateView::const_iterator unshiftedObject = unshiftedObjects->begin();
44  unshiftedObject != unshiftedObjects->end(); ++unshiftedObject ) {
45  isMatched_Object = false;
46  dR2bestMatch_Object = 1.e+3;
47 
48  for ( CandidateView::const_iterator shiftedObject = shiftedObjects->begin();
49  shiftedObject != shiftedObjects->end(); ++shiftedObject ) {
50  double dR2 = deltaR2(unshiftedObject->p4(), shiftedObject->p4());
51  if ( dR2 < dR2match_Object_ && dR2 < dR2bestMatch_Object ) {
52  shiftedObjectP4_matched = shiftedObject;
53  isMatched_Object = true;
54  dR2bestMatch_Object = dR2;
55  }
56  }
57  if ( isMatched_Object ) {
58  objects_.push_back(objectEntryType(shiftedObjectP4_matched->p4(), unshiftedObject->p4(), sqrt(dR2bestMatch_Object) ));
59  }
60  }
61 
62  std::auto_ptr<reco::PFCandidateCollection> shiftedPFCandidates(new reco::PFCandidateCollection);
63 
64  for ( reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin();
65  originalPFCandidate != originalPFCandidates->end(); ++originalPFCandidate ) {
66 
67  double shift = 0.;
68  bool applyShift = false;
69  double dR2bestMatch_PFCandidate = 1.e+3;
70  for ( std::vector<objectEntryType>::const_iterator object = objects_.begin();
71  object != objects_.end(); ++object ) {
72  if ( !object->isValidMatch_ ) continue;
73  double dR2 = deltaR2(originalPFCandidate->p4(), object->unshiftedObjectP4_);
74  if ( dR2 < dR2match_PFCandidate_ && dR2 < dR2bestMatch_PFCandidate ) {
75  shift = object->shift_;
76  applyShift = true;
77  dR2bestMatch_PFCandidate = dR2;
78  }
79  }
80 
81  reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4();
82  if ( applyShift ) {
83  double shiftedPx = (1. + shift)*originalPFCandidate->px();
84  double shiftedPy = (1. + shift)*originalPFCandidate->py();
85  double shiftedPz = (1. + shift)*originalPFCandidate->pz();
86  double mass = originalPFCandidate->mass();
87  double shiftedEn = TMath::Sqrt(shiftedPx*shiftedPx + shiftedPy*shiftedPy + shiftedPz*shiftedPz + mass*mass);
88  shiftedPFCandidateP4.SetPxPyPzE(shiftedPx, shiftedPy, shiftedPz, shiftedEn);
89  }
90 
91  reco::PFCandidate shiftedPFCandidate(*originalPFCandidate);
92  shiftedPFCandidate.setP4(shiftedPFCandidateP4);
93 
94  shiftedPFCandidates->push_back(shiftedPFCandidate);
95  }
96 
97  evt.put(shiftedPFCandidates);
98 }
99 
101 
103 
104 
105 
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool exists(std::string const &parameterName) const
checks if a parameter exists
virtual void setP4(const LorentzVector &p4)
set 4-momentum
edm::EDGetTokenT< edm::View< reco::Candidate > > srcShiftedObjects_
edm::View< reco::Candidate > CandidateView
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
T sqrt(T t)
Definition: SSEVec.h:48
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
edm::EDGetTokenT< edm::Handle< reco::PFCandidateCollection > > srcPFCandidates_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcUnshiftedObjects_
std::vector< reco::PFCandidate > PFCandidateCollection
collection of PFCandidates
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
list object
Definition: dbtoconf.py:77
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
static unsigned int const shift
moduleLabel_(iConfig.getParameter< string >("@module_label"))