Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
DetectorData.cxx
Go to the documentation of this file.
1
2//
3// Podd::DetectorData
4//
6
7#include "DetectorData.h"
8#include "Decoder.h"
9#include "THaAnalysisObject.h" // For DefineVarsFromList
10
11#include <stdexcept>
12#include <sstream>
13
14using namespace std;
16
17namespace Podd {
18
19//_____________________________________________________________________________
20DetectorData::DetectorData( const char* name, const char* desc )
21 : TNamed(name,desc), fVarOK(false), fHitDone(false)
22{
23 // Base class constructor
24}
25
26//_____________________________________________________________________________
31
32//_____________________________________________________________________________
34{
35 // Return the 'logical channel' for the hardware channel referenced by
36 // 'hitinfo'. The logical channel is the user-facing channel number, the
37 // index into whatever arrays the detector data are stored.
38 //
39 // By default, this is the sequence number of the channel in the detector
40 // map modulo the number of channels defined.
41 //
42 // Derived classes may use a different mapping here, e.g. a lookup table to
43 // handle an irregular wiring scheme.
44
45 UInt_t nelem = GetSize();
46 if( nelem == 0 )
47 throw logic_error(msg(hitinfo, "DetectorData: bad size. "
48 "Should never happen. Call expert."));
49 return hitinfo.lchan % static_cast<Int_t>(nelem);
50}
51
52//_____________________________________________________________________________
54 const char* key_prefix,
55 const char* comment_subst )
56{
57 // Define variables for DetectorData and subclasses. The actual work is done
58 // in the virtual function DefineVariablesImpl.
59
62
63 Int_t ret = DefineVariablesImpl(mode, key_prefix, comment_subst);
64 if( ret )
65 return ret;
66
69}
70
71//_____________________________________________________________________________
73 const char* /*key_prefix*/,
74 const char* /*comment_subst*/ )
75{
76 // Define global variables for these detector data. This is the base class
77 // version, which currently does not define anything. Derived classes will
78 // typically override this function. (DetectorData without variables would be
79 // rather pointless.)
80
82}
83
84//_____________________________________________________________________________
87 const char* key_prefix,
88 const char* here,
89 const char* comment_subst )
90{
91 // Standard implementation of DefineVariables for DetectorData.
92 // Avoids code duplication and ensures consistent behavior.
93
94 TString prefix = fName + ".";
95 if( key_prefix && *key_prefix )
96 prefix += key_prefix;
98 vars, THaAnalysisObject::kRVarDef, mode, "", this, prefix.Data(),
99 here, comment_subst);
100}
101
102//_____________________________________________________________________________
103string DetectorData::msg( const DigitizerHitInfo_t& hitinfo, const char* txt )
104{
105 // Format message string for exceptions
106 ostringstream ostr;
107 ostr << "Event " << hitinfo.ev << ", ";
108 ostr << "channel "
109 << hitinfo.crate << "/" << hitinfo.slot << "/"
110 << hitinfo.chan << "/" << hitinfo.hit << ": ";
111 if( txt and *txt ) ostr << txt; else ostr << "Unspecified error.";
112 return ostr.str();
113}
114
115//=============================================================================
116ADCData::ADCData( const char* name, const char* desc, UInt_t nelem )
117 : DetectorData(name, desc), fCalib(nelem), fADCs(nelem), fNHits(0)
118{
119 // Constructor. Creates data structures for 'nelem' ADC channels, i.e.
120 // each channel is assumed to have one ADC reading plus pedestal-corrected
121 // and calibrated values and associated calibration constants.
122 // See the ADCCalib_t and ADCData_t structures for details.
123}
124
125//_____________________________________________________________________________
127{
128 // Clear event-by-event data
130
131 for( auto& adc : fADCs ) {
132 adc.adc_clear();
133 }
134 fNHits = 0;
135}
136
137//_____________________________________________________________________________
139{
140 // Clear event-by-event data and reset calibration values to defaults.
141 Clear(opt);
142
143 for( auto& calib : fCalib ) {
144 calib.adc_calib_reset();
145 }
146}
147
148//_____________________________________________________________________________
149static void StoreADC( ADCData_t& ADC, const ADCCalib_t& CALIB,
150 const DigitizerHitInfo_t& hitinfo, UInt_t data )
151{
152 ADC.adc = data;
153 ADC.adc_p = ADC.adc - CALIB.ped;
154 ADC.adc_c = ADC.adc_p * CALIB.gain;
155 ADC.nadc = hitinfo.nhit;
156}
157
158//_____________________________________________________________________________
159static void StoreTDC( TDCData_t& TDC, const TDCCalib_t& CALIB,
160 const DigitizerHitInfo_t& hitinfo, UInt_t data )
161{
162 TDC.tdc = data;
163 TDC.tdc_c = (TDC.tdc - CALIB.off) * CALIB.tdc2t;
164 assert(CALIB.tdc2t >= 0.0); // else bug in ReadDatabase
165 if( hitinfo.type == ChannelType::kCommonStopTDC ) {
166 // For common stop TDCs, time is negatively correlated to raw data
167 // time = (offset-data)*res, so reverse the sign.
168 TDC.tdc_c *= -1.0;
169 }
170 TDC.ntdc = hitinfo.nhit;
171}
172
173//_____________________________________________________________________________
175{
176 // Copy the raw and calibrated ADC/TDC data to the member variables.
177 // This is the single-hit version of this function.
178
179 size_t k = GetLogicalChannel(hitinfo);
180 if( k >= fADCs.size() )
181 throw
182 std::invalid_argument(msg(hitinfo, "Logical channel number out of range"));
183
184 switch( hitinfo.type ) {
185 case ChannelType::kADC:
186 case ChannelType::kMultiFunctionADC:
187 StoreADC(fADCs[k], fCalib[k], hitinfo, data);
188 fNHits++;
189 fHitDone = true;
190 break;
191
192 case ChannelType::kUndefined:
193 throw logic_error(msg(hitinfo, "Invalid channel type"));
194 default:
195 break;
196 }
197 return 0;
198}
199
200//_____________________________________________________________________________
202 const char* key_prefix,
203 const char* comment_subst )
204{
205 // Export ADCData results as global variables
206
207 const char* const here = "ADCData::DefineVariables";
208
209 // Define variables of the base class, if any
210 Int_t ret = DetectorData::DefineVariablesImpl(mode, key_prefix, comment_subst);
211 if( ret )
212 return ret;
213
214 const RVarDef vars[] = {
215 { "nhit", "Number of %s PMTs with ADC signal", "fNHits" },
216 { "a", "Raw %s ADC amplitudes", "fADCs.adc" },
217 { "a_p", "Pedestal-subtracted %s ADC amplitudes", "fADCs.adc_p" },
218 { "a_c", "Gain-corrected %s ADC amplitudes", "fADCs.adc_c" },
219 { nullptr }
220 };
221 return StdDefineVariables(vars, mode, key_prefix, here, comment_subst);
222}
223
224//=============================================================================
225PMTData::PMTData( const char* name, const char* desc, UInt_t nelem )
226 : DetectorData(name, desc), fCalib(nelem), fPMTs(nelem)
227{
228 // Constructor. Creates data structures for 'nelem' ADC+TDC channels, i.e.
229 // each channel is assumed to have one ADC and one TDC reading plus pedestal-
230 // corrected and calibrated values and associated calibration constants.
231 // See the ADC/TDCCalib_t and ADC/TDCData_t structures for details.
232}
233
234//_____________________________________________________________________________
236{
237 // Clear event-by-event data
239
240 for( auto& pmt : fPMTs ) {
241 pmt.clear();
242 }
243 fNHits.clear();
244}
245
246//_____________________________________________________________________________
248{
249 // Clear event-by-event data and reset calibration values to defaults.
250 Clear(opt);
251
252 for( auto& calib : fCalib ) {
253 calib.reset();
254 }
255}
256
257//_____________________________________________________________________________
259{
260 // Copy the raw and calibrated ADC/TDC data to the member variables.
261 // This is the single-hit version of this function.
262
263 size_t k = GetLogicalChannel(hitinfo);
264 if( k >= fPMTs.size() )
265 throw
266 std::invalid_argument(msg(hitinfo, "Logical channel number out of range"));
267
268 switch( hitinfo.type ) {
269 case ChannelType::kADC:
270 case ChannelType::kMultiFunctionADC:
271 StoreADC(fPMTs[k], fCalib[k], hitinfo, data);
272 fNHits.adc++;
273 fHitDone = true;
274 break;
275
276 case ChannelType::kCommonStopTDC:
277 case ChannelType::kCommonStartTDC:
278 case ChannelType::kMultiFunctionTDC:
279 StoreTDC(fPMTs[k], fCalib[k], hitinfo, data);
280 fNHits.tdc++;
281 fHitDone = true;
282 break;
283
284 default:
285 break;
286 case ChannelType::kUndefined:
287 throw logic_error(msg(hitinfo, "Invalid channel type"));
288 }
289 return 0;
290}
291
292//_____________________________________________________________________________
294 const char* key_prefix,
295 const char* comment_subst )
296{
297 // Export PMTData results as global variables
298
299 const char* const here = "PMTData::DefineVariables";
300
301 // Define variables of the base class, if any
302 Int_t ret = DetectorData::DefineVariablesImpl(mode, key_prefix, comment_subst);
303 if( ret )
304 return ret;
305
306 const RVarDef vars[] = {
307 { "nthit", "Number of %s PMTs with valid TDC", "fNHits.tdc" },
308 { "nahit", "Number of %s PMTs with ADC signal", "fNHits.adc" },
309 { "nhits", "Total number of %s TDC hits", "fPMTs.ntdc" },
310 { "t", "Raw %s TDC times", "fPMTs.tdc" },
311 { "t_c", "Calibrated %s TDC times (s)", "fPMTs.tdc_c" },
312 { "a", "Raw %s ADC amplitudes", "fPMTs.adc" },
313 { "a_p", "Pedestal-subtracted %s ADC amplitudes", "fPMTs.adc_p" },
314 { "a_c", "Gain-corrected %s ADC amplitudes", "fPMTs.adc_c" },
315 { nullptr }
316 };
317 return StdDefineVariables(vars, mode, key_prefix, here, comment_subst);
318}
319
320//_____________________________________________________________________________
321
322} // namespace Podd
323
int Int_t
unsigned int UInt_t
const char Option_t
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char mode
char name[80]
static const char *const here
Definition THaVar.cxx:64
std::vector< ADCData_t > fADCs
std::vector< ADCCalib_t > fCalib
void Reset(Option_t *="") override
Int_t StoreHit(const DigitizerHitInfo_t &hitinfo, UInt_t data) override
void Clear(Option_t *="") override
Int_t DefineVariablesImpl(THaAnalysisObject::EMode mode=THaAnalysisObject::kDefine, const char *key_prefix="", const char *comment_subst="") override
ADCData(const char *name, const char *desc, UInt_t nelem)
virtual Int_t DefineVariablesImpl(THaAnalysisObject::EMode mode=THaAnalysisObject::kDefine, const char *key_prefix="", const char *comment_subst="")
virtual Int_t GetLogicalChannel(const DigitizerHitInfo_t &hitinfo) const
static std::string msg(const DigitizerHitInfo_t &hitinfo, const char *txt)
Int_t DefineVariables(THaAnalysisObject::EMode mode=THaAnalysisObject::kDefine, const char *key_prefix="", const char *comment_subst="")
virtual UInt_t GetSize() const =0
Int_t StdDefineVariables(const RVarDef *vars, THaAnalysisObject::EMode mode, const char *key_prefix, const char *here, const char *comment_subst)
void Clear(Option_t *="") override
std::vector< PMTData_t > fPMTs
Int_t DefineVariablesImpl(THaAnalysisObject::EMode mode=THaAnalysisObject::kDefine, const char *key_prefix="", const char *comment_subst="") override
std::vector< PMTCalib_t > fCalib
Int_t StoreHit(const DigitizerHitInfo_t &hitinfo, UInt_t data) override
void Clear(Option_t *="") override
HitCount_t fNHits
void Reset(Option_t *="") override
PMTData(const char *name, const char *desc, UInt_t nelem)
static Int_t DefineVarsFromList(const void *list, EType type, EMode mode, const char *def_prefix, const TObject *obj, const char *prefix, const char *here, const char *comment_subst="")
Decoder::Module *Decoder::ChannelType type
Definition THaDetMap.h:197
TString fName
const char * Data() const
ChannelType
Definition Decoder.h:61
static void StoreADC(ADCData_t &ADC, const ADCCalib_t &CALIB, const DigitizerHitInfo_t &hitinfo, UInt_t data)
static void StoreTDC(TDCData_t &TDC, const TDCCalib_t &CALIB, const DigitizerHitInfo_t &hitinfo, UInt_t data)
STL namespace.
ClassImp(TPyArg)