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

Last change on this file since 7804 was 7170, checked in by tbretz, 19 years ago
*** empty log message ***
File size: 9.7 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
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#include "MFTriggerPattern.h"
37
38#include "MLog.h"
39#include "MLogManip.h"
40
41#include "MParList.h"
42#include "MTriggerPattern.h"
43
44ClassImp(MFTriggerPattern);
45
46using namespace std;
47
48// --------------------------------------------------------------------------
49//
50// Default constructor. The default is to allow passing any trigger pattern.
51//
52MFTriggerPattern::MFTriggerPattern(const char *name, const char *title)
53 : fPattern(0), fMaskRequiredPrescaled(0), fMaskRequiredUnprescaled(0),
54 fMaskDeniedPrescaled(0), fMaskDeniedUnprescaled(0), fDefault(kTRUE)
55{
56 fName = name ? name : "MFTriggerPattern";
57 fTitle = title ? title : "Filter on Trigger Pattern";
58}
59
60// --------------------------------------------------------------------------
61//
62// Copy constructor
63//
64MFTriggerPattern::MFTriggerPattern(MFTriggerPattern &trigpatt)
65: MFilter(trigpatt)
66{
67 fMaskRequiredPrescaled = trigpatt.fMaskRequiredPrescaled;
68 fMaskRequiredUnprescaled = trigpatt.fMaskRequiredUnprescaled;
69}
70
71
72// --------------------------------------------------------------------------
73//
74Int_t MFTriggerPattern::PreProcess(MParList *pList)
75{
76 fPattern = (MTriggerPattern*)pList->FindObject("MTriggerPattern");
77 if (!fPattern)
78 {
79 *fLog << err << "MTriggerPattern not found... abort." << endl;
80 return kFALSE;
81 }
82
83 return kTRUE;
84}
85
86// --------------------------------------------------------------------------
87//
88Int_t MFTriggerPattern::Process()
89{
90 const Byte_t p = fPattern->GetPrescaled();
91 const Byte_t u = fPattern->GetUnprescaled();
92 if (p==0 && u==0)
93 {
94 fResult = fDefault;
95 return kTRUE;
96 }
97
98 fResult = kFALSE;
99
100 // Check whether all the bits required are ON
101 if ( ((p & fMaskRequiredPrescaled) == fMaskRequiredPrescaled) &&
102 ((u & fMaskRequiredUnprescaled) == fMaskRequiredUnprescaled))
103 fResult = kTRUE;
104
105 // Now overwrite the result if one of the bits is denied
106 if ( (p & fMaskDeniedPrescaled) || (u & fMaskDeniedUnprescaled) )
107 fResult = kFALSE;
108
109 return kTRUE;
110}
111
112void MFTriggerPattern::RequireTriggerLvl1(Prescale_t prescaled)
113{
114 prescaled==kPrescaled ? (fMaskRequiredPrescaled |= MTriggerPattern::kTriggerLvl1) : (fMaskRequiredUnprescaled |= MTriggerPattern::kTriggerLvl1);
115}
116
117void MFTriggerPattern::RequireTriggerLvl2(Prescale_t prescaled)
118{
119 prescaled==kPrescaled ? (fMaskRequiredPrescaled |= MTriggerPattern::kTriggerLvl2) : (fMaskRequiredUnprescaled |= MTriggerPattern::kTriggerLvl2);
120}
121
122void MFTriggerPattern::RequireCalibration(Prescale_t prescaled)
123{
124 prescaled==kPrescaled ? (fMaskRequiredPrescaled |= MTriggerPattern::kCalibration) : (fMaskRequiredUnprescaled |= MTriggerPattern::kCalibration);
125}
126
127void MFTriggerPattern::RequirePedestal(Prescale_t prescaled)
128{
129 prescaled==kPrescaled ? (fMaskRequiredPrescaled |= MTriggerPattern::kPedestal) : (fMaskRequiredUnprescaled |= MTriggerPattern::kPedestal);
130}
131
132void MFTriggerPattern::RequirePinDiode(Prescale_t prescaled)
133{
134 prescaled==kPrescaled ? (fMaskRequiredPrescaled |= MTriggerPattern::kPinDiode) : (fMaskRequiredUnprescaled |= MTriggerPattern::kPinDiode);
135}
136
137
138void MFTriggerPattern::DenyTriggerLvl1(Prescale_t prescaled)
139{
140 prescaled==kPrescaled ? (fMaskDeniedPrescaled |= MTriggerPattern::kTriggerLvl1) : (fMaskDeniedUnprescaled |= MTriggerPattern::kTriggerLvl1);
141}
142
143void MFTriggerPattern::DenyTriggerLvl2(Prescale_t prescaled)
144{
145 prescaled==kPrescaled ? (fMaskDeniedPrescaled |= MTriggerPattern::kTriggerLvl2) : (fMaskDeniedUnprescaled |= MTriggerPattern::kTriggerLvl2);
146}
147
148void MFTriggerPattern::DenyCalibration(Prescale_t prescaled)
149{
150 prescaled==kPrescaled ? (fMaskDeniedPrescaled |= MTriggerPattern::kCalibration) : (fMaskDeniedUnprescaled |= MTriggerPattern::kCalibration);
151}
152
153void MFTriggerPattern::DenyPedestal(Prescale_t prescaled)
154{
155 prescaled==kPrescaled ? (fMaskDeniedPrescaled |= MTriggerPattern::kPedestal) : (fMaskDeniedUnprescaled |= MTriggerPattern::kPedestal);
156}
157
158void MFTriggerPattern::DenyPinDiode(Prescale_t prescaled)
159{
160 prescaled==kPrescaled ? (fMaskDeniedPrescaled |= MTriggerPattern::kPinDiode) : (fMaskDeniedUnprescaled |= MTriggerPattern::kPinDiode);
161}
162
163// -------------------------------------------------------------------------
164//
165// Low level settings. USE THESE ONLY IF YOU ARE AN EXPERT!
166//
167// You can concatenate bits either by using MTriggerPatter:
168// eg. MTriggerPattern::kTriggerLvl1 & MTiggerPattern::kTriggerLvl2
169// of by hexadecimal values:
170// eg. 0xab
171//
172// while 0xab can be decoded like:
173//
174// 8421 8421
175// 0xa=10=8+2 0xb=11=8+2+1 --> 1010 1011
176//
177// or vice versa it is easy to get a hexadecimal number from a bit pattern,
178// eg.
179//
180// 8421 8421
181// 0101 1101 --> 4+1=5=0x5 8+4+1=13=0xd --> 0x5d
182//
183void MFTriggerPattern::SetMaskRequired(const Byte_t mask, Prescale_t prescaled)
184{
185 prescaled==kPrescaled ? (fMaskRequiredPrescaled = mask) : (fMaskRequiredUnprescaled = mask);
186}
187
188// -------------------------------------------------------------------------
189//
190// Low level settings. USE THESE ONLY IF YOU ARE AN EXPERT!
191//
192// You can concatenate bits either by using MTriggerPatter:
193// eg. MTriggerPattern::kTriggerLvl1 & MTiggerPattern::kTriggerLvl2
194// of by hexadecimal values:
195// eg. 0xab
196//
197// while 0xab can be decoded like:
198//
199// 8421 8421
200// 0xa=10=8+2 0xb=11=8+2+1 --> 1010 1011
201//
202// or vice versa it is easy to get a hexadecimal number from a bit pattern,
203// eg.
204//
205// 8421 8421
206// 0101 1101 --> 4+1=5=0x5 8+4+1=13=0xd --> 0x5d
207//
208void MFTriggerPattern::SetMaskDenied(const Byte_t mask, Prescale_t prescaled)
209{
210 prescaled==kPrescaled ? (fMaskDeniedPrescaled = mask) : (fMaskDeniedUnprescaled = mask);
211}
212
213// -------------------------------------------------------------------------
214//
215// Create the mask to allow a particular (un)prescaled trigger pattern.
216//
217// Possible arguments are (upper/lower case is ignored):
218//
219// "LT1" : Trigger Level 1 flag
220// "CAL" : Calibration flag
221// "LT2" : Trigger Level 2 flag
222// "PED" : Pedestal flag
223// "PIND" : Pin Diode flag
224//
225// concatenations of these strings are allowed and considered as
226// a logic "and", while trigger pattern flags not considered are
227// anyway allowed. To deny a particular trigger pattern use
228// the method Deny
229// Example: patt = "lt1 lt2" allows events with trigger pattern flags
230// {LT1,CAL,LT2} but not events with flags {LT1,CAL}.
231//
232void MFTriggerPattern::Require(TString patt, Prescale_t prescaled)
233{
234 if (patt.Contains("LT1", TString::kIgnoreCase))
235 RequireTriggerLvl1(prescaled);
236
237 if (patt.Contains("LT2", TString::kIgnoreCase))
238 RequireTriggerLvl2(prescaled);
239
240 if (patt.Contains("CAL", TString::kIgnoreCase))
241 RequireCalibration(prescaled);
242
243 if (patt.Contains("PED", TString::kIgnoreCase))
244 RequirePedestal(prescaled);
245
246 if (patt.Contains("PIND", TString::kIgnoreCase))
247 RequirePinDiode(prescaled);
248}
249
250// -------------------------------------------------------------------------
251//
252// Create the mask to deny a particular (un)prescaled trigger pattern.
253//
254// This method is there because is not possible to deny trigger patterns
255// using only the Require pattern. Possible arguments are (upper/lower
256// case is ignored):
257//
258// "LT1" : Trigger Level 1 flag
259// "CAL" : Calibration flag
260// "LT2" : Trigger Level 2 flag
261// "PED" : Pedestal flag
262// "PIND" : Pin Diode flag
263//
264// concatenations of these strings are allowed and considered as
265// a logic "and", while trigger pattern flags not considered are
266// anyway allowed.
267//
268// Example: patt = "lt1 lt2" deny events with trigger pattern flags
269// {LT1,CAL,LT2} but not events with flags {LT1,CAL}.
270//
271void MFTriggerPattern::Deny(TString patt, Prescale_t prescaled)
272{
273 if (patt.Contains("LT1", TString::kIgnoreCase))
274 DenyTriggerLvl1(prescaled);
275
276 if (patt.Contains("LT2", TString::kIgnoreCase))
277 DenyTriggerLvl2(prescaled);
278
279 if (patt.Contains("CAL", TString::kIgnoreCase))
280 DenyCalibration(prescaled);
281
282 if (patt.Contains("PED", TString::kIgnoreCase))
283 DenyPedestal(prescaled);
284
285 if (patt.Contains("PIND", TString::kIgnoreCase))
286 DenyPinDiode(prescaled);
287}
288
289// --------------------------------------------------------------------------
290//
291Bool_t MFTriggerPattern::IsExpressionTrue() const
292{
293 return fResult;
294}
Note: See TracBrowser for help on using the repository browser.