stream  0.10.0
stream analysis framework
SpillProcessor.h
1 #ifndef HADAQ_SPILLPROCESSOR_H
2 #define HADAQ_SPILLPROCESSOR_H
3 
4 #include "base/StreamProc.h"
5 
6 namespace hadaq {
7 
11 
12 protected:
13  base::H1handle fEvType;
14  base::H1handle fEvSize;
15  base::H1handle fSubevSize;
16 
17  base::H1handle fHitsFast;
18  base::H1handle fHitsSlow;
19  base::H1handle fQualitySlow;
20  base::H1handle fTrendXSlow;
21  base::H1handle fTrendYSlow;
22 
23  base::H1handle fHitsSpill;
24  base::H1handle fHitsLastSpill;
25 
26  base::H1handle fTrendXHaloSlow;
27  base::H1handle fTrendYHaloSlow;
28 
29  base::H1handle fTriggerFast;
30  base::H1handle fTriggerSlow;
31 
32  base::H1handle fSpill;
33  base::H1handle fLastSpill;
34 
35  base::H1handle fBeamX;
36  base::H1handle fBeamY;
37 
38  base::H1handle fTrendX;
39  base::H1handle fTrendY;
40 
41  base::H2handle fHaloPattern;
42  base::H2handle fVetoPattern;
43 
44  long fSumX;
45  long fCntX;
46  long fSumY;
47  long fCntY;
48  long fSumHaloX;
49  long fCntHaloX;
50  long fSumHaloY;
51  long fCntHaloY;
52  unsigned fCurrXYBin;
53  double fLastX;
54  double fLastY;
55  double fLastHaloX;
56  double fLastHaloY;
57 
58  unsigned fLastBinFast;
59  unsigned fLastBinSlow;
60  unsigned fLastEpoch;
61  unsigned fLastSpillEpoch;
62  unsigned fLastSpillBin;
64 
65  bool fFirstEpoch;
66 
67  double fSpillOnLevel;
68  double fSpillOffLevel;
69  unsigned fSpillMinCnt;
70 
71  unsigned fSpillStartEpoch;
72  unsigned fSpillEndEpoch;
73  unsigned fSpillStartCoarse;
74 
75  double fMinSpillLength;
76  double fMaxSpillLength;
77 
78  unsigned fTdcMin;
79  unsigned fTdcMax;
80 
81  unsigned fChannelsLookup1[33];
82  unsigned fChannelsLookup2[33];
83  unsigned fChannelsLookup3[33];
84 
85  double fLastQSlowValue;
86 
87  int CompareHistBins(unsigned leftbin, unsigned rightbin);
88 
90  inline unsigned EpochDiff(unsigned ep1, unsigned ep2) { return ep1 <= ep2 ? ep2 - ep1 : ep2 + 0x10000000 - ep1; }
91 
93  inline unsigned Get1msBin(unsigned ep1, unsigned c1, unsigned ep2, unsigned c2)
94  {
95  unsigned ediff = EpochDiff(ep1,ep2) * 2048 + c2 - c1; // 5ns
96  return ediff / 200000;
97  }
98 
99  double EpochTmDiff(unsigned ep1, unsigned ep2);
100 
101  void StartSpill(unsigned epoch, unsigned coarse = 0);
102  void StopSpill(unsigned epoch);
103 
104  double CalcQuality(unsigned firstbin, unsigned len);
105 
106 public:
107  SpillProcessor();
108  virtual ~SpillProcessor();
109 
110  virtual bool FirstBufferScan(const base::Buffer &buf);
111 
113  void SetTdcRange(unsigned min, unsigned max)
114  {
115  fTdcMin = min;
116  fTdcMax = max;
117  }
118 
120  void SetSpillDetect(double lvl_on, double lvl_off, unsigned cnt = 3)
121  {
122  fSpillOnLevel = lvl_on;
123  fSpillOffLevel = lvl_off;
124  fSpillMinCnt = cnt;
125  }
126 
128  void SetMinSpillLength(double tm = 0.1) { fMinSpillLength = tm; }
130  void SetMaxSpillLength(double tm = 10) { fMaxSpillLength = tm; }
131 
133  void SetChannelsLookup1(unsigned ch, unsigned lookup) { fChannelsLookup1[ch] = lookup; }
135  void SetChannelsLookup2(unsigned ch, unsigned lookup) { fChannelsLookup2[ch] = lookup; }
137  void SetChannelsLookup3(unsigned ch, unsigned lookup) { fChannelsLookup3[ch] = lookup; }
138 
140  void SetSpillChannel(unsigned ch)
141  {
142  SetChannelsLookup3(ch, 401);
143  fAutoSpillDetect = false;
144  }
145 
147  void SetTriggerChannel(unsigned ch)
148  {
149  SetChannelsLookup3(ch, 402);
150  }
151 
152 };
153 }
154 
155 #endif
Memory management class.
Definition: Buffer.h:49
Abstract processor of data streams.
Definition: StreamProc.h:21
This is specialized process for spill structures
Definition: SpillProcessor.h:10
long fSumY
sum y
Definition: SpillProcessor.h:46
void SetMinSpillLength(double tm=0.1)
Set min spill length.
Definition: SpillProcessor.h:128
unsigned fTdcMin
minimal TDC id
Definition: SpillProcessor.h:78
unsigned fSpillStartEpoch
epoch value which assumed to be spill start, 0 - off
Definition: SpillProcessor.h:71
void StartSpill(unsigned epoch, unsigned coarse=0)
start spill
Definition: SpillProcessor.cxx:159
base::H1handle fTrendX
Beam X trending.
Definition: SpillProcessor.h:38
double fLastHaloX
last halo x
Definition: SpillProcessor.h:55
base::H1handle fTrendXSlow
Beam X with Quality histogram (with 40 ms binning)
Definition: SpillProcessor.h:20
base::H2handle fVetoPattern
2dim Veto detector Pattern
Definition: SpillProcessor.h:42
virtual bool FirstBufferScan(const base::Buffer &buf)
buffer scan
Definition: SpillProcessor.cxx:219
base::H1handle fTrendYHaloSlow
Quality histogram (with 40 ms binning)
Definition: SpillProcessor.h:27
long fCntX
cnt x
Definition: SpillProcessor.h:45
double fLastY
last y
Definition: SpillProcessor.h:54
double CalcQuality(unsigned firstbin, unsigned len)
calculate quality
Definition: SpillProcessor.cxx:200
long fCntHaloY
counter halo y
Definition: SpillProcessor.h:51
base::H1handle fHitsSpill
Hits in current spill (with 1 ms binning)
Definition: SpillProcessor.h:23
void SetChannelsLookup1(unsigned ch, unsigned lookup)
Set channel lookup 1.
Definition: SpillProcessor.h:133
unsigned fLastEpoch
last epoch
Definition: SpillProcessor.h:60
unsigned fChannelsLookup1[33]
first tdc
Definition: SpillProcessor.h:81
bool fAutoSpillDetect
true when spill will be detected automatically
Definition: SpillProcessor.h:63
base::H1handle fHitsLastSpill
Hits in last spill (with 1 ms binning)
Definition: SpillProcessor.h:24
long fSumX
sum x
Definition: SpillProcessor.h:44
unsigned fTdcMax
maximal TDC id
Definition: SpillProcessor.h:79
unsigned fLastSpillBin
last bin number filled in the histogram
Definition: SpillProcessor.h:62
long fCntY
cnt y
Definition: SpillProcessor.h:47
double fSpillOffLevel
number of hits in 40ms bin to detect spill off (at least N bins below limit)
Definition: SpillProcessor.h:68
int CompareHistBins(unsigned leftbin, unsigned rightbin)
returns -1 when leftbin<rightbin, taking into account overflow around 0x1000) +1 when leftbin>rightbi...
Definition: SpillProcessor.cxx:138
SpillProcessor()
constructor
Definition: SpillProcessor.cxx:27
double fLastX
last x
Definition: SpillProcessor.h:53
base::H1handle fEvSize
HADAQ event size.
Definition: SpillProcessor.h:14
bool fFirstEpoch
first epoch
Definition: SpillProcessor.h:65
double EpochTmDiff(unsigned ep1, unsigned ep2)
Return time difference between epochs in seconds.
Definition: SpillProcessor.cxx:151
unsigned fSpillMinCnt
minimal number of counts to detect spill
Definition: SpillProcessor.h:69
base::H1handle fTriggerFast
Quality histogram (with 20 us binning)
Definition: SpillProcessor.h:29
unsigned fLastSpillEpoch
last epoch used to calculate spill quality
Definition: SpillProcessor.h:61
base::H1handle fEvType
HADAQ event type.
Definition: SpillProcessor.h:13
void SetTriggerChannel(unsigned ch)
Set special channel with trigger info.
Definition: SpillProcessor.h:147
base::H1handle fSubevSize
HADAQ sub-event size.
Definition: SpillProcessor.h:15
double fMaxSpillLength
maximal spill time in seconds
Definition: SpillProcessor.h:76
unsigned fLastBinFast
last bin fast
Definition: SpillProcessor.h:58
long fSumHaloX
sum halo x
Definition: SpillProcessor.h:48
base::H1handle fHitsFast
Hits fast (with 20 us binning)
Definition: SpillProcessor.h:17
unsigned fLastBinSlow
last bin slow
Definition: SpillProcessor.h:59
base::H2handle fHaloPattern
2dim Halo detector Pattern
Definition: SpillProcessor.h:41
base::H1handle fLastSpill
Last SPILL histogram.
Definition: SpillProcessor.h:33
long fSumHaloY
sum halo y
Definition: SpillProcessor.h:50
base::H1handle fQualitySlow
Quality histogram (with 40 ms binning)
Definition: SpillProcessor.h:19
base::H1handle fBeamX
Accumulated X position.
Definition: SpillProcessor.h:35
unsigned EpochDiff(unsigned ep1, unsigned ep2)
Hard difference between epochs.
Definition: SpillProcessor.h:90
unsigned fChannelsLookup2[33]
second tdc
Definition: SpillProcessor.h:82
long fCntHaloX
counter halo x
Definition: SpillProcessor.h:49
base::H1handle fTrendXHaloSlow
Quality histogram (with 40 ms binning)
Definition: SpillProcessor.h:26
base::H1handle fSpill
Current SPILL histogram.
Definition: SpillProcessor.h:32
unsigned fChannelsLookup3[33]
third tdc
Definition: SpillProcessor.h:83
void SetChannelsLookup2(unsigned ch, unsigned lookup)
Set channel lookup 2.
Definition: SpillProcessor.h:135
double fMinSpillLength
minimal spill time in seconds
Definition: SpillProcessor.h:75
unsigned fSpillEndEpoch
epoch value when switch off spill
Definition: SpillProcessor.h:72
void SetTdcRange(unsigned min, unsigned max)
Set TDC range.
Definition: SpillProcessor.h:113
double fSpillOnLevel
number of hits in 40ms bin to detect spill on (at least N bins after each other over limit)
Definition: SpillProcessor.h:67
unsigned fCurrXYBin
bin where current XY is calculated
Definition: SpillProcessor.h:52
base::H1handle fTriggerSlow
Quality histogram (with 40 ms binning)
Definition: SpillProcessor.h:30
base::H1handle fHitsSlow
Hits slow (with 40 ms binning)
Definition: SpillProcessor.h:18
void SetSpillChannel(unsigned ch)
Set channel id on third TDC, which should detect spill-start signal.
Definition: SpillProcessor.h:140
base::H1handle fTrendYSlow
Quality histogram (with 40 ms binning)
Definition: SpillProcessor.h:21
void SetChannelsLookup3(unsigned ch, unsigned lookup)
Set channel lookup 3.
Definition: SpillProcessor.h:137
double fLastQSlowValue
last value of Q factor for slow histogram
Definition: SpillProcessor.h:85
base::H1handle fBeamY
Accumulated Y position.
Definition: SpillProcessor.h:36
double fLastHaloY
last halo y
Definition: SpillProcessor.h:56
base::H1handle fTrendY
Beam Y trending.
Definition: SpillProcessor.h:39
void SetMaxSpillLength(double tm=10)
Set max spill length.
Definition: SpillProcessor.h:130
unsigned fSpillStartCoarse
spill start coarse
Definition: SpillProcessor.h:73
void StopSpill(unsigned epoch)
stop spill
Definition: SpillProcessor.cxx:183
void SetSpillDetect(double lvl_on, double lvl_off, unsigned cnt=3)
Set spill detect.
Definition: SpillProcessor.h:120
unsigned Get1msBin(unsigned ep1, unsigned c1, unsigned ep2, unsigned c2)
Get 1ms bin.
Definition: SpillProcessor.h:93