Skip to content

Commit

Permalink
Full workflow from raw data to pixel tracks and vertices on GPUs (#216)
Browse files Browse the repository at this point in the history
Port and optimise the full workflow from pixel raw data to pixel tracks and vertices to GPUs.
Clean the pixel n-tuplets with the "fishbone" algorithm (only on GPUs).

Other changes:
  - recover the Riemann fit updates lost during the merge with CMSSW 10.4.x;
  - speed up clustering and track fitting;
  - minor bug fix to avoid trivial regression with the optimized fit.
  • Loading branch information
VinInn authored and fwyzard committed Dec 29, 2020
1 parent fbdfdb0 commit 27bbcdd
Show file tree
Hide file tree
Showing 8 changed files with 366 additions and 161 deletions.
61 changes: 61 additions & 0 deletions Geometry/TrackerGeometryBuilder/interface/phase1PixelTopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define Geometry_TrackerGeometryBuilder_phase1PixelTopology_h

#include <cstdint>
#include <array>

namespace phase1PixelTopology {

Expand Down Expand Up @@ -29,6 +30,66 @@ namespace phase1PixelTopology {
};


template<class Function, std::size_t... Indices>
constexpr auto map_to_array_helper(Function f, std::index_sequence<Indices...>)
-> std::array<typename std::result_of<Function(std::size_t)>::type, sizeof...(Indices)>
{
return {{ f(Indices)... }};
}

template<int N, class Function>
constexpr auto map_to_array(Function f)
-> std::array<typename std::result_of<Function(std::size_t)>::type, N>
{
return map_to_array_helper(f, std::make_index_sequence<N>{});
}


constexpr uint32_t findMaxModuleStride() {
bool go = true;
int n=2;
while (go) {
for (uint8_t i=1; i<11; ++i) {
if (layerStart[i]%n !=0) {go=false; break;}
}
if(!go) break;
n*=2;
}
return n/2;
}

constexpr uint32_t maxModuleStride = findMaxModuleStride();


constexpr uint8_t findLayer(uint32_t detId) {
for (uint8_t i=0; i<11; ++i) if (detId<layerStart[i+1]) return i;
return 11;
}

constexpr uint8_t findLayerFromCompact(uint32_t detId) {
detId*=maxModuleStride;
for (uint8_t i=0; i<11; ++i) if (detId<layerStart[i+1]) return i;
return 11;
}


constexpr uint32_t layerIndexSize = numberOfModules/maxModuleStride;
constexpr std::array<uint8_t,layerIndexSize> layer = map_to_array<layerIndexSize>(findLayerFromCompact);

constexpr bool validateLayerIndex() {
bool res=true;
for (auto i=0U; i<numberOfModules; ++i) {
auto j = i/maxModuleStride;
res &=(layer[j]<10);
res &=(i>=layerStart[layer[j]]);
res &=(i<layerStart[layer[j]+1]);
}
return res;
}

static_assert(validateLayerIndex(),"layer from detIndex algo is buggy");


// this is for the ROC n<512 (upgrade 1024)
constexpr inline
uint16_t divu52(uint16_t n) {
Expand Down
231 changes: 119 additions & 112 deletions Geometry/TrackerGeometryBuilder/test/phase1PixelTopology_t.cpp
Original file line number Diff line number Diff line change
@@ -1,128 +1,128 @@
#include <cassert>
#include <iostream>
#include <tuple>

#include "Geometry/TrackerGeometryBuilder/interface/phase1PixelTopology.h"
#include<cassert>
#include<tuple>

namespace {

// original code from CMSSW_4_4

std::tuple<int,bool> localXori(int mpx) {
const float m_pitchx=1.f;
int binoffx = int(mpx); // truncate to int
float local_pitchx = m_pitchx; // defaultpitch

if (binoffx>80) { // ROC 1 - handles x on edge cluster
binoffx=binoffx+2;
} else if (binoffx==80) { // ROC 1
binoffx=binoffx+1;
local_pitchx = 2 * m_pitchx;

} else if (binoffx==79) { // ROC 0
binoffx=binoffx+0;
local_pitchx = 2 * m_pitchx;
} else if (binoffx>=0) { // ROC 0
binoffx=binoffx+0;

} else { // too small
assert("binoffx too small"==0);
}

return std::make_tuple(binoffx,local_pitchx>m_pitchx);
}
const float m_pitchx=1.f;
int binoffx = int(mpx); // truncate to int
float local_pitchx = m_pitchx; // defaultpitch

if (binoffx>80) { // ROC 1 - handles x on edge cluster
binoffx=binoffx+2;
} else if (binoffx==80) { // ROC 1
binoffx=binoffx+1;
local_pitchx = 2 * m_pitchx;

} else if (binoffx==79) { // ROC 0
binoffx=binoffx+0;
local_pitchx = 2 * m_pitchx;
} else if (binoffx>=0) { // ROC 0
binoffx=binoffx+0;

} else { // too small
assert("binoffx too small"==0);
}

return std::make_tuple(binoffx,local_pitchx>m_pitchx);
}

std::tuple<int,bool> localYori(int mpy) {
const float m_pitchy=1.f;
int binoffy = int(mpy); // truncate to int
float local_pitchy = m_pitchy; // defaultpitch
if (binoffy>416) { // ROC 8, not real ROC
binoffy=binoffy+17;
} else if (binoffy==416) { // ROC 8
binoffy=binoffy+16;
local_pitchy = 2 * m_pitchy;
} else if (binoffy==415) { // ROC 7, last big pixel
binoffy=binoffy+15;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>364) { // ROC 7
binoffy=binoffy+15;
} else if (binoffy==364) { // ROC 7
binoffy=binoffy+14;
local_pitchy = 2 * m_pitchy;
} else if (binoffy==363) { // ROC 6
binoffy=binoffy+13;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>312) { // ROC 6
binoffy=binoffy+13;
} else if (binoffy==312) { // ROC 6
binoffy=binoffy+12;
local_pitchy = 2 * m_pitchy;
} else if (binoffy==311) { // ROC 5
binoffy=binoffy+11;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>260) { // ROC 5
binoffy=binoffy+11;
} else if (binoffy==260) { // ROC 5
binoffy=binoffy+10;
local_pitchy = 2 * m_pitchy;
} else if (binoffy==259) { // ROC 4
binoffy=binoffy+9;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>208) { // ROC 4
binoffy=binoffy+9;
} else if (binoffy==208) { // ROC 4
binoffy=binoffy+8;
local_pitchy = 2 * m_pitchy;
} else if (binoffy==207) { // ROC 3
binoffy=binoffy+7;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>156) { // ROC 3
binoffy=binoffy+7;
} else if (binoffy==156) { // ROC 3
binoffy=binoffy+6;
local_pitchy = 2 * m_pitchy;
} else if (binoffy==155) { // ROC 2
binoffy=binoffy+5;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>104) { // ROC 2
binoffy=binoffy+5;
} else if (binoffy==104) { // ROC 2
binoffy=binoffy+4;
local_pitchy = 2 * m_pitchy;
} else if (binoffy==103) { // ROC 1
binoffy=binoffy+3;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>52) { // ROC 1
binoffy=binoffy+3;
} else if (binoffy==52) { // ROC 1
binoffy=binoffy+2;
local_pitchy = 2 * m_pitchy;
} else if (binoffy==51) { // ROC 0
binoffy=binoffy+1;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>0) { // ROC 0
binoffy=binoffy+1;
} else if (binoffy==0) { // ROC 0
binoffy=binoffy+0;
local_pitchy = 2 * m_pitchy;
} else {
assert("binoffy too small"==0);
}

return std::make_tuple(binoffy,local_pitchy>m_pitchy);
}
const float m_pitchy=1.f;
int binoffy = int(mpy); // truncate to int
float local_pitchy = m_pitchy; // defaultpitch

if (binoffy>416) { // ROC 8, not real ROC
binoffy=binoffy+17;
} else if (binoffy==416) { // ROC 8
binoffy=binoffy+16;
local_pitchy = 2 * m_pitchy;

} else if (binoffy==415) { // ROC 7, last big pixel
binoffy=binoffy+15;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>364) { // ROC 7
binoffy=binoffy+15;
} else if (binoffy==364) { // ROC 7
binoffy=binoffy+14;
local_pitchy = 2 * m_pitchy;

} else if (binoffy==363) { // ROC 6
binoffy=binoffy+13;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>312) { // ROC 6
binoffy=binoffy+13;
} else if (binoffy==312) { // ROC 6
binoffy=binoffy+12;
local_pitchy = 2 * m_pitchy;

} else if (binoffy==311) { // ROC 5
binoffy=binoffy+11;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>260) { // ROC 5
binoffy=binoffy+11;
} else if (binoffy==260) { // ROC 5
binoffy=binoffy+10;
local_pitchy = 2 * m_pitchy;

} else if (binoffy==259) { // ROC 4
binoffy=binoffy+9;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>208) { // ROC 4
binoffy=binoffy+9;
} else if (binoffy==208) { // ROC 4
binoffy=binoffy+8;
local_pitchy = 2 * m_pitchy;

} else if (binoffy==207) { // ROC 3
binoffy=binoffy+7;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>156) { // ROC 3
binoffy=binoffy+7;
} else if (binoffy==156) { // ROC 3
binoffy=binoffy+6;
local_pitchy = 2 * m_pitchy;

} else if (binoffy==155) { // ROC 2
binoffy=binoffy+5;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>104) { // ROC 2
binoffy=binoffy+5;
} else if (binoffy==104) { // ROC 2
binoffy=binoffy+4;
local_pitchy = 2 * m_pitchy;

} else if (binoffy==103) { // ROC 1
binoffy=binoffy+3;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>52) { // ROC 1
binoffy=binoffy+3;
} else if (binoffy==52) { // ROC 1
binoffy=binoffy+2;
local_pitchy = 2 * m_pitchy;

} else if (binoffy==51) { // ROC 0
binoffy=binoffy+1;
local_pitchy = 2 * m_pitchy;
} else if (binoffy>0) { // ROC 0
binoffy=binoffy+1;
} else if (binoffy==0) { // ROC 0
binoffy=binoffy+0;
local_pitchy = 2 * m_pitchy;
} else {
assert("binoffy too small"==0);
}

return std::make_tuple(binoffy,local_pitchy>m_pitchy);
}

}

#include<iostream>
int main() {

for (uint16_t ix=0; ix<80*2; ++ix) {
Expand All @@ -141,6 +141,13 @@ int main() {
assert(std::get<1>(ori)==bp);
}

using namespace phase1PixelTopology;
for (auto i=0U; i<numberOfModules; ++i) {
assert(layer[i]<10);
assert(i>=layerStart[layer[i]]);
assert(i<layerStart[layer[i]+1]);
}


return 0;
}
Loading

0 comments on commit 27bbcdd

Please sign in to comment.