Skip to content

Commit

Permalink
Merge pull request cms-sw#9 from SegmentLinking/CMSSW_13_0_0_pre4_LST…
Browse files Browse the repository at this point in the history
…_improveLSTOutConv

Sync with standalone developments and options for the LSTOutputConverter
  • Loading branch information
VourMa authored May 15, 2023
2 parents 52f4284 + 45cf6f9 commit 2b2e194
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,12 @@

_HighPtTripletStepTask_LST = HighPtTripletStepTask.copy()
from RecoLocalTracker.Phase2TrackerRecHits.Phase2TrackerRecHits_cfi import siPhase2RecHits
from RecoTracker.LST.lstSeedTracks_cfi import lstInitialStepSeedTracks,lstHighPtTripletStepSeedTracks
from RecoTracker.LST.lstPixelSeedInputProducer_cfi import lstPixelSeedInputProducer
from RecoTracker.LST.lstPhase2OTHitsInputProducer_cfi import lstPhase2OTHitsInputProducer
from RecoTracker.LST.alpaka_cuda_asyncLSTProducer_cfi import alpaka_cuda_asyncLSTProducer
lstProducer = alpaka_cuda_asyncLSTProducer.clone()
_HighPtTripletStepTask_LST.add(siPhase2RecHits, lstPixelSeedInputProducer, lstPhase2OTHitsInputProducer, lstProducer)
_HighPtTripletStepTask_LST.add(siPhase2RecHits, lstInitialStepSeedTracks, lstHighPtTripletStepSeedTracks, lstPixelSeedInputProducer, lstPhase2OTHitsInputProducer, lstProducer)
(trackingPhase2PU140 & trackingLST).toReplaceWith(HighPtTripletStepTask, _HighPtTripletStepTask_LST)

# fast tracking mask producer
Expand Down
3 changes: 2 additions & 1 deletion RecoTracker/LST/interface/LSTOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class LSTOutput {
LSTOutput() = default;
~LSTOutput() = default;

enum LSTTCType { T5 = 4, pT3 = 5, pT5 = 7, pLS = 8 };

void setLSTOutputTraits(std::vector<std::vector<unsigned int>> hitIdx,
std::vector<unsigned int> len,
std::vector<float> pt,
Expand Down Expand Up @@ -44,4 +46,3 @@ class LSTOutput {
};

#endif

1 change: 0 additions & 1 deletion RecoTracker/LST/interface/LSTPhase2OTHitsInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ class LSTPhase2OTHitsInput {
};

#endif

5 changes: 0 additions & 5 deletions RecoTracker/LST/interface/LSTPixelSeedInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class LSTPixelSeedInput {
std::vector<float> stateTrajGlbPy,
std::vector<float> stateTrajGlbPz,
std::vector<int> q,
std::vector<unsigned int> algo,
std::vector<std::vector<int>> hitIdx) {
px_ = px;
py_ = py;
Expand All @@ -39,7 +38,6 @@ class LSTPixelSeedInput {
stateTrajGlbPy_ = stateTrajGlbPy;
stateTrajGlbPz_ = stateTrajGlbPz;
q_ = q;
algo_ = algo;
hitIdx_ = hitIdx;
}

Expand All @@ -57,7 +55,6 @@ class LSTPixelSeedInput {
std::vector<float> const& stateTrajGlbPy() const { return stateTrajGlbPy_; }
std::vector<float> const& stateTrajGlbPz() const { return stateTrajGlbPz_; }
std::vector<int> const& q() const { return q_; }
std::vector<unsigned int> const& algo() const { return algo_; }
std::vector<std::vector<int>> const& hitIdx() const { return hitIdx_; }

private:
Expand All @@ -75,9 +72,7 @@ class LSTPixelSeedInput {
std::vector<float> stateTrajGlbPy_;
std::vector<float> stateTrajGlbPz_;
std::vector<int> q_;
std::vector<unsigned int> algo_;
std::vector<std::vector<int>> hitIdx_;
};

#endif

1 change: 0 additions & 1 deletion RecoTracker/LST/plugins/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<use name="RecoTracker/LST"/>
<use name="RecoTracker/TkSeedingLayers"/>
<use name="RecoTracker/TkSeedGenerator"/>
<use name="TrackingTools/Records"/>
<use name="TrackingTools/GeomPropagators"/>
<use name="TrackingTools/Records"/>
<use name="TrackingTools/TrajectoryState"/>
Expand Down
120 changes: 70 additions & 50 deletions RecoTracker/LST/plugins/LSTOutputConverter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
#include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"


class LSTOutputConverter : public edm::global::EDProducer<> {
public:
explicit LSTOutputConverter(edm::ParameterSet const& iConfig);
Expand All @@ -39,26 +38,34 @@ class LSTOutputConverter : public edm::global::EDProducer<> {
const edm::EDGetTokenT<LSTOutput> lstOutputToken_;
const edm::EDGetTokenT<LSTPhase2OTHitsInput> lstPhase2OTHitsInputToken_;
const edm::EDGetTokenT<TrajectorySeedCollection> lstPixelSeedToken_;
const bool includeT5s_;
const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> mfToken_;
edm::ESGetToken<Propagator, TrackingComponentsRecord> propagatorAlongToken_;
edm::ESGetToken<Propagator, TrackingComponentsRecord> propagatorOppositeToken_;
const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tGeomToken_;
//const edm::EDGetTokenT<reco::BeamSpot> beamSpotToken_;
std::unique_ptr<SeedCreator> seedCreator_;
const edm::EDPutTokenT<TrajectorySeedCollection> trajectorySeedPutToken_;
const edm::EDPutTokenT<TrackCandidateCollection> trackCandidatePutToken_;
const edm::EDPutTokenT<std::vector<SeedStopInfo>> seedStopInfoPutToken_;
};

LSTOutputConverter::LSTOutputConverter(edm::ParameterSet const& iConfig)
: lstOutputToken_(consumes<LSTOutput>(iConfig.getUntrackedParameter<edm::InputTag>("lstOutput"))),
lstPhase2OTHitsInputToken_{consumes<LSTPhase2OTHitsInput>(iConfig.getUntrackedParameter<edm::InputTag>("phase2OTHits"))},
lstPixelSeedToken_{consumes<TrajectorySeedCollection>(iConfig.getUntrackedParameter<edm::InputTag>("lstPixelSeeds"))},
lstPhase2OTHitsInputToken_{
consumes<LSTPhase2OTHitsInput>(iConfig.getUntrackedParameter<edm::InputTag>("phase2OTHits"))},
lstPixelSeedToken_{
consumes<TrajectorySeedCollection>(iConfig.getUntrackedParameter<edm::InputTag>("lstPixelSeeds"))},
includeT5s_(iConfig.getParameter<bool>("includeT5s")),
mfToken_(esConsumes()),
propagatorAlongToken_{esConsumes<Propagator, TrackingComponentsRecord>(iConfig.getParameter<edm::ESInputTag>("propagatorAlong"))},
propagatorOppositeToken_{esConsumes<Propagator, TrackingComponentsRecord>(iConfig.getParameter<edm::ESInputTag>("propagatorOpposite"))},
//beamSpotToken_(consumes<reco::BeamSpot>(iConfig.getUntrackedParameter<edm::InputTag>("beamSpot"))),
propagatorAlongToken_{
esConsumes<Propagator, TrackingComponentsRecord>(iConfig.getParameter<edm::ESInputTag>("propagatorAlong"))},
propagatorOppositeToken_{esConsumes<Propagator, TrackingComponentsRecord>(
iConfig.getParameter<edm::ESInputTag>("propagatorOpposite"))},
tGeomToken_(esConsumes()),
seedCreator_(SeedCreatorFactory::get()->create("SeedFromConsecutiveHitsCreator", iConfig.getParameter<edm::ParameterSet>("SeedCreatorPSet"), consumesCollector())),
seedCreator_(SeedCreatorFactory::get()->create("SeedFromConsecutiveHitsCreator",
iConfig.getParameter<edm::ParameterSet>("SeedCreatorPSet"),
consumesCollector())),
trajectorySeedPutToken_(produces<TrajectorySeedCollection>()),
trackCandidatePutToken_(produces<TrackCandidateCollection>()),
seedStopInfoPutToken_(produces<std::vector<SeedStopInfo>>()) {}

Expand All @@ -68,9 +75,9 @@ void LSTOutputConverter::fillDescriptions(edm::ConfigurationDescriptions& descri
desc.addUntracked<edm::InputTag>("lstOutput", edm::InputTag("lstProducer"));
desc.addUntracked<edm::InputTag>("phase2OTHits", edm::InputTag("lstPhase2OTHitsInputProducer"));
desc.addUntracked<edm::InputTag>("lstPixelSeeds", edm::InputTag("lstPixelSeedInputProducer"));
desc.add<bool>("includeT5s", true);
desc.add("propagatorAlong", edm::ESInputTag{"", "PropagatorWithMaterial"});
desc.add("propagatorOpposite", edm::ESInputTag{"", "PropagatorWithMaterialOpposite"});
//desc.addUntracked<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));

edm::ParameterSetDescription psd0;
psd0.add<std::string>("ComponentName", std::string("SeedFromConsecutiveHitsCreator"));
Expand All @@ -95,7 +102,6 @@ void LSTOutputConverter::produce(edm::StreamID, edm::Event& iEvent, const edm::E
const auto& propAlo = iSetup.getData(propagatorAlongToken_);
const auto& propOppo = iSetup.getData(propagatorOppositeToken_);
const auto& tracker = iSetup.getData(tGeomToken_);
//auto const& bs = iEvent.get(beamSpotToken_);

// Vector definitions
std::vector<std::vector<unsigned int>> const& lstTC_hitIdx = lstOutput.hitIdx();
Expand All @@ -106,28 +112,29 @@ void LSTOutputConverter::produce(edm::StreamID, edm::Event& iEvent, const edm::E
std::vector<int> const& lstTC_seedIdx = lstOutput.seedIdx();
std::vector<short> const& lstTC_trackCandidateType = lstOutput.trackCandidateType();

TrackCandidateCollection output;
output.reserve(lstTC_len.size());
TrajectorySeedCollection outputTS;
outputTS.reserve(lstTC_len.size());
TrackCandidateCollection outputTC;
outputTC.reserve(lstTC_len.size());

auto const& OTHits = phase2OTRecHits.hits();

//auto seedsFromT5 = std::make_unique<TrajectorySeedCollection>();
//GlobalPoint vtxOfBs(bs.x0(), bs.y0(), bs.z0());
LogDebug("LSTOutputConverter")<<"lstTC size "<<lstTC_len.size();
for (unsigned int i=0; i<lstTC_len.size(); i++) {
LogDebug("LSTOutputConverter")<<" cand "<<i<<" "<<lstTC_len[i]<<" "<<lstTC_pt[i]<<" "<<lstTC_eta[i]<<" "<<lstTC_phi[i]<<" "<<lstTC_seedIdx[i];
LogDebug("LSTOutputConverter") << "lstTC size " << lstTC_len.size();
for (unsigned int i = 0; i < lstTC_len.size(); i++) {
LogDebug("LSTOutputConverter") << " cand " << i << " " << lstTC_len[i] << " " << lstTC_pt[i] << " " << lstTC_eta[i]
<< " " << lstTC_phi[i] << " " << lstTC_seedIdx[i];
TrajectorySeed seed;
if (lstTC_seedIdx[i] != - 1)
if (lstTC_trackCandidateType[i] != LSTOutput::LSTTCType::T5)
seed = pixelSeeds[lstTC_seedIdx[i]];

edm::OwnVector<TrackingRecHit> recHits;
if (lstTC_seedIdx[i] != - 1) {
if (lstTC_trackCandidateType[i] != LSTOutput::LSTTCType::T5) {
for (auto const& hit : seed.recHits())
recHits.push_back(hit.clone());
}

unsigned int const nPixelHits = lstTC_seedIdx[i] == -1 ? 0 : recHits.size();
for (unsigned int j=nPixelHits; j<lstTC_hitIdx[i].size(); j++)
unsigned int const nPixelHits = lstTC_trackCandidateType[i] == LSTOutput::LSTTCType::T5 ? 0 : recHits.size();
for (unsigned int j = nPixelHits; j < lstTC_hitIdx[i].size(); j++)
recHits.push_back(OTHits[lstTC_hitIdx[i][j]]->clone());

recHits.sort([](const auto& a, const auto& b) {
Expand All @@ -150,57 +157,70 @@ void LSTOutputConverter::produce(edm::StreamID, edm::Event& iEvent, const edm::E
}
});

if (lstTC_seedIdx[i] == -1) { // T5
TrajectorySeedCollection seeds;
if (lstTC_trackCandidateType[i] != LSTOutput::LSTTCType::pLS) {
using Hit = SeedingHitSet::ConstRecHitPointer;
std::vector<Hit> hitsFromT5;
hitsFromT5.reserve(lstTC_len[i]);
std::vector<Hit> hitsForSeed;
hitsForSeed.reserve(lstTC_len.size());
int nHits = 0;
for (auto const& hit : recHits) {
auto hType = tracker.getDetectorType(hit.geographicalId());
if (hType != TrackerGeometry::ModuleType::Ph2PSP && nHits < 2)
continue; // the first two should be P
hitsFromT5.emplace_back(dynamic_cast<Hit>(&hit));
if (lstTC_trackCandidateType[i] == LSTOutput::LSTTCType::T5) {
auto hType = tracker.getDetectorType(hit.geographicalId());
if (hType != TrackerGeometry::ModuleType::Ph2PSP && nHits < 2)
continue; // the first two should be P
}
hitsForSeed.emplace_back(dynamic_cast<Hit>(&hit));
nHits++;
}

TrajectorySeedCollection seeds;
seedCreator_->init(GlobalTrackingRegion(), iSetup, nullptr);
seedCreator_->makeSeed(seeds, hitsFromT5);
seedCreator_->makeSeed(seeds, hitsForSeed);
if (seeds.empty()) {
edm::LogInfo("LSTOutputConverter")<<"failed to convert a T5 to a seed"<<i<<" "<<lstTC_len[i]
<<" "<<lstTC_pt[i]<<" "<<lstTC_eta[i]<<" "<<lstTC_phi[i]<<" "<<lstTC_seedIdx[i];
continue;
edm::LogInfo("LSTOutputConverter")
<< "failed to convert a LST object to a seed" << i << " " << lstTC_len[i] << " " << lstTC_pt[i] << " "
<< lstTC_eta[i] << " " << lstTC_phi[i] << " " << lstTC_seedIdx[i];
if (lstTC_trackCandidateType[i] == LSTOutput::LSTTCType::T5)
continue;
}
seed = seeds[0];
auto const& ss = seed.startingState();
LogDebug("LSTOutputConverter")<<"Created a seed with "<<seed.nHits()<<" "<<ss.detId()<<" "<<ss.pt()
<<" "<<ss.parameters().vector()<<" "<<ss.error(0);
if (lstTC_trackCandidateType[i] == LSTOutput::LSTTCType::T5)
seed = seeds[0];
outputTS.emplace_back(seeds[0]);
auto const& ss = seeds[0].startingState();
LogDebug("LSTOutputConverter") << "Created a seed with " << seed.nHits() << " " << ss.detId() << " " << ss.pt()
<< " " << ss.parameters().vector() << " " << ss.error(0);
} else {
outputTS.emplace_back(seed);
}


TrajectoryStateOnSurface tsos = trajectoryStateTransform::transientState(seed.startingState(), (seed.recHits().end()-1)->surface(), &mf);
TrajectoryStateOnSurface tsos =
trajectoryStateTransform::transientState(seed.startingState(), (seed.recHits().end() - 1)->surface(), &mf);
auto tsosPair = propOppo.propagateWithPath(tsos, *recHits[0].surface());
if (!tsosPair.first.isValid()) {
LogDebug("LSTOutputConverter") << "Propagating to startingState opposite to momentum failed, trying along next";
tsosPair = propAlo.propagateWithPath(tsos, *recHits[0].surface());
}
if (tsosPair.first.isValid()) {
PTrajectoryStateOnDet st = trajectoryStateTransform::persistentState(tsosPair.first, recHits[0].det()->geographicalId().rawId());
PTrajectoryStateOnDet st =
trajectoryStateTransform::persistentState(tsosPair.first, recHits[0].det()->geographicalId().rawId());

output.emplace_back(TrackCandidate(recHits,seed,st));
if (lstTC_trackCandidateType[i] == LSTOutput::LSTTCType::T5 && !includeT5s_) {
continue;
} else {
outputTC.emplace_back(TrackCandidate(recHits, seed, st));
}
} else {
edm::LogInfo("LSTOutputConverter")<<"Failed to make a candidate initial state. Seed state is "<<tsos
<<" TC cand "<<i<<" "<<lstTC_len[i]
<<" "<<lstTC_pt[i]<<" "<<lstTC_eta[i]<<" "<<lstTC_phi[i]<<" "<<lstTC_seedIdx[i]
<<" first hit "<<recHits.front().globalPosition()
<<" last hit "<<recHits.back().globalPosition();
edm::LogInfo("LSTOutputConverter") << "Failed to make a candidate initial state. Seed state is " << tsos
<< " TC cand " << i << " " << lstTC_len[i] << " " << lstTC_pt[i] << " "
<< lstTC_eta[i] << " " << lstTC_phi[i] << " " << lstTC_seedIdx[i]
<< " first hit " << recHits.front().globalPosition() << " last hit "
<< recHits.back().globalPosition();
}
}

LogDebug("LSTOutputConverter")<<"done with conversion: output size "<<output.size();
iEvent.emplace(trackCandidatePutToken_, std::move(output));
iEvent.emplace(seedStopInfoPutToken_, 0U); //dummy stop info
LogDebug("LSTOutputConverter") << "done with conversion: Track candidate output size " << outputTC.size();
iEvent.emplace(trajectorySeedPutToken_, std::move(outputTS));
iEvent.emplace(trackCandidatePutToken_, std::move(outputTC));
iEvent.emplace(seedStopInfoPutToken_, 0U); //dummy stop info
}

DEFINE_FWK_MODULE(LSTOutputConverter);

3 changes: 2 additions & 1 deletion RecoTracker/LST/plugins/LSTPhase2OTHitsInputProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class LSTPhase2OTHitsInputProducer : public edm::global::EDProducer<> {
};

LSTPhase2OTHitsInputProducer::LSTPhase2OTHitsInputProducer(edm::ParameterSet const& iConfig)
: phase2OTRecHitToken_(consumes<Phase2TrackerRecHit1DCollectionNew>(iConfig.getUntrackedParameter<edm::InputTag>("phase2OTRecHits"))),
: phase2OTRecHitToken_(consumes<Phase2TrackerRecHit1DCollectionNew>(
iConfig.getUntrackedParameter<edm::InputTag>("phase2OTRecHits"))),
lstPhase2OTHitsInputPutToken_(produces<LSTPhase2OTHitsInput>()) {}

void LSTPhase2OTHitsInputProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
Expand Down
Loading

0 comments on commit 2b2e194

Please sign in to comment.