CMS 3D CMS Logo

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