Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DMCTrigger_factory.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DMCTrigger_factory.cc
4 // Created: Tue Jun 7 10:15:05 EDT 2011 (originally was DTrigger_factory.cc)
5 // Creator: davidl (on Darwin eleanor.jlab.org 10.7.0 i386)
6 //
7 
8 
9 #include <iostream>
10 #include <iomanip>
11 #include <cmath>
12 using namespace std;
13 
14 #include <JANA/JApplication.h>
15 #include "DMCTrigger_factory.h"
16 using namespace jana;
17 
18 #include <BCAL/DBCALHit.h>
19 #include <BCAL/DBCALDigiHit.h>
20 #include <FCAL/DFCALHit.h>
21 #include <START_COUNTER/DSCHit.h>
22 #include <TOF/DTOFHit.h>
23 
24 // constant stolen from mcsmear - this should be put in the CCDB
25 static double BCAL_MEV_PER_ADC_COUNT = 0.029;
26 
27 //------------------
28 // init
29 //------------------
31 {
32  return NOERROR;
33 }
34 
35 //------------------
36 // brun
37 //------------------
38 jerror_t DMCTrigger_factory::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
39 {
40  // load BCAL geometry
41  vector<const DBCALGeometry *> BCALGeomVec;
42  eventLoop->Get(BCALGeomVec);
43  if(BCALGeomVec.size() == 0)
44  throw JException("Could not load DBCALGeometry object!");
45  const DBCALGeometry *dBCALGeom = BCALGeomVec[0];
46 
47  // Get attenuation parameters
48  double L_over_2 = dBCALGeom->GetBCAL_length()/2.0;
49  double Xo = dBCALGeom->GetBCAL_attenutation_length();
50  unattenuate_to_center = exp(+L_over_2/Xo);
51 
52  USE_OLD_BCAL_HITS = 0;
53  gPARMS->SetDefaultParameter("TRIGGER:USE_OLD_BCAL_HITS", USE_OLD_BCAL_HITS,
54  "Use old DBCALHit calculation for BCAL energy sum.");
55 
56  // Per-channel trigger thresholds
57  // Defaults in data according to A. Somov for Spring 2015 run (as of 11/13/15):
58  // FCAL: 130 MeV (65 adc counts)
59  // BCAL: 13.2 MeV (20 adc counts)
60  // Added 11/17/15 (sdobbs):
61  // Caveat: BCAL simulations use an adc count -> MeV conversion factor of 0.029,
62  // so for the BCAL use a threshold of
63  BCAL_CHANNEL_THRESHOLD = 455.; // in adc counts
64  FCAL_CHANNEL_THRESHOLD = 0.130; // in MeV
65  gPARMS->SetDefaultParameter("TRIGGER:BCAL_CHANNEL_THRESHOLD", BCAL_CHANNEL_THRESHOLD,
66  "Threshold for BCAL energy sum (units of adc counts)");
67  gPARMS->SetDefaultParameter("TRIGGER:FCAL_CHANNEL_THRESHOLD", FCAL_CHANNEL_THRESHOLD,
68  "Threshold for FCAL energy sum (units of MeV)");
69 
70 
71  return NOERROR;
72 }
73 
74 //------------------
75 // evnt
76 //------------------
77 jerror_t DMCTrigger_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
78 {
79  // See comments in DMCTrigger_factory.h
80 
81  vector<const DBCALHit*> bcalhits;
82  vector<const DFCALHit*> fcalhits;
83  vector<const DSCHit*> schits;
84  vector<const DTOFHit*> tofhits;
85  loop->Get(bcalhits);
86  loop->Get(fcalhits);
87  loop->Get(schits);
88  loop->Get(tofhits);
89 
90  double Ebcal = 0.0;
91  double Ebcal_all = 0.0;
92  double Efcal = 0.0;
93  double Efcal_all = 0.0;
94  double BCAL_Eupstream = 0.0;
95  double BCAL_Edownstream = 0.0;
96  // BCAL simulations now write out DBCALDigiHits, so we can directly sum the unattenuated energies
97  // Keep the old algorithm around for compatabilty
98  if(USE_OLD_BCAL_HITS) {
99  /// In GlueX-doc-1043, it appaears the energy deposited in the BCAL
100  /// is used. In reality, only the attenuated energy will be available
101  /// to the L1 trigger electronics. If an average of the sum of both
102  /// sides is used, it will be off by at most, 20% at the ends (excluding
103  /// any dark pulsing effects). This conclusion comes from assuming
104  /// we scale the values by e^(L/2/lambda) such that the value of the
105  /// threshold is in GeV for energy deposited at the center of the module.
106  /// The average of the two ends then is:
107  ///
108  /// Eavg = (E*e^+x + E*e^-x)/2
109  ///
110  /// or
111  ///
112  /// Eavg = E * cosh(x)
113  ///
114  /// where x = L/2/lambda
115  /// L = 390 cm
116  /// lambda = 300 cm
117  ///
118  /// The dark pulses should contribute at most about 10 MeV.
119  ///
120  /// For the BCAL "energy" we therefore take the average of the
121  /// sums of the DBCALHits for each side knowing it is
122  /// overestimated by as much as 20%.
123  ///
124  /// The FCAL energy is just a straight sum of the FCAL hits
125 
126  for(unsigned int i=0; i< bcalhits.size(); i++){
127  const DBCALHit* bcalhit = bcalhits[i];
128 
129  if(bcalhit->end == DBCALGeometry::kUpstream){
130  Ebcal_all += bcalhit->E;
131  if(1000.*bcalhit->E > BCAL_CHANNEL_THRESHOLD*BCAL_MEV_PER_ADC_COUNT)
132  BCAL_Eupstream += bcalhit->E;
133  }else{
134  Ebcal_all += bcalhit->E;
135  if(1000.*bcalhit->E > BCAL_CHANNEL_THRESHOLD*BCAL_MEV_PER_ADC_COUNT)
136  BCAL_Edownstream += bcalhit->E;
137  }
138  }
139 
140  // Calculate "energy" sum for BCAL in GeV-ish units
141  Ebcal = unattenuate_to_center * (BCAL_Eupstream + BCAL_Edownstream)/2.0;
142 
143  // Sum up FCAL energy
144  for(unsigned int i=0; i< fcalhits.size(); i++){
145  const DFCALHit* fcalhit = fcalhits[i];
146 
147  Efcal_all += fcalhit->E;
148  if(fcalhit->E > FCAL_CHANNEL_THRESHOLD)
149  Efcal += fcalhit->E;
150  }
151  } else {
152  // Sum up BCAL energy
153  for(unsigned int i=0; i< bcalhits.size(); i++){
154  const DBCALHit* bcalhit = bcalhits[i];
155  const DBCALDigiHit* bcaldigihit = NULL;
156  bcalhit->GetSingle(bcaldigihit);
157  if(bcaldigihit == NULL)
158  continue;
159 
160  Ebcal_all += bcalhit->E;
161  if(bcaldigihit->pulse_integral > BCAL_CHANNEL_THRESHOLD)
162  Ebcal += bcalhit->E;
163  }
164 
165  // Sum up FCAL energy
166  for(unsigned int i=0; i< fcalhits.size(); i++){
167  const DFCALHit* fcalhit = fcalhits[i];
168 
169  Efcal_all += fcalhit->E;
170  if(fcalhit->E > FCAL_CHANNEL_THRESHOLD)
171  Efcal += fcalhit->E;
172  }
173  }
174 
175  // Number of start counter hits
176  unsigned int Nschits = schits.size();
177 
178  // Number of TOF hits
179  unsigned int Ntofhits = tofhits.size();
180 
181  DMCTrigger *trig = new DMCTrigger;
182 
183  // BCAL and FCAL
184  bool sum_cut = (Ebcal + 4.0*Efcal)>=2.0;
185  trig->L1a_fired = sum_cut && Ebcal>0.200 && Efcal>0.030;
186  trig->L1b_fired = sum_cut && Ebcal>0.030 && Efcal>0.030 && Nschits>0;
187  trig->L1c_fired = Efcal>=0.250;
188 
189  trig->Ebcal = Ebcal;
190  trig->Efcal = Efcal;
191  trig->Ebcal_all = Ebcal_all;
192  trig->Efcal_all = Efcal_all;
193  trig->Nschits = Nschits;
194  trig->Ntofhits = Ntofhits;
195 
196  _data.push_back(trig);
197 
198  return NOERROR;
199 }
200 
201 //------------------
202 // erun
203 //------------------
205 {
206  return NOERROR;
207 }
208 
209 //------------------
210 // fini
211 //------------------
213 {
214  return NOERROR;
215 }
216 
bool L1c_fired
Definition: DMCTrigger.h:20
double Efcal_all
Definition: DMCTrigger.h:27
float E
Definition: DBCALHit.h:30
jerror_t init(void)
Called once at program start.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
bool L1b_fired
Definition: DMCTrigger.h:19
unsigned int Ntofhits
Definition: DMCTrigger.h:30
trig[33-1]
float GetBCAL_attenutation_length() const
Definition: DBCALGeometry.h:67
double Ebcal
Definition: DMCTrigger.h:23
float GetBCAL_length() const
DBCALGeometry::End end
Definition: DBCALHit.h:28
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
Definition: DBCALDigiHit.h:29
bool L1a_fired
Definition: DMCTrigger.h:18
unsigned int Nschits
Definition: DMCTrigger.h:29
double Ebcal_all
Definition: DMCTrigger.h:26
jerror_t fini(void)
Called after last event of last event source has been processed.
float E
Definition: DFCALHit.h:27
static double BCAL_MEV_PER_ADC_COUNT
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
double Efcal
Definition: DMCTrigger.h:24