CMS 3D CMS Logo

ShiftedPFCandidateProducerByMatchedObject.cc
Go to the documentation of this file.
2 
3 const double dRDefault = 1000;
4 
6  srcPFCandidates_ = consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("srcPFCandidates"));
7  srcUnshiftedObjects_ = consumes<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("srcUnshiftedObjects"));
8  srcShiftedObjects_ = consumes<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("srcShiftedObjects"));
9 
10  dRmatch_PFCandidate_ = cfg.getParameter<double>("dRmatch_PFCandidate");
12  dRmatch_Object_ = cfg.exists("dRmatch_Object") ? cfg.getParameter<double>("dRmatch_Object") : 0.1;
14  produces<reco::PFCandidateCollection>();
15 }
16 
18  // nothing to be done yet...
19 }
20 
22  edm::Handle<reco::PFCandidateCollection> originalPFCandidates;
23  evt.getByToken(srcPFCandidates_, originalPFCandidates);
24 
26 
27  edm::Handle<CandidateView> unshiftedObjects;
28  evt.getByToken(srcUnshiftedObjects_, unshiftedObjects);
29 
30  edm::Handle<CandidateView> shiftedObjects;
31  evt.getByToken(srcShiftedObjects_, shiftedObjects);
32 
33  objects_.clear();
34 
35  CandidateView::const_iterator shiftedObjectP4_matched;
36  bool isMatched_Object = false;
37  double dR2bestMatch_Object = dRDefault;
38  for (CandidateView::const_iterator unshiftedObject = unshiftedObjects->begin();
39  unshiftedObject != unshiftedObjects->end();
40  ++unshiftedObject) {
41  isMatched_Object = false;
42  dR2bestMatch_Object = dRDefault;
43 
44  for (CandidateView::const_iterator shiftedObject = shiftedObjects->begin(); shiftedObject != shiftedObjects->end();
45  ++shiftedObject) {
46  double dR2 = deltaR2(unshiftedObject->p4(), shiftedObject->p4());
47  if (dR2 < dR2match_Object_ && dR2 < dR2bestMatch_Object) {
48  shiftedObjectP4_matched = shiftedObject;
49  isMatched_Object = true;
50  dR2bestMatch_Object = dR2;
51  }
52  }
53  if (isMatched_Object) {
54  objects_.push_back(
55  objectEntryType(shiftedObjectP4_matched->p4(), unshiftedObject->p4(), sqrt(dR2bestMatch_Object)));
56  }
57  }
58 
59  auto shiftedPFCandidates = std::make_unique<reco::PFCandidateCollection>();
60 
61  for (reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin();
62  originalPFCandidate != originalPFCandidates->end();
63  ++originalPFCandidate) {
64  double shift = 0.;
65  bool applyShift = false;
66  double dR2bestMatch_PFCandidate = dRDefault;
67  for (std::vector<objectEntryType>::const_iterator object = objects_.begin(); object != objects_.end(); ++object) {
68  if (!object->isValidMatch_)
69  continue;
70  double dR2 = deltaR2(originalPFCandidate->p4(), object->unshiftedObjectP4_);
71  if (dR2 < dR2match_PFCandidate_ && dR2 < dR2bestMatch_PFCandidate) {
72  shift = object->shift_;
73  applyShift = true;
74  dR2bestMatch_PFCandidate = dR2;
75  }
76  }
77 
78  reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4();
79  if (applyShift) {
80  double shiftedPx = (1. + shift) * originalPFCandidate->px();
81  double shiftedPy = (1. + shift) * originalPFCandidate->py();
82  double shiftedPz = (1. + shift) * originalPFCandidate->pz();
83  double mass = originalPFCandidate->mass();
84  double shiftedEn = sqrt(shiftedPx * shiftedPx + shiftedPy * shiftedPy + shiftedPz * shiftedPz + mass * mass);
85  shiftedPFCandidateP4.SetPxPyPzE(shiftedPx, shiftedPy, shiftedPz, shiftedEn);
86  }
87 
88  reco::PFCandidate shiftedPFCandidate(*originalPFCandidate);
89  shiftedPFCandidate.setP4(shiftedPFCandidateP4);
90 
91  shiftedPFCandidates->push_back(shiftedPFCandidate);
92  }
93 
94  evt.put(std::move(shiftedPFCandidates));
95 }
96 
98 
reco::CandidateView
edm::View< Candidate > CandidateView
view of a collection containing candidates
Definition: CandidateFwd.h:23
ShiftedPFCandidateProducerByMatchedObject::objectEntryType
Definition: ShiftedPFCandidateProducerByMatchedObject.h:48
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
ShiftedPFCandidateProducerByMatchedObject::dR2match_PFCandidate_
double dR2match_PFCandidate_
Definition: ShiftedPFCandidateProducerByMatchedObject.h:44
edm::Handle
Definition: AssociativeIterator.h:50
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ShiftedPFCandidateProducerByMatchedObject::~ShiftedPFCandidateProducerByMatchedObject
~ShiftedPFCandidateProducerByMatchedObject() override
Definition: ShiftedPFCandidateProducerByMatchedObject.cc:17
ShiftedPFCandidateProducerByMatchedObject::srcShiftedObjects_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcShiftedObjects_
Definition: ShiftedPFCandidateProducerByMatchedObject.h:41
ShiftedPFCandidateProducerByMatchedObject::dRmatch_PFCandidate_
double dRmatch_PFCandidate_
Definition: ShiftedPFCandidateProducerByMatchedObject.h:43
ShiftedPFCandidateProducerByMatchedObject::dRmatch_Object_
double dRmatch_Object_
Definition: ShiftedPFCandidateProducerByMatchedObject.h:45
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:535
edm::View
Definition: CaloClusterFwd.h:14
ShiftedPFCandidateProducerByMatchedObject.h
edm::ParameterSet
Definition: ParameterSet.h:47
ShiftedPFCandidateProducerByMatchedObject::srcPFCandidates_
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidates_
Definition: ShiftedPFCandidateProducerByMatchedObject.h:39
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EventSetup
Definition: EventSetup.h:58
ShiftedPFCandidateProducerByMatchedObject
Definition: ShiftedPFCandidateProducerByMatchedObject.h:31
looper.cfg
cfg
Definition: looper.py:297
ShiftedPFCandidateProducerByMatchedObject::objects_
std::vector< objectEntryType > objects_
Definition: ShiftedPFCandidateProducerByMatchedObject.h:69
ShiftedPFCandidateProducerByMatchedObject::srcUnshiftedObjects_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcUnshiftedObjects_
Definition: ShiftedPFCandidateProducerByMatchedObject.h:40
ShiftedPFCandidateProducerByMatchedObject::dR2match_Object_
double dR2match_Object_
Definition: ShiftedPFCandidateProducerByMatchedObject.h:46
reco::LeafCandidate::setP4
void setP4(const LorentzVector &p4) final
set 4-momentum
Definition: LeafCandidate.h:158
eostools.move
def move(src, dest)
Definition: eostools.py:511
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
EgHLTOffHistBins_cfi.mass
mass
Definition: EgHLTOffHistBins_cfi.py:34
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
ShiftedPFCandidateProducerByMatchedObject::ShiftedPFCandidateProducerByMatchedObject
ShiftedPFCandidateProducerByMatchedObject(const edm::ParameterSet &)
Definition: ShiftedPFCandidateProducerByMatchedObject.cc:5
reco::Candidate::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
edm::Event
Definition: Event.h:73
dRDefault
const double dRDefault
Definition: ShiftedPFCandidateProducerByMatchedObject.cc:3
edm::InputTag
Definition: InputTag.h:15
ShiftedPFCandidateProducerByMatchedObject::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ShiftedPFCandidateProducerByMatchedObject.cc:21