File: example_VectorConversion.cc

package info (click to toggle)
hepmc 2.06.09-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 11,524 kB
  • ctags: 1,521
  • sloc: sh: 9,138; cpp: 8,113; ansic: 682; makefile: 240; csh: 6; fortran: 4
file content (126 lines) | stat: -rw-r--r-- 4,964 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//////////////////////////////////////////////////////////////////////////
// Matt.Dobbs@Cern.CH, Feb 2000
// Example of building an event and a particle data table from scratch
// This is meant to be of use for persons implementing HepMC inside a MC 
// event generator
//////////////////////////////////////////////////////////////////////////
// To Compile: go to the HepMC directory and type:
// gmake examples/example_BuildEventFromScratch.exe
//

#include <iostream>

#include "VectorConversion.h"
#include "HepMC/GenEvent.h"
#include "CLHEP/Vector/LorentzVector.h"

// in this example we use the HepMC namespace, so that we do not have to 
// precede all HepMC classes with HepMC::

// This example also shows how to use the CLHEP Lorentz vector with HepMC2

using namespace HepMC;
using namespace CLHEP;

int main() {
    //
    // In this example we will place the following event into HepMC "by hand"
    //
    //     name status pdg_id  parent Px       Py    Pz       Energy      Mass
    //  1  !p+!    3   2212    0,0    0.000    0.000 7000.000 7000.000    0.938
    //  2  !p+!    3   2212    0,0    0.000    0.000-7000.000 7000.000    0.938
    //=========================================================================
    //  3  !d!     3      1    1,1    0.750   -1.569   32.191   32.238    0.000
    //  4  !u~!    3     -2    2,2   -3.047  -19.000  -54.629   57.920    0.000
    //  5  !W-!    3    -24    1,2    1.517   -20.68  -20.605   85.925   80.799
    //  6  !gamma! 1     22    1,2   -3.813    0.113   -1.833    4.233    0.000
    //  7  !d!     1      1    5,5   -2.445   28.816    6.082   29.552    0.010
    //  8  !u~!    1     -2    5,5    3.962  -49.498  -26.687   56.373    0.006

    // now we build the graph, which will look like
    //                       p7                         #
    // p1                   /                           #
    //   \v1__p3      p5---v4                           #
    //         \_v3_/       \                           #
    //         /    \        p8                         #
    //    v2__p4     \                                  #
    //   /            p6                                #
    // p2                                               #
    //                                                  #

    // First create the event container, with Signal Process 20, event number 1
    //
    // Note that the HepLorentzVectors will be automatically converted to 
    // HepMC::FourVector within GenParticle and GenVertex
    GenEvent* evt = new GenEvent( 20, 1 );
    // define the units
    evt->use_units(HepMC::Units::GEV, HepMC::Units::MM);
    //
    // create vertex 1 and vertex 2, together with their inparticles
    GenVertex* v1 = new GenVertex();
    evt->add_vertex( v1 );
    v1->add_particle_in( new GenParticle( HepLorentzVector(0,0,7000,7000),
				       2212, 3 ) );
    GenVertex* v2 = new GenVertex();
    evt->add_vertex( v2 );
    v2->add_particle_in( new GenParticle( HepLorentzVector(0,0,-7000,7000),
				       2212, 3 ) );
    //
    // create the outgoing particles of v1 and v2
    GenParticle* p3 = 
	new GenParticle( HepLorentzVector(.750,-1.569,32.191,32.238), 1, 3 );
    v1->add_particle_out( p3 );
    GenParticle* p4 = 
	new GenParticle( HepLorentzVector(-3.047,-19.,-54.629,57.920), -2, 3 );
    v2->add_particle_out( p4 );
    //
    // create v3
    GenVertex* v3 = new GenVertex();
    evt->add_vertex( v3 );
    v3->add_particle_in( p3 );
    v3->add_particle_in( p4 );
    v3->add_particle_out( 
	new GenParticle( HepLorentzVector(-3.813,0.113,-1.833,4.233 ), 22, 1 )
	);
    GenParticle* p5 = 
	new GenParticle( HepLorentzVector(1.517,-20.68,-20.605,85.925), -24,3);
    v3->add_particle_out( p5 );
    //
    // create v4
    GenVertex* v4 = new GenVertex(HepLorentzVector(0.12,-0.3,0.05,0.004));
    evt->add_vertex( v4 );
    v4->add_particle_in( p5 );
    v4->add_particle_out( 
	new GenParticle( HepLorentzVector(-2.445,28.816,6.082,29.552), 1,1 )
	);
    v4->add_particle_out( 
	new GenParticle( HepLorentzVector(3.962,-49.498,-26.687,56.373), -2,1 )
	);
    //    
    // tell the event which vertex is the signal process vertex
    evt->set_signal_process_vertex( v3 );
    // the event is complete, we now print it out to the screen
    evt->print();
    
    // example conversion back to Lorentz vector
    // add all outgoing momenta
    std::cout << std::endl;
    std::cout << " Add output momenta " << std::endl;
    HepLorentzVector sum;
    for ( GenEvent::particle_const_iterator p = evt->particles_begin(); 
	      p != evt->particles_end(); ++p ){
	if( (*p)->status() == 1 ) {
	    sum += convertTo( (*p)->momentum() );
	    (*p)->print();
	}
    }
    std::cout << "Vector Sum: " << sum << std::endl;

    // now clean-up by deleteing all objects from memory
    //
    // deleting the event deletes all contained vertices, and all particles
    // contained in those vertices
    delete evt;

    return 0;
}