CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TriggerSummaryProducerAOD.cc
Go to the documentation of this file.
1 
14 
16 
17 #include<string>
18 
35 
41 
47 
52 
53 #include <algorithm>
54 #include <typeinfo>
55 
56 
57 //
58 // constructors and destructor
59 //
61  pn_(ps.getParameter<std::string>("processName")),
62  selector_(edm::ProcessNameSelector(pn_)),
63  tns_(),
64  filterTagsEvent_(pn_!="*"),
65  filterTagsGlobal_(pn_!="*"),
66  collectionTagsEvent_(pn_!="*"),
67  collectionTagsGlobal_(pn_!="*"),
68  toc_(),
69  tags_(),
70  offset_(),
71  fobs_(),
72  keys_(),
73  ids_(),
74  maskFilters_()
75 {
76  if (pn_=="@") {
77  // use tns
79  // get tns pointer
81  if (tns_!=0) {
83  } else {
84  edm::LogError("TriggerSummaryProducerAOD") << "HLT Error: TriggerNamesService pointer = 0!";
85  pn_="*";
86  }
87  } else {
88  edm::LogError("TriggerSummaryProducerAOD") << "HLT Error: TriggerNamesService not available!";
89  pn_="*";
90  }
96  }
97  LogDebug("TriggerSummaryProducerAOD") << "Using process name: '" << pn_ <<"'";
98 
99  filterTagsGlobal_.clear();
100  collectionTagsGlobal_.clear();
101 
102  produces<trigger::TriggerEvent>();
103 
104 }
105 
107 {
108 }
109 
110 //
111 // member functions
112 //
113 
114 namespace {
115  inline void
116  tokenizeTag(const std::string& tag, std::string& label, std::string& instance, std::string& process){
117 
118  using std::string;
119 
120  const char token(':');
121  const string empty;
122 
123  label=tag;
124  const string::size_type i1(label.find(token));
125  if (i1==string::npos) {
126  instance=empty;
127  process=empty;
128  } else {
129  instance=label.substr(i1+1);
130  label.resize(i1);
131  const string::size_type i2(instance.find(token));
132  if (i2==string::npos) {
133  process=empty;
134  } else {
135  process=instance.substr(i2+1);
136  instance.resize(i2);
137  }
138  }
139  }
140 }
141 
142 // ------------ method called to produce the data ------------
143 void
145 {
146  using namespace std;
147  using namespace edm;
148  using namespace reco;
149  using namespace l1extra;
150  using namespace trigger;
151 
154  fobs_.clear();
155  iEvent.getMany(selector_,fobs_);
156  const unsigned int nfob(fobs_.size());
157  LogTrace("TriggerSummaryProducerAOD") << "Number of filter objects found: " << nfob;
158 
159  string tagLabel,tagInstance,tagProcess;
160 
166  maskFilters_.clear();
167  maskFilters_.resize(nfob);
168  filterTagsEvent_.clear();
169  collectionTagsEvent_.clear();
170  unsigned int nf(0);
171  for (unsigned int ifob=0; ifob!=nfob; ++ifob) {
172  maskFilters_[ifob]=false;
173  const vector<string>& collectionTags_(fobs_[ifob]->getCollectionTagsAsStrings());
174  const unsigned int ncol(collectionTags_.size());
175  if (ncol>0) {
176  nf++;
177  maskFilters_[ifob]=true;
178  const string& label (fobs_[ifob].provenance()->moduleLabel());
179  const string& instance (fobs_[ifob].provenance()->productInstanceName());
180  const string& process (fobs_[ifob].provenance()->processName());
181  filterTagsEvent_.insert(InputTag(label,instance,process));
182  for (unsigned int icol=0; icol!=ncol; ++icol) {
183  // overwrite process name (usually not set)
184  tokenizeTag(collectionTags_[icol],tagLabel,tagInstance,tagProcess);
185  collectionTagsEvent_.insert(InputTag(tagLabel,tagInstance,pn_));
186  }
187  }
188  }
190  if (filterTagsEvent_.size()!=nf) {
191  LogError("TriggerSummaryProducerAOD")
192  << "Mismatch in number of filter tags: "
193  << filterTagsEvent_.size() << "!=" << nf ;
194  }
195 
199 
201  if (isDebugEnabled()) {
202 
204  const unsigned int nc(collectionTagsEvent_.size());
205  LogTrace("TriggerSummaryProducerAOD") << "Number of unique collections requested " << nc;
206  const InputTagSet::const_iterator cb(collectionTagsEvent_.begin());
207  const InputTagSet::const_iterator ce(collectionTagsEvent_.end());
208  for ( InputTagSet::const_iterator ci=cb; ci!=ce; ++ci) {
209  LogTrace("TriggerSummaryProducerAOD") << distance(cb,ci) << " " << ci->encode();
210  }
211  const unsigned int nf(filterTagsEvent_.size());
212  LogTrace("TriggerSummaryProducerAOD") << "Number of unique filters requested " << nf;
213  const InputTagSet::const_iterator fb(filterTagsEvent_.begin());
214  const InputTagSet::const_iterator fe(filterTagsEvent_.end());
215  for ( InputTagSet::const_iterator fi=fb; fi!=fe; ++fi) {
216  LogTrace("TriggerSummaryProducerAOD") << distance(fb,fi) << " " << fi->encode();
217  }
218 
219  }
220 
226  toc_.clear();
227  tags_.clear();
228  keys_.clear();
229  offset_.clear();
230  fillTriggerObjectCollections< RecoEcalCandidateCollection>(iEvent);
231  fillTriggerObjectCollections< ElectronCollection>(iEvent);
232  fillTriggerObjectCollections< RecoChargedCandidateCollection>(iEvent);
233  fillTriggerObjectCollections< CaloJetCollection>(iEvent);
234  fillTriggerObjectCollections< CompositeCandidateCollection>(iEvent);
235  fillTriggerObjectCollections< METCollection>(iEvent);
236  fillTriggerObjectCollections< CaloMETCollection>(iEvent);
237  fillTriggerObjectCollections<IsolatedPixelTrackCandidateCollection>(iEvent);
239  fillTriggerObjectCollections< L1EmParticleCollection>(iEvent);
240  fillTriggerObjectCollections< L1MuonParticleCollection>(iEvent);
241  fillTriggerObjectCollections< L1JetParticleCollection>(iEvent);
242  fillTriggerObjectCollections< L1EtMissParticleCollection>(iEvent);
243  fillTriggerObjectCollections< L1HFRingsCollection>(iEvent);
245  fillTriggerObjectCollections< PFJetCollection>(iEvent);
246  fillTriggerObjectCollections< PFTauCollection>(iEvent);
248  const unsigned int nk(tags_.size());
249  LogDebug("TriggerSummaryProducerAOD") << "Number of collections found: " << nk;
250  const unsigned int no(toc_.size());
251  LogDebug("TriggerSummaryProducerAOD") << "Number of physics objects found: " << no;
252 
255  auto_ptr<TriggerEvent> product(new TriggerEvent(pn_,nk,no,nf));
256 
258  product->addCollections(tags_,keys_);
259  product->addObjects(toc_);
260 
262  for (unsigned int ifob=0; ifob!=nfob; ++ifob) {
263  if (maskFilters_[ifob]) {
264  const string& label (fobs_[ifob].provenance()->moduleLabel());
265  const string& instance (fobs_[ifob].provenance()->productInstanceName());
266  const string& process (fobs_[ifob].provenance()->processName());
267  const edm::InputTag filterTag(label,instance,process);
268  ids_.clear();
269  keys_.clear();
270  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->photonIds() ,fobs_[ifob]->photonRefs());
271  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->electronIds() ,fobs_[ifob]->electronRefs());
272  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->muonIds() ,fobs_[ifob]->muonRefs());
273  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->jetIds() ,fobs_[ifob]->jetRefs());
274  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->compositeIds(),fobs_[ifob]->compositeRefs());
275  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->basemetIds() ,fobs_[ifob]->basemetRefs());
276  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->calometIds() ,fobs_[ifob]->calometRefs());
277  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->pixtrackIds() ,fobs_[ifob]->pixtrackRefs());
278  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1emIds() ,fobs_[ifob]->l1emRefs());
279  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1muonIds() ,fobs_[ifob]->l1muonRefs());
280  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1jetIds() ,fobs_[ifob]->l1jetRefs());
281  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1etmissIds() ,fobs_[ifob]->l1etmissRefs());
282  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1hfringsIds(),fobs_[ifob]->l1hfringsRefs());
283  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->pfjetIds() ,fobs_[ifob]->pfjetRefs());
284  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->pftauIds() ,fobs_[ifob]->pftauRefs());
285  product->addFilter(filterTag,ids_,keys_);
286  }
287  }
288 
289  OrphanHandle<TriggerEvent> ref = iEvent.put(product);
290  LogTrace("TriggerSummaryProducerAOD") << "Number of physics objects packed: " << ref->sizeObjects();
291  LogTrace("TriggerSummaryProducerAOD") << "Number of filter objects packed: " << ref->sizeFilters();
292 
293 }
294 
295 template <typename C>
297 
301 
302  using namespace std;
303  using namespace edm;
304  using namespace reco;
305  using namespace l1extra;
306  using namespace trigger;
307 
308  vector<Handle<C> > collections;
309  iEvent.getMany(selector_,collections);
310  const unsigned int nc(collections.size());
311 
312  for (unsigned int ic=0; ic!=nc; ++ic) {
313  const Provenance& provenance(*(collections[ic].provenance()));
314  const string& label (provenance.moduleLabel());
315  const string& instance (provenance.productInstanceName());
316  const string& process (provenance.processName());
317  const InputTag collectionTag(label,instance,process);
318 
319  if (collectionTagsEvent_.find(collectionTag)!=collectionTagsEvent_.end()) {
320  const ProductID pid(collections[ic].provenance()->productID());
321  if (offset_.find(pid)!=offset_.end()) {
322  LogError("TriggerSummaryProducerAOD") << "Duplicate pid!";
323  }
324  offset_[pid]=toc_.size();
325  const unsigned int n(collections[ic]->size());
326  for (unsigned int i=0; i!=n; ++i) {
327  fillTriggerObject( (*collections[ic])[i] );
328  }
329  tags_.push_back(collectionTag.encode());
330  keys_.push_back(toc_.size());
331  }
332 
333  }
334 }
335 
336 template <typename T>
338 
339  using namespace trigger;
340  toc_.push_back( TriggerObject(object) );
341 
342  return;
343 }
344 
346 
347  using namespace l1extra;
348  using namespace trigger;
349 
351  object.hfEtSum(L1HFRings::kRing1PosEta),
352  object.hfEtSum(L1HFRings::kRing1NegEta),
353  object.hfEtSum(L1HFRings::kRing2PosEta),
354  object.hfEtSum(L1HFRings::kRing2NegEta) ) );
356  object.hfBitCount(L1HFRings::kRing1PosEta),
357  object.hfBitCount(L1HFRings::kRing1NegEta),
358  object.hfBitCount(L1HFRings::kRing2PosEta),
359  object.hfBitCount(L1HFRings::kRing2NegEta) ) );
360 
361  return;
362 }
363 
365 
366  using namespace l1extra;
367  using namespace trigger;
368 
369  toc_.push_back( TriggerObject(object) );
370  if (object.type()==L1EtMissParticle::kMET) {
371  toc_.push_back(TriggerObject(TriggerL1ETT,object.etTotal(),0.0,0.0,0.0));
372  } else if (object.type()==L1EtMissParticle::kMHT) {
373  toc_.push_back(TriggerObject(TriggerL1HTT,object.etTotal(),0.0,0.0,0.0));
374  } else {
375  toc_.push_back(TriggerObject(0, object.etTotal(),0.0,0.0,0.0));
376  }
377 
378  return;
379 }
380 
382 
383  using namespace reco;
384  using namespace trigger;
385 
386  toc_.push_back( TriggerObject(object) );
387  toc_.push_back(TriggerObject(TriggerTET ,object.sumEt() ,0.0,0.0,0.0));
388  toc_.push_back(TriggerObject(TriggerMETSig ,object.mEtSig() ,0.0,0.0,0.0));
389  toc_.push_back(TriggerObject(TriggerELongit,object.e_longitudinal(),0.0,0.0,0.0));
390 
391  return;
392 }
393 
395 
396  using namespace reco;
397  using namespace trigger;
398 
399  toc_.push_back( TriggerObject(object) );
400  toc_.push_back(TriggerObject(TriggerTHT ,object.sumEt() ,0.0,0.0,0.0));
401  toc_.push_back(TriggerObject(TriggerMHTSig ,object.mEtSig() ,0.0,0.0,0.0));
402  toc_.push_back(TriggerObject(TriggerHLongit,object.e_longitudinal(),0.0,0.0,0.0));
403 
404  return;
405 }
406 
407 template <typename C>
408 void TriggerSummaryProducerAOD::fillFilterObjectMembers(const edm::Event& iEvent, const edm::InputTag& tag, const trigger::Vids& ids, const std::vector<edm::Ref<C> >& refs) {
409 
413 
414  using namespace std;
415  using namespace edm;
416  using namespace reco;
417  using namespace l1extra;
418  using namespace trigger;
419 
420  if (ids.size()!=refs.size()) {
421  LogError("TriggerSummaryProducerAOD") << "Vector length is different: "
422  << ids.size() << " " << refs.size();
423  }
424 
425  const unsigned int n(min(ids.size(),refs.size()));
426  for (unsigned int i=0; i!=n; ++i) {
427  const ProductID pid(refs[i].id());
428  if (offset_.find(pid)==offset_.end()) {
429  const string& label(iEvent.getProvenance(pid).moduleLabel());
430  const string& instance(iEvent.getProvenance(pid).productInstanceName());
431  const string& process(iEvent.getProvenance(pid).processName());
432  LogError("TriggerSummaryProducerAOD")
433  << "Uunknown pid:"
434  << " FilterTag/Key: " << tag.encode()
435  << "/" << i
436  << " CollectionTag/Key: "
437  << InputTag(label,instance,process).encode()
438  << "/" << refs[i].key()
439  << " CollectionType: " << typeid(C).name();
440  } else {
441  fillFilterObjectMember(offset_[pid],ids[i],refs[i]);
442  }
443  }
444  return;
445 
446 }
447 
448 template <typename C>
449 void TriggerSummaryProducerAOD::fillFilterObjectMember(const int& offset, const int& id, const edm::Ref<C> & ref) {
450 
451  keys_.push_back(offset+ref.key());
452  ids_.push_back(id);
453 
454  return;
455 }
456 
458 
459  using namespace trigger;
460 
461  if (id==TriggerL1HfBitCounts) {
462  keys_.push_back(offset+2*ref.key()+1);
463  } else { // if (ids[i]==TriggerL1HfRingEtSums) {
464  keys_.push_back(offset+2*ref.key()+0);
465  }
466  ids_.push_back(id);
467 
468  return;
469 }
470 
472 
473  using namespace trigger;
474 
475  if ( (id==TriggerL1ETT) || (id==TriggerL1HTT) ) {
476  keys_.push_back(offset+2*ref.key()+1);
477  } else {
478  keys_.push_back(offset+2*ref.key()+0);
479  }
480  ids_.push_back(id);
481 
482  return;
483 }
484 
486 
487  using namespace trigger;
488 
489  if ( (id==TriggerTHT) || (id==TriggerTET) ) {
490  keys_.push_back(offset+4*ref.key()+1);
491  } else if ( (id==TriggerMETSig) || (id==TriggerMHTSig) ) {
492  keys_.push_back(offset+4*ref.key()+2);
493  } else if ( (id==TriggerELongit) || (id==TriggerHLongit) ) {
494  keys_.push_back(offset+4*ref.key()+3);
495  } else {
496  keys_.push_back(offset+4*ref.key()+0);
497  }
498  ids_.push_back(id);
499 
500  return;
501 }
502 
504 
505  using namespace trigger;
506 
507  if ( (id==TriggerTHT) || (id==TriggerTET) ) {
508  keys_.push_back(offset+4*ref.key()+1);
509  } else if ( (id==TriggerMETSig) || (id==TriggerMHTSig) ) {
510  keys_.push_back(offset+4*ref.key()+2);
511  } else if ( (id==TriggerELongit) || (id==TriggerHLongit) ) {
512  keys_.push_back(offset+4*ref.key()+3);
513  } else {
514  keys_.push_back(offset+4*ref.key()+0);
515  }
516  ids_.push_back(id);
517 
518  return;
519 }
520 
522 
523  using namespace std;
524  using namespace edm;
525  using namespace trigger;
526 
527  LogVerbatim("TriggerSummaryProducerAOD") << endl;
528  LogVerbatim("TriggerSummaryProducerAOD") << "TriggerSummaryProducerAOD::endJob - accumulated tags:" << endl;
529 
530  const unsigned int nc(collectionTagsGlobal_.size());
531  const unsigned int nf(filterTagsGlobal_.size());
532  LogVerbatim("TriggerSummaryProducerAOD") << " Overall number of Collections/Filters: "
533  << nc << "/" << nf << endl;
534 
535  LogVerbatim("TriggerSummaryProducerAOD") << " The collections: " << nc << endl;
536  const InputTagSet::const_iterator cb(collectionTagsGlobal_.begin());
537  const InputTagSet::const_iterator ce(collectionTagsGlobal_.end());
538  for ( InputTagSet::const_iterator ci=cb; ci!=ce; ++ci) {
539  LogVerbatim("TriggerSummaryProducerAOD") << " " << distance(cb,ci) << " " << ci->encode() << endl;
540  }
541 
542  LogVerbatim("TriggerSummaryProducerAOD") << " The filters:" << nf << endl;
543  const InputTagSet::const_iterator fb(filterTagsGlobal_.begin());
544  const InputTagSet::const_iterator fe(filterTagsGlobal_.end());
545  for ( InputTagSet::const_iterator fi=fb; fi!=fe; ++fi) {
546  LogVerbatim("TriggerSummaryProducerAOD") << " " << distance(fb,fi) << " " << fi->encode() << endl;
547  }
548 
549  LogVerbatim("TriggerSummaryProducerAOD") << "TriggerSummaryProducerAOD::endJob." << endl;
550  LogVerbatim("TriggerSummaryProducerAOD") << endl;
551 
552  return;
553 
554 }
#define LogDebug(id)
type
Definition: HCALResponse.h:22
bool isDebugEnabled()
int i
Definition: DBlmapReader.cc:9
virtual void produce(edm::Event &, const edm::EventSetup &)
std::string const & getProcessName() const
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:27
trigger::TriggerObjectCollection toc_
trigger object collection
static PFTauRenderPlugin instance
std::vector< bool > maskFilters_
packing decision
std::set< edm::InputTag, OrderInputTag > InputTagSet
edm::ProcessNameSelector selector_
selector for getMany methods
#define min(a, b)
Definition: mlp_lapack.h:161
void fillFilterObjectMember(const int &, const int &, const edm::Ref< C > &)
edm::service::TriggerNamesService * tns_
the pointer to the current TriggerNamesService
void fillTriggerObjectCollections(const edm::Event &)
std::vector< std::string > tags_
std::string const & processName() const
Definition: Provenance.h:63
uint16_t size_type
std::string encode() const
Definition: InputTag.cc:72
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:24
int iEvent
Definition: GenABIO.cc:243
TriggerSummaryProducerAOD(const edm::ParameterSet &)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
Definition: MET.h:32
void getMany(SelectorBase const &sel, std::vector< Handle< PROD > > &results) const
Definition: Event.h:388
std::map< edm::ProductID, unsigned int > offset_
global map for indices into toc_: offset per input L3 collection
unsigned int offset(bool)
void fillFilterObjectMembers(const edm::Event &, const edm::InputTag &tag, const trigger::Vids &, const std::vector< edm::Ref< C > > &)
#define LogTrace(id)
double & fe
Definition: VDTMath.h:196
std::vector< edm::Handle< trigger::TriggerFilterObjectWithRefs > > fobs_
handles to the filter objects
key_type key() const
Accessor for product key.
Definition: Ref.h:266
std::string const & moduleLabel() const
Definition: Provenance.h:62
InputTagSet collectionTagsEvent_
list of L3 collection tags
std::string pn_
process name
InputTagSet filterTagsEvent_
list of L3 filter tags
std::string const & productInstanceName() const
Definition: Provenance.h:64
tuple process
Definition: LaserDQM_cfg.py:3
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:60
long double T
tuple size
Write out results.
std::vector< int > Vids