All of these can be used to iterate over the particles in an event, optionally applying some selection criteria.
#include <iostream>
#include <algorithm>
using std::cout;
using std::endl;
{
return a.GetZ() <
b.GetZ();
}
void iterator_examples()
{
for (int i = 0; i < 10; ++i) {
if (i > 4)
n->AddGroup(
"GROUP");
}
cout << "Loop over all particles (0-9):" << endl;
(*it).Print();
}
cout << "\nNested loops over N*(N-1)/2 pairs of particles:" << endl;
for (++it2; it2 !=
Event.end(); ++it2) {
cout << (*it).GetZ() << "-" << (*it2).GetZ() << " ";
}
cout << endl;
}
#ifdef WITH_CPP11
cout << "\nLoop over all particles (0-9) [range-based for loop]:" << endl;
for (
auto& nuc :
Event) {
nuc.Print();
}
#endif
cout << "\nLoop over OK particles (1,3,5,7,9):" << endl;
(*it).Print();
}
cout << "\nLoop over GROUP particles (5,6,7,8,9):" << endl;
(*it).Print();
}
cout << "\nPerform two different iterations with the same iterator" << endl;
cout << "\n1.) Loop over OK particles (1,3,5,7,9):" << endl;
#ifdef WITH_CPP11
#else
#endif
(*iter).Print();
}
cout << "\n2.) Loop over GROUP particles (5,6,7,8,9):" << endl;
#ifdef WITH_CPP11
iter.Reset(KVEvent::Iterator::Type::Group, "GROUP");
#else
#endif
(*iter).Print();
}
#ifdef WITH_CPP11
cout << "\nLoop over RANDOM particles [range-based for loop]:" << endl;
nuc.Print();
}
cout << "\nLoop over OK particles [range-based for loop]:" << endl;
nuc.Print();
}
#endif
cout << "\nSearch using algorithm std::find:" << endl;
#if !defined(__ROOTCINT__) && !defined(__ROOTCLING__)
(*found).Print();
#endif
#if !defined(__APPLE__)
cout << "\nFind largest Z in RANDOM group using std::max_element:" << endl;
(*maxZ).Print();
#endif
cout << "\nLoop over all particles (0-9) [GetNextParticle]:" << endl;
while ((n =
Event.GetNextParticle())) {
}
cout << "\nInterrupted iteration restarted with different criteria [GetNextParticle]:" << endl;
cout << "\n1.) Loop over OK particles with Z<=5 (1,3,5):" << endl;
while ((n =
Event.GetNextParticle(
"ok"))) {
if (
n->GetZ() > 5)
break;
}
Event.ResetGetNextParticle();
cout << "\n2.) Loop over GROUP particles (5,6,7,8,9):" << endl;
while ((n =
Event.GetNextParticle(
"GROUP"))) {
}
cout << "\nKVEvent::Print():" << endl;
cout << "\nKVEvent::Print(\"ok\"): (1,3,5,7,9)" << endl;
cout << "\nKVEvent::Print(\"group\"): (5,6,7,8,9)" << endl;
cout << "\nKVEvent::GetParticle(\"group\"): (5)" << endl;
Event.GetParticle(
"group")->Print();
cout << "\nKVEvent::GetParticle(\"unknown_group\"): (error)" << endl;
cout << "\nKVEvent::GetMult(\"ok\"): (5)" << endl;
cout <<
Event.GetMult(
"ok") << endl;
cout << "\nKVEvent::GetMult(\"group\"): (5)" << endl;
cout <<
Event.GetMult(
"group") << endl;
cout << "\nKVEvent::GetSum(\"GetZ\"): (45)" << endl;
cout <<
Event.GetSum(
"GetZ") << endl;
cout << "\nKVEvent::GetSum(\"GetZ\",\"group\"): (35)" << endl;
cout <<
Event.GetSum(
"GetZ",
"group") << endl;
cout << "\nKVEvent::GetSum(\"GetZ\",\"ok\"): (25)" << endl;
cout <<
Event.GetSum(
"GetZ",
"ok") << endl;
cout << "\nKVEvent::FillHisto(h,\"GetZ\",\"ok\"):" << endl;
TH1F*
h =
new TH1F(
"h",
"KVEvent::GetZ() for \"ok\" particles", 10, -.5, 9.5);
Event.FillHisto(h,
"GetZ",
"ok");
}
R__EXTERN TRandom * gRandom
Base class container for multi-particle events.
Description of properties and kinematics of atomic nuclei.
virtual void Print(Option_t *t="") const
Display nucleus parameters.
void SetZ(Int_t z, Char_t mt=-1)
virtual void Draw(Option_t *option="")
virtual Double_t Uniform(Double_t x1, Double_t x2)