CMS 3D CMS Logo

HGCalMulticlusteringImpl.cc
Go to the documentation of this file.
1 
2 
6 
7 
9  dr_(conf.getParameter<double>("dR_multicluster")),
10  ptC3dThreshold_(conf.getParameter<double>("minPt_multicluster")),
11  multiclusterAlgoType_(conf.getParameter<string>("type_multicluster")),
12  distDbscan_(conf.getParameter<double>("dist_dbscan_multicluster")),
13  minNDbscan_(conf.getParameter<unsigned>("minN_dbscan_multicluster"))
14 {
15  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster dR for Near Neighbour search: " << dr_;
16  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster minimum transverse-momentum: " << ptC3dThreshold_;
17  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster DBSCAN Clustering distance: " << distDbscan_;
18  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster clustering min number of subclusters: " << minNDbscan_;
19  edm::LogInfo("HGCalMulticlusterParameters") << "Multicluster type of multiclustering algortihm: " << multiclusterAlgoType_;
20 }
21 
22 
24  const l1t::HGCalMulticluster & mclu,
25  double dR ) const
26 {
27  HGCalDetId cluDetId( clu.detId() );
28  HGCalDetId firstClusterDetId( mclu.detId() );
29 
30  if( cluDetId.zside() != firstClusterDetId.zside() ){
31  return false;
32  }
33  if( ( mclu.centreProj() - clu.centreProj() ).mag() < dR ){
34  return true;
35  }
36  return false;
37 
38 }
39 
40 
41 void HGCalMulticlusteringImpl::findNeighbor( const std::vector<std::pair<unsigned int,double>>& rankedList,
42  unsigned int searchInd,
43  const std::vector<edm::Ptr<l1t::HGCalCluster>>& clustersPtrs,
44  std::vector<unsigned int>& neighbors
45  ){
46 
47  if(clustersPtrs.size() <= searchInd || clustersPtrs.size() < rankedList.size()){
48  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
49  }
50 
51  for(unsigned int ind = searchInd+1; ind < rankedList.size() && fabs(rankedList.at(ind).second - rankedList.at(searchInd).second) < distDbscan_ ; ind++){
52 
53  if(clustersPtrs.size() <= rankedList.at(ind).first){
54  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
55 
56  } else if(((*(clustersPtrs[rankedList.at(ind).first])).centreProj() - (*(clustersPtrs[rankedList.at(searchInd).first])).centreProj()).mag() < distDbscan_){
57  neighbors.push_back(ind);
58  }
59  }
60 
61  for(unsigned int ind = 0; ind < searchInd && fabs(rankedList.at(searchInd).second - rankedList.at(ind).second) < distDbscan_ ; ind++){
62 
63  if(clustersPtrs.size() <= rankedList.at(ind).first){
64  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
65 
66  } else if(((*(clustersPtrs[rankedList.at(ind).first])).centreProj() - (*(clustersPtrs[rankedList.at(searchInd).first])).centreProj()).mag() < distDbscan_){
67  neighbors.push_back(ind);
68  }
69  }
70 }
71 
72 
74  l1t::HGCalMulticlusterBxCollection & multiclusters,
75  const HGCalTriggerGeometryBase & triggerGeometry)
76 {
77 
78  std::vector<l1t::HGCalMulticluster> multiclustersTmp;
79 
80  int iclu = 0;
81  for(std::vector<edm::Ptr<l1t::HGCalCluster>>::const_iterator clu = clustersPtrs.begin(); clu != clustersPtrs.end(); ++clu, ++iclu){
82 
83  int imclu=0;
84  vector<int> tcPertinentMulticlusters;
85  for( const auto& mclu : multiclustersTmp ){
86  if( this->isPertinent(**clu, mclu, dr_) ){
87  tcPertinentMulticlusters.push_back(imclu);
88  }
89  ++imclu;
90  }
91  if( tcPertinentMulticlusters.empty() ){
92  multiclustersTmp.emplace_back( *clu );
93  }
94  else{
95  unsigned minDist = 1;
96  unsigned targetMulticlu = 0;
97  for( int imclu : tcPertinentMulticlusters ){
98  double d = ( multiclustersTmp.at(imclu).centreProj() - (*clu)->centreProj() ).mag() ;
99  if( d < minDist ){
100  minDist = d;
101  targetMulticlu = imclu;
102  }
103  }
104 
105  multiclustersTmp.at( targetMulticlu ).addConstituent( *clu );
106 
107  }
108  }
109 
110  /* making the collection of multiclusters */
111  for( unsigned i(0); i<multiclustersTmp.size(); ++i ){
112 
113  // compute the eta, phi observables for multicluster starting from its barycenter x,y,z position + pT as scalar sum of pT of constituents
114  double sumPt=0.;
115 
116  const std::unordered_map<uint32_t, edm::Ptr<l1t::HGCalCluster>> &pertinentClu = multiclustersTmp[i].constituents();
117  for(const auto& id_cluster : pertinentClu) sumPt += id_cluster.second->pt();
118  math::PtEtaPhiMLorentzVector multiclusterP4( sumPt,
119  multiclustersTmp[i].centre().eta(),
120  multiclustersTmp[i].centre().phi(),
121  0. );
122  multiclustersTmp[i].setP4( multiclusterP4 );
123 
124 
125  if( multiclustersTmp[i].pt() > ptC3dThreshold_ ){
126 
127  //compute shower shape
128  multiclustersTmp[i].showerLength(shape_.showerLength(multiclustersTmp[i]));
129  multiclustersTmp[i].coreShowerLength(shape_.coreShowerLength(multiclustersTmp[i], triggerGeometry));
130  multiclustersTmp[i].firstLayer(shape_.firstLayer(multiclustersTmp[i]));
131  multiclustersTmp[i].maxLayer(shape_.maxLayer(multiclustersTmp[i]));
132  multiclustersTmp[i].sigmaEtaEtaTot(shape_.sigmaEtaEtaTot(multiclustersTmp[i]));
133  multiclustersTmp[i].sigmaEtaEtaMax(shape_.sigmaEtaEtaMax(multiclustersTmp[i]));
134  multiclustersTmp[i].sigmaPhiPhiTot(shape_.sigmaPhiPhiTot(multiclustersTmp[i]));
135  multiclustersTmp[i].sigmaPhiPhiMax(shape_.sigmaPhiPhiMax(multiclustersTmp[i]));
136  multiclustersTmp[i].sigmaZZ(shape_.sigmaZZ(multiclustersTmp[i]));
137  multiclustersTmp[i].sigmaRRTot(shape_.sigmaRRTot(multiclustersTmp[i]));
138  multiclustersTmp[i].sigmaRRMax(shape_.sigmaRRMax(multiclustersTmp[i]));
139  multiclustersTmp[i].sigmaRRMean(shape_.sigmaRRMean(multiclustersTmp[i]));
140  multiclustersTmp[i].eMax(shape_.eMax(multiclustersTmp[i]));
141 
142  multiclusters.push_back( 0, multiclustersTmp[i]);
143  }
144  }
145 
146 }
148  l1t::HGCalMulticlusterBxCollection & multiclusters,
149  const HGCalTriggerGeometryBase & triggerGeometry)
150 {
151 
152  std::vector<l1t::HGCalMulticluster> multiclustersTmp;
153  l1t::HGCalMulticluster mcluTmp;
154  std::vector<bool> visited(clustersPtrs.size(),false);
155  std::vector<bool> merged (clustersPtrs.size(),false);
156  std::vector<std::pair<unsigned int,double>> rankedList;
157  rankedList.reserve(clustersPtrs.size());
158  std::vector<std::vector<unsigned int>> neighborList;
159  neighborList.reserve(clustersPtrs.size());
160 
161  int iclu = 0, imclu = 0, neighNo;
162  double dist = 0.;
163 
164  for(std::vector<edm::Ptr<l1t::HGCalCluster>>::const_iterator clu = clustersPtrs.begin(); clu != clustersPtrs.end(); ++clu, ++iclu){
165  dist = (*clu)->centreProj().mag()*HGCalDetId((*clu)->detId()).zside();
166  rankedList.push_back(std::make_pair(iclu,dist));
167  }
168  iclu = 0;
169  std::sort(rankedList.begin(), rankedList.end(), [](auto &left, auto &right) {
170  return left.second < right.second;
171  });
172 
173  for(const auto& cluRanked: rankedList){
174  std::vector<unsigned int> neighbors;
175 
176  if(!visited.at(iclu)){
177  visited.at(iclu) = true;
178  findNeighbor(rankedList, iclu, clustersPtrs, neighbors);
179  neighborList.push_back(std::move(neighbors));
180 
181  if(neighborList.at(iclu).size() >= minNDbscan_) {
182  multiclustersTmp.emplace_back( clustersPtrs[cluRanked.first] );
183  merged.at(iclu) = true;
184  /* dynamic range loop: range-based loop syntax cannot be employed */
185  for(unsigned int neighInd = 0; neighInd < neighborList.at(iclu).size(); neighInd++){
186  neighNo = neighborList.at(iclu).at(neighInd);
187  /* This condition also ensures merging of clusters visited by other clusters but not merged. */
188  if(!merged.at(neighNo) ){
189  merged.at(neighNo) = true;
190  multiclustersTmp.at(imclu).addConstituent( clustersPtrs[rankedList.at(neighNo).first] );
191 
192  if(!visited.at(neighNo)){
193  visited.at(neighNo) = true;
194  std::vector<unsigned int> secNeighbors;
195  findNeighbor(rankedList, neighNo,clustersPtrs, secNeighbors);
196 
197  if(secNeighbors.size() >= minNDbscan_){
198  neighborList.at(iclu).insert(neighborList.at(iclu).end(), secNeighbors.begin(), secNeighbors.end());
199  }
200  }
201  }
202  }
203  imclu++;
204  }
205  }
206  else neighborList.push_back(std::move(neighbors));
207  iclu++;
208  }
209  /* making the collection of multiclusters */
210  for( unsigned i(0); i<multiclustersTmp.size(); ++i ){
211 
212  // compute the eta, phi observables for multicluster starting from its barycenter x,y,z position + pT as scalar sum of pT of constituents
213  double sumPt=0.;
214 
215  const std::unordered_map<uint32_t, edm::Ptr<l1t::HGCalCluster>> &pertinentClu = multiclustersTmp[i].constituents();
216  for(const auto& id_cluster : pertinentClu) sumPt += id_cluster.second->pt();
217 
218  math::PtEtaPhiMLorentzVector multiclusterP4( sumPt,
219  multiclustersTmp[i].centre().eta(),
220  multiclustersTmp[i].centre().phi(),
221  0. );
222  multiclustersTmp[i].setP4( multiclusterP4 );
223 
224 
225  if( multiclustersTmp[i].pt() > ptC3dThreshold_ ){
226 
227  //compute shower shape
228  multiclustersTmp[i].showerLength(shape_.showerLength(multiclustersTmp[i]));
229  multiclustersTmp[i].coreShowerLength(shape_.coreShowerLength(multiclustersTmp[i], triggerGeometry));
230  multiclustersTmp[i].firstLayer(shape_.firstLayer(multiclustersTmp[i]));
231  multiclustersTmp[i].maxLayer(shape_.maxLayer(multiclustersTmp[i]));
232  multiclustersTmp[i].sigmaEtaEtaTot(shape_.sigmaEtaEtaTot(multiclustersTmp[i]));
233  multiclustersTmp[i].sigmaEtaEtaMax(shape_.sigmaEtaEtaMax(multiclustersTmp[i]));
234  multiclustersTmp[i].sigmaPhiPhiTot(shape_.sigmaPhiPhiTot(multiclustersTmp[i]));
235  multiclustersTmp[i].sigmaPhiPhiMax(shape_.sigmaPhiPhiMax(multiclustersTmp[i]));
236  multiclustersTmp[i].sigmaZZ(shape_.sigmaZZ(multiclustersTmp[i]));
237  multiclustersTmp[i].sigmaRRTot(shape_.sigmaRRTot(multiclustersTmp[i]));
238  multiclustersTmp[i].sigmaRRMax(shape_.sigmaRRMax(multiclustersTmp[i]));
239  multiclustersTmp[i].sigmaRRMean(shape_.sigmaRRMean(multiclustersTmp[i]));
240  multiclustersTmp[i].eMax(shape_.eMax(multiclustersTmp[i]));
241 
242  multiclusters.push_back( 0, multiclustersTmp[i]);
243  }
244  }
245 }
float sigmaRRMax(const l1t::HGCalMulticluster &c3d) const
HGCalMulticlusteringImpl(const edm::ParameterSet &conf)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
int coreShowerLength(const l1t::HGCalMulticluster &c3d, const HGCalTriggerGeometryBase &triggerGeometry) const
float sigmaRRTot(const l1t::HGCalMulticluster &c3d) const
float sigmaPhiPhiTot(const l1t::HGCalMulticluster &c3d) const
int firstLayer(const l1t::HGCalMulticluster &c3d) const
int zside(DetId const &)
const GlobalPoint & centreProj() const
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:25
float sigmaRRMean(const l1t::HGCalMulticluster &c3d, float radius=5.) const
float sigmaEtaEtaMax(const l1t::HGCalMulticluster &c3d) const
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)
uint32_t detId() const
bool isPertinent(const l1t::HGCalCluster &clu, const l1t::HGCalMulticluster &mclu, double dR) const
void clusterizeDR(const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, l1t::HGCalMulticlusterBxCollection &multiclusters, const HGCalTriggerGeometryBase &triggerGeometry)
int showerLength(const l1t::HGCalMulticluster &c3d) const
float sigmaZZ(const l1t::HGCalMulticluster &c3d) const
float sigmaPhiPhiMax(const l1t::HGCalMulticluster &c3d) const
int maxLayer(const l1t::HGCalMulticluster &c3d) const
float eMax(const l1t::HGCalMulticluster &c3d) const
float sigmaEtaEtaTot(const l1t::HGCalMulticluster &c3d) const
def move(src, dest)
Definition: eostools.py:510
void push_back(int bx, T object)
void clusterizeDBSCAN(const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, l1t::HGCalMulticlusterBxCollection &multiclusters, const HGCalTriggerGeometryBase &triggerGeometry)