1 |
loizides |
1.1 |
// $Id:$
|
2 |
|
|
|
3 |
|
|
#include "MitProd/TreeFiller/interface/FillGenParts.h"
|
4 |
|
|
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
5 |
|
|
#include "FWCore/Framework/interface/ESHandle.h"
|
6 |
|
|
#include "DataFormats/Common/interface/Handle.h"
|
7 |
|
|
#include "FWCore/ServiceRegistry/interface/Service.h"
|
8 |
|
|
|
9 |
|
|
#include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
|
10 |
|
|
#include "MitAna/DataTree/interface/Particle.h"
|
11 |
|
|
|
12 |
|
|
#include "TLorentzVector.h"
|
13 |
|
|
|
14 |
|
|
using namespace std;
|
15 |
|
|
using namespace edm;
|
16 |
|
|
using namespace mithep;
|
17 |
|
|
|
18 |
|
|
//-------------------------------------------------------------------------------------------------
|
19 |
|
|
FillGenParts::FillGenParts(const edm::ParameterSet &iConfig)
|
20 |
|
|
: anaMCSource_(iConfig.getUntrackedParameter<string>("anaMCSource" , "source"))
|
21 |
|
|
{
|
22 |
|
|
genParticles_ = new mithep::Vector<mithep::Particle>();
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
//-------------------------------------------------------------------------------------------------
|
26 |
|
|
FillGenParts::~FillGenParts()
|
27 |
|
|
{
|
28 |
|
|
cout << " Fillgenpars done " <<endl;
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
//-------------------------------------------------------------------------------------------------
|
32 |
|
|
void FillGenParts::analyze(const edm::Event &theEvent,
|
33 |
|
|
const edm::EventSetup &iSetup)
|
34 |
|
|
{
|
35 |
|
|
genParticles_->Reset();
|
36 |
|
|
|
37 |
|
|
Handle<HepMCProduct> theMCProduct;
|
38 |
|
|
try {
|
39 |
|
|
theEvent.getByLabel(anaMCSource_, theMCProduct);
|
40 |
|
|
} catch (cms::Exception& ex) {
|
41 |
|
|
printf("Error! can't get collection with label %s\n",anaMCSource_.c_str());
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
const HepMC::GenEvent GenEvent = theMCProduct->getHepMCData();
|
45 |
|
|
|
46 |
|
|
int nGen = 0;
|
47 |
|
|
for (HepMC::GenEvent::particle_const_iterator pgen =
|
48 |
|
|
GenEvent.particles_begin();
|
49 |
|
|
pgen != GenEvent.particles_end(); ++pgen) {
|
50 |
|
|
|
51 |
|
|
HepMC::GenParticle* mcPart = (*pgen);
|
52 |
|
|
if(!mcPart) continue;
|
53 |
|
|
|
54 |
|
|
mithep::Particle genParticle;
|
55 |
|
|
genParticle.SetPxPyPzE(mcPart->momentum().x(),mcPart->momentum().y(),
|
56 |
|
|
mcPart->momentum().z(),mcPart->momentum().e());
|
57 |
|
|
|
58 |
|
|
//printf("ngen %d\n",nGen);
|
59 |
|
|
#if 0
|
60 |
|
|
genParticle.setPdgID(MCPart->pdg_id());
|
61 |
|
|
genParticle.setBarCode(MCPart->barcode()-1);
|
62 |
|
|
genParticle.setStatus(MCPart->status());
|
63 |
|
|
|
64 |
|
|
HepMC::GenVertex * momVert = MCPart->production_vertex();
|
65 |
|
|
//genParticle.setMother(-1);
|
66 |
|
|
if(momVert) {
|
67 |
|
|
if(momVert->particles_in_size() == 1) {
|
68 |
|
|
HepMC::GenVertex::particles_in_const_iterator mom = momVert->particles_in_const_begin();
|
69 |
|
|
genParticle.setMother((*mom)->barcode() - 1);
|
70 |
|
|
} else {genParticle.setMother(-1);}
|
71 |
|
|
} else {genParticle.setMother(-1);}
|
72 |
|
|
//if(MCPart->mother()) genParticle.setMother(MCPart->mother()->barcode()-1);
|
73 |
|
|
//else genParticle.setMother(-1);
|
74 |
|
|
genParticle.setPtr(nGen);
|
75 |
|
|
#endif
|
76 |
|
|
genParticles_->Add(genParticle);
|
77 |
|
|
nGen++;
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
//genParticles_->resize(nGen);
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
//-------------------------------------------------------------------------------------------------
|
84 |
|
|
void FillGenParts::beginJob(edm::EventSetup const &iEvent)
|
85 |
|
|
{
|
86 |
|
|
Service<TreeService> ts;
|
87 |
|
|
TreeWriter *tws = ts->get();
|
88 |
|
|
if(!tws) {
|
89 |
|
|
//todo error
|
90 |
|
|
return;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
tws->AddBranch("Particles","mithep::Vector<mithep::Particle>",&genParticles_,32000,99);
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
//-------------------------------------------------------------------------------------------------
|
97 |
|
|
void FillGenParts::endJob()
|
98 |
|
|
{
|
99 |
|
|
edm::LogInfo("FillGenParts::endJob") << "Ending Job" << endl;
|
100 |
|
|
}
|