ATLAS Offline Software
TrigCaloClusterMaker.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // ********************************************************************
6 //
7 // NAME: TrigCaloClusterMaker.cxx
8 // PACKAGE: Trigger/TrigAlgorithms/TrigCaloRec
9 //
10 // AUTHOR: C. Santamarina
11 // This is an Hlt algorithm that creates a cell container
12 // with calorimeter cells within an RoI. Afterwards a cluster
13 // container with the clusters made with those cells is
14 // created with the standard offline clustering algorithms.
15 //
16 // ********************************************************************
17 //
18 #include <sstream>
19 
20 #include "GaudiKernel/StatusCode.h"
21 
23 
29 
30 #include "TrigCaloClusterMaker.h"
31 
33 
35 
36 
38 // CONSTRUCTOR:
40 //
41 TrigCaloClusterMaker::TrigCaloClusterMaker(const std::string& name, ISvcLocator* pSvcLocator)
42  : AthReentrantAlgorithm(name, pSvcLocator)
43 {
44 }
45 
47 // INITIALIZE:
48 // The initialize method will create all the required algorithm objects
49 // Note that it is NOT NECESSARY to run the initialize of individual
50 // sub-algorithms. The framework takes care of it.
52 //
53 
55 {
56  ATH_MSG_DEBUG("in TrigCaloClusterMaker::initialize()" );
57 
58  if (!m_monTool.empty()) {
59  ATH_MSG_DEBUG("Retrieving monTool");
60  CHECK(m_monTool.retrieve());
61  } else {
62  ATH_MSG_INFO("No monTool configured => NO MONITOING");
63  }
64 
66  ATH_CHECK( m_mDecor_ncells.initialize());
67 
68  ATH_CHECK( m_clusterMakers.retrieve() );
69  ATH_CHECK( m_clusterCorrections.retrieve() );
70 
74  ATH_CHECK( m_avgMuKey.initialize() );
76 
77  for (ToolHandle<CaloClusterCollectionProcessor>& clproc : m_clusterMakers) {
78  // Set the CellsName property on the input tool (why isn't this done in
79  // python?)
80  AlgTool* algtool = dynamic_cast<AlgTool*> (clproc.get());
81  if (clproc->name().find("CaloTopoClusterMaker") != std::string::npos) {
82  if (!algtool) {
83  ATH_MSG_ERROR("Could not cast " << clproc->name() << " to an AlgTool!");
84  return StatusCode::FAILURE;
85  }
86  ATH_CHECK(algtool->setProperty(StringProperty("CellsName", m_inputCellsKey.key())));
87  }
88  if (clproc->name().find("trigslw") != std::string::npos)
89  m_isSW = true;
90  }
91 
92  for (ToolHandle<CaloClusterProcessor>& clcorr : m_clusterCorrections) {
93  ISetCaloCellContainerName* setter =
94  dynamic_cast<ISetCaloCellContainerName*> (clcorr.get());
95  if (setter)
97  }
98 
99  ATH_MSG_DEBUG("Initialization of TrigCaloClusterMaker completed successfully");
100 
101  return StatusCode::SUCCESS;
102 }
103 
104 
105 StatusCode TrigCaloClusterMaker::execute(const EventContext& ctx) const
106 {
107  // Monitoring initialization...
108  auto time_tot = Monitored::Timer("TIME_execute");
109  auto time_clusMaker = Monitored::Timer("TIME_ClustMaker");
110  auto time_clusCorr = Monitored::Timer("TIME_ClustCorr");
111 
112  // Start timer
113  time_tot.start();
114 
115  ATH_MSG_DEBUG("in TrigCaloClusterMaker::execute()" );
116  bool shouldMon = ((ctx.eventID().event_number() % 20)==0);
117 
118  // We now take care of the Cluster Making...
119  auto clusterContainer = SG::makeHandle (m_outputClustersKey, ctx);
120  ATH_MSG_VERBOSE(" Output Clusters : " << clusterContainer.name());
121  ATH_CHECK( clusterContainer.record (std::make_unique<xAOD::CaloClusterContainer>(), std::make_unique<xAOD::CaloClusterTrigAuxContainer> () ));
122 
123  xAOD::CaloClusterContainer* pCaloClusterContainer = clusterContainer.ptr();
124  ATH_MSG_VERBOSE(" created ClusterContainer at 0x" << std::hex << pCaloClusterContainer<< std::dec);
125 
126 
127  // monitored variables
128  auto mon_clusEt = Monitored::Collection("Et", *pCaloClusterContainer, &xAOD::CaloCluster::et );
129  auto mon_clusSignalState = Monitored::Collection("signalState", *pCaloClusterContainer, &xAOD::CaloCluster::signalState );
130  auto mon_clusSize = Monitored::Collection("clusterSize", *pCaloClusterContainer, &xAOD::CaloCluster::clusterSize );
131  std::vector<double> clus_phi;
132  std::vector<double> clus_eta;
133  std::vector<double> N_BAD_CELLS;
134  std::vector<double> ENG_FRAC_MAX;
135  std::vector<unsigned int> sizeVec;
136  clus_phi.reserve(300); clus_eta.reserve(300);
137  N_BAD_CELLS.reserve(300); ENG_FRAC_MAX.reserve(300);
138  sizeVec.reserve(300);
139  auto mon_clusPhi = Monitored::Collection("Phi", clus_phi); // phi and eta are virtual methods of CaloCluster
140  auto mon_clusEta = Monitored::Collection("Eta", clus_eta);
141  auto mon_badCells = Monitored::Collection("N_BAD_CELLS",N_BAD_CELLS );
142  auto mon_engFrac = Monitored::Collection("ENG_FRAC_MAX",N_BAD_CELLS );
143  auto mon_size = Monitored::Collection("size",sizeVec );
144  auto monmu = Monitored::Scalar("mu",-999.0);
145  auto mon_container_size = Monitored::Scalar("container_size", 0.);
146 
147 
148  // Looping over cluster maker tools...
149 
150  time_clusMaker.start();
151 
152  auto cells = SG::makeHandle(m_inputCellsKey, ctx);
153  ATH_MSG_VERBOSE(" Input Cells : " << cells.name() <<" of size " <<cells->size() );
154 
155  float mu(0.0);
157  if(eventInfoDecor.isPresent()) {
158  mu = eventInfoDecor(0);
159  }
160  unsigned int count_1thrsigma(0), count_2thrsigma(0);
161  if (m_monCells && shouldMon) {
163  const CaloNoise *noisep = *noiseHdl;
164  for (const auto cell : *cells ) {
165  float energy = cell->energy();
166  if ( energy <= 0.0 ) continue;
167  const CaloDetDescrElement* cdde = cell->caloDDE();
168  if (cdde->is_tile() ) continue;
169  float thr=noisep->getNoise(cdde->identifyHash(), cell->gain());
170  if ( energy <= thr ) continue;
171  if ( energy > m_1thr*thr ){
172  count_1thrsigma++;
173  if ( energy > m_2thr*thr )count_2thrsigma++;
174  } // if 1th
175  } // end of for over cells
176  } // end of if m_monCells
177 
178 
179 
180  for (const ToolHandle<CaloClusterCollectionProcessor>& clproc : m_clusterMakers) {
181 
182  ATH_CHECK(clproc->execute(ctx, pCaloClusterContainer));
183  ATH_MSG_VERBOSE("Executed tool " << clproc->name() );
184 
185  }
186  time_clusMaker.stop();
187 
188  ATH_MSG_VERBOSE("......pCaloClusterContainer size: " << pCaloClusterContainer->size());
189  //save raw state (uncalibrated)
190  for (xAOD::CaloCluster* cl : *pCaloClusterContainer)
191  {
192 #ifndef NDEBUG
193  ATH_MSG_VERBOSE("found cluster with state "
194  << cl->signalState() << ", calE: " << cl->calE() << ", calEta: " << cl->calEta() << ", calPhi: " << cl->calPhi() << " calM: " <<cl->calM());
195  ATH_MSG_VERBOSE(" Cluster Et = " << cl->et() );
196  ATH_MSG_VERBOSE(" Cluster eta = " << cl->eta() );
197  ATH_MSG_VERBOSE(" Cluster phi = " << cl->phi() );
198 #endif
199  cl->setRawE(cl->calE());
200  cl->setRawEta(cl->calEta());
201  cl->setRawPhi(cl->calPhi());
202  cl->setRawM(cl->calM());
203 #ifndef NDEBUG
204  ATH_MSG_VERBOSE(" before correction=>Cluster Et = " << cl->et() );
205  ATH_MSG_VERBOSE(" before correction=>Cluster eta = " << cl->eta() );
206  ATH_MSG_VERBOSE(" before correction=>Cluster phi = " << cl->phi() );
207 #endif
208  }
209 
210 
211 
212  // Looping over cluster correction tools...
213 
214  time_clusCorr.start();
215 
216  for (const ToolHandle<CaloClusterProcessor>& clcorr : m_clusterCorrections) {
217 
218  for (xAOD::CaloCluster* cl : *pCaloClusterContainer) {
219  if (!m_isSW ||
220  (std::abs(cl->eta0()) < 1.45 && clcorr->name().find("37") != std::string::npos) ||
221  (std::abs(cl->eta0()) >= 1.45 && clcorr->name().find("55") != std::string::npos) ) {
222  ATH_CHECK(clcorr->execute(ctx, cl) );
223  }
224  }
225  }
226  time_clusCorr.stop();
227 
228  // Decorator handle
230 
231  // fill monitored variables
232  for (xAOD::CaloCluster* cl : *pCaloClusterContainer) {
233 
234  const CaloClusterCellLink* num_cell_links = cl->getCellLinks();
235  if(! num_cell_links) {
236  sizeVec.push_back(0);
237  mDecor_ncells(*cl) = 0;
238  } else {
239  sizeVec.push_back(num_cell_links->size());
240  mDecor_ncells(*cl) = num_cell_links->size();
241  }
242  clus_phi.push_back(cl->phi());
243  clus_eta.push_back(cl->eta());
244  N_BAD_CELLS.push_back(cl->getMomentValue(xAOD::CaloCluster::N_BAD_CELLS));
245  ENG_FRAC_MAX.push_back(cl->getMomentValue(xAOD::CaloCluster::ENG_FRAC_MAX));
246  }
247 
248  // Finalize the clusters so cells are available in later steps
250  ATH_CHECK(CaloClusterStoreHelper::finalizeClusters (cellLinks, pCaloClusterContainer));
251 
252  ATH_MSG_DEBUG(" REGTEST: Produced a Cluster Container of Size= " << pCaloClusterContainer->size() );
253  if(!pCaloClusterContainer->empty()) {
254  ATH_MSG_DEBUG(" REGTEST: Last Cluster Et = " << (pCaloClusterContainer->back())->et() );
255  ATH_MSG_DEBUG(" REGTEST: Last Cluster eta = " << (pCaloClusterContainer->back())->eta() );
256  ATH_MSG_DEBUG(" REGTEST: Last Cluster phi = " << (pCaloClusterContainer->back())->phi() );
257  mon_container_size = pCaloClusterContainer->size(); // fill monitored variable
258  }
259  monmu=mu;
260  if ( shouldMon ){
261  auto moncount_1thrsigma = Monitored::Scalar("count_1thrsigma",-999.0);
262  auto moncount_2thrsigma = Monitored::Scalar("count_2thrsigma",-999.0);
263  auto mon_container_size_by_mu = Monitored::Scalar("container_size_by_mu", 0.);
264  auto moncount_1thrsigma_by_mu2 = Monitored::Scalar("count_1thrsigma_by_mu2",-999.0);
265  auto moncount_2thrsigma_by_mu2 = Monitored::Scalar("count_2thrsigma_by_mu2",-999.0);
266  moncount_1thrsigma = count_1thrsigma;
267  moncount_2thrsigma = count_2thrsigma;
268  if ( mu > 5 ){
269  mon_container_size_by_mu = pCaloClusterContainer->size()/mu; // fill monitored variable
270  float onemu2 = 1.0/(mu*mu);
271  moncount_1thrsigma_by_mu2 = count_1thrsigma*onemu2;
272  moncount_2thrsigma_by_mu2 = count_2thrsigma*onemu2;
273  }
274  auto monitorIt = Monitored::Group( m_monTool, time_tot, time_clusMaker, time_clusCorr, mon_container_size, mon_clusEt,
275  mon_clusPhi, mon_clusEta, mon_clusSignalState, mon_clusSize,
276  mon_badCells, mon_engFrac, mon_size, monmu, moncount_1thrsigma, moncount_2thrsigma, mon_container_size_by_mu, moncount_1thrsigma_by_mu2, moncount_2thrsigma_by_mu2);
277  }else{
278  auto monitorIt = Monitored::Group( m_monTool, time_tot, time_clusMaker, time_clusCorr, mon_container_size, mon_clusEt,
279  mon_clusPhi, mon_clusEta, mon_clusSignalState, mon_clusSize,
280  mon_badCells, mon_engFrac, mon_size, monmu );
281  }
282 
283  // Stop timer
284  time_tot.stop();
285 
286  return StatusCode::SUCCESS;
287 }
288 
289 
290 
TrigCaloClusterMaker::m_clusterMakers
ToolHandleArray< CaloClusterCollectionProcessor > m_clusterMakers
Definition: TrigCaloClusterMaker.h:57
RunTileCalibRec.cells
cells
Definition: RunTileCalibRec.py:271
CaloClusterProcessor.h
Base class for cluster processing tools called from CaloClusterMaker that operate on individual clust...
CaloClusterStoreHelper::finalizeClusters
static StatusCode finalizeClusters(SG::WriteHandle< CaloClusterCellLinkContainer > &h, xAOD::CaloClusterContainer *pClusterColl)
Finalize clusters (move CaloClusterCellLink to a separate container).
Definition: CaloClusterStoreHelper.cxx:64
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
CaloClusterTrigAuxContainer.h
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
TrigCaloClusterMaker::m_clusterCorrections
ToolHandleArray< CaloClusterProcessor > m_clusterCorrections
Definition: TrigCaloClusterMaker.h:59
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ISetCaloCellContainerName
Allow changing the name of the CaloCellContainer used by a tool.
Definition: ISetCaloCellContainerName.h:23
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TrigCaloClusterMaker::m_outputClustersKey
SG::WriteHandleKey< xAOD::CaloClusterContainer > m_outputClustersKey
Definition: TrigCaloClusterMaker.h:70
TrigCaloClusterMaker::m_mDecor_ncells
Gaudi::Property< SG::WriteDecorHandleKey< xAOD::CaloClusterContainer > > m_mDecor_ncells
Definition: TrigCaloClusterMaker.h:84
CaloDetDescrElement
This class groups all DetDescr information related to a CaloCell. Provides a generic interface for al...
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:66
TrigCaloClusterMaker::m_1thr
Gaudi::Property< float > m_1thr
Definition: TrigCaloClusterMaker.h:93
TrigCaloClusterMaker::m_inputCellsKey
SG::ReadHandleKey< CaloCellContainer > m_inputCellsKey
Definition: TrigCaloClusterMaker.h:65
SG::ReadDecorHandle::isPresent
bool isPresent() const
Is the referenced container present in SG?
xAOD::CaloCluster_v1::et
double et() const
Definition: CaloCluster_v1.h:856
ISetCaloCellContainerName.h
xAOD::CaloCluster_v1::signalState
State signalState() const
Get the current signal state.
Definition: CaloCluster_v1.h:633
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
xAOD::CaloCluster_v1::ENG_FRAC_MAX
@ ENG_FRAC_MAX
Energy fraction of hottest cell.
Definition: CaloCluster_v1.h:140
CaloNoise::getNoise
float getNoise(const IdentifierHash h, const int gain) const
Accessor by IdentifierHash and gain.
Definition: CaloNoise.h:34
TrigCaloClusterMaker::m_monCells
Gaudi::Property< bool > m_monCells
Definition: TrigCaloClusterMaker.h:92
TrigCaloClusterMaker::TrigCaloClusterMaker
TrigCaloClusterMaker(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TrigCaloClusterMaker.cxx:41
TrigCaloClusterMaker::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition: TrigCaloClusterMaker.cxx:105
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
TrigCaloClusterMaker::m_2thr
Gaudi::Property< float > m_2thr
Definition: TrigCaloClusterMaker.h:94
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
xAOD::CaloCluster_v1::clusterSize
ClusterSize clusterSize() const
Get cluster size.
Definition: CaloCluster_v1.cxx:364
TrigCaloClusterMaker::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: TrigCaloClusterMaker.h:82
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
SG::ReadDecorHandle
Handle class for reading a decoration on an object.
Definition: StoreGate/StoreGate/ReadDecorHandle.h:94
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
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
WriteDecorHandle.h
Handle class for adding a decoration to an object.
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
TrigCaloClusterMaker::m_avgMuKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_avgMuKey
Definition: TrigCaloClusterMaker.h:96
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
CaloDetDescrElement::is_tile
bool is_tile() const
cell belongs to Tile
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:442
CaloNoise
Definition: CaloNoise.h:16
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CaloDetDescrElement::identifyHash
IdentifierHash identifyHash() const override final
cell subcalo hash same as subcalo_hash(), but kept for backward compatibility
Definition: Calorimeter/CaloDetDescr/CaloDetDescr/CaloDetDescrElement.h:424
CaloClusterCollectionProcessor.h
Base class for cluster processing tools called from CaloClusterMaker.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloCellContainer.h
CaloClusterStoreHelper.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
TrigCaloClusterMaker::m_clusterCellLinkOutput
SG::WriteHandleKey< CaloClusterCellLinkContainer > m_clusterCellLinkOutput
Definition: TrigCaloClusterMaker.h:76
TrigCaloClusterMaker::m_isSW
bool m_isSW
Definition: TrigCaloClusterMaker.h:98
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
TrigCaloClusterMaker.h
TrigCaloClusterMaker::initialize
virtual StatusCode initialize() override
Definition: TrigCaloClusterMaker.cxx:54
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
xAOD::CaloCluster_v1::N_BAD_CELLS
@ N_BAD_CELLS
number of bad cells
Definition: CaloCluster_v1.h:149
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
TrigCaloClusterMaker::m_noiseCDOKey
SG::ReadCondHandleKey< CaloNoise > m_noiseCDOKey
Definition: TrigCaloClusterMaker.h:90
ISetCaloCellContainerName::setCaloCellContainerName
virtual StatusCode setCaloCellContainerName(const std::string &name)=0
Change the name of the CaloCellContainer used by this tool.