SND@LHC Software
Loading...
Searching...
No Matches
RPCUnpack.cxx
Go to the documentation of this file.
1#include <cassert>
2
3// ROOT headers
4#include "TClonesArray.h"
5
6// Fair headers
7#include "FairRootManager.h"
8#include "FairRunOnline.h"
9#include "FairLogger.h"
10
11// SHiP headers
12#include "RPCUnpack.h"
13#include "MuonTaggerHit.h"
15
16struct RawHit {
17 uint16_t ncrate : 8;
18 uint16_t nboard : 8;
19 uint16_t hitTime;
20 uint8_t pattern[8];
21};
22
23enum Direction { horizontal = 0, vertical = 1 };
24
25int GetId(int ncrate, int nboard, int channel)
26{
27 assert(ncrate == 16 || ncrate == 18);
28 assert(nboard > 0 && nboard < 16);
29 int station;
30 int nboardofstation;
31 switch (ncrate) {
32 case 16:
33 station = (nboard < 6) ? 1 : 2;
34 nboardofstation = nboard - (station - 1) * 5;
35 break;
36 case 18:
37 station = (nboard < 6) ? 3 : (nboard < 11) ? 4 : 5;
38 nboardofstation = nboard - (station - 3) * 5;
39 break;
40 }
41 int direction = (nboardofstation < 4) ? vertical : horizontal;
42 int strip = direction == vertical
43 ? channel - 3
44 : (channel < 16) ? 10 - channel
45 : (channel < 32) ? 42 - channel : (channel < 48) ? 74 - channel : 106 - channel;
46 strip += (nboardofstation - (direction == vertical ? 1 : 4)) * 64;
47 LOG(DEBUG) << ncrate << '\t' << nboard << '\t' << channel << '\t' << station << '\t' << strip << '\t'
48 << (direction == vertical ? 'V' : 'H');
49 return 10000 * station + 1000 * direction + strip;
50}
51
52// RPCUnpack: Constructor
53RPCUnpack::RPCUnpack() : fRawData(new TClonesArray("MuonTaggerHit")), fNHits(0), fNHitsTotal(0), fPartitionId(0x0B00) {}
54
55// Virtual RPCUnpack: Public method
56RPCUnpack::~RPCUnpack() = default;
57
58// Init: Public method
60{
61 Register();
62 return kTRUE;
63}
64
65// Register: Protected method
67{
68 LOG(INFO) << "RPCUnpack : Registering...";
69 FairRootManager *fMan = FairRootManager::Instance();
70 if (!fMan) {
71 return;
72 }
73 fMan->Register("Digi_MuonTaggerHits", "RPCs", fRawData.get(), kTRUE);
74}
75
76// DoUnpack: Public method
77Bool_t RPCUnpack::DoUnpack(Int_t *data, Int_t size)
78{
79 LOG(DEBUG) << "RPCUnpack : Unpacking frame... size/bytes = " << size;
80
81 auto df = reinterpret_cast<DataFrame *>(data);
82 switch (df->header.frameTime) {
83 case SoS: LOG(INFO) << "RPCUnpack: SoS frame."; return kTRUE;
84 case EoS: LOG(INFO) << "RPCUnpack: EoS frame."; return kTRUE;
85 default: break;
86 }
87 assert(df->header.size == size);
88 auto nhits = (size - sizeof(DataFrame)) / 12;
89 static_assert(sizeof(RawHit) == 12, "Padding is off");
90 int skipped = 0;
91 auto hits = reinterpret_cast<unsigned char *>(df->hits);
92 const int BYTES_PER_HITPATTERN = 8;
93 const int BYTES_PER_RECORD = 12;
94 for (int i = 0; i < nhits; i++) {
95 auto hit = hits + i * BYTES_PER_RECORD;
96 auto crate = (unsigned int)hit[0];
97 auto board = (unsigned int)hit[1];
98 for (int k = 1; k <= BYTES_PER_HITPATTERN; k++) {
99 auto index = k + 3;
100
101 auto bitMask = 0x1;
102 for (int j = 0; j < 8; j++) {
103 if (hit[index] & bitMask) {
104 auto channel = (BYTES_PER_HITPATTERN - k) * 8 + j;
105 if ((crate == 16 && (board == 5 || board == 10) && channel >= 48 && channel <= 53) ||
106 (crate == 16 && (board == 3 || board == 8) && channel >= 60 && channel <= 63) ||
107 (crate == 16 && (board == 4 || board == 9) && channel >= 10 && channel <= 15) ||
108 (crate == 16 && (board == 1 || board == 6) && channel >= 0 && channel <= 3) ||
109 (crate == 18 && (board == 5 || board == 10 || board == 15) && channel >= 48 && channel <= 53) ||
110 (crate == 18 && (board == 3 || board == 8 || board == 13) && channel >= 60 && channel <= 63) ||
111 (crate == 18 && (board == 4 || board == 9 || board == 14) && channel >= 10 && channel <= 15) ||
112 (crate == 18 && (board == 1 || board == 6 || board == 11) && channel >= 0 && channel <= 3)) {
113 skipped++;
114 continue;
115 }
116 new ((*fRawData)[fNHits])
117 MuonTaggerHit(GetId(crate, board, channel), Float_t(df->header.frameTime) * 25);
118 fNHits++;
119 }
120 bitMask <<= 1;
121 }
122 }
123 }
124
125 if (skipped) {
126 LOG(WARNING) << "Skipped " << skipped << " hits on unconnected channels (probably noise).";
127 }
129 return kTRUE;
130}
131
132// Reset: Public method
134{
135 LOG(DEBUG) << "RPCUnpack : Clearing Data Structure";
136 fRawData->Clear();
137 fNHits = 0;
138}
139
Direction
Definition RPCUnpack.cxx:23
@ vertical
Definition RPCUnpack.cxx:23
@ horizontal
Definition RPCUnpack.cxx:23
int GetId(int ncrate, int nboard, int channel)
Definition RPCUnpack.cxx:25
std::unique_ptr< TClonesArray > fRawData
Definition RPCUnpack.h:42
virtual void Reset() override
virtual Bool_t Init() override
Definition RPCUnpack.cxx:59
Int_t fNHitsTotal
Definition RPCUnpack.h:44
Int_t fNHits
Definition RPCUnpack.h:43
virtual void Register() override
Definition RPCUnpack.cxx:66
virtual ~RPCUnpack()
virtual Bool_t DoUnpack(Int_t *data, Int_t size) override
Definition RPCUnpack.cxx:77
ClassImp(ecalContFact) ecalContFact
uint8_t pattern[8]
Definition RPCUnpack.cxx:20
uint16_t nboard
Definition RPCUnpack.cxx:18
uint16_t hitTime
Definition RPCUnpack.cxx:19
uint16_t ncrate
Definition RPCUnpack.cxx:17