ATLAS Offline Software
Loading...
Searching...
No Matches
BigWheelCoincidenceLUT.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <iostream>
8#include <fstream>
9#include <sstream>
10#include <string>
11
14
19
20namespace LVL1TGC {
21
22int8_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 auto pPair = m_pTdef.find(pt_char);
57 if (pPair != m_pTdef.end()){
58 content = pPair->second;
59 }
60 }
61 }
62
63 return content;
64}
65
66
69 const std::string& version)
70: m_verName(version),
71 m_tgcArgs(tgcargs),
72 m_readCondKey(readKey) {
73
74 MsgStream log(Athena::getMessageSvc(), "LVL1TGC::BigWheelCoincidenceLUT");
75 log << MSG::INFO
76 << " BigWheel LUT version of " << m_verName << " is selected." << endmsg;
77
78 if (!tgcArgs()->USE_CONDDB()) {
79 // read LUT contents from local files
80 this->readMap();
81 }
82}
83
86
88{
89 const uint8_t kNMODULETYPE = 12;
90 const uint8_t modulenumber[kNMODULETYPE] = {0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8};
91 const std::string modulename[kNMODULETYPE] = {"0a","1a","2a","2b","3a","4a","5a","5b","6a","7a","8a","8b"};
92 const std::string sidename[TGCSide::kNSide] = {"a","c"};
93 const std::string capitalsidename[TGCSide::kNSide] = {"A", "C"};
94
95 const std::string octantName[kNOctant] =
96 { "0", "1", "2", "3", "4", "5", "6", "7"};
97 const std::string coincidenceTypeName[N_COIN_TYPE] = {"HH", "HL", "LH", "LL"};
98
99 MsgStream log(Athena::getMessageSvc(), "LVL1TGC::BigWheelCoincidenceLUT");
100
101 // Automatic identification of octant-symmetry or full-CW from version
102 std::string tryname = PathResolver::FindCalibDirectory("dev")+"/TrigT1TGC/BW/cm_a0aHH_Octant_" + m_verName + ".db";
103 std::ifstream tryfile(tryname.c_str(), std::ios::in);
104 if (tryfile) {
105 m_fullCW = false;
106 tryfile.close();
107 } else {
108 tryname = PathResolver::FindCalibDirectory("dev")+"/TrigT1TGC/BW/cm_mod0aHH_A0_" + m_verName + ".db";
109 tryfile = std::ifstream(tryname.c_str(), std::ios::in);
110 if (tryfile) {
111 m_fullCW = true;
112 tryfile.close();
113 } else {
114 log << MSG::ERROR << "Could not found the expected file!" << endmsg;
115 }
116 }
117
118 const uint8_t num_sides = (m_fullCW) ? TGCSide::kNSide : 1;
119 const uint8_t num_octants = (m_fullCW) ? kNOctant : 1;
120
121 for (uint8_t iside=0; iside < num_sides; iside++) {
122 for (uint8_t ioctant=0; ioctant < num_octants; ioctant++) {
123 uint32_t octaddr = (iside<<TGCTriggerLUTs::SIDE_SHIFT) +
125
126 // loop over all files...
127 for (int iModule=0; iModule < kNMODULETYPE; iModule+=1) {
128 uint32_t phimod2 = (modulename[iModule].find("b") != std::string::npos) ? 1 : 0;
129
130 if (m_fullCW && iModule%4 > 1) { // only forward sectors
131 if ((ioctant%2 == 0 && uint32_t(iModule/4)%2 != phimod2) || // A0, A2, A4, ...
132 (ioctant%2 == 1 && uint32_t(iModule/4)%2 == phimod2)) { // A1, A3, A5, ...
133 continue; // only one of phimod2 sectors should be used
134 }
135 }
136 uint32_t modaddr = ((modulenumber[iModule] & TGCTriggerLUTs::MODULE_MASK)<<TGCTriggerLUTs::MODULE_SHIFT) +
138
139 for (int iCoinType=0; iCoinType != N_COIN_TYPE; iCoinType++) {
140 std::string fn = "/BW/cm_";
141 if (m_fullCW) {
142 fn += "mod" + modulename[iModule] + coincidenceTypeName[iCoinType] + "_" + capitalsidename[iside] + octantName[ioctant] + "_";
143 } else {
144 fn += sidename[iside] + modulename[iModule] + coincidenceTypeName[iCoinType] + "_Octant_";
145 }
146 fn += m_verName + ".db";
147
148 int type = -1;
149 int lDR, hDR, lDPhi, hDPhi;
150 std::string fullName = PathResolver::FindCalibDirectory("dev")+"/TrigT1TGC"+fn;
151 if( fullName.length() == 0 ) {
152 log << MSG::ERROR << " Could not found " << fn.c_str() << endmsg;
153 continue;
154 }
155
156 std::ifstream file(fullName.c_str(),std::ios::in);
157 if(!file){
158 log << MSG::ERROR << " Could not found " << fullName.c_str() << endmsg;
159 continue;
160 }
161
162 std::string buf, tag;
163 char delimiter = '\n';
164 while (getline(file,buf,delimiter)){
165 std::istringstream header(buf);
166 header>>tag;
167
168 if (tag == "#") { // read header part
169 int roi;
170 header >> roi >> lDR >> hDR >> lDPhi >> hDPhi;
171 type = getTYPE(lDR, hDR, lDPhi, hDPhi);
172 // check moduleNumber and ptLevel
173 if(type < 0) {
174 log << MSG::WARNING
175 << " illegal parameter in database header : " << header.str() << " in file " << fn << endmsg;
176 break;
177 }
178
179 uint32_t cwaddr = ((uint8_t(type) & TGCTriggerLUTs::TYPE_MASK)<<TGCTriggerLUTs::TYPE_SHIFT) +
181
184
185 // get window data
186 getline(file, buf, delimiter);
187
188 for(uint8_t iphi=lDPhi+TGCTriggerLUTs::DPHI_HIGH_RANGE; iphi <= hDPhi+TGCTriggerLUTs::DPHI_HIGH_RANGE; iphi++) {
189 uint32_t theaddr = octaddr + modaddr + cwaddr + draddr + iphi;
190 char pt = buf[iphi-lDPhi-TGCTriggerLUTs::DPHI_HIGH_RANGE];
191 if (pt == 'X') continue; // not opened
192 if(m_lut.count(theaddr)==0){
193 m_lut[theaddr] = pt;
194 }else{
195 log << MSG::ERROR
196 << " Problem with loading TGC BW Trigger LUT: duplicated entry at address=" << theaddr << " with pt=" << pt << endmsg;
197 }
198 }
199 }
200 } // if (tag == "#")
201 } // while (getline(...))
202 } // for (int iCoinType)
203 } // for (int iModule)
204 } // for (uint8_t ioctant)
205 } // for (uint8_t iside)
206
207 return true;
208}
209
210
211} //end of namespace bracket
#define endmsg
This file defines the class for a collection of AttributeLists where each one is associated with a ch...
LVL1TGCTrigger::TGCArguments * m_tgcArgs
const LVL1TGCTrigger::TGCArguments * tgcArgs() const
static constexpr uint32_t N_COIN_TYPE
int getTYPE(int lDR, int hDR, int lDPhi, int hDPhi) const
int8_t test(int sideId, int octantId, int moduleId, int subsector, int type, int dr, int dphi) const
std::unordered_map< uint32_t, char > m_lut
const SG::ReadCondHandleKey< TGCTriggerLUTs > & m_readCondKey
static std::string FindCalibDirectory(const std::string &logical_file_name)
int8_t getBigWheelPt(const uint32_t addr) const
static constexpr uint8_t SIDE_SHIFT
Bit position of the side bit in the GLOBALADDR.
static constexpr uint8_t DR_MASK
Mask for extracting the deltaR from the GLOBALADDR.
static constexpr uint8_t DPHI_HIGH_RANGE
Range of DPhi in the BW coincidence window for 3-station.
static constexpr uint8_t DPHI_SHIFT
Bit position of the deltaPhi bits in the GLOBALADDR.
static constexpr uint8_t ROI_MASK
Mask for extracting the module number from the GLOBALADDR.
static constexpr uint8_t PHIMOD2_SHIFT
Bit position of the module number bits in the GLOBALADDR.
static constexpr uint8_t TYPE_MASK
Mask for extracting the octant from the GLOBALADDR.
static constexpr uint8_t DR_SHIFT
Bit position of the deltaR bits in the GLOBALADDR.
static constexpr uint8_t OCTANT_SHIFT
Bit position of the octant bits in the GLOBALADDR.
static constexpr uint8_t DR_HIGH_RANGE
Range of DR in the BW coincidence window for 3-station.
std::string getType(int cwtype, int channel=0) const
static constexpr uint8_t MODULE_MASK
Mask for extracting the module number from the GLOBALADDR.
static constexpr uint8_t OCTANT_MASK
Mask for extracting the octant from the GLOBALADDR.
static constexpr uint8_t TYPE_SHIFT
Bit position of the octant bits in the GLOBALADDR.
static constexpr uint8_t MODULE_SHIFT
Bit position of the module number bits in the GLOBALADDR.
static constexpr uint8_t PHIMOD2_MASK
Mask for extracting the phi(F or B) from the GLOBALADDR.
static constexpr uint8_t DPHI_MASK
Mask for extracting the deltaPhi from the GLOBALADDR.
static constexpr uint8_t ROI_SHIFT
Bit position of the module number bits in the GLOBALADDR.
int ir
counter of the current depth
Definition fastadd.cxx:49
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
static constexpr unsigned int kNOctant
The number of octants per side.
TFile * file