50 GenParticlePtr p1 = make_shared<GenParticle>(
FourVector( 0.0, 0.0, 7000.0, 7000.0 ),2212, 3 );
51 GenParticlePtr p2 = make_shared<GenParticle>(
FourVector( 0.750, -1.569, 32.191, 32.238), 1, 3 );
52 GenParticlePtr p3 = make_shared<GenParticle>(
FourVector( 0.0, 0.0, -7000.0, 7000.0 ),2212, 3 );
53 GenParticlePtr p4 = make_shared<GenParticle>(
FourVector(-3.047,-19.0, -54.629, 57.920), -2, 3 );
55 GenVertexPtr v1 = make_shared<GenVertex>();
56 v1->add_particle_in (p1);
57 v1->add_particle_out(p2);
63 GenVertexPtr v2 = make_shared<GenVertex>();
64 v2->add_particle_in (p3);
65 v2->add_particle_out(p4);
68 GenVertexPtr v3 = make_shared<GenVertex>();
69 v3->add_particle_in(p2);
70 v3->add_particle_in(p4);
73 GenParticlePtr p5 = make_shared<GenParticle>(
FourVector(-3.813, 0.113, -1.833, 4.233), 22, 1 );
74 GenParticlePtr p6 = make_shared<GenParticle>(
FourVector( 1.517,-20.68, -20.605,85.925), -24, 3 );
76 v3->add_particle_out(p5);
77 v3->add_particle_out(p6);
79 GenVertexPtr v4 = make_shared<GenVertex>();
80 v4->add_particle_in (p6);
83 GenParticlePtr p7 = make_shared<GenParticle>(
FourVector(-2.445, 28.816, 6.082,29.552), 1, 1 );
84 GenParticlePtr p8 = make_shared<GenParticle>(
FourVector( 3.962,-49.498,-26.687,56.373), -2, 1 );
86 v4->add_particle_out(p7);
87 v4->add_particle_out(p8);
94 std::cout << std::endl <<
"Find all stable particles: " << std::endl;
96 for(ConstGenParticlePtr p:
applyFilter(Selector::STATUS == 1, evt.particles())){
101 std::cout <<std::endl <<
"Find all ancestors of particle with id " << p5->id() <<
": " << std::endl;
103 for(ConstGenParticlePtr p: Relatives::ANCESTORS(p5)){
108 std::cout <<std::endl <<
"Find stable descendants of particle with id " << p4->id() <<
": " << std::endl;
109 std::cout<<
"We check both for STATUS == 1 (equivalent of IS_STABLE) and no end vertex, just to be safe" << std::endl;
111 Filter has_end_vtx = [](ConstGenParticlePtr input)->
bool{
return (
bool)input->end_vertex();};
113 vector<GenParticlePtr> results3 =
applyFilter(Selector::STATUS==1 && has_end_vtx, Relatives::DESCENDANTS(p4));
114 for(ConstGenParticlePtr p: results3){
119 std::cout << std::endl <<
"Narrow down results of previous search to quarks only: " << std::endl;
122 for(ConstGenParticlePtr p:
applyFilter( *
abs(Selector::PDG_ID) <= 6, results3)){
129 shared_ptr<GenPdfInfo> pdf_info = make_shared<GenPdfInfo>();
130 evt.add_attribute(
"GenPdfInfo",pdf_info);
132 pdf_info->
set(1,2,3.4,5.6,7.8,9.0,1.2,3,4);
134 shared_ptr<GenHeavyIon> heavy_ion = make_shared<GenHeavyIon>();
135 evt.add_attribute(
"GenHeavyIon",heavy_ion);
137 heavy_ion->
set( 1,2,3,4,5,6,7,8,9,0.1,2.3,4.5,6.7);
139 shared_ptr<GenCrossSection> cross_section = make_shared<GenCrossSection>();
140 evt.add_attribute(
"GenCrossSection",cross_section);
148 std::cout << std::endl <<
" Manipulating attributes:" << std::endl;
151 shared_ptr<GenCrossSection> cs = evt.attribute<
GenCrossSection>(
"GenCrossSection");
158 else std::cout <<
"Problem accessing attribute!" <<std::endl;
161 evt.remove_attribute(
"GenCrossSection");
162 evt.remove_attribute(
"GenCrossSection");
167 if(!cs)std::cout <<
"Successfully removed attribute" <<std::endl;
168 else std::cout <<
"Problem removing attribute!" <<std::endl;
174 shared_ptr<Attribute> tool1 = make_shared<IntAttribute>(1);
175 shared_ptr<Attribute> tool999 = make_shared<IntAttribute>(999);
176 shared_ptr<Attribute> test_attribute = make_shared<StringAttribute>(
"test attribute");
177 shared_ptr<Attribute> test_attribute2 = make_shared<StringAttribute>(
"test attribute2");
179 p2->add_attribute(
"tool" , tool1 );
180 p2->add_attribute(
"other" , test_attribute );
182 p4->add_attribute(
"tool" , tool1 );
184 p6->add_attribute(
"tool" , tool999 );
185 p6->add_attribute(
"other" , test_attribute2 );
187 v3->add_attribute(
"vtx_att" , test_attribute );
188 v4->add_attribute(
"vtx_att" , test_attribute2 );
190 std::cout << std::endl <<
"Find all particles with attribute 'tool' "<< std::endl;
191 std::cout <<
"(should return particles 2,4,6):" << std::endl;
197 for(ConstGenParticlePtr p:
applyFilter(Selector::ATTRIBUTE(
"tool"), evt.particles())){
201 std::cout <<std::endl <<
"Find all particles with attribute 'tool' equal 1 "<< std::endl;
202 std::cout <<
"(should return particles 2,4):" <<std::endl;
204 for(ConstGenParticlePtr p:
applyFilter(Selector::ATTRIBUTE(
"tool") && Selector::ATTRIBUTE(
"tool") == tool1, evt.particles())){
208 std::cout << std::endl <<
"Find all particles with a string attribute 'other' equal 'test attribute' "<< std::endl;
209 std::cout <<
"(should return particle 2):" << std::endl;
212 for(ConstGenParticlePtr p:
applyFilter(Selector::ATTRIBUTE(
"other") && Selector::ATTRIBUTE(
"other") ==
"test_attribute", evt.particles())){
216 std::cout << std::endl <<
"Offsetting event position by 5,5,5,5" << std::endl;
222 std::cout << std::endl <<
"Printing full content of the GenEvent object " << std::endl
223 <<
"(including particles and vertices in one-line format):" << std::endl << std::endl;
227 std::cout <<std::endl <<
"Now: removing particle with id 6 and printing again:" <<std::endl <<std::endl;
228 evt.remove_particle(p6);
233 std::cout <<std::endl <<
"Now: removing beam particles, leaving an empty event" <<std::endl <<std::endl;
234 evt.remove_particles( evt.beams() );