ATLAS Offline Software
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 $
14 #include "LArElecCalib/ILArShape.h"
17 #include "StoreGate/StoreGateSvc.h"
19 #include "TFile.h"
20 #include "TH1.h"
21 #include <cstdio>
22 #include <cmath>
23 
24 
30 LArDumpShapes::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 {
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 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArEM_Base_ID::phi
int phi(const Identifier id) const
return phi according to :
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
LArDumpShapes::LArDumpShapes
LArDumpShapes(const std::string &name, ISvcLocator *svcloc)
Standard Algorithm constructor.
Definition: LArDumpShapes.cxx:30
fitman.sz2
sz2
Definition: fitman.py:543
LArDumpShapes::m_filename
std::string m_filename
JO property: The nmae of the ROOT file to create.
Definition: LArDumpShapes.h:70
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
CaloCell_ID::em_idHelper
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition: CaloCell_ID.h:63
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
ILArShape::ShapeDer
virtual ShapeRef_t ShapeDer(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0
LArDumpShapes::m_gain
int m_gain
JO property: The desired gain.
Definition: LArDumpShapes.h:73
LArEM_Base_ID::region
int region(const Identifier id) const
return region according to :
LArEM_Base_ID::sampling
int sampling(const Identifier id) const
return sampling according to :
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
read_hist_ntuple.h1
h1
Definition: read_hist_ntuple.py:21
HWIdentifier
Definition: HWIdentifier.h:13
Identifier::is_valid
bool is_valid() const
Check if id is in a valid state.
LArEM_Base_ID::eta
int eta(const Identifier id) const
return eta according to :
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
CaloCell_ID.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
LArDumpShapes::initialize
StatusCode initialize()
Standard algorithm methods.
Definition: LArDumpShapes.cxx:43
LArDumpShapes::execute
StatusCode execute()
Standard Gaudi execute method.
Definition: LArDumpShapes.cxx:54
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Identifier32::get_compact
value_type get_compact(void) const
Get the compact id.
Definition: Identifier32.h:171
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
LArDumpShapes::m_first
bool m_first
True for the first event.
Definition: LArDumpShapes.h:76
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
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
AthAlgorithm
Definition: AthAlgorithm.h:47
ILArShape.h
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
errorcheck.h
Helpers for checking error return status codes and reporting errors.
LArEM_Base_ID::barrel_ec
int barrel_ec(const Identifier id) const
return barrel_ec according to :
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
CaloGain::LARHIGHGAIN
@ LARHIGHGAIN
Definition: CaloGain.h:18
LArEM_Base_ID::em_end
id_iterator em_end(void) const
end iterator over full set of EM Identifiers
LArDumpShapes.h
Dump out shape information to a ROOT file.
LArEM_Base_ID::em_begin
id_iterator em_begin(void) const
begin iterator over full set of EM Identifiers
TH1
Definition: rootspy.cxx:268
LArDumpShapes::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: LArDumpShapes.h:67
LArEM_ID
Helper class for LArEM offline identifiers.
Definition: LArEM_ID.h:118
python.TrigEgammaMonitorHelper.TH1F
def TH1F(name, title, nxbins, bins_par2, bins_par3=None, path='', **kwargs)
Definition: TrigEgammaMonitorHelper.py:24
Identifier::get_identifier32
Identifier32 get_identifier32(void) const
Get the 32-bit version Identifier, will be invalid if >32 bits needed.
CaloGain.h
ILArShape
Definition: ILArShape.h:13
StoreGateSvc.h
LArVectorProxy
Proxy for accessing a range of float values like a vector.
Definition: LArVectorProxy.h:38
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20
ILArShape::Shape
virtual ShapeRef_t Shape(const HWIdentifier &id, int gain, int tbin=0, int mode=0) const =0