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 
20  dR2match_Object_ = dRmatch_Object_ * dRmatch_Object_;
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 
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
ShiftedJetProducerByMatchedObjectT< reco::CaloJet > ShiftedCaloJetProducerByMatchedObject
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void produce(edm::Event &, const edm::EventSetup &) override
bool exists(std::string const &parameterName) const
checks if a parameter exists
size_type size() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const_iterator begin() const
T sqrt(T t)
Definition: SSEVec.h:19
edm::EDGetTokenT< edm::View< reco::Candidate > > srcShiftedObjects_
ShiftedJetProducerByMatchedObjectT< reco::PFJet > ShiftedPFJetProducerByMatchedObject
edm::EDGetTokenT< edm::View< reco::Candidate > > srcUnshiftedObjects_
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
static unsigned int const shift
const_iterator end() const
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
long double T
def move(src, dest)
Definition: eostools.py:511
ShiftedJetProducerByMatchedObjectT(const edm::ParameterSet &)