ATLAS Offline Software
Loading...
Searching...
No Matches
TGCTileMuCoincidenceLUT.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
9
10#include <fstream>
11
12namespace LVL1TGC {
13
16 const std::string& version)
17 : m_verName(version),
18 m_tgcArgs(tgcargs),
19 m_readCondKey(readCondKey)
20{
21 if (!tgcArgs()->TILE_MU()) return;
22 if (tgcArgs()->USE_CONDDB()) return;
23
24 MsgStream log(Athena::getMessageSvc(), "LVL1TGC::TGCTileMuCoincidenceLUT");
25
26 // read Inner Coincidence Map
27 if (this->readMap()) {
28 log << MSG::INFO
29 << " TGC TileMu CW version of " << m_verName << " is selected " << endmsg;
30 } else {
31 log << MSG::INFO
32 << " NOT use TileMu " << endmsg;
33 m_flagpt.clear();
34 m_flagroi.clear();
35 m_trigbit.clear();
36 }
37}
38
39
43
45{
46 MsgStream log(Athena::getMessageSvc(), "LVL1TGC::TGCTileMuCoincidenceLUT");
47
48 // select right database according to a set of thresholds
49 std::string dbname="";
50 dbname = "TileMuCoincidenceMap." + m_verName + "._12.db";
51
52 //-----
53
54 std::string fullName;
55 fullName = PathResolver::FindCalibDirectory("dev")+"/TrigT1TGC/TILE/"+dbname;
56 bool isFound =( fullName.length() > 0 );
57 if( !isFound) {
58 log << MSG::WARNING
59 << " Could not found " << dbname << endmsg;
60 return false ;
61 }
62
63 std::ifstream file(fullName.c_str(),std::ios::in);
64
65 static constexpr unsigned int BufferSize = 256;
66 char buf[BufferSize];
67
68 while (file.getline(buf, BufferSize)) {
69
70 int16_t sideId = -1;
71 int16_t sectorId = -1;
72 int16_t sscId = -1;
73
74 std::istringstream header(buf);
75 std::string tag;
76 header >> tag;
77 if(tag == "#") {
78 header >> sideId >> sectorId >> sscId;
79 }
80
81 // check Id
82 if(sideId < 0 || sideId>=TGCTriggerData::N_SIDE ||
83 sectorId < 0 || sectorId>=TGCTriggerData::N_ENDCAP_SECTOR ||
84 sscId < 0 || sscId>=TGCTriggerData::N_ENDCAP_SSC ) {
85 log << MSG::WARNING
86 << " illegal parameter in database header : " << header.str()
87 << " in file " << dbname
88 << endmsg;
89 file.close();
90 return false;
91 }
92
93 uint16_t addr = this->getAddr(sideId, sectorId, sscId);
94
95 uint8_t flagpt = 0;
96 for (size_t pt = 0; pt < TGCTriggerData::N_PT_THRESH; pt++){
97 uint8_t use;
98 header >> use;
99 flagpt |= (use&0x1)<<pt;
100 }
101 m_flagpt[addr] = flagpt;
102
103 uint8_t roi = 0;
104 for (size_t pos=0; pos< TGCTriggerData::N_ROI_IN_SSC; pos++){
105 uint8_t use;
106 header >> use;
107 roi |= (use&0x1)<<pos;
108 }
109 m_flagroi[addr] = roi;
110
111 // get trigger word
112 file.getline(buf,BufferSize);
113 std::istringstream cont(buf);
114 uint16_t trigbit = 0x0;
115 for(size_t pos=0; pos < TGCTriggerData::N_TILE_INPUT; pos++){
116 uint16_t word;
117 cont >> word;
118 trigbit |= (word & 0xf)<<(pos*4);
119 }
120 m_trigbit[addr] = trigbit;
121
122 }
123 file.close();
124
125 return true;
126}
127
128
130 const int16_t ssc,
131 const int16_t sec,
132 const int16_t side) const
133{
134 if ((module<0)||(module>=TGCTriggerData::N_TILE_INPUT)) return TM_NA;
135
136 uint16_t mask = 0x0;
137 if (tgcArgs()->USE_CONDDB()) {
139 const TGCTriggerData* readCdo{*readHandle};
140 mask = readCdo->getTrigMaskTile(ssc, sec, side);
141 } else {
142 uint16_t addr = this->getAddr(side, sec, ssc);
143 std::unordered_map<uint16_t, uint16_t>::const_iterator it = m_trigbit.find(addr);
144 if(it != m_trigbit.end()) mask = it->second;
145 }
146
147 return mask>>(module*4) & 0x7;
148}
149
151 const int16_t ssc,
152 const int16_t sec,
153 const int16_t side) const
154{
155 if ((pt<=0)||(pt>TGCTriggerData::N_PT_THRESH)) return -1;
156
157 uint8_t ptmask = 0x0;
158 if (tgcArgs()->USE_CONDDB()) {
160 const TGCTriggerData* readCdo{*readHandle};
161 ptmask = readCdo->getFlagPtTile(ssc, sec, side);
162 } else {
163 uint16_t addr = this->getAddr(side, sec, ssc);
164 std::unordered_map<uint16_t, uint8_t>::const_iterator it = m_flagpt.find(addr);
165 if(it != m_flagpt.end()) ptmask = it->second;
166 }
167 return (ptmask>>(pt-1)) & 0x1; /* only 1st bit needed (0x1) */
168}
169
171 const int16_t ssc,
172 const int16_t sec,
173 const int16_t side) const
174{
175 if ((roi<0)||(roi>=TGCTriggerData::N_ROI_IN_SSC)) return -1;
176
177 uint8_t roimask = 0x0;
178 if (tgcArgs()->USE_CONDDB()) {
180 const TGCTriggerData* readCdo{*readHandle};
181 roimask = readCdo->getFlagRoiTile(ssc, sec, side);
182 } else {
183 uint16_t addr = this->getAddr(side, sec, ssc);
184 std::unordered_map<uint16_t, uint8_t>::const_iterator it = m_flagroi.find(addr);
185 if(it != m_flagroi.end()) roimask = it->second;
186 }
187 return (roimask >> roi) & 0x1; /* only 1st bit needed (0x1) */
188}
189
190uint16_t TGCTileMuCoincidenceLUT::getAddr(int16_t side, int16_t sec, int16_t ssc) const
191{
195}
196
197
198} //end of namespace bracket
#define endmsg
LVL1TGCTrigger::TGCArguments * m_tgcArgs
uint16_t getAddr(int16_t side, int16_t sec, int16_t ssc) const
std::unordered_map< uint16_t, uint8_t > m_flagroi
std::unordered_map< uint16_t, uint16_t > m_trigbit
TGCTileMuCoincidenceLUT(LVL1TGCTrigger::TGCArguments *, const SG::ReadCondHandleKey< TGCTriggerData > &readCondKey, const std::string &version="NA")
int getTrigMask(const int module, const int16_t ssc, const int16_t sec, const int16_t side) const
int getFlagPT(const int pt, const int16_t ssc, const int16_t sec, const int16_t side) const
int getFlagROI(const int roi, const int16_t ssc, const int16_t sec, const int16_t side) const
const SG::ReadCondHandleKey< TGCTriggerData > & m_readCondKey
std::unordered_map< uint16_t, uint8_t > m_flagpt
LVL1TGCTrigger::TGCArguments * tgcArgs()
static std::string FindCalibDirectory(const std::string &logical_file_name)
uint8_t getFlagRoiTile(int ssc, int sectorId, int side) const
static constexpr uint8_t SECTOR_MASK
Mask for trigger sector for the (EIFI/TILE) ADDR.
unsigned char getFlagPtTile(int ssc, int sectorId, int side) const
static constexpr uint8_t SIDE_MASK
Mask for extracting the side from the GLOBALADDR.
unsigned short getTrigMaskTile(int ssc, int sectorId, int side) const
static constexpr uint8_t ADDR_SIDE_SHIFT
Bit position of the side bit in the (EIFI/TILE) ADDR.
static constexpr uint8_t SSC_MASK
Mask for SSC for the (EIFI/TILE) ADDR.
static constexpr uint8_t ADDR_SECTOR_SHIFT
Bit position of the trigger sector bit in the (EIFI/TILE) ADDR.
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
TFile * file