| /branches/HEPMC_02_04_branch/test/testFlow.cc |
New file
| @@ -0,0 +1,191 @@ |
| ////////////////////////////////////////////////////////////////////////// |
| // testFlow.cc |
| // |
| // garren@fnal.gov, June 2009 |
| // based on example_BuildEventFromScratch.cc |
| ////////////////////////////////////////////////////////////////////////// |
| |
| #include <iostream> |
| #include <fstream> |
| #include <vector> |
| |
| #include "HepMC/GenEvent.h" |
| #include "HepMC/IO_GenEvent.h" |
| |
| typedef std::vector<HepMC::GenParticle*> FlowVec; |
| |
| 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 |
| |
| // open an output file |
| const char outfile[] = "testFlow.out"; |
| std::ofstream os( outfile ); |
| if( !os ) { |
| std::cerr << "cannot open " << outfile << std::endl; |
| exit(-1); |
| } |
| // declare several IO_GenEvent instances for comparison |
| HepMC::IO_GenEvent xout1("testFlow.out1",std::ios::out); |
| HepMC::IO_GenEvent xout2("testFlow.out2",std::ios::out); |
| HepMC::IO_GenEvent xout3("testFlow.out3",std::ios::out); |
| |
| int numbad = 0; |
| |
| |
| // build the graph, which will look like |
| // p7 # |
| // p1 / # |
| // \v1__p3 p5---v4 # |
| // \_v3_/ \ # |
| // / \ p8 # |
| // v2__p4 \ # |
| // / p6 # |
| // p2 # |
| // |
| // define a flow pattern as p1 -> p3 -> p6 |
| // and p2 -> p4 -> p5 |
| // |
| |
| // First create the event container, with Signal Process 20, event number 1 |
| // |
| HepMC::GenEvent* evt = new HepMC::GenEvent( 20, 1 ); |
| // |
| // create vertex 1 and vertex 2, together with their inparticles |
| HepMC::GenVertex* v1 = new HepMC::GenVertex(); |
| evt->add_vertex( v1 ); |
| HepMC::GenParticle* p1 = new HepMC::GenParticle( HepMC::FourVector(0,0,7000,7000), |
| 2212, 3 ); |
| p1->set_flow(1,231); |
| v1->add_particle_in( p1 ); |
| HepMC::GenVertex* v2 = new HepMC::GenVertex(); |
| evt->add_vertex( v2 ); |
| HepMC::GenParticle* p2 = new HepMC::GenParticle( HepMC::FourVector(0,0,-7000,7000), |
| 2212, 3 ); |
| p2->set_flow(1,243); |
| v2->add_particle_in( p2 ); |
| // |
| // create the outgoing particles of v1 and v2 |
| HepMC::GenParticle* p3 = |
| new HepMC::GenParticle( HepMC::FourVector(.750,-1.569,32.191,32.238), |
| 1, 3 ); |
| p3->set_flow(1,231); |
| v1->add_particle_out( p3 ); |
| HepMC::GenParticle* p4 = |
| new HepMC::GenParticle( HepMC::FourVector(-3.047,-19.,-54.629,57.920), |
| -2, 3 ); |
| p4->set_flow(1,243); |
| v2->add_particle_out( p4 ); |
| // |
| // create v3 |
| HepMC::GenVertex* v3 = new HepMC::GenVertex(); |
| evt->add_vertex( v3 ); |
| v3->add_particle_in( p3 ); |
| v3->add_particle_in( p4 ); |
| HepMC::GenParticle* p6 = |
| new HepMC::GenParticle( HepMC::FourVector(-3.813,0.113,-1.833,4.233 ), |
| 22, 1 ); |
| p6->set_flow(1,231); |
| v3->add_particle_out( p6 ); |
| HepMC::GenParticle* p5 = |
| new HepMC::GenParticle( HepMC::FourVector(1.517,-20.68,-20.605,85.925), |
| -24, 3 ); |
| p5->set_flow(1,243); |
| v3->add_particle_out( p5 ); |
| // |
| // create v4 |
| HepMC::GenVertex* v4 = new HepMC::GenVertex(HepMC::FourVector(0.12,-0.3,0.05,0.004)); |
| evt->add_vertex( v4 ); |
| v4->add_particle_in( p5 ); |
| HepMC::GenParticle* p7 = new HepMC::GenParticle( HepMC::FourVector(-2.445,28.816,6.082,29.552), 1,1 ); |
| v4->add_particle_out( p7 ); |
| HepMC::GenParticle* p8 = new HepMC::GenParticle( HepMC::FourVector(3.962,-49.498,-26.687,56.373), -2,1 ); |
| v4->add_particle_out( p8 ); |
| // |
| // 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 |
| evt->print( os ); |
| |
| // look at the flow we created |
| os << std::endl; |
| FlowVec result1 = p1->flow().dangling_connected_partners( p1->flow().icode(1) ); |
| FlowVec result2 = p1->flow().connected_partners( p1->flow().icode(1) ); |
| FlowVec::iterator it; |
| os << "dangling partners of particle " << p1->barcode() << std::endl; |
| for( it = result1.begin(); it != result1.end(); ++it ) { |
| os << (*it)->barcode() << " " ; |
| os.width(8); |
| os << (*it)->pdg_id() << " " << (*it)->flow(1) << std::endl; |
| } |
| os << "all partners of particle " << p1->barcode() << std::endl; |
| for( it = result2.begin(); it != result2.end(); ++it ) { |
| os << (*it)->barcode() << " " ; |
| os.width(8); |
| os << (*it)->pdg_id() << " " << (*it)->flow(1) << std::endl; |
| } |
| FlowVec result3 = p2->flow().dangling_connected_partners( p2->flow().icode(1) ); |
| FlowVec result4 = p2->flow().connected_partners( p2->flow().icode(1) ); |
| os << "dangling partners of particle " << p2->barcode() << std::endl; |
| for( it = result3.begin(); it != result3.end(); ++it ) { |
| os << (*it)->barcode() << " " ; |
| os.width(8); |
| os << (*it)->pdg_id() << " " << (*it)->flow(1) << std::endl; |
| } |
| os << "all partners of particle " << p2->barcode() << std::endl; |
| for( it = result4.begin(); it != result4.end(); ++it ) { |
| os << (*it)->barcode() << " " ; |
| os.width(8); |
| os << (*it)->pdg_id() << " " << (*it)->flow(1) << std::endl; |
| } |
| xout1 << evt; |
| |
| // try changing and erasing flow |
| p2->set_flow(2,345); |
| xout2 << evt; |
| FlowVec result5 = p2->flow().connected_partners( p2->flow().icode(1) ); |
| if ( result4 != result5 ) { |
| std::cerr << "ERROR: list of partners has changed after adding flow" << std::endl; |
| ++numbad; |
| } |
| // the flow method returns a copy, |
| // so we must set the flow again to change it |
| HepMC::Flow f2 = p2->flow(); |
| if( f2.erase(2) ) { |
| p2->set_flow( f2 ); |
| } else { |
| std::cerr << "ERROR: first erase was NOT successful" << std::endl; |
| ++numbad; |
| } |
| f2 = p2->flow(); |
| if( f2.erase(2) ) { |
| std::cerr << "ERROR: second erase was successful" << std::endl; |
| } |
| xout3 << evt; |
| FlowVec result6 = p2->flow().connected_partners( p2->flow().icode(1) ); |
| if ( result4 != result6 ) { |
| std::cerr << "ERROR: list of partners has changed after removing flow" << std::endl; |
| ++numbad; |
| } |
| |
| // 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; |
| |
| if( numbad > 0 ) std::cerr << numbad << " errors in testFlow" << std::endl; |
| |
| return numbad; |
| } |
| /branches/HEPMC_02_04_branch/test/testFlow.output |
New file
| @@ -0,0 +1,42 @@ |
| ________________________________________________________________________________ |
| GenEvent: #1 ID=20 SignalProcessGenVertex Barcode: -3 |
| Momenutm units: GEV Position units: MM |
| Entries this event: 4 vertices, 8 particles. |
| Beam Particles are not defined. |
| RndmState(0)= |
| Wgts(0)= |
| EventScale -1 [energy] alphaQCD=-1 alphaQED=-1 |
| GenParticle Legend |
| Barcode PDG ID ( Px, Py, Pz, E ) Stat DecayVtx |
| ________________________________________________________________________________ |
| GenVertex: -1 ID: 0 (X,cT):0 |
| I: 1 10001 2212 +0.00e+00,+0.00e+00,+7.00e+03,+7.00e+03 3 -1 |
| O: 1 10003 1 +7.50e-01,-1.57e+00,+3.22e+01,+3.22e+01 3 -3 |
| GenVertex: -2 ID: 0 (X,cT):0 |
| I: 1 10002 2212 +0.00e+00,+0.00e+00,-7.00e+03,+7.00e+03 3 -2 |
| O: 1 10004 -2 -3.05e+00,-1.90e+01,-5.46e+01,+5.79e+01 3 -3 |
| GenVertex: -3 ID: 0 (X,cT):0 |
| I: 2 10003 1 +7.50e-01,-1.57e+00,+3.22e+01,+3.22e+01 3 -3 |
| 10004 -2 -3.05e+00,-1.90e+01,-5.46e+01,+5.79e+01 3 -3 |
| O: 2 10005 22 -3.81e+00,+1.13e-01,-1.83e+00,+4.23e+00 1 |
| 10006 -24 +1.52e+00,-2.07e+01,-2.06e+01,+8.59e+01 3 -4 |
| Vertex: -4 ID: 0 (X,cT)=+1.20e-01,-3.00e-01,+5.00e-02,+4.00e-03 |
| I: 1 10006 -24 +1.52e+00,-2.07e+01,-2.06e+01,+8.59e+01 3 -4 |
| O: 2 10007 1 -2.44e+00,+2.88e+01,+6.08e+00,+2.96e+01 1 |
| 10008 -2 +3.96e+00,-4.95e+01,-2.67e+01,+5.64e+01 1 |
| ________________________________________________________________________________ |
| |
| dangling partners of particle 10001 |
| 10005 22 231 |
| 10001 2212 231 |
| all partners of particle 10001 |
| 10001 2212 231 |
| 10003 1 231 |
| 10005 22 231 |
| dangling partners of particle 10002 |
| 10006 -24 243 |
| 10002 2212 243 |
| all partners of particle 10002 |
| 10002 2212 243 |
| 10004 -2 243 |
| 10006 -24 243 |
| /branches/HEPMC_02_04_branch/test/Makefile.am |
| @@ -7,14 +7,14 @@ |
| # Identify executables needed during testing: |
| check_PROGRAMS = testSimpleVector testUnits testPrintBug \ |
| testHepMC testHepMCIteration testMass \ |
| testMultipleCopies testDeprecated |
| testMultipleCopies testDeprecated testFlow |
| |
| check_SCRIPTS = testHepMC.sh testHepMCIteration.sh testPrintBug.sh \ |
| testMass.sh testDeprecated.sh |
| testMass.sh testDeprecated.sh testFlow.sh |
| |
| # Identify test(s) to run when 'make check' is requested: |
| TESTS = testSimpleVector testUnits \ |
| testHepMC.sh testHepMCIteration.sh testMass.sh \ |
| testHepMC.sh testHepMCIteration.sh testMass.sh testFlow.sh \ |
| testPrintBug.sh testMultipleCopies testDeprecated.sh |
| |
| # Identify the test(s) for which failure is the intended outcome: |
| @@ -23,6 +23,7 @@ |
| # Identify the dependencies on a per-test basis: |
| testSimpleVector_SOURCES = testSimpleVector.cc |
| testUnits_SOURCES = testUnits.cc |
| testFlow_SOURCES = testFlow.cc |
| testHepMC_SOURCES = testHepMC.cc |
| testMass_SOURCES = testMass.cc |
| testHepMCIteration_SOURCES = testHepMCIteration.cc |
| @@ -34,7 +35,7 @@ |
| EXTRA_DIST = testHepMC.input testHepMC.output testHepMCParticle.output \ |
| testPrintBug.output \ |
| testHepMCIteration.output \ |
| testAscii.input testAscii.dat |
| testAscii.input testAscii.dat testFlow.output |
| |
| # Identify generated file(s) to be removed when 'make clean' is requested: |
| CLEANFILES = testHepMC.out testHepMCParticle.out \ |
| @@ -44,4 +45,5 @@ |
| testDeprecated.cout testHepMC.cout testHepMCIteration.cout \ |
| testMultipleCopies.out testHepMCVarious.out testIOAscii.dat \ |
| testMultipleCopies1.dat testMultipleCopies2.dat \ |
| testMultipleOriginals.dat testUnits.out |
| testMultipleOriginals.dat testUnits.out \ |
| testFlow.out testFlow.out1 testFlow.out2 testFlow.out3 |
| /branches/HEPMC_02_04_branch/test/VCMakefile.in |
| @@ -19,10 +19,10 @@ |
| check_PROGRAMS = testSimpleVector$(EXEEXT) testUnits$(EXEEXT) \ |
| testPrintBug$(EXEEXT) testHepMC$(EXEEXT) \ |
| testHepMCIteration$(EXEEXT) testMass$(EXEEXT) \ |
| testMultipleCopies$(EXEEXT) testDeprecated$(EXEEXT) |
| testMultipleCopies$(EXEEXT) testDeprecated$(EXEEXT) testFlow$(EXEEXT) |
| TESTS = testSimpleVector$(EXEEXT) testUnits$(EXEEXT) testHepMC.sh \ |
| testHepMCIteration.sh testMass.sh testPrintBug.sh \ |
| testMultipleCopies$(EXEEXT) testDeprecated.sh |
| testMultipleCopies$(EXEEXT) testDeprecated.sh testFlow.sh |
| XFAIL_TESTS = |
| subdir = test |
| DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \ |
| @@ -31,7 +31,7 @@ |
| $(srcdir)/testHepMCIteration.cc.in \ |
| $(srcdir)/testHepMCIteration.sh.in $(srcdir)/testMass.cc.in \ |
| $(srcdir)/testMass.sh.in $(srcdir)/testMultipleCopies.cc.in \ |
| $(srcdir)/testPrintBug.sh.in |
| $(srcdir)/testPrintBug.sh.in $(srcdir)/testFlow.sh.in |
| |
| ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 |
| am__aclocal_m4_deps = $(top_srcdir)/configure.ac |
| @@ -41,7 +41,7 @@ |
| CONFIG_CLEAN_FILES = testHepMC.cc testMass.cc testHepMCIteration.cc \ |
| testMultipleCopies.cc testDeprecated.cc testHepMC.sh \ |
| testMass.sh testHepMCIteration.sh testPrintBug.sh \ |
| testDeprecated.sh |
| testDeprecated.sh testFlow.sh |
| am_testDeprecated_OBJECTS = testDeprecated.$(OBJEXT) |
| testDeprecated_OBJECTS = $(am_testDeprecated_OBJECTS) |
| testDeprecated_DEPENDENCIES = $(top_builddir)/src/HepMC.lib |
| @@ -51,6 +51,9 @@ |
| am_testHepMCIteration_OBJECTS = testHepMCIteration.$(OBJEXT) |
| testHepMCIteration_OBJECTS = $(am_testHepMCIteration_OBJECTS) |
| testHepMCIteration_DEPENDENCIES = $(top_builddir)/src/HepMC.lib |
| am_testFlow_OBJECTS = testFlow.$(OBJEXT) |
| testFlow_OBJECTS = $(am_testFlow_OBJECTS) |
| testFlow_DEPENDENCIES = $(top_builddir)/src/HepMC.lib |
| am_testMass_OBJECTS = testMass.$(OBJEXT) |
| testMass_OBJECTS = $(am_testMass_OBJECTS) |
| testMass_DEPENDENCIES = $(top_builddir)/src/HepMC.lib |
| @@ -76,11 +79,13 @@ |
| SOURCES = $(testDeprecated_SOURCES) $(testHepMC_SOURCES) \ |
| $(testHepMCIteration_SOURCES) $(testMass_SOURCES) \ |
| $(testMultipleCopies_SOURCES) $(testPrintBug_SOURCES) \ |
| $(testSimpleVector_SOURCES) $(testUnits_SOURCES) |
| $(testSimpleVector_SOURCES) $(testUnits_SOURCES) \ |
| $(testFlow_SOURCES) |
| DIST_SOURCES = $(testDeprecated_SOURCES) $(testHepMC_SOURCES) \ |
| $(testHepMCIteration_SOURCES) $(testMass_SOURCES) \ |
| $(testMultipleCopies_SOURCES) $(testPrintBug_SOURCES) \ |
| $(testSimpleVector_SOURCES) $(testUnits_SOURCES) |
| $(testSimpleVector_SOURCES) $(testUnits_SOURCES) \ |
| $(testFlow_SOURCES) |
| ETAGS = etags |
| CTAGS = ctags |
| DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(EXTRA_DIST) |
| @@ -149,13 +154,14 @@ |
| # how to specify output file |
| OUTFLAG = /Fo$@ |
| check_SCRIPTS = testHepMC.sh testHepMCIteration.sh testPrintBug.sh \ |
| testMass.sh testDeprecated.sh |
| testMass.sh testDeprecated.sh testFlow.sh |
| |
| |
| # Identify the dependencies on a per-test basis: |
| testSimpleVector_SOURCES = testSimpleVector.cc |
| testUnits_SOURCES = testUnits.cc |
| testHepMC_SOURCES = testHepMC.cc |
| testFlow_SOURCES = testFlow.cc |
| testMass_SOURCES = testMass.cc |
| testHepMCIteration_SOURCES = testHepMCIteration.cc |
| testMultipleCopies_SOURCES = testMultipleCopies.cc |
| @@ -166,6 +172,7 @@ |
| testSimpleVector_LDADD = $(top_builddir)/src/HepMC.lib |
| testUnits_LDADD = $(top_builddir)/src/HepMC.lib |
| testHepMC_LDADD = $(top_builddir)/src/HepMC.lib |
| testFlow_LDADD = $(top_builddir)/src/HepMC.lib |
| testMass_LDADD = $(top_builddir)/src/HepMC.lib |
| testHepMCIteration_LDADD = $(top_builddir)/src/HepMC.lib |
| testMultipleCopies_LDADD = $(top_builddir)/src/HepMC.lib |
| @@ -183,7 +190,7 @@ |
| EXTRA_DIST = testHepMC.input testHepMC.output testHepMCParticle.output \ |
| testPrintBug.output testHepMCExtended.dat \ |
| testHepMCIteration.output testHepMCIterationExtended.output \ |
| testAscii.input testAscii.dat |
| testAscii.input testAscii.dat testFlow.output |
| |
| |
| # Identify generated file(s) to be removed when 'make clean' is requested: |
| @@ -195,6 +202,7 @@ |
| testMultipleCopies.out testHepMCVarious.out testIOAscii.dat \ |
| testMultipleCopies1.dat testMultipleCopies2.dat \ |
| testMultipleOriginals.dat testIOHepMCExtended.dat \ |
| testFlow.out testFlow.out1 testFlow.out2 testFlow.out3 \ |
| testUnits.out |
| |
| all: all-am |
| @@ -230,6 +238,8 @@ |
| cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ |
| testHepMC.sh: $(top_builddir)/config.status $(srcdir)/testHepMC.sh.in |
| cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ |
| testFlow.sh: $(top_builddir)/config.status $(srcdir)/testFlow.sh.in |
| cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ |
| testMass.sh: $(top_builddir)/config.status $(srcdir)/testMass.sh.in |
| cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ |
| testHepMCIteration.sh: $(top_builddir)/config.status $(srcdir)/testHepMCIteration.sh.in |
| @@ -254,6 +264,9 @@ |
| testHepMCIteration$(EXEEXT): $(testHepMCIteration_OBJECTS) $(testHepMCIteration_DEPENDENCIES) |
| @rm -f testHepMCIteration$(EXEEXT) |
| $(CXXLINK) $(testHepMCIteration_OBJECTS) $(testHepMCIteration_LDADD) $(LIBS) |
| testFlow$(EXEEXT): $(testFlow_OBJECTS) $(testFlow_DEPENDENCIES) |
| @rm -f testFlow$(EXEEXT) |
| $(CXXLINK) $(testFlow_OBJECTS) $(testFlow_LDADD) $(LIBS) |
| testMass$(EXEEXT): $(testMass_OBJECTS) $(testMass_DEPENDENCIES) |
| @rm -f testMass$(EXEEXT) |
| $(CXXLINK) $(testMass_OBJECTS) $(testMass_LDADD) $(LIBS) |
| @@ -279,6 +292,7 @@ |
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testDeprecated.Po@am__quote@ |
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testHepMC.Po@am__quote@ |
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testHepMCIteration.Po@am__quote@ |
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testFlow.Po@am__quote@ |
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testMass.Po@am__quote@ |
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testMultipleCopies.Po@am__quote@ |
| @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/testPrintBug.Po@am__quote@ |