Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_FCALLEDTree.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_FCALLEDTree.cc
4 // Created: Fri May 19 12:39:24 EDT 2017
5 // Creator: mashephe (on Linux stanley.physics.indiana.edu 2.6.32-642.6.2.el6.x86_64 unknown)
6 //
7 
9 using namespace jana;
10 
11 #include "FCAL/DFCALGeometry.h"
12 #include "FCAL/DFCALHit.h"
13 #include "FCAL/DFCALDigiHit.h"
14 
15 #include "TTree.h"
16 
17 // Routine used to create our JEventProcessor
18 #include <JANA/JApplication.h>
19 #include <JANA/JFactory.h>
20 extern "C"{
21  void InitPlugin(JApplication *app){
22  InitJANAPlugin(app);
23  app->AddProcessor(new JEventProcessor_FCALLEDTree());
24  }
25 } // "C"
26 
27 
28 //------------------
29 // JEventProcessor_FCALLEDTree (Constructor)
30 //------------------
32 {
33 
34 }
35 
36 //------------------
37 // ~JEventProcessor_FCALLEDTree (Destructor)
38 //------------------
40 {
41 
42 }
43 
44 //------------------
45 // init
46 //------------------
48 {
49  // This is called once at program startup.
50  japp->RootWriteLock();
51 
52  m_tree = new TTree( "fcalBlockHits", "FCAL Block Hits" );
53 
54  m_tree->Branch( "nHits", &m_nHits, "nHits/I" );
55  m_tree->Branch( "chan", m_chan, "chan[nHits]/I" );
56  m_tree->Branch( "x", m_x, "x[nHits]/F" );
57  m_tree->Branch( "y", m_y, "y[nHits]/F" );
58  m_tree->Branch( "E", m_E, "E[nHits]/F" );
59  m_tree->Branch( "t", m_t, "t[nHits]/F" );
60  m_tree->Branch( "integ", m_integ, "integ[nHits]/F" );
61  m_tree->Branch( "ped", m_ped, "ped[nHits]/F" );
62  m_tree->Branch( "peak", m_peak, "peak[nHits]/F" );
63 
64  m_tree->Branch( "run", &m_run, "run/I" );
65  m_tree->Branch( "event", &m_event, "event/L" );
66  m_tree->Branch( "eTot", &m_eTot, "eTot/F" );
67 
68  japp->RootUnLock();
69 
70  return NOERROR;
71 }
72 
73 //------------------
74 // brun
75 //------------------
76 jerror_t JEventProcessor_FCALLEDTree::brun(JEventLoop *eventLoop, int32_t runnumber)
77 {
78 
79  // this is not thread safe and may lead to an incorrect run number for
80  // a few events in the worst case scenario -- I don't think it is a major problem
81  m_run = runnumber;
82 
83  // This is called whenever the run number changes
84  return NOERROR;
85 }
86 
87 //------------------
88 // evnt
89 //------------------
90 jerror_t JEventProcessor_FCALLEDTree::evnt(JEventLoop *loop, uint64_t eventnumber)
91 {
92 
93  vector< const DFCALHit* > hits;
94  loop->Get( hits );
95 
96  if( hits.size() > kMaxHits ) return NOERROR;
97 
98  vector<const DFCALGeometry*> fcalGeomVect;
99  loop->Get( fcalGeomVect );
100  if (fcalGeomVect.size() < 1)
101  return OBJECT_NOT_AVAILABLE;
102  const DFCALGeometry& fcalGeom = *(fcalGeomVect[0]);
103 
104  japp->RootFillLock(this);
105 
106  m_event = eventnumber;
107 
108  m_nHits = 0;
109  m_eTot = 0;
110 
111  for( vector< const DFCALHit* >::const_iterator hit = hits.begin();
112  hit != hits.end();
113  ++hit ){
114 
115  vector< const DFCALDigiHit* > digiHits;
116  (**hit).Get( digiHits );
117  if( digiHits.size() != 1 ) std::cout << "ERROR: wrong size!! " << std::endl;
118 
119  const DFCALDigiHit& dHit = *(digiHits[0]);
120 
121  m_chan[m_nHits] = fcalGeom.channel( (**hit).row, (**hit).column );
122  m_x[m_nHits] = (**hit).x;
123  m_y[m_nHits] = (**hit).y;
124  m_E[m_nHits] = (**hit).E;
125  m_t[m_nHits] = (**hit).t;
126 
127  m_eTot += (**hit).E;
128 
129  m_ped[m_nHits] = (float)dHit.pedestal/dHit.nsamples_pedestal;
130  m_peak[m_nHits] = dHit.pulse_peak - m_ped[m_nHits];
131  m_integ[m_nHits] = dHit.pulse_integral -
132  (m_ped[m_nHits]*dHit.nsamples_integral);
133 
134  ++m_nHits;
135  }
136 
137  m_tree->Fill();
138 
139  japp->RootFillUnLock(this);
140 
141  return NOERROR;
142 }
143 
144 //------------------
145 // erun
146 //------------------
148 {
149  // This is called whenever the run number changes, before it is
150  // changed to give you a chance to clean up before processing
151  // events from the next run number.
152  return NOERROR;
153 }
154 
155 //------------------
156 // fini
157 //------------------
159 {
160  // Called before program exit after event processing is finished.
161  japp->RootWriteLock();
162  m_tree->Write();
163  japp->RootUnLock();
164 
165  return NOERROR;
166 }
167 
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
uint32_t pulse_peak
maximum sample in pulse
Definition: DFCALDigiHit.h:26
uint32_t nsamples_integral
number of samples used in integral
Definition: DFCALDigiHit.h:24
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
JApplication * japp
uint32_t pedestal
pedestal info used by FPGA (if any)
Definition: DFCALDigiHit.h:22
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t init(void)
Called once at program start.
InitPlugin_t InitPlugin
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
Definition: DFCALDigiHit.h:20
uint32_t nsamples_pedestal
number of samples used in pedestal
Definition: DFCALDigiHit.h:25
int channel(int row, int column) const
jerror_t fini(void)
Called after last event of last event source has been processed.