CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
HGCalMulticlusteringImpl Class Reference

#include <HGCalMulticlusteringImpl.h>

Public Member Functions

void clusterizeDBSCAN (const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, l1t::HGCalMulticlusterBxCollection &multiclusters, const HGCalTriggerGeometryBase &triggerGeometry)
 
void clusterizeDR (const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, l1t::HGCalMulticlusterBxCollection &multiclusters, const HGCalTriggerGeometryBase &triggerGeometry)
 
void eventSetup (const edm::EventSetup &es)
 
 HGCalMulticlusteringImpl (const edm::ParameterSet &conf)
 
bool isPertinent (const l1t::HGCalCluster &clu, const l1t::HGCalMulticluster &mclu, double dR) const
 

Private Member Functions

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)
 

Private Attributes

double distDbscan_ = 0.005
 
double dr_
 
unsigned minNDbscan_ = 3
 
std::string multiclusterAlgoType_
 
double ptC3dThreshold_
 
HGCalShowerShape shape_
 
HGCalTriggerTools triggerTools_
 

Detailed Description

Definition at line 14 of file HGCalMulticlusteringImpl.h.

Constructor & Destructor Documentation

HGCalMulticlusteringImpl::HGCalMulticlusteringImpl ( const edm::ParameterSet conf)

Definition at line 8 of file HGCalMulticlusteringImpl.cc.

References distDbscan_, dr_, minNDbscan_, multiclusterAlgoType_, and ptC3dThreshold_.

8  :
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 }
T getParameter(std::string const &) const

Member Function Documentation

void HGCalMulticlusteringImpl::clusterizeDBSCAN ( const std::vector< edm::Ptr< l1t::HGCalCluster >> &  clustersPtr,
l1t::HGCalMulticlusterBxCollection multiclusters,
const HGCalTriggerGeometryBase triggerGeometry 
)

Definition at line 147 of file HGCalMulticlusteringImpl.cc.

References HGCalShowerShape::coreShowerLength(), HGCalShowerShape::eMax(), PVValHelper::eta, findNeighbor(), HGCalShowerShape::firstLayer(), mps_fire::i, HGCalShowerShape::maxLayer(), minNDbscan_, eostools::move(), phi, EnergyCorrector::pt, ptC3dThreshold_, BXVector< T >::push_back(), shape_, HGCalShowerShape::showerLength(), HGCalShowerShape::sigmaEtaEtaMax(), HGCalShowerShape::sigmaEtaEtaTot(), HGCalShowerShape::sigmaPhiPhiMax(), HGCalShowerShape::sigmaPhiPhiTot(), HGCalShowerShape::sigmaRRMax(), HGCalShowerShape::sigmaRRMean(), HGCalShowerShape::sigmaRRTot(), HGCalShowerShape::sigmaZZ(), TtFullHadEvtBuilder_cfi::sumPt, class-composition::visited, and HcalDigiParam_cfi::zside.

Referenced by eventSetup().

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
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
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)
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 HGCalMulticlusteringImpl::clusterizeDR ( const std::vector< edm::Ptr< l1t::HGCalCluster >> &  clustersPtr,
l1t::HGCalMulticlusterBxCollection multiclusters,
const HGCalTriggerGeometryBase triggerGeometry 
)

Definition at line 73 of file HGCalMulticlusteringImpl.cc.

References HGCalShowerShape::coreShowerLength(), edmIntegrityCheck::d, dr_, HGCalShowerShape::eMax(), PVValHelper::eta, HGCalShowerShape::firstLayer(), mps_fire::i, isPertinent(), mag(), HGCalShowerShape::maxLayer(), phi, EnergyCorrector::pt, ptC3dThreshold_, BXVector< T >::push_back(), shape_, HGCalShowerShape::showerLength(), HGCalShowerShape::sigmaEtaEtaMax(), HGCalShowerShape::sigmaEtaEtaTot(), HGCalShowerShape::sigmaPhiPhiMax(), HGCalShowerShape::sigmaPhiPhiTot(), HGCalShowerShape::sigmaRRMax(), HGCalShowerShape::sigmaRRMean(), HGCalShowerShape::sigmaRRTot(), HGCalShowerShape::sigmaZZ(), and TtFullHadEvtBuilder_cfi::sumPt.

Referenced by eventSetup().

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 }
float sigmaRRMax(const l1t::HGCalMulticluster &c3d) const
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
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
bool isPertinent(const l1t::HGCalCluster &clu, const l1t::HGCalMulticluster &mclu, double dR) const
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
void push_back(int bx, T object)
void HGCalMulticlusteringImpl::eventSetup ( const edm::EventSetup es)
inline
void HGCalMulticlusteringImpl::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 
)
private

Definition at line 41 of file HGCalMulticlusteringImpl.cc.

References distDbscan_, Exception, and mag().

Referenced by clusterizeDBSCAN(), and eventSetup().

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 }
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
bool HGCalMulticlusteringImpl::isPertinent ( const l1t::HGCalCluster clu,
const l1t::HGCalMulticluster mclu,
double  dR 
) const

Definition at line 23 of file HGCalMulticlusteringImpl.cc.

References l1t::HGCalClusterT< C >::centreProj(), l1t::HGCalClusterT< C >::detId(), PFRecoTauDiscriminationAgainstElectronDeadECAL_cfi::dR, and mag().

Referenced by clusterizeDR(), and eventSetup().

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 }
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
const GlobalPoint & centreProj() const
uint32_t detId() const

Member Data Documentation

double HGCalMulticlusteringImpl::distDbscan_ = 0.005
private

Definition at line 50 of file HGCalMulticlusteringImpl.h.

Referenced by findNeighbor(), and HGCalMulticlusteringImpl().

double HGCalMulticlusteringImpl::dr_
private

Definition at line 47 of file HGCalMulticlusteringImpl.h.

Referenced by clusterizeDR(), and HGCalMulticlusteringImpl().

unsigned HGCalMulticlusteringImpl::minNDbscan_ = 3
private

Definition at line 51 of file HGCalMulticlusteringImpl.h.

Referenced by clusterizeDBSCAN(), and HGCalMulticlusteringImpl().

std::string HGCalMulticlusteringImpl::multiclusterAlgoType_
private

Definition at line 49 of file HGCalMulticlusteringImpl.h.

Referenced by HGCalMulticlusteringImpl().

double HGCalMulticlusteringImpl::ptC3dThreshold_
private
HGCalShowerShape HGCalMulticlusteringImpl::shape_
private

Definition at line 53 of file HGCalMulticlusteringImpl.h.

Referenced by clusterizeDBSCAN(), clusterizeDR(), and eventSetup().

HGCalTriggerTools HGCalMulticlusteringImpl::triggerTools_
private

Definition at line 54 of file HGCalMulticlusteringImpl.h.

Referenced by eventSetup().