84 kPtSize = TTTrack_TrackWord::TrackBitWidths::kRinvSize - 1,
86 kEtaSize = TTTrack_TrackWord::TrackBitWidths::kTanlSize,
133 ap_fixed<TrackBitWidths::kEtaSize, TrackBitWidths::kEtaMagSize> etaEmulation;
134 etaEmulation.V = etaEmulationBits.range();
143 ap_uint<TrackBitWidths::kPtSize> ptEmulationBits =
t.getTrackWord()(
144 TTTrack_TrackWord::TrackBitLocations::kRinvMSB - 1, TTTrack_TrackWord::TrackBitLocations::kRinvLSB);
145 ap_ufixed<TrackBitWidths::kPtSize, TrackBitWidths::kPtMagSize> ptEmulation;
146 ptEmulation.V = ptEmulationBits.range();
157 const double AssociationThreshold,
158 const std::vector<double>& AssociationNetworkZ0binning,
159 const std::vector<double>& AssociationNetworkEtaBounds,
160 const std::vector<double>& AssociationNetworkZ0ResBins)
165 res_bins_(AssociationNetworkZ0ResBins) {}
168 tensorflow::Tensor inputAssoc(tensorflow::DT_FLOAT, {1, 4});
169 std::vector<tensorflow::Tensor> outputAssoc;
172 ap_fixed<16, 3> etaEmulation;
173 etaEmulation.V = (etaEmulationBits.range());
184 ap_uint<14> ptEmulationBits =
t.getTrackWord()(TTTrack_TrackWord::TrackBitLocations::kRinvMSB - 1,
185 TTTrack_TrackWord::TrackBitLocations::kRinvLSB);
186 ap_ufixed<14, 9> ptEmulation;
187 ptEmulation.V = (ptEmulationBits.range());
189 ap_ufixed<22, 9> ptEmulation_rescale;
190 ptEmulation_rescale = ptEmulation.to_double();
192 ap_ufixed<22, 9> resBinEmulation_rescale;
193 resBinEmulation_rescale =
res_bins_[resbin];
195 ap_ufixed<22, 9> MVAEmulation_rescale;
196 MVAEmulation_rescale =
t.getMVAQualityBits();
198 ap_ufixed<22, 9> dZEmulation_rescale;
199 dZEmulation_rescale =
dZ;
201 inputAssoc.tensor<
float, 2>()(0, 0) = ptEmulation_rescale.to_double();
202 inputAssoc.tensor<
float, 2>()(0, 1) = MVAEmulation_rescale.to_double();
203 inputAssoc.tensor<
float, 2>()(0, 2) = resBinEmulation_rescale.to_double() / 16.0;
204 inputAssoc.tensor<
float, 2>()(0, 3) = dZEmulation_rescale.to_double();
209 double NNOutput = (double)outputAssoc[0].tensor<float, 2>()(0, 0);
211 double NNOutput_exp = 1.0 / (1.0 +
exp(-1.0 * (NNOutput)));
249 log <<
"Processed track link counters:\t[";
256 log <<
"Truncated track link counters:\t[";
300 : processSimulatedTracks_(iConfig.getParameter<
bool>(
"processSimulatedTracks")),
301 processEmulatedTracks_(iConfig.getParameter<
bool>(
"processEmulatedTracks")),
303 l1VerticesToken_(processSimulatedTracks_
306 l1SelectedTracksToken_(
307 processSimulatedTracks_
310 l1VerticesEmulationToken_(
311 processEmulatedTracks_
314 l1SelectedTracksEmulationToken_(processEmulatedTracks_
316 "l1SelectedTracksEmulationInputTag"))
318 outputCollectionName_(iConfig.getParameter<
std::
string>(
"outputCollectionName")),
321 deltaZMaxEtaBounds_(cutSet_.getParameter<
std::
vector<double>>(
"deltaZMaxEtaBounds")),
322 deltaZMax_(cutSet_.getParameter<
std::
vector<double>>(
"deltaZMax")),
323 useDisplacedTracksDeltaZOverride_(iConfig.getParameter<double>(
"useDisplacedTracksDeltaZOverride")),
324 fwNTrackSetsTVA_(iConfig.getParameter<unsigned
int>(
"fwNTrackSetsTVA")),
325 associationThreshold_(iConfig.getParameter<double>(
"associationThreshold")),
326 useAssociationNetwork_(iConfig.getParameter<
bool>(
"useAssociationNetwork")),
327 associationNetworkZ0binning_(iConfig.getParameter<
std::
vector<double>>(
"associationNetworkZ0binning")),
328 associationNetworkEtaBounds_(iConfig.getParameter<
std::
vector<double>>(
"associationNetworkEtaBounds")),
329 associationNetworkZ0ResBins_(iConfig.getParameter<
std::
vector<double>>(
"associationNetworkZ0ResBins")),
330 debug_(iConfig.getParameter<
int>(
"debug")) {
338 throw cms::Exception(
"You must process at least one of the track collections (simulated or emulated).");
342 throw cms::Exception(
"The number of deltaZ cuts does not match the number of eta bins!");
369 log <<
"The original selected track collection (pt, eta, phi, nstub, bendchi2, chi2rz, chi2rphi, z0) values are " 371 for (
const auto&
track : *l1SelectedTracksHandle) {
374 log <<
"\t---\n\tNumber of tracks in this selection = " << l1SelectedTracksHandle->size() <<
"\n\n";
377 log <<
"The original selected emulated track collection (pt, eta, phi, nstub, bendchi2, chi2rz, chi2rphi, z0) " 379 for (
const auto&
track : *l1SelectedTracksEmulationHandle) {
382 log <<
"\t---\n\tNumber of tracks in this selection = " << l1SelectedTracksEmulationHandle->size() <<
"\n\n";
388 l1SelectedTracksHandle->
end(),
389 l1SelectedTracksEmulationHandle->
begin(),
390 l1SelectedTracksEmulationHandle->
end(),
391 std::back_inserter(inSimButNotEmu));
393 l1SelectedTracksEmulationHandle->
end(),
394 l1SelectedTracksHandle->
begin(),
395 l1SelectedTracksHandle->
end(),
396 std::back_inserter(inEmuButNotSim));
397 log <<
"The set of tracks selected via cuts on the simulated values which are not in the set of tracks selected " 398 "by cutting on the emulated values ... \n";
399 for (
const auto&
track : inSimButNotEmu) {
402 log <<
"\t---\n\tNumber of tracks in this selection = " << inSimButNotEmu.size() <<
"\n\n" 403 <<
"The set of tracks selected via cuts on the emulated values which are not in the set of tracks selected " 404 "by cutting on the simulated values ... \n";
405 for (
const auto&
track : inEmuButNotSim) {
408 log <<
"\t---\n\tNumber of tracks in this selection = " << inEmuButNotSim.size() <<
"\n\n";
411 log <<
"The selected and leading vertex associated track collection (pt, eta, phi, nstub, bendchi2, chi2rz, " 412 "chi2rphi, z0) values are ... \n";
413 for (
const auto&
track : *vTTTrackAssociatedOutput) {
416 log <<
"\t---\n\tNumber of tracks in this selection = " << vTTTrackAssociatedOutput->size() <<
"\n\n";
419 log <<
"The emulation selected and leading vertex associated track collection (pt, eta, phi, nstub, bendchi2, " 420 "chi2rz, chi2rphi, z0) values are " 422 for (
const auto&
track : *vTTTrackAssociatedEmulationOutput) {
425 log <<
"\t---\n\tNumber of tracks in this selection = " << vTTTrackAssociatedEmulationOutput->size() <<
"\n\n";
431 vTTTrackAssociatedOutput->end(),
432 vTTTrackAssociatedEmulationOutput->begin(),
433 vTTTrackAssociatedEmulationOutput->end(),
434 std::back_inserter(inSimButNotEmu));
436 vTTTrackAssociatedEmulationOutput->end(),
437 vTTTrackAssociatedOutput->begin(),
438 vTTTrackAssociatedOutput->end(),
439 std::back_inserter(inEmuButNotSim));
440 log <<
"The set of vertex associated tracks selected via cuts on the simulated values which are not in the set of " 442 "by cutting on the emulated values ... \n";
443 for (
const auto&
track : inSimButNotEmu) {
446 log <<
"\t---\n\tNumber of tracks in this selection = " << inSimButNotEmu.size() <<
"\n\n" 447 <<
"The set of vertex associated tracks selected via cuts on the emulated values which are not in the set of " 449 "by cutting on the simulated values ... \n";
450 for (
const auto&
track : inEmuButNotSim) {
453 log <<
"\t---\n\tNumber of tracks in this selection = " << inEmuButNotSim.size() <<
"\n\n";
459 bool printEmulation)
const {
460 log <<
"\t(" <<
track.momentum().perp() <<
", " <<
track.momentum().eta() <<
", " <<
track.momentum().phi() <<
", " 461 <<
track.getStubRefs().size() <<
", " <<
track.stubPtConsistency() <<
", " <<
track.chi2ZRed() <<
", " 462 <<
track.chi2XYRed() <<
", " <<
track.z0() <<
")\n";
464 if (printEmulation) {
465 ap_uint<TrackBitWidths::kPtSize> ptEmulationBits =
track.getTrackWord()(
466 TTTrack_TrackWord::TrackBitLocations::kRinvMSB - 1, TTTrack_TrackWord::TrackBitLocations::kRinvLSB);
467 ap_ufixed<TrackBitWidths::kPtSize, TrackBitWidths::kPtMagSize> ptEmulation;
468 ptEmulation.V = ptEmulationBits.range();
470 ap_fixed<TrackBitWidths::kEtaSize, TrackBitWidths::kEtaMagSize> etaEmulation;
471 etaEmulation.V = etaEmulationBits.range();
472 double floatTkZ0 =
track.undigitizeSignedValue(
474 double floatTkPhi =
track.undigitizeSignedValue(
476 log <<
"\t\t(" << ptEmulation.to_double() <<
", " << etaEmulation.to_double() <<
", " << floatTkPhi <<
", " 477 <<
track.getNStubs() <<
", " <<
track.getBendChi2() <<
", " <<
track.getChi2RZ() <<
", " <<
track.getChi2RPhi()
478 <<
", " << floatTkZ0 <<
")\n";
484 auto vTTTrackAssociatedOutput = std::make_unique<TTTrackRefCollectionType>();
485 auto vTTTrackAssociatedEmulationOutput = std::make_unique<TTTrackRefCollectionType>();
509 size_t nOutputApproximate = l1TracksHandle->size();
514 leadingVertex = l1VerticesHandle->at(0);
516 edm::LogInfo(
"L1TrackVertexAssociationProducer") <<
"leading vertex z0 = " << leadingVertex.
z0();
518 vTTTrackAssociatedOutput->reserve(nOutputApproximate);
523 leadingEmulationVertex = l1VerticesEmulationHandle->at(0);
526 <<
"leading emulation vertex z0 = " << leadingEmulationVertex.
z0();
528 vTTTrackAssociatedEmulationOutput->reserve(nOutputApproximate);
530 for (
size_t i = 0;
i < nOutputApproximate;
i++) {
531 const auto&
track = l1TracksHandle->at(
i);
534 bool passLinkLimit = linkLimitSel(
track);
536 auto itr = std::find_if(l1SelectedTracksHandle->
begin(), l1SelectedTracksHandle->
end(), [
track](
const auto& ref) {
537 return (*ref).getTrackWord() ==
track.getTrackWord();
539 bool passSelection = (itr != l1SelectedTracksHandle->
end());
541 if (passLinkLimit && passSelection && deltaZSel(
track, leadingVertex)) {
542 vTTTrackAssociatedOutput->push_back(
TTTrackRef(l1TracksHandle,
i));
547 bool passLinkLimitEmu = linkLimitSelEmu(
track);
549 auto itrEmu = std::find_if(l1SelectedTracksEmulationHandle->
begin(),
550 l1SelectedTracksEmulationHandle->
end(),
551 [
track](
const auto& ref) {
return (*ref).getTrackWord() ==
track.getTrackWord(); });
552 bool passSelectionEmu = (itrEmu != l1SelectedTracksEmulationHandle->
end());
555 if (passLinkLimitEmu && passSelectionEmu && TTTrackNetworkSelector(
track, l1VerticesEmulationHandle->at(0))) {
556 vTTTrackAssociatedEmulationOutput->push_back(
TTTrackRef(l1TracksHandle,
i));
559 if (passLinkLimitEmu && passSelectionEmu && deltaZSelEmu(
track, l1VerticesEmulationHandle->at(0))) {
560 vTTTrackAssociatedEmulationOutput->push_back(
TTTrackRef(l1TracksHandle,
i));
568 l1SelectedTracksEmulationHandle,
569 vTTTrackAssociatedOutput,
570 vTTTrackAssociatedEmulationOutput);
580 linkLimitSelEmu.
log();
589 edm::InputTag(
"l1tTrackSelectionProducer",
"Level1TTTracksSelected"));
591 edm::InputTag(
"l1tTrackSelectionProducer",
"Level1TTTracksSelectedEmulation"));
594 edm::InputTag(
"l1tVertexFinderEmulator",
"L1VerticesEmulation"));
595 desc.add<
std::string>(
"outputCollectionName",
"Level1TTTracksSelectedAssociated");
598 descCutSet.
add<std::vector<double>>(
"deltaZMaxEtaBounds", {0.0, 0.7, 1.0, 1.2, 1.6, 2.0, 2.4})
599 ->setComment(
"these values define the bin boundaries in |eta|");
600 descCutSet.
add<std::vector<double>>(
"deltaZMax", {0.37, 0.50, 0.60, 0.75, 1.00, 1.60})
602 "delta z must be less than these values, there will be one less value here than in deltaZMaxEtaBounds, " 606 desc.add<
double>(
"useDisplacedTracksDeltaZOverride", -1.0)
607 ->setComment(
"override the deltaZ cut value for displaced tracks");
608 desc.add<
bool>(
"processSimulatedTracks",
true)
609 ->setComment(
"return selected tracks after cutting on the floating point values");
610 desc.add<
bool>(
"processEmulatedTracks",
true)
611 ->setComment(
"return selected tracks after cutting on the bitwise emulated values");
612 desc.add<
unsigned int>(
"fwNTrackSetsTVA", 94)->setComment(
"firmware limit on processed tracks per GTT input link");
613 desc.add<
bool>(
"useAssociationNetwork",
false)->setComment(
"Enable Association Network");
614 desc.add<
double>(
"associationThreshold", 0)->setComment(
"Association Network threshold for PV tracks");
615 desc.addOptional<
edm::FileInPath>(
"associationGraph")->setComment(
"Location of Association Network model file");
616 desc.add<std::vector<double>>(
"associationNetworkZ0binning", {})
617 ->setComment(
"z0 binning used for setting the input feature digitisation");
618 desc.add<std::vector<double>>(
"associationNetworkEtaBounds", {})
619 ->setComment(
"Eta bounds used to set z0 resolution input feature");
620 desc.add<std::vector<double>>(
"associationNetworkZ0ResBins", {})->setComment(
"z0 resolution input feature bins");
622 desc.add<
int>(
"debug", 0)->setComment(
"Verbosity levels: 0, 1, 2, 3");
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
std::vector< double > associationNetworkEtaBounds_
T getParameter(std::string const &) const
std::vector< double > deltaZMax_
const edm::EDGetTokenT< TTTrackCollectionType > l1TracksToken_
void printTrackInfo(edm::LogInfo &log, const TTTrackType &track, bool printEmulation=false) const
bool operator()(const TTTrackType &t, const l1t::VertexWord &v) const
tensorflow::GraphDef * associationGraph_
TTTrackWordLinkLimitSelector(const edm::ParameterSet &cfg)
L1TrackVertexAssociationProducer(const edm::ParameterSet &)
std::string fullPath() const
std::vector< double > associationNetworkZ0ResBins_
TTTrackDeltaZMaxSelector(const std::vector< double > &deltaZMaxEtaBounds, const std::vector< double > &deltaZMax)
std::vector< double > associationNetworkZ0binning_
GraphDef * loadGraphDef(const std::string &pbFile)
tensorflow::Session * associationSesh_
std::vector< unsigned int > processedTracksPerLink_
TTTrackDeltaZMaxSelector(const edm::ParameterSet &cfg)
bool operator()(const TTTrackType &t, const l1t::Vertex &v) const
std::vector< double > deltaZMaxEtaBounds_
~L1TrackVertexAssociationProducer() override
const std::string outputCollectionName_
const bool processEmulatedTracks_
const edm::ParameterSet cutSet_
std::vector< double > z0_binning_
std::vector< Vertex > VertexCollection
const double useDisplacedTracksDeltaZOverride_
const edm::EDGetTokenT< l1t::VertexCollection > l1VerticesToken_
const edm::EDGetTokenT< TTTrackRefCollectionType > l1SelectedTracksToken_
std::vector< double > eta_bins_
tensorflow::Session * AssociationSesh_
TTTrackWordDeltaZMaxSelector(const std::vector< double > &deltaZMaxEtaBounds, const std::vector< double > &deltaZMax)
const unsigned int fwNTrackSetsTVA_
ap_fixed< VertexBitWidths::kZ0Size, VertexBitWidths::kZ0MagSize, AP_RND_CONV, AP_SAT > vtxz0_t
edm::Handle< TTTrackCollectionType > TTTrackCollectionHandle
double AssociationThreshold_
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
TTTrackWordLinkLimitSelector(const unsigned int fwNTrackSetsTVA)
unsigned int gttLinkID(T track)
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Abs< T >::type abs(const T &t)
def template(fileName, svg, replaceme="REPLACEME")
std::vector< unsigned int > truncatedTracksPerLink_
#define DEFINE_FWK_MODULE(type)
std::vector< VertexWord > VertexWordCollection
std::vector< double > res_bins_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
bool operator()(const TTTrackType &t)
unsigned int fwNTrackSetsTVA_
const double associationThreshold_
TTTrackWordDeltaZMaxSelector(const edm::ParameterSet &cfg)
edm::FileInPath associationGraphPath_
Session * createSession()
Log< level::Info, false > LogInfo
std::vector< double > deltaZMax_
Class to store the L1 Track Trigger tracks.
const_iterator end() const
Termination of iteration.
void printDebugInfo(const edm::Handle< TTTrackRefCollectionType > &l1SelectedTracksHandle, const edm::Handle< TTTrackRefCollectionType > &l1SelectedTracksEmulationHandle, const TTTrackRefCollectionUPtr &vTTTrackAssociatedOutput, const TTTrackRefCollectionUPtr &vTTTrackAssociatedEmulationOutput) const
std::vector< double > deltaZMaxEtaBounds_
static constexpr double stepPhi0
bool operator()(const TTTrackType &t, const l1t::VertexWord &v) const
std::vector< double > deltaZMax_
std::vector< double > deltaZMaxEtaBounds_
std::unique_ptr< TTTrackRefCollectionType > TTTrackRefCollectionUPtr
ap_uint< TrackBitWidths::kTanlSize > tanl_t
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool useAssociationNetwork_
const edm::EDGetTokenT< l1t::VertexWordCollection > l1VerticesEmulationToken_
edm::RefVector< TTTrackCollectionType > TTTrackRefCollectionType
const_iterator begin() const
Initialize an iterator over the RefVector.
TTTrack< Ref_Phase2TrackerDigi_ > TTTrackType
static constexpr double stepZ0
const edm::EDGetTokenT< TTTrackRefCollectionType > l1SelectedTracksEmulationToken_
const bool processSimulatedTracks_
std::vector< TTTrackType > TTTrackCollectionType
NNTrackWordSelector(tensorflow::Session *AssociationSesh, const double AssociationThreshold, const std::vector< double > &AssociationNetworkZ0binning, const std::vector< double > &AssociationNetworkEtaBounds, const std::vector< double > &AssociationNetworkZ0ResBins)