Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_TPOL_tree.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_TPOL_tree.cc
4 // Created: Thu Feb 4 16:11:54 EST 2016
5 // Creator: nsparks (on Linux cua2.jlab.org 3.10.0-327.4.4.el7.x86_64 x86_64)
6 //
7 #include <iostream>
8 #include <cmath>
9 #include <stdint.h>
11 using namespace jana;
12 using namespace std;
13 
14 #include <TRIGGER/DL1Trigger.h>
15 #include <TPOL/DTPOLHit_factory.h>
19 #include <TAGGER/DTAGHHit.h>
20 #include <TAGGER/DTAGMHit.h>
21 #include <TAGGER/DTAGHGeometry.h>
22 #include <TAGGER/DTAGMGeometry.h>
23 #include <PID/DBeamPhoton.h>
24 #include <PID/DEventRFBunch.h>
25 #include <DAQ/DBeamCurrent.h>
26 
33 const bool VERBOSE = false;
34 
35 // Routine used to create our JEventProcessor
36 #include <JANA/JApplication.h>
37 #include <JANA/JFactory.h>
38 #include <TH1.h>
39 #include <TH2.h>
40 #include <TDirectory.h>
41 #include <TVector3.h>
42 
43 extern "C"{
44  void InitPlugin(JApplication *app){
45  InitJANAPlugin(app);
46  app->AddProcessor(new JEventProcessor_TPOL_tree());
47  }
48 } // "C"
49 
51 
52 //------------------
53 // JEventProcessor_TPOL_tree (Constructor)
54 //------------------
56 {
57 
58 }
59 
60 //------------------
61 // ~JEventProcessor_TPOL_tree (Destructor)
62 //------------------
64 {
65 
66 }
67 
68 //------------------
69 // init
70 //------------------
72 {
73  // This is called once at program startup. If you are creating
74  // and filling historgrams in this plugin, you should lock the
75  // ROOT mutex like this:
76  //
77 
78  t= clock();
79 
80  // Construct DTreeInterface and register branches for TPOL tree
81  double locNumTAGHhits = 500;
82  double locNumTAGMhits = 200;
83  double locNumPShits = 200;
84  double locNumRFhits = 200;
85 
86  dTreeInterface = DTreeInterface::Create_DTreeInterface("TPOL_tree","tree_TPOL.root");
87  DTreeBranchRegister locTreeBranchRegister;
88 
89  locTreeBranchRegister.Register_Single<UShort_t>("nadc");
90  locTreeBranchRegister.Register_Single<ULong64_t>("eventnum");
91  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("rocid","nadc",NSECTORS);
92  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("slot","nadc",NSECTORS);
93  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("channel","nadc",NSECTORS);
94  locTreeBranchRegister.Register_FundamentalArray<UInt_t>("itrigger","nadc",NSECTORS);
95  locTreeBranchRegister.Register_FundamentalArray<ULong64_t>("w_integral","nadc",NSECTORS);
96  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("w_max","nadc",NSECTORS);
97  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("w_min","nadc",NSECTORS);
98  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("i_w_max","nadc",NSECTORS);
99  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("i_w_min","nadc",NSECTORS);
100  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("w_samp1","nadc",NSECTORS);
101  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("sector","nadc",NSECTORS);
102  locTreeBranchRegister.Register_FundamentalArray<Double_t>("phi","nadc",NSECTORS);
103  locTreeBranchRegister.Register_Single<UShort_t>("ntpol");
104  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("waveform","ntpol",NSECTORS*150);
105  locTreeBranchRegister.Register_Single<Bool_t>("isFiducial");
106  locTreeBranchRegister.Register_Single<UShort_t>("nPSC");
107  locTreeBranchRegister.Register_FundamentalArray<Double_t>("PSCtime_lhit","nPSC",locNumPShits);
108  locTreeBranchRegister.Register_FundamentalArray<Double_t>("PSCtime_rhit","nPSC",locNumPShits);
109  locTreeBranchRegister.Register_FundamentalArray<Int_t>("PSCmodule_lhit","nPSC",locNumPShits);
110  locTreeBranchRegister.Register_FundamentalArray<Int_t>("PSCmodule_rhit","nPSC",locNumPShits);
111  locTreeBranchRegister.Register_Single<UShort_t>("nPS");
112  locTreeBranchRegister.Register_FundamentalArray<Double_t>("PSenergy_lhit","nPS",locNumPShits);
113  locTreeBranchRegister.Register_FundamentalArray<Double_t>("PSenergy_rhit","nPS",locNumPShits);
114  locTreeBranchRegister.Register_FundamentalArray<Double_t>("PStime_lhit","nPS",locNumPShits);
115  locTreeBranchRegister.Register_FundamentalArray<Double_t>("PStime_rhit","nPS",locNumPShits);
116  locTreeBranchRegister.Register_FundamentalArray<Int_t>("PScolumn_lhit","nPS",locNumPShits);
117  locTreeBranchRegister.Register_FundamentalArray<Int_t>("PScolumn_rhit","nPS",locNumPShits);
118  locTreeBranchRegister.Register_Single<UShort_t>("ntagh");
119  locTreeBranchRegister.Register_FundamentalArray<Bool_t>("TAGH_DBeam","ntagh",locNumTAGHhits);
120  locTreeBranchRegister.Register_FundamentalArray<Double_t>("TAGHenergy","ntagh",locNumTAGHhits);
121  locTreeBranchRegister.Register_FundamentalArray<Double_t>("TAGHtime","ntagh",locNumTAGHhits);
122  locTreeBranchRegister.Register_FundamentalArray<UInt_t>("TAGHcounter","ntagh",locNumTAGHhits);
123  locTreeBranchRegister.Register_Single<UShort_t>("ntagm");
124  locTreeBranchRegister.Register_FundamentalArray<Bool_t>("TAGM_DBeam","ntagm",locNumTAGMhits);
125  locTreeBranchRegister.Register_FundamentalArray<Double_t>("TAGMenergy","ntagm",locNumTAGMhits);
126  locTreeBranchRegister.Register_FundamentalArray<Double_t>("TAGMtime","ntagm",locNumTAGMhits);
127  locTreeBranchRegister.Register_FundamentalArray<UInt_t>("TAGMcolumn","ntagm",locNumTAGMhits);
128  locTreeBranchRegister.Register_Single<UShort_t>("nRF");
129  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("RFDetSys","nRF",locNumRFhits);
130  locTreeBranchRegister.Register_FundamentalArray<Double_t>("RFTime","nRF",locNumRFhits);
131  locTreeBranchRegister.Register_FundamentalArray<Double_t>("RFTimeVar","nRF",locNumRFhits);
132  locTreeBranchRegister.Register_FundamentalArray<UShort_t>("RFNumParticleVotes","nRF",locNumRFhits);
133  dTreeInterface->Create_Branches(locTreeBranchRegister);
134 
135  count = 0;
136 
137  //
138  return NOERROR;
139 }
140 
141 //------------------
142 // brun
143 //------------------
144 jerror_t JEventProcessor_TPOL_tree::brun(JEventLoop *eventLoop, int32_t runnumber)
145 {
146  // This is called whenever the run number changes
147  // Set up beam current factory for is_Fiducial
148  dBeamCurrentFactory = new DBeamCurrent_factory();
149  dBeamCurrentFactory->init();
150  dBeamCurrentFactory->brun(eventLoop, runnumber);
151 
152  // Set up beam period for beam bunches
153  //vector<double> locBeamPeriodVector;
154  //eventLoop->GetCalib("PHOTON_BEAM/RF/beam_period",locBeamPeriodVector);
155  //dBeamBunchPeriod = locBeamPeriodVector[0];
156 
157  return NOERROR;
158 }
159 
160 //------------------
161 // evnt
162 //------------------
163 jerror_t JEventProcessor_TPOL_tree::evnt(JEventLoop *loop, uint64_t eventnumber)
164 {
165  // This is called for every event. Use of common resources like writing
166  // to a file or filling a histogram should be mutex protected. Using
167  // loop->Get(...) to get reconstructed objects (and thereby activating the
168  // reconstruction algorithm) should be done outside of any mutex lock
169  // since multiple threads may call this method at the same time.
170 
171  //if (count > 10000) return NOERROR;
172 
173  // Construct trigger information
174  const DL1Trigger *trig_words = NULL;
175  uint32_t trig_mask, fp_trig_mask;
176  try {
177  loop->GetSingle(trig_words);
178  } catch(...) {};
179  if (trig_words) {
180  trig_mask = trig_words->trig_mask;
181  fp_trig_mask = trig_words->fp_trig_mask;
182  }
183  else {
184  trig_mask = 0;
185  fp_trig_mask = 0;
186  }
187  int trig_bits = fp_trig_mask > 0 ? 10 + fp_trig_mask:trig_mask;
188  // skim PS triggers
189  if (trig_bits!=8) {
190  return NOERROR;
191  }
192 
193  //Get RF bunch information
194  vector<const DEventRFBunch*> rfBunch;
195  loop->Get(rfBunch);
196 
197  // Get fADC 250 windowraws
198  vector<const Df250WindowRawData*> windowraws;
199  loop->Get(windowraws);
200 
201  // Get coarse PS pairs
202  vector<const DPSCPair*> cpairs;
203  loop->Get(cpairs);
204 
205  // Get fine PS pairs
206  vector<const DPSPair*> fpairs;
207  loop->Get(fpairs);
208 
209  // Get TAGH hits
210  vector<const DTAGHHit*> taghhits;
211  loop->Get(taghhits);
212 
213  // Get TAGM hits
214  vector<const DTAGMHit*> tagmhits;
215  loop->Get(tagmhits);
216 
217  // Get beam photons
218  vector<const DBeamPhoton*> beamPhotons;
219  loop->Get(beamPhotons);
220 
221  // Get beam current
222  vector<const DBeamCurrent*> beamCurrent;
223  loop->Get(beamCurrent);
224 
225  japp->RootFillLock(this);
226  if (!beamCurrent.empty())
227  {
228  // Check that photons are is_Fiducial
229  Bool_t isFiducial = beamCurrent[0]->is_fiducial;
230  dTreeFillData.Fill_Single<Bool_t>("isFiducial",isFiducial);
231  }
232 
233  // PSC coincidences
234 
235  //if (cpairs.size()<1 || fpairs.size()<1) return NOERROR;
236 
237  dTreeFillData.Fill_Single<ULong64_t>("eventnum",eventnumber);
238 
239  // loop over RF hits and save
240  unsigned int nRF = rfBunch.size();
241  dTreeFillData.Fill_Single<UShort_t>("nRF",nRF);
242  for (unsigned int i_RF = 0; i_RF < nRF; i_RF++)
243  {
244  dTreeFillData.Fill_Array<Double_t>("RFTime",rfBunch[i_RF]->dTime,i_RF);
245  dTreeFillData.Fill_Array<Double_t>("RFTimeVar",rfBunch[i_RF]->dTimeVariance,i_RF);
246  dTreeFillData.Fill_Array<UShort_t>("RFNumParticleVotes",rfBunch[i_RF]->dNumParticleVotes,i_RF);
247  }
248 
249  // take pair with smallest time difference from sorted vector
250  unsigned int nPSC = cpairs.size();
251  dTreeFillData.Fill_Single<UShort_t>("nPSC",nPSC);
252  for (unsigned int i_PSC = 0; i_PSC < nPSC; i_PSC++)
253  {
254  const DPSCHit* clhit = cpairs[i_PSC]->ee.first; // left hit in coarse PS
255  const DPSCHit* crhit = cpairs[i_PSC]->ee.second;// right hit in coarse PS
256 
257  dTreeFillData.Fill_Array<Double_t>("PSCtime_lhit",clhit->t,i_PSC);
258  dTreeFillData.Fill_Array<Double_t>("PSCtime_rhit",crhit->t,i_PSC);
259  dTreeFillData.Fill_Array<Int_t>("PSCmodule_lhit",clhit->module,i_PSC);
260  dTreeFillData.Fill_Array<Int_t>("PSCmodule_rhit",crhit->module,i_PSC);
261  }
262 
263  // Removed check on ensuring the pair are well timed
264 
265  // PSC,PS coincidences
266  // take pair with smallest time difference from sorted vector
267  unsigned int nPS = fpairs.size();
268  dTreeFillData.Fill_Single<UShort_t>("nPS",nPS);
269  for (unsigned int i_PS = 0; i_PS < nPS; i_PS++)
270  {
271  //const DPSPair::PSClust*
272  const DPSPair::PSClust* flhit = fpairs[i_PS]->ee.first; // left hit in fine PS
273  //const DPSPair::PSClust*
274  const DPSPair::PSClust* frhit = fpairs[i_PS]->ee.second; // right hit in fine PS
275 
276  dTreeFillData.Fill_Array<Double_t>("PSenergy_lhit",flhit->E,i_PS);
277  dTreeFillData.Fill_Array<Double_t>("PSenergy_rhit",frhit->E,i_PS);
278  dTreeFillData.Fill_Array<Double_t>("PStime_lhit",flhit->t,i_PS);
279  dTreeFillData.Fill_Array<Double_t>("PStime_rhit",frhit->t,i_PS);
280  dTreeFillData.Fill_Array<Int_t>("PScolumn_lhit",flhit->column,i_PS);
281  dTreeFillData.Fill_Array<Int_t>("PScolumn_rhit",frhit->column,i_PS);
282 
283  /** if(flhit->column < geomModuleColumn[clhit->module-1][0] || flhit->column > geomModuleColumn[clhit->module-1][1])
284  {
285  japp->RootFillUnLock(this);
286  return NOERROR;
287  }
288  if(frhit->column < geomModuleColumn[crhit->module-1][0] || frhit->column > geomModuleColumn[crhit->module-1][1])
289  {
290  japp->RootFillUnLock(this);
291  return NOERROR;
292  }**/
293  }
294 
295  // Loop over TAGH hits and match to DBeamPhotons
296  unsigned int htag = 0;
297  unsigned int htag_DBeam = 0;
298  for (unsigned int i=0; i < taghhits.size(); i++) {
299  const DTAGHHit* tag = taghhits[i];
300  if (!tag->has_TDC||!tag->has_fADC) continue;
301  if (std::isnan(tag->t) || std::isnan(tag->E)) continue;
302  dTreeFillData.Fill_Array<Double_t>("TAGHenergy",tag->E,htag);
303  dTreeFillData.Fill_Array<Double_t>("TAGHtime",tag->t,htag);
304  dTreeFillData.Fill_Array<UInt_t>("TAGHcounter",tag->counter_id,htag);
305  unsigned int same = 0;
306  for (unsigned int j=0; j < beamPhotons.size(); j++)
307  {
308  const DTAGHHit* tagh;
309  beamPhotons[j]->GetSingle(tagh);
310  if (!tagh) continue;
311  if (!tagh->has_TDC || !tagh->has_fADC) continue;
312  if (std::isnan(tagh->t) || std::isnan(tagh->E))
313  {
314  if (VERBOSE) jerr<<"Found TAGH with NAN."<<tagh->counter_id<<endl;
315  continue;
316  }
317  if (tagh->t != tag->t || tagh->E != tag->E || tagh->counter_id != tag->counter_id) continue;
318  same++;
319  htag_DBeam++;
320  }
321  if (same > 1 && VERBOSE) jerr<<"Found more than one match for TAGH."<<endl;
322  if (same == 0) dTreeFillData.Fill_Array<Bool_t>("TAGH_DBeam",false,htag);
323  else dTreeFillData.Fill_Array<Bool_t>("TAGH_DBeam",true,htag);
324  htag++;
325  }
326 
327  // Loop over TAGM hits and match to DBeamPhotons
328  unsigned int mtag = 0;
329  unsigned int mtag_DBeam = 0;
330  for (unsigned int i=0; i < tagmhits.size(); i++) {
331  const DTAGMHit* tag = tagmhits[i];
332  if (!tag->has_TDC||!tag->has_fADC) continue;
333  if (tag->row!=0) continue;
334  if (std::isnan(tag->t) || std::isnan(tag->E)) continue;
335  dTreeFillData.Fill_Array<Double_t>("TAGMenergy",tag->E,mtag);
336  dTreeFillData.Fill_Array<Double_t>("TAGMtime",tag->t,mtag);
337  dTreeFillData.Fill_Array<UInt_t>("TAGMcolumn",tag->column,mtag);
338  unsigned int same = 0;
339  for (unsigned int j=0; j < beamPhotons.size(); j++)
340  {
341  const DTAGMHit* tagm;
342  beamPhotons[j]->GetSingle(tagm);
343  if (!tagm) continue;
344  if (!tagm->has_TDC || !tagm->has_fADC) continue;
345  if (tagm->row != 0) continue;
346  if (std::isnan(tagm->t) || std::isnan(tagm->E))
347  {
348  if (VERBOSE) jerr<<"Found TAGM with NAN."<<tagm->column<<endl;
349  continue;
350  }
351  if (tagm->t != tag->t || tagm->E != tag->E || tagm->column != tag->column) continue;
352  same++;
353  mtag_DBeam++;
354  }
355  if (same > 1 && VERBOSE) jerr<<"Found more than one match for TAGM."<<endl;
356  if (same == 0) dTreeFillData.Fill_Array<Bool_t>("TAGM_DBeam",false,mtag);
357  else dTreeFillData.Fill_Array<Bool_t>("TAGM_DBeam",true,mtag);
358  mtag++;
359  }
360 
361  // Ensure TAGH hits match DBeamPhotons
362  unsigned int htag_Check = 0;
363  for (unsigned int i=0; i < beamPhotons.size(); i++) {
364  const DTAGHHit* tag;
365  beamPhotons[i]->GetSingle(tag);
366  if (!tag) continue;
367  if (!tag->has_TDC||!tag->has_fADC) continue;
368  if (std::isnan(tag->t) || std::isnan(tag->E)) continue;
369  htag_Check++;
370  }
371  if (htag_Check != htag_DBeam && VERBOSE) jerr<<"TAGH: "<<htag_DBeam<<" , "<<htag_Check<<endl;
372 
373  // Ensure TAGM hits match DBeamPhotons
374  unsigned int mtag_Check = 0;
375  for (unsigned int i=0; i < beamPhotons.size(); i++) {
376  const DTAGMHit* tag;
377  beamPhotons[i]->GetSingle(tag);
378  if(!tag) continue;
379  if (!tag->has_TDC||!tag->has_fADC) continue;
380  if (tag->row!=0) continue;
381  if (std::isnan(tag->t) || std::isnan(tag->E)) continue;
382  mtag_Check++;
383  }
384  if (mtag_Check != mtag_DBeam && VERBOSE) jerr<<"TAGM: "<<mtag_DBeam<<" , "<<mtag_Check<<endl;
385 
386  dTreeFillData.Fill_Single<UShort_t>("ntagh",htag);
387  dTreeFillData.Fill_Single<UShort_t>("ntagm",mtag);
388 
389  // Loop over windowraws to collect TPOL hits
390  // No cuts are applied to the TPOL hits
391  unsigned int hit = 0;
392  unsigned int ntpol = 0;
393  for(unsigned int i=0; i< windowraws.size(); i++) {
394  const Df250WindowRawData *windowraw = windowraws[i];
395  if (windowraw->rocid!=84) continue;
396  if (!(windowraw->slot==13||windowraw->slot==14)) continue; // azimuthal sectors, rings: 15,16
397  unsigned int rocid = windowraw->rocid;
398  unsigned int slot = windowraw->slot;
399  unsigned int channel = windowraw->channel;
400  unsigned int itrigger = windowraw->itrigger;
401  // Get a vector of the samples for this channel
402  const vector<uint16_t> &samplesvector = windowraw->samples;
403  unsigned int nsamples = samplesvector.size();
404 
405  // loop over the samples to calculate integral, min, max
406  if (nsamples==0 && VERBOSE) jerr << "Raw samples vector is empty." << endl;
407 
408  ULong64_t w_integral = 0;
409  unsigned int w_max = 0;
410  unsigned int w_min = 0;
411  unsigned int w_samp1 = 0;
412  unsigned int i_w_max = 0;
413  unsigned int i_w_min = 0;
414  for (uint16_t c_samp=0; c_samp<nsamples; c_samp++) {
415  dTreeFillData.Fill_Array<UShort_t>("waveform",samplesvector[c_samp],ntpol);
416  ntpol++;
417  if (c_samp==0) { // use first sample for initialization
418  w_integral = samplesvector[0];
419  w_min = samplesvector[0];
420  w_max = samplesvector[0];
421  w_samp1 = samplesvector[0];
422  }
423  else {
424  w_integral += samplesvector[c_samp];
425  if (w_min > samplesvector[c_samp])
426  {
427  w_min = samplesvector[c_samp];
428  i_w_min = c_samp;
429  }
430  if (w_max < samplesvector[c_samp])
431  {
432  w_max = samplesvector[c_samp];
433  i_w_max = c_samp;
434  }
435  }
436  }
437 
438  unsigned int sector = GetSector(slot,channel);
439  double phi = GetPhi(sector);
440 
441  dTreeFillData.Fill_Array<UShort_t>("rocid",rocid,hit);
442  dTreeFillData.Fill_Array<UShort_t>("slot",slot,hit);
443  dTreeFillData.Fill_Array<UShort_t>("channel",channel,hit);
444  dTreeFillData.Fill_Array<UInt_t>("itrigger",itrigger,hit);
445  dTreeFillData.Fill_Array<ULong64_t>("w_integral",w_integral,hit);
446  dTreeFillData.Fill_Array<UShort_t>("w_max",w_max,hit);
447  dTreeFillData.Fill_Array<UShort_t>("w_min",w_min,hit);
448  dTreeFillData.Fill_Array<UShort_t>("i_w_min",i_w_min,hit);
449  dTreeFillData.Fill_Array<UShort_t>("i_w_max",i_w_max,hit);
450  dTreeFillData.Fill_Array<UShort_t>("w_samp1",w_samp1,hit);
451  dTreeFillData.Fill_Array<UShort_t>("sector",sector,hit);
452  dTreeFillData.Fill_Array<Double_t>("phi",phi,hit);
453  hit++;
454  }
455  unsigned int nadc = hit;
456  if (nadc>NSECTORS && VERBOSE) jerr << "TPOL_tree plugin error: nadc exceeds nmax(" << NSECTORS << ")." << endl;
457  dTreeFillData.Fill_Single<UShort_t>("nadc",nadc);
458  dTreeFillData.Fill_Single<UShort_t>("ntpol",ntpol);
459 
460  if (nadc == 0 && htag == 0 && mtag == 0 && nPS == 0 && nPSC == 0) return NOERROR;
461 
462  dTreeInterface->Fill(dTreeFillData);
463  count++;
464 
465  japp->RootFillUnLock(this);
466  //
467  return NOERROR;
468 }
469 
470 int JEventProcessor_TPOL_tree::GetSector(int slot,int channel)
471 {
472  int sector = 0;
473  if (slot == 13) sector = 25 - channel;
474  if (slot == 14) {
475  if (channel <= 8) sector = 9 - channel;
476  else sector = NSECTORS + 9 - channel;
477  }
478  // fix cable swap
479  if (sector == 9) sector = 6;
480  else if (sector == 6) sector = 9;
481  if (sector == 0 && VERBOSE) jerr << "sector did not change from initial value (0)." << endl;
482  return sector;
483 }
485 {
486  double phi = -10.0;
487  if(sector <= 8) phi = (sector + 23)*SECTOR_DIVISION + 0.5*SECTOR_DIVISION;
488  if(sector >= 9) phi = (sector - 9)*SECTOR_DIVISION + 0.5*SECTOR_DIVISION;
489  return phi;
490 }
491 double JEventProcessor_TPOL_tree::GetPulseTime(const vector<uint16_t> waveform,double w_min,double w_max,double minpeakheight)
492 {
493  // find the time to cross half peak height
494  int lastbelowsamp=0; double peakheight = w_max-w_min;
495  double threshold = w_min + peakheight/2.0;
496  double firstaboveheight=0, lastbelowheight=0;
497  double w_time=0;
498  if (peakheight > minpeakheight) {
499  for (uint16_t c_samp=0; c_samp<waveform.size(); c_samp++) {
500  if (waveform[c_samp]>threshold) {
501  firstaboveheight = waveform[c_samp];
502  lastbelowsamp = c_samp-1;
503  lastbelowheight = waveform[c_samp-1];
504  break;
505  }
506  }
507  w_time = lastbelowsamp + (threshold-lastbelowheight)/(firstaboveheight-lastbelowheight);
508  }
509  return 64.0*w_time;
510 }
511 //------------------
512 // erun
513 //------------------
515 {
516  // This is called whenever the run number changes, before it is
517  // changed to give you a chance to clean up before processing
518  // events from the next run number.
519  return NOERROR;
520 }
521 
522 //------------------
523 // fini
524 //------------------
526 {
527  delete dTreeInterface;
528 
529  t = clock() - t;
530  cout<<endl<<endl;
531  cout<<"Time in minutes for the plugin to complete: "<<t*1.0/CLOCKS_PER_SEC/60.0<<endl<<endl;
532  // Called before program exit after event processing is finished.
533  return NOERROR;
534 }
double GetPulseTime(const vector< uint16_t > waveform, double w_min, double w_max, double minpeakheight)
double t
Definition: DTAGHHit.h:19
double E
Definition: DTAGHHit.h:18
double E
Definition: DTAGMHit.h:18
const int NC_PSC
int module
Definition: DPSCHit.h:20
const double SECTOR_DIVISION
static thread_local DTreeFillData dTreeFillData
uint32_t trig_mask
Definition: DL1Trigger.h:18
uint32_t fp_trig_mask
Definition: DL1Trigger.h:19
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
int row
Definition: DTAGMHit.h:20
bool has_TDC
Definition: DTAGHHit.h:26
void Register_Single(string locBranchName)
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
const int NC_TAGM
vector< uint16_t > samples
double t
Definition: DTAGMHit.h:19
double t
Definition: DPSCHit.h:21
JApplication * japp
jerror_t init(void)
Called once at program start.
bool has_fADC
Definition: DTAGMHit.h:27
int counter_id
Definition: DTAGHHit.h:20
int GetSector(int slot, int channel)
const int NSECTORS
static DTreeInterface * Create_DTreeInterface(string locTreeName, string locFileName)
InitPlugin_t InitPlugin
const bool VERBOSE
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
bool has_TDC
Definition: DTAGMHit.h:27
jerror_t fini(void)
Called after last event of last event source has been processed.
void Register_FundamentalArray(string locBranchName, string locArraySizeName, size_t locInitialArraySize=10)
static const int NUM_COARSE_COLUMNS
Definition: DPSGeometry.h:25
static const double SECTOR_DIVISION
uint32_t channel
Definition: DDAQAddress.h:34
bool has_fADC
Definition: DTAGHHit.h:26
uint32_t rocid
Definition: DDAQAddress.h:32
const int NC_TAGH
static const unsigned int kColumnCount
Definition: DTAGMGeometry.h:31
int column
Definition: DTAGMHit.h:21
static const int NUM_FINE_COLUMNS
Definition: DPSGeometry.h:26
static const unsigned int kCounterCount
Definition: DTAGHGeometry.h:28
uint32_t itrigger
Definition: DDAQAddress.h:35
uint32_t slot
Definition: DDAQAddress.h:33
const int NC_PS
static const int NSECTORS