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  id_.reset( HGCalTriggerClusterIdentificationFactory::get()->create("HGCalTriggerClusterIdentificationBDT") );
21  id_->initialize(conf.getParameter<edm::ParameterSet>("EGIdentification"));
22 }
23 
24 
26  const l1t::HGCalMulticluster & mclu,
27  double dR ) const
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 }
41 
42 
43 void HGCalMulticlusteringImpl::findNeighbor( const std::vector<std::pair<unsigned int,double>>& rankedList,
44  unsigned int searchInd,
45  const std::vector<edm::Ptr<l1t::HGCalCluster>>& clustersPtrs,
46  std::vector<unsigned int>& neighbors
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 }
73 
74 
76  l1t::HGCalMulticlusterBxCollection & multiclusters,
77  const HGCalTriggerGeometryBase & triggerGeometry)
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  double minDist = dr_;
86  int targetMulticlu = -1;
87 
88  for(unsigned imclu=0; imclu<multiclustersTmp.size(); imclu++){
89 
90  if(!this->isPertinent(**clu, multiclustersTmp.at(imclu), dr_)) continue;
91 
92  double d = ( multiclustersTmp.at(imclu).centreProj() - (*clu)->centreProj() ).mag() ;
93  if(d<minDist){
94  minDist = d;
95  targetMulticlu = int(imclu);
96  }
97  }
98 
99  if(targetMulticlu<0) multiclustersTmp.emplace_back( *clu );
100  else multiclustersTmp.at( targetMulticlu ).addConstituent( *clu );
101 
102  }
103 
104  /* making the collection of multiclusters */
105  finalizeClusters(multiclustersTmp, multiclusters, triggerGeometry);
106 
107 }
109  l1t::HGCalMulticlusterBxCollection & multiclusters,
110  const HGCalTriggerGeometryBase & triggerGeometry)
111 {
112 
113  std::vector<l1t::HGCalMulticluster> multiclustersTmp;
114  l1t::HGCalMulticluster mcluTmp;
115  std::vector<bool> visited(clustersPtrs.size(),false);
116  std::vector<bool> merged (clustersPtrs.size(),false);
117  std::vector<std::pair<unsigned int,double>> rankedList;
118  rankedList.reserve(clustersPtrs.size());
119  std::vector<std::vector<unsigned int>> neighborList;
120  neighborList.reserve(clustersPtrs.size());
121 
122  int iclu = 0, imclu = 0, neighNo;
123  double dist = 0.;
124 
125  for(std::vector<edm::Ptr<l1t::HGCalCluster>>::const_iterator clu = clustersPtrs.begin(); clu != clustersPtrs.end(); ++clu, ++iclu){
126  dist = (*clu)->centreProj().mag()*HGCalDetId((*clu)->detId()).zside();
127  rankedList.push_back(std::make_pair(iclu,dist));
128  }
129  iclu = 0;
130  std::sort(rankedList.begin(), rankedList.end(), [](auto &left, auto &right) {
131  return left.second < right.second;
132  });
133 
134  for(const auto& cluRanked: rankedList){
135  std::vector<unsigned int> neighbors;
136 
137  if(!visited.at(iclu)){
138  visited.at(iclu) = true;
139  findNeighbor(rankedList, iclu, clustersPtrs, neighbors);
140  neighborList.push_back(std::move(neighbors));
141 
142  if(neighborList.at(iclu).size() >= minNDbscan_) {
143  multiclustersTmp.emplace_back( clustersPtrs[cluRanked.first] );
144  merged.at(iclu) = true;
145  /* dynamic range loop: range-based loop syntax cannot be employed */
146  for(unsigned int neighInd = 0; neighInd < neighborList.at(iclu).size(); neighInd++){
147  neighNo = neighborList.at(iclu).at(neighInd);
148  /* This condition also ensures merging of clusters visited by other clusters but not merged. */
149  if(!merged.at(neighNo) ){
150  merged.at(neighNo) = true;
151  multiclustersTmp.at(imclu).addConstituent( clustersPtrs[rankedList.at(neighNo).first] );
152 
153  if(!visited.at(neighNo)){
154  visited.at(neighNo) = true;
155  std::vector<unsigned int> secNeighbors;
156  findNeighbor(rankedList, neighNo,clustersPtrs, secNeighbors);
157 
158  if(secNeighbors.size() >= minNDbscan_){
159  neighborList.at(iclu).insert(neighborList.at(iclu).end(), secNeighbors.begin(), secNeighbors.end());
160  }
161  }
162  }
163  }
164  imclu++;
165  }
166  }
167  else neighborList.push_back(std::move(neighbors));
168  iclu++;
169  }
170  /* making the collection of multiclusters */
171  finalizeClusters(multiclustersTmp, multiclusters, triggerGeometry);
172 }
173 
174 
175 void
177 finalizeClusters(std::vector<l1t::HGCalMulticluster>& multiclusters_in,
178  l1t::HGCalMulticlusterBxCollection& multiclusters_out,
179  const HGCalTriggerGeometryBase& triggerGeometry) {
180  for(auto& multicluster : multiclusters_in) {
181  // compute the eta, phi from its barycenter
182  // + pT as scalar sum of pT of constituents
183  double sumPt=0.;
184  const std::unordered_map<uint32_t, edm::Ptr<l1t::HGCalCluster>>& clusters = multicluster.constituents();
185  for(const auto& id_cluster : clusters) sumPt += id_cluster.second->pt();
186 
187  math::PtEtaPhiMLorentzVector multiclusterP4( sumPt,
188  multicluster.centre().eta(),
189  multicluster.centre().phi(),
190  0. );
191  multicluster.setP4( multiclusterP4 );
192 
193  if( multicluster.pt() > ptC3dThreshold_ ){
194  //compute shower shapes
195  multicluster.showerLength(shape_.showerLength(multicluster));
196  multicluster.coreShowerLength(shape_.coreShowerLength(multicluster, triggerGeometry));
197  multicluster.firstLayer(shape_.firstLayer(multicluster));
198  multicluster.maxLayer(shape_.maxLayer(multicluster));
199  multicluster.sigmaEtaEtaTot(shape_.sigmaEtaEtaTot(multicluster));
200  multicluster.sigmaEtaEtaMax(shape_.sigmaEtaEtaMax(multicluster));
201  multicluster.sigmaPhiPhiTot(shape_.sigmaPhiPhiTot(multicluster));
202  multicluster.sigmaPhiPhiMax(shape_.sigmaPhiPhiMax(multicluster));
203  multicluster.sigmaZZ(shape_.sigmaZZ(multicluster));
204  multicluster.sigmaRRTot(shape_.sigmaRRTot(multicluster));
205  multicluster.sigmaRRMax(shape_.sigmaRRMax(multicluster));
206  multicluster.sigmaRRMean(shape_.sigmaRRMean(multicluster));
207  multicluster.eMax(shape_.eMax(multicluster));
208  // fill quality flag
209  multicluster.setHwQual(id_->decision(multicluster));
210 
211  multiclusters_out.push_back( 0, multicluster);
212  }
213  }
214 }
float sigmaRRMax(const l1t::HGCalMulticluster &c3d) const
T getParameter(std::string const &) const
HGCalMulticlusteringImpl(const edm::ParameterSet &conf)
def create(alignables, pedeDump, additionalData, outputFile, config)
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
std::unique_ptr< HGCalTriggerClusterIdentificationBase > id_
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)
void finalizeClusters(std::vector< l1t::HGCalMulticluster > &, l1t::HGCalMulticlusterBxCollection &, const HGCalTriggerGeometryBase &)
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:511
T get(const Candidate &c)
Definition: component.h:55
void push_back(int bx, T object)
void clusterizeDBSCAN(const std::vector< edm::Ptr< l1t::HGCalCluster >> &clustersPtr, l1t::HGCalMulticlusterBxCollection &multiclusters, const HGCalTriggerGeometryBase &triggerGeometry)