CMS 3D CMS Logo

MSLayersAtAngle.cc
Go to the documentation of this file.
1 
2 #include "MSLayersAtAngle.h"
3 
6 
7 using namespace std;
8 
9 namespace {
10  template <class T> inline T sqr( T t) {return t*t;}
11 }
12 
13 
14 void
16  std::sort(theLayers.begin(), theLayers.end());
17  int i = -1; indeces.clear();
18  for ( auto const & l : theLayers ) {
19  ++i;
20  int sq = l.seqNum();
21  if (sq<0) continue;
22  if (sq>=int(indeces.size())) indeces.resize(sq+1,-1);
23  indeces[sq]=i;
24  }
25 }
26 
27 //------------------------------------------------------------------------------
28 MSLayersAtAngle::MSLayersAtAngle(const vector<MSLayer> & layers)
29  : theLayers(layers)
30 {
31  init();
32 }
33 //------------------------------------------------------------------------------
34 const MSLayer * MSLayersAtAngle::findLayer(const MSLayer & layer) const
35 {
36  vector<MSLayer>::const_iterator it =
37  find(theLayers.begin(), theLayers.end(), layer);
38  return it==theLayers.end() ? 0 : &(*it);
39 }
40 
41 //------------------------------------------------------------------------------
42 void MSLayersAtAngle::update(const MSLayer & layer)
43 {
44  vector<MSLayer>::iterator it = find(theLayers.begin(),theLayers.end(),layer);
45  if (it == theLayers.end()) {
46  theLayers.push_back(layer);
47  init();
48  } else {
49  *it = layer;
50  }
51 }
52 
53 //------------------------------------------------------------------------------
55  const PixelRecoPointRZ & pointI,
56  const PixelRecoPointRZ & pointO) const
57 {
58  LayerItr iO = findLayer(pointO, theLayers.begin(), theLayers.end());
59 // cout << "outer Layer: "<<*iO<<endl;
60  LayerItr iI = findLayer(pointI, theLayers.begin(), iO);
61 // cout << "inner Layer: "<<*iI<<endl;
62 
63  return sqrt(sum2RmRn(iI,iO, pointO.r(),
64  SimpleLineRZ(pointI, pointO)));
65 }
66 
67 
68 float MSLayersAtAngle::sumX0D( int il, int ol,
69  const PixelRecoPointRZ & pointI,
70  const PixelRecoPointRZ & pointO) const
71 {
72  // if layer not at this angle (WHY???) revert to slow comp
73  if (il>=int(indeces.size()) || ol>=int(indeces.size()) ||
74  indeces[il]<0 || indeces[ol] < 0) return sumX0D(pointI,pointO);
75 
76  LayerItr iI = theLayers.begin() + indeces[il];
77  LayerItr iO = theLayers.begin() + indeces[ol];
78 
79 
80  return sqrt(sum2RmRn(iI,iO, pointO.r(),
81  SimpleLineRZ(pointI, pointO)));
82 }
83 
84 //------------------------------------------------------------------------------
85 
86 static const bool doPrint=false;
87 
89  const PixelRecoPointRZ & pointI,
90  const PixelRecoPointRZ & pointM,
91  const PixelRecoPointRZ & pointO) const
92 {
93  LayerItr iO = findLayer(pointO, theLayers.begin(), theLayers.end());
94  LayerItr iI = findLayer(pointI, theLayers.begin(), iO);
95  LayerItr iM = findLayer(pointM, iI, iO);
96 
97 
98  float drOI = pointO.r() - pointI.r();
99  float drMO = pointO.r() - pointM.r();
100  float drMI = pointM.r() - pointI.r();
101 
102  SimpleLineRZ line(pointI, pointO);
103  float sum2I = sum2RmRn(iI+1, iM, pointI.r(), line);
104  float sum2O = sum2RmRn(iM, iO, pointO.r(), line);
105 
106  float sum = std::sqrt( sum2I* sqr(drMO) + sum2O*sqr(drMI) )/drOI;
107 
108  // if (iI!=theLayers.begin() )
109  // doPrint = ((*iM).seqNum()<0 || (*iO).seqNum()<0);
110  if (doPrint)
111  std::cout << "old " << (*iI).seqNum() << " " << iI-theLayers.begin() << ", "
112  << (*iM).seqNum() << " " << iM-theLayers.begin() << ", "
113  << (*iO).seqNum() << " " << iO-theLayers.begin() << " "
114  << pointI.r() << " " << pointI.z()
115  << " " << sum
116  << std::endl;
117 
118 
119  return sum;
120 }
121 
122 
123 float MSLayersAtAngle::sumX0D(float zV, int il, int ol,
124  const PixelRecoPointRZ & pointI,
125  const PixelRecoPointRZ & pointO) const {
126 
127  PixelRecoPointRZ pointV(0.f,zV);
128 
129  // if layer not at this angle (WHY???) revert to slow comp
130  if (il>=int(indeces.size()) || ol>=int(indeces.size()) ||
131  indeces[il]<0 || indeces[ol] < 0) return sumX0D(pointV,pointI,pointO);
132 
133  LayerItr iI = theLayers.begin() + indeces[il];
134  LayerItr iO = theLayers.begin() + indeces[ol];
135 
136 
137 
138  float drOI = pointO.r();
139  float drMO = pointO.r() - pointI.r();
140  float drMI = pointI.r();
141 
142  SimpleLineRZ line(pointV, pointO);
143  float sum2I = sum2RmRn(theLayers.begin()+1, iI, pointV.r(), line);
144  float sum2O = sum2RmRn(iI, iO, pointO.r(), line);
145 
146  float sum = std::sqrt( sum2I* sqr(drMO) + sum2O*sqr(drMI) )/drOI;
147 
148  if (doPrint)
149  std::cout << "new " << il << " " << (*iI).seqNum() << " " << iI-theLayers.begin() << ", "
150  << ol << " " << (*iO).seqNum() << " " << iO-theLayers.begin() << " " << zV
151  << " " << sum
152  << std::endl;
153 
154  return sum;
155 
156 }
157 
158 
159 //------------------------------------------------------------------------------
163  float rTarget,
164  const SimpleLineRZ & line) const
165 {
166  float sum2 = 0.f;
167  float cotTh = line.cotLine();
168  for (LayerItr it = i1; it < i2; it++) {
169  std::pair<PixelRecoPointRZ,bool> cross = it->crossing(line);
170  if (cross.second) {
171  float x0 = it->x0(cotTh);
172  float dr = rTarget-cross.first.r();
173  if (x0 > 1.e-5f) dr *= 1.f+0.038f*unsafe_logf<2>(x0);
174  sum2 += x0*dr*dr;
175  }
176 // cout << *it << " crossing: "<<cross.second<<endl;
177  }
178  return sum2;
179 }
180 //------------------------------------------------------------------------------
182  const PixelRecoPointRZ & point,
184  MSLayersAtAngle::LayerItr iend) const
185 {
186  const float BIG=99999.f;
187  const float EPSILON = 1.e-8f;
188  LayerItr theIt = ibeg; float dist = BIG;
189  for (LayerItr it = ibeg; it < iend; it++) {
190  float d = it->distance2(point);
191  if (d < dist) {
192  if (d < EPSILON) return it;
193  dist = d;
194  theIt = it;
195  }
196  }
197  return theIt;
198 }
199 
200 //------------------------------------------------------------------------------
202 {
203  for (LayerItr it = theLayers.begin(); it != theLayers.end(); it++)
204  cout <<*it<<endl;
205 }
206 
std::vector< int > indeces
std::vector< MSLayer > theLayers
float cotLine() const
std::vector< LayerSetAndLayers > layers(const SeedingLayerSetsHits &sets)
Definition: LayerTriplets.cc:4
void print() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
void update(const MSLayer &layer)
T sqrt(T t)
Definition: SSEVec.h:18
double f[11][100]
float sum2RmRn(LayerItr i1, LayerItr i2, float rTarget, const SimpleLineRZ &line) const
float sumX0D(const PixelRecoPointRZ &pointI, const PixelRecoPointRZ &pointO) const
std::vector< MSLayer >::const_iterator LayerItr
const float EPSILON
Definition: AnglesUtil.h:23
float z() const
float r() const
Square< F >::type sqr(const F &f)
Definition: Square.h:13
long double T
static const bool doPrint
const MSLayer * findLayer(const MSLayer &layer) const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.