hepmc - Blame information for rev 128

Subversion Repositories:
Rev:
Rev Author Line No. Line
107 garren 1 //////////////////////////////////////////////////////////////////////////
2 // testMass.cc.in
3 //
4 // garren@fnal.gov, March 2006
128 garren 5 // Read events written by example_MyPythia.cc
6 // Select events containing a photon of pT > 25 GeV
7 // Add arbitrary PDF information to one of the good events
8 // Write the selected events and read them back in
107 garren 9 //////////////////////////////////////////////////////////////////////////
10 //
11  
128 garren 12 #include "HepMC/IO_GenEvent.h"
107 garren 13 #include "HepMC/GenEvent.h"
113 garren 14 #include "HepMC/Version.h"
107 garren 15  
16 // define methods and classes used by this test
17 #include "IsGoodEvent.h"
18  
19 void massInfo( const HepMC::GenEvent* );
20  
21 int main() {
22 // read and process the input file
23 {
24 // declare an input strategy to read the data produced with the
25 // example_MyPythia
128 garren 26 HepMC::IO_GenEvent ascii_in("@srcdir@/testIOGenEvent.input",std::ios::in);
27 // declare another IO_GenEvent for output
28 HepMC::IO_GenEvent ascii_out("testMass1.dat",std::ios::out);
107 garren 29 // declare an instance of the event selection predicate
30 IsGoodEvent is_good_event;
113 garren 31 // send version to standard output
32 HepMC::version();
107 garren 33 //........................................EVENT LOOP
34 int icount=0;
35 int num_good_events=0;
36 double x=0., y=0., z=0.;
37 HepMC::GenEvent* evt = ascii_in.read_next_event();
38 while ( evt ) {
39 icount++;
40 if ( icount%50==1 ) std::cout << "Processing Event Number " << icount
41 << " its # " << evt->event_number()
42 << std::endl;
43 if ( is_good_event(evt) ) {
44 if (num_good_events == 0 ) {
45 // add some arbitrary PDF information
46 x = 0.1 * icount;
47 y = 0.13 * icount;
48 z = 0.012 * icount;
49 HepMC::PdfInfo pdf( 11, 12, x, y, z, 0.11, 0.34);
50 evt->set_pdf_info(pdf);
51 }
52 ascii_out << evt;
53 ++num_good_events;
54 }
55  
56 // clean up and get next event
57 delete evt;
58 ascii_in >> evt;
59 }
60 //........................................PRINT RESULT
61 std::cout << num_good_events << " out of " << icount
62 << " processed events passed the cuts. Finished." << std::endl;
63 }
64 // now read the file we just created
65 {
66 // declare an input strategy
128 garren 67 HepMC::IO_GenEvent xin("testMass1.dat",std::ios::in);
68 // declare another IO_GenEvent for output
69 HepMC::IO_GenEvent xout("testMass2.dat",std::ios::out);
107 garren 70 //........................................EVENT LOOP
71 int ixin=0;
72 HepMC::GenEvent* evt = xin.read_next_event();
73 while ( evt ) {
74 ixin++;
75 xout << evt;
76 // look at mass info
77 massInfo(evt);
78  
79 // clean up and get next event
80 delete evt;
81 xin >> evt;
82 }
83 //........................................PRINT RESULT
84 std::cout << ixin
85 << " events in the second pass. Finished." << std::endl;
86 }
87 }
88  
89 void massInfo( const HepMC::GenEvent* e )
90 {
91 double gm, m, d;
92 for ( HepMC::GenEvent::particle_const_iterator p = e->particles_begin(); p != e->particles_end();
93 ++p ) {
94  
95 gm = (*p)->generated_mass();
96 m = (*p)->momentum().m();
97 d = fabs(m-gm);
117 garren 98 if( d > 1.0e-5 ) {
99 std::cout << "Event " << e->event_number()
100 << " Particle " << (*p)->barcode()
101 << " " << (*p)->pdg_id()
102 << " generated mass " << gm
103 << " mass from momentum " << m
104 << " difference " << d << std::endl;
107 garren 105 }
106 }
107 }