ATLAS Offline Software
TriggerTowerThinningAlg.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 // * Author: John Morris (john.morris@cern.ch) *
6 // * Queen Mary University of London *
7 // * *
8 
23 // TrigT1 common definitions
28 #include "GaudiKernel/ThreadLocalContext.h"
29 #include "CLHEP/Random/RandomEngine.h"
30 #include "CLHEP/Random/RandFlat.h"
31 
32 namespace DerivationFramework {
33 
34  TriggerTowerThinningAlg::TriggerTowerThinningAlg(const std::string& t, const std::string& n, const IInterface* p) :
35  base_class(t,n,p),
36  m_minCaloCellET(0.4),
37  m_minADC(32),
38  m_useRandom(false),
39  m_minRandom(0.03),
40  m_nEventsProcessed(0),
41  m_nEventsAllTriggerTowersKeptByRandom(0),
42  m_nTriggerTowersProcessed(0),
43  m_nTriggerTowersKept(0),
44  m_nTriggerTowersRejected(0)
45  {
46  declareProperty("MinCaloCellET",m_minCaloCellET);
47  declareProperty("MinADC",m_minADC);
48  declareProperty("UseRandom",m_useRandom);
49  declareProperty("MinRandom",m_minRandom);
50  }
51 
53  {
54  }
55 
57  ATH_MSG_INFO("L1Calo TriggerTowerThinningAlg::initialize()");
58 
61 
62  ATH_CHECK( m_rndmSvc.retrieve() );
63 
64  return StatusCode::SUCCESS;
65  }
66 
68  const EventContext& ctx = Gaudi::Hive::currentContext();
69 
70  // Create the mask to be used for thinning
71  std::vector<bool> mask;
72 
73  // Counters
74  unsigned long nKeep(0),nReject(0),nTotal(0);
76 
79 
80  mask.assign(tts->size(),false); // default: don't keep any clusters
81 
82  // Should we save the trigger tower or not???
83  // If this is calibration data, then yes - save the lot
84  // Randomly save all trigger towers m_minRandom % of the time.
85  //
86  // If this is collisions data then only save if:
87  // 1.) Any ADC value is greater than m_minADC OR
88  // 2.) The CaloCell ET is greater than m_minCaloCellET
89 
90  bool globalSaveMe(false);
91  // Random number save all
92  if(m_useRandom == true){
93  if(globalSaveMe == false){
94  ATHRNG::RNGWrapper* wrapper = m_rndmSvc->getEngine (this);
95  wrapper->setSeed (this->name(), ctx);
96  CLHEP::HepRandomEngine* engine = wrapper->getEngine (ctx);
97  if (CLHEP::RandFlat::shoot (engine) < m_minRandom) {
98  globalSaveMe = true;
100  }
101  }
102  }
103 
105  bool isDecorAvailable = caloCellETByLayerHandle.isAvailable();
106 
107  // Iterate over all trigger towers
108  for(auto tt : *tts){
109 
110  bool saveMe(false);
111  if(globalSaveMe == true){saveMe = true;}
112 
113  // Test for Calo ET
114  if(saveMe == false){
115  if (isDecorAvailable) {
116  const std::vector<float>& caloCellETByLayer = caloCellETByLayerHandle(*tt);
117 
118  float totalCaloCellET(0.);
119  for (float c : caloCellETByLayer) {
120  totalCaloCellET += c;
121  }
122  if (totalCaloCellET > m_minCaloCellET) {
123  saveMe = true;
124  }
125  }
126  }
127 
128 
129  // Test for ADC values
130  if (saveMe == false) {
131  const std::vector<uint16_t>& ttADC = tt->adc();
132  for (uint16_t i : ttADC) {
133  if ( i > m_minADC) {
134  saveMe = true;
135  break;
136  }
137  }
138  }
139 
140  // assign result to mask
141  mask[nTotal] = saveMe;
142 
143  ++nTotal;
144  } // End loop over trigger towers
145 
146 
147  tts.keep (mask);
148 
149  // Counters
150  m_nTriggerTowersProcessed += nTotal;
151  // FIXME: nKeep is always 0
152  m_nTriggerTowersKept += nKeep;
153  m_nTriggerTowersRejected += nReject;
154 
155  ATH_MSG_DEBUG(" L1Calo Trigger Tower Thinning statistics: keeping " << nKeep << " cells"
156  << " and rejecting " << nReject << " cells");
157 
158 
159  return StatusCode::SUCCESS;
160  }
161 
163 
164  ATH_MSG_INFO(
165  "==> finalize " << name() << "...\n"
166  << "***************************************************************\n"
167  << "Results of " << name() << " thinning algorithm:\n"
168  << "-------------");
169  ATH_MSG_INFO(" Number of processed events: " << m_nEventsProcessed);
170 
171  if(m_nTriggerTowersProcessed > 0) {
172  ATH_MSG_INFO(
173  " Average percent of Trigger Towers kept = "
174  << 100.0 * m_nTriggerTowersKept / (double)m_nTriggerTowersProcessed << " %");
175  }
176  if(m_useRandom == true && m_nEventsProcessed > 0){
177  ATH_MSG_INFO(
178  " Percentage of events where all Trigger Towers were kept (should be approx "<< 100.0*m_minRandom << ") = "
180  }
181 
182 
183  return StatusCode::SUCCESS;
184  }
185 
186 } // namespace
ATHRNG::RNGWrapper::setSeed
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition: RNGWrapper.h:169
DerivationFramework::TriggerTowerThinningAlg::m_rndmSvc
ServiceHandle< IAthRNGSvc > m_rndmSvc
Definition: TriggerTowerThinningAlg.h:76
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
DerivationFramework::TriggerTowerThinningAlg::m_minCaloCellET
double m_minCaloCellET
Definition: TriggerTowerThinningAlg.h:62
DerivationFramework::TriggerTowerThinningAlg::m_nEventsProcessed
std::atomic< unsigned long > m_nEventsProcessed
Definition: TriggerTowerThinningAlg.h:68
ThinningHandle.h
Handle for requesting thinning for a data object.
DerivationFramework::TriggerTowerThinningAlg::m_nEventsAllTriggerTowersKeptByRandom
std::atomic< unsigned long > m_nEventsAllTriggerTowersKeptByRandom
Definition: TriggerTowerThinningAlg.h:69
DerivationFramework::TriggerTowerThinningAlg::~TriggerTowerThinningAlg
virtual ~TriggerTowerThinningAlg()
Definition: TriggerTowerThinningAlg.cxx:52
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DerivationFramework::TriggerTowerThinningAlg::m_minRandom
double m_minRandom
Definition: TriggerTowerThinningAlg.h:65
DerivationFramework::TriggerTowerThinningAlg::m_nTriggerTowersRejected
std::atomic< unsigned long > m_nTriggerTowersRejected
Definition: TriggerTowerThinningAlg.h:72
DerivationFramework::TriggerTowerThinningAlg::m_useRandom
bool m_useRandom
Definition: TriggerTowerThinningAlg.h:64
DerivationFramework::TriggerTowerThinningAlg::m_minADC
int m_minADC
Definition: TriggerTowerThinningAlg.h:63
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
SG::ThinningHandle
Handle for requesting thinning for a data object.
Definition: ThinningHandle.h:84
TriggerTowerThinningAlg.h
DerivationFramework::TriggerTowerThinningAlg::m_nTriggerTowersKept
std::atomic< unsigned long > m_nTriggerTowersKept
Definition: TriggerTowerThinningAlg.h:71
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
DerivationFramework::TriggerTowerThinningAlg::initialize
virtual StatusCode initialize() override
Definition: TriggerTowerThinningAlg.cxx:56
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
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
DerivationFramework::TriggerTowerThinningAlg::m_nTriggerTowersProcessed
std::atomic< unsigned long > m_nTriggerTowersProcessed
Definition: TriggerTowerThinningAlg.h:70
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DerivationFramework
THE reconstruction tool.
Definition: ParticleSortingAlg.h:24
DerivationFramework::TriggerTowerThinningAlg::m_streamName
StringProperty m_streamName
Definition: TriggerTowerThinningAlg.h:53
DerivationFramework::TriggerTowerThinningAlg::TriggerTowerThinningAlg
TriggerTowerThinningAlg(const std::string &t, const std::string &n, const IInterface *p)
Definition: TriggerTowerThinningAlg.cxx:34
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ATHRNG::RNGWrapper
A wrapper class for event-slot-local random engines.
Definition: RNGWrapper.h:56
TrigT1CaloDefs.h
ATHRNG::RNGWrapper::getEngine
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition: RNGWrapper.h:134
RNGWrapper.h
DerivationFramework::TriggerTowerThinningAlg::m_caloCellETByLayerKey
SG::ReadDecorHandleKey< xAOD::TriggerTowerContainer > m_caloCellETByLayerKey
Definition: TriggerTowerThinningAlg.h:59
DerivationFramework::TriggerTowerThinningAlg::doThinning
virtual StatusCode doThinning() const override
Definition: TriggerTowerThinningAlg.cxx:67
DerivationFramework::TriggerTowerThinningAlg::m_triggerTowerLocation
SG::ThinningHandleKey< xAOD::TriggerTowerContainer > m_triggerTowerLocation
Definition: TriggerTowerThinningAlg.h:56
ReadDecorHandle.h
Handle class for reading a decoration on an object.
SG::AllowEmpty
@ AllowEmpty
Definition: StoreGate/StoreGate/VarHandleKey.h:30
SG::ReadDecorHandle::isAvailable
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
TileDCSDataPlotter.tt
tt
Definition: TileDCSDataPlotter.py:874
python.compressB64.c
def c
Definition: compressB64.py:93
DerivationFramework::TriggerTowerThinningAlg::finalize
virtual StatusCode finalize() override
Definition: TriggerTowerThinningAlg.cxx:162