-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathSBSGenericDetector.h
290 lines (247 loc) · 10.7 KB
/
SBSGenericDetector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#ifndef SBSGenericDetector_h
#define SBSGenericDetector_h
////////////////////////////////////////////////////////////////////////////////
//
//SBSGenericDetector
//
// A generic detector class which could contain the following types
// of data:
// - ADC
// - Can be single valued OR
// - Can contain pulse information such as integral, amplitude and time
// - Can be using Waveform data
// - TDC
// - Can be single valued (leading edge) OR:
// - Can contain both leading and trailing edge and Time-Over-Threshold
//
// Organized into row, col, and layer structure (but makes no assumption about
// number of rows, cols or layers are constant throughout).
//
////////////////////////////////////////////////////////////////////////////////
#include "THaNonTrackingDetector.h"
#include "TRotation.h"
#include "TVector3.h"
#include "THaDetMap.h"
#include "SBSElement.h"
#include "Helper.h"
#include "TH1D.h"
#include "THaRunBase.h"
namespace SBSModeADC {
enum Mode{
kNone,
kADC, //< Contains pulse information also
kADCSimple, //< Does not contain pulse information (nor reference info)
kWaveform, //< Contains waveform data
};
}
namespace SBSModeTDC {
enum Mode{
kNone,
kIgnore, //< Useful to preserve DB but ignore ADCs otherwise
kTDC, //< Includes Trailing edge (and ToT)
kTDCSimple, //< Does not contain trailing edge, and hence no ToT info
};
}
// structure for sorting TDC hits
struct TDCHits {
UInt_t edge;
UInt_t rawtime;
};
// This structure has output data when the user wants every hit to be stored
// in the rootfile.
struct SBSGenericOutputData {
// Note [] means it can be variable sized data per event/module
// Module info
std::vector<Int_t> TDCrow; //< [] row
std::vector<Int_t> TDCcol; //< [] col
std::vector<Int_t> TDClayer; //< [] layer
std::vector<Int_t> TDCelemID; //< [] element ID
std::vector<Int_t> ADCrow; //< [] row
std::vector<Int_t> ADCcol; //< [] col
std::vector<Int_t> ADClayer; //< [] layer
std::vector<Int_t> ADCelemID; //< [] element ID
std::vector<Double_t> ADCxpos; //< [] x-position (m)
std::vector<Double_t> ADCypos; //< [] y-position (m)
// ADC variables
std::vector<Int_t> ped; //< [] pedestal
std::vector<Int_t> a_mult; //< [] ADC # of hits per channel
std::vector<Double_t> a; //< [] ADC integral
std::vector<Double_t> a_p; //< [] ADC integral -pedestal
std::vector<Double_t> a_c; //< [] (ADC integral -pedestal)*calib
std::vector<Double_t> a_amp; //< [] ADC pulse amplitude
std::vector<Double_t> a_amp_p; //< [] ADC pulse amplitude -pedestal
std::vector<Double_t> a_amp_c; //< [] ADC pulse amplitude -pedestal
std::vector<Double_t> a_amptrig_p; //< [] ADC pulse amplitude -pedestal
std::vector<Double_t> a_amptrig_c; //< [] ADC pulse amplitude -pedestal
std::vector<Double_t> a_time; //< [] ADC pulse time
// TDC variables
std::vector<Int_t> t_mult; //< [] TDC # of hits per channel
std::vector<Double_t> t; //< [] TDC (leading edge) time
std::vector<Double_t> t_te; //< [] TDC trailing edge time
std::vector<Double_t> t_ToT; //< [] TDC Time-Over-Threshold
// Waveform variables
std::vector<Int_t> samps_elemID; //< [] Element ID of samples
std::vector<Int_t> nsamps; //< [] Number of ADC samples
std::vector<Int_t> sidx; //< [] Index of start of ADC samples in for this row-col-layer
std::vector<Double_t> samps; //< []*nsamps ADC samples
// Quick clear class
void clear() {
TDCrow.clear();
TDCcol.clear();
TDCelemID.clear();
TDClayer.clear();
ADCrow.clear();
ADCcol.clear();
ADCelemID.clear();
ADClayer.clear();
ADCxpos.clear();
ADCypos.clear();
ped.clear();
a_mult.clear();
a.clear();
a_p.clear();
a_c.clear();
a_amp.clear();
a_amp_p.clear();
a_amp_c.clear();
a_amptrig_p.clear();
a_amptrig_c.clear();
a_time.clear();
t.clear();
t_mult.clear();
t_te.clear();
t_ToT.clear();
nsamps.clear();
sidx.clear();
samps.clear();
samps_elemID.clear();
}
};
class SBSGenericDetector : public THaNonTrackingDetector {
//class SBSGenericDetector : public THaShower {
public:
explicit SBSGenericDetector( const char* name, const char* description = "",
THaApparatus* a = nullptr);
virtual ~SBSGenericDetector();
virtual void Clear( Option_t* opt="" );
void SetModeADC(SBSModeADC::Mode mode);
void SetModeTDC(SBSModeTDC::Mode mode) { fModeTDC = mode; }
void SetDisableRefADC(Bool_t b) { fDisableRefADC = b; }
void SetDisableRefTDC(Bool_t b) { fDisableRefTDC = b; }
void SetStoreRawHits(Bool_t var) { fStoreRawHits = var; }
void SetStoreEmptyElements(Bool_t b) { fStoreEmptyElements = b; }
Bool_t WithTDC() { return fModeTDC != SBSModeTDC::kNone; };
Bool_t WithADC() { return fModeADC != SBSModeADC::kNone; };
//Let's add Begin and End methods to accumulate some useful hard-coded diagnostic histograms
virtual Int_t Begin( THaRunBase* r=0 );
virtual Int_t End( THaRunBase* r=0 );
// Standard apparatus re-implemented functions
virtual Int_t Decode( const THaEvData& );
virtual Int_t CoarseProcess(TClonesArray& tracks);
virtual Int_t FineProcess(TClonesArray& tracks);
virtual Int_t DecodeADC( const THaEvData&, SBSElement *blk,
THaDetMap::Module *d, Int_t chan, Bool_t IsRef);
virtual Int_t DecodeTDC( const THaEvData&, SBSElement *blk,
THaDetMap::Module *d, Int_t chan, Bool_t IsRef);
// Utility functions
// Can be re-implemented by other classes to specify a different
// SBSElement sub-class (i.e. useful when one wants to chang the logic
// in SBSElement::CoarseProcess()
virtual SBSElement* MakeElement(Double_t x, Double_t y, Double_t z, Int_t row,
Int_t col, Int_t layer, Int_t id = 0);
Double_t SizeRow() const { return fSizeRow; };
Double_t SizeCol() const { return fSizeCol; };
Double_t GetRFtime() const { return fRFtime; };
Double_t GetTrigTime() const { return fTrigTime; };
void DecodeRFandTriggerTime( const THaEvData & );
protected:
virtual Int_t ReadDatabase( const TDatime& date );
virtual Int_t DefineVariables( EMode mode = kDefine );
virtual Int_t FindGoodHit(SBSElement *); //
// Configuration
Int_t fNRefElem; ///< Number of Ref Time elements
Int_t fNrows; ///< Number of rows
std::vector<Int_t> fNcols; ///< Number of columns per row
Double_t fSizeRow;
Double_t fSizeCol;
Int_t fNcolsMax; ///< Max number of columns out of all rows
Int_t fNlayers; ///< Number of layers (in z-direction)
SBSModeADC::Mode fModeADC; //< ADC Mode
SBSModeTDC::Mode fModeTDC; //< TDC Mode
Bool_t fDisableRefADC; //< Reference ADC may be optionally disabled
Bool_t fDisableRefTDC; //< Reference TDC may be optionally disabled
Bool_t fStoreEmptyElements; //< Do not store data for empty elements in rootfile
Bool_t fIsMC; // flag to indicate if data are simulated;
Int_t fF1_RollOver;
Int_t fF1_TimeWindow;
// Mapping (see also fDetMap)
UShort_t fChanMapStart; ///< Starting number for element number (i.e. 0 or 1)
std::vector<std::vector<Int_t> > fChanMap; //< Maps modules in THaDetMap to element number: outer index = module, inner index = channel, value = element id?
std::vector<std::vector<Int_t> > fRefChanMap; //< Maps modules in THaDetMap to Reference time: outer index = module, inner index = channel, value = Ref element ID?
std::vector<Bool_t> fModuleRefTimeFlag; //< If module has Reftime set to true
std::vector<Int_t> fRefChanLo; //< Module Reftime Low channel number
std::vector<Int_t> fRefChanHi; //< Module Reftime High channel number
// Output variable containers
SBSGenericOutputData fGood; //< Good data output
SBSGenericOutputData fRaw; //< All hits
SBSGenericOutputData fRefGood; //< Good Ref time data output
SBSGenericOutputData fRefRaw; //< All Ref time hits
// Blocks, where the grid is just for easy access to the elements by row,col,layer
std::vector<SBSElement*> fElements;
std::vector<SBSElement*> fRefElements; //< Reference elements (for TDCs and multi-function ADCs)
std::vector<std::vector<std::vector<SBSElement*> > > fElementGrid;
// Clusters for this event
// Other parameters
Bool_t fCoarseProcessed; //< Was CourseProcessed already called?
Bool_t fFineProcessed; //< Was fine processed already called
//Gain correction
Double_t fConst; // const from gain correction
Double_t fSlope; // slope for gain correction
Double_t fAccCharge; // accumulated charge
// Per event data
Int_t fNhits; ///< Number of hits in event
Int_t fNRefhits; ///< Number of reference hits in event
Int_t fNGoodTDChits; ///< Number of good TDC hits in event
Int_t fNGoodADChits; ///< Number of good ADC hits in event
// New protected data members to hold trigger and RF time information;
// Here we are interested in the "main" physics trigger and assuming it is recorded by a TDC (we might add FADC trigger and/or RF time later but so far
// we have not recorded those signals in an FADC channel).
//Are we attempting to decode RF and trigger time for this detector?
Bool_t fDecodeRFtime;
Bool_t fDecodeTrigTime;
TH1D *hdTRF; //histogram to hold RF time differences (for TDC calibration purposes):
Double_t fRFtime; //Decoded accelerator RF time
Double_t fTrigTime; //Decoded "trigger" time (for copy of "main" trigger (usually either BigBite singles or coincidence))
Bool_t fRFtimeIsRef; // Flag for whether RF time is stored in a "reference" or "normal" channel
Bool_t fTrigTimeIsRef; // Flag for whether trigger time is stored in a "reference" or "normal" channel
Int_t fElemID_RFtime; //
Int_t fElemID_TrigTime; //
UInt_t fCrate_RFtime;
UInt_t fSlot_RFtime;
UInt_t fChan_RFtime;
UInt_t fCrate_TrigTime;
UInt_t fSlot_TrigTime;
UInt_t fChan_TrigTime;
// Flags for enabling and disabling various features
Bool_t fStoreRawHits; ///< Store the raw data in the root tree?
UInt_t fF1TDCminraw, fF1TDCmaxraw;
private:
void ClearOutputVariables();
ClassDef(SBSGenericDetector,0) //Generic shower detector class
};
/*inline Int_t SBSGenericDetector::blkidx(Int_t row, Int_t col, Int_t layer)
{
return fNlayers*(fNcols[row]*row + col) + layer;
}
inline void SBSGenericDetector::blkrcl(Int_t index, Int_t &row, Int_t &col,
Int_t &layer)
{
row = index/(fNlayers*fNcols);
index -= row*fNlayers*fNcols;
col = index/fNlayers;
layer = index%fNlayers;
}
*/
////////////////////////////////////////////////////////////////////////////////
// Specify some default sub-classes available to the user
#endif // SBSGenericDetector_h