ATLAS Offline Software
Loading...
Searching...
No Matches
LArDumpShapes.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5// $Id: LArDumpShapes.cxx,v 1.3 2007-12-03 10:02:56 wlampl Exp $
12
19#include "TFile.h"
20#include "TH1.h"
21#include <cstdio>
22#include <cmath>
23
24
30LArDumpShapes::LArDumpShapes (const std::string& name, ISvcLocator* svcloc)
31 : AthAlgorithm (name, svcloc),
32 m_first (true)
33{
34 // Set up properties.
35 declareProperty ("filename", m_filename = "shapes.root");
37}
38
39
44{
45 ATH_CHECK( m_cablingKey.initialize() );
46
47 return StatusCode::SUCCESS;
48}
49
50
55{
56 // Only do this for the first event.
57 if (!m_first)
58 return StatusCode::SUCCESS;
59
60 // Get the shapes from the detector store.
61 const ILArShape* dd_shape = nullptr;
62 CHECK( detStore()->retrieve (dd_shape) );
63
65 const LArOnOffIdMapping* cabling{*cablingHdl};
66 if(!cabling){
67 ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key() );
68 return StatusCode::FAILURE;
69 }
70 // Get the calorimeter identifier helper.
71 const CaloCell_ID* idHelper = nullptr;
72 ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
73 const LArEM_ID* em_id = idHelper->em_idHelper();
74
75 // Open the ROOT file.
76 TFile f (m_filename.c_str(), "RECREATE");
77
78 // Loop over all EM cells.
79 typedef std::vector<Identifier>::const_iterator It;
80 It beg = em_id->em_begin();
81 It end = em_id->em_end();
82 for (; beg != end; ++beg) {
83 // Check that this is a valid cell.
84 Identifier id = *beg;
85 if (!id.is_valid()) continue;
86 HWIdentifier chid = cabling->createSignalChannelID (id);
87 if (!chid.is_valid()) continue;
88
89 // Get the shape information for this cell.
90 ILArShape::ShapeRef_t shape = dd_shape->Shape(chid, m_gain, 0);
91 ILArShape::ShapeRef_t shapeder = dd_shape->ShapeDer(chid, m_gain, 0);
92
93 // Construct the name to use for the histogram.
94 char name[50];
95 std::sprintf(name, "shap%.9d_%.1d%.1d%.1d%.1d%.3d%.3d",
96 (int)chid.get_identifier32().get_compact(),
97 m_gain,
98 em_id->barrel_ec (id)+3,
99 em_id->sampling(id),
100 em_id->region(id),
101 em_id->phi(id),
102 em_id->eta(id));
103
104 // Create the histogram.
105 unsigned sz1 = shape.size();
106 unsigned sz2 = shapeder.size();
107 TH1* h1 = new TH1F (name, name, sz1 + sz2, 0, sz1 + sz2);
108
109 // Copy the data to the histogram.
110 for (unsigned int i=0; i < sz1; i++)
111 h1->SetBinContent (i+1, shape[i]);
112 for (unsigned int i=0; i < sz2; i++) {
113 double der = shapeder[i];
114 // ShapeDer uses 1e100 as a flag, which is not
115 // convertable to a float...
116 if (std::abs(der) > 1e10) der = 1e10;
117 h1->SetBinContent (i+sz1+1, der);
118 }
119
120 // Write the histogram to the ROOT file.
121 h1->Write();
122 delete h1;
123 }
124
125 // Close the ROOT file and remember that we did this.
126 f.Close();
127 m_first = false;
128 return StatusCode::SUCCESS;
129}
130
131
132
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Dump out shape information to a ROOT file.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition CaloCell_ID.h:63
LArVectorProxy ShapeRef_t
This class defines the interface for accessing Shape (Nsample variable, Dt = 25 ns fixed) @stereotype...
Definition ILArShape.h:26
virtual ShapeRef_t Shape(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
virtual ShapeRef_t ShapeDer(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
value_type get_compact() const
Get the compact id.
bool is_valid() const
Check if id is in a valid state.
Identifier32 get_identifier32() const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
StatusCode execute()
Standard Gaudi execute method.
std::string m_filename
JO property: The nmae of the ROOT file to create.
LArDumpShapes(const std::string &name, ISvcLocator *svcloc)
Standard Algorithm constructor.
bool m_first
True for the first event.
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
int m_gain
JO property: The desired gain.
StatusCode initialize()
Standard algorithm methods.
int region(const Identifier id) const
return region according to :
int eta(const Identifier id) const
return eta according to :
int phi(const Identifier id) const
return phi according to :
id_iterator em_begin() const
begin iterator over full set of EM Identifiers
int barrel_ec(const Identifier id) const
return barrel_ec according to :
int sampling(const Identifier id) const
return sampling according to :
id_iterator em_end() const
end iterator over full set of EM Identifiers
Helper class for LArEM offline identifiers.
Definition LArEM_ID.h:111
@ LARHIGHGAIN
Definition CaloGain.h:18