11 template <
typename TILES>
13 const std::vector<TICLSeedingRegion> &
regions,
16 const std::vector<reco::CaloCluster> &layerClusters,
17 const std::vector<float> &mask,
18 const edm::ValueMap<std::pair<float, float>> &layerClustersTime,
23 float root_doublet_max_distance_from_seed_squared,
24 float etaLimitIncreaseWindow,
28 isOuterClusterOfDoublets_.clear();
29 isOuterClusterOfDoublets_.resize(layerClusters.size());
31 theRootDoublets_.clear();
32 bool checkDistanceRootDoubletVsSeed = root_doublet_max_distance_from_seed_squared < 9999;
35 for (
const auto &
r : regions) {
36 bool isGlobal = (
r.index == -1);
38 int startEtaBin, endEtaBin, startPhiBin, endPhiBin;
48 auto firstLayerOnZSide = maxNumberOfLayers * zSide;
49 const auto &firstLayerHisto = histo[firstLayerOnZSide];
50 origin_eta =
r.origin.eta();
51 origin_phi =
r.origin.phi();
52 int entryEtaBin = firstLayerHisto.etaBin(origin_eta);
53 int entryPhiBin = firstLayerHisto.phiBin(origin_phi);
58 auto etaWindow = deltaIEta;
59 auto phiWindow = deltaIPhi;
60 if (
std::abs(origin_eta) > etaLimitIncreaseWindow) {
63 LogDebug(
"HGCGraph") <<
"Limit of Eta for increase: " << etaLimitIncreaseWindow
64 <<
" reached! Increasing inner search window" << std::endl;
66 startEtaBin =
std::max(entryEtaBin - etaWindow, 0);
67 endEtaBin =
std::min(entryEtaBin + etaWindow + 1, nEtaBins);
68 startPhiBin = entryPhiBin - phiWindow;
69 endPhiBin = entryPhiBin + phiWindow + 1;
70 if (verbosity_ > Guru) {
71 LogDebug(
"HGCGraph") <<
" Entrance eta, phi: " << origin_eta <<
", " << origin_phi
72 <<
" entryEtaBin: " << entryEtaBin <<
" entryPhiBin: " << entryPhiBin
73 <<
" globalBin: " << firstLayerHisto.globalBin(origin_eta, origin_phi)
74 <<
" on layer: " << firstLayerOnZSide <<
" startEtaBin: " << startEtaBin
75 <<
" endEtaBin: " << endEtaBin <<
" startPhiBin: " << startPhiBin
76 <<
" endPhiBin: " << endPhiBin <<
" phiBin(0): " << firstLayerHisto.phiBin(0.)
77 <<
" phiBin(" <<
M_PI / 2. <<
"): " << firstLayerHisto.phiBin(
M_PI / 2.) <<
" phiBin("
78 <<
M_PI <<
"): " << firstLayerHisto.phiBin(
M_PI) <<
" phiBin(" << -
M_PI / 2.
79 <<
"): " << firstLayerHisto.phiBin(-
M_PI / 2.) <<
" phiBin(" << -
M_PI
80 <<
"): " << firstLayerHisto.phiBin(-
M_PI) <<
" phiBin(" << 2. *
M_PI
81 <<
"): " << firstLayerHisto.phiBin(2. *
M_PI) << std::endl;
85 for (
int il = 0; il < maxNumberOfLayers - 1; ++il) {
86 for (
int outer_layer = 0; outer_layer <
std::min(1 + skip_layers, maxNumberOfLayers - 1 - il); ++outer_layer) {
87 int currentInnerLayerId = il + maxNumberOfLayers * zSide;
88 int currentOuterLayerId = currentInnerLayerId + 1 + outer_layer;
89 auto const &outerLayerHisto = histo[currentOuterLayerId];
90 auto const &innerLayerHisto = histo[currentInnerLayerId];
91 const int etaLimitIncreaseWindowBin = innerLayerHisto.etaBin(etaLimitIncreaseWindow);
92 if (verbosity_ > Advanced) {
93 LogDebug(
"HGCGraph") <<
"Limit of Eta for increase: " << etaLimitIncreaseWindow
94 <<
" at etaBin: " << etaLimitIncreaseWindowBin << std::endl;
97 for (
int ieta = startEtaBin; ieta < endEtaBin; ++ieta) {
99 for (
int iphi_it = startPhiBin; iphi_it < endPhiBin; ++iphi_it) {
100 int iphi = ((iphi_it % nPhiBins +
nPhiBins) % nPhiBins);
101 if (verbosity_ > Guru) {
103 <<
" on layers I/O: " << currentInnerLayerId <<
"/" << currentOuterLayerId
104 <<
" with clusters: " << innerLayerHisto[
offset + iphi].
size() << std::endl;
106 for (
auto innerClusterId : innerLayerHisto[
offset + iphi]) {
108 if (mask[innerClusterId] == 0.) {
109 if (verbosity_ > Advanced)
110 LogDebug(
"HGCGraph") <<
"Skipping inner masked cluster " << innerClusterId << std::endl;
119 auto etaWindow = deltaIEta;
120 auto phiWindow = deltaIPhi;
121 if (isGlobal && ieta > etaLimitIncreaseWindowBin) {
124 if (verbosity_ > Advanced) {
125 LogDebug(
"HGCGraph") <<
"Eta and Phi window increased by one" << std::endl;
128 const auto etaRangeMin =
std::max(0, ieta - etaWindow);
129 const auto etaRangeMax =
std::min(ieta + etaWindow + 1, nEtaBins);
131 for (
int oeta = etaRangeMin; oeta < etaRangeMax; ++oeta) {
133 for (
int phiRange = 0; phiRange < 2 * phiWindow + 1; ++phiRange) {
139 auto ophi = ((iphi + phiRange - phiWindow) % nPhiBins + nPhiBins) %
nPhiBins;
140 if (verbosity_ > Guru) {
141 LogDebug(
"HGCGraph") <<
"Outer Global Bin: " << (oeta * nPhiBins + ophi)
142 <<
" on layers I/O: " << currentInnerLayerId <<
"/" << currentOuterLayerId
143 <<
" with clusters: " << innerLayerHisto[oeta * nPhiBins + ophi].
size()
146 for (
auto outerClusterId : outerLayerHisto[oeta * nPhiBins + ophi]) {
148 if (mask[outerClusterId] == 0.) {
149 if (verbosity_ > Advanced)
150 LogDebug(
"HGCGraph") <<
"Skipping outer masked cluster " << outerClusterId << std::endl;
153 auto doubletId = allDoublets_.size();
154 if (maxDeltaTime != -1 &&
155 !areTimeCompatible(innerClusterId, outerClusterId, layerClustersTime, maxDeltaTime)) {
156 if (verbosity_ > Advanced)
157 LogDebug(
"HGCGraph") <<
"Rejecting doublets due to timing!" << std::endl;
160 allDoublets_.emplace_back(innerClusterId, outerClusterId, doubletId, &layerClusters,
r.index);
161 if (verbosity_ > Advanced) {
163 <<
"Creating doubletsId: " << doubletId <<
" layerLink in-out: [" << currentInnerLayerId
164 <<
", " << currentOuterLayerId <<
"] clusterLink in-out: [" << innerClusterId <<
", "
165 << outerClusterId <<
"]" << std::endl;
167 isOuterClusterOfDoublets_[outerClusterId].push_back(doubletId);
168 auto &neigDoublets = isOuterClusterOfDoublets_[innerClusterId];
169 auto &thisDoublet = allDoublets_[doubletId];
170 if (verbosity_ > Expert) {
172 <<
"Checking compatibility of doubletId: " << doubletId
173 <<
" with all possible inners doublets link by the innerClusterId: " << innerClusterId
176 bool isRootDoublet = thisDoublet.checkCompatibilityAndTag(allDoublets_,
181 verbosity_ > Advanced);
182 if (isRootDoublet and checkDistanceRootDoubletVsSeed) {
184 layerClusters[innerClusterId].
phi(),
186 origin_phi) > root_doublet_max_distance_from_seed_squared) {
187 isRootDoublet =
false;
191 theRootDoublets_.push_back(doubletId);
203 if (verbosity_ >
None) {
204 LogDebug(
"HGCGraph") <<
"number of Root doublets " << theRootDoublets_.size() <<
" over a total number of doublets "
205 << allDoublets_.size() << std::endl;
210 template <
typename TILES>
213 const edm::ValueMap<std::pair<float, float>> &layerClustersTime,
214 float maxDeltaTime) {
215 float timeIn = layerClustersTime.get(innerIdx).first;
216 float timeInE = layerClustersTime.get(innerIdx).second;
217 float timeOut = layerClustersTime.get(outerIdx).first;
218 float timeOutE = layerClustersTime.get(outerIdx).second;
220 return (timeIn == -99. || timeOut == -99. ||
221 std::abs(timeIn - timeOut) < maxDeltaTime *
sqrt(timeInE * timeInE + timeOutE * timeOutE));
225 template <
typename TILES>
227 std::vector<int> &seedIndices,
228 const unsigned int minClustersPerNtuplet,
230 unsigned int maxOutInHops) {
232 tmpNtuplet.reserve(minClustersPerNtuplet);
233 std::vector<std::pair<unsigned int, unsigned int>> outInToVisit;
234 for (
auto rootDoublet : theRootDoublets_) {
236 outInToVisit.clear();
237 int seedIndex = allDoublets_[rootDoublet].seedIndex();
239 allDoublets_[rootDoublet].findNtuplets(
240 allDoublets_, tmpNtuplet, seedIndex, outInDFS, outInHops, maxOutInHops, outInToVisit);
241 while (!outInToVisit.empty()) {
242 allDoublets_[outInToVisit.back().first].findNtuplets(
243 allDoublets_, tmpNtuplet, seedIndex, outInDFS, outInToVisit.back().second, maxOutInHops, outInToVisit);
244 outInToVisit.pop_back();
247 if (tmpNtuplet.size() > minClustersPerNtuplet) {
248 foundNtuplets.push_back(tmpNtuplet);
249 seedIndices.push_back(seedIndex);
std::vector< unsigned int > HGCntuplet
auto const & foundNtuplets
constexpr uint32_t maxNumberOfLayers
Abs< T >::type abs(const T &t)
bool areTimeCompatible(int innerIdx, int outerIdx, const edm::ValueMap< std::pair< float, float >> &layerClustersTime, float maxDeltaTime)
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
void makeAndConnectDoublets(const TILES &h, const std::vector< TICLSeedingRegion > ®ions, int nEtaBins, int nPhiBins, const std::vector< reco::CaloCluster > &layerClusters, const std::vector< float > &mask, const edm::ValueMap< std::pair< float, float >> &layerClustersTime, int deltaIEta, int deltaIPhi, float minCosThetai, float maxCosPointing, float root_doublet_max_distance_from_seed_squared, float etaLimitIncreaseWindow, int skip_layers, int maxNumberOfLayers, float maxDeltaTime)
void findNtuplets(std::vector< HGCDoublet::HGCntuplet > &foundNtuplets, std::vector< int > &seedIndices, const unsigned int minClustersPerNtuplet, const bool outInDFS, const unsigned int maxOutInHops)
tuple size
Write out results.