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 
17 #include "TrigT1TGC/TGCArguments.h"
18 
19 namespace 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
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:61
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:55
LVL1TGCTrigger::TGCNSWCoincidenceMap::m_Offset_Phi
std::vector< short int > m_Offset_Phi
Definition: TGCNSWCoincidenceMap.h:58
NSWTrigOut.h
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:83
TGCDatabaseManager.h
LVL1TGCTrigger::TGCNSWCoincidenceMap::ReadCW_Type
ReadCW_Type
Definition: TGCNSWCoincidenceMap.h:29
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:31
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:64
LVL1TGC::NSWTrigOut::getNSWDtheta
const std::vector< uint8_t > & getNSWDtheta() const
Definition: NSWTrigOut.h:68
LVL1TGCTrigger::TGCNSWCoincidenceMap::m_sector
int m_sector
Definition: TGCNSWCoincidenceMap.h:65
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:129
LVL1TGCTrigger::TGCNSWCoincidenceMap::m_Offset_Eta
std::vector< short int > m_Offset_Eta
Definition: TGCNSWCoincidenceMap.h:57
LVL1TGCTrigger::TGCNSWCoincidenceMap::N_dEta
@ N_dEta
Definition: TGCNSWCoincidenceMap.h:28
LVL1TGCTrigger
Definition: LVL1TGCTrigger.cxx:47
LVL1TGCTrigger::TGCNSWCoincidenceMap::m_NumberOfEtaRaw
std::map< TGCRegionType, int > m_NumberOfEtaRaw
Definition: TGCNSWCoincidenceMap.h:30
LVL1TGCTrigger::TGCNSWCoincidenceMap::tgcArgs
TGCArguments * tgcArgs()
Definition: TGCNSWCoincidenceMap.h:51
fill
void fill(H5::Group &out_file, size_t iterations)
Definition: test-hdf5-writer.cxx:95
LVL1TGCTrigger::TGCNSWCoincidenceMap::N_Dtheta
@ N_Dtheta
Definition: TGCNSWCoincidenceMap.h:28
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:88
LVL1TGCTrigger::TGCNSWCoincidenceMap::TGCNSWCoincidenceMap
TGCNSWCoincidenceMap()=delete
LVL1TGCTrigger::TGCNSWCoincidenceMap::TGCNSW_pTcalcu_EtaDtheta
int TGCNSW_pTcalcu_EtaDtheta(const LVL1TGC::NSWTrigOut *nswOut, int RoI) const
Definition: TGCNSWCoincidenceMap.cxx:110
LVL1TGCTrigger::TGCNSWCoincidenceMap::m_region
TGCRegionType m_region
Definition: TGCNSWCoincidenceMap.h:66
PathResolver.h
LVL1TGCTrigger::TGCNSWCoincidenceMap::m_octant
int m_octant
Definition: TGCNSWCoincidenceMap.h:63
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:56
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LVL1TGCTrigger::TGCNSWCoincidenceMap::m_side
int m_side
Definition: TGCNSWCoincidenceMap.h:62
LVL1TGC::NSWTrigOut::getNSWphi
const std::vector< uint8_t > & getNSWphi() const
Definition: NSWTrigOut.h:67
LVL1TGCTrigger::TGCNSWCoincidenceMap::readShift
bool readShift()
Definition: TGCNSWCoincidenceMap.cxx:195
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
LVL1TGCTrigger::TGCNSWCoincidenceMap::N_dPhi
@ N_dPhi
Definition: TGCNSWCoincidenceMap.h:28