83{
84
85
86
87
88
89
90
91
92
93
94
96
98 DataVector<CMXCPTob>* CMXTobs = new DataVector<CMXCPTob>;
100 DataVector<CMXCPHits>* CMXHits = new DataVector<CMXCPHits>;
102
103
108
109 std::vector< std::vector< std::vector<int> > > crateHits;
110 std::vector< std::vector<int> > Hits;
111
112 Hits.resize(2);
113 Hits[0].resize(16);
114 Hits[1].resize(16);
115
116 crateHits.resize(4);
117 for (int crate = 0; crate < 4; ++crate) {
118 crateHits[crate].resize(2);
119 for (int cmx = 0; cmx < 2; ++cmx) {
120 crateHits[crate][cmx].resize(16);
121 }
122 }
123
124
125
127 ATH_CHECK(topoData.
record(std::make_unique<DataVector<CPCMXTopoData>>()));
128 for (int crate = 0; crate < 4; ++crate) {
129 for (int cmx = 0; cmx < 2; ++cmx) {
130 CPCMXTopoData* link = new CPCMXTopoData(crate, cmx);
131 topoData->push_back(link);
132 }
133 }
134
135
136 bool cpmOverflow[2] = {false, false};
137
140
141
142 float cpScale = l1Menu->thrExtraInfo().EM().emScale();
143 std::vector<std::shared_ptr<TrigConf::L1Threshold>> allThresholds = l1Menu->thresholds();
144 std::vector<std::shared_ptr<TrigConf::L1Threshold>> thresholds;
145 for ( const auto& thresh : allThresholds ) {
148 thresholds.push_back( thresh );
149 }
150
153
155 for ( ;
it != bpData->end(); ++
it) {
156 int crate = (*it)->crate();
157 int cmx = (*it)->type();
158 std::vector<unsigned int> tobWords = (*it)->TopoTOBs();
159
160
161 int index = 2*crate + cmx;
162 bool overflow = (*it)->overflow();
163 if (overflow) {
164 (*topoData)[
index]->setOverflow(
true);
165 cpmOverflow[cmx] = true;
166 }
167
168 for (std::vector<unsigned int>::const_iterator word = tobWords.begin();
169 word != tobWords.end(); ++word) {
170
171
172 (*topoData)[
index]->addTOB( (*word) );
173
174
175 CPTopoTOB tob( crate, cmx, (*word) );
176 int ieta = tob.ieta() - 1;
177 int iphi = tob.iphi();
178 if (iphi < 0) iphi += 64;
180 unsigned int isol = tob.isolation();
181
182
183 for ( const auto& thresh : thresholds ) {
184
185 if (
thresh->type() != triggerTypes[cmx] )
continue;
186
187 std::optional<uint16_t> isolMask;
188 if (
thresh->className() ==
"L1Threshold_EM") {
189 auto thresh_EM =
static_cast<TrigConf::L1Threshold_EM*
>(
thresh.get());
190 isolMask = thresh_EM->isolationMask(ieta);
191 }
192 else if (
thresh->className() ==
"L1Threshold_TAU") {
193 auto thresh_TAU =
static_cast<TrigConf::L1Threshold_TAU*
>(
thresh.get());
194 isolMask = thresh_TAU->isolationMask();
195 }
196
197
198 bool isolationPassed = true;
199 if (isolMask) {
201 if ( (*isolMask & (1<<bit)) && !(isol & (1<<bit)) ) isolationPassed = false;
202 }
203
204 int etCut =
thresh->thrValue(ieta)*cpScale;
205 if (
et > etCut && isolationPassed ) {
207 if (num < 16) {
208 if (crateHits[crate][cmx][num] < 7) crateHits[crate][cmx][
num]++;
209 if (Hits[cmx][num] < 7) Hits[cmx][
num]++;
210 }
212 }
213
214 }
215
216 }
217
218 }
219
220
221 for (int cmx = 0; cmx < 2; ++cmx) {
222 if (cpmOverflow[cmx]) {
223 for (
int i = 0;
i < 16; ++
i) Hits[cmx][i] = 7;
224 }
225 }
226
227
228 unsigned int cableWord0 = 0;
229 unsigned int cableWord1 = 0;
230 unsigned int cableWord2 = 0;
231 unsigned int cableWord3 = 0;
232 for (
int i = 0;
i < 8; ++
i) {
233 cableWord0 |= ( Hits[0][
i]<<(3*
i) );
234 cableWord1 |= ( Hits[0][
i+8]<<(3*
i) );
235 cableWord2 |= ( Hits[1][
i]<<(3*
i) );
236 cableWord3 |= ( Hits[1][
i+8]<<(3*
i) );
237 }
238
240 ATH_CHECK(emTauCTP.
record(std::make_unique<EmTauCTP>(cableWord0, cableWord1, cableWord2, cableWord3)));
241
242
243 std::vector<int> error0;
244 std::vector<int> error1;
245
246
247 std::vector<unsigned int> cratehits0;
248 std::vector<unsigned int> cratehits1;
249 const int peak = 0;
250 const int system_crate = 3;
251
252
253 for (int crate = 0; crate < 4; ++crate) {
254 for (int cmx = 0; cmx < 2; ++cmx) {
255 cratehits0.assign(1,0);
256 cratehits1.assign(1,0);
257 for (
int i = 0;
i < 8; ++
i) {
258 cratehits0[0] |= ( crateHits[crate][cmx][
i]<<(3*
i) );
259 cratehits1[0] |= ( crateHits[crate][cmx][
i+8]<<(3*
i) );
260 }
262 cratehits0, cratehits1, error0, error1, peak);
264 if (crate != system_crate) {
266 cratehits0, cratehits1, error0, error1, peak);
268 }
269 }
270 }
271
272
273 cratehits0.assign(1,cableWord0);
274 cratehits1.assign(1,cableWord1);
276 cratehits0, cratehits1, error0, error1, peak);
277 cratehits0.assign(1,cableWord2);
278 cratehits1.assign(1,cableWord3);
280 cratehits0, cratehits1, error0, error1, peak);
283
284
285 return StatusCode::SUCCESS ;
286}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
float et(const xAOD::jFexSRJetRoI *j)
DataModel_detail::const_iterator< DataVector > const_iterator
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::WriteHandleKey< EmTauCTP > m_CTPOutputKey
SG::WriteHandleKey< DataVector< CMXCPTob > > m_CMXCPTobLocation
Where to store the CMXCPTobs (for CMX readout simulation)
SG::ReadHandleKey< DataVector< LVL1::CPMCMXData > > m_CPMCMXDataLocation
Location of input data in StoreGate.
SG::WriteHandleKey< DataVector< CPCMXTopoData > > m_TopoOutputLocation
Locations of real-time outputs in StoreGate.
SG::ReadHandleKey< TrigConf::L1Menu > m_L1MenuKey
SG::WriteHandleKey< DataVector< CMXCPHits > > m_CMXCPHitsLocation
Store CTP SLink data objects in the TES.
static const unsigned int numOfIsolationBits
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
static std::string & typeAsString(TriggerType tt)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
CMXCPHits_v1 CMXCPHits
Define the latest version of the CMMCPHits class.