44 struct LayerRZPredictions {
53 cfg.getParameter<double>(
"extraHitRZtolerance")),
55 "extraHitRPhitolerance")),
57 cfg.getParameter<double>(
"extraZKDBox")),
59 cfg.getParameter<double>(
"extraRKDBox")),
66 filterName_(
cfg.getParameter<
std::
string>(
"ClusterShapeHitFilterName")),
67 builderName_(
cfg.getParameter<
std::
string>(
"TTRHBuilder")),
71 dphi =
cfg.getParameter<
double>(
"phiPreFiltering");
73 pt_interv =
cfg.getParameter<std::vector<double> >(
"pt_interv");
74 chi2_cuts =
cfg.getParameter<std::vector<double> >(
"chi2_cuts");
88 if (
cfg.exists(
"SimpleMagneticField")) {
113 desc.add<
bool>(
"useFixedPreFiltering",
false);
114 desc.add<
double>(
"phiPreFiltering", 0.3);
117 desc.add<
double>(
"extraHitRPhitolerance", 0);
118 desc.add<
double>(
"extraHitRZtolerance", 0);
119 desc.add<
double>(
"extraZKDBox", 0.2);
120 desc.add<
double>(
"extraRKDBox", 0.2);
121 desc.add<
double>(
"extraPhiKDBox", 0.005);
122 desc.add<
double>(
"fnSigmaRZ", 2.0);
125 desc.add<
bool>(
"refitHits",
true);
126 desc.add<
std::string>(
"ClusterShapeHitFilterName",
"ClusterShapeHitFilter");
130 desc.add<
double>(
"maxChi2", 5.0);
131 desc.add<
bool>(
"chi2VsPtCut",
true);
132 desc.add<std::vector<double> >(
"pt_interv", std::vector<double>{{0.4, 0.7, 1.0, 2.0}});
133 desc.add<std::vector<double> >(
"chi2_cuts", std::vector<double>{{3.0, 4.0, 5.0, 5.0}});
136 desc.add<std::vector<int> >(
"detIdsToDebug", std::vector<int>{{0, 0, 0}});
148 cloner = (*builder).cloner();
169 std::vector<SeedingLayerSetsHits::SeedingLayer> thirdLayers) {
172 <<
" 3rd lay size: " << thirdLayers.size();
175 LogTrace(
"MultiHitGeneratorFromChi2") <<
"";
188 const std::vector<SeedingLayerSetsHits::SeedingLayer>& thirdLayers,
191 int size = thirdLayers.size();
193 vector<const DetLayer*> thirdLayerDetLayer(
size,
nullptr);
194 for (
int il = 0; il <
size; ++il) {
195 thirdHitMap[il] = &layerCache(thirdLayers[il],
region);
197 thirdLayerDetLayer[il] = thirdLayers[il].detLayer();
206 const std::vector<const DetLayer*>& thirdLayerDetLayer,
207 const int nThirdLayers) {
215 const std::vector<const DetLayer*>& thirdLayerDetLayer,
216 const int nThirdLayers,
224 std::array<bool, 3> bl;
225 bl[0] =
doublets.innerLayer().isBarrel;
226 bl[1] =
doublets.outerLayer().isBarrel;
231 std::vector<KDTreeNodeInfo<RecHitsSortedInPhi::HitIter, 2> > layerTree;
232 std::vector<RecHitsSortedInPhi::HitIter> foundNodes;
233 foundNodes.reserve(100);
236 float rzError[nThirdLayers];
239 const float maxphi =
M_PI + maxDelphi, minphi = -maxphi;
240 const float safePhi =
M_PI - maxDelphi;
243 for (
int il = 0; il < nThirdLayers; il++) {
244 LogTrace(
"MultiHitGeneratorFromChi2")
245 <<
"considering third layer: with hits: " << thirdHitMap[il]->
all().second - thirdHitMap[il]->
all().first;
247 LayerRZPredictions& predRZ = mapPred[il];
248 predRZ.line.initLayer(
layer);
252 auto const& layer3 = *thirdHitMap[il];
256 if (!layer3.empty()) {
259 for (
auto i = 0
U;
i < layer3.size(); ++
i) {
260 auto hi = layer3.theHits.begin() +
i;
261 auto angle = layer3.phi(
i);
262 auto myz = layer3.v[
i];
264 IfLogTrace(
hi->hit()->rawId() == debug_Id2,
"MultiHitGeneratorFromChi2")
265 <<
"filling KDTree with hit in id=" << debug_Id2 <<
" with pos: " <<
hi->hit()->globalPosition()
266 <<
" phi=" <<
hi->hit()->globalPosition().phi() <<
" z=" <<
hi->hit()->globalPosition().z()
267 <<
" r=" <<
hi->hit()->globalPosition().perp();
277 auto myerr = layer3.dv[
i];
278 if (myerr > maxErr) {
286 else if (
angle < -safePhi)
293 hitTree[il].build(layerTree, phiZ);
294 rzError[il] = maxErr;
301 LogTrace(
"MultiHitGeneratorFromChi2") <<
"doublet size=" <<
doublets.size() << std::endl;
312 if (
hh->isMatched()) {
317 }
else if (
hh->isProjected()) {
321 }
else if (
hh->isSingle()) {
331 for (std::size_t ip = 0; ip !=
doublets.size(); ip++) {
332 int foundTripletsFromPair = 0;
333 bool usePair =
false;
346 bool debugPair = oriHit0->rawId() == debug_Id0 && oriHit1->rawId() == debug_Id1;
348 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") << endl
350 <<
"found new pair with ids " << oriHit0->rawId() <<
" " 351 << oriHit1->rawId() <<
" with pos: " << gp0 <<
" " << gp1;
363 bool passFilterHit0 = filterHit(hit0->hit(), tsos0.
globalMomentum());
364 IfLogTrace(debugPair && !passFilterHit0,
"MultiHitGeneratorFromChi2") <<
"hit0 did not pass cluster shape filter";
367 bool passFilterHit1 = filterHit(hit1->hit(), tsos1.
globalMomentum());
368 IfLogTrace(debugPair && !passFilterHit1,
"MultiHitGeneratorFromChi2") <<
"hit1 did not pass cluster shape filter";
376 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2")
377 <<
"charge=" << tsos0.
charge() << std::endl
382 <<
"positions after refitting: " << hit0->globalPosition() <<
" " << hit1->globalPosition();
397 auto toPos = std::signbit(gp1.z() - gp0.
z());
402 if (!intersect(pairCurvature,
Range(-curv, curv))) {
403 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2")
404 <<
"curvature cut: curv=" << curv <<
" gc=(" << pairCurvature.first <<
", " << pairCurvature.second <<
")";
408 std::array<GlobalPoint, 3>
gp;
409 std::array<GlobalError, 3> ge;
410 gp[0] = hit0->globalPosition();
411 ge[0] = hit0->globalPositionError();
412 gp[1] = hit1->globalPosition();
413 ge[1] = hit1->globalPositionError();
416 for (
int il = 0; (il < nThirdLayers) & (!usePair); il++) {
417 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2")
419 <<
" for this pair. Location: " << thirdLayerDetLayer[il]->location();
421 if (hitTree[il].
empty()) {
422 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"empty hitTree";
431 auto const& layer3 = *thirdHitMap[il];
433 bl[2] = layer3.isBarrel;
435 if ((!barrelLayer) & (toPos != std::signbit(
layer->position().z())))
438 LayerRZPredictions& predRZ = mapPred[il];
439 predRZ.line.initPropagator(&
line);
443 Range rzRange = predRZ.line();
445 if (rzRange.first >= rzRange.second) {
446 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"rzRange empty";
451 if (!intersect(rzRange, predRZ.line.detSize())) {
452 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"rzRange and detector do not intersect";
455 Range radius = barrelLayer ? predRZ.line.detRange() : rzRange;
462 float phi0 = oriHit0->globalPosition().phi();
466 if (pairCurvature.first < 0. && pairCurvature.second < 0.) {
468 }
else if (pairCurvature.first >= 0. && pairCurvature.second >= 0.) {
473 auto phi12 = predictionRPhi.
phi(pairCurvature.first,
radius.first);
474 auto phi22 = predictionRPhi.
phi(pairCurvature.second,
radius.second);
476 phi22 =
proxim(phi22, phi12);
477 phiRange =
Range(phi12, phi22);
481 float prmin = phiRange.min(), prmax = phiRange.max();
483 if (prmax - prmin > maxDelphi) {
484 auto prm = phiRange.mean();
485 prmin = prm - 0.5f * maxDelphi;
486 prmax = prm + 0.5f * maxDelphi;
493 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"defining kd tree box";
500 hitTree[il].search(phiZ, foundNodes);
502 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2")
505 << rzRange.max() +
fnSigmaRZ * rzError[il] +
extraZKDBox <<
" rzRange: " << rzRange.min() <<
"," 513 hitTree[il].search(phiR, foundNodes);
515 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2")
518 << rzRange.max() +
fnSigmaRZ * rzError[il] +
extraRKDBox <<
" rzRange: " << rzRange.min() <<
"," 522 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"kd tree box size: " << foundNodes.size();
525 for (std::vector<RecHitsSortedInPhi::HitIter>::iterator ih = foundNodes.begin();
526 ih != foundNodes.end() && !usePair;
528 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") << endl <<
"triplet candidate";
532 auto oriHit2 = KDdata->hit();
533 auto kk = KDdata - layer3.theHits.begin();
535 auto gp2 = layer3.gp(
kk);
540 initMomentum /= initMomentum.
perp();
543 bool passFilterHit2 = filterHit(oriHit2->hit(), initMomentum);
547 *oriHit2->surface());
556 gp[2] = hit2->globalPosition();
557 ge[2] = hit2->globalPositionError();
562 bool debugTriplet = debugPair && hit2->rawId() == debug_Id2;
564 IfLogTrace(debugTriplet,
"MultiHitGeneratorFromChi2")
566 <<
"triplet candidate in debug id" << std::endl
567 <<
"hit in id=" << hit2->rawId() <<
" (from KDTree) with pos: " << KDdata->hit()->globalPosition()
568 <<
" refitted: " << hit2->globalPosition() <<
" chi2: " <<
chi2;
576 float rho = theCircle.
rho();
577 float cm2GeV = 0.01f * 0.3f * tesla0;
578 float pt = cm2GeV *
rho;
579 IfLogTrace(debugTriplet,
"MultiHitGeneratorFromChi2") <<
"triplet pT=" <<
pt;
609 edm::LogError(
"TooManyTriplets") <<
" number of triples exceed maximum. no triplets produced.";
612 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"triplet made";
623 chi2FromThisLayer =
chi2;
624 foundTripletsFromPair++;
625 if (foundTripletsFromPair >= 2) {
627 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"using pair";
636 if (chi2FromThisLayer <
minChi2) {
650 if (foundTripletsFromPair == 0)
654 IfLogTrace(debugPair,
"MultiHitGeneratorFromChi2") <<
"Done seed #" <<
result.size();
658 assert(1 == foundTripletsFromPair);
660 result.emplace_back(&*hit0, &*hit1, &*bestH2);
663 refittedHitStorage.emplace_back(const_cast<BaseTrackerRecHit*>(hit0.
release()));
664 refittedHitStorage.emplace_back(const_cast<BaseTrackerRecHit*>(hit1.
release()));
665 refittedHitStorage.emplace_back(
std::move(bestH2));
673 LogTrace(
"MultiHitGeneratorFromChi2") <<
"triplet size=" <<
result.size();
689 IfLogTrace(isDebug,
"MultiHitGeneratorFromChi2")
690 <<
"positions before refitting: " << hit1->globalPosition() <<
" " << hit2->globalPosition();
695 float rho = theCircle.
rho();
696 float cm2GeV = 0.01f * 0.3f * tesla0;
697 float pt = cm2GeV *
rho;
702 GlobalVector p0(gp0.y() - cc.y(), -gp0.x() + cc.x(), 0.);
710 if ((p0.
x() * (gp1.
x() - gp0.x()) + p0.
y() * (gp1.
y() - gp0.y())) < 0) {
717 auto zv = vec20.
z() / vec20.
perp();
724 if ((gp1 - cc).x() *
p1.y() - (gp1 - cc).
y() *
p1.x() > 0)
LayerCacheType * theLayerCache
MultiHitGeneratorFromChi2(const edm::ParameterSet &cfg, edm::ConsumesCollector &&iC)
~MultiHitGeneratorFromChi2() override
__constant__ float const maxz[nPairs]
std::unique_ptr< BaseTrackerRecHit > cacheHitPointer
__constant__ float const minz[nPairs]
#define IfLogTrace(cond, cat)
constexpr bool isNotFinite(T x)
static constexpr auto TID
TkTransientTrackingRecHitBuilder const * builder
std::vector< cacheHitPointer > cacheHits
std::vector< int > detIdsToDebug
const ClusterShapeHitFilter * filter
Geom::Phi< T > phi() const
constexpr T normalizedPhi(T phi)
unsigned int stereoId() const
Log< level::Error, false > LogError
edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > transientTrackingRecHitBuilderESToken_
bool isCompatible(const SiPixelRecHit &recHit, const LocalVector &ldir, const SiPixelClusterShapeCache &clusterShapeCache, PixelData const *pd=nullptr) const
void swap(Association< C > &lhs, Association< C > &rhs)
T curvature(T InversePt, const MagneticField &field)
constexpr T proxim(T b, T a)
constexpr std::array< uint8_t, layerIndexSize > layer
U second(std::pair< T, U > const &p)
constexpr float fnSigmaRZ
BaseTrackerRecHit const * ConstRecHitPointer
bool useFixedPreFiltering
SiStripCluster const & monoCluster() const
std::vector< HitWithPhi >::const_iterator HitIter
const MagneticField * bfield
edm::ESGetToken< ClusterShapeHitFilter, CkfComponentsRecord > clusterShapeHitFilterESToken_
void initES(const edm::EventSetup &es) override
TrackCharge charge() const
bool getData(T &iHolder) const
std::vector< double > pt_interv
BaseTrackerRecHit const * Hit
UniformMagneticField ufield
unsigned int monoId() const
float extraHitRZtolerance
void hitSets(const TrackingRegion ®ion, OrderedMultiHits &trs, const edm::Event &ev, const edm::EventSetup &es, SeedingLayerSetsHits::SeedingLayerSet pairLayers, std::vector< SeedingLayerSetsHits::SeedingLayer > thirdLayers) override
GlobalVector globalMomentum() const
SiStripCluster const & stereoCluster() const
static constexpr auto TIB
float extraHitRPhitolerance
std::vector< double > chi2_cuts
void hitTriplets(const TrackingRegion ®ion, OrderedMultiHits &result, const HitDoublets &doublets, const RecHitsSortedInPhi **thirdHitMap, const std::vector< const DetLayer *> &thirdLayerDetLayer, const int nThirdLayers) override
SiStripRecHit2D originalHit() const
std::unique_ptr< HitPairGeneratorFromLayerPair > thePairGenerator
static void fillDescriptions(edm::ParameterSetDescription &desc)
int nominalValue() const
The nominal field value for this map in kGauss.
#define declareDynArray(T, n, x)
const unsigned int theMaxElement
PixelRecoRange< float > Range
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magneticFieldESToken_
static void fillDescriptions(edm::ParameterSetDescription &desc)
float phi(float curvature, float radius) const
Global3DVector GlobalVector
Range curvature(double transverseIP) const
void refit2Hits(HitOwnPtr &hit0, HitOwnPtr &hit1, TrajectoryStateOnSurface &tsos0, TrajectoryStateOnSurface &tsos1, const TrackingRegion ®ion, float nomField, bool isDebug)
T angle(T x1, T y1, T z1, T x2, T y2, T z2)