ATLAS Offline Software
Loading...
Searching...
No Matches
LArAccumulatedDigits2Ntuple.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
7
8//#include "GaudiKernel/ToolHandle.h"
9
10LArAccumulatedDigits2Ntuple::LArAccumulatedDigits2Ntuple(const std::string& name, ISvcLocator* pSvcLocator):
11 LArCond2NtupleBase(name, pSvcLocator),
12 m_ipass(0),
13 m_event(0)
14{
15 m_ntTitle="AccumulatedDigits";
16 m_ntpath="/NTUPLES/FILE1/ACCUMULATEDDIGITS"+m_contKey.key();
17
18}
19
21= default;
22
23
25{
26 ATH_MSG_INFO( "in initialize" );
27
29 if (sc!=StatusCode::SUCCESS) {
30 ATH_MSG_ERROR( "Base init failed" );
31 return StatusCode::FAILURE;
32 }
33
34
35
36 sc=m_nt->addItem("IEvent",m_IEvent);
37 if (sc!=StatusCode::SUCCESS) {
38 ATH_MSG_ERROR( "addItem 'IEvent' failed" );
39 return sc;
40 }
41
42 sc=m_nt->addItem("EventNum",m_EventNum);
43 if (sc!=StatusCode::SUCCESS) {
44 ATH_MSG_ERROR( "addItem 'EventNum' failed" );
45 return sc;
46 }
47
48 sc=m_nt->addItem("Ntrigger",m_Ntrigger,0,500);
49 if (sc!=StatusCode::SUCCESS) {
50 ATH_MSG_ERROR( "addItem 'Ntrigger' failed" );
51 return sc;
52 }
53
54 sc=m_nt->addItem("Nsamples",m_ntNsamples,0,32);
55 if (sc!=StatusCode::SUCCESS) {
56 ATH_MSG_ERROR( "addItem 'Nsamples' failed" );
57 return sc;
58 }
59
60 sc=m_nt->addItem("Sum",m_Nsamples,m_sum);
61 if (sc!=StatusCode::SUCCESS) {
62 ATH_MSG_ERROR( "addItem 'sum' failed" );
63 return sc;
64 }
65
66 sc=m_nt->addItem("Sumsq",m_Nsamples,m_sumsq);
67 if (sc!=StatusCode::SUCCESS) {
68 ATH_MSG_ERROR( "addItem 'sumsq' failed" );
69 return sc;
70 }
71
72 sc=m_nt->addItem("Mean",m_mean);
73 if (sc!=StatusCode::SUCCESS) {
74 ATH_MSG_ERROR( "addItem 'mean' failed" );
75 return sc;
76 }
77
78 sc=m_nt->addItem("RMS",m_rms);
79 if (sc!=StatusCode::SUCCESS) {
80 ATH_MSG_ERROR( "addItem 'rms' failed" );
81 return sc;
82 }
83
84 sc=m_nt->addItem("covr",m_Nsamples-1,m_covr);
85 if (sc!=StatusCode::SUCCESS) {
86 ATH_MSG_ERROR( "addItem 'covr' failed" );
87 return sc;
88 }
89
90 ATH_CHECK( m_contKey.initialize(!m_contKey.key().empty()) );
91
92 m_ipass = 0;
93 m_event=0;
94
95 return StatusCode::SUCCESS;
96
97}
98
100{
101
102 ATH_MSG_DEBUG( "in execute" );
103 StatusCode sc;
104
105 if (m_contKey.key().empty()) return StatusCode::SUCCESS;
106
107 const EventContext& ctx = Gaudi::Hive::currentContext();
108
109 m_event++;
110
111 const LArAccumulatedDigitContainer* accuDigitContainer = nullptr;
113 if (!Hdl.isValid()) {
114 ATH_MSG_WARNING( "Unable to retrieve LArAccumulatedDigitContainer with key " << m_contKey.key() << " from DetectorStore. " );
115 return StatusCode::SUCCESS;
116 } else {
117 ATH_MSG_DEBUG( "Got LArAccumulatedDigitContainer with key " << m_contKey.key() );
118 accuDigitContainer = Hdl.cptr();
119 }
120
121 if (accuDigitContainer) {
122
123 if(accuDigitContainer->empty()) {
124 ATH_MSG_DEBUG( "LArAccumulatedDigitContainer with key=" << m_contKey << " is empty " );
125 return StatusCode::SUCCESS;
126 }else{
127 ATH_MSG_DEBUG( "LArAccumulatedDigitContainer with key=" << m_contKey << " has " <<accuDigitContainer->size() << " entries" );
128 }
129
130 for (const LArAccumulatedDigit* digit : *accuDigitContainer) {
131
133 m_EventNum = ctx.eventID().event_number();
134 m_Ntrigger = digit->nTrigger();
135 unsigned int trueMaxSample = digit->nsample();
136 m_ntNsamples = trueMaxSample;
137
138 if(trueMaxSample>m_Nsamples){
139 if(!m_ipass){
140 ATH_MSG_WARNING( "The number of samples in data is larger than the one specified by JO: " << trueMaxSample << " > " << m_Nsamples << " --> only " << m_Nsamples << " will be available in the ntuple " );
141 m_ipass=1;
142 }
143 trueMaxSample = m_Nsamples;
144 }
145
146 m_mean = digit->mean();
147 m_rms = digit->RMS();
148 const std::vector<uint64_t> sampleSquare = digit->sampleSquare();
149 const std::vector<uint64_t> sampleSum = digit->sampleSum();
150 for(unsigned i=0;i<trueMaxSample;i++) {
151 m_sumsq[i] = sampleSquare[i];
152 m_sum[i] = sampleSum[i];
153 }
154 std::vector<float> cov;
155 digit->getCov(cov,m_normalize);
156 for(unsigned i=0;i<trueMaxSample-1;i++) {
157 m_covr[i] = cov[i];
158 }
159
160 fillFromIdentifier(digit->hardwareID());
161 sc=ntupleSvc()->writeRecord(m_nt);
162 if (sc!=StatusCode::SUCCESS) {
163 ATH_MSG_ERROR( "writeRecord failed" );
164 return sc;
165 }
166 }
167 }
168 return StatusCode::SUCCESS;
169}// end execute method.
#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)
static Double_t sc
INTupleSvc * ntupleSvc()
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
Container class for LArAccumulatedDigit.
Data class for ADC samples and autocorr preprocessed by the DSP.
SG::ReadHandleKey< LArAccumulatedDigitContainer > m_contKey
virtual StatusCode initialize() override final
virtual StatusCode execute() override final
LArAccumulatedDigits2Ntuple(const std::string &name, ISvcLocator *pSvcLocator)
Gaudi::Property< unsigned int > m_Nsamples
bool fillFromIdentifier(const HWIdentifier &id)
LArCond2NtupleBase(const std::string &name, ISvcLocator *pSvcLocator)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.