CMS 3D CMS Logo

HGCGraph.cc
Go to the documentation of this file.
1 // Author: Felice Pantaleo - felice.pantaleo@cern.ch
2 // Date: 11/2018
6 #include "HGCDoublet.h"
7 #include "HGCGraph.h"
9 
10 template <typename TILES>
12  const std::vector<TICLSeedingRegion> &regions,
13  int nEtaBins,
14  int nPhiBins,
15  const std::vector<reco::CaloCluster> &layerClusters,
16  const std::vector<float> &mask,
17  const edm::ValueMap<std::pair<float, float>> &layerClustersTime,
18  int deltaIEta,
19  int deltaIPhi,
20  float minCosTheta,
21  float minCosPointing,
24  int skip_layers,
25  int maxNumberOfLayers,
26  float maxDeltaTime) {
27  isOuterClusterOfDoublets_.clear();
28  isOuterClusterOfDoublets_.resize(layerClusters.size());
29  allDoublets_.clear();
30  theRootDoublets_.clear();
31  bool checkDistanceRootDoubletVsSeed = root_doublet_max_distance_from_seed_squared < 9999;
32  float origin_eta;
33  float origin_phi;
34  for (const auto &r : regions) {
35  bool isGlobal = (r.index == -1);
36  auto zSide = r.zSide;
37  int startEtaBin, endEtaBin, startPhiBin, endPhiBin;
38 
39  if (isGlobal) {
40  startEtaBin = 0;
41  startPhiBin = 0;
42  endEtaBin = nEtaBins;
43  endPhiBin = nPhiBins;
44  origin_eta = 0;
45  origin_phi = 0;
46  } else {
47  auto firstLayerOnZSide = maxNumberOfLayers * zSide;
48  const auto &firstLayerHisto = histo[firstLayerOnZSide];
49  origin_eta = r.origin.eta();
50  origin_phi = r.origin.phi();
51  int entryEtaBin = firstLayerHisto.etaBin(origin_eta);
52  int entryPhiBin = firstLayerHisto.phiBin(origin_phi);
53  // For track-seeded iterations, if the impact point is below a certain
54  // eta-threshold, i.e., it has higher eta, make the initial search
55  // window bigger in both eta and phi by one bin, to contain better low
56  // energy showers.
57  auto etaWindow = deltaIEta;
58  auto phiWindow = deltaIPhi;
59  if (std::abs(origin_eta) > etaLimitIncreaseWindow) {
60  etaWindow++;
61  phiWindow++;
62  LogDebug("HGCGraph") << "Limit of Eta for increase: " << etaLimitIncreaseWindow
63  << " reached! Increasing inner search window" << std::endl;
64  }
65  startEtaBin = std::max(entryEtaBin - etaWindow, 0);
66  endEtaBin = std::min(entryEtaBin + etaWindow + 1, nEtaBins);
67  startPhiBin = entryPhiBin - phiWindow;
68  endPhiBin = entryPhiBin + phiWindow + 1;
69  if (verbosity_ > Guru) {
70  LogDebug("HGCGraph") << " Entrance eta, phi: " << origin_eta << ", " << origin_phi
71  << " entryEtaBin: " << entryEtaBin << " entryPhiBin: " << entryPhiBin
72  << " globalBin: " << firstLayerHisto.globalBin(origin_eta, origin_phi)
73  << " on layer: " << firstLayerOnZSide << " startEtaBin: " << startEtaBin
74  << " endEtaBin: " << endEtaBin << " startPhiBin: " << startPhiBin
75  << " endPhiBin: " << endPhiBin << " phiBin(0): " << firstLayerHisto.phiBin(0.)
76  << " phiBin(" << M_PI / 2. << "): " << firstLayerHisto.phiBin(M_PI / 2.) << " phiBin("
77  << M_PI << "): " << firstLayerHisto.phiBin(M_PI) << " phiBin(" << -M_PI / 2.
78  << "): " << firstLayerHisto.phiBin(-M_PI / 2.) << " phiBin(" << -M_PI
79  << "): " << firstLayerHisto.phiBin(-M_PI) << " phiBin(" << 2. * M_PI
80  << "): " << firstLayerHisto.phiBin(2. * M_PI) << std::endl;
81  }
82  }
83 
84  for (int il = 0; il < maxNumberOfLayers - 1; ++il) {
85  for (int outer_layer = 0; outer_layer < std::min(1 + skip_layers, maxNumberOfLayers - 1 - il); ++outer_layer) {
86  int currentInnerLayerId = il + maxNumberOfLayers * zSide;
87  int currentOuterLayerId = currentInnerLayerId + 1 + outer_layer;
88  auto const &outerLayerHisto = histo[currentOuterLayerId];
89  auto const &innerLayerHisto = histo[currentInnerLayerId];
90  const int etaLimitIncreaseWindowBin = innerLayerHisto.etaBin(etaLimitIncreaseWindow);
91  if (verbosity_ > Advanced) {
92  LogDebug("HGCGraph") << "Limit of Eta for increase: " << etaLimitIncreaseWindow
93  << " at etaBin: " << etaLimitIncreaseWindowBin << std::endl;
94  }
95 
96  for (int ieta = startEtaBin; ieta < endEtaBin; ++ieta) {
97  auto offset = ieta * nPhiBins;
98  for (int iphi_it = startPhiBin; iphi_it < endPhiBin; ++iphi_it) {
99  int iphi = ((iphi_it % nPhiBins + nPhiBins) % nPhiBins);
100  if (verbosity_ > Guru) {
101  LogDebug("HGCGraph") << "Inner Global Bin: " << (offset + iphi)
102  << " on layers I/O: " << currentInnerLayerId << "/" << currentOuterLayerId
103  << " with clusters: " << innerLayerHisto[offset + iphi].size() << std::endl;
104  }
105  for (auto innerClusterId : innerLayerHisto[offset + iphi]) {
106  // Skip masked clusters
107  if (mask[innerClusterId] == 0.) {
108  if (verbosity_ > Advanced)
109  LogDebug("HGCGraph") << "Skipping inner masked cluster " << innerClusterId << std::endl;
110  continue;
111  }
112 
113  // For global-seeded iterations, if the inner cluster is above a certain
114  // eta-threshold, i.e., it has higher eta, make the outer search
115  // window bigger in both eta and phi by one bin, to contain better low
116  // energy showers. Track-Seeded iterations are excluded since, in
117  // that case, the inner search window has already been enlarged.
118  auto etaWindow = deltaIEta;
119  auto phiWindow = deltaIPhi;
120  if (isGlobal && ieta > etaLimitIncreaseWindowBin) {
121  etaWindow++;
122  phiWindow++;
123  if (verbosity_ > Advanced) {
124  LogDebug("HGCGraph") << "Eta and Phi window increased by one" << std::endl;
125  }
126  }
127  const auto etaRangeMin = std::max(0, ieta - etaWindow);
128  const auto etaRangeMax = std::min(ieta + etaWindow + 1, nEtaBins);
129 
130  for (int oeta = etaRangeMin; oeta < etaRangeMax; ++oeta) {
131  // wrap phi bin
132  for (int phiRange = 0; phiRange < 2 * phiWindow + 1; ++phiRange) {
133  // The first wrapping is to take into account the
134  // cases in which we would have to seach in
135  // negative bins. The second wrap is mandatory to
136  // account for all other cases, since we add in
137  // between a full nPhiBins slot.
138  auto ophi = ((iphi + phiRange - phiWindow) % nPhiBins + nPhiBins) % nPhiBins;
139  if (verbosity_ > Guru) {
140  LogDebug("HGCGraph") << "Outer Global Bin: " << (oeta * nPhiBins + ophi)
141  << " on layers I/O: " << currentInnerLayerId << "/" << currentOuterLayerId
142  << " with clusters: " << innerLayerHisto[oeta * nPhiBins + ophi].size()
143  << std::endl;
144  }
145  for (auto outerClusterId : outerLayerHisto[oeta * nPhiBins + ophi]) {
146  // Skip masked clusters
147  if (mask[outerClusterId] == 0.) {
148  if (verbosity_ > Advanced)
149  LogDebug("HGCGraph") << "Skipping outer masked cluster " << outerClusterId << std::endl;
150  continue;
151  }
152  auto doubletId = allDoublets_.size();
153  if (maxDeltaTime != -1 &&
154  !areTimeCompatible(innerClusterId, outerClusterId, layerClustersTime, maxDeltaTime)) {
155  if (verbosity_ > Advanced)
156  LogDebug("HGCGraph") << "Rejecting doublets due to timing!" << std::endl;
157  continue;
158  }
159  allDoublets_.emplace_back(innerClusterId, outerClusterId, doubletId, &layerClusters, r.index);
160  if (verbosity_ > Advanced) {
161  LogDebug("HGCGraph")
162  << "Creating doubletsId: " << doubletId << " layerLink in-out: [" << currentInnerLayerId
163  << ", " << currentOuterLayerId << "] clusterLink in-out: [" << innerClusterId << ", "
164  << outerClusterId << "]" << std::endl;
165  }
166  isOuterClusterOfDoublets_[outerClusterId].push_back(doubletId);
167  auto &neigDoublets = isOuterClusterOfDoublets_[innerClusterId];
168  auto &thisDoublet = allDoublets_[doubletId];
169  if (verbosity_ > Expert) {
170  LogDebug("HGCGraph")
171  << "Checking compatibility of doubletId: " << doubletId
172  << " with all possible inners doublets link by the innerClusterId: " << innerClusterId
173  << std::endl;
174  }
175  bool isRootDoublet = thisDoublet.checkCompatibilityAndTag(allDoublets_,
176  neigDoublets,
177  r.directionAtOrigin,
178  minCosTheta,
179  minCosPointing,
180  verbosity_ > Advanced);
181  if (isRootDoublet and checkDistanceRootDoubletVsSeed) {
182  auto dEtaSquared = (layerClusters[innerClusterId].eta() - origin_eta);
183  dEtaSquared *= dEtaSquared;
184  auto dPhiSquared = (layerClusters[innerClusterId].phi() - origin_phi);
185  dPhiSquared *= dPhiSquared;
186  if (dEtaSquared + dPhiSquared > root_doublet_max_distance_from_seed_squared)
187  isRootDoublet = false;
188  }
189  if (isRootDoublet) {
190  theRootDoublets_.push_back(doubletId);
191  }
192  }
193  }
194  }
195  }
196  }
197  }
198  }
199  }
200  }
201  // #ifdef FP_DEBUG
202  if (verbosity_ > None) {
203  LogDebug("HGCGraph") << "number of Root doublets " << theRootDoublets_.size() << " over a total number of doublets "
204  << allDoublets_.size() << std::endl;
205  }
206  // #endif
207 }
208 
209 template <typename TILES>
211  int outerIdx,
212  const edm::ValueMap<std::pair<float, float>> &layerClustersTime,
213  float maxDeltaTime) {
214  float timeIn = layerClustersTime.get(innerIdx).first;
215  float timeInE = layerClustersTime.get(innerIdx).second;
216  float timeOut = layerClustersTime.get(outerIdx).first;
217  float timeOutE = layerClustersTime.get(outerIdx).second;
218 
219  return (timeIn == -99. || timeOut == -99. ||
220  std::abs(timeIn - timeOut) < maxDeltaTime * sqrt(timeInE * timeInE + timeOutE * timeOutE));
221 }
222 
223 //also return a vector of seedIndex for the reconstructed tracksters
224 template <typename TILES>
225 void HGCGraphT<TILES>::findNtuplets(std::vector<HGCDoublet::HGCntuplet> &foundNtuplets,
226  std::vector<int> &seedIndices,
227  const unsigned int minClustersPerNtuplet,
228  const bool outInDFS,
229  unsigned int maxOutInHops) {
230  HGCDoublet::HGCntuplet tmpNtuplet;
231  tmpNtuplet.reserve(minClustersPerNtuplet);
232  std::vector<std::pair<unsigned int, unsigned int>> outInToVisit;
233  for (auto rootDoublet : theRootDoublets_) {
234  tmpNtuplet.clear();
235  outInToVisit.clear();
236  int seedIndex = allDoublets_[rootDoublet].seedIndex();
237  int outInHops = 0;
238  allDoublets_[rootDoublet].findNtuplets(
239  allDoublets_, tmpNtuplet, seedIndex, outInDFS, outInHops, maxOutInHops, outInToVisit);
240  while (!outInToVisit.empty()) {
241  allDoublets_[outInToVisit.back().first].findNtuplets(
242  allDoublets_, tmpNtuplet, seedIndex, outInDFS, outInToVisit.back().second, maxOutInHops, outInToVisit);
243  outInToVisit.pop_back();
244  }
245 
246  if (tmpNtuplet.size() > minClustersPerNtuplet) {
247  foundNtuplets.push_back(tmpNtuplet);
248  seedIndices.push_back(seedIndex);
249  }
250  }
251 }
252 
253 template class HGCGraphT<TICLLayerTiles>;
254 template class HGCGraphT<TICLLayerTilesHFNose>;
Common.h
MessageLogger.h
min
T min(T a, T b)
Definition: MathUtil.h:58
timingPdfMaker.histo
histo
Definition: timingPdfMaker.py:279
HGCGraphT::makeAndConnectDoublets
void makeAndConnectDoublets(const TILES &h, const std::vector< TICLSeedingRegion > &regions, 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)
Definition: HGCGraph.cc:11
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
HGCGraphT::findNtuplets
void findNtuplets(std::vector< HGCDoublet::HGCntuplet > &foundNtuplets, std::vector< int > &seedIndices, const unsigned int minClustersPerNtuplet, const bool outInDFS, const unsigned int maxOutInHops)
Definition: HGCGraph.cc:225
None
Definition: APVGainStruct.h:53
HGCDoublet::HGCntuplet
std::vector< unsigned int > HGCntuplet
Definition: HGCDoublet.h:16
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
HLTEgPhaseIITestSequence_cff.etaLimitIncreaseWindow
etaLimitIncreaseWindow
Definition: HLTEgPhaseIITestSequence_cff.py:2197
HLTEgPhaseIITestSequence_cff.layerClusters
layerClusters
Definition: HLTEgPhaseIITestSequence_cff.py:2506
trackingPOGFilters_cfi.phiWindow
phiWindow
Definition: trackingPOGFilters_cfi.py:109
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
HGCGraphT::areTimeCompatible
bool areTimeCompatible(int innerIdx, int outerIdx, const edm::ValueMap< std::pair< float, float >> &layerClustersTime, float maxDeltaTime)
Definition: HGCGraph.cc:210
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
HGCDoublet.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
HLTEgPhaseIITestSequence_cff.root_doublet_max_distance_from_seed_squared
root_doublet_max_distance_from_seed_squared
Definition: HLTEgPhaseIITestSequence_cff.py:2217
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
PatternRecognitionbyCA.h
muons_cff.isGlobal
isGlobal
Definition: muons_cff.py:149
alignCSCRings.r
r
Definition: alignCSCRings.py:93
ValueMap.h
HLTEgPhaseIITestSequence_cff.skip_layers
skip_layers
Definition: HLTEgPhaseIITestSequence_cff.py:2220
L1TMuonDQMOffline_cfi.nEtaBins
nEtaBins
Definition: L1TMuonDQMOffline_cfi.py:21
edm::ValueMap
Definition: ValueMap.h:107
HGCGraphT
Definition: HGCGraph.h:15
AlignmentPI::regions
regions
Definition: AlignmentPayloadInspectorHelper.h:76
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ecaldqm::binning::nPhiBins
Definition: MESetBinningUtils.h:69
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
HGCGraph.h
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443