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  //
82  TkNavigationSchool const& navSchool = dynamic_cast<TkNavigationSchool const&>(iRecord.get(theNavSchoolToken_));
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 
Vector3DBase
Definition: Vector3DBase.h:8
ConfigurationDescriptions.h
histoParameters_cff.maxLayers
maxLayers
Definition: histoParameters_cff.py:74
Chi2MeasurementEstimator.h
TkRotation< float >
KFUpdator::update
TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const override
Definition: KFUpdator.cc:177
TrajectoryStateOnSurface.h
TkMSParameterizationBuilder::thePropagatorToken_
edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropagatorToken_
Definition: TkMSParameterizationBuilder.cc:65
tkMSParameterization::packLID
constexpr unsigned short packLID(unsigned int id, unsigned int od)
Definition: TkMSParameterization.h:17
edm::ESInputTag
Definition: ESInputTag.h:87
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
TkMSParameterizationRecord
Definition: TkMSParameterizationRecord.h:13
TkMSParameterizationRecord.h
ESHandle.h
DetLayer
Definition: DetLayer.h:21
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
DiDispStaMuonMonitor_cfi.pt
pt
Definition: DiDispStaMuonMonitor_cfi.py:39
min
T min(T a, T b)
Definition: MathUtil.h:58
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
ESProducer.h
typelookup.h
operator<<
std::ostream & operator<<(std::ostream &os, MSData d)
Definition: TkMSParameterizationBuilder.cc:45
TkMSParameterization.h
GeometricSearchDet::compatibleDets
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
Definition: GeometricSearchDet.cc:35
GloballyPositioned< float >::RotationType
TkRotation< float > RotationType
Definition: GloballyPositioned.h:22
SiPixelRecHit
Our base class.
Definition: SiPixelRecHit.h:23
edm::Ref
Definition: AssociativeIterator.h:58
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
TkMSParameterizationBuilder::theNavSchoolToken_
edm::ESGetToken< NavigationSchool, NavigationSchoolRecord > theNavSchoolToken_
Definition: TkMSParameterizationBuilder.cc:64
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MakerMacros.h
PlaneBuilder.h
debug
#define debug
Definition: HDRShower.cc:19
Vector3DBase::unit
Vector3DBase unit() const
Definition: Vector3DBase.h:54
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
PVValHelper::estimator
estimator
Definition: PVValidationHelpers.h:45
CurvilinearTrajectoryError
Definition: CurvilinearTrajectoryError.h:27
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
tkMSParameterization::Elem
Definition: TkMSParameterization.h:26
DDAxes::z
Chi2MeasurementEstimator_cfi.Chi2MeasurementEstimator
Chi2MeasurementEstimator
Definition: Chi2MeasurementEstimator_cfi.py:5
HLT_FULL_cff.zAxis
zAxis
Definition: HLT_FULL_cff.py:46155
GlobalTrajectoryParameters
Definition: GlobalTrajectoryParameters.h:15
TkMSParameterizationBuilder::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: TkMSParameterizationBuilder.cc:53
Point3DBase< float, GlobalTag >
edm::eventsetup::DependentRecordImplementation::get
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
Definition: DependentRecordImplementation.h:109
SiPixelRecHit.h
b
double b
Definition: hdecay.h:118
TkNavigationSchool
Definition: TkNavigationSchool.h:12
TkMSParameterizationBuilder
Definition: TkMSParameterizationBuilder.cc:50
DetLayer::seqNum
int seqNum() const
Definition: DetLayer.h:35
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
runTauDisplay.gp
gp
Definition: runTauDisplay.py:431
TkMSParameterizationBuilder::ReturnType
std::unique_ptr< TkMSParameterization > ReturnType
Definition: TkMSParameterizationBuilder.cc:60
KFUpdator.h
edm::ParameterSet
Definition: ParameterSet.h:47
idealTransformation.rotation
dictionary rotation
Definition: idealTransformation.py:1
a
double a
Definition: hdecay.h:119
LocalError
Definition: LocalError.h:12
HLT_FULL_cff.yAxis
yAxis
Definition: HLT_FULL_cff.py:46156
ModuleDef.h
createfilelist.int
int
Definition: createfilelist.py:10
cuy.ib
ib
Definition: cuy.py:662
MagneticField.h
defaultRKPropagator.h
AnalyticalPropagator.h
HLT_FULL_cff.navSchool
navSchool
Definition: HLT_FULL_cff.py:15288
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
PlaneBuilder::plane
ReturnType plane(const PositionType &pos, const RotationType &rot) const
Definition: PlaneBuilder.h:21
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
cc
edm::ESGetToken< NavigationSchool, NavigationSchoolRecord >
TkNavigationSchool.h
alignCSCRings.r
r
Definition: alignCSCRings.py:93
tkMSParameterization::lmBin
constexpr float lmBin()
Definition: TkMSParameterization.h:23
groupFilesInBlocks.nn
nn
Definition: groupFilesInBlocks.py:150
DDAxes::phi
ModuleFactory.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
hcalSimParameters_cfi.he
he
Definition: hcalSimParameters_cfi.py:79
gen::C
C
Definition: PomwigHadronizer.cc:78
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
TrackingComponentsRecord.h
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
HLT_FULL_cff.xAxis
xAxis
Definition: HLT_FULL_cff.py:46154
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
GlobalVector.h
tkMSParameterization::nLmBins
constexpr unsigned int nLmBins()
Definition: TkMSParameterization.h:22
PlaneBuilder
Definition: PlaneBuilder.h:13
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
edm::ESProducer
Definition: ESProducer.h:104
ztail.d
d
Definition: ztail.py:151
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TkMSParameterizationBuilder::produce
ReturnType produce(TkMSParameterizationRecord const &)
Definition: TkMSParameterizationBuilder.cc:74
ParameterSet.h
NavigationSchoolRecord.h
ErrorFrameTransformer::transform
static GlobalError transform(const LocalError &le, const Surface &surf)
Definition: ErrorFrameTransformer.h:16
AlgebraicSymMatrix55
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
Definition: AlgebraicROOTObjects.h:23
spu::zerr
void zerr(int)
Definition: SherpackUtilities.cc:129
volumeBasedMagneticField_160812_cfi.magfield
magfield
Definition: volumeBasedMagneticField_160812_cfi.py:11
GlobalPoint.h
alongMomentum
Definition: PropagationDirection.h:4
TkMSParameterizationBuilder::TkMSParameterizationBuilder
TkMSParameterizationBuilder(edm::ParameterSet const &)
Definition: TkMSParameterizationBuilder.cc:68
KFUpdator
Definition: KFUpdator.h:32
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
tkMSParameterization
Definition: TkMSParameterization.h:15