|
| 1 | +/* |
| 2 | + * This file is part of KFParticle package |
| 3 | + * Copyright (C) 2007-2019 FIAS Frankfurt Institute for Advanced Studies |
| 4 | + * 2007-2019 Goethe University of Frankfurt |
| 5 | + * 2007-2019 Ivan Kisel <I.Kisel@compeng.uni-frankfurt.de> |
| 6 | + * 2007-2019 Maksym Zyzak |
| 7 | + * |
| 8 | + * KFParticle is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License as published by |
| 10 | + * the Free Software Foundation, either version 3 of the License, or |
| 11 | + * (at your option) any later version. |
| 12 | + * |
| 13 | + * KFParticle is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License |
| 19 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | + */ |
| 21 | + |
| 22 | +#include "KFPEmcCluster.h" |
| 23 | +#include <iostream> |
| 24 | + |
| 25 | +void KFPEmcCluster::SetParameter(const float32_v& value, int iP, int iTr) |
| 26 | +{ |
| 27 | + /** Copies the SIMD vector "value" to the parameter vector KFPEmcCluster::fP[iP] |
| 28 | + ** starting at the position "iTr". |
| 29 | + ** \param[in] value - SIMD vector with the values to be stored |
| 30 | + ** \param[in] iP - number of the parameter vector |
| 31 | + ** \param[in] iTr - starting position in the parameter vector where the values should be stored |
| 32 | + **/ |
| 33 | + if( (iTr+SimdLen) < Size()) |
| 34 | + reinterpret_cast<float32_v&>(fP[iP][iTr]) = value; |
| 35 | + else |
| 36 | + { |
| 37 | + int32_v index = int32_v::indicesSequence(); |
| 38 | + index = select(index<(Size() - iTr), index, 0); |
| 39 | + (reinterpret_cast<float32_v&>(fP[iP][iTr])).gather(reinterpret_cast<const float*>(&value), index); |
| 40 | + } |
| 41 | +} |
| 42 | +void KFPEmcCluster::SetCovariance(const float32_v& value, int iC, int iTr) |
| 43 | +{ |
| 44 | + /** Copies the SIMD vector "value" to the element of the covariance matrix vector KFPEmcCluster::fC[iC] |
| 45 | + ** starting at the position "iTr". |
| 46 | + ** \param[in] value - SIMD vector with the values to be stored |
| 47 | + ** \param[in] iC - number of the element of the covariance matrix |
| 48 | + ** \param[in] iTr - starting position in the parameter vector where the values should be stored |
| 49 | + **/ |
| 50 | + if( (iTr+SimdLen) < Size()) |
| 51 | + reinterpret_cast<float32_v&>(fC[iC][iTr]) = value; |
| 52 | + else |
| 53 | + { |
| 54 | + int32_v index = int32_v::indicesSequence(); |
| 55 | + index = select(index<(Size() - iTr), index, 0); |
| 56 | + (reinterpret_cast<float32_v&>(fC[iC][iTr])).gather(reinterpret_cast<const float*>(&value), index); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +void KFPEmcCluster::Resize(const int n) |
| 61 | +{ |
| 62 | + /** Resizes all vectors in the class to a given value. |
| 63 | + ** \param[in] n - new size of the vector |
| 64 | + **/ |
| 65 | + for(int i=0; i<4; i++) |
| 66 | + fP[i].resize(n); |
| 67 | + for(int i=0; i<10; i++) |
| 68 | + fC[i].resize(n); |
| 69 | + fId.resize(n); |
| 70 | +} |
| 71 | + |
| 72 | +void KFPEmcCluster::Set(KFPEmcCluster& v, int vSize, int offset) |
| 73 | +{ |
| 74 | + /** Copies "vSize" clusters from the KFPEmcCluster "v" to the current object. |
| 75 | + ** Tracks are put starting from the "offset" position. |
| 76 | + ** \param[in] v - external KFPEmcCluster with input clusters to be copied |
| 77 | + ** \param[in] vSize - number of clusters to be copied from "v" |
| 78 | + ** \param[in] offset - offset position in the current object, starting from which input clusters will be stored |
| 79 | + **/ |
| 80 | + for(int iV=0; iV<vSize; iV++) |
| 81 | + { |
| 82 | + for(int i=0; i<4; i++) |
| 83 | + fP[i][offset+iV] = v.fP[i][iV]; |
| 84 | + for(int i=0; i<10; i++) |
| 85 | + fC[i][offset+iV] = v.fC[i][iV]; |
| 86 | + fId[offset+iV] = v.fId[iV]; |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +void KFPEmcCluster::SetTracks(const KFPEmcCluster& track, const kfvector_int& trackIndex, const int nIndexes) |
| 91 | +{ |
| 92 | + /** The current object is resised to "nIndexes", clusters with indices "trackIndex" are copied to the current object. |
| 93 | + ** \param[in] track - input vector of clusters |
| 94 | + ** \param[in] trackIndex - indices of clusters in a vector "track", which should be stored to the current object |
| 95 | + ** \param[in] nIndexes - number of clusters to be copied, defines the new size of the current object |
| 96 | + **/ |
| 97 | + |
| 98 | + if(nIndexes == 0) return; |
| 99 | + |
| 100 | + Resize(nIndexes); |
| 101 | + |
| 102 | + for(int iP=0; iP<4; iP++) |
| 103 | + { |
| 104 | + int iElement = 0; |
| 105 | + for(iElement=0; iElement<nIndexes-SimdLen; iElement += SimdLen) |
| 106 | + { |
| 107 | + const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]); |
| 108 | + float32_v& vec = reinterpret_cast<float32_v&>(fP[iP][iElement]); |
| 109 | + vec.gather(&(track.fP[iP][0]), index); |
| 110 | + } |
| 111 | + const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]); |
| 112 | + float32_v& vec = reinterpret_cast<float32_v&>(fP[iP][iElement]); |
| 113 | + const int32_v correctedIndices = select(int32_v::indicesSequence(iElement)<nIndexes, index, 0); |
| 114 | + vec.gather(&(track.fP[iP][0]), correctedIndices); |
| 115 | + } |
| 116 | + for(int iC=0; iC<10; iC++) |
| 117 | + { |
| 118 | + int iElement=0; |
| 119 | + for(iElement=0; iElement<nIndexes-SimdLen; iElement += SimdLen) |
| 120 | + { |
| 121 | + const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]); |
| 122 | + float32_v& vec = reinterpret_cast<float32_v&>(fC[iC][iElement]); |
| 123 | + vec.gather(&(track.fC[iC][0]), index); |
| 124 | + } |
| 125 | + const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]); |
| 126 | + float32_v& vec = reinterpret_cast<float32_v&>(fC[iC][iElement]); |
| 127 | + const int32_v correctedIndices = select(int32_v::indicesSequence(iElement)<nIndexes, index, 0); |
| 128 | + vec.gather(&(track.fC[iC][0]), correctedIndices); |
| 129 | + } |
| 130 | + { |
| 131 | + int iElement=0; |
| 132 | + for(iElement=0; iElement<nIndexes-SimdLen; iElement += SimdLen) |
| 133 | + { |
| 134 | + const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]); |
| 135 | + int32_v& vec = reinterpret_cast<int32_v&>(fId[iElement]); |
| 136 | + vec.gather(&(track.fId[0]), index); |
| 137 | + } |
| 138 | + const int32_v& index = reinterpret_cast<const int32_v&>(trackIndex[iElement]); |
| 139 | + int32_v& vec = reinterpret_cast<int32_v&>(fId[iElement]); |
| 140 | + const int32_v correctedIndices = select(int32_v::indicesSequence(iElement)<nIndexes, index, 0); |
| 141 | + vec.gather(&(track.fId[0]), correctedIndices); |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | +void KFPEmcCluster::PrintTrack(int n) |
| 146 | +{ |
| 147 | + /** Prints parameters of the cluster with index "n". |
| 148 | + ** \param[in] n - index of cluster to be printed |
| 149 | + **/ |
| 150 | + for(int i=0; i<4; i++) |
| 151 | + std::cout << fP[i][n] << " "; |
| 152 | + std::cout << std::endl; |
| 153 | + for(int i=0; i<10; i++) |
| 154 | + std::cout << fC[i][n] << " "; |
| 155 | + std::cout << std::endl; |
| 156 | + |
| 157 | + std::cout << fId[n] << std::endl; |
| 158 | +} |
| 159 | + |
| 160 | +void KFPEmcCluster::PrintTracks() |
| 161 | +{ |
| 162 | + /** Prints all field of the current object. **/ |
| 163 | + |
| 164 | + std::cout << "NTracks " << Size() << std::endl; |
| 165 | + if( Size()==0 ) return; |
| 166 | + |
| 167 | + std::cout << "Parameters: " << std::endl; |
| 168 | + for(int iP=0; iP<4; iP++) |
| 169 | + { |
| 170 | + std::cout << " iP " << iP << ": "; |
| 171 | + for(int iTr=0; iTr<Size(); iTr++) |
| 172 | + std::cout << Parameter(iP)[iTr]<< " "; |
| 173 | + std::cout << std::endl; |
| 174 | + } |
| 175 | + |
| 176 | + std::cout << "Cov matrix: " << std::endl; |
| 177 | + for(int iC=0; iC<10; iC++) |
| 178 | + { |
| 179 | + std::cout << " iC " << iC << ": "; |
| 180 | + for(int iTr=0; iTr<Size(); iTr++) |
| 181 | + std::cout << Covariance(iC)[iTr]<< " "; |
| 182 | + std::cout << std::endl; |
| 183 | + } |
| 184 | + |
| 185 | + std::cout << "Id: " << std::endl; |
| 186 | + for(int iTr=0; iTr<Size(); iTr++) |
| 187 | + std::cout << Id()[iTr] << " "; |
| 188 | + std::cout << std::endl; |
| 189 | +} |
| 190 | + |
0 commit comments