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),
28 prop1stLayer(
nullptr), prop2ndLayer(
nullptr),theGeometricSearchTracker(
nullptr),theTrackerEvent(
nullptr),theTracker(
nullptr),vertex_(0.),
29 searchInTIDTEC_(searchInTIDTEC), useRecoVertex_(
false)
31 meas1stFLayer.setRRangeI(rMinI,rMaxI) ;
32 meas2ndFLayer.setRRangeI(rMinI,rMaxI) ;
43 meas1stBLayer.setPhiRange(dummyphi1min,dummyphi1max) ;
44 meas1stFLayer.setPhiRange(dummyphi1min,dummyphi1max) ;
49 meas1stBLayer.setZRange(zmin1,zmax1) ;
50 meas1stFLayer.setRRange(zmin1,zmax1) ;
55 meas2ndBLayer.setPhiRange(dummyphi2minB,dummyphi2maxB) ;
56 meas2ndFLayer.setPhiRange(dummyphi2minF,dummyphi2maxF) ;
60 { useRecoVertex_ =
val ; }
64 theTrackerEvent = & trackerData;
72 if (theMeasurementTracker)
74 theTracker = theMeasurementTracker;
75 theGeometricSearchTracker=theMeasurementTracker->geometricSearchTracker() ;
76 startLayers.setup(theGeometricSearchTracker) ;
79 theMagField = magField ;
80 theTrackerGeometry = trackerGeometry ;
82 if (prop1stLayer)
delete prop1stLayer ;
84 if (prop2ndLayer)
delete prop2ndLayer ;
89 {
return pred1Meas ; }
92 {
return pred2Meas ; }
98 std::vector<SeedWithInfo>
100 (
const std::vector<const TrajectorySeedCollection *>& seedsV,
const GlobalPoint & xmeas,
101 const GlobalPoint & vprim,
float energy,
float fcharge )
103 typedef std::unordered_map<const GeomDet *, TrajectoryStateOnSurface> DetTsosAssoc;
108 auto xmeas_r = xmeas.
perp();
117 std::vector<SeedWithInfo>
result ;
118 unsigned int allSeedsSize = 0;
119 for (
auto const sc : seedsV) allSeedsSize +=
sc->size();
121 mapTsos2_fast_.clear();
122 mapTsos2_fast_.reserve(allSeedsSize) ;
127 auto ndets = theTrackerGeometry->dets().size();
130 for (
auto &
i : iTsos)
i=-1;
131 std::vector<TrajectoryStateOnSurface> vTsos; vTsos.reserve(allSeedsSize);
133 for (
const auto seeds : seedsV) {
134 for(
const auto&
seed : *seeds) {
136 if(
seed.nHits() > 9 ) {
137 edm::LogWarning(
"GsfElectronAlgo|UnexpectedSeed") <<
"We cannot deal with seeds having more than 9 hits." ;
144 for(
auto it = hits.first; it != hits.second; ++it ) {
145 hit_gp_map_.emplace_back(it->globalPosition());
149 auto he = hits.second -1;
150 for(
auto it1 = hits.first; it1 <
he; ++it1 ) {
151 if( !it1->isValid() )
continue;
153 const DetId id1 = it1->geographicalId();
154 const GeomDet *geomdet1 = it1->det();
164 auto dt = hit1Pos.
x()*xmeas.
x()+hit1Pos.
y()*xmeas.
y();
166 if (
dt<phicut*(xmeas_r*hit1Pos.
perp()))
continue;
169 iTsos[ix1] = vTsos.size();
170 vTsos.push_back(prop1stLayer->propagate(tsos,geomdet1->
surface()));
172 auto tsos1 = &vTsos[iTsos[ix1]];
174 if( !tsos1->isValid() )
continue;
175 std::pair<bool, double> est = ( id1.
subdetId() % 2 ?
176 meas1stBLayer.estimate(vprim, *tsos1, hit1Pos) :
177 meas1stFLayer.estimate(vprim, *tsos1, hit1Pos) );
178 if( !est.first )
continue;
179 EleRelPointPair pp1(hit1Pos,tsos1->globalParameters().position(),vprim);
180 const math::XYZPoint relHit1Pos(hit1Pos-vprim), relTSOSPos(tsos1->globalParameters().position() - vprim);
182 const float dRz1 = ( id1.
subdetId()%2 ? pp1.dZ() : pp1.dPerp() );
183 const float dPhi1 = pp1.dPhi();
186 if (!useRecoVertex_) {
189 const double pxHit1z = hit1Pos.
z();
190 const double pxHit1x = hit1Pos.
x();
191 const double pxHit1y = hit1Pos.
y();
192 const double r1diff =
std::sqrt( (pxHit1x-vprim.
x())*(pxHit1x-vprim.
x()) +
193 (pxHit1y-vprim.
y())*(pxHit1y-vprim.
y()) );
194 const double r2diff =
std::sqrt( (xmeas.
x()-pxHit1x)*(xmeas.
x()-pxHit1x) +
195 (xmeas.
y()-pxHit1y)*(xmeas.
y()-pxHit1y) );
196 zVertex = pxHit1z - r1diff*(xmeas.
z()-pxHit1z)/r2diff;
204 for(
auto it2 = it1+1; it2 != hits.second; ++it2 ) {
205 if( !it2->isValid() )
continue;
207 const DetId id2 = it2->geographicalId();
208 const GeomDet *geomdet2 = it2->det();
209 const std::pair<const GeomDet *,GlobalPoint> det_key(geomdet2,hit1Pos);
211 auto tsos2_itr = mapTsos2_fast_.find(det_key);
212 if( tsos2_itr != mapTsos2_fast_.end() ) {
213 tsos2 = &(tsos2_itr->second);
216 mapTsos2_fast_.emplace(det_key,prop2ndLayer->propagate(fts2,geomdet2->
surface()));
217 tsos2 = &(empl_result.first->second);
219 if( !tsos2->
isValid() )
continue;
221 std::pair<bool,double> est2 = ( id2.
subdetId()%2 ?
222 meas2ndBLayer.estimate(vertex, *tsos2,hit2Pos) :
223 meas2ndFLayer.estimate(vertex, *tsos2,hit2Pos) );
227 const float dRz2 = (subDet2%2==1)?pp2.dZ():pp2.dPerp();
228 const float dPhi2 = pp2.dPhi();
229 const unsigned char hitsMask = (1<<idx1)|(1<<idx2);
230 result.push_back(
SeedWithInfo(
seed,hitsMask,subDet2,dRz2,dPhi2,subDet1,dRz1,dPhi1)) ;
236 mapTsos2_fast_.clear() ;
243 vector< pair< RecHitWithDist, PixelHitMatcher::ConstRecHitPointer > >
247 float energy,
float fcharge,
251 float SCl_phi = xmeas.
phi();
255 vector<pair<RecHitWithDist, ConstRecHitPointer> >
result;
256 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] entering .. ";
258 vector<TrajectoryMeasurement> validMeasurements;
259 vector<TrajectoryMeasurement> invalidMeasurements;
261 typedef vector<TrajectoryMeasurement>::const_iterator aMeas;
266 typedef vector<const BarrelDetLayer*>::const_iterator BarrelLayerIterator;
267 BarrelLayerIterator firstLayer = startLayers.firstBLayer();
275 vector<TrajectoryMeasurement> pixelMeasurements =
276 theLayerMeasurements.measurements(**firstLayer,tsos,
277 *prop1stLayer, meas1stBLayer);
279 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] nbr of hits compatible with extrapolation to first layer: " << pixelMeasurements.size();
280 for (aMeas
m=pixelMeasurements.begin();
m!=pixelMeasurements.end();
m++){
281 if (
m->recHit()->isValid()) {
282 float localDphi =
normalized_phi(SCl_phi-
m->forwardPredictedState().globalPosition().barePhi()) ;
283 if(
std::abs(localDphi)>2.5)
continue;
284 CLHEP::Hep3Vector prediction(
m->forwardPredictedState().globalPosition().x(),
285 m->forwardPredictedState().globalPosition().y(),
286 m->forwardPredictedState().globalPosition().z());
287 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] compatible hit position " <<
m->recHit()->globalPosition();
288 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] predicted position " <<
m->forwardPredictedState().globalPosition();
289 pred1Meas.push_back( prediction);
291 validMeasurements.push_back(*
m);
293 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] Found a rechit in layer ";
298 else LogDebug(
"") <<
"Could not downcast!!";
306 vector<TrajectoryMeasurement> pixel2Measurements =
307 theLayerMeasurements.measurements(**firstLayer,tsos,
308 *prop1stLayer, meas1stBLayer);
310 for (aMeas
m=pixel2Measurements.begin();
m!=pixel2Measurements.end();
m++){
311 if (
m->recHit()->isValid()) {
312 float localDphi =
normalized_phi(SCl_phi-
m->forwardPredictedState().globalPosition().barePhi()) ;
313 if(
std::abs(localDphi)>2.5)
continue;
314 CLHEP::Hep3Vector prediction(
m->forwardPredictedState().globalPosition().x(),
315 m->forwardPredictedState().globalPosition().y(),
316 m->forwardPredictedState().globalPosition().z());
317 pred1Meas.push_back( prediction);
318 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] compatible hit position " <<
m->recHit()->globalPosition() << endl;
319 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] predicted position " <<
m->forwardPredictedState().globalPosition() << endl;
321 validMeasurements.push_back(*
m);
322 LogDebug(
"") <<
"[PixelHitMatcher::compatibleHits] Found a rechit in layer ";
327 else LogDebug(
"") <<
"Could not downcast!!";
335 typedef vector<const ForwardDetLayer*>::const_iterator ForwardLayerIterator;
336 ForwardLayerIterator flayer;
341 for (
int i=0;
i<2;
i++) {
342 i == 0 ? flayer = startLayers.pos1stFLayer() : flayer = startLayers.neg1stFLayer();
344 if (
i==0 && xmeas.
z() < -100. )
continue;
345 if (
i==1 && xmeas.
z() > 100. )
continue;
347 vector<TrajectoryMeasurement> pixelMeasurements =
348 theLayerMeasurements.measurements(**flayer, tsosfwd,
349 *prop1stLayer, meas1stFLayer);
351 for (aMeas
m=pixelMeasurements.begin();
m!=pixelMeasurements.end();
m++){
352 if (
m->recHit()->isValid()) {
353 float localDphi =
normalized_phi(SCl_phi-
m->forwardPredictedState().globalPosition().barePhi());
354 if(
std::abs(localDphi)>2.5)
continue;
355 CLHEP::Hep3Vector prediction(
m->forwardPredictedState().globalPosition().x(),
356 m->forwardPredictedState().globalPosition().y(),
357 m->forwardPredictedState().globalPosition().z());
358 pred1Meas.push_back( prediction);
360 validMeasurements.push_back(*
m);
365 if (searchInTIDTEC_) {
368 vector<TrajectoryMeasurement> pixel2Measurements =
369 theLayerMeasurements.measurements(**flayer, tsosfwd,
370 *prop1stLayer, meas1stFLayer);
372 for (aMeas
m=pixel2Measurements.begin();
m!=pixel2Measurements.end();
m++){
373 if (
m->recHit()->isValid()) {
374 float localDphi =
normalized_phi(SCl_phi-
m->forwardPredictedState().globalPosition().barePhi()) ;
375 if(
std::abs(localDphi)>2.5)
continue;
376 CLHEP::Hep3Vector prediction(
m->forwardPredictedState().globalPosition().x(),
377 m->forwardPredictedState().globalPosition().y(),
378 m->forwardPredictedState().globalPosition().z());
379 pred1Meas.push_back( prediction);
381 validMeasurements.push_back(*
m);
390 for (
unsigned i=0;
i<validMeasurements.size();
i++){
392 const DetLayer * newLayer = theGeometricSearchTracker->detLayer(validMeasurements[
i].
recHit()->det()->geographicalId());
399 double pxHit1z = validMeasurements[
i].recHit()->det()->surface().toGlobal(
400 validMeasurements[
i].
recHit()->localPosition()).z();
401 double pxHit1x = validMeasurements[
i].recHit()->det()->surface().toGlobal(
402 validMeasurements[
i].
recHit()->localPosition()).x();
403 double pxHit1y = validMeasurements[
i].recHit()->det()->surface().toGlobal(
404 validMeasurements[
i].
recHit()->localPosition()).y();
405 double r1diff = (pxHit1x-vprim.
x())*(pxHit1x-vprim.
x()) + (pxHit1y-vprim.
y())*(pxHit1y-vprim.
y());
407 double r2diff = (xmeas.
x()-pxHit1x)*(xmeas.
x()-pxHit1x) + (xmeas.
y()-pxHit1y)*(xmeas.
y()-pxHit1y);
409 zVertex = pxHit1z - r1diff*(xmeas.
z()-pxHit1z)/r2diff;
421 GlobalPoint hitPos( validMeasurements[
i].
recHit()->det()->surface().toGlobal( validMeasurements[
i].
recHit()->localPosition() ) ) ;
426 prop2ndLayer, &meas2ndBLayer,&meas2ndFLayer,
427 tTopo,navigationSchool,searchInTIDTEC_);
430 for (
unsigned it = 0; it < predictions.size(); it++) pred2Meas.push_back(predictions[it]);
448 pair<RecHitWithDist,ConstRecHitPointer> compatiblePair = pair<RecHitWithDist,ConstRecHitPointer>(rh,pxrh) ;
449 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)
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)
RealType normalized_phi(RealType phi)
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)