CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/L1Trigger/CSCTriggerPrimitives/src/CSCCathodeLCTProcessor.h

Go to the documentation of this file.
00001 #ifndef CSCTriggerPrimitives_CSCCathodeLCTProcessor_h
00002 #define CSCTriggerPrimitives_CSCCathodeLCTProcessor_h
00003 
00030 #include <vector>
00031 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00032 #include <DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h>
00033 #include <DataFormats/CSCDigi/interface/CSCCLCTDigi.h>
00034 #include <CondFormats/CSCObjects/interface/CSCDBL1TPParameters.h>
00035 #include <L1Trigger/CSCCommonTrigger/interface/CSCConstants.h>
00036 
00037 class CSCCathodeLCTProcessor
00038 {
00039  public:
00041   CSCCathodeLCTProcessor(unsigned endcap, unsigned station, unsigned sector,
00042                          unsigned subsector, unsigned chamber,
00043                          const edm::ParameterSet& conf,
00044                          const edm::ParameterSet& comm,
00045                          const edm::ParameterSet& ctmb);
00046 
00048   CSCCathodeLCTProcessor();
00049 
00051   void setConfigParameters(const CSCDBL1TPParameters* conf);
00052 
00054   void clear();
00055 
00058   std::vector<CSCCLCTDigi> run(const CSCComparatorDigiCollection* compdc);
00059 
00062   void run(const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00063            const std::vector<int> distrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]);
00064  
00066   bool getDigis(const CSCComparatorDigiCollection* compdc);
00067   void getDigis(const CSCComparatorDigiCollection* compdc, const CSCDetId& id);
00068 
00070   enum {MAX_CLCT_BINS = 16};
00071 
00073   CSCCLCTDigi bestCLCT[MAX_CLCT_BINS];
00074 
00076   CSCCLCTDigi secondCLCT[MAX_CLCT_BINS];
00077 
00079   std::vector<CSCCLCTDigi> readoutCLCTs();
00080 
00082   std::vector<CSCCLCTDigi> getCLCTs();
00083 
00084   std::vector<int> preTriggerBXs() const {return thePreTriggerBXs;}
00085 
00086   static void distripStagger(int stag_triad[CSCConstants::MAX_NUM_STRIPS],
00087                              int stag_time[CSCConstants::MAX_NUM_STRIPS],
00088                              int stag_digi[CSCConstants::MAX_NUM_STRIPS],
00089                              int i_distrip, bool debug = false);
00090 
00094   void setRing(unsigned r) {theRing = r;}
00095 
00097   enum {NUM_PATTERN_STRIPS = 26};
00098   static const int pre_hit_pattern[2][NUM_PATTERN_STRIPS];
00099   static const int pattern[CSCConstants::NUM_CLCT_PATTERNS_PRE_TMB07][NUM_PATTERN_STRIPS+1];
00100 
00101   enum {NUM_PATTERN_HALFSTRIPS = 42};
00102   static const int pattern2007_offset[NUM_PATTERN_HALFSTRIPS];
00103   static const int pattern2007[CSCConstants::NUM_CLCT_PATTERNS][NUM_PATTERN_HALFSTRIPS+2];
00104 
00106   enum {MAX_CFEBS = 5};
00107 
00108   // we use these next ones to address the various bits inside the array that's
00109   // used to make the cathode LCTs.
00110   enum CLCT_INDICES {CLCT_PATTERN, CLCT_BEND, CLCT_STRIP, CLCT_BX,
00111                      CLCT_STRIP_TYPE, CLCT_QUALITY, CLCT_CFEB};
00112 
00113  private:
00118   int infoV;
00119 
00121   const unsigned theEndcap;
00122   const unsigned theStation;
00123   const unsigned theSector;
00124   const unsigned theSubsector;
00125   const unsigned theTrigChamber;
00126   
00127   // holders for easy access:
00128   unsigned int theRing;
00129   unsigned int theChamber;
00130   bool isME11;
00131   
00132   int numStrips;
00133   int stagger[CSCConstants::NUM_LAYERS];
00134 
00135   std::vector<CSCComparatorDigi> digiV[CSCConstants::NUM_LAYERS];
00136   std::vector<int> thePreTriggerBXs;
00137 
00139   bool isMTCC; 
00140 
00142   bool isTMB07;
00143 
00145   bool isSLHC;
00146 
00148   unsigned int fifo_tbins,  fifo_pretrig; // only for test beam mode.
00149   unsigned int hit_persist, drift_delay;
00150   unsigned int nplanes_hit_pretrig, nplanes_hit_pattern;
00151   unsigned int pid_thresh_pretrig,  min_separation;
00152   unsigned int tmb_l1a_window_size;
00153 
00155   int start_bx_shift;
00156 
00158   bool smartME1aME1b, disableME1a, gangedME1a;
00159 
00161   int early_tbins;
00162 
00164   bool use_dead_time_zoning;
00165   unsigned int clct_state_machine_zone; // +- around a keystrip
00166   bool dynamic_state_machine_zone;  //use a pattern dependent zone
00167 
00169   unsigned int pretrig_trig_zone;
00170 
00172   bool use_corrected_bx;
00173 
00175   bool readout_earliest_2;
00176 
00178   static const unsigned int def_fifo_tbins,  def_fifo_pretrig;
00179   static const unsigned int def_hit_persist, def_drift_delay;
00180   static const unsigned int def_nplanes_hit_pretrig;
00181   static const unsigned int def_nplanes_hit_pattern;
00182   static const unsigned int def_pid_thresh_pretrig, def_min_separation;
00183   static const unsigned int def_tmb_l1a_window_size;
00184 
00186   void setDefaultConfigParameters();
00187 
00189   void checkConfigParameters();
00190 
00192   static const int cfeb_strips[2];
00193 
00194   //---------------- Methods common to all firmware versions ------------------
00195   void readComparatorDigis(std::vector<int>halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00196                            std::vector<int> distrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]);
00197   void readComparatorDigis(std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]);
00198   void pulseExtension(
00199  const std::vector<int> time[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00200  const int nStrips,
00201  unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]);
00202 
00203   //------------- Functions for idealized version for MC studies --------------
00204   std::vector<CSCCLCTDigi> findLCTs(
00205      const std::vector<int> strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00206      int stripType);
00207   bool preTrigger(
00208      const std::vector<int> strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00209      const int stripType, const int nStrips, int& first_bx);
00210   void getKeyStripData(
00211      const std::vector<int> strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00212      int keystrip_data[CSCConstants::NUM_HALF_STRIPS][7],
00213      int nStrips, int first_bx, int& best_strip, int stripType);
00214   void getPattern(int pattern_num, int strip_value[NUM_PATTERN_STRIPS],
00215                   int bx_time, int &quality, int &bend);
00216   bool hitIsGood(int hitTime, int BX);
00217 
00218   //-------------------- Functions for pre-2007 firmware ----------------------
00219   std::vector<CSCCLCTDigi> findLCTs(
00220   const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00221   const std::vector<int> distrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]);
00222   bool preTrigger(
00223       const std::vector<int> strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00224    unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00225       const int stripType, const int nStrips,
00226       const int start_bx, int& first_bx);
00227   bool preTrigLookUp(const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00228                      const int stripType, const int nStrips,
00229                      const unsigned int bx_time);
00230   void latchLCTs(const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00231                  int keyStrip[MAX_CFEBS], unsigned int nhits[MAX_CFEBS],
00232                  const int stripType, const int nStrips, const int bx_time);
00233   void priorityEncode(const int h_keyStrip[MAX_CFEBS],
00234                       const unsigned int h_nhits[MAX_CFEBS],
00235                       const int d_keyStrip[MAX_CFEBS],
00236                       const unsigned int d_nhits[MAX_CFEBS],
00237                       int keystrip_data[2][7]);
00238   void getKeyStripData(const unsigned int h_pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00239                        const unsigned int d_pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00240                        int keystrip_data[2][7], const int first_bx);
00241   void getPattern(unsigned int pattern_num,
00242                   const int strip_value[NUM_PATTERN_STRIPS],
00243                   unsigned int& quality, unsigned int& bend);
00244 
00245   //--------------- Functions for 2007 version of the firmware ----------------
00246   std::vector<CSCCLCTDigi> findLCTs(
00247  const std::vector<int> halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]);
00248   bool preTrigger(
00249       const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00250       const int start_bx, int& first_bx);
00251   bool ptnFinding(
00252       const unsigned int pulse[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00253       const int nStrips, const unsigned int bx_time);
00254   void markBusyKeys(const int best_hstrip, const int best_patid,
00255                     int quality[CSCConstants::NUM_HALF_STRIPS]);
00256 
00257   unsigned int best_pid[CSCConstants::NUM_HALF_STRIPS];
00258   unsigned int nhits[CSCConstants::NUM_HALF_STRIPS];
00259   int first_bx_corrected[CSCConstants::NUM_HALF_STRIPS];
00260 
00261   //--------------- Functions for SLHC studies ----------------
00262 
00263   std::vector<CSCCLCTDigi> findLCTsSLHC(
00264     const std::vector<int>  halfstrip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]);
00265 
00266   bool ispretrig[CSCConstants::NUM_HALF_STRIPS];
00267 
00268   //--------------------------- Auxiliary methods -----------------------------
00270   void dumpConfigParams() const;
00271 
00273   void dumpDigis(
00274       const std::vector<int> strip[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS],
00275       const int stripType, const int nStrips) const;
00276 
00277   //--------------------------- Methods for tests -----------------------------
00278   void testDistripStagger();
00279   void testLCTs();
00280   void printPatterns();
00281   void testPatterns();
00282   int findNumLayersHit(std::vector<int> stripsHit[CSCConstants::NUM_LAYERS][CSCConstants::NUM_HALF_STRIPS]);
00283 };
00284 
00285 #endif