CMS 3D CMS Logo

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