CMS 3D CMS Logo

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