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