Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_CDC_online.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_CDC_online.cc
4 // Created: Wed Oct 22 2014
5 // Creator: Naomi Jarvis
6 
7 
8 #include <stdint.h>
9 #include <vector>
10 
11 #include <TMath.h>
12 
13 
15 #include <JANA/JApplication.h>
16 
17 
18 using namespace std;
19 using namespace jana;
20 
21 
22 #include "CDC/DCDCHit.h"
23 #include "CDC/DCDCDigiHit.h"
24 #include "DAQ/Df125PulseIntegral.h"
25 #include "DAQ/Df125PulsePedestal.h"
26 #include "DAQ/Df125WindowRawData.h"
27 #include "DAQ/Df125CDCPulse.h"
28 #include "DAQ/Df125Config.h"
29 #include "TRIGGER/DTrigger.h"
30 
31 #include <TDirectory.h>
32 #include <TH2.h>
33 #include <TH1.h>
34 
35 
36 // root hist pointers
37 
38 static TH1I *cdc_num_events = NULL;
39 
40 static TH2I *cdc_o = NULL;
41 static TH2D *cdc_occ_ring[29];
42 
43 static TH1I *cdc_raw_amp = NULL;
44 static TH2I *cdc_raw_amp_vs_n = NULL;
45 
46 static TH1I *cdc_raw_t;
47 static TH2I *cdc_raw_t_vs_n;
48 
49 static TH1I *cdc_raw_intpp; //raw integral including pedestal
50 static TH2I *cdc_raw_intpp_vs_n;
51 
52 static TH1I *cdc_raw_int; //raw integral minus pedestal
53 static TH2I *cdc_raw_int_vs_n;
54 
55 static TH1I *cdc_ped = NULL;
56 static TH2I *cdc_ped_vs_n = NULL;
57 
58 static TH1I *cdc_windata_ped = NULL;
59 static TH2I *cdc_windata_ped_vs_n = NULL;
60 
61 
62 
63 
64 //----------------------------------------------------------------------------------
65 
66 
67 // Routine used to create our JEventProcessor
68 extern "C"{
69  void InitPlugin(JApplication *app){
70  InitJANAPlugin(app);
71  app->AddProcessor(new JEventProcessor_CDC_online());
72  }
73 }
74 
75 
76 //----------------------------------------------------------------------------------
77 
78 
80  initialized_histograms = false;
81 }
82 
83 
84 //----------------------------------------------------------------------------------
85 
86 
88 }
89 
90 
91 //----------------------------------------------------------------------------------
92 
94 
95  // I moved all the histogram setup into the brun so that I can use different
96  // scales for the later runs using the new firmware
97 
98 
99  // create root folder for cdc and cd to it, store main dir
100  TDirectory *main = gDirectory;
101  gDirectory->mkdir("CDC")->cd();
102 
103 
104  cdc_num_events = new TH1I("cdc_num_events","CDC number of events",1, 0.5, 1.5);
105 
106  cdc_o = new TH2I("cdc_o","CDC occupancy by straw, ring;straw;ring",209,0.5,209.5,28,0.5,28.5);
107 
108 
109  gDirectory->mkdir("rings_occupancy","CDC rings: occupancy")->cd();
110 
111 
112  // Hit occupancy
113  int Nstraws[28] = {42, 42, 54, 54, 66, 66, 80, 80, 93, 93, 106, 106, 123, 123, 135, 135, 146, 146, 158, 158, 170, 170, 182, 182, 197, 197, 209, 209};
114  double radius[28] = {10.72134, 12.08024, 13.7795, 15.14602, 18.71726, 20.2438, 22.01672, 23.50008, 25.15616, 26.61158, 28.33624, 29.77388, 31.3817, 32.75838, 34.43478, 35.81146, 38.28542, 39.7002, 41.31564, 42.73042, 44.34078, 45.75302, 47.36084, 48.77054, 50.37582, 51.76012, 53.36286, 54.74716};
115  double phi[28] = {0, 0.074707844, 0.038166294, 0.096247609, 0.05966371, 0.012001551, 0.040721951, 0.001334527, 0.014963808, 0.048683644, 0.002092645, 0.031681749, 0.040719354, 0.015197341, 0.006786058, 0.030005892, 0.019704045, -0.001782064, -0.001306618, 0.018592421, 0.003686784, 0.022132975, 0.019600866, 0.002343723, 0.021301449, 0.005348855, 0.005997358, 0.021018761};
116 
117  // Define a different 2D histogram for each ring. X-axis is phi, Y-axis is radius (to plot correctly with "pol" option)
118  for(int iring=0; iring<28; iring++){
119  double r_start = radius[iring] - 0.8;
120  double r_end = radius[iring] + 0.8;
121  double phi_start = phi[iring]; // this is for center of straw. Need additional calculation for phi at end plate
122  double phi_end = phi_start + TMath::TwoPi();
123 
124  char hname[256];
125  sprintf(hname, "cdc_occ_ring[%d]", iring+1);
126  cdc_occ_ring[iring+1] = new TH2D(hname, "", Nstraws[iring], phi_start, phi_end, 1, r_start, r_end);
127  }
128 
129 
130  // back to main dir
131  main->cd();
132 
133 
134  return NOERROR;
135 }
136 
137 
138 //----------------------------------------------------------------------------------
139 
140 
141 jerror_t JEventProcessor_CDC_online::brun(JEventLoop *eventLoop, int32_t runnumber) {
142  // This is called whenever the run number changes
143 
144  // max values for histogram scales, modified fa250-format readout
145 
146 
147  Int_t AMAX = 4096; //max for amplitude, fa250-format, 12 bits
148 
149  // Int_t IMAX = 524288; //max for raw integral, fa250-format, 19 bits
150  Int_t IMAX = 400000; //max for raw integral, fa250-format, 19 bits
151 
152  Int_t PMAX = 512; //max for pedestal, fa250-format max is 512
153  // Int_t RTMAX = 32768; //max for raw time, fa250-format, 15 bits
154  Int_t RTMAX = 12000; //max for raw time, less than full field width
155 
156  Char_t rtunits[8] = "0.125ns"; //raw time is in units of sample/64 = ns/8
157 
158 
159 
160  if (runnumber > 3675) { //new fa125 format firmware, from 11 Sept 2015
161 
162 
163  // raw quantities for read out (125 format) are
164  // time field max 2047 scaled x 1, units 0.8ns
165  // time qf field max 1
166  // overflow count field max 7
167  // pedestal field max 255 scaled x 1/1 initially
168  // max amplitude 9 bits, field max 511 scaled x 1/8
169  // integral field max 16383 scaled x 1/16
170 
171  // max values for histogram scales, fa125-format readout
172 
173  IMAX = 16384; //max for raw integral, fa125-format, 14 bits
174  PMAX = 256; //max for pedestal, fa125-format, 8 bits
175  RTMAX = 2048; //max for raw time, fa125-format, 11 bits
176  AMAX = 512; //max for amplitude, fa125-format, 9 bits
177 
178  sprintf(rtunits,"0.8ns"); //raw time is in units of sample/10 = 0.8ns
179 
180  }
181 
182 
183  const Int_t NSTRAWS = 3522;
184  const Float_t HALF = 0.5;
185  const Float_t NSTRAWSPH = 3522.5;
186 
187  japp->RootWriteLock(); //ACQUIRE ROOT LOCK!!
188 
189  if(initialized_histograms) //don't init twice!
190  {
191  japp->RootUnLock(); //RELEASE ROOT LOCK
192  return NOERROR;
193  }
194 
195  gDirectory->cd("CDC");
196 
197  // book histograms
198 
199  cdc_raw_amp = new TH1I("cdc_raw_amp","CDC amplitude (ADC units, scaled); ADC units",AMAX,0,AMAX);
200 
201  cdc_raw_amp_vs_n = new TH2I("cdc_raw_amp_vs_n","CDC amplitude (ADC units, scaled) vs straw number;straw;ADC units",NSTRAWS,HALF,NSTRAWSPH,128,0,AMAX);
202 
203  cdc_raw_t = new TH1I("cdc_raw_t",Form("CDC raw time (units of %s); raw time (%s)",rtunits,rtunits),200,0,RTMAX);
204 
205  cdc_raw_t_vs_n = new TH2I("cdc_raw_t_vs_n",Form("CDC raw time (units of %s) vs straw number;straw;time (%s)",rtunits,rtunits),NSTRAWS,HALF,NSTRAWSPH,100,0,RTMAX);
206 
207  cdc_raw_int = new TH1I("cdc_raw_int","CDC integral (ADC units, scaled), pedestal subtracted; ADC units",200,0,IMAX);
208 
209  cdc_raw_int_vs_n = new TH2I("cdc_raw_int_vs_n","CDC integral (ADC units,scaled), pedestal subtracted, vs straw number;straw;ADC units",NSTRAWS,HALF,NSTRAWSPH,100,0,IMAX);
210 
211  cdc_raw_intpp = new TH1I("cdc_raw_intpp","CDC integral (ADC units, scaled), includes pedestal; ADC units",200,0,IMAX);
212 
213  cdc_raw_intpp_vs_n = new TH2I("cdc_raw_intpp_vs_n","CDC integral (ADC units, scaled), including pedestal, vs straw number;straw;ADC units",NSTRAWS,HALF,NSTRAWSPH,100,0,IMAX);
214 
215  cdc_ped = new TH1I("cdc_ped","CDC pedestal (ADC units);pedestal (ADC units)",(Int_t)(PMAX/2),0,PMAX);
216 
217  cdc_ped_vs_n = new TH2I("cdc_ped_vs_n","CDC pedestal (ADC units) vs straw number;straw;pedestal (ADC units)",NSTRAWS,HALF,NSTRAWSPH,(Int_t)(PMAX/4),0,PMAX);
218 
219  cdc_windata_ped = new TH1I("cdc_windata_ped","CDC pedestal (ADC units) from raw window data;pedestal (ADC units)",(Int_t)(PMAX/2),0,PMAX);
220 
221  cdc_windata_ped_vs_n = new TH2I("cdc_windata_ped_vs_n","CDC pedestal (ADC units) from raw window data vs straw number;straw;pedestal (ADC units)",NSTRAWS,HALF,NSTRAWSPH,(Int_t)(PMAX/4),0,PMAX);
222 
223  gDirectory->cd(".."); //RETURN TO MAIN FOLDER
224 
225  initialized_histograms = true;
226 
227  japp->RootUnLock(); //RELEASE ROOT LOCK
228 
229 
230  return NOERROR;
231 }
232 
233 
234 //----------------------------------------------------------------------------------
235 
236 
237 jerror_t JEventProcessor_CDC_online::evnt(JEventLoop *eventLoop, uint64_t eventnumber) {
238  // This is called for every event. Use of common resources like writing
239  // to a file or filling a histogram should be mutex protected. Using
240  // loop-Get(...) to get reconstructed objects (and thereby activating the
241  // reconstruction algorithm) should be done outside of any mutex lock
242  // since multiple threads may call this method at the same time.
243 
244 
245  uint32_t tr,p,a; // dcdcdigihits raw quantities: time, pedestal, amplitude, quality factor, overflow count
246  uint32_t integral; // dcdcdigihits integral, includes pedestal
247  uint32_t integ; // dcdcdigihits integral minus pedestal
248 
249  uint16_t ring,straw; // ring and straw numbers from either dcdchits or dcdcdigihits
250  uint16_t n; // straw number, 1 to 3522
251 
252  uint32_t total_ped; //total pedestal during integration period
253 
254  Bool_t PED_SUB; // if this is false, integration window info is missing, so don't plot integrals
255 
256 
257  uint32_t nsamples_integral=0; ///< number of samples used in integral
258  uint32_t nsamples_pedestal=0; ///< number of samples used in pedestal
259 
260  const uint16_t NPEDSAMPLES=16;
261 
262 // Bool_t FoundRawData=kFALSE; //set true if found window raw data, present in mode 8 and raw mode
263 
264  //add extra 0 at front to use offset[1] for ring 1
265  int straw_offset[29] = {0,0,42,84,138,192,258,324,404,484,577,670,776,882,1005,1128,1263,1398,1544,1690,1848,2006,2176,2346,2528,2710,2907,3104,3313};
266 
267 
268  const DTrigger* locTrigger = NULL;
269  eventLoop->GetSingle(locTrigger);
270  if(locTrigger->Get_L1FrontPanelTriggerBits() != 0)
271  return NOERROR;
272  if (!locTrigger->Get_IsPhysicsEvent()){ // do not look at PS triggers
273  return NOERROR;
274  }
275 
276 
277  // get raw data for cdc
278  vector<const DCDCDigiHit*> digihits;
279  eventLoop->Get(digihits);
280 
281  //get WRD data for new format (until it is linked to CDCPulse)
282  vector<const Df125WindowRawData*> wrdvector;
283  eventLoop->Get(wrdvector);
284 
285 
286 
287  // FILL HISTOGRAMS
288  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
289  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
290 
291  if(digihits.size() > 0)
292  cdc_num_events->Fill(1);
293 
294  for(uint32_t i=0; i<digihits.size(); i++) {
295 
296  const DCDCDigiHit *digihit = digihits[i];
297 
298  // Get pointers to the underlying objects of interest
299  const Df125PulseIntegral *pi = NULL;
300  const Df125PulsePedestal *pp = NULL;
301  const Df125WindowRawData *windat = NULL;
302  const Df125CDCPulse *cp = NULL;
303  const Df125Config *cf = NULL;
304 
305  vector<uint16_t> samples;
306  uint32_t winped=0;
307 
308 
309 
310  PED_SUB = kFALSE; //set this to true when we find the config params
311  total_ped = 0;
312  a = 0;
313 
314  //get raw window data via pulse integral
315  digihit->GetSingle(pi);
316  if (pi) {
317  pi->GetSingle(windat);
318 
319  nsamples_integral = pi ? pi->nsamples_integral : 0;
320  nsamples_pedestal = pi ? pi->nsamples_pedestal : 0;
321 
322  if ((nsamples_integral > 0) && (nsamples_pedestal > 0)) PED_SUB = kTRUE;
323 
324  } else if (i < (uint32_t)wrdvector.size()) {
325  windat = wrdvector[i];
326  }
327 
328  //get amplitude from pulse peak in pulse pedestal
329  digihit->GetSingle(pp);
330  if (pp) a = pp->pulse_peak;
331 
332  //get amplitude from CDCPulseData for new firmware
333  digihit->GetSingle(cp);
334  if (cp) a = cp->first_max_amp;
335 
336  //get IE from Df125Config when available
337  digihit->GetSingle(cf);
338  if (cf) nsamples_integral = cf->IE - (int)(0.1*digihit->pulse_time);
339 
340 
341  ring = digihit->ring;
342  straw = digihit->straw;
343  n = straw_offset[ring] + straw;
344 
345  if ((digihit->pulse_integral > 0)||(digihit->pulse_time > 0)) {
346 
347  p = digihit->pedestal;
348  tr = digihit->pulse_time; // raw time in 0.8 ns units
349  integral = digihit->pulse_integral; // pulse integral in fadc units, pedestal not subtracted
350 
351 
352  cdc_o->Fill(straw,ring);
353 
354  Double_t w = cdc_occ_ring[ring]->GetBinContent(straw, 1) + 1.0;
355  cdc_occ_ring[ring]->SetBinContent(straw, 1, w);
356 
357 
358  integ = 0;
359 
360  //ok to use p for pedestal subtraction here because if fa250 algo fails with p=0, integral=0 and amplitude=0 also
361 
362  if (PED_SUB) {
363  total_ped = p*nsamples_integral/nsamples_pedestal;
364  integ = integral - total_ped;
365  }
366 
367  if (tr>0) {
368  cdc_raw_t->Fill(tr);
369  cdc_raw_t_vs_n->Fill(n,tr);
370  }
371 
372 
373  if (PED_SUB && (integ>0)) {
374  cdc_raw_int->Fill(integ);
375  cdc_raw_int_vs_n->Fill(n,integ);
376  }
377 
378  if (integral>0) {
379  cdc_raw_intpp->Fill(integral);
380  cdc_raw_intpp_vs_n->Fill(n,integral);
381  }
382 
383  if (p > 0) {
384  cdc_ped->Fill(p);
385  cdc_ped_vs_n->Fill(n,p);
386  }
387 
388  if (a > 0) {
389  //a = a - p; //not subtracting pedestal as scaling factors may differ
390  cdc_raw_amp->Fill(a);
391  cdc_raw_amp_vs_n->Fill(n,a);
392  }
393 
394 
395  }
396 
397  // get raw window data for cdc
398 
399  if (windat) {
400 
401  if (windat->samples.size()>=NPEDSAMPLES) {
402 
403 // FoundRawData = kTRUE;
404 
405  winped = 0;
406 
407  for (uint16_t i=0; i<NPEDSAMPLES; i++) winped += (uint32_t)windat->samples[i];
408 
409  winped = (uint32_t)winped/16.0;
410 
411  if (winped > 0) {
412  cdc_windata_ped->Fill(winped);
413  cdc_windata_ped_vs_n->Fill(n,winped);
414  }
415 
416  }//sample size
417  } //windat
418 
419  } //end of loop through digihits
420 
421  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
422 
423  return NOERROR;
424 }
425 
426 
427 //----------------------------------------------------------------------------------
428 
429 
431  // This is called whenever the run number changes, before it is
432  // changed to give you a chance to clean up before processing
433  // events from the next run number.
434  return NOERROR;
435 }
436 
437 
438 //----------------------------------------------------------------------------------
439 
440 
442  // Called before program exit after event processing is finished.
443 
444 
445 
446  return NOERROR;
447 }
448 
449 
450 //----------------------------------------------------------------------------------
451 //----------------------------------------------------------------------------------
TH1I * cdc_windata_ped
Definition: CDC_overview.C:26
uint32_t first_max_amp
from second word
Definition: Df125CDCPulse.h:68
uint32_t nsamples_integral
number of samples used in integral
jerror_t init(void)
Called once at program start.
TH2D * cdc_raw_t_vs_n
Definition: CDC_overview.C:29
uint32_t nsamples_pedestal
number of samples used in pedestal
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
const double PMAX
uint32_t pulse_peak
from Pulse Pedestal Data word
sprintf(text,"Post KinFit Cut")
static TH1I * cdc_raw_amp
uint16_t IE
Definition: Df125Config.h:40
uint32_t Get_L1FrontPanelTriggerBits(void) const
TH2I * cdc_ped_vs_n
Definition: CDC_overview.C:30
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
static TH2I * cdc_raw_int_vs_n
JApplication * japp
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
Definition: DCDCDigiHit.h:22
bool Get_IsPhysicsEvent(void) const
InitPlugin_t InitPlugin
static TH1I * cdc_raw_int
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
Definition: DCDCDigiHit.h:21
vector< uint16_t > samples
jerror_t fini(void)
Called after last event of last event source has been processed.
TH2I * cdc_windata_ped_vs_n
Definition: CDC_overview.C:31
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
TH1D * cdc_raw_t
Definition: CDC_overview.C:24
static TH1I * cdc_num_events
TH1I * cdc_ped
Definition: CDC_overview.C:25
static TH2I * cdc_raw_amp_vs_n
TH1D * cdc_raw_intpp
Definition: CDC_overview.C:23
static TH2I * cdc_o
static TH2D * cdc_occ_ring[29]
TCanvas * cp
uint32_t pedestal
pedestal info used by FPGA (if any)
Definition: DCDCDigiHit.h:23
TH2D * cdc_raw_intpp_vs_n
Definition: CDC_overview.C:28
int main(int argc, char *argv[])
Definition: gendoc.cc:6