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 
48 #include <algorithm>
49 #include <typeinfo>
50 
51 
52 //
53 // constructors and destructor
54 //
56  pn_(ps.getParameter<std::string>("processName")),
57  selector_(edm::ProcessNameSelector(pn_)),
58  tns_(),
59  filterTagsEvent_(pn_!="*"),
60  filterTagsGlobal_(pn_!="*"),
61  collectionTagsEvent_(pn_!="*"),
62  collectionTagsGlobal_(pn_!="*"),
63  toc_(),
64  tags_(),
65  offset_(),
66  fobs_(),
67  keys_(),
68  ids_(),
69  maskFilters_()
70 {
71  if (pn_=="@") {
72  // use tns
74  // get tns pointer
76  if (tns_!=0) {
78  } else {
79  edm::LogError("TriggerSummaryProducerAOD") << "HLT Error: TriggerNamesService pointer = 0!";
80  pn_="*";
81  }
82  } else {
83  edm::LogError("TriggerSummaryProducerAOD") << "HLT Error: TriggerNamesService not available!";
84  pn_="*";
85  }
91  }
92  LogDebug("TriggerSummaryProducerAOD") << "Using process name: '" << pn_ <<"'";
93 
94  filterTagsGlobal_.clear();
95  collectionTagsGlobal_.clear();
96 
97  produces<trigger::TriggerEvent>();
98 
99 }
100 
102 {
103 }
104 
105 //
106 // member functions
107 //
108 
109 namespace {
110  inline void
111  tokenizeTag(const std::string& tag, std::string& label, std::string& instance, std::string& process){
112 
113  using std::string;
114 
115  const char token(':');
116  const string empty;
117 
118  label=tag;
119  const string::size_type i1(label.find(token));
120  if (i1==string::npos) {
121  instance=empty;
122  process=empty;
123  } else {
124  instance=label.substr(i1+1);
125  label.resize(i1);
126  const string::size_type i2(instance.find(token));
127  if (i2==string::npos) {
128  process=empty;
129  } else {
130  process=instance.substr(i2+1);
131  instance.resize(i2);
132  }
133  }
134  }
135 }
136 
137 // ------------ method called to produce the data ------------
138 void
140 {
141  using namespace std;
142  using namespace edm;
143  using namespace reco;
144  using namespace l1extra;
145  using namespace trigger;
146 
149  fobs_.clear();
150  iEvent.getMany(selector_,fobs_);
151  const unsigned int nfob(fobs_.size());
152  LogTrace("TriggerSummaryProducerAOD") << "Number of filter objects found: " << nfob;
153 
154  string tagLabel,tagInstance,tagProcess;
155 
161  maskFilters_.clear();
162  maskFilters_.resize(nfob);
163  filterTagsEvent_.clear();
164  collectionTagsEvent_.clear();
165  unsigned int nf(0);
166  for (unsigned int ifob=0; ifob!=nfob; ++ifob) {
167  maskFilters_[ifob]=false;
168  const vector<string>& collectionTags_(fobs_[ifob]->getCollectionTagsAsStrings());
169  const unsigned int ncol(collectionTags_.size());
170  if (ncol>0) {
171  nf++;
172  maskFilters_[ifob]=true;
173  const string& label (fobs_[ifob].provenance()->moduleLabel());
174  const string& instance (fobs_[ifob].provenance()->productInstanceName());
175  const string& process (fobs_[ifob].provenance()->processName());
176  filterTagsEvent_.insert(InputTag(label,instance,process));
177  for (unsigned int icol=0; icol!=ncol; ++icol) {
178  // overwrite process name (usually not set)
179  tokenizeTag(collectionTags_[icol],tagLabel,tagInstance,tagProcess);
180  collectionTagsEvent_.insert(InputTag(tagLabel,tagInstance,pn_));
181  }
182  }
183  }
185  if (filterTagsEvent_.size()!=nf) {
186  LogError("TriggerSummaryProducerAOD")
187  << "Mismatch in number of filter tags: "
188  << filterTagsEvent_.size() << "!=" << nf ;
189  }
190 
194 
196  if (isDebugEnabled()) {
197 
199  const unsigned int nc(collectionTagsEvent_.size());
200  LogTrace("TriggerSummaryProducerAOD") << "Number of unique collections requested " << nc;
201  const InputTagSet::const_iterator cb(collectionTagsEvent_.begin());
202  const InputTagSet::const_iterator ce(collectionTagsEvent_.end());
203  for ( InputTagSet::const_iterator ci=cb; ci!=ce; ++ci) {
204  LogTrace("TriggerSummaryProducerAOD") << distance(cb,ci) << " " << ci->encode();
205  }
206  const unsigned int nf(filterTagsEvent_.size());
207  LogTrace("TriggerSummaryProducerAOD") << "Number of unique filters requested " << nf;
208  const InputTagSet::const_iterator fb(filterTagsEvent_.begin());
209  const InputTagSet::const_iterator fe(filterTagsEvent_.end());
210  for ( InputTagSet::const_iterator fi=fb; fi!=fe; ++fi) {
211  LogTrace("TriggerSummaryProducerAOD") << distance(fb,fi) << " " << fi->encode();
212  }
213 
214  }
215 
221  toc_.clear();
222  tags_.clear();
223  keys_.clear();
224  offset_.clear();
225  fillTriggerObjectCollections< RecoEcalCandidateCollection>(iEvent);
226  fillTriggerObjectCollections< ElectronCollection>(iEvent);
227  fillTriggerObjectCollections< RecoChargedCandidateCollection>(iEvent);
228  fillTriggerObjectCollections< CaloJetCollection>(iEvent);
229  fillTriggerObjectCollections< CompositeCandidateCollection>(iEvent);
230  fillTriggerObjectCollections< METCollection>(iEvent);
231  fillTriggerObjectCollections< CaloMETCollection>(iEvent);
232  fillTriggerObjectCollections<IsolatedPixelTrackCandidateCollection>(iEvent);
234  fillTriggerObjectCollections< L1EmParticleCollection>(iEvent);
235  fillTriggerObjectCollections< L1MuonParticleCollection>(iEvent);
236  fillTriggerObjectCollections< L1JetParticleCollection>(iEvent);
237  fillTriggerObjectCollections< L1EtMissParticleCollection>(iEvent);
238  fillTriggerObjectCollections< L1HFRingsCollection>(iEvent);
240  const unsigned int nk(tags_.size());
241  LogDebug("TriggerSummaryProducerAOD") << "Number of collections found: " << nk;
242  const unsigned int no(toc_.size());
243  LogDebug("TriggerSummaryProducerAOD") << "Number of physics objects found: " << no;
244 
247  auto_ptr<TriggerEvent> product(new TriggerEvent(pn_,nk,no,nf));
248 
250  product->addCollections(tags_,keys_);
251  product->addObjects(toc_);
252 
254  for (unsigned int ifob=0; ifob!=nfob; ++ifob) {
255  if (maskFilters_[ifob]) {
256  const string& label (fobs_[ifob].provenance()->moduleLabel());
257  const string& instance (fobs_[ifob].provenance()->productInstanceName());
258  const string& process (fobs_[ifob].provenance()->processName());
259  const edm::InputTag filterTag(label,instance,process);
260  ids_.clear();
261  keys_.clear();
262  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->photonIds() ,fobs_[ifob]->photonRefs());
263  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->electronIds() ,fobs_[ifob]->electronRefs());
264  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->muonIds() ,fobs_[ifob]->muonRefs());
265  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->jetIds() ,fobs_[ifob]->jetRefs());
266  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->compositeIds(),fobs_[ifob]->compositeRefs());
267  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->basemetIds() ,fobs_[ifob]->basemetRefs());
268  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->calometIds() ,fobs_[ifob]->calometRefs());
269  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->pixtrackIds() ,fobs_[ifob]->pixtrackRefs());
270  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1emIds() ,fobs_[ifob]->l1emRefs());
271  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1muonIds() ,fobs_[ifob]->l1muonRefs());
272  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1jetIds() ,fobs_[ifob]->l1jetRefs());
273  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1etmissIds() ,fobs_[ifob]->l1etmissRefs());
274  fillFilterObjectMembers(iEvent,filterTag,fobs_[ifob]->l1hfringsIds(),fobs_[ifob]->l1hfringsRefs());
275  product->addFilter(filterTag,ids_,keys_);
276  }
277  }
278 
279  OrphanHandle<TriggerEvent> ref = iEvent.put(product);
280  LogTrace("TriggerSummaryProducerAOD") << "Number of physics objects packed: " << ref->sizeObjects();
281  LogTrace("TriggerSummaryProducerAOD") << "Number of filter objects packed: " << ref->sizeFilters();
282 
283 }
284 
285 template <typename C>
287 
291 
292  using namespace std;
293  using namespace edm;
294  using namespace reco;
295  using namespace l1extra;
296  using namespace trigger;
297 
298  vector<Handle<C> > collections;
299  iEvent.getMany(selector_,collections);
300  const unsigned int nc(collections.size());
301 
302  for (unsigned int ic=0; ic!=nc; ++ic) {
303  const Provenance& provenance(*(collections[ic].provenance()));
304  const string& label (provenance.moduleLabel());
305  const string& instance (provenance.productInstanceName());
306  const string& process (provenance.processName());
307  const InputTag collectionTag(label,instance,process);
308 
309  if (collectionTagsEvent_.find(collectionTag)!=collectionTagsEvent_.end()) {
310  const ProductID pid(collections[ic].provenance()->productID());
311  if (offset_.find(pid)!=offset_.end()) {
312  LogError("TriggerSummaryProducerAOD") << "Duplicate pid!";
313  }
314  offset_[pid]=toc_.size();
315  const unsigned int n(collections[ic]->size());
316  for (unsigned int i=0; i!=n; ++i) {
317  fillTriggerObject( (*collections[ic])[i] );
318  }
319  tags_.push_back(collectionTag.encode());
320  keys_.push_back(toc_.size());
321  }
322 
323  }
324 }
325 
326 template <typename T>
328 
329  using namespace trigger;
330  toc_.push_back( TriggerObject(object) );
331 
332  return;
333 }
334 
336 
337  using namespace l1extra;
338  using namespace trigger;
339 
341  object.hfEtSum(L1HFRings::kRing1PosEta),
342  object.hfEtSum(L1HFRings::kRing1NegEta),
343  object.hfEtSum(L1HFRings::kRing2PosEta),
344  object.hfEtSum(L1HFRings::kRing2NegEta) ) );
346  object.hfBitCount(L1HFRings::kRing1PosEta),
347  object.hfBitCount(L1HFRings::kRing1NegEta),
348  object.hfBitCount(L1HFRings::kRing2PosEta),
349  object.hfBitCount(L1HFRings::kRing2NegEta) ) );
350 
351  return;
352 }
353 
355 
356  using namespace l1extra;
357  using namespace trigger;
358 
359  toc_.push_back( TriggerObject(object) );
360  if (object.type()==L1EtMissParticle::kMET) {
361  toc_.push_back(TriggerObject(TriggerL1ETT,object.etTotal(),0.0,0.0,0.0));
362  } else if (object.type()==L1EtMissParticle::kMHT) {
363  toc_.push_back(TriggerObject(TriggerL1HTT,object.etTotal(),0.0,0.0,0.0));
364  } else {
365  toc_.push_back(TriggerObject(0, object.etTotal(),0.0,0.0,0.0));
366  }
367 
368  return;
369 }
370 
372 
373  using namespace reco;
374  using namespace trigger;
375 
376  toc_.push_back( TriggerObject(object) );
377  toc_.push_back(TriggerObject(TriggerTET ,object.sumEt() ,0.0,0.0,0.0));
378  toc_.push_back(TriggerObject(TriggerMETSig ,object.mEtSig() ,0.0,0.0,0.0));
379  toc_.push_back(TriggerObject(TriggerELongit,object.e_longitudinal(),0.0,0.0,0.0));
380 
381  return;
382 }
383 
385 
386  using namespace reco;
387  using namespace trigger;
388 
389  toc_.push_back( TriggerObject(object) );
390  toc_.push_back(TriggerObject(TriggerTHT ,object.sumEt() ,0.0,0.0,0.0));
391  toc_.push_back(TriggerObject(TriggerMHTSig ,object.mEtSig() ,0.0,0.0,0.0));
392  toc_.push_back(TriggerObject(TriggerHLongit,object.e_longitudinal(),0.0,0.0,0.0));
393 
394  return;
395 }
396 
397 template <typename C>
398 void TriggerSummaryProducerAOD::fillFilterObjectMembers(const edm::Event& iEvent, const edm::InputTag& tag, const trigger::Vids& ids, const std::vector<edm::Ref<C> >& refs) {
399 
403 
404  using namespace std;
405  using namespace edm;
406  using namespace reco;
407  using namespace l1extra;
408  using namespace trigger;
409 
410  if (ids.size()!=refs.size()) {
411  LogError("TriggerSummaryProducerAOD") << "Vector length is different: "
412  << ids.size() << " " << refs.size();
413  }
414 
415  const unsigned int n(min(ids.size(),refs.size()));
416  for (unsigned int i=0; i!=n; ++i) {
417  const ProductID pid(refs[i].id());
418  if (offset_.find(pid)==offset_.end()) {
419  const string& label(iEvent.getProvenance(pid).moduleLabel());
420  const string& instance(iEvent.getProvenance(pid).productInstanceName());
421  const string& process(iEvent.getProvenance(pid).processName());
422  LogError("TriggerSummaryProducerAOD")
423  << "Uunknown pid:"
424  << " FilterTag/Key: " << tag.encode()
425  << "/" << i
426  << " CollectionTag/Key: "
427  << InputTag(label,instance,process).encode()
428  << "/" << refs[i].key()
429  << " CollectionType: " << typeid(C).name();
430  } else {
431  fillFilterObjectMember(offset_[pid],ids[i],refs[i]);
432  }
433  }
434  return;
435 
436 }
437 
438 template <typename C>
439 void TriggerSummaryProducerAOD::fillFilterObjectMember(const int& offset, const int& id, const edm::Ref<C> & ref) {
440 
441  keys_.push_back(offset+ref.key());
442  ids_.push_back(id);
443 
444  return;
445 }
446 
448 
449  using namespace trigger;
450 
451  if (id==TriggerL1HfBitCounts) {
452  keys_.push_back(offset+2*ref.key()+1);
453  } else { // if (ids[i]==TriggerL1HfRingEtSums) {
454  keys_.push_back(offset+2*ref.key()+0);
455  }
456  ids_.push_back(id);
457 
458  return;
459 }
460 
462 
463  using namespace trigger;
464 
465  if ( (id==TriggerL1ETT) || (id==TriggerL1HTT) ) {
466  keys_.push_back(offset+2*ref.key()+1);
467  } else {
468  keys_.push_back(offset+2*ref.key()+0);
469  }
470  ids_.push_back(id);
471 
472  return;
473 }
474 
476 
477  using namespace trigger;
478 
479  if ( (id==TriggerTHT) || (id==TriggerTET) ) {
480  keys_.push_back(offset+4*ref.key()+1);
481  } else if ( (id==TriggerMETSig) || (id==TriggerMHTSig) ) {
482  keys_.push_back(offset+4*ref.key()+2);
483  } else if ( (id==TriggerELongit) || (id==TriggerHLongit) ) {
484  keys_.push_back(offset+4*ref.key()+3);
485  } else {
486  keys_.push_back(offset+4*ref.key()+0);
487  }
488  ids_.push_back(id);
489 
490  return;
491 }
492 
494 
495  using namespace trigger;
496 
497  if ( (id==TriggerTHT) || (id==TriggerTET) ) {
498  keys_.push_back(offset+4*ref.key()+1);
499  } else if ( (id==TriggerMETSig) || (id==TriggerMHTSig) ) {
500  keys_.push_back(offset+4*ref.key()+2);
501  } else if ( (id==TriggerELongit) || (id==TriggerHLongit) ) {
502  keys_.push_back(offset+4*ref.key()+3);
503  } else {
504  keys_.push_back(offset+4*ref.key()+0);
505  }
506  ids_.push_back(id);
507 
508  return;
509 }
510 
512 
513  using namespace std;
514  using namespace edm;
515  using namespace trigger;
516 
517  LogVerbatim("TriggerSummaryProducerAOD") << endl;
518  LogVerbatim("TriggerSummaryProducerAOD") << "TriggerSummaryProducerAOD::endJob - accumulated tags:" << endl;
519 
520  const unsigned int nc(collectionTagsGlobal_.size());
521  const unsigned int nf(filterTagsGlobal_.size());
522  LogVerbatim("TriggerSummaryProducerAOD") << " Overall number of Collections/Filters: "
523  << nc << "/" << nf << endl;
524 
525  LogVerbatim("TriggerSummaryProducerAOD") << " The collections: " << nc << endl;
526  const InputTagSet::const_iterator cb(collectionTagsGlobal_.begin());
527  const InputTagSet::const_iterator ce(collectionTagsGlobal_.end());
528  for ( InputTagSet::const_iterator ci=cb; ci!=ce; ++ci) {
529  LogVerbatim("TriggerSummaryProducerAOD") << " " << distance(cb,ci) << " " << ci->encode() << endl;
530  }
531 
532  LogVerbatim("TriggerSummaryProducerAOD") << " The filters:" << nf << endl;
533  const InputTagSet::const_iterator fb(filterTagsGlobal_.begin());
534  const InputTagSet::const_iterator fe(filterTagsGlobal_.end());
535  for ( InputTagSet::const_iterator fi=fb; fi!=fe; ++fi) {
536  LogVerbatim("TriggerSummaryProducerAOD") << " " << distance(fb,fi) << " " << fi->encode() << endl;
537  }
538 
539  LogVerbatim("TriggerSummaryProducerAOD") << "TriggerSummaryProducerAOD::endJob." << endl;
540  LogVerbatim("TriggerSummaryProducerAOD") << endl;
541 
542  return;
543 
544 }
#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
const std::string & label
Definition: MVAComputer.cc:186
trigger::TriggerObjectCollection toc_
trigger object collection
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:84
Definition: MET.h:32
void getMany(SelectorBase const &sel, std::vector< Handle< PROD > > &results) const
Definition: Event.h:387
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)
std::vector< edm::Handle< trigger::TriggerFilterObjectWithRefs > > fobs_
handles to the filter objects
key_type key() const
Accessor for product key.
Definition: Ref.h:265
std::string const & moduleLabel() const
Definition: Provenance.h:62
tuple process
Definition: align_tpl.py:3
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:65
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:61
long double T
tuple size
Write out results.
std::vector< int > Vids
const std::string * moduleLabel() const
Definition: HLTadd.h:40