16 using namespace reco ;
20 (
float phi1min,
float phi1max,
21 float phi2minB,
float phi2maxB,
float phi2minF,
float phi2maxF,
22 float z2minB,
float z2maxB,
float r2minF,
float r2maxF,
25 meas1stBLayer(phi1min,phi1max,0.,0.), meas2ndBLayer(phi2minB,phi2maxB,z2minB,z2maxB),
26 meas1stFLayer(phi1min,phi1max,0.,0.), meas2ndFLayer(phi2minF,phi2maxF,r2minF,r2maxF),
27 prop1stLayer(
nullptr), prop2ndLayer(
nullptr),theGeometricSearchTracker(
nullptr),theTrackerEvent(
nullptr),theTracker(
nullptr),vertex_(0.),
28 searchInTIDTEC_(searchInTIDTEC), useRecoVertex_(
false)
30 meas1stFLayer.setRRangeI(rMinI,rMaxI) ;
31 meas2ndFLayer.setRRangeI(rMinI,rMaxI) ;
42 meas1stBLayer.setPhiRange(dummyphi1min,dummyphi1max) ;
43 meas1stFLayer.setPhiRange(dummyphi1min,dummyphi1max) ;
48 meas1stBLayer.setZRange(zmin1,zmax1) ;
49 meas1stFLayer.setRRange(zmin1,zmax1) ;
54 meas2ndBLayer.setPhiRange(dummyphi2minB,dummyphi2maxB) ;
55 meas2ndFLayer.setPhiRange(dummyphi2minF,dummyphi2maxF) ;
59 { useRecoVertex_ =
val ; }
63 theTrackerEvent = & trackerData;
71 if (theMeasurementTracker)
73 theTracker = theMeasurementTracker;
74 theGeometricSearchTracker=theMeasurementTracker->geometricSearchTracker() ;
77 theMagField = magField ;
78 theTrackerGeometry = trackerGeometry ;
80 if (prop1stLayer)
delete prop1stLayer ;
82 if (prop2ndLayer)
delete prop2ndLayer ;
87 {
return pred1Meas ; }
90 {
return pred2Meas ; }
96 std::vector<SeedWithInfo>
98 (
const std::vector<const TrajectorySeedCollection *>& seedsV,
const GlobalPoint & xmeas,
101 typedef std::unordered_map<const GeomDet *, TrajectoryStateOnSurface> DetTsosAssoc;
106 auto xmeas_r = xmeas.
perp();
115 std::vector<SeedWithInfo>
result ;
116 unsigned int allSeedsSize = 0;
117 for (
auto const sc : seedsV) allSeedsSize +=
sc->size();
119 mapTsos2_fast_.clear();
120 mapTsos2_fast_.reserve(allSeedsSize) ;
125 auto ndets = theTrackerGeometry->dets().size();
128 for (
auto &
i : iTsos)
i=-1;
129 std::vector<TrajectoryStateOnSurface> vTsos; vTsos.reserve(allSeedsSize);
131 for (
const auto seeds : seedsV) {
132 for(
const auto&
seed : *seeds) {
134 if(
seed.nHits() > 9 ) {
135 edm::LogWarning(
"GsfElectronAlgo|UnexpectedSeed") <<
"We cannot deal with seeds having more than 9 hits." ;
142 for(
auto it = hits.first; it != hits.second; ++it ) {
143 hit_gp_map_.emplace_back(it->globalPosition());
147 auto he = hits.second -1;
148 for(
auto it1 = hits.first; it1 <
he; ++it1 ) {
149 if( !it1->isValid() )
continue;
151 const DetId id1 = it1->geographicalId();
152 const GeomDet *geomdet1 = it1->det();
162 auto dt = hit1Pos.
x()*xmeas.
x()+hit1Pos.
y()*xmeas.
y();
164 if (
dt<phicut*(xmeas_r*hit1Pos.
perp()))
continue;
167 iTsos[ix1] = vTsos.size();
168 vTsos.push_back(prop1stLayer->propagate(tsos,geomdet1->
surface()));
170 auto tsos1 = &vTsos[iTsos[ix1]];
172 if( !tsos1->isValid() )
continue;
173 std::pair<bool, double> est = ( id1.
subdetId() % 2 ?
174 meas1stBLayer.estimate(vprim, *tsos1, hit1Pos) :
175 meas1stFLayer.estimate(vprim, *tsos1, hit1Pos) );
176 if( !est.first )
continue;
177 EleRelPointPair pp1(hit1Pos,tsos1->globalParameters().position(),vprim);
178 const math::XYZPoint relHit1Pos(hit1Pos-vprim), relTSOSPos(tsos1->globalParameters().position() - vprim);
180 const float dRz1 = ( id1.
subdetId()%2 ? pp1.dZ() : pp1.dPerp() );
181 const float dPhi1 = pp1.dPhi();
184 if (!useRecoVertex_) {
187 const double pxHit1z = hit1Pos.
z();
188 const double pxHit1x = hit1Pos.
x();
189 const double pxHit1y = hit1Pos.
y();
190 const double r1diff =
std::sqrt( (pxHit1x-vprim.
x())*(pxHit1x-vprim.
x()) +
191 (pxHit1y-vprim.
y())*(pxHit1y-vprim.
y()) );
192 const double r2diff =
std::sqrt( (xmeas.
x()-pxHit1x)*(xmeas.
x()-pxHit1x) +
193 (xmeas.
y()-pxHit1y)*(xmeas.
y()-pxHit1y) );
194 zVertex = pxHit1z - r1diff*(xmeas.
z()-pxHit1z)/r2diff;
202 for(
auto it2 = it1+1; it2 != hits.second; ++it2 ) {
203 if( !it2->isValid() )
continue;
205 const DetId id2 = it2->geographicalId();
206 const GeomDet *geomdet2 = it2->det();
207 const std::pair<const GeomDet *,GlobalPoint> det_key(geomdet2,hit1Pos);
209 auto tsos2_itr = mapTsos2_fast_.find(det_key);
210 if( tsos2_itr != mapTsos2_fast_.end() ) {
211 tsos2 = &(tsos2_itr->second);
214 mapTsos2_fast_.emplace(det_key,prop2ndLayer->propagate(fts2,geomdet2->
surface()));
215 tsos2 = &(empl_result.first->second);
217 if( !tsos2->
isValid() )
continue;
219 std::pair<bool,double> est2 = ( id2.
subdetId()%2 ?
220 meas2ndBLayer.estimate(vertex, *tsos2,hit2Pos) :
221 meas2ndFLayer.estimate(vertex, *tsos2,hit2Pos) );
225 const float dRz2 = (subDet2%2==1)?pp2.dZ():pp2.dPerp();
226 const float dPhi2 = pp2.dPhi();
227 const unsigned char hitsMask = (1<<idx1)|(1<<idx2);
228 result.push_back(
SeedWithInfo(
seed,hitsMask,subDet2,dRz2,dPhi2,subDet1,dRz1,dPhi1)) ;
234 mapTsos2_fast_.clear() ;
241 vector< pair< RecHitWithDist, PixelHitMatcher::ConstRecHitPointer > >
245 float energy,
float fcharge,
249 float SCl_phi = xmeas.
phi();
253 vector<pair<RecHitWithDist, ConstRecHitPointer> >
result;
254 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] entering .. ";
256 vector<TrajectoryMeasurement> validMeasurements;
257 vector<TrajectoryMeasurement> invalidMeasurements;
259 typedef vector<TrajectoryMeasurement>::const_iterator aMeas;
264 auto firstLayer = theGeometricSearchTracker->pixelBarrelLayers().begin();
272 vector<TrajectoryMeasurement> pixelMeasurements =
273 theLayerMeasurements.measurements(**firstLayer,tsos,
274 *prop1stLayer, meas1stBLayer);
276 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] nbr of hits compatible with extrapolation to first layer: " << pixelMeasurements.size();
277 for (aMeas
m=pixelMeasurements.begin();
m!=pixelMeasurements.end();
m++){
278 if (
m->recHit()->isValid()) {
279 float localDphi =
normalizedPhi(SCl_phi-
m->forwardPredictedState().globalPosition().barePhi()) ;
280 if(
std::abs(localDphi)>2.5)
continue;
281 CLHEP::Hep3Vector prediction(
m->forwardPredictedState().globalPosition().x(),
282 m->forwardPredictedState().globalPosition().y(),
283 m->forwardPredictedState().globalPosition().z());
284 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] compatible hit position " <<
m->recHit()->globalPosition();
285 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] predicted position " <<
m->forwardPredictedState().globalPosition();
286 pred1Meas.push_back( prediction);
288 validMeasurements.push_back(*
m);
290 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] Found a rechit in layer ";
295 else LogDebug(
"") <<
"Could not downcast!!";
303 vector<TrajectoryMeasurement> pixel2Measurements =
304 theLayerMeasurements.measurements(**firstLayer,tsos,
305 *prop1stLayer, meas1stBLayer);
307 for (aMeas
m=pixel2Measurements.begin();
m!=pixel2Measurements.end();
m++){
308 if (
m->recHit()->isValid()) {
309 float localDphi =
normalizedPhi(SCl_phi-
m->forwardPredictedState().globalPosition().barePhi()) ;
310 if(
std::abs(localDphi)>2.5)
continue;
311 CLHEP::Hep3Vector prediction(
m->forwardPredictedState().globalPosition().x(),
312 m->forwardPredictedState().globalPosition().y(),
313 m->forwardPredictedState().globalPosition().z());
314 pred1Meas.push_back( prediction);
315 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] compatible hit position " <<
m->recHit()->globalPosition() << endl;
316 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] predicted position " <<
m->forwardPredictedState().globalPosition() << endl;
318 validMeasurements.push_back(*
m);
319 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] Found a rechit in layer ";
324 else LogDebug(
"") <<
"Could not downcast!!";
336 for (
int i=0;
i<2;
i++) {
337 auto flayer =
i == 0 ? theGeometricSearchTracker->posPixelForwardLayers().begin()
338 : theGeometricSearchTracker->negPixelForwardLayers().begin();
340 if (
i==0 && xmeas.
z() < -100. )
continue;
341 if (
i==1 && xmeas.
z() > 100. )
continue;
343 vector<TrajectoryMeasurement> pixelMeasurements =
344 theLayerMeasurements.measurements(**flayer, tsosfwd,
345 *prop1stLayer, meas1stFLayer);
347 for (aMeas
m=pixelMeasurements.begin();
m!=pixelMeasurements.end();
m++){
348 if (
m->recHit()->isValid()) {
349 float localDphi =
normalizedPhi(SCl_phi-
m->forwardPredictedState().globalPosition().barePhi());
350 if(
std::abs(localDphi)>2.5)
continue;
351 CLHEP::Hep3Vector prediction(
m->forwardPredictedState().globalPosition().x(),
352 m->forwardPredictedState().globalPosition().y(),
353 m->forwardPredictedState().globalPosition().z());
354 pred1Meas.push_back( prediction);
356 validMeasurements.push_back(*
m);
361 if (searchInTIDTEC_) {
364 vector<TrajectoryMeasurement> pixel2Measurements =
365 theLayerMeasurements.measurements(**flayer, tsosfwd,
366 *prop1stLayer, meas1stFLayer);
368 for (aMeas
m=pixel2Measurements.begin();
m!=pixel2Measurements.end();
m++){
369 if (
m->recHit()->isValid()) {
370 float localDphi =
normalizedPhi(SCl_phi-
m->forwardPredictedState().globalPosition().barePhi()) ;
371 if(
std::abs(localDphi)>2.5)
continue;
372 CLHEP::Hep3Vector prediction(
m->forwardPredictedState().globalPosition().x(),
373 m->forwardPredictedState().globalPosition().y(),
374 m->forwardPredictedState().globalPosition().z());
375 pred1Meas.push_back( prediction);
377 validMeasurements.push_back(*
m);
386 for (
unsigned i=0;
i<validMeasurements.size();
i++){
388 const DetLayer * newLayer = theGeometricSearchTracker->detLayer(validMeasurements[
i].
recHit()->det()->geographicalId());
395 double pxHit1z = validMeasurements[
i].recHit()->det()->surface().toGlobal(
396 validMeasurements[
i].
recHit()->localPosition()).z();
397 double pxHit1x = validMeasurements[
i].recHit()->det()->surface().toGlobal(
398 validMeasurements[
i].
recHit()->localPosition()).x();
399 double pxHit1y = validMeasurements[
i].recHit()->det()->surface().toGlobal(
400 validMeasurements[
i].
recHit()->localPosition()).y();
401 double r1diff = (pxHit1x-vprim.
x())*(pxHit1x-vprim.
x()) + (pxHit1y-vprim.
y())*(pxHit1y-vprim.
y());
403 double r2diff = (xmeas.
x()-pxHit1x)*(xmeas.
x()-pxHit1x) + (xmeas.
y()-pxHit1y)*(xmeas.
y()-pxHit1y);
405 zVertex = pxHit1z - r1diff*(xmeas.
z()-pxHit1z)/r2diff;
417 GlobalPoint hitPos( validMeasurements[
i].
recHit()->det()->surface().toGlobal( validMeasurements[
i].
recHit()->localPosition() ) ) ;
422 prop2ndLayer, &meas2ndBLayer,&meas2ndFLayer,
423 tTopo,navigationSchool,searchInTIDTEC_);
426 for (
unsigned it = 0; it < predictions.size(); it++) pred2Meas.push_back(predictions[it]);
444 pair<RecHitWithDist,ConstRecHitPointer> compatiblePair = pair<RecHitWithDist,ConstRecHitPointer>(rh,pxrh) ;
445 result.push_back(compatiblePair);
static FreeTrajectoryState get(MagneticField const &magField, GlobalPoint const &xmeas, GlobalPoint const &xvert, float momentum, TrackCharge charge)
void setEvent(const MeasurementTrackerEvent &event)
constexpr T normalizedPhi(T phi)
void setES(const MagneticField *, const MeasurementTracker *theMeasurementTracker, const TrackerGeometry *trackerGeometry)
Geom::Phi< T > phi() const
std::vector< CLHEP::Hep3Vector > predictionInNextLayers() const
virtual const BoundCylinder & specificSurface() const final
Extension of the interface.
const Plane & surface() const
The nominal surface of the GeomDet.
TransientTrackingRecHit::ConstRecHitPointer ConstRecHitPointer
void set2ndLayer(float dummyphi2minB, float dummyphi2maxB, float dummyphi2minF, float dummyphi2maxF)
void set1stLayerZRange(float zmin1, float zmax1)
PixelHitMatcher(float phi1min, float phi1max, float phi2minB, float phi2maxB, float phi2minF, float phi2maxF, float z2minB, float z2maxB, float r2minF, float r2maxF, float rMinI, float rMaxI, bool searchInTIDTEC)
rMaxI
intermediate region SC in EB and 2nd hits in PXF
Cos< T >::type cos(const T &t)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
Abs< T >::type abs(const T &t)
std::pair< const_iterator, const_iterator > range
std::vector< CLHEP::Hep3Vector > predicted1Hits()
std::vector< SeedWithInfo > compatibleSeeds(const std::vector< const TrajectorySeedCollection * > &seedsV, const GlobalPoint &xmeas, const GlobalPoint &vprim, float energy, float charge)
GlobalVector momentum() const
GlobalPoint position() const
GlobalPoint position() const
std::vector< TrajectoryMeasurement > measurementsInNextLayers() const
const GlobalTrajectoryParameters & globalParameters() const
void set1stLayer(float dummyphi1min, float dummyphi1max)
XYZPointD XYZPoint
point in space with cartesian internal representation
virtual ~PixelHitMatcher()
std::vector< CLHEP::Hep3Vector > predicted2Hits()
std::vector< std::pair< RecHitWithDist, ConstRecHitPointer > > compatibleHits(const GlobalPoint &xmeas, const GlobalPoint &vprim, float energy, float charge, const TrackerTopology *tTopo, const NavigationSchool &navigationSchool)
void setUseRecoVertex(bool val)