Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KFParticle without Vc #722

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/StRoot/PWGTools @nigmatkulov @zsweger @marrbnl @lbavinh
/StRoot/RTS @akioogawa @jml985 @tonko-lj
/StRoot/StAnalysisMaker @fisyak @R-Witt @iraklic
/StRoot/*KFP* @fisyak @R-Witt @iraklic
/StRoot/StAnalysisUtilities/StHistUtil* @genevb
/StRoot/StAssociationMaker/EMC @kkauder @rkunnawa @Navagyan
/StRoot/StBFChain @genevb @plexoos @klendathu2k @fisyak @R-Witt @iraklic
Expand Down
1 change: 1 addition & 0 deletions StRoot/KFParticle/.includes_for_export.flg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All include files of this directory for export
190 changes: 190 additions & 0 deletions StRoot/KFParticle/KFPEmcCluster.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/*
* This file is part of KFParticle package
* Copyright (C) 2007-2019 FIAS Frankfurt Institute for Advanced Studies
* 2007-2019 Goethe University of Frankfurt
* 2007-2019 Ivan Kisel <[email protected]>
* 2007-2019 Maksym Zyzak
*
* KFParticle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KFParticle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "KFPEmcCluster.h"
#include <iostream>

void KFPEmcCluster::SetParameter(const float32_v& value, int iP, int iTr)
{
/** Copies the SIMD vector "value" to the parameter vector KFPEmcCluster::fP[iP]
** starting at the position "iTr".
** \param[in] value - SIMD vector with the values to be stored
** \param[in] iP - number of the parameter vector
** \param[in] iTr - starting position in the parameter vector where the values should be stored
**/
if( (iTr+SimdLen) < Size())
reinterpret_cast<float32_v&>(fP[iP][iTr]) = value;
else
{
int32_v index = int32_v::indicesSequence();
index = select(index<(Size() - iTr), index, 0);
(reinterpret_cast<float32_v&>(fP[iP][iTr])).gather(reinterpret_cast<const float*>(&value), index);
}
}
void KFPEmcCluster::SetCovariance(const float32_v& value, int iC, int iTr)
{
/** Copies the SIMD vector "value" to the element of the covariance matrix vector KFPEmcCluster::fC[iC]
** starting at the position "iTr".
** \param[in] value - SIMD vector with the values to be stored
** \param[in] iC - number of the element of the covariance matrix
** \param[in] iTr - starting position in the parameter vector where the values should be stored
**/
if( (iTr+SimdLen) < Size())
reinterpret_cast<float32_v&>(fC[iC][iTr]) = value;
else
{
int32_v index = int32_v::indicesSequence();
index = select(index<(Size() - iTr), index, 0);
(reinterpret_cast<float32_v&>(fC[iC][iTr])).gather(reinterpret_cast<const float*>(&value), index);
}
}

void KFPEmcCluster::Resize(const int n)
{
/** Resizes all vectors in the class to a given value.
** \param[in] n - new size of the vector
**/
for(int i=0; i<4; i++)
fP[i].resize(n);
for(int i=0; i<10; i++)
fC[i].resize(n);
fId.resize(n);
}

void KFPEmcCluster::Set(KFPEmcCluster& v, int vSize, int offset)
{
/** Copies "vSize" clusters from the KFPEmcCluster "v" to the current object.
** Tracks are put starting from the "offset" position.
** \param[in] v - external KFPEmcCluster with input clusters to be copied
** \param[in] vSize - number of clusters to be copied from "v"
** \param[in] offset - offset position in the current object, starting from which input clusters will be stored
**/
for(int iV=0; iV<vSize; iV++)
{
for(int i=0; i<4; i++)
fP[i][offset+iV] = v.fP[i][iV];
for(int i=0; i<10; i++)
fC[i][offset+iV] = v.fC[i][iV];
fId[offset+iV] = v.fId[iV];
}
}

void KFPEmcCluster::SetTracks(const KFPEmcCluster& track, const kfvector_int& trackIndex, const int nIndexes)
{
/** The current object is resised to "nIndexes", clusters with indices "trackIndex" are copied to the current object.
** \param[in] track - input vector of clusters
** \param[in] trackIndex - indices of clusters in a vector "track", which should be stored to the current object
** \param[in] nIndexes - number of clusters to be copied, defines the new size of the current object
**/

if(nIndexes == 0) return;

Resize(nIndexes);

for(int iP=0; iP<4; iP++)
{
int iElement = 0;
for(iElement=0; iElement<nIndexes-SimdLen; iElement += SimdLen)
{
const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]);
float32_v& vec = reinterpret_cast<float32_v&>(fP[iP][iElement]);
vec.gather(&(track.fP[iP][0]), index);
}
const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]);
float32_v& vec = reinterpret_cast<float32_v&>(fP[iP][iElement]);
const int32_v correctedIndices = select(int32_v::indicesSequence(iElement)<nIndexes, index, 0);
vec.gather(&(track.fP[iP][0]), correctedIndices);
}
for(int iC=0; iC<10; iC++)
{
int iElement=0;
for(iElement=0; iElement<nIndexes-SimdLen; iElement += SimdLen)
{
const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]);
float32_v& vec = reinterpret_cast<float32_v&>(fC[iC][iElement]);
vec.gather(&(track.fC[iC][0]), index);
}
const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]);
float32_v& vec = reinterpret_cast<float32_v&>(fC[iC][iElement]);
const int32_v correctedIndices = select(int32_v::indicesSequence(iElement)<nIndexes, index, 0);
vec.gather(&(track.fC[iC][0]), correctedIndices);
}
{
int iElement=0;
for(iElement=0; iElement<nIndexes-SimdLen; iElement += SimdLen)
{
const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]);
int32_v& vec = reinterpret_cast<int32_v&>(fId[iElement]);
vec.gather(&(track.fId[0]), index);
}
const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]);
int32_v& vec = reinterpret_cast<int32_v&>(fId[iElement]);
const int32_v correctedIndices = select(int32_v::indicesSequence(iElement)<nIndexes, index, 0);
vec.gather(&(track.fId[0]), correctedIndices);
}
}

void KFPEmcCluster::PrintTrack(int n)
{
/** Prints parameters of the cluster with index "n".
** \param[in] n - index of cluster to be printed
**/
for(int i=0; i<4; i++)
std::cout << fP[i][n] << " ";
std::cout << std::endl;
for(int i=0; i<10; i++)
std::cout << fC[i][n] << " ";
std::cout << std::endl;

std::cout << fId[n] << std::endl;
}

void KFPEmcCluster::PrintTracks()
{
/** Prints all field of the current object. **/

std::cout << "NTracks " << Size() << std::endl;
if( Size()==0 ) return;

std::cout << "Parameters: " << std::endl;
for(int iP=0; iP<4; iP++)
{
std::cout << " iP " << iP << ": ";
for(int iTr=0; iTr<Size(); iTr++)
std::cout << Parameter(iP)[iTr]<< " ";
std::cout << std::endl;
}

std::cout << "Cov matrix: " << std::endl;
for(int iC=0; iC<10; iC++)
{
std::cout << " iC " << iC << ": ";
for(int iTr=0; iTr<Size(); iTr++)
std::cout << Covariance(iC)[iTr]<< " ";
std::cout << std::endl;
}

std::cout << "Id: " << std::endl;
for(int iTr=0; iTr<Size(); iTr++)
std::cout << Id()[iTr] << " ";
std::cout << std::endl;
}

133 changes: 133 additions & 0 deletions StRoot/KFParticle/KFPEmcCluster.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
/*
* This file is part of KFParticle package
* Copyright (C) 2007-2019 FIAS Frankfurt Institute for Advanced Studies
* 2007-2019 Goethe University of Frankfurt
* 2007-2019 Ivan Kisel <[email protected]>
* 2007-2019 Maksym Zyzak
*
* KFParticle is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KFParticle is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef KFPEmcCluster_H
#define KFPEmcCluster_H

#include "KFParticleDef.h"

/** @class KFPEmcCluster
** @brief A class to store vectors of input cluster from the electro-magnetic calorimeter.
** @author M.Zyzak, I.Kisel
** @date 05.02.2019
** @version 1.0
**
** A cluster is described with the state vector { X, Y, Z, E }
** and the corresponding covariance matrix. Also contains a unique id.
** The data model implemented in the class is "Structure Of Arrays":
** each parameter is stroed in a separate vector. Such data structure
** allows fast vectorised access to the aligned data providing the
** maximum possible speed for data reading, and at the same time easy
** random access to the data members.
**/

class KFPEmcCluster
{
public:
KFPEmcCluster():fP(), fC(), fId() { }
~KFPEmcCluster() {}

/**Returns size of the vectors. All data vectors have the same size. */
int Size() const { return fP[0].size(); }

void Resize(const int n);
void Set(KFPEmcCluster& v, int vSize, int offset);
void SetTracks(const KFPEmcCluster& track, const kfvector_int& trackIndex, const int nIndexes);

const kfvector_float& X() const { return fP[0]; } ///< Returns constant reference to the vector with X coordinates.
const kfvector_float& Y() const { return fP[1]; } ///< Returns constant reference to the vector with Y coordinates.
const kfvector_float& Z() const { return fP[2]; } ///< Returns constant reference to the vector with Z coordinates.
const kfvector_float& E() const { return fP[3]; } ///< Returns constant reference to the vector with energy of the cluster.

const kfvector_float& Parameter(const int i) const { return fP[i]; } ///< Returns constant reference to the parameter vector with index "i".
const kfvector_float& Covariance(const int i) const { return fC[i]; } ///< Returns constant reference to the vector of the covariance matrix elements with index "i".
const kfvector_int& Id() const { return fId; } ///< Returns constant reference to the vector with unique id of the clusters.

//modifiers
void SetParameter (float value, int iP, int iTr) { fP[iP][iTr] = value; } ///< Sets the "value" of the parameter "iP" of the cluster with index "iTr".
void SetCovariance(float value, int iC, int iTr) { fC[iC][iTr] = value; } ///< Sets the "value" of the element of covariance matrix "iC" of the cluster with index "iTr".

void SetParameter (const float32_v& value, int iP, int iTr);
void SetCovariance(const float32_v& value, int iC, int iTr);

void SetId (int value, int iTr) { fId[iTr] = value; } ///< Sets the "value" of the id of the cluster with index "iTr".

void PrintTrack(int n);
void PrintTracks();

KFPEmcCluster(const KFPEmcCluster& clusters): fId()
{
/** Copy-constructor. Makes one-to-one copy.*/
const int localSize = clusters.Size();

for(int i=0; i<4; i++)
{
fP[i].resize(localSize);
for(int n=0; n<localSize; n++)
fP[i][n] = clusters.fP[i][n];
}

for(int i=0; i<10; i++)
{
fC[i].resize(localSize);
for(int n=0; n<localSize; n++)
fC[i][n] = clusters.fC[i][n];
}

fId.resize(localSize);
for(int n=0; n<localSize; n++)
fId[n] = clusters.fId[n];
}

const KFPEmcCluster& operator = (const KFPEmcCluster& clusters)
{
/** Operator to copy one KFPEmcCluster object to another. Makes one-to-one copy.*/
const int localSize = clusters.Size();

for(int i=0; i<4; i++)
{
fP[i].resize(localSize);
for(int n=0; n<localSize; n++)
fP[i][n] = clusters.fP[i][n];
}

for(int i=0; i<10; i++)
{
fC[i].resize(localSize);
for(int n=0; n<localSize; n++)
fC[i][n] = clusters.fC[i][n];
}

fId.resize(localSize);
for(int n=0; n<localSize; n++)
fId[n] = clusters.fId[n];

return *this;
}

private:
kfvector_float fP[4]; ///< Coordinates of the cluster and energy: X, Y, Z, E.
kfvector_float fC[10]; ///< Covariance matrix of the parameters of the cluster.

kfvector_int fId; ///< Vector with unique ids of the clusters.
};

#endif
Loading
Loading