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