Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_FDC_online.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_FCAL_online.cc
4 // Created: Fri Nov 9 11:58:09 EST 2012
5 // Creator: wolin (on Linux stan.jlab.org 2.6.32-279.11.1.el6.x86_64 x86_64)
6 
7 
8 #include <stdint.h>
9 #include <vector>
10 
11 
13 #include <JANA/JApplication.h>
14 
15 using namespace std;
16 using namespace jana;
17 
18 #include "FDC/DFDCHit.h"
19 #include "FDC/DFDCWireDigiHit.h"
20 #include "FDC/DFDCCathodeDigiHit.h"
21 #include "FDC/DFDCPseudo.h"
22 #include "DAQ/Df125PulsePedestal.h"
23 #include <DAQ/Df125PulseTime.h>
24 
25 #include <TMath.h>
26 #include <TDirectory.h>
27 #include <TH2.h>
28 #include <TH1.h>
29 
30 #define PI 3.14159265
31 #define TDC_v3BIN_SIZE 0.1118 // ns/LSB
32 //#define TDC_v3BIN_SIZE 1. // ns/LSB
33 
34 // root hist pointers
35 static TH1I *fdc_wire_occ[4][6];
36 static TH1I *fdc_cathode_occ[2][4][6];
37 static TH2I *fdc_cathode_time[2][4][6];
38 static TH2I *fdc_cathode_pulse_height[2][4][6];
39 static TH2F *fdc_occ_plane[24];
40 
41 static TH1I *fdc_num_events;
42 
43 static TH2I *fdcow;
44 static TH2I *fdcos;
45 
46 //------------------------------------------------------------------------------
47 // Routine used to create our JEventProcessor
48 extern "C"{
49  void InitPlugin(JApplication *app){
50  InitJANAPlugin(app);
51  app->AddProcessor(new JEventProcessor_FDC_online());
52  }
53 }
54 
55 
56 //------------------------------------------------------------------------------
58 }
59 
60 //------------------------------------------------------------------------------
62 }
63 //------------------------------------------------------------------------------
65 
66  // soft threshold
67  thresh=50; // threshold in f125 units (0-4096)
68 
69  wire_pitch=10.; // wire pitch in mm
70  strip_pitch_u=5.007; // average upper strip pitch in mm
71  strip_pitch_d=5.007; // average down strip pitch in mm
72  strip_angle=15.*PI/180.; // strip angle now in rads
73  cell_rot_step=60.*PI/180.; // cell rotation step now in rads
74 
75  // create root folder for fdc and cd to it, store main dir
76  TDirectory *main = gDirectory;
77  gDirectory->mkdir("FDC")->cd();
78 
79  // book hist
80  fdc_num_events = new TH1I("fdc_num_events","FDC Number of events",1, 0.5, 1.5);
81  fdcow = new TH2I("fdcow","FDC wire occupancy by wire,gLayer",96,0.5,96.5,
82  24,0.5,24.5);
83  fdcow->SetXTitle("wire number");
84  fdcow->SetYTitle("plane");
85  fdcos = new TH2I("fdcos","FDC strip occupancy by strip,plane",192,0.5,
86  192.5,48,0.5,48.5);
87  fdcos->SetXTitle("Strip number");
88  fdcos->SetYTitle("plane");
89 
90  for(int iPlane = 0; iPlane < 24; iPlane++){
91  char hname[256];
92  char htitle[256];
93  sprintf(hname, "fdc_occ_plane_%02d", iPlane);
94  sprintf(htitle, "FDC Occupancy Package %01d Cell %01d", (iPlane / 6) + 1, (iPlane % 6) + 1);
95  fdc_occ_plane[iPlane] = new TH2F(hname, htitle, 100, -50.0, 50.0, 100, -50.0, 50.0);
96  }
97 
98  for (unsigned k=0;k<4;k++){
99  char mypackagename[40];
100  int package=k+1;
101  sprintf(mypackagename,"Package_%d",package);
102  gDirectory->mkdir(mypackagename)->cd();
103 
104  char hname[80],htitle[80];
105  for (unsigned i=0;i<6;i++){
106  int chamber=i+1;
107 
108  sprintf(hname,"fdc_pack%d_chamber%d_wire_occ",package,chamber);
109  sprintf(htitle,"FDC wire occupancy for Package %d Chamber %d",package,
110  chamber);
111  fdc_wire_occ[k][i]=new TH1I(hname,htitle,96,0.5,96.5);
112  fdc_wire_occ[k][i]->SetXTitle("Wire number");
113 
114  sprintf(hname,"fdc_pack%d_chamber%d_upstream_cathode_occ",package,
115  chamber);
116  sprintf(htitle,"FDC upstream cathode occupancy for Package %d Chamber %d",
117  package,chamber);
118  fdc_cathode_occ[0][k][i]=new TH1I(hname,htitle,192,0.5,192.5);
119  fdc_cathode_occ[0][k][i]->SetXTitle("Strip number");
120 
121  sprintf(hname,"fdc_pack%d_chamber%d_upstream_cathode_time",package,
122  chamber);
123  sprintf(htitle,"FDC upstream cathode times for Package %d Chamber %d",
124  package,chamber);
125  fdc_cathode_time[0][k][i]=new TH2I(hname,htitle,200,0,200,192,0.5,192.5);
126  fdc_cathode_time[0][k][i]->SetXTitle("t");
127  fdc_cathode_time[0][k][i]->SetYTitle("Strip number");
128 
129  sprintf(hname,"fdc_pack%d_chamber%d_upstream_cathode_pulse_height",package,
130  chamber);
131  sprintf(htitle,"FDC upstream cathode pulse heights for Package %d Chamber %d",
132  package,chamber);
133  fdc_cathode_pulse_height[0][k][i]=new TH2I(hname,htitle,100,0,1000,192,0.5,192.5);
134  fdc_cathode_pulse_height[0][k][i]->SetXTitle("Pulse Height (ADC counts)");
135  fdc_cathode_pulse_height[0][k][i]->SetYTitle("Strip number");
136 
137 
138  sprintf(hname,"fdc_pack%d_chamber%d_downstream_cathode_occ",package,
139  chamber);
140  sprintf(htitle,"FDC downstream cathode occupancy for Package %d Chamber %d",
141  package,chamber);
142  fdc_cathode_occ[1][k][i]=new TH1I(hname,htitle,192,0.5,192.5);
143  fdc_cathode_occ[1][k][i]->SetXTitle("Strip number");
144 
145 
146  sprintf(hname,"fdc_pack%d_chamber%d_downstream_cathode_time",package,
147  chamber);
148  sprintf(htitle,"FDC downstream cathode times for Package %d Chamber %d",
149  package,chamber);
150  fdc_cathode_time[1][k][i]=new TH2I(hname,htitle,200,0,200,192,0.5,192.5);
151  fdc_cathode_time[1][k][i]->SetXTitle("t");
152  fdc_cathode_time[1][k][i]->SetYTitle("Strip number");
153 
154  sprintf(hname,"fdc_pack%d_chamber%d_downstream_cathode_pulse_height",package,
155  chamber);
156  sprintf(htitle,"FDC downstream cathode pulse heights for Package %d Chamber %d",
157  package,chamber);
158  fdc_cathode_pulse_height[1][k][i]=new TH2I(hname,htitle,100,0,1000,192,0.5,192.5);
159  fdc_cathode_pulse_height[1][k][i]->SetXTitle("Pulse Height (ADC counts)");
160  fdc_cathode_pulse_height[1][k][i]->SetYTitle("Strip number");
161  }
162 
163  gDirectory->cd("../");
164  }
165 
166  // back to main dir
167  main->cd();
168 
169  return NOERROR;
170 }
171 
172 
173 //------------------------------------------------------------------------------
174 jerror_t JEventProcessor_FDC_online::brun(JEventLoop *eventLoop, int32_t runnumber) {
175  // This is called whenever the run number changes
176  return NOERROR;
177 }
178 
179 //------------------------------------------------------------------------------
180 jerror_t JEventProcessor_FDC_online::evnt(JEventLoop *eventLoop, uint64_t eventnumber) {
181  // This is called for every event. Use of common resources like writing
182  // to a file or filling a histogram should be mutex protected. Using
183  // loop-Get(...) to get reconstructed objects (and thereby activating the
184  // reconstruction algorithm) should be done outside of any mutex lock
185  // since multiple threads may call this method at the same time.
186 
187  for(int pack=0;pack<4;pack++){
188  for(int cell=0;cell<6;cell++){
189  for(int wire=0;wire<96;wire++){
190  TDCnh[pack][cell][wire]=0;
191  for(int hit=0;hit<20;hit++){
192  TDCval[pack][cell][wire][hit]=-1000.;
193  }
194  }
195  for(int ud=0;ud<2;ud++){
196  for(int strip=0;strip<192;strip++){
197  ADCnh[pack][cell][ud][strip]=0;
198  for(int hit=0;hit<20;hit++){
199  ADCmax[pack][cell][ud][strip][hit]=-1000.;
200  ADCtime[pack][cell][ud][strip][hit]=-1000.;
201  }
202  }
203  }
204  }
205  }
206 
207  // get anode digis
208  vector<const DFDCWireDigiHit*>anodedigis;
209  eventLoop->Get(anodedigis);
210 
211  // Get cathode digis
212  vector<const DFDCCathodeDigiHit *>cathodedigis;
213  eventLoop->Get(cathodedigis);
214 
215  // Get Pseudo hits
216  vector<const DFDCPseudo *>fdcpseudohits;
217  eventLoop->Get(fdcpseudohits);
218 
219  // FILL HISTOGRAMS
220  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
221  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
222 
223  if( (anodedigis.size()>0) || (cathodedigis.size()>0) )
224  fdc_num_events->Fill(1);
225 
226  for(unsigned int i = 0; i < fdcpseudohits.size(); i++){
227  fdc_occ_plane[fdcpseudohits[i]->wire->layer - 1]->Fill(fdcpseudohits[i]->xy.X(),fdcpseudohits[i]->xy.Y());
228  }
229 
230  for (unsigned int i=0;i<cathodedigis.size();i++){
231  const DFDCCathodeDigiHit *digi=cathodedigis[i];
232 
233  int ud=0;
234  if(digi->view==3)ud=1;
235  int pack=digi->package-1;
236  int cell=digi->chamber-1;
237  int strip=digi->strip-1;
238 
239  const Df125PulsePedestal *pulseped;
240  digi->GetSingle(pulseped);
241 
242  if (pulseped!=NULL){
243  float peak=pulseped->pulse_peak;
244  float ped=pulseped->pedestal;
245  uint32_t p_pulse_num=pulseped->pulse_number;
246  if(peak>ped+thresh){
247  // cout<<" pack,cell,ud,strip,pn,peak="<<pack<<" "<<cell<<" "<<ud<<" "<<strip<<" "<<p_pulse_num<<" "<<peak-ped<<endl;
248  ADCmax[pack][cell][ud][strip][ADCnh[pack][cell][ud][strip]]=peak-ped;
249 
250  const Df125PulseTime *pulsetime;
251  digi->GetSingle(pulsetime);
252 
253  if(pulsetime!=NULL){
254  uint32_t t_pulse_num=pulsetime->pulse_number;
255  if(t_pulse_num==p_pulse_num){
256  //float time=pulsetime->time/64.;
257  float time=pulsetime->time/8;
258  ADCtime[pack][cell][ud][strip][ADCnh[pack][cell][ud][strip]]=time;
259  }
260  }
261  ADCnh[pack][cell][ud][strip]++;
262  }
263  }
264  }
265 
266  for (unsigned int i=0;i<anodedigis.size();i++){
267  const DFDCWireDigiHit *wdigi=anodedigis[i];
268  int pack=wdigi->package-1;
269  int cell=wdigi->chamber-1;
270  int wire=wdigi->wire-1;
271  int time=wdigi->time*TDC_v3BIN_SIZE/8.;
272  TDCval[pack][cell][wire][TDCnh[pack][cell][wire]]=time;
273  // cout<<" pack,cell,wire="<<pack<<" "<<cell<<" "<<wire<<endl;
274  TDCnh[pack][cell][wire]++;
275  }
276 
277  float val,val1,val2;
278  for (int pack=0;pack<4;pack++){
279  for (int cell=0;cell<6;cell++){
280  for (int wire=0;wire<96;wire++){
281  if(TDCval[pack][cell][wire][0]>0){
282  fdc_wire_occ[pack][cell]->Fill(wire);
283 
284  int plane=6*pack+cell+1;
285  fdcow->Fill(wire+1,plane);
286  } // end if tdc hit
287  } //end wire loop
288  } //end cell loop
289  } //end package loop
290 
291  for (int pack=0;pack<4;pack++){
292  for (int cell=0;cell<6;cell++){
293  for (int ud=0;ud<2;ud++){
294  for (int strip=0;strip<192;strip++){
295  val=ADCmax[pack][cell][ud][strip][0];
296  if(val>thresh){
297  val1=0;
298  if(strip>2)val1=ADCmax[pack][cell][ud][strip-1][0];
299  val2=0;
300  if(strip<191)val2=ADCmax[pack][cell][ud][strip+1][0];
301  if(val1>thresh||val2>thresh){
302  fdc_cathode_occ[ud][pack][cell]->Fill(strip);
303 
304  for (int nh=0;nh<ADCnh[pack][cell][ud][strip];nh++){
305  fdc_cathode_time[ud][pack][cell]->Fill(ADCtime[pack][cell][ud][strip][nh],strip);
306  fdc_cathode_pulse_height[ud][pack][cell]->Fill(ADCmax[pack][cell][ud][strip][nh],strip);
307 
308  int plane=12*pack+2*cell+ud+1;
309  fdcos->Fill(strip+1,plane);
310  }
311  } //end if val>thresh
312  } //end if val1,2>thresh
313  } //end strip loop
314  } //end ud loop
315  } //end cell loop
316  } //end package loop
317 
318  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
319 
320  return NOERROR;
321 }
322 
323 
324 //------------------------------------------------------------------------------
326  // This is called whenever the run number changes, before it is
327  // changed to give you a chance to clean up before processing
328  // events from the next run number.
329  return NOERROR;
330 }
331 
332 //------------------------------------------------------------------------------
334  // Called before program exit after event processing is finished.
335  return NOERROR;
336 }
337 
338 //------------------------------------------------------------------------------
static TH2I * fdcos
static TH2I * fdcow
static TH2F * fdc_occ_plane[24]
static TH2I * fdc_cathode_time[2][4][6]
static TH1I * fdc_num_events
uint32_t pulse_peak
from Pulse Pedestal Data word
sprintf(text,"Post KinFit Cut")
static TH1I * fdc_cathode_occ[2][4][6]
static TH2I * fdc_cathode_pulse_height[2][4][6]
#define TDC_v3BIN_SIZE
JApplication * japp
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
static TH1I * fdc_wire_occ[4][6]
uint32_t pulse_number
from Pulse Time Data word
jerror_t init(void)
Called once at program start.
jerror_t fini(void)
Called after last event of last event source has been processed.
InitPlugin_t InitPlugin
uint32_t time
from Pulse Time Data word
uint32_t pulse_number
from Pulse Pedestal Data word
uint32_t pedestal
from Pulse Pedestal Data word
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
int main(int argc, char *argv[])
Definition: gendoc.cc:6