CMS 3D CMS Logo

TriggerObjectTableProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 #include <sstream>
4 
5 // user include files
8 
11 
14 
26 
28 public:
30  : name_(iConfig.getParameter<std::string>("name")),
31  src_(consumes<std::vector<pat::TriggerObjectStandAlone>>(iConfig.getParameter<edm::InputTag>("src"))),
32  l1EG_(consumes<l1t::EGammaBxCollection>(iConfig.getParameter<edm::InputTag>("l1EG"))),
33  l1Sum_(consumes<l1t::EtSumBxCollection>(iConfig.getParameter<edm::InputTag>("l1Sum"))),
34  l1Jet_(consumes<l1t::JetBxCollection>(iConfig.getParameter<edm::InputTag>("l1Jet"))),
35  l1Muon_(consumes<l1t::MuonBxCollection>(iConfig.getParameter<edm::InputTag>("l1Muon"))),
36  l1Tau_(consumes<l1t::TauBxCollection>(iConfig.getParameter<edm::InputTag>("l1Tau"))) {
37  std::vector<edm::ParameterSet> selPSets = iConfig.getParameter<std::vector<edm::ParameterSet>>("selections");
38  sels_.reserve(selPSets.size());
39  std::stringstream idstr, qualitystr;
40  idstr << "ID of the object: ";
41  for (auto &pset : selPSets) {
42  sels_.emplace_back(pset);
43  idstr << sels_.back().id << " = " << sels_.back().name;
44  if (sels_.size() < selPSets.size())
45  idstr << ", ";
46  if (!sels_.back().qualityBitsDoc.empty()) {
47  qualitystr << sels_.back().qualityBitsDoc << " for " << sels_.back().name << "; ";
48  }
49  }
50  idDoc_ = idstr.str();
51  bitsDoc_ = qualitystr.str();
52 
53  produces<nanoaod::FlatTable>();
54  }
55 
57 
58 private:
59  void produce(edm::Event &, edm::EventSetup const &) override;
60 
64 
70 
71  struct SelectedObject {
73  int id;
76  float l1DR2, l1DR2_2, l2DR2;
80 
82  : name(pset.getParameter<std::string>("name")),
83  id(pset.getParameter<int>("id")),
84  cut(pset.getParameter<std::string>("sel")),
85  l1cut(""),
86  l1cut_2(""),
87  l2cut(""),
88  l1DR2(-1),
89  l1DR2_2(-1),
90  l2DR2(-1),
91  skipObjectsNotPassingQualityBits(pset.getParameter<bool>("skipObjectsNotPassingQualityBits")),
92  qualityBits(pset.getParameter<std::string>("qualityBits")),
93  qualityBitsDoc(pset.getParameter<std::string>("qualityBitsDoc")) {
94  if (pset.existsAs<std::string>("l1seed")) {
96  l1DR2 = std::pow(pset.getParameter<double>("l1deltaR"), 2);
97  }
98  if (pset.existsAs<std::string>("l1seed_2")) {
100  l1DR2_2 = std::pow(pset.getParameter<double>("l1deltaR_2"), 2);
101  }
102  if (pset.existsAs<std::string>("l2seed")) {
104  l2DR2 = std::pow(pset.getParameter<double>("l2deltaR"), 2);
105  }
106  }
107 
108  bool match(const pat::TriggerObjectStandAlone &obj) const { return cut(obj); }
109  };
110 
111  std::vector<SelectedObject> sels_;
112 };
113 
114 // ------------ method called to produce the data ------------
117  iEvent.getByToken(src_, src);
118 
119  std::vector<std::pair<const pat::TriggerObjectStandAlone *, const SelectedObject *>> selected;
120  for (const auto &obj : *src) {
121  for (const auto &sel : sels_) {
122  if (sel.match(obj) && (sel.skipObjectsNotPassingQualityBits ? (int(sel.qualityBits(obj)) > 0) : true)) {
123  selected.emplace_back(&obj, &sel);
124  break;
125  }
126  }
127  }
128 
129  // Self-cleaning
130  std::map<const pat::TriggerObjectStandAlone *, int> selected_bits;
131  for (unsigned int i = 0; i < selected.size(); ++i) {
132  const auto &obj = *selected[i].first;
133  const auto &sel = *selected[i].second;
134  selected_bits[&obj] = int(sel.qualityBits(obj));
135 
136  for (unsigned int j = 0; j < i; ++j) {
137  const auto &obj2 = *selected[j].first;
138  const auto &sel2 = *selected[j].second;
139  if (sel.id == sel2.id && abs(obj.pt() - obj2.pt()) < 1e-6 && deltaR2(obj, obj2) < 1e-6) {
140  selected_bits[&obj2] |= selected_bits[&obj]; //Keep filters from all the objects
141  selected.erase(selected.begin() + i);
142  i--;
143  }
144  }
145  }
146 
152  iEvent.getByToken(l1EG_, l1EG);
153  iEvent.getByToken(l1Sum_, l1Sum);
154  iEvent.getByToken(l1Jet_, l1Jet);
155  iEvent.getByToken(l1Muon_, l1Muon);
156  iEvent.getByToken(l1Tau_, l1Tau);
157 
158  std::vector<pair<pat::TriggerObjectStandAlone, int>> l1Objects;
159 
160  for (l1t::EGammaBxCollection::const_iterator it = l1EG->begin(0); it != l1EG->end(0); it++) {
161  pat::TriggerObjectStandAlone l1obj(it->p4());
162  l1obj.setCollection("L1EG");
163  l1obj.addTriggerObjectType(trigger::TriggerL1EG);
164  l1Objects.emplace_back(l1obj, it->hwIso());
165  }
166 
167  for (l1t::EtSumBxCollection::const_iterator it = l1Sum->begin(0); it != l1Sum->end(0); it++) {
168  pat::TriggerObjectStandAlone l1obj(it->p4());
169 
170  switch (it->getType()) {
172  l1obj.addTriggerObjectType(trigger::TriggerL1ETM);
173  l1obj.setCollection("L1ETM");
174  break;
175 
177  l1obj.addTriggerObjectType(trigger::TriggerL1ETM);
178  l1obj.setCollection("L1ETMHF");
179  break;
180 
182  l1obj.addTriggerObjectType(trigger::TriggerL1ETT);
183  l1obj.setCollection("L1ETT");
184  break;
185 
187  l1obj.addTriggerObjectType(trigger::TriggerL1ETT);
188  l1obj.setCollection("L1ETEm");
189  break;
190 
192  l1obj.addTriggerObjectType(trigger::TriggerL1HTT);
193  l1obj.setCollection("L1HTT");
194  break;
195 
197  l1obj.addTriggerObjectType(trigger::TriggerL1HTT);
198  l1obj.setCollection("L1HTTHF");
199  break;
200 
202  l1obj.addTriggerObjectType(trigger::TriggerL1HTM);
203  l1obj.setCollection("L1HTM");
204  break;
205 
207  l1obj.addTriggerObjectType(trigger::TriggerL1HTM);
208  l1obj.setCollection("L1HTMHF");
209  break;
210 
211  default:
212  continue;
213  }
214 
215  l1Objects.emplace_back(l1obj, it->hwIso());
216  }
217 
218  for (l1t::JetBxCollection::const_iterator it = l1Jet->begin(0); it != l1Jet->end(0); it++) {
219  pat::TriggerObjectStandAlone l1obj(it->p4());
220  l1obj.setCollection("L1Jet");
221  l1obj.addTriggerObjectType(trigger::TriggerL1Jet);
222  l1Objects.emplace_back(l1obj, it->hwIso());
223  }
224 
225  for (l1t::MuonBxCollection::const_iterator it = l1Muon->begin(0); it != l1Muon->end(0); it++) {
226  pat::TriggerObjectStandAlone l1obj(it->p4());
227  l1obj.setCollection("L1Mu");
228  l1obj.addTriggerObjectType(trigger::TriggerL1Mu);
229  l1obj.setCharge(it->charge());
230  l1Objects.emplace_back(l1obj, it->hwIso());
231  }
232 
233  for (l1t::TauBxCollection::const_iterator it = l1Tau->begin(0); it != l1Tau->end(0); it++) {
234  pat::TriggerObjectStandAlone l1obj(it->p4());
235  l1obj.setCollection("L1Tau");
236  l1obj.addTriggerObjectType(trigger::TriggerL1Tau);
237  l1Objects.emplace_back(l1obj, it->hwIso());
238  }
239 
240  unsigned int nobj = selected.size();
241  std::vector<float> pt(nobj, 0), eta(nobj, 0), phi(nobj, 0), l1pt(nobj, 0), l1pt_2(nobj, 0), l2pt(nobj, 0);
242  std::vector<int> id(nobj, 0), bits(nobj, 0), l1iso(nobj, 0), l1charge(nobj, 0);
243  for (unsigned int i = 0; i < nobj; ++i) {
244  const auto &obj = *selected[i].first;
245  const auto &sel = *selected[i].second;
246  pt[i] = obj.pt();
247  eta[i] = obj.eta();
248  phi[i] = obj.phi();
249  id[i] = sel.id;
250  bits[i] = selected_bits[&obj];
251  if (sel.l1DR2 > 0) {
252  float best = sel.l1DR2;
253  for (const auto &l1obj : l1Objects) {
254  const auto &seed = l1obj.first;
255  float dr2 = deltaR2(seed, obj);
256  if (dr2 < best && sel.l1cut(seed)) {
257  l1pt[i] = seed.pt();
258  l1iso[i] = l1obj.second;
259  l1charge[i] = seed.charge();
260  }
261  }
262  }
263  if (sel.l1DR2_2 > 0) {
264  float best = sel.l1DR2_2;
265  for (const auto &l1obj : l1Objects) {
266  const auto &seed = l1obj.first;
267  float dr2 = deltaR2(seed, obj);
268  if (dr2 < best && sel.l1cut_2(seed)) {
269  l1pt_2[i] = seed.pt();
270  }
271  }
272  }
273  if (sel.l2DR2 > 0) {
274  float best = sel.l2DR2;
275  for (const auto &seed : *src) {
276  float dr2 = deltaR2(seed, obj);
277  if (dr2 < best && sel.l2cut(seed)) {
278  l2pt[i] = seed.pt();
279  }
280  }
281  }
282  }
283 
284  auto tab = std::make_unique<nanoaod::FlatTable>(nobj, name_, false, false);
285  tab->addColumn<int>("id", id, idDoc_);
286  tab->addColumn<float>("pt", pt, "pt", 12);
287  tab->addColumn<float>("eta", eta, "eta", 12);
288  tab->addColumn<float>("phi", phi, "phi", 12);
289  tab->addColumn<float>("l1pt", l1pt, "pt of associated L1 seed", 8);
290  tab->addColumn<int>("l1iso", l1iso, "iso of associated L1 seed");
291  tab->addColumn<int>("l1charge", l1charge, "charge of associated L1 seed");
292  tab->addColumn<float>("l1pt_2", l1pt_2, "pt of associated secondary L1 seed", 8);
293  tab->addColumn<float>("l2pt", l2pt, "pt of associated 'L2' seed (i.e. HLT before tracking/PF)", 10);
294  tab->addColumn<int>("filterBits", bits, "extra bits of associated information: " + bitsDoc_);
295  iEvent.put(std::move(tab));
296 }
297 
298 //define this as a plug-in
TriggerObjectTableProducer::SelectedObject::cut
StringCutObjectSelector< pat::TriggerObjectStandAlone > cut
Definition: TriggerObjectTableProducer.cc:74
L1Analysis::kMissingHtHF
Definition: L1AnalysisL1UpgradeDataFormat.h:37
triggerObjects_cff.l1Tau
l1Tau
Definition: triggerObjects_cff.py:25
TriggerObjectTableProducer::SelectedObject::l1cut
StringCutObjectSelector< pat::TriggerObjectStandAlone > l1cut
Definition: TriggerObjectTableProducer.cc:75
electrons_cff.bool
bool
Definition: electrons_cff.py:366
trigger::TriggerL1HTM
Definition: TriggerTypeDefs.h:39
mps_fire.i
i
Definition: mps_fire.py:428
TriggerObjectTableProducer::l1EG_
edm::EDGetTokenT< l1t::EGammaBxCollection > l1EG_
Definition: TriggerObjectTableProducer.cc:65
StringObjectFunction< pat::TriggerObjectStandAlone >
TriggerObjectTableProducer::src_
edm::EDGetTokenT< std::vector< pat::TriggerObjectStandAlone > > src_
Definition: TriggerObjectTableProducer.cc:62
TriggerObjectTableProducer::SelectedObject::qualityBits
StringObjectFunction< pat::TriggerObjectStandAlone > qualityBits
Definition: TriggerObjectTableProducer.cc:78
triggerObjects_cff.l1EG
l1EG
Definition: triggerObjects_cff.py:21
l1t::EtSumBxCollection
BXVector< EtSum > EtSumBxCollection
Definition: EtSum.h:10
TriggerObjectTableProducer::SelectedObject::skipObjectsNotPassingQualityBits
bool skipObjectsNotPassingQualityBits
Definition: TriggerObjectTableProducer.cc:77
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
TriggerObjectTableProducer::produce
void produce(edm::Event &, edm::EventSetup const &) override
Definition: TriggerObjectTableProducer.cc:115
pat::TriggerObjectStandAlone
Analysis-level trigger object class (stand-alone)
Definition: TriggerObjectStandAlone.h:32
edm::EDGetTokenT
Definition: EDGetToken.h:33
BXVector::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:18
edm
HLT enums.
Definition: AlignableModifier.h:19
TriggerObjectTableProducer::l1Muon_
edm::EDGetTokenT< l1t::MuonBxCollection > l1Muon_
Definition: TriggerObjectTableProducer.cc:68
TriggerObjectTableProducer::name_
std::string name_
Definition: TriggerObjectTableProducer.cc:61
l1t::MuonBxCollection
BXVector< Muon > MuonBxCollection
Definition: Muon.h:11
Muon.h
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
l1t::JetBxCollection
BXVector< Jet > JetBxCollection
Definition: Jet.h:10
TriggerTypeDefs.h
EDProducer.h
Jet.h
TriggerObjectTableProducer::bitsDoc_
std::string bitsDoc_
Definition: TriggerObjectTableProducer.cc:63
edm::Handle
Definition: AssociativeIterator.h:50
TriggerObjectTableProducer::SelectedObject::l1DR2_2
float l1DR2_2
Definition: TriggerObjectTableProducer.cc:76
fileCollector.seed
seed
Definition: fileCollector.py:127
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TriggerObjectTableProducer::idDoc_
std::string idDoc_
Definition: TriggerObjectTableProducer.cc:63
L1Analysis::kMissingEtHF
Definition: L1AnalysisL1UpgradeDataFormat.h:25
TriggerObjectTableProducer::SelectedObject::qualityBitsDoc
std::string qualityBitsDoc
Definition: TriggerObjectTableProducer.cc:79
EGamma.h
PVValHelper::eta
Definition: PVValidationHelpers.h:70
TriggerObjectTableProducer::TriggerObjectTableProducer
TriggerObjectTableProducer(const edm::ParameterSet &iConfig)
Definition: TriggerObjectTableProducer.cc:29
TriggerObjectTableProducer::SelectedObject
Definition: TriggerObjectTableProducer.cc:71
L1Analysis::kTotalEt
Definition: L1AnalysisL1UpgradeDataFormat.h:17
TriggerObjectTableProducer::l1Sum_
edm::EDGetTokenT< l1t::EtSumBxCollection > l1Sum_
Definition: TriggerObjectTableProducer.cc:66
TriggerObjectTableProducer::SelectedObject::l1DR2
float l1DR2
Definition: TriggerObjectTableProducer.cc:76
triggerObjects_cff.l1Jet
l1Jet
Definition: triggerObjects_cff.py:23
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
l1t::EGammaBxCollection
BXVector< EGamma > EGammaBxCollection
Definition: EGamma.h:10
TriggerObjectTableProducer::SelectedObject::name
std::string name
Definition: TriggerObjectTableProducer.cc:72
edm::ParameterSet
Definition: ParameterSet.h:47
TrackRefitter_38T_cff.src
src
Definition: TrackRefitter_38T_cff.py:24
Event.h
trigger::TriggerL1Tau
Definition: TriggerTypeDefs.h:49
deltaR.h
TriggerObjectTableProducer
Definition: TriggerObjectTableProducer.cc:27
l1t
delete x;
Definition: CaloConfig.h:22
trigger::TriggerL1Mu
enum start value shifted to 81 so as to avoid clashes with PDG codes
Definition: TriggerTypeDefs.h:30
TriggerObjectTableProducer::l1Jet_
edm::EDGetTokenT< l1t::JetBxCollection > l1Jet_
Definition: TriggerObjectTableProducer.cc:67
l1t::TauBxCollection
BXVector< Tau > TauBxCollection
Definition: Tau.h:10
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
trigger::TriggerL1Jet
Definition: TriggerTypeDefs.h:48
TriggerObjectTableProducer::sels_
std::vector< SelectedObject > sels_
Definition: TriggerObjectTableProducer.cc:111
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
L1Analysis::kMissingHt
Definition: L1AnalysisL1UpgradeDataFormat.h:20
edm::stream::EDProducer
Definition: EDProducer.h:36
edm::EventSetup
Definition: EventSetup.h:58
TriggerObjectTableProducer::~TriggerObjectTableProducer
~TriggerObjectTableProducer() override
Definition: TriggerObjectTableProducer.cc:56
pat
Definition: HeavyIon.h:7
TriggerObjectTableProducer::SelectedObject::id
int id
Definition: TriggerObjectTableProducer.cc:73
L1Analysis::kMissingEt
Definition: L1AnalysisL1UpgradeDataFormat.h:19
trigger::TriggerL1EG
Definition: TriggerTypeDefs.h:47
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
L1Analysis::kTotalHtHF
Definition: L1AnalysisL1UpgradeDataFormat.h:34
TriggerObjectTableProducer::l1Tau_
edm::EDGetTokenT< l1t::TauBxCollection > l1Tau_
Definition: TriggerObjectTableProducer.cc:69
FlatTable.h
DDAxes::phi
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
TriggerObjectTableProducer::SelectedObject::l2DR2
float l2DR2
Definition: TriggerObjectTableProducer.cc:76
triggerObjects_cff.l1Sum
l1Sum
Definition: triggerObjects_cff.py:22
TriggerObjectTableProducer::SelectedObject::l1cut_2
StringCutObjectSelector< pat::TriggerObjectStandAlone > l1cut_2
Definition: TriggerObjectTableProducer.cc:75
StringCutObjectSelector.h
trigger::TriggerL1HTT
Definition: TriggerTypeDefs.h:38
HLTMuonOfflineAnalyzer_cfi.deltaR2
deltaR2
Definition: HLTMuonOfflineAnalyzer_cfi.py:105
TriggerObjectTableProducer::SelectedObject::l2cut
StringCutObjectSelector< pat::TriggerObjectStandAlone > l2cut
Definition: TriggerObjectTableProducer.cc:75
Frameworkfwd.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
triggerObjects_cff.l1Muon
l1Muon
Definition: triggerObjects_cff.py:24
TriggerObjectTableProducer::SelectedObject::match
bool match(const pat::TriggerObjectStandAlone &obj) const
Definition: TriggerObjectTableProducer.cc:108
StringCutObjectSelector< pat::TriggerObjectStandAlone >
trigger::TriggerL1ETM
Definition: TriggerTypeDefs.h:36
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TriggerObjectTableProducer::SelectedObject::SelectedObject
SelectedObject(const edm::ParameterSet &pset)
Definition: TriggerObjectTableProducer.cc:81
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
L1Analysis::kTotalEtEm
Definition: L1AnalysisL1UpgradeDataFormat.h:33
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
EtSum.h
EgammaValidation_Wenu_cff.sel
sel
Definition: EgammaValidation_Wenu_cff.py:33
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
L1Analysis::kTotalHt
Definition: L1AnalysisL1UpgradeDataFormat.h:18
edm::Event
Definition: Event.h:73
StringObjectFunction.h
StreamID.h
TriggerObjectStandAlone.h
pat::TriggerObject::setCollection
void setCollection(const std::string &collName)
Methods.
Definition: TriggerObject.h:79
trigger::TriggerL1ETT
Definition: TriggerTypeDefs.h:37
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
Tau.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37