ATLAS Offline Software
Loading...
Searching...
No Matches
LArShapeCompleteMakerAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
10#include "GaudiKernel/MsgStream.h"
19
20using namespace LArSamples;
21
22LArShapeCompleteMakerAlg::LArShapeCompleteMakerAlg(const std::string & name, ISvcLocator * pSvcLocator) :
23 AthAlgorithm(name, pSvcLocator),
24 m_template(nullptr),
25 m_dumperTool("LArShapeDumperTool")
26{
27 //declareProperty("NSamples", m_nSamples = 5);
28 //declareProperty("NPhases", m_nPhases = 17);
29 //declareProperty("IPhase", m_iPhase = 8);
30 //declareProperty("ShapeErrorFileName", m_shapeErrorFileName);
31 //declareProperty("OutputFileName", m_outputFileName);
32 //declareProperty("OutputTemplateFileName", m_outputTemplateFileName);
33 //declareProperty("StoreGateKey", m_sgKey = "LArResiduals");
34 //declareProperty("MinNPulses", m_minNPulses = 0);
35 //declareProperty("GroupingType", m_groupingType = "ExtendedSubDetector");
36}
37
38
42
43
45{
46
47 ATH_CHECK(detStore()->retrieve(m_onlineHelper, "LArOnlineID"));
48
49 ATH_CHECK( m_onOffMapKey.initialize() );
50
51 //return StatusCode::SUCCESS;
52 return AthAlgorithm::initialize();
53}
54
55
57{
58 if (m_template) return StatusCode::SUCCESS;
59 m_template = new DataStore();
60
62
63 if (lsc->setGroupingType(m_groupingType, msg()).isFailure() || lsc->initialize().isFailure()) {
64 ATH_MSG_ERROR("Unable to initialize LArShapeComplete");
65 delete lsc;
66 return StatusCode::FAILURE;
67 };
68
69 TreeShapeErrorGetter* errorGetter = new TreeShapeErrorGetter((std::string) m_shapeErrorFileName);
70
72
73 for (unsigned int k = 0; k < LArSamples::Definitions::nChannels; k++) {
74
75 HWIdentifier channelID = m_onlineHelper->channel_Id((IdentifierHash)k);
76 const Identifier id = onOffMap->cnvToIdentifier(channelID);
77 if (id.get_compact() == 0xffffffff) {
78 ATH_MSG_WARNING( "Skipping invalid hash = " << k << "." );
79 continue;
80 }
81
82 CellInfo* info = m_dumperTool->makeCellInfo(channelID, id);
83 if (!info) {
84 ATH_MSG_ERROR("Problem making cell info for hash = " << k << ", terminating...");
85 delete errorGetter;
86 return StatusCode::FAILURE;
87 }
88
89 HistoryContainer* histCont = m_template->makeNewHistory(k, info);
90 std::vector<const EventData*> events;
91 for (unsigned int g = 0; g < 3; g++) {
92 DataContainer* data = new DataContainer((CaloGain::CaloGain)g, std::vector<short>(), 0, 0, 0, -1, std::vector<float>());
93 events.push_back(new EventData(-1,-1,-1,-1));
94 histCont->add(data);
95 }
96 History* history = new History(*histCont, events, k, errorGetter);
97
98 for (unsigned int g = 0; g < 3; g++) {
100 const LArSamples::ShapeErrorData* sed = nullptr;
101 if (history) sed = history->shapeErrorData(gain, LArSamples::BestShapeError);
102
103 // The containers
104 std::vector<std::vector<float> > deltaVal, deltaDer;
105
106 // Fill them with 0's to start with
107 std::vector<float> phaseVect(m_nSamples);
108 for (unsigned int j = 0; j < m_nSamples; j++) phaseVect[j] = 0;
109 for (unsigned int i = 0; i < m_nPhases; i++) {
110 deltaVal.push_back(phaseVect);
111 deltaDer.push_back(phaseVect);
112 }
113
114 if (sed && sed->n() > m_minNPulses) {
115 ATH_MSG_DEBUG("--> Setting channel " << k << ", id = " << channelID << ", gain = " << gain << ", size = "
116 << deltaVal.size() << " " << deltaDer.size());
117 for (unsigned int i = 0; i < m_nSamples; i++) {
118 deltaVal[m_iPhase][i] = sed->xi()(i);
119 deltaDer[m_iPhase][i] = sed->xip()(i);
120 ATH_MSG_DEBUG(" xi[" << i << " ] = " << deltaVal[m_iPhase][i]);
121 }
122 }
123 else {
124 ATH_MSG_DEBUG("--> No information for channel " << k<< ", id = " << channelID << ", gain = " << gain);
125 }
126 lsc->set(channelID, gain, deltaVal, deltaDer);
127 }
128 delete history;
129 }
130
131 ATH_MSG_INFO("Writing LArShapeComplete output to " << m_outputFileName );
132 //TFile* out = TFile::Open(m_outputFileName.c_str(), "RECREATE");
133 //out->WriteObjectAny(lsc, "LArShapeComplete", "LArShape");
134 //delete out;
135 if (detStore()->record(lsc, m_sgKey).isFailure()) {
136 ATH_MSG_ERROR("Unable to write LArShapeComplete");
137 return StatusCode::FAILURE;
138 };
139
140 ATH_MSG_INFO( "Done!");
141
142 return StatusCode::SUCCESS;
143}
144
145
147{
148 ATH_MSG_INFO( "Writing template..." );
149 //m_template->writeTrees(m_outputTemplateFileName.c_str());
150 m_template->writeTrees(((std::string)m_outputTemplateFileName).c_str());
151 ATH_MSG_INFO("done..." );
152 return StatusCode::SUCCESS;
153}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
This is a "hash" representation of an Identifier.
void setGroupingType(GroupingType type)
allow group type to be set externally - need to (re)initialize after setting grouping type
virtual StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
storage of the time histories of all the cells
void add(const DataContainer *data)
append data (takes ownership)
const ShapeErrorData * shapeErrorData(CaloGain::CaloGain gain, ShapeErrorType shapeErrorType=BestShapeError, const Residual *res=0) const
Definition History.cxx:302
const TVectorD & xi() const
const TVectorD & xip() const
virtual StatusCode finalize() override final
Gaudi::Property< std::string > m_shapeErrorFileName
Gaudi::Property< std::string > m_groupingType
Gaudi::Property< std::string > m_outputFileName
LArSamples::DataStore * m_template
Gaudi::Property< std::string > m_sgKey
Gaudi::Property< std::string > m_outputTemplateFileName
ToolHandle< ILArShapeDumperTool > m_dumperTool
LArShapeCompleteMakerAlg(const std::string &name, ISvcLocator *pSvcLocator)
virtual StatusCode execute() override final
virtual StatusCode initialize() override final
SG::ReadCondHandleKey< LArOnOffIdMapping > m_onOffMapKey
Gaudi::Property< int > m_minNPulses
This class implements the ILArShape interface.
void set(const HWIdentifier &CellID, int gain, const std::vector< std::vector< float > > &vShape, const std::vector< std::vector< float > > &vShapeDer, float timeOffset=0, float timeBinWidth=25./24.)