ATLAS Offline Software
Loading...
Searching...
No Matches
TGCNSWCoincidenceMap.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6#include <iostream>
7#include <fstream>
8#include <sstream>
9#include <iomanip>
10#include <stdexcept>
11
16
18
19namespace LVL1TGCTrigger {
20
21
22 TGCNSWCoincidenceMap::TGCNSWCoincidenceMap(TGCArguments* tgcargs,const std::string& version,int side,int oct,int mod)
23 :AthMessaging("TGCNSWCoincidenceMap"),
24 m_verName(version),
25 m_side(side),
26 m_octant(oct),
27 m_module(mod),
28 m_tgcArgs(tgcargs)
29 {
30
31 setLevel(tgcArgs()->MSGLEVEL());
32
33 if(!tgcArgs()->USE_NSW()){return;}
34
35 std::string moduleName = std::to_string(mod);
36 if( isForward(mod)){
38 m_sector = m_module/3;
39 m_sector += 3*m_octant;
40 }
41 else{
43 m_sector = m_module%3 + 2*(m_module/3);
44 m_sector += 6*m_octant;
45 }
46
47
50
51 for(int dr=0;dr!=N_dEta;dr++){
52 for(int dphi=0;dphi!=N_dPhi;dphi++){
53 m_EtaPhi_CW[dr][dphi].resize(m_NumberOfRoI[m_region]);
54 std::fill(m_EtaPhi_CW[dr][dphi].begin(), m_EtaPhi_CW[dr][dphi].end(),0);
55 }
56 for(int dTheta=0;dTheta!=N_Dtheta;dTheta++){
57 m_EtaDtheta_CW[dr][dTheta].resize(m_NumberOfRoI[m_region]);
58 std::fill(m_EtaDtheta_CW[dr][dTheta].begin(), m_EtaDtheta_CW[dr][dTheta].end(),0);
59 }
60 }
61
62 if( ( oct%2==0 && mod==5 ) || (oct%2==1 && (mod==2 || mod==8)) ){moduleName+="b";}
63 else{moduleName+="a";}
64
65
66 //---------Read out CW data---------
67 if(!this->readMap( moduleName, ReadCW_Type::EtaPhi_CW) ||
68 !this->readMap( moduleName, ReadCW_Type::EtaDtheta_CW)
69 ){
70 // NSW trigger flag is set to false when the map reading failed.
71 tgcArgs()->set_USE_NSW(false);
72 }
73
74 //---------Fill Shift data---------
75 if(!this->readShift()){
76 // NSW trigger flag is set to false when the map reading failed.
77 tgcArgs()->set_USE_NSW(false);
78 }
79
80 }
81
82
84 return ( mod==2 || mod==5 || mod==8 );
85 }
86
87 //TGC-NSW Eta-Phi Coincidence
89 {
90 std::vector<uint8_t> nswEta_vec=nswOut->getNSWeta();
91 std::vector<uint8_t> nswPhi_vec=nswOut->getNSWphi();
92 int highest_pT=0;
93
94 for(unsigned int nswTrk_id=0;nswTrk_id!=nswEta_vec.size();nswTrk_id++){
95 int eta_decode=m_Offset_Eta[roi]-nswEta_vec[nswTrk_id];
96 int phi_decode=m_Offset_Phi[roi]-nswPhi_vec[nswTrk_id];
97 if(eta_decode<0 || eta_decode>=N_dEta){continue;}
98 if(phi_decode<0 || phi_decode>=N_dPhi){continue;}
99
100 if(highest_pT<m_EtaPhi_CW[eta_decode][phi_decode][roi]){
101 highest_pT=m_EtaPhi_CW[eta_decode][phi_decode][roi];
102 }
103 }
104
105 return 1;
106 }
107
108
109 //TGC-NSW Eta-DeltaTheta Coincidence
111 {
112 std::vector<uint8_t> nswEta_vec=nswOut->getNSWeta();
113 std::vector<uint8_t> nswDtheta_vec=nswOut->getNSWDtheta();
114 int highest_pT=0;
115
116 for(unsigned int nswTrk_id=0;nswTrk_id!=nswEta_vec.size();nswTrk_id++){
117 int eta_decode=m_Offset_Eta[roi]-nswEta_vec[nswTrk_id];
118 int dTheta_decode=nswDtheta_vec[nswTrk_id];
119 if(eta_decode<0 || eta_decode>=N_dEta){continue;}
120 if(highest_pT<m_EtaDtheta_CW[eta_decode][dTheta_decode][roi]){
121 highest_pT=m_EtaDtheta_CW[eta_decode][dTheta_decode][roi];
122 }
123 }
124
125 return 1;
126 }
127
128
129 bool TGCNSWCoincidenceMap::readMap(const std::string& moduleName, ReadCW_Type cw_type)
130 {
131 std::string kSide[2] = {"a", "c"};
132 std::string kCWtype[2] = {"EtaPhi","EtaDtheta"};
133
134 std::string dbname="";
135
136 dbname = "/NSW/cm_" + kSide[m_side] + moduleName +kCWtype[cw_type]+"_Octant_"+m_verName+".db";
137 std::string fullName = PathResolver::FindCalibDirectory("dev")+"/TrigT1TGC"+dbname;
138
139 std::ifstream data(fullName);
140 if(!data.is_open()){
141 ATH_MSG_WARNING("Cannot open file dev/TrigT1TGC" << dbname);
142 return false;
143 }
144 char delimiter = '\n';
145 std::string field;
146 std::string tag;
147
148 while (std::getline(data, field, delimiter)) {
149 int roi=-1;
150 unsigned int n_Etabit=0;
151 unsigned int n_Phibit=0;
152 std::istringstream header(field);
153 header >> tag;
154 if(tag=="#"){ // read header part.
155 header >> roi >> n_Etabit >> n_Phibit;
156 }
157 // get trigger word
158 std::string word;
159 unsigned int pT=0;
160
162 for(size_t posR=0; posR<N_dEta ; posR++){
163 std::getline(data, field, delimiter);
164 std::istringstream cont(field);
165 //----Read EtaPhi CW---------
166 if(cw_type==ReadCW_Type::EtaPhi_CW){
167 for(size_t posPHI=0; posPHI<N_dPhi; posPHI++){
168 cont >> word;
169 std::istringstream(word) >> std::hex >> pT;
170 m_EtaPhi_CW[posR][posPHI][roi]=pT;
171 }
172 }
173 //-----Read EtaDtheta CW-----
174 if(cw_type==ReadCW_Type::EtaDtheta_CW){
175 for(size_t posDTHETA=0; posDTHETA<N_Dtheta; posDTHETA++){
176 cont >> word;
177 std::istringstream(word) >> std::hex >> pT;
178 auto & roiIndexedVector = m_EtaDtheta_CW[posR][posDTHETA];
179 if ((roi<0) or (static_cast<size_t>(roi)>=roiIndexedVector.size())){
180 throw std::out_of_range("roi outside of vector limits in TGCNSWCoincidenceMap::readMap");
181 }
182 roiIndexedVector[roi]=pT;
183 }
184 }
185 }
186
187 }
188 data.close();
189
190
191 return true;
192 }
193
194
196
197 char delimiter = '\n';
198 std::string field;
199 std::string tag;
200 int side;
201 int triggerSector;
202
203 //------- Read Endcap Shift
204 std::string dbname="/NSW/";
205
206 if(m_region==TGCRegionType::ENDCAP){dbname += "RoIpos_Endcap.db";}
207 if(m_region==TGCRegionType::FORWARD){dbname += "RoIpos_Forward.db";}
208 std::string fullName = PathResolver::FindCalibDirectory("dev")+"/TrigT1TGC"+dbname;
209
210 std::ifstream data(fullName);
211 if(!data.is_open()){return false;}
212 while (std::getline(data, field, delimiter)) {
213 std::istringstream header(field);
214 header >> tag;
215 if(tag=="#"){ // read header part.
216 header >> side >> triggerSector ;
217 }
218
219 // get trigger word
220 std::getline(data, field, delimiter);
221 std::istringstream cont(field);
222 std::string word;
223 int shift=0;
224 std::array<int, 4> phi_shift {};
225 std::array<int, 37> eta_shift {};
226
227 if(side!=m_side || triggerSector!=m_sector){ continue; }
228 for(int phiN=0; phiN!=4; phiN++){
229 cont >> word;
230 std::istringstream(word) >> shift;
231 phi_shift[phiN]=shift;
232 }
233 for(int etaN=0; etaN!=m_NumberOfEtaRaw[m_region]; etaN++){
234 cont >> word;
235 std::istringstream(word) >> shift;
236 eta_shift[etaN]=shift;
237 }
238 for(int roi=0;roi!=m_NumberOfRoI[m_region];roi++){
239 m_Offset_Eta[roi]=eta_shift[roi/4]+N_dEta/2;
240 m_Offset_Phi[roi]=phi_shift[roi%4]+N_dPhi/2;
241 }
242
243 break;
244 }
245 data.close();
246
247 return true;
248 }
249
250} //end of namespace bracket
#define ATH_MSG_WARNING(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
void setLevel(MSG::Level lvl)
Change the current logging level.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
std::vector< short int > m_EtaDtheta_CW[N_dEta][N_Dtheta]
int TGCNSW_pTcalcu_EtaPhi(const LVL1TGC::NSWTrigOut *nswOut, int RoI) const
std::map< TGCRegionType, int > m_NumberOfRoI
bool readMap(const std::string &moduleName, ReadCW_Type cw_type)
int TGCNSW_pTcalcu_EtaDtheta(const LVL1TGC::NSWTrigOut *nswOut, int RoI) const
std::vector< short int > m_EtaPhi_CW[N_dEta][N_dPhi]
std::map< TGCRegionType, int > m_NumberOfEtaRaw
const std::vector< uint8_t > & getNSWphi() const
Definition NSWTrigOut.h:67
const std::vector< uint8_t > & getNSWDtheta() const
Definition NSWTrigOut.h:68
const std::vector< uint8_t > & getNSWeta() const
Definition NSWTrigOut.h:66
static std::string FindCalibDirectory(const std::string &logical_file_name)