Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:45

0001 #ifndef Phase2L1Trigger_DTTrigger_TrapezoidalGrouping_h
0002 #define Phase2L1Trigger_DTTrigger_TrapezoidalGrouping_h
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0008 #include "DataFormats/MuonDetId/interface/DTSuperLayerId.h"
0009 #include "DataFormats/MuonDetId/interface/DTLayerId.h"
0010 #include "DataFormats/MuonDetId/interface/DTWireId.h"
0011 #include "DataFormats/DTDigi/interface/DTDigiCollection.h"
0012 
0013 #include "L1Trigger/DTTriggerPhase2/interface/MuonPath.h"
0014 #include "L1Trigger/DTTriggerPhase2/interface/constants.h"
0015 
0016 #include "L1Trigger/DTTriggerPhase2/interface/MotherGrouping.h"
0017 
0018 #include <iostream>
0019 #include <fstream>
0020 #include <stack>
0021 
0022 // ===============================================================================
0023 // Previous definitions and declarations
0024 // ===============================================================================
0025 
0026 /*
0027   Channels are labeled following next schema:
0028     ---------------------------------
0029     |   6   |   7   |   8   |   9   |
0030     ---------------------------------
0031         |   3   |   4   |   5   |
0032         -------------------------
0033             |   1   |   2   |
0034             -----------------
0035                 |   0   |
0036                 ---------
0037 */
0038 
0039 inline bool hitWireSort(const DTPrimitive& hit1, const DTPrimitive& hit2) {
0040   int wi1 = hit1.channelId();
0041   int wi2 = hit2.channelId();
0042 
0043   if (wi1 < wi2)
0044     return true;
0045   else
0046     return false;
0047 }
0048 
0049 inline bool hitLayerSort(const DTPrimitive& hit1, const DTPrimitive& hit2) {
0050   int lay1 = hit1.layerId();
0051   int lay2 = hit2.layerId();
0052 
0053   if (lay1 < lay2)
0054     return true;
0055   else if (lay1 > lay2)
0056     return false;
0057   else
0058     return hitWireSort(hit1, hit2);
0059 }
0060 
0061 inline bool hitTimeSort(const DTPrimitive& hit1, const DTPrimitive& hit2) {
0062   int tdc1 = hit1.tdcTimeStamp();
0063   int tdc2 = hit2.tdcTimeStamp();
0064 
0065   if (tdc1 < tdc2)
0066     return true;
0067   else if (tdc1 > tdc2)
0068     return false;
0069   else
0070     return hitLayerSort(hit1, hit2);
0071 }
0072 
0073 namespace dtamgrouping {
0074   /* Cell's combination, following previous labeling, to obtain every possible  muon's path. 
0075      Others cells combinations imply non straight paths */
0076   constexpr int CHANNELS_PATH_ARRANGEMENTS[8][4] = {
0077       {0, 1, 3, 6}, {0, 1, 3, 7}, {0, 1, 4, 7}, {0, 1, 4, 8}, {0, 2, 4, 7}, {0, 2, 4, 8}, {0, 2, 5, 8}, {0, 2, 5, 9}};
0078 
0079   /* For each of the previous cell's combinations, this array stores the associated cell's 
0080      displacement, relative to lower layer cell, measured in semi-cell length units */
0081 
0082   constexpr int CELL_HORIZONTAL_LAYOUTS[8][4] = {{0, -1, -2, -3},
0083                                                  {0, -1, -2, -1},
0084                                                  {0, -1, 0, -1},
0085                                                  {0, -1, 0, 1},
0086                                                  {0, 1, 0, -1},
0087                                                  {0, 1, 0, 1},
0088                                                  {0, 1, 2, 1},
0089                                                  {0, 1, 2, 3}};
0090 }  // namespace dtamgrouping
0091 
0092 // ===============================================================================
0093 // Class declarations
0094 // ===============================================================================
0095 
0096 class TrapezoidalGrouping : public MotherGrouping {
0097 public:
0098   // Constructors and destructor
0099   TrapezoidalGrouping(const edm::ParameterSet& pset, edm::ConsumesCollector& iC);
0100   ~TrapezoidalGrouping() override;
0101 
0102   // Main methods
0103   void initialise(const edm::EventSetup& iEventSetup) override;
0104   void run(edm::Event& iEvent,
0105            const edm::EventSetup& iEventSetup,
0106            const DTDigiCollection& digis,
0107            MuonPathPtrs& outMpath) override;
0108   void finish() override;
0109 
0110   // Other public methods
0111 
0112   // Public attributes
0113 
0114 private:
0115   // Private methods
0116   void setInChannels(const DTDigiCollection* digi, int sl);
0117   std::vector<DTPrimitives> group_hits(DTPrimitive pivot_hit,
0118                                        std::vector<DTPrimitives> input_paths,
0119                                        DTPrimitives hits_per_cell,
0120                                        DTPrimitives& hits_in_trapezoid);
0121 
0122   // Private attributes
0123   const bool debug_;
0124 
0125   DTPrimitives muxInChannels_[cmsdt::NUM_CELLS_PER_BLOCK];
0126   DTPrimitives channelIn_[cmsdt::NUM_LAYERS][cmsdt::NUM_CH_PER_LAYER];
0127   DTPrimitives all_hits;
0128   DTPrimitives chInDummy_;
0129   int prevTDCTimeStamps_[4];
0130   int currentBaseChannel_;
0131 
0132   // The trapezoid is as follows:
0133   // [  0  ][  1  ][  2  ][  3  ][  4  ][  5  ][  6  ][  7  ][  8  ]
0134 
0135   // And maps to the physical cells as follows:
0136 
0137   // Pivot in layer 1 = "00"
0138   // [  5  ][  6  ][  7  ][  8  ] Layer C
0139   //    [  2  ][  3  ][  4  ]     Layer B
0140   //        [  0  ][  1  ]        Layer A
0141   //            Pivot
0142 
0143   // Pivot in layer 2 = "01"
0144   //    [  2  ][  3  ][  4  ]     Layer B
0145   //        [  0  ][  1  ]        Layer A
0146   //            Pivot
0147   //        [ 6,8 ][ 5,7 ]        Layer C
0148 
0149   // Pivot in layer 3 = "10"
0150   //        [ 6,8 ][ 5,7 ]        Layer C
0151   //            Pivot
0152   //        [  0  ][  1  ]        Layer A
0153   //    [  2  ][  3  ][  4  ]     Layer B
0154 
0155   // Pivot in layer 4 = "11"
0156   //            Pivot
0157   //        [  0  ][  1  ]        Layer A
0158   //    [  2  ][  3  ][  4  ]     Layer B
0159   // [  5  ][  6  ][  7  ][  8  ] Layer C
0160 
0161   short trapezoid_vertical_mapping[4][9] = {{1, 1, 2, 2, 2, 3, 3, 3, 3},
0162                                             {1, 1, 2, 2, 2, -1, -1, -1, -1},
0163                                             {-1, -1, -2, -2, -2, 1, 1, 1, 1},
0164                                             {-1, -1, -2, -2, -2, -3, -3, -3, -3}};
0165 
0166   short trapezoid_horizontal_mapping[4][9] = {{0, 1, -1, 0, 1, -1, 0, 1, 2},
0167                                               {-1, 0, -1, 0, 1, 0, -1, 0, -1},
0168                                               {0, 1, -1, 0, 1, 1, 0, 1, 0},
0169                                               {-1, 0, -1, 0, 1, -2, -1, 0, 1}};
0170 
0171   // Task list
0172   // 4 hit candidates
0173   // 0 => (0,2,5),       1 => (0,2,6),       2 => (0,3,6),       3 => (0,3,7),
0174   // 4 => (1,3,6),       5 => (1,3,7),       6 => (1,4,7),       7 => (1,4,8),
0175   // the rest are 3-hit candidates, last value not used
0176   // 8 => (0,2,0),       9 => (0,3,0),      10 => (1,3,0),      11 => (1,4,0),
0177   // 12 => (0,5,0),      13 => (0,6,0),      14 => (0,7,0),      15 => (1,6,0),
0178   // 16 => (1,7,0),      17 => (1,8,0),      18 => (2,5,0),      19 => (2,6,0),
0179   // 20 => (3,6,0),      21 => (3,7,0),      22 => (4,7,0),      23 => (4,8,0)
0180 
0181   std::vector<std::vector<short>> task_list = {// 4-hit
0182                                                {0, 2, 5},
0183                                                {0, 2, 6},
0184                                                {0, 3, 6},
0185                                                {0, 3, 7},
0186                                                {1, 3, 6},
0187                                                {1, 3, 7},
0188                                                {1, 4, 7},
0189                                                {1, 4, 8},
0190                                                // 3-hit
0191                                                {0, 2},
0192                                                {0, 3},
0193                                                {1, 3},
0194                                                {1, 4},
0195                                                {0, 5},
0196                                                {0, 6},
0197                                                {0, 7},
0198                                                {1, 6},
0199                                                {1, 7},
0200                                                {1, 8},
0201                                                {2, 5},
0202                                                {2, 6},
0203                                                {3, 6},
0204                                                {3, 7},
0205                                                {4, 7},
0206                                                {4, 8}};
0207 
0208   int CELL_HORIZONTAL_LAYOUTS_PER_TASK[4][24][4] = { // pivoting over layer 1
0209                                                     {// all layers available
0210                                                      {0, 0, 0, -1},
0211                                                      {0, 0, 1, -1},
0212                                                      {0, 1, 0, -1},
0213                                                      {0, 1, 1, -1},
0214                                                      {1, 0, 0, -1},
0215                                                      {1, 0, 1, -1},
0216                                                      {1, 1, 0, -1},
0217                                                      {1, 1, 1, -1},
0218                                                      // layer 4 missing
0219                                                      {0, 0, 0, -1},
0220                                                      {0, 1, 0, -1},
0221                                                      {1, 0, 0, -1},
0222                                                      {1, 1, 0, -1},
0223                                                      // layer 3 missing
0224                                                      {0, 0, 0, -1},
0225                                                      {0, 0, 1, -1},
0226                                                      {0, 1, 1, -1},
0227                                                      {1, 0, 0, -1},
0228                                                      {1, 0, 1, -1},
0229                                                      {1, 1, 1, -1},
0230                                                      // layer 2 missing
0231                                                      {0, 0, 0, -1},
0232                                                      {0, 0, 1, -1},
0233                                                      {0, 1, 0, -1},
0234                                                      {0, 1, 1, -1},
0235                                                      {1, 1, 0, -1},
0236                                                      {1, 1, 1, -1}},
0237                                                     // pivoting over layer 2
0238                                                     {// all layers available
0239                                                      {0, 0, 0, -1},
0240                                                      {1, 0, 0, -1},
0241                                                      {1, 0, 1, -1},
0242                                                      {0, 0, 1, -1},
0243                                                      {1, 1, 0, -1},
0244                                                      {0, 1, 0, -1},
0245                                                      {0, 1, 1, -1},
0246                                                      {1, 1, 1, -1},
0247                                                      // layer 1 missing
0248                                                      {0, 0, 0, -1},
0249                                                      {0, 0, 1, -1},
0250                                                      {0, 1, 0, -1},
0251                                                      {0, 1, 1, -1},
0252                                                      // layer 4 missing
0253                                                      {0, 0, 0, -1},
0254                                                      {1, 0, 0, -1},
0255                                                      {0, 0, 0, -1},
0256                                                      {1, 1, 0, -1},
0257                                                      {0, 1, 0, -1},
0258                                                      {1, 1, 0, -1},
0259                                                      // layer 3 missing
0260                                                      {0, 0, 0, -1},
0261                                                      {1, 0, 0, -1},
0262                                                      {1, 0, 1, -1},
0263                                                      {0, 0, 1, -1},
0264                                                      {0, 1, 1, -1},
0265                                                      {1, 1, 1, -1}},
0266                                                     // pivoting over layer 3
0267                                                     {// all layers available
0268                                                      {1, 1, 1, -1},
0269                                                      {1, 1, 0, -1},
0270                                                      {0, 1, 0, -1},
0271                                                      {0, 1, 1, -1},
0272                                                      {1, 0, 0, -1},
0273                                                      {1, 0, 1, -1},
0274                                                      {0, 0, 1, -1},
0275                                                      {0, 0, 0, -1},
0276                                                      // layer 4 missing
0277                                                      {1, 1, 0, -1},
0278                                                      {0, 1, 0, -1},
0279                                                      {1, 0, 0, -1},
0280                                                      {0, 0, 0, -1},
0281                                                      // layer 1 missing
0282                                                      {0, 1, 1, -1},
0283                                                      {0, 1, 0, -1},
0284                                                      {0, 1, 1, -1},
0285                                                      {0, 0, 0, -1},
0286                                                      {0, 0, 1, -1},
0287                                                      {0, 0, 0, -1},
0288                                                      // layer 2 missing
0289                                                      {1, 1, 1, -1},
0290                                                      {1, 1, 0, -1},
0291                                                      {0, 1, 0, -1},
0292                                                      {0, 1, 1, -1},
0293                                                      {0, 0, 1, -1},
0294                                                      {0, 0, 0, -1}},
0295                                                     // pivoting over layer 4
0296                                                     {// all layers available
0297                                                      {1, 1, 1, -1},
0298                                                      {0, 1, 1, -1},
0299                                                      {1, 0, 1, -1},
0300                                                      {0, 0, 1, -1},
0301                                                      {1, 1, 0, -1},
0302                                                      {0, 1, 0, -1},
0303                                                      {1, 0, 0, -1},
0304                                                      {0, 0, 0, -1},
0305                                                      // layer 1 missing
0306                                                      {0, 1, 1, -1},
0307                                                      {0, 0, 1, -1},
0308                                                      {0, 1, 0, -1},
0309                                                      {0, 0, 0, -1},
0310                                                      // layer 2 missing
0311                                                      {1, 1, 1, -1},
0312                                                      {0, 1, 1, -1},
0313                                                      {0, 0, 1, -1},
0314                                                      {1, 1, 0, -1},
0315                                                      {0, 1, 0, -1},
0316                                                      {0, 0, 0, -1},
0317                                                      // layer 3 missing
0318                                                      {1, 1, 1, -1},
0319                                                      {0, 1, 1, -1},
0320                                                      {1, 0, 1, -1},
0321                                                      {0, 0, 1, -1},
0322                                                      {1, 0, 0, -1},
0323                                                      {0, 0, 0, -1}}};
0324 
0325   int MISSING_LAYER_LAYOUTS_PER_TASK[4][24] = {
0326       {-1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1},
0327       {-1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2},
0328       {-1, -1, -1, -1, -1, -1, -1, -1, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1},
0329       {-1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2}};
0330 };
0331 
0332 #endif