CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RivetAnalyzer.cc
Go to the documentation of this file.
2 
6 
9 
10 #include "Rivet/AnalysisHandler.hh"
11 #include "Rivet/Analysis.hh"
12 
13 #include <string>
14 #include <vector>
15 #include <iostream>
16 #include <cstdlib>
17 #include <cstring>
18 
19 using namespace Rivet;
20 using namespace edm;
21 
23 _analysisHandler(),
24 _isFirstEvent(true),
25 _outFileName(pset.getParameter<std::string>("OutputFile"))
26 {
27  //retrive the analysis name from paarmeter set
28  std::vector<std::string> analysisNames = pset.getParameter<std::vector<std::string> >("AnalysisNames");
29 
30  _hepmcCollection = pset.getParameter<edm::InputTag>("HepMCCollection");
31 
32  //get the analyses
33  _analysisHandler.addAnalyses(analysisNames);
34 
35  //go through the analyses and check those that need the cross section
36  const std::set< AnaHandle, AnaHandleLess > & analyses = _analysisHandler.analyses();
37 
38  std::set< AnaHandle, AnaHandleLess >::const_iterator ibeg = analyses.begin();
39  std::set< AnaHandle, AnaHandleLess >::const_iterator iend = analyses.end();
40  std::set< AnaHandle, AnaHandleLess >::const_iterator iana;
41  double xsection = -1.;
42  xsection = pset.getParameter<double>("CrossSection");
43  for (iana = ibeg; iana != iend; ++iana){
44  if ((*iana)->needsCrossSection())
45  (*iana)->setCrossSection(xsection);
46  }
47 }
48 
50 }
51 
53  //set the environment, very ugly but rivet is monolithic when it comes to paths
54  char * cmsswbase = getenv("CMSSW_BASE");
55  char * cmsswrelease = getenv("CMSSW_RELEASE_BASE");
56  std::string rivetref, rivetinfo;
57  rivetref = "RIVET_REF_PATH=" + string(cmsswbase) + "/src/GeneratorInterface/RivetInterface/data:" + string(cmsswrelease) + "/src/GeneratorInterface/RivetInterface/data";
58  rivetinfo = "RIVET_INFO_PATH=" + string(cmsswbase) + "/src/GeneratorInterface/RivetInterface/data:" + string(cmsswrelease) + "/src/GeneratorInterface/RivetInterface/data";
59  putenv(strdup(rivetref.c_str()));
60  putenv(strdup(rivetinfo.c_str()));
61 }
62 
63 void RivetAnalyzer::beginRun(const edm::Run& iRun,const edm::EventSetup& iSetup){
64  return;
65 }
66 
68 
69  //get the hepmc product from the event
71  iEvent.getByLabel(_hepmcCollection, evt);
72 
73  // get HepMC GenEvent
74  const HepMC::GenEvent *myGenEvent = evt->GetEvent();
75 
76  //aaply the beams initialization on the first event
77  if (_isFirstEvent){
78  _analysisHandler.init(*myGenEvent);
79  _isFirstEvent = false;
80  }
81 
82  //run the analysis
83  _analysisHandler.analyze(*myGenEvent);
84 }
85 
86 
87 void RivetAnalyzer::endRun(const edm::Run& iRun,const edm::EventSetup& iSetup){
88  return;
89 }
90 
92  _analysisHandler.finalize();
93  _analysisHandler.writeData(_outFileName);
94 }
95 
T getParameter(std::string const &) const
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
virtual void endRun(const edm::Run &, const edm::EventSetup &)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::InputTag _hepmcCollection
Definition: RivetAnalyzer.h:35
Rivet::AnalysisHandler _analysisHandler
Definition: RivetAnalyzer.h:36
int iEvent
Definition: GenABIO.cc:243
RivetAnalyzer(const edm::ParameterSet &)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
std::string _outFileName
Definition: RivetAnalyzer.h:38
virtual ~RivetAnalyzer()
virtual void beginJob()
Definition: Run.h:32
virtual void endJob()