Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plugins/Analysis/level1_trigger/DTrigger_factory.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DTrigger_factory.cc
4 // Created: Tue Jun 7 10:15:05 EDT 2011
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>
16 #include "DTrigger_factory.h"
17 using namespace jana;
18 
19 #include <BCAL/DBCALHit.h>
20 #include <FCAL/DFCALHit.h>
21 #include <START_COUNTER/DSCHit.h>
22 
23 // Routine used to create our JEventProcessor
24 extern "C"{
25 void InitPlugin(JApplication *app){
26  InitJANAPlugin(app);
27  app->AddFactoryGenerator(new JFactoryGenerator_DTrigger);
28 
29  stringstream mess;
30  mess << "=========================================================================="<<endl;
31  mess << endl;
32  mess << "W W A RRRRR NN N IIIIIII NN N GGGGGG "<<endl;
33  mess << "W W A A R R N N N I N N N G "<<endl;
34  mess << "W W A A R R N N N I N N N G "<<endl;
35  mess << "W W W AAAAAAA RRRRR N N N I N N N G GGGGG"<<endl;
36  mess << " W W W W A A R R N NN I N NN G G "<<endl;
37  mess << " W W A A R R N N IIIIIII N N GGGGG "<<endl;
38  mess << "=========================================================================="<<endl;
39  mess << endl;
40  mess << "Warning! You are using a deprecated plugin!"<<endl;
41  mess << "The level1_trigger plugin has been replaced with the TRIGGER library"<<endl;
42  mess << "that is now a part of standard DANA. "<<endl;
43  mess << endl;
44  mess << "ALSO! The DTrigger class has been renamed to DMCTrigger to allow DTrigger"<<endl;
45  mess << "to be used for data related to the real hardware trigger in the future."<<endl;
46  mess << "=========================================================================="<<endl;
47  cerr << mess.str();
48 
49 }
50 } // "C"
51 
52 
53 //------------------
54 // init
55 //------------------
56 jerror_t DTrigger_factory::init(void)
57 {
58  return NOERROR;
59 }
60 
61 //------------------
62 // brun
63 //------------------
64 jerror_t DTrigger_factory::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
65 {
66  // Get attenuation parameters
67  double L_over_2 = DBCALGeometry::BCALFIBERLENGTH/2.0;
68  double Xo = DBCALGeometry::ATTEN_LENGTH;
69  unattenuate_to_center = exp(+L_over_2/Xo);
70 
71  return NOERROR;
72 }
73 
74 //------------------
75 // evnt
76 //------------------
77 jerror_t DTrigger_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
78 {
79  // See comments in DTrigger_factory.h
80 
81  vector<const DBCALHit*> bcalhits;
82  vector<const DFCALHit*> fcalhits;
83  vector<const DSCHit*> schits;
84  loop->Get(bcalhits);
85  loop->Get(fcalhits);
86  loop->Get(schits);
87 
88  /// In GlueX-doc-1043, it appaears the energy deposited in the BCAL
89  /// is used. In reality, only the attenuated energy will be available
90  /// to the L1 trigger electronics. If an average of the sum of both
91  /// sides is used, it will be off by at most, 20% at the ends (excluding
92  /// any dark pulsing effects). This conclusion comes from assuming
93  /// we scale the values by e^(L/2/lambda) such that the value of the
94  /// threshold is in GeV for energy deposited at the center of the module.
95  /// The average of the two ends then is:
96  ///
97  /// Eavg = (E*e^+x + E*e^-x)/2
98  ///
99  /// or
100  ///
101  /// Eavg = E * cosh(x)
102  ///
103  /// where x = L/2/lambda
104  /// L = 390 cm
105  /// lambda = 300 cm
106  ///
107  /// The dark pulses should contribute at most about 10 MeV.
108  ///
109  /// For the BCAL "energy" we therefore take the average of the
110  /// sums of the DBCALHits for each side knowing it is
111  /// overestimated by as much as 20%.
112  ///
113  /// The FCAL energy is just a straight sum of the FCAL hits
114 
115  double BCAL_Eupstream = 0.0;
116  double BCAL_Edownstream = 0.0;
117  for(unsigned int i=0; i< bcalhits.size(); i++){
118  const DBCALHit* bcalhit = bcalhits[i];
119 
120  if(bcalhit->end == DBCALGeometry::kUpstream){
121  BCAL_Eupstream += bcalhit->E;
122  }else{
123  BCAL_Edownstream += bcalhit->E;
124  }
125  }
126 
127  // Calculate "energy" sum for BCAL in GeV-ish units
128  double Ebcal = unattenuate_to_center * (BCAL_Eupstream + BCAL_Edownstream)/2.0;
129 
130  // Sum up FCAL energy
131  double Efcal = 0.0;
132  for(unsigned int i=0; i< fcalhits.size(); i++){
133  const DFCALHit* fcalhit = fcalhits[i];
134 
135  Efcal += fcalhit->E;
136  }
137 
138  // Number of start counter hits
139  unsigned int Nschits = schits.size();
140 
141  DTrigger *trig = new DTrigger;
142 
143  // BCAL and FCAL
144  bool sum_cut = (Ebcal + 4.0*Efcal)>=2.0;
145  trig->L1a_fired = sum_cut && Ebcal>0.200 && Efcal>0.030;
146  trig->L1b_fired = sum_cut && Ebcal>0.030 && Efcal>0.030 && Nschits>0;
147  trig->L1c_fired = Efcal>=0.250;
148 
149  trig->Ebcal = Ebcal;
150  trig->Efcal = Efcal;
151  trig->Nschits = Nschits;
152 
153  _data.push_back(trig);
154 
155  return NOERROR;
156 }
157 
158 //------------------
159 // erun
160 //------------------
162 {
163  return NOERROR;
164 }
165 
166 //------------------
167 // fini
168 //------------------
170 {
171  return NOERROR;
172 }
173 
float E
Definition: DBCALHit.h:30
float ATTEN_LENGTH
attenuation length
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t init(void)
Called once at program start.
trig[33-1]
DBCALGeometry::End end
Definition: DBCALHit.h:28
InitPlugin_t InitPlugin
jerror_t evnt(JEventLoop *locEventLoop, uint64_t locEventNumber)
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
float BCALFIBERLENGTH
BCAL Scintilator fiber lenth in cm.
float E
Definition: DFCALHit.h:27
jerror_t fini(void)
Called after last event of last event source has been processed.