Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
FADCData.cxx
Go to the documentation of this file.
1
2//
3// HallA::FADCData
4//
6
7#include "FADCData.h"
8#include "THaDetectorBase.h"
9#include "Fadc250Module.h"
10#include "Decoder.h"
11#include <stdexcept>
12
13using namespace std;
14using namespace Decoder;
15
16namespace HallA {
17
18//_____________________________________________________________________________
19// Convenience macro for readability
20#if __cplusplus >= 201402L
21# define MKFADCDATA(name,title,nelem) make_unique<FADCData>((name),(title),(nelem))
22#else
23# define MKFADCDATA(name,title,nelem) unique_ptr<FADCData>(new FADCData((name),(title),(nelem)))
24#endif
25
26//_____________________________________________________________________________
27pair<unique_ptr<FADCData>,Int_t> MakeFADCData( const TDatime& date,
28 THaDetectorBase* det )
29{
30 // Set up FADC data object and read configuration from the database.
31 // Return value:
32 // ret.first: unique_ptr to FADCData object
33 // ret.second: return value from ReadConfig (a ReadDatabase EStatus)
34
35 pair<unique_ptr<FADCData>, Int_t> ret(nullptr, THaAnalysisObject::kFileError);
36 if( !det )
37 return ret;
38
39 // Create new FADC data object
40 auto detdata = MKFADCDATA(det->GetPrefixName(), det->GetTitle(),
41 det->GetNelem());
42
43 // Initialize FADC configuration parameters, using the detector's database
44 FILE* file = det->OpenFile(date);
45 if( !file )
46 return ret;
47 Int_t err = detdata->ReadConfig(file, date, det->GetPrefix());
48 fclose(file);
49 if( err ) {
50 ret.second = err;
51 return ret;
52 }
53
54 ret.first = std::move(detdata);
55 ret.second = THaAnalysisObject::kOK;
56 return ret;
57}
58
59//_____________________________________________________________________________
60FADCData::FADCData( const char* name, const char* desc, Int_t nelem )
61 : DetectorData(name, desc), fFADCData(nelem)
62{
63 // Constructor
64}
65
66//_____________________________________________________________________________
68{
69 // Clear event-by-event data
70 DetectorData::Clear(opt);
71
72 for( auto& fdat : fFADCData ) {
73 fdat.clear();
74 }
75// fNHits.clear();
76}
77
78//_____________________________________________________________________________
80{
81 // Clear event-by-event data and reset calibration values to defaults.
82 Clear(opt);
83
84 fConfig.reset();
85}
86
87//_____________________________________________________________________________
88Int_t FADCData::ReadConfig( FILE* file, const TDatime& date, const char* prefix )
89{
90 // Load FADC configuration parameters (required) from database
91
92 VarType kDataType = std::is_same<Data_t, Float_t>::value ? kFloat : kDouble;
93
94 fConfig.reset(); // Sets default TDC scale
95 DBRequest calib_request[] = {
96 {"NPED", &fConfig.nped, kInt},
97 {"NSA", &fConfig.nsa, kInt},
98 {"NSB", &fConfig.nsb, kInt},
99 {"Win", &fConfig.win, kInt},
100 {"TFlag", &fConfig.tflag, kInt},
101 {"TDCscale", &fConfig.tdcscale, kDataType, 0, true},
102 {nullptr}
103 };
104 return THaAnalysisObject::LoadDB(file, date, calib_request, prefix);
105}
106
107//_____________________________________________________________________________
108static inline
110 Fadc250Module* fadc ) {
111 // Get item 'm.type' from FADC module pointed to by fFADC
112
113 assert(fadc);
114 OptUInt_t val;
115 if( fadc->HasCapability(type) &&
116 hitinfo.hit < fadc->GetNumEvents(type, hitinfo.chan) ) {
117 val = fadc->GetData(type, hitinfo.chan, hitinfo.hit);
118 if( val == kMaxUInt ) // error return code
119 val = nullopt;
120 }
121 return val;
122}
123
124//_____________________________________________________________________________
126{
127 // Retrieve "pulse integral" value from FADC channel given in 'hitinfo'
128
129 auto* fadc = dynamic_cast<Fadc250Module*>(hitinfo.module);
130 if( !fadc )
131 throw logic_error("Bad module type (expected Fadc250Module). "
132 "Should never happen. Call expert.");
133
134 return GetFADCValue( kPulseIntegral, hitinfo, fadc );
135}
136
137//_____________________________________________________________________________
139{
140 // Retrieve full set of FADC data and store it in our data members.
141 // Must call LoadData first. Pass LoadData's return value (= pulse integral
142 // value) into this routine as 'data'.
143
144 if( hitinfo.type != ChannelType::kMultiFunctionADC )
145 return 0;
146
147 size_t k = GetLogicalChannel(hitinfo);
148 if( k >= fFADCData.size() )
149 throw
150 std::invalid_argument(msg(hitinfo, "Logical channel number out of range"));
151
152 auto* fadc = dynamic_cast<Fadc250Module*>(hitinfo.module);
153 assert(fadc); // should have been caught in LoadData
154
155 auto& FDAT = fFADCData[k];
156 FDAT.fIntegral = data;
157 FDAT.fOverflow = fadc->GetOverflowBit(hitinfo.chan, hitinfo.hit);
158 FDAT.fUnderflow = fadc->GetUnderflowBit(hitinfo.chan, hitinfo.hit);
159 FDAT.fPedq = fadc->GetPedestalQuality(hitinfo.chan, hitinfo.hit);
160
161 class TypeItem { public: EModuleType type; const string name; };
162 static const vector<TypeItem> items = {
163 { kPulsePeak, "kPulsePeak" },
164 { kPulseTime, "kPulseTime" },
165 { kPulsePedestal, "kPulsePedestal" }
166 };
167
168 for( const auto& item : items ) {
169 OptUInt_t val = GetFADCValue(item.type, hitinfo, fadc);
170 if( !val ) {
171 string s("Error retrieving FADC item type ");
172 s += item.name; s += ". Decoder bug. Call expert.";
173 throw logic_error(msg(hitinfo,s.c_str())); // FADC's GetNumHits lied to us
174 }
175 switch( item.type ) {
176 case kPulsePeak:
177 FDAT.fPeak = val.value();
178 break;
179 case kPulseTime:
180 FDAT.fT = val.value();
181 FDAT.fT_c = FDAT.fT * fConfig.tdcscale;
182 break;
183 case kPulsePedestal:
184 // Retrieve pedestal, if available
185 if( FDAT.fPedq == 0 ) {
186 Data_t p = val.value();
187 if( fConfig.tflag ) {
188 p *= static_cast<Data_t>(fConfig.nsa + fConfig.nsb) / fConfig.nped;
189 } else {
190 p *= static_cast<Data_t>(fConfig.win) / fConfig.nped;
191 }
192 FDAT.fPedestal = p;
193 }
194 break;
195 default:
196 assert(false); // Not reached
197 }
198 }
199 fHitDone = true;
200 return 0;
201}
202
203//_____________________________________________________________________________
205 const char* key_prefix,
206 const char* comment_subst )
207{
208 // Export FADCData results as global variables
209
210 const char* const here = "FADCData::DefineVariables";
211
212 // Define variables of the base class, if any.
213 Int_t ret = DetectorData::DefineVariablesImpl(mode, key_prefix, comment_subst);
214 if( ret )
215 return ret;
216
217 const RVarDef vars[] = {
218 { "peak", "FADC ADC peak values %s", "fFADCData.fPeak" },
219 { "t_fadc", "FADC TDC values %s", "fFADCData.fT" },
220 { "tc_fadc", "FADC Corrected times %s", "fFADCData.fT_c" },
221 { "overflow", "Overflow bit of FADC pulse %s", "fFADCData.fOverflow" },
222 { "underflow", "Underflow bit of FADC pulse %s", "fFADCData.fUnderflow" },
223 { "badped", "Pedestal quality bit of FADC pulse %s", "fFADCData.fPedq" },
224 { nullptr }
225 };
226 return StdDefineVariables(vars, mode, key_prefix, here, comment_subst);
227}
228
229//_____________________________________________________________________________
230
231} // namespace HallA
232
int Int_t
unsigned int UInt_t
Double_t Data_t
Definition DataType.h:13
#define MKFADCDATA(name, title, nelem)
Definition FADCData.cxx:23
const UInt_t kMaxUInt
const char Option_t
winID h TVirtualViewer3D TVirtualGLPainter p
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
static const char *const here
Definition THaVar.cxx:64
virtual UInt_t GetData(Decoder::EModuleType mtype, UInt_t chan, UInt_t ievent) const
virtual UInt_t GetNumEvents(Decoder::EModuleType mtype, UInt_t ichan) const
virtual Bool_t HasCapability(Decoder::EModuleType type)
Int_t StoreHit(const DigitizerHitInfo_t &hitinfo, UInt_t data) override
Definition FADCData.cxx:138
Int_t ReadConfig(FILE *file, const TDatime &date, const char *prefix)
Definition FADCData.cxx:88
FADCConfig_t fConfig
Definition FADCData.h:90
static OptUInt_t LoadFADCData(const DigitizerHitInfo_t &hitinfo)
Definition FADCData.cxx:125
void Clear(Option_t *="") override
Definition FADCData.cxx:67
void Reset(Option_t *="") override
Definition FADCData.cxx:79
std::vector< FADCData_t > fFADCData
Definition FADCData.h:93
FADCData(const char *name, const char *desc, Int_t nelem)
Definition FADCData.cxx:60
Int_t DefineVariablesImpl(THaAnalysisObject::EMode mode=THaAnalysisObject::kDefine, const char *key_prefix="", const char *comment_subst="") override
Definition FADCData.cxx:204
virtual Int_t GetLogicalChannel(const DigitizerHitInfo_t &hitinfo) const
static std::string msg(const DigitizerHitInfo_t &hitinfo, const char *txt)
Int_t StdDefineVariables(const RVarDef *vars, THaAnalysisObject::EMode mode, const char *key_prefix, const char *here, const char *comment_subst)
static Int_t LoadDB(FILE *file, const TDatime &date, const DBRequest *request, const char *prefix, Int_t search=0, const char *here="THaAnalysisObject::LoadDB")
const char * GetPrefix() const
TString GetPrefixName() const
virtual FILE * OpenFile(const TDatime &date)
Decoder::Module *Decoder::ChannelType type
Definition THaDetMap.h:197
Int_t GetNelem() const
const char * GetTitle() const override
constexpr T const & value() const
Definition optional.hpp:569
EModuleType
Definition Decoder.h:57
@ kPulseTime
Definition Decoder.h:57
@ kPulsePedestal
Definition Decoder.h:58
@ kPulsePeak
Definition Decoder.h:58
@ kPulseIntegral
Definition Decoder.h:57
pair< unique_ptr< FADCData >, Int_t > MakeFADCData(const TDatime &date, THaDetectorBase *det)
Definition FADCData.cxx:27
static OptUInt_t GetFADCValue(EModuleType type, const DigitizerHitInfo_t &hitinfo, Fadc250Module *fadc)
Definition FADCData.cxx:109
STL namespace.
ClassImp(TPyArg)