1 |
loizides |
1.2 |
// $Id: FillerMCParticles.cc,v 1.1 2008/07/25 11:33:58 bendavid Exp $
|
2 |
bendavid |
1.1 |
|
3 |
|
|
#include "MitProd/TreeFiller/interface/FillerMCParticles.h"
|
4 |
|
|
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
5 |
|
|
#include "DataFormats/Common/interface/Handle.h"
|
6 |
|
|
#include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
|
7 |
|
|
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
|
8 |
|
|
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
|
9 |
|
|
#include "SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h"
|
10 |
|
|
#include "SimDataFormats/TrackingAnalysis/interface/TrackingVertexContainer.h"
|
11 |
|
|
#include "MitAna/DataTree/interface/Names.h"
|
12 |
|
|
|
13 |
|
|
using namespace std;
|
14 |
|
|
using namespace edm;
|
15 |
|
|
using namespace mithep;
|
16 |
|
|
|
17 |
|
|
//--------------------------------------------------------------------------------------------------
|
18 |
|
|
FillerMCParticles::FillerMCParticles(const ParameterSet &cfg, const char *name, bool active) :
|
19 |
|
|
BaseFiller(cfg, name, active),
|
20 |
|
|
genActive_(Conf().getUntrackedParameter<bool>("genActive",true)),
|
21 |
|
|
simActive_(Conf().getUntrackedParameter<bool>("simActive",true)),
|
22 |
|
|
genEdmName_(Conf().getUntrackedParameter<string>("genEdmName","source")),
|
23 |
|
|
simEdmName_(Conf().getUntrackedParameter<string>("simEdmName","mergedtruth:MergedTrackTruth")),
|
24 |
|
|
mitName_(Conf().getUntrackedParameter<string>("mitName",Names::gkMCPartBrn)),
|
25 |
|
|
mcParticles_(new mithep::MCParticleArr(250)),
|
26 |
|
|
genMap_(new mithep::GenParticleMap),
|
27 |
|
|
simMap_(new mithep::SimParticleMap)
|
28 |
|
|
{
|
29 |
|
|
// Constructor.
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
//--------------------------------------------------------------------------------------------------
|
33 |
|
|
FillerMCParticles::~FillerMCParticles()
|
34 |
|
|
{
|
35 |
|
|
// Destructor.
|
36 |
|
|
|
37 |
|
|
delete mcParticles_;
|
38 |
|
|
delete genMap_;
|
39 |
|
|
delete simMap_;
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
//--------------------------------------------------------------------------------------------------
|
43 |
|
|
void FillerMCParticles::BookDataBlock(TreeWriter &tws)
|
44 |
|
|
{
|
45 |
|
|
// Add branch to tree.
|
46 |
|
|
|
47 |
|
|
tws.AddBranch(mitName_.c_str(),&mcParticles_);
|
48 |
loizides |
1.2 |
|
49 |
|
|
// publish our maps
|
50 |
|
|
OS()->add(genMap_,"GenMap");
|
51 |
|
|
OS()->add(simMap_,"SimMap");
|
52 |
bendavid |
1.1 |
}
|
53 |
|
|
|
54 |
|
|
//--------------------------------------------------------------------------------------------------
|
55 |
|
|
void FillerMCParticles::FillDataBlock(const edm::Event &event,
|
56 |
loizides |
1.2 |
const edm::EventSetup &setup)
|
57 |
bendavid |
1.1 |
{
|
58 |
|
|
// Loop over HepMC particle and fill their information.
|
59 |
|
|
|
60 |
|
|
genMap_->Reset();
|
61 |
|
|
simMap_->Reset();
|
62 |
|
|
mcParticles_->Reset();
|
63 |
|
|
|
64 |
|
|
if (genActive_) {
|
65 |
|
|
|
66 |
|
|
Handle<edm::HepMCProduct> hHepMCProduct;
|
67 |
|
|
GetProduct(genEdmName_, hHepMCProduct, event);
|
68 |
|
|
|
69 |
|
|
const HepMC::GenEvent &GenEvent = hHepMCProduct->getHepMCData();
|
70 |
|
|
|
71 |
|
|
//loop over all hepmc particles and copy their information
|
72 |
|
|
for (HepMC::GenEvent::particle_const_iterator pgen = GenEvent.particles_begin();
|
73 |
|
|
pgen != GenEvent.particles_end(); ++pgen) {
|
74 |
|
|
|
75 |
|
|
HepMC::GenParticle *mcPart = (*pgen);
|
76 |
|
|
if(!mcPart) continue;
|
77 |
|
|
|
78 |
|
|
mithep::MCParticle *genParticle = mcParticles_->Allocate();
|
79 |
|
|
new (genParticle) mithep::MCParticle(mcPart->momentum().x(),mcPart->momentum().y(),
|
80 |
|
|
mcPart->momentum().z(),mcPart->momentum().e(),
|
81 |
|
|
mcPart->pdg_id(),
|
82 |
|
|
mcPart->status());
|
83 |
|
|
|
84 |
|
|
genParticle->SetIsGenerated();
|
85 |
|
|
|
86 |
|
|
genMap_->Add(mcPart->barcode(), genParticle);
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
if (simActive_) {
|
92 |
|
|
|
93 |
|
|
Handle<TrackingParticleCollection> hTrackingParticleProduct;
|
94 |
|
|
GetProduct(simEdmName_, hTrackingParticleProduct, event);
|
95 |
|
|
|
96 |
|
|
const TrackingParticleCollection trackingParticles = *(hTrackingParticleProduct.product());
|
97 |
|
|
|
98 |
|
|
// loop through all simParticles
|
99 |
|
|
for (TrackingParticleCollection::const_iterator iM = trackingParticles.begin();
|
100 |
|
|
iM != trackingParticles.end(); ++iM) {
|
101 |
|
|
|
102 |
|
|
TrackingParticleRef theRef(hTrackingParticleProduct, iM-trackingParticles.begin());
|
103 |
|
|
mithep::MCParticle *outSimParticle;
|
104 |
|
|
|
105 |
|
|
if (genActive_ && iM->genParticle().size()) {
|
106 |
|
|
const HepMC::GenParticle *mcPart = iM->genParticle_begin()->get();
|
107 |
|
|
outSimParticle=genMap_->GetMit(mcPart->barcode());
|
108 |
|
|
outSimParticle->SetStatus(iM->status());
|
109 |
|
|
}
|
110 |
|
|
else {
|
111 |
|
|
outSimParticle = mcParticles_->Allocate();
|
112 |
|
|
new (outSimParticle) mithep::MCParticle(iM->px(),iM->py(),iM->pz(),iM->energy(),iM->pdgId(), iM->status());
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
outSimParticle->SetIsSimulated();
|
116 |
|
|
simMap_->Add(theRef, outSimParticle);
|
117 |
|
|
}
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
mcParticles_->Trim();
|
121 |
|
|
}
|
122 |
|
|
|
123 |
|
|
//--------------------------------------------------------------------------------------------------
|
124 |
|
|
void FillerMCParticles::ResolveLinks(const edm::Event &event,
|
125 |
loizides |
1.2 |
const edm::EventSetup &setup)
|
126 |
bendavid |
1.1 |
{
|
127 |
|
|
// Loop over HepMC particle and resolve their links.
|
128 |
|
|
|
129 |
|
|
if (genActive_) {
|
130 |
|
|
|
131 |
|
|
Handle<edm::HepMCProduct> hHepMCProduct;
|
132 |
|
|
GetProduct(genEdmName_, hHepMCProduct, event);
|
133 |
|
|
|
134 |
|
|
const HepMC::GenEvent &GenEvent = hHepMCProduct->getHepMCData();
|
135 |
|
|
|
136 |
|
|
for (HepMC::GenEvent::particle_const_iterator pgen = GenEvent.particles_begin();
|
137 |
|
|
pgen != GenEvent.particles_end(); ++pgen) {
|
138 |
|
|
|
139 |
|
|
HepMC::GenParticle *mcPart = (*pgen);
|
140 |
|
|
if(!mcPart) continue;
|
141 |
|
|
|
142 |
|
|
//check if genpart has a decay vertex
|
143 |
|
|
HepMC::GenVertex *dVertex = mcPart->end_vertex();
|
144 |
|
|
if (!dVertex) continue;
|
145 |
|
|
|
146 |
|
|
//find corresponding mithep genparticle parent in association table
|
147 |
|
|
mithep::MCParticle *genParent = genMap_->GetMit(mcPart->barcode());
|
148 |
|
|
|
149 |
|
|
if (genParent->IsSimulated()) continue;
|
150 |
|
|
|
151 |
|
|
//set decay vertex
|
152 |
|
|
//division by 10.0 is needed due to HepMC use of mm instead of cm for distance units
|
153 |
|
|
genParent->SetVertex(dVertex->point3d().x()/10.0,
|
154 |
|
|
dVertex->point3d().y()/10.0,
|
155 |
|
|
dVertex->point3d().z()/10.0);
|
156 |
|
|
|
157 |
|
|
//loop through daugthers
|
158 |
|
|
for (HepMC::GenVertex::particles_out_const_iterator pgenD = dVertex->particles_out_const_begin();
|
159 |
|
|
pgenD != dVertex->particles_out_const_end(); ++pgenD) {
|
160 |
|
|
HepMC::GenParticle *mcDaughter = (*pgenD);
|
161 |
|
|
mithep::MCParticle *genDaughter = genMap_->GetMit(mcDaughter->barcode());
|
162 |
|
|
genParent->AddDaughter(genDaughter);
|
163 |
|
|
if (!(genDaughter->HasMother()))
|
164 |
|
|
genDaughter->SetMother(genParent);
|
165 |
|
|
}
|
166 |
|
|
}
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
if (simActive_) {
|
170 |
loizides |
1.2 |
|
171 |
bendavid |
1.1 |
Handle<TrackingParticleCollection> hTrackingParticleProduct;
|
172 |
|
|
GetProduct(simEdmName_, hTrackingParticleProduct, event);
|
173 |
|
|
|
174 |
|
|
const TrackingParticleCollection trackingParticles = *(hTrackingParticleProduct.product());
|
175 |
|
|
|
176 |
|
|
// loop through all simParticles
|
177 |
|
|
for (TrackingParticleCollection::const_iterator iM = trackingParticles.begin();
|
178 |
|
|
iM != trackingParticles.end(); ++iM) {
|
179 |
|
|
|
180 |
|
|
if (iM->decayVertices().size() <= 0)
|
181 |
|
|
continue;
|
182 |
|
|
|
183 |
|
|
TrackingParticleRef theRef(hTrackingParticleProduct, iM-trackingParticles.begin());
|
184 |
|
|
mithep::MCParticle *simParent = simMap_->GetMit(theRef);
|
185 |
|
|
for (TrackingVertexRefVector::iterator v= iM->decayVertices().begin();
|
186 |
|
|
v != iM->decayVertices().end(); ++v) {
|
187 |
|
|
for (TrackingParticleRefVector::iterator pd = v->get()->daughterTracks().begin();
|
188 |
|
|
pd != v->get()->daughterTracks().end(); ++pd) {
|
189 |
|
|
mithep::MCParticle *simDaughter = simMap_->GetMit(*pd);
|
190 |
|
|
simParent->AddDaughter(simDaughter);
|
191 |
|
|
simDaughter->SetMother(simParent);
|
192 |
|
|
}
|
193 |
|
|
if (v == iM->decayVertices().end()-1) {
|
194 |
|
|
simParent->SetVertex(v->get()->position().x(),
|
195 |
|
|
v->get()->position().y(),
|
196 |
|
|
v->get()->position().z());
|
197 |
|
|
}
|
198 |
|
|
}
|
199 |
|
|
}
|
200 |
|
|
}
|
201 |
|
|
}
|