ATLAS Offline Software
TrigT1MBTS.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 
4 #include "TrigT1MBTS.h"
7 #include "TrigConfData/L1Menu.h"
8 
9 
10 
11 LVL1::TrigT1MBTS::TrigT1MBTS(const std::string& name, ISvcLocator* pSvcLocator)
12  : AthAlgorithm(name, pSvcLocator),
13  m_thresholdNumber{{0,1,2,3,4,5,6,7}, {8,9,10,11,12,13,14,15}},
14  m_thresholdNumber12{{0,1,2,3,4,5,6,7}, {8,1000,9,1000,10,1000,11,1000}} // in Run 2 the outer MBTS were reduced to 4
15 {}
16 
19 {
20  ATH_MSG_INFO("Initialising TrigT1MBTS, name = " << name());
21 
22  m_thresholds_a.clear();
23  m_thresholds_c.clear();
24  m_thresholds_short_a.clear();
25  m_thresholds_short_c.clear();
26  m_thresholds_a.resize(16,0);// set the threshold to zero here -
27  // override again further down
28  m_thresholds_c.resize(16,0);// set the threshold to zero here -
29  // override again further down
30  m_thresholds_short_a.resize(12,0);// set the threshold to zero here -
31  // override again further down
32  m_thresholds_short_c.resize(12,0);// set the threshold to zero here -
33  // override again further down
34  m_cablestarts_a.clear();
35  m_cablestarts_c.clear();
36  m_cablestarts_a.resize(16,0);// default is bit 0
37  m_cablestarts_c.resize(16,0);// default is bit 0
38 
39  // Retrieve TileTBID helper from det store
40  // (The MBTS was added to the Test Beam (TB) list.)
41  ATH_CHECK(detStore()->retrieve(m_tileTBID));
42 
43  const TrigConf::L1Menu * l1menu = nullptr;
45 
46  // MBTS
47  for (std::shared_ptr<TrigConf::L1Threshold> thr : l1menu->thresholds("MBTS")) {
48  if(thr->name() != "MBTS_A" && thr->name() != "MBTS_C") {
49  continue;
50  }
51  std::string connName = l1menu->connectorNameFromThreshold(thr->name());
52  unsigned int startbit = l1menu->connector(connName).triggerLine(thr->name()).startbit();
53  m_ThrVecSize12 = true; // TODO: check for (thresholds[0]->thresholdValueVector().size() == 12);
54  std::vector<float> hwThrValues(12, 0.0); // TODO need to add configuration access in TrigConfData/Threshold.h
55  if(thr->name() == "MBTS_A") {
56  m_cablestart_a = startbit;
57  if(m_ThrVecSize12) {
58  m_thresholds_short_a = hwThrValues;
59  } else {
60  m_thresholds_a = hwThrValues;
61  }
62  } else {
63  m_cablestart_c = startbit;
64  if(m_ThrVecSize12) {
65  m_thresholds_short_c = hwThrValues;
66  } else {
67  m_thresholds_c = hwThrValues;
68  }
69  }
70  }
71 
72  // MBTSSI
73  for (std::shared_ptr<TrigConf::L1Threshold> thr : l1menu->thresholds("MBTSSI")) {
74  //m_singleCounterInputs = true;
75  std::string thrname = thr->name();
76  // figure out module number from threshold name
77  size_t module = std::stoi(thrname.substr(6));
78  float hwValue = 0; // TODO implement access
79  std::string connName = l1menu->connectorNameFromThreshold(thr->name());
80  unsigned int startbit = l1menu->connector(connName).triggerLine(thr->name()).startbit();
81  ATH_MSG_INFO("Read " << thrname << " with voltage " << hwValue << "mV at bit " << startbit << " on " << connName);
82  // Get the discriminator threshold settings (single inputs) for the C side.
83  bool isCSide = thrname.find("MBTS_C")==0;
84  if(isCSide) {
85  if(module >= m_thresholds_c.size()) {
86  ATH_MSG_WARNING("Module number " << module << " on side C out of range");
87  } else {
88  m_thresholds_c[module] = hwValue;
89  m_cablestarts_c[module] = startbit;
90  }
91  } else if(thrname.starts_with( "MBTS_A") && thrname.size()>6) {
92  // Get the discriminator threshold settings (single inputs) for the A side.
93  // figure out module number from threshold name
94  if(module >= m_thresholds_a.size()) {
95  ATH_MSG_WARNING("Module number " << module << " on side A out of range");
96  } else {
97  m_thresholds_a[module] = hwValue;
98  m_cablestarts_a[module] = startbit;
99  }
100  }
101  }
102 
103 
104  // MBTS_A, MBTS_C or MBTS_A, MBTS_C, MBTS_0, MBTS_1,...,MBTS_15 are used.
105  // Therefore thess messages are just INFO rather than warning.
106  if(m_thresholds_a.size() != 16) {
107  ATH_MSG_INFO("MBTS_A Lvl 1 single input thresholds not set. Triggers will be disabled.");
108  m_thresholds_a.clear();
109  for(size_t i=0;i<16;i++) {
110  m_thresholds_a.push_back(10000000);
111  }
112  }
113  if(m_thresholds_c.size() != 16) {
114  ATH_MSG_INFO("MBTS_C Lvl 1 single input thresholds not set. Triggers will be disabled.");
115  m_thresholds_c.clear();
116  for(size_t i=0;i<16;i++) {
117  m_thresholds_c.push_back(10000000);
118  }
119  }
120 
121  // Print out the state of this algorithm
122  if(msgLvl(MSG::INFO)) {
123  msg(MSG::INFO) << "=================== Settings ==================" << endmsg;
124  msg(MSG::INFO) << "TileTTL1ContainerName = " << m_tileTTL1ContainerName << endmsg;
125  msg(MSG::INFO) << "Sample t0 bin index = " << m_tZeroBin << endmsg;
126  msg(MSG::INFO) << "CFD fraction constant = " << m_CFD_fraction << endmsg;
127  if(m_ThrVecSize12){
128  msg(MSG::INFO) << "C side thresholds for single inputs = {";
129  for(size_t i=0;i<12;i++) {
130  msg(MSG::INFO) << m_thresholds_short_c[i];
131  if(i<11) msg(MSG::INFO) << ",";
132  }
133  msg(MSG::INFO) << "}" << endmsg;
134  msg(MSG::INFO) << "A side thresholds for single inputs = {";
135  for(size_t i=0;i<12;i++) {
136  msg(MSG::INFO) << m_thresholds_short_a[i];
137  if(i<11) msg(MSG::INFO) << ",";
138  }
139  msg(MSG::INFO) << "}" << endmsg;
140  if(msgLvl(MSG::INFO)) {
141  msg(MSG::DEBUG) << "thresholdNumber12: ";
142  for(size_t j=0;j<2;j++) {
143  for(size_t i=0;i<8;i++) {
144  msg(MSG::DEBUG) << m_thresholdNumber12[j][i];
145  if(i<7) msg(MSG::DEBUG) << ",";
146  }
147  msg(MSG::DEBUG) << endmsg;
148  }
149  }
150  } else {
151  msg(MSG::INFO) << "C side thresholds for single inputs = {";
152  for(size_t i=0;i<16;i++) {
153  msg(MSG::INFO) << m_thresholds_c[i];
154  if(i<15) msg(MSG::INFO) << ",";
155  }
156  msg(MSG::INFO) << "}" << endmsg;
157  msg(MSG::INFO) << "A side thresholds for single inputs = {";
158  for(size_t i=0;i<16;i++) {
159  msg(MSG::INFO) << m_thresholds_a[i];
160  if(i<15) msg(MSG::INFO) << ",";
161  }
162  msg(MSG::INFO) << "}" << endmsg;
163  }
164 
165  msg(MSG::DEBUG) << "thresholdNumber: " << endmsg;
166  for(size_t j=0;j<2;j++) {
167  for(size_t i=0;i<8;i++) {
168  msg(MSG::DEBUG) << m_thresholdNumber[j][i];
169  if(i<7) msg(MSG::DEBUG) << ",";
170  }
171  msg(MSG::DEBUG) << endmsg;
172  }
173  msg(MSG::INFO) << "===============================================" << endmsg;
174  }
175  return StatusCode::SUCCESS;
176 }
177 
180 {
181  // Retrieve the TileTTL1 container that contains the input MBTS information.
182  const TileTTL1Container* tileTTL1MBTSContainer{nullptr};
183  StatusCode sc = evtStore()->retrieve(tileTTL1MBTSContainer, m_tileTTL1ContainerName);
184  if( sc.isFailure() || !tileTTL1MBTSContainer ) {
185  ATH_MSG_WARNING(m_tileTTL1ContainerName << " not found. This event will be skipped.");
186  return StatusCode::SUCCESS;
187  }
188 
189  // Check for previous bug: there should be 24 or less depending on
190  // the configuration of the Tile algorithm that creates the
191  // TileTTL1MBTS container.
192  if(tileTTL1MBTSContainer->size() > 32) {
193  if(!m_badDataFound) {
194  ATH_MSG_WARNING("BAD DATA!!! tileTTL1MBTSContainer->size() = " << tileTTL1MBTSContainer->size());
195  ATH_MSG_WARNING("There should be no more than 24 TileTTL1MBTS elements in one event.");
196  ATH_MSG_WARNING("This event will be skipped. Any further bad data will be skipped.");
197  m_badDataFound = true;
198  }
199  return StatusCode::SUCCESS;
200  }
201 
202  unsigned int triggersEBA = 0; // Number of triggers in EBA
203  unsigned int triggersEBC = 0; // Number of triggers in EBC
204  unsigned int single_triggers_A = 0;
205  unsigned int single_triggers_C = 0;
206 
207  // Loop over all Lvl 1 MBTS trigger paddles
208  for(const TileTTL1 * ttl1_mbts : *tileTTL1MBTSContainer) {
209 
210  // Find out which MBTS paddle this is.
211  Identifier id = ttl1_mbts->identify();
212  if (!m_tileTBID->is_tiletb(id)) {
213  ATH_MSG_ERROR("This is not an MBTS identifier!");
214  return StatusCode::FAILURE;
215  }
216 
217  int phi = m_tileTBID->phi(id);
218  if(phi < 0 || phi > 7) {
219  ATH_MSG_ERROR("Phi value " << phi << " is out of range!");
220  return StatusCode::FAILURE;
221  }
222 
223  int channel = m_tileTBID->channel(id);
224  if(channel < 0 || channel > 1) {
225  ATH_MSG_ERROR("Channel value " << channel << " is out of range!");
226  return StatusCode::FAILURE;
227  }
228 
229  int detSide = m_tileTBID->type(id);
230  if(detSide != -1 && detSide != 1) {
231  ATH_MSG_ERROR("Side value " << detSide << " is out of range!");
232  return StatusCode::FAILURE;
233  }
234 
235  // Retrieve the MBTS signal samples.
236  const std::vector<double> & samples = ttl1_mbts->samples();
237  unsigned int numSamples = samples.size();
238  if(m_tZeroBin >= numSamples) {
239  ATH_MSG_ERROR("t0 bin index " << m_tZeroBin << " is greater than the number of bins " << numSamples);
240  return StatusCode::FAILURE;
241  }
242 
243  ATH_MSG_DEBUG("Sample [" << m_tZeroBin << "]=" << samples[m_tZeroBin]);
244  /*
245  // Only the even counters are used for RunII
246  if(channel == 1 && phi > 7 && phi%2 != 0) {
247  ATH_MSG_DEBUG("Out counter " << phi << " is not used for RunII! This counter will be skipped!");
248  continue;
249  }
250  */
251  // Single input triggers.
252  unsigned int thresholdIndex = m_thresholdNumber[channel][phi];
253  unsigned int thresholdIndex12 = m_thresholdNumber12[channel][phi];
254  if(thresholdIndex > (unsigned int)m_thresholds_c.size() || thresholdIndex > (unsigned int)m_thresholds_a.size()) {
255  ATH_MSG_ERROR("Threshold index \"" << thresholdIndex << "\" for single triggers is out of range.");
256  return StatusCode::FAILURE;
257  }
258 
259  if(thresholdIndex12 == 1000){
260  ATH_MSG_DEBUG("this is a needless counter for run2, the sample will be skipped!");
261  continue;
262  }
263 
264  // Emulate CFD samples[m_tZeroBin]*m_CFD_fraction
265  float ThrValue_a = 0;
266  float ThrValue_c = 0;
267  if(m_ThrVecSize12) {
268  ThrValue_a = m_thresholds_short_a[thresholdIndex12];
269  ThrValue_c = m_thresholds_short_c[thresholdIndex12];
270  } else {
271  ThrValue_a = m_thresholds_a[thresholdIndex];
272  ThrValue_c = m_thresholds_c[thresholdIndex];
273  }
274 
275  if((samples[m_tZeroBin]*m_CFD_fraction > ThrValue_c && detSide == -1) ||
276  (samples[m_tZeroBin]*m_CFD_fraction > ThrValue_a && detSide == 1))
277  {
278  // Add the trigger bit to the correct trigger word
279  if(detSide == -1)
280  { // EBC
281  single_triggers_C += (1<<m_cablestarts_c[thresholdIndex]);
282  triggersEBC++; // Increment the number of EBC triggers
283  }
284  else if (detSide == 1)
285  { // EBA
286  single_triggers_A += (1<<m_cablestarts_a[thresholdIndex]);
287  triggersEBA++; // Increment the number of EBA triggers.
288  }
289 
290  ATH_MSG_DEBUG( "Single input triggered on sample " << m_tZeroBin << " of " << numSamples << " bins.");
291  }
292  }
293 
294  // Cropping to 3 bits
295  if (triggersEBA>7) triggersEBA=7;
296  if (triggersEBC>7) triggersEBC=7;
297 
298  ATH_MSG_DEBUG( "Multis: "<< triggersEBA <<" and "<< triggersEBC );
299 
300  unsigned int cableWordA = single_triggers_A + (triggersEBA<<m_cablestart_a);
301  unsigned int cableWordC = single_triggers_C + (triggersEBC<<m_cablestart_c);
302 
303  // Record the CTP trigger word in StoreGate.
304  MbtsCTP *mbtsACTP = new MbtsCTP(cableWordA);
305  MbtsCTP *mbtsCCTP = new MbtsCTP(cableWordC);
306 
307  // Methods used in CTPsimulation are added for testing
308  ATH_MSG_DEBUG( " (in CTPSimulation) mbtsA cable word 0 is: 0x" << std::hex << std::setw( 8 ) << std::setfill( '0' ) << mbtsACTP->cableWord0() );
309  ATH_MSG_DEBUG( " (in CTPSimulation) Mult of mbtsA is: "<< static_cast<int>( (mbtsACTP->cableWord0() >> m_cablestart_a) & static_cast<unsigned int>( pow( 2, 3 ) - 1 ) ) );
310  ATH_MSG_DEBUG( " mbtsC cable " << mbtsCCTP->print() );
311  ATH_MSG_DEBUG( " (in CTPSimulation) mbtsC cable word 0 is: 0x" << std::hex << std::setw( 8 ) << std::setfill( '0' ) << mbtsCCTP->cableWord0() );
312  ATH_MSG_DEBUG( " (in CTPSimulation) Mult of mbtsC is: "<< static_cast<int>( (mbtsCCTP->cableWord0() >> m_cablestart_c) & static_cast<unsigned int>( pow( 2, 3 ) - 1 ) ) );
313 
314  ATH_CHECK(evtStore()->record(mbtsACTP, DEFAULT_MbtsACTPLocation, false));
315  ATH_CHECK(evtStore()->record(mbtsCCTP, DEFAULT_MbtsCCTPLocation, false));
316 
317  return StatusCode::SUCCESS;
318 }
319 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
LVL1::TrigT1MBTS::initialize
StatusCode initialize()
Definition: TrigT1MBTS.cxx:18
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TileTTL1
Definition: TileTTL1.h:26
TrigConf::L1Menu
L1 menu configuration.
Definition: L1Menu.h:28
LVL1::TrigT1MBTS::execute
StatusCode execute()
Definition: TrigT1MBTS.cxx:179
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TrigT1MBTS.h
TrigT1StoreGateKeys.h
python.PyAthena.module
module
Definition: PyAthena.py:131
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LVL1::MbtsCTP
MBTS input class to the CTP simulation.
Definition: MbtsCTP.h:27
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthAlgorithm
Definition: AthAlgorithm.h:47
TrigConf::name
Definition: HLTChainList.h:35
LVL1::TrigT1MBTS::TrigT1MBTS
TrigT1MBTS(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigT1MBTS.cxx:11
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LVL1::MbtsCTP::cableWord0
uint32_t cableWord0(void) const
Returns an unsigned integer trigger word containing two 3bit trigger multiplicities: backward and for...
Definition: MbtsCTP.h:37
MbtsCTP.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
python.XMLReader.l1menu
l1menu
Definition: XMLReader.py:73
L1Menu.h
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
TileContainer
Definition: TileContainer.h:38
LVL1::MbtsCTP::print
const std::string print() const
print object content in a human readable form to string
Definition: MbtsCTP.cxx:30
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Identifier
Definition: IdentifierFieldParser.cxx:14