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