6 #include "CTPfragment/CTPfragment.h"
7 #include "CTPfragment/CTPdataformat.h"
30 return StatusCode::SUCCESS;
39 std::vector<int> ctpids_ele;
40 std::vector<int> ctpids_mu;
41 std::vector<int> ctpids_jets;
42 std::vector<int> ctpids;
47 ATH_MSG_DEBUG(
"L1CorrAlgInit: Configured to use item:" <<
item.name().c_str()<<
" CTPID:"<<
item.ctpId());
48 ctpids.push_back(
item.ctpId() );
50 ctpids_ele.push_back(
item.ctpId() );
53 ctpids_mu.push_back(
item.ctpId() );
56 ctpids_jets.push_back(
item.ctpId() );
67 for(
int n=0;
n<16 ;
n++){
76 for(
unsigned int n=0;
n<ctpids.size() ;
n++){
78 int cycle = ctpids[
n] / 32;
79 int pos = ctpids[
n] % 32;
84 tmpmask = tmpmask << (
pos);
91 for(
unsigned int n=0;
n<ctpids_ele.size() ;
n++){
93 int cycle = ctpids_ele[
n] / 32;
94 int pos = ctpids_ele[
n] % 32;
99 tmpmask = tmpmask << (
pos);
106 for(
unsigned int n=0;
n<ctpids_mu.size() ;
n++){
108 int cycle = ctpids_mu[
n] / 32;
109 int pos = ctpids_mu[
n] % 32;
114 tmpmask = tmpmask << (
pos);
121 for(
unsigned int n=0;
n<ctpids_jets.size() ;
n++){
123 int cycle = ctpids_jets[
n] / 32;
124 int pos = ctpids_jets[
n] % 32;
129 tmpmask = tmpmask << (
pos);
135 return StatusCode::SUCCESS;
143 ATH_CHECK(wh_trigComposite.
record(std::make_unique<xAOD::TrigCompositeContainer>(), std::make_unique<xAOD::TrigCompositeAuxContainer>()));
144 auto trigCompCont = wh_trigComposite.
ptr();
156 std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFragments;
157 std::vector<uint32_t> roblist;
159 roblist.push_back(0x770000);
163 std::ostringstream
os;
164 for(
auto rob : roblist){
168 <<
" ROBs requested/retrieved:" <<
os.str());
170 if (robFragments.size()<1){
172 return StatusCode::SUCCESS;
181 const int nBC = 2 * l1a_idx + 1;
182 const int mid = l1a_idx;
185 std::vector<std::vector<uint32_t>> tbpWords(nBC), tapWords(nBC);
186 for (
int i = 0;
i < nBC; ++
i) {
187 const unsigned k =
static_cast<unsigned>(
i);
188 tbpWords[
i] = CTPfragment::triggerDecisionBeforePrescales(rbf,
k);
189 tapWords[
i] = CTPfragment::triggerDecisionAfterPrescales (rbf,
k);
193 auto firedFromWords = [&](
const std::vector<uint32_t>&
w,
197 for (std::size_t iw = 0; iw < nw; ++iw) on |= static_cast<uint8_t>((
w[iw] &
mask[iw]) != 0
u);
202 std::vector<uint8_t> firedbc(nBC,0), firedbc_ele(nBC,0), firedbc_mu(nBC,0), firedbc_jet(nBC,0);
203 for (
int i = 0;
i < nBC; ++
i) {
212 firedbc[mid] = firedbc_ele[mid] = firedbc_mu[mid] = firedbc_jet[mid] = 1;
216 auto collect_ids_from_words = [
this](
const std::vector<uint32_t>&
words) {
217 std::vector<int>
ids;
218 const std::size_t nw =
std::min(
words.size(), this->m_bitmasks.size());
219 ids.reserve(32
u * nw);
220 for (std::size_t iw = 0; iw < nw; ++iw) {
223 const unsigned base =
static_cast<unsigned>(iw * 32
u);
224 for (
unsigned b = 0;
b < 32; ++
b)
if (
w & (1
u <<
b))
ids.emplace_back(
static_cast<int>(
base +
b));
229 std::vector<int> vDeltaBC_all_TBP, vCtpId_all_TBP, vDeltaBC_all_TAP, vCtpId_all_TAP;
230 vDeltaBC_all_TBP.reserve(64); vCtpId_all_TBP.reserve(64);
231 vDeltaBC_all_TAP.reserve(64); vCtpId_all_TAP.reserve(64);
233 for (
int i = 0;
i < nBC; ++
i) {
234 const int delta =
i - mid;
236 const auto ids = collect_ids_from_words(tbpWords[
i]);
237 vDeltaBC_all_TBP.insert(vDeltaBC_all_TBP.end(),
ids.size(), delta);
238 vCtpId_all_TBP.insert (vCtpId_all_TBP.end(),
ids.begin(),
ids.end());
241 const auto ids = collect_ids_from_words(tapWords[
i]);
242 vDeltaBC_all_TAP.insert(vDeltaBC_all_TAP.end(),
ids.size(), delta);
243 vCtpId_all_TAP.insert (vCtpId_all_TAP.end(),
ids.begin(),
ids.end());
249 int beforeafterflag = 0;
250 int offset_before = 0, offset_after = 0;
251 for (
int d = 1;
d <= l1a_idx; ++
d) {
252 if (firedbc[mid] && firedbc[mid -
d] && offset_before == 0) { offset_before =
d; isPassed = 1; }
253 if (firedbc[mid] && firedbc[mid +
d] && offset_after == 0) { offset_after =
d; isPassed = 1; }
254 if (offset_before && offset_after)
break;
259 if (firedbc_ele[
idx] && !firedbc_mu[
idx] && !firedbc_jet[
idx])
return 1;
260 else if (firedbc_mu [
idx] && !firedbc_ele[
idx] && !firedbc_jet[
idx])
return 2;
261 else if (firedbc_jet[
idx] && !firedbc_ele[
idx] && !firedbc_mu[
idx])
return 3;
262 else if (firedbc_ele[
idx] && firedbc_mu[
idx] && !firedbc_jet[
idx])
return 4;
263 else if (firedbc_ele[
idx] && firedbc_jet[
idx] && !firedbc_mu[
idx])
return 5;
264 else if (firedbc_mu [
idx] && firedbc_jet[
idx] && !firedbc_ele[
idx])
return 6;
265 else if (firedbc_ele[
idx] && firedbc_mu[
idx] && firedbc_jet[
idx])
return 7;
270 int other_type_before = (offset_before > 0) ?
classify(mid - offset_before) : 0;
271 int other_type_after = (offset_after > 0) ?
classify(mid + offset_after ) : 0;
274 if (offset_before > 0 && offset_after > 0) {
275 if (offset_before < offset_after) beforeafterflag = -offset_before;
276 else if (offset_after < offset_before) beforeafterflag = +offset_after;
277 else beforeafterflag = +offset_after;
278 }
else if (offset_before > 0) {
279 beforeafterflag = -offset_before;
280 }
else if (offset_after > 0) {
281 beforeafterflag = +offset_after;
285 if (beforeafterflag < 0) other_type = other_type_before;
286 else if (beforeafterflag > 0) other_type = other_type_after;
291 trigCompCont->push_back(trigComp);
292 trigComp->setName(
"mistimemon_L1Dec");
294 trigCompL1A (*trigComp) = l1a_type;
295 trigCompOther (*trigComp) = other_type;
296 trigCompBeforeAfter (*trigComp) = beforeafterflag;
297 trigCompPass (*trigComp) = isPassed;
298 trigCompOtherBefore (*trigComp) = other_type_before;
299 trigCompOtherAfter (*trigComp) = other_type_after;
300 trigCompBeforeOffset(*trigComp) = offset_before;
301 trigCompAfterOffset (*trigComp) = offset_after;
310 if (offset_before > 0 && offset_after > 0) {
317 }
else if (offset_before > 0) {
322 }
else if (offset_after > 0) {
335 mon_dbc_all_tap, mon_id_all_tap);
339 const auto ids0_tbp = collect_ids_from_words(tbpWords[mid]);
340 const auto ids0_tap = collect_ids_from_words(tapWords[mid]);
342 auto fill_pair_map = [&](
int deltaSel,
bool useTAP,
343 const char* varX,
const char* varY) {
344 const int kN = mid + deltaSel;
345 if (kN < 0 || kN >= nBC)
return;
347 const auto &idsN = useTAP ? collect_ids_from_words(tapWords[kN])
348 : collect_ids_from_words(tbpWords[kN]);
349 const auto& ids0 = useTAP ? ids0_tap : ids0_tbp;
351 if (ids0.empty() || idsN.empty())
return;
353 std::vector<int> vId0; vId0.reserve(ids0.size() * idsN.size());
354 std::vector<int> vIdN; vIdN.reserve(vId0.capacity());
355 for (
int id0 : ids0)
for (
int idN : idsN) { vId0.emplace_back(id0); vIdN.emplace_back(idN); }
364 fill_pair_map(+2,
false,
"CTPID0tbp_p2",
"CTPIDtbp_p2");
365 fill_pair_map(-2,
false,
"CTPID0tbp_m2",
"CTPIDtbp_m2");
366 fill_pair_map(+1,
false,
"CTPID0tbp_p1",
"CTPIDtbp_p1");
367 fill_pair_map(-1,
false,
"CTPID0tbp_m1",
"CTPIDtbp_m1");
370 fill_pair_map(+2,
true ,
"CTPID0tap_p2",
"CTPIDtap_p2");
371 fill_pair_map(-2,
true ,
"CTPID0tap_m2",
"CTPIDtap_m2");
372 fill_pair_map(+1,
true ,
"CTPID0tap_p1",
"CTPIDtap_p1");
373 fill_pair_map(-1,
true ,
"CTPID0tap_m1",
"CTPIDtap_m1");
375 return StatusCode::SUCCESS;