ATLAS Offline Software
L1CorrelationAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "L1CorrelationAlg.h"
6 #include "CTPfragment/CTPfragment.h"
7 #include "CTPfragment/CTPdataformat.h"
8 
12 
13 L1CorrelationAlg::L1CorrelationAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
14 
16 
17  ATH_CHECK(m_robDataProviderSvc.retrieve());
18  ATH_CHECK(m_trigCompositeKey.initialize());
20  ATH_CHECK(m_passKey.initialize());
21  ATH_CHECK(m_l1AKey.initialize());
22  ATH_CHECK(m_otherTypeKey.initialize());
23  ATH_CHECK(m_beforeAfterKey.initialize());
24  ATH_CHECK(m_monTool.retrieve());
25 
26  return StatusCode::SUCCESS;
27 }
28 
30 
31  //get L1 menu and initialise bitMasks based on l1 em/j/mu triggers
33  ATH_CHECK(rh_l1Menu.isValid());
34  std::vector<int> ctpids_ele;
35  std::vector<int> ctpids_mu;
36  std::vector<int> ctpids_jets;
37  std::vector<int> ctpids;
38  for(const TrigConf::L1Item& item : *rh_l1Menu){
39  for(uint nl1=0; nl1<m_l1itemlist.size(); nl1++){
40  if(m_l1itemlist[nl1].compare(item.name()) == 0 ){
41  ATH_MSG_DEBUG("L1CorrAlgInit: Configured to use item:" <<item.name().c_str()<< " CTPID:"<<item.ctpId());
42  ctpids.push_back( item.ctpId() );
43  if( m_l1itemlist[nl1].find( "L1_EM" ) != std::string::npos ){
44  ctpids_ele.push_back( item.ctpId() );
45  }
46  if( m_l1itemlist[nl1].find( "L1_MU" ) != std::string::npos ){
47  ctpids_mu.push_back( item.ctpId() );
48  }
49  if(( m_l1itemlist[nl1].find( "L1_J") != std::string::npos ) || ( m_l1itemlist[nl1].find( "L1_jJ" ) != std::string::npos)){
50  ctpids_jets.push_back( item.ctpId() );
51  }
52  }
53  }
54  }
55 
56  // init with 0
57  m_bitmasks.clear();
58  m_bitmasks_ele.clear();
59  m_bitmasks_mu.clear();
60  m_bitmasks_jets.clear();
61  for(int n=0; n<16 ; n++){
62  uint32_t tmpword=0;
63  m_bitmasks.push_back(tmpword);
64  m_bitmasks_ele.push_back(tmpword);
65  m_bitmasks_mu.push_back(tmpword);
66  m_bitmasks_jets.push_back(tmpword);
67  }
68 
69  //all ctpids
70  for(unsigned int n=0; n<ctpids.size() ; n++){
71  // check in which word it belongs
72  int cycle = ctpids[n] / 32;
73  int pos = ctpids[n] % 32;
74 
75  uint32_t currentmask = m_bitmasks[cycle];
76  uint32_t tmpmask = 1;
77  // shift this pos positions to left
78  tmpmask = tmpmask << (pos);
79 
80  // OR this with the existing mask
81  m_bitmasks[cycle] = tmpmask | currentmask;
82  }
83 
84  //electrons
85  for(unsigned int n=0; n<ctpids_ele.size() ; n++){
86  // check in which word it belongs
87  int cycle = ctpids_ele[n] / 32;
88  int pos = ctpids_ele[n] % 32;
89 
90  uint32_t currentmask = m_bitmasks_ele[cycle];
91  uint32_t tmpmask = 1;
92  // shift this pos positions to left
93  tmpmask = tmpmask << (pos);
94 
95  // OR this with the existing mask
96  m_bitmasks_ele[cycle] = tmpmask | currentmask;
97  }
98 
99  //muons
100  for(unsigned int n=0; n<ctpids_mu.size() ; n++){
101  // check in which word it belongs
102  int cycle = ctpids_mu[n] / 32;
103  int pos = ctpids_mu[n] % 32;
104 
105  uint32_t currentmask = m_bitmasks_mu[cycle];
106  uint32_t tmpmask = 1;
107  // shift this pos positions to left
108  tmpmask = tmpmask << (pos);
109 
110  // OR this with the existing mask
111  m_bitmasks_mu[cycle] = tmpmask | currentmask;
112  }
113 
114  //jets
115  for(unsigned int n=0; n<ctpids_jets.size() ; n++){
116  // check in which word it belongs
117  int cycle = ctpids_jets[n] / 32;
118  int pos = ctpids_jets[n] % 32;
119 
120  uint32_t currentmask = m_bitmasks_jets[cycle];
121  uint32_t tmpmask = 1;
122  // shift this pos positions to left
123  tmpmask = tmpmask << (pos);
124 
125  // OR this with the existing mask
126  m_bitmasks_jets[cycle] = tmpmask | currentmask;
127  }
128 
129  return StatusCode::SUCCESS;
130 }
131 
132 
133 StatusCode L1CorrelationAlg::execute(const EventContext& ctx) const {
134 
135 
136  //TrigComposite Container to record
138  ATH_CHECK(wh_trigComposite.record(std::make_unique<xAOD::TrigCompositeContainer>(), std::make_unique<xAOD::TrigCompositeAuxContainer>()));
139  auto trigCompCont = wh_trigComposite.ptr();
140 
145 
146  //CTP ROB
147  std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*> robFragments;
148  std::vector<uint32_t> roblist;
149  // magic number!
150  roblist.push_back(0x770000);
151  m_robDataProviderSvc->addROBData(ctx, roblist);
152  m_robDataProviderSvc->getROBData(ctx, roblist, robFragments);
153  if (msgLvl(MSG::DEBUG)) {
154  std::ostringstream os;
155  for(auto rob : roblist){
156  os << std::hex<<rob;
157  }
158  ATH_MSG_DEBUG(roblist.size() << "/" << robFragments.size()
159  << " ROBs requested/retrieved:" << os.str());
160  }
161  if (robFragments.size()<1){
162  ATH_MSG_DEBUG("Could not retrieve ROB!");
163  return StatusCode::SUCCESS;
164  }
165  const eformat::ROBFragment<const uint32_t*>* rbf = robFragments[0];
166 
167  // this is the l1a accept position
169 
170  std::vector<uint32_t> tbp;
171  bool firedbc[3] = {0,0,0};
172  bool firedbc_ele[3] = {0,0,0};
173  bool firedbc_mu[3] = {0,0,0};
174  bool firedbc_jet[3] = {0,0,0};
175 
176  // if currentBCincl flag is toggled don't ask for any specific trigger in the central BCID
177  if(m_currentBCincl){
178  firedbc[1]=1;
179  firedbc_ele[1]=1;
180  firedbc_mu[1]=1;
181  firedbc_jet[1]=1;
182  }
183 
184  //check BC-1 to BC+1
185  unsigned int ibc=0;
186  for(unsigned int bc=l1a-1; bc<l1a+2; bc++) {
187  tbp = CTPfragment::triggerDecisionBeforePrescales(rbf,bc);
188  unsigned ntbpwords(tbp.size());
189  for(unsigned iw=0; iw<ntbpwords; iw++ ) {
190  uint32_t tmpand = tbp[iw] & m_bitmasks[iw];
191  uint32_t tmpand_ele = tbp[iw] & m_bitmasks_ele[iw];
192  uint32_t tmpand_mu = tbp[iw] & m_bitmasks_mu[iw];
193  uint32_t tmpand_jet = tbp[iw] & m_bitmasks_jets[iw];
194  firedbc[ibc] = firedbc[ibc] || (tmpand > 0);
195  firedbc_ele[ibc] = firedbc_ele[ibc] || (tmpand_ele > 0);
196  firedbc_mu[ibc] = firedbc_mu[ibc] || (tmpand_mu > 0);
197  firedbc_jet[ibc] = firedbc_jet[ibc] || (tmpand_jet > 0);
198  }
199  ibc++;
200  }
201 
202  int l1a_type = 0;
203  int beforeafterflag=0;
204  int other_type=0;
205  int isPassed = 0;
206  if ((firedbc[0] && firedbc[1]) || (firedbc[1] && firedbc[2])){
207 
208  ATH_MSG_DEBUG("Event fired bc[0]: "<<firedbc[0]<<", bc[1]: "<<firedbc[1]<<", bc[2]: "<<firedbc[2]);
209  isPassed = 1;
210 
211  if(firedbc_ele[1]) l1a_type = 1;
212  if(firedbc_mu[1]) l1a_type = 2;
213  if(firedbc_jet[1]) l1a_type = 3;
214  if(firedbc_ele[1] && firedbc_mu[1]) l1a_type = 4;
215  if(firedbc_ele[1] && firedbc_jet[1]) l1a_type = 5;
216  if(firedbc_mu[1] && firedbc_jet[1]) l1a_type = 6;
217  if(firedbc_ele[1] && firedbc_mu[1] && firedbc_jet[1]) l1a_type = 7;
218 
219  if((firedbc[0] && firedbc[1])){
220  beforeafterflag = -1;
221 
222  if(firedbc_ele[0]) other_type = 1;
223  if(firedbc_mu[0]) other_type = 2;
224  if(firedbc_jet[0]) other_type = 3;
225  if(firedbc_ele[0] && firedbc_mu[0]) other_type = 4;
226  if(firedbc_ele[0] && firedbc_jet[0]) other_type = 5;
227  if(firedbc_mu[0] && firedbc_jet[0]) other_type = 6;
228  if(firedbc_ele[0] && firedbc_mu[0] && firedbc_jet[0]) other_type = 7;
229 
230  }
231  else if((firedbc[1] && firedbc[2])){
232  beforeafterflag = 1;
233  if(firedbc_ele[2]) other_type = 1;
234  if(firedbc_mu[2]) other_type = 2;
235  if(firedbc_jet[2]) other_type = 3;
236  if(firedbc_ele[2] && firedbc_mu[2]) other_type = 4;
237  if(firedbc_ele[2] && firedbc_jet[2]) other_type = 5;
238  if(firedbc_mu[2] && firedbc_jet[2]) other_type = 6;
239  if(firedbc_ele[2] && firedbc_mu[2] && firedbc_jet[2]) other_type = 7;
240 
241  }
242  if ((firedbc[0] && firedbc[1]) && (firedbc[1] && firedbc[2])){
243  beforeafterflag = 2;
244 
245  }
246 
247  auto trigComp = new xAOD::TrigComposite();
248  trigCompCont->push_back(trigComp);
249  trigComp->setName("mistimemon_L1Dec");
250  trigCompL1A(*trigComp) = l1a_type;
251  trigCompOther(*trigComp) = other_type;
252  trigCompBeforeAfter(*trigComp) = beforeafterflag;
253  trigCompPass(*trigComp) = isPassed;
254  }
255 
256  //setup monitoring
257  auto mon_l1a = Monitored::Scalar<int>("l1Accept", l1a_type);
258  auto mon_otherType = Monitored::Scalar<int>("otherType", other_type);
259  auto mon_beforeAfter = Monitored::Scalar<int>("BeforeAfterFlag", beforeafterflag);
260  auto monitorIt = Monitored::Group(m_monTool, mon_l1a, mon_otherType, mon_beforeAfter);
261 
262  return StatusCode::SUCCESS;
263 
264 }
L1CorrelationAlg::L1CorrelationAlg
L1CorrelationAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: L1CorrelationAlg.cxx:13
Amg::compare
std::pair< int, int > compare(const AmgSymMatrix(N) &m1, const AmgSymMatrix(N) &m2, double precision=1e-9, bool relative=false)
compare two matrices, returns the indices of the first element that fails the condition,...
Definition: EventPrimitivesHelpers.h:109
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
L1CorrelationAlg.h
xAOD::TrigComposite
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:16
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
L1CorrelationAlg::m_bitmasks_mu
std::vector< uint32_t > m_bitmasks_mu
Definition: L1CorrelationAlg.h:38
cycle
double cycle(double a, double b)
Definition: SiHitCollectionCnv_p2.cxx:38
L1CorrelationAlg::initialize
virtual StatusCode initialize() override
Definition: L1CorrelationAlg.cxx:15
AthCommonMsg< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
L1CorrelationAlg::m_l1AKey
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_l1AKey
Definition: L1CorrelationAlg.h:26
L1CorrelationAlg::m_bitmasks
std::vector< uint32_t > m_bitmasks
Definition: L1CorrelationAlg.h:36
L1CorrelationAlg::m_currentBCincl
Gaudi::Property< bool > m_currentBCincl
Definition: L1CorrelationAlg.h:32
L1CorrelationAlg::m_beforeAfterKey
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_beforeAfterKey
Definition: L1CorrelationAlg.h:28
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
L1CorrelationAlg::m_robDataProviderSvc
ServiceHandle< IROBDataProviderSvc > m_robDataProviderSvc
Definition: L1CorrelationAlg.h:24
L1CorrelationAlg::m_bitmasks_jets
std::vector< uint32_t > m_bitmasks_jets
Definition: L1CorrelationAlg.h:39
uint
unsigned int uint
Definition: LArOFPhaseFill.cxx:20
eformat::ROBFragment< const uint32_t * >
L1CorrelationAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: L1CorrelationAlg.h:31
beamspotman.n
n
Definition: beamspotman.py:731
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
L1CorrelationAlg::m_passKey
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_passKey
Definition: L1CorrelationAlg.h:29
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:100
WriteDecorHandle.h
Handle class for adding a decoration to an object.
TrigConf::L1Item
L1 threshold configuration.
Definition: L1Item.h:18
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
TrigCompositeAuxContainer.h
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
L1CorrelationAlg::m_bitmasks_ele
std::vector< uint32_t > m_bitmasks_ele
Definition: L1CorrelationAlg.h:37
L1CorrelationAlg::m_otherTypeKey
SG::WriteDecorHandleKey< xAOD::TrigCompositeContainer > m_otherTypeKey
Definition: L1CorrelationAlg.h:27
L1CorrelationAlg::m_l1itemlist
Gaudi::Property< std::vector< std::string > > m_l1itemlist
Definition: L1CorrelationAlg.h:33
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
item
Definition: ItemListSvc.h:43
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
python.CTPfragment.lvl1AcceptBunch
def lvl1AcceptBunch(rob)
Definition: CTPfragment.py:150
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
L1CorrelationAlg::start
virtual StatusCode start() override
Definition: L1CorrelationAlg.cxx:29
DEBUG
#define DEBUG
Definition: page_access.h:11
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
L1CorrelationAlg::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: L1CorrelationAlg.cxx:133
L1CorrelationAlg::m_l1MenuKey
SG::ReadHandleKey< TrigConf::L1Menu > m_l1MenuKey
Definition: L1CorrelationAlg.h:30
L1CorrelationAlg::m_trigCompositeKey
SG::WriteHandleKey< xAOD::TrigCompositeContainer > m_trigCompositeKey
Definition: L1CorrelationAlg.h:25