Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_DAQTreeBCAL.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_DAQTreeBCAL.cc
4 // Created: Mon May 5 15:20:49 EDT 2014
5 // Creator: davidl (on Darwin harriet.jlab.org 13.1.0 i386)
6 //
7 
8 #include <iostream>
9 using namespace std;
10 
12 using namespace jana;
13 
14 #include <BCAL/DBCALDigiHit.h>
15 #include <BCAL/DBCALTDCDigiHit.h>
16 #include <DAQ/Df250PulseIntegral.h>
17 #include <DAQ/Df250WindowRawData.h>
18 #include <DAQ/Df250PulseData.h>
19 #include <DAQ/DF1TDCHit.h>
20 
21 
22 // Routine used to create our JEventProcessor
23 #include <JANA/JApplication.h>
24 #include <JANA/JFactory.h>
25 extern "C"{
26 void InitPlugin(JApplication *app){
27  InitJANAPlugin(app);
28  app->AddProcessor(new JEventProcessor_DAQTreeBCAL());
29 }
30 } // "C"
31 
32 
33 //------------------
34 // JEventProcessor_DAQTreeBCAL (Constructor)
35 //------------------
37 {
38 
39 }
40 
41 //------------------
42 // ~JEventProcessor_DAQTreeBCAL (Destructor)
43 //------------------
45 {
46 
47 }
48 
49 //------------------
50 // init
51 //------------------
53 {
54  BCALdigi = new TTree("BCALdigi","DBCALDigiHit objects (w/ waveform samples) for each channel and event");
55  BCALdigi->Branch("channelnum",&channelnum,"channelnum/i");
56  BCALdigi->Branch("eventnum",&eventnum,"eventnum/i");
57  BCALdigi->Branch("rocid",&rocid,"rocid/i");
58  BCALdigi->Branch("slot",&slot,"slot/i");
59  BCALdigi->Branch("channel",&channel,"channel/i");
60  BCALdigi->Branch("itrigger",&itrigger,"itrigger/i");
61  BCALdigi->Branch("waveform",&waveform);
62  BCALdigi->Branch("nsamples",&nsamples,"nsamples/i");
63  BCALdigi->Branch("w_integral",&w_integral,"w_integral/i");
64  BCALdigi->Branch("w_min",&w_min,"w_min/i");
65  BCALdigi->Branch("w_max",&w_max,"w_max/i");
66  BCALdigi->Branch("w_samp1",&w_samp1,"w_samp1/i");
67 
68  BCALdigi->Branch("module",&module,"module/i");
69  BCALdigi->Branch("layer",&layer,"layer/i");
70  BCALdigi->Branch("sector",&sector,"sector/i");
71  BCALdigi->Branch("end",&end,"end/i");
72 
73 
74 
75  BCALTDCdigi = new TTree("BCALTDCdigi","DBCALTDCDigiHit objects for each channel and event");
76  BCALTDCdigi->Branch("channelnum",&channelnum,"channelnum/i");
77  BCALTDCdigi->Branch("eventnum",&eventnum,"eventnum/i");
78  BCALTDCdigi->Branch("rocid",&rocid,"rocid/i");
79  BCALTDCdigi->Branch("slot",&slot,"slot/i");
80  BCALTDCdigi->Branch("channel",&channel,"channel/i");
81  BCALTDCdigi->Branch("itrigger",&itrigger,"itrigger/i");
82  BCALTDCdigi->Branch("time",&time,"time/i");
83  //BCALTDCdigi->Branch("trigger_time",&trigger_time,"trigger_time/i");
84 
85  BCALTDCdigi->Branch("module",&module,"module/i");
86  BCALTDCdigi->Branch("layer",&layer,"layer/i");
87  BCALTDCdigi->Branch("sector",&sector,"sector/i");
88  BCALTDCdigi->Branch("end",&end,"end/i");
89 
90 
91 
92  return NOERROR;
93 }
94 
95 //------------------
96 // brun
97 //------------------
98 jerror_t JEventProcessor_DAQTreeBCAL::brun(JEventLoop *eventLoop, int32_t runnumber)
99 {
100  // This is called whenever the run number changes
101  return NOERROR;
102 }
103 
104 //------------------
105 // evnt
106 //------------------
107 jerror_t JEventProcessor_DAQTreeBCAL::evnt(JEventLoop *loop, uint64_t eventnumber)
108 {
109  eventnum = eventnumber;
110 
111  // Get the DBCALDigiHit objects
112  vector<const DBCALDigiHit*> bcaldigihits;
113  loop->Get(bcaldigihits);
114 
115  // Get the DBCALTDCDigiHit objects
116  vector<const DBCALTDCDigiHit*> bcaltdcdigihits;
117  loop->Get(bcaltdcdigihits);
118 
119  // Although we are only filling objects local to this plugin, TTree::Fill() periodically writes to file: Global ROOT lock
120  japp->RootWriteLock(); //ACQUIRE ROOT LOCK
121 
122  // Loop over DBCALDigiHit objects
123  for(unsigned int i=0; i< bcaldigihits.size(); i++){
124 
125  // Get Df250PulseIntegral and Df250WindowRawData objects
126  // associated with this. If either fails then an exeption
127  // is thrown (and caught) and the hit is ignored.
128  try {
129  const DBCALDigiHit *bcaldigihit = bcaldigihits[i];
130  const Df250WindowRawData *windorawdata = NULL;
131 
132  const Df250PulseData *pulsedata = NULL;
133  bcaldigihit->GetSingle(pulsedata);
134  if(pulsedata){
135  pulsedata->GetSingle(windorawdata);
136  }else{
137  const Df250PulseIntegral *pulseintegral = NULL;
138  bcaldigihit->GetSingle(pulseintegral);
139  pulseintegral->GetSingle(windorawdata);
140  }
141 
142  if(!windorawdata){
143  jerr << "No Df250WindowRawData objects associate with DBCALDigiHit!" << endl;
144  continue;
145  }
146 
147  pulsedata->GetSingle(windorawdata);
148 
149  waveform.clear();
150  channelnum = i;
151  rocid = windorawdata->rocid;
152  slot = windorawdata->slot;
153  channel = windorawdata->channel;
154  itrigger = windorawdata->itrigger;
155 
156  // Get a vector of the samples for this channel
157  const vector<uint16_t> &samplesvector = windorawdata->samples;
158  nsamples=samplesvector.size();
159 
160  // loop over the samples to calculate integral, min, max
161  for (uint16_t c_samp=0; c_samp<nsamples; c_samp++) {
162  waveform.push_back(samplesvector[c_samp]); // push the sample into the waveform vector
163  if (c_samp==0) { // use first sample for initialization
164  w_integral = samplesvector[0];
165  w_min = samplesvector[0];
166  w_max = samplesvector[0];
167  w_samp1 = samplesvector[0];
168  } else {
169  w_integral += samplesvector[c_samp];
170  if (w_min > samplesvector[c_samp]) w_min = samplesvector[c_samp];
171  if (w_max < samplesvector[c_samp]) w_max = samplesvector[c_samp];
172  }
173  }
174 
175  module = bcaldigihit->module;
176  layer = bcaldigihit->layer;
177  sector = bcaldigihit->sector;
178  end = bcaldigihit->end;
179 
180 
181  // Fill tree
182  BCALdigi->Fill();
183 
184  } catch (...) {}
185  }
186 
187  // Loop over DBCALTDCDigiHit objects
188  for(unsigned int i=0; i< bcaltdcdigihits.size(); i++){
189 
190  const DBCALTDCDigiHit *bcaltdcdigihit = bcaltdcdigihits[i];
191  const DF1TDCHit *tdchit;
192  bcaltdcdigihit->GetSingle(tdchit);
193 
194  channelnum = i;
195  rocid = tdchit->rocid;
196  slot = tdchit->slot;
197  channel = tdchit->channel;
198  itrigger = tdchit->itrigger;
199 
200  time = bcaltdcdigihit->time;
201 
202  module = bcaltdcdigihit->module;
203  layer = bcaltdcdigihit->layer;
204  sector = bcaltdcdigihit->sector;
205  end = bcaltdcdigihit->end;
206 
207  // Fill tree
208  BCALTDCdigi->Fill();
209  }
210 
211  japp->RootUnLock(); //RELEASE ROOT LOCK
212 
213  return NOERROR;
214 }
215 
216 //------------------
217 // erun
218 //------------------
220 {
221  // This is called whenever the run number changes, before it is
222  // changed to give you a chance to clean up before processing
223  // events from the next run number.
224  return NOERROR;
225 }
226 
227 //------------------
228 // fini
229 //------------------
231 {
232  // Called before program exit after event processing is finished.
233  return NOERROR;
234 }
235 
Int_t layer
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
vector< uint16_t > samples
JApplication * japp
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
DBCALGeometry::End end
Definition: DBCALDigiHit.h:28
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
InitPlugin_t InitPlugin
DBCALGeometry::End end
uint32_t channel
Definition: DDAQAddress.h:34
uint32_t rocid
Definition: DDAQAddress.h:32
jerror_t fini(void)
Called after last event of last event source has been processed.
uint32_t itrigger
Definition: DDAQAddress.h:35
jerror_t init(void)
Called once at program start.
uint32_t slot
Definition: DDAQAddress.h:33