49 struct LayerRZPredictions {
58 cfg.getParameter<double>(
"extraHitRZtolerance")),
60 "extraHitRPhitolerance")),
62 cfg.getParameter<double>(
"extraZKDBox")),
64 cfg.getParameter<double>(
"extraRKDBox")),
71 filterName_(
cfg.getParameter<
std::
string>(
"ClusterShapeHitFilterName")),
77 dphi =
cfg.getParameter<
double>(
"phiPreFiltering");
79 pt_interv =
cfg.getParameter<std::vector<double> >(
"pt_interv");
80 chi2_cuts =
cfg.getParameter<std::vector<double> >(
"chi2_cuts");
94 if (
cfg.exists(
"SimpleMagneticField")) {
109 desc.add<
bool>(
"useFixedPreFiltering",
false);
110 desc.add<
double>(
"phiPreFiltering", 0.3);
113 desc.add<
double>(
"extraHitRPhitolerance", 0);
114 desc.add<
double>(
"extraHitRZtolerance", 0);
115 desc.add<
double>(
"extraZKDBox", 0.2);
116 desc.add<
double>(
"extraRKDBox", 0.2);
117 desc.add<
double>(
"extraPhiKDBox", 0.005);
118 desc.add<
double>(
"fnSigmaRZ", 2.0);
121 desc.add<
bool>(
"refitHits",
true);
122 desc.add<
std::string>(
"ClusterShapeHitFilterName",
"ClusterShapeHitFilter");
126 desc.add<
double>(
"maxChi2", 5.0);
127 desc.add<
bool>(
"chi2VsPtCut",
true);
128 desc.add<std::vector<double> >(
"pt_interv", std::vector<double>{{0.4, 0.7, 1.0, 2.0}});
129 desc.add<std::vector<double> >(
"chi2_cuts", std::vector<double>{{3.0, 4.0, 5.0, 5.0}});
132 desc.add<std::vector<int> >(
"detIdsToDebug", std::vector<int>{{0, 0, 0}});
153 cloner = (*builder).cloner();
174 std::vector<SeedingLayerSetsHits::SeedingLayer> thirdLayers) {
177 <<
" 3rd lay size: " << thirdLayers.size();
180 LogTrace(
"MultiHitGeneratorFromChi2") <<
"";
195 const std::vector<SeedingLayerSetsHits::SeedingLayer>& thirdLayers,
198 int size = thirdLayers.size();
200 vector<const DetLayer*> thirdLayerDetLayer(
size,
nullptr);
201 for (
int il = 0; il <
size; ++il) {
202 thirdHitMap[il] = &layerCache(thirdLayers[il],
region, es);
204 thirdLayerDetLayer[il] = thirdLayers[il].detLayer();
214 const std::vector<const DetLayer*>& thirdLayerDetLayer,
215 const int nThirdLayers) {
224 const std::vector<const DetLayer*>& thirdLayerDetLayer,
225 const int nThirdLayers,
233 std::array<bool, 3> bl;
234 bl[0] =
doublets.innerLayer().isBarrel;
235 bl[1] =
doublets.outerLayer().isBarrel;
240 std::vector<KDTreeNodeInfo<RecHitsSortedInPhi::HitIter, 2> > layerTree;
241 std::vector<RecHitsSortedInPhi::HitIter> foundNodes;
242 foundNodes.reserve(100);
245 float rzError[nThirdLayers];
248 const float maxphi =
M_PI + maxDelphi, minphi = -maxphi;
249 const float safePhi =
M_PI - maxDelphi;
252 for (
int il = 0; il < nThirdLayers; il++) {
253 LogTrace(
"MultiHitGeneratorFromChi2")
254 <<
"considering third layer: with hits: " << thirdHitMap[il]->
all().second - thirdHitMap[il]->
all().first;
256 LayerRZPredictions& predRZ = mapPred[il];
257 predRZ.line.initLayer(
layer);
261 auto const& layer3 = *thirdHitMap[il];
265 if (!layer3.empty()) {
268 for (
auto i = 0
U;
i < layer3.size(); ++
i) {
269 auto hi = layer3.theHits.begin() +
i;
270 auto angle = layer3.phi(
i);
271 auto myz = layer3.v[
i];
273 IfLogTrace(
hi->hit()->rawId() == debug_Id2,
"MultiHitGeneratorFromChi2")
274 <<
"filling KDTree with hit in id=" << debug_Id2 <<
" with pos: " <<
hi->hit()->globalPosition()
275 <<
" phi=" <<
hi->hit()->globalPosition().phi() <<
" z=" <<
hi->hit()->globalPosition().z()
276 <<
" r=" <<
hi->hit()->globalPosition().perp();
286 auto myerr = layer3.dv[
i];
287 if (myerr > maxErr) {
295 else if (
angle < -safePhi)
302 hitTree[il].build(layerTree, phiZ);
303 rzError[il] = maxErr;
310 LogTrace(
"MultiHitGeneratorFromChi2") <<
"doublet size=" <<
doublets.size() << std::endl;
314 auto hh = reinterpret_cast<BaseTrackerRecHit const*>(
hit);
321 if (
hh->isMatched()) {
326 }
else if (
hh->isProjected()) {
330 }
else if (
hh->isSingle()) {
340 for (std::size_t ip = 0; ip !=
doublets.size(); ip++) {
341 int foundTripletsFromPair = 0;
342 bool usePair =
false;
355 bool debugPair = oriHit0->rawId() == debug_Id0 && oriHit1->rawId() == debug_Id1;
357 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") << endl
359 <<
"found new pair with ids " << oriHit0->rawId() <<
" "
360 << oriHit1->rawId() <<
" with pos: " << gp0 <<
" " << gp1;
372 bool passFilterHit0 = filterHit(hit0->hit(), tsos0.
globalMomentum());
373 IfLogTrace(debugPair && !passFilterHit0,
"MultiHitGeneratorFromChi2") <<
"hit0 did not pass cluster shape filter";
376 bool passFilterHit1 = filterHit(hit1->hit(), tsos1.
globalMomentum());
377 IfLogTrace(debugPair && !passFilterHit1,
"MultiHitGeneratorFromChi2") <<
"hit1 did not pass cluster shape filter";
385 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2")
386 <<
"charge=" << tsos0.
charge() << std::endl
391 <<
"positions after refitting: " << hit0->globalPosition() <<
" " << hit1->globalPosition();
406 auto toPos = std::signbit(gp1.z() - gp0.
z());
411 if (!intersect(pairCurvature,
Range(-curv, curv))) {
412 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2")
413 <<
"curvature cut: curv=" << curv <<
" gc=(" << pairCurvature.first <<
", " << pairCurvature.second <<
")";
417 std::array<GlobalPoint, 3>
gp;
418 std::array<GlobalError, 3> ge;
419 gp[0] = hit0->globalPosition();
420 ge[0] = hit0->globalPositionError();
421 gp[1] = hit1->globalPosition();
422 ge[1] = hit1->globalPositionError();
425 for (
int il = 0; (il < nThirdLayers) & (!usePair); il++) {
426 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2")
428 <<
" for this pair. Location: " << thirdLayerDetLayer[il]->location();
430 if (hitTree[il].
empty()) {
431 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"empty hitTree";
440 auto const& layer3 = *thirdHitMap[il];
442 bl[2] = layer3.isBarrel;
444 if ((!barrelLayer) & (toPos != std::signbit(
layer->position().z())))
447 LayerRZPredictions& predRZ = mapPred[il];
448 predRZ.line.initPropagator(&
line);
452 Range rzRange = predRZ.line();
454 if (rzRange.first >= rzRange.second) {
455 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"rzRange empty";
460 if (!intersect(rzRange, predRZ.line.detSize())) {
461 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"rzRange and detector do not intersect";
464 Range radius = barrelLayer ? predRZ.line.detRange() : rzRange;
471 float phi0 = oriHit0->globalPosition().phi();
475 if (pairCurvature.first < 0. && pairCurvature.second < 0.) {
477 }
else if (pairCurvature.first >= 0. && pairCurvature.second >= 0.) {
482 auto phi12 = predictionRPhi.
phi(pairCurvature.first,
radius.first);
483 auto phi22 = predictionRPhi.
phi(pairCurvature.second,
radius.second);
485 phi22 =
proxim(phi22, phi12);
486 phiRange =
Range(phi12, phi22);
490 float prmin = phiRange.min(), prmax = phiRange.max();
492 if (prmax - prmin > maxDelphi) {
493 auto prm = phiRange.mean();
494 prmin = prm - 0.5f * maxDelphi;
495 prmax = prm + 0.5f * maxDelphi;
502 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"defining kd tree box";
509 hitTree[il].search(phiZ, foundNodes);
511 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2")
514 << rzRange.max() +
fnSigmaRZ * rzError[il] +
extraZKDBox <<
" rzRange: " << rzRange.min() <<
","
522 hitTree[il].search(phiR, foundNodes);
524 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2")
527 << rzRange.max() +
fnSigmaRZ * rzError[il] +
extraRKDBox <<
" rzRange: " << rzRange.min() <<
","
531 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"kd tree box size: " << foundNodes.size();
534 for (std::vector<RecHitsSortedInPhi::HitIter>::iterator ih = foundNodes.begin();
535 ih != foundNodes.end() && !usePair;
537 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") << endl <<
"triplet candidate";
541 auto oriHit2 = KDdata->hit();
542 auto kk = KDdata - layer3.theHits.begin();
544 auto gp2 = layer3.gp(
kk);
549 initMomentum /= initMomentum.
perp();
552 bool passFilterHit2 = filterHit(oriHit2->hit(), initMomentum);
556 *oriHit2->surface());
565 gp[2] = hit2->globalPosition();
566 ge[2] = hit2->globalPositionError();
571 bool debugTriplet = debugPair && hit2->rawId() == debug_Id2;
573 IfLogTrace(debugTriplet,
"MultiHitGeneratorFromChi2")
575 <<
"triplet candidate in debug id" << std::endl
576 <<
"hit in id=" << hit2->rawId() <<
" (from KDTree) with pos: " << KDdata->hit()->globalPosition()
577 <<
" refitted: " << hit2->globalPosition() <<
" chi2: " <<
chi2;
585 float rho = theCircle.
rho();
586 float cm2GeV = 0.01f * 0.3f * tesla0;
587 float pt = cm2GeV *
rho;
588 IfLogTrace(debugTriplet,
"MultiHitGeneratorFromChi2") <<
"triplet pT=" <<
pt;
618 edm::LogError(
"TooManyTriplets") <<
" number of triples exceed maximum. no triplets produced.";
621 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"triplet made";
632 chi2FromThisLayer =
chi2;
633 foundTripletsFromPair++;
634 if (foundTripletsFromPair >= 2) {
636 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"using pair";
645 if (chi2FromThisLayer <
minChi2) {
659 if (foundTripletsFromPair == 0)
663 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"Done seed #" <<
result.size();
667 assert(1 == foundTripletsFromPair);
669 result.emplace_back(&*hit0, &*hit1, &*bestH2);
672 refittedHitStorage.emplace_back(const_cast<BaseTrackerRecHit*>(hit0.
release()));
673 refittedHitStorage.emplace_back(const_cast<BaseTrackerRecHit*>(hit1.
release()));
674 refittedHitStorage.emplace_back(
std::move(bestH2));
682 LogTrace(
"MultiHitGeneratorFromChi2") <<
"triplet size=" <<
result.size();
698 IfLogTrace(isDebug,
"MultiHitGeneratorFromChi2")
699 <<
"positions before refitting: " << hit1->globalPosition() <<
" " << hit2->globalPosition();
704 float rho = theCircle.
rho();
705 float cm2GeV = 0.01f * 0.3f * tesla0;
706 float pt = cm2GeV *
rho;
719 if ((p0.
x() * (gp1.
x() - gp0.x()) + p0.
y() * (gp1.
y() - gp0.y())) < 0) {
726 auto zv = vec20.
z() / vec20.
perp();
733 if ((gp1 -
cc).x() *
p1.y() - (gp1 -
cc).
y() *
p1.x() > 0)