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