9 #include "GaudiKernel/MsgStream.h"
38 m_modules(16), m_maxTobs(4), m_sysCrate(1), m_debug(false) {
39 declareInterface<IL1JetCMXTools>(
this);
53 return StatusCode::SUCCESS;
60 std::vector<const xAOD::JEMTobRoIContainer *> jemRoiColls(1, jemRoiVec);
65 const std::vector<const xAOD::JEMTobRoIContainer *> &jemRoiColls,
67 std::map<uint32_t, const xAOD::JEMTobRoI *> jemRoiMap;
68 std::map<int, xAOD::CMXJetTob *> cmxTobMap;
70 int timeslices = jemRoiColls.size();
80 const int crate = roi->
crate();
81 const int jem = roi->
jem();
83 const int presenceBit = roi->
frame();
84 presenceMaps[
index] |= (1 << presenceBit);
87 jemRoiMap.insert(std::make_pair(
key, roi));
89 std::map<uint32_t, const xAOD::JEMTobRoI *>::const_iterator mit =
91 std::map<uint32_t, const xAOD::JEMTobRoI *>::const_iterator mitE =
93 for (; mit != mitE; ++mit) {
95 const int crate = roi->
crate();
96 const int jem = roi->
jem();
97 const int frame = roi->
frame();
102 const unsigned int presence = presenceMaps[
index];
106 for (
int bit = 0; bit <= frame; ++bit)
107 count += (presence >> bit) & 0x1;
114 const int key = (((((crate << 4) | jem) << 3) | frame) << 2) | loc;
117 if (xit == cmxTobMap.end()) {
121 if (timeslices > 0) {
122 std::vector<uint16_t> vecU16(timeslices);
123 std::vector<uint32_t> vecU32(timeslices);
124 tob->
addTob(vecU16, vecU16, vecU32, vecU16);
127 cmxTobMap.insert(std::make_pair(
key, tob));
133 std::vector<uint32_t> errorVec(tob->
errorVec());
135 energyLgVec[
slice] = energyLg;
136 energySmVec[
slice] = energySm;
138 presenceMapVec[
slice] = presence;
139 tob->
addTob(energyLgVec, energySmVec, errorVec, presenceMapVec);
168 std::vector<HitsVector> hitVecM(2 *
m_crates);
169 std::vector<HitsVector> hitVecF(2 *
m_crates);
170 std::vector<ErrorVector> errVecM(2 *
m_crates);
171 std::vector<ErrorVector> errVecF(2 *
m_crates);
176 for (;
pos != pose; ++
pos) {
184 getHits(tob, hit10, hit11, hit20, hit21);
195 const int peak = tob->
peak();
200 for (
int crate = 0; crate <
m_crates; ++crate) {
201 const int index = crate * 2;
230 for (;
pos != pose; ++
pos) {
240 int peak =
hits->peak();
257 saveCMXJetHits(cmxHitsSys, systemMain0, systemMain1, errVec, errVec,
268 std::vector<HitsVector> hitVec(4 *
m_crates);
271 for (;
pos != pose; ++
pos) {
273 const int crate = tob->
crate();
274 const int jem = tob->
jem();
275 const int frame = tob->
frame();
277 const int index = crate * 4;
283 timeslices = energyLg.size();
288 checksum.resize(timeslices);
289 map.resize(timeslices);
290 countsLow.resize(timeslices);
291 countsHigh.resize(timeslices);
293 if (energyLg[
slice] == 0 && energySm[
slice] == 0)
298 const int overflow = 0;
300 jem + frame + loc + energyLg[
slice] + energySm[
slice] + overflow;
301 checksum[
slice] &= 0xffff;
303 map[
slice] |= (1 << jem);
306 countsLow[
slice] += (1 << (3 * jem));
308 countsHigh[
slice] += (1 << (3 * (jem - 8)));
311 const int peak = tob->
peak();
318 for (
int crate = 0; crate <
m_crates; ++crate) {
319 const int index = crate * 4;
336 const int timeslices = energyLg.size();
339 hit10.assign(timeslices, 0);
340 hit11.assign(timeslices, 0);
341 hit20.assign(timeslices, 0);
342 hit21.assign(timeslices, 0);
346 hit10[
slice] = 0x7fff;
347 hit11[
slice] = 0x7fff;
348 hit20[
slice] = 0xffff;
349 hit21[
slice] = 0x3fff;
353 if (energyLg[
slice] == 0 && energySm[
slice] == 0)
364 unsigned int numThresholdsHalf = 5;
365 unsigned int numBitsPerCounter = 3;
367 for (
unsigned int i = 0;
i < numThresholdsHalf * 2; ++
i) {
369 HitsVector &hit =
i < numThresholdsHalf ? hit10 : hit11;
370 unsigned int ibit =
i < numThresholdsHalf ?
i :
i - numThresholdsHalf;
371 hit[
slice] |= (1 << (ibit * numBitsPerCounter));
375 numThresholdsHalf = 8;
376 numBitsPerCounter = 2;
378 for (
unsigned int i = 0;
i < numThresholdsHalf * 2; ++
i) {
380 HitsVector &hit =
i < numThresholdsHalf ? hit20 : hit21;
381 unsigned int ibit =
i < numThresholdsHalf ?
i :
i - numThresholdsHalf;
382 hit[
slice] |= (1 << (ibit * numBitsPerCounter));
393 const int timeslices = tobErr.size();
394 hitErr.resize(timeslices);
411 int size1 = vec1.size();
412 int size2 =
vec2.size();
417 HitsVector::const_iterator pos2 =
vec2.begin();
418 HitsVector::const_iterator pose2 =
vec2.end();
419 for (; pos1 != pose1 && pos2 != pose2; ++pos1, ++pos2) {
421 *pos1 =
addHits(*pos1, *pos2, 15, 15, 5);
423 *pos1 =
addHits(*pos1, *pos2, 16, 16, 8);
430 int multBits,
int vecBits,
433 msg(
MSG::DEBUG) <<
"addHits: Original hitMult = " << std::hex << hitMult
434 <<
". Add hitWord = " << hitVec << std::dec <<
endmsg;
436 int nbitsOut = multBits / nthresh;
437 int nbitsIn = vecBits / nthresh;
442 int max = (1 << nbitsOut) - 1;
443 unsigned int multMask =
max;
444 unsigned int hitMask = (1 << nbitsIn) - 1;
445 unsigned int shift = 0;
447 unsigned int hits = 0;
449 for (
int i = 0;
i < nthresh;
i++) {
450 int mult = (hitMult & multMask) + (hitVec & hitMask);
451 mult = ((mult <=
max) ? mult :
max);
452 hits += (mult << shift);
454 hitMult >>= nbitsOut;
478 cmxHitsVec2->
clear();
488 int source,
int peak)
const {
492 item->makePrivateStore();
493 item->initialize(crate,
source, hits0, hits1, err0, err1, peak);