ATLAS Offline Software
MMARTPacket.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 #include <vector>
5 #include <exception>
6 #include <sstream>
7 #include <string>
8 #include <algorithm>
9 #include <tuple>
10 
13 
14 
15 Muon::nsw::MMARTPacket::MMARTPacket (std::vector<uint32_t>& payload) {
16 
17  std::size_t readPointer{0};
18  std::span<const std::uint32_t> data{payload.data(), 3};
19 
20  if (payload.size()!=3) {
21  throw std::runtime_error( Muon::nsw::format( "ART Packet size not as expected: expected exactly 3 uint32_t, got {}", payload.size() ));
22  }
23 
24  //decoding
25  m_art_BCID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMART::size_art_BCID);
26  m_art_pipeID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMART::size_art_pipeID);
27  m_art_fiberID = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMART::size_art_fiberID);
28  m_art_VMMmap = Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMART::size_art_VMMmap);
29  //remember ART 7 is first in the bit stream, ART 0 is last!
30  for (uint8_t i = 0; i < 8; i++){
31  m_art_ARTs.push_back( Muon::nsw::decode_and_advance<uint64_t>(data, readPointer, Muon::nsw::MMART::size_art_ARTs) );
32  }
33  std::reverse(m_art_ARTs.begin(), m_art_ARTs.end()); //so that ART0 is element0 and no confusion is made
34 
35  //populating layer,channel pair
36  std::vector<std::tuple<uint8_t,uint8_t,uint8_t>> artHitInfo = VMMmapToHits();
37 
38  for (uint8_t i = 0; i < artHitInfo.size(); i++){
39  m_channels.push_back( std::pair<uint8_t,uint16_t>(getLayer(), getVMMChannelPosition( getBoardPosition(std::get<0>(artHitInfo[i])) , std::get<1>(artHitInfo[i]) , std::get<2>(artHitInfo[i]))) );
40  }
41 
42 }
43 
44 
45 std::vector<std::tuple<uint8_t,uint8_t,uint8_t>> Muon::nsw::MMARTPacket::VMMmapToHits (){
46  std::vector<std::tuple<uint8_t,uint8_t>> hitmapBoardVMM;
47  std::vector<std::tuple<uint8_t,uint8_t,uint8_t>> artHitInfo;
48 
49  for (uint8_t i = 0; i<32; i++){
50  if ((m_art_VMMmap >> i) & 0b1) {
51  hitmapBoardVMM.push_back( std::make_tuple( (int)(i/8), i%8 ) ); //board, vmm
52  }
53  }
54 
55  if (hitmapBoardVMM.size()>8) {
56  throw std::runtime_error("ART Packet cannot contain more than 8 ART hits!");
57  }
58 
59  for (uint8_t i = 0; i<hitmapBoardVMM.size(); i++){
60  artHitInfo.push_back( std::make_tuple( std::get<0>(hitmapBoardVMM[i]), std::get<1>(hitmapBoardVMM[i]), m_art_ARTs[i] ) );
61  }
62 
63  return artHitInfo;
64 }
65 
66 
68  int rightLeft = (int)(m_art_fiberID/2.) % 2;
69  int layer = getLayer();
70 
71  int flipBoardOrder = 0;
72  int flipFiberOrder = 0;
73 
74  if (rightLeft==0){
75  if ( layer==1 || layer==2 || layer==5 || layer==6 ) {flipFiberOrder = 1;}
76  else {flipBoardOrder = 1;}
77  } else {
78  if ( layer==1 || layer==2 || layer==5 || layer==6 ) {flipBoardOrder = 1;}
79  else {flipFiberOrder = 1;}
80  }
81  if (flipBoardOrder) board = 3-board;
82 
83  int pcb = 0;
84  if (!flipFiberOrder){
85  if (m_art_fiberID % 2 == 0) {pcb = board;}
86  else {pcb = board+4;}
87  } else {
88  if (m_art_fiberID % 2 == 1) {pcb = board;}
89  else {pcb = board+4;}
90  }
91  pcb+=1;
92 
93  int boardPosition = -1;
94  if (layer%2==1){
95  if (rightLeft==1) {boardPosition = (pcb-1) * 2;}
96  else {boardPosition = (pcb-1) * 2 + 1;}
97  } else {
98  if (rightLeft==0) {boardPosition = (pcb-1) * 2;}
99  else {boardPosition = (pcb-1) * 2 + 1;}
100  }
101 
102  return boardPosition;
103 
104 }
105 
106 int Muon::nsw::MMARTPacket::getVMMChannelPosition (int boardPosition, int vmm, int ch){
107  int vmmPosition;
108  if (boardPosition%2==0){vmmPosition = 7-vmm;}
109  else {vmmPosition = vmm;}
110 
111  vmmPosition += boardPosition*8;
112  int chPosition = 64*vmmPosition;
113 
114  if (boardPosition%2==0){chPosition += (63 - ch);}
115  else {chPosition += ch;}
116 
117  return chPosition;
118 
119 }
Muon::nsw::MMARTPacket::m_art_ARTs
std::vector< uint32_t > m_art_ARTs
Definition: MMARTPacket.h:35
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
MMARTPacket.h
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Muon::nsw::MMARTPacket::m_art_VMMmap
uint64_t m_art_VMMmap
Definition: MMARTPacket.h:33
Muon::nsw::MMARTPacket::getBoardPosition
int getBoardPosition(int board)
Definition: MMARTPacket.cxx:67
Muon::nsw::MMARTPacket::getVMMChannelPosition
int getVMMChannelPosition(int boardPosition, int vmm, int ch)
Definition: MMARTPacket.cxx:106
Muon::nsw::MMART::size_art_ARTs
constexpr int size_art_ARTs
Definition: NSWMMTPDecodeBitmaps.h:92
module_driven_slicing.getLayer
def getLayer(trk, hit_idx)
Definition: module_driven_slicing.py:172
DeMoUpdate.reverse
reverse
Definition: DeMoUpdate.py:563
Muon::nsw::MMARTPacket::m_art_fiberID
uint32_t m_art_fiberID
Definition: MMARTPacket.h:32
Muon::nsw::MMARTPacket::m_channels
std::vector< std::pair< uint8_t, uint16_t > > m_channels
Definition: MMARTPacket.h:37
Muon::nsw::MMART::size_art_pipeID
constexpr int size_art_pipeID
Definition: NSWMMTPDecodeBitmaps.h:89
lumiFormat.i
int i
Definition: lumiFormat.py:85
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
Muon::nsw::MMART::size_art_fiberID
constexpr int size_art_fiberID
Definition: NSWMMTPDecodeBitmaps.h:90
Muon::nsw::format
std::string format(const std::string &str, const T &arg)
Definition: NSWDecodeHelper.h:43
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
NSWMMTPDecodeBitmaps.h
Muon::nsw::MMART::size_art_BCID
constexpr int size_art_BCID
Definition: NSWMMTPDecodeBitmaps.h:88
Muon::nsw::MMARTPacket::m_art_pipeID
uint32_t m_art_pipeID
Definition: MMARTPacket.h:31
Muon::nsw::MMART::size_art_VMMmap
constexpr int size_art_VMMmap
Definition: NSWMMTPDecodeBitmaps.h:91
Muon::nsw::MMARTPacket::MMARTPacket
MMARTPacket(std::vector< uint32_t > &payload)
Definition: MMARTPacket.cxx:15
Muon::nsw::MMARTPacket::m_art_BCID
uint32_t m_art_BCID
Definition: MMARTPacket.h:30
Muon::nsw::MMARTPacket::getLayer
uint8_t getLayer() const
Definition: MMARTPacket.h:39
Muon::nsw::MMARTPacket::VMMmapToHits
std::vector< std::tuple< uint8_t, uint8_t, uint8_t > > VMMmapToHits()
Definition: MMARTPacket.cxx:45