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): Nicola Galante 12/2004 <mailto:nicola.galante@pi.infn.it>
|
---|
19 | ! Author(s): Thomas Bretz 12/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: MAGIC Software Development, 2004-2008
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | //
|
---|
27 | // MFTriggerPattern
|
---|
28 | //
|
---|
29 | // A Filter for testing the trigger performance using Trigger Pattern.
|
---|
30 | //
|
---|
31 | // For files before file version 5 the trigger pattern is set to 00000000.
|
---|
32 | //
|
---|
33 | // For more details see: MTriggerPattern
|
---|
34 | //
|
---|
35 | //
|
---|
36 | // Input Containers:
|
---|
37 | // MTriggerPattern
|
---|
38 | //
|
---|
39 | //
|
---|
40 | /////////////////////////////////////////////////////////////////////////////
|
---|
41 | #include "MFTriggerPattern.h"
|
---|
42 |
|
---|
43 | #include "MLog.h"
|
---|
44 | #include "MLogManip.h"
|
---|
45 |
|
---|
46 | #include "MParList.h"
|
---|
47 | #include "MTriggerPattern.h"
|
---|
48 |
|
---|
49 | ClassImp(MFTriggerPattern);
|
---|
50 |
|
---|
51 | using namespace std;
|
---|
52 |
|
---|
53 | // --------------------------------------------------------------------------
|
---|
54 | //
|
---|
55 | // Default constructor. The default is to allow passing any trigger pattern.
|
---|
56 | //
|
---|
57 | MFTriggerPattern::MFTriggerPattern(const char *name, const char *title)
|
---|
58 | : fPattern(0), fMaskRequiredPrescaled(0), fMaskRequiredUnprescaled(0),
|
---|
59 | fMaskDeniedPrescaled(0), fMaskDeniedUnprescaled(0), fDefault(kTRUE)
|
---|
60 | {
|
---|
61 | fName = name ? name : "MFTriggerPattern";
|
---|
62 | fTitle = title ? title : "Filter on Trigger Pattern";
|
---|
63 | }
|
---|
64 |
|
---|
65 | // --------------------------------------------------------------------------
|
---|
66 | //
|
---|
67 | // Copy constructor
|
---|
68 | //
|
---|
69 | MFTriggerPattern::MFTriggerPattern(MFTriggerPattern &trigpatt)
|
---|
70 | : MFilter(trigpatt)
|
---|
71 | {
|
---|
72 | fMaskRequiredPrescaled = trigpatt.fMaskRequiredPrescaled;
|
---|
73 | fMaskRequiredUnprescaled = trigpatt.fMaskRequiredUnprescaled;
|
---|
74 |
|
---|
75 | fMaskDeniedPrescaled = trigpatt.fMaskDeniedPrescaled;
|
---|
76 | fMaskDeniedUnprescaled = trigpatt.fMaskDeniedUnprescaled;
|
---|
77 |
|
---|
78 | fDefault = trigpatt.fDefault;
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | // --------------------------------------------------------------------------
|
---|
83 | //
|
---|
84 | // Search for MTriggerPattern in the paremeter list.
|
---|
85 | //
|
---|
86 | Int_t MFTriggerPattern::PreProcess(MParList *pList)
|
---|
87 | {
|
---|
88 | fPattern = (MTriggerPattern*)pList->FindObject("MTriggerPattern");
|
---|
89 | if (!fPattern)
|
---|
90 | {
|
---|
91 | *fLog << err << "MTriggerPattern not found... abort." << endl;
|
---|
92 | return kFALSE;
|
---|
93 | }
|
---|
94 |
|
---|
95 | memset(fCounter, 0, sizeof(fCounter));
|
---|
96 |
|
---|
97 | return kTRUE;
|
---|
98 | }
|
---|
99 |
|
---|
100 | // --------------------------------------------------------------------------
|
---|
101 | //
|
---|
102 | // If Prescaled and Unprescaled pattern is 0 return default.
|
---|
103 | //
|
---|
104 | // If at least all bits in the fMaskRequired* mask are found in the
|
---|
105 | // trigger pattern set fResult to true. This means that is the required
|
---|
106 | // mask is 0 the dafult is changed from false to true.
|
---|
107 | //
|
---|
108 | // If any bit matches the fMasDenied* mask fResult is forced to be false.
|
---|
109 | //
|
---|
110 | Int_t MFTriggerPattern::Eval()
|
---|
111 | {
|
---|
112 | const Byte_t p = fPattern->GetPrescaled();
|
---|
113 | const Byte_t u = fPattern->GetUnprescaled();
|
---|
114 | if (p==0 && u==0)
|
---|
115 | {
|
---|
116 | fCounter[2]++;
|
---|
117 | return fDefault;
|
---|
118 | }
|
---|
119 |
|
---|
120 | Bool_t rc = kFALSE;
|
---|
121 |
|
---|
122 | // Check whether all the bits required are ON
|
---|
123 | if ( ((p & fMaskRequiredPrescaled) == fMaskRequiredPrescaled) &&
|
---|
124 | ((u & fMaskRequiredUnprescaled) == fMaskRequiredUnprescaled))
|
---|
125 | rc = kTRUE;
|
---|
126 |
|
---|
127 | // Now overwrite the result if one of the bits is denied
|
---|
128 | if ( (p & fMaskDeniedPrescaled) || (u & fMaskDeniedUnprescaled) )
|
---|
129 | {
|
---|
130 | fCounter[3]++;
|
---|
131 | return kFALSE;
|
---|
132 | }
|
---|
133 |
|
---|
134 | return rc;
|
---|
135 | }
|
---|
136 |
|
---|
137 | // --------------------------------------------------------------------------
|
---|
138 | //
|
---|
139 | // If Prescaled and Unprescaled pattern is 0 return default.
|
---|
140 | // If all bits of the fMaskRequired* mask are found in the pattern set
|
---|
141 | // fResult to true.
|
---|
142 | // If any bit matches the fMasDenied* mask fResult is forced to be false.
|
---|
143 | //
|
---|
144 | Int_t MFTriggerPattern::Process()
|
---|
145 | {
|
---|
146 | fResult = Eval();
|
---|
147 | fCounter[fResult ? 0 : 1]++;
|
---|
148 |
|
---|
149 | return kTRUE;
|
---|
150 | }
|
---|
151 |
|
---|
152 | // --------------------------------------------------------------------------
|
---|
153 | //
|
---|
154 | Int_t MFTriggerPattern::PostProcess()
|
---|
155 | {
|
---|
156 | const UInt_t n = GetNumExecutions();
|
---|
157 | if (n==0)
|
---|
158 | return kTRUE;
|
---|
159 |
|
---|
160 | *fLog << inf << endl;
|
---|
161 | *fLog << GetDescriptor() << " execution statistics:" << endl;
|
---|
162 | *fLog << dec << setfill(' ');
|
---|
163 |
|
---|
164 | *fLog << " " << setw(7) << fCounter[2] << " (" << setw(3);
|
---|
165 | *fLog << (int)(fCounter[2]*100/n);
|
---|
166 | *fLog << "%) Default (" << (fDefault?"true":"false") << ") returned." << endl;
|
---|
167 |
|
---|
168 | *fLog << " " << setw(7) << fCounter[3] << " (" << setw(3);
|
---|
169 | *fLog << (int)(fCounter[3]*100/n);
|
---|
170 | *fLog << "%) Trigger denied." << endl;
|
---|
171 |
|
---|
172 | *fLog << " " << setw(7) << fCounter[0] << " (" << setw(3);
|
---|
173 | *fLog << (int)(fCounter[0]*100/n);
|
---|
174 | *fLog << "%) Accepted trigger pattern." << endl;
|
---|
175 |
|
---|
176 | *fLog << " " << setw(7) << fCounter[1] << " (" << setw(3);
|
---|
177 | *fLog << (int)(fCounter[1]*100/n);
|
---|
178 | *fLog << "%) Rejected trigger pattern!" << endl;
|
---|
179 | *fLog << endl;
|
---|
180 |
|
---|
181 | return kTRUE;
|
---|
182 | }
|
---|
183 |
|
---|
184 | // -------------------------------------------------------------------------
|
---|
185 | //
|
---|
186 | // Require that a prescaled or unprescaled bit in the trigger pattern is
|
---|
187 | // passed. The bit is defined by mask, the prescaling by prescaled. The
|
---|
188 | // default is unprescaled.
|
---|
189 | //
|
---|
190 | // Because it doesn't make sense to require a denied bit we reset
|
---|
191 | // the deny bit at the same time.
|
---|
192 | //
|
---|
193 | void MFTriggerPattern::Require(const Byte_t mask, Prescale_t prescaled)
|
---|
194 | {
|
---|
195 | prescaled==kPrescaled ? (fMaskRequiredPrescaled |= mask) : (fMaskRequiredUnprescaled |= mask);
|
---|
196 | prescaled==kPrescaled ? (fMaskDeniedPrescaled &= ~mask) : (fMaskDeniedUnprescaled &= ~mask);
|
---|
197 | }
|
---|
198 |
|
---|
199 | // -------------------------------------------------------------------------
|
---|
200 | //
|
---|
201 | // Deny that a prescaled or unprescaled bit in the trigger pattern is
|
---|
202 | // passed. The bit is defined by mask, the prescaling by prescaled. The
|
---|
203 | // default is unprescaled.
|
---|
204 | //
|
---|
205 | // Because it doesn't make sense to deny a required bit we reset
|
---|
206 | // the require bit at the same time.
|
---|
207 | //
|
---|
208 | void MFTriggerPattern::Deny(const Byte_t mask, Prescale_t prescaled)
|
---|
209 | {
|
---|
210 | prescaled==kPrescaled ? (fMaskDeniedPrescaled |= mask) : (fMaskDeniedUnprescaled |= mask);
|
---|
211 | prescaled==kPrescaled ? (fMaskRequiredPrescaled &= ~mask) : (fMaskRequiredUnprescaled &= ~mask);
|
---|
212 | }
|
---|
213 |
|
---|
214 | // -------------------------------------------------------------------------
|
---|
215 | //
|
---|
216 | // Remove the given bits from the deny-mask. Thus you can first deny
|
---|
217 | // all bits to pass and then define which bit you want to allow
|
---|
218 | // to pass. The bit is defined by mask, the prescaling by prescaled. The
|
---|
219 | // default is unprescaled.
|
---|
220 | //
|
---|
221 | void MFTriggerPattern::Allow(const Byte_t mask, Prescale_t prescaled)
|
---|
222 | {
|
---|
223 | prescaled==kPrescaled ? (fMaskDeniedPrescaled &= ~mask) : (fMaskDeniedUnprescaled &= ~mask);
|
---|
224 | }
|
---|
225 |
|
---|
226 |
|
---|
227 | // -------------------------------------------------------------------------
|
---|
228 | //
|
---|
229 | // Deny all bits (i.e. also require non bits) for the given prescaling
|
---|
230 | // option. The prescaling is defined by prescaled. The default is
|
---|
231 | // unprescaled.
|
---|
232 | //
|
---|
233 | void MFTriggerPattern::DenyAll(Prescale_t prescaled)
|
---|
234 | {
|
---|
235 | Deny(0xff, prescaled);
|
---|
236 | }
|
---|
237 |
|
---|
238 | // -------------------------------------------------------------------------
|
---|
239 | //
|
---|
240 | // Allow all bits. resets the deny mask for the given prescaling option,
|
---|
241 | // but keeps the require mask unchanged. The prescaling is defined
|
---|
242 | // by prescaled. The default is unprescaled.
|
---|
243 | //
|
---|
244 | void MFTriggerPattern::AllowAll(Prescale_t prescaled)
|
---|
245 | {
|
---|
246 | prescaled==kPrescaled ? (fMaskDeniedPrescaled = 0) : (fMaskDeniedUnprescaled = 0);
|
---|
247 | }
|
---|
248 |
|
---|
249 | // -------------------------------------------------------------------------
|
---|
250 | //
|
---|
251 | // Low level settings. USE THESE ONLY IF YOU ARE AN EXPERT!
|
---|
252 | //
|
---|
253 | // You can concatenate bits either by using MTriggerPatter:
|
---|
254 | // eg. MTriggerPattern::kTriggerLvl1 & MTiggerPattern::kTriggerLvl2
|
---|
255 | // of by hexadecimal values:
|
---|
256 | // eg. 0xab
|
---|
257 | //
|
---|
258 | // while 0xab can be decoded like:
|
---|
259 | //
|
---|
260 | // 8421 8421
|
---|
261 | // 0xa=10=8+2 0xb=11=8+2+1 --> 1010 1011
|
---|
262 | //
|
---|
263 | // or vice versa it is easy to get a hexadecimal number from a bit pattern,
|
---|
264 | // eg.
|
---|
265 | //
|
---|
266 | // 8421 8421
|
---|
267 | // 0101 1101 --> 4+1=5=0x5 8+4+1=13=0xd --> 0x5d
|
---|
268 | //
|
---|
269 | void MFTriggerPattern::SetMaskRequired(const Byte_t mask, Prescale_t prescaled)
|
---|
270 | {
|
---|
271 | prescaled==kPrescaled ? (fMaskRequiredPrescaled = mask) : (fMaskRequiredUnprescaled = mask);
|
---|
272 | }
|
---|
273 |
|
---|
274 | // -------------------------------------------------------------------------
|
---|
275 | //
|
---|
276 | // Low level settings. USE THESE ONLY IF YOU ARE AN EXPERT!
|
---|
277 | //
|
---|
278 | // You can concatenate bits either by using MTriggerPatter:
|
---|
279 | // eg. MTriggerPattern::kTriggerLvl1 & MTiggerPattern::kTriggerLvl2
|
---|
280 | // of by hexadecimal values:
|
---|
281 | // eg. 0xab
|
---|
282 | //
|
---|
283 | // while 0xab can be decoded like:
|
---|
284 | //
|
---|
285 | // 8421 8421
|
---|
286 | // 0xa=10=8+2 0xb=11=8+2+1 --> 1010 1011
|
---|
287 | //
|
---|
288 | // or vice versa it is easy to get a hexadecimal number from a bit pattern,
|
---|
289 | // eg.
|
---|
290 | //
|
---|
291 | // 8421 8421
|
---|
292 | // 0101 1101 --> 4+1=5=0x5 8+4+1=13=0xd --> 0x5d
|
---|
293 | //
|
---|
294 | void MFTriggerPattern::SetMaskDenied(const Byte_t mask, Prescale_t prescaled)
|
---|
295 | {
|
---|
296 | prescaled==kPrescaled ? (fMaskDeniedPrescaled = mask) : (fMaskDeniedUnprescaled = mask);
|
---|
297 | }
|
---|
298 |
|
---|
299 | // -------------------------------------------------------------------------
|
---|
300 | //
|
---|
301 | // Create the mask to allow a particular (un)prescaled trigger pattern.
|
---|
302 | //
|
---|
303 | // Possible arguments are (upper/lower case is ignored):
|
---|
304 | //
|
---|
305 | // "LT1" : Trigger Level 1 flag
|
---|
306 | // "CAL" : Calibration flag
|
---|
307 | // "LT2" : Trigger Level 2 flag
|
---|
308 | // "PED" : Pedestal flag
|
---|
309 | // "PIND" : Pin Diode flag
|
---|
310 | // "SUMT" : Sum Trigger flag
|
---|
311 | //
|
---|
312 | // concatenations of these strings are allowed and considered as
|
---|
313 | // a logic "and", while trigger pattern flags not considered are
|
---|
314 | // anyway allowed. To deny a particular trigger pattern use
|
---|
315 | // the method Deny
|
---|
316 | // Example: patt = "lt1 lt2" allows events with trigger pattern flags
|
---|
317 | // {LT1,CAL,LT2} but not events with flags {LT1,CAL}.
|
---|
318 | //
|
---|
319 | void MFTriggerPattern::Require(TString patt, Prescale_t prescaled)
|
---|
320 | {
|
---|
321 | if (patt.Contains("LT1", TString::kIgnoreCase))
|
---|
322 | RequireTriggerLvl1(prescaled);
|
---|
323 |
|
---|
324 | if (patt.Contains("LT2", TString::kIgnoreCase))
|
---|
325 | RequireTriggerLvl2(prescaled);
|
---|
326 |
|
---|
327 | if (patt.Contains("CAL", TString::kIgnoreCase))
|
---|
328 | RequireCalibration(prescaled);
|
---|
329 |
|
---|
330 | if (patt.Contains("PED", TString::kIgnoreCase))
|
---|
331 | RequirePedestal(prescaled);
|
---|
332 |
|
---|
333 | if (patt.Contains("PIND", TString::kIgnoreCase))
|
---|
334 | RequirePinDiode(prescaled);
|
---|
335 |
|
---|
336 | if (patt.Contains("SUMT", TString::kIgnoreCase))
|
---|
337 | RequireSumTrigger(prescaled);
|
---|
338 | }
|
---|
339 |
|
---|
340 | // -------------------------------------------------------------------------
|
---|
341 | //
|
---|
342 | // Create the mask to deny a particular (un)prescaled trigger pattern.
|
---|
343 | //
|
---|
344 | // This method is there because is not possible to deny trigger patterns
|
---|
345 | // using only the Require pattern. Possible arguments are (upper/lower
|
---|
346 | // case is ignored) the flags for:
|
---|
347 | //
|
---|
348 | // "LT1" : Trigger Level 1
|
---|
349 | // "CAL" : Calibration
|
---|
350 | // "LT2" : Trigger Level 2
|
---|
351 | // "PED" : Pedestal
|
---|
352 | // "PIND" : Pin Diode
|
---|
353 | // "SUMT" : Sum Trigger
|
---|
354 | //
|
---|
355 | // concatenations of these strings are allowed and considered as
|
---|
356 | // a logic "and", while trigger pattern flags not considered are
|
---|
357 | // anyway allowed.
|
---|
358 | //
|
---|
359 | // Example: patt = "lt1 lt2" deny events with trigger pattern flags
|
---|
360 | // {LT1,CAL,LT2} but not events with flags {LT1,CAL}.
|
---|
361 | //
|
---|
362 | void MFTriggerPattern::Deny(TString patt, Prescale_t prescaled)
|
---|
363 | {
|
---|
364 | if (patt.Contains("LT1", TString::kIgnoreCase))
|
---|
365 | DenyTriggerLvl1(prescaled);
|
---|
366 |
|
---|
367 | if (patt.Contains("LT2", TString::kIgnoreCase))
|
---|
368 | DenyTriggerLvl2(prescaled);
|
---|
369 |
|
---|
370 | if (patt.Contains("CAL", TString::kIgnoreCase))
|
---|
371 | DenyCalibration(prescaled);
|
---|
372 |
|
---|
373 | if (patt.Contains("PED", TString::kIgnoreCase))
|
---|
374 | DenyPedestal(prescaled);
|
---|
375 |
|
---|
376 | if (patt.Contains("PIND", TString::kIgnoreCase))
|
---|
377 | DenyPinDiode(prescaled);
|
---|
378 |
|
---|
379 | if (patt.Contains("SUMT", TString::kIgnoreCase))
|
---|
380 | DenySumTrigger(prescaled);
|
---|
381 | }
|
---|