test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFClusterShapeAlgo.cc
Go to the documentation of this file.
2 
3 PFClusterShapeAlgo::PFClusterShapeAlgo(bool useFractions, double w0)
4 {
5  useFractions_ = useFractions;
6  w0_ = w0;
7 }
8 
10 {
11 }
12 
16  const CaloSubdetectorGeometry * the_barrelGeo_p,
17  const CaloSubdetectorTopology * the_barrelTop_p,
18  const CaloSubdetectorGeometry * the_endcapGeo_p,
19  const CaloSubdetectorTopology * the_endcapTop_p)
20 {
21  static const float etaEndOfBarrel = 1.497;
22 
23  topoVector.push_back(the_barrelTop_p);
24  topoVector.push_back(the_endcapTop_p);
25  geomVector.push_back(the_barrelGeo_p);
26  geomVector.push_back(the_endcapGeo_p);
27 
29 
30  currentRecHit_v_p = rechitHandle;
31 
32  for (unsigned int i = 0; i < clusterHandle->size(); ++i)
33  {
34  // Make each cluster the "current" cluster
35  currentCluster_p = reco::PFClusterRef(clusterHandle, i);
37 
38  // Find the right topology to use with this cluster
39  topoIndex = BARREL;
40  geomIndex = BARREL;
41  const math::XYZVector currentClusterPos(currentCluster_p->position());
42  if (fabs(currentClusterPos.eta()) > etaEndOfBarrel)
43  {
44  topoIndex = ENDCAP;
45  geomIndex = ENDCAP;
46  }
47 
48  // Create the clustershape and push it into the vector
49  shape_v_p->push_back(makeClusterShape());
50  }
51 
52  topoVector.clear();
53  topoVector.clear();
54  geomVector.clear();
55  geomVector.clear();
56 
57  return shape_v_p;
58 }
59 
61 {
63  fill5x5Map();
64 
65  find_e2x2();
66  find_e3x2();
67  find_e3x3();
68  find_e4x4();
69  find_e5x5();
70 
72  find_e2x5Left();
73  find_e2x5Top();
75 
76  covariances();
77 
78  double dummyLAT = 0;
79  double dummyEtaLAT = 0;
80  double dummyPhiLAT = 0;
81  double dummyA20 = 0;
82  double dummyA42 = 0;
83 
84  std::vector<double> dummyEnergyBasketFractionEta_v;
85  std::vector<double> dummyEnergyBasketFractionPhi_v;
86 
91  dummyLAT, dummyEtaLAT, dummyPhiLAT, dummyA20, dummyA42,
92  dummyEnergyBasketFractionEta_v, dummyEnergyBasketFractionPhi_v);
93 }
94 
95 
97 {
98  std::map<double, DetId> energyMap;
99 
100  // First get the RecHitFractions:
101  const std::vector<reco::PFRecHitFraction> & fraction_v = currentCluster_p->recHitFractions();
102  // For every one of them...
103  for (std::vector<reco::PFRecHitFraction>::const_iterator it = fraction_v.begin(); it != fraction_v.end(); ++it)
104  {
105  // ...find the corresponding rechit:
106  // const reco::PFRecHit & rechit = (*currentRecHit_v_p)[it->recHitIndex()];
107  const reco::PFRecHitRef rechit = it->recHitRef();
108  // ...and DetId:
109  const DetId rechitDetId = DetId(rechit->detId());
110  // Make the new Pair and put it in the map:
111  energyMap[rechit->energy()] = rechitDetId;
112  }
113  // maps are sorted in ascending order so get the last two elements:
114  std::map<double, DetId>::reverse_iterator it = energyMap.rbegin();
115  eMax_ = it->first;
116  eMaxId_ = it->second;
117  it++;
118  e2nd_ = it->first;
119  e2ndId_ = it->second;
120 }
121 
123 {
124  int index = -1; // need some negative number
125  for (unsigned int k = 0; k < currentRecHit_v_p->size(); ++k)
126  {
127  if ((*currentRecHit_v_p)[k].detId() == id)
128  {
129  index = static_cast<int>(k);
130  break;
131  }
132  }
133  return index;
134 }
135 
136 
138 {
139  const std::vector< reco::PFRecHitFraction > & fraction_v = currentCluster_p->recHitFractions();
140  for (std::vector<reco::PFRecHitFraction>::const_iterator it = fraction_v.begin(); it != fraction_v.end(); ++it)
141  {
142  //const unsigned int rhIndex = it->recHitIndex();
143  //reco::PFRecHitRef rh_p(currentRecHit_v_p, rhIndex);
144  const reco::PFRecHitRef rh_p = it->recHitRef();
145  const DetId rhDetId = DetId(rh_p->detId());
146  if (rhDetId == id)
147  {
148  return &(*it);
149  }
150  }
151  return 0;
152 }
153 
154 
156 {
157  // first get a navigator to the central element
159 
160  meanPosition_ = math::XYZVector(0.0, 0.0, 0.0);
161  totalE_ = 0;
162 
163  for (int i = 0; i < 5; ++i)
164  {
165  for (int j = 0; j < 5; ++j)
166  {
167  position.home();
168  position.offsetBy(i - 2, j - 2);
169 
170  RecHitWithFraction newEntry;
171  newEntry.detId = DetId(0);
172  newEntry.energy = 0.0;
173  newEntry.position = math::XYZVector(0, 0, 0);
174 
175  if (*position != DetId(0)) // if this is a valid detId...
176  {
177  // ...find the corresponding PFRecHit index
178  const int index = findPFRHIndexFromDetId((*position).rawId());
179 
180  if (index >= 0) // if a PFRecHit exists for this detId
181  {
182  double fraction = 1.0;
183  if (useFractions_) // if the algorithm should use fractions
184  {
185  fraction = 0.0;
186  const reco::PFRecHitFraction * fraction_p = getFractionFromDetId(*position);
187  if (fraction_p) { fraction = fraction_p->fraction(); }
188  }
189 
190  const reco::PFRecHitRef rhRef(currentRecHit_v_p, index);
191  const math::XYZVector crystalPosition(rhRef->position());
192  const double energyFraction = rhRef->energy() * fraction;
193 
194  newEntry.detId = *position;
195  newEntry.energy = energyFraction;
196  newEntry.position = crystalPosition;
197 
198  meanPosition_ = meanPosition_ + crystalPosition * energyFraction;
199  totalE_ += energyFraction;
200  }
201  }
202  map5x5[i][j] = newEntry;
203  }
204  }
205  meanPosition_ /= totalE_;
206 }
207 
208 double PFClusterShapeAlgo::addMapEnergies(int etaIndexLow, int etaIndexHigh, int phiIndexLow, int phiIndexHigh)
209 {
210  const int etaLow = etaIndexLow + 2;
211  const int etaHigh = etaIndexHigh + 2;
212  const int phiLow = phiIndexLow + 2;
213  const int phiHigh = phiIndexHigh + 2;
214 
215  double energy = 0;
216 
217  for (int i = etaLow; i <= etaHigh; ++i)
218  {
219  for (int j = phiLow; j <= phiHigh; ++j)
220  {
221  energy += map5x5[i][j].energy;
222  }
223  }
224  return energy;
225 }
226 
233 
235 {
236  if (eMaxDir == SE) { e4x4_ = addMapEnergies(-2, +1, -2, +1); return; }
237  if (eMaxDir == NE) { e4x4_ = addMapEnergies(-2, +1, -1, +2); return; }
238  if (eMaxDir == SW) { e4x4_ = addMapEnergies(-1, +2, -2, +1); return; }
239  if (eMaxDir == NW) { e4x4_ = addMapEnergies(-1, +2, -1, +2); return; }
240 }
241 
243 {
244  std::map<double, Direction> directionMap;
245 
246  directionMap[addMapEnergies(-1, +0, -1, +0)] = SE;
247  directionMap[addMapEnergies(-1, +0, +0, +1)] = NE;
248  directionMap[addMapEnergies(+0, +1, -1, +0)] = SW;
249  directionMap[addMapEnergies(+0, +1, +0, +1)] = NW;
250 
251  const std::map<double, Direction>::reverse_iterator eMaxDir_it = directionMap.rbegin();
252 
253  eMaxDir = eMaxDir_it->second;
254 
255  e2x2_ = eMaxDir_it->first;
256 }
257 
259 {
260  // Find the direction of the highest energy neighbour
261  std::map<double, Direction> directionMap;
262  directionMap[map5x5[2][3].energy] = N;
263  directionMap[map5x5[2][1].energy] = S;
264  directionMap[map5x5[1][2].energy] = E;
265  directionMap[map5x5[3][2].energy] = W;
266  // Maps are sorted in ascending order - get the last element
267  const Direction dir = directionMap.rbegin()->second;
268 
269  if (dir == N)
270  {
271  e3x2_ = addMapEnergies(-1, +1, +0, +1);
272  const double numerator = map5x5[3][2].energy + map5x5[1][2].energy;
273  const double denominator = map5x5[1][3].energy + map5x5[3][3].energy + 0.5;
274  e3x2Ratio_ = numerator / denominator;
275  }
276  else if (dir == S)
277  {
278  e3x2_ = addMapEnergies(-1, +1, -1, +0);
279  const double numerator = map5x5[3][2].energy + map5x5[1][2].energy;
280  const double denominator = map5x5[1][1].energy + map5x5[3][1].energy + 0.5;
281  e3x2Ratio_ = numerator / denominator;
282  }
283  else if (dir == W)
284  {
285  e3x2_ = addMapEnergies(+0, +1, -1, +1);
286  const double numerator = map5x5[2][3].energy + map5x5[2][1].energy;
287  const double denominator = map5x5[3][3].energy + map5x5[3][1].energy + 0.5;
288  e3x2Ratio_ = numerator / denominator;
289  }
290  else if (dir == E)
291  {
292  e3x2_ = addMapEnergies(-1, +0, -1, +1);
293  const double numerator = map5x5[2][3].energy + map5x5[2][1].energy;
294  const double denominator = map5x5[1][1].energy + map5x5[1][3].energy + 0.5;
295  e3x2Ratio_ = numerator / denominator;
296  }
297 }
298 
300 {
301  double numeratorEtaEta = 0;
302  double numeratorEtaPhi = 0;
303  double numeratorPhiPhi = 0;
304  double denominator = 0;
305 
306  for (int i = 0; i < 5; ++i)
307  {
308  for (int j = 0; j < 5; ++j)
309  {
310  const math::XYZVector & crystalPosition(map5x5[i][j].position);
311 
312  double dPhi = crystalPosition.phi() - meanPosition_.phi();
313  if (dPhi > + Geom::pi()) { dPhi = Geom::twoPi() - dPhi; }
314  if (dPhi < - Geom::pi()) { dPhi = Geom::twoPi() - dPhi; }
315 
316  const double dEta = crystalPosition.eta() - meanPosition_.eta();
317 
318  const double w = std::max(0.0, w0_ + log(map5x5[i][j].energy / totalE_));
319 
320  denominator += w;
321  numeratorEtaEta += w * dEta * dEta;
322  numeratorEtaPhi += w * dEta * dPhi;
323  numeratorPhiPhi += w * dPhi * dPhi;
324  }
325  }
326 
327  covEtaEta_ = numeratorEtaEta / denominator;
328  covEtaPhi_ = numeratorEtaPhi / denominator;
329  covPhiPhi_ = numeratorPhiPhi / denominator;
330 }
331 
332 
333 
int i
Definition: DBlmapReader.cc:9
math::XYZVector position
list numerator
Definition: cuy.py:483
const double w
Definition: UKUtility.cc:23
reco::ClusterShape makeClusterShape()
Fraction of a PFRecHit (rechits can be shared between several PFCluster&#39;s)
std::vector< ClusterShape > ClusterShapeCollection
collection of ClusterShape objects
double fraction() const
int findPFRHIndexFromDetId(unsigned int id)
math::XYZVector meanPosition_
std::vector< const CaloSubdetectorGeometry * > geomVector
T offsetBy(int deltaX, int deltaY) const
Free movement of arbitray steps.
Definition: CaloNavigator.h:80
list denominator
Definition: cuy.py:484
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
edm::Ref< PFClusterCollection > PFClusterRef
persistent reference to PFCluster objects
Definition: PFClusterFwd.h:15
int j
Definition: DBlmapReader.cc:9
reco::ClusterShapeCollection * makeClusterShapes(edm::Handle< reco::PFClusterCollection > clusterHandle, edm::Handle< reco::PFRecHitCollection > rechitHandle, const CaloSubdetectorGeometry *barrelGeo_p, const CaloSubdetectorTopology *barrelTop_p, const CaloSubdetectorGeometry *endcapGeo_p, const CaloSubdetectorTopology *endcapTop_p)
RecHitWithFraction map5x5[5][5]
reco::PFClusterRef currentCluster_p
unsigned int currentClusterIndex_
void home() const
move the navigator back to the starting point
Definition: DetId.h:18
edm::Handle< reco::PFRecHitCollection > currentRecHit_v_p
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
std::vector< const CaloSubdetectorTopology * > topoVector
double addMapEnergies(int etaIndexLow, int etaIndexHigh, int phiIndexLow, int phiIndexHigh)
static int position[264][3]
Definition: ReadPGInfo.cc:509
const reco::PFRecHitFraction * getFractionFromDetId(const DetId &id)
dbl *** dir
Definition: mlp_gen.cc:35
constexpr double pi()
Definition: Pi.h:31
constexpr double twoPi()
Definition: Pi.h:32
PFClusterShapeAlgo(bool useFractions, double w0)