Skip to content

Commit

Permalink
Thomas' comments #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriisbrown committed Oct 13, 2021
1 parent 5f37f86 commit ef3edb7
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 121 deletions.
157 changes: 63 additions & 94 deletions L1Trigger/TrackFindingTracklet/plugins/ProducerKFout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,12 @@ 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
// Bins for dPhi/dZ use to create weight LUT
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_;

// Constant used throughout for partial ttrack words
int partialTrackWordBits_;
};

ProducerKFout::ProducerKFout(const ParameterSet& iConfig) :
Expand Down Expand Up @@ -114,34 +101,22 @@ namespace trackFindingTracklet {
// 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));
// Calculate 1/dz**2 and 1/dphi**2 bins for v0 and v1 weightings
for(int i = 0; i < pow(2,dataFormats_->width(Variable::dPhi, Process::kfin)) * setup_->weightBinFraction(); i++)
dPhiBins_.push_back( 1/pow((dataFormats_->base(Variable::dPhi, Process::kfin) * (i / setup_->weightBinFraction() ) ),2));
for(int i = 0; i < pow(2,dataFormats_->width(Variable::dZ, Process::kfin)) * setup_->weightBinFraction(); i++)
dZBins_.push_back( 1/pow((dataFormats_->base(Variable::dZ, Process::kfin) * (i / setup_->weightBinFraction() )),2));

modChosenRofZ_ = setup_->chosenRofZ();
modChosenRofPhi_ = setup_->hybridChosenRofPhi();

UnsignedBaseSector_ = (M_PI / (double)(setup_->numRegions() * setup_->numSectorsPhi()) );

// 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));
maxTracksPerEvent_ = setup_->numFramesIO() * setup_->clockRatio();
partialTrackWordBits_ = TTBV::S_/2;
}



// Helper function to convert floating chi2 to chi2 bin
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;}
if (Value > Bins[i] && Value*factor <= Bins[i+1]) {return i;}
}
return -1;
}
Expand All @@ -168,63 +143,63 @@ namespace trackFindingTracklet {
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);
const auto& track = streamsTracks[iLink].at(iTrack);
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_;
else BaseSectorCorr_ = UnsignedBaseSector_;
const double baseSectorCorr = InTrack.sectorPhi() ? -setup_->baseSector(): -setup_->baseSector();

double temp_phi0 = InTrack.phiT() - ((InTrack.inv2R()) * setup_->hybridChosenRofPhi()) + BaseSectorCorr_;
double temp_phi0 = InTrack.phiT() - ((InTrack.inv2R()) * setup_->hybridChosenRofPhi()) + baseSectorCorr;

double temp_tanL = cotBins_[InTrack.sectorEta()] + InTrack.cot();
double temp_tanL = InTrack.cotGlobal();

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);
const auto& stub = streamsStubs[setup_->numLayers()*iLink+iStub].at(iTrack);
StubKF InStub(stub,dataFormats_,iStub);

if (stub.first.isNonnull()){
HitPattern.set(iStub);
if (!stub.first.isNonnull())
continue;

double phiSquared = InStub.phi() * InStub.phi();
double zSquared = InStub.z() * InStub.z();
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 tempv0 = dPhiBins_[(InStub.dPhi()/dataFormats_->base(Variable::dPhi, Process::kfin))*setup_->weightBinFraction()];
double tempv1 = dZBins_[(InStub.dZ()/dataFormats_->base(Variable::dZ, Process::kfin))*setup_->weightBinFraction()];

double tempRphi = phiSquared * tempv0;
double tempRz = zSquared * tempv1;
double tempRphi = phiSquared * tempv0;
double tempRz = zSquared * tempv1;

tempchi2rphi += tempRphi;
tempchi2rz += tempRz;
} // Iterate over track stubs

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 Chi2rphi(digitise(setup_->kfoutchi2rphiBins(),tempchi2rphi,(double)setup_->kfoutchi2rphiConv()),4,false);
TTBV Chi2rz(digitise(setup_->kfoutchi2rzBins(),tempchi2rz,(double)setup_->kfoutchi2rzConv()),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);
TTBV InvR(-InTrack.inv2R(),dataFormats_->base(Variable::inv2R,Process::kf) ,16,true );
InvR.resize(15);
// 13 + 3 + 7 + 3 + 3
TTBV PartialTrack3((D0 + BendChi2 + HitPattern + TQMVA + extraMVA),partialTrackWordBits_,false);
// 16 + 12 + 4
TTBV PartialTrack2((TanL + z0 + Chi2rz),partialTrackWordBits_,false);
// 1 + 15 + 12 + 4
TTBV PartialTrack1((TrackValid + InvR + phi0 + Chi2rphi),partialTrackWordBits_,false);

// Sort Tracks based on eta
if (iLink % 2 == 0){
Expand Down Expand Up @@ -256,39 +231,33 @@ namespace trackFindingTracklet {
}

}
} // Tracks
} // Links

} // Iterate over Tracks
} // Iterate over Links
// Fill products and match up tracks
TTBV NullBitTrack(0,32,false);
const TTBV NullBitTrack(0,partialTrackWordBits_,false);
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
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()));
}
}
if (numLinkTracks == 0)
continue; // Don't fill links if no tracks
if ((numLinkTracks % 2 != 0)) {
SortedPartialTracks[iLink].push_back(NullBitTrack); //Pad out final set of bits
OutputStreamsTracks[iLink][numLinkTracks++] = OutputStreamsTracks[iLink][numLinkTracks]; //Pad out with final repeated track
} //If there is an odd number of tracks
for (int iTrack = 0; iTrack < (int)(SortedPartialTracks[iLink].size()); iTrack++ ){
if (iTrack % 2 != 1) // Write to links every other partial track, 3 partial tracks per full TTTrack
continue;
TTTrackRef TrackRef;
for (auto &it : ttTrackRefMap) { //Iterate through 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 <= setup_->numFramesIO()* ((double)TTBV::S_/setup_->tttrackBits()))
accepted[iLink].emplace_back(std::make_pair(TrackRef,(SortedPartialTracks[iLink][iTrack].slice(partialTrackWordBits_) + SortedPartialTracks[iLink][iTrack-1].slice(partialTrackWordBits_)).bs()));
else
lost[iLink].emplace_back(std::make_pair(TrackRef,(SortedPartialTracks[iLink][iTrack].slice(partialTrackWordBits_) + SortedPartialTracks[iLink][iTrack-1].slice(partialTrackWordBits_)).bs()));
} //Iterate through sorted partial tracks
} // Iterate through links
} // Config Supported
// store products
iEvent.emplace(edPutTokenAccepted_, move(accepted));
Expand Down
23 changes: 9 additions & 14 deletions L1Trigger/TrackTrigger/interface/Setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ namespace tt {
double maxdPhi() const { return maxdPhi_; }
// maximum representable stub z uncertainty
double maxdZ() const { return maxdZ_; }
// firmware clock / 360 MHz
double clockRatio() const { return clockRatio_; }


// Common track finding parameter

Expand Down Expand Up @@ -451,15 +448,7 @@ namespace tt {
double kfRangeFactor() const { return kfRangeFactor_; }

// Parameter specifying KalmanFilter Output Formatter

// Bins used to digitize dPhi for chi2 calculation
std::vector<int> kfoutdPhiBins() const { return kfoutdPhiBins_; }
// Bins used to digitize dZ for chi2 calculation
std::vector<int> kfoutdZBins() const { return kfoutdZBins_; }
// v0 weight Bins corresponding to dPhi Bins for chi2 calculation
std::vector<int> kfoutv0Bins() const { return kfoutv0Bins_; }
// v1 weight Bins corresponding to dZ Bins for chi2 calculation
std::vector<int> kfoutv1Bins() const { return kfoutv1Bins_; }

// Final Chi2rphi digitization TODO extract from TTTrack Word
std::vector<double> kfoutchi2rphiBins() const { return kfoutchi2rphiBins_; }
// Final Chi2rz digitization TODO extract from TTTrack Word
Expand All @@ -468,6 +457,10 @@ namespace tt {
int kfoutchi2rphiConv() const { return kfoutchi2rphiConv_; }
// Conversion factor between dz^2/weight and chi2rz
int kfoutchi2rzConv() const { return kfoutchi2rzConv_; }
// Number of bits for the tttrack word
int tttrackBits() const { return tttrackBits_; }
// Fraction of total dphi and dz ranges to calculate v0 and v1 LUT for
double weightBinFraction() const { return weightBinFraction_; }

// Parameter specifying DuplicateRemoval

Expand Down Expand Up @@ -690,8 +683,6 @@ namespace tt {
double mindZ_;
// maximum representable stub z uncertainty
double maxdZ_;
// firmware clock / 360 MHz
double clockRatio_;

// Parameter specifying front-end
edm::ParameterSet pSetFE_;
Expand Down Expand Up @@ -845,6 +836,10 @@ namespace tt {
int kfoutchi2rphiConv_;
// Conversion factor between dz^2/weight and chi2rz
int kfoutchi2rzConv_;
// Number of bits for the tttrack word
int tttrackBits_;
// Fraction of total dphi and dz ranges to calculate v0 and v1 LUT for
double weightBinFraction_;

// Parameter specifying DuplicateRemoval
edm::ParameterSet pSetDR_;
Expand Down
14 changes: 6 additions & 8 deletions L1Trigger/TrackTrigger/python/ProducerSetup_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
MaxdPhi = cms.double( 0.02 ), # maximum representable stub phi uncertainty
MindZ = cms.double( 0.1 ), # minimum representable stub z uncertainty
MaxdZ = cms.double( 30. ), # maximum representable stub z uncertainty
ClockRatio = cms.double( 0.666 ) # firmware clock / 360 MHz
),

# Parmeter specifying front-end
Expand Down Expand Up @@ -194,16 +193,15 @@

# Parmeter specifying KalmanFilter Output Formatter
KalmanFilterOut = cms.PSet (
dPhiBins = cms.vint32( 0,10,35,70,100,130,165,200,225,260,300,330,360,512 ), # Bins used to digitize dPhi for chi2 calculation
dZBins = cms.vint32( 0,100,150,233,266,300,333,366,400,433,466,500,533,566,1024), # Bins used to digitize dZ for chi2 calculation
v0Bins = cms.vint32(32716, 7139, 209, 82, 43, 26, 18, 13, 9, 7, 6, 5, 4), # v0 weight Bins corresponding to dPhi Bins for chi2 calculation
v1Bins = cms.vint32(63607, 486, 155, 121, 97, 77, 63, 52, 44, 39, 33, 29, 26, 0), # v1 weight Bins corresponding to dZ Bins for chi2 calculation

chi2rphiBins = cms.vdouble( 0, 0.25, 0.5, 1, 2, 3, 5, 7, 10, 20, 40, 100, 200, 500, 1000, 3000,6000 ), # Final Chi2rphi digitization TODO extract from TTTrack Word
chi2rzBins = cms.vdouble( 0, 0.25, 0.5, 1, 2, 3, 5, 7, 10, 20, 40, 100, 200, 500, 1000, 3000,6000 ), # Final Chi2rz digitization TODO extract from TTTrack Word

chi2rphiConv = cms.int32 ( 537600 ), # Conversion factor between dphi^2/weight and chi2rphi
chi2rzConv = cms.int32 ( 641024 ), # Conversion factor between dz^2/weight and chi2rz
chi2rphiConv = cms.int32 ( 1 ), # Conversion factor between dphi^2/weight and chi2rphi
chi2rzConv = cms.int32 ( 1 ), # Conversion factor between dz^2/weight and chi2rz

WeightBinFraction = cms.double( 0.5 ), # Fraction of total dphi and dz ranges to calculate v0 and v1 LUT for

TTTrackBits = cms.int32( 96 ) # Number of bits for the tttrack word TODO extract from TTTrack_word dataformat
),

# Parmeter specifying DuplicateRemoval
Expand Down
7 changes: 2 additions & 5 deletions L1Trigger/TrackTrigger/src/Setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ namespace tt {
maxdPhi_(pSetFW_.getParameter<double>("MaxdPhi")),
mindZ_(pSetFW_.getParameter<double>("MindZ")),
maxdZ_(pSetFW_.getParameter<double>("MaxdZ")),
clockRatio_(pSetFW_.getParameter<double>("ClockRatio")),
// Parmeter specifying front-end
pSetFE_(iConfig.getParameter<ParameterSet>("FrontEnd")),
widthBend_(pSetFE_.getParameter<int>("WidthBend")),
Expand Down Expand Up @@ -190,14 +189,12 @@ namespace tt {
kfRangeFactor_(pSetKF_.getParameter<double>("RangeFactor")),
// Parmeter specifying KalmanFilter Output Formatter
pSetKFOut_(iConfig.getParameter<ParameterSet>("KalmanFilterOut")),
kfoutdPhiBins_(pSetKFOut_.getParameter<vector<int>>("dPhiBins")),
kfoutdZBins_(pSetKFOut_.getParameter<vector<int>>("dZBins")),
kfoutv0Bins_(pSetKFOut_.getParameter<vector<int>>("v0Bins")),
kfoutv1Bins_(pSetKFOut_.getParameter<vector<int>>("v1Bins")),
kfoutchi2rphiBins_(pSetKFOut_.getParameter<vector<double>>("chi2rphiBins")),
kfoutchi2rzBins_(pSetKFOut_.getParameter<vector<double>>("chi2rzBins")),
kfoutchi2rphiConv_(pSetKFOut_.getParameter<int>("chi2rphiConv")),
kfoutchi2rzConv_(pSetKFOut_.getParameter<int>("chi2rzConv")),
tttrackBits_(pSetKFOut_.getParameter<int>("TTTrackBits")),
weightBinFraction_(pSetKFOut_.getParameter<double>("WeightBinFraction")),
// Parmeter specifying DuplicateRemoval
pSetDR_(iConfig.getParameter<ParameterSet>("DuplicateRemoval")),
drDepthMemory_(pSetDR_.getParameter<int>("DepthMemory")) {
Expand Down
2 changes: 2 additions & 0 deletions L1Trigger/TrackerTFP/interface/DataFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ namespace trackerTFP {
double cot() const { return std::get<5>(data_); }
// track z at radius chosenRofZ wrt eta sector centre
double zT() const { return std::get<6>(data_); }
// global cotTheta
double cotGlobal() const { return cot() + setup()->sectorCot(sectorEta()); }
// conversion to TTTrack with given stubs
TTTrack<Ref_Phase2TrackerDigi_> ttTrack(const std::vector<StubKF>& stubs) const;
private:
Expand Down

0 comments on commit ef3edb7

Please sign in to comment.