1 |
loizides |
1.1 |
// $Id: FillerMCVertexes.cc,v 1.17 2009/07/20 03:19:24 loizides Exp $
|
2 |
|
|
|
3 |
|
|
#include "MitProd/TreeFiller/interface/FillerMCVertexes.h"
|
4 |
|
|
#include "MitAna/DataTree/interface/Names.h"
|
5 |
|
|
#include "MitAna/DataTree/interface/VertexCol.h"
|
6 |
|
|
#include "MitProd/ObjectService/interface/ObjectService.h"
|
7 |
|
|
|
8 |
|
|
using namespace std;
|
9 |
|
|
using namespace edm;
|
10 |
|
|
using namespace mithep;
|
11 |
|
|
|
12 |
|
|
//--------------------------------------------------------------------------------------------------
|
13 |
|
|
FillerMCVertexes::FillerMCVertexes(const ParameterSet &cfg, const char *name, bool active) :
|
14 |
|
|
BaseFiller(cfg, name, active),
|
15 |
|
|
useAodGen_(Conf().getUntrackedParameter<bool>("useAodGen",true)),
|
16 |
|
|
edmName_(Conf().getUntrackedParameter<string>("edmName","genParticles")),
|
17 |
|
|
mitName_(Conf().getUntrackedParameter<string>("mitName","MCVertexes")),
|
18 |
|
|
vertexes_(new mithep::VertexArr(1))
|
19 |
|
|
{
|
20 |
|
|
// Constructor.
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
//--------------------------------------------------------------------------------------------------
|
24 |
|
|
FillerMCVertexes::~FillerMCVertexes()
|
25 |
|
|
{
|
26 |
|
|
// Destructor.
|
27 |
|
|
|
28 |
|
|
delete vertexes_;
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
//--------------------------------------------------------------------------------------------------
|
32 |
|
|
void FillerMCVertexes::BookDataBlock(TreeWriter &tws, const edm::EventSetup &es)
|
33 |
|
|
{
|
34 |
|
|
// Add branch to tree.
|
35 |
|
|
|
36 |
|
|
tws.AddBranch(mitName_,&vertexes_);
|
37 |
|
|
OS()->add<VertexArr>(vertexes_,mitName_);
|
38 |
|
|
}
|
39 |
|
|
|
40 |
|
|
//--------------------------------------------------------------------------------------------------
|
41 |
|
|
void FillerMCVertexes::FillDataBlock(const edm::Event &event,
|
42 |
|
|
const edm::EventSetup &setup)
|
43 |
|
|
{
|
44 |
|
|
// Loop over generated or simulated particles and fill their information.
|
45 |
|
|
|
46 |
|
|
vertexes_->Delete();
|
47 |
|
|
|
48 |
|
|
Double_t vtx=0, vty=0, vtz=0;
|
49 |
|
|
|
50 |
|
|
if (!useAodGen_) {
|
51 |
|
|
Handle<edm::HepMCProduct> hHepMCProduct;
|
52 |
|
|
GetProduct(edmName_, hHepMCProduct, event);
|
53 |
|
|
const HepMC::GenEvent &GenEvent = hHepMCProduct->getHepMCData();
|
54 |
|
|
|
55 |
|
|
for (HepMC::GenEvent::particle_const_iterator pgen = GenEvent.particles_begin();
|
56 |
|
|
pgen != GenEvent.particles_end(); ++pgen) {
|
57 |
|
|
HepMC::GenParticle *mcPart = (*pgen);
|
58 |
|
|
if(!mcPart)
|
59 |
|
|
continue;
|
60 |
|
|
HepMC::GenVertex *dvtx = mcPart->end_vertex();
|
61 |
|
|
if (dvtx) {
|
62 |
|
|
vtx = dvtx->point3d().x()/10.0;
|
63 |
|
|
vty = dvtx->point3d().y()/10.0;
|
64 |
|
|
vtz = dvtx->point3d().z()/10.0;
|
65 |
|
|
break;
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
} else { /*useAodGen_*/
|
69 |
|
|
Handle<reco::GenParticleCollection> hGenPProduct;
|
70 |
|
|
GetProduct(edmName_, hGenPProduct, event);
|
71 |
|
|
const reco::GenParticleCollection genParticles = *(hGenPProduct.product());
|
72 |
|
|
for (reco::GenParticleCollection::const_iterator pgen = genParticles.begin();
|
73 |
|
|
pgen != genParticles.end(); ++pgen) {
|
74 |
|
|
|
75 |
|
|
int found = 0;
|
76 |
|
|
for (unsigned int i=0; i<pgen->numberOfDaughters(); ++i) {
|
77 |
|
|
const reco::Candidate *dau = pgen->daughter(i);
|
78 |
|
|
if (dau) {
|
79 |
|
|
vtx = dau->vx();
|
80 |
|
|
vty = dau->vy();
|
81 |
|
|
vtz = dau->vz();
|
82 |
|
|
found = 1;
|
83 |
|
|
break;
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
if (found)
|
87 |
|
|
break;
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
mithep::Vertex *newvtx = vertexes_->Allocate();
|
92 |
|
|
new (newvtx) mithep::Vertex(vtx, vty, vtz);
|
93 |
|
|
vertexes_->Trim();
|
94 |
|
|
}
|