18 #include <HepMC/GenEvent.h>
19 #include <HepMC/GenVertex.h>
20 #include <HepMC/GenParticle.h>
21 #include <HepMC/Polarization.h>
23 #include <ThePEG/StandardModel/StandardModelBase.h>
24 #include <ThePEG/Repository/EventGenerator.h>
25 #include <ThePEG/EventRecord/Particle.h>
26 #include <ThePEG/EventRecord/StandardSelectors.h>
27 #include <ThePEG/EventRecord/Collision.h>
28 #include <ThePEG/EventRecord/Step.h>
29 #include <ThePEG/EventRecord/SubProcess.h>
30 #include <ThePEG/Handlers/XComb.h>
31 #include <ThePEG/Handlers/EventHandler.h>
32 #include <ThePEG/PDF/PartonExtractor.h>
33 #include <ThePEG/PDF/PDF.h>
40 template <
typename HepMCEventT,
typename Traits>
41 typename HepMCConverter<HepMCEventT,Traits>::GenEvent *
48 template <
typename HepMCEventT,
typename Traits>
52 converter(ev, gev, nocopies,
53 Traits::momentumUnit(gev), Traits::lengthUnit(gev));
56 template <
typename HepMCEventT,
typename Traits>
59 Energy eunit, Length lunit) {
63 template <
typename HepMCEventT,
typename Traits>
66 : energyUnit(eunit), lengthUnit(lunit) {
68 geneve = Traits::newEvent(ev.number(), ev.weight(), ev.optionalWeights());
74 template <
typename HepMCEventT,
typename Traits>
77 Energy eunit, Length lunit)
78 : energyUnit(eunit), lengthUnit(lunit) {
88 return a->number() < b->number();
92 template <
typename HepMCEventT,
typename Traits>
95 if ( Traits::hasUnits() ) {
96 if ( lengthUnit != millimeter && lengthUnit != centimeter )
97 throw HepMCConverterException()
98 <<
"Length unit used for HepMC::GenEvent was not MM nor CM."
99 << Exception::runerror;
100 if ( energyUnit !=
GeV && energyUnit !=
MeV )
101 throw HepMCConverterException()
102 <<
"Momentum unit used for HepMC::GenEvent was not GEV nor MEV."
103 << Exception::runerror;
105 if ( lengthUnit != millimeter )
106 throw HepMCConverterException()
107 <<
"Length unit used for HepMC::GenEvent was not MM and the "
108 <<
"HepMCTraits class claims that the used version of HepMC "
109 <<
"cannot handle user-defined units."
110 << Exception::runerror;
111 if ( energyUnit !=
GeV )
112 throw HepMCConverterException()
113 <<
"Momentum unit used for HepMC::GenEvent was not GEV and the "
114 <<
"HepMCTraits class claims that the used version of HepMC "
115 <<
"cannot handle user-defined units."
116 << Exception::runerror;
118 Traits::setUnits(*geneve, energyUnit, lengthUnit);
120 if ( ev.primaryCollision() && ( eh =
121 dynamic_ptr_cast<tcEHPtr>(ev.primaryCollision()->handler()) ) ) {
128 ev.select(back_inserter(all), SelectAll());
129 vertices.reserve(all.size()*2);
130 sortTopologically(all);
133 for (
int i = 0,
N = all.size();
i <
N; ++
i ) {
135 if ( nocopies && p->next() )
continue;
136 if ( pmap.find(p) != pmap.end() )
continue;
138 if ( p->hasColourInfo() ) {
143 if ( l = p->colourLine() ) {
144 if ( !member(flowmap, l) ) flowmap[l] = flowmap.size() + 500;
145 Traits::setColourLine(*gp, 1, flowmap[l]);
147 if ( l = p->antiColourLine() ) {
148 if ( !member(flowmap, l) ) flowmap[l] = flowmap.size() + 500;
149 Traits::setColourLine(*gp, 2, flowmap[l]);
153 if ( !p->children().empty() || p->next() ) {
155 vertices.push_back(
Vertex());
156 decv[
p] = &vertices.back();
157 vertices.back().in.insert(p);
160 if ( !p->parents().empty() || p->previous() ||
161 (p->children().empty() && !p->next()) ) {
165 vertices.push_back(
Vertex());
166 prov[
p] = &vertices.back();
167 vertices.back().out.insert(p);
172 for (
int i = 0, N = all.size();
i <
N; ++
i ) {
175 if ( p->next() )
continue;
176 for (
int i = 0, N = p->children().size();
i <
N; ++
i )
177 join(p, p->children()[
i]->final());
179 while ( pp->parents().empty() && pp->previous() ) pp = pp->previous();
180 for (
int i = 0, N = pp->parents().size();
i <
N; ++
i )
181 join(pp->parents()[
i]->final(),
p);
183 for (
int i = 0, N = p->children().size();
i <
N; ++
i )
184 join(p, p->children()[
i]);
185 if ( p->next() )
join(p, p->next());
186 for (
int i = 0, N = p->parents().size();
i <
N; ++
i )
188 if ( p->previous() )
join(p->previous(),
p);
193 for (
typename VertexMap::iterator it = prov.begin(); it != prov.end(); ++it )
194 if ( !member(vmap, it->second) )
195 vmap[it->second] = createVertex(it->second);
196 for (
typename VertexMap::iterator it = decv.begin(); it != decv.end(); ++it )
197 if ( !member(vmap, it->second) )
198 vmap[it->second] = createVertex(it->second);
201 for (
typename GenVertexMap::iterator it = vmap.begin();
202 it != vmap.end(); ++it )
203 Traits::addVertex(*geneve, it->second);
208 tSubProPtr sub = ev.primarySubProcess();
209 if ( sub && sub->incoming().first ) {
210 const Vertex * prim = decv[sub->incoming().first];
211 Traits::setSignalProcessVertex(*geneve, vmap[prim]);
217 geneve->set_beam_particles(pmap[ev.incoming().first],
218 pmap[ev.incoming().second]);
223 template <
typename HepMCEventT,
typename Traits>
227 if ( !p->children().empty() || p->next() ) {
228 tStepPtr
step = p->birthStep();
229 if ((!step || (step && (!step->handler() || step->handler() == eh))) && p->id() != 82)
235 Traits::newParticle(p->momentum(), p->id(),
status, energyUnit);
237 if ( p->spinInfo() && p->spinInfo()->hasPolarization() ) {
238 DPair pol = p->spinInfo()->polarization();
239 Traits::setPolarization(*gp, pol.first, pol.second);
246 template <
typename HepMCEventT,
typename Traits>
249 Vertex * pro = prov[child];
250 if ( !pro || !dec )
throw HepMCConverterException()
251 <<
"Found a reference to a ThePEG::Particle which was not in the Event."
252 << Exception::eventerror;
253 if ( pro == dec )
return;
254 while ( !pro->
in.empty() ) {
255 dec->
in.insert(*(pro->
in.begin()));
256 decv[*(pro->
in.begin())] = dec;
257 pro->
in.erase(pro->
in.begin());
259 while ( !pro->
out.empty() ) {
260 dec->
out.insert(*(pro->
out.begin()));
261 prov[*(pro->
out.begin())] = dec;
262 pro->
out.erase(pro->
out.begin());
266 template <
typename HepMCEventT,
typename Traits>
269 if ( !v )
throw HepMCConverterException()
270 <<
"Found internal null Vertex." << Exception::abortnow;
279 for ( tcParticleSet::iterator it = v->
in.begin();
280 it != v->
in.end(); ++it ) {
281 p += (**it).labDecayVertex();
282 Traits::addIncoming(*gv, pmap[*it]);
284 for ( tcParticleSet::iterator it = v->
out.begin();
285 it != v->
out.end(); ++it ) {
286 p += (**it).labVertex();
287 Traits::addOutgoing(*gv, pmap[*it]);
290 p /= double(v->
in.size() + v->
out.size());
291 Traits::setPosition(*gv, p, lengthUnit);
296 template <
typename HepMCEventT,
typename Traits>
299 tSubProPtr sub = e.primarySubProcess();
300 int id1 = sub->incoming().first ->id();
301 int id2 = sub->incoming().second->id();
303 tcEHPtr eh = dynamic_ptr_cast<tcEHPtr>(e.handler());
305 double x1 = eh->lastX1();
306 double x2 = eh->lastX2();
309 pdfs.first = eh->pdf<PDF>(sub->incoming().first );
310 pdfs.second = eh->pdf<PDF>(sub->incoming().second);
312 Energy2
scale = eh->lastScale();
314 double xf1 = pdfs.first.xfx(sub->incoming().first->dataPtr(),
scale, x1);
315 double xf2 = pdfs.second.xfx(sub->incoming().second->dataPtr(),
scale, x2);
317 Traits::setPdfInfo(*geneve, id1, id2, x1, x2,
sqrt(scale/GeV2), xf1, xf2);
321 template<
typename HepMCEventT,
typename Traits>
325 std::set<tcPPtr> visited;
326 for(
unsigned int head = 0; head < all.size(); head++) {
328 for(
unsigned int cur = head; cur < all.size(); cur++) {
330 for(tParticleVector::const_iterator
iter =
332 iter != all[cur]->parents().end(); ++
iter) {
333 if (visited.find(*
iter) == visited.end()) {
344 visited.insert(all[head]);
bool operator()(tcPPtr a, tcPPtr b) const
void join(tcPPtr parent, tcPPtr child)
GenParticle * createParticle(tcPPtr p) const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
GenVertex * createVertex(Vertex *v)
static GenEvent * convert(const Event &ev, bool nocopies=false, Energy eunit=Traits::defaultEnergyUnit(), Length lunit=Traits::defaultLengthUnit())
void setPdfInfo(const Event &e)
void sortTopologically(tcPVector &allv)
static std::string join(char **cmd)
void init(const Event &ev, bool nocopies)
Traits::ParticleT GenParticle
Traits::VertexT GenVertex