1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appear in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz, 2016 <mailto:tbretz@physik.rwth-aachen.de>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2016
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | //////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MSoftwareTrigger
|
---|
28 | //
|
---|
29 | //////////////////////////////////////////////////////////////////////////////
|
---|
30 | #include "MSoftwareTrigger.h"
|
---|
31 |
|
---|
32 | #include <algorithm>
|
---|
33 |
|
---|
34 | #include "MLog.h"
|
---|
35 | #include "MLogManip.h"
|
---|
36 |
|
---|
37 | #include "MParList.h"
|
---|
38 |
|
---|
39 | #include "MParameters.h"
|
---|
40 | #include "MRawEvtData.h"
|
---|
41 | #include "MPedestalSubtractedEvt.h"
|
---|
42 |
|
---|
43 | ClassImp(MSoftwareTrigger);
|
---|
44 |
|
---|
45 | using namespace std;
|
---|
46 |
|
---|
47 | // --------------------------------------------------------------------------
|
---|
48 | //
|
---|
49 | // Default constructor.
|
---|
50 | //
|
---|
51 | MSoftwareTrigger::MSoftwareTrigger(const char *name, const char *title)
|
---|
52 | : fRawEvt(0), fSignal(0), fTriggerSignal(0), fTriggerBaseline(0)
|
---|
53 | {
|
---|
54 | fName = name ? name : "MSoftwareTrigger";
|
---|
55 | fTitle = title ? title : "Calculate the FACT trigger in software";
|
---|
56 | }
|
---|
57 |
|
---|
58 | // --------------------------------------------------------------------------
|
---|
59 | //
|
---|
60 | Int_t MSoftwareTrigger::PreProcess(MParList *pList)
|
---|
61 | {
|
---|
62 | fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");//, AddSerialNumber(fNamePedestalSubtractedEvt));
|
---|
63 | if (!fRawEvt)
|
---|
64 | {
|
---|
65 | *fLog << err << "MRawEvtData not found... aborting." << endl;
|
---|
66 | return kFALSE;
|
---|
67 | }
|
---|
68 |
|
---|
69 | fSignal = (MPedestalSubtractedEvt*)pList->FindObject("MPedestalSubtractedEvt");//, AddSerialNumber(fNamePedestalSubtractedEvt));
|
---|
70 | if (!fSignal)
|
---|
71 | {
|
---|
72 | *fLog << err << "MPedestalSubtractedEvt not found... aborting." << endl;
|
---|
73 | return kFALSE;
|
---|
74 | }
|
---|
75 |
|
---|
76 | fTriggerSignal = (MParameterD*)pList->FindCreateObj("MParameterD","SoftwareTriggerSignal");
|
---|
77 | if (!fTriggerSignal)
|
---|
78 | return kFALSE;
|
---|
79 |
|
---|
80 | fTriggerBaseline = (MParameterD*)pList->FindCreateObj("MParameterD","SoftwareTriggerBaseline");
|
---|
81 | if (!fTriggerBaseline)
|
---|
82 | return kFALSE;
|
---|
83 |
|
---|
84 | *fLog << flush << inf;
|
---|
85 | return kTRUE;
|
---|
86 | }
|
---|
87 |
|
---|
88 | // --------------------------------------------------------------------------
|
---|
89 | //
|
---|
90 | Bool_t MSoftwareTrigger::ReInit(MParList *pList)
|
---|
91 | {
|
---|
92 | // FIXME: Check number of samples!
|
---|
93 | return kTRUE;
|
---|
94 | }
|
---|
95 |
|
---|
96 | // --------------------------------------------------------------------------
|
---|
97 | //
|
---|
98 | Int_t MSoftwareTrigger::Process()
|
---|
99 | {
|
---|
100 | const UShort_t *idx = fRawEvt->GetPixelIds();
|
---|
101 |
|
---|
102 | const int beg = 10;
|
---|
103 | const int end = std::min(UInt_t(200), fSignal->GetNumSamples());
|
---|
104 | const int num = end-beg;
|
---|
105 |
|
---|
106 | MArrayF buf(160*num);
|
---|
107 |
|
---|
108 | double avg = 0;
|
---|
109 |
|
---|
110 | for (int hw=0; hw<1440; hw++)
|
---|
111 | {
|
---|
112 | // dead pixels
|
---|
113 | if (hw==927 || hw==80 || hw==873) // 3
|
---|
114 | continue;
|
---|
115 | // crazy pixels
|
---|
116 | if (hw==863 || hw==297 || hw==868) // 3
|
---|
117 | continue;
|
---|
118 | // broken DRS board
|
---|
119 | if (hw>=720 && hw<=728) // 9
|
---|
120 | continue;
|
---|
121 | // broken/suspicious bias channels
|
---|
122 | if ((hw>=171 && hw<=174) || (hw>=184 && hw<=188)) // 9
|
---|
123 | continue;
|
---|
124 |
|
---|
125 | const Float_t *raw = fSignal->GetSamples(idx[hw]);
|
---|
126 |
|
---|
127 | Float_t *sum = buf.GetArray()+(hw/9)*num;
|
---|
128 |
|
---|
129 | // Sum all nine pixel of one trigger patch
|
---|
130 | for (const Float_t *ptr=raw+beg; ptr<raw+end; ptr++, sum++)
|
---|
131 | *sum += *ptr;
|
---|
132 | }
|
---|
133 |
|
---|
134 | // apply correction factor for patches
|
---|
135 | // 927/9, 80/9, 873/9, 863/9, 297/9, 868/9
|
---|
136 | /*
|
---|
137 | const int excl[] = { 8, 33, 95, 96, 97, 103, -1};
|
---|
138 | for (const int *e=excl; *e>=0; e++)
|
---|
139 | {
|
---|
140 | Float_t *raw = buf.GetArray() + *e * num;
|
---|
141 | for (Float_t *ptr=raw; ptr<raw+num; ptr++)
|
---|
142 | *ptr *= 1.125; // 9/8
|
---|
143 | }
|
---|
144 | {
|
---|
145 | Float_t *raw = buf.GetArray() + 19 * num; // 171-174
|
---|
146 | for (Float_t *ptr=raw; ptr<raw+num; ptr++)
|
---|
147 | *ptr *= 1.8; // 9/5 // 5 channels left
|
---|
148 | }
|
---|
149 | {
|
---|
150 | Float_t *raw = buf.GetArray() + 20 * num; // 184-188
|
---|
151 | for (Float_t *ptr=raw; ptr<raw+num; ptr++)
|
---|
152 | *ptr *= 2.25; // 9/4 // 4 channels left
|
---|
153 | }
|
---|
154 | */
|
---|
155 |
|
---|
156 | Float_t max = -50000;
|
---|
157 |
|
---|
158 | const UInt_t nsum = buf.GetSize();
|
---|
159 | for (Float_t *sum=buf.GetArray(); sum<buf.GetArray()+nsum; sum+=num)
|
---|
160 | {
|
---|
161 | int idx = 0;
|
---|
162 | Float_t v[4] = { 0, 0, 0, 0 };
|
---|
163 |
|
---|
164 | for (Float_t *ptr=sum+15; ptr<sum+num; ptr++)
|
---|
165 | {
|
---|
166 | ptr[0] -= 0.5*ptr[-15];
|
---|
167 |
|
---|
168 | avg += ptr[0];
|
---|
169 | v[idx++%4] = ptr[0];
|
---|
170 |
|
---|
171 | const Float_t min = *std::min_element(v, v+4);
|
---|
172 | if (min>max)
|
---|
173 | max = min;
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | // Question: Should we also keep position and patch id?
|
---|
178 |
|
---|
179 | avg /= (num-15)*(1440-24);
|
---|
180 |
|
---|
181 | fTriggerSignal->SetVal(max);
|
---|
182 | fTriggerSignal->SetReadyToSave();
|
---|
183 |
|
---|
184 | fTriggerBaseline->SetVal(avg);
|
---|
185 | fTriggerBaseline->SetReadyToSave();
|
---|
186 |
|
---|
187 | return kTRUE;
|
---|
188 | }
|
---|
189 |
|
---|
190 | // --------------------------------------------------------------------------
|
---|
191 | //
|
---|
192 | Int_t MSoftwareTrigger::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
|
---|
193 | {
|
---|
194 | return kTRUE;
|
---|
195 | }
|
---|
196 |
|
---|