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

ElectronNHitSeedProducer modernization #29512

Merged
merged 3 commits into from
May 5, 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
20 changes: 20 additions & 0 deletions HLTrigger/Configuration/python/customizeHLTforCMSSW.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,30 @@ def customiseFor2017DtUnpacking(process):

return process

def customiseFor29512(process):
"""Refresh configuration of ElectronNHitSeedProducer instances.

Loops over some parameters of ElectronNHitSeedProducer instances and changes their type from string to ESInputTag.

For PR https://github.com/cms-sw/cmssw/pull/29512 "ElectronNHitSeedProducer modernization"
"""

for producer in producers_by_type(process, "ElectronNHitSeedProducer"):
matcherConfig = producer.matcherConfig
for parameter_name in ("detLayerGeom", "navSchool", "paramMagField"):
if hasattr(matcherConfig, parameter_name):
old_parameter = getattr(matcherConfig, parameter_name)
if old_parameter.pythonTypeName().endswith("string"):
old_value = old_parameter.pythonValue()[1:-1]
setattr(matcherConfig, parameter_name, cms.ESInputTag("", old_value))

return process

# CMSSW version specific customizations
def customizeHLTforCMSSW(process, menuType="GRun"):

# add call to action function in proper order: newest last!
# process = customiseFor12718(process)
process = customiseFor29512(process)

return process
157 changes: 58 additions & 99 deletions RecoEgamma/EgammaElectronAlgos/interface/TrajSeedMatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
#include "RecoTracker/MeasurementDet/interface/MeasurementTrackerEvent.h"
#include "RecoEgamma/EgammaElectronAlgos/interface/utils.h"

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

namespace edm {
class ConsumesCollector;
class EventSetup;
class ConfigurationDescriptions;
class ParameterSet;
Expand All @@ -47,55 +51,17 @@ class TrackingRecHit;

class TrajSeedMatcher {
public:
class SCHitMatch {
public:
SCHitMatch()
: detId_(0),
dRZ_(std::numeric_limits<float>::max()),
dPhi_(std::numeric_limits<float>::max()),
hit_(nullptr),
et_(0),
eta_(0),
phi_(0),
charge_(0),
nrClus_(0) {}

//does not set charge,et,nrclus
SCHitMatch(const GlobalPoint& vtxPos, const TrajectoryStateOnSurface& trajState, const TrackingRecHit& hit);
~SCHitMatch() = default;

void setExtra(float et, float eta, float phi, int charge, int nrClus) {
et_ = et;
eta_ = eta;
phi_ = phi;
charge_ = charge;
nrClus_ = nrClus;
}

int subdetId() const { return detId_.subdetId(); }
DetId detId() const { return detId_; }
float dRZ() const { return dRZ_; }
float dPhi() const { return dPhi_; }
const GlobalPoint& hitPos() const { return hitPos_; }
float et() const { return et_; }
float eta() const { return eta_; }
float phi() const { return phi_; }
int charge() const { return charge_; }
int nrClus() const { return nrClus_; }
const TrackingRecHit* hit() const { return hit_; }

private:
DetId detId_;
GlobalPoint hitPos_;
float dRZ_;
float dPhi_;
const TrackingRecHit* hit_; //we do not own this
//extra quanities which are set later
float et_;
float eta_;
float phi_;
int charge_;
int nrClus_;
struct SCHitMatch {
const DetId detId = 0;
const GlobalPoint hitPos;
const float dRZ = std::numeric_limits<float>::max();
const float dPhi = std::numeric_limits<float>::max();
const TrackingRecHit& hit;
const float et = 0.f;
const float eta = 0.f;
const float phi = 0.f;
const int charge = 0;
const int nrClus = 0;
};

struct MatchInfo {
Expand Down Expand Up @@ -178,19 +144,41 @@ class TrajSeedMatcher {
};

public:
explicit TrajSeedMatcher(const edm::ParameterSet& pset);
struct Configuration {
Configuration(const edm::ParameterSet& pset, edm::ConsumesCollector&& cc);

const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magFieldToken;
const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> paramMagFieldToken;
const edm::ESGetToken<NavigationSchool, NavigationSchoolRecord> navSchoolToken;
const edm::ESGetToken<DetLayerGeometry, RecoGeometryRecord> detLayerGeomToken;

const bool useRecoVertex;
const bool enableHitSkipping;
const bool requireExactMatchCount;
const bool useParamMagFieldIfDefined;

//these two variables determine how hits we require
//based on how many valid layers we had
//right now we always need atleast two hits
//also highly dependent on the seeds you pass in
//which also require a given number of hits
const std::vector<unsigned int> minNrHits;
const std::vector<int> minNrHitsValidLayerBins;

const std::vector<std::unique_ptr<MatchingCuts> > matchingCuts;
};

explicit TrajSeedMatcher(Configuration const& cfg,
edm::EventSetup const& iSetup,
MeasurementTrackerEvent const& measTkEvt);
~TrajSeedMatcher() = default;

static edm::ParameterSetDescription makePSetDescription();

void doEventSetup(const edm::EventSetup& iSetup);

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

void setMeasTkEvtHandle(edm::Handle<MeasurementTrackerEvent> handle) { measTkEvt_ = std::move(handle); }
std::vector<TrajSeedMatcher::SeedWithInfo> operator()(const TrajectorySeedCollection& seeds,
const GlobalPoint& candPos,
const GlobalPoint& vprim,
const float energy);

private:
std::vector<SCHitMatch> processSeed(const TrajectorySeed& seed,
Expand All @@ -203,20 +191,6 @@ class TrajSeedMatcher {
const GlobalPoint& hitPos,
const GlobalPoint& candPos);

bool passTrajPreSel(const GlobalPoint& hitPos, const GlobalPoint& candPos) const;

TrajSeedMatcher::SCHitMatch matchFirstHit(const TrajectorySeed& seed,
const TrajectoryStateOnSurface& trajState,
const GlobalPoint& vtxPos,
const PropagatorWithMaterial& propagator);

TrajSeedMatcher::SCHitMatch match2ndToNthHit(const TrajectorySeed& seed,
const FreeTrajectoryState& trajState,
const size_t hitNr,
const GlobalPoint& prevHitPos,
const GlobalPoint& vtxPos,
const PropagatorWithMaterial& propagator);

const TrajectoryStateOnSurface& getTrajStateFromVtx(const TrackingRecHit& hit,
const TrajectoryStateOnSurface& initialState,
const PropagatorWithMaterial& propagator);
Expand Down Expand Up @@ -252,37 +226,22 @@ class TrajSeedMatcher {
//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 useParamMagFieldIfDefined_ && magFieldParam_->isDefined(point) ? *magFieldParam_ : *magField_;
return cfg_.useParamMagFieldIfDefined && magFieldParam_.isDefined(point) ? magFieldParam_ : magField_;
}

private:
static constexpr float kElectronMass_ = 0.000511;
static constexpr float kPhiCut_ = -0.801144; //cos(2.5)
std::unique_ptr<PropagatorWithMaterial> forwardPropagator_;
std::unique_ptr<PropagatorWithMaterial> backwardPropagator_;
unsigned long long cacheIDMagField_;
edm::ESHandle<MagneticField> magField_;
edm::ESHandle<MagneticField> magFieldParam_;
edm::Handle<MeasurementTrackerEvent> measTkEvt_;
edm::ESHandle<NavigationSchool> navSchool_;
edm::ESHandle<DetLayerGeometry> detLayerGeom_;
std::string paramMagFieldLabel_;
std::string navSchoolLabel_;
std::string detLayerGeomLabel_;

bool useRecoVertex_;
bool enableHitSkipping_;
bool requireExactMatchCount_;
bool useParamMagFieldIfDefined_;
std::vector<std::unique_ptr<MatchingCuts> > matchingCuts_;

//these two varibles determine how hits we require
//based on how many valid layers we had
//right now we always need atleast two hits
//also highly dependent on the seeds you pass in
//which also require a given number of hits
const std::vector<unsigned int> minNrHits_;
const std::vector<int> minNrHitsValidLayerBins_;

Configuration const& cfg_;

MagneticField const& magField_;
MagneticField const& magFieldParam_;
MeasurementTrackerEvent const& measTkEvt_;
NavigationSchool const& navSchool_;
DetLayerGeometry const& detLayerGeom_;

PropagatorWithMaterial forwardPropagator_;
PropagatorWithMaterial backwardPropagator_;

std::unordered_map<int, TrajectoryStateOnSurface> trajStateFromVtxPosChargeCache_;
std::unordered_map<int, TrajectoryStateOnSurface> trajStateFromVtxNegChargeCache_;
Expand Down
Loading