CMS 3D CMS Logo

ShiftedPFCandidateProducerForPFMVAMEt.cc
Go to the documentation of this file.
1 
26 
27 #include <string>
28 #include <vector>
29 
31 public:
34 
35 private:
37 
38  void produce(edm::Event&, const edm::EventSetup&) override;
39 
41 
45 
48 
51 
52  struct objectEntryType {
54  const reco::Candidate::LorentzVector& unshiftedObjectP4,
55  double dRmatch)
56  : shiftedObjectP4_(shiftedObjectP4),
57  unshiftedObjectP4_(unshiftedObjectP4),
58  dRmatch_(dRmatch),
60  if (unshiftedObjectP4.energy() > 0.) {
61  shift_ = (shiftedObjectP4.energy() / unshiftedObjectP4.energy()) - 1.;
62  isValidMatch_ = true;
63  }
64  }
68  double dRmatch_;
69  double shift_;
71  };
72 
73  std::vector<objectEntryType> objects_;
74 };
75 
76 const double dRDefault = 1000;
77 
79  : moduleLabel_(cfg.getParameter<std::string>("@module_label")),
80  srcPFCandidatesToken_(consumes<reco::PFCandidateCollection>(cfg.getParameter<edm::InputTag>("srcPFCandidates"))),
81  srcUnshiftedObjectsToken_(consumes<CandidateView>(cfg.getParameter<edm::InputTag>("srcUnshiftedObjects"))),
82  srcShiftedObjectsToken_(consumes<CandidateView>(cfg.getParameter<edm::InputTag>("srcShiftedObjects"))) {
83  dRmatch_PFCandidate_ = cfg.getParameter<double>("dRmatch_PFCandidate");
84  dRmatch_Object_ = cfg.exists("dRmatch_Object") ? cfg.getParameter<double>("dRmatch_Object") : 0.1;
85 
88 
89  produces<reco::PFCandidateCollection>();
90 }
91 
93  // nothing to be done yet...
94 }
95 
97  edm::Handle<reco::PFCandidateCollection> originalPFCandidates;
98  evt.getByToken(srcPFCandidatesToken_, originalPFCandidates);
99 
100  edm::Handle<CandidateView> unshiftedObjects;
101  evt.getByToken(srcUnshiftedObjectsToken_, unshiftedObjects);
102 
103  edm::Handle<CandidateView> shiftedObjects;
104  evt.getByToken(srcShiftedObjectsToken_, shiftedObjects);
105 
106  objects_.clear();
107 
108  std::vector<bool> match(shiftedObjects->size(), false);
109  int prevMatch = -1;
110  int cnt = 0;
111 
112  for (CandidateView::const_iterator unshiftedObject = unshiftedObjects->begin();
113  unshiftedObject != unshiftedObjects->end();
114  ++unshiftedObject) {
115  bool isMatched_Object = false;
116  double dR2bestMatch_Object = dRDefault;
117  reco::Candidate::LorentzVector shiftedObjectP4_matched;
118  prevMatch = -1;
119 
120  for (CandidateView::const_iterator shiftedObject = shiftedObjects->begin(); shiftedObject != shiftedObjects->end();
121  ++shiftedObject) {
122  if (match[cnt])
123  continue;
124 
125  double dR2 = deltaR2(unshiftedObject->p4(), shiftedObject->p4());
126  if (dR2 < dR2match_Object_ && dR2 < dR2bestMatch_Object) {
127  shiftedObjectP4_matched = shiftedObject->p4();
128  isMatched_Object = true;
129  dR2bestMatch_Object = dR2;
130 
131  prevMatch = cnt;
132  }
133  cnt++;
134  }
135  if (isMatched_Object) {
136  //Ambiguity removal
137  match[prevMatch] = true;
138  objects_.push_back(objectEntryType(shiftedObjectP4_matched, unshiftedObject->p4(), sqrt(dR2bestMatch_Object)));
139  }
140  }
141 
142  match.assign(objects_.size(), false);
143 
144  auto shiftedPFCandidates = std::make_unique<reco::PFCandidateCollection>();
145 
146  for (reco::PFCandidateCollection::const_iterator originalPFCandidate = originalPFCandidates->begin();
147  originalPFCandidate != originalPFCandidates->end();
148  ++originalPFCandidate) {
149  double shift = 0.;
150  bool applyShift = false;
151  double dR2bestMatch_PFCandidate = dRDefault;
152  prevMatch = -1;
153  cnt = 0;
154 
155  for (std::vector<objectEntryType>::const_iterator object = objects_.begin(); object != objects_.end(); ++object) {
156  if (!object->isValidMatch_)
157  continue;
158  if (match[cnt])
159  continue;
160 
161  double dR2 = deltaR2(originalPFCandidate->p4(), object->unshiftedObjectP4_);
162  if (dR2 < dR2match_PFCandidate_ && dR2 < dR2bestMatch_PFCandidate) {
163  shift = object->shift_;
164  applyShift = true;
165  dR2bestMatch_PFCandidate = dR2;
166 
167  prevMatch = cnt;
168  }
169  cnt++;
170  }
171 
172  reco::Candidate::LorentzVector shiftedPFCandidateP4 = originalPFCandidate->p4();
173  if (applyShift) {
174  //Ambiguity removal
175  match[prevMatch] = true;
176 
177  shiftedPFCandidateP4 *= (1. + shift);
178  }
179 
180  reco::PFCandidate shiftedPFCandidate(*originalPFCandidate);
181  shiftedPFCandidate.setP4(shiftedPFCandidateP4);
182 
183  shiftedPFCandidates->push_back(shiftedPFCandidate);
184  }
185 
186  evt.put(std::move(shiftedPFCandidates));
187 }
188 
190 
ShiftedPFCandidateProducerForPFMVAMEt::ShiftedPFCandidateProducerForPFMVAMEt
ShiftedPFCandidateProducerForPFMVAMEt(const edm::ParameterSet &)
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:78
edm::View::begin
const_iterator begin() const
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
ShiftedPFCandidateProducerForPFMVAMEt::dRmatch_PFCandidate_
double dRmatch_PFCandidate_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:46
funct::false
false
Definition: Factorize.h:29
ShiftedPFCandidateProducerForPFMVAMEt::objectEntryType::shift_
double shift_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:69
PFCandidate.h
dRDefault
const double dRDefault
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:76
edm::EDGetTokenT< reco::PFCandidateCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
EDProducer.h
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
ShiftedPFCandidateProducerForPFMVAMEt::dRmatch_Object_
double dRmatch_Object_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:47
edm::Handle
Definition: AssociativeIterator.h:50
ShiftedPFCandidateProducerForPFMVAMEt::dR2match_PFCandidate_
double dR2match_PFCandidate_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:49
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ShiftedPFCandidateProducerForPFMVAMEt::objectEntryType
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:52
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
ShiftedPFCandidateProducerForPFMVAMEt::moduleLabel_
std::string moduleLabel_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:40
ShiftedPFCandidateProducerForPFMVAMEt::dR2match_Object_
double dR2match_Object_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:50
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
ShiftedPFCandidateProducerForPFMVAMEt::srcShiftedObjectsToken_
edm::EDGetTokenT< CandidateView > srcShiftedObjectsToken_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:44
edm::View::size
size_type size() const
ShiftedPFCandidateProducerForPFMVAMEt::objectEntryType::objectEntryType
objectEntryType(const reco::Candidate::LorentzVector &shiftedObjectP4, const reco::Candidate::LorentzVector &unshiftedObjectP4, double dRmatch)
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:53
ShiftedPFCandidateProducerForPFMVAMEt::objectEntryType::~objectEntryType
~objectEntryType()
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:65
ShiftedPFCandidateProducerForPFMVAMEt::objectEntryType::dRmatch_
double dRmatch_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:68
edm::View
Definition: CaloClusterFwd.h:14
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
deltaR.h
ShiftedPFCandidateProducerForPFMVAMEt
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:30
ShiftedPFCandidateProducerForPFMVAMEt::~ShiftedPFCandidateProducerForPFMVAMEt
~ShiftedPFCandidateProducerForPFMVAMEt() override
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:92
ShiftedPFCandidateProducerForPFMVAMEt::objectEntryType::unshiftedObjectP4_
reco::Candidate::LorentzVector unshiftedObjectP4_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:67
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::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
l1t::PFCandidateCollection
std::vector< l1t::PFCandidate > PFCandidateCollection
Definition: PFCandidate.h:57
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
InputTag.h
looper.cfg
cfg
Definition: looper.py:296
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:96
ShiftedPFCandidateProducerForPFMVAMEt::objectEntryType::isValidMatch_
bool isValidMatch_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:70
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
EventSetup.h
ShiftedPFCandidateProducerForPFMVAMEt::srcPFCandidatesToken_
edm::EDGetTokenT< reco::PFCandidateCollection > srcPFCandidatesToken_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:42
ShiftedPFCandidateProducerForPFMVAMEt::CandidateView
edm::View< reco::Candidate > CandidateView
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:36
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
ShiftedPFCandidateProducerForPFMVAMEt::objectEntryType::shiftedObjectP4_
reco::Candidate::LorentzVector shiftedObjectP4_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:66
Candidate.h
edm::View::end
const_iterator end() const
View.h
ParameterSet.h
reco::Candidate::LorentzVector
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:36
ShiftedPFCandidateProducerForPFMVAMEt::srcUnshiftedObjectsToken_
edm::EDGetTokenT< CandidateView > srcUnshiftedObjectsToken_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:43
ShiftedPFCandidateProducerForPFMVAMEt::objects_
std::vector< objectEntryType > objects_
Definition: ShiftedPFCandidateProducerForPFMVAMEt.cc:73
edm::Event
Definition: Event.h:73
PFCandidateFwd.h