Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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                          CSCBaseboard::Parameters& 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   /** Clears the LCT containers. */
0061   void clear();
0062 
0063   /** Runs the LCT processor code. Called in normal running -- gets info from
0064       a collection of comparator digis. */
0065   std::vector<CSCCLCTDigi> run(const CSCComparatorDigiCollection* compdc,
0066                                const CSCChamber* chamber,
0067                                const CSCL1TPLookupTableCCLUT* lookupTable);
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            const CSCL1TPLookupTableCCLUT* lookupTable);
0073 
0074   /** Returns vector of CLCTs in the read-out time window, if any. */
0075   std::vector<CSCCLCTDigi> readoutCLCTs() const;
0076 
0077   /** Returns vector of all found CLCTs, if any. */
0078   std::vector<CSCCLCTDigi> getCLCTs() const;
0079 
0080   /** get best/second best CLCT
0081    * Note: CLCT has BX shifted */
0082   CSCCLCTDigi getBestCLCT(int bx) const;
0083   CSCCLCTDigi getSecondCLCT(int bx) const;
0084 
0085   /* get the flag of local shower around best CLCT at bx */
0086   bool getLocalShowerFlag(int bx) const;
0087 
0088   std::vector<int> preTriggerBXs() const { return thePreTriggerBXs; }
0089 
0090   /** read out CLCTs in ME1a , ME1b */
0091   std::vector<CSCCLCTPreTriggerDigi> preTriggerDigis() const { return thePreTriggerDigis; }
0092 
0093   /* get special bits for high multiplicity triggers */
0094   //unsigned getInTimeHMT() const { return inTimeHMT_; }
0095   //unsigned getOutTimeHMT() const { return outTimeHMT_; }
0096   /* get array of high multiplicity triggers */
0097   std::vector<CSCShowerDigi> getAllShower() const;
0098 
0099   /** Returns shower bits */
0100   std::vector<CSCShowerDigi> readoutShower() const;
0101 
0102 protected:
0103   /** Best LCT in this chamber, as found by the processor. */
0104   CSCCLCTDigi bestCLCT[CSCConstants::MAX_CLCT_TBINS];
0105 
0106   /** Second best LCT in this chamber, as found by the processor. */
0107   CSCCLCTDigi secondCLCT[CSCConstants::MAX_CLCT_TBINS];
0108 
0109   CSCShowerDigi cathode_showers_[CSCConstants::MAX_CLCT_TBINS];
0110   //CSCShowerDigi shower_;
0111 
0112   /* flag of shower around best CLCT in each BX */
0113   bool localShowerFlag[CSCConstants::MAX_CLCT_TBINS];
0114 
0115   /** Access routines to comparator digis. */
0116   bool getDigis(const CSCComparatorDigiCollection* compdc);
0117   void getDigis(const CSCComparatorDigiCollection* compdc, const CSCDetId& id);
0118 
0119   /** Set default values for configuration parameters. */
0120   void setDefaultConfigParameters();
0121 
0122   /** Make sure that the parameter values are within the allowed range. */
0123   void checkConfigParameters();
0124 
0125   //---------------- Methods common to all firmware versions ------------------
0126   // Single-argument version for TMB07 (halfstrip-only) firmware.
0127   // Takes the comparator & time info and stuffs it into halfstrip vector.
0128   // Multiple hits on the same strip are allowed.
0129   void readComparatorDigis(
0130       std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]);
0131   void pulseExtension(
0132       const std::vector<int> time[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]);
0133 
0134   //--------------- Functions for post-2007 version of the firmware -----------
0135   virtual std::vector<CSCCLCTDigi> findLCTs(
0136       const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER],
0137       const CSCL1TPLookupTableCCLUT* lookupTable);
0138 
0139   /* Check all half-strip pattern envelopes simultaneously, on every clock cycle, for a matching pattern
0140      Returns true if a pretrigger was found, and the first BX of the pretrigger */
0141   virtual bool preTrigger(const int start_bx, int& first_bx);
0142 
0143   /* For a given clock cycle, check each half-strip if a pattern matches
0144      This function determines best_pid_ and nhits_ for each half-strip */
0145   bool patternFinding(const unsigned int bx_time,
0146                       std::map<int, std::map<int, CSCCLCTDigi::ComparatorContainer> >& hits_in_patterns);
0147 
0148   void cleanComparatorContainer(CSCCLCTDigi& lct) const;
0149 
0150   /* Mark the half-strips around the best half-strip as busy */
0151   void markBusyKeys(const int best_hstrip,
0152                     const int best_patid,
0153                     int quality[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]);
0154 
0155   // build a new CLCT trigger
0156   CSCCLCTDigi constructCLCT(const int bx,
0157                             const unsigned halfstrip_withstagger,
0158                             const CSCCLCTDigi::ComparatorContainer& hits,
0159                             const CSCL1TPLookupTableCCLUT* lookupTable);
0160 
0161   // build a new CLCT pretrigger
0162   CSCCLCTPreTriggerDigi constructPreCLCT(const int bx, const unsigned halfstrip, const unsigned index) const;
0163 
0164   // resets ispretrig_
0165   void clearPreTriggers();
0166   //--------------------------- Auxiliary methods -----------------------------
0167   /** Dump CLCT configuration parameters. */
0168   void dumpConfigParams() const;
0169 
0170   /** Dump half-strip digis */
0171   void dumpDigis(
0172       const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]) const;
0173 
0174   /* check whether there is a shower around best CLCT */
0175   void checkLocalShower(
0176       int zone,
0177       const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER]);
0178 
0179   void encodeHighMultiplicityBits();
0180 
0181   //--------------------------- Member variables -----------------------------
0182 
0183   PulseArray pulse_;
0184 
0185   /* best pattern Id for a given half-strip */
0186   unsigned int best_pid[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER];
0187 
0188   /* number of layers hit on a given half-strip */
0189   unsigned int nhits[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER];
0190 
0191   /* does a given half-strip have a pre-trigger? */
0192   bool ispretrig_[CSCConstants::MAX_NUM_HALF_STRIPS_RUN2_TRIGGER];
0193 
0194   // actual LUT used
0195   CSCPatternBank::LCTPatterns clct_pattern_ = {};
0196 
0197   /* number of strips used in this processor */
0198   int numStrips_;
0199   int numCFEBs_;
0200   int numHalfStrips_;
0201 
0202   /* Is the layer in the chamber staggered? */
0203   int stagger[CSCConstants::NUM_LAYERS];
0204 
0205   std::vector<CSCComparatorDigi> digiV[CSCConstants::NUM_LAYERS];
0206   std::vector<int> thePreTriggerBXs;
0207   std::vector<CSCCLCTPreTriggerDigi> thePreTriggerDigis;
0208 
0209   /* data members for high multiplicity triggers */
0210   std::vector<unsigned> thresholds_;
0211   unsigned showerNumTBins_;
0212   unsigned minLayersCentralTBin_;
0213   unsigned minbx_readout_;
0214   unsigned maxbx_readout_;
0215   /** check the peak of total hits and single bx hits for cathode HMT */
0216   bool peakCheck_;
0217 
0218   /** Configuration parameters. */
0219   unsigned int fifo_tbins, fifo_pretrig;  // only for test beam mode.
0220   unsigned int hit_persist, drift_delay;
0221   unsigned int nplanes_hit_pretrig, nplanes_hit_pattern;
0222   unsigned int pid_thresh_pretrig, min_separation;
0223   unsigned int tmb_l1a_window_size;
0224 
0225   /** VK: some quick and dirty fix to reduce CLCT deadtime */
0226   int start_bx_shift;
0227 
0228   /* define the region around best CLCT to check local shower */
0229   int localShowerZone;
0230 
0231   /* threshold of total hits for local shower */
0232   int localShowerThresh;
0233 
0234   /** VK: separate handle for early time bins */
0235   int early_tbins;
0236 
0237   /** VK: whether to readout only the earliest two LCTs in readout window */
0238   bool readout_earliest_2;
0239 
0240   /** Default values of configuration parameters. */
0241   static const unsigned int def_fifo_tbins, def_fifo_pretrig;
0242   static const unsigned int def_hit_persist, def_drift_delay;
0243   static const unsigned int def_nplanes_hit_pretrig;
0244   static const unsigned int def_nplanes_hit_pattern;
0245   static const unsigned int def_pid_thresh_pretrig, def_min_separation;
0246   static const unsigned int def_tmb_l1a_window_size;
0247 
0248   /* quality control */
0249   std::unique_ptr<LCTQualityControl> qualityControl_;
0250 
0251   /* comparator-code lookup table algorithm */
0252   std::unique_ptr<ComparatorCodeLUT> cclut_;
0253 };
0254 
0255 #endif