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>
11  inline T sqr(T t) {
12  return t * t;
13  }
14 } // namespace
15 
17  std::sort(theLayers.begin(), theLayers.end());
18  int i = -1;
19  indeces.clear();
20  for (auto const& l : theLayers) {
21  ++i;
22  int sq = l.seqNum();
23  if (sq < 0)
24  continue;
25  if (sq >= int(indeces.size()))
26  indeces.resize(sq + 1, -1);
27  indeces[sq] = i;
28  }
29 }
30 
31 //------------------------------------------------------------------------------
32 MSLayersAtAngle::MSLayersAtAngle(const vector<MSLayer>& layers) : theLayers(layers) { init(); }
33 //------------------------------------------------------------------------------
35  vector<MSLayer>::const_iterator it = find(theLayers.begin(), theLayers.end(), layer);
36  return it == theLayers.end() ? nullptr : &(*it);
37 }
38 
39 //------------------------------------------------------------------------------
41  vector<MSLayer>::iterator it = find(theLayers.begin(), theLayers.end(), layer);
42  if (it == theLayers.end()) {
43  theLayers.push_back(layer);
44  init();
45  } else {
46  *it = layer;
47  }
48 }
49 
50 //------------------------------------------------------------------------------
51 float MSLayersAtAngle::sumX0D(const PixelRecoPointRZ& pointI, const PixelRecoPointRZ& pointO) const {
52  LayerItr iO = findLayer(pointO, theLayers.begin(), theLayers.end());
53  // cout << "outer Layer: "<<*iO<<endl;
54  LayerItr iI = findLayer(pointI, theLayers.begin(), iO);
55  // cout << "inner Layer: "<<*iI<<endl;
56 
57  return sqrt(sum2RmRn(iI, iO, pointO.r(), SimpleLineRZ(pointI, pointO)));
58 }
59 
60 float MSLayersAtAngle::sumX0D(int il, int ol, const PixelRecoPointRZ& pointI, const PixelRecoPointRZ& pointO) const {
61  // if layer not at this angle (WHY???) revert to slow comp
62  if (il >= int(indeces.size()) || ol >= int(indeces.size()) || indeces[il] < 0 || indeces[ol] < 0)
63  return sumX0D(pointI, pointO);
64 
65  LayerItr iI = theLayers.begin() + indeces[il];
66  LayerItr iO = theLayers.begin() + indeces[ol];
67 
68  return sqrt(sum2RmRn(iI, iO, pointO.r(), SimpleLineRZ(pointI, pointO)));
69 }
70 
71 //------------------------------------------------------------------------------
72 
73 static const bool doPrint = false;
74 
76  const PixelRecoPointRZ& pointM,
77  const PixelRecoPointRZ& pointO) const {
78  LayerItr iO = findLayer(pointO, theLayers.begin(), theLayers.end());
79  LayerItr iI = findLayer(pointI, theLayers.begin(), iO);
80  LayerItr iM = findLayer(pointM, iI, iO);
81 
82  float drOI = pointO.r() - pointI.r();
83  float drMO = pointO.r() - pointM.r();
84  float drMI = pointM.r() - pointI.r();
85 
86  SimpleLineRZ line(pointI, pointO);
87  float sum2I = sum2RmRn(iI + 1, iM, pointI.r(), line);
88  float sum2O = sum2RmRn(iM, iO, pointO.r(), line);
89 
90  float sum = std::sqrt(sum2I * sqr(drMO) + sum2O * sqr(drMI)) / drOI;
91 
92  // if (iI!=theLayers.begin() )
93  // doPrint = ((*iM).seqNum()<0 || (*iO).seqNum()<0);
94  if (doPrint)
95  std::cout << "old " << (*iI).seqNum() << " " << iI - theLayers.begin() << ", " << (*iM).seqNum() << " "
96  << iM - theLayers.begin() << ", " << (*iO).seqNum() << " " << iO - theLayers.begin() << " " << pointI.r()
97  << " " << pointI.z() << " " << sum << std::endl;
98 
99  return sum;
100 }
101 
103  float zV, int il, int ol, const PixelRecoPointRZ& pointI, const PixelRecoPointRZ& pointO) const {
104  PixelRecoPointRZ pointV(0.f, zV);
105 
106  // if layer not at this angle (WHY???) revert to slow comp
107  if (il >= int(indeces.size()) || ol >= int(indeces.size()) || indeces[il] < 0 || indeces[ol] < 0)
108  return sumX0D(pointV, pointI, pointO);
109 
110  LayerItr iI = theLayers.begin() + indeces[il];
111  LayerItr iO = theLayers.begin() + indeces[ol];
112 
113  float drOI = pointO.r();
114  float drMO = pointO.r() - pointI.r();
115  float drMI = pointI.r();
116 
117  SimpleLineRZ line(pointV, pointO);
118  float sum2I = sum2RmRn(theLayers.begin() + 1, iI, pointV.r(), line);
119  float sum2O = sum2RmRn(iI, iO, pointO.r(), line);
120 
121  float sum = std::sqrt(sum2I * sqr(drMO) + sum2O * sqr(drMI)) / drOI;
122 
123  if (doPrint)
124  std::cout << "new " << il << " " << (*iI).seqNum() << " " << iI - theLayers.begin() << ", " << ol << " "
125  << (*iO).seqNum() << " " << iO - theLayers.begin() << " " << zV << " " << sum << std::endl;
126 
127  return sum;
128 }
129 
130 //------------------------------------------------------------------------------
133  float rTarget,
134  const SimpleLineRZ& line) const {
135  float sum2 = 0.f;
136  float cotTh = line.cotLine();
137  for (LayerItr it = i1; it < i2; it++) {
138  std::pair<PixelRecoPointRZ, bool> cross = it->crossing(line);
139  if (cross.second) {
140  float x0 = it->x0(cotTh);
141  float dr = rTarget - cross.first.r();
142  if (x0 > 1.e-5f)
143  dr *= 1.f + 0.038f * unsafe_logf<2>(x0);
144  sum2 += x0 * dr * dr;
145  }
146  // cout << *it << " crossing: "<<cross.second<<endl;
147  }
148  return sum2;
149 }
150 //------------------------------------------------------------------------------
153  MSLayersAtAngle::LayerItr iend) const {
154  const float BIG = 99999.f;
155  const float EPSILON = 1.e-8f;
156  LayerItr theIt = ibeg;
157  float dist = BIG;
158  for (LayerItr it = ibeg; it < iend; it++) {
159  float d = it->distance2(point);
160  if (d < dist) {
161  if (d < EPSILON)
162  return it;
163  dist = d;
164  theIt = it;
165  }
166  }
167  return theIt;
168 }
169 
170 //------------------------------------------------------------------------------
172  for (LayerItr it = theLayers.begin(); it != theLayers.end(); it++)
173  cout << *it << endl;
174 }
std::vector< int > indeces
std::vector< MSLayer > theLayers
Basic3DVector cross(const Basic3DVector &v) const
Vector product, or "cross" product, with a vector of same type.
const MSLayer * findLayer(const MSLayer &layer) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void update(const MSLayer &layer)
T sqrt(T t)
Definition: SSEVec.h:19
double f[11][100]
float r() const
d
Definition: ztail.py:151
std::vector< MSLayer >::const_iterator LayerItr
float sum2RmRn(LayerItr i1, LayerItr i2, float rTarget, const SimpleLineRZ &line) const
const float EPSILON
Definition: AnglesUtil.h:22
Square< F >::type sqr(const F &f)
Definition: Square.h:14
float z() const
long double T
static const bool doPrint
float sumX0D(const PixelRecoPointRZ &pointI, const PixelRecoPointRZ &pointO) 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
void print() const