Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-09-02 08:36:16

0001 #ifndef L1Trigger_CSCTriggerPrimitives_CSCMotherboard_h
0002 #define L1Trigger_CSCTriggerPrimitives_CSCMotherboard_h
0003 
0004 /** \class CSCMotherboard
0005  *
0006  * Correlates anode and cathode LCTs from the same chamber.
0007  *
0008  * When the Trigger MotherBoard (TMB) is instantiated it instantiates an ALCT
0009  * and CLCT board.  The MotherBoard takes up to two LCTs from each anode
0010  * and cathode LCT card and combines them into a single Correlated LCT.
0011  * The output is up to two Correlated LCTs.
0012  *
0013  * It can be run in either a test mode, where the arguments are a collection
0014  * of wire times and arrays of halfstrip times, or
0015  * for general use, with wire digi and comparator digi collections as
0016  * arguments.  In the latter mode, the wire & strip info is passed on the
0017  * LCTProcessors, where it is decoded and converted into a convenient form.
0018  * After running the anode and cathode LCTProcessors, TMB correlates the
0019  * anode and cathode LCTs.  At present, it simply matches the best CLCT
0020  * with the best ALCT; perhaps a better algorithm will be determined in
0021  * the future.  The MotherBoard then determines a few more numbers (such as
0022  * quality and pattern) from the ALCT and CLCT information, and constructs
0023  * two correlated LCT "digis".
0024  *
0025  * \author Benn Tannenbaum 28 August 1999 benn@physics.ucla.edu
0026  *
0027  * Based on code by Nick Wisniewski (nw@its.caltech.edu) and a framework
0028  * by Darin Acosta (acosta@phys.ufl.edu).
0029  *
0030  * Numerous later improvements by Jason Mumford and Slava Valuev (see cvs
0031  * in ORCA).
0032  * Porting from ORCA by S. Valuev (Slava.Valuev@cern.ch), May 2006.
0033  *
0034  * Extended for Run-3 and Phase-2 by Vadim Khotilovich, Tao Huang, Sven Dildick and Giovanni Mocellin
0035  */
0036 
0037 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCAnodeLCTProcessor.h"
0038 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCCathodeLCTProcessor.h"
0039 #include "L1Trigger/CSCTriggerPrimitives/interface/LCTContainer.h"
0040 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCALCTCrossCLCT.h"
0041 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCUpgradeAnodeLCTProcessor.h"
0042 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCUpgradeCathodeLCTProcessor.h"
0043 #include "L1Trigger/CSCTriggerPrimitives/interface/LCTQualityAssignment.h"
0044 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigi.h"
0045 #include "DataFormats/CSCDigi/interface/CSCShowerDigi.h"
0046 #include "CondFormats/CSCObjects/interface/CSCL1TPLookupTableCCLUT.h"
0047 #include "CondFormats/CSCObjects/interface/CSCL1TPLookupTableME21ILT.h"
0048 #include "CondFormats/CSCObjects/interface/CSCL1TPLookupTableME11ILT.h"
0049 
0050 class CSCMotherboard : public CSCBaseboard {
0051 public:
0052   /** Normal constructor. */
0053   CSCMotherboard(unsigned endcap,
0054                  unsigned station,
0055                  unsigned sector,
0056                  unsigned subsector,
0057                  unsigned chamber,
0058                  const edm::ParameterSet& conf);
0059 
0060   /** Default destructor. */
0061   ~CSCMotherboard() override = default;
0062 
0063   /** Run function for normal usage.  Runs cathode and anode LCT processors,
0064       takes results and correlates into CorrelatedLCT. */
0065   void run(const CSCWireDigiCollection* wiredc, const CSCComparatorDigiCollection* compdc);
0066 
0067   /*
0068     Returns vector of good correlated LCTs in the read-out time window.
0069     LCTs in the BX window [early_tbins,...,late_tbins] are considered
0070     good for physics. The central LCT BX is time bin 8.
0071     - tmb_l1a_window_size = 7 (Run-1, Run-2) -> [5, 6, 7, 8, 9, 10, 11]
0072     - tmb_l1a_window_size = 5 (Run-3)        ->    [6, 7, 8, 9, 10]
0073     - tmb_l1a_window_size = 3 (Run-4?)       ->       [7, 8, 9]
0074 
0075     Note, this function does not have an exact counterpart in the
0076     firmware. The reason is that the DAQ of LCTs is not correctly
0077     simulated in CMSSW - at least the simulation of the L1-accept.
0078     So, this function corresponds to both the trigger path and the
0079     DAQ path in the firmware. In general, the function will return
0080     LCTs that would not be used in the OMTF or EMTF emulator,
0081     because they are out-of-time relative for tracking purposes. For
0082     instance an LCT with BX5 would be read out by the DAQ, but would
0083     likely not be used by the EMTF.
0084   */
0085   virtual std::vector<CSCCorrelatedLCTDigi> readoutLCTs() const;
0086 
0087   // LCT selection: at most 2 in each BX
0088   void selectLCTs();
0089 
0090   /** Returns shower bits */
0091   std::vector<CSCShowerDigi> readoutShower() const;
0092 
0093   /** Clears correlated LCT and passes clear signal on to cathode and anode
0094       LCT processors. */
0095   void clear();
0096 
0097   /** Set configuration parameters obtained via EventSetup mechanism. */
0098   void setConfigParameters(const CSCDBL1TPParameters* conf);
0099   void setESLookupTables(const CSCL1TPLookupTableCCLUT* conf);
0100   void setESLookupTables(const CSCL1TPLookupTableME11ILT* conf);
0101   void setESLookupTables(const CSCL1TPLookupTableME21ILT* conf);
0102 
0103   /** Anode LCT processor. */
0104   std::unique_ptr<CSCAnodeLCTProcessor> alctProc;
0105 
0106   /** Cathode LCT processor. */
0107   std::unique_ptr<CSCCathodeLCTProcessor> clctProc;
0108 
0109   // VK: change to protected, to allow inheritance
0110 protected:
0111   // access to lookup tables via eventsetup
0112   const CSCL1TPLookupTableCCLUT* lookupTableCCLUT_;
0113   const CSCL1TPLookupTableME11ILT* lookupTableME11ILT_;
0114   const CSCL1TPLookupTableME21ILT* lookupTableME21ILT_;
0115 
0116   /* Containers for reconstructed ALCTs and CLCTs */
0117   std::vector<CSCALCTDigi> alctV;
0118   std::vector<CSCCLCTDigi> clctV;
0119 
0120   /** Container with all LCTs prior to sorting and selecting. */
0121   LCTContainer allLCTs_;
0122 
0123   /* Container with sorted and selected LCTs */
0124   std::vector<CSCCorrelatedLCTDigi> lctV;
0125 
0126   CSCShowerDigi showers_[CSCConstants::MAX_LCT_TBINS];
0127 
0128   // helper function to return ALCT/CLCT with correct central BX
0129   CSCALCTDigi getBXShiftedALCT(const CSCALCTDigi&) const;
0130   CSCCLCTDigi getBXShiftedCLCT(const CSCCLCTDigi&) const;
0131 
0132   /** Configuration parameters. */
0133   unsigned int mpc_block_me1a;
0134   unsigned int alct_trig_enable, clct_trig_enable, match_trig_enable;
0135   unsigned int match_trig_window_size, tmb_l1a_window_size;
0136 
0137   /** Phase2: whether to not reuse CLCTs that were used by previous matching ALCTs */
0138   bool drop_used_clcts;
0139 
0140   /** Phase2: separate handle for early time bins */
0141   int early_tbins;
0142 
0143   /** Phase2: whether to readout only the earliest two LCTs in readout window */
0144   bool readout_earliest_2;
0145 
0146   // when set to true, ignore CLCTs found in later BX's
0147   bool match_earliest_clct_only_;
0148 
0149   // encode special bits for high-multiplicity triggers
0150   std::vector<unsigned> showerSource_;
0151   unsigned thisShowerSource_;
0152   unsigned minbx_readout_;
0153   unsigned maxbx_readout_;
0154 
0155   bool ignoreAlctCrossClct_;
0156 
0157   /*
0158      Preferential index array in matching window, relative to the ALCT BX.
0159      Where the central match BX goes first,
0160      then the closest early, the closest late, etc.
0161   */
0162   std::vector<int> preferred_bx_match_;
0163 
0164   /** Default values of configuration parameters. */
0165   static const unsigned int def_mpc_block_me1a;
0166   static const unsigned int def_alct_trig_enable, def_clct_trig_enable;
0167   static const unsigned int def_match_trig_enable, def_match_trig_window_size;
0168   static const unsigned int def_tmb_l1a_window_size;
0169 
0170   /* quality assignment */
0171   std::unique_ptr<LCTQualityAssignment> qualityAssignment_;
0172 
0173   /* quality control */
0174   std::unique_ptr<LCTQualityControl> qualityControl_;
0175 
0176   /*
0177     Helper class to check if an ALCT intersects with a CLCT. Normally
0178     this class should not be used. It is left in the code as a potential
0179     improvement for ME1/1 when unphysical LCTs are not desired. This
0180     function is not implemented in the firmware.
0181   */
0182   std::unique_ptr<CSCALCTCrossCLCT> cscOverlap_;
0183 
0184   /** Make sure that the parameter values are within the allowed range. */
0185   void checkConfigParameters();
0186 
0187   /*
0188      For valid ALCTs in the trigger time window, look for CLCTs within the
0189      match-time window. Valid CLCTs are matched in-time. If a match was found
0190      for the best ALCT and best CLCT, also the second best ALCT and second
0191      best CLCT are sent to a correlation function "correlateLCTs" that will
0192      make the best-best pair and second-second pair (if applicable).
0193   */
0194   void matchALCTCLCT();
0195 
0196   /*
0197     This function matches maximum two ALCTs with maximum two CLCTs in
0198     a bunch crossing. The best ALCT is considered the one with the highest
0199     quality in a BX. Similarly for the best CLCT. If there is just one
0200     ALCT and just one CLCT, the correlated LCT is made from those two
0201     components. If there are exactly two ALCTs and two CLCTs, the best
0202     LCT and second best LCT are formed from the best ALCT-CLCT combination
0203     and the second best ALCT-CLCT combination. In case there is missing
0204     information (e.g. second best ALCT, but no second best CLCT), information
0205     is copied over.
0206    */
0207   void correlateLCTs(const CSCALCTDigi& bestALCT,
0208                      const CSCALCTDigi& secondALCT,
0209                      const CSCCLCTDigi& bestCLCT,
0210                      const CSCCLCTDigi& secondCLCT,
0211                      CSCCorrelatedLCTDigi& bLCT,
0212                      CSCCorrelatedLCTDigi& sLCT,
0213                      int type) const;
0214 
0215   /*
0216      This method calculates all the TMB words and then passes them to the
0217      constructor of correlated LCTs. The LCT data members are filled with
0218      information from the ALCT-CLCT combination.
0219   */
0220   void constructLCTs(
0221       const CSCALCTDigi& aLCT, const CSCCLCTDigi& cLCT, int type, int trknmb, CSCCorrelatedLCTDigi& lct) const;
0222 
0223   /*
0224     These functions copy valid ALCT/CLCT information to invalid the ALCT/CLCT
0225     if present, so that we always construct the maximum number of valid LCTs
0226   */
0227   void copyValidToInValidALCT(CSCALCTDigi&, CSCALCTDigi&) const;
0228   void copyValidToInValidCLCT(CSCCLCTDigi&, CSCCLCTDigi&) const;
0229 
0230   bool doesALCTCrossCLCT(const CSCALCTDigi&, const CSCCLCTDigi&) const;
0231 
0232   // CLCT pattern number: encodes the pattern number itself
0233   unsigned int encodePattern(const int clctPattern) const;
0234 
0235   /** Dump TMB/MPC configuration parameters. */
0236   void dumpConfigParams() const;
0237 
0238   /* match cathode shower and anode shower with and/or logic */
0239   void matchShowers(CSCShowerDigi* anode_showers, CSCShowerDigi* cathode_showers, bool andlogic);
0240 
0241   /* encode high multiplicity bits for Run-3 exotic triggers */
0242   void encodeHighMultiplicityBits();
0243 };
0244 #endif