ATLAS Offline Software
Loading...
Searching...
No Matches
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
21
23// TrigT1 common definitions
28#include "GaudiKernel/ThreadLocalContext.h"
29#include "CLHEP/Random/RandomEngine.h"
30#include "CLHEP/Random/RandFlat.h"
31
32namespace 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),
45 {
46 declareProperty("MinCaloCellET",m_minCaloCellET);
47 declareProperty("MinADC",m_minADC);
48 declareProperty("UseRandom",m_useRandom);
49 declareProperty("MinRandom",m_minRandom);
50 }
51
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
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
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
173 " Average percent of Trigger Towers kept = "
174 << 100.0 * m_nTriggerTowersKept / (double)m_nTriggerTowersProcessed << " %");
175 }
176 if(m_useRandom == true && m_nEventsProcessed > 0){
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
Handle class for reading a decoration on an object.
Handle for requesting thinning for a data object.
A wrapper class for event-slot-local random engines.
Definition RNGWrapper.h:56
void setSeed(const std::string &algName, const EventContext &ctx)
Set the random seed using a string (e.g.
Definition RNGWrapper.h:169
CLHEP::HepRandomEngine * getEngine(const EventContext &ctx) const
Retrieve the random engine corresponding to the provided EventContext.
Definition RNGWrapper.h:134
std::atomic< unsigned long > m_nEventsAllTriggerTowersKeptByRandom
SG::ReadDecorHandleKey< xAOD::TriggerTowerContainer > m_caloCellETByLayerKey
TriggerTowerThinningAlg(const std::string &t, const std::string &n, const IInterface *p)
SG::ThinningHandleKey< xAOD::TriggerTowerContainer > m_triggerTowerLocation
Handle class for reading a decoration on an object.
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Handle for requesting thinning for a data object.
THE reconstruction tool.