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;
79 
81  : name(pset.getParameter<std::string>("name")),
82  id(pset.getParameter<int>("id")),
83  cut(pset.getParameter<std::string>("sel")),
84  l1cut(""),
85  l1cut_2(""),
86  l2cut(""),
87  l1DR2(-1),
88  l1DR2_2(-1),
89  l2DR2(-1),
90  qualityBits(pset.getParameter<std::string>("qualityBits")),
91  qualityBitsDoc(pset.getParameter<std::string>("qualityBitsDoc")) {
92  if (pset.existsAs<std::string>("l1seed")) {
94  l1DR2 = std::pow(pset.getParameter<double>("l1deltaR"), 2);
95  }
96  if (pset.existsAs<std::string>("l1seed_2")) {
98  l1DR2_2 = std::pow(pset.getParameter<double>("l1deltaR_2"), 2);
99  }
100  if (pset.existsAs<std::string>("l2seed")) {
102  l2DR2 = std::pow(pset.getParameter<double>("l2deltaR"), 2);
103  }
104  }
105 
106  bool match(const pat::TriggerObjectStandAlone &obj) const { return cut(obj); }
107  };
108 
109  std::vector<SelectedObject> sels_;
110 };
111 
112 // ------------ method called to produce the data ------------
115  iEvent.getByToken(src_, src);
116 
117  std::vector<std::pair<const pat::TriggerObjectStandAlone *, const SelectedObject *>> selected;
118  for (const auto &obj : *src) {
119  for (const auto &sel : sels_) {
120  if (sel.match(obj)) {
121  selected.emplace_back(&obj, &sel);
122  break;
123  }
124  }
125  }
126 
127  // Self-cleaning
128  std::map<const pat::TriggerObjectStandAlone *, int> selected_bits;
129  for (unsigned int i = 0; i < selected.size(); ++i) {
130  const auto &obj = *selected[i].first;
131  const auto &sel = *selected[i].second;
132  selected_bits[&obj] = int(sel.qualityBits(obj));
133 
134  for (unsigned int j = 0; j < i; ++j) {
135  const auto &obj2 = *selected[j].first;
136  const auto &sel2 = *selected[j].second;
137  if (sel.id == sel2.id && abs(obj.pt() - obj2.pt()) < 1e-6 && deltaR2(obj, obj2) < 1e-6) {
138  selected_bits[&obj2] |= selected_bits[&obj]; //Keep filters from all the objects
139  selected.erase(selected.begin() + i);
140  i--;
141  }
142  }
143  }
144 
150  iEvent.getByToken(l1EG_, l1EG);
151  iEvent.getByToken(l1Sum_, l1Sum);
152  iEvent.getByToken(l1Jet_, l1Jet);
153  iEvent.getByToken(l1Muon_, l1Muon);
154  iEvent.getByToken(l1Tau_, l1Tau);
155 
156  std::vector<pair<pat::TriggerObjectStandAlone, int>> l1Objects;
157 
158  for (l1t::EGammaBxCollection::const_iterator it = l1EG->begin(0); it != l1EG->end(0); it++) {
159  pat::TriggerObjectStandAlone l1obj(it->p4());
160  l1obj.setCollection("L1EG");
161  l1obj.addTriggerObjectType(trigger::TriggerL1EG);
162  l1Objects.emplace_back(l1obj, it->hwIso());
163  }
164 
165  for (l1t::EtSumBxCollection::const_iterator it = l1Sum->begin(0); it != l1Sum->end(0); it++) {
166  pat::TriggerObjectStandAlone l1obj(it->p4());
167 
168  switch (it->getType()) {
170  l1obj.addTriggerObjectType(trigger::TriggerL1ETM);
171  l1obj.setCollection("L1ETM");
172  break;
173 
175  l1obj.addTriggerObjectType(trigger::TriggerL1ETM);
176  l1obj.setCollection("L1ETMHF");
177  break;
178 
180  l1obj.addTriggerObjectType(trigger::TriggerL1ETT);
181  l1obj.setCollection("L1ETT");
182  break;
183 
185  l1obj.addTriggerObjectType(trigger::TriggerL1ETT);
186  l1obj.setCollection("L1ETEm");
187  break;
188 
190  l1obj.addTriggerObjectType(trigger::TriggerL1HTT);
191  l1obj.setCollection("L1HTT");
192  break;
193 
195  l1obj.addTriggerObjectType(trigger::TriggerL1HTT);
196  l1obj.setCollection("L1HTTHF");
197  break;
198 
200  l1obj.addTriggerObjectType(trigger::TriggerL1HTM);
201  l1obj.setCollection("L1HTM");
202  break;
203 
205  l1obj.addTriggerObjectType(trigger::TriggerL1HTM);
206  l1obj.setCollection("L1HTMHF");
207  break;
208 
209  default:
210  continue;
211  }
212 
213  l1Objects.emplace_back(l1obj, it->hwIso());
214  }
215 
216  for (l1t::JetBxCollection::const_iterator it = l1Jet->begin(0); it != l1Jet->end(0); it++) {
217  pat::TriggerObjectStandAlone l1obj(it->p4());
218  l1obj.setCollection("L1Jet");
219  l1obj.addTriggerObjectType(trigger::TriggerL1Jet);
220  l1Objects.emplace_back(l1obj, it->hwIso());
221  }
222 
223  for (l1t::MuonBxCollection::const_iterator it = l1Muon->begin(0); it != l1Muon->end(0); it++) {
224  pat::TriggerObjectStandAlone l1obj(it->p4());
225  l1obj.setCollection("L1Mu");
226  l1obj.addTriggerObjectType(trigger::TriggerL1Mu);
227  l1obj.setCharge(it->charge());
228  l1Objects.emplace_back(l1obj, it->hwIso());
229  }
230 
231  for (l1t::TauBxCollection::const_iterator it = l1Tau->begin(0); it != l1Tau->end(0); it++) {
232  pat::TriggerObjectStandAlone l1obj(it->p4());
233  l1obj.setCollection("L1Tau");
234  l1obj.addTriggerObjectType(trigger::TriggerL1Tau);
235  l1Objects.emplace_back(l1obj, it->hwIso());
236  }
237 
238  unsigned int nobj = selected.size();
239  std::vector<float> pt(nobj, 0), eta(nobj, 0), phi(nobj, 0), l1pt(nobj, 0), l1pt_2(nobj, 0), l2pt(nobj, 0);
240  std::vector<int> id(nobj, 0), bits(nobj, 0), l1iso(nobj, 0), l1charge(nobj, 0);
241  for (unsigned int i = 0; i < nobj; ++i) {
242  const auto &obj = *selected[i].first;
243  const auto &sel = *selected[i].second;
244  pt[i] = obj.pt();
245  eta[i] = obj.eta();
246  phi[i] = obj.phi();
247  id[i] = sel.id;
248  bits[i] = selected_bits[&obj];
249  if (sel.l1DR2 > 0) {
250  float best = sel.l1DR2;
251  for (const auto &l1obj : l1Objects) {
252  const auto &seed = l1obj.first;
253  float dr2 = deltaR2(seed, obj);
254  if (dr2 < best && sel.l1cut(seed)) {
255  l1pt[i] = seed.pt();
256  l1iso[i] = l1obj.second;
257  l1charge[i] = seed.charge();
258  }
259  }
260  }
261  if (sel.l1DR2_2 > 0) {
262  float best = sel.l1DR2_2;
263  for (const auto &l1obj : l1Objects) {
264  const auto &seed = l1obj.first;
265  float dr2 = deltaR2(seed, obj);
266  if (dr2 < best && sel.l1cut_2(seed)) {
267  l1pt_2[i] = seed.pt();
268  }
269  }
270  }
271  if (sel.l2DR2 > 0) {
272  float best = sel.l2DR2;
273  for (const auto &seed : *src) {
274  float dr2 = deltaR2(seed, obj);
275  if (dr2 < best && sel.l2cut(seed)) {
276  l2pt[i] = seed.pt();
277  }
278  }
279  }
280  }
281 
282  auto tab = std::make_unique<nanoaod::FlatTable>(nobj, name_, false, false);
283  tab->addColumn<int>("id", id, idDoc_, nanoaod::FlatTable::IntColumn);
284  tab->addColumn<float>("pt", pt, "pt", nanoaod::FlatTable::FloatColumn, 12);
285  tab->addColumn<float>("eta", eta, "eta", nanoaod::FlatTable::FloatColumn, 12);
286  tab->addColumn<float>("phi", phi, "phi", nanoaod::FlatTable::FloatColumn, 12);
287  tab->addColumn<float>("l1pt", l1pt, "pt of associated L1 seed", nanoaod::FlatTable::FloatColumn, 8);
288  tab->addColumn<int>("l1iso", l1iso, "iso of associated L1 seed", nanoaod::FlatTable::IntColumn);
289  tab->addColumn<int>("l1charge", l1charge, "charge of associated L1 seed", nanoaod::FlatTable::IntColumn);
290  tab->addColumn<float>("l1pt_2", l1pt_2, "pt of associated secondary L1 seed", nanoaod::FlatTable::FloatColumn, 8);
291  tab->addColumn<float>(
292  "l2pt", l2pt, "pt of associated 'L2' seed (i.e. HLT before tracking/PF)", nanoaod::FlatTable::FloatColumn, 10);
293  tab->addColumn<int>(
294  "filterBits", bits, "extra bits of associated information: " + bitsDoc_, nanoaod::FlatTable::IntColumn);
295  iEvent.put(std::move(tab));
296 }
297 
298 //define this as a plug-in
BXVector< EGamma > EGammaBxCollection
Definition: EGamma.h:10
const_iterator end(int bx) const
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:160
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
enum start value shifted to 81 so as to avoid clashes with PDG codes
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
delete x;
Definition: CaloConfig.h:22
BXVector< Tau > TauBxCollection
Definition: Tau.h:10
StringCutObjectSelector< pat::TriggerObjectStandAlone > l1cut
Definition: HeavyIon.h:7
edm::EDGetTokenT< l1t::JetBxCollection > l1Jet_
std::vector< T >::const_iterator const_iterator
Definition: BXVector.h:18
BXVector< EtSum > EtSumBxCollection
Definition: EtSum.h:10
TriggerObjectTableProducer(const edm::ParameterSet &iConfig)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< std::vector< pat::TriggerObjectStandAlone > > src_
void setCollection(const std::string &collName)
Methods.
Definition: TriggerObject.h:79
StringObjectFunction< pat::TriggerObjectStandAlone > qualityBits
edm::EDGetTokenT< l1t::MuonBxCollection > l1Muon_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
BXVector< Muon > MuonBxCollection
Definition: Muon.h:11
BXVector< Jet > JetBxCollection
Definition: Jet.h:10
StringCutObjectSelector< pat::TriggerObjectStandAlone > l1cut_2
bool match(const pat::TriggerObjectStandAlone &obj) const
HLT enums.
edm::EDGetTokenT< l1t::TauBxCollection > l1Tau_
StringCutObjectSelector< pat::TriggerObjectStandAlone > cut
std::vector< SelectedObject > sels_
edm::EDGetTokenT< l1t::EGammaBxCollection > l1EG_
edm::EDGetTokenT< l1t::EtSumBxCollection > l1Sum_
void produce(edm::Event &, edm::EventSetup const &) override
const_iterator begin(int bx) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
def move(src, dest)
Definition: eostools.py:511
StringCutObjectSelector< pat::TriggerObjectStandAlone > l2cut
Analysis-level trigger object class (stand-alone)