-
Notifications
You must be signed in to change notification settings - Fork 6
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
Cbrown kfout #93
Cbrown kfout #93
Changes from 7 commits
eed1c60
dcaef22
8fc570e
686e754
1d347ff
2577813
5f37f86
ef3edb7
5110583
f899d07
1c2bd8c
b4b4879
bd968ae
c78f1fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -32,6 +32,8 @@ namespace trackFindingTracklet { | |||||
public: | ||||||
explicit ProducerKFout(const ParameterSet&); | ||||||
~ProducerKFout() override {} | ||||||
template<typename T> | ||||||
int digitise(const vector<T> Bins, T Value, T factor = 1 ); | ||||||
|
||||||
private: | ||||||
void beginRun(const Run&, const EventSetup&) override; | ||||||
|
@@ -58,6 +60,25 @@ namespace trackFindingTracklet { | |||||
const Setup* setup_; | ||||||
// helper class to extract structured data from TTDTC::Frames | ||||||
const DataFormats* dataFormats_; | ||||||
// Cot bins used to convert from cot to TanL | ||||||
vector<double> cotBins_; | ||||||
// Factors used to convert between phi/Z at a radius T, modified to include scale conversions needed in calculation | ||||||
double modChosenRofZ_ = 0; | ||||||
double modChosenRofPhi_ = 0; | ||||||
// Corrections to Phi depending on which phi sector | ||||||
double BaseSectorCorr_ = 0; | ||||||
double UnsignedBaseSector_ = 0; | ||||||
// Bins for dPhi/dZ use to access weight LUT below | ||||||
vector<double> dPhiBins_; | ||||||
vector<double> dZBins_; | ||||||
// LUT for weighting functions for chi2 calculation | ||||||
vector<double> v0Bins_; | ||||||
vector<double> v1Bins_; | ||||||
// Bins for final Chi2 Packing | ||||||
vector<double> chi2rphiBins_; | ||||||
vector<double> chi2rzBins_; | ||||||
|
||||||
int maxTracksPerEvent_; | ||||||
}; | ||||||
|
||||||
ProducerKFout::ProducerKFout(const ParameterSet& iConfig) : | ||||||
|
@@ -92,6 +113,37 @@ namespace trackFindingTracklet { | |||||
setup_->checkHistory(iRun.processHistory()); | ||||||
// helper class to extract structured data from TTDTC::Frames | ||||||
dataFormats_ = &iSetup.getData(esGetTokenDataFormats_); | ||||||
|
||||||
for (int i = 0; i < setup_->numSectorsEta(); i++) cotBins_.push_back(setup_->sectorCot(i)); | ||||||
|
||||||
modChosenRofZ_ = setup_->chosenRofZ(); | ||||||
modChosenRofPhi_ = setup_->hybridChosenRofPhi(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also those are not really doing anything, you could just use setup_->chosenRofZ() when needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, forgot to clear them after my previous commit |
||||||
|
||||||
UnsignedBaseSector_ = (M_PI / (double)(setup_->numRegions() * setup_->numSectorsPhi()) ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that value exist already inside Setup, you can get the value via setup_->baseSector() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
|
||||||
// Convert Integer bins to doubles for internal calculation | ||||||
for(size_t i = 0; i < setup_->kfoutdPhiBins().size(); i++) | ||||||
dPhiBins_.push_back((double)setup_->kfoutdPhiBins()[i] * dataFormats_->base(Variable::dPhi, Process::kfin)); | ||||||
for(size_t i = 0; i < setup_->kfoutdZBins().size(); i++) | ||||||
dZBins_.push_back((double)setup_->kfoutdZBins()[i] * dataFormats_->base(Variable::dZ, Process::kfin)); | ||||||
for(size_t i = 0; i < setup_->kfoutv0Bins().size(); i++) | ||||||
v0Bins_.push_back(setup_->kfoutv0Bins()[i]*dataFormats_->base(Variable::dPhi, Process::kfin)); | ||||||
for(size_t i = 0; i < setup_->kfoutv1Bins().size(); i++) | ||||||
v1Bins_.push_back(setup_->kfoutv1Bins()[i]*dataFormats_->base(Variable::dZ, Process::kfin)); | ||||||
for(size_t i = 0; i < setup_->kfoutchi2rphiBins().size(); i++) | ||||||
chi2rphiBins_.push_back((double)setup_->kfoutchi2rphiBins()[i] *setup_->kfoutchi2rphiConv() * pow(dataFormats_->base(Variable::dPhi, Process::kfin),3)); | ||||||
for(size_t i = 0; i < setup_->kfoutchi2rzBins().size(); i++) | ||||||
chi2rzBins_.push_back((double)setup_->kfoutchi2rzBins()[i] *setup_->kfoutchi2rzConv() * pow(dataFormats_->base(Variable::dZ, Process::kfin),3)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why there are any configuration parameter for all this bins. I expect that you look up for any dPhi or dZ value the squared inverse. Since the number of bits and base of dPhi and dZ are known there is no external input needed to do so. The only thing I can imagine is if one does not want to use all bits of those variables in order to minimize BRAM resources in f/w. If that is the case I expect one integer per variable defining how many msb one wants to use. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done, reworked the calculation of v0 and v1 throughout |
||||||
maxTracksPerEvent_ = setup_->numFramesIO() * setup_->clockRatio(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this clock ratio thingi is very irritating. The factor 2 / 3 comes from the fact that you send 96 bit tracks over the 64 bit emp links, that has nothing to do with a ratio of clocks. The 64 bit are defined here: https://github.com/cms-L1TK/cmssw/blob/cbrown-kfout/DataFormats/L1TrackTrigger/interface/TTBV.h#L22. What you should add to Setup are the 96 bits for TTTrack word. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I misunderstood where the 2/3 factor was coming from, for now I will add it to the setup but in the coming update to the tttrack word dataformat it should be possible to extract the 96 bits from the tttrack word |
||||||
} | ||||||
|
||||||
|
||||||
template<typename T> | ||||||
int ProducerKFout::digitise(const vector<T> Bins, T Value, T factor ) { | ||||||
for (int i = 0; i < (int)Bins.size(); i++){ | ||||||
if (Value > Bins[i]*factor && Value <= Bins[i+1]*factor) {return i;} | ||||||
} | ||||||
return -1; | ||||||
} | ||||||
|
||||||
void ProducerKFout::produce(Event& iEvent, const EventSetup& iSetup) { | ||||||
|
@@ -109,19 +161,139 @@ namespace trackFindingTracklet { | |||||
Handle<TTTrackRefMap> handleTTTrackRefMap; | ||||||
iEvent.getByToken<TTTrackRefMap>(edGetTokenTTTrackRefMap_, handleTTTrackRefMap); | ||||||
const TTTrackRefMap& ttTrackRefMap = *handleTTTrackRefMap.product(); | ||||||
// perform KFout emulation and fill accepted and lost | ||||||
// StreamsTrack is a vector of StreamTrack which is a vector of FrameTrack which is a pair of an edm::Ref<TTTrack> and std::bitset<64> | ||||||
// the std::bitset<64> are the frames of an emp link | ||||||
// the edm::Ref<TTTrack> is used to meassure tracking efficiency | ||||||
// your input streamsTracks contain edm::Ref<TTTrack> to KF input TTTracks | ||||||
// use ttTrackRefMap to lookup edm::Ref<TTTrack> of KF output TTTracks, that allows us to meassure the tracking efficiency after the KFout block | ||||||
// your output frames belong to either only one TTTrack or to two, in the later case chose any edm::Ref<TTTrack> of the two | ||||||
} | ||||||
// 18 Output Links (First Vector) each has a vector of tracks per event (second vector) each track is 3 32 bit TTBV partial tracks | ||||||
vector<vector<TTBV>> SortedPartialTracks(setup_->numRegions() * setup_->tfpNumChannel(),vector<TTBV>(0)); | ||||||
StreamsTrack OutputStreamsTracks(setup_->numRegions() * setup_->tfpNumChannel()); | ||||||
|
||||||
for (int iLink = 0; iLink < (int)streamsTracks.size(); iLink++ ){ | ||||||
|
||||||
for (int iTrack = 0; iTrack < (int)streamsTracks[iLink].size(); iTrack++ ){ | ||||||
auto track = streamsTracks[iLink].at(iTrack); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use const auto& if you are not manipulating track There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
TrackKF InTrack(track,dataFormats_); | ||||||
|
||||||
double temp_z0 = InTrack.zT() - ((InTrack.cot() * setup_->chosenRofZ())); | ||||||
|
||||||
// Correction to Phi calcuation depending if +ve/-ve phi sector | ||||||
if (InTrack.sectorPhi() == 0) BaseSectorCorr_ = -UnsignedBaseSector_; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is not need for BaseSectorCorr_ to be an class member. Why not writing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
else BaseSectorCorr_ = UnsignedBaseSector_; | ||||||
|
||||||
double temp_phi0 = InTrack.phiT() - ((InTrack.inv2R()) * setup_->hybridChosenRofPhi()) + BaseSectorCorr_; | ||||||
|
||||||
double temp_tanL = cotBins_[InTrack.sectorEta()] + InTrack.cot(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could copy those lines https://github.com/cms-L1TK/cmssw/blob/cbrown-kfout/L1Trigger/TrackerTFP/interface/DataFormats.h#L637-L638 to TrackKF and use InTrack.cotGlobal() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
|
||||||
TTBV HitPattern(0,setup_->numLayers()); | ||||||
|
||||||
double tempchi2rphi = 0; | ||||||
double tempchi2rz = 0; | ||||||
|
||||||
for (int iStub = 0; iStub < setup_->numLayers() - 1; iStub++ ){ | ||||||
auto stub = streamsStubs[setup_->numLayers()*iLink+iStub].at(iTrack); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
StubKF InStub(stub,dataFormats_,iStub); | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use this class to unpack Stubs KF: cmssw/L1Trigger/TrackerTFP/interface/DataFormats.h Lines 528 to 529 in 539dc1a
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
if (stub.first.isNonnull()){ | ||||||
HitPattern.set(iStub); | ||||||
|
||||||
double phiSquared = InStub.phi() * InStub.phi(); | ||||||
double zSquared = InStub.z() * InStub.z(); | ||||||
|
||||||
double tempv0 = (v0Bins_[digitise(dPhiBins_, InStub.dPhi())]); | ||||||
double tempv1 = (v1Bins_[digitise(dZBins_ , InStub.dZ())]); | ||||||
|
||||||
double tempRphi = phiSquared * tempv0; | ||||||
double tempRz = zSquared * tempv1; | ||||||
|
||||||
tempchi2rphi += tempRphi; | ||||||
tempchi2rz += tempRz; | ||||||
} | ||||||
} | ||||||
// TODO extract TTTrack bit widths from TTTrack word pending update to the TTTrack_word class | ||||||
TTBV TrackValid(1,1,false); | ||||||
TTBV extraMVA(0,6,false); | ||||||
TTBV TQMVA(0,3,false); | ||||||
TTBV BendChi2(0,3,false); | ||||||
TTBV Chi2rphi(digitise(chi2rphiBins_,tempchi2rphi),4,false); | ||||||
TTBV Chi2rz(digitise(chi2rzBins_,tempchi2rz),4,false); | ||||||
TTBV D0(0,13,false); | ||||||
TTBV z0(temp_z0 ,dataFormats_->base(Variable::zT,Process::kf) ,12,true); | ||||||
TTBV TanL(temp_tanL,dataFormats_->base(Variable::cot,Process::kf),16,true); | ||||||
TTBV phi0(temp_phi0,dataFormats_->base(Variable::phiT,Process::kf),12,true); | ||||||
TTBV InvR(-1*InTrack.inv2R(),dataFormats_->base(Variable::inv2R,Process::kf) ,16,true ); | ||||||
|
||||||
// 6 + 3 + 7 + 3 + 13 | ||||||
TTBV PartialTrack1((extraMVA + TQMVA + HitPattern + BendChi2 + D0),32,false); | ||||||
// 4 + 12 + 16 | ||||||
TTBV PartialTrack2((Chi2rz + z0 + TanL),32,false); | ||||||
// 4 + 12 + 15 + 1 | ||||||
TTBV PartialTrack3((Chi2rphi + phi0 + InvR + TrackValid),32,false); | ||||||
|
||||||
// Sort Tracks based on eta | ||||||
if (iLink % 2 == 0){ | ||||||
if (InTrack.sectorEta() < (int)(setup_->numSectorsEta()/2)){ | ||||||
SortedPartialTracks[iLink].push_back(PartialTrack1); | ||||||
SortedPartialTracks[iLink].push_back(PartialTrack2); | ||||||
SortedPartialTracks[iLink].push_back(PartialTrack3); | ||||||
OutputStreamsTracks[iLink].emplace_back(track); | ||||||
} | ||||||
else{ | ||||||
SortedPartialTracks[iLink+1].push_back(PartialTrack1); | ||||||
SortedPartialTracks[iLink+1].push_back(PartialTrack2); | ||||||
SortedPartialTracks[iLink+1].push_back(PartialTrack3); | ||||||
OutputStreamsTracks[iLink+1].emplace_back(track); | ||||||
} | ||||||
} | ||||||
else{ | ||||||
if (InTrack.sectorEta() < (int)(setup_->numSectorsEta()/2)){ | ||||||
SortedPartialTracks[iLink-1].push_back(PartialTrack1); | ||||||
SortedPartialTracks[iLink-1].push_back(PartialTrack2); | ||||||
SortedPartialTracks[iLink-1].push_back(PartialTrack3); | ||||||
OutputStreamsTracks[iLink-1].emplace_back(track); | ||||||
} | ||||||
else{ | ||||||
SortedPartialTracks[iLink].push_back(PartialTrack1); | ||||||
SortedPartialTracks[iLink].push_back(PartialTrack2); | ||||||
SortedPartialTracks[iLink].push_back(PartialTrack3); | ||||||
OutputStreamsTracks[iLink].emplace_back(track); | ||||||
} | ||||||
|
||||||
} | ||||||
} // Tracks | ||||||
} // Links | ||||||
|
||||||
// Fill products and match up tracks | ||||||
TTBV NullBitTrack(0,32,false); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this could be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
for (int iLink = 0; iLink < (int)OutputStreamsTracks.size(); iLink++ ){ | ||||||
// Iterate through partial tracks | ||||||
int numLinkTracks = (int)OutputStreamsTracks[iLink].size(); | ||||||
if (numLinkTracks > 0){ | ||||||
if ((numLinkTracks % 2 != 0)) { //If there is an odd number of tracks | ||||||
SortedPartialTracks[iLink].push_back(NullBitTrack); //Pad out final set of bits | ||||||
OutputStreamsTracks[iLink].emplace_back(OutputStreamsTracks[iLink][numLinkTracks]); //Pad out with final repeated track | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could write There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
numLinkTracks++; | ||||||
} //If there is an odd number of tracks | ||||||
for (int iTrack = 0; iTrack < (int)(SortedPartialTracks[iLink].size()); iTrack++ ){ | ||||||
if (iTrack % 2 == 1){ | ||||||
TTTrackRef TrackRef; | ||||||
for (auto &it : ttTrackRefMap) { //Iterate throguh ttTrackRefMap to find TTTrackRef Key by a TTTrack Value | ||||||
if(it.second == OutputStreamsTracks[iLink][(int)(iTrack-1)/3].first) { | ||||||
TrackRef = it.first; | ||||||
} | ||||||
} | ||||||
if ((int)iTrack/3 <= maxTracksPerEvent_){ | ||||||
accepted[iLink].emplace_back(std::make_pair(TrackRef,(SortedPartialTracks[iLink][iTrack].slice(32) + SortedPartialTracks[iLink][iTrack-1].slice(32)).bs())); | ||||||
} | ||||||
else{ | ||||||
lost[iLink].emplace_back(std::make_pair(TrackRef,(SortedPartialTracks[iLink][iTrack].slice(32) + SortedPartialTracks[iLink][iTrack-1].slice(32)).bs())); | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally prefer less indented code. In case where you have an
without else branch could you consider
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when bla is multiple lines long. I see a lot of one liner which are enclosed by corny brackets, I would prefer to remove the brackets for those one liners. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done and labelled final curly brackets if they remain |
||||||
|
||||||
} // Config Supported | ||||||
// store products | ||||||
iEvent.emplace(edPutTokenAccepted_, move(accepted)); | ||||||
iEvent.emplace(edPutTokenLost_, move(lost)); | ||||||
} | ||||||
|
||||||
} // namespace trackFindingTracklet | ||||||
|
||||||
DEFINE_FWK_MODULE(trackFindingTracklet::ProducerKFout); | ||||||
DEFINE_FWK_MODULE(trackFindingTracklet::ProducerKFout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like a weird way to copy a vector, you could just call setup_->sectorCot() when needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done