CMS 3D CMS Logo

ShiftedJetProducerByMatchedObject.cc
Go to the documentation of this file.
1 
22 
23 #include <string>
24 #include <vector>
25 
26 template <typename T>
28  typedef std::vector<T> JetCollection;
29 
30 public:
33 
34 private:
35  void produce(edm::Event&, const edm::EventSetup&) override;
36 
38 
42 
43  double dRmatch_Jet_;
45 
46  double dR2match_Jet_;
48 
49  struct objectEntryType {
51  const reco::Candidate::LorentzVector& unshiftedObjectP4,
52  double dRmatch)
53  : shiftedObjectP4_(shiftedObjectP4),
54  unshiftedObjectP4_(unshiftedObjectP4),
55  dRmatch_(dRmatch),
57  if (unshiftedObjectP4.energy() > 0.) {
58  shift_ = (shiftedObjectP4.energy() / unshiftedObjectP4.energy()) - 1.;
59  isValidMatch_ = true;
60  }
61  }
65  double shift_;
66  double dRmatch_;
68  };
69 
70  std::vector<objectEntryType> objects_;
71 };
72 
73 template <typename T>
75  : moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
76  srcJets_ = consumes<JetCollection>(cfg.getParameter<edm::InputTag>("srcJets"));
77  srcUnshiftedObjects_ = consumes<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("srcUnshiftedObjects"));
78  srcShiftedObjects_ = consumes<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("srcShiftedObjects"));
79 
80  dRmatch_Jet_ = cfg.getParameter<double>("dRmatch_Jet");
81  dRmatch_Object_ = cfg.exists("dRmatch_Object") ? cfg.getParameter<double>("dRmatch_Object") : 0.1;
82 
85 
86  produces<JetCollection>();
87 }
88 
89 template <typename T>
91  // nothing to be done yet...
92 }
93 
94 template <typename T>
96  edm::Handle<JetCollection> originalJets;
97  evt.getByToken(srcJets_, originalJets);
98 
99  edm::Handle<reco::CandidateView> unshiftedObjects;
100  evt.getByToken(srcUnshiftedObjects_, unshiftedObjects);
101 
102  edm::Handle<reco::CandidateView> shiftedObjects;
103  evt.getByToken(srcShiftedObjects_, shiftedObjects);
104 
105  objects_.clear();
106 
107  std::vector<bool> match(shiftedObjects->size(), false);
108  int prevMatch = -1;
109  int cnt = 0;
110 
111  for (reco::CandidateView::const_iterator unshiftedObject = unshiftedObjects->begin();
112  unshiftedObject != unshiftedObjects->end();
113  ++unshiftedObject) {
114  bool isMatched_Object = false;
115  double dR2bestMatch_Object = std::numeric_limits<double>::max();
116  prevMatch = -1;
117  cnt = 0;
118 
119  reco::Candidate::LorentzVector shiftedObjectP4_matched;
120  for (reco::CandidateView::const_iterator shiftedObject = shiftedObjects->begin();
121  shiftedObject != shiftedObjects->end();
122  ++shiftedObject) {
123  if (match[cnt])
124  continue;
125 
126  double dR2 = deltaR2(unshiftedObject->p4(), shiftedObject->p4());
127  if (dR2 < dR2match_Object_ && dR2 < dR2bestMatch_Object) {
128  shiftedObjectP4_matched = shiftedObject->p4();
129  isMatched_Object = true;
130  dR2bestMatch_Object = dR2;
131 
132  prevMatch = cnt;
133  }
134  cnt++;
135  }
136  if (isMatched_Object) {
137  //Ambiguity removal
138  match[prevMatch] = true;
139  objects_.push_back(objectEntryType(shiftedObjectP4_matched, unshiftedObject->p4(), sqrt(dR2bestMatch_Object)));
140  }
141  }
142 
143  match.assign(objects_.size(), false);
144 
145  auto shiftedJets = std::make_unique<JetCollection>();
146 
147  for (typename JetCollection::const_iterator originalJet = originalJets->begin(); originalJet != originalJets->end();
148  ++originalJet) {
149  double shift = 0.;
150  bool applyShift = false;
151  double dR2bestMatch_Jet = std::numeric_limits<double>::max();
152  prevMatch = -1;
153  cnt = 0;
154 
155  for (typename std::vector<objectEntryType>::const_iterator object = objects_.begin(); object != objects_.end();
156  ++object) {
157  if (!object->isValidMatch_)
158  continue;
159  if (match[cnt])
160  continue;
161 
162  double dR2 = deltaR2(originalJet->p4(), object->unshiftedObjectP4_);
163  if (dR2 < dR2match_Jet_ && dR2 < dR2bestMatch_Jet) {
164  shift = object->shift_;
165  applyShift = true;
166  dR2bestMatch_Jet = dR2;
167 
168  prevMatch = cnt;
169  }
170  cnt++;
171  }
172 
173  reco::Candidate::LorentzVector shiftedJetP4 = originalJet->p4();
174  if (applyShift) {
175  //Ambiguity removal
176  match[prevMatch] = true;
177 
178  shiftedJetP4 *= (1. + shift);
179  }
180 
181  T shiftedJet(*originalJet);
182  shiftedJet.setP4(shiftedJetP4);
183 
184  shiftedJets->push_back(shiftedJet);
185  }
186 
187  evt.put(std::move(shiftedJets));
188 }
189 
192 
195 
197 
edm::View::begin
const_iterator begin() const
Handle.h
CaloJet.h
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
ShiftedJetProducerByMatchedObjectT::srcJets_
edm::EDGetTokenT< JetCollection > srcJets_
Definition: ShiftedJetProducerByMatchedObject.cc:39
funct::false
false
Definition: Factorize.h:29
ShiftedCaloJetProducerByMatchedObject
ShiftedJetProducerByMatchedObjectT< reco::CaloJet > ShiftedCaloJetProducerByMatchedObject
Definition: ShiftedJetProducerByMatchedObject.cc:193
PFCandidate.h
ShiftedJetProducerByMatchedObjectT::ShiftedJetProducerByMatchedObjectT
ShiftedJetProducerByMatchedObjectT(const edm::ParameterSet &)
Definition: ShiftedJetProducerByMatchedObject.cc:74
ShiftedJetProducerByMatchedObjectT::objectEntryType::shiftedObjectP4_
reco::Candidate::LorentzVector shiftedObjectP4_
Definition: ShiftedJetProducerByMatchedObject.cc:63
edm::EDGetTokenT< JetCollection >
PFJet.h
EDProducer.h
ShiftedJetProducerByMatchedObjectT::objectEntryType::unshiftedObjectP4_
reco::Candidate::LorentzVector unshiftedObjectP4_
Definition: ShiftedJetProducerByMatchedObject.cc:64
edm::Handle
Definition: AssociativeIterator.h:50
CandidateFwd.h
MakerMacros.h
ShiftedJetProducerByMatchedObjectT::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ShiftedJetProducerByMatchedObject.cc:95
ShiftedJetProducerByMatchedObjectT::objectEntryType::isValidMatch_
bool isValidMatch_
Definition: ShiftedJetProducerByMatchedObject.cc:67
ShiftedJetProducerByMatchedObjectT::objectEntryType::~objectEntryType
~objectEntryType()
Definition: ShiftedJetProducerByMatchedObject.cc:62
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ShiftedJetProducerByMatchedObjectT::dRmatch_Jet_
double dRmatch_Jet_
Definition: ShiftedJetProducerByMatchedObject.cc:43
ShiftedJetProducerByMatchedObjectT::srcShiftedObjects_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcShiftedObjects_
Definition: ShiftedJetProducerByMatchedObject.cc:41
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
ShiftedJetProducerByMatchedObjectT::JetCollection
std::vector< T > JetCollection
Definition: ShiftedJetProducerByMatchedObject.cc:28
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
ShiftedJetProducerByMatchedObjectT::dR2match_Jet_
double dR2match_Jet_
Definition: ShiftedJetProducerByMatchedObject.cc:46
edm::View::size
size_type size() const
edm::ParameterSet
Definition: ParameterSet.h:47
ShiftedJetProducerByMatchedObjectT::objectEntryType
Definition: ShiftedJetProducerByMatchedObject.cc:49
Event.h
deltaR.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
ShiftedJetProducerByMatchedObjectT::srcUnshiftedObjects_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcUnshiftedObjects_
Definition: ShiftedJetProducerByMatchedObject.cc:40
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
ShiftedJetProducerByMatchedObjectT::~ShiftedJetProducerByMatchedObjectT
~ShiftedJetProducerByMatchedObjectT() override
Definition: ShiftedJetProducerByMatchedObject.cc:90
edm::EventSetup
Definition: EventSetup.h:58
ShiftedJetProducerByMatchedObjectT::dRmatch_Object_
double dRmatch_Object_
Definition: ShiftedJetProducerByMatchedObject.cc:44
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ShiftedJetProducerByMatchedObjectT
Definition: ShiftedJetProducerByMatchedObject.cc:27
InputTag.h
looper.cfg
cfg
Definition: looper.py:296
ShiftedJetProducerByMatchedObjectT::objects_
std::vector< objectEntryType > objects_
Definition: ShiftedJetProducerByMatchedObject.cc:70
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::shift
static unsigned const int shift
Definition: LuminosityBlockID.cc:7
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
T
long double T
Definition: Basic3DVectorLD.h:48
ShiftedJetProducerByMatchedObjectT::objectEntryType::shift_
double shift_
Definition: ShiftedJetProducerByMatchedObject.cc:65
ShiftedJetProducerByMatchedObjectT::dR2match_Object_
double dR2match_Object_
Definition: ShiftedJetProducerByMatchedObject.cc:47
ShiftedPFJetProducerByMatchedObject
ShiftedJetProducerByMatchedObjectT< reco::PFJet > ShiftedPFJetProducerByMatchedObject
Definition: ShiftedJetProducerByMatchedObject.cc:194
EventSetup.h
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
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
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
ShiftedJetProducerByMatchedObjectT::objectEntryType::objectEntryType
objectEntryType(const reco::Candidate::LorentzVector &shiftedObjectP4, const reco::Candidate::LorentzVector &unshiftedObjectP4, double dRmatch)
Definition: ShiftedJetProducerByMatchedObject.cc:50
ShiftedJetProducerByMatchedObjectT::moduleLabel_
std::string moduleLabel_
Definition: ShiftedJetProducerByMatchedObject.cc:37
PFCandidateFwd.h
ShiftedJetProducerByMatchedObjectT::objectEntryType::dRmatch_
double dRmatch_
Definition: ShiftedJetProducerByMatchedObject.cc:66