00001 00009 #include "FWCore/Framework/interface/EDProducer.h" 00010 #include "FWCore/ParameterSet/interface/InputTag.h" 00011 #include "DataFormats/Candidate/interface/CandidateFwd.h" 00012 #include <vector> 00013 00014 namespace edm { class ParameterSet; } 00015 namespace HepMC { class GenParticle; class GenEvent; } 00016 00017 class GenEventScaleProducer : public edm::EDProducer { 00018 public: 00020 GenEventScaleProducer( const edm::ParameterSet & ); 00021 00022 private: 00023 void produce( edm::Event& evt, const edm::EventSetup& es ); 00024 edm::InputTag src_; 00025 }; 00026 00027 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h" 00028 #include "DataFormats/Common/interface/Handle.h" 00029 #include "FWCore/Framework/interface/Event.h" 00030 #include "FWCore/Utilities/interface/EDMException.h" 00031 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00032 using namespace edm; 00033 using namespace std; 00034 using namespace HepMC; 00035 00036 GenEventScaleProducer::GenEventScaleProducer( const ParameterSet & p ) : 00037 src_( p.getParameter<InputTag>( "src" ) ) { 00038 produces<double>(); 00039 } 00040 00041 00042 void GenEventScaleProducer::produce( Event& evt, const EventSetup& es ) { 00043 Handle<HepMCProduct> mc; 00044 evt.getByLabel( src_, mc ); 00045 const GenEvent * genEvt = mc->GetEvent(); 00046 if( genEvt == 0 ) 00047 throw edm::Exception( edm::errors::InvalidReference ) 00048 << "HepMC has null pointer to GenEvent" << endl; 00049 auto_ptr<double> event_scale( new double(1) ); 00050 (*event_scale) = genEvt->event_scale(); 00051 evt.put( event_scale ); 00052 } 00053 00054 #include "FWCore/Framework/interface/MakerMacros.h" 00055 00056 DEFINE_FWK_MODULE( GenEventScaleProducer ); 00057