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 
10 #include <algorithm>
11 #include <memory>
12 #include <typeinfo>
13 
16 
23 
34 
40 
43 
46 
47 //
48 // constructors and destructor
49 //
51  pn_(ps.getParameter<std::string>("processName")),
52  filterTagsEvent_(pn_!="*"),
53  filterTagsStream_(pn_!="*"),
54  collectionTagsEvent_(pn_!="*"),
55  collectionTagsStream_(pn_!="*"),
56  toc_(),
57  tags_(),
58  offset_(),
59  keys_(),
60  ids_(),
61  maskFilters_()
62 {
63  if (pn_=="@") {
65  if (tns.isAvailable()) {
66  pn_ = tns->getProcessName();
67  } else {
68  edm::LogError("TriggerSummaryProducerAOD") << "HLT Error: TriggerNamesService not available!";
69  pn_="*";
70  }
71 
76  }
77  LogDebug("TriggerSummaryProducerAOD") << "Using process name: '" << pn_ <<"'";
78 
79  filterTagsStream_.clear();
80  collectionTagsStream_.clear();
81 
82  produces<trigger::TriggerEvent>();
83 
100 
108  getMETCollection_(bd);
118  });
119 }
120 
122 {
123 }
124 
125 //
126 // member functions
127 //
128 
129 namespace {
130  inline void
132 
133  using std::string;
134 
135  const char token(':');
136  const string empty;
137 
138  label=tag;
139  const string::size_type i1(label.find(token));
140  if (i1==string::npos) {
141  instance=empty;
142  process=empty;
143  } else {
144  instance=label.substr(i1+1);
145  label.resize(i1);
146  const string::size_type i2(instance.find(token));
147  if (i2==string::npos) {
148  process=empty;
149  } else {
150  process=instance.substr(i2+1);
151  instance.resize(i2);
152  }
153  }
154  }
155 }
156 
159  desc.add<std::string>("processName","@");
160  descriptions.add("triggerSummaryProducerAOD", desc);
161 }
162 
163 // ------------ method called to produce the data ------------
164 void
166 {
167  using namespace std;
168  using namespace edm;
169  using namespace reco;
170  using namespace l1extra;
171  using namespace trigger;
172 
173  std::vector<edm::Handle<trigger::TriggerFilterObjectWithRefs> > fobs;
175 
176  const unsigned int nfob(fobs.size());
177  LogTrace("TriggerSummaryProducerAOD") << "Number of filter objects found: " << nfob;
178 
179  string tagLabel,tagInstance,tagProcess;
180 
186  maskFilters_.clear();
187  maskFilters_.resize(nfob);
188  filterTagsEvent_.clear();
189  collectionTagsEvent_.clear();
190  unsigned int nf(0);
191  for (unsigned int ifob=0; ifob!=nfob; ++ifob) {
192  maskFilters_[ifob]=false;
193  const vector<string>& collectionTags_(fobs[ifob]->getCollectionTagsAsStrings());
194  const unsigned int ncol(collectionTags_.size());
195  if (ncol>0) {
196  nf++;
197  maskFilters_[ifob]=true;
198  const string& label (fobs[ifob].provenance()->moduleLabel());
199  const string& instance (fobs[ifob].provenance()->productInstanceName());
200  const string& process (fobs[ifob].provenance()->processName());
201  filterTagsEvent_.insert(InputTag(label,instance,process));
202  for (unsigned int icol=0; icol!=ncol; ++icol) {
203  // overwrite process name (usually not set)
204  tokenizeTag(collectionTags_[icol],tagLabel,tagInstance,tagProcess);
205  collectionTagsEvent_.insert(InputTag(tagLabel,tagInstance,pn_));
206  }
207  }
208  }
210  if (filterTagsEvent_.size()!=nf) {
211  LogError("TriggerSummaryProducerAOD")
212  << "Mismatch in number of filter tags: "
213  << filterTagsEvent_.size() << "!=" << nf ;
214  }
215 
219 
221  if (isDebugEnabled()) {
222 
224  const unsigned int nc(collectionTagsEvent_.size());
225  LogTrace("TriggerSummaryProducerAOD") << "Number of unique collections requested " << nc;
226  const InputTagSet::const_iterator cb(collectionTagsEvent_.begin());
227  const InputTagSet::const_iterator ce(collectionTagsEvent_.end());
228  for ( InputTagSet::const_iterator ci=cb; ci!=ce; ++ci) {
229  LogTrace("TriggerSummaryProducerAOD") << distance(cb,ci) << " " << ci->encode();
230  }
231  const unsigned int nf(filterTagsEvent_.size());
232  LogTrace("TriggerSummaryProducerAOD") << "Number of unique filters requested " << nf;
233  const InputTagSet::const_iterator fb(filterTagsEvent_.begin());
234  const InputTagSet::const_iterator fe(filterTagsEvent_.end());
235  for ( InputTagSet::const_iterator fi=fb; fi!=fe; ++fi) {
236  LogTrace("TriggerSummaryProducerAOD") << distance(fb,fi) << " " << fi->encode();
237  }
238 
239  }
240 
246  toc_.clear();
247  tags_.clear();
248  keys_.clear();
249  offset_.clear();
250  fillTriggerObjectCollections< RecoEcalCandidateCollection>(iEvent, getRecoEcalCandidateCollection_);
251  fillTriggerObjectCollections< ElectronCollection>(iEvent, getElectronCollection_);
252  fillTriggerObjectCollections< RecoChargedCandidateCollection>(iEvent, getRecoChargedCandidateCollection_);
253  fillTriggerObjectCollections< CaloJetCollection>(iEvent, getCaloJetCollection_);
254  fillTriggerObjectCollections< CompositeCandidateCollection>(iEvent, getCompositeCandidateCollection_);
255  fillTriggerObjectCollections< METCollection>(iEvent, getMETCollection_);
256  fillTriggerObjectCollections< CaloMETCollection>(iEvent, getCaloMETCollection_);
257  fillTriggerObjectCollections<IsolatedPixelTrackCandidateCollection>(iEvent, getIsolatedPixelTrackCandidateCollection_);
259  fillTriggerObjectCollections< L1EmParticleCollection>(iEvent, getL1EmParticleCollection_);
260  fillTriggerObjectCollections< L1MuonParticleCollection>(iEvent, getL1MuonParticleCollection_);
261  fillTriggerObjectCollections< L1JetParticleCollection>(iEvent, getL1JetParticleCollection_);
262  fillTriggerObjectCollections< L1EtMissParticleCollection>(iEvent, getL1EtMissParticleCollection_);
263  fillTriggerObjectCollections< L1HFRingsCollection>(iEvent, getL1HFRingsCollection_);
265  fillTriggerObjectCollections< PFJetCollection>(iEvent, getPFJetCollection_);
266  fillTriggerObjectCollections< PFTauCollection>(iEvent, getPFTauCollection_);
268  const unsigned int nk(tags_.size());
269  LogDebug("TriggerSummaryProducerAOD") << "Number of collections found: " << nk;
270  const unsigned int no(toc_.size());
271  LogDebug("TriggerSummaryProducerAOD") << "Number of physics objects found: " << no;
272 
275  auto_ptr<TriggerEvent> product(new TriggerEvent(pn_,nk,no,nf));
276 
278  product->addCollections(tags_,keys_);
279  product->addObjects(toc_);
280 
282  for (unsigned int ifob=0; ifob!=nfob; ++ifob) {
283  if (maskFilters_[ifob]) {
284  const string& label (fobs[ifob].provenance()->moduleLabel());
285  const string& instance (fobs[ifob].provenance()->productInstanceName());
286  const string& process (fobs[ifob].provenance()->processName());
287  const edm::InputTag filterTag(label,instance,process);
288  ids_.clear();
289  keys_.clear();
290  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->photonIds() ,fobs[ifob]->photonRefs());
291  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->electronIds() ,fobs[ifob]->electronRefs());
292  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->muonIds() ,fobs[ifob]->muonRefs());
293  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->jetIds() ,fobs[ifob]->jetRefs());
294  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->compositeIds(),fobs[ifob]->compositeRefs());
295  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->basemetIds() ,fobs[ifob]->basemetRefs());
296  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->calometIds() ,fobs[ifob]->calometRefs());
297  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->pixtrackIds() ,fobs[ifob]->pixtrackRefs());
298  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->l1emIds() ,fobs[ifob]->l1emRefs());
299  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->l1muonIds() ,fobs[ifob]->l1muonRefs());
300  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->l1jetIds() ,fobs[ifob]->l1jetRefs());
301  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->l1etmissIds() ,fobs[ifob]->l1etmissRefs());
302  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->l1hfringsIds(),fobs[ifob]->l1hfringsRefs());
303  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->pfjetIds() ,fobs[ifob]->pfjetRefs());
304  fillFilterObjectMembers(iEvent,filterTag,fobs[ifob]->pftauIds() ,fobs[ifob]->pftauRefs());
305  product->addFilter(filterTag,ids_,keys_);
306  }
307  }
308 
309  OrphanHandle<TriggerEvent> ref = iEvent.put(product);
310  LogTrace("TriggerSummaryProducerAOD") << "Number of physics objects packed: " << ref->sizeObjects();
311  LogTrace("TriggerSummaryProducerAOD") << "Number of filter objects packed: " << ref->sizeFilters();
312 
313 }
314 
315 template <typename C>
317 
321 
322  using namespace std;
323  using namespace edm;
324  using namespace reco;
325  using namespace l1extra;
326  using namespace trigger;
327 
328  vector<Handle<C> > collections;
329  getter.fillHandles(iEvent, collections);
330  const unsigned int nc(collections.size());
331 
332  for (unsigned int ic=0; ic!=nc; ++ic) {
333  const Provenance& provenance(*(collections[ic].provenance()));
334  const string& label (provenance.moduleLabel());
335  const string& instance (provenance.productInstanceName());
336  const string& process (provenance.processName());
337  const InputTag collectionTag(label,instance,process);
338 
339  if (collectionTagsEvent_.find(collectionTag)!=collectionTagsEvent_.end()) {
340  const ProductID pid(collections[ic].provenance()->productID());
341  if (offset_.find(pid)!=offset_.end()) {
342  LogError("TriggerSummaryProducerAOD") << "Duplicate pid!";
343  }
344  offset_[pid]=toc_.size();
345  const unsigned int n(collections[ic]->size());
346  for (unsigned int i=0; i!=n; ++i) {
347  fillTriggerObject( (*collections[ic])[i] );
348  }
349  tags_.push_back(collectionTag.encode());
350  keys_.push_back(toc_.size());
351  }
352 
353  }
354 }
355 
356 template <typename T>
358 
359  using namespace trigger;
360  toc_.push_back( TriggerObject(object) );
361 
362  return;
363 }
364 
366 
367  using namespace l1extra;
368  using namespace trigger;
369 
371  object.hfEtSum(L1HFRings::kRing1PosEta),
372  object.hfEtSum(L1HFRings::kRing1NegEta),
373  object.hfEtSum(L1HFRings::kRing2PosEta),
374  object.hfEtSum(L1HFRings::kRing2NegEta) ) );
376  object.hfBitCount(L1HFRings::kRing1PosEta),
377  object.hfBitCount(L1HFRings::kRing1NegEta),
378  object.hfBitCount(L1HFRings::kRing2PosEta),
379  object.hfBitCount(L1HFRings::kRing2NegEta) ) );
380 
381  return;
382 }
383 
385 
386  using namespace l1extra;
387  using namespace trigger;
388 
389  toc_.push_back( TriggerObject(object) );
390  if (object.type()==L1EtMissParticle::kMET) {
391  toc_.push_back(TriggerObject(TriggerL1ETT,object.etTotal(),0.0,0.0,0.0));
392  } else if (object.type()==L1EtMissParticle::kMHT) {
393  toc_.push_back(TriggerObject(TriggerL1HTT,object.etTotal(),0.0,0.0,0.0));
394  } else {
395  toc_.push_back(TriggerObject(0, object.etTotal(),0.0,0.0,0.0));
396  }
397 
398  return;
399 }
400 
402 
403  using namespace reco;
404  using namespace trigger;
405 
406  toc_.push_back( TriggerObject(object) );
407  toc_.push_back(TriggerObject(TriggerTET ,object.sumEt() ,0.0,0.0,0.0));
408  toc_.push_back(TriggerObject(TriggerMETSig ,object.mEtSig() ,0.0,0.0,0.0));
409  toc_.push_back(TriggerObject(TriggerELongit,object.e_longitudinal(),0.0,0.0,0.0));
410 
411  return;
412 }
413 
415 
416  using namespace reco;
417  using namespace trigger;
418 
419  toc_.push_back( TriggerObject(object) );
420  toc_.push_back(TriggerObject(TriggerTHT ,object.sumEt() ,0.0,0.0,0.0));
421  toc_.push_back(TriggerObject(TriggerMHTSig ,object.mEtSig() ,0.0,0.0,0.0));
422  toc_.push_back(TriggerObject(TriggerHLongit,object.e_longitudinal(),0.0,0.0,0.0));
423 
424  return;
425 }
426 
427 template <typename C>
428 void TriggerSummaryProducerAOD::fillFilterObjectMembers(const edm::Event& iEvent, const edm::InputTag& tag, const trigger::Vids& ids, const std::vector<edm::Ref<C> >& refs) {
429 
433 
434  using namespace std;
435  using namespace edm;
436  using namespace reco;
437  using namespace l1extra;
438  using namespace trigger;
439 
440  if (ids.size()!=refs.size()) {
441  LogError("TriggerSummaryProducerAOD") << "Vector length is different: "
442  << ids.size() << " " << refs.size();
443  }
444 
445  const unsigned int n(min(ids.size(),refs.size()));
446  for (unsigned int i=0; i!=n; ++i) {
447  const ProductID pid(refs[i].id());
448  if (offset_.find(pid)==offset_.end()) {
449  const string& label(iEvent.getProvenance(pid).moduleLabel());
450  const string& instance(iEvent.getProvenance(pid).productInstanceName());
451  const string& process(iEvent.getProvenance(pid).processName());
452  LogError("TriggerSummaryProducerAOD")
453  << "Uunknown pid:"
454  << " FilterTag/Key: " << tag.encode()
455  << "/" << i
456  << " CollectionTag/Key: "
457  << InputTag(label,instance,process).encode()
458  << "/" << refs[i].key()
459  << " CollectionType: " << typeid(C).name();
460  } else {
461  fillFilterObjectMember(offset_[pid],ids[i],refs[i]);
462  }
463  }
464  return;
465 
466 }
467 
468 template <typename C>
469 void TriggerSummaryProducerAOD::fillFilterObjectMember(const int& offset, const int& id, const edm::Ref<C> & ref) {
470 
471  keys_.push_back(offset+ref.key());
472  ids_.push_back(id);
473 
474  return;
475 }
476 
478 
479  using namespace trigger;
480 
481  if (id==TriggerL1HfBitCounts) {
482  keys_.push_back(offset+2*ref.key()+1);
483  } else { // if (ids[i]==TriggerL1HfRingEtSums) {
484  keys_.push_back(offset+2*ref.key()+0);
485  }
486  ids_.push_back(id);
487 
488  return;
489 }
490 
492 
493  using namespace trigger;
494 
495  if ( (id==TriggerL1ETT) || (id==TriggerL1HTT) ) {
496  keys_.push_back(offset+2*ref.key()+1);
497  } else {
498  keys_.push_back(offset+2*ref.key()+0);
499  }
500  ids_.push_back(id);
501 
502  return;
503 }
504 
506 
507  using namespace trigger;
508 
509  if ( (id==TriggerTHT) || (id==TriggerTET) ) {
510  keys_.push_back(offset+4*ref.key()+1);
511  } else if ( (id==TriggerMETSig) || (id==TriggerMHTSig) ) {
512  keys_.push_back(offset+4*ref.key()+2);
513  } else if ( (id==TriggerELongit) || (id==TriggerHLongit) ) {
514  keys_.push_back(offset+4*ref.key()+3);
515  } else {
516  keys_.push_back(offset+4*ref.key()+0);
517  }
518  ids_.push_back(id);
519 
520  return;
521 }
522 
524 
525  using namespace trigger;
526 
527  if ( (id==TriggerTHT) || (id==TriggerTET) ) {
528  keys_.push_back(offset+4*ref.key()+1);
529  } else if ( (id==TriggerMETSig) || (id==TriggerMHTSig) ) {
530  keys_.push_back(offset+4*ref.key()+2);
531  } else if ( (id==TriggerELongit) || (id==TriggerHLongit) ) {
532  keys_.push_back(offset+4*ref.key()+3);
533  } else {
534  keys_.push_back(offset+4*ref.key()+0);
535  }
536  ids_.push_back(id);
537 
538  return;
539 }
540 
542  globalCache()->collectionTagsGlobal_.insert(collectionTagsStream_.begin(),collectionTagsStream_.end());
543  globalCache()->filterTagsGlobal_.insert(filterTagsStream_.begin(),filterTagsStream_.end());
544  return;
545 }
546 
548 
549  using namespace std;
550  using namespace edm;
551  using namespace trigger;
552 
553  LogVerbatim("TriggerSummaryProducerAOD") << endl;
554  LogVerbatim("TriggerSummaryProducerAOD") << "TriggerSummaryProducerAOD::globalEndJob - accumulated tags:" << endl;
555 
556  InputTagSet filterTags(false);
557  InputTagSet collectionTags(false);
558 
559  filterTags.insert(globalInputTags->filterTagsGlobal_.begin(),globalInputTags->filterTagsGlobal_.end());
560  collectionTags.insert(globalInputTags->collectionTagsGlobal_.begin(),globalInputTags->collectionTagsGlobal_.end());
561 
562  const unsigned int nc(collectionTags.size());
563  const unsigned int nf(filterTags.size());
564  LogVerbatim("TriggerSummaryProducerAOD") << " Overall number of Collections/Filters: "
565  << nc << "/" << nf << endl;
566 
567  LogVerbatim("TriggerSummaryProducerAOD") << " The collections: " << nc << endl;
568  const InputTagSet::const_iterator cb(collectionTags.begin());
569  const InputTagSet::const_iterator ce(collectionTags.end());
570  for ( InputTagSet::const_iterator ci=cb; ci!=ce; ++ci) {
571  LogVerbatim("TriggerSummaryProducerAOD") << " " << distance(cb,ci) << " " << ci->encode() << endl;
572  }
573 
574  LogVerbatim("TriggerSummaryProducerAOD") << " The filters:" << nf << endl;
575  const InputTagSet::const_iterator fb(filterTags.begin());
576  const InputTagSet::const_iterator fe(filterTags.end());
577  for ( InputTagSet::const_iterator fi=fb; fi!=fe; ++fi) {
578  LogVerbatim("TriggerSummaryProducerAOD") << " " << distance(fb,fi) << " " << fi->encode() << endl;
579  }
580 
581  LogVerbatim("TriggerSummaryProducerAOD") << "TriggerSummaryProducerAOD::endJob." << endl;
582  LogVerbatim("TriggerSummaryProducerAOD") << endl;
583 
584  return;
585 
586 }
#define LogDebug(id)
virtual void produce(edm::Event &, const edm::EventSetup &) override
type
Definition: HCALResponse.h:21
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
Definition: ProducerBase.h:51
bool isDebugEnabled()
int i
Definition: DBlmapReader.cc:9
edm::GetterOfProducts< l1extra::L1JetParticleCollection > getL1JetParticleCollection_
edm::GetterOfProducts< reco::IsolatedPixelTrackCandidateCollection > getIsolatedPixelTrackCandidateCollection_
edm::GetterOfProducts< reco::RecoEcalCandidateCollection > getRecoEcalCandidateCollection_
std::string const & getProcessName() const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::GetterOfProducts< l1extra::L1MuonParticleCollection > getL1MuonParticleCollection_
The single EDProduct to be saved for each event (AOD case)
Definition: TriggerEvent.h:25
trigger::TriggerObjectCollection toc_
trigger object collection
edm::GetterOfProducts< reco::PFTauCollection > getPFTauCollection_
static PFTauRenderPlugin instance
std::vector< bool > maskFilters_
packing decision
edm::GetterOfProducts< reco::METCollection > getMETCollection_
std::set< edm::InputTag, OrderInputTag > InputTagSet
edm::GetterOfProducts< reco::CaloJetCollection > getCaloJetCollection_
void fillFilterObjectMember(const int &, const int &, const edm::Ref< C > &)
edm::GetterOfProducts< l1extra::L1EtMissParticleCollection > getL1EtMissParticleCollection_
key_type key() const
Accessor for product key.
Definition: Ref.h:266
std::vector< std::string > tags_
std::string const & processName() const
Definition: Provenance.h:61
uint16_t size_type
std::string encode() const
Definition: InputTag.cc:164
edm::GetterOfProducts< reco::PFJetCollection > getPFJetCollection_
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
int iEvent
Definition: GenABIO.cc:230
edm::GetterOfProducts< reco::RecoChargedCandidateCollection > getRecoChargedCandidateCollection_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
Definition: MET.h:42
edm::GetterOfProducts< l1extra::L1HFRingsCollection > getL1HFRingsCollection_
bool isAvailable() const
Definition: Service.h:46
std::map< edm::ProductID, unsigned int > offset_
global map for indices into toc_: offset per input L3 collection
T min(T a, T b)
Definition: MathUtil.h:58
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void fillFilterObjectMembers(const edm::Event &, const edm::InputTag &tag, const trigger::Vids &, const std::vector< edm::Ref< C > > &)
#define LogTrace(id)
tbb::concurrent_unordered_set< edm::InputTag, InputTagHash > filterTagsGlobal_
tuple pid
Definition: sysUtil.py:22
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::string const & moduleLabel() const
Definition: Provenance.h:60
edm::GetterOfProducts< reco::CaloMETCollection > getCaloMETCollection_
edm::GetterOfProducts< reco::ElectronCollection > getElectronCollection_
InputTagSet collectionTagsEvent_
list of L3 collection tags
void fillHandles(edm::Event const &event, std::vector< edm::Handle< T > > &handles) const
edm::GetterOfProducts< reco::CompositeCandidateCollection > getCompositeCandidateCollection_
edm::GetterOfProducts< trigger::TriggerFilterObjectWithRefs > getTriggerFilterObjectWithRefs_
void fillTriggerObjectCollections(const edm::Event &, edm::GetterOfProducts< C > &)
InputTagSet filterTagsEvent_
list of L3 filter tags
TriggerSummaryProducerAOD(const edm::ParameterSet &, const GlobalInputTags *)
static void globalEndJob(const GlobalInputTags *)
std::string const & productInstanceName() const
Definition: Provenance.h:62
tuple process
Definition: LaserDQM_cfg.py:3
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:73
long double T
tbb::concurrent_unordered_set< edm::InputTag, InputTagHash > collectionTagsGlobal_
tuple size
Write out results.
std::vector< int > Vids
edm::GetterOfProducts< l1extra::L1EmParticleCollection > getL1EmParticleCollection_