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