source: trunk/MagicSoft/Mars/mtrigger/MFTriggerPattern.cc@ 8903

Last change on this file since 8903 was 8903, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 10.6 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// 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
49ClassImp(MFTriggerPattern);
50
51using namespace std;
52
53// --------------------------------------------------------------------------
54//
55// Default constructor. The default is to allow passing any trigger pattern.
56//
57MFTriggerPattern::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//
69MFTriggerPattern::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//
86Int_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 return kTRUE;
96}
97
98// --------------------------------------------------------------------------
99//
100// If Prescaled and Unprescaled pattern is 0 return default.
101// If all bits of the fMaskRequired* mask are found in the pattern set
102// fResult to true.
103// If any bit matches the fMasDenied* mask fResult is forced to be false.
104//
105Int_t MFTriggerPattern::Process()
106{
107 const Byte_t p = fPattern->GetPrescaled();
108 const Byte_t u = fPattern->GetUnprescaled();
109 if (p==0 && u==0)
110 {
111 fResult = fDefault;
112 return kTRUE;
113 }
114
115 fResult = kFALSE;
116
117 // Check whether all the bits required are ON
118 if ( ((p & fMaskRequiredPrescaled) == fMaskRequiredPrescaled) &&
119 ((u & fMaskRequiredUnprescaled) == fMaskRequiredUnprescaled))
120 fResult = kTRUE;
121
122 // Now overwrite the result if one of the bits is denied
123 if ( (p & fMaskDeniedPrescaled) || (u & fMaskDeniedUnprescaled) )
124 fResult = kFALSE;
125
126 return kTRUE;
127}
128
129// -------------------------------------------------------------------------
130//
131// Require that a prescaled or unprescaled bit in the trigger pattern is
132// passed. The bit is defined by mask, the prescaling by prescaled. The
133// default is unprescaled.
134//
135// Because it doesn't make sense to require a denied bit we reset
136// the deny bit at the same time.
137//
138void MFTriggerPattern::Require(const Byte_t mask, Prescale_t prescaled)
139{
140 prescaled==kPrescaled ? (fMaskRequiredPrescaled |= mask) : (fMaskRequiredUnprescaled |= mask);
141 prescaled==kPrescaled ? (fMaskDeniedPrescaled &= ~mask) : (fMaskDeniedUnprescaled &= ~mask);
142}
143
144// -------------------------------------------------------------------------
145//
146// Deny that a prescaled or unprescaled bit in the trigger pattern is
147// passed. The bit is defined by mask, the prescaling by prescaled. The
148// default is unprescaled.
149//
150// Because it doesn't make sense to deny a required bit we reset
151// the require bit at the same time.
152//
153void MFTriggerPattern::Deny(const Byte_t mask, Prescale_t prescaled)
154{
155 prescaled==kPrescaled ? (fMaskDeniedPrescaled |= mask) : (fMaskDeniedUnprescaled |= mask);
156 prescaled==kPrescaled ? (fMaskRequiredPrescaled &= ~mask) : (fMaskRequiredUnprescaled &= ~mask);
157}
158
159// -------------------------------------------------------------------------
160//
161// Remove the given bits from the deny-mask. Thus you can first deny
162// all bits to pass and then define which bit you want to allow
163// to pass. The bit is defined by mask, the prescaling by prescaled. The
164// default is unprescaled.
165//
166void MFTriggerPattern::Allow(const Byte_t mask, Prescale_t prescaled)
167{
168 prescaled==kPrescaled ? (fMaskDeniedPrescaled &= ~mask) : (fMaskDeniedUnprescaled &= ~mask);
169}
170
171
172// -------------------------------------------------------------------------
173//
174// Deny all bits (i.e. also require non bits) for the given prescaling
175// option. The prescaling is defined by prescaled. The default is
176// unprescaled.
177//
178void MFTriggerPattern::DenyAll(Prescale_t prescaled)
179{
180 Deny(0xff, prescaled);
181}
182
183// -------------------------------------------------------------------------
184//
185// Allow all bits. resets the deny mask for the given prescaling option,
186// but keeps the require mask unchanged. The prescaling is defined
187// by prescaled. The default is unprescaled.
188//
189void MFTriggerPattern::AllowAll(Prescale_t prescaled)
190{
191 prescaled==kPrescaled ? (fMaskDeniedPrescaled = 0) : (fMaskDeniedUnprescaled = 0);
192}
193
194// -------------------------------------------------------------------------
195//
196// Low level settings. USE THESE ONLY IF YOU ARE AN EXPERT!
197//
198// You can concatenate bits either by using MTriggerPatter:
199// eg. MTriggerPattern::kTriggerLvl1 & MTiggerPattern::kTriggerLvl2
200// of by hexadecimal values:
201// eg. 0xab
202//
203// while 0xab can be decoded like:
204//
205// 8421 8421
206// 0xa=10=8+2 0xb=11=8+2+1 --> 1010 1011
207//
208// or vice versa it is easy to get a hexadecimal number from a bit pattern,
209// eg.
210//
211// 8421 8421
212// 0101 1101 --> 4+1=5=0x5 8+4+1=13=0xd --> 0x5d
213//
214void MFTriggerPattern::SetMaskRequired(const Byte_t mask, Prescale_t prescaled)
215{
216 prescaled==kPrescaled ? (fMaskRequiredPrescaled = mask) : (fMaskRequiredUnprescaled = mask);
217}
218
219// -------------------------------------------------------------------------
220//
221// Low level settings. USE THESE ONLY IF YOU ARE AN EXPERT!
222//
223// You can concatenate bits either by using MTriggerPatter:
224// eg. MTriggerPattern::kTriggerLvl1 & MTiggerPattern::kTriggerLvl2
225// of by hexadecimal values:
226// eg. 0xab
227//
228// while 0xab can be decoded like:
229//
230// 8421 8421
231// 0xa=10=8+2 0xb=11=8+2+1 --> 1010 1011
232//
233// or vice versa it is easy to get a hexadecimal number from a bit pattern,
234// eg.
235//
236// 8421 8421
237// 0101 1101 --> 4+1=5=0x5 8+4+1=13=0xd --> 0x5d
238//
239void MFTriggerPattern::SetMaskDenied(const Byte_t mask, Prescale_t prescaled)
240{
241 prescaled==kPrescaled ? (fMaskDeniedPrescaled = mask) : (fMaskDeniedUnprescaled = mask);
242}
243
244// -------------------------------------------------------------------------
245//
246// Create the mask to allow a particular (un)prescaled trigger pattern.
247//
248// Possible arguments are (upper/lower case is ignored):
249//
250// "LT1" : Trigger Level 1 flag
251// "CAL" : Calibration flag
252// "LT2" : Trigger Level 2 flag
253// "PED" : Pedestal flag
254// "PIND" : Pin Diode flag
255// "SUMT" : Sum Trigger flag
256//
257// concatenations of these strings are allowed and considered as
258// a logic "and", while trigger pattern flags not considered are
259// anyway allowed. To deny a particular trigger pattern use
260// the method Deny
261// Example: patt = "lt1 lt2" allows events with trigger pattern flags
262// {LT1,CAL,LT2} but not events with flags {LT1,CAL}.
263//
264void MFTriggerPattern::Require(TString patt, Prescale_t prescaled)
265{
266 if (patt.Contains("LT1", TString::kIgnoreCase))
267 RequireTriggerLvl1(prescaled);
268
269 if (patt.Contains("LT2", TString::kIgnoreCase))
270 RequireTriggerLvl2(prescaled);
271
272 if (patt.Contains("CAL", TString::kIgnoreCase))
273 RequireCalibration(prescaled);
274
275 if (patt.Contains("PED", TString::kIgnoreCase))
276 RequirePedestal(prescaled);
277
278 if (patt.Contains("PIND", TString::kIgnoreCase))
279 RequirePinDiode(prescaled);
280
281 if (patt.Contains("SUMT", TString::kIgnoreCase))
282 RequireSumTrigger(prescaled);
283}
284
285// -------------------------------------------------------------------------
286//
287// Create the mask to deny a particular (un)prescaled trigger pattern.
288//
289// This method is there because is not possible to deny trigger patterns
290// using only the Require pattern. Possible arguments are (upper/lower
291// case is ignored) the flags for:
292//
293// "LT1" : Trigger Level 1
294// "CAL" : Calibration
295// "LT2" : Trigger Level 2
296// "PED" : Pedestal
297// "PIND" : Pin Diode
298// "SUMT" : Sum Trigger
299//
300// concatenations of these strings are allowed and considered as
301// a logic "and", while trigger pattern flags not considered are
302// anyway allowed.
303//
304// Example: patt = "lt1 lt2" deny events with trigger pattern flags
305// {LT1,CAL,LT2} but not events with flags {LT1,CAL}.
306//
307void MFTriggerPattern::Deny(TString patt, Prescale_t prescaled)
308{
309 if (patt.Contains("LT1", TString::kIgnoreCase))
310 DenyTriggerLvl1(prescaled);
311
312 if (patt.Contains("LT2", TString::kIgnoreCase))
313 DenyTriggerLvl2(prescaled);
314
315 if (patt.Contains("CAL", TString::kIgnoreCase))
316 DenyCalibration(prescaled);
317
318 if (patt.Contains("PED", TString::kIgnoreCase))
319 DenyPedestal(prescaled);
320
321 if (patt.Contains("PIND", TString::kIgnoreCase))
322 DenyPinDiode(prescaled);
323
324 if (patt.Contains("SUMT", TString::kIgnoreCase))
325 DenySumTrigger(prescaled);
326}
Note: See TracBrowser for help on using the repository browser.