Subversion Repositories hepmc

Rev

Rev 43 | Rev 266 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 43 Rev 67
Line 6... Line 6...
6
  • //////////////////////////////////////////////////////////////////////////
  • 6
  • //////////////////////////////////////////////////////////////////////////
  • 7
  • // To Compile: go to the HepMC directory and type:
  • 7
  • // To Compile: go to the HepMC directory and type:
  • 8
  • // gmake examples/example_BuildEventFromScratch.exe
  • 8
  • // gmake examples/example_BuildEventFromScratch.exe
  • 9
  • //
  • 9
  • //
  • 10
  •  
  • 10
  •  
  • -
     
    11
  • #include <iostream>
  • -
     
    12
  •  
  • -
     
    13
  • #include "VectorConversion.h"
  • 11
  • #include "HepMC/GenEvent.h"
  • 14
  • #include "HepMC/GenEvent.h"
  • 12
  • #include "HepMC/ParticleDataTable.h"
  • 15
  • #include "HepMC/ParticleDataTable.h"
  • 13
  • #include "CLHEP/Vector/LorentzVector.h"
  • 16
  • #include "CLHEP/Vector/LorentzVector.h"
  • 14
  •  
  • 17
  •  
  • 15
  • // in this example we use the HepMC namespace, so that we do not have to
  • 18
  • // in this example we use the HepMC namespace, so that we do not have to
  • 16
  • // precede all HepMC classes with HepMC::
  • 19
  • // precede all HepMC classes with HepMC::
  • -
     
    20
  •  
  • -
     
    21
  • // This example also shows how to use the CLHEP Lorentz vector with HepMC2
  • 17
  •  
  • 22
  •  
  • 18
  • using namespace HepMC;
  • 23
  • using namespace HepMC;
  • 19
  • using namespace CLHEP;
  • 24
  • using namespace CLHEP;
  • 20
  •  
  • 25
  •  
  • 21
  • int main() {
  • 26
  • int main() {
  • Line 57... Line 62...
    57
  •     //   /            p6
  • 62
  •     //   /            p6
  • 58
  •     // p2
  • 63
  •     // p2
  • 59
  •     //
  • 64
  •     //
  • 60
  •  
  • 65
  •  
  • 61
  •     // First create the event container, with Signal Process 20, event number 1
  • 66
  •     // First create the event container, with Signal Process 20, event number 1
  • -
     
    67
  •     //
  • -
     
    68
  •     // Note that the HepLorentzVectors will be automatically converted to
  • -
     
    69
  •     // HepMC::FourVector within GenParticle and GenVertex
  • 62
  •     GenEvent* evt = new GenEvent( 20, 1 );
  • 70
  •     GenEvent* evt = new GenEvent( 20, 1 );
  • 63
  •     //
  • 71
  •     //
  • 64
  •     // create vertex 1 and vertex 2, together with their inparticles
  • 72
  •     // create vertex 1 and vertex 2, together with their inparticles
  • 65
  •     GenVertex* v1 = new GenVertex();
  • 73
  •     GenVertex* v1 = new GenVertex();
  • 66
  •     evt->add_vertex( v1 );
  • 74
  •     evt->add_vertex( v1 );
  • Line 90... Line 98...
    90
  •     GenParticle* p5 =
  • 98
  •     GenParticle* p5 =
  • 91
  •         new GenParticle( HepLorentzVector(1.517,-20.68,-20.605,85.925), -24,3);
  • 99
  •         new GenParticle( HepLorentzVector(1.517,-20.68,-20.605,85.925), -24,3);
  • 92
  •     v3->add_particle_out( p5 );
  • 100
  •     v3->add_particle_out( p5 );
  • 93
  •     //
  • 101
  •     //
  • 94
  •     // create v4
  • 102
  •     // create v4
  • 95
  •     GenVertex* v4 = new GenVertex();
  • 103
  •     GenVertex* v4 = new GenVertex(HepLorentzVector(0.12,-0.3,0.05,0.004));
  • 96
  •     evt->add_vertex( v4 );
  • 104
  •     evt->add_vertex( v4 );
  • 97
  •     v4->add_particle_in( p5 );
  • 105
  •     v4->add_particle_in( p5 );
  • 98
  •     v4->add_particle_out(
  • 106
  •     v4->add_particle_out(
  • 99
  •         new GenParticle( HepLorentzVector(-2.445,28.816,6.082,29.552), 1,1 )
  • 107
  •         new GenParticle( HepLorentzVector(-2.445,28.816,6.082,29.552), 1,1 )
  • 100
  •         );
  • 108
  •         );
  • Line 104... Line 112...
    104
  •     //    
  • 112
  •     //    
  • 105
  •     // tell the event which vertex is the signal process vertex
  • 113
  •     // tell the event which vertex is the signal process vertex
  • 106
  •     evt->set_signal_process_vertex( v3 );
  • 114
  •     evt->set_signal_process_vertex( v3 );
  • 107
  •     // the event is complete, we now print it out to the screen
  • 115
  •     // the event is complete, we now print it out to the screen
  • 108
  •     evt->print();
  • 116
  •     evt->print();
  • -
     
    117
  •    
  • -
     
    118
  •     // example conversion back to Lorentz vector
  • -
     
    119
  •     // add all outgoing momenta
  • -
     
    120
  •     std::cout << std::endl;
  • -
     
    121
  •     std::cout << " Add output momenta " << std::endl;
  • -
     
    122
  •     HepLorentzVector sum;
  • -
     
    123
  •     for ( GenEvent::particle_const_iterator p = evt->particles_begin();
  • -
     
    124
  •               p != evt->particles_end(); ++p ){
  • -
     
    125
  •         if( (*p)->status() == 1 ) {
  • -
     
    126
  •             sum += SVtoLV( (*p)->momentum() );
  • -
     
    127
  •             (*p)->print();
  • -
     
    128
  •         }
  • -
     
    129
  •     }
  • -
     
    130
  •     std::cout << "Vector Sum: " << sum << std::endl;
  • 109
  •  
  • 131
  •  
  • 110
  •     // now clean-up by deleteing all objects from memory
  • 132
  •     // now clean-up by deleteing all objects from memory
  • 111
  •     //
  • 133
  •     //
  • 112
  •     // deleting the event deletes all contained vertices, and all particles
  • 134
  •     // deleting the event deletes all contained vertices, and all particles
  • 113
  •     // contained in those vertices
  • 135
  •     // contained in those vertices