CMS 3D CMS Logo

TkMSParameterizationBuilder.cc
Go to the documentation of this file.
2 
6 
11 
12 
16 
19 
21 
22 
23 
28 
30 
31 
32 namespace {
33  inline
35  {
36  GlobalVector zAxis = zDir.unit();
37  GlobalVector yAxis( zAxis.y(), -zAxis.x(), 0);
38  GlobalVector xAxis = yAxis.cross( zAxis);
39  return Surface::RotationType( xAxis, yAxis, zAxis);
40  }
41 
42  struct MSData {
43  int stid;
44  int lid;
45  float zi;
46  float zo;
47  float uerr;
48  float verr;
49  };
50 }
51 inline
52 std::ostream & operator<<(std::ostream & os, MSData d) {
53  os << d.stid<<'>' <<d.lid <<'|'<<d.zi<<'/'<<d.zo<<':'<<d.uerr<<'/'<<d.verr;
54  return os;
55 }
56 
57 
58 
60 public:
64  // desc.add<std::string>("ComponentName","TkMSParameterization");
65  desc.add<std::string>("navigationSchool","SimpleNavigationSchool");
66  descriptions.add("TkMSParameterizationBuilder",desc);
67  }
68 
69  using ReturnType = std::shared_ptr<TkMSParameterization>;
70  ReturnType produce(TkMSParameterizationRecord const&);
71 
74 };
75 
77  theNavigationSchoolName(pset.getParameter<std::string>("navigationSchool")){
78  setWhatProduced(this,"");
79 }
80 
83 
84  using namespace tkMSParameterization;
85 
86  product = std::make_shared<TkMSParameterization>();
87 
88  auto & msParam = *product;
89 
90  //
92  iRecord.getRecord<NavigationSchoolRecord>().get(theNavigationSchoolName, navSchoolH);
93  TkNavigationSchool const & navSchool = *(TkNavigationSchool const *)navSchoolH.product();
94  auto const & searchGeom = navSchool.searchTracker();
95  auto const & magfield = navSchool.field();
96 
97  //
98  edm::ESHandle<Propagator> propagatorHandle;
99  iRecord.getRecord<TrackingComponentsRecord>().get("PropagatorWithMaterial", propagatorHandle);
100  auto const & ANprop = *propagatorHandle;
101 
102 
103  // error (very very small)
104  ROOT::Math::SMatrixIdentity id;
106  C *= 1.e-16;
107 
109 
110  Chi2MeasurementEstimator estimator(30.,-3.0,0.5,2.0,0.5,1.e12); // same as defauts....
111  KFUpdator kfu;
112  LocalError he(0.001*0.001,0,0.002*0.002);
113 
114 
115  // loop over lambdas
116  bool debug = false;
117  float tl=0;
118  for (decltype(nLmBins()) ib=0; ib<nLmBins(); ++ib, tl+=lmBin()) {
119 
120  float pt = 1.0f;
121  float tanlmd = tl; // 0.1f;
122  auto sinth2 = 1.f/(1.f+tanlmd*tanlmd);
123  auto sinth = std::sqrt(sinth2);
124  auto overp = sinth/pt;
125  auto pz = pt*tanlmd;
126 
127  // debug= (tl>2.34f && tl<2.55f);
128  if(debug) std::cout << tl << ' ' << pz << ' ' << 1./overp << std::endl;
129 
130 
131  float lastzz=-18.f;
132  bool goFw=false;
133  std::string loc=" Barrel";
134  for (int iz=0;iz<2; ++iz) {
135  if (iz>0) goFw=true;
136  for (float zz=lastzz; zz<18.1f; zz+=0.2f) {
137  float z = zz;
138  GlobalPoint startingPosition(0,0,z);
139 
140  constexpr int maxLayers=6;
141 
142  std::vector<MSData> mserr[maxLayers][maxLayers];
143 
144  // define propagation from/to
145  std::function<void(int, TrajectoryStateOnSurface, DetLayer const *, float, int)>
146  propagate = [&](int from, TrajectoryStateOnSurface tsos, DetLayer const * layer, float z1, int stid) {
147 
148  for (auto il=from+1; il<maxLayers; ++il) {
149 
150  auto compLayers = navSchool.nextLayers(*layer,*tsos.freeState(),alongMomentum);
151  std::stable_sort(compLayers.begin(),compLayers.end(),[](auto a, auto b){return a->seqNum()<b->seqNum();});
152  layer = nullptr;
153  for(auto it : compLayers){
154  if (it->basicComponents().empty()) {
155  //this should never happen. but better protect for it
156  edm::LogError("TkMSParameterizationBuilder") <<"a detlayer with no components: I cannot figure out a DetId from this layer. please investigate.";
157  continue;
158  }
159  if (debug) std::cout << il << (it->isBarrel() ? " Barrel" : " Forward") << " layer " << it->seqNum() << " SubDet " << it->subDetector()<< std::endl;
160  auto const & detWithState = it->compatibleDets(tsos,ANprop,estimator);
161  if(detWithState.empty()) {
162  if(debug) std::cout << "no det on this layer" << it->seqNum() << std::endl;
163  continue;
164  }
165  layer = it;
166  auto did = detWithState.front().first->geographicalId();
167  if (debug) std::cout << "arrived at " << int(did) << std::endl;
168  tsos = detWithState.front().second;
169  if(debug) std::cout << tsos.globalPosition() << ' ' << tsos.localError().positionError() << std::endl;
170 
171 
172  // save errs
173  auto globalError = ErrorFrameTransformer::transform(tsos.localError().positionError(), tsos.surface());
174  auto gp = tsos.globalPosition();
175  float r = gp.perp();
176  float errorPhi = std::sqrt(float(globalError.phierr(gp)));
177  float errorR = std::sqrt(float(globalError.rerr(gp)));
178  float errorZ = std::sqrt(float(globalError.czz()));
179  float xerr = overp*errorPhi;
180  float zerr = overp*(layer->isBarrel() ? errorZ : errorR);
181  auto zo = layer->isBarrel() ? gp.z() : r;
182  // std::cout << tanlmd << ' ' << z1 << ' ' << it->seqNum() << ':' << xerr <<'/'<<zerr << std::endl;
183  mserr[from][il-1].emplace_back(MSData{stid,it->seqNum(),z1,zo,xerr,zerr});
184 
185  if (from==0) {
186  // spawn prop from this layer
187  // constrain it to this location (relevant for layer other than very first)
189  SiPixelRecHit hitpx(tsos.localPosition(),he,1.,*detWithState.front().first,pref);
190  auto tsosl = kfu.update(tsos, hitpx);
191  auto z1l = layer->isBarrel() ? tsos.globalPosition().z() : tsos.globalPosition().perp();
192  auto stidl = layer->seqNum();
193  propagate(il,tsosl,layer,z1l, stidl);
194  }
195  break;
196  } // loop on compLayers
197  if (!layer) break;
198  // if (!goFw) lastbz=z1;
199  if(from==0) lastzz=zz;
200 
201  } // layer loop
202 
203  if (debug && mserr[from][from].empty()) {
204  std::cout << "tl " << tanlmd << loc << ' ' <<from<< std::endl;
205  for (auto il=from; il<maxLayers; ++il) { std::cout << il << ' ';
206  for ( auto const & e : mserr[from][il]) std::cout << e<<' '; // << '-' <<e.uerr*sinth <<'/'<<e.verr*sinth <<' ';
207  std::cout << std::endl;
208  }
209  }
210  }; // propagate
211 
212  float phi = 0.0415f;
213  for (int ip=0;ip<5; ++ip) {
214  phi += (3.14159f/6.f)/5.f;
215  GlobalVector startingMomentum(pt*std::sin(phi),pt*std::cos(phi),pz);
216 
217  // make TSOS happy
218  //Define starting plane
219  PlaneBuilder pb;
220  auto rot = rotation(startingMomentum);
221  auto startingPlane = pb.plane( startingPosition, rot);
222 
223  TrajectoryStateOnSurface startingStateP( GlobalTrajectoryParameters(startingPosition,
224  startingMomentum, 1, &magfield),
225  err, *startingPlane);
226  auto tsos0 = startingStateP;
227 
228  DetLayer const * layer0 = searchGeom.pixelBarrelLayers()[0];
229  if (goFw) layer0 = searchGeom.posPixelForwardLayers()[0];
230  int stid0 = layer0->seqNum();
231 
232  {
233  auto it = layer0;
234  if(debug) std::cout << "first layer " << (it->isBarrel() ? " Barrel" : " Forward") << " layer " << it->seqNum() << " SubDet " << it->subDetector()<< std::endl;
235  }
236 
237  auto const & detWithState = layer0->compatibleDets(tsos0,ANprop,estimator);
238  if(detWithState.empty()) {
239  if(debug) std::cout << "no det on first layer" << layer0->seqNum() << std::endl;
240  continue;
241  }
242  tsos0 = detWithState.front().second;
243  if(debug) std::cout << "arrived at " << int(detWithState.front().first->geographicalId()) << ' ' << tsos0.globalPosition() << ' ' << tsos0.localError().positionError() << std::endl;
244 
245  // for barrel
246  float z1l = tsos0.globalPosition().z();
247  if (goFw) {
248  loc = " Forward";
249  z1l = tsos0.globalPosition().perp();
250  }
251 
252  propagate(0,tsos0,layer0,z1l,stid0);
253 
254  } // loop on phi
255 
256  // fill
257  for (auto from=0; from<maxLayers; ++from)
258  for (auto il=from; il<maxLayers; ++il) {
259  if (mserr[from][il].empty()) continue;
260  auto stid=mserr[from][il].front().stid;
261  auto lid=mserr[from][il].front().lid;
262  auto zi = mserr[from][il].front().zi;
263  float xerr =0;
264  float zerr =0;
265  float zo=0;
266  for (auto const & e : mserr[from][il]) {
267  if (e.stid!=stid) continue;
268  lid = std::min(lid,e.lid);
269  }
270  float nn=0;
271  for (auto const & e : mserr[from][il]) {
272  if (e.stid!=stid || lid!=e.lid) continue;
273  xerr+=e.uerr; zerr+=e.verr; zo+=e.zo; ++nn;
274  }
275  xerr/=nn; zerr/=nn; zo/=nn;
276  auto iid = packLID(stid,lid);
277  auto & md = msParam.data[iid].data[ib].data;
278  if (md.empty()
279  || std::abs(xerr-md.back().uerr)>0.2f*xerr
280  || std::abs(zerr-md.back().verr)>0.2f*zerr
281  ) md.emplace_back(Elem{zi,zo,xerr,zerr});
282  } // loop on layers
283 
284  }} // loop on z
285 
286  } // loop on tanLa
287 
288  // sort
289  for (auto & e : msParam.data)
290  for (auto & d : e.second.data) std::stable_sort(d.data.begin(),d.data.end(),[](auto const & a, auto const & b){return a.vo<b.vo;});
291 
292  return product;
293 }
294 
295 
296 
297 
unsigned short packLID(unsigned int id, unsigned int od)
static GlobalError transform(const LocalError &le, const Surface &surf)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ReturnType produce(TkMSParameterizationRecord const &)
void zerr(int)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
ReturnType plane(const PositionType &pos, const RotationType &rot) const
Definition: PlaneBuilder.h:22
T y() const
Definition: PV3DBase.h:63
const GeometricSearchTracker & searchTracker() const
GlobalPoint globalPosition() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
#define constexpr
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
int seqNum() const
Definition: DetLayer.h:36
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const override
Definition: KFUpdator.cc:75
TkMSParameterizationBuilder(edm::ParameterSet const &)
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
T min(T a, T b)
Definition: MathUtil.h:58
ParameterDescriptionBase * add(U const &iLabel, T const &value)
Vector3DBase unit() const
Definition: Vector3DBase.h:57
std::shared_ptr< TkMSParameterization > ReturnType
const MagneticField & field() const
#define debug
Definition: HDRShower.cc:19
std::vector< const DetLayer * > nextLayers(const DetLayer &detLayer, Args &&...args) const
NavigationDirection.
double b
Definition: hdecay.h:120
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::ostream & operator<<(std::ostream &os, MSData d)
double a
Definition: hdecay.h:121
TkRotation< float > RotationType
T x() const
Definition: PV3DBase.h:62
T const * product() const
Definition: ESHandle.h:86
ib
Definition: cuy.py:660
Our base class.
Definition: SiPixelRecHit.h:23