00001
00002
00003
00004
00005
00006 #include "PhysicsTools/PatAlgos/plugins/PATTriggerProducer.h"
00007
00008 #include <vector>
00009 #include <map>
00010 #include <utility>
00011 #include <cassert>
00012
00013 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00014 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00015 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
00016 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00017 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h"
00018 #include "DataFormats/Common/interface/TriggerResults.h"
00019 #include "DataFormats/HLTReco/interface/TriggerEvent.h"
00020 #include "DataFormats/Provenance/interface/ProcessHistory.h"
00021 #include "FWCore/ParameterSet/interface/Registry.h"
00022
00023 #include "DataFormats/PatCandidates/interface/TriggerAlgorithm.h"
00024 #include "DataFormats/PatCandidates/interface/TriggerCondition.h"
00025 #include "DataFormats/PatCandidates/interface/TriggerPath.h"
00026 #include "DataFormats/PatCandidates/interface/TriggerFilter.h"
00027 #include "DataFormats/PatCandidates/interface/TriggerObjectStandAlone.h"
00028
00029 #include "FWCore/Framework/interface/ESHandle.h"
00030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00031
00032
00033 using namespace pat;
00034 using namespace edm;
00035
00036
00037
00038 const unsigned L1GlobalTriggerReadoutSetup::NumberPhysTriggers;
00039 const unsigned L1GlobalTriggerReadoutSetup::NumberPhysTriggersExtended;
00040 const unsigned L1GlobalTriggerReadoutSetup::NumberTechnicalTriggers;
00041
00042
00043 PATTriggerProducer::PATTriggerProducer( const ParameterSet & iConfig ) :
00044 nameProcess_( iConfig.getParameter< std::string >( "processName" ) ),
00045 autoProcessName_( nameProcess_ == "*" ),
00046 onlyStandAlone_( iConfig.getParameter< bool >( "onlyStandAlone" ) ),
00047
00048 addL1Algos_( false ),
00049 tagL1GlobalTriggerObjectMapRecord_( "hltL1GtObjectMap" ),
00050 tagL1ExtraMu_(),
00051 tagL1ExtraNoIsoEG_(),
00052 tagL1ExtraIsoEG_(),
00053 tagL1ExtraCenJet_(),
00054 tagL1ExtraForJet_(),
00055 tagL1ExtraTauJet_(),
00056 tagL1ExtraETM_(),
00057 tagL1ExtraHTM_(),
00058 autoProcessNameL1ExtraMu_( false ),
00059 autoProcessNameL1ExtraNoIsoEG_( false ),
00060 autoProcessNameL1ExtraIsoEG_( false ),
00061 autoProcessNameL1ExtraCenJet_( false ),
00062 autoProcessNameL1ExtraForJet_( false ),
00063 autoProcessNameL1ExtraTauJet_( false ),
00064 autoProcessNameL1ExtraETM_( false ),
00065 autoProcessNameL1ExtraHTM_( false ),
00066 mainBxOnly_( true ),
00067 saveL1Refs_( false ),
00068
00069 tagTriggerResults_( "TriggerResults" ),
00070 tagTriggerEvent_( "hltTriggerSummaryAOD" ),
00071 hltPrescaleLabel_(),
00072 labelHltPrescaleTable_(),
00073 hltPrescaleTableRun_(),
00074 hltPrescaleTableLumi_(),
00075 addPathModuleLabels_( false )
00076 {
00077
00078
00079 if ( iConfig.exists( "addL1Algos" ) ) addL1Algos_ = iConfig.getParameter< bool >( "addL1Algos" );
00080 if ( iConfig.exists( "l1GlobalTriggerObjectMapRecord" ) ) tagL1GlobalTriggerObjectMapRecord_ = iConfig.getParameter< InputTag >( "l1GlobalTriggerObjectMapRecord" );
00081 if ( iConfig.exists( "l1ExtraMu" ) ) {
00082 tagL1ExtraMu_ = iConfig.getParameter< InputTag >( "l1ExtraMu" );
00083 if ( tagL1ExtraMu_.process() == "*" ) {
00084 if ( autoProcessName_ ) autoProcessNameL1ExtraMu_ = true;
00085 else tagL1ExtraMu_ = InputTag( tagL1ExtraMu_.label(), tagL1ExtraMu_.instance(), nameProcess_ );
00086 }
00087 }
00088 if ( iConfig.exists( "l1ExtraNoIsoEG" ) ) {
00089 tagL1ExtraNoIsoEG_ = iConfig.getParameter< InputTag >( "l1ExtraNoIsoEG" );
00090 if ( tagL1ExtraNoIsoEG_.process() == "*" ) {
00091 if ( autoProcessName_ ) autoProcessNameL1ExtraNoIsoEG_ = true;
00092 else tagL1ExtraNoIsoEG_ = InputTag( tagL1ExtraNoIsoEG_.label(), tagL1ExtraNoIsoEG_.instance(), nameProcess_ );
00093 }
00094 }
00095 if ( iConfig.exists( "l1ExtraIsoEG" ) ) {
00096 tagL1ExtraIsoEG_ = iConfig.getParameter< InputTag >( "l1ExtraIsoEG" );
00097 if ( tagL1ExtraIsoEG_.process() == "*" ) {
00098 if ( autoProcessName_ ) autoProcessNameL1ExtraIsoEG_ = true;
00099 else tagL1ExtraIsoEG_ = InputTag( tagL1ExtraIsoEG_.label(), tagL1ExtraIsoEG_.instance(), nameProcess_ );
00100 }
00101 }
00102 if ( iConfig.exists( "l1ExtraCenJet" ) ) {
00103 tagL1ExtraCenJet_ = iConfig.getParameter< InputTag >( "l1ExtraCenJet" );
00104 if ( tagL1ExtraCenJet_.process() == "*" ) {
00105 if ( autoProcessName_ ) autoProcessNameL1ExtraCenJet_ = true;
00106 else tagL1ExtraCenJet_ = InputTag( tagL1ExtraCenJet_.label(), tagL1ExtraCenJet_.instance(), nameProcess_ );
00107 }
00108 }
00109 if ( iConfig.exists( "l1ExtraForJet" ) ) {
00110 tagL1ExtraForJet_ = iConfig.getParameter< InputTag >( "l1ExtraForJet" );
00111 if ( tagL1ExtraForJet_.process() == "*" ) {
00112 if ( autoProcessName_ ) autoProcessNameL1ExtraForJet_ = true;
00113 else tagL1ExtraForJet_ = InputTag( tagL1ExtraForJet_.label(), tagL1ExtraForJet_.instance(), nameProcess_ );
00114 }
00115 }
00116 if ( iConfig.exists( "l1ExtraTauJet" ) ) {
00117 tagL1ExtraTauJet_ = iConfig.getParameter< InputTag >( "l1ExtraTauJet" );
00118 if ( tagL1ExtraTauJet_.process() == "*" ) {
00119 if ( autoProcessName_ ) autoProcessNameL1ExtraTauJet_ = true;
00120 else tagL1ExtraTauJet_ = InputTag( tagL1ExtraTauJet_.label(), tagL1ExtraTauJet_.instance(), nameProcess_ );
00121 }
00122 }
00123 if ( iConfig.exists( "l1ExtraETM" ) ) {
00124 tagL1ExtraETM_ = iConfig.getParameter< InputTag >( "l1ExtraETM" );
00125 if ( tagL1ExtraETM_.process() == "*" ) {
00126 if ( autoProcessName_ ) autoProcessNameL1ExtraETM_ = true;
00127 else tagL1ExtraETM_ = InputTag( tagL1ExtraETM_.label(), tagL1ExtraETM_.instance(), nameProcess_ );
00128 }
00129 }
00130 if ( iConfig.exists( "l1ExtraHTM" ) ) {
00131 tagL1ExtraHTM_ = iConfig.getParameter< InputTag >( "l1ExtraHTM" );
00132 if ( tagL1ExtraHTM_.process() == "*" ) {
00133 if ( autoProcessName_ ) autoProcessNameL1ExtraHTM_ = true;
00134 else tagL1ExtraHTM_ = InputTag( tagL1ExtraHTM_.label(), tagL1ExtraHTM_.instance(), nameProcess_ );
00135 }
00136 }
00137 if ( iConfig.exists( "mainBxOnly" ) ) mainBxOnly_ = iConfig.getParameter< bool >( "mainBxOnly" );
00138 if ( iConfig.exists( "saveL1Refs" ) ) saveL1Refs_ = iConfig.getParameter< bool >( "saveL1Refs" );
00139
00140
00141 if ( iConfig.exists( "triggerResults" ) ) tagTriggerResults_ = iConfig.getParameter< InputTag >( "triggerResults" );
00142 if ( iConfig.exists( "triggerEvent" ) ) tagTriggerEvent_ = iConfig.getParameter< InputTag >( "triggerEvent" );
00143 if ( iConfig.exists( "hltPrescaleLabel" ) ) hltPrescaleLabel_ = iConfig.getParameter< std::string >( "hltPrescaleLabel" );
00144 if ( iConfig.exists( "hltPrescaleTable" ) ) labelHltPrescaleTable_ = iConfig.getParameter< std::string >( "hltPrescaleTable" );
00145 if ( iConfig.exists( "addPathModuleLabels" ) ) addPathModuleLabels_ = iConfig.getParameter< bool >( "addPathModuleLabels" );
00146 exludeCollections_.clear();
00147 if ( iConfig.exists( "exludeCollections" ) ) exludeCollections_ = iConfig.getParameter< std::vector< std::string > >( "exludeCollections" );
00148
00149 if ( ! onlyStandAlone_ ) {
00150 produces< TriggerAlgorithmCollection >();
00151 produces< TriggerConditionCollection >();
00152 produces< TriggerPathCollection >();
00153 produces< TriggerFilterCollection >();
00154 produces< TriggerObjectCollection >();
00155 }
00156 produces< TriggerObjectStandAloneCollection >();
00157
00158 }
00159
00160
00161 void PATTriggerProducer::beginRun( Run & iRun, const EventSetup & iSetup )
00162 {
00163
00164
00165 hltConfigInit_ = false;
00166
00167
00168 if ( autoProcessName_ ) {
00169
00170 nameProcess_ = "*";
00171
00172 const ProcessHistory & processHistory( iRun.processHistory() );
00173 ProcessConfiguration processConfiguration;
00174 ParameterSet processPSet;
00175
00176 for ( ProcessHistory::const_iterator iHist = processHistory.begin(); iHist != processHistory.end(); ++iHist ) {
00177 if ( processHistory.getConfigurationForProcess( iHist->processName(), processConfiguration ) &&
00178 pset::Registry::instance()->getMapped( processConfiguration.parameterSetID(), processPSet ) &&
00179 processPSet.exists( tagTriggerEvent_.label() )
00180 ) {
00181 nameProcess_ = iHist->processName();
00182 LogDebug( "autoProcessName" ) << "HLT process name '" << nameProcess_ << "' discovered";
00183 }
00184 }
00185
00186 if ( nameProcess_ == "*" ) {
00187 LogError( "autoProcessName" ) << "trigger::TriggerEvent product with label '" << tagTriggerEvent_.label() << "' not produced according to process history of input data\n"
00188 << "No trigger information produced";
00189 return;
00190 }
00191 LogInfo( "autoProcessName" ) << "HLT process name' " << nameProcess_ << "' used for PAT trigger information";
00192 }
00193
00194 if ( tagTriggerResults_.process().empty() || tagTriggerResults_.process() == "*" ) {
00195 tagTriggerResults_ = InputTag( tagTriggerResults_.label(), tagTriggerResults_.instance(), nameProcess_ );
00196 } else if ( tagTriggerEvent_.process() != nameProcess_ ) {
00197 LogWarning( "triggerResultsTag" ) << "TriggerResults process name '" << tagTriggerResults_.process() << "' differs from HLT process name '" << nameProcess_ << "'";
00198 }
00199 if ( tagTriggerEvent_.process().empty() || tagTriggerEvent_.process() == "*" ) {
00200 tagTriggerEvent_ = InputTag( tagTriggerEvent_.label(), tagTriggerEvent_.instance(), nameProcess_ );
00201 } else if ( tagTriggerEvent_.process() != nameProcess_ ) {
00202 LogWarning( "triggerEventTag" ) << "TriggerEvent process name '" << tagTriggerEvent_.process() << "' differs from HLT process name '" << nameProcess_ << "'";
00203 }
00204 if ( autoProcessNameL1ExtraMu_ ) tagL1ExtraMu_ = InputTag( tagL1ExtraMu_.label() , tagL1ExtraMu_.instance() , nameProcess_ );
00205 if ( autoProcessNameL1ExtraNoIsoEG_ ) tagL1ExtraNoIsoEG_ = InputTag( tagL1ExtraNoIsoEG_.label(), tagL1ExtraNoIsoEG_.instance(), nameProcess_ );
00206 if ( autoProcessNameL1ExtraIsoEG_ ) tagL1ExtraIsoEG_ = InputTag( tagL1ExtraIsoEG_.label() , tagL1ExtraIsoEG_.instance() , nameProcess_ );
00207 if ( autoProcessNameL1ExtraCenJet_ ) tagL1ExtraCenJet_ = InputTag( tagL1ExtraCenJet_.label() , tagL1ExtraCenJet_.instance() , nameProcess_ );
00208 if ( autoProcessNameL1ExtraForJet_ ) tagL1ExtraForJet_ = InputTag( tagL1ExtraForJet_.label() , tagL1ExtraForJet_.instance() , nameProcess_ );
00209 if ( autoProcessNameL1ExtraTauJet_ ) tagL1ExtraTauJet_ = InputTag( tagL1ExtraTauJet_.label() , tagL1ExtraTauJet_.instance() , nameProcess_ );
00210 if ( autoProcessNameL1ExtraETM_ ) tagL1ExtraETM_ = InputTag( tagL1ExtraETM_.label() , tagL1ExtraETM_.instance() , nameProcess_ );
00211 if ( autoProcessNameL1ExtraHTM_ ) tagL1ExtraHTM_ = InputTag( tagL1ExtraHTM_.label() , tagL1ExtraHTM_.instance() , nameProcess_ );
00212
00213
00214 bool changed( true );
00215 if ( ! hltConfig_.init( iRun, iSetup, nameProcess_, changed ) ) {
00216 LogError( "hltConfigExtraction" ) << "HLT config extraction error with process name '" << nameProcess_ << "'";
00217 } else if ( hltConfig_.size() <= 0 ) {
00218 LogError( "hltConfigSize" ) << "HLT config size error";
00219 } else hltConfigInit_ = true;
00220
00221
00222 if ( hltConfigInit_ ) {
00223
00224 hltPrescaleTableRun_ = trigger::HLTPrescaleTable();
00225
00226 if ( ! labelHltPrescaleTable_.empty() ) {
00227 Handle< trigger::HLTPrescaleTable > handleHltPrescaleTable;
00228 iRun.getByLabel( InputTag( labelHltPrescaleTable_, "Run", nameProcess_ ), handleHltPrescaleTable );
00229 if ( handleHltPrescaleTable.isValid() ) {
00230 hltPrescaleTableRun_ = trigger::HLTPrescaleTable( handleHltPrescaleTable->set(), handleHltPrescaleTable->labels(), handleHltPrescaleTable->table() );
00231 }
00232 }
00233 }
00234
00235 }
00236
00237
00238 void PATTriggerProducer::beginLuminosityBlock( LuminosityBlock & iLuminosityBlock, const EventSetup & iSetup )
00239 {
00240
00241
00242 if ( nameProcess_ == "*" ) return;
00243
00244
00245 if ( hltConfigInit_ ) {
00246
00247 hltPrescaleTableLumi_ = trigger::HLTPrescaleTable( hltPrescaleTableRun_.set(), hltPrescaleTableRun_.labels(), hltPrescaleTableRun_.table() );
00248
00249 if ( ! labelHltPrescaleTable_.empty() ) {
00250 Handle< trigger::HLTPrescaleTable > handleHltPrescaleTable;
00251 iLuminosityBlock.getByLabel( InputTag( labelHltPrescaleTable_, "Lumi", nameProcess_ ), handleHltPrescaleTable );
00252 if ( handleHltPrescaleTable.isValid() ) {
00253 hltPrescaleTableLumi_ = trigger::HLTPrescaleTable( handleHltPrescaleTable->set(), handleHltPrescaleTable->labels(), handleHltPrescaleTable->table() );
00254 }
00255 }
00256 }
00257
00258 }
00259
00260
00261 void PATTriggerProducer::produce( Event& iEvent, const EventSetup& iSetup )
00262 {
00263
00264
00265 if ( nameProcess_ == "*" ) return;
00266
00267 std::auto_ptr< TriggerObjectCollection > triggerObjects( new TriggerObjectCollection() );
00268 if ( onlyStandAlone_ ) triggerObjects->reserve( 0 );
00269 std::auto_ptr< TriggerObjectStandAloneCollection > triggerObjectsStandAlone( new TriggerObjectStandAloneCollection() );
00270
00271
00272
00273
00274 Handle< trigger::TriggerEvent > handleTriggerEvent;
00275 iEvent.getByLabel( tagTriggerEvent_, handleTriggerEvent );
00276 Handle< TriggerResults > handleTriggerResults;
00277 iEvent.getByLabel( tagTriggerResults_, handleTriggerResults );
00278 bool goodHlt( hltConfigInit_ );
00279 if ( goodHlt ) {
00280 if( ! handleTriggerResults.isValid() ) {
00281 LogError( "triggerResultsValid" ) << "TriggerResults product with InputTag '" << tagTriggerResults_.encode() << "' not in event\n"
00282 << "No HLT information produced";
00283 goodHlt = false;
00284 } else if ( ! handleTriggerEvent.isValid() ) {
00285 LogError( "triggerEventValid" ) << "trigger::TriggerEvent product with InputTag '" << tagTriggerEvent_.encode() << "' not in event\n"
00286 << "No HLT information produced";
00287 goodHlt = false;
00288 }
00289 }
00290
00291
00292
00293 if ( goodHlt ) {
00294
00295
00296
00297 trigger::HLTPrescaleTable hltPrescaleTable( hltPrescaleTableLumi_.set(), hltPrescaleTableLumi_.labels(), hltPrescaleTableLumi_.table() );
00298
00299 if ( ! labelHltPrescaleTable_.empty() ) {
00300 Handle< trigger::HLTPrescaleTable > handleHltPrescaleTable;
00301 iEvent.getByLabel( InputTag( labelHltPrescaleTable_, "Event", nameProcess_ ), handleHltPrescaleTable );
00302 if ( handleHltPrescaleTable.isValid() ) {
00303 hltPrescaleTable = trigger::HLTPrescaleTable( handleHltPrescaleTable->set(), handleHltPrescaleTable->labels(), handleHltPrescaleTable->table() );
00304 }
00305 }
00306
00307 if ( hltPrescaleTable.size() == 0 ) {
00308 if ( ! labelHltPrescaleTable_.empty() ) {
00309 LogWarning( "hltPrescaleInputTag" ) << "HLTPrescaleTable product with label '" << labelHltPrescaleTable_ << "' not found in process" << nameProcess_ << "\n"
00310 << "Using default from event setup";
00311 }
00312 if ( hltConfig_.prescaleSize() > 0 ) {
00313 if ( hltConfig_.prescaleSet( iEvent, iSetup ) != -1 ) {
00314 hltPrescaleTable = trigger::HLTPrescaleTable( hltConfig_.prescaleSet( iEvent, iSetup ), hltConfig_.prescaleLabels(), hltConfig_.prescaleTable() );
00315 LogDebug( "hltPrescaleTable" ) << "HLT prescale table found in event setup";
00316 } else {
00317 LogWarning( "hltPrescaleSet" ) << "HLTPrescaleTable from event setup has error";
00318 }
00319 }
00320 }
00321 unsigned set( hltPrescaleTable.set() );
00322 if ( hltPrescaleTable.size() > 0 ) {
00323 if ( hltPrescaleLabel_.size() > 0 ) {
00324 bool foundPrescaleLabel( false );
00325 for ( unsigned iLabel = 0; iLabel < hltPrescaleTable.labels().size(); ++iLabel ) {
00326 if ( hltPrescaleTable.labels().at( iLabel ) == hltPrescaleLabel_ ) {
00327 set = iLabel;
00328 foundPrescaleLabel = true;
00329 break;
00330 }
00331 }
00332 if ( ! foundPrescaleLabel ) {
00333 LogWarning( "hltPrescaleLabel" ) << "HLT prescale label '" << hltPrescaleLabel_ << "' not in prescale table\n"
00334 << "Using default";
00335 }
00336 }
00337 } else if ( iEvent.isRealData() ) {
00338 LogWarning( "hltPrescaleTable" ) << "No HLT prescale table found\n"
00339 << "Using default empty table with all prescales 1";
00340 }
00341
00342 const unsigned sizePaths( hltConfig_.size() );
00343 const unsigned sizeFilters( handleTriggerEvent->sizeFilters() );
00344 const unsigned sizeObjects( handleTriggerEvent->sizeObjects() );
00345
00346 std::auto_ptr< TriggerPathCollection > triggerPaths( new TriggerPathCollection() );
00347 triggerPaths->reserve( onlyStandAlone_ ? 0 : sizePaths );
00348 std::map< std::string, int > moduleStates;
00349 std::multimap< std::string, std::pair< std::string, std::pair< bool, bool > > > filterPaths;
00350
00351 for ( size_t iP = 0; iP < sizePaths; ++iP ) {
00352 const std::string namePath( hltConfig_.triggerName( iP ) );
00353 const unsigned indexPath( hltConfig_.triggerIndex( namePath ) );
00354 const unsigned sizeModulesPath( hltConfig_.size( namePath ) );
00355 unsigned indexLastFilterPathModules( handleTriggerResults->index( indexPath ) + 1 );
00356 unsigned indexLastFilterFilters( sizeFilters );
00357 while ( indexLastFilterPathModules > 0 ) {
00358 --indexLastFilterPathModules;
00359 const std::string labelLastFilterPathModules( hltConfig_.moduleLabel( indexPath, indexLastFilterPathModules ) );
00360 indexLastFilterFilters = handleTriggerEvent->filterIndex( InputTag( labelLastFilterPathModules, "", nameProcess_ ) );
00361 if ( indexLastFilterFilters < sizeFilters ) {
00362 if ( hltConfig_.moduleType( labelLastFilterPathModules ) == "HLTBool" ) continue;
00363 break;
00364 }
00365 }
00366 for ( size_t iM = 0; iM < sizeModulesPath; ++iM ) {
00367 const std::string nameFilter( hltConfig_.moduleLabel( indexPath, iM ) );
00368 const unsigned indexFilter( handleTriggerEvent->filterIndex( InputTag( nameFilter, "", nameProcess_ ) ) );
00369 if ( indexFilter < sizeFilters ) {
00370 bool pathLastFilterAccepted( handleTriggerResults->wasrun( indexPath ) && handleTriggerResults->accept( indexPath ) && indexFilter == indexLastFilterFilters );
00371 bool pathL3FilterAccepted( handleTriggerResults->wasrun( indexPath ) && handleTriggerResults->accept( indexPath ) && hltConfig_.saveTags( nameFilter ) );
00372 std::pair< bool, bool > pathStatusValues( pathLastFilterAccepted, pathL3FilterAccepted );
00373 std::pair< std::string, std::pair< bool, bool > > pathAndStatus( namePath, pathStatusValues );
00374 filterPaths.insert( std::pair< std::string, std::pair< std::string, std::pair< bool, bool > > >( nameFilter, pathAndStatus ) );
00375 }
00376 }
00377 if ( ! onlyStandAlone_ ) {
00378 TriggerPath triggerPath( namePath, indexPath, hltConfig_.prescaleValue( set, namePath ), handleTriggerResults->wasrun( indexPath ), handleTriggerResults->accept( indexPath ), handleTriggerResults->error( indexPath ), indexLastFilterPathModules, hltConfig_.saveTagsModules( namePath ).size() );
00379
00380 assert( indexLastFilterPathModules < sizeModulesPath );
00381 std::map< unsigned, std::string > indicesModules;
00382 for ( size_t iM = 0; iM < sizeModulesPath; ++iM ) {
00383 const std::string nameModule( hltConfig_.moduleLabel( indexPath, iM ) );
00384 if ( addPathModuleLabels_ ) {
00385 triggerPath.addModule( nameModule );
00386 }
00387 const unsigned indexFilter( handleTriggerEvent->filterIndex( InputTag( nameModule, "", nameProcess_ ) ) );
00388 if ( indexFilter < sizeFilters ) {
00389 triggerPath.addFilterIndex( indexFilter );
00390 }
00391 const unsigned slotModule( hltConfig_.moduleIndex( indexPath, nameModule ) );
00392 indicesModules.insert( std::pair< unsigned, std::string >( slotModule, nameModule ) );
00393 }
00394
00395 const L1SeedCollection l1Seeds( hltConfig_.hltL1GTSeeds( namePath ) );
00396 for ( L1SeedCollection::const_iterator iSeed = l1Seeds.begin(); iSeed != l1Seeds.end(); ++iSeed ) {
00397 triggerPath.addL1Seed( *iSeed );
00398 }
00399
00400 triggerPaths->push_back( triggerPath );
00401
00402 for ( std::map< unsigned, std::string >::const_iterator iM = indicesModules.begin(); iM != indicesModules.end(); ++iM ) {
00403 if ( iM->first < indexLastFilterPathModules ) {
00404 moduleStates[ iM->second ] = 1;
00405 } else if ( iM->first == indexLastFilterPathModules ) {
00406 moduleStates[ iM->second ] = handleTriggerResults->accept( indexPath );
00407 } else if ( moduleStates.find( iM->second ) == moduleStates.end() ) {
00408 moduleStates[ iM->second ] = -1;
00409 }
00410 }
00411 }
00412 }
00413
00414
00415 if ( ! onlyStandAlone_ ) iEvent.put( triggerPaths );
00416
00417
00418
00419
00420 std::auto_ptr< TriggerFilterCollection > triggerFilters( new TriggerFilterCollection() );
00421 triggerFilters->reserve( onlyStandAlone_ ? 0 : sizeFilters );
00422 std::multimap< trigger::size_type, int > objectTypes;
00423 std::multimap< trigger::size_type, std::string > filterLabels;
00424
00425 for ( size_t iF = 0; iF < sizeFilters; ++iF ) {
00426 const std::string nameFilter( handleTriggerEvent->filterTag( iF ).label() );
00427 const trigger::Keys & keys = handleTriggerEvent->filterKeys( iF );
00428 const trigger::Vids & types = handleTriggerEvent->filterIds( iF );
00429 assert( types.size() == keys.size() );
00430 for ( size_t iK = 0; iK < keys.size(); ++iK ) {
00431 filterLabels.insert( std::pair< trigger::size_type, std::string >( keys[ iK ], nameFilter ) );
00432 objectTypes.insert( std::pair< trigger::size_type, int >( keys[ iK ], types[ iK ] ) );
00433 }
00434 }
00435
00436
00437
00438 const trigger::Keys & collectionKeys( handleTriggerEvent->collectionKeys() );
00439 std::map< trigger::size_type, trigger::size_type > newObjectKeys;
00440 for ( size_t iO = 0, iC = 0; iO < sizeObjects && iC < handleTriggerEvent->sizeCollections(); ++iO ) {
00441
00442 TriggerObject triggerObject( handleTriggerEvent->getObjects().at( iO ) );
00443
00444 while ( iO >= collectionKeys[ iC ] ) ++iC;
00445 triggerObject.setCollection( handleTriggerEvent->collectionTag( iC ) );
00446
00447 for ( std::multimap< trigger::size_type, int >::iterator iM = objectTypes.begin(); iM != objectTypes.end(); ++iM ) {
00448 if ( iM->first == iO ) {
00449 triggerObject.addTriggerObjectType( iM->second );
00450 }
00451 }
00452
00453
00454 TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
00455
00456 bool excluded( false );
00457 for ( size_t iE = 0; iE < exludeCollections_.size(); ++iE ) {
00458 if ( triggerObjectStandAlone.hasCollection( exludeCollections_.at( iE ) ) ) {
00459 newObjectKeys[ iO ] = trigger::size_type( sizeObjects );
00460 excluded = true;
00461 break;
00462 }
00463 }
00464 if ( excluded ) continue;
00465 for ( std::multimap< trigger::size_type, std::string >::iterator iM = filterLabels.begin(); iM != filterLabels.end(); ++iM ) {
00466 if ( iM->first == iO ) {
00467 triggerObjectStandAlone.addFilterLabel( iM->second );
00468 for ( std::multimap< std::string, std::pair< std::string, std::pair< bool, bool > > >::iterator iP = filterPaths.begin(); iP != filterPaths.end(); ++iP ) {
00469 if ( iP->first == iM->second ) {
00470 triggerObjectStandAlone.addPathName( iP->second.first, iP->second.second.first, iP->second.second.second );
00471 }
00472 }
00473 }
00474 }
00475
00476 if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
00477 triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
00478 newObjectKeys[ iO ] = trigger::size_type( triggerObjectsStandAlone->size() - 1 );
00479 }
00480
00481
00482
00483
00484 if ( ! onlyStandAlone_ ) {
00485 for ( size_t iF = 0; iF < sizeFilters; ++iF ) {
00486 const std::string nameFilter( handleTriggerEvent->filterTag( iF ).label() );
00487 const trigger::Keys & keys = handleTriggerEvent->filterKeys( iF );
00488 const trigger::Vids & types = handleTriggerEvent->filterIds( iF );
00489 TriggerFilter triggerFilter( nameFilter );
00490
00491 const std::string typeFilter( hltConfig_.moduleType( nameFilter ) );
00492 triggerFilter.setType( typeFilter );
00493 triggerFilter.setSaveTags( hltConfig_.saveTags( nameFilter ) );
00494
00495 for ( size_t iK = 0; iK < keys.size(); ++iK ) {
00496
00497 if ( newObjectKeys.find( keys.at( iK ) ) != newObjectKeys.end() ) {
00498 if ( newObjectKeys[ keys.at( iK ) ] == sizeObjects ) continue;
00499 triggerFilter.addObjectKey( keys.at( iK ) );
00500 triggerFilter.addTriggerObjectType( types.at( iK ) );
00501 } else {
00502 LogWarning( "triggerObjectKey" ) << "TriggerFilter '" << nameFilter << "' requests non-existing TriggerObject key " << keys.at( iK ) << "\n"
00503 << "Skipping object assignment";
00504 }
00505 }
00506
00507 std::map< std::string, int >::iterator iS( moduleStates.find( nameFilter ) );
00508 if ( iS != moduleStates.end() ) {
00509 if ( ! triggerFilter.setStatus( iS->second ) ) {
00510 triggerFilter.setStatus( -1 );
00511 }
00512 } else {
00513 triggerFilter.setStatus( -1 );
00514 }
00515
00516 triggerFilters->push_back( triggerFilter );
00517 }
00518
00519 iEvent.put( triggerFilters );
00520 }
00521
00522 }
00523
00524
00525
00526
00527
00528 std::map< L1GtObject, std::vector< unsigned > > l1ObjectTypeMap;
00529
00530 if ( ! tagL1ExtraMu_.label().empty() ) {
00531 Handle< l1extra::L1MuonParticleCollection > handleL1ExtraMu;
00532 iEvent.getByLabel( tagL1ExtraMu_, handleL1ExtraMu );
00533 if ( handleL1ExtraMu.isValid() ) {
00534 std::vector< unsigned > muKeys;
00535 for ( size_t l1Mu = 0; l1Mu < handleL1ExtraMu->size(); ++l1Mu ) {
00536 if ( mainBxOnly_ && handleL1ExtraMu->at( l1Mu ).bx() != 0 ) continue;
00537 TriggerObject triggerObject;
00538 if ( saveL1Refs_ ) {
00539 const reco::CandidateBaseRef leafCandRef( l1extra::L1MuonParticleRef( handleL1ExtraMu, l1Mu ) );
00540 triggerObject = TriggerObject( leafCandRef );
00541 } else {
00542 const reco::LeafCandidate * leafCandidate( handleL1ExtraMu->at( l1Mu ).reco::LeafCandidate::clone() );
00543 triggerObject = TriggerObject( *leafCandidate );
00544 }
00545 triggerObject.setCollection( tagL1ExtraMu_ );
00546 triggerObject.addTriggerObjectType( trigger::TriggerL1Mu );
00547 if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
00548 TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
00549 triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
00550 if ( handleL1ExtraMu->at( l1Mu ).bx() == 0 ) muKeys.push_back( triggerObjectsStandAlone->size() - 1 );
00551 }
00552 l1ObjectTypeMap.insert( std::make_pair( Mu, muKeys ) );
00553 } else LogError( "l1ExtraValid" ) << "l1extra::L1MuonParticleCollection product with InputTag '" << tagL1ExtraMu_.encode() << "' not in event";
00554 }
00555 if ( ! tagL1ExtraNoIsoEG_.label().empty() ) {
00556 Handle< l1extra::L1EmParticleCollection > handleL1ExtraNoIsoEG;
00557 iEvent.getByLabel( tagL1ExtraNoIsoEG_, handleL1ExtraNoIsoEG );
00558 if ( handleL1ExtraNoIsoEG.isValid() ) {
00559 std::vector< unsigned > noIsoEGKeys;
00560 for ( size_t l1NoIsoEG = 0; l1NoIsoEG < handleL1ExtraNoIsoEG->size(); ++l1NoIsoEG ) {
00561 if ( mainBxOnly_ && handleL1ExtraNoIsoEG->at( l1NoIsoEG ).bx() != 0 ) continue;
00562 TriggerObject triggerObject;
00563 if ( saveL1Refs_ ) {
00564 const reco::CandidateBaseRef leafCandRef( l1extra::L1EmParticleRef( handleL1ExtraNoIsoEG, l1NoIsoEG ) );
00565 triggerObject = TriggerObject( leafCandRef );
00566 } else {
00567 const reco::LeafCandidate * leafCandidate( handleL1ExtraNoIsoEG->at( l1NoIsoEG ).reco::LeafCandidate::clone() );
00568 triggerObject = TriggerObject( *leafCandidate );
00569 }
00570 triggerObject.setCollection( tagL1ExtraNoIsoEG_ );
00571 triggerObject.addTriggerObjectType( trigger::TriggerL1NoIsoEG );
00572 if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
00573 TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
00574 triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
00575 if ( handleL1ExtraNoIsoEG->at( l1NoIsoEG ).bx() == 0 ) noIsoEGKeys.push_back( triggerObjectsStandAlone->size() - 1 );
00576 }
00577 l1ObjectTypeMap.insert( std::make_pair( NoIsoEG, noIsoEGKeys ) );
00578 } else LogError( "l1ExtraValid" ) << "l1extra::L1EmParticleCollection product with InputTag '" << tagL1ExtraNoIsoEG_.encode() << "' not in event";
00579 }
00580 if ( ! tagL1ExtraIsoEG_.label().empty() ) {
00581 Handle< l1extra::L1EmParticleCollection > handleL1ExtraIsoEG;
00582 iEvent.getByLabel( tagL1ExtraIsoEG_, handleL1ExtraIsoEG );
00583 if ( handleL1ExtraIsoEG.isValid() ) {
00584 std::vector< unsigned > isoEGKeys;
00585 for ( size_t l1IsoEG = 0; l1IsoEG < handleL1ExtraIsoEG->size(); ++l1IsoEG ) {
00586 if ( mainBxOnly_ && handleL1ExtraIsoEG->at( l1IsoEG ).bx() != 0 ) continue;
00587 TriggerObject triggerObject;
00588 if ( saveL1Refs_ ) {
00589 const reco::CandidateBaseRef leafCandRef( l1extra::L1EmParticleRef( handleL1ExtraIsoEG, l1IsoEG ) );
00590 triggerObject = TriggerObject( leafCandRef );
00591 } else {
00592 const reco::LeafCandidate * leafCandidate( handleL1ExtraIsoEG->at( l1IsoEG ).reco::LeafCandidate::clone() );
00593 triggerObject = TriggerObject( *leafCandidate );
00594 }
00595 triggerObject.setCollection( tagL1ExtraIsoEG_ );
00596 triggerObject.addTriggerObjectType( trigger::TriggerL1IsoEG );
00597 if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
00598 TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
00599 triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
00600 if ( handleL1ExtraIsoEG->at( l1IsoEG ).bx() == 0 ) isoEGKeys.push_back( triggerObjectsStandAlone->size() - 1 );
00601 }
00602 l1ObjectTypeMap.insert( std::make_pair( IsoEG, isoEGKeys ) );
00603 } else LogError( "l1ExtraValid" ) << "l1extra::L1EmParticleCollection product with InputTag '" << tagL1ExtraIsoEG_.encode() << "' not in event";
00604 }
00605 if ( ! tagL1ExtraCenJet_.label().empty() ) {
00606 Handle< l1extra::L1JetParticleCollection > handleL1ExtraCenJet;
00607 iEvent.getByLabel( tagL1ExtraCenJet_, handleL1ExtraCenJet );
00608 if ( handleL1ExtraCenJet.isValid() ) {
00609 std::vector< unsigned > cenJetKeys;
00610 for ( size_t l1CenJet = 0; l1CenJet < handleL1ExtraCenJet->size(); ++l1CenJet ) {
00611 if ( mainBxOnly_ && handleL1ExtraCenJet->at( l1CenJet ).bx() != 0 ) continue;
00612 TriggerObject triggerObject;
00613 if ( saveL1Refs_ ) {
00614 const reco::CandidateBaseRef leafCandRef( l1extra::L1JetParticleRef( handleL1ExtraCenJet, l1CenJet ) );
00615 triggerObject = TriggerObject( leafCandRef );
00616 } else {
00617 const reco::LeafCandidate * leafCandidate( handleL1ExtraCenJet->at( l1CenJet ).reco::LeafCandidate::clone() );
00618 triggerObject = TriggerObject( *leafCandidate );
00619 }
00620 triggerObject.setCollection( tagL1ExtraCenJet_ );
00621 triggerObject.addTriggerObjectType( trigger::TriggerL1CenJet );
00622 if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
00623 TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
00624 triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
00625 if ( handleL1ExtraCenJet->at( l1CenJet ).bx() == 0 ) cenJetKeys.push_back( triggerObjectsStandAlone->size() - 1 );
00626 }
00627 l1ObjectTypeMap.insert( std::make_pair( CenJet, cenJetKeys ) );
00628 } else LogError( "l1ExtraValid" ) << "l1extra::L1JetParticleCollection product with InputTag '" << tagL1ExtraCenJet_.encode() << "' not in event";
00629 }
00630 if ( ! tagL1ExtraForJet_.label().empty() ) {
00631 Handle< l1extra::L1JetParticleCollection > handleL1ExtraForJet;
00632 iEvent.getByLabel( tagL1ExtraForJet_, handleL1ExtraForJet );
00633 if ( handleL1ExtraForJet.isValid() ) {
00634 std::vector< unsigned > forJetKeys;
00635 for ( size_t l1ForJet = 0; l1ForJet < handleL1ExtraForJet->size(); ++l1ForJet ) {
00636 if ( mainBxOnly_ && handleL1ExtraForJet->at( l1ForJet ).bx() != 0 ) continue;
00637 TriggerObject triggerObject;
00638 if ( saveL1Refs_ ) {
00639 const reco::CandidateBaseRef leafCandRef( l1extra::L1JetParticleRef( handleL1ExtraForJet, l1ForJet ) );
00640 triggerObject = TriggerObject( leafCandRef );
00641 } else {
00642 const reco::LeafCandidate * leafCandidate( handleL1ExtraForJet->at( l1ForJet ).reco::LeafCandidate::clone() );
00643 triggerObject = TriggerObject( *leafCandidate );
00644 }
00645 triggerObject.setCollection( tagL1ExtraForJet_ );
00646 triggerObject.addTriggerObjectType( trigger::TriggerL1ForJet );
00647 if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
00648 TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
00649 triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
00650 if ( handleL1ExtraForJet->at( l1ForJet ).bx() == 0 ) forJetKeys.push_back( triggerObjectsStandAlone->size() - 1 );
00651 }
00652 l1ObjectTypeMap.insert( std::make_pair( ForJet, forJetKeys ) );
00653 } else LogError( "l1ExtraValid" ) << "l1extra::L1JetParticleCollection product with InputTag '" << tagL1ExtraForJet_.encode() << "' not in event";
00654 }
00655 if ( ! tagL1ExtraTauJet_.label().empty() ) {
00656 Handle< l1extra::L1JetParticleCollection > handleL1ExtraTauJet;
00657 iEvent.getByLabel( tagL1ExtraTauJet_, handleL1ExtraTauJet );
00658 if ( handleL1ExtraTauJet.isValid() ) {
00659 std::vector< unsigned > tauJetKeys;
00660 for ( size_t l1TauJet = 0; l1TauJet < handleL1ExtraTauJet->size(); ++l1TauJet ) {
00661 if ( mainBxOnly_ && handleL1ExtraTauJet->at( l1TauJet ).bx() != 0 ) continue;
00662 TriggerObject triggerObject;
00663 if ( saveL1Refs_ ) {
00664 const reco::CandidateBaseRef leafCandRef( l1extra::L1JetParticleRef( handleL1ExtraTauJet, l1TauJet ) );
00665 triggerObject = TriggerObject( leafCandRef );
00666 } else {
00667 const reco::LeafCandidate * leafCandidate( handleL1ExtraTauJet->at( l1TauJet ).reco::LeafCandidate::clone() );
00668 triggerObject = TriggerObject( *leafCandidate );
00669 }
00670 triggerObject.setCollection( tagL1ExtraTauJet_ );
00671 triggerObject.addTriggerObjectType( trigger::TriggerL1TauJet );
00672 if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
00673 TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
00674 triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
00675 if ( handleL1ExtraTauJet->at( l1TauJet ).bx() == 0 ) tauJetKeys.push_back( triggerObjectsStandAlone->size() - 1 );
00676 }
00677 l1ObjectTypeMap.insert( std::make_pair( TauJet, tauJetKeys ) );
00678 } else LogError( "l1ExtraValid" ) << "l1extra::L1JetParticleCollection product with InputTag '" << tagL1ExtraTauJet_.encode() << "' not in event";
00679 }
00680 if ( ! tagL1ExtraETM_ .label().empty()) {
00681 Handle< l1extra::L1EtMissParticleCollection > handleL1ExtraETM;
00682 iEvent.getByLabel( tagL1ExtraETM_, handleL1ExtraETM );
00683 if ( handleL1ExtraETM.isValid() ) {
00684 std::vector< unsigned > etmKeys;
00685 for ( size_t l1ETM = 0; l1ETM < handleL1ExtraETM->size(); ++l1ETM ) {
00686 if ( mainBxOnly_ && handleL1ExtraETM->at( l1ETM ).bx() != 0 ) continue;
00687 TriggerObject triggerObject;
00688 if ( saveL1Refs_ ) {
00689 const reco::CandidateBaseRef leafCandRef( l1extra::L1EtMissParticleRef( handleL1ExtraETM, l1ETM ) );
00690 triggerObject = TriggerObject( leafCandRef );
00691 } else {
00692 const reco::LeafCandidate * leafCandidate( handleL1ExtraETM->at( l1ETM ).reco::LeafCandidate::clone() );
00693 triggerObject = TriggerObject( *leafCandidate );
00694 }
00695 triggerObject.setCollection( tagL1ExtraETM_ );
00696 triggerObject.addTriggerObjectType( trigger::TriggerL1ETM );
00697 if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
00698 TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
00699 triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
00700 if ( handleL1ExtraETM->at( l1ETM ).bx() == 0 ) etmKeys.push_back( triggerObjectsStandAlone->size() - 1 );
00701 }
00702 l1ObjectTypeMap.insert( std::make_pair( ETM, etmKeys ) );
00703 } else LogError( "l1ExtraValid" ) << "l1extra::L1EtMissParticleCollection product with InputTag '" << tagL1ExtraETM_.encode() << "' not in event";
00704 }
00705 if ( ! tagL1ExtraHTM_.label().empty() ) {
00706 Handle< l1extra::L1EtMissParticleCollection > handleL1ExtraHTM;
00707 iEvent.getByLabel( tagL1ExtraHTM_, handleL1ExtraHTM );
00708 if ( handleL1ExtraHTM.isValid() ) {
00709 std::vector< unsigned > htmKeys;
00710 for ( size_t l1HTM = 0; l1HTM < handleL1ExtraHTM->size(); ++l1HTM ) {
00711 if ( mainBxOnly_ && handleL1ExtraHTM->at( l1HTM ).bx() != 0 ) continue;
00712 TriggerObject triggerObject;
00713 if ( saveL1Refs_ ) {
00714 const reco::CandidateBaseRef leafCandRef( l1extra::L1EtMissParticleRef( handleL1ExtraHTM, l1HTM ) );
00715 triggerObject = TriggerObject( leafCandRef );
00716 } else {
00717 const reco::LeafCandidate * leafCandidate( handleL1ExtraHTM->at( l1HTM ).reco::LeafCandidate::clone() );
00718 triggerObject = TriggerObject( *leafCandidate );
00719 }
00720 triggerObject.setCollection( tagL1ExtraHTM_ );
00721 triggerObject.addTriggerObjectType( trigger::TriggerL1HTM );
00722 if ( ! onlyStandAlone_ ) triggerObjects->push_back( triggerObject );
00723 TriggerObjectStandAlone triggerObjectStandAlone( triggerObject );
00724 triggerObjectsStandAlone->push_back( triggerObjectStandAlone );
00725 if ( handleL1ExtraHTM->at( l1HTM ).bx() == 0 ) htmKeys.push_back( triggerObjectsStandAlone->size() - 1 );
00726 }
00727 l1ObjectTypeMap.insert( std::make_pair( HTM, htmKeys ) );
00728 } else LogError( "l1ExtraValid" ) << "l1extra::L1EtMissParticleCollection product with InputTag '" << tagL1ExtraHTM_.encode() << "' not in event";
00729 }
00730
00731
00732 if ( ! onlyStandAlone_ ) iEvent.put( triggerObjects );
00733
00734
00735 if ( ! onlyStandAlone_ ) {
00736 std::auto_ptr< TriggerAlgorithmCollection > triggerAlgos( new TriggerAlgorithmCollection() );
00737 std::auto_ptr< TriggerConditionCollection > triggerConditions( new TriggerConditionCollection() );
00738 if ( addL1Algos_ ) {
00739
00740 std::map< L1GtObject, trigger::TriggerObjectType > mapObjectTypes;
00741 mapObjectTypes.insert( std::make_pair( Mu , trigger::TriggerL1Mu ) );
00742 mapObjectTypes.insert( std::make_pair( NoIsoEG, trigger::TriggerL1NoIsoEG ) );
00743 mapObjectTypes.insert( std::make_pair( IsoEG , trigger::TriggerL1IsoEG ) );
00744 mapObjectTypes.insert( std::make_pair( CenJet , trigger::TriggerL1CenJet ) );
00745 mapObjectTypes.insert( std::make_pair( ForJet , trigger::TriggerL1ForJet ) );
00746 mapObjectTypes.insert( std::make_pair( TauJet , trigger::TriggerL1TauJet ) );
00747 mapObjectTypes.insert( std::make_pair( ETM , trigger::TriggerL1ETM ) );
00748 mapObjectTypes.insert( std::make_pair( HTM , trigger::TriggerL1HTM ) );
00749
00750 l1GtUtils_.retrieveL1EventSetup( iSetup );
00751 ESHandle< L1GtTriggerMenu > handleL1GtTriggerMenu;
00752 iSetup.get< L1GtTriggerMenuRcd >().get( handleL1GtTriggerMenu );
00753 L1GtTriggerMenu l1GtTriggerMenu( *handleL1GtTriggerMenu );
00754 const AlgorithmMap l1GtAlgorithms( l1GtTriggerMenu.gtAlgorithmMap() );
00755 const AlgorithmMap l1GtTechTriggers( l1GtTriggerMenu.gtTechnicalTriggerMap() );
00756 l1GtTriggerMenu.buildGtConditionMap();
00757 const std::vector< ConditionMap > l1GtConditionsVector( l1GtTriggerMenu.gtConditionMap() );
00758
00759 ConditionMap l1GtConditions;
00760 for ( size_t iCv = 0; iCv < l1GtConditionsVector.size(); ++iCv ) {
00761 l1GtConditions.insert( l1GtConditionsVector.at( iCv ).begin(), l1GtConditionsVector.at( iCv ).end() );
00762 }
00763 triggerAlgos->reserve( l1GtAlgorithms.size() + l1GtTechTriggers.size() );
00764 Handle< L1GlobalTriggerObjectMapRecord > handleL1GlobalTriggerObjectMapRecord;
00765 iEvent.getByLabel( tagL1GlobalTriggerObjectMapRecord_, handleL1GlobalTriggerObjectMapRecord );
00766 if( ! handleL1GlobalTriggerObjectMapRecord.isValid() ) {
00767 LogWarning( "l1ObjectMap" ) << "L1GlobalTriggerObjectMapRecord product with InputTag '" << tagL1GlobalTriggerObjectMapRecord_.encode() << "' not in event\n"
00768 << "No L1 objects and GTL results available for physics algorithms";
00769 }
00770
00771 for ( CItAlgo iAlgo = l1GtAlgorithms.begin(); iAlgo != l1GtAlgorithms.end(); ++iAlgo ) {
00772 const std::string & algoName( iAlgo->second.algoName() );
00773 if ( ! ( iAlgo->second.algoBitNumber() < int( L1GlobalTriggerReadoutSetup::NumberPhysTriggers ) ) ) {
00774 LogError( "l1Algo" ) << "L1 physics algorithm '" << algoName << "' has bit number " << iAlgo->second.algoBitNumber() << " >= " << L1GlobalTriggerReadoutSetup::NumberPhysTriggers << "\n"
00775 << "Skipping";
00776 continue;
00777 }
00778 L1GtUtils::TriggerCategory category;
00779 int bit;
00780 if ( ! l1GtUtils_.l1AlgoTechTrigBitNumber( algoName, category, bit ) ) {
00781 LogError( "l1Algo" ) << "L1 physics algorithm '" << algoName << "' not found in the L1 menu\n"
00782 << "Skipping";
00783 continue;
00784 }
00785 if ( category != L1GtUtils::AlgorithmTrigger ) {
00786 LogError( "l1Algo" ) << "L1 physics algorithm '" << algoName << "' does not have category 'AlgorithmTrigger' from 'L1GtUtils'\n"
00787 << "Skipping";
00788 continue;
00789 }
00790 bool decisionBeforeMask;
00791 bool decisionAfterMask;
00792 int prescale;
00793 int mask;
00794 int error( l1GtUtils_.l1Results( iEvent, algoName, decisionBeforeMask, decisionAfterMask, prescale, mask ) );
00795 if ( error ) {
00796 LogError( "l1Algo" ) << "L1 physics algorithm '" << algoName << "' decision has error code " << error << " from 'L1GtUtils'\n"
00797 << "Skipping";
00798 continue;
00799 }
00800 TriggerAlgorithm triggerAlgo( algoName, iAlgo->second.algoAlias(), category == L1GtUtils::TechnicalTrigger, (unsigned)bit, (unsigned)prescale, (bool)mask, decisionBeforeMask, decisionAfterMask );
00801 triggerAlgo.setLogicalExpression( iAlgo->second.algoLogicalExpression() );
00802
00803 if( ! handleL1GlobalTriggerObjectMapRecord.isValid() ) {
00804 triggerAlgos->push_back( triggerAlgo );
00805 continue;
00806 }
00807 const L1GlobalTriggerObjectMap * l1ObjectMap( handleL1GlobalTriggerObjectMapRecord->getObjectMap( algoName ) );
00808 if ( ! l1ObjectMap ) {
00809 LogError( "l1ObjectMap" ) << "L1 physics algorithm '" << algoName << "' is missing in L1GlobalTriggerObjectMapRecord\n"
00810 << "Skipping conditions and GTL result";
00811 triggerAlgos->push_back( triggerAlgo );
00812 continue;
00813 }
00814
00815 if ( ( l1ObjectMap->algoGtlResult() != decisionBeforeMask ) && ( decisionBeforeMask == true ) ) {
00816 LogInfo( "l1ObjectMap" ) << "L1 physics algorithm '" << algoName << "' with different decisions in\n"
00817 << "L1GlobalTriggerObjectMapRecord (GTL result) : " << l1ObjectMap->algoGtlResult() << "\n"
00818 << "L1GlobalTriggerReadoutRecord (decision before mask): " << decisionBeforeMask;
00819 }
00820 triggerAlgo.setGtlResult( l1ObjectMap->algoGtlResult() );
00821
00822 const std::vector< L1GtLogicParser::OperandToken > & tokens( l1ObjectMap->operandTokenVector() );
00823 for ( size_t iT = 0; iT < tokens.size(); ++iT ) {
00824 const L1GtLogicParser::OperandToken & token( tokens.at( iT ) );
00825 size_t key( triggerConditions->size() );
00826 for ( size_t iC = 0; iC < triggerConditions->size(); ++iC ) {
00827 if ( token.tokenName == triggerConditions->at( iC ).name() ) {
00828 key = iC;
00829 break;
00830 }
00831 }
00832 if ( key == triggerConditions->size() ) {
00833 TriggerCondition triggerCond( token.tokenName, token.tokenResult );
00834 if ( l1GtConditions.find( triggerCond.name() ) != l1GtConditions.end() ) {
00835 triggerCond.setCategory( l1GtConditions[ triggerCond.name() ]->condCategory() );
00836 triggerCond.setType( l1GtConditions[ triggerCond.name() ]->condType() );
00837 const std::vector< L1GtObject > l1ObjectTypes( l1GtConditions[ triggerCond.name() ]->objectType() );
00838 for ( size_t iT = 0 ; iT < l1ObjectTypes.size(); ++iT ) {
00839 triggerCond.addTriggerObjectType( mapObjectTypes[ l1ObjectTypes.at( iT ) ] );
00840 }
00841
00842 CombinationsInCond combis( l1ObjectMap->combinationVector().at( token.tokenNumber ) );
00843 for ( size_t iVV = 0; iVV < combis.size(); ++iVV ) {
00844 SingleCombInCond combi( combis.at( iVV ) );
00845 for ( size_t iV = 0; iV < combi.size(); ++iV ) {
00846 if ( iV >= l1ObjectTypes.size() ) {
00847 LogError( "l1CondMap" ) << "Index " << iV << " in combinations vector overshoots size " << l1ObjectTypes.size() << " of types vector in conditions map\n"
00848 << "Skipping object key in condition " << triggerCond.name();
00849 } else if ( l1ObjectTypeMap.find( l1ObjectTypes.at( iV ) ) != l1ObjectTypeMap.end() ) {
00850 if ( combi.at( iV ) >= int( l1ObjectTypeMap[ l1ObjectTypes.at( iV ) ].size() ) ) {
00851 LogError( "l1CondMap" ) << "Index " << combi.at( iV ) << " in combination overshoots number " << l1ObjectTypeMap[ l1ObjectTypes.at( iV ) ].size() << "of according trigger objects\n"
00852 << "Skipping object key in condition " << triggerCond.name();
00853 }
00854 const unsigned objectKey( l1ObjectTypeMap[ l1ObjectTypes.at( iV ) ].at( combi.at( iV ) ) );
00855 triggerCond.addObjectKey( objectKey );
00856
00857 triggerObjectsStandAlone->at( objectKey ).addAlgorithmName( triggerAlgo.name(), ( triggerAlgo.decision() && triggerCond.wasAccept() ) );
00858 triggerObjectsStandAlone->at( objectKey ).addConditionName( triggerCond.name() );
00859 }
00860 }
00861 }
00862 } else {
00863 LogWarning( "l1CondMap" ) << "L1 conditions '" << triggerCond.name() << "' not found in the L1 menu\n"
00864 << "Remains incomplete";
00865 }
00866 triggerConditions->push_back( triggerCond );
00867 }
00868 triggerAlgo.addConditionKey( key );
00869 }
00870 triggerAlgos->push_back( triggerAlgo );
00871 }
00872
00873 for ( CItAlgo iAlgo = l1GtTechTriggers.begin(); iAlgo != l1GtTechTriggers.end(); ++iAlgo ) {
00874 const std::string & algoName( iAlgo->second.algoName() );
00875 if ( ! ( iAlgo->second.algoBitNumber() < int( L1GlobalTriggerReadoutSetup::NumberTechnicalTriggers ) ) ) {
00876 LogError( "l1Algo" ) << "L1 technical trigger '" << algoName << "' has bit number " << iAlgo->second.algoBitNumber() << " >= " << L1GlobalTriggerReadoutSetup::NumberTechnicalTriggers << "\n"
00877 << "Skipping";
00878 continue;
00879 }
00880 L1GtUtils::TriggerCategory category;
00881 int bit;
00882 if ( ! l1GtUtils_.l1AlgoTechTrigBitNumber( algoName, category, bit ) ) {
00883 LogError( "l1Algo" ) << "L1 technical trigger '" << algoName << "' not found in the L1 menu\n"
00884 << "Skipping";
00885 continue;
00886 }
00887 if ( category != L1GtUtils::TechnicalTrigger ) {
00888 LogError( "l1Algo" ) << "L1 technical trigger '" << algoName << "' does not have category 'TechnicalTrigger' from 'L1GtUtils'\n"
00889 << "Skipping";
00890 continue;
00891 }
00892 bool decisionBeforeMask;
00893 bool decisionAfterMask;
00894 int prescale;
00895 int mask;
00896 int error( l1GtUtils_.l1Results( iEvent, algoName, decisionBeforeMask, decisionAfterMask, prescale, mask ) );
00897 if ( error ) {
00898 LogError( "l1Algo" ) << "L1 technical trigger '" << algoName << "' decision has error code " << error << " from 'L1GtUtils'\n"
00899 << "Skipping";
00900 continue;
00901 }
00902 TriggerAlgorithm triggerAlgo( algoName, iAlgo->second.algoAlias(), category == L1GtUtils::TechnicalTrigger, (unsigned)bit, (unsigned)prescale, (bool)mask, decisionBeforeMask, decisionAfterMask );
00903 triggerAlgo.setLogicalExpression( iAlgo->second.algoLogicalExpression() );
00904 triggerAlgos->push_back( triggerAlgo );
00905 }
00906 }
00907
00908
00909 iEvent.put( triggerAlgos );
00910 iEvent.put( triggerConditions );
00911 }
00912
00913
00914 iEvent.put( triggerObjectsStandAlone );
00915
00916 }
00917
00918
00919 #include "FWCore/Framework/interface/MakerMacros.h"
00920 DEFINE_FWK_MODULE( PATTriggerProducer );