38 double delta = gluedPlane.localZ( hitPlane.position());
41 LocalPoint projectedHitPos = lhitPos - ldir * delta/ldir.
z();
45 if (gluedPlane.normalVector().dot( hitPlane.normalVector()) < 0) {
51 return std::make_pair(projectedHitPos, rotatedError);
56 std::pair<LocalPoint,LocalError> projectedPos(
const TrackingRecHit& hit,
60 return projectedPos(hit, det, gdir, cpe);
69 TkGluedMeasurementDet::TkGluedMeasurementDet(
const GluedGeomDet* gdet,
73 theMatcher(matcher), theCPE(cpe),
79 theMonoDet =
dynamic_cast<const TkStripMeasurementDet *
>(monoDet);
80 theStereoDet =
dynamic_cast<const TkStripMeasurementDet *
>(stereoDet);
82 if ((theMonoDet == 0) || (theStereoDet == 0)) {
83 throw MeasurementDetException(
"TkGluedMeasurementDet ERROR: Trying to glue a det which is not a TkStripMeasurementDet");
87 TkGluedMeasurementDet::RecHitContainer
92 HitCollectorForRecHits collector( &fastGeomDet(), theMatcher, theCPE, result );
93 collectRecHits(ts, data, collector);
99 bool TkGluedMeasurementDet::recHits(SimpleHitContainer & result,
102 if unlikely((!theMonoDet->isActive(data)) && (!theStereoDet->isActive(data)))
return false;
103 auto oldSize = result.
size();
104 HitCollectorForSimpleHits collector( &fastGeomDet(), theMatcher, theCPE, stateOnThisDet, est, result);
105 collectRecHits(stateOnThisDet, data, collector);
107 return result.size()>oldSize;
117 TempMeasurements & result)
const {
119 if unlikely((!theMonoDet->isActive(data)) && (!theStereoDet->isActive(data))) {
121 result.add(theInactiveHit, 0.
F);
125 auto oldSize = result.size();
127 HitCollectorForFastMeasurements collector( &fastGeomDet(), theMatcher, theCPE, stateOnThisDet, est, result);
128 collectRecHits(stateOnThisDet, data, collector);
131 if (result.size()>oldSize)
return true;
134 const BoundPlane &gluedPlane = geomDet().surface();
136 stateOnThisDet.hasError() && (
138 (theMonoDet->isActive(data) &&
139 (theMonoDet->hasAllGoodChannels() ||
140 testStrips(stateOnThisDet,gluedPlane,*theMonoDet)
143 (theStereoDet->isActive(data) &&
144 (theStereoDet->hasAllGoodChannels() ||
145 testStrips(stateOnThisDet,gluedPlane,*theStereoDet)
150 result.add(theMissingHit, 0.
F);
153 result.add(theInactiveHit, 0.
F);
162 template<
typename Collector>
166 doubleMatch(ts,data,collector);
169 template<
typename Collector>
176 RecHitContainer monoHits = theMonoDet->recHits( ts, data );
183 if (monoHits.empty()) {
185 projectOnGluedDet( collector, theStereoDet->recHits(ts, data), glbDir);
188 std::vector<SiStripRecHit2D> simpleSteroHitsByValue;
189 theStereoDet->simpleRecHits(ts, data, simpleSteroHitsByValue);
191 if (simpleSteroHitsByValue.empty()) {
192 projectOnGluedDet( collector, monoHits, glbDir);
197 vsStereoHits.resize(simpleSteroHitsByValue.size());
201 for (RecHitContainer::const_iterator monoHit = monoHits.begin();
202 monoHit != monoHits.end(); ++monoHit) {
204 const SiStripRecHit2D* verySpecificMonoHit =
reinterpret_cast<const SiStripRecHit2D*
>(tkhit);
205 theMatcher->match( verySpecificMonoHit, vsStereoHits.begin(), vsStereoHits.end(),
206 collector.collector(), &specificGeomDet(), tkDir);
208 if (collector.hasNewMatchedHits()) {
209 collector.clearNewMatchedHitsFlag();
211 collector.addProjected( **monoHit, glbDir );
252 if(fm!=0&&fs!=0) ++matchF;
253 if(fm!=0||fs!=0) ++singleF;
257 printf(
"Matches:%d/%d/%d/%d/%d/%d : %f/%f/%f/%f/%f/%f/%f\n",
258 int(totCall),
int(matchF),
int(singleF-matchF),
int(matchT),
int(zeroM),
int(zeroS),
259 totMono/totCall,totStereo/totCall,totComb/totCall,totMatched/matchT,
260 filtMono/totCall,filtStereo/totCall,filtComb/matchF);
270 TkGluedMeasurementDet::RecHitContainer
271 TkGluedMeasurementDet::projectOnGluedDet(
const RecHitContainer& hits,
275 for (
auto const & hit : hits) {
277 auto && phit = std::make_shared<ProjectedSiStripRecHit2D> (vl.first,vl.second, fastGeomDet(),
static_cast<SiStripRecHit2D
const &
>(*hit));
278 result.push_back(std::move(phit));
283 template<
typename Collector>
285 TkGluedMeasurementDet::projectOnGluedDet( Collector& collector,
286 const RecHitContainer& hits,
289 for ( RecHitContainer::const_iterator ihit = hits.begin(); ihit!=hits.end(); ihit++) {
290 collector.addProjected( **ihit, gdir );
294 TkGluedMeasurementDet::RecHitContainer
295 TkGluedMeasurementDet::projectOnGluedDet( std::vector<SiStripRecHit2D>
const & hits,
299 for (
auto const & hit : hits) {
301 auto && phit = std::make_shared<ProjectedSiStripRecHit2D> (vl.first,vl.second,fastGeomDet(),
static_cast<SiStripRecHit2D
const &
>(hit));
302 result.push_back(std::move(phit));
307 template<
typename Collector>
309 TkGluedMeasurementDet::projectOnGluedDet( Collector& collector,
310 std::vector<SiStripRecHit2D>
const & hits,
313 for (
auto const & hit : hits)
314 collector.addProjected(hit, gdir );
322 const RecHitContainer& monoHits,
323 const RecHitContainer& stereoHits)
const
325 for (RecHitContainer::const_iterator
i=monoHits.begin();
i != monoHits.end(); ++
i) {
326 checkHitProjection( **
i, ts, fastGeomDet());
328 for (RecHitContainer::const_iterator
i=stereoHits.begin();
i != stereoHits.end(); ++
i) {
329 checkHitProjection( **
i, ts, fastGeomDet());
333 void TkGluedMeasurementDet::checkHitProjection(
const TrackingRecHit& hit,
338 ProjectedSiStripRecHit2D projectedHit(vl.first,vl.second, det, static_cast<SiStripRecHit2D const &>(hit));
343 if ((projectedHit.localPosition()-propState.
localPosition()).
mag() > 0.0001f) {
344 std::cout <<
"PROBLEM: projected and propagated hit positions differ by "
345 << (projectedHit.localPosition()-propState.
localPosition()).
mag() << std::endl;
348 LocalError le1 = projectedHit.localPositionError();
353 fabs(le1.
xy() - le2.
xy())/(cutoff+fabs(le1.
xy()))),
354 fabs(le1.
yy() - le2.
yy())/(cutoff+le1.
xx()));
356 std::cout <<
"PROBLEM: projected and propagated hit errors differ by "
357 << maxdiff << std::endl;
365 const TkStripMeasurementDet &mdet)
const {
367 const GeomDet &det = mdet.fastGeomDet();
389 if (stripPlane.normalVector().dot( gluedPlane.normalVector()) < 0) {
407 const StripTopology &topo = mdet.specificGeomDet().specificTopology();
410 return mdet.testStrips(utraj, uerr);
413 #include<boost/bind.hpp>
414 TkGluedMeasurementDet::HitCollectorForRecHits::HitCollectorForRecHits(
const GeomDet * geomDet,
416 RecHitContainer &
target) :
417 geomDet_(geomDet), matcher_(matcher), cpe_(cpe),target_(target),
418 collector_(boost::bind(&HitCollectorForRecHits::
add,boost::ref(*this),_1)),
423 TkGluedMeasurementDet::HitCollectorForSimpleHits::HitCollectorForSimpleHits(
429 SimpleHitContainer &
target) :
430 geomDet_(geomDet), matcher_(matcher), cpe_(cpe),stateOnThisDet_(stateOnThisDet), est_(est), target_(target),
431 collector_(boost::bind(&HitCollectorForSimpleHits::
add,boost::ref(*this),_1)),
438 TkGluedMeasurementDet::HitCollectorForRecHits::addProjected(
const TrackingRecHit& hit,
441 auto && vl = projectedPos(hit,*geomDet_, gdir, cpe_);
442 auto && phit = std::make_shared<ProjectedSiStripRecHit2D> (vl.first,vl.second,*geomDet_,
static_cast<SiStripRecHit2D
const &
>(hit));
443 target_.push_back(std::move(phit));
451 std::pair<bool,double> diffEst = est_.estimate( stateOnThisDet_, hit2d);
452 if (!diffEst.first)
return;
453 target_.emplace_back(
new SiStripMatchedRecHit2D(hit2d));
459 TkGluedMeasurementDet::HitCollectorForSimpleHits::addProjected(
const TrackingRecHit& hit,
463 auto && vl = projectedPos(hit,*geomDet_, gdir, cpe_);
464 std::unique_ptr<ProjectedSiStripRecHit2D> phit(
new ProjectedSiStripRecHit2D(vl.first,vl.second,*geomDet_, static_cast<SiStripRecHit2D const &>(hit)));
465 std::pair<bool,double> diffEst = est_.estimate( stateOnThisDet_, *phit);
466 if ( diffEst.first) {
467 target_.emplace_back(phit.release());
474 TkGluedMeasurementDet::HitCollectorForFastMeasurements::HitCollectorForFastMeasurements
479 TempMeasurements &
target) :
480 geomDet_(geomDet), matcher_(matcher), cpe_(cpe),stateOnThisDet_(stateOnThisDet), est_(est), target_(target),
481 collector_(boost::bind(&HitCollectorForFastMeasurements::
add,boost::ref(*this),_1)),
491 std::pair<bool,double> diffEst = est_.estimate( stateOnThisDet_, hit2d);
492 if (!diffEst.first)
return;
493 target_.add(std::move(hit2d.cloneSH()),diffEst.second);
516 TkGluedMeasurementDet::HitCollectorForFastMeasurements::addProjected(
const TrackingRecHit& hit,
520 auto && vl = projectedPos(hit,*geomDet_, gdir, cpe_);
521 auto && phit = std::make_shared<ProjectedSiStripRecHit2D> (vl.first,vl.second,*geomDet_,
static_cast<SiStripRecHit2D
const &
>(hit));
522 std::pair<bool,double> diffEst = est_.estimate( stateOnThisDet_, *phit);
523 if ( diffEst.first) {
524 target_.add(phit, diffEst.second);
531 #include "doubleMatch.icc"
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
LocalVector localDirection() const
LocalPoint localPosition() const
Global3DPoint GlobalPoint
GlobalPoint globalPosition() const
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
virtual GlobalPoint globalPosition() const
const Plane & surface() const
The nominal surface of the GeomDet.
LocalError positionError() const
static int position[TOTALCHAMBERS][3]
virtual MeasurementError measurementError(const LocalPoint &, const LocalError &) const =0
TrajectoryStateOnSurface propagate(const TrackingRecHit &hit, const Plane &plane, const TrajectoryStateOnSurface &ts) const
const T & max(const T &a, const T &b)
const GeomDet * det() const
GlobalVector momentum() const
virtual MeasurementPoint measurementPosition(const LocalPoint &) const =0
const LocalTrajectoryError & localError() const
const T * operator()(const T &val) const
virtual TrackingRecHit const * hit() const
unsigned long long uint64_t
const GlobalTrajectoryParameters & globalParameters() const
std::vector< const SiStripRecHit2D * > SimpleHitCollection
virtual LocalError localPositionError() const =0
return(e1-e2)*(e1-e2)+dp *dp
char data[epos_bytes_allocation]
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
volatile std::atomic< bool > shutdown_flag false
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
LocalError rotate(float x, float y) const
Return a new LocalError, rotated by an angle defined by the direction (x,y)
tuple size
Write out results.