source: branches/Mars_McMismatchStudy/mtrigger/MFTriggerPattern.cc@ 18730

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