14 #include "GaudiKernel/MsgStream.h"
15 #include "GaudiKernel/StatusCode.h"
52 for (
auto elem :
vec) {
53 s << std::hex << std::showbase << std::setfill(
'0') << std::setw(8)
54 << elem <<
" " << std::dec << std::noshowbase;
73 const std::string &
name,
76 m_configSvc(
"TrigConf::TrigConfigSvc/TrigConfigSvc",
name),
77 m_errorTool(
"LVL1::TrigT1CaloMonErrorTool/TrigT1CaloMonErrorTool"),
78 m_histTool(
"LVL1::TrigT1CaloLWHistogramTool/TrigT1CaloLWHistogramTool"),
79 m_debug(false), m_histBooked(false),m_lumiNo(0),
80 m_h_l1topo_1d_CMXTobs(0),
81 m_h_l1topo_1d_Simulation(0),
82 m_h_l1topo_1d_JetTobs_EnergyLg(0),
83 m_h_l1topo_2d_Tobs_Hitmap_mismatch{},
84 m_h_l1topo_2d_Tobs_Hitmap_match{},
85 m_h_l1topo_2d_Tobs_etaPhi_mismatch{},
86 m_h_l1topo_2d_Tobs_etaPhi_match{},
87 m_h_l1topo_1d_Errors(0),
88 m_h_l1topo_1d_Overflows(0),
89 m_h_l1topo_1d_DAQTobs(0),
90 m_h_l1topo_1d_DAQJetTobs(0),
91 m_h_l1topo_1d_DAQTauTobs(0),
92 m_h_l1topo_1d_DAQEMTobs(0),
93 m_h_l1topo_1d_DAQMuonTobs(0),
94 m_h_l1topo_1d_DAQTriggerBits(0),
95 m_h_l1topo_1d_DAQMismatchTriggerBits(0),
96 m_h_l1topo_1d_DAQOverflowBits(0),
97 m_h_l1topo_1d_ROITobs(0),
98 m_h_l1topo_1d_ErrorsByLumiblock(0),
99 m_h_l1topo_2d_ItemsBC{},
100 m_h_l1topo_2d_ItemsBC_ratio{}
110 m_PathInRootFile=
"LVL1_Interfaces/L1Topo");
131 if (
sc.isFailure())
return sc;
134 if (
sc.isFailure() ) {
135 msg(MSG::ERROR) <<
"Couldn't connect to " <<
m_configSvc.typeAndName()
143 if (
sc.isFailure() ) {
144 msg(MSG::ERROR) <<
"Unable to locate Tool TrigT1CaloMonErrorTool"
150 if (
sc.isFailure() ) {
151 msg(MSG::ERROR) <<
"Unable to locate Tool TrigT1CaloLWHistogramTool"
158 return StatusCode::SUCCESS;
178 const EventContext& ctx = Gaudi::Hive::currentContext();
179 m_lumiNo = ctx.eventID().lumi_block();
193 "L1Topo error summary;;Number of Events",
194 ERROR_BIT::NUMBEROFBITS, 0, ERROR_BIT::NUMBEROFBITS);
198 "L1Topo overflows;Overflow;Number of Events",1,0,1);
200 for (
int i=0;
i<ERROR_BIT::NUMBEROFBITS;++
i)
205 m_histTool->book1F(
"l1topo_1d_ErrorsByLumiblock",
206 "Events with Errors by Lumiblock;"
207 "Lumi Block;Number of Events",2500,0,2500);
211 "Number of CMX TOBs",
216 "Simulated L1Topo trigger bits", 128, 0, 128);
221 bookJEMRoIEtaVsPhi(
"l1topo_2d_JetSTobs_etaPhi_mismatch",
222 "CMX-L1Topo mismatched small jet TOBs hit map");
224 bookJEMRoIEtaVsPhi(
"l1topo_2d_JetSTobs_etaPhi_match",
225 "CMX-L1Topo matched small jet TOBs hit map");
227 bookJEMRoIEtaVsPhi(
"l1topo_2d_JetLTobs_etaPhi_mismatch",
228 "CMX-L1Topo mismatched large jet TOBs hit map");
230 bookJEMRoIEtaVsPhi(
"l1topo_2d_JetLTobs_etaPhi_match",
231 "CMX-L1Topo matched large jet TOBs hit map");
233 bookCPMEtaVsPhi(
"l1topo_2d_TauTobs_etaPhi_mismatch",
234 "CMX-L1Topo mismatched tau TOBs hit map");
236 bookCPMEtaVsPhi(
"l1topo_2d_TauTobs_etaPhi_match",
237 "CMX-L1Topo matched tau TOBs hit map");
239 bookCPMEtaVsPhi(
"l1topo_2d_EMTobs_etaPhi_mismatch",
240 "CMX-L1Topo mismatched EM TOBs hit map");
242 bookCPMEtaVsPhi(
"l1topo_2d_EMTobs_etaPhi_match",
243 "CMX-L1Topo matched EM TOBs hit map");
245 bookCPMEtaVsPhi(
"l1topo_2d_MuTobs_etaPhi_mismatch",
246 "CMX-L1Topo mismatched muon TOBs hit map");
248 bookCPMEtaVsPhi(
"l1topo_2d_MuTobs_etaPhi_match",
249 "CMX-L1Topo matched muon TOBs hit map");
254 bookJEMCrateModuleVsFrameLoc(
"l1topo_2d_JetSTobs_Hitmap_mismatch",
255 "CMX-L1Topo mismatched small jet TOBs hit map");
257 bookJEMCrateModuleVsFrameLoc(
"l1topo_2d_JetSTobs_Hitmap_match",
258 "CMX-L1Topo matched small jet TOBs hit map");
260 bookJEMCrateModuleVsFrameLoc(
"l1topo_2d_JetLTobs_Hitmap_mismatch",
261 "CMX-L1Topo mismatched large jet TOBs hit map");
263 bookJEMCrateModuleVsFrameLoc(
"l1topo_2d_JetLTobs_Hitmap_match",
264 "CMX-L1Topo matched large jet TOBs hit map");
266 bookCPMCrateModuleVsTobChipLocalCoord(
"l1topo_2d_TauTobs_Hitmap_mismatch",
267 "CMX-L1Topo mismatched tau TOBs hit map");
269 bookCPMCrateModuleVsTobChipLocalCoord(
"l1topo_2d_TauTobs_Hitmap_match",
270 "CMX-L1Topo matched tau TOBs hit map");
272 bookCPMCrateModuleVsTobChipLocalCoord(
"l1topo_2d_EMTobs_Hitmap_mismatch",
273 "CMX-L1Topo mismatched EM TOBs hit map");
275 bookCPMCrateModuleVsTobChipLocalCoord(
"l1topo_2d_EMTobs_Hitmap_match",
276 "CMX-L1Topo matched EM TOBs hit map");
278 bookCPMCrateModuleVsTobChipLocalCoord(
"l1topo_2d_MuTobs_Hitmap_mismatch",
279 "CMX-L1Topo mismatched muon TOBs hit map");
281 bookCPMCrateModuleVsTobChipLocalCoord(
"l1topo_2d_MuTobs_Hitmap_match",
282 "CMX-L1Topo matched muon TOBs hit map");
287 book1F(
"l1topo_1d_JetTobs_EnergyLg",
288 "L1Topo-Jet TOB Energy Large Window Size", 256, 0., 1024);
293 "Number of L1Topo DAQ L1Topo TOBs",
297 "Number of L1Topo DAQ Jet TOBs",
301 "Number of L1Topo DAQ Tau TOBs",
305 "Number of L1Topo DAQ EM TOBs",
309 "Number of L1Topo DAQ Muon TOBs",
312 m_histTool->book1F(
"l1topo_1d_DAQTriggerBits",
313 "L1Topo DAQ trigger bits",
316 m_histTool->book1F(
"l1topo_1d_DAQMismatchTriggerBits",
317 "L1Topo DAQ-Simulation trigger bits mismatch",
320 m_histTool->book1F(
"l1topo_1d_DAQOverflowBits",
321 "L1Topo DAQ overflow bits",
325 "Number of L1Topo ROI L1Topo TOBs",
327 for (
int i=0;
i<4; ++
i) {
328 const std::string textFPGA[4]=
329 {
"L1Topo_00_U1",
"L1Topo_00_U2",
"L1Topo_01_U1",
"L1Topo_01_U2"};
331 m_histTool->bookTH2F(std::string(
"l1topo_2d_ItemsBC")+
333 std::string(
"Timing vs "
334 "Algorithm Number ")+textFPGA[
i],
335 32,
i*32, (
i+1)*32, 5, -2.5, 2.5);
337 m_histTool->bookTH2F(std::string(
"l1topo_2d_ItemsBC_online_ratio")+
339 std::string(
"(online) Timing Ratio vs "
340 "Algorithm Number ")+textFPGA[
i],
341 32,
i*32, (
i+1)*32, 5, -2.5, 2.5);
343 m_histTool->bookTH2F(std::string(
"l1topo_2d_ItemsBC_ratio")+
345 std::string(
"Timing Ratio vs "
346 "Algorithm Number ")+textFPGA[
i],
347 32,
i*32, (
i+1)*32, 5, -2.5, 2.5);
351 std::map<unsigned int, std::string> topoCounterToName;
352 const std::vector<TrigConf::TriggerThreshold*>& thrVec =
355 ATH_MSG_DEBUG(
"L1Topo bits found in the LVL1 menu = " << thrVec.size());
356 if (thrVec.size()>0) {
357 for (
auto thr : thrVec) {
361 topoCounterToName.emplace(thr->mapping(),thr->name());
367 << topoCounterToName.size());
371 if (
it != topoCounterToName.end()){
372 const bool USE_ALPHANUM=
true;
373 if (USE_ALPHANUM &&
it->second.length()>2) {
377 SetBinContent(
binIndex%32+1,bc,0.0001);
389 return StatusCode::SUCCESS;
402 return StatusCode::SUCCESS;
409 typedef std::tuple<int,int,int,int,int,int> TobKey;
422 if (
sc.isFailure()) {
436 if (
bx>=3 && l1aPos>0) {
437 for (
int bc=-dbx; bc<=dbx; ++bc) {
438 const CTP_BC& ctp_bc =
ctp.getBunchCrossings().at(l1aPos+bc);
439 std::bitset<512> tip = ctp_bc.
getTIP();
441 const unsigned int topoTipStart(384);
442 const unsigned int nTopoCTPOutputs(128);
443 for (
unsigned int item=0;
item<nTopoCTPOutputs;++
item) {
445 if (tip.test(
item+topoTipStart)) {
458 if (
sc.isFailure() || !cmxcptob) {
463 ATH_MSG_DEBUG(
"Found CMXCPTobCollection, looping on TOBs ..." );
468 cmxKeys[
TAU_TOB].insert(std::make_tuple(
t->crate(),
t->cpm(),
469 t->chip(),
t->location(),
472 cmxKeys[
EM_TOB].insert(std::make_tuple(
t->crate(),
t->cpm(),
473 t->chip(),
t->location(),
481 std::vector<const xAOD::CMXJetTob*> cmxtobs;
485 if (
sc.isFailure() || !cmxtob) {
491 ATH_MSG_DEBUG(
"Found CMXJetTobCollection, looping on TOBs ..." );
493 if (
t->energyLarge()) cmxtobs.push_back(
t);
495 if (
t->energyLarge())
496 cmxKeys[
JETL_TOB].insert(std::make_tuple(
t->crate(),
t->jem(),
497 t->frame(),
t->location(),
499 if (
t->energySmall())
500 cmxKeys[
JETS_TOB].insert(std::make_tuple(
t->crate(),
t->jem(),
501 t->frame(),
t->location(),
510 ATH_MSG_DEBUG(
"Could not retrieve LVL1::FrontPanelCTP with key "
516 ATH_MSG_INFO(
"Retrieve of LVL1::FrontPanelCTP failed." );
519 for(
unsigned int i=0;
i<32; ++
i) {
526 if( (topores0 & (0x1UL << (2*
i+0))))
528 if( (topores0 & (0x1UL << (2*
i+1))))
530 if( (topores1 & (0x1UL << (2*
i+0))))
532 if( (topores1 & (0x1UL << (2*
i+1))))
535 ATH_MSG_DEBUG(
"Simulated output from L1Topo from StoreGate with key "
538 << std::hex << std::setw( 8 ) << std::setfill(
'0' )
541 << std::hex << std::setw( 8 ) << std::setfill(
'0' )
544 << std::hex << std::setw( 8 ) << std::setfill(
'0' )
547 << std::hex << std::setw( 8 ) << std::setfill(
'0' )
556 if (
sc.isFailure() or 0 == rdos) {
559 ATH_MSG_DEBUG (
"Could not retrieve L1Topo DAQ RDO collection "
564 std::vector<L1Topo::L1TopoTOB> daqTobs;
565 std::vector<uint32_t> daqJetTobs;
566 std::vector<uint32_t> daqTauTobs;
567 std::vector<uint32_t> daqEMTobs;
568 std::vector<uint32_t> daqMuonTobs;
569 std::vector<uint32_t> vFibreSizes;
570 std::vector<uint32_t> vFibreStatus;
573 ATH_MSG_DEBUG(
"Trigger bits from L1Topo RDOs 0b" << triggerBits.first );
574 ATH_MSG_DEBUG(
"Overflow bits from L1Topo RDOs 0b" << triggerBits.second );
580 std::vector<L1Topo::Error>
errors = rdo->getErrors();
586 const std::vector<uint32_t> cDataWords = rdo->getDataWords();
588 if ( cDataWords.size() == 0 ) {
598 for (
const uint32_t word : cDataWords){
603 if (
header.payload_crc()!=0) {
607 i_fpga=(((rdo->getSourceID())>>3)&2)+
header.fpga();
613 for (
auto fsize: fibreBlock.count()){
614 vFibreSizes.push_back(fsize);
616 for (
auto fstatus: fibreBlock.status()){
617 vFibreStatus.push_back(fstatus);
625 <<
" fibre crc: " <<
status.crc() );
629 topo_error|=(1<<
F_CRC);
635 if (
header.bcn_offset()==0){
638 daqTobs.push_back(tob);
640 for (
unsigned int i=0;
i<8; ++
i){
641 if ((tob.trigger_bits() >>
i)&1)
643 if ((tob.overflow_bits()>>
i)&1)
652 if (
header.bcn_offset()==0) {
653 const int crate = (word >> 28) & 0
x1;
654 const int jem = (word >> 24) & 0xF;
655 const int frame = (word >> 21) & 0x7;
656 const int location = (word >> 19) & 0x3;
657 const int energyS = (word >> 10) & 0x1FF;
658 const int energyL = (word & 0x3FF);
660 topoKeys[
JETL_TOB].insert(std::make_tuple(crate,jem,frame,
664 daqJetTobs.push_back(tob);
668 topoKeys[
JETS_TOB].insert(std::make_tuple(crate,jem,frame,
676 if (
header.bcn_offset()==0) {
678 daqTauTobs.push_back(tob);
679 const int crate = (word >> 26) & 0x3;
680 const int cpm = (word >> 20) & 0xF;
681 const int chip = (word >> 15) & 0xF;
682 const int location = (word >> 13) & 0x3;
683 const int energy = (word & 0xFF);
692 if (
header.bcn_offset()==0) {
694 daqEMTobs.push_back(tob);
695 const int crate = (word >> 26) & 0x3;
696 const int cpm = (word >> 20) & 0xF;
697 const int chip = (word >> 15) & 0xF;
698 const int location = (word >> 13) & 0x3;
699 const int energy = (word & 0xFF);
701 topoKeys[
EM_TOB].insert(std::make_tuple(crate,cpm,chip,
708 if (
header.bcn_offset()==0){
710 daqMuonTobs.push_back(tob);
716 if (
header.bcn_offset()==0){
739 std::vector<L1Topo::L1TopoTOB> roiTobs;
742 const std::vector< ROIB::L1TopoResult > l1TopoResults =
744 ATH_MSG_DEBUG(
"Number of L1Topo ROI RODs found: " << l1TopoResults.size() );
745 for (
auto &
r : l1TopoResults) {
747 const auto& rdo =
r.rdo();
750 auto errors = rdo.getErrors();
756 const std::vector<uint32_t>& cDataWords = rdo.getDataWords();
757 if ( cDataWords.size() == 0 ) {
762 for (
const uint32_t word : cDataWords) {
768 roiTobs.push_back(tob);
770 for (
unsigned int i = 0;
i < 8; ++
i) {
790 for (
unsigned int i=1;
i<=128;++
i) {
799 set_symmetric_difference(cmxKeys[
t].
begin(),cmxKeys[
t].
end(),
801 inserter(keyDiff[
t],keyDiff[
t].
begin()));
802 if (keyDiff[
t].
size()>0) {
806 for (
auto& tob : keyDiff[
t]) {
810 jem2Coord(std::get<0>(tob),std::get<1>(tob),std::get<2>(tob),std::get<3>(tob),
815 cpm2Coord(std::get<0>(tob),std::get<1>(tob),std::get<2>(tob),std::get<3>(tob),
823 inserter(keyIntersect[
t],keyIntersect[
t].
begin()));
824 for (
auto& tob : keyIntersect[
t]) {
828 jem2Coord(std::get<0>(tob),std::get<1>(tob),std::get<2>(tob),std::get<3>(tob),
833 cpm2Coord(std::get<0>(tob),std::get<1>(tob),std::get<2>(tob),std::get<3>(tob),
845 return StatusCode::SUCCESS;
858 for (
int cpu=0; cpu<=3; ++cpu) {
860 for (
int bc=1; bc<=5; ++bc) {
867 float ratio=(binval<1 || centerbin<1 ? 0 : binval/centerbin);
875 return StatusCode::SUCCESS;
883 const int frame,
const int location,
884 int &
x,
int &
y,
double &
eta,
double &
phi)
889 ((((((crate << 4) + jem) << 3) + frame) << 2) +
location) << 19;
898 int &
x,
int &
y,
double &
eta,
double &
phi)
900 x = crate*14 + cpm - 1;
903 ((((((crate << 4) + cpm) << 4) + chip) << 2)