40 {
41 bool trigger = false;
42 bool beamcounter = false;
43 bool RC_signal = false;
44 bool scintillatorA = false;
45 bool scintillatorB = false;
46 bool master_trigger = false;
47 bool blacklisted = false;
48 int module = 0;
49 int station = 0;
50 int channel_offset = 0;
52 case 0:
55 station = (
channel < 96) ? 1 : 2;
56 module = (channel / 48) % 2;
58 break;
59 case 1:
62 station = (
channel < 80) ? 2 : 4;
63 channel_offset = (
channel < 80) ? 112 : 1;
67 break;
68 case 2:
71 station = 4;
72 channel_offset = -119;
73 module = (channel / 48) % 3 + 1;
75 break;
76 case 3:
79 station = (
channel < 32) ? 4 : 3;
80 channel_offset = (
channel < 32) ? 1 : 33;
81 module = ((channel + 16) / 48 + 3) % 4;
84 break;
85 case 4:
90 module = (channel / 48) % 2 + 2;
91 channel_offset = (
channel < 48) * 33;
92 station = 3;
94 break;
95 }
96 if (trigger) {
97 return 0;
98 } else if (master_trigger) {
99 return 1;
100 } else if (beamcounter || RC_signal) {
101 return -1;
102 } else if (scintillatorA) {
103 return 6;
104 } else if (scintillatorB) {
105 return 7;
106 } else if(blacklisted) {
107 return -2;
108 }
109 bool reverse_x = !(station == 2 || (
TDC == 4 &&
channel >= 48));
110 int _channel =
channel + channel_offset;
111 _channel += (_channel < 0) * 0x80;
112 _channel = reverse_x ? (0x80 - _channel % 0x80) % 0x80 : _channel;
114 _channel += _channel ? 63 : 191;
116 _channel += (
channel < 32) ? 24 : 32;
117 }
119 module = (_channel / 48) % 2;
120 }
121
122 int view = (station == 1 || station == 2) * module % 2;
123 int plane = (
TDC == 2) ? ((_channel % 48) / 24 + 1) % 2
124 : (station == 3 &&
TDC == 4) ? 1 - (
channel % 48) / 24 : (_channel % 48) / 24;
125 if (station == 4 &&
TDC == 3) {
126 plane -= 1;
127 }
128 int layer = (
TDC == 4) ? 1 - (
channel % 24) / 12 : (_channel % 24) / 12;
129 int straw = _channel % 12 + ((station == 3 || station == 4) ? 1 + (3 - module) * 12 : 1);
130 return station * 10000000 + view * 1000000 + plane * 100000 + layer * 10000 + 2000 +
straw;
131 };