CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Attributes
RealisticHitToClusterAssociator Class Reference

#include <RealisticHitToClusterAssociator.h>

Classes

struct  RealisticHit
 

Public Member Functions

void computeAssociation (float exclusiveFraction, bool useMCFractionsForExclEnergy, unsigned int fhOffset, unsigned int bhOffset)
 
void filterHitsByDistance (float maxDistance)
 
void findAndMergeInvisibleClusters (float invisibleFraction, float exclusiveFraction)
 
void findCentersOfGravity ()
 
void init (std::size_t numberOfHits, std::size_t numberOfSimClusters, std::size_t numberOfLayers)
 
void insertHitEnergy (float energy, unsigned int hitIndex)
 
void insertHitPosition (float x, float y, float z, unsigned int hitIndex)
 
void insertLayerId (unsigned int layerId, unsigned int hitIndex)
 
void insertSimClusterIdAndFraction (unsigned int scIdx, float fraction, unsigned int hitIndex, float associatedEnergy)
 
const std::vector< RealisticCluster > & realisticClusters () const
 
float XYdistanceFromMaxHit (unsigned int hitId, unsigned int clusterId)
 
float XYdistanceFromPointOnSameLayer (unsigned int hitId, const Hit3DPosition &point)
 

Private Types

using Hit3DPosition = std::array< float, 3 >
 

Private Attributes

std::vector< RealisticHitrealisticHits_
 
std::vector< RealisticClusterrealisticSimClusters_
 

Detailed Description

Definition at line 31 of file RealisticHitToClusterAssociator.h.

Member Typedef Documentation

using RealisticHitToClusterAssociator::Hit3DPosition = std::array<float,3>
private

Definition at line 33 of file RealisticHitToClusterAssociator.h.

Member Function Documentation

void RealisticHitToClusterAssociator::computeAssociation ( float  exclusiveFraction,
bool  useMCFractionsForExclEnergy,
unsigned int  fhOffset,
unsigned int  bhOffset 
)
inline

Definition at line 98 of file RealisticHitToClusterAssociator.h.

References MillePedeFileConverter_cfg::e, JetChargeProducer_cfi::exp, f, or, realisticHits_, realisticSimClusters_, x, and XYdistanceFromMaxHit().

Referenced by RealisticSimClusterMapper::buildClusters().

99  {
100  //if more than exclusiveFraction of a hit's energy belongs to a cluster, that rechit is not counted as shared
101  unsigned int numberOfHits = realisticHits_.size();
102  std::vector<float> partialEnergies;
103  for(unsigned int hitId = 0; hitId < numberOfHits; ++hitId)
104  {
105  partialEnergies.clear();
106  std::vector<unsigned int> removeAssociation;
107  auto& realisticHit = realisticHits_[hitId];
108  unsigned int numberOfClusters = realisticHit.hitToCluster_.size();
109  if(numberOfClusters == 1)
110  {
111  unsigned int simClusterId = realisticHit.hitToCluster_[0].simClusterId_;
112  float assignedFraction = 1.f;
113  realisticHit.hitToCluster_[0].realisticEnergyFraction_ = assignedFraction;
114  float assignedEnergy = realisticHit.totalEnergy_;
115  realisticSimClusters_[simClusterId].increaseEnergy(assignedEnergy);
116  realisticSimClusters_[simClusterId].addHitAndFraction(hitId, assignedFraction);
117  realisticSimClusters_[simClusterId].increaseExclusiveEnergy(assignedEnergy);
118  }
119  else
120  {
121  partialEnergies.resize(numberOfClusters,0.f);
122  unsigned int layer = realisticHit.layerId_;
123  float sumE = 0.f;
124  float energyDecayLength = getDecayLength(layer, fhOffset, bhOffset);
125  for(unsigned int clId = 0; clId < numberOfClusters; ++clId )
126  {
127  auto simClusterId = realisticHit.hitToCluster_[clId].simClusterId_;
128  realisticHit.hitToCluster_[clId].distanceFromMaxHit_ = XYdistanceFromMaxHit(hitId,simClusterId);
129  // partial energy is computed based on the distance from the maximum energy hit and its energy
130  // partial energy is only needed to compute a fraction and it's not the energy assigned to the cluster
131  auto maxEnergyOnLayer = realisticSimClusters_[simClusterId].getMaxEnergy(layer);
132  if(maxEnergyOnLayer>0.f)
133  {
134  partialEnergies[clId] = maxEnergyOnLayer * std::exp(-realisticHit.hitToCluster_[clId].distanceFromMaxHit_/energyDecayLength);
135  }
136  sumE += partialEnergies[clId];
137  }
138  if(sumE > 0.f)
139  {
140  float invSumE = 1.f/sumE;
141  for(unsigned int clId = 0; clId < numberOfClusters; ++clId )
142  {
143  unsigned int simClusterIndex = realisticHit.hitToCluster_[clId].simClusterId_;
144  float assignedFraction = partialEnergies[clId]*invSumE;
145  if(assignedFraction > 1e-3)
146  {
147  realisticHit.hitToCluster_[clId].realisticEnergyFraction_ = assignedFraction;
148  float assignedEnergy = assignedFraction *realisticHit.totalEnergy_;
149  realisticSimClusters_[simClusterIndex].increaseEnergy(assignedEnergy);
150  realisticSimClusters_[simClusterIndex].addHitAndFraction(hitId, assignedFraction);
151  // if the hits energy belongs for more than exclusiveFraction to a cluster, also the cluster's
152  // exclusive energy is increased. The exclusive energy will be needed to evaluate if
153  // a realistic cluster will be invisible, i.e. absorbed by other clusters
154  if( (useMCFractionsForExclEnergy and realisticHit.hitToCluster_[clId].mcEnergyFraction_ > exclusiveFraction) or
155  (!useMCFractionsForExclEnergy and assignedFraction > exclusiveFraction) )
156  {
157  realisticSimClusters_[simClusterIndex].increaseExclusiveEnergy(assignedEnergy);
158  }
159  }
160  else
161  {
162  removeAssociation.push_back(simClusterIndex);
163  }
164  }
165  }
166  }
167 
168  while(!removeAssociation.empty())
169  {
170  auto clusterToRemove = removeAssociation.back();
171  removeAssociation.pop_back();
172 
173  realisticHit.hitToCluster_.erase(std::remove_if(realisticHit.hitToCluster_.begin(), realisticHit.hitToCluster_.end(), [clusterToRemove](const RealisticHit::HitToCluster& x)
174  {
175  return x.simClusterId_ == clusterToRemove;
176  }), realisticHit.hitToCluster_.end());
177  }
178  }
179  }
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
double f[11][100]
std::vector< RealisticCluster > realisticSimClusters_
float XYdistanceFromMaxHit(unsigned int hitId, unsigned int clusterId)
void RealisticHitToClusterAssociator::filterHitsByDistance ( float  maxDistance)
inline

Definition at line 304 of file RealisticHitToClusterAssociator.h.

References f, mps_fire::i, realisticHits_, realisticSimClusters_, and XYdistanceFromPointOnSameLayer().

Referenced by RealisticSimClusterMapper::buildClusters().

305  {
306  for(auto& cluster : realisticSimClusters_)
307  {
308  if(cluster.isVisible())
309  {
310  auto& hAndF = cluster.hitsIdsAndFractions();
311  for(unsigned int i = 0; i<hAndF.size(); ++i)
312  {
313  auto hitId = hAndF[i].first;
314  const auto & hit = realisticHits_[hitId];
315  auto layerId = hit.layerId_;
316  if(XYdistanceFromPointOnSameLayer(hitId, cluster.getCenterOfGravity(layerId)) > maxDistance)
317  {
318  cluster.increaseEnergy(-hit.totalEnergy_*hAndF[i].second);
319  cluster.modifyFractionByIndex(0.f, i);
320  }
321  }
322  }
323  }
324  }
double f[11][100]
std::vector< RealisticCluster > realisticSimClusters_
float XYdistanceFromPointOnSameLayer(unsigned int hitId, const Hit3DPosition &point)
void RealisticHitToClusterAssociator::findAndMergeInvisibleClusters ( float  invisibleFraction,
float  exclusiveFraction 
)
inline

Definition at line 181 of file RealisticHitToClusterAssociator.h.

References f, dedxEstimators_cff::fraction, mps_fire::i, realisticHits_, realisticSimClusters_, and EgAmbiguityTools::sharedEnergy().

Referenced by RealisticSimClusterMapper::buildClusters().

182  {
183  unsigned int numberOfRealSimClusters = realisticSimClusters_.size();
184 
185  for(unsigned int clId= 0; clId < numberOfRealSimClusters; ++clId)
186  {
187  if(realisticSimClusters_[clId].getExclusiveEnergyFraction() < invisibleFraction)
188  {
189  realisticSimClusters_[clId].setVisible(false);
190  auto& hAndF = realisticSimClusters_[clId].hitsIdsAndFractions();
191  std::unordered_map < unsigned int, float> energyInNeighbors;
192  float totalSharedEnergy=0.f;
193 
194  for(auto& elt : hAndF)
195  {
196  unsigned int hitId = elt.first;
197  float fraction = elt.second;
198  auto& realisticHit = realisticHits_[hitId];
199 
200  if(realisticHit.hitToCluster_.size() >1 && fraction < 1.f)
201  {
202  float correction = 1.f - fraction;
203  unsigned int numberOfClusters = realisticHit.hitToCluster_.size();
204  int clusterToRemove = -1;
205  for(unsigned int i = 0; i< numberOfClusters; ++i)
206  {
207  auto simClusterIndex = realisticHit.hitToCluster_[i].simClusterId_;
208  if(simClusterIndex == clId)
209  {
210  clusterToRemove = i;
211  }
212  else
213  if(realisticSimClusters_[simClusterIndex].isVisible())
214  {
215  float oldFraction = realisticHit.hitToCluster_[i].realisticEnergyFraction_;
216  float newFraction = oldFraction/correction;
217  float oldEnergy = oldFraction*realisticHit.totalEnergy_;
218  float newEnergy= newFraction*realisticHit.totalEnergy_;
219  float sharedEnergy = newEnergy-oldEnergy;
220  energyInNeighbors[simClusterIndex] +=sharedEnergy;
221  totalSharedEnergy +=sharedEnergy;
222  realisticSimClusters_[simClusterIndex].increaseEnergy(sharedEnergy);
223  realisticSimClusters_[simClusterIndex].modifyFractionForHitId(newFraction, hitId);
224  realisticHit.hitToCluster_[i].realisticEnergyFraction_ = newFraction;
225  if(newFraction > exclusiveFraction)
226  {
227  realisticSimClusters_[simClusterIndex].increaseExclusiveEnergy(sharedEnergy);
228  if(oldFraction <=exclusiveFraction)
229  {
230  realisticSimClusters_[simClusterIndex].increaseExclusiveEnergy(oldEnergy);
231  }
232  }
233  }
234  }
235  realisticSimClusters_[realisticHit.hitToCluster_[clusterToRemove].simClusterId_].modifyFractionForHitId(0.f, hitId);
236  realisticHit.hitToCluster_.erase(realisticHit.hitToCluster_.begin()+clusterToRemove);
237  }
238  }
239 
240  for(auto& elt : hAndF)
241  {
242  unsigned int hitId = elt.first;
243  auto& realisticHit = realisticHits_[hitId];
244  if(realisticHit.hitToCluster_.size()==1 and realisticHit.hitToCluster_[0].simClusterId_ == clId and totalSharedEnergy > 0.f)
245  {
246  for (auto& pair: energyInNeighbors)
247  {
248  // hits that belonged completely to the absorbed cluster are redistributed
249  // based on the fraction of energy shared in the shared hits
250  float sharedFraction = pair.second/totalSharedEnergy;
251  float assignedEnergy = realisticHit.totalEnergy_*sharedFraction;
252  realisticSimClusters_[pair.first].increaseEnergy(assignedEnergy);
253  realisticSimClusters_[pair.first].addHitAndFraction(hitId, sharedFraction);
254  realisticHit.hitToCluster_.emplace_back(RealisticHit::HitToCluster{pair.first, 0.f, -1.f, sharedFraction});
255  if(sharedFraction > exclusiveFraction)
256  realisticSimClusters_[pair.first].increaseExclusiveEnergy(assignedEnergy);
257  }
258  }
259  }
260 
261  }
262  }
263  }
float sharedEnergy(const reco::CaloCluster *, const reco::CaloCluster *, edm::Handle< EcalRecHitCollection > &barrelRecHits, edm::Handle< EcalRecHitCollection > &endcapRecHits)
double f[11][100]
std::vector< RealisticCluster > realisticSimClusters_
void RealisticHitToClusterAssociator::findCentersOfGravity ( )
inline

Definition at line 265 of file RealisticHitToClusterAssociator.h.

References f, dedxEstimators_cff::fraction, realisticHits_, and realisticSimClusters_.

Referenced by RealisticSimClusterMapper::buildClusters().

266  {
267  for(auto& cluster : realisticSimClusters_)
268  {
269  if(cluster.isVisible())
270  {
271  unsigned int layersNum = cluster.getLayersNum();
272  std::vector<float> totalEnergyPerLayer(layersNum, 0.f);
273  std::vector<float> xEnergyPerLayer(layersNum, 0.f);
274  std::vector<float> yEnergyPerLayer(layersNum, 0.f);
275  std::vector<float> zPositionPerLayer(layersNum, 0.f);
276  const auto& hAndF = cluster.hitsIdsAndFractions();
277  for(auto& elt : hAndF)
278  {
279  auto hitId = elt.first;
280  auto fraction = elt.second;
281  const auto & hit = realisticHits_[hitId];
282  const auto & hitPos = hit.hitPosition_;
283  auto layerId = hit.layerId_;
284  auto hitEinCluster = hit.totalEnergy_*fraction;
285  totalEnergyPerLayer[layerId]+= hitEinCluster;
286  xEnergyPerLayer[layerId] += hitPos[0]*hitEinCluster;
287  yEnergyPerLayer[layerId] += hitPos[1]*hitEinCluster;
288  zPositionPerLayer[layerId] = hitPos[2];
289  }
290  Hit3DPosition centerOfGravity;
291  for(unsigned int layerId=0; layerId<layersNum; layerId++)
292  {
293  auto energyOnLayer = totalEnergyPerLayer[layerId];
294  if(energyOnLayer > 0.f)
295  {
296  centerOfGravity = {{xEnergyPerLayer[layerId]/energyOnLayer,yEnergyPerLayer[layerId]/energyOnLayer, zPositionPerLayer[layerId] }};
297  cluster.setCenterOfGravity(layerId,centerOfGravity );
298  }
299  }
300  }
301  }
302  }
double f[11][100]
std::vector< RealisticCluster > realisticSimClusters_
void RealisticHitToClusterAssociator::init ( std::size_t  numberOfHits,
std::size_t  numberOfSimClusters,
std::size_t  numberOfLayers 
)
inline

Definition at line 53 of file RealisticHitToClusterAssociator.h.

References realisticHits_, realisticSimClusters_, and SimDataFormats::CaloAnalysis::sc.

Referenced by RealisticSimClusterMapper::buildClusters().

55  {
56  realisticHits_.resize(numberOfHits);
57  realisticSimClusters_.resize(numberOfSimClusters);
58  for(auto& sc: realisticSimClusters_)
59  sc.setLayersNum(numberOfLayers);
60  }
std::vector< RealisticCluster > realisticSimClusters_
void RealisticHitToClusterAssociator::insertHitEnergy ( float  energy,
unsigned int  hitIndex 
)
inline

Definition at line 72 of file RealisticHitToClusterAssociator.h.

References realisticHits_.

Referenced by RealisticSimClusterMapper::buildClusters().

73  {
74  realisticHits_[hitIndex].totalEnergy_ = energy;
75  }
void RealisticHitToClusterAssociator::insertHitPosition ( float  x,
float  y,
float  z,
unsigned int  hitIndex 
)
inline

Definition at line 62 of file RealisticHitToClusterAssociator.h.

References realisticHits_, x, and y.

Referenced by RealisticSimClusterMapper::buildClusters().

63  {
64  realisticHits_[hitIndex].hitPosition_ = {{x,y,z}};
65  }
void RealisticHitToClusterAssociator::insertLayerId ( unsigned int  layerId,
unsigned int  hitIndex 
)
inline

Definition at line 67 of file RealisticHitToClusterAssociator.h.

References realisticHits_.

Referenced by RealisticSimClusterMapper::buildClusters().

68  {
69  realisticHits_[hitIndex].layerId_ = layerId;
70  }
void RealisticHitToClusterAssociator::insertSimClusterIdAndFraction ( unsigned int  scIdx,
float  fraction,
unsigned int  hitIndex,
float  associatedEnergy 
)
inline

Definition at line 77 of file RealisticHitToClusterAssociator.h.

References dedxEstimators_cff::fraction, RealisticHitToClusterAssociator::RealisticHit::hitPosition_, RealisticHitToClusterAssociator::RealisticHit::layerId_, realisticHits_, and realisticSimClusters_.

Referenced by RealisticSimClusterMapper::buildClusters().

79  {
80  realisticHits_[hitIndex].hitToCluster_.emplace_back(RealisticHit::HitToCluster{scIdx, fraction, 0.f, 0.f});
81  realisticSimClusters_[scIdx].setMaxEnergyHit(realisticHits_[hitIndex].layerId_, associatedEnergy, realisticHits_[hitIndex].hitPosition_);
82  }
std::vector< RealisticCluster > realisticSimClusters_
const std::vector< RealisticCluster >& RealisticHitToClusterAssociator::realisticClusters ( ) const
inline

Definition at line 326 of file RealisticHitToClusterAssociator.h.

References realisticSimClusters_.

Referenced by RealisticSimClusterMapper::buildClusters().

327  { return realisticSimClusters_;}
std::vector< RealisticCluster > realisticSimClusters_
float RealisticHitToClusterAssociator::XYdistanceFromMaxHit ( unsigned int  hitId,
unsigned int  clusterId 
)
inline

Definition at line 84 of file RealisticHitToClusterAssociator.h.

References RealisticHitToClusterAssociator::RealisticHit::hitPosition_, checklumidiff::l, funct::pow(), realisticHits_, realisticSimClusters_, and mathSSE::sqrt().

Referenced by computeAssociation().

85  {
86  auto l = realisticHits_[hitId].layerId_;
87  const auto& maxHitPosition = realisticSimClusters_[clusterId].getMaxEnergyPosition(l);
88  float distanceSquared = std::pow((realisticHits_[hitId].hitPosition_[0] - maxHitPosition[0]),2) + std::pow((realisticHits_[hitId].hitPosition_[1] - maxHitPosition[1]),2);
89  return std::sqrt(distanceSquared);
90  }
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< RealisticCluster > realisticSimClusters_
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
float RealisticHitToClusterAssociator::XYdistanceFromPointOnSameLayer ( unsigned int  hitId,
const Hit3DPosition point 
)
inline

Definition at line 92 of file RealisticHitToClusterAssociator.h.

References RealisticHitToClusterAssociator::RealisticHit::hitPosition_, funct::pow(), realisticHits_, and mathSSE::sqrt().

Referenced by filterHitsByDistance().

93  {
94  float distanceSquared = std::pow((realisticHits_[hitId].hitPosition_[0] - point[0]),2) + std::pow((realisticHits_[hitId].hitPosition_[1] - point[1]),2);
95  return std::sqrt(distanceSquared);
96  }
T sqrt(T t)
Definition: SSEVec.h:18
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5

Member Data Documentation

std::vector< RealisticHit > RealisticHitToClusterAssociator::realisticHits_
private
std::vector< RealisticCluster > RealisticHitToClusterAssociator::realisticSimClusters_
private