ATLAS Offline Software
BigWheelCoincidenceLUT.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <iostream>
8 #include <fstream>
9 #include <sstream>
10 #include <string>
11 
12 #include "TrigT1TGC/TGCNumbering.h"
14 
19 
20 namespace LVL1TGC {
21 
22 int8_t BigWheelCoincidenceLUT::test(int sideId, int octantId, int moduleId, int subsector,
23  int type, int dr, int dphi) const {
24  if (type < TGCTriggerLUTs::COIN_HH || type > TGCTriggerLUTs::COIN_LL) return 0; // no candidate
25 
26  int phimod2 = 0;
27  if (moduleId == 2 || moduleId == 5 || moduleId == 8) { // forward sectors
28  int sector = (moduleId-2) / 3 + octantId * 3; // sector number assuming the forward sector
29  phimod2 = (sector%2 == 1) ? 1 : 0;
30  }
31 
38 
39  int8_t content = 0x0; // outside from defined window, i.e. pT=0
40 
41  if(tgcArgs()->USE_CONDDB()) {
43  const TGCTriggerLUTs* readCdo{*readHandle};
44  bool fullCW = (readCdo->getType(TGCTriggerLUTs::CW_BW) == "full");
45  if(fullCW) addr += (sideId<<TGCTriggerLUTs::SIDE_SHIFT) +
47 
48  content = readCdo->getBigWheelPt(addr);
49  } else {
50  if(m_fullCW) addr += (sideId<<TGCTriggerLUTs::SIDE_SHIFT) +
52 
53  std::unordered_map<uint32_t, char>::const_iterator it = m_lut.find(addr);
54  if(it != m_lut.end()) {
55  char pt_char = it->second;
56  content = m_pTdef.find(pt_char)->second;
57  }
58  }
59 
60  return content;
61 }
62 
63 
66  const std::string& version)
67 : m_verName(version),
68  m_tgcArgs(tgcargs),
69  m_readCondKey(readKey) {
70 
71  MsgStream log(Athena::getMessageSvc(), "LVL1TGC::BigWheelCoincidenceLUT");
72  log << MSG::INFO
73  << " BigWheel LUT version of " << m_verName << " is selected." << endmsg;
74 
75  if (!tgcArgs()->USE_CONDDB()) {
76  // read LUT contents from local files
77  this->readMap();
78  }
79 }
80 
82 }
83 
85 {
86  const uint8_t kNMODULETYPE = 12;
87  const uint8_t modulenumber[kNMODULETYPE] = {0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8};
88  const std::string modulename[kNMODULETYPE] = {"0a","1a","2a","2b","3a","4a","5a","5b","6a","7a","8a","8b"};
89  const std::string sidename[TGCSide::kNSide] = {"a","c"};
90  const std::string capitalsidename[TGCSide::kNSide] = {"A", "C"};
91 
92  const std::string octantName[kNOctant] =
93  { "0", "1", "2", "3", "4", "5", "6", "7"};
94  const std::string coincidenceTypeName[N_COIN_TYPE] = {"HH", "HL", "LH", "LL"};
95 
96  MsgStream log(Athena::getMessageSvc(), "LVL1TGC::BigWheelCoincidenceLUT");
97 
98  // Automatic identification of octant-symmetry or full-CW from version
99  std::string tryname = PathResolver::FindCalibDirectory("dev")+"/TrigT1TGC/BW/cm_a0aHH_Octant_" + m_verName + ".db";
100  std::ifstream tryfile(tryname.c_str(), std::ios::in);
101  if (tryfile) {
102  m_fullCW = false;
103  tryfile.close();
104  } else {
105  tryname = PathResolver::FindCalibDirectory("dev")+"/TrigT1TGC/BW/cm_mod0aHH_A0_" + m_verName + ".db";
106  tryfile = std::ifstream(tryname.c_str(), std::ios::in);
107  if (tryfile) {
108  m_fullCW = true;
109  tryfile.close();
110  } else {
111  log << MSG::ERROR << "Could not found the expected file!" << endmsg;
112  }
113  }
114 
115  const uint8_t num_sides = (m_fullCW) ? TGCSide::kNSide : 1;
116  const uint8_t num_octants = (m_fullCW) ? kNOctant : 1;
117 
118  for (uint8_t iside=0; iside < num_sides; iside++) {
119  for (uint8_t ioctant=0; ioctant < num_octants; ioctant++) {
120  uint32_t octaddr = (iside<<TGCTriggerLUTs::SIDE_SHIFT) +
122 
123  // loop over all files...
124  for (int iModule=0; iModule < kNMODULETYPE; iModule+=1) {
125  uint32_t phimod2 = (modulename[iModule].find("b") != std::string::npos) ? 1 : 0;
126 
127  if (m_fullCW && iModule%4 > 1) { // only forward sectors
128  if ((ioctant%2 == 0 && uint32_t(iModule/4)%2 != phimod2) || // A0, A2, A4, ...
129  (ioctant%2 == 1 && uint32_t(iModule/4)%2 == phimod2)) { // A1, A3, A5, ...
130  continue; // only one of phimod2 sectors should be used
131  }
132  }
133  uint32_t modaddr = ((modulenumber[iModule] & TGCTriggerLUTs::MODULE_MASK)<<TGCTriggerLUTs::MODULE_SHIFT) +
135 
136  for (int iCoinType=0; iCoinType != N_COIN_TYPE; iCoinType++) {
137  std::string fn = "/BW/cm_";
138  if (m_fullCW) {
139  fn += "mod" + modulename[iModule] + coincidenceTypeName[iCoinType] + "_" + capitalsidename[iside] + octantName[ioctant] + "_";
140  } else {
141  fn += sidename[iside] + modulename[iModule] + coincidenceTypeName[iCoinType] + "_Octant_";
142  }
143  fn += m_verName + ".db";
144 
145  int type = -1;
146  int lDR, hDR, lDPhi, hDPhi;
147  std::string fullName = PathResolver::FindCalibDirectory("dev")+"/TrigT1TGC"+fn;
148  if( fullName.length() == 0 ) {
149  log << MSG::ERROR << " Could not found " << fn.c_str() << endmsg;
150  continue;
151  }
152 
153  std::ifstream file(fullName.c_str(),std::ios::in);
154  if(!file){
155  log << MSG::ERROR << " Could not found " << fullName.c_str() << endmsg;
156  continue;
157  }
158 
159  std::string buf, tag;
160  char delimiter = '\n';
161  while (getline(file,buf,delimiter)){
162  std::istringstream header(buf);
163  header>>tag;
164 
165  if (tag == "#") { // read header part
166  int roi;
167  header >> roi >> lDR >> hDR >> lDPhi >> hDPhi;
168  type = getTYPE(lDR, hDR, lDPhi, hDPhi);
169  // check moduleNumber and ptLevel
170  if(type < 0) {
171  log << MSG::WARNING
172  << " illegal parameter in database header : " << header.str() << " in file " << fn << endmsg;
173  break;
174  }
175 
178 
181 
182  // get window data
183  getline(file, buf, delimiter);
184 
185  for(uint8_t iphi=lDPhi+TGCTriggerLUTs::DPHI_HIGH_RANGE; iphi <= hDPhi+TGCTriggerLUTs::DPHI_HIGH_RANGE; iphi++) {
186  uint32_t theaddr = octaddr + modaddr + cwaddr + draddr + iphi;
187  char pt = buf[iphi-lDPhi-TGCTriggerLUTs::DPHI_HIGH_RANGE];
188  if (pt == 'X') continue; // not opened
189  if(m_lut.count(theaddr)==0){
190  m_lut[theaddr] = pt;
191  }else{
192  log << MSG::ERROR
193  << " Problem with loading TGC BW Trigger LUT: duplicated entry at address=" << theaddr << " with pt=" << pt << endmsg;
194  }
195  }
196  }
197  } // if (tag == "#")
198  } // while (getline(...))
199  } // for (int iCoinType)
200  } // for (int iModule)
201  } // for (uint8_t ioctant)
202  } // for (uint8_t iside)
203 
204  return true;
205 }
206 
207 
208 } //end of namespace bracket
TGCTriggerLUTs::PHIMOD2_MASK
static constexpr uint8_t PHIMOD2_MASK
Mask for extracting the phi(F or B) from the GLOBALADDR.
Definition: TGCTriggerLUTs.h:36
LVL1TGC::BigWheelCoincidenceLUT::readMap
bool readMap()
Definition: BigWheelCoincidenceLUT.cxx:84
header
Definition: hcg.cxx:526
CondAttrListCollection.h
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
WriteCellNoiseToCool.fullName
fullName
Definition: WriteCellNoiseToCool.py:461
TGCTriggerLUTs::DPHI_SHIFT
static constexpr uint8_t DPHI_SHIFT
Bit position of the deltaPhi bits in the GLOBALADDR.
Definition: TGCTriggerLUTs.h:54
skel.it
it
Definition: skel.GENtoEVGEN.py:396
test_pyathena.pt
pt
Definition: test_pyathena.py:11
BigWheelCoincidenceLUT.h
TGCTriggerLUTs::CW_BW
@ CW_BW
Definition: TGCTriggerLUTs.h:66
LVL1TGC::BigWheelCoincidenceLUT::tgcArgs
const LVL1TGCTrigger::TGCArguments * tgcArgs() const
Definition: BigWheelCoincidenceLUT.h:80
LVL1TGC::BigWheelCoincidenceLUT::m_pTdef
std::map< char, int8_t > m_pTdef
Definition: BigWheelCoincidenceLUT.h:65
python.TurnDataReader.dr
dr
Definition: TurnDataReader.py:112
TGCDatabaseManager.h
PathResolver::FindCalibDirectory
static std::string FindCalibDirectory(const std::string &logical_file_name)
Definition: PathResolver.h:109
TGCTriggerLUTs::ROI_SHIFT
static constexpr uint8_t ROI_SHIFT
Bit position of the module number bits in the GLOBALADDR.
Definition: TGCTriggerLUTs.h:46
LVL1TGC::BigWheelCoincidenceLUT::N_COIN_TYPE
static constexpr uint32_t N_COIN_TYPE
Definition: BigWheelCoincidenceLUT.h:62
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
TGCTriggerLUTs::TYPE_SHIFT
static constexpr uint8_t TYPE_SHIFT
Bit position of the octant bits in the GLOBALADDR.
Definition: TGCTriggerLUTs.h:34
ReadCondHandle.h
TGCTriggerLUTs::DPHI_MASK
static constexpr uint8_t DPHI_MASK
Mask for extracting the deltaPhi from the GLOBALADDR.
Definition: TGCTriggerLUTs.h:52
LVL1TGC::BigWheelCoincidenceLUT::getTYPE
int getTYPE(int lDR, int hDR, int lDPhi, int hDPhi) const
Definition: BigWheelCoincidenceLUT.h:88
LVL1TGC::BigWheelCoincidenceLUT::m_readCondKey
const SG::ReadCondHandleKey< TGCTriggerLUTs > & m_readCondKey
Definition: BigWheelCoincidenceLUT.h:77
TGCTriggerLUTs::DR_MASK
static constexpr uint8_t DR_MASK
Mask for extracting the deltaR from the GLOBALADDR.
Definition: TGCTriggerLUTs.h:48
TGCTriggerLUTs::COIN_LL
@ COIN_LL
Definition: TGCTriggerLUTs.h:65
grepfile.content
string content
Definition: grepfile.py:56
LVL1TGC::BigWheelCoincidenceLUT::~BigWheelCoincidenceLUT
virtual ~BigWheelCoincidenceLUT()
Definition: BigWheelCoincidenceLUT.cxx:81
PlotCalibFromCool.modulename
modulename
Definition: PlotCalibFromCool.py:81
python.AthDsoLogger.delimiter
delimiter
Definition: AthDsoLogger.py:71
TGCTriggerLUTs::DPHI_HIGH_RANGE
static constexpr uint8_t DPHI_HIGH_RANGE
Range of DPhi in the BW coincidence window for 3-station.
Definition: TGCTriggerLUTs.h:61
python.getCurrentFolderTag.fn
fn
Definition: getCurrentFolderTag.py:65
TGCTriggerLUTs
Definition: TGCTriggerLUTs.h:16
TGCTriggerLUTs::OCTANT_MASK
static constexpr uint8_t OCTANT_MASK
Mask for extracting the octant from the GLOBALADDR.
Definition: TGCTriggerLUTs.h:28
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LVL1TGC
Definition: BigWheelCoincidenceLUT.cxx:20
file
TFile * file
Definition: tile_monitor.h:29
TGCTriggerLUTs::DR_HIGH_RANGE
static constexpr uint8_t DR_HIGH_RANGE
Range of DR in the BW coincidence window for 3-station.
Definition: TGCTriggerLUTs.h:57
TGCTriggerLUTs::DR_SHIFT
static constexpr uint8_t DR_SHIFT
Bit position of the deltaR bits in the GLOBALADDR.
Definition: TGCTriggerLUTs.h:50
TGCTriggerLUTs::OCTANT_SHIFT
static constexpr uint8_t OCTANT_SHIFT
Bit position of the octant bits in the GLOBALADDR.
Definition: TGCTriggerLUTs.h:30
LVL1TGC::BigWheelCoincidenceLUT::test
int8_t test(int sideId, int octantId, int moduleId, int subsector, int type, int dr, int dphi) const
Definition: BigWheelCoincidenceLUT.cxx:22
PathResolver.h
TGCNumbering.h
TGCTriggerLUTs::MODULE_MASK
static constexpr uint8_t MODULE_MASK
Mask for extracting the module number from the GLOBALADDR.
Definition: TGCTriggerLUTs.h:40
TGCTriggerLUTs::SIDE_SHIFT
static constexpr uint8_t SIDE_SHIFT
Bit position of the side bit in the GLOBALADDR.
Definition: TGCTriggerLUTs.h:26
LVL1TGCTrigger::TGCArguments
Definition: TGCArguments.h:12
LVL1TGCTrigger::TGCArguments::USE_CONDDB
bool USE_CONDDB() const
Definition: TGCArguments.cxx:45
SG::ReadCondHandleKey< TGCTriggerLUTs >
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
get_generator_info.version
version
Definition: get_generator_info.py:33
LVL1TGC::BigWheelCoincidenceLUT::m_lut
std::unordered_map< uint32_t, char > m_lut
Definition: BigWheelCoincidenceLUT.h:70
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TGCTriggerLUTs::TYPE_MASK
static constexpr uint8_t TYPE_MASK
Mask for extracting the octant from the GLOBALADDR.
Definition: TGCTriggerLUTs.h:32
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LVL1TGC::kNSide
@ kNSide
Definition: TGCNumbering.h:16
LVL1TGC::BigWheelCoincidenceLUT::m_fullCW
bool m_fullCW
Definition: BigWheelCoincidenceLUT.h:73
LVL1TGC::BigWheelCoincidenceLUT::BigWheelCoincidenceLUT
BigWheelCoincidenceLUT()=delete
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
makeTOC.header
header
Definition: makeTOC.py:28
TGCTriggerLUTs::MODULE_SHIFT
static constexpr uint8_t MODULE_SHIFT
Bit position of the module number bits in the GLOBALADDR.
Definition: TGCTriggerLUTs.h:42
LVL1TGC::BigWheelCoincidenceLUT::m_verName
std::string m_verName
Definition: BigWheelCoincidenceLUT.h:72
TGCTriggerLUTs::ROI_MASK
static constexpr uint8_t ROI_MASK
Mask for extracting the module number from the GLOBALADDR.
Definition: TGCTriggerLUTs.h:44
TGCTriggerLUTs::PHIMOD2_SHIFT
static constexpr uint8_t PHIMOD2_SHIFT
Bit position of the module number bits in the GLOBALADDR.
Definition: TGCTriggerLUTs.h:38