1 |
#include "FWCore/Framework/interface/EDProducer.h"
|
2 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
3 |
|
4 |
#include <vector>
|
5 |
#include <string>
|
6 |
|
7 |
class HepMCFileReader;
|
8 |
|
9 |
namespace HepMC{
|
10 |
class GenEvent;
|
11 |
}
|
12 |
|
13 |
class MCFileReader : public edm::EDProducer {
|
14 |
public:
|
15 |
MCFileReader(const edm::ParameterSet &);
|
16 |
virtual ~MCFileReader();
|
17 |
|
18 |
private:
|
19 |
void produce(edm::Event&, const edm::EventSetup&);
|
20 |
void endRun(edm::Run&, edm::EventSetup const&);
|
21 |
|
22 |
std::vector<std::string> fileNames_;
|
23 |
HepMCFileReader *reader_;
|
24 |
HepMC::GenEvent *evt_;
|
25 |
};
|
26 |
|
27 |
#include "FWCore/Framework/interface/Event.h"
|
28 |
#include "FWCore/Framework/interface/Run.h"
|
29 |
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
30 |
#include "FWCore/Framework/interface/MakerMacros.h"
|
31 |
|
32 |
#include "ForwardAnalysis/Utilities/interface/HepMCFileReader.h"
|
33 |
#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
|
34 |
#include "SimDataFormats/GeneratorProducts/interface/GenRunInfoProduct.h"
|
35 |
#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
|
36 |
|
37 |
using namespace edm;
|
38 |
using namespace std;
|
39 |
|
40 |
MCFileReader::MCFileReader(const ParameterSet & pset):
|
41 |
fileNames_( pset.getUntrackedParameter<vector<string> >("fileNames") ),
|
42 |
reader_(HepMCFileReader::instance()), evt_(0)
|
43 |
{
|
44 |
LogInfo("MCFileReader") << "Reading HepMC file:" << fileNames_[0];
|
45 |
string fileName = fileNames_[0];
|
46 |
// strip the file:
|
47 |
if (fileName.find("file:") == 0){
|
48 |
fileName.erase(0,5);
|
49 |
}
|
50 |
|
51 |
reader_->initialize(fileName);
|
52 |
produces<HepMCProduct>();
|
53 |
produces<GenEventInfoProduct>();
|
54 |
produces<GenRunInfoProduct, edm::InRun>();
|
55 |
}
|
56 |
|
57 |
MCFileReader::~MCFileReader(){}
|
58 |
|
59 |
void MCFileReader::produce(Event & event, const EventSetup& setup){
|
60 |
auto_ptr<HepMCProduct> bare_product(new HepMCProduct());
|
61 |
|
62 |
LogInfo("MCFileSource") << "Start Reading";
|
63 |
evt_ = reader_->fillCurrentEventData();
|
64 |
if (evt_ == 0) return;
|
65 |
|
66 |
bare_product->addHepMCData(evt_);
|
67 |
event.put(bare_product);
|
68 |
|
69 |
auto_ptr<GenEventInfoProduct> genEventInfo( new GenEventInfoProduct(evt_) );
|
70 |
event.put(genEventInfo);
|
71 |
}
|
72 |
|
73 |
void MCFileReader::endRun(Run& run, EventSetup const& setup) {
|
74 |
|
75 |
auto_ptr<GenRunInfoProduct> genRunInfoProd( new GenRunInfoProduct() );
|
76 |
genRunInfoProd->setInternalXSec(-1.);
|
77 |
genRunInfoProd->setFilterEfficiency(-1.);
|
78 |
genRunInfoProd->setExternalXSecLO(-1.);
|
79 |
genRunInfoProd->setExternalXSecNLO(-1.);
|
80 |
|
81 |
run.put(genRunInfoProd);
|
82 |
}
|
83 |
DEFINE_FWK_MODULE(MCFileReader);
|