14 template<
class T>
inline T sqr(
T x){
return x*
x;}
46 double riseTime,
double fallTime,
52 exps[
t] = (
t >
t0) ?
exp(-(
t-t0)/fallTime)*(1-
exp(-(
t-t0)/riseTime)) : 0;
58 U = V = W = X = Z = 0;
66 const double norm = (W*U-V*
Z)/(U*U-X*V);
67 const double base = (W*X-Z*U)/(X*V-U*U);
71 exps[
n] = norm*exps[
n]+
base;
114 return (n < 32 ) ? (0x1 <<
n) : 0x0 ;
120 unsigned int mask = 0xffffffff;
121 mask = mask << (32 -
n);
122 mask = mask >> (32 -
n);
131 while(highBit_idx > 0){
132 if(
bitMask(highBit_idx) & input ){
143 unsigned int NBitInt2Float(
float _input,
int inputBits,
int outputBitsMantisa,
int outputBitsExpo){
145 unsigned int InputMask = 0;
146 unsigned int nBitIn = 0;
148 int mantisaShift = 0;
149 unsigned int expo = 0;
150 unsigned int fp_rep=0;
152 int input = (
int)_input;
164 if(input < (0
x1 << (outputBitsMantisa+1) )){
return (neg) ? 256-input: 256+input;}
172 nBitIn = input & InputMask;
177 if(highBit < 0){
return 0;}
182 mantisaShift = highBit - outputBitsMantisa;
187 if(mantisaShift > 0){
188 nBitIn = nBitIn >> mantisaShift;
193 nBitIn &=
nbitMask(outputBitsMantisa);
199 if(mantisaShift > 0){
200 expo = mantisaShift + 1;
206 expo = expo << outputBitsMantisa;
211 fp_rep = expo | nBitIn;
215 return (neg) ? 256 - fp_rep: 256 + fp_rep;
222 double riseTime,
double fallTime,
227 double bestchisq = 1e10;
242 if(norm < 0)
continue;
248 chisq +=
sqr(obs[
i]-exps[
i]);
251 if(chisq < bestchisq){
256 }
while(++offset != 0);
258 if(bestoffset == 0 || bestoffset == 255){
276 : fSampleTime (pset.
get< double > (
"SampleTime"))
277 , fRiseTime (pset.
get< double > (
"RiseTime"))
278 , fFallTime (pset.
get< double > (
"FallTime"))
279 , fUseMulti (pset.
get< bool > (
"UseMulti"))
280 , fUseMulti4ADC(pset.
get< bool > (
"UseMulti4ADC"))
281 , fDoHighADCFits(pset.
get< bool > (
"DoHighADCFits"))
309 TTree*
tr = (TTree*)
f.Get(
"shape_lookup");
312 const unsigned int N = tr->GetEntries();
318 tr->SetBranchAddress(
"offset", &offset);
319 tr->SetBranchAddress(
"good", &good);
321 tr->SetBranchAddress(
"adc", &adc);
323 for (
unsigned int n=0;
n<N;
n++){
337 int16_t
const& adc1, int16_t
const& adc2,
338 int16_t
const& adc3,
ADC& adcpeak,
339 bool& goodTime,
TDC& retval)
360 offset =
fTable[tableIdx];
361 goodTime =
fGood[tableIdx];
413 retval.
val = (high_time<<32 | (t0 + (uint64_t)(offset *
414 (kNumTDCPerSample * kSamplesPerOffset))));
415 retval.
frac = (uint8_t)(offset%2 * 50);
425 const unsigned int nSamples = conv.
getNSamples(version);
428 if ( (nSamples < 3) ||
429 (nSamples <= nPretrig) ||
436 uint32_t
t0 =
fNano->getTimeStamp();
438 int16_t adc1 = (int16_t)
fNano->getValue(1) - (int16_t)
fNano->getValue(0);
439 int16_t adc2 = (int16_t)
fNano->getValue(2) - (int16_t)
fNano->getValue(0);
440 int16_t adc3 = (int16_t)
fNano->getValue(3) - (int16_t)
fNano->getValue(0);
441 bool goodTime =
true;
442 process(t0, high_time, adc1, adc2, adc3, tempADC, goodTime, tempTDC);
444 if(adc3 < 0) adc3 = 0;
445 if(tempADC.
val < 0) tempADC = (
ADC)0;
453 int16_t
const& adc1, int16_t
const& adc2, int16_t
const& adc3,
463 bool goodTime =
true;
466 process(t0, high_time, adc1, adc2, adc3, tempADC, goodTime, tempTDC);
487 |
fNano->getTimeStamp();
490 int16_t adc3 = (int16_t)
fNano->getValue(3) - (int16_t)
fNano->getValue(0);
static const int kADC1Min
static const int kADC2Min
static const int kADC3Min
#define DEFINE_ART_SERVICE(svc)
Float_t x1[n_points_granero]
const double kSamplesPerOffset
const unsigned int kNumFineTimingADCPoints
unsigned int bitMask(unsigned int n)
int highestBit(unsigned int input)
GlobalSignal< detail::SignalResponseType::LIFO, void(Run const &)> sPostBeginRun
std::string find_file(std::string const &filename) const
const XML_Char int const XML_Char int const XML_Char * base
static const int kADC1RelMax
double GetExpectations(double t0, double riseTime, double fallTime, const int16_t *obs, double *exps)
Helper function for ADCShapeFit inner loop.
static const unsigned int kNumTableEntries
T get(std::string const &key) const
fvar< T > exp(const fvar< T > &x)
const double kZeroOffsetSamples
static const int kADC2Max
unsigned int NBitInt2Float(float _input, int inputBits, int outputBitsMantisa, int outputBitsExpo)
unsigned int nbitMask(unsigned int n)
assert(nhit_max >=nhit_nbins)
const unsigned int kNumTDCPerSample
static const int kADC3Max
uint8_t ADCShapeFit(int16_t adc1, int16_t adc2, int16_t adc3, double riseTime, double fallTime, bool &goodTime)