All of these can be used to iterate over the particles in an event, optionally applying some selection criteria.
#include <iostream>
#include <algorithm>
#include "KVNucleusEvent.h"
#include "KVReconstructedEvent.h"
using std::cout;
using std::endl;
{
return a.GetZ() <
b.GetZ();
}
void nucleus_event_iterator(
KVEvent* e_ptr)
{
}
}
void recon_event_iterator(
KVEvent* e_ptr)
{
}
}
void iterator_examples()
{
for (int i = 0; i < 10; ++i) {
if (i > 4)
n->AddGroup(
"GROUP");
}
}
cout <<
"RANDOM group : " << random_Z.
AsString() << endl << endl;
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;
}
cout << "\nLoop over all particles (0-9) [range-based for loop]:" << endl;
for (
auto& nuc :
Event) {
nuc.Print();
}
cout << "\nLoop over OK particles (1,3,5,7,9):" << endl;
}
cout << "\nLoop over GROUP particles (5,6,7,8,9):" << endl;
}
cout << "\nArbitrary selection of particle using KVParticleCondition (Z<3 || Z>7):" << endl;
{
return (
n->GetZ() < 3 ||
n->GetZ() > 7);
}
})) {
}
cout << "\nPerform two different iterations with the same iterator" << endl;
cout << "\n1.) Loop over OK particles (1,3,5,7,9):" << endl;
for (; iter != KVNucleusEvent::Iterator::End(); ++iter) {
(*iter).Print();
}
cout << "\n2.) Loop over GROUP particles (5,6,7,8,9):" << endl;
iter.Reset(KVNucleusEvent::Iterator::Type::Group, "GROUP");
for (; iter != KVNucleusEvent::Iterator::End(); ++iter) {
(*iter).Print();
}
cout << "\nLoop over RANDOM particles [range-based for loop]:" << endl;
nuc.Print();
}
cout << "\nLoop over OK particles [range-based for loop]:" << endl;
nuc.Print();
}
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 OK particles using base pointer (KVEvent*):" << endl;
cout << "\n1.) KVNucleusEventIterator with KVNucleusEvent" << endl;
nucleus_event_iterator(_eptr);
cout << "\n2.) KVReconstructedEventIterator with KVNucleusEvent [Warning]" << endl;
recon_event_iterator(_eptr);
_eptr = &recev;
cout << "\n3.) KVNucleusEventIterator with KVReconstructedEvent" << endl;
nucleus_event_iterator(_eptr);
cout << "\n4.) KVReconstructedEventIterator with KVReconstructedEvent" << endl;
recon_event_iterator(_eptr);
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;
auto h =
new TH1F(
"h",
"KVEvent::GetZ() for \"ok\" particles", 10, -.5, 9.5);
Event.FillHisto(h,
"GetZ",
"ok");
cout << "\nUsing non-nuclear particle species in event classes:" << endl;
for (
auto&
p : my_event) {
std::cout <<
"This particle's mass is " <<
p.GetMass() << std::endl;
}
std::cout <<
"Total mass of event = " << my_event.
GetSum(
"GetMass") << std::endl;
}
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t b
R__EXTERN TRandom * gRandom
Class for iterating over nuclei of given group in events accessed through base pointer/reference.
Class for iterating over nuclei in events accessed through base pointer/reference.
Class for iterating over "OK" nuclei in events accessed through base pointer/reference.
Abstract base class container for multi-particle events.
An event container for KVNucleus objects.
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)
Strings used to represent a set of ranges of values.
const Char_t * AsString(Int_t maxchars=0) const
void Add(Int_t)
Add value 'n' to the list.
Event containing KVReconstructedNucleus nuclei reconstructed from hits in detectors.
Class used for iterating over particles in events.
Base class for event classes (containers for different types of particle objects)
Double_t GetSum(const Char_t *Nucleus_method, Option_t *opt="")
Wrapper class for iterating over "OK" nuclei in KVReconstructedEvent accessed through base pointer or...
void Draw(Option_t *option="") override
virtual Double_t Uniform(Double_t x1, Double_t x2)