ATLAS Offline Software
LArShapeCompleteMakerAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
10 #include "GaudiKernel/MsgStream.h"
14 #include "LArCafJobs/DataStore.h"
16 #include "LArSamplesMon/History.h"
17 #include "LArCafJobs/EventData.h"
19 
20 using namespace LArSamples;
21 
22 LArShapeCompleteMakerAlg::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 
40 {
41 }
42 
43 
45 {
46 
47  ATH_CHECK(detStore()->retrieve(m_onlineHelper, "LArOnlineID"));
48 
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  return StatusCode::FAILURE;
66  };
67 
68  TreeShapeErrorGetter* errorGetter = new TreeShapeErrorGetter((std::string) m_shapeErrorFileName);
69 
71 
72  for (unsigned int k = 0; k < LArSamples::Definitions::nChannels; k++) {
73 
74  HWIdentifier channelID = m_onlineHelper->channel_Id((IdentifierHash)k);
75  const Identifier id = onOffMap->cnvToIdentifier(channelID);
76  if (id.get_compact() == 0xffffffff) {
77  ATH_MSG_WARNING( "Skipping invalid hash = " << k << "." );
78  continue;
79  }
80 
81  CellInfo* info = m_dumperTool->makeCellInfo(channelID, id);
82  if (!info) {
83  ATH_MSG_ERROR("Problem making cell info for hash = " << k << ", terminating...");
84  return StatusCode::FAILURE;
85  }
86 
88  std::vector<const EventData*> events;
89  for (unsigned int g = 0; g < 3; g++) {
90  DataContainer* data = new DataContainer((CaloGain::CaloGain)g, std::vector<short>(), 0, 0, 0, -1, std::vector<float>());
91  events.push_back(new EventData(-1,-1,-1,-1));
92  histCont->add(data);
93  }
94  History* history = new History(*histCont, events, k, errorGetter);
95 
96  for (unsigned int g = 0; g < 3; g++) {
98  const LArSamples::ShapeErrorData* sed = nullptr;
99  if (history) sed = history->shapeErrorData(gain, LArSamples::BestShapeError);
100 
101  // The containers
102  std::vector<std::vector<float> > deltaVal, deltaDer;
103 
104  // Fill them with 0's to start with
105  std::vector<float> phaseVect(m_nSamples);
106  for (unsigned int j = 0; j < m_nSamples; j++) phaseVect[j] = 0;
107  for (unsigned int i = 0; i < m_nPhases; i++) {
108  deltaVal.push_back(phaseVect);
109  deltaDer.push_back(phaseVect);
110  }
111 
112  if (sed && sed->n() > m_minNPulses) {
113  ATH_MSG_DEBUG("--> Setting channel " << k << ", id = " << channelID << ", gain = " << gain << ", size = "
114  << deltaVal.size() << " " << deltaDer.size());
115  for (unsigned int i = 0; i < m_nSamples; i++) {
116  deltaVal[m_iPhase][i] = sed->xi()(i);
117  deltaDer[m_iPhase][i] = sed->xip()(i);
118  ATH_MSG_DEBUG(" xi[" << i << " ] = " << deltaVal[m_iPhase][i]);
119  }
120  }
121  else {
122  ATH_MSG_DEBUG("--> No information for channel " << k<< ", id = " << channelID << ", gain = " << gain);
123  }
124  lsc->set(channelID, gain, deltaVal, deltaDer);
125  }
126  delete history;
127  }
128 
129  ATH_MSG_INFO("Writing LArShapeComplete output to " << m_outputFileName );
130  //TFile* out = TFile::Open(m_outputFileName.c_str(), "RECREATE");
131  //out->WriteObjectAny(lsc, "LArShapeComplete", "LArShape");
132  //delete out;
133  if (detStore()->record(lsc, m_sgKey).isFailure()) {
134  ATH_MSG_ERROR("Unable to write LArShapeComplete");
135  return StatusCode::FAILURE;
136  };
137 
138  ATH_MSG_INFO( "Done!");
139 
140  return StatusCode::SUCCESS;
141 }
142 
143 
145 {
146  ATH_MSG_INFO( "Writing template..." );
147  //m_template->writeTrees(m_outputTemplateFileName.c_str());
148  m_template->writeTrees(((std::string)m_outputTemplateFileName).c_str());
149  ATH_MSG_INFO("done..." );
150  return StatusCode::SUCCESS;
151 }
grepfile.info
info
Definition: grepfile.py:38
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TreeShapeErrorGetter.h
LArShapeCompleteMakerAlg::~LArShapeCompleteMakerAlg
virtual ~LArShapeCompleteMakerAlg()
Definition: LArShapeCompleteMakerAlg.cxx:39
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
LArShapeCompleteMakerAlg::m_minNPulses
Gaudi::Property< int > m_minNPulses
Definition: LArShapeCompleteMakerAlg.h:63
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArShapeCompleteMakerAlg::execute
virtual StatusCode execute() override final
Definition: LArShapeCompleteMakerAlg.cxx:56
LArShapeCompleteMakerAlg::m_shapeErrorFileName
Gaudi::Property< std::string > m_shapeErrorFileName
Definition: LArShapeCompleteMakerAlg.h:64
DataStore.h
initialize
void initialize()
Definition: run_EoverP.cxx:894
LArSamples::History
Definition: History.h:40
CaloCondBlobAlgs_fillNoiseFromASCII.gain
gain
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:110
LArShapeCompleteMakerAlg::m_onlineHelper
const LArOnlineID * m_onlineHelper
Definition: LArShapeCompleteMakerAlg.h:52
LArShapeCompleteMakerAlg::LArShapeCompleteMakerAlg
LArShapeCompleteMakerAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArShapeCompleteMakerAlg.cxx:22
LArShapeCompleteMakerAlg::m_outputFileName
Gaudi::Property< std::string > m_outputFileName
Definition: LArShapeCompleteMakerAlg.h:66
LArShapeComplete
This class implements the ILArShape interface.
Definition: LArShapeComplete.h:26
LArSamples
Definition: AbsShape.h:24
LArShapeCompleteMakerAlg::initialize
virtual StatusCode initialize() override final
Definition: LArShapeCompleteMakerAlg.cxx:44
LArShapeComplete.h
LArShapeCompleteMakerAlg::finalize
virtual StatusCode finalize() override final
Definition: LArShapeCompleteMakerAlg.cxx:144
python.DataFormatRates.events
events
Definition: DataFormatRates.py:105
ReadCondHandle.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
LArSamples::ShapeErrorData::xip
const TVectorD & xip() const
Definition: ShapeErrorData.h:41
DataContainer.h
LArShapeCompleteMakerAlg::m_outputTemplateFileName
Gaudi::Property< std::string > m_outputTemplateFileName
Definition: LArShapeCompleteMakerAlg.h:65
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
LArSamples::Definitions::nChannels
static const unsigned int nChannels
Definition: Definitions.h:14
lumiFormat.i
int i
Definition: lumiFormat.py:92
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
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
LArShapeCompleteMakerAlg.h
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:1569
LArSamples::BestShapeError
@ BestShapeError
Definition: Definitions.h:25
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArShapeCompleteMakerAlg::m_template
LArSamples::DataStore * m_template
Definition: LArShapeCompleteMakerAlg.h:54
ITk::EventData
InDet::SiSpacePointsSeedMakerEventData EventData
Definition: ITkSiSpacePointsSeedMaker.h:63
LArShapeCompleteMakerAlg::m_dumperTool
ToolHandle< ILArShapeDumperTool > m_dumperTool
Definition: LArShapeCompleteMakerAlg.h:56
EventData.h
LArShapeCompleteMakerAlg::m_nSamples
unsigned int m_nSamples
Definition: LArShapeCompleteMakerAlg.h:58
AthAlgorithm
Definition: AthAlgorithm.h:47
LArSamples::ShapeErrorData::n
int n() const
Definition: ShapeErrorData.h:54
LArShapeCompleteMakerAlg::m_iPhase
unsigned int m_iPhase
Definition: LArShapeCompleteMakerAlg.h:60
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
LArShapeComplete::set
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.)
Definition: LArShapeComplete.cxx:17
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArSamples::TreeShapeErrorGetter
Definition: TreeShapeErrorGetter.h:31
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
LArShapeCompleteMakerAlg::m_nPhases
unsigned int m_nPhases
Definition: LArShapeCompleteMakerAlg.h:59
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:299
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
LArConditionsContainer::initialize
virtual StatusCode initialize()
Initialization done after creation or read back - derived classes may augment the functionality.
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
LArShapeCompleteMakerAlg::m_onOffMapKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_onOffMapKey
Definition: LArShapeCompleteMakerAlg.h:74
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
ShapeErrorData.h
LArSamples::ShapeErrorData
Definition: ShapeErrorData.h:19
History.h
LArSamples::ShapeErrorData::xi
const TVectorD & xi() const
Definition: ShapeErrorData.h:40
LArSamples::FitterData::sed
const ScaledErrorData * sed
Definition: ShapeFitter.cxx:26
LArShapeCompleteMakerAlg::m_sgKey
Gaudi::Property< std::string > m_sgKey
Definition: LArShapeCompleteMakerAlg.h:67
StoreGateSvc.h
LArShapeCompleteMakerAlg::m_groupingType
Gaudi::Property< std::string > m_groupingType
Definition: LArShapeCompleteMakerAlg.h:68
LArSamples::DataStore::writeTrees
bool writeTrees(const char *fileName)
Definition: LArCalorimeter/LArCafJobs/src/DataStore.cxx:110
fitman.k
k
Definition: fitman.py:528
LArOnlineID.h
LArSamples::DataStore::makeNewHistory
HistoryContainer * makeNewHistory(const IdentifierHash &hash, CellInfo *info)
append data (takes ownership of everything)
Definition: LArCalorimeter/LArCafJobs/src/DataStore.cxx:38