Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-15 23:40:43

0001 //
0002 // Class to build the configuration for the tracklet based track finding
0003 //
0004 //
0005 //
0006 #ifndef L1Trigger_TrackFindingTracklet_interface_TrackletConfigBuilder_h
0007 #define L1Trigger_TrackFindingTracklet_interface_TrackletConfigBuilder_h
0008 
0009 #include "L1Trigger/TrackFindingTracklet/interface/Settings.h"
0010 
0011 #include <vector>
0012 #include <list>
0013 #include <utility>
0014 #include <set>
0015 #include <iostream>
0016 #include <fstream>
0017 #include <cstdlib>
0018 
0019 namespace tt {
0020   class Setup;
0021 }
0022 
0023 namespace trklet {
0024 
0025   class TrackletConfigBuilder {
0026   public:
0027     //Builds the configuration for the tracklet based track finding
0028     TrackletConfigBuilder(const Settings& settings, const tt::Setup* setup = nullptr);
0029 
0030     //This method writes out the configuration as files
0031     void writeAll(std::ostream& wires, std::ostream& memories, std::ostream& modules);
0032 
0033     //
0034     // The next group of fcn formats a string to write out names of different
0035     // memories and processing modules
0036     //
0037 
0038     //Seed string, eg. L1L2
0039     std::string iSeedStr(unsigned int iSeed) const;
0040 
0041     //Return unsigned as string
0042     static std::string numStr(unsigned int i);
0043 
0044     //Return iTC as string - ie A, B, C, etc
0045     std::string iTCStr(unsigned int iTC) const;
0046 
0047     //The region string A, B, C etc for layers and disks; X, Y, Z etc for overlap
0048     std::string iRegStr(unsigned int iReg, unsigned int iSeed) const;
0049 
0050     //TC Name
0051     std::string TCName(unsigned int iSeed, unsigned int iTC) const;
0052 
0053     //Name of layer or disk, e.g. L1 or D1
0054     static std::string LayerName(unsigned int ilayer);
0055 
0056     //Tracklet projection name
0057     std::string TPROJName(unsigned int iSeed, unsigned int iTC, unsigned int ilayer, unsigned int ireg) const;
0058 
0059     //Projection router name
0060     std::string PRName(unsigned int ilayer, unsigned int ireg) const;
0061 
0062   private:
0063     //
0064     // Method to initialize the regions and VM in each layer
0065     //
0066     void initGeom();
0067 
0068     //
0069     // Builds the list of TE for each seeding combination
0070     //
0071     void buildTE();
0072 
0073     //
0074     // Builds the lists of TC for each seeding combination
0075     //
0076     void buildTC();
0077 
0078     //
0079     // Finds the projections needed for each seeding combination
0080     //
0081     void buildProjections();
0082 
0083 #ifdef CMSSW_GIT_HASH
0084     // Calculate phi range of modules read by each DTC.
0085     void setDTCphirange(const tt::Setup* setup);
0086 
0087     // Write DTC phi ranges to dtcphirange.txt for stand-alone emulation.
0088     void writeDTCphirange() const;
0089 #else
0090     // Set phi ranges after reading them from dtcphirange.txt (stand-alone emulation)
0091     void setDTCphirange(const tt::Setup* setup = nullptr);
0092 #endif
0093 
0094     //
0095     // Helper function to determine if a pair of VM memories form valid TE
0096     //
0097     bool validTEPair(unsigned int iseed, unsigned int iTE1, unsigned int iTE2);
0098 
0099     //
0100     // Helper fcn. to get the layers/disks for a seed
0101     //
0102     std::pair<unsigned int, unsigned int> seedLayers(unsigned int iSeed);
0103 
0104     //
0105     // Helper fcn to get the radii of the two layers in a seed
0106     //
0107     std::pair<double, double> seedRadii(unsigned int iseed);
0108 
0109     //
0110     // Helper fcn to return the phi range of a projection of a tracklet from a TC
0111     //
0112     std::pair<double, double> seedPhiRange(double rproj, unsigned int iSeed, unsigned int iTC);
0113 
0114     //
0115     // Helper function to calculate the phi position of a seed at radius r that is formed
0116     // by two stubs at (r1,phi1) and (r2, phi2)
0117     //
0118     double phi(double r1, double phi1, double r2, double phi2, double r);
0119 
0120     //
0121     // Helper function to calculate rinv for two stubs at (r1,phi1) and (r2,phi2)
0122     //
0123     double rinv(double r1, double phi1, double r2, double phi2);
0124 
0125     //StubPair Name
0126     std::string SPName(unsigned int l1,
0127                        unsigned int ireg1,
0128                        unsigned int ivm1,
0129                        unsigned int l2,
0130                        unsigned int ireg2,
0131                        unsigned int ivm2,
0132                        unsigned int iseed) const;
0133 
0134     //StubPair displaced name
0135     std::string SPDName(unsigned int l1,
0136                         unsigned int ireg1,
0137                         unsigned int ivm1,
0138                         unsigned int l2,
0139                         unsigned int ireg2,
0140                         unsigned int ivm2,
0141                         unsigned int l3,
0142                         unsigned int ireg3,
0143                         unsigned int ivm3,
0144                         unsigned int iseed) const;
0145 
0146     //Stub Triplet name
0147     std::string STName(unsigned int l1,
0148                        unsigned int ireg1,
0149                        unsigned int l2,
0150                        unsigned int ireg2,
0151                        unsigned int l3,
0152                        unsigned int ireg3,
0153                        unsigned int iseed,
0154                        unsigned int count) const;
0155 
0156     //TrackletEngine name
0157     std::string TEName(unsigned int l1,
0158                        unsigned int ireg1,
0159                        unsigned int ivm1,
0160                        unsigned int l2,
0161                        unsigned int ireg2,
0162                        unsigned int ivm2,
0163                        unsigned int iseed) const;
0164 
0165     //Triplet engine name
0166     std::string TREName(unsigned int l1,
0167                         unsigned int ireg1,
0168                         unsigned int l2,
0169                         unsigned int ireg2,
0170                         unsigned int iseed,
0171                         unsigned int count) const;
0172 
0173     //TrackletEngine displaced name
0174     std::string TEDName(unsigned int l1,
0175                         unsigned int ireg1,
0176                         unsigned int ivm1,
0177                         unsigned int l2,
0178                         unsigned int ireg2,
0179                         unsigned int ivm2,
0180                         unsigned int iseed) const;
0181 
0182     //Tracklet parameter memory name
0183     std::string TParName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc) const;
0184 
0185     //TrackletCalculator displaced name
0186     std::string TCDName(unsigned int l1, unsigned int l2, unsigned int l3, unsigned int itc) const;
0187 
0188     //TrackletProjection name
0189     std::string TPROJName(unsigned int l1,
0190                           unsigned int l2,
0191                           unsigned int l3,
0192                           unsigned int itc,
0193                           unsigned int projlay,
0194                           unsigned int projreg) const;
0195 
0196     //FitTrack module name
0197     std::string FTName(unsigned int l1, unsigned int l2, unsigned int l3) const;
0198 
0199     //
0200     // This group of methods are used to print out the configuration as a file
0201     //
0202     void writeProjectionMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0203 
0204     void writeSPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0205 
0206     void writeSPDMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0207 
0208     void writeAPMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0209 
0210     void writeCMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0211 
0212     void writeVMPROJMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0213 
0214     void writeFMMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0215 
0216     void writeASMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0217 
0218     void writeVMSMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0219 
0220     void writeTPARMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0221 
0222     void writeTFMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0223 
0224     void writeCTMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0225 
0226     void writeILMemories(std::ostream& os, std::ostream& memories, std::ostream& modules);
0227 
0228     //
0229     //--- Store constants extracted from Settings
0230     //
0231 
0232     unsigned int NSector_;  //Number of sectors
0233     double rcrit_;          //critical radius that defines the sector
0234 
0235     bool duplicateMPs_;     //if true write configuration with MPs duplicated for L3,L4
0236     bool combinedmodules_;  //if true write configuration for combined modules
0237 
0238     bool extended_;  //if true write configuration for extended configuration
0239 
0240     double rinvmax_;         //Max value for valid rinv
0241     double rmaxdisk_;        //Maximim disk radius
0242     double zlength_;         //Maximim (abslute) z-positon in barrel
0243     double rmean_[N_LAYER];  //Mean layer radius
0244     double zmean_[N_DISK];   //Mean disk z-position
0245 
0246     double dphisectorHG_;  //Full sector width
0247 
0248     unsigned int NTC_[N_SEED_PROMPT];  //Number of TC per seeding combination
0249 
0250     unsigned int NRegions_[N_LAYER + N_DISK];                     //Regions (all stubs memories 6 layers +5 disks
0251     unsigned int NVMME_[N_LAYER + N_DISK];                        //Number of MEs (all stubs memories 6 layers +5 disks
0252     std::pair<unsigned int, unsigned int> NVMTE_[N_SEED_PROMPT];  //number of TEs for each seeding combination
0253 
0254     //Min and max phi for a phi region (e.g. all stubs)
0255     std::vector<std::pair<double, double> > allStubs_[N_LAYER + N_DISK];
0256 
0257     //Min and max phi for VM bin
0258     std::vector<std::pair<double, double> > VMStubsME_[N_LAYER + N_DISK];
0259 
0260     //Phi ranges for the stubs in the VM bins used in the pair in th TE
0261     std::pair<std::vector<std::pair<double, double> >, std::vector<std::pair<double, double> > >
0262         VMStubsTE_[N_SEED_PROMPT];
0263 
0264     // VM bin in inner/outer seeding layer of each TE.
0265     std::vector<std::pair<unsigned int, unsigned int> > TE_[N_SEED_PROMPT];
0266 
0267     //The ID of all TE that send data to TCs for each seeding combination
0268     std::vector<std::vector<unsigned int> > TC_[N_SEED_PROMPT];
0269 
0270     //The projections to each layer/disk from a seed and TC
0271     std::vector<std::vector<std::pair<unsigned int, unsigned int> > > projections_[N_LAYER + N_DISK];
0272 
0273     //Which matches are used for each seeding layer
0274     //                                                L1 L2 L3 L4 L5 L6 D1 D2 D3 D4 D5
0275     int matchport_[N_SEED_PROMPT][N_LAYER + N_DISK] = {{-1, -1, 1, 2, 3, 4, 4, 3, 2, 1, -1},       //L1L2
0276                                                        {1, -1, -1, 2, 3, -1, 4, 3, 2, 1, -1},      //L2L3
0277                                                        {1, 2, -1, -1, 3, 4, 4, 3, -1, -1, -1},     //L3L4
0278                                                        {1, 2, 3, 4, -1, -1, -1, -1, -1, -1, -1},   //L5L6
0279                                                        {1, 2, -1, -1, -1, -1, -1, -1, 2, 3, 4},    //D1D2
0280                                                        {1, -1, -1, -1, -1, -1, 2, 3, -1, -1, 4},   //D3D4
0281                                                        {-1, -1, -1, -1, -1, -1, -1, 1, 2, 3, 4},   //L1D1
0282                                                        {1, -1, -1, -1, -1, -1, -1, 2, 3, 4, -1}};  //L2D1
0283 
0284     struct DTCinfo {
0285       std::string name;
0286       int layer;
0287       float phimin;
0288       float phimax;
0289     };
0290     std::list<DTCinfo> vecDTCinfo_;
0291 
0292     //Settings
0293     const Settings& settings_;
0294   };
0295 }  // namespace trklet
0296 #endif