Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
libraries/TRIGGER/DTrigger_factory.cc
Go to the documentation of this file.
1 #include "DTrigger_factory.h"
2 #include <bitset>
3 #include "BCAL/DBCALHit.h"
4 #include "FCAL/DFCALHit.h"
5 
6 
7 //------------------
8 // init
9 //------------------
10 jerror_t DTrigger_factory::init(void)
11 {
14 
17 
18 
19  string locUsageString = "Set BCAL LED front panel trigger bits if such events leak into other triggers (1/0, off by default)";
20  gPARMS->SetDefaultParameter("TRIGGER:EMULATE_BCAL_LED_TRIGGER", EMULATE_BCAL_LED_TRIGGER, locUsageString);
21  locUsageString = "Set FCAL LED front panel trigger bits if such events leak into other triggers (1/0, off by default)";
22  gPARMS->SetDefaultParameter("TRIGGER:EMULATE_FCAL_LED_TRIGGER", EMULATE_FCAL_LED_TRIGGER, locUsageString);
23 
24 
25  return NOERROR;
26 }
27 
28 
29 
30 
31 //------------------
32 // evnt
33 //------------------
34 jerror_t DTrigger_factory::evnt(JEventLoop* locEventLoop, uint64_t locEventNumber)
35 {
36  vector<const DL1Trigger*> locL1Triggers;
37  locEventLoop->Get(locL1Triggers);
38  const DL1Trigger* locL1Trigger = locL1Triggers.empty() ? NULL : locL1Triggers[0];
39 
40  DTrigger *locTrigger = new DTrigger;
41 
42  //SET LEVEL-1 TRIGGER INFO
43  if(locL1Trigger != NULL)
44  {
45  locTrigger->Set_L1TriggerBits(locL1Trigger->trig_mask);
46  uint32_t locFpTrigMask = locL1Trigger->fp_trig_mask;
47 
48  // Sometimes the BCAL/FCAL LED trigger also trip the main physics trigger,
49  // due to hardware problems, afterglow, etc...
50  // These events are generally easy to identify due to their extremely large
51  // occupancies in the calorimeters. So, we allow the option to exclude
52  // these events by setting the trigger bits when it looks like they are firing
53 
55  vector<const DBCALHit *> bcal_hits;
56  locEventLoop->Get(bcal_hits);
57 
58  if( bcal_hits.size() > BCAL_LED_NHITS_THRESHOLD) {
59  // naively, not sure if this due to the up- or down-stream LEDs, so pick the upstream one
60  locFpTrigMask |= 0x100;
61  }
62  }
63 
65  vector<const DFCALHit *> fcal_hits;
66  locEventLoop->Get(fcal_hits);
67 
68  if( fcal_hits.size() > FCAL_LED_NHITS_THRESHOLD) {
69  locFpTrigMask |= 0x004;
70  }
71  }
72 
73  locTrigger->Set_L1FrontPanelTriggerBits(locFpTrigMask);
74 
75  }
76  else
77  {
78  // IF TRIGGER INFO IS NOT IN THE DATA STREAM, LOAD TRIGGER SIMULATIONS LAZILY
79 
80  // cerr << " event status = " << std::bitset<32>(locEventLoop->GetJEvent().GetStatus()) << endl;
81 
82  // don't bother simulating the trigger for non-physics events
83  // for now, just don't run this for EVIO (raw data) events
84  if( locEventLoop->GetJEvent().GetStatusBit(kSTATUS_EVIO) ){
85  _data.push_back(locTrigger);
86  return NOERROR;
87  }
88 
89  // realistic trigger simulation
90  vector<const DL1MCTrigger*> locMCTriggers;
91  locEventLoop->Get(locMCTriggers);
92  const DL1MCTrigger* locMCTrigger = locMCTriggers.empty() ? NULL : locMCTriggers[0];
93 
94  if(locMCTrigger != NULL)
95  {
96  //IS MC DATA: USE SIMULATED TRIGGER INFORMATION IF AVAILABLE
97  locTrigger->Set_L1TriggerBits(locMCTrigger->trig_mask);
98  locTrigger->Set_L1FrontPanelTriggerBits(0);
99  }
100  else
101  {
102  locTrigger->Set_L1TriggerBits(0);
103  locTrigger->Set_L1FrontPanelTriggerBits(0);
104  }
105  }
106 
107  //SET LEVEL-3 TRIGGER INFO HERE
108 
109  _data.push_back(locTrigger);
110 
111  return NOERROR;
112 }
jerror_t init(void)
Called once at program start.
uint32_t trig_mask
Definition: DL1MCTrigger.h:15
uint32_t trig_mask
Definition: DL1Trigger.h:18
uint32_t fp_trig_mask
Definition: DL1Trigger.h:19
void Set_L1FrontPanelTriggerBits(uint32_t locL1FrontPanelTriggerBits)
jerror_t evnt(JEventLoop *locEventLoop, uint64_t locEventNumber)
void Set_L1TriggerBits(uint32_t locL1TriggerBits)