CMS 3D CMS Logo

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