CMS 3D CMS Logo

PATTriggerProducer.cc
Go to the documentation of this file.
1 //
2 //
3 
4 
6 
7 #include <vector>
8 #include <map>
9 #include <utility>
10 #include <cassert>
11 #include <string>
12 
14 
24 
30 
33 
35 
36 using namespace pat;
37 using namespace edm;
38 
39 
40 // Constants' definitions
44 
45 
47  nameProcess_( iConfig.getParameter< std::string >( "processName" ) ),
48  autoProcessName_( nameProcess_ == "*" ),
49  onlyStandAlone_( iConfig.getParameter< bool >( "onlyStandAlone" ) ),
50  firstInRun_( true ),
51  // L1 configuration parameters
52  addL1Algos_( false ),
53  tagL1GlobalTriggerObjectMaps_( "l1L1GtObjectMap" ),
54  tagL1ExtraMu_(),
55  tagL1ExtraNoIsoEG_(),
56  tagL1ExtraIsoEG_(),
57  tagL1ExtraCenJet_(),
58  tagL1ExtraForJet_(),
59  tagL1ExtraTauJet_(),
60  tagL1ExtraETM_(),
61  tagL1ExtraHTM_(),
62  autoProcessNameL1ExtraMu_( false ),
63  autoProcessNameL1ExtraNoIsoEG_( false ),
64  autoProcessNameL1ExtraIsoEG_( false ),
65  autoProcessNameL1ExtraCenJet_( false ),
66  autoProcessNameL1ExtraForJet_( false ),
67  autoProcessNameL1ExtraTauJet_( false ),
68  autoProcessNameL1ExtraETM_( false ),
69  autoProcessNameL1ExtraHTM_( false ),
70  mainBxOnly_( true ),
71  saveL1Refs_( false ),
72  hltPrescaleProvider_(iConfig, consumesCollector(), *this),
73  hltConfigInit_( false ),
74  // HLT configuration parameters
75  tagTriggerResults_( "TriggerResults" ),
76  tagTriggerEvent_( "hltTriggerSummaryAOD" ),
77  hltPrescaleLabel_(),
78  labelHltPrescaleTable_(),
79  hltPrescaleTableRun_(),
80  hltPrescaleTableLumi_(),
81  addPathModuleLabels_( false ),
82  packPathNames_( iConfig.existsAs<bool>("packTriggerPathNames") ? iConfig.getParameter<bool>("packTriggerPathNames") : false ),
83  packLabels_( iConfig.existsAs<bool>("packTriggerLabels") ? iConfig.getParameter<bool>("packTriggerLabels") : true ),
84  packPrescales_( iConfig.existsAs<bool>("packTriggerPrescales") ? iConfig.getParameter<bool>("packTriggerPrescales") : true )
85 {
86 
87  // L1 configuration parameters
88  if ( iConfig.exists( "addL1Algos" ) ) addL1Algos_ = iConfig.getParameter< bool >( "addL1Algos" );
89  if ( iConfig.exists( "l1GlobalTriggerObjectMaps" ) ) tagL1GlobalTriggerObjectMaps_ = iConfig.getParameter< InputTag >( "l1GlobalTriggerObjectMaps" );
90  l1GlobalTriggerObjectMapsToken_ = mayConsume< L1GlobalTriggerObjectMaps >( tagL1GlobalTriggerObjectMaps_ );
91  if ( iConfig.exists( "l1ExtraMu" ) ) {
92  tagL1ExtraMu_ = iConfig.getParameter< InputTag >( "l1ExtraMu" );
93  if ( tagL1ExtraMu_.process() == "*" ) {
96  }
98  }
99  if ( iConfig.exists( "l1ExtraNoIsoEG" ) ) {
100  tagL1ExtraNoIsoEG_ = iConfig.getParameter< InputTag >( "l1ExtraNoIsoEG" );
101  if ( tagL1ExtraNoIsoEG_.process() == "*" ) {
104  }
106  }
107  if ( iConfig.exists( "l1ExtraIsoEG" ) ) {
108  tagL1ExtraIsoEG_ = iConfig.getParameter< InputTag >( "l1ExtraIsoEG" );
109  if ( tagL1ExtraIsoEG_.process() == "*" ) {
112  }
114  }
115  if ( iConfig.exists( "l1ExtraCenJet" ) ) {
116  tagL1ExtraCenJet_ = iConfig.getParameter< InputTag >( "l1ExtraCenJet" );
117  if ( tagL1ExtraCenJet_.process() == "*" ) {
120  }
122  }
123  if ( iConfig.exists( "l1ExtraForJet" ) ) {
124  tagL1ExtraForJet_ = iConfig.getParameter< InputTag >( "l1ExtraForJet" );
125  if ( tagL1ExtraForJet_.process() == "*" ) {
128  }
130  }
131  if ( iConfig.exists( "l1ExtraTauJet" ) ) {
132  tagL1ExtraTauJet_ = iConfig.getParameter< InputTag >( "l1ExtraTauJet" );
133  if ( tagL1ExtraTauJet_.process() == "*" ) {
136  }
138  }
139  if ( iConfig.exists( "l1ExtraETM" ) ) {
140  tagL1ExtraETM_ = iConfig.getParameter< InputTag >( "l1ExtraETM" );
141  if ( tagL1ExtraETM_.process() == "*" ) {
144  }
146  }
147  if ( iConfig.exists( "l1ExtraHTM" ) ) {
148  tagL1ExtraHTM_ = iConfig.getParameter< InputTag >( "l1ExtraHTM" );
149  if ( tagL1ExtraHTM_.process() == "*" ) {
152  }
154  }
155  if ( iConfig.exists( "mainBxOnly" ) ) mainBxOnly_ = iConfig.getParameter< bool >( "mainBxOnly" );
156  if ( iConfig.exists( "saveL1Refs" ) ) saveL1Refs_ = iConfig.getParameter< bool >( "saveL1Refs" );
157 
158  // HLT configuration parameters
159  if ( iConfig.exists( "triggerResults" ) ) tagTriggerResults_ = iConfig.getParameter< InputTag >( "triggerResults" );
161  if ( iConfig.exists( "triggerEvent" ) ) tagTriggerEvent_ = iConfig.getParameter< InputTag >( "triggerEvent" );
163  if ( iConfig.exists( "hltPrescaleLabel" ) ) hltPrescaleLabel_ = iConfig.getParameter< std::string >( "hltPrescaleLabel" );
164  if ( iConfig.exists( "hltPrescaleTable" ) ) {
165  labelHltPrescaleTable_ = iConfig.getParameter< std::string >( "hltPrescaleTable" );
169  }
170  if ( iConfig.exists( "addPathModuleLabels" ) ) addPathModuleLabels_ = iConfig.getParameter< bool >( "addPathModuleLabels" );
171  exludeCollections_.clear();
172  if ( iConfig.exists( "exludeCollections" ) ) exludeCollections_ = iConfig.getParameter< std::vector< std::string > >( "exludeCollections" );
173 
174  callWhenNewProductsRegistered( [ this, &iConfig ]( BranchDescription const& bd ) {
175  if ( iConfig.exists( "l1ExtraMu" ) ) l1ExtraMuGetter_( bd );
176  if ( iConfig.exists( "l1ExtraNoIsoEG" ) ) l1ExtraNoIsoEGGetter_( bd );
177  if ( iConfig.exists( "l1ExtraIsoEG" ) ) l1ExtraIsoEGGetter_( bd );
178  if ( iConfig.exists( "l1ExtraCenJet" ) ) l1ExtraCenJetGetter_( bd );
179  if ( iConfig.exists( "l1ExtraForJet" ) ) l1ExtraForJetGetter_( bd );
180  if ( iConfig.exists( "l1ExtraTauJet" ) ) l1ExtraTauJetGetter_( bd );
181  if ( iConfig.exists( "l1ExtraETM" ) ) l1ExtraETMGetter_( bd );
182  if ( iConfig.exists( "l1ExtraHTM" ) ) l1ExtraHTMGetter_( bd );
183  if(not ( this->autoProcessName_ and bd.processName()==this->moduleDescription().processName()) ) {
184  triggerResultsGetter_( bd );
185  }
186  triggerEventGetter_( bd );
187  if ( iConfig.exists( "hltPrescaleTable" ) ) {
191  }
192  } );
193 
194  if ( ! onlyStandAlone_ ) {
195  produces< TriggerAlgorithmCollection >();
196  produces< TriggerConditionCollection >();
197  produces< TriggerPathCollection >();
198  produces< TriggerFilterCollection >();
199  produces< TriggerObjectCollection >();
200  }
201  if (packPrescales_) {
202  produces< PackedTriggerPrescales >();
203  produces< PackedTriggerPrescales >("l1max");
204  produces< PackedTriggerPrescales >("l1min");
205  }
206  produces< TriggerObjectStandAloneCollection >();
207 
208 }
209 
210 
211 void PATTriggerProducer::beginRun(const Run & iRun, const EventSetup & iSetup )
212 {
213 
214  // Initialize
215  firstInRun_ = true;
216  l1PSet_ = nullptr;
217  hltConfigInit_ = false;
218 
219  // Initialize process name
220  if ( autoProcessName_ ) {
221  // reset
222  nameProcess_ = "*";
223  // determine process name from last run TriggerSummaryProducerAOD module in process history of input
224  const ProcessHistory & processHistory( iRun.processHistory() );
225  ProcessConfiguration processConfiguration;
226  ParameterSet processPSet;
227  // unbroken loop, which relies on time ordering (accepts the last found entry)
228  for ( ProcessHistory::const_iterator iHist = processHistory.begin(); iHist != processHistory.end(); ++iHist ) {
229  if ( processHistory.getConfigurationForProcess( iHist->processName(), processConfiguration ) &&
230  pset::Registry::instance()->getMapped( processConfiguration.parameterSetID(), processPSet ) &&
231  processPSet.exists( tagTriggerEvent_.label() )
232  ) {
233  nameProcess_ = iHist->processName();
234  LogDebug( "autoProcessName" ) << "HLT process name '" << nameProcess_ << "' discovered";
235  }
236  }
237  // terminate, if nothing is found
238  if ( nameProcess_ == "*" ) {
239  LogError( "autoProcessName" ) << "trigger::TriggerEvent product with label '" << tagTriggerEvent_.label() << "' not produced according to process history of input data\n"
240  << "No trigger information produced";
241  return;
242  }
243  LogInfo( "autoProcessName" ) << "HLT process name' " << nameProcess_ << "' used for PAT trigger information";
244  }
245  // adapt configuration of used input tags
246  if ( tagTriggerResults_.process().empty() || tagTriggerResults_.process() == "*" ) {
248  } else if ( tagTriggerEvent_.process() != nameProcess_ ) {
249  LogWarning( "inputTags" ) << "TriggerResults process name '" << tagTriggerResults_.process() << "' differs from HLT process name '" << nameProcess_ << "'";
250  }
251  if ( tagTriggerEvent_.process().empty() || tagTriggerEvent_.process() == "*" ) {
253  } else if ( tagTriggerEvent_.process() != nameProcess_ ) {
254  LogWarning( "inputTags" ) << "TriggerEvent process name '" << tagTriggerEvent_.process() << "' differs from HLT process name '" << nameProcess_ << "'";
255  }
264 
265  // Initialize HLTConfigProvider
267  bool changed( true );
268  if ( ! hltPrescaleProvider_.init( iRun, iSetup, nameProcess_, changed ) ) {
269  LogError( "hltConfig" ) << "HLT config extraction error with process name '" << nameProcess_ << "'";
270  } else if ( hltConfig.size() <= 0 ) {
271  LogError( "hltConfig" ) << "HLT config size error";
272  } else hltConfigInit_ = true;
273 
274  // Update mapping from filter names to path names
275  if (hltConfigInit_ && changed) moduleLabelToPathAndFlags_.init( hltConfig );
276 
277  // Extract pre-scales
278  if ( hltConfigInit_ ) {
279  // Start empty
281  // Try run product, if configured
282  if ( ! labelHltPrescaleTable_.empty() ) {
283  Handle< trigger::HLTPrescaleTable > handleHltPrescaleTable;
284  iRun.getByLabel( InputTag( labelHltPrescaleTable_, "Run", nameProcess_ ), handleHltPrescaleTable );
285  if ( handleHltPrescaleTable.isValid() ) {
286  hltPrescaleTableRun_ = trigger::HLTPrescaleTable( handleHltPrescaleTable->set(), handleHltPrescaleTable->labels(), handleHltPrescaleTable->table() );
287  }
288  }
289  }
290 
291 }
292 
293 
294 void PATTriggerProducer::beginLuminosityBlock(const LuminosityBlock & iLuminosityBlock, const EventSetup & iSetup )
295 {
296 
297  // Terminate, if auto process name determination failed
298  if ( nameProcess_ == "*" ) return;
299 
300  // Extract pre-scales
301  if ( hltConfigInit_ ) {
302  // Start from run
304  // Try lumi product, if configured and available
305  if ( ! labelHltPrescaleTable_.empty() ) {
306  Handle< trigger::HLTPrescaleTable > handleHltPrescaleTable;
307  iLuminosityBlock.getByLabel( InputTag( labelHltPrescaleTable_, "Lumi", nameProcess_ ), handleHltPrescaleTable );
308  if ( handleHltPrescaleTable.isValid() ) {
309  hltPrescaleTableLumi_ = trigger::HLTPrescaleTable( handleHltPrescaleTable->set(), handleHltPrescaleTable->labels(), handleHltPrescaleTable->table() );
310  }
311  }
312  }
313 
314 }
315 
316 
318 {
319 
320  // Terminate, if auto process name determination failed
321  if ( nameProcess_ == "*" ) return;
322 
323  auto triggerObjects = std::make_unique<TriggerObjectCollection>();
324  auto triggerObjectsStandAlone = std::make_unique<TriggerObjectStandAloneCollection>();
325  std::unique_ptr<PackedTriggerPrescales> packedPrescales, packedPrescalesL1min, packedPrescalesL1max;
326 
327  // HLT
329 
330  // Get and check HLT event data
331  Handle< trigger::TriggerEvent > handleTriggerEvent;
332  iEvent.getByLabel( tagTriggerEvent_, handleTriggerEvent );
333  Handle< TriggerResults > handleTriggerResults;
334  iEvent.getByLabel( tagTriggerResults_, handleTriggerResults );
335  bool goodHlt( hltConfigInit_ );
336  if ( goodHlt ) {
337  if( ! handleTriggerResults.isValid() ) {
338  LogError( "triggerResultsValid" ) << "TriggerResults product with InputTag '" << tagTriggerResults_.encode() << "' not in event\n"
339  << "No HLT information produced";
340  goodHlt = false;
341  } else if ( ! handleTriggerEvent.isValid() ) {
342  LogError( "triggerEventValid" ) << "trigger::TriggerEvent product with InputTag '" << tagTriggerEvent_.encode() << "' not in event\n"
343  << "No HLT information produced";
344  goodHlt = false;
345  }
346  }
347 
348  // Produce HLT paths and determine status of modules
349 
350  if ( goodHlt ) {
351 
352  // Extract pre-scales
353  // Start from lumi
355  // Try event product, if configured and available
356  if ( ! labelHltPrescaleTable_.empty() ) {
357  Handle< trigger::HLTPrescaleTable > handleHltPrescaleTable;
358  iEvent.getByLabel( InputTag( labelHltPrescaleTable_, "Event", nameProcess_ ), handleHltPrescaleTable );
359  if ( handleHltPrescaleTable.isValid() ) {
360  hltPrescaleTable = trigger::HLTPrescaleTable( handleHltPrescaleTable->set(), handleHltPrescaleTable->labels(), handleHltPrescaleTable->table() );
361  }
362  }
363  // Try event setup, if no product
364  if ( hltPrescaleTable.size() == 0 ) {
365  if ( ! labelHltPrescaleTable_.empty() ) {
366  LogWarning( "hltPrescaleInputTag" ) << "HLTPrescaleTable product with label '" << labelHltPrescaleTable_ << "' not found in process" << nameProcess_ << "\n"
367  << "Using default from event setup";
368  }
369  if ( hltConfig.prescaleSize() > 0 ) {
370  if ( hltPrescaleProvider_.prescaleSet( iEvent, iSetup ) != -1 ) {
371  hltPrescaleTable = trigger::HLTPrescaleTable( hltPrescaleProvider_.prescaleSet( iEvent, iSetup ), hltConfig.prescaleLabels(), hltConfig.prescaleTable() );
372  LogDebug( "hltPrescaleTable" ) << "HLT prescale table found in event setup";
373  } else {
374  LogWarning( "hltPrescaleSet" ) << "HLTPrescaleTable from event setup has error";
375  }
376  }
377  }
378  unsigned set( hltPrescaleTable.set() );
379  if ( hltPrescaleTable.size() > 0 ) {
380  if ( !hltPrescaleLabel_.empty() ) {
381  bool foundPrescaleLabel( false );
382  for ( unsigned iLabel = 0; iLabel < hltPrescaleTable.labels().size(); ++iLabel ) {
383  if ( hltPrescaleTable.labels().at( iLabel ) == hltPrescaleLabel_ ) {
384  set = iLabel;
385  foundPrescaleLabel = true;
386  break;
387  }
388  }
389  if ( ! foundPrescaleLabel ) {
390  LogWarning( "hltPrescaleLabel" ) << "HLT prescale label '" << hltPrescaleLabel_ << "' not in prescale table\n"
391  << "Using default";
392  }
393  }
394  } else if ( iEvent.isRealData() ) {
395  if ( ( labelHltPrescaleTable_.empty() && firstInRun_ ) || ! labelHltPrescaleTable_.empty() ) {
396  LogError( "hltPrescaleTable" ) << "No HLT prescale table found\n"
397  << "Using default empty table with all prescales 1";
398  }
399  }
400 
401  const unsigned sizePaths( hltConfig.size() );
402  const unsigned sizeFilters( handleTriggerEvent->sizeFilters() );
403  const unsigned sizeObjects( handleTriggerEvent->sizeObjects() );
404 
405  std::map< std::string, int > moduleStates;
406 
407  if ( ! onlyStandAlone_ ) {
408  auto triggerPaths = std::make_unique<TriggerPathCollection>();
409  triggerPaths->reserve( sizePaths );
410  const std::vector<std::string> & pathNames = hltConfig.triggerNames();
411  for ( size_t indexPath = 0; indexPath < sizePaths; ++indexPath ) {
412  const std::string & namePath = pathNames.at( indexPath );
413  unsigned indexLastFilterPathModules( handleTriggerResults->index( indexPath ) + 1 );
414  while ( indexLastFilterPathModules > 0 ) {
415  --indexLastFilterPathModules;
416  const std::string & labelLastFilterPathModules( hltConfig.moduleLabel( indexPath, indexLastFilterPathModules ) );
417  unsigned indexLastFilterFilters = handleTriggerEvent->filterIndex( InputTag( labelLastFilterPathModules, "", nameProcess_ ) );
418  if ( indexLastFilterFilters < sizeFilters ) {
419  if ( hltConfig.moduleType( labelLastFilterPathModules ) == "HLTBool" ) continue;
420  break;
421  }
422  }
423  TriggerPath triggerPath( namePath, indexPath, hltConfig.prescaleValue( set, namePath ), handleTriggerResults->wasrun( indexPath ), handleTriggerResults->accept( indexPath ), handleTriggerResults->error( indexPath ), indexLastFilterPathModules, hltConfig.saveTagsModules( namePath ).size() );
424  // add module names to path and states' map
425  const unsigned sizeModulesPath( hltConfig.size( indexPath ) );
426  assert( indexLastFilterPathModules < sizeModulesPath );
427  std::map< unsigned, std::string > indicesModules;
428  for ( size_t iM = 0; iM < sizeModulesPath; ++iM ) {
429  const std::string& nameModule( hltConfig.moduleLabel( indexPath, iM ) );
430  if ( addPathModuleLabels_ ) {
431  triggerPath.addModule( nameModule );
432  }
433  const unsigned indexFilter( handleTriggerEvent->filterIndex( InputTag( nameModule, "", nameProcess_ ) ) );
434  if ( indexFilter < sizeFilters ) {
435  triggerPath.addFilterIndex( indexFilter );
436  }
437  const unsigned slotModule( hltConfig.moduleIndex( indexPath, nameModule ) );
438  indicesModules.insert( std::pair< unsigned, std::string >( slotModule, nameModule ) );
439  }
440  // add L1 seeds
441  const L1SeedCollection& l1Seeds( hltConfig.hltL1GTSeeds( namePath ) );
442  for ( L1SeedCollection::const_iterator iSeed = l1Seeds.begin(); iSeed != l1Seeds.end(); ++iSeed ) {
443  triggerPath.addL1Seed( *iSeed );
444  }
445  // store path
446  triggerPaths->push_back( triggerPath );
447  // cache module states to be used for the filters
448  for ( std::map< unsigned, std::string >::const_iterator iM = indicesModules.begin(); iM != indicesModules.end(); ++iM ) {
449  if ( iM->first < indexLastFilterPathModules ) {
450  moduleStates[ iM->second ] = 1;
451  } else if ( iM->first == indexLastFilterPathModules ) {
452  moduleStates[ iM->second ] = handleTriggerResults->accept( indexPath );
453  } else if ( moduleStates.find( iM->second ) == moduleStates.end() ) {
454  moduleStates[ iM->second ] = -1;
455  }
456  }
457  }
458  // Put HLT paths to event
459  iEvent.put(std::move(triggerPaths));
460  }
461 
462  // Store used trigger objects and their types for HLT filters
463  // (only active filter(s) available from trigger::TriggerEvent)
464 
465  std::multimap< trigger::size_type, int > objectTypes;
466  std::multimap< trigger::size_type, std::string > filterLabels;
467 
468  for ( size_t iF = 0; iF < sizeFilters; ++iF ) {
469  const std::string nameFilter( handleTriggerEvent->filterLabel( iF ) );
470  const trigger::Keys & keys = handleTriggerEvent->filterKeys( iF );
471  const trigger::Vids & types = handleTriggerEvent->filterIds( iF );
472  assert( types.size() == keys.size() );
473  for ( size_t iK = 0; iK < keys.size(); ++iK ) {
474  filterLabels.insert( std::pair< trigger::size_type, std::string >( keys[ iK ], nameFilter ) );
475  objectTypes.insert( std::pair< trigger::size_type, int >( keys[ iK ], types[ iK ] ) );
476  }
477  }
478 
479  // HLT objects
480 
481  triggerObjects->reserve( onlyStandAlone_ ? 0 : sizeObjects );
482  triggerObjectsStandAlone->reserve( sizeObjects );
483 
484  const trigger::Keys & collectionKeys( handleTriggerEvent->collectionKeys() );
485  std::map< trigger::size_type, trigger::size_type > newObjectKeys;
486  for ( size_t iO = 0, iC = 0, nC = handleTriggerEvent->sizeCollections(); iO < sizeObjects && iC < nC; ++iO ) {
487  const trigger::TriggerObject tobj = handleTriggerEvent->getObjects().at( iO );
488  TriggerObject triggerObject( reco::Particle::PolarLorentzVector(tobj.pt(), tobj.eta(), tobj.phi(), tobj.mass()), tobj.id() );
489  // set collection
490  while ( iO >= collectionKeys[ iC ] ) ++iC; // relies on well ordering of trigger objects with respect to the collections
491  triggerObject.setCollection( handleTriggerEvent->collectionTagEncoded( iC ) );
492  // set filter ID
493  typedef std::multimap< trigger::size_type, int >::const_iterator it_type;
494  for (std::pair<it_type,it_type> trange = objectTypes.equal_range(iO);
495  trange.first != trange.second; ++trange.first) {
496  triggerObject.addTriggerObjectType( trange.first->second );
497  }
498 
499  // stand-alone trigger object
500  TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
501  // check for excluded collections
502  bool excluded( false );
503  for ( size_t iE = 0; iE < exludeCollections_.size(); ++iE ) {
504  if ( triggerObjectStandAlone.hasCollection( exludeCollections_.at( iE ) ) ) {
505  if ( ! onlyStandAlone_ ) newObjectKeys[ iO ] = trigger::size_type( sizeObjects );
506  excluded = true;
507  break;
508  }
509  }
510  if ( excluded ) continue;
511  typedef std::multimap< trigger::size_type, std::string >::const_iterator it_fl;
512  for (std::pair<it_fl,it_fl> frange = filterLabels.equal_range(iO); frange.first != frange.second; ++frange.first) {
513  triggerObjectStandAlone.addFilterLabel( frange.first->second );
514  const std::vector<ModuleLabelToPathAndFlags::PathAndFlags> & paths = moduleLabelToPathAndFlags_[frange.first->second];
515  for (std::vector<ModuleLabelToPathAndFlags::PathAndFlags>::const_iterator iP = paths.begin(); iP != paths.end(); ++iP) {
516  bool pathFired = handleTriggerResults->wasrun( iP->pathIndex ) && handleTriggerResults->accept( iP->pathIndex );
517  triggerObjectStandAlone.addPathName( iP->pathName, pathFired && iP->lastFilter, pathFired && iP->l3Filter );
518  }
519  }
520 
521  triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
522  if ( ! onlyStandAlone_ ) {
523  triggerObjects->push_back( triggerObject );
524  newObjectKeys[ iO ] = trigger::size_type( triggerObjects->size() - 1 );
525  }
526  }
527 
528  // Re-iterate HLT filters and finally produce them in order to account for optionally skipped objects
529  if ( ! onlyStandAlone_ ) {
530  auto triggerFilters = std::make_unique<TriggerFilterCollection>();
531  triggerFilters->reserve( sizeFilters );
532  for ( size_t iF = 0; iF < sizeFilters; ++iF ) {
533  const std::string nameFilter( handleTriggerEvent->filterTag( iF ).label() );
534  const trigger::Keys & keys = handleTriggerEvent->filterKeys( iF ); // not cached
535  const trigger::Vids & types = handleTriggerEvent->filterIds( iF ); // not cached
536  TriggerFilter triggerFilter( nameFilter );
537  // set filter type
538  const std::string typeFilter( hltConfig.moduleType( nameFilter ) );
539  triggerFilter.setType( typeFilter );
540  triggerFilter.setSaveTags( hltConfig.saveTags( nameFilter ) );
541  // set keys and trigger object types of used objects
542  for ( size_t iK = 0; iK < keys.size(); ++iK ) { // identical to types.size()
543  // check, if current object is excluded
544  if ( newObjectKeys.find( keys.at( iK ) ) != newObjectKeys.end() ) {
545  if ( newObjectKeys[ keys.at( iK ) ] == sizeObjects ) continue;
546  triggerFilter.addObjectKey( newObjectKeys[ keys.at( iK ) ] );
547  triggerFilter.addTriggerObjectType( types.at( iK ) );
548  } else {
549  LogWarning( "triggerObjectKey" ) << "TriggerFilter '" << nameFilter << "' requests non-existing TriggerObject key " << keys.at( iK ) << "\n"
550  << "Skipping object assignment";
551  }
552  }
553  // set status from path info
554  std::map< std::string, int >::iterator iS( moduleStates.find( nameFilter ) );
555  if ( iS != moduleStates.end() ) {
556  if ( ! triggerFilter.setStatus( iS->second ) ) {
557  triggerFilter.setStatus( -1 ); // FIXME different code for "unvalid status determined" needed?
558  }
559  } else {
560  triggerFilter.setStatus( -1 ); // FIXME different code for "unknown" needed?
561  }
562  // store filter
563  triggerFilters->push_back( triggerFilter );
564  }
565  // put HLT filters to event
566  iEvent.put(std::move(triggerFilters));
567  }
568 
569  if (packPrescales_) {
570  packedPrescales.reset(new PackedTriggerPrescales(handleTriggerResults));
571  packedPrescalesL1min.reset(new PackedTriggerPrescales(handleTriggerResults));
572  packedPrescalesL1max.reset(new PackedTriggerPrescales(handleTriggerResults));
573  const edm::TriggerNames & names = iEvent.triggerNames(*handleTriggerResults);
574  //std::cout << "Run " << iEvent.id().run() << ", LS " << iEvent.id().luminosityBlock() << ": pset " << set << std::endl;
575  for (unsigned int i = 0, n = names.size(); i < n; ++i) {
576  auto pvdet = hltPrescaleProvider_.prescaleValuesInDetail( iEvent, iSetup, names.triggerName(i) );
577  //int hltprescale = hltConfig_.prescaleValue(set, names.triggerName(i));
578  if (pvdet.first.empty()) {
579  packedPrescalesL1max->addPrescaledTrigger(i, 1);
580  packedPrescalesL1min->addPrescaledTrigger(i, 1);
581  } else {
582  int pmin = -1, pmax = -1;
583  for (const auto & p : pvdet.first) {
584  pmax = std::max(pmax, p.second);
585  if (p.second > 0 && (pmin == -1 || pmin > p.second)) pmin = p.second;
586  }
587  packedPrescalesL1max->addPrescaledTrigger(i, pmax);
588  packedPrescalesL1min->addPrescaledTrigger(i, pmin);
589  //std::cout << "\tTrigger " << names.triggerName(i) << ", L1 ps " << pmin << "-" << pmax << ", HLT ps " << hltprescale << std::endl;
590  }
591  packedPrescales->addPrescaledTrigger(i, pvdet.second);
592  //assert( hltprescale == pvdet.second );
593  }
594  iEvent.put(std::move(packedPrescales));
595  iEvent.put(std::move(packedPrescalesL1max), "l1max");
596  iEvent.put(std::move(packedPrescalesL1min), "l1min");
597  }
598 
599  } // if ( goodHlt )
600 
601  // L1 objects
602  // (needs to be done after HLT objects, since their x-links with filters rely on their collection keys)
603 
604  // map for assignments of objects to conditions
605  std::map< L1GtObject, std::vector< unsigned > > l1ObjectTypeMap;
606  if ( ! tagL1ExtraMu_.label().empty() ) {
608  iEvent.getByLabel( tagL1ExtraMu_, handleL1ExtraMu );
609  if ( handleL1ExtraMu.isValid() ) {
610  std::vector< unsigned > muKeys;
611  for ( size_t l1Mu = 0; l1Mu < handleL1ExtraMu->size(); ++l1Mu ) {
612  if ( mainBxOnly_ && handleL1ExtraMu->at( l1Mu ).bx() != 0 ) continue;
613  TriggerObject triggerObject;
614  if ( saveL1Refs_ ) {
615  const reco::CandidateBaseRef leafCandRef( l1extra::L1MuonParticleRef( handleL1ExtraMu, l1Mu ) );
616  triggerObject = TriggerObject( leafCandRef );
617  } else {
618  const reco::LeafCandidate leafCandidate( *( handleL1ExtraMu->at( l1Mu ).reco::LeafCandidate::clone() ) );
619  triggerObject = TriggerObject( leafCandidate );
620  }
621  triggerObject.setCollection( tagL1ExtraMu_ );
623  if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
624  TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
625  triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
626  if ( handleL1ExtraMu->at( l1Mu ).bx() == 0 ) muKeys.push_back( triggerObjectsStandAlone->size() - 1 );
627  }
628  l1ObjectTypeMap.insert( std::make_pair( Mu, muKeys ) );
629  } else LogError( "l1ExtraValid" ) << "l1extra::L1MuonParticleCollection product with InputTag '" << tagL1ExtraMu_.encode() << "' not in event";
630  }
631  if ( ! tagL1ExtraNoIsoEG_.label().empty() ) {
632  Handle< l1extra::L1EmParticleCollection > handleL1ExtraNoIsoEG;
633  iEvent.getByLabel( tagL1ExtraNoIsoEG_, handleL1ExtraNoIsoEG );
634  if ( handleL1ExtraNoIsoEG.isValid() ) {
635  std::vector< unsigned > noIsoEGKeys;
636  for ( size_t l1NoIsoEG = 0; l1NoIsoEG < handleL1ExtraNoIsoEG->size(); ++l1NoIsoEG ) {
637  if ( mainBxOnly_ && handleL1ExtraNoIsoEG->at( l1NoIsoEG ).bx() != 0 ) continue;
638  TriggerObject triggerObject;
639  if ( saveL1Refs_ ) {
640  const reco::CandidateBaseRef leafCandRef( l1extra::L1EmParticleRef( handleL1ExtraNoIsoEG, l1NoIsoEG ) );
641  triggerObject = TriggerObject( leafCandRef );
642  } else {
643  const reco::LeafCandidate leafCandidate( *( handleL1ExtraNoIsoEG->at( l1NoIsoEG ).reco::LeafCandidate::clone() ) );
644  triggerObject = TriggerObject( leafCandidate );
645  }
646  triggerObject.setCollection( tagL1ExtraNoIsoEG_ );
648  if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
649  TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
650  triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
651  if ( handleL1ExtraNoIsoEG->at( l1NoIsoEG ).bx() == 0 ) noIsoEGKeys.push_back( triggerObjectsStandAlone->size() - 1 );
652  }
653  l1ObjectTypeMap.insert( std::make_pair( NoIsoEG, noIsoEGKeys ) );
654  } else LogError( "l1ExtraValid" ) << "l1extra::L1EmParticleCollection product with InputTag '" << tagL1ExtraNoIsoEG_.encode() << "' not in event";
655  }
656  if ( ! tagL1ExtraIsoEG_.label().empty() ) {
658  iEvent.getByLabel( tagL1ExtraIsoEG_, handleL1ExtraIsoEG );
659  if ( handleL1ExtraIsoEG.isValid() ) {
660  std::vector< unsigned > isoEGKeys;
661  for ( size_t l1IsoEG = 0; l1IsoEG < handleL1ExtraIsoEG->size(); ++l1IsoEG ) {
662  if ( mainBxOnly_ && handleL1ExtraIsoEG->at( l1IsoEG ).bx() != 0 ) continue;
663  TriggerObject triggerObject;
664  if ( saveL1Refs_ ) {
665  const reco::CandidateBaseRef leafCandRef( l1extra::L1EmParticleRef( handleL1ExtraIsoEG, l1IsoEG ) );
666  triggerObject = TriggerObject( leafCandRef );
667  } else {
668  const reco::LeafCandidate leafCandidate( *( handleL1ExtraIsoEG->at( l1IsoEG ).reco::LeafCandidate::clone() ) );
669  triggerObject = TriggerObject( leafCandidate );
670  }
671  triggerObject.setCollection( tagL1ExtraIsoEG_ );
673  if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
674  TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
675  triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
676  if ( handleL1ExtraIsoEG->at( l1IsoEG ).bx() == 0 ) isoEGKeys.push_back( triggerObjectsStandAlone->size() - 1 );
677  }
678  l1ObjectTypeMap.insert( std::make_pair( IsoEG, isoEGKeys ) );
679  } else LogError( "l1ExtraValid" ) << "l1extra::L1EmParticleCollection product with InputTag '" << tagL1ExtraIsoEG_.encode() << "' not in event";
680  }
681  if ( ! tagL1ExtraCenJet_.label().empty() ) {
682  Handle< l1extra::L1JetParticleCollection > handleL1ExtraCenJet;
683  iEvent.getByLabel( tagL1ExtraCenJet_, handleL1ExtraCenJet );
684  if ( handleL1ExtraCenJet.isValid() ) {
685  std::vector< unsigned > cenJetKeys;
686  for ( size_t l1CenJet = 0; l1CenJet < handleL1ExtraCenJet->size(); ++l1CenJet ) {
687  if ( mainBxOnly_ && handleL1ExtraCenJet->at( l1CenJet ).bx() != 0 ) continue;
688  TriggerObject triggerObject;
689  if ( saveL1Refs_ ) {
690  const reco::CandidateBaseRef leafCandRef( l1extra::L1JetParticleRef( handleL1ExtraCenJet, l1CenJet ) );
691  triggerObject = TriggerObject( leafCandRef );
692  } else {
693  const reco::LeafCandidate leafCandidate( *( handleL1ExtraCenJet->at( l1CenJet ).reco::LeafCandidate::clone() ) );
694  triggerObject = TriggerObject( leafCandidate );
695  }
696  triggerObject.setCollection( tagL1ExtraCenJet_ );
698  if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
699  TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
700  triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
701  if ( handleL1ExtraCenJet->at( l1CenJet ).bx() == 0 ) cenJetKeys.push_back( triggerObjectsStandAlone->size() - 1 );
702  }
703  l1ObjectTypeMap.insert( std::make_pair( CenJet, cenJetKeys ) );
704  } else LogError( "l1ExtraValid" ) << "l1extra::L1JetParticleCollection product with InputTag '" << tagL1ExtraCenJet_.encode() << "' not in event";
705  }
706  if ( ! tagL1ExtraForJet_.label().empty() ) {
707  Handle< l1extra::L1JetParticleCollection > handleL1ExtraForJet;
708  iEvent.getByLabel( tagL1ExtraForJet_, handleL1ExtraForJet );
709  if ( handleL1ExtraForJet.isValid() ) {
710  std::vector< unsigned > forJetKeys;
711  for ( size_t l1ForJet = 0; l1ForJet < handleL1ExtraForJet->size(); ++l1ForJet ) {
712  if ( mainBxOnly_ && handleL1ExtraForJet->at( l1ForJet ).bx() != 0 ) continue;
713  TriggerObject triggerObject;
714  if ( saveL1Refs_ ) {
715  const reco::CandidateBaseRef leafCandRef( l1extra::L1JetParticleRef( handleL1ExtraForJet, l1ForJet ) );
716  triggerObject = TriggerObject( leafCandRef );
717  } else {
718  const reco::LeafCandidate leafCandidate( *( handleL1ExtraForJet->at( l1ForJet ).reco::LeafCandidate::clone() ) );
719  triggerObject = TriggerObject( leafCandidate );
720  }
721  triggerObject.setCollection( tagL1ExtraForJet_ );
723  if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
724  TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
725  triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
726  if ( handleL1ExtraForJet->at( l1ForJet ).bx() == 0 ) forJetKeys.push_back( triggerObjectsStandAlone->size() - 1 );
727  }
728  l1ObjectTypeMap.insert( std::make_pair( ForJet, forJetKeys ) );
729  } else LogError( "l1ExtraValid" ) << "l1extra::L1JetParticleCollection product with InputTag '" << tagL1ExtraForJet_.encode() << "' not in event";
730  }
731  if ( ! tagL1ExtraTauJet_.label().empty() ) {
732  Handle< l1extra::L1JetParticleCollection > handleL1ExtraTauJet;
733  iEvent.getByLabel( tagL1ExtraTauJet_, handleL1ExtraTauJet );
734  if ( handleL1ExtraTauJet.isValid() ) {
735  std::vector< unsigned > tauJetKeys;
736  for ( size_t l1TauJet = 0; l1TauJet < handleL1ExtraTauJet->size(); ++l1TauJet ) {
737  if ( mainBxOnly_ && handleL1ExtraTauJet->at( l1TauJet ).bx() != 0 ) continue;
738  TriggerObject triggerObject;
739  if ( saveL1Refs_ ) {
740  const reco::CandidateBaseRef leafCandRef( l1extra::L1JetParticleRef( handleL1ExtraTauJet, l1TauJet ) );
741  triggerObject = TriggerObject( leafCandRef );
742  } else {
743  const reco::LeafCandidate leafCandidate( *( handleL1ExtraTauJet->at( l1TauJet ).reco::LeafCandidate::clone() ) );
744  triggerObject = TriggerObject( leafCandidate );
745  }
746  triggerObject.setCollection( tagL1ExtraTauJet_ );
748  if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
749  TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
750  triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
751  if ( handleL1ExtraTauJet->at( l1TauJet ).bx() == 0 ) tauJetKeys.push_back( triggerObjectsStandAlone->size() - 1 );
752  }
753  l1ObjectTypeMap.insert( std::make_pair( TauJet, tauJetKeys ) );
754  } else LogError( "l1ExtraValid" ) << "l1extra::L1JetParticleCollection product with InputTag '" << tagL1ExtraTauJet_.encode() << "' not in event";
755  }
756  if ( ! tagL1ExtraETM_ .label().empty()) {
758  iEvent.getByLabel( tagL1ExtraETM_, handleL1ExtraETM );
759  if ( handleL1ExtraETM.isValid() ) {
760  std::vector< unsigned > etmKeys;
761  for ( size_t l1ETM = 0; l1ETM < handleL1ExtraETM->size(); ++l1ETM ) {
762  if ( mainBxOnly_ && handleL1ExtraETM->at( l1ETM ).bx() != 0 ) continue;
763  TriggerObject triggerObject;
764  if ( saveL1Refs_ ) {
765  const reco::CandidateBaseRef leafCandRef( l1extra::L1EtMissParticleRef( handleL1ExtraETM, l1ETM ) );
766  triggerObject = TriggerObject( leafCandRef );
767  } else {
768  const reco::LeafCandidate leafCandidate( *( handleL1ExtraETM->at( l1ETM ).reco::LeafCandidate::clone() ) );
769  triggerObject = TriggerObject( leafCandidate );
770  }
771  triggerObject.setCollection( tagL1ExtraETM_ );
773  if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
774  TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
775  triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
776  if ( handleL1ExtraETM->at( l1ETM ).bx() == 0 ) etmKeys.push_back( triggerObjectsStandAlone->size() - 1 );
777  }
778  l1ObjectTypeMap.insert( std::make_pair( ETM, etmKeys ) );
779  } else LogError( "l1ExtraValid" ) << "l1extra::L1EtMissParticleCollection product with InputTag '" << tagL1ExtraETM_.encode() << "' not in event";
780  }
781  if ( ! tagL1ExtraHTM_.label().empty() ) {
783  iEvent.getByLabel( tagL1ExtraHTM_, handleL1ExtraHTM );
784  if ( handleL1ExtraHTM.isValid() ) {
785  std::vector< unsigned > htmKeys;
786  for ( size_t l1HTM = 0; l1HTM < handleL1ExtraHTM->size(); ++l1HTM ) {
787  if ( mainBxOnly_ && handleL1ExtraHTM->at( l1HTM ).bx() != 0 ) continue;
788  TriggerObject triggerObject;
789  if ( saveL1Refs_ ) {
790  const reco::CandidateBaseRef leafCandRef( l1extra::L1EtMissParticleRef( handleL1ExtraHTM, l1HTM ) );
791  triggerObject = TriggerObject( leafCandRef );
792  } else {
793  const reco::LeafCandidate leafCandidate( *( handleL1ExtraHTM->at( l1HTM ).reco::LeafCandidate::clone() ) );
794  triggerObject = TriggerObject( leafCandidate );
795  }
796  triggerObject.setCollection( tagL1ExtraHTM_ );
798  if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
799  TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
800  triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
801  if ( handleL1ExtraHTM->at( l1HTM ).bx() == 0 ) htmKeys.push_back( triggerObjectsStandAlone->size() - 1 );
802  }
803  l1ObjectTypeMap.insert( std::make_pair( HTM, htmKeys ) );
804  } else LogError( "l1ExtraValid" ) << "l1extra::L1EtMissParticleCollection product with InputTag '" << tagL1ExtraHTM_.encode() << "' not in event";
805  }
806 
807  // Put trigger objects to event
808  if ( ! onlyStandAlone_ ) iEvent.put(std::move(triggerObjects));
809 
810  // L1 algorithms
811  if ( ! onlyStandAlone_ ) {
812  auto triggerAlgos = std::make_unique<TriggerAlgorithmCollection>();
813  auto triggerConditions = std::make_unique<TriggerConditionCollection>();
814  if ( addL1Algos_ ) {
815  // create trigger object types transalation map (yes, it's ugly!)
816  std::map< L1GtObject, trigger::TriggerObjectType > mapObjectTypes;
817  mapObjectTypes.insert( std::make_pair( Mu , trigger::TriggerL1Mu ) );
818  mapObjectTypes.insert( std::make_pair( NoIsoEG, trigger::TriggerL1NoIsoEG ) );
819  mapObjectTypes.insert( std::make_pair( IsoEG , trigger::TriggerL1IsoEG ) );
820  mapObjectTypes.insert( std::make_pair( CenJet , trigger::TriggerL1CenJet ) );
821  mapObjectTypes.insert( std::make_pair( ForJet , trigger::TriggerL1ForJet ) );
822  mapObjectTypes.insert( std::make_pair( TauJet , trigger::TriggerL1TauJet ) );
823  mapObjectTypes.insert( std::make_pair( ETM , trigger::TriggerL1ETM ) );
824  mapObjectTypes.insert( std::make_pair( HTM , trigger::TriggerL1HTM ) );
825  // get and cache L1 menu
826  L1GtUtils const& l1GtUtils = hltPrescaleProvider_.l1GtUtils();
827  ESHandle< L1GtTriggerMenu > handleL1GtTriggerMenu;
828  iSetup.get< L1GtTriggerMenuRcd >().get( handleL1GtTriggerMenu );
829  auto const & l1GtAlgorithms = handleL1GtTriggerMenu->gtAlgorithmMap();
830  auto const & l1GtTechTriggers = handleL1GtTriggerMenu->gtTechnicalTriggerMap();
831  auto const & l1GtConditionsVector = handleL1GtTriggerMenu->gtConditionMap();
832  // cache conditions in one single condition map
833  ConditionMap l1GtConditions;
834  for ( size_t iCv = 0; iCv < l1GtConditionsVector.size(); ++iCv ) {
835  l1GtConditions.insert( l1GtConditionsVector.at( iCv ).begin(), l1GtConditionsVector.at( iCv ).end() );
836  }
837  triggerAlgos->reserve( l1GtAlgorithms.size() + l1GtTechTriggers.size() );
838  Handle< L1GlobalTriggerObjectMaps > handleL1GlobalTriggerObjectMaps;
839  iEvent.getByToken( l1GlobalTriggerObjectMapsToken_, handleL1GlobalTriggerObjectMaps );
840  if( ! handleL1GlobalTriggerObjectMaps.isValid() ) {
841  LogError( "l1ObjectMap" ) << "L1GlobalTriggerObjectMaps product with InputTag '" << tagL1GlobalTriggerObjectMaps_.encode() << "' not in event\n"
842  << "No L1 objects and GTL results available for physics algorithms";
843  }
844  handleL1GlobalTriggerObjectMaps->consistencyCheck();
845  if ( firstInRun_ ) {
846  l1PSet_ = ( ParameterSet* )( pset::Registry::instance()->getMapped(handleL1GlobalTriggerObjectMaps->namesParameterSetID()) );
847  if (l1PSet_ == nullptr) {
848  LogError( "l1ObjectMap" ) << "ParameterSet registry not available\n"
849  << "Skipping conditions for all L1 physics algorithm names in this run";
850  }
851  } else {
852  if (l1PSet_ == nullptr) {
853  LogInfo( "l1ObjectMap" ) << "ParameterSet registry not available\n"
854  << "Skipping conditions for all L1 physics algorithm names in this event";
855  }
856  }
857  // physics algorithms
858  for ( CItAlgo iAlgo = l1GtAlgorithms.begin(); iAlgo != l1GtAlgorithms.end(); ++iAlgo ) {
859  const std::string & algoName( iAlgo->second.algoName() );
860  if ( ! ( iAlgo->second.algoBitNumber() < int( L1GlobalTriggerReadoutSetup::NumberPhysTriggers ) ) ) {
861  LogError( "l1Algo" ) << "L1 physics algorithm '" << algoName << "' has bit number " << iAlgo->second.algoBitNumber() << " >= " << L1GlobalTriggerReadoutSetup::NumberPhysTriggers << "\n"
862  << "Skipping";
863  continue;
864  }
866  int bit;
867  if ( ! l1GtUtils.l1AlgoTechTrigBitNumber( algoName, category, bit ) ) {
868  LogError( "l1Algo" ) << "L1 physics algorithm '" << algoName << "' not found in the L1 menu\n"
869  << "Skipping";
870  continue;
871  }
872  if ( category != L1GtUtils::AlgorithmTrigger ) {
873  LogError( "l1Algo" ) << "L1 physics algorithm '" << algoName << "' does not have category 'AlgorithmTrigger' from 'L1GtUtils'\n"
874  << "Skipping";
875  continue;
876  }
877  bool decisionBeforeMask;
878  bool decisionAfterMask;
879  int prescale;
880  int mask;
881  int error( l1GtUtils.l1Results( iEvent, algoName, decisionBeforeMask, decisionAfterMask, prescale, mask ) );
882  if ( error ) {
883  LogError( "l1Algo" ) << "L1 physics algorithm '" << algoName << "' decision has error code " << error << " from 'L1GtUtils'\n"
884  << "Skipping";
885  continue;
886  }
887  TriggerAlgorithm triggerAlgo( algoName, iAlgo->second.algoAlias(), category == L1GtUtils::TechnicalTrigger, (unsigned)bit, (unsigned)prescale, (bool)mask, decisionBeforeMask, decisionAfterMask );
888  triggerAlgo.setLogicalExpression( iAlgo->second.algoLogicalExpression() );
889  // GTL result and used conditions in physics algorithm
890  if( ! handleL1GlobalTriggerObjectMaps.isValid() ) {
891  triggerAlgos->push_back( triggerAlgo );
892  continue; // LogWarning already earlier (before loop)
893  }
894  if ( ! handleL1GlobalTriggerObjectMaps->algorithmExists(bit)) {
895  LogError( "l1ObjectMap" ) << "L1 physics algorithm '" << algoName << "' is missing in L1GlobalTriggerObjectMaps\n"
896  << "Skipping conditions and GTL result";
897  triggerAlgos->push_back( triggerAlgo );
898  continue;
899  }
900  bool algorithmResult = handleL1GlobalTriggerObjectMaps->algorithmResult(bit);
901 // if ( ( algorithmResult != decisionBeforeMask ) && ( decisionBeforeMask == true || prescale == 1 ) ) {
902  if ( ( algorithmResult != decisionBeforeMask ) && ( decisionBeforeMask == true ) ) { // FIXME: understand the difference for un-prescaled algos 118, 119, 123
903  LogInfo( "l1ObjectMap" ) << "L1 physics algorithm '" << algoName << "' with different decisions in\n"
904  << "L1GlobalTriggerObjectMaps (GTL result) : " << algorithmResult << "\n"
905  << "L1GlobalTriggerReadoutRecord (decision before mask): " << decisionBeforeMask;
906  }
907  triggerAlgo.setGtlResult( algorithmResult );
908  // conditions in algorithm
909  L1GlobalTriggerObjectMaps::ConditionsInAlgorithm conditions = handleL1GlobalTriggerObjectMaps->getConditionsInAlgorithm(bit);
910  if (l1PSet_ == nullptr) {
911  triggerAlgos->push_back( triggerAlgo );
912  continue;
913  }
914  if (!l1PSet_->exists(algoName)) {
915  if ( firstInRun_ ) {
916  LogError( "l1ObjectMap" ) << "L1 physics algorithm name '" << algoName << "' not available in ParameterSet registry\n"
917  << "Skipping conditions for this algorithm in this run";
918  } else {
919  LogInfo( "l1ObjectMap" ) << "L1 physics algorithm name '" << algoName << "' not available in ParameterSet registry\n"
920  << "Skipping conditions for this algorithm in this event";
921  }
922  triggerAlgos->push_back( triggerAlgo );
923  continue;
924  }
925  std::vector<std::string> conditionNames( l1PSet_->getParameter<std::vector<std::string> >(algoName) );
926 
927  for ( unsigned iT = 0; iT < conditionNames.size(); ++iT ) {
928  size_t key( triggerConditions->size() );
929  for ( size_t iC = 0; iC < triggerConditions->size(); ++iC ) {
930  if ( conditionNames.at(iT) == triggerConditions->at( iC ).name() ) {
931  key = iC;
932  break;
933  }
934  }
935  if ( key == triggerConditions->size() ) {
936  if ( iT >= conditions.nConditions() ) {
937  LogError( "l1CondMap" ) << "More condition names from ParameterSet registry than the " << conditions.nConditions() << " conditions in L1GlobalTriggerObjectMaps\n"
938  << "Skipping condition " << conditionNames.at(iT) << " in algorithm " << algoName;
939  break;
940  }
941  TriggerCondition triggerCond( conditionNames[iT], conditions.getConditionResult(iT) );
942  if ( l1GtConditions.find( triggerCond.name() ) != l1GtConditions.end() ) {
943  triggerCond.setCategory( l1GtConditions[ triggerCond.name() ]->condCategory() );
944  triggerCond.setType( l1GtConditions[ triggerCond.name() ]->condType() );
945  const std::vector< L1GtObject > l1ObjectTypes( l1GtConditions[ triggerCond.name() ]->objectType() );
946  for ( size_t iType = 0 ; iType < l1ObjectTypes.size(); ++iType ) {
947  triggerCond.addTriggerObjectType( mapObjectTypes[ l1ObjectTypes.at( iType ) ] );
948  }
949  // objects in condition
950  L1GlobalTriggerObjectMaps::CombinationsInCondition combinations = handleL1GlobalTriggerObjectMaps->getCombinationsInCondition(bit, iT);
951  for ( size_t iVV = 0; iVV < combinations.nCombinations(); ++iVV ) {
952  for ( size_t iV = 0; iV < combinations.nObjectsPerCombination(); ++iV ) {
953 
954  unsigned objectIndex = combinations.getObjectIndex(iVV, iV);
955  if ( iV >= l1ObjectTypes.size() ) {
956  LogError( "l1CondMap" ) << "Index " << iV << " in combinations vector overshoots size " << l1ObjectTypes.size() << " of types vector in conditions map\n"
957  << "Skipping object key in condition " << triggerCond.name();
958  } else if ( l1ObjectTypeMap.find( l1ObjectTypes.at( iV ) ) != l1ObjectTypeMap.end() ) {
959  if ( objectIndex >= l1ObjectTypeMap[ l1ObjectTypes.at( iV ) ].size() ) {
960  LogError( "l1CondMap" ) << "Index " << objectIndex << " in combination overshoots number " << l1ObjectTypeMap[ l1ObjectTypes.at( iV ) ].size() << "of according trigger objects\n"
961  << "Skipping object key in condition " << triggerCond.name();
962  }
963  const unsigned objectKey( l1ObjectTypeMap[ l1ObjectTypes.at( iV ) ].at( objectIndex ) );
964  triggerCond.addObjectKey( objectKey );
965  // add current condition and algorithm also to the according stand-alone trigger object
966  triggerObjectsStandAlone->at( objectKey ).addAlgorithmName( triggerAlgo.name(), ( triggerAlgo.decision() && triggerCond.wasAccept() ) );
967  triggerObjectsStandAlone->at( objectKey ).addConditionName( triggerCond.name() );
968  }
969  }
970  }
971  } else {
972  LogWarning( "l1CondMap" ) << "L1 conditions '" << triggerCond.name() << "' not found in the L1 menu\n"
973  << "Remains incomplete";
974  }
975  triggerConditions->push_back( triggerCond );
976  }
977  triggerAlgo.addConditionKey( key );
978  }
979  triggerAlgos->push_back( triggerAlgo );
980  }
981  // technical triggers
982  for ( CItAlgo iAlgo = l1GtTechTriggers.begin(); iAlgo != l1GtTechTriggers.end(); ++iAlgo ) {
983  const std::string & algoName( iAlgo->second.algoName() );
984  if ( ! ( iAlgo->second.algoBitNumber() < int( L1GlobalTriggerReadoutSetup::NumberTechnicalTriggers ) ) ) {
985  LogError( "l1Algo" ) << "L1 technical trigger '" << algoName << "' has bit number " << iAlgo->second.algoBitNumber() << " >= " << L1GlobalTriggerReadoutSetup::NumberTechnicalTriggers << "\n"
986  << "Skipping";
987  continue;
988  }
990  int bit;
991  if ( ! l1GtUtils.l1AlgoTechTrigBitNumber( algoName, category, bit ) ) {
992  LogError( "l1Algo" ) << "L1 technical trigger '" << algoName << "' not found in the L1 menu\n"
993  << "Skipping";
994  continue;
995  }
996  if ( category != L1GtUtils::TechnicalTrigger ) {
997  LogError( "l1Algo" ) << "L1 technical trigger '" << algoName << "' does not have category 'TechnicalTrigger' from 'L1GtUtils'\n"
998  << "Skipping";
999  continue;
1000  }
1001  bool decisionBeforeMask;
1002  bool decisionAfterMask;
1003  int prescale;
1004  int mask;
1005  int error( l1GtUtils.l1Results( iEvent, algoName, decisionBeforeMask, decisionAfterMask, prescale, mask ) );
1006  if ( error ) {
1007  LogError( "l1Algo" ) << "L1 technical trigger '" << algoName << "' decision has error code " << error << " from 'L1GtUtils'\n"
1008  << "Skipping";
1009  continue;
1010  }
1011  TriggerAlgorithm triggerAlgo( algoName, iAlgo->second.algoAlias(), category == L1GtUtils::TechnicalTrigger, (unsigned)bit, (unsigned)prescale, (bool)mask, decisionBeforeMask, decisionAfterMask );
1012  triggerAlgo.setLogicalExpression( iAlgo->second.algoLogicalExpression() );
1013  triggerAlgos->push_back( triggerAlgo );
1014  }
1015  }
1016 
1017  // Put L1 algorithms and conditions to event
1018  iEvent.put(std::move(triggerAlgos));
1019  iEvent.put(std::move(triggerConditions));
1020  }
1021 
1022 
1025 
1026 
1027  const edm::TriggerNames & names = iEvent.triggerNames(*handleTriggerResults);
1028  for (pat::TriggerObjectStandAlone &obj : *triggerObjectsStandAlone) {
1029  obj.setPSetID(config.parameterSetID());
1030  if(packPathNames_) obj.packPathNames(names);
1031  if(packLabels_) obj.packFilterLabels(iEvent,*handleTriggerResults);
1032  }
1033 
1034  // Put (finally) stand-alone trigger objects to event
1035  iEvent.put(std::move(triggerObjectsStandAlone));
1036 
1037  firstInRun_ = false;
1038 
1039 }
1040 
1042  clear();
1043  const std::vector<std::string> & pathNames = hltConfig.triggerNames();
1044  unsigned int sizePaths = pathNames.size();
1045  for ( unsigned int indexPath = 0; indexPath < sizePaths; ++indexPath ) {
1046  const std::string & namePath = pathNames[indexPath];
1047 
1048  const std::vector<std::string> & nameModules = hltConfig.moduleLabels(indexPath);
1049  unsigned int sizeModulesPath = nameModules.size();
1050  bool lastFilter = true;
1051  unsigned int iM = sizeModulesPath;
1052  while (iM > 0) {
1053  const std::string & nameFilter = nameModules[--iM];
1054  if (hltConfig.moduleEDMType(nameFilter) != "EDFilter") continue;
1055  if (hltConfig.moduleType(nameFilter) == "HLTBool") continue;
1056  bool saveTags = hltConfig.saveTags(nameFilter);
1057  insert( nameFilter, namePath, indexPath, lastFilter, saveTags );
1058  if (saveTags) lastFilter = false; // FIXME: rather always?
1059  }
1060  }
1061 }
1062 
#define LogDebug(id)
unsigned int set() const
low-level const accessors for data members
unsigned int size() const
number of trigger paths in trigger table
const std::string & collectionTagEncoded(trigger::size_type index) const
Definition: TriggerEvent.h:101
collection_type::const_iterator const_iterator
T getParameter(std::string const &) const
edm::GetterOfProducts< l1extra::L1MuonParticleCollection > l1ExtraMuGetter_
edm::GetterOfProducts< trigger::HLTPrescaleTable > hltPrescaleTableEventGetter_
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:303
unsigned char getObjectIndex(unsigned combination, unsigned object) const
bool wasrun() const
Was at least one path run?
bool saveTags(const std::string &module) const
Is module an L3 filter (ie, tracked saveTags=true)
std::pair< std::vector< std::pair< std::string, int > >, int > prescaleValuesInDetail(const edm::Event &iEvent, const edm::EventSetup &iSetup, const std::string &trigger)
Analysis-level L1 trigger algorithm class.
void beginLuminosityBlock(const edm::LuminosityBlock &iLuminosityBlock, const edm::EventSetup &iSetup) override
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
const std::string moduleType(const std::string &module) const
C++ class name of module.
int id() const
getters
Definition: TriggerObject.h:55
Definition: L1GtObject.h:39
trigger::size_type sizeFilters() const
Definition: TriggerEvent.h:135
PATTriggerProducer(const edm::ParameterSet &iConfig)
bool setStatus(int status)
static PFTauRenderPlugin instance
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
enum start value shifted to 81 so as to avoid clashes with PDG codes
float phi() const
Definition: TriggerObject.h:58
std::map< std::string, L1GtCondition * > ConditionMap
map containing the conditions
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Definition: L1GtObject.h:36
const bool l1AlgoTechTrigBitNumber(const std::string &nameAlgoTechTrig, TriggerCategory &trigCategory, int &bitNumber) const
Definition: L1GtUtils.cc:376
static const unsigned int NumberTechnicalTriggers
const std::vector< std::vector< std::pair< bool, std::string > > > & hltL1GTSeeds() const
bool accept() const
Has at least one path accepted the event?
const std::vector< std::string > & triggerNames() const
names of trigger paths
const Keys & filterKeys(trigger::size_type index) const
Definition: TriggerEvent.h:111
The single EDProduct containing the HLT Prescale Table.
void setGtlResult(bool gtlResult)
Set L1 algorithm GTL result.
edm::GetterOfProducts< trigger::TriggerEvent > triggerEventGetter_
trigger::size_type filterIndex(const edm::InputTag &filterTag) const
find index of filter in data-member vector from filter tag
Definition: TriggerEvent.h:123
bool exists(std::string const &parameterName) const
checks if a parameter exists
const std::string moduleEDMType(const std::string &module) const
C++ base class name of module.
void beginRun(const edm::Run &iRun, const edm::EventSetup &iSetup) override
std::string const & processName() const
void addTriggerObjectType(trigger::TriggerObjectType triggerObjectType)
Add a new trigger object type identifier.
Definition: TriggerFilter.h:79
Strings::size_type size() const
Definition: TriggerNames.cc:39
float eta() const
Definition: TriggerObject.h:57
void addObjectKey(unsigned objectKey)
Add a new trigger object collection index.
Definition: TriggerFilter.h:77
const std::vector< ConditionMap > & gtConditionMap() const
get / set / build the condition maps
edm::GetterOfProducts< trigger::HLTPrescaleTable > hltPrescaleTableLumiGetter_
bool getByLabel(std::string const &label, Handle< PROD > &result) const
const std::map< std::string, std::vector< unsigned int > > & prescaleTable() const
uint16_t size_type
bool isRealData() const
Definition: EventBase.h:64
bool hasCollection(const std::string &collName) const override
Checks, if a certain label of original collection is assigned (method overrides)
const std::map< std::string, std::vector< unsigned int > > & table() const
const std::string names[nVars_]
std::string encode() const
Definition: InputTag.cc:166
void addFilterLabel(const std::string &filterLabel)
Adds a new HLT filter label.
const std::string & moduleLabel(unsigned int trigger, unsigned int module) const
edm::GetterOfProducts< l1extra::L1JetParticleCollection > l1ExtraForJetGetter_
bool algorithmExists(int algorithmBitNumber) const
Returns true if there is an entry for this algorithm bit number.
const Keys & collectionKeys() const
Definition: TriggerEvent.h:97
Definition: HeavyIon.h:7
AlgorithmMap::const_iterator CItAlgo
iterators through map containing the algorithms
const std::vector< std::string > & saveTagsModules(unsigned int trigger) const
Single trigger physics object (e.g., an isolated muon)
Definition: TriggerObject.h:22
bool getConfigurationForProcess(std::string const &name, ProcessConfiguration &config) const
config
Definition: looper.py:288
void addPathName(const std::string &pathName, bool pathLastFilterAccepted=true, bool pathL3FilterAccepted=true)
Adds a new HLT path name.
Analysis-level HLTrigger filter class.
Definition: TriggerFilter.h:35
const Vids & filterIds(trigger::size_type index) const
Definition: TriggerEvent.h:110
Produces the full or stand-alone PAT trigger information collections.
unsigned int prescaleValue(unsigned int set, const std::string &trigger) const
HLT prescale value in specific prescale set for a specific trigger path.
int iEvent
Definition: GenABIO.cc:230
ParameterSetID const & parameterSetID() const
unsigned int moduleIndex(unsigned int trigger, const std::string &module) const
slot position of module on trigger path (0 to size-1)
edm::ParameterSetID const & namesParameterSetID() const
void setCollection(const std::string &collName)
Methods.
Definition: TriggerObject.h:84
Analysis-level L1 trigger condition class.
Analysis-level HLTrigger path class.
Definition: TriggerPath.h:39
static const unsigned int NumberPhysTriggersExtended
const TriggerObjectCollection & getObjects() const
Definition: TriggerEvent.h:98
const std::vector< std::string > & labels() const
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
edm::GetterOfProducts< l1extra::L1JetParticleCollection > l1ExtraTauJetGetter_
trigger::HLTPrescaleTable hltPrescaleTableLumi_
ProcessHistory const & processHistory() const override
Definition: Event.cc:273
const std::string & name() const
Get L1 algorithm name.
unsigned int index(const unsigned int i) const
Get index (slot position) of module giving the decision of the ith path.
std::string filterLabel(trigger::size_type index) const
Definition: TriggerEvent.h:105
bool error() const
Has any path encountered an error (exception)
ProcessHistory const & processHistory() const
Definition: Run.cc:121
const int l1Results(const edm::Event &iEvent, const std::string &nameAlgoTechTrig, bool &decisionBeforeMask, bool &decisionAfterMask, int &prescaleFactor, int &triggerMask) const
Definition: L1GtUtils.cc:713
edm::GetterOfProducts< l1extra::L1EtMissParticleCollection > l1ExtraHTMGetter_
static const unsigned int NumberPhysTriggers
void setSaveTags(bool saveTags)
Set the L3 status.
Definition: TriggerFilter.h:87
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
Definition: HCMethods.h:49
void setLogicalExpression(const std::string &expression)
Set L1 algorithm logical expression.
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< L1GlobalTriggerObjectMaps > l1GlobalTriggerObjectMapsToken_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
edm::GetterOfProducts< l1extra::L1EmParticleCollection > l1ExtraNoIsoEGGetter_
int prescaleSet(const edm::Event &iEvent, const edm::EventSetup &iSetup)
edm::GetterOfProducts< l1extra::L1EtMissParticleCollection > l1ExtraETMGetter_
const std::vector< std::string > & moduleLabels(unsigned int trigger) const
label(s) of module(s) on a trigger path
edm::GetterOfProducts< trigger::HLTPrescaleTable > hltPrescaleTableRunGetter_
edm::InputTag tagL1GlobalTriggerObjectMaps_
const edm::InputTag filterTag(trigger::size_type index) const
Definition: TriggerEvent.h:103
ModuleLabelToPathAndFlags moduleLabelToPathAndFlags_
L1GtUtils const & l1GtUtils() const
void setCategory(L1GtConditionCategory category)
Set the condition category.
CombinationsInCondition getCombinationsInCondition(int algorithmBitNumber, unsigned conditionNumber) const
Definition: L1GtObject.h:30
trigger::size_type sizeObjects() const
Definition: TriggerEvent.h:134
std::string const & triggerName(unsigned int index) const
Definition: TriggerNames.cc:27
std::vector< size_type > Keys
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
edm::GetterOfProducts< l1extra::L1EmParticleCollection > l1ExtraIsoEGGetter_
trigger::size_type sizeCollections() const
other
Definition: TriggerEvent.h:133
const std::vector< std::string > & prescaleLabels() const
low-level data member access
edm::GetterOfProducts< l1extra::L1JetParticleCollection > l1ExtraCenJetGetter_
HLTConfigProvider const & hltConfigProvider() const
void addConditionKey(unsigned conditionKey)
Add a new trigger condition collection index.
std::string const & label() const
Definition: InputTag.h:36
std::string const & process() const
Definition: InputTag.h:40
void setType(const std::string &type)
Set the filter module type.
Definition: TriggerFilter.h:75
edm::GetterOfProducts< edm::TriggerResults > triggerResultsGetter_
HLT enums.
T get() const
Definition: EventSetup.h:63
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
const AlgorithmMap & gtAlgorithmMap() const
get / set the algorithm map (by name)
unsigned int prescaleSize() const
trigger::HLTPrescaleTable hltPrescaleTableRun_
ConditionsInAlgorithm getConditionsInAlgorithm(int algorithmBitNumber) const
const AlgorithmMap & gtTechnicalTriggerMap() const
get / set the technical trigger map
std::vector< std::string > exludeCollections_
std::vector< L1Seed > L1SeedCollection
Collection of L1Seed.
Definition: TriggerPath.h:37
float mass() const
Definition: TriggerObject.h:59
void addTriggerObjectType(trigger::TriggerObjectType triggerObjectType)
Add a new trigger object type identifier.
Definition: TriggerObject.h:87
bool algorithmResult(int algorithmBitNumber) const
Returns whether an algorithm trigger passed or failed.
static std::string const triggerPaths
Definition: EdmProvDump.cc:42
std::string const & instance() const
Definition: InputTag.h:37
edm::TriggerNames const & triggerNames(edm::TriggerResults const &triggerResults) const override
Definition: Event.cc:301
edm::InputTag tagL1ExtraNoIsoEG_
bool init(const edm::Run &iRun, const edm::EventSetup &iSetup, const std::string &processName, bool &changed)
std::vector< int > Vids
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:44
HLTPrescaleProvider hltPrescaleProvider_
Analysis-level trigger object class (stand-alone)
edm::ParameterSet * l1PSet_