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