Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Df250PulseIntegral_factory.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: Df250PulseIntegral_factory.cc
4 // Created: Thu Feb 13 12:49:12 EST 2014
5 // Creator: dalton (on Linux gluon104.jlab.org 2.6.32-358.23.2.el6.x86_64 x86_64)
6 //
7 
8 
9 #include <iostream>
10 #include <iomanip>
11 using namespace std;
12 
13 #include <JANA/JApplication.h>
14 using namespace jana;
15 #include <DAQ/Df250WindowRawData.h>
16 
19 
20 
21 // Routine used to create our JEventProcessor
22 
23 extern "C"{
24  void InitPlugin(JApplication *app){
25  InitJANAPlugin(app);
26  app->AddFactoryGenerator(new JFactoryGenerator_Df250PulseIntegral());
27  }
28 } // "C"
29 
30 //------------------
31 // init
32 //------------------
34 {
35  printf("Df250PulseIntegral_factory::init()\n");
36  return NOERROR;
37 }
38 
39 //------------------
40 // brun
41 //------------------
42 jerror_t Df250PulseIntegral_factory::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
43 {
44  return NOERROR;
45 }
46 
47 //------------------
48 // evnt
49 //------------------
50 jerror_t Df250PulseIntegral_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
51 {
52 
53  // Code to generate factory data goes here. Add it like:
54  //
55  // Df250PulseIntegral *myDf250PulseIntegral = new Df250PulseIntegral;
56  // myDf250PulseIntegral->x = x;
57  // myDf250PulseIntegral->y = y;
58  // ...
59  // _data.push_back(myDf250PulseIntegral);
60  //
61  // Note that the objects you create here will be deleted later
62  // by the system and the _data vector will be cleared automatically.
63 
64  uint32_t pulse_number = 0;
65  uint32_t quality_factor = 0;
66 
67  // Get a vector of objects for this event (1 object for each crate/slot/channel)
68  vector<const Df250WindowRawData*> f250WindowRawData_vec;
69  loop->Get(f250WindowRawData_vec);
70  uint32_t Nchannels = f250WindowRawData_vec.size();
71 
72  // Loop over all channels in this event
73  for(unsigned int c_chan=0; c_chan<Nchannels; c_chan++){
74  // get Df250WindowRawData object
75  const Df250WindowRawData *f250WindowRawData = f250WindowRawData_vec[c_chan];
76  // create new Df250PulseIntegral object
77  Df250PulseIntegral *myDf250PulseIntegral = new Df250PulseIntegral;
78  myDf250PulseIntegral->rocid =f250WindowRawData->rocid;
79  myDf250PulseIntegral->slot = f250WindowRawData->slot;
80  myDf250PulseIntegral->channel = f250WindowRawData->channel;
81  myDf250PulseIntegral->itrigger = f250WindowRawData->itrigger;
82 
83  // Get a vector of the samples for this channel
84  const vector<uint16_t> &samplesvector = f250WindowRawData->samples;
85  uint32_t nsamples=samplesvector.size();
86  uint32_t pedestalsum = 0;
87  uint32_t signalsum = 0;
88 
89  // loop over the first X samples to calculate pedestal
90  for (uint16_t c_samp=0; c_samp<ped_samples; c_samp++) {
91  pedestalsum += samplesvector[c_samp];
92  }
93  // loop over the remaining samples to calculate integral
94  for (uint16_t c_samp=ped_samples; c_samp<nsamples; c_samp++) {
95  signalsum += samplesvector[c_samp];
96  }
97  //uint32_t pedestaleffect = ((pedestalsum * isamples)/ped_samples);
98  // myintegral = signalsum - pedestaleffect;
99  // if (myintegral > 10000) jout << myintegral << " " << signalsum << " " << pedestaleffect << " " << pedestalsum << " " << nsamples << " " << ped_samples << " " << isamples << " \n";
100  myDf250PulseIntegral->pulse_number = pulse_number;
101  myDf250PulseIntegral->quality_factor = quality_factor;
102  myDf250PulseIntegral->integral = signalsum;
103  myDf250PulseIntegral->pedestal = pedestalsum;
104  _data.push_back(myDf250PulseIntegral);
105  }
106 
107  return NOERROR;
108 }
109 
110 //------------------
111 // erun
112 //------------------
114 {
115  return NOERROR;
116 }
117 
118 //------------------
119 // fini
120 //------------------
122 {
123  return NOERROR;
124 }
125 
126 
127 /* emacs
128  * Local Variables:
129  * mode:C++
130  * mode:font-lock
131  * c-file-style: "stroustrup"
132  * tab-width: 4
133  * End:
134  */
jerror_t init(void)
Called once at program start.
jerror_t fini(void)
Called after last event of last event source has been processed.
uint32_t quality_factor
from Pulse Integral Data word
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
vector< uint16_t > samples
InitPlugin_t InitPlugin
uint32_t pulse_number
from Pulse Integral Data word
uint32_t integral
from Pulse Integral Data word
uint32_t pedestal
from Pulse Integral Data word (future)
uint32_t channel
Definition: DDAQAddress.h:34
uint32_t rocid
Definition: DDAQAddress.h:32
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
const int Nchannels
uint32_t itrigger
Definition: DDAQAddress.h:35
printf("string=%s", string)
uint32_t slot
Definition: DDAQAddress.h:33