1 |
loizides |
1.7 |
// $Id: FillGenParts.cc,v 1.6 2008/06/17 13:31:38 loizides Exp $
|
2 |
loizides |
1.1 |
|
3 |
|
|
#include "MitProd/TreeFiller/interface/FillGenParts.h"
|
4 |
|
|
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
5 |
|
|
#include "FWCore/Framework/interface/ESHandle.h"
|
6 |
loizides |
1.5 |
#include "FWCore/ServiceRegistry/interface/Service.h"
|
7 |
loizides |
1.1 |
#include "DataFormats/Common/interface/Handle.h"
|
8 |
|
|
#include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
|
9 |
loizides |
1.4 |
#include "MitAna/DataTree/interface/Names.h"
|
10 |
|
|
#include "MitAna/DataTree/interface/GenParticle.h"
|
11 |
loizides |
1.1 |
|
12 |
|
|
using namespace std;
|
13 |
|
|
using namespace edm;
|
14 |
|
|
using namespace mithep;
|
15 |
|
|
|
16 |
|
|
//-------------------------------------------------------------------------------------------------
|
17 |
loizides |
1.7 |
FillGenParts::FillGenParts(const edm::ParameterSet &cfg) :
|
18 |
loizides |
1.6 |
genParticles_(new mithep::Array<mithep::GenParticle>()),
|
19 |
loizides |
1.7 |
mcSource_(cfg.getUntrackedParameter<string>("source", "source")),
|
20 |
|
|
genPartBrn_(cfg.getUntrackedParameter<string>("brname", Names::gkGenPartBrn))
|
21 |
loizides |
1.1 |
{
|
22 |
|
|
}
|
23 |
|
|
|
24 |
|
|
//-------------------------------------------------------------------------------------------------
|
25 |
|
|
FillGenParts::~FillGenParts()
|
26 |
|
|
{
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
//-------------------------------------------------------------------------------------------------
|
30 |
loizides |
1.7 |
void FillGenParts::analyze(const edm::Event &event, const edm::EventSetup &setup)
|
31 |
loizides |
1.1 |
{
|
32 |
|
|
genParticles_->Reset();
|
33 |
|
|
|
34 |
|
|
Handle<HepMCProduct> theMCProduct;
|
35 |
|
|
try {
|
36 |
loizides |
1.7 |
event.getByLabel(mcSource_, theMCProduct);
|
37 |
loizides |
1.1 |
} catch (cms::Exception& ex) {
|
38 |
loizides |
1.4 |
edm::LogError("FillGenParts") << "Error! Can not get collection with label "
|
39 |
|
|
<< mcSource_ << endl;
|
40 |
|
|
throw edm::Exception(edm::errors::Configuration, "FillGenParts::analyze()\n")
|
41 |
|
|
<< "Error! Can not get collection with label " << mcSource_ << endl;
|
42 |
loizides |
1.1 |
}
|
43 |
|
|
|
44 |
|
|
const HepMC::GenEvent GenEvent = theMCProduct->getHepMCData();
|
45 |
|
|
|
46 |
|
|
int nGen = 0;
|
47 |
loizides |
1.4 |
for (HepMC::GenEvent::particle_const_iterator pgen = GenEvent.particles_begin();
|
48 |
loizides |
1.1 |
pgen != GenEvent.particles_end(); ++pgen) {
|
49 |
|
|
|
50 |
|
|
HepMC::GenParticle* mcPart = (*pgen);
|
51 |
|
|
if(!mcPart) continue;
|
52 |
|
|
|
53 |
loizides |
1.4 |
Short_t moind = -1;
|
54 |
|
|
HepMC::GenVertex * momVert = mcPart->production_vertex();
|
55 |
paus |
1.3 |
if (momVert) {
|
56 |
|
|
if (momVert->particles_in_size() == 1) {
|
57 |
loizides |
1.4 |
HepMC::GenVertex::particles_in_const_iterator mom =
|
58 |
|
|
momVert->particles_in_const_begin();
|
59 |
|
|
moind = (*mom)->barcode() - 1;
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
mithep::GenParticle genParticle(mcPart->momentum().x(),mcPart->momentum().y(),
|
64 |
|
|
mcPart->momentum().z(),mcPart->momentum().e(),
|
65 |
|
|
mcPart->pdg_id(),
|
66 |
|
|
mcPart->status(),
|
67 |
|
|
moind);
|
68 |
loizides |
1.6 |
genParticles_->AddCopy(genParticle);
|
69 |
loizides |
1.1 |
nGen++;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
loizides |
1.4 |
genParticles_->Trim();
|
73 |
loizides |
1.1 |
}
|
74 |
|
|
|
75 |
|
|
//-------------------------------------------------------------------------------------------------
|
76 |
loizides |
1.7 |
void FillGenParts::beginJob(const edm::EventSetup &event)
|
77 |
loizides |
1.1 |
{
|
78 |
|
|
Service<TreeService> ts;
|
79 |
|
|
TreeWriter *tws = ts->get();
|
80 |
|
|
if(!tws) {
|
81 |
loizides |
1.4 |
throw edm::Exception(edm::errors::Configuration, "FillGenParts::beginJob()\n")
|
82 |
|
|
<< "Could not get pointer to Tree with name " << tws->GetName() << "\n";
|
83 |
loizides |
1.1 |
return;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
loizides |
1.7 |
tws->AddBranch(genPartBrn_.c_str(), &genParticles_);
|
87 |
loizides |
1.1 |
}
|
88 |
|
|
|
89 |
|
|
//-------------------------------------------------------------------------------------------------
|
90 |
|
|
void FillGenParts::endJob()
|
91 |
|
|
{
|
92 |
|
|
edm::LogInfo("FillGenParts::endJob") << "Ending Job" << endl;
|
93 |
|
|
}
|