CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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=std::max(eta0xsineta0*(p00*eta0xsineta0+p01)+p02,
51  0.0f);
52  const float curv_low=std::max(eta0xsineta0*(p10*eta0xsineta0+p11)+p12,
53  0.0f);
54 
55  //solving for the curviness given the width of this particular point
56  const float a_upper=(1/(4*curv_up))-fabs(b_upper);
57  const float a_lower = (1/(4*curv_low))-fabs(b_lower);
58 
59  const double dphi=TVector2::Phi_mpi_pi(ClusPhi-maxPhi);
60  const double dphi2 = dphi*dphi;
61  // minimum offset is half a crystal width in either direction
62  // because science.
63  const float upper_cut=( std::max((1./(4.*a_upper)),0.0)*dphi2 +
64  std::max(b_upper,0.0087f) );
65  const float lower_cut=( std::max((1./(4.*a_lower)),0.0)*dphi2 +
66  std::min(b_lower,-0.0087f) );
67 
68  //if(deta < upper_cut && deta > lower_cut) inMust=true;
69 
70  const float deta=(1-2*(maxEta<0))*(ClusEta-maxEta); // sign flip deta
71  return (deta < upper_cut && deta > lower_cut);
72  }
73 
74  bool inDynamicDPhiWindow(const bool isEB, const float seedPhi,
75  const float ClustE, const float ClusEta,
76  const float ClusPhi) {
77  // from Rishi's fit 21 May 2013
78  constexpr double yoffsetEB = 0.04635;
79  constexpr double scaleEB = 0.6514;
80  constexpr double xoffsetEB = 0.5709;
81  constexpr double widthEB = 0.7814;
82 
83  constexpr double yoffsetEE = 0.0453;
84  constexpr double scaleEE = 0.7416;
85  constexpr double xoffsetEE = 0.09217;
86  constexpr double widthEE = 1.059;
87 
88  double maxdphi;
89 
90  const double logClustEt = std::log(ClustE/std::cosh(ClusEta));
91  const double clusDphi = std::abs(TVector2::Phi_mpi_pi(seedPhi -
92  ClusPhi));
93  if( isEB ) {
94  maxdphi = (yoffsetEB + scaleEB/(1+std::exp((logClustEt -
95  xoffsetEB)/widthEB)));
96  } else {
97  maxdphi = (yoffsetEE + scaleEE/(1+std::exp((logClustEt -
98  xoffsetEE)/widthEE)));
99  }
100  maxdphi = ( logClustEt > 2.0 ) ? 0.15 : maxdphi;
101  maxdphi = ( logClustEt < -1.0 ) ? 0.6 : maxdphi;
102 
103  return clusDphi < maxdphi;
104  }
105  }
106 
107  void Mustache::MustacheID(const reco::SuperCluster& sc,
108  int & nclusters,
109  float & EoutsideMustache) {
110  MustacheID(sc.clustersBegin(),sc.clustersEnd(),
111  nclusters, EoutsideMustache);
112  }
113 
114  void Mustache::MustacheID(const CaloClusterPtrVector& clusters,
115  int & nclusters,
116  float & EoutsideMustache) {
117  MustacheID(clusters.begin(),clusters.end(),nclusters,EoutsideMustache);
118  }
119 
120  void Mustache::MustacheID(const std::vector<const CaloCluster*>& clusters,
121  int & nclusters,
122  float & EoutsideMustache) {
123  MustacheID(clusters.cbegin(),clusters.cend(),nclusters,EoutsideMustache);
124  }
125 
126  template<class RandomAccessPtrIterator>
127  void Mustache::MustacheID(const RandomAccessPtrIterator& begin,
128  const RandomAccessPtrIterator& end,
129  int & nclusters,
130  float & EoutsideMustache) {
131  nclusters = 0;
132  EoutsideMustache = 0;
133 
134  unsigned int ncl = end-begin;
135  if(!ncl) return;
136 
137  //loop over all clusters to find the one with highest energy
138  RandomAccessPtrIterator icl = begin;
139  RandomAccessPtrIterator clmax = end;
140  float emax = 0;
141  for( ; icl != end; ++icl){
142  const float e = (*icl)->energy();
143  if(e > emax){
144  emax = e;
145  clmax = icl;
146  }
147  }
148 
149  if(end == clmax) return;
150 
151  float eta0 = (*clmax)->eta();
152  float phi0 = (*clmax)->phi();
153 
154 
155  bool inMust = false;
156  icl = begin;
157  for( ; icl != end; ++icl ){
158  inMust=MustacheKernel::inMustache(eta0, phi0,
159  (*icl)->energy(),
160  (*icl)->eta(),
161  (*icl)->phi());
162 
163  nclusters += (int)!inMust;
164  EoutsideMustache += (!inMust)*((*icl)->energy());
165  }
166  }
167 
168  void Mustache::MustacheClust(const std::vector<CaloCluster>& clusters,
169  std::vector<unsigned int>& insideMust,
170  std::vector<unsigned int>& outsideMust){
171  unsigned int ncl = clusters.size();
172  if(!ncl) return;
173 
174  //loop over all clusters to find the one with highest energy
175  float emax = 0;
176  int imax = -1;
177  for(unsigned int i=0; i<ncl; ++i){
178  float e = (clusters[i]).energy();
179  if(e > emax){
180  emax = e;
181  imax = i;
182  }
183  }
184 
185  if(imax<0) return;
186  float eta0 = (clusters[imax]).eta();
187  float phi0 = (clusters[imax]).phi();
188 
189 
190  for(unsigned int k=0; k<ncl; k++){
191 
192  bool inMust=MustacheKernel::inMustache(eta0, phi0,
193  (clusters[k]).energy(),
194  (clusters[k]).eta(),
195  (clusters[k]).phi());
196  //return indices of Clusters outside the Mustache
197  if (!(inMust)){
198  outsideMust.push_back(k);
199  }
200  else{//return indices of Clusters inside the Mustache
201  insideMust.push_back(k);
202  }
203  }
204  }
205 
206  void Mustache::FillMustacheVar(const std::vector<CaloCluster>& clusters){
207  Energy_In_Mustache_=0;
208  Energy_Outside_Mustache_=0;
209  LowestClusterEInMustache_=0;
210  excluded_=0;
211  included_=0;
212  std::multimap<float, unsigned int>OrderedClust;
213  std::vector<unsigned int> insideMust;
214  std::vector<unsigned int> outsideMust;
215  MustacheClust(clusters, insideMust, outsideMust);
216  included_=insideMust.size(); excluded_=outsideMust.size();
217  for(unsigned int i=0; i<insideMust.size(); ++i){
218  unsigned int index=insideMust[i];
219  Energy_In_Mustache_=clusters[index].energy()+Energy_In_Mustache_;
220  OrderedClust.insert(make_pair(clusters[index].energy(), index));
221  }
222  for(unsigned int i=0; i<outsideMust.size(); ++i){
223  unsigned int index=outsideMust[i];
224  Energy_Outside_Mustache_=clusters[index].energy()+Energy_Outside_Mustache_;
225  Et_Outside_Mustache_=clusters[index].energy()*sin(clusters[index].position().theta())
226  +Et_Outside_Mustache_;
227  }
228  std::multimap<float, unsigned int>::iterator it;
229  it=OrderedClust.begin();
230  unsigned int lowEindex=(*it).second;
231  LowestClusterEInMustache_=clusters[lowEindex].energy();
232 
233  }
234 }
int i
Definition: DBlmapReader.cc:9
bool inDynamicDPhiWindow(const bool isEE, const float seedPhi, const float ClustE, const float ClusEta, const float clusPhi)
Definition: Mustache.cc:74
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
#define abs(x)
Definition: mlp_lapack.h:159
common ppss p3p6s2 common epss epspn46 common const1 w10
Definition: inclppp.h:1
#define min(a, b)
Definition: mlp_lapack.h:161
double Phi_mpi_pi(double x)
Definition: JetUtil.h:24
double maxEta
T eta() const
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
common ppss p3p6s2 common epss epspn46 common const1 w11
Definition: inclppp.h:1
const_iterator begin() const
Definition: PtrVector.h:126
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:48
const_iterator end() const
Definition: PtrVector.h:131
double f[11][100]
#define end
Definition: vmac.h:38
int k[5][pyjets_maxn]
#define begin
Definition: vmac.h:31
CaloCluster_iterator clustersBegin() const
fist iterator over BasicCluster constituents
Definition: SuperCluster.h:71
bool inMustache(const float maxEta, const float maxPhi, const float ClustE, const float ClusEta, const float ClusPhi)
Definition: Mustache.cc:9
#define constexpr
CaloCluster_iterator clustersEnd() const
last iterator over BasicCluster constituents
Definition: SuperCluster.h:74
Definition: DDAxes.h:10