From f417fbb5762b956d80cb6bee714bf9acbd8312ee Mon Sep 17 00:00:00 2001 From: Anders Date: Thu, 2 Jan 2025 18:50:48 +0100 Subject: [PATCH 01/13] squashed my commits --- .../interface/AllProjectionsMemory.h | 37 - .../interface/CandidateMatchMemory.h | 38 - .../interface/CircularBuffer.h | 5 + .../TrackFindingTracklet/interface/FitTrack.h | 7 + .../TrackFindingTracklet/interface/Globals.h | 37 - .../interface/IMATH_TrackletCalculator.h | 476 ------- .../interface/IMATH_TrackletCalculatorDisk.h | 406 ------ .../IMATH_TrackletCalculatorOverlap.h | 429 ------ .../interface/MatchCalculator.h | 68 - .../interface/MatchEngine.h | 45 - .../interface/MatchEngineUnit.h | 6 +- .../interface/MatchProcessor.h | 17 +- .../interface/ProjectionCalculator.h | 68 + .../interface/ProjectionRouter.h | 43 - .../TrackFindingTracklet/interface/Sector.h | 39 +- .../TrackFindingTracklet/interface/Settings.h | 27 +- .../TrackFindingTracklet/interface/Stub.h | 17 +- .../interface/StubPairsMemory.h | 52 - .../TrackFindingTracklet/interface/Tracklet.h | 3 +- .../interface/TrackletCalculator.h | 43 - .../interface/TrackletCalculatorBase.h | 58 +- .../interface/TrackletConfigBuilder.h | 33 +- .../interface/TrackletEngine.h | 54 - .../interface/TrackletEngineDisplaced.h | 54 - .../interface/TrackletEventProcessor.h | 10 +- .../interface/TrackletParametersMemory.h | 13 +- .../interface/TrackletProjectionsMemory.h | 13 +- .../interface/TripletEngine.h | 70 - .../interface/VMProjectionsMemory.h | 41 - .../TrackFindingTracklet/interface/VMRouter.h | 77 -- .../interface/VMRouterCM.h | 7 +- .../interface/VMStubMERouter.h | 58 + .../interface/VMStubsMEMemory.h | 3 + .../TrackFindingTracklet/interface/imath.h | 1122 ---------------- .../plugins/L1FPGATrackProducer.cc | 4 +- .../l1tTTTracksFromTrackletEmulation_cfi.py | 2 +- .../src/AllProjectionsMemory.cc | 40 - .../src/CandidateMatchMemory.cc | 59 - .../TrackFindingTracklet/src/FitTrack.cc | 283 +++- L1Trigger/TrackFindingTracklet/src/Globals.cc | 23 - .../src/MatchCalculator.cc | 581 -------- .../TrackFindingTracklet/src/MatchEngine.cc | 302 ----- .../src/MatchEngineUnit.cc | 53 +- .../src/MatchProcessor.cc | 474 ++++--- .../TrackFindingTracklet/src/ProcessBase.cc | 7 +- .../TrackFindingTracklet/src/Projection.cc | 6 +- .../src/ProjectionCalculator.cc | 377 ++++++ .../src/ProjectionRouter.cc | 152 --- L1Trigger/TrackFindingTracklet/src/Sector.cc | 115 +- L1Trigger/TrackFindingTracklet/src/Stub.cc | 20 +- .../src/StubPairsMemory.cc | 35 - .../TrackFindingTracklet/src/Tracklet.cc | 110 +- .../src/TrackletCalculator.cc | 472 ------- .../src/TrackletCalculatorBase.cc | 1126 +++++----------- .../src/TrackletCalculatorDisplaced.cc | 19 +- .../src/TrackletConfigBuilder.cc | 1167 ++++++----------- .../src/TrackletEngine.cc | 230 ---- .../src/TrackletEngineDisplaced.cc | 422 ------ .../src/TrackletEventProcessor.cc | 128 +- .../src/TrackletParametersMemory.cc | 29 +- .../src/TrackletProcessor.cc | 55 +- .../src/TrackletProcessorDisplaced.cc | 3 +- .../src/TrackletProjectionsMemory.cc | 48 +- .../TrackFindingTracklet/src/TripletEngine.cc | 481 ------- .../src/VMProjectionsMemory.cc | 52 - .../TrackFindingTracklet/src/VMRouter.cc | 385 ------ .../TrackFindingTracklet/src/VMRouterCM.cc | 54 +- .../src/VMStubMERouter.cc | 154 +++ .../src/VMStubsMEMemory.cc | 14 +- .../src/VMStubsTEMemory.cc | 5 +- L1Trigger/TrackFindingTracklet/src/imath.cc | 439 ------- .../TrackFindingTracklet/src/imath_HLS.cc | 404 ------ .../TrackFindingTracklet/src/imath_Verilog.cc | 534 -------- .../src/imath_calculate.cc | 198 --- .../test/L1TrackNtupleMaker_cfg.py | 2 +- L1Trigger/TrackTrigger/interface/Setup.h | 16 +- .../TrackTrigger/python/ProducerSetup_cfi.py | 231 ++++ L1Trigger/TrackTrigger/src/Setup.cc | 19 +- L1Trigger/TrackerDTC/interface/Stub.h | 2 + L1Trigger/TrackerDTC/src/Stub.cc | 28 +- 80 files changed, 2642 insertions(+), 10194 deletions(-) delete mode 100644 L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/MatchEngine.h create mode 100644 L1Trigger/TrackFindingTracklet/interface/ProjectionCalculator.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/TripletEngine.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/VMRouter.h create mode 100644 L1Trigger/TrackFindingTracklet/interface/VMStubMERouter.h delete mode 100644 L1Trigger/TrackFindingTracklet/interface/imath.h delete mode 100644 L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/MatchEngine.cc create mode 100644 L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/TripletEngine.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/VMRouter.cc create mode 100644 L1Trigger/TrackFindingTracklet/src/VMStubMERouter.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/imath.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/imath_HLS.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/imath_Verilog.cc delete mode 100644 L1Trigger/TrackFindingTracklet/src/imath_calculate.cc create mode 100644 L1Trigger/TrackTrigger/python/ProducerSetup_cfi.py diff --git a/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h deleted file mode 100644 index 7f84afe390301..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_AllProjectionsMemory_h -#define L1Trigger_TrackFindingTracklet_interface_AllProjectionsMemory_h - -#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" - -#include -#include - -namespace trklet { - - class Settings; - class Tracklet; - - class AllProjectionsMemory : public MemoryBase { - public: - AllProjectionsMemory(std::string name, Settings const& settings); - - ~AllProjectionsMemory() override = default; - - void addTracklet(Tracklet* tracklet) { tracklets_.push_back(tracklet); } - - unsigned int nTracklets() const { return tracklets_.size(); } - - const Tracklet* getTracklet(unsigned int i) const { return tracklets_[i]; } - - void clean() override { tracklets_.clear(); } - - void writeAP(bool first, unsigned int iSector); - - private: - std::vector tracklets_; - - int layer_; - int disk_; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h b/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h deleted file mode 100644 index 8a20813e378d4..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_CandidateMatchMemory_h -#define L1Trigger_TrackFindingTracklet_interface_CandidateMatchMemory_h - -#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" - -#include -#include -#include - -namespace trklet { - - class Settings; - class Stub; - class L1TStub; - class Tracklet; - - class CandidateMatchMemory : public MemoryBase { - public: - CandidateMatchMemory(std::string name, Settings const& settings); - - ~CandidateMatchMemory() override = default; - - void addMatch(std::pair tracklet, const Stub* stub); - - unsigned int nMatches() const { return matches_.size(); } - - std::pair, const Stub*> getMatch(unsigned int i) { return matches_[i]; } - - void clean() override { matches_.clear(); } - - void writeCM(bool first, unsigned int iSector); - - private: - std::vector, const Stub*> > matches_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h b/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h index f00b8721b17a8..e2afd05d216a9 100644 --- a/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h +++ b/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h @@ -33,6 +33,11 @@ namespace trklet { return (((wptr_ + 1) % size_) == rptr_) || (((wptr_ + 2) % size_) == rptr_) || (((wptr_ + 3) % size_) == rptr_); } + //near full if writer ptr incremented by 1, 2, or 3 is same as read ptr + bool nearfull4() const { + return (((wptr_ + 1) % size_) == rptr_) || (((wptr_ + 2) % size_) == rptr_) || (((wptr_ + 3) % size_) == rptr_) || (((wptr_ + 4) % size_) == rptr_); + } + //Empty buffer is write ptr is same as read ptr bool empty() const { return wptr_ == rptr_; } diff --git a/L1Trigger/TrackFindingTracklet/interface/FitTrack.h b/L1Trigger/TrackFindingTracklet/interface/FitTrack.h index c7f97fdf7e51b..229abeb087943 100644 --- a/L1Trigger/TrackFindingTracklet/interface/FitTrack.h +++ b/L1Trigger/TrackFindingTracklet/interface/FitTrack.h @@ -48,10 +48,17 @@ namespace trklet { private: std::vector seedtracklet_; + std::vector fullmatch0_; std::vector fullmatch1_; std::vector fullmatch2_; std::vector fullmatch3_; std::vector fullmatch4_; + std::vector fullmatch5_; + std::vector fullmatch6_; + std::vector fullmatch7_; + std::vector fullmatch8_; + std::vector fullmatch9_; + std::vector fullmatch10_; unsigned int iSector_; diff --git a/L1Trigger/TrackFindingTracklet/interface/Globals.h b/L1Trigger/TrackFindingTracklet/interface/Globals.h index e33b6600e9ac7..11ecd48978252 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Globals.h +++ b/L1Trigger/TrackFindingTracklet/interface/Globals.h @@ -22,10 +22,6 @@ namespace trklet { class HistBase; class Settings; class TrackletLUT; - struct imathGlobals; - class IMATH_TrackletCalculator; - class IMATH_TrackletCalculatorDisk; - class IMATH_TrackletCalculatorOverlap; class Globals { public: @@ -45,21 +41,6 @@ namespace trklet { std::map& layerdiskmap() { return layerdiskmap_; } - IMATH_TrackletCalculator* ITC_L1L2() { return ITC_L1L2_.get(); } - IMATH_TrackletCalculator* ITC_L2L3() { return ITC_L2L3_.get(); } - IMATH_TrackletCalculator* ITC_L3L4() { return ITC_L3L4_.get(); } - IMATH_TrackletCalculator* ITC_L5L6() { return ITC_L5L6_.get(); } - - IMATH_TrackletCalculatorDisk* ITC_F1F2() { return ITC_F1F2_.get(); } - IMATH_TrackletCalculatorDisk* ITC_F3F4() { return ITC_F3F4_.get(); } - IMATH_TrackletCalculatorDisk* ITC_B1B2() { return ITC_B1B2_.get(); } - IMATH_TrackletCalculatorDisk* ITC_B3B4() { return ITC_B3B4_.get(); } - - IMATH_TrackletCalculatorOverlap* ITC_L1F1() { return ITC_L1F1_.get(); } - IMATH_TrackletCalculatorOverlap* ITC_L1B1() { return ITC_L1B1_.get(); } - IMATH_TrackletCalculatorOverlap* ITC_L2F1() { return ITC_L2F1_.get(); } - IMATH_TrackletCalculatorOverlap* ITC_L2B1() { return ITC_L2B1_.get(); } - std::ofstream& ofstream(std::string fname); #ifdef USEHYBRID @@ -70,24 +51,6 @@ namespace trklet { private: std::unordered_map ofstreams_; - std::unique_ptr imathGlobals_; - - // tracklet calculators - std::unique_ptr ITC_L1L2_; - std::unique_ptr ITC_L2L3_; - std::unique_ptr ITC_L3L4_; - std::unique_ptr ITC_L5L6_; - - std::unique_ptr ITC_F1F2_; - std::unique_ptr ITC_F3F4_; - std::unique_ptr ITC_B1B2_; - std::unique_ptr ITC_B3B4_; - - std::unique_ptr ITC_L1F1_; - std::unique_ptr ITC_L2F1_; - std::unique_ptr ITC_L1B1_; - std::unique_ptr ITC_L2B1_; - SLHCEvent* theEvent_{nullptr}; HistBase* theHistBase_{nullptr}; diff --git a/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h b/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h deleted file mode 100644 index 15814a40643eb..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h +++ /dev/null @@ -1,476 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculator_h -#define L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculator_h - -#include "Settings.h" -#include "imath.h" - -// -// Constants used: -// dphisector -// rmaxL6 -// zmaxD5 -// rmaxdisk -// kr, kphi1, kz -// -// rmean[], zmean[] - -namespace trklet { - class Globals; - - class IMATH_TrackletCalculator { - public: - IMATH_TrackletCalculator(Settings const& settings, imathGlobals* globals, int i1, int i2) - : settings_(settings), globals_(globals) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "============================================="; - char s[1024]; - snprintf(s, 1024, "IMATH Tracklet Calculator %i %i dphisector = %f", i1, i2, settings_.dphisector()); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, 1024, "rmaxL6 = %f, zmaxD5 = %f", settings_.rmax(5), settings_.zmax(4)); - edm::LogVerbatim("Tracklet") << s; - snprintf( - s, 1024, " stub Ks: kr, kphi1, kz = %g, %g, %g", settings_.kr(), settings_.kphi1(), settings_.kz()); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, - 1024, - " tracklet Ks: krinvpars, kphi0pars, ktpars, kzpars = %g, %g, %g, %g", - settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift()), - settings_.kphi1() * pow(2, settings_.phi0_shift()), - settings_.kz() / settings_.kr() * pow(2, settings_.t_shift()), - settings_.kz() * pow(2, settings_.z0_shift())); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, - 1024, - "layer proj Ks: kphiproj456, kphider, kzproj, kzder = %g, %g, %g, %g", - settings_.kphi1() * pow(2, settings_.SS_phiL_shift()), - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift()), - settings_.kz() * pow(2, settings_.PS_zL_shift()), - settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, - 1024, - " disk proj Ks: kphiprojdisk, kphiprojderdisk, krprojdisk, krprojderdisk = %g, %g, %g, %g", - settings_.kphi1() * pow(2, settings_.SS_phiD_shift()), - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift()), - settings_.kr() * pow(2, settings_.PS_rD_shift()), - settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())); - edm::LogVerbatim("Tracklet") << s; - edm::LogVerbatim("Tracklet") << "============================================="; - - snprintf(s, 1024, "initializing 1/dr LUT %f %f", settings_.rmean(i1 - 1), settings_.rmean(i2 - 1)); - edm::LogVerbatim("Tracklet") << s; - } - - drinv.initLUT(settings_.rmean(i2 - 1) - settings_.rmean(i1 - 1)); - r1mean.set_fval(settings_.rmean(i1 - 1)); - r2mean.set_fval(settings_.rmean(i2 - 1)); - r12mean.set_fval(settings_.rmean(i1 - 1) + settings_.rmean(i2 - 1)); - - if (i1 == 1) - z0_final.add_cut(&z0_final_L1_cut); - else - z0_final.add_cut(&z0_final_cut); - - valid_phiL_0.add_cut(&t_layer_cut); - valid_phiL_1.add_cut(&t_layer_cut); - valid_phiL_2.add_cut(&t_layer_cut); - valid_phiL_3.add_cut(&t_layer_cut); - - valid_der_phiL.add_cut(&t_layer_cut); - - valid_zL_0.add_cut(&t_layer_cut); - valid_zL_1.add_cut(&t_layer_cut); - valid_zL_2.add_cut(&t_layer_cut); - valid_zL_3.add_cut(&t_layer_cut); - - valid_der_zL.add_cut(&t_layer_cut); - - valid_phiD_0.add_cut(&t_disk_cut_left); - valid_phiD_1.add_cut(&t_disk_cut_left); - valid_phiD_2.add_cut(&t_disk_cut_left); - valid_phiD_3.add_cut(&t_disk_cut_left); - valid_phiD_4.add_cut(&t_disk_cut_left); - - valid_der_phiD.add_cut(&t_disk_cut_left); - - valid_rD_0.add_cut(&t_disk_cut_left); - valid_rD_1.add_cut(&t_disk_cut_left); - valid_rD_2.add_cut(&t_disk_cut_left); - valid_rD_3.add_cut(&t_disk_cut_left); - valid_rD_4.add_cut(&t_disk_cut_left); - - valid_der_rD.add_cut(&t_disk_cut_left); - - valid_phiD_0.add_cut(&t_disk_cut_right); - valid_phiD_1.add_cut(&t_disk_cut_right); - valid_phiD_2.add_cut(&t_disk_cut_right); - valid_phiD_3.add_cut(&t_disk_cut_right); - valid_phiD_4.add_cut(&t_disk_cut_right); - - valid_der_phiD.add_cut(&t_disk_cut_right); - - valid_rD_0.add_cut(&t_disk_cut_right); - valid_rD_1.add_cut(&t_disk_cut_right); - valid_rD_2.add_cut(&t_disk_cut_right); - valid_rD_3.add_cut(&t_disk_cut_right); - valid_rD_4.add_cut(&t_disk_cut_right); - - valid_der_rD.add_cut(&t_disk_cut_right); - } - - ~IMATH_TrackletCalculator() = default; - - Settings const& settings_; - - imathGlobals* globals_; - - //max values - const double dz_max = 50.; - const double delta0_max = 0.005; - const double a2_max = 3.; - const double a2a_max = 0.1; - const double x6a_max = 0.02; - const double x6m_max = 2.; - const double x8_max = 1.; - const double x13_max = 300.; - const double x22_max = 0.3; - const double x23_max = 200.; - const double t_max = 4.; - const double z0_max = 20.; - const double der_phiD_max = 0.002; - const double t_disk_min = 1; - const double t_disk_max = 4; - const double t_layer_max = 2.5; - - //constants - VarParam plus1{globals_, "plus1", 1., 10}; - VarParam plus2{globals_, "plus2", 2., 10}; - VarParam minus1{globals_, "minus1", -1., 10}; - - VarParam r1mean{globals_, "r1mean", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarParam r2mean{globals_, "r2mean", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarParam r12mean{globals_, "r12mean", "Kr", 2 * settings_.rmax(N_DISK - 1), settings_.kr()}; - - //inputs - VarDef r1{globals_, "r1", "Kr", settings_.drmax(), settings_.kr()}; - VarDef r2{globals_, "r2", "Kr", settings_.drmax(), settings_.kr()}; - VarDef z1{globals_, "z1", "Kz", settings_.zlength(), settings_.kz()}; - VarDef z2{globals_, "z2", "Kz", settings_.zlength(), settings_.kz()}; - - //0.75 below comes from phi range for coordinate can be larger than for sector - VarDef phi1{globals_, "phi1", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; - VarDef phi2{globals_, "phi2", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; - - VarDef rproj0{globals_, "rproj0", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarDef rproj1{globals_, "rproj1", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarDef rproj2{globals_, "rproj2", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarDef rproj3{globals_, "rproj3", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - - VarDef zproj0{globals_, "zproj0", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - VarDef zproj1{globals_, "zproj1", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - VarDef zproj2{globals_, "zproj2", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - VarDef zproj3{globals_, "zproj3", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - VarDef zproj4{globals_, "zproj4", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - - //calculations - - //tracklet - VarAdd r1abs{globals_, "r1abs", &r1, &r1mean, settings_.rmax(N_LAYER - 1)}; - VarAdd r2abs{globals_, "r2abs", &r2, &r2mean, settings_.rmax(N_LAYER - 1)}; - - VarSubtract dr{globals_, "dr", &r2, &r1}; - - //R LUT - VarInv drinv{globals_, "drinv", &dr, 0, 18, 24, 0, VarInv::mode::both}; - - VarSubtract dphi{globals_, "dphi", &phi2, &phi1, settings_.dphisector() / 4.}; - VarSubtract dz{globals_, "dz", &z2, &z1, dz_max}; - - VarMult delta0{globals_, "delta0", &dphi, &drinv, delta0_max}; - VarMult deltaZ{globals_, "deltaZ", &dz, &drinv}; - VarMult delta1{globals_, "delta1", &r1abs, &delta0}; - VarMult delta2{globals_, "delta2", &r2abs, &delta0}; - VarMult a2a{globals_, "a2a", &delta1, &delta2, a2a_max}; - VarNounits a2b{globals_, "a2b", &a2a}; - VarSubtract a2{globals_, "a2", &plus2, &a2b, a2_max}; - VarNeg a2n{globals_, "a2n", &a2}; - VarShift a{globals_, "a", &a2, 1}; - - VarAdd Rabs{globals_, "Rabs", &r1abs, &r2abs}; - VarTimesC R6{globals_, "R6", &Rabs, 1. / 6., 12}; - - VarMult x4{globals_, "x4", &R6, &delta0}; - VarMult x6a{globals_, "x6a", &delta2, &x4, 2 * x6a_max}; - VarNounits x6b{globals_, "x6b", &x6a}; - VarAdd x6m{globals_, "x6m", &minus1, &x6b, x6m_max}; - VarMult phi0a{globals_, "phi0a", &delta1, &x6m, settings_.dphisector()}; - - VarMult z0a{globals_, "z0a", &r1abs, &deltaZ, settings_.zlength()}; - VarMult z0b{globals_, "z0b", &z0a, &x6m, settings_.zlength()}; - - VarAdd phi0{globals_, "phi0", &phi1, &phi0a, 2 * settings_.dphisector()}; - VarMult rinv{globals_, "rinv", &a2n, &delta0, 2 * settings_.maxrinv()}; - VarMult t{globals_, "t", &a, &deltaZ, t_max}; - VarAdd z0{globals_, "z0", &z1, &z0b, 2 * z0_max}; - - VarAdjustK rinv_final{ - globals_, "rinv_final", &rinv, settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift())}; - VarAdjustK phi0_final{globals_, "phi0_final", &phi0, settings_.kphi1() * pow(2, settings_.phi0_shift())}; - VarAdjustKR t_final{globals_, "t_final", &t, settings_.kz() / settings_.kr() * pow(2, settings_.t_shift())}; - VarAdjustKR z0_final{globals_, "z0_final", &z0, settings_.kz() * pow(2, settings_.z0_shift())}; - - //projection to r - VarShift x2{globals_, "x2", &delta0, 1}; - - VarMult x1_0{globals_, "x1_0", &x2, &rproj0}; - VarMult x1_1{globals_, "x1_1", &x2, &rproj1}; - VarMult x1_2{globals_, "x1_2", &x2, &rproj2}; - VarMult x1_3{globals_, "x1_3", &x2, &rproj3}; - - VarMult x8_0{globals_, "x8_0", &x1_0, &a2n, x8_max}; - VarMult x8_1{globals_, "x8_1", &x1_1, &a2n, x8_max}; - VarMult x8_2{globals_, "x8_2", &x1_2, &a2n, x8_max}; - VarMult x8_3{globals_, "x8_3", &x1_3, &a2n, x8_max}; - - VarMult x12_0{globals_, "x12_0", &x8_0, &x8_0}; - VarMult x12_1{globals_, "x12_1", &x8_1, &x8_1}; - VarMult x12_2{globals_, "x12_2", &x8_2, &x8_2}; - VarMult x12_3{globals_, "x12_3", &x8_3, &x8_3}; - - VarNounits x12A_0{globals_, "x12A_0", &x12_0}; - VarNounits x12A_1{globals_, "x12A_1", &x12_1}; - VarNounits x12A_2{globals_, "x12A_2", &x12_2}; - VarNounits x12A_3{globals_, "x12A_3", &x12_3}; - - VarTimesC x20_0{globals_, "x20_0", &x12A_0, 1. / 6.}; - VarTimesC x20_1{globals_, "x20_1", &x12A_1, 1. / 6.}; - VarTimesC x20_2{globals_, "x20_2", &x12A_2, 1. / 6.}; - VarTimesC x20_3{globals_, "x20_3", &x12A_3, 1. / 6.}; - - VarAdd x10_0{globals_, "x10_0", &plus1, &x20_0}; - VarAdd x10_1{globals_, "x10_1", &plus1, &x20_1}; - VarAdd x10_2{globals_, "x10_2", &plus1, &x20_2}; - VarAdd x10_3{globals_, "x10_3", &plus1, &x20_3}; - - VarMult x22_0{globals_, "x22_0", &x8_0, &x10_0, 2 * x22_max}; - VarMult x22_1{globals_, "x22_1", &x8_1, &x10_1, 2 * x22_max}; - VarMult x22_2{globals_, "x22_2", &x8_2, &x10_2, 2 * x22_max}; - VarMult x22_3{globals_, "x22_3", &x8_3, &x10_3, 2 * x22_max}; - - VarSubtract phiL_0{globals_, "phiL_0", &phi0_final, &x22_0, -1, phi0_final.nbits() + 1}; - VarSubtract phiL_1{globals_, "phiL_1", &phi0_final, &x22_1, -1, phi0_final.nbits() + 1}; - VarSubtract phiL_2{globals_, "phiL_2", &phi0_final, &x22_2, -1, phi0_final.nbits() + 1}; - VarSubtract phiL_3{globals_, "phiL_3", &phi0_final, &x22_3, -1, phi0_final.nbits() + 1}; - - VarShift x3{globals_, "x3", &rinv, 1}; - VarNeg der_phiL{globals_, "der_phiL", &x3}; - - VarAdjustK phiL_0_final{globals_, "phiL_0_final", &phiL_0, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; - VarAdjustK phiL_1_final{globals_, "phiL_1_final", &phiL_1, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; - VarAdjustK phiL_2_final{globals_, "phiL_2_final", &phiL_2, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; - VarAdjustK phiL_3_final{globals_, "phiL_3_final", &phiL_3, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; - - VarAdjustK der_phiL_final{globals_, - "der_phiL_final", - &der_phiL, - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift())}; - - VarMult x11_0{globals_, "x11_0", &rproj0, &t}; - VarMult x11_1{globals_, "x11_1", &rproj1, &t}; - VarMult x11_2{globals_, "x11_2", &rproj2, &t}; - VarMult x11_3{globals_, "x11_3", &rproj3, &t}; - - VarMult x23_0{globals_, "x23_0", &x11_0, &x10_0, 2 * x23_max}; - VarMult x23_1{globals_, "x23_1", &x11_1, &x10_1, 2 * x23_max}; - VarMult x23_2{globals_, "x23_2", &x11_2, &x10_2, 2 * x23_max}; - VarMult x23_3{globals_, "x23_3", &x11_3, &x10_3, 2 * x23_max}; - - VarAdd zL_0{globals_, "zL_0", &z0, &x23_0}; - VarAdd zL_1{globals_, "zL_1", &z0, &x23_1}; - VarAdd zL_2{globals_, "zL_2", &z0, &x23_2}; - VarAdd zL_3{globals_, "zL_3", &z0, &x23_3}; - - VarAdjustKR zL_0_final{globals_, "zL_0_final", &zL_0, settings_.kz() * pow(2, settings_.PS_zL_shift())}; - VarAdjustKR zL_1_final{globals_, "zL_1_final", &zL_1, settings_.kz() * pow(2, settings_.PS_zL_shift())}; - VarAdjustKR zL_2_final{globals_, "zL_2_final", &zL_2, settings_.kz() * pow(2, settings_.PS_zL_shift())}; - VarAdjustKR zL_3_final{globals_, "zL_3_final", &zL_3, settings_.kz() * pow(2, settings_.PS_zL_shift())}; - - VarAdjustK der_zL_final{ - globals_, "der_zL_final", &t_final, settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())}; - - //projection to z - // - VarInv invt{globals_, "invt", &t_final, 0., 18, 26, 1, VarInv::mode::both, 13}; - - VarMult x7{globals_, "x7", &x2, &a2}; - - VarSubtract x5_0{globals_, "x5_0", &zproj0, &z0}; - VarSubtract x5_1{globals_, "x5_1", &zproj1, &z0}; - VarSubtract x5_2{globals_, "x5_2", &zproj2, &z0}; - VarSubtract x5_3{globals_, "x5_3", &zproj3, &z0}; - VarSubtract x5_4{globals_, "x5_4", &zproj4, &z0}; - - VarMult x13_0{globals_, "x13_0", &x5_0, &invt, x13_max}; - VarMult x13_1{globals_, "x13_1", &x5_1, &invt, x13_max}; - VarMult x13_2{globals_, "x13_2", &x5_2, &invt, x13_max}; - VarMult x13_3{globals_, "x13_3", &x5_3, &invt, x13_max}; - VarMult x13_4{globals_, "x13_4", &x5_4, &invt, x13_max}; - - VarMult x25_0{globals_, "x25_0", &x13_0, &x7, 2 * settings_.dphisector()}; - VarMult x25_1{globals_, "x25_1", &x13_1, &x7, 2 * settings_.dphisector()}; - VarMult x25_2{globals_, "x25_2", &x13_2, &x7, 2 * settings_.dphisector()}; - VarMult x25_3{globals_, "x25_3", &x13_3, &x7, 2 * settings_.dphisector()}; - VarMult x25_4{globals_, "x25_4", &x13_4, &x7, 2 * settings_.dphisector()}; - - VarAdd phiD_0{globals_, "phiD_0", &phi0, &x25_0, 2 * settings_.dphisector()}; - VarAdd phiD_1{globals_, "phiD_1", &phi0, &x25_1, 2 * settings_.dphisector()}; - VarAdd phiD_2{globals_, "phiD_2", &phi0, &x25_2, 2 * settings_.dphisector()}; - VarAdd phiD_3{globals_, "phiD_3", &phi0, &x25_3, 2 * settings_.dphisector()}; - VarAdd phiD_4{globals_, "phiD_4", &phi0, &x25_4, 2 * settings_.dphisector()}; - - VarAdjustK phiD_0_final{globals_, "phiD_0_final", &phiD_0, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - VarAdjustK phiD_1_final{globals_, "phiD_1_final", &phiD_1, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - VarAdjustK phiD_2_final{globals_, "phiD_2_final", &phiD_2, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - VarAdjustK phiD_3_final{globals_, "phiD_3_final", &phiD_3, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - VarAdjustK phiD_4_final{globals_, "phiD_4_final", &phiD_4, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - - VarMult der_phiD{globals_, "der_phiD", &x7, &invt, 4 * der_phiD_max}; - - VarAdjustK der_phiD_final{globals_, - "der_phiD_final", - &der_phiD, - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift())}; - - VarMult x26_0{globals_, "x26_0", &x25_0, &x25_0}; - VarMult x26_1{globals_, "x26_1", &x25_1, &x25_1}; - VarMult x26_2{globals_, "x26_2", &x25_2, &x25_2}; - VarMult x26_3{globals_, "x26_3", &x25_3, &x25_3}; - VarMult x26_4{globals_, "x26_4", &x25_4, &x25_4}; - - VarNounits x26A_0{globals_, "x26A_0", &x26_0}; - VarNounits x26A_1{globals_, "x26A_1", &x26_1}; - VarNounits x26A_2{globals_, "x26A_2", &x26_2}; - VarNounits x26A_3{globals_, "x26A_3", &x26_3}; - VarNounits x26A_4{globals_, "x26A_4", &x26_4}; - - VarTimesC x9_0{globals_, "x9_0", &x26A_0, 1. / 6.}; - VarTimesC x9_1{globals_, "x9_1", &x26A_1, 1. / 6.}; - VarTimesC x9_2{globals_, "x9_2", &x26A_2, 1. / 6.}; - VarTimesC x9_3{globals_, "x9_3", &x26A_3, 1. / 6.}; - VarTimesC x9_4{globals_, "x9_4", &x26A_4, 1. / 6.}; - - VarSubtract x27m_0{globals_, "x27_0", &plus1, &x9_0}; - VarSubtract x27m_1{globals_, "x27_1", &plus1, &x9_1}; - VarSubtract x27m_2{globals_, "x27_2", &plus1, &x9_2}; - VarSubtract x27m_3{globals_, "x27_3", &plus1, &x9_3}; - VarSubtract x27m_4{globals_, "x27_4", &plus1, &x9_4}; - - VarMult rD_0{globals_, "rD_0", &x13_0, &x27m_0, 2 * settings_.rmaxdisk()}; - VarMult rD_1{globals_, "rD_1", &x13_1, &x27m_1, 2 * settings_.rmaxdisk()}; - VarMult rD_2{globals_, "rD_2", &x13_2, &x27m_2, 2 * settings_.rmaxdisk()}; - VarMult rD_3{globals_, "rD_3", &x13_3, &x27m_3, 2 * settings_.rmaxdisk()}; - VarMult rD_4{globals_, "rD_4", &x13_4, &x27m_4, 2 * settings_.rmaxdisk()}; - - VarAdjustK rD_0_final{globals_, "rD_0_final", &rD_0, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - VarAdjustK rD_1_final{globals_, "rD_1_final", &rD_1, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - VarAdjustK rD_2_final{globals_, "rD_2_final", &rD_2, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - VarAdjustK rD_3_final{globals_, "rD_3_final", &rD_3, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - VarAdjustK rD_4_final{globals_, "rD_4_final", &rD_4, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - - VarAdjustK der_rD_final{ - globals_, "der_rD_final", &invt, settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())}; - - VarCut rinv_final_cut{globals_, &rinv_final, -settings_.rinvcut(), settings_.rinvcut()}; - // the following two are not associated with any variable yet; this is done - // in the constructor of this class since it depends on the layer - VarCut z0_final_L1_cut{globals_, -settings_.z0cut(), settings_.z0cut()}; - VarCut z0_final_cut{globals_, -1.5 * settings_.z0cut(), 1.5 * settings_.z0cut()}; - - VarCut r1abs_cut{globals_, &r1abs, -settings_.rmax(5), settings_.rmax(5)}; - VarCut r2abs_cut{globals_, &r2abs, -settings_.rmax(5), settings_.rmax(5)}; - VarCut dphi_cut{globals_, &dphi, -settings_.dphisector() / 4., settings_.dphisector() / 4.}; - VarCut dz_cut{globals_, &dz, -dz_max, dz_max}; - VarCut delta0_cut{globals_, &delta0, -delta0_max, delta0_max}; - VarCut a2a_cut{globals_, &a2a, -a2a_max, a2a_max}; - VarCut a2_cut{globals_, &a2, -a2_max, a2_max}; - VarCut x6a_cut{globals_, &x6a, -x6a_max, x6a_max}; - VarCut x6m_cut{globals_, &x6m, -x6m_max, x6m_max}; - VarCut phi0a_cut{globals_, &phi0a, -settings_.dphisector(), settings_.dphisector()}; - VarCut z0a_cut{globals_, &z0a, (-1) * settings_.zlength(), settings_.zlength()}; - VarCut phi0_cut{globals_, &phi0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut rinv_cut{globals_, &rinv, -settings_.maxrinv(), settings_.maxrinv()}; - VarCut t_cut{globals_, &t, -t_max, t_max}; - VarCut z0_cut{globals_, &z0, -z0_max, z0_max}; - VarCut x8_0_cut{globals_, &x8_0, -x8_max, x8_max}; - VarCut x8_1_cut{globals_, &x8_1, -x8_max, x8_max}; - VarCut x8_2_cut{globals_, &x8_2, -x8_max, x8_max}; - VarCut x8_3_cut{globals_, &x8_3, -x8_max, x8_max}; - VarCut x22_0_cut{globals_, &x22_0, -x22_max, x22_max}; - VarCut x22_1_cut{globals_, &x22_1, -x22_max, x22_max}; - VarCut x22_2_cut{globals_, &x22_2, -x22_max, x22_max}; - VarCut x22_3_cut{globals_, &x22_3, -x22_max, x22_max}; - VarCut x23_0_cut{globals_, &x23_0, -x23_max, x23_max}; - VarCut x23_1_cut{globals_, &x23_1, -x23_max, x23_max}; - VarCut x23_2_cut{globals_, &x23_2, -x23_max, x23_max}; - VarCut x23_3_cut{globals_, &x23_3, -x23_max, x23_max}; - VarCut x13_0_cut{globals_, &x13_0, -x13_max, x13_max}; - VarCut x13_1_cut{globals_, &x13_1, -x13_max, x13_max}; - VarCut x13_2_cut{globals_, &x13_2, -x13_max, x13_max}; - VarCut x13_3_cut{globals_, &x13_3, -x13_max, x13_max}; - VarCut x13_4_cut{globals_, &x13_4, -x13_max, x13_max}; - VarCut x25_0_cut{globals_, &x25_0, -settings_.dphisector(), settings_.dphisector()}; - VarCut x25_1_cut{globals_, &x25_1, -settings_.dphisector(), settings_.dphisector()}; - VarCut x25_2_cut{globals_, &x25_2, -settings_.dphisector(), settings_.dphisector()}; - VarCut x25_3_cut{globals_, &x25_3, -settings_.dphisector(), settings_.dphisector()}; - VarCut x25_4_cut{globals_, &x25_4, -settings_.dphisector(), settings_.dphisector()}; - VarCut phiD_0_cut{globals_, &phiD_0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut phiD_1_cut{globals_, &phiD_1, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut phiD_2_cut{globals_, &phiD_2, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut phiD_3_cut{globals_, &phiD_3, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut phiD_4_cut{globals_, &phiD_4, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut der_phiD_cut{globals_, &der_phiD, -der_phiD_max, der_phiD_max}; - VarCut rD_0_cut{globals_, &rD_0, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - VarCut rD_1_cut{globals_, &rD_1, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - VarCut rD_2_cut{globals_, &rD_2, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - VarCut rD_3_cut{globals_, &rD_3, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - VarCut rD_4_cut{globals_, &rD_4, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - - VarCut t_disk_cut_left{globals_, &t, -t_disk_max, -t_disk_min}; - VarCut t_disk_cut_right{globals_, &t, t_disk_min, t_disk_max}; - VarCut t_layer_cut{globals_, &t, -t_layer_max, t_layer_max}; - - // the following flags are used to apply the cuts in TrackletCalculator - // and in the output Verilog - VarFlag valid_trackpar{globals_, "valid_trackpar", &rinv_final, &phi0_final, &t_final, &z0_final}; - - VarFlag valid_phiL_0{globals_, "valid_phiL_0", &phiL_0_final}; - VarFlag valid_phiL_1{globals_, "valid_phiL_1", &phiL_1_final}; - VarFlag valid_phiL_2{globals_, "valid_phiL_2", &phiL_2_final}; - VarFlag valid_phiL_3{globals_, "valid_phiL_3", &phiL_3_final}; - - VarFlag valid_zL_0{globals_, "valid_zL_0", &zL_0_final}; - VarFlag valid_zL_1{globals_, "valid_zL_1", &zL_1_final}; - VarFlag valid_zL_2{globals_, "valid_zL_2", &zL_2_final}; - VarFlag valid_zL_3{globals_, "valid_zL_3", &zL_3_final}; - - VarFlag valid_der_phiL{globals_, "valid_der_phiL", &der_phiL_final}; - VarFlag valid_der_zL{globals_, "valid_der_zL", &der_zL_final}; - - VarFlag valid_phiD_0{globals_, "valid_phiD_0", &phiD_0_final}; - VarFlag valid_phiD_1{globals_, "valid_phiD_1", &phiD_1_final}; - VarFlag valid_phiD_2{globals_, "valid_phiD_2", &phiD_2_final}; - VarFlag valid_phiD_3{globals_, "valid_phiD_3", &phiD_3_final}; - VarFlag valid_phiD_4{globals_, "valid_phiD_4", &phiD_4_final}; - - VarFlag valid_rD_0{globals_, "valid_rD_0", &rD_0_final}; - VarFlag valid_rD_1{globals_, "valid_rD_1", &rD_1_final}; - VarFlag valid_rD_2{globals_, "valid_rD_2", &rD_2_final}; - VarFlag valid_rD_3{globals_, "valid_rD_3", &rD_3_final}; - VarFlag valid_rD_4{globals_, "valid_rD_4", &rD_4_final}; - - VarFlag valid_der_phiD{globals_, "valid_der_phiD", &der_phiD_final}; - VarFlag valid_der_rD{globals_, "valid_der_rD", &der_rD_final}; - }; -}; // namespace trklet - -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h b/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h deleted file mode 100644 index cb80405b2344b..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h +++ /dev/null @@ -1,406 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculatorDisk_h -#define L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculatorDisk_h - -#include "Settings.h" -#include "imath.h" - -// -// Constants used: -// dphisector -// rmaxL6 -// zmaxD5 -// rmaxdisk -// kr, kphi1, kz -// -// rmean[], zmean[] - -namespace trklet { - - class IMATH_TrackletCalculatorDisk { - public: - IMATH_TrackletCalculatorDisk(Settings const& settings, imathGlobals* globals, int i1, int i2) - : settings_(settings), globals_(globals) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "============================================="; - char s[1024]; - snprintf(s, 1024, "IMATH Tracklet Calculator for Disk %i %i dphisector = %f", i1, i2, settings_.dphisector()); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, 1024, "rmaxL6 = %f, zmaxD5 = %f", settings_.rmax(5), settings_.zmax(4)); - edm::LogVerbatim("Tracklet") << s; - snprintf( - s, 1024, " stub Ks: kr, kphi1, kz = %g, %g, %g", settings_.kr(), settings_.kphi1(), settings_.kz()); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, - 1024, - " tracklet Ks: krinvpars, kphi0pars, ktpars, kzpars = %g, %g, %g, %g", - settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift()), - settings_.kphi1() * pow(2, settings_.phi0_shift()), - settings_.kz() / settings_.kr() * pow(2, settings_.t_shift()), - settings_.kz() * pow(2, settings_.z0_shift())); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, - 1024, - "layer proj Ks: kphiproj456, kphider, kzproj, kzder = %g, %g, %g, %g", - settings_.kphi1() * pow(2, settings_.SS_phiL_shift()), - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift()), - settings_.kz() * pow(2, settings_.PS_zL_shift()), - settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, - 1024, - " disk proj Ks: kphiprojdisk, kphiprojderdisk, krprojdisk, krprojderdisk = %g, %g, %g, %g", - settings_.kphi1() * pow(2, settings_.SS_phiD_shift()), - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift()), - settings_.kr() * pow(2, settings_.PS_rD_shift()), - settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())); - edm::LogVerbatim("Tracklet") << s; - edm::LogVerbatim("Tracklet") << "============================================="; - } - - z1mean.set_fval(settings_.zmean(abs(i1) - 1)); - z2mean.set_fval(settings_.zmean(abs(i2) - 1)); - - if (i2 < 0) { //t is negative - z1mean.set_fval(-settings_.zmean(abs(i1) - 1)); - z2mean.set_fval(-settings_.zmean(abs(i2) - 1)); - invt.set_mode(VarInv::mode::neg); - invt.initLUT(0.); - } - - valid_phiL_0.add_cut(&t_layer_cut); - valid_phiL_1.add_cut(&t_layer_cut); - valid_phiL_2.add_cut(&t_layer_cut); - - valid_der_phiL.add_cut(&t_layer_cut); - - valid_zL_0.add_cut(&t_layer_cut); - valid_zL_1.add_cut(&t_layer_cut); - valid_zL_2.add_cut(&t_layer_cut); - - valid_der_zL.add_cut(&t_layer_cut); - - valid_phiD_0.add_cut(&t_disk_cut_left); - valid_phiD_1.add_cut(&t_disk_cut_left); - valid_phiD_2.add_cut(&t_disk_cut_left); - - valid_der_phiD.add_cut(&t_disk_cut_left); - - valid_rD_0.add_cut(&t_disk_cut_left); - valid_rD_1.add_cut(&t_disk_cut_left); - valid_rD_2.add_cut(&t_disk_cut_left); - - valid_der_rD.add_cut(&t_disk_cut_left); - - valid_phiD_0.add_cut(&t_disk_cut_right); - valid_phiD_1.add_cut(&t_disk_cut_right); - valid_phiD_2.add_cut(&t_disk_cut_right); - - valid_der_phiD.add_cut(&t_disk_cut_right); - - valid_rD_0.add_cut(&t_disk_cut_right); - valid_rD_1.add_cut(&t_disk_cut_right); - valid_rD_2.add_cut(&t_disk_cut_right); - - valid_der_rD.add_cut(&t_disk_cut_right); - } - - ~IMATH_TrackletCalculatorDisk() = default; - - Settings const& settings_; - - imathGlobals* globals_; - - //max values - const double dz_max = 50.; - const double dr_max = 20.; - const double delta0_max = 0.005; - const double a2_max = 3.; - const double a2a_max = 0.1; - const double x6a_max = 0.02; - const double x6m_max = 2.; - const double x8_max = 1.; - const double x13_max = 300.; - const double x22_max = 0.3; - const double x23_max = 200.; - const double deltaZ_max = 8.; - const double der_phiD_max = 0.002; - const double t_max = 7.9; - const double t_disk_min = 1.; - const double t_disk_max = 7.9; - const double t_layer_max = 2.5; - const double z0_max = 20.; - const double z0a_max = 205.; - - //constants - VarParam plus2{globals_, "plus2", 2., 10}; - VarParam plus1{globals_, "plus1", 1., 10}; - VarParam minus1{globals_, "minus1", -1, 10}; - - VarParam z1mean{globals_, "z1mean", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - VarParam z2mean{globals_, "z2mean", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - - //inputs - VarDef r1{globals_, "r1", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarDef r2{globals_, "r2", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarDef z1{globals_, "z1", "Kz", settings_.dzmax(), settings_.kz()}; - VarDef z2{globals_, "z2", "Kz", settings_.dzmax(), settings_.kz()}; - - VarDef phi1{globals_, "phi1", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; - VarDef phi2{globals_, "phi2", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; - - VarDef rproj0{globals_, "rproj0", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarDef rproj1{globals_, "rproj1", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarDef rproj2{globals_, "rproj2", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - - VarDef zproj0{globals_, "zproj0", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - VarDef zproj1{globals_, "zproj1", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - VarDef zproj2{globals_, "zproj2", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - - //calculations - - //tracklet - VarAdd z1abs{globals_, "z1abs", &z1, &z1mean, settings_.zmax(N_DISK - 1)}; - VarAdd z2abs{globals_, "z2abs", &z2, &z2mean, settings_.zmax(N_DISK - 1)}; - - VarSubtract dr{globals_, "dr", &r2, &r1, dr_max}; - - //R LUT - VarInv drinv{globals_, "drinv", &dr, 0, 18, 23, 0, VarInv::mode::pos}; - - VarSubtract dphi{globals_, "dphi", &phi2, &phi1, settings_.dphisector() / 4.}; - VarSubtract dz{globals_, "dz", &z2abs, &z1abs, dz_max}; - - VarMult delta0{globals_, "delta0", &dphi, &drinv, 4 * delta0_max}; - VarMult deltaZ{globals_, "deltaZ", &dz, &drinv, deltaZ_max}; - VarMult delta1{globals_, "delta1", &r1, &delta0}; - VarMult delta2{globals_, "delta2", &r2, &delta0}; - VarMult a2a{globals_, "a2a", &delta1, &delta2, 4 * a2a_max}; - VarNounits a2b{globals_, "a2b", &a2a}; - VarSubtract a2{globals_, "a2", &plus2, &a2b, 3.}; - VarNeg a2n{globals_, "a2n", &a2}; - VarShift a{globals_, "a", &a2, 1}; - - VarAdd Rabs{globals_, "Rabs", &r1, &r2}; - VarTimesC R6{globals_, "R6", &Rabs, 1. / 6., 12}; - - VarMult x4{globals_, "x4", &R6, &delta0}; - VarMult x6a{globals_, "x6a", &delta2, &x4, 8 * x6a_max}; - VarNounits x6b{globals_, "x6b", &x6a}; - VarAdd x6m{globals_, "x6m", &minus1, &x6b, 2.}; - VarMult phi0a{globals_, "phi0a", &delta1, &x6m, settings_.dphisector()}; - - VarMult z0a{globals_, "z0a", &r1, &deltaZ, 2 * settings_.zlength()}; - VarMult z0b{globals_, "z0b", &z0a, &x6m, 2 * settings_.zlength()}; - - VarAdd phi0{globals_, "phi0", &phi1, &phi0a, 2 * settings_.dphisector()}; - VarMult rinv{globals_, "rinv", &a2n, &delta0, 4 * settings_.maxrinv()}; - VarMult t{globals_, "t", &a, &deltaZ, 2 * t_max}; - VarAdd z0{globals_, "z0", &z1abs, &z0b, 2 * z0_max}; - - VarAdjustK rinv_final{ - globals_, "rinv_final", &rinv, settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift())}; - VarAdjustK phi0_final{globals_, "phi0_final", &phi0, settings_.kphi1() * pow(2, settings_.phi0_shift())}; - VarAdjustK t_final{globals_, "t_final", &t, settings_.kz() / settings_.kr() * pow(2, settings_.t_shift())}; - VarAdjustK z0_final{globals_, "z0_final", &z0, settings_.kz() * pow(2, settings_.z0_shift())}; - - //projection to r - VarShift x2{globals_, "x2", &delta0, 1}; - - VarMult x1_0{globals_, "x1_0", &x2, &rproj0}; - VarMult x1_1{globals_, "x1_1", &x2, &rproj1}; - VarMult x1_2{globals_, "x1_2", &x2, &rproj2}; - - VarMult x8_0{globals_, "x8_0", &x1_0, &a2n, x8_max}; - VarMult x8_1{globals_, "x8_1", &x1_1, &a2n, x8_max}; - VarMult x8_2{globals_, "x8_2", &x1_2, &a2n, x8_max}; - - VarMult x12_0{globals_, "x12_0", &x8_0, &x8_0}; - VarMult x12_1{globals_, "x12_1", &x8_1, &x8_1}; - VarMult x12_2{globals_, "x12_2", &x8_2, &x8_2}; - - VarNounits x12A_0{globals_, "x12A_0", &x12_0}; - VarNounits x12A_1{globals_, "x12A_1", &x12_1}; - VarNounits x12A_2{globals_, "x12A_2", &x12_2}; - - VarTimesC x20_0{globals_, "x20_0", &x12A_0, 1. / 6.}; - VarTimesC x20_1{globals_, "x20_1", &x12A_1, 1. / 6.}; - VarTimesC x20_2{globals_, "x20_2", &x12A_2, 1. / 6.}; - - VarAdd x10_0{globals_, "x10_0", &plus1, &x20_0}; - VarAdd x10_1{globals_, "x10_1", &plus1, &x20_1}; - VarAdd x10_2{globals_, "x10_2", &plus1, &x20_2}; - - VarMult x22_0{globals_, "x22_0", &x8_0, &x10_0, 2 * x22_max}; - VarMult x22_1{globals_, "x22_1", &x8_1, &x10_1, 2 * x22_max}; - VarMult x22_2{globals_, "x22_2", &x8_2, &x10_2, 2 * x22_max}; - - VarSubtract phiL_0{globals_, "phiL_0", &phi0_final, &x22_0, -1, phi0_final.nbits() + 1}; - VarSubtract phiL_1{globals_, "phiL_1", &phi0_final, &x22_1, -1, phi0_final.nbits() + 1}; - VarSubtract phiL_2{globals_, "phiL_2", &phi0_final, &x22_2, -1, phi0_final.nbits() + 1}; - - VarShift x3{globals_, "x3", &rinv, 1}; - VarNeg der_phiL{globals_, "der_phiL", &x3}; - - VarAdjustK phiL_0_final{globals_, "phiL_0_final", &phiL_0, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; - VarAdjustK phiL_1_final{globals_, "phiL_1_final", &phiL_1, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; - VarAdjustK phiL_2_final{globals_, "phiL_2_final", &phiL_2, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; - - VarAdjustK der_phiL_final{globals_, - "der_phiL_final", - &der_phiL, - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift())}; - - VarMult x11_0{globals_, "x11_0", &rproj0, &t}; - VarMult x11_1{globals_, "x11_1", &rproj1, &t}; - VarMult x11_2{globals_, "x11_2", &rproj2, &t}; - - VarMult x23_0{globals_, "x23_0", &x11_0, &x10_0, 4 * x23_max}; - VarMult x23_1{globals_, "x23_1", &x11_1, &x10_1, 4 * x23_max}; - VarMult x23_2{globals_, "x23_2", &x11_2, &x10_2, 4 * x23_max}; - - VarAdd zL_0{globals_, "zL_0", &z0, &x23_0}; - VarAdd zL_1{globals_, "zL_1", &z0, &x23_1}; - VarAdd zL_2{globals_, "zL_2", &z0, &x23_2}; - - VarAdjustK zL_0_final{globals_, "zL_0_final", &zL_0, settings_.kz() * pow(2, settings_.PS_zL_shift())}; - VarAdjustK zL_1_final{globals_, "zL_1_final", &zL_1, settings_.kz() * pow(2, settings_.PS_zL_shift())}; - VarAdjustK zL_2_final{globals_, "zL_2_final", &zL_2, settings_.kz() * pow(2, settings_.PS_zL_shift())}; - - VarAdjustK der_zL_final{ - globals_, "der_zL_final", &t_final, settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())}; - - //projection to z - VarInv invt{globals_, "invt", &t_final, 0., 18, 26, 1, VarInv::mode::pos, 13}; - - VarMult x7{globals_, "x7", &x2, &a2}; - - VarSubtract x5_0{globals_, "x5_0", &zproj0, &z0}; - VarSubtract x5_1{globals_, "x5_1", &zproj1, &z0}; - VarSubtract x5_2{globals_, "x5_2", &zproj2, &z0}; - - VarMult x13_0{globals_, "x13_0", &x5_0, &invt, x13_max}; - VarMult x13_1{globals_, "x13_1", &x5_1, &invt, x13_max}; - VarMult x13_2{globals_, "x13_2", &x5_2, &invt, x13_max}; - - VarMult x25_0{globals_, "x25_0", &x13_0, &x7, settings_.dphisector()}; - VarMult x25_1{globals_, "x25_1", &x13_1, &x7, settings_.dphisector()}; - VarMult x25_2{globals_, "x25_2", &x13_2, &x7, settings_.dphisector()}; - - VarAdd phiD_0{globals_, "phiD_0", &phi0, &x25_0, 2 * settings_.dphisector()}; - VarAdd phiD_1{globals_, "phiD_1", &phi0, &x25_1, 2 * settings_.dphisector()}; - VarAdd phiD_2{globals_, "phiD_2", &phi0, &x25_2, 2 * settings_.dphisector()}; - - VarAdjustK phiD_0_final{globals_, "phiD_0_final", &phiD_0, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - VarAdjustK phiD_1_final{globals_, "phiD_1_final", &phiD_1, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - VarAdjustK phiD_2_final{globals_, "phiD_2_final", &phiD_2, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - - VarMult der_phiD{globals_, "der_phiD", &x7, &invt, 2 * der_phiD_max}; - - VarAdjustK der_phiD_final{globals_, - "der_phiD_final", - &der_phiD, - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift())}; - - VarMult x26_0{globals_, "x26_0", &x25_0, &x25_0}; - VarMult x26_1{globals_, "x26_1", &x25_1, &x25_1}; - VarMult x26_2{globals_, "x26_2", &x25_2, &x25_2}; - - VarNounits x26A_0{globals_, "x26A_0", &x26_0}; - VarNounits x26A_1{globals_, "x26A_1", &x26_1}; - VarNounits x26A_2{globals_, "x26A_2", &x26_2}; - - VarTimesC x9_0{globals_, "x9_0", &x26A_0, 1. / 6.}; - VarTimesC x9_1{globals_, "x9_1", &x26A_1, 1. / 6.}; - VarTimesC x9_2{globals_, "x9_2", &x26A_2, 1. / 6.}; - - VarSubtract x27_0{globals_, "x27_0", &plus1, &x9_0}; - VarSubtract x27_1{globals_, "x27_1", &plus1, &x9_1}; - VarSubtract x27_2{globals_, "x27_2", &plus1, &x9_2}; - - VarMult rD_0{globals_, "rD_0", &x13_0, &x27_0, settings_.rmaxdisk()}; - VarMult rD_1{globals_, "rD_1", &x13_1, &x27_1, settings_.rmaxdisk()}; - VarMult rD_2{globals_, "rD_2", &x13_2, &x27_2, settings_.rmaxdisk()}; - - VarAdjustK rD_0_final{globals_, "rD_0_final", &rD_0, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - VarAdjustK rD_1_final{globals_, "rD_1_final", &rD_1, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - VarAdjustK rD_2_final{globals_, "rD_2_final", &rD_2, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - - VarAdjustK der_rD_final{ - globals_, "der_rD_final", &invt, settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())}; - - VarCut rinv_final_cut{globals_, &rinv_final, -settings_.rinvcut(), settings_.rinvcut()}; - VarCut z0_final_cut{globals_, &z0_final, -settings_.z0cut(), settings_.z0cut()}; - - VarCut z1abs_cut{globals_, &z1abs, -settings_.zmax(4), settings_.zmax(4)}; - VarCut z2abs_cut{globals_, &z2abs, -settings_.zmax(4), settings_.zmax(4)}; - VarCut dr_cut{globals_, &dr, -dr_max, dr_max}; - VarCut dphi_cut{globals_, &dphi, -settings_.dphisector() / 4., settings_.dphisector() / 4.}; - VarCut dz_cut{globals_, &dz, -dz_max, dz_max}; - VarCut delta0_cut{globals_, &delta0, -delta0_max, delta0_max}; - VarCut deltaZ_cut{globals_, &deltaZ, -deltaZ_max, deltaZ_max}; - VarCut a2a_cut{globals_, &a2a, -a2a_max, a2a_max}; - VarCut a2_cut{globals_, &a2, -a2_max, a2_max}; - VarCut x6a_cut{globals_, &x6a, -x6a_max, x6a_max}; - VarCut x6m_cut{globals_, &x6m, -x6m_max, x6m_max}; - VarCut phi0a_cut{globals_, &phi0a, -settings_.dphisector(), settings_.dphisector()}; - VarCut z0a_cut{globals_, &z0a, -z0a_max, z0a_max}; - VarCut phi0_cut{globals_, &phi0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut rinv_cut{globals_, &rinv, -settings_.maxrinv(), settings_.maxrinv()}; - VarCut t_cut{globals_, &t, -t_max, t_max}; - VarCut z0_cut{globals_, &z0, -z0_max, z0_max}; - VarCut x8_0_cut{globals_, &x8_0, -x8_max, x8_max}; - VarCut x8_1_cut{globals_, &x8_1, -x8_max, x8_max}; - VarCut x8_2_cut{globals_, &x8_2, -x8_max, x8_max}; - VarCut x22_0_cut{globals_, &x22_0, -x22_max, x22_max}; - VarCut x22_1_cut{globals_, &x22_1, -x22_max, x22_max}; - VarCut x22_2_cut{globals_, &x22_2, -x22_max, x22_max}; - VarCut x23_0_cut{globals_, &x23_0, -x23_max, x23_max}; - VarCut x23_1_cut{globals_, &x23_1, -x23_max, x23_max}; - VarCut x23_2_cut{globals_, &x23_2, -x23_max, x23_max}; - VarCut x13_0_cut{globals_, &x13_0, -x13_max, x13_max}; - VarCut x13_1_cut{globals_, &x13_1, -x13_max, x13_max}; - VarCut x13_2_cut{globals_, &x13_2, -x13_max, x13_max}; - VarCut x25_0_cut{globals_, &x25_0, -settings_.dphisector(), settings_.dphisector()}; - VarCut x25_1_cut{globals_, &x25_1, -settings_.dphisector(), settings_.dphisector()}; - VarCut x25_2_cut{globals_, &x25_2, -settings_.dphisector(), settings_.dphisector()}; - VarCut phiD_0_cut{globals_, &phiD_0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut phiD_1_cut{globals_, &phiD_1, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut phiD_2_cut{globals_, &phiD_2, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut der_phiD_cut{globals_, &der_phiD, -der_phiD_max, der_phiD_max}; - VarCut rD_0_cut{globals_, &rD_0, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - VarCut rD_1_cut{globals_, &rD_1, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - VarCut rD_2_cut{globals_, &rD_2, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - - VarCut t_disk_cut_left{globals_, &t, -t_disk_max, -t_disk_min}; - VarCut t_disk_cut_right{globals_, &t, t_disk_min, t_disk_max}; - VarCut t_layer_cut{globals_, &t, -t_layer_max, t_layer_max}; - - // the following flags are used to apply the cuts in TrackletCalculator - // and in the output Verilog - VarFlag valid_trackpar{globals_, "valid_trackpar", &rinv_final, &phi0_final, &t_final, &z0_final}; - - VarFlag valid_phiL_0{globals_, "valid_phiL_0", &phiL_0_final}; - VarFlag valid_phiL_1{globals_, "valid_phiL_1", &phiL_1_final}; - VarFlag valid_phiL_2{globals_, "valid_phiL_2", &phiL_2_final}; - - VarFlag valid_zL_0{globals_, "valid_zL_0", &zL_0_final}; - VarFlag valid_zL_1{globals_, "valid_zL_1", &zL_1_final}; - VarFlag valid_zL_2{globals_, "valid_zL_2", &zL_2_final}; - - VarFlag valid_der_phiL{globals_, "valid_der_phiL", &der_phiL_final}; - VarFlag valid_der_zL{globals_, "valid_der_zL", &der_zL_final}; - - VarFlag valid_phiD_0{globals_, "valid_phiD_0", &phiD_0_final}; - VarFlag valid_phiD_1{globals_, "valid_phiD_1", &phiD_1_final}; - VarFlag valid_phiD_2{globals_, "valid_phiD_2", &phiD_2_final}; - - VarFlag valid_rD_0{globals_, "valid_rD_0", &rD_0_final}; - VarFlag valid_rD_1{globals_, "valid_rD_1", &rD_1_final}; - VarFlag valid_rD_2{globals_, "valid_rD_2", &rD_2_final}; - - VarFlag valid_der_phiD{globals_, "valid_der_phiD", &der_phiD_final}; - VarFlag valid_der_rD{globals_, "valid_der_rD", &der_rD_final}; - }; -}; // namespace trklet - -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h b/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h deleted file mode 100644 index f6b77ca73f8f6..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h +++ /dev/null @@ -1,429 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculatorOverlap_h -#define L1Trigger_TrackFindingTracklet_interface_IMATH_TrackletCalculatorOverlap_h - -#include "Settings.h" -#include "imath.h" - -// -// Constants used: -// dphisector -// rmaxL6 -// zmaxD5 -// rmaxdisk -// kr, kphi1, kz -// -// rmean[], zmean[] - -namespace trklet { - - class IMATH_TrackletCalculatorOverlap { - public: - IMATH_TrackletCalculatorOverlap(Settings const& settings, imathGlobals* globals, int i1, int i2) - : settings_(settings), globals_(globals) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "============================================="; - char s[1024]; - snprintf( - s, 1024, "IMATH Tracklet Calculator for Overlap %i %i dphisector = %f", i1, i2, settings_.dphisector()); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, 1024, "rmaxL6 = %f, zmaxD5 = %f", settings_.rmax(5), settings_.zmax(4)); - edm::LogVerbatim("Tracklet") << s; - snprintf( - s, 1024, " stub Ks: kr, kphi1, kz = %g, %g, %g", settings_.kr(), settings_.kphi1(), settings_.kz()); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, - 1024, - " tracklet Ks: krinvpars, kphi0pars, ktpars, kzpars = %g, %g, %g, %g", - settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift()), - settings_.kphi1() * pow(2, settings_.phi0_shift()), - settings_.kz() / settings_.kr() * pow(2, settings_.t_shift()), - settings_.kz() * pow(2, settings_.z0_shift())); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, - 1024, - "layer proj Ks: kphiproj456, kphider, kzproj, kzder = %g, %g, %g, %g", - settings_.kphi1() * pow(2, settings_.SS_phiL_shift()), - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift()), - settings_.kz() * pow(2, settings_.PS_zL_shift()), - settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())); - edm::LogVerbatim("Tracklet") << s; - snprintf(s, - 1024, - " disk proj Ks: kphiprojdisk, kphiprojderdisk, krprojdisk, krprojderdisk = %g, %g, %g, %g", - settings_.kphi1() * pow(2, settings_.SS_phiD_shift()), - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift()), - settings_.kr() * pow(2, settings_.PS_rD_shift()), - settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())); - edm::LogVerbatim("Tracklet") << s; - edm::LogVerbatim("Tracklet") << "============================================="; - } - - r1mean.set_fval(settings_.rmean(i1 - 1)); - z2mean.set_fval(settings_.zmean(abs(i2) - 1)); - - if (i2 < 0) { //t is negative - z2mean.set_fval(-settings_.zmean(abs(i2) - 1)); - invt.set_mode(VarInv::mode::neg); - invt.initLUT(0.); - } - - valid_phiL_0.add_cut(&t_layer_cut); - valid_phiL_1.add_cut(&t_layer_cut); - valid_phiL_2.add_cut(&t_layer_cut); - - valid_der_phiL.add_cut(&t_layer_cut); - - valid_zL_0.add_cut(&t_layer_cut); - valid_zL_1.add_cut(&t_layer_cut); - valid_zL_2.add_cut(&t_layer_cut); - - valid_der_zL.add_cut(&t_layer_cut); - - valid_phiD_0.add_cut(&t_disk_cut_left); - valid_phiD_1.add_cut(&t_disk_cut_left); - valid_phiD_2.add_cut(&t_disk_cut_left); - valid_phiD_3.add_cut(&t_disk_cut_left); - - valid_der_phiD.add_cut(&t_disk_cut_left); - - valid_rD_0.add_cut(&t_disk_cut_left); - valid_rD_1.add_cut(&t_disk_cut_left); - valid_rD_2.add_cut(&t_disk_cut_left); - valid_rD_3.add_cut(&t_disk_cut_left); - - valid_der_rD.add_cut(&t_disk_cut_left); - - valid_phiD_0.add_cut(&t_disk_cut_right); - valid_phiD_1.add_cut(&t_disk_cut_right); - valid_phiD_2.add_cut(&t_disk_cut_right); - valid_phiD_3.add_cut(&t_disk_cut_right); - - valid_der_phiD.add_cut(&t_disk_cut_right); - - valid_rD_0.add_cut(&t_disk_cut_right); - valid_rD_1.add_cut(&t_disk_cut_right); - valid_rD_2.add_cut(&t_disk_cut_right); - valid_rD_3.add_cut(&t_disk_cut_right); - - valid_der_rD.add_cut(&t_disk_cut_right); - } - - ~IMATH_TrackletCalculatorOverlap() = default; - - Settings const& settings_; - - imathGlobals* globals_; - - //max values - const double dz_max = 50.; - const double dr_max = 40; - const double delta0_max = 0.005; - const double a2_max = 3.; - const double a2a_max = 0.1; - const double x6a_max = 0.02; - const double x6m_max = 2.; - const double x8_max = 1.; - const double x13_max = 300.; - const double x22_max = 0.3; - const double x23_max = 200.; - const double deltaZ_max = 8.; - const double der_phiD_max = 0.002; - const double t_max = 7.9; - const double t_disk_min = 1.; - const double t_disk_max = 7.9; - const double t_layer_max = 2.5; - const double z0_max = 20.; - - // constants - // - VarParam plus2{globals_, "plus2", 2., 10}; - VarParam plus1{globals_, "plus1", 1., 10}; - VarParam minus1{globals_, "minus1", -1, 10}; - // - // - VarParam r1mean{globals_, "r1mean", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarParam z2mean{globals_, "z2mean", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - - //inputs - VarDef r1{globals_, "r1", "Kr", settings_.drmax(), settings_.kr()}; - VarDef r2{globals_, "r2", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarDef z1{globals_, "z1", "Kz", settings_.zlength(), settings_.kz()}; - VarDef z2{globals_, "z2", "Kz", settings_.dzmax(), settings_.kz()}; - - VarDef phi1{globals_, "phi1", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; - VarDef phi2{globals_, "phi2", "Kphi", settings_.dphisector() / 0.75, settings_.kphi1()}; - - VarDef rproj0{globals_, "rproj0", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarDef rproj1{globals_, "rproj1", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - VarDef rproj2{globals_, "rproj2", "Kr", settings_.rmax(N_LAYER - 1), settings_.kr()}; - - VarDef zproj0{globals_, "zproj0", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - VarDef zproj1{globals_, "zproj1", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - VarDef zproj2{globals_, "zproj2", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - VarDef zproj3{globals_, "zproj3", "Kz", settings_.zmax(N_DISK - 1), settings_.kz()}; - - //calculations - - //tracklet - VarAdd r1abs{globals_, "r1abs", &r1, &r1mean, settings_.rmax(N_LAYER - 1)}; - VarAdd z2abs{globals_, "z2abs", &z2, &z2mean, settings_.zmax(N_DISK - 1)}; - - VarSubtract dr{globals_, "dr", &r2, &r1abs, dr_max}; - - //R LUT - VarInv drinv{globals_, "drinv", &dr, 0, 18, 23, 0, VarInv::mode::pos}; - - VarSubtract dphi{globals_, "dphi", &phi2, &phi1, settings_.dphisector() / 4.}; - VarSubtract dz{globals_, "dz", &z2abs, &z1, 2 * dz_max}; - - VarMult delta0{globals_, "delta0", &dphi, &drinv, 8 * delta0_max}; - VarMult deltaZ{globals_, "deltaZ", &dz, &drinv, deltaZ_max}; - VarMult delta1{globals_, "delta1", &r1abs, &delta0}; - VarMult delta2{globals_, "delta2", &r2, &delta0}; - VarMult a2a{globals_, "a2a", &delta1, &delta2, 32 * a2a_max}; - VarNounits a2b{globals_, "a2b", &a2a}; - VarSubtract a2{globals_, "a2", &plus2, &a2b, a2_max}; - VarNeg a2n{globals_, "a2n", &a2}; - VarShift a{globals_, "a", &a2, 1}; - - VarAdd Rabs{globals_, "Rabs", &r1abs, &r2}; - VarTimesC R6{globals_, "R6", &Rabs, 1. / 6., 12}; - - VarMult x4{globals_, "x4", &R6, &delta0}; - VarMult x6a{globals_, "x6a", &delta2, &x4, 32 * x6a_max}; - VarNounits x6b{globals_, "x6b", &x6a}; - VarAdd x6m{globals_, "x6m", &minus1, &x6b, x6m_max}; - VarMult phi0a{globals_, "phi0a", &delta1, &x6m, settings_.dphisector()}; - - VarMult z0a{globals_, "z0a", &r1abs, &deltaZ, 2 * settings_.zlength()}; - VarMult z0b{globals_, "z0b", &z0a, &x6m, 2 * settings_.zlength()}; - - VarAdd phi0{globals_, "phi0", &phi1, &phi0a, 2 * settings_.dphisector()}; - VarMult rinv{globals_, "rinv", &a2n, &delta0, 8 * settings_.maxrinv()}; - VarMult t{globals_, "t", &a, &deltaZ, t_max}; - VarAdd z0{globals_, "z0", &z1, &z0b, 16 * z0_max}; - - VarAdjustK rinv_final{ - globals_, "rinv_final", &rinv, settings_.kphi1() / settings_.kr() * pow(2, settings_.rinv_shift())}; - VarAdjustK phi0_final{globals_, "phi0_final", &phi0, settings_.kphi1() * pow(2, settings_.phi0_shift())}; - VarAdjustK t_final{globals_, "t_final", &t, settings_.kz() / settings_.kr() * pow(2, settings_.t_shift())}; - VarAdjustK z0_final{globals_, "z0_final", &z0, settings_.kz() * pow(2, settings_.z0_shift())}; - - //projection to r - VarShift x2{globals_, "x2", &delta0, 1}; - - VarMult x1_0{globals_, "x1_0", &x2, &rproj0}; - VarMult x1_1{globals_, "x1_1", &x2, &rproj1}; - VarMult x1_2{globals_, "x1_2", &x2, &rproj2}; - - VarMult x8_0{globals_, "x8_0", &x1_0, &a2n, 2 * x8_max}; - VarMult x8_1{globals_, "x8_1", &x1_1, &a2n, 2 * x8_max}; - VarMult x8_2{globals_, "x8_2", &x1_2, &a2n, 2 * x8_max}; - - VarMult x12_0{globals_, "x12_0", &x8_0, &x8_0}; - VarMult x12_1{globals_, "x12_1", &x8_1, &x8_1}; - VarMult x12_2{globals_, "x12_2", &x8_2, &x8_2}; - - VarNounits x12A_0{globals_, "x12A_0", &x12_0}; - VarNounits x12A_1{globals_, "x12A_1", &x12_1}; - VarNounits x12A_2{globals_, "x12A_2", &x12_2}; - - VarTimesC x20_0{globals_, "x20_0", &x12A_0, 1. / 6.}; - VarTimesC x20_1{globals_, "x20_1", &x12A_1, 1. / 6.}; - VarTimesC x20_2{globals_, "x20_2", &x12A_2, 1. / 6.}; - - VarAdd x10_0{globals_, "x10_0", &plus1, &x20_0}; - VarAdd x10_1{globals_, "x10_1", &plus1, &x20_1}; - VarAdd x10_2{globals_, "x10_2", &plus1, &x20_2}; - - VarMult x22_0{globals_, "x22_0", &x8_0, &x10_0, 4 * x22_max}; - VarMult x22_1{globals_, "x22_1", &x8_1, &x10_1, 4 * x22_max}; - VarMult x22_2{globals_, "x22_2", &x8_2, &x10_2, 4 * x22_max}; - - VarSubtract phiL_0{globals_, "phiL_0", &phi0_final, &x22_0, -1, phi0_final.nbits() + 1}; - VarSubtract phiL_1{globals_, "phiL_1", &phi0_final, &x22_1, -1, phi0_final.nbits() + 1}; - VarSubtract phiL_2{globals_, "phiL_2", &phi0_final, &x22_2, -1, phi0_final.nbits() + 1}; - - VarShift x3{globals_, "x3", &rinv, 1}; - VarNeg der_phiL{globals_, "der_phiL", &x3}; - - VarAdjustK phiL_0_final{globals_, "phiL_0_final", &phiL_0, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; - VarAdjustK phiL_1_final{globals_, "phiL_1_final", &phiL_1, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; - VarAdjustK phiL_2_final{globals_, "phiL_2_final", &phiL_2, settings_.kphi1() * pow(2, settings_.SS_phiL_shift())}; - - VarAdjustK der_phiL_final{globals_, - "der_phiL_final", - &der_phiL, - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderL_shift())}; - - VarMult x11_0{globals_, "x11_0", &rproj0, &t}; - VarMult x11_1{globals_, "x11_1", &rproj1, &t}; - VarMult x11_2{globals_, "x11_2", &rproj2, &t}; - - VarMult x23_0{globals_, "x23_0", &x11_0, &x10_0, 2 * x23_max}; - VarMult x23_1{globals_, "x23_1", &x11_1, &x10_1, 2 * x23_max}; - VarMult x23_2{globals_, "x23_2", &x11_2, &x10_2, 2 * x23_max}; - - VarAdd zL_0{globals_, "zL_0", &z0, &x23_0}; - VarAdd zL_1{globals_, "zL_1", &z0, &x23_1}; - VarAdd zL_2{globals_, "zL_2", &z0, &x23_2}; - - VarAdjustK zL_0_final{globals_, "zL_0_final", &zL_0, settings_.kz() * pow(2, settings_.PS_zL_shift())}; - VarAdjustK zL_1_final{globals_, "zL_1_final", &zL_1, settings_.kz() * pow(2, settings_.PS_zL_shift())}; - VarAdjustK zL_2_final{globals_, "zL_2_final", &zL_2, settings_.kz() * pow(2, settings_.PS_zL_shift())}; - - VarAdjustK der_zL_final{ - globals_, "der_zL_final", &t_final, settings_.kz() / settings_.kr() * pow(2, settings_.PS_zderL_shift())}; - - //projection to z - VarInv invt{globals_, "invt", &t_final, 0., 18, 26, 1, VarInv::mode::pos, 13}; - - VarMult x7{globals_, "x7", &x2, &a2}; - - VarSubtract x5_0{globals_, "x5_0", &zproj0, &z0}; - VarSubtract x5_1{globals_, "x5_1", &zproj1, &z0}; - VarSubtract x5_2{globals_, "x5_2", &zproj2, &z0}; - VarSubtract x5_3{globals_, "x5_3", &zproj3, &z0}; - - VarMult x13_0{globals_, "x13_0", &x5_0, &invt, x13_max}; - VarMult x13_1{globals_, "x13_1", &x5_1, &invt, x13_max}; - VarMult x13_2{globals_, "x13_2", &x5_2, &invt, x13_max}; - VarMult x13_3{globals_, "x13_3", &x5_3, &invt, x13_max}; - - VarMult x25_0{globals_, "x25_0", &x13_0, &x7, 4 * settings_.dphisector()}; - VarMult x25_1{globals_, "x25_1", &x13_1, &x7, 4 * settings_.dphisector()}; - VarMult x25_2{globals_, "x25_2", &x13_2, &x7, 4 * settings_.dphisector()}; - VarMult x25_3{globals_, "x25_3", &x13_3, &x7, 4 * settings_.dphisector()}; - - VarAdd phiD_0{globals_, "phiD_0", &phi0, &x25_0, 4 * settings_.dphisector()}; - VarAdd phiD_1{globals_, "phiD_1", &phi0, &x25_1, 4 * settings_.dphisector()}; - VarAdd phiD_2{globals_, "phiD_2", &phi0, &x25_2, 4 * settings_.dphisector()}; - VarAdd phiD_3{globals_, "phiD_3", &phi0, &x25_3, 4 * settings_.dphisector()}; - - VarAdjustK phiD_0_final{globals_, "phiD_0_final", &phiD_0, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - VarAdjustK phiD_1_final{globals_, "phiD_1_final", &phiD_1, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - VarAdjustK phiD_2_final{globals_, "phiD_2_final", &phiD_2, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - VarAdjustK phiD_3_final{globals_, "phiD_3_final", &phiD_3, settings_.kphi1() * pow(2, settings_.SS_phiD_shift())}; - - VarMult der_phiD{globals_, "der_phiD", &x7, &invt, 8 * der_phiD_max}; - - VarAdjustK der_phiD_final{globals_, - "der_phiD_final", - &der_phiD, - settings_.kphi1() / settings_.kr() * pow(2, settings_.SS_phiderD_shift())}; - - VarMult x26_0{globals_, "x26_0", &x25_0, &x25_0}; - VarMult x26_1{globals_, "x26_1", &x25_1, &x25_1}; - VarMult x26_2{globals_, "x26_2", &x25_2, &x25_2}; - VarMult x26_3{globals_, "x26_3", &x25_3, &x25_3}; - - VarNounits x26A_0{globals_, "x26A_0", &x26_0}; - VarNounits x26A_1{globals_, "x26A_1", &x26_1}; - VarNounits x26A_2{globals_, "x26A_2", &x26_2}; - VarNounits x26A_3{globals_, "x26A_3", &x26_3}; - - VarTimesC x9_0{globals_, "x9_0", &x26A_0, 1. / 6.}; - VarTimesC x9_1{globals_, "x9_1", &x26A_1, 1. / 6.}; - VarTimesC x9_2{globals_, "x9_2", &x26A_2, 1. / 6.}; - VarTimesC x9_3{globals_, "x9_3", &x26A_3, 1. / 6.}; - - VarSubtract x27m_0{globals_, "x27_0", &plus1, &x9_0}; - VarSubtract x27m_1{globals_, "x27_1", &plus1, &x9_1}; - VarSubtract x27m_2{globals_, "x27_2", &plus1, &x9_2}; - VarSubtract x27m_3{globals_, "x27_3", &plus1, &x9_3}; - - VarMult rD_0{globals_, "rD_0", &x13_0, &x27m_0, settings_.rmaxdisk()}; - VarMult rD_1{globals_, "rD_1", &x13_1, &x27m_1, settings_.rmaxdisk()}; - VarMult rD_2{globals_, "rD_2", &x13_2, &x27m_2, settings_.rmaxdisk()}; - VarMult rD_3{globals_, "rD_3", &x13_3, &x27m_3, settings_.rmaxdisk()}; - - VarAdjustK rD_0_final{globals_, "rD_0_final", &rD_0, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - VarAdjustK rD_1_final{globals_, "rD_1_final", &rD_1, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - VarAdjustK rD_2_final{globals_, "rD_2_final", &rD_2, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - VarAdjustK rD_3_final{globals_, "rD_3_final", &rD_3, settings_.kr() * pow(2, settings_.PS_rD_shift())}; - - VarAdjustK der_rD_final{ - globals_, "der_rD_final", &invt, settings_.kr() / settings_.kz() * pow(2, settings_.PS_rderD_shift())}; - - VarCut t_final_cut{globals_, &t_final, -10, 10}; - VarCut rinv_final_cut{globals_, &rinv_final, -settings_.rinvcut(), settings_.rinvcut()}; - VarCut z0_final_cut{globals_, &z0_final, -settings_.z0cut(), settings_.z0cut()}; - - VarCut r1abs_cut{globals_, &r1abs, -settings_.rmax(5), settings_.rmax(5)}; - VarCut z2abs_cut{globals_, &z2abs, -settings_.zmax(4), settings_.zmax(4)}; - VarCut dr_cut{globals_, &dr, -dr_max, dr_max}; - VarCut dphi_cut{globals_, &dphi, -settings_.dphisector() / 4., settings_.dphisector() / 4.}; - VarCut dz_cut{globals_, &dz, -dz_max, dz_max}; - VarCut delta0_cut{globals_, &delta0, -delta0_max, delta0_max}; - VarCut deltaZ_cut{globals_, &deltaZ, -deltaZ_max, deltaZ_max}; - VarCut a2a_cut{globals_, &a2a, -a2a_max, a2a_max}; - VarCut a2_cut{globals_, &a2, -a2_max, a2_max}; - VarCut x6a_cut{globals_, &x6a, -x6a_max, x6a_max}; - VarCut x6m_cut{globals_, &x6m, -x6m_max, x6m_max}; - VarCut phi0a_cut{globals_, &phi0a, -settings_.dphisector(), settings_.dphisector()}; - VarCut z0a_cut{globals_, &z0a, -2 * settings_.zlength(), 2 * settings_.zlength()}; - VarCut phi0_cut{globals_, &phi0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut rinv_cut{globals_, &rinv, -settings_.maxrinv(), settings_.maxrinv()}; - VarCut t_cut{globals_, &t, -t_max, t_max}; - VarCut z0_cut{globals_, &z0, -z0_max, z0_max}; - VarCut x8_0_cut{globals_, &x8_0, -x8_max, x8_max}; - VarCut x8_1_cut{globals_, &x8_1, -x8_max, x8_max}; - VarCut x8_2_cut{globals_, &x8_2, -x8_max, x8_max}; - VarCut x22_0_cut{globals_, &x22_0, -x22_max, x22_max}; - VarCut x22_1_cut{globals_, &x22_1, -x22_max, x22_max}; - VarCut x22_2_cut{globals_, &x22_2, -x22_max, x22_max}; - VarCut x23_0_cut{globals_, &x23_0, -x23_max, x23_max}; - VarCut x23_1_cut{globals_, &x23_1, -x23_max, x23_max}; - VarCut x23_2_cut{globals_, &x23_2, -x23_max, x23_max}; - VarCut x13_0_cut{globals_, &x13_0, -x13_max, x13_max}; - VarCut x13_1_cut{globals_, &x13_1, -x13_max, x13_max}; - VarCut x13_2_cut{globals_, &x13_2, -x13_max, x13_max}; - VarCut x13_3_cut{globals_, &x13_3, -x13_max, x13_max}; - VarCut x25_0_cut{globals_, &x25_0, -settings_.dphisector(), settings_.dphisector()}; - VarCut x25_1_cut{globals_, &x25_1, -settings_.dphisector(), settings_.dphisector()}; - VarCut x25_2_cut{globals_, &x25_2, -settings_.dphisector(), settings_.dphisector()}; - VarCut x25_3_cut{globals_, &x25_3, -settings_.dphisector(), settings_.dphisector()}; - VarCut phiD_0_cut{globals_, &phiD_0, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut phiD_1_cut{globals_, &phiD_1, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut phiD_2_cut{globals_, &phiD_2, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut phiD_3_cut{globals_, &phiD_3, -2 * settings_.dphisector(), 2 * settings_.dphisector()}; - VarCut der_phiD_cut{globals_, &der_phiD, -der_phiD_max, der_phiD_max}; - VarCut rD_0_cut{globals_, &rD_0, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - VarCut rD_1_cut{globals_, &rD_1, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - VarCut rD_2_cut{globals_, &rD_2, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - VarCut rD_3_cut{globals_, &rD_3, -settings_.rmaxdisk(), settings_.rmaxdisk()}; - - VarCut t_disk_cut_left{globals_, &t, -t_disk_max, -t_disk_min}; - VarCut t_disk_cut_right{globals_, &t, t_disk_min, t_disk_max}; - VarCut t_layer_cut{globals_, &t, -t_layer_max, t_layer_max}; - - // the following flags are used to apply the cuts in TrackletCalculator - // and in the output Verilog - VarFlag valid_trackpar{globals_, "valid_trackpar", &rinv_final, &phi0_final, &t_final, &z0_final}; - - VarFlag valid_phiL_0{globals_, "valid_phiL_0", &phiL_0_final}; - VarFlag valid_phiL_1{globals_, "valid_phiL_1", &phiL_1_final}; - VarFlag valid_phiL_2{globals_, "valid_phiL_2", &phiL_2_final}; - - VarFlag valid_zL_0{globals_, "valid_zL_0", &zL_0_final}; - VarFlag valid_zL_1{globals_, "valid_zL_1", &zL_1_final}; - VarFlag valid_zL_2{globals_, "valid_zL_2", &zL_2_final}; - - VarFlag valid_der_phiL{globals_, "valid_der_phiL", &der_phiL_final}; - VarFlag valid_der_zL{globals_, "valid_der_zL", &der_zL_final}; - - VarFlag valid_phiD_0{globals_, "valid_phiD_0", &phiD_0_final}; - VarFlag valid_phiD_1{globals_, "valid_phiD_1", &phiD_1_final}; - VarFlag valid_phiD_2{globals_, "valid_phiD_2", &phiD_2_final}; - VarFlag valid_phiD_3{globals_, "valid_phiD_3", &phiD_3_final}; - - VarFlag valid_rD_0{globals_, "valid_rD_0", &rD_0_final}; - VarFlag valid_rD_1{globals_, "valid_rD_1", &rD_1_final}; - VarFlag valid_rD_2{globals_, "valid_rD_2", &rD_2_final}; - VarFlag valid_rD_3{globals_, "valid_rD_3", &rD_3_final}; - - VarFlag valid_der_phiD{globals_, "valid_der_phiD", &der_phiD_final}; - VarFlag valid_der_rD{globals_, "valid_der_rD", &der_rD_final}; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h b/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h deleted file mode 100644 index 3f4865598b388..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_MatchCalculator_h -#define L1Trigger_TrackFindingTracklet_interface_MatchCalculator_h - -#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" -#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" - -#include -#include - -namespace trklet { - - class Globals; - class Stub; - class L1TStub; - class Tracklet; - class AllStubsMemory; - class AllProjectionsMemory; - class CandidateMatchMemory; - class FullMatchMemory; - - class MatchCalculator : public ProcessBase { - public: - MatchCalculator(std::string name, Settings const& settings, Globals* global); - - ~MatchCalculator() override = default; - - void addOutput(MemoryBase* memory, std::string output) override; - void addInput(MemoryBase* memory, std::string input) override; - - void execute(unsigned int iSector, double phioffset); - - std::vector, const Stub*> > mergeMatches( - std::vector& candmatch); - - private: - unsigned int layerdisk_; - unsigned int phiregion_; - - int fact_; - int icorrshift_; - int icorzshift_; - int phi0shift_; - - TrackletLUT phimatchcuttable_; - TrackletLUT zmatchcuttable_; - - TrackletLUT rphicutPStable_; - TrackletLUT rphicut2Stable_; - TrackletLUT rcutPStable_; - TrackletLUT rcut2Stable_; - TrackletLUT alphainner_; - TrackletLUT alphaouter_; - TrackletLUT rSSinner_; - TrackletLUT rSSouter_; - - int ialphafactinner_[N_DSS_MOD * 2]; - int ialphafactouter_[N_DSS_MOD * 2]; - - AllStubsMemory* allstubs_; - AllProjectionsMemory* allprojs_; - - std::vector matches_; - std::vector fullMatches_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h deleted file mode 100644 index 10b76d002169b..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_MatchEngine_h -#define L1Trigger_TrackFindingTracklet_interface_MatchEngine_h - -#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" -#include - -namespace trklet { - - class Settings; - class Globals; - class MemoryBase; - class VMStubsMEMemory; - class VMProjectionsMemory; - class CandidateMatchMemory; - - class MatchEngine : public ProcessBase { - public: - MatchEngine(std::string name, Settings const& settings, Globals* global); - - ~MatchEngine() override = default; - - void addOutput(MemoryBase* memory, std::string output) override; - void addInput(MemoryBase* memory, std::string input) override; - - void execute(unsigned int iSector); - - private: - VMStubsMEMemory* vmstubs_; - VMProjectionsMemory* vmprojs_; - - CandidateMatchMemory* candmatches_; - - unsigned int layerdisk_; - - bool barrel_; - - unsigned int nrinv_; //number of bits for rinv in stub bend LUT - - //LUT for bend consistency - TrackletLUT luttable_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h index e4b5bf3cd7bc5..792a56f16c8de 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h @@ -44,7 +44,7 @@ namespace trklet { bool usesecondMinus, bool usesecondPlus, bool isPSseed, - Tracklet* proj); + Tracklet* proj, bool print); bool empty() const { return candmatches_.empty(); } @@ -69,9 +69,9 @@ namespace trklet { unsigned int rptr() const { return candmatches_.rptr(); } unsigned int wptr() const { return candmatches_.wptr(); } - void step(); + void step(bool print = false); - void processPipeline(); + void processPipeline(bool print = false); private: //Provide access to constants diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h index 5f3527ce29a4f..649df05a6c0dc 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h @@ -35,10 +35,19 @@ namespace trklet { bool matchCalculator(Tracklet* tracklet, const Stub* fpgastub, bool print, unsigned int istep); + void read_input_mems(bool &read_is_valid, + std::vector& mem_hasdata, + std::vector& nentries, + int &read_addr, + const std::vector& iMem, + const std::vector& iPage, + unsigned int &imem, + unsigned int &ipage); + + private: unsigned int layerdisk_; bool barrel_; - bool first_; unsigned int phiregion_; @@ -72,6 +81,12 @@ namespace trklet { //Number of r bits for the projection to use in LUT for disk int nrprojbits_; + //Pipeline variables for MatchCalculation + bool candidatematch_; + const Stub* fpgastub_; + Tracklet* tracklet_; + + AllStubsMemory* allstubs_; std::vector vmstubs_; std::vector inputprojs_; diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionCalculator.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionCalculator.h new file mode 100644 index 0000000000000..3e2ef592b310d --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/ProjectionCalculator.h @@ -0,0 +1,68 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_ProjectionCalculator_h +#define L1Trigger_TrackFindingTracklet_interface_ProjectionCalculator_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h" + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + + class ProjectionCalculator : public ProcessBase { + public: + ProjectionCalculator(std::string name, Settings const& settings, Globals* global); + + ~ProjectionCalculator() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + void projLayer(int ir, int irinv, int iphi0, int it,int iz0, int &iz, int &iphi); + + void projDisk(int iz, int irinv, int iphi0, int it,int iz0, int &ir, int &iphi, int &iderphi, int &iderr); + + private: + + std::vector > > outputproj_; // projs now stored by layer/disk & phi region + + std::vector inputpars_; + std::vector outputpars_; + std::vector projnames_; + + //Constants for coordinates and track parameter definitions + int n_phi_; + int n_r_; + int n_z_; + int n_phi0_; + int n_rinv_; + int n_t_; + int n_phidisk_; + int n_rdisk_; + + //Constants used for projectison to layers + int n_s_; + int n_s6_; + + //Constants used for projectison to disks + int n_tinv_; + int n_y_; + int n_x_; + int n_xx6_; + + unsigned int nMergedTC[8] = {6, 1, 2, 1, 1, 1, 2, 1}; + + double phiHG_; + + std::vector LUT_itinv_; + + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h deleted file mode 100644 index 230de71eb656d..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_ProjectionRouter_h -#define L1Trigger_TrackFindingTracklet_interface_ProjectionRouter_h - -#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" -#include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h" - -namespace trklet { - - class Settings; - class Globals; - class MemoryBase; - - class ProjectionRouter : public ProcessBase { - public: - ProjectionRouter(std::string name, Settings const& settings, Globals* global); - - ~ProjectionRouter() override = default; - - void addOutput(MemoryBase* memory, std::string output) override; - void addInput(MemoryBase* memory, std::string input) override; - - void execute(); - - private: - unsigned int layerdisk_; - - int nrbits_; - int nphiderbits_; - - //disk projectionrinv table - TrackletLUT rinvbendlut_; - - std::vector inputproj_; - - AllProjectionsMemory* allproj_; - std::vector vmprojs_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Sector.h b/L1Trigger/TrackFindingTracklet/interface/Sector.h index eb724e2d003c7..ec774b4c3ce13 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Sector.h +++ b/L1Trigger/TrackFindingTracklet/interface/Sector.h @@ -31,31 +31,21 @@ namespace trklet { class AllInnerStubsMemory; class VMStubsTEMemory; class VMStubsMEMemory; - class StubPairsMemory; class StubTripletsMemory; class TrackletParametersMemory; class TrackletProjectionsMemory; - class AllProjectionsMemory; - class VMProjectionsMemory; - class CandidateMatchMemory; class FullMatchMemory; class TrackFitMemory; class CleanTrackMemory; //Processing modules class InputRouter; - class VMRouter; class VMRouterCM; - class TrackletEngine; - class TrackletEngineDisplaced; - class TripletEngine; - class TrackletCalculator; class TrackletProcessor; class TrackletProcessorDisplaced; class TrackletCalculatorDisplaced; - class ProjectionRouter; - class MatchEngine; - class MatchCalculator; + class ProjectionCalculator; + class VMStubMERouter; class MatchProcessor; class FitTrack; class PurgeDuplicate; @@ -90,13 +80,9 @@ namespace trklet { void writeVMSME(bool first); void writeAS(bool first); void writeAIS(bool first); - void writeSP(bool first); void writeST(bool first); void writeTPAR(bool first); void writeTPROJ(bool first); - void writeAP(bool first); - void writeVMPROJ(bool first); - void writeCM(bool first); void writeMC(bool first); void writeTF(bool first); void writeCT(bool first); @@ -106,16 +92,13 @@ namespace trklet { // execute the different tracklet processing modules void executeIR(); void executeVMR(); - void executeTE(); void executeTED(); void executeTRE(); void executeTP(); void executeTPD(); - void executeTC(); void executeTCD(); - void executePR(); - void executeME(); - void executeMC(); + void executePC(); + void executeVMSMER(); void executeMP(); void executeFT(std::vector>& streamsTrackRaw, std::vector>& streamsStubRaw); @@ -157,31 +140,21 @@ namespace trklet { std::vector> AIS_; std::vector> VMSTE_; std::vector> VMSME_; - std::vector> SP_; std::vector> ST_; std::vector> TPAR_; std::vector> TPROJ_; - std::vector> AP_; - std::vector> VMPROJ_; - std::vector> CM_; std::vector> FM_; std::vector> TF_; std::vector> CT_; std::map Processes_; std::vector> IR_; - std::vector> VMR_; std::vector> VMRCM_; - std::vector> TE_; - std::vector> TED_; - std::vector> TRE_; std::vector> TP_; std::vector> TPD_; - std::vector> TC_; std::vector> TCD_; - std::vector> PR_; - std::vector> ME_; - std::vector> MC_; + std::vector> PC_; + std::vector> VMSMER_; std::vector> MP_; std::vector> FT_; std::vector> PD_; diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index 9675d6ae85dbe..14259e2a51568 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -27,6 +27,7 @@ namespace trklet { constexpr unsigned int N_PSLAYER = 3; // # of barrel PS layers assumed constexpr unsigned int N_SEED = 12; // # of tracklet+triplet seeds constexpr unsigned int N_SEED_PROMPT = 8; // # of tracklet (prompt) seeds + constexpr unsigned int N_TB = 2; // # of track builders constexpr unsigned int N_DSS_MOD = 5; // # of rings with 2S modules per disk @@ -88,6 +89,7 @@ namespace trklet { void setTableTEDFile(std::string tableTEDFileName) { tableTEDFile_ = tableTEDFileName; } void setTableTREFile(std::string tableTREFileName) { tableTREFile_ = tableTREFileName; } + unsigned int nndbitsstub(unsigned int layerdisk) const { return nndbitsstub_[layerdisk]; } unsigned int nzbitsstub(unsigned int layerdisk) const { return nzbitsstub_[layerdisk]; } unsigned int nphibitsstub(unsigned int layerdisk) const { return nphibitsstub_[layerdisk]; } unsigned int nrbitsstub(unsigned int layerdisk) const { return nrbitsstub_[layerdisk]; } @@ -171,9 +173,11 @@ namespace trklet { double rphicut2S(unsigned int iSeed, unsigned int idisk) const { return rphicut2S_[idisk][iSeed]; } double rcut2S(unsigned int iSeed, unsigned int idisk) const { return rcut2S_[idisk][iSeed]; } + unsigned int irmean(unsigned int iLayer) const { return irmean_[iLayer]; } double rmean(unsigned int iLayer) const { return irmean_[iLayer] * rmaxdisk_ / 4096; } double rmax(unsigned int iLayer) const { return rmean(iLayer) + drmax(); } double rmin(unsigned int iLayer) const { return rmean(iLayer) - drmax(); } + unsigned int izmean(unsigned int iDisk) const { return izmean_[iDisk]; } double zmean(unsigned int iDisk) const { return izmean_[iDisk] * zlength_ / 2048; } double zmax(unsigned int iDisk) const { return zmean(iDisk) + dzmax(); } double zmin(unsigned int iDisk) const { return zmean(iDisk) - dzmax(); } @@ -349,7 +353,9 @@ namespace trklet { double kz() const { return 2.0 * zlength_ / (1 << nzbitsstub_[0]); } double kz(unsigned int layerdisk) const { return 2.0 * zlength_ / (1 << nzbitsstub_[layerdisk]); } - double kr() const { return rmaxdisk_ / (1 << nrbitsstub_[N_LAYER]); } + double kr() const { + return rmaxdisk_ / (1 << (nrbitsstub_[N_LAYER] + 1)); + } // + 1 required to offset artificial decrease in # of diskps r bits from 12 -> 11 to make space for negDisk bit double krbarrel() const { return 2.0 * drmax() / (1 << nrbitsstub_[0]); } double maxrinv() const { return maxrinv_; } @@ -532,9 +538,10 @@ namespace trklet { std::array irmean_{{851, 1269, 1784, 2347, 2936, 3697}}; std::array izmean_{{2239, 2645, 3163, 3782, 4523}}; + std::array nndbitsstub_{{0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}}; std::array nzbitsstub_{{12, 12, 12, 8, 8, 8, 7, 7, 7, 7, 7}}; std::array nphibitsstub_{{14, 14, 14, 17, 17, 17, 14, 14, 14, 14, 14}}; - std::array nrbitsstub_{{7, 7, 7, 7, 7, 7, 12, 12, 12, 12, 12}}; + std::array nrbitsstub_{{7, 7, 7, 7, 7, 7, 11, 11, 11, 11, 11}}; unsigned int nrbitsprojderdisk_{9}; unsigned int nbitsphiprojderL123_{10}; @@ -883,7 +890,7 @@ namespace trklet { //IR should be set to 108 to match the FW for the summer chain, but ultimately should be at 156 std::unordered_map maxstep_{ - {"IR", 156}, //IR will run at a higher clock speed to handle + {"IR", 108}, //IR will run at a higher clock speed to handle //input links running at 25 Gbits/s //Set to 108 to match firmware project 240 MHz clock @@ -953,9 +960,9 @@ namespace trklet { bool warnNoDer_{false}; //If true will print out warnings about missing track fit derivatives //--- These used to create files needed by HLS code. - bool writeMem_{false}; //If true will print out content of memories (between algo steps) to files - bool writeTable_{false}; //If true will print out content of LUTs to files - bool writeConfig_{false}; //If true will print out the autogenerated configuration as files + bool writeMem_{true}; //If true will print out content of memories (between algo steps) to files + bool writeTable_{true}; //If true will print out content of LUTs to files + bool writeConfig_{true}; //If true will print out the autogenerated configuration as files std::string memPath_{"../data/MemPrints/"}; //path for writing memories std::string tablePath_{"../data/LUTs/"}; //path for writing LUTs @@ -1024,7 +1031,7 @@ namespace trklet { // This is a temporary fix for compatibilty with HLS. We will need to implement multiple match // printing in emulator eventually, possibly after CMSSW-integration inspired rewrites // Use false when generating HLS files, use true when doing full hybrid tracking - bool doMultipleMatches_{true}; + bool doMultipleMatches_{false}; // NEXT 2 VALUES OVERRIDDEN BY PYTHON CFG // if true, run a dummy fit, producing TTracks directly from output of tracklet pattern reco stage @@ -1047,7 +1054,7 @@ namespace trklet { // Use chain with duplicated MPs for L3,L4 to reduce truncation issue // Balances load from projections roughly in half for each of the two MPs - bool duplicateMPs_{false}; + bool duplicateMPs_{true}; // Determines which layers, disks the MatchProcessor is duplicated for // (note: in TCB by default always duplicated for phi B, C as truncation is significantly worse than A, D) @@ -1055,12 +1062,12 @@ namespace trklet { // EqualProjBalancing is for layers for which the projections to each duplicated MP are split in half sequentially std::array layersDisksDuplicatedEqualProjBalance_{ - {false, false, false, false, false, false, false, false, false, false, false}}; + {false, false, true, true, true, true, false, false, true, true, false}}; // Weighted proj balancing is for specifically L4, L5 where the split of the projections is weighted to account for // Higher occupancy in the L1L2 seed to minimize truncation std::array layersDisksDuplicatedWeightedProjBalance_{ - {false, false, false, false, false, false, false, false, false, false, false}}; + {false, false, true, true, true, true, false, false, true, true, false}}; // Example use where for L3, L4, L5, D2, D3, the layers/disks where truncation is worst //std::array layersDisksDuplicatedEqualProjBalance_{{0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0}}; diff --git a/L1Trigger/TrackFindingTracklet/interface/Stub.h b/L1Trigger/TrackFindingTracklet/interface/Stub.h index 6a2dc6bd21f6f..9b17919786b9f 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Stub.h +++ b/L1Trigger/TrackFindingTracklet/interface/Stub.h @@ -30,9 +30,10 @@ namespace trklet { return r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + bend_.str(); } else { if (isPSmodule()) { - return r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + bend_.str(); + return negdisk_.str() + "|" + r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + bend_.str(); } else { - return "000" + r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + alpha_.str() + "|" + bend_.str(); + return negdisk_.str() + "|" + "00" + r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + alpha_.str() + "|" + + bend_.str(); } } } @@ -43,11 +44,7 @@ namespace trklet { unsigned int nbitsfinephi = 8; FPGAWord finephi( phicorr_.bits(phicorr_.nbits() - nbitsfinephi, nbitsfinephi), nbitsfinephi, true, __LINE__, __FILE__); - if (layer_.value() == -1) { - return str() + "|" + negdisk_.str() + "|" + stubindex_.str() + "|" + finephi.str(); - } else { - return str() + "|" + stubindex_.str() + "|" + finephi.str(); - } + return str() + "|" + stubindex_.str() + "|" + finephi.str(); } FPGAWord allStubIndex() const { return stubindex_; } @@ -62,6 +59,10 @@ namespace trklet { const FPGAWord& bend() const { return bend_; } + const int rvalue() const { + return (layerdisk_ < N_LAYER) ? r_.value() : (r_.value() > 10) ? r_.value() + (1 << r_offset_bits) : r_.value(); + } + const FPGAWord& r() const { return r_; } const FPGAWord& z() const { return z_; } const FPGAWord& negdisk() const { return negdisk_; } @@ -103,6 +104,8 @@ namespace trklet { FPGAWord stubindex_; + int r_offset_bits; + L1TStub* l1tstub_; Settings const& settings_; }; diff --git a/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h b/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h deleted file mode 100644 index 9f87f84ee490f..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_StubPairsMemory_h -#define L1Trigger_TrackFindingTracklet_interface_StubPairsMemory_h - -#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMStubTE.h" - -#include - -namespace trklet { - - class Settings; - - class StubPairsMemory : public MemoryBase { - public: - StubPairsMemory(std::string name, Settings const& settings); - - ~StubPairsMemory() override = default; - - void addStubPair(const VMStubTE& stub1, - const VMStubTE& stub2, - const unsigned index = 0, - const std::string& tedName = "") { - stubs_.emplace_back(stub1, stub2); - indices_.push_back(index); - tedNames_.push_back(tedName); - } - - unsigned int nStubPairs() const { return stubs_.size(); } - - const VMStubTE& getVMStub1(unsigned int i) const { return stubs_[i].first; } - const VMStubTE& getVMStub2(unsigned int i) const { return stubs_[i].second; } - - unsigned getIndex(const unsigned i) const { return indices_.at(i); } - const std::string& getTEDName(const unsigned i) const { return tedNames_.at(i); } - - void clean() override { - stubs_.clear(); - indices_.clear(); - tedNames_.clear(); - } - - void writeSP(bool first, unsigned int iSector); - - private: - std::vector > stubs_; - - std::vector indices_; - std::vector tedNames_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/Tracklet.h b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h index 01b038a8e4a9e..d3c7aa605d99e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Tracklet.h +++ b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h @@ -46,7 +46,6 @@ namespace trklet { int id0, int iz0, int it, - Projection projs[N_LAYER + N_DISK], bool disk, bool overlap = false); @@ -79,6 +78,8 @@ namespace trklet { std::string trackletprojstrlayer(int layer) const { return trackletprojstr(layer); } std::string trackletprojstrdisk(int disk) const { return trackletprojstrD(disk); } + void addProjs(Projection projs[N_LAYER + N_DISK]); + bool validProj(int layerdisk) const { assert(layerdisk >= 0 && layerdisk < N_LAYER + N_DISK); return proj_[layerdisk].valid(); diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h deleted file mode 100644 index a271bab238d69..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletCalculator_h -#define L1Trigger_TrackFindingTracklet_interface_TrackletCalculator_h - -#include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h" - -#include -#include - -namespace trklet { - - class Settings; - class Globals; - class TrackletProjectionsMemory; - class MemoryBase; - class AllStubsMemory; - class StubPairsMemory; - class VarInv; - class VarBase; - - class TrackletCalculator : public TrackletCalculatorBase { - public: - TrackletCalculator(std::string name, Settings const& settings, Globals* globals); - - ~TrackletCalculator() override = default; - - void addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory); - void addOutput(MemoryBase* memory, std::string output) override; - void addInput(MemoryBase* memory, std::string input) override; - - void execute(unsigned int iSector, double phimin, double phimax); - - private: - int iTC_; - - std::vector innerallstubs_; - std::vector outerallstubs_; - std::vector stubpairs_; - - void writeInvTable(void (*writeLUT)(const VarInv&, const std::string&)); - void writeFirmwareDesign(void (*writeDesign)(const std::vector&, const std::string&)); - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h index 4638b07f5e5a9..0184174ed6133 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h @@ -21,6 +21,8 @@ namespace trklet { ~TrackletCalculatorBase() override = default; + void init(int iSeed); + void exacttracklet(double r1, double z1, double phi1, @@ -101,6 +103,14 @@ namespace trklet { double& phider, double& rder); + + void projlayer(int ir, int irinv, int iphi0, int it,int iz0, int &iz, int &iphi); // lower case to differentiate from ProjectionCalculator functions + + void projdisk(int iz, int irinv, int iphi0, int it,int iz0, int &ir, int &iphi, int &iderphi, int &iderr); + + void calcPars(unsigned int idr, int iphi1, int ir1, int iz1, int iphi2, int ir2, int iz2, + int &irinv_new, int &iphi0_new, int &iz0_new, int &it_new); + void addDiskProj(Tracklet* tracklet, int disk); bool addLayerProj(Tracklet* tracklet, int layer); @@ -118,11 +128,14 @@ namespace trklet { bool diskSeeding(const Stub* innerFPGAStub, const L1TStub* innerStub, const Stub* outerFPGAStub, - const L1TStub* outerStub); + const L1TStub* outerStub, + bool print = false); bool overlapSeeding(const Stub* innerFPGAStub, const L1TStub* innerStub, const Stub* outerFPGAStub, - const L1TStub* outerStub); + const L1TStub* outerStub, + bool print = false); + protected: unsigned int iSeed_; @@ -133,12 +146,53 @@ namespace trklet { unsigned int iSector_; double phimin_, phimax_; + double phiHG_; + + TrackletParametersMemory* trackletpars_; //First index is layer/disk second is phi region std::vector > trackletprojlayers_; std::vector > trackletprojdisks_; + + //Constants for coordinates and track parameter definitions + int n_phi_; + int n_r_; + int n_z_; + int n_phi0_; + int n_rinv_; + int n_t_; + int n_phidisk_; + int n_rdisk_; + + //Constants used for tracklet parameter calculations + int n_Deltar_; + int n_delta0_; + int n_deltaz_; + int n_delta1_; + int n_delta2_; + int n_delta12_; + int n_a_; + int n_r6_; + int n_delta02_; + int n_x6_; + int n_HG_; + + //Constants used for projectison to layers + int n_s_; + int n_s6_; + + //Constants used for projectison to disks + int n_tinv_; + int n_y_; + int n_x_; + int n_xx6_; + + std::vector LUT_itinv_; + std::vector LUT_idrinv_; + + }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h index f451c05ad95a7..86d4174331b5a 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h @@ -38,26 +38,38 @@ namespace trklet { //Seed string, eg. L1L2 std::string iSeedStr(unsigned int iSeed) const; + //TB string, AAAA or BBBB + std::string iTBStr(unsigned int iTB) const; + //Return unsigned as string static std::string numStr(unsigned int i); //Return iTC as string - ie A, B, C, etc std::string iTCStr(unsigned int iTC) const; + //Return iTC as string - ie AB, CD, ABC, etc + static std::string iMergedTCStr(unsigned int iSeed, unsigned int iMergedTC); + //The region string A, B, C etc for layers and disks; X, Y, Z etc for overlap std::string iRegStr(unsigned int iReg, unsigned int iSeed) const; //TC Name std::string TCName(unsigned int iSeed, unsigned int iTC) const; + //TC Name + std::string PCName(unsigned int iSeed, unsigned int iMergedTC) const; + //Name of layer or disk, e.g. L1 or D1 static std::string LayerName(unsigned int ilayer); //Tracklet projection name std::string TPROJName(unsigned int iSeed, unsigned int iTC, unsigned int ilayer, unsigned int ireg) const; - //Projection router name - std::string PRName(unsigned int ilayer, unsigned int ireg) const; + //Merged tracklet projection name + std::string MPROJName(unsigned int iSeed, unsigned int iTC, unsigned int ilayer, unsigned int ireg) const; + + //MatchProcessor name + std::string MPName(unsigned int ilayer, unsigned int ireg) const; private: // @@ -199,18 +211,10 @@ namespace trklet { // // This group of methods are used to print out the configuration as a file // - void writeProjectionMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); - - void writeSPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + void writeMergedProjectionMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); void writeSPDMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); - void writeAPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); - - void writeCMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); - - void writeVMPROJMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); - void writeFMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); void writeASMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); @@ -269,7 +273,7 @@ namespace trklet { //The projections to each layer/disk from a seed and TC std::vector > > projections_[N_LAYER + N_DISK]; - + //Which matches are used for each seeding layer // L1 L2 L3 L4 L5 L6 D1 D2 D3 D4 D5 int matchport_[N_SEED_PROMPT][N_LAYER + N_DISK] = {{-1, -1, 1, 2, 3, 4, 4, 3, 2, 1, -1}, //L1L2 @@ -281,6 +285,11 @@ namespace trklet { {-1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 4}, //L1D1 {1, -1, -1, -1, -1, -1, -1, 2, 3, 4, -1}}; //L2D1 + //Which seeds handled by each TB + int tbseed_[N_TB][4] = {{0, 1, 3, 7}, + {2, 4, 5, 6}}; + + struct DTCinfo { std::string name; int layer; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h deleted file mode 100644 index 054f66bca1b47..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletEngine_h -#define L1Trigger_TrackFindingTracklet_interface_TrackletEngine_h - -#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" - -#include -#include - -namespace trklet { - - class Settings; - class Globals; - class MemoryBase; - class VMStubsTEMemory; - class StubPairsMemory; - - class TrackletEngine : public ProcessBase { - public: - TrackletEngine(std::string name, Settings const& settings, Globals* global); - - ~TrackletEngine() override = default; - - void addOutput(MemoryBase* memory, std::string output) override; - void addInput(MemoryBase* memory, std::string input) override; - - void execute(); - - void setVMPhiBin(); - - private: - //Which seed type and which layer/disk is used - unsigned int iSeed_; - unsigned int layerdisk1_; //inner seeding layer - unsigned int layerdisk2_; //outer seeding layer - - //The input vmstubs memories - VMStubsTEMemory* innervmstubs_; - VMStubsTEMemory* outervmstubs_; - - //The output stub pair memory - StubPairsMemory* stubpairs_; - - //The stub pt (bend) lookup table for the inner and outer stub - TrackletLUT innerptlut_; - TrackletLUT outerptlut_; - - //Number of phi bits used in the lookup table - unsigned int innerphibits_; - unsigned int outerphibits_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h deleted file mode 100644 index 91ea9e6ad4ee8..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h +++ /dev/null @@ -1,54 +0,0 @@ -// TrackletEngineDisplaced: this class forms tracklets (pairs of stubs) w/o beamspot constraint for the displaced (extended) tracking. -// Triplet seeds are formed in the TripletEngine from these (=TrackletEngineDisplaced) + a third stub. -#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletEngineDisplaced_h -#define L1Trigger_TrackFindingTracklet_interface_TrackletEngineDisplaced_h - -#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" - -#include -#include -#include - -namespace trklet { - - class Settings; - class Globals; - class MemoryBase; - class VMStubsTEMemory; - class StubPairsMemory; - - class TrackletEngineDisplaced : public ProcessBase { - public: - TrackletEngineDisplaced(std::string name, Settings const& settings, Globals* global); - - ~TrackletEngineDisplaced() override; - - void addOutput(MemoryBase* memory, std::string output) override; - void addInput(MemoryBase* memory, std::string input) override; - - void execute(); - - void readTables(); - - short memNameToIndex(const std::string& name); - - private: - int layer1_; - int layer2_; - int disk1_; - int disk2_; - - std::vector firstvmstubs_; - VMStubsTEMemory* secondvmstubs_; - - std::vector stubpairs_; - - std::vector > table_; - - int firstphibits_; - int secondphibits_; - - int iSeed_; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h index e617ef173e6ea..03d2a4b0b9fe9 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h @@ -57,16 +57,10 @@ namespace trklet { Timer addStubTimer_; Timer InputRouterTimer_; Timer VMRouterTimer_; - Timer TETimer_; - Timer TEDTimer_; - Timer TRETimer_; Timer TPTimer_; Timer TPDTimer_; - Timer TCTimer_; - Timer TCDTimer_; - Timer PRTimer_; - Timer METimer_; - Timer MCTimer_; + Timer PCTimer_; + Timer VMSMERTimer_; Timer MPTimer_; Timer FTTimer_; Timer PDTimer_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h index 7a81bececba65..aed59ce403a17 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h @@ -20,18 +20,23 @@ namespace trklet { ~TrackletParametersMemory() override = default; - void addTracklet(Tracklet *tracklet) { tracklets_.push_back(tracklet); } + void addTracklet(Tracklet *tracklet,unsigned int page = 0) { tracklets_[page].push_back(tracklet); } - unsigned int nTracklets() const { return tracklets_.size(); } + unsigned int nTracklets(unsigned int page = 0) const { return tracklets_[page].size(); } - Tracklet *getTracklet(unsigned int i) { return tracklets_[i]; } + Tracklet *getTracklet(unsigned int i, unsigned int page = 0) { return tracklets_[page][i]; } + + unsigned int nPage() const { return npage_; } void clean() override; void writeTPAR(bool first, unsigned int iSector); private: - std::vector tracklets_; + + std::vector > tracklets_; + unsigned int npage_; + }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h index 038306d981a63..a2a0ff9fd9b74 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h @@ -22,12 +22,14 @@ namespace trklet { } }; - void addProj(Tracklet* tracklet); + void addProj(Tracklet* tracklet, unsigned int page = 0); - unsigned int nTracklets() const { return tracklets_.size(); } - - Tracklet* getTracklet(unsigned int i) { return tracklets_[i]; } + unsigned int nTracklets(unsigned int page = 0) const { return tracklets_[page].size(); } + Tracklet* getTracklet(unsigned int i, unsigned int page = 0) { return tracklets_[page][i]; } + + unsigned int nPage() const { return npage_; } + void clean() override; void writeTPROJ(bool first, unsigned int iSector); @@ -36,11 +38,12 @@ namespace trklet { int disk() const { return disk_; } private: - std::vector tracklets_; + std::vector< std::vector > tracklets_; bool hasProj_; int layer_; int disk_; + int npage_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h b/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h deleted file mode 100644 index ad5840af13a0e..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h +++ /dev/null @@ -1,70 +0,0 @@ -// TripletEngine: Adds third stub to stub pairs found by TrackletEngineDisplaced to form "triplet" seeds for the displaced (extended) tracking -#ifndef L1Trigger_TrackFindingTracklet_interface_TripletEngine_h -#define L1Trigger_TrackFindingTracklet_interface_TripletEngine_h - -#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" - -#include -#include - -namespace trklet { - - class Settings; - class Globals; - - class TripletEngine : public ProcessBase { - public: - TripletEngine(std::string name, Settings const& settings, Globals* global); - - ~TripletEngine() override; - - void addOutput(MemoryBase* memory, std::string output) override; - void addInput(MemoryBase* memory, std::string input) override; - - void execute(); - - void readTables(); - void writeTables(); - - private: - int count_; - - int layer1_; - int layer2_; - int layer3_; - int disk1_; - int disk2_; - int disk3_; - int dct1_; - int dct2_; - int dct3_; - int phi1_; - int phi2_; - int phi3_; - int z1_; - int z2_; - int z3_; - int r1_; - int r2_; - int r3_; - - std::vector thirdvmstubs_; - std::vector stubpairs_; - - StubTripletsMemory* stubtriplets_; - - std::map > > tmpSPTable_; - std::map > > spTable_; - std::vector table_; - - int secondphibits_; - int thirdphibits_; - - int iSeed_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h deleted file mode 100644 index 47f15743dc6c8..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h +++ /dev/null @@ -1,41 +0,0 @@ -// VMProjectionsMemory: Class to hold a reduced format of the tracklet projections (from ProjectionRouter) -#ifndef L1Trigger_TrackFindingTracklet_interface_VMProjectionsMemory_h -#define L1Trigger_TrackFindingTracklet_interface_VMProjectionsMemory_h - -#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" - -#include - -namespace trklet { - - class Settings; - class Tracklet; - - class VMProjectionsMemory : public MemoryBase { - public: - VMProjectionsMemory(std::string name, Settings const& settings); - - ~VMProjectionsMemory() override = default; - - void addTracklet(Tracklet* tracklet, unsigned int allprojindex); - - unsigned int nTracklets() const { return tracklets_.size(); } - - Tracklet* getTracklet(unsigned int i) { return tracklets_[i].first; } - int getAllProjIndex(unsigned int i) const { return tracklets_[i].second; } - - void writeVMPROJ(bool first, unsigned int iSector); - - void clean() override { tracklets_.clear(); } - - int layer() const { return layer_; } - int disk() const { return disk_; } - - private: - int layer_; - int disk_; - std::vector > tracklets_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouter.h b/L1Trigger/TrackFindingTracklet/interface/VMRouter.h deleted file mode 100644 index 5f5fc7ae6d981..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouter.h +++ /dev/null @@ -1,77 +0,0 @@ -// VMRouter: sorts input stubs into smaller units in phi (and possibly z), referred to as "Virtual Modules" (VMs) -#ifndef L1Trigger_TrackFindingTracklet_interface_VMRouter_h -#define L1Trigger_TrackFindingTracklet_interface_VMRouter_h - -#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" -#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" - -#include -#include -#include - -namespace trklet { - - class Settings; - class Globals; - class MemoryBase; - class InputLinkMemory; - class AllStubsMemory; - class VMStubsMEMemory; - class VMStubsTEMemory; - - struct VMStubsTEPHI { - VMStubsTEPHI(unsigned int seednumber_, - unsigned int stubposition_, - std::vector > vmstubmem_) - : seednumber(seednumber_), stubposition(stubposition_), vmstubmem(vmstubmem_) {} - - unsigned int seednumber; //seed number [0,11] - unsigned int stubposition; //stub position in the seed - std::vector > - vmstubmem; // m_vmstubmem[iVM][n] is the VMStubsTEMemory for iVM and the nth copy - }; - - class VMRouter : public ProcessBase { - public: - VMRouter(std::string name, Settings const& settings, Globals* global); - - ~VMRouter() override = default; - - void addOutput(MemoryBase* memory, std::string output) override; - void addInput(MemoryBase* memory, std::string input) override; - - void execute(); - - private: - //0-5 are the layers and 6-10 are the disks - unsigned int layerdisk_; - - //overlapbits_ is the top bits of phicorr used to add or subtract one to see if stub should be added to - //two VMs. nextrabits_ is the number of bits beyond the bits for the phivm that is used by overlapbits_ - unsigned int overlapbits_; - unsigned int nextrabits_; - - int nbitszfinebintable_; - int nbitsrfinebintable_; - - TrackletLUT meTable_; //used for ME and outer TE barrel - TrackletLUT diskTable_; //outer disk used by D1, D2, and D4 - TrackletLUT innerTable_; //projection to next layer/disk - TrackletLUT innerOverlapTable_; //projection to disk from layer - TrackletLUT innerThirdTable_; //projection to disk1 for extended - iseed=10 - - //The input stub memories the two tmp inputs are used to build the order needed in HLS - std::vector stubinputs_, stubinputtmp_, stubinputdisk2stmp_; - - //The all stub memories - std::vector allstubs_; - - //The VM stubs memories used by the MEs - std::vector vmstubsMEPHI_; - - //The VM stubs memories used by the TEs (using structure defined above) - std::vector vmstubsTEPHI_; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h index 38c3286b4c286..369caf1362d9f 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h @@ -55,12 +55,12 @@ namespace trklet { //two VMs. nextrabits_ is the number of bits beyond the bits for the phivm that is used by overlapbits_ unsigned int overlapbits_; unsigned int nextrabits_; - + int nbitszfinebintable_; int nbitsrfinebintable_; unsigned int nvmmebins_; //number of long z/r bins in VM - + TrackletLUT meTable_; //used for ME and outer TE barrel TrackletLUT diskTable_; //outer disk used by D1, D2, and D4 @@ -79,9 +79,6 @@ namespace trklet { std::vector allstubs_; std::vector > allinnerstubs_; - //The VM stubs memories used by the MEs - std::vector vmstubsMEPHI_; - //The VM stubs memories used by the TEs (using structure defined above) std::vector vmstubsTEPHI_; }; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubMERouter.h b/L1Trigger/TrackFindingTracklet/interface/VMStubMERouter.h new file mode 100644 index 0000000000000..4b1ead41f2569 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubMERouter.h @@ -0,0 +1,58 @@ +// VMStubMERouter: sorts input stubs into smaller units in phi (and possibly z), referred to as "Virtual Modules" (VMs) - implementation for combined modules +#ifndef L1Trigger_TrackFindingTracklet_interface_VMStubMERouter_h +#define L1Trigger_TrackFindingTracklet_interface_VMStubMERouter_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" + +#include +#include +#include + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + class AllStubsMemory; + class VMStubsMEMemory; + + class VMStubMERouter : public ProcessBase { + public: + VMStubMERouter(std::string name, Settings const& settings, Globals* global); + + ~VMStubMERouter() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(unsigned int iSector); + + private: + //0-5 are the layers and 6-10 are the disks + unsigned int layerdisk_; + + int nbitszfinebintable_; + int nbitsrfinebintable_; + + unsigned int nvmmebins_; //number of long z/r bins in VM + + TrackletLUT meTable_; //used for ME and outer TE barrel + + //The input stub memories + std::vector stubinputs_; + + //The all stub memories + std::vector allstubs_; + + //The VM stubs memories used by the MEs + std::vector vmstubsinput_; + + //The VM stubs memories used by the MEs + std::vector vmstubsMEPHI_; + }; +}; // namespace trklet + +#endif + diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h index ee85a668da883..df95d6f8172e1 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h @@ -27,6 +27,8 @@ namespace trklet { void resize(int nbins) { binnedstubs_.resize(nbins); } + unsigned int size() { return binnedstubs_.size(); } + unsigned int nStubsBin(unsigned int bin) const { assert(bin < binnedstubs_.size()); return binnedstubs_[bin].size(); @@ -54,6 +56,7 @@ namespace trklet { private: std::vector > binnedstubs_; + unsigned int layerdisk_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/imath.h b/L1Trigger/TrackFindingTracklet/interface/imath.h deleted file mode 100644 index a3e5ad3f597d2..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/imath.h +++ /dev/null @@ -1,1122 +0,0 @@ -// // Integer representation of floating point arithmetic suitable for FPGA designs -// -// Author: Yuri Gershtein -// Date: March 2018 -// -// Functionality: -// -// *note* all integers are assumed to be signed -// -// all variables have units, stored in a map , with string a unit (i.e. "phi") and int the power -// "2" is always present in the map, and it's int pair is referred to as 'shift' -// units are properly combined / propagated through calculations -// adding/subtracting variables with different units throws an exception -// adding/subtracting variables with different shifts is allowed and is handled correctly -// -// calculate() method re-calculates the variable double and int values based on its operands -// returns false in case of overflows and/or mismatches between double and int calculations. -// -// the maximum and minimum values that the variable assumes are stored and updated each time calculate() is called -// if IMATH_ROOT is defined, all values are also stored in a histogram -// -// VarDef (string name, string units, double fmax, double K): -// define variable with bit value fval = K*ival, and maximum absolute value fmax. -// calculates nbins on its own -// one can assign value to it using set_ methods -// -// VarParam (string name, string units, double fval, int nbits): -// define a parameter. K is calculated based on the fval and nbits -// -// or (string name, std::string units, double fval, double K): -// define a parameer with bit value fval = K*ival. -// calculates nbins on its own -// -// VarAdd (string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18): -// VarSubtract(string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18): -// add/subtract variables. Bit length increases by 1, but capped at nmax -// if range>0 specified, bit length is decreased to drop unnecessary high bits -// -// VarMult (string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18): -// multiplication. Bit length is a sum of the lengths of the operads, but capped at nmax -// if range>0 specified, bit length is decreased to drop unnecessary high bits or post-shift is reduced -// -// VarTimesC (string name, VarBase *p1, double cF, int ps = 17): -// multiplication by a constant. Bit length stays the same -// ps defines number of bits used to represent the constant -// -// VarDSPPostadd (string name, VarBase *p1, VarBase *p2, VarBase *p3, double range = -1, int nmax = 18): -// explicit instantiation of the 3-clock DSP postaddition: p1*p2+p3 -// range and nmax have the same meaning as for the VarMult. -// -// VarShift (string name, VarBase *p1, int shift): -// shifts the variable right by shift (equivalent to multiplication by pow(2, -shift)); -// Units stay the same, nbits are adjusted. -// -// VarShiftround (string name, VarBase *p1, int shift): -// shifts the variable right by shift, but doing rounding, i.e. -// (p>>(shift-1)+1)>>1; -// Units stay the same, nbits are adjusted. -// -// VarNeg (string name, VarBase *p1): -// multiplies the variable by -1 -// -// VarInv (string name, VarBase *p1, double offset, int nbits, int n, unsigned int shift, mode m, int nbaddr=-1): -// LUT-based inversion, f = 1./(offset + f1) and i = 2^n / (offsetI + i1) -// nbits is the width of the LUT (signed) -// m is from enum mode {pos, neg, both} and refers to possible sign values of f -// for pos and neg, the most significant bit of p1 (i.e. the sign bit) is ignored -// shift is a shift applied in i1<->address conversions (used to reduce size of LUT) -// nbaddr: if not specified, it is taken to be equal to p1->nbits() -// -// -// VarNounits (string name, VarBase *p1, int ps = 17): -// convert a number with units to a number - needed for trig function expansion (i.e. 1 - 0.5*phi^2) -// ps is a number of bits to represent the unit conversion constant -// -// VarAdjustK (string name, VarBase *p1, double Knew, double epsilon = 1e-5, bool do_assert = false, int nbits = -1) -// adjust variable shift so the K is as close to Knew as possible (needed for bit length adjustments) -// if do_assert is true, throw an exeption if Knew/Kold is not a power of two -// epsilon is a comparison precision, nbits forces the bit length (possibly discarding MSBs) -// -// VarAdjustKR (string name, VarBase *p1, double Knew, double epsilon = 1e-5, bool do_assert = false, int nbits = -1) -// - same as adjustK(), but with rounding, and therefore latency=1 -// -// bool calculate(int debug_level) runs through the entire formula tree recalculating both ineteger and floating point values -// returns true if everything is OK, false if obvious problems with the calculation exist, i.e -// - integer value does not fit into the alotted number of bins -// - integer value is more then 10% or more then 2 away from fval_/K_ -// debug_level: 0 - no warnings -// 1 - limited warning -// 2 - as 1, but also include explicit warnings when LUT was used out of its range -// 3 - maximum complaints level -// -// VarFlag (string name, VarBase *cut_var, VarBase *...) -// -// flag to apply cuts defined for any variable. When output as Verilog, the flag -// is true if and only if the following conditions are all true: -// 1) the cut defined by each VarCut pointer in the argument list must be passed -// by the associated variable -// 2) each VarBase pointer in the argument list that is not also a VarCut -// pointer must pass all of its associated cuts -// 3) all children of the variables in the argument list must pass all of their -// associated cuts -// The VarFlag::passes() method replicates the behavior of the output Verilog, -// returning true if and only if the above conditions are all true. The -// VarBase::local_passes() method can be used to query if a given variable passes -// its associated cuts, regardless of whether its children do. -// -#ifndef L1Trigger_TrackFindingTracklet_interface_imath_h -#define L1Trigger_TrackFindingTracklet_interface_imath_h - -//use root if uncommented -//#ifndef CMSSW_GIT_HASH -//#define IMATH_ROOT -//#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "L1Trigger/TrackFindingTracklet/interface/Util.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" -#include "L1Trigger/L1TCommon/interface/BitShift.h" - -#ifdef IMATH_ROOT -#include -#include -#include -#include -#endif - -//operation latencies for proper HDL pipelining -#define MULT_LATENCY 1 -#define LUT_LATENCY 2 -#define DSP_LATENCY 3 - -// Print out information on the pass/fail status of all variables. Warning: -// this outputs a lot of information for busy events! - -namespace trklet { - - struct imathGlobals { - bool printCutInfo_{false}; -#ifdef IMATH_ROOT - TFile *h_file_ = new TFile("imath.root", "RECREATE"); - bool use_root; -#endif - }; - - class VarCut; - class VarFlag; - - class VarBase { - public: - VarBase(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, int l) { - globals_ = globals; - p1_ = p1; - p2_ = p2; - p3_ = p3; - name_ = name; - latency_ = l; - int step1 = (p1) ? p1->step() + p1->latency() : 0; - int step2 = (p2) ? p2->step() + p2->latency() : 0; - step_ = std::max(step1, step2); - - cuts_.clear(); - cut_var_ = nullptr; - - pipe_counter_ = 0; - pipe_delays_.clear(); - - minval_ = std::numeric_limits::max(); - maxval_ = -std::numeric_limits::max(); - readytoprint_ = true; - readytoanalyze_ = true; - usedasinput_ = false; - Kmap_.clear(); - Kmap_["2"] = 0; // initially, zero shift -#ifdef IMATH_ROOT - h_ = 0; - h_nbins_ = 1024; - h_precision_ = 0.02; -#endif - } - virtual ~VarBase() { -#ifdef IMATH_ROOT - if (globals_->h_file_) { - globals_->h_file_->ls(); - globals_->h_file_->Close(); - globals_->h_file_ = 0; - } -#endif - } - - static struct Verilog { - } verilog; - static struct HLS { - } hls; - - std::string kstring() const; - std::string name() const { return name_; } - std::string op() const { return op_; } - VarBase *p1() const { return p1_; } - VarBase *p2() const { return p2_; } - VarBase *p3() const { return p3_; } - double fval() const { return fval_; } - long int ival() const { return ival_; } - - bool local_passes() const; - void passes(std::map > &passes, - const std::map > *const previous_passes = nullptr) const; - void print_cuts(std::map > &cut_strings, - const int step, - Verilog, - const std::map > *const previous_cut_strings = nullptr) const; - void print_cuts(std::map > &cut_strings, - const int step, - HLS, - const std::map > *const previous_cut_strings = nullptr) const; - void add_cut(VarCut *cut, const bool call_set_cut_var = true); - VarBase *cut_var(); - // observed range of fval_ (only filled if debug_level > 0) - double minval() const { return minval_; } - double maxval() const { return maxval_; } - void analyze(); -#ifdef IMATH_ROOT - TH2F *h() { return h_; } -#endif - void reset() { - minval_ = std::numeric_limits::max(); - maxval_ = -std::numeric_limits::max(); -#ifdef IMATH_ROOT - h_->Clear(); -#endif - } - - int nbits() const { return nbits_; } - std::map Kmap() const { return Kmap_; } - double range() const { return (1 << (nbits_ - 1)) * K_; } // everything is signed - double K() const { return K_; }; - int shift() const { return Kmap_.at("2"); } - - void makeready(); - int step() const { return step_; } - int latency() const { return latency_; } - void add_latency(unsigned int l) { latency_ += l; } //only call before using the variable in calculation! - bool calculate(int debug_level = 0); - virtual void local_calculate() {} - void calcDebug(int debug_level, long int ival_prev, bool &all_ok); - virtual void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) { - fs << "// VarBase here. Soemthing is wrong!! " << l1 << ", " << l2 << ", " << l3 << "\n"; - } - virtual void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) { - fs << "// VarBase here. Soemthing is wrong!! " << l1 << ", " << l2 << ", " << l3 << "\n"; - } - void print_step(int step, std::ofstream &fs, Verilog); - void print_step(int step, std::ofstream &fs, HLS); - void print_all(std::ofstream &fs, Verilog); - void print_all(std::ofstream &fs, HLS); - void print_truncation(std::string &t, const std::string &o1, const int ps, Verilog) const; - void print_truncation(std::string &t, const std::string &o1, const int ps, HLS) const; - void inputs(std::vector *vd); //collect all inputs - - int pipe_counter() { return pipe_counter_; } - void pipe_increment() { pipe_counter_++; } - void add_delay(int i) { pipe_delays_.push_back(i); } - bool has_delay(int i); //returns true if already have this variable delayed. - static void verilog_print(const std::vector &v, std::ofstream &fs) { design_print(v, fs, verilog); } - static void hls_print(const std::vector &v, std::ofstream &fs) { design_print(v, fs, hls); } - static void design_print(const std::vector &v, std::ofstream &fs, Verilog); - static void design_print(const std::vector &v, std::ofstream &fs, HLS); - static std::string pipe_delay(VarBase *v, int nbits, int delay); - std::string pipe_delays(const int step); - static std::string pipe_delay_wire(VarBase *v, std::string name_delayed, int nbits, int delay); - -#ifdef IMATH_ROOT - static TTree *addToTree(imathGlobals *globals, VarBase *v, char *s = 0); - static TTree *addToTree(imathGlobals *globals, int *v, char *s); - static TTree *addToTree(imathGlobals *globals, double *v, char *s); - static void fillTree(imathGlobals *globals); - static void writeTree(imathGlobals *globals); -#endif - - void dump_msg(); - std::string dump(); - static std::string itos(int i); - - protected: - imathGlobals *globals_; - std::string name_; - VarBase *p1_; - VarBase *p2_; - VarBase *p3_; - std::string op_; // operation - int latency_; // number of clock cycles for the operation (for HDL output) - int step_; // step number in the calculation (for HDL output) - - double fval_; // exact calculation - long int ival_; // integer calculation - double val_; // integer calculation converted to double, ival_*K - - std::vector cuts_; - VarBase *cut_var_; - - int nbits_; - double K_; - std::map Kmap_; - - int pipe_counter_; - std::vector pipe_delays_; - - bool readytoanalyze_; - bool readytoprint_; - bool usedasinput_; - - double minval_; - double maxval_; -#ifdef IMATH_ROOT - void set_hist_pars(int n = 256, double p = 0.05) { - h_nbins_ = n; - h_precision_ = p; - } - int h_nbins_; - double h_precision_; - TH2F *h_; -#endif - }; - - class VarAdjustK : public VarBase { - public: - VarAdjustK(imathGlobals *globals, - std::string name, - VarBase *p1, - double Knew, - double epsilon = 1e-5, - bool do_assert = false, - int nbits = -1) - : VarBase(globals, name, p1, nullptr, nullptr, 0) { - op_ = "adjustK"; - K_ = p1->K(); - Kmap_ = p1->Kmap(); - - double r = Knew / K_; - - lr_ = (r > 1) ? log2(r) + epsilon : log2(r); - K_ = K_ * pow(2, lr_); - if (do_assert) - assert(std::abs(Knew / K_ - 1) < epsilon); - - if (nbits > 0) - nbits_ = nbits; - else - nbits_ = p1->nbits() - lr_; - - Kmap_["2"] = Kmap_["2"] + lr_; - } - - ~VarAdjustK() override = default; - - void adjust(double Knew, double epsilon = 1e-5, bool do_assert = false, int nbits = -1); - - void local_calculate() override; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - - protected: - int lr_; - }; - - class VarAdjustKR : public VarBase { - public: - VarAdjustKR(imathGlobals *globals, - std::string name, - VarBase *p1, - double Knew, - double epsilon = 1e-5, - bool do_assert = false, - int nbits = -1) - : VarBase(globals, name, p1, nullptr, nullptr, 1) { - op_ = "adjustKR"; - K_ = p1->K(); - Kmap_ = p1->Kmap(); - - double r = Knew / K_; - - lr_ = (r > 1) ? log2(r) + epsilon : log2(r); - K_ = K_ * pow(2, lr_); - if (do_assert) - assert(std::abs(Knew / K_ - 1) < epsilon); - - if (nbits > 0) - nbits_ = nbits; - else - nbits_ = p1->nbits() - lr_; - - Kmap_["2"] = Kmap_["2"] + lr_; - } - - ~VarAdjustKR() override = default; - - void local_calculate() override; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - - protected: - int lr_; - }; - - class VarParam : public VarBase { - public: - VarParam(imathGlobals *globals, std::string name, double fval, int nbits) - : VarBase(globals, name, nullptr, nullptr, nullptr, 0) { - op_ = "const"; - nbits_ = nbits; - int l = log2(std::abs(fval)) + 1.9999999 - nbits; - Kmap_["2"] = l; - K_ = pow(2, l); - fval_ = fval; - ival_ = fval / K_; - } - VarParam(imathGlobals *globals, std::string name, std::string units, double fval, double K) - : VarBase(globals, name, nullptr, nullptr, nullptr, 0) { - op_ = "const"; - K_ = K; - nbits_ = log2(fval / K) + 1.999999; //plus one to round up - if (!units.empty()) - Kmap_[units] = 1; - else { - //defining a constant, K should be a power of two - int l = log2(K); - if (std::abs(pow(2, l) / K - 1) > 1e-5) { - char slog[100]; - snprintf(slog, 100, "defining unitless constant, yet K is not a power of 2! %g, %g", K, pow(2, l)); - edm::LogVerbatim("Tracklet") << slog; - } - Kmap_["2"] = l; - } - } - - ~VarParam() override = default; - - void set_fval(double fval) { - fval_ = fval; - if (fval > 0) - ival_ = fval / K_ + 0.5; - else - ival_ = fval / K_ - 0.5; - val_ = ival_ * K_; - } - void set_ival(int ival) { - ival_ = ival; - fval_ = ival * K_; - val_ = fval_; - } - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - }; - - class VarDef : public VarBase { - public: - //construct from scratch - VarDef(imathGlobals *globals, std::string name, std::string units, double fmax, double K) - : VarBase(globals, name, nullptr, nullptr, nullptr, 1) { - op_ = "def"; - K_ = K; - nbits_ = log2(fmax / K) + 1.999999; //plus one to round up - if (!units.empty()) - Kmap_[units] = 1; - else { - //defining a constant, K should be a power of two - int l = log2(K); - if (std::abs(pow(2, l) / K - 1) > 1e-5) { - char slog[100]; - snprintf(slog, 100, "defining unitless constant, yet K is not a power of 2! %g, %g", K, pow(2, l)); - edm::LogVerbatim("Tracklet") << slog; - } - Kmap_["2"] = l; - } - } - //construct from abother variable (all provenance info is lost!) - VarDef(imathGlobals *globals, std::string name, VarBase *p) : VarBase(globals, name, nullptr, nullptr, nullptr, 1) { - op_ = "def"; - K_ = p->K(); - nbits_ = p->nbits(); - Kmap_ = p->Kmap(); - } - void set_fval(double fval) { - fval_ = fval; - if (fval > 0) - ival_ = fval / K_; - else - ival_ = fval / K_ - 1; - val_ = ival_ * K_; - } - void set_ival(int ival) { - ival_ = ival; - fval_ = ival * K_; - val_ = ival_ * K_; - } - ~VarDef() override = default; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - }; - - class VarAdd : public VarBase { - public: - VarAdd(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18) - : VarBase(globals, name, p1, p2, nullptr, 1) { - op_ = "add"; - - std::map map1 = p1->Kmap(); - std::map map2 = p2->Kmap(); - int s1 = map1["2"]; - int s2 = map2["2"]; - - //first check if the constants are all lined up - //go over the two maps subtracting the units - for (const auto &it : map2) { - if (map1.find(it.first) == map1.end()) - map1[it.first] = -it.second; - else - map1[it.first] = map1[it.first] - it.second; - } - - char slog[100]; - - //assert if different - for (const auto &it : map1) { - if (it.second != 0) { - if (it.first != "2") { - snprintf( - slog, 100, "VarAdd: bad units! %s^%i for variable %s", (it.first).c_str(), it.second, name_.c_str()); - edm::LogVerbatim("Tracklet") << slog; - p1->dump_msg(); - p2->dump_msg(); - throw cms::Exception("BadConfig") << "imath units are different!"; - } - } - } - - double ki1 = p1->K() / pow(2, s1); - double ki2 = p2->K() / pow(2, s2); - //those should be the same - if (std::abs(ki1 / ki2 - 1.) > 1e-6) { - snprintf(slog, 100, "VarAdd: bad constants! %f %f for variable %s", ki1, ki2, name_.c_str()); - edm::LogVerbatim("Tracklet") << slog; - p1->dump_msg(); - p2->dump_msg(); - throw cms::Exception("BadConfig") << "imath constants are different!"; - } - //everything checks out! - - Kmap_ = p1->Kmap(); - - int s0 = s1 < s2 ? s1 : s2; - shift1 = s1 - s0; - shift2 = s2 - s0; - - int n1 = p1->nbits() + shift1; - int n2 = p2->nbits() + shift2; - int n0 = 1 + (n1 > n2 ? n1 : n2); - - //before shifting, check the range - if (range > 0) { - n0 = log2(range / ki1 / pow(2, s0)) + 1e-9; - n0 = n0 + 2; - } - - if (n0 <= nmax) { //if it fits, we're done - ps_ = 0; - Kmap_["2"] = s0; - nbits_ = n0; - } else { - ps_ = n0 - nmax; - Kmap_["2"] = s0 + ps_; - nbits_ = nmax; - } - - K_ = ki1 * pow(2, Kmap_["2"]); - } - ~VarAdd() override = default; - void local_calculate() override; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - - protected: - int ps_; - int shift1; - int shift2; - }; - - class VarSubtract : public VarBase { - public: - VarSubtract(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18) - : VarBase(globals, name, p1, p2, nullptr, 1) { - op_ = "subtract"; - - std::map map1 = p1->Kmap(); - std::map map2 = p2->Kmap(); - int s1 = map1["2"]; - int s2 = map2["2"]; - - //first check if the constants are all lined up go over the two maps subtracting the units - for (const auto &it : map2) { - if (map1.find(it.first) == map1.end()) - map1[it.first] = -it.second; - else - map1[it.first] = map1[it.first] - it.second; - } - - char slog[100]; - - //assert if different - for (const auto &it : map1) { - if (it.second != 0) { - if (it.first != "2") { - snprintf( - slog, 100, "VarAdd: bad units! %s^%i for variable %s", (it.first).c_str(), it.second, name_.c_str()); - edm::LogVerbatim("Tracklet") << slog; - p1->dump_msg(); - p2->dump_msg(); - throw cms::Exception("BadConfig") << "imath units are different!"; - } - } - } - - double ki1 = p1->K() / pow(2, s1); - double ki2 = p2->K() / pow(2, s2); - //those should be the same - if (std::abs(ki1 / ki2 - 1.) > 1e-6) { - snprintf(slog, 100, "VarAdd: bad constants! %f %f for variable %s", ki1, ki2, name_.c_str()); - edm::LogVerbatim("Tracklet") << slog; - p1->dump_msg(); - p2->dump_msg(); - throw cms::Exception("BadConfig") << "imath constants are different!"; - } - //everything checks out! - - Kmap_ = p1->Kmap(); - - int s0 = s1 < s2 ? s1 : s2; - shift1 = s1 - s0; - shift2 = s2 - s0; - - int n1 = p1->nbits() + shift1; - int n2 = p2->nbits() + shift2; - int n0 = 1 + (n1 > n2 ? n1 : n2); - - //before shifting, check the range - if (range > 0) { - n0 = log2(range / ki1 / pow(2, s0)) + 1e-9; - n0 = n0 + 2; - } - - if (n0 <= nmax) { //if it fits, we're done - ps_ = 0; - Kmap_["2"] = s0; - nbits_ = n0; - } else { - ps_ = n0 - nmax; - Kmap_["2"] = s0 + ps_; - nbits_ = nmax; - } - - K_ = ki1 * pow(2, Kmap_["2"]); - } - - ~VarSubtract() override = default; - - void local_calculate() override; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - - protected: - int ps_; - int shift1; - int shift2; - }; - - class VarNounits : public VarBase { - public: - VarNounits(imathGlobals *globals, std::string name, VarBase *p1, int ps = 17) - : VarBase(globals, name, p1, nullptr, nullptr, MULT_LATENCY) { - op_ = "nounits"; - ps_ = ps; - nbits_ = p1->nbits(); - - int s1 = p1->shift(); - double ki = p1->K() / pow(2, s1); - int m = log2(ki); - - K_ = pow(2, s1 + m); - Kmap_["2"] = s1 + m; - double c = ki * pow(2, -m); - cI_ = c * pow(2, ps_); - } - ~VarNounits() override = default; - - void local_calculate() override; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - - protected: - int ps_; - int cI_; - }; - - class VarShiftround : public VarBase { - public: - VarShiftround(imathGlobals *globals, std::string name, VarBase *p1, int shift) - : VarBase(globals, name, p1, nullptr, nullptr, 1) { // latency is one because there is an addition - op_ = "shiftround"; - shift_ = shift; - - nbits_ = p1->nbits() - shift; - Kmap_ = p1->Kmap(); - K_ = p1->K(); - } - ~VarShiftround() override = default; - - void local_calculate() override; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - - protected: - int shift_; - }; - - class VarShift : public VarBase { - public: - VarShift(imathGlobals *globals, std::string name, VarBase *p1, int shift) - : VarBase(globals, name, p1, nullptr, nullptr, 0) { - op_ = "shift"; - shift_ = shift; - - nbits_ = p1->nbits() - shift; - Kmap_ = p1->Kmap(); - K_ = p1->K(); - } - ~VarShift() override = default; - void local_calculate() override; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - - protected: - int shift_; - }; - - class VarNeg : public VarBase { - public: - VarNeg(imathGlobals *globals, std::string name, VarBase *p1) : VarBase(globals, name, p1, nullptr, nullptr, 1) { - op_ = "neg"; - nbits_ = p1->nbits(); - Kmap_ = p1->Kmap(); - K_ = p1->K(); - } - ~VarNeg() override = default; - void local_calculate() override; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - }; - - class VarTimesC : public VarBase { - public: - VarTimesC(imathGlobals *globals, std::string name, VarBase *p1, double cF, int ps = 17) - : VarBase(globals, name, p1, nullptr, nullptr, MULT_LATENCY) { - op_ = "timesC"; - cF_ = cF; - ps_ = ps; - - nbits_ = p1->nbits(); - Kmap_ = p1->Kmap(); - K_ = p1->K(); - - int s1 = Kmap_["2"]; - double l = log2(std::abs(cF)); - if (l > 0) - l += 0.999999; - int m = l; - - cI_ = cF * pow(2, ps - m); - K_ = K_ * pow(2, m); - Kmap_["2"] = s1 + m; - } - ~VarTimesC() override = default; - void local_calculate() override; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - - protected: - int ps_; - int cI_; - double cF_; - }; - - class VarMult : public VarBase { - public: - VarMult(imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, double range = -1, int nmax = 18) - : VarBase(globals, name, p1, p2, nullptr, MULT_LATENCY) { - op_ = "mult"; - - const std::map map1 = p1->Kmap(); - const std::map map2 = p2->Kmap(); - for (const auto &it : map1) { - if (Kmap_.find(it.first) == Kmap_.end()) - Kmap_[it.first] = it.second; - else - Kmap_[it.first] = Kmap_[it.first] + it.second; - } - for (const auto &it : map2) { - if (Kmap_.find(it.first) == Kmap_.end()) - Kmap_[it.first] = it.second; - else - Kmap_[it.first] = Kmap_[it.first] + it.second; - } - K_ = p1->K() * p2->K(); - int s0 = Kmap_["2"]; - - int n0 = p1->nbits() + p2->nbits(); - if (range > 0) { - n0 = log2(range / K_) + 1e-9; - n0 = n0 + 2; - } - if (n0 < nmax) { - ps_ = 0; - nbits_ = n0; - } else { - ps_ = n0 - nmax; - nbits_ = nmax; - Kmap_["2"] = s0 + ps_; - K_ = K_ * pow(2, ps_); - } - } - ~VarMult() override = default; - void local_calculate() override; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - - protected: - int ps_; - }; - - class VarDSPPostadd : public VarBase { - public: - VarDSPPostadd( - imathGlobals *globals, std::string name, VarBase *p1, VarBase *p2, VarBase *p3, double range = -1, int nmax = 18) - : VarBase(globals, name, p1, p2, p3, DSP_LATENCY) { - op_ = "DSP_postadd"; - - //first, get constants for the p1*p2 - std::map map1 = p1->Kmap(); - std::map map2 = p2->Kmap(); - for (const auto &it : map2) { - if (map1.find(it.first) == map1.end()) - map1[it.first] = it.second; - else - map1[it.first] = map1[it.first] + it.second; - } - double k0 = p1->K() * p2->K(); - int s0 = map1["2"]; - - //now addition - std::map map3 = p3->Kmap(); - int s3 = map3["2"]; - - //first check if the constants are all lined up - //go over the two maps subtracting the units - for (const auto &it : map3) { - if (map1.find(it.first) == map1.end()) - map1[it.first] = -it.second; - else - map1[it.first] = map1[it.first] - it.second; - } - - char slog[100]; - - //assert if different - for (const auto &it : map1) { - if (it.second != 0) { - if (it.first != "2") { - snprintf(slog, - 100, - "VarDSPPostadd: bad units! %s^%i for variable %s", - (it.first).c_str(), - it.second, - name_.c_str()); - edm::LogVerbatim("Tracklet") << slog; - p1->dump_msg(); - p2->dump_msg(); - p3->dump_msg(); - throw cms::Exception("BadConfig") << "imath units are different!"; - } - } - } - - double ki1 = k0 / pow(2, s0); - double ki2 = p3->K() / pow(2, s3); - //those should be the same - if (std::abs(ki1 / ki2 - 1.) > 1e-6) { - snprintf(slog, 100, "VarDSPPostadd: bad constants! %f %f for variable %s", ki1, ki2, name_.c_str()); - edm::LogVerbatim("Tracklet") << slog; - p1->dump_msg(); - p2->dump_msg(); - p3->dump_msg(); - throw cms::Exception("BadConfig") << "imath constants are different!"; - } - //everything checks out! - - shift3_ = s3 - s0; - if (shift3_ < 0) { - throw cms::Exception("BadConfig") << "imath VarDSPPostadd: loosing precision on C in A*B+C: " << shift3_; - } - - Kmap_ = p3->Kmap(); - Kmap_["2"] = Kmap_["2"] - shift3_; - - int n12 = p1->nbits() + p2->nbits(); - int n3 = p3->nbits() + shift3_; - int n0 = 1 + (n12 > n3 ? n12 : n3); - - //before shifting, check the range - if (range > 0) { - n0 = log2(range / ki2 / pow(2, s3)) + 1e-9; - n0 = n0 + 2; - } - - if (n0 <= nmax) { //if it fits, we're done - ps_ = 0; - nbits_ = n0; - } else { - ps_ = n0 - nmax; - Kmap_["2"] = Kmap_["2"] + ps_; - nbits_ = nmax; - } - - K_ = ki2 * pow(2, Kmap_["2"]); - } - ~VarDSPPostadd() override = default; - - void local_calculate() override; - using VarBase::print; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - - protected: - int ps_; - int shift3_; - }; - - class VarInv : public VarBase { - public: - enum mode { pos, neg, both }; - - VarInv(imathGlobals *globals, - std::string name, - VarBase *p1, - double offset, - int nbits, - int n, - unsigned int shift, - mode m, - int nbaddr = -1) - : VarBase(globals, name, p1, nullptr, nullptr, LUT_LATENCY) { - op_ = "inv"; - offset_ = offset; - nbits_ = nbits; - n_ = n; - shift_ = shift; - m_ = m; - if (nbaddr < 0) - nbaddr = p1->nbits(); - nbaddr_ = nbaddr - shift; - if (m_ != mode::both) - nbaddr_--; - Nelements_ = 1 << nbaddr_; - mask_ = Nelements_ - 1; - ashift_ = sizeof(int) * 8 - nbaddr_; - - const std::map map1 = p1->Kmap(); - for (const auto &it : map1) - Kmap_[it.first] = -it.second; - Kmap_["2"] = Kmap_["2"] - n; - K_ = pow(2, -n) / p1->K(); - - LUT = new int[Nelements_]; - double offsetI = lround(offset_ / p1_->K()); - for (int i = 0; i < Nelements_; ++i) { - int i1 = addr_to_ival(i); - LUT[i] = gen_inv(offsetI + i1); - } - } - ~VarInv() override { delete[] LUT; } - - void set_mode(mode m) { m_ = m; } - void initLUT(double offset); - double offset() { return offset_; } - double Ioffset() { return offset_ / p1_->K(); } - - void local_calculate() override; - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - void writeLUT(std::ofstream &fs) const { writeLUT(fs, verilog); } - void writeLUT(std::ofstream &fs, Verilog) const; - void writeLUT(std::ofstream &fs, HLS) const; - - int ival_to_addr(int ival) { return ((ival >> shift_) & mask_); } - int addr_to_ival(int addr) { - switch (m_) { - case mode::pos: - return l1t::bitShift(addr, shift_); - case mode::neg: - return l1t::bitShift((addr - Nelements_), shift_); - case mode::both: - return l1t::bitShift(addr, ashift_) >> (ashift_ - shift_); - } - assert(0); - } - int gen_inv(int i) { - unsigned int ms = sizeof(int) * 8 - nbits_; - int lut = 0; - if (i > 0) { - int i1 = i + (1 << shift_) - 1; - int lut1 = (lround((1 << n_) / i) << ms) >> ms; - int lut2 = (lround((1 << n_) / (i1)) << ms) >> ms; - lut = 0.5 * (lut1 + lut2); - } else if (i < -1) { - int i1 = i + (1 << shift_) - 1; - int i2 = i; - int lut1 = (lround((1 << n_) / i1) << ms) >> ms; - int lut2 = (lround((1 << n_) / i2) << ms) >> ms; - lut = 0.5 * (lut1 + lut2); - } - return lut; - } - - protected: - double offset_; - int n_; - mode m_; - unsigned int shift_; - unsigned int mask_; - unsigned int ashift_; - int Nelements_; - int nbaddr_; - - int *LUT; - }; - - class VarCut : public VarBase { - public: - VarCut(imathGlobals *globals, double lower_cut, double upper_cut) - : VarBase(globals, "", nullptr, nullptr, nullptr, 0), - lower_cut_(lower_cut), - upper_cut_(upper_cut), - parent_flag_(nullptr) { - op_ = "cut"; - } - - VarCut(imathGlobals *globals, VarBase *cut_var, double lower_cut, double upper_cut) - : VarCut(globals, lower_cut, upper_cut) { - set_cut_var(cut_var); - } - ~VarCut() override = default; - - double lower_cut() const { return lower_cut_; } - double upper_cut() const { return upper_cut_; } - - void local_passes(std::map > &passes, - const std::map > *const previous_passes = nullptr) const; - using VarBase::print; - void print(std::map > &cut_strings, - const int step, - Verilog, - const std::map > *const previous_cut_strings = nullptr) const; - void print(std::map > &cut_strings, - const int step, - HLS, - const std::map > *const previous_cut_strings = nullptr) const; - - void set_parent_flag(VarFlag *parent_flag, const bool call_add_cut); - VarFlag *parent_flag() { return parent_flag_; } - void set_cut_var(VarBase *cut_var, const bool call_add_cut = true); - - protected: - double lower_cut_; - double upper_cut_; - VarFlag *parent_flag_; - }; - - class VarFlag : public VarBase { - public: - template - VarFlag(imathGlobals *globals, std::string name, VarBase *cut, Args... args) - : VarBase(globals, name, nullptr, nullptr, nullptr, 0) { - op_ = "flag"; - nbits_ = 1; - add_cuts(cut, args...); - } - - template - void add_cuts(VarBase *cut, Args... args) { - add_cut(cut); - add_cuts(args...); - } - - void add_cuts(VarBase *cut) { add_cut(cut); } - - void add_cut(VarBase *cut, const bool call_set_parent_flag = true); - - void calculate_step(); - bool passes(); - void print(std::ofstream &fs, Verilog, int l1 = 0, int l2 = 0, int l3 = 0) override; - void print(std::ofstream &fs, HLS, int l1 = 0, int l2 = 0, int l3 = 0) override; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc index 6cd0d241241ce..4f45064f706f6 100644 --- a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc +++ b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc @@ -346,7 +346,9 @@ L1FPGATrackProducer::~L1FPGATrackProducer() { ///////END RUN // -void L1FPGATrackProducer::endRun(const edm::Run& run, const edm::EventSetup& iSetup) {} +void L1FPGATrackProducer::endRun(const edm::Run& run, const edm::EventSetup& iSetup) { + eventProcessor.printSummary(); +} //////////// // BEGIN JOB diff --git a/L1Trigger/TrackFindingTracklet/python/l1tTTTracksFromTrackletEmulation_cfi.py b/L1Trigger/TrackFindingTracklet/python/l1tTTTracksFromTrackletEmulation_cfi.py index 4066a576a5250..401551a0fa885 100644 --- a/L1Trigger/TrackFindingTracklet/python/l1tTTTracksFromTrackletEmulation_cfi.py +++ b/L1Trigger/TrackFindingTracklet/python/l1tTTTracksFromTrackletEmulation_cfi.py @@ -28,7 +28,7 @@ Fakefit = cms.bool(False), # True causes Tracklet reco to output TTTracks before DR & KF StoreTrackBuilderOutput = cms.bool(False), # if True EDProducts for TrackBuilder tracks and stubs will be filled RemovalType = cms.string("merge"), # Duplicate track removal - DoMultipleMatches = cms.bool(True) # Allow tracklet tracks multiple stubs per layer + DoMultipleMatches = cms.bool(False) # Allow tracklet tracks multiple stubs per layer ) l1tTTTracksFromExtendedTrackletEmulation = l1tTTTracksFromTrackletEmulation.clone( diff --git a/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc deleted file mode 100644 index 409bd8eb7e663..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc +++ /dev/null @@ -1,40 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" -#include "L1Trigger/TrackFindingTracklet/interface/Util.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -#include -#include - -using namespace trklet; -using namespace std; - -AllProjectionsMemory::AllProjectionsMemory(string name, Settings const& settings) : MemoryBase(name, settings) { - initLayerDisk(3, layer_, disk_); -} - -void AllProjectionsMemory::writeAP(bool first, unsigned int iSector) { - iSector_ = iSector; - const string dirTP = settings_.memPath() + "TrackletProjections/"; - - std::ostringstream oss; - oss << dirTP << "AllProj_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; - auto const& fname = oss.str(); - - openfile(out_, first, dirTP, fname, __FILE__, __LINE__); - - out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; - - for (unsigned int j = 0; j < tracklets_.size(); j++) { - string proj = - (layer_ > 0) ? tracklets_[j]->trackletprojstrlayer(layer_) : tracklets_[j]->trackletprojstrdisk(disk_); - out_ << hexstr(j) << " " << proj << " " << trklet::hexFormat(proj) << endl; - } - out_.close(); - - bx_++; - event_++; - if (bx_ > 7) - bx_ = 0; -} diff --git a/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc b/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc deleted file mode 100644 index adef2141b7223..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc +++ /dev/null @@ -1,59 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" -#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" -#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" - -#include -#include - -using namespace std; -using namespace trklet; - -CandidateMatchMemory::CandidateMatchMemory(string name, Settings const& settings) : MemoryBase(name, settings) {} - -void CandidateMatchMemory::addMatch(std::pair tracklet, const Stub* stub) { - std::pair, const Stub*> tmp(tracklet, stub); - - //Check for consistency - for (auto& match : matches_) { - if (tracklet.first->TCID() < match.first.first->TCID()) { - throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " In " << getName() << " adding tracklet " - << tracklet.first << " with lower TCID : " << tracklet.first->TCID() - << " than earlier TCID " << match.first.first->TCID(); - } - } - matches_.push_back(tmp); -} - -void CandidateMatchMemory::writeCM(bool first, unsigned int iSector) { - iSector_ = iSector; - const string dirM = settings_.memPath() + "Matches/"; - - std::ostringstream oss; - oss << dirM << "CandidateMatches_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) - << ".dat"; - auto const& fname = oss.str(); - - openfile(out_, first, dirM, fname, __FILE__, __LINE__); - - out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; - - for (unsigned int j = 0; j < matches_.size(); j++) { - string stubid = matches_[j].second->stubindex().str(); // stub ID - int projindex = matches_[j].first.second; // Allproj index - FPGAWord tmp; - if (projindex >= (1 << 7)) { - projindex = (1 << 7) - 1; - } - tmp.set(projindex, 7, true, __LINE__, __FILE__); - out_ << hexstr(j) << " " << tmp.str() << "|" << stubid << " " << trklet::hexFormat(tmp.str() + stubid) << endl; - } - out_.close(); - - bx_++; - event_++; - if (bx_ > 7) - bx_ = 0; -} diff --git a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc index b0b0b9412da91..c6d93837cbf26 100644 --- a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc +++ b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc @@ -42,30 +42,72 @@ void FitTrack::addInput(MemoryBase* memory, string input) { seedtracklet_.push_back(tmp); return; } - if (input.substr(0, 10) == "fullmatch1") { + if (input.substr(0, 11) == "fullmatch0i") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch0_.push_back(tmp); + return; + } + if (input.substr(0, 11) == "fullmatch1i") { auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); fullmatch1_.push_back(tmp); return; } - if (input.substr(0, 10) == "fullmatch2") { + if (input.substr(0, 11) == "fullmatch2i") { auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); fullmatch2_.push_back(tmp); return; } - if (input.substr(0, 10) == "fullmatch3") { + if (input.substr(0, 11) == "fullmatch3i") { auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); fullmatch3_.push_back(tmp); return; } - if (input.substr(0, 10) == "fullmatch4") { + if (input.substr(0, 11) == "fullmatch4i") { auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); fullmatch4_.push_back(tmp); return; } + if (input.substr(0, 11) == "fullmatch5i") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch5_.push_back(tmp); + return; + } + if (input.substr(0, 11) == "fullmatch6i") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch6_.push_back(tmp); + return; + } + if (input.substr(0, 11) == "fullmatch7i") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch7_.push_back(tmp); + return; + } + if (input.substr(0, 11) == "fullmatch8i") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch8_.push_back(tmp); + return; + } + if (input.substr(0, 11) == "fullmatch9i") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch9_.push_back(tmp); + return; + } + if (input.substr(0, 11) == "fullmatch10") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch10_.push_back(tmp); + return; + } throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " input = " << input << " not found"; } @@ -880,11 +922,22 @@ void FitTrack::execute(deque& streamTrackRaw, vector>& streamsStubRaw, unsigned int iSector) { // merge + const std::vector& matches0 = orderedMatches(fullmatch0_); const std::vector& matches1 = orderedMatches(fullmatch1_); const std::vector& matches2 = orderedMatches(fullmatch2_); const std::vector& matches3 = orderedMatches(fullmatch3_); const std::vector& matches4 = orderedMatches(fullmatch4_); + const std::vector& matches5 = orderedMatches(fullmatch5_); + const std::vector& matches6 = orderedMatches(fullmatch6_); + const std::vector& matches7 = orderedMatches(fullmatch7_); + const std::vector& matches8 = orderedMatches(fullmatch8_); + const std::vector& matches9 = orderedMatches(fullmatch9_); + const std::vector& matches10 = orderedMatches(fullmatch10_); + + bool print = getName() == "FT_D1D2" && iSector == 3; + print = false; + iSector_ = iSector; if (settings_.debugTracklet() && (matches1.size() + matches2.size() + matches3.size() + matches4.size()) > 0) { @@ -895,58 +948,129 @@ void FitTrack::execute(deque& streamTrackRaw, << matches3.size() << " " << matches4.size(); } - unsigned int indexArray[4]; - for (unsigned int i = 0; i < 4; i++) { + unsigned int indexArray[11]; + for (unsigned int i = 0; i < 11; i++) { indexArray[i] = 0; } - unsigned int countAll = 0; + unsigned int count = 0; unsigned int countFit = 0; + unsigned int countAll = 0; + int istep=-1; + Tracklet* bestTracklet = nullptr; do { - countAll++; + istep++; + count++; bestTracklet = nullptr; - if (indexArray[0] < matches1.size()) { + if (indexArray[0] < matches0.size()) { + if (bestTracklet == nullptr) { + bestTracklet = matches0[indexArray[0]]; + } else { + if (matches0[indexArray[0]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches0[indexArray[0]]; + } + } + + if (indexArray[1] < matches1.size()) { + if (bestTracklet == nullptr) { + bestTracklet = matches1[indexArray[1]]; + } else { + if (matches1[indexArray[1]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches1[indexArray[1]]; + } + } + + if (indexArray[2] < matches2.size()) { + if (bestTracklet == nullptr) { + bestTracklet = matches2[indexArray[2]]; + } else { + if (matches2[indexArray[2]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches2[indexArray[2]]; + } + } + + if (indexArray[3] < matches3.size()) { if (bestTracklet == nullptr) { - bestTracklet = matches1[indexArray[0]]; + bestTracklet = matches3[indexArray[3]]; } else { - if (matches1[indexArray[0]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches1[indexArray[0]]; + if (matches3[indexArray[3]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches3[indexArray[3]]; } } - if (indexArray[1] < matches2.size()) { + if (indexArray[4] < matches4.size()) { if (bestTracklet == nullptr) { - bestTracklet = matches2[indexArray[1]]; + bestTracklet = matches4[indexArray[4]]; } else { - if (matches2[indexArray[1]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches2[indexArray[1]]; + if (matches4[indexArray[4]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches4[indexArray[4]]; } } - if (indexArray[2] < matches3.size()) { + if (indexArray[5] < matches5.size()) { if (bestTracklet == nullptr) { - bestTracklet = matches3[indexArray[2]]; + bestTracklet = matches5[indexArray[5]]; } else { - if (matches3[indexArray[2]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches3[indexArray[2]]; + if (matches5[indexArray[5]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches5[indexArray[5]]; } } - if (indexArray[3] < matches4.size()) { + if (indexArray[6] < matches6.size()) { if (bestTracklet == nullptr) { - bestTracklet = matches4[indexArray[3]]; + bestTracklet = matches6[indexArray[6]]; } else { - if (matches4[indexArray[3]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches4[indexArray[3]]; + if (matches6[indexArray[6]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches6[indexArray[6]]; } } + if (indexArray[7] < matches7.size()) { + if (bestTracklet == nullptr) { + bestTracklet = matches7[indexArray[7]]; + } else { + if (matches7[indexArray[7]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches7[indexArray[7]]; + } + } + + if (indexArray[8] < matches8.size()) { + if (bestTracklet == nullptr) { + bestTracklet = matches8[indexArray[8]]; + } else { + if (matches8[indexArray[8]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches8[indexArray[8]]; + } + } + + if (indexArray[9] < matches9.size()) { + if (bestTracklet == nullptr) { + bestTracklet = matches9[indexArray[9]]; + } else { + if (matches9[indexArray[9]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches9[indexArray[9]]; + } + } + + if (indexArray[10] < matches10.size()) { + if (bestTracklet == nullptr) { + bestTracklet = matches10[indexArray[10]]; + } else { + if (matches10[indexArray[10]]->TCID() < bestTracklet->TCID()) + bestTracklet = matches10[indexArray[10]]; + } + } + + + if (bestTracklet == nullptr) break; + countAll++; + //Counts total number of matched hits int nMatches = 0; @@ -954,7 +1078,10 @@ void FitTrack::execute(deque& streamTrackRaw, int nMatchesUniq = 0; bool match = false; - while (indexArray[0] < matches1.size() && matches1[indexArray[0]] == bestTracklet) { + if (print) std::cout << "istep = " << istep; + + while (indexArray[0] < matches0.size() && matches0[indexArray[0]] == bestTracklet) { + if (print) std::cout << " match0"; indexArray[0]++; nMatches++; match = true; @@ -964,7 +1091,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[1] < matches2.size() && matches2[indexArray[1]] == bestTracklet) { + + while (indexArray[1] < matches1.size() && matches1[indexArray[1]] == bestTracklet) { + if (print) std::cout << " match1"; indexArray[1]++; nMatches++; match = true; @@ -974,7 +1103,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[2] < matches3.size() && matches3[indexArray[2]] == bestTracklet) { + + while (indexArray[2] < matches2.size() && matches2[indexArray[2]] == bestTracklet) { + if (print) std::cout << " match2"; indexArray[2]++; nMatches++; match = true; @@ -984,7 +1115,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[3] < matches4.size() && matches4[indexArray[3]] == bestTracklet) { + + while (indexArray[3] < matches3.size() && matches3[indexArray[3]] == bestTracklet) { + if (print) std::cout << " match3"; indexArray[3]++; nMatches++; match = true; @@ -992,12 +1125,100 @@ void FitTrack::execute(deque& streamTrackRaw, if (match) nMatchesUniq++; + match = false; + + + while (indexArray[4] < matches4.size() && matches4[indexArray[4]] == bestTracklet) { + if (print) std::cout << " match4"; + indexArray[4]++; + nMatches++; + match = true; + } + + if (match) + nMatchesUniq++; + match = false; + + + while (indexArray[5] < matches5.size() && matches5[indexArray[5]] == bestTracklet) { + if (print) std::cout << " match5"; + indexArray[5]++; + nMatches++; + match = true; + } + + if (match) + nMatchesUniq++; + match = false; + + + while (indexArray[6] < matches6.size() && matches6[indexArray[6]] == bestTracklet) { + if (print) std::cout << " match6"; + indexArray[6]++; + nMatches++; + match = true; + } + + if (match) + nMatchesUniq++; + match = false; + + + while (indexArray[7] < matches7.size() && matches7[indexArray[7]] == bestTracklet) { + if (print) std::cout << " match7"; + indexArray[7]++; + nMatches++; + match = true; + } + + if (match) + nMatchesUniq++; + match = false; + + + while (indexArray[8] < matches8.size() && matches8[indexArray[8]] == bestTracklet) { + if (print) std::cout << " match8"; + indexArray[8]++; + nMatches++; + match = true; + } + + if (match) + nMatchesUniq++; + match = false; + + + while (indexArray[9] < matches9.size() && matches9[indexArray[9]] == bestTracklet) { + if (print) std::cout << " match9"; + indexArray[9]++; + nMatches++; + match = true; + } + + if (match) + nMatchesUniq++; + match = false; + + + while (indexArray[10] < matches10.size() && matches10[indexArray[10]] == bestTracklet) { + if (print) std::cout << " match10"; + indexArray[10]++; + nMatches++; + match = true; + } + + if (match) + nMatchesUniq++; + match = false; + + if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " : nMatches = " << nMatches << " nMatchesUniq = " << nMatchesUniq - << " " << asinh(bestTracklet->t()); + edm::LogVerbatim("Tracklet") << getName() << " : nMatches = " << nMatches << " nMatchesUniq = " << nMatchesUniq; } + if (print) std::cout << " nMatchesUniq = " << nMatchesUniq << std::endl; + std::vector trackstublist; std::vector> stubidslist; // Track Builder cut of >= 4 layers with stubs. @@ -1089,7 +1310,7 @@ void FitTrack::execute(deque& streamTrackRaw, } } - } while (bestTracklet != nullptr && countAll < settings_.maxStep("TB")); + } while (bestTracklet != nullptr && count < settings_.maxStep("TB")); if (settings_.writeMonitorData("FT")) { globals_->ofstream("fittrack.txt") << getName() << " " << countAll << " " << countFit << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/Globals.cc b/L1Trigger/TrackFindingTracklet/src/Globals.cc index 0581f6f8f8bc1..bf49c9f56a5b3 100644 --- a/L1Trigger/TrackFindingTracklet/src/Globals.cc +++ b/L1Trigger/TrackFindingTracklet/src/Globals.cc @@ -1,10 +1,6 @@ // Globals: holds "global" variables such as the IMATH_TrackletCalculators #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" -#include "L1Trigger/TrackFindingTracklet/interface/imath.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletLUT.h" #include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" @@ -12,26 +8,7 @@ using namespace std; using namespace trklet; Globals::Globals(Settings const& settings) { - imathGlobals* imathGlobs = new imathGlobals(); - //takes owernship of globals pointer - imathGlobals_.reset(imathGlobs); - - // tracklet calculators - ITC_L1L2_ = make_unique(settings, imathGlobs, 1, 2); - ITC_L2L3_ = make_unique(settings, imathGlobs, 2, 3); - ITC_L3L4_ = make_unique(settings, imathGlobs, 3, 4); - ITC_L5L6_ = make_unique(settings, imathGlobs, 5, 6); - - ITC_F1F2_ = make_unique(settings, imathGlobs, 1, 2); - ITC_F3F4_ = make_unique(settings, imathGlobs, 3, 4); - ITC_B1B2_ = make_unique(settings, imathGlobs, -1, -2); - ITC_B3B4_ = make_unique(settings, imathGlobs, -3, -4); - - ITC_L1F1_ = make_unique(settings, imathGlobs, 1, 1); - ITC_L2F1_ = make_unique(settings, imathGlobs, 2, 1); - ITC_L1B1_ = make_unique(settings, imathGlobs, 1, -1); - ITC_L2B1_ = make_unique(settings, imathGlobs, 2, -1); } Globals::~Globals() { diff --git a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc deleted file mode 100644 index b39cc0d31e3b0..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc +++ /dev/null @@ -1,581 +0,0 @@ -////////////////////////////////////////////////////////////////// -// MatchCalculator -// This class loads pairs for tracklet/stubs and looks for the -// best possible match. -// Variables such as `best_ideltaphi_barrel` store the "global" -// best value for delta phi, r, z, and r*phi, for instances -// where the same tracklet has multiple stub pairs. This allows -// us to find the truly best match -////////////////////////////////////////////////////////////////// - -#include "L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h" -#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" -#include "L1Trigger/TrackFindingTracklet/interface/Util.h" -#include "L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" -#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" -#include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" -#include "DataFormats/Math/interface/deltaPhi.h" - -#include -#include - -using namespace std; -using namespace trklet; - -MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), - phimatchcuttable_(settings), - zmatchcuttable_(settings), - rphicutPStable_(settings), - rphicut2Stable_(settings), - rcutPStable_(settings), - rcut2Stable_(settings), - alphainner_(settings), - alphaouter_(settings), - rSSinner_(settings), - rSSouter_(settings) { - phiregion_ = name[8] - 'A'; - layerdisk_ = initLayerDisk(3); - - fullMatches_.resize(12, nullptr); - - //TODO - need to sort out constants here - icorrshift_ = 7; - - if (layerdisk_ < N_PSLAYER) { - icorzshift_ = -1 - settings_.PS_zderL_shift(); - } else { - icorzshift_ = -1 - settings_.SS_zderL_shift(); - } - phi0shift_ = 3; - fact_ = 1; - if (layerdisk_ >= N_PSLAYER && layerdisk_ < N_LAYER) { - fact_ = (1 << (settings_.nzbitsstub(0) - settings_.nzbitsstub(5))); - icorrshift_ -= (10 - settings_.nrbitsstub(layerdisk_)); - icorzshift_ += (settings_.nzbitsstub(0) - settings_.nzbitsstub(5) + settings_.nrbitsstub(layerdisk_) - - settings_.nrbitsstub(0)); - phi0shift_ = 0; - } - - unsigned int region = getName()[8] - 'A'; - assert(region < settings_.nallstubs(layerdisk_)); - - if (layerdisk_ < N_LAYER) { - phimatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelphi, region); - zmatchcuttable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::barrelz, region); - } else { - rphicutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSphi, region); - rphicut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sphi, region); - rcutPStable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::diskPSr, region); - rcut2Stable_.initmatchcut(layerdisk_, TrackletLUT::MatchType::disk2Sr, region); - alphainner_.initmatchcut(layerdisk_, TrackletLUT::MatchType::alphainner, region); - alphaouter_.initmatchcut(layerdisk_, TrackletLUT::MatchType::alphaouter, region); - rSSinner_.initmatchcut(layerdisk_, TrackletLUT::MatchType::rSSinner, region); - rSSouter_.initmatchcut(layerdisk_, TrackletLUT::MatchType::rSSouter, region); - } - - for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) { - ialphafactinner_[i] = (1 << settings_.alphashift()) * settings_.krprojshiftdisk() * settings_.half2SmoduleWidth() / - (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSinner(i) * settings_.rDSSinner(i)) / - settings_.kphi(); - ialphafactouter_[i] = (1 << settings_.alphashift()) * settings_.krprojshiftdisk() * settings_.half2SmoduleWidth() / - (1 << (settings_.nbitsalpha() - 1)) / (settings_.rDSSouter(i) * settings_.rDSSouter(i)) / - settings_.kphi(); - } -} - -void MatchCalculator::addOutput(MemoryBase* memory, string output) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " - << output; - } - if (output.substr(0, 8) == "matchout") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - unsigned int iSeed = getISeed(memory->getName()); - fullMatches_[iSeed] = tmp; - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output " << output; -} - -void MatchCalculator::addInput(MemoryBase* memory, string input) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " - << input; - } - if (input == "allstubin") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - allstubs_ = tmp; - return; - } - if (input == "allprojin") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - allprojs_ = tmp; - return; - } - if (input.substr(0, 5) == "match" && input.substr(input.size() - 2, 2) == "in") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - matches_.push_back(tmp); - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input " << input; -} - -void MatchCalculator::execute(unsigned int iSector, double phioffset) { - unsigned int countall = 0; - unsigned int countsel = 0; - - //bool print = getName() == "MC_L4PHIC" && iSector == 3; - - Tracklet* oldTracklet = nullptr; - - // Get all tracklet/stub pairs - std::vector, const Stub*> > mergedMatches = mergeMatches(matches_); - - // Number of clock cycles the pipeline in HLS takes to process the projection merging to - // produce the first projection - unsigned int mergedepth = 3; - - unsigned int maxProc = std::min(settings_.maxStep("MC") - mergedepth, (unsigned int)mergedMatches.size()); - - // Pick some initial large values - int best_ideltaphi_barrel = 0xFFFF; - int best_ideltaz_barrel = 0xFFFF; - int best_ideltaphi_disk = 0xFFFF; - int best_ideltar_disk = 0xFFFF; - unsigned int curr_projid = -1; - unsigned int next_projid = -1; - - for (unsigned int j = 0; j < maxProc; j++) { - if (settings_.debugTracklet() && j == 0) { - edm::LogVerbatim("Tracklet") << getName() << " has " << mergedMatches.size() << " candidate matches"; - } - - countall++; - - const Stub* fpgastub = mergedMatches[j].second; - Tracklet* tracklet = mergedMatches[j].first.first; - const L1TStub* stub = fpgastub->l1tstub(); - - //check that the matches are ordered correctly - //allow equal here since we can have more than one candidate match per tracklet projection - if (oldTracklet != nullptr) { - assert(oldTracklet->TCID() <= tracklet->TCID()); - } - oldTracklet = tracklet; - - if (layerdisk_ < N_LAYER) { - //Integer calculation - - const Projection& proj = tracklet->proj(layerdisk_); - - int ir = fpgastub->r().value(); - int iphi = proj.fpgaphiproj().value(); - int icorr = (ir * proj.fpgaphiprojder().value()) >> icorrshift_; - iphi += icorr; - - int iz = proj.fpgarzproj().value(); - int izcor = (ir * proj.fpgarzprojder().value() + (1 << (icorzshift_ - 1))) >> icorzshift_; - iz += izcor; - - int ideltaz = fpgastub->z().value() - iz; - int ideltaphi = (fpgastub->phi().value() << phi0shift_) - (iphi << (settings_.phi0bitshift() - 1 + phi0shift_)); - - //Floating point calculations - - double phi = stub->phi() - phioffset; - double r = stub->r(); - double z = stub->z(); - - if (settings_.useapprox()) { - double dphi = reco::reduceRange(phi - fpgastub->phiapprox(0.0, 0.0)); - assert(std::abs(dphi) < 0.001); - phi = fpgastub->phiapprox(0.0, 0.0); - z = fpgastub->zapprox(); - r = fpgastub->rapprox(); - } - - if (phi < 0) - phi += 2 * M_PI; - - double dr = r - settings_.rmean(layerdisk_); - assert(std::abs(dr) < settings_.drmax()); - - double dphi = reco::reduceRange(phi - (proj.phiproj() + dr * proj.phiprojder())); - - double dz = z - (proj.rzproj() + dr * proj.rzprojder()); - - double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dr * proj.phiprojderapprox())); - - double dzapprox = z - (proj.rzprojapprox() + dr * proj.rzprojderapprox()); - - int seedindex = tracklet->getISeed(); - unsigned int projindex = mergedMatches[j].first.second; // Allproj index - curr_projid = next_projid; - next_projid = projindex; - - // Do we have a new tracklet? - bool newtracklet = (j == 0 || projindex != curr_projid); - if (j == 0) - best_ideltar_disk = (1 << (fpgastub->r().nbits() - 1)); // Set to the maximum possible - // If so, replace the "best" values with the cut tables - if (newtracklet) { - best_ideltaphi_barrel = (int)phimatchcuttable_.lookup(seedindex); - best_ideltaz_barrel = (int)zmatchcuttable_.lookup(seedindex); - } - - assert(phimatchcuttable_.lookup(seedindex) > 0); - assert(zmatchcuttable_.lookup(seedindex) > 0); - - if (settings_.bookHistos()) { - bool truthmatch = tracklet->stubtruthmatch(stub); - - HistBase* hists = globals_->histograms(); - hists->FillLayerResidual(layerdisk_ + 1, - seedindex, - dphiapprox * settings_.rmean(layerdisk_), - ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_), - ideltaz * fact_ * settings_.kz(), - dz, - truthmatch); - } - - //This would catch significant consistency problems in the configuration - helps to debug if there are problems. - if (std::abs(dphi) > 0.5 * settings_.dphisectorHG() || std::abs(dphiapprox) > 0.5 * settings_.dphisectorHG()) { - throw cms::Exception("LogicError") - << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox << endl; - } - - if (settings_.writeMonitorData("Residuals")) { - double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); - - globals_->ofstream("layerresiduals.txt") - << layerdisk_ + 1 << " " << seedindex << " " << pt << " " - << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " " - << dphiapprox * settings_.rmean(layerdisk_) << " " - << phimatchcuttable_.lookup(seedindex) * settings_.kphi1() * settings_.rmean(layerdisk_) << " " - << ideltaz * fact_ * settings_.kz() << " " << dz << " " - << zmatchcuttable_.lookup(seedindex) * settings_.kz() << endl; - } - - // integer match - bool imatch = (std::abs(ideltaphi) <= best_ideltaphi_barrel) && (ideltaz * fact_ < best_ideltaz_barrel) && - (ideltaz * fact_ >= -best_ideltaz_barrel); - // Update the "best" values - if (imatch) { - best_ideltaphi_barrel = std::abs(ideltaphi); - best_ideltaz_barrel = std::abs(ideltaz * fact_); - } - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " " - << phimatchcuttable_.lookup(seedindex) << " ideltaz*fact cut " << ideltaz * fact_ - << " " << zmatchcuttable_.lookup(seedindex); - } - - if (imatch) { - countsel++; - - tracklet->addMatch(layerdisk_, - ideltaphi, - ideltaz, - dphi, - dz, - dphiapprox, - dzapprox, - (phiregion_ << 7) + fpgastub->stubindex().value(), - mergedMatches[j].second); - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet; - } - - fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second); - } - } else { //disk matches - //check that stubs and projections in same half of detector - assert(stub->z() * tracklet->t() > 0.0); - - int sign = (tracklet->t() > 0.0) ? 1 : -1; - int disk = sign * (layerdisk_ - (N_LAYER - 1)); - assert(disk != 0); - - //Perform integer calculations here - - const Projection& proj = tracklet->proj(layerdisk_); - - int iz = fpgastub->z().value(); - int iphi = proj.fpgaphiproj().value(); - - //TODO - need to express in terms of constants - int shifttmp = 6; - int iphicorr = (iz * proj.fpgaphiprojder().value()) >> shifttmp; - - iphi += iphicorr; - - int ir = proj.fpgarzproj().value(); - - //TODO - need to express in terms of constants - int shifttmp2 = 7; - int ircorr = (iz * proj.fpgarzprojder().value()) >> shifttmp2; - - ir += ircorr; - - int ideltaphi = fpgastub->phi().value() * settings_.kphi() / settings_.kphi() - iphi; - - int irstub = fpgastub->r().value(); - int ialphafact = 0; - if (!stub->isPSmodule()) { - assert(irstub < (int)N_DSS_MOD * 2); - if (abs(disk) <= 2) { - ialphafact = ialphafactinner_[irstub]; - irstub = settings_.rDSSinner(irstub) / settings_.kr(); - } else { - ialphafact = ialphafactouter_[irstub]; - irstub = settings_.rDSSouter(irstub) / settings_.kr(); - } - } - - //TODO stub and projection r should not use different # bits... - int ideltar = (irstub >> 1) - ir; - - if (!stub->isPSmodule()) { - int ialpha = fpgastub->alpha().value(); - int iphialphacor = ((ideltar * ialpha * ialphafact) >> settings_.alphashift()); - ideltaphi += iphialphacor; - } - - //Perform floating point calculations here - - double phi = stub->phi() - phioffset; - double z = stub->z(); - double r = stub->r(); - - if (settings_.useapprox()) { - double dphi = reco::reduceRange(phi - fpgastub->phiapprox(0.0, 0.0)); - assert(std::abs(dphi) < 0.001); - phi = fpgastub->phiapprox(0.0, 0.0); - z = fpgastub->zapprox(); - r = fpgastub->rapprox(); - } - - if (phi < 0) - phi += 2 * M_PI; - - double dz = z - sign * settings_.zmean(layerdisk_ - N_LAYER); - - if (std::abs(dz) > settings_.dzmax()) { - throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " " << name_ << " " << tracklet->getISeed() - << "\n stub " << stub->z() << " disk " << disk << " " << dz; - } - - double phiproj = proj.phiproj() + dz * proj.phiprojder(); - - double rproj = proj.rzproj() + dz * proj.rzprojder(); - - double deltar = r - rproj; - - double dr = stub->r() - rproj; - - double dphi = reco::reduceRange(phi - phiproj); - - double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dz * proj.phiprojderapprox())); - - double drapprox = stub->r() - (proj.rzprojapprox() + dz * proj.rzprojderapprox()); - - double drphi = dphi * stub->r(); - double drphiapprox = dphiapprox * stub->r(); - - if (!stub->isPSmodule()) { - double alphanorm = stub->alphanorm(); - dphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r2(); - dphiapprox += drapprox * alphanorm * settings_.half2SmoduleWidth() / stub->r2(); - - drphi += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r(); - drphiapprox += dr * alphanorm * settings_.half2SmoduleWidth() / stub->r(); - } - - int seedindex = tracklet->getISeed(); - - int idrphicut = rphicutPStable_.lookup(seedindex); - int idrcut = rcutPStable_.lookup(seedindex); - if (!stub->isPSmodule()) { - idrphicut = rphicut2Stable_.lookup(seedindex); - idrcut = rcut2Stable_.lookup(seedindex); - } - - unsigned int projindex = mergedMatches[j].first.second; // Allproj index - curr_projid = next_projid; - next_projid = projindex; - // Do we have a new tracklet? - bool newtracklet = (j == 0 || projindex != curr_projid); - // If so, replace the "best" values with the cut tables - if (newtracklet) { - best_ideltaphi_disk = idrphicut; - best_ideltar_disk = idrcut; - } - - double drphicut = idrphicut * settings_.kphi() * settings_.kr(); - double drcut = idrcut * settings_.krprojshiftdisk(); - - bool match, imatch; - if (std::abs(dphi) < third * settings_.dphisectorHG() && - std::abs(dphiapprox) < third * settings_.dphisectorHG()) { //1/3 of sector size to catch errors - if (settings_.writeMonitorData("Residuals")) { - double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); - - globals_->ofstream("diskresiduals.txt") - << disk << " " << stub->isPSmodule() << " " << tracklet->layer() << " " << abs(tracklet->disk()) << " " - << pt << " " << ideltaphi * settings_.kphi() * stub->r() << " " << drphiapprox << " " << drphicut << " " - << ideltar * settings_.krprojshiftdisk() << " " << deltar << " " << drcut << " " << endl; - } - - // floating point match - match = (std::abs(drphi) < drphicut) && (std::abs(deltar) < drcut); - - // integer match - imatch = (std::abs(ideltaphi) * irstub < best_ideltaphi_disk) && (std::abs(ideltar) < best_ideltar_disk); - // Update the "best" values - if (imatch) { - best_ideltaphi_disk = std::abs(ideltaphi) * irstub; - best_ideltar_disk = std::abs(ideltar); - } - } else { - edm::LogProblem("Tracklet") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox - << "dphi " << dphi << " Seed / ISeed " << tracklet->getISeed() << endl; - match = false; - imatch = false; - } - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "imatch match disk: " << imatch << " " << match << " " << std::abs(ideltaphi) - << " " << drphicut / (settings_.kphi() * stub->r()) << " " << std::abs(ideltar) - << " " << drcut / settings_.krprojshiftdisk() << " r = " << stub->r(); - } - - if (imatch) { - countsel++; - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "MatchCalculator found match in disk " << getName(); - } - - tracklet->addMatch(layerdisk_, - ideltaphi, - ideltar, - drphi / stub->r(), - dr, - drphiapprox / stub->r(), - drapprox, - (phiregion_ << 7) + fpgastub->stubindex().value(), - fpgastub); - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet; - } - - fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second); - } - } - if (countall >= settings_.maxStep("MC")) - break; - } - - if (settings_.writeMonitorData("MC")) { - globals_->ofstream("matchcalculator.txt") << getName() << " " << countall << " " << countsel << endl; - } -} - -// Combines all tracklet/stub pairs into a vector -std::vector, const Stub*> > MatchCalculator::mergeMatches( - vector& candmatch) { - std::vector, const Stub*> > tmp; - - std::vector indexArray; - indexArray.reserve(candmatch.size()); - for (unsigned int i = 0; i < candmatch.size(); i++) { - indexArray.push_back(0); - } - - int bestIndex = -1; - do { - int bestSector = 100; - int bestTCID = -1; - bestIndex = -1; - for (unsigned int i = 0; i < candmatch.size(); i++) { - if (indexArray[i] >= candmatch[i]->nMatches()) { - // skip as we were at the end - continue; - } - int TCID = candmatch[i]->getMatch(indexArray[i]).first.first->TCID(); - int dSector = 0; - if (dSector > 2) - dSector -= N_SECTOR; - if (dSector < -2) - dSector += N_SECTOR; - assert(abs(dSector) < 2); - if (dSector == -1) - dSector = 2; - if (dSector < bestSector) { - bestSector = dSector; - bestTCID = TCID; - bestIndex = i; - } - if (dSector == bestSector) { - if (TCID < bestTCID || bestTCID < 0) { - bestTCID = TCID; - bestIndex = i; - } - } - } - if (bestIndex != -1) { - tmp.push_back(candmatch[bestIndex]->getMatch(indexArray[bestIndex])); - indexArray[bestIndex]++; - } - } while (bestIndex != -1); - - if (layerdisk_ < N_LAYER) { - int lastTCID = -1; - bool error = false; - - //Allow equal TCIDs since we can have multiple candidate matches - for (unsigned int i = 1; i < tmp.size(); i++) { - if (lastTCID > tmp[i].first.first->TCID()) { - edm::LogProblem("Tracklet") << "Wrong TCID ordering for projections in " << getName() << " last " << lastTCID - << " " << tmp[i].first.first->TCID(); - error = true; - } else { - lastTCID = tmp[i].first.first->TCID(); - } - } - - if (error) { - for (unsigned int i = 1; i < tmp.size(); i++) { - edm::LogProblem("Tracklet") << "Wrong order for in " << getName() << " " << i << " " << tmp[i].first.first - << " " << tmp[i].first.first->TCID(); - } - } - } - - for (unsigned int i = 0; i < tmp.size(); i++) { - if (i > 0) { - //This allows for equal TCIDs. This means that we can e.g. have a track seeded - //in L1L2 that projects to both L3 and D4. The algorithm will pick up the first hit and - //drop the second - - assert(tmp[i - 1].first.first->TCID() <= tmp[i].first.first->TCID()); - } - } - - return tmp; -} diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc deleted file mode 100644 index 61e17acac9a82..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc +++ /dev/null @@ -1,302 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/MatchEngine.h" -#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" -#include "L1Trigger/TrackFindingTracklet/interface/Util.h" -#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" - -#include - -using namespace std; -using namespace trklet; - -MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), luttable_(settings) { - layerdisk_ = initLayerDisk(3); - - barrel_ = layerdisk_ < N_LAYER; - - luttable_.initBendMatch(layerdisk_); - - nrinv_ = NRINVBITS; -} - -void MatchEngine::addOutput(MemoryBase* memory, string output) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " - << output; - } - if (output == "matchout") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - candmatches_ = tmp; - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output; -} - -void MatchEngine::addInput(MemoryBase* memory, string input) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " - << input; - } - if (input == "vmstubin") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - vmstubs_ = tmp; - return; - } - if (input == "vmprojin") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - vmprojs_ = tmp; - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; -} - -void MatchEngine::execute(unsigned int iSector) { - unsigned int countall = 0; - unsigned int countpass = 0; - - //bool print = (iSector == 3 && getName() == "ME_L3PHIC20"); - bool print = false; - - constexpr unsigned int kNBitsBuffer = 3; - - int writeindex = 0; - int readindex = 0; - std::pair projbuffer[1 << kNBitsBuffer]; //iproj zbin - - //The next projection to read, the number of projections and flag if we have more projections to read - int iproj = 0; - int nproj = vmprojs_->nTracklets(); - bool moreproj = iproj < nproj; - - //Projection that is read from the buffer and compared to stubs - int rzbin = 0; - int projfinerz = 0; - int projfinerzadj = 0; - unsigned int projfinephi = 0; - - int projindex = 0; - int projrinv = 0; - bool isPSseed = false; - - //Number of stubs for current zbin and the stub being processed on this clock - int nstubs = 0; - int istub = 0; - - //Main processing loops starts here - for (unsigned int istep = 0; istep < settings_.maxStep("ME"); istep++) { - countall++; - - int writeindexplus = (writeindex + 1) % (1 << kNBitsBuffer); - int writeindexplusplus = (writeindex + 2) % (1 << kNBitsBuffer); - - //Determine if buffer is full - or near full as a projection - //can point to two z bins we might fill two slots in the buffer - bool bufferfull = (writeindexplus == readindex) || (writeindexplusplus == readindex); - - //Determin if buffer is empty - bool buffernotempty = (writeindex != readindex); - - //If we have more projections and the buffer is not full we read - //next projection and put in buffer if there are stubs in the - //memory the projection points to - - if ((!moreproj) && (!buffernotempty)) - break; - - if (moreproj && (!bufferfull)) { - Tracklet* proj = vmprojs_->getTracklet(iproj); - - int iprojtmp = iproj; - - iproj++; - moreproj = iproj < nproj; - - unsigned int rzfirst = proj->proj(layerdisk_).fpgarzbin1projvm().value(); - unsigned int rzlast = rzfirst; - - bool second = proj->proj(layerdisk_).fpgarzbin2projvm().value(); - - if (second) - rzlast += 1; - - //Check if there are stubs in the memory - int nstubfirst = vmstubs_->nStubsBin(rzfirst); - int nstublast = vmstubs_->nStubsBin(rzlast); - bool savefirst = nstubfirst != 0; - bool savelast = second && (nstublast != 0); - - int writeindextmp = writeindex; - int writeindextmpplus = (writeindex + 1) % (1 << kNBitsBuffer); - - if (savefirst && savelast) { - writeindex = writeindexplusplus; - } else if (savefirst || savelast) { - writeindex = writeindexplus; - } - - if (savefirst) { //TODO for HLS (make code logic simpler) - std::pair tmp(iprojtmp, rzfirst); - projbuffer[writeindextmp] = tmp; - } - if (savelast) { - std::pair tmp(iprojtmp, rzlast + 100); //TODO for HLS (fix flagging that this is second bin) - if (savefirst) { - projbuffer[writeindextmpplus] = tmp; - } else { - projbuffer[writeindextmp] = tmp; - } - } - } - - //If the buffer is not empty we have a projection that we need to process. - - if (buffernotempty) { - int istubtmp = istub; - - //New projection - if (istub == 0) { - projindex = projbuffer[readindex].first; - rzbin = projbuffer[readindex].second; - bool second = false; - if (rzbin >= 100) { - rzbin -= 100; - second = true; - } - - Tracklet* proj = vmprojs_->getTracklet(projindex); - - FPGAWord fpgafinephi = proj->proj(layerdisk_).fpgafinephivm(); - - projfinephi = fpgafinephi.value(); - - nstubs = vmstubs_->nStubsBin(rzbin); - - projfinerz = proj->proj(layerdisk_).fpgafinerzvm().value(); - - projrinv = barrel_ ? ((1 << (nrinv_ - 1)) + ((-2 * proj->proj(layerdisk_).fpgaphiprojder().value()) >> - (proj->proj(layerdisk_).fpgaphiprojder().nbits() - (nrinv_ - 1)))) - : proj->proj(layerdisk_).getBendIndex().value(); - assert(projrinv >= 0); - if (settings_.extended() && projrinv == (1 << nrinv_)) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Extended tracking, projrinv:" << projrinv; - } - projrinv = (1 << nrinv_) - 1; - } - assert(projrinv < (1 << nrinv_)); - - isPSseed = proj->PSseed(); - - //Calculate fine z position - if (second) { - projfinerzadj = projfinerz - (1 << NFINERZBITS); - } else { - projfinerzadj = projfinerz; - } - if (nstubs == 1) { - istub = 0; - readindex = (readindex + 1) % (1 << kNBitsBuffer); - } else { - istub++; - } - } else { - //Check if last stub, if so, go to next buffer entry - if (istub + 1 >= nstubs) { - istub = 0; - readindex = (readindex + 1) % (1 << kNBitsBuffer); - } else { - istub++; - } - } - - //Read vmstub memory and extract data fields - const VMStubME& vmstub = vmstubs_->getVMStubMEBin(rzbin, istubtmp); - - int stubfinerz = vmstub.finerz().value(); - - bool isPSmodule; - - if (barrel_) { - isPSmodule = layerdisk_ < N_PSLAYER; - } else { - if (layerdisk_ < N_LAYER + 2) { - isPSmodule = ((rzbin & 7) < 3) || ((rzbin & 7) == 3 && stubfinerz <= 3); - } else { - isPSmodule = ((rzbin & 7) < 3) || ((rzbin & 7) == 3 && stubfinerz <= 2); - } - } - - assert(isPSmodule == vmstub.isPSmodule()); - - int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S; - - int deltaphi = projfinephi - vmstub.finephi().value(); - - constexpr int mindeltaphicut = 3; - constexpr int maxdeltaphicut = 5; - bool passphi = (std::abs(deltaphi) < mindeltaphicut) || (std::abs(deltaphi) > maxdeltaphicut); - - unsigned int index = (projrinv << nbits) + vmstub.bend().value(); - if (!barrel_ && isPSmodule) { - index += (1 << (nrinv_ + N_BENDBITS_2S)); - } - - //Check if stub z position consistent - int idrz = stubfinerz - projfinerzadj; - bool passz; - - if (barrel_) { - if (isPSseed) { - constexpr int drzcut = 1; - passz = std::abs(idrz) <= drzcut; - } else { - constexpr int drzcut = 5; - passz = std::abs(idrz) <= drzcut; - } - } else { - if (isPSmodule) { - constexpr int drzcut = 1; - passz = std::abs(idrz) <= drzcut; - } else { - constexpr int drzcut = 3; - passz = std::abs(idrz) <= drzcut; - } - } - - if (print) { - edm::LogVerbatim("Tracklet") << "istep index : " << istep << " " << index << " " << vmstub.bend().value() - << " rzbin istubtmp : " << rzbin << " " << istubtmp << " dz " << stubfinerz << " " - << projfinerzadj << " dphi: " << deltaphi; - } - - //Check if stub bend and proj rinv consistent - if (passz && passphi) { - if (luttable_.lookup(index)) { - Tracklet* proj = vmprojs_->getTracklet(projindex); - std::pair tmp(proj, vmprojs_->getAllProjIndex(projindex)); - if (settings_.writeMonitorData("Seeds")) { - ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << proj->getISeed() << endl; - fout.close(); - } - candmatches_->addMatch(tmp, vmstub.stub()); - countpass++; - } - } - } - } - - if (settings_.writeMonitorData("ME")) { - globals_->ofstream("matchengine.txt") << getName() << " " << countall << " " << countpass << endl; - } -} diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc index f04c76fbc924d..486254d491021 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc @@ -48,7 +48,7 @@ void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, bool usesecondMinus, bool usesecondPlus, bool isPSseed, - Tracklet* proj) { + Tracklet* proj, bool print) { vmstubsmemory_ = vmstubsmemory; idle_ = false; nrzbins_ = nrzbins; @@ -77,10 +77,14 @@ void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, isPSseed_ = isPSseed; proj_ = proj; + if (print) { + std::cout << "MEU Init: " << imeu_ << " " << projfinerz << " " << projfinephi << std::endl; + } + good__ = false; } -void MatchEngineUnit::step() { +void MatchEngineUnit::step(bool print) { good__ = !idle() && !almostfullsave_; if (!good__) @@ -102,6 +106,11 @@ void MatchEngineUnit::step() { } vmstub__ = vmstubsmemory_->getVMStubMEBin(slot, istub_); + + if (print) { + std::cout << "Read vmstub MEU "< tmppair(proj____, vmstub____.stub()); if (goodpair) { + if (print) { + std::cout << "Write tp match buffer : " << imeu_ << " " < @@ -38,7 +37,7 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g rSSinner_(settings), rSSouter_(settings), diskRadius_(settings), - fullmatches_(12), + fullmatches_(2), rinvbendlut_(settings), luttable_(settings), inputProjBuffer_(3) { @@ -68,7 +67,7 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g if (!barrel_) { rinvbendlut_.initProjectionBend( - global->ITC_L1L2()->der_phiD_final.K(), layerdisk_ - N_LAYER, nrbits_, nphiderbits_); + settings_.kphiderdisk(), layerdisk_ - N_LAYER, nrbits_, nphiderbits_); } nrinv_ = NRINVBITS; @@ -118,7 +117,6 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g best_ideltar_disk = 0xFFFF; curr_tracklet = nullptr; next_tracklet = nullptr; - first_ = false; } void MatchProcessor::addOutput(MemoryBase* memory, string output) { @@ -126,13 +124,16 @@ void MatchProcessor::addOutput(MemoryBase* memory, string output) { edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " << output; } - if (output.find("matchout") != std::string::npos) { + if (output.find("matchout0") != std::string::npos) { auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); - unsigned int iSeed = getISeed(tmp->getName()); - assert(iSeed < fullmatches_.size()); - assert(fullmatches_[iSeed] == nullptr); - fullmatches_[iSeed] = tmp; + fullmatches_[0] = tmp; + return; + } + if (output.find("matchout1") != std::string::npos) { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatches_[1] = tmp; return; } throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output; @@ -164,6 +165,58 @@ void MatchProcessor::addInput(MemoryBase* memory, string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; } + +void MatchProcessor::read_input_mems(bool &read_is_valid, + std::vector& mem_hasdata, + std::vector& nentries, + int &read_addr, + const std::vector& iMem, + const std::vector& iPage, + unsigned int &imem, + unsigned int &ipage) { + + + bool any_mem_hasdata = false; + + for (unsigned int i=0; i= nentries[read_imem]) { + // All entries in the memory[read_imem] have been read out + // Prepare to move to the next non-empty memory + read_addr = 0; + mem_hasdata[any_mem_hasdata ? read_imem : 0] = false; // set the current lowest 1 bit to 0 + } else { + read_addr = read_addr_next; + } + } + + read_is_valid = read_is_valid && any_mem_hasdata; + +} + + void MatchProcessor::execute(unsigned int iSector, double phimin) { assert(vmstubs_.size() == 1); @@ -182,25 +235,54 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { */ - // bool print = getName() == "MP_L3PHIC" && iSector == 3; - bool print = false; + + bool print = getName() == "MP_L3PHIB_E" && iSector == 3; + print = false; phimin_ = phimin; Tracklet* oldTracklet = nullptr; + candidatematch_ = false; + unsigned int countme = 0; unsigned int countall = 0; unsigned int countsel = 0; unsigned int countinputproj = 0; - unsigned int iprojmem = 0; - while (iprojmem < inputprojs_.size() && inputprojs_[iprojmem]->nTracklets() == 0) { - iprojmem++; + if (print) { + for (unsigned int i=0; inPage(); p++) { + std::cout << "ProjOcc: " << inputprojs_[i]->getName() << " " << p << " " << inputprojs_[i]->nTracklets(p) << std::endl; + } + } + } + + unsigned int imem = 0; + unsigned int ipage = 0; + + std::vector iMem, iPage, nentries; + std::vector mem_hasdata; + + while (imem < inputprojs_.size()) { + iMem.push_back(imem); + iPage.push_back(ipage); + nentries.push_back(inputprojs_[imem]->nTracklets(ipage)); + mem_hasdata.push_back(inputprojs_[imem]->nTracklets(ipage)>0); + ipage++; + if (ipage>=inputprojs_[imem]->nPage()) { + ipage = 0; + imem++; + } } - unsigned int iproj = 0; + imem=0; + ipage=0; + int read_address = 0; + int mem_read_addr = 0; + + inputProjBuffer_.reset(); for (const auto& inputproj : inputprojs_) { @@ -211,32 +293,42 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { matchengine.reset(); } - ProjectionTemp tmpProj_, tmpProj__; - bool good_ = false; - bool good__ = false; + Tracklet *projdata = 0; + Tracklet *projdata_ = 0; + bool validin = false; + bool validin_ = false; + bool validmem = false; + + // Reset so events avoids stale pointers + curr_tracklet = nullptr; + next_tracklet = nullptr; + for (unsigned int istep = 0; istep < settings_.maxStep("MP"); istep++) { + + //bool projdone = false; + + bool projBufferNearFull = inputProjBuffer_.nearfull4(); + // This print statement is useful for detailed comparison with the HLS code // It prints out detailed status information for each clock step - /* + if (print) { - cout << "istep = "< candmatch = matchengines_[iMEbest].read(); - const Stub* fpgastub = candmatch.second; - Tracklet* tracklet = candmatch.first; + candidatematch_ = true; + + fpgastub_ = candmatch.second; + tracklet_ = candmatch.first; //Consistency check if (oldTracklet != nullptr) { //allow equal here since we can have more than one cadidate match per tracklet projection //cout << "old new : "<TCID()<<" "<TCID()<<" "<TCID() <= tracklet->TCID()); + assert(oldTracklet->TCID() <= tracklet_->TCID()); } - oldTracklet = tracklet; + oldTracklet = tracklet_; + /* bool match = matchCalculator(tracklet, fpgastub, print, istep); - + if (settings_.debugTracklet() && match) { edm::LogVerbatim("Tracklet") << getName() << " have match"; } @@ -282,6 +395,7 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { countall++; if (match) countsel++; + */ } //Step 2 @@ -318,165 +432,182 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { tmpProj.use(1, 0), tmpProj.use(1, 1), tmpProj.isPSseed(), - tmpProj.proj()); + tmpProj.proj(), print); meactive = true; addedProjection = true; } else { - matchengines_[iME].step(); + matchengines_[iME].step(print); } - matchengines_[iME].processPipeline(); + matchengines_[iME].processPipeline(print); } //Step 1 //First step here checks if we have more input projections to put into //the input puffer for projections - if (good__) { - inputProjBuffer_.store(tmpProj__); - } + if (validin_) { + //if (settings_.debugTracklet()) { + // edm::LogVerbatim("Tracklet") << getName() << " have projection in memory : " << projMem->getName(); + //} - good__ = good_; - tmpProj__ = tmpProj_; + FPGAWord fpgaphi = projdata_->proj(layerdisk_).fpgaphiproj(); - good_ = false; + unsigned int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1); - if (iprojmem < inputprojs_.size()) { - TrackletProjectionsMemory* projMem = inputprojs_[iprojmem]; - if (!projBuffNearFull) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " have projection in memory : " << projMem->getName(); - } + constexpr int nextrabits = 2; + int overlapbits = nvmbits_ + nextrabits; - Tracklet* proj = projMem->getTracklet(iproj); + unsigned int extrabits = fpgaphi.bits(fpgaphi.nbits() - overlapbits - nextrabits, nextrabits); - FPGAWord fpgaphi = proj->proj(layerdisk_).fpgaphiproj(); + unsigned int ivmPlus = iphi; - unsigned int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1); + int shift = 0; - constexpr int nextrabits = 2; - int overlapbits = nvmbits_ + nextrabits; + if (extrabits == ((1U << nextrabits) - 1) && iphi != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) { + shift = 1; + ivmPlus++; + } + unsigned int ivmMinus = iphi; + if (extrabits == 0 && iphi != 0) { + shift = -1; + ivmMinus--; + } - unsigned int extrabits = fpgaphi.bits(fpgaphi.nbits() - overlapbits - nextrabits, nextrabits); + int projrinv = -1; + if (barrel_) { + FPGAWord phider = projdata_->proj(layerdisk_).fpgaphiprojder(); + projrinv = (1 << (nrinv_ - 1)) - 1 - (phider.value() >> (phider.nbits() - nrinv_)); + } else { + //The next lines looks up the predicted bend based on: + // 1 - r projections + // 2 - phi derivative + // 3 - the sign - i.e. if track is forward or backward - unsigned int ivmPlus = iphi; + int rindex = + (projdata_->proj(layerdisk_).fpgarzproj().value() >> (projdata_->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) & + ((1 << nrbits_) - 1); - int shift = 0; + int phiprojder = projdata_->proj(layerdisk_).fpgaphiprojder().value(); - if (extrabits == ((1U << nextrabits) - 1) && iphi != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) { - shift = 1; - ivmPlus++; - } - unsigned int ivmMinus = iphi; - if (extrabits == 0 && iphi != 0) { - shift = -1; - ivmMinus--; - } + int phiderindex = (phiprojder >> (projdata_->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) & + ((1 << nphiderbits_) - 1); - int projrinv = -1; - if (barrel_) { - FPGAWord phider = proj->proj(layerdisk_).fpgaphiprojder(); - projrinv = (1 << (nrinv_ - 1)) - 1 - (phider.value() >> (phider.nbits() - nrinv_)); - } else { - //The next lines looks up the predicted bend based on: - // 1 - r projections - // 2 - phi derivative - // 3 - the sign - i.e. if track is forward or backward + int signindex = projdata_->proj(layerdisk_).fpgarzprojder().value() < 0; - int rindex = - (proj->proj(layerdisk_).fpgarzproj().value() >> (proj->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) & - ((1 << nrbits_) - 1); + int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; - int phiprojder = proj->proj(layerdisk_).fpgaphiprojder().value(); + projrinv = rinvbendlut_.lookup(bendindex); - int phiderindex = (phiprojder >> (proj->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) & - ((1 << nphiderbits_) - 1); + projdata_->proj(layerdisk_).setBendIndex(projrinv); + } + assert(projrinv >= 0); - int signindex = proj->proj(layerdisk_).fpgarzprojder().value() < 0; + unsigned int projfinephi = + (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + NFINEPHIBITS))) & ((1 << NFINEPHIBITS) - 1); - int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; + unsigned int slot; + bool second; + int projfinerz; - projrinv = rinvbendlut_.lookup(bendindex); + if (barrel_) { + slot = projdata_->proj(layerdisk_).fpgarzbin1projvm().value(); + second = projdata_->proj(layerdisk_).fpgarzbin2projvm().value(); + projfinerz = projdata_->proj(layerdisk_).fpgafinerzvm().value(); + } else { + //The -1 here is due to not using the full range of bits. Should be fixed. + unsigned int ir = projdata_->proj(layerdisk_).fpgarzproj().value() >> + (projdata_->proj(layerdisk_).fpgarzproj().nbits() - nrprojbits_ - 1); + unsigned int word = diskRadius_.lookup(ir); + + slot = (word >> 1) & ((1 << N_RZBITS) - 1); + if (projdata_->proj(layerdisk_).fpgarzprojder().value() < 0) { + slot += (1 << N_RZBITS); + } + second = word & 1; + projfinerz = word >> 4; + } - proj->proj(layerdisk_).setBendIndex(projrinv); - } - assert(projrinv >= 0); - - unsigned int projfinephi = - (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + NFINEPHIBITS))) & ((1 << NFINEPHIBITS) - 1); - - unsigned int slot; - bool second; - int projfinerz; - - if (barrel_) { - slot = proj->proj(layerdisk_).fpgarzbin1projvm().value(); - second = proj->proj(layerdisk_).fpgarzbin2projvm().value(); - projfinerz = proj->proj(layerdisk_).fpgafinerzvm().value(); - } else { - //The -1 here is due to not using the full range of bits. Should be fixed. - unsigned int ir = proj->proj(layerdisk_).fpgarzproj().value() >> - (proj->proj(layerdisk_).fpgarzproj().nbits() - nrprojbits_ - 1); - unsigned int word = diskRadius_.lookup(ir); - - slot = (word >> 1) & ((1 << N_RZBITS) - 1); - if (proj->proj(layerdisk_).fpgarzprojder().value() < 0) { - slot += (1 << N_RZBITS); - } - second = word & 1; - projfinerz = word >> 4; - } + bool isPSseed = projdata_->PSseed(); - bool isPSseed = proj->PSseed(); + int nbins = (1 << N_RZBITS); + if (layerdisk_ >= N_LAYER) { + nbins *= 2; //twice as many bins in disks (since there are two disks) + } - int nbins = (1 << N_RZBITS); - if (layerdisk_ >= N_LAYER) { - nbins *= 2; //twice as many bins in disks (since there are two disks) - } + VMStubsMEMemory* stubmem = vmstubs_[0]; + bool usefirstMinus = stubmem->nStubsBin(ivmMinus * nbins + slot) != 0; + bool usesecondMinus = (second && (stubmem->nStubsBin(ivmMinus * nbins + slot + 1) != 0)); + bool usefirstPlus = ivmPlus != ivmMinus && (stubmem->nStubsBin(ivmPlus * nbins + slot) != 0); + bool usesecondPlus = ivmPlus != ivmMinus && (second && (stubmem->nStubsBin(ivmPlus * nbins + slot + 1) != 0)); + + bool good = usefirstPlus || usesecondPlus || usefirstMinus || usesecondMinus; + + /* + int offset = 4; + + int ztemp = proj->proj(layerdisk_).fpgarzproj().value() >> (proj->proj(layerdisk_).fpgarzproj().nbits() - settings_.MEBinsBits() - NFINERZBITS); + unsigned int zbin1 = (1 << (settings_.MEBinsBits() - 1)) + ((ztemp - offset) >> NFINERZBITS); + unsigned int zbin2 = (1 << (settings_.MEBinsBits() - 1)) + ((ztemp + offset) >> NFINERZBITS); + + if (zbin1 >= settings_.MEBins()) { + zbin1 = 0; //note that zbin1 is unsigned + } + if (zbin2 >= settings_.MEBins()) { + zbin2 = settings_.MEBins() - 1; + } + */ + + if (good) { + ProjectionTemp tmpProj(projdata_, + slot, + projrinv, + projfinerz, + projfinephi, + ivmMinus, + shift, + usefirstMinus, + usefirstPlus, + usesecondMinus, + usesecondPlus, + isPSseed); + if (print) { + std::cout << "Add projection to inputProjBuffer istep = " << istep << std::endl; + } + inputProjBuffer_.store(tmpProj); + } + } - VMStubsMEMemory* stubmem = vmstubs_[0]; - bool usefirstMinus = stubmem->nStubsBin(ivmMinus * nbins + slot) != 0; - bool usesecondMinus = (second && (stubmem->nStubsBin(ivmMinus * nbins + slot + 1) != 0)); - bool usefirstPlus = ivmPlus != ivmMinus && (stubmem->nStubsBin(ivmPlus * nbins + slot) != 0); - bool usesecondPlus = ivmPlus != ivmMinus && (second && (stubmem->nStubsBin(ivmPlus * nbins + slot + 1) != 0)); - - good_ = usefirstPlus || usesecondPlus || usefirstMinus || usesecondMinus; - - if (good_) { - ProjectionTemp tmpProj(proj, - slot, - projrinv, - projfinerz, - projfinephi, - ivmMinus, - shift, - usefirstMinus, - usefirstPlus, - usesecondMinus, - usesecondPlus, - isPSseed); - tmpProj_ = tmpProj; - } + projdata_ = projdata; + validin_ = validin; - iproj++; - if (iproj == projMem->nTracklets()) { - iproj = 0; - do { - iprojmem++; - } while (iprojmem < inputprojs_.size() && inputprojs_[iprojmem]->nTracklets() == 0); - } + validin = validmem; - } else { - projdone = true && !good_ && !good__; + if (validin) { + TrackletProjectionsMemory* projMem = inputprojs_[imem]; + projdata = projMem->getTracklet(read_address,ipage); + if (print & validin) { + std::cout << "Reading iprojmem page, readaddress : " << istep << " " << imem << " " << ipage << " " << read_address << std::endl; } } + + validmem = !projBufferNearFull; + + read_address = mem_read_addr; + if (validmem) { + read_input_mems(validmem, mem_hasdata, nentries, mem_read_addr, iMem, iPage, imem, ipage); + } + + + // // Check if done // // // - if ((projdone && !meactive && inputProjBuffer_.rptr() == inputProjBuffer_.wptr()) || + /* + if ((iprojmem!=0 && projdone && !meactive && inputProjBuffer_.rptr() == inputProjBuffer_.wptr()) || (istep == settings_.maxStep("MP") - 1)) { if (settings_.writeMonitorData("MP")) { globals_->ofstream("matchprocessor.txt") << getName() << " " << istep << " " << countall << " " << countsel @@ -484,19 +615,22 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { } break; } - } + */ + + + } // end of istep if (settings_.writeMonitorData("MC")) { globals_->ofstream("matchcalculator.txt") << getName() << " " << countall << " " << countsel << endl; } } -bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, bool, unsigned int istep) { +bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, bool print, unsigned int istep) { const L1TStub* stub = fpgastub->l1tstub(); if (layerdisk_ < N_LAYER) { const Projection& proj = tracklet->proj(layerdisk_); - int ir = fpgastub->r().value(); + int ir = fpgastub->rvalue(); int iphi = proj.fpgaphiproj().value(); int icorr = (ir * proj.fpgaphiprojder().value()) >> icorrshift_; iphi += icorr; @@ -542,8 +676,7 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b next_tracklet = tracklet; // Do we have a new tracklet? - bool newtracklet = (!first_ || next_tracklet != curr_tracklet); - first_ = newtracklet ? true : first_; + bool newtracklet = next_tracklet != curr_tracklet; if (istep == 0) best_ideltar_disk = (1 << (fpgastub->r().nbits() - 1)); // Set to the maximum possible // If so, replace the "best" values with the cut tables @@ -591,8 +724,9 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b //This would catch significant consistency problems in the configuration - helps to debug if there are problems. if (std::abs(dphi) > 0.5 * settings_.dphisectorHG() || std::abs(dphiapprox) > 0.5 * settings_.dphisectorHG()) { - throw cms::Exception("LogicError") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox - << endl; + //throw cms::Exception("LogicError") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox + // << endl; + std::cout << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox << std::endl; } bool keep = true; @@ -612,6 +746,11 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b } if (imatch) { + + if (print) { + std::cout << "Adding match on istep = " << istep << std::endl; + } + tracklet->addMatch(layerdisk_, ideltaphi, ideltaz, @@ -627,8 +766,12 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b } int iSeed = tracklet->getISeed(); - assert(fullmatches_[iSeed] != nullptr); - fullmatches_[iSeed]->addMatch(tracklet, fpgastub); + int iTB = 0; + if ( iSeed == 2 || iSeed == 4 || iSeed == 5 || iSeed == 6 ) { + iTB = 1; + } + assert(fullmatches_[iTB] != nullptr); + fullmatches_[iTB]->addMatch(tracklet, fpgastub); return true; } else { @@ -660,7 +803,7 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b int ideltaphi = fpgastub->phi().value() - iphi; - int irstub = fpgastub->r().value(); + int irstub = fpgastub->rvalue(); int ialphafact = 0; if (!stub->isPSmodule()) { assert(irstub < (int)N_DSS_MOD * 2); @@ -744,8 +887,7 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b curr_tracklet = next_tracklet; next_tracklet = tracklet; // Do we have a new tracklet? - bool newtracklet = (!first_ || next_tracklet != curr_tracklet); - first_ = newtracklet ? true : first_; + bool newtracklet = next_tracklet != curr_tracklet; // If so, replace the "best" values with the cut tables if (newtracklet) { best_ideltaphi_disk = idrphicut; @@ -766,7 +908,7 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b } bool match = (std::abs(drphi) < drphicut) && (std::abs(deltar) < drcut); - bool imatch = (std::abs(ideltaphi * irstub) < best_ideltaphi_disk) && (std::abs(ideltar) < best_ideltar_disk); + bool imatch = (std::abs(ideltaphi * irstub) < idrphicut) && (std::abs(ideltar) < idrcut); if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "imatch match disk: " << imatch << " " << match << " " << std::abs(ideltaphi) @@ -798,8 +940,8 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b if (std::abs(dphi) >= third * settings_.dphisectorHG()) { edm::LogPrint("Tracklet") << "dphi " << dphi << " ISeed " << tracklet->getISeed(); } - assert(std::abs(dphi) < third * settings_.dphisectorHG()); - assert(std::abs(dphiapprox) < third * settings_.dphisectorHG()); + //assert(std::abs(dphi) < third * settings_.dphisectorHG()); + //assert(std::abs(dphiapprox) < third * settings_.dphisectorHG()); tracklet->addMatch(layerdisk_, ideltaphi, @@ -816,8 +958,12 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b } int iSeed = tracklet->getISeed(); - assert(fullmatches_[iSeed] != nullptr); - fullmatches_[iSeed]->addMatch(tracklet, fpgastub); + int iTB = 0; + if ( iSeed == 2 || iSeed == 4 || iSeed == 5 || iSeed == 6 ) { + iTB = 1; + } + assert(fullmatches_[iTB] != nullptr); + fullmatches_[iTB]->addMatch(tracklet, fpgastub); return true; } else { diff --git a/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc index bbddcf67d5d9a..3362536bdba19 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc @@ -160,10 +160,9 @@ unsigned int ProcessBase::getISeed(const std::string& name) { std::string name2 = name1.substr(0, pos); unordered_map seedmap = { - {"L1L2", 0}, {"L2L3", 1}, {"L3L4", 2}, {"L5L6", 3}, {"D1D2", 4}, {"D3D4", 5}, {"L1D1", 6}, - {"L2D1", 7}, {"L1L2XX", 0}, {"L2L3XX", 1}, {"L3L4XX", 2}, {"L5L6XX", 3}, {"D1D2XX", 4}, {"D3D4XX", 5}, - {"L1D1XX", 6}, {"L2D1XX", 7}, {"L3L4L2", 8}, {"L5L6L4", 9}, {"L2L3D1", 10}, {"D1D2L2", 11}}; - auto found = seedmap.find(name2); + {"AAAA", 0}, {"BBBB", 1} + }; + auto found = seedmap.find(name2); if (found != seedmap.end()) return found->second; diff --git a/L1Trigger/TrackFindingTracklet/src/Projection.cc b/L1Trigger/TrackFindingTracklet/src/Projection.cc index 2f08e1a5348a2..3267f8d9cc14b 100644 --- a/L1Trigger/TrackFindingTracklet/src/Projection.cc +++ b/L1Trigger/TrackFindingTracklet/src/Projection.cc @@ -32,7 +32,11 @@ void Projection::init(Settings const& settings, if (layerdisk < N_LAYER) { fpgarzproj_.set(irzproj, settings.nzbitsstub(layerdisk), false, __LINE__, __FILE__); } else { - fpgarzproj_.set(irzproj, settings.nrbitsstub(layerdisk), false, __LINE__, __FILE__); + fpgarzproj_.set(irzproj, + settings.nrbitsstub(layerdisk) + 1, + false, + __LINE__, + __FILE__); // + 1 to account for artificially reduced nrbits from r value offset for diskps stubs } if (layerdisk < N_LAYER) { diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc new file mode 100644 index 0000000000000..447f5a5d81c5e --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc @@ -0,0 +1,377 @@ +#include "L1Trigger/TrackFindingTracklet/interface/ProjectionCalculator.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" +#include "L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace std; +using namespace trklet; + +ProjectionCalculator::ProjectionCalculator(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) { + + //Constants for coordinates and track parameter definitions (taken from TrackletCalculatorBase.cc) + n_phi_ = 17; + n_r_ = 12; + n_z_ = 11; + n_phi0_ = 16; + n_rinv_ = 13; + n_t_ = 9; + n_phidisk_ = n_phi_-3; + n_rdisk_ = n_r_-1; + + //Constants used for projectison to layers + n_s_ = 12; + n_s6_ = 14; + + //Constants used for projectison to disks + n_tinv_ = 12; + n_y_ = 14; + n_x_ = 14; + n_xx6_ = 14; + + phiHG_ = settings_.dphisectorHG(); + + LUT_itinv_.resize(8192); + + for (int it = 0; it < 8192; it++) { + if (it<100) { + LUT_itinv_[it] = 0; + } else { + LUT_itinv_[it] = (1 << (n_t_ + n_tinv_)) / abs(it); + } + } + + for (unsigned int layerdisk = 0; layerdisk < N_LAYER + N_DISK; layerdisk++) { + std::vector> tmp(settings_.nallstubs(layerdisk)); + outputproj_.push_back(tmp); + } + +} + + // Project to layer (taken from TrackletCalculatorBase.cc) +void ProjectionCalculator::projLayer(int ir, int irinv, int iphi0, int it, int iz0, int &iz, int &iphi) { + int irtilde = ir*phiHG_/sqrt(6.0)+0.5; + int is = (irtilde*irinv) >> n_s_; + int is6 = (1 << n_s6_) + ((is*is) >> (2 + 2*n_r_ + 2*n_rinv_ - 2*n_s_ - n_s6_)); + int iu = (ir*irinv) >> (n_r_ + n_rinv_ + 1 - n_phi_); + iphi = (iphi0 << (n_phi_ - n_phi0_)) - ((iu*is6) >> n_s6_); + int iv = (it*ir) >> (n_r_ + n_t_ - n_z_); + iz = iz0 + ((iv*is6) >> n_s6_); +} + // Project to disk (taken from TrackletCalculatorBase.cc) +void ProjectionCalculator::projDisk(int iz, int irinv, int iphi0, int it,int iz0, int &ir, int &iphi, int &iderphi, int &iderr) { + + int iz0_sign = (it>0)?iz0:-iz0; + + assert(abs(it)> 17; + iderr = itinv >> 5; + + if (it<0) { + iderphi = -iderphi; + iderr = -iderr; + } + + int iw = (((iz << (n_r_ - n_z_)) - (iz0_sign << (n_r_ - n_z_)))*itinv) >> n_tinv_; + + iphi = (iphi0 >> (n_phi0_ - n_phidisk_)) - ((iw*irinv) >> (1 + n_r_ + n_rinv_ - n_phidisk_)); + + int ifact = (1 << n_y_)*phiHG_/sqrt(6.0); + + int iy = (ifact * irinv) >> n_y_; + + int ix = (iw*iy) >> n_x_; + + int ix6 = (1 << n_xx6_) - ( (ix*ix) >> (2 + 2*n_r_ + 2*n_rinv_ - 2*n_x_ - n_xx6_)); + + ir = (iw*ix6) >> (n_r_ - n_rdisk_ + n_xx6_); +} + +void ProjectionCalculator::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + if (output == "projout") { + auto* tmp = dynamic_cast(memory); + int extraMPOffset = 0; + if (memory->getName().substr(memory->getName().size()-2,2) == "_E") { + extraMPOffset = 2; + } + std::cout << "extraMPOffset: " << memory->getName() << " " << extraMPOffset << std::endl; + unsigned int layerdisk = memory->getName()[memory->getName().size() - 5 - extraMPOffset] - '1'; //layer or disk counting from 0 + unsigned int phiregion = memory->getName()[memory->getName().size() - 1 - extraMPOffset] - 'A'; //phiregion counting from 0 + if (memory->getName()[memory->getName().size() - 6 - extraMPOffset] == 'D') layerdisk += N_LAYER; + projnames_.push_back(memory->getName()); + assert(layerdisk < N_LAYER + N_DISK); + assert(phiregion < outputproj_[layerdisk].size()); + assert(outputproj_[layerdisk][phiregion].size()<2); + assert(tmp != nullptr); + outputproj_[layerdisk][phiregion].push_back(tmp); + return; + } + + if (output == "tparout") { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + outputpars_.push_back(tmp); + return; + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output; +} + +void ProjectionCalculator::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + + if (input == "tparin" ) { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + inputpars_.push_back(tmp); + return; + } + + if (input == "projin" ) { + //Hack to keep projection in config but ignore here + return; + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; +} + +void ProjectionCalculator::execute() { + + for(unsigned int i = 0 ; i < inputpars_.size() ; i++) { // send copy of tpars to TB + int projPage = 0; + std::string iname = inputpars_[i]->getName(); + + + std::vector seedNames = {"L1L2", "L2L3", "L3L4", "L5L6", "D1D2", "D3D4", "L1D1", "L2D1"}; + + for (int iSeed = 0; iSeed < 8; ++iSeed){ + std::string seed = iname.substr(5, 4); // extract seed from name + bool psSeed = !(iSeed == Seed::L3L4 || iSeed == Seed::L5L6 ); + if (seed == seedNames[iSeed]){ // FIXME find easier way to get iSeed (probably from seed name) + unsigned int numTCs = nMergedTC[iSeed]; + for(unsigned int iTC = 0; iTC < numTCs; ++iTC){ + std::string tcStr = TrackletConfigBuilder::iMergedTCStr(iSeed, iTC); + size_t index = tcStr.find(iname[9]); // find index in merged TC string to find page + if (index != std::string::npos) { + projPage = static_cast(index); // calculate projPage FIXME find better way of doing this + } else { + continue; + } + } + + for(unsigned int k = 0 ; k < outputpars_.size() ; k++) { // add copy of par to merged par output memory + std::string oname = outputpars_[k]->getName(); + int parPage = iname[9]-oname[9]; + for(unsigned int j = 0; j < inputpars_[i]->nTracklets(); j++) { + outputpars_[k]->addTracklet(inputpars_[i]->getTracklet(j), parPage); + } + } + + + for(unsigned int k = 0; k < inputpars_[i]->nTracklets(); k++){ + auto tracklet = inputpars_[i]->getTracklet(k); + //double phi0 = tracklet->phi0(); // non-digi track params, currently unneeded / unused + //double z0 = tracklet->z0(); + //double t = tracklet->t(); + //double rinv = tracklet->rinv(); + + int irinv = tracklet->fpgarinv().value(); // digi track params + int iphi0 = tracklet->fpgaphi0().value(); + int iz0 = tracklet->fpgaz0().value(); + int it = tracklet->fpgat().value(); + + std::vector izr_LD(N_LAYER + N_DISK, 0); + std::vector iphi_LD(N_LAYER + N_DISK, 0); + std::vector valid_LD(N_LAYER + N_DISK, 0); + std::vector addedLayer(N_LAYER, 0); + std::vector der_phi_LD(2, 0); + std::vector der_zr_LD(2, 0); + + Projection projs[N_LAYER + N_DISK]; + + ///////////////////////////////// + // calculate layer projections // + ///////////////////////////////// + bool valid_zmin, valid_zmax, valid_phimin, valid_phimax; // CODE ADAPTED FROM FIRMWARE-HLS PROJECTIONCALCULATOR - could be simplified to only consider layers/disks in wiring config. + const int zmin = -(1 << (settings_.nzbitsstub(0) - 1)); + const int zmax = (1 << (settings_.nzbitsstub(0) - 1)); + const int phimax = (1 << (settings_.nphibitsstub(3))) - 1; + const int phimin = 0; + for (unsigned int iLayer = 0; iLayer < N_LAYER; ++iLayer){ // calculate layer projections + int ir; + ir = settings_.irmean(iLayer); + projLayer(ir, irinv, iphi0, it, iz0, izr_LD[iLayer], iphi_LD[iLayer]); + valid_zmin = izr_LD[iLayer] >= zmin; + valid_zmax = izr_LD[iLayer] < zmax; + valid_phimax = iphi_LD[iLayer] < phimax; + valid_phimin = iphi_LD[iLayer] > phimin; + valid_LD[iLayer] = valid_zmin & valid_zmax & valid_phimax & valid_phimin; + if(iLayer < N_PSLAYER){ // shift phi or z value if PS or 2S layer + iphi_LD[iLayer] = iphi_LD[iLayer] >> 3; + } + else{ + izr_LD[iLayer] = izr_LD[iLayer] >> 4; + } + } + + // Layer Proj Derivatives + der_phi_LD[0] = -(irinv >> (1+3)); + der_zr_LD[0] = it >> 3; + + //////////////////////////////// + // calculate disk projections // + //////////////////////////////// + double irmindisk = settings_.rmindisk() / settings_.krprojshiftdisk(); + double irmaxdisk = settings_.rmaxdisk() / settings_.krprojshiftdisk(); + + int tcut = 1.0/(settings_.ktpars()); + + for (unsigned int iDisk = N_LAYER; iDisk < N_LAYER + N_DISK; ++iDisk){ + int izproj = settings_.izmean(iDisk % N_LAYER); + projDisk(izproj, irinv, iphi0, it, iz0, izr_LD[iDisk], iphi_LD[iDisk], der_phi_LD[1], der_zr_LD[1]); + valid_LD[iDisk] = izr_LD[iDisk] >= irmindisk && izr_LD[iDisk] < irmaxdisk && ((it > tcut) || (it < -tcut)); + } + + /////////////////////////////////// + // Write projections to memories // + /////////////////////////////////// + + for (unsigned int j = 0; j < settings_.projlayers()[iSeed].size(); ++j){ + unsigned int layer = settings_.projlayers()[iSeed][j]; // Loop through layers/disks projected to + if (layer == 0) continue; // for seeds not projecting to any layers + if(valid_LD[layer - 1]){ // If projection to layer/disk is valid + if ((izr_LD[layer - 1] == - (1 << (settings_.nzbitsstub(layer - 1) - 1))) || (izr_LD[layer - 1] == ((1 << (settings_.nzbitsstub(layer - 1) - 1)) - 1))) { // reject extreme z values + continue; + } + if (std::abs(izr_LD[layer - 1]) > 2048) { + continue; + } + + double phiprojlayer = iphi_LD[layer - 1] * settings_.kphi(layer - 1); // get un-digi projections + double zprojlayer = izr_LD[layer - 1] * settings_.kz(); // FIXME find better way to calculate these - but don't have stub coordinates to use exacttracklet function + double phiderlayer = der_phi_LD[0] * settings_.kphider(); + double zderlayer = der_zr_LD[0] * settings_.kzder(); + + projs[layer - 1].init(settings_, + layer - 1, + iphi_LD[layer - 1], + izr_LD[layer - 1], + der_phi_LD[0], + der_zr_LD[0], + phiprojlayer, + zprojlayer, + phiderlayer, + zderlayer, + phiprojlayer, + zprojlayer, + phiderlayer, + zderlayer, + psSeed); + addedLayer[layer - 1] = true; + } + } + for (unsigned int j = 0; j < settings_.projdisks()[iSeed].size(); ++j){ + unsigned int disk = settings_.projdisks()[iSeed][j]; + if (disk == 0) continue; // for seeds not projecting to any disks + if(valid_LD[N_LAYER + disk - 1]){ // If projection to layer/disk is valid + + if (iphi_LD[N_LAYER + disk - 1] <= 0) // reject extreme phi values + continue; + if (iphi_LD[N_LAYER + disk - 1] >= (1 << settings_.nphibitsstub(0)) - 1) + continue; + + if (iSeed <= 4){ // if barrel seed, need to check if haven't already projected to layer + if (disk == 1 && addedLayer[5]) continue; + if (disk == 2 && addedLayer[4]) continue; + if (disk == 3 && addedLayer[3]) continue; + if (disk == 4 && addedLayer[2]) continue; + } + + double phiprojdisk = iphi_LD[N_LAYER + disk - 1]*settings_.kphi(N_LAYER); // un-digitize values using granularities for initializing projections + double rprojdisk = izr_LD[N_LAYER + disk - 1] * settings_.kr(); + double phiderdisk = der_phi_LD[1]* settings_.kphiderdisk(); + double rderdisk = der_zr_LD[1] * settings_.krder(); + + projs[N_LAYER + disk - 1].init(settings_, + N_LAYER + disk - 1, + iphi_LD[N_LAYER + disk - 1], + izr_LD[N_LAYER + disk - 1], + der_phi_LD[1], + der_zr_LD[1], + phiprojdisk, + rprojdisk, + phiderdisk, + rderdisk, + phiprojdisk, + rprojdisk, + phiderdisk, + rderdisk, + psSeed); + } + } + + tracklet->addProjs(projs); + for(unsigned int layerdisk = 0; layerdisk < N_LAYER + N_DISK; ++layerdisk){ + if (tracklet->validProj(layerdisk)) { + if (layerdisk < N_LAYER){ + + FPGAWord fpgaz = tracklet->proj(layerdisk).fpgarzproj(); + FPGAWord fpgaphi = tracklet->proj(layerdisk).fpgaphiproj(); + + if (fpgaphi.atExtreme()) + edm::LogProblem("Tracklet") << "at extreme! " << fpgaphi.value(); + + assert(!fpgaphi.atExtreme()); + + if (fpgaz.atExtreme()) + continue; + + if (std::abs(fpgaz.value() * settings_.kz()) > settings_.zlength()) + continue; + + int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); + int iphi = iphivmRaw / (32 / settings_.nallstubs(layerdisk)); + + for (unsigned int i = 0; i < outputproj_[layerdisk][iphi].size(); i++) { + outputproj_[layerdisk][iphi][i]->addProj(tracklet, projPage); // FIXME write to correct page - though doesn't affect emulation + } + } else{ + + FPGAWord fpgar = tracklet->proj(layerdisk).fpgarzproj(); + + if (fpgar.value() * settings_.krprojshiftdisk() < settings_.rmindiskvm()) + continue; + if (fpgar.value() * settings_.krprojshiftdisk() > settings_.rmaxdisk()) + continue; + + FPGAWord fpgaphi = tracklet->proj(layerdisk).fpgaphiproj(); + int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); + int iphi = iphivmRaw / (32 / settings_.nallstubs(layerdisk));//>> settings_.nbitsallstubs(layerdisk); + + for (unsigned int i = 0; i < outputproj_[layerdisk][iphi].size(); i++) { + outputproj_[layerdisk][iphi][i]->addProj(tracklet, projPage); // FIXME write to correct page + } + } + } + } + } + } + } + } + + return; + +} diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc deleted file mode 100644 index 0e59a8b0dafc2..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc +++ /dev/null @@ -1,152 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" -#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" -#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" -#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" - -using namespace std; -using namespace trklet; - -ProjectionRouter::ProjectionRouter(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), rinvbendlut_(settings) { - layerdisk_ = initLayerDisk(3); - - vmprojs_.resize(settings_.nvmme(layerdisk_), nullptr); - - nrbits_ = 5; - nphiderbits_ = 6; - - if (layerdisk_ >= N_LAYER) { - rinvbendlut_.initProjectionBend( - global->ITC_L1L2()->der_phiD_final.K(), layerdisk_ - N_LAYER, nrbits_, nphiderbits_); - } -} - -void ProjectionRouter::addOutput(MemoryBase* memory, string output) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " - << output; - } - if (output == "allprojout") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - allproj_ = tmp; - return; - } - - unsigned int nproj = settings_.nallstubs(layerdisk_); - unsigned int nprojvm = settings_.nvmme(layerdisk_); - - for (unsigned int iproj = 0; iproj < nproj; iproj++) { - for (unsigned int iprojvm = 0; iprojvm < nprojvm; iprojvm++) { - std::string name = "vmprojoutPHI"; - name += char(iproj + 'A'); - name += std::to_string(iproj * nprojvm + iprojvm + 1); - if (output == name) { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - vmprojs_[iprojvm] = tmp; - return; - } - } - } - - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find output: " << output; -} - -void ProjectionRouter::addInput(MemoryBase* memory, string input) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " - << input; - } - if (input.substr(0, 4) == "proj" && input.substr(input.size() - 2, 2) == "in") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - inputproj_.push_back(tmp); - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; -} - -void ProjectionRouter::execute() { - unsigned int allprojcount = 0; - - //These are just here to test that the order is correct. Does not affect the actual execution - - int lastTCID = -1; - - for (auto& iproj : inputproj_) { - for (unsigned int i = 0; i < iproj->nTracklets(); i++) { - if (allprojcount >= settings_.maxStep("PR")) - continue; - - Tracklet* tracklet = iproj->getTracklet(i); - - FPGAWord fpgaphi; - - if (layerdisk_ < N_LAYER) { - fpgaphi = tracklet->proj(layerdisk_).fpgaphiproj(); - } else { - Projection& proj = tracklet->proj(layerdisk_); - fpgaphi = proj.fpgaphiproj(); - - //The next lines looks up the predicted bend based on: - // 1 - r projections - // 2 - phi derivative - // 3 - the sign - i.e. if track is forward or backward - - int rindex = (proj.fpgarzproj().value() >> (proj.fpgarzproj().nbits() - nrbits_)) & ((1 << nrbits_) - 1); - - int phiderindex = (proj.fpgaphiprojder().value() >> (proj.fpgaphiprojder().nbits() - nphiderbits_)) & - ((1 << nphiderbits_) - 1); - - int signindex = (proj.fpgarzprojder().value() < 0); - - int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; - - int ibendproj = rinvbendlut_.lookup(bendindex); - - proj.setBendIndex(ibendproj); - } - - unsigned int iphivm = - fpgaphi.bits(fpgaphi.nbits() - settings_.nbitsallstubs(layerdisk_) - settings_.nbitsvmme(layerdisk_), - settings_.nbitsvmme(layerdisk_)); - - //This block of code just checks that the configuration is consistent - if (lastTCID >= tracklet->TCID()) { - edm::LogPrint("Tracklet") << "Wrong TCID ordering for projections in " << getName(); - } else { - lastTCID = tracklet->TCID(); - } - - allproj_->addTracklet(tracklet); - - vmprojs_[iphivm]->addTracklet(tracklet, allprojcount); - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " projection to " << vmprojs_[iphivm]->getName() << " iphivm " - << iphivm; - } - - allprojcount++; - } - } - - if (settings_.writeMonitorData("AP")) { - globals_->ofstream("allprojections.txt") << getName() << " " << allproj_->nTracklets() << endl; - } - - if (settings_.writeMonitorData("VMP")) { - ofstream& out = globals_->ofstream("chisq.txt"); - for (unsigned int i = 0; i < 8; i++) { - if (vmprojs_[i] != nullptr) { - out << vmprojs_[i]->getName() << " " << vmprojs_[i]->nTracklets() << endl; - } - } - } -} diff --git a/L1Trigger/TrackFindingTracklet/src/Sector.cc b/L1Trigger/TrackFindingTracklet/src/Sector.cc index b17e9adf692fb..7b9b236992fdb 100644 --- a/L1Trigger/TrackFindingTracklet/src/Sector.cc +++ b/L1Trigger/TrackFindingTracklet/src/Sector.cc @@ -9,30 +9,20 @@ #include "L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/InputRouter.h" #include "L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMRouter.h" -#include "L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h" -#include "L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h" -#include "L1Trigger/TrackFindingTracklet/interface/TripletEngine.h" -#include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletProcessorDisplaced.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h" -#include "L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h" -#include "L1Trigger/TrackFindingTracklet/interface/MatchEngine.h" -#include "L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h" +#include "L1Trigger/TrackFindingTracklet/interface/ProjectionCalculator.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubMERouter.h" #include "L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h" #include "L1Trigger/TrackFindingTracklet/interface/FitTrack.h" #include "L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h" @@ -117,20 +107,12 @@ void Sector::addMem(string memType, string memName) { addMemToVec(VMSTE_, memName, settings_); } else if (memType == "VMStubsME:") { addMemToVec(VMSME_, memName, settings_); - } else if (memType == "StubPairs:" || memType == "StubPairsDisplaced:") { - addMemToVec(SP_, memName, settings_); } else if (memType == "StubTriplets:") { addMemToVec(ST_, memName, settings_); } else if (memType == "TrackletParameters:") { addMemToVec(TPAR_, memName, settings_); } else if (memType == "TrackletProjections:") { addMemToVec(TPROJ_, memName, settings_); - } else if (memType == "AllProj:") { - addMemToVec(AP_, memName, settings_); - } else if (memType == "VMProjections:") { - addMemToVec(VMPROJ_, memName, settings_); - } else if (memType == "CandidateMatch:") { - addMemToVec(CM_, memName, settings_); } else if (memType == "FullMatch:") { addMemToVec(FM_, memName, settings_); } else if (memType == "TrackFit:") { @@ -146,31 +128,18 @@ void Sector::addMem(string memType, string memName) { void Sector::addProc(string procType, string procName) { if (procType == "InputRouter:") { addProcToVec(IR_, procName, settings_, globals_); - } else if (procType == "VMRouter:") { - addProcToVec(VMR_, procName, settings_, globals_); } else if (procType == "VMRouterCM:") { addProcToVec(VMRCM_, procName, settings_, globals_); - } else if (procType == "TrackletEngine:") { - addProcToVec(TE_, procName, settings_, globals_); - } else if (procType == "TrackletEngineDisplaced:") { - addProcToVec(TED_, procName, settings_, globals_); - } else if (procType == "TripletEngine:") { - addProcToVec(TRE_, procName, settings_, globals_); - } else if (procType == "TrackletCalculator:") { - addProcToVec(TC_, procName, settings_, globals_); } else if (procType == "TrackletProcessor:") { addProcToVec(TP_, procName, settings_, globals_); } else if (procType == "TrackletProcessorDisplaced:") { addProcToVec(TPD_, procName, settings_, globals_); } else if (procType == "TrackletCalculatorDisplaced:") { addProcToVec(TCD_, procName, settings_, globals_); - } else if (procType == "ProjectionRouter:") { - addProcToVec(PR_, procName, settings_, globals_); - } else if (procType == "MatchEngine:") { - addProcToVec(ME_, procName, settings_, globals_); - } else if (procType == "MatchCalculator:" || - procType == "DiskMatchCalculator:") { //TODO should not be used in configurations - addProcToVec(MC_, procName, settings_, globals_); + } else if (procType == "ProjectionCalculator:") { + addProcToVec(PC_, procName, settings_, globals_); + } else if (procType == "VMStubMERouter:") { + addProcToVec(VMSMER_, procName, settings_, globals_); } else if (procType == "MatchProcessor:") { addProcToVec(MP_, procName, settings_, globals_); } else if (procType == "FitTrack:") { @@ -263,12 +232,6 @@ void Sector::writeAIS(bool first) { } } -void Sector::writeSP(bool first) { - for (auto& i : SP_) { - i->writeSP(first, isector_); - } -} - void Sector::writeST(bool first) { for (auto& i : ST_) { i->writeST(first, isector_); @@ -287,24 +250,6 @@ void Sector::writeTPROJ(bool first) { } } -void Sector::writeAP(bool first) { - for (auto& i : AP_) { - i->writeAP(first, isector_); - } -} - -void Sector::writeVMPROJ(bool first) { - for (auto& i : VMPROJ_) { - i->writeVMPROJ(first, isector_); - } -} - -void Sector::writeCM(bool first) { - for (auto& i : CM_) { - i->writeCM(first, isector_); - } -} - void Sector::writeMC(bool first) { for (auto& i : FM_) { i->writeMC(first, isector_); @@ -342,32 +287,11 @@ void Sector::executeVMR() { out << i->getName() << " " << i->nStubs() << endl; } } - for (auto& i : VMR_) { - i->execute(); - } for (auto& i : VMRCM_) { i->execute(isector_); } } -void Sector::executeTE() { - for (auto& i : TE_) { - i->execute(); - } -} - -void Sector::executeTED() { - for (auto& i : TED_) { - i->execute(); - } -} - -void Sector::executeTRE() { - for (auto& i : TRE_) { - i->execute(); - } -} - void Sector::executeTP() { for (auto& i : TP_) { i->execute(isector_, phimin_, phimax_); @@ -380,43 +304,24 @@ void Sector::executeTPD() { } } -void Sector::executeTC() { - for (auto& i : TC_) { - i->execute(isector_, phimin_, phimax_); - } - - if (settings_.writeMonitorData("TrackProjOcc")) { - ofstream& out = globals_->ofstream("trackprojocc.txt"); - for (auto& i : TPROJ_) { - out << i->getName() << " " << i->nTracklets() << endl; - } - } -} - void Sector::executeTCD() { for (auto& i : TCD_) { i->execute(isector_, phimin_, phimax_); } } -void Sector::executePR() { - for (auto& i : PR_) { +void Sector::executePC() { + for (auto& i : PC_) { i->execute(); } } -void Sector::executeME() { - for (auto& i : ME_) { +void Sector::executeVMSMER() { + for (auto& i : VMSMER_) { i->execute(isector_); } } -void Sector::executeMC() { - for (auto& i : MC_) { - i->execute(isector_, phimin_); - } -} - void Sector::executeMP() { for (auto& i : MP_) { i->execute(isector_, phimin_); diff --git a/L1Trigger/TrackFindingTracklet/src/Stub.cc b/L1Trigger/TrackFindingTracklet/src/Stub.cc index 6b973e59f1c15..27a14a11bdf7d 100644 --- a/L1Trigger/TrackFindingTracklet/src/Stub.cc +++ b/L1Trigger/TrackFindingTracklet/src/Stub.cc @@ -25,25 +25,27 @@ Stub::Stub(L1TStub& stub, Settings const& settings, Globals& globals) : settings int nalphabits = 0; + r_offset_bits = 8; + + int nndbits = settings_.nndbitsstub(layerdisk_); int nrbits = settings_.nrbitsstub(layerdisk_); int nzbits = settings_.nzbitsstub(layerdisk_); int nphibits = settings_.nphibitsstub(layerdisk_); if (layerdisk_ >= N_LAYER && !stub.isPSmodule()) { nalphabits = settings.nbitsalpha(); - nrbits = 7; + nrbits = 6; } - assert(nbendbits + nalphabits + nrbits + nzbits + nphibits == 36); + assert(nndbits + nbendbits + nalphabits + nrbits + nzbits + nphibits == 36); - bitset<32> rbits(stubwordbin.substr(0, nrbits)); - bitset<32> zbits(stubwordbin.substr(nrbits, nzbits)); - bitset<32> phibits(stubwordbin.substr(nrbits + nzbits, nphibits)); - bitset<32> alphabits(stubwordbin.substr(nphibits + nzbits + nrbits, nalphabits)); - bitset<32> bendbits(stubwordbin.substr(nphibits + nzbits + nrbits + nalphabits, nbendbits)); + bitset<32> rbits(stubwordbin.substr(nndbits, nrbits)); + bitset<32> zbits(stubwordbin.substr(nrbits + nndbits, nzbits)); + bitset<32> phibits(stubwordbin.substr(nrbits + nzbits + nndbits, nphibits)); + bitset<32> alphabits(stubwordbin.substr(nphibits + nzbits + nrbits + nndbits, nalphabits)); + bitset<32> bendbits(stubwordbin.substr(nphibits + nzbits + nrbits + nalphabits + nndbits, nbendbits)); int newbend = bendbits.to_ulong(); - int newr = rbits.to_ulong(); if (layerdisk_ < N_LAYER) { if (newr >= (1 << (nrbits - 1))) @@ -160,7 +162,7 @@ double Stub::rapprox() const { else return settings_.rDSSouter(r_.value()); } - return r_.value() * settings_.kr(); + return (r_.value() + (1 << r_offset_bits)) * settings_.kr(); // Incorporating r offset for disk PS stubs } double Stub::zapprox() const { diff --git a/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc b/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc deleted file mode 100644 index ea29fe811d0fd..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc +++ /dev/null @@ -1,35 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMStubTE.h" -#include -#include - -using namespace std; -using namespace trklet; - -StubPairsMemory::StubPairsMemory(string name, Settings const& settings) : MemoryBase(name, settings) {} - -void StubPairsMemory::writeSP(bool first, unsigned int iSector) { - iSector_ = iSector; - const string dirSP = settings_.memPath() + "StubPairs/"; - - std::ostringstream oss; - oss << dirSP << "StubPairs_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; - auto const& fname = oss.str(); - - openfile(out_, first, dirSP, fname, __FILE__, __LINE__); - - out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; - - for (unsigned int j = 0; j < stubs_.size(); j++) { - string stub1index = stubs_[j].first.stub()->stubindex().str(); - string stub2index = stubs_[j].second.stub()->stubindex().str(); - out_ << hexstr(j) << " " << stub1index << "|" << stub2index << " " << trklet::hexFormat(stub1index + stub2index) - << endl; - } - out_.close(); - - bx_++; - event_++; - if (bx_ > 7) - bx_ = 0; -} diff --git a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc index 6ca7310501b3d..4f54e262ec5cc 100644 --- a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc +++ b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc @@ -33,7 +33,6 @@ Tracklet::Tracklet(Settings const& settings, int id0, int iz0, int it, - Projection projs[N_LAYER + N_DISK], bool disk, bool overlap) : settings_(settings) { @@ -81,6 +80,11 @@ Tracklet::Tracklet(Settings const& settings, projdisk_[i] = settings.projdisks(seedIndex_, i); } + ichisqrphifit_.set(-1, 8, false); + ichisqrzfit_.set(-1, 8, false); +} + +void Tracklet::addProjs(Projection projs[N_LAYER + N_DISK]){ // needs to be separate from constructor to allow TPars only calculated in TrackletProcessor //Handle projections to the layers for (unsigned int i = 0; i < N_LAYER - 2; i++) { if (projlayer_[i] == 0) @@ -99,9 +103,6 @@ Tracklet::Tracklet(Settings const& settings, proj_[N_LAYER + projdisk_[i] - 1] = projs[N_LAYER + projdisk_[i] - 1]; } - - ichisqrphifit_.set(-1, 8, false); - ichisqrzfit_.set(-1, 8, false); } int Tracklet::tpseed() { @@ -342,7 +343,7 @@ std::string Tracklet::fullmatchdiskstr(int disk) { const FPGAWord& stubr = resid_[N_LAYER + disk - 1].stubptr()->r(); const bool isPS = resid_[N_LAYER + disk - 1].stubptr()->isPSmodule(); std::string oss = tcid.str() + "|" + tmp.str() + "|" + resid_[N_LAYER + disk - 1].fpgastubid().str() + "|" + - (isPS ? stubr.str() : ("00000000" + stubr.str())) + "|" + + (isPS ? "0"+stubr.str() : ("00000000" + stubr.str())) + "|" + resid_[N_LAYER + disk - 1].fpgaphiresid().str() + "|" + resid_[N_LAYER + disk - 1].fpgarzresid().str(); return oss; @@ -617,7 +618,7 @@ const std::string Tracklet::diskstubstr(const unsigned disk) const { oss << "1|"; // valid bit oss << tmp.str() << "|"; oss << resid_[N_LAYER + disk].fpgastubid().str() << "|"; - oss << (isPS ? stubr.str() : ("00000000" + stubr.str())) << "|"; + oss << (isPS ? ("0"+stubr.str()) : ("00000000" + stubr.str())) << "|"; oss << resid_[N_LAYER + disk].fpgaphiresid().str() << "|"; oss << resid_[N_LAYER + disk].fpgarzresid().str(); } @@ -626,47 +627,57 @@ const std::string Tracklet::diskstubstr(const unsigned disk) const { } std::string Tracklet::trackfitstr() const { - const unsigned maxNHits = 8; + const unsigned maxNHits = N_LAYER + N_DISK; const unsigned nBitsPerHit = 3; - vector stub(maxNHits, "0"); + vector stub(maxNHits); + for (unsigned int i = 0; iphiregionstr() + "|"; - oss += innerFPGAStub()->phiregionstr() + "|"; - } else { - oss += innerFPGAStub()->phiregionstr() + "|"; - oss += outerFPGAStub()->phiregionstr() + "|"; - } + if (seedIndex() == Seed::L1D1 || seedIndex() == Seed::L2D1) { + oss += outerFPGAStub()->phiregionstr() + "|"; + oss += innerFPGAStub()->phiregionstr() + "|"; + } else { + oss += innerFPGAStub()->phiregionstr() + "|"; + oss += outerFPGAStub()->phiregionstr() + "|"; } oss += innerFPGAStub()->stubindex().str() + "|"; oss += outerFPGAStub()->stubindex().str() + "|"; @@ -745,10 +756,7 @@ std::string Tracklet::trackfitstr() const { oss += fpgapars_.t().str() + "|"; oss += hitmap; for (unsigned i = 0; i < maxNHits; i++) - // If a valid stub string was never assigned, then that stub is not - // included in the output. - if (stub[i] != "0") - oss += "|" + stub[i]; + oss += "|" + stub[i]; } return oss; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc deleted file mode 100644 index 74e93e2040eb2..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc +++ /dev/null @@ -1,472 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" -#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" -#include "L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" - -using namespace std; -using namespace trklet; - -TrackletCalculator::TrackletCalculator(string name, Settings const& settings, Globals* globals) - : TrackletCalculatorBase(name, settings, globals) { - for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { - vector tmp(settings.nallstubs(ilayer), nullptr); - trackletprojlayers_.push_back(tmp); - } - - for (unsigned int idisk = 0; idisk < N_DISK; idisk++) { - vector tmp(settings.nallstubs(idisk + N_LAYER), nullptr); - trackletprojdisks_.push_back(tmp); - } - - initLayerDisksandISeed(layerdisk1_, layerdisk2_, iSeed_); - - // set TC index - iTC_ = name_[7] - 'A'; - - TCIndex_ = (iSeed_ << 4) + iTC_; - assert(TCIndex_ >= 0 && TCIndex_ <= (int)settings_.ntrackletmax()); - - if (settings_.usephicritapprox()) { - double phicritFactor = - 0.5 * settings_.rcrit() * globals_->ITC_L1L2()->rinv_final.K() / globals_->ITC_L1L2()->phi0_final.K(); - if (std::abs(phicritFactor - 2.) > 0.25) - edm::LogPrint("Tracklet") - << "TrackletCalculator::TrackletCalculator phicrit approximation may be invalid! Please check."; - } - - // reduced config has only one TC, so this must be the first - const bool isFirstTC = (iTC_ == 0 || settings_.reduced()); - - // write the drinv and invt inverse tables - if ((settings_.writeInvTable() || settings_.writeHLSInvTable() || settings_.writeTable()) && isFirstTC) { - void (*writeLUT)(const VarInv&, const string&) = nullptr; - if (settings.writeInvTable()) { // Verilog version - writeLUT = [](const VarInv& x, const string& basename) -> void { - ofstream fs(basename + ".tab"); - return x.writeLUT(fs, VarBase::verilog); - }; - } else { // HLS version - writeLUT = [](const VarInv& x, const string& basename) -> void { - ofstream fs(basename + ".tab"); - return x.writeLUT(fs, VarBase::hls); - }; - } - writeInvTable(writeLUT); - } - - // write the firmware design for the calculation of the tracklet parameters - // and projections - if ((settings_.writeVerilog() || settings_.writeHLS()) && isFirstTC) { - void (*writeDesign)(const vector&, const string&) = nullptr; - if (settings.writeVerilog()) { // Verilog version - writeDesign = [](const vector& v, const string& basename) -> void { - ofstream fs(basename + ".v"); - return VarBase::verilog_print(v, fs); - }; - } else { // HLS version - writeDesign = [](const vector& v, const string& basename) -> void { - ofstream fs(basename + ".cpp"); - return VarBase::hls_print(v, fs); - }; - } - writeFirmwareDesign(writeDesign); - } -} - -void TrackletCalculator::addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory) { - outputProj = dynamic_cast(memory); - assert(outputProj != nullptr); -} - -void TrackletCalculator::addOutput(MemoryBase* memory, string output) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " - << output; - } - if (output == "trackpar") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - trackletpars_ = tmp; - return; - } - - if (output.substr(0, 7) == "projout") { - //output is on the form 'projoutL2PHIC' or 'projoutD3PHIB' - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - - unsigned int layerdisk = output[8] - '1'; //layer or disk counting from 0 - unsigned int phiregion = output[12] - 'A'; //phiregion counting from 0 - - if (output[7] == 'L') { - assert(layerdisk < N_LAYER); - assert(phiregion < trackletprojlayers_[layerdisk].size()); - //check that phiregion not already initialized - assert(trackletprojlayers_[layerdisk][phiregion] == nullptr); - trackletprojlayers_[layerdisk][phiregion] = tmp; - return; - } - - if (output[7] == 'D') { - assert(layerdisk < N_DISK); - assert(phiregion < trackletprojdisks_[layerdisk].size()); - //check that phiregion not already initialized - assert(trackletprojdisks_[layerdisk][phiregion] == nullptr); - trackletprojdisks_[layerdisk][phiregion] = tmp; - return; - } - } - - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; -} - -void TrackletCalculator::addInput(MemoryBase* memory, string input) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " - << input; - } - if (input == "innerallstubin") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - innerallstubs_.push_back(tmp); - return; - } - if (input == "outerallstubin") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - outerallstubs_.push_back(tmp); - return; - } - if (input.substr(0, 8) == "stubpair") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - stubpairs_.push_back(tmp); - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find intput : " << input; -} - -void TrackletCalculator::execute(unsigned int iSector, double phimin, double phimax) { - unsigned int countall = 0; - unsigned int countsel = 0; - - phimin_ = phimin; - phimax_ = phimax; - iSector_ = iSector; - - //Helpfull to have for debugging the HLS code - will keep here for now. - //bool print = (iSector == 3) && (getName() == "TC_L1L2G"); - //print = false; - - for (auto& stubpair : stubpairs_) { - if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { - edm::LogVerbatim("Tracklet") << "Will break on too many tracklets in " << getName(); - break; - } - for (unsigned int i = 0; i < stubpair->nStubPairs(); i++) { - countall++; - const Stub* innerFPGAStub = stubpair->getVMStub1(i).stub(); - const L1TStub* innerStub = innerFPGAStub->l1tstub(); - - const Stub* outerFPGAStub = stubpair->getVMStub2(i).stub(); - const L1TStub* outerStub = outerFPGAStub->l1tstub(); - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "TrackletCalculator execute " << getName() << "[" << iSector << "]"; - } - - if (innerFPGAStub->layerdisk() < N_LAYER && (getName() != "TC_D1L2A" && getName() != "TC_D1L2B")) { - if (outerFPGAStub->layerdisk() >= N_LAYER) { - //overlap seeding - bool accept = overlapSeeding(outerFPGAStub, outerStub, innerFPGAStub, innerStub); - if (accept) - countsel++; - } else { - //barrel+barrel seeding - bool accept = barrelSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); - if (accept) - countsel++; - } - } else { - if (outerFPGAStub->layerdisk() >= N_LAYER) { - //disk+disk seeding - bool accept = diskSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); - if (accept) - countsel++; - } else if (innerFPGAStub->layerdisk() >= N_LAYER) { - //layer+disk seeding - bool accept = overlapSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); - if (accept) - countsel++; - } else { - throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " invalid seeding"; - } - } - - if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { - edm::LogVerbatim("Tracklet") << "Will break on number of tracklets in " << getName(); - break; - } - - if (countall >= settings_.maxStep("TC")) { - if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << "Will break on MAXTC 1"; - break; - } - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "TrackletCalculator execute done"; - } - } - if (countall >= settings_.maxStep("TC")) { - if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << "Will break on MAXTC 2"; - break; - } - } - - if (settings_.writeMonitorData("TC")) { - globals_->ofstream("trackletcalculator.txt") << getName() << " " << countall << " " << countsel << endl; - } -} - -void TrackletCalculator::writeInvTable(void (*writeLUT)(const VarInv&, const string&)) { - switch (iSeed_) { - case 0: // L1L2 - writeLUT(globals_->ITC_L1L2()->drinv, settings_.tablePath() + "TC_L1L2_drinv"); - writeLUT(globals_->ITC_L1L2()->invt, settings_.tablePath() + "TC_L1L2_invt"); - break; - case 1: // L2L3 - writeLUT(globals_->ITC_L2L3()->drinv, settings_.tablePath() + "TC_L2L3_drinv"); - writeLUT(globals_->ITC_L2L3()->invt, settings_.tablePath() + "TC_L2L3_invt"); - break; - case 2: // L3L4 - writeLUT(globals_->ITC_L3L4()->drinv, settings_.tablePath() + "TC_L3L4_drinv"); - writeLUT(globals_->ITC_L3L4()->invt, settings_.tablePath() + "TC_L3L4_invt"); - break; - case 3: // L5L6 - writeLUT(globals_->ITC_L5L6()->drinv, settings_.tablePath() + "TC_L5L6_drinv"); - writeLUT(globals_->ITC_L5L6()->invt, settings_.tablePath() + "TC_L5L6_invt"); - break; - case 4: // D1D2 - writeLUT(globals_->ITC_F1F2()->drinv, settings_.tablePath() + "TC_F1F2_drinv"); - writeLUT(globals_->ITC_F1F2()->invt, settings_.tablePath() + "TC_F1F2_invt"); - writeLUT(globals_->ITC_B1B2()->drinv, settings_.tablePath() + "TC_B1B2_drinv"); - writeLUT(globals_->ITC_B1B2()->invt, settings_.tablePath() + "TC_B1B2_invt"); - break; - case 5: // D3D4 - writeLUT(globals_->ITC_F3F4()->drinv, settings_.tablePath() + "TC_F3F4_drinv"); - writeLUT(globals_->ITC_F3F4()->invt, settings_.tablePath() + "TC_F3F4_invt"); - writeLUT(globals_->ITC_B3B4()->drinv, settings_.tablePath() + "TC_B3B4_drinv"); - writeLUT(globals_->ITC_B3B4()->invt, settings_.tablePath() + "TC_B3B4_invt"); - break; - case 6: // L1D1 - writeLUT(globals_->ITC_L1F1()->drinv, settings_.tablePath() + "TC_L1F1_drinv"); - writeLUT(globals_->ITC_L1F1()->invt, settings_.tablePath() + "TC_L1F1_invt"); - writeLUT(globals_->ITC_L1B1()->drinv, settings_.tablePath() + "TC_L1B1_drinv"); - writeLUT(globals_->ITC_L1B1()->invt, settings_.tablePath() + "TC_L1B1_invt"); - break; - case 7: // L2D1 - writeLUT(globals_->ITC_L2F1()->drinv, settings_.tablePath() + "TC_L2F1_drinv"); - writeLUT(globals_->ITC_L2F1()->invt, settings_.tablePath() + "TC_L2F1_invt"); - writeLUT(globals_->ITC_L2B1()->drinv, settings_.tablePath() + "TC_L2B1_drinv"); - writeLUT(globals_->ITC_L2B1()->invt, settings_.tablePath() + "TC_L2B1_invt"); - break; - } -} - -void TrackletCalculator::writeFirmwareDesign(void (*writeDesign)(const vector&, const string&)) { - switch (iSeed_) { - case 0: // L1L2 - { - const vector v = {&globals_->ITC_L1L2()->rinv_final, &globals_->ITC_L1L2()->phi0_final, - &globals_->ITC_L1L2()->t_final, &globals_->ITC_L1L2()->z0_final, - &globals_->ITC_L1L2()->phiL_0_final, &globals_->ITC_L1L2()->phiL_1_final, - &globals_->ITC_L1L2()->phiL_2_final, &globals_->ITC_L1L2()->phiL_3_final, - &globals_->ITC_L1L2()->zL_0_final, &globals_->ITC_L1L2()->zL_1_final, - &globals_->ITC_L1L2()->zL_2_final, &globals_->ITC_L1L2()->zL_3_final, - &globals_->ITC_L1L2()->der_phiL_final, &globals_->ITC_L1L2()->der_zL_final, - &globals_->ITC_L1L2()->phiD_0_final, &globals_->ITC_L1L2()->phiD_1_final, - &globals_->ITC_L1L2()->phiD_2_final, &globals_->ITC_L1L2()->phiD_3_final, - &globals_->ITC_L1L2()->phiD_4_final, &globals_->ITC_L1L2()->rD_0_final, - &globals_->ITC_L1L2()->rD_1_final, &globals_->ITC_L1L2()->rD_2_final, - &globals_->ITC_L1L2()->rD_3_final, &globals_->ITC_L1L2()->rD_4_final, - &globals_->ITC_L1L2()->der_phiD_final, &globals_->ITC_L1L2()->der_rD_final}; - writeDesign(v, "TC_L1L2"); - } break; - case 1: // L2L3 - { - const vector v = {&globals_->ITC_L2L3()->rinv_final, &globals_->ITC_L2L3()->phi0_final, - &globals_->ITC_L2L3()->t_final, &globals_->ITC_L2L3()->z0_final, - &globals_->ITC_L2L3()->phiL_0_final, &globals_->ITC_L2L3()->phiL_1_final, - &globals_->ITC_L2L3()->phiL_2_final, &globals_->ITC_L2L3()->phiL_3_final, - &globals_->ITC_L2L3()->zL_0_final, &globals_->ITC_L2L3()->zL_1_final, - &globals_->ITC_L2L3()->zL_2_final, &globals_->ITC_L2L3()->zL_3_final, - &globals_->ITC_L2L3()->der_phiL_final, &globals_->ITC_L2L3()->der_zL_final, - &globals_->ITC_L2L3()->phiD_0_final, &globals_->ITC_L2L3()->phiD_1_final, - &globals_->ITC_L2L3()->phiD_2_final, &globals_->ITC_L2L3()->phiD_3_final, - &globals_->ITC_L2L3()->phiD_4_final, &globals_->ITC_L2L3()->rD_0_final, - &globals_->ITC_L2L3()->rD_1_final, &globals_->ITC_L2L3()->rD_2_final, - &globals_->ITC_L2L3()->rD_3_final, &globals_->ITC_L2L3()->rD_4_final, - &globals_->ITC_L2L3()->der_phiD_final, &globals_->ITC_L2L3()->der_rD_final}; - writeDesign(v, "TC_L2L3"); - } break; - case 2: // L3L4 - { - const vector v = {&globals_->ITC_L3L4()->rinv_final, &globals_->ITC_L3L4()->phi0_final, - &globals_->ITC_L3L4()->t_final, &globals_->ITC_L3L4()->z0_final, - &globals_->ITC_L3L4()->phiL_0_final, &globals_->ITC_L3L4()->phiL_1_final, - &globals_->ITC_L3L4()->phiL_2_final, &globals_->ITC_L3L4()->phiL_3_final, - &globals_->ITC_L3L4()->zL_0_final, &globals_->ITC_L3L4()->zL_1_final, - &globals_->ITC_L3L4()->zL_2_final, &globals_->ITC_L3L4()->zL_3_final, - &globals_->ITC_L3L4()->der_phiL_final, &globals_->ITC_L3L4()->der_zL_final, - &globals_->ITC_L3L4()->phiD_0_final, &globals_->ITC_L3L4()->phiD_1_final, - &globals_->ITC_L3L4()->phiD_2_final, &globals_->ITC_L3L4()->phiD_3_final, - &globals_->ITC_L3L4()->phiD_4_final, &globals_->ITC_L3L4()->rD_0_final, - &globals_->ITC_L3L4()->rD_1_final, &globals_->ITC_L3L4()->rD_2_final, - &globals_->ITC_L3L4()->rD_3_final, &globals_->ITC_L3L4()->rD_4_final, - &globals_->ITC_L3L4()->der_phiD_final, &globals_->ITC_L3L4()->der_rD_final}; - writeDesign(v, "TC_L3L4"); - } break; - case 3: // L5L6 - { - const vector v = {&globals_->ITC_L5L6()->rinv_final, &globals_->ITC_L5L6()->phi0_final, - &globals_->ITC_L5L6()->t_final, &globals_->ITC_L5L6()->z0_final, - &globals_->ITC_L5L6()->phiL_0_final, &globals_->ITC_L5L6()->phiL_1_final, - &globals_->ITC_L5L6()->phiL_2_final, &globals_->ITC_L5L6()->phiL_3_final, - &globals_->ITC_L5L6()->zL_0_final, &globals_->ITC_L5L6()->zL_1_final, - &globals_->ITC_L5L6()->zL_2_final, &globals_->ITC_L5L6()->zL_3_final, - &globals_->ITC_L5L6()->der_phiL_final, &globals_->ITC_L5L6()->der_zL_final, - &globals_->ITC_L5L6()->phiD_0_final, &globals_->ITC_L5L6()->phiD_1_final, - &globals_->ITC_L5L6()->phiD_2_final, &globals_->ITC_L5L6()->phiD_3_final, - &globals_->ITC_L5L6()->phiD_4_final, &globals_->ITC_L5L6()->rD_0_final, - &globals_->ITC_L5L6()->rD_1_final, &globals_->ITC_L5L6()->rD_2_final, - &globals_->ITC_L5L6()->rD_3_final, &globals_->ITC_L5L6()->rD_4_final, - &globals_->ITC_L5L6()->der_phiD_final, &globals_->ITC_L5L6()->der_rD_final}; - writeDesign(v, "TC_L5L6"); - } break; - case 4: // D1D2 - { - const vector v = {&globals_->ITC_F1F2()->rinv_final, &globals_->ITC_F1F2()->phi0_final, - &globals_->ITC_F1F2()->t_final, &globals_->ITC_F1F2()->z0_final, - &globals_->ITC_F1F2()->phiL_0_final, &globals_->ITC_F1F2()->phiL_1_final, - &globals_->ITC_F1F2()->phiL_2_final, &globals_->ITC_F1F2()->zL_0_final, - &globals_->ITC_F1F2()->zL_1_final, &globals_->ITC_F1F2()->zL_2_final, - &globals_->ITC_F1F2()->der_phiL_final, &globals_->ITC_F1F2()->der_zL_final, - &globals_->ITC_F1F2()->phiD_0_final, &globals_->ITC_F1F2()->phiD_1_final, - &globals_->ITC_F1F2()->phiD_2_final, &globals_->ITC_F1F2()->rD_0_final, - &globals_->ITC_F1F2()->rD_1_final, &globals_->ITC_F1F2()->rD_2_final, - &globals_->ITC_F1F2()->der_phiD_final, &globals_->ITC_F1F2()->der_rD_final}; - writeDesign(v, "TC_F1F2"); - } - { - const vector v = {&globals_->ITC_B1B2()->rinv_final, &globals_->ITC_B1B2()->phi0_final, - &globals_->ITC_B1B2()->t_final, &globals_->ITC_B1B2()->z0_final, - &globals_->ITC_B1B2()->phiL_0_final, &globals_->ITC_B1B2()->phiL_1_final, - &globals_->ITC_B1B2()->phiL_2_final, &globals_->ITC_B1B2()->zL_0_final, - &globals_->ITC_B1B2()->zL_1_final, &globals_->ITC_B1B2()->zL_2_final, - &globals_->ITC_B1B2()->der_phiL_final, &globals_->ITC_B1B2()->der_zL_final, - &globals_->ITC_B1B2()->phiD_0_final, &globals_->ITC_B1B2()->phiD_1_final, - &globals_->ITC_B1B2()->phiD_2_final, &globals_->ITC_B1B2()->rD_0_final, - &globals_->ITC_B1B2()->rD_1_final, &globals_->ITC_B1B2()->rD_2_final, - &globals_->ITC_B1B2()->der_phiD_final, &globals_->ITC_B1B2()->der_rD_final}; - writeDesign(v, "TC_B1B2"); - } - break; - case 5: // D3D4 - { - const vector v = {&globals_->ITC_F3F4()->rinv_final, &globals_->ITC_F3F4()->phi0_final, - &globals_->ITC_F3F4()->t_final, &globals_->ITC_F3F4()->z0_final, - &globals_->ITC_F3F4()->phiL_0_final, &globals_->ITC_F3F4()->phiL_1_final, - &globals_->ITC_F3F4()->phiL_2_final, &globals_->ITC_F3F4()->zL_0_final, - &globals_->ITC_F3F4()->zL_1_final, &globals_->ITC_F3F4()->zL_2_final, - &globals_->ITC_F3F4()->der_phiL_final, &globals_->ITC_F3F4()->der_zL_final, - &globals_->ITC_F3F4()->phiD_0_final, &globals_->ITC_F3F4()->phiD_1_final, - &globals_->ITC_F3F4()->phiD_2_final, &globals_->ITC_F3F4()->rD_0_final, - &globals_->ITC_F3F4()->rD_1_final, &globals_->ITC_F3F4()->rD_2_final, - &globals_->ITC_F3F4()->der_phiD_final, &globals_->ITC_F3F4()->der_rD_final}; - writeDesign(v, "TC_F3F4"); - } - { - const vector v = {&globals_->ITC_B3B4()->rinv_final, &globals_->ITC_B3B4()->phi0_final, - &globals_->ITC_B3B4()->t_final, &globals_->ITC_B3B4()->z0_final, - &globals_->ITC_B3B4()->phiL_0_final, &globals_->ITC_B3B4()->phiL_1_final, - &globals_->ITC_B3B4()->phiL_2_final, &globals_->ITC_B3B4()->zL_0_final, - &globals_->ITC_B3B4()->zL_1_final, &globals_->ITC_B3B4()->zL_2_final, - &globals_->ITC_B3B4()->der_phiL_final, &globals_->ITC_B3B4()->der_zL_final, - &globals_->ITC_B3B4()->phiD_0_final, &globals_->ITC_B3B4()->phiD_1_final, - &globals_->ITC_B3B4()->phiD_2_final, &globals_->ITC_B3B4()->rD_0_final, - &globals_->ITC_B3B4()->rD_1_final, &globals_->ITC_B3B4()->rD_2_final, - &globals_->ITC_B3B4()->der_phiD_final, &globals_->ITC_B3B4()->der_rD_final}; - writeDesign(v, "TC_B3B4"); - } - break; - case 6: // L1D1 - { - const vector v = {&globals_->ITC_L1F1()->rinv_final, &globals_->ITC_L1F1()->phi0_final, - &globals_->ITC_L1F1()->t_final, &globals_->ITC_L1F1()->z0_final, - &globals_->ITC_L1F1()->phiL_0_final, &globals_->ITC_L1F1()->phiL_1_final, - &globals_->ITC_L1F1()->phiL_2_final, &globals_->ITC_L1F1()->zL_0_final, - &globals_->ITC_L1F1()->zL_1_final, &globals_->ITC_L1F1()->zL_2_final, - &globals_->ITC_L1F1()->der_phiL_final, &globals_->ITC_L1F1()->der_zL_final, - &globals_->ITC_L1F1()->phiD_0_final, &globals_->ITC_L1F1()->phiD_1_final, - &globals_->ITC_L1F1()->phiD_2_final, &globals_->ITC_L1F1()->phiD_3_final, - &globals_->ITC_L1F1()->rD_0_final, &globals_->ITC_L1F1()->rD_1_final, - &globals_->ITC_L1F1()->rD_2_final, &globals_->ITC_L1F1()->rD_3_final, - &globals_->ITC_L1F1()->der_phiD_final, &globals_->ITC_L1F1()->der_rD_final}; - writeDesign(v, "TC_L1F1"); - } - { - const vector v = {&globals_->ITC_L1B1()->rinv_final, &globals_->ITC_L1B1()->phi0_final, - &globals_->ITC_L1B1()->t_final, &globals_->ITC_L1B1()->z0_final, - &globals_->ITC_L1B1()->phiL_0_final, &globals_->ITC_L1B1()->phiL_1_final, - &globals_->ITC_L1B1()->phiL_2_final, &globals_->ITC_L1B1()->zL_0_final, - &globals_->ITC_L1B1()->zL_1_final, &globals_->ITC_L1B1()->zL_2_final, - &globals_->ITC_L1B1()->der_phiL_final, &globals_->ITC_L1B1()->der_zL_final, - &globals_->ITC_L1B1()->phiD_0_final, &globals_->ITC_L1B1()->phiD_1_final, - &globals_->ITC_L1B1()->phiD_2_final, &globals_->ITC_L1B1()->phiD_3_final, - &globals_->ITC_L1B1()->rD_0_final, &globals_->ITC_L1B1()->rD_1_final, - &globals_->ITC_L1B1()->rD_2_final, &globals_->ITC_L1B1()->rD_3_final, - &globals_->ITC_L1B1()->der_phiD_final, &globals_->ITC_L1B1()->der_rD_final}; - writeDesign(v, "TC_L1B1"); - } - break; - case 7: // L2D1 - { - const vector v = {&globals_->ITC_L2F1()->rinv_final, &globals_->ITC_L2F1()->phi0_final, - &globals_->ITC_L2F1()->t_final, &globals_->ITC_L2F1()->z0_final, - &globals_->ITC_L2F1()->phiL_0_final, &globals_->ITC_L2F1()->phiL_1_final, - &globals_->ITC_L2F1()->phiL_2_final, &globals_->ITC_L2F1()->zL_0_final, - &globals_->ITC_L2F1()->zL_1_final, &globals_->ITC_L2F1()->zL_2_final, - &globals_->ITC_L2F1()->der_phiL_final, &globals_->ITC_L2F1()->der_zL_final, - &globals_->ITC_L2F1()->phiD_0_final, &globals_->ITC_L2F1()->phiD_1_final, - &globals_->ITC_L2F1()->phiD_2_final, &globals_->ITC_L2F1()->phiD_3_final, - &globals_->ITC_L2F1()->rD_0_final, &globals_->ITC_L2F1()->rD_1_final, - &globals_->ITC_L2F1()->rD_2_final, &globals_->ITC_L2F1()->rD_3_final, - &globals_->ITC_L2F1()->der_phiD_final, &globals_->ITC_L2F1()->der_rD_final}; - writeDesign(v, "TC_L2F1"); - } - { - const vector v = {&globals_->ITC_L2B1()->rinv_final, &globals_->ITC_L2B1()->phi0_final, - &globals_->ITC_L2B1()->t_final, &globals_->ITC_L2B1()->z0_final, - &globals_->ITC_L2B1()->phiL_0_final, &globals_->ITC_L2B1()->phiL_1_final, - &globals_->ITC_L2B1()->phiL_2_final, &globals_->ITC_L2B1()->zL_0_final, - &globals_->ITC_L2B1()->zL_1_final, &globals_->ITC_L2B1()->zL_2_final, - &globals_->ITC_L2B1()->der_phiL_final, &globals_->ITC_L2B1()->der_zL_final, - &globals_->ITC_L2B1()->phiD_0_final, &globals_->ITC_L2B1()->phiD_1_final, - &globals_->ITC_L2B1()->phiD_2_final, &globals_->ITC_L2B1()->phiD_3_final, - &globals_->ITC_L2B1()->rD_0_final, &globals_->ITC_L2B1()->rD_1_final, - &globals_->ITC_L2B1()->rD_2_final, &globals_->ITC_L2B1()->rD_3_final, - &globals_->ITC_L2B1()->der_phiD_final, &globals_->ITC_L2B1()->der_rD_final}; - writeDesign(v, "TC_L2B1"); - } - break; - } -} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc index bf05456826184..78a6f9f401732 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc @@ -3,9 +3,6 @@ #include "L1Trigger/TrackFindingTracklet/interface/Stub.h" #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" #include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorDisk.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculatorOverlap.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -18,6 +15,85 @@ using namespace trklet; TrackletCalculatorBase::TrackletCalculatorBase(string name, Settings const& settings, Globals* global) : ProcessBase(name, settings, global) {} +void TrackletCalculatorBase::init(int iSeed){ + + phiHG_ = settings_.dphisectorHG(); + + //Constants for coordinates and track parameter definitions + n_phi_ = 17; + n_r_ = 12; + n_z_ = 11; + n_phi0_ = 16; + n_rinv_ = 13; + n_t_ = 9; + n_phidisk_ = n_phi_-3; + n_rdisk_ = n_r_-1; + + //Constants used for tracklet parameter calculations + n_delta0_ = 13; + n_deltaz_ = 11; + n_delta1_ = 13; + n_delta2_ = 13; + n_delta12_ = 13; + n_a_ = 15; + n_r6_ = 4; + n_delta02_ = 14; + n_x6_ = 15; + n_HG_ = 15; + + //Constants used for projectison to layers + n_s_ = 12; + n_s6_ = 14; + + //Constants used for projectison to disks + n_tinv_ = 12; + n_y_ = 14; + n_x_ = 14; + n_xx6_ = 14; + + LUT_itinv_.resize(8192); + + for (int it = 0; it < 8192; it++) { + if (it<100) { + LUT_itinv_[it] = 0; + } else { + LUT_itinv_[it] = (1 << (n_t_ + n_tinv_)) / abs(it); + } + } + + if (iSeed<4) { //FIXME - should not have hardcoded number here + n_Deltar_ = 24; + LUT_idrinv_.resize(512); + for(int idr=-256; idr<256; idr++){ + int uidr = idr; + if (uidr < 0) uidr += 512; + int idrabs = idr + settings_.irmean(layerdisk2_) - settings_.irmean(layerdisk1_); + LUT_idrinv_[uidr] = (1<=4 && iSeed<6){ //FIXME - should not have hardcoded number here + n_Deltar_ = 23; + LUT_idrinv_.resize(512); + for(unsigned int idr=1; idr<512; idr++){ + LUT_idrinv_[idr] = (1<=6) { //FIXME - should not have hardcoded number here + n_Deltar_ = 23; + n_delta0_ = 14; + n_deltaz_ = 9; + n_a_ = 14; + n_r6_ = 6; + LUT_idrinv_.resize(1024); + for(unsigned int idr=1; idr<1024; idr++){ + LUT_idrinv_[idr] = (1<> n_s_; + + int is6 = (1 << n_s6_) + ((is*is) >> (2 + 2*n_r_ + 2*n_rinv_ - 2*n_s_ - n_s6_)); + + int iu = (ir*irinv) >> (n_r_ + n_rinv_ + 1 - n_phi_); + + iphi = (iphi0 << (n_phi_ - n_phi0_)) - ((iu*is6) >> n_s6_); + + int iv = (it*ir) >> (n_r_ + n_t_ - n_z_); + + iz = iz0 + ((iv*is6) >> n_s6_); + +} + +void TrackletCalculatorBase::projdisk(int iz, int irinv, int iphi0, int it,int iz0, int &ir, int &iphi, int &iderphi, int &iderr) { + int iz0_sign = (it>0)?iz0:-iz0; + + assert(abs(it)> 17; + iderr = itinv >> 5; + if (it<0) { + iderphi = -iderphi; + iderr = -iderr; + } + + int iw = (((iz << (n_r_ - n_z_)) - (iz0_sign << (n_r_ - n_z_)))*itinv) >> n_tinv_; + + iphi = (iphi0 >> (n_phi0_ - n_phidisk_)) - ((iw*irinv) >> (1 + n_r_ + n_rinv_ - n_phidisk_)); + + int ifact = (1 << n_y_)*phiHG_/sqrt(6.0); + + int iy = (ifact * irinv) >> n_y_; + + int ix = (iw*iy) >> n_x_; + + int ix6 = (1 << n_xx6_) - ( (ix*ix) >> (2 + 2*n_r_ + 2*n_rinv_ - 2*n_x_ - n_xx6_)); + + ir = (iw*ix6) >> (n_r_ - n_rdisk_ + n_xx6_); + +} + +void TrackletCalculatorBase::calcPars(unsigned int idr, int iphi1, int ir1, int iz1, int iphi2, int ir2, int iz2, int &irinv_new, int &iphi0_new, int &iz0_new, int &it_new) { + + int idz = iz2 - iz1; + + assert(idr> n_delta0_; + int ideltaz = (idz*invdr) >> n_deltaz_; + + int idelta1 = (ir1*idelta0) >> n_delta1_; + int idelta2 = (ir2*idelta0) >> n_delta2_; + + int idelta12 = (idelta1*idelta2) >> n_delta12_; + + int iHG = phiHG_*phiHG_*(1 << n_HG_); + + int ia = ((1 << n_a_) - ((idelta12*iHG) >> (2*n_Deltar_ + 2*n_phi_ + n_HG_ - 2*n_delta0_ - n_delta1_ - n_delta2_ - n_delta12_ + 1 - n_a_))); + + int ifact = (1<> n_delta02_; + + int ix6 = (-(1 << n_x6_)+((ir6*idelta02) >> (n_r6_ + 2*n_Deltar_ + 2*n_phi_ - n_x6_ - n_delta2_- n_delta02_ - 2*n_delta0_))); + + int it1 = (ir1*ideltaz) >> (n_Deltar_ - n_deltaz_); + + irinv_new = ((-idelta0*ia) >> (n_phi_ + n_a_ - n_rinv_ + n_Deltar_ - n_delta0_ - n_r_ - 1)); + + iphi0_new = (iphi1 >> (n_phi_ - n_phi0_))+((idelta1*ix6) >> (n_Deltar_ + n_x6_ + n_phi_ - n_delta0_ - n_delta1_ - n_phi0_)); + + it_new = ((ideltaz*ia) >> (n_Deltar_ + n_a_ + n_z_ - n_t_ - n_deltaz_ - n_r_)); + + iz0_new = iz1+((it1*ix6) >> n_x6_); + +} + void TrackletCalculatorBase::addDiskProj(Tracklet* tracklet, int disk) { disk = std::abs(disk); @@ -309,8 +435,8 @@ bool TrackletCalculatorBase::inSector(int iphi0, int irinv, double phi0approx, d int ifactor = 0.5 * settings_.rcrit() * settings_.krinvpars() / settings_.kphi0pars() * (1 << 8); int iphicrit = iphi0 - (irinv >> 8) * ifactor; - int iphicritmincut = settings_.phicritminmc() / globals_->ITC_L1L2()->phi0_final.K(); - int iphicritmaxcut = settings_.phicritmaxmc() / globals_->ITC_L1L2()->phi0_final.K(); + int iphicritmincut = settings_.phicritminmc() / settings_.kphi0pars(); + int iphicritmaxcut = settings_.phicritmaxmc() / settings_.kphi0pars(); bool keepapprox = (phicritapprox > settings_.phicritminmc()) && (phicritapprox < settings_.phicritmaxmc()), keep = (iphicrit > iphicritmincut) && (iphicrit < iphicritmaxcut); @@ -385,114 +511,14 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, r2 = outerFPGAStub->rapprox(); } - double rinvapprox, phi0approx, tapprox, z0approx; - double phiprojapprox[N_LAYER - 2], zprojapprox[N_LAYER - 2]; - double phiprojdiskapprox[N_DISK], rprojdiskapprox[N_DISK]; - - IMATH_TrackletCalculator* ITC; - if (iSeed_ == 0) - ITC = globals_->ITC_L1L2(); - else if (iSeed_ == 1) - ITC = globals_->ITC_L2L3(); - else if (iSeed_ == 2) - ITC = globals_->ITC_L3L4(); - else - ITC = globals_->ITC_L5L6(); - - ITC->r1.set_fval(r1 - settings_.rmean(layerdisk1_)); - ITC->r2.set_fval(r2 - settings_.rmean(layerdisk2_)); - ITC->z1.set_fval(z1); - ITC->z2.set_fval(z2); - double sphi1 = angle0to2pi::make0To2pi(phi1 - phimin_); - double sphi2 = angle0to2pi::make0To2pi(phi2 - phimin_); - - ITC->phi1.set_fval(sphi1); - ITC->phi2.set_fval(sphi2); - - ITC->rproj0.set_fval(settings_.rmean(settings_.projlayers(iSeed_, 0) - 1)); - ITC->rproj1.set_fval(settings_.rmean(settings_.projlayers(iSeed_, 1) - 1)); - ITC->rproj2.set_fval(settings_.rmean(settings_.projlayers(iSeed_, 2) - 1)); - ITC->rproj3.set_fval(settings_.rmean(settings_.projlayers(iSeed_, 3) - 1)); - - ITC->zproj0.set_fval(t > 0 ? settings_.zmean(0) : -settings_.zmean(0)); - ITC->zproj1.set_fval(t > 0 ? settings_.zmean(1) : -settings_.zmean(1)); - ITC->zproj2.set_fval(t > 0 ? settings_.zmean(2) : -settings_.zmean(2)); - ITC->zproj3.set_fval(t > 0 ? settings_.zmean(3) : -settings_.zmean(3)); - ITC->zproj4.set_fval(t > 0 ? settings_.zmean(4) : -settings_.zmean(4)); - - ITC->rinv_final.calculate(); - ITC->phi0_final.calculate(); - ITC->t_final.calculate(); - ITC->z0_final.calculate(); - - ITC->phiL_0_final.calculate(); - ITC->phiL_1_final.calculate(); - ITC->phiL_2_final.calculate(); - ITC->phiL_3_final.calculate(); - - ITC->zL_0_final.calculate(); - ITC->zL_1_final.calculate(); - ITC->zL_2_final.calculate(); - ITC->zL_3_final.calculate(); - - ITC->phiD_0_final.calculate(); - ITC->phiD_1_final.calculate(); - ITC->phiD_2_final.calculate(); - ITC->phiD_3_final.calculate(); - ITC->phiD_4_final.calculate(); - - ITC->rD_0_final.calculate(); - ITC->rD_1_final.calculate(); - ITC->rD_2_final.calculate(); - ITC->rD_3_final.calculate(); - ITC->rD_4_final.calculate(); - - ITC->der_phiL_final.calculate(); - ITC->der_zL_final.calculate(); - ITC->der_phiD_final.calculate(); - ITC->der_rD_final.calculate(); - - //store the approximate results - rinvapprox = ITC->rinv_final.fval(); - phi0approx = ITC->phi0_final.fval(); - tapprox = ITC->t_final.fval(); - z0approx = ITC->z0_final.fval(); - - phiprojapprox[0] = ITC->phiL_0_final.fval(); - phiprojapprox[1] = ITC->phiL_1_final.fval(); - phiprojapprox[2] = ITC->phiL_2_final.fval(); - phiprojapprox[3] = ITC->phiL_3_final.fval(); - - zprojapprox[0] = ITC->zL_0_final.fval(); - zprojapprox[1] = ITC->zL_1_final.fval(); - zprojapprox[2] = ITC->zL_2_final.fval(); - zprojapprox[3] = ITC->zL_3_final.fval(); - - phiprojdiskapprox[0] = ITC->phiD_0_final.fval(); - phiprojdiskapprox[1] = ITC->phiD_1_final.fval(); - phiprojdiskapprox[2] = ITC->phiD_2_final.fval(); - phiprojdiskapprox[3] = ITC->phiD_3_final.fval(); - phiprojdiskapprox[4] = ITC->phiD_4_final.fval(); - - rprojdiskapprox[0] = ITC->rD_0_final.fval(); - rprojdiskapprox[1] = ITC->rD_1_final.fval(); - rprojdiskapprox[2] = ITC->rD_2_final.fval(); - rprojdiskapprox[3] = ITC->rD_3_final.fval(); - rprojdiskapprox[4] = ITC->rD_4_final.fval(); - //now binary - int irinv, iphi0, it, iz0; - Projection projs[N_LAYER + N_DISK]; - - int iphiproj[N_LAYER - 2], izproj[N_LAYER - 2]; - int iphiprojdisk[N_DISK], irprojdisk[N_DISK]; int ir1 = innerFPGAStub->r().value(); int iphi1 = innerFPGAStub->phi().value(); int iz1 = innerFPGAStub->z().value(); - int ir2 = outerFPGAStub->r().value(); + int ir2 = outerFPGAStub->rvalue(); int iphi2 = outerFPGAStub->phi().value(); int iz2 = outerFPGAStub->z().value(); @@ -504,158 +530,46 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, iz1 <<= (settings_.nzbitsstub(0) - settings_.nzbitsstub(layerdisk1_)); iz2 <<= (settings_.nzbitsstub(0) - settings_.nzbitsstub(layerdisk2_)); - ITC->r1.set_ival(ir1); - ITC->r2.set_ival(ir2); - ITC->z1.set_ival(iz1); - ITC->z2.set_ival(iz2); - ITC->phi1.set_ival(iphi1); - ITC->phi2.set_ival(iphi2); - - ITC->rinv_final.calculate(); - ITC->phi0_final.calculate(); - ITC->t_final.calculate(); - ITC->z0_final.calculate(); - - ITC->phiL_0_final.calculate(); - ITC->phiL_1_final.calculate(); - ITC->phiL_2_final.calculate(); - ITC->phiL_3_final.calculate(); - - ITC->zL_0_final.calculate(); - ITC->zL_1_final.calculate(); - ITC->zL_2_final.calculate(); - ITC->zL_3_final.calculate(); - - ITC->phiD_0_final.calculate(); - ITC->phiD_1_final.calculate(); - ITC->phiD_2_final.calculate(); - ITC->phiD_3_final.calculate(); - ITC->phiD_4_final.calculate(); - - ITC->rD_0_final.calculate(); - ITC->rD_1_final.calculate(); - ITC->rD_2_final.calculate(); - ITC->rD_3_final.calculate(); - ITC->rD_4_final.calculate(); - - ITC->der_phiL_final.calculate(); - ITC->der_zL_final.calculate(); - ITC->der_phiD_final.calculate(); - ITC->der_rD_final.calculate(); - - //store the binary results - irinv = ITC->rinv_final.ival(); - iphi0 = ITC->phi0_final.ival(); - it = ITC->t_final.ival(); - iz0 = ITC->z0_final.ival(); - - iphiproj[0] = ITC->phiL_0_final.ival(); - iphiproj[1] = ITC->phiL_1_final.ival(); - iphiproj[2] = ITC->phiL_2_final.ival(); - iphiproj[3] = ITC->phiL_3_final.ival(); - - izproj[0] = ITC->zL_0_final.ival(); - izproj[1] = ITC->zL_1_final.ival(); - izproj[2] = ITC->zL_2_final.ival(); - izproj[3] = ITC->zL_3_final.ival(); - - if (!goodTrackPars(ITC->rinv_final.local_passes(), ITC->z0_final.local_passes())) { + //Each of ir1 and ir2 are signed 8 bit integers. idr is signed 9 bit integer + int idr = ir2 - ir1; + + if (idr < 0) idr += 512; + + int irinv_new, iphi0_new, iz0_new, it_new; + + unsigned int ir1mean = settings_.irmean(layerdisk1_); + unsigned int ir2mean = settings_.irmean(layerdisk2_); + + int ir1abs = ir1 + ir1mean; + int ir2abs = ir2 + ir2mean; + + calcPars(idr, iphi1, ir1abs, iz1, iphi2, ir2abs, iz2, irinv_new, iphi0_new, iz0_new, it_new); + + bool rinvcut = abs(irinv_new) < settings_.rinvcut()*(120.0*(1<= (1 << (settings_.nzbitsstub(0) - 1))) - continue; - - //reject projection if phi is out of range - if (iphiproj[i] >= (1 << settings_.nphibitsstub(5)) - 1) - continue; - if (iphiproj[i] <= 0) - continue; - - //Adjust bits for r and z projection depending on layer - if (settings_.projlayers(iSeed_, i) <= 3) { //TODO clean up logic - iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(settings_.projlayers(iSeed_, i) - 1)); - } else { - izproj[i] >>= (settings_.nzbitsstub(0) - settings_.nzbitsstub(5)); - } - - projs[settings_.projlayers(iSeed_, i) - 1].init(settings_, - settings_.projlayers(iSeed_, i) - 1, - iphiproj[i], - izproj[i], - ITC->der_phiL_final.ival(), - ITC->der_zL_final.ival(), - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - ITC->der_phiL_final.fval(), - ITC->der_zL_final.fval(), - !(iSeed_ == 2 || iSeed_ == 3)); - } - - iphiprojdisk[0] = ITC->phiD_0_final.ival(); - iphiprojdisk[1] = ITC->phiD_1_final.ival(); - iphiprojdisk[2] = ITC->phiD_2_final.ival(); - iphiprojdisk[3] = ITC->phiD_3_final.ival(); - iphiprojdisk[4] = ITC->phiD_4_final.ival(); - - irprojdisk[0] = ITC->rD_0_final.ival(); - irprojdisk[1] = ITC->rD_1_final.ival(); - irprojdisk[2] = ITC->rD_2_final.ival(); - irprojdisk[3] = ITC->rD_3_final.ival(); - irprojdisk[4] = ITC->rD_4_final.ival(); - - if (std::abs(it * ITC->t_final.K()) > 1.0) { - for (unsigned int i = 0; i < N_DISK; ++i) { - if (iphiprojdisk[i] <= 0) - continue; - if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1) - continue; - - if (irprojdisk[i] < settings_.rmindisk() / ITC->rD_0_final.K() || - irprojdisk[i] >= settings_.rmaxdisk() / ITC->rD_0_final.K()) - continue; - - projs[i + N_LAYER].init(settings_, - i + N_LAYER, - iphiprojdisk[i], - irprojdisk[i], - ITC->der_phiD_final.ival(), - ITC->der_rD_final.ival(), - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - ITC->der_phiD_final.fval(), - ITC->der_rD_final.fval(), - !(iSeed_ == 2 || iSeed_ == 3)); - } - } - if (settings_.writeMonitorData("TPars")) { globals_->ofstream("trackletpars.txt") - << "Trackpars " << layerdisk1_ + 1 << " " << rinv << " " << rinvapprox << " " << ITC->rinv_final.fval() - << " " << phi0 << " " << phi0approx << " " << ITC->phi0_final.fval() << " " << t << " " << tapprox << " " - << ITC->t_final.fval() << " " << z0 << " " << z0approx << " " << ITC->z0_final.fval() << endl; + << "Trackpars " << layerdisk1_ + 1 << " " << " " << rinv << " " << irinv_new + << " " << phi0 << " " << iphi0_new << " " << t << " " + << it_new << " " << " " << iz0_new << endl; } Tracklet* tracklet = new Tracklet(settings_, @@ -668,17 +582,16 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, 0.0, z0, t, - rinvapprox, - phi0approx, + rinv, + phi0, 0.0, - z0approx, - tapprox, - irinv, - iphi0, + z0, + t, + irinv_new, + iphi0_new, 0, - iz0, - it, - projs, + iz0_new, + it_new, false); if (settings_.debugTracklet()) { @@ -703,61 +616,27 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, globals_, iSeed_, iSector_, - rinvapprox, - irinv * ITC->rinv_final.K(), - phi0approx, - iphi0 * ITC->phi0_final.K(), - asinh(tapprox), - asinh(it * ITC->t_final.K()), - z0approx, - iz0 * ITC->z0_final.K(), + rinv, + irinv_new * settings_.krinvpars(), + phi0, + iphi0_new * settings_.kphi0pars(), + asinh(t), + asinh(it_new * settings_.ktpars()), + z0, + iz0_new * settings_.kz0pars(), tp); } - bool addL3 = false; - bool addL4 = false; - bool addL5 = false; - bool addL6 = false; - for (unsigned int j = 0; j < N_LAYER - 2; j++) { - int lproj = settings_.projlayers(iSeed_, j); - bool added = false; - if (tracklet->validProj(lproj - 1)) { - added = addLayerProj(tracklet, lproj); - if (added && lproj == 3) - addL3 = true; - if (added && lproj == 4) - addL4 = true; - if (added && lproj == 5) - addL5 = true; - if (added && lproj == 6) - addL6 = true; - } - } - - for (unsigned int j = 0; j < N_DISK - 1; j++) { //no projections to 5th disk!! - int disk = j + 1; - if (disk == 4 && addL3) - continue; - if (disk == 3 && addL4) - continue; - if (disk == 2 && addL5) - continue; - if (disk == 1 && addL6) - continue; - if (it < 0) - disk = -disk; - if (tracklet->validProj(N_LAYER + abs(disk) - 1)) { - addDiskProj(tracklet, disk); - } - } - return true; } bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, const L1TStub* innerStub, const Stub* outerFPGAStub, - const L1TStub* outerStub) { + const L1TStub* outerStub, + bool print) { + + if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "TrackletCalculator::execute calculate disk seeds"; } @@ -820,98 +699,13 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, r2 = outerFPGAStub->rapprox(); } - double rinvapprox, phi0approx, tapprox, z0approx; - double phiprojapprox[N_PSLAYER], zprojapprox[N_PSLAYER]; - double phiprojdiskapprox[N_DISK - 2], rprojdiskapprox[N_DISK - 2]; - - IMATH_TrackletCalculatorDisk* ITC; - if (disk == 1) - ITC = globals_->ITC_F1F2(); - else if (disk == 3) - ITC = globals_->ITC_F3F4(); - else if (disk == -1) - ITC = globals_->ITC_B1B2(); - else - ITC = globals_->ITC_B3B4(); - - ITC->r1.set_fval(r1); - ITC->r2.set_fval(r2); - int signt = t > 0 ? 1 : -1; - ITC->z1.set_fval(z1 - signt * settings_.zmean(layerdisk1_ - N_LAYER)); - ITC->z2.set_fval(z2 - signt * settings_.zmean(layerdisk2_ - N_LAYER)); - double sphi1 = angle0to2pi::make0To2pi(phi1 - phimin_); - double sphi2 = angle0to2pi::make0To2pi(phi2 - phimin_); - ITC->phi1.set_fval(sphi1); - ITC->phi2.set_fval(sphi2); - - ITC->rproj0.set_fval(settings_.rmean(0)); - ITC->rproj1.set_fval(settings_.rmean(1)); - ITC->rproj2.set_fval(settings_.rmean(2)); - - ITC->zproj0.set_fval(signt * settings_.zmean(settings_.projdisks(iSeed_, 0) - 1)); - ITC->zproj1.set_fval(signt * settings_.zmean(settings_.projdisks(iSeed_, 1) - 1)); - ITC->zproj2.set_fval(signt * settings_.zmean(settings_.projdisks(iSeed_, 2) - 1)); - - ITC->rinv_final.calculate(); - ITC->phi0_final.calculate(); - ITC->t_final.calculate(); - ITC->z0_final.calculate(); - - ITC->phiL_0_final.calculate(); - ITC->phiL_1_final.calculate(); - ITC->phiL_2_final.calculate(); - - ITC->zL_0_final.calculate(); - ITC->zL_1_final.calculate(); - ITC->zL_2_final.calculate(); - - ITC->phiD_0_final.calculate(); - ITC->phiD_1_final.calculate(); - ITC->phiD_2_final.calculate(); - - ITC->rD_0_final.calculate(); - ITC->rD_1_final.calculate(); - ITC->rD_2_final.calculate(); - - ITC->der_phiL_final.calculate(); - ITC->der_zL_final.calculate(); - ITC->der_phiD_final.calculate(); - ITC->der_rD_final.calculate(); - - //store the approximate results - rinvapprox = ITC->rinv_final.fval(); - phi0approx = ITC->phi0_final.fval(); - tapprox = ITC->t_final.fval(); - z0approx = ITC->z0_final.fval(); - - phiprojapprox[0] = ITC->phiL_0_final.fval(); - phiprojapprox[1] = ITC->phiL_1_final.fval(); - phiprojapprox[2] = ITC->phiL_2_final.fval(); - - zprojapprox[0] = ITC->zL_0_final.fval(); - zprojapprox[1] = ITC->zL_1_final.fval(); - zprojapprox[2] = ITC->zL_2_final.fval(); - - phiprojdiskapprox[0] = ITC->phiD_0_final.fval(); - phiprojdiskapprox[1] = ITC->phiD_1_final.fval(); - phiprojdiskapprox[2] = ITC->phiD_2_final.fval(); - - rprojdiskapprox[0] = ITC->rD_0_final.fval(); - rprojdiskapprox[1] = ITC->rD_1_final.fval(); - rprojdiskapprox[2] = ITC->rD_2_final.fval(); - //now binary - int irinv, iphi0, it, iz0; - int iphiproj[N_PSLAYER], izproj[N_PSLAYER]; - - int iphiprojdisk[N_DISK - 2], irprojdisk[N_DISK - 2]; - - int ir1 = innerFPGAStub->r().value(); + int ir1 = innerFPGAStub->rvalue(); int iphi1 = innerFPGAStub->phi().value(); int iz1 = innerFPGAStub->z().value(); - int ir2 = outerFPGAStub->r().value(); + int ir2 = outerFPGAStub->rvalue(); int iphi2 = outerFPGAStub->phi().value(); int iz2 = outerFPGAStub->z().value(); @@ -919,135 +713,51 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, iphi1 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); iphi2 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); - ITC->r1.set_ival(ir1); - ITC->r2.set_ival(ir2); - ITC->z1.set_ival(iz1); - ITC->z2.set_ival(iz2); - ITC->phi1.set_ival(iphi1); - ITC->phi2.set_ival(iphi2); - - ITC->rinv_final.calculate(); - ITC->phi0_final.calculate(); - ITC->t_final.calculate(); - ITC->z0_final.calculate(); - - ITC->phiL_0_final.calculate(); - ITC->phiL_1_final.calculate(); - ITC->phiL_2_final.calculate(); - - ITC->zL_0_final.calculate(); - ITC->zL_1_final.calculate(); - ITC->zL_2_final.calculate(); - - ITC->phiD_0_final.calculate(); - ITC->phiD_1_final.calculate(); - ITC->phiD_2_final.calculate(); - - ITC->rD_0_final.calculate(); - ITC->rD_1_final.calculate(); - ITC->rD_2_final.calculate(); - - ITC->der_phiL_final.calculate(); - ITC->der_zL_final.calculate(); - ITC->der_phiD_final.calculate(); - ITC->der_rD_final.calculate(); - - //store the binary results - irinv = ITC->rinv_final.ival(); - iphi0 = ITC->phi0_final.ival(); - it = ITC->t_final.ival(); - iz0 = ITC->z0_final.ival(); - - iphiproj[0] = ITC->phiL_0_final.ival(); - iphiproj[1] = ITC->phiL_1_final.ival(); - iphiproj[2] = ITC->phiL_2_final.ival(); - - izproj[0] = ITC->zL_0_final.ival(); - izproj[1] = ITC->zL_1_final.ival(); - izproj[2] = ITC->zL_2_final.ival(); - - if (!goodTrackPars(ITC->rinv_final.local_passes(), ITC->z0_final.local_passes())) - return false; + //Each of ir1 and ir2 are signed 8 bit integers. idr is signed 9 bit integer + unsigned int idr = ir2-ir1; - if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) - return false; + unsigned int iz1mean = sign*settings_.izmean(layerdisk1_ - N_LAYER); + unsigned int iz2mean = sign*settings_.izmean(layerdisk2_ - N_LAYER); + + int iz1abs = iz1 + iz1mean; + int iz2abs = iz2 + iz2mean; + + int irinv_new, iphi0_new, iz0_new, it_new; - Projection projs[N_LAYER + N_DISK]; - - for (unsigned int i = 0; i < N_DISK - 2; ++i) { - //Check is outside z range - if (izproj[i] < -(1 << (settings_.nzbitsstub(0) - 1))) - continue; - if (izproj[i] >= (1 << (settings_.nzbitsstub(0) - 1))) - continue; - - //Check if outside phi range - if (iphiproj[i] >= (1 << settings_.nphibitsstub(5)) - 1) - continue; - if (iphiproj[i] <= 0) - continue; - - //shift bits - allways in PS modules for disk seeding - iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); - - projs[i].init(settings_, - i, - iphiproj[i], - izproj[i], - ITC->der_phiL_final.ival(), - ITC->der_zL_final.ival(), - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - ITC->der_phiL_final.fval(), - ITC->der_zL_final.fval(), - true); + calcPars(idr, iphi1, ir1, iz1abs, iphi2, ir2, iz2abs, irinv_new, iphi0_new, iz0_new, it_new); + + if (print) { + std::cout << "=======================" << std::endl; + std::cout << "iphi1, ir1, iz1abs : " << iphi1 << " " << ir1 << " " << iz1abs << std::endl; + std::cout << "iphi2, ir2, iz2abs : " << iphi2 << " " << ir2 << " " << iz2abs << std::endl; + std::cout << "idr irinv iphi0 iz0 it : " << idr << " " << irinv_new << " " << iphi0_new + << " " << iz0_new << " " << it_new <phiD_0_final.ival(); - iphiprojdisk[1] = ITC->phiD_1_final.ival(); - iphiprojdisk[2] = ITC->phiD_2_final.ival(); - - irprojdisk[0] = ITC->rD_0_final.ival(); - irprojdisk[1] = ITC->rD_1_final.ival(); - irprojdisk[2] = ITC->rD_2_final.ival(); - - for (unsigned int i = 0; i < N_DISK - 2; ++i) { - //check that phi projection in range - if (iphiprojdisk[i] <= 0) - continue; - if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1) - continue; - - //check that r projection in range - if (irprojdisk[i] <= 0 || irprojdisk[i] >= settings_.rmaxdisk() / ITC->rD_0_final.K()) - continue; - - projs[settings_.projdisks(iSeed_, i) + N_LAYER - 1].init(settings_, - settings_.projdisks(iSeed_, i) + N_LAYER - 1, - iphiprojdisk[i], - irprojdisk[i], - ITC->der_phiD_final.ival(), - ITC->der_rD_final.ival(), - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - ITC->der_phiD_final.fval(), - ITC->der_rD_final.fval(), - true); + bool rinvcut = abs(irinv_new) < settings_.rinvcut()*(120.0*(1<ofstream("trackletparsdisk.txt") - << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << rinvapprox << " " - << ITC->rinv_final.fval() << " " << phi0 << " " << phi0approx << " " << ITC->phi0_final.fval() << " " << t - << " " << tapprox << " " << ITC->t_final.fval() << " " << z0 << " " << z0approx << " " << ITC->z0_final.fval() + << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << rinv << " " + << rinv << " " << phi0 << " " << phi0 << " " << phi0 << " " << t + << " " << t << " " << t << " " << z0 << " " << z0 << " " << z0 << endl; } @@ -1061,17 +771,16 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, 0.0, z0, t, - rinvapprox, - phi0approx, + rinv, + phi0, 0.0, - z0approx, - tapprox, - irinv, - iphi0, + z0, + t, + irinv_new, + iphi0_new, 0, - iz0, - it, - projs, + iz0_new, + it_new, true); if (settings_.debugTracklet()) { @@ -1088,34 +797,21 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, } trackletpars_->addTracklet(tracklet); - if (tracklet->validProj(0)) { - addLayerProj(tracklet, 1); - } - - if (tracklet->validProj(1)) { - addLayerProj(tracklet, 2); - } - - for (unsigned int j = 0; j < N_DISK - 2; j++) { - if (tracklet->validProj(N_LAYER + settings_.projdisks(iSeed_, j) - 1)) { - addDiskProj(tracklet, sign * settings_.projdisks(iSeed_, j)); - } - } - return true; } bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, const L1TStub* innerStub, const Stub* outerFPGAStub, - const L1TStub* outerStub) { + const L1TStub* outerStub, + bool print) { + + //Deal with overlap stubs here assert(outerFPGAStub->layerdisk() < N_LAYER); assert(innerFPGAStub->layerdisk() >= N_LAYER); - int disk = innerFPGAStub->disk().value(); - if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "trying to make overlap tracklet for seed = " << iSeed_ << " " << getName(); } @@ -1169,246 +865,67 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, r2 = outerFPGAStub->rapprox(); } - double rinvapprox, phi0approx, tapprox, z0approx; - double phiprojapprox[N_PSLAYER], zprojapprox[N_PSLAYER]; - double phiprojdiskapprox[N_DISK - 1], rprojdiskapprox[N_DISK - 1]; - - IMATH_TrackletCalculatorOverlap* ITC; - int ll = outerFPGAStub->layer().value() + 1; - if (ll == 1 && disk == 1) - ITC = globals_->ITC_L1F1(); - else if (ll == 2 && disk == 1) - ITC = globals_->ITC_L2F1(); - else if (ll == 1 && disk == -1) - ITC = globals_->ITC_L1B1(); - else if (ll == 2 && disk == -1) - ITC = globals_->ITC_L2B1(); - else - throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; - - ITC->r1.set_fval(r2 - settings_.rmean(ll - 1)); - ITC->r2.set_fval(r1); - int signt = t > 0 ? 1 : -1; - ITC->z1.set_fval(z2); - ITC->z2.set_fval(z1 - signt * settings_.zmean(layerdisk2_ - N_LAYER)); - double sphi1 = angle0to2pi::make0To2pi(phi1 - phimin_); - double sphi2 = angle0to2pi::make0To2pi(phi2 - phimin_); - ITC->phi1.set_fval(sphi2); - ITC->phi2.set_fval(sphi1); - - ITC->rproj0.set_fval(settings_.rmean(0)); - ITC->rproj1.set_fval(settings_.rmean(1)); - ITC->rproj2.set_fval(settings_.rmean(2)); - - ITC->zproj0.set_fval(signt * settings_.zmean(1)); - ITC->zproj1.set_fval(signt * settings_.zmean(2)); - ITC->zproj2.set_fval(signt * settings_.zmean(3)); - ITC->zproj3.set_fval(signt * settings_.zmean(4)); - - ITC->rinv_final.calculate(); - ITC->phi0_final.calculate(); - ITC->t_final.calculate(); - ITC->z0_final.calculate(); - - ITC->phiL_0_final.calculate(); - ITC->phiL_1_final.calculate(); - ITC->phiL_2_final.calculate(); - - ITC->zL_0_final.calculate(); - ITC->zL_1_final.calculate(); - ITC->zL_2_final.calculate(); - - ITC->phiD_0_final.calculate(); - ITC->phiD_1_final.calculate(); - ITC->phiD_2_final.calculate(); - ITC->phiD_3_final.calculate(); - - ITC->rD_0_final.calculate(); - ITC->rD_1_final.calculate(); - ITC->rD_2_final.calculate(); - ITC->rD_3_final.calculate(); - - ITC->der_phiL_final.calculate(); - ITC->der_zL_final.calculate(); - ITC->der_phiD_final.calculate(); - ITC->der_rD_final.calculate(); - - //store the approximate results - rinvapprox = ITC->rinv_final.fval(); - phi0approx = ITC->phi0_final.fval(); - tapprox = ITC->t_final.fval(); - z0approx = ITC->z0_final.fval(); - - phiprojapprox[0] = ITC->phiL_0_final.fval(); - phiprojapprox[1] = ITC->phiL_1_final.fval(); - phiprojapprox[2] = ITC->phiL_2_final.fval(); - - zprojapprox[0] = ITC->zL_0_final.fval(); - zprojapprox[1] = ITC->zL_1_final.fval(); - zprojapprox[2] = ITC->zL_2_final.fval(); - - phiprojdiskapprox[0] = ITC->phiD_0_final.fval(); - phiprojdiskapprox[1] = ITC->phiD_1_final.fval(); - phiprojdiskapprox[2] = ITC->phiD_2_final.fval(); - phiprojdiskapprox[3] = ITC->phiD_3_final.fval(); - - rprojdiskapprox[0] = ITC->rD_0_final.fval(); - rprojdiskapprox[1] = ITC->rD_1_final.fval(); - rprojdiskapprox[2] = ITC->rD_2_final.fval(); - rprojdiskapprox[3] = ITC->rD_3_final.fval(); - //now binary - int irinv, iphi0, it, iz0; - int iphiproj[N_LAYER - 2], izproj[N_LAYER - 2]; - int iphiprojdisk[N_DISK], irprojdisk[N_DISK]; - - int ir2 = innerFPGAStub->r().value(); + int ir2 = innerFPGAStub->rvalue(); int iphi2 = innerFPGAStub->phi().value(); int iz2 = innerFPGAStub->z().value(); - int ir1 = outerFPGAStub->r().value(); + int ir1 = outerFPGAStub->rvalue(); int iphi1 = outerFPGAStub->phi().value(); int iz1 = outerFPGAStub->z().value(); //To get global precission + int ll = outerFPGAStub->layer().value() + 1; ir1 = l1t::bitShift(ir1, (8 - settings_.nrbitsstub(ll - 1))); iphi1 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); iphi2 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); - ITC->r1.set_ival(ir1); - ITC->r2.set_ival(ir2); - ITC->z1.set_ival(iz1); - ITC->z2.set_ival(iz2); - ITC->phi1.set_ival(iphi1); - ITC->phi2.set_ival(iphi2); - - ITC->rinv_final.calculate(); - ITC->phi0_final.calculate(); - ITC->t_final.calculate(); - ITC->z0_final.calculate(); - - ITC->phiL_0_final.calculate(); - ITC->phiL_1_final.calculate(); - ITC->phiL_2_final.calculate(); - - ITC->zL_0_final.calculate(); - ITC->zL_1_final.calculate(); - ITC->zL_2_final.calculate(); - - ITC->phiD_0_final.calculate(); - ITC->phiD_1_final.calculate(); - ITC->phiD_2_final.calculate(); - ITC->phiD_3_final.calculate(); - - ITC->rD_0_final.calculate(); - ITC->rD_1_final.calculate(); - ITC->rD_2_final.calculate(); - ITC->rD_3_final.calculate(); - - ITC->der_phiL_final.calculate(); - ITC->der_zL_final.calculate(); - ITC->der_phiD_final.calculate(); - ITC->der_rD_final.calculate(); - - //store the binary results - irinv = ITC->rinv_final.ival(); - iphi0 = ITC->phi0_final.ival(); - it = ITC->t_final.ival(); - iz0 = ITC->z0_final.ival(); - - iphiproj[0] = ITC->phiL_0_final.ival(); - iphiproj[1] = ITC->phiL_1_final.ival(); - iphiproj[2] = ITC->phiL_2_final.ival(); - - izproj[0] = ITC->zL_0_final.ival(); - izproj[1] = ITC->zL_1_final.ival(); - izproj[2] = ITC->zL_2_final.ival(); - - iphiprojdisk[0] = ITC->phiD_0_final.ival(); - iphiprojdisk[1] = ITC->phiD_1_final.ival(); - iphiprojdisk[2] = ITC->phiD_2_final.ival(); - iphiprojdisk[3] = ITC->phiD_3_final.ival(); - - irprojdisk[0] = ITC->rD_0_final.ival(); - irprojdisk[1] = ITC->rD_1_final.ival(); - irprojdisk[2] = ITC->rD_2_final.ival(); - irprojdisk[3] = ITC->rD_3_final.ival(); - - if (!goodTrackPars(ITC->rinv_final.local_passes(), ITC->z0_final.local_passes())) - return false; + unsigned int ir1mean = settings_.irmean(layerdisk1_); + + int ir1abs = ir1 + ir1mean; - if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) + unsigned int idr = ir2-ir1abs; + + if (idr >= LUT_idrinv_.size()) { return false; + } - Projection projs[N_LAYER + N_DISK]; - - for (unsigned int i = 0; i < N_DISK - 2; ++i) { - //check that zproj is in range - if (izproj[i] < -(1 << (settings_.nzbitsstub(0) - 1))) - continue; - if (izproj[i] >= (1 << (settings_.nzbitsstub(0) - 1))) - continue; - - //check that phiproj is in range - if (iphiproj[i] >= (1 << settings_.nphibitsstub(5)) - 1) - continue; - if (iphiproj[i] <= 0) - continue; - - //adjust bits for PS modules (no 2S modules in overlap seeds) - iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); - - projs[i].init(settings_, - i, - iphiproj[i], - izproj[i], - ITC->der_phiL_final.ival(), - ITC->der_zL_final.ival(), - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - ITC->der_phiL_final.fval(), - ITC->der_zL_final.fval(), - true); + int iz2mean = settings_.izmean(layerdisk2_ - N_LAYER); + + if (iz1<0) { + iz2mean = -iz2mean; } - for (int i = 0; i < 4; ++i) { - //check that phi projection in range - if (iphiprojdisk[i] <= 0) - continue; - if (iphiprojdisk[i] >= (1 << settings_.nphibitsstub(0)) - 1) - continue; - - //check that r projection in range - if (irprojdisk[i] <= 0 || irprojdisk[i] >= settings_.rmaxdisk() / ITC->rD_0_final.K()) - continue; - - projs[N_LAYER + i + 1].init(settings_, - N_LAYER + i + 1, - iphiprojdisk[i], - irprojdisk[i], - ITC->der_phiD_final.ival(), - ITC->der_rD_final.ival(), - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - ITC->der_phiD_final.fval(), - ITC->der_rD_final.fval(), - true); + int iz2abs = iz2 + iz2mean; + + int irinv_new, iphi0_new, iz0_new, it_new; + + calcPars(idr, iphi1, ir1abs, iz1, iphi2, ir2, iz2abs, irinv_new, iphi0_new, iz0_new, it_new); + + if (print) { + std::cout << "======================================" << std::endl; + std::cout << "ir: " << ir1abs << " " << ir2 << std::endl; + std::cout << "iphi: " << iphi1 << " " << iphi2 << std::endl; + std::cout << "iz: " << iz1 << " " << iz2abs << std::endl; + std::cout << "iz2 iz2mean " << iz2 << " " << iz2mean << std::endl; + std::cout << "pars: " << irinv_new << " " << iphi0_new << " " << iz0_new << " " << it_new << std::endl; } + bool rinvcut = abs(irinv_new) < settings_.rinvcut()*(120.0*(1<ofstream("trackletparsoverlap.txt") - << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << irinv << " " << ITC->rinv_final.fval() << " " - << phi0 << " " << iphi0 << " " << ITC->phi0_final.fval() << " " << t << " " << it << " " - << ITC->t_final.fval() << " " << z0 << " " << iz0 << " " << ITC->z0_final.fval() << endl; + << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << irinv_new << " " + << phi0 << " " << iphi0_new << " " << t << " " << it_new << " " + << z0 << " " << iz0_new << endl; } Tracklet* tracklet = new Tracklet(settings_, @@ -1421,17 +938,16 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, 0.0, z0, t, - rinvapprox, - phi0approx, + rinv, + phi0, 0.0, - z0approx, - tapprox, - irinv, - iphi0, + z0, + t, + irinv_new, + iphi0_new, 0, - iz0, - it, - projs, + iz0_new, + it_new, false, true); @@ -1449,21 +965,5 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, } trackletpars_->addTracklet(tracklet); - int layer = outerFPGAStub->layer().value() + 1; - - if (layer == 2) { - if (tracklet->validProj(0)) { - addLayerProj(tracklet, 1); - } - } - - for (unsigned int disk = 2; disk < 6; disk++) { - if (layer == 2 && disk == 5) - continue; - if (tracklet->validProj(N_LAYER + disk - 1)) { - addDiskProj(tracklet, disk); - } - } - return true; } diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc index 9138bf16a9145..1c72c8ef46672 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc @@ -4,7 +4,6 @@ #include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" #include "L1Trigger/TrackFindingTracklet/interface/Stub.h" #include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -599,8 +598,8 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, double phicritapprox = phi0approx - asin((0.5 * settings_.rcrit() * rinvapprox) + (d0approx / settings_.rcrit())); int phicrit = iphi0 - 2 * irinv - 2 * id0; - int iphicritmincut = settings_.phicritminmc() / globals_->ITC_L1L2()->phi0_final.K(); - int iphicritmaxcut = settings_.phicritmaxmc() / globals_->ITC_L1L2()->phi0_final.K(); + int iphicritmincut = settings_.phicritminmc() / settings_.kphi0pars(); + int iphicritmaxcut = settings_.phicritmaxmc() / settings_.kphi0pars(); bool keepapprox = (phicritapprox > settings_.phicritminmc()) && (phicritapprox < settings_.phicritmaxmc()), keep = (phicrit > iphicritmincut) && (phicrit < iphicritmaxcut); @@ -743,8 +742,8 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, id0, iz0, it, - projs, false); + tracklet->addProjs(projs); // add projections to tracklet if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() @@ -1019,8 +1018,8 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, double phicritapprox = phi0approx - asin((0.5 * settings_.rcrit() * rinvapprox) + (d0approx / settings_.rcrit())); int phicrit = iphi0 - 2 * irinv - 2 * id0; - int iphicritmincut = settings_.phicritminmc() / globals_->ITC_L1L2()->phi0_final.K(); - int iphicritmaxcut = settings_.phicritmaxmc() / globals_->ITC_L1L2()->phi0_final.K(); + int iphicritmincut = settings_.phicritminmc() / settings_.kphi0pars(); + int iphicritmaxcut = settings_.phicritmaxmc() / settings_.kphi0pars(); bool keepapprox = (phicritapprox > settings_.phicritminmc()) && (phicritapprox < settings_.phicritmaxmc()), keep = (phicrit > iphicritmincut) && (phicrit < iphicritmaxcut); @@ -1154,8 +1153,8 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, id0, iz0, it, - projs, true); + tracklet->addProjs(projs); // add projections to tracklet if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() @@ -1423,8 +1422,8 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, double phicritapprox = phi0approx - asin((0.5 * settings_.rcrit() * rinvapprox) + (d0approx / settings_.rcrit())); int phicrit = iphi0 - 2 * irinv - 2 * id0; - int iphicritmincut = settings_.phicritminmc() / globals_->ITC_L1L2()->phi0_final.K(); - int iphicritmaxcut = settings_.phicritmaxmc() / globals_->ITC_L1L2()->phi0_final.K(); + int iphicritmincut = settings_.phicritminmc() / settings_.kphi0pars(); + int iphicritmaxcut = settings_.phicritmaxmc() / settings_.kphi0pars(); bool keepapprox = (phicritapprox > settings_.phicritminmc()) && (phicritapprox < settings_.phicritmaxmc()), keep = (phicrit > iphicritmincut) && (phicrit < iphicritmaxcut); @@ -1559,8 +1558,8 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, id0, iz0, it, - projs, false); + tracklet->addProjs(projs); // add projections to tracklet if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc index c84581a47a33d..70a3dc3f7d2e1 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc @@ -24,7 +24,6 @@ TrackletConfigBuilder::TrackletConfigBuilder(const Settings& settings, const tt: rcrit_ = settings.rcrit(); duplicateMPs_ = settings.duplicateMPs(); - combinedmodules_ = settings.combined(); extended_ = settings.extended(); @@ -356,26 +355,12 @@ std::pair TrackletConfigBuilder::seedPhiRange(double rproj, unsi } } } - return std::pair(phimin, phimax); + return std::pair(phimin-0.07, phimax+0.07); } //--- Finds the projections needed for each seeding combination void TrackletConfigBuilder::buildProjections() { - set emptyProjStandard = { - "TPROJ_L1L2H_L3PHIB", "TPROJ_L1L2E_L3PHIC", "TPROJ_L1L2K_L3PHIC", "TPROJ_L1L2H_L3PHID", "TPROJ_L1L2F_L5PHIA", - "TPROJ_L1L2G_L5PHID", "TPROJ_L1L2A_L6PHIA", "TPROJ_L1L2J_L6PHIB", "TPROJ_L1L2C_L6PHIC", "TPROJ_L1L2L_L6PHID", - "TPROJ_L3L4D_D1PHIB", "TPROJ_L2L3A_D1PHIC", "TPROJ_L3L4A_D1PHIC", "TPROJ_L1L2G_D2PHIA", "TPROJ_L1D1D_D2PHIA", - "TPROJ_L1D1E_D2PHIA", "TPROJ_L1L2J_D2PHIB", "TPROJ_L3L4D_D2PHIB", "TPROJ_L1D1A_D2PHIB", "TPROJ_L1D1F_D2PHIB", - "TPROJ_L1D1G_D2PHIB", "TPROJ_L1L2C_D2PHIC", "TPROJ_L2L3A_D2PHIC", "TPROJ_L3L4A_D2PHIC", "TPROJ_L1D1B_D2PHIC", - "TPROJ_L1D1C_D2PHIC", "TPROJ_L1D1H_D2PHIC", "TPROJ_L2D1A_D2PHIC", "TPROJ_L1L2F_D2PHID", "TPROJ_L1D1D_D2PHID", - "TPROJ_L1D1E_D2PHID", "TPROJ_L1L2G_D3PHIA", "TPROJ_L1D1D_D3PHIA", "TPROJ_L1D1E_D3PHIA", "TPROJ_L1L2J_D3PHIB", - "TPROJ_L1D1A_D3PHIB", "TPROJ_L1D1F_D3PHIB", "TPROJ_L1D1G_D3PHIB", "TPROJ_L1L2C_D3PHIC", "TPROJ_L2L3A_D3PHIC", - "TPROJ_L1D1B_D3PHIC", "TPROJ_L1D1C_D3PHIC", "TPROJ_L1D1H_D3PHIC", "TPROJ_L2D1A_D3PHIC", "TPROJ_L1L2F_D3PHID", - "TPROJ_L1D1D_D3PHID", "TPROJ_L1D1E_D3PHID", "TPROJ_L1L2G_D4PHIA", "TPROJ_L1D1D_D4PHIA", "TPROJ_L1D1E_D4PHIA", - "TPROJ_L1L2J_D4PHIB", "TPROJ_L1D1G_D4PHIB", "TPROJ_L1L2C_D4PHIC", "TPROJ_L2L3A_D4PHIC", "TPROJ_L1D1B_D4PHIC", - "TPROJ_L2D1A_D4PHIC", "TPROJ_L1L2F_D4PHID", "TPROJ_L1D1D_D4PHID", "TPROJ_L1D1E_D5PHIA", "TPROJ_L1D1G_D5PHIB", - "TPROJ_L1D1B_D5PHIC", "TPROJ_L1D1D_D5PHID"}; set emptyProjCombined = { "TPROJ_L1L2J_L6PHIB", "TPROJ_L1L2C_L6PHIC", "TPROJ_L1L2G_D1PHIA", "TPROJ_L1L2J_D1PHIB", "TPROJ_L2L3D_D1PHIB", @@ -387,7 +372,69 @@ void TrackletConfigBuilder::buildProjections() { "TPROJ_L1D1B_D3PHIC", "TPROJ_L2D1A_D3PHIC", "TPROJ_L1L2F_D3PHID", "TPROJ_L1D1D_D3PHID", "TPROJ_L1L2G_D4PHIA", "TPROJ_L1D1E_D4PHIA", "TPROJ_L1L2J_D4PHIB", "TPROJ_L2L3D_D4PHIB", "TPROJ_L1D1G_D4PHIB", "TPROJ_L1L2C_D4PHIC", "TPROJ_L2L3A_D4PHIC", "TPROJ_L1D1B_D4PHIC", "TPROJ_L2D1A_D4PHIC", "TPROJ_L1L2F_D4PHID", "TPROJ_L1D1D_D4PHID", - "TPROJ_L1D1E_D5PHIA", "TPROJ_L1D1G_D5PHIB", "TPROJ_L1D1B_D5PHIC", "TPROJ_L1D1D_D5PHID"}; + "TPROJ_L1D1E_D5PHIA", "TPROJ_L1D1G_D5PHIB", "TPROJ_L1D1B_D5PHIC", "TPROJ_L1D1D_D5PHID", "TPROJ_L1D1D_D4PHID", + "TPROJ_L5L6C_L1PHIA", "TPROJ_L5L6D_L1PHIA", "TPROJ_L5L6A_L4PHID", "TPROJ_L5L6B_L4PHID", "TPROJ_L2L3B_L1PHIH", + "TPROJ_L2L3A_L1PHIH", "TPROJ_L2D1C_L1PHIB", "TPROJ_D1D2D_L2PHIA", "TPROJ_D1D2C_L2PHIA", "TPROJ_L2L3A_L4PHID", + "TPROJ_L2L3B_L4PHID", "TPROJ_L2D1B_D3PHID", "TPROJ_L2D1A_D2PHIC", "TPROJ_D3D4B_D1PHID", "TPROJ_D3D4A_D1PHID", + "TPROJ_L3L4D_L6PHIB", "TPROJ_L1D1H_D4PHIB", "TPROJ_D3D4B_D5PHID", "TPROJ_L2D1D_D3PHIB", "TPROJ_D3D4A_D5PHID", + "TPROJ_L1D1A_D4PHIC", "TPROJ_L1D1B_D4PHIC", "TPROJ_L2D1A_D3PHIC", "TPROJ_L2L3D_L4PHIB", "TPROJ_L2L3B_L1PHIF", + "TPROJ_L2L3A_L1PHIF", "TPROJ_L3L4A_D1PHID", "TPROJ_L3L4B_D1PHID", "TPROJ_D1D2B_D5PHID", "TPROJ_D3D4A_D1PHIC", + "TPROJ_L2L3A_L1PHID", "TPROJ_L2L3D_L1PHID", "TPROJ_L3L4D_D1PHIB", "TPROJ_L2L3A_D2PHIC", "TPROJ_L3L4A_L5PHIC", + "TPROJ_L1L2I_D4PHIA", "TPROJ_L2D1C_L1PHIH", "TPROJ_L2D1B_L1PHIH", "TPROJ_L2D1A_L1PHIH", "TPROJ_L1L2L_L3PHIC", + "TPROJ_L1D1H_D2PHIB", "TPROJ_L5L6D_L4PHIB", "TPROJ_L2D1D_L1PHID", "TPROJ_L2D1A_L1PHID", "TPROJ_L1L2C_D3PHIC", + "TPROJ_L1L2B_D3PHIC", "TPROJ_L1L2A_D3PHIC", "TPROJ_L2D1D_L1PHIB", "TPROJ_L2L3C_L1PHIH", "TPROJ_D1D2A_D5PHIC", + "TPROJ_L2L3D_D4PHIB", "TPROJ_L1L2H_D4PHIA", "TPROJ_L2D1B_L1PHIF", "TPROJ_L2D1A_L1PHIF", "TPROJ_D1D2C_D5PHIA", + "TPROJ_D1D2D_D5PHIA", "TPROJ_L1D1A_D3PHID", "TPROJ_L2D1D_D4PHIB", "TPROJ_L1D1B_D3PHID", "TPROJ_L1D1C_D3PHID", + "TPROJ_L2L3A_L1PHIG", "TPROJ_L1L2F_L6PHID", "TPROJ_L2L3B_D3PHID", "TPROJ_L2L3A_D3PHID", "TPROJ_D1D2A_D4PHIC", + "TPROJ_D1D2D_D4PHIA", "TPROJ_D1D2C_D4PHIA", "TPROJ_L1L2E_D2PHID", "TPROJ_L2L3D_L4PHIA", "TPROJ_L2L3C_L4PHIA", + "TPROJ_L2L3A_L4PHIC", "TPROJ_L2L3B_L5PHID", "TPROJ_L2L3A_L5PHID", "TPROJ_L3L4D_D2PHIB", "TPROJ_L2L3D_D2PHIA", + "TPROJ_L3L4A_D1PHIC", "TPROJ_L2L3D_D3PHIB", "TPROJ_L1D1A_D3PHIC", "TPROJ_L2L3D_D4PHIA", "TPROJ_L1L2H_D2PHIA", + "TPROJ_L2L3C_D1PHIA", "TPROJ_L2L3D_D1PHIA", "TPROJ_L2L3A_D1PHIC", "TPROJ_L2L3A_D2PHID", "TPROJ_L2L3B_D2PHID", + "TPROJ_D1D2D_D5PHIB", "TPROJ_L1D1G_D4PHIB", "TPROJ_L1L2B_D4PHIC", "TPROJ_L2D1A_D2PHID", "TPROJ_D1D2A_D5PHID", + "TPROJ_L1L2B_L5PHIC", "TPROJ_L1L2A_L5PHIC", "TPROJ_L1L2C_L5PHIC", "TPROJ_L1L2H_D3PHIA", "TPROJ_L1L2K_D1PHIB", + "TPROJ_L1L2J_D1PHIB", "TPROJ_L1L2L_D1PHIB", "TPROJ_D3D4A_D2PHID", "TPROJ_D3D4B_D2PHID", "TPROJ_L2L3B_D1PHID", + "TPROJ_L2L3A_D1PHID", "TPROJ_L3L4A_L6PHIC", "TPROJ_D3D4D_L1PHID", "TPROJ_D3D4A_L1PHID", "TPROJ_D1D2D_D3PHIB", + "TPROJ_L1L2J_D4PHIB", "TPROJ_L1L2K_D4PHIB", "TPROJ_L1L2L_D4PHIB", "TPROJ_D1D2D_D4PHIB", "TPROJ_L1L2I_D1PHIA", + "TPROJ_L1L2H_D1PHIA", "TPROJ_L2L3A_D4PHID", "TPROJ_L2L3B_D4PHID", "TPROJ_L3L4C_D2PHIA", "TPROJ_L3L4D_D2PHIA", + "TPROJ_L3L4B_L1PHIA", "TPROJ_L2L3A_L5PHIC", "TPROJ_L3L4A_L1PHIE", "TPROJ_D3D4C_L1PHIH", "TPROJ_D3D4B_L1PHIH", + "TPROJ_D3D4A_L1PHIH", "TPROJ_L1L2B_D1PHIC", "TPROJ_L1L2A_D1PHIC", "TPROJ_L1L2C_D1PHIC", "TPROJ_D1D2A_D4PHID", + "TPROJ_D1D2B_D4PHID", "TPROJ_L1D1C_D5PHID", "TPROJ_L1D1D_D5PHID", "TPROJ_L1D1A_D5PHID", "TPROJ_L1D1B_D5PHID", + "TPROJ_D3D4C_L1PHIC", "TPROJ_D3D4D_L1PHIC", "TPROJ_L1D1B_D3PHIC", "TPROJ_L2L3C_D2PHIA", "TPROJ_L3L4D_L5PHIB", + "TPROJ_L2L3D_D1PHIB", "TPROJ_L5L6D_L2PHIA", "TPROJ_L5L6C_L2PHIA", "TPROJ_L2L3C_L5PHIA", "TPROJ_L2L3D_L5PHIA", + "TPROJ_L5L6A_L2PHIC", "TPROJ_L1D1C_D4PHID", "TPROJ_L1D1B_D4PHID", "TPROJ_L5L6B_L3PHID", "TPROJ_L1D1A_D4PHID", + "TPROJ_L5L6A_L3PHID", "TPROJ_L1D1G_D2PHIB", "TPROJ_D3D4C_L1PHIA", "TPROJ_D3D4D_L1PHIA", "TPROJ_D3D4B_L1PHIA", + "TPROJ_L2L3B_L1PHIG", "TPROJ_D3D4C_D2PHIA", "TPROJ_D1D2A_D3PHIC", "TPROJ_L3L4D_D1PHIA", "TPROJ_L3L4C_D1PHIA", + "TPROJ_D3D4D_D1PHIB", "TPROJ_D1D2D_L1PHID", "TPROJ_D1D2A_L1PHID", "TPROJ_L2D1D_D4PHIA", "TPROJ_L2D1C_D4PHIA", + "TPROJ_L1D1H_D5PHIB", "TPROJ_D1D2D_L1PHIB", "TPROJ_D1D2C_L1PHIB", "TPROJ_L2L3C_D4PHIA", "TPROJ_D3D4C_D5PHIA", + "TPROJ_D3D4D_D5PHIA", "TPROJ_D3D4A_L1PHIG", "TPROJ_D3D4B_L1PHIG", "TPROJ_L2D1A_D4PHID", "TPROJ_L2L3D_L5PHIB", + "TPROJ_D3D4D_L1PHIE", "TPROJ_D3D4A_L1PHIE", "TPROJ_L1L2K_L5PHIB", "TPROJ_L1L2J_L5PHIB", "TPROJ_L1L2L_L5PHIB", + "TPROJ_D1D2C_D3PHIA", "TPROJ_D1D2D_D3PHIA", "TPROJ_D3D4A_D5PHIC", "TPROJ_L2L3C_D3PHIA", "TPROJ_D3D4A_D2PHIC", + "TPROJ_L2L3D_D3PHIA", "TPROJ_L1D1B_D5PHIC", "TPROJ_L1D1A_D5PHIC", "TPROJ_D1D2B_L1PHIF", "TPROJ_D1D2A_L1PHIF", + "TPROJ_L3L4A_L1PHIF", "TPROJ_L2D1A_D4PHIC", "TPROJ_L3L4A_L2PHIC", "TPROJ_D1D2C_L1PHIH", "TPROJ_D1D2A_L1PHIH", + "TPROJ_L1L2D_L3PHIC", "TPROJ_L5L6D_L1PHIC", "TPROJ_D3D4D_L1PHIB", "TPROJ_D3D4C_L1PHIB", "TPROJ_L5L6A_L1PHIG", + "TPROJ_L5L6B_L1PHIG", "TPROJ_L3L4D_L2PHIB", "TPROJ_L1L2D_D3PHID", "TPROJ_L1L2E_D3PHID", "TPROJ_L1L2I_D2PHIA", + "TPROJ_L1D1D_D3PHID", "TPROJ_L5L6A_L1PHIE", "TPROJ_L2D1D_D2PHIB", "TPROJ_L2D1B_D2PHID", "TPROJ_L1L2E_D4PHID", + "TPROJ_L1L2D_D4PHID", "TPROJ_L5L6A_L2PHID", "TPROJ_L5L6B_L2PHID", "TPROJ_D1D2B_L1PHIH", "TPROJ_D3D4B_L1PHIF", + "TPROJ_D3D4A_L1PHIF", "TPROJ_D3D4D_D2PHIB", "TPROJ_D1D2A_L2PHIC", "TPROJ_L3L4D_L1PHID", "TPROJ_L1L2I_D3PHIA", + "TPROJ_L5L6A_L3PHIC", "TPROJ_L5L6D_L2PHIB", "TPROJ_L2D1B_D4PHID", "TPROJ_D1D2B_D3PHID", "TPROJ_D1D2A_D3PHID", + "TPROJ_L1L2I_L3PHIB", "TPROJ_L5L6C_L3PHIA", "TPROJ_L5L6D_L3PHIA", "TPROJ_D1D2C_L1PHIA", "TPROJ_D1D2D_L1PHIA", + "TPROJ_D1D2B_L1PHIA", "TPROJ_L2D1A_D3PHID", "TPROJ_D1D2D_L1PHIE", "TPROJ_D1D2A_L1PHIE", "TPROJ_L2L3A_D4PHIC", + "TPROJ_D1D2C_L1PHIC", "TPROJ_D1D2D_L1PHIC", "TPROJ_L1L2C_D2PHIC", "TPROJ_L1L2A_D2PHIC", "TPROJ_L1L2B_D2PHIC", + "TPROJ_D1D2A_L2PHID", "TPROJ_D1D2B_L2PHID", "TPROJ_L1D1G_D5PHIB", "TPROJ_L1L2A_L3PHIB", "TPROJ_L1D1G_D3PHIB", + "TPROJ_D3D4D_D5PHIB", "TPROJ_L2D1D_D2PHIA", "TPROJ_L1D1H_D3PHIB", "TPROJ_L3L4A_D2PHIC", "TPROJ_L5L6B_L1PHIH", + "TPROJ_L5L6A_L1PHIH", "TPROJ_D3D4C_D1PHIA", "TPROJ_D3D4D_D1PHIA", "TPROJ_D1D2A_L1PHIG", "TPROJ_D1D2B_L1PHIG", + "TPROJ_L1L2L_D3PHIB", "TPROJ_L5L6A_L1PHIF", "TPROJ_L5L6A_L4PHIC", "TPROJ_L1D1B_D2PHID", "TPROJ_L1D1A_D2PHID", + "TPROJ_L1D1D_D2PHID", "TPROJ_L1D1C_D2PHID", "TPROJ_L5L6D_L4PHIA", "TPROJ_L5L6C_L4PHIA", "TPROJ_L5L6D_L1PHIB", + "TPROJ_L5L6C_L1PHIB", "TPROJ_L1L2D_D2PHID", "TPROJ_L2D1C_D3PHIA", "TPROJ_L2D1D_D3PHIA", "TPROJ_L1L2D_D1PHID", + "TPROJ_L1L2E_D1PHID", "TPROJ_L5L6D_L1PHID", "TPROJ_L2D1C_D2PHIA", "TPROJ_L2D1A_L1PHIE", "TPROJ_L2L3D_D2PHIB", + "TPROJ_L1L2A_D4PHIC", "TPROJ_L2L3D_L1PHIB", "TPROJ_L1L2C_D4PHIC", "TPROJ_L2L3C_L1PHIB", "TPROJ_L2L3A_L1PHIE", + "TPROJ_L2L3D_L1PHIE", "TPROJ_L5L6D_L3PHIB", "TPROJ_D1D2D_L2PHIB", "TPROJ_D3D4D_D2PHIA", "TPROJ_L2D1C_L1PHIC", + "TPROJ_L2D1D_L1PHIC", "TPROJ_L3L4B_D2PHID", "TPROJ_L3L4A_D2PHID", "TPROJ_L2D1C_L1PHIA", "TPROJ_L2D1D_L1PHIA", + "TPROJ_L2D1B_L1PHIA", "TPROJ_L3L4D_L1PHIC", "TPROJ_L3L4C_L1PHIC", "TPROJ_L1L2K_D3PHIB", "TPROJ_L1L2J_D3PHIB", + "TPROJ_L3L4C_L1PHIH", "TPROJ_L2L3A_D3PHIC", "TPROJ_L2L3B_L1PHIA", "TPROJ_L2L3C_L1PHIA", "TPROJ_L2L3D_L1PHIA", + "TPROJ_L1D1A_D2PHIC", "TPROJ_L1D1B_D2PHIC", "TPROJ_L2L3C_L1PHIC", "TPROJ_L2L3D_L1PHIC", "TPROJ_L1L2L_D2PHIB", + "TPROJ_L1L2J_D2PHIB", "TPROJ_L1L2K_D2PHIB", "TPROJ_L2D1D_L1PHIE", "TPROJ_L1L2G_L6PHIA", "TPROJ_L2D1A_L1PHIG", + "TPROJ_L2D1B_L1PHIG"}; for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) { std::vector >& TCs = TC_[iseed]; @@ -404,15 +451,9 @@ void TrackletConfigBuilder::buildProjections() { if (phiRange.first < allStubs_[ilayer][iReg].second && phiRange.second > allStubs_[ilayer][iReg].first) { std::pair tmp(iseed, iTC); //seedindex and TC string projName = TPROJName(iseed, iTC, ilayer, iReg); - if (combinedmodules_) { - if (emptyProjCombined.find(projName) == emptyProjCombined.end()) { - projections_[ilayer][iReg].push_back(tmp); - } - } else { - if (emptyProjStandard.find(projName) == emptyProjStandard.end()) { - projections_[ilayer][iReg].push_back(tmp); - } - } + if (emptyProjCombined.find(projName) == emptyProjCombined.end()) { + projections_[ilayer][iReg].push_back(tmp); + } } } } @@ -438,6 +479,13 @@ double TrackletConfigBuilder::rinv(double r1, double phi1, double r2, double phi return 2 * sin(deltaphi) / sqrt(r2 * r2 + r1 * r1 - 2 * r1 * r2 * cos(deltaphi)); } +std::string TrackletConfigBuilder::iTBStr(unsigned int iTB) const { + static std::string name[2] = {"AAAA", "BBBB"}; + + assert(iTB < 2); + return name[iTB]; +} + std::string TrackletConfigBuilder::iSeedStr(unsigned int iSeed) const { static std::string name[8] = {"L1L2", "L2L3", "L3L4", "L5L6", "D1D2", "D3D4", "L1D1", "L2D1"}; @@ -460,6 +508,61 @@ std::string TrackletConfigBuilder::iTCStr(unsigned int iTC) const { return name[iTC]; } +std::string TrackletConfigBuilder::iMergedTCStr(unsigned int iSeed, unsigned int iTC) { + + assert(iSeed<8); + + if (iSeed == 0) { + static std::string name[6] = {"ABC", "DE", "F", "G", "HI", "JKL"}; + assert(iTC<6); + return name[iTC]; + } + + if (iSeed == 1) { + static std::string name[1] = {"ABCD"}; + assert(iTC<1); + return name[iTC]; + } + + if (iSeed == 2) { + static std::string name[2] = {"AB", "CD"}; + assert(iTC<2); + return name[iTC]; + } + + if (iSeed == 3) { + static std::string name[1] = {"ABCD"}; + assert(iTC<1); + return name[iTC]; + } + + if (iSeed == 4) { + static std::string name[1] = {"ABCD"}; + assert(iTC<1); + return name[iTC]; + } + + if (iSeed == 5) { + static std::string name[1] = {"ABCD"}; + assert(iTC<1); + return name[iTC]; + } + + if (iSeed == 6) { + static std::string name[2] = {"ABCD", "EFGH"}; + assert(iTC<2); + return name[iTC]; + } + + if (iSeed == 7) { + static std::string name[1] = {"ABCD"}; + assert(iTC<1); + return name[iTC]; + } + + return "Error";; +} + std::string TrackletConfigBuilder::iRegStr(unsigned int iReg, unsigned int iSeed) const { static std::string name[8] = {"A", "B", "C", "D", "E", "F", "G", "H"}; @@ -480,11 +583,11 @@ std::string TrackletConfigBuilder::iRegStr(unsigned int iReg, unsigned int iSeed } std::string TrackletConfigBuilder::TCName(unsigned int iSeed, unsigned int iTC) const { - if (combinedmodules_) { - return "TP_" + iSeedStr(iSeed) + iTCStr(iTC); - } else { - return "TC_" + iSeedStr(iSeed) + iTCStr(iTC); - } + return "TP_" + iSeedStr(iSeed) + iTCStr(iTC); +} + +std::string TrackletConfigBuilder::PCName(unsigned int iSeed, unsigned int iMergedTC) const { + return "PC_" + iSeedStr(iSeed) + iMergedTCStr(iSeed,iMergedTC); } std::string TrackletConfigBuilder::LayerName(unsigned int ilayer) { @@ -498,71 +601,88 @@ std::string TrackletConfigBuilder::TPROJName(unsigned int iSeed, return "TPROJ_" + iSeedStr(iSeed) + iTCStr(iTC) + "_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); } -std::string TrackletConfigBuilder::PRName(unsigned int ilayer, unsigned int ireg) const { - if (combinedmodules_) { - return "MP_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); - } else { - return "PR_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); - } +std::string TrackletConfigBuilder::MPROJName(unsigned int iSeed, + unsigned int iTC, + unsigned int ilayer, + unsigned int ireg) const { + return "MPROJ_" + iSeedStr(iSeed) + iMergedTCStr(iSeed,iTC) + "_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); +} + +std::string TrackletConfigBuilder::MPName(unsigned int ilayer, unsigned int ireg) const { + return "MP_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); } -void TrackletConfigBuilder::writeProjectionMemories(std::ostream& os, std::ostream& memories, std::ostream&) { - // Each TC (e.g. TC_L1L2D) writes a projection memory (TPROJ) for each layer the seed projects to, - // with name indicating the TC and which layer & phi region it projects to (e.g. TPROJ_L1L2D_L3PHIA). + +void TrackletConfigBuilder::writeMergedProjectionMemories(std::ostream& os, std::ostream& memories, std::ostream& process) { + // Writed the merged projection memories as produced by the ProjectionCalculator mdoels + // MPROJ_L1L2ABC_L3PHIA) indicating that TP_L1L2A, TP_L1L2B, and TP_L1L2C are merged together // - // Each PR (e.g. PR_L3PHIA) reads all TPROJ memories for the given layer & phi region. + + unsigned int nMergedTC[8] = {6, 1, 2, 1, 1, 1, 2, 1}; + + for (unsigned int iSeed = 0; iSeed < 8; iSeed++){ + unsigned int iTB = 0; + if ( iSeed==2 || iSeed==4 || iSeed==5 || iSeed==6 ) { + iTB = 1; + } + for (unsigned int iPC = 0; iPC < nMergedTC[iSeed]; iPC++) { + process << "ProjectionCalculator: " << PCName(iSeed, iPC) << std::endl; + memories << "TrackletParameters: MPAR_" << iSeedStr(iSeed) << iMergedTCStr(iSeed,iPC) << " [73]" << std::endl; + os << "MPAR_"< " << PCName(iSeed, iPC) << ".tparout" + << " output=> TB_" < MPROJNames; for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { for (unsigned int ireg = 0; ireg < projections_[ilayer].size(); ireg++) { for (unsigned int imem = 0; imem < projections_[ilayer][ireg].size(); imem++) { unsigned int iSeed = projections_[ilayer][ireg][imem].first; unsigned int iTC = projections_[ilayer][ireg][imem].second; - if (combinedmodules_) { - if (duplicateMPs_) { - if ((settings_.layersDisksDuplicatedEqualProjBalance()[ilayer]) && (ireg == 1 || ireg == 2)) { - memories << "TrackletProjections: " + TPROJName(iSeed, iTC, ilayer, ireg) + " [54]" << std::endl; - if (imem < projections_[ilayer][ireg].size() / 2) { - os << TPROJName(iSeed, iTC, ilayer, ireg) << " input=> " << TCName(iSeed, iTC) << ".projout" - << LayerName(ilayer) << "PHI" << iTCStr(ireg) << " output=> " << PRName(ilayer, ireg) << ".projin" - << std::endl; - } else { - os << TPROJName(iSeed, iTC, ilayer, ireg) << " input=> " << TCName(iSeed, iTC) << ".projout" - << LayerName(ilayer) << "PHI" << iTCStr(ireg) << " output=> " << PRName(ilayer, ireg) + "_E" - << ".projin" // duplicate MPs denoted by extra _E - << std::endl; - } - } else if ((settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && (ireg == 1 || ireg == 2)) { - memories << "TrackletProjections: " + TPROJName(iSeed, iTC, ilayer, ireg) + " [54]" << std::endl; - if (imem < 4 || - imem > - 9) { // FIXME need to replace magic numbers, corresponds to allowing MP1 4 L1L2 TCs, 3 L5L6 TCs, MP2 3 L1L2 3 L3L4 TCs - os << TPROJName(iSeed, iTC, ilayer, ireg) << " input=> " << TCName(iSeed, iTC) << ".projout" - << LayerName(ilayer) << "PHI" << iTCStr(ireg) << " output=> " << PRName(ilayer, ireg) << ".projin" - << std::endl; - } else { - os << TPROJName(iSeed, iTC, ilayer, ireg) << " input=> " << TCName(iSeed, iTC) << ".projout" - << LayerName(ilayer) << "PHI" << iTCStr(ireg) << " output=> " << PRName(ilayer, ireg) + "_E" - << ".projin" // duplicate MPs - << std::endl; - } - } else { - memories << "TrackletProjections: " + TPROJName(iSeed, iTC, ilayer, ireg) + " [54]" << std::endl; - os << TPROJName(iSeed, iTC, ilayer, ireg) << " input=> " << TCName(iSeed, iTC) << ".projout" - << LayerName(ilayer) << "PHI" << iTCStr(ireg) << " output=> " << PRName(ilayer, ireg) << ".projin" - << std::endl; - } - } else { // non-duplicate MPs configuration - memories << "TrackletProjections: " + TPROJName(iSeed, iTC, ilayer, ireg) + " [54]" << std::endl; - os << TPROJName(iSeed, iTC, ilayer, ireg) << " input=> " << TCName(iSeed, iTC) << ".projout" - << LayerName(ilayer) << "PHI" << iTCStr(ireg) << " output=> " << PRName(ilayer, ireg) << ".projin" - << std::endl; - } - } else { // non-combined modules - memories << "TrackletProjections: " + TPROJName(iSeed, iTC, ilayer, ireg) + " [54]" << std::endl; - os << TPROJName(iSeed, iTC, ilayer, ireg) << " input=> " << TCName(iSeed, iTC) << ".projout" - << LayerName(ilayer) << "PHI" << iTCStr(ireg) << " output=> " << PRName(ilayer, ireg) << ".projin" - << std::endl; - } + for (unsigned int iMergedTC = 0 ; iMergedTC " << PCName(iSeed, iMergedTC) << ".projout" + //<< LayerName(ilayer) << "PHI" << iTCStr(ireg) + << " output=> " << MPName(ilayer, ireg) << "_E.projin" + << std::endl; + } else { + memories << "TrackletProjections: " + MPROJName(iSeed, iMergedTC, ilayer, ireg) + " [54]" << std::endl; + os << MPROJName(iSeed, iMergedTC, ilayer, ireg) << " input=> " << PCName(iSeed, iMergedTC) << ".projout" + //<< LayerName(ilayer) << "PHI" << iTCStr(ireg) + << " output=> " << MPName(ilayer, ireg) << ".projin" + << std::endl; + } + } else { + memories << "TrackletProjections: " + MPROJName(iSeed, iMergedTC, ilayer, ireg) + " [54]" << std::endl; + os << MPROJName(iSeed, iMergedTC, ilayer, ireg) << " input=> " << PCName(iSeed, iMergedTC) << ".projout" + //<< LayerName(ilayer) << "PHI" << iTCStr(ireg) + << " output=> " << MPName(ilayer, ireg) << ".projin" + << std::endl; + } + } } } } @@ -658,247 +778,6 @@ std::string TrackletConfigBuilder::STName(unsigned int l1, iRegStr(ireg3, iseed) + "_" + numStr(count); } -void TrackletConfigBuilder::writeSPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { - // Each TE reads one VM in two seed layers, finds stub pairs & writes to a StubPair ("SP") memory. - // - // Each TC reads several StubPair (SP) memories, each containing a pair of VMs of two seeding layers. - // Several TC are created for each layer pair, and the SP distributed between them. - // If TC name is TC_L1L2C, "C" indicates this is the 3rd TC in L1L2. - - if (combinedmodules_) - return; - - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { - for (unsigned int iTE = 0; iTE < TC_[iSeed][iTC].size(); iTE++) { - unsigned int theTE = TC_[iSeed][iTC][iTE]; - - unsigned int TE1 = TE_[iSeed][theTE].first; - unsigned int TE2 = TE_[iSeed][theTE].second; - - unsigned int l1 = seedLayers(iSeed).first; - unsigned int l2 = seedLayers(iSeed).second; - - memories << "StubPairs: " - << SPName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed) << " [12]" - << std::endl; - modules << "TrackletEngine: " - << TEName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed) << std::endl; - - os << SPName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed) << " input=> " - << TEName(l1, TE1 / NVMTE_[iSeed].first, TE1, l2, TE2 / NVMTE_[iSeed].second, TE2, iSeed) - << ".stubpairout output=> " << TCName(iSeed, iTC) << ".stubpairin" << std::endl; - } - } - } -} - -void TrackletConfigBuilder::writeSPDMemories(std::ostream& wires, std::ostream& memories, std::ostream& modules) { - // Similar to writeSPMemories, but for displaced (=extended) tracking, - // with seeds based on triplets of layers. - - if (!extended_) - return; - - vector stubTriplets[N_SEED]; - - for (unsigned int iSeed = N_SEED_PROMPT; iSeed < N_SEED; iSeed++) { - int layerdisk1 = settings_.seedlayers(0, iSeed); - int layerdisk2 = settings_.seedlayers(1, iSeed); - int layerdisk3 = settings_.seedlayers(2, iSeed); - - unsigned int nallstub1 = settings_.nallstubs(layerdisk1); - unsigned int nallstub2 = settings_.nallstubs(layerdisk2); - unsigned int nallstub3 = settings_.nallstubs(layerdisk3); - - unsigned int nvm1 = settings_.nvmte(0, iSeed); - unsigned int nvm2 = settings_.nvmte(1, iSeed); - unsigned int nvm3 = settings_.nvmte(2, iSeed); - - int count = 0; - for (unsigned int ireg1 = 0; ireg1 < nallstub1; ireg1++) { - for (unsigned int ireg2 = 0; ireg2 < nallstub2; ireg2++) { - for (unsigned int ireg3 = 0; ireg3 < nallstub3; ireg3++) { - count++; - memories << "StubTriplets: " << STName(layerdisk1, ireg1, layerdisk2, ireg2, layerdisk3, ireg3, iSeed, count) - << " [18]" << std::endl; - stubTriplets[iSeed].push_back(STName(layerdisk1, ireg1, layerdisk2, ireg2, layerdisk3, ireg3, iSeed, count)); - } - } - } - - for (unsigned int ireg1 = 0; ireg1 < nallstub1; ireg1++) { - for (unsigned int ivm1 = 0; ivm1 < nvm1; ivm1++) { - for (unsigned int ireg2 = 0; ireg2 < nallstub2; ireg2++) { - for (unsigned int ivm2 = 0; ivm2 < nvm2; ivm2++) { - int count = 0; - - modules << "TrackletEngineDisplaced: " - << TEDName(layerdisk1, ireg1, ireg1 * nvm1 + ivm1, layerdisk2, ireg2, ireg2 * nvm2 + ivm2, iSeed) - << std::endl; - - for (unsigned int ireg3 = 0; ireg3 < nallstub3; ireg3++) { - for (unsigned int ivm3 = 0; ivm3 < nvm3; ivm3++) { - count++; - - memories << "StubPairsDisplaced: " - << SPDName(layerdisk1, - ireg1, - ireg1 * nvm1 + ivm1, - layerdisk2, - ireg2, - ireg2 * nvm2 + ivm2, - layerdisk3, - ireg3, - ireg3 * nvm3 + ivm3, - iSeed) - << " [12]" << std::endl; - - modules << "TripletEngine: " << TREName(layerdisk1, ireg1, layerdisk2, ireg2, iSeed, count) - << std::endl; - - wires << SPDName(layerdisk1, - ireg1, - ireg1 * nvm1 + ivm1, - layerdisk2, - ireg2, - ireg2 * nvm2 + ivm2, - layerdisk3, - ireg3, - ireg3 * nvm3 + ivm3, - iSeed) - << " input=> " - << TEDName(layerdisk1, ireg1, ireg1 * nvm1 + ivm1, layerdisk2, ireg2, ireg2 * nvm2 + ivm2, iSeed) - << ".stubpairout output=> " << TREName(layerdisk1, ireg1, layerdisk2, ireg2, iSeed, count) - << ".stubpair" - << "1" - << "in" << std::endl; - } - } - } - } - } - } - - unsigned int nTC = 10; - for (unsigned int itc = 0; itc < nTC; itc++) { - for (int iproj = 0; iproj < 4; iproj++) { - int ilay = settings_.projlayers(iSeed, iproj); - if (ilay > 0) { - unsigned int nallstub = settings_.nallstubs(ilay - 1); - for (unsigned int ireg = 0; ireg < nallstub; ireg++) { - memories << "TrackletProjections: " << TPROJName(layerdisk1, layerdisk2, layerdisk3, itc, ilay - 1, ireg) - << " [54]" << std::endl; - } - } - - int idisk = settings_.projdisks(iSeed, iproj); - if (idisk > 0) { - unsigned int nallstub = settings_.nallstubs(idisk + 5); - for (unsigned int ireg = 0; ireg < nallstub; ireg++) { - memories << "TrackletProjections: " << TPROJName(layerdisk1, layerdisk2, layerdisk3, itc, idisk + 5, ireg) - << " [54]" << std::endl; - - wires << TPROJName(layerdisk1, layerdisk2, layerdisk3, itc, idisk + 5, ireg) << " input=> " - << TCDName(layerdisk1, layerdisk2, layerdisk3, itc) << ".projout" << LayerName(idisk + 1) << "PHI" - << iTCStr(ireg) << " output=> " - << "PR_" << LayerName(idisk + 1) << "PHI" << iTCStr(ireg) << ".projin" << std::endl; - } - } - } - - memories << "TrackletParameters: " << TParName(layerdisk1, layerdisk2, layerdisk3, itc) << " [56]" << std::endl; - - modules << "TrackletCalculatorDisplaced: " << TCDName(layerdisk1, layerdisk2, layerdisk3, itc) << std::endl; - } - - unsigned int nST = stubTriplets[iSeed].size(); - for (unsigned int iST = 0; iST < nST; iST++) { - unsigned int iTC = (iST * nTC) / nST; - assert(iTC < nTC); - string stname = stubTriplets[iSeed][iST]; - string trename = "TRE_" + stname.substr(3, 6) + "_"; - unsigned int stlen = stname.size(); - if (stname[stlen - 2] == '_') - trename += stname.substr(stlen - 1, 1); - if (stname[stlen - 3] == '_') - trename += stname.substr(stlen - 2, 2); - wires << stname << " input=> " << trename << ".stubtripout output=> " - << TCDName(layerdisk1, layerdisk2, layerdisk3, iTC) << ".stubtriplet" << ((iST * nTC) % nST) << "in" - << std::endl; - } - - modules << "FitTrack: " << FTName(layerdisk1, layerdisk2, layerdisk3) << std::endl; - } -} - -void TrackletConfigBuilder::writeAPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { - // The AllProjection memories (e.g. AP_L2PHIA) contain the intercept point of the projection to - // a layer. Each is written by one PR module of similar name (e.g. PR_L2PHIA), and read by - // a MC (e.g. MC_L2PHIA). - - if (combinedmodules_) - return; - - for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { - for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { - memories << "AllProj: AP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " [56]" << std::endl; - modules << "ProjectionRouter: PR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - - os << "AP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> PR_" << LayerName(ilayer) << "PHI" - << iTCStr(iReg) << ".allprojout output=> MC_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allprojin" - << std::endl; - } - } -} - -void TrackletConfigBuilder::writeCMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { - // The CandidateMatch memory (e.g. CM_L1PHIA1) are each written by ME module of similar name - // (e.g. ME_L1PHIA1) and contain indices of matching (tracklet projections,stubs) in the specified - // VM region. - // All CM memories in a given phi region (e.g. L1PHIA) are read by a MC module (e.g. MC_L1PHIA) that - // does more precise matching. - - if (combinedmodules_) - return; - - for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { - for (unsigned int iME = 0; iME < NVMME_[ilayer] * NRegions_[ilayer]; iME++) { - memories << "CandidateMatch: CM_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 - << " [12]" << std::endl; - modules << "MatchEngine: ME_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 - << std::endl; - - os << "CM_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << " input=> ME_" - << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << ".matchout output=> MC_" - << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << ".matchin" << std::endl; - } - } -} - -void TrackletConfigBuilder::writeVMPROJMemories(std::ostream& os, std::ostream& memories, std::ostream&) { - // The VMPROJ memories (e.g. VMPROJ_L2PHIA1) written by a PR module each correspond to projections to - // a single VM region in a layer. Each is filled by the PR using all projections (TPROJ) to this VM - // from different seeding layers. - // - // Each VMPROJ memory is read by a ME module, which matches the projection to stubs. - - if (combinedmodules_) - return; - - for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { - for (unsigned int iME = 0; iME < NVMME_[ilayer] * NRegions_[ilayer]; iME++) { - memories << "VMProjections: VMPROJ_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 - << " [13]" << std::endl; - - os << "VMPROJ_" << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << " input=> PR_" - << LayerName(ilayer) << "PHI" << iTCStr(iME / NVMME_[ilayer]) << ".vmprojout" - << "PHI" << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << " output=> ME_" << LayerName(ilayer) << "PHI" - << iTCStr(iME / NVMME_[ilayer]) << iME + 1 << ".vmprojin" << std::endl; - } - } -} - void TrackletConfigBuilder::writeFMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { // All FullMatch (e.g. FM_L2L3_L1PHIA) memories corresponding to a matches between stubs & tracklets // in a given region (e.g. L1PHIA) from all seeding layers, are written by a MC module (e.g. MC_L1PHIA). @@ -906,70 +785,28 @@ void TrackletConfigBuilder::writeFMMemories(std::ostream& os, std::ostream& memo // All FullMatch memories corresponding to a given seed pair are read by the TrackBuilder (e.g. FT_L1L2), // which checks if the track has stubs in enough layers. - if (combinedmodules_) { - for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { - for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { - if (duplicateMPs_) { - if ((settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || - settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && - (iReg == 1 || iReg == 2)) { // regions with worst truncation - modules << "MatchProcessor: MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - modules << "MatchProcessor: MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) + "_E" << std::endl; - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - if (matchport_[iSeed][ilayer] == -1) - continue; - memories << "FullMatch: FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) - << " [36]" << std::endl; - memories << "FullMatch: FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" - << iTCStr(iReg) + "_E" - << " [36]" << std::endl; - os << "FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> MP_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".matchout1 output=> FT_" << iSeedStr(iSeed) - << ".fullmatch" << matchport_[iSeed][ilayer] << "in" << iReg + 1 << std::endl; - os << "FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) + "_E" - << " input=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) + "_E" - << ".matchout1 output=> FT_" << iSeedStr(iSeed) << ".fullmatch" << matchport_[iSeed][ilayer] << "in" - << iReg + 1 << std::endl; - } - } else { - modules << "MatchProcessor: MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - if (matchport_[iSeed][ilayer] == -1) - continue; - memories << "FullMatch: FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) - << " [36]" << std::endl; - os << "FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> MP_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".matchout1 output=> FT_" << iSeedStr(iSeed) - << ".fullmatch" << matchport_[iSeed][ilayer] << "in" << iReg + 1 << std::endl; - } - } - } else { // non-duplicate MPs configuration - modules << "MatchProcessor: MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - if (matchport_[iSeed][ilayer] == -1) - continue; - memories << "FullMatch: FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) - << " [36]" << std::endl; - os << "FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> MP_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".matchout1 output=> FT_" << iSeedStr(iSeed) - << ".fullmatch" << matchport_[iSeed][ilayer] << "in" << iReg + 1 << std::endl; - } - } + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + modules << "MatchProcessor: MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; + for (unsigned int iTB = 0; iTB < N_TB; iTB++) { + memories << "FullMatch: FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) + << " [36]" << std::endl; + os << "FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> MP_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".matchout" << iTB << " output=> TB_" << iTBStr(iTB) + << ".fullmatch" << ilayer << "in" << iReg + 1 << std::endl; } - } - } else { - for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { - for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { - modules << "MatchCalculator: MC_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - if (matchport_[iSeed][ilayer] == -1) - continue; - memories << "FullMatch: FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) - << " [36]" << std::endl; - os << "FM_" << iSeedStr(iSeed) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> MC_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".matchout1 output=> FT_" << iSeedStr(iSeed) - << ".fullmatch" << matchport_[iSeed][ilayer] << "in" << iReg + 1 << std::endl; - } + //Write duplicate MPs + if (duplicateMPs_ && (settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || + settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && + (iReg == 1 || iReg == 2)) { // regions with worst truncation + modules << "MatchProcessor: MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) + "_E" << std::endl; + for (unsigned int iTB = 0; iTB < N_TB; iTB++) { + memories << "FullMatch: FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) + << "_E [36]" << std::endl; + os << "FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E input=> MP_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E.matchout" << iTB << " output=> TB_" << iTBStr(iTB) + << ".fullmatch" << ilayer << "in" << iReg + 1 << std::endl; + } } } } @@ -983,89 +820,65 @@ void TrackletConfigBuilder::writeASMemories(std::ostream& os, std::ostream& memo // an AS memory ("AS_L1PHIC"). // Multiple copies of each AS memory exist where several modules in chain want to read it. - if (combinedmodules_) { - //First write AS memories used by MatchProcessor - for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { - for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { - if (duplicateMPs_) { - if ((settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || - settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && - (iReg == 1 || iReg == 2)) { - memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " [42]" << std::endl; - memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2" - << " [42]" << std::endl; - if (combinedmodules_) { - modules << "VMRouterCM: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - } else { - modules << "VMRouter: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - } - os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; - os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) + "_E" - << ".allstubin" << std::endl; - } else { - memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " [42]" << std::endl; - if (combinedmodules_) { - modules << "VMRouterCM: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - } else { - modules << "VMRouter: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - } - os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; - } - } else { // non duplicate MPs configuration - memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " [42]" << std::endl; - if (combinedmodules_) { - modules << "VMRouterCM: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - } else { - modules << "VMRouter: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - } - os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; - } + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" + << " [42]" << std::endl; + memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2" + << " [42]" << std::endl; + modules << "VMRouterCM: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; + modules << "VMStubMERouter: VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; + os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" + << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> VMSMER_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; + os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2" + << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; + //Write duplicate MPs + if (duplicateMPs_ && (settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || + settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && (iReg == 1 || iReg == 2)) { + memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3" + << " [42]" << std::endl; + os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3" + << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E.allstubin" << std::endl; } } + } - //Next write AS memories used by TrackletProcessor - for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { - for (int iReg = 0; iReg < (int)NRegions_[ilayer]; iReg++) { - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - unsigned int l1 = seedLayers(iSeed).first; - unsigned int l2 = seedLayers(iSeed).second; + //Next write AS memories used by TrackletProcessor + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (int iReg = 0; iReg < (int)NRegions_[ilayer]; iReg++) { + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + unsigned int l1 = seedLayers(iSeed).first; + unsigned int l2 = seedLayers(iSeed).second; + + if (ilayer != l1 && ilayer != l2) + continue; - if (ilayer != l1 && ilayer != l2) - continue; + bool inner = ilayer == l1; - bool inner = ilayer == l1; + for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { + int nTCReg = TC_[iSeed].size() / NRegions_[l2]; - for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { - int nTCReg = TC_[iSeed].size() / NRegions_[l2]; + int iTCReg = iTC / nTCReg; - int iTCReg = iTC / nTCReg; + int jTCReg = iTC % nTCReg; - int jTCReg = iTC % nTCReg; + if (ilayer == l2) { + if (iTCReg != iReg) + continue; + } - if (ilayer == l2) { - if (iTCReg != iReg) - continue; - } + string ext = ""; - string ext = ""; + if (ilayer == l1) { + int ratio = NRegions_[l1] / NRegions_[l2]; + int min = iTCReg * ratio - 1 + jTCReg; + int max = (iTCReg + 1) * ratio - (nTCReg - jTCReg - 1); + if ((int)iReg < min || (int)iReg > max) + continue; - if (ilayer == l1) { - int ratio = NRegions_[l1] / NRegions_[l2]; - int min = iTCReg * ratio - 1 + jTCReg; - int max = (iTCReg + 1) * ratio - (nTCReg - jTCReg - 1); - if ((int)iReg < min || (int)iReg > max) - continue; if (max - min >= 2) { ext = "M"; @@ -1081,136 +894,84 @@ void TrackletConfigBuilder::writeASMemories(std::ostream& os, std::ostream& memo } } - if (max - min == 1) { - if (nTCReg == 2) { - assert(0); - if (jTCReg == 0) { - if (iReg == min) - ext = "R"; - if (iReg == max) - ext = "B"; - } - if (jTCReg == 1) { - if (iReg == min) - ext = "A"; - if (iReg == max) - ext = "L"; - } - } - if (nTCReg == 3) { - if (jTCReg == 0) { - if (iReg == min) - ext = "A"; - if (iReg == max) - ext = "F"; - } - if (jTCReg == 1) { - if (iReg == min) - ext = "E"; - if (iReg == max) - ext = "D"; - } - if (jTCReg == 2) { - if (iReg == min) - ext = "C"; - if (iReg == max) - ext = "B"; - } - } - } - assert(!ext.empty()); - } - - if (ext.empty()) { - ext = "_" + LayerName(l1) + iTCStr(iTC); - } - - if (iSeed < 4) { //Barrel seeding - ext = "_B" + ext; - } else if (iSeed > 5) { - ext = "_O" + ext; - } else { - ext = "_D" + ext; - } - - if (inner) { - memories << "AllInnerStubs: "; - } else { - memories << "AllStubs: "; - } - memories << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " [42]" << std::endl; - os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " input=> VMR_" << LayerName(ilayer) - << "PHI" << iTCStr(iReg) << ".all" << (inner ? "inner" : "") << "stubout output=> TP_" << iSeedStr(iSeed) - << iTCStr(iTC); - if (inner) { - os << ".innerallstubin" << std::endl; - } else { - os << ".outerallstubin" << std::endl; - } - } - } - } - } - - } else { - //First write AS memories used by MatchCalculator - for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { - for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { - memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " [42]" << std::endl; - if (combinedmodules_) { - modules << "VMRouterCM: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - } else { - modules << "VMRouter: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; - } - os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MC_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; - } - } - - //Next write AS memories used by TrackletCalculator - for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { - for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { - unsigned int nmem = 1; - - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - unsigned int l1 = seedLayers(iSeed).first; - unsigned int l2 = seedLayers(iSeed).second; - - if (ilayer != l1 && ilayer != l2) - continue; - - for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { - bool used = false; - // Each TC processes data from several TEs. - for (unsigned int iTE = 0; iTE < TC_[iSeed][iTC].size(); iTE++) { - unsigned int theTE = TC_[iSeed][iTC][iTE]; - - unsigned int TE1 = TE_[iSeed][theTE].first; // VM in inner/outer layer of this TE. - unsigned int TE2 = TE_[iSeed][theTE].second; - - if (l1 == ilayer && iReg == TE1 / NVMTE_[iSeed].first) - used = true; - if (l2 == ilayer && iReg == TE2 / NVMTE_[iSeed].second) - used = true; - } - - if (used) { - nmem++; // Another copy of memory - memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n" << nmem << " [42]" - << std::endl; - os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n" << nmem << " input=> VMR_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> TC_" << iSeedStr(iSeed) - << iTCStr(iTC); - if (ilayer == l1) { - os << ".innerallstubin" << std::endl; - } else { - os << ".outerallstubin" << std::endl; - } - } - } - } + //old code + /* + if (max - min >= 2) { + ext = "M"; + if (iReg == min) + ext = "R"; + if (iReg == max) + ext = "L"; + } + */ + + if (max - min == 1) { + if (nTCReg == 2) { + assert(0); + if (jTCReg == 0) { + if (iReg == min) + ext = "R"; + if (iReg == max) + ext = "B"; + } + if (jTCReg == 1) { + if (iReg == min) + ext = "A"; + if (iReg == max) + ext = "L"; + } + } + if (nTCReg == 3) { + if (jTCReg == 0) { + if (iReg == min) + ext = "A"; + if (iReg == max) + ext = "F"; + } + if (jTCReg == 1) { + if (iReg == min) + ext = "E"; + if (iReg == max) + ext = "D"; + } + if (jTCReg == 2) { + if (iReg == min) + ext = "C"; + if (iReg == max) + ext = "B"; + } + } + } + assert(!ext.empty()); + } + + if (ext.empty()) { + ext = "_" + LayerName(l1) + iTCStr(iTC); + } + + if (iSeed < 4) { //Barrel seeding + ext = "_B" + ext; + } else if (iSeed > 5) { + ext = "_O" + ext; + } else { + ext = "_D" + ext; + } + + if (inner) { + memories << "AllInnerStubs: "; + } else { + memories << "AllStubs: "; + } + memories << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " [42]" << std::endl; + os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " input=> VMR_" << LayerName(ilayer) + << "PHI" << iTCStr(iReg) << ".all" << (inner ? "inner" : "") << "stubout output=> TP_" << iSeedStr(iSeed) + << iTCStr(iTC); + if (inner) { + os << ".innerallstubin" << std::endl; + } else { + os << ".outerallstubin" << std::endl; + } + } } } } @@ -1223,142 +984,51 @@ void TrackletConfigBuilder::writeVMSMemories(std::ostream& os, std::ostream& mem // // Each TE reads one VMS memory in each seeding layer. - if (combinedmodules_) { - //First write VMS memories used by MatchProcessor - for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { - for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { - if (duplicateMPs_) { - if ((settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || - settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && - (iReg == 1 || iReg == 2)) { - memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1 [18]" << std::endl; - memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2 [18]" << std::endl; - os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutPHI" << iTCStr(iReg) - << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubin" << std::endl; - os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutPHI" << iTCStr(iReg) - << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) + "_E" - << ".vmstubin" << std::endl; - } else { - memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1 [18]" << std::endl; - os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutPHI" << iTCStr(iReg) - << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubin" << std::endl; - } - } else { // non duplicate MPs configuration - memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1 [18]" << std::endl; - os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutPHI" << iTCStr(iReg) - << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubin" << std::endl; - } - } + //First write VMS memories used by MatchProcessor + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2 [18]" << std::endl; + os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2" + << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout" + << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubin" << std::endl; + //Write duplicate MPs + if (duplicateMPs_ && (settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || + settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && + (iReg == 1 || iReg == 2)) { + memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3 [18]" << std::endl; + os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3" + << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout" + << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E.vmstubin" << std::endl; + } } + } - //Next write VMS memories used by TrackletProcessor - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - //FIXME - code could be cleaner - unsigned int l1 = seedLayers(iSeed).first; - unsigned int l2 = seedLayers(iSeed).second; - - unsigned int ilayer = seedLayers(iSeed).second; - - //for(unsigned int iReg=0;iReg VMR_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout_seed_" << iSeed << " output=> TP_" - << LayerName(l1) << LayerName(l2) << iTCStr(iReg * nTCReg + iTC) << ".outervmstubin" << std::endl; - } + for (unsigned int iReg = 0; iReg < NRegions_[l2]; iReg++) { + unsigned int nmem = 0; + //Hack since we use same module twice + if (iSeed == Seed::L2D1) { + nmem = 2; } - } - } else { - //First write VMS memories used by MatchEngine - for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { - for (unsigned int iVMME = 0; iVMME < NVMME_[ilayer] * NRegions_[ilayer]; iVMME++) { - unsigned int iReg = iVMME / NVMME_[ilayer]; - memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << "n1 [18]" - << std::endl; - os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << "n1" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutMEPHI" << iTCStr(iReg) - << iVMME + 1 << " output=> ME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << ".vmstubin" - << std::endl; - } - } - - // Next write VMS memories used by TrackletEngine - // Each TE processes one VM region in inner + outer seeding layers, and needs its own copy of input memories. - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - for (unsigned int innerouterseed = 0; innerouterseed < 2; innerouterseed++) { - //FIXME - code could be cleaner - unsigned int l1 = seedLayers(iSeed).first; - unsigned int l2 = seedLayers(iSeed).second; - - unsigned int NVMTE1 = NVMTE_[iSeed].first; - unsigned int NVMTE2 = NVMTE_[iSeed].second; - - unsigned int ilayer = l1; - unsigned int NVMTE = NVMTE1; - if (innerouterseed == 1) { - ilayer = l2; - NVMTE = NVMTE2; - } - - for (unsigned int iVMTE = 0; iVMTE < NVMTE * NRegions_[ilayer]; iVMTE++) { - unsigned int iReg = iVMTE / NVMTE; - - unsigned int nmem = 0; - - if (iSeed == Seed::L2D1) { - nmem = 4; - } - - for (unsigned int iTE = 0; iTE < TE_[iSeed].size(); iTE++) { - unsigned int TE1 = TE_[iSeed][iTE].first; // VM region in inner/outer layer of this TE - unsigned int TE2 = TE_[iSeed][iTE].second; - - bool used = false; - - if (innerouterseed == 0 && iVMTE == TE1) - used = true; - if (innerouterseed == 1 && iVMTE == TE2) - used = true; - - if (!used) - continue; - - string inorout = "I"; - if (innerouterseed == 1) - inorout = "O"; - - nmem++; // Add another copy of memory. - memories << "VMStubsTE: VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << iVMTE + 1 << "n" - << nmem << " [18]" << std::endl; - os << "VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << iVMTE + 1 << "n" << nmem - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstuboutTE" << inorout << "PHI" - << iRegStr(iReg, iSeed) << iVMTE + 1 << " output=> TE_" << LayerName(l1) << "PHI" - << iRegStr(TE1 / NVMTE1, iSeed) << TE1 + 1 << "_" << LayerName(l2) << "PHI" - << iRegStr(TE2 / NVMTE2, iSeed) << TE2 + 1; - if (innerouterseed == 0) { - os << ".innervmstubin" << std::endl; - } else { - os << ".outervmstubin" << std::endl; - } - } - } + for (unsigned iTC = 0; iTC < nTCReg; iTC++) { + nmem++; + memories << "VMStubsTE: VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << "n" << nmem + << " [18]" << std::endl; + os << "VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << "n" << nmem << " input=> VMR_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout_seed_" << iSeed << " output=> TP_" + << LayerName(l1) << LayerName(l2) << iTCStr(iReg * nTCReg + iTC) << ".outervmstubin" << std::endl; } } } @@ -1368,42 +1038,40 @@ void TrackletConfigBuilder::writeTPARMemories(std::ostream& os, std::ostream& me // Each TC module (e.g. TC_L1L2A) stores helix params in a single TPAR memory of similar name // (e.g. TPAR_L1L2A). The TPAR is subsequently read by the TrackBuilder (FT). - if (combinedmodules_) { - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - for (unsigned int iTP = 0; iTP < TC_[iSeed].size(); iTP++) { - memories << "TrackletParameters: TPAR_" << iSeedStr(iSeed) << iTCStr(iTP) << " [56]" << std::endl; - modules << "TrackletProcessor: TP_" << iSeedStr(iSeed) << iTCStr(iTP) << std::endl; - os << "TPAR_" << iSeedStr(iSeed) << iTCStr(iTP) << " input=> TP_" << iSeedStr(iSeed) << iTCStr(iTP) - << ".trackpar output=> FT_" << iSeedStr(iSeed) << ".tparin" << std::endl; - } - } - } else { - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { - memories << "TrackletParameters: TPAR_" << iSeedStr(iSeed) << iTCStr(iTC) << " [56]" << std::endl; - modules << "TrackletCalculator: TC_" << iSeedStr(iSeed) << iTCStr(iTC) << std::endl; - os << "TPAR_" << iSeedStr(iSeed) << iTCStr(iTC) << " input=> TC_" << iSeedStr(iSeed) << iTCStr(iTC) - << ".trackpar output=> FT_" << iSeedStr(iSeed) << ".tparin" << std::endl; + unsigned int nMergedTC[8] = {6, 1, 2, 1, 1, 1, 2, 1}; + + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + for (unsigned int iTP = 0; iTP < TC_[iSeed].size(); iTP++) { + memories << "TrackletParameters: TPAR_" << iSeedStr(iSeed) << iTCStr(iTP) << " [56]" << std::endl; + modules << "TrackletProcessor: TP_" << iSeedStr(iSeed) << iTCStr(iTP) << std::endl; + for (unsigned int iMergedTC = 0 ; iMergedTC TP_" << iSeedStr(iSeed) << iTCStr(iTP) + << ".trackpar output=> " << PCName(iSeed, iMergedTC) << ".tparin" << std::endl; + } } } } } void TrackletConfigBuilder::writeTFMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - memories << "TrackFit: TF_" << iSeedStr(iSeed) << " [126]" << std::endl; - modules << "FitTrack: FT_" << iSeedStr(iSeed) << std::endl; - os << "TF_" << iSeedStr(iSeed) << " input=> FT_" << iSeedStr(iSeed) << ".trackout output=> PD.trackin" << std::endl; + for (unsigned int iTB = 0; iTB < N_TB; iTB++) { + memories << "TrackFit: TF_" << iTBStr(iTB) << " [126]" << std::endl; + modules << "FitTrack: TB_" << iTBStr(iTB) << std::endl; + os << "TF_" << iTBStr(iTB) << " input=> TB_" << iTBStr(iTB) << ".trackout output=> PD.trackin" << std::endl; } } void TrackletConfigBuilder::writeCTMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { modules << "PurgeDuplicate: PD" << std::endl; - for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - memories << "CleanTrack: CT_" << iSeedStr(iSeed) << " [126]" << std::endl; - os << "CT_" << iSeedStr(iSeed) << " input=> PD.trackout output=>" << std::endl; - } + memories << "CleanTrack: CT_AAAA" << " [126]" << std::endl; + os << "CT_AAAA" << " input=> PD.trackout output=>" << std::endl; + + memories << "CleanTrack: CT_BBBB" << " [126]" << std::endl; + os << "CT_BBBB" << " input=> PD.trackout output=>" << std::endl; + } void TrackletConfigBuilder::writeILMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { @@ -1488,13 +1156,8 @@ void TrackletConfigBuilder::writeAll(std::ostream& wires, std::ostream& memories writeILMemories(wires, memories, modules); writeASMemories(wires, memories, modules); writeVMSMemories(wires, memories, modules); - writeSPMemories(wires, memories, modules); - writeSPDMemories(wires, memories, modules); - writeProjectionMemories(wires, memories, modules); + writeMergedProjectionMemories(wires, memories, modules); writeTPARMemories(wires, memories, modules); - writeVMPROJMemories(wires, memories, modules); - writeAPMemories(wires, memories, modules); - writeCMMemories(wires, memories, modules); writeFMMemories(wires, memories, modules); writeTFMemories(wires, memories, modules); writeCTMemories(wires, memories, modules); diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc deleted file mode 100644 index 4510ce2079561..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc +++ /dev/null @@ -1,230 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h" -#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" -#include "L1Trigger/TrackFindingTracklet/interface/Util.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" - -#include - -using namespace trklet; -using namespace std; - -TrackletEngine::TrackletEngine(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), innerptlut_(settings), outerptlut_(settings) { - stubpairs_ = nullptr; - innervmstubs_ = nullptr; - outervmstubs_ = nullptr; - - initLayerDisksandISeed(layerdisk1_, layerdisk2_, iSeed_); - - innerphibits_ = settings.nfinephi(0, iSeed_); - outerphibits_ = settings.nfinephi(1, iSeed_); -} - -void TrackletEngine::addOutput(MemoryBase* memory, string output) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " - << output; - } - if (output == "stubpairout") { - StubPairsMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - stubpairs_ = tmp; - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; -} - -void TrackletEngine::addInput(MemoryBase* memory, string input) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " - << input; - } - if (input == "innervmstubin") { - VMStubsTEMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - innervmstubs_ = tmp; - setVMPhiBin(); - return; - } - if (input == "outervmstubin") { - VMStubsTEMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - outervmstubs_ = tmp; - setVMPhiBin(); - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; -} - -void TrackletEngine::execute() { - if (!settings_.useSeed(iSeed_)) - return; - - unsigned int countall = 0; - unsigned int countpass = 0; - - assert(innervmstubs_ != nullptr); - assert(outervmstubs_ != nullptr); - - for (unsigned int i = 0; i < innervmstubs_->nVMStubs(); i++) { - const VMStubTE& innervmstub = innervmstubs_->getVMStubTE(i); - FPGAWord lookupbits = innervmstub.vmbits(); - - unsigned int nbits = 7; - if (iSeed_ == 4 || iSeed_ == 5) - nbits = 6; - int rzdiffmax = lookupbits.bits(nbits, lookupbits.nbits() - nbits); - int rzbinfirst = lookupbits.bits(0, 3); - int start = lookupbits.bits(4, nbits - 4); - int next = lookupbits.bits(3, 1); - - if ((iSeed_ == 4 || iSeed_ == 5) && innervmstub.stub()->disk().value() < 0) { //TODO - need to store negative disk - start += 4; - } - int last = start + next; - - for (int ibin = start; ibin <= last; ibin++) { - for (unsigned int j = 0; j < outervmstubs_->nVMStubsBinned(ibin); j++) { - if (countall >= settings_.maxStep("TE")) - break; - countall++; - const VMStubTE& outervmstub = outervmstubs_->getVMStubTEBinned(ibin, j); - - int rzbin = outervmstub.vmbits().bits(0, N_RZBITS); - - FPGAWord iphiinnerbin = innervmstub.finephi(); - FPGAWord iphiouterbin = outervmstub.finephi(); - - unsigned int index = (iphiinnerbin.value() << outerphibits_) + iphiouterbin.value(); - - if (iSeed_ >= 4) { //Also use r-position - - int nrbits = 3; // Number of bits used for r position in disk LUT - int ibinmask = (1 << (nrbits - 1)) - 1; // Mask of two least significant bits - - int ir = ((ibin & ibinmask) << 1) + (rzbin >> (N_RZBITS - 1)); - index += (ir << (outerphibits_ + innerphibits_)); - } - - if (start != ibin) - rzbin += (1 << N_RZBITS); - if ((rzbin < rzbinfirst) || (rzbin - rzbinfirst > rzdiffmax)) { - continue; - } - - FPGAWord innerbend = innervmstub.bend(); - FPGAWord outerbend = outervmstub.bend(); - - int ptinnerindex = (index << innerbend.nbits()) + innerbend.value(); - int ptouterindex = (index << outerbend.nbits()) + outerbend.value(); - - if (!(innerptlut_.lookup(ptinnerindex) && outerptlut_.lookup(ptouterindex))) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " - << settings_.benddecode( - innervmstub.bend().value(), layerdisk1_, innervmstub.isPSmodule()) - << " " - << settings_.benddecode( - outervmstub.bend().value(), layerdisk2_, outervmstub.isPSmodule()); - } - continue; - } - - if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << "Adding stub pair in " << getName(); - - assert(stubpairs_ != nullptr); - stubpairs_->addStubPair(innervmstub, outervmstub); - countpass++; - } - } - } - - if (settings_.writeMonitorData("TE")) { - globals_->ofstream("trackletengine.txt") << getName() << " " << countall << " " << countpass << endl; - } -} - -void TrackletEngine::setVMPhiBin() { - if (innervmstubs_ == nullptr || outervmstubs_ == nullptr) - return; - - innervmstubs_->setother(outervmstubs_); - outervmstubs_->setother(innervmstubs_); - - double innerphimin, innerphimax; - innervmstubs_->getPhiRange(innerphimin, innerphimax, iSeed_, 0); - - double outerphimin, outerphimax; - outervmstubs_->getPhiRange(outerphimin, outerphimax, iSeed_, 1); - - string innermem = innervmstubs_->getName().substr(6); - string outermem = outervmstubs_->getName().substr(6); - - innerptlut_.initteptlut(true, - false, - iSeed_, - layerdisk1_, - layerdisk2_, - innerphibits_, - outerphibits_, - innerphimin, - innerphimax, - outerphimin, - outerphimax, - innermem, - outermem); - - outerptlut_.initteptlut(false, - false, - iSeed_, - layerdisk1_, - layerdisk2_, - innerphibits_, - outerphibits_, - innerphimin, - innerphimax, - outerphimin, - outerphimax, - innermem, - outermem); - - TrackletLUT innertememlut(settings_); - TrackletLUT outertememlut(settings_); - - innertememlut.initteptlut(true, - true, - iSeed_, - layerdisk1_, - layerdisk2_, - innerphibits_, - outerphibits_, - innerphimin, - innerphimax, - outerphimin, - outerphimax, - innermem, - outermem); - - outertememlut.initteptlut(false, - true, - iSeed_, - layerdisk1_, - layerdisk2_, - innerphibits_, - outerphibits_, - innerphimin, - innerphimax, - outerphimin, - outerphimax, - innermem, - outermem); - - innervmstubs_->setbendtable(innertememlut); - outervmstubs_->setbendtable(outertememlut); -} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc deleted file mode 100644 index 927cd2b43505a..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc +++ /dev/null @@ -1,422 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" -#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" - -using namespace std; -using namespace trklet; - -TrackletEngineDisplaced::TrackletEngineDisplaced(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global) { - stubpairs_.clear(); - firstvmstubs_.clear(); - secondvmstubs_ = nullptr; - layer1_ = 0; - layer2_ = 0; - disk1_ = 0; - disk2_ = 0; - string name1 = name.substr(1); //this is to correct for "TED" having one more letter then "TE" - if (name1[3] == 'L') { - layer1_ = name1[4] - '0'; - } - if (name1[3] == 'D') { - disk1_ = name1[4] - '0'; - } - if (name1[11] == 'L') { - layer2_ = name1[12] - '0'; - } - if (name1[11] == 'D') { - disk2_ = name1[12] - '0'; - } - if (name1[12] == 'L') { - layer2_ = name1[13] - '0'; - } - if (name1[12] == 'D') { - disk2_ = name1[13] - '0'; - } - - iSeed_ = -1; - if (layer1_ == 3 && layer2_ == 4) - iSeed_ = 8; - if (layer1_ == 5 && layer2_ == 6) - iSeed_ = 9; - if (layer1_ == 2 && layer2_ == 3) - iSeed_ = 10; - if (disk1_ == 1 && disk2_ == 2) - iSeed_ = 11; - - firstphibits_ = settings_.nfinephi(0, iSeed_); - secondphibits_ = settings_.nfinephi(1, iSeed_); -} - -TrackletEngineDisplaced::~TrackletEngineDisplaced() { table_.clear(); } - -void TrackletEngineDisplaced::addOutput(MemoryBase* memory, string output) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " - << output; - } - if (output == "stubpairout") { - StubPairsMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - stubpairs_.push_back(tmp); - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; -} - -void TrackletEngineDisplaced::addInput(MemoryBase* memory, string input) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " - << input; - } - if (input == "firstvmstubin") { - VMStubsTEMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - firstvmstubs_.push_back(tmp); - return; - } - if (input == "secondvmstubin") { - VMStubsTEMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - secondvmstubs_ = tmp; - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; -} - -void TrackletEngineDisplaced::execute() { - if (!settings_.useSeed(iSeed_)) - return; - - if (table_.empty() && (settings_.enableTripletTables() && !settings_.writeTripletTables())) - readTables(); - - unsigned int countall = 0; - unsigned int countpass = 0; - unsigned int nInnerStubs = 0; - - for (unsigned int iInnerMem = 0; iInnerMem < firstvmstubs_.size(); - nInnerStubs += firstvmstubs_.at(iInnerMem)->nVMStubs(), iInnerMem++) - ; - - assert(!firstvmstubs_.empty()); - assert(secondvmstubs_ != nullptr); - - for (auto& iInnerMem : firstvmstubs_) { - assert(iInnerMem->nVMStubs() == iInnerMem->nVMStubs()); - for (unsigned int i = 0; i < iInnerMem->nVMStubs(); i++) { - const VMStubTE& firstvmstub = iInnerMem->getVMStubTE(i); - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "In " << getName() << " have first stub"; - } - - if ((layer1_ == 3 && layer2_ == 4) || (layer1_ == 5 && layer2_ == 6)) { - int lookupbits = firstvmstub.vmbits().value() & 1023; - int zdiffmax = (lookupbits >> 7); - int newbin = (lookupbits & 127); - int bin = newbin / 8; - - int zbinfirst = newbin & 7; - - int start = (bin >> 1); - int last = start + (bin & 1); - - assert(last < 8); - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last; - } - for (int ibin = start; ibin <= last; ibin++) { - for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "In " << getName() << " have second stub(1) " << ibin << " " << j; - } - - if (countall >= settings_.maxStep("TE")) - break; - countall++; - const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j); - - int zbin = (secondvmstub.vmbits().value() & 7); - if (start != ibin) - zbin += 8; - if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong zbin"; - } - continue; - } - - assert(firstphibits_ != -1); - assert(secondphibits_ != -1); - - FPGAWord iphifirstbin = firstvmstub.finephi(); - FPGAWord iphisecondbin = secondvmstub.finephi(); - - unsigned int index = (iphifirstbin.value() << secondphibits_) + iphisecondbin.value(); - - FPGAWord firstbend = firstvmstub.bend(); - FPGAWord secondbend = secondvmstub.bend(); - - index = (index << firstbend.nbits()) + firstbend.value(); - index = (index << secondbend.nbits()) + secondbend.value(); - - if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && - (index >= table_.size() || table_.at(index).empty())) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") - << "Stub pair rejected because of stub pt cut bends : " - << settings_.benddecode(firstvmstub.bend().value(), layer1_ - 1, firstvmstub.isPSmodule()) << " " - << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule()); - } - - //FIXME temporarily commented out until stub bend table fixed - //if (!settings_.writeTripletTables()) - // continue; - } - - if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); - for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) { - if (!settings_.enableTripletTables() || settings_.writeTripletTables() || table_.at(index).count(isp)) { - if (settings_.writeMonitorData("Seeds")) { - ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; - fout.close(); - } - stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); - } - } - - countpass++; - } - } - - } else if (layer1_ == 2 && layer2_ == 3) { - int lookupbits = firstvmstub.vmbits().value() & 1023; - int zdiffmax = (lookupbits >> 7); - int newbin = (lookupbits & 127); - int bin = newbin / 8; - - int zbinfirst = newbin & 7; - - int start = (bin >> 1); - int last = start + (bin & 1); - - assert(last < 8); - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Will look in zbins " << start << " to " << last; - } - for (int ibin = start; ibin <= last; ibin++) { - for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "In " << getName() << " have second stub(2) "; - } - - if (countall >= settings_.maxStep("TE")) - break; - countall++; - - const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j); - - int zbin = (secondvmstub.vmbits().value() & 7); - if (start != ibin) - zbin += 8; - if (zbin < zbinfirst || zbin - zbinfirst > zdiffmax) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Stubpair rejected because of wrong zbin"; - } - continue; - } - - assert(firstphibits_ != -1); - assert(secondphibits_ != -1); - - FPGAWord iphifirstbin = firstvmstub.finephi(); - FPGAWord iphisecondbin = secondvmstub.finephi(); - - unsigned int index = (iphifirstbin.value() << secondphibits_) + iphisecondbin.value(); - - FPGAWord firstbend = firstvmstub.bend(); - FPGAWord secondbend = secondvmstub.bend(); - - index = (index << firstbend.nbits()) + firstbend.value(); - index = (index << secondbend.nbits()) + secondbend.value(); - - if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && - (index >= table_.size() || table_.at(index).empty())) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") - << "Stub pair rejected because of stub pt cut bends : " - << settings_.benddecode(firstvmstub.bend().value(), layer1_ - 1, firstvmstub.isPSmodule()) << " " - << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule()); - } - continue; - } - - if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); - for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) { - if ((!settings_.enableTripletTables() || settings_.writeTripletTables()) || - (index < table_.size() && table_.at(index).count(isp))) { - if (settings_.writeMonitorData("Seeds")) { - ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; - fout.close(); - } - stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); - } - } - - countpass++; - } - } - - } else if (disk1_ == 1 && disk2_ == 2) { - if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << getName() << " Disk-disk pair"; - - int lookupbits = firstvmstub.vmbits().value() & 511; - bool negdisk = firstvmstub.stub()->disk().value() < 0; - int rdiffmax = (lookupbits >> 6); - int newbin = (lookupbits & 63); - int bin = newbin / 8; - - int rbinfirst = newbin & 7; - - int start = (bin >> 1); - if (negdisk) - start += 4; - int last = start + (bin & 1); - assert(last < 8); - for (int ibin = start; ibin <= last; ibin++) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " looking for matching stub in " << secondvmstubs_->getName() - << " in bin = " << ibin << " with " << secondvmstubs_->nVMStubsBinned(ibin) - << " stubs"; - } - for (unsigned int j = 0; j < secondvmstubs_->nVMStubsBinned(ibin); j++) { - if (countall >= settings_.maxStep("TE")) - break; - countall++; - - const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTEBinned(ibin, j); - - int rbin = (secondvmstub.vmbits().value() & 7); - if (start != ibin) - rbin += 8; - if (rbin < rbinfirst) - continue; - if (rbin - rbinfirst > rdiffmax) - continue; - - unsigned int irsecondbin = secondvmstub.vmbits().value() >> 2; - - FPGAWord iphifirstbin = firstvmstub.finephi(); - FPGAWord iphisecondbin = secondvmstub.finephi(); - - unsigned int index = (irsecondbin << (secondphibits_ + firstphibits_)) + - (iphifirstbin.value() << secondphibits_) + iphisecondbin.value(); - - FPGAWord firstbend = firstvmstub.bend(); - FPGAWord secondbend = secondvmstub.bend(); - - index = (index << firstbend.nbits()) + firstbend.value(); - index = (index << secondbend.nbits()) + secondbend.value(); - - if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && - (index >= table_.size() || table_.at(index).empty())) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") - << "Stub pair rejected because of stub pt cut bends : " - << settings_.benddecode(firstvmstub.bend().value(), disk1_ + 5, firstvmstub.isPSmodule()) << " " - << settings_.benddecode(secondvmstub.bend().value(), disk2_ + 5, secondvmstub.isPSmodule()); - } - continue; - } - - if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << "Adding disk-disk pair in " << getName(); - - for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) { - if ((!settings_.enableTripletTables() || settings_.writeTripletTables()) || - (index < table_.size() && table_.at(index).count(isp))) { - if (settings_.writeMonitorData("Seeds")) { - ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; - fout.close(); - } - stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); - } - } - countpass++; - } - } - } - } - } - if (countall > 5000) { - edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute : " << getName() << " " << nInnerStubs << " " - << secondvmstubs_->nVMStubs() << " " << countall << " " << countpass; - for (auto& iInnerMem : firstvmstubs_) { - for (unsigned int i = 0; i < iInnerMem->nVMStubs(); i++) { - const VMStubTE& firstvmstub = iInnerMem->getVMStubTE(i); - edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute first stub : " - << firstvmstub.stub()->l1tstub()->r() << " " - << firstvmstub.stub()->l1tstub()->phi() << " " - << firstvmstub.stub()->l1tstub()->r() * firstvmstub.stub()->l1tstub()->phi() << " " - << firstvmstub.stub()->l1tstub()->z(); - } - } - for (unsigned int i = 0; i < secondvmstubs_->nVMStubs(); i++) { - const VMStubTE& secondvmstub = secondvmstubs_->getVMStubTE(i); - edm::LogVerbatim("Tracklet") << "In TrackletEngineDisplaced::execute second stub : " - << secondvmstub.stub()->l1tstub()->r() << " " - << secondvmstub.stub()->l1tstub()->phi() << " " - << secondvmstub.stub()->l1tstub()->r() * secondvmstub.stub()->l1tstub()->phi() << " " - << secondvmstub.stub()->l1tstub()->z(); - } - } - - if (settings_.writeMonitorData("TED")) { - globals_->ofstream("trackletenginedisplaces.txt") << getName() << " " << countall << " " << countpass << endl; - } -} - -void TrackletEngineDisplaced::readTables() { - ifstream fin; - string tableName, line, word; - - string tablePath = settings_.tableTEDFile(); - unsigned int finddir = tablePath.find("table_TED_"); - tableName = tablePath.substr(0, finddir) + "table_" + name_ + ".txt"; - - fin.open(tableName, ifstream::in); - if (!fin) { - throw cms::Exception("BadConfig") << "TripletEngine::readTables, file " << tableName << " not known"; - } - - while (getline(fin, line)) { - istringstream iss(line); - table_.resize(table_.size() + 1); - - while (iss >> word) - table_[table_.size() - 1].insert(memNameToIndex(word)); - } - fin.close(); -} - -short TrackletEngineDisplaced::memNameToIndex(const string& name) { - for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) - if (stubpairs_.at(isp)->getName() == name) - return isp; - return -1; -} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc index 2104d3cea740b..2c9b7cf8c493e 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc @@ -6,7 +6,6 @@ #include "L1Trigger/TrackFindingTracklet/interface/HistBase.h" #include "L1Trigger/TrackFindingTracklet/interface/Track.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" #include "L1Trigger/TrackFindingTracklet/interface/StubStreamData.h" #include "DataFormats/Math/interface/deltaPhi.h" @@ -29,25 +28,6 @@ void TrackletEventProcessor::init(Settings const& theSettings, const tt::Setup* settings_ = &theSettings; globals_ = make_unique(*settings_); - //Verify consistency - if (settings_->kphi0pars() != globals_->ITC_L1L2()->phi0_final.K()) { - throw cms::Exception("Inconsistency") << "phi0 conversion parameter inconsistency\n"; - } - - if (settings_->krinvpars() != globals_->ITC_L1L2()->rinv_final.K()) { - throw cms::Exception("Inconsistency") << "ring conversion parameter inconsistency\n"; - } - - if (settings_->ktpars() != globals_->ITC_L1L2()->t_final.K()) { - throw cms::Exception("Inconsistency") << "t conversion parameter inconsistency\n"; - } - - if (settings_->kphider() != globals_->ITC_L1L2()->der_phiL_final.K()) { - throw cms::Exception("Inconsistency") - << "t conversion parameter inconsistency:" << settings_->kphider() / globals_->ITC_L1L2()->der_phiL_final.K() - << "\n"; - } - if (settings_->debugTracklet()) { edm::LogVerbatim("Tracklet") << "========================================================= \n" << "Conversion factors for global coordinates: \n" @@ -242,44 +222,15 @@ void TrackletEventProcessor::event(SLHCEvent& ev, sector_->executeVMR(); if (settings_->writeMem() && k == settings_->writememsect()) { sector_->writeVMSTE(first); - sector_->writeVMSME(first); - sector_->writeAS(first); sector_->writeAIS(first); } VMRouterTimer_.stop(); - // tracklet engine - TETimer_.start(); - sector_->executeTE(); - TETimer_.stop(); - - // tracklet engine displaced - TEDTimer_.start(); - sector_->executeTED(); - TEDTimer_.stop(); - - // triplet engine - TRETimer_.start(); - sector_->executeTRE(); - if (settings_->writeMem() && k == settings_->writememsect()) { - sector_->writeST(first); - } - TRETimer_.stop(); - // tracklet processor (alternative implementation to TE+TC) TPTimer_.start(); sector_->executeTP(); TPTimer_.stop(); - if (settings_->writeMem() && k == settings_->writememsect()) { - sector_->writeSP(first); - } - - // tracklet calculator - TCTimer_.start(); - sector_->executeTC(); - TCTimer_.stop(); - if (settings_->writeMonitorData("HitEff") || settings_->bookHistos()) { int nTP = globals_->event()->nsimtracks(); for (int iTP = 0; iTP < nTP; iTP++) { @@ -325,42 +276,29 @@ void TrackletEventProcessor::event(SLHCEvent& ev, } } - // tracklet calculator displaced - TCDTimer_.start(); - sector_->executeTCD(); - TCDTimer_.stop(); // tracklet processor displaced TPDTimer_.start(); sector_->executeTPD(); TPDTimer_.stop(); + // projection calculator + PCTimer_.start(); + sector_->executePC(); + PCTimer_.stop(); if (settings_->writeMem() && k == settings_->writememsect()) { - sector_->writeTPAR(first); sector_->writeTPROJ(first); + sector_->writeTPAR(first); } - // projection router - PRTimer_.start(); - sector_->executePR(); - if (settings_->writeMem() && k == settings_->writememsect()) { - sector_->writeVMPROJ(first); - sector_->writeAP(first); - } - PRTimer_.stop(); - - // match engine - METimer_.start(); - sector_->executeME(); + // VMStub ME Router + VMSMERTimer_.start(); + sector_->executeVMSMER(); + VMSMERTimer_.stop(); if (settings_->writeMem() && k == settings_->writememsect()) { - sector_->writeCM(first); + sector_->writeVMSME(first); + sector_->writeAS(first); } - METimer_.stop(); - - // match calculator - MCTimer_.start(); - sector_->executeMC(); - MCTimer_.stop(); // match processor (alternative to ME+MC) MPTimer_.start(); @@ -408,46 +346,18 @@ void TrackletEventProcessor::printSummary() { << InputRouterTimer_.tottime() << "\n" << "VMRouter " << setw(10) << VMRouterTimer_.ntimes() << setw(20) << setprecision(3) << VMRouterTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << VMRouterTimer_.tottime(); - if (settings_->combined()) { - edm::LogVerbatim("Tracklet") << "TrackletProcessor " << setw(10) << TPTimer_.ntimes() << setw(20) - << setprecision(3) << TPTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << TPTimer_.tottime() << "\n" - << "MatchProcessor " << setw(10) << MPTimer_.ntimes() << setw(20) - << setprecision(3) << MPTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << MPTimer_.tottime(); - } else { - edm::LogVerbatim("Tracklet") << "TrackletEngine " << setw(10) << TETimer_.ntimes() << setw(20) - << setprecision(3) << TETimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << TETimer_.tottime(); + << VMRouterTimer_.tottime() << "\n" + << "TrackletProcessor " << setw(10) << TPTimer_.ntimes() << setw(20) + << setprecision(3) << TPTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << TPTimer_.tottime() << "\n" + << "MatchProcessor " << setw(10) << MPTimer_.ntimes() << setw(20) + << setprecision(3) << MPTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << MPTimer_.tottime(); if (settings_->extended()) { - edm::LogVerbatim("Tracklet") << "TrackletEngineDisplaced" << setw(10) << TEDTimer_.ntimes() << setw(20) - << setprecision(3) << TEDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << TEDTimer_.tottime() << "\n" - << "TripletEngine " << setw(10) << TRETimer_.ntimes() << setw(20) - << setprecision(3) << TRETimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << TRETimer_.tottime() << "\n" - << "TrackletCalculatorDisplaced" << setw(10) << TCDTimer_.ntimes() << setw(20) - << setprecision(3) << TCDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << TCDTimer_.tottime() << "\n" - << TCDTimer_.tottime() << "\n" - << "TrackletProcessorDisplaced" << setw(10) << TPDTimer_.ntimes() << setw(20) + edm::LogVerbatim("Tracklet") << "TrackletProcessorDisplaced" << setw(10) << TPDTimer_.ntimes() << setw(20) << setprecision(3) << TPDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TPDTimer_.tottime(); } - edm::LogVerbatim("Tracklet") << "TrackletCalculator " << setw(10) << TCTimer_.ntimes() << setw(20) - << setprecision(3) << TCTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << TCTimer_.tottime() << "\n" - << "ProjectionRouter " << setw(10) << PRTimer_.ntimes() << setw(20) - << setprecision(3) << PRTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << PRTimer_.tottime() << "\n" - << "MatchEngine " << setw(10) << METimer_.ntimes() << setw(20) - << setprecision(3) << METimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << METimer_.tottime() << "\n" - << "MatchCalculator " << setw(10) << MCTimer_.ntimes() << setw(20) - << setprecision(3) << MCTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << MCTimer_.tottime(); - } edm::LogVerbatim("Tracklet") << "FitTrack " << setw(10) << FTTimer_.ntimes() << setw(20) << setprecision(3) << FTTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << FTTimer_.tottime() << "\n" diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc index 7368391eeff70..e12d9cc7988d8 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc @@ -9,13 +9,25 @@ using namespace std; using namespace trklet; TrackletParametersMemory::TrackletParametersMemory(string name, Settings const& settings) - : MemoryBase(name, settings) {} + : MemoryBase(name, settings) { + npage_ = name.size()-9; + tracklets_.resize(npage_); +} void TrackletParametersMemory::clean() { - for (auto& tracklet : tracklets_) { - delete tracklet; + + //This is where we delete the tracklets that were created. As tracklet as stored in both the TPAR and MPAR memories + //we will onlu delete once in the TPAR memory + if (name_[0] == 'T') { + for (unsigned int page = 0 ; page < npage_ ; page++ ){ + for (auto& tracklet : tracklets_[page]) { + delete tracklet; + } + } + } + for (unsigned int page = 0; page < tracklets_.size(); page++) { + tracklets_[page].clear(); } - tracklets_.clear(); } void TrackletParametersMemory::writeTPAR(bool first, unsigned int iSector) { @@ -31,9 +43,12 @@ void TrackletParametersMemory::writeTPAR(bool first, unsigned int iSector) { out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; - for (unsigned int j = 0; j < tracklets_.size(); j++) { - string tpar = tracklets_[j]->trackletparstr(); - out_ << hexstr(j) << " " << tpar << " " << trklet::hexFormat(tpar) << endl; + + for (unsigned int page = 0; page < tracklets_.size(); page++) { + for (unsigned int j = 0; j < tracklets_[page].size(); j++) { + string tpar = tracklets_[page][j]->trackletparstr(); + out_ << hexstr(page) << " " << hexstr(j) << " " << tpar << " " << trklet::hexFormat(tpar) << endl; + } } out_.close(); diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc index 7d7822b1c0f2e..db8605e22811e 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc @@ -4,7 +4,6 @@ #include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/Util.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -26,16 +25,6 @@ TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Glob innerOverlapTable_(settings) { iAllStub_ = -1; - for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { - vector tmp(settings_.nallstubs(ilayer), nullptr); - trackletprojlayers_.push_back(tmp); - } - - for (unsigned int idisk = 0; idisk < N_DISK; idisk++) { - vector tmp(settings_.nallstubs(idisk + N_LAYER), nullptr); - trackletprojdisks_.push_back(tmp); - } - outervmstubs_ = nullptr; initLayerDisksandISeed(layerdisk1_, layerdisk2_, iSeed_); @@ -59,6 +48,8 @@ TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Glob } } + init(iSeed_); + double dphimax = asin(0.5 * settings_.maxrinv() * rmax) - asin(0.5 * settings_.maxrinv() * rmin); //number of fine phi bins in sector @@ -102,11 +93,6 @@ TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Glob maxStep_ = settings_.maxStep("TP"); } -void TrackletProcessor::addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory) { - outputProj = dynamic_cast(memory); - assert(outputProj != nullptr); -} - void TrackletProcessor::addOutput(MemoryBase* memory, string output) { if (settings_.writetrace()) { edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " @@ -119,32 +105,10 @@ void TrackletProcessor::addOutput(MemoryBase* memory, string output) { return; } - if (output.substr(0, 7) == "projout") { - //output is on the form 'projoutL2PHIC' or 'projoutD3PHIB' - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - - unsigned int layerdisk = output[8] - '1'; //layer or disk counting from 0 - unsigned int phiregion = output[12] - 'A'; //phiregion counting from 0 - - if (output[7] == 'L') { - assert(layerdisk < N_LAYER); - assert(phiregion < trackletprojlayers_[layerdisk].size()); - //check that phiregion not already initialized - assert(trackletprojlayers_[layerdisk][phiregion] == nullptr); - trackletprojlayers_[layerdisk][phiregion] = tmp; - return; - } - - if (output[7] == 'D') { - assert(layerdisk < N_DISK); - assert(phiregion < trackletprojdisks_[layerdisk].size()); - //check that phiregion not already initialized - assert(trackletprojdisks_[layerdisk][phiregion] == nullptr); - trackletprojdisks_[layerdisk][phiregion] = tmp; - return; - } - } + //if (output.substr(0,4) == "proj") { + //Hack to keep proj output in config - but ignore in application + // return; + //} throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; } @@ -402,9 +366,12 @@ void TrackletProcessor::execute(unsigned int iSector, double phimin, double phim if (negdisk) { indexz = ((1 << nbitszfinebintable_) - 1) - indexz; } - indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_); + indexr = + stub->rvalue() >> + (stub->r().nbits() + 1 - + nbitsrfinebintable_); // + 1 required to offset artificial decrease in # of diskps r bits from 12 -> 11 to make space for negDisk bit } else { //Take the top nbitsfinebintable_ bits of the z coordinate - indexr = (stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_)) & ((1 << nbitsrfinebintable_) - 1); + indexr = (stub->rvalue() >> (stub->r().nbits() - nbitsrfinebintable_)) & ((1 << nbitsrfinebintable_) - 1); } int lutval = -1; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProcessorDisplaced.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProcessorDisplaced.cc index 0c8a1424264e0..c94b7a511a345 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProcessorDisplaced.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProcessorDisplaced.cc @@ -3,10 +3,8 @@ #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" #include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" #include "L1Trigger/TrackFindingTracklet/interface/Util.h" -#include "L1Trigger/TrackFindingTracklet/interface/IMATH_TrackletCalculator.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -141,6 +139,7 @@ void TrackletProcessorDisplaced::addInput(MemoryBase* memory, string input) { outerallstubs_.push_back(tmp); return; } + if (input == "thirdvmstubin") { auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc index 2cde8759a71e8..00e41006b72be 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc @@ -13,9 +13,14 @@ TrackletProjectionsMemory::TrackletProjectionsMemory(string name, Settings const assert(pos != string::npos); initLayerDisk(pos + 1, layer_, disk_); hasProj_ = false; + npage_ = name.size()-17; + if (name.substr(name.size()-2,2)=="_E") { + npage_ = name.size()-19; + } + tracklets_.resize(npage_); } -void TrackletProjectionsMemory::addProj(Tracklet* tracklet) { +void TrackletProjectionsMemory::addProj(Tracklet* tracklet, unsigned int page) { if (layer_ != 0 && disk_ == 0) assert(tracklet->validProj(layer_ - 1)); if (layer_ == 0 && disk_ != 0) @@ -23,7 +28,7 @@ void TrackletProjectionsMemory::addProj(Tracklet* tracklet) { if (layer_ != 0 && disk_ != 0) assert(tracklet->validProj(layer_ - 1) || tracklet->validProj(N_LAYER + abs(disk_) - 1)); - for (auto& itracklet : tracklets_) { + for (auto& itracklet : tracklets_[page]) { if (itracklet == tracklet) { edm::LogPrint("Tracklet") << "Adding same tracklet " << tracklet << " twice in " << getName(); } @@ -31,15 +36,26 @@ void TrackletProjectionsMemory::addProj(Tracklet* tracklet) { } hasProj_ = true; - tracklets_.push_back(tracklet); + + if (tracklets_[page].size()<(1<<(N_BITSMEMADDRESS-1))-1) { + tracklets_[page].push_back(tracklet); + } } -void TrackletProjectionsMemory::clean() { tracklets_.clear(); } +void TrackletProjectionsMemory::clean() { + for (unsigned int i = 0; i < tracklets_.size() ; i++){ + tracklets_[i].clear(); + } +} void TrackletProjectionsMemory::writeTPROJ(bool first, unsigned int iSector) { iSector_ = iSector; const string dirTP = settings_.memPath() + "TrackletProjections/"; + + //Hack to suppress writing empty TPROJ memories - only want to write MPROJ memories + if (getName()[0] == 'T') return; + std::ostringstream oss; oss << dirTP << "TrackletProjections_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; @@ -50,9 +66,27 @@ void TrackletProjectionsMemory::writeTPROJ(bool first, unsigned int iSector) { out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; for (unsigned int j = 0; j < tracklets_.size(); j++) { - string proj = (layer_ > 0 && tracklets_[j]->validProj(layer_ - 1)) ? tracklets_[j]->trackletprojstrlayer(layer_) - : tracklets_[j]->trackletprojstrdisk(disk_); - out_ << hexstr(j) << " " << proj << " " << trklet::hexFormat(proj) << endl; + // This is a hack here to write out the TPAR files for backward compatibility + std::ofstream out; + std::string moduleName = getName().substr(0,10);; + moduleName[0]='T'; + std::ostringstream oss2; + char postfix = getName()[10]; + postfix+=j; + oss2 << dirTP << "TrackletProjections_" << moduleName << postfix << "_" << getName().substr(getName().size()-6,6) + << "_" < 0 && tracklets_[j][i]->validProj(layer_ - 1)) ? tracklets_[j][i]->trackletprojstrlayer(layer_) + : tracklets_[j][i]->trackletprojstrdisk(disk_); + out_ << hexstr(j) << " " << hexstr(i) << " " << proj << " " << trklet::hexFormat(proj) << endl; + out << hexstr(i) << " " << proj << " " << trklet::hexFormat(proj) << endl; + } + out.close(); } out_.close(); diff --git a/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc b/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc deleted file mode 100644 index c934ecb220d06..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc +++ /dev/null @@ -1,481 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/TripletEngine.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" -#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" - -#include - -using namespace std; -using namespace trklet; - -TripletEngine::TripletEngine(string name, Settings const &settings, Globals *global) - : ProcessBase(name, settings, global) { - stubpairs_.clear(); - thirdvmstubs_.clear(); - layer1_ = 0; - layer2_ = 0; - layer3_ = 0; - disk1_ = 0; - disk2_ = 0; - disk3_ = 0; - dct1_ = 0; - dct2_ = 0; - dct3_ = 0; - phi1_ = 0; - phi2_ = 0; - phi3_ = 0; - z1_ = 0; - z2_ = 0; - z3_ = 0; - r1_ = 0; - r2_ = 0; - r3_ = 0; - - if (name_[4] == 'L') - layer1_ = name_[5] - '0'; - if (name_[4] == 'D') - disk1_ = name_[5] - '0'; - if (name_[7] == 'L') - layer2_ = name_[8] - '0'; - if (name_[7] == 'D') - disk2_ = name_[8] - '0'; - - if (layer1_ == 3 && layer2_ == 4) { - layer3_ = 2; - iSeed_ = 8; - } else if (layer1_ == 5 && layer2_ == 6) { - layer3_ = 4; - iSeed_ = 9; - } else if (layer1_ == 2 && layer2_ == 3) { - disk3_ = 1; - iSeed_ = 10; - } else if (disk1_ == 1 && disk2_ == 2) { - layer3_ = 2; - iSeed_ = 11; - } else - throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; - - if ((layer2_ == 4 && layer3_ == 2) || (layer2_ == 6 && layer3_ == 4)) { - secondphibits_ = settings_.nfinephi(1, iSeed_); - thirdphibits_ = settings_.nfinephi(2, iSeed_); - } - if ((layer2_ == 3 && disk3_ == 1) || (disk2_ == 2 && layer3_ == 2)) { - secondphibits_ = settings_.nfinephi(1, iSeed_); - thirdphibits_ = settings_.nfinephi(2, iSeed_); - } - if (settings_.enableTripletTables() && !settings_.writeTripletTables()) - readTables(); -} - -TripletEngine::~TripletEngine() { - if (settings_.writeTripletTables()) - writeTables(); -} - -void TripletEngine::addOutput(MemoryBase *memory, string output) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " - << output; - } - if (output == "stubtripout") { - auto *tmp = dynamic_cast(memory); - assert(tmp != nullptr); - stubtriplets_ = tmp; - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; -} - -void TripletEngine::addInput(MemoryBase *memory, string input) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " - << input; - } - if (input == "thirdvmstubin") { - auto *tmp = dynamic_cast(memory); - assert(tmp != nullptr); - thirdvmstubs_.push_back(tmp); - return; - } - if (input.substr(0, 8) == "stubpair") { - auto *tmp = dynamic_cast(memory); - assert(tmp != nullptr); - stubpairs_.push_back(tmp); - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; -} - -void TripletEngine::execute() { - unsigned int countall = 0; - unsigned int countpass = 0; - unsigned int nThirdStubs = 0; - count_ = 0; - - for (unsigned int iThirdMem = 0; iThirdMem < thirdvmstubs_.size(); - nThirdStubs += thirdvmstubs_.at(iThirdMem)->nVMStubs(), iThirdMem++) - ; - - assert(!thirdvmstubs_.empty()); - assert(!stubpairs_.empty()); - - bool print = false && (getName().substr(0, 10) == "TRE_L2cL3c"); - - print = print && nThirdStubs > 0; - - if (print) { - edm::LogVerbatim("Tracklet") << "In TripletEngine::execute : " << getName() << " " << nThirdStubs << ":"; - for (unsigned int i = 0; i < thirdvmstubs_.size(); ++i) { - edm::LogVerbatim("Tracklet") << thirdvmstubs_.at(i)->getName() << " " << thirdvmstubs_.at(i)->nVMStubs(); - } - std::string oss = ""; - for (unsigned int i = 0; i < stubpairs_.size(); ++i) { - oss += std::to_string(stubpairs_.at(i)->nStubPairs()); - oss += " "; - } - edm::LogVerbatim("Tracklet") << oss; - for (unsigned int i = 0; i < stubpairs_.size(); ++i) { - edm::LogVerbatim("Tracklet") << " " << stubpairs_.at(i)->getName(); - } - } - - tmpSPTable_.clear(); - - for (unsigned int i = 0; i < stubpairs_.size(); ++i) { - for (unsigned int j = 0; j < stubpairs_.at(i)->nStubPairs(); ++j) { - if (print) - edm::LogVerbatim("Tracklet") << " ***** " << stubpairs_.at(i)->getName() << " " - << stubpairs_.at(i)->nStubPairs(); - - auto firstvmstub = stubpairs_.at(i)->getVMStub1(j); - auto secondvmstub = stubpairs_.at(i)->getVMStub2(j); - - if ((layer2_ == 4 && layer3_ == 2) || (layer2_ == 6 && layer3_ == 4)) { - constexpr unsigned int vmbitshift = 10; - int lookupbits = (int)((firstvmstub.vmbits().value() >> vmbitshift) & 1023); //1023=2^vmbitshift-1 - int newbin = (lookupbits & 127); - int bin = newbin / 8; - - int start = (bin >> 1); - int last = start + (bin & 1); - - for (int ibin = start; ibin <= last; ibin++) { - for (unsigned int k = 0; k < thirdvmstubs_.size(); k++) { - string vmsteSuffix = thirdvmstubs_.at(k)->getLastPartOfName(); - vmsteSuffix = vmsteSuffix.substr(0, vmsteSuffix.find_last_of('n')); - if (stubpairs_.at(i)->getLastPartOfName() != vmsteSuffix) - continue; - for (unsigned int l = 0; l < thirdvmstubs_.at(k)->nVMStubsBinned(ibin); l++) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "In " << getName() << " have third stub"; - } - - if (countall >= settings_.maxStep("TRE")) - break; - countall++; - - const VMStubTE &thirdvmstub = thirdvmstubs_.at(k)->getVMStubTEBinned(ibin, l); - - assert(secondphibits_ != -1); - assert(thirdphibits_ != -1); - - unsigned int nvmsecond = settings_.nallstubs(layer2_ - 1) * settings_.nvmte(1, iSeed_); - unsigned int nvmbitssecond = nbits(nvmsecond); - - FPGAWord iphisecondbin = secondvmstub.stub()->iphivmFineBins(nvmbitssecond, secondphibits_); - - //currently not using same number of bits as in the TED - //assert(iphisecondbin==(int)secondvmstub.finephi()); - FPGAWord iphithirdbin = thirdvmstub.finephi(); - - unsigned int index = (iphisecondbin.value() << thirdphibits_) + iphithirdbin.value(); - - FPGAWord secondbend = secondvmstub.bend(); - FPGAWord thirdbend = thirdvmstub.bend(); - - index = (index << secondbend.nbits()) + secondbend.value(); - index = (index << thirdbend.nbits()) + thirdbend.value(); - - if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && - (index >= table_.size() || !table_[index])) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") - << "Stub pair rejected because of stub pt cut bends : " - << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule()) - << " " << settings_.benddecode(thirdvmstub.bend().value(), layer3_ - 1, thirdvmstub.isPSmodule()); - } - - //FIXME temporarily commented out until bend table fixed - //if (!settings_.writeTripletTables()) - // continue; - } - if (settings_.writeTripletTables()) { - if (index >= table_.size()) - table_.resize(index + 1, false); - table_[index] = true; - - const unsigned spIndex = stubpairs_.at(i)->getIndex(j); - const string &tedName = stubpairs_.at(i)->getTEDName(j); - if (!tmpSPTable_.count(tedName)) - tmpSPTable_[tedName]; - if (spIndex >= tmpSPTable_.at(tedName).size()) - tmpSPTable_.at(tedName).resize(spIndex + 1); - tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); - } - - if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); - if (settings_.writeMonitorData("Seeds")) { - ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; - fout.close(); - } - stubtriplets_->addStubs(thirdvmstub.stub(), - (stubpairs_.at(i))->getVMStub1(j).stub(), - (stubpairs_.at(i))->getVMStub2(j).stub()); - - countpass++; - } - } - } - - } - - else if (disk2_ == 2 && layer3_ == 2) { - int lookupbits = (int)((firstvmstub.vmbits().value() >> 10) & 1023); - int newbin = (lookupbits & 127); - int bin = newbin / 8; - - int start = (bin >> 1); - int last = start + (bin & 1); - - if (firstvmstub.stub()->disk().value() < 0) { //TODO - negative disk should come from memory - start = settings_.NLONGVMBINS() - last - 1; - last = settings_.NLONGVMBINS() - start - 1; - } - - for (int ibin = start; ibin <= last; ibin++) { - for (unsigned int k = 0; k < thirdvmstubs_.size(); k++) { - string vmsteSuffix = thirdvmstubs_.at(k)->getLastPartOfName(); - vmsteSuffix = vmsteSuffix.substr(0, vmsteSuffix.find_last_of('n')); - if (stubpairs_.at(i)->getLastPartOfName() != vmsteSuffix) - continue; - - for (unsigned int l = 0; l < thirdvmstubs_.at(k)->nVMStubsBinned(ibin); l++) { - if (countall >= settings_.maxStep("TRE")) - break; - countall++; - - const VMStubTE &thirdvmstub = thirdvmstubs_.at(k)->getVMStubTEBinned(ibin, l); - - assert(secondphibits_ != -1); - assert(thirdphibits_ != -1); - - FPGAWord iphisecondbin = secondvmstub.finephi(); - FPGAWord iphithirdbin = thirdvmstub.finephi(); - - unsigned int index = (iphisecondbin.value() << thirdphibits_) + iphithirdbin.value(); - - FPGAWord secondbend = secondvmstub.bend(); - FPGAWord thirdbend = thirdvmstub.bend(); - - index = (index << secondbend.nbits()) + secondbend.value(); - index = (index << thirdbend.nbits()) + thirdbend.value(); - - if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && - (index >= table_.size() || !table_[index])) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") - << "Stub triplet rejected because of stub pt cut bends : " - << settings_.benddecode(secondvmstub.bend().value(), disk2_ + 5, secondvmstub.isPSmodule()) << " " - << settings_.benddecode(thirdvmstub.bend().value(), layer3_ - 1, thirdvmstub.isPSmodule()); - } - continue; - } - if (settings_.writeTripletTables()) { - if (index >= table_.size()) - table_.resize(index + 1, false); - table_[index] = true; - - const unsigned spIndex = stubpairs_.at(i)->getIndex(j); - const string &tedName = stubpairs_.at(i)->getTEDName(j); - if (!tmpSPTable_.count(tedName)) - tmpSPTable_[tedName]; - if (spIndex >= tmpSPTable_.at(tedName).size()) - tmpSPTable_.at(tedName).resize(spIndex + 1); - tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); - } - - if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << "Adding layer-disk pair in " << getName(); - if (settings_.writeMonitorData("Seeds")) { - ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; - fout.close(); - } - stubtriplets_->addStubs(thirdvmstub.stub(), - (stubpairs_.at(i))->getVMStub1(j).stub(), - (stubpairs_.at(i))->getVMStub2(j).stub()); - countpass++; - } - } - } - } - - else if (layer2_ == 3 && disk3_ == 1) { - int lookupbits = (int)((firstvmstub.vmbits().value() >> 10) & 1023); - - int newbin = (lookupbits & 127); - int bin = newbin / 8; - - int start = (bin >> 1); - int last = start + (bin & 1); - - for (int ibin = start; ibin <= last; ibin++) { - for (unsigned int k = 0; k < thirdvmstubs_.size(); k++) { - string vmsteSuffix = thirdvmstubs_.at(k)->getLastPartOfName(); - vmsteSuffix = vmsteSuffix.substr(0, vmsteSuffix.find_last_of('n')); - if (stubpairs_.at(i)->getLastPartOfName() != vmsteSuffix) - continue; - for (unsigned int l = 0; l < thirdvmstubs_.at(k)->nVMStubsBinned(ibin); l++) { - if (countall >= settings_.maxStep("TRE")) - break; - countall++; - - const VMStubTE &thirdvmstub = thirdvmstubs_.at(k)->getVMStubTEBinned(ibin, l); - - assert(secondphibits_ != -1); - assert(thirdphibits_ != -1); - - unsigned int nvmsecond; - - nvmsecond = settings_.nallstubs(layer2_ - 1) * settings_.nvmte(1, iSeed_); - unsigned int nvmbitssecond = nbits(nvmsecond); - - FPGAWord iphisecondbin = secondvmstub.stub()->iphivmFineBins(nvmbitssecond, secondphibits_); - - //currentlty not using same number of bits as in the TED - //assert(iphisecondbin==(int)secondvmstub.finephi()); - FPGAWord iphithirdbin = thirdvmstub.finephi(); - - unsigned int index = (iphisecondbin.value() << thirdphibits_) + iphithirdbin.value(); - - FPGAWord secondbend = secondvmstub.bend(); - FPGAWord thirdbend = thirdvmstub.bend(); - - index = (index << secondbend.nbits()) + secondbend.value(); - index = (index << thirdbend.nbits()) + thirdbend.value(); - - if ((settings_.enableTripletTables() && !settings_.writeTripletTables()) && - (index >= table_.size() || !table_[index])) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") - << "Stub pair rejected because of stub pt cut bends : " - << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule()) - << " " << settings_.benddecode(thirdvmstub.bend().value(), disk3_ + 5, thirdvmstub.isPSmodule()); - } - continue; - } - if (settings_.writeTripletTables()) { - if (index >= table_.size()) - table_.resize(index + 1, false); - table_[index] = true; - - const unsigned spIndex = stubpairs_.at(i)->getIndex(j); - const string &tedName = stubpairs_.at(i)->getTEDName(j); - if (!tmpSPTable_.count(tedName)) - tmpSPTable_[tedName]; - if (spIndex >= tmpSPTable_.at(tedName).size()) - tmpSPTable_.at(tedName).resize(spIndex + 1); - tmpSPTable_.at(tedName).at(spIndex).push_back(stubpairs_.at(i)->getName()); - } - - if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << "Adding layer-disk pair in " << getName(); - if (settings_.writeMonitorData("Seeds")) { - ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; - fout.close(); - } - stubtriplets_->addStubs(thirdvmstub.stub(), - (stubpairs_.at(i))->getVMStub1(j).stub(), - (stubpairs_.at(i))->getVMStub2(j).stub()); - countpass++; - } - } - } - } - } - } - - for (const auto &tedName : tmpSPTable_) { - for (unsigned spIndex = 0; spIndex < tedName.second.size(); spIndex++) { - if (tedName.second.at(spIndex).empty()) - continue; - vector entry(tedName.second.at(spIndex)); - sort(entry.begin(), entry.end()); - entry.erase(unique(entry.begin(), entry.end()), entry.end()); - const string &spName = entry.at(0); - - if (!spTable_.count(tedName.first)) - spTable_[tedName.first]; - if (spIndex >= spTable_.at(tedName.first).size()) - spTable_.at(tedName.first).resize(spIndex + 1); - if (!spTable_.at(tedName.first).at(spIndex).count(spName)) - spTable_.at(tedName.first).at(spIndex)[spName] = 0; - spTable_.at(tedName.first).at(spIndex)[spName]++; - } - } - - if (settings_.writeMonitorData("TRE")) { - globals_->ofstream("tripletengine.txt") << getName() << " " << countall << " " << countpass << endl; - } -} - -void TripletEngine::readTables() { - ifstream fin; - string tableName, word; - unsigned num; - - string tablePath = settings_.tableTREFile(); - unsigned int finddir = tablePath.find("table_TRE_"); - tableName = tablePath.substr(0, finddir) + "table_" + name_ + ".txt"; - - fin.open(tableName, ifstream::in); - if (!fin) { - throw cms::Exception("BadConfig") << "TripletEngine::readTables, file " << tableName << " not known"; - } - while (!fin.eof()) { - fin >> word; - num = atoi(word.c_str()); - table_.push_back(num > 0 ? true : false); - } - fin.close(); -} - -void TripletEngine::writeTables() { - ofstream fout; - stringstream tableName; - - tableName << "table/table_" << name_ << ".txt"; - - fout.open(tableName.str(), ofstream::out); - for (const auto entry : table_) - fout << entry << endl; - fout.close(); - - for (const auto &tedName : spTable_) { - tableName.str(""); - tableName << "table/table_" << tedName.first << "_" << name_ << ".txt"; - - fout.open(tableName.str(), ofstream::out); - for (const auto &entry : tedName.second) { - for (const auto &spName : entry) - fout << spName.first << ":" << spName.second << " "; - fout << endl; - } - fout.close(); - } -} diff --git a/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc deleted file mode 100644 index 007f865f73db3..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc +++ /dev/null @@ -1,52 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/Tracklet.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include -#include - -using namespace std; -using namespace trklet; - -VMProjectionsMemory::VMProjectionsMemory(string name, Settings const& settings) : MemoryBase(name, settings) { - initLayerDisk(7, layer_, disk_); -} - -void VMProjectionsMemory::addTracklet(Tracklet* tracklet, unsigned int allprojindex) { - std::pair tmp(tracklet, allprojindex); - //Check that order of TCID is correct - if (!tracklets_.empty()) { - assert(tracklets_[tracklets_.size() - 1].first->TCID() <= tracklet->TCID()); - } - tracklets_.push_back(tmp); -} - -void VMProjectionsMemory::writeVMPROJ(bool first, unsigned int iSector) { - iSector_ = iSector; - const string dirVM = settings_.memPath() + "VMProjections/"; - - std::ostringstream oss; - oss << dirVM + "VMProjections_" << getName(); - //get rid of duplicates - auto const& tmp = oss.str(); - int len = tmp.size(); - if (tmp[len - 2] == 'n' && tmp[len - 1] > '1' && tmp[len - 1] <= '9') - return; - oss << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; - auto const& fname = oss.str(); - - openfile(out_, first, dirVM, fname, __FILE__, __LINE__); - - out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; - - for (unsigned int j = 0; j < tracklets_.size(); j++) { - string vmproj = (layer_ > 0) ? tracklets_[j].first->vmstrlayer(layer_, tracklets_[j].second) - : tracklets_[j].first->vmstrdisk(disk_, tracklets_[j].second); - out_ << hexstr(j) << " " << vmproj << " " << trklet::hexFormat(vmproj) << endl; - } - out_.close(); - - bx_++; - event_++; - if (bx_ > 7) - bx_ = 0; -} diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc deleted file mode 100644 index 8ba7cf4c39770..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc +++ /dev/null @@ -1,385 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/VMRouter.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" -#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMStubTE.h" -#include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" - -using namespace std; -using namespace trklet; - -VMRouter::VMRouter(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), - meTable_(settings), - diskTable_(settings), - innerTable_(settings), - innerOverlapTable_(settings), - innerThirdTable_(settings) { - layerdisk_ = initLayerDisk(4); - - vmstubsMEPHI_.resize(settings_.nvmme(layerdisk_), nullptr); - - unsigned int region = name[9] - 'A'; - assert(region < settings_.nallstubs(layerdisk_)); - - overlapbits_ = 7; - nextrabits_ = overlapbits_ - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)); - - meTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::me, region); //used for ME and outer TE barrel - - if (layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D2 || layerdisk_ == D4) { - diskTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::disk, region); //outer disk used by D1, D2, and D4 - } - - if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3 || - layerdisk_ == LayerDisk::L5 || layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) { - innerTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::inner, region); //projection to next layer/disk - } - - if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2) { - innerOverlapTable_.initVMRTable( - layerdisk_, TrackletLUT::VMRTableType::inneroverlap, region); //projection to disk from layer - } - - if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5 || - layerdisk_ == LayerDisk::D1) { - innerThirdTable_.initVMRTable( - layerdisk_, TrackletLUT::VMRTableType::innerthird, region); //projection to third layer/disk - } - - nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk_); - nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk_); -} - -void VMRouter::addOutput(MemoryBase* memory, string output) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " - << output; - } - - if (output.substr(0, 10) == "allstubout") { - AllStubsMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - allstubs_.push_back(tmp); - return; - } - - if (output.substr(0, 12) == "vmstuboutPHI" || output.substr(0, 14) == "vmstuboutMEPHI" || - output.substr(0, 15) == "vmstuboutTEIPHI" || output.substr(0, 15) == "vmstuboutTEOPHI") { - char seedtype = memory->getName().substr(11, 1)[0]; - unsigned int pos = 12; - int vmbin = memory->getName().substr(pos, 1)[0] - '0'; - pos++; - if (pos < memory->getName().size()) { - if (memory->getName().substr(pos, 1)[0] != 'n') { - vmbin = vmbin * 10 + memory->getName().substr(pos, 1)[0] - '0'; - pos++; - } - } - - int iseed = -1; - unsigned int inner = 1; - if (memory->getName().substr(3, 2) == "TE") { - VMStubsTEMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - if (seedtype < 'I') { - if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2) - iseed = Seed::L1L2; - if (layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L4) - iseed = Seed::L3L4; - if (layerdisk_ == LayerDisk::L5 || layerdisk_ == LayerDisk::L6) - iseed = Seed::L5L6; - if (layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D2) - iseed = Seed::D1D2; - if (layerdisk_ == LayerDisk::D3 || layerdisk_ == LayerDisk::D4) - iseed = Seed::D3D4; - if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L3 || layerdisk_ == LayerDisk::L5 || - layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) - inner = 0; - } else if (seedtype < 'M') { - if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3) - iseed = Seed::L2L3; - if (layerdisk_ == LayerDisk::L2) - inner = 0; - } else if (seedtype <= 'Z') { - if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::D1) - iseed = Seed::L1D1; - if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::D1) - iseed = Seed::L2D1; - if (layerdisk_ == LayerDisk::L1 || layerdisk_ == LayerDisk::L2) - inner = 0; - } else if (seedtype < 'o' && seedtype >= 'a') { - if (layerdisk_ == LayerDisk::L2 || layerdisk_ == LayerDisk::L3) - iseed = Seed::L2L3D1; - if (layerdisk_ == LayerDisk::L2) - inner = 0; - } else if (seedtype > 'o' && seedtype <= 'z') { - if (layerdisk_ == LayerDisk::L2) - iseed = Seed::D1D2L2; - if (layerdisk_ == LayerDisk::D1) - iseed = Seed::L2L3D1; - inner = 2; - } else { - throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; - } - assert(iseed != -1); - int seedindex = -1; - for (unsigned int k = 0; k < vmstubsTEPHI_.size(); k++) { - if (vmstubsTEPHI_[k].seednumber == (unsigned int)iseed) { - seedindex = k; - } - } - if (seedindex == -1) { - seedindex = vmstubsTEPHI_.size(); - vector avectmp; - vector > vectmp(settings_.nvmte(inner, iseed), avectmp); - VMStubsTEPHI atmp(iseed, inner, vectmp); - vmstubsTEPHI_.push_back(atmp); - } - vmstubsTEPHI_[seedindex].vmstubmem[(vmbin - 1) & (settings_.nvmte(inner, iseed) - 1)].push_back(tmp); - - } else if (memory->getName().substr(3, 2) == "ME") { - VMStubsMEMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - vmstubsMEPHI_[(vmbin - 1) & (settings_.nvmme(layerdisk_) - 1)] = tmp; - } else { - throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " should never get here!"; - } - - return; - } - - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; -} - -void VMRouter::addInput(MemoryBase* memory, string input) { - if (settings_.writetrace()) { - edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " - << input; - } - if (input == "stubin") { - InputLinkMemory* tmp1 = dynamic_cast(memory); - assert(tmp1 != nullptr); - if (tmp1 != nullptr) { - if (layerdisk_ >= N_LAYER && tmp1->getName().find("2S_") != string::npos) { - stubinputdisk2stmp_.push_back(tmp1); - } else { - stubinputtmp_.push_back(tmp1); - } - } - //This gymnastic is done to ensure that in the disks the PS stubs are processed before - //the 2S stubs. This is needed by the current HLS implemenation of the VM router. - stubinputs_ = stubinputtmp_; - for (auto& mem : stubinputdisk2stmp_) { - stubinputs_.push_back(mem); - } - return; - } - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; -} - -void VMRouter::execute() { - unsigned int allStubCounter = 0; - - //Loop over the input stubs - for (auto& stubinput : stubinputs_) { - for (unsigned int i = 0; i < stubinput->nStubs(); i++) { - if (allStubCounter >= settings_.maxStep("VMR")) - continue; - if (allStubCounter >= (1 << N_BITSMEMADDRESS)) - continue; - Stub* stub = stubinput->getStub(i); - - //Note - below information is not part of the stub, but rather from which input memory we are reading - bool negdisk = (stub->disk().value() < 0); - - //use &127 to make sure we fit into the number of bits - - //though we should have protected against overflows above - FPGAWord allStubIndex(allStubCounter & ((1 << N_BITSMEMADDRESS) - 1), N_BITSMEMADDRESS, true, __LINE__, __FILE__); - - //TODO - should not be needed - but need to migrate some other pieces of code before removing - stub->setAllStubIndex(allStubCounter); - //TODO - should not be needed - but need to migrate some other pieces of code before removing - stub->l1tstub()->setAllStubIndex(allStubCounter); - - allStubCounter++; - - //Fill allstubs memories - in HLS this is the same write to multiple memories - for (auto& allstub : allstubs_) { - allstub->addStub(stub); - } - - //Fill all the ME VM memories - - FPGAWord iphi = stub->phicorr(); - unsigned int ivm = - iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)), - settings_.nbitsvmme(layerdisk_)); - unsigned int extrabits = iphi.bits(iphi.nbits() - overlapbits_, nextrabits_); - - unsigned int ivmPlus = ivm; - - if (extrabits == ((1U << nextrabits_) - 1) && ivm != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) - ivmPlus++; - unsigned int ivmMinus = ivm; - if (extrabits == 0 && ivm != 0) - ivmMinus--; - - //Calculate the z and r position for the vmstub - - //Take the top nbitszfinebintable_ bits of the z coordinate - int indexz = (((1 << (stub->z().nbits() - 1)) + stub->z().value()) >> (stub->z().nbits() - nbitszfinebintable_)); - int indexr = -1; - if (layerdisk_ > (N_LAYER - 1)) { - if (negdisk) { - indexz = (1 << nbitszfinebintable_) - indexz; - } - indexr = stub->r().value(); - if (stub->isPSmodule()) { - indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_); - } - } else { - //Take the top nbitsfinebintable_ bits of the z coordinate. The & is to handle the negative z values. - indexr = (((1 << (stub->r().nbits() - 1)) + stub->r().value()) >> (stub->r().nbits() - nbitsrfinebintable_)); - } - - assert(indexz >= 0); - assert(indexr >= 0); - assert(indexz < (1 << nbitszfinebintable_)); - assert(indexr < (1 << nbitsrfinebintable_)); - - int melut = meTable_.lookup((indexz << nbitsrfinebintable_) + indexr); - assert(melut >= 0); - - int vmbin = melut >> 3; - if (negdisk) - vmbin += 8; - int rzfine = melut & 7; - - // pad disk PS bend word with a '0' in MSB so that all disk bends have 4 bits (for HLS compatibility) - int nbendbits = stub->bend().nbits(); - if (layerdisk_ >= N_LAYER) - nbendbits = settings_.nbendbitsmedisk(); - - VMStubME vmstub(stub, - stub->iphivmFineBins(settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_), 3), - FPGAWord(rzfine, 3, true, __LINE__, __FILE__), - FPGAWord(stub->bend().value(), nbendbits, true, __LINE__, __FILE__), - allStubIndex); - - if (!(settings_.reduced())) - assert(vmstubsMEPHI_[ivmPlus] != nullptr); - if (vmstubsMEPHI_[ivmPlus] != nullptr) - vmstubsMEPHI_[ivmPlus]->addStub(vmstub, vmbin); - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << vmstubsMEPHI_[ivmPlus]->getName() - << " ivmPlus" << ivmPlus << " bin=" << vmbin; - } - - if (ivmMinus != ivmPlus && vmstubsMEPHI_[ivmMinus] != nullptr) { - vmstubsMEPHI_[ivmMinus]->addStub(vmstub, vmbin); - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << vmstubsMEPHI_[ivmMinus]->getName() - << " ivmMinus" << ivmMinus << " bin=" << vmbin; - } - } - - //Fill the TE VM memories - - for (auto& ivmstubTEPHI : vmstubsTEPHI_) { - unsigned int iseed = ivmstubTEPHI.seednumber; - unsigned int inner = ivmstubTEPHI.stubposition; - if ((iseed == Seed::D1D2 || iseed == Seed::D3D4 || iseed == Seed::L1D1 || iseed == Seed::L2D1) && - (!stub->isPSmodule())) - continue; - - unsigned int lutwidth = settings_.lutwidthtab(inner, iseed); - if (settings_.extended()) { - lutwidth = settings_.lutwidthtabextended(inner, iseed); - } - - int lutval = -999; - - if (inner > 0) { - if (layerdisk_ < N_LAYER) { - lutval = melut; - } else { - if (inner == 2 && iseed == Seed::L2L3D1) { - lutval = 0; - if (stub->r().value() < 10) { - lutval = 8 * (1 + (stub->r().value() >> 2)); - } else { - if (stub->r().value() < settings_.rmindiskl3overlapvm() / settings_.kr()) { - lutval = -1; - } - } - } else { - lutval = diskTable_.lookup((indexz << nbitsrfinebintable_) + indexr); - } - } - if (lutval == -1) - continue; - } else { - if (iseed < Seed::L1D1 || iseed > Seed::L2D1) { - lutval = innerTable_.lookup((indexz << nbitsrfinebintable_) + indexr); - } else { - lutval = innerOverlapTable_.lookup((indexz << nbitsrfinebintable_) + indexr); - } - if (lutval == -1) - continue; - if (settings_.extended() && - (iseed == Seed::L3L4 || iseed == Seed::L5L6 || iseed == Seed::D1D2 || iseed == Seed::L2L3D1)) { - int lutval2 = innerThirdTable_.lookup((indexz << nbitsrfinebintable_) + indexr); - if (lutval2 != -1) - lutval += (lutval2 << 10); - } - } - - assert(lutval >= 0); - - FPGAWord binlookup(lutval, lutwidth, true, __LINE__, __FILE__); - - if (binlookup.value() < 0) - continue; - - unsigned int ivmte = - iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmte(inner, iseed)), - settings_.nbitsvmte(inner, iseed)); - - int bin = -1; - if (inner != 0) { - bin = binlookup.value() / 8; - unsigned int tmp = binlookup.value() & 7; //three bits in outer layers - this could be coded cleaner... - binlookup.set(tmp, 3, true, __LINE__, __FILE__); - } - - FPGAWord finephi = stub->iphivmFineBins(settings_.nphireg(inner, iseed), settings_.nfinephi(inner, iseed)); - - VMStubTE tmpstub(stub, finephi, stub->bend(), binlookup, allStubIndex); - - unsigned int nmem = ivmstubTEPHI.vmstubmem[ivmte].size(); - - if (!(settings_.reduced())) - assert(nmem > 0); - - for (unsigned int l = 0; l < nmem; l++) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " try adding stub to " - << ivmstubTEPHI.vmstubmem[ivmte][l]->getName() << " inner=" << inner - << " bin=" << bin; - } - if (inner == 0) { - ivmstubTEPHI.vmstubmem[ivmte][l]->addVMStub(tmpstub); - } else { - ivmstubTEPHI.vmstubmem[ivmte][l]->addVMStub(tmpstub, bin); - } - } - } - } - } -} diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc index b46554a4d0f1f..fb3ce38af7b30 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc @@ -65,8 +65,6 @@ VMRouterCM::VMRouterCM(string name, Settings const& settings, Globals* global) nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk_); nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk_); - - nvmmebins_ = settings_.NLONGVMBINS() * ((layerdisk_ >= N_LAYER) ? 2 : 1); //number of long z/r bins in VM } void VMRouterCM::addOutput(MemoryBase* memory, string output) { @@ -145,18 +143,13 @@ void VMRouterCM::addOutput(MemoryBase* memory, string output) { VMStubsTEPHICM atmp(iseed, inner, vectmp); vmstubsTEPHI_.push_back(atmp); } + if (!isTripletSeed) { tmp->resize(settings_.NLONGVMBINS() * settings_.nvmte(1, iseed)); vmstubsTEPHI_[seedindex].vmstubmem[0].push_back(tmp); } else { vmstubsTEPHI_[seedindex].vmstubmem[(vmbin - 1) & (settings_.nvmte(inner, iseed) - 1)].push_back(tmp); } - - } else if (memory->getName().substr(3, 2) == "ME") { - VMStubsMEMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - tmp->resize(nvmmebins_ * settings_.nvmme(layerdisk_)); - vmstubsMEPHI_.push_back(tmp); } else { throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " memory: " << memory->getName() << " => should never get here!"; @@ -260,9 +253,9 @@ void VMRouterCM::execute(unsigned int) { absz > VMROUTERCUTZL1L3L5 / settings_.kz(layerdisk_)) continue; if ((layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) && - stub->r().value() > VMROUTERCUTRD1D3 / settings_.kr()) + stub->rvalue() > VMROUTERCUTRD1D3 / settings_.kr()) continue; - if ((layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) && stub->r().value() < 2 * int(N_DSS_MOD)) + if ((layerdisk_ == LayerDisk::D1 || layerdisk_ == LayerDisk::D3) && stub->rvalue() < 2 * int(N_DSS_MOD)) continue; if (layerdisk_ == LayerDisk::L1) { if (memtype == 'M' || memtype == 'R' || memtype == 'L') { @@ -281,13 +274,7 @@ void VMRouterCM::execute(unsigned int) { allstub.second->addStub(stub); } - //Fill all the ME VM memories - unsigned int ivm = - iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)), - settings_.nbitsvmme(layerdisk_)); - //Calculate the z and r position for the vmstub - //Take the top nbitszfinebintable_ bits of the z coordinate int indexz = (stub->z().value() >> (stub->z().nbits() - nbitszfinebintable_)) & ((1 << nbitszfinebintable_) - 1); int indexr = -1; @@ -295,13 +282,13 @@ void VMRouterCM::execute(unsigned int) { if (negdisk) { indexz = ((1 << nbitszfinebintable_) - 1) - indexz; } - indexr = stub->r().value(); + indexr = stub->rvalue(); if (stub->isPSmodule()) { - indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_); + indexr = stub->rvalue() >> (stub->r().nbits() + 1 - nbitsrfinebintable_); } } else { //Take the top nbitsfinebintable_ bits of the z coordinate. The & is to handle the negative z values. - indexr = (stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_)) & ((1 << nbitsrfinebintable_) - 1); + indexr = (stub->rvalue() >> (stub->r().nbits() - nbitsrfinebintable_)) & ((1 << nbitsrfinebintable_) - 1); } assert(indexz >= 0); @@ -310,7 +297,6 @@ void VMRouterCM::execute(unsigned int) { assert(indexr < (1 << nbitsrfinebintable_)); int melut = meTable_.lookup((indexz << nbitsrfinebintable_) + indexr); - assert(melut >= 0); // The following indices are calculated in the same way as in the old @@ -339,30 +325,10 @@ void VMRouterCM::execute(unsigned int) { int melutOld = meTableOld_.lookup((indexzOld << nbitsrfinebintable_) + indexrOld); assert(melutOld >= 0); - - int vmbin = melut >> NFINERZBITS; - if (negdisk) - vmbin += (1 << NFINERZBITS); - int rzfine = melut & ((1 << NFINERZBITS) - 1); - - // pad disk PS bend word with a '0' in MSB so that all disk bends have 4 bits (for HLS compatibility) - int nbendbits = stub->bend().nbits(); - if (layerdisk_ >= N_LAYER) - nbendbits = settings_.nbendbitsmedisk(); - - VMStubME vmstub( - stub, - stub->iphivmFineBins(settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_), NFINERZBITS), - FPGAWord(rzfine, NFINERZBITS, true, __LINE__, __FILE__), - FPGAWord(stub->bend().value(), nbendbits, true, __LINE__, __FILE__), - allStubIndex); - - unsigned int nmems = vmstubsMEPHI_.size(); - - for (unsigned int i = 0; i < nmems; i++) { // allows multiple VMStubs to be written for duplicated MPs - if (vmstubsMEPHI_[i] != nullptr) - vmstubsMEPHI_[i]->addStub(vmstub, ivm * nvmmebins_ + vmbin); - } + + //Fill the TE VM memories + if (layerdisk_ >= N_LAYER && (!stub->isPSmodule())) + continue; for (auto& ivmstubTEPHI : vmstubsTEPHI_) { unsigned int iseed = ivmstubTEPHI.seednumber; diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubMERouter.cc b/L1Trigger/TrackFindingTracklet/src/VMStubMERouter.cc new file mode 100644 index 0000000000000..5d7e2358a3766 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/VMStubMERouter.cc @@ -0,0 +1,154 @@ +#include "L1Trigger/TrackFindingTracklet/interface/VMStubMERouter.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace std; +using namespace trklet; + +VMStubMERouter::VMStubMERouter(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global), meTable_(settings) { + layerdisk_ = initLayerDisk(7); + + nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk_); + nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk_); + + unsigned int region = name[12] - 'A'; + assert(region < settings_.nallstubs(layerdisk_)); + + meTable_.initVMRTable(layerdisk_, TrackletLUT::VMRTableType::me, region); //used for ME and outer TE barrel + + vmstubsMEPHI_.resize(1, nullptr); + nvmmebins_ = settings_.NLONGVMBINS() * ((layerdisk_ >= N_LAYER) ? 2 : 1); +} + +void VMStubMERouter::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + + if (output.substr(0, 10) == "allstubout") { + AllStubsMemory* tmp = dynamic_cast(memory); + allstubs_.push_back(tmp); + return; + } + + if (output == "vmstubout") { + VMStubsMEMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + tmp->resize(16 * settings_.nvmme(layerdisk_)); + assert(vmstubsMEPHI_.size()<=2); + if (vmstubsMEPHI_[0] == nullptr) { + vmstubsMEPHI_[0] = tmp; + } else { + vmstubsMEPHI_.push_back(tmp); + } + + return; + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; +} + +void VMStubMERouter::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "allstubin") { + AllStubsMemory* tmp1 = dynamic_cast(memory); + assert(tmp1 != nullptr); + if (tmp1 != nullptr) { + stubinputs_.push_back(tmp1); + } + return; + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; +} + +void VMStubMERouter::execute(unsigned int) { + unsigned int allStubCounter = 0; + + //Loop over the input stubs + for (auto& stubinput : stubinputs_) { + for (unsigned int i = 0; i < stubinput->nStubs(); i++) { + if (allStubCounter > settings_.maxStep("VMR")) + continue; + if (allStubCounter >= (1 << N_BITSMEMADDRESS)) + continue; + + FPGAWord allStubIndex(allStubCounter & ((1 << N_BITSMEMADDRESS) - 1), N_BITSMEMADDRESS, true, __LINE__, __FILE__); + const Stub* stub = stubinput->getStub(i); + allStubCounter++; + + for (auto& allstub : allstubs_) { + allstub->addStub(stub); + } + + FPGAWord iphi = stub->phicorr(); + + bool negdisk = (stub->disk().value() < 0); + //Fill all the ME VM memories + unsigned int ivm = + iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)), + settings_.nbitsvmme(layerdisk_)); + + //Calculate the z and r position for the vmstub + + //Take the top nbitszfinebintable_ bits of the z coordinate + int indexz = (stub->z().value() >> (stub->z().nbits() - nbitszfinebintable_)) & ((1 << nbitszfinebintable_) - 1); + int indexr = -1; + if (layerdisk_ > (N_LAYER - 1)) { + if (negdisk) { + indexz = ((1 << nbitszfinebintable_) - 1) - indexz; + } + indexr = stub->rvalue(); + if (stub->isPSmodule()) { + indexr = stub->rvalue() >> (stub->r().nbits() + 1 - nbitsrfinebintable_); + } + } else { + //Take the top nbitsfinebintable_ bits of the z coordinate. The & is to handle the negative z values. + indexr = (stub->rvalue() >> (stub->r().nbits() - nbitsrfinebintable_)) & ((1 << nbitsrfinebintable_) - 1); + } + + assert(indexz >= 0); + assert(indexr >= 0); + assert(indexz < (1 << nbitszfinebintable_)); + assert(indexr < (1 << nbitsrfinebintable_)); + + int melut = meTable_.lookup((indexz << nbitsrfinebintable_) + indexr); + + assert(melut >= 0); + + int vmbin = melut >> NFINERZBITS; + if (negdisk) + vmbin += (1 << NFINERZBITS); + int rzfine = melut & ((1 << NFINERZBITS) - 1); + + // pad disk PS bend word with a '0' in MSB so that all disk bends have 4 bits (for HLS compatibility) + int nbendbits = stub->bend().nbits(); + if (layerdisk_ >= N_LAYER) + nbendbits = settings_.nbendbitsmedisk(); + + VMStubME vmstub( + stub, + stub->iphivmFineBins(settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_), NFINERZBITS), + FPGAWord(rzfine, NFINERZBITS, true, __LINE__, __FILE__), + FPGAWord(stub->bend().value(), nbendbits, true, __LINE__, __FILE__), + allStubIndex); + + if (vmstubsMEPHI_[0] != nullptr) { + for (unsigned int i=0; iaddStub(vmstub, ivm * nvmmebins_ + vmbin); + } + } + } + } +} + diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc index 60d437ad2f39f..e10d85d6f15d5 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc @@ -7,8 +7,8 @@ using namespace std; using namespace trklet; VMStubsMEMemory::VMStubsMEMemory(string name, Settings const& settings) : MemoryBase(name, settings) { - unsigned int layerdisk = initLayerDisk(6); - if (layerdisk < N_LAYER) { + layerdisk_ = initLayerDisk(6); + if (layerdisk_ < N_LAYER) { binnedstubs_.resize(settings_.NLONGVMBINS()); } else { //For disks we have NLONGVMBITS on each disk @@ -22,11 +22,6 @@ void VMStubsMEMemory::writeStubs(bool first, unsigned int iSector) { std::ostringstream oss; oss << dirVM << "VMStubs_" << getName(); - //get rid of duplicates - auto const& tmp = oss.str(); - int len = tmp.size(); - if (tmp[len - 2] == 'n' && tmp[len - 1] > '1' && tmp[len - 1] <= '9') - return; oss << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); @@ -35,6 +30,8 @@ void VMStubsMEMemory::writeStubs(bool first, unsigned int iSector) { out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; for (unsigned int i = 0; i < binnedstubs_.size(); i++) { + int nbitsrz = (layerdisk_ < N_LAYER) ? 3 : 4; + unsigned int newi = 8*(i&((1<>nbitsrz); for (unsigned int j = 0; j < binnedstubs_[i].size(); j++) { string stub = binnedstubs_[i][j].stubindex().str(); stub += "|" + binnedstubs_[i][j].bend().str(); @@ -43,7 +40,8 @@ void VMStubsMEMemory::writeStubs(bool first, unsigned int iSector) { stub += "|" + finephipos.str(); FPGAWord finepos = binnedstubs_[i][j].finerz(); stub += "|" + finepos.str(); - out_ << hexstr(i) << " " << hexstr(j) << " " << stub << " " << trklet::hexFormat(stub) << endl; + + out_ << hexstr(newi) << " " << hexstr(j) << " " << stub << " " << trklet::hexFormat(stub) << endl; } } out_.close(); diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc index 8de1d3c01d225..9dd8ebe2c4202 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc @@ -194,7 +194,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub) { if (vmstub.stub()->isPSmodule()) { bin = 0; } else { - bin = vmstub.stub()->r().value(); // 0 to 9 + bin = vmstub.stub()->rvalue(); // 0 to 9 bin = bin >> 2; // 0 to 2 bin += 1; } @@ -232,9 +232,10 @@ void VMStubsTEMemory::writeStubs(bool first, unsigned int iSector) { } } else { // outer VM for TE purpose for (unsigned int i = 0; i < stubsbinnedvm_.size(); i++) { + unsigned int newi = 8*(i&7)+(i>>3); for (unsigned int j = 0; j < stubsbinnedvm_[i].size(); j++) { string stub = stubsbinnedvm_[i][j].str(); - out_ << hexstr(i) << " " << hexstr(j) << " " << stub << " " << trklet::hexFormat(stub) << endl; + out_ << hexstr(newi) << " " << hexstr(j) << " " << stub << " " << trklet::hexFormat(stub) << endl; } } } diff --git a/L1Trigger/TrackFindingTracklet/src/imath.cc b/L1Trigger/TrackFindingTracklet/src/imath.cc deleted file mode 100644 index 3f5ce5dd37ebd..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/imath.cc +++ /dev/null @@ -1,439 +0,0 @@ -// -// Integer representation of floating point arithmetic suitable for FPGA designs -// -// Author: Yuri Gershtein -// Date: March 2018 -// - -#include "L1Trigger/TrackFindingTracklet/interface/imath.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -#include - -using namespace trklet; - -std::string VarBase::itos(int i) { return std::to_string(i); } - -std::string VarBase::kstring() const { - char s[1024]; - std::string t = ""; - for (const auto &Kmap : Kmap_) { - sprintf(s, "^(%i)", Kmap.second); - std::string t0(s); - t = t + Kmap.first + t0; - } - return t; -} - -void VarBase::analyze() { - if (!readytoanalyze_) - return; - - double u = maxval_; - if (u < -minval_) - u = -minval_; - - int iu = log2(range() / u); - if (iu > 1) { - char slog[1024]; - sprintf(slog, - "analyzing %s: range %g is much larger then %g. suggest cutting by a factor of 2^%i", - name_.c_str(), - range(), - u, - iu); - edm::LogVerbatim("Tracklet") << slog; - } -#ifdef IMATH_ROOT - char slog[100]; - if (h_) { - double eff = h_->Integral() / h_->GetEntries(); - if (eff < 0.99) { - sprintf(slog, "analyzing %s: range is too small, contains %f", name_.c_str(), eff); - edm::LogVerbatim("Tracklet") << slog; - h_->Print(); - } - globals_->h_file_->cd(); - TCanvas *c = new TCanvas(); - c->cd(); - h_->Draw("colz"); - h_->Write(); - } else { - if (globals_->use_root) { - sprintf(slog, "analyzing %s: no histogram!\n", name_.c_str()); - edm::LogVerbatim("Tracklet") << slog; - } - } -#endif - - if (p1_) - p1_->analyze(); - if (p2_) - p2_->analyze(); - - readytoanalyze_ = false; -} - -std::string VarBase::dump() { - char s[1024]; - std::string u = kstring(); - sprintf( - s, - "Name = %s \t Op = %s \t nbits = %i \n ival = %li \t fval = %g \t K = %g Range = %f\n units = %s\n", - name_.c_str(), - op_.c_str(), - nbits_, - ival_, - fval_, - K_, - range(), - u.c_str()); - std::string t(s); - return t; -} - -void VarBase::dump_msg() { - char s[2048]; - std::string u = kstring(); - sprintf(s, - "Name = %s \t Op = %s \t nbits = %i \n ival = %li \t fval = %g \t K = %g Range = %f\n units = " - "%s\n step = %i, latency = %i\n", - name_.c_str(), - op_.c_str(), - nbits_, - ival_, - fval_, - K_, - range(), - u.c_str(), - step_, - latency_); - std::string t(s); - edm::LogVerbatim("Tracklet") << t; - if (p1_) - p1_->dump_msg(); - if (p2_) - p2_->dump_msg(); -} - -void VarAdjustK::adjust(double Knew, double epsilon, bool do_assert, int nbits) { - //WARNING!!! - //THIS METHID CAN BE USED ONLY FOR THE FINAL ANSWER - //THE CHANGE IN CONSTANT CAN NOT BE PROPAGATED UP THE CALCULATION TREE - - K_ = p1_->K(); - Kmap_ = p1_->Kmap(); - double r = Knew / K_; - - lr_ = (r > 1) ? log2(r) + epsilon : log2(r); - K_ = K_ * pow(2, lr_); - if (do_assert) - assert(std::abs(Knew / K_ - 1) < epsilon); - - if (nbits > 0) - nbits_ = nbits; - else - nbits_ = p1_->nbits() - lr_; - - Kmap_["2"] = Kmap_["2"] + lr_; -} - -void VarInv::initLUT(double offset) { - offset_ = offset; - double offsetI = lround(offset_ / p1_->K()); - for (int i = 0; i < Nelements_; ++i) { - int i1 = addr_to_ival(i); - LUT[i] = gen_inv(offsetI + i1); - } -} - -void VarBase::makeready() { - pipe_counter_ = 0; - pipe_delays_.clear(); - readytoprint_ = true; - readytoanalyze_ = true; - usedasinput_ = false; - if (p1_) - p1_->makeready(); - if (p2_) - p2_->makeready(); - if (p3_) - p3_->makeready(); -} - -bool VarBase::has_delay(int i) { - //dumb sequential search - for (int pipe_delay : pipe_delays_) - if (pipe_delay == i) - return true; - return false; -} - -std::string VarBase::pipe_delay(VarBase *v, int nbits, int delay) { - //have we been delayed by this much already? - if (v->has_delay(delay)) - return ""; - v->add_delay(delay); - std::string name = v->name(); - std::string name_delayed = name + "_delay" + itos(delay); - std::string out = "wire signed [" + itos(nbits - 1) + ":0] " + name_delayed + ";\n"; - out = out + pipe_delay_wire(v, name_delayed, nbits, delay); - return out; -} -std::string VarBase::pipe_delays(const int step) { - std::string out = ""; - if (p1_) - out += p1_->pipe_delays(step); - if (p2_) - out += p2_->pipe_delays(step); - if (p3_) - out += p3_->pipe_delays(step); - - int l = step - latency_ - step_; - return (out + pipe_delay(this, nbits(), l)); -} -std::string VarBase::pipe_delay_wire(VarBase *v, std::string name_delayed, int nbits, int delay) { - std::string name = v->name(); - std::string name_pipe = name + "_pipe" + itos(v->pipe_counter()); - v->pipe_increment(); - std::string out = "pipe_delay #(.STAGES(" + itos(delay) + "), .WIDTH(" + itos(nbits) + ")) " + name_pipe + - "(.clk(clk), .val_in(" + name + "), .val_out(" + name_delayed + "));\n"; - return out; -} - -void VarBase::inputs(std::vector *vd) { - if (op_ == "def" && !usedasinput_) { - usedasinput_ = true; - vd->push_back(this); - } else { - if (p1_) - p1_->inputs(vd); - if (p2_) - p2_->inputs(vd); - if (p3_) - p3_->inputs(vd); - } -} - -#ifdef IMATH_ROOT -TTree *VarBase::addToTree(imathGlobals *globals, VarBase *v, char *s) { - if (globals->h_file_ == 0) { - globals->h_file_ = new TFile("imath.root", "RECREATE"); - edm::LogVerbatim("Tracklet") << "recreating file imath.root"; - } - globals->h_file_->cd(); - TTree *tt = (TTree *)globals->h_file_->Get("tt"); - if (tt == 0) { - tt = new TTree("tt", ""); - edm::LogVerbatim("Tracklet") << "creating TTree tt"; - } - std::string si = v->name() + "_i"; - std::string sf = v->name() + "_f"; - std::string sv = v->name(); - if (s != 0) { - std::string prefix(s); - si = prefix + si; - sf = prefix + sf; - sv = prefix + sv; - } - if (!tt->GetBranchStatus(si.c_str())) { - tt->Branch(si.c_str(), (Long64_t *)&(v->ival_)); - tt->Branch(sf.c_str(), &(v->fval_)); - tt->Branch(sv.c_str(), &(v->val_)); - } - - if (v->p1_) - addToTree(globals, v->p1_, s); - if (v->p2_) - addToTree(globals, v->p2_, s); - if (v->p3_) - addToTree(globals, v->p3_, s); - - return tt; -} -TTree *VarBase::addToTree(imathGlobals *globals, double *v, char *s) { - if (globals->h_file_ == 0) { - globals->h_file_ = new TFile("imath.root", "RECREATE"); - edm::LogVerbatim("Tracklet") << "recreating file imath.root"; - } - globals->h_file_->cd(); - TTree *tt = (TTree *)globals->h_file_->Get("tt"); - if (tt == 0) { - tt = new TTree("tt", ""); - edm::LogVerbatim("Tracklet") << "creating TTree tt"; - } - tt->Branch(s, v); - return tt; -} -TTree *VarBase::addToTree(imathGlobals *globals, int *v, char *s) { - if (globals->h_file_ == 0) { - globals->h_file_ = new TFile("imath.root", "RECREATE"); - edm::LogVerbatim("Tracklet") << "recreating file imath.root"; - } - globals->h_file_->cd(); - TTree *tt = (TTree *)globals->h_file_->Get("tt"); - if (tt == 0) { - tt = new TTree("tt", ""); - edm::LogVerbatim("Tracklet") << "creating TTree tt"; - } - tt->Branch(s, v); - return tt; -} -void VarBase::fillTree(imathGlobals *globals) { - if (globals->h_file_ == 0) - return; - globals->h_file_->cd(); - TTree *tt = (TTree *)globals->h_file_->Get("tt"); - if (tt == 0) - return; - tt->Fill(); -} -void VarBase::writeTree(imathGlobals *globals) { - if (globals->h_file_ == 0) - return; - globals->h_file_->cd(); - TTree *tt = (TTree *)globals->h_file_->Get("tt"); - if (tt == 0) - return; - tt->Write(); -} - -#endif - -void VarCut::local_passes(std::map > &passes, - const std::map > *const previous_passes) const { - const int lower_cut = lower_cut_ / cut_var_->K(); - const int upper_cut = upper_cut_ / cut_var_->K(); - if (!previous_passes || (previous_passes && !previous_passes->count(cut_var_))) { - if (!passes.count(cut_var_)) - passes[cut_var_]; - passes.at(cut_var_).push_back(cut_var_->ival() > lower_cut && cut_var_->ival() < upper_cut); - } -} - -bool VarBase::local_passes() const { - bool passes = false; - for (const auto &cut : cuts_) { - const VarCut *const cast_cut = (VarCut *)cut; - const int lower_cut = cast_cut->lower_cut() / K_; - const int upper_cut = cast_cut->upper_cut() / K_; - passes = passes || (ival_ > lower_cut && ival_ < upper_cut); - if (globals_->printCutInfo_) { - edm::LogVerbatim("Tracklet") << " " << name_ << " " - << ((ival_ > lower_cut && ival_ < upper_cut) ? "PASSES" : "FAILS") - << " (required: " << lower_cut * K_ << " < " << ival_ * K_ << " < " << upper_cut * K_ - << ")"; - } - } - return passes; -} - -void VarBase::passes(std::map > &passes, - const std::map > *const previous_passes) const { - if (p1_) - p1_->passes(passes, previous_passes); - if (p2_) - p2_->passes(passes, previous_passes); - if (p3_) - p3_->passes(passes, previous_passes); - - for (const auto &cut : cuts_) { - const VarCut *const cast_cut = (VarCut *)cut; - const int lower_cut = cast_cut->lower_cut() / K_; - const int upper_cut = cast_cut->upper_cut() / K_; - if (!previous_passes || (previous_passes && !previous_passes->count(this))) { - if (!passes.count(this)) - passes[this]; - passes.at(this).push_back(ival_ > lower_cut && ival_ < upper_cut); - if (globals_->printCutInfo_) { - edm::LogVerbatim("Tracklet") << " " << name_ << " " - << ((ival_ > lower_cut && ival_ < upper_cut) ? "PASSES" : "FAILS") - << " (required: " << lower_cut * K_ << " < " << ival_ * K_ << " < " - << upper_cut * K_ << ")"; - } - } - } -} - -void VarBase::add_cut(VarCut *cut, const bool call_set_cut_var) { - cuts_.push_back(cut); - if (call_set_cut_var) - cut->set_cut_var(this, false); -} - -void VarCut::set_cut_var(VarBase *cut_var, const bool call_add_cut) { - cut_var_ = cut_var; - if (call_add_cut) - cut_var->add_cut(this, false); - if (parent_flag_) - parent_flag_->calculate_step(); -} - -void VarFlag::add_cut(VarBase *cut, const bool call_set_parent_flag) { - cuts_.push_back(cut); - if (cut->op() == "cut" && call_set_parent_flag) { - VarCut *const cast_cut = (VarCut *)cut; - cast_cut->set_parent_flag(this, false); - } - calculate_step(); -} - -void VarCut::set_parent_flag(VarFlag *parent_flag, const bool call_add_cut) { - parent_flag_ = parent_flag; - if (call_add_cut) - parent_flag->add_cut(this, false); -} - -VarBase *VarBase::cut_var() { - if (op_ == "cut") - return cut_var_; - else - return this; -} - -bool VarFlag::passes() { - if (globals_->printCutInfo_) { - edm::LogVerbatim("Tracklet") << "Checking if " << name_ << " passes..."; - } - - std::map > passes0, passes1; - for (const auto &cut : cuts_) { - if (cut->op() != "cut") - continue; - const VarCut *const cast_cut = (VarCut *)cut; - cast_cut->local_passes(passes0); - } - for (const auto &cut : cuts_) { - if (cut->op() != "cut") - cut->passes(passes1, &passes0); - else { - if (cut->cut_var()->p1()) - cut->cut_var()->p1()->passes(passes1, &passes0); - if (cut->cut_var()->p2()) - cut->cut_var()->p2()->passes(passes1, &passes0); - if (cut->cut_var()->p3()) - cut->cut_var()->p3()->passes(passes1, &passes0); - } - } - - bool passes = true; - for (const auto &cut_var : passes0) { - bool local_passes = false; - for (const auto pass : cut_var.second) - local_passes = local_passes || pass; - passes = passes && local_passes; - } - for (const auto &cut_var : passes1) { - bool local_passes = false; - for (const auto pass : cut_var.second) - local_passes = local_passes || pass; - passes = passes && local_passes; - } - - if (globals_->printCutInfo_) { - edm::LogVerbatim("Tracklet") << name_ << " " << (passes ? "PASSES" : "FAILS"); - } - - return passes; -} diff --git a/L1Trigger/TrackFindingTracklet/src/imath_HLS.cc b/L1Trigger/TrackFindingTracklet/src/imath_HLS.cc deleted file mode 100644 index c3f5b3d1268ec..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/imath_HLS.cc +++ /dev/null @@ -1,404 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/imath.h" - -using namespace trklet; - -void VarInv::writeLUT(std::ofstream& fs, HLS) const { - for (int i = 0; i < Nelements_ - 1; ++i) - fs << "0x" << std::hex << (LUT[i] & ((1 << nbits_) - 1)) << std::dec << ",\n"; - fs << "0x" << std::hex << (LUT[Nelements_ - 1] & ((1 << nbits_) - 1)) << std::dec << "\n"; -} - -void VarBase::print_truncation(std::string& t, const std::string& o1, const int ps, HLS) const { - if (ps > 0) { - t += "const ap_int<" + itos(nbits_ + ps) + "> " + name_ + "_tmp = " + o1 + ";\n"; - t += "const ap_int<" + itos(nbits_) + "> " + name_ + " = " + name_ + "_tmp >> " + itos(ps) + ";\n"; - } else - t += "const ap_int<" + itos(nbits_) + "> " + name_ + " = " + o1 + ";\n"; -} - -// -// print functions -// - -void VarCut::print(std::map >& cut_strings, - const int step, - HLS, - const std::map >* const previous_cut_strings) const { - assert(step > -1); - std::string name = cut_var_->name(); - - const int lower_cut = lower_cut_ / cut_var_->K(); - const int upper_cut = upper_cut_ / cut_var_->K(); - if (!previous_cut_strings || (previous_cut_strings && !previous_cut_strings->count(cut_var_))) { - if (!cut_strings.count(cut_var_)) - cut_strings[cut_var_]; - cut_strings.at(cut_var_).insert(name + " > " + itos(lower_cut) + " && " + name + " < " + itos(upper_cut)); - } -} - -void VarBase::print_cuts(std::map >& cut_strings, - const int step, - HLS, - const std::map >* const previous_cut_strings) const { - if (p1_) - p1_->print_cuts(cut_strings, step, hls, previous_cut_strings); - if (p2_) - p2_->print_cuts(cut_strings, step, hls, previous_cut_strings); - if (p3_) - p3_->print_cuts(cut_strings, step, hls, previous_cut_strings); - - std::string name = name_; - - for (const auto& cut : cuts_) { - const VarCut* const cast_cut = (VarCut*)cut; - const int lower_cut = cast_cut->lower_cut() / K_; - const int upper_cut = cast_cut->upper_cut() / K_; - if (!previous_cut_strings || (previous_cut_strings && !previous_cut_strings->count(this))) { - if (!cut_strings.count(this)) - cut_strings[this]; - cut_strings.at(this).insert(name + " > " + itos(lower_cut) + " && " + name + " < " + itos(upper_cut)); - } - } -} - -void VarAdjustK::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(p1_); - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - - std::string shift = ""; - if (lr_ > 0) - shift = " >> " + itos(lr_); - else if (lr_ < 0) - shift = " << " + itos(-lr_); - - std::string n1 = p1_->name(); - - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n"; - fs << "const ap_int<" << nbits_ << "> " << name_ << " = " << n1 << shift << ";\n"; -} - -void VarAdjustKR::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(p1_); - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - - std::string n1 = p1_->name(); - - std::string o1 = n1; - if (lr_ == 1) - o1 = "(" + o1 + "+1)>>1"; - if (lr_ > 1) - o1 = "( (" + o1 + ">>" + itos(lr_ - 1) + ")+1)>>1"; - if (lr_ < 0) - o1 = "ap_int<" + itos(nbits_) + ">(" + o1 + ")<<" + itos(-lr_); - - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n"; - fs << "const ap_int<" << nbits_ << "> " << name_ << " = " << o1 << ";\n"; -} - -void VarDef::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - - fs << "// units " << kstring() << "\t" << K_ << "\n"; - fs << "const ap_int<" << nbits_ << "> " << name_ << " = " << name_ << "_wire;\n"; -} - -void VarParam::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n"; - fs << "static const ap_int<" << nbits_ << "> " << name_ << " = " << ival_ << ";\n"; -} - -void VarAdd::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(p1_); - assert(p2_); - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - std::string o1 = p1_->name(); - if (shift1 > 0) { - o1 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o1 + ")"; - o1 += "<<" + itos(shift1); - o1 = "(" + o1 + ")"; - } - - std::string o2 = p2_->name(); - if (shift2 > 0) { - o2 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o2 + ")"; - o2 += "<<" + itos(shift2); - o2 = "(" + o2 + ")"; - } - - o1 = o1 + " + " + o2; - - std::string t = ""; - print_truncation(t, o1, ps_, hls); - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; -} - -void VarSubtract::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(p1_); - assert(p2_); - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - std::string o1 = p1_->name(); - if (shift1 > 0) { - o1 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o1 + ")"; - o1 += "<<" + itos(shift1); - o1 = "(" + o1 + ")"; - } - - std::string o2 = p2_->name(); - if (shift2 > 0) { - o2 = "ap_int<" + itos(nbits_ + ps_) + ">(" + o2 + ")"; - o2 += "<<" + itos(shift2); - o2 = "(" + o2 + ")"; - } - - o1 = o1 + " - " + o2; - - std::string t = ""; - print_truncation(t, o1, ps_, hls); - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; -} - -void VarNounits::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(p1_); - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - std::string n1 = p1_->name(); - std::string o1 = "(" + n1 + " * " + itos(cI_) + ")"; - - std::string t = ""; - print_truncation(t, o1, ps_, hls); - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; -} - -void VarTimesC::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(p1_); - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - std::string n1 = p1_->name(); - std::string o1 = "(" + n1 + " * " + itos(cI_) + ")"; - - std::string t = ""; - print_truncation(t, o1, ps_, hls); - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; -} - -void VarNeg::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(p1_); - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - std::string n1 = p1_->name(); - - std::string t = "const ap_int<" + itos(nbits_) + "> " + name_ + " = -" + n1 + ";\n"; - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; -} - -void VarShiftround::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(p1_); - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - std::string n1 = p1_->name(); - std::string o1 = n1; - if (shift_ == 1) - o1 = "(" + o1 + "+1)>>1"; - if (shift_ > 1) - o1 = "( (" + o1 + ">>" + itos(shift_ - 1) + ")+1)>>1"; - if (shift_ < 0) - o1 = "ap_int<" + itos(nbits_) + ">(" + o1 + ")<<" + itos(-shift_); - - std::string t = "const ap_int<" + itos(nbits_) + "> " + name_ + " = " + o1 + ";\n"; - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; -} - -void VarShift::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(p1_); - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - std::string n1 = p1_->name(); - std::string o1 = n1; - if (shift_ > 0) - o1 = o1 + ">>" + itos(shift_); - if (shift_ < 0) - o1 = "ap_int<" + itos(nbits_) + ">(" + o1 + ")<<" + itos(-shift_); - - std::string t = "const ap_int<" + itos(nbits_) + "> " + name_ + " = " + o1 + ";\n"; - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; -} - -void VarMult::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - assert(p1_); - std::string n1 = p1_->name(); - assert(p2_); - std::string n2 = p2_->name(); - std::string o1 = n1 + " * " + n2; - - std::string t = ""; - print_truncation(t, o1, ps_, hls); - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; -} - -void VarInv::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(p1_); - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - - fs << "static const ap_int<" << itos(nbits_) << "> LUT_" << name_ << "[" << Nelements_ << "] = {\n"; - fs << "#include \"LUT_" << name_ << ".h\"\n"; - fs << "};\n"; - - std::string n1 = p1_->name(); - //first calculate address - std::string t1 = "addr_" + name_; - std::string t = "const ap_uint<" + itos(nbaddr_) + "> " + t1 + " = "; - if (shift_ > 0) - t = t + "(" + n1 + ">>" + itos(shift_) + ") & " + itos(mask_); - else - t = t + n1 + " & " + itos(mask_); - fs << t << "; // address for the LUT\n"; - - t = "const ap_int<" + itos(nbits_) + "> " + name_ + " = LUT_" + name_ + "[addr_" + name_ + "];\n"; - fs << t; -} - -void VarFlag::print(std::ofstream& fs, HLS, int l1, int l2, int l3) { - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - - fs << "const ap_int<1> " << name_ << " = ("; - std::map > cut_strings0, cut_strings1; - for (const auto& cut : cuts_) { - if (cut->op() != "cut") - continue; - const VarCut* const cast_cut = (VarCut*)cut; - cast_cut->print(cut_strings0, step_, hls); - } - for (const auto& cut : cuts_) { - if (cut->op() != "cut") - cut->print_cuts(cut_strings1, step_, hls, &cut_strings0); - else { - if (cut->cut_var()->p1()) - cut->cut_var()->p1()->print_cuts(cut_strings1, step_, hls, &cut_strings1); - if (cut->cut_var()->p2()) - cut->cut_var()->p2()->print_cuts(cut_strings1, step_, hls, &cut_strings1); - if (cut->cut_var()->p3()) - cut->cut_var()->p3()->print_cuts(cut_strings1, step_, hls, &cut_strings1); - } - } - - std::string separator = ""; - for (const auto& cut_var : cut_strings0) { - separator += "(("; - for (const auto& cut_string : cut_var.second) { - fs << separator << cut_string; - separator = ") || ("; - } - separator = ")) && "; - } - for (const auto& cut_var : cut_strings1) { - separator += "(("; - for (const auto& cut_string : cut_var.second) { - fs << separator << cut_string; - separator = ") || ("; - } - separator = ")) && "; - } - - fs << ")));"; -} - -void VarBase::print_step(int step, std::ofstream& fs, HLS) { - if (!readytoprint_) - return; - if (step > step_) - return; - if (p1_) - p1_->print_step(step, fs, hls); - if (p2_) - p2_->print_step(step, fs, hls); - if (p3_) - p3_->print_step(step, fs, hls); - if (step == step_) { - print(fs, hls, 0, 0, 0); - readytoprint_ = false; - } -} - -void VarBase::print_all(std::ofstream& fs, HLS) { - for (int i = 0; i <= step_; ++i) { - fs << "//\n// STEP " << i << "\n\n"; - print_step(i, fs, hls); - } -} - -void VarBase::design_print(const std::vector& v, std::ofstream& fs, HLS) { - //header of the module - - //inputs - std::vector vd; - vd.clear(); - int imax = v.size(); - for (int i = 0; i < imax; ++i) - (v[i])->inputs(&vd); - - //print header - fs << "#include \"ap_int.h\"\n\n"; - fs << "void XXX (\n"; - - imax = vd.size(); - for (int i = 0; i < imax; ++i) - fs << " const ap_int<" << (vd[i])->nbits() << "> " << (vd[i])->name() << "_wire,\n"; - fs << "\n"; - - imax = v.size() - 1; - for (int i = 0; i < imax; ++i) - fs << " ap_int<" << (v[i])->nbits() << "> * const " << (v[i])->name() << "_wire,\n"; - if (imax >= 0) - fs << " ap_int<" << (v[imax])->nbits() << "> * const " << (v[imax])->name() << "_wire\n"; - fs << ")\n{\n"; - fs << "#pragma HLS pipeline II=1\n"; - fs << "#pragma HLS latency max=25\n"; - - //body of the module - imax = v.size(); - for (int i = 0; i < imax; ++i) { - fs << "\n//\n"; - fs << "// calculating " << (v[i])->name() << "\n"; - fs << "//\n"; - (v[i])->print_all(fs, hls); - } - fs << "\n"; - - //trailer - fs << "\n"; - fs << "\n//\n"; - fs << "// wiring the outputs \n"; - fs << "//\n"; - for (int i = 0; i < imax; ++i) { - std::string n = v[i]->name() + "_wire"; - fs << "*" << n << " = " << (v[i])->name() << ";\n"; - } - - fs << "}\n"; -} diff --git a/L1Trigger/TrackFindingTracklet/src/imath_Verilog.cc b/L1Trigger/TrackFindingTracklet/src/imath_Verilog.cc deleted file mode 100644 index b5707da78929a..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/imath_Verilog.cc +++ /dev/null @@ -1,534 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/imath.h" - -using namespace trklet; - -void VarInv::writeLUT(std::ofstream& fs, Verilog) const { - for (int i = 0; i < Nelements_; ++i) - fs << std::hex << (LUT[i] & ((1 << nbits_) - 1)) << std::dec << "\n"; -} - -void VarBase::print_truncation(std::string& t, const std::string& o1, const int ps, Verilog) const { - if (ps > 0) { - t += "wire signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; - t += "reg signed [" + itos(nbits_ + ps - 1) + ":0]" + name_ + "_tmp;\n"; - t += "always @(posedge clk) " + name_ + "_tmp <= " + o1 + ";\n"; - t += "assign " + name_ + " = " + name_ + "_tmp[" + itos(nbits_ + ps - 1) + ":" + itos(ps) + "];\n"; - } else { - t += "reg signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; - t += "always @(posedge clk) " + name_ + " <= " + o1 + ";\n"; - } -} - -// -// print functions -// - -void VarCut::print(std::map >& cut_strings, - const int step, - Verilog, - const std::map >* const previous_cut_strings) const { - int l = step - cut_var_->latency() - cut_var_->step(); - std::string name = cut_var_->name(); - if (l > 0) - name += "_delay" + itos(l); - - const int lower_cut = lower_cut_ / cut_var_->K(); - const int upper_cut = upper_cut_ / cut_var_->K(); - if (!previous_cut_strings || (previous_cut_strings && !previous_cut_strings->count(cut_var_))) { - if (!cut_strings.count(cut_var_)) - cut_strings[cut_var_]; - cut_strings.at(cut_var_).insert(name + " > " + itos(lower_cut) + " && " + name + " < " + itos(upper_cut)); - } -} - -void VarBase::print_cuts(std::map >& cut_strings, - const int step, - Verilog, - const std::map >* const previous_cut_strings) const { - if (p1_) - p1_->print_cuts(cut_strings, step, verilog, previous_cut_strings); - if (p2_) - p2_->print_cuts(cut_strings, step, verilog, previous_cut_strings); - if (p3_) - p3_->print_cuts(cut_strings, step, verilog, previous_cut_strings); - - int l = step - latency_ - step_; - std::string name = name_; - if (l > 0) - name += "_delay" + itos(l); - - for (const auto& cut : cuts_) { - const VarCut* const cast_cut = (VarCut*)cut; - const int lower_cut = cast_cut->lower_cut() / K_; - const int upper_cut = cast_cut->upper_cut() / K_; - if (!previous_cut_strings || (previous_cut_strings && !previous_cut_strings->count(this))) { - if (!cut_strings.count(this)) - cut_strings[this]; - cut_strings.at(this).insert(name + " > " + itos(lower_cut) + " && " + name + " < " + itos(upper_cut)); - } - } -} - -void VarAdjustK::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(p1_); - assert(l2 == 0); - assert(l3 == 0); - - std::string shift = ""; - if (lr_ > 0) - shift = " >>> " + itos(lr_); - else if (lr_ < 0) - shift = " << " + itos(-lr_); - - std::string n1 = p1_->name(); - if (l1 > 0) - n1 = n1 + "_delay" + itos(l1); - - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n"; - std::string t = "wire signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; - t += "assign " + name_ + " = " + n1 + shift; - fs << t << "; \n"; -} - -void VarAdjustKR::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(p1_); - assert(l2 == 0); - assert(l3 == 0); - - std::string n1 = p1_->name(); - if (l1 > 0) - n1 = n1 + "_delay" + itos(l1); - - std::string o1 = n1; - if (lr_ == 1) - o1 = "(" + o1 + "+1)>>>1"; - if (lr_ > 1) - o1 = "( (" + o1 + ">>>" + itos(lr_ - 1) + ")+1)>>>1"; - if (lr_ < 0) - o1 = o1 + "<<" + itos(-lr_); - - std::string t = "reg signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; - t += "always @(posedge clk) " + name_ + " <= " + o1; - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; -} - -void VarDef::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - - std::string t = "reg signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; - t = t + "always @(posedge clk) " + name_ + " <= " + name_ + "_wire;\n"; - fs << "// units " << kstring() << "\t" << K_ << "\n" << t; -} - -void VarParam::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - std::string t = "parameter " + name_ + " = "; - if (ival_ < 0) - t = t + "- " + itos(nbits_) + "\'sd" + itos(-ival_); - else - t = t + itos(nbits_) + "\'sd" + itos(ival_); - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; -} - -void VarAdd::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(p1_); - assert(p2_); - assert(l3 == 0); - std::string o1 = p1_->name(); - if (l1 > 0) - o1 += "_delay" + itos(l1); - if (shift1 > 0) { - o1 += "<<" + itos(shift1); - o1 = "(" + o1 + ")"; - } - - std::string o2 = p2_->name(); - if (l2 > 0) - o2 += "_delay" + itos(l2); - if (shift2 > 0) { - o2 += "<<" + itos(shift2); - o2 = "(" + o2 + ")"; - } - - o1 = o1 + " + " + o2; - - std::string t = ""; - print_truncation(t, o1, ps_, verilog); - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; -} - -void VarSubtract::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(p1_); - assert(p2_); - assert(l3 == 0); - std::string o1 = p1_->name(); - if (l1 > 0) - o1 += "_delay" + itos(l1); - if (shift1 > 0) { - o1 += "<<" + itos(shift1); - o1 = "(" + o1 + ")"; - } - - std::string o2 = p2_->name(); - if (l2 > 0) - o2 += "_delay" + itos(l2); - if (shift2 > 0) { - o2 += "<<" + itos(shift2); - o2 = "(" + o2 + ")"; - } - - o1 = o1 + " - " + o2; - - std::string t = ""; - print_truncation(t, o1, ps_, verilog); - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; -} - -void VarNounits::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(p1_); - assert(l2 == 0); - assert(l3 == 0); - std::string n1 = p1_->name(); - if (l1 > 0) - n1 = n1 + "_delay" + itos(l1); - std::string o1 = "(" + n1 + " * " + itos(cI_) + ")"; - - std::string t = ""; - print_truncation(t, o1, ps_, verilog); - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; -} - -void VarTimesC::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(p1_); - assert(l2 == 0); - assert(l3 == 0); - std::string n1 = p1_->name(); - if (l1 > 0) - n1 = n1 + "_delay" + itos(l1); - std::string o1 = "(" + n1 + " * " + itos(cI_) + ")"; - - std::string t = ""; - print_truncation(t, o1, ps_, verilog); - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; -} - -void VarNeg::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(p1_); - assert(l2 == 0); - assert(l3 == 0); - std::string n1 = p1_->name(); - if (l1 > 0) - n1 = n1 + "_delay" + itos(l1); - - std::string t = "reg signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; - t += "always @(posedge clk) " + name_ + " <= - " + n1; - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; -} - -void VarShiftround::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(p1_); - assert(l2 == 0); - assert(l3 == 0); - std::string n1 = p1_->name(); - if (l1 > 0) - n1 = n1 + "_delay" + itos(l1); - std::string o1 = n1; - if (shift_ == 1) - o1 = "(" + o1 + "+1)>>>1"; - if (shift_ > 1) - o1 = "( (" + o1 + ">>>" + itos(shift_ - 1) + ")+1)>>>1"; - if (shift_ < 0) - o1 = o1 + "<<" + itos(-shift_); - - std::string t = "reg signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; - t += "always @(posedge clk) " + name_ + " <= " + o1; - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; -} - -void VarShift::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(p1_); - assert(l2 == 0); - assert(l3 == 0); - std::string n1 = p1_->name(); - if (l1 > 0) - n1 = n1 + "_delay" + itos(l1); - std::string o1 = n1; - if (shift_ > 0) - o1 = o1 + ">>>" + itos(shift_); - if (shift_ < 0) - o1 = o1 + "<<" + itos(-shift_); - - std::string t = "wire signed [" + itos(nbits_ - 1) + ":0]" + name_ + ";\n"; - t += "assign " + name_ + " = " + o1; - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t << ";\n"; -} - -void VarMult::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(l3 == 0); - assert(p1_); - std::string n1 = p1_->name(); - if (l1 > 0) - n1 = n1 + "_delay" + itos(l1); - assert(p2_); - std::string n2 = p2_->name(); - if (l2 > 0) - n2 = n2 + "_delay" + itos(l2); - std::string o1 = n1 + " * " + n2; - - std::string t = ""; - print_truncation(t, o1, ps_, verilog); - fs << "// " << nbits_ << " bits \t " << kstring() << "\t" << K_ << "\n" << t; -} - -void VarInv::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(p1_); - assert(l2 == 0); - assert(l3 == 0); - std::string n1 = p1_->name(); - if (l1 > 0) - n1 = n1 + "_delay" + itos(l1); - //first calculate address - std::string t1 = "addr_" + name_; - std::string t = "wire [" + itos(nbaddr_ - 1) + ":0] " + t1 + ";\n"; - t = t + "assign " + t1 + " = "; - if (shift_ > 0) - t = t + "(" + n1 + ">>>" + itos(shift_) + ") & " + itos(mask_); - else - t = t + n1 + " & " + itos(mask_); - fs << t << "; // address for the LUT\n"; - - t = "wire signed [" + itos(nbits_ - 1) + ":0] " + name_ + ";\n"; - fs << t; - - std::string t2 = "LUT_" + name_; - - fs << "Memory #( \n"; - fs << " .RAM_WIDTH(" << nbits_ << "), // Specify RAM data width \n"; - fs << " .RAM_DEPTH(" << Nelements_ << "), // Specify RAM depth (number of entries) \n"; - fs << " .RAM_PERFORMANCE(\"HIGH_PERFORMANCE\"), // \"HIGH_PERFORMANCE\" = 2 clks latency \n"; - fs << " .INIT_FILE() \n"; - fs << " ) " << t2 << " ( \n"; - fs << " .addra(" << itos(nbaddr_) << "\'b0), // Write address bus, width determined from RAM_DEPTH \n"; - fs << " .addrb(" << t1 << " ), // Read address bus, width determined from RAM_DEPTH \n"; - fs << " .dina(" << itos(nbits_) << "\'b0), // RAM input data, width determined from RAM_WIDTH \n"; - fs << " .clka(clk), // Write clock \n"; - fs << " .clkb(clk), // Read clock \n"; - fs << " .wea(1\'b0), // Write enable \n"; - fs << " .enb(1\'b1), // Read Enable, for additional power savings, disable when not in use \n"; - fs << " .rstb(reset), // Output reset (does not affect memory contents) \n"; - fs << " .regceb(1\'b1), // Output register enable \n"; - fs << " .doutb(" << name_ << ") // RAM output data, \n"; - fs << " ); \n"; -} - -void VarDSPPostadd::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(p1_); - assert(p2_); - assert(p3_); - std::string n1 = p1_->name(); - if (l1 > 0) - n1 = n1 + "_delay" + itos(l1); - std::string n2 = p2_->name(); - if (l2 > 0) - n2 = n2 + "_delay" + itos(l2); - std::string n3 = p3_->name(); - if (l3 > 0) - n3 = n3 + "_delay" + itos(l3); - - if (shift3_ > 0) - n3 = n3 + "<<" + itos(shift3_); - if (shift3_ < 0) - n3 = n3 + ">>>" + itos(-shift3_); - - std::string n4 = ""; - if (ps_ > 0) - n4 = ">>>" + itos(ps_); - - fs << name_ + " = DSP_postadd(" + n1 + ", " + n2 + ", " + n3 + ")" + n4 + ";"; -} - -void VarFlag::print(std::ofstream& fs, Verilog, int l1, int l2, int l3) { - assert(l1 == 0); - assert(l2 == 0); - assert(l3 == 0); - - fs << "wire " << name_ << ";" << std::endl; - fs << "assign " << name_ << " = ("; - std::map > cut_strings0, cut_strings1; - for (const auto& cut : cuts_) { - if (cut->op() != "cut") - continue; - const VarCut* const cast_cut = (VarCut*)cut; - cast_cut->print(cut_strings0, step_, verilog); - } - for (const auto& cut : cuts_) { - if (cut->op() != "cut") - cut->print_cuts(cut_strings1, step_, verilog, &cut_strings0); - else { - if (cut->cut_var()->p1()) - cut->cut_var()->p1()->print_cuts(cut_strings1, step_, verilog, &cut_strings1); - if (cut->cut_var()->p2()) - cut->cut_var()->p2()->print_cuts(cut_strings1, step_, verilog, &cut_strings1); - if (cut->cut_var()->p3()) - cut->cut_var()->p3()->print_cuts(cut_strings1, step_, verilog, &cut_strings1); - } - } - - std::string separator = ""; - for (const auto& cut_var : cut_strings0) { - separator += "(("; - for (const auto& cut_string : cut_var.second) { - fs << separator << cut_string; - separator = ") || ("; - } - separator = ")) && "; - } - for (const auto& cut_var : cut_strings1) { - separator += "(("; - for (const auto& cut_string : cut_var.second) { - fs << separator << cut_string; - separator = ") || ("; - } - separator = ")) && "; - } - - fs << ")));"; -} - -void VarBase::print_step(int step, std::ofstream& fs, Verilog) { - if (!readytoprint_) - return; - if (step > step_) - return; - int l1 = 0; - int l2 = 0; - int l3 = 0; - if (p1_) { - p1_->print_step(step, fs, verilog); - l1 = step_ - p1_->latency() - p1_->step(); - } - if (p2_) { - p2_->print_step(step, fs, verilog); - l2 = step_ - p2_->latency() - p2_->step(); - } - if (p3_) { - p3_->print_step(step, fs, verilog); - l3 = step_ - p3_->latency() - p3_->step(); - } - if (step == step_) { - if (l1 < 0 || l2 < 0 || l3 < 0 || (l1 > 0 && l2 > 0 && l3 > 0)) { - char slog[100]; - sprintf(slog, "%s::print_step(%i): something wrong with latencies! %i %i %i\n", name_.c_str(), step, l1, l2, l3); - edm::LogVerbatim("Tracklet") << slog; - dump_msg(); - assert(0); - } - if (l1 > 0) { - if (p1_->op() != "const") - fs << pipe_delay(p1_, p1_->nbits(), l1); - else - l1 = 0; - } - if (l2 > 0) { - if (p2_->op() != "const") - fs << pipe_delay(p2_, p2_->nbits(), l2); - else - l2 = 0; - } - if (l3 > 0) { - if (p3_->op() != "const") - fs << pipe_delay(p3_, p3_->nbits(), l3); - else - l3 = 0; - } - - if (op_ == "flag") { - for (const auto& cut : cuts_) - fs << cut->cut_var()->pipe_delays(step_); - } - - print(fs, verilog, l1, l2, l3); - readytoprint_ = false; - } -} - -void VarBase::print_all(std::ofstream& fs, Verilog) { - for (int i = 0; i <= step_; ++i) { - fs << "//\n// STEP " << i << "\n\n"; - print_step(i, fs, verilog); - } -} - -void VarBase::design_print(const std::vector& v, std::ofstream& fs, Verilog) { - //step at which all the outputs should be valid - int maxstep = 0; - - //header of the module - - //inputs - std::vector vd; - vd.clear(); - int imax = v.size(); - for (int i = 0; i < imax; ++i) { - (v[i])->inputs(&vd); - int step = v[i]->step() + v[i]->latency(); - if (step > maxstep) - maxstep = step; - } - - //print header - fs << "module \n"; - fs << "(\n"; - fs << " input clk,\n"; - fs << " input reset,\n\n"; - - imax = vd.size(); - for (int i = 0; i < imax; ++i) - fs << " input [" << (vd[i])->nbits() - 1 << ":0] " << (vd[i])->name() << "_wire,\n"; - fs << "\n"; - - imax = v.size() - 1; - for (int i = 0; i < imax; ++i) - if (v[i]->nbits() > 1) - fs << " output [" << (v[i])->nbits() - 1 << ":0] " << (v[i])->name() << "_wire,\n"; - else - fs << " output " << (v[i])->name() << "_wire,\n"; - if (imax >= 0) { - if (v[imax]->nbits() > 1) - fs << " output [" << (v[imax])->nbits() - 1 << ":0] " << (v[imax])->name() << "_wire\n"; - else - fs << " output " << (v[imax])->name() << "_wire\n"; - } - fs << ");\n\n"; - - //body of the module - imax = v.size(); - for (int i = 0; i < imax; ++i) { - fs << "\n//\n"; - fs << "// calculating " << (v[i])->name() << "\n"; - fs << "//\n"; - (v[i])->print_all(fs, verilog); - } - fs << "\n"; - - //trailer - fs << "\n"; - fs << "\n//\n"; - fs << "// wiring the outputs \n"; - fs << "// latency = " << maxstep << "\n"; - fs << "//\n"; - for (int i = 0; i < imax; ++i) { - std::string n = v[i]->name() + "_wire"; - int delay = maxstep - v[i]->step() - v[i]->latency(); - if (delay == 0) - fs << "assign " << n << " = " << (v[i])->name() << ";\n"; - else - fs << pipe_delay_wire(v[i], n, v[i]->nbits(), delay); - } - - fs << "endmodule\n"; -} diff --git a/L1Trigger/TrackFindingTracklet/src/imath_calculate.cc b/L1Trigger/TrackFindingTracklet/src/imath_calculate.cc deleted file mode 100644 index 7171a44ca717e..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/imath_calculate.cc +++ /dev/null @@ -1,198 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/imath.h" -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -using namespace trklet; - -bool VarBase::calculate(int debug_level) { - bool ok1 = true; - bool ok2 = true; - bool ok3 = true; - - if (p1_) - ok1 = p1_->calculate(debug_level); - if (p2_) - ok2 = p2_->calculate(debug_level); - if (p3_) - ok3 = p3_->calculate(debug_level); - - bool all_ok = debug_level && ok1 && ok2 && ok3; - long int ival_prev = ival_; - - local_calculate(); - - val_ = ival_ * K_; - -#ifdef IMATH_ROOT - if (globals_->use_root) { - if (h_ == 0) { - globals_->h_file_->cd(); - std::string hname = "h_" + name_; - h_ = (TH2F *)globals_->h_file_->Get(hname.c_str()); - if (h_ == 0) { - h_precision_ = 0.5 * h_nbins_ * K_; - std::string st = name_ + ";fval;fval-ival*K"; - h_ = new TH2F(hname.c_str(), name_.c_str(), h_nbins_, -range(), range(), h_nbins_, -h_precision_, h_precision_); - if (debug_level == 3) - edm::LogVerbatim("Tracklet") << " booking histogram " << hname; - } - } - if (ival_ != ival_prev || op_ == "def" || op_ == "const") - h_->Fill(fval_, K_ * ival_ - fval_); - } -#endif - - if (debug_level) - calcDebug(debug_level, ival_prev, all_ok); - - return all_ok; -} - -void VarBase::calcDebug(int debug_level, long int ival_prev, bool &all_ok) { - if (fval_ > maxval_) - maxval_ = fval_; - if (fval_ < minval_) - minval_ = fval_; - - bool todump = false; - int nmax = sizeof(long int) * 8; - int ns = nmax - nbits_; - long int itest = ival_; - itest = l1t::bitShift(itest, ns); - itest = itest >> ns; - if (itest != ival_) { - if (debug_level == 3 || (ival_ != ival_prev && all_ok)) { - edm::LogVerbatim("Tracklet") << "imath: truncated value mismatch!! " << ival_ << " != " << itest; - todump = true; - } - all_ok = false; - } - - float ftest = val_; - float tolerance = 0.1 * std::abs(fval_); - if (tolerance < 2 * K_) - tolerance = 2 * K_; - if (std::abs(ftest - fval_) > tolerance) { - if (debug_level == 3 || (ival_ != ival_prev && (all_ok && (op_ != "inv" || debug_level >= 2)))) { - edm::LogVerbatim("Tracklet") << "imath: **GROSS** value mismatch!! " << fval_ << " != " << ftest; - if (op_ == "inv" && p1_) - edm::LogVerbatim("Tracklet") << p1_->dump() << "\n-----------------------------------"; - todump = true; - } - all_ok = false; - } - if (todump) - edm::LogVerbatim("Tracklet") << dump(); -} - -void VarFlag::calculate_step() { - int max_step = 0; - for (const auto &cut : cuts_) { - if (!cut->cut_var()) - continue; - if (cut->cut_var()->latency() + cut->cut_var()->step() > max_step) - max_step = cut->cut_var()->latency() + cut->cut_var()->step(); - } - step_ = max_step; -} - -// -// local calculations -// - -void VarAdjustK::local_calculate() { - fval_ = p1_->fval(); - ival_ = p1_->ival(); - if (lr_ > 0) - ival_ = ival_ >> lr_; - else if (lr_ < 0) - ival_ = l1t::bitShift(ival_, (-lr_)); -} - -void VarAdjustKR::local_calculate() { - fval_ = p1_->fval(); - ival_ = p1_->ival(); - if (lr_ > 0) - ival_ = ((ival_ >> (lr_ - 1)) + 1) >> 1; //rounding - else if (lr_ < 0) - ival_ = l1t::bitShift(ival_, (-lr_)); -} - -void VarAdd::local_calculate() { - fval_ = p1_->fval() + p2_->fval(); - long int i1 = p1_->ival(); - long int i2 = p2_->ival(); - if (shift1 > 0) - i1 = l1t::bitShift(i1, shift1); - if (shift2 > 0) - i2 = l1t::bitShift(i2, shift2); - ival_ = i1 + i2; - if (ps_ > 0) - ival_ = ival_ >> ps_; -} - -void VarSubtract::local_calculate() { - fval_ = p1_->fval() - p2_->fval(); - long int i1 = p1_->ival(); - long int i2 = p2_->ival(); - if (shift1 > 0) - i1 = l1t::bitShift(i1, shift1); - if (shift2 > 0) - i2 = l1t::bitShift(i2, shift2); - ival_ = i1 - i2; - if (ps_ > 0) - ival_ = ival_ >> ps_; -} - -void VarNounits::local_calculate() { - fval_ = p1_->fval(); - ival_ = (p1_->ival() * cI_) >> ps_; -} - -void VarTimesC::local_calculate() { - fval_ = p1_->fval() * cF_; - ival_ = (p1_->ival() * cI_) >> ps_; -} - -void VarNeg::local_calculate() { - fval_ = -p1_->fval(); - ival_ = -p1_->ival(); -} - -void VarShift::local_calculate() { - fval_ = p1_->fval() * pow(2, -shift_); - ival_ = p1_->ival(); - if (shift_ > 0) - ival_ = ival_ >> shift_; - if (shift_ < 0) - ival_ = l1t::bitShift(ival_, (-shift_)); -} - -void VarShiftround::local_calculate() { - fval_ = p1_->fval() * pow(2, -shift_); - ival_ = p1_->ival(); - if (shift_ > 0) - ival_ = ((ival_ >> (shift_ - 1)) + 1) >> 1; - if (shift_ < 0) - ival_ = l1t::bitShift(ival_, (-shift_)); -} - -void VarMult::local_calculate() { - fval_ = p1_->fval() * p2_->fval(); - ival_ = (p1_->ival() * p2_->ival()) >> ps_; -} - -void VarDSPPostadd::local_calculate() { - fval_ = p1_->fval() * p2_->fval() + p3_->fval(); - ival_ = p3_->ival(); - if (shift3_ > 0) - ival_ = l1t::bitShift(ival_, shift3_); - if (shift3_ < 0) - ival_ = ival_ >> (-shift3_); - ival_ += p1_->ival() * p2_->ival(); - ival_ = ival_ >> ps_; -} - -void VarInv::local_calculate() { - fval_ = 1. / (offset_ + p1_->fval()); - ival_ = LUT[ival_to_addr(p1_->ival())]; -} diff --git a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py index 4a9717c407f3c..8d4b119d77e7e 100644 --- a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py +++ b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py @@ -60,7 +60,7 @@ # input and output ############################################################ -process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(100)) +process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(5)) #--- To use MCsamples scripts, defining functions get*data*() for easy MC access, #--- follow instructions in https://github.com/cms-L1TK/MCsamples diff --git a/L1Trigger/TrackTrigger/interface/Setup.h b/L1Trigger/TrackTrigger/interface/Setup.h index 2e2724e37c8fe..1a49aa45670b6 100644 --- a/L1Trigger/TrackTrigger/interface/Setup.h +++ b/L1Trigger/TrackTrigger/interface/Setup.h @@ -242,8 +242,18 @@ namespace tt { // Hybrid specific parameter - // max number of layer connected to one DTC - double hybridNumLayers() const { return hybridNumLayers_; } + // cut on stub pt in GeV, also defines region overlap shape + double hybridMinPtStub() const { return hybridMinPtStub_; } + // cut on andidate pt in GeV + double hybridMinPtCand() const { return hybridMinPtCand_; } + // cut on stub eta + double hybridMaxEta() const { return hybridMaxEta_; } + // critical radius defining region overlap shape in cm + double hybridChosenRofPhi() const { return hybridChosenRofPhi_; } + // max number of detector layer connected to one DTC + int hybridNumLayers() const { return hybridNumLayers_; } + // number of bits used for stub negative disk (w.r.t. z region of detector) boolean for module types (barrelPS, barrel2S, diskPS, disk2S) + int hybridWidthND(SensorModule::Type type) const { return hybridWidthsND_.at(type); } // number of bits used for stub r w.r.t layer/disk centre for module types (barrelPS, barrel2S, diskPS, disk2S) int hybridWidthR(SensorModule::Type type) const { return hybridWidthsR_.at(type); } // number of bits used for stub z w.r.t layer/disk centre for module types (barrelPS, barrel2S, diskPS, disk2S) @@ -562,6 +572,8 @@ namespace tt { int hybridNumLayers_; // number of outer PS rings for disk 1, 2, 3, 4, 5 std::vector hybridNumRingsPS_; + // number of bits used for stub negative disk (w.r.t. z region of detector) boolean for module types (barrelPS, barrel2S, diskPS, disk2S) + std::vector hybridWidthsND_; // number of bits used for stub r w.r.t layer/disk centre for module types (barrelPS, barrel2S, diskPS, disk2S) std::vector hybridWidthsR_; // number of bits used for stub z w.r.t layer/disk centre for module types (barrelPS, barrel2S, diskPS, disk2S) diff --git a/L1Trigger/TrackTrigger/python/ProducerSetup_cfi.py b/L1Trigger/TrackTrigger/python/ProducerSetup_cfi.py new file mode 100644 index 0000000000000..25c832a84826a --- /dev/null +++ b/L1Trigger/TrackTrigger/python/ProducerSetup_cfi.py @@ -0,0 +1,231 @@ +import FWCore.ParameterSet.Config as cms + +TrackTrigger_params = cms.PSet ( + + fromDD4hep = cms.bool(False), + + # Parameter to check if configured Tracker Geometry is supported + # this refers to files included by Configuration/Geometry/python/GeometryExtended*_cff.py + UnSupportedGeometry = cms.PSet ( + XMLLabel = cms.string ("geomXMLFiles" ), # label of ESProducer/ESSource + XMLPath = cms.string ("Geometry/TrackerCommonData/data/PhaseII/" ), # compared path + XMLFile = cms.string ("tracker.xml" ), # compared filen ame + XMLVersions = cms.vstring() # list of unsupported versions + ), + + # Parameter to check if Process History is consistent with process configuration + ProcessHistory = cms.PSet ( + GeometryConfiguration = cms.string( "XMLIdealGeometryESSource@" ), # label of compared GeometryConfiguration + TTStubAlgorithm = cms.string( "TTStubAlgorithm_official_Phase2TrackerDigi_@" ) # label of compared TTStubAlgorithm + ), + + # Common track finding parameter + TrackFinding = cms.PSet ( + BeamWindowZ = cms.double( 15. ), # half lumi region size in cm + MatchedLayers = cms.int32 ( 4 ), # required number of layers a found track has to have in common with a TP to consider it matched to it + MatchedLayersPS = cms.int32 ( 0 ), # required number of ps layers a found track has to have in common with a TP to consider it matched to it + UnMatchedStubs = cms.int32 ( 1 ), # allowed number of stubs a found track may have not in common with its matched TP + UnMatchedStubsPS = cms.int32 ( 0 ), # allowed number of PS stubs a found track may have not in common with its matched TP + Scattering = cms.double( 0.131283 ) # additional radial uncertainty in cm used to calculate stub phi residual uncertainty to take multiple scattering into account + ), + + # TMTT specific parameter + TMTT = cms.PSet ( + MinPt = cms.double( 3. ), # cut on stub in GeV, also defines region overlap shape + MaxEta = cms.double( 2.4 ), # cut on stub eta + ChosenRofPhi = cms.double( 67.24 ), # critical radius defining region overlap shape in cm + NumLayers = cms.int32 ( 7 ), # number of detector layers a reconstructbale particle may cross, reduced to 7, 8th layer almost never corssed + WidthR = cms.int32 ( 12 ), # number of bits used for stub r - ChosenRofPhi + WidthPhi = cms.int32 ( 15 ), # number of bits used for stub phi w.r.t. phi region centre + WidthZ = cms.int32 ( 14 ) # number of bits used for stub z + ), + + # Hybrid specific parameter + Hybrid = cms.PSet ( + MinPtStub = cms.double( 2.0 ), # cut on stub pt in GeV, also defines region overlap shape + MinPtCand = cms.double( 1.34 ), # cut on candidate pt in GeV + MaxEta = cms.double( 2.5 ), # cut on stub eta + ChosenRofPhi = cms.double( 55. ), # critical radius defining region overlap shape in cm + NumLayers = cms.int32 ( 4 ), # max number of detector layer connected to one DTC + NumRingsPS = cms.vint32 ( 11, 11, 8, 8, 8 ), # number of outer PS rings for disk 1, 2, 3, 4, 5 + WidthsND = cms.vint32 ( 0, 0, 1, 1 ), # number of bits used for stub negDisk boolean, determined by if in neg. or pos. z region (barrelPS, barrel2S, diskPS, disk2S) + WidthsR = cms.vint32 ( 7, 7, 11, 6 ), # number of bits used for stub r w.r.t layer/disk centre for module types (barrelPS, barrel2S, diskPS, disk2S) + WidthsZ = cms.vint32 ( 12, 8, 7, 7 ), # number of bits used for stub z w.r.t layer/disk centre for module types (barrelPS, barrel2S, diskPS, disk2S) + WidthsPhi = cms.vint32 ( 14, 17, 14, 14 ), # number of bits used for stub phi w.r.t. region centre for module types (barrelPS, barrel2S, diskPS, disk2S) + WidthsAlpha = cms.vint32 ( 0, 0, 0, 4 ), # number of bits used for stub row number for module types (barrelPS, barrel2S, diskPS, disk2S) + WidthsBend = cms.vint32 ( 3, 4, 3, 4 ), # number of bits used for stub bend number for module types (barrelPS, barrel2S, diskPS, disk2S) + RangesR = cms.vdouble( 7.5, 7.5, 120. , 0. ), # range in stub r which needs to be covered for module types (barrelPS, barrel2S, diskPS, disk2S) + RangesZ = cms.vdouble( 240., 240., 7.5, 7.5 ), # range in stub z which needs to be covered for module types (barrelPS, barrel2S, diskPS, disk2S) + RangesAlpha = cms.vdouble( 0., 0., 0., 2048. ), # range in stub row which needs to be covered for module types (barrelPS, barrel2S, diskPS, disk2S) + LayerRs = cms.vdouble( 24.9316, 37.1777, 52.2656, 68.7598, 86.0156, 108.3105 ), # mean radius of outer tracker barrel layer + DiskZs = cms.vdouble( 131.1914, 154.9805, 185.3320, 221.6016, 265.0195 ), # mean z of outer tracker endcap disks + Disk2SRsSet = cms.VPSet( # center radius of outer tracker endcap 2S diks strips + cms.PSet( Disk2SRs = cms.vdouble( 66.4391, 71.4391, 76.2750, 81.2750, 82.9550, 87.9550, 93.8150, 98.8150, 99.8160, 104.8160 ) ), # disk 1 + cms.PSet( Disk2SRs = cms.vdouble( 66.4391, 71.4391, 76.2750, 81.2750, 82.9550, 87.9550, 93.8150, 98.8150, 99.8160, 104.8160 ) ), # disk 2 + cms.PSet( Disk2SRs = cms.vdouble( 63.9903, 68.9903, 74.2750, 79.2750, 81.9562, 86.9562, 92.4920, 97.4920, 99.8160, 104.8160 ) ), # disk 3 + cms.PSet( Disk2SRs = cms.vdouble( 63.9903, 68.9903, 74.2750, 79.2750, 81.9562, 86.9562, 92.4920, 97.4920, 99.8160, 104.8160 ) ), # disk 4 + cms.PSet( Disk2SRs = cms.vdouble( 63.9903, 68.9903, 74.2750, 79.2750, 81.9562, 86.9562, 92.4920, 97.4920, 99.8160, 104.8160 ) ) # disk 5 + ), + InnerRadius = cms.double( 19.6 ), # smallest stub radius after TrackBuilder in cm + WidthsRTB = cms.vint32 ( 7, 7, 12, 12 ), # number of bits used for stub r w.r.t layer/disk centre for module types (barrelPS, barrel2S, diskPS, disk2S) at TB output + ), + + # Parameter specifying TrackingParticle used for Efficiency measurements + TrackingParticle = cms.PSet ( + MinPt = cms.double( 2. ), # pt cut in GeV + MaxEta = cms.double( 2.4 ), # eta cut + MaxVertR = cms.double( 1. ), # cut on vertex pos r in cm + MaxVertZ = cms.double( 30. ), # cut on vertex pos z in cm + MaxD0 = cms.double( 5. ), # cut on impact parameter in cm + MinLayers = cms.int32 ( 4 ), # required number of associated layers to a TP to consider it reconstruct-able and to match it with TTTrack + MinLayersPS = cms.int32 ( 0 ), # required number of associated ps layers to a TP to consider it reconstruct-able + MaxBadStubs2S = cms.int32 ( 1 ), # max number of unassociated 2S stubs allowed to still associate TTTrack with TP + MaxBadStubsPS = cms.int32 ( 0 ) # max number of unassociated PS stubs allowed to still associate TTTrack with TP + ), + + # Fimrware specific Parameter + Firmware = cms.PSet ( + WidthDSPa = cms.int32( 27 ), # width of the 'A' port of an DSP slice + WidthDSPb = cms.int32( 18 ), # width of the 'B' port of an DSP slice + WidthDSPc = cms.int32( 48 ), # width of the 'C' port of an DSP slice + WidthAddrBRAM36 = cms.int32( 9 ), # smallest address width of an BRAM36 configured as broadest simple dual port memory + WidthAddrBRAM18 = cms.int32( 10 ), # smallest address width of an BRAM18 configured as broadest simple dual port memory + NumFramesInfra = cms.int32 ( 6 ), # needed gap between events of emp-infrastructure firmware + FreqLHC = cms.double( 40. ), # LHC bunch crossing rate in MHz + FreqBE = cms.double( 360. ), # processing Frequency of DTC, KF & TFP in MHz, has to be integer multiple of FreqLHC + TMP_FE = cms.int32 ( 8 ), # number of events collected in front-end + TMP_TFP = cms.int32 ( 18 ), # time multiplexed period of track finding processor + SpeedOfLight = cms.double( 2.99792458 ), # in e8 m/s + BField = cms.double( 3.81120228767395 ), # in T + BFieldError = cms.double( 1.e-6 ), # accepted difference to EventSetup in T + OuterRadius = cms.double( 112.7 ), # outer radius of outer tracker in cm + InnerRadius = cms.double( 21.8 ), # inner radius of outer tracker in cm + HalfLength = cms.double( 270. ), # half length of outer tracker in cm + TiltApproxSlope = cms.double( 0.884 ), # In tilted barrel, grad*|z|/r + int approximates |cosTilt| + |sinTilt * cotTheta| + TiltApproxIntercept = cms.double( 0.507 ), # In tilted barrel, grad*|z|/r + int approximates |cosTilt| + |sinTilt * cotTheta| + TiltUncertaintyR = cms.double( 0.12 ), # In tilted barrel, constant assumed stub radial uncertainty * sqrt(12) in cm + MindPhi = cms.double( 0.0001 ), # minimum representable stub phi uncertainty * sqrt(12) + additional terms in rad + MaxdPhi = cms.double( 0.02 ), # maximum representable stub phi uncertainty * sqrt(12) + additional terms in rad + MindZ = cms.double( 0.1 ), # minimum representable stub z uncertainty * sqrt(12) + additional terms in cm + MaxdZ = cms.double( 30. ), # maximum representable stub z uncertainty * sqrt(12) + additional terms in cm + Pitch2S = cms.double( 0.009 ), # strip pitch of outer tracker sensors in cm + PitchPS = cms.double( 0.01 ), # pixel pitch of outer tracker sensors in cm + Length2S = cms.double( 5.025 ), # strip length of outer tracker sensors in cm + LengthPS = cms.double( 0.1467 ), # pixel length of outer tracker sensors in cm + TiltedLayerLimitsZ = cms.vdouble( 15.5, 24.9, 34.3, -1., -1., -1. ), # barrel layer limit |z| value to partition into tilted and untilted region + PSDiskLimitsR = cms.vdouble( 66.4, 66.4, 64.55, 64.55, 64.55 ), # endcap disk limit r value to partition into PS and 2S region + ), + + # Parmeter specifying front-end + FrontEnd = cms.PSet ( + WidthBend = cms.int32 ( 6 ), # number of bits used for internal stub bend + WidthCol = cms.int32 ( 5 ), # number of bits used for internal stub column + WidthRow = cms.int32 ( 11 ), # number of bits used for internal stub row + BaseBend = cms.double( .25 ), # precision of internal stub bend in pitch units + BaseCol = cms.double( 1. ), # precision of internal stub column in pitch units + BaseRow = cms.double( .5 ), # precision of internal stub row in pitch units + BaseWindowSize = cms.double( .5 ), # precision of window sizes in pitch units + BendCut = cms.double( 1.3125 ) # used stub bend uncertainty in pitch units + ), + + # Parmeter specifying DTC + DTC = cms.PSet ( + NumRegions = cms.int32( 9 ), # number of phi slices the outer tracker readout is organized in + NumOverlappingRegions = cms.int32( 2 ), # number of regions a reconstructable particles may cross + NumATCASlots = cms.int32( 12 ), # number of Slots in used ATCA crates + NumDTCsPerRegion = cms.int32( 24 ), # number of DTC boards used to readout a detector region, likely constructed to be an integerer multiple of NumSlots_ + NumModulesPerDTC = cms.int32( 72 ), # max number of sensor modules connected to one DTC board + NumRoutingBlocks = cms.int32( 2 ), # number of systiloic arrays in stub router firmware + DepthMemory = cms.int32( 64 ), # fifo depth in stub router firmware + WidthRowLUT = cms.int32( 4 ), # number of row bits used in look up table + WidthInv2R = cms.int32( 9 ), # number of bits used for stub inv2R. lut addr is col + bend = 11 => 1 BRAM -> 18 bits for min and max val -> 9 + OffsetDetIdDSV = cms.int32( 1 ), # tk layout det id minus DetSetVec->detId + OffsetDetIdTP = cms.int32( -1 ), # tk layout det id minus TrackerTopology lower det id + OffsetLayerDisks = cms.int32( 10 ), # offset in layer ids between barrel layer and endcap disks + OffsetLayerId = cms.int32( 1 ), # offset between 0 and smallest layer id (barrel layer 1) + NumBarrelLayer = cms.int32( 6 ), # + SlotLimitPS = cms.int32( 6 ), # slot number changing from PS to 2S + SlotLimit10gbps = cms.int32( 3 ) # slot number changing from 10 gbps to 5gbps + ), + + # Parmeter specifying TFP + TFP = cms.PSet ( + WidthPhi0 = cms.int32( 12 ), # number of bist used for phi0 + WidthInv2R = cms.int32( 15 ), # number of bist used for inv2R + WidthCot = cms.int32( 16 ), # number of bist used for cot(theta) + WidthZ0 = cms.int32( 12 ), # number of bist used for z0 + NumChannel = cms.int32( 2 ) # number of output links + ), + + # Parmeter specifying GeometricProcessor + GeometricProcessor = cms.PSet ( + NumSectorsPhi = cms.int32 ( 2 ), # number of phi sectors used in hough transform + ChosenRofZ = cms.double( 50. ), # critical radius defining r-z sector shape in cm + RangeChiZ = cms.double( 160. ), # range of stub z residual w.r.t. sector center which needs to be covered + DepthMemory = cms.int32 ( 64 ), # fifo depth in stub router firmware + #BoundariesEta = cms.vdouble( -2.40, -2.08, -1.68, -1.26, -0.90, -0.62, -0.41, -0.20, 0.0, 0.20, 0.41, 0.62, 0.90, 1.26, 1.68, 2.08, 2.40 ) # defining r-z sector shape + BoundariesEta = cms.vdouble( -2.50, -2.23, -1.88, -1.36, -0.90, -0.62, -0.41, -0.20, 0.0, 0.20, 0.41, 0.62, 0.90, 1.36, 1.88, 2.23, 2.50 ) # defining r-z sector shape + ), + + # Parmeter specifying HoughTransform + HoughTransform = cms.PSet ( + NumBinsInv2R = cms.int32( 16 ), # number of used inv2R bins + NumBinsPhiT = cms.int32( 32 ), # number of used phiT bins + MinLayers = cms.int32( 5 ), # required number of stub layers to form a candidate + DepthMemory = cms.int32( 32 ) # internal fifo depth + ), + + # Parmeter specifying MiniHoughTransform + MiniHoughTransform = cms.PSet ( + NumBinsInv2R = cms.int32( 2 ), # number of finer inv2R bins inside HT bin + NumBinsPhiT = cms.int32( 2 ), # number of finer phiT bins inside HT bin + NumDLBs = cms.int32( 2 ), # number of dynamic load balancing steps + NumDLBNodes = cms.int32( 8 ), # number of units per dynamic load balancing step + NumDLBChannel = cms.int32( 2 ), # number of inputs per dynamic load balancing unit + MinLayers = cms.int32( 5 ) # required number of stub layers to form a candidate + ), + + # Parmeter specifying ZHoughTransform + ZHoughTransform = cms.PSet ( + NumBinsZT = cms.int32( 2 ), # + NumBinsCot = cms.int32( 2 ), # + NumStages = cms.int32( 5 ), # + MinLayers = cms.int32( 4 ), # required number of stub layers to form a candidate + MaxTracks = cms.int32( 16 ), # max number of output tracks per node + MaxStubsPerLayer = cms.int32( 4 ) # cut on number of stub per layer for input candidates + ), + + # Parmeter specifying KalmanFilter Input Formatter + + KalmanFilterIn = cms.PSet ( + ShiftRangePhi = cms.int32( 2 ), # power of 2 multiplier of stub phi residual range + ShiftRangeZ = cms.int32( 1 ) # power of 2 multiplier of stub z residual range + ), + + # Parmeter specifying KalmanFilter + KalmanFilter = cms.PSet ( + NumWorker = cms.int32 ( 2 ), # number of kf worker + RangeFactor = cms.double( 2.0 ), # search window of each track parameter in initial uncertainties + MinLayers = cms.int32 ( 4 ), # required number of stub layers to form a track + MaxLayers = cms.int32 ( 7 ), # maximum number of layers added to a track + ShiftInitialC00 = cms.int32 ( 0 ), # + ShiftInitialC11 = cms.int32 ( -2 ), # + ShiftInitialC22 = cms.int32 ( 0 ), # + ShiftInitialC33 = cms.int32 ( 0 ) # + ), + + # Parmeter specifying KalmanFilter Output Formatter + KalmanFilterOut = cms.PSet ( + Chi2rphiConv = cms.int32( 3 ), # Conversion factor between dphi^2/weight and chi2rphi + Chi2rzConv = cms.int32( 13 ), # Conversion factor between dz^2/weight and chi2rz + WeightBinFraction = cms.int32( 0 ), # Number of bits dropped from dphi and dz for v0 and v1 LUTs + DzTruncation = cms.int32( 262144 ), # Constant used in FW to prevent 32-bit int overflow + DphiTruncation = cms.int32( 16 ) # Constant used in FW to prevent 32-bit int overflow + ), + + # Parmeter specifying DuplicateRemoval + DuplicateRemoval = cms.PSet ( + DepthMemory = cms.int32( 16 ) # internal memory depth + ) + +) diff --git a/L1Trigger/TrackTrigger/src/Setup.cc b/L1Trigger/TrackTrigger/src/Setup.cc index e9dab24ac4496..720e0969eb85b 100644 --- a/L1Trigger/TrackTrigger/src/Setup.cc +++ b/L1Trigger/TrackTrigger/src/Setup.cc @@ -44,6 +44,7 @@ namespace tt { pSetHybrid_(iConfig.getParameter("Hybrid")), hybridNumLayers_(pSetHybrid_.getParameter("NumLayers")), hybridNumRingsPS_(pSetHybrid_.getParameter>("NumRingsPS")), + hybridWidthsND_(pSetHybrid_.getParameter>("WidthsND")), hybridWidthsR_(pSetHybrid_.getParameter>("WidthsR")), hybridWidthsZ_(pSetHybrid_.getParameter>("WidthsZ")), hybridWidthsPhi_(pSetHybrid_.getParameter>("WidthsPhi")), @@ -590,7 +591,11 @@ namespace tt { hybridBasesZ_.emplace_back(hybridRangesZ_.at(type) / pow(2., hybridWidthsZ_.at(type))); hybridBasesR_.reserve(SensorModule::NumTypes); for (int type = 0; type < SensorModule::NumTypes; type++) - hybridBasesR_.emplace_back(hybridRangesR_.at(type) / pow(2., hybridWidthsR_.at(type))); + if (type == SensorModule::DiskPS) + hybridBasesR_.emplace_back(hybridRangesR_.at(type) / + pow(2., hybridWidthsR_.at(type) + 1)); // to account for 7.5 cm offset + else + hybridBasesR_.emplace_back(hybridRangesR_.at(type) / pow(2., hybridWidthsR_.at(type))); hybridBasesR_[SensorModule::Disk2S] = 1.; hybridBasesPhi_.reserve(SensorModule::NumTypes); for (int type = 0; type < SensorModule::NumTypes; type++) @@ -600,13 +605,11 @@ namespace tt { hybridBasesAlpha_.emplace_back(hybridRangesAlpha_.at(type) / pow(2., hybridWidthsAlpha_.at(type))); hybridNumsUnusedBits_.reserve(SensorModule::NumTypes); for (int type = 0; type < SensorModule::NumTypes; type++) - hybridNumsUnusedBits_.emplace_back(TTBV::S_ - hybridWidthsR_.at(type) - hybridWidthsZ_.at(type) - - hybridWidthsPhi_.at(type) - hybridWidthsAlpha_.at(type) - - hybridWidthsBend_.at(type) - hybridWidthLayerId_ - 1); - hybridBaseR_ = *min_element(hybridBasesR_.begin(), hybridBasesR_.end()); - hybridBasePhi_ = *min_element(hybridBasesPhi_.begin(), hybridBasesPhi_.end()); - hybridBaseZ_ = *min_element(hybridBasesZ_.begin(), hybridBasesZ_.end()); - hybridMaxCot_ = sinh(maxEta_); + hybridNumsUnusedBits_.emplace_back(TTBV::S_ - hybridWidthsND_.at(type) - hybridWidthsR_.at(type) - + hybridWidthsZ_.at(type) - hybridWidthsPhi_.at(type) - + hybridWidthsAlpha_.at(type) - hybridWidthsBend_.at(type) - + hybridWidthLayerId_ - 1); + hybridMaxCot_ = sinh(hybridMaxEta_); disk2SRs_.reserve(hybridDisk2SRsSet_.size()); for (const auto& pSet : hybridDisk2SRsSet_) disk2SRs_.emplace_back(pSet.getParameter>("Disk2SRs")); diff --git a/L1Trigger/TrackerDTC/interface/Stub.h b/L1Trigger/TrackerDTC/interface/Stub.h index 37d06f774ccd4..ce28ef6079ba6 100644 --- a/L1Trigger/TrackerDTC/interface/Stub.h +++ b/L1Trigger/TrackerDTC/interface/Stub.h @@ -71,6 +71,8 @@ namespace trackerDTC { int rowLUT_; // sub row number inside reduced row number int rowSub_; + // stub negDisk bool, determined by if in neg. or pos. z region + bool nd_; // stub r w.r.t. an offset in cm double r_; // stub phi w.r.t. detector region centre in rad diff --git a/L1Trigger/TrackerDTC/src/Stub.cc b/L1Trigger/TrackerDTC/src/Stub.cc index 7775e53277f74..b4ad2b870a3c5 100644 --- a/L1Trigger/TrackerDTC/src/Stub.cc +++ b/L1Trigger/TrackerDTC/src/Stub.cc @@ -137,6 +137,14 @@ namespace trackerDTC { r_ = sm->encodedR() + (sm->side() ? -col_ : (col_ + sm->numColumns() / 2)); r_ = (r_ + 0.5) * setup->hybridBaseR(sm->type()); } + if (sm->type() == SensorModule::DiskPS || + sm->type() == SensorModule::Disk2S) { // set negDisk bit based on which z-side of detector stub is in + if (sm_->side()) + nd_ = 0; + else + nd_ = 1; + } + // encode bend const vector& encodingBend = setup->encodingBend(sm->windowSize(), sm->psModule()); const auto pos = find(encodingBend.begin(), encodingBend.end(), abs(ttStubRef->bendBE())); @@ -161,10 +169,18 @@ namespace trackerDTC { const int decodedLayerId = layerEncoding_->decode(sm_); // stub phi w.r.t. processing region border in rad double phi = phi_ - (region - .5) * setup_->baseRegion() + setup_->hybridRangePhi() / 2.; - // convert stub variables into bit vectors - const bool twosR = type == SensorModule::BarrelPS || type == SensorModule::Barrel2S; - const TTBV hwR(r_, setup_->hybridBaseR(type), setup_->hybridWidthR(type), twosR); - const TTBV hwPhi(phi, setup_->hybridBasePhi(type), setup_->hybridWidthPhi(type)); + if (phi >= setup_->hybridRangePhi()) + phi = setup_->hybridRangePhi() - setup_->hybridBasePhi(type) / 2.; + double r; + if (type == SensorModule::DiskPS) + r = r_ - + 7.5; // Adding offset of 7.5 cm (256 * granularity) to allow adding negDisk bit required for dual FPGA project + else + r = r_; + + const TTBV hwND(nd_, setup_->hybridWidthND(type)); + const TTBV hwR(r, setup_->hybridBaseR(type), setup_->hybridWidthR(type), true); + const TTBV hwPhi(phi, setup_->hybridBasePhi(type), setup_->hybridWidthPhi(type), true); const TTBV hwZ(z_, setup_->hybridBaseZ(type), setup_->hybridWidthZ(type), true); const TTBV hwAlpha(row_, setup_->hybridBaseAlpha(type), setup_->hybridWidthAlpha(type), true); const TTBV hwBend(bend_, setup_->hybridWidthBend(type), true); @@ -172,8 +188,8 @@ namespace trackerDTC { const TTBV hwGap(0, setup_->hybridNumUnusedBits(type)); const TTBV hwValid(1, 1); // assemble final bitset - return Frame(hwGap.str() + hwR.str() + hwZ.str() + hwPhi.str() + hwAlpha.str() + hwBend.str() + hwLayer.str() + - hwValid.str()); + return Frame(hwGap.str() + hwND.str() + hwR.str() + hwZ.str() + hwPhi.str() + hwAlpha.str() + hwBend.str() + + hwLayer.str() + hwValid.str()); } Frame Stub::formatTMTT(int region) const { From d77ac23d4882ef5728f468686e41af9ef7c00fe0 Mon Sep 17 00:00:00 2001 From: Anders Date: Fri, 3 Jan 2025 00:38:40 +0100 Subject: [PATCH 02/13] Some fixes after rebase to get code to run --- .../TrackFindingTracklet/src/ProjectionCalculator.cc | 1 - L1Trigger/TrackFindingTracklet/src/Tracklet.cc | 2 -- L1Trigger/TrackTrigger/interface/Setup.h | 8 ++++++++ L1Trigger/TrackTrigger/python/Setup_cfi.py | 3 ++- L1Trigger/TrackerDTC/src/Stub.cc | 8 ++++---- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc index 447f5a5d81c5e..55bafea743340 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc @@ -104,7 +104,6 @@ void ProjectionCalculator::addOutput(MemoryBase* memory, string output) { if (memory->getName().substr(memory->getName().size()-2,2) == "_E") { extraMPOffset = 2; } - std::cout << "extraMPOffset: " << memory->getName() << " " << extraMPOffset << std::endl; unsigned int layerdisk = memory->getName()[memory->getName().size() - 5 - extraMPOffset] - '1'; //layer or disk counting from 0 unsigned int phiregion = memory->getName()[memory->getName().size() - 1 - extraMPOffset] - 'A'; //phiregion counting from 0 if (memory->getName()[memory->getName().size() - 6 - extraMPOffset] == 'D') layerdisk += N_LAYER; diff --git a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc index 4f54e262ec5cc..92cc3ab055a57 100644 --- a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc +++ b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc @@ -732,8 +732,6 @@ std::string Tracklet::trackfitstr() const { for (unsigned i = 0; i < maxNHits; i++) hitmap[i * nBitsPerHit + 2] = stub[i][0]; - std::cout << "hitmap :"<decode(sm_); // stub phi w.r.t. processing region border in rad double phi = phi_ - (region - .5) * setup_->baseRegion() + setup_->hybridRangePhi() / 2.; - if (phi >= setup_->hybridRangePhi()) - phi = setup_->hybridRangePhi() - setup_->hybridBasePhi(type) / 2.; double r; if (type == SensorModule::DiskPS) r = r_ - @@ -178,9 +176,11 @@ namespace trackerDTC { else r = r_; + // convert stub variables into bit vectors const TTBV hwND(nd_, setup_->hybridWidthND(type)); - const TTBV hwR(r, setup_->hybridBaseR(type), setup_->hybridWidthR(type), true); - const TTBV hwPhi(phi, setup_->hybridBasePhi(type), setup_->hybridWidthPhi(type), true); + const bool twosR = type == SensorModule::BarrelPS || type == SensorModule::Barrel2S; + const TTBV hwR(r, setup_->hybridBaseR(type), setup_->hybridWidthR(type), twosR); + const TTBV hwPhi(phi, setup_->hybridBasePhi(type), setup_->hybridWidthPhi(type)); const TTBV hwZ(z_, setup_->hybridBaseZ(type), setup_->hybridWidthZ(type), true); const TTBV hwAlpha(row_, setup_->hybridBaseAlpha(type), setup_->hybridWidthAlpha(type), true); const TTBV hwBend(bend_, setup_->hybridWidthBend(type), true); From 8b12344a7d6b0ee562c0ee6d5144c72c2313d321 Mon Sep 17 00:00:00 2001 From: Anders Date: Fri, 3 Jan 2025 09:42:35 +0100 Subject: [PATCH 03/13] Remove now usused combined flag in Settings.h --- .../TrackFindingTracklet/interface/Settings.h | 27 +- .../interface/TrackletConfigBuilder.h | 1 - .../src/MatchProcessor.cc | 2 +- .../TrackFindingTracklet/src/Tracklet.cc | 13 +- .../TrackFindingTracklet/src/TrackletLUT.cc | 8 +- .../src/VMStubsTEMemory.cc | 2 +- .../TrackTrigger/python/ProducerSetup_cfi.py | 231 ------------------ 7 files changed, 17 insertions(+), 267 deletions(-) delete mode 100644 L1Trigger/TrackTrigger/python/ProducerSetup_cfi.py diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index 14259e2a51568..1ed22bd138e9b 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -104,10 +104,7 @@ namespace trklet { bool useSeed(unsigned int iSeed) const { return useseeding_.find(iSeed) != useseeding_.end(); } unsigned int nbitsvmte(unsigned int inner, unsigned int iSeed) const { - if (combined_) { - return nbitsvmtecm_[inner][iSeed]; - } - return nbitsvmte_[inner][iSeed]; + return nbitsvmtecm_[inner][iSeed]; } unsigned int nvmte(unsigned int inner, unsigned int iSeed) const { return (1 << nbitsvmte(inner, iSeed)); } @@ -143,10 +140,7 @@ namespace trklet { int nfinephi(unsigned int inner, unsigned int iSeed) const { return nfinephi_[inner][iSeed]; } double nphireg(unsigned int inner, unsigned int iSeed) const { - if (combined_) { - return nphiregcm_[inner][iSeed]; - } - return nphireg_[inner][iSeed]; + return nphiregcm_[inner][iSeed]; } double lutwidthtab(unsigned int inner, unsigned int iSeed) const { return lutwidthtab_[inner][iSeed]; } double lutwidthtabextended(unsigned int inner, unsigned int iSeed) const { @@ -242,8 +236,7 @@ namespace trklet { std::string geomext() const { std::string geo = extended_ ? "hourglassExtended" : "hourglass"; - if (combined_) - geo += "Combined"; + geo += "Combined"; return geo; } @@ -279,8 +272,6 @@ namespace trklet { const std::array& layersDisksDuplicatedWeightedProjBalance() const { return layersDisksDuplicatedWeightedProjBalance_; } - bool combined() const { return combined_; } - void setCombined(bool combined) { combined_ = combined; } bool reduced() const { return reduced_; } void setReduced(bool reduced) { reduced_ = reduced; } bool inventStubs() const { return inventStubs_; } @@ -555,7 +546,7 @@ namespace trklet { std::array nbitsallstubs_{{3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}}; std::array nbitsvmme_{{2, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2}}; - std::array, 3> nbitsvmte_{ + std::array, 3> nbitsvmte_{ //FIXME unused? {{{2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 3, 2}}, // (3 = #stubs/triplet, only row 1+2 used for tracklet) {{3, 2, 3, 3, 2, 2, 2, 2, 3, 3, 2, 2}}, {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1}}}}; @@ -689,12 +680,11 @@ namespace trklet { //These are the number of bits used for the VM regions in the TE by seedindex //FIXME not independed nbitsvmte - std::array, 3> nphireg_{ + std::array, 3> nphireg_{ //FIXME unused? {{{5, 4, 4, 4, 4, 4, 4, 3, 4, 4, 5, 4}}, //inner {{5, 4, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4}}, //outer {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4}}}}; //outermost (triplets only) - //For combined modules std::array, 3> nphiregcm_{ {{{5, 4, 4, 4, 4, 4, 4, 3, 4, 4, 5, 4}}, //inner {{5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4}}, //outer @@ -1045,13 +1035,6 @@ namespace trklet { bool reduced_{false}; // use reduced (Summer Chain) config bool inventStubs_{false}; // invent seeding stub coordinates based on tracklet traj - // Use combined TP (TE+TC) & MP (PR+ME+MC) config (with prompt tracking) - bool combined_{true}; - // N.B. For extended tracking, this combined_ is overridden by python cfg - // to false, but combined modules are nonetheless used by default. - // If you don't want them, edit l1tTTTracksFromTrackletEmulation_cfi.py - // to refer to *_hourglassExtended.dat . - // Use chain with duplicated MPs for L3,L4 to reduce truncation issue // Balances load from projections roughly in half for each of the two MPs bool duplicateMPs_{true}; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h index 86d4174331b5a..72c6e033f988b 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h @@ -237,7 +237,6 @@ namespace trklet { double rcrit_; //critical radius that defines the sector bool duplicateMPs_; //if true write configuration with MPs duplicated for L3,L4 - bool combinedmodules_; //if true write configuration for combined modules bool extended_; //if true write configuration for extended configuration diff --git a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc index d0dbd953c1d3d..096acc19b1c41 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc @@ -1,7 +1,7 @@ ////////////////////////////////////////////////////////////////// // MatchProcessor // -// This module is the combined version of the PR+ME+MC +// This module is the combines the old PR+ME+MC modules // See more in execute() // // Variables such as `best_ideltaphi_barrel` store the "global" diff --git a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc index 92cc3ab055a57..413290dd037f2 100644 --- a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc +++ b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc @@ -196,20 +196,19 @@ std::string Tracklet::trackletparstr() { return oss; } else { std::string str = ""; - if (settings_.combined()) { - if (seedIndex() == Seed::L1D1 || seedIndex() == Seed::L2D1) { - str += outerFPGAStub_->phiregionstr() + "|"; - } else { - str += innerFPGAStub_->phiregionstr() + "|"; - } + if (seedIndex() == Seed::L1D1 || seedIndex() == Seed::L2D1) { + str += outerFPGAStub_->phiregionstr() + "|"; + } else { + str += innerFPGAStub_->phiregionstr() + "|"; } str += innerFPGAStub_->stubindex().str() + "|"; if (middleFPGAStub_) { str += middleFPGAStub_->stubindex().str() + "|"; } str += outerFPGAStub_->stubindex().str() + "|" + fpgapars_.rinv().str() + "|" + fpgapars_.phi0().str() + "|"; - if (middleFPGAStub_) + if (middleFPGAStub_) { str += fpgapars_.d0().str() + "|"; + } str += fpgapars_.z0().str() + "|" + fpgapars_.t().str(); return str; } diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc b/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc index 91dec76731c1b..07b0460dca573 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletLUT.cc @@ -235,7 +235,7 @@ void TrackletLUT::initmatchcut(unsigned int layerdisk, MatchType type, unsigned } } - name_ = settings_.combined() ? "MP_" : "MC_"; + name_ = "MP_"; if (type == barrelphi) { nbits_ = 10; @@ -845,7 +845,7 @@ void TrackletLUT::initProjectionBend(double k_phider, positive_ = false; nbits_ = 5; - name_ = settings_.combined() ? "MP_" : "PR_"; + name_ = "MP_"; name_ += "ProjectionBend_" + TrackletConfigBuilder::LayerName(N_LAYER + idisk) + ".tab"; writeTable(); @@ -1031,7 +1031,7 @@ void TrackletLUT::initVMRTable(unsigned int layerdisk, VMRTableType type, int re // VMRouterCM and TrackletProcessorDisplaced currently use the older LUTs // that were used with the non-combined modules. Once these modules are // updated, this extra flag can be removed. - if (settings_.combined() && combined) { + if (combined) { int iznew = izbin - (1 << (zbits - 1)); if (iznew < 0) iznew += (1 << zbits); @@ -1124,7 +1124,7 @@ void TrackletLUT::initVMRTable(unsigned int layerdisk, VMRTableType type, int re // VMRouterCM and TrackletProcessorDisplaced currently use the older LUTs // that were used with the non-combined modules. Once these modules are // updated, this extra flag can be removed. - if (settings_.combined() && combined) { + if (combined) { if (type == VMRTableType::me) { nbits_ = 2 * settings_.NLONGVMBITS(); positive_ = false; diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc index 9dd8ebe2c4202..c7aa34841be4d 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc @@ -56,7 +56,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub, int bin, int ivmte, bool combin //If the pt of the stub is consistent with the allowed pt of tracklets //in that can be formed in this VM and the other VM used in the TE. - if (settings_.combined() && combined) { + if (combined) { if (disk_ > 0) { assert(vmstub.stub()->isPSmodule()); } diff --git a/L1Trigger/TrackTrigger/python/ProducerSetup_cfi.py b/L1Trigger/TrackTrigger/python/ProducerSetup_cfi.py deleted file mode 100644 index 25c832a84826a..0000000000000 --- a/L1Trigger/TrackTrigger/python/ProducerSetup_cfi.py +++ /dev/null @@ -1,231 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -TrackTrigger_params = cms.PSet ( - - fromDD4hep = cms.bool(False), - - # Parameter to check if configured Tracker Geometry is supported - # this refers to files included by Configuration/Geometry/python/GeometryExtended*_cff.py - UnSupportedGeometry = cms.PSet ( - XMLLabel = cms.string ("geomXMLFiles" ), # label of ESProducer/ESSource - XMLPath = cms.string ("Geometry/TrackerCommonData/data/PhaseII/" ), # compared path - XMLFile = cms.string ("tracker.xml" ), # compared filen ame - XMLVersions = cms.vstring() # list of unsupported versions - ), - - # Parameter to check if Process History is consistent with process configuration - ProcessHistory = cms.PSet ( - GeometryConfiguration = cms.string( "XMLIdealGeometryESSource@" ), # label of compared GeometryConfiguration - TTStubAlgorithm = cms.string( "TTStubAlgorithm_official_Phase2TrackerDigi_@" ) # label of compared TTStubAlgorithm - ), - - # Common track finding parameter - TrackFinding = cms.PSet ( - BeamWindowZ = cms.double( 15. ), # half lumi region size in cm - MatchedLayers = cms.int32 ( 4 ), # required number of layers a found track has to have in common with a TP to consider it matched to it - MatchedLayersPS = cms.int32 ( 0 ), # required number of ps layers a found track has to have in common with a TP to consider it matched to it - UnMatchedStubs = cms.int32 ( 1 ), # allowed number of stubs a found track may have not in common with its matched TP - UnMatchedStubsPS = cms.int32 ( 0 ), # allowed number of PS stubs a found track may have not in common with its matched TP - Scattering = cms.double( 0.131283 ) # additional radial uncertainty in cm used to calculate stub phi residual uncertainty to take multiple scattering into account - ), - - # TMTT specific parameter - TMTT = cms.PSet ( - MinPt = cms.double( 3. ), # cut on stub in GeV, also defines region overlap shape - MaxEta = cms.double( 2.4 ), # cut on stub eta - ChosenRofPhi = cms.double( 67.24 ), # critical radius defining region overlap shape in cm - NumLayers = cms.int32 ( 7 ), # number of detector layers a reconstructbale particle may cross, reduced to 7, 8th layer almost never corssed - WidthR = cms.int32 ( 12 ), # number of bits used for stub r - ChosenRofPhi - WidthPhi = cms.int32 ( 15 ), # number of bits used for stub phi w.r.t. phi region centre - WidthZ = cms.int32 ( 14 ) # number of bits used for stub z - ), - - # Hybrid specific parameter - Hybrid = cms.PSet ( - MinPtStub = cms.double( 2.0 ), # cut on stub pt in GeV, also defines region overlap shape - MinPtCand = cms.double( 1.34 ), # cut on candidate pt in GeV - MaxEta = cms.double( 2.5 ), # cut on stub eta - ChosenRofPhi = cms.double( 55. ), # critical radius defining region overlap shape in cm - NumLayers = cms.int32 ( 4 ), # max number of detector layer connected to one DTC - NumRingsPS = cms.vint32 ( 11, 11, 8, 8, 8 ), # number of outer PS rings for disk 1, 2, 3, 4, 5 - WidthsND = cms.vint32 ( 0, 0, 1, 1 ), # number of bits used for stub negDisk boolean, determined by if in neg. or pos. z region (barrelPS, barrel2S, diskPS, disk2S) - WidthsR = cms.vint32 ( 7, 7, 11, 6 ), # number of bits used for stub r w.r.t layer/disk centre for module types (barrelPS, barrel2S, diskPS, disk2S) - WidthsZ = cms.vint32 ( 12, 8, 7, 7 ), # number of bits used for stub z w.r.t layer/disk centre for module types (barrelPS, barrel2S, diskPS, disk2S) - WidthsPhi = cms.vint32 ( 14, 17, 14, 14 ), # number of bits used for stub phi w.r.t. region centre for module types (barrelPS, barrel2S, diskPS, disk2S) - WidthsAlpha = cms.vint32 ( 0, 0, 0, 4 ), # number of bits used for stub row number for module types (barrelPS, barrel2S, diskPS, disk2S) - WidthsBend = cms.vint32 ( 3, 4, 3, 4 ), # number of bits used for stub bend number for module types (barrelPS, barrel2S, diskPS, disk2S) - RangesR = cms.vdouble( 7.5, 7.5, 120. , 0. ), # range in stub r which needs to be covered for module types (barrelPS, barrel2S, diskPS, disk2S) - RangesZ = cms.vdouble( 240., 240., 7.5, 7.5 ), # range in stub z which needs to be covered for module types (barrelPS, barrel2S, diskPS, disk2S) - RangesAlpha = cms.vdouble( 0., 0., 0., 2048. ), # range in stub row which needs to be covered for module types (barrelPS, barrel2S, diskPS, disk2S) - LayerRs = cms.vdouble( 24.9316, 37.1777, 52.2656, 68.7598, 86.0156, 108.3105 ), # mean radius of outer tracker barrel layer - DiskZs = cms.vdouble( 131.1914, 154.9805, 185.3320, 221.6016, 265.0195 ), # mean z of outer tracker endcap disks - Disk2SRsSet = cms.VPSet( # center radius of outer tracker endcap 2S diks strips - cms.PSet( Disk2SRs = cms.vdouble( 66.4391, 71.4391, 76.2750, 81.2750, 82.9550, 87.9550, 93.8150, 98.8150, 99.8160, 104.8160 ) ), # disk 1 - cms.PSet( Disk2SRs = cms.vdouble( 66.4391, 71.4391, 76.2750, 81.2750, 82.9550, 87.9550, 93.8150, 98.8150, 99.8160, 104.8160 ) ), # disk 2 - cms.PSet( Disk2SRs = cms.vdouble( 63.9903, 68.9903, 74.2750, 79.2750, 81.9562, 86.9562, 92.4920, 97.4920, 99.8160, 104.8160 ) ), # disk 3 - cms.PSet( Disk2SRs = cms.vdouble( 63.9903, 68.9903, 74.2750, 79.2750, 81.9562, 86.9562, 92.4920, 97.4920, 99.8160, 104.8160 ) ), # disk 4 - cms.PSet( Disk2SRs = cms.vdouble( 63.9903, 68.9903, 74.2750, 79.2750, 81.9562, 86.9562, 92.4920, 97.4920, 99.8160, 104.8160 ) ) # disk 5 - ), - InnerRadius = cms.double( 19.6 ), # smallest stub radius after TrackBuilder in cm - WidthsRTB = cms.vint32 ( 7, 7, 12, 12 ), # number of bits used for stub r w.r.t layer/disk centre for module types (barrelPS, barrel2S, diskPS, disk2S) at TB output - ), - - # Parameter specifying TrackingParticle used for Efficiency measurements - TrackingParticle = cms.PSet ( - MinPt = cms.double( 2. ), # pt cut in GeV - MaxEta = cms.double( 2.4 ), # eta cut - MaxVertR = cms.double( 1. ), # cut on vertex pos r in cm - MaxVertZ = cms.double( 30. ), # cut on vertex pos z in cm - MaxD0 = cms.double( 5. ), # cut on impact parameter in cm - MinLayers = cms.int32 ( 4 ), # required number of associated layers to a TP to consider it reconstruct-able and to match it with TTTrack - MinLayersPS = cms.int32 ( 0 ), # required number of associated ps layers to a TP to consider it reconstruct-able - MaxBadStubs2S = cms.int32 ( 1 ), # max number of unassociated 2S stubs allowed to still associate TTTrack with TP - MaxBadStubsPS = cms.int32 ( 0 ) # max number of unassociated PS stubs allowed to still associate TTTrack with TP - ), - - # Fimrware specific Parameter - Firmware = cms.PSet ( - WidthDSPa = cms.int32( 27 ), # width of the 'A' port of an DSP slice - WidthDSPb = cms.int32( 18 ), # width of the 'B' port of an DSP slice - WidthDSPc = cms.int32( 48 ), # width of the 'C' port of an DSP slice - WidthAddrBRAM36 = cms.int32( 9 ), # smallest address width of an BRAM36 configured as broadest simple dual port memory - WidthAddrBRAM18 = cms.int32( 10 ), # smallest address width of an BRAM18 configured as broadest simple dual port memory - NumFramesInfra = cms.int32 ( 6 ), # needed gap between events of emp-infrastructure firmware - FreqLHC = cms.double( 40. ), # LHC bunch crossing rate in MHz - FreqBE = cms.double( 360. ), # processing Frequency of DTC, KF & TFP in MHz, has to be integer multiple of FreqLHC - TMP_FE = cms.int32 ( 8 ), # number of events collected in front-end - TMP_TFP = cms.int32 ( 18 ), # time multiplexed period of track finding processor - SpeedOfLight = cms.double( 2.99792458 ), # in e8 m/s - BField = cms.double( 3.81120228767395 ), # in T - BFieldError = cms.double( 1.e-6 ), # accepted difference to EventSetup in T - OuterRadius = cms.double( 112.7 ), # outer radius of outer tracker in cm - InnerRadius = cms.double( 21.8 ), # inner radius of outer tracker in cm - HalfLength = cms.double( 270. ), # half length of outer tracker in cm - TiltApproxSlope = cms.double( 0.884 ), # In tilted barrel, grad*|z|/r + int approximates |cosTilt| + |sinTilt * cotTheta| - TiltApproxIntercept = cms.double( 0.507 ), # In tilted barrel, grad*|z|/r + int approximates |cosTilt| + |sinTilt * cotTheta| - TiltUncertaintyR = cms.double( 0.12 ), # In tilted barrel, constant assumed stub radial uncertainty * sqrt(12) in cm - MindPhi = cms.double( 0.0001 ), # minimum representable stub phi uncertainty * sqrt(12) + additional terms in rad - MaxdPhi = cms.double( 0.02 ), # maximum representable stub phi uncertainty * sqrt(12) + additional terms in rad - MindZ = cms.double( 0.1 ), # minimum representable stub z uncertainty * sqrt(12) + additional terms in cm - MaxdZ = cms.double( 30. ), # maximum representable stub z uncertainty * sqrt(12) + additional terms in cm - Pitch2S = cms.double( 0.009 ), # strip pitch of outer tracker sensors in cm - PitchPS = cms.double( 0.01 ), # pixel pitch of outer tracker sensors in cm - Length2S = cms.double( 5.025 ), # strip length of outer tracker sensors in cm - LengthPS = cms.double( 0.1467 ), # pixel length of outer tracker sensors in cm - TiltedLayerLimitsZ = cms.vdouble( 15.5, 24.9, 34.3, -1., -1., -1. ), # barrel layer limit |z| value to partition into tilted and untilted region - PSDiskLimitsR = cms.vdouble( 66.4, 66.4, 64.55, 64.55, 64.55 ), # endcap disk limit r value to partition into PS and 2S region - ), - - # Parmeter specifying front-end - FrontEnd = cms.PSet ( - WidthBend = cms.int32 ( 6 ), # number of bits used for internal stub bend - WidthCol = cms.int32 ( 5 ), # number of bits used for internal stub column - WidthRow = cms.int32 ( 11 ), # number of bits used for internal stub row - BaseBend = cms.double( .25 ), # precision of internal stub bend in pitch units - BaseCol = cms.double( 1. ), # precision of internal stub column in pitch units - BaseRow = cms.double( .5 ), # precision of internal stub row in pitch units - BaseWindowSize = cms.double( .5 ), # precision of window sizes in pitch units - BendCut = cms.double( 1.3125 ) # used stub bend uncertainty in pitch units - ), - - # Parmeter specifying DTC - DTC = cms.PSet ( - NumRegions = cms.int32( 9 ), # number of phi slices the outer tracker readout is organized in - NumOverlappingRegions = cms.int32( 2 ), # number of regions a reconstructable particles may cross - NumATCASlots = cms.int32( 12 ), # number of Slots in used ATCA crates - NumDTCsPerRegion = cms.int32( 24 ), # number of DTC boards used to readout a detector region, likely constructed to be an integerer multiple of NumSlots_ - NumModulesPerDTC = cms.int32( 72 ), # max number of sensor modules connected to one DTC board - NumRoutingBlocks = cms.int32( 2 ), # number of systiloic arrays in stub router firmware - DepthMemory = cms.int32( 64 ), # fifo depth in stub router firmware - WidthRowLUT = cms.int32( 4 ), # number of row bits used in look up table - WidthInv2R = cms.int32( 9 ), # number of bits used for stub inv2R. lut addr is col + bend = 11 => 1 BRAM -> 18 bits for min and max val -> 9 - OffsetDetIdDSV = cms.int32( 1 ), # tk layout det id minus DetSetVec->detId - OffsetDetIdTP = cms.int32( -1 ), # tk layout det id minus TrackerTopology lower det id - OffsetLayerDisks = cms.int32( 10 ), # offset in layer ids between barrel layer and endcap disks - OffsetLayerId = cms.int32( 1 ), # offset between 0 and smallest layer id (barrel layer 1) - NumBarrelLayer = cms.int32( 6 ), # - SlotLimitPS = cms.int32( 6 ), # slot number changing from PS to 2S - SlotLimit10gbps = cms.int32( 3 ) # slot number changing from 10 gbps to 5gbps - ), - - # Parmeter specifying TFP - TFP = cms.PSet ( - WidthPhi0 = cms.int32( 12 ), # number of bist used for phi0 - WidthInv2R = cms.int32( 15 ), # number of bist used for inv2R - WidthCot = cms.int32( 16 ), # number of bist used for cot(theta) - WidthZ0 = cms.int32( 12 ), # number of bist used for z0 - NumChannel = cms.int32( 2 ) # number of output links - ), - - # Parmeter specifying GeometricProcessor - GeometricProcessor = cms.PSet ( - NumSectorsPhi = cms.int32 ( 2 ), # number of phi sectors used in hough transform - ChosenRofZ = cms.double( 50. ), # critical radius defining r-z sector shape in cm - RangeChiZ = cms.double( 160. ), # range of stub z residual w.r.t. sector center which needs to be covered - DepthMemory = cms.int32 ( 64 ), # fifo depth in stub router firmware - #BoundariesEta = cms.vdouble( -2.40, -2.08, -1.68, -1.26, -0.90, -0.62, -0.41, -0.20, 0.0, 0.20, 0.41, 0.62, 0.90, 1.26, 1.68, 2.08, 2.40 ) # defining r-z sector shape - BoundariesEta = cms.vdouble( -2.50, -2.23, -1.88, -1.36, -0.90, -0.62, -0.41, -0.20, 0.0, 0.20, 0.41, 0.62, 0.90, 1.36, 1.88, 2.23, 2.50 ) # defining r-z sector shape - ), - - # Parmeter specifying HoughTransform - HoughTransform = cms.PSet ( - NumBinsInv2R = cms.int32( 16 ), # number of used inv2R bins - NumBinsPhiT = cms.int32( 32 ), # number of used phiT bins - MinLayers = cms.int32( 5 ), # required number of stub layers to form a candidate - DepthMemory = cms.int32( 32 ) # internal fifo depth - ), - - # Parmeter specifying MiniHoughTransform - MiniHoughTransform = cms.PSet ( - NumBinsInv2R = cms.int32( 2 ), # number of finer inv2R bins inside HT bin - NumBinsPhiT = cms.int32( 2 ), # number of finer phiT bins inside HT bin - NumDLBs = cms.int32( 2 ), # number of dynamic load balancing steps - NumDLBNodes = cms.int32( 8 ), # number of units per dynamic load balancing step - NumDLBChannel = cms.int32( 2 ), # number of inputs per dynamic load balancing unit - MinLayers = cms.int32( 5 ) # required number of stub layers to form a candidate - ), - - # Parmeter specifying ZHoughTransform - ZHoughTransform = cms.PSet ( - NumBinsZT = cms.int32( 2 ), # - NumBinsCot = cms.int32( 2 ), # - NumStages = cms.int32( 5 ), # - MinLayers = cms.int32( 4 ), # required number of stub layers to form a candidate - MaxTracks = cms.int32( 16 ), # max number of output tracks per node - MaxStubsPerLayer = cms.int32( 4 ) # cut on number of stub per layer for input candidates - ), - - # Parmeter specifying KalmanFilter Input Formatter - - KalmanFilterIn = cms.PSet ( - ShiftRangePhi = cms.int32( 2 ), # power of 2 multiplier of stub phi residual range - ShiftRangeZ = cms.int32( 1 ) # power of 2 multiplier of stub z residual range - ), - - # Parmeter specifying KalmanFilter - KalmanFilter = cms.PSet ( - NumWorker = cms.int32 ( 2 ), # number of kf worker - RangeFactor = cms.double( 2.0 ), # search window of each track parameter in initial uncertainties - MinLayers = cms.int32 ( 4 ), # required number of stub layers to form a track - MaxLayers = cms.int32 ( 7 ), # maximum number of layers added to a track - ShiftInitialC00 = cms.int32 ( 0 ), # - ShiftInitialC11 = cms.int32 ( -2 ), # - ShiftInitialC22 = cms.int32 ( 0 ), # - ShiftInitialC33 = cms.int32 ( 0 ) # - ), - - # Parmeter specifying KalmanFilter Output Formatter - KalmanFilterOut = cms.PSet ( - Chi2rphiConv = cms.int32( 3 ), # Conversion factor between dphi^2/weight and chi2rphi - Chi2rzConv = cms.int32( 13 ), # Conversion factor between dz^2/weight and chi2rz - WeightBinFraction = cms.int32( 0 ), # Number of bits dropped from dphi and dz for v0 and v1 LUTs - DzTruncation = cms.int32( 262144 ), # Constant used in FW to prevent 32-bit int overflow - DphiTruncation = cms.int32( 16 ) # Constant used in FW to prevent 32-bit int overflow - ), - - # Parmeter specifying DuplicateRemoval - DuplicateRemoval = cms.PSet ( - DepthMemory = cms.int32( 16 ) # internal memory depth - ) - -) From 4a0885dc422475c423f921fcf11024cb30acb2c3 Mon Sep 17 00:00:00 2001 From: Anders Date: Fri, 3 Jan 2025 09:49:11 +0100 Subject: [PATCH 04/13] code formatting --- .../interface/CircularBuffer.h | 3 +- .../interface/MatchEngineUnit.h | 3 +- .../interface/MatchProcessor.h | 20 +- .../interface/ProjectionCalculator.h | 21 +- .../TrackFindingTracklet/interface/Settings.h | 14 +- .../interface/TrackletCalculatorBase.h | 43 +- .../interface/TrackletConfigBuilder.h | 10 +- .../interface/TrackletParametersMemory.h | 4 +- .../interface/TrackletProjectionsMemory.h | 6 +- .../interface/VMRouterCM.h | 4 +- .../interface/VMStubMERouter.h | 1 - .../plugins/L1FPGATrackProducer.cc | 4 +- .../TrackFindingTracklet/src/FitTrack.cc | 62 +- L1Trigger/TrackFindingTracklet/src/Globals.cc | 4 +- .../src/MatchEngineUnit.cc | 18 +- .../src/MatchProcessor.cc | 216 ++++--- .../TrackFindingTracklet/src/ProcessBase.cc | 6 +- .../src/ProjectionCalculator.cc | 553 +++++++++--------- .../TrackFindingTracklet/src/Tracklet.cc | 30 +- .../src/TrackletCalculatorBase.cc | 240 ++++---- .../src/TrackletCalculatorDisplaced.cc | 6 +- .../src/TrackletConfigBuilder.cc | 470 +++++++-------- .../src/TrackletEventProcessor.cc | 23 +- .../src/TrackletParametersMemory.cc | 11 +- .../src/TrackletProcessor.cc | 2 +- .../src/TrackletProjectionsMemory.cc | 36 +- .../TrackFindingTracklet/src/VMRouterCM.cc | 2 +- .../src/VMStubMERouter.cc | 11 +- .../src/VMStubsMEMemory.cc | 2 +- .../src/VMStubsTEMemory.cc | 4 +- 30 files changed, 908 insertions(+), 921 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h b/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h index e2afd05d216a9..fc5fe1708f5ed 100644 --- a/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h +++ b/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h @@ -35,7 +35,8 @@ namespace trklet { //near full if writer ptr incremented by 1, 2, or 3 is same as read ptr bool nearfull4() const { - return (((wptr_ + 1) % size_) == rptr_) || (((wptr_ + 2) % size_) == rptr_) || (((wptr_ + 3) % size_) == rptr_) || (((wptr_ + 4) % size_) == rptr_); + return (((wptr_ + 1) % size_) == rptr_) || (((wptr_ + 2) % size_) == rptr_) || (((wptr_ + 3) % size_) == rptr_) || + (((wptr_ + 4) % size_) == rptr_); } //Empty buffer is write ptr is same as read ptr diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h index 792a56f16c8de..0fbfd0654760c 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h @@ -44,7 +44,8 @@ namespace trklet { bool usesecondMinus, bool usesecondPlus, bool isPSseed, - Tracklet* proj, bool print); + Tracklet* proj, + bool print); bool empty() const { return candmatches_.empty(); } diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h index 649df05a6c0dc..6c2b4b0c43517 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h @@ -35,16 +35,15 @@ namespace trklet { bool matchCalculator(Tracklet* tracklet, const Stub* fpgastub, bool print, unsigned int istep); - void read_input_mems(bool &read_is_valid, - std::vector& mem_hasdata, - std::vector& nentries, - int &read_addr, - const std::vector& iMem, - const std::vector& iPage, - unsigned int &imem, - unsigned int &ipage); - - + void read_input_mems(bool& read_is_valid, + std::vector& mem_hasdata, + std::vector& nentries, + int& read_addr, + const std::vector& iMem, + const std::vector& iPage, + unsigned int& imem, + unsigned int& ipage); + private: unsigned int layerdisk_; bool barrel_; @@ -86,7 +85,6 @@ namespace trklet { const Stub* fpgastub_; Tracklet* tracklet_; - AllStubsMemory* allstubs_; std::vector vmstubs_; std::vector inputprojs_; diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionCalculator.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionCalculator.h index 3e2ef592b310d..2e8c749f5ab40 100644 --- a/L1Trigger/TrackFindingTracklet/interface/ProjectionCalculator.h +++ b/L1Trigger/TrackFindingTracklet/interface/ProjectionCalculator.h @@ -15,26 +15,26 @@ namespace trklet { class ProjectionCalculator : public ProcessBase { public: - ProjectionCalculator(std::string name, Settings const& settings, Globals* global); + ProjectionCalculator(std::string name, Settings const &settings, Globals *global); ~ProjectionCalculator() override = default; - void addOutput(MemoryBase* memory, std::string output) override; - void addInput(MemoryBase* memory, std::string input) override; + void addOutput(MemoryBase *memory, std::string output) override; + void addInput(MemoryBase *memory, std::string input) override; void execute(); - void projLayer(int ir, int irinv, int iphi0, int it,int iz0, int &iz, int &iphi); + void projLayer(int ir, int irinv, int iphi0, int it, int iz0, int &iz, int &iphi); - void projDisk(int iz, int irinv, int iphi0, int it,int iz0, int &ir, int &iphi, int &iderphi, int &iderr); + void projDisk(int iz, int irinv, int iphi0, int it, int iz0, int &ir, int &iphi, int &iderphi, int &iderr); private: + std::vector > > + outputproj_; // projs now stored by layer/disk & phi region - std::vector > > outputproj_; // projs now stored by layer/disk & phi region - - std::vector inputpars_; - std::vector outputpars_; - std::vector projnames_; + std::vector inputpars_; + std::vector outputpars_; + std::vector projnames_; //Constants for coordinates and track parameter definitions int n_phi_; @@ -61,7 +61,6 @@ namespace trklet { double phiHG_; std::vector LUT_itinv_; - }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index 1ed22bd138e9b..dbca5afe67a20 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -103,9 +103,7 @@ namespace trklet { unsigned int nbendbitsmedisk() const { return nbendbitsmedisk_; } bool useSeed(unsigned int iSeed) const { return useseeding_.find(iSeed) != useseeding_.end(); } - unsigned int nbitsvmte(unsigned int inner, unsigned int iSeed) const { - return nbitsvmtecm_[inner][iSeed]; - } + unsigned int nbitsvmte(unsigned int inner, unsigned int iSeed) const { return nbitsvmtecm_[inner][iSeed]; } unsigned int nvmte(unsigned int inner, unsigned int iSeed) const { return (1 << nbitsvmte(inner, iSeed)); } unsigned int nbitsvmme(unsigned int layerdisk) const { return nbitsvmme_[layerdisk]; } @@ -139,9 +137,7 @@ namespace trklet { double half2SmoduleWidth() const { return half2SmoduleWidth_; } int nfinephi(unsigned int inner, unsigned int iSeed) const { return nfinephi_[inner][iSeed]; } - double nphireg(unsigned int inner, unsigned int iSeed) const { - return nphiregcm_[inner][iSeed]; - } + double nphireg(unsigned int inner, unsigned int iSeed) const { return nphiregcm_[inner][iSeed]; } double lutwidthtab(unsigned int inner, unsigned int iSeed) const { return lutwidthtab_[inner][iSeed]; } double lutwidthtabextended(unsigned int inner, unsigned int iSeed) const { return lutwidthtabextended_[inner][iSeed]; @@ -546,7 +542,8 @@ namespace trklet { std::array nbitsallstubs_{{3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}}; std::array nbitsvmme_{{2, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2}}; - std::array, 3> nbitsvmte_{ //FIXME unused? + std::array, 3> nbitsvmte_{ + //FIXME unused? {{{2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 3, 2}}, // (3 = #stubs/triplet, only row 1+2 used for tracklet) {{3, 2, 3, 3, 2, 2, 2, 2, 3, 3, 2, 2}}, {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1}}}}; @@ -680,7 +677,8 @@ namespace trklet { //These are the number of bits used for the VM regions in the TE by seedindex //FIXME not independed nbitsvmte - std::array, 3> nphireg_{ //FIXME unused? + std::array, 3> nphireg_{ + //FIXME unused? {{{5, 4, 4, 4, 4, 4, 4, 3, 4, 4, 5, 4}}, //inner {{5, 4, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4}}, //outer {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4}}}}; //outermost (triplets only) diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h index 0184174ed6133..fe2abf9c9b6fd 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h @@ -103,13 +103,27 @@ namespace trklet { double& phider, double& rder); - - void projlayer(int ir, int irinv, int iphi0, int it,int iz0, int &iz, int &iphi); // lower case to differentiate from ProjectionCalculator functions - - void projdisk(int iz, int irinv, int iphi0, int it,int iz0, int &ir, int &iphi, int &iderphi, int &iderr); - - void calcPars(unsigned int idr, int iphi1, int ir1, int iz1, int iphi2, int ir2, int iz2, - int &irinv_new, int &iphi0_new, int &iz0_new, int &it_new); + void projlayer(int ir, + int irinv, + int iphi0, + int it, + int iz0, + int& iz, + int& iphi); // lower case to differentiate from ProjectionCalculator functions + + void projdisk(int iz, int irinv, int iphi0, int it, int iz0, int& ir, int& iphi, int& iderphi, int& iderr); + + void calcPars(unsigned int idr, + int iphi1, + int ir1, + int iz1, + int iphi2, + int ir2, + int iz2, + int& irinv_new, + int& iphi0_new, + int& iz0_new, + int& it_new); void addDiskProj(Tracklet* tracklet, int disk); bool addLayerProj(Tracklet* tracklet, int layer); @@ -129,13 +143,12 @@ namespace trklet { const L1TStub* innerStub, const Stub* outerFPGAStub, const L1TStub* outerStub, - bool print = false); + bool print = false); bool overlapSeeding(const Stub* innerFPGAStub, const L1TStub* innerStub, const Stub* outerFPGAStub, const L1TStub* outerStub, - bool print = false); - + bool print = false); protected: unsigned int iSeed_; @@ -148,8 +161,6 @@ namespace trklet { double phimin_, phimax_; double phiHG_; - - TrackletParametersMemory* trackletpars_; //First index is layer/disk second is phi region @@ -165,7 +176,7 @@ namespace trklet { int n_t_; int n_phidisk_; int n_rdisk_; - + //Constants used for tracklet parameter calculations int n_Deltar_; int n_delta0_; @@ -177,7 +188,7 @@ namespace trklet { int n_r6_; int n_delta02_; int n_x6_; - int n_HG_; + int n_HG_; //Constants used for projectison to layers int n_s_; @@ -188,11 +199,9 @@ namespace trklet { int n_y_; int n_x_; int n_xx6_; - + std::vector LUT_itinv_; std::vector LUT_idrinv_; - - }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h index 72c6e033f988b..3c31eb924334e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h @@ -236,7 +236,7 @@ namespace trklet { unsigned int NSector_; //Number of sectors double rcrit_; //critical radius that defines the sector - bool duplicateMPs_; //if true write configuration with MPs duplicated for L3,L4 + bool duplicateMPs_; //if true write configuration with MPs duplicated for L3,L4 bool extended_; //if true write configuration for extended configuration @@ -272,7 +272,7 @@ namespace trklet { //The projections to each layer/disk from a seed and TC std::vector > > projections_[N_LAYER + N_DISK]; - + //Which matches are used for each seeding layer // L1 L2 L3 L4 L5 L6 D1 D2 D3 D4 D5 int matchport_[N_SEED_PROMPT][N_LAYER + N_DISK] = {{-1, -1, 1, 2, 3, 4, 4, 3, 2, 1, -1}, //L1L2 @@ -285,10 +285,8 @@ namespace trklet { {1, -1, -1, -1, -1, -1, -1, 2, 3, 4, -1}}; //L2D1 //Which seeds handled by each TB - int tbseed_[N_TB][4] = {{0, 1, 3, 7}, - {2, 4, 5, 6}}; - - + int tbseed_[N_TB][4] = {{0, 1, 3, 7}, {2, 4, 5, 6}}; + struct DTCinfo { std::string name; int layer; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h index aed59ce403a17..196f7d268cf08 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h @@ -20,7 +20,7 @@ namespace trklet { ~TrackletParametersMemory() override = default; - void addTracklet(Tracklet *tracklet,unsigned int page = 0) { tracklets_[page].push_back(tracklet); } + void addTracklet(Tracklet *tracklet, unsigned int page = 0) { tracklets_[page].push_back(tracklet); } unsigned int nTracklets(unsigned int page = 0) const { return tracklets_[page].size(); } @@ -33,10 +33,8 @@ namespace trklet { void writeTPAR(bool first, unsigned int iSector); private: - std::vector > tracklets_; unsigned int npage_; - }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h index a2a0ff9fd9b74..07e0fe6220665 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h @@ -27,9 +27,9 @@ namespace trklet { unsigned int nTracklets(unsigned int page = 0) const { return tracklets_[page].size(); } Tracklet* getTracklet(unsigned int i, unsigned int page = 0) { return tracklets_[page][i]; } - + unsigned int nPage() const { return npage_; } - + void clean() override; void writeTPROJ(bool first, unsigned int iSector); @@ -38,7 +38,7 @@ namespace trklet { int disk() const { return disk_; } private: - std::vector< std::vector > tracklets_; + std::vector > tracklets_; bool hasProj_; int layer_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h index 369caf1362d9f..0431b66b30552 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h @@ -55,12 +55,12 @@ namespace trklet { //two VMs. nextrabits_ is the number of bits beyond the bits for the phivm that is used by overlapbits_ unsigned int overlapbits_; unsigned int nextrabits_; - + int nbitszfinebintable_; int nbitsrfinebintable_; unsigned int nvmmebins_; //number of long z/r bins in VM - + TrackletLUT meTable_; //used for ME and outer TE barrel TrackletLUT diskTable_; //outer disk used by D1, D2, and D4 diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubMERouter.h b/L1Trigger/TrackFindingTracklet/interface/VMStubMERouter.h index 4b1ead41f2569..e136d644ac41d 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMStubMERouter.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubMERouter.h @@ -55,4 +55,3 @@ namespace trklet { }; // namespace trklet #endif - diff --git a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc index 4f45064f706f6..a7ce9f7785a82 100644 --- a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc +++ b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc @@ -346,9 +346,7 @@ L1FPGATrackProducer::~L1FPGATrackProducer() { ///////END RUN // -void L1FPGATrackProducer::endRun(const edm::Run& run, const edm::EventSetup& iSetup) { - eventProcessor.printSummary(); -} +void L1FPGATrackProducer::endRun(const edm::Run& run, const edm::EventSetup& iSetup) { eventProcessor.printSummary(); } //////////// // BEGIN JOB diff --git a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc index c6d93837cbf26..cd37e8f3a8cea 100644 --- a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc +++ b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc @@ -937,7 +937,6 @@ void FitTrack::execute(deque& streamTrackRaw, bool print = getName() == "FT_D1D2" && iSector == 3; print = false; - iSector_ = iSector; if (settings_.debugTracklet() && (matches1.size() + matches2.size() + matches3.size() + matches4.size()) > 0) { @@ -957,8 +956,8 @@ void FitTrack::execute(deque& streamTrackRaw, unsigned int countFit = 0; unsigned int countAll = 0; - int istep=-1; - + int istep = -1; + Tracklet* bestTracklet = nullptr; do { istep++; @@ -1064,13 +1063,11 @@ void FitTrack::execute(deque& streamTrackRaw, } } - - if (bestTracklet == nullptr) break; countAll++; - + //Counts total number of matched hits int nMatches = 0; @@ -1078,10 +1075,12 @@ void FitTrack::execute(deque& streamTrackRaw, int nMatchesUniq = 0; bool match = false; - if (print) std::cout << "istep = " << istep; - + if (print) + std::cout << "istep = " << istep; + while (indexArray[0] < matches0.size() && matches0[indexArray[0]] == bestTracklet) { - if (print) std::cout << " match0"; + if (print) + std::cout << " match0"; indexArray[0]++; nMatches++; match = true; @@ -1091,9 +1090,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[1] < matches1.size() && matches1[indexArray[1]] == bestTracklet) { - if (print) std::cout << " match1"; + if (print) + std::cout << " match1"; indexArray[1]++; nMatches++; match = true; @@ -1103,9 +1102,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[2] < matches2.size() && matches2[indexArray[2]] == bestTracklet) { - if (print) std::cout << " match2"; + if (print) + std::cout << " match2"; indexArray[2]++; nMatches++; match = true; @@ -1115,9 +1114,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[3] < matches3.size() && matches3[indexArray[3]] == bestTracklet) { - if (print) std::cout << " match3"; + if (print) + std::cout << " match3"; indexArray[3]++; nMatches++; match = true; @@ -1127,9 +1126,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[4] < matches4.size() && matches4[indexArray[4]] == bestTracklet) { - if (print) std::cout << " match4"; + if (print) + std::cout << " match4"; indexArray[4]++; nMatches++; match = true; @@ -1139,9 +1138,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[5] < matches5.size() && matches5[indexArray[5]] == bestTracklet) { - if (print) std::cout << " match5"; + if (print) + std::cout << " match5"; indexArray[5]++; nMatches++; match = true; @@ -1151,9 +1150,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[6] < matches6.size() && matches6[indexArray[6]] == bestTracklet) { - if (print) std::cout << " match6"; + if (print) + std::cout << " match6"; indexArray[6]++; nMatches++; match = true; @@ -1163,9 +1162,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[7] < matches7.size() && matches7[indexArray[7]] == bestTracklet) { - if (print) std::cout << " match7"; + if (print) + std::cout << " match7"; indexArray[7]++; nMatches++; match = true; @@ -1175,9 +1174,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[8] < matches8.size() && matches8[indexArray[8]] == bestTracklet) { - if (print) std::cout << " match8"; + if (print) + std::cout << " match8"; indexArray[8]++; nMatches++; match = true; @@ -1187,9 +1186,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[9] < matches9.size() && matches9[indexArray[9]] == bestTracklet) { - if (print) std::cout << " match9"; + if (print) + std::cout << " match9"; indexArray[9]++; nMatches++; match = true; @@ -1199,9 +1198,9 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - while (indexArray[10] < matches10.size() && matches10[indexArray[10]] == bestTracklet) { - if (print) std::cout << " match10"; + if (print) + std::cout << " match10"; indexArray[10]++; nMatches++; match = true; @@ -1211,13 +1210,12 @@ void FitTrack::execute(deque& streamTrackRaw, nMatchesUniq++; match = false; - - if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << getName() << " : nMatches = " << nMatches << " nMatchesUniq = " << nMatchesUniq; } - if (print) std::cout << " nMatchesUniq = " << nMatchesUniq << std::endl; + if (print) + std::cout << " nMatchesUniq = " << nMatchesUniq << std::endl; std::vector trackstublist; std::vector> stubidslist; diff --git a/L1Trigger/TrackFindingTracklet/src/Globals.cc b/L1Trigger/TrackFindingTracklet/src/Globals.cc index bf49c9f56a5b3..0eecd7047b8bc 100644 --- a/L1Trigger/TrackFindingTracklet/src/Globals.cc +++ b/L1Trigger/TrackFindingTracklet/src/Globals.cc @@ -7,9 +7,7 @@ using namespace std; using namespace trklet; -Globals::Globals(Settings const& settings) { - -} +Globals::Globals(Settings const& settings) {} Globals::~Globals() { for (auto i : thePhiCorr_) { diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc index 486254d491021..2191fd2de5539 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc @@ -48,7 +48,8 @@ void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, bool usesecondMinus, bool usesecondPlus, bool isPSseed, - Tracklet* proj, bool print) { + Tracklet* proj, + bool print) { vmstubsmemory_ = vmstubsmemory; idle_ = false; nrzbins_ = nrzbins; @@ -80,7 +81,7 @@ void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, if (print) { std::cout << "MEU Init: " << imeu_ << " " << projfinerz << " " << projfinephi << std::endl; } - + good__ = false; } @@ -108,7 +109,8 @@ void MatchEngineUnit::step(bool print) { vmstub__ = vmstubsmemory_->getVMStubMEBin(slot, istub_); if (print) { - std::cout << "Read vmstub MEU "<& mem_hasdata, - std::vector& nentries, - int &read_addr, - const std::vector& iMem, - const std::vector& iPage, - unsigned int &imem, - unsigned int &ipage) { - - +void MatchProcessor::read_input_mems(bool& read_is_valid, + std::vector& mem_hasdata, + std::vector& nentries, + int& read_addr, + const std::vector& iMem, + const std::vector& iPage, + unsigned int& imem, + unsigned int& ipage) { bool any_mem_hasdata = false; - for (unsigned int i=0; inPage(); p++) { - std::cout << "ProjOcc: " << inputprojs_[i]->getName() << " " << p << " " << inputprojs_[i]->nTracklets(p) << std::endl; + for (unsigned int i = 0; i < inputprojs_.size(); i++) { + for (unsigned int p = 0; p < inputprojs_[i]->nPage(); p++) { + std::cout << "ProjOcc: " << inputprojs_[i]->getName() << " " << p << " " << inputprojs_[i]->nTracklets(p) + << std::endl; } } } - + unsigned int imem = 0; unsigned int ipage = 0; @@ -268,21 +260,20 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { iMem.push_back(imem); iPage.push_back(ipage); nentries.push_back(inputprojs_[imem]->nTracklets(ipage)); - mem_hasdata.push_back(inputprojs_[imem]->nTracklets(ipage)>0); + mem_hasdata.push_back(inputprojs_[imem]->nTracklets(ipage) > 0); ipage++; - if (ipage>=inputprojs_[imem]->nPage()) { + if (ipage >= inputprojs_[imem]->nPage()) { ipage = 0; imem++; } } - imem=0; - ipage=0; + imem = 0; + ipage = 0; int read_address = 0; int mem_read_addr = 0; - inputProjBuffer_.reset(); for (const auto& inputproj : inputprojs_) { @@ -293,43 +284,39 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { matchengine.reset(); } - Tracklet *projdata = 0; - Tracklet *projdata_ = 0; + Tracklet* projdata = 0; + Tracklet* projdata_ = 0; bool validin = false; bool validin_ = false; bool validmem = false; - + // Reset so events avoids stale pointers curr_tracklet = nullptr; next_tracklet = nullptr; - for (unsigned int istep = 0; istep < settings_.maxStep("MP"); istep++) { - //bool projdone = false; bool projBufferNearFull = inputProjBuffer_.nearfull4(); // This print statement is useful for detailed comparison with the HLS code // It prints out detailed status information for each clock step - + if (print) { - std::cout << "istep = "< candmatch = matchengines_[iMEbest].read(); candidatematch_ = true; - + fpgastub_ = candmatch.second; tracklet_ = candmatch.first; @@ -432,7 +418,8 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { tmpProj.use(1, 0), tmpProj.use(1, 1), tmpProj.isPSseed(), - tmpProj.proj(), print); + tmpProj.proj(), + print); meactive = true; addedProjection = true; } else { @@ -464,74 +451,74 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { int shift = 0; if (extrabits == ((1U << nextrabits) - 1) && iphi != ((1U << settings_.nbitsvmme(layerdisk_)) - 1)) { - shift = 1; - ivmPlus++; + shift = 1; + ivmPlus++; } unsigned int ivmMinus = iphi; if (extrabits == 0 && iphi != 0) { - shift = -1; - ivmMinus--; + shift = -1; + ivmMinus--; } int projrinv = -1; if (barrel_) { - FPGAWord phider = projdata_->proj(layerdisk_).fpgaphiprojder(); - projrinv = (1 << (nrinv_ - 1)) - 1 - (phider.value() >> (phider.nbits() - nrinv_)); + FPGAWord phider = projdata_->proj(layerdisk_).fpgaphiprojder(); + projrinv = (1 << (nrinv_ - 1)) - 1 - (phider.value() >> (phider.nbits() - nrinv_)); } else { - //The next lines looks up the predicted bend based on: - // 1 - r projections - // 2 - phi derivative - // 3 - the sign - i.e. if track is forward or backward + //The next lines looks up the predicted bend based on: + // 1 - r projections + // 2 - phi derivative + // 3 - the sign - i.e. if track is forward or backward - int rindex = - (projdata_->proj(layerdisk_).fpgarzproj().value() >> (projdata_->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) & - ((1 << nrbits_) - 1); + int rindex = (projdata_->proj(layerdisk_).fpgarzproj().value() >> + (projdata_->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) & + ((1 << nrbits_) - 1); - int phiprojder = projdata_->proj(layerdisk_).fpgaphiprojder().value(); + int phiprojder = projdata_->proj(layerdisk_).fpgaphiprojder().value(); - int phiderindex = (phiprojder >> (projdata_->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) & - ((1 << nphiderbits_) - 1); + int phiderindex = (phiprojder >> (projdata_->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) & + ((1 << nphiderbits_) - 1); - int signindex = projdata_->proj(layerdisk_).fpgarzprojder().value() < 0; + int signindex = projdata_->proj(layerdisk_).fpgarzprojder().value() < 0; - int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; + int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; - projrinv = rinvbendlut_.lookup(bendindex); + projrinv = rinvbendlut_.lookup(bendindex); - projdata_->proj(layerdisk_).setBendIndex(projrinv); + projdata_->proj(layerdisk_).setBendIndex(projrinv); } assert(projrinv >= 0); unsigned int projfinephi = - (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + NFINEPHIBITS))) & ((1 << NFINEPHIBITS) - 1); + (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + NFINEPHIBITS))) & ((1 << NFINEPHIBITS) - 1); unsigned int slot; bool second; int projfinerz; if (barrel_) { - slot = projdata_->proj(layerdisk_).fpgarzbin1projvm().value(); - second = projdata_->proj(layerdisk_).fpgarzbin2projvm().value(); - projfinerz = projdata_->proj(layerdisk_).fpgafinerzvm().value(); + slot = projdata_->proj(layerdisk_).fpgarzbin1projvm().value(); + second = projdata_->proj(layerdisk_).fpgarzbin2projvm().value(); + projfinerz = projdata_->proj(layerdisk_).fpgafinerzvm().value(); } else { - //The -1 here is due to not using the full range of bits. Should be fixed. - unsigned int ir = projdata_->proj(layerdisk_).fpgarzproj().value() >> - (projdata_->proj(layerdisk_).fpgarzproj().nbits() - nrprojbits_ - 1); - unsigned int word = diskRadius_.lookup(ir); - - slot = (word >> 1) & ((1 << N_RZBITS) - 1); - if (projdata_->proj(layerdisk_).fpgarzprojder().value() < 0) { - slot += (1 << N_RZBITS); - } - second = word & 1; - projfinerz = word >> 4; + //The -1 here is due to not using the full range of bits. Should be fixed. + unsigned int ir = projdata_->proj(layerdisk_).fpgarzproj().value() >> + (projdata_->proj(layerdisk_).fpgarzproj().nbits() - nrprojbits_ - 1); + unsigned int word = diskRadius_.lookup(ir); + + slot = (word >> 1) & ((1 << N_RZBITS) - 1); + if (projdata_->proj(layerdisk_).fpgarzprojder().value() < 0) { + slot += (1 << N_RZBITS); + } + second = word & 1; + projfinerz = word >> 4; } bool isPSseed = projdata_->PSseed(); int nbins = (1 << N_RZBITS); if (layerdisk_ >= N_LAYER) { - nbins *= 2; //twice as many bins in disks (since there are two disks) + nbins *= 2; //twice as many bins in disks (since there are two disks) } VMStubsMEMemory* stubmem = vmstubs_[0]; @@ -539,7 +526,7 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { bool usesecondMinus = (second && (stubmem->nStubsBin(ivmMinus * nbins + slot + 1) != 0)); bool usefirstPlus = ivmPlus != ivmMinus && (stubmem->nStubsBin(ivmPlus * nbins + slot) != 0); bool usesecondPlus = ivmPlus != ivmMinus && (second && (stubmem->nStubsBin(ivmPlus * nbins + slot + 1) != 0)); - + bool good = usefirstPlus || usesecondPlus || usefirstMinus || usesecondMinus; /* @@ -556,24 +543,24 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { zbin2 = settings_.MEBins() - 1; } */ - + if (good) { - ProjectionTemp tmpProj(projdata_, - slot, - projrinv, - projfinerz, - projfinephi, - ivmMinus, - shift, - usefirstMinus, - usefirstPlus, - usesecondMinus, - usesecondPlus, - isPSseed); - if (print) { - std::cout << "Add projection to inputProjBuffer istep = " << istep << std::endl; - } - inputProjBuffer_.store(tmpProj); + ProjectionTemp tmpProj(projdata_, + slot, + projrinv, + projfinerz, + projfinephi, + ivmMinus, + shift, + usefirstMinus, + usefirstPlus, + usesecondMinus, + usesecondPlus, + isPSseed); + if (print) { + std::cout << "Add projection to inputProjBuffer istep = " << istep << std::endl; + } + inputProjBuffer_.store(tmpProj); } } @@ -584,12 +571,13 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { if (validin) { TrackletProjectionsMemory* projMem = inputprojs_[imem]; - projdata = projMem->getTracklet(read_address,ipage); + projdata = projMem->getTracklet(read_address, ipage); if (print & validin) { - std::cout << "Reading iprojmem page, readaddress : " << istep << " " << imem << " " << ipage << " " << read_address << std::endl; + std::cout << "Reading iprojmem page, readaddress : " << istep << " " << imem << " " << ipage << " " + << read_address << std::endl; } } - + validmem = !projBufferNearFull; read_address = mem_read_addr; @@ -598,8 +586,6 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { read_input_mems(validmem, mem_hasdata, nentries, mem_read_addr, iMem, iPage, imem, ipage); } - - // // Check if done // @@ -617,8 +603,7 @@ void MatchProcessor::execute(unsigned int iSector, double phimin) { } */ - - } // end of istep + } // end of istep if (settings_.writeMonitorData("MC")) { globals_->ofstream("matchcalculator.txt") << getName() << " " << countall << " " << countsel << endl; @@ -746,11 +731,10 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b } if (imatch) { - if (print) { - std::cout << "Adding match on istep = " << istep << std::endl; + std::cout << "Adding match on istep = " << istep << std::endl; } - + tracklet->addMatch(layerdisk_, ideltaphi, ideltaz, @@ -767,8 +751,8 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b int iSeed = tracklet->getISeed(); int iTB = 0; - if ( iSeed == 2 || iSeed == 4 || iSeed == 5 || iSeed == 6 ) { - iTB = 1; + if (iSeed == 2 || iSeed == 4 || iSeed == 5 || iSeed == 6) { + iTB = 1; } assert(fullmatches_[iTB] != nullptr); fullmatches_[iTB]->addMatch(tracklet, fpgastub); @@ -959,8 +943,8 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, b int iSeed = tracklet->getISeed(); int iTB = 0; - if ( iSeed == 2 || iSeed == 4 || iSeed == 5 || iSeed == 6 ) { - iTB = 1; + if (iSeed == 2 || iSeed == 4 || iSeed == 5 || iSeed == 6) { + iTB = 1; } assert(fullmatches_[iTB] != nullptr); fullmatches_[iTB]->addMatch(tracklet, fpgastub); diff --git a/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc index 3362536bdba19..e072c52e6b8e9 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc @@ -159,10 +159,8 @@ unsigned int ProcessBase::getISeed(const std::string& name) { pos = name1.find('_'); std::string name2 = name1.substr(0, pos); - unordered_map seedmap = { - {"AAAA", 0}, {"BBBB", 1} - }; - auto found = seedmap.find(name2); + unordered_map seedmap = {{"AAAA", 0}, {"BBBB", 1}}; + auto found = seedmap.find(name2); if (found != seedmap.end()) return found->second; diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc index 55bafea743340..07b964fda6e4b 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionCalculator.cc @@ -12,85 +12,83 @@ using namespace trklet; ProjectionCalculator::ProjectionCalculator(string name, Settings const& settings, Globals* global) : ProcessBase(name, settings, global) { + //Constants for coordinates and track parameter definitions (taken from TrackletCalculatorBase.cc) + n_phi_ = 17; + n_r_ = 12; + n_z_ = 11; + n_phi0_ = 16; + n_rinv_ = 13; + n_t_ = 9; + n_phidisk_ = n_phi_ - 3; + n_rdisk_ = n_r_ - 1; + + //Constants used for projectison to layers + n_s_ = 12; + n_s6_ = 14; + + //Constants used for projectison to disks + n_tinv_ = 12; + n_y_ = 14; + n_x_ = 14; + n_xx6_ = 14; + + phiHG_ = settings_.dphisectorHG(); + + LUT_itinv_.resize(8192); + + for (int it = 0; it < 8192; it++) { + if (it < 100) { + LUT_itinv_[it] = 0; + } else { + LUT_itinv_[it] = (1 << (n_t_ + n_tinv_)) / abs(it); + } + } - //Constants for coordinates and track parameter definitions (taken from TrackletCalculatorBase.cc) - n_phi_ = 17; - n_r_ = 12; - n_z_ = 11; - n_phi0_ = 16; - n_rinv_ = 13; - n_t_ = 9; - n_phidisk_ = n_phi_-3; - n_rdisk_ = n_r_-1; - - //Constants used for projectison to layers - n_s_ = 12; - n_s6_ = 14; - - //Constants used for projectison to disks - n_tinv_ = 12; - n_y_ = 14; - n_x_ = 14; - n_xx6_ = 14; - - phiHG_ = settings_.dphisectorHG(); - - LUT_itinv_.resize(8192); - - for (int it = 0; it < 8192; it++) { - if (it<100) { - LUT_itinv_[it] = 0; - } else { - LUT_itinv_[it] = (1 << (n_t_ + n_tinv_)) / abs(it); - } - } - - for (unsigned int layerdisk = 0; layerdisk < N_LAYER + N_DISK; layerdisk++) { - std::vector> tmp(settings_.nallstubs(layerdisk)); - outputproj_.push_back(tmp); - } - + for (unsigned int layerdisk = 0; layerdisk < N_LAYER + N_DISK; layerdisk++) { + std::vector> tmp(settings_.nallstubs(layerdisk)); + outputproj_.push_back(tmp); + } } - // Project to layer (taken from TrackletCalculatorBase.cc) -void ProjectionCalculator::projLayer(int ir, int irinv, int iphi0, int it, int iz0, int &iz, int &iphi) { - int irtilde = ir*phiHG_/sqrt(6.0)+0.5; - int is = (irtilde*irinv) >> n_s_; - int is6 = (1 << n_s6_) + ((is*is) >> (2 + 2*n_r_ + 2*n_rinv_ - 2*n_s_ - n_s6_)); - int iu = (ir*irinv) >> (n_r_ + n_rinv_ + 1 - n_phi_); - iphi = (iphi0 << (n_phi_ - n_phi0_)) - ((iu*is6) >> n_s6_); - int iv = (it*ir) >> (n_r_ + n_t_ - n_z_); - iz = iz0 + ((iv*is6) >> n_s6_); +// Project to layer (taken from TrackletCalculatorBase.cc) +void ProjectionCalculator::projLayer(int ir, int irinv, int iphi0, int it, int iz0, int& iz, int& iphi) { + int irtilde = ir * phiHG_ / sqrt(6.0) + 0.5; + int is = (irtilde * irinv) >> n_s_; + int is6 = (1 << n_s6_) + ((is * is) >> (2 + 2 * n_r_ + 2 * n_rinv_ - 2 * n_s_ - n_s6_)); + int iu = (ir * irinv) >> (n_r_ + n_rinv_ + 1 - n_phi_); + iphi = (iphi0 << (n_phi_ - n_phi0_)) - ((iu * is6) >> n_s6_); + int iv = (it * ir) >> (n_r_ + n_t_ - n_z_); + iz = iz0 + ((iv * is6) >> n_s6_); } - // Project to disk (taken from TrackletCalculatorBase.cc) -void ProjectionCalculator::projDisk(int iz, int irinv, int iphi0, int it,int iz0, int &ir, int &iphi, int &iderphi, int &iderr) { +// Project to disk (taken from TrackletCalculatorBase.cc) +void ProjectionCalculator::projDisk( + int iz, int irinv, int iphi0, int it, int iz0, int& ir, int& iphi, int& iderphi, int& iderr) { + int iz0_sign = (it > 0) ? iz0 : -iz0; + + assert(abs(it) < LUT_itinv_.size()); + int itinv = LUT_itinv_[abs(it)]; - int iz0_sign = (it>0)?iz0:-iz0; + iderphi = (-irinv * itinv) >> 17; + iderr = itinv >> 5; - assert(abs(it)> 17; - iderr = itinv >> 5; - - if (it<0) { - iderphi = -iderphi; - iderr = -iderr; - } - - int iw = (((iz << (n_r_ - n_z_)) - (iz0_sign << (n_r_ - n_z_)))*itinv) >> n_tinv_; + if (it < 0) { + iderphi = -iderphi; + iderr = -iderr; + } + + int iw = (((iz << (n_r_ - n_z_)) - (iz0_sign << (n_r_ - n_z_))) * itinv) >> n_tinv_; - iphi = (iphi0 >> (n_phi0_ - n_phidisk_)) - ((iw*irinv) >> (1 + n_r_ + n_rinv_ - n_phidisk_)); + iphi = (iphi0 >> (n_phi0_ - n_phidisk_)) - ((iw * irinv) >> (1 + n_r_ + n_rinv_ - n_phidisk_)); - int ifact = (1 << n_y_)*phiHG_/sqrt(6.0); + int ifact = (1 << n_y_) * phiHG_ / sqrt(6.0); - int iy = (ifact * irinv) >> n_y_; + int iy = (ifact * irinv) >> n_y_; - int ix = (iw*iy) >> n_x_; + int ix = (iw * iy) >> n_x_; - int ix6 = (1 << n_xx6_) - ( (ix*ix) >> (2 + 2*n_r_ + 2*n_rinv_ - 2*n_x_ - n_xx6_)); + int ix6 = (1 << n_xx6_) - ((ix * ix) >> (2 + 2 * n_r_ + 2 * n_rinv_ - 2 * n_x_ - n_xx6_)); - ir = (iw*ix6) >> (n_r_ - n_rdisk_ + n_xx6_); + ir = (iw * ix6) >> (n_r_ - n_rdisk_ + n_xx6_); } void ProjectionCalculator::addOutput(MemoryBase* memory, string output) { @@ -101,16 +99,19 @@ void ProjectionCalculator::addOutput(MemoryBase* memory, string output) { if (output == "projout") { auto* tmp = dynamic_cast(memory); int extraMPOffset = 0; - if (memory->getName().substr(memory->getName().size()-2,2) == "_E") { + if (memory->getName().substr(memory->getName().size() - 2, 2) == "_E") { extraMPOffset = 2; } - unsigned int layerdisk = memory->getName()[memory->getName().size() - 5 - extraMPOffset] - '1'; //layer or disk counting from 0 - unsigned int phiregion = memory->getName()[memory->getName().size() - 1 - extraMPOffset] - 'A'; //phiregion counting from 0 - if (memory->getName()[memory->getName().size() - 6 - extraMPOffset] == 'D') layerdisk += N_LAYER; + unsigned int layerdisk = + memory->getName()[memory->getName().size() - 5 - extraMPOffset] - '1'; //layer or disk counting from 0 + unsigned int phiregion = + memory->getName()[memory->getName().size() - 1 - extraMPOffset] - 'A'; //phiregion counting from 0 + if (memory->getName()[memory->getName().size() - 6 - extraMPOffset] == 'D') + layerdisk += N_LAYER; projnames_.push_back(memory->getName()); assert(layerdisk < N_LAYER + N_DISK); assert(phiregion < outputproj_[layerdisk].size()); - assert(outputproj_[layerdisk][phiregion].size()<2); + assert(outputproj_[layerdisk][phiregion].size() < 2); assert(tmp != nullptr); outputproj_[layerdisk][phiregion].push_back(tmp); return; @@ -132,14 +133,14 @@ void ProjectionCalculator::addInput(MemoryBase* memory, string input) { << input; } - if (input == "tparin" ) { + if (input == "tparin") { auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); inputpars_.push_back(tmp); return; } - if (input == "projin" ) { + if (input == "projin") { //Hack to keep projection in config but ignore here return; } @@ -148,229 +149,237 @@ void ProjectionCalculator::addInput(MemoryBase* memory, string input) { } void ProjectionCalculator::execute() { - - for(unsigned int i = 0 ; i < inputpars_.size() ; i++) { // send copy of tpars to TB + for (unsigned int i = 0; i < inputpars_.size(); i++) { // send copy of tpars to TB int projPage = 0; std::string iname = inputpars_[i]->getName(); - std::vector seedNames = {"L1L2", "L2L3", "L3L4", "L5L6", "D1D2", "D3D4", "L1D1", "L2D1"}; - for (int iSeed = 0; iSeed < 8; ++iSeed){ - std::string seed = iname.substr(5, 4); // extract seed from name - bool psSeed = !(iSeed == Seed::L3L4 || iSeed == Seed::L5L6 ); - if (seed == seedNames[iSeed]){ // FIXME find easier way to get iSeed (probably from seed name) - unsigned int numTCs = nMergedTC[iSeed]; - for(unsigned int iTC = 0; iTC < numTCs; ++iTC){ - std::string tcStr = TrackletConfigBuilder::iMergedTCStr(iSeed, iTC); - size_t index = tcStr.find(iname[9]); // find index in merged TC string to find page - if (index != std::string::npos) { - projPage = static_cast(index); // calculate projPage FIXME find better way of doing this - } else { + for (int iSeed = 0; iSeed < 8; ++iSeed) { + std::string seed = iname.substr(5, 4); // extract seed from name + bool psSeed = !(iSeed == Seed::L3L4 || iSeed == Seed::L5L6); + if (seed == seedNames[iSeed]) { // FIXME find easier way to get iSeed (probably from seed name) + unsigned int numTCs = nMergedTC[iSeed]; + for (unsigned int iTC = 0; iTC < numTCs; ++iTC) { + std::string tcStr = TrackletConfigBuilder::iMergedTCStr(iSeed, iTC); + size_t index = tcStr.find(iname[9]); // find index in merged TC string to find page + if (index != std::string::npos) { + projPage = static_cast(index); // calculate projPage FIXME find better way of doing this + } else { continue; + } } - } - - for(unsigned int k = 0 ; k < outputpars_.size() ; k++) { // add copy of par to merged par output memory - std::string oname = outputpars_[k]->getName(); - int parPage = iname[9]-oname[9]; - for(unsigned int j = 0; j < inputpars_[i]->nTracklets(); j++) { - outputpars_[k]->addTracklet(inputpars_[i]->getTracklet(j), parPage); - } - } - - - for(unsigned int k = 0; k < inputpars_[i]->nTracklets(); k++){ - auto tracklet = inputpars_[i]->getTracklet(k); - //double phi0 = tracklet->phi0(); // non-digi track params, currently unneeded / unused - //double z0 = tracklet->z0(); - //double t = tracklet->t(); - //double rinv = tracklet->rinv(); - - int irinv = tracklet->fpgarinv().value(); // digi track params - int iphi0 = tracklet->fpgaphi0().value(); - int iz0 = tracklet->fpgaz0().value(); - int it = tracklet->fpgat().value(); - - std::vector izr_LD(N_LAYER + N_DISK, 0); - std::vector iphi_LD(N_LAYER + N_DISK, 0); - std::vector valid_LD(N_LAYER + N_DISK, 0); - std::vector addedLayer(N_LAYER, 0); - std::vector der_phi_LD(2, 0); - std::vector der_zr_LD(2, 0); - - Projection projs[N_LAYER + N_DISK]; - - ///////////////////////////////// - // calculate layer projections // - ///////////////////////////////// - bool valid_zmin, valid_zmax, valid_phimin, valid_phimax; // CODE ADAPTED FROM FIRMWARE-HLS PROJECTIONCALCULATOR - could be simplified to only consider layers/disks in wiring config. - const int zmin = -(1 << (settings_.nzbitsstub(0) - 1)); - const int zmax = (1 << (settings_.nzbitsstub(0) - 1)); - const int phimax = (1 << (settings_.nphibitsstub(3))) - 1; - const int phimin = 0; - for (unsigned int iLayer = 0; iLayer < N_LAYER; ++iLayer){ // calculate layer projections - int ir; - ir = settings_.irmean(iLayer); - projLayer(ir, irinv, iphi0, it, iz0, izr_LD[iLayer], iphi_LD[iLayer]); - valid_zmin = izr_LD[iLayer] >= zmin; - valid_zmax = izr_LD[iLayer] < zmax; - valid_phimax = iphi_LD[iLayer] < phimax; - valid_phimin = iphi_LD[iLayer] > phimin; - valid_LD[iLayer] = valid_zmin & valid_zmax & valid_phimax & valid_phimin; - if(iLayer < N_PSLAYER){ // shift phi or z value if PS or 2S layer - iphi_LD[iLayer] = iphi_LD[iLayer] >> 3; - } - else{ - izr_LD[iLayer] = izr_LD[iLayer] >> 4; - } - } - - // Layer Proj Derivatives - der_phi_LD[0] = -(irinv >> (1+3)); - der_zr_LD[0] = it >> 3; - - //////////////////////////////// - // calculate disk projections // - //////////////////////////////// - double irmindisk = settings_.rmindisk() / settings_.krprojshiftdisk(); - double irmaxdisk = settings_.rmaxdisk() / settings_.krprojshiftdisk(); - - int tcut = 1.0/(settings_.ktpars()); - - for (unsigned int iDisk = N_LAYER; iDisk < N_LAYER + N_DISK; ++iDisk){ - int izproj = settings_.izmean(iDisk % N_LAYER); - projDisk(izproj, irinv, iphi0, it, iz0, izr_LD[iDisk], iphi_LD[iDisk], der_phi_LD[1], der_zr_LD[1]); - valid_LD[iDisk] = izr_LD[iDisk] >= irmindisk && izr_LD[iDisk] < irmaxdisk && ((it > tcut) || (it < -tcut)); - } - /////////////////////////////////// - // Write projections to memories // - /////////////////////////////////// + for (unsigned int k = 0; k < outputpars_.size(); k++) { // add copy of par to merged par output memory + std::string oname = outputpars_[k]->getName(); + int parPage = iname[9] - oname[9]; + for (unsigned int j = 0; j < inputpars_[i]->nTracklets(); j++) { + outputpars_[k]->addTracklet(inputpars_[i]->getTracklet(j), parPage); + } + } - for (unsigned int j = 0; j < settings_.projlayers()[iSeed].size(); ++j){ - unsigned int layer = settings_.projlayers()[iSeed][j]; // Loop through layers/disks projected to - if (layer == 0) continue; // for seeds not projecting to any layers - if(valid_LD[layer - 1]){ // If projection to layer/disk is valid - if ((izr_LD[layer - 1] == - (1 << (settings_.nzbitsstub(layer - 1) - 1))) || (izr_LD[layer - 1] == ((1 << (settings_.nzbitsstub(layer - 1) - 1)) - 1))) { // reject extreme z values - continue; + for (unsigned int k = 0; k < inputpars_[i]->nTracklets(); k++) { + auto tracklet = inputpars_[i]->getTracklet(k); + //double phi0 = tracklet->phi0(); // non-digi track params, currently unneeded / unused + //double z0 = tracklet->z0(); + //double t = tracklet->t(); + //double rinv = tracklet->rinv(); + + int irinv = tracklet->fpgarinv().value(); // digi track params + int iphi0 = tracklet->fpgaphi0().value(); + int iz0 = tracklet->fpgaz0().value(); + int it = tracklet->fpgat().value(); + + std::vector izr_LD(N_LAYER + N_DISK, 0); + std::vector iphi_LD(N_LAYER + N_DISK, 0); + std::vector valid_LD(N_LAYER + N_DISK, 0); + std::vector addedLayer(N_LAYER, 0); + std::vector der_phi_LD(2, 0); + std::vector der_zr_LD(2, 0); + + Projection projs[N_LAYER + N_DISK]; + + ///////////////////////////////// + // calculate layer projections // + ///////////////////////////////// + bool valid_zmin, valid_zmax, valid_phimin, + valid_phimax; // CODE ADAPTED FROM FIRMWARE-HLS PROJECTIONCALCULATOR - could be simplified to only consider layers/disks in wiring config. + const int zmin = -(1 << (settings_.nzbitsstub(0) - 1)); + const int zmax = (1 << (settings_.nzbitsstub(0) - 1)); + const int phimax = (1 << (settings_.nphibitsstub(3))) - 1; + const int phimin = 0; + for (unsigned int iLayer = 0; iLayer < N_LAYER; ++iLayer) { // calculate layer projections + int ir; + ir = settings_.irmean(iLayer); + projLayer(ir, irinv, iphi0, it, iz0, izr_LD[iLayer], iphi_LD[iLayer]); + valid_zmin = izr_LD[iLayer] >= zmin; + valid_zmax = izr_LD[iLayer] < zmax; + valid_phimax = iphi_LD[iLayer] < phimax; + valid_phimin = iphi_LD[iLayer] > phimin; + valid_LD[iLayer] = valid_zmin & valid_zmax & valid_phimax & valid_phimin; + if (iLayer < N_PSLAYER) { // shift phi or z value if PS or 2S layer + iphi_LD[iLayer] = iphi_LD[iLayer] >> 3; + } else { + izr_LD[iLayer] = izr_LD[iLayer] >> 4; + } + } + + // Layer Proj Derivatives + der_phi_LD[0] = -(irinv >> (1 + 3)); + der_zr_LD[0] = it >> 3; + + //////////////////////////////// + // calculate disk projections // + //////////////////////////////// + double irmindisk = settings_.rmindisk() / settings_.krprojshiftdisk(); + double irmaxdisk = settings_.rmaxdisk() / settings_.krprojshiftdisk(); + + int tcut = 1.0 / (settings_.ktpars()); + + for (unsigned int iDisk = N_LAYER; iDisk < N_LAYER + N_DISK; ++iDisk) { + int izproj = settings_.izmean(iDisk % N_LAYER); + projDisk(izproj, irinv, iphi0, it, iz0, izr_LD[iDisk], iphi_LD[iDisk], der_phi_LD[1], der_zr_LD[1]); + valid_LD[iDisk] = izr_LD[iDisk] >= irmindisk && izr_LD[iDisk] < irmaxdisk && ((it > tcut) || (it < -tcut)); + } + + /////////////////////////////////// + // Write projections to memories // + /////////////////////////////////// + + for (unsigned int j = 0; j < settings_.projlayers()[iSeed].size(); ++j) { + unsigned int layer = settings_.projlayers()[iSeed][j]; // Loop through layers/disks projected to + if (layer == 0) + continue; // for seeds not projecting to any layers + if (valid_LD[layer - 1]) { // If projection to layer/disk is valid + if ((izr_LD[layer - 1] == -(1 << (settings_.nzbitsstub(layer - 1) - 1))) || + (izr_LD[layer - 1] == + ((1 << (settings_.nzbitsstub(layer - 1) - 1)) - 1))) { // reject extreme z values + continue; + } + if (std::abs(izr_LD[layer - 1]) > 2048) { + continue; + } + + double phiprojlayer = iphi_LD[layer - 1] * settings_.kphi(layer - 1); // get un-digi projections + double zprojlayer = + izr_LD[layer - 1] * + settings_ + .kz(); // FIXME find better way to calculate these - but don't have stub coordinates to use exacttracklet function + double phiderlayer = der_phi_LD[0] * settings_.kphider(); + double zderlayer = der_zr_LD[0] * settings_.kzder(); + + projs[layer - 1].init(settings_, + layer - 1, + iphi_LD[layer - 1], + izr_LD[layer - 1], + der_phi_LD[0], + der_zr_LD[0], + phiprojlayer, + zprojlayer, + phiderlayer, + zderlayer, + phiprojlayer, + zprojlayer, + phiderlayer, + zderlayer, + psSeed); + addedLayer[layer - 1] = true; } - if (std::abs(izr_LD[layer - 1]) > 2048) { - continue; + } + for (unsigned int j = 0; j < settings_.projdisks()[iSeed].size(); ++j) { + unsigned int disk = settings_.projdisks()[iSeed][j]; + if (disk == 0) + continue; // for seeds not projecting to any disks + if (valid_LD[N_LAYER + disk - 1]) { // If projection to layer/disk is valid + + if (iphi_LD[N_LAYER + disk - 1] <= 0) // reject extreme phi values + continue; + if (iphi_LD[N_LAYER + disk - 1] >= (1 << settings_.nphibitsstub(0)) - 1) + continue; + + if (iSeed <= 4) { // if barrel seed, need to check if haven't already projected to layer + if (disk == 1 && addedLayer[5]) + continue; + if (disk == 2 && addedLayer[4]) + continue; + if (disk == 3 && addedLayer[3]) + continue; + if (disk == 4 && addedLayer[2]) + continue; + } + + double phiprojdisk = + iphi_LD[N_LAYER + disk - 1] * + settings_.kphi(N_LAYER); // un-digitize values using granularities for initializing projections + double rprojdisk = izr_LD[N_LAYER + disk - 1] * settings_.kr(); + double phiderdisk = der_phi_LD[1] * settings_.kphiderdisk(); + double rderdisk = der_zr_LD[1] * settings_.krder(); + + projs[N_LAYER + disk - 1].init(settings_, + N_LAYER + disk - 1, + iphi_LD[N_LAYER + disk - 1], + izr_LD[N_LAYER + disk - 1], + der_phi_LD[1], + der_zr_LD[1], + phiprojdisk, + rprojdisk, + phiderdisk, + rderdisk, + phiprojdisk, + rprojdisk, + phiderdisk, + rderdisk, + psSeed); } + } - double phiprojlayer = iphi_LD[layer - 1] * settings_.kphi(layer - 1); // get un-digi projections - double zprojlayer = izr_LD[layer - 1] * settings_.kz(); // FIXME find better way to calculate these - but don't have stub coordinates to use exacttracklet function - double phiderlayer = der_phi_LD[0] * settings_.kphider(); - double zderlayer = der_zr_LD[0] * settings_.kzder(); - - projs[layer - 1].init(settings_, - layer - 1, - iphi_LD[layer - 1], - izr_LD[layer - 1], - der_phi_LD[0], - der_zr_LD[0], - phiprojlayer, - zprojlayer, - phiderlayer, - zderlayer, - phiprojlayer, - zprojlayer, - phiderlayer, - zderlayer, - psSeed); - addedLayer[layer - 1] = true; - } - } - for (unsigned int j = 0; j < settings_.projdisks()[iSeed].size(); ++j){ - unsigned int disk = settings_.projdisks()[iSeed][j]; - if (disk == 0) continue; // for seeds not projecting to any disks - if(valid_LD[N_LAYER + disk - 1]){ // If projection to layer/disk is valid - - if (iphi_LD[N_LAYER + disk - 1] <= 0) // reject extreme phi values - continue; - if (iphi_LD[N_LAYER + disk - 1] >= (1 << settings_.nphibitsstub(0)) - 1) - continue; - - if (iSeed <= 4){ // if barrel seed, need to check if haven't already projected to layer - if (disk == 1 && addedLayer[5]) continue; - if (disk == 2 && addedLayer[4]) continue; - if (disk == 3 && addedLayer[3]) continue; - if (disk == 4 && addedLayer[2]) continue; - } - - double phiprojdisk = iphi_LD[N_LAYER + disk - 1]*settings_.kphi(N_LAYER); // un-digitize values using granularities for initializing projections - double rprojdisk = izr_LD[N_LAYER + disk - 1] * settings_.kr(); - double phiderdisk = der_phi_LD[1]* settings_.kphiderdisk(); - double rderdisk = der_zr_LD[1] * settings_.krder(); - - projs[N_LAYER + disk - 1].init(settings_, - N_LAYER + disk - 1, - iphi_LD[N_LAYER + disk - 1], - izr_LD[N_LAYER + disk - 1], - der_phi_LD[1], - der_zr_LD[1], - phiprojdisk, - rprojdisk, - phiderdisk, - rderdisk, - phiprojdisk, - rprojdisk, - phiderdisk, - rderdisk, - psSeed); - } - } - - tracklet->addProjs(projs); - for(unsigned int layerdisk = 0; layerdisk < N_LAYER + N_DISK; ++layerdisk){ - if (tracklet->validProj(layerdisk)) { - if (layerdisk < N_LAYER){ - - FPGAWord fpgaz = tracklet->proj(layerdisk).fpgarzproj(); - FPGAWord fpgaphi = tracklet->proj(layerdisk).fpgaphiproj(); + tracklet->addProjs(projs); + for (unsigned int layerdisk = 0; layerdisk < N_LAYER + N_DISK; ++layerdisk) { + if (tracklet->validProj(layerdisk)) { + if (layerdisk < N_LAYER) { + FPGAWord fpgaz = tracklet->proj(layerdisk).fpgarzproj(); + FPGAWord fpgaphi = tracklet->proj(layerdisk).fpgaphiproj(); - if (fpgaphi.atExtreme()) - edm::LogProblem("Tracklet") << "at extreme! " << fpgaphi.value(); + if (fpgaphi.atExtreme()) + edm::LogProblem("Tracklet") << "at extreme! " << fpgaphi.value(); - assert(!fpgaphi.atExtreme()); + assert(!fpgaphi.atExtreme()); - if (fpgaz.atExtreme()) - continue; + if (fpgaz.atExtreme()) + continue; - if (std::abs(fpgaz.value() * settings_.kz()) > settings_.zlength()) - continue; + if (std::abs(fpgaz.value() * settings_.kz()) > settings_.zlength()) + continue; - int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); - int iphi = iphivmRaw / (32 / settings_.nallstubs(layerdisk)); + int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); + int iphi = iphivmRaw / (32 / settings_.nallstubs(layerdisk)); - for (unsigned int i = 0; i < outputproj_[layerdisk][iphi].size(); i++) { - outputproj_[layerdisk][iphi][i]->addProj(tracklet, projPage); // FIXME write to correct page - though doesn't affect emulation - } - } else{ + for (unsigned int i = 0; i < outputproj_[layerdisk][iphi].size(); i++) { + outputproj_[layerdisk][iphi][i]->addProj( + tracklet, projPage); // FIXME write to correct page - though doesn't affect emulation + } + } else { + FPGAWord fpgar = tracklet->proj(layerdisk).fpgarzproj(); - FPGAWord fpgar = tracklet->proj(layerdisk).fpgarzproj(); + if (fpgar.value() * settings_.krprojshiftdisk() < settings_.rmindiskvm()) + continue; + if (fpgar.value() * settings_.krprojshiftdisk() > settings_.rmaxdisk()) + continue; - if (fpgar.value() * settings_.krprojshiftdisk() < settings_.rmindiskvm()) - continue; - if (fpgar.value() * settings_.krprojshiftdisk() > settings_.rmaxdisk()) - continue; + FPGAWord fpgaphi = tracklet->proj(layerdisk).fpgaphiproj(); + int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); + int iphi = iphivmRaw / (32 / settings_.nallstubs(layerdisk)); //>> settings_.nbitsallstubs(layerdisk); - FPGAWord fpgaphi = tracklet->proj(layerdisk).fpgaphiproj(); - int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); - int iphi = iphivmRaw / (32 / settings_.nallstubs(layerdisk));//>> settings_.nbitsallstubs(layerdisk); - - for (unsigned int i = 0; i < outputproj_[layerdisk][iphi].size(); i++) { - outputproj_[layerdisk][iphi][i]->addProj(tracklet, projPage); // FIXME write to correct page - } + for (unsigned int i = 0; i < outputproj_[layerdisk][iphi].size(); i++) { + outputproj_[layerdisk][iphi][i]->addProj(tracklet, projPage); // FIXME write to correct page + } + } + } + } } } - } } } - } - } return; - } diff --git a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc index 413290dd037f2..2c6d57db82d8f 100644 --- a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc +++ b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc @@ -84,7 +84,10 @@ Tracklet::Tracklet(Settings const& settings, ichisqrzfit_.set(-1, 8, false); } -void Tracklet::addProjs(Projection projs[N_LAYER + N_DISK]){ // needs to be separate from constructor to allow TPars only calculated in TrackletProcessor +void Tracklet::addProjs( + Projection + projs[N_LAYER + + N_DISK]) { // needs to be separate from constructor to allow TPars only calculated in TrackletProcessor //Handle projections to the layers for (unsigned int i = 0; i < N_LAYER - 2; i++) { if (projlayer_[i] == 0) @@ -342,7 +345,7 @@ std::string Tracklet::fullmatchdiskstr(int disk) { const FPGAWord& stubr = resid_[N_LAYER + disk - 1].stubptr()->r(); const bool isPS = resid_[N_LAYER + disk - 1].stubptr()->isPSmodule(); std::string oss = tcid.str() + "|" + tmp.str() + "|" + resid_[N_LAYER + disk - 1].fpgastubid().str() + "|" + - (isPS ? "0"+stubr.str() : ("00000000" + stubr.str())) + "|" + + (isPS ? "0" + stubr.str() : ("00000000" + stubr.str())) + "|" + resid_[N_LAYER + disk - 1].fpgaphiresid().str() + "|" + resid_[N_LAYER + disk - 1].fpgarzresid().str(); return oss; @@ -617,7 +620,7 @@ const std::string Tracklet::diskstubstr(const unsigned disk) const { oss << "1|"; // valid bit oss << tmp.str() << "|"; oss << resid_[N_LAYER + disk].fpgastubid().str() << "|"; - oss << (isPS ? ("0"+stubr.str()) : ("00000000" + stubr.str())) << "|"; + oss << (isPS ? ("0" + stubr.str()) : ("00000000" + stubr.str())) << "|"; oss << resid_[N_LAYER + disk].fpgaphiresid().str() << "|"; oss << resid_[N_LAYER + disk].fpgarzresid().str(); } @@ -629,8 +632,8 @@ std::string Tracklet::trackfitstr() const { const unsigned maxNHits = N_LAYER + N_DISK; const unsigned nBitsPerHit = 3; vector stub(maxNHits); - for (unsigned int i = 0; i=4 && iSeed<6){ //FIXME - should not have hardcoded number here + if (iSeed >= 4 && iSeed < 6) { //FIXME - should not have hardcoded number here n_Deltar_ = 23; LUT_idrinv_.resize(512); - for(unsigned int idr=1; idr<512; idr++){ - LUT_idrinv_[idr] = (1<=6) { //FIXME - should not have hardcoded number here + if (iSeed >= 6) { //FIXME - should not have hardcoded number here n_Deltar_ = 23; n_delta0_ = 14; n_deltaz_ = 9; n_a_ = 14; n_r6_ = 6; LUT_idrinv_.resize(1024); - for(unsigned int idr=1; idr<1024; idr++){ - LUT_idrinv_[idr] = (1<> n_s_; - int is = (irtilde*irinv) >> n_s_; + int is6 = (1 << n_s6_) + ((is * is) >> (2 + 2 * n_r_ + 2 * n_rinv_ - 2 * n_s_ - n_s6_)); - int is6 = (1 << n_s6_) + ((is*is) >> (2 + 2*n_r_ + 2*n_rinv_ - 2*n_s_ - n_s6_)); + int iu = (ir * irinv) >> (n_r_ + n_rinv_ + 1 - n_phi_); - int iu = (ir*irinv) >> (n_r_ + n_rinv_ + 1 - n_phi_); + iphi = (iphi0 << (n_phi_ - n_phi0_)) - ((iu * is6) >> n_s6_); - iphi = (iphi0 << (n_phi_ - n_phi0_)) - ((iu*is6) >> n_s6_); - - int iv = (it*ir) >> (n_r_ + n_t_ - n_z_); - - iz = iz0 + ((iv*is6) >> n_s6_); + int iv = (it * ir) >> (n_r_ + n_t_ - n_z_); + iz = iz0 + ((iv * is6) >> n_s6_); } -void TrackletCalculatorBase::projdisk(int iz, int irinv, int iphi0, int it,int iz0, int &ir, int &iphi, int &iderphi, int &iderr) { - int iz0_sign = (it>0)?iz0:-iz0; +void TrackletCalculatorBase::projdisk( + int iz, int irinv, int iphi0, int it, int iz0, int& ir, int& iphi, int& iderphi, int& iderr) { + int iz0_sign = (it > 0) ? iz0 : -iz0; + + assert(abs(it) < LUT_itinv_.size()); + int itinv = LUT_itinv_[abs(it)]; - assert(abs(it)> 17; - iderr = itinv >> 5; - if (it<0) { - iderphi = -iderphi; - iderr = -iderr; - } - - int iw = (((iz << (n_r_ - n_z_)) - (iz0_sign << (n_r_ - n_z_)))*itinv) >> n_tinv_; + iderphi = (-irinv * itinv) >> 17; + iderr = itinv >> 5; + if (it < 0) { + iderphi = -iderphi; + iderr = -iderr; + } - iphi = (iphi0 >> (n_phi0_ - n_phidisk_)) - ((iw*irinv) >> (1 + n_r_ + n_rinv_ - n_phidisk_)); + int iw = (((iz << (n_r_ - n_z_)) - (iz0_sign << (n_r_ - n_z_))) * itinv) >> n_tinv_; - int ifact = (1 << n_y_)*phiHG_/sqrt(6.0); + iphi = (iphi0 >> (n_phi0_ - n_phidisk_)) - ((iw * irinv) >> (1 + n_r_ + n_rinv_ - n_phidisk_)); - int iy = (ifact * irinv) >> n_y_; + int ifact = (1 << n_y_) * phiHG_ / sqrt(6.0); - int ix = (iw*iy) >> n_x_; + int iy = (ifact * irinv) >> n_y_; - int ix6 = (1 << n_xx6_) - ( (ix*ix) >> (2 + 2*n_r_ + 2*n_rinv_ - 2*n_x_ - n_xx6_)); + int ix = (iw * iy) >> n_x_; - ir = (iw*ix6) >> (n_r_ - n_rdisk_ + n_xx6_); + int ix6 = (1 << n_xx6_) - ((ix * ix) >> (2 + 2 * n_r_ + 2 * n_rinv_ - 2 * n_x_ - n_xx6_)); + ir = (iw * ix6) >> (n_r_ - n_rdisk_ + n_xx6_); } -void TrackletCalculatorBase::calcPars(unsigned int idr, int iphi1, int ir1, int iz1, int iphi2, int ir2, int iz2, int &irinv_new, int &iphi0_new, int &iz0_new, int &it_new) { - +void TrackletCalculatorBase::calcPars(unsigned int idr, + int iphi1, + int ir1, + int iz1, + int iphi2, + int ir2, + int iz2, + int& irinv_new, + int& iphi0_new, + int& iz0_new, + int& it_new) { int idz = iz2 - iz1; - assert(idr> n_delta0_; - int ideltaz = (idz*invdr) >> n_deltaz_; + int idelta0 = ((iphi2 - iphi1) * invdr) >> n_delta0_; + int ideltaz = (idz * invdr) >> n_deltaz_; + + int idelta1 = (ir1 * idelta0) >> n_delta1_; + int idelta2 = (ir2 * idelta0) >> n_delta2_; - int idelta1 = (ir1*idelta0) >> n_delta1_; - int idelta2 = (ir2*idelta0) >> n_delta2_; + int idelta12 = (idelta1 * idelta2) >> n_delta12_; - int idelta12 = (idelta1*idelta2) >> n_delta12_; + int iHG = phiHG_ * phiHG_ * (1 << n_HG_); - int iHG = phiHG_*phiHG_*(1 << n_HG_); + int ia = ((1 << n_a_) - ((idelta12 * iHG) >> (2 * n_Deltar_ + 2 * n_phi_ + n_HG_ - 2 * n_delta0_ - n_delta1_ - + n_delta2_ - n_delta12_ + 1 - n_a_))); - int ia = ((1 << n_a_) - ((idelta12*iHG) >> (2*n_Deltar_ + 2*n_phi_ + n_HG_ - 2*n_delta0_ - n_delta1_ - n_delta2_ - n_delta12_ + 1 - n_a_))); + int ifact = (1 << n_r6_) * phiHG_ * phiHG_ / 6.0; - int ifact = (1<> n_delta02_; - int idelta02 = (idelta0*idelta2) >> n_delta02_; - - int ix6 = (-(1 << n_x6_)+((ir6*idelta02) >> (n_r6_ + 2*n_Deltar_ + 2*n_phi_ - n_x6_ - n_delta2_- n_delta02_ - 2*n_delta0_))); - - int it1 = (ir1*ideltaz) >> (n_Deltar_ - n_deltaz_); + int ix6 = (-(1 << n_x6_) + ((ir6 * idelta02) >> + (n_r6_ + 2 * n_Deltar_ + 2 * n_phi_ - n_x6_ - n_delta2_ - n_delta02_ - 2 * n_delta0_))); - irinv_new = ((-idelta0*ia) >> (n_phi_ + n_a_ - n_rinv_ + n_Deltar_ - n_delta0_ - n_r_ - 1)); + int it1 = (ir1 * ideltaz) >> (n_Deltar_ - n_deltaz_); - iphi0_new = (iphi1 >> (n_phi_ - n_phi0_))+((idelta1*ix6) >> (n_Deltar_ + n_x6_ + n_phi_ - n_delta0_ - n_delta1_ - n_phi0_)); + irinv_new = ((-idelta0 * ia) >> (n_phi_ + n_a_ - n_rinv_ + n_Deltar_ - n_delta0_ - n_r_ - 1)); - it_new = ((ideltaz*ia) >> (n_Deltar_ + n_a_ + n_z_ - n_t_ - n_deltaz_ - n_r_)); + iphi0_new = (iphi1 >> (n_phi_ - n_phi0_)) + + ((idelta1 * ix6) >> (n_Deltar_ + n_x6_ + n_phi_ - n_delta0_ - n_delta1_ - n_phi0_)); - iz0_new = iz1+((it1*ix6) >> n_x6_); + it_new = ((ideltaz * ia) >> (n_Deltar_ + n_a_ + n_z_ - n_t_ - n_deltaz_ - n_r_)); + iz0_new = iz1 + ((it1 * ix6) >> n_x6_); } void TrackletCalculatorBase::addDiskProj(Tracklet* tracklet, int disk) { @@ -513,7 +518,6 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, //now binary - int ir1 = innerFPGAStub->r().value(); int iphi1 = innerFPGAStub->phi().value(); int iz1 = innerFPGAStub->z().value(); @@ -530,28 +534,29 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, iz1 <<= (settings_.nzbitsstub(0) - settings_.nzbitsstub(layerdisk1_)); iz2 <<= (settings_.nzbitsstub(0) - settings_.nzbitsstub(layerdisk2_)); - //Each of ir1 and ir2 are signed 8 bit integers. idr is signed 9 bit integer + //Each of ir1 and ir2 are signed 8 bit integers. idr is signed 9 bit integer int idr = ir2 - ir1; - if (idr < 0) idr += 512; + if (idr < 0) + idr += 512; int irinv_new, iphi0_new, iz0_new, it_new; unsigned int ir1mean = settings_.irmean(layerdisk1_); unsigned int ir2mean = settings_.irmean(layerdisk2_); - + int ir1abs = ir1 + ir1mean; int ir2abs = ir2 + ir2mean; calcPars(idr, iphi1, ir1abs, iz1, iphi2, ir2abs, iz2, irinv_new, iphi0_new, iz0_new, it_new); - bool rinvcut = abs(irinv_new) < settings_.rinvcut()*(120.0*(1<ofstream("trackletpars.txt") - << "Trackpars " << layerdisk1_ + 1 << " " << " " << rinv << " " << irinv_new - << " " << phi0 << " " << iphi0_new << " " << t << " " - << it_new << " " << " " << iz0_new << endl; + << "Trackpars " << layerdisk1_ + 1 << " " + << " " << rinv << " " << irinv_new << " " << phi0 << " " << iphi0_new << " " << t << " " << it_new << " " + << " " << iz0_new << endl; } Tracklet* tracklet = new Tracklet(settings_, @@ -633,10 +638,8 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, const L1TStub* innerStub, const Stub* outerFPGAStub, - const L1TStub* outerStub, - bool print) { - - + const L1TStub* outerStub, + bool print) { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "TrackletCalculator::execute calculate disk seeds"; } @@ -713,11 +716,11 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, iphi1 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); iphi2 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); - //Each of ir1 and ir2 are signed 8 bit integers. idr is signed 9 bit integer - unsigned int idr = ir2-ir1; + //Each of ir1 and ir2 are signed 8 bit integers. idr is signed 9 bit integer + unsigned int idr = ir2 - ir1; - unsigned int iz1mean = sign*settings_.izmean(layerdisk1_ - N_LAYER); - unsigned int iz2mean = sign*settings_.izmean(layerdisk2_ - N_LAYER); + unsigned int iz1mean = sign * settings_.izmean(layerdisk1_ - N_LAYER); + unsigned int iz2mean = sign * settings_.izmean(layerdisk2_ - N_LAYER); int iz1abs = iz1 + iz1mean; int iz2abs = iz2 + iz2mean; @@ -730,24 +733,21 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, std::cout << "=======================" << std::endl; std::cout << "iphi1, ir1, iz1abs : " << iphi1 << " " << ir1 << " " << iz1abs << std::endl; std::cout << "iphi2, ir2, iz2abs : " << iphi2 << " " << ir2 << " " << iz2abs << std::endl; - std::cout << "idr irinv iphi0 iz0 it : " << idr << " " << irinv_new << " " << iphi0_new - << " " << iz0_new << " " << it_new <ofstream("trackletparsdisk.txt") - << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << rinv << " " - << rinv << " " << phi0 << " " << phi0 << " " << phi0 << " " << t - << " " << t << " " << t << " " << z0 << " " << z0 << " " << z0 + << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << rinv << " " << rinv << " " << phi0 + << " " << phi0 << " " << phi0 << " " << t << " " << t << " " << t << " " << z0 << " " << z0 << " " << z0 << endl; } @@ -804,9 +803,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, const L1TStub* innerStub, const Stub* outerFPGAStub, const L1TStub* outerStub, - bool print) { - - + bool print) { //Deal with overlap stubs here assert(outerFPGAStub->layerdisk() < N_LAYER); @@ -876,7 +873,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, int iz1 = outerFPGAStub->z().value(); //To get global precission - int ll = outerFPGAStub->layer().value() + 1; + int ll = outerFPGAStub->layer().value() + 1; ir1 = l1t::bitShift(ir1, (8 - settings_.nrbitsstub(ll - 1))); iphi1 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); iphi2 <<= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); @@ -885,7 +882,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, int ir1abs = ir1 + ir1mean; - unsigned int idr = ir2-ir1abs; + unsigned int idr = ir2 - ir1abs; if (idr >= LUT_idrinv_.size()) { return false; @@ -893,7 +890,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, int iz2mean = settings_.izmean(layerdisk2_ - N_LAYER); - if (iz1<0) { + if (iz1 < 0) { iz2mean = -iz2mean; } @@ -912,8 +909,8 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, std::cout << "pars: " << irinv_new << " " << iphi0_new << " " << iz0_new << " " << it_new << std::endl; } - bool rinvcut = abs(irinv_new) < settings_.rinvcut()*(120.0*(1<ofstream("trackletparsoverlap.txt") - << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << irinv_new << " " - << phi0 << " " << iphi0_new << " " << t << " " << it_new << " " - << z0 << " " << iz0_new << endl; + << "Trackpars " << layerdisk1_ - 5 << " " << rinv << " " << irinv_new << " " << phi0 << " " << iphi0_new + << " " << t << " " << it_new << " " << z0 << " " << iz0_new << endl; } Tracklet* tracklet = new Tracklet(settings_, diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc index 1c72c8ef46672..019d863cc32a3 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc @@ -743,7 +743,7 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, iz0, it, false); - tracklet->addProjs(projs); // add projections to tracklet + tracklet->addProjs(projs); // add projections to tracklet if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() @@ -1154,7 +1154,7 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, iz0, it, true); - tracklet->addProjs(projs); // add projections to tracklet + tracklet->addProjs(projs); // add projections to tracklet if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() @@ -1559,7 +1559,7 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, iz0, it, false); - tracklet->addProjs(projs); // add projections to tracklet + tracklet->addProjs(projs); // add projections to tracklet if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced " << getName() diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc index 70a3dc3f7d2e1..8a438f78c3d3a 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc @@ -355,13 +355,12 @@ std::pair TrackletConfigBuilder::seedPhiRange(double rproj, unsi } } } - return std::pair(phimin-0.07, phimax+0.07); + return std::pair(phimin - 0.07, phimax + 0.07); } //--- Finds the projections needed for each seeding combination void TrackletConfigBuilder::buildProjections() { - set emptyProjCombined = { "TPROJ_L1L2J_L6PHIB", "TPROJ_L1L2C_L6PHIC", "TPROJ_L1L2G_D1PHIA", "TPROJ_L1L2J_D1PHIB", "TPROJ_L2L3D_D1PHIB", "TPROJ_L3L4D_D1PHIB", "TPROJ_L1L2C_D1PHIC", "TPROJ_L2L3A_D1PHIC", "TPROJ_L3L4A_D1PHIC", "TPROJ_L1L2F_D1PHID", @@ -451,9 +450,9 @@ void TrackletConfigBuilder::buildProjections() { if (phiRange.first < allStubs_[ilayer][iReg].second && phiRange.second > allStubs_[ilayer][iReg].first) { std::pair tmp(iseed, iTC); //seedindex and TC string projName = TPROJName(iseed, iTC, ilayer, iReg); - if (emptyProjCombined.find(projName) == emptyProjCombined.end()) { - projections_[ilayer][iReg].push_back(tmp); - } + if (emptyProjCombined.find(projName) == emptyProjCombined.end()) { + projections_[ilayer][iReg].push_back(tmp); + } } } } @@ -509,58 +508,58 @@ std::string TrackletConfigBuilder::iTCStr(unsigned int iTC) const { } std::string TrackletConfigBuilder::iMergedTCStr(unsigned int iSeed, unsigned int iTC) { - - assert(iSeed<8); - + assert(iSeed < 8); + if (iSeed == 0) { static std::string name[6] = {"ABC", "DE", "F", "G", "HI", "JKL"}; - assert(iTC<6); + assert(iTC < 6); return name[iTC]; } if (iSeed == 1) { static std::string name[1] = {"ABCD"}; - assert(iTC<1); + assert(iTC < 1); return name[iTC]; } if (iSeed == 2) { static std::string name[2] = {"AB", "CD"}; - assert(iTC<2); + assert(iTC < 2); return name[iTC]; } if (iSeed == 3) { static std::string name[1] = {"ABCD"}; - assert(iTC<1); + assert(iTC < 1); return name[iTC]; } if (iSeed == 4) { static std::string name[1] = {"ABCD"}; - assert(iTC<1); + assert(iTC < 1); return name[iTC]; } if (iSeed == 5) { static std::string name[1] = {"ABCD"}; - assert(iTC<1); + assert(iTC < 1); return name[iTC]; } if (iSeed == 6) { static std::string name[2] = {"ABCD", "EFGH"}; - assert(iTC<2); + assert(iTC < 2); return name[iTC]; } if (iSeed == 7) { static std::string name[1] = {"ABCD"}; - assert(iTC<1); + assert(iTC < 1); return name[iTC]; } - return "Error";; + return "Error"; + ; } std::string TrackletConfigBuilder::iRegStr(unsigned int iReg, unsigned int iSeed) const { @@ -587,7 +586,7 @@ std::string TrackletConfigBuilder::TCName(unsigned int iSeed, unsigned int iTC) } std::string TrackletConfigBuilder::PCName(unsigned int iSeed, unsigned int iMergedTC) const { - return "PC_" + iSeedStr(iSeed) + iMergedTCStr(iSeed,iMergedTC); + return "PC_" + iSeedStr(iSeed) + iMergedTCStr(iSeed, iMergedTC); } std::string TrackletConfigBuilder::LayerName(unsigned int ilayer) { @@ -605,33 +604,34 @@ std::string TrackletConfigBuilder::MPROJName(unsigned int iSeed, unsigned int iTC, unsigned int ilayer, unsigned int ireg) const { - return "MPROJ_" + iSeedStr(iSeed) + iMergedTCStr(iSeed,iTC) + "_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); + return "MPROJ_" + iSeedStr(iSeed) + iMergedTCStr(iSeed, iTC) + "_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); } std::string TrackletConfigBuilder::MPName(unsigned int ilayer, unsigned int ireg) const { return "MP_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); } - -void TrackletConfigBuilder::writeMergedProjectionMemories(std::ostream& os, std::ostream& memories, std::ostream& process) { +void TrackletConfigBuilder::writeMergedProjectionMemories(std::ostream& os, + std::ostream& memories, + std::ostream& process) { // Writed the merged projection memories as produced by the ProjectionCalculator mdoels // MPROJ_L1L2ABC_L3PHIA) indicating that TP_L1L2A, TP_L1L2B, and TP_L1L2C are merged together // unsigned int nMergedTC[8] = {6, 1, 2, 1, 1, 1, 2, 1}; - for (unsigned int iSeed = 0; iSeed < 8; iSeed++){ + for (unsigned int iSeed = 0; iSeed < 8; iSeed++) { unsigned int iTB = 0; - if ( iSeed==2 || iSeed==4 || iSeed==5 || iSeed==6 ) { + if (iSeed == 2 || iSeed == 4 || iSeed == 5 || iSeed == 6) { iTB = 1; } for (unsigned int iPC = 0; iPC < nMergedTC[iSeed]; iPC++) { process << "ProjectionCalculator: " << PCName(iSeed, iPC) << std::endl; - memories << "TrackletParameters: MPAR_" << iSeedStr(iSeed) << iMergedTCStr(iSeed,iPC) << " [73]" << std::endl; - os << "MPAR_"< " << PCName(iSeed, iPC) << ".tparout" - << " output=> TB_" < " << PCName(iSeed, iPC) << ".tparout" + << " output=> TB_" << iTBStr(iTB) << ".tparin" << std::endl; } - } + } std::set MPROJNames; @@ -640,49 +640,49 @@ void TrackletConfigBuilder::writeMergedProjectionMemories(std::ostream& os, std: for (unsigned int imem = 0; imem < projections_[ilayer][ireg].size(); imem++) { unsigned int iSeed = projections_[ilayer][ireg][imem].first; unsigned int iTC = projections_[ilayer][ireg][imem].second; - for (unsigned int iMergedTC = 0 ; iMergedTC " << PCName(iSeed, iMergedTC) << ".projout" - //<< LayerName(ilayer) << "PHI" << iTCStr(ireg) - << " output=> " << MPName(ilayer, ireg) << "_E.projin" - << std::endl; - } else { - memories << "TrackletProjections: " + MPROJName(iSeed, iMergedTC, ilayer, ireg) + " [54]" << std::endl; - os << MPROJName(iSeed, iMergedTC, ilayer, ireg) << " input=> " << PCName(iSeed, iMergedTC) << ".projout" - //<< LayerName(ilayer) << "PHI" << iTCStr(ireg) - << " output=> " << MPName(ilayer, ireg) << ".projin" - << std::endl; - } - } else { - memories << "TrackletProjections: " + MPROJName(iSeed, iMergedTC, ilayer, ireg) + " [54]" << std::endl; - os << MPROJName(iSeed, iMergedTC, ilayer, ireg) << " input=> " << PCName(iSeed, iMergedTC) << ".projout" - //<< LayerName(ilayer) << "PHI" << iTCStr(ireg) - << " output=> " << MPName(ilayer, ireg) << ".projin" - << std::endl; - } - } + for (unsigned int iMergedTC = 0; iMergedTC < nMergedTC[iSeed]; iMergedTC++) { + std::string mergetcstr = iMergedTCStr(iSeed, iMergedTC); + + if (mergetcstr.find(iTCStr(iTC)) == std::string::npos) { + continue; + } + + std::string mtprojname = MPROJName(iSeed, iMergedTC, ilayer, ireg); + + //std::cout << "mtprojname: " << mtprojname << " " << iSeed << std::endl; + + if (MPROJNames.find(mtprojname) != MPROJNames.end()) { + //std::cout << "Already have: " << mtprojname << std::endl; + continue; + } + + //std::cout << "Adding: " << mtprojname << std::endl; + MPROJNames.insert(mtprojname); + if (duplicateMPs_ && + (settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || + settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && + (ireg == 1 || ireg == 2)) { // regions with worst truncation + if (iSeed == 0) { + memories << "TrackletProjections: " + MPROJName(iSeed, iMergedTC, ilayer, ireg) + "_E [54]" << std::endl; + os << MPROJName(iSeed, iMergedTC, ilayer, ireg) << "_E input=> " << PCName(iSeed, iMergedTC) + << ".projout" + //<< LayerName(ilayer) << "PHI" << iTCStr(ireg) + << " output=> " << MPName(ilayer, ireg) << "_E.projin" << std::endl; + } else { + memories << "TrackletProjections: " + MPROJName(iSeed, iMergedTC, ilayer, ireg) + " [54]" << std::endl; + os << MPROJName(iSeed, iMergedTC, ilayer, ireg) << " input=> " << PCName(iSeed, iMergedTC) + << ".projout" + //<< LayerName(ilayer) << "PHI" << iTCStr(ireg) + << " output=> " << MPName(ilayer, ireg) << ".projin" << std::endl; + } + } else { + memories << "TrackletProjections: " + MPROJName(iSeed, iMergedTC, ilayer, ireg) + " [54]" << std::endl; + os << MPROJName(iSeed, iMergedTC, ilayer, ireg) << " input=> " << PCName(iSeed, iMergedTC) + << ".projout" + //<< LayerName(ilayer) << "PHI" << iTCStr(ireg) + << " output=> " << MPName(ilayer, ireg) << ".projin" << std::endl; + } + } } } } @@ -789,24 +789,25 @@ void TrackletConfigBuilder::writeFMMemories(std::ostream& os, std::ostream& memo for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { modules << "MatchProcessor: MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; for (unsigned int iTB = 0; iTB < N_TB; iTB++) { - memories << "FullMatch: FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) - << " [36]" << std::endl; - os << "FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> MP_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".matchout" << iTB << " output=> TB_" << iTBStr(iTB) - << ".fullmatch" << ilayer << "in" << iReg + 1 << std::endl; + memories << "FullMatch: FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " [36]" + << std::endl; + os << "FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << " input=> MP_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".matchout" << iTB << " output=> TB_" << iTBStr(iTB) + << ".fullmatch" << ilayer << "in" << iReg + 1 << std::endl; } //Write duplicate MPs - if (duplicateMPs_ && (settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || - settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && - (iReg == 1 || iReg == 2)) { // regions with worst truncation - modules << "MatchProcessor: MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) + "_E" << std::endl; - for (unsigned int iTB = 0; iTB < N_TB; iTB++) { - memories << "FullMatch: FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) - << "_E [36]" << std::endl; - os << "FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E input=> MP_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E.matchout" << iTB << " output=> TB_" << iTBStr(iTB) - << ".fullmatch" << ilayer << "in" << iReg + 1 << std::endl; - } + if (duplicateMPs_ && + (settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || + settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && + (iReg == 1 || iReg == 2)) { // regions with worst truncation + modules << "MatchProcessor: MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) + "_E" << std::endl; + for (unsigned int iTB = 0; iTB < N_TB; iTB++) { + memories << "FullMatch: FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E [36]" + << std::endl; + os << "FM_" << iTBStr(iTB) << "_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E input=> MP_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E.matchout" << iTB << " output=> TB_" << iTBStr(iTB) + << ".fullmatch" << ilayer << "in" << iReg + 1 << std::endl; + } } } } @@ -823,25 +824,27 @@ void TrackletConfigBuilder::writeASMemories(std::ostream& os, std::ostream& memo for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " [42]" << std::endl; + << " [42]" << std::endl; memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2" - << " [42]" << std::endl; + << " [42]" << std::endl; modules << "VMRouterCM: VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; modules << "VMStubMERouter: VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << std::endl; os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n1" - << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> VMSMER_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; + << " input=> VMR_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> VMSMER_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2" - << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; + << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubin" << std::endl; //Write duplicate MPs - if (duplicateMPs_ && (settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || - settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && (iReg == 1 || iReg == 2)) { - memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3" - << " [42]" << std::endl; - os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3" - << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E.allstubin" << std::endl; + if (duplicateMPs_ && + (settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || + settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && + (iReg == 1 || iReg == 2)) { + memories << "AllStubs: AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3" + << " [42]" << std::endl; + os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3" + << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".allstubout output=> MP_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E.allstubin" << std::endl; } } } @@ -850,52 +853,51 @@ void TrackletConfigBuilder::writeASMemories(std::ostream& os, std::ostream& memo for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { for (int iReg = 0; iReg < (int)NRegions_[ilayer]; iReg++) { for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { - unsigned int l1 = seedLayers(iSeed).first; - unsigned int l2 = seedLayers(iSeed).second; - - if (ilayer != l1 && ilayer != l2) - continue; + unsigned int l1 = seedLayers(iSeed).first; + unsigned int l2 = seedLayers(iSeed).second; - bool inner = ilayer == l1; + if (ilayer != l1 && ilayer != l2) + continue; - for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { - int nTCReg = TC_[iSeed].size() / NRegions_[l2]; + bool inner = ilayer == l1; - int iTCReg = iTC / nTCReg; + for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { + int nTCReg = TC_[iSeed].size() / NRegions_[l2]; - int jTCReg = iTC % nTCReg; + int iTCReg = iTC / nTCReg; - if (ilayer == l2) { - if (iTCReg != iReg) - continue; - } - - string ext = ""; - - if (ilayer == l1) { - int ratio = NRegions_[l1] / NRegions_[l2]; - int min = iTCReg * ratio - 1 + jTCReg; - int max = (iTCReg + 1) * ratio - (nTCReg - jTCReg - 1); - if ((int)iReg < min || (int)iReg > max) - continue; + int jTCReg = iTC % nTCReg; + if (ilayer == l2) { + if (iTCReg != iReg) + continue; + } - if (max - min >= 2) { - ext = "M"; - if (iReg == min) { - if (iReg % 2 == 0) - continue; - ext = "R"; - } - if (iReg == max) { - if (iReg % 2 == 1) - continue; - ext = "L"; - } + string ext = ""; + + if (ilayer == l1) { + int ratio = NRegions_[l1] / NRegions_[l2]; + int min = iTCReg * ratio - 1 + jTCReg; + int max = (iTCReg + 1) * ratio - (nTCReg - jTCReg - 1); + if ((int)iReg < min || (int)iReg > max) + continue; + + if (max - min >= 2) { + ext = "M"; + if (iReg == min) { + if (iReg % 2 == 0) + continue; + ext = "R"; } + if (iReg == max) { + if (iReg % 2 == 1) + continue; + ext = "L"; + } + } - //old code - /* + //old code + /* if (max - min >= 2) { ext = "M"; if (iReg == min) @@ -905,73 +907,73 @@ void TrackletConfigBuilder::writeASMemories(std::ostream& os, std::ostream& memo } */ - if (max - min == 1) { - if (nTCReg == 2) { - assert(0); - if (jTCReg == 0) { - if (iReg == min) - ext = "R"; - if (iReg == max) - ext = "B"; - } - if (jTCReg == 1) { - if (iReg == min) - ext = "A"; - if (iReg == max) - ext = "L"; - } - } - if (nTCReg == 3) { - if (jTCReg == 0) { - if (iReg == min) - ext = "A"; - if (iReg == max) - ext = "F"; - } - if (jTCReg == 1) { - if (iReg == min) - ext = "E"; - if (iReg == max) - ext = "D"; - } - if (jTCReg == 2) { - if (iReg == min) - ext = "C"; - if (iReg == max) - ext = "B"; - } - } - } - assert(!ext.empty()); - } - - if (ext.empty()) { - ext = "_" + LayerName(l1) + iTCStr(iTC); - } - - if (iSeed < 4) { //Barrel seeding - ext = "_B" + ext; - } else if (iSeed > 5) { - ext = "_O" + ext; - } else { - ext = "_D" + ext; - } - - if (inner) { - memories << "AllInnerStubs: "; - } else { - memories << "AllStubs: "; - } - memories << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " [42]" << std::endl; - os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " input=> VMR_" << LayerName(ilayer) - << "PHI" << iTCStr(iReg) << ".all" << (inner ? "inner" : "") << "stubout output=> TP_" << iSeedStr(iSeed) - << iTCStr(iTC); - if (inner) { - os << ".innerallstubin" << std::endl; - } else { - os << ".outerallstubin" << std::endl; - } - } + if (max - min == 1) { + if (nTCReg == 2) { + assert(0); + if (jTCReg == 0) { + if (iReg == min) + ext = "R"; + if (iReg == max) + ext = "B"; + } + if (jTCReg == 1) { + if (iReg == min) + ext = "A"; + if (iReg == max) + ext = "L"; + } + } + if (nTCReg == 3) { + if (jTCReg == 0) { + if (iReg == min) + ext = "A"; + if (iReg == max) + ext = "F"; + } + if (jTCReg == 1) { + if (iReg == min) + ext = "E"; + if (iReg == max) + ext = "D"; + } + if (jTCReg == 2) { + if (iReg == min) + ext = "C"; + if (iReg == max) + ext = "B"; + } + } + } + assert(!ext.empty()); + } + + if (ext.empty()) { + ext = "_" + LayerName(l1) + iTCStr(iTC); + } + + if (iSeed < 4) { //Barrel seeding + ext = "_B" + ext; + } else if (iSeed > 5) { + ext = "_O" + ext; + } else { + ext = "_D" + ext; + } + + if (inner) { + memories << "AllInnerStubs: "; + } else { + memories << "AllStubs: "; + } + memories << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " [42]" << std::endl; + os << "AS_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ext << " input=> VMR_" << LayerName(ilayer) + << "PHI" << iTCStr(iReg) << ".all" << (inner ? "inner" : "") << "stubout output=> TP_" << iSeedStr(iSeed) + << iTCStr(iTC); + if (inner) { + os << ".innerallstubin" << std::endl; + } else { + os << ".outerallstubin" << std::endl; + } + } } } } @@ -989,17 +991,18 @@ void TrackletConfigBuilder::writeVMSMemories(std::ostream& os, std::ostream& mem for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2 [18]" << std::endl; os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n2" - << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout" - << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubin" << std::endl; + << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout" + << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubin" << std::endl; //Write duplicate MPs - if (duplicateMPs_ && (settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || - settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && - (iReg == 1 || iReg == 2)) { - memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3 [18]" << std::endl; - os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3" - << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout" - << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E.vmstubin" << std::endl; - } + if (duplicateMPs_ && + (settings_.layersDisksDuplicatedEqualProjBalance()[ilayer] || + settings_.layersDisksDuplicatedWeightedProjBalance()[ilayer]) && + (iReg == 1 || iReg == 2)) { + memories << "VMStubsME: VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3 [18]" << std::endl; + os << "VMSME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "n3" + << " input=> VMSMER_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout" + << " output=> MP_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << "_E.vmstubin" << std::endl; + } } } @@ -1008,7 +1011,7 @@ void TrackletConfigBuilder::writeVMSMemories(std::ostream& os, std::ostream& mem //FIXME - code could be cleaner unsigned int l1 = seedLayers(iSeed).first; unsigned int l2 = seedLayers(iSeed).second; - + unsigned int ilayer = seedLayers(iSeed).second; //for(unsigned int iReg=0;iReg VMR_" - << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout_seed_" << iSeed << " output=> TP_" - << LayerName(l1) << LayerName(l2) << iTCStr(iReg * nTCReg + iTC) << ".outervmstubin" << std::endl; + nmem++; + memories << "VMStubsTE: VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << "n" << nmem << " [18]" + << std::endl; + os << "VMSTE_" << LayerName(ilayer) << "PHI" << iRegStr(iReg, iSeed) << "n" << nmem << " input=> VMR_" + << LayerName(ilayer) << "PHI" << iTCStr(iReg) << ".vmstubout_seed_" << iSeed << " output=> TP_" + << LayerName(l1) << LayerName(l2) << iTCStr(iReg * nTCReg + iTC) << ".outervmstubin" << std::endl; } } } @@ -1044,12 +1047,12 @@ void TrackletConfigBuilder::writeTPARMemories(std::ostream& os, std::ostream& me for (unsigned int iTP = 0; iTP < TC_[iSeed].size(); iTP++) { memories << "TrackletParameters: TPAR_" << iSeedStr(iSeed) << iTCStr(iTP) << " [56]" << std::endl; modules << "TrackletProcessor: TP_" << iSeedStr(iSeed) << iTCStr(iTP) << std::endl; - for (unsigned int iMergedTC = 0 ; iMergedTC TP_" << iSeedStr(iSeed) << iTCStr(iTP) - << ".trackpar output=> " << PCName(iSeed, iMergedTC) << ".tparin" << std::endl; - } + for (unsigned int iMergedTC = 0; iMergedTC < nMergedTC[iSeed]; iMergedTC++) { + std::string mergetcstr = iMergedTCStr(iSeed, iMergedTC); + if (mergetcstr.find(iTCStr(iTP)) != std::string::npos) { + os << "TPAR_" << iSeedStr(iSeed) << iTCStr(iTP) << " input=> TP_" << iSeedStr(iSeed) << iTCStr(iTP) + << ".trackpar output=> " << PCName(iSeed, iMergedTC) << ".tparin" << std::endl; + } } } } @@ -1066,12 +1069,15 @@ void TrackletConfigBuilder::writeTFMemories(std::ostream& os, std::ostream& memo void TrackletConfigBuilder::writeCTMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { modules << "PurgeDuplicate: PD" << std::endl; - memories << "CleanTrack: CT_AAAA" << " [126]" << std::endl; - os << "CT_AAAA" << " input=> PD.trackout output=>" << std::endl; - - memories << "CleanTrack: CT_BBBB" << " [126]" << std::endl; - os << "CT_BBBB" << " input=> PD.trackout output=>" << std::endl; + memories << "CleanTrack: CT_AAAA" + << " [126]" << std::endl; + os << "CT_AAAA" + << " input=> PD.trackout output=>" << std::endl; + memories << "CleanTrack: CT_BBBB" + << " [126]" << std::endl; + os << "CT_BBBB" + << " input=> PD.trackout output=>" << std::endl; } void TrackletConfigBuilder::writeILMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc index 2c9b7cf8c493e..58c055a3b552a 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc @@ -276,7 +276,6 @@ void TrackletEventProcessor::event(SLHCEvent& ev, } } - // tracklet processor displaced TPDTimer_.start(); sector_->executeTPD(); @@ -347,17 +346,17 @@ void TrackletEventProcessor::printSummary() { << "VMRouter " << setw(10) << VMRouterTimer_.ntimes() << setw(20) << setprecision(3) << VMRouterTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << VMRouterTimer_.tottime() << "\n" - << "TrackletProcessor " << setw(10) << TPTimer_.ntimes() << setw(20) - << setprecision(3) << TPTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << TPTimer_.tottime() << "\n" - << "MatchProcessor " << setw(10) << MPTimer_.ntimes() << setw(20) - << setprecision(3) << MPTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << MPTimer_.tottime(); - if (settings_->extended()) { - edm::LogVerbatim("Tracklet") << "TrackletProcessorDisplaced" << setw(10) << TPDTimer_.ntimes() << setw(20) - << setprecision(3) << TPDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) - << TPDTimer_.tottime(); - } + << "TrackletProcessor " << setw(10) << TPTimer_.ntimes() << setw(20) + << setprecision(3) << TPTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << TPTimer_.tottime() << "\n" + << "MatchProcessor " << setw(10) << MPTimer_.ntimes() << setw(20) + << setprecision(3) << MPTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << MPTimer_.tottime(); + if (settings_->extended()) { + edm::LogVerbatim("Tracklet") << "TrackletProcessorDisplaced" << setw(10) << TPDTimer_.ntimes() << setw(20) + << setprecision(3) << TPDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << TPDTimer_.tottime(); + } edm::LogVerbatim("Tracklet") << "FitTrack " << setw(10) << FTTimer_.ntimes() << setw(20) << setprecision(3) << FTTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << FTTimer_.tottime() << "\n" diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc index e12d9cc7988d8..65349e971d0a9 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc @@ -8,20 +8,18 @@ using namespace std; using namespace trklet; -TrackletParametersMemory::TrackletParametersMemory(string name, Settings const& settings) - : MemoryBase(name, settings) { - npage_ = name.size()-9; +TrackletParametersMemory::TrackletParametersMemory(string name, Settings const& settings) : MemoryBase(name, settings) { + npage_ = name.size() - 9; tracklets_.resize(npage_); } void TrackletParametersMemory::clean() { - //This is where we delete the tracklets that were created. As tracklet as stored in both the TPAR and MPAR memories //we will onlu delete once in the TPAR memory if (name_[0] == 'T') { - for (unsigned int page = 0 ; page < npage_ ; page++ ){ + for (unsigned int page = 0; page < npage_; page++) { for (auto& tracklet : tracklets_[page]) { - delete tracklet; + delete tracklet; } } } @@ -43,7 +41,6 @@ void TrackletParametersMemory::writeTPAR(bool first, unsigned int iSector) { out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; - for (unsigned int page = 0; page < tracklets_.size(); page++) { for (unsigned int j = 0; j < tracklets_[page].size(); j++) { string tpar = tracklets_[page][j]->trackletparstr(); diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc index db8605e22811e..9001724176a48 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc @@ -106,7 +106,7 @@ void TrackletProcessor::addOutput(MemoryBase* memory, string output) { } //if (output.substr(0,4) == "proj") { - //Hack to keep proj output in config - but ignore in application + //Hack to keep proj output in config - but ignore in application // return; //} diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc index 00e41006b72be..26e4552b23d29 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc @@ -13,9 +13,9 @@ TrackletProjectionsMemory::TrackletProjectionsMemory(string name, Settings const assert(pos != string::npos); initLayerDisk(pos + 1, layer_, disk_); hasProj_ = false; - npage_ = name.size()-17; - if (name.substr(name.size()-2,2)=="_E") { - npage_ = name.size()-19; + npage_ = name.size() - 17; + if (name.substr(name.size() - 2, 2) == "_E") { + npage_ = name.size() - 19; } tracklets_.resize(npage_); } @@ -37,14 +37,14 @@ void TrackletProjectionsMemory::addProj(Tracklet* tracklet, unsigned int page) { hasProj_ = true; - if (tracklets_[page].size()<(1<<(N_BITSMEMADDRESS-1))-1) { + if (tracklets_[page].size() < (1 << (N_BITSMEMADDRESS - 1)) - 1) { tracklets_[page].push_back(tracklet); } } void TrackletProjectionsMemory::clean() { - for (unsigned int i = 0; i < tracklets_.size() ; i++){ - tracklets_[i].clear(); + for (unsigned int i = 0; i < tracklets_.size(); i++) { + tracklets_[i].clear(); } } @@ -52,10 +52,10 @@ void TrackletProjectionsMemory::writeTPROJ(bool first, unsigned int iSector) { iSector_ = iSector; const string dirTP = settings_.memPath() + "TrackletProjections/"; - //Hack to suppress writing empty TPROJ memories - only want to write MPROJ memories - if (getName()[0] == 'T') return; - + if (getName()[0] == 'T') + return; + std::ostringstream oss; oss << dirTP << "TrackletProjections_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; @@ -68,21 +68,21 @@ void TrackletProjectionsMemory::writeTPROJ(bool first, unsigned int iSector) { for (unsigned int j = 0; j < tracklets_.size(); j++) { // This is a hack here to write out the TPAR files for backward compatibility std::ofstream out; - std::string moduleName = getName().substr(0,10);; - moduleName[0]='T'; + std::string moduleName = getName().substr(0, 10); + ; + moduleName[0] = 'T'; std::ostringstream oss2; char postfix = getName()[10]; - postfix+=j; - oss2 << dirTP << "TrackletProjections_" << moduleName << postfix << "_" << getName().substr(getName().size()-6,6) - << "_" < 0 && tracklets_[j][i]->validProj(layer_ - 1)) ? tracklets_[j][i]->trackletprojstrlayer(layer_) - : tracklets_[j][i]->trackletprojstrdisk(disk_); + string proj = (layer_ > 0 && tracklets_[j][i]->validProj(layer_ - 1)) + ? tracklets_[j][i]->trackletprojstrlayer(layer_) + : tracklets_[j][i]->trackletprojstrdisk(disk_); out_ << hexstr(j) << " " << hexstr(i) << " " << proj << " " << trklet::hexFormat(proj) << endl; out << hexstr(i) << " " << proj << " " << trklet::hexFormat(proj) << endl; } diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc index fb3ce38af7b30..23da910c90ad7 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc @@ -325,7 +325,7 @@ void VMRouterCM::execute(unsigned int) { int melutOld = meTableOld_.lookup((indexzOld << nbitsrfinebintable_) + indexrOld); assert(melutOld >= 0); - + //Fill the TE VM memories if (layerdisk_ >= N_LAYER && (!stub->isPSmodule())) continue; diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubMERouter.cc b/L1Trigger/TrackFindingTracklet/src/VMStubMERouter.cc index 5d7e2358a3766..f604eecd73b76 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubMERouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubMERouter.cc @@ -42,13 +42,13 @@ void VMStubMERouter::addOutput(MemoryBase* memory, string output) { VMStubsMEMemory* tmp = dynamic_cast(memory); assert(tmp != nullptr); tmp->resize(16 * settings_.nvmme(layerdisk_)); - assert(vmstubsMEPHI_.size()<=2); + assert(vmstubsMEPHI_.size() <= 2); if (vmstubsMEPHI_[0] == nullptr) { vmstubsMEPHI_[0] = tmp; } else { vmstubsMEPHI_.push_back(tmp); } - + return; } @@ -144,11 +144,10 @@ void VMStubMERouter::execute(unsigned int) { allStubIndex); if (vmstubsMEPHI_[0] != nullptr) { - for (unsigned int i=0; iaddStub(vmstub, ivm * nvmmebins_ + vmbin); - } + for (unsigned int i = 0; i < vmstubsMEPHI_.size(); i++) { + vmstubsMEPHI_[i]->addStub(vmstub, ivm * nvmmebins_ + vmbin); + } } } } } - diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc index e10d85d6f15d5..3123ba65d78fc 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc @@ -31,7 +31,7 @@ void VMStubsMEMemory::writeStubs(bool first, unsigned int iSector) { for (unsigned int i = 0; i < binnedstubs_.size(); i++) { int nbitsrz = (layerdisk_ < N_LAYER) ? 3 : 4; - unsigned int newi = 8*(i&((1<>nbitsrz); + unsigned int newi = 8 * (i & ((1 << nbitsrz) - 1)) + (i >> nbitsrz); for (unsigned int j = 0; j < binnedstubs_[i].size(); j++) { string stub = binnedstubs_[i][j].stubindex().str(); stub += "|" + binnedstubs_[i][j].bend().str(); diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc index c7aa34841be4d..52c487926fe63 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc @@ -195,7 +195,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub) { bin = 0; } else { bin = vmstub.stub()->rvalue(); // 0 to 9 - bin = bin >> 2; // 0 to 2 + bin = bin >> 2; // 0 to 2 bin += 1; } } @@ -232,7 +232,7 @@ void VMStubsTEMemory::writeStubs(bool first, unsigned int iSector) { } } else { // outer VM for TE purpose for (unsigned int i = 0; i < stubsbinnedvm_.size(); i++) { - unsigned int newi = 8*(i&7)+(i>>3); + unsigned int newi = 8 * (i & 7) + (i >> 3); for (unsigned int j = 0; j < stubsbinnedvm_[i].size(); j++) { string stub = stubsbinnedvm_[i][j].str(); out_ << hexstr(newi) << " " << hexstr(j) << " " << stub << " " << trklet::hexFormat(stub) << endl; From 0cce4a06a35fadd9e964a0a128079b4d924c0b45 Mon Sep 17 00:00:00 2001 From: Anders Date: Fri, 3 Jan 2025 10:10:52 +0100 Subject: [PATCH 05/13] Some more cleanup --- .../TrackFindingTracklet/interface/Settings.h | 32 +++---------------- .../l1tTTTracksFromTrackletEmulation_cfi.py | 2 +- .../TrackFindingTracklet/src/VMRouterCM.cc | 2 +- .../test/L1TrackNtupleMaker_cfg.py | 2 +- 4 files changed, 8 insertions(+), 30 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index dbca5afe67a20..8241bfa45b158 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -542,12 +542,6 @@ namespace trklet { std::array nbitsallstubs_{{3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}}; std::array nbitsvmme_{{2, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2}}; - std::array, 3> nbitsvmte_{ - //FIXME unused? - {{{2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 3, 2}}, // (3 = #stubs/triplet, only row 1+2 used for tracklet) - {{3, 2, 3, 3, 2, 2, 2, 2, 3, 3, 2, 2}}, - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1}}}}; - std::array, 3> nbitsvmtecm_{ {{{2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 3, 2}}, // (3 = #stubs/triplet, only row 1+2 used for tracklet) {{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2}}, @@ -676,13 +670,6 @@ namespace trklet { {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3}}}}; //outermost (triplets only) //These are the number of bits used for the VM regions in the TE by seedindex - //FIXME not independed nbitsvmte - std::array, 3> nphireg_{ - //FIXME unused? - {{{5, 4, 4, 4, 4, 4, 4, 3, 4, 4, 5, 4}}, //inner - {{5, 4, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4}}, //outer - {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4}}}}; //outermost (triplets only) - std::array, 3> nphiregcm_{ {{{5, 4, 4, 4, 4, 4, 4, 3, 4, 4, 5, 4}}, //inner {{5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4}}, //outer @@ -878,19 +865,10 @@ namespace trklet { //IR should be set to 108 to match the FW for the summer chain, but ultimately should be at 156 std::unordered_map maxstep_{ - {"IR", 108}, //IR will run at a higher clock speed to handle + {"IR", 156}, //IR will run at a higher clock speed to handle //input links running at 25 Gbits/s //Set to 108 to match firmware project 240 MHz clock - - {"VMR", 107}, - {"TE", 107}, - {"TC", 108}, - {"PR", 108}, - {"ME", 108}, - //NOTE: The MC is set to 108, but `mergedepth` - //removes 3 iterations to emulate the delay - //due to the HLS priority encoder - {"MC", 108}, + {"VMR", 108}, {"TB", 108}, {"MP", 108}, {"TP", 108}, @@ -948,9 +926,9 @@ namespace trklet { bool warnNoDer_{false}; //If true will print out warnings about missing track fit derivatives //--- These used to create files needed by HLS code. - bool writeMem_{true}; //If true will print out content of memories (between algo steps) to files - bool writeTable_{true}; //If true will print out content of LUTs to files - bool writeConfig_{true}; //If true will print out the autogenerated configuration as files + bool writeMem_{false}; //If true will print out content of memories (between algo steps) to files + bool writeTable_{false}; //If true will print out content of LUTs to files + bool writeConfig_{false}; //If true will print out the autogenerated configuration as files std::string memPath_{"../data/MemPrints/"}; //path for writing memories std::string tablePath_{"../data/LUTs/"}; //path for writing LUTs diff --git a/L1Trigger/TrackFindingTracklet/python/l1tTTTracksFromTrackletEmulation_cfi.py b/L1Trigger/TrackFindingTracklet/python/l1tTTTracksFromTrackletEmulation_cfi.py index 401551a0fa885..4066a576a5250 100644 --- a/L1Trigger/TrackFindingTracklet/python/l1tTTTracksFromTrackletEmulation_cfi.py +++ b/L1Trigger/TrackFindingTracklet/python/l1tTTTracksFromTrackletEmulation_cfi.py @@ -28,7 +28,7 @@ Fakefit = cms.bool(False), # True causes Tracklet reco to output TTTracks before DR & KF StoreTrackBuilderOutput = cms.bool(False), # if True EDProducts for TrackBuilder tracks and stubs will be filled RemovalType = cms.string("merge"), # Duplicate track removal - DoMultipleMatches = cms.bool(False) # Allow tracklet tracks multiple stubs per layer + DoMultipleMatches = cms.bool(True) # Allow tracklet tracks multiple stubs per layer ) l1tTTTracksFromExtendedTrackletEmulation = l1tTTTracksFromTrackletEmulation.clone( diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc index 23da910c90ad7..8a5f78144e7c5 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc @@ -186,7 +186,7 @@ void VMRouterCM::execute(unsigned int) { //Loop over the input stubs for (auto& stubinput : stubinputs_) { for (unsigned int i = 0; i < stubinput->nStubs(); i++) { - if (allStubCounter > settings_.maxStep("VMR")) + if (allStubCounter >= settings_.maxStep("VMR")) continue; if (allStubCounter >= (1 << N_BITSMEMADDRESS)) continue; diff --git a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py index 8d4b119d77e7e..4a9717c407f3c 100644 --- a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py +++ b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py @@ -60,7 +60,7 @@ # input and output ############################################################ -process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(5)) +process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(100)) #--- To use MCsamples scripts, defining functions get*data*() for easy MC access, #--- follow instructions in https://github.com/cms-L1TK/MCsamples From eafc65be07dc6fcfafb5fc01af36deb4d23548b2 Mon Sep 17 00:00:00 2001 From: Anders Date: Fri, 3 Jan 2025 17:01:54 +0100 Subject: [PATCH 06/13] Fix inefficiency for hybrid tracks --- .../TrackFindingTracklet/src/FitTrack.cc | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc index cd37e8f3a8cea..2ab57984f28e5 100644 --- a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc +++ b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc @@ -158,6 +158,54 @@ void FitTrack::trackFitKF(Tracklet* tracklet, } } + for (const auto& i : fullmatch5_) { + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } + } + + for (const auto& i : fullmatch6_) { + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } + } + + for (const auto& i : fullmatch7_) { + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } + } + + for (const auto& i : fullmatch8_) { + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } + } + + for (const auto& i : fullmatch9_) { + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } + } + + for (const auto& i : fullmatch10_) { + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } + } + // For merge removal, loop through the resulting list of stubs to calculate their stubids if (settings_.removalType() == "merge") { for (const auto& it : trackstublist) { From 7fa46c4abff1b173516fe2b9913a9c237aa8d6fd Mon Sep 17 00:00:00 2001 From: Anders Date: Fri, 3 Jan 2025 23:00:10 +0100 Subject: [PATCH 07/13] Cleanup/simplify code in FitTrack --- .../TrackFindingTracklet/interface/FitTrack.h | 13 +- .../TrackFindingTracklet/src/FitTrack.cc | 438 ++---------------- 2 files changed, 52 insertions(+), 399 deletions(-) diff --git a/L1Trigger/TrackFindingTracklet/interface/FitTrack.h b/L1Trigger/TrackFindingTracklet/interface/FitTrack.h index 229abeb087943..6a28bf290d255 100644 --- a/L1Trigger/TrackFindingTracklet/interface/FitTrack.h +++ b/L1Trigger/TrackFindingTracklet/interface/FitTrack.h @@ -48,17 +48,8 @@ namespace trklet { private: std::vector seedtracklet_; - std::vector fullmatch0_; - std::vector fullmatch1_; - std::vector fullmatch2_; - std::vector fullmatch3_; - std::vector fullmatch4_; - std::vector fullmatch5_; - std::vector fullmatch6_; - std::vector fullmatch7_; - std::vector fullmatch8_; - std::vector fullmatch9_; - std::vector fullmatch10_; + + std::vector> fullmatch_; unsigned int iSector_; diff --git a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc index 2ab57984f28e5..6493ec20bad43 100644 --- a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc +++ b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc @@ -14,7 +14,9 @@ using namespace std; using namespace trklet; FitTrack::FitTrack(string name, Settings const& settings, Globals* global) - : ProcessBase(name, settings, global), trackfit_(nullptr) {} + : ProcessBase(name, settings, global), trackfit_(nullptr) { + fullmatch_.resize(N_LAYER+N_DISK); +} void FitTrack::addOutput(MemoryBase* memory, string output) { if (settings_.writetrace()) { @@ -42,71 +44,17 @@ void FitTrack::addInput(MemoryBase* memory, string input) { seedtracklet_.push_back(tmp); return; } - if (input.substr(0, 11) == "fullmatch0i") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - fullmatch0_.push_back(tmp); - return; - } - if (input.substr(0, 11) == "fullmatch1i") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - fullmatch1_.push_back(tmp); - return; - } - if (input.substr(0, 11) == "fullmatch2i") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - fullmatch2_.push_back(tmp); - return; - } - if (input.substr(0, 11) == "fullmatch3i") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - fullmatch3_.push_back(tmp); - return; - } - if (input.substr(0, 11) == "fullmatch4i") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - fullmatch4_.push_back(tmp); - return; - } - if (input.substr(0, 11) == "fullmatch5i") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - fullmatch5_.push_back(tmp); - return; - } - if (input.substr(0, 11) == "fullmatch6i") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - fullmatch6_.push_back(tmp); - return; - } - if (input.substr(0, 11) == "fullmatch7i") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - fullmatch7_.push_back(tmp); - return; - } - if (input.substr(0, 11) == "fullmatch8i") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - fullmatch8_.push_back(tmp); - return; - } - if (input.substr(0, 11) == "fullmatch9i") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - fullmatch9_.push_back(tmp); - return; - } - if (input.substr(0, 11) == "fullmatch10") { - auto* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - fullmatch10_.push_back(tmp); - return; + + for(unsigned int i = 0; i < N_LAYER + N_DISK; i++) { + std::ostringstream oss; + oss << "fullmatch" << i << "in";; + auto const& str = oss.str(); + if (input.substr(0, 11) == str.substr(0, 11)) { + auto* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + fullmatch_[i].push_back(tmp); + return; + } } throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " input = " << input << " not found"; @@ -126,85 +74,16 @@ void FitTrack::trackFitKF(Tracklet* tracklet, trackstublist.emplace_back(tracklet->outerFPGAStub()); // Now get ALL matches (can have multiple per layer) - for (const auto& i : fullmatch1_) { - for (unsigned int j = 0; j < i->nMatches(); j++) { - if (i->getTracklet(j)->TCID() == tracklet->TCID()) { - trackstublist.push_back(i->getMatch(j).second); - } - } - } - - for (const auto& i : fullmatch2_) { - for (unsigned int j = 0; j < i->nMatches(); j++) { - if (i->getTracklet(j)->TCID() == tracklet->TCID()) { - trackstublist.push_back(i->getMatch(j).second); - } - } - } - - for (const auto& i : fullmatch3_) { - for (unsigned int j = 0; j < i->nMatches(); j++) { - if (i->getTracklet(j)->TCID() == tracklet->TCID()) { - trackstublist.push_back(i->getMatch(j).second); - } + for (unsigned int k = 0 ; k < fullmatch_.size(); k++){ + for (const auto& i : fullmatch_[k]) { + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } } } - for (const auto& i : fullmatch4_) { - for (unsigned int j = 0; j < i->nMatches(); j++) { - if (i->getTracklet(j)->TCID() == tracklet->TCID()) { - trackstublist.push_back(i->getMatch(j).second); - } - } - } - - for (const auto& i : fullmatch5_) { - for (unsigned int j = 0; j < i->nMatches(); j++) { - if (i->getTracklet(j)->TCID() == tracklet->TCID()) { - trackstublist.push_back(i->getMatch(j).second); - } - } - } - - for (const auto& i : fullmatch6_) { - for (unsigned int j = 0; j < i->nMatches(); j++) { - if (i->getTracklet(j)->TCID() == tracklet->TCID()) { - trackstublist.push_back(i->getMatch(j).second); - } - } - } - - for (const auto& i : fullmatch7_) { - for (unsigned int j = 0; j < i->nMatches(); j++) { - if (i->getTracklet(j)->TCID() == tracklet->TCID()) { - trackstublist.push_back(i->getMatch(j).second); - } - } - } - - for (const auto& i : fullmatch8_) { - for (unsigned int j = 0; j < i->nMatches(); j++) { - if (i->getTracklet(j)->TCID() == tracklet->TCID()) { - trackstublist.push_back(i->getMatch(j).second); - } - } - } - - for (const auto& i : fullmatch9_) { - for (unsigned int j = 0; j < i->nMatches(); j++) { - if (i->getTracklet(j)->TCID() == tracklet->TCID()) { - trackstublist.push_back(i->getMatch(j).second); - } - } - } - - for (const auto& i : fullmatch10_) { - for (unsigned int j = 0; j < i->nMatches(); j++) { - if (i->getTracklet(j)->TCID() == tracklet->TCID()) { - trackstublist.push_back(i->getMatch(j).second); - } - } - } // For merge removal, loop through the resulting list of stubs to calculate their stubids if (settings_.removalType() == "merge") { @@ -970,33 +849,20 @@ void FitTrack::execute(deque& streamTrackRaw, vector>& streamsStubRaw, unsigned int iSector) { // merge - const std::vector& matches0 = orderedMatches(fullmatch0_); - const std::vector& matches1 = orderedMatches(fullmatch1_); - const std::vector& matches2 = orderedMatches(fullmatch2_); - const std::vector& matches3 = orderedMatches(fullmatch3_); - const std::vector& matches4 = orderedMatches(fullmatch4_); - const std::vector& matches5 = orderedMatches(fullmatch5_); - const std::vector& matches6 = orderedMatches(fullmatch6_); - const std::vector& matches7 = orderedMatches(fullmatch7_); - const std::vector& matches8 = orderedMatches(fullmatch8_); - const std::vector& matches9 = orderedMatches(fullmatch9_); - const std::vector& matches10 = orderedMatches(fullmatch10_); + std::vector> matches; + + for (unsigned int i = 0; i < fullmatch_.size(); i++) { + matches.push_back(orderedMatches(fullmatch_[i])); + } + bool print = getName() == "FT_D1D2" && iSector == 3; print = false; iSector_ = iSector; - if (settings_.debugTracklet() && (matches1.size() + matches2.size() + matches3.size() + matches4.size()) > 0) { - for (auto& imatch : fullmatch1_) { - edm::LogVerbatim("Tracklet") << imatch->getName() << " " << imatch->nMatches(); - } - edm::LogVerbatim("Tracklet") << getName() << " matches : " << matches1.size() << " " << matches2.size() << " " - << matches3.size() << " " << matches4.size(); - } - - unsigned int indexArray[11]; - for (unsigned int i = 0; i < 11; i++) { + unsigned int indexArray[N_LAYER + N_DISK]; + for (unsigned int i = 0; i < N_LAYER + N_DISK; i++) { indexArray[i] = 0; } @@ -1012,102 +878,15 @@ void FitTrack::execute(deque& streamTrackRaw, count++; bestTracklet = nullptr; - if (indexArray[0] < matches0.size()) { - if (bestTracklet == nullptr) { - bestTracklet = matches0[indexArray[0]]; - } else { - if (matches0[indexArray[0]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches0[indexArray[0]]; - } - } - - if (indexArray[1] < matches1.size()) { - if (bestTracklet == nullptr) { - bestTracklet = matches1[indexArray[1]]; - } else { - if (matches1[indexArray[1]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches1[indexArray[1]]; - } - } - - if (indexArray[2] < matches2.size()) { - if (bestTracklet == nullptr) { - bestTracklet = matches2[indexArray[2]]; - } else { - if (matches2[indexArray[2]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches2[indexArray[2]]; - } - } - - if (indexArray[3] < matches3.size()) { - if (bestTracklet == nullptr) { - bestTracklet = matches3[indexArray[3]]; - } else { - if (matches3[indexArray[3]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches3[indexArray[3]]; - } - } - - if (indexArray[4] < matches4.size()) { - if (bestTracklet == nullptr) { - bestTracklet = matches4[indexArray[4]]; - } else { - if (matches4[indexArray[4]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches4[indexArray[4]]; - } - } - - if (indexArray[5] < matches5.size()) { - if (bestTracklet == nullptr) { - bestTracklet = matches5[indexArray[5]]; - } else { - if (matches5[indexArray[5]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches5[indexArray[5]]; - } - } - - if (indexArray[6] < matches6.size()) { - if (bestTracklet == nullptr) { - bestTracklet = matches6[indexArray[6]]; - } else { - if (matches6[indexArray[6]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches6[indexArray[6]]; - } - } - - if (indexArray[7] < matches7.size()) { - if (bestTracklet == nullptr) { - bestTracklet = matches7[indexArray[7]]; - } else { - if (matches7[indexArray[7]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches7[indexArray[7]]; - } - } - - if (indexArray[8] < matches8.size()) { - if (bestTracklet == nullptr) { - bestTracklet = matches8[indexArray[8]]; - } else { - if (matches8[indexArray[8]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches8[indexArray[8]]; - } - } - - if (indexArray[9] < matches9.size()) { - if (bestTracklet == nullptr) { - bestTracklet = matches9[indexArray[9]]; - } else { - if (matches9[indexArray[9]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches9[indexArray[9]]; - } - } - - if (indexArray[10] < matches10.size()) { - if (bestTracklet == nullptr) { - bestTracklet = matches10[indexArray[10]]; - } else { - if (matches10[indexArray[10]]->TCID() < bestTracklet->TCID()) - bestTracklet = matches10[indexArray[10]]; + for(unsigned int i = 0; iTCID() < bestTracklet->TCID()) { + bestTracklet = matches[i][indexArray[i]]; + } + } } } @@ -1121,142 +900,25 @@ void FitTrack::execute(deque& streamTrackRaw, //Counts unique hits in each layer int nMatchesUniq = 0; - bool match = false; + if (print) std::cout << "istep = " << istep; - while (indexArray[0] < matches0.size() && matches0[indexArray[0]] == bestTracklet) { - if (print) - std::cout << " match0"; - indexArray[0]++; - nMatches++; - match = true; - } - - if (match) - nMatchesUniq++; - match = false; - - while (indexArray[1] < matches1.size() && matches1[indexArray[1]] == bestTracklet) { - if (print) - std::cout << " match1"; - indexArray[1]++; - nMatches++; - match = true; - } - - if (match) - nMatchesUniq++; - match = false; - - while (indexArray[2] < matches2.size() && matches2[indexArray[2]] == bestTracklet) { - if (print) - std::cout << " match2"; - indexArray[2]++; - nMatches++; - match = true; - } - - if (match) - nMatchesUniq++; - match = false; - - while (indexArray[3] < matches3.size() && matches3[indexArray[3]] == bestTracklet) { - if (print) - std::cout << " match3"; - indexArray[3]++; - nMatches++; - match = true; - } - - if (match) - nMatchesUniq++; - match = false; - - while (indexArray[4] < matches4.size() && matches4[indexArray[4]] == bestTracklet) { - if (print) - std::cout << " match4"; - indexArray[4]++; - nMatches++; - match = true; - } - - if (match) - nMatchesUniq++; - match = false; - - while (indexArray[5] < matches5.size() && matches5[indexArray[5]] == bestTracklet) { - if (print) - std::cout << " match5"; - indexArray[5]++; - nMatches++; - match = true; - } - - if (match) - nMatchesUniq++; - match = false; - - while (indexArray[6] < matches6.size() && matches6[indexArray[6]] == bestTracklet) { - if (print) - std::cout << " match6"; - indexArray[6]++; - nMatches++; - match = true; - } - - if (match) - nMatchesUniq++; - match = false; - - while (indexArray[7] < matches7.size() && matches7[indexArray[7]] == bestTracklet) { - if (print) - std::cout << " match7"; - indexArray[7]++; - nMatches++; - match = true; - } - - if (match) - nMatchesUniq++; - match = false; - - while (indexArray[8] < matches8.size() && matches8[indexArray[8]] == bestTracklet) { - if (print) - std::cout << " match8"; - indexArray[8]++; - nMatches++; - match = true; - } - - if (match) - nMatchesUniq++; - match = false; - - while (indexArray[9] < matches9.size() && matches9[indexArray[9]] == bestTracklet) { - if (print) - std::cout << " match9"; - indexArray[9]++; - nMatches++; - match = true; - } - - if (match) - nMatchesUniq++; - match = false; + for(unsigned int i=0; i(memory); @@ -74,17 +75,16 @@ void FitTrack::trackFitKF(Tracklet* tracklet, trackstublist.emplace_back(tracklet->outerFPGAStub()); // Now get ALL matches (can have multiple per layer) - for (unsigned int k = 0 ; k < fullmatch_.size(); k++){ + for (unsigned int k = 0; k < fullmatch_.size(); k++) { for (const auto& i : fullmatch_[k]) { - for (unsigned int j = 0; j < i->nMatches(); j++) { - if (i->getTracklet(j)->TCID() == tracklet->TCID()) { - trackstublist.push_back(i->getMatch(j).second); - } - } + for (unsigned int j = 0; j < i->nMatches(); j++) { + if (i->getTracklet(j)->TCID() == tracklet->TCID()) { + trackstublist.push_back(i->getMatch(j).second); + } + } } } - // For merge removal, loop through the resulting list of stubs to calculate their stubids if (settings_.removalType() == "merge") { for (const auto& it : trackstublist) { @@ -855,7 +855,6 @@ void FitTrack::execute(deque& streamTrackRaw, matches.push_back(orderedMatches(fullmatch_[i])); } - bool print = getName() == "FT_D1D2" && iSector == 3; print = false; @@ -878,15 +877,15 @@ void FitTrack::execute(deque& streamTrackRaw, count++; bestTracklet = nullptr; - for(unsigned int i = 0; iTCID() < bestTracklet->TCID()) { - bestTracklet = matches[i][indexArray[i]]; - } - } + if (bestTracklet == nullptr) { + bestTracklet = matches[i][indexArray[i]]; + } else { + if (matches[i][indexArray[i]]->TCID() < bestTracklet->TCID()) { + bestTracklet = matches[i][indexArray[i]]; + } + } } } @@ -901,25 +900,23 @@ void FitTrack::execute(deque& streamTrackRaw, //Counts unique hits in each layer int nMatchesUniq = 0; - if (print) std::cout << "istep = " << istep; - for(unsigned int i=0; i