00001 // 00002 // $Id: PATTrigProducer.cc,v 1.2 2008/06/08 12:24:03 vadler Exp $ 00003 // 00004 00005 00006 #include "PhysicsTools/PatAlgos/plugins/PATTrigProducer.h" 00007 00008 #include "DataFormats/HLTReco/interface/TriggerEvent.h" 00009 00010 #include "DataFormats/PatCandidates/interface/TriggerPrimitive.h" 00011 00012 00013 using namespace pat; 00014 using namespace trigger; 00015 using namespace edm; 00016 using namespace std; 00017 00018 00019 PATTrigProducer::PATTrigProducer( const ParameterSet & iConfig ) : 00020 // initialize 00021 triggerEvent_ (iConfig.getParameter<InputTag>( "triggerEvent" ) ), 00022 filterName_ (iConfig.getParameter<InputTag>( "filterName" ) ) 00023 { 00024 produces<TriggerPrimitiveCollection>(); 00025 } 00026 00027 00028 PATTrigProducer::~PATTrigProducer() 00029 { 00030 } 00031 00032 00033 void PATTrigProducer::produce( Event& iEvent, const EventSetup& iSetup ) 00034 { 00035 auto_ptr<TriggerPrimitiveCollection> patTrigCandidates( new TriggerPrimitiveCollection ); 00036 Handle<TriggerEvent> triggerEvent; 00037 try { // In this case, we want to act differently compared to the usual behaviour on "ProductNotFound" exception thrown by Event::getByLabel. 00038 iEvent.getByLabel( triggerEvent_, triggerEvent ); 00039 size_type nFilters = triggerEvent->sizeFilters(); 00040 if ( nFilters == 0 ) { 00041 LogDebug( "noTriggerFilters" ) << "PATTrigProducer: The TriggerEvent of this event contains no filter information at all!"; 00042 } else { 00043 size_type iFilter = triggerEvent->filterIndex( filterName_ ); 00044 if ( iFilter == nFilters ) { 00045 LogDebug( "noTriggerFilter" ) << "PATTrigProducer: The TriggerEvent of this event contains no filter information on filter " << filterName_.label() << "!"; 00046 } else { 00047 const Vids & triggerIds = triggerEvent->filterIds( iFilter ); 00048 const Keys & triggerKeys = triggerEvent->filterKeys( iFilter ); 00049 const TriggerObjectCollection & triggerObjects = triggerEvent->getObjects(); 00050 assert( triggerIds.size() == triggerKeys.size() ); 00051 for ( size_type idx = 0; idx < triggerKeys.size(); ++idx ) { 00052 const TriggerObject triggerObject = triggerObjects.at( triggerKeys.at( idx ) ); 00053 auto_ptr<TriggerPrimitive> ptr( new TriggerPrimitive( triggerObject.particle().p4(), filterName_.label(), triggerIds.at( idx ), triggerObject.id() ) ); 00054 patTrigCandidates->push_back( ptr ); 00055 } 00056 } 00057 } 00058 } catch( Exception exc ) { 00059 if ( exc.categoryCode() == errors::ProductNotFound ) { 00060 LogWarning( "noTriggerEvent" ) << "PATTrigProducer: No TriggerEvent " << triggerEvent_.label() << " found!"; 00061 } else { 00062 throw exc; 00063 } 00064 } 00065 iEvent.put( patTrigCandidates ); 00066 } 00067 00068 00069 #include "FWCore/Framework/interface/MakerMacros.h" 00070 DEFINE_FWK_MODULE(PATTrigProducer);