-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
420 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
RecoLocalCalo/HGCalRecProducers/interface/HGCalLayerTiles.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Authors: Felice Pantaleo - [email protected] | ||
// Date: 03/2019 | ||
// Copyright CERN | ||
|
||
#ifndef RecoLocalCalo_HGCalRecAlgos_HGCalLayerTiles | ||
#define RecoLocalCalo_HGCalRecAlgos_HGCalLayerTiles | ||
|
||
#include "RecoLocalCalo/HGCalRecProducers/interface/HGCalTilesConstants.h" | ||
|
||
#include <vector> | ||
#include <array> | ||
#include <cmath> | ||
#include <algorithm> | ||
#include <cassert> | ||
|
||
class HGCalLayerTiles { | ||
public: | ||
|
||
void fill(const std::vector<float>& x, const std::vector<float>& y) { | ||
auto cellsSize = x.size(); | ||
for (unsigned int i = 0; i < cellsSize; ++i) { | ||
tiles_[getGlobalBin(x[i], y[i])].push_back(i); | ||
} | ||
} | ||
|
||
int getXBin(float x) const { | ||
constexpr float xRange = hgcaltilesconstants::maxX - hgcaltilesconstants::minX; | ||
static_assert(xRange >= 0.); | ||
constexpr float r = hgcaltilesconstants::nColumns / xRange; | ||
int xBin = (x - hgcaltilesconstants::minX) * r; | ||
xBin = std::clamp(xBin, 0, hgcaltilesconstants::nColumns); | ||
return xBin; | ||
} | ||
|
||
int getYBin(float y) const { | ||
constexpr float yRange = hgcaltilesconstants::maxY - hgcaltilesconstants::minY; | ||
static_assert(yRange >= 0.); | ||
constexpr float r = hgcaltilesconstants::nRows / yRange; | ||
int yBin = (y - hgcaltilesconstants::minY) * r; | ||
yBin = std::clamp(yBin, 0, hgcaltilesconstants::nRows); | ||
return yBin; | ||
} | ||
|
||
int getGlobalBin(float x, float y) const { return getXBin(x) + getYBin(y) * hgcaltilesconstants::nColumns; } | ||
|
||
int getGlobalBinByBin(int xBin, int yBin) const { return xBin + yBin * hgcaltilesconstants::nColumns; } | ||
|
||
std::array<int, 4> searchBox(float xMin, float xMax, float yMin, float yMax) const { | ||
int xBinMin = getXBin(xMin); | ||
int xBinMax = getXBin(xMax); | ||
int yBinMin = getYBin(yMin); | ||
int yBinMax = getYBin(yMax); | ||
return std::array<int, 4>({{xBinMin, xBinMax, yBinMin, yBinMax}}); | ||
} | ||
|
||
void clear() { | ||
for (auto& t : tiles_) | ||
t.clear(); | ||
} | ||
|
||
const std::vector<int>& operator[](int globalBinId) const { return tiles_[globalBinId]; } | ||
|
||
private: | ||
std::array<std::vector<int>, hgcaltilesconstants::nColumns * hgcaltilesconstants::nRows > tiles_; | ||
}; | ||
|
||
#endif |
28 changes: 28 additions & 0 deletions
28
RecoLocalCalo/HGCalRecProducers/interface/HGCalTilesConstants.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Authors: Felice Pantaleo - [email protected] | ||
// Date: 03/2019 | ||
// Copyright CERN | ||
|
||
#ifndef RecoLocalCalo_HGCalRecAlgos_interface_HGCalTilesConstants_h | ||
#define RecoLocalCalo_HGCalRecAlgos_interface_HGCalTilesConstants_h | ||
|
||
#include <cstdint> | ||
#include <array> | ||
|
||
namespace hgcaltilesconstants { | ||
|
||
constexpr int32_t ceil(float num) { | ||
return (static_cast<float>(static_cast<int32_t>(num)) == num) ? static_cast<int32_t>(num) | ||
: static_cast<int32_t>(num) + ((num > 0) ? 1 : 0); | ||
} | ||
|
||
constexpr float minX = -285.f; | ||
constexpr float maxX = 285.f; | ||
constexpr float minY = -285.f; | ||
constexpr float maxY = 285.f; | ||
constexpr float tileSize = 5.f; | ||
constexpr int nColumns = hgcaltilesconstants::ceil((maxX - minX) / tileSize); | ||
constexpr int nRows = hgcaltilesconstants::ceil((maxY - minY) / tileSize); | ||
|
||
} // namespace hgcaltilesconstants | ||
|
||
#endif // RecoLocalCalo_HGCalRecAlgos_interface_HGCalTilesConstants_h |
Oops, something went wrong.