ATLAS Offline Software
LVL1TrigTowerRetriever.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "CLHEP/Units/SystemOfUnits.h"
8 
10 
11 namespace JiveXML {
12 
16  LVL1TrigTowerRetriever::LVL1TrigTowerRetriever(const std::string& type, const std::string& name, const IInterface* parent):
18  m_typeName("LVL1TriggerTower")
19  {
20 
21  declareInterface<IDataRetriever>(this);
22 
23  declareProperty("StoreGateKey", m_sgKey = "TriggerTowers", "Storegate key for Level-1 TriggerTowers");
24  declareProperty("SumEnergyThreshold", m_sumEnergyThr = 0, "TriggerTower only written out if sumEnergy above this");
25  }
26 
33  StatusCode LVL1TrigTowerRetriever::retrieve(ToolHandle<IFormatTool> &FormatTool) {
34 
35  //Retrieve trigger towers
36  const DataVector<LVL1::TriggerTower>* TTVector;
37 
38  if ( evtStore()->retrieve(TTVector,m_sgKey).isFailure() ) {
39  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << "No Level-1 Trigger Towers found in SG at "
40  << m_sgKey << endmsg;
41  return StatusCode::SUCCESS;
42  }
43 
44  //Get number of trigger towers
45  int numTrigTowers = TTVector->size();
46  int count = 0;
47  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << " Retrieving Level-1 Trigger Towers with size " << numTrigTowers << endmsg;
48 
49  DataVect phi; phi.reserve(numTrigTowers);
50  DataVect eta; eta.reserve(numTrigTowers);
51  DataVect emEnergyVec; emEnergyVec.reserve(numTrigTowers);
52  DataVect hadEnergyVec; hadEnergyVec.reserve(numTrigTowers);
53  DataVect sumEnergyVec; sumEnergyVec.reserve(numTrigTowers);
54  DataVect numADCVec; numADCVec.reserve(numTrigTowers);
55  DataVect emBCIDVec; emBCIDVec.reserve(numTrigTowers);
56  DataVect hadBCIDVec; hadBCIDVec.reserve(numTrigTowers);
57  DataVect isEMSaturated; isEMSaturated.reserve(numTrigTowers);
58  DataVect isHadSaturated; isHadSaturated.reserve(numTrigTowers);
59  DataVect emADCVec; emADCVec.reserve(numTrigTowers);
60  DataVect hadADCVec; hadADCVec.reserve(numTrigTowers);
61 
62  // Loop over all trigger towers and fill vectors
63  DataVector<LVL1::TriggerTower>::const_iterator trigTowerIter = TTVector->begin();
64  for ( trigTowerIter = TTVector->begin(); trigTowerIter < TTVector->end(); ++trigTowerIter ){
65 
66  // skip TTs with no energy
67  if ( (*trigTowerIter)->hadEnergy() == 0 && (*trigTowerIter)->emEnergy() == 0 ) continue;
68 
69  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) <<" Lvl1 TriggerTower No " << count++ << " with"
70  << " eta:"<<(*trigTowerIter)->eta() << ", phi:"<<(*trigTowerIter)->phi()
71  << ", EM energy:"<<(*trigTowerIter)->emEnergy()<<", Had Energy:"<<(*trigTowerIter)->hadEnergy() <<endmsg;
72 
73  //Be verbose
74  //if (msgLvl(MSG::DEBUG)){
75  // msg(MSG::DEBUG) << " Em ADC size:" << (*trigTowerIter)->emADC().size() << endmsg;
76  // msg(MSG::DEBUG) << " Had ADC size:" << (*trigTowerIter)->hadADC().size() << endmsg;
77  //}
78 
79  int sumEnergy = 0;
80  int emEnergy = 0;
81  int hadEnergy = 0;
82 
83  emEnergy = (*trigTowerIter)->emEnergy();
84  hadEnergy = (*trigTowerIter)->hadEnergy();
85  // propagate saturated towers
86  if ((emEnergy != 255) && (hadEnergy != 255)){ // are in GeV
87  sumEnergy = (*trigTowerIter)->emEnergy()+(*trigTowerIter)->hadEnergy();
88  } else {
89  sumEnergy = 255;
90  }
91 
92  // finally write out only TrigTowers with sumEnergy > sumEnergyThr (default: 0)
93  if ( sumEnergy > m_sumEnergyThr ){
94 
95  //Store energies
96  emEnergyVec.push_back( emEnergy );
97  hadEnergyVec.push_back( hadEnergy );
98  sumEnergyVec.push_back( sumEnergy );
99 
100  //Store eta and phi
101  eta.push_back(DataType((*trigTowerIter)->eta()));
102  phi.push_back(DataType((*trigTowerIter)->phi()));
103 
104  //Store the bunch crossing ID
105  emBCIDVec.push_back(DataType((*trigTowerIter)->emBCID()));
106  hadBCIDVec.push_back(DataType((*trigTowerIter)->hadBCID()));
107 
108  //Store saturation flag
109  isEMSaturated.push_back(DataType( ((*trigTowerIter)->isEMSaturated())? 1 : 0 ));
110  isHadSaturated.push_back(DataType( ((*trigTowerIter)->isHadSaturated())? 1 : 0 ));
111 
112  //Make sure number of hadronic and em ADC values match.
113  //Dummy data inserted if they don't.
114  if ((*trigTowerIter)->emADC().size() != (*trigTowerIter)->hadADC().size()){
115  if (msgLvl(MSG::WARNING)) msg(MSG::WARNING) << "Number of EmADC and HadADC values do not match"
116  << ",em:"<< (*trigTowerIter)->emADC().size()
117  << ",had:" << (*trigTowerIter)->hadADC().size() << endmsg;
118  numADCVec.push_back(DataType( 1 ));
119  emADCVec.push_back(DataType( 0 ));
120  hadADCVec.push_back(DataType( 0 ));
121  continue ; // next tower or exit
122  }
123 
124  // We have checked that em and had have same size
125  numADCVec.push_back(DataType( (*trigTowerIter)->emADC().size() ));
126 
127  // loop again over ADCs to write values out:
128  std::vector<int>::const_iterator emADCItr = ((*trigTowerIter)->emADC()).begin();
129  for (; emADCItr != ((*trigTowerIter)->emADC()).end(); ++emADCItr)
130  emADCVec.emplace_back( *emADCItr );
131 
132  std::vector<int>::const_iterator hadADCItr = ((*trigTowerIter)->hadADC()).begin();
133  for (; hadADCItr != ((*trigTowerIter)->hadADC()).end(); ++hadADCItr)
134  hadADCVec.emplace_back( *hadADCItr );
135  } // end sumEnergy > sumEnergyThr
136  }//end trigger tower iterator loop
137 
138  //Calculate multiple string (we have checked that EM and Had match)
139  std::string multiple = " multiple=\"0.\"";
140  if (emEnergyVec.size() != 0){ // avoid division by zero !
141  multiple = " multiple=\""+DataType(((float)emADCVec.size())/((float)emEnergyVec.size())).toString()+"\"";
142  }
143 
144  DataMap myDataMap;
145  const int nEntries = phi.size();
146  myDataMap["phi"] = std::move(phi);
147  myDataMap["eta"] = std::move(eta);
148  myDataMap["emEnergy"] = std::move(emEnergyVec);
149  myDataMap["hadEnergy"] = std::move(hadEnergyVec);
150  myDataMap["sumEnergy"] = std::move(sumEnergyVec);
151  myDataMap["emADC"+multiple] = std::move(emADCVec);
152  myDataMap["hadADC"+multiple] = std::move(hadADCVec);
153  myDataMap["numADC"] = std::move(numADCVec);
154  myDataMap["emBCID"] = std::move(emBCIDVec);
155  myDataMap["hadBCID"] = std::move(hadBCIDVec);
156  myDataMap["isEMSaturated"] = std::move(isEMSaturated);
157  myDataMap["isHadSaturated"] = std::move(isHadSaturated);
158 
159  if (msgLvl(MSG::DEBUG)) msg(MSG::DEBUG) << dataTypeName() << ": "<< nEntries << endmsg;
160 
161  //forward data to formating tool
162  return FormatTool->AddToEvent(dataTypeName(), m_sgKey, &myDataMap);
163  }
164 }
JiveXML::LVL1TrigTowerRetriever::m_sgKey
std::string m_sgKey
The storegate key for the TriggerTowers.
Definition: LVL1TrigTowerRetriever.h:36
JiveXML::LVL1TrigTowerRetriever::LVL1TrigTowerRetriever
LVL1TrigTowerRetriever(const std::string &type, const std::string &name, const IInterface *parent)
Standard Constructor.
Definition: LVL1TrigTowerRetriever.cxx:16
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
JiveXML::DataVect
std::vector< DataType > DataVect
Defines a map with a key and a vector of DataType objects e.g.
Definition: DataType.h:58
DataType
OFFLINE_FRAGMENTS_NAMESPACE::PointerType DataType
Definition: RoIBResultByteStreamTool.cxx:25
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
JiveXML::DataMap
std::map< std::string, DataVect > DataMap
Definition: DataType.h:59
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
JiveXML::LVL1TrigTowerRetriever::dataTypeName
virtual std::string dataTypeName() const
Return the name of the data type.
Definition: LVL1TrigTowerRetriever.h:28
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
LVL1TrigTowerRetriever.h
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
JiveXML::LVL1TrigTowerRetriever::m_sumEnergyThr
int m_sumEnergyThr
Definition: LVL1TrigTowerRetriever.h:37
test_pyathena.parent
parent
Definition: test_pyathena.py:15
DataVector< LVL1::TriggerTower >
JiveXML
This header is shared inbetween the C-style server thread and the C++ Athena ServerSvc.
Definition: BadLArRetriever.cxx:22
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
AthAlgTool
Definition: AthAlgTool.h:26
dqBeamSpot.nEntries
int nEntries
Definition: dqBeamSpot.py:73
JiveXML::LVL1TrigTowerRetriever::retrieve
virtual StatusCode retrieve(ToolHandle< IFormatTool > &FormatTool)
Retrieve all the data.
Definition: LVL1TrigTowerRetriever.cxx:33
TriggerTower.h
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.