CMS 3D CMS Logo

Mustache.cc
Go to the documentation of this file.
2 #include "TVector2.h"
3 #include <cmath>
4 using namespace std;
5 
6 namespace reco {
7  namespace MustacheKernel {
9  const float maxEta,
10  const float maxPhi,
11  const float ClustE,
12  const float ClusEta,
13  const float ClusPhi) {
14  const auto log10ClustE = std::log10(ClustE);
15  const auto parabola_params = params->parabolaParameters(log10ClustE, std::abs(ClusEta));
16  if (!parabola_params) {
17  return false;
18  }
19 
20  const float sineta0 = std::sin(maxEta);
21  const float eta0xsineta0 = maxEta * sineta0;
22 
23  //2 parabolas (upper and lower)
24  //of the form: y = a*x*x + b
25 
26  //b comes from a fit to the width
27  //and has a slight dependence on E on the upper edge
28  // this only works because of fine tuning :-D
29  const float sqrt_log10_clustE = std::sqrt(log10ClustE + params->sqrtLogClustETuning());
30  const float b_upper =
31  parabola_params->w1Up[0] * eta0xsineta0 + parabola_params->w1Up[1] / sqrt_log10_clustE -
32  0.5 * (parabola_params->w1Up[0] * eta0xsineta0 + parabola_params->w1Up[1] / sqrt_log10_clustE +
33  parabola_params->w0Up[0] * eta0xsineta0 + parabola_params->w0Up[1] / sqrt_log10_clustE);
34  const float b_lower =
35  parabola_params->w0Low[0] * eta0xsineta0 + parabola_params->w0Low[1] / sqrt_log10_clustE -
36  0.5 * (parabola_params->w1Low[0] * eta0xsineta0 + parabola_params->w1Low[1] / sqrt_log10_clustE +
37  parabola_params->w0Low[0] * eta0xsineta0 + parabola_params->w0Low[1] / sqrt_log10_clustE);
38 
39  //the curvature comes from a parabolic
40  //fit for many slices in eta given a
41  //slice -0.1 < log10(Et) < 0.1
42  const float curv_up =
43  eta0xsineta0 * (parabola_params->pUp[0] * eta0xsineta0 + parabola_params->pUp[1]) + parabola_params->pUp[2];
44  const float curv_low = eta0xsineta0 * (parabola_params->pLow[0] * eta0xsineta0 + parabola_params->pLow[1]) +
45  parabola_params->pLow[2];
46 
47  //solving for the curviness given the width of this particular point
48  const float a_upper = (1. / (4. * curv_up)) - std::abs(b_upper);
49  const float a_lower = (1. / (4. * curv_low)) - std::abs(b_lower);
50 
51  const double dphi = TVector2::Phi_mpi_pi(ClusPhi - maxPhi);
52  const double dphi2 = dphi * dphi;
53  // minimum offset is half a crystal width in either direction
54  // because science.
55  constexpr float half_crystal_width = 0.0087;
56  const float upper_cut =
57  (std::max((1. / (4. * a_upper)), 0.0) * dphi2 + std::max(b_upper, half_crystal_width)) + half_crystal_width;
58  const float lower_cut = (std::max((1. / (4. * a_lower)), 0.0) * dphi2 + std::min(b_lower, -half_crystal_width));
59 
60  const float deta = (1 - 2 * (maxEta < 0)) * (ClusEta - maxEta); // sign flip deta
61  return (deta < upper_cut && deta > lower_cut);
62  }
63 
65  const float seedEta,
66  const float seedPhi,
67  const float ClustE,
68  const float ClusEta,
69  const float ClusPhi) {
70  const double absSeedEta = std::abs(seedEta);
71  const double logClustEt = std::log10(ClustE / std::cosh(ClusEta));
72  const double clusDphi = std::abs(TVector2::Phi_mpi_pi(seedPhi - ClusPhi));
73 
74  const auto dynamicDPhiParams = params->dynamicDPhiParameters(ClustE, absSeedEta);
75  if (!dynamicDPhiParams) {
76  return false;
77  }
78 
79  auto maxdphi = dynamicDPhiParams->yoffset +
80  dynamicDPhiParams->scale /
81  (1. + std::exp((logClustEt - dynamicDPhiParams->xoffset) / dynamicDPhiParams->width));
82  maxdphi = std::min(maxdphi, dynamicDPhiParams->cutoff);
83  maxdphi = std::max(maxdphi, dynamicDPhiParams->saturation);
84 
85  return clusDphi < maxdphi;
86  }
87  } // namespace MustacheKernel
88 
89  Mustache::Mustache(const EcalMustacheSCParameters* mustache_params) : mustache_params_(mustache_params) {}
90 
91  void Mustache::MustacheID(const reco::SuperCluster& sc, int& nclusters, float& EoutsideMustache) {
92  MustacheID(sc.clustersBegin(), sc.clustersEnd(), nclusters, EoutsideMustache);
93  }
94 
95  void Mustache::MustacheID(const CaloClusterPtrVector& clusters, int& nclusters, float& EoutsideMustache) {
96  MustacheID(clusters.begin(), clusters.end(), nclusters, EoutsideMustache);
97  }
98 
99  void Mustache::MustacheID(const std::vector<const CaloCluster*>& clusters, int& nclusters, float& EoutsideMustache) {
100  MustacheID(clusters.cbegin(), clusters.cend(), nclusters, EoutsideMustache);
101  }
102 
103  template <class RandomAccessPtrIterator>
104  void Mustache::MustacheID(const RandomAccessPtrIterator& begin,
105  const RandomAccessPtrIterator& end,
106  int& nclusters,
107  float& EoutsideMustache) {
108  nclusters = 0;
109  EoutsideMustache = 0;
110 
111  unsigned int ncl = end - begin;
112  if (!ncl)
113  return;
114 
115  //loop over all clusters to find the one with highest energy
116  RandomAccessPtrIterator icl = begin;
117  RandomAccessPtrIterator clmax = end;
118  float emax = 0;
119  for (; icl != end; ++icl) {
120  const float e = (*icl)->energy();
121  if (e > emax) {
122  emax = e;
123  clmax = icl;
124  }
125  }
126 
127  if (end == clmax)
128  return;
129 
130  float eta0 = (*clmax)->eta();
131  float phi0 = (*clmax)->phi();
132 
133  bool inMust = false;
134  icl = begin;
135  for (; icl != end; ++icl) {
136  inMust = MustacheKernel::inMustache(mustache_params_, eta0, phi0, (*icl)->energy(), (*icl)->eta(), (*icl)->phi());
137 
138  nclusters += (int)!inMust;
139  EoutsideMustache += (!inMust) * ((*icl)->energy());
140  }
141  }
142 
143  void Mustache::MustacheClust(const std::vector<CaloCluster>& clusters,
144  std::vector<unsigned int>& insideMust,
145  std::vector<unsigned int>& outsideMust) {
146  unsigned int ncl = clusters.size();
147  if (!ncl)
148  return;
149 
150  //loop over all clusters to find the one with highest energy
151  float emax = 0;
152  int imax = -1;
153  for (unsigned int i = 0; i < ncl; ++i) {
154  float e = (clusters[i]).energy();
155  if (e > emax) {
156  emax = e;
157  imax = i;
158  }
159  }
160 
161  if (imax < 0)
162  return;
163  float eta0 = (clusters[imax]).eta();
164  float phi0 = (clusters[imax]).phi();
165 
166  for (unsigned int k = 0; k < ncl; k++) {
167  bool inMust = MustacheKernel::inMustache(
168  mustache_params_, eta0, phi0, (clusters[k]).energy(), (clusters[k]).eta(), (clusters[k]).phi());
169  //return indices of Clusters outside the Mustache
170  if (!(inMust)) {
171  outsideMust.push_back(k);
172  } else { //return indices of Clusters inside the Mustache
173  insideMust.push_back(k);
174  }
175  }
176  }
177 
178  void Mustache::FillMustacheVar(const std::vector<CaloCluster>& clusters) {
182  excluded_ = 0;
183  included_ = 0;
184  std::multimap<float, unsigned int> OrderedClust;
185  std::vector<unsigned int> insideMust;
186  std::vector<unsigned int> outsideMust;
187  MustacheClust(clusters, insideMust, outsideMust);
188  included_ = insideMust.size();
189  excluded_ = outsideMust.size();
190  for (unsigned int i = 0; i < insideMust.size(); ++i) {
191  unsigned int index = insideMust[i];
193  OrderedClust.insert(make_pair(clusters[index].energy(), index));
194  }
195  for (unsigned int i = 0; i < outsideMust.size(); ++i) {
196  unsigned int index = outsideMust[i];
199  }
200  std::multimap<float, unsigned int>::iterator it;
201  it = OrderedClust.begin();
202  unsigned int lowEindex = (*it).second;
203  LowestClusterEInMustache_ = clusters[lowEindex].energy();
204  }
205 } // namespace reco
void MustacheID(const CaloClusterPtrVector &clusters, int &nclusters, float &EoutsideMustache)
Definition: Mustache.cc:95
const float maxdphi
Definition: Config.cc:38
void MustacheClust(const std::vector< CaloCluster > &clusters, std::vector< unsigned int > &insideMust, std::vector< unsigned int > &outsideMust)
Definition: Mustache.cc:143
float Energy_In_Mustache_
Definition: Mustache.h:56
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:88
bool inMustache(const EcalMustacheSCParameters *params, const float maxEta, const float maxPhi, const float ClustE, const float ClusEta, const float ClusPhi)
Definition: Mustache.cc:8
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:91
float LowestClusterEInMustache_
Definition: Mustache.h:59
float Et_Outside_Mustache_
Definition: Mustache.h:58
T sqrt(T t)
Definition: SSEVec.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
fixed size matrix
bool inDynamicDPhiWindow(const EcalSCDynamicDPhiParameters *params, const float seedEta, const float seedPhi, const float ClustE, const float ClusEta, const float clusPhi)
Definition: Mustache.cc:64
static int position[264][3]
Definition: ReadPGInfo.cc:289
float Energy_Outside_Mustache_
Definition: Mustache.h:57
const EcalMustacheSCParameters * mustache_params_
Definition: Mustache.h:62
void FillMustacheVar(const std::vector< CaloCluster > &clusters)
Definition: Mustache.cc:178
Geom::Theta< T > theta() const