CbmRoot
L1Grid.cxx
Go to the documentation of this file.
1 #include "L1Grid.h"
2 
3 #include "CbmL1Def.h"
4 #include <algorithm>
5 #include <string.h>
6 
7 #include <assert.h>
8 #include <cstdio>
9 #ifdef _OPENMP
10 #include "omp.h"
11 #endif
12 #include "L1Algo.h"
13 
14 
15 using namespace std;
16 
19 template<typename T>
20 
21 inline void memset(T* dest, T i, size_t num) {
22  const size_t tsize = sizeof(T);
23  unsigned int lastBin = 0;
24  dest[0] = i;
25  while (lastBin + 1 < num) {
26  unsigned int l = lastBin + 1;
27  l = lastBin + l + 1 > num ? num - lastBin - 1 : l;
28  memcpy(dest + lastBin + 1, dest, l * tsize);
29  lastBin += l;
30  }
31 }
32 
33 
34 void L1Grid::UpdateIterGrid(unsigned int Nelements,
35  L1StsHit* hits,
36  vector<THitI>* indicesBuf,
37  THitI* indices,
38  vector<L1StsHit>* hits2,
39  vector<L1HitPoint>* pointsBuf,
41  int& NHitsOnStation,
42  char iS,
43  L1Algo& Algo,
44  const vector<unsigned char>* vSFlag,
45  const vector<unsigned char>* vSFlagB) {
46 
47  fFirstHitInBin.assign(fN + 2, 0);
48 
49  fscal xs = 0;
50  fscal ys = 0;
51 
52 #ifdef _OPENMP
53 #pragma omp parallel for schedule(dynamic, 250) firstprivate(xs, ys)
54 #endif
55  for (THitI x = 0; x < Nelements; x++) {
56 
57  const L1StsHit& hit = hits[x];
58 
59  if (!L1Algo::GetFUsed((*vSFlag)[hit.f] | (*vSFlagB)[hit.b])) {
60  Algo.GetHitCoor(hit, xs, ys, iS);
61 
62  const THitI& bin = GetBinBounded(xs, ys, hit.t_reco);
63 
64  fHitsInBin[x] = fFirstHitInBin[bin + 1];
65 #ifdef _OPENMP
66 #pragma omp atomic
67 #endif
68  fFirstHitInBin[bin + 1]++;
69  }
70  }
71 
72  int kk = 2;
73  /* Up-Sweep Phase */
74  for (unsigned int k = 1; k < fN + 2; k = kk) {
75  kk = k << 1;
76 #ifdef _OPENMP
77 #pragma omp parallel for //schedule(guided)
78 #endif
79  for (unsigned int i = kk - 1; i < fN + 2; i += kk) {
80  fFirstHitInBin[i] = fFirstHitInBin[i - k] + fFirstHitInBin[i];
81  }
82  }
83 
84  /* Down-Sweep Phase */
85  for (int k = kk >> 1; k > 1; k = kk) {
86  kk = k >> 1;
87 #ifdef _OPENMP
88 #pragma omp parallel for //schedule(guided)
89 #endif
90  for (unsigned int i = k - 1; i < fN + 2 - kk; i += k) {
91  fFirstHitInBin[i + kk] = fFirstHitInBin[i] + fFirstHitInBin[i + kk];
92  }
93  }
94 
95 #ifdef _OPENMP
96 #pragma omp parallel for schedule(dynamic, 250) firstprivate(xs, ys)
97 #endif
98  for (THitI x = 0; x < Nelements; x++) {
99 
100  const L1StsHit& hit = hits[x];
101  if (!L1Algo::GetFUsed((*vSFlag)[hit.f] | (*vSFlagB)[hit.b])) {
102  Algo.GetHitCoor(hit, xs, ys, iS);
103 
104 
105  const THitI& bin = GetBinBounded(xs, ys, hit.t_reco);
106 
107  {
108 
109  const THitI& index1 = fHitsInBin[x] + fFirstHitInBin[bin];
110 
111  (*hits2)[index1 + NHitsOnStation] = hits[x];
112  (*indicesBuf)[index1 + NHitsOnStation] = indices[x];
113  (*pointsBuf)[index1 + NHitsOnStation] = points[x];
114  }
115  }
116  }
117 
118  NHitsOnStation += fFirstHitInBin[fN + 1];
119 }
120 
121 
122 void L1Grid::AllocateMemory(int NThreads) {
123 
124  fNThreads = NThreads * 1;
125 
126  // fFirstHitInBinArray.resize(fNThreads, 0);
127 
128 
129  int binsGrid = 600000;
130 
131  fFirstHitInBin.resize(binsGrid, 0);
132  fHitsInBin.resize(binsGrid, 0);
133 
134  // for( int i = 0; i < fNThreads; i++ )
135  // {
136  // delete[] fFirstHitInBinArray[i];
137  // delete[] fFirstHitInBin[i];
138  // fFirstHitInBinArray[i] = new THitI[binsGrid];// TODO calculate safe number of bins
139  // fFirstHitInBin[i] = new THitI[binsGrid];
140  // }
141  // fOffsets.resize(fNThreads +1, 0);
142  // fNumberHitsInBin.resize(binsGrid, 0);
143 }
144 
145 
146 void L1Grid::BuildBins(float yMin,
147  float yMax,
148  float zMin,
149  float zMax,
150  float tMin,
151  float tMax,
152  float sy,
153  float sz,
154  float st) {
155 
156  fStepYInv = 1.f / sy;
157  fStepZInv = 1.f / sz;
158  fStepTInv = 1.f / st;
159 
160  fYMinOverStep = yMin * fStepYInv;
161  fZMinOverStep = zMin * fStepZInv;
162  fTMinOverStep = tMin * fStepTInv;
163 
164  fNy = (yMax * fStepYInv - fYMinOverStep + 1.f);
165  fNz = (zMax * fStepZInv - fZMinOverStep + 1.f);
166  fNt = (tMax * fStepTInv - fTMinOverStep + 1.f);
167  // unsigned int Nold = fN;
168 
169  fN = fNy * fNz * fNt;
170 
171  fBinInGrid = (((fN) / fNThreads) + 1);
172 }
173 
174 
176  const L1StsHit* hits,
177  char iS,
178  L1Algo& Algo,
179  THitI n,
180  L1StsHit* hitsBuf1,
181  const L1StsHit* hits1,
182  THitI* indices1) {
183 
184  fscal xs = 0;
185  fscal ys = 0;
186 
187  fFirstHitInBin.assign(fN + 2, 0);
188 
189 #ifdef _OPENMP
190 #pragma omp parallel for firstprivate(xs, ys)
191 #endif
192  for (THitI x = 0; x < nhits; x++) {
193  Algo.GetHitCoor((hits)[x], xs, ys, iS);
194 
195 
196  fHitsInBin[x] = fFirstHitInBin[GetBinBounded(xs, ys, (hits)[x].t_reco) + 1];
197 #ifdef _OPENMP
198 #pragma omp atomic
199 #endif
200  fFirstHitInBin[GetBinBounded(xs, ys, (hits)[x].t_reco) + 1]++;
201  }
202 
203 
204  int kk = 2;
205  /* Up-Sweep Phase */
206  for (unsigned int k = 1; k < fN + 2; k = kk) {
207  kk = k << 1;
208 #ifdef _OPENMP
209 #pragma omp parallel for //schedule(guided)
210 #endif
211  for (unsigned int i = kk - 1; i < fN + 2; i += kk) {
212  fFirstHitInBin[i] = fFirstHitInBin[i - k] + fFirstHitInBin[i];
213  }
214  }
215 
216  /* Down-Sweep Phase */
217  for (unsigned int k = kk >> 1; k > 1; k = kk) {
218  kk = k >> 1;
219 #ifdef _OPENMP
220 #pragma omp parallel for //schedule(guided)
221 #endif
222  for (unsigned int i = k - 1; i < fN + 2 - kk; i += k) {
223  fFirstHitInBin[i + kk] = fFirstHitInBin[i] + fFirstHitInBin[i + kk];
224  }
225  }
226 
227 
228 #pragma omp parallel for firstprivate(xs, ys)
229  for (THitI x = 0; x < nhits; x++) {
230 
231  Algo.GetHitCoor((hits1)[x], xs, ys, iS);
232 
233 
234  const THitI& bin = GetBinBounded(xs, ys, (hits1)[x].t_reco);
235 
236  {
237 
238  const THitI& index1 = fHitsInBin[x] + fFirstHitInBin[bin];
239 
240  (hitsBuf1)[index1] = hits[x];
241 
242 
243  (indices1)[index1] = x + n;
244  }
245  }
246 }
fscal
float fscal
Definition: L1/vectors/P4_F32vec4.h:250
L1HitPoint
contain strips positions and coordinates of hit
Definition: L1HitPoint.h:6
L1Algo.h
memset
void memset(T *dest, T i, size_t num)
Definition: L1Grid.cxx:21
L1Grid::AllocateMemory
void AllocateMemory(int NThreads)
Definition: L1Grid.cxx:122
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
L1StsHit
Definition: L1StsHit.h:12
L1StsHit::b
TStripI b
Definition: L1StsHit.h:15
CbmL1Def.h
THitI
unsigned int THitI
Definition: L1StsHit.h:8
L1Grid::UpdateIterGrid
void UpdateIterGrid(unsigned int Nelements, L1StsHit *hits, vector< THitI > *indicesBuf, THitI *indices, vector< L1StsHit > *hits2, vector< L1HitPoint > *pointsBuf, L1HitPoint *points, int &NHitsOnStation, char iS, L1Algo &Algo, const vector< unsigned char > *vSFlag, const vector< unsigned char > *vSFlagB)
Definition: L1Grid.cxx:34
L1Grid::BuildBins
void BuildBins(float yMin, float yMax, float zMin, float zMax, float tMin, float tMax, float sy, float sz, float st)
Definition: L1Grid.cxx:146
L1Algo
Definition: L1Algo.h:79
L1StsHit::t_reco
float t_reco
Definition: L1StsHit.h:17
points
TClonesArray * points
Definition: Analyze_matching.h:18
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
hits
static vector< vector< QAHit > > hits
Definition: CbmTofHitFinderTBQA.cxx:114
L1Algo::GetHitCoor
void GetHitCoor(const L1StsHit &_h, fscal &_x, fscal &_y, fscal &_z, const L1Station &sta)
--— Hit-point-strips conversion routines ---—
Definition: L1Algo.cxx:235
L1StsHit::f
TStripI f
Definition: L1StsHit.h:15
L1Grid::StoreHits
void StoreHits(THitI nhits, const L1StsHit *hits, char iS, L1Algo &Algo, THitI n, L1StsHit *hitsBuf1, const L1StsHit *hits1, THitI *indices1)
Definition: L1Grid.cxx:175
L1Grid.h