diff --git a/L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h b/L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h new file mode 100644 index 0000000000000..50048e22a96ee --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h @@ -0,0 +1,37 @@ +#ifndef L1Trigger_TrackFindingTracklet_interface_AllInnerStubsMemory_h +#define L1Trigger_TrackFindingTracklet_interface_AllInnerStubsMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include +#include +#include + +namespace trklet { + + class Settings; + class Stub; + class L1TStub; + + class AllInnerStubsMemory : public MemoryBase { + public: + AllInnerStubsMemory(std::string name, Settings const& settings); + + ~AllInnerStubsMemory() override = default; + + void addStub(const Stub* stub) { stubs_.push_back(stub); } + + unsigned int nStubs() const { return stubs_.size(); } + + const Stub* getStub(unsigned int i) const { return stubs_[i]; } + + void clean() override { stubs_.clear(); } + + void writeStubs(bool first, unsigned int iSector); + + private: + std::vector stubs_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h index f6367108d9ca4..7f84afe390301 100644 --- a/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/AllProjectionsMemory.h @@ -13,7 +13,7 @@ namespace trklet { class AllProjectionsMemory : public MemoryBase { public: - AllProjectionsMemory(std::string name, Settings const& settings, unsigned int iSector); + AllProjectionsMemory(std::string name, Settings const& settings); ~AllProjectionsMemory() override = default; @@ -25,7 +25,7 @@ namespace trklet { void clean() override { tracklets_.clear(); } - void writeAP(bool first); + void writeAP(bool first, unsigned int iSector); private: std::vector tracklets_; diff --git a/L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h b/L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h index c34601997b069..71254d512e3ac 100644 --- a/L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h @@ -15,7 +15,7 @@ namespace trklet { class AllStubsMemory : public MemoryBase { public: - AllStubsMemory(std::string name, Settings const& settings, unsigned int iSector); + AllStubsMemory(std::string name, Settings const& settings); ~AllStubsMemory() override = default; @@ -27,7 +27,7 @@ namespace trklet { void clean() override { stubs_.clear(); } - void writeStubs(bool first); + void writeStubs(bool first, unsigned int iSector); private: std::vector stubs_; diff --git a/L1Trigger/TrackFindingTracklet/interface/Cabling.h b/L1Trigger/TrackFindingTracklet/interface/Cabling.h deleted file mode 100644 index f835b0d446234..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/Cabling.h +++ /dev/null @@ -1,39 +0,0 @@ -// This class holds a list of stubs that are in a given layer and DCT region -#ifndef L1Trigger_TrackFindingTracklet_interface_Cabling_h -#define L1Trigger_TrackFindingTracklet_interface_Cabling_h - -#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" -#include "L1Trigger/TrackFindingTracklet/interface/DTC.h" -#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" - -#include -#include - -namespace trklet { - - class Settings; - - class Cabling { - public: - Cabling(std::string dtcconfig, std::string moduleconfig, Settings const& settings); - - ~Cabling() = default; - - const std::string& dtc(int layer, int ladder, int module) const; - - void addphi(const std::string& dtc, double phi, int layer, int module); - - void writephirange() const; - - std::vector DTCs() const; - - private: - Settings const& settings_; - std::vector links_; - std::map dtcranges_; - std::map dtcs_; - std::map > > modules_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h b/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h index 96358051401c6..8a20813e378d4 100644 --- a/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/CandidateMatchMemory.h @@ -16,7 +16,7 @@ namespace trklet { class CandidateMatchMemory : public MemoryBase { public: - CandidateMatchMemory(std::string name, Settings const& settings, unsigned int iSector); + CandidateMatchMemory(std::string name, Settings const& settings); ~CandidateMatchMemory() override = default; @@ -28,7 +28,7 @@ namespace trklet { void clean() override { matches_.clear(); } - void writeCM(bool first); + void writeCM(bool first, unsigned int iSector); private: std::vector, const Stub*> > matches_; diff --git a/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h b/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h index 3d0832f56dc5e..e133757bbb70e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h +++ b/L1Trigger/TrackFindingTracklet/interface/CircularBuffer.h @@ -28,6 +28,11 @@ namespace trklet { //Almost full if writer ptr incremented by 1 or 2 is same as read ptr bool almostfull() const { return (((wptr_ + 1) % size_) == rptr_) || (((wptr_ + 2) % size_) == rptr_); } + //near full if writer ptr incremented by 1, 2, or 3 is same as read ptr + bool nearfull() const { + return (((wptr_ + 1) % size_) == rptr_) || (((wptr_ + 2) % size_) == rptr_) || (((wptr_ + 3) % size_) == rptr_); + } + //Empty buffer is write ptr is same as read ptr bool empty() const { return wptr_ == rptr_; } @@ -47,8 +52,13 @@ namespace trklet { assert(!full()); buffer_[wptr_++] = element; wptr_ = wptr_ % size_; + assert(wptr_ != rptr_); } + unsigned int rptr() const { return rptr_; } + + unsigned int wptr() const { return wptr_; } + private: std::vector buffer_; diff --git a/L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h b/L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h index 41e64bd302f12..d17754d944f4b 100644 --- a/L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/CleanTrackMemory.h @@ -12,7 +12,7 @@ namespace trklet { class CleanTrackMemory : public MemoryBase { public: - CleanTrackMemory(std::string name, Settings const& settings, unsigned int iSector, double phimin, double phimax); + CleanTrackMemory(std::string name, Settings const& settings, double phimin, double phimax); ~CleanTrackMemory() override = default; @@ -22,7 +22,7 @@ namespace trklet { void clean() override { tracks_.clear(); } - void writeCT(bool first); + void writeCT(bool first, unsigned int iSector); private: double phimin_; diff --git a/L1Trigger/TrackFindingTracklet/interface/DTC.h b/L1Trigger/TrackFindingTracklet/interface/DTC.h deleted file mode 100644 index bbdf38c07636b..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/DTC.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_DTC_h -#define L1Trigger_TrackFindingTracklet_interface_DTC_h - -#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" - -namespace trklet { - - class Stub; - class L1TStub; - - class DTC { - public: - DTC(std::string name = ""); - - ~DTC() = default; - - void setName(std::string name); - - void addSec(int sector); - - void addphi(double phi, unsigned int layerdisk); - - void addLink(double phimin, double phimax); - - int addStub(std::pair stub); - - unsigned int nLinks() const { return links_.size(); } - - const DTCLink& link(unsigned int i) const { return links_[i]; } - - void clean(); - - double min(unsigned int i) const { return phimin_[i]; } - double max(unsigned int i) const { return phimax_[i]; } - - private: - std::string name_; - std::vector links_; - std::vector sectors_; - - double phimin_[N_LAYER + N_DISK]; - double phimax_[N_LAYER + N_DISK]; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/DTCLink.h b/L1Trigger/TrackFindingTracklet/interface/DTCLink.h deleted file mode 100644 index d9f7a0c24bcf5..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/DTCLink.h +++ /dev/null @@ -1,34 +0,0 @@ -// This class holds a list of stubs that are in a given layer and DCT region -#ifndef L1Trigger_TrackFindingTracklet_interface_DTCLink_h -#define L1Trigger_TrackFindingTracklet_interface_DTCLink_h - -#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" -#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" - -namespace trklet { - - class DTCLink { - public: - DTCLink(double phimin, double phimax); - - ~DTCLink() = default; - - void addStub(std::pair stub); - - bool inRange(double phi, bool overlaplayer); - - unsigned int nStubs() const { return stubs_.size(); } - - Stub* getFPGAStub(unsigned int i) const { return stubs_[i].first; } - L1TStub* getL1TStub(unsigned int i) const { return stubs_[i].second; } - std::pair getStub(unsigned int i) const { return stubs_[i]; } - - void clean() { stubs_.clear(); } - - private: - double phimin_; - double phimax_; - std::vector > stubs_; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h b/L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h new file mode 100644 index 0000000000000..daab972a6ff0d --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h @@ -0,0 +1,38 @@ +// This class holds a list of stubs for an DTC link. +// This modules 'owns' the pointers to the stubs. All subsequent modules that handles stubs uses a pointer to the original stored here. +#ifndef L1Trigger_TrackFindingTracklet_interface_DTCLinkMemory_h +#define L1Trigger_TrackFindingTracklet_interface_DTCLinkMemory_h + +#include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" + +#include + +namespace trklet { + + class Settings; + class Globals; + class Stub; + class L1TStub; + + class DTCLinkMemory : public MemoryBase { + public: + DTCLinkMemory(std::string name, Settings const& settings, double, double); + + ~DTCLinkMemory() override = default; + + void addStub(const L1TStub& al1stub, const Stub& stub); + + unsigned int nStubs() const { return stubs_.size(); } + + Stub* getStub(unsigned int i) { return stubs_[i]; } + + void writeStubs(bool first, unsigned int iSector); + + void clean() override; + + private: + std::vector stubs_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/DiskResidual.h b/L1Trigger/TrackFindingTracklet/interface/DiskResidual.h deleted file mode 100644 index 546410e5a78b7..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/DiskResidual.h +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_DiskResidual_h -#define L1Trigger_TrackFindingTracklet_interface_DiskResidual_h - -#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" - -#include - -namespace trklet { - - class Settings; - class Stub; - - class DiskResidual { - public: - DiskResidual() { valid_ = false; } - - ~DiskResidual() = default; - - void init(Settings const& settings, - int disk, - int iphiresid, - int irresid, - int istubid, - double phiresid, - double rresid, - double phiresidapprox, - double rresidapprox, - double zstub, - double alpha, - FPGAWord ialpha, - const Stub* stubptr); - - bool valid() const { return valid_; } - - const FPGAWord& fpgaphiresid() const { - assert(valid_); - return fpgaphiresid_; - }; - - const FPGAWord& fpgarresid() const { - assert(valid_); - return fpgarresid_; - }; - - const FPGAWord& fpgastubid() const { - assert(valid_); - return fpgastubid_; - }; - - double phiresid() const { - assert(valid_); - return phiresid_; - }; - - double rresid() const { - assert(valid_); - return rresid_; - }; - - double phiresidapprox() const { - assert(valid_); - return phiresidapprox_; - }; - - double rresidapprox() const { - assert(valid_); - return rresidapprox_; - }; - - double zstub() const { - assert(valid_); - return zstub_; - }; - - double alpha() const { - assert(valid_); - return alpha_; - }; - - const FPGAWord& ialpha() const { - assert(valid_); - return ialpha_; - }; - - const Stub* stubptr() const { - assert(valid_); - return stubptr_; - }; - - protected: - bool valid_; - - int disk_; - - FPGAWord fpgaphiresid_; - FPGAWord fpgarresid_; - FPGAWord fpgastubid_; - - double phiresid_; - double rresid_; - - double phiresidapprox_; - double rresidapprox_; - - double zstub_; - double alpha_; - FPGAWord ialpha_; - const Stub* stubptr_; - }; - -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/FitTrack.h b/L1Trigger/TrackFindingTracklet/interface/FitTrack.h index fb897ec1660bd..e72c4cf664132 100644 --- a/L1Trigger/TrackFindingTracklet/interface/FitTrack.h +++ b/L1Trigger/TrackFindingTracklet/interface/FitTrack.h @@ -17,7 +17,7 @@ namespace trklet { class FitTrack : public ProcessBase { public: - FitTrack(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + FitTrack(std::string name, Settings const& settings, Globals* global); ~FitTrack() override = default; @@ -38,7 +38,7 @@ namespace trklet { std::vector orderedMatches(std::vector& fullmatch); - void execute(); + void execute(unsigned int iSector); private: std::vector seedtracklet_; @@ -47,6 +47,8 @@ namespace trklet { std::vector fullmatch3_; std::vector fullmatch4_; + unsigned int iSector_; + TrackFitMemory* trackfit_; }; diff --git a/L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h b/L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h index 10215946939c5..49f60cad58cf3 100644 --- a/L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/FullMatchMemory.h @@ -16,7 +16,7 @@ namespace trklet { class FullMatchMemory : public MemoryBase { public: - FullMatchMemory(std::string name, Settings const& settings, unsigned int iSector); + FullMatchMemory(std::string name, Settings const& settings); ~FullMatchMemory() override = default; @@ -30,7 +30,7 @@ namespace trklet { void clean() override { matches_.clear(); } - void writeMC(bool first); + void writeMC(bool first, unsigned int iSector); int layer() const { return layer_; } int disk() const { return disk_; } diff --git a/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h b/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h index 02879946c8eb7..90dae4b7ccf58 100644 --- a/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h @@ -17,24 +17,22 @@ namespace trklet { class InputLinkMemory : public MemoryBase { public: - InputLinkMemory(std::string name, Settings const& settings, unsigned int iSector, double, double); + InputLinkMemory(std::string name, Settings const& settings, double, double); ~InputLinkMemory() override = default; - bool addStub(Settings const& settings, Globals* globals, L1TStub& al1stub, Stub& stub, std::string dtc); + void addStub(Stub* stub); unsigned int nStubs() const { return stubs_.size(); } Stub* getStub(unsigned int i) { return stubs_[i]; } - void writeStubs(bool first); + void writeStubs(bool first, unsigned int iSector); void clean() override; private: std::vector stubs_; - int phiregion_; - unsigned int layerdisk_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/InputRouter.h b/L1Trigger/TrackFindingTracklet/interface/InputRouter.h new file mode 100644 index 0000000000000..55551d615ff21 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/InputRouter.h @@ -0,0 +1,39 @@ +// InputRouter: sorts input stubs into layer/disk and phi region +#ifndef L1Trigger_TrackFindingTracklet_interface_InputRouter_h +#define L1Trigger_TrackFindingTracklet_interface_InputRouter_h + +#include "L1Trigger/TrackFindingTracklet/interface/ProcessBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" + +#include +#include +#include + +namespace trklet { + + class Settings; + class Globals; + class MemoryBase; + class DTCLinkMemory; + class InputLinkMemory; + + class InputRouter : public ProcessBase { + public: + InputRouter(std::string name, Settings const& settings, Globals* global); + + ~InputRouter() override = default; + + void addOutput(MemoryBase* memory, std::string output) override; + void addInput(MemoryBase* memory, std::string input) override; + + void execute(); + + private: + //The input stub memories + DTCLinkMemory* dtcstubs_; + + //The all stub memories - the ints are layerdisk and phiregion + std::vector, InputLinkMemory*> > irstubs_; + }; +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/L1SimTrack.h b/L1Trigger/TrackFindingTracklet/interface/L1SimTrack.h new file mode 100644 index 0000000000000..eddda2dbc1171 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/L1SimTrack.h @@ -0,0 +1,53 @@ +// Stores MC truth information, pt, eta, phi, vx, vy, vz, as well as particle type and track id +#ifndef L1Trigger_TrackFindingTracklet_interface_L1SimTrack_h +#define L1Trigger_TrackFindingTracklet_interface_L1SimTrack_h + +#include +#include +#include +#include +#include +#include + +namespace trklet { + + class L1SimTrack { + public: + L1SimTrack(); + L1SimTrack(int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz); + ~L1SimTrack() = default; + + void write(std::ofstream& out); + void write(std::ostream& out); + + int eventid() const { return eventid_; } + int trackid() const { return trackid_; } + int type() const { return type_; } + double pt() const { return pt_; } + double eta() const { return eta_; } + double phi() const { return phi_; } + double vx() const { return vx_; } + double vy() const { return vy_; } + double vz() const { return vz_; } + double dxy() const { return -vx() * sin(phi()) + vy() * cos(phi()); } + double d0() const { return -dxy(); } + int charge() const { + if (type_ == 11 || type_ == 13 || type_ == -211 || type_ == -321 || type_ == -2212) + return -1; + return 1; + } + + private: + int eventid_; + int trackid_; + int type_; + double pt_; + double eta_; + double phi_; + double vx_; + double vy_; + double vz_; + }; + +}; // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/L1TStub.h b/L1Trigger/TrackFindingTracklet/interface/L1TStub.h index 2010d1eae1bb6..95a85bdaf4f1a 100644 --- a/L1Trigger/TrackFindingTracklet/interface/L1TStub.h +++ b/L1Trigger/TrackFindingTracklet/interface/L1TStub.h @@ -1,6 +1,8 @@ #ifndef L1Trigger_TrackFindingTracklet_interface_L1TStub_h #define L1Trigger_TrackFindingTracklet_interface_L1TStub_h +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + #include #include #include @@ -12,28 +14,23 @@ namespace trklet { class L1TStub { public: L1TStub(); - L1TStub(int eventid, - std::vector tps, - int iphi, - int iz, - int layer, - int ladder, - int module, - int strip, + + L1TStub(std::string DTClink, + int region, + int layerdisk, + std::string stubword, + int isPSmodule, + int isFlipped, double x, double y, double z, - double sigmax, - double sigmaz, - double pt, double bend, - int isPSmodule, - int isFlipped); + double strip, + std::vector tps); ~L1TStub() = default; void write(std::ofstream& out); - void write(std::ostream& out); double diphi(); @@ -43,10 +40,14 @@ namespace trklet { unsigned int layer() const { return layer_; } int disk() const { + if (layerdisk_ < N_LAYER) { + return 0; + } + int disk = layerdisk_ - N_LAYER + 1; if (z_ < 0.0) { - return -module_; + return -disk; } - return module_; + return disk; } unsigned int ladder() const { return ladder_; } unsigned int module() const { return module_; } @@ -96,8 +97,21 @@ namespace trklet { bool isTilted() const; bool tpmatch(int tp) const; + bool tpmatch2(int tp) const; + + const std::string& DTClink() const { return DTClink_; } + + int layerdisk() const { return layerdisk_; } + + int region() const { return region_; } + + const std::string& stubword() const { return stubword_; } private: + int layerdisk_; + std::string DTClink_; + int region_; + std::string stubword_; int eventid_; std::vector tps_; unsigned int iphi_; diff --git a/L1Trigger/TrackFindingTracklet/interface/LayerProjection.h b/L1Trigger/TrackFindingTracklet/interface/LayerProjection.h deleted file mode 100644 index b31854c5adcd2..0000000000000 --- a/L1Trigger/TrackFindingTracklet/interface/LayerProjection.h +++ /dev/null @@ -1,163 +0,0 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_LayerProjection_h -#define L1Trigger_TrackFindingTracklet_interface_LayerProjection_h - -#include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" - -namespace trklet { - - class Settings; - - class LayerProjection { - public: - LayerProjection() { valid_ = false; } - - ~LayerProjection() = default; - - void init(Settings const& settings, - int projlayer, - double rproj, - int iphiproj, - int izproj, - int iphider, - int izder, - double phiproj, - double zproj, - double phiprojder, - double zprojder, - double phiprojapprox, - double zprojapprox, - double phiprojderapprox, - double zprojderapprox, - bool isPSseed = false); - - bool valid() const { return valid_; } - - int projlayer() const { - assert(valid_); - return projlayer_; - }; - - double rproj() const { - assert(valid_); - return rproj_; - }; - - const FPGAWord& fpgaphiproj() const { - assert(valid_); - return fpgaphiproj_; - }; - - const FPGAWord& fpgazproj() const { - assert(valid_); - return fpgazproj_; - }; - - const FPGAWord& fpgaphiprojder() const { - assert(valid_); - return fpgaphiprojder_; - }; - - const FPGAWord& fpgazprojder() const { - assert(valid_); - return fpgazprojder_; - }; - - const FPGAWord& fpgaphiprojvm() const { - assert(valid_); - return fpgaphiprojvm_; - }; - - const FPGAWord& fpgazbin1projvm() const { - assert(valid_); - return fpgazbin1projvm_; - }; - - const FPGAWord& fpgazbin2projvm() const { - assert(valid_); - return fpgazbin2projvm_; - }; - - const FPGAWord& fpgafinezvm() const { - assert(valid_); - return fpgafinezvm_; - }; - - const FPGAWord& fpgazprojvm() const { - assert(valid_); - return fpgazprojvm_; - }; - - double phiproj() const { - assert(valid_); - return phiproj_; - }; - - double zproj() const { - assert(valid_); - return zproj_; - }; - - double phiprojder() const { - assert(valid_); - return phiprojder_; - }; - - double zprojder() const { - assert(valid_); - return zprojder_; - }; - - double phiprojapprox() const { - assert(valid_); - return phiprojapprox_; - }; - - double zprojapprox() const { - assert(valid_); - return zprojapprox_; - }; - - double phiprojderapprox() const { - assert(valid_); - return phiprojderapprox_; - }; - - double zprojderapprox() const { - assert(valid_); - return zprojderapprox_; - }; - - protected: - bool valid_; - - int projlayer_; - - double rproj_; - - FPGAWord fpgaphiproj_; - FPGAWord fpgazproj_; - FPGAWord fpgaphiprojder_; - FPGAWord fpgazprojder_; - - FPGAWord fpgaphiprojvm_; - FPGAWord fpgazprojvm_; - - FPGAWord fpgazbin1projvm_; - FPGAWord fpgazbin2projvm_; - FPGAWord fpgafinezvm_; - - double phiproj_; - double zproj_; - double phiprojder_; - double zprojder_; - - double zbin1_; - double zbin2_; - - double phiprojapprox_; - double zprojapprox_; - double phiprojderapprox_; - double zprojderapprox_; - }; -}; // namespace trklet -#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h b/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h index 16d95f9d85f33..2a4051e98cb55 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchCalculator.h @@ -20,14 +20,14 @@ namespace trklet { class MatchCalculator : public ProcessBase { public: - MatchCalculator(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + 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(); + void execute(double phioffset); std::vector, const Stub*> > mergeMatches( std::vector& candmatch); @@ -40,7 +40,6 @@ namespace trklet { int icorrshift_; int icorzshift_; int phi0shift_; - double phioffset_; unsigned int phimatchcut_[N_SEED]; unsigned int zmatchcut_[N_SEED]; diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h index 4d935e87322c1..db0ba984a85a5 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngine.h @@ -15,7 +15,7 @@ namespace trklet { class MatchEngine : public ProcessBase { public: - MatchEngine(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + MatchEngine(std::string name, Settings const& settings, Globals* global); ~MatchEngine() override = default; @@ -30,13 +30,15 @@ namespace trklet { CandidateMatchMemory* candmatches_; - int layer_; - int disk_; + unsigned int layerdisk_; bool barrel_; int nvm_; int nvmbits_; + unsigned int nfinephibits_; //number of fine phi bits in phi VM bin + unsigned int nrinv_; //number of bits for rinv in stub bend LUT + //used in the layers std::vector table_; diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h index cb84945be1865..f61a4a659ee7c 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchEngineUnit.h @@ -17,16 +17,22 @@ namespace trklet { class MatchEngineUnit { public: - MatchEngineUnit(bool barrel, std::vector table, std::vector tablePS, std::vector table2S); + MatchEngineUnit(bool barrel, unsigned int layerdisk, std::vector table); ~MatchEngineUnit() = default; void init(VMStubsMEMemory* vmstubsmemory, - unsigned int slot, + unsigned int nrzbin, + unsigned int rzbin, + unsigned int iphi, + int shift, int projrinv, int projfinerz, int projfinephi, - bool usesecond, + bool usefirstMinus, + bool usefirstPlus, + bool usesecondMinus, + bool usesecondPlus, bool isPSseed, Tracklet* proj); @@ -42,34 +48,36 @@ namespace trklet { void reset(); - void step(); + void step(bool print); private: VMStubsMEMemory* vmstubsmemory_; - //unsigned int memory slot - unsigned int slot_; + unsigned int nrzbins_; + unsigned int rzbin_; + unsigned int phibin_; + int shift_; + unsigned int istub_; + unsigned int iuse_; bool barrel_; int projrinv_; int projfinerz_; int projfinephi_; - bool usesecond_; + std::vector> use_; bool isPSseed_; Tracklet* proj_; bool idle_; - //used in the layers - std::vector table_; + unsigned int layerdisk_; - //used in the disks - std::vector tablePS_; - std::vector table2S_; + //used for bend consistency with rinv + std::vector table_; //save the candidate matches - CircularBuffer > candmatches_; + CircularBuffer> candmatches_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h index 5758957ec555b..cbda531d96186 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/MatchProcessor.h @@ -23,20 +23,18 @@ namespace trklet { class MatchProcessor : public ProcessBase { public: - MatchProcessor(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + MatchProcessor(std::string name, Settings const& settings, Globals* global); ~MatchProcessor() override = default; void addOutput(MemoryBase* memory, std::string output) override; void addInput(MemoryBase* memory, std::string input) override; - void execute(); + void execute(unsigned int iSector, double phimin); - bool matchCalculator(Tracklet* tracklet, const Stub* fpgastub); + bool matchCalculator(Tracklet* tracklet, const Stub* fpgastub, bool print, unsigned int istep); private: - int layer_; - int disk_; unsigned int layerdisk_; bool barrel_; @@ -45,13 +43,12 @@ namespace trklet { int nvm_; //VMs in sector int nvmbits_; //# of bits for VMs in sector int nvmbins_; //VMs in in phi region + int nrinv_; //# of bits for rinv - int fact_; + int dzshift_; int icorrshift_; int icorzshift_; - int phi0shift_; - - double phioffset_; + int phishift_; unsigned int phimatchcut_[N_SEED]; unsigned int zmatchcut_[N_SEED]; @@ -61,9 +58,6 @@ namespace trklet { unsigned int rcutPS_[N_SEED]; unsigned int rcut2S_[N_SEED]; - double phifact_; - double rzfact_; - int nrbits_; int nphiderbits_; @@ -77,12 +71,10 @@ namespace trklet { //Memory for the full matches std::vector fullmatches_; - //used in the layers + //used for bend consistency with rinv std::vector table_; - //used in the disks - std::vector tablePS_; - std::vector table2S_; + double phimin_; unsigned int nMatchEngines_; std::vector matchengines_; diff --git a/L1Trigger/TrackFindingTracklet/interface/MemoryBase.h b/L1Trigger/TrackFindingTracklet/interface/MemoryBase.h index 2c92d3606d5c7..ca0280bff8911 100644 --- a/L1Trigger/TrackFindingTracklet/interface/MemoryBase.h +++ b/L1Trigger/TrackFindingTracklet/interface/MemoryBase.h @@ -12,7 +12,7 @@ namespace trklet { class MemoryBase { public: - MemoryBase(std::string name, Settings const& settings, unsigned int iSector); + MemoryBase(std::string name, Settings const& settings); virtual ~MemoryBase() = default; diff --git a/L1Trigger/TrackFindingTracklet/interface/ProcessBase.h b/L1Trigger/TrackFindingTracklet/interface/ProcessBase.h index 4033b6ca025cf..35fe4015c5e92 100644 --- a/L1Trigger/TrackFindingTracklet/interface/ProcessBase.h +++ b/L1Trigger/TrackFindingTracklet/interface/ProcessBase.h @@ -11,7 +11,7 @@ namespace trklet { class ProcessBase { public: - ProcessBase(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + ProcessBase(std::string name, Settings const& settings, Globals* global); virtual ~ProcessBase() = default; @@ -36,10 +36,6 @@ namespace trklet { protected: std::string name_; - unsigned int iSector_; - - double phimin_; - double phimax_; Settings const& settings_; Globals* globals_; diff --git a/L1Trigger/TrackFindingTracklet/interface/DiskProjection.h b/L1Trigger/TrackFindingTracklet/interface/Projection.h similarity index 50% rename from L1Trigger/TrackFindingTracklet/interface/DiskProjection.h rename to L1Trigger/TrackFindingTracklet/interface/Projection.h index 83784c5ea042b..80739c56672d5 100644 --- a/L1Trigger/TrackFindingTracklet/interface/DiskProjection.h +++ b/L1Trigger/TrackFindingTracklet/interface/Projection.h @@ -1,46 +1,39 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_DiskProjection_h -#define L1Trigger_TrackFindingTracklet_interface_DiskProjection_h +#ifndef L1Trigger_TrackFindingTracklet_interface_Projection_h +#define L1Trigger_TrackFindingTracklet_interface_Projection_h #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" -#include - namespace trklet { class Settings; - class DiskProjection { + class Projection { public: - DiskProjection() { valid_ = false; } + Projection() { valid_ = false; } - ~DiskProjection() = default; + ~Projection() = default; void init(Settings const& settings, - int projdisk, - double zproj, + unsigned int layerdisk, int iphiproj, - int irproj, + int irzproj, int iphider, - int irder, + int irzder, double phiproj, - double rproj, + double rzproj, double phiprojder, - double rprojder, + double rzprojder, double phiprojapprox, - double rprojapprox, + double rzprojapprox, double phiprojderapprox, - double rprojderapprox); + double rzprojderapprox, + bool isPSseed); bool valid() const { return valid_; } - int projdisk() const { + unsigned int layerdisk() const { assert(valid_); - return projdisk_; - }; - - double zproj() const { - assert(valid_); - return zproj_; + return layerdisk_; }; const FPGAWord& fpgaphiproj() const { @@ -48,9 +41,9 @@ namespace trklet { return fpgaphiproj_; }; - const FPGAWord& fpgarproj() const { + const FPGAWord& fpgarzproj() const { assert(valid_); - return fpgarproj_; + return fpgarzproj_; }; const FPGAWord& fpgaphiprojder() const { @@ -58,44 +51,39 @@ namespace trklet { return fpgaphiprojder_; }; - const FPGAWord& fpgarprojder() const { + const FPGAWord& fpgarzprojder() const { assert(valid_); - return fpgarprojder_; + return fpgarzprojder_; }; - const FPGAWord& fpgaphiprojvm() const { + const FPGAWord& fpgarzbin1projvm() const { assert(valid_); - return fpgaphiprojvm_; + return fpgarzbin1projvm_; }; - const FPGAWord& fpgarprojvm() const { + const FPGAWord& fpgarzbin2projvm() const { assert(valid_); - return fpgarprojvm_; - }; - - double phiproj() const { - assert(valid_); - return phiproj_; + return fpgarzbin2projvm_; }; - const FPGAWord& fpgarbin1projvm() const { + const FPGAWord& fpgafinerzvm() const { assert(valid_); - return fpgarbin1projvm_; + return fpgafinerzvm_; }; - const FPGAWord& fpgarbin2projvm() const { + const FPGAWord& fpgafinephivm() const { assert(valid_); - return fpgarbin2projvm_; + return fpgafinephivm_; }; - const FPGAWord& fpgafinervm() const { + double phiproj() const { assert(valid_); - return fpgafinervm_; + return phiproj_; }; - double rproj() const { + double rzproj() const { assert(valid_); - return rproj_; + return rzproj_; }; double phiprojder() const { @@ -103,9 +91,9 @@ namespace trklet { return phiprojder_; }; - double rprojder() const { + double rzprojder() const { assert(valid_); - return rprojder_; + return rzprojder_; }; double phiprojapprox() const { @@ -113,9 +101,9 @@ namespace trklet { return phiprojapprox_; }; - double rprojapprox() const { + double rzprojapprox() const { assert(valid_); - return rprojapprox_; + return rzprojapprox_; }; double phiprojderapprox() const { @@ -123,9 +111,9 @@ namespace trklet { return phiprojderapprox_; }; - double rprojderapprox() const { + double rzprojderapprox() const { assert(valid_); - return rprojderapprox_; + return rzprojderapprox_; }; void setBendIndex(int bendindex) { fpgabendindex_.set(bendindex, 5, true, __LINE__, __FILE__); } @@ -135,34 +123,30 @@ namespace trklet { protected: bool valid_; - int projdisk_; - - double zproj_; + unsigned int layerdisk_; FPGAWord fpgaphiproj_; - FPGAWord fpgarproj_; + FPGAWord fpgarzproj_; FPGAWord fpgaphiprojder_; - FPGAWord fpgarprojder_; + FPGAWord fpgarzprojder_; - FPGAWord fpgaphiprojvm_; - FPGAWord fpgarprojvm_; - - FPGAWord fpgarbin1projvm_; - FPGAWord fpgarbin2projvm_; - FPGAWord fpgafinervm_; - - FPGAWord fpgabendindex_; + FPGAWord fpgarzbin1projvm_; + FPGAWord fpgarzbin2projvm_; + FPGAWord fpgafinerzvm_; + FPGAWord fpgafinephivm_; double phiproj_; - double rproj_; + double rzproj_; double phiprojder_; - double rprojder_; + double rzprojder_; double phiprojapprox_; - double rprojapprox_; + double rzprojapprox_; double phiprojderapprox_; - double rprojderapprox_; - }; + double rzprojderapprox_; + //used by projections to disks + FPGAWord fpgabendindex_; + }; }; // namespace trklet #endif diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h index 2559a22a96fbf..7b898f1b2e7a4 100644 --- a/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h +++ b/L1Trigger/TrackFindingTracklet/interface/ProjectionRouter.h @@ -15,7 +15,7 @@ namespace trklet { class ProjectionRouter : public ProcessBase { public: - ProjectionRouter(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + ProjectionRouter(std::string name, Settings const& settings, Globals* global); ~ProjectionRouter() override = default; diff --git a/L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h b/L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h index 4b8a445146d96..e34786d37587e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h +++ b/L1Trigger/TrackFindingTracklet/interface/ProjectionTemp.h @@ -14,7 +14,11 @@ namespace trklet { int projfinerz, unsigned int projfinephi, unsigned int iphi, - bool usesecond, + int shift, + bool usefirstMinus, + bool usefirstPlus, + bool usesecondMinus, + bool usesecondPlus, bool isPSseed); ProjectionTemp(); @@ -27,7 +31,8 @@ namespace trklet { int projfinerz() const { return projfinerz_; } unsigned int projfinephi() const { return projfinephi_; } unsigned int iphi() const { return iphi_; } - bool usesecond() const { return usesecond_; } + int shift() const { return shift_; } + bool use(unsigned int nextrzbin, unsigned int nextiphibin) const { return use_[nextrzbin][nextiphibin]; } bool isPSseed() const { return isPSseed_; } private: @@ -37,7 +42,10 @@ namespace trklet { unsigned int projfinerz_; unsigned int projfinephi_; unsigned int iphi_; - bool usesecond_; + int shift_; + //Projection may use two bins in rz and phi if the projection is near a boundary + //The use_[rz][phi] array indicates which bins are used. + bool use_[2][2]; bool isPSseed_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h b/L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h index 833c41e30a7b4..6600a3de15d98 100644 --- a/L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h +++ b/L1Trigger/TrackFindingTracklet/interface/PurgeDuplicate.h @@ -19,14 +19,14 @@ namespace trklet { class PurgeDuplicate : public ProcessBase { public: - PurgeDuplicate(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + PurgeDuplicate(std::string name, Settings const& settings, Globals* global); ~PurgeDuplicate() override = default; void addOutput(MemoryBase* memory, std::string output) override; void addInput(MemoryBase* memory, std::string input) override; - void execute(std::vector& outputtracks_); + void execute(std::vector& outputtracks_, unsigned int iSector); private: double getPhiRes(Tracklet* curTracklet, const Stub* curStub); diff --git a/L1Trigger/TrackFindingTracklet/interface/LayerResidual.h b/L1Trigger/TrackFindingTracklet/interface/Residual.h similarity index 61% rename from L1Trigger/TrackFindingTracklet/interface/LayerResidual.h rename to L1Trigger/TrackFindingTracklet/interface/Residual.h index 1c2cf303ae479..8eb934bee4d92 100644 --- a/L1Trigger/TrackFindingTracklet/interface/LayerResidual.h +++ b/L1Trigger/TrackFindingTracklet/interface/Residual.h @@ -1,5 +1,5 @@ -#ifndef L1Trigger_TrackFindingTracklet_interface_LayerResidual_h -#define L1Trigger_TrackFindingTracklet_interface_LayerResidual_h +#ifndef L1Trigger_TrackFindingTracklet_interface_Residual_h +#define L1Trigger_TrackFindingTracklet_interface_Residual_h #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" @@ -10,22 +10,21 @@ namespace trklet { class Settings; class Stub; - class LayerResidual { + class Residual { public: - LayerResidual() { valid_ = false; } + Residual() { valid_ = false; } - ~LayerResidual() = default; + ~Residual() = default; void init(Settings const& settings, - int layer, + unsigned int layerdisk, int iphiresid, - int izresid, + int irzresid, int istubid, double phiresid, - double zresid, + double rzresid, double phiresidapprox, - double zresidapprox, - double rstub, + double rzresidapprox, const Stub* stubptr); bool valid() const { return valid_; } @@ -35,9 +34,9 @@ namespace trklet { return fpgaphiresid_; }; - const FPGAWord& fpgazresid() const { + const FPGAWord& fpgarzresid() const { assert(valid_); - return fpgazresid_; + return fpgarzresid_; }; const FPGAWord& fpgastubid() const { @@ -50,9 +49,9 @@ namespace trklet { return phiresid_; }; - double zresid() const { + double rzresid() const { assert(valid_); - return zresid_; + return rzresid_; }; double phiresidapprox() const { @@ -60,16 +59,11 @@ namespace trklet { return phiresidapprox_; }; - double zresidapprox() const { + double rzresidapprox() const { assert(valid_); - return zresidapprox_; + return rzresidapprox_; }; - double rstub() const { - assert(valid_); - return rstub_; - } - const Stub* stubptr() const { assert(valid_); return stubptr_; @@ -78,19 +72,18 @@ namespace trklet { protected: bool valid_; - int layer_; + unsigned int layerdisk_; FPGAWord fpgaphiresid_; - FPGAWord fpgazresid_; + FPGAWord fpgarzresid_; FPGAWord fpgastubid_; double phiresid_; - double zresid_; + double rzresid_; double phiresidapprox_; - double zresidapprox_; + double rzresidapprox_; - double rstub_; const Stub* stubptr_; }; diff --git a/L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h b/L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h index 0ef6024854059..74dfc0d22d3fd 100644 --- a/L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h +++ b/L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h @@ -10,47 +10,10 @@ #include #include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1SimTrack.h" namespace trklet { - class L1SimTrack { - public: - L1SimTrack(); - L1SimTrack(int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz); - ~L1SimTrack() = default; - - void write(std::ofstream& out); - void write(std::ostream& out); - - int eventid() const { return eventid_; } - int trackid() const { return trackid_; } - int type() const { return type_; } - double pt() const { return pt_; } - double eta() const { return eta_; } - double phi() const { return phi_; } - double vx() const { return vx_; } - double vy() const { return vy_; } - double vz() const { return vz_; } - double dxy() const { return -vx() * sin(phi()) + vy() * cos(phi()); } - double d0() const { return -dxy(); } - int charge() const { - if (type_ == 11 || type_ == 13 || type_ == -211 || type_ == -321 || type_ == -2212) - return -1; - return 1; - } - - private: - int eventid_; - int trackid_; - int type_; - double pt_; - double eta_; - double phi_; - double vx_; - double vy_; - double vz_; - }; - class SLHCEvent { public: SLHCEvent() { @@ -60,32 +23,32 @@ namespace trklet { SLHCEvent(std::istream& in); ~SLHCEvent() = default; - void setIPx(double x) { x_offset_ = x; } - void setIPy(double y) { y_offset_ = y; } - void setEventNum(int eventnum) { eventnum_ = eventnum; } void addL1SimTrack( int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz); - bool addStub(int layer, - int ladder, - int module, - int strip, - int eventid, - std::vector tps, - double pt, - double bend, + bool addStub(std::string DTClink, + int region, + int layerdisk, + std::string stubword, + int isPSmodule, + int isFlipped, double x, double y, double z, - int isPSmodule, - int isFlipped); + double bend, + double strip, + std::vector tps); const L1TStub& lastStub() const { return stubs_.back(); } + void setIP(double x, double y) { + ipx_ = x; + ipy_ = y; + } + void write(std::ofstream& out); - void write(std::ostream& out); unsigned int layersHit(int tpid, int& nlayers, int& ndisks); @@ -99,15 +62,11 @@ namespace trklet { int eventnum() const { return eventnum_; } - int getSimtrackFromSimtrackid(int simtrackid, int eventid = 0) const; - private: int eventnum_; std::vector simtracks_; std::vector stubs_; - - double x_offset_{0.0}; - double y_offset_{0.0}; + double ipx_, ipy_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/Sector.h b/L1Trigger/TrackFindingTracklet/interface/Sector.h index fdddb08af0055..ab3d67bdb39e7 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Sector.h +++ b/L1Trigger/TrackFindingTracklet/interface/Sector.h @@ -11,6 +11,7 @@ #include #include #include +#include namespace trklet { @@ -23,8 +24,10 @@ namespace trklet { class Stub; //Memory modules + class DTCLinkMemory; class InputLinkMemory; class AllStubsMemory; + class AllInnerStubsMemory; class VMStubsTEMemory; class VMStubsMEMemory; class StubPairsMemory; @@ -39,6 +42,7 @@ namespace trklet { class CleanTrackMemory; //Processing modules + class InputRouter; class VMRouter; class VMRouterCM; class TrackletEngine; @@ -56,10 +60,13 @@ namespace trklet { class Sector { public: - Sector(unsigned int i, Settings const& settings, Globals* globals); + Sector(Settings const& settings, Globals* globals); ~Sector(); + //Set the sector + void setSector(unsigned int isector); + bool addStub(L1TStub stub, std::string dtc); //TODO - should be pointer or string // Creates all required memory modules based on wiring map (args: module type, module instance) @@ -75,10 +82,12 @@ namespace trklet { ProcessBase* getProc(std::string procName); MemoryBase* getMem(std::string memName); - void writeInputStubs(bool first); + void writeDTCStubs(bool first); + void writeIRStubs(bool first); void writeVMSTE(bool first); void writeVMSME(bool first); void writeAS(bool first); + void writeAIS(bool first); void writeSP(bool first); void writeST(bool first); void writeTPAR(bool first); @@ -93,6 +102,7 @@ namespace trklet { void clean(); // execute the different tracklet processing modules + void executeIR(); void executeVMR(); void executeTE(); void executeTED(); @@ -105,7 +115,7 @@ namespace trklet { void executeMC(); void executeMP(); void executeFT(); - void executePD(std::vector& tracks); + void executePD(std::vector& tracks); std::vector getAllTracklets() const; std::vector getStubs() const; @@ -137,8 +147,10 @@ namespace trklet { std::map Memories_; std::vector MemoriesV_; + std::vector > DL_; std::vector > IL_; std::vector > AS_; + std::vector > AIS_; std::vector > VMSTE_; std::vector > VMSME_; std::vector > SP_; @@ -153,6 +165,7 @@ namespace trklet { std::vector > CT_; std::map Processes_; + std::vector > IR_; std::vector > VMR_; std::vector > VMRCM_; std::vector > TE_; diff --git a/L1Trigger/TrackFindingTracklet/interface/Settings.h b/L1Trigger/TrackFindingTracklet/interface/Settings.h index 1e045222c4ada..0759b7ebcf279 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Settings.h +++ b/L1Trigger/TrackFindingTracklet/interface/Settings.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -16,18 +18,33 @@ namespace trklet { constexpr unsigned int N_SECTOR = 9; // # of phi sectors for L1TK processing - constexpr int N_LAYER = 6; // # of barrel layers assumed - constexpr int N_DISK = 5; // # of endcap disks assumed - constexpr unsigned int N_PSLAYER = 3; // # of barrel PS layers assumed - constexpr unsigned int N_SEED = 12; // # of tracklet+triplet seeds + constexpr int N_LAYER = 6; // # of barrel layers assumed + constexpr int N_DISK = 5; // # of endcap disks assumed + 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_DSS_MOD = 5; // # of rings with 2S modules per disk - constexpr unsigned int NRINVBITS = 5; //number of bit for rinv in bend match table - constexpr unsigned int NFINERZBITS = 3; //number of bit for r or z within a r/z bin + constexpr unsigned int N_BENDBITS_PS = 3; // Number of bend bits for PS modules + constexpr unsigned int N_BENDBITS_2S = 4; // Number of bend bits for 2S modules + + constexpr unsigned int NRINVBITS = 5; //number of bit for rinv in bend match table + constexpr unsigned int NFINERZBITS = 3; //number of bit for r or z within a r/z bin + constexpr unsigned int NFINEPHIBITS = 3; //number of bits for phi within a vm bin + constexpr unsigned int N_RZBITS = 3; //number of bit for the r/z bins + + constexpr unsigned int N_VMSTUBSMAX = 15; // maximum number of stubs in VM bin + constexpr unsigned int N_BITSMEMADDRESS = 7; // Number of bits for address in memories constexpr double sixth = 1.0 / 6.0; //Commonly used factor + constexpr double third = 1.0 / 3.0; //Commonly used factor + constexpr double VMROUTERCUTZL2 = 50.0; //Min L2 z for inner allstub + constexpr double VMROUTERCUTZL1L3L5 = 95.0; //Max z for inner barrel layers + constexpr double VMROUTERCUTZL1 = 70.0; //Max z for L1 barrel seeding + constexpr double VMROUTERCUTRD1D3 = 55.0; //Max r for disk seeds + class Settings { public: Settings() { @@ -42,9 +59,6 @@ namespace trklet { ~Settings() = default; // processing & memory modules, wiring, etc. - std::string DTCLinkFile() const { return DTCLinkFile_; } - std::string const& moduleCablingFile() const { return moduleCablingFile_; } - std::string const& DTCLinkLayerDiskFile() const { return DTCLinkLayerDiskFile_; } std::string const& fitPatternFile() const { return fitPatternFile_; } std::string const& processingModulesFile() const { return processingModulesFile_; } std::string const& memoryModulesFile() const { return memoryModulesFile_; } @@ -52,11 +66,6 @@ namespace trklet { std::string const& tableTEDFile() const { return tableTEDFile_; } std::string const& tableTREFile() const { return tableTREFile_; } - void setDTCLinkFile(std::string DTCLinkFileName) { DTCLinkFile_ = DTCLinkFileName; } - void setModuleCablingFile(std::string moduleCablingFileName) { moduleCablingFile_ = moduleCablingFileName; } - void setDTCLinkLayerDiskFile(std::string DTCLinkLayerDiskFileName) { - DTCLinkLayerDiskFile_ = DTCLinkLayerDiskFileName; - } void setFitPatternFile(std::string fitPatternFileName) { fitPatternFile_ = fitPatternFileName; } void setProcessingModulesFile(std::string processingModulesFileName) { processingModulesFile_ = processingModulesFileName; @@ -117,8 +126,6 @@ namespace trklet { double half2SmoduleWidth() const { return half2SmoduleWidth_; } - double bendcutte(unsigned int inner, unsigned int iSeed) const { return bendcutte_[inner][iSeed]; } - double bendcutme(unsigned int layerdisk) const { return bendcutme_[layerdisk]; } int nfinephi(unsigned int inner, unsigned int iSeed) const { return nfinephi_[inner][iSeed]; } double nphireg(unsigned int inner, unsigned int iSeed) const { if (combined_) { @@ -131,6 +138,16 @@ namespace trklet { return lutwidthtabextended_[inner][iSeed]; } + unsigned int seedlayers(int inner, int seed) const { + int layerdisk = seedlayers_[seed][inner]; + assert(layerdisk >= 0); + return layerdisk; + } + + unsigned int teunits(unsigned int iSeed) const { return teunits_[iSeed]; } + + unsigned int NTC(int seed) const { return ntc_[seed]; } + unsigned int projlayers(unsigned int iSeed, unsigned int i) const { return projlayers_[iSeed][i]; } unsigned int projdisks(unsigned int iSeed, unsigned int i) const { return projdisks_[iSeed][i]; } double rphimatchcut(unsigned int iSeed, unsigned int ilayer) const { return rphimatchcut_[ilayer][iSeed]; } @@ -166,8 +183,10 @@ namespace trklet { bool writeMem() const { return writeMem_; } bool writeTable() const { return writeTable_; } - std::string const& memPath() const { return memPath_; } - std::string const& tablePath() const { return tablePath_; } + bool writeConfig() const { return writeConfig_; } + + std::string memPath() const { return memPath_; } + std::string tablePath() const { return tablePath_; } bool writeVerilog() const { return writeVerilog_; } bool writeHLS() const { return writeHLS_; } @@ -256,9 +275,10 @@ namespace trklet { void setNbitsseedextended(unsigned int nbitsseed) { nbitsseedextended_ = nbitsseed; } double dphisectorHG() const { - return 2 * M_PI / N_SECTOR + - 2 * std::max(std::abs(asin(0.5 * rinvmax() * rmean(0)) - asin(0.5 * rinvmax() * rcrit_)), - std::abs(asin(0.5 * rinvmax() * rmean(5)) - asin(0.5 * rinvmax() * rcrit_))); + //These values are used in the DTC emulation code. + double rsectmin = 21.8; + double rsectmax = 112.7; + return 2 * M_PI / N_SECTOR + rinvmax() * std::max(rcrit_ - rsectmin, rsectmax - rcrit_); } double rcrit() const { return rcrit_; } @@ -272,10 +292,13 @@ namespace trklet { double phicritmaxmc() const { return phicritmax() + dphicritmc_; } double kphi() const { return dphisectorHG() / (1 << nphibitsstub(0)); } - double kphi1() const { return dphisectorHG() / (1 << nphibitsstub(5)); } + double kphi1() const { return dphisectorHG() / (1 << nphibitsstub(N_LAYER - 1)); } + double kphi(unsigned int layerdisk) const { return dphisectorHG() / (1 << nphibitsstub(layerdisk)); } - double kz() const { return 2 * zlength_ / (1 << nzbitsstub_[0]); } - double kr() const { return rmaxdisk_ / (1 << nrbitsstub_[6]); } + 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 krbarrel() const { return 2.0 * drmax() / (1 << nrbitsstub_[0]); } double maxrinv() const { return maxrinv_; } double maxd0() const { return maxd0_; } @@ -363,17 +386,48 @@ namespace trklet { double kz0pars() const { return kz(); } double kd0pars() const { return kd0(); } - double kphider() const { return krinvpars() / (1 << phiderbitshift_); } - double kzder() const { return ktpars() / (1 << zderbitshift_); } + double kphider() const { return kphi() / kr() / 256; } + double kphiderdisk() const { return kphi() / kr() / 128; } + double kzder() const { return 1.0 / 64; } + double krder() const { return 1.0 / 128; } //This is a 'historical accident' and should be fixed so that we don't //have the factor if 2 double krprojshiftdisk() const { return 2 * kr(); } + double benddecode(int ibend, int layerdisk, bool isPSmodule) const { + if (layerdisk >= N_LAYER && (!isPSmodule)) + layerdisk += (N_LAYER - 1); + double bend = benddecode_[layerdisk][ibend]; + assert(bend < 99.0); + return bend; + } + + double bendcut(int ibend, int layerdisk, bool isPSmodule) const { + if (layerdisk >= N_LAYER && (!isPSmodule)) + layerdisk += (N_LAYER - 1); + double bendcut = bendcut_[layerdisk][ibend]; + if (bendcut <= 0.0) + std::cout << "bendcut : " << layerdisk << " " << ibend << " " << isPSmodule << std::endl; + assert(bendcut > 0.0); + return bendcut; + } + + const std::vector& dtcLayers(const std::string& dtcName) const { + auto iter=dtclayers_.find(dtcName); + assert(iter!=dtclayers_.end()); + return iter->second; + } + + double bendcutte(int ibend, int layerdisk, bool isPSmodule) const { return bendcut(ibend, layerdisk, isPSmodule); } + + double bendcutme(int ibend, int layerdisk, bool isPSmodule) const { + //FIXME temporary fix until phiprojderdisk bits adjusted. But requires coordinatin with HLS + double fact = (layerdisk < N_LAYER) ? 1.0 : 1.8; + return fact * bendcut(ibend, layerdisk, isPSmodule); + } + private: - std::string DTCLinkFile_; - std::string moduleCablingFile_; - std::string DTCLinkLayerDiskFile_; std::string fitPatternFile_; std::string processingModulesFile_; std::string memoryModulesFile_; @@ -419,11 +473,18 @@ namespace trklet { {{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2}}, {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1}}}}; - std::array, 2> bendcutte_{ - {{{1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25}}, //inner (2 = #stubs/tracklet) - {{1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25, 1.25}}}}; //outer - - std::array bendcutme_{{2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.5, 1.5, 1.5, 1.5, 1.5}}; + std::map > dtclayers_{{"PS10G_1", {0, 6, 8, 10}}, + {"PS10G_2", {0, 7, 9}}, + {"PS10G_3", {1, 7}}, + {"PS10G_4", {6, 8, 10}}, + {"PS_1", {2, 7}}, + {"PS_2", {2, 9}}, + {"2S_1", {3, 4}}, + {"2S_2", {4}}, + {"2S_3", {5}}, + {"2S_4", {5, 8}}, + {"2S_5", {6, 9}}, + {"2S_6", {7, 10}}}; double rmindiskvm_{22.5}; double rmaxdiskvm_{67.0}; @@ -513,6 +574,8 @@ namespace trklet { int chisqphifactbits_{14}; int chisqzfactbits_{14}; + std::array teunits_{{5, 2, 5, 3, 3, 2, 3, 2, 0, 0, 0, 0}}; //teunits used by seed + std::array vmrlutzbits_{ {7, 7, 7, 7, 7, 7, 3, 3, 3, 3, 3}}; // zbits used by LUT in VMR std::array vmrlutrbits_{ @@ -545,6 +608,23 @@ namespace trklet { {{6, 6, 6, 6, 10, 10, 10, 10, 0, 0, 6, 0}}, {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6}}}}; + //layers/disks used by each seed + std::array, N_SEED> seedlayers_{{{{0, 1, -1}}, //L1L2 + {{1, 2, -1}}, //1 L2L3 + {{2, 3, -1}}, //2 L3L4 + {{4, 5, -1}}, //3 L5L6 + {{6, 7, -1}}, //4 D1D2 + {{8, 9, -1}}, //5 D3D4 + {{0, 6, -1}}, //6 L1D1 + {{1, 6, -1}}, //7 L2D1 + {{2, 3, 1}}, //8 L2L3L4 + {{4, 5, 3}}, //9 L4L5L6 + {{1, 2, 6}}, //10 L2L3D1 + {{6, 7, 1}}}}; //11 D1D2L2 + + //Number of tracklet calculators for the prompt seeding combinations + std::array ntc_{{12, 4, 4, 4, 4, 4, 8, 4, 0, 0, 0, 0}}; + //projection layers by seed index. For each seeding index (row) the list of layers that we consider projections to std::array, N_SEED> projlayers_{{{{3, 4, 5, 6}}, //0 L1L2 {{1, 4, 5, 6}}, //1 L2L3 @@ -568,7 +648,7 @@ namespace trklet { {{1, 2, 5}}, //5 D3D4 {{2, 3, 4, 5}}, //6 L1D1 {{2, 3, 4}}, //7 L2D1 - {{1, 2}}, //8 L2L3L4 + {{1, 2, 3}}, //8 L2L3L4 {{}}, //9 L4L5L6 {{2, 3, 4}}, //10 L2L3D1 {{3, 4}}}}; //11 D1D2L2 @@ -623,14 +703,53 @@ namespace trklet { {{3.6, 3.8, 0.0, 0.0, 3.6, 0.0, 3.5, 3.8, 0.0, 0.0, 3.0, 3.0}}, //disk 4 {{0.0, 0.0, 0.0, 0.0, 3.6, 3.4, 3.7, 0.0, 0.0, 0.0, 0.0, 3.0}}}}; //disk 5 + //returns the mean bend (in strips at a 1.8cm separation) for bendcode + std::array, 16> benddecode_{ + {{{0.0, 0.5, 0.7, 0.8, 89.9, -1.0, -0.9, -0.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //L1 PS + {{0.0, 0.7, 1.0, 1.5, 89.9, -1.5, -1.0, -0.7, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //L2 PS + {{0.0, 1.0, 1.8, 2.2, 89.9, -2.2, -1.8, -1.0, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //L3 PS + {{0.0, 0.7, 1.2, 1.8, 2.1, 2.6, 3.2, 3.5, 89.9, -3.5, -3.2, -2.6, -2.1, -1.8, -1.2, -0.7}}, //L4 2S + {{0.0, 0.8, 1.2, 1.8, 2.2, 3.2, 4.1, 4.4, 89.9, -4.4, -4.1, -3.2, -2.2, -1.8, -1.2, -0.8}}, //L5 2S + {{0.0, 0.9, 1.8, 2.8, 3.8, 4.5, 5.3, 5.9, 89.9, -5.9, -5.3, -4.5, -3.8, -2.8, -1.8, -0.9}}, //L6 2S + {{0.0, 0.8, 1.2, 2.0, 89.9, -2.0, -1.2, -0.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //D1 PS + {{0.0, 1.5, 1.8, 2.4, 89.9, -2.4, -1.8, -1.4, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //D2 PS + {{0.0, 1.7, 2.0, 2.2, 89.9, -2.2, -2.0, -1.7, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //D3 PS + {{0.0, 1.8, 2.0, 2.4, 89.9, -2.4, -2.0, -1.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //D4 PS + {{0.0, 2.0, 2.2, 2.4, 89.9, -2.4, -2.0, -1.8, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9, 99.9}}, //D5 PS + {{0.0, 1.8, 2.3, 2.5, 3.0, 3.9, 4.5, 5.2, 89.9, -5.2, -4.5, -3.9, -3.0, -2.5, -2.3, -1.8}}, //D1 2S + {{0.0, 2.0, 2.4, 2.9, 3.2, 4.0, 4.8, 5.2, 89.9, -5.2, -4.8, -4.0, -3.2, -2.9, -2.4, -2.0}}, //D2 2S + {{0.0, 2.0, 2.4, 2.7, 3.6, 3.7, 4.4, 4.6, 89.9, -4.6, -4.4, -3.7, -3.6, -2.7, -2.4, -2.0}}, //D3 2S + {{0.0, 2.0, 2.6, 3.2, 3.8, 4.0, 4.4, 4.4, 89.9, -4.4, -4.4, -4.0, -3.8, -3.2, -2.6, -2.0}}, //D4 2S + {{0.0, 2.0, 3.2, 3.4, 3.9, 3.9, 4.4, 4.4, 89.9, -4.4, -4.4, -3.9, -3.9, -3.4, -3.2, -2.0}}}}; //D5 2S + + //returns the bend 'cut' (in strips at a 1.8cm separation) for bendcode + std::array, 16> bendcut_{ + {{{1.5, 1.2, 0.8, 0.8, 99.9, 0.8, 0.8, 1.2, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //L1 PS + {{1.5, 1.3, 1.0, 1.0, 99.9, 1.0, 1.0, 1.3, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //L2 PS + {{1.6, 1.5, 1.0, 1.0, 99.9, 1.0, 1.0, 1.5, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //L3 PS + {{1.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}}, //L4 2S + {{1.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}}, //L5 2S + {{1.6, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 99.9, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}}, //L6 2S + {{1.8, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //D1 PS + {{1.8, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //D2 PS + {{1.8, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //D3 PS + {{2.2, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //D4 PS + {{2.2, 1.6, 1.6, 1.6, 99.9, 1.6, 1.6, 1.6, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0}}, //D5 PS + {{2.0, 1.2, 1.2, 1.2, 1.5, 1.5, 1.5, 1.5, 99.9, 1.5, 1.5, 1.5, 1.5, 1.2, 1.2, 1.2}}, //D1 2S + {{2.0, 1.2, 1.2, 1.2, 1.5, 1.5, 1.5, 1.5, 99.9, 1.5, 1.5, 1.5, 1.5, 1.2, 1.2, 1.2}}, //D2 2S + {{2.2, 1.5, 1.5, 1.5, 2.0, 2.0, 2.0, 2.0, 99.9, 2.0, 2.0, 2.0, 2.0, 1.5, 1.5, 1.5}}, //D3 2S + {{2.5, 1.5, 1.5, 2.0, 2.0, 2.0, 2.0, 2.0, 99.9, 2.0, 2.0, 2.0, 2.0, 2.0, 1.5, 1.5}}, //D4 2S + {{2.5, 1.5, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 99.9, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.5}}}}; //D5 2S + // Offset to the maximum number of steps in each processing step: // Set to 0 (default) means standard truncation // Set to large value, e.g. 10000, to disable truncation unsigned int maxstepoffset_{0}; //Number of processing steps for one event (108=18TM*240MHz/40MHz) - std::unordered_map maxstep_{{"Link", 108}, - {"VMR", 108}, + std::unordered_map maxstep_{{"IR", 168}, //IR will run at a higher clock speed to handle + //input links running at 25 Gbits/s + {"VMR", 108}, {"TE", 108}, {"TC", 108}, {"PR", 108}, @@ -641,37 +760,21 @@ namespace trklet { {"TRE", 108}}; // If set to true this will generate debub printout in text files - std::unordered_map writeMonitorData_{{"IL", false}, - {"TE", false}, - {"CT", false}, - {"HitPattern", false}, - {"ChiSq", false}, - {"Seeds", false}, - {"FT", false}, - {"Residuals", false}, - {"MC", false}, - {"MP", false}, - {"ME", false}, - {"AP", false}, - {"VMP", false}, - {"NMatches", false}, - {"TrackProjOcc", false}, - {"TC", false}, - {"Pars", false}, - {"TPars", false}, - {"TPD", false}, - {"TrackletPars", false}, - {"TED", false}, - {"TP", false}, - {"TRE", false}, - {"VMR", false}, - {"StubsLayer", false}, - {"StubsLayerSector", false}, - {"HitEff", false}, - {"MatchEff", false}, - {"Cabling", false}, - {"IFit", false}, - {"AS", false}}; + std::unordered_map writeMonitorData_{{"IL", false}, {"TE", false}, + {"CT", false}, {"HitPattern", false}, + {"ChiSq", false}, {"Seeds", false}, + {"FT", false}, {"Residuals", false}, + {"StubBend", false}, {"MC", false}, + {"MP", false}, {"ME", false}, + {"AP", false}, {"VMP", false}, + {"TrackProjOcc", false}, {"TC", false}, + {"Pars", false}, {"TPars", false}, + {"TPD", false}, {"TrackletPars", false}, + {"TED", false}, {"TP", false}, + {"TRE", false}, {"VMR", false}, + {"StubsLayer", false}, {"StubsLayerSector", false}, + {"HitEff", false}, {"MatchEff", false}, + {"IFit", false}, {"AS", false}}; std::array rDSSinner_mod_{{68.9391, 78.7750, 85.4550, 96.3150, 102.3160}}; std::array rDSSouter_mod_{{66.4903, 76.7750, 84.4562, 94.9920, 102.3160}}; @@ -688,8 +791,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 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/interface/Stub.h b/L1Trigger/TrackFindingTracklet/interface/Stub.h index 8b5536d270d84..90c8f7f1dbd80 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Stub.h +++ b/L1Trigger/TrackFindingTracklet/interface/Stub.h @@ -13,11 +13,13 @@ namespace trklet { + class Globals; + class Stub { public: Stub(Settings const& settings); - Stub(L1TStub& stub, Settings const& settings, double phiminsec, double phimaxsec); + Stub(L1TStub& stub, Settings const& settings, Globals& globals); ~Stub() = default; @@ -30,13 +32,22 @@ namespace trklet { if (isPSmodule()) { return r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + bend_.str(); } else { - return "000" + r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + alphanew_.str() + "|" + bend_.str(); + return "000" + r_.str() + "|" + z_.str() + "|" + phi_.str() + "|" + alpha_.str() + "|" + bend_.str(); } } } std::string strbare() const { return bend_.str() + r_.str() + z_.str() + phi_.str(); } + std::string strinner() const { + unsigned int nbitsfinephi = 8; + FPGAWord finephi( + phicorr_.bits(phicorr_.nbits() - nbitsfinephi, nbitsfinephi), nbitsfinephi, true, __LINE__, __FILE__); + return str() + "|" + stubindex_.str() + "|" + finephi.str(); + } + + FPGAWord allStubIndex() const { return stubindex_; } + unsigned int phiregionaddress() const; std::string phiregionaddressstr() const; @@ -50,17 +61,14 @@ namespace trklet { const FPGAWord& z() const { return z_; } const FPGAWord& phi() const { return phi_; } const FPGAWord& phicorr() const { return phicorr_; } - const FPGAWord& alphanew() const { return alphanew_; } + const FPGAWord& alpha() const { return alpha_; } const FPGAWord& stubindex() const { return stubindex_; } const FPGAWord& layer() const { return layer_; } const FPGAWord& disk() const { return disk_; } unsigned int layerdisk() const; - bool isBarrel() const { return layer_.value() != -1; } - bool isDisk() const { return disk_.value() != 0; } - - bool isPSmodule() const { return isBarrel() ? (layer_.value() < (int)N_PSLAYER) : (r_.value() > 10); } + bool isPSmodule() const { return (layerdisk_ < N_LAYER) ? (layerdisk_ < N_PSLAYER) : (r_.value() > 10); } double rapprox() const; double zapprox() const; @@ -70,13 +78,17 @@ namespace trklet { const L1TStub* l1tstub() const { return l1tstub_; } void setl1tstub(L1TStub* l1tstub) { l1tstub_ = l1tstub; } + bool isBarrel() const { return layerdisk_ < N_LAYER; } + private: + unsigned int layerdisk_; + FPGAWord layer_; FPGAWord disk_; FPGAWord r_; FPGAWord z_; FPGAWord phi_; - FPGAWord alphanew_; + FPGAWord alpha_; FPGAWord bend_; diff --git a/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h b/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h index cc219691a61ff..9f87f84ee490f 100644 --- a/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h @@ -12,7 +12,7 @@ namespace trklet { class StubPairsMemory : public MemoryBase { public: - StubPairsMemory(std::string name, Settings const& settings, unsigned int iSector); + StubPairsMemory(std::string name, Settings const& settings); ~StubPairsMemory() override = default; @@ -39,7 +39,7 @@ namespace trklet { tedNames_.clear(); } - void writeSP(bool first); + void writeSP(bool first, unsigned int iSector); private: std::vector > stubs_; diff --git a/L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h b/L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h index ecb2163251a38..00e94404feadd 100644 --- a/L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/StubTripletsMemory.h @@ -13,7 +13,7 @@ namespace trklet { class StubTripletsMemory : public MemoryBase { public: - StubTripletsMemory(std::string name, Settings const& settings, unsigned int iSector); + StubTripletsMemory(std::string name, Settings const& settings); ~StubTripletsMemory() override = default; @@ -35,7 +35,7 @@ namespace trklet { stubs3_.clear(); } - void writeST(bool first); + void writeST(bool first, unsigned int iSector); private: std::vector stubs1_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TETableBase.h b/L1Trigger/TrackFindingTracklet/interface/TETableBase.h index 754ac6345c4c4..c12a818eb35f7 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TETableBase.h +++ b/L1Trigger/TrackFindingTracklet/interface/TETableBase.h @@ -2,6 +2,7 @@ #define L1Trigger_TrackFindingTracklet_interface_TETableBase_h #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" #include #include @@ -21,7 +22,7 @@ namespace trklet { virtual void lookup(int, int) {} - void writeVMTable(std::string name, bool positive = true); + void writeVMTable(const std::string& dir, const std::string& name, bool positive = true); protected: Settings const& settings_; diff --git a/L1Trigger/TrackFindingTracklet/interface/Track.h b/L1Trigger/TrackFindingTracklet/interface/Track.h index cbf27a81c3f63..bd95a2a6cc43c 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Track.h +++ b/L1Trigger/TrackFindingTracklet/interface/Track.h @@ -24,7 +24,7 @@ namespace trklet { double chisqrz, int hitpattern, std::map stubID, - const std::vector& l1stub, + const std::vector& l1stub, int seed); ~Track() = default; @@ -39,7 +39,7 @@ namespace trklet { int ichisq() const { return ichisqrphi_ + ichisqrz_; } const std::map& stubID() const { return stubID_; } - const std::vector& stubs() const { return l1stub_; } + const std::vector& stubs() const { return l1stub_; } //These are not used? Should be removed? const std::vector>& stubIDpremerge() const { return stubIDpremerge_; } @@ -69,7 +69,7 @@ namespace trklet { int nPSstubs() const { int npsstubs = 0; for (auto istub : l1stub_) { - if (istub->layer() < N_PSLAYER) + if (istub.layer() < N_PSLAYER) npsstubs++; } return npsstubs; @@ -88,7 +88,7 @@ namespace trklet { std::vector> stubIDpremerge_; std::vector> stubIDprefit_; std::map stubID_; - std::vector l1stub_; + std::vector l1stub_; unsigned int nstubs_; int seed_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h index 6775080971f1a..f8c9335abd8fa 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackFitMemory.h @@ -14,7 +14,7 @@ namespace trklet { class TrackFitMemory : public MemoryBase { public: - TrackFitMemory(std::string name, Settings const& settings, unsigned int iSector, double phimin, double phimax); + TrackFitMemory(std::string name, Settings const& settings, double phimin, double phimax); ~TrackFitMemory() override = default; @@ -36,7 +36,7 @@ namespace trklet { stubidslists_.clear(); } - void writeTF(bool first); + void writeTF(bool first, unsigned int iSector); private: double phimin_; diff --git a/L1Trigger/TrackFindingTracklet/interface/Tracklet.h b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h index 870dd822bbbd0..30e1ae3900ec3 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Tracklet.h +++ b/L1Trigger/TrackFindingTracklet/interface/Tracklet.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" @@ -13,10 +14,8 @@ #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" #include "L1Trigger/TrackFindingTracklet/interface/Track.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackPars.h" -#include "L1Trigger/TrackFindingTracklet/interface/LayerProjection.h" -#include "L1Trigger/TrackFindingTracklet/interface/DiskProjection.h" -#include "L1Trigger/TrackFindingTracklet/interface/LayerResidual.h" -#include "L1Trigger/TrackFindingTracklet/interface/DiskResidual.h" +#include "L1Trigger/TrackFindingTracklet/interface/Projection.h" +#include "L1Trigger/TrackFindingTracklet/interface/Residual.h" #include "L1Trigger/TrackFindingTracklet/interface/Util.h" namespace trklet { @@ -28,9 +27,7 @@ namespace trklet { class Tracklet { public: Tracklet(Settings const& settings, - const L1TStub* innerStub, - const L1TStub* middleStub, - const L1TStub* outerStub, + unsigned int iSeed, const Stub* innerFPGAStub, const Stub* middleFPGAStub, const Stub* outerFPGAStub, @@ -49,8 +46,7 @@ namespace trklet { int id0, int iz0, int it, - LayerProjection layerprojs[N_PROJ], - DiskProjection diskprojs[N_PROJ], + Projection projs[N_LAYER + N_DISK], bool disk, bool overlap = false); @@ -62,13 +58,10 @@ namespace trklet { bool stubtruthmatch(const L1TStub* stub); - const L1TStub* innerStub() { return innerStub_; } const Stub* innerFPGAStub() { return innerFPGAStub_; } - const L1TStub* middleStub() { return middleStub_; } const Stub* middleFPGAStub() { return middleFPGAStub_; } - const L1TStub* outerStub() { return outerStub_; } const Stub* outerFPGAStub() { return outerFPGAStub_; } std::string addressstr(); @@ -86,320 +79,38 @@ namespace trklet { std::string trackletprojstrlayer(int layer) const { return trackletprojstr(layer); } std::string trackletprojstrdisk(int disk) const { return trackletprojstrD(disk); } - bool validProj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].valid(); + bool validProj(int layerdisk) const { + assert(layerdisk >= 0 && layerdisk < N_LAYER + N_DISK); + return proj_[layerdisk].valid(); } - const FPGAWord& fpgaphiprojder(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgaphiprojder(); + Projection& proj(int layerdisk) { + assert(validProj(layerdisk)); + return proj_[layerdisk]; } - const FPGAWord& fpgazproj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgazproj(); - } - - const FPGAWord& fpgaphiproj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgaphiproj(); - } - - const FPGAWord& fpgazprojder(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgazprojder(); - } - - int zbin1projvm(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgazbin1projvm().value(); - } - - int zbin2projvm(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgazbin2projvm().value(); - } - - int finezvm(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgafinezvm().value(); - } - - int rbin1projvm(int disk) const { - assert(disk > 0 && disk <= N_DISK); - return diskproj_[disk - 1].fpgarbin1projvm().value(); - } - - int rbin2projvm(int disk) const { - assert(disk > 0 && disk <= N_DISK); - return diskproj_[disk - 1].fpgarbin2projvm().value(); - } - - int finervm(int disk) const { - assert(disk > 0 && disk <= N_DISK); - return diskproj_[disk - 1].fpgafinervm().value(); - } - - int phiprojvm(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgaphiprojvm().value(); - } - - int zprojvm(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].fpgazprojvm().value(); - } - - double phiproj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].phiproj(); - } - - double phiprojder(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].phiprojder(); - } - - double zproj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].zproj(); - } - - double zprojder(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].zprojder(); - } - - double zprojapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].zprojapprox(); - } - - double zprojderapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].zprojderapprox(); - } - - double phiprojapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].phiprojapprox(); - } - - double phiprojderapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].phiprojderapprox(); - } - - double rproj(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerproj_[layer - 1].rproj(); - } - - double rstub(int layer) { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].rstub(); - } - - //Disks residuals - - bool validProjDisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].valid(); - } - - const FPGAWord& fpgaphiresiddisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].fpgaphiresid(); - } - - const FPGAWord& fpgarresiddisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].fpgarresid(); - } - - double phiresiddisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].phiresid(); - } - - double rresiddisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].rresid(); - } - - double phiresidapproxdisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].phiresidapprox(); - } - - double rresidapproxdisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].rresidapprox(); - } - - double zstubdisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].zstub(); - } - - void setBendIndex(int bendIndex, int disk) { - assert(abs(disk) <= N_DISK); - diskproj_[abs(disk) - 1].setBendIndex(bendIndex); - } - - const FPGAWord& getBendIndex(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].getBendIndex(); - } - - double alphadisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].alpha(); - } - - const FPGAWord& ialphadisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].ialpha(); - } - - const FPGAWord& fpgaphiprojdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].fpgaphiproj(); - } - - const FPGAWord& fpgaphiprojderdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].fpgaphiprojder(); - } - - const FPGAWord& fpgarprojdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].fpgarproj(); - } - - const FPGAWord& fpgarprojderdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].fpgarprojder(); - } - - double phiprojapproxdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].phiprojapprox(); - } - - double phiprojderapproxdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].phiprojderapprox(); - } - - double rprojapproxdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].rprojapprox(); - } - - double rprojderapproxdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].rprojderapprox(); - } - - double phiprojdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].phiproj(); - } - - double phiprojderdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].phiprojder(); - } - - double rprojdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].rproj(); - } - - double rprojderdisk(int disk) const { - assert(abs(disk) <= N_DISK); - return diskproj_[abs(disk) - 1].rprojder(); - } - - bool matchdisk(int disk) { - assert(abs(disk) <= N_DISK); - return diskresid_[abs(disk) - 1].valid(); - } - - void addMatch(int layer, + void addMatch(unsigned int layerdisk, int ideltaphi, - int ideltaz, + int ideltarz, double dphi, - double dz, + double drz, double dphiapprox, - double dzapprox, + double drzapprox, int stubid, - double rstub, const trklet::Stub* stubptr); - void addMatchDisk(int disk, - int ideltaphi, - int ideltar, - double dphi, - double dr, - double dphiapprox, - double drapprox, - double alpha, - int stubid, - double zstub, - const trklet::Stub* stubptr); - - int nMatches(); - int nMatchesDisk(); - - bool match(int layer) { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].valid(); - } - std::string fullmatchstr(int layer); std::string fullmatchdiskstr(int disk); - bool validResid(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].valid(); + bool match(unsigned int layerdisk) { + assert(layerdisk < N_LAYER + N_DISK); + return resid_[layerdisk].valid(); } - const trklet::Stub* stubptr(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].stubptr(); - } - - double phiresid(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].phiresid(); - } - - double phiresidapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].phiresidapprox(); - } - - double zresid(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].zresid(); - } - - double zresidapprox(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].zresidapprox(); - } - - const FPGAWord& fpgaphiresid(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].fpgaphiresid(); - } - - const FPGAWord& fpgazresid(int layer) const { - assert(layer > 0 && layer <= N_LAYER); - return layerresid_[layer - 1].fpgazresid(); + const Residual& resid(unsigned int layerdisk) { + assert(layerdisk < N_LAYER + N_DISK); + assert(resid_[layerdisk].valid()); + return resid_[layerdisk]; } std::vector getL1Stubs(); @@ -485,7 +196,6 @@ namespace trklet { int layer() const; int disk() const; - int disk2() const; bool isBarrel() const { return barrel_; } bool isOverlap() const { return overlap_; } @@ -501,18 +211,16 @@ namespace trklet { int TCID() const { return TCIndex_ * (1 << settings_.nbitstrackletindex()) + trackletIndex_; } - const int getISeed() const; - const int getITC() const; + int getISeed() const; + int getITC() const; void setTrackIndex(int index); - const int trackIndex() const; + int trackIndex() const; unsigned int PSseed() const { return ((layer() == 1) || (layer() == 2) || (disk() != 0)) ? 1 : 0; } unsigned int seedIndex() const { return seedIndex_; } - unsigned int calcSeedIndex() const; - private: unsigned int seedIndex_; @@ -526,10 +234,6 @@ namespace trklet { const Stub* middleFPGAStub_; const Stub* outerFPGAStub_; - const L1TStub* innerStub_; - const L1TStub* middleStub_; - const L1TStub* outerStub_; - int trackletIndex_; int TCIndex_; int trackIndex_; @@ -561,11 +265,9 @@ namespace trklet { std::unique_ptr fpgatrack_; - LayerProjection layerproj_[N_LAYER]; - DiskProjection diskproj_[N_DISK]; + Projection proj_[N_LAYER + N_DISK]; - LayerResidual layerresid_[N_LAYER]; - DiskResidual diskresid_[N_DISK]; + Residual resid_[N_LAYER + N_DISK]; Settings const& settings_; }; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h index 16d65ae9518b8..a271bab238d69 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculator.h @@ -19,7 +19,7 @@ namespace trklet { class TrackletCalculator : public TrackletCalculatorBase { public: - TrackletCalculator(std::string name, Settings const& settings, Globals* globals, unsigned int iSector); + TrackletCalculator(std::string name, Settings const& settings, Globals* globals); ~TrackletCalculator() override = default; @@ -27,7 +27,7 @@ namespace trklet { void addOutput(MemoryBase* memory, std::string output) override; void addInput(MemoryBase* memory, std::string input) override; - void execute(); + void execute(unsigned int iSector, double phimin, double phimax); private: int iTC_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h index e58c5eb340adb..4638b07f5e5a9 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorBase.h @@ -17,7 +17,7 @@ namespace trklet { class TrackletCalculatorBase : public ProcessBase { public: - TrackletCalculatorBase(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + TrackletCalculatorBase(std::string name, Settings const& settings, Globals* global); ~TrackletCalculatorBase() override = default; @@ -131,6 +131,9 @@ namespace trklet { int TCIndex_; + unsigned int iSector_; + double phimin_, phimax_; + TrackletParametersMemory* trackletpars_; //First index is layer/disk second is phi region diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h index 541d7043dfc60..9bc51a81d34c8 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletCalculatorDisplaced.h @@ -19,7 +19,7 @@ namespace trklet { class TrackletCalculatorDisplaced : public ProcessBase { public: - TrackletCalculatorDisplaced(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + TrackletCalculatorDisplaced(std::string name, Settings const& settings, Globals* global); ~TrackletCalculatorDisplaced() override = default; @@ -28,7 +28,7 @@ namespace trklet { void addOutput(MemoryBase* memory, std::string output) override; void addInput(MemoryBase* memory, std::string input) override; - void execute(); + void execute(unsigned int iSector, double phimin, double phimax); void addDiskProj(Tracklet* tracklet, int disk); bool addLayerProj(Tracklet* tracklet, int layer); @@ -159,12 +159,16 @@ namespace trklet { int TCIndex_; int layer_; int disk_; + unsigned int iSeed_; double rproj_[N_LAYER - 2]; int lproj_[N_LAYER - 2]; double zproj_[N_DISK - 2]; int dproj_[N_DISK - 2]; double rzmeanInv_[N_DISK - 2]; + unsigned int iSector_; + double phimin_, phimax_; + std::vector toR_; std::vector toZ_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h new file mode 100644 index 0000000000000..f1734c35f2cd3 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h @@ -0,0 +1,273 @@ +// +// Class to build the configuration for the tracklet based track finding +// +// +// +#ifndef L1Trigger_TrackFindingTracklet_interface_TrackletConfigBuilder_h +#define L1Trigger_TrackFindingTracklet_interface_TrackletConfigBuilder_h + +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include +#include +#include +#include +#include +#include + +namespace trklet { + + class TrackletConfigBuilder { + public: + //Builds the configuration for the tracklet based track finding + TrackletConfigBuilder(const Settings& settings); + + //This method writes out the configuration as files + void writeAll(std::ostream& wires, std::ostream& memories, std::ostream& modules); + + private: + // + // Method to initialize the regions and VM in each layer + // + void initGeom(); + + // + // Builds the list of TE for each seeding combination + // + void buildTE(); + + // + // Builds the lists of TC for each seeding combination + // + void buildTC(); + + // + // Finds the projections needed for each seeding combination + // + void buildProjections(); + + // + // Helper function to determine if a pair of VM memories form valid TE + // + bool validTEPair(unsigned int iseed, unsigned int iTE1, unsigned int iTE2); + + // + // Helper fcn. to get the layers/disks for a seed + // + std::pair seedLayers(unsigned int iSeed); + + // + // Helper fcn to get the radii of the two layers in a seed + // + std::pair seedRadii(unsigned int iseed); + + // + // Helper fcn to return the phi range of a projection of a tracklet from a TC + // + std::pair seedPhiRange(double rproj, unsigned int iSeed, unsigned int iTC); + + // + // Helper function to calculate the phi position of a seed at radius r that is formed + // by two stubs at (r1,phi1) and (r2, phi2) + // + double phi(double r1, double phi1, double r2, double phi2, double r); + + // + // Helper function to calculate rinv for two stubs at (r1,phi1) and (r2,phi2) + // + double rinv(double r1, double phi1, double r2, double phi2); + + // + // The next group of fcn formats a string to write out names of different + // memories and processing modules + // + + //Seed string, eg. L1L2 + std::string iSeedStr(unsigned int iSeed); + + //Return unsigned as string + std::string numStr(unsigned int i); + + //Retunr iTC as string - ie A, B, C, etc + std::string iTCStr(unsigned int iTC); + + //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); + + //TC Name + std::string TCName(unsigned int iSeed, unsigned int iTC); + + //Name of layer or disk, e.g. L1 or D1 + std::string LayerName(unsigned int ilayer); + + //Tracklet projection name + std::string TPROJName(unsigned int iSeed, unsigned int iTC, unsigned int ilayer, unsigned int ireg); + + //Projection router name + std::string PRName(unsigned int ilayer, unsigned int ireg); + + //StubPair Name + std::string SPName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed); + + //StubPaur displaced name + std::string SPDName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int l3, + unsigned int ireg3, + unsigned int ivm3, + unsigned int iseed); + + //Stub Triplet name + std::string STName(unsigned int l1, + unsigned int ireg1, + unsigned int l2, + unsigned int ireg2, + unsigned int l3, + unsigned int ireg3, + unsigned int iseed, + unsigned int count); + + //TrackletEngine name + std::string TEName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed); + + //Triplet engine name + std::string TREName(unsigned int l1, + unsigned int ireg1, + unsigned int l2, + unsigned int ireg2, + unsigned int iseed, + unsigned int count); + + //TrackletEngine displaced name + std::string TEDName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed); + + //Tracklet parameter memory name + std::string TParName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc); + + //TrackletCalculator displaced name + std::string TCDName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc); + + //TrackletProjection name + std::string TPROJName(unsigned int l1, + unsigned int l2, + unsigned int l3, + unsigned int itc, + unsigned int projlay, + unsigned int projreg); + + //FitTrack module name + std::string FTName(unsigned int l1, unsigned int l2, unsigned int l3); + + //TrackletCalculator name + std::string TCNAme(unsigned int iseed, unsigned int iTC); + + // + // 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 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); + + void writeVMSMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeTPARMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeTFMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeCTMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + void writeILMemories(std::ostream& os, std::ostream& memories, std::ostream& modules); + + // + // Store constants extracted from Settings + // + unsigned int NSector_; //Number of sectors + double rcrit_; //critical radius that defines the sector + + bool combinedmodules_; //if true write configuration for combined modules + + bool extended_; //if true write configuration for extended configuration + + double rinvmax_; //Max value for valid rinv + double rmaxdisk_; //Maximim disk radius + double zlength_; //Maximim (abslute) z-positon in barrel + double rmean_[N_LAYER]; //Mean layer radius + double zmean_[N_DISK]; //Mean disk z-position + + double dphisectorHG_; //Full sector width + + unsigned int NTC_[N_SEED_PROMPT]; //Number of TC per seeding combination + + unsigned int NRegions_[N_LAYER + N_DISK]; //Regions (all stubs memories 6 layers +5 disks + unsigned int NVMME_[N_LAYER + N_DISK]; //Number of MEs (all stubs memories 6 layers +5 disks + std::pair NVMTE_[N_SEED_PROMPT]; //number of TEs for each seeding combination + + //Min and max phi for a phi region (e.g. all stubs) + std::vector > allStubs_[N_LAYER + N_DISK]; + + //Min and max phi for VM bin + std::vector > VMStubsME_[N_LAYER + N_DISK]; + + //Phi ranges for the stubs in the VM bins used in the pair in th TE + std::pair >, std::vector > > + VMStubsTE_[N_SEED_PROMPT]; + + //List of the TEs and the VM bins for each TE + std::vector > TE_[N_SEED_PROMPT]; + + //The TCs for each seeding combination + std::vector > TC_[N_SEED_PROMPT]; + + //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 + {1, -1, -1, 2, 3, -1, 4, 3, 2, 1, -1}, //L2L3 + {1, 2, -1, -1, 3, 4, 4, 3, -1, -1, -1}, //L3L4 + {1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1}, //L5L6 + {1, 2, -1, -1, -1, -1, -1, -1, 2, 3, 4}, //D1D2 + {1, -1, -1, -1, -1, -1, 2, 3, -1, -1, 4}, //D3D4 + {-1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 4}, //L1D1 + {1, -1, -1, -1, -1, -1, -1, 2, 3, 4, -1}}; //L2D1 + + //Settings + const Settings& settings_; + }; +} // namespace trklet +#endif diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h index a6fd3f9492fe2..e827185374716 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngine.h @@ -16,7 +16,7 @@ namespace trklet { class TrackletEngine : public ProcessBase { public: - TrackletEngine(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + TrackletEngine(std::string name, Settings const& settings, Globals* global); ~TrackletEngine() override = default; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h index 79eadb944b67e..91ea9e6ad4ee8 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineDisplaced.h @@ -19,7 +19,7 @@ namespace trklet { class TrackletEngineDisplaced : public ProcessBase { public: - TrackletEngineDisplaced(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + TrackletEngineDisplaced(std::string name, Settings const& settings, Globals* global); ~TrackletEngineDisplaced() override; @@ -30,7 +30,7 @@ namespace trklet { void readTables(); - const short memNameToIndex(const std::string& name); + short memNameToIndex(const std::string& name); private: int layer1_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h index 120e8891e9c2e..dd12be6851287 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEngineUnit.h @@ -28,6 +28,7 @@ namespace trklet { public: TrackletEngineUnit(const Settings* const settings, unsigned int nbitsfinephi, + unsigned int layerdisk1, unsigned int layerdisk2, unsigned int iSeed, unsigned int nbitsfinephiediff, @@ -48,19 +49,28 @@ namespace trklet { bool idle() const { return idle_; } + void setNearFull() { nearfull_ = candpairs_.nearfull(); } + void reset(); - void step(); + void step(bool print, int istep, int iTE); + + int rptr() const { return candpairs_.rptr(); } + + int wptr() const { return candpairs_.wptr(); } + + const Stub* innerStub() const { return tedata_.stub_; } private: VMStubsTEMemory* outervmstubs_; TEData tedata_; const Settings* settings_; unsigned int nbitsfinephi_; + unsigned int layerdisk1_; unsigned int layerdisk2_; unsigned int iSeed_; unsigned int nbitsfinephidiff_; - + bool nearfull_; //initialized at start of each processing step unsigned int iAllStub_; //unsigned int memory slot @@ -75,6 +85,9 @@ namespace trklet { std::vector pttableinner_; std::vector pttableouter_; + std::pair candpair_, candpair__; + bool goodpair_, goodpair__; + //save the candidate matches CircularBuffer > candpairs_; }; // TrackletEngineUnit diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h b/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h index e46685eaf563c..114b2f0e32dc5 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h @@ -17,7 +17,6 @@ namespace trklet { class Sector; class HistBase; class Track; - class Cabling; class TrackletEventProcessor { public: @@ -31,23 +30,24 @@ namespace trklet { void printSummary(); - std::vector& tracks() { return tracks_; } + const std::vector& tracks() const { return tracks_; } private: + void configure(std::istream& inwire, std::istream& inmem, std::istream& inproc); + const Settings* settings_{nullptr}; std::unique_ptr globals_; - std::vector > sectors_; + std::unique_ptr sector_; HistBase* histbase_{}; int eventnum_ = {0}; - std::unique_ptr cabling_; - Timer cleanTimer_; Timer addStubTimer_; + Timer InputRouterTimer_; Timer VMRouterTimer_; Timer TETimer_; Timer TEDTimer_; @@ -62,9 +62,7 @@ namespace trklet { Timer FTTimer_; Timer PDTimer_; - std::vector tracks_; - - std::map > dtclayerdisk_; + std::vector tracks_; }; }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h index 088f937dcbc4c..7a81bececba65 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletParametersMemory.h @@ -16,7 +16,7 @@ namespace trklet { class TrackletParametersMemory : public MemoryBase { public: - TrackletParametersMemory(std::string name, Settings const &settings, unsigned int iSector); + TrackletParametersMemory(std::string name, Settings const &settings); ~TrackletParametersMemory() override = default; @@ -28,9 +28,7 @@ namespace trklet { void clean() override; - void writeMatches(Globals *globals, int &matchesL1, int &matchesL3, int &matchesL5); - - void writeTPAR(bool first); + void writeTPAR(bool first, unsigned int iSector); private: std::vector tracklets_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h b/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h index d740b26b8ff35..c32a718681fc1 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h @@ -18,11 +18,12 @@ namespace trklet { class Globals; class MemoryBase; class AllStubsMemory; + class AllInnerStubsMemory; class VMStubsTEMemory; class TrackletProcessor : public TrackletCalculatorBase { public: - TrackletProcessor(std::string name, Settings const& settings, Globals* globals, unsigned int iSector); + TrackletProcessor(std::string name, Settings const& settings, Globals* globals); ~TrackletProcessor() override = default; @@ -32,7 +33,7 @@ namespace trklet { void addInput(MemoryBase* memory, std::string input) override; - void execute(); + void execute(unsigned int iSector, double phimin, double phimax); void writeTETable(); @@ -42,18 +43,16 @@ namespace trklet { int iTC_; int iAllStub_; + unsigned int maxStep_; + VMStubsTEMemory* outervmstubs_; - // The use of a std::tuple here is awkward and should be fixed. This code is slotted for a significant - // overhaul to allign with the HLS implementation. At that point the use fo the tuple should be - // eliminated - // istub imem start imem end imem - std::vector, unsigned int, unsigned int, unsigned int, unsigned int> > - tedatabuffers_; + // istub imem start imem end imem + std::tuple, unsigned int, unsigned int, unsigned int, unsigned int> tebuffer_; std::vector teunits_; - std::vector innerallstubs_; + std::vector innerallstubs_; std::vector outerallstubs_; std::map > pttableinner_; @@ -62,7 +61,7 @@ namespace trklet { std::vector pttableinnernew_; std::vector pttableouternew_; - std::vector > useregion_; + std::vector useregion_; int nbitsfinephi_; int nbitsfinephidiff_; diff --git a/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h index 3d376d3b98dcc..4a936c7c4f950 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/TrackletProjectionsMemory.h @@ -14,7 +14,7 @@ namespace trklet { class TrackletProjectionsMemory : public MemoryBase { public: - TrackletProjectionsMemory(std::string name, Settings const& settings, unsigned int iSector); + TrackletProjectionsMemory(std::string name, Settings const& settings); ~TrackletProjectionsMemory() override = default; @@ -26,7 +26,7 @@ namespace trklet { void clean() override; - void writeTPROJ(bool first); + void writeTPROJ(bool first, unsigned int iSector); int layer() const { return layer_; } int disk() const { return disk_; } diff --git a/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h b/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h index 1652262c1808a..ad5840af13a0e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h +++ b/L1Trigger/TrackFindingTracklet/interface/TripletEngine.h @@ -17,7 +17,7 @@ namespace trklet { class TripletEngine : public ProcessBase { public: - TripletEngine(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + TripletEngine(std::string name, Settings const& settings, Globals* global); ~TripletEngine() override; diff --git a/L1Trigger/TrackFindingTracklet/interface/Util.h b/L1Trigger/TrackFindingTracklet/interface/Util.h index 818b548880d98..41ed3a8e25390 100644 --- a/L1Trigger/TrackFindingTracklet/interface/Util.h +++ b/L1Trigger/TrackFindingTracklet/interface/Util.h @@ -2,9 +2,13 @@ #define L1Trigger_TrackFindingTracklet_interface_Util_h #include +#include #include #include +#include #include +#include +#include #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -35,150 +39,142 @@ namespace trklet { return str; } - //Should be optimized by layer - now first implementation to make sure it works OK - inline int bendencode(double bend, bool isPS) { - int ibend = 2.0 * bend; + inline double bendstrip(double r, double rinv, double stripPitch) { + constexpr double dr = 0.18; + double delta = r * dr * 0.5 * rinv; + double bend = delta / stripPitch; + return bend; + } - assert(std::abs(ibend - 2.0 * bend) < 0.1); + inline double rinv(double phi1, double phi2, double r1, double r2) { + if (r2 <= r1) { //FIXME can not form tracklet should not call function with r2<=r1 + return 20.0; + } - if (isPS) { - if (ibend == 0 || ibend == 1) - return 0; - if (ibend == 2 || ibend == 3) - return 1; - if (ibend == 4 || ibend == 5) - return 2; - if (ibend >= 6) - return 3; - if (ibend == -1 || ibend == -2) - return 4; - if (ibend == -3 || ibend == -4) - return 5; - if (ibend == -5 || ibend == -6) - return 6; - if (ibend <= -7) - return 7; - - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ - << " Unknown bendencode for PS module for bend = " << bend - << " ibend = " << ibend; + double dphi = phi2 - phi1; + double dr = r2 - r1; + + return 2.0 * sin(dphi) / dr / sqrt(1.0 + 2 * r1 * r2 * (1.0 - cos(dphi)) / (dr * dr)); + } + + inline std::string convertHexToBin(const std::string& stubwordhex) { + std::string stubwordbin = ""; + + for (char word : stubwordhex) { + std::string hexword = ""; + if (word == '0') + hexword = "0000"; + if (word == '1') + hexword = "0001"; + if (word == '2') + hexword = "0010"; + if (word == '3') + hexword = "0011"; + if (word == '4') + hexword = "0100"; + if (word == '5') + hexword = "0101"; + if (word == '6') + hexword = "0110"; + if (word == '7') + hexword = "0111"; + if (word == '8') + hexword = "1000"; + if (word == '9') + hexword = "1001"; + if (word == 'A') + hexword = "1010"; + if (word == 'B') + hexword = "1011"; + if (word == 'C') + hexword = "1100"; + if (word == 'D') + hexword = "1101"; + if (word == 'E') + hexword = "1110"; + if (word == 'F') + hexword = "1111"; + if (hexword == "") { + throw cms::Exception("Inconsistency") + << __FILE__ << " " << __LINE__ << " hex string format invalid: " << stubwordhex; + } + stubwordbin += hexword; } + return stubwordbin; + } - if (ibend == 0 || ibend == 1) - return 0; - if (ibend == 2 || ibend == 3) - return 1; - if (ibend == 4 || ibend == 5) - return 2; - if (ibend == 6 || ibend == 7) - return 3; - if (ibend == 8 || ibend == 9) - return 4; - if (ibend == 10 || ibend == 11) - return 5; - if (ibend == 12 || ibend == 13) - return 6; - if (ibend >= 14) - return 7; - if (ibend == -1 || ibend == -2) - return 8; - if (ibend == -3 || ibend == -4) - return 9; - if (ibend == -5 || ibend == -6) - return 10; - if (ibend == -7 || ibend == -8) - return 11; - if (ibend == -9 || ibend == -10) - return 12; - if (ibend == -11 || ibend == -12) - return 13; - if (ibend == -13 || ibend == -14) - return 14; - if (ibend <= -15) - return 15; - - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ - << " Unknown bendencode for 2S module for bend = " << bend - << " ibend = " << ibend; + inline int ilog2(double factor) { + double power = log(factor) / log(2); + int ipower = round(power); + assert(std::abs(power - ipower) < 0.1); + return ipower; } - //Should be optimized by layer - now first implementation to make sure it works OK - inline double benddecode(int ibend, bool isPS) { - if (isPS) { - if (ibend == 0) - return 0.25; - if (ibend == 1) - return 1.25; - if (ibend == 2) - return 2.25; - if (ibend == 3) - return 3.25; - if (ibend == 4) - return -0.75; - if (ibend == 5) - return -1.75; - if (ibend == 6) - return -2.75; - if (ibend == 7) - return -3.75; - - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ - << " Unknown benddecode for PS module for ibend = " << ibend; + /****************************************************************************** + * Checks to see if a directory exists. Note: This method only checks the + * existence of the full path AND if path leaf is a dir. + * + * @return 1 if dir exists AND is a dir, + * 0 if dir does not exist OR exists but not a dir, + * -1 if an error occurred (errno is also set) + *****************************************************************************/ + inline int dirExists(const std::string& path) { + struct stat info; + + int statRC = stat(path.c_str(), &info); + if (statRC != 0) { + if (errno == ENOENT) { + return 0; + } // something along the path does not exist + if (errno == ENOTDIR) { + return 0; + } // something in path prefix is not a dir + return -1; } - if (ibend == 0) - return 0.25; - if (ibend == 1) - return 1.25; - if (ibend == 2) - return 2.25; - if (ibend == 3) - return 3.25; - if (ibend == 4) - return 4.25; - if (ibend == 5) - return 5.25; - if (ibend == 6) - return 6.25; - if (ibend == 7) - return 7.25; - if (ibend == 8) - return -0.75; - if (ibend == 9) - return -1.75; - if (ibend == 10) - return -2.75; - if (ibend == 11) - return -3.75; - if (ibend == 12) - return -4.75; - if (ibend == 13) - return -5.75; - if (ibend == 14) - return -6.75; - if (ibend == 15) - return -7.75; - - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ - << " Unknown benddecode for 2S module for ibend = " << ibend; + return (info.st_mode & S_IFDIR) ? 1 : 0; } - inline double bend(double r, double rinv, double stripPitch) { - constexpr double dr = 0.18; - double delta = r * dr * 0.5 * rinv; - double bend = -delta / stripPitch; - return bend; + //Open file - create directory if not existent. + inline std::ofstream openfile(const std::string& dir, const std::string& fname, const char* file, int line) { + if (dirExists(dir) != 1) { + std::cout << "Creating directory : " << dir << std::endl; + int fail = system((std::string("mkdir -p ") + dir).c_str()); + if (fail) { + throw cms::Exception("BadDir") << file << " " << line << " could not create directory " << dir; + } + } + + std::ofstream out(dir + "/" + fname); + + if (out.fail()) { + throw cms::Exception("BadFile") << file << " " << line << " could not create file " << fname << " in " << dir; + } + + return out; } - inline double rinv(double phi1, double phi2, double r1, double r2) { - if (r2 <= r1) { //can not form tracklet - return 20.0; + //Open file - create directory if not existent. + //If first==true open file in create mode, if first==false open in append mode + inline void openfile( + std::ofstream& out, bool first, const std::string& dir, const std::string& fname, const char* file, int line) { + if (dirExists(dir) != 1) { + std::cout << "Creating directory : " << dir << std::endl; + int fail = system((std::string("mkdir -p ") + dir).c_str()); + if (fail) { + throw cms::Exception("BadDir") << file << " " << line << " could not create directory " << dir; + } } - double dphi = phi2 - phi1; - double dr = r2 - r1; + if (first) { + out.open(fname); + } else { + out.open(fname, std::ofstream::app); + } - return 2.0 * sin(dphi) / dr / sqrt(1.0 + 2 * r1 * r2 * (1.0 - cos(dphi)) / (dr * dr)); + if (out.fail()) { + throw cms::Exception("BadFile") << file << " " << line << " could not create file " << fname << " in " << dir; + } } }; // namespace trklet diff --git a/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h index 1b3e37aba7184..47f15743dc6c8 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMProjectionsMemory.h @@ -13,7 +13,7 @@ namespace trklet { class VMProjectionsMemory : public MemoryBase { public: - VMProjectionsMemory(std::string name, Settings const& settings, unsigned int iSector); + VMProjectionsMemory(std::string name, Settings const& settings); ~VMProjectionsMemory() override = default; @@ -24,7 +24,7 @@ namespace trklet { Tracklet* getTracklet(unsigned int i) { return tracklets_[i].first; } int getAllProjIndex(unsigned int i) const { return tracklets_[i].second; } - void writeVMPROJ(bool first); + void writeVMPROJ(bool first, unsigned int iSector); void clean() override { tracklets_.clear(); } diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouter.h b/L1Trigger/TrackFindingTracklet/interface/VMRouter.h index 5e93482182cfe..52811501ac88e 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouter.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouter.h @@ -34,7 +34,7 @@ namespace trklet { class VMRouter : public ProcessBase { public: - VMRouter(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + VMRouter(std::string name, Settings const& settings, Globals* global); ~VMRouter() override = default; @@ -57,8 +57,8 @@ namespace trklet { VMRouterTable vmrtable_; - //The input stub memories - std::vector stubinputs_; + //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_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h index a360351aafe84..3322ea12019aa 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouterCM.h @@ -17,6 +17,7 @@ namespace trklet { class MemoryBase; class InputLinkMemory; class AllStubsMemory; + class AllInnerStubsMemory; class VMStubsMEMemory; class VMStubsTEMemory; @@ -30,7 +31,7 @@ namespace trklet { class VMRouterCM : public ProcessBase { public: - VMRouterCM(std::string name, Settings const& settings, Globals* global, unsigned int iSector); + VMRouterCM(std::string name, Settings const& settings, Globals* global); ~VMRouterCM() override = default; @@ -59,7 +60,8 @@ namespace trklet { std::vector stubinputs_; //The all stub memories - std::vector > allstubs_; + std::vector allstubs_; + std::vector > allinnerstubs_; //The VM stubs memories used by the MEs std::vector vmstubsMEPHI_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h b/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h index 08a1ecd198fe2..b376c5d712c79 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h @@ -20,7 +20,7 @@ namespace trklet { ~VMRouterTable() = default; - void init(unsigned int layerdisk, std::string const& name); + void init(unsigned int layerdisk, std::string const& name = ""); // negative return means that seed can not be formed int getLookup(unsigned int layerdisk, double z, double r, int iseed = -1); @@ -30,7 +30,8 @@ namespace trklet { int lookupinner(int zbin, int rbin); int lookupinneroverlap(int zbin, int rbin); int lookupinnerThird(int zbin, int rbin); - void writeVMTable(std::string const& name, std::vector const& table); + + void writeVMTable(std::string const& dir, std::string const& name, std::vector const& table); private: Settings const& settings_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h index 8c231f2909352..ee85a668da883 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h @@ -15,7 +15,7 @@ namespace trklet { class VMStubsMEMemory : public MemoryBase { public: - VMStubsMEMemory(std::string name, Settings const& settings, unsigned int iSector); + VMStubsMEMemory(std::string name, Settings const& settings); ~VMStubsMEMemory() override = default; @@ -50,7 +50,7 @@ namespace trklet { } } - void writeStubs(bool first); + void writeStubs(bool first, unsigned int iSector); private: std::vector > binnedstubs_; diff --git a/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h b/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h index b494573c7de79..e77d22ba3cb02 100644 --- a/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h +++ b/L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h @@ -15,7 +15,7 @@ namespace trklet { class VMStubsTEMemory : public MemoryBase { public: - VMStubsTEMemory(std::string name, Settings const& settings, unsigned int iSector); + VMStubsTEMemory(std::string name, Settings const& settings); ~VMStubsTEMemory() override = default; @@ -37,7 +37,7 @@ namespace trklet { void clean() override; - void writeStubs(bool first); + void writeStubs(bool first, unsigned int iSector); int phibin() const { return phibin_; } @@ -59,6 +59,7 @@ namespace trklet { private: int layer_; int disk_; + int layerdisk_; int phibin_; VMStubsTEMemory* other_; bool overlap_; diff --git a/L1Trigger/TrackFindingTracklet/plugins/BuildFile.xml b/L1Trigger/TrackFindingTracklet/plugins/BuildFile.xml index df534e5516622..c9303f449c53b 100644 --- a/L1Trigger/TrackFindingTracklet/plugins/BuildFile.xml +++ b/L1Trigger/TrackFindingTracklet/plugins/BuildFile.xml @@ -4,6 +4,7 @@ + diff --git a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc index aa6b5f30f9860..ad83e1ec15f16 100644 --- a/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc +++ b/L1Trigger/TrackFindingTracklet/plugins/L1FPGATrackProducer.cc @@ -40,7 +40,6 @@ #include "SimDataFormats/Vertex/interface/SimVertex.h" #include "SimDataFormats/Vertex/interface/SimVertexContainer.h" #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" -#include "SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h" #include "SimTracker/TrackTriggerAssociation/interface/TTStubAssociationMap.h" #include "SimTracker/TrackTriggerAssociation/interface/TTClusterAssociationMap.h" // @@ -52,6 +51,8 @@ #include "DataFormats/L1TrackTrigger/interface/TTTrack.h" #include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h" #include "DataFormats/L1TrackTrigger/interface/TTTypes.h" +#include "DataFormats/L1TrackTrigger/interface/TTDTC.h" +#include "L1Trigger/TrackerDTC/interface/Setup.h" // #include "DataFormats/HepMCCandidate/interface/GenParticle.h" #include "DataFormats/Candidate/interface/Candidate.h" @@ -80,7 +81,6 @@ // Tracklet emulation #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" #include "L1Trigger/TrackFindingTracklet/interface/Sector.h" -#include "L1Trigger/TrackFindingTracklet/interface/Cabling.h" #include "L1Trigger/TrackFindingTracklet/interface/Track.h" #include "L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h" @@ -118,14 +118,14 @@ using namespace std; // between different types of stubs struct L1TStubCompare { public: - bool operator()(const trklet::L1TStub& x, const trklet::L1TStub& y) const { - if (x.x() != y.x()) - return (y.x() > x.x()); + bool operator()(const trklet::L1TStub& a, const trklet::L1TStub& b) const { + if (a.x() != b.x()) + return (b.x() > a.x()); else { - if (x.y() != y.y()) - return (y.y() > x.y()); + if (a.y() != b.y()) + return (b.y() > a.y()); else - return (x.z() > y.z()); + return (a.z() > b.z()); } } }; @@ -150,18 +150,12 @@ class L1FPGATrackProducer : public edm::one::EDProducer { edm::FileInPath processingModulesFile; edm::FileInPath wiresFile; - edm::FileInPath DTCLinkFile; - edm::FileInPath moduleCablingFile; - edm::FileInPath DTCLinkLayerDiskFile; - edm::FileInPath tableTEDFile; edm::FileInPath tableTREFile; string asciiEventOutName_; std::ofstream asciiEventOut_; - string geometryType_; - // settings containing various constants for the tracklet processing trklet::Settings settings; @@ -182,17 +176,18 @@ class L1FPGATrackProducer : public edm::one::EDProducer { edm::InputTag MCTruthClusterInputTag; edm::InputTag MCTruthStubInputTag; edm::InputTag TrackingParticleInputTag; - edm::InputTag TrackingVertexInputTag; - edm::InputTag ttStubSrc_; - edm::InputTag bsSrc_; - const edm::EDGetTokenT>> ttStubToken_; const edm::EDGetTokenT bsToken_; edm::EDGetTokenT> ttClusterMCTruthToken_; - edm::EDGetTokenT> ttStubMCTruthToken_; edm::EDGetTokenT> TrackingParticleToken_; - edm::EDGetTokenT> TrackingVertexToken_; + edm::EDGetTokenT tokenDTC_; + + // helper class to store DTC configuration + trackerDTC::Setup setup_; + + // Setup token + edm::ESGetToken esGetToken_; /// ///////////////// /// /// MANDATORY METHODS /// @@ -212,18 +207,11 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) : edm::InputTag()), TrackingParticleInputTag(readMoreMcTruth_ ? iConfig.getParameter("TrackingParticleInputTag") : edm::InputTag()), - TrackingVertexInputTag(readMoreMcTruth_ ? iConfig.getParameter("TrackingVertexInputTag") - : edm::InputTag()), - ttStubSrc_(config.getParameter("TTStubSource")), - bsSrc_(config.getParameter("BeamSpotSource")), - - ttStubToken_(consumes>>(ttStubSrc_)), - bsToken_(consumes(bsSrc_)) { + bsToken_(consumes(config.getParameter("BeamSpotSource"))), + tokenDTC_(consumes(edm::InputTag(iConfig.getParameter("InputTagTTDTC")))) { if (readMoreMcTruth_) { ttClusterMCTruthToken_ = consumes>(MCTruthClusterInputTag); - ttStubMCTruthToken_ = consumes>(MCTruthStubInputTag); TrackingParticleToken_ = consumes>(TrackingParticleInputTag); - TrackingVertexToken_ = consumes>(TrackingVertexInputTag); } produces>>("Level1TTTracks").setBranchAlias("Level1TTTracks"); @@ -235,10 +223,6 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) memoryModulesFile = iConfig.getParameter("memoryModulesFile"); wiresFile = iConfig.getParameter("wiresFile"); - DTCLinkFile = iConfig.getParameter("DTCLinkFile"); - moduleCablingFile = iConfig.getParameter("moduleCablingFile"); - DTCLinkLayerDiskFile = iConfig.getParameter("DTCLinkLayerDiskFile"); - extended_ = iConfig.getParameter("Extended"); nHelixPar_ = iConfig.getParameter("Hnpar"); @@ -247,6 +231,9 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) tableTREFile = iConfig.getParameter("tableTREFile"); } + // book ES product + esGetToken_ = esConsumes(); + // -------------------------------------------------------------------------------- // set options in Settings based on inputs from configuration files // -------------------------------------------------------------------------------- @@ -254,9 +241,6 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) settings.setExtended(extended_); settings.setNHelixPar(nHelixPar_); - settings.setDTCLinkFile(DTCLinkFile.fullPath()); - settings.setModuleCablingFile(moduleCablingFile.fullPath()); - settings.setDTCLinkLayerDiskFile(DTCLinkLayerDiskFile.fullPath()); settings.setFitPatternFile(fitPatternFile.fullPath()); settings.setProcessingModulesFile(processingModulesFile.fullPath()); settings.setMemoryModulesFile(memoryModulesFile.fullPath()); @@ -278,10 +262,7 @@ L1FPGATrackProducer::L1FPGATrackProducer(edm::ParameterSet const& iConfig) } if (settings.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "cabling DTC links : " << DTCLinkFile.fullPath() - << "\n module cabling : " << moduleCablingFile.fullPath() - << "\n DTC link layer disk : " << DTCLinkLayerDiskFile.fullPath() - << "\n fit pattern : " << fitPatternFile.fullPath() + edm::LogVerbatim("Tracklet") << "fit pattern : " << fitPatternFile.fullPath() << "\n process modules : " << processingModulesFile.fullPath() << "\n memory modules : " << memoryModulesFile.fullPath() << "\n wires : " << wiresFile.fullPath(); @@ -320,6 +301,8 @@ void L1FPGATrackProducer::beginRun(const edm::Run& run, const edm::EventSetup& i double mMagneticFieldStrength = theMagneticField->inTesla(GlobalPoint(0, 0, 0)).z(); settings.setBfield(mMagneticFieldStrength); + setup_ = iSetup.getData(esGetToken_); + // initialize the tracklet event processing (this sets all the processing & memory modules, wiring, etc) eventProcessor.init(settings); } @@ -357,16 +340,12 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe eventnum++; trklet::SLHCEvent ev; ev.setEventNum(eventnum); - ev.setIPx(bsPosition.x()); - ev.setIPy(bsPosition.y()); + ev.setIP(bsPosition.x(), bsPosition.y()); // tracking particles edm::Handle> TrackingParticleHandle; - edm::Handle> TrackingVertexHandle; if (readMoreMcTruth_) iEvent.getByToken(TrackingParticleToken_, TrackingParticleHandle); - if (readMoreMcTruth_) - iEvent.getByToken(TrackingVertexToken_, TrackingVertexHandle); // tracker topology const TrackerTopology* const tTopo = tTopoHandle.product(); @@ -374,18 +353,16 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe //////////////////////// // GET THE PRIMITIVES // - edm::Handle>> Phase2TrackerDigiTTStubHandle; - iEvent.getByToken(ttStubToken_, Phase2TrackerDigiTTStubHandle); + edm::Handle handleDTC; + iEvent.getByToken(tokenDTC_, handleDTC); // must be defined for code to compile, even if it's not used unless readMoreMcTruth_ is true map, int> translateTP; // MC truth association maps edm::Handle> MCTruthTTClusterHandle; - edm::Handle> MCTruthTTStubHandle; if (readMoreMcTruth_) { iEvent.getByToken(ttClusterMCTruthToken_, MCTruthTTClusterHandle); - iEvent.getByToken(ttStubMCTruthToken_, MCTruthTTStubHandle); //////////////////////////////////////////////// /// LOOP OVER TRACKING PARTICLES & GET SIMTRACKS @@ -427,57 +404,110 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe } // end if (readMoreMcTruth_) - //////////////////////////////// - /// COLLECT STUB INFORMATION /// - //////////////////////////////// + ///////////////////////////////// + /// READ DTC STUB INFORMATION /// + ///////////////////////////////// - bool firstPS = true; - bool first2S = true; + // Process stubs in each region and channel within that region + for (const int& region : handleDTC->tfpRegions()) { + for (const int& channel : handleDTC->tfpChannels()) { + // Get the DTC name form the channel - for (const auto& gd : theTrackerGeom->dets()) { - DetId detid = (*gd).geographicalId(); - if (detid.subdetId() != StripSubdetector::TOB && detid.subdetId() != StripSubdetector::TID) - continue; // only run on OT - if (!tTopo->isLower(detid)) - continue; // loop on the stacks: choose the lower arbitrarily - DetId stackDetid = tTopo->stack(detid); // Stub module detid + static string dtcbasenames[12] = { + "PS10G_1", "PS10G_2", "PS10G_3", "PS10G_4", "PS_1", "PS_2", "2S_1", "2S_2", "2S_3", "2S_4", "2S_5", "2S_6"}; - if (Phase2TrackerDigiTTStubHandle->find(stackDetid) == Phase2TrackerDigiTTStubHandle->end()) - continue; + string dtcname = dtcbasenames[channel % 12]; - // Get the DetSets of the Clusters - edmNew::DetSet> stubs = (*Phase2TrackerDigiTTStubHandle)[stackDetid]; - const GeomDetUnit* det0 = theTrackerGeom->idToDetUnit(detid); - const auto* theGeomDet = dynamic_cast(det0); - const PixelTopology* topol = dynamic_cast(&(theGeomDet->specificTopology())); + if (channel % 24 >= 12) + dtcname = "neg" + dtcname; - bool isPSmodule = theTrackerGeom->getDetectorType(detid) == TrackerGeometry::ModuleType::Ph2PSP; + dtcname += (channel < 24) ? "_A" : "_B"; - // set constants that are common for all modules/stubs of a given type (PS vs 2S) - if (isPSmodule && firstPS) { - settings.setNStrips_PS(topol->nrows()); - settings.setStripPitch_PS(topol->pitch().first); - settings.setStripLength_PS(topol->pitch().second); - firstPS = false; - } - if (!isPSmodule && first2S) { - settings.setNStrips_2S(topol->nrows()); - settings.setStripPitch_2S(topol->pitch().first); - settings.setStripLength_2S(topol->pitch().second); - first2S = false; - } + // Get the stubs from the DTC + const TTDTC::Stream& streamFromDTC{handleDTC->stream(region, channel)}; - // loop over stubs - for (auto stubIter = stubs.begin(); stubIter != stubs.end(); ++stubIter) { - edm::Ref>, TTStub> tempStubPtr = - edmNew::makeRefTo(Phase2TrackerDigiTTStubHandle, stubIter); + // Prepare the DTC stubs for the IR + for (size_t stubIndex = 0; stubIndex < streamFromDTC.size(); ++stubIndex) { + const TTDTC::Frame& stub{streamFromDTC[stubIndex]}; - vector assocTPs; + if (stub.first.isNull()) { + continue; + } + + const GlobalPoint& ttPos = setup_.stubPos(stub.first); + + //Get the 2 bits for the layercode + string layerword = stub.second.to_string().substr(61, 2); + unsigned int layercode = 2 * (layerword[0] - '0') + layerword[1] - '0'; + assert(layercode < 4); + + //translation from the two bit layercode to the layer/disk number of each of the + //12 channels (dtcs) + static int layerdisktab[12][4] = {{0, 6, 8, 10}, + {0, 7, 9, -1}, + {1, 7, -1, -1}, + {6, 8, 10, -1}, + {2, 7, -1, -1}, + {2, 9, -1, -1}, + {3, 4, -1, -1}, + {4, -1, -1, -1}, + {5, -1, -1, -1}, + {5, 8, -1, -1}, + {6, 9, -1, -1}, + {7, 10, -1, -1}}; + + int layerdisk = layerdisktab[channel % 12][layercode]; + assert(layerdisk != -1); + + //Get the 36 bit word - skip the lowest 3 buts (status and layer code) + constexpr int DTCLinkWordSize = 64; + constexpr int StubWordSize = 36; + constexpr int LayerandStatusCodeSize = 3; + string stubword = stub.second.to_string().substr(DTCLinkWordSize - StubWordSize - LayerandStatusCodeSize, StubWordSize); + string stubwordhex = ""; + + //Loop over the 9 words in the 36 bit stub word + for (unsigned int i = 0; i < 9; i++) { + bitset<4> bits(stubword.substr(i * 4, 4)); + ulong val = bits.to_ulong(); + stubwordhex += ((val < 10) ? ('0' + val) : ('A' + val - 10)); + } + + /// Get the Inner and Outer TTCluster + edm::Ref>, TTCluster> + innerCluster = stub.first->clusterRef(0); + edm::Ref>, TTCluster> + outerCluster = stub.first->clusterRef(1); + + // ----------------------------------------------------- + // check module orientation, if flipped, need to store that information for track fit + // ----------------------------------------------------- + + const DetId innerDetId = innerCluster->getDetId(); + const GeomDetUnit* det_inner = theTrackerGeom->idToDetUnit(innerDetId); + const auto* theGeomDet_inner = dynamic_cast(det_inner); + const PixelTopology* topol_inner = dynamic_cast(&(theGeomDet_inner->specificTopology())); + + MeasurementPoint coords_inner = innerCluster->findAverageLocalCoordinatesCentered(); + LocalPoint clustlp_inner = topol_inner->localPosition(coords_inner); + GlobalPoint posStub_inner = theGeomDet_inner->surface().toGlobal(clustlp_inner); + + const DetId outerDetId = outerCluster->getDetId(); + const GeomDetUnit* det_outer = theTrackerGeom->idToDetUnit(outerDetId); + const auto* theGeomDet_outer = dynamic_cast(det_outer); + const PixelTopology* topol_outer = dynamic_cast(&(theGeomDet_outer->specificTopology())); + + MeasurementPoint coords_outer = outerCluster->findAverageLocalCoordinatesCentered(); + LocalPoint clustlp_outer = topol_outer->localPosition(coords_outer); + GlobalPoint posStub_outer = theGeomDet_outer->surface().toGlobal(clustlp_outer); + + bool isFlipped = (posStub_outer.mag() < posStub_inner.mag()); + + vector assocTPs; - if (readMoreMcTruth_) { for (unsigned int iClus = 0; iClus <= 1; iClus++) { // Loop over both clusters that make up stub. - const TTClusterRef& ttClusterRef = tempStubPtr->clusterRef(iClus); + const TTClusterRef& ttClusterRef = stub.first->clusterRef(iClus); // Now identify all TP's contributing to either cluster in stub. vector> vecTpPtr = MCTruthTTClusterHandle->findTrackingParticlePtrs(ttClusterRef); @@ -495,128 +525,27 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe } } } - } // end if (readMoreMcTruth_) - - MeasurementPoint coords = tempStubPtr->clusterRef(0)->findAverageLocalCoordinatesCentered(); - LocalPoint clustlp = topol->localPosition(coords); - GlobalPoint posStub = theGeomDet->surface().toGlobal(clustlp); - int eventID = -1; - - if (readMoreMcTruth_) { - edm::Ptr my_tp = MCTruthTTStubHandle->findTrackingParticlePtr(tempStubPtr); - } - - int layer = -999999; - int ladder = -999999; - int module = -999999; - - int strip = 460; - - if (detid.subdetId() == StripSubdetector::TOB) { - layer = static_cast(tTopo->layer(detid)); - module = static_cast(tTopo->module(detid)); - ladder = static_cast(tTopo->tobRod(detid)); - - // https://github.com/cms-sw/cmssw/tree/master/Geometry/TrackerNumberingBuilder - // tobSide = 1: ring- (tilted) - // tobSide = 2: ring+ (tilted) - // tobSide = 3: barrel (flat) - enum TypeBarrel { nonBarrel = 0, tiltedMinus = 1, tiltedPlus = 2, flat = 3 }; - const TypeBarrel type = static_cast(tTopo->tobSide(detid)); - - // modules in the flat part of barrel are mounted on planks, while modules in tilted part are on rings - // below, "module" is the module number in the z direction (from minus z to positive), - // while "ladder" is the module number in the phi direction - - if (layer > 0 && layer <= (int)trklet::N_PSLAYER) { - if (type == tiltedMinus) { - module = static_cast(tTopo->tobRod(detid)); - ladder = static_cast(tTopo->module(detid)); - } - if (type == tiltedPlus) { - module = - trklet::N_TILTED_RINGS + trklet::N_MOD_PLANK.at(layer - 1) + static_cast(tTopo->tobRod(detid)); - ladder = static_cast(tTopo->module(detid)); - } - if (type == flat) { - module = trklet::N_TILTED_RINGS + static_cast(tTopo->module(detid)); - } + double stubbend = stub.first->bendFE(); //stub.first->rawBend() + if (ttPos.z() < -120) { + stubbend = -stubbend; } - } else if (detid.subdetId() == StripSubdetector::TID) { - layer = 1000 + static_cast(tTopo->tidRing(detid)); - ladder = static_cast(tTopo->module(detid)); - module = static_cast(tTopo->tidWheel(detid)); - } - /// Get the Inner and Outer TTCluster - edm::Ref>, TTCluster> innerCluster = - tempStubPtr->clusterRef(0); - edm::Ref>, TTCluster> outerCluster = - tempStubPtr->clusterRef(1); - - std::vector irphi; - std::vector innerrows = innerCluster->getRows(); - irphi.reserve(innerrows.size()); - for (int innerrow : innerrows) { - irphi.push_back(innerrow); - } - std::vector outerrows = outerCluster->getRows(); - for (int outerrow : outerrows) { - irphi.push_back(outerrow); - } - - // ----------------------------------------------------- - // check module orientation, if flipped, need to store that information for track fit - // ----------------------------------------------------- - - const DetId innerDetId = innerCluster->getDetId(); - const GeomDetUnit* det_inner = theTrackerGeom->idToDetUnit(innerDetId); - const auto* theGeomDet_inner = dynamic_cast(det_inner); - const PixelTopology* topol_inner = dynamic_cast(&(theGeomDet_inner->specificTopology())); - - MeasurementPoint coords_inner = innerCluster->findAverageLocalCoordinatesCentered(); - LocalPoint clustlp_inner = topol_inner->localPosition(coords_inner); - GlobalPoint posStub_inner = theGeomDet_inner->surface().toGlobal(clustlp_inner); - - const DetId outerDetId = outerCluster->getDetId(); - const GeomDetUnit* det_outer = theTrackerGeom->idToDetUnit(outerDetId); - const auto* theGeomDet_outer = dynamic_cast(det_outer); - const PixelTopology* topol_outer = dynamic_cast(&(theGeomDet_outer->specificTopology())); + ev.addStub(dtcname, + region, + layerdisk, + stubwordhex, + setup_.psModule(setup_.dtcId(region, channel)), + isFlipped, + ttPos.x(), + ttPos.y(), + ttPos.z(), + stubbend, + stub.first->innerClusterPosition(), + assocTPs); - MeasurementPoint coords_outer = outerCluster->findAverageLocalCoordinatesCentered(); - LocalPoint clustlp_outer = topol_outer->localPosition(coords_outer); - GlobalPoint posStub_outer = theGeomDet_outer->surface().toGlobal(clustlp_outer); - - bool isFlipped = (posStub_outer.mag() < posStub_inner.mag()); - - // ----------------------------------------------------- - // correct sign for stubs in negative endcap - float stub_bend = tempStubPtr->bendFE(); - float stub_pt = -1; - if (layer > 999 && posStub.z() < 0.0) { - stub_bend = -stub_bend; - } - if (!irphi.empty()) { - strip = irphi[0]; - } - - //if module FE inefficiencies are calculated, a stub is thrown out if rawBend > 100 - if ((tempStubPtr->rawBend() < 100.) && (ev.addStub(layer, - ladder, - module, - strip, - eventID, - assocTPs, - stub_pt, - stub_bend, - posStub.x(), - posStub.y(), - posStub.z(), - isPSmodule, - isFlipped))) { const trklet::L1TStub& lastStub = ev.lastStub(); - stubMap[lastStub] = tempStubPtr; + stubMap[lastStub] = stub.first; } } } @@ -628,9 +557,7 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe ev.write(asciiEventOut_); } - std::vector& tracks = eventProcessor.tracks(); - - trklet::L1SimTrack simtrk(0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); + const std::vector& tracks = eventProcessor.tracks(); // this performs the actual tracklet event processing eventProcessor.event(ev); @@ -638,20 +565,20 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe int ntracks = 0; for (auto track : tracks) { - if (track->duplicate()) + if (track.duplicate()) continue; ntracks++; // this is where we create the TTTrack object - double tmp_rinv = track->rinv(settings); - double tmp_phi = track->phi0(settings); - double tmp_tanL = track->tanL(settings); - double tmp_z0 = track->z0(settings); - double tmp_d0 = track->d0(settings); - double tmp_chi2rphi = track->chisqrphi(); - double tmp_chi2rz = track->chisqrz(); - unsigned int tmp_hit = track->hitpattern(); + double tmp_rinv = track.rinv(settings); + double tmp_phi = track.phi0(settings); + double tmp_tanL = track.tanL(settings); + double tmp_z0 = track.z0(settings); + double tmp_d0 = track.d0(settings); + double tmp_chi2rphi = track.chisqrphi(); + double tmp_chi2rz = track.chisqrz(); + unsigned int tmp_hit = track.hitpattern(); TTTrack aTrack(tmp_rinv, tmp_phi, @@ -667,18 +594,18 @@ void L1FPGATrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe settings.nHelixPar(), settings.bfield()); - unsigned int trksector = track->sector(); - unsigned int trkseed = (unsigned int)abs(track->seed()); + unsigned int trksector = track.sector(); + unsigned int trkseed = (unsigned int)abs(track.seed()); aTrack.setPhiSector(trksector); aTrack.setTrackSeedType(trkseed); - const vector& stubptrs = track->stubs(); + const vector& stubptrs = track.stubs(); vector stubs; stubs.reserve(stubptrs.size()); for (auto stubptr : stubptrs) { - stubs.push_back(*stubptr); + stubs.push_back(stubptr); } stubMapType::const_iterator it; diff --git a/L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py b/L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py index cab518307ffb2..0ca90046d6e93 100644 --- a/L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py +++ b/L1Trigger/TrackFindingTracklet/python/Tracklet_cfi.py @@ -3,11 +3,11 @@ TTTracksFromTrackletEmulation = cms.EDProducer("L1FPGATrackProducer", TTStubSource = cms.InputTag("TTStubsFromPhase2TrackerDigis","StubAccepted"), + InputTagTTDTC = cms.InputTag ( "TrackerDTCProducer", "StubAccepted" ), readMoreMcTruth = cms.bool(True), MCTruthClusterInputTag = cms.InputTag("TTClusterAssociatorFromPixelDigis", "ClusterAccepted"), MCTruthStubInputTag = cms.InputTag("TTStubAssociatorFromPixelDigis", "StubAccepted"), TrackingParticleInputTag = cms.InputTag("mix", "MergedTrackTruth"), - TrackingVertexInputTag = cms.InputTag("mix", "MergedTrackTruth"), BeamSpotSource = cms.InputTag("offlineBeamSpot"), asciiFileName = cms.untracked.string(""), # (if running on CRAB use "../../fitpattern.txt" etc instead) @@ -17,9 +17,6 @@ memoryModulesFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/memorymodules_hourglass.dat'), processingModulesFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/processingmodules_hourglass.dat'), wiresFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/wires_hourglass.dat'), - DTCLinkFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/calcNumDTCLinks.txt'), - DTCLinkLayerDiskFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/dtclinklayerdisk.dat'), - moduleCablingFile = cms.FileInPath('L1Trigger/TrackFindingTracklet/data/modules_T5v3_27SP_nonant_tracklet.dat'), # Quality Flag and Quality params TrackQuality =cms.bool(True), TrackQualityPSet = cms.PSet(TrackQualityParams) diff --git a/L1Trigger/TrackFindingTracklet/src/AllInnerStubsMemory.cc b/L1Trigger/TrackFindingTracklet/src/AllInnerStubsMemory.cc new file mode 100644 index 0000000000000..5ee9e5b1cda63 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/AllInnerStubsMemory.cc @@ -0,0 +1,24 @@ +#include "L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include + +using namespace std; +using namespace trklet; + +AllInnerStubsMemory::AllInnerStubsMemory(string name, Settings const& settings) : MemoryBase(name, settings) {} + +void AllInnerStubsMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; + const string dirS = settings_.memPath() + "Stubs/"; + openFile(first, dirS, "AllInnerStubs_"); + + for (unsigned int j = 0; j < stubs_.size(); j++) { + string stub = stubs_[j]->strinner(); + out_ << "0x"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << stub << " " << hexFormat(stub) << endl; + } + out_.close(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc index 2aef2b74ef8ca..d15cb03d753de 100644 --- a/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/AllProjectionsMemory.cc @@ -1,6 +1,7 @@ #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 @@ -9,33 +10,19 @@ using namespace trklet; using namespace std; -AllProjectionsMemory::AllProjectionsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +AllProjectionsMemory::AllProjectionsMemory(string name, Settings const& settings) : MemoryBase(name, settings) { initLayerDisk(3, layer_, disk_); } -void AllProjectionsMemory::writeAP(bool first) { +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(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirTP)) { - int fail = system((string("mkdir -p ") + dirTP).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirTP; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirTP, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc b/L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc index 315b7f668fbc9..db3993fdd74c5 100644 --- a/L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/AllStubsMemory.cc @@ -6,10 +6,10 @@ using namespace std; using namespace trklet; -AllStubsMemory::AllStubsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) {} +AllStubsMemory::AllStubsMemory(string name, Settings const& settings) : MemoryBase(name, settings) {} -void AllStubsMemory::writeStubs(bool first) { +void AllStubsMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirS = settings_.memPath() + "Stubs/"; openFile(first, dirS, "AllStubs_"); diff --git a/L1Trigger/TrackFindingTracklet/src/Cabling.cc b/L1Trigger/TrackFindingTracklet/src/Cabling.cc deleted file mode 100644 index c0b48b3e494ad..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/Cabling.cc +++ /dev/null @@ -1,126 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/Cabling.h" -#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" -#include "L1Trigger/TrackFindingTracklet/interface/DTC.h" -#include "L1Trigger/TrackFindingTracklet/interface/Util.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" -#include "FWCore/Utilities/interface/Exception.h" -#include "DataFormats/Math/interface/deltaPhi.h" - -using namespace std; -using namespace trklet; - -Cabling::Cabling(string dtcconfig, string moduleconfig, Settings const& settings) : settings_(settings) { - ifstream indtc(dtcconfig.c_str()); - assert(indtc.good()); - - string dtc; - int isec; - - while (indtc.good()) { - indtc >> dtc >> isec; - - if (!indtc.good()) - continue; - - if (dtcs_.find(dtc) == dtcs_.end()) { - dtcs_[dtc].setName(dtc); - } - - dtcs_[dtc].addSec(isec); - - string dtcbase = dtc.substr(2, dtc.size() - 2); - if (dtc[0] == 'n') { - dtcbase = "neg_" + dtc.substr(6, dtc.size() - 6); - } - if (dtcranges_.find(dtcbase) == dtcranges_.end()) { - dtcranges_[dtcbase].setName(dtcbase); - } - } - - ifstream inmodules(moduleconfig.c_str()); - - int layer, ladder, module; - - while (inmodules.good()) { - inmodules >> layer >> ladder >> module >> dtc; - - // in the cabling module map, module# 300+ is flat part of barrel, 200-299 is tilted z-, 100-199 is tilted z+ - if (module > 300) { - if (layer > 0 && layer <= (int)N_PSLAYER) { - module = (module - 300) + N_TILTED_RINGS; - } else if (layer > (int)N_PSLAYER) { - module = (module - 300); - } - } - if (module > 200) { - module = (module - 200); - } - if ((module > 100) && (layer > 0 && layer <= (int)N_PSLAYER)) { - module = (module - 100) + N_TILTED_RINGS + N_MOD_PLANK.at(layer - 1); - } - if (!inmodules.good()) - break; - modules_[layer][ladder][module] = dtc; - } -} - -const string& Cabling::dtc(int layer, int ladder, int module) const { - auto it1 = modules_.find(layer); - assert(it1 != modules_.end()); - auto it2 = it1->second.find(ladder); - assert(it2 != it1->second.end()); - auto it3 = it2->second.find(module); - if (it3 == it2->second.end()) { - throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << "Could not find stub " << layer << " " - << ladder << " " << module; - } - return it3->second; -} - -void Cabling::addphi(const string& dtc, double phi, int layer, int module) { - unsigned int layerdisk = layer - 1; - - if (layer > 1000) - layerdisk = module + N_DISK; - - assert(layerdisk < N_LAYER + N_DISK); - - int isec = dtc[0] - '0'; - - string dtcbase = dtc.substr(2, dtc.size() - 2); - if (dtc[0] == 'n') { - dtcbase = "neg_" + dtc.substr(6, dtc.size() - 6); - isec = dtc[4] - '0'; - } - - double phisec = reco::reduceRange(phi - isec * settings_.dphisector()); - - assert(dtcranges_.find(dtcbase) != dtcranges_.end()); - - dtcranges_[dtcbase].addphi(phisec, layerdisk); -} - -void Cabling::writephirange() const { - ofstream out("dtcphirange.txt"); - - for (auto&& it : dtcranges_) { - for (unsigned int i = 0; i < N_LAYER + N_DISK; i++) { - double min = it.second.min(i); - double max = it.second.max(i); - if (min < max) { - out << it.first << " " << i + 1 << " " << min << " " << max << endl; - } - } - } -} - -std::vector Cabling::DTCs() const { - std::vector tmp; - - for (const auto& it : dtcs_) { - tmp.push_back(it.first); - } - - return tmp; -} diff --git a/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc b/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc index 41b0326f7e5f0..06092b28350ed 100644 --- a/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/CandidateMatchMemory.cc @@ -11,8 +11,7 @@ using namespace std; using namespace trklet; -CandidateMatchMemory::CandidateMatchMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) {} +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); @@ -28,7 +27,8 @@ void CandidateMatchMemory::addMatch(std::pair tracklet, const St matches_.push_back(tmp); } -void CandidateMatchMemory::writeCM(bool first) { +void CandidateMatchMemory::writeCM(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirM = settings_.memPath() + "Matches/"; std::ostringstream oss; @@ -36,21 +36,7 @@ void CandidateMatchMemory::writeCM(bool first) { << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirM)) { - int fail = system((string("mkdir -p ") + dirM).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirM; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirM, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc b/L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc index 9c90b757e7225..b5adf1859e29c 100644 --- a/L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/CleanTrackMemory.cc @@ -7,35 +7,21 @@ using namespace std; using namespace trklet; -CleanTrackMemory::CleanTrackMemory( - string name, Settings const& settings, unsigned int iSector, double phimin, double phimax) - : MemoryBase(name, settings, iSector) { +CleanTrackMemory::CleanTrackMemory(string name, Settings const& settings, double phimin, double phimax) + : MemoryBase(name, settings) { phimin_ = phimin; phimax_ = phimax; } -void CleanTrackMemory::writeCT(bool first) { +void CleanTrackMemory::writeCT(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirCT = settings_.memPath() + "CleanTrack/"; std::ostringstream oss; oss << dirCT << "CleanTrack_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirCT)) { - int fail = system((string("mkdir -p ") + dirCT).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirCT; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirCT, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/DTC.cc b/L1Trigger/TrackFindingTracklet/src/DTC.cc deleted file mode 100644 index 6fb97d524565e..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/DTC.cc +++ /dev/null @@ -1,52 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/DTC.h" -#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" -#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" - -#include "DataFormats/Math/interface/deltaPhi.h" - -using namespace std; -using namespace trklet; - -DTC::DTC(string name) { - name_ = name; - for (unsigned int i = 0; i < N_LAYER + N_DISK; i++) { - phimin_[i] = 10.0; - phimax_[i] = -10.0; - } -} - -void DTC::setName(string name) { name_ = name; } - -void DTC::addSec(int sector) { sectors_.push_back(sector); } - -void DTC::addphi(double phi, unsigned int layerdisk) { - assert(layerdisk < N_LAYER + N_DISK); - if (phi < phimin_[layerdisk]) - phimin_[layerdisk] = phi; - if (phi > phimax_[layerdisk]) - phimax_[layerdisk] = phi; -} - -void DTC::addLink(double phimin, double phimax) { - DTCLink link(phimin, phimax); - links_.push_back(link); -} - -int DTC::addStub(std::pair stub) { - double phi = reco::reduceRange(stub.second->phi()); - bool overlaplayer = ((stub.second->layer() + 1) % 2 == 0); - int added = 0; - for (auto& link : links_) { - if (link.inRange(phi, overlaplayer)) { - added++; - link.addStub(stub); - } - } - return added; -} - -void DTC::clean() { - for (auto& link : links_) { - link.clean(); - } -} diff --git a/L1Trigger/TrackFindingTracklet/src/DTCLink.cc b/L1Trigger/TrackFindingTracklet/src/DTCLink.cc deleted file mode 100644 index 8b5c59c671fd2..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/DTCLink.cc +++ /dev/null @@ -1,29 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/DTCLink.h" - -using namespace std; -using namespace trklet; - -DTCLink::DTCLink(double phimin, double phimax) { - if (phimin > M_PI) { - phimin -= 2 * M_PI; - phimax -= 2 * M_PI; - } - assert(phimax > phimin); - phimin_ = phimin; - phimax_ = phimax; -} - -void DTCLink::addStub(std::pair stub) { stubs_.push_back(stub); } - -bool DTCLink::inRange(double phi, bool overlaplayer) { - double phimax = phimax_; - double phimin = phimin_; - if (overlaplayer) { - double dphi = phimax - phimin; - assert(dphi > 0.0); - assert(dphi < M_PI); - phimin -= dphi / 6.0; - phimax += dphi / 6.0; - } - return (phi < phimax && phi > phimin) || (phi + 2 * M_PI < phimax && phi + 2 * M_PI > phimin); -} diff --git a/L1Trigger/TrackFindingTracklet/src/DTCLinkMemory.cc b/L1Trigger/TrackFindingTracklet/src/DTCLinkMemory.cc new file mode 100644 index 0000000000000..d80531fa86687 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/DTCLinkMemory.cc @@ -0,0 +1,71 @@ +#include "L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" + +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" + +#include +#include +#include +#include + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace trklet; +using namespace std; + +DTCLinkMemory::DTCLinkMemory(string name, Settings const& settings, double, double) : MemoryBase(name, settings) {} + +void DTCLinkMemory::addStub(const L1TStub& al1stub, const Stub& stub) { + //Make new objects owned by the dtclink memory and save in list of stubs + if (stubs_.size() < settings_.maxStep("IR")) { + Stub* stubptr = new Stub(stub); + stubptr->setl1tstub(new L1TStub(al1stub)); + + stubs_.emplace_back(stubptr); + } +} + +void DTCLinkMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; + + const string dirIS = settings_.memPath() + "InputStubs/"; + openFile(first, dirIS, "Link_"); + + for (unsigned int j = 0; j < stubs_.size(); j++) { + string dtcname = stubs_[j]->l1tstub()->DTClink(); + int layerdisk = stubs_[j]->l1tstub()->layerdisk(); + + //If the string starts with 'neg' skip the first three character + int start = dtcname.substr(0, 3) == "neg" ? 3 : 0; + + //For the dtcbase name remove the leading 'neg' if in the name and the trailing '_A' or '_B' + string dtcbase = dtcname.substr(start, dtcname.size() - 2 - start); + + const vector& layers = settings_.dtcLayers(dtcbase); + + int lcode = -1; + for (unsigned int index = 0; index < layers.size(); index++) { + if (layerdisk == layers[index]) { + lcode = index; + } + } + assert(lcode != -1); + + FPGAWord ldcode(lcode, 2, true); + + string stub = stubs_[j]->str() + "|" + ldcode.str() + "|1"; + out_ << std::setfill('0') << std::setw(2); + out_ << hex << j << dec; + out_ << " " << stub << " " << trklet::hexFormat(stub) << endl; + } + out_.close(); +} + +void DTCLinkMemory::clean() { + for (auto& stub : stubs_) { + delete stub->l1tstub(); + delete stub; + } + stubs_.clear(); +} diff --git a/L1Trigger/TrackFindingTracklet/src/DiskProjection.cc b/L1Trigger/TrackFindingTracklet/src/DiskProjection.cc deleted file mode 100644 index 4fa054be39805..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/DiskProjection.cc +++ /dev/null @@ -1,94 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/DiskProjection.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -#include -#include - -using namespace std; -using namespace trklet; - -void DiskProjection::init(Settings const& settings, - int projdisk, - double zproj, - int iphiproj, - int irproj, - int iphider, - int irder, - double phiproj, - double rproj, - double phiprojder, - double rprojder, - double phiprojapprox, - double rprojapprox, - double phiprojderapprox, - double rprojderapprox) { - assert(abs(projdisk) >= 0); - assert(abs(projdisk) <= N_DISK); - - valid_ = true; - - zproj_ = zproj; - - projdisk_ = projdisk; - - assert(iphiproj >= 0); - - fpgaphiproj_.set(iphiproj, settings.nphibitsstub(0), true, __LINE__, __FILE__); - int iphivm = (iphiproj >> (settings.nphibitsstub(0) - 5)) & 0x7; - if ((abs(projdisk_) % 2) == 1) { - iphivm ^= 4; - } - fpgaphiprojvm_.set(iphivm, 3, true, __LINE__, __FILE__); - fpgarproj_.set(irproj, settings.nrbitsstub(6), false, __LINE__, __FILE__); - int irvm = irproj >> (13 - 7) & 0xf; - fpgarprojvm_.set(irvm, 4, true, __LINE__, __FILE__); - fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__); - fpgarprojder_.set(irder, settings.nrbitsprojderdisk(), false, __LINE__, __FILE__); - - //TODO the -3 and +3 should be evaluated and efficiency for matching hits checked. - //This code should be migrated in the ProjectionRouter - int rbin1 = 8.0 * (irproj * settings.krprojshiftdisk() - 3 - settings.rmindiskvm()) / - (settings.rmaxdisk() - settings.rmindiskvm()); - int rbin2 = 8.0 * (irproj * settings.krprojshiftdisk() + 3 - settings.rmindiskvm()) / - (settings.rmaxdisk() - settings.rmindiskvm()); - - if (irproj * settings.krprojshiftdisk() < 20.0) { - edm::LogPrint("Tracklet") << " WARNING : irproj = " << irproj << " " << irproj * settings.krprojshiftdisk() << " " - << projdisk_; - } - - if (rbin1 < 0) - rbin1 = 0; - rbin2 = clamp(rbin2, 0, 7); - - assert(rbin1 <= rbin2); - assert(rbin2 - rbin1 <= 1); - - int finer = 64 * - ((irproj * settings.krprojshiftdisk() - settings.rmindiskvm()) - - rbin1 * (settings.rmaxdisk() - settings.rmindiskvm()) / 8.0) / - (settings.rmaxdisk() - settings.rmindiskvm()); - - finer = clamp(finer, 0, 15); - - int diff = rbin1 != rbin2; - if (irder < 0) - rbin1 += 8; - - fpgarbin1projvm_.set(rbin1, 4, true, __LINE__, __FILE__); // first r bin - fpgarbin2projvm_.set(diff, 1, true, __LINE__, __FILE__); // need to check adjacent r bin - - fpgafinervm_.set(finer, 4, true, __LINE__, __FILE__); // fine r postions starting at rbin1 - - phiproj_ = phiproj; - rproj_ = rproj; - phiprojder_ = phiprojder; - rprojder_ = rprojder; - - phiprojapprox_ = phiprojapprox; - rprojapprox_ = rprojapprox; - phiprojderapprox_ = phiprojderapprox; - rprojderapprox_ = rprojderapprox; -} diff --git a/L1Trigger/TrackFindingTracklet/src/DiskResidual.cc b/L1Trigger/TrackFindingTracklet/src/DiskResidual.cc deleted file mode 100644 index 99213f18b9848..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/DiskResidual.cc +++ /dev/null @@ -1,47 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/DiskResidual.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" - -using namespace std; -using namespace trklet; - -void DiskResidual::init(Settings const& settings, - int disk, - int iphiresid, - int irresid, - int istubid, - double phiresid, - double rresid, - double phiresidapprox, - double rresidapprox, - double zstub, - double alpha, - FPGAWord ialpha, - const Stub* stubptr) { - assert(abs(disk) > 0); - assert(abs(disk) <= N_DISK); - - if (valid_ && (std::abs(iphiresid) > std::abs(fpgaphiresid_.value()))) - return; - - valid_ = true; - - disk_ = disk; - - fpgaphiresid_.set(iphiresid, settings.phiresidbits(), false, __LINE__, __FILE__); - fpgarresid_.set(irresid, settings.rresidbits(), false, __LINE__, __FILE__); - assert(istubid >= 0); - unsigned int nbitsstubid = 10; - fpgastubid_.set(istubid, nbitsstubid, true, __LINE__, __FILE__); - assert(!fpgaphiresid_.atExtreme()); - - phiresid_ = phiresid; - rresid_ = rresid; - - phiresidapprox_ = phiresidapprox; - rresidapprox_ = rresidapprox; - - zstub_ = zstub; - alpha_ = alpha; - ialpha_ = ialpha; - stubptr_ = stubptr; -} diff --git a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc index bf17095e35a09..20bf5e741e2b6 100644 --- a/L1Trigger/TrackFindingTracklet/src/FitTrack.cc +++ b/L1Trigger/TrackFindingTracklet/src/FitTrack.cc @@ -11,8 +11,8 @@ using namespace std; using namespace trklet; -FitTrack::FitTrack(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector), trackfit_(nullptr) {} +FitTrack::FitTrack(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global), trackfit_(nullptr) {} void FitTrack::addOutput(MemoryBase* memory, string output) { if (settings_.writetrace()) { @@ -200,15 +200,16 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: layers[nlayers++] = l; continue; } - if (tracklet->match(l)) { + if (tracklet->match(l - 1)) { + const Residual& resid = tracklet->resid(l - 1); lmatches.set(N_LAYER - l); layermask |= (1 << (N_LAYER - l)); - phiresid[nlayers] = tracklet->phiresidapprox(l); - zresid[nlayers] = tracklet->zresidapprox(l); - phiresidexact[nlayers] = tracklet->phiresid(l); - zresidexact[nlayers] = tracklet->zresid(l); - iphiresid[nlayers] = tracklet->fpgaphiresid(l).value(); - izresid[nlayers] = tracklet->fpgazresid(l).value(); + phiresid[nlayers] = resid.phiresidapprox(); + zresid[nlayers] = resid.rzresidapprox(); + phiresidexact[nlayers] = resid.phiresid(); + zresidexact[nlayers] = resid.rzresid(); + iphiresid[nlayers] = resid.fpgaphiresid().value(); + izresid[nlayers] = resid.fpgarzresid().value(); layers[nlayers++] = l; } @@ -223,13 +224,15 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: if (ndisks + nlayers >= N_FITSTUB) continue; - if (tracklet->matchdisk(d)) { - if (std::abs(tracklet->alphadisk(d)) < 1e-20) { + if (tracklet->match(N_LAYER + d - 1)) { + const Residual& resid = tracklet->resid(N_LAYER + d - 1); + double pitch = settings_.stripPitch(resid.stubptr()->l1tstub()->isPSmodule()); + if (std::abs(resid.stubptr()->l1tstub()->alpha(pitch)) < 1e-20) { dmatches.set(2 * d - 1); diskmask |= (1 << (2 * (N_DISK - d) + 1)); } else { - int ialpha = tracklet->ialphadisk(d).value(); - int nalpha = tracklet->ialphadisk(d).nbits(); + int ialpha = resid.stubptr()->alpha().value(); + int nalpha = resid.stubptr()->alpha().nbits(); nalpha = nalpha - settings_.alphaBitsTable(); ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha); @@ -239,13 +242,13 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: diskmask |= (1 << (2 * (N_DISK - d))); mult = mult << settings_.alphaBitsTable(); } - alpha[ndisks] = tracklet->alphadisk(d); - phiresid[nlayers + ndisks] = tracklet->phiresidapproxdisk(d); - zresid[nlayers + ndisks] = tracklet->rresidapproxdisk(d); - phiresidexact[nlayers + ndisks] = tracklet->phiresiddisk(d); - zresidexact[nlayers + ndisks] = tracklet->rresiddisk(d); - iphiresid[nlayers + ndisks] = tracklet->fpgaphiresiddisk(d).value(); - izresid[nlayers + ndisks] = tracklet->fpgarresiddisk(d).value(); + alpha[ndisks] = resid.stubptr()->l1tstub()->alpha(pitch); + phiresid[nlayers + ndisks] = resid.phiresidapprox(); + zresid[nlayers + ndisks] = resid.rzresidapprox(); + phiresidexact[nlayers + ndisks] = resid.phiresid(); + zresidexact[nlayers + ndisks] = resid.rzresid(); + iphiresid[nlayers + ndisks] = resid.fpgaphiresid().value(); + izresid[nlayers + ndisks] = resid.fpgarzresid().value(); disks[ndisks++] = d; } @@ -261,17 +264,17 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: if (tracklet->isDisk()) { for (unsigned int l = 1; l <= 2; l++) { - if (tracklet->match(l)) { + if (tracklet->match(l - 1)) { lmatches.set(N_LAYER - l); layermask |= (1 << (N_LAYER - l)); - - phiresid[nlayers] = tracklet->phiresidapprox(l); - zresid[nlayers] = tracklet->zresidapprox(l); - phiresidexact[nlayers] = tracklet->phiresid(l); - zresidexact[nlayers] = tracklet->zresid(l); - iphiresid[nlayers] = tracklet->fpgaphiresid(l).value(); - izresid[nlayers] = tracklet->fpgazresid(l).value(); + const Residual& resid = tracklet->resid(l - 1); + phiresid[nlayers] = resid.phiresidapprox(); + zresid[nlayers] = resid.rzresidapprox(); + phiresidexact[nlayers] = resid.phiresid(); + zresidexact[nlayers] = resid.rzresid(); + iphiresid[nlayers] = resid.fpgaphiresid().value(); + izresid[nlayers] = resid.fpgarzresid().value(); layers[nlayers++] = l; } @@ -296,13 +299,15 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: if (ndisks + nlayers >= N_FITSTUB) continue; - if (tracklet->matchdisk(d)) { - if (std::abs(tracklet->alphadisk(d)) < 1e-20) { + if (tracklet->match(N_LAYER + abs(d) - 1)) { + const Residual& resid = tracklet->resid(N_LAYER + abs(d) - 1); + double pitch = settings_.stripPitch(resid.stubptr()->l1tstub()->isPSmodule()); + if (std::abs(resid.stubptr()->l1tstub()->alpha(pitch)) < 1e-20) { dmatches.set(2 * d1 - 1); diskmask |= (1 << (2 * (N_DISK - d1) + 1)); } else { - int ialpha = tracklet->ialphadisk(d).value(); - int nalpha = tracklet->ialphadisk(d).nbits(); + int ialpha = resid.stubptr()->alpha().value(); + int nalpha = resid.stubptr()->alpha().nbits(); nalpha = nalpha - settings_.alphaBitsTable(); ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha); @@ -313,15 +318,15 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: mult = mult << settings_.alphaBitsTable(); } - alpha[ndisks] = tracklet->alphadisk(d); - assert(std::abs(tracklet->phiresidapproxdisk(d)) < 0.2); - phiresid[nlayers + ndisks] = tracklet->phiresidapproxdisk(d); - zresid[nlayers + ndisks] = tracklet->rresidapproxdisk(d); - assert(std::abs(tracklet->phiresiddisk(d)) < 0.2); - phiresidexact[nlayers + ndisks] = tracklet->phiresiddisk(d); - zresidexact[nlayers + ndisks] = tracklet->rresiddisk(d); - iphiresid[nlayers + ndisks] = tracklet->fpgaphiresiddisk(d).value(); - izresid[nlayers + ndisks] = tracklet->fpgarresiddisk(d).value(); + alpha[ndisks] = resid.stubptr()->l1tstub()->alpha(pitch); + assert(std::abs(resid.phiresidapprox()) < 0.2); + phiresid[nlayers + ndisks] = resid.phiresidapprox(); + zresid[nlayers + ndisks] = resid.rzresidapprox(); + assert(std::abs(resid.phiresid()) < 0.2); + phiresidexact[nlayers + ndisks] = resid.phiresid(); + zresidexact[nlayers + ndisks] = resid.rzresid(); + iphiresid[nlayers + ndisks] = resid.fpgaphiresid().value(); + izresid[nlayers + ndisks] = resid.fpgarzresid().value(); disks[ndisks++] = d; } @@ -336,17 +341,18 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: layers[nlayers++] = l; continue; } - if (tracklet->match(l)) { + if (tracklet->match(l - 1)) { lmatches.set(N_LAYER - l); layermask |= (1 << (N_LAYER - l)); - assert(std::abs(tracklet->phiresidapprox(l)) < 0.2); - phiresid[nlayers] = tracklet->phiresidapprox(l); - zresid[nlayers] = tracklet->zresidapprox(l); - assert(std::abs(tracklet->phiresid(l)) < 0.2); - phiresidexact[nlayers] = tracklet->phiresid(l); - zresidexact[nlayers] = tracklet->zresid(l); - iphiresid[nlayers] = tracklet->fpgaphiresid(l).value(); - izresid[nlayers] = tracklet->fpgazresid(l).value(); + const Residual& resid = tracklet->resid(l - 1); + assert(std::abs(resid.phiresidapprox()) < 0.2); + phiresid[nlayers] = resid.phiresidapprox(); + zresid[nlayers] = resid.rzresidapprox(); + assert(std::abs(resid.phiresid()) < 0.2); + phiresidexact[nlayers] = resid.phiresid(); + zresidexact[nlayers] = resid.rzresid(); + iphiresid[nlayers] = resid.fpgaphiresid().value(); + izresid[nlayers] = resid.fpgarzresid().value(); layers[nlayers++] = l; } @@ -368,15 +374,17 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: if (ndisks + nlayers >= N_FITSTUB) continue; - if (tracklet->matchdisk(d)) { - if (std::abs(tracklet->alphadisk(d)) < 1e-20) { + if (tracklet->match(N_LAYER + abs(d) - 1)) { + const Residual& resid = tracklet->resid(N_LAYER + abs(d) - 1); + double pitch = settings_.stripPitch(resid.stubptr()->l1tstub()->isPSmodule()); + if (std::abs(resid.stubptr()->l1tstub()->alpha(pitch)) < 1e-20) { dmatches.set(2 * (N_DISK - d1)); diskmask |= (1 << (2 * (N_DISK - d1) + 1)); FPGAWord tmp; tmp.set(diskmask, 10); } else { - int ialpha = tracklet->ialphadisk(d).value(); - int nalpha = tracklet->ialphadisk(d).nbits(); + int ialpha = resid.stubptr()->alpha().value(); + int nalpha = resid.stubptr()->alpha().nbits(); nalpha = nalpha - settings_.alphaBitsTable(); ialpha = (1 << (settings_.alphaBitsTable() - 1)) + (ialpha >> nalpha); @@ -389,15 +397,15 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: mult = mult << settings_.alphaBitsTable(); } - alpha[ndisks] = tracklet->alphadisk(d); - assert(std::abs(tracklet->phiresidapproxdisk(d)) < 0.2); - phiresid[nlayers + ndisks] = tracklet->phiresidapproxdisk(d); - zresid[nlayers + ndisks] = tracklet->rresidapproxdisk(d); - assert(std::abs(tracklet->phiresiddisk(d)) < 0.2); - phiresidexact[nlayers + ndisks] = tracklet->phiresiddisk(d); - zresidexact[nlayers + ndisks] = tracklet->rresiddisk(d); - iphiresid[nlayers + ndisks] = tracklet->fpgaphiresiddisk(d).value(); - izresid[nlayers + ndisks] = tracklet->fpgarresiddisk(d).value(); + alpha[ndisks] = resid.stubptr()->l1tstub()->alpha(pitch); + assert(std::abs(resid.phiresidapprox()) < 0.2); + phiresid[nlayers + ndisks] = resid.phiresidapprox(); + zresid[nlayers + ndisks] = resid.rzresidapprox(); + assert(std::abs(resid.phiresid()) < 0.2); + phiresidexact[nlayers + ndisks] = resid.phiresid(); + zresidexact[nlayers + ndisks] = resid.rzresid(); + iphiresid[nlayers + ndisks] = resid.fpgaphiresid().value(); + izresid[nlayers + ndisks] = resid.fpgarzresid().value(); disks[ndisks++] = d; } @@ -448,16 +456,16 @@ void FitTrack::trackFitChisq(Tracklet* tracklet, std::vector&, std: r[i] = settings_.rmean(layers[i] - 1); if (layers[i] == tracklet->layer()) { if (tracklet->isOverlap()) { - realrstub[i] = tracklet->outerStub()->r(); + realrstub[i] = tracklet->outerFPGAStub()->l1tstub()->r(); } else { - realrstub[i] = tracklet->innerStub()->r(); + realrstub[i] = tracklet->innerFPGAStub()->l1tstub()->r(); } } if (layers[i] == tracklet->layer() + 1) { - realrstub[i] = tracklet->outerStub()->r(); + realrstub[i] = tracklet->outerFPGAStub()->l1tstub()->r(); } - if (tracklet->validResid(layers[i]) && layers[i] < 4) { - const Stub* stubptr = tracklet->stubptr(layers[i]); + if (tracklet->match(layers[i] - 1) && layers[i] < 4) { + const Stub* stubptr = tracklet->resid(layers[i] - 1).stubptr(); realrstub[i] = stubptr->l1tstub()->r(); assert(std::abs(realrstub[i] - r[i]) < 5.0); } @@ -859,19 +867,21 @@ std::vector FitTrack::orderedMatches(vector& fullma return tmp; } -void FitTrack::execute() { +void FitTrack::execute(unsigned int iSector) { // merge const std::vector& matches1 = orderedMatches(fullmatch1_); const std::vector& matches2 = orderedMatches(fullmatch2_); const std::vector& matches3 = orderedMatches(fullmatch3_); const std::vector& matches4 = orderedMatches(fullmatch4_); + 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() << "[" << iSector_ << "] matches : " << matches1.size() << " " - << matches2.size() << " " << matches3.size() << " " << matches4.size(); + edm::LogVerbatim("Tracklet") << getName() << " matches : " << matches1.size() << " " << matches2.size() << " " + << matches3.size() << " " << matches4.size(); } unsigned int indexArray[4]; @@ -1002,8 +1012,8 @@ void FitTrack::execute() { assert(trackfit_ != nullptr); if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << bestTracklet->getISeed() - << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" + << " " << bestTracklet->getISeed() << endl; fout.close(); } bestTracklet->setTrackIndex(trackfit_->nTracks()); diff --git a/L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc b/L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc index 1f43b6a1f0439..f4bf27d54e5e1 100644 --- a/L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/FullMatchMemory.cc @@ -9,8 +9,7 @@ using namespace std; using namespace trklet; -FullMatchMemory::FullMatchMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +FullMatchMemory::FullMatchMemory(string name, Settings const& settings) : MemoryBase(name, settings) { size_t pos = find_nth(name, 0, "_", 1); assert(pos != string::npos); initLayerDisk(pos + 1, layer_, disk_); @@ -39,28 +38,15 @@ void FullMatchMemory::addMatch(Tracklet* tracklet, const Stub* stub) { matches_.push_back(tmp); } -void FullMatchMemory::writeMC(bool first) { +void FullMatchMemory::writeMC(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirM = settings_.memPath() + "Matches/"; std::ostringstream oss; oss << dirM << "FullMatches_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirM)) { - int fail = system((string("mkdir -p ") + dirM).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirM; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirM, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/HybridFit.cc b/L1Trigger/TrackFindingTracklet/src/HybridFit.cc index 9d129fa24db53..82b6233e31c14 100644 --- a/L1Trigger/TrackFindingTracklet/src/HybridFit.cc +++ b/L1Trigger/TrackFindingTracklet/src/HybridFit.cc @@ -75,7 +75,7 @@ void HybridFit::Fit(Tracklet* tracklet, std::vector& trackstublist) double alpha = L1stubptr->alpha(settings_.stripPitch(psmodule)); bool isTilted = L1stubptr->isTilted(); - bool isBarrel = trackstublist[k]->isBarrel(); + bool isBarrel = trackstublist[k]->layerdisk() < N_LAYER; int kflayer; if (isBarrel) { // Barrel-specific diff --git a/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc b/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc index ddfd115a53fcf..92affaed962c9 100644 --- a/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/InputLinkMemory.cc @@ -1,7 +1,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" #include "L1Trigger/TrackFindingTracklet/interface/Stub.h" -#include "L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h" + #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" #include @@ -14,78 +14,12 @@ using namespace trklet; using namespace std; -InputLinkMemory::InputLinkMemory(string name, Settings const& settings, unsigned int iSector, double, double) - : MemoryBase(name, settings, iSector) { - string subname = name.substr(5, 7); - phiregion_ = subname[3] - 'A'; - assert(phiregion_ >= 0 && phiregion_ < 8); - - layerdisk_ = initLayerDisk(3); -} - -bool InputLinkMemory::addStub( - Settings const& settings, Globals* globals, L1TStub& al1stub, Stub& stub, string dtc = "") { - if (layerdisk_ < N_LAYER && globals->phiCorr(layerdisk_) == nullptr) { - globals->phiCorr(layerdisk_) = new VMRouterPhiCorrTable(settings); - int nbits = 3; - if (layerdisk_ >= N_PSLAYER) - nbits = 4; - globals->phiCorr(layerdisk_)->init(layerdisk_ + 1, nbits, 3); - } - - unsigned int stublayerdisk = stub.layerdisk(); - assert(stublayerdisk < 11); - - if (stublayerdisk != layerdisk_) - return false; - - if (layerdisk_ < N_LAYER) { - FPGAWord r = stub.r(); - int bendbin = stub.bend().value(); - int rbin = (r.value() + (1 << (r.nbits() - 1))) >> (r.nbits() - 3); - const VMRouterPhiCorrTable& phiCorrTable = *globals->phiCorr(layerdisk_); - int iphicorr = phiCorrTable.getphiCorrValue(bendbin, rbin); - stub.setPhiCorr(iphicorr); - } - - FPGAWord iphi = stub.phicorr(); - unsigned int nallbits = settings_.nbitsallstubs(layerdisk_); - int phibin = iphi.bits(iphi.nbits() - nallbits, nallbits); - int iphivmRaw = iphi.bits(iphi.nbits() - 5, 5); - - if (phibin != phiregion_) - return false; +InputLinkMemory::InputLinkMemory(string name, Settings const& settings, double, double) : MemoryBase(name, settings) {} - if (getName().substr(10, dtc.size()) != dtc) - return false; +void InputLinkMemory::addStub(Stub* stub) { stubs_.push_back(stub); } - string half = getName().substr(getName().size() - 3, 3); - if (half[1] != 'n') { - half = getName().substr(getName().size() - 1, 1); - } - - assert(half[0] == 'A' || half[0] == 'B'); - - if (half[0] == 'B' && iphivmRaw <= 15) - return false; - if (half[0] == 'A' && iphivmRaw > 15) - return false; - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Will add stub in " << getName() << " " - << "iphiwmRaw = " << iphivmRaw << " phi=" << al1stub.phi() << " z=" << al1stub.z() - << " r=" << al1stub.r(); - } - if (stubs_.size() < settings_.maxStep("Link")) { - Stub* stubptr = new Stub(stub); - stubptr->setl1tstub(new L1TStub(al1stub)); - - stubs_.emplace_back(stubptr); - } - return true; -} - -void InputLinkMemory::writeStubs(bool first) { +void InputLinkMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirIS = settings_.memPath() + "InputStubs/"; openFile(first, dirIS, "InputStubs_"); @@ -98,10 +32,4 @@ void InputLinkMemory::writeStubs(bool first) { out_.close(); } -void InputLinkMemory::clean() { - for (auto& stub : stubs_) { - delete stub->l1tstub(); - delete stub; - } - stubs_.clear(); -} +void InputLinkMemory::clean() { stubs_.clear(); } diff --git a/L1Trigger/TrackFindingTracklet/src/InputRouter.cc b/L1Trigger/TrackFindingTracklet/src/InputRouter.cc new file mode 100644 index 0000000000000..2ee8e965a90c1 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/InputRouter.cc @@ -0,0 +1,79 @@ +#include "L1Trigger/TrackFindingTracklet/interface/InputRouter.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" +#include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "FWCore/Utilities/interface/Exception.h" + +using namespace std; +using namespace trklet; + +InputRouter::InputRouter(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) {} + +void InputRouter::addOutput(MemoryBase* memory, string output) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " + << output; + } + + if (output == "stubout") { + InputLinkMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + unsigned int layerdisk = tmp->getName()[4] - '1'; + if (tmp->getName()[3] == 'D') { + layerdisk += N_LAYER; + } + assert(layerdisk < N_LAYER + N_DISK); + unsigned int phireg = tmp->getName()[8] - 'A'; + std::pair layerphireg(layerdisk, phireg); + irstubs_.emplace_back(layerphireg, tmp); + return; + } + + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find output : " << output; +} + +void InputRouter::addInput(MemoryBase* memory, string input) { + if (settings_.writetrace()) { + edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " + << input; + } + if (input == "stubin") { + dtcstubs_ = dynamic_cast(memory); + assert(dtcstubs_ != nullptr); + return; + } + throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; +} + +void InputRouter::execute() { + for (unsigned int i = 0; i < settings_.maxStep("IR"); i++) { + if (i >= dtcstubs_->nStubs()) { + break; + } + + Stub* stub = dtcstubs_->getStub(i); + + unsigned int layerdisk = stub->l1tstub()->layerdisk(); + + FPGAWord iphi = stub->phicorr(); + unsigned int iphipos = iphi.value() >> (iphi.nbits() - settings_.nbitsallstubs(layerdisk)); + + std::pair layerphireg(layerdisk, iphipos); + + //Fill inner allstubs memories - in HLS this is the same write to multiple memories + int iadd = 0; + for (auto& irstubmem : irstubs_) { + if (layerphireg == irstubmem.first) { + irstubmem.second->addStub(stub); + iadd++; + } + } + assert(iadd == 1); + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/L1SimTrack.cc b/L1Trigger/TrackFindingTracklet/src/L1SimTrack.cc new file mode 100644 index 0000000000000..e0744ff66763c --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/L1SimTrack.cc @@ -0,0 +1,37 @@ +#include "L1Trigger/TrackFindingTracklet/interface/L1SimTrack.h" +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +using namespace std; +using namespace trklet; + +L1SimTrack::L1SimTrack() { + eventid_ = -1; + trackid_ = -1; +} + +L1SimTrack::L1SimTrack( + int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz) { + eventid_ = eventid; + trackid_ = trackid; + type_ = type; + pt_ = pt; + eta_ = eta; + phi_ = phi; + vx_ = vx; + vy_ = vy; + vz_ = vz; +} + +void L1SimTrack::write(ofstream& out) { + if (pt_ > -2.0) { + out << "SimTrack: " << eventid_ << "\t" << trackid_ << "\t" << type_ << "\t" << pt_ << "\t" << eta_ << "\t" << phi_ + << "\t" << vx_ << "\t" << vy_ << "\t" << vz_ << "\t" << endl; + } +} + +void L1SimTrack::write(ostream& out) { + if (pt_ > -2) { + out << "SimTrack: " << eventid_ << "\t" << trackid_ << "\t" << type_ << "\t" << pt_ << "\t" << eta_ << "\t" << phi_ + << "\t" << vx_ << "\t" << vy_ << "\t" << vz_ << "\t" << endl; + } +} diff --git a/L1Trigger/TrackFindingTracklet/src/L1TStub.cc b/L1Trigger/TrackFindingTracklet/src/L1TStub.cc index 1ae8497e75396..d7cc37d26b863 100644 --- a/L1Trigger/TrackFindingTracklet/src/L1TStub.cc +++ b/L1Trigger/TrackFindingTracklet/src/L1TStub.cc @@ -1,42 +1,46 @@ #include "L1Trigger/TrackFindingTracklet/interface/L1TStub.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" using namespace std; using namespace trklet; L1TStub::L1TStub() {} -L1TStub::L1TStub(int eventid, - vector tps, - int iphi, - int iz, - int layer, - int ladder, - int module, - int strip, +L1TStub::L1TStub(std::string DTClink, + int region, + int layerdisk, + std::string stubword, + int isPSmodule, + int isFlipped, double x, double y, double z, - double sigmax, - double sigmaz, - double pt, double bend, - int isPSmodule, - int isFlipped) { - eventid_ = eventid; + double strip, + std::vector tps) { + DTClink_ = DTClink; + layerdisk_ = layerdisk; + region_ = region; + stubword_ = stubword; + eventid_ = -1; tps_ = tps; - iphi_ = iphi; - iz_ = iz; - layer_ = layer; - ladder_ = ladder; - module_ = module; + iphi_ = -1; + iz_ = -1; + layer_ = layerdisk; + if (layerdisk >= N_LAYER) { + layer_ = 1000 + layerdisk - N_LAYER + 1; + if (z < 0.0) + layer_ += 1000; + } + + ladder_ = -1; + module_ = -1; strip_ = strip; x_ = x; y_ = y; z_ = z; - sigmax_ = sigmax; - sigmaz_ = sigmaz; - pt_ = pt; + sigmax_ = -1.0; + sigmaz_ = -1.0; + pt_ = -1.0; bend_ = bend; isPSmodule_ = isPSmodule; isFlipped_ = isFlipped; @@ -45,18 +49,8 @@ L1TStub::L1TStub(int eventid, } void L1TStub::write(ofstream& out) { - out << "Stub: " << layer_ + 1 << "\t" << ladder_ << "\t" << module_ << "\t" << strip_ << "\t" << eventid_ << "\t" - << pt_ << "\t" << x_ << "\t" << y_ << "\t" << z_ << "\t" << bend_ << "\t" << isPSmodule_ << "\t" << isFlipped_ - << "\t" << tps_.size() << " \t"; - for (int itp : tps_) { - out << itp << " \t"; - } - out << endl; -} - -void L1TStub::write(ostream& out) { - out << "Stub: " << layer_ + 1 << "\t" << ladder_ << "\t" << module_ << "\t" << strip_ << "\t" << eventid_ << "\t" - << pt_ << "\t" << x_ << "\t" << y_ << "\t" << z_ << "\t" << bend_ << "\t" << isPSmodule_ << "\t" << isFlipped_ + out << "Stub: " << DTClink_ << "\t" << region_ << "\t" << layerdisk_ << "\t" << stubword_ << "\t" << isPSmodule_ + << "\t" << isFlipped_ << "\t" << x_ << "\t" << y_ << "\t" << z_ << "\t" << bend_ << "\t" << strip_ << "\t" << "\t" << tps_.size() << " \t"; for (int itp : tps_) { out << itp << " \t"; @@ -107,13 +101,28 @@ void L1TStub::setXY(double x, double y) { bool L1TStub::tpmatch(int tp) const { for (int itp : tps_) { - if (tp == itp) + if (tp == std::abs(itp)) return true; } return false; } +bool L1TStub::tpmatch2(int tp) const { + bool match1 = false; + bool match2 = false; + for (int itp : tps_) { + if (tp == itp) { + match1 = true; + } + if (tp == -itp) { + match2 = true; + } + } + + return match1 && match2; +} + bool L1TStub::isTilted() const { //here layer_ runs 0-5 for barrel, >1000 for disk //disk modules and outer barrel modules are not tilted by construction diff --git a/L1Trigger/TrackFindingTracklet/src/LayerProjection.cc b/L1Trigger/TrackFindingTracklet/src/LayerProjection.cc deleted file mode 100644 index 83cb116eacb6a..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/LayerProjection.cc +++ /dev/null @@ -1,103 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/LayerProjection.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" - -#include "FWCore/MessageLogger/interface/MessageLogger.h" - -using namespace std; -using namespace trklet; - -void LayerProjection::init(Settings const& settings, - int projlayer, - double rproj, - int iphiproj, - int izproj, - int iphider, - int izder, - double phiproj, - double zproj, - double phiprojder, - double zprojder, - double phiprojapprox, - double zprojapprox, - double phiprojderapprox, - double zprojderapprox, - bool isPSseed) { - assert(projlayer > 0); - assert(projlayer <= N_LAYER); - - valid_ = true; - - rproj_ = rproj; - - projlayer_ = projlayer; - - assert(iphiproj >= 0); - - if (rproj < settings.rPS2S()) { - fpgaphiproj_.set(iphiproj, settings.nphibitsstub(0), true, __LINE__, __FILE__); - int iphivm = (iphiproj >> (settings.nphibitsstub(0) - 5)) & 0x7; - if ((projlayer_ % 2) == 1) { - iphivm ^= 4; - } - fpgaphiprojvm_.set(iphivm, 3, true, __LINE__, __FILE__); - fpgazproj_.set(izproj, settings.nzbitsstub(0), false, __LINE__, __FILE__); - int izvm = izproj >> (12 - 7) & 0xf; - fpgazprojvm_.set(izvm, 4, true, __LINE__, __FILE__); - fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__); - fpgazprojder_.set(izder, settings.nbitszprojderL123(), false, __LINE__, __FILE__); - } else { - fpgaphiproj_.set(iphiproj, settings.nphibitsstub(5), true, __LINE__, __FILE__); - int iphivm = (iphiproj >> (settings.nphibitsstub(5) - 5)) & 0x7; - if ((projlayer_ % 2) == 1) { - iphivm ^= 4; - } - fpgaphiprojvm_.set(iphivm, 3, true, __LINE__, __FILE__); - fpgazproj_.set(izproj, settings.nzbitsstub(5), false, __LINE__, __FILE__); - int izvm = izproj >> (8 - 7) & 0xf; - fpgazprojvm_.set(izvm, 4, true, __LINE__, __FILE__); - fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL456(), false, __LINE__, __FILE__); - fpgazprojder_.set(izder, settings.nbitszprojderL456(), false, __LINE__, __FILE__); - } - - ////Separate the vm projections into zbins - ////This determines the central bin: - ////int zbin=4+(zproj.value()>>(zproj.nbits()-3)); - ////But we need some range (particularly for L5L6 seed projecting to L1-L3): - int offset = 4; - if (isPSseed) { - offset = 1; - } - unsigned int zbin1 = (1 << (settings.MEBinsBits() - 1)) + - (((fpgazproj_.value() >> (fpgazproj_.nbits() - settings.MEBinsBits() - 3)) - offset) >> 3); - unsigned int zbin2 = (1 << (settings.MEBinsBits() - 1)) + - (((fpgazproj_.value() >> (fpgazproj_.nbits() - settings.MEBinsBits() - 3)) + offset) >> 3); - if (zbin1 >= settings.MEBins()) { - zbin1 = 0; //note that zbin1 is unsigned - } - if (zbin2 >= settings.MEBins()) - zbin2 = settings.MEBins() - 1; - assert(zbin1 <= zbin2); - assert(zbin2 - zbin1 <= 1); - fpgazbin1projvm_.set(zbin1, settings.MEBinsBits(), true, __LINE__, __FILE__); // first z bin - if (zbin1 == zbin2) - fpgazbin2projvm_.set(0, 1, true, __LINE__, __FILE__); // don't need to check adjacent z bin - else - fpgazbin2projvm_.set(1, 1, true, __LINE__, __FILE__); // do need to check next z bin - - //fine vm z bits. Use 4 bits for fine position. starting at zbin 1 - int finez = ((1 << (settings.MEBinsBits() + 2)) + - (fpgazproj_.value() >> (fpgazproj_.nbits() - (settings.MEBinsBits() + 3)))) - - (zbin1 << 3); - - fpgafinezvm_.set(finez, 4, true, __LINE__, __FILE__); // fine z postions starting at zbin1 //FIXME using 3 bits - - phiproj_ = phiproj; - zproj_ = zproj; - phiprojder_ = phiprojder; - zprojder_ = zprojder; - - phiprojapprox_ = phiprojapprox; - zprojapprox_ = zprojapprox; - phiprojderapprox_ = phiprojderapprox; - zprojderapprox_ = zprojderapprox; -} diff --git a/L1Trigger/TrackFindingTracklet/src/LayerResidual.cc b/L1Trigger/TrackFindingTracklet/src/LayerResidual.cc deleted file mode 100644 index b9483e5135881..0000000000000 --- a/L1Trigger/TrackFindingTracklet/src/LayerResidual.cc +++ /dev/null @@ -1,42 +0,0 @@ -#include "L1Trigger/TrackFindingTracklet/interface/LayerResidual.h" -#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" - -using namespace std; -using namespace trklet; - -void LayerResidual::init(Settings const& settings, - int layer, - int iphiresid, - int izresid, - int istubid, - double phiresid, - double zresid, - double phiresidapprox, - double zresidapprox, - double rstub, - const Stub* stubptr) { - assert(layer > 0); - assert(layer <= N_LAYER); - - if (valid_ && (std::abs(iphiresid) > std::abs(fpgaphiresid_.value()))) - return; - - valid_ = true; - - layer_ = layer; - - fpgaphiresid_.set(iphiresid, settings.phiresidbits(), false, __LINE__, __FILE__); - fpgazresid_.set(izresid, settings.zresidbits(), false, __LINE__, __FILE__); - int nbitsid = 10; - fpgastubid_.set(istubid, nbitsid, true, __LINE__, __FILE__); - assert(!fpgaphiresid_.atExtreme()); - - phiresid_ = phiresid; - zresid_ = zresid; - - phiresidapprox_ = phiresidapprox; - zresidapprox_ = zresidapprox; - - rstub_ = rstub; - stubptr_ = stubptr; -} diff --git a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc index be1fdd992fea2..86549eac723bf 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchCalculator.cc @@ -18,10 +18,8 @@ using namespace std; using namespace trklet; -MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { - phioffset_ = phimin_; - +MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) { phiregion_ = name[8] - 'A'; layerdisk_ = initLayerDisk(3); @@ -58,18 +56,8 @@ MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* } } - if (iSector_ == 0 && layerdisk_ < N_LAYER && settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - const string filephicut = settings_.tablePath() + getName() + "_phicut.tab"; - ofstream outphicut(filephicut); - if (outphicut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << filephicut; + if (layerdisk_ < N_LAYER && settings_.writeTable()) { + ofstream outphicut = openfile(settings_.tablePath(), getName() + "_phicut.tab", __FILE__, __LINE__); outphicut << "{" << endl; for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { @@ -95,18 +83,9 @@ MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* outzcut.close(); } - if (iSector_ == 0 && layerdisk_ >= N_LAYER && settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } + if (layerdisk_ >= N_LAYER && settings_.writeTable()) { + ofstream outPSphicut = openfile(settings_.tablePath(), getName() + "_PSphicut.tab", __FILE__, __LINE__); - const string filePSphicut = settings_.tablePath() + getName() + "_PSphicut.tab"; - ofstream outPSphicut(filePSphicut); - if (outPSphicut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << filePSphicut; outPSphicut << "{" << endl; for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { if (seedindex != 0) @@ -116,10 +95,8 @@ MatchCalculator::MatchCalculator(string name, Settings const& settings, Globals* outPSphicut << endl << "};" << endl; outPSphicut.close(); - const string file2Sphicut = settings_.tablePath() + getName() + "_2Sphicut.tab"; - ofstream out2Sphicut(file2Sphicut); - if (out2Sphicut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << file2Sphicut; + ofstream out2Sphicut = openfile(settings_.tablePath(), getName() + "_2Sphicut.tab", __FILE__, __LINE__); + out2Sphicut << "{" << endl; for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { if (seedindex != 0) @@ -207,7 +184,7 @@ void MatchCalculator::addInput(MemoryBase* memory, string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input " << input; } -void MatchCalculator::execute() { +void MatchCalculator::execute(double phioffset) { unsigned int countall = 0; unsigned int countsel = 0; @@ -236,13 +213,15 @@ void MatchCalculator::execute() { if (layerdisk_ < N_LAYER) { //Integer calculation + const Projection& proj = tracklet->proj(layerdisk_); + int ir = fpgastub->r().value(); - int iphi = tracklet->fpgaphiproj(layerdisk_ + 1).value(); - int icorr = (ir * tracklet->fpgaphiprojder(layerdisk_ + 1).value()) >> icorrshift_; + int iphi = proj.fpgaphiproj().value(); + int icorr = (ir * proj.fpgaphiprojder().value()) >> icorrshift_; iphi += icorr; - int iz = tracklet->fpgazproj(layerdisk_ + 1).value(); - int izcor = (ir * tracklet->fpgazprojder(layerdisk_ + 1).value() + (1 << (icorzshift_ - 1))) >> icorzshift_; + int iz = proj.fpgarzproj().value(); + int izcor = (ir * proj.fpgarzprojder().value() + (1 << (icorzshift_ - 1))) >> icorzshift_; iz += izcor; int ideltaz = fpgastub->z().value() - iz; @@ -250,7 +229,7 @@ void MatchCalculator::execute() { //Floating point calculations - double phi = stub->phi() - phioffset_; + double phi = stub->phi() - phioffset; double r = stub->r(); double z = stub->z(); @@ -265,18 +244,16 @@ void MatchCalculator::execute() { if (phi < 0) phi += 2 * M_PI; - double dr = r - tracklet->rproj(layerdisk_ + 1); + double dr = r - settings_.rmean(layerdisk_); assert(std::abs(dr) < settings_.drmax()); - double dphi = - reco::reduceRange(phi - (tracklet->phiproj(layerdisk_ + 1) + dr * tracklet->phiprojder(layerdisk_ + 1))); + double dphi = reco::reduceRange(phi - (proj.phiproj() + dr * proj.phiprojder())); - double dz = z - (tracklet->zproj(layerdisk_ + 1) + dr * tracklet->zprojder(layerdisk_ + 1)); + double dz = z - (proj.rzproj() + dr * proj.rzprojder()); - double dphiapprox = reco::reduceRange( - phi - (tracklet->phiprojapprox(layerdisk_ + 1) + dr * tracklet->phiprojderapprox(layerdisk_ + 1))); + double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dr * proj.phiprojderapprox())); - double dzapprox = z - (tracklet->zprojapprox(layerdisk_ + 1) + dr * tracklet->zprojderapprox(layerdisk_ + 1)); + double dzapprox = z - (proj.rzprojapprox() + dr * proj.rzprojderapprox()); int seedindex = tracklet->getISeed(); @@ -296,9 +273,21 @@ void MatchCalculator::execute() { truthmatch); } - if (std::abs(dphi) > 0.2 || std::abs(dphiapprox) > 0.2) { - edm::LogProblem("Tracklet") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox - << endl; + //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_) << " " + << phimatchcut_[seedindex] * settings_.kphi1() * settings_.rmean(layerdisk_) << " " + << ideltaz * fact_ * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() << endl; } bool imatch = false; @@ -326,7 +315,7 @@ void MatchCalculator::execute() { if (imatch) { countsel++; - tracklet->addMatch(layerdisk_ + 1, + tracklet->addMatch(layerdisk_, ideltaphi, ideltaz, dphi, @@ -334,12 +323,10 @@ void MatchCalculator::execute() { dphiapprox, dzapprox, (phiregion_ << 7) + fpgastub->stubindex().value(), - stub->r(), mergedMatches[j].second); if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet << " " - << iSector_; + edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet; } fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second); @@ -355,20 +342,22 @@ void MatchCalculator::execute() { //Perform integer calculations here + const Projection& proj = tracklet->proj(layerdisk_); + int iz = fpgastub->z().value(); - int iphi = tracklet->fpgaphiprojdisk(disk).value(); + int iphi = proj.fpgaphiproj().value(); //TODO - need to express interms of constants int shifttmp = 6; - int iphicorr = (iz * tracklet->fpgaphiprojderdisk(disk).value()) >> shifttmp; + int iphicorr = (iz * proj.fpgaphiprojder().value()) >> shifttmp; iphi += iphicorr; - int ir = tracklet->fpgarprojdisk(disk).value(); + int ir = proj.fpgarzproj().value(); //TODO - need to express interms of constants int shifttmp2 = 7; - int ircorr = (iz * tracklet->fpgarprojderdisk(disk).value()) >> shifttmp2; + int ircorr = (iz * proj.fpgarzprojder().value()) >> shifttmp2; ir += ircorr; @@ -391,14 +380,14 @@ void MatchCalculator::execute() { int ideltar = (irstub >> 1) - ir; if (!stub->isPSmodule()) { - int ialphanew = fpgastub->alphanew().value(); - int iphialphacor = ((ideltar * ialphanew * ialphafact) >> settings_.alphashift()); + 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 phi = stub->phi() - phioffset; double z = stub->z(); double r = stub->r(); @@ -416,14 +405,13 @@ void MatchCalculator::execute() { double dz = z - sign * settings_.zmean(layerdisk_ - N_LAYER); if (std::abs(dz) > settings_.dzmax()) { - throw cms::Exception("LogicError") - << __FILE__ << " " << __LINE__ << " " << name_ << "_" << iSector_ << " " << tracklet->getISeed() - << "\n stub " << stub->z() << " disk " << disk << " " << dz; + throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " " << name_ << " " << tracklet->getISeed() + << "\n stub " << stub->z() << " disk " << disk << " " << dz; } - double phiproj = tracklet->phiprojdisk(disk) + dz * tracklet->phiprojderdisk(disk); + double phiproj = proj.phiproj() + dz * proj.phiprojder(); - double rproj = tracklet->rprojdisk(disk) + dz * tracklet->rprojderdisk(disk); + double rproj = proj.rzproj() + dz * proj.rzprojder(); double deltar = r - rproj; @@ -431,10 +419,9 @@ void MatchCalculator::execute() { double dphi = reco::reduceRange(phi - phiproj); - double dphiapprox = - reco::reduceRange(phi - (tracklet->phiprojapproxdisk(disk) + dz * tracklet->phiprojderapproxdisk(disk))); + double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dz * proj.phiprojderapprox())); - double drapprox = stub->r() - (tracklet->rprojapproxdisk(disk) + dz * tracklet->rprojderapproxdisk(disk)); + double drapprox = stub->r() - (proj.rzprojapprox() + dz * proj.rzprojderapprox()); double drphi = dphi * stub->r(); double drphiapprox = dphiapprox * stub->r(); @@ -461,7 +448,7 @@ void MatchCalculator::execute() { double drcut = idrcut * settings_.krprojshiftdisk(); bool match, imatch; - if (std::abs(dphi) < 0.25 && std::abs(dphiapprox) < 0.25) { //Changed the Asserts into if statements + 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()); @@ -493,20 +480,18 @@ void MatchCalculator::execute() { edm::LogVerbatim("Tracklet") << "MatchCalculator found match in disk " << getName(); } - tracklet->addMatchDisk(disk, - ideltaphi, - ideltar, - drphi / stub->r(), - dr, - drphiapprox / stub->r(), - drapprox, - stub->alpha(settings_.stripPitch(stub->isPSmodule())), - (phiregion_ << 7) + fpgastub->stubindex().value(), - stub->z(), - fpgastub); + 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 << " " - << iSector_; + edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet; } fullMatches_[seedindex]->addMatch(tracklet, mergedMatches[j].second); diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc index 0e528803e2747..2668c2e646761 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngine.cc @@ -15,64 +15,44 @@ using namespace std; using namespace trklet; -MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { - layer_ = 0; - disk_ = 0; - string subname = name.substr(3, 2); - if (subname.substr(0, 1) == "L") - layer_ = stoi(subname.substr(1, 1)); - else if (subname.substr(0, 1) == "D") - disk_ = stoi(subname.substr(1, 1)); - else - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " " << name << " subname = " << subname << " " - << layer_ << " " << disk_; - - barrel_ = layer_ > 0; - - nvm_ = barrel_ ? settings_.nvmme(layer_ - 1) * settings_.nallstubs(layer_ - 1) - : settings_.nvmme(disk_ + N_LAYER - 1) * settings_.nallstubs(disk_ + N_LAYER - 1); - - if (nvm_ == 32) - nvmbits_ = 5; - else if (nvm_ == 16) - nvmbits_ = 4; - - if (layer_ > 0) { - unsigned int nbits = 3; - if (layer_ >= 4) - nbits = 4; - - for (unsigned int irinv = 0; irinv < 32; irinv++) { - double rinv = (irinv - 15.5) * (1 << (settings_.nbitsrinv() - 5)) * settings_.krinvpars(); - - double stripPitch = - (settings_.rmean(layer_ - 1) < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double projbend = bend(settings_.rmean(layer_ - 1), rinv, stripPitch); - for (unsigned int ibend = 0; ibend < (unsigned int)(1 << nbits); ibend++) { - double stubbend = benddecode(ibend, layer_ <= 3); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(layer_ - 1); +MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global) : ProcessBase(name, settings, global) { + layerdisk_ = initLayerDisk(3); + + barrel_ = layerdisk_ < N_LAYER; + + nvm_ = settings_.nvmme(layerdisk_) * settings_.nallstubs(layerdisk_); + + nvmbits_ = settings_.nbitsvmme(layerdisk_) + settings_.nbitsallstubs(layerdisk_); + + nrinv_ = NRINVBITS; + double rinvhalf = 0.5 * ((1 << nrinv_) - 1); + + nfinephibits_ = 3; + + if (barrel_) { + bool isPSmodule = layerdisk_ < N_PSLAYER; + + unsigned int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S; + + for (unsigned int irinv = 0; irinv < (1u << nrinv_); irinv++) { + double rinv = (irinv - rinvhalf) * (1 << (settings_.nbitsrinv() - nrinv_)) * settings_.krinvpars(); + + double stripPitch = settings_.stripPitch(isPSmodule); + double projbend = bendstrip(settings_.rmean(layerdisk_), rinv, stripPitch); + for (unsigned int ibend = 0; ibend < (1u << nbits); ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk_, isPSmodule); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, isPSmodule); table_.push_back(pass); } } if (settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - char layer = '0' + layer_; + char layer = '1' + layerdisk_; string fname = "METable_L"; fname += layer; fname += ".tab"; - const string full_fname = settings_.tablePath() + fname; - ofstream out(full_fname); - if (out.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << full_fname; + ofstream out = openfile(settings_.tablePath(), fname, __FILE__, __LINE__); out << "{" << endl; for (unsigned int i = 0; i < table_.size(); i++) { @@ -86,17 +66,17 @@ MatchEngine::MatchEngine(string name, Settings const& settings, Globals* global, } } - if (disk_ > 0) { - for (unsigned int iprojbend = 0; iprojbend < 32; iprojbend++) { - double projbend = 0.5 * (iprojbend - 15.0); - for (unsigned int ibend = 0; ibend < 8; ibend++) { - double stubbend = benddecode(ibend, true); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); + if (layerdisk_ >= N_LAYER) { + for (unsigned int iprojbend = 0; iprojbend < (1u << nrinv_); iprojbend++) { + double projbend = 0.5 * (iprojbend - rinvhalf); + for (unsigned int ibend = 0; ibend < (1 << N_BENDBITS_PS); ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk_, true); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, true); tablePS_.push_back(pass); } - for (unsigned int ibend = 0; ibend < 16; ibend++) { - double stubbend = benddecode(ibend, false); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); + for (unsigned int ibend = 0; ibend < (1 << N_BENDBITS_2S); ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk_, false); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, false); table2S_.push_back(pass); } } @@ -141,6 +121,9 @@ void MatchEngine::execute() { unsigned int countall = 0; unsigned int countpass = 0; + bool print = (getName() == "ME_L3PHIC20"); + print = false; + constexpr unsigned int kNBitsBuffer = 3; int writeindex = 0; @@ -195,9 +178,11 @@ void MatchEngine::execute() { iproj++; moreproj = iproj < nproj; - unsigned int rzfirst = barrel_ ? proj->zbin1projvm(layer_) : proj->rbin1projvm(disk_); + unsigned int rzfirst = proj->proj(layerdisk_).fpgarzbin1projvm().value(); unsigned int rzlast = rzfirst; - bool second = (barrel_ ? proj->zbin2projvm(layer_) : proj->rbin2projvm(disk_)) == 1; + + bool second = proj->proj(layerdisk_).fpgarzbin2projvm().value(); + if (second) rzlast += 1; @@ -247,31 +232,31 @@ void MatchEngine::execute() { Tracklet* proj = vmprojs_->getTracklet(projindex); - FPGAWord fpgaphi = barrel_ ? proj->fpgaphiproj(layer_) : proj->fpgaphiprojdisk(disk_); - projfinephi = (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + 3))) & 7; + FPGAWord fpgafinephi = proj->proj(layerdisk_).fpgafinephivm(); + + projfinephi = fpgafinephi.value(); nstubs = vmstubs_->nStubsBin(rzbin); - projfinerz = barrel_ ? proj->finezvm(layer_) : proj->finervm(disk_); + projfinerz = proj->proj(layerdisk_).fpgafinerzvm().value(); - projrinv = - barrel_ - ? (16 + (((-2) * proj->fpgaphiprojder(layer_).value()) >> (proj->fpgaphiprojder(layer_).nbits() - 4))) - : proj->getBendIndex(disk_).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 == 32) { + if (settings_.extended() && projrinv == (1 << nrinv_)) { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "Extended tracking, projrinv:" << projrinv; } - projrinv = 31; + projrinv = (1 << nrinv_) - 1; } - assert(projrinv < 32); + assert(projrinv < (1 << nrinv_)); - isPSseed = proj->PSseed() == 1; + isPSseed = proj->PSseed(); //Calculate fine z position if (second) { - projfinerzadj = projfinerz - 8; + projfinerzadj = projfinerz - (1 << NFINERZBITS); } else { projfinerzadj = projfinerz; } @@ -298,11 +283,13 @@ void MatchEngine::execute() { int stubfinerz = vmstub.finerz().value(); - int nbits = isPSmodule ? 3 : 4; + int nbits = isPSmodule ? N_BENDBITS_PS : N_BENDBITS_2S; int deltaphi = projfinephi - vmstub.finephi().value(); - bool passphi = (abs(deltaphi) < 3) || (abs(deltaphi) > 5); + 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(); @@ -312,18 +299,28 @@ void MatchEngine::execute() { if (barrel_) { if (isPSseed) { - passz = idrz >= -2 && idrz <= 2; + constexpr int drzcut = 1; + passz = std::abs(idrz) <= drzcut; } else { - passz = idrz >= -5 && idrz <= 5; + constexpr int drzcut = 5; + passz = std::abs(idrz) <= drzcut; } } else { if (isPSmodule) { - passz = idrz >= -1 && idrz <= 1; + constexpr int drzcut = 1; + passz = std::abs(idrz) <= drzcut; } else { - passz = idrz >= -5 && idrz <= 5; + constexpr int drzcut = 3; + passz = std::abs(idrz) <= drzcut; } } + if (print) { + cout << "istep index : " << istep << " " << index << " " << vmstub.bend().value() + << " rzbin istubtmp : " << rzbin << " " << istubtmp << " dz " << stubfinerz << " " << projfinerzadj + << " dphi: " << deltaphi << endl; + } + //Check if stub bend and proj rinv consistent if (passz && passphi) { if (barrel_ ? table_[index] : (isPSmodule ? tablePS_[index] : table2S_[index])) { @@ -331,7 +328,7 @@ void MatchEngine::execute() { std::pair tmp(proj, vmprojs_->getAllProjIndex(projindex)); if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << proj->getISeed() << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << proj->getISeed() << endl; fout.close(); } candmatches_->addMatch(tmp, vmstub.stub()); diff --git a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc index 47d621adcaec6..6bea2f165c795 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchEngineUnit.cc @@ -3,56 +3,93 @@ using namespace std; using namespace trklet; -MatchEngineUnit::MatchEngineUnit(bool barrel, vector table, vector tablePS, vector table2S) - : candmatches_(5) { +MatchEngineUnit::MatchEngineUnit(bool barrel, unsigned int layerdisk, vector table) : candmatches_(5) { idle_ = true; barrel_ = barrel; table_ = table; - tablePS_ = tablePS; - table2S_ = table2S; - slot_ = 1; //This makes it idle until initialized + layerdisk_ = layerdisk; } void MatchEngineUnit::init(VMStubsMEMemory* vmstubsmemory, - unsigned int slot, + unsigned int nrzbins, + unsigned int rzbin, + unsigned int phibin, + int shift, int projrinv, int projfinerz, int projfinephi, - bool usesecond, + bool usefirstMinus, + bool usefirstPlus, + bool usesecondMinus, + bool usesecondPlus, bool isPSseed, Tracklet* proj) { vmstubsmemory_ = vmstubsmemory; idle_ = false; - slot_ = slot; + nrzbins_ = nrzbins; + rzbin_ = rzbin; + phibin_ = phibin; + shift_ = shift; istub_ = 0; + iuse_ = 0; projrinv_ = projrinv; projfinerz_ = projfinerz; projfinephi_ = projfinephi; - usesecond_ = usesecond; + use_.clear(); + if (usefirstMinus) { + use_.emplace_back(0, 0); + } + if (usefirstPlus) { + use_.emplace_back(0, 1); + } + if (usesecondMinus) { + use_.emplace_back(1, 0); + } + if (usesecondPlus) { + use_.emplace_back(1, 1); + } + assert(use_.size() != 0); isPSseed_ = isPSseed; proj_ = proj; } -void MatchEngineUnit::step() { +void MatchEngineUnit::step(bool print) { if (idle() || candmatches_.almostfull()) return; - const VMStubME& vmstub = vmstubsmemory_->getVMStubMEBin(slot_, istub_); + unsigned int slot = (phibin_ + use_[iuse_].second) * nrzbins_ + rzbin_ + use_[iuse_].first; + + int projfinerz = projfinerz_ - (1 << NFINERZBITS) * use_[iuse_].first; + int projfinephi = projfinephi_; + if (use_[iuse_].second == 0) { + if (shift_ == -1) { + projfinephi -= (1 << NFINEPHIBITS); + } + } else { + //When we get here shift_ is either 1 or -1 + if (shift_ == 1) { + projfinephi += (1 << NFINEPHIBITS); + } + } + + const VMStubME& vmstub = vmstubsmemory_->getVMStubMEBin(slot, istub_); bool isPSmodule = vmstub.isPSmodule(); int stubfinerz = vmstub.finerz().value(); int stubfinephi = vmstub.finephi().value(); - int deltaphi = stubfinephi - projfinephi_; + int deltaphi = stubfinephi - projfinephi; - bool dphicut = (abs(deltaphi) < 3) || (abs(deltaphi) > 5); //TODO - need better implementations + bool dphicut = (abs(deltaphi) < 3); int nbits = isPSmodule ? 3 : 4; - unsigned int index = (projrinv_ << nbits) + vmstub.bend().value(); + int diskps = (!barrel_) && isPSmodule; + + unsigned int index = (diskps << (4 + 5)) + (projrinv_ << nbits) + vmstub.bend().value(); //Check if stub z position consistent - int idrz = stubfinerz - projfinerz_; + int idrz = stubfinerz - projfinerz; bool pass; if (barrel_) { @@ -69,19 +106,23 @@ void MatchEngineUnit::step() { } } + if (print) + cout << "MEU TrkId stubindex : " << 128 * proj_->TCIndex() + proj_->trackletIndex() << " " + << vmstub.stubindex().value() << " " << ((pass && dphicut) && table_[index]) << " index=" << index + << " projrinv bend : " << projrinv_ << " " << vmstub.bend().value() << " shift_ isPSseed_ :" << shift_ << " " + << isPSseed_ << " slot=" << slot << endl; + //Check if stub bend and proj rinv consistent - if ((pass && dphicut) && (barrel_ ? table_[index] : (isPSmodule ? tablePS_[index] : table2S_[index]))) { + if ((pass && dphicut) && table_[index]) { std::pair tmp(proj_, vmstub.stub()); candmatches_.store(tmp); } istub_++; - if (istub_ >= vmstubsmemory_->nStubsBin(slot_)) { - if (usesecond_) { - usesecond_ = false; + if (istub_ >= vmstubsmemory_->nStubsBin(slot)) { + iuse_++; + if (iuse_ < use_.size()) { istub_ = 0; - slot_++; - projfinerz_ -= (1 << NFINERZBITS); } else { idle_ = true; } diff --git a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc index 2a977a963cc00..b2f7722a5b1d5 100644 --- a/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/MatchProcessor.cc @@ -13,66 +13,46 @@ using namespace std; using namespace trklet; -MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector), fullmatches_(12), inputProjBuffer_(3) { - phioffset_ = phimin_; - +MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global), fullmatches_(12), inputProjBuffer_(3) { phiregion_ = name[8] - 'A'; - initLayerDisk(3, layer_, disk_); layerdisk_ = initLayerDisk(3); - //TODO should sort out constants here - icorrshift_ = 7; + barrel_ = layerdisk_ < N_LAYER; + + phishift_ = settings_.nphibitsstub(N_LAYER - 1) - settings_.nphibitsstub(layerdisk_); + dzshift_ = settings_.nzbitsstub(0) - settings_.nzbitsstub(layerdisk_); - if (layer_ <= 3) { - icorzshift_ = -1 - settings_.PS_zderL_shift(); + if (barrel_) { + icorrshift_ = ilog2(settings_.kphi(layerdisk_) / (settings_.krbarrel() * settings_.kphider())); + icorzshift_ = ilog2(settings_.kz(layerdisk_) / (settings_.krbarrel() * settings_.kzder())); } else { - icorzshift_ = -1 - settings_.SS_zderL_shift(); - } - phi0shift_ = 3; - fact_ = 1; - if (layer_ >= 4) { - fact_ = (1 << (settings_.nzbitsstub(0) - settings_.nzbitsstub(5))); - icorrshift_ -= (10 - settings_.nrbitsstub(layer_ - 1)); - icorzshift_ += (settings_.nzbitsstub(0) - settings_.nzbitsstub(5) + settings_.nrbitsstub(layer_ - 1) - - settings_.nrbitsstub(0)); - phi0shift_ = 0; + icorrshift_ = ilog2(settings_.kphi(layerdisk_) / (settings_.kz() * settings_.kphiderdisk())); + icorzshift_ = ilog2(settings_.krprojshiftdisk() / (settings_.kz() * settings_.krder())); } nrbits_ = 5; nphiderbits_ = 6; - //to adjust globaly the phi and rz matching cuts - phifact_ = 1.0; - rzfact_ = 1.0; + nrinv_ = NRINVBITS; + double rinvhalf = 0.5 * ((1 << nrinv_) - 1); for (unsigned int iSeed = 0; iSeed < 12; iSeed++) { - if (layer_ > 0) { + if (layerdisk_ < N_LAYER) { phimatchcut_[iSeed] = - settings_.rphimatchcut(iSeed, layer_ - 1) / (settings_.kphi1() * settings_.rmean(layer_ - 1)); - zmatchcut_[iSeed] = settings_.zmatchcut(iSeed, layer_ - 1) / settings_.kz(); - } - if (disk_ != 0) { - rphicutPS_[iSeed] = settings_.rphicutPS(iSeed, abs(disk_) - 1) / (settings_.kphi() * settings_.kr()); - rphicut2S_[iSeed] = settings_.rphicut2S(iSeed, abs(disk_) - 1) / (settings_.kphi() * settings_.kr()); - rcut2S_[iSeed] = settings_.rcut2S(iSeed, abs(disk_) - 1) / settings_.krprojshiftdisk(); - rcutPS_[iSeed] = settings_.rcutPS(iSeed, abs(disk_) - 1) / settings_.krprojshiftdisk(); + settings_.rphimatchcut(iSeed, layerdisk_) / (settings_.kphi1() * settings_.rmean(layerdisk_)); + zmatchcut_[iSeed] = settings_.zmatchcut(iSeed, layerdisk_) / settings_.kz(); + } else { + rphicutPS_[iSeed] = settings_.rphicutPS(iSeed, layerdisk_ - N_LAYER) / (settings_.kphi() * settings_.kr()); + rphicut2S_[iSeed] = settings_.rphicut2S(iSeed, layerdisk_ - N_LAYER) / (settings_.kphi() * settings_.kr()); + rcut2S_[iSeed] = settings_.rcut2S(iSeed, layerdisk_ - N_LAYER) / settings_.krprojshiftdisk(); + rcutPS_[iSeed] = settings_.rcutPS(iSeed, layerdisk_ - N_LAYER) / settings_.krprojshiftdisk(); } } - if (iSector_ == 0 && layer_ > 0 && settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - const string filephicut = settings_.tablePath() + getName() + "_phicut.tab"; - ofstream outphicut(filephicut); - if (outphicut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << filephicut; + if (barrel_ && settings_.writeTable()) { + ofstream outphicut = openfile(settings_.tablePath(), getName() + "_phicut.tab", __FILE__, __LINE__); outphicut << "{" << endl; for (unsigned int seedindex = 0; seedindex < 12; seedindex++) { @@ -83,10 +63,7 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g outphicut << endl << "};" << endl; outphicut.close(); - const string filezcut = settings_.tablePath() + getName() + "_zcut.tab"; - ofstream outzcut(filezcut); - if (outzcut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << filezcut; + ofstream outzcut = openfile(settings_.tablePath(), getName() + "_zcut.tab", __FILE__, __LINE__); outzcut << "{" << endl; for (unsigned int seedindex = 0; seedindex < N_SEED; seedindex++) { @@ -98,66 +75,55 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g outzcut.close(); } - if (layer_ > 0) { - unsigned int nbits = 3; - if (layer_ >= 4) - nbits = 4; + if (barrel_) { + unsigned int nbits = (layerdisk_ < N_PSLAYER) ? N_BENDBITS_PS : N_BENDBITS_2S; - for (unsigned int irinv = 0; irinv < 32; irinv++) { - double rinv = (irinv - 15.5) * (1 << (settings_.nbitsrinv() - 5)) * settings_.krinvpars(); - double stripPitch = - (settings_.rmean(layer_ - 1) < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double projbend = bend(settings_.rmean(layer_ - 1), rinv, stripPitch); + for (unsigned int irinv = 0; irinv < (1u << nrinv_); irinv++) { + double rinv = (irinv - rinvhalf) * (1 << (settings_.nbitsrinv() - nrinv_)) * settings_.krinvpars(); + double stripPitch = settings_.stripPitch(layerdisk_ < N_PSLAYER); + double projbend = bendstrip(settings_.rmean(layerdisk_), rinv, stripPitch); for (unsigned int ibend = 0; ibend < (unsigned int)(1 << nbits); ibend++) { - double stubbend = benddecode(ibend, layer_ <= (int)N_PSLAYER); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(layer_ - 1); + double stubbend = settings_.benddecode(ibend, layerdisk_, layerdisk_ < (int)N_PSLAYER); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, layerdisk_ < (int)N_PSLAYER); table_.push_back(pass); } } - - if (settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); + } else { + constexpr int nprojbends = 1 << NRINVBITS; + constexpr int npsbends = 1 << N_BENDBITS_PS; + constexpr int n2sbends = 1 << N_BENDBITS_2S; + table_.resize(nprojbends * n2sbends * 2, false); //Factor of 2 is to have both 2s and ps bends in same table + for (unsigned int iprojbend = 0; iprojbend < nprojbends; iprojbend++) { + double projbend = 0.5 * (iprojbend - rinvhalf); + for (unsigned int ibend = 0; ibend < npsbends; ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk_, true); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, true); + table_[nprojbends*n2sbends + npsbends * iprojbend + ibend] = pass; } - - char layer = '0' + layer_; - string fname = "METable_L"; - fname += layer; - fname += ".tab"; - const string full_fname = settings_.tablePath() + fname; - ofstream out(full_fname); - if (out.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << full_fname; - - out << "{" << endl; - for (unsigned int i = 0; i < table_.size(); i++) { - if (i != 0) { - out << "," << endl; - } - out << table_[i]; + for (unsigned int ibend = 0; ibend < n2sbends; ibend++) { + double stubbend = settings_.benddecode(ibend, layerdisk_, false); + bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(ibend, layerdisk_, false); + table_[n2sbends * iprojbend + ibend] = pass; } - out << "};" << endl; - out.close(); } } - if (disk_ > 0) { - for (unsigned int iprojbend = 0; iprojbend < 32; iprojbend++) { - double projbend = 0.5 * (iprojbend - 15.0); - for (unsigned int ibend = 0; ibend < 8; ibend++) { - double stubbend = benddecode(ibend, true); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); - tablePS_.push_back(pass); - } - for (unsigned int ibend = 0; ibend < 16; ibend++) { - double stubbend = benddecode(ibend, false); - bool pass = std::abs(stubbend - projbend) < settings_.bendcutme(disk_ + 5); - table2S_.push_back(pass); + if (settings_.writeTable()) { + char layerdisk = barrel_ ? '0' + layerdisk_ + 1 : '0' + layerdisk_ - N_LAYER + 1; + string fname = barrel_ ? "METable_L" : "METable_D"; + fname += layerdisk; + fname += ".tab"; + + ofstream out = openfile(settings_.tablePath(), fname, __FILE__, __LINE__); + out << "{" << endl; + for (unsigned int i = 0; i < table_.size(); i++) { + if (i != 0) { + out << "," << endl; } + out << table_[i]; } + out << "};" << endl; + out.close(); } for (unsigned int i = 0; i < N_DSS_MOD * 2; i++) { @@ -169,23 +135,21 @@ MatchProcessor::MatchProcessor(string name, Settings const& settings, Globals* g settings_.kphi(); } - barrel_ = layer_ > 0; - - nvm_ = barrel_ ? settings_.nvmme(layer_ - 1) * settings_.nallstubs(layer_ - 1) - : settings_.nvmme(disk_ + 5) * settings_.nallstubs(disk_ + 5); - nvmbins_ = barrel_ ? settings_.nvmme(layer_ - 1) : settings_.nvmme(disk_ + 5); - - if (nvm_ == 32) - nvmbits_ = 5; - if (nvm_ == 16) - nvmbits_ = 4; - assert(nvmbits_ != -1); + nvm_ = settings_.nvmme(layerdisk_) * settings_.nallstubs(layerdisk_); + nvmbins_ = settings_.nvmme(layerdisk_); + nvmbits_ = settings_.nbitsvmme(layerdisk_) + settings_.nbitsallstubs(layerdisk_); nMatchEngines_ = 4; for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { - MatchEngineUnit tmpME(barrel_, table_, tablePS_, table2S_); + MatchEngineUnit tmpME(barrel_, layerdisk_, table_); matchengines_.push_back(tmpME); } + + if (globals_->projectionRouterBendTable() == nullptr) { + auto* bendTablePtr = new ProjectionRouterBendTable(); + bendTablePtr->init(settings_, globals_, nrbits_, nphiderbits_); + globals_->projectionRouterBendTable() = bendTablePtr; + } } void MatchProcessor::addOutput(MemoryBase* memory, string output) { @@ -231,15 +195,9 @@ void MatchProcessor::addInput(MemoryBase* memory, string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; } -void MatchProcessor::execute() { +void MatchProcessor::execute(unsigned int iSector, double phimin) { assert(vmstubs_.size() == 1); - if (globals_->projectionRouterBendTable() == nullptr) { // move to constructor?! - auto* bendTablePtr = new ProjectionRouterBendTable(); - bendTablePtr->init(settings_, globals_, nrbits_, nphiderbits_); - globals_->projectionRouterBendTable() = bendTablePtr; - } - /* The code is organized in three 'steps' corresponding to the PR, ME, and MC functions. The output from the PR step is buffered in a 'circular' buffer, and similarly the ME output is put in a circular buffer. @@ -254,6 +212,11 @@ void MatchProcessor::execute() { */ + bool print = getName() == "MP_L3PHIC" && iSector == 3; + print = false; + + phimin_ = phimin; + Tracklet* oldTracklet = nullptr; unsigned int countme = 0; @@ -266,18 +229,15 @@ void MatchProcessor::execute() { inputProjBuffer_.reset(); - for (unsigned int i = 0; i < inputprojs_.size(); i++) { - countinputproj += inputprojs_[i]->nTracklets(); + for (const auto& inputproj : inputprojs_) { + countinputproj += inputproj->nTracklets(); } - for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { - matchengines_[iME].reset(); + for (auto& matchengine : matchengines_) { + matchengine.reset(); } - unsigned int step2delay = 0; - unsigned int step3delay = 0; - - for (unsigned int istep = 0; istep < settings_.maxStep("MP") + step3delay; istep++) { + for (unsigned int istep = 0; istep < settings_.maxStep("MP"); istep++) { bool projdone = false; bool medone = true; //Step 1 @@ -296,60 +256,96 @@ void MatchProcessor::execute() { } Tracklet* proj = projMem->getTracklet(iproj); - FPGAWord fpgaphi = barrel_ ? proj->fpgaphiproj(layer_) : proj->fpgaphiprojdisk(disk_); - int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1); + FPGAWord fpgaphi = proj->proj(layerdisk_).fpgaphiproj(); + + unsigned int iphi = (fpgaphi.value() >> (fpgaphi.nbits() - nvmbits_)) & (nvmbins_ - 1); + + int nextrabits = 2; + int overlapbits = nvmbits_ + nextrabits; + + unsigned int extrabits = fpgaphi.bits(fpgaphi.nbits() - overlapbits, nextrabits); + + unsigned int ivmPlus = iphi; + + int shift = 0; + + 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 projrinv = -1; if (barrel_) { - projrinv = (1 << (NRINVBITS - 1)) + (proj->fpgarinv().value() >> (proj->fpgarinv().nbits() - NRINVBITS)); + 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 rindex = (proj->fpgarprojdisk(disk_).value() >> (proj->fpgarprojdisk(disk_).nbits() - nrbits_)) & + + int rindex = (proj->proj(layerdisk_).fpgarzproj().value() >> + (proj->proj(layerdisk_).fpgarzproj().nbits() - nrbits_)) & ((1 << nrbits_) - 1); - int phiderindex = (proj->fpgaphiprojderdisk(disk_).value() >> - (proj->fpgaphiprojderdisk(disk_).nbits() - nphiderbits_)) & + int phiderindex = (proj->proj(layerdisk_).fpgaphiprojder().value() >> + (proj->proj(layerdisk_).fpgaphiprojder().nbits() - nphiderbits_)) & ((1 << nphiderbits_) - 1); - int signindex = (proj->fpgarprojderdisk(disk_).value() < 0); + int signindex = proj->proj(layerdisk_).fpgarzprojder().value() < 0; int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; - projrinv = globals_->projectionRouterBendTable()->bendLoookup(abs(disk_) - 1, bendindex); + projrinv = globals_->projectionRouterBendTable()->bendLoookup(layerdisk_ - N_LAYER, bendindex); - proj->setBendIndex(projrinv, disk_); + proj->proj(layerdisk_).setBendIndex(projrinv); } assert(projrinv >= 0); - unsigned int slot = barrel_ ? proj->zbin1projvm(layer_) : proj->rbin1projvm(disk_); - bool second = (barrel_ ? proj->zbin2projvm(layer_) : proj->rbin2projvm(disk_)); + unsigned int slot = proj->proj(layerdisk_).fpgarzbin1projvm().value(); + bool second = proj->proj(layerdisk_).fpgarzbin2projvm().value(); - int nfinephi = 3; - unsigned int projfinephi = - (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + nfinephi))) & ((1 << nfinephi) - 1); - int projfinerz = barrel_ ? proj->finezvm(layer_) : proj->finervm(disk_); + unsigned int projfinephi = (fpgaphi.value() >> (fpgaphi.nbits() - (nvmbits_ + NFINEPHIBITS))) & ((1<proj(layerdisk_).fpgafinerzvm().value(); - bool isPSseed = proj->PSseed() == 1; + bool isPSseed = proj->PSseed(); - int nbins = 8; - if (layerdisk_ >= 6) - nbins = 16; + 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 usefirst = stubmem->nStubsBin(iphi * nbins + slot) != 0; - bool usesecond = (second && (stubmem->nStubsBin(iphi * nbins + slot + 1) != 0)); - - if (usefirst) { - ProjectionTemp tmpProj(proj, slot, projrinv, projfinerz, projfinephi, iphi, usesecond, isPSseed); - inputProjBuffer_.store(tmpProj); - } else if (usesecond) { - ProjectionTemp tmpProj(proj, slot + 1, projrinv, projfinerz - 8, projfinephi, iphi, false, isPSseed); + 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 useProj = usefirstPlus || usesecondPlus || usefirstMinus || usesecondMinus; + + if (useProj) { + ProjectionTemp tmpProj(proj, + slot, + projrinv, + projfinerz, + projfinephi, + ivmMinus, + shift, + usefirstMinus, + usefirstPlus, + usesecondMinus, + usesecondPlus, + isPSseed); inputProjBuffer_.store(tmpProj); } + iproj++; if (iproj == projMem->nTracklets()) { iproj = 0; @@ -365,84 +361,90 @@ void MatchProcessor::execute() { //Step 2 //Check if we have ME that can process projection - if (istep >= step2delay && istep < settings_.maxStep("MP") + step2delay) { - bool addedProjection = false; - for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { - if (!matchengines_[iME].idle()) - countme++; - matchengines_[iME].step(); - //if match engine empty and we have queued projections add to match engine - if ((!addedProjection) && matchengines_[iME].idle() && (!inputProjBuffer_.empty())) { - ProjectionTemp tmpProj = inputProjBuffer_.read(); - VMStubsMEMemory* stubmem = vmstubs_[0]; - - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " adding projection to match engine"; - } - - int nbins = 8; - if (layerdisk_ >= 6) - nbins = 16; - - matchengines_[iME].init(stubmem, - tmpProj.iphi() * nbins + tmpProj.slot(), - tmpProj.projrinv(), - tmpProj.projfinerz(), - tmpProj.projfinephi(), - tmpProj.usesecond(), - tmpProj.isPSseed(), - tmpProj.proj()); - addedProjection = true; + bool addedProjection = false; + for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { + if (!matchengines_[iME].idle()) + countme++; + matchengines_[iME].step(print); + //if match engine empty and we have queued projections add to match engine + if ((!addedProjection) && matchengines_[iME].idle() && (!inputProjBuffer_.empty())) { + ProjectionTemp tmpProj = inputProjBuffer_.read(); + VMStubsMEMemory* stubmem = vmstubs_[0]; + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " adding projection to match engine"; } + + int nbins = (1 << N_RZBITS); + if (layerdisk_ >= N_LAYER) { + nbins*=2; //twice as many bins in disks (since there are two disks) + } + + matchengines_[iME].init(stubmem, + nbins, + tmpProj.slot(), + tmpProj.iphi(), + tmpProj.shift(), + tmpProj.projrinv(), + tmpProj.projfinerz(), + tmpProj.projfinephi(), + tmpProj.use(0, 0), + tmpProj.use(0, 1), + tmpProj.use(1, 0), + tmpProj.use(1, 1), + tmpProj.isPSseed(), + tmpProj.proj()); + addedProjection = true; } } //Step 3 //Check if we have candidate match to process - if (istep >= step3delay) { - unsigned int iMEbest = nMatchEngines_; - int bestTCID = -1; - bool bestInPipeline = false; - for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { - bool empty = matchengines_[iME].empty(); - medone = medone && (empty && matchengines_[iME].idle()); - if (empty && matchengines_[iME].idle()) - continue; - int currentTCID = empty ? matchengines_[iME].currentProj()->TCID() : matchengines_[iME].peek().first->TCID(); - if ((iMEbest == nMatchEngines_) || (currentTCID < bestTCID)) { - iMEbest = iME; - bestTCID = currentTCID; - bestInPipeline = empty; - } + unsigned int iMEbest = nMatchEngines_; + int bestTCID = -1; + bool bestInPipeline = false; + for (unsigned int iME = 0; iME < nMatchEngines_; iME++) { + bool empty = matchengines_[iME].empty(); + medone = medone && (empty && matchengines_[iME].idle()); + if (empty && matchengines_[iME].idle()) + continue; + int currentTCID = empty ? matchengines_[iME].currentProj()->TCID() : matchengines_[iME].peek().first->TCID(); + if ((iMEbest == nMatchEngines_) || (currentTCID < bestTCID)) { + iMEbest = iME; + bestTCID = currentTCID; + bestInPipeline = empty; } + } - if (iMEbest != nMatchEngines_ && (!bestInPipeline)) { - const std::pair& candmatch = matchengines_[iMEbest].read(); - - const Stub* fpgastub = candmatch.second; - Tracklet* tracklet = candmatch.first; + if (iMEbest != nMatchEngines_ && (!bestInPipeline)) { + std::pair candmatch = matchengines_[iMEbest].read(); - if (oldTracklet != nullptr) { - //allow equal here since we can have more than one cadidate match per tracklet projection - assert(oldTracklet->TCID() <= tracklet->TCID()); - } - oldTracklet = tracklet; + const Stub* fpgastub = candmatch.second; + Tracklet* tracklet = candmatch.first; - bool match = matchCalculator(tracklet, fpgastub); + if (oldTracklet != nullptr) { + //allow equal here since we can have more than one cadidate match per tracklet projection + assert(oldTracklet->TCID() <= tracklet->TCID()); + } + oldTracklet = tracklet; - if (settings_.debugTracklet() && match) { - edm::LogVerbatim("Tracklet") << getName() << " have match"; - } + bool match = matchCalculator(tracklet, fpgastub, print, istep); - countall++; - if (match) - countsel++; + if (settings_.debugTracklet() && match) { + edm::LogVerbatim("Tracklet") << getName() << " have match"; } + + countall++; + if (match) + countsel++; } - if ((projdone && medone) || (istep == settings_.maxStep("MP") + step3delay - 1)) { - globals_->ofstream("matchprocessor.txt") << getName() << " " << istep << " " << countall << " " << countsel << " " - << countme << " " << countinputproj << endl; + + if ((projdone && medone) || (istep == settings_.maxStep("MP") - 1)) { + if (settings_.writeMonitorData("MP")) { + globals_->ofstream("matchprocessor.txt") << getName() << " " << istep << " " << countall << " " << countsel + << " " << countme << " " << countinputproj << endl; + } break; } } @@ -452,21 +454,22 @@ void MatchProcessor::execute() { } } -bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { +bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub, bool, unsigned int) { const L1TStub* stub = fpgastub->l1tstub(); - if (layer_ != 0) { + if (layerdisk_ < N_LAYER) { + const Projection& proj = tracklet->proj(layerdisk_); int ir = fpgastub->r().value(); - int iphi = tracklet->fpgaphiproj(layer_).value(); - int icorr = (ir * tracklet->fpgaphiprojder(layer_).value()) >> icorrshift_; + int iphi = proj.fpgaphiproj().value(); + int icorr = (ir * proj.fpgaphiprojder().value()) >> icorrshift_; iphi += icorr; - int iz = tracklet->fpgazproj(layer_).value(); - int izcor = (ir * tracklet->fpgazprojder(layer_).value() + (1 << (icorzshift_ - 1))) >> icorzshift_; + 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_)); + int ideltaphi = (fpgastub->phi().value() - iphi) << phishift_; //Floating point calculations @@ -475,28 +478,27 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { double z = stub->z(); if (settings_.useapprox()) { - double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, phimax_)); + double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, 0.0)); assert(std::abs(dphi) < 0.001); - phi = fpgastub->phiapprox(phimin_, phimax_); + phi = fpgastub->phiapprox(phimin_, 0.0); z = fpgastub->zapprox(); r = fpgastub->rapprox(); } if (phi < 0) phi += 2 * M_PI; - phi -= phioffset_; + phi -= phimin_; - double dr = r - tracklet->rproj(layer_); + double dr = r - settings_.rmean(layerdisk_); assert(std::abs(dr) < settings_.drmax()); - double dphi = reco::reduceRange(phi - (tracklet->phiproj(layer_) + dr * tracklet->phiprojder(layer_))); + double dphi = reco::reduceRange(phi - (proj.phiproj() + dr * proj.phiprojder())); - double dz = z - (tracklet->zproj(layer_) + dr * tracklet->zprojder(layer_)); + double dz = z - (proj.rzproj() + dr * proj.rzprojder()); - double dphiapprox = - reco::reduceRange(phi - (tracklet->phiprojapprox(layer_) + dr * tracklet->phiprojderapprox(layer_))); + double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dr * proj.phiprojderapprox())); - double dzapprox = z - (tracklet->zprojapprox(layer_) + dr * tracklet->zprojderapprox(layer_)); + double dzapprox = z - (proj.rzprojapprox() + dr * proj.rzprojderapprox()); int seedindex = tracklet->getISeed(); @@ -507,11 +509,11 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { bool truthmatch = tracklet->stubtruthmatch(stub); HistBase* hists = globals_->histograms(); - hists->FillLayerResidual(layer_, + hists->FillLayerResidual(layerdisk_ + 1, seedindex, - dphiapprox * settings_.rmean(layer_ - 1), - ideltaphi * settings_.kphi1() * settings_.rmean(layer_ - 1), - ideltaz * fact_ * settings_.kz(), + dphiapprox * settings_.rmean(layerdisk_), + ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_), + (ideltaz << dzshift_) * settings_.kz(), dz, truthmatch); } @@ -520,44 +522,42 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { double pt = 0.01 * settings_.c() * settings_.bfield() / std::abs(tracklet->rinv()); globals_->ofstream("layerresiduals.txt") - << layer_ << " " << seedindex << " " << pt << " " - << ideltaphi * settings_.kphi1() * settings_.rmean(layer_ - 1) << " " - << dphiapprox * settings_.rmean(layer_ - 1) << " " - << phimatchcut_[seedindex] * settings_.kphi1() * settings_.rmean(layer_ - 1) << " " - << ideltaz * fact_ * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() << endl; + << layerdisk_ + 1 << " " << seedindex << " " << pt << " " + << ideltaphi * settings_.kphi1() * settings_.rmean(layerdisk_) << " " + << dphiapprox * settings_.rmean(layerdisk_) << " " + << phimatchcut_[seedindex] * settings_.kphi1() * settings_.rmean(layerdisk_) << " " + << (ideltaz << dzshift_) * settings_.kz() << " " << dz << " " << zmatchcut_[seedindex] * settings_.kz() + << endl; } - bool imatch = (std::abs(ideltaphi) <= phifact_ * phimatchcut_[seedindex]) && - (std::abs(ideltaz * fact_) <= rzfact_ * zmatchcut_[seedindex]); + bool imatch = ((unsigned int)std::abs(ideltaphi) <= phimatchcut_[seedindex]) && + ((unsigned int)std::abs(ideltaz << dzshift_) <= zmatchcut_[seedindex]); if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << getName() << " imatch = " << imatch << " ideltaphi cut " << ideltaphi << " " - << phimatchcut_[seedindex] << " ideltaz*fact cut " << ideltaz * fact_ << " " - << zmatchcut_[seedindex]; + << phimatchcut_[seedindex] << " ideltaz< 0.2 || std::abs(dphiapprox) > 0.2) { - edm::LogPrint("Tracklet") << "WARNING dphi and/or dphiapprox too large : " << dphi << " " << dphiapprox; + //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; } - assert(std::abs(dphi) < 0.2); - assert(std::abs(dphiapprox) < 0.2); - if (imatch) { - tracklet->addMatch(layer_, + tracklet->addMatch(layerdisk_, ideltaphi, ideltaz, dphi, dz, dphiapprox, dzapprox, - (phiregion_ << 7) + fpgastub->stubindex().value(), - stub->r(), + (phiregion_ << N_BITSMEMADDRESS) + fpgastub->stubindex().value(), fpgastub); if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet << " " - << iSector_; + edm::LogVerbatim("Tracklet") << "Accepted full match in layer " << getName() << " " << tracklet; } int iSeed = tracklet->getISeed(); @@ -574,35 +574,31 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { assert(stub->z() * tracklet->t() > 0.0); int sign = (tracklet->t() > 0.0) ? 1 : -1; - int disk = sign * disk_; + int disk = sign * (layerdisk_ - N_LAYER + 1); assert(disk != 0); //Perform integer calculations here int iz = fpgastub->z().value(); - int iphi = tracklet->fpgaphiprojdisk(disk).value(); - int shifttmp = 6; //TODO - express in terms of constants - assert(shifttmp >= 0); - int iphicorr = (iz * tracklet->fpgaphiprojderdisk(disk).value()) >> shifttmp; + const Projection& proj = tracklet->proj(layerdisk_); - iphi += iphicorr; + int iphi = proj.fpgaphiproj().value(); + int iphicorr = (iz * proj.fpgaphiprojder().value()) >> icorrshift_; - int ir = tracklet->fpgarprojdisk(disk).value(); - - int shifttmp2 = 7; //TODO - express in terms of constants - assert(shifttmp2 >= 0); - int ircorr = (iz * tracklet->fpgarprojderdisk(disk).value()) >> shifttmp2; + iphi += iphicorr; + int ir = proj.fpgarzproj().value(); + int ircorr = (iz * proj.fpgarzprojder().value()) >> icorzshift_; ir += ircorr; - int ideltaphi = fpgastub->phi().value() * settings_.kphi() / settings_.kphi() - iphi; + int ideltaphi = fpgastub->phi().value() - iphi; int irstub = fpgastub->r().value(); int ialphafact = 0; if (!stub->isPSmodule()) { assert(irstub < (int)N_DSS_MOD * 2); - if (disk_ <= 2) { + if (layerdisk_ - N_LAYER <= 1) { ialphafact = ialphafactinner_[irstub]; irstub = settings_.rDSSinner(irstub) / settings_.kr(); } else { @@ -614,8 +610,8 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { int ideltar = (irstub * settings_.kr()) / settings_.krprojshiftdisk() - ir; if (!stub->isPSmodule()) { - int ialphanew = fpgastub->alphanew().value(); - int iphialphacor = ((ideltar * ialphanew * ialphafact) >> settings_.alphashift()); + int ialpha = fpgastub->alpha().value(); + int iphialphacor = ((ideltar * ialpha * ialphafact) >> settings_.alphashift()); ideltaphi += iphialphacor; } @@ -626,36 +622,35 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { double r = stub->r(); if (settings_.useapprox()) { - double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, phimax_)); + double dphi = reco::reduceRange(phi - fpgastub->phiapprox(phimin_, 0.0)); assert(std::abs(dphi) < 0.001); - phi = fpgastub->phiapprox(phimin_, phimax_); + phi = fpgastub->phiapprox(phimin_, 0.0); z = fpgastub->zapprox(); r = fpgastub->rapprox(); } if (phi < 0) phi += 2 * M_PI; - phi -= phioffset_; + phi -= phimin_; - double dz = z - sign * settings_.zmean(disk_ - 1); + double dz = z - sign * settings_.zmean(layerdisk_ - N_LAYER); if (std::abs(dz) > settings_.dzmax()) { - edm::LogProblem("Tracklet") << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " - << tracklet->getISeed(); + edm::LogProblem("Tracklet") << __FILE__ << ":" << __LINE__ << " " << name_ << " " << tracklet->getISeed(); edm::LogProblem("Tracklet") << "stub " << stub->z() << " disk " << disk << " " << dz; assert(std::abs(dz) < settings_.dzmax()); } - double phiproj = tracklet->phiprojdisk(disk) + dz * tracklet->phiprojderdisk(disk); - double rproj = tracklet->rprojdisk(disk) + dz * tracklet->rprojderdisk(disk); + double phiproj = proj.phiproj() + dz * proj.phiprojder(); + double rproj = proj.rzproj() + dz * proj.rzprojder(); double deltar = r - rproj; double dr = stub->r() - rproj; - double drapprox = stub->r() - (tracklet->rprojapproxdisk(disk) + dz * tracklet->rprojderapproxdisk(disk)); + double drapprox = stub->r() - (proj.rzprojapprox() + dz * proj.rzprojderapprox()); double dphi = reco::reduceRange(phi - phiproj); - double dphiapprox = - reco::reduceRange(phi - (tracklet->phiprojapproxdisk(disk) + dz * tracklet->phiprojderapproxdisk(disk))); + + double dphiapprox = reco::reduceRange(phi - (proj.phiprojapprox() + dz * proj.phiprojderapprox())); double drphi = dphi * stub->r(); double drphiapprox = dphiapprox * stub->r(); @@ -686,9 +681,10 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { 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; + << layerdisk_ - N_LAYER + 1 << " " << stub->isPSmodule() << " " << tracklet->layer() << " " + << abs(tracklet->disk()) << " " << pt << " " << ideltaphi * settings_.kphi() * stub->r() << " " << drphiapprox + << " " << drphicut << " " << ideltar * settings_.krprojshiftdisk() << " " << deltar << " " << drcut << " " + << endl; } bool match = (std::abs(drphi) < drphicut) && (std::abs(deltar) < drcut); @@ -705,26 +701,24 @@ bool MatchProcessor::matchCalculator(Tracklet* tracklet, const Stub* fpgastub) { edm::LogVerbatim("Tracklet") << "MatchCalculator found match in disk " << getName(); } - if (std::abs(dphi) >= 0.25) { + if (std::abs(dphi) >= third*settings_.dphisectorHG()) { edm::LogPrint("Tracklet") << "dphi " << dphi << " ISeed " << tracklet->getISeed(); } - assert(std::abs(dphi) < 0.25); - assert(std::abs(dphiapprox) < 0.25); - - tracklet->addMatchDisk(disk, - ideltaphi, - ideltar, - drphi / stub->r(), - dr, - drphiapprox / stub->r(), - drapprox, - stub->alpha(settings_.stripPitch(stub->isPSmodule())), - (phiregion_ << 7) + fpgastub->stubindex().value(), - stub->z(), - fpgastub); + assert(std::abs(dphi) < third*settings_.dphisectorHG()); + assert(std::abs(dphiapprox) < third*settings_.dphisectorHG()); + + tracklet->addMatch(layerdisk_, + ideltaphi, + ideltar, + drphi / stub->r(), + dr, + drphiapprox / stub->r(), + drapprox, + (phiregion_ << N_BITSMEMADDRESS) + fpgastub->stubindex().value(), + fpgastub); + if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet << " " - << iSector_; + edm::LogVerbatim("Tracklet") << "Accepted full match in disk " << getName() << " " << tracklet; } int iSeed = tracklet->getISeed(); diff --git a/L1Trigger/TrackFindingTracklet/src/MemoryBase.cc b/L1Trigger/TrackFindingTracklet/src/MemoryBase.cc index e7c0ee7b241ec..580dae3a8df7f 100644 --- a/L1Trigger/TrackFindingTracklet/src/MemoryBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/MemoryBase.cc @@ -1,4 +1,5 @@ #include "L1Trigger/TrackFindingTracklet/interface/MemoryBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" @@ -9,8 +10,8 @@ using namespace trklet; using namespace std; -MemoryBase::MemoryBase(string name, Settings const& settings, unsigned int iSector) : name_(name), settings_(settings) { - iSector_ = iSector; +MemoryBase::MemoryBase(string name, Settings const& settings) : name_(name), settings_(settings) { + iSector_ = 0; bx_ = 0; event_ = 0; } @@ -71,14 +72,7 @@ void MemoryBase::findAndReplaceAll(std::string& data, std::string toSearch, std: } void MemoryBase::openFile(bool first, std::string dirName, std::string filebase) { - if (not std::filesystem::exists(dirName)) { - int fail = system((string("mkdir -p ") + dirName).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirName; - } - - std::string fname = dirName + filebase; - fname += getName(); + std::string fname = filebase + getName(); findAndReplaceAll(fname, "PHIa", "PHIaa"); findAndReplaceAll(fname, "PHIb", "PHIbb"); @@ -96,16 +90,7 @@ void MemoryBase::openFile(bool first, std::string dirName, std::string filebase) fname += std::to_string(iSector_ + 1); fname += ".dat"; - if (first) { - bx_ = 0; - event_ = 1; - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else { - out_.open(fname, std::ofstream::app); - } + openfile(out_, first, dirName, dirName + fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc index b0a478f962424..20fb0b1082ce9 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProcessBase.cc @@ -11,20 +11,8 @@ using namespace trklet; using namespace std; -ProcessBase::ProcessBase(string name, Settings const& settings, Globals* global, unsigned int iSector) - : name_(name), settings_(settings), globals_(global) { - iSector_ = iSector; - double dphi = 2 * M_PI / N_SECTOR; - double dphiHG = 0.5 * settings_.dphisectorHG() - M_PI / N_SECTOR; - phimin_ = iSector_ * dphi - dphiHG; - phimax_ = phimin_ + dphi + 2 * dphiHG; - phimin_ -= M_PI / N_SECTOR; - phimax_ -= M_PI / N_SECTOR; - if (phimin_ > M_PI) { - phimin_ -= 2 * M_PI; - phimax_ -= 2 * M_PI; - } -} +ProcessBase::ProcessBase(string name, Settings const& settings, Globals* global) + : name_(name), settings_(settings), globals_(global) {} unsigned int ProcessBase::nbits(unsigned int power) { if (power == 2) diff --git a/L1Trigger/TrackFindingTracklet/src/Projection.cc b/L1Trigger/TrackFindingTracklet/src/Projection.cc new file mode 100644 index 0000000000000..2f08e1a5348a2 --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/Projection.cc @@ -0,0 +1,132 @@ + +#include "L1Trigger/TrackFindingTracklet/interface/Projection.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +#include "FWCore/MessageLogger/interface/MessageLogger.h" +#include + +using namespace std; +using namespace trklet; + +void Projection::init(Settings const& settings, + unsigned int layerdisk, + int iphiproj, + int irzproj, + int iphider, + int irzder, + double phiproj, + double rzproj, + double phiprojder, + double rzprojder, + double phiprojapprox, + double rzprojapprox, + double phiprojderapprox, + double rzprojderapprox, + bool isPSseed) { + assert(layerdisk < N_LAYER + N_DISK); + + valid_ = true; + + fpgaphiproj_.set(iphiproj, settings.nphibitsstub(layerdisk), true, __LINE__, __FILE__); + + if (layerdisk < N_LAYER) { + fpgarzproj_.set(irzproj, settings.nzbitsstub(layerdisk), false, __LINE__, __FILE__); + } else { + fpgarzproj_.set(irzproj, settings.nrbitsstub(layerdisk), false, __LINE__, __FILE__); + } + + if (layerdisk < N_LAYER) { + if (layerdisk < N_PSLAYER) { + fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__); + fpgarzprojder_.set(irzder, settings.nbitszprojderL123(), false, __LINE__, __FILE__); + } else { + fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL456(), false, __LINE__, __FILE__); + fpgarzprojder_.set(irzder, settings.nbitszprojderL456(), false, __LINE__, __FILE__); + } + } else { + fpgaphiprojder_.set(iphider, settings.nbitsphiprojderL123(), false, __LINE__, __FILE__); + fpgarzprojder_.set(irzder, settings.nrbitsprojderdisk(), false, __LINE__, __FILE__); + } + + if (layerdisk < N_LAYER) { + ////Separate the vm projections into zbins + ////This determines the central bin: + ////int zbin=4+(zproj.value()>>(zproj.nbits()-3)); + ////But we need some range (particularly for L5L6 seed projecting to L1-L3): + int offset = isPSseed ? 1 : 4; + + int ztemp = fpgarzproj_.value() >> (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; + } + + assert(zbin1 <= zbin2); + assert(zbin2 - zbin1 <= 1); + + fpgarzbin1projvm_.set(zbin1, settings.MEBinsBits(), true, __LINE__, __FILE__); // first z bin + + int nextbin = zbin1 != zbin2; + fpgarzbin2projvm_.set(nextbin, 1, true, __LINE__, __FILE__); // need to check adjacent z bin? + + //fine vm z bits. Use 4 bits for fine position. starting at zbin 1 + int finez = ((1 << (settings.MEBinsBits() + NFINERZBITS - 1)) + ztemp) - (zbin1 << NFINERZBITS); + + fpgafinerzvm_.set(finez, NFINERZBITS + 1, true, __LINE__, __FILE__); // fine z postions starting at zbin1 + + } else { + //TODO the -3 and +3 should be evaluated and efficiency for matching hits checked. + //This code should be migrated in the ProjectionRouter + double roffset = 3.0; + int rbin1 = 8.0 * (irzproj * settings.krprojshiftdisk() - roffset - settings.rmindiskvm()) / + (settings.rmaxdisk() - settings.rmindiskvm()); + int rbin2 = 8.0 * (irzproj * settings.krprojshiftdisk() + roffset - settings.rmindiskvm()) / + (settings.rmaxdisk() - settings.rmindiskvm()); + + if (rbin1 < 0) { + rbin1 = 0; + } + rbin2 = clamp(rbin2, 0, 7); + + assert(rbin1 <= rbin2); + assert(rbin2 - rbin1 <= 1); + + int finer = 64 * + ((irzproj * settings.krprojshiftdisk() - settings.rmindiskvm()) - + rbin1 * (settings.rmaxdisk() - settings.rmindiskvm()) / 8.0) / + (settings.rmaxdisk() - settings.rmindiskvm()); + + finer = clamp(finer, 0, 15); + + int diff = rbin1 != rbin2; + if (irzder < 0) + rbin1 += 8; + + fpgarzbin1projvm_.set(rbin1, 4, true, __LINE__, __FILE__); // first r bin + fpgarzbin2projvm_.set(diff, 1, true, __LINE__, __FILE__); // need to check adjacent r bin + + fpgafinerzvm_.set(finer, 4, true, __LINE__, __FILE__); // fine r postions starting at rbin1 + } + + //fine phi bits + int projfinephi = + (fpgaphiproj_.value() >> + (fpgaphiproj_.nbits() - (settings.nbitsallstubs(layerdisk) + settings.nbitsvmme(layerdisk) + NFINEPHIBITS))) & + ((1 << NFINEPHIBITS) - 1); + fpgafinephivm_.set(projfinephi, NFINEPHIBITS, true, __LINE__, __FILE__); // fine phi postions + + phiproj_ = phiproj; + rzproj_ = rzproj; + phiprojder_ = phiprojder; + rzprojder_ = rzprojder; + + phiprojapprox_ = phiprojapprox; + rzprojapprox_ = rzprojapprox; + phiprojderapprox_ = phiprojderapprox; + rzprojderapprox_ = rzprojderapprox; +} diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc index 06856031b1e1d..711b0972bf715 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionRouter.cc @@ -10,8 +10,8 @@ using namespace std; using namespace trklet; -ProjectionRouter::ProjectionRouter(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { +ProjectionRouter::ProjectionRouter(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) { layerdisk_ = initLayerDisk(3); vmprojs_.resize(settings_.nvmme(layerdisk_), nullptr); @@ -81,7 +81,7 @@ void ProjectionRouter::execute() { for (auto& iproj : inputproj_) { for (unsigned int i = 0; i < iproj->nTracklets(); i++) { - if (allprojcount > settings_.maxStep("PR")) + if (allprojcount >= settings_.maxStep("PR")) continue; Tracklet* tracklet = iproj->getTracklet(i); @@ -89,29 +89,30 @@ void ProjectionRouter::execute() { FPGAWord fpgaphi; if (layerdisk_ < N_LAYER) { - fpgaphi = tracklet->fpgaphiproj(layerdisk_ + 1); + fpgaphi = tracklet->proj(layerdisk_).fpgaphiproj(); } else { int disk = layerdisk_ - (N_LAYER - 1); - fpgaphi = tracklet->fpgaphiprojdisk(disk); + + 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 = (tracklet->fpgarprojdisk(disk).value() >> (tracklet->fpgarprojdisk(disk).nbits() - nrbits_)) & - ((1 << nrbits_) - 1); - int phiderindex = (tracklet->fpgaphiprojderdisk(disk).value() >> - (tracklet->fpgaphiprojderdisk(disk).nbits() - nphiderbits_)) & + 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 = (tracklet->fpgarprojderdisk(disk).value() < 0); + int signindex = (proj.fpgarzprojder().value() < 0); int bendindex = (signindex << (nphiderbits_ + nrbits_)) + (rindex << (nphiderbits_)) + phiderindex; int ibendproj = globals_->projectionRouterBendTable()->bendLoookup(disk - 1, bendindex); - tracklet->setBendIndex(ibendproj, disk); + proj.setBendIndex(ibendproj); } unsigned int iphivm = @@ -129,6 +130,11 @@ void ProjectionRouter::execute() { vmprojs_[iphivm]->addTracklet(tracklet, allprojcount); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " projection to " << vmprojs_[iphivm]->getName() << " iphivm " + << iphivm; + } + allprojcount++; } } diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc index 6ddbcc3628cf2..78de56f0076db 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionRouterBendTable.cc @@ -36,7 +36,7 @@ void ProjectionRouterBendTable::init(Settings const& settings, double rinv = -phider * (2.0 * t); double stripPitch = (rproj < settings.rcrit()) ? settings.stripPitch(true) : settings.stripPitch(false); - double bendproj = 0.5 * bend(rproj, rinv, stripPitch); + double bendproj = bendstrip(rproj, rinv, stripPitch); int ibendproj = 2.0 * bendproj + 15.5; if (ibendproj < 0) diff --git a/L1Trigger/TrackFindingTracklet/src/ProjectionTemp.cc b/L1Trigger/TrackFindingTracklet/src/ProjectionTemp.cc index e8f902f1dd27d..f43b6fd2056c6 100644 --- a/L1Trigger/TrackFindingTracklet/src/ProjectionTemp.cc +++ b/L1Trigger/TrackFindingTracklet/src/ProjectionTemp.cc @@ -9,7 +9,11 @@ ProjectionTemp::ProjectionTemp(Tracklet* proj, int projfinerz, unsigned int projfinephi, unsigned int iphi, - bool usesecond, + int shift, + bool usefirstMinus, + bool usefirstPlus, + bool usesecondMinus, + bool usesecondPlus, bool isPSseed) { proj_ = proj; slot_ = slot; @@ -17,7 +21,11 @@ ProjectionTemp::ProjectionTemp(Tracklet* proj, projfinerz_ = projfinerz; projfinephi_ = projfinephi; iphi_ = iphi; - usesecond_ = usesecond; + shift_ = shift; + use_[0][0] = usefirstMinus; + use_[0][1] = usefirstPlus; + use_[1][0] = usesecondMinus; + use_[1][1] = usesecondPlus; isPSseed_ = isPSseed; } @@ -28,6 +36,10 @@ ProjectionTemp::ProjectionTemp() { projfinerz_ = 0; projfinephi_ = 0; iphi_ = 0; - usesecond_ = false; + shift_ = 0; + use_[0][0] = false; + use_[0][1] = false; + use_[1][0] = false; + use_[1][1] = false; isPSseed_ = false; } diff --git a/L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc b/L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc index 8c3e3f76ae02f..c334a7c488b01 100644 --- a/L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc +++ b/L1Trigger/TrackFindingTracklet/src/PurgeDuplicate.cc @@ -22,8 +22,8 @@ using namespace std; using namespace trklet; -PurgeDuplicate::PurgeDuplicate(std::string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) {} +PurgeDuplicate::PurgeDuplicate(std::string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) {} void PurgeDuplicate::addOutput(MemoryBase* memory, std::string output) { if (settings_.writetrace()) { @@ -78,7 +78,7 @@ void PurgeDuplicate::addInput(MemoryBase* memory, std::string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " could not find input: " << input; } -void PurgeDuplicate::execute(std::vector& outputtracks_) { +void PurgeDuplicate::execute(std::vector& outputtracks_, unsigned int iSector) { inputtracklets_.clear(); inputtracks_.clear(); @@ -92,7 +92,7 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { continue; for (unsigned int j = 0; j < inputtrackfit->nTracks(); j++) { Track* aTrack = inputtrackfit->getTrack(j)->getTrack(); - aTrack->setSector(iSector_); + aTrack->setSector(iSector); inputtracks_.push_back(aTrack); } } @@ -326,14 +326,14 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { Tracklet* tracklet = inputtracklets_[itrk]; std::vector trackstublist = inputstublists_[itrk]; - HybridFit hybridFitter(iSector_, settings_, globals_); + HybridFit hybridFitter(iSector, settings_, globals_); hybridFitter.Fit(tracklet, trackstublist); // If the track was accepted (and thus fit), add to output if (tracklet->fit()) { // Add track to output if it wasn't merged into another Track* outtrack = tracklet->getTrack(); - outtrack->setSector(iSector_); + outtrack->setSector(iSector); if (trackInfo[itrk].second == true) outtrack->setDuplicate(true); else @@ -342,7 +342,7 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { // Add all tracks to standalone root file output outtrack->setStubIDpremerge(inputstubidslists_[itrk]); outtrack->setStubIDprefit(mergedstubidslists_[itrk]); - outputtracks_.push_back(outtrack); + outputtracks_.push_back(*outtrack); } } } @@ -362,7 +362,7 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { if (inputtracks_[itrk]->duplicate()) edm::LogPrint("Tracklet") << "WARNING: Track already tagged as duplicate!!"; - double phiBin = (inputtracks_[itrk]->phi0(settings_) - 2 * M_PI / 27 * iSector_) / (2 * M_PI / 9 / 50) + 9; + double phiBin = (inputtracks_[itrk]->phi0(settings_) - 2 * M_PI / 27 * iSector) / (2 * M_PI / 9 / 50) + 9; phiBin = std::max(phiBin, 0.); phiBin = std::min(phiBin, 34.); @@ -374,7 +374,7 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { inputtracks_[itrk]->setDuplicate(true); grid[(int)phiBin][(int)ptBin] = true; - double phiTest = inputtracks_[itrk]->phi0(settings_) - 2 * M_PI / 27 * iSector_; + double phiTest = inputtracks_[itrk]->phi0(settings_) - 2 * M_PI / 27 * iSector; if (phiTest < -2 * M_PI / 27) edm::LogVerbatim("Tracklet") << "track phi too small!"; if (phiTest > 2 * 2 * M_PI / 27) @@ -463,14 +463,14 @@ void PurgeDuplicate::execute(std::vector& outputtracks_) { if (inputtrackfits_[i]->getTrack(j)->getTrack()->duplicate() == 0) { if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " + fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector << " " << inputtrackfits_[i]->getTrack(j)->getISeed() << endl; fout.close(); } outputtracklets_[i]->addTrack(inputtrackfits_[i]->getTrack(j)); } //For root file: - outputtracks_.push_back(inputtrackfits_[i]->getTrack(j)->getTrack()); + outputtracks_.push_back(*inputtrackfits_[i]->getTrack(j)->getTrack()); } } } @@ -483,8 +483,14 @@ double PurgeDuplicate::getPhiRes(Tracklet* curTracklet, const Stub* curStub) { // Get phi position of stub stubphi = curStub->l1tstub()->phi(); // Get region that the stub is in (Layer 1->6, Disk 1->5) - int Layer = curStub->layer().value() + 1; - int Disk = curStub->disk().value(); + int Layer = curStub->layerdisk() + 1; + if (Layer > N_LAYER) { + Layer = 0; + } + int Disk = curStub->layerdisk() - (N_LAYER - 1); + if (Disk < 0) { + Disk = 0; + } // Get phi projection of tracklet int seedindex = curTracklet->seedIndex(); // If this stub is a seed stub, set projection=phi, so that res=0 @@ -499,13 +505,8 @@ double PurgeDuplicate::getPhiRes(Tracklet* curTracklet, const Stub* curStub) { (seedindex == 11 && (Layer == 2 || abs(Disk) == 1 || abs(Disk) == 2))) { phiproj = stubphi; // Otherwise, get projection of tracklet - } else if (Layer != 0) { - phiproj = curTracklet->phiproj(Layer); - } else if (Disk != 0) { - phiproj = curTracklet->phiprojdisk(Disk); } else { - throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Layer: " << Layer << " -- Disk: " << Disk - << " Stub is not layer or disk in getPhiRes"; + phiproj = curTracklet->proj(curStub->layerdisk()).phiproj(); } // Calculate residual phires = std::abs(stubphi - phiproj); diff --git a/L1Trigger/TrackFindingTracklet/src/Residual.cc b/L1Trigger/TrackFindingTracklet/src/Residual.cc new file mode 100644 index 0000000000000..1507d73bc4e6b --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/Residual.cc @@ -0,0 +1,44 @@ +#include "L1Trigger/TrackFindingTracklet/interface/Residual.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +using namespace std; +using namespace trklet; + +void Residual::init(Settings const& settings, + unsigned int layerdisk, + int iphiresid, + int irzresid, + int istubid, + double phiresid, + double rzresid, + double phiresidapprox, + double rzresidapprox, + const Stub* stubptr) { + assert(layerdisk < N_LAYER + N_DISK); + + if (valid_ && (std::abs(iphiresid) > std::abs(fpgaphiresid_.value()))) + return; + + valid_ = true; + + layerdisk_ = layerdisk; + + fpgaphiresid_.set(iphiresid, settings.phiresidbits(), false, __LINE__, __FILE__); + if (layerdisk < N_LAYER) { + fpgarzresid_.set(irzresid, settings.zresidbits(), false, __LINE__, __FILE__); + } else { + fpgarzresid_.set(irzresid, settings.rresidbits(), false, __LINE__, __FILE__); + } + + int nbitsid = 10; + fpgastubid_.set(istubid, nbitsid, true, __LINE__, __FILE__); + assert(!fpgaphiresid_.atExtreme()); + + phiresid_ = phiresid; + rzresid_ = rzresid; + + phiresidapprox_ = phiresidapprox; + rzresidapprox_ = rzresidapprox; + + stubptr_ = stubptr; +} diff --git a/L1Trigger/TrackFindingTracklet/src/SLHCEvent.cc b/L1Trigger/TrackFindingTracklet/src/SLHCEvent.cc index 966bc40bca0e6..4ea8f49d3f953 100644 --- a/L1Trigger/TrackFindingTracklet/src/SLHCEvent.cc +++ b/L1Trigger/TrackFindingTracklet/src/SLHCEvent.cc @@ -1,73 +1,28 @@ #include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" - #include "FWCore/MessageLogger/interface/MessageLogger.h" using namespace std; using namespace trklet; -L1SimTrack::L1SimTrack() { - eventid_ = -1; - trackid_ = -1; -} - -L1SimTrack::L1SimTrack( - int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz) { - eventid_ = eventid; - trackid_ = trackid; - type_ = type; - pt_ = pt; - eta_ = eta; - phi_ = phi; - vx_ = vx; - vy_ = vy; - vz_ = vz; -} - -void L1SimTrack::write(ofstream& out) { - if (pt_ > -2.0) { - out << "SimTrack: " << eventid_ << "\t" << trackid_ << "\t" << type_ << "\t" << pt_ << "\t" << eta_ << "\t" << phi_ - << "\t" << vx_ << "\t" << vy_ << "\t" << vz_ << "\t" << endl; - } -} - -void L1SimTrack::write(ostream& out) { - if (pt_ > -2) { - out << "SimTrack: " << eventid_ << "\t" << trackid_ << "\t" << type_ << "\t" << pt_ << "\t" << eta_ << "\t" << phi_ - << "\t" << vx_ << "\t" << vy_ << "\t" << vz_ << "\t" << endl; - } -} - void SLHCEvent::addL1SimTrack( int eventid, int trackid, int type, double pt, double eta, double phi, double vx, double vy, double vz) { - vx -= x_offset_; - vy -= y_offset_; L1SimTrack simtrack(eventid, trackid, type, pt, eta, phi, vx, vy, vz); simtracks_.push_back(simtrack); } -bool SLHCEvent::addStub(int layer, - int ladder, - int module, - int strip, - int eventid, - vector tps, - double pt, - double bend, +bool SLHCEvent::addStub(string DTClink, + int region, + int layerdisk, + string stubword, + int isPSmodule, + int isFlipped, double x, double y, double z, - int isPSmodule, - int isFlipped) { - if (layer > 999 && layer < 1999 && z < 0.0) { - layer += 1000; - } - - layer--; - x -= x_offset_; - y -= y_offset_; - - L1TStub stub( - eventid, tps, -1, -1, layer, ladder, module, strip, x, y, z, -1.0, -1.0, pt, bend, isPSmodule, isFlipped); + double bend, + double strip, + vector tps) { + L1TStub stub(DTClink, region, layerdisk, stubword, isPSmodule, isFlipped, x, y, z, bend, strip, tps); stubs_.push_back(stub); return true; @@ -76,13 +31,6 @@ bool SLHCEvent::addStub(int layer, SLHCEvent::SLHCEvent(istream& in) { string tmp; in >> tmp; - while (tmp == "Map:") { - in >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp; - in >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp >> tmp; - } - if (tmp == "EndMap") { - in >> tmp; - } if (tmp != "Event:") { edm::LogVerbatim("Tracklet") << "Expected to read 'Event:' but found:" << tmp; if (tmp.empty()) { @@ -105,67 +53,44 @@ SLHCEvent::SLHCEvent(istream& in) { int eventid; int trackid; int type; - string pt_str; - string eta_str; - string phi_str; - string vx_str; - string vy_str; - string vz_str; double pt; double eta; double phi; double vx; double vy; double vz; - in >> eventid >> trackid >> type >> pt_str >> eta_str >> phi_str >> vx_str >> vy_str >> vz_str; - pt = strtod(pt_str.c_str(), nullptr); - eta = strtod(eta_str.c_str(), nullptr); - phi = strtod(phi_str.c_str(), nullptr); - vx = strtod(vx_str.c_str(), nullptr); - vy = strtod(vy_str.c_str(), nullptr); - vz = strtod(vz_str.c_str(), nullptr); - vx -= x_offset_; - vy -= y_offset_; + in >> eventid >> trackid >> type >> pt >> eta >> phi >> vx >> vy >> vz; L1SimTrack simtrack(eventid, trackid, type, pt, eta, phi, vx, vy, vz); simtracks_.push_back(simtrack); in >> tmp; } - int oldlayer = 0; - int oldladder = 0; - int oldmodule = 0; - int oldcbc = -1; - int count = 1; - double oldz = -1000.0; - //read stubs in >> tmp; - while (tmp != "StubEnd") { + while (tmp != "Stubend") { if (!in.good()) { - edm::LogVerbatim("Tracklet") << "File not good"; + edm::LogVerbatim("Tracklet") << "File not good (SLHCEvent)"; abort(); }; - if (!(tmp == "Stub:" || tmp == "StubEnd")) { + if (!(tmp == "Stub:" || tmp == "Stubend")) { edm::LogVerbatim("Tracklet") << "Expected to read 'Stub:' or 'StubEnd' but found:" << tmp; abort(); } - int layer; - int ladder; - int module; - int eventid; - vector tps; - int strip; - double pt; + string DTClink; + int region; + int layerdisk; + string stubword; + int isPSmodule; + int isFlipped; double x; double y; double z; double bend; - int isPSmodule; - int isFlipped; - + double strip; unsigned int ntps; + vector tps; - in >> layer >> ladder >> module >> strip >> eventid >> pt >> x >> y >> z >> bend >> isPSmodule >> isFlipped >> ntps; + in >> DTClink >> region >> layerdisk >> stubword >> isPSmodule >> isFlipped >> x >> y >> z >> bend >> strip >> ntps; for (unsigned int itps = 0; itps < ntps; itps++) { int tp; @@ -173,36 +98,14 @@ SLHCEvent::SLHCEvent(istream& in) { tps.push_back(tp); } - if (layer > 999 && layer < 1999 && z < 0.0) { //negative disk - layer += 1000; - } - - int cbc = strip / 126; - if (layer > 3 && layer == oldlayer && ladder == oldladder && module == oldmodule && cbc == oldcbc && - std::abs(oldz - z) < 1.0) { - count++; - } else { - oldlayer = layer; - oldladder = ladder; - oldmodule = module; - oldcbc = cbc; - oldz = z; - count = 1; - } - - layer--; - x -= x_offset_; - y -= y_offset_; - - L1TStub stub( - eventid, tps, -1, -1, layer, ladder, module, strip, x, y, z, -1.0, -1.0, pt, bend, isPSmodule, isFlipped); + L1TStub stub(DTClink, region, layerdisk, stubword, isPSmodule, isFlipped, x, y, z, bend, strip, tps); in >> tmp; double t = std::abs(stub.z()) / stub.r(); double eta = asinh(t); - if (std::abs(eta) < 2.6 && count <= 100) { + if (std::abs(eta) < 2.6) { stubs_.push_back(stub); } } @@ -219,21 +122,7 @@ void SLHCEvent::write(ofstream& out) { for (auto& stub : stubs_) { stub.write(out); } - out << "StubEnd" << endl; -} - -void SLHCEvent::write(ostream& out) { - out << "Event: " << eventnum_ << endl; - - for (auto& simtrack : simtracks_) { - simtrack.write(out); - } - out << "SimTrackEnd" << endl; - - for (auto& stub : stubs_) { - stub.write(out); - } - out << "StubEnd" << endl; + out << "Stubend" << endl; } unsigned int SLHCEvent::layersHit(int tpid, int& nlayers, int& ndisks) { @@ -283,11 +172,3 @@ unsigned int SLHCEvent::layersHit(int tpid, int& nlayers, int& ndisks) { return l1 + 2 * l2 + 4 * l3 + 8 * l4 + 16 * l5 + 32 * l6 + 64 * d1 + 128 * d2 + 256 * d3 + 512 * d4 + 1024 * d5; } - -int SLHCEvent::getSimtrackFromSimtrackid(int simtrackid, int eventid) const { - for (unsigned int i = 0; i < simtracks_.size(); i++) { - if (simtracks_[i].trackid() == simtrackid && simtracks_[i].eventid() == eventid) - return i; - } - return -1; -} diff --git a/L1Trigger/TrackFindingTracklet/src/Sector.cc b/L1Trigger/TrackFindingTracklet/src/Sector.cc index 9ecef0c857f3e..c0d874d16d8de 100644 --- a/L1Trigger/TrackFindingTracklet/src/Sector.cc +++ b/L1Trigger/TrackFindingTracklet/src/Sector.cc @@ -3,8 +3,10 @@ #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/DTCLinkMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/StubPairsMemory.h" @@ -18,6 +20,7 @@ #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" @@ -37,12 +40,18 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "FWCore/Utilities/interface/Exception.h" #include "DataFormats/Math/interface/deltaPhi.h" +#include "L1Trigger/TrackFindingTracklet/interface/VMRouterPhiCorrTable.h" using namespace std; using namespace trklet; -Sector::Sector(unsigned int i, Settings const& settings, Globals* globals) : settings_(settings), globals_(globals) { - isector_ = i; +Sector::Sector(Settings const& settings, Globals* globals) : isector_(-1), settings_(settings), globals_(globals) {} + +Sector::~Sector() = default; + +void Sector::setSector(unsigned int isector) { + assert(isector < N_SECTOR); + isector_ = isector; double dphi = 2 * M_PI / N_SECTOR; double dphiHG = 0.5 * settings_.dphisectorHG() - M_PI / N_SECTOR; phimin_ = isector_ * dphi - dphiHG; @@ -51,75 +60,81 @@ Sector::Sector(unsigned int i, Settings const& settings, Globals* globals) : set phimax_ -= M_PI / N_SECTOR; phimin_ = reco::reduceRange(phimin_); phimax_ = reco::reduceRange(phimax_); - if (phimin_ > phimax_) + if (phimin_ > phimax_) { phimin_ -= 2 * M_PI; -} - -Sector::~Sector() { - for (auto& mem : MemoriesV_) { - mem->clean(); } } bool Sector::addStub(L1TStub stub, string dtc) { - bool add = false; + unsigned int layerdisk = stub.layerdisk(); - double phi = stub.phi(); - double dphi = 0.5 * settings_.dphisectorHG() - M_PI / N_SECTOR; + if (layerdisk < N_LAYER && globals_->phiCorr(layerdisk) == nullptr) { + globals_->phiCorr(layerdisk) = new VMRouterPhiCorrTable(settings_); - std::map >& ILindex = globals_->ILindex(); - std::vector& tmp = ILindex[dtc]; - if (tmp.empty()) { - for (unsigned int i = 0; i < IL_.size(); i++) { - if (IL_[i]->getName().find("_" + dtc) != string::npos) { - tmp.push_back(i); - } - } + int nbits = 3; + if (layerdisk >= N_PSLAYER) + nbits = 4; + globals_->phiCorr(layerdisk)->init(layerdisk + 1, nbits, 3); } - if (((phi > phimin_ - dphi) && (phi < phimax_ + dphi)) || - ((phi > 2 * M_PI + phimin_ - dphi) && (phi < 2 * M_PI + phimax_ + dphi))) { - Stub fpgastub(stub, settings_, phimin_, phimax_); - std::vector& tmp = ILindex[dtc]; - assert(!tmp.empty()); - for (int i : tmp) { - if (IL_[i]->addStub(settings_, globals_, stub, fpgastub, dtc)) - add = true; - } + Stub fpgastub(stub, settings_, *globals_); + + if (layerdisk < N_LAYER) { + FPGAWord r = fpgastub.r(); + int bendbin = fpgastub.bend().value(); + int rbin = (r.value() + (1 << (r.nbits() - 1))) >> (r.nbits() - 3); + const VMRouterPhiCorrTable& phiCorrTable = *globals_->phiCorr(layerdisk); + int iphicorr = phiCorrTable.getphiCorrValue(bendbin, rbin); + fpgastub.setPhiCorr(iphicorr); + } + + int nadd = 0; + for (unsigned int i = 0; i < DL_.size(); i++) { + const string& name = DL_[i]->getName(); + if (name.find("_" + dtc) == string::npos) + continue; + DL_[i]->addStub(stub, fpgastub); + nadd++; } - return add; + assert(nadd == 1); + + return true; } void Sector::addMem(string memType, string memName) { - if (memType == "InputLink:") { - addMemToVec(IL_, memName, settings_, isector_, phimin_, phimax_); + if (memType == "DTCLink:") { + addMemToVec(DL_, memName, settings_, phimin_, phimax_); + } else if (memType == "InputLink:") { + addMemToVec(IL_, memName, settings_, phimin_, phimax_); } else if (memType == "AllStubs:") { - addMemToVec(AS_, memName, settings_, isector_); + addMemToVec(AS_, memName, settings_); + } else if (memType == "AllInnerStubs:") { + addMemToVec(AIS_, memName, settings_); } else if (memType == "VMStubsTE:") { - addMemToVec(VMSTE_, memName, settings_, isector_); + addMemToVec(VMSTE_, memName, settings_); } else if (memType == "VMStubsME:") { - addMemToVec(VMSME_, memName, settings_, isector_); + addMemToVec(VMSME_, memName, settings_); } else if (memType == "StubPairs:" || memType == "StubPairsDisplaced:") { - addMemToVec(SP_, memName, settings_, isector_); + addMemToVec(SP_, memName, settings_); } else if (memType == "StubTriplets:") { - addMemToVec(ST_, memName, settings_, isector_); + addMemToVec(ST_, memName, settings_); } else if (memType == "TrackletParameters:") { - addMemToVec(TPAR_, memName, settings_, isector_); + addMemToVec(TPAR_, memName, settings_); } else if (memType == "TrackletProjections:") { - addMemToVec(TPROJ_, memName, settings_, isector_); + addMemToVec(TPROJ_, memName, settings_); } else if (memType == "AllProj:") { - addMemToVec(AP_, memName, settings_, isector_); + addMemToVec(AP_, memName, settings_); } else if (memType == "VMProjections:") { - addMemToVec(VMPROJ_, memName, settings_, isector_); + addMemToVec(VMPROJ_, memName, settings_); } else if (memType == "CandidateMatch:") { - addMemToVec(CM_, memName, settings_, isector_); + addMemToVec(CM_, memName, settings_); } else if (memType == "FullMatch:") { - addMemToVec(FM_, memName, settings_, isector_); + addMemToVec(FM_, memName, settings_); } else if (memType == "TrackFit:") { - addMemToVec(TF_, memName, settings_, isector_, phimin_, phimax_); + addMemToVec(TF_, memName, settings_, phimin_, phimax_); } else if (memType == "CleanTrack:") { - addMemToVec(CT_, memName, settings_, isector_, phimin_, phimax_); + addMemToVec(CT_, memName, settings_, phimin_, phimax_); } else { edm::LogPrint("Tracklet") << "Don't know of memory type: " << memType; exit(0); @@ -127,35 +142,37 @@ void Sector::addMem(string memType, string memName) { } void Sector::addProc(string procType, string procName) { - if (procType == "VMRouter:") { - addProcToVec(VMR_, procName, settings_, globals_, isector_); + 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_, isector_); + addProcToVec(VMRCM_, procName, settings_, globals_); } else if (procType == "TrackletEngine:") { - addProcToVec(TE_, procName, settings_, globals_, isector_); + addProcToVec(TE_, procName, settings_, globals_); } else if (procType == "TrackletEngineDisplaced:") { - addProcToVec(TED_, procName, settings_, globals_, isector_); + addProcToVec(TED_, procName, settings_, globals_); } else if (procType == "TripletEngine:") { - addProcToVec(TRE_, procName, settings_, globals_, isector_); + addProcToVec(TRE_, procName, settings_, globals_); } else if (procType == "TrackletCalculator:") { - addProcToVec(TC_, procName, settings_, globals_, isector_); + addProcToVec(TC_, procName, settings_, globals_); } else if (procType == "TrackletProcessor:") { - addProcToVec(TP_, procName, settings_, globals_, isector_); + addProcToVec(TP_, procName, settings_, globals_); } else if (procType == "TrackletCalculatorDisplaced:") { - addProcToVec(TCD_, procName, settings_, globals_, isector_); + addProcToVec(TCD_, procName, settings_, globals_); } else if (procType == "ProjectionRouter:") { - addProcToVec(PR_, procName, settings_, globals_, isector_); + addProcToVec(PR_, procName, settings_, globals_); } else if (procType == "MatchEngine:") { - addProcToVec(ME_, procName, settings_, globals_, isector_); + addProcToVec(ME_, procName, settings_, globals_); } else if (procType == "MatchCalculator:" || procType == "DiskMatchCalculator:") { //TODO should not be used in configurations - addProcToVec(MC_, procName, settings_, globals_, isector_); + addProcToVec(MC_, procName, settings_, globals_); } else if (procType == "MatchProcessor:") { - addProcToVec(MP_, procName, settings_, globals_, isector_); + addProcToVec(MP_, procName, settings_, globals_); } else if (procType == "FitTrack:") { - addProcToVec(FT_, procName, settings_, globals_, isector_); + addProcToVec(FT_, procName, settings_, globals_); } else if (procType == "PurgeDuplicate:") { - addProcToVec(PD_, procName, settings_, globals_, isector_); + addProcToVec(PD_, procName, settings_, globals_); } else { edm::LogPrint("Tracklet") << "Don't know of processing type: " << procType; exit(0); @@ -206,106 +223,114 @@ MemoryBase* Sector::getMem(string memName) { return nullptr; } -void Sector::writeInputStubs(bool first) { +void Sector::writeDTCStubs(bool first) { + for (auto& i : DL_) { + i->writeStubs(first, isector_); + } +} + +void Sector::writeIRStubs(bool first) { for (auto& i : IL_) { - i->writeStubs(first); + i->writeStubs(first, isector_); } } void Sector::writeVMSTE(bool first) { for (auto& i : VMSTE_) { - i->writeStubs(first); + i->writeStubs(first, isector_); } } void Sector::writeVMSME(bool first) { for (auto& i : VMSME_) { - i->writeStubs(first); + i->writeStubs(first, isector_); } } void Sector::writeAS(bool first) { for (auto& i : AS_) { - i->writeStubs(first); + i->writeStubs(first, isector_); + } +} + +void Sector::writeAIS(bool first) { + for (auto& i : AIS_) { + i->writeStubs(first, isector_); } } void Sector::writeSP(bool first) { for (auto& i : SP_) { - i->writeSP(first); + i->writeSP(first, isector_); } } void Sector::writeST(bool first) { for (auto& i : ST_) { - i->writeST(first); + i->writeST(first, isector_); } } void Sector::writeTPAR(bool first) { for (auto& i : TPAR_) { - i->writeTPAR(first); + i->writeTPAR(first, isector_); } } void Sector::writeTPROJ(bool first) { for (auto& i : TPROJ_) { - i->writeTPROJ(first); + i->writeTPROJ(first, isector_); } } void Sector::writeAP(bool first) { for (auto& i : AP_) { - i->writeAP(first); + i->writeAP(first, isector_); } } void Sector::writeVMPROJ(bool first) { for (auto& i : VMPROJ_) { - i->writeVMPROJ(first); + i->writeVMPROJ(first, isector_); } } void Sector::writeCM(bool first) { for (auto& i : CM_) { - i->writeCM(first); + i->writeCM(first, isector_); } } void Sector::writeMC(bool first) { for (auto& i : FM_) { - i->writeMC(first); + i->writeMC(first, isector_); } } void Sector::writeTF(bool first) { for (auto& i : TF_) { - i->writeTF(first); + i->writeTF(first, isector_); } } void Sector::writeCT(bool first) { for (auto& i : CT_) { - i->writeCT(first); + i->writeCT(first, isector_); } } void Sector::clean() { - if (settings_.writeMonitorData("NMatches")) { - int matchesL1 = 0; - int matchesL3 = 0; - int matchesL5 = 0; - for (auto& i : TPAR_) { - i->writeMatches(globals_, matchesL1, matchesL3, matchesL5); - } - globals_->ofstream("nmatchessector.txt") << matchesL1 << " " << matchesL3 << " " << matchesL5 << endl; - } - for (auto& mem : MemoriesV_) { mem->clean(); } } +void Sector::executeIR() { + for (auto& i : IR_) { + i->execute(); + } +} + void Sector::executeVMR() { if (settings_.writeMonitorData("IL")) { ofstream& out = globals_->ofstream("inputlink.txt"); @@ -341,13 +366,13 @@ void Sector::executeTRE() { void Sector::executeTP() { for (auto& i : TP_) { - i->execute(); + i->execute(isector_, phimin_, phimax_); } } void Sector::executeTC() { for (auto& i : TC_) { - i->execute(); + i->execute(isector_, phimin_, phimax_); } if (settings_.writeMonitorData("TrackProjOcc")) { @@ -360,7 +385,7 @@ void Sector::executeTC() { void Sector::executeTCD() { for (auto& i : TCD_) { - i->execute(); + i->execute(isector_, phimin_, phimax_); } } @@ -378,25 +403,25 @@ void Sector::executeME() { void Sector::executeMC() { for (auto& i : MC_) { - i->execute(); + i->execute(phimin_); } } void Sector::executeMP() { for (auto& i : MP_) { - i->execute(); + i->execute(isector_, phimin_); } } void Sector::executeFT() { for (auto& i : FT_) { - i->execute(); + i->execute(isector_); } } -void Sector::executePD(std::vector& tracks) { +void Sector::executePD(std::vector& tracks) { for (auto& i : PD_) { - i->execute(tracks); + i->execute(tracks, isector_); } } diff --git a/L1Trigger/TrackFindingTracklet/src/Stub.cc b/L1Trigger/TrackFindingTracklet/src/Stub.cc index 449b17fe79238..fe7595a7dd784 100644 --- a/L1Trigger/TrackFindingTracklet/src/Stub.cc +++ b/L1Trigger/TrackFindingTracklet/src/Stub.cc @@ -1,171 +1,110 @@ #include "L1Trigger/TrackFindingTracklet/interface/Stub.h" +#include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.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; Stub::Stub(Settings const& settings) : settings_(settings) {} -Stub::Stub(L1TStub& stub, Settings const& settings, double phiminsec, double phimaxsec) : settings_(settings) { - double r = stub.r(); - double z = stub.z(); - double sbend = stub.bend(); +Stub::Stub(L1TStub& stub, Settings const& settings, Globals& globals) : settings_(settings) { + const string& stubwordhex = stub.stubword(); - l1tstub_ = &stub; - - int bendbits = 4; - if (stub.isPSmodule()) - bendbits = 3; + const string stubwordbin = convertHexToBin(stubwordhex); - int ibend = bendencode(sbend, stub.isPSmodule()); + layerdisk_ = stub.layerdisk(); - bend_.set(ibend, bendbits, true, __LINE__, __FILE__); - - int layer = stub.layer() + 1; + int nbendbits = 4; + if (stub.isPSmodule()) + nbendbits = 3; - // hold the real values from L1Stub - double stubphi = stub.phi(); + int nalphabits = 0; - if (layer < 999) { - disk_.set(0, 4, false, __LINE__, __FILE__); + int nrbits = settings_.nrbitsstub(layerdisk_); + int nzbits = settings_.nzbitsstub(layerdisk_); + int nphibits = settings_.nphibitsstub(layerdisk_); - assert(layer > 0 && layer <= N_LAYER); - double rmin = settings_.rmean(layer - 1) - settings_.drmax(); - double rmax = settings_.rmean(layer - 1) + settings_.drmax(); + if (layerdisk_ >= N_LAYER && !stub.isPSmodule()) { + nalphabits = settings.nbitsalpha(); + nrbits = 7; + } - if (r < rmin || r > rmax) { - edm::LogProblem("Tracklet") << "Error r, rmin, rmeas, rmax :" << r << " " << rmin << " " << 0.5 * (rmin + rmax) - << " " << rmax; - } + int layer = stub.layer() + 1; - int irbits = settings_.nrbitsstub(layer - 1); + assert(nbendbits + nalphabits + nrbits + nzbits + nphibits == 36); - int ir = lround((1 << irbits) * ((r - settings_.rmean(layer - 1)) / (rmax - rmin))); + 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)); - double zmin = -settings_.zlength(); - double zmax = settings_.zlength(); + int newbend = bendbits.to_ulong(); - if (z < zmin || z > zmax) { - edm::LogProblem("Tracklet") << "Error z, zmin, zmax :" << z << " " << zmin << " " << zmax; - } + int newr = rbits.to_ulong(); + if (layerdisk_ < N_LAYER) { + if (newr >= (1 << (nrbits - 1))) + newr = newr - (1 << nrbits); + } - int izbits = settings_.nzbitsstub(layer - 1); + int newz = zbits.to_ulong(); + if (newz >= (1 << (nzbits - 1))) + newz = newz - (1 << nzbits); - int iz = lround((1 << izbits) * z / (zmax - zmin)); + int newphi = phibits.to_ulong(); - if (z < zmin || z > zmax) { - edm::LogProblem("Tracklet") << "Error z, zmin, zmax :" << z << " " << zmin << " " << zmax; - } + int newalpha = alphabits.to_ulong(); + if (newalpha >= (1 << (nalphabits - 1))) + newalpha = newalpha - (1 << nalphabits); - assert(phimaxsec - phiminsec > 0.0); + l1tstub_ = &stub; - if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) { - stubphi += 2 * M_PI; + bend_.set(newbend, nbendbits, true, __LINE__, __FILE__); + + phi_.set(newphi, nphibits, true, __LINE__, __FILE__); + phicorr_.set(newphi, nphibits, true, __LINE__, __FILE__); + bool pos = false; + if (layerdisk_ > 5) { + pos = true; + int disk = layerdisk_ - 5; + if (stub.z() < 0.0) + disk = -disk; + disk_.set(disk, 4, false, __LINE__, __FILE__); + if (!stub.isPSmodule()) { + alpha_.set(newalpha, nalphabits, false, __LINE__, __FILE__); + nrbits = 4; } - assert((phimaxsec - phiminsec) > 0.0); - - int iphibits = settings_.nphibitsstub(layer - 1); - - double deltaphi = reco::reduceRange(stubphi - phiminsec); - - int iphi = (1 << iphibits) * deltaphi / (phimaxsec - phiminsec); - - layer_.set(layer - 1, 3, true, __LINE__, __FILE__); - r_.set(ir, irbits, false, __LINE__, __FILE__); - z_.set(iz, izbits, false, __LINE__, __FILE__); - phi_.set(iphi, iphibits, true, __LINE__, __FILE__); - - phicorr_.set(iphi, iphibits, true, __LINE__, __FILE__); - } else { - // Here we handle the hits on disks. - - int disk = stub.module(); - assert(disk > 0 && disk <= N_DISK); - int sign = 1; - if (z < 0.0) - sign = -1; - - double zmin = sign * (settings_.zmean(disk - 1) - sign * settings_.dzmax()); - double zmax = sign * (settings_.zmean(disk - 1) + sign * settings_.dzmax()); - - if ((z > zmax) || (z < zmin)) { - edm::LogProblem("Tracklet") << "Error disk z, zmax, zmin: " << z << " " << zmax << " " << zmin; - } - - int iz = - (1 << settings.nzbitsstub(disk + N_DISK)) * ((z - sign * settings_.zmean(disk - 1)) / std::abs(zmax - zmin)); - - assert(phimaxsec - phiminsec > 0.0); - if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) { - stubphi += 2 * M_PI; - } - - assert(phimaxsec - phiminsec > 0.0); - if (stubphi < phiminsec - (phimaxsec - phiminsec) / 6.0) { - stubphi += 2 * M_PI; - } - - int iphibits = settings_.nphibitsstub(disk + 5); - - double deltaphi = reco::reduceRange(stubphi - phiminsec); - - int iphi = (1 << iphibits) * deltaphi / (phimaxsec - phiminsec); - - double rmin = 0; - double rmax = settings_.rmaxdisk(); - - if (r < rmin || r > rmax) { - edm::LogProblem("Tracklet") << "Error disk r, rmin, rmax :" << r << " " << rmin << " " << rmax; - } - - int ir = (1 << settings_.nrbitsstub(disk + 5)) * (r - rmin) / (rmax - rmin); - - int irSS = -1; - if (!stub.isPSmodule()) { - for (unsigned int i = 0; i < N_DSS_MOD * 2; ++i) { - if (disk <= 2) { - if (std::abs(r - settings_.rDSSinner(i)) < 0.2) { - irSS = i; - break; - } - } else { - if (std::abs(r - settings_.rDSSouter(i)) < 0.2) { - irSS = i; - break; - } - } - } - if (irSS < 0) { - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " didn't find rDSS value! r = " << r - << " Check that correct geometry is used!"; + disk_.set(0, 4, false, __LINE__, __FILE__); + layer_.set(layer - 1, 3, true, __LINE__, __FILE__); + } + r_.set(newr, nrbits, pos, __LINE__, __FILE__); + z_.set(newz, nzbits, false, __LINE__, __FILE__); + + if (settings.writeMonitorData("StubBend")) { + unsigned int nsimtrks = globals.event()->nsimtracks(); + + for (unsigned int isimtrk = 0; isimtrk < nsimtrks; isimtrk++) { + const L1SimTrack& simtrk = globals.event()->simtrack(isimtrk); + if (stub.tpmatch2(simtrk.trackid())) { + double dr = 0.18; + double rinv = simtrk.charge() * 0.01 * settings_.c() * settings_.bfield() / simtrk.pt(); + double pitch = settings_.stripPitch(stub.isPSmodule()); + double bend = stub.r() * dr * 0.5 * rinv / pitch; + + globals.ofstream("stubbend.dat") << layerdisk_ << " " << stub.isPSmodule() << " " + << simtrk.pt() * simtrk.charge() << " " << bend << " " << newbend << " " + << settings.benddecode(newbend, layerdisk_, stub.isPSmodule()) << " " + << settings.bendcut(newbend, layerdisk_, stub.isPSmodule()) << endl; } } - if (irSS < 0) { - //PS modules - r_.set(ir, settings_.nrbitsstub(disk + N_DISK), true, __LINE__, __FILE__); - } else { - //SS modules - r_.set(irSS, 4, true, __LINE__, __FILE__); // in case of SS modules, store index, not r itself - } - - z_.set(iz, settings.nzbitsstub(disk + 5), false, __LINE__, __FILE__); - phi_.set(iphi, iphibits, true, __LINE__, __FILE__); - phicorr_.set(iphi, iphibits, true, __LINE__, __FILE__); - - disk_.set(sign * disk, 4, false, __LINE__, __FILE__); - - double alphanorm = stub.alphanorm(); - assert(std::abs(alphanorm) < 1.0); - int ialphanew = alphanorm * (1 << (settings.nbitsalpha() - 1)); - assert(ialphanew < (1 << (settings.nbitsalpha() - 1))); - assert(ialphanew >= -(1 << (settings.nbitsalpha() - 1))); - alphanew_.set(ialphanew, settings.nbitsalpha(), false, __LINE__, __FILE__); } } diff --git a/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc b/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc index 4e882c62789c8..40d81f17e3147 100644 --- a/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/StubPairsMemory.cc @@ -6,31 +6,17 @@ using namespace std; using namespace trklet; -StubPairsMemory::StubPairsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) {} +StubPairsMemory::StubPairsMemory(string name, Settings const& settings) : MemoryBase(name, settings) {} -void StubPairsMemory::writeSP(bool first) { +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(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirSP)) { - int fail = system((string("mkdir -p ") + dirSP).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirSP; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirSP, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc b/L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc index cd6f8dcbb1cf1..73a63404b83c5 100644 --- a/L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/StubTripletsMemory.cc @@ -7,31 +7,17 @@ using namespace std; using namespace trklet; -StubTripletsMemory::StubTripletsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) {} +StubTripletsMemory::StubTripletsMemory(string name, Settings const& settings) : MemoryBase(name, settings) {} -void StubTripletsMemory::writeST(bool first) { +void StubTripletsMemory::writeST(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirSP = settings_.memPath() + "StubPairs/"; std::ostringstream oss; oss << dirSP << "StubTriplets_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirSP)) { - int fail = system((string("mkdir -p ") + dirSP).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirSP; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirSP, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/TETableBase.cc b/L1Trigger/TrackFindingTracklet/src/TETableBase.cc index 6ece1f83d3b35..6e701edf0ee15 100644 --- a/L1Trigger/TrackFindingTracklet/src/TETableBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/TETableBase.cc @@ -1,16 +1,15 @@ #include "L1Trigger/TrackFindingTracklet/interface/TETableBase.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" using namespace std; using namespace trklet; TETableBase::TETableBase(Settings const& settings) : settings_(settings) {} -void TETableBase::writeVMTable(std::string name, bool positive) { +void TETableBase::writeVMTable(const std::string& dir, const std::string& name, bool positive) { // Write LUT table. - ofstream out(name); - if (out.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << name; + ofstream out = openfile(dir, name, __FILE__, __LINE__); out << "{" << endl; for (unsigned int i = 0; i < table_.size(); i++) { diff --git a/L1Trigger/TrackFindingTracklet/src/Track.cc b/L1Trigger/TrackFindingTracklet/src/Track.cc index 58e1469936aae..61cb8d1521704 100644 --- a/L1Trigger/TrackFindingTracklet/src/Track.cc +++ b/L1Trigger/TrackFindingTracklet/src/Track.cc @@ -14,7 +14,7 @@ Track::Track(TrackPars ipars, double chisqrz, int hitpattern, std::map stubID, - const std::vector& l1stub, + const std::vector& l1stub, int seed) { ipars_ = ipars; ichisqrphi_ = ichisqrphi; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc b/L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc index 03cac8804cbd3..3b39c761a80e7 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackDerTable.cc @@ -1,11 +1,10 @@ #include "L1Trigger/TrackFindingTracklet/interface/TrackDerTable.h" #include "L1Trigger/TrackFindingTracklet/interface/FPGAWord.h" #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" -#include - using namespace std; using namespace trklet; @@ -359,17 +358,7 @@ void TrackDerTable::fillTable() { } if (settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - const string fnameL = settings_.tablePath() + "FitDerTableNew_LayerMem.tab"; - ofstream outL(fnameL); - if (outL.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fnameL; + ofstream outL = openfile(settings_.tablePath(), "FitDerTableNew_LayerMem.tab", __FILE__, __LINE__); int nbits = 6; for (unsigned int i = 0; i < LayerMem_.size(); i++) { @@ -382,10 +371,7 @@ void TrackDerTable::fillTable() { } outL.close(); - const string fnameD = settings_.tablePath() + "FitDerTableNew_DiskMem.tab"; - ofstream outD(fnameD); - if (outD.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fnameD; + ofstream outD = openfile(settings_.tablePath(), "FitDerTableNew_DiskMem.tab", __FILE__, __LINE__); nbits = 7; for (int tmp1 : DiskMem_) { @@ -397,10 +383,7 @@ void TrackDerTable::fillTable() { } outD.close(); - const string fnameLD = settings_.tablePath() + "FitDerTableNew_LayerDiskMem.tab"; - ofstream outLD(fnameLD); - if (outLD.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fnameLD; + ofstream outLD = openfile(settings_.tablePath(), "FitDerTableNew_LayerDiskMem.tab", __FILE__, __LINE__); nbits = 15; for (int tmp1 : LayerDiskMem_) { diff --git a/L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc index 63505b224f8a1..55e95adadf29d 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackFitMemory.cc @@ -7,34 +7,21 @@ using namespace std; using namespace trklet; -TrackFitMemory::TrackFitMemory(string name, Settings const& settings, unsigned int iSector, double phimin, double phimax) - : MemoryBase(name, settings, iSector) { +TrackFitMemory::TrackFitMemory(string name, Settings const& settings, double phimin, double phimax) + : MemoryBase(name, settings) { phimin_ = phimin; phimax_ = phimax; } -void TrackFitMemory::writeTF(bool first) { +void TrackFitMemory::writeTF(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirFT = settings_.memPath() + "FitTrack/"; std::ostringstream oss; oss << dirFT << "TrackFit_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirFT)) { - int fail = system((string("mkdir -p ") + dirFT).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirFT; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirFT, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc index a116a646fb23c..bc7ba9f5d1f1a 100644 --- a/L1Trigger/TrackFindingTracklet/src/Tracklet.cc +++ b/L1Trigger/TrackFindingTracklet/src/Tracklet.cc @@ -14,9 +14,7 @@ using namespace std; using namespace trklet; Tracklet::Tracklet(Settings const& settings, - const L1TStub* innerStub, - const L1TStub* middleStub, - const L1TStub* outerStub, + unsigned int iSeed, const Stub* innerFPGAStub, const Stub* middleFPGAStub, const Stub* outerFPGAStub, @@ -35,11 +33,12 @@ Tracklet::Tracklet(Settings const& settings, int id0, int iz0, int it, - LayerProjection layerprojs[N_PROJ], - DiskProjection diskprojs[N_PROJ], + Projection projs[N_LAYER + N_DISK], bool disk, bool overlap) : settings_(settings) { + seedIndex_ = iSeed; + overlap_ = overlap; disk_ = disk; assert(!(disk && overlap)); @@ -51,12 +50,9 @@ Tracklet::Tracklet(Settings const& settings, assert(disk_ || barrel_ || overlap_); - if (barrel_ && middleStub == nullptr) - assert(innerStub->layer() < N_LAYER); + if (barrel_ && middleFPGAStub == nullptr) + assert(innerFPGAStub->l1tstub()->layer() < N_LAYER); - innerStub_ = innerStub; - middleStub_ = middleStub; - outerStub_ = outerStub; innerFPGAStub_ = innerFPGAStub; middleFPGAStub_ = middleFPGAStub; outerFPGAStub_ = outerFPGAStub; @@ -73,15 +69,6 @@ Tracklet::Tracklet(Settings const& settings, fpgatrack_ = nullptr; - if (innerStub_) - assert(innerStub_->layer() < N_LAYER || innerStub_->disk() < N_DISK); - if (middleStub_) - assert(middleStub_->layer() < N_LAYER || middleStub_->disk() < N_DISK); - if (outerStub_) - assert(outerStub_->layer() < N_LAYER || outerStub_->disk() < N_DISK); - - seedIndex_ = calcSeedIndex(); - triplet_ = (seedIndex_ >= 8); //fill projection layers @@ -98,19 +85,19 @@ Tracklet::Tracklet(Settings const& settings, for (unsigned int i = 0; i < N_LAYER - 2; i++) { if (projlayer_[i] == 0) continue; - if (!layerprojs[i].valid()) + if (!projs[projlayer_[i] - 1].valid()) continue; - layerproj_[projlayer_[i] - 1] = layerprojs[i]; + proj_[projlayer_[i] - 1] = projs[projlayer_[i] - 1]; } //Now handle projections to the disks for (unsigned int i = 0; i < N_DISK; i++) { if (projdisk_[i] == 0) continue; - if (!diskprojs[i].valid()) + if (!projs[N_LAYER + projdisk_[i] - 1].valid()) continue; - diskproj_[projdisk_[i] - 1] = diskprojs[i]; + proj_[N_LAYER + projdisk_[i] - 1] = projs[N_LAYER + projdisk_[i] - 1]; } ichisqrphifit_.set(-1, 8, false); @@ -123,7 +110,7 @@ int Tracklet::tpseed() { set tpsetstubinner; set tpsetstubouter; - vector tps = innerStub_->tps(); + vector tps = innerFPGAStub_->l1tstub()->tps(); for (auto tp : tps) { if (tp != 0) { tpsetstubinner.insert(tp); @@ -131,7 +118,7 @@ int Tracklet::tpseed() { } } - tps = outerStub_->tps(); + tps = outerFPGAStub_->l1tstub()->tps(); for (auto tp : tps) { if (tp != 0) { tpsetstubouter.insert(tp); @@ -161,14 +148,14 @@ bool Tracklet::stubtruthmatch(const L1TStub* stub) { tpset.insert(abs(tp)); } } - tps = innerStub_->tps(); + tps = innerFPGAStub_->l1tstub()->tps(); for (auto tp : tps) { if (tp != 0) { tpsetstubinner.insert(tp); tpset.insert(abs(tp)); } } - tps = outerStub_->tps(); + tps = outerFPGAStub_->l1tstub()->tps(); for (auto tp : tps) { if (tp != 0) { tpsetstubouter.insert(tp); @@ -232,8 +219,8 @@ std::string Tracklet::vmstrlayer(int layer, unsigned int allstubindex) { //int irinvvm=16+(fpgarinv().value()>>(fpgarinv().nbits()-5)); // rinv is not directly available in the TrackletProjection. // can be inferred from phi derivative: rinv = - phider * 2 - int tmp_irinv = layerproj_[layer - 1].fpgaphiprojder().value() * (-2); - int nbits_irinv = layerproj_[layer - 1].fpgaphiprojder().nbits() + 1; + int tmp_irinv = proj_[layer - 1].fpgaphiprojder().value() * (-2); + int nbits_irinv = proj_[layer - 1].fpgaphiprojder().nbits() + 1; // irinv in VMProjection: // top 5 bits of rinv and shifted to be positive @@ -248,9 +235,9 @@ std::string Tracklet::vmstrlayer(int layer, unsigned int allstubindex) { assert(irinvvm < 32); FPGAWord tmp; tmp.set(irinvvm, 5, true, __LINE__, __FILE__); - std::string oss = index.str() + "|" + layerproj_[layer - 1].fpgazbin1projvm().str() + "|" + - layerproj_[layer - 1].fpgazbin2projvm().str() + "|" + layerproj_[layer - 1].fpgafinezvm().str() + - "|" + tmp.str() + "|" + std::to_string(PSseed()); + std::string oss = index.str() + "|" + proj_[layer - 1].fpgarzbin1projvm().str() + "|" + + proj_[layer - 1].fpgarzbin2projvm().str() + "|" + proj_[layer - 1].fpgafinerzvm().str() + "|" + + proj_[layer - 1].fpgafinephivm().str() + "|" + tmp.str() + "|" + std::to_string(PSseed()); return oss; } @@ -262,9 +249,10 @@ std::string Tracklet::vmstrdisk(int disk, unsigned int allstubindex) { } else { index.set(allstubindex, 7, true, __LINE__, __FILE__); } - std::string oss = index.str() + "|" + diskproj_[disk - 1].fpgarbin1projvm().str() + "|" + - diskproj_[disk - 1].fpgarbin2projvm().str() + "|" + diskproj_[disk - 1].fpgafinervm().str() + "|" + - diskproj_[disk - 1].getBendIndex().str(); + std::string oss = + index.str() + "|" + proj_[N_LAYER + disk - 1].fpgarzbin1projvm().str() + "|" + + proj_[N_LAYER + disk - 1].fpgarzbin2projvm().str() + "|" + proj_[N_LAYER + disk - 1].fpgafinerzvm().str() + "|" + + proj_[N_LAYER + disk - 1].fpgafinephivm().str() + "|" + proj_[N_LAYER + disk - 1].getBendIndex().str(); return oss; } @@ -278,9 +266,9 @@ std::string Tracklet::trackletprojstr(int layer) const { FPGAWord tcid; tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); - std::string oss = tcid.str() + "|" + tmp.str() + "|" + layerproj_[layer - 1].fpgaphiproj().str() + "|" + - layerproj_[layer - 1].fpgazproj().str() + "|" + layerproj_[layer - 1].fpgaphiprojder().str() + "|" + - layerproj_[layer - 1].fpgazprojder().str(); + std::string oss = tcid.str() + "|" + tmp.str() + "|" + proj_[layer - 1].fpgaphiproj().str() + "|" + + proj_[layer - 1].fpgarzproj().str() + "|" + proj_[layer - 1].fpgaphiprojder().str() + "|" + + proj_[layer - 1].fpgarzprojder().str(); return oss; } @@ -292,76 +280,29 @@ std::string Tracklet::trackletprojstrD(int disk) const { } tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; - tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); - std::string oss = tcid.str() + "|" + tmp.str() + "|" + diskproj_[abs(disk) - 1].fpgaphiproj().str() + "|" + - diskproj_[abs(disk) - 1].fpgarproj().str() + "|" + diskproj_[abs(disk) - 1].fpgaphiprojder().str() + - "|" + diskproj_[abs(disk) - 1].fpgarprojder().str(); + if (settings_.extended()) { + tcid.set(TCIndex_, 8, true, __LINE__, __FILE__); + } else { + tcid.set(TCIndex_, 7, true, __LINE__, __FILE__); + } + std::string oss = tcid.str() + "|" + tmp.str() + "|" + proj_[N_LAYER + abs(disk) - 1].fpgaphiproj().str() + "|" + + proj_[N_LAYER + abs(disk) - 1].fpgarzproj().str() + "|" + + proj_[N_LAYER + abs(disk) - 1].fpgaphiprojder().str() + "|" + + proj_[N_LAYER + abs(disk) - 1].fpgarzprojder().str(); return oss; } -void Tracklet::addMatch(int layer, +void Tracklet::addMatch(unsigned int layerdisk, int ideltaphi, - int ideltaz, + int ideltarz, double dphi, - double dz, + double drz, double dphiapprox, - double dzapprox, + double drzapprox, int stubid, - double rstub, const trklet::Stub* stubptr) { - assert(layer > 0 && layer <= N_LAYER); - layerresid_[layer - 1].init( - settings_, layer, ideltaphi, ideltaz, stubid, dphi, dz, dphiapprox, dzapprox, rstub, stubptr); -} - -void Tracklet::addMatchDisk(int disk, - int ideltaphi, - int ideltar, - double dphi, - double dr, - double dphiapprox, - double drapprox, - double alpha, - int stubid, - double zstub, - const trklet::Stub* stubptr) { - assert(abs(disk) <= N_DISK); - diskresid_[abs(disk) - 1].init(settings_, - disk, - ideltaphi, - ideltar, - stubid, - dphi, - dr, - dphiapprox, - drapprox, - zstub, - alpha, - stubptr->alphanew(), - stubptr); -} - -int Tracklet::nMatches() { - int nmatches = 0; - - for (const auto& ilayerresid : layerresid_) { - if (ilayerresid.valid()) { - nmatches++; - } - } - - return nmatches; -} - -int Tracklet::nMatchesDisk() { - int nmatches = 0; - - for (const auto& idiskresid : diskresid_) { - if (idiskresid.valid()) { - nmatches++; - } - } - return nmatches; + assert(layerdisk < N_LAYER + N_DISK); + resid_[layerdisk].init(settings_, layerdisk, ideltaphi, ideltarz, stubid, dphi, drz, dphiapprox, drzapprox, stubptr); } std::string Tracklet::fullmatchstr(int layer) { @@ -374,9 +315,9 @@ std::string Tracklet::fullmatchstr(int layer) { tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); - std::string oss = tcid.str() + "|" + tmp.str() + "|" + layerresid_[layer - 1].fpgastubid().str() + "|" + - layerresid_[layer - 1].stubptr()->r().str() + "|" + layerresid_[layer - 1].fpgaphiresid().str() + - "|" + layerresid_[layer - 1].fpgazresid().str(); + std::string oss = tcid.str() + "|" + tmp.str() + "|" + resid_[layer - 1].fpgastubid().str() + "|" + + resid_[layer - 1].stubptr()->r().str() + "|" + resid_[layer - 1].fpgaphiresid().str() + "|" + + resid_[layer - 1].fpgarzresid().str(); return oss; } @@ -390,32 +331,28 @@ std::string Tracklet::fullmatchdiskstr(int disk) { tmp.set(trackletIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); FPGAWord tcid; tcid.set(TCIndex_, settings_.nbitstcindex(), true, __LINE__, __FILE__); - const FPGAWord& stubr = diskresid_[disk - 1].stubptr()->r(); - const bool isPS = diskresid_[disk - 1].stubptr()->isPSmodule(); - std::string oss = tcid.str() + "|" + tmp.str() + "|" + diskresid_[disk - 1].fpgastubid().str() + "|" + + 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())) + "|" + - diskresid_[disk - 1].fpgaphiresid().str() + "|" + diskresid_[disk - 1].fpgarresid().str(); + resid_[N_LAYER + disk - 1].fpgaphiresid().str() + "|" + + resid_[N_LAYER + disk - 1].fpgarzresid().str(); return oss; } std::vector Tracklet::getL1Stubs() { std::vector tmp; - if (innerStub_) - tmp.push_back(innerStub_); - if (middleStub_) - tmp.push_back(middleStub_); - if (outerStub_) - tmp.push_back(outerStub_); - - for (const auto& ilayerresid : layerresid_) { - if (ilayerresid.valid()) - tmp.push_back(ilayerresid.stubptr()->l1tstub()); - } + if (innerFPGAStub_) + tmp.push_back(innerFPGAStub_->l1tstub()); + if (middleFPGAStub_) + tmp.push_back(middleFPGAStub_->l1tstub()); + if (outerFPGAStub_) + tmp.push_back(outerFPGAStub_->l1tstub()); - for (const auto& idiskresid : diskresid_) { - if (idiskresid.valid()) - tmp.push_back(idiskresid.stubptr()->l1tstub()); + for (const auto& iresid : resid_) { + if (iresid.valid()) + tmp.push_back(iresid.stubptr()->l1tstub()); } return tmp; @@ -429,37 +366,37 @@ std::map Tracklet::getStubIDs() { // E.g. An L3L4 track has 0=L1, 1=L2, 2=L4, 3=L5 for the barrels (for proj*_[i]) if (innerFPGAStub_) - assert(innerFPGAStub_->stubindex().nbits() == 7); + assert(innerFPGAStub_->stubindex().nbits() == N_BITSMEMADDRESS); if (middleFPGAStub_) - assert(middleFPGAStub_->stubindex().nbits() == 7); + assert(middleFPGAStub_->stubindex().nbits() == N_BITSMEMADDRESS); if (outerFPGAStub_) - assert(outerFPGAStub_->stubindex().nbits() == 7); + assert(outerFPGAStub_->stubindex().nbits() == N_BITSMEMADDRESS); if (barrel_) { for (int i = 0; i < N_LAYER; i++) { //check barrel - if (layerresid_[i].valid()) { + if (resid_[i].valid()) { // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= layerresid_[i].fpgastubid().nbits(); + location <<= resid_[i].fpgastubid().nbits(); - stubIDs[1 + i] = layerresid_[i].fpgastubid().value() + location; + stubIDs[1 + i] = resid_[i].fpgastubid().value() + location; } //check disk if (i >= N_DISK) continue; //i=[0..4] for disks - if (diskresid_[i].valid()) { - if (i == 3 && layerresid_[0].valid() && innerFPGAStub_->layer().value() == 1) + if (resid_[N_LAYER + i].valid()) { + if (i == 3 && resid_[0].valid() && innerFPGAStub_->layer().value() == 1) continue; // Don't add D4 if track has L1 stub // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= diskresid_[i].fpgastubid().nbits(); + location <<= resid_[N_LAYER + i].fpgastubid().nbits(); if (itfit().value() < 0) { - stubIDs[-11 - i] = diskresid_[i].fpgastubid().value() + location; + stubIDs[-(N_LAYER + N_DISK) - i] = resid_[N_LAYER + i].fpgastubid().value() + location; } else { - stubIDs[11 + i] = diskresid_[i].fpgastubid().value() + location; + stubIDs[N_LAYER + N_DISK + i] = resid_[N_LAYER + i].fpgastubid().value() + location; } } } @@ -475,26 +412,26 @@ std::map Tracklet::getStubIDs() { } else if (disk_) { for (int i = 0; i < N_DISK; i++) { //check barrel - if (layerresid_[i].valid()) { + if (resid_[i].valid()) { // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= layerresid_[i].fpgastubid().nbits(); + location <<= resid_[i].fpgastubid().nbits(); - stubIDs[1 + i] = layerresid_[i].fpgastubid().value() + location; + stubIDs[1 + i] = resid_[i].fpgastubid().value() + location; } //check disks - if (i == 4 && layerresid_[1].valid()) + if (i == 4 && resid_[1].valid()) continue; // Don't add D5 if track has L2 stub - if (diskresid_[i].valid()) { + if (resid_[N_LAYER + i].valid()) { // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= diskresid_[i].fpgastubid().nbits(); + location <<= resid_[N_LAYER + i].fpgastubid().nbits(); - if (innerStub_->disk() < 0) { - stubIDs[-11 - i] = diskresid_[i].fpgastubid().value() + location; + if (innerFPGAStub_->l1tstub()->disk() < 0) { + stubIDs[-11 - i] = resid_[N_LAYER + i].fpgastubid().value() + location; } else { - stubIDs[11 + i] = diskresid_[i].fpgastubid().value() + location; + stubIDs[11 + i] = resid_[N_LAYER + i].fpgastubid().value() + location; } } } @@ -519,28 +456,28 @@ std::map Tracklet::getStubIDs() { } else if (overlap_) { for (int i = 0; i < N_DISK; i++) { //check barrel - if (layerresid_[i].valid()) { + if (resid_[i].valid()) { // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= layerresid_[i].fpgastubid().nbits(); + location <<= resid_[i].fpgastubid().nbits(); - stubIDs[1 + i] = layerresid_[i].fpgastubid().value() + location; + stubIDs[1 + i] = resid_[i].fpgastubid().value() + location; } //check disks - if (diskresid_[i].valid()) { + if (resid_[N_LAYER + i].valid()) { // two extra bits to indicate if the matched stub is local or from neighbor int location = 1; // local - location <<= diskresid_[i].fpgastubid().nbits(); + location <<= resid_[N_LAYER + i].fpgastubid().nbits(); - if (innerStub_->disk() < 0) { // if negative overlap - if (innerFPGAStub_->layer().value() != 2 || !layerresid_[0].valid() || + if (innerFPGAStub_->l1tstub()->disk() < 0) { // if negative overlap + if (innerFPGAStub_->layer().value() != 2 || !resid_[0].valid() || i != 3) { // Don't add D4 if this is an L3L2 track with an L1 stub - stubIDs[-11 - i] = diskresid_[i].fpgastubid().value() + location; + stubIDs[-11 - i] = resid_[N_LAYER + i].fpgastubid().value() + location; } } else { - if (innerFPGAStub_->layer().value() != 2 || !layerresid_[0].valid() || i != 3) { - stubIDs[11 + i] = diskresid_[i].fpgastubid().value() + location; + if (innerFPGAStub_->layer().value() != 2 || !resid_[0].valid() || i != 3) { + stubIDs[11 + i] = resid_[N_LAYER + i].fpgastubid().value() + location; } } } @@ -636,7 +573,7 @@ const std::string Tracklet::layerstubstr(const unsigned layer) const { assert(layer < N_LAYER); std::stringstream oss(""); - if (!layerresid_[layer].valid()) + if (!resid_[layer].valid()) oss << "0|0000000|0000000000|0000000|000000000000|000000000"; else { if (trackIndex_ < 0 || trackIndex_ > (int)settings_.ntrackletmax()) { @@ -646,10 +583,10 @@ const std::string Tracklet::layerstubstr(const unsigned layer) const { const FPGAWord tmp(trackIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); oss << "1|"; // valid bit oss << tmp.str() << "|"; - oss << layerresid_[layer].fpgastubid().str() << "|"; - oss << layerresid_[layer].stubptr()->r().str() << "|"; - oss << layerresid_[layer].fpgaphiresid().str() << "|"; - oss << layerresid_[layer].fpgazresid().str(); + oss << resid_[layer].fpgastubid().str() << "|"; + oss << resid_[layer].stubptr()->r().str() << "|"; + oss << resid_[layer].fpgaphiresid().str() << "|"; + oss << resid_[layer].fpgarzresid().str(); } return oss.str(); @@ -659,7 +596,7 @@ const std::string Tracklet::diskstubstr(const unsigned disk) const { assert(disk < N_DISK); std::stringstream oss(""); - if (!diskresid_[disk].valid()) + if (!resid_[N_LAYER + disk].valid()) oss << "0|0000000|0000000000|000000000000|000000000000|0000000"; else { if (trackIndex_ < 0 || trackIndex_ > (int)settings_.ntrackletmax()) { @@ -667,14 +604,14 @@ const std::string Tracklet::diskstubstr(const unsigned disk) const { assert(0); } const FPGAWord tmp(trackIndex_, settings_.nbitstrackletindex(), true, __LINE__, __FILE__); - const FPGAWord& stubr = diskresid_[disk].stubptr()->r(); - const bool isPS = diskresid_[disk].stubptr()->isPSmodule(); + const FPGAWord& stubr = resid_[N_LAYER + disk].stubptr()->r(); + const bool isPS = resid_[N_LAYER + disk].stubptr()->isPSmodule(); oss << "1|"; // valid bit oss << tmp.str() << "|"; - oss << diskresid_[disk].fpgastubid().str() << "|"; + oss << resid_[N_LAYER + disk].fpgastubid().str() << "|"; oss << (isPS ? stubr.str() : ("00000000" + stubr.str())) << "|"; - oss << diskresid_[disk].fpgaphiresid().str() << "|"; - oss << diskresid_[disk].fpgarresid().str(); + oss << resid_[N_LAYER + disk].fpgaphiresid().str() << "|"; + oss << resid_[N_LAYER + disk].fpgarzresid().str(); } return oss.str(); @@ -807,31 +744,42 @@ Track Tracklet::makeTrack(const vector& l1stubs) { fpgafitpars_.t().value(), fpgafitpars_.z0().value()); - Track tmpTrack( - ipars, - ichisqrphifit_.value(), - ichisqrzfit_.value(), - chisqrphifit_, - chisqrzfit_, - hitpattern_, - getStubIDs(), - (l1stubs.empty()) ? getL1Stubs() : l1stubs, // If fitter produced no stub list, take it from original tracklet. - getISeed()); + // If fitter produced no stub list, take it from original tracklet. + vector tmp = l1stubs.empty() ? getL1Stubs() : l1stubs; + + vector tmp2; + + for (auto stub : tmp) { + tmp2.push_back(*stub); + } + + Track tmpTrack(ipars, + ichisqrphifit_.value(), + ichisqrzfit_.value(), + chisqrphifit_, + chisqrzfit_, + hitpattern_, + getStubIDs(), + tmp2, + getISeed()); return tmpTrack; } int Tracklet::layer() const { - int l1 = (innerFPGAStub_ && innerFPGAStub_->isBarrel()) ? innerStub_->layer() + 1 : 999, - l2 = (middleFPGAStub_ && middleFPGAStub_->isBarrel()) ? middleStub_->layer() + 1 : 999, - l3 = (outerFPGAStub_ && outerFPGAStub_->isBarrel()) ? outerStub_->layer() + 1 : 999, l = min(min(l1, l2), l3); + int l1 = (innerFPGAStub_ && innerFPGAStub_->layerdisk() < N_LAYER) ? innerFPGAStub_->l1tstub()->layerdisk() + 1 : 999, + l2 = (middleFPGAStub_ && middleFPGAStub_->layerdisk() < N_LAYER) ? middleFPGAStub_->l1tstub()->layerdisk() + 1 + : 999, + l3 = (outerFPGAStub_ && outerFPGAStub_->layerdisk() < N_LAYER) ? outerFPGAStub_->l1tstub()->layerdisk() + 1 : 999, + l = min(min(l1, l2), l3); return (l < 999 ? l : 0); } int Tracklet::disk() const { - int d1 = (innerFPGAStub_ && innerFPGAStub_->isDisk()) ? innerStub_->disk() : 999, - d2 = (middleFPGAStub_ && middleFPGAStub_->isDisk()) ? middleStub_->disk() : 999, - d3 = (outerFPGAStub_ && outerFPGAStub_->isDisk()) ? outerStub_->disk() : 999, d = 999; + int d1 = (innerFPGAStub_ && (innerFPGAStub_->layerdisk() >= N_LAYER)) ? innerFPGAStub_->l1tstub()->disk() : 999, + d2 = (middleFPGAStub_ && (middleFPGAStub_->layerdisk() >= N_LAYER)) ? middleFPGAStub_->l1tstub()->disk() : 999, + d3 = (outerFPGAStub_ && (outerFPGAStub_->layerdisk() >= N_LAYER)) ? outerFPGAStub_->l1tstub()->disk() : 999, + d = 999; if (abs(d1) < min(abs(d2), abs(d3))) d = d1; if (abs(d2) < min(abs(d1), abs(d3))) @@ -841,25 +789,18 @@ int Tracklet::disk() const { return (d < 999 ? d : 0); } -int Tracklet::disk2() const { - if (innerStub_->disk() > 0) { - return innerStub_->disk() + 1; - } - return innerStub_->disk() - 1; -} - void Tracklet::setTrackletIndex(unsigned int index) { trackletIndex_ = index; assert(index <= settings_.ntrackletmax()); } -const int Tracklet::getISeed() const { +int Tracklet::getISeed() const { const int iSeed = TCIndex_ >> settings_.nbitsitc(); assert(iSeed >= 0 && iSeed <= (int)N_SEED); return iSeed; } -const int Tracklet::getITC() const { +int Tracklet::getITC() const { const int iSeed = getISeed(), iTC = TCIndex_ - (iSeed << settings_.nbitsitc()); assert(iTC >= 0 && iTC <= 14); return iTC; @@ -870,50 +811,4 @@ void Tracklet::setTrackIndex(int index) { assert(index <= (int)settings_.ntrackletmax()); } -const int Tracklet::trackIndex() const { return trackIndex_; } - -unsigned int Tracklet::calcSeedIndex() const { - int seedindex = -1; - int seedlayer = layer(); - int seeddisk = disk(); - - if (seedlayer == 1 && seeddisk == 0) - seedindex = 0; //L1L2 - if (seedlayer == 3 && seeddisk == 0) - seedindex = 2; //L3L4 - if (seedlayer == 5 && seeddisk == 0) - seedindex = 3; //L5L6 - if (seedlayer == 0 && abs(seeddisk) == 1) - seedindex = 4; //D1D2 - if (seedlayer == 0 && abs(seeddisk) == 3) - seedindex = 5; //D3D4 - if (seedlayer == 1 && abs(seeddisk) == 1) - seedindex = 6; //L1D1 - if (seedlayer == 2 && abs(seeddisk) == 1) - seedindex = 7; //L2D1 - if (seedlayer == 2 && abs(seeddisk) == 0) - seedindex = 1; //L2L3 - if (middleFPGAStub_ && seedlayer == 2 && seeddisk == 0) - seedindex = 8; // L3L4L2 - if (middleFPGAStub_ && seedlayer == 4 && seeddisk == 0) - seedindex = 9; // L5L6L4 - assert(innerFPGAStub_ != nullptr); - assert(outerFPGAStub_ != nullptr); - if (middleFPGAStub_ && seedlayer == 2 && abs(seeddisk) == 1) { - int l1 = (innerFPGAStub_ && innerFPGAStub_->isBarrel()) ? innerStub_->layer() + 1 : 999, - l2 = (middleFPGAStub_ && middleFPGAStub_->isBarrel()) ? middleStub_->layer() + 1 : 999, - l3 = (outerFPGAStub_ && outerFPGAStub_->isBarrel()) ? outerStub_->layer() + 1 : 999; - if (l1 + l2 + l3 < 1998) { // If two stubs are layer stubs - seedindex = 10; // L2L3D1 - } else { - seedindex = 11; // D1D2L2 - } - } - - if (seedindex < 0) { - throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " seedlayer abs(seeddisk) : " << seedlayer - << " " << abs(seeddisk); - } - - return seedindex; -} +int Tracklet::trackIndex() const { return trackIndex_; } diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc index edf75772c4758..2ad45e30c6717 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculator.cc @@ -14,8 +14,8 @@ using namespace std; using namespace trklet; -TrackletCalculator::TrackletCalculator(string name, Settings const& settings, Globals* globals, unsigned int iSector) - : TrackletCalculatorBase(name, settings, globals, iSector) { +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); @@ -43,7 +43,7 @@ TrackletCalculator::TrackletCalculator(string name, Settings const& settings, Gl } // write the drinv and invt inverse tables - if ((settings_.writeInvTable() || settings_.writeHLSInvTable()) && iTC_ == 0 && iSector_ == 0) { + if ((settings_.writeInvTable() || settings_.writeHLSInvTable() || settings_.writeTable()) && iTC_ == 0) { void (*writeLUT)(const VarInv&, const string&) = nullptr; if (settings.writeInvTable()) { // Verilog version writeLUT = [](const VarInv& x, const string& basename) -> void { @@ -61,7 +61,7 @@ TrackletCalculator::TrackletCalculator(string name, Settings const& settings, Gl // write the firmware design for the calculation of the tracklet parameters // and projections - if ((settings_.writeVerilog() || settings_.writeHLS()) && iTC_ == 0 && iSector_ == 0) { + if ((settings_.writeVerilog() || settings_.writeHLS()) && iTC_ == 0) { void (*writeDesign)(const vector&, const string&) = nullptr; if (settings.writeVerilog()) { // Verilog version writeDesign = [](const vector& v, const string& basename) -> void { @@ -151,10 +151,18 @@ void TrackletCalculator::addInput(MemoryBase* memory, string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find intput : " << input; } -void TrackletCalculator::execute() { +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(); @@ -169,11 +177,11 @@ void TrackletCalculator::execute() { const L1TStub* outerStub = outerFPGAStub->l1tstub(); if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "TrackletCalculator execute " << getName() << "[" << iSector_ << "]"; + edm::LogVerbatim("Tracklet") << "TrackletCalculator execute " << getName() << "[" << iSector << "]"; } - if (innerFPGAStub->isBarrel() && (getName() != "TC_D1L2A" && getName() != "TC_D1L2B")) { - if (outerFPGAStub->isDisk()) { + 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) @@ -185,12 +193,12 @@ void TrackletCalculator::execute() { countsel++; } } else { - if (outerFPGAStub->isDisk()) { + if (outerFPGAStub->layerdisk() >= N_LAYER) { //disk+disk seeding bool accept = diskSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); if (accept) countsel++; - } else if (innerFPGAStub->isDisk()) { + } else if (innerFPGAStub->layerdisk() >= N_LAYER) { //layer+disk seeding bool accept = overlapSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); if (accept) diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc index 86299e4ce3293..24e397c30d433 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorBase.cc @@ -14,11 +14,8 @@ using namespace std; using namespace trklet; -TrackletCalculatorBase::TrackletCalculatorBase(string name, - Settings const& settings, - Globals* global, - unsigned int iSector) - : ProcessBase(name, settings, global, iSector) {} +TrackletCalculatorBase::TrackletCalculatorBase(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) {} void TrackletCalculatorBase::exacttracklet(double r1, double z1, @@ -211,27 +208,29 @@ void TrackletCalculatorBase::exactprojdisk(double zproj, } void TrackletCalculatorBase::addDiskProj(Tracklet* tracklet, int disk) { - FPGAWord fpgar = tracklet->fpgarprojdisk(disk); + disk = std::abs(disk); + + FPGAWord fpgar = tracklet->proj(N_LAYER + disk - 1).fpgarzproj(); if (fpgar.value() * settings_.krprojshiftdisk() < settings_.rmindiskvm()) return; if (fpgar.value() * settings_.krprojshiftdisk() > settings_.rmaxdisk()) return; - FPGAWord fpgaphi = tracklet->fpgaphiprojdisk(disk); + FPGAWord fpgaphi = tracklet->proj(N_LAYER + disk - 1).fpgaphiproj(); int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); - int iphi = iphivmRaw / (32 / settings_.nallstubs(abs(disk) + N_DISK)); + int iphi = iphivmRaw / (32 / settings_.nallstubs(disk + N_LAYER - 1)); - addProjectionDisk(disk, iphi, trackletprojdisks_[abs(disk) - 1][iphi], tracklet); + addProjectionDisk(disk, iphi, trackletprojdisks_[disk - 1][iphi], tracklet); } bool TrackletCalculatorBase::addLayerProj(Tracklet* tracklet, int layer) { assert(layer > 0); - FPGAWord fpgaz = tracklet->fpgazproj(layer); - FPGAWord fpgaphi = tracklet->fpgaphiproj(layer); + FPGAWord fpgaz = tracklet->proj(layer - 1).fpgarzproj(); + FPGAWord fpgaphi = tracklet->proj(layer - 1).fpgaphiproj(); if (fpgaphi.atExtreme()) edm::LogProblem("Tracklet") << "at extreme! " << fpgaphi.value(); @@ -333,12 +332,12 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, const Stub* outerFPGAStub, const L1TStub* outerStub) { if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << "TrackletCalculator " << getName() + edm::LogVerbatim("Tracklet") << "TrackletCalculatorBase " << getName() << " trying stub pair in layer (inner outer): " << innerFPGAStub->layer().value() << " " << outerFPGAStub->layer().value(); } - assert(outerFPGAStub->isBarrel()); + assert(outerFPGAStub->layerdisk() < N_LAYER); assert(layerdisk1_ == (unsigned int)innerFPGAStub->layer().value()); assert(layerdisk1_ < N_LAYER && layerdisk2_ < N_LAYER); @@ -483,8 +482,7 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, //now binary int irinv, iphi0, it, iz0; - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK]; + Projection projs[N_LAYER + N_DISK]; int iphiproj[N_LAYER - 2], izproj[N_LAYER - 2]; int iphiprojdisk[N_DISK], irprojdisk[N_DISK]; @@ -561,11 +559,18 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, izproj[3] = ITC->zL_3_final.ival(); if (!goodTrackPars(ITC->rinv_final.local_passes(), ITC->z0_final.local_passes())) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " Failed rinv or z0 cut"; + } return false; } - if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) + if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) { + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " Failed in sector check"; + } return false; + } for (unsigned int i = 0; i < N_LAYER - 2; ++i) { //reject projection if z is out of range @@ -587,22 +592,21 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, izproj[i] >>= (settings_.nzbitsstub(0) - settings_.nzbitsstub(5)); } - layerprojs[i].init(settings_, - settings_.projlayers(iSeed_, i), - settings_.rmean(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_ == 1 || iSeed_ == 2)); + 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(); @@ -628,21 +632,21 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K()) continue; - diskprojs[i].init(settings_, - i + 1, - settings_.zmean(i), - 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()); + 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)); } } @@ -654,9 +658,7 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - nullptr, - outerStub, + iSeed_, innerFPGAStub, nullptr, outerFPGAStub, @@ -675,8 +677,7 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, 0, iz0, it, - layerprojs, - diskprojs, + projs, false); if (settings_.debugTracklet()) { @@ -719,7 +720,7 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, for (unsigned int j = 0; j < N_LAYER - 2; j++) { int lproj = settings_.projlayers(iSeed_, j); bool added = false; - if (tracklet->validProj(lproj)) { + if (tracklet->validProj(lproj - 1)) { added = addLayerProj(tracklet, lproj); if (added && lproj == 3) addL3 = true; @@ -744,7 +745,7 @@ bool TrackletCalculatorBase::barrelSeeding(const Stub* innerFPGAStub, continue; if (it < 0) disk = -disk; - if (tracklet->validProjDisk(abs(disk))) { + if (tracklet->validProj(N_LAYER + abs(disk) - 1)) { addDiskProj(tracklet, disk); } } @@ -970,8 +971,7 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) return false; - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK - 2]; + Projection projs[N_LAYER + N_DISK]; for (unsigned int i = 0; i < N_DISK - 2; ++i) { //Check is outside z range @@ -989,22 +989,21 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, //shift bits - allways in PS modules for disk seeding iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); - layerprojs[i].init(settings_, - i + 1, - settings_.rmean(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); + 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); } iphiprojdisk[0] = ITC->phiD_0_final.ival(); @@ -1026,21 +1025,21 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, if (irprojdisk[i] <= 0 || irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K()) continue; - diskprojs[i].init(settings_, - i + 1, - settings_.zmean(settings_.projdisks(iSeed_, 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()); + 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); } if (settings_.writeMonitorData("TPars")) { @@ -1052,9 +1051,7 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - nullptr, - outerStub, + iSeed_, innerFPGAStub, nullptr, outerFPGAStub, @@ -1073,8 +1070,7 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, 0, iz0, it, - layerprojs, - diskprojs, + projs, true); if (settings_.debugTracklet()) { @@ -1091,16 +1087,16 @@ bool TrackletCalculatorBase::diskSeeding(const Stub* innerFPGAStub, } trackletpars_->addTracklet(tracklet); - if (tracklet->validProj(1)) { + if (tracklet->validProj(0)) { addLayerProj(tracklet, 1); } - if (tracklet->validProj(2)) { + if (tracklet->validProj(1)) { addLayerProj(tracklet, 2); } for (unsigned int j = 0; j < N_DISK - 2; j++) { - if (tracklet->validProjDisk(sign * settings_.projdisks(iSeed_, j))) { + if (tracklet->validProj(N_LAYER + settings_.projdisks(iSeed_, j) - 1)) { addDiskProj(tracklet, sign * settings_.projdisks(iSeed_, j)); } } @@ -1113,9 +1109,9 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, const Stub* outerFPGAStub, const L1TStub* outerStub) { //Deal with overlap stubs here - assert(outerFPGAStub->isBarrel()); + assert(outerFPGAStub->layerdisk() < N_LAYER); - assert(innerFPGAStub->isDisk()); + assert(innerFPGAStub->layerdisk() >= N_LAYER); int disk = innerFPGAStub->disk().value(); @@ -1344,8 +1340,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, if (!inSector(iphi0, irinv, phi0approx, rinvapprox)) return false; - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK]; + Projection projs[N_LAYER + N_DISK]; for (unsigned int i = 0; i < N_DISK - 2; ++i) { //check that zproj is in range @@ -1363,22 +1358,21 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, //adjust bits for PS modules (no 2S modules in overlap seeds) iphiproj[i] >>= (settings_.nphibitsstub(5) - settings_.nphibitsstub(0)); - layerprojs[i].init(settings_, - i + 1, - settings_.rmean(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); + 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); } for (int i = 0; i < 4; ++i) { @@ -1392,21 +1386,21 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, if (irprojdisk[i] <= 0 || irprojdisk[i] > settings_.rmaxdisk() / ITC->rD_0_final.K()) continue; - diskprojs[i].init(settings_, - i + 1, - settings_.zmean(i), - 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()); + 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); } if (settings_.writeMonitorData("TPars")) { @@ -1417,9 +1411,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - nullptr, - outerStub, + iSeed_, innerFPGAStub, nullptr, outerFPGAStub, @@ -1438,8 +1430,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, 0, iz0, it, - layerprojs, - diskprojs, + projs, false, true); @@ -1460,7 +1451,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, int layer = outerFPGAStub->layer().value() + 1; if (layer == 2) { - if (tracklet->validProj(1)) { + if (tracklet->validProj(0)) { addLayerProj(tracklet, 1); } } @@ -1468,7 +1459,7 @@ bool TrackletCalculatorBase::overlapSeeding(const Stub* innerFPGAStub, for (unsigned int disk = 2; disk < 6; disk++) { if (layer == 2 && disk == 5) continue; - if (tracklet->validProjDisk(disk)) { + if (tracklet->validProj(N_LAYER + disk - 1)) { addDiskProj(tracklet, disk); } } diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc index 5c99dfd6238a4..56fd768ef6163 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletCalculatorDisplaced.cc @@ -13,11 +13,8 @@ using namespace std; using namespace trklet; -TrackletCalculatorDisplaced::TrackletCalculatorDisplaced(string name, - Settings const& settings, - Globals* global, - unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { +TrackletCalculatorDisplaced::TrackletCalculatorDisplaced(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) { for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { vector tmp(settings.nallstubs(ilayer), nullptr); trackletprojlayers_.push_back(tmp); @@ -38,22 +35,22 @@ TrackletCalculatorDisplaced::TrackletCalculatorDisplaced(string name, disk_ = name1[4] - '0'; // set TC index - int iSeed = -1; + iSeed_ = 0; int iTC = name1[9] - 'A'; if (name1.substr(3, 6) == "L3L4L2") - iSeed = 8; + iSeed_ = 8; else if (name1.substr(3, 6) == "L5L6L4") - iSeed = 9; + iSeed_ = 9; else if (name1.substr(3, 6) == "L2L3D1") - iSeed = 10; + iSeed_ = 10; else if (name1.substr(3, 6) == "D1D2L2") - iSeed = 11; + iSeed_ = 11; - assert(iSeed != -1); + assert(iSeed_ != 0); - TCIndex_ = (iSeed << 4) + iTC; + TCIndex_ = (iSeed_ << 4) + iTC; assert(TCIndex_ >= 128 && TCIndex_ < 191); assert((layer_ != 0) || (disk_ != 0)); @@ -61,7 +58,7 @@ TrackletCalculatorDisplaced::TrackletCalculatorDisplaced(string name, toR_.clear(); toZ_.clear(); - if (iSeed == 8 || iSeed == 9) { + if (iSeed_ == 8 || iSeed_ == 9) { if (layer_ == 3) { rzmeanInv_[0] = 1.0 / settings_.rmean(2 - 1); rzmeanInv_[1] = 1.0 / settings_.rmean(3 - 1); @@ -100,7 +97,7 @@ TrackletCalculatorDisplaced::TrackletCalculatorDisplaced(string name, toR_.push_back(rproj_[i]); } - if (iSeed == 10 || iSeed == 11) { + if (iSeed_ == 10 || iSeed_ == 11) { if (layer_ == 2) { rzmeanInv_[0] = 1.0 / settings_.rmean(2 - 1); rzmeanInv_[1] = 1.0 / settings_.rmean(3 - 1); @@ -151,6 +148,7 @@ void TrackletCalculatorDisplaced::addOutput(MemoryBase* memory, string output) { edm::LogVerbatim("Tracklet") << "In " << name_ << " adding output to " << memory->getName() << " to output " << output; } + if (output == "trackpar") { auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); @@ -193,6 +191,7 @@ void TrackletCalculatorDisplaced::addInput(MemoryBase* memory, string input) { edm::LogVerbatim("Tracklet") << "In " << name_ << " adding input from " << memory->getName() << " to input " << input; } + if (input == "thirdallstubin") { auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); @@ -220,10 +219,14 @@ void TrackletCalculatorDisplaced::addInput(MemoryBase* memory, string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; } -void TrackletCalculatorDisplaced::execute() { +void TrackletCalculatorDisplaced::execute(unsigned int iSector, double phimin, double phimax) { unsigned int countall = 0; unsigned int countsel = 0; + phimin_ = phimin; + phimax_ = phimax; + iSector_ = iSector; + for (auto& stubtriplet : stubtriplets_) { if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { edm::LogVerbatim("Tracklet") << "Will break on too many tracklets in " << getName(); @@ -244,20 +247,24 @@ void TrackletCalculatorDisplaced::execute() { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "TrackletCalculatorDisplaced execute " << getName() << "[" << iSector_ << "]"; - if (innerFPGAStub->isBarrel() && middleFPGAStub->isBarrel() && outerFPGAStub->isBarrel()) { + if (innerFPGAStub->layerdisk() < N_LAYER && middleFPGAStub->layerdisk() < N_LAYER && + outerFPGAStub->layerdisk() < N_LAYER) { //barrel+barrel seeding bool accept = LLLSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub); if (accept) countsel++; - } else if (innerFPGAStub->isDisk() && middleFPGAStub->isDisk() && outerFPGAStub->isDisk()) { + } else if (innerFPGAStub->layerdisk() >= N_LAYER && middleFPGAStub->layerdisk() >= N_LAYER && + outerFPGAStub->layerdisk() >= N_LAYER) { throw cms::Exception("LogicError") << __FILE__ << " " << __LINE__ << " Invalid seeding!"; } else { //layer+disk seeding - if (innerFPGAStub->isBarrel() && middleFPGAStub->isDisk() && outerFPGAStub->isDisk()) { //D1D2L2 + if (innerFPGAStub->layerdisk() < N_LAYER && middleFPGAStub->layerdisk() >= N_LAYER && + outerFPGAStub->layerdisk() >= N_LAYER) { //D1D2L2 bool accept = DDLSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub); if (accept) countsel++; - } else if (innerFPGAStub->isDisk() && middleFPGAStub->isBarrel() && outerFPGAStub->isBarrel()) { //L2L3D1 + } else if (innerFPGAStub->layerdisk() >= N_LAYER && middleFPGAStub->layerdisk() < N_LAYER && + outerFPGAStub->layerdisk() < N_LAYER) { //L2L3D1 bool accept = LLDSeeding(innerFPGAStub, innerStub, middleFPGAStub, middleStub, outerFPGAStub, outerStub); if (accept) countsel++; @@ -292,26 +299,27 @@ void TrackletCalculatorDisplaced::execute() { } void TrackletCalculatorDisplaced::addDiskProj(Tracklet* tracklet, int disk) { - FPGAWord fpgar = tracklet->fpgarprojdisk(disk); + disk = std::abs(disk); + FPGAWord fpgar = tracklet->proj(N_LAYER + disk - 1).fpgarzproj(); if (fpgar.value() * settings_.krprojshiftdisk() < settings_.rmindiskvm()) return; if (fpgar.value() * settings_.krprojshiftdisk() > settings_.rmaxdisk()) return; - FPGAWord fpgaphi = tracklet->fpgaphiprojdisk(disk); + FPGAWord fpgaphi = tracklet->proj(N_LAYER + disk - 1).fpgaphiproj(); int iphivmRaw = fpgaphi.value() >> (fpgaphi.nbits() - 5); - int iphi = iphivmRaw / (32 / settings_.nallstubs(abs(disk) + N_DISK)); + int iphi = iphivmRaw / (32 / settings_.nallstubs(disk + N_LAYER - 1)); - addProjectionDisk(disk, iphi, trackletprojdisks_[abs(disk) - 1][iphi], tracklet); + addProjectionDisk(disk, iphi, trackletprojdisks_[disk - 1][iphi], tracklet); } bool TrackletCalculatorDisplaced::addLayerProj(Tracklet* tracklet, int layer) { assert(layer > 0); - FPGAWord fpgaz = tracklet->fpgazproj(layer); - FPGAWord fpgaphi = tracklet->fpgaphiproj(layer); + FPGAWord fpgaz = tracklet->proj(layer - 1).fpgarzproj(); + FPGAWord fpgaphi = tracklet->proj(layer - 1).fpgaphiproj(); if (fpgaz.atExtreme()) return false; @@ -372,7 +380,7 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, << " trying stub triplet in layer (L L L): " << innerFPGAStub->layer().value() << " " << middleFPGAStub->layer().value() << " " << outerFPGAStub->layer().value(); - assert(outerFPGAStub->isBarrel()); + assert(outerFPGAStub->layerdisk() < N_LAYER); double r1 = innerStub->r(); double z1 = innerStub->z(); @@ -393,8 +401,7 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, double rinv, phi0, d0, t, z0; - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK]; + Projection projs[N_LAYER + N_DISK]; double phiproj[N_LAYER - 2], zproj[N_LAYER - 2], phider[N_LAYER - 2], zder[N_LAYER - 2]; double phiprojdisk[N_DISK], rprojdisk[N_DISK], phiderdisk[N_DISK], rderdisk[N_DISK]; @@ -580,8 +587,9 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, success = false; } - if (!success) + if (!success) { return false; + } double phicritapprox = phi0approx - asin(0.5 * settings_.rcrit() * rinvapprox); int phicrit = iphi0 - 2 * irinv; @@ -598,11 +606,13 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, "but not approximate, phicritapprox: " << phicritapprox; if (settings_.usephicritapprox()) { - if (!keepapprox) + if (!keepapprox) { return false; + } } else { - if (!keep) + if (!keep) { return false; + } } for (unsigned int i = 0; i < toR_.size(); ++i) { @@ -649,21 +659,21 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, } } - layerprojs[i].init(settings_, - lproj_[i], - rproj_[i], - iphiproj[i], - izproj[i], - iphider[i], - izder[i], - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - phiderapprox[i], - zderapprox[i]); + projs[lproj_[i] - 1].init(settings_, + lproj_[i] - 1, + iphiproj[i], + izproj[i], + iphider[i], + izder[i], + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + phiderapprox[i], + zderapprox[i], + false); } if (std::abs(it * kt) > 1.0) { @@ -684,21 +694,21 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, if (rprojdiskapprox[i] < settings_.rmindisk() || rprojdiskapprox[i] > settings_.rmaxdisk()) continue; - diskprojs[i].init(settings_, - i + 1, - rproj_[i], - iphiprojdisk[i], - irprojdisk[i], - iphiderdisk[i], - irderdisk[i], - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - phiderdisk[i], - rderdisk[i]); + projs[N_LAYER + i].init(settings_, + N_LAYER + i, + iphiprojdisk[i], + irprojdisk[i], + iphiderdisk[i], + irderdisk[i], + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + phiderdisk[i], + rderdisk[i], + false); } } @@ -709,9 +719,7 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - middleStub, - outerStub, + iSeed_, innerFPGAStub, middleFPGAStub, outerFPGAStub, @@ -730,8 +738,7 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, id0, iz0, it, - layerprojs, - diskprojs, + projs, false); if (settings_.debugTracklet()) @@ -752,9 +759,10 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, bool addL6 = false; for (unsigned int j = 0; j < toR_.size(); j++) { bool added = false; + if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding layer projection " << j << "/" << toR_.size() << " " << lproj_[j]; - if (tracklet->validProj(lproj_[j])) { + if (tracklet->validProj(lproj_[j] - 1)) { added = addLayerProj(tracklet, lproj_[j]); if (added && lproj_[j] == 5) addL5 = true; @@ -775,7 +783,7 @@ bool TrackletCalculatorDisplaced::LLLSeeding(const Stub* innerFPGAStub, disk = -disk; if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding disk projection " << j << "/" << toZ_.size() << " " << disk; - if (tracklet->validProjDisk(abs(disk))) { + if (tracklet->validProj(N_LAYER + abs(disk) - 1)) { addDiskProj(tracklet, disk); } } @@ -1020,8 +1028,7 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, return false; } - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK]; + Projection projs[N_LAYER + N_DISK]; for (unsigned int i = 0; i < toR_.size(); ++i) { iphiproj[i] = phiprojapprox[i] / kphiproj; @@ -1060,21 +1067,21 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, iphider[i] = (1 << (settings_.nbitsphiprojderL456() - 1)) - 1; } - layerprojs[i].init(settings_, - lproj_[i], - rproj_[i], - iphiproj[i], - izproj[i], - iphider[i], - izder[i], - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - phiderapprox[i], - zderapprox[i]); + projs[lproj_[i] - 1].init(settings_, + lproj_[i] - 1, + iphiproj[i], + izproj[i], + iphider[i], + izder[i], + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + phiderapprox[i], + zderapprox[i], + false); } if (std::abs(it * kt) > 1.0) { @@ -1093,21 +1100,21 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, if (irprojdisk[i] < settings_.rmindisk() / krprojdisk || irprojdisk[i] > settings_.rmaxdisk() / krprojdisk) continue; - diskprojs[i].init(settings_, - i + 1, - rproj_[i], - iphiprojdisk[i], - irprojdisk[i], - iphiderdisk[i], - irderdisk[i], - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - phiderdisk[i], - rderdisk[i]); + projs[N_LAYER + i + 2].init(settings_, + N_LAYER + i + 2, + iphiprojdisk[i], + irprojdisk[i], + iphiderdisk[i], + irderdisk[i], + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + phiderdisk[i], + rderdisk[i], + false); } } @@ -1118,9 +1125,7 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - middleStub, - outerStub, + iSeed_, innerFPGAStub, middleFPGAStub, outerFPGAStub, @@ -1139,8 +1144,7 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, id0, iz0, it, - layerprojs, - diskprojs, + projs, true); if (settings_.debugTracklet()) @@ -1160,8 +1164,8 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, for (unsigned int j = 0; j < toR_.size(); j++) { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding layer projection " << j << "/" << toR_.size() << " " << lproj_[j] << " " - << tracklet->validProj(lproj_[j]); - if (tracklet->validProj(lproj_[j])) { + << tracklet->validProj(lproj_[j] - 1); + if (tracklet->validProj(lproj_[j] - 1)) { addLayerProj(tracklet, lproj_[j]); } } @@ -1174,8 +1178,8 @@ bool TrackletCalculatorDisplaced::DDLSeeding(const Stub* innerFPGAStub, disk = -disk; if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding disk projection " << j << "/" << toZ_.size() << " " << disk << " " - << tracklet->validProjDisk(abs(disk)); - if (tracklet->validProjDisk(abs(disk))) { + << tracklet->validProj(N_LAYER + abs(disk) - 1); + if (tracklet->validProj(N_LAYER + abs(disk) - 1)) { addDiskProj(tracklet, disk); } } @@ -1420,8 +1424,7 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, return false; } - LayerProjection layerprojs[N_LAYER - 2]; - DiskProjection diskprojs[N_DISK]; + Projection projs[N_LAYER + N_DISK]; for (unsigned int i = 0; i < toR_.size(); ++i) { iphiproj[i] = phiprojapprox[i] / kphiproj; @@ -1459,21 +1462,21 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, iphider[i] = (1 << (settings_.nbitsphiprojderL456() - 1)) - 1; } - layerprojs[i].init(settings_, - lproj_[i], - rproj_[i], - iphiproj[i], - izproj[i], - iphider[i], - izder[i], - phiproj[i], - zproj[i], - phider[i], - zder[i], - phiprojapprox[i], - zprojapprox[i], - phiderapprox[i], - zderapprox[i]); + projs[lproj_[i] - 1].init(settings_, + lproj_[i] - 1, + iphiproj[i], + izproj[i], + iphider[i], + izder[i], + phiproj[i], + zproj[i], + phider[i], + zder[i], + phiprojapprox[i], + zprojapprox[i], + phiderapprox[i], + zderapprox[i], + false); } if (std::abs(it * kt) > 1.0) { @@ -1494,21 +1497,21 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, if (irprojdisk[i] < settings_.rmindisk() / krprojdisk || irprojdisk[i] > settings_.rmaxdisk() / krprojdisk) continue; - diskprojs[i].init(settings_, - i + 1, - rproj_[i], - iphiprojdisk[i], - irprojdisk[i], - iphiderdisk[i], - irderdisk[i], - phiprojdisk[i], - rprojdisk[i], - phiderdisk[i], - rderdisk[i], - phiprojdiskapprox[i], - rprojdiskapprox[i], - phiderdisk[i], - rderdisk[i]); + projs[N_LAYER + i + 1].init(settings_, + N_LAYER + i + 1, + iphiprojdisk[i], + irprojdisk[i], + iphiderdisk[i], + irderdisk[i], + phiprojdisk[i], + rprojdisk[i], + phiderdisk[i], + rderdisk[i], + phiprojdiskapprox[i], + rprojdiskapprox[i], + phiderdisk[i], + rderdisk[i], + false); } } @@ -1519,9 +1522,7 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, } Tracklet* tracklet = new Tracklet(settings_, - innerStub, - middleStub, - outerStub, + iSeed_, innerFPGAStub, middleFPGAStub, outerFPGAStub, @@ -1540,8 +1541,7 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, id0, iz0, it, - layerprojs, - diskprojs, + projs, false); if (settings_.debugTracklet()) @@ -1561,7 +1561,7 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, for (unsigned int j = 0; j < toR_.size(); j++) { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding layer projection " << j << "/" << toR_.size() << " " << lproj_[j]; - if (tracklet->validProj(lproj_[j])) { + if (tracklet->validProj(lproj_[j] - 1)) { addLayerProj(tracklet, lproj_[j]); } } @@ -1574,7 +1574,7 @@ bool TrackletCalculatorDisplaced::LLDSeeding(const Stub* innerFPGAStub, disk = -disk; if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << "adding disk projection " << j << "/" << toZ_.size() << " " << disk; - if (tracklet->validProjDisk(abs(disk))) { + if (tracklet->validProj(N_LAYER + abs(disk) - 1)) { addDiskProj(tracklet, disk); } } @@ -1679,8 +1679,18 @@ void TrackletCalculatorDisplaced::exacttracklet(double r1, double y2 = r2 * sin(phi2); double y3 = r3 * sin(phi3); - double k1 = -(x2 - x1) / (y2 - y1); - double k2 = -(x3 - x2) / (y3 - y2); + double dy21 = y2 - y1; + double dy32 = y3 - y2; + + //Hack to protect against dividing by zero + //code should be rewritten to avoid this + if (dy21 == 0.0) + dy21 = 1e-9; + if (dy32 == 0.0) + dy32 = 1e-9; + + double k1 = -(x2 - x1) / dy21; + double k2 = -(x3 - x2) / dy32; double b1 = 0.5 * (y2 + y1) - 0.5 * (x1 + x2) * k1; double b2 = 0.5 * (y3 + y2) - 0.5 * (x2 + x3) * k2; //their intersection gives the center of the circle diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc new file mode 100644 index 0000000000000..cfed9abbcaebb --- /dev/null +++ b/L1Trigger/TrackFindingTracklet/src/TrackletConfigBuilder.cc @@ -0,0 +1,1294 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "L1Trigger/TrackFindingTracklet/interface/TrackletConfigBuilder.h" +#include "L1Trigger/TrackFindingTracklet/interface/Settings.h" + +using namespace std; +using namespace trklet; + +TrackletConfigBuilder::TrackletConfigBuilder(const Settings& settings) : settings_(settings) { + NSector_ = N_SECTOR; + rcrit_ = settings.rcrit(); + + combinedmodules_ = settings.combined(); + + extended_ = settings.extended(); + + rinvmax_ = settings.rinvmax(); + + rmaxdisk_ = settings.rmaxdisk(); + zlength_ = settings.zlength(); + + for (int i = 0; i < N_LAYER; i++) { + rmean_[i] = settings.rmean(i); + } + + for (int i = 0; i < N_DISK; i++) { + zmean_[i] = settings.zmean(i); + } + + dphisectorHG_ = settings.dphisectorHG(); + + for (int layerdisk = 0; layerdisk < N_LAYER + N_DISK; layerdisk++) { + NRegions_[layerdisk] = settings.nallstubs(layerdisk); + NVMME_[layerdisk] = settings.nvmme(layerdisk); + } + + for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) { + NVMTE_[iseed] = std::pair(settings.nvmte(0, iseed), settings.nvmte(1, iseed)); + NTC_[iseed] = settings.NTC(iseed); + } + + initGeom(); + + buildTE(); + + buildTC(); + + buildProjections(); +} + +std::pair TrackletConfigBuilder::seedLayers(unsigned int iSeed) { + return std::pair(settings_.seedlayers(0, iSeed), settings_.seedlayers(1, iSeed)); +} + +void TrackletConfigBuilder::initGeom() { + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + double dphi = dphisectorHG_ / NRegions_[ilayer]; + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + std::vector > emptyVec; + projections_[ilayer].push_back(emptyVec); + double phimin = dphi * iReg; + double phimax = phimin + dphi; + std::pair tmp(phimin, phimax); + allStubs_[ilayer].push_back(tmp); + double dphiVM = dphi / NVMME_[ilayer]; + for (unsigned int iVM = 0; iVM < NVMME_[ilayer]; iVM++) { + double phivmmin = phimin + iVM * dphiVM; + double phivmmax = phivmmin + dphiVM; + std::pair tmp(phivmmin, phivmmax); + VMStubsME_[ilayer].push_back(tmp); + } + } + } + for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) { + unsigned int l1 = seedLayers(iseed).first; + unsigned int l2 = seedLayers(iseed).second; + unsigned int nVM1 = NVMTE_[iseed].first; + unsigned int nVM2 = NVMTE_[iseed].second; + double dphiVM = dphisectorHG_ / (nVM1 * NRegions_[l1]); + for (unsigned int iVM = 0; iVM < nVM1 * NRegions_[l1]; iVM++) { + double phivmmin = iVM * dphiVM; + double phivmmax = phivmmin + dphiVM; + std::pair tmp(phivmmin, phivmmax); + VMStubsTE_[iseed].first.push_back(tmp); + } + dphiVM = dphisectorHG_ / (nVM2 * NRegions_[l2]); + for (unsigned int iVM = 0; iVM < nVM2 * NRegions_[l2]; iVM++) { + double phivmmin = iVM * dphiVM; + double phivmmax = phivmmin + dphiVM; + std::pair tmp(phivmmin, phivmmax); + VMStubsTE_[iseed].second.push_back(tmp); + } + } +} + +std::pair TrackletConfigBuilder::seedRadii(unsigned int iseed) { + std::pair seedlayers = seedLayers(iseed); + + unsigned int l1 = seedlayers.first; + unsigned int l2 = seedlayers.second; + + double r1, r2; + + if (iseed < 4) { //barrel seeding + r1 = rmean_[l1]; + r2 = rmean_[l2]; + } else if (iseed < 6) { //disk seeding + r1 = rmean_[0] + 40.0; //Somwwhat of a hack - but allows finding all the regions + //when projecting to L1 + r2 = r1 * zmean_[l2 - 6] / zmean_[l1 - 6]; + } else { //overlap seeding + r1 = rmean_[l1]; + r2 = r1 * zmean_[l2 - 6] / zlength_; + } + + return std::pair(r1, r2); +} + +bool TrackletConfigBuilder::validTEPair(unsigned int iseed, unsigned int iTE1, unsigned int iTE2) { + double rinvmin = 999.9; + double rinvmax = -999.9; + + double phi1[2] = {VMStubsTE_[iseed].first[iTE1].first, VMStubsTE_[iseed].first[iTE1].second}; + double phi2[2] = {VMStubsTE_[iseed].second[iTE2].first, VMStubsTE_[iseed].second[iTE2].second}; + + std::pair seedradii = seedRadii(iseed); + + for (unsigned int i1 = 0; i1 < 2; i1++) { + for (unsigned int i2 = 0; i2 < 2; i2++) { + double arinv = rinv(seedradii.first, phi1[i1], seedradii.second, phi2[i2]); + if (arinv < rinvmin) + rinvmin = arinv; + if (arinv > rinvmax) + rinvmax = arinv; + } + } + + if (rinvmin > rinvmax_) + return false; + if (rinvmax < -rinvmax_) + return false; + + return true; +} + +void TrackletConfigBuilder::buildTE() { + for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) { + for (unsigned int i1 = 0; i1 < VMStubsTE_[iseed].first.size(); i1++) { + for (unsigned int i2 = 0; i2 < VMStubsTE_[iseed].second.size(); i2++) { + if (validTEPair(iseed, i1, i2)) { + std::pair tmp(i1, i2); + TE_[iseed].push_back(tmp); + } + } + } + } +} + +void TrackletConfigBuilder::buildTC() { + for (unsigned int iSeed = 0; iSeed < N_SEED_PROMPT; iSeed++) { + unsigned int nTC = NTC_[iSeed]; + std::vector >& TEs = TE_[iSeed]; + std::vector >& TCs = TC_[iSeed]; + + //Very naive method to group TEs in TC + + double invnTC = nTC * (1.0 / TEs.size()); + + for (unsigned int iTE = 0; iTE < TEs.size(); iTE++) { + int iTC = invnTC * iTE; + assert(iTC < (int)nTC); + if (iTC >= (int)TCs.size()) { + std::vector tmp; + tmp.push_back(iTE); + TCs.push_back(tmp); + } else { + TCs[iTC].push_back(iTE); + } + } + } +} + +std::pair TrackletConfigBuilder::seedPhiRange(double rproj, unsigned int iSeed, unsigned int iTC) { + std::vector >& TCs = TC_[iSeed]; + + std::pair seedradii = seedRadii(iSeed); + + double phimin = 999.0; + double phimax = -999.0; + for (unsigned int iTE = 0; iTE < TCs[iTC].size(); iTE++) { + unsigned int theTE = TCs[iTC][iTE]; + unsigned int l1TE = TE_[iSeed][theTE].first; + unsigned int l2TE = TE_[iSeed][theTE].second; + double phi1[2] = {VMStubsTE_[iSeed].first[l1TE].first, VMStubsTE_[iSeed].first[l1TE].second}; + double phi2[2] = {VMStubsTE_[iSeed].second[l2TE].first, VMStubsTE_[iSeed].second[l2TE].second}; + for (unsigned int i1 = 0; i1 < 2; i1++) { + for (unsigned int i2 = 0; i2 < 2; i2++) { + double aphi = phi(seedradii.first, phi1[i1], seedradii.second, phi2[i2], rproj); + if (aphi < phimin) + phimin = aphi; + if (aphi > phimax) + phimax = aphi; + } + } + } + return std::pair(phimin, phimax); +} + +void TrackletConfigBuilder::buildProjections() { + for (unsigned int iseed = 0; iseed < N_SEED_PROMPT; iseed++) { + std::vector >& TCs = TC_[iseed]; + + for (unsigned int ilayer = 0; ilayer < N_LAYER + N_DISK; ilayer++) { + if (matchport_[iseed][ilayer] == -1) + continue; + for (unsigned int iReg = 0; iReg < NRegions_[ilayer]; iReg++) { + for (unsigned int iTC = 0; iTC < TCs.size(); iTC++) { + double rproj = rmaxdisk_; + if (ilayer < 6) + rproj = rmean_[ilayer]; + std::pair phiRange = seedPhiRange(rproj, iseed, iTC); + if (phiRange.first < allStubs_[ilayer][iReg].second && phiRange.second > allStubs_[ilayer][iReg].first) { + std::pair tmp(iseed, iTC); //seedindex and TC + projections_[ilayer][iReg].push_back(tmp); + } + } + } + } + } +} + +double TrackletConfigBuilder::phi(double r1, double phi1, double r2, double phi2, double r) { + double rhoinv = rinv(r1, phi1, r2, phi2); + if (fabs(rhoinv) > rinvmax_) { + rhoinv = rinvmax_ * rhoinv / fabs(rhoinv); + } + return phi1 + asin(0.5 * r * rhoinv) - asin(0.5 * r1 * rhoinv); +} + +double TrackletConfigBuilder::rinv(double r1, double phi1, double r2, double phi2) { + double deltaphi = phi1 - phi2; + return 2 * sin(deltaphi) / sqrt(r2 * r2 + r1 * r1 - 2 * r1 * r2 * cos(deltaphi)); +} + +std::string TrackletConfigBuilder::iSeedStr(unsigned int iSeed) { + static std::string name[8] = {"L1L2", "L2L3", "L3L4", "L5L6", "D1D2", "D3D4", "L1D1", "L2D1"}; + + assert(iSeed < 8); + return name[iSeed]; +} + +std::string TrackletConfigBuilder::numStr(unsigned int i) { + static std::string num[32] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", + "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", + "23", "24", "25", "26", "27", "28", "29", "30", "31", "32"}; + assert(i < 32); + return num[i]; +} + +std::string TrackletConfigBuilder::iTCStr(unsigned int iTC) { + static std::string name[12] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"}; + + assert(iTC < 12); + return name[iTC]; +} + +std::string TrackletConfigBuilder::iRegStr(unsigned int iReg, unsigned int iSeed) { + static std::string name[8] = {"A", "B", "C", "D", "E", "F", "G", "H"}; + + static std::string nameOverlap[8] = {"X", "Y", "Z", "W", "Q", "R", "S", "T"}; + + static std::string nameL2L3[4] = {"I", "J", "K", "L"}; + + if (iSeed == 1) { + assert(iReg < 4); + return nameL2L3[iReg]; + } + if (iSeed == 6 || iSeed == 7) { + assert(iReg < 8); + return nameOverlap[iReg]; + } + assert(iReg < 8); + return name[iReg]; +} + +std::string TrackletConfigBuilder::TCName(unsigned int iSeed, unsigned int iTC) { + if (combinedmodules_) { + return "TP_" + iSeedStr(iSeed) + iTCStr(iTC); + } else { + return "TC_" + iSeedStr(iSeed) + iTCStr(iTC); + } +} + +std::string TrackletConfigBuilder::LayerName(unsigned int ilayer) { + return ilayer < 6 ? ("L" + numStr(ilayer)) : ("D" + numStr(ilayer - 6)); +} + +std::string TrackletConfigBuilder::TPROJName(unsigned int iSeed, + unsigned int iTC, + unsigned int ilayer, + unsigned int ireg) { + return "TPROJ_" + iSeedStr(iSeed) + iTCStr(iTC) + "_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); +} + +std::string TrackletConfigBuilder::PRName(unsigned int ilayer, unsigned int ireg) { + if (combinedmodules_) { + return "MP_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); + } else { + return "PR_" + LayerName(ilayer) + "PHI" + iTCStr(ireg); + } +} + +void TrackletConfigBuilder::writeProjectionMemories(std::ostream& os, std::ostream& memories, std::ostream&) { + 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; + + 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; + } + } + } +} + +std::string TrackletConfigBuilder::SPName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed) { + return "SP_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" + + iRegStr(ireg2, iseed) + numStr(ivm2); +} + +std::string TrackletConfigBuilder::SPDName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int l3, + unsigned int ireg3, + unsigned int ivm3, + unsigned int iseed) { + return "SPD_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" + + iRegStr(ireg2, iseed) + numStr(ivm2) + "_" + LayerName(l3) + "PHI" + iRegStr(ireg3, iseed) + numStr(ivm3); +} + +std::string TrackletConfigBuilder::TEName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed) { + return "TE_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" + + iRegStr(ireg2, iseed) + numStr(ivm2); +} + +std::string TrackletConfigBuilder::TEDName(unsigned int l1, + unsigned int ireg1, + unsigned int ivm1, + unsigned int l2, + unsigned int ireg2, + unsigned int ivm2, + unsigned int iseed) { + return "TED_" + LayerName(l1) + "PHI" + iRegStr(ireg1, iseed) + numStr(ivm1) + "_" + LayerName(l2) + "PHI" + + iRegStr(ireg2, iseed) + numStr(ivm2); +} + +std::string TrackletConfigBuilder::TParName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc) { + return "TPAR_" + LayerName(l1) + LayerName(l2) + LayerName(l3) + iTCStr(itc); +} + +std::string TrackletConfigBuilder::TCDName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc) { + return "TCD_" + LayerName(l1) + LayerName(l2) + LayerName(l3) + iTCStr(itc); +} + +std::string TrackletConfigBuilder::TPROJName( + unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc, unsigned int projlayer, unsigned int projreg) { + return "TPROJ_" + LayerName(l1) + LayerName(l2) + LayerName(l3) + iTCStr(itc) + "_" + LayerName(projlayer) + "PHI" + + iTCStr(projreg); +} + +std::string TrackletConfigBuilder::FTName(unsigned int l1, unsigned int l2, unsigned int l3) { + return "FT_" + LayerName(l1) + LayerName(l2) + LayerName(l3); +} + +std::string TrackletConfigBuilder::TREName( + unsigned int l1, unsigned int ireg1, unsigned int l2, unsigned int ireg2, unsigned int iseed, unsigned int count) { + return "TRE_" + LayerName(l1) + iRegStr(ireg1, iseed) + LayerName(l2) + iRegStr(ireg2, iseed) + "_" + numStr(count); +} + +std::string TrackletConfigBuilder::STName(unsigned int l1, + unsigned int ireg1, + unsigned int l2, + unsigned int ireg2, + unsigned int l3, + unsigned int ireg3, + unsigned int iseed, + unsigned int count) { + return "ST_" + LayerName(l1) + iRegStr(ireg1, iseed) + LayerName(l2) + iRegStr(ireg2, iseed) + "_" + LayerName(l3) + + iRegStr(ireg3, iseed) + "_" + numStr(count); +} + +std::string TrackletConfigBuilder::TCNAme(unsigned int iseed, unsigned int iTC) { + return "TC_" + iSeedStr(iseed) + iTCStr(iTC); +} + +void TrackletConfigBuilder::writeSPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + 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) { + 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) { + 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) { + 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&) { + 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) { + if (combinedmodules_) { + 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 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 { + 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; + } + } + } + } +} + +void TrackletConfigBuilder::writeASMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + 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++) { + 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; + } + } + + //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++) { + 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; + + bool inner = ilayer == l1; + + for (unsigned int iTC = 0; iTC < TC_[iSeed].size(); iTC++) { + int nTCReg = TC_[iSeed].size() / NRegions_[l2]; + + int iTCReg = iTC / nTCReg; + + int jTCReg = 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; + + 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 != ""); + } + + if (ext == "") { + ext = "_" + iTCStr(iTC); + } + + if (iSeed < 4) { //Barrel seeding + ext = "_B" + ext; + } else if (iSeed > 5) { + ext = "_O" + ext; + } else { + ext = "_D" + ext; + } + + nmem++; + 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; + 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; + + if (l1 == ilayer && iReg == TE1 / NVMTE_[iSeed].first) + used = true; + if (l2 == ilayer && iReg == TE2 / NVMTE_[iSeed].second) + used = true; + } + + if (used) { + nmem++; + 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; + } + } + } + } + } + } + } +} + +void TrackletConfigBuilder::writeVMSMemories(std::ostream& os, std::ostream& memories, std::ostream&) { + 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++) { + 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; + } + } + + //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; + } + } + } + } 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) << ".vmstuboutPHI" << iTCStr(iReg) + << iVMME + 1 << " output=> ME_" << LayerName(ilayer) << "PHI" << iTCStr(iReg) << iVMME + 1 << ".vmstubin" + << std::endl; + } + } + + //Next write VMS memories used by MatchCalculator + 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 = seedLayers(iSeed).first; + unsigned int NVMTE = NVMTE_[iSeed].first; + if (innerouterseed == 1) { + ilayer = seedLayers(iSeed).second; + NVMTE = NVMTE_[iSeed].second; + } + + for (unsigned int iVMTE = 0; iVMTE < NVMTE * NRegions_[ilayer]; iVMTE++) { + unsigned int iReg = iVMTE / NVMTE; + + unsigned int nmem = 0; + + if (iSeed == 7) { + nmem = 4; + } + + for (unsigned int iTE = 0; iTE < TE_[iSeed].size(); iTE++) { + unsigned int TE1 = TE_[iSeed][iTE].first; + 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; + nmem++; + 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) << ".vmstuboutPHI" << iTCStr(iReg) + << 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; + } + } + } + } + } + } +} + +void TrackletConfigBuilder::writeTPARMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + 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; + } + } + } +} + +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; + } +} + +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; + } +} + +void TrackletConfigBuilder::writeILMemories(std::ostream& os, std::ostream& memories, std::ostream& modules) { + //FIXME these should not be hardcoded - but for now wanted to avoid reading file + string dtcname[52]; + unsigned int layerdisk[52]; + double phimin[52]; + double phimax[52]; + + dtcname[0] = "PS10G_1"; + layerdisk[0] = 0; + phimin[0] = 0.304273; + phimax[0] = 0.742925; + dtcname[1] = "PS10G_1"; + layerdisk[1] = 6; + phimin[1] = -0.185672; + phimax[1] = 0.883803; + dtcname[2] = "PS10G_1"; + layerdisk[2] = 8; + phimin[2] = -0.132414; + phimax[2] = 0.830545; + dtcname[3] = "PS10G_1"; + layerdisk[3] = 10; + phimin[3] = -0.132414; + phimax[3] = 0.830545; + dtcname[4] = "PS10G_2"; + layerdisk[4] = 0; + phimin[4] = -0.0133719; + phimax[4] = 0.715599; + dtcname[5] = "PS10G_2"; + layerdisk[5] = 7; + phimin[5] = -0.110089; + phimax[5] = 0.808221; + dtcname[6] = "PS10G_2"; + layerdisk[6] = 9; + phimin[6] = -0.132414; + phimax[6] = 0.830545; + dtcname[7] = "PS10G_3"; + layerdisk[7] = 1; + phimin[7] = -0.11381; + phimax[7] = 0.822812; + dtcname[8] = "PS10G_3"; + layerdisk[8] = 7; + phimin[8] = -0.185672; + phimax[8] = 0.883803; + dtcname[9] = "PS10G_4"; + layerdisk[9] = 6; + phimin[9] = -0.0823971; + phimax[9] = 0.780529; + dtcname[10] = "PS10G_4"; + layerdisk[10] = 8; + phimin[10] = -0.0963091; + phimax[10] = 0.794441; + dtcname[11] = "PS10G_4"; + layerdisk[11] = 10; + phimin[11] = -0.0963091; + phimax[11] = 0.794441; + dtcname[12] = "PS_1"; + layerdisk[12] = 2; + phimin[12] = 0.0827748; + phimax[12] = 0.615357; + dtcname[13] = "PS_1"; + layerdisk[13] = 7; + phimin[13] = -0.0823971; + phimax[13] = 0.780529; + dtcname[14] = "PS_2"; + layerdisk[14] = 2; + phimin[14] = -0.0917521; + phimax[14] = 0.614191; + dtcname[15] = "PS_2"; + layerdisk[15] = 9; + phimin[15] = -0.0963091; + phimax[15] = 0.794441; + dtcname[16] = "2S_1"; + layerdisk[16] = 3; + phimin[16] = -0.0246209; + phimax[16] = 0.763311; + dtcname[17] = "2S_1"; + layerdisk[17] = 4; + phimin[17] = 0.261875; + phimax[17] = 0.403311; + dtcname[18] = "2S_2"; + layerdisk[18] = 4; + phimin[18] = -0.0542445; + phimax[18] = 0.715509; + dtcname[19] = "2S_3"; + layerdisk[19] = 5; + phimin[19] = 0.0410126; + phimax[19] = 0.730605; + dtcname[20] = "2S_4"; + layerdisk[20] = 5; + phimin[20] = -0.0428961; + phimax[20] = 0.693862; + dtcname[21] = "2S_4"; + layerdisk[21] = 8; + phimin[21] = -0.0676705; + phimax[21] = 0.765802; + dtcname[22] = "2S_5"; + layerdisk[22] = 6; + phimin[22] = -0.0648206; + phimax[22] = 0.762952; + dtcname[23] = "2S_5"; + layerdisk[23] = 9; + phimin[23] = -0.0676705; + phimax[23] = 0.765802; + dtcname[24] = "2S_6"; + layerdisk[24] = 7; + phimin[24] = -0.0648206; + phimax[24] = 0.762952; + dtcname[25] = "2S_6"; + layerdisk[25] = 10; + phimin[25] = -0.0676705; + phimax[25] = 0.765802; + dtcname[26] = "negPS10G_1"; + layerdisk[26] = 0; + phimin[26] = -0.023281; + phimax[26] = 0.372347; + dtcname[27] = "negPS10G_1"; + layerdisk[27] = 6; + phimin[27] = -0.185672; + phimax[27] = 0.883803; + dtcname[28] = "negPS10G_1"; + layerdisk[28] = 8; + phimin[28] = -0.132414; + phimax[28] = 0.830545; + dtcname[29] = "negPS10G_1"; + layerdisk[29] = 10; + phimin[29] = -0.132414; + phimax[29] = 0.830545; + dtcname[30] = "negPS10G_2"; + layerdisk[30] = 0; + phimin[30] = -0.0133719; + phimax[30] = 0.715599; + dtcname[31] = "negPS10G_2"; + layerdisk[31] = 7; + phimin[31] = -0.110089; + phimax[31] = 0.808221; + dtcname[32] = "negPS10G_2"; + layerdisk[32] = 9; + phimin[32] = -0.132414; + phimax[32] = 0.830545; + dtcname[33] = "negPS10G_3"; + layerdisk[33] = 1; + phimin[33] = -0.115834; + phimax[33] = 0.813823; + dtcname[34] = "negPS10G_3"; + layerdisk[34] = 7; + phimin[34] = -0.185672; + phimax[34] = 0.883803; + dtcname[35] = "negPS10G_4"; + layerdisk[35] = 6; + phimin[35] = -0.0823971; + phimax[35] = 0.780529; + dtcname[36] = "negPS10G_4"; + layerdisk[36] = 8; + phimin[36] = -0.0963091; + phimax[36] = 0.794441; + dtcname[37] = "negPS10G_4"; + layerdisk[37] = 10; + phimin[37] = -0.0963091; + phimax[37] = 0.794441; + dtcname[38] = "negPS_1"; + layerdisk[38] = 2; + phimin[38] = -0.0961318; + phimax[38] = 0.445198; + dtcname[39] = "negPS_1"; + layerdisk[39] = 7; + phimin[39] = -0.0823971; + phimax[39] = 0.780529; + dtcname[40] = "negPS_2"; + layerdisk[40] = 2; + phimin[40] = -0.0917521; + phimax[40] = 0.614191; + dtcname[41] = "negPS_2"; + layerdisk[41] = 9; + phimin[41] = -0.0963091; + phimax[41] = 0.794441; + dtcname[42] = "neg2S_1"; + layerdisk[42] = 3; + phimin[42] = -0.0246209; + phimax[42] = 0.763311; + dtcname[43] = "neg2S_1"; + layerdisk[43] = 4; + phimin[43] = 0.261875; + phimax[43] = 0.403311; + dtcname[44] = "neg2S_2"; + layerdisk[44] = 4; + phimin[44] = -0.0542445; + phimax[44] = 0.715509; + dtcname[45] = "neg2S_3"; + layerdisk[45] = 5; + phimin[45] = 0.0410126; + phimax[45] = 0.730605; + dtcname[46] = "neg2S_4"; + layerdisk[46] = 5; + phimin[46] = -0.0428961; + phimax[46] = 0.693862; + dtcname[47] = "neg2S_4"; + layerdisk[47] = 8; + phimin[47] = -0.06767; + phimax[47] = 0.765802; + dtcname[48] = "neg2S_5"; + layerdisk[48] = 6; + phimin[48] = -0.0648201; + phimax[48] = 0.762952; + dtcname[49] = "neg2S_5"; + layerdisk[49] = 9; + phimin[49] = -0.06767; + phimax[49] = 0.765802; + dtcname[50] = "neg2S_6"; + layerdisk[50] = 7; + phimin[50] = -0.0648201; + phimax[50] = 0.762952; + dtcname[51] = "neg2S_6"; + layerdisk[51] = 10; + phimin[51] = -0.06767; + phimax[51] = 0.765802; + + double dphi = 0.5 * dphisectorHG_ - M_PI / NSector_; + + string olddtc = ""; + for (unsigned int i = 0; i < 52; i++) { + if (olddtc != dtcname[i]) { + modules << "InputRouter: IR_" << dtcname[i] << "_A" << std::endl; + modules << "InputRouter: IR_" << dtcname[i] << "_B" << std::endl; + memories << "DTCLink: DL_" << dtcname[i] << "_A [36]" << std::endl; + memories << "DTCLink: DL_" << dtcname[i] << "_B [36]" << std::endl; + os << "DL_" << dtcname[i] << "_A" + << " input=> output=> IR_" << dtcname[i] << "_A.stubin" << std::endl; + os << "DL_" << dtcname[i] << "_B" + << " input=> output=> IR_" << dtcname[i] << "_B.stubin" << std::endl; + } + olddtc = dtcname[i]; + } + + for (unsigned int i = 0; i < 52; i++) { + double phimintmp = phimin[i] + dphi; + double phimaxtmp = phimax[i] + dphi; + + for (unsigned int iReg = 0; iReg < NRegions_[layerdisk[i]]; iReg++) { + if (allStubs_[layerdisk[i]][iReg].first > phimaxtmp && allStubs_[layerdisk[i]][iReg].second < phimintmp) + continue; + + if (allStubs_[layerdisk[i]][iReg].second < phimaxtmp) { + memories << "InputLink: IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_A" + << " [36]" << std::endl; + os << "IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_A" + << " input=> IR_" << dtcname[i] << "_A.stubout output=> VMR_" << LayerName(layerdisk[i]) << "PHI" + << iTCStr(iReg) << ".stubin" << std::endl; + } + + if (allStubs_[layerdisk[i]][iReg].first > phimintmp) { + memories << "InputLink: IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_B" + << " [36]" << std::endl; + os << "IL_" << LayerName(layerdisk[i]) << "PHI" << iTCStr(iReg) << "_" << dtcname[i] << "_B" + << " input=> IR_" << dtcname[i] << "_B.stubout output=> VMR_" << LayerName(layerdisk[i]) << "PHI" + << iTCStr(iReg) << ".stubin" << std::endl; + } + } + } +} + +void TrackletConfigBuilder::writeAll(std::ostream& wires, std::ostream& memories, std::ostream& modules) { + writeILMemories(wires, memories, modules); + writeASMemories(wires, memories, modules); + writeVMSMemories(wires, memories, modules); + writeSPMemories(wires, memories, modules); + writeSPDMemories(wires, memories, modules); + writeProjectionMemories(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 index 3119888246b09..42f5d49cc2947 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngine.cc @@ -13,8 +13,8 @@ using namespace trklet; using namespace std; -TrackletEngine::TrackletEngine(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { +TrackletEngine::TrackletEngine(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) { stubpairs_ = nullptr; innervmstubs_ = nullptr; outervmstubs_ = nullptr; @@ -122,8 +122,11 @@ void TrackletEngine::execute() { if (!(pttableinner_[ptinnerindex] && pttableouter_[ptouterindex])) { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " - << benddecode(innervmstub.bend().value(), innervmstub.isPSmodule()) << " " - << benddecode(outervmstub.bend().value(), outervmstub.isPSmodule()); + << settings_.benddecode( + innervmstub.bend().value(), layerdisk1_, innervmstub.isPSmodule()) + << " " + << settings_.benddecode( + outervmstub.bend().value(), layerdisk2_, outervmstub.isPSmodule()); } continue; } @@ -212,13 +215,13 @@ void TrackletEngine::setVMPhiBin() { } else { rinner = settings_.rmean(layerdisk1_); } - double rinv1 = rinv(phiinner[i1], phiouter[i2], rinner, router[i3]); + double rinv1 = -rinv(phiinner[i1], phiouter[i2], rinner, router[i3]); double pitchinner = (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); double pitchouter = (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double abendinner = -bend(rinner, rinv1, pitchinner); - double abendouter = -bend(router[i3], rinv1, pitchouter); + double abendinner = bendstrip(rinner, rinv1, pitchinner); + double abendouter = bendstrip(router[i3], rinv1, pitchouter); if (abendinner < bendinnermin) bendinnermin = abendinner; if (abendinner > bendinnermax) @@ -237,20 +240,20 @@ void TrackletEngine::setVMPhiBin() { bool passptcut = rinvmin < settings_.rinvcutte(); for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { - double bend = benddecode(ibend, nbendbitsinner == 3); + double bend = settings_.benddecode(ibend, layerdisk1_, nbendbitsinner == 3); - bool passinner = bend - bendinnermin > -settings_.bendcutte(0, iSeed_) && - bend - bendinnermax < settings_.bendcutte(0, iSeed_); + bool passinner = bend > bendinnermin - settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3) && + bend < bendinnermax + settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3); if (passinner) vmbendinner[ibend] = true; pttableinner_.push_back(passinner && passptcut); } for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { - double bend = benddecode(ibend, nbendbitsouter == 3); + double bend = settings_.benddecode(ibend, layerdisk2_, nbendbitsouter == 3); - bool passouter = bend - bendoutermin > -settings_.bendcutte(1, iSeed_) && - bend - bendoutermax < settings_.bendcutte(1, iSeed_); + bool passouter = bend > bendoutermin - settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3) && + bend < bendoutermax + settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3); if (passouter) vmbendouter[ibend] = true; pttableouter_.push_back(passouter && passptcut); @@ -262,22 +265,12 @@ void TrackletEngine::setVMPhiBin() { innervmstubs_->setbendtable(vmbendinner); outervmstubs_->setbendtable(vmbendouter); - if (iSector_ == 0 && settings_.writeTable()) + if (settings_.writeTable()) writeTETable(); } void TrackletEngine::writeTETable() { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - const string fnameI = settings_.tablePath() + getName() + "_stubptinnercut.tab"; - ofstream outstubptinnercut(fnameI); - if (outstubptinnercut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fnameI; + ofstream outstubptinnercut = openfile(settings_.tablePath(), getName() + "_stubptinnercut.tab", __FILE__, __LINE__); outstubptinnercut << "{" << endl; for (unsigned int i = 0; i < pttableinner_.size(); i++) { @@ -288,10 +281,7 @@ void TrackletEngine::writeTETable() { outstubptinnercut << endl << "};" << endl; outstubptinnercut.close(); - const string fnameO = settings_.tablePath() + getName() + "_stubptoutercut.tab"; - ofstream outstubptoutercut(fnameO); - if (outstubptoutercut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fnameI; + ofstream outstubptoutercut = openfile(settings_.tablePath(), getName() + "_stubptoutercut.tab", __FILE__, __LINE__); outstubptoutercut << "{" << endl; for (unsigned int i = 0; i < pttableouter_.size(); i++) { diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc index 201b0b9b99723..927cd2b43505a 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngineDisplaced.cc @@ -12,11 +12,8 @@ using namespace std; using namespace trklet; -TrackletEngineDisplaced::TrackletEngineDisplaced(string name, - Settings const& settings, - Globals* global, - unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { +TrackletEngineDisplaced::TrackletEngineDisplaced(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global) { stubpairs_.clear(); firstvmstubs_.clear(); secondvmstubs_ = nullptr; @@ -174,21 +171,24 @@ void TrackletEngineDisplaced::execute() { 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 : " - << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()); + 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; + + //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()) || - (index < table_.size() && table_.at(index).count(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_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); @@ -254,9 +254,10 @@ void TrackletEngineDisplaced::execute() { 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 : " - << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()); + 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; } @@ -268,7 +269,7 @@ void TrackletEngineDisplaced::execute() { (index < table_.size() && table_.at(index).count(isp))) { if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); @@ -281,7 +282,7 @@ void TrackletEngineDisplaced::execute() { } else if (disk1_ == 1 && disk2_ == 2) { if (settings_.debugTracklet()) - edm::LogVerbatim("Tracklet") << getName() << "[" << iSector_ << "] Disk-disk pair"; + edm::LogVerbatim("Tracklet") << getName() << " Disk-disk pair"; int lookupbits = firstvmstub.vmbits().value() & 511; bool negdisk = firstvmstub.stub()->disk().value() < 0; @@ -334,9 +335,10 @@ void TrackletEngineDisplaced::execute() { 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 : " - << benddecode(firstvmstub.bend().value(), firstvmstub.isPSmodule()) << " " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()); + 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; } @@ -349,7 +351,7 @@ void TrackletEngineDisplaced::execute() { (index < table_.size() && table_.at(index).count(isp))) { if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubpairs_.at(isp)->addStubPair(firstvmstub, secondvmstub, index, getName()); @@ -412,7 +414,7 @@ void TrackletEngineDisplaced::readTables() { fin.close(); } -const short TrackletEngineDisplaced::memNameToIndex(const string& name) { +short TrackletEngineDisplaced::memNameToIndex(const string& name) { for (unsigned int isp = 0; isp < stubpairs_.size(); ++isp) if (stubpairs_.at(isp)->getName() == name) return isp; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc index 10bc49cad08a9..291d47b7ad5cc 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEngineUnit.cc @@ -7,6 +7,7 @@ using namespace trklet; TrackletEngineUnit::TrackletEngineUnit(const Settings* const settings, unsigned int nbitsfinephi, + unsigned int layerdisk1, unsigned int layerdisk2, unsigned int iSeed, unsigned int nbitsfinephidiff, @@ -14,10 +15,11 @@ TrackletEngineUnit::TrackletEngineUnit(const Settings* const settings, std::vector const& pttableinner, std::vector const& pttableouter, VMStubsTEMemory* outervmstubs) - : settings_(settings), candpairs_(5) { + : settings_(settings), candpairs_(3) { idle_ = true; nbitsfinephi_ = nbitsfinephi; layerdisk2_ = layerdisk2; + layerdisk1_ = layerdisk1; iSeed_ = iSeed; nbitsfinephidiff_ = nbitsfinephidiff; iAllStub_ = iAllStub; @@ -31,18 +33,31 @@ void TrackletEngineUnit::init(const TEData& tedata) { nreg_ = 0; istub_ = 0; idle_ = false; - assert(!tedata_.regions_.empty()); + assert(tedata_.regions_.size() > 0); std::tie(next_, ireg_, nstub_) = tedata_.regions_[0]; } void TrackletEngineUnit::reset() { idle_ = true; + goodpair_ = false; + goodpair__ = false; candpairs_.reset(); } -void TrackletEngineUnit::step() { - if (candpairs_.full()) +void TrackletEngineUnit::step(bool, int, int) { + + if (goodpair__) { + candpairs_.store(candpair__); + } + + goodpair__ = goodpair_; + candpair__ = candpair_; + + goodpair_ = false; + + if (idle_ || nearfull_) { return; + } int ibin = tedata_.start_ + next_; @@ -61,9 +76,10 @@ void TrackletEngineUnit::step() { int outerfinephi = iAllStub_ * (1 << (nbitsfinephi_ - settings_->nbitsallstubs(layerdisk2_))) + ireg_ * (1 << settings_->nfinephi(1, iSeed_)) + iphiouterbin.value(); int idphi = outerfinephi - tedata_.innerfinephi_; + bool inrange = (idphi < (1 << (nbitsfinephidiff_ - 1))) && (idphi >= -(1 << (nbitsfinephidiff_ - 1))); - if (idphi < 0) - idphi = idphi + (1 << nbitsfinephidiff_); + + idphi = idphi & ((1 << nbitsfinephidiff_) - 1); unsigned int firstDiskSeed = 4; if (iSeed_ >= firstDiskSeed) { //Also use r-position @@ -75,6 +91,7 @@ void TrackletEngineUnit::step() { if (next_ != 0) rzbin += (1 << NFINERZBITS); + if ((rzbin < tedata_.rzbinfirst_) || (rzbin - tedata_.rzbinfirst_ > tedata_.rzdiffmax_)) { if (settings_->debugTracklet()) { edm::LogVerbatim("Tracklet") << " layer-disk stub pair rejected because rbin cut : " << rzbin << " " @@ -89,14 +106,19 @@ void TrackletEngineUnit::step() { if (!(inrange && pttableinner_[ptinnerindex] && pttableouter_[ptouterindex])) { if (settings_->debugTracklet()) { edm::LogVerbatim("Tracklet") << " Stub pair rejected because of stub pt cut bends : " - << benddecode(tedata_.innerbend_.value(), tedata_.stub_->isPSmodule()) << " " - << benddecode(outerbend.value(), outervmstub.isPSmodule()); + << settings_->benddecode( + tedata_.innerbend_.value(), layerdisk1_, tedata_.stub_->isPSmodule()) + << " " + << settings_->benddecode(outerbend.value(), layerdisk2_, outervmstub.isPSmodule()); } } else { - candpairs_.store(pair(tedata_.stub_, outervmstub.stub())); + candpair_ = pair(tedata_.stub_, outervmstub.stub()); + goodpair_ = true; } } + istub_++; + assert(nstub_ <= N_VMSTUBSMAX); if (istub_ >= nstub_) { istub_ = 0; nreg_++; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc index 77dc376c1e9e0..19286102bbaf3 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletEventProcessor.cc @@ -1,11 +1,12 @@ #include "L1Trigger/TrackFindingTracklet/interface/TrackletEventProcessor.h" +#include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" #include "L1Trigger/TrackFindingTracklet/interface/SLHCEvent.h" #include "L1Trigger/TrackFindingTracklet/interface/Sector.h" #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/Cabling.h" #include "DataFormats/Math/interface/deltaPhi.h" @@ -41,6 +42,12 @@ void TrackletEventProcessor::init(Settings const& theSettings) { 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" @@ -71,21 +78,47 @@ void TrackletEventProcessor::init(Settings const& theSettings) { globals_->histograms() = histbase_; } - // create the sector processors (1 sector processor = 1 board) - sectors_.resize(N_SECTOR); + sector_ = make_unique(*settings_, globals_.get()); + + if (settings_->extended()) { + ifstream inmem(settings_->memoryModulesFile().c_str()); + assert(inmem.good()); + + ifstream inproc(settings_->processingModulesFile().c_str()); + assert(inproc.good()); + + ifstream inwire(settings_->wiresFile().c_str()); + assert(inwire.good()); + + configure(inwire, inmem, inproc); + + } else { + TrackletConfigBuilder config(*settings_); + + //Write configurations to file. + if (settings_->writeConfig()) { + std::ofstream wires = openfile(settings_->tablePath(), "wires.dat", __FILE__, __LINE__); + std::ofstream memorymodules = openfile(settings_->tablePath(), "memorymodules.dat", __FILE__, __LINE__); + std::ofstream processingmodules = openfile(settings_->tablePath(), "processingmodules.dat", __FILE__, __LINE__); + + config.writeAll(wires, memorymodules, processingmodules); + } - for (unsigned int i = 0; i < N_SECTOR; i++) { - sectors_[i] = make_unique(i, *settings_, globals_.get()); + std::stringstream wires; + std::stringstream memorymodules; + std::stringstream processingmodules; + + config.writeAll(wires, memorymodules, processingmodules); + configure(wires, memorymodules, processingmodules); } +} +void TrackletEventProcessor::configure(istream& inwire, istream& inmem, istream& inproc) { // get the memory modules if (settings_->debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Will read memory modules file"; + edm::LogVerbatim("Tracklet") << "Will read memory modules"; } - ifstream inmem(settings_->memoryModulesFile().c_str()); - assert(inmem.good()); - while (inmem.good()) { string memType, memName, size; inmem >> memType >> memName >> size; @@ -94,19 +127,14 @@ void TrackletEventProcessor::init(Settings const& theSettings) { if (settings_->writetrace()) { edm::LogVerbatim("Tracklet") << "Read memory: " << memType << " " << memName; } - for (auto& sector : sectors_) { - sector->addMem(memType, memName); - } + sector_->addMem(memType, memName); } // get the processing modules if (settings_->debugTracklet()) { - edm::LogVerbatim("Tracklet") << "Will read processing modules file"; + edm::LogVerbatim("Tracklet") << "Will read processing modules"; } - ifstream inproc(settings_->processingModulesFile().c_str()); - assert(inproc.good()); - while (inproc.good()) { string procType, procName; inproc >> procType >> procName; @@ -115,9 +143,7 @@ void TrackletEventProcessor::init(Settings const& theSettings) { if (settings_->writetrace()) { edm::LogVerbatim("Tracklet") << "Read process: " << procType << " " << procName; } - for (auto& sector : sectors_) { - sector->addProc(procType, procName); - } + sector_->addProc(procType, procName); } // get the wiring information @@ -125,9 +151,6 @@ void TrackletEventProcessor::init(Settings const& theSettings) { edm::LogVerbatim("Tracklet") << "Will read wiring information"; } - ifstream inwire(settings_->wiresFile().c_str()); - assert(inwire.good()); - while (inwire.good()) { string line; getline(inwire, line); @@ -146,29 +169,8 @@ void TrackletEventProcessor::init(Settings const& theSettings) { ss >> tmp2 >> procout; } - for (auto& sector : sectors_) { - sector->addWire(mem, procin, procout); - } - } - - // get the DTC/cabling information - ifstream indtc(settings_->DTCLinkLayerDiskFile()); - assert(indtc.good()); - string dtc; - indtc >> dtc; - while (indtc.good()) { - vector tmp; - dtclayerdisk_[dtc] = tmp; - int layerdisk; - indtc >> layerdisk; - while (layerdisk > 0) { - dtclayerdisk_[dtc].push_back(layerdisk); - indtc >> layerdisk; - } - indtc >> dtc; + sector_->addWire(mem, procin, procout); } - - cabling_ = make_unique(settings_->DTCLinkFile(), settings_->moduleCablingFile(), *settings_); } void TrackletEventProcessor::event(SLHCEvent& ev) { @@ -179,323 +181,207 @@ void TrackletEventProcessor::event(SLHCEvent& ev) { eventnum_++; bool first = (eventnum_ == 1); - cleanTimer_.start(); for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->clean(); - } - cleanTimer_.stop(); - - addStubTimer_.start(); + sector_->setSector(k); - for (int j = 0; j < ev.nstubs(); j++) { - L1TStub stub = ev.stub(j); + cleanTimer_.start(); + sector_->clean(); + cleanTimer_.stop(); - int layer = stub.layer() + 1; - int ladder = stub.ladder(); - int module = stub.module(); + addStubTimer_.start(); - string dtc = cabling_->dtc(layer, ladder, module); - string dtcbase = dtc.substr(2, dtc.size() - 2); - if (dtc[0] == 'n') { - dtcbase = dtc.substr(0, 4) + dtc.substr(6, dtc.size() - 6); - } + vector layerstubs(N_LAYER + N_DISK, 0); + vector layerstubssector(N_SECTOR * (N_LAYER + N_DISK), 0); - cabling_->addphi(dtc, stub.phi(), layer, module); + for (int j = 0; j < ev.nstubs(); j++) { + L1TStub stub = ev.stub(j); + unsigned int isector = stub.region(); + if (isector != k) { + continue; + } - double phi = angle0to2pi::make0To2pi(stub.phi() + 0.5 * settings_->dphisectorHG()); + string dtc = stub.DTClink(); - unsigned int isector = N_SECTOR * phi / (2 * M_PI); + layerstubs[stub.layerdisk()]++; + layerstubssector[isector * (N_LAYER + N_DISK) + stub.layerdisk()]++; - for (unsigned int k = 0; k < N_SECTOR; k++) { - int diff = k - isector; - if (diff > (int)N_SECTOR / 2) - diff -= (int)N_SECTOR; - if (diff < (-1) * (int)N_SECTOR / 2) - diff += (int)N_SECTOR; - if (abs(diff) > 1) - continue; - double phiminsect = - k * 2 * M_PI / N_SECTOR - 0.5 * (settings_->dphisectorHG() - 2 * M_PI / N_SECTOR) - M_PI / N_SECTOR; - double dphi = stub.phi() - phiminsect; - if (dphi > M_PI) - dphi -= 2 * M_PI; - while (dphi < 0.0) - dphi += 2 * M_PI; - if (dphi > settings_->dphisectorHG()) - continue; - bool add = sectors_[k]->addStub(stub, dtcbase); - - static std::map dtcstubs; - - if (settings_->writeMem()) { - vector dtcs = cabling_->DTCs(); - for (const auto& dtc : dtcs) { - string dtcbase = dtc.substr(2, dtc.size() - 2); - if (dtc[0] == 'n') { - dtcbase = dtc.substr(0, 4) + dtc.substr(6, dtc.size() - 6); - } - - const string dirIS = settings_->memPath() + "InputStubs/"; - string fname = dirIS + "Link_"; - fname += dtcbase; - if (dtcstubs.find(dtcbase + "A") != dtcstubs.end()) - continue; - fname += "_A.dat"; - - if (not std::filesystem::exists(dirIS)) { - int fail = system((string("mkdir -p ") + dirIS).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirIS; - } - - ofstream* out = new ofstream; - out->open(fname); - if (out->fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - dtcstubs[dtcbase + "A"] = out; - - fname = dirIS + "Link_"; - fname += dtcbase; - if (dtcstubs.find(dtcbase + "B") != dtcstubs.end()) - continue; - fname += "_B.dat"; - out = new ofstream; - out->open(fname); - if (out->fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - dtcstubs[dtcbase + "B"] = out; - } + sector_->addStub(stub, dtc); + } - static int oldevent = -1; - if (eventnum_ != oldevent) { - oldevent = eventnum_; - for (auto& dtcstub : dtcstubs) { - FPGAWord tmp; - tmp.set(eventnum_ % 8, 3); - (*(dtcstub.second)) << "BX " << tmp.str() << " Event : " << eventnum_ + 1 << endl; - } - } + if (settings_->writeMonitorData("StubsLayerSector")) { + for (unsigned int index = 0; index < layerstubssector.size(); index++) { + int layerdisk = index % (N_LAYER + N_DISK); + int sector = index / (N_LAYER + N_DISK); + globals_->ofstream("stubslayersector.txt") + << layerdisk << " " << sector << " " << layerstubssector[index] << endl; } + } - if (add && settings_->writeMem() && k == settings_->writememsect()) { - Stub fpgastub(stub, *settings_, sectors_[k]->phimin(), sectors_[k]->phimax()); - FPGAWord phi = fpgastub.phi(); - int topbit = phi.value() >> (phi.nbits() - 1); - std::vector tmp = dtclayerdisk_[dtcbase]; - int layerdisk = stub.layer() + 1; - if (layerdisk > 999) { - layerdisk = 10 + abs(stub.disk()); - } - int layerdiskcode = -1; - for (unsigned int i = 0; i < tmp.size(); i++) { - if (tmp[i] == layerdisk) - layerdiskcode = i; - } - if (layerdiskcode == -1) { - edm::LogVerbatim("Tracklet") << "dtcbase layerdisk layer disk : " << dtcbase << " " << layerdisk << " " - << stub.layer() + 1 << " " << stub.disk(); - } - assert(layerdiskcode >= 0); - assert(layerdiskcode < 4); - FPGAWord ldcode; - ldcode.set(layerdiskcode, 2); - string dataword = fpgastub.str() + "|" + ldcode.str() + "|1"; - if (topbit == 0) { - (*dtcstubs[dtcbase + "A"]) << dataword << " " << trklet::hexFormat(dataword) << endl; - } else { - (*dtcstubs[dtcbase + "B"]) << dataword << " " << trklet::hexFormat(dataword) << endl; - } + if (settings_->writeMonitorData("StubsLayer")) { + for (unsigned int layerdisk = 0; layerdisk < layerstubs.size(); layerdisk++) { + globals_->ofstream("stubslayer.txt") << layerdisk << " " << layerstubs[layerdisk] << endl; } } - } - addStubTimer_.stop(); + addStubTimer_.stop(); - // ---------------------------------------------------------------------------------------- - // Now start the tracklet processing + // ---------------------------------------------------------------------------------------- + // Now start the tracklet processing - // VM router - VMRouterTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeVMR(); + // VM router + InputRouterTimer_.start(); + sector_->executeIR(); if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeInputStubs(first); - sectors_[k]->writeVMSTE(first); - sectors_[k]->writeVMSME(first); - sectors_[k]->writeAS(first); + sector_->writeDTCStubs(first); + sector_->writeIRStubs(first); } - } - VMRouterTimer_.stop(); + InputRouterTimer_.stop(); - // tracklet engine - TETimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTE(); - } - TETimer_.stop(); + VMRouterTimer_.start(); + sector_->executeVMR(); + if (settings_->writeMem() && k == settings_->writememsect()) { + sector_->writeVMSTE(first); + sector_->writeVMSME(first); + sector_->writeAS(first); + sector_->writeAIS(first); + } + VMRouterTimer_.stop(); - // tracklet engine displaced - TEDTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTED(); - } - TEDTimer_.stop(); + // tracklet engine + TETimer_.start(); + sector_->executeTE(); + TETimer_.stop(); - // triplet engine - TRETimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTRE(); + // tracklet engine displaced + TEDTimer_.start(); + sector_->executeTED(); + TEDTimer_.stop(); + + // triplet engine + TRETimer_.start(); + sector_->executeTRE(); if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeST(first); + sector_->writeST(first); } - } - TRETimer_.stop(); + TRETimer_.stop(); - // tracklet processor (alternative implementation to TE+TC) - TPTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTP(); - } - TPTimer_.stop(); + // tracklet processor (alternative implementation to TE+TC) + TPTimer_.start(); + sector_->executeTP(); + TPTimer_.stop(); - for (unsigned int k = 0; k < N_SECTOR; k++) { if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeSP(first); + sector_->writeSP(first); } - } - // tracklet calculator - TCTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTC(); - } - TCTimer_.stop(); + // tracklet calculator + TCTimer_.start(); + sector_->executeTC(); + TCTimer_.stop(); - int nTP = globals_->event()->nsimtracks(); - for (int iTP = 0; iTP < nTP; iTP++) { - L1SimTrack simtrk = globals_->event()->simtrack(iTP); - if (simtrk.pt() < 2.0) - continue; - if (std::abs(simtrk.vz()) > 15.0) - continue; - if (hypot(simtrk.vx(), simtrk.vy()) > 0.1) - continue; - bool electron = (abs(simtrk.type()) == 11); - bool muon = (abs(simtrk.type()) == 13); - bool pion = (abs(simtrk.type()) == 211); - bool kaon = (abs(simtrk.type()) == 321); - bool proton = (abs(simtrk.type()) == 2212); - if (!(electron || muon || pion || kaon || proton)) - continue; - int nlayers = 0; - int ndisks = 0; - int simtrackid = simtrk.trackid(); - unsigned int hitmask = ev.layersHit(simtrackid, nlayers, ndisks); - if (nlayers + ndisks < 4) - continue; + int nTP = globals_->event()->nsimtracks(); + for (int iTP = 0; iTP < nTP; iTP++) { + L1SimTrack simtrk = globals_->event()->simtrack(iTP); + if (simtrk.pt() < 2.0) + continue; + if (std::abs(simtrk.vz()) > 15.0) + continue; + if (hypot(simtrk.vx(), simtrk.vy()) > 0.1) + continue; + bool electron = (abs(simtrk.type()) == 11); + bool muon = (abs(simtrk.type()) == 13); + bool pion = (abs(simtrk.type()) == 211); + bool kaon = (abs(simtrk.type()) == 321); + bool proton = (abs(simtrk.type()) == 2212); + if (!(electron || muon || pion || kaon || proton)) + continue; + int nlayers = 0; + int ndisks = 0; + int simtrackid = simtrk.trackid(); + unsigned int hitmask = ev.layersHit(simtrackid, nlayers, ndisks); + if (nlayers + ndisks < 4) + continue; - if (settings_->writeMonitorData("HitEff")) { - static ofstream outhit("hiteff.txt"); - outhit << simtrk.eta() << " " << (hitmask & 1) << " " << (hitmask & 2) << " " << (hitmask & 4) << " " - << (hitmask & 8) << " " << (hitmask & 16) << " " << (hitmask & 32) << " " << (hitmask & 64) << " " - << (hitmask & 128) << " " << (hitmask & 256) << " " << (hitmask & 512) << " " << (hitmask & 1024) << endl; - } + if (settings_->writeMonitorData("HitEff")) { + static ofstream outhit("hiteff.txt"); + outhit << simtrk.eta() << " " << (hitmask & 1) << " " << (hitmask & 2) << " " << (hitmask & 4) << " " + << (hitmask & 8) << " " << (hitmask & 16) << " " << (hitmask & 32) << " " << (hitmask & 64) << " " + << (hitmask & 128) << " " << (hitmask & 256) << " " << (hitmask & 512) << " " << (hitmask & 1024) + << endl; + } - std::unordered_set matchseed; - for (unsigned int k = 0; k < N_SECTOR; k++) { - std::unordered_set matchseedtmp = sectors_[k]->seedMatch(iTP); + std::unordered_set matchseed; + std::unordered_set matchseedtmp = sector_->seedMatch(iTP); matchseed.insert(matchseedtmp.begin(), matchseedtmp.end()); - } - if (settings_->bookHistos()) { - for (int iseed = 0; iseed < 8; iseed++) { - bool eff = matchseed.find(iseed) != matchseed.end(); - globals_->histograms()->fillSeedEff(iseed, simtrk.eta(), eff); + if (settings_->bookHistos()) { + for (int iseed = 0; iseed < 8; iseed++) { + bool eff = matchseed.find(iseed) != matchseed.end(); + globals_->histograms()->fillSeedEff(iseed, simtrk.eta(), eff); + } } } - } - // tracklet calculator displaced - TCDTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeTCD(); - } - TCDTimer_.stop(); + // tracklet calculator displaced + TCDTimer_.start(); + sector_->executeTCD(); + TCDTimer_.stop(); - for (unsigned int k = 0; k < N_SECTOR; k++) { if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeTPAR(first); - sectors_[k]->writeTPROJ(first); + sector_->writeTPAR(first); + sector_->writeTPROJ(first); } - } - // projection router - PRTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executePR(); + // projection router + PRTimer_.start(); + sector_->executePR(); if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeVMPROJ(first); - sectors_[k]->writeAP(first); + sector_->writeVMPROJ(first); + sector_->writeAP(first); } - } - PRTimer_.stop(); + PRTimer_.stop(); - // match engine - METimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeME(); + // match engine + METimer_.start(); + sector_->executeME(); if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeCM(first); + sector_->writeCM(first); } - } - METimer_.stop(); + METimer_.stop(); - // match calculator - MCTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeMC(); - } - MCTimer_.stop(); + // match calculator + MCTimer_.start(); + sector_->executeMC(); + MCTimer_.stop(); - // match processor (alternative to ME+MC) - MPTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeMP(); - } - MPTimer_.stop(); + // match processor (alternative to ME+MC) + MPTimer_.start(); + sector_->executeMP(); + MPTimer_.stop(); - for (unsigned int k = 0; k < N_SECTOR; k++) { if (settings_->writeMem() && k == settings_->writememsect()) { - sectors_[k]->writeMC(first); + sector_->writeMC(first); } - } - // fit track - FTTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executeFT(); + // fit track + FTTimer_.start(); + sector_->executeFT(); if ((settings_->writeMem() || settings_->writeMonitorData("IFit")) && k == settings_->writememsect()) { - sectors_[k]->writeTF(first); + sector_->writeTF(first); } - } - FTTimer_.stop(); + FTTimer_.stop(); - // purge duplicate - PDTimer_.start(); - for (unsigned int k = 0; k < N_SECTOR; k++) { - sectors_[k]->executePD(tracks_); + // purge duplicate + PDTimer_.start(); + sector_->executePD(tracks_); if (((settings_->writeMem() || settings_->writeMonitorData("IFit")) && k == settings_->writememsect()) || settings_->writeMonitorData("CT")) { - sectors_[k]->writeCT(first); + sector_->writeCT(first); } + PDTimer_.stop(); } - PDTimer_.stop(); } void TrackletEventProcessor::printSummary() { - if (settings_->writeMonitorData("Cabling")) { - cabling_->writephirange(); - } - if (settings_->bookHistos()) { globals_->histograms()->close(); } @@ -508,6 +394,9 @@ void TrackletEventProcessor::printSummary() { << "Add Stubs " << setw(10) << addStubTimer_.ntimes() << setw(20) << setprecision(3) << addStubTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << addStubTimer_.tottime() << "\n" + << "InputRouter " << setw(10) << InputRouterTimer_.ntimes() << setw(20) + << setprecision(3) << InputRouterTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << InputRouterTimer_.tottime() << "\n" << "VMRouter " << setw(10) << VMRouterTimer_.ntimes() << setw(20) << setprecision(3) << VMRouterTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << VMRouterTimer_.tottime(); @@ -519,23 +408,32 @@ void TrackletEventProcessor::printSummary() { << 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() << "\n" - << "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" - << "TrackletCalculator " << setw(10) << TCTimer_.ntimes() << setw(20) << setprecision(3) - << TCTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TCTimer_.tottime() << "\n" - << "TrackletCalculatorDisplaced" << setw(10) << TCDTimer_.ntimes() << setw(20) << setprecision(3) - << TCDTimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) << TCDTimer_.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") << "TrackletEngine " << setw(10) << TETimer_.ntimes() << setw(20) + << setprecision(3) << TETimer_.avgtime() * 1000.0 << setw(20) << setprecision(3) + << TETimer_.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(); + } + 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) diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc index dbba44f2b361a..7667f26038a97 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletParametersMemory.cc @@ -8,8 +8,8 @@ using namespace std; using namespace trklet; -TrackletParametersMemory::TrackletParametersMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) {} +TrackletParametersMemory::TrackletParametersMemory(string name, Settings const& settings) + : MemoryBase(name, settings) {} void TrackletParametersMemory::clean() { for (auto& tracklet : tracklets_) { @@ -18,23 +18,8 @@ void TrackletParametersMemory::clean() { tracklets_.clear(); } -void TrackletParametersMemory::writeMatches(Globals* globals, int& matchesL1, int& matchesL3, int& matchesL5) { - ofstream& out = globals->ofstream("nmatches.txt"); - for (auto& tracklet : tracklets_) { - if ((tracklet->nMatches() + tracklet->nMatchesDisk()) > 0) { - if (tracklet->layer() == 1) - matchesL1++; - if (tracklet->layer() == 3) - matchesL3++; - if (tracklet->layer() == 5) - matchesL5++; - } - out << tracklet->layer() << " " << tracklet->disk() << " " << tracklet->nMatches() << " " - << tracklet->nMatchesDisk() << endl; - } -} - -void TrackletParametersMemory::writeTPAR(bool first) { +void TrackletParametersMemory::writeTPAR(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirTP = settings_.memPath() + "TrackletParameters/"; std::ostringstream oss; @@ -42,21 +27,7 @@ void TrackletParametersMemory::writeTPAR(bool first) { << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirTP)) { - int fail = system((string("mkdir -p ") + dirTP).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirTP; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirTP, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc index de95f8c19bedf..ee937c120033f 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProcessor.cc @@ -1,8 +1,8 @@ - #include "L1Trigger/TrackFindingTracklet/interface/TrackletProcessor.h" #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" #include "L1Trigger/TrackFindingTracklet/interface/Globals.h" #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" @@ -16,8 +16,10 @@ using namespace std; using namespace trklet; -TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Globals* globals, unsigned int iSector) - : TrackletCalculatorBase(name, settings, globals, iSector), vmrtable_(settings) { +TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Globals* globals) + : TrackletCalculatorBase(name, settings, globals), + tebuffer_(CircularBuffer(3), 0, 0, 0, 0), + vmrtable_(settings) { iAllStub_ = -1; for (unsigned int ilayer = 0; ilayer < N_LAYER; ilayer++) { @@ -37,9 +39,9 @@ TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Glob nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk1_); nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk1_); - vmrtable_.init(layerdisk1_, getName()); + vmrtable_.init(layerdisk1_); - nbitsrzbin_ = NFINERZBITS; + nbitsrzbin_ = N_RZBITS; if (iSeed_ == 4 || iSeed_ == 5) nbitsrzbin_ = 2; @@ -52,6 +54,8 @@ TrackletProcessor::TrackletProcessor(string name, Settings const& settings, Glob TCIndex_ = (iSeed_ << 4) + iTC_; assert(TCIndex_ >= 0 && TCIndex_ <= (int)settings_.ntrackletmax()); + + maxStep_ = settings_.maxStep("TP"); } void TrackletProcessor::addOutputProjection(TrackletProjectionsMemory*& outputProj, MemoryBase* memory) { @@ -128,6 +132,7 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { TrackletEngineUnit teunit(&settings_, nbitsfinephi_, + layerdisk1_, layerdisk2_, iSeed_, nbitsfinephidiff_, @@ -135,13 +140,14 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { pttableinnernew_, pttableouternew_, outervmstubs_); - teunits_.resize(6, teunit); + + teunits_.resize(settings_.teunits(iSeed_), teunit); return; } if (input == "innerallstubin") { - auto* tmp = dynamic_cast(memory); + auto* tmp = dynamic_cast(memory); assert(tmp != nullptr); if (innerallstubs_.size() == 2) { //FIXME this should be done with better logic with reading the input stubs innerallstubs_.insert(innerallstubs_.begin(), tmp); @@ -150,13 +156,8 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { } //FIXME should be done once after all inputs are added - tedatabuffers_.clear(); - CircularBuffer tedatabuffertmp(5); - tedatabuffertmp.reset(); - - tedatabuffers_.emplace_back(tedatabuffertmp, 0, 0, 0, (innerallstubs_.size() + 1) / 2); - tedatabuffers_.emplace_back( - tedatabuffertmp, 0, (innerallstubs_.size() + 1) / 2, (innerallstubs_.size() + 1) / 2, innerallstubs_.size()); + tebuffer_ = tuple, unsigned int, unsigned int, unsigned int, unsigned int>( + CircularBuffer(3), 0, 0, 0, innerallstubs_.size()); return; } @@ -169,10 +170,20 @@ void TrackletProcessor::addInput(MemoryBase* memory, string input) { throw cms::Exception("BadConfig") << __FILE__ << " " << __LINE__ << " Could not find input : " << input; } -void TrackletProcessor::execute() { +void TrackletProcessor::execute(unsigned int iSector, double phimin, double phimax) { + bool print = (iSector == 3) && (getName() == "TP_L1L2D"); + print = false; + + phimin_ = phimin; + phimax_ = phimax; + iSector_ = iSector; + if (!settings_.useSeed(iSeed_)) return; + //Not most elegant solution; but works + int donecount = 0; + //Consistency checks assert(iAllStub_ >= 0); assert(iAllStub_ < (int)settings_.nallstubs(layerdisk2_)); @@ -191,152 +202,58 @@ void TrackletProcessor::execute() { //Actual implemenation starts here - //Reset the tebuffers - for (auto& tebuffer : tedatabuffers_) { - std::get<0>(tebuffer).reset(); - std::get<1>(tebuffer) = 0; - std::get<2>(tebuffer) = std::get<3>(tebuffer); - } + //Reset the tebuffer + std::get<0>(tebuffer_).reset(); + std::get<1>(tebuffer_) = 0; + std::get<2>(tebuffer_) = std::get<3>(tebuffer_); //Reset the teunits for (auto& teunit : teunits_) { teunit.reset(); } - for (unsigned int istep = 0; istep < settings_.maxStep("TP"); istep++) { - for (auto& tebuffer : tedatabuffers_) { - CircularBuffer& tedatabuffer = std::get<0>(tebuffer); - unsigned int& istub = std::get<1>(tebuffer); - unsigned int& imem = std::get<2>(tebuffer); - unsigned int imemend = std::get<4>(tebuffer); - - if ((!tedatabuffer.full()) && imem < imemend && istub < innerallstubs_[imem]->nStubs()) { - ninnerstubs++; - - const Stub* stub = innerallstubs_[imem]->getStub(istub); - - bool negdisk = (stub->disk().value() < 0); //FIXME stub needs to contain bit for +/- z disk - - FPGAWord phicorr = stub->phicorr(); - int innerfinephi = phicorr.bits(phicorr.nbits() - nbitsfinephi_, nbitsfinephi_); - FPGAWord innerbend = stub->bend(); - - //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 (layerdisk1_ > (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 - indexr = (((1 << (stub->r().nbits() - 1)) + stub->r().value()) >> (stub->r().nbits() - nbitsrfinebintable_)); - } - - int lutval = -1; - if (iSeed_ < 6) { //FIXME should only be one table... - lutval = vmrtable_.lookupinner(indexz, indexr); - } else { - lutval = vmrtable_.lookupinneroverlap(indexz, indexr); - } - - if (lutval != -1) { - unsigned int lutwidth = settings_.lutwidthtab(0, iSeed_); - FPGAWord lookupbits(lutval, lutwidth, true, __LINE__, __FILE__); - - int rzfinebinfirst = lookupbits.bits(0, 3); //finephi - int next = lookupbits.bits(3, 1); //next r/z bin - int start = lookupbits.bits(4, nbitsrzbin_); - int rzdiffmax = lookupbits.bits(lookupbits.nbits() - 3, 3); - - if ((iSeed_ == 4 || iSeed_ == 5) && negdisk) { //TODO - need to store negative disk - start += 4; - } - int last = start + next; - - int nbins = 8; - - unsigned int useregindex = (innerfinephi << innerbend.nbits()) + innerbend.value(); - if (iSeed_ >= 4) { - //FIXME If the lookupbits were rationally organized this would be much simpler - int ir = ((start & 3) << 1) + (rzfinebinfirst >> 2); - useregindex = (useregindex << 3) + ir; - } - - assert(useregindex < useregion_.size()); - vector usereg = useregion_[useregindex]; - - TEData tedata; - tedata.stub_ = stub; - tedata.rzbinfirst_ = rzfinebinfirst; - tedata.start_ = start; - tedata.innerfinephi_ = innerfinephi; - tedata.rzdiffmax_ = rzdiffmax; - tedata.innerbend_ = innerbend; - - for (unsigned int ireg = 0; ireg < settings_.nvmte(1, iSeed_); ireg++) { - assert(ireg < usereg.size()); - if (!usereg[ireg]) - continue; - - for (int ibin = start; ibin <= last; ibin++) { - if (settings_.debugTracklet()) { - edm::LogVerbatim("Tracklet") << getName() << " looking for matching stub in bin " << ibin << " with " - << outervmstubs_->nVMStubsBinned(ireg * nbins + ibin) << " stubs"; - } - assert(ireg * nbins + ibin < outervmstubs_->nBin()); - int nstubs = outervmstubs_->nVMStubsBinned(ireg * nbins + ibin); - if (nstubs > 0) { - tedata.regions_.emplace_back(tuple(ibin - start, ireg, nstubs)); - countteall += nstubs; - } - } - } - - if (!tedata.regions_.empty()) { - ntedata++; - //cout << getName() << " adding TE data" << endl; - tedatabuffer.store(tedata); - } - } - istub++; - if (istub >= innerallstubs_[imem]->nStubs()) { - istub = 0; - imem++; - } + TEData tedata; + TEData tedata__; + TEData tedata___; + bool goodtedata = false; + bool goodtedata__ = false; + bool goodtedata___ = false; + + bool tebuffernearfull; + + for (unsigned int istep = 0; istep < maxStep_; istep++) { + if (print) { + CircularBuffer& tedatabuffer = std::get<0>(tebuffer_); + unsigned int& istub = std::get<1>(tebuffer_); + unsigned int& imem = std::get<2>(tebuffer_); + cout << "istep=" << istep << " TEBuffer: " << istub << " " << imem << " " << tedatabuffer.rptr() << " " + << tedatabuffer.wptr(); + int k = -1; + for (auto& teunit : teunits_) { + k++; + cout << " [" << k << " " << teunit.rptr() << " " << teunit.wptr() << " " << teunit.idle() << "]"; } + cout << endl; } - bool tedatabuffersdone = true; - for (auto& tebuffer : tedatabuffers_) { - CircularBuffer& tedatabuffer = std::get<0>(tebuffer); - tedatabuffersdone &= tedatabuffer.empty(); //buffer empty - tedatabuffersdone &= (std::get<2>(tebuffer) == std::get<4>(tebuffer)); //buffer processed all stubs - if (!tedatabuffer.empty()) { - for (auto& teunit : teunits_) { - if (teunit.empty() && teunit.idle()) { - teunit.init(tedatabuffer.read()); - break; - } - } - } - } + CircularBuffer& tedatabuffer = std::get<0>(tebuffer_); + tebuffernearfull = tedatabuffer.nearfull(); + + // + // First block here checks if there is a teunit with data that should should be used + // to calculate the tracklet parameters + // - bool teunitsdone = true; TrackletEngineUnit* teunitptr = nullptr; + + int iTE = 0; + int icount = -1; for (auto& teunit : teunits_) { - if (!teunit.idle()) { - teunit.step(); - teunitsdone = false; - } + teunit.setNearFull(); + icount++; if (!teunit.empty()) { teunitptr = &teunit; - teunitsdone = false; + iTE = icount; } } @@ -362,6 +279,8 @@ void TrackletProcessor::execute() { bool accept = false; if (iSeed_ < 4) { + if (print) + cout << "istep=" << istep << " TEUnit read iTE=" << iTE << endl; accept = barrelSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); } else if (iSeed_ < 6) { accept = diskSeeding(innerFPGAStub, innerStub, outerFPGAStub, outerStub); @@ -374,6 +293,7 @@ void TrackletProcessor::execute() { if (trackletpars_->nTracklets() >= settings_.ntrackletmax()) { edm::LogVerbatim("Tracklet") << "Will break on number of tracklets in " << getName(); + assert(0); break; } @@ -382,43 +302,198 @@ void TrackletProcessor::execute() { } } - if (settings_.writeMonitorData("TP")) { - globals_->ofstream("trackletprocessor.txt") << getName() << " " << ninnerstubs //# inner stubs - << " " << outervmstubs_->nVMStubs() //# outer stubs - << " " << countteall //# pairs tried in TE - << " " << stubpairs //# stubs pairs - << " " << countsel //# tracklets found - << endl; + // + // The second block fills the teunit if data in buffer and process TEUnit step + // + // + + bool notemptytebuffer = !tedatabuffer.empty(); + + int ite = -1; + for (auto& teunit : teunits_) { + ite++; + if (teunit.idle()) { + if (notemptytebuffer) { + teunit.init(std::get<0>(tebuffer_).read()); + if (print) + std::cout << "istep=" << istep << " TEUnit init iTE inner : " << ite << " " + << teunit.innerStub()->allStubIndex().value() << std::endl; + notemptytebuffer = false; //prevent initialzing another TE unit + } + } + teunit.step(print, istep, ite); } - if (teunitsdone && tedatabuffersdone) { + // + // The third block here checks if we have input stubs to process + // + // + + if (goodtedata___) + tedatabuffer.store(tedata___); + + goodtedata = false; + + unsigned int& istub = std::get<1>(tebuffer_); + unsigned int& imem = std::get<2>(tebuffer_); + unsigned int imemend = std::get<4>(tebuffer_); + + if ((!tebuffernearfull) && imem < imemend && istub < innerallstubs_[imem]->nStubs()) { + ninnerstubs++; + + const Stub* stub = innerallstubs_[imem]->getStub(istub); + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " Have stub in " << innerallstubs_[imem]->getName(); + } + + bool negdisk = (stub->disk().value() < 0); //FIXME stub needs to contain bit for +/- z disk + + FPGAWord phicorr = stub->phicorr(); + int innerfinephi = phicorr.bits(phicorr.nbits() - nbitsfinephi_, nbitsfinephi_); + FPGAWord innerbend = stub->bend(); + + //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 (layerdisk1_ > (N_LAYER - 1)) { + if (negdisk) { + indexz = ((1 << nbitszfinebintable_) - 1) - indexz; + } + indexr = stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_); + } else { //Take the top nbitsfinebintable_ bits of the z coordinate + indexr = (stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_)) & ((1 << nbitsrfinebintable_) - 1); + } + + int lutval = -1; + if (iSeed_ < 6) { //FIXME should only be one table - but will need coordination with HLS code. + lutval = vmrtable_.lookupinner(indexz, indexr); + } else { + lutval = vmrtable_.lookupinneroverlap(indexz, indexr); + } + + if (lutval != -1) { + unsigned int lutwidth = settings_.lutwidthtab(0, iSeed_); + FPGAWord lookupbits(lutval, lutwidth, true, __LINE__, __FILE__); + + int rzfinebinfirst = lookupbits.bits(0, NFINERZBITS); //finerz + int next = lookupbits.bits(NFINERZBITS, 1); //use next r/z bin + int start = lookupbits.bits(NFINERZBITS + 1, nbitsrzbin_); //rz bin + int rzdiffmax = lookupbits.bits(NFINERZBITS + 1 + nbitsrzbin_, NFINERZBITS); + + if ((iSeed_ == 4 || iSeed_ == 5) && negdisk) { //TODO - need to store negative disk + start += (1 << nbitsrzbin_); + } + int last = start + next; + + int nbins = (1 << N_RZBITS); + + unsigned int useregindex = (innerfinephi << innerbend.nbits()) + innerbend.value(); + if (iSeed_ >= 4) { + //FIXME If the lookupbits were rationally organized this would be much simpler + unsigned int nrbits = 3; + int ir = ((start & ((1 << (nrbits - 1)) - 1)) << 1) + (rzfinebinfirst >> (NFINERZBITS - 1)); + useregindex = (useregindex << nrbits) + ir; + } + + assert(useregindex < useregion_.size()); + unsigned int usereg = useregion_[useregindex]; + + tedata.regions_.clear(); + tedata.stub_ = stub; + tedata.rzbinfirst_ = rzfinebinfirst; + tedata.start_ = start; + tedata.innerfinephi_ = innerfinephi; + tedata.rzdiffmax_ = rzdiffmax; + tedata.innerbend_ = innerbend; + + std::string mask = ""; + + for (int ibin = start; ibin <= last; ibin++) { + for (unsigned int ireg = 0; ireg < settings_.nvmte(1, iSeed_); ireg++) { + if (!(usereg & (1 << ireg))) { + mask = "0" + mask; + continue; + } + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " looking for matching stub in bin " << ibin << " with " + << outervmstubs_->nVMStubsBinned(ireg * nbins + ibin) << " stubs"; + } + assert(ireg * nbins + ibin < outervmstubs_->nBin()); + int nstubs = outervmstubs_->nVMStubsBinned(ireg * nbins + ibin); + + if (print) + cout << "Add to TEBuffer stub ibin ireg nstubs: " << stub->allStubIndex().value() << " " << ibin << " " + << ireg << " " << nstubs << endl; + + if (nstubs > 0) { + mask = "1" + mask; + tedata.regions_.emplace_back(tuple(ibin - start, ireg, nstubs)); + countteall += nstubs; + } else { + mask = "0" + mask; + } + } + } + + if (tedata.regions_.size() > 0) { + ntedata++; + goodtedata = true; + } + } + istub++; + if (istub >= innerallstubs_[imem]->nStubs()) { + istub = 0; + imem++; + } + } else if ((!tebuffernearfull) && imem < imemend && istub == 0) { + imem++; + } + + goodtedata___ = goodtedata__; + goodtedata__ = goodtedata; + + tedata___ = tedata__; + tedata__ = tedata; + + // + // stop looping over istep if done + // + + bool done = true; + + if (imem < imemend || (!tedatabuffer.empty())) { + done = false; + } + + for (auto& teunit : teunits_) { + if (!(teunit.idle() && teunit.empty())) + done = false; + } + + if (done) { + donecount++; + } + + //FIXME This should be done cleaner... Not too hard, but need to check fully the TEBuffer and TEUnit buffer. + if (donecount > 4) { break; } } -} -void TrackletProcessor::writeTETable() { - ofstream outstubptinnercut; - outstubptinnercut.open(getName() + "_stubptinnercut.tab"); - outstubptinnercut << "{" << endl; - // the below is outcommented as the writing of these tables are currently not implemented, to be adressed - //for(unsigned int i=0;iofstream("trackletprocessor.txt") << getName() << " " << ninnerstubs //# inner stubs + << " " << outervmstubs_->nVMStubs() //# outer stubs + << " " << countteall //# pairs tried in TE + << " " << stubpairs //# stubs pairs + << " " << countsel //# tracklets found + << endl; + } } void TrackletProcessor::buildLUT() { @@ -437,7 +512,8 @@ void TrackletProcessor::buildLUT() { if (iSeed_ > 5) { if (iSeed_ == 6) { rmax = settings_.rmaxdiskl1overlapvm(); - } else if (iSeed_ == 7) { + } + if (iSeed_ == 7) { rmax = settings_.rmaxdiskvm(); } rmin = settings_.rmean(layerdisk1_); @@ -508,12 +584,12 @@ void TrackletProcessor::buildLUT() { } else { rinner = settings_.rmean(layerdisk1_); } - double rinv1 = rinv(0.0, dphi[i2], rinner, router[i3]); + double rinv1 = rinv(0.0, -dphi[i2], rinner, router[i3]); double pitchinner = (rinner < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); double pitchouter = (router[i3] < settings_.rcrit()) ? settings_.stripPitch(true) : settings_.stripPitch(false); - double abendinner = -bend(rinner, rinv1, pitchinner); - double abendouter = -bend(router[i3], rinv1, pitchouter); + double abendinner = bendstrip(rinner, rinv1, pitchinner); + double abendouter = bendstrip(router[i3], rinv1, pitchouter); if (abendinner < bendinnermin) bendinnermin = abendinner; if (abendinner > bendinnermax) @@ -531,18 +607,18 @@ void TrackletProcessor::buildLUT() { bool passptcut = rinvmin < settings_.rinvcutte(); for (int ibend = 0; ibend < (1 << nbendbitsinner); ibend++) { - double bend = benddecode(ibend, nbendbitsinner == 3); + double bend = settings_.benddecode(ibend, layerdisk1_, nbendbitsinner == 3); - bool passinner = bend - bendinnermin > -settings_.bendcutte(0, iSeed_) && - bend - bendinnermax < settings_.bendcutte(0, iSeed_); + bool passinner = bend <= bendinnermax + settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3) && + bend >= bendinnermin - settings_.bendcutte(ibend, layerdisk1_, nbendbitsinner == 3); pttableinnernew_.push_back(passinner && passptcut); } for (int ibend = 0; ibend < (1 << nbendbitsouter); ibend++) { - double bend = benddecode(ibend, nbendbitsouter == 3); + double bend = settings_.benddecode(ibend, layerdisk2_, nbendbitsouter == 3); - bool passouter = bend - bendoutermin > -settings_.bendcutte(1, iSeed_) && - bend - bendoutermax < settings_.bendcutte(1, iSeed_); + bool passouter = bend <= bendoutermax + settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3) && + bend >= bendoutermin - settings_.bendcutte(ibend, layerdisk2_, nbendbitsouter == 3); pttableouternew_.push_back(passouter && passptcut); } } @@ -558,7 +634,7 @@ void TrackletProcessor::buildLUT() { for (int innerbend = 0; innerbend < (1 << nbendbitsinner); innerbend++) { for (int ir = 0; ir < (1 << nirbits); ir++) { int nreg = 0; - vector usereg; + unsigned int usereg = 0; for (unsigned int ireg = 0; ireg < settings_.nvmte(1, iSeed_); ireg++) { bool match = false; for (int ifinephiouter = 0; ifinephiouter < (1 << settings_.nfinephi(1, iSeed_)); ifinephiouter++) { @@ -576,7 +652,9 @@ void TrackletProcessor::buildLUT() { } if (match && ir < 3) nreg++; - usereg.push_back(match); + if (match) { + usereg = usereg | (1 << ireg); + } } useregion_.push_back(usereg); @@ -585,4 +663,41 @@ void TrackletProcessor::buildLUT() { } } } + + if (settings_.writeTable()) { + ofstream out; + out.open(settings_.tablePath() + getName() + "_usereg.tab"); + + out << "{" << endl; + for (unsigned int i = 0; i < useregion_.size(); i++) { + if (i != 0) { + out << "," << endl; + } + out << useregion_[i]; + } + out << endl << "};" << endl; + out.close(); + + ofstream outstubptinnercut; + outstubptinnercut.open(settings_.tablePath() + getName() + "_stubptinnercut.tab"); + outstubptinnercut << "{" << endl; + for (unsigned int i = 0; i < pttableinnernew_.size(); i++) { + if (i != 0) + outstubptinnercut << "," << endl; + outstubptinnercut << pttableinnernew_[i]; + } + outstubptinnercut << endl << "};" << endl; + outstubptinnercut.close(); + + ofstream outstubptoutercut; + outstubptoutercut.open(settings_.tablePath() + getName() + "_stubptoutercut.tab"); + outstubptoutercut << "{" << endl; + for (unsigned int i = 0; i < pttableouternew_.size(); i++) { + if (i != 0) + outstubptoutercut << "," << endl; + outstubptoutercut << pttableouternew_[i]; + } + outstubptoutercut << endl << "};" << endl; + outstubptoutercut.close(); + } } diff --git a/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc index 50080813e2438..b1861fdc64dab 100644 --- a/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/TrackletProjectionsMemory.cc @@ -7,8 +7,8 @@ using namespace std; using namespace trklet; -TrackletProjectionsMemory::TrackletProjectionsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +TrackletProjectionsMemory::TrackletProjectionsMemory(string name, Settings const& settings) + : MemoryBase(name, settings) { size_t pos = find_nth(name, 0, "_", 1); assert(pos != string::npos); initLayerDisk(pos + 1, layer_, disk_); @@ -16,11 +16,11 @@ TrackletProjectionsMemory::TrackletProjectionsMemory(string name, Settings const void TrackletProjectionsMemory::addProj(Tracklet* tracklet) { if (layer_ != 0 && disk_ == 0) - assert(tracklet->validProj(layer_)); + assert(tracklet->validProj(layer_ - 1)); if (layer_ == 0 && disk_ != 0) - assert(tracklet->validProjDisk(disk_)); + assert(tracklet->validProj(N_LAYER + abs(disk_) - 1)); if (layer_ != 0 && disk_ != 0) - assert(tracklet->validProj(layer_) || tracklet->validProjDisk(disk_)); + assert(tracklet->validProj(layer_ - 1) || tracklet->validProj(N_LAYER + abs(disk_) - 1)); for (auto& itracklet : tracklets_) { if (itracklet == tracklet) { @@ -34,31 +34,22 @@ void TrackletProjectionsMemory::addProj(Tracklet* tracklet) { void TrackletProjectionsMemory::clean() { tracklets_.clear(); } -void TrackletProjectionsMemory::writeTPROJ(bool first) { +void TrackletProjectionsMemory::writeTPROJ(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirTP = settings_.memPath() + "TrackletProjections/"; - if (not std::filesystem::exists(dirTP)) { - int fail = system((string("mkdir -p ") + dirTP).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirTP; - } std::ostringstream oss; oss << dirTP << "TrackletProjections_" << getName() << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - out_.open(fname); - } else - out_.open(fname, std::ofstream::app); + 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]->validProj(layer_)) ? tracklets_[j]->trackletprojstrlayer(layer_) - : tracklets_[j]->trackletprojstrdisk(disk_); + string proj = (layer_ > 0 && tracklets_[j]->validProj(layer_ - 1)) ? tracklets_[j]->trackletprojstrlayer(layer_) + : tracklets_[j]->trackletprojstrdisk(disk_); out_ << "0x"; out_ << std::setfill('0') << std::setw(2); out_ << hex << j << dec; diff --git a/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc b/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc index a7ef1821f3273..e08cd039b9e24 100644 --- a/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc +++ b/L1Trigger/TrackFindingTracklet/src/TripletEngine.cc @@ -10,8 +10,8 @@ using namespace std; using namespace trklet; -TripletEngine::TripletEngine(string name, Settings const &settings, Globals *global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector) { +TripletEngine::TripletEngine(string name, Settings const &settings, Globals *global) + : ProcessBase(name, settings, global) { stubpairs_.clear(); thirdvmstubs_.clear(); layer1_ = 0; @@ -207,10 +207,13 @@ void TripletEngine::execute() { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()) << " " - << benddecode(thirdvmstub.bend().value(), thirdvmstub.isPSmodule()); + << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule()) + << " " << settings_.benddecode(thirdvmstub.bend().value(), layer3_ - 1, thirdvmstub.isPSmodule()); } - continue; + + //FIXME temporarily commented out until bend table fixed + //if (!settings_.writeTripletTables()) + // continue; } if (settings_.writeTripletTables()) { if (index >= table_.size()) @@ -230,7 +233,7 @@ void TripletEngine::execute() { edm::LogVerbatim("Tracklet") << "Adding layer-layer pair in " << getName(); if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubtriplets_->addStubs(thirdvmstub.stub(), @@ -290,8 +293,8 @@ void TripletEngine::execute() { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "Stub triplet rejected because of stub pt cut bends : " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()) << " " - << benddecode(thirdvmstub.bend().value(), thirdvmstub.isPSmodule()); + << settings_.benddecode(secondvmstub.bend().value(), disk2_ + 5, secondvmstub.isPSmodule()) << " " + << settings_.benddecode(thirdvmstub.bend().value(), layer3_ - 1, thirdvmstub.isPSmodule()); } continue; } @@ -313,7 +316,7 @@ void TripletEngine::execute() { edm::LogVerbatim("Tracklet") << "Adding layer-disk pair in " << getName(); if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubtriplets_->addStubs(thirdvmstub.stub(), @@ -374,8 +377,8 @@ void TripletEngine::execute() { if (settings_.debugTracklet()) { edm::LogVerbatim("Tracklet") << "Stub pair rejected because of stub pt cut bends : " - << benddecode(secondvmstub.bend().value(), secondvmstub.isPSmodule()) << " " - << benddecode(thirdvmstub.bend().value(), thirdvmstub.isPSmodule()); + << settings_.benddecode(secondvmstub.bend().value(), layer2_ - 1, secondvmstub.isPSmodule()) + << " " << settings_.benddecode(thirdvmstub.bend().value(), disk3_ + 5, thirdvmstub.isPSmodule()); } continue; } @@ -397,7 +400,7 @@ void TripletEngine::execute() { edm::LogVerbatim("Tracklet") << "Adding layer-disk pair in " << getName(); if (settings_.writeMonitorData("Seeds")) { ofstream fout("seeds.txt", ofstream::app); - fout << __FILE__ << ":" << __LINE__ << " " << name_ << "_" << iSector_ << " " << iSeed_ << endl; + fout << __FILE__ << ":" << __LINE__ << " " << name_ << " " << iSeed_ << endl; fout.close(); } stubtriplets_->addStubs(thirdvmstub.stub(), @@ -460,7 +463,7 @@ void TripletEngine::writeTables() { ofstream fout; stringstream tableName; - tableName << "table/table_" << name_ << "_" << iSector_ << ".txt"; + tableName << "table/table_" << name_ << ".txt"; fout.open(tableName.str(), ofstream::out); for (const auto &entry : table_) @@ -469,7 +472,7 @@ void TripletEngine::writeTables() { for (const auto &tedName : spTable_) { tableName.str(""); - tableName << "table/table_" << tedName.first << "_" << name_ << "_" << iSector_ << ".txt"; + tableName << "table/table_" << tedName.first << "_" << name_ << ".txt"; fout.open(tableName.str(), ofstream::out); for (const auto &entry : tedName.second) { diff --git a/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc index 9ff195063fb54..3541d9ce522f6 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMProjectionsMemory.cc @@ -7,8 +7,7 @@ using namespace std; using namespace trklet; -VMProjectionsMemory::VMProjectionsMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +VMProjectionsMemory::VMProjectionsMemory(string name, Settings const& settings) : MemoryBase(name, settings) { initLayerDisk(7, layer_, disk_); } @@ -21,7 +20,8 @@ void VMProjectionsMemory::addTracklet(Tracklet* tracklet, unsigned int allprojin tracklets_.push_back(tmp); } -void VMProjectionsMemory::writeVMPROJ(bool first) { +void VMProjectionsMemory::writeVMPROJ(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirVM = settings_.memPath() + "VMProjections/"; std::ostringstream oss; @@ -34,21 +34,7 @@ void VMProjectionsMemory::writeVMPROJ(bool first) { oss << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirVM)) { - int fail = system((string("mkdir -p ") + dirVM).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirVM; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirVM, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc index dd3015ea1e75f..484bd3ad549fe 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouter.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouter.cc @@ -13,8 +13,8 @@ using namespace std; using namespace trklet; -VMRouter::VMRouter(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector), vmrtable_(settings) { +VMRouter::VMRouter(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global), vmrtable_(settings) { layerdisk_ = initLayerDisk(4); vmstubsMEPHI_.resize(settings_.nvmme(layerdisk_), nullptr); @@ -22,7 +22,7 @@ VMRouter::VMRouter(string name, Settings const& settings, Globals* global, unsig overlapbits_ = 7; nextrabits_ = overlapbits_ - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)); - vmrtable_.init(layerdisk_, getName()); + vmrtable_.init(layerdisk_, name); nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk_); nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk_); @@ -136,7 +136,17 @@ void VMRouter::addInput(MemoryBase* memory, string input) { InputLinkMemory* tmp1 = dynamic_cast(memory); assert(tmp1 != nullptr); if (tmp1 != nullptr) { - stubinputs_.push_back(tmp1); + 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; } @@ -149,7 +159,7 @@ void VMRouter::execute() { //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 > 127) continue; @@ -235,10 +245,18 @@ void VMRouter::execute() { assert(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) { assert(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 diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc index f6ce34e3badc6..b2025b7d0067f 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouterCM.cc @@ -4,6 +4,7 @@ #include "L1Trigger/TrackFindingTracklet/interface/VMStubTE.h" #include "L1Trigger/TrackFindingTracklet/interface/InputLinkMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/AllStubsMemory.h" +#include "L1Trigger/TrackFindingTracklet/interface/AllInnerStubsMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubsMEMemory.h" #include "L1Trigger/TrackFindingTracklet/interface/VMStubsTEMemory.h" @@ -13,8 +14,8 @@ using namespace std; using namespace trklet; -VMRouterCM::VMRouterCM(string name, Settings const& settings, Globals* global, unsigned int iSector) - : ProcessBase(name, settings, global, iSector), vmrtable_(settings) { +VMRouterCM::VMRouterCM(string name, Settings const& settings, Globals* global) + : ProcessBase(name, settings, global), vmrtable_(settings) { layerdisk_ = initLayerDisk(4); vmstubsMEPHI_.resize(1, nullptr); @@ -22,7 +23,7 @@ VMRouterCM::VMRouterCM(string name, Settings const& settings, Globals* global, u overlapbits_ = 7; nextrabits_ = overlapbits_ - (settings_.nbitsallstubs(layerdisk_) + settings_.nbitsvmme(layerdisk_)); - vmrtable_.init(layerdisk_, getName()); + vmrtable_.init(layerdisk_); nbitszfinebintable_ = settings_.vmrlutzbits(layerdisk_); nbitsrfinebintable_ = settings_.vmrlutrbits(layerdisk_); @@ -36,14 +37,17 @@ void VMRouterCM::addOutput(MemoryBase* memory, string output) { << output; } + if (output == "allinnerstubout") { + AllInnerStubsMemory* tmp = dynamic_cast(memory); + assert(tmp != nullptr); + char memtype = memory->getName().back(); + allinnerstubs_.emplace_back(memtype, tmp); + return; + } + if (output.substr(0, 10) == "allstubout") { AllStubsMemory* tmp = dynamic_cast(memory); - assert(tmp != nullptr); - char memtype = 0; - if (output.size() > 10) { - memtype = output[11]; - } - allstubs_.emplace_back(memtype, tmp); + allstubs_.push_back(tmp); return; } @@ -139,16 +143,67 @@ void VMRouterCM::execute() { allStubCounter++; + for (auto& allstub : allstubs_) { + allstub->addStub(stub); + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << allstub->getName(); + } + } + FPGAWord iphi = stub->phicorr(); unsigned int iphipos = iphi.bits(iphi.nbits() - (settings_.nbitsallstubs(layerdisk_) + 3), 3); - //Fill allstubs memories - in HLS this is the same write to multiple memories - for (auto& allstub : allstubs_) { + unsigned int phicutmax = 4; + unsigned int phicutmin = 4; + + if (layerdisk_ != 0) { + phicutmax = 6; + phicutmin = 2; + } + + //Fill inner allstubs memories - in HLS this is the same write to multiple memories + for (auto& allstub : allinnerstubs_) { char memtype = allstub.first; - if ((memtype == 'R' && iphipos < 5) || (memtype == 'L' && iphipos >= 3) || (memtype == 'A' && iphipos < 4) || - (memtype == 'B' && iphipos >= 4) || (memtype == 'E' && iphipos >= 4) || (memtype == 'F' && iphipos < 4) || - (memtype == 'C' && iphipos >= 4) || (memtype == 'D' && iphipos < 4)) + if (memtype == 'R' && iphipos < phicutmax) + continue; + if (memtype == 'L' && iphipos >= phicutmin) + continue; + if (memtype == 'A' && iphipos < 4) + continue; + if (memtype == 'B' && iphipos >= 4) + continue; + if (memtype == 'E' && iphipos >= 4) continue; + if (memtype == 'F' && iphipos < 4) + continue; + if (memtype == 'C' && iphipos >= 4) + continue; + if (memtype == 'D' && iphipos < 4) + continue; + + int absz = std::abs(stub->z().value()); + if (layerdisk_ == 1 && absz < VMROUTERCUTZL2 / settings_.kz(layerdisk_)) + continue; + if ((layerdisk_ == 2 || layerdisk_ == 4) && absz > VMROUTERCUTZL1L3L5 / settings_.kz(layerdisk_)) + continue; + if ((layerdisk_ == 6 || layerdisk_ == 8) && stub->r().value() > VMROUTERCUTRD1D3 / settings_.kr()) + continue; + if ((layerdisk_ == 6 || layerdisk_ == 8) && stub->r().value() < 2 * int(N_DSS_MOD)) + continue; + if (layerdisk_ == 0) { + if (memtype == 'M' || memtype == 'R' || memtype == 'L') { + if (absz < VMROUTERCUTZL1 / settings_.kz(layerdisk_)) + continue; + } else { + if (absz > VMROUTERCUTZL1L3L5 / settings_.kz(layerdisk_)) + continue; + } + } + + if (settings_.debugTracklet()) { + edm::LogVerbatim("Tracklet") << getName() << " adding stub to " << allstub.second->getName(); + } + allstub.second->addStub(stub); } @@ -156,24 +211,15 @@ void VMRouterCM::execute() { 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 indexz = (stub->z().value() >> (stub->z().nbits() - nbitszfinebintable_)) & ((1 << nbitszfinebintable_) - 1); int indexr = -1; if (layerdisk_ > (N_LAYER - 1)) { if (negdisk) { - indexz = (1 << nbitszfinebintable_) - indexz; + indexz = ((1 << nbitszfinebintable_) - 1) - indexz; } indexr = stub->r().value(); if (stub->isPSmodule()) { @@ -181,7 +227,7 @@ void VMRouterCM::execute() { } } 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_)); + indexr = (stub->r().value() >> (stub->r().nbits() - nbitsrfinebintable_)) & ((1 << nbitsrfinebintable_) - 1); } assert(indexz >= 0); @@ -211,11 +257,8 @@ void VMRouterCM::execute() { allStubIndex); assert(vmstubsMEPHI_[0] != nullptr); - vmstubsMEPHI_[0]->addStub(vmstub, ivmPlus * nvmmebins_ + vmbin); - if (ivmMinus != ivmPlus) { - vmstubsMEPHI_[0]->addStub(vmstub, ivmMinus * nvmmebins_ + vmbin); - } + vmstubsMEPHI_[0]->addStub(vmstub, ivm * nvmmebins_ + vmbin); //Fill the TE VM memories if (layerdisk_ >= 6 && (!stub->isPSmodule())) @@ -231,9 +274,10 @@ void VMRouterCM::execute() { lutval = melut; } else { lutval = vmrtable_.lookupdisk(indexz, indexr); + if (lutval == 0) { + continue; + } } - if (lutval == -1) - continue; assert(lutval >= 0); diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc index 257843cd5c49b..84cb75dac4e14 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouterPhiCorrTable.cc @@ -33,25 +33,19 @@ void VMRouterPhiCorrTable::init(int layer, int bendbits, int rbits) { } if (settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - writeVMTable(settings_.tablePath() + "VMPhiCorrL" + std::to_string(layer_) + ".tab", false); + writeVMTable(settings_.tablePath(), "VMPhiCorrL" + std::to_string(layer_) + ".tab", false); } } int VMRouterPhiCorrTable::getphiCorrValue(int ibend, int irbin) const { - double bend = trklet::benddecode(ibend, layer_ <= (int)N_PSLAYER); + assert(layer_ > 0.0 && layer_ <= (int)N_LAYER); + double bend = -settings_.benddecode(ibend, layer_ - 1, layer_ <= (int)N_PSLAYER); //for the rbin - calculate the distance to the nominal layer radius double Delta = (irbin + 0.5) * dr_ - settings_.drmax(); //calculate the phi correction - this is a somewhat approximate formula - double dphi = (Delta / 0.18) * (bend * settings_.stripPitch(false)) / rmean_; + double dphi = (Delta / 0.18) * (bend * settings_.stripPitch(layer_ <= (int)N_PSLAYER)) / rmean_; int idphi = 0; diff --git a/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc b/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc index 3605f8aadbae0..1853a01f71f6b 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMRouterTable.cc @@ -1,6 +1,7 @@ // VMRouterTable: Lookup table used by the VMRouter to route stubs and provide information about which VMStubs are needed by the TrackletEngine #include "L1Trigger/TrackFindingTracklet/interface/VMRouterTable.h" #include "L1Trigger/TrackFindingTracklet/interface/Settings.h" +#include "L1Trigger/TrackFindingTracklet/interface/Util.h" #include #include @@ -43,6 +44,23 @@ void VMRouterTable::init(unsigned int layerdisk, std::string const& name) { double r = rmin_ + (irbin + 0.5) * dr_; double z = zmin_ + (izbin + 0.5) * dz_; + if (settings_.combined()) { + int iznew = izbin - (1 << (zbits_ - 1)); + if (iznew < 0) + iznew += (1 << zbits_); + assert(iznew >= 0); + assert(iznew < (1 << zbits_)); + z = zmin_ + (iznew + 0.5) * dz_; + if (layerdisk < N_LAYER) { + int irnew = irbin - (1 << (rbits_ - 1)); + if (irnew < 0) + irnew += (1 << rbits_); + assert(irnew >= 0); + assert(irnew < (1 << rbits_)); + r = rmin_ + (irnew + 0.5) * dr_; + } + } + if (layerdisk > (N_LAYER - 1) && irbin < 10) //special case for the tabulated radii in 2S disks r = (layerdisk <= 7) ? settings_.rDSSinner(irbin) : settings_.rDSSouter(irbin); @@ -63,10 +81,11 @@ void VMRouterTable::init(unsigned int layerdisk, std::string const& name) { if (layerdisk >= N_LAYER) { double rproj = r * settings_.zmean(layerdisk - N_LAYER) / z; bin = 0.5 * NBINS * (rproj - settings_.rmindiskvm()) / (settings_.rmaxdiskvm() - settings_.rmindiskvm()); + //bin value of zero indicates that stub is out of range if (bin < 0) bin = 0; if (bin >= NBINS / 2) - bin = NBINS / 2 - 1; + bin = 0; vmrtabletedisk_.push_back(bin); } @@ -101,39 +120,69 @@ void VMRouterTable::init(unsigned int layerdisk, std::string const& name) { } if (settings_.writeTable()) { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } + if (!settings_.combined()) { + // write finebin tables + writeVMTable(settings_.tablePath(), name + "_finebin.tab", vmrtable_); + // write barrel seed teinner tables (L1L2, L2L3, L3L4, L5L6) + if (layerdisk == 0 || layerdisk == 1 || layerdisk == 2 || layerdisk == 4) { + std::string fnamesuffix = "L" + to_string(layerdisk + 1) + "L" + std::to_string(layerdisk + 2); + writeVMTable(settings_.tablePath(), "VMTableInner" + fnamesuffix + ".tab", vmrtableteinner_); + } + // write disk seed teinner tables (D1D2, D3D4) + if (layerdisk == 6 || layerdisk == 8) { + std::string fnamesuffix = "D" + to_string(layerdisk - N_LAYER + 1) + "D" + to_string(layerdisk - N_LAYER + 2); + writeVMTable(settings_.tablePath(), "VMTableInner" + fnamesuffix + ".tab", vmrtableteinner_); + } + // write overlap seed teinner tables (L1D1, L2D1) + if (layerdisk == 0 || layerdisk == 1) { + std::string fnamesuffix = "L" + to_string(layerdisk + 1) + "D1"; + writeVMTable(settings_.tablePath(), "VMTableInner" + fnamesuffix + ".tab", vmrtableteinneroverlap_); + } + // write barrel teouter tables (L2, L3, L4, L6, same as finebin tables) + if (layerdisk == 1 || layerdisk == 2 || layerdisk == 3 || layerdisk == 5) { + std::string fnamesuffix = "L" + to_string(layerdisk + 1); + writeVMTable(settings_.tablePath(), "VMTableOuter" + fnamesuffix + ".tab", vmrtable_); + } + // write disk teouter tables (D1, D2, D4) + if (layerdisk == 6 || layerdisk == 7 || layerdisk == 9) { + std::string fnamesuffix = "D" + to_string(layerdisk - N_LAYER + 1); + writeVMTable(settings_.tablePath(), "VMTableOuter" + fnamesuffix + ".tab", vmrtabletedisk_); + } + } else { + std::string fname = "VMRME_"; + if (layerdisk < 6) { + fname += "L" + std::to_string(layerdisk + 1) + ".tab"; + } else { + fname += "D" + std::to_string(layerdisk - 5) + ".tab"; + } + writeVMTable(settings_.tablePath(), fname, vmrtable_); - // write finebin tables - writeVMTable(settings_.tablePath() + name + "_finebin.tab", vmrtable_); - // write barrel seed teinner tables (L1L2, L2L3, L3L4, L5L6) - if (layerdisk == 0 || layerdisk == 1 || layerdisk == 2 || layerdisk == 4) { - std::string fnamesuffix = "L" + to_string(layerdisk + 1) + "L" + std::to_string(layerdisk + 2); - writeVMTable(settings_.tablePath() + "VMTableInner" + fnamesuffix + ".tab", vmrtableteinner_); - } - // write disk seed teinner tables (D1D2, D3D4) - if (layerdisk == 6 || layerdisk == 8) { - std::string fnamesuffix = "D" + to_string(layerdisk - N_LAYER + 1) + "D" + to_string(layerdisk - N_LAYER + 2); - writeVMTable(settings_.tablePath() + "VMTableInner" + fnamesuffix + ".tab", vmrtableteinner_); - } - // write overlap seed teinner tables (L1D1, L2D1) - if (layerdisk == 0 || layerdisk == 1) { - std::string fnamesuffix = "L" + to_string(layerdisk + 1) + "D1"; - writeVMTable(settings_.tablePath() + "VMTableInner" + fnamesuffix + ".tab", vmrtableteinneroverlap_); - } - // write barrel teouter tables (L2, L3, L4, L6, same as finebin tables) - if (layerdisk == 1 || layerdisk == 2 || layerdisk == 3 || layerdisk == 5) { - std::string fnamesuffix = "L" + to_string(layerdisk + 1); - writeVMTable(settings_.tablePath() + "VMTableOuter" + fnamesuffix + ".tab", vmrtable_); - } - // write disk teouter tables (D1, D2, D4) - if (layerdisk == 6 || layerdisk == 7 || layerdisk == 9) { - std::string fnamesuffix = "D" + to_string(layerdisk - N_LAYER + 1); - writeVMTable(settings_.tablePath() + "VMTableOuter" + fnamesuffix + ".tab", vmrtabletedisk_); + if (layerdisk == 6 || layerdisk == 7 || layerdisk == 9) { + std::string fname = "VMRTE_D" + to_string(layerdisk - N_LAYER + 1) + ".tab"; + writeVMTable(settings_.tablePath(), fname, vmrtabletedisk_); + } + + if (vmrtableteinner_.size() > 0) { + ofstream out; + if (layerdisk < 6) { + out.open(settings_.tablePath() + "TP_L" + std::to_string(layerdisk + 1) + ".tab"); + } else { + out.open(settings_.tablePath() + "TP_D" + std::to_string(layerdisk - 5) + ".tab"); + } + out << "{" << endl; + for (unsigned int i = 0; i < vmrtableteinner_.size(); i++) { + if (i != 0) { + out << "," << endl; + } + if (vmrtableteinner_[i] == -1) { + out << 1023; + } else { + out << vmrtableteinner_[i]; + } + } + out << endl << "};" << endl; + out.close(); + } } } } @@ -325,10 +374,8 @@ int VMRouterTable::lookupinnerThird(int zbin, int rbin) { return vmrtableteinnerThird_[index]; } -void VMRouterTable::writeVMTable(std::string const& name, std::vector const& table) { - ofstream out(name); - if (out.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << name; +void VMRouterTable::writeVMTable(std::string const& dir, std::string const& name, std::vector const& table) { + ofstream out = openfile(dir, name, __FILE__, __LINE__); out << "{" << endl; for (unsigned int i = 0; i < table.size(); i++) { diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc index 275a73aca4213..9ac11723a6fcf 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsMEMemory.cc @@ -6,8 +6,7 @@ using namespace std; using namespace trklet; -VMStubsMEMemory::VMStubsMEMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +VMStubsMEMemory::VMStubsMEMemory(string name, Settings const& settings) : MemoryBase(name, settings) { unsigned int layerdisk = initLayerDisk(6); if (layerdisk < N_LAYER) { binnedstubs_.resize(settings_.NLONGVMBINS()); @@ -17,7 +16,8 @@ VMStubsMEMemory::VMStubsMEMemory(string name, Settings const& settings, unsigned } } -void VMStubsMEMemory::writeStubs(bool first) { +void VMStubsMEMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirVM = settings_.memPath() + "VMStubsME/"; std::ostringstream oss; @@ -30,21 +30,7 @@ void VMStubsMEMemory::writeStubs(bool first) { oss << "_" << std::setfill('0') << std::setw(2) << (iSector_ + 1) << ".dat"; auto const& fname = oss.str(); - if (first) { - bx_ = 0; - event_ = 1; - - if (not std::filesystem::exists(dirVM)) { - int fail = system((string("mkdir -p ") + dirVM).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " << dirVM; - } - out_.open(fname); - if (out_.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; - - } else - out_.open(fname, std::ofstream::app); + openfile(out_, first, dirVM, fname, __FILE__, __LINE__); out_ << "BX = " << (bitset<3>)bx_ << " Event : " << event_ << endl; @@ -53,6 +39,8 @@ void VMStubsMEMemory::writeStubs(bool first) { string stub = binnedstubs_[i][j].stubindex().str(); stub += "|" + binnedstubs_[i][j].bend().str(); + FPGAWord finephipos = binnedstubs_[i][j].finephi(); + stub += "|" + finephipos.str(); FPGAWord finepos = binnedstubs_[i][j].finerz(); stub += "|" + finepos.str(); out_ << hex << i << " " << j << dec << " " << stub << " " << trklet::hexFormat(stub) << endl; diff --git a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc index be05d40c9536a..47c70a825d5b4 100644 --- a/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc +++ b/L1Trigger/TrackFindingTracklet/src/VMStubsTEMemory.cc @@ -6,11 +6,12 @@ using namespace std; using namespace trklet; -VMStubsTEMemory::VMStubsTEMemory(string name, Settings const& settings, unsigned int iSector) - : MemoryBase(name, settings, iSector) { +VMStubsTEMemory::VMStubsTEMemory(string name, Settings const& settings) : MemoryBase(name, settings) { //set the layer or disk that the memory is in initLayerDisk(6, layer_, disk_); + layerdisk_ = initLayerDisk(6); + //Pointer to other VMStub memory for creating stub pairs other_ = nullptr; @@ -71,8 +72,10 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub, int bin) { if (negdisk) bin += 4; assert(bin < (int)stubsbinnedvm_.size()); - stubsbinnedvm_[bin].push_back(vmstub); - stubsvm_.push_back(vmstub); + if (stubsbinnedvm_[bin].size() < N_VMSTUBSMAX) { + stubsbinnedvm_[bin].push_back(vmstub); + stubsvm_.push_back(vmstub); + } return true; } @@ -81,7 +84,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub, int bin) { if (!pass) { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = " - << benddecode(vmstub.bend().value(), vmstub.isPSmodule()); + << settings_.benddecode(vmstub.bend().value(), layerdisk_, vmstub.isPSmodule()); return false; } @@ -103,7 +106,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub, int bin) { stubsbinnedvm_[bin].push_back(vmstub); } } else { - if (vmstub.stub()->isBarrel()) { + if (vmstub.stub()->layerdisk() < N_LAYER) { if (!isinner_) { if (stubsbinnedvm_[bin].size() >= settings_.maxStubsPerBin()) return false; @@ -143,7 +146,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub) { if (!pass) { if (settings_.debugTracklet()) edm::LogVerbatim("Tracklet") << getName() << " Stub failed bend cut. bend = " - << benddecode(vmstub.bend().value(), vmstub.isPSmodule()); + << settings_.benddecode(vmstub.bend().value(), layerdisk_, vmstub.isPSmodule()); return false; } @@ -162,7 +165,7 @@ bool VMStubsTEMemory::addVMStub(VMStubTE vmstub) { } } } else { - if (vmstub.stub()->isBarrel()) { + if (vmstub.stub()->layerdisk() < N_LAYER) { if (!isinner_) { stubsbinnedvm_[bin].push_back(vmstub); } @@ -214,7 +217,8 @@ void VMStubsTEMemory::clean() { } } -void VMStubsTEMemory::writeStubs(bool first) { +void VMStubsTEMemory::writeStubs(bool first, unsigned int iSector) { + iSector_ = iSector; const string dirVM = settings_.memPath() + "VMStubsTE/"; openFile(first, dirVM, "VMStubs_"); @@ -227,7 +231,7 @@ void VMStubsTEMemory::writeStubs(bool first) { out_ << " " << stub << " " << trklet::hexFormat(stub) << endl; } } else { // outer VM for TE purpose - for (unsigned int i = 0; i < settings_.NLONGVMBINS(); i++) { + for (unsigned int i = 0; i < stubsbinnedvm_.size(); i++) { for (unsigned int j = 0; j < stubsbinnedvm_[i].size(); j++) { string stub = stubsbinnedvm_[i][j].str(); out_ << hex << i << " " << j << dec << " " << stub << " " << trklet::hexFormat(stub) << endl; @@ -273,22 +277,12 @@ void VMStubsTEMemory::setbendtable(std::vector vmbendtable) { vmbendtable_[i] = vmbendtable[i]; } - if (iSector_ == 0 && settings_.writeTable()) + if (settings_.writeTable()) writeVMBendTable(); } void VMStubsTEMemory::writeVMBendTable() { - if (not std::filesystem::exists(settings_.tablePath())) { - int fail = system((string("mkdir -p ") + settings_.tablePath()).c_str()); - if (fail) - throw cms::Exception("BadDir") << __FILE__ << " " << __LINE__ << " could not create directory " - << settings_.tablePath(); - } - - const string fname = settings_.tablePath() + getName() + "_vmbendcut.tab"; - ofstream outvmbendcut(fname); - if (outvmbendcut.fail()) - throw cms::Exception("BadFile") << __FILE__ << " " << __LINE__ << " could not create file " << fname; + ofstream outvmbendcut = openfile(settings_.tablePath(), getName() + "_vmbendcut.tab", __FILE__, __LINE__); outvmbendcut << "{" << endl; unsigned int vmbendtableSize = vmbendtable_.size(); diff --git a/L1Trigger/TrackFindingTracklet/test/HybridTracks_cfg.py b/L1Trigger/TrackFindingTracklet/test/HybridTracks_cfg.py index 7b355253cc4e5..357f01cf38584 100644 --- a/L1Trigger/TrackFindingTracklet/test/HybridTracks_cfg.py +++ b/L1Trigger/TrackFindingTracklet/test/HybridTracks_cfg.py @@ -18,6 +18,11 @@ from Configuration.AlCa.GlobalTag import GlobalTag process.GlobalTag = GlobalTag(process.GlobalTag, 'auto:upgradePLS3', '') +############################################################ +# L1 tracking: remake stubs? +############################################################ +process.load('L1Trigger.TrackTrigger.TrackTrigger_cff') + # ---------------------------------------------------------------------------------- # input @@ -27,8 +32,6 @@ ) process.source = cms.Source("PoolSource", fileNames = Source_Files) - -# ---------------------------------------------------------------------------------- # L1 tracking => hybrid emulation process.load("L1Trigger.TrackFindingTracklet.L1HybridEmulationTracks_cff") @@ -44,6 +47,26 @@ #process.TTTracksEmulation = cms.Path(process.L1PromptExtendedHybridTracks) #process.TTTracksEmulationWithTruth = cms.Path(process.L1PromptExtendedHybridTracksWithAssociators) +# ----------------------------------------------------------------------------------- +# DTC Emulations +process.load( 'L1Trigger.TrackerDTC.ProducerED_cff' ) +process.load( 'L1Trigger.TrackerDTC.ProducerES_cff' ) + +#--- Load code that produces DTCStubs + +# load Track Trigger Configuration +process.load( 'L1Trigger.TrackerDTC.ProducerES_cff' ) +# load code that produces DTCStubs +process.load( 'L1Trigger.TrackerDTC.ProducerED_cff' ) +# load code that analyzes DTCStubs +process.load( 'L1Trigger.TrackerDTC.Analyzer_cff' ) + +process.dtc = cms.Path( process.TrackerDTCProducer ) + + + +# ---------------------------------------------------------------------------------- + # ---------------------------------------------------------------------------------- # output module @@ -58,5 +81,5 @@ #process.schedule = cms.Schedule(process.TTTracksEmulation,process.FEVToutput_step) -process.schedule = cms.Schedule(process.TTTracksEmulationWithTruth,process.FEVToutput_step) +process.schedule = cms.Schedule(process.dtc,process.TTTracksEmulationWithTruth,process.FEVToutput_step) diff --git a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py index aea44217dbdff..494fdfc7e4470 100644 --- a/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py +++ b/L1Trigger/TrackFindingTracklet/test/L1TrackNtupleMaker_cfg.py @@ -28,8 +28,8 @@ process.load('Configuration.StandardSequences.MagneticField_cff') process.load('FWCore.MessageService.MessageLogger_cfi') -process.MessageLogger.L1track=dict() -process.MessageLogger.Tracklet = cms.untracked.PSet(limit = cms.untracked.int32(-1)) +process.MessageLogger.L1track = dict(limit = -1) +process.MessageLogger.Tracklet = dict(limit = -1) if GEOMETRY == "D49": print "using geometry " + GEOMETRY + " (tilted)" @@ -72,6 +72,8 @@ # Or read specified .root file: inputMC = ["/store/relval/CMSSW_11_3_0_pre3/RelValTTbar_14TeV/GEN-SIM-DIGI-RAW/PU_113X_mcRun4_realistic_v3_2026D49PU200-v1/00000/001edbad-174e-46af-932a-6ce8e04aee1c.root"] + #inputMC = ["/store/relval/CMSSW_11_2_0_pre8/RelValSingleMuPt10/GEN-SIM-RECO/112X_mcRun4_realistic_v3_2026D49noPU-v1/00000/007d817e-9c59-4dec-959b-0f227942cdf0.root"] + #inputMC = ["/store/relval/CMSSW_11_3_0_pre3/RelValSingleMuPt10/GEN-SIM-DIGI-RAW/113X_mcRun4_realistic_v3_2026D49noPU-v1/00000/04514913-efc7-49fc-8df4-90efe43ca047.root"] else: print "this is not a valid geometry!!!" @@ -86,7 +88,7 @@ # L1 tracking: remake stubs? ############################################################ -#process.load('L1Trigger.TrackTrigger.TrackTrigger_cff') +process.load('L1Trigger.TrackTrigger.TrackTrigger_cff') #from L1Trigger.TrackTrigger.TTStubAlgorithmRegister_cfi import * #process.load("SimTracker.TrackTriggerAssociation.TrackTriggerAssociator_cff") @@ -96,6 +98,7 @@ #process.TTClusterStub = cms.Path(process.TrackTriggerClustersStubs) #process.TTClusterStubTruth = cms.Path(process.TrackTriggerAssociatorClustersStubs) + ############################################################ # L1 tracking ############################################################ @@ -189,6 +192,23 @@ process.ana = cms.Path(process.L1TrackNtuple) +process.load( 'L1Trigger.TrackerDTC.ProducerED_cff' ) +process.load( 'L1Trigger.TrackerDTC.ProducerES_cff' ) + +#--- Load code that produces DTCStubs +# load Track Trigger Configuration +process.load( 'L1Trigger.TrackerDTC.ProducerES_cff' ) +# load code that produces DTCStubs +process.load( 'L1Trigger.TrackerDTC.ProducerED_cff' ) +# load code that analyzes DTCStubs +process.load( 'L1Trigger.TrackerDTC.Analyzer_cff' ) +#process.TrackTriggerSetup.FrontEnd.BendCut=5.0 +#process.TrackTriggerSetup.Hybrid.MinPt=1.0 +process.dtc = cms.Path( process.TrackerDTCProducer )#* process.TrackerDTCAnalyzer ) + + + + # use this if you want to re-run the stub making # process.schedule = cms.Schedule(process.TTClusterStub,process.TTClusterStubTruth,process.TTTracksEmulationWithTruth,process.ana) @@ -196,7 +216,7 @@ # process.schedule = cms.Schedule(process.TTClusterStubTruth,process.TTTracksEmulationWithTruth,process.ana) # use this to only run tracking + track associator -process.schedule = cms.Schedule(process.TTTracksEmulationWithTruth,process.ana) +process.schedule = cms.Schedule(process.dtc,process.TTTracksEmulationWithTruth,process.ana) ############################################################ diff --git a/L1Trigger/TrackFindingTracklet/test/Makefile b/L1Trigger/TrackFindingTracklet/test/Makefile index 263ae484f31ac..0288bbb14082e 100644 --- a/L1Trigger/TrackFindingTracklet/test/Makefile +++ b/L1Trigger/TrackFindingTracklet/test/Makefile @@ -57,6 +57,7 @@ $(shell touch dummyIncl/ctime) $(shell touch dummyIncl/cstdlib) $(shell touch dummyIncl/cmath) $(shell touch dummyIncl/exception) +$(shell touch dummyIncl/filesystem) $(shell touch dummyIncl/fstream) $(shell touch dummyIncl/iomanip) $(shell touch dummyIncl/iostream) @@ -66,6 +67,7 @@ $(shell touch dummyIncl/memory) $(shell touch dummyIncl/set) $(shell touch dummyIncl/sstream) $(shell touch dummyIncl/string) +$(shell touch dummyIncl/tuple) $(shell touch dummyIncl/vector) $(shell touch dummyIncl/unordered_map) $(shell touch dummyIncl/unordered_set) @@ -73,6 +75,8 @@ $(shell touch dummyIncl/utility) $(shell touch dummyIncl/algorithm) $(shell touch dummyIncl/ext/hash_set) $(shell touch dummyIncl/sys/time.h) +$(shell touch dummyIncl/sys/stat.h) +$(shell touch dummyIncl/sys/types.h) $(shell touch dummyIncl/ctime) $(shell touch dummyIncl/chrono) endif @@ -165,10 +169,23 @@ $(shell echo " while (phi > M_PI) { phi -= 2 * M_PI; }" >> DataFormats/Math/i $(shell echo " return phi; } " >> DataFormats/Math/interface/deltaPhi.h) $(shell echo "};" >> DataFormats/Math/interface/deltaPhi.h) $(shell echo "namespace angle0to2pi {" >> DataFormats/Math/interface/deltaPhi.h) -$(shell echo " inline double make0To2pi(double phi) { assert(std::abs(phi) < 100.0); " >> DataFormats/Math/interface/deltaPhi.h) -$(shell echo " while (phi < 0.0) { phi += 2 * M_PI; }" >> DataFormats/Math/interface/deltaPhi.h) -$(shell echo " while (phi > 2 * M_PI) { phi -= 2 * M_PI; }" >> DataFormats/Math/interface/deltaPhi.h) -$(shell echo " return phi; } " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " template " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " inline constexpr valType make0To2pi(valType angle) {" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " constexpr valType twoPi = 2*M_PI;" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " constexpr valType oneOverTwoPi = 1. / twoPi;" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " constexpr valType epsilon = 1.e-13;" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " if ((std::abs(angle) <= epsilon) || (std::abs(twoPi - std::abs(angle)) <= epsilon))" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " return (0.);" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " if (std::abs(angle) > twoPi) { " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " valType nFac = trunc(angle * oneOverTwoPi);" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " angle -= (nFac * twoPi);" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " if (std::abs(angle) <= epsilon)" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " return (0.);" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " } " >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " if (angle < 0.)" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " angle += twoPi;" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " return (angle);" >> DataFormats/Math/interface/deltaPhi.h) +$(shell echo " }" >> DataFormats/Math/interface/deltaPhi.h) $(shell echo "};" >> DataFormats/Math/interface/deltaPhi.h) $(shell echo "#endif" >> DataFormats/Math/interface/deltaPhi.h) endif @@ -188,13 +205,14 @@ CXXFLAGS += -std=c++17 #fix, otherwise ROOT cflags overrule c++11 LIBS = -lHtml - ifneq ($(CMSSW_BASE),) ROOTFIT_INCLUDE := $(shell cd $(CMSSW_BASE); scram tool info roofitcore | grep INCLUDE= | sed 's|INCLUDE=||') ROOTFIT_LIBDIR := $(shell cd $(CMSSW_BASE); scram tool info roofitcore | grep LIBDIR= | sed 's|LIBDIR=||') CINTINCLUDES := -I$(ROOTFIT_INCLUDE) +ifneq ($(ROOTFIT_INCLUDE),) CXXFLAGS += -I$(ROOTFIT_INCLUDE) +endif LDFLAGS += -L$(ROOTFIT_LIBDIR) endif diff --git a/L1Trigger/TrackFindingTracklet/test/fpga.cc b/L1Trigger/TrackFindingTracklet/test/fpga.cc index b9c1786f4549f..69736de2f3adf 100644 --- a/L1Trigger/TrackFindingTracklet/test/fpga.cc +++ b/L1Trigger/TrackFindingTracklet/test/fpga.cc @@ -54,9 +54,6 @@ int main(const int argc, const char **argv) { // --------------------------------------------------------- // these are options that are read from python configuration files for the CMSSW running, set manually for the standalone version - settings.setDTCLinkFile("../data/calcNumDTCLinks.txt"); - settings.setModuleCablingFile("../data/modules_T5v3_27SP_nonant_tracklet.dat"); - settings.setDTCLinkLayerDiskFile("../data/dtclinklayerdisk.dat"); settings.setFitPatternFile("../data/fitpattern.txt"); settings.setProcessingModulesFile("../data/processingmodules_" + settings.geomext() + ".dat"); settings.setMemoryModulesFile("../data/memorymodules_" + settings.geomext() + ".dat"); @@ -67,10 +64,6 @@ int main(const int argc, const char **argv) { settings.setTableTREFile("../data/table_TRE/table_TRE_Dummy.txt"); } - edm::LogVerbatim("Tracklet") << "cabling DTC links : " << settings.DTCLinkFile(); - edm::LogVerbatim("Tracklet") << "module cabling : " << settings.moduleCablingFile(); - edm::LogVerbatim("Tracklet") << "DTC link layer disk : " << settings.DTCLinkLayerDiskFile(); - edm::LogVerbatim("Tracklet") << "fit pattern : " << settings.fitPatternFile(); edm::LogVerbatim("Tracklet") << "process modules : " << settings.processingModulesFile(); edm::LogVerbatim("Tracklet") << "memory modules : " << settings.memoryModulesFile(); @@ -116,7 +109,8 @@ int main(const int argc, const char **argv) { for (int eventnum = 0; eventnum < nevents && !in->eof(); eventnum++) { SLHCEvent ev(*in); - L1SimTrack simtrk; + //auto simtrk = ev.simtrack(0); + //if (std::abs(std::abs(simtrk.eta())-1.3)>0.1) continue; // ----------------------------------------------------------------- // setup ROOT Tree and Add Monte Carlo tracks to the ROOT-Tree Event @@ -216,7 +210,7 @@ int main(const int argc, const char **argv) { eventProcessor.event(ev); - std::vector &tracks = eventProcessor.tracks(); + const std::vector &tracks = eventProcessor.tracks(); // --------------------------------------------------------- // Block for producing ROOT-Tree @@ -253,23 +247,23 @@ int main(const int argc, const char **argv) { if (nlayers + ndisks < 4) continue; nsim++; - for (int seed = -1; seed < 8; seed++) { + for (int seed = -1; seed < 12; seed++) { bool eff = false; bool effloose = false; int itrackmatch = -1; for (unsigned int itrack = 0; itrack < tracks.size(); itrack++) { - const std::vector &stubs = tracks[itrack]->stubs(); + const std::vector &stubs = tracks[itrack].stubs(); if (seed == -1) { - if (tracks[itrack]->duplicate()) + if (tracks[itrack].duplicate()) continue; } else { - if (seed != tracks[itrack]->seed()) + if (seed != tracks[itrack].seed()) continue; } unsigned int nmatch = 0; for (auto stub : stubs) { - if (stub->tpmatch(simtrackid)) { + if (stub.tpmatch(simtrackid)) { nmatch++; } } @@ -295,14 +289,14 @@ int main(const int argc, const char **argv) { } if (itrackmatch >= 0) { - dpt = tracks[itrackmatch]->pt(settings) - q * simtrack.pt(); - dphi = tracks[itrackmatch]->phi0(settings) - simtrack.phi(); + dpt = tracks[itrackmatch].pt(settings) - q * simtrack.pt(); + dphi = tracks[itrackmatch].phi0(settings) - simtrack.phi(); if (dphi > M_PI) dphi -= 2 * M_PI; if (dphi < -M_PI) dphi += 2 * M_PI; - deta = tracks[itrackmatch]->eta(settings) - simtrack.eta(); - dz0 = tracks[itrackmatch]->z0(settings) - simtrack.vz(); + deta = tracks[itrackmatch].eta(settings) - simtrack.eta(); + dz0 = tracks[itrackmatch].z0(settings) - simtrack.vz(); } out << eventnum << " " << simeventid << " " << seed << " " << simtrackid << " " << simtrack.type() << " " @@ -314,18 +308,20 @@ int main(const int argc, const char **argv) { } int ntrack = 0; + int i = 0; for (auto &track : tracks) { + i++; if (settings.writeMonitorData("Pars")) { - outpars << track->duplicate() << " " << track->eta(settings) << " " << track->phi0(settings) << " " - << track->z0(settings) << " " << angle0to2pi::make0To2pi(track->phi0(settings)) / (2 * M_PI / N_SECTOR) - << " " << track->rinv(settings); + outpars << track.duplicate() << " " << track.eta(settings) << " " << track.phi0(settings) << " " + << track.z0(settings) << " " << angle0to2pi::make0To2pi(track.phi0(settings)) / (2 * M_PI / N_SECTOR) + << " " << track.rinv(settings); } - if (!track->duplicate()) { + if (!track.duplicate()) { ntrack++; } } - edm::LogVerbatim("Tracklet") << "Number of found tracks : " << tracks.size() << " unique " << ntrack; + edm::LogVerbatim("Tracklet") << "Number of found tracks : " << tracks.size() << " unique " << ntrack << " "; } eventProcessor.printSummary(); diff --git a/L1Trigger/TrackerDTC/src/Stub.cc b/L1Trigger/TrackerDTC/src/Stub.cc index 73b23f4a7be38..5647a6a74027d 100644 --- a/L1Trigger/TrackerDTC/src/Stub.cc +++ b/L1Trigger/TrackerDTC/src/Stub.cc @@ -131,9 +131,9 @@ namespace trackerDTC { // encode bend const vector& encodingBend = setup.encodingBend(sm->windowSize(), sm->psModule()); - const auto pos = find(encodingBend.begin(), encodingBend.end(), abs(bend_)); + const auto pos = find(encodingBend.begin(), encodingBend.end(), abs(ttStubRef->bendBE())); const int uBend = distance(encodingBend.begin(), pos); - bend_ = pow(-1, signbit(bend_)) * (uBend - (int)encodingBend.size() / 2); + bend_ = pow(-1, signbit(bend_)) * uBend; } // returns bit accurate representation of Stub @@ -149,7 +149,9 @@ namespace trackerDTC { TTDTC::BV Stub::formatHybrid(int region) const { const SensorModule::Type type = sm_->type(); // stub phi w.r.t. processing region centre in rad - const double phi = phi_ - (region - .5) * setup_->baseRegion(); + const double phi = phi_ - (region - .5) * setup_->baseRegion() + + 0.5 * setup_->hybridBasePhi(type) * (1 << setup_->hybridWidthPhi(type)); + // convert stub variables into bit vectors const TTBV hwR(r_, setup_->hybridBaseR(type), setup_->hybridWidthR(type), true); const TTBV hwPhi(phi, setup_->hybridBasePhi(type), setup_->hybridWidthPhi(type), true); @@ -235,4 +237,4 @@ namespace trackerDTC { hwLayer.str()); } -} // namespace trackerDTC \ No newline at end of file +} // namespace trackerDTC