CMS 3D CMS Logo

Mustache.cc
Go to the documentation of this file.
2 #include "TMath.h"
3 #include "TVector2.h"
4 #include <cmath>
5 using namespace std;
6 
7 namespace reco {
8  namespace MustacheKernel {
9  bool inMustache(
10  const float maxEta, const float maxPhi, const float ClustE, const float ClusEta, const float ClusPhi) {
11  //bool inMust=false;
12  //float eta0 = maxEta;
13  //float phi0 = maxPhi;
14 
15  constexpr float p00 = -0.107537;
16  constexpr float p01 = 0.590969;
17  constexpr float p02 = -0.076494;
18  constexpr float p10 = -0.0268843;
19  constexpr float p11 = 0.147742;
20  constexpr float p12 = -0.0191235;
21 
22  constexpr float w00 = -0.00571429;
23  constexpr float w01 = -0.002;
24  constexpr float w10 = 0.0135714;
25  constexpr float w11 = 0.001;
26 
27  const float sineta0 = std::sin(maxEta);
28  const float eta0xsineta0 = maxEta * sineta0;
29 
30  //2 parabolas (upper and lower)
31  //of the form: y = a*x*x + b
32 
33  //b comes from a fit to the width
34  //and has a slight dependence on E on the upper edge
35  // this only works because of fine tuning :-D
36  const float sqrt_log10_clustE = std::sqrt(std::log10(ClustE) + 1.1);
37  // we need to have this in two steps, so that we don't improperly shift
38  // the lower bound!
39  float b_upper = w10 * eta0xsineta0 + w11 / sqrt_log10_clustE;
40  float b_lower = w00 * eta0xsineta0 + w01 / sqrt_log10_clustE;
41  const float midpoint = 0.5 * (b_upper + b_lower);
42  b_upper -= midpoint;
43  b_lower -= midpoint;
44 
45  //the curvature comes from a parabolic
46  //fit for many slices in eta given a
47  //slice -0.1 < log10(Et) < 0.1
48  const float curv_up = eta0xsineta0 * (p00 * eta0xsineta0 + p01) + p02;
49  const float curv_low = eta0xsineta0 * (p10 * eta0xsineta0 + p11) + p12;
50 
51  //solving for the curviness given the width of this particular point
52  const float a_upper = (1 / (4 * curv_up)) - fabs(b_upper);
53  const float a_lower = (1 / (4 * curv_low)) - fabs(b_lower);
54 
55  const double dphi = TVector2::Phi_mpi_pi(ClusPhi - maxPhi);
56  const double dphi2 = dphi * dphi;
57  // minimum offset is half a crystal width in either direction
58  // because science.
59  const float upper_cut = (std::max((1. / (4. * a_upper)), 0.0) * dphi2 + std::max(b_upper, 0.0087f)) + 0.0087;
60  const float lower_cut = (std::max((1. / (4. * a_lower)), 0.0) * dphi2 + std::min(b_lower, -0.0087f));
61 
62  //if(deta < upper_cut && deta > lower_cut) inMust=true;
63 
64  const float deta = (1 - 2 * (maxEta < 0)) * (ClusEta - maxEta); // sign flip deta
65  return (deta < upper_cut && deta > lower_cut);
66  }
67 
69  const float seedEta, const float seedPhi, const float ClustE, const float ClusEta, const float ClusPhi) {
70  // from Rishi's fits 06 June 2013 in log base 10
71  constexpr double yoffsetEB = 7.151e-02;
72  constexpr double scaleEB = 5.656e-01;
73  constexpr double xoffsetEB = 2.931e-01;
74  constexpr double widthEB = 2.976e-01;
75 
76  constexpr double yoffsetEE_0 = 5.058e-02;
77  constexpr double scaleEE_0 = 7.131e-01;
78  constexpr double xoffsetEE_0 = 1.668e-02;
79  constexpr double widthEE_0 = 4.114e-01;
80 
81  constexpr double yoffsetEE_1 = -9.913e-02;
82  constexpr double scaleEE_1 = 4.404e+01;
83  constexpr double xoffsetEE_1 = -5.326e+00;
84  constexpr double widthEE_1 = 1.184e+00;
85 
86  constexpr double yoffsetEE_2 = -6.346e-01;
87  constexpr double scaleEE_2 = 1.317e+01;
88  constexpr double xoffsetEE_2 = -7.037e+00;
89  constexpr double widthEE_2 = 2.836e+00;
90 
91  const double absSeedEta = std::abs(seedEta);
92  const int etaBin = ((int)(absSeedEta >= 1.479) + (int)(absSeedEta >= 1.75) + (int)(absSeedEta >= 2.0));
93  const double logClustEt = std::log10(ClustE / std::cosh(ClusEta));
94  const double clusDphi = std::abs(TVector2::Phi_mpi_pi(seedPhi - ClusPhi));
95 
96  double yoffset, scale, xoffset, width, saturation, cutoff, maxdphi;
97 
98  switch (etaBin) {
99  case 0: // EB
100  yoffset = yoffsetEB;
101  scale = scaleEB;
102  xoffset = xoffsetEB;
103  width = 1.0 / widthEB;
104  saturation = 0.14;
105  cutoff = 0.60;
106  break;
107  case 1: // 1.479 -> 1.75
108  yoffset = yoffsetEE_0;
109  scale = scaleEE_0;
110  xoffset = xoffsetEE_0;
111  width = 1.0 / widthEE_0;
112  saturation = 0.14;
113  cutoff = 0.55;
114  break;
115  case 2: // 1.75 -> 2.0
116  yoffset = yoffsetEE_1;
117  scale = scaleEE_1;
118  xoffset = xoffsetEE_1;
119  width = 1.0 / widthEE_1;
120  saturation = 0.12;
121  cutoff = 0.45;
122  break;
123  case 3: // 2.0 and up
124  yoffset = yoffsetEE_2;
125  scale = scaleEE_2;
126  xoffset = xoffsetEE_2;
127  width = 1.0 / widthEE_2;
128  saturation = 0.12;
129  cutoff = 0.30;
130  break;
131  default:
132  throw cms::Exception("InValidEtaBin")
133  << "Calculated invalid eta bin = " << etaBin << " in \"inDynamicDPhiWindow\"" << std::endl;
134  }
135 
136  maxdphi = yoffset + scale / (1 + std::exp((logClustEt - xoffset) * width));
137  maxdphi = std::min(maxdphi, cutoff);
138  maxdphi = std::max(maxdphi, saturation);
139 
140  return clusDphi < maxdphi;
141  }
142  } // namespace MustacheKernel
143 
144  void Mustache::MustacheID(const reco::SuperCluster& sc, int& nclusters, float& EoutsideMustache) {
145  MustacheID(sc.clustersBegin(), sc.clustersEnd(), nclusters, EoutsideMustache);
146  }
147 
148  void Mustache::MustacheID(const CaloClusterPtrVector& clusters, int& nclusters, float& EoutsideMustache) {
149  MustacheID(clusters.begin(), clusters.end(), nclusters, EoutsideMustache);
150  }
151 
152  void Mustache::MustacheID(const std::vector<const CaloCluster*>& clusters, int& nclusters, float& EoutsideMustache) {
153  MustacheID(clusters.cbegin(), clusters.cend(), nclusters, EoutsideMustache);
154  }
155 
156  template <class RandomAccessPtrIterator>
157  void Mustache::MustacheID(const RandomAccessPtrIterator& begin,
158  const RandomAccessPtrIterator& end,
159  int& nclusters,
160  float& EoutsideMustache) {
161  nclusters = 0;
162  EoutsideMustache = 0;
163 
164  unsigned int ncl = end - begin;
165  if (!ncl)
166  return;
167 
168  //loop over all clusters to find the one with highest energy
169  RandomAccessPtrIterator icl = begin;
170  RandomAccessPtrIterator clmax = end;
171  float emax = 0;
172  for (; icl != end; ++icl) {
173  const float e = (*icl)->energy();
174  if (e > emax) {
175  emax = e;
176  clmax = icl;
177  }
178  }
179 
180  if (end == clmax)
181  return;
182 
183  float eta0 = (*clmax)->eta();
184  float phi0 = (*clmax)->phi();
185 
186  bool inMust = false;
187  icl = begin;
188  for (; icl != end; ++icl) {
189  inMust = MustacheKernel::inMustache(eta0, phi0, (*icl)->energy(), (*icl)->eta(), (*icl)->phi());
190 
191  nclusters += (int)!inMust;
192  EoutsideMustache += (!inMust) * ((*icl)->energy());
193  }
194  }
195 
196  void Mustache::MustacheClust(const std::vector<CaloCluster>& clusters,
197  std::vector<unsigned int>& insideMust,
198  std::vector<unsigned int>& outsideMust) {
199  unsigned int ncl = clusters.size();
200  if (!ncl)
201  return;
202 
203  //loop over all clusters to find the one with highest energy
204  float emax = 0;
205  int imax = -1;
206  for (unsigned int i = 0; i < ncl; ++i) {
207  float e = (clusters[i]).energy();
208  if (e > emax) {
209  emax = e;
210  imax = i;
211  }
212  }
213 
214  if (imax < 0)
215  return;
216  float eta0 = (clusters[imax]).eta();
217  float phi0 = (clusters[imax]).phi();
218 
219  for (unsigned int k = 0; k < ncl; k++) {
220  bool inMust =
221  MustacheKernel::inMustache(eta0, phi0, (clusters[k]).energy(), (clusters[k]).eta(), (clusters[k]).phi());
222  //return indices of Clusters outside the Mustache
223  if (!(inMust)) {
224  outsideMust.push_back(k);
225  } else { //return indices of Clusters inside the Mustache
226  insideMust.push_back(k);
227  }
228  }
229  }
230 
231  void Mustache::FillMustacheVar(const std::vector<CaloCluster>& clusters) {
232  Energy_In_Mustache_ = 0;
233  Energy_Outside_Mustache_ = 0;
234  LowestClusterEInMustache_ = 0;
235  excluded_ = 0;
236  included_ = 0;
237  std::multimap<float, unsigned int> OrderedClust;
238  std::vector<unsigned int> insideMust;
239  std::vector<unsigned int> outsideMust;
240  MustacheClust(clusters, insideMust, outsideMust);
241  included_ = insideMust.size();
242  excluded_ = outsideMust.size();
243  for (unsigned int i = 0; i < insideMust.size(); ++i) {
244  unsigned int index = insideMust[i];
245  Energy_In_Mustache_ = clusters[index].energy() + Energy_In_Mustache_;
246  OrderedClust.insert(make_pair(clusters[index].energy(), index));
247  }
248  for (unsigned int i = 0; i < outsideMust.size(); ++i) {
249  unsigned int index = outsideMust[i];
250  Energy_Outside_Mustache_ = clusters[index].energy() + Energy_Outside_Mustache_;
251  Et_Outside_Mustache_ = clusters[index].energy() * sin(clusters[index].position().theta()) + Et_Outside_Mustache_;
252  }
253  std::multimap<float, unsigned int>::iterator it;
254  it = OrderedClust.begin();
255  unsigned int lowEindex = (*it).second;
256  LowestClusterEInMustache_ = clusters[lowEindex].energy();
257  }
258 } // namespace reco
ApeEstimator_cff.width
width
Definition: ApeEstimator_cff.py:24
mps_fire.i
i
Definition: mps_fire.py:355
w10
common ppss p3p6s2 common epss epspn46 common const1 w10
Definition: inclppp.h:1
etaBin
int etaBin(const l1t::HGCalMulticluster *cl)
Definition: L1EGammaEEProducer.cc:19
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
qjetsadder_cfi.cutoff
cutoff
Definition: qjetsadder_cfi.py:11
reco::SuperCluster
Definition: SuperCluster.h:18
min
T min(T a, T b)
Definition: MathUtil.h:58
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
end
#define end
Definition: vmac.h:39
w11
common ppss p3p6s2 common epss epspn46 common const1 w11
Definition: inclppp.h:1
Mustache.h
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
HLT_2018_cff.maxPhi
maxPhi
Definition: HLT_2018_cff.py:51498
edm::PtrVector< CaloCluster >
PVValHelper::eta
Definition: PVValidationHelpers.h:69
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
maxEta
double maxEta
Definition: PFJetBenchmarkAnalyzer.cc:76
theta
Geom::Theta< T > theta() const
Definition: Basic3DVectorLD.h:150
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
reco::MustacheKernel::inDynamicDPhiWindow
bool inDynamicDPhiWindow(const float seedEta, const float seedPhi, const float ClustE, const float ClusEta, const float clusPhi)
Definition: Mustache.cc:68
dqmdumpme.k
k
Definition: dqmdumpme.py:60
bsc_activity_cfg.clusters
clusters
Definition: bsc_activity_cfg.py:36
Scenarios_cff.scale
scale
Definition: Scenarios_cff.py:2186
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
createfilelist.int
int
Definition: createfilelist.py:10
reco::SuperCluster::clustersBegin
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:86
std
Definition: JetResolutionObject.h:76
Exception
Definition: hltDiff.cc:246
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
reco::MustacheKernel::inMustache
bool inMustache(const float maxEta, const float maxPhi, const float ClustE, const float ClusEta, const float ClusPhi)
Definition: Mustache.cc:9
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
reco::SuperCluster::clustersEnd
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:89
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
begin
#define begin
Definition: vmac.h:32
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37