ATLAS Offline Software
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 
8 #include "LArCafJobs/DataStore.h"
10 
12 #include "StoreGate/StoreGateSvc.h"
14 #include "GaudiKernel/MsgStream.h"
18 #include "LArSamplesMon/History.h"
19 #include "LArCafJobs/EventData.h"
20 #include <memory>
21 
22 using namespace LArSamples;
23 
24 LArShapeCompleteMaker::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 
42 {
43 }
44 
45 
47 {
48 
49  ATH_CHECK(detStore()->retrieve(m_onlineHelper, "LArOnlineID"));
50 
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 
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..." );
146  ATH_MSG_INFO("done..." );
147  return StatusCode::SUCCESS;
148 }
grepfile.info
info
Definition: grepfile.py:38
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TreeShapeErrorGetter.h
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
LArShapeCompleteMaker::m_outputTemplateFileName
std::string m_outputTemplateFileName
Definition: LArShapeCompleteMaker.h:51
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArShapeCompleteMaker::m_minNPulses
int m_minNPulses
Definition: LArShapeCompleteMaker.h:50
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
LArShapeCompleteMaker::m_nSamples
unsigned int m_nSamples
Definition: LArShapeCompleteMaker.h:49
DataStore.h
LArShapeCompleteMaker::execute
virtual StatusCode execute() override
Definition: LArShapeCompleteMaker.cxx:57
LArSamples::History
Definition: History.h:35
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
LArShapeCompleteMaker::m_iPhase
unsigned int m_iPhase
Definition: LArShapeCompleteMaker.h:49
LArShapeCompleteMaker::m_template
LArSamples::DataStore * m_template
Definition: LArShapeCompleteMaker.h:45
LArSamples
Definition: AbsShape.h:24
LArShapeCompleteMaker::initialize
virtual StatusCode initialize() override
Definition: LArShapeCompleteMaker.cxx:46
LArShapeCompleteMaker::m_nPhases
unsigned int m_nPhases
Definition: LArShapeCompleteMaker.h:49
LArShapeCompleteMaker::m_dumperTool
ToolHandle< ILArShapeDumperTool > m_dumperTool
Definition: LArShapeCompleteMaker.h:47
LArShapeComplete.h
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
LArShapeCompleteMaker::m_shapeErrorFileName
std::string m_shapeErrorFileName
Definition: LArShapeCompleteMaker.h:51
ReadCondHandle.h
LArShapeCompleteMaker::LArShapeCompleteMaker
LArShapeCompleteMaker(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArShapeCompleteMaker.cxx:24
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
LArShapeCompleteMaker::m_outputFileName
std::string m_outputFileName
Definition: LArShapeCompleteMaker.h:51
LArSamples::ShapeErrorData::xip
const TVectorD & xip() const
Definition: ShapeErrorData.h:41
DataContainer.h
LArShapeCompleteMaker::m_sgKey
std::string m_sgKey
Definition: LArShapeCompleteMaker.h:51
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArSamples::Definitions::nChannels
static const unsigned int nChannels
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/Definitions.h:14
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
LArShapeCompleteMaker::finalize
virtual StatusCode finalize() override
Definition: LArShapeCompleteMaker.cxx:142
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
LArOnlineID_Base::channel_Id
HWIdentifier channel_Id(int barrel_ec, int pos_neg, int feedthrough, int slot, int channel) const
create channel identifier from fields
Definition: LArOnlineID_Base.cxx:1565
LArSamples::BestShapeError
@ BestShapeError
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/Definitions.h:25
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ITk::EventData
InDet::SiSpacePointsSeedMakerEventData EventData
Definition: ITkSiSpacePointsSeedMaker.h:63
LArShapeCompleteMaker::~LArShapeCompleteMaker
~LArShapeCompleteMaker()
Definition: LArShapeCompleteMaker.cxx:41
EventData.h
AthAlgorithm
Definition: AthAlgorithm.h:47
LArShapeCompleteMaker::m_onOffMapKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_onOffMapKey
Definition: LArShapeCompleteMaker.h:55
LArSamples::ShapeErrorData::n
int n() const
Definition: ShapeErrorData.h:54
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArSamples::DataStore
storage of the time histories of all the cells
Definition: LArCalorimeter/LArCafJobs/LArCafJobs/DataStore.h:32
LArSamples::CellInfo
Definition: CellInfo.h:31
CaloGain::CaloGain
CaloGain
Definition: CaloGain.h:11
LArSamples::DataContainer
Definition: DataContainer.h:25
LArSamples::History::shapeErrorData
const ShapeErrorData * shapeErrorData(CaloGain::CaloGain gain, ShapeErrorType shapeErrorType=BestShapeError, const Residual *res=0) const
Definition: History.cxx:302
LArShapeCompleteMaker::m_groupingType
std::string m_groupingType
Definition: LArShapeCompleteMaker.h:52
LArSamples::HistoryContainer
Definition: HistoryContainer.h:29
LArOnOffIdMapping::cnvToIdentifier
Identifier cnvToIdentifier(const HWIdentifier &sid) const
create an Identifier from a HWIdentifier (inline)
Definition: LArOnOffIdMapping.h:116
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArSamples::HistoryContainer::add
void add(const DataContainer *data)
append data (takes ownership)
Definition: HistoryContainer.h:46
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArShapeCompleteMaker::m_onlineHelper
const LArOnlineID * m_onlineHelper
Definition: LArShapeCompleteMaker.h:43
ShapeErrorData.h
LArSamples::ShapeErrorData
Definition: ShapeErrorData.h:19
History.h
LArShapeCompleteMaker.h
LArSamples::ShapeErrorData::xi
const TVectorD & xi() const
Definition: ShapeErrorData.h:40
LArSamples::FitterData::sed
const ScaledErrorData * sed
Definition: ShapeFitter.cxx:26
CaloGain.h
StoreGateSvc.h
LArSamples::DataStore::writeTrees
bool writeTrees(const char *fileName)
Definition: LArCalorimeter/LArCafJobs/src/DataStore.cxx:110
fitman.k
k
Definition: fitman.py:528
LArOnlineID.h
Identifier
Definition: IdentifierFieldParser.cxx:14
LArSamples::DataStore::makeNewHistory
HistoryContainer * makeNewHistory(const IdentifierHash &hash, CellInfo *info)
append data (takes ownership of everything)
Definition: LArCalorimeter/LArCafJobs/src/DataStore.cxx:38