L1MuGMTCand

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
//-------------------------------------------------
//
/**  \class L1MuGMTCand
 *
 *   L1 Global Muon Trigger Candidate.
 *
 *   This candidate contains only information sent to the GT.
*/
//
//
//   Author :
//   H. Sakulin               HEPHY Vienna
//   N. Neumeister            CERN EP
//
//   Migrated to CMSSW:
//   I. Mikulec
//
//--------------------------------------------------
#ifndef DataFormatsL1GlobalMuonTrigger_L1MuGMTCand_h
#define DataFormatsL1GlobalMuonTrigger_L1MuGMTCand_h

//---------------
// C++ Headers --
//---------------
#include <string>

//----------------------
// Base Class Headers --
//----------------------

//------------------------------------
// Collaborating Class Declarations --
//------------------------------------

//              ---------------------
//              -- Class Interface --
//              ---------------------

class L1MuGMTCand {
public:
  /// constructor
  L1MuGMTCand();

  /// constructor from dataword
  L1MuGMTCand(unsigned data, int bx = 0);

  /// copy constructor
  L1MuGMTCand(const L1MuGMTCand&);

  /// assignment operator
  L1MuGMTCand& operator=(const L1MuGMTCand&) = default;

  /// destructor
  virtual ~L1MuGMTCand();

  /// reset muon candidate
  void reset();

  //
  // Getters
  //

  /// is it an empty  muon candidate?
  bool empty() const { return readDataField(PT_START, PT_LENGTH) == 0; }

  /// get muon data word
  unsigned getDataWord() const { return m_dataWord; }

  /// get name of object
  std::string name() const { return m_name; }

  /// get phi-code
  unsigned int phiIndex() const { return readDataField(PHI_START, PHI_LENGTH); }

  /// get pt-code
  unsigned int ptIndex() const { return readDataField(PT_START, PT_LENGTH); }

  /// get quality

  /// Quality codes:
  ///
  /// 0 .. no muon
  /// 1 .. beam halo muon (CSC)
  /// 2 .. very low quality level 1 (e.g. ignore in single and di-muon trigger)
  /// 3 .. very low quality level 2 (e.g. ignore in single muon trigger use in di-muon trigger)
  /// 4 .. very low quality level 3 (e.g. ignore in di-muon trigger, use in single-muon trigger)
  /// 5 .. unmatched RPC
  /// 6 .. unmatched DT or CSC
  /// 7 .. matched DT-RPC or CSC-RPC
  ///
  /// attention: try not to rely on quality codes in analysis: they may change again
  ///
  unsigned int quality() const { return readDataField(QUAL_START, QUAL_LENGTH); }

  /// interpretation of quality code: is the candidate to be used in a single muon trigger ?
  bool useInSingleMuonTrigger() const { return quality() >= 4; };

  /// interpretation of quality code: is the candidate to be used in a di-muon trigger ?
  bool useInDiMuonTrigger() const { return (quality() >= 3) && (quality() != 4); };

  /// interpretation of quality code: is the candidate a matched candidate ?
  bool isMatchedCand() const { return quality() == 7; }

  /// interpretation of quality code: is the candidate a beam halo muon ?
  bool isHaloCand() const { return quality() == 1; }

  /// get eta-code
  unsigned int etaIndex() const { return readDataField(ETA_START, ETA_LENGTH); }

  /// get charge/synchronization word (0=POS, 1=NEG, 2=UNDEF, 3=SYNC)
  unsigned sysign() const { return readDataField(SYSIGN_START, SYSIGN_LENGTH); }

  /// get isolation
  bool isol() const { return readDataField(ISO_START, ISO_LENGTH) == 1; }

  /// get mip
  bool mip() const { return readDataField(MIP_START, MIP_LENGTH) == 1; }

  /// get bunch crossing identifier
  int bx() const { return m_bx; }

  /// get phi-value of muon candidate in radians (low edge of bin)
  /// this functionality will be moved to an extra Producer
  float phiValue() const;

  /// get eta-value of muon candidate
  /// this functionality will be moved to an extra Producer
  float etaValue() const;

  /// get pt-value of muon candidate in GeV
  /// this functionality will be moved to an extra Producer
  float ptValue() const;

  /// get charge (+1  -1)
  int charge() const { return (readDataField(SYSIGN_START, SYSIGN_LENGTH) & 1) == 0 ? 1 : -1; }

  /// is the charge valid ?
  bool charge_valid() const {
    unsigned sysign = readDataField(SYSIGN_START, SYSIGN_LENGTH);
    return (sysign == 0 || sysign == 1);
  }

  /// is the candidate a sync word
  bool isSyncWord() const { return readDataField(SYSIGN_START, SYSIGN_LENGTH) == 3; }

  ///
  /// Setters
  ///

  /// set packed phi-code of muon candidate
  void setPhiPacked(unsigned phi) { writeDataField(PHI_START, PHI_LENGTH, phi); }

  /// set packed pt-code of muon candidate
  void setPtPacked(unsigned pt) { writeDataField(PT_START, PT_LENGTH, pt); }

  /// set quality of muon candidate
  void setQuality(unsigned quality) { writeDataField(QUAL_START, QUAL_LENGTH, quality); }

  /// set packed eta-code of muon candidate
  void setEtaPacked(unsigned eta) { writeDataField(ETA_START, ETA_LENGTH, eta); }

  /// set isolation of muon candidate
  void setIsolation(bool isol) { writeDataField(ISO_START, ISO_LENGTH, isol ? 1 : 0); }

  /// set min ionizing bit for muon candidate
  void setMIP(bool mip) { writeDataField(MIP_START, MIP_LENGTH, mip ? 1 : 0); }

  /// set packed charge/synchronization word of muon candidate (0=POS, 1=NEG, 2=UNDEF, 3=SYNC)
  void setChargePacked(unsigned ch) { writeDataField(SYSIGN_START, SYSIGN_LENGTH, ch); }

  /// set bunch crossing identifier
  void setBx(int bx) { m_bx = bx; }

  /// Setters for physical values

  /// Set Phi Value
  void setPhiValue(float phiVal) { m_phiValue = phiVal; }

  /// Set Pt Value
  void setPtValue(float ptVal) { m_ptValue = ptVal; }

  /// Set Eta Value (need to set type, first)
  void setEtaValue(float etaVal) { m_etaValue = etaVal; }

  //
  // Other
  //

  unsigned int linearizedPt(float lsbValue, unsigned maxScale) const { return 0; }

  unsigned int etaRegionIndex() const { return etaIndex(); }

  unsigned int phiRegionIndex() const { return phiIndex(); }

  /// equal operator
  bool operator==(const L1MuGMTCand&) const;

  /// unequal operator
  bool operator!=(const L1MuGMTCand&) const;

  /// print parameters of muon candidate
  void print() const;

  /// output stream operator
  friend std::ostream& operator<<(std::ostream&, const L1MuGMTCand&);

protected:
protected:
  inline unsigned readDataField(unsigned start, unsigned count) const;
  inline void writeDataField(unsigned start, unsigned count, unsigned value);

  std::string m_name;
  int m_bx;             // in here only for technical reasons in simulation
  unsigned m_dataWord;  // muon data word (26 bits) :

  float m_phiValue;
  float m_etaValue;
  float m_ptValue;
  static const float m_invalidValue;

  // definition of the bit fields
  enum { PHI_START = 0 };
  enum { PHI_LENGTH = 8 };  // Bits 0:7   phi (8 bits)
  enum { PT_START = 8 };
  enum { PT_LENGTH = 5 };  // Bits 8:12  pt  (5 bits)
  enum { QUAL_START = 13 };
  enum { QUAL_LENGTH = 3 };  // Bits 13:15 quality (3 bits)
  enum { ETA_START = 16 };
  enum { ETA_LENGTH = 6 };  // Bits 16:21 eta (6 bits)
  enum { ISO_START = 22 };
  enum { ISO_LENGTH = 1 };  // Bit  22    Isolation
  enum { MIP_START = 23 };
  enum { MIP_LENGTH = 1 };  // Bit  23    MIP
  enum { SYSIGN_START = 24 };
  enum { SYSIGN_LENGTH = 2 };  // Bit  24:25 Charge/Syncword
};

unsigned L1MuGMTCand::readDataField(unsigned start, unsigned count) const {
  unsigned mask = ((1 << count) - 1) << start;
  return (m_dataWord & mask) >> start;
}

void L1MuGMTCand::writeDataField(unsigned start, unsigned count, unsigned value) {
  unsigned mask = ((1 << count) - 1) << start;
  m_dataWord &= ~mask;  // clear
  m_dataWord |= (value << start) & mask;
}

#endif