CMS 3D CMS Logo

ShiftedJetProducerByMatchedObject.cc
Go to the documentation of this file.
2 
8 
9 template <typename T>
11  : moduleLabel_(cfg.getParameter<std::string>("@module_label")) {
12  srcJets_ = consumes<JetCollection>(cfg.getParameter<edm::InputTag>("srcJets"));
13  srcUnshiftedObjects_ = consumes<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("srcUnshiftedObjects"));
14  srcShiftedObjects_ = consumes<edm::View<reco::Candidate> >(cfg.getParameter<edm::InputTag>("srcShiftedObjects"));
15 
16  dRmatch_Jet_ = cfg.getParameter<double>("dRmatch_Jet");
17  dRmatch_Object_ = cfg.exists("dRmatch_Object") ? cfg.getParameter<double>("dRmatch_Object") : 0.1;
18 
21 
22  produces<JetCollection>();
23 }
24 
25 template <typename T>
27  // nothing to be done yet...
28 }
29 
30 template <typename T>
32  edm::Handle<JetCollection> originalJets;
33  evt.getByToken(srcJets_, originalJets);
34 
35  edm::Handle<reco::CandidateView> unshiftedObjects;
36  evt.getByToken(srcUnshiftedObjects_, unshiftedObjects);
37 
38  edm::Handle<reco::CandidateView> shiftedObjects;
39  evt.getByToken(srcShiftedObjects_, shiftedObjects);
40 
41  objects_.clear();
42 
43  std::vector<bool> match(shiftedObjects->size(), false);
44  int prevMatch = -1;
45  int cnt = 0;
46 
47  for (reco::CandidateView::const_iterator unshiftedObject = unshiftedObjects->begin();
48  unshiftedObject != unshiftedObjects->end();
49  ++unshiftedObject) {
50  bool isMatched_Object = false;
51  double dR2bestMatch_Object = std::numeric_limits<double>::max();
52  prevMatch = -1;
53  cnt = 0;
54 
55  reco::Candidate::LorentzVector shiftedObjectP4_matched;
56  for (reco::CandidateView::const_iterator shiftedObject = shiftedObjects->begin();
57  shiftedObject != shiftedObjects->end();
58  ++shiftedObject) {
59  if (match[cnt])
60  continue;
61 
62  double dR2 = deltaR2(unshiftedObject->p4(), shiftedObject->p4());
63  if (dR2 < dR2match_Object_ && dR2 < dR2bestMatch_Object) {
64  shiftedObjectP4_matched = shiftedObject->p4();
65  isMatched_Object = true;
66  dR2bestMatch_Object = dR2;
67 
68  prevMatch = cnt;
69  }
70  cnt++;
71  }
72  if (isMatched_Object) {
73  //Ambiguity removal
74  match[prevMatch] = true;
75  objects_.push_back(objectEntryType(shiftedObjectP4_matched, unshiftedObject->p4(), sqrt(dR2bestMatch_Object)));
76  }
77  }
78 
79  match.assign(objects_.size(), false);
80 
81  auto shiftedJets = std::make_unique<JetCollection>();
82 
83  for (typename JetCollection::const_iterator originalJet = originalJets->begin(); originalJet != originalJets->end();
84  ++originalJet) {
85  double shift = 0.;
86  bool applyShift = false;
87  double dR2bestMatch_Jet = std::numeric_limits<double>::max();
88  prevMatch = -1;
89  cnt = 0;
90 
91  for (typename std::vector<objectEntryType>::const_iterator object = objects_.begin(); object != objects_.end();
92  ++object) {
93  if (!object->isValidMatch_)
94  continue;
95  if (match[cnt])
96  continue;
97 
98  double dR2 = deltaR2(originalJet->p4(), object->unshiftedObjectP4_);
99  if (dR2 < dR2match_Jet_ && dR2 < dR2bestMatch_Jet) {
100  shift = object->shift_;
101  applyShift = true;
102  dR2bestMatch_Jet = dR2;
103 
104  prevMatch = cnt;
105  }
106  cnt++;
107  }
108 
109  reco::Candidate::LorentzVector shiftedJetP4 = originalJet->p4();
110  if (applyShift) {
111  //Ambiguity removal
112  match[prevMatch] = true;
113 
114  shiftedJetP4 *= (1. + shift);
115  }
116 
117  T shiftedJet(*originalJet);
118  shiftedJet.setP4(shiftedJetP4);
119 
120  shiftedJets->push_back(shiftedJet);
121  }
122 
123  evt.put(std::move(shiftedJets));
124 }
125 
128 
131 
133 
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.h:38
ShiftedCaloJetProducerByMatchedObject
ShiftedJetProducerByMatchedObjectT< reco::CaloJet > ShiftedCaloJetProducerByMatchedObject
Definition: ShiftedJetProducerByMatchedObject.cc:129
PFCandidate.h
ShiftedJetProducerByMatchedObjectT::ShiftedJetProducerByMatchedObjectT
ShiftedJetProducerByMatchedObjectT(const edm::ParameterSet &)
Definition: ShiftedJetProducerByMatchedObject.cc:10
PFJet.h
edm::Handle
Definition: AssociativeIterator.h:50
MakerMacros.h
ShiftedJetProducerByMatchedObjectT::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ShiftedJetProducerByMatchedObject.cc:31
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ShiftedJetProducerByMatchedObjectT::dRmatch_Jet_
double dRmatch_Jet_
Definition: ShiftedJetProducerByMatchedObject.h:42
ShiftedJetProducerByMatchedObjectT::srcShiftedObjects_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcShiftedObjects_
Definition: ShiftedJetProducerByMatchedObject.h:40
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:531
ShiftedJetProducerByMatchedObjectT::dR2match_Jet_
double dR2match_Jet_
Definition: ShiftedJetProducerByMatchedObject.h:45
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::View::size
size_type size() const
edm::ParameterSet
Definition: ParameterSet.h:47
ShiftedJetProducerByMatchedObjectT::objectEntryType
Definition: ShiftedJetProducerByMatchedObject.h:48
deltaR.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
ShiftedJetProducerByMatchedObjectT::srcUnshiftedObjects_
edm::EDGetTokenT< edm::View< reco::Candidate > > srcUnshiftedObjects_
Definition: ShiftedJetProducerByMatchedObject.h:39
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
ShiftedJetProducerByMatchedObjectT::~ShiftedJetProducerByMatchedObjectT
~ShiftedJetProducerByMatchedObjectT() override
Definition: ShiftedJetProducerByMatchedObject.cc:26
edm::EventSetup
Definition: EventSetup.h:57
ShiftedJetProducerByMatchedObjectT::dRmatch_Object_
double dRmatch_Object_
Definition: ShiftedJetProducerByMatchedObject.h:43
ShiftedJetProducerByMatchedObjectT
Definition: ShiftedJetProducerByMatchedObject.h:26
looper.cfg
cfg
Definition: looper.py:297
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::dR2match_Object_
double dR2match_Object_
Definition: ShiftedJetProducerByMatchedObject.h:46
ShiftedPFJetProducerByMatchedObject
ShiftedJetProducerByMatchedObjectT< reco::PFJet > ShiftedPFJetProducerByMatchedObject
Definition: ShiftedJetProducerByMatchedObject.cc:130
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::View::end
const_iterator end() const
View.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
PFCandidateFwd.h
ShiftedJetProducerByMatchedObject.h