CMS 3D CMS Logo

JetDeltaRValueMapProducer.cc
Go to the documentation of this file.
1 /* \class JetDeltaRValueMapProducer
2  *
3  * Associates jets using delta-R matching, and writes out
4  * a valuemap of single float variables based on a StringObjectFunction.
5  * This is used for miniAOD.
6  *
7  * \author: Sal Rappoccio
8  *
9  *
10  * for more details about the cut syntax, see the documentation
11  * page below:
12  *
13  * https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePhysicsCutParser
14  *
15  *
16  */
17 
23 
29 
30 template <class T, class C = T>
32 public:
34 
36  : srcToken_(consumes<typename edm::View<T> >(params.getParameter<edm::InputTag>("src"))),
37  matchedToken_(consumes<typename edm::View<C> >(params.getParameter<edm::InputTag>("matched"))),
38  distMax_(params.getParameter<double>("distMax")),
39  value_(params.existsAs<std::string>("value") ? params.getParameter<std::string>("value") : ""),
40  values_(params.existsAs<std::vector<std::string> >("values")
41  ? params.getParameter<std::vector<std::string> >("values")
42  : std::vector<std::string>()),
43  valueLabels_(params.existsAs<std::vector<std::string> >("valueLabels")
44  ? params.getParameter<std::vector<std::string> >("valueLabels")
45  : std::vector<std::string>()),
46  lazyParser_(params.existsAs<bool>("lazyParser") ? params.getParameter<bool>("lazyParser") : false),
48  if (!value_.empty()) {
49  evaluationMap_.insert(std::make_pair(
51  produces<JetValueMap>();
52  }
53 
54  if (!valueLabels_.empty() || !values_.empty()) {
55  if (valueLabels_.size() == values_.size()) {
56  multiValue_ = true;
57  for (size_t i = 0; i < valueLabels_.size(); ++i) {
58  evaluationMap_.insert(std::make_pair(
59  valueLabels_[i],
61  produces<JetValueMap>(valueLabels_[i]);
62  }
63  } else
64  edm::LogWarning("ValueLabelMismatch")
65  << "The number of value labels does not match the number of values. Values will not be evaluated.";
66  }
67  }
68 
70 
71 private:
72  void produce(edm::Event& iEvent, const edm::EventSetup& iSetup) override {
74  iEvent.getByToken(srcToken_, h_jets1);
76  iEvent.getByToken(matchedToken_, h_jets2);
77 
78  std::vector<float> values(h_jets1->size(), -99999);
79  std::map<std::string, std::vector<float> > valuesMap;
80  if (multiValue_) {
81  for (size_t i = 0; i < valueLabels_.size(); ++i)
82  valuesMap.insert(std::make_pair(valueLabels_[i], std::vector<float>(h_jets1->size(), -99999)));
83  }
84  std::vector<bool> jets1_locks(h_jets1->size(), false);
85 
86  for (typename edm::View<C>::const_iterator ibegin = h_jets2->begin(), iend = h_jets2->end(), ijet = ibegin;
87  ijet != iend;
88  ++ijet) {
89  float matched_dR2 = 1e9;
90  int matched_index = -1;
91 
92  for (typename edm::View<T>::const_iterator jbegin = h_jets1->begin(), jend = h_jets1->end(), jjet = jbegin;
93  jjet != jend;
94  ++jjet) {
95  int index = jjet - jbegin;
96 
97  if (jets1_locks.at(index))
98  continue; // skip jets that have already been matched
99 
100  float temp_dR2 = reco::deltaR2(ijet->eta(), ijet->phi(), jjet->eta(), jjet->phi());
101  if (temp_dR2 < matched_dR2) {
102  matched_dR2 = temp_dR2;
103  matched_index = index;
104  }
105  } // end loop over src jets
106 
107  if (matched_index >= 0) {
108  if (matched_dR2 > distMax_ * distMax_)
109  edm::LogInfo("MatchedJetsFarApart") << "Matched jets separated by dR greater than distMax=" << distMax_;
110  else {
111  jets1_locks.at(matched_index) = true;
112  if (!value_.empty())
113  values.at(matched_index) = (*(evaluationMap_.at(value_)))(*ijet);
114  if (multiValue_) {
115  for (size_t i = 0; i < valueLabels_.size(); ++i)
116  valuesMap.at(valueLabels_[i]).at(matched_index) = (*(evaluationMap_.at(valueLabels_[i])))(*ijet);
117  }
118  }
119  }
120  } // end loop over matched jets
121 
122  if (!value_.empty()) {
123  std::unique_ptr<JetValueMap> jetValueMap(new JetValueMap());
124 
125  JetValueMap::Filler filler(*jetValueMap);
126  filler.insert(h_jets1, values.begin(), values.end());
127  filler.fill();
128 
129  // put in Event
130  iEvent.put(std::move(jetValueMap));
131  }
132  if (multiValue_) {
133  for (size_t i = 0; i < valueLabels_.size(); ++i) {
134  std::unique_ptr<JetValueMap> jetValueMap(new JetValueMap());
135 
136  JetValueMap::Filler filler(*jetValueMap);
137  filler.insert(h_jets1, valuesMap.at(valueLabels_[i]).begin(), valuesMap.at(valueLabels_[i]).end());
138  filler.fill();
139 
140  // put in Event
141  iEvent.put(std::move(jetValueMap), valueLabels_[i]);
142  }
143  }
144  }
145 
148  const double distMax_;
150  const std::vector<std::string> values_;
151  const std::vector<std::string> valueLabels_;
152  const bool lazyParser_;
154  std::map<std::string, std::unique_ptr<const StringObjectFunction<C> > > evaluationMap_;
155 };
156 
160 
CaloJet.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
StringObjectFunction
Definition: StringObjectFunction.h:16
JetDeltaRValueMapProducer::distMax_
const double distMax_
Definition: JetDeltaRValueMapProducer.cc:148
funct::false
false
Definition: Factorize.h:34
RecoJetToPatJetDeltaRValueMapProducer
JetDeltaRValueMapProducer< reco::Jet, pat::Jet > RecoJetToPatJetDeltaRValueMapProducer
Definition: JetDeltaRValueMapProducer.cc:158
sistrip::View
View
Definition: ConstantsForView.h:26
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm::EDGetTokenT
Definition: EDGetToken.h:33
JetDeltaRValueMapProducer::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: JetDeltaRValueMapProducer.cc:72
edm
HLT enums.
Definition: AlignableModifier.h:19
PFJet.h
edm::LogInfo
Definition: MessageLogger.h:254
PatJetDeltaRValueMapProducer
JetDeltaRValueMapProducer< pat::Jet > PatJetDeltaRValueMapProducer
Definition: JetDeltaRValueMapProducer.cc:159
EDProducer.h
Jet.h
JetDeltaRValueMapProducer::JetValueMap
edm::ValueMap< float > JetValueMap
Definition: JetDeltaRValueMapProducer.cc:33
JetDeltaRValueMapProducer::value_
const std::string value_
Definition: JetDeltaRValueMapProducer.cc:149
JetDeltaRValueMapProducer::valueLabels_
const std::vector< std::string > valueLabels_
Definition: JetDeltaRValueMapProducer.cc:151
edm::Handle
Definition: AssociativeIterator.h:50
deltaR.h
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
JetDeltaRValueMapProducer::evaluationMap_
std::map< std::string, std::unique_ptr< const StringObjectFunction< C > > > evaluationMap_
Definition: JetDeltaRValueMapProducer.cc:154
JetDeltaRValueMapProducer::JetDeltaRValueMapProducer
JetDeltaRValueMapProducer(edm::ParameterSet const &params)
Definition: JetDeltaRValueMapProducer.cc:35
JetDeltaRValueMapProducer::srcToken_
const edm::EDGetTokenT< typename edm::View< T > > srcToken_
Definition: JetDeltaRValueMapProducer.cc:146
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
JetDeltaRValueMapProducer::matchedToken_
const edm::EDGetTokenT< typename edm::View< C > > matchedToken_
Definition: JetDeltaRValueMapProducer.cc:147
edm::LogWarning
Definition: MessageLogger.h:141
edm::View
Definition: CaloClusterFwd.h:14
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
reco::deltaR2
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
JetDeltaRValueMapProducer::values_
const std::vector< std::string > values_
Definition: JetDeltaRValueMapProducer.cc:150
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::stream::EDProducer
Definition: EDProducer.h:38
JetDeltaRValueMapProducer::multiValue_
bool multiValue_
Definition: JetDeltaRValueMapProducer.cc:153
edm::EventSetup
Definition: EventSetup.h:57
Jet.h
ValueMap.h
RecoJetDeltaRValueMapProducer
JetDeltaRValueMapProducer< reco::Jet > RecoJetDeltaRValueMapProducer
Definition: JetDeltaRValueMapProducer.cc:157
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
JetDeltaRValueMapProducer::lazyParser_
const bool lazyParser_
Definition: JetDeltaRValueMapProducer.cc:152
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
gen::C
C
Definition: PomwigHadronizer.cc:76
T
long double T
Definition: Basic3DVectorLD.h:48
edm::ValueMap< float >
JetDeltaRValueMapProducer::~JetDeltaRValueMapProducer
~JetDeltaRValueMapProducer() override
Definition: JetDeltaRValueMapProducer.cc:69
JetDeltaRValueMapProducer
Definition: JetDeltaRValueMapProducer.cc:31
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
edm::helper::Filler
Definition: ValueMap.h:22
edm::Event
Definition: Event.h:73
StringObjectFunction.h