Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef L1Trigger_CSCTriggerPrimitives_CSCAnodeLCTProcessor_h
0002 #define L1Trigger_CSCTriggerPrimitives_CSCAnodeLCTProcessor_h
0003 
0004 /** \class CSCAnodeLCTProcessor
0005  *
0006  * This class simulates the functionality of the anode LCT card. It is run by
0007  * the MotherBoard and returns up to two AnodeLCTs.  It can be run either in a
0008  * test mode, where it is passed an array of wire times, or in normal mode
0009  * where it determines the wire times from the wire digis.
0010  *
0011  *    This is the simulation for the Anode LCT Processor for the Level-1
0012  *    Trigger.  This processor consists of several stages:
0013  *
0014  *      1. Pulse extension of signals coming from wires.
0015  *      2. Pretrigger for each key-wire.
0016  *      3. Pattern detector if a pretrigger is found for the given key-wire.
0017  *      4. Ghost Cancellation Logic (GCL).
0018  *      5. Best track search and promotion.
0019  *      6. Second best track search and promotion.
0020  *
0021  *    The inputs to the ALCT Processor are wire digis.
0022  *     The output is up to two ALCT digi words.
0023  *
0024  * \author Benn Tannenbaum  benn@physics.ucla.edu 13 July 1999
0025  * Numerous later improvements by Jason Mumford and Slava Valuev (see cvs
0026  * in ORCA).
0027  * Porting from ORCA by S. Valuev (Slava.Valuev@cern.ch), May 2006.
0028  *
0029  * Updates for high pileup running by Vadim Khotilovich (TAMU), December 2012
0030  *
0031  * Updates for integrated local trigger with GEMs by
0032  * Sven Dildick (TAMU) and Tao Huang (TAMU), April 2015
0033  *
0034  * Removing usage of outdated class CSCTriggerGeometry by Sven Dildick (TAMU)
0035  */
0036 
0037 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
0038 #include "DataFormats/CSCDigi/interface/CSCALCTDigi.h"
0039 #include "DataFormats/CSCDigi/interface/CSCALCTPreTriggerDigi.h"
0040 #include "DataFormats/CSCDigi/interface/CSCShowerDigi.h"
0041 #include "CondFormats/CSCObjects/interface/CSCDBL1TPParameters.h"
0042 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCBaseboard.h"
0043 #include "L1Trigger/CSCTriggerPrimitives/interface/LCTQualityControl.h"
0044 #include "L1Trigger/CSCTriggerPrimitives/interface/PulseArray.h"
0045 
0046 #include <vector>
0047 
0048 class CSCAnodeLCTProcessor : public CSCBaseboard {
0049 public:
0050   /** Normal constructor. */
0051   CSCAnodeLCTProcessor(unsigned endcap,
0052                        unsigned station,
0053                        unsigned sector,
0054                        unsigned subsector,
0055                        unsigned chamber,
0056                        const edm::ParameterSet& conf);
0057 
0058   /** Default destructor. */
0059   ~CSCAnodeLCTProcessor() override = default;
0060 
0061   /** Sets configuration parameters obtained via EventSetup mechanism. */
0062   void setConfigParameters(const CSCDBL1TPParameters* conf);
0063 
0064   /** Clears the LCT containers. */
0065   void clear();
0066 
0067   // This is the main routine for normal running.  It gets wire times
0068   // from the wire digis and then passes them on to another run() function.
0069   std::vector<CSCALCTDigi> run(const CSCWireDigiCollection* wiredc);
0070 
0071   // This version of the run() function can either be called in a standalone
0072   // test, being passed the time array, or called by the run() function above.
0073   // It gets wire times from an input array and then loops over the keywires.
0074   // All found LCT candidates are sorted and the best two are retained.
0075   void run(const std::vector<int> wire[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_WIREGROUPS]);
0076 
0077   /** Returns vector of ALCTs in the read-out time window, if any. */
0078   std::vector<CSCALCTDigi> readoutALCTs() const;
0079 
0080   /** Returns vector of all found ALCTs, if any. */
0081   std::vector<CSCALCTDigi> getALCTs() const;
0082 
0083   /** read out pre-ALCTs */
0084   std::vector<CSCALCTPreTriggerDigi> preTriggerDigis() const { return thePreTriggerDigis; }
0085 
0086   /** Return best/second best ALCTs */
0087   CSCALCTDigi getBestALCT(int bx) const;
0088   CSCALCTDigi getSecondALCT(int bx) const;
0089 
0090   /* get array of high multiplicity triggers */
0091   std::vector<CSCShowerDigi> getAllShower() const;
0092 
0093   /** Returns shower bits */
0094   std::vector<CSCShowerDigi> readoutShower() const;
0095 
0096 protected:
0097   /** Best LCTs in this chamber, as found by the processor.
0098       In old ALCT algorithms, up to two best ALCT per Level-1 accept window
0099       had been reported.
0100       In the ALCT-2006 algorithms, up to two best ALCTs PER EVERY TIME BIN in
0101       Level-1 accept window are reported. */
0102   CSCALCTDigi bestALCT[CSCConstants::MAX_ALCT_TBINS];
0103 
0104   /** Second best LCTs in this chamber, as found by the processor. */
0105   CSCALCTDigi secondALCT[CSCConstants::MAX_ALCT_TBINS];
0106 
0107   PulseArray pulse_;
0108 
0109   CSCShowerDigi anode_showers_[CSCConstants::MAX_ALCT_TBINS];
0110 
0111   /** Access routines to wire digis. */
0112   bool getDigis(const CSCWireDigiCollection* wiredc);
0113   void getDigis(const CSCWireDigiCollection* wiredc, const CSCDetId& id);
0114 
0115   int numWireGroups;
0116   int MESelection;
0117 
0118   int first_bx[CSCConstants::MAX_NUM_WIREGROUPS];
0119   int first_bx_corrected[CSCConstants::MAX_NUM_WIREGROUPS];
0120 
0121   int quality[CSCConstants::MAX_NUM_WIREGROUPS][CSCConstants::NUM_ALCT_PATTERNS];
0122   std::vector<CSCWireDigi> digiV[CSCConstants::NUM_LAYERS];
0123 
0124   std::vector<CSCALCTDigi> lct_list;
0125 
0126   std::vector<CSCALCTPreTriggerDigi> thePreTriggerDigis;
0127 
0128   /* data members for high multiplicity triggers */
0129   void encodeHighMultiplicityBits();
0130   std::vector<unsigned> thresholds_;
0131   unsigned showerNumTBins_;
0132   unsigned minLayersCentralTBin_;
0133   unsigned minbx_readout_;
0134   unsigned maxbx_readout_;
0135 
0136   /** Configuration parameters. */
0137   unsigned int fifo_tbins, fifo_pretrig, drift_delay;
0138   unsigned int nplanes_hit_pretrig, nplanes_hit_accel_pretrig;
0139   unsigned int nplanes_hit_pattern, nplanes_hit_accel_pattern;
0140   unsigned int trig_mode, accel_mode, l1a_window_width;
0141 
0142   /** Phase2: hit persistency length */
0143   unsigned int hit_persist;
0144 
0145   /** Phase2: separate handle for early time bins */
0146   int early_tbins;
0147 
0148   /** Phase2: delta BX time depth for ghostCancellationLogic */
0149   int ghost_cancellation_bx_depth;
0150 
0151   /** Phase2: whether to consider ALCT candidates' qualities
0152       while doing ghostCancellationLogic on +-1 wire groups */
0153   bool ghost_cancellation_side_quality;
0154 
0155   /** Phase2: deadtime clocks after pretrigger (extra in addition to drift_delay) */
0156   unsigned int pretrig_extra_deadtime;
0157 
0158   /** Phase2: whether to use corrected_bx instead of pretrigger BX */
0159   bool use_corrected_bx;
0160 
0161   /** Phase2: whether to use narrow pattern mask for the rings close to the beam */
0162   bool narrow_mask_r1;
0163 
0164   /** Default values of configuration parameters. */
0165   static const unsigned int def_fifo_tbins, def_fifo_pretrig;
0166   static const unsigned int def_drift_delay;
0167   static const unsigned int def_nplanes_hit_pretrig, def_nplanes_hit_pattern;
0168   static const unsigned int def_nplanes_hit_accel_pretrig;
0169   static const unsigned int def_nplanes_hit_accel_pattern;
0170   static const unsigned int def_trig_mode, def_accel_mode;
0171   static const unsigned int def_l1a_window_width;
0172 
0173   /* quality control */
0174   std::unique_ptr<LCTQualityControl> qualityControl_;
0175 
0176   /** Chosen pattern mask. */
0177   CSCPatternBank::LCTPatterns alct_pattern_ = {};
0178 
0179   /** Load pattern mask defined by configuration into pattern_mask */
0180   void loadPatternMask();
0181 
0182   /** Set default values for configuration parameters. */
0183   void setDefaultConfigParameters();
0184 
0185   /** Make sure that the parameter values are within the allowed range. */
0186   void checkConfigParameters();
0187 
0188   /** Clears the quality for a given wire and pattern if it is a ghost. */
0189   void clear(const int wire, const int pattern);
0190 
0191   /* Gets wire times from the wire digis and fills wire[][] vector */
0192   void readWireDigis(std::vector<int> wire[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_WIREGROUPS]);
0193 
0194   /* A pulse array will be used as a bit representation of hit times.
0195      For example: if a keywire has a bx_time of 3, then 1 shifted
0196      left 3 will be bit pattern 0000000000001000.  Bits are then added to
0197      signify the duration of a signal (hit_persist, formerly bx_width).  So
0198      for the pulse with a hit_persist of 6 will look like 0000000111111000. */
0199   bool pulseExtension(const std::vector<int> wire[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_WIREGROUPS]);
0200 
0201   /* Check that there are nplanes_hit_pretrig or more layers hit in collision
0202      or accelerator patterns for a particular key_wire.  If so, return
0203      true and the PatternDetection process will start. */
0204   bool preTrigger(const int key_wire, const int start_bx);
0205 
0206   /* See if there is a pattern that satisfies nplanes_hit_pattern number of
0207      layers hit for either the accelerator or collision patterns.  Use
0208      the pattern with the best quality. */
0209   bool patternDetection(const int key_wire,
0210                         std::map<int, std::map<int, CSCALCTDigi::WireContainer> >& hits_in_patterns);
0211 
0212   // remove the invalid wires from the container
0213   void cleanWireContainer(CSCALCTDigi::WireContainer& wireHits) const;
0214 
0215   //  set the wire hit container
0216   void setWireContainer(CSCALCTDigi&, CSCALCTDigi::WireContainer& wireHits) const;
0217 
0218   /* In older versions of the ALCT emulation, the ghost cancellation was performed after
0219      the ALCTs were found. In December 2018 it became clear that during the study of data
0220      and emulation comparison on 2018 data, a small disagreement between data and emulation
0221      was found. The changes we implemented then allow re-triggering on one wiregroup after
0222      some dead time once an earlier ALCT was constructed built on this wiregroup. Before this
0223      commit the ALCT processor would prohibit the wiregroup from triggering in one event after
0224      an ALCT was found on that wiregroup. In the firwmare, the wiregroup with ALCT is only dead
0225      for a few BX before it can be triggered by next muon. The implementation of ghost cancellation
0226      logic wqas changed to accommodate the re-triggering change while the idea of the ghost
0227      cancellation logic is kept the same.
0228   */
0229   virtual void ghostCancellationLogicOneWire(const int key_wire, int* ghost_cleared);
0230 
0231   virtual int getTempALCTQuality(int temp_quality) const;
0232 
0233   void lctSearch();
0234   /* Function which enables/disables either collision or accelerator tracks.
0235      The function uses the trig_mode parameter to decide. */
0236   void trigMode(const int key_wire);
0237 
0238   /* Function which gives a preference either to the collision patterns
0239      or accelerator patterns.  The function uses the accel_mode parameter
0240      to decide. */
0241   void accelMode(const int key_wire);
0242 
0243   /* Selects two collision and two accelerator ALCTs per time bin with
0244      the best quality. */
0245   std::vector<CSCALCTDigi> bestTrackSelector(const std::vector<CSCALCTDigi>& all_alcts);
0246 
0247   /* This method should have been an overloaded > operator, but we
0248      have to keep it here since need to check values in quality[][]
0249      array modified according to accel_mode parameter. */
0250   bool isBetterALCT(const CSCALCTDigi& lhsALCT, const CSCALCTDigi& rhsALCT) const;
0251 
0252   /** Dump ALCT configuration parameters. */
0253   void dumpConfigParams() const;
0254 
0255   /** Dump digis on wire groups. */
0256   void dumpDigis(const std::vector<int> wire[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_WIREGROUPS]) const;
0257 
0258   void showPatterns(const int key_wire);
0259 };
0260 
0261 #endif