Go to the documentation of this file.00001 #include "GeneratorInterface/RivetInterface/interface/RivetAnalyzer.h"
00002
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/Framework/interface/MakerMacros.h"
00006
00007 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
00008 #include "DataFormats/Common/interface/Handle.h"
00009
00010 #include "Rivet/AnalysisHandler.hh"
00011 #include "Rivet/Analysis.hh"
00012
00013 #include <string>
00014 #include <vector>
00015 #include <iostream>
00016 #include <cstdlib>
00017 #include <cstring>
00018
00019 using namespace Rivet;
00020 using namespace edm;
00021
00022 RivetAnalyzer::RivetAnalyzer(const edm::ParameterSet& pset) :
00023 _analysisHandler(),
00024 _isFirstEvent(true),
00025 _outFileName(pset.getParameter<std::string>("OutputFile"))
00026 {
00027
00028 std::vector<std::string> analysisNames = pset.getParameter<std::vector<std::string> >("AnalysisNames");
00029
00030 _hepmcCollection = pset.getParameter<edm::InputTag>("HepMCCollection");
00031
00032
00033 _analysisHandler.addAnalyses(analysisNames);
00034
00035
00036 const std::set< AnaHandle, AnaHandleLess > & analyses = _analysisHandler.analyses();
00037
00038 std::set< AnaHandle, AnaHandleLess >::const_iterator ibeg = analyses.begin();
00039 std::set< AnaHandle, AnaHandleLess >::const_iterator iend = analyses.end();
00040 std::set< AnaHandle, AnaHandleLess >::const_iterator iana;
00041 double xsection = -1.;
00042 xsection = pset.getParameter<double>("CrossSection");
00043 for (iana = ibeg; iana != iend; ++iana){
00044 if ((*iana)->needsCrossSection())
00045 (*iana)->setCrossSection(xsection);
00046 }
00047 }
00048
00049 RivetAnalyzer::~RivetAnalyzer(){
00050 }
00051
00052 void RivetAnalyzer::beginJob(){
00053
00054 char * cmsswbase = getenv("CMSSW_BASE");
00055 char * cmsswrelease = getenv("CMSSW_RELEASE_BASE");
00056 std::string rivetref, rivetinfo;
00057 rivetref = "RIVET_REF_PATH=" + string(cmsswbase) + "/src/GeneratorInterface/RivetInterface/data:" + string(cmsswrelease) + "/src/GeneratorInterface/RivetInterface/data";
00058 rivetinfo = "RIVET_INFO_PATH=" + string(cmsswbase) + "/src/GeneratorInterface/RivetInterface/data:" + string(cmsswrelease) + "/src/GeneratorInterface/RivetInterface/data";
00059 putenv(strdup(rivetref.c_str()));
00060 putenv(strdup(rivetinfo.c_str()));
00061 }
00062
00063 void RivetAnalyzer::beginRun(const edm::Run& iRun,const edm::EventSetup& iSetup){
00064 return;
00065 }
00066
00067 void RivetAnalyzer::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup){
00068
00069
00070 edm::Handle<HepMCProduct> evt;
00071 iEvent.getByLabel(_hepmcCollection, evt);
00072
00073
00074 const HepMC::GenEvent *myGenEvent = evt->GetEvent();
00075
00076
00077 if (_isFirstEvent){
00078 _analysisHandler.init(*myGenEvent);
00079 _isFirstEvent = false;
00080 }
00081
00082
00083 _analysisHandler.analyze(*myGenEvent);
00084 }
00085
00086
00087 void RivetAnalyzer::endRun(const edm::Run& iRun,const edm::EventSetup& iSetup){
00088 return;
00089 }
00090
00091 void RivetAnalyzer::endJob(){
00092 _analysisHandler.finalize();
00093 _analysisHandler.writeData(_outFileName);
00094 }
00095
00096 DEFINE_FWK_MODULE(RivetAnalyzer);