19 #ifndef __FIZIKA_REACTION__
20 #define __FIZIKA_REACTION__
46 std::vector<hipo::bank> banks;
47 std::vector<std::pair<int,int>> filter;
48 bool filter_exclusive =
true;
50 void initialize(
const char* file, std::vector<std::string> blist){
53 for(decltype(blist)::size_type i = 0; i < blist.size(); i++) {
66 initialize(file,{
"REC::Particle"});
71 reaction(
const char *file, std::initializer_list<std::tuple<int,int> > desc){
72 initialize(file,{
"REC::Particle"});
79 reaction(
const char *file,
double benergy, std::initializer_list<std::tuple<int,int> > desc){
80 initialize(file,{
"REC::Particle"});
82 lz4_beam.
setXYZM(0.0,0.0,benergy, 0.0005);
83 lz4_target.
setXYZM(0.0,0.0,0.0,0.938);
84 centermass = lz4_beam + lz4_target;
93 reaction(
const char *file,
double benergy,
int *pids,
int *count,
int length){
94 initialize(file,{
"REC::Particle"});
95 lz4_beam.
setXYZM(0.0,0.0,benergy, 0.0005);
96 lz4_target.
setXYZM(0.0,0.0,0.0,0.938);
97 centermass = lz4_beam + lz4_target;
98 printf(
">>>> initializing the reaction\n");
99 for(
int k = 0; k < length; k++){
100 filter.push_back(std::make_pair(pids[k],count[k]));
101 printf(
"push back -> %6d %6d\n",pids[k],count[k]);
113 void init_filter(std::initializer_list<std::tuple<int,int> > desc){
114 std::initializer_list< std::tuple<int,int>>::iterator it;
115 for ( it=desc.begin(); it!=desc.end(); ++it){
116 printf(
"PID %d, count %d\n", std::get<0>(*it),std::get<1>(*it));
117 filter.push_back(std::make_pair( std::get<0>(*it),std::get<1>(*it)));
131 std::initializer_list< std::tuple<int,int,int ,double>>::iterator it;
132 for ( it=desc.begin(); it!=desc.end(); ++it){
133 int ind =
index(std::get<1>(*it), std::get<2>(*it));
135 get_vector(temp,std::get<3>(*it),banks[0],ind, 1,2,3);
136 if(std::get<0>(*it)<0) vec -= temp;
else vec += temp;
151 for(
int k = 0; k < length; k++){
152 int ind =
index(pids[k],skips[k]);
154 get_vector(temp,masses[k],banks[0],ind,1,2,3);
155 if(signs[k]<0) vec -= temp;
else vec += temp;
165 bool status = reader.
next();
166 if(status==
false)
return status;
168 for(decltype(banks)::size_type r = 0; r < banks.size(); r++) event.
read(banks[r]);
180 for(decltype(filter)::size_type f = 0; f < filter.size(); f++){
181 int count =
countpid(filter[f].first);
183 if(filter_exclusive==
true){
184 if(count!=filter[f].second)
return false;
185 }
else {
if(count<filter[f].second)
return false; }
194 for(
int r = 0; r < banks[0].getRows(); r++){
195 int upid = banks[0].getInt(0,r);
196 int stat = banks[0].getInt(
"status",r);
198 if(abs(stat)>2000&&abs(stat)<3000) counter++;
209 for(
int r = 0; r < banks[0].getRows(); r++){
210 int upid = banks[0].getInt(0,r);
211 int stat = banks[0].getInt(
"status",r);
213 if(abs(stat)>2000&&abs(stat)<3000){
214 if(skip==skipped) {
return r; }
else { skipped++;}
Four-component Lorentz vector for relativistic kinematics.
void setXYZM(double _x, double _y, double _z, double _m)
Set components from momentum and mass; energy is computed.
Physics analysis helper for filtering and reconstructing reactions from HIPO data.
reaction(const char *file, double benergy, std::initializer_list< std::tuple< int, int > > desc)
Construct a reaction with beam energy and particle filter.
fizika::lorentz4 & beam()
void get_vector(fizika::lorentz4 &vec, double mass, hipo::bank &b, int order, int ind_px, int ind_py, int ind_pz)
Fill a Lorentz vector from a bank row's momentum columns and a given mass.
reaction(const char *file)
Construct a reaction from a HIPO file (no filter, no beam setup).
bool next()
Advance to the next event and read all banks.
fizika::lorentz4 get(int *signs, int *pids, int *skips, double *masses, int length)
Reconstruct a Lorentz vector from arrays of particle parameters.
int index(int pid, int skip)
Find the row index of the Nth particle with the given PID.
void init_filter(std::initializer_list< std::tuple< int, int > > desc)
Initialize the particle filter from PID/count pairs.
bool is_valid()
Check if the current event passes the particle filter.
int countpid(int pid)
Count particles with the given PID that pass status cuts.
reaction(const char *file, std::initializer_list< std::tuple< int, int > > desc)
Construct a reaction with a particle filter.
reaction(const char *file, double benergy, int *pids, int *count, int length)
Construct a reaction with beam energy and C-style filter arrays.
std::vector< hipo::bank > & getBanks()
fizika::lorentz4 & target()
fizika::lorentz4 get(std::initializer_list< std::tuple< int, int, int, double > > desc)
Reconstruct a Lorentz vector from a particle combination.
reaction()
Default constructor.
Represents a HIPO bank, a tabular data structure with rows and typed columns.
float getFloat(int item, int index) const noexcept
Collection of schema definitions, typically read from a HIPO file header.
schema & getSchema(const char *name)
Retrieve a schema by name.
Represents a HIPO event, a container for multiple structures/banks.
void read(hipo::bank &b)
Read a bank from this event (alias for getStructure).
Sequential reader for HIPO files.
void read(hipo::event &dataevent)
Read the current event into the given event object.
void readDictionary(hipo::dictionary &dict)
Read the schema dictionary from the file header.
bool next()
Advance to the next event.
void open(const char *filename)
Open a HIPO file for reading.
Vector physics library including 3D and Lorentz 4-vectors for relativistic kinematics.
Sequential and random-access reader for HIPO files with event filtering and dictionary support.