CMS 3D CMS Logo

HGCalMulticlusteringImpl.cc
Go to the documentation of this file.
4 
6  : dr_(conf.getParameter<double>("dR_multicluster")),
7  ptC3dThreshold_(conf.getParameter<double>("minPt_multicluster")),
8  multiclusterAlgoType_(conf.getParameter<string>("type_multicluster")),
9  distDbscan_(conf.getParameter<double>("dist_dbscan_multicluster")),
10  minNDbscan_(conf.getParameter<unsigned>("minN_dbscan_multicluster")) {
11  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster dR for Near Neighbour search: " << dr_;
12  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster minimum transverse-momentum: " << ptC3dThreshold_;
13  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster DBSCAN Clustering distance: " << distDbscan_;
14  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster clustering min number of subclusters: " << minNDbscan_;
15  edm::LogInfo("HGCalMulticlusterParameters")
16  << "Multicluster type of multiclustering algortihm: " << multiclusterAlgoType_;
17  id_ = std::unique_ptr<HGCalTriggerClusterIdentificationBase>{
18  HGCalTriggerClusterIdentificationFactory::get()->create("HGCalTriggerClusterIdentificationBDT")};
19  id_->initialize(conf.getParameter<edm::ParameterSet>("EGIdentification"));
20 }
21 
23  const l1t::HGCalMulticluster& mclu,
24  double dR) const {
25  DetId cluDetId(clu.detId());
26  DetId firstClusterDetId(mclu.detId());
27 
28  if (triggerTools_.zside(cluDetId) != triggerTools_.zside(firstClusterDetId)) {
29  return false;
30  }
31  if ((mclu.centreProj() - clu.centreProj()).mag() < dR) {
32  return true;
33  }
34  return false;
35 }
36 
37 void HGCalMulticlusteringImpl::findNeighbor(const std::vector<std::pair<unsigned int, double>>& rankedList,
38  unsigned int searchInd,
39  const std::vector<edm::Ptr<l1t::HGCalCluster>>& clustersPtrs,
40  std::vector<unsigned int>& neighbors) {
41  if (clustersPtrs.size() <= searchInd || clustersPtrs.size() < rankedList.size()) {
42  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
43  }
44 
45  for (unsigned int ind = searchInd + 1;
46  ind < rankedList.size() && fabs(rankedList.at(ind).second - rankedList.at(searchInd).second) < distDbscan_;
47  ind++) {
48  if (clustersPtrs.size() <= rankedList.at(ind).first) {
49  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
50 
51  } else if (((*(clustersPtrs[rankedList.at(ind).first])).centreProj() -
52  (*(clustersPtrs[rankedList.at(searchInd).first])).centreProj())
53  .mag() < distDbscan_) {
54  neighbors.push_back(ind);
55  }
56  }
57 
58  for (unsigned int ind = 0;
59  ind < searchInd && fabs(rankedList.at(searchInd).second - rankedList.at(ind).second) < distDbscan_;
60  ind++) {
61  if (clustersPtrs.size() <= rankedList.at(ind).first) {
62  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
63 
64  } else if (((*(clustersPtrs[rankedList.at(ind).first])).centreProj() -
65  (*(clustersPtrs[rankedList.at(searchInd).first])).centreProj())
66  .mag() < distDbscan_) {
67  neighbors.push_back(ind);
68  }
69  }
70 }
71 
74  const HGCalTriggerGeometryBase& triggerGeometry) {
75  std::vector<l1t::HGCalMulticluster> multiclustersTmp;
76 
77  int iclu = 0;
78  for (std::vector<edm::Ptr<l1t::HGCalCluster>>::const_iterator clu = clustersPtrs.begin(); clu != clustersPtrs.end();
79  ++clu, ++iclu) {
80  double minDist = dr_;
81  int targetMulticlu = -1;
82 
83  for (unsigned imclu = 0; imclu < multiclustersTmp.size(); imclu++) {
84  if (!this->isPertinent(**clu, multiclustersTmp.at(imclu), dr_))
85  continue;
86 
87  double d = (multiclustersTmp.at(imclu).centreProj() - (*clu)->centreProj()).mag();
88  if (d < minDist) {
89  minDist = d;
90  targetMulticlu = int(imclu);
91  }
92  }
93 
94  if (targetMulticlu < 0)
95  multiclustersTmp.emplace_back(*clu);
96  else
97  multiclustersTmp.at(targetMulticlu).addConstituent(*clu);
98  }
99 
100  /* making the collection of multiclusters */
101  finalizeClusters(multiclustersTmp, multiclusters, triggerGeometry);
102 }
104  l1t::HGCalMulticlusterBxCollection& multiclusters,
105  const HGCalTriggerGeometryBase& triggerGeometry) {
106  std::vector<l1t::HGCalMulticluster> multiclustersTmp;
107  l1t::HGCalMulticluster mcluTmp;
108  std::vector<bool> visited(clustersPtrs.size(), false);
109  std::vector<bool> merged(clustersPtrs.size(), false);
110  std::vector<std::pair<unsigned int, double>> rankedList;
111  rankedList.reserve(clustersPtrs.size());
112  std::vector<std::vector<unsigned int>> neighborList;
113  neighborList.reserve(clustersPtrs.size());
114 
115  int iclu = 0, imclu = 0, neighNo;
116  double dist = 0.;
117 
118  for (std::vector<edm::Ptr<l1t::HGCalCluster>>::const_iterator clu = clustersPtrs.begin(); clu != clustersPtrs.end();
119  ++clu, ++iclu) {
120  dist = (*clu)->centreProj().mag() * triggerTools_.zside((*clu)->detId());
121  rankedList.push_back(std::make_pair(iclu, dist));
122  }
123  iclu = 0;
124  std::sort(rankedList.begin(), rankedList.end(), [](auto& left, auto& right) { return left.second < right.second; });
125 
126  for (const auto& cluRanked : rankedList) {
127  std::vector<unsigned int> neighbors;
128 
129  if (!visited.at(iclu)) {
130  visited.at(iclu) = true;
131  findNeighbor(rankedList, iclu, clustersPtrs, neighbors);
132  neighborList.push_back(std::move(neighbors));
133 
134  if (neighborList.at(iclu).size() >= minNDbscan_) {
135  multiclustersTmp.emplace_back(clustersPtrs[cluRanked.first]);
136  merged.at(iclu) = true;
137  /* dynamic range loop: range-based loop syntax cannot be employed */
138  for (unsigned int neighInd = 0; neighInd < neighborList.at(iclu).size(); neighInd++) {
139  neighNo = neighborList.at(iclu).at(neighInd);
140  /* This condition also ensures merging of clusters visited by other clusters but not merged. */
141  if (!merged.at(neighNo)) {
142  merged.at(neighNo) = true;
143  multiclustersTmp.at(imclu).addConstituent(clustersPtrs[rankedList.at(neighNo).first]);
144 
145  if (!visited.at(neighNo)) {
146  visited.at(neighNo) = true;
147  std::vector<unsigned int> secNeighbors;
148  findNeighbor(rankedList, neighNo, clustersPtrs, secNeighbors);
149 
150  if (secNeighbors.size() >= minNDbscan_) {
151  neighborList.at(iclu).insert(neighborList.at(iclu).end(), secNeighbors.begin(), secNeighbors.end());
152  }
153  }
154  }
155  }
156  imclu++;
157  }
158  } else
159  neighborList.push_back(std::move(neighbors));
160  iclu++;
161  }
162  /* making the collection of multiclusters */
163  finalizeClusters(multiclustersTmp, multiclusters, triggerGeometry);
164 }
165 
166 void HGCalMulticlusteringImpl::finalizeClusters(std::vector<l1t::HGCalMulticluster>& multiclusters_in,
167  l1t::HGCalMulticlusterBxCollection& multiclusters_out,
168  const HGCalTriggerGeometryBase& triggerGeometry) {
169  for (auto& multicluster : multiclusters_in) {
170  // compute the eta, phi from its barycenter
171  // + pT as scalar sum of pT of constituents
172  double sumPt = 0.;
173  const std::unordered_map<uint32_t, edm::Ptr<l1t::HGCalCluster>>& clusters = multicluster.constituents();
174  for (const auto& id_cluster : clusters)
175  sumPt += id_cluster.second->pt();
176 
177  math::PtEtaPhiMLorentzVector multiclusterP4(sumPt, multicluster.centre().eta(), multicluster.centre().phi(), 0.);
178  multicluster.setP4(multiclusterP4);
179 
180  if (multicluster.pt() > ptC3dThreshold_) {
181  //compute shower shapes
182  shape_.fillShapes(multicluster, triggerGeometry);
183  // fill quality flag
184  multicluster.setHwQual(id_->decision(multicluster));
185  // fill H/E
186  multicluster.saveHOverE();
187 
188  multiclusters_out.push_back(0, multicluster);
189  }
190  }
191 }
HGCalTriggerGeometryBase
Definition: HGCalTriggerGeometryBase.h:19
HGCalShowerShape::fillShapes
void fillShapes(l1t::HGCalMulticluster &, const HGCalTriggerGeometryBase &) const
Definition: HGCalShowerShape.cc:515
l1t::HGCalCluster
Definition: HGCalCluster.h:11
HGCalMulticlusteringImpl::findNeighbor
void findNeighbor(const std::vector< std::pair< unsigned int, double >> &rankedList, unsigned int searchInd, const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, std::vector< unsigned int > &neigbors)
Definition: HGCalMulticlusteringImpl.cc:37
HGCalMulticlusteringImpl::clusterizeDBSCAN
void clusterizeDBSCAN(const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, l1t::HGCalMulticlusterBxCollection &multiclusters, const HGCalTriggerGeometryBase &triggerGeometry)
Definition: HGCalMulticlusteringImpl.cc:103
HGCalMulticlusteringImpl::id_
std::unique_ptr< HGCalTriggerClusterIdentificationBase > id_
Definition: HGCalMulticlusteringImpl.h:50
HGCalMulticlusteringImpl.h
edm::LogInfo
Definition: MessageLogger.h:254
HGCalMulticlusteringImpl::shape_
HGCalShowerShape shape_
Definition: HGCalMulticlusteringImpl.h:48
HGCalShowerShape.h
HGCalMulticlusteringImpl::HGCalMulticlusteringImpl
HGCalMulticlusteringImpl(const edm::ParameterSet &conf)
Definition: HGCalMulticlusteringImpl.cc:5
TtFullHadEvtBuilder_cfi.sumPt
sumPt
Definition: TtFullHadEvtBuilder_cfi.py:38
deltaR.h
l1t::HGCalClusterT::detId
uint32_t detId() const
Definition: HGCalClusterT.h:94
BXVector
Definition: BXVector.h:15
DetId
Definition: DetId.h:17
l1t::HGCalMulticluster
Definition: HGCalMulticluster.h:13
HGCalTriggerTools::zside
int zside(const DetId &) const
Definition: HGCalTriggerTools.cc:210
class-composition.visited
visited
Definition: class-composition.py:74
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
HGCalMulticlusteringImpl::clusterizeDR
void clusterizeDR(const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, l1t::HGCalMulticlusterBxCollection &multiclusters, const HGCalTriggerGeometryBase &triggerGeometry)
Definition: HGCalMulticlusteringImpl.cc:72
edm::ParameterSet
Definition: ParameterSet.h:36
HGCalMulticlusteringImpl::isPertinent
bool isPertinent(const l1t::HGCalCluster &clu, const l1t::HGCalMulticluster &mclu, double dR) const
Definition: HGCalMulticlusteringImpl.cc:22
createfilelist.int
int
Definition: createfilelist.py:10
HGCalMulticlusteringImpl::multiclusterAlgoType_
std::string multiclusterAlgoType_
Definition: HGCalMulticlusteringImpl.h:44
HGCalMulticlusteringImpl::dr_
double dr_
Definition: HGCalMulticlusteringImpl.h:42
get
#define get
HGCalMulticlusteringImpl::triggerTools_
HGCalTriggerTools triggerTools_
Definition: HGCalMulticlusteringImpl.h:49
edm::Ptr
Definition: AssociationVector.h:31
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
mag
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Definition: Basic3DVectorLD.h:127
eostools.move
def move(src, dest)
Definition: eostools.py:511
HGCalMulticlusteringImpl::distDbscan_
double distDbscan_
Definition: HGCalMulticlusteringImpl.h:45
Exception
Definition: hltDiff.cc:246
l1t::HGCalClusterT::centreProj
const GlobalPoint & centreProj() const
Definition: HGCalClusterT.h:103
ztail.d
d
Definition: ztail.py:151
HGCalMulticlusteringImpl::ptC3dThreshold_
double ptC3dThreshold_
Definition: HGCalMulticlusteringImpl.h:43
math::PtEtaPhiMLorentzVector
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
HGCalMulticlusteringImpl::minNDbscan_
unsigned minNDbscan_
Definition: HGCalMulticlusteringImpl.h:46
BXVector::push_back
void push_back(int bx, T object)
HGCalMulticlusteringImpl::finalizeClusters
void finalizeClusters(std::vector< l1t::HGCalMulticluster > &, l1t::HGCalMulticlusterBxCollection &, const HGCalTriggerGeometryBase &)
Definition: HGCalMulticlusteringImpl.cc:166