eFexEMRoI_v1.cxx 7.89 KB
Newer Older
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
/*
  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/


// System include(s):
#include <stdexcept>

// xAOD include(s):
#include "xAODCore/AuxStoreAccessorMacros.h"

// Local include(s):
#include "xAODTrigger/versions/eFexEMRoI_v1.h"

namespace xAOD {

  /// Constants used in converting to ATLAS units
  const float eFexEMRoI_v1::s_tobEtScale = 100.;
  const float eFexEMRoI_v1::s_xTobEtScale = 25.;
  const float eFexEMRoI_v1::s_towerEtaWidth = 0.1;
  const float eFexEMRoI_v1::s_minEta = -2.5;

   eFexEMRoI_v1::eFexEMRoI_v1()
      : SG::AuxElement() {

   }

   void eFexEMRoI_v1::initialize( uint8_t eFexNumber, uint32_t word0, uint32_t word1 ) {

      setWord0( word0 );
      setWord1( word1 );
      seteFexNumber( eFexNumber );
      setTobEt( etTOB() );
      setEta( etaIndex() );
      setPhi( phiIndex() );

      /** If the object is a TOB then the isTOB should be true.
          For xTOB default is false, but should be set if a matching TOB is found */
      if (type() == TOB) setIsTOB(1);
      else               setIsTOB(0);

      return;
   }


   /// Raw data words
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint32_t, Word0,
                                         setWord0 )
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint32_t, Word1,
                                         setWord1 )
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint8_t, eFexNumber,
                                         seteFexNumber )

   /// Only calculable externally
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint16_t, RetaCore,
                                         setRetaCore )
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint16_t, RetaEnv,
                                         setRetaEnv )
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint16_t, RhadEM,
                                         setRhadEM )
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint16_t, RhadHad,
                                         setRhadHad )
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint16_t, WstotNumerator,
                                         setWstotNumerator )
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint16_t, WstotDenominator,
                                         setWstotDenominator )
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint32_t, thrPattern,
                                         setThrPattern )


   /// Should be set for xTOB if there is a matching TOB
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, char, isTOB,
                                         setIsTOB )

   /// Extracted from data words, stored for convenience
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint16_t, tobEt,
                                         setTobEt )
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint8_t, iEta,
                                         setEta )
   AUXSTORE_PRIMITIVE_SETTER_AND_GETTER( eFexEMRoI_v1, uint8_t, iPhi,
                                         setPhi )


   /// Methods to decode data from the TOB/RoI and return to the user

   /// TOB or xTOB?
   eFexEMRoI_v1::ObjectType eFexEMRoI_v1::type() const {
     if (Word1() == 0) return TOB;
     else              return xTOB;
   }
    
   /// Hardware coordinate elements
   unsigned int eFexEMRoI_v1::fpga() const {
     return (Word0() >> s_fpgaBit) & s_fpgaMask;
   }
    
   unsigned int eFexEMRoI_v1::fpgaEta() const {
     return (Word0() >> s_etaBit) & s_etaMask;
   }
    
   unsigned int eFexEMRoI_v1::fpgaPhi() const {
     return (Word0() >> s_phiBit) & s_phiMask;
   }
    
   unsigned int eFexEMRoI_v1::UpNotDown() const {
     return (Word0() >> s_updownBit) & s_updownMask;
   }
    
   unsigned int eFexEMRoI_v1::seed() const {
     return (Word0() >> s_seedBit) & s_seedMask;
   }
    
   unsigned int eFexEMRoI_v1::seedMax() const {
     return (Word0() >> s_maxBit) & s_maxMask;
   }

   /// Raw ET on TOB scale (100 MeV/count)
   unsigned int eFexEMRoI_v1::etTOB() const {
     // Data content = TOB
     if (Word1() == 0) {
       return (Word0() >> s_etBit) & s_etMask;
     }
     // Data Content = xTOB. Need to remove lower bits and cap range
     else {
       unsigned int etWord = (etXTOB() >> s_etBitXTOB);
       if (etWord > s_etMask) etWord = s_etMask; 
       return etWord;
     }
   }
   
   /// Full precision ET (25 MeV/count, only available if object is an xTOB
   unsigned int eFexEMRoI_v1::etXTOB() const {
     /// If the object is not an xTOB return 0 as high-precision ET unavailable
     if (Word1() == 0) { 
       //return etTOB()*s_tobEtScale/s_xTobEtScale;
       return 0; 
     }
     else {
       return (Word1() >> s_etBit) & s_etFullMask;
     }
   }
    
   /// Results of the 3 jet discriminant algorithms
   unsigned int eFexEMRoI_v1::RetaThresholds() const {
     return (Word0() >> s_veto1Bit) & s_veto1Mask;
   }
    
   unsigned int eFexEMRoI_v1::RhadThresholds() const {
     return (Word0() >> s_veto2Bit) & s_veto2Mask;
   }
    
   unsigned int eFexEMRoI_v1::WstotThresholds() const {
     return (Word0() >> s_veto3Bit) & s_veto3Mask;
   }
    
   unsigned int eFexEMRoI_v1::bcn4() const {
     return (Word1() >> s_bcn4Bit) & s_bcn4Mask;
   }

   /// Return single 32-bit TOB word from an xTOB 
   uint32_t eFexEMRoI_v1::tobWord() const {
     // Do something sensible if called for a TOB
     if (Word1() == 0) return Word0();
     // When called for xTOB
     else {
       uint32_t word = Word0() + etTOB();
       return word;
     }
   }

   /// Methods that require combining results or applying scales
   /// ET on TOB scale
   float eFexEMRoI_v1::et() const {
     return tobEt()*s_tobEtScale;
   }

   /// Floating point coordinates
   float eFexEMRoI_v1::eta() const {
     return (s_minEta + iEta()*s_towerEtaWidth + (seed()+0.5)*s_towerEtaWidth/4);
   }

   float eFexEMRoI_v1::phi() const {
     float value = iPhi() * M_PI/32. + M_PI/64.;
     if (value > M_PI) value = value - 2.*M_PI;
     return value;
   }

   /// Jet discriminant values. 
   /// Note that these are for convenience & intelligibility, but these should
   /// not be used for bitwise-accurate menu studies
   float eFexEMRoI_v1::Reta() const {
     float sum = RetaCore() + RetaEnv();
     if (sum > 0) return (1. - RetaCore()/sum);
     else         return -1.;
   }

   float eFexEMRoI_v1::Rhad() const {
     float sum = RhadEM() + RhadHad();
     if (sum > 0) return (RhadHad()/sum);
     else         return -1.;
   }

   float eFexEMRoI_v1::Wstot() const {
     if (WstotDenominator() > 0) return (WstotNumerator()/WstotDenominator());
     else         return -1.;
   }

   /// Methods that decode the eFEX number

  /// Return phi index in the range 0-63
  int eFexEMRoI_v1::phiIndex() const {

     /// Get the eFEX index in phi (1-8, unfortunately)
     unsigned int eFEX = (eFexNumber() >> s_eFexPhiBit) & s_eFexPhiMask;

     /// Find global phi index (0-63) for this window in this eFEX (the -1 is to correct for the eFEX phi index)
     unsigned int index = s_eFexPhiWidth*eFEX + s_eFexPhiOffset  + fpgaPhi() -1;
     if (index >= s_numPhi) index -= s_numPhi;
     return index;
   }

   /// Return an eta index in the range 0-49
   /// Note that this may not be the final format!
   /// And you need to combine with the seed() value to get full eta precision
   int eFexEMRoI_v1::etaIndex() const {

     /// Get the eFEX number
     uint8_t eFEX = (eFexNumber() >> s_eFexEtaBit) & s_eFexEtaMask;

     /// FPGA min eta
     uint8_t index = 99; /// Define a default value in case of invalid eFEX number

     switch (eFEX) {
       case eFexC: index = s_EtaCOffset + fpga()*s_fpgaEtaWidth + (fpga() > 0 ? 1 : 0);
                   break;
       case eFexB: index = s_EtaBOffset + fpga()*s_fpgaEtaWidth;
                   break;
       case eFexA: index = s_EtaAOffset + fpga()*s_fpgaEtaWidth;
                   break;
     }

     /// Add eta location within the FPGA & return value
     return index + fpgaEta();

   }



} // namespace xAOD