CMS 3D CMS Logo

ShiftedPFCandidateProducerForPFMVAMEt.cc
Go to the documentation of this file.
2 
4 
5 const double dRDefault = 1000;
6 
8  : moduleLabel_(cfg.getParameter<std::string>("@module_label")),
9  srcPFCandidatesToken_(consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("srcPFCandidates"))),
10  srcUnshiftedObjectsToken_(consumes<CandidateView>(cfg.getParameter<edm::InputTag>("srcUnshiftedObjects"))),
11  srcShiftedObjectsToken_(consumes<CandidateView>(cfg.getParameter<edm::InputTag>("srcShiftedObjects"))) {
12  dRmatch_PFCandidate_ = cfg.getParameter<double>("dRmatch_PFCandidate");
13  dRmatch_Object_ = cfg.exists("dRmatch_Object") ? cfg.getParameter<double>("dRmatch_Object") : 0.1;
14 
17 
18  produces<reco::PFCandidateCollection>();
19 }
20 
22  // nothing to be done yet...
23 }
24 
26  edm::Handle<reco::PFCandidateCollection> originalPFCandidates;
27  evt.getByToken(srcPFCandidatesToken_, originalPFCandidates);
28 
29  edm::Handle<CandidateView> unshiftedObjects;
30  evt.getByToken(srcUnshiftedObjectsToken_, unshiftedObjects);
31 
32  edm::Handle<CandidateView> shiftedObjects;
33  evt.getByToken(srcShiftedObjectsToken_, shiftedObjects);
34 
35  objects_.clear();
36 
37  std::vector<bool> match(shiftedObjects->size(), false);
38  int prevMatch = -1;
39  int cnt = 0;
40 
41  for (CandidateView::const_iterator unshiftedObject = unshiftedObjects->begin();
42  unshiftedObject != unshiftedObjects->end();
43  ++unshiftedObject) {
44  bool isMatched_Object = false;
45  double dR2bestMatch_Object = dRDefault;
46  reco::Candidate::LorentzVector shiftedObjectP4_matched;
47  prevMatch = -1;
48 
49  for (CandidateView::const_iterator shiftedObject = shiftedObjects->begin(); shiftedObject != shiftedObjects->end();
50  ++shiftedObject) {
51  if (match[cnt])
52  continue;
53 
54  double dR2 = deltaR2(unshiftedObject->p4(), shiftedObject->p4());
55  if (dR2 < dR2match_Object_ && dR2 < dR2bestMatch_Object) {
56  shiftedObjectP4_matched = shiftedObject->p4();
57  isMatched_Object = true;
58  dR2bestMatch_Object = dR2;
59 
60  prevMatch = cnt;
61  }
62  cnt++;
63  }
64  if (isMatched_Object) {
65  //Ambiguity removal
66  match[prevMatch] = true;
67  objects_.push_back(objectEntryType(shiftedObjectP4_matched, unshiftedObject->p4(), sqrt(dR2bestMatch_Object)));
68  }
69  }
70 
71  match.assign(objects_.size(), false);
72 
73  auto shiftedPFCandidates = std::make_unique<reco::PFCandidateCollection>();
74 
75  for (reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin();
76  originalPFCandidate != originalPFCandidates->end();
77  ++originalPFCandidate) {
78  double shift = 0.;
79  bool applyShift = false;
80  double dR2bestMatch_PFCandidate = dRDefault;
81  prevMatch = -1;
82  cnt = 0;
83 
84  for (std::vector<objectEntryType>::const_iterator object = objects_.begin(); object != objects_.end(); ++object) {
85  if (!object->isValidMatch_)
86  continue;
87  if (match[cnt])
88  continue;
89 
90  double dR2 = deltaR2(originalPFCandidate->p4(), object->unshiftedObjectP4_);
91  if (dR2 < dR2match_PFCandidate_ && dR2 < dR2bestMatch_PFCandidate) {
92  shift = object->shift_;
93  applyShift = true;
94  dR2bestMatch_PFCandidate = dR2;
95 
96  prevMatch = cnt;
97  }
98  cnt++;
99  }
100 
101  reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4();
102  if (applyShift) {
103  //Ambiguity removal
104  match[prevMatch] = true;
105 
106  shiftedPFCandidateP4 *= (1. + shift);
107  }
108 
109  reco::PFCandidate shiftedPFCandidate(*originalPFCandidate);
110  shiftedPFCandidate.setP4(shiftedPFCandidateP4);
111 
112  shiftedPFCandidates->push_back(shiftedPFCandidate);
113  }
114 
115  evt.put(std::move(shiftedPFCandidates));
116 }
117 
119 
ShiftedPFCandidateProducerForPFMVAMEt::ShiftedPFCandidateProducerForPFMVAMEt
ShiftedPFCandidateProducerForPFMVAMEt(const edm::ParameterSet &)
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:7
edm::View::begin
const_iterator begin() const
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
ShiftedPFCandidateProducerForPFMVAMEt::dRmatch_PFCandidate_
double dRmatch_PFCandidate_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.h:49
ShiftedPFCandidateProducerForPFMVAMEt.h
dRDefault
const double dRDefault
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:5
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89353
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
ShiftedPFCandidateProducerForPFMVAMEt::dRmatch_Object_
double dRmatch_Object_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.h:50
edm::Handle
Definition: AssociativeIterator.h:50
ShiftedPFCandidateProducerForPFMVAMEt::dR2match_PFCandidate_
double dR2match_PFCandidate_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.h:52
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ShiftedPFCandidateProducerForPFMVAMEt::objectEntryType
Definition: ShiftedPFCandidateProducerForPFMVAMEt.h:55
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
ShiftedPFCandidateProducerForPFMVAMEt::dR2match_Object_
double dR2match_Object_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.h:53
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
ShiftedPFCandidateProducerForPFMVAMEt::srcShiftedObjectsToken_
edm::EDGetTokenT< CandidateView > srcShiftedObjectsToken_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.h:47
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View::size
size_type size() const
edm::View
Definition: CaloClusterFwd.h:14
edm::ParameterSet
Definition: ParameterSet.h:47
deltaR.h
ShiftedPFCandidateProducerForPFMVAMEt
Definition: ShiftedPFCandidateProducerForPFMVAMEt.h:33
ShiftedPFCandidateProducerForPFMVAMEt::~ShiftedPFCandidateProducerForPFMVAMEt
~ShiftedPFCandidateProducerForPFMVAMEt() override
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:21
match
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
edm::EventSetup
Definition: EventSetup.h:57
l1t::PFCandidateCollection
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
looper.cfg
cfg
Definition: looper.py:297
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
std
Definition: JetResolutionObject.h:76
ShiftedPFCandidateProducerForPFMVAMEt::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:25
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
ShiftedPFCandidateProducerForPFMVAMEt::srcPFCandidatesToken_
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidatesToken_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.h:45
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
reco::PFCandidate
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:41
edm::View::end
const_iterator end() const
reco::Candidate::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
ShiftedPFCandidateProducerForPFMVAMEt::srcUnshiftedObjectsToken_
edm::EDGetTokenT< CandidateView > srcUnshiftedObjectsToken_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.h:46
ShiftedPFCandidateProducerForPFMVAMEt::objects_
std::vector< objectEntryType > objects_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.h:76
edm::Event
Definition: Event.h:73