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 finalizeClusters (std::vector< l1t::HGCalMulticluster > &, l1t::HGCalMulticlusterBxCollection &, const HGCalTriggerGeometryBase &)
 
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_
 
std::unique_ptr< HGCalTriggerClusterIdentificationBaseid_
 
unsigned minNDbscan_ = 3
 
std::string multiclusterAlgoType_
 
double ptC3dThreshold_
 
HGCalShowerShape shape_
 
HGCalTriggerTools triggerTools_
 

Detailed Description

Definition at line 15 of file HGCalMulticlusteringImpl.h.

Constructor & Destructor Documentation

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

Definition at line 8 of file HGCalMulticlusteringImpl.cc.

References beamerCreator::create(), distDbscan_, dr_, reco::get(), edm::ParameterSet::getParameter(), id_, 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  id_.reset( HGCalTriggerClusterIdentificationFactory::get()->create("HGCalTriggerClusterIdentificationBDT") );
21  id_->initialize(conf.getParameter<edm::ParameterSet>("EGIdentification"));
22 }
T getParameter(std::string const &) const
def create(alignables, pedeDump, additionalData, outputFile, config)
std::unique_ptr< HGCalTriggerClusterIdentificationBase > id_
T get(const Candidate &c)
Definition: component.h:55

Member Function Documentation

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

Definition at line 116 of file HGCalMulticlusteringImpl.cc.

References finalizeClusters(), findNeighbor(), minNDbscan_, eostools::move(), class-composition::visited, and ecaldqm::zside().

Referenced by eventSetup().

119 {
120 
121  std::vector<l1t::HGCalMulticluster> multiclustersTmp;
122  l1t::HGCalMulticluster mcluTmp;
123  std::vector<bool> visited(clustersPtrs.size(),false);
124  std::vector<bool> merged (clustersPtrs.size(),false);
125  std::vector<std::pair<unsigned int,double>> rankedList;
126  rankedList.reserve(clustersPtrs.size());
127  std::vector<std::vector<unsigned int>> neighborList;
128  neighborList.reserve(clustersPtrs.size());
129 
130  int iclu = 0, imclu = 0, neighNo;
131  double dist = 0.;
132 
133  for(std::vector<edm::Ptr<l1t::HGCalCluster>>::const_iterator clu = clustersPtrs.begin(); clu != clustersPtrs.end(); ++clu, ++iclu){
134  dist = (*clu)->centreProj().mag()*HGCalDetId((*clu)->detId()).zside();
135  rankedList.push_back(std::make_pair(iclu,dist));
136  }
137  iclu = 0;
138  std::sort(rankedList.begin(), rankedList.end(), [](auto &left, auto &right) {
139  return left.second < right.second;
140  });
141 
142  for(const auto& cluRanked: rankedList){
143  std::vector<unsigned int> neighbors;
144 
145  if(!visited.at(iclu)){
146  visited.at(iclu) = true;
147  findNeighbor(rankedList, iclu, clustersPtrs, neighbors);
148  neighborList.push_back(std::move(neighbors));
149 
150  if(neighborList.at(iclu).size() >= minNDbscan_) {
151  multiclustersTmp.emplace_back( clustersPtrs[cluRanked.first] );
152  merged.at(iclu) = true;
153  /* dynamic range loop: range-based loop syntax cannot be employed */
154  for(unsigned int neighInd = 0; neighInd < neighborList.at(iclu).size(); neighInd++){
155  neighNo = neighborList.at(iclu).at(neighInd);
156  /* This condition also ensures merging of clusters visited by other clusters but not merged. */
157  if(!merged.at(neighNo) ){
158  merged.at(neighNo) = true;
159  multiclustersTmp.at(imclu).addConstituent( clustersPtrs[rankedList.at(neighNo).first] );
160 
161  if(!visited.at(neighNo)){
162  visited.at(neighNo) = true;
163  std::vector<unsigned int> secNeighbors;
164  findNeighbor(rankedList, neighNo,clustersPtrs, secNeighbors);
165 
166  if(secNeighbors.size() >= minNDbscan_){
167  neighborList.at(iclu).insert(neighborList.at(iclu).end(), secNeighbors.begin(), secNeighbors.end());
168  }
169  }
170  }
171  }
172  imclu++;
173  }
174  }
175  else neighborList.push_back(std::move(neighbors));
176  iclu++;
177  }
178  /* making the collection of multiclusters */
179  finalizeClusters(multiclustersTmp, multiclusters, triggerGeometry);
180 }
int zside(DetId 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)
void finalizeClusters(std::vector< l1t::HGCalMulticluster > &, l1t::HGCalMulticlusterBxCollection &, const HGCalTriggerGeometryBase &)
def move(src, dest)
Definition: eostools.py:510
void HGCalMulticlusteringImpl::clusterizeDR ( const std::vector< edm::Ptr< l1t::HGCalCluster >> &  clustersPtr,
l1t::HGCalMulticlusterBxCollection multiclusters,
const HGCalTriggerGeometryBase triggerGeometry 
)

Definition at line 75 of file HGCalMulticlusteringImpl.cc.

References edmIntegrityCheck::d, dr_, finalizeClusters(), isPertinent(), and mag().

Referenced by eventSetup().

78 {
79 
80  std::vector<l1t::HGCalMulticluster> multiclustersTmp;
81 
82  int iclu = 0;
83  for(std::vector<edm::Ptr<l1t::HGCalCluster>>::const_iterator clu = clustersPtrs.begin(); clu != clustersPtrs.end(); ++clu, ++iclu){
84 
85  int imclu=0;
86  vector<int> tcPertinentMulticlusters;
87  for( const auto& mclu : multiclustersTmp ){
88  if( this->isPertinent(**clu, mclu, dr_) ){
89  tcPertinentMulticlusters.push_back(imclu);
90  }
91  ++imclu;
92  }
93  if( tcPertinentMulticlusters.empty() ){
94  multiclustersTmp.emplace_back( *clu );
95  }
96  else{
97  unsigned minDist = 1;
98  unsigned targetMulticlu = 0;
99  for( int imclu : tcPertinentMulticlusters ){
100  double d = ( multiclustersTmp.at(imclu).centreProj() - (*clu)->centreProj() ).mag() ;
101  if( d < minDist ){
102  minDist = d;
103  targetMulticlu = imclu;
104  }
105  }
106 
107  multiclustersTmp.at( targetMulticlu ).addConstituent( *clu );
108 
109  }
110  }
111 
112  /* making the collection of multiclusters */
113  finalizeClusters(multiclustersTmp, multiclusters, triggerGeometry);
114 
115 }
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
bool isPertinent(const l1t::HGCalCluster &clu, const l1t::HGCalMulticluster &mclu, double dR) const
void finalizeClusters(std::vector< l1t::HGCalMulticluster > &, l1t::HGCalMulticlusterBxCollection &, const HGCalTriggerGeometryBase &)
void HGCalMulticlusteringImpl::eventSetup ( const edm::EventSetup es)
inline
void HGCalMulticlusteringImpl::finalizeClusters ( std::vector< l1t::HGCalMulticluster > &  multiclusters_in,
l1t::HGCalMulticlusterBxCollection multiclusters_out,
const HGCalTriggerGeometryBase triggerGeometry 
)
private

Definition at line 185 of file HGCalMulticlusteringImpl.cc.

References fastPrimaryVertexProducer_cfi::clusters, HGCalShowerShape::coreShowerLength(), HGCalShowerShape::eMax(), HGCalShowerShape::firstLayer(), id_, HGCalShowerShape::maxLayer(), 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 clusterizeDBSCAN(), clusterizeDR(), and eventSetup().

187  {
188  for(auto& multicluster : multiclusters_in) {
189  // compute the eta, phi from its barycenter
190  // + pT as scalar sum of pT of constituents
191  double sumPt=0.;
192  const std::unordered_map<uint32_t, edm::Ptr<l1t::HGCalCluster>>& clusters = multicluster.constituents();
193  for(const auto& id_cluster : clusters) sumPt += id_cluster.second->pt();
194 
195  math::PtEtaPhiMLorentzVector multiclusterP4( sumPt,
196  multicluster.centre().eta(),
197  multicluster.centre().phi(),
198  0. );
199  multicluster.setP4( multiclusterP4 );
200 
201  if( multicluster.pt() > ptC3dThreshold_ ){
202  //compute shower shapes
203  multicluster.showerLength(shape_.showerLength(multicluster));
204  multicluster.coreShowerLength(shape_.coreShowerLength(multicluster, triggerGeometry));
205  multicluster.firstLayer(shape_.firstLayer(multicluster));
206  multicluster.maxLayer(shape_.maxLayer(multicluster));
207  multicluster.sigmaEtaEtaTot(shape_.sigmaEtaEtaTot(multicluster));
208  multicluster.sigmaEtaEtaMax(shape_.sigmaEtaEtaMax(multicluster));
209  multicluster.sigmaPhiPhiTot(shape_.sigmaPhiPhiTot(multicluster));
210  multicluster.sigmaPhiPhiMax(shape_.sigmaPhiPhiMax(multicluster));
211  multicluster.sigmaZZ(shape_.sigmaZZ(multicluster));
212  multicluster.sigmaRRTot(shape_.sigmaRRTot(multicluster));
213  multicluster.sigmaRRMax(shape_.sigmaRRMax(multicluster));
214  multicluster.sigmaRRMean(shape_.sigmaRRMean(multicluster));
215  multicluster.eMax(shape_.eMax(multicluster));
216  // fill quality flag
217  multicluster.setHwQual(id_->decision(multicluster));
218 
219  multiclusters_out.push_back( 0, multicluster);
220  }
221  }
222 }
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
std::unique_ptr< HGCalTriggerClusterIdentificationBase > id_
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::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 43 of file HGCalMulticlusteringImpl.cc.

References distDbscan_, Exception, and mag().

Referenced by clusterizeDBSCAN(), and eventSetup().

47  {
48 
49  if(clustersPtrs.size() <= searchInd || clustersPtrs.size() < rankedList.size()){
50  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
51  }
52 
53  for(unsigned int ind = searchInd+1; ind < rankedList.size() && fabs(rankedList.at(ind).second - rankedList.at(searchInd).second) < distDbscan_ ; ind++){
54 
55  if(clustersPtrs.size() <= rankedList.at(ind).first){
56  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
57 
58  } else if(((*(clustersPtrs[rankedList.at(ind).first])).centreProj() - (*(clustersPtrs[rankedList.at(searchInd).first])).centreProj()).mag() < distDbscan_){
59  neighbors.push_back(ind);
60  }
61  }
62 
63  for(unsigned int ind = 0; ind < searchInd && fabs(rankedList.at(searchInd).second - rankedList.at(ind).second) < distDbscan_ ; ind++){
64 
65  if(clustersPtrs.size() <= rankedList.at(ind).first){
66  throw cms::Exception("IndexOutOfBound: clustersPtrs in 'findNeighbor'");
67 
68  } else if(((*(clustersPtrs[rankedList.at(ind).first])).centreProj() - (*(clustersPtrs[rankedList.at(searchInd).first])).centreProj()).mag() < distDbscan_){
69  neighbors.push_back(ind);
70  }
71  }
72 }
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 25 of file HGCalMulticlusteringImpl.cc.

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

Referenced by clusterizeDR(), and eventSetup().

28 {
29  HGCalDetId cluDetId( clu.detId() );
30  HGCalDetId firstClusterDetId( mclu.detId() );
31 
32  if( cluDetId.zside() != firstClusterDetId.zside() ){
33  return false;
34  }
35  if( ( mclu.centreProj() - clu.centreProj() ).mag() < dR ){
36  return true;
37  }
38  return false;
39 
40 }
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 54 of file HGCalMulticlusteringImpl.h.

Referenced by findNeighbor(), and HGCalMulticlusteringImpl().

double HGCalMulticlusteringImpl::dr_
private

Definition at line 51 of file HGCalMulticlusteringImpl.h.

Referenced by clusterizeDR(), and HGCalMulticlusteringImpl().

std::unique_ptr<HGCalTriggerClusterIdentificationBase> HGCalMulticlusteringImpl::id_
private

Definition at line 59 of file HGCalMulticlusteringImpl.h.

Referenced by finalizeClusters(), and HGCalMulticlusteringImpl().

unsigned HGCalMulticlusteringImpl::minNDbscan_ = 3
private

Definition at line 55 of file HGCalMulticlusteringImpl.h.

Referenced by clusterizeDBSCAN(), and HGCalMulticlusteringImpl().

std::string HGCalMulticlusteringImpl::multiclusterAlgoType_
private

Definition at line 53 of file HGCalMulticlusteringImpl.h.

Referenced by HGCalMulticlusteringImpl().

double HGCalMulticlusteringImpl::ptC3dThreshold_
private

Definition at line 52 of file HGCalMulticlusteringImpl.h.

Referenced by finalizeClusters(), and HGCalMulticlusteringImpl().

HGCalShowerShape HGCalMulticlusteringImpl::shape_
private

Definition at line 57 of file HGCalMulticlusteringImpl.h.

Referenced by eventSetup(), and finalizeClusters().

HGCalTriggerTools HGCalMulticlusteringImpl::triggerTools_
private

Definition at line 58 of file HGCalMulticlusteringImpl.h.

Referenced by eventSetup().