AlcapDAQ  1
MaxBinCFAPGenerator.cpp
Go to the documentation of this file.
1 #include "MaxBinCFAPGenerator.h"
2 #include "TPulseIsland.h"
3 #include "TAnalysedPulse.h"
5 
6 #include <algorithm>
7 #include <vector>
8 
9 // IsTimeOrdered()
10 // -- Returns tru of the first pulse is before the second
11 // Static so that only this file sees it
12 // Useful for sorting the pulses
14  // Want a to be before b
15  return ( a->GetTime() < b->GetTime() );
16 }
17 
18 MaxBinCFAPGenerator::MaxBinCFAPGenerator(double fraction) : fFraction(fraction) {}
19 
20 // Constant Fraction
21 // The time the pulse reaches some fraction of its height
22 // is recorded as the time of the pulse.
23 // Max Bin
24 // The height of the largest bin (pedestal subtracted and
25 // flipped according to its polarity) is considered the
26 // amplitude.
28  const PulseIslandList_t& pulseList,
29  AnalysedPulseList_t& analysedList){
30 
31  std::string bank = pulseList[0]->GetBankName();
32  int ped = gSetup->GetPedestal(bank);
33  int pol = gSetup->GetTriggerPolarity(bank);
34 
35  for (PulseIslandList_t::const_iterator iPulse = pulseList.begin(); iPulse != pulseList.end(); ++iPulse) {
36  std::vector<int> samples = (*iPulse)->GetSamples();
37  int t1 = 0; // Time tick right before crossing CF level
38  int t2 = 1; // Time tick right after crossing CF level
39  int tmax = 1; // Time tick of maximum value
40  int s1 = pol * (samples[t1] - ped); // Sample value right before crossing CF level
41  int s2 = pol * (samples[t2] - ped); // Sample value right after crossing CF level
42  int smax = s2; // Sample value at maximum
43  double cf = fFraction * (double)smax;
44  for (int iSample = 2; iSample < (int)samples.size(); ++iSample) {
45  if (pol * (samples[iSample] - ped) > smax) {
46  tmax = iSample;
47  smax = pol * (samples[tmax] - ped);
48  cf = fFraction * (double)smax;
49  while (s2 < (int)cf && s2 <= smax) {
50  ++t1; ++t2;
51  s1 = pol * (samples[t1] - ped); s2 = pol * (samples[t2] - ped);
52  }
53  }
54  }
55 
56  // Some sanity checks
57  if (s1 > (int)cf || s2 < (int)cf || s1 >= s2 || smax < 0)
58  std::cout << "MaxBinCFAPGenerator: Warning: Sanity check failed.." std::endl;
59 
60  // Linear interpolation of constant fraction time
61  // Then shift and scale by tick size
62  double t0 = gSetup->GetTimeShift(bank);
63  double dt = gSetup->GetClockTick(bank);
64  double t = (double)(t2 - t1) / (double)(s2 - s1) * (cf - (double)s1) + (double)t1; // Units of clock tick
65  t = t*dt + t0;
66 
67  // Add the pulse into the list
68  analysedList.push_back(new TAnalysedPulse((double)smax, t, 0., 0., gSetup->GetDetectorName(bank)));
69 
70  std::sort(analysedList.begin(), analysedList.end(), IsTimeOrdered);
71 
72 }