Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef L1Trigger_CSCTriggerPrimitives_CSCCathodeLCTProcessor_h
0002 #define L1Trigger_CSCTriggerPrimitives_CSCCathodeLCTProcessor_h
0003 
0004 /** \class CSCCathodeLCTProcessor
0005  *
0006  * This class simulates the functionality of the cathode LCT card. It is run by
0007  * the MotherBoard and returns up to two CathodeLCTs.  It can be run either in
0008  * a test mode, where it is passed arrays of halfstrip times,
0009  * or in normal mode where it determines the time and comparator
0010  * information from the comparator digis.
0011  *
0012  * The CathodeLCTs only come halfstrip flavors
0013  *
0014  * \date May 2001  Removed the card boundaries.  Changed the Pretrigger to
0015  * emulate the hardware electronic logic.  Also changed the keylayer to be
0016  * the 4th layer in a chamber instead of the 3rd layer from the interaction
0017  * region. The code is a more realistic simulation of hardware LCT logic now.
0018  * -Jason Mumford.
0019  *
0020  * \author Benn Tannenbaum  UCLA 13 July 1999 benn@physics.ucla.edu
0021  * Numerous later improvements by Jason Mumford and Slava Valuev (see cvs
0022  * in ORCA).
0023  * Porting from ORCA by S. Valuev (Slava.Valuev@cern.ch), May 2006.
0024  *
0025  * Updates for high pileup running by Vadim Khotilovich (TAMU), December 2012
0026  *
0027  * Updates for integrated local trigger with GEMs by
0028  * Sven Dildick (TAMU) and Tao Huang (TAMU), April 2015
0029  *
0030  * Removing usage of outdated class CSCTriggerGeometry by Sven Dildick (TAMU)
0031  */
0032 
0033 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
0034 #include "DataFormats/CSCDigi/interface/CSCCLCTDigi.h"
0035 #include "DataFormats/CSCDigi/interface/CSCCLCTPreTriggerDigi.h"
0036 #include "DataFormats/CSCDigi/interface/CSCShowerDigi.h"
0037 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCBaseboard.h"
0038 #include "L1Trigger/CSCTriggerPrimitives/interface/LCTQualityControl.h"
0039 #include "L1Trigger/CSCTriggerPrimitives/interface/ComparatorCodeLUT.h"
0040 #include "L1Trigger/CSCTriggerPrimitives/interface/PulseArray.h"
0041 
0042 #include <vector>
0043 
0044 class CSCCathodeLCTProcessor : public CSCBaseboard {
0045 public:
0046   /** Normal constructor. */
0047   CSCCathodeLCTProcessor(unsigned endcap,
0048                          unsigned station,
0049                          unsigned sector,
0050                          unsigned subsector,
0051                          unsigned chamber,
0052                          const edm::ParameterSet& conf);
0053 
0054   /** Default destructor. */
0055   ~CSCCathodeLCTProcessor() override = default;
0056 
0057   /** Sets configuration parameters obtained via EventSetup mechanism. */
0058   void setConfigParameters(const CSCDBL1TPParameters* conf);
0059 
0060   void setESLookupTables(const CSCL1TPLookupTableCCLUT* conf);
0061 
0062   /** Clears the LCT containers. */
0063   void clear();
0064 
0065   /** Runs the LCT processor code. Called in normal running -- gets info from
0066       a collection of comparator digis. */
0067   std::vector<CSCCLCTDigi> run(const CSCComparatorDigiCollection* compdc);
0068 
0069   /** Called in test mode and by the run(compdc) function; does the actual LCT
0070       finding. */
0071   void run(const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]);
0072 
0073   /** Returns vector of CLCTs in the read-out time window, if any. */
0074   std::vector<CSCCLCTDigi> readoutCLCTs() const;
0075 
0076   /** Returns vector of all found CLCTs, if any. */
0077   std::vector<CSCCLCTDigi> getCLCTs() const;
0078 
0079   /** get best/second best CLCT
0080    * Note: CLCT has BX shifted */
0081   CSCCLCTDigi getBestCLCT(int bx) const;
0082   CSCCLCTDigi getSecondCLCT(int bx) const;
0083 
0084   std::vector<int> preTriggerBXs() const { return thePreTriggerBXs; }
0085 
0086   /** read out CLCTs in ME1a , ME1b */
0087   std::vector<CSCCLCTPreTriggerDigi> preTriggerDigis() const { return thePreTriggerDigis; }
0088 
0089   /* get special bits for high multiplicity triggers */
0090   //unsigned getInTimeHMT() const { return inTimeHMT_; }
0091   //unsigned getOutTimeHMT() const { return outTimeHMT_; }
0092   /* get array of high multiplicity triggers */
0093   std::vector<CSCShowerDigi> getAllShower() const;
0094 
0095   /** Returns shower bits */
0096   std::vector<CSCShowerDigi> readoutShower() const;
0097 
0098 protected:
0099   /** Best LCT in this chamber, as found by the processor. */
0100   CSCCLCTDigi bestCLCT[CSCConstants::MAX_CLCT_TBINS];
0101 
0102   /** Second best LCT in this chamber, as found by the processor. */
0103   CSCCLCTDigi secondCLCT[CSCConstants::MAX_CLCT_TBINS];
0104 
0105   CSCShowerDigi cathode_showers_[CSCConstants::MAX_CLCT_TBINS];
0106   //CSCShowerDigi shower_;
0107 
0108   /** Access routines to comparator digis. */
0109   bool getDigis(const CSCComparatorDigiCollection* compdc);
0110   void getDigis(const CSCComparatorDigiCollection* compdc, const CSCDetId& id);
0111 
0112   /** Set default values for configuration parameters. */
0113   void setDefaultConfigParameters();
0114 
0115   /** Make sure that the parameter values are within the allowed range. */
0116   void checkConfigParameters();
0117 
0118   //---------------- Methods common to all firmware versions ------------------
0119   // Single-argument version for TMB07 (halfstrip-only) firmware.
0120   // Takes the comparator & time info and stuffs it into halfstrip vector.
0121   // Multiple hits on the same strip are allowed.
0122   void readComparatorDigis(
0123       std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]);
0124   void pulseExtension(
0125       const std::vector<int> time[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]);
0126 
0127   //--------------- Functions for post-2007 version of the firmware -----------
0128   virtual std::vector<CSCCLCTDigi> findLCTs(
0129       const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]);
0130 
0131   /* Check all half-strip pattern envelopes simultaneously, on every clock cycle, for a matching pattern
0132      Returns true if a pretrigger was found, and the first BX of the pretrigger */
0133   virtual bool preTrigger(const int start_bx, int& first_bx);
0134 
0135   /* For a given clock cycle, check each half-strip if a pattern matches
0136      This function determines best_pid_ and nhits_ for each half-strip */
0137   bool patternFinding(const unsigned int bx_time,
0138                       std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer> >& hits_in_patterns);
0139 
0140   void cleanComparatorContainer(CSCCLCTDigi& lct) const;
0141 
0142   /* Mark the half-strips around the best half-strip as busy */
0143   void markBusyKeys(const int best_hstrip,
0144                     const int best_patid,
0145                     int quality[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]);
0146 
0147   // build a new CLCT trigger
0148   CSCCLCTDigi constructCLCT(const int bx,
0149                             const unsigned halfstrip_withstagger,
0150                             const CSCCLCTDigi::ComparatorContainer& hits);
0151 
0152   // build a new CLCT pretrigger
0153   CSCCLCTPreTriggerDigi constructPreCLCT(const int bx, const unsigned halfstrip, const unsigned index) const;
0154 
0155   // resets ispretrig_
0156   void clearPreTriggers();
0157   //--------------------------- Auxiliary methods -----------------------------
0158   /** Dump CLCT configuration parameters. */
0159   void dumpConfigParams() const;
0160 
0161   /** Dump half-strip digis */
0162   void dumpDigis(
0163       const std::vector<int> strip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) const;
0164 
0165   //--------------------------- Member variables -----------------------------
0166 
0167   PulseArray pulse_;
0168 
0169   /* best pattern Id for a given half-strip */
0170   unsigned int best_pid[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER];
0171 
0172   /* number of layers hit on a given half-strip */
0173   unsigned int nhits[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER];
0174 
0175   /* does a given half-strip have a pre-trigger? */
0176   bool ispretrig_[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER];
0177 
0178   // actual LUT used
0179   CSCPatternBank::LCTPatterns clct_pattern_ = {};
0180 
0181   /* number of strips used in this processor */
0182   int numStrips_;
0183   int numCFEBs_;
0184   int numHalfStrips_;
0185 
0186   /* Is the layer in the chamber staggered? */
0187   int stagger[CSCConstants::NUM_LAYERS];
0188 
0189   std::vector<CSCComparatorDigi> digiV[CSCConstants::NUM_LAYERS];
0190   std::vector<int> thePreTriggerBXs;
0191   std::vector<CSCCLCTPreTriggerDigi> thePreTriggerDigis;
0192 
0193   /* data members for high multiplicity triggers */
0194   void encodeHighMultiplicityBits();
0195   std::vector<unsigned> thresholds_;
0196   unsigned showerNumTBins_;
0197   unsigned minLayersCentralTBin_;
0198   unsigned minbx_readout_;
0199   unsigned maxbx_readout_;
0200   /** check the peak of total hits and single bx hits for cathode HMT */
0201   bool peakCheck_;
0202 
0203   /** Configuration parameters. */
0204   unsigned int fifo_tbins, fifo_pretrig;  // only for test beam mode.
0205   unsigned int hit_persist, drift_delay;
0206   unsigned int nplanes_hit_pretrig, nplanes_hit_pattern;
0207   unsigned int pid_thresh_pretrig, min_separation;
0208   unsigned int tmb_l1a_window_size;
0209 
0210   /** VK: some quick and dirty fix to reduce CLCT deadtime */
0211   int start_bx_shift;
0212 
0213   /** VK: separate handle for early time bins */
0214   int early_tbins;
0215 
0216   /** VK: whether to readout only the earliest two LCTs in readout window */
0217   bool readout_earliest_2;
0218 
0219   /** Default values of configuration parameters. */
0220   static const unsigned int def_fifo_tbins, def_fifo_pretrig;
0221   static const unsigned int def_hit_persist, def_drift_delay;
0222   static const unsigned int def_nplanes_hit_pretrig;
0223   static const unsigned int def_nplanes_hit_pattern;
0224   static const unsigned int def_pid_thresh_pretrig, def_min_separation;
0225   static const unsigned int def_tmb_l1a_window_size;
0226 
0227   /* quality control */
0228   std::unique_ptr<LCTQualityControl> qualityControl_;
0229 
0230   /* comparator-code lookup table algorithm */
0231   std::unique_ptr<ComparatorCodeLUT> cclut_;
0232 };
0233 
0234 #endif