ATLAS Offline Software
TrigMonRoi.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // C/C++
6 #include <algorithm>
7 #include <iostream>
8 #include <sstream>
9 
12 
13 namespace RoiBits
14 {
15  const uint32_t maskId = 0x000000ff;
16  const uint32_t maskType = 0x00000f00;
17  const uint32_t maskL1 = 0x000ff000;
18  //const uint32_t maskFree = 0xfff00000;
19 
20  const uint32_t shiftId = 0;
21  const uint32_t shiftType = 8;
22  const uint32_t shiftL1 = 12;
23  //const uint32_t shiftFree = 20;
24 }
25 
26 //--------------------------------------------------------------------------------------
28  :m_word(1, 0)
29 {
30 }
31 
32 //--------------------------------------------------------------------------------------
34  :m_word(1, 0)
35 {
36  //
37  // Set RoiId to uknown state
38  //
39  m_word[0] = roi_word;
40 }
41 
42 //--------------------------------------------------------------------------------------
44 {
45  //
46  // Set roi type
47  //
48  if(m_word.size() < 2) return;
49 
50  m_word[1] |= (type << RoiBits::shiftType);
51 }
52 
53 //--------------------------------------------------------------------------------------
54 void TrigMonRoi::setRoiId(unsigned int id)
55 {
56  //
57  // Set roi type
58  //
59  if(m_word.size() < 2) return;
60 
61  if(id < 256) {
62  m_word[1] |= (id << RoiBits::shiftId);
63  }
64  else {
65  if(m_word.size()<3){
66  m_word.push_back(id);
67  }
68  else{
69  m_word[2]=id;
70  }
71  }
72 }
73 
74 //--------------------------------------------------------------------------------------
75 void TrigMonRoi::setNL1th(unsigned int lt)
76 {
77  //
78  // Set roi type
79  //
80  if(m_word.size() < 2) return;
81 
82  if(lt < 256) {
83  m_word[1] |= (lt << RoiBits::shiftL1);
84  }
85  else {
86  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonRoi")
87  << "setL1thresholds error! Value is out of range: " << lt;
88  }
89 }
90 
91 //--------------------------------------------------------------------------------------
92 void TrigMonRoi::setEtaPhi(float eta, float phi)
93 {
94  //
95  // Add eta and phi coordinatesat key=0 and key=1
96  //
97  if(std::count(m_var_key.begin(), m_var_key.end(), 0) == 0 &&
98  std::count(m_var_key.begin(), m_var_key.end(), 1) == 0) {
99  m_var_key.push_back(0);
100  m_var_val.push_back(eta);
101 
102  m_var_key.push_back(1);
103  m_var_val.push_back(phi);
104  }
105 }
106 
107 //--------------------------------------------------------------------------------------
108 void TrigMonRoi::setRoIArea(float eta_width, float phi_width)
109 {
110  //
111  // Add eta and phi coordinatesat key=0 and key=1
112  //
113  if(std::count(m_var_key.begin(), m_var_key.end(), 2) == 0) {
114 
115  // Assuming the area is an ellipse - approximate
116  //float area = 3.14159*eta_width*phi_width;
117 
118  // Chainging to square area, assume supplied are full width
119  float area = eta_width * phi_width;
120 
121  m_var_key.push_back(2);
122  m_var_val.push_back(area);
123  }
124 }
125 
126 //--------------------------------------------------------------------------------------
128 {
129  //
130  // Store variable as int and float, reserve 0-9 keys
131  //
132  if(var.getKey() > 9) {
133  m_var_key.push_back(var.getKey());
134  m_var_val.push_back(var.getData());
135  } else {
136  REPORT_MESSAGE_WITH_CONTEXT(MSG::ERROR, "TrigMonRoi")
137  << "Cannot add a var with key < 9 (internal use only)";
138  }
139 }
140 
141 //--------------------------------------------------------------------------------------
143 {
144  //
145  // Return RoI type assigned by HLT
146  //
147  if(m_word.size() < 2) return kNone;
148 
149  const unsigned int val = (m_word[1] & RoiBits::maskType) >> RoiBits::shiftType;
150 
151  switch (val) {
152  case 1: return kMuon;
153  case 2: return kEmTau;
154  case 3: return kJet;
155  case 4: return kJetEt;
156  case 5: return kEnergy;
157  default: break;
158  }
159 
160  return kNone;
161 }
162 
163 //--------------------------------------------------------------------------------------
165 {
166  //
167  // Return RoI id assigned by HLT
168  //
169  if(m_word.size() < 2) return Trig::getRoiId_Unknown();
170 
171  // For 2012 data
172  if(m_word.size() == 3) return m_word[2];
173 
174  return (m_word[1] & RoiBits::maskId) >> RoiBits::shiftId;
175 }
176 
177 //--------------------------------------------------------------------------------------
178 float TrigMonRoi::getEta() const
179 {
180  //
181  // Search for eta value at key=0
182  //
183 
184  if(m_var_key.size() == m_var_val.size()) {
185  for(unsigned int i = 0; i < m_var_key.size(); ++i) {
186  if(m_var_key[i] == 0) return m_var_val[i];
187  }
188  }
189 
190  return -9999.0;
191 }
192 
193 //--------------------------------------------------------------------------------------
194 float TrigMonRoi::getPhi() const
195 {
196  //
197  // Search for phi value at key=1
198  //
199 
200  if(m_var_key.size() == m_var_val.size()) {
201  for(unsigned int i = 0; i < m_var_key.size(); ++i) {
202  if(m_var_key[i] == 1) return m_var_val[i];
203  }
204  }
205 
206  return -9999.0;
207 }
208 
209 //--------------------------------------------------------------------------------------
211 {
212  //
213  // Search for phi value at key=2
214  //
215 
216  if(m_var_key.size() == m_var_val.size()) {
217  for(unsigned int i = 0; i < m_var_key.size(); ++i) {
218  if(m_var_key[i] == 2) return m_var_val[i];
219  }
220  }
221 
222  return -9999.0;
223 }
224 
225 //--------------------------------------------------------------------------------------
227 {
228  //
229  // Return number of L1 thresholds assigned by HLT
230  //
231  if(m_word.size() < 2) return 0;
232 
233  return (m_word[1] & RoiBits::maskL1) >> RoiBits::shiftL1;
234 }
235 
236 //--------------------------------------------------------------------------------------
237 const std::vector<TrigMonVar> TrigMonRoi::getVar() const
238 {
239  //
240  // Build variables on a fly and return vector by value
241  //
242  std::vector<TrigMonVar> var;
243 
244  if(m_var_key.size() == m_var_val.size()) {
245  //
246  // Iterate over keys abd values
247  //
248  var.reserve(m_var_key.size());
249 
250  for(unsigned int i = 0; i < m_var_key.size(); ++i) {
251  var.push_back(TrigMonVar(m_var_key[i], m_var_val[i]));
252  }
253  }
254 
255  return var;
256 }
257 
258 float TrigMonRoi::getVarVal( const uint32_t key ) const
259 {
260  for(unsigned int i = 0; i < m_var_key.size(); ++i) {
261  if (m_var_key.at(i) == key) return m_var_val.at(i);
262  }
263  return 0.;
264 }
265 
266 
267 //--------------------------------------------------------------------------------------
268 void TrigMonRoi::print(std::ostream &os)
269 {
270  os << str(*this) << std::endl;
271 }
272 
273 //--------------------------------------------------------------------------------------
274 std::string str(const TrigMonRoi &o)
275 {
276  std::stringstream s;
277  s << "TrigMonRoi: id=" << o.getRoiId() << " word=" << o.getRoiWord();
278 
279  return s.str();
280 }
TrigMonRoi::getRoiId
uint32_t getRoiId() const
Definition: TrigMonRoi.cxx:164
TrigMonRoi::m_var_val
std::vector< float > m_var_val
Definition: TrigMonRoi.h:79
beamspotnt.var
var
Definition: bin/beamspotnt.py:1394
TrigMonRoi::kJet
@ kJet
Definition: TrigMonRoi.h:33
TrigMonRoi::getRoiType
Type getRoiType() const
Definition: TrigMonRoi.cxx:142
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
TrigMonRoi::getRoiWord
uint32_t getRoiWord() const
Definition: TrigMonRoi.h:53
RoiBits::maskL1
const uint32_t maskL1
Definition: TrigMonRoi.cxx:17
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
TrigMonRoi::kJetEt
@ kJetEt
Definition: TrigMonRoi.h:34
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:575
TrigMonRoi::kEmTau
@ kEmTau
Definition: TrigMonRoi.h:32
TrigMonRoi::getEta
float getEta() const
Definition: TrigMonRoi.cxx:178
TrigMonRoi::setRoIArea
void setRoIArea(float eta_width, float phi_width)
Definition: TrigMonRoi.cxx:108
RoiBits::shiftL1
const uint32_t shiftL1
Definition: TrigMonRoi.cxx:22
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
RoiBits::maskType
const uint32_t maskType
Definition: TrigMonRoi.cxx:16
TrigMonRoi::Type
Type
Definition: TrigMonRoi.h:29
TrigMonRoi::setNL1th
void setNL1th(unsigned int lt)
Definition: TrigMonRoi.cxx:75
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
TrigMonRoi::getPhi
float getPhi() const
Definition: TrigMonRoi.cxx:194
lumiFormat.i
int i
Definition: lumiFormat.py:92
TrigMonRoi::kEnergy
@ kEnergy
Definition: TrigMonRoi.h:35
TrigMonRoi::kNone
@ kNone
Definition: TrigMonRoi.h:30
Trig::getRoiId_Unknown
uint8_t getRoiId_Unknown()
Definition: TrigMonRoi.h:89
RoiBits::maskId
const uint32_t maskId
Definition: TrigMonRoi.cxx:15
TrigMonRoi::TrigMonRoi
TrigMonRoi()
Definition: TrigMonRoi.cxx:27
TrigMonVar
Definition: TrigMonVar.h:59
TrigMonRoi::addVar
void addVar(const TrigMonVar &var)
Definition: TrigMonRoi.cxx:127
RoiBits::shiftType
const uint32_t shiftType
Definition: TrigMonRoi.cxx:21
TrigMonRoi::m_var_key
std::vector< uint16_t > m_var_key
Definition: TrigMonRoi.h:78
xAODType
Definition: ObjectType.h:13
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
TrigMonRoi::getRoIArea
float getRoIArea() const
Definition: TrigMonRoi.cxx:210
REPORT_MESSAGE_WITH_CONTEXT
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:345
TrigMonRoi::kMuon
@ kMuon
Definition: TrigMonRoi.h:31
TrigMonRoi
Definition: TrigMonRoi.h:26
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:191
errorcheck.h
Helpers for checking error return status codes and reporting errors.
TrigMonRoi.h
TrigMonRoi::setType
void setType(Type type)
Definition: TrigMonRoi.cxx:43
TrigMonRoi::print
void print(std::ostream &os=std::cout)
Definition: TrigMonRoi.cxx:268
RoiBits::shiftId
const uint32_t shiftId
Definition: TrigMonRoi.cxx:20
RoiBits
Definition: TrigMonRoi.cxx:14
TrigMonRoi::getVarVal
std::vector< float > & getVarVal()
Definition: TrigMonRoi.h:65
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigMonRoi::setRoiId
void setRoiId(unsigned int id)
Definition: TrigMonRoi.cxx:54
TrigMonRoi::setEtaPhi
void setEtaPhi(float eta, float phi)
Definition: TrigMonRoi.cxx:92
area
double area(double R)
Definition: ConvertStaveServices.cxx:42
TrigMonRoi::getNL1th
uint8_t getNL1th() const
Definition: TrigMonRoi.cxx:226
str
std::string str(const TrigMonRoi &o)
Definition: TrigMonRoi.cxx:274
TrigMonRoi::m_word
std::vector< uint32_t > m_word
Definition: TrigMonRoi.h:77
TrigMonRoi::getVar
const std::vector< TrigMonVar > getVar() const
Definition: TrigMonRoi.cxx:237
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37