Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue work on electron seeding convergence #29815

Merged
merged 1 commit into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ class ElectronSeedGenerator {
const float phiMax2B_;
const float phiMax2F_;

PixelHitMatcher electronMatcher_;
PixelHitMatcher positronMatcher_;
PixelHitMatcher matcher_;
};

#endif // ElectronSeedGenerator_H
11 changes: 4 additions & 7 deletions RecoEgamma/EgammaElectronAlgos/interface/PixelHitMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,8 @@ class PixelHitMatcher {
float phi2maxB,
float phi2minF,
float phi2maxF,
float z2minB,
float z2maxB,
float r2minF,
float r2maxF,
float rMinI,
float rMaxI,
bool useRecoVertex);

Expand All @@ -71,7 +68,7 @@ class PixelHitMatcher {

private:
struct BarrelMeasurementEstimator {
bool operator()(const GlobalPoint& vprim, const TrajectoryStateOnSurface& ts, const GlobalPoint& gp) const;
bool operator()(const GlobalPoint& vprim, const TrajectoryStateOnSurface&, const GlobalPoint&, int charge) const;

float thePhiMin;
float thePhiMax;
Expand All @@ -80,7 +77,7 @@ class PixelHitMatcher {
};

struct ForwardMeasurementEstimator {
bool operator()(const GlobalPoint& vprim, const TrajectoryStateOnSurface& ts, const GlobalPoint& gp) const;
bool operator()(const GlobalPoint& vprim, const TrajectoryStateOnSurface&, const GlobalPoint&, int charge) const;

float thePhiMin;
float thePhiMax;
Expand All @@ -94,8 +91,8 @@ class PixelHitMatcher {
BarrelMeasurementEstimator meas2ndBLayer;
ForwardMeasurementEstimator meas1stFLayer;
ForwardMeasurementEstimator meas2ndFLayer;
std::unique_ptr<PropagatorWithMaterial> prop1stLayer;
std::unique_ptr<PropagatorWithMaterial> prop2ndLayer;
std::unique_ptr<PropagatorWithMaterial> prop1stLayer = nullptr;
std::unique_ptr<PropagatorWithMaterial> prop2ndLayer = nullptr;
const MagneticField* theMagField;
const TrackerGeometry* theTrackerGeometry;
const bool useRecoVertex_;
Expand Down
83 changes: 27 additions & 56 deletions RecoEgamma/EgammaElectronAlgos/interface/TrajSeedMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"

#include "DataFormats/Math/interface/Point3D.h"
#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
#include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
#include "DataFormats/DetId/interface/DetId.h"
Expand All @@ -37,6 +38,7 @@

#include "RecoTracker/Record/interface/NavigationSchoolRecord.h"
#include "TrackingTools/RecoGeometry/interface/RecoGeometryRecord.h"
#include "TrackingTools/TrajectoryState/interface/ftsFromVertexToPoint.h"

namespace edm {
class ConsumesCollector;
Expand Down Expand Up @@ -65,42 +67,17 @@ class TrajSeedMatcher {
};

struct MatchInfo {
public:
DetId detId;
float dRZPos, dRZNeg;
float dPhiPos, dPhiNeg;

MatchInfo(const DetId& iDetId, float iDRZPos, float iDRZNeg, float iDPhiPos, float iDPhiNeg)
: detId(iDetId), dRZPos(iDRZPos), dRZNeg(iDRZNeg), dPhiPos(iDPhiPos), dPhiNeg(iDPhiNeg) {}
const DetId detId;
const float dRZPos;
const float dRZNeg;
const float dPhiPos;
const float dPhiNeg;
};

class SeedWithInfo {
public:
SeedWithInfo(const TrajectorySeed& seed,
const std::vector<SCHitMatch>& posCharge,
const std::vector<SCHitMatch>& negCharge,
int nrValidLayers);
~SeedWithInfo() = default;

const TrajectorySeed& seed() const { return seed_; }
float dRZPos(size_t hitNr) const { return getVal(hitNr, &MatchInfo::dRZPos); }
float dRZNeg(size_t hitNr) const { return getVal(hitNr, &MatchInfo::dRZNeg); }
float dPhiPos(size_t hitNr) const { return getVal(hitNr, &MatchInfo::dPhiPos); }
float dPhiNeg(size_t hitNr) const { return getVal(hitNr, &MatchInfo::dPhiNeg); }
DetId detId(size_t hitNr) const { return hitNr < matchInfo_.size() ? matchInfo_[hitNr].detId : DetId(0); }
size_t nrMatchedHits() const { return matchInfo_.size(); }
const std::vector<MatchInfo>& matches() const { return matchInfo_; }
int nrValidLayers() const { return nrValidLayers_; }

private:
float getVal(size_t hitNr, float MatchInfo::*val) const {
return hitNr < matchInfo_.size() ? matchInfo_[hitNr].*val : std::numeric_limits<float>::max();
}

private:
const TrajectorySeed& seed_;
std::vector<MatchInfo> matchInfo_;
int nrValidLayers_;
struct SeedWithInfo {
const TrajectorySeed& seed;
const std::vector<MatchInfo> matchInfos;
const int nrValidLayers;
};

class MatchingCuts {
Expand Down Expand Up @@ -168,22 +145,20 @@ class TrajSeedMatcher {
const std::vector<std::unique_ptr<MatchingCuts> > matchingCuts;
};

explicit TrajSeedMatcher(Configuration const& cfg,
explicit TrajSeedMatcher(TrajectorySeedCollection const& seeds,
math::XYZPoint const& vprim,
Configuration const& cfg,
edm::EventSetup const& iSetup,
MeasurementTrackerEvent const& measTkEvt);
~TrajSeedMatcher() = default;

static edm::ParameterSetDescription makePSetDescription();

std::vector<TrajSeedMatcher::SeedWithInfo> operator()(const TrajectorySeedCollection& seeds,
const GlobalPoint& candPos,
const GlobalPoint& vprim,
const float energy);
std::vector<TrajSeedMatcher::SeedWithInfo> operator()(const GlobalPoint& candPos, const float energy);

private:
std::vector<SCHitMatch> processSeed(const TrajectorySeed& seed,
const GlobalPoint& candPos,
const GlobalPoint& vprim,
const float energy,
const TrajectoryStateOnSurface& initialTrajState);

Expand All @@ -200,20 +175,11 @@ class TrajSeedMatcher {
const GlobalPoint& point,
const PropagatorWithMaterial& propagator);

TrajectoryStateOnSurface makeTrajStateOnSurface(const GlobalPoint& pos,
const GlobalPoint& vtx,
const float energy,
const int charge) const;
TrajectoryStateOnSurface makeTrajStateOnSurface(const GlobalPoint& pos, const float energy, const int charge) const;
void clearCache();

bool passesMatchSel(const SCHitMatch& hit, const size_t hitNr) const;

int getNrValidLayersAlongTraj(const SCHitMatch& hit1,
const SCHitMatch& hit2,
const GlobalPoint& candPos,
const GlobalPoint& vprim,
const float energy,
const int charge);
int getNrValidLayersAlongTraj(
const SCHitMatch& hit1, const SCHitMatch& hit2, const GlobalPoint& candPos, const float energy, const int charge);

int getNrValidLayersAlongTraj(const DetId& hitId, const TrajectoryStateOnSurface& hitTrajState) const;

Expand All @@ -223,15 +189,20 @@ class TrajSeedMatcher {

size_t getNrHitsRequired(const int nrValidLayers) const;

//parameterised b-fields may not be valid for entire detector, just tracker volume
//however need we ecal so we auto select based on the position
const MagneticField& getMagField(const GlobalPoint& point) const {
return cfg_.useParamMagFieldIfDefined && magFieldParam_.isDefined(point) ? magFieldParam_ : magField_;
inline auto ftsFromVertexToPoint(GlobalPoint const& point, GlobalPoint const& vertex, float energy, int charge) const {
//parameterised b-fields may not be valid for entire detector, just tracker volume
//however need we ecal so we auto select based on the position
bool useMagFieldParam = cfg_.useParamMagFieldIfDefined && magFieldParam_.isDefined(point);
auto const& magneticField = useMagFieldParam ? magFieldParam_ : magField_;
return trackingTools::ftsFromVertexToPoint(magneticField, point, vertex, energy, charge);
}

private:
static constexpr float kElectronMass_ = 0.000511;

TrajectorySeedCollection const& seeds_;
const GlobalPoint vprim_;

Configuration const& cfg_;

MagneticField const& magField_;
Expand Down
69 changes: 19 additions & 50 deletions RecoEgamma/EgammaElectronAlgos/src/ElectronSeedGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,32 +152,16 @@ ElectronSeedGenerator::ElectronSeedGenerator(const edm::ParameterSet &pset, cons
phiMin2F_(-pset.getParameter<double>("PhiMax2F")),
phiMax2B_(pset.getParameter<double>("PhiMax2B")),
phiMax2F_(pset.getParameter<double>("PhiMax2F")),
electronMatcher_(pset.getParameter<double>("ePhiMin1"),
pset.getParameter<double>("ePhiMax1"),
phiMin2B_,
phiMax2B_,
phiMin2F_,
phiMax2F_,
-pset.getParameter<double>("z2MaxB"),
pset.getParameter<double>("z2MaxB"),
-pset.getParameter<double>("r2MaxF"),
pset.getParameter<double>("r2MaxF"),
-pset.getParameter<double>("rMaxI"),
pset.getParameter<double>("rMaxI"),
useRecoVertex_),
positronMatcher_(pset.getParameter<double>("pPhiMin1"),
pset.getParameter<double>("pPhiMax1"),
phiMin2B_,
phiMax2B_,
phiMin2F_,
phiMax2F_,
-pset.getParameter<double>("z2MaxB"),
pset.getParameter<double>("z2MaxB"),
-pset.getParameter<double>("r2MaxF"),
pset.getParameter<double>("r2MaxF"),
-pset.getParameter<double>("rMaxI"),
pset.getParameter<double>("rMaxI"),
useRecoVertex_) {}
matcher_(pset.getParameter<double>("ePhiMin1"),
pset.getParameter<double>("ePhiMax1"),
phiMin2B_,
phiMax2B_,
phiMin2F_,
phiMax2F_,
pset.getParameter<double>("z2MaxB"),
pset.getParameter<double>("r2MaxF"),
pset.getParameter<double>("rMaxI"),
useRecoVertex_) {}

void ElectronSeedGenerator::setupES(const edm::EventSetup &setup) {
// get records if necessary (called once per event)
Expand All @@ -197,8 +181,7 @@ void ElectronSeedGenerator::setupES(const edm::EventSetup &setup) {
}

if (tochange) {
electronMatcher_.setES(magField_.product(), trackerGeometry_.product());
positronMatcher_.setES(magField_.product(), trackerGeometry_.product());
matcher_.setES(magField_.product(), trackerGeometry_.product());
}
}

Expand Down Expand Up @@ -248,20 +231,8 @@ void ElectronSeedGenerator::seedsFromThisCluster(edm::Ref<reco::SuperClusterColl
deltaPhi1 = dPhi1Coef1_ + dPhi1Coef2_ / clusterEnergyT;
}

float ephimin1 = -deltaPhi1 * sizeWindowENeg_;
float ephimax1 = deltaPhi1 * (1. - sizeWindowENeg_);
float pphimin1 = -deltaPhi1 * (1. - sizeWindowENeg_);
float pphimax1 = deltaPhi1 * sizeWindowENeg_;

float phimin2B = -deltaPhi2B_ / 2.;
float phimax2B = deltaPhi2B_ / 2.;
float phimin2F = -deltaPhi2F_ / 2.;
float phimax2F = deltaPhi2F_ / 2.;

electronMatcher_.set1stLayer(ephimin1, ephimax1);
positronMatcher_.set1stLayer(pphimin1, pphimax1);
electronMatcher_.set2ndLayer(phimin2B, phimax2B, phimin2F, phimax2F);
positronMatcher_.set2ndLayer(phimin2B, phimax2B, phimin2F, phimax2F);
matcher_.set1stLayer(-deltaPhi1 * sizeWindowENeg_, deltaPhi1 * (1. - sizeWindowENeg_));
matcher_.set2ndLayer(-deltaPhi2B_ / 2., deltaPhi2B_ / 2., -deltaPhi2F_ / 2., deltaPhi2F_ / 2.);
}

if (!useRecoVertex_) // here use the beam spot position
Expand All @@ -275,14 +246,13 @@ void ElectronSeedGenerator::seedsFromThisCluster(edm::Ref<reco::SuperClusterColl
GlobalPoint vertexPos;
ele_convert(beamSpot.position(), vertexPos);

electronMatcher_.set1stLayerZRange(myZmin1, myZmax1);
positronMatcher_.set1stLayerZRange(myZmin1, myZmax1);
matcher_.set1stLayerZRange(myZmin1, myZmax1);

// try electron
auto elePixelSeeds = electronMatcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, -1.);
auto elePixelSeeds = matcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, -1.);
seedsFromTrajectorySeeds(elePixelSeeds, caloCluster, out, false);
// try positron
auto posPixelSeeds = positronMatcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, 1.);
auto posPixelSeeds = matcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, 1.);
seedsFromTrajectorySeeds(posPixelSeeds, caloCluster, out, true);

} else if (vertices) // here we use the reco vertices
Expand All @@ -301,14 +271,13 @@ void ElectronSeedGenerator::seedsFromThisCluster(edm::Ref<reco::SuperClusterColl
myZmax1 = vertex.position().z() + deltaZ1WithVertex_;
}

electronMatcher_.set1stLayerZRange(myZmin1, myZmax1);
positronMatcher_.set1stLayerZRange(myZmin1, myZmax1);
matcher_.set1stLayerZRange(myZmin1, myZmax1);

// try electron
auto elePixelSeeds = electronMatcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, -1.);
auto elePixelSeeds = matcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, -1.);
seedsFromTrajectorySeeds(elePixelSeeds, caloCluster, out, false);
// try positron
auto posPixelSeeds = positronMatcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, 1.);
auto posPixelSeeds = matcher_(*initialSeedCollectionVector_, clusterPos, vertexPos, clusterEnergy, 1.);
seedsFromTrajectorySeeds(posPixelSeeds, caloCluster, out, true);
}
}
Expand Down
28 changes: 13 additions & 15 deletions RecoEgamma/EgammaElectronAlgos/src/PixelHitMatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ using namespace std;

bool PixelHitMatcher::ForwardMeasurementEstimator::operator()(const GlobalPoint &vprim,
const TrajectoryStateOnSurface &absolute_ts,
const GlobalPoint &absolute_gp) const {
const GlobalPoint &absolute_gp,
int charge) const {
GlobalVector ts = absolute_ts.globalParameters().position() - vprim;
GlobalVector gp = absolute_gp - vprim;

Expand All @@ -30,14 +31,15 @@ bool PixelHitMatcher::ForwardMeasurementEstimator::operator()(const GlobalPoint
if ((rDiff >= rMax) | (rDiff <= rMin))
return false;

float phiDiff = normalizedPhi(gp.barePhi() - ts.barePhi());
float phiDiff = -charge * normalizedPhi(gp.barePhi() - ts.barePhi());

return (phiDiff < thePhiMax) & (phiDiff > thePhiMin);
}

bool PixelHitMatcher::BarrelMeasurementEstimator::operator()(const GlobalPoint &vprim,
const TrajectoryStateOnSurface &absolute_ts,
const GlobalPoint &absolute_gp) const {
const GlobalPoint &absolute_gp,
int charge) const {
GlobalVector ts = absolute_ts.globalParameters().position() - vprim;
GlobalVector gp = absolute_gp - vprim;

Expand All @@ -53,7 +55,7 @@ bool PixelHitMatcher::BarrelMeasurementEstimator::operator()(const GlobalPoint &
if ((zDiff >= myZmax) | (zDiff <= myZmin))
return false;

float phiDiff = normalizedPhi(gp.barePhi() - ts.barePhi());
float phiDiff = -charge * normalizedPhi(gp.barePhi() - ts.barePhi());

return (phiDiff < thePhiMax) & (phiDiff > thePhiMin);
}
Expand All @@ -64,20 +66,15 @@ PixelHitMatcher::PixelHitMatcher(float phi1min,
float phi2maxB,
float phi2minF,
float phi2maxF,
float z2minB,
float z2maxB,
float r2minF,
float r2maxF,
float rMinI,
float rMaxI,
bool useRecoVertex)
: //zmin1 and zmax1 are dummy at this moment, set from beamspot later
meas1stBLayer{phi1min, phi1max, 0., 0.},
meas2ndBLayer{phi2minB, phi2maxB, z2minB, z2maxB},
meas1stFLayer{phi1min, phi1max, 0., 0., rMinI, rMaxI},
meas2ndFLayer{phi2minF, phi2maxF, r2minF, r2maxF, rMinI, rMaxI},
prop1stLayer(nullptr),
prop2ndLayer(nullptr),
meas2ndBLayer{phi2minB, phi2maxB, -z2maxB, z2maxB},
meas1stFLayer{phi1min, phi1max, 0., 0., -rMaxI, rMaxI},
meas2ndFLayer{phi2minF, phi2maxF, -r2maxF, r2maxF, -rMaxI, rMaxI},
useRecoVertex_(useRecoVertex) {}

void PixelHitMatcher::set1stLayer(float dummyphi1min, float dummyphi1max) {
Expand Down Expand Up @@ -183,7 +180,8 @@ std::vector<SeedWithInfo> PixelHitMatcher::operator()(const std::vector<const Tr

if (!tsos1->isValid())
continue;
bool est = id1.subdetId() % 2 ? meas1stBLayer(vprim, *tsos1, hit1Pos) : meas1stFLayer(vprim, *tsos1, hit1Pos);
bool est = id1.subdetId() % 2 ? meas1stBLayer(vprim, *tsos1, hit1Pos, charge)
: meas1stFLayer(vprim, *tsos1, hit1Pos, charge);
if (!est)
continue;
EleRelPointPair pp1(hit1Pos, tsos1->globalParameters().position(), vprim);
Expand Down Expand Up @@ -229,8 +227,8 @@ std::vector<SeedWithInfo> PixelHitMatcher::operator()(const std::vector<const Tr
if (!tsos2->isValid())
continue;
const GlobalPoint &hit2Pos = hitGpMap[idx2];
bool est2 =
id2.subdetId() % 2 ? meas2ndBLayer(vertex, *tsos2, hit2Pos) : meas2ndFLayer(vertex, *tsos2, hit2Pos);
bool est2 = id2.subdetId() % 2 ? meas2ndBLayer(vertex, *tsos2, hit2Pos, charge)
: meas2ndFLayer(vertex, *tsos2, hit2Pos, charge);
if (est2) {
EleRelPointPair pp2(hit2Pos, tsos2->globalParameters().position(), vertex);
const int subDet2 = id2.subdetId();
Expand Down
Loading