1 |
|
---|
2 |
|
---|
3 | float getValue( int slice, int pixel,
|
---|
4 | vector<float> &drs_basemean,
|
---|
5 | vector<float> &drs_gainmean,
|
---|
6 | vector<float> &drs_triggeroffsetmean,
|
---|
7 | UInt_t RegionOfInterest,
|
---|
8 | vector<int16_t> AllPixelDataVector,
|
---|
9 | vector<int16_t> StartCellVector
|
---|
10 | ){
|
---|
11 | const float dconv = 2000/4096.0;
|
---|
12 |
|
---|
13 | float vraw, vcal;
|
---|
14 |
|
---|
15 | unsigned int pixel_pt;
|
---|
16 | unsigned int slice_pt;
|
---|
17 | unsigned int cal_pt;
|
---|
18 | unsigned int drs_cal_offset;
|
---|
19 |
|
---|
20 | // printf("pixel = %d, slice = %d\n", slice, pixel);
|
---|
21 |
|
---|
22 | pixel_pt = pixel * RegionOfInterest;
|
---|
23 | slice_pt = pixel_pt + slice;
|
---|
24 | drs_cal_offset = ( slice + StartCellVector[ pixel ] )%RegionOfInterest;
|
---|
25 | cal_pt = pixel_pt + drs_cal_offset;
|
---|
26 |
|
---|
27 | vraw = AllPixelDataVector[ slice_pt ] * dconv;
|
---|
28 | vcal = ( vraw - drs_basemean[ cal_pt ] - drs_triggeroffsetmean[ slice_pt ] ) / drs_gainmean[ cal_pt ]*1907.35;
|
---|
29 |
|
---|
30 | return( vcal );
|
---|
31 | }
|
---|
32 |
|
---|
33 | size_t applyDrsCalibration( vector<float> &destination,
|
---|
34 | int pixel,
|
---|
35 | int LeaveOutLeft,
|
---|
36 | int LeaveOutRight,
|
---|
37 | vector<float> &drs_basemean,
|
---|
38 | vector<float> &drs_gainmean,
|
---|
39 | vector<float> &drs_triggeroffsetmean,
|
---|
40 | UInt_t RegionOfInterest,
|
---|
41 | vector<int16_t> AllPixelDataVector,
|
---|
42 | vector<int16_t> StartCellVector
|
---|
43 | ){
|
---|
44 | // In order to minimize mem free and alloc actions
|
---|
45 | // the destination vector is only resized, if it is way too big
|
---|
46 | // or too small
|
---|
47 | size_t DestinationLength = RegionOfInterest-LeaveOutRight-LeaveOutLeft;
|
---|
48 | if ( destination.size() < DestinationLength || destination.size() > 2 * DestinationLength ){
|
---|
49 | destination.resize( DestinationLength );
|
---|
50 | }
|
---|
51 |
|
---|
52 | // the vector drs_triggeroffsetmean is not 1440 * 1024 entries long
|
---|
53 | // but has hopefully the length 1440 * RegionOfInterest (or longer)
|
---|
54 | if ( drs_triggeroffsetmean.size() < 1440*RegionOfInterest ){
|
---|
55 | return 0;
|
---|
56 | }
|
---|
57 |
|
---|
58 | // We do not entirely know how the calibration constants, which are saved in a filename.drs.fits file
|
---|
59 | // were calculated, so it is not fully clear how they should be applied to the raw data for calibration.
|
---|
60 | // apparently the calibration constants were transformed to the unit mV, which means we have to do the same to
|
---|
61 | // the raw data prior to apply the calibration
|
---|
62 | //
|
---|
63 | // on the FAD board, there is a 12bit ADC, with a 2.0V range, so the factor between ADC units and mV is
|
---|
64 | // ADC2mV = 2000/4096. = 0.48828125 (numerically exact)
|
---|
65 | //
|
---|
66 | // from the schematic of the FAD we learned, that the voltage at the ADC
|
---|
67 | // should be 1907.35 mV when the calibration DAC is set to 50000.
|
---|
68 | //
|
---|
69 | // One would further assume that the calibration constants are calculated like this:
|
---|
70 |
|
---|
71 | // The DRS Offset of each bin in each channel is the mean value in this very bin,
|
---|
72 | // obtained from so called DRS pedestal data
|
---|
73 | // Its value is about -1820 ADC units or -910mV
|
---|
74 |
|
---|
75 | // In order to obtain the DRS Gain of each bin of each channel
|
---|
76 | // again data is takes, with the calibration DAC set to 50000
|
---|
77 | // This is called DRS calibration data.
|
---|
78 | // We assume the DRS Offset is already subtracted from the DRS calibration data
|
---|
79 | // so the typical value is assumed to be ~3600 ADC units oder ~1800mV
|
---|
80 | // As mentioned before, the value *should* be 1907.35 mV
|
---|
81 | // So one might assume that the Gain is a number, which actually converts ~3600 ADC units into 1907.35mV for each bin of each channel.
|
---|
82 | // So that the calibration procedure looks like this
|
---|
83 | // TrueValue = (RawValue - Offset) * Gain
|
---|
84 | // The numerical value of Gain would differ slightly from the theoretical value of 2000/4096.
|
---|
85 | // But this is apparently not the case.
|
---|
86 | // The Gain, as it is stored in the DRS calibration file of FACT++ has numerical values
|
---|
87 | // around +1800.
|
---|
88 | // So it seems one should calibrate like this:
|
---|
89 | // TrueValue = (RawValue - Offset) / Gain * 1907.35
|
---|
90 |
|
---|
91 | // When these calibrations are done, one ends up with a quite nice calibrated voltage.
|
---|
92 | // But it turns out that, if one returns the first measurement, and calculates the mean voltages
|
---|
93 | // in each bin of the now *logical* DRS pipeline, the mean voltage is not zero, but slightly varies
|
---|
94 | // So one can store these systematical deviations from zero in the logical pipeline as well, and subtract them.
|
---|
95 | // The remaining question is, when to subtract them.
|
---|
96 | // I assume, in the process of measuring this third calibration constant, the first two
|
---|
97 | // calibrations are already applied to the raw data.
|
---|
98 |
|
---|
99 | // So the calculation of the calibrated volatage from some raw voltage works like this:
|
---|
100 | // assume the raw voltage is the s'th sample in channel c. While the Trigger made the DRS stopp in its t'th cell.
|
---|
101 | // note, that the DRS pipeline is always 1024 bins long. This is constant of the DRS4 chip.
|
---|
102 |
|
---|
103 | // TrueValue[c][s] = ( RawValue[c][s] - Offset[c][ (c+t)%1024 ] ) / Gain[c][ (c+t)%1024 ] * 1907.35 - TriggerOffset[c][s]
|
---|
104 |
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 | const float dconv = 2000/4096.0;
|
---|
109 | float vraw;
|
---|
110 | // float vcal;
|
---|
111 | // unsigned int pixel_pt;
|
---|
112 | // unsigned int slice_pt;
|
---|
113 | // unsigned int cal_pt;
|
---|
114 | // unsigned int drs_cal_offset;
|
---|
115 |
|
---|
116 | if ( RegionOfInterest != AllPixelDataVector.size()/1440 ){
|
---|
117 | cout << "RegionOfInterest != AllPixelDataVector.size()/1440 .. this makes no sense ... I guess ... aborting" << endl;
|
---|
118 | return 0;
|
---|
119 | }
|
---|
120 |
|
---|
121 | int Offset_offset = pixel * drs_basemean.size()/1440;
|
---|
122 | int Gain_offset = pixel * drs_gainmean.size()/1440;
|
---|
123 | int TriggerOffset_offset = pixel * drs_triggeroffsetmean.size()/1440;
|
---|
124 | int Data_offset = pixel * RegionOfInterest;
|
---|
125 |
|
---|
126 | for ( unsigned int sl = LeaveOutLeft; sl < RegionOfInterest-LeaveOutRight ; sl++){
|
---|
127 | vraw = AllPixelDataVector[ Data_offset + sl ] * dconv;
|
---|
128 | vraw -= drs_basemean[ Offset_offset + (sl + StartCellVector[pixel])%1024 ];
|
---|
129 | vraw /= drs_gainmean[ Gain_offset + (sl + StartCellVector[pixel])%1024 ];
|
---|
130 | vraw *= 1907.35;
|
---|
131 | vraw -= drs_triggeroffsetmean[ TriggerOffset_offset + sl ];
|
---|
132 |
|
---|
133 | // slice_pt = pixel_pt + sl;
|
---|
134 | // drs_cal_offset = ( sl + StartCellVector[ pixel ] ) % RegionOfInterest;
|
---|
135 | // cal_pt = pixel_pt + drs_cal_offset;
|
---|
136 | // vraw = AllPixelDataVector[ slice_pt ] * dconv;
|
---|
137 | // vcal = ( vraw - drs_basemean[ cal_pt ] - drs_triggeroffsetmean[ slice_pt ] ) / drs_gainmean[ cal_pt ]*1907.35;
|
---|
138 | // destination.push_back(vcal);
|
---|
139 |
|
---|
140 | destination[sl-LeaveOutLeft] = vraw;
|
---|
141 | }
|
---|
142 |
|
---|
143 | return destination.size();
|
---|
144 | }
|
---|