45 struct LayerRZPredictions {
51 : thePairGenerator(0),
53 useFixedPreFiltering(cfg.getParameter<bool>(
"useFixedPreFiltering")),
54 extraHitRZtolerance(cfg.getParameter<double>(
"extraHitRZtolerance")),
55 extraHitRPhitolerance(cfg.getParameter<double>(
"extraHitRPhitolerance")),
56 extraZKDBox(cfg.getParameter<double>(
"extraZKDBox")),
57 extraRKDBox(cfg.getParameter<double>(
"extraRKDBox")),
59 fnSigmaRZ(cfg.getParameter<double>(
"fnSigmaRZ")),
60 chi2VsPtCut(cfg.getParameter<bool>(
"chi2VsPtCut")),
61 maxChi2(cfg.getParameter<double>(
"maxChi2")),
62 refitHits(cfg.getParameter<bool>(
"refitHits")),
63 debug(cfg.getParameter<bool>(
"debug")),
64 filterName_(cfg.getParameter<std::
string>(
"ClusterShapeHitFilterName")),
65 builderName_(cfg.existsAs<std::
string>(
"TTRHBuilder") ? cfg.getParameter<std::
string>(
"TTRHBuilder") : std::
string(
"WithTrackAngle")),
88 if (cfg.
exists(
"SimpleMagneticField")) {
120 cloner = (*builder).cloner();
124 std::vector<SeedingLayerSetsHits::SeedingLayer> thirdLayers) {
133 if (range.first > second.max() || range.second < second.min())
135 if (range.first < second.min())
136 range.first = second.min();
137 if (range.second > second.max())
138 range.second = second.max();
139 return range.first < range.second;
157 pairs.reserve(30000);
158 thePairGenerator->hitPairs(region,pairs,ev,es);
170 std::vector<KDTreeNodeInfo<RecHitsSortedInPhi::HitIter> > layerTree;
171 std::vector<RecHitsSortedInPhi::HitIter> foundNodes;
172 foundNodes.reserve(100);
174 std::vector<KDTreeLinkerAlgo<RecHitsSortedInPhi::HitIter>> hitTree(size);
181 map<std::string, LayerRZPredictions> mapPred;
185 for(
int il = 0; il <
size; il++) {
186 thirdHitMap[il] = &(*theLayerCache)(
theLayers[il], region,
ev, es);
187 if (
debug)
cout <<
"considering third layer: " << theLayers[il].name() <<
" with hits: " << thirdHitMap[il]->
all().second-thirdHitMap[il]->
all().first << endl;
188 const DetLayer *layer = theLayers[il].detLayer();
189 LayerRZPredictions &predRZ = mapPred[theLayers[il].name()];
190 predRZ.line.initLayer(layer);
196 double minz=999999.0, maxz= -999999.0;
199 if (hitRange.first != hitRange.second)
200 { minz = barrelLayer? hitRange.first->hit()->globalPosition().z() : hitRange.first->hit()->globalPosition().perp();
203 {
double angle = hi->phi();
204 double myz = barrelLayer? hi->hit()->globalPosition().z() : hi->hit()->globalPosition().perp();
206 if (
debug && hi->hit()->rawId()==debug_Id2) {
207 cout <<
"filling KDTree with hit in id=" << debug_Id2
208 <<
" with pos: " << hi->hit()->globalPosition()
209 <<
" phi=" << hi->hit()->globalPosition().phi()
210 <<
" z=" << hi->hit()->globalPosition().z()
211 <<
" r=" << hi->hit()->globalPosition().perp()
215 if (myz < minz) { minz = myz;}
else {
if (myz > maxz) {maxz = myz;}}
216 float myerr = barrelLayer? hi->hit()->errorGlobalZ(): hi->hit()->errorGlobalR();
217 if (myerr > maxErr) { maxErr = myerr;}
225 KDTreeBox phiZ(minphi, maxphi, minz-0.01, maxz+0.01);
227 hitTree[il].
build(layerTree, phiZ);
228 rzError[il] = maxErr;
238 for (OrderedHitPairs::const_iterator ip = pairs.begin(); ip != pairs.end(); ++ip) {
240 int foundTripletsFromPair = 0;
241 bool usePair =
false;
253 bool debugPair =
debug && ip->inner()->rawId()==debug_Id0 && ip->outer()->rawId()==debug_Id1;
257 <<
"found new pair with ids "<<debug_Id0<<
" "<<debug_Id1<<
" with pos: " << gp0 <<
" " << gp1
269 bool passFilterHit0 =
true;
276 const std::type_info &tid =
typeid(*hit0->hit());
289 if (debugPair&&!passFilterHit0)
cout <<
"hit0 did not pass cluster shape filter" << endl;
290 if (!passFilterHit0)
continue;
291 bool passFilterHit1 =
true;
298 const std::type_info &tid =
typeid(*hit1->hit());
311 if (debugPair&&!passFilterHit1)
cout <<
"hit1 did not pass cluster shape filter" << endl;
312 if (!passFilterHit1)
continue;
327 if (!intersect(pairCurvature,
Range(-curv, curv))) {
328 if (debugPair)
std::cout <<
"curvature cut: curv=" << curv
329 <<
" gc=(" << pairCurvature.first <<
", " << pairCurvature.second <<
")" << std::endl;
334 for(
int il = 0; (il <
size) & (!usePair); il++) {
337 cout <<
"cosider layer: " <<
theLayers[il].name() <<
" for this pair. Location: " <<
theLayers[il].detLayer()->location() << endl;
339 if (hitTree[il].
empty()) {
341 cout <<
"empty hitTree" << endl;
352 LayerRZPredictions &predRZ = mapPred.find(
theLayers[il].
name())->second;
353 predRZ.line.initPropagator(&line);
357 Range rzRange = predRZ.line();
359 if (rzRange.first >= rzRange.second) {
361 cout <<
"rzRange empty" << endl;
367 if (!intersect(rzRange, predRZ.line.detSize())) {
369 cout <<
"rzRange and detector do not intersect" << endl;
373 Range radius = barrelLayer ? predRZ.line.detRange() : rzRange;
380 float phi0 = ip->outer()->globalPosition().phi();
384 if (pairCurvature.first<0. && pairCurvature.second<0.) {
385 float phi12 = predictionRPhi.
phi(pairCurvature.first,radius.second);
386 float phi21 = predictionRPhi.
phi(pairCurvature.second,radius.first);
387 while(
unlikely(phi12 < phi21)) phi12 += float(2. *
M_PI);
388 phiRange =
Range(phi21,phi12);
389 }
else if (pairCurvature.first>=0. && pairCurvature.second>=0.) {
390 float phi11 = predictionRPhi.
phi(pairCurvature.first,radius.first);
391 float phi22 = predictionRPhi.
phi(pairCurvature.second,radius.second);
392 while(
unlikely(phi11 < phi22)) phi11 += float(2. *
M_PI);
393 phiRange =
Range(phi22,phi11);
395 float phi12 = predictionRPhi.
phi(pairCurvature.first,radius.second);
396 float phi22 = predictionRPhi.
phi(pairCurvature.second,radius.second);
397 while(
unlikely(phi12 < phi22)) phi12 += float(2. *
M_PI);
398 phiRange =
Range(phi22,phi12);
406 float prmin=phiRange.min(), prmax=phiRange.max();
414 if (debugPair)
cout <<
"defining kd tree box" << endl;
420 hitTree[il].
search(phiZ, foundNodes);
423 <<
" z: "<< rzRange.min()-
fnSigmaRZ*rzError[il]-extraZKDBox <<
","<<rzRange.max()+
fnSigmaRZ*rzError[il]+extraZKDBox
424 <<
" rzRange: " << rzRange.min() <<
","<<rzRange.max()
431 hitTree[il].
search(phiR, foundNodes);
434 <<
" r: "<< rzRange.min()-
fnSigmaRZ*rzError[il]-extraRKDBox <<
","<<rzRange.max()+
fnSigmaRZ*rzError[il]+extraRKDBox
435 <<
" rzRange: " << rzRange.min() <<
","<<rzRange.max()
439 if (debugPair)
cout <<
"kd tree box size: " << foundNodes.size() << endl;
443 for (std::vector<RecHitsSortedInPhi::HitIter>::iterator ih = foundNodes.begin();
444 ih !=foundNodes.end() && !usePair; ++ih) {
446 if (debugPair)
std::cout << endl <<
"triplet candidate" << std::endl;
456 GlobalVector initMomentum(oriHit2->globalPosition() - gp1);
457 initMomentum *= (1./initMomentum.perp());
463 bool passFilterHit2 =
true;
469 const std::type_info &tid =
typeid(*hit2->hit());
482 if (debugPair&&!passFilterHit2)
cout <<
"hit2 did not pass cluster shape filter" << endl;
483 if (!passFilterHit2)
continue;
513 vector<GlobalPoint> gp(3);
514 vector<GlobalError> ge(3);
516 gp[0] = hit0->globalPosition();
517 ge[0] = hit0->globalPositionError();
518 int subid0 = hit0->geographicalId().subdetId();
520 gp[1] = hit1->globalPosition();
521 ge[1] = hit1->globalPositionError();
522 int subid1 = hit1->geographicalId().subdetId();
524 gp[2] = hit2->globalPosition();
525 ge[2] = hit2->globalPositionError();
526 int subid2 = hit2->geographicalId().subdetId();
529 float cottheta, intercept, covss, covii, covsi;
530 rzLine.
fit(cottheta, intercept, covss, covii, covsi);
531 float chi2 = rzLine.
chi2(cottheta, intercept);
533 bool debugTriplet = debugPair && hit2->rawId()==debug_Id2;
535 std::cout << endl <<
"triplet candidate in debug id" << std::endl;
536 cout <<
"hit in id="<<hit2->rawId()<<
" (from KDTree) with pos: " << KDdata->hit()->globalPosition()
537 <<
" refitted: " << hit2->globalPosition()
547 FastCircle theCircle(hit2->globalPosition(),hit1->globalPosition(),hit0->globalPosition());
549 float rho = theCircle.rho();
550 float cm2GeV = 0.01 * 0.3*tesla0;
551 float pt = cm2GeV *
rho;
553 std::cout <<
"triplet pT=" << pt << std::endl;
555 if (pt<region.
ptMin())
continue;
583 edm::LogError(
"TooManyTriplets")<<
" number of triples exceed maximum. no triplets produced.";
586 if (debugPair)
std::cout <<
"triplet made" << std::endl;
596 bestL2 = std::move(hit2);
597 chi2FromThisLayer = chi2;
598 foundTripletsFromPair++;
599 if (foundTripletsFromPair>=2) {
610 if (chi2FromThisLayer<minChi2) {
611 bestH2 = std::move(bestL2);
612 minChi2 = chi2FromThisLayer;
624 if (foundTripletsFromPair==0)
continue;
627 if (debugPair)
std::cout <<
"Done seed #" << result.
size() << std::endl;
628 if (usePair) result.push_back(
SeedingHitSet(ip->inner(), ip->outer()));
630 assert(1==foundTripletsFromPair);
632 result.emplace_back(&*hit0,&*hit1,&*bestH2);
634 cache.emplace_back(const_cast<BaseTrackerRecHit*>(hit0.
release()));
635 cache.emplace_back(const_cast<BaseTrackerRecHit*>(hit1.
release()));
636 cache.emplace_back(std::move(bestH2));
637 assert(hit0.
empty()); assert(hit1.
empty());assert(!bestH2);
649 {
while (phi > phi2) phi -= 2. *
M_PI;
650 while (phi < phi1) phi += 2. *
M_PI;
654 std::pair<float, float>
656 const std::pair<float, float> &
r2)
const
657 {
float r2Min = r2.first;
658 float r2Max = r2.second;
659 while (r1.first - r2Min > +
M_PI) r2Min += 2. *
M_PI, r2Max += 2. *
M_PI;
660 while (r1.first - r2Min < -
M_PI) r2Min -= 2. *
M_PI, r2Max -= 2. *
M_PI;
662 return std::make_pair(
min(r1.first, r2Min),
max(r1.second, r2Max));
677 cout <<
"positions before refitting: " << hit1->globalPosition() <<
" " << hit2->globalPosition() <<endl;
683 float rho = theCircle.
rho();
684 float cm2GeV = 0.01 * 0.3*tesla0;
685 float pt = cm2GeV *
rho;
691 p0 = p0*pt/p0.
perp();
693 p1 = p1*pt/p1.perp();
695 p2 = p2*pt/p2.perp();
698 if ( (p0.x()*(gp1.
x()-gp0.x())+p0.y()*(gp1.
y()-gp0.y()) ) < 0 ) {
711 if ((gp1-cc).
x()*p1.y() - (gp1-cc).
y()*p1.x() > 0) q =-q;
722 cout <<
"charge=" << q << endl;
725 cout <<
"positions after refitting: " << hit1->globalPosition() <<
" " << hit2->globalPosition() <<endl;
float originRBound() const
bounds the particle vertex in the transverse plane
T getParameter(std::string const &) const
std::pair< float, float > mergePhiRanges(const std::pair< float, float > &r1, const std::pair< float, float > &r2) const
virtual HitPairGenerator * clone() const =0
unsigned int stereoId() const
void build(std::vector< KDTreeNodeInfo > &eltList, const KDTreeBox ®ion)
GlobalPoint const & origin() const
virtual Location location() const =0
Which part of the detector (barrel, endcap)
int nominalValue() const
The nominal field value for this map in kGauss.
TkTransientTrackingRecHitBuilder const * builder
std::vector< int > detIdsToDebug
SiStripCluster const & monoCluster() const
const ClusterShapeHitFilter * filter
Geom::Phi< T > phi() const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual unsigned int size() const
void search(const KDTreeBox &searchBox, std::vector< KDTreeNodeInfo > &resRecHitList)
Range curvature(double transverseIP) const
std::vector< SeedingLayerSetsHits::SeedingLayer > theLayers
Geom::Theta< T > theta() const
LocalVector localMomentum() const
U second(std::pair< T, U > const &p)
virtual unsigned int size() const
void init(const HitPairGenerator &pairs, LayerCacheType *layerCache) override
std::pair< HitIter, HitIter > Range
BaseTrackerRecHit const * ConstRecHitPointer
T curvature(T InversePt, const edm::EventSetup &iSetup)
bool useFixedPreFiltering
std::vector< HitWithPhi >::const_iterator HitIter
LayerCacheType * theLayerCache
void setSeedingLayers(SeedingLayerSetsHits::SeedingLayerSet pairLayers, std::vector< SeedingLayerSetsHits::SeedingLayer > thirdLayers) override
const MagneticField * bfield
void initES(const edm::EventSetup &es) override
Tan< T >::type tan(const T &t)
MultiHitGeneratorFromChi2(const edm::ParameterSet &cfg)
unsigned int theMaxElement
std::vector< double > pt_interv
bool isCompatible(const SiPixelRecHit &recHit, const LocalVector &ldir, const SiPixelClusterShapeCache &clusterShapeCache, PixelData const *pd=0) const
SeedingHitSet::ConstRecHitPointer Hit
BaseTrackerRecHit const * Hit
SiStripRecHit2D originalHit() const
PixelRecoRange< float > Range
float extraHitRZtolerance
HitPairGenerator * thePairGenerator
T const * product() const
float ptMin() const
minimal pt of interest
float extraHitRPhitolerance
std::vector< double > chi2_cuts
SiStripCluster const & stereoCluster() const
GlobalVector globalMomentum() const
void fit(float &cotTheta, float &intercept, float &covss, float &covii, float &covsi) const
float chi2(float cotTheta, float intercept) const
unsigned int monoId() const
volatile std::atomic< bool > shutdown_flag false
std::unique_ptr< BaseTrackerRecHit > cacheHitPointer
list pairs
sort tag files by run number
float phi(float curvature, float radius) const
tuple size
Write out results.
virtual void setSeedingLayers(SeedingLayerSetsHits::SeedingLayerSet layers)=0
bool checkPhiInRange(float phi, float phi1, float phi2) const
virtual void hitSets(const TrackingRegion ®ion, OrderedMultiHits &trs, const edm::Event &ev, const edm::EventSetup &es)
Global3DVector GlobalVector
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)