ATLAS Offline Software
Loading...
Searching...
No Matches
LArShapeCompleteMaker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
10
14#include "GaudiKernel/MsgStream.h"
20#include <memory>
21
22using namespace LArSamples;
23
24LArShapeCompleteMaker::LArShapeCompleteMaker(const std::string & name, ISvcLocator * pSvcLocator) :
25 AthAlgorithm(name, pSvcLocator),
26 m_template(nullptr),
27 m_dumperTool("LArShapeDumperTool")
28{
29 declareProperty("NSamples", m_nSamples = 5);
30 declareProperty("NPhases", m_nPhases = 17);
31 declareProperty("IPhase", m_iPhase = 8);
32 declareProperty("ShapeErrorFileName", m_shapeErrorFileName);
33 declareProperty("OutputFileName", m_outputFileName);
34 declareProperty("OutputTemplateFileName", m_outputTemplateFileName);
35 declareProperty("StoreGateKey", m_sgKey = "LArResiduals");
36 declareProperty("MinNPulses", m_minNPulses = 0);
37 declareProperty("GroupingType", m_groupingType = "ExtendedSubDetector");
38}
39
40
44
45
47{
48
49 ATH_CHECK(detStore()->retrieve(m_onlineHelper, "LArOnlineID"));
50
51 ATH_CHECK( m_onOffMapKey.initialize() );
52
53 return StatusCode::SUCCESS;
54}
55
56
58{
59 if (m_template) return StatusCode::SUCCESS;
60 m_template = new DataStore();
61
62 auto lsc = std::make_unique<LArShapeComplete>();
63
64 if (lsc->setGroupingType(m_groupingType, msg()).isFailure() || lsc->initialize().isFailure()) {
65 ATH_MSG_ERROR("Unable to initialize LArShapeComplete");
66 return StatusCode::FAILURE;
67 };
68
70
71 auto errorGetter = std::make_unique<TreeShapeErrorGetter>(m_shapeErrorFileName);
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 return StatusCode::FAILURE;
86 }
87
88 HistoryContainer* histCont = m_template->makeNewHistory(k, info);
89 std::vector<const EventData*> events;
90 for (unsigned int g = 0; g < 3; g++) {
91 DataContainer* data = new DataContainer((CaloGain::CaloGain)g, std::vector<short>(), 0, 0, 0, -1, std::vector<float>());
92 events.push_back(new EventData(-1,-1,-1,-1));
93 histCont->add(data);
94 }
95 History* history = new History(*histCont, events, k, errorGetter.get());
96
97 for (unsigned int g = 0; g < 3; g++) {
99 const LArSamples::ShapeErrorData* sed = nullptr;
100 if (history) sed = history->shapeErrorData(gain, LArSamples::BestShapeError);
101
102 // The containers
103
104 // Fill them with 0's to start with
105 std::vector<float> phaseVect(m_nSamples,0);
106 std::vector<std::vector<float> > deltaVal(m_nPhases, phaseVect);
107 std::vector<std::vector<float> > deltaDer(m_nPhases, phaseVect);
108
109
110 if (sed && sed->n() > m_minNPulses) {
111 ATH_MSG_DEBUG("--> Setting channel " << k << ", id = " << channelID << ", gain = " << gain << ", size = "
112 << deltaVal.size() << " " << deltaDer.size());
113 for (unsigned int i = 0; i < m_nSamples; i++) {
114 deltaVal[m_iPhase][i] = sed->xi()(i);
115 deltaDer[m_iPhase][i] = sed->xip()(i);
116 ATH_MSG_DEBUG(" xi[" << i << " ] = " << deltaVal[m_iPhase][i]);
117 }
118 }
119 else {
120 ATH_MSG_DEBUG("--> No information for channel " << k<< ", id = " << channelID << ", gain = " << gain);
121 }
122 lsc->set(channelID, gain, deltaVal, deltaDer);
123 }
124 delete history;
125 }
126
127 ATH_MSG_INFO("Writing LArShapeComplete output to " << m_outputFileName );
128 //TFile* out = TFile::Open(m_outputFileName.c_str(), "RECREATE");
129 //out->WriteObjectAny(lsc, "LArShapeComplete", "LArShape");
130 //delete out;
131 if (detStore()->record(std::move(lsc), m_sgKey).isFailure()) {
132 ATH_MSG_ERROR("Unable to write LArShapeComplete");
133 return StatusCode::FAILURE;
134 };
135
136 ATH_MSG_INFO( "Done!");
137
138 return StatusCode::SUCCESS;
139}
140
141
143{
144 ATH_MSG_INFO( "Writing template..." );
145 m_template->writeTrees(m_outputTemplateFileName.c_str());
146 ATH_MSG_INFO("done..." );
147 return StatusCode::SUCCESS;
148}
#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:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
This is a "hash" representation of an Identifier.
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
ToolHandle< ILArShapeDumperTool > m_dumperTool
virtual StatusCode execute() override
const LArOnlineID * m_onlineHelper
SG::ReadCondHandleKey< LArOnOffIdMapping > m_onOffMapKey
LArSamples::DataStore * m_template
virtual StatusCode finalize() override
virtual StatusCode initialize() override
LArShapeCompleteMaker(const std::string &name, ISvcLocator *pSvcLocator)