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