CMS 3D CMS Logo

MSLayersKeeperX0AtEta.cc
Go to the documentation of this file.
4 #include <algorithm>
6 
7 using namespace std;
8 
9 namespace {
10  template <class T>
11  inline T sqr(T t) {
12  return t * t;
13  }
14  // float unsafe_asinhf(float x) { return std::abs(x)>10.f ? std::copysign(3.f,x) : unsafe_logf<3>(x+std::sqrt(1.f+x*x)); }
15  inline float unsafe_asinhf(float x) { return unsafe_logf<3>(x + std::sqrt(1.f + x * x)); }
16 } // namespace
17 
18 //------------------------------------------------------------------------------
19 const MSLayersAtAngle& MSLayersKeeperX0AtEta::layers(float cotTheta) const {
20  float eta = unsafe_asinhf(cotTheta);
21  return theLayersData[idxBin(eta)];
22 }
23 
24 //------------------------------------------------------------------------------
25 float MSLayersKeeperX0AtEta::eta(int idxBin) const { return (idxBin + 0.5 - theHalfNBins) * theDeltaEta; }
26 
27 //------------------------------------------------------------------------------
29  float ieta = eta / theDeltaEta;
30  if (std::abs(ieta) >= theHalfNBins - 1.e-3)
31  return (eta > 0) ? max(2 * theHalfNBins - 1, 0) : 0;
32  else
33  return int(ieta + theHalfNBins);
34 }
35 
36 //------------------------------------------------------------------------------
38  const float BIG = 99999.;
39 
40  // set size from data file
41  MultipleScatteringX0Data msX0data;
42  theHalfNBins = msX0data.nBinsEta();
43  float etaMax = msX0data.maxEta();
44  theDeltaEta = (theHalfNBins != 0) ? etaMax / theHalfNBins : BIG;
45 
46  theLayersData = vector<MSLayersAtAngle>(max(2 * theHalfNBins, 1));
48  for (int idxbin = 0; idxbin < 2 * theHalfNBins; idxbin++) {
49  float etaValue = eta(idxbin);
50  float cotTheta = sinh(etaValue);
51 
52  vector<MSLayer> layers = layout.detLayers(etaValue, 0, bfield);
53  vector<MSLayer> tmplay = layout.otherLayers(etaValue);
54  layers.insert(layers.end(), tmplay.begin(), tmplay.end());
55  sort(layers.begin(), layers.end());
56  setX0(layers, etaValue, msX0data);
57  theLayersData[idxbin] = MSLayersAtAngle(layers);
58  PixelRecoPointRZ zero(0., 0.);
59  PixelRecoLineRZ line(zero, cotTheta);
60  vector<MSLayer>::iterator it;
61  for (it = layers.begin(); it != layers.end(); it++) {
62  float x0 = getDataX0(*it).x0;
63  float sumX0D = theLayersData[idxbin].sumX0D(zero, it->crossing(line).first);
64  setDataX0(*it, DataX0(x0, sumX0D, cotTheta));
65  theLayersData[idxbin].update(*it);
66  }
67  }
68 
69  // add layers not seen from nominal vertex but crossed if
70  // vertex seperated from nominal by less than 3 sigma
71  for (int idxbin = 0; idxbin < 2 * theHalfNBins; idxbin++) {
72  float etaValue = eta(idxbin);
73  for (int isign = -1; isign <= 1; isign += 2) {
74  float z = isign * 15.9; //3 sigma from zero
75  const MSLayersAtAngle& layersAtAngle = theLayersData[idxbin];
76  vector<MSLayer> candidates = layout.detLayers(etaValue, z, bfield);
77  vector<MSLayer>::iterator it;
78  for (it = candidates.begin(); it != candidates.end(); it++) {
79  if (layersAtAngle.findLayer(*it))
80  continue;
81  const MSLayer* found = nullptr;
82  int bin = idxbin;
83  while (!found) {
84  bin--;
85  if (bin < 0)
86  break;
87  found = theLayersData[bin].findLayer(*it);
88  }
89  bin = idxbin;
90  while (!found) {
91  bin++;
92  if (bin > 2 * theHalfNBins - 1)
93  break;
94  found = theLayersData[bin].findLayer(*it);
95  }
96  if (found)
97  theLayersData[idxbin].update(*found);
98  }
99  }
100  }
101 
102  // cout << "LAYERS, size=: "<<theLayersData.size()<< endl;
103  /*
104  for (int idxbin = 0; idxbin <= theHalfNBins; idxbin+=25) {
105  float etaValue = eta(idxbin);
106  const MSLayersAtAngle & layers= theLayersData[idxbin];
107  cout << "ETA: "<< etaValue <<" (bin:"<<idxbin<<") #layers:"
108  <<layers.size()<<endl;
109  layers.print();
110  }
111  for (int idxbin = 2*theHalfNBins-1; idxbin > theHalfNBins; idxbin-=25) {
112  float etaValue = eta(idxbin);
113  const MSLayersAtAngle & layers= theLayersData[idxbin];
114  cout << "ETA: "<< etaValue <<" (bin:"<<idxbin<<") #layers:"
115  <<layers.size()<<endl;
116  layers.print();
117  }
118 */
119 }
120 
121 //------------------------------------------------------------------------------
122 void MSLayersKeeperX0AtEta::setX0(vector<MSLayer>& layers, float eta, const SumX0AtEtaDataProvider& sumX0) {
123  const float BIG = 99999.;
124  float cotTheta = sinh(eta);
125  float sinTheta = 1 / sqrt(1 + sqr(cotTheta));
126  float cosTheta = cotTheta * sinTheta;
127 
128  float sumX0atAngleLast = 0.;
129  vector<MSLayer>::iterator il;
130  for (il = layers.begin(); il != layers.end(); il++) {
131  PixelRecoLineRZ line(PixelRecoPointRZ(0., 0.), cotTheta);
132  float rL = (*il).crossing(line).first.r();
133  float rN = (il + 1 != layers.end()) ? (il + 1)->crossing(line).first.r() : BIG;
134  float rBound = (rL + rN) / 2.;
135  float sumX0atAngle = sumX0.sumX0atEta(eta, rBound);
136 
137  float dX0 = (il->face() == GeomDetEnumerators::barrel) ? (sumX0atAngle - sumX0atAngleLast) * sinTheta
138  : (sumX0atAngle - sumX0atAngleLast) * fabs(cosTheta);
139 
140  setDataX0(*il, DataX0(dX0, 0, cotTheta));
141  sumX0atAngleLast = sumX0atAngle;
142  }
143 }
144 
145 //------------------------------------------------------------------------------
int idxBin(float eta) const
MSLayersKeeperX0AtEta(const GeometricSearchTracker &tracker, const MagneticField &bfield)
~MSLayersKeeperX0AtEta() override
const MSLayersAtAngle & layers(float cotTheta) const override
const MSLayer * findLayer(const MSLayer &layer) const
virtual float sumX0atEta(float eta, float r) const =0
T sqrt(T t)
Definition: SSEVec.h:23
float eta(int idxBin) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
static void setX0(std::vector< MSLayer > &, float eta, const SumX0AtEtaDataProvider &)
Square< F >::type sqr(const F &f)
Definition: Square.h:14
float x
long double T