Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DDIRCLEDRef_factory.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DDIRCLEDRef_factory.cc
4 // Created: Wed Aug 7 09:30:17 EDT 2013
5 // Creator: davidl (on Darwin harriet.jlab.org 11.4.2 i386)
6 //
7 
8 
9 #include <iostream>
10 #include <iomanip>
11 #include <cmath>
12 #include <vector>
13 #include <limits>
14 
15 #include <TMath.h>
16 
17 using namespace std;
18 
19 #include "DDIRCLEDRef_factory.h"
20 #include <DAQ/Df250PulseIntegral.h>
21 #include <DAQ/Df250Config.h>
22 
23 #include <DAQ/DCODAROCInfo.h>
24 
25 using namespace jana;
26 
27 //------------------
28 // init
29 //------------------
31 {
32 
33  /// Set basic conversion constants
34  a_scale = 0.2/5.2E5;
35  t_scale = 0.0625; // 62.5 ps/count
36  t_base = 0.; // ns
37  t_base_tdc = 0.; // ns
38 
39  return NOERROR;
40 }
41 
42 //------------------
43 // brun
44 //------------------
45 jerror_t DDIRCLEDRef_factory::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
46 {
47  return NOERROR;
48 }
49 
50 //------------------
51 // evnt
52 //------------------
53 jerror_t DDIRCLEDRef_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
54 {
55  /// Generate DDIRCLEDRef object for each DTOFDigiHit object.
56  /// This is where the first set of calibration constants
57  /// is applied to convert from digitzed units into natural
58  /// units.
59  ///
60  /// Note that this code does NOT get called for simulated
61  /// data in HDDM format. The HDDM event source will copy
62  /// the precalibrated values directly into the _data vector.
63 
64  const DTTabUtilities* locTTabUtilities = NULL;
65  loop->GetSingle(locTTabUtilities);
66 
67  vector<const DCAEN1290TDCHit*> sipmtdchits;
68  loop->Get(sipmtdchits);
69  vector<const Df250PulseData*> sipmadchits;
70  loop->Get(sipmadchits);
71 
72  for(uint i=0; i<sipmadchits.size(); i++) {
73  const Df250PulseData* sipmadchit = (Df250PulseData*)sipmadchits[i];
74  if(sipmadchit->rocid == 77 && sipmadchit->slot == 16 && sipmadchit->channel == 15) {
75  double T = (double)((sipmadchit->course_time<<6) + sipmadchit->fine_time);
76 
77  // Apply calibration constants here
78  T = t_scale * T - 115;
79  //T = T - GetConstant(adc_time_offsets, digihit) + t_base;
80 
81  DDIRCLEDRef *hit = new DDIRCLEDRef;
82  hit->amp = (double)sipmadchit->pulse_peak;
83  hit->integral = (double)sipmadchit->integral;
84 
85  hit->t_TDC=numeric_limits<double>::quiet_NaN();
86  hit->t_fADC=T;
87  hit->t = hit->t_fADC; // set initial time to the ADC time, in case there's no matching TDC hit
88 
89  hit->has_fADC=true;
90  hit->has_TDC=false;
91 
92  hit->AddAssociatedObject(sipmadchit);
93 
94  _data.push_back(hit);
95  }
96  }
97 
98  for(uint i=0; i<sipmtdchits.size(); i++) {
99  const DCAEN1290TDCHit* sipmtdchit = (DCAEN1290TDCHit*)sipmtdchits[i];
100  if(sipmtdchit->rocid == 78 && sipmtdchit->slot == 8 && sipmtdchit->channel == 30) {
101 
102  // Apply calibration constants here
103  double T = locTTabUtilities->Convert_DigiTimeToNs_CAEN1290TDC(sipmtdchit) - 368.;
104  //T += t_base_tdc - GetConstant(tdc_time_offsets, digihit) + tdc_adc_time_offset;
105 
106  // Look for existing hits to see if there is a match
107  // or create new one if there is no match
108  DDIRCLEDRef *hit = FindMatch(T);
109  if(!hit){
110  continue; // Do not use unmatched TDC hits
111  } else if (hit->has_TDC) { // this tof ADC hit has already a matching TDC, make new tof ADC hit
112  DDIRCLEDRef *newhit = new DDIRCLEDRef;
113  newhit->amp = hit->amp;
114  newhit->integral = hit->integral;
115  newhit->t_fADC = hit->t_fADC;
116  newhit->has_fADC = hit->has_fADC;
117  newhit->t_TDC=numeric_limits<double>::quiet_NaN();
118  newhit->t = hit->t_fADC; // set initial time to the ADC time, in case there's no matching TDC hit
119  newhit->has_TDC=false;
120  newhit->AddAssociatedObject(sipmtdchit);
121  _data.push_back(newhit);
122  hit = newhit;
123  }
124  hit->has_TDC=true;
125  hit->t_TDC=T;
126  hit->t = T;
127 
128 /*
129  if (hit->dE>0.){
130 
131  // time walk correction
132  // Note at this point the dE value is still in ADC units
133  double tcorr = 0.;
134  if (USE_AMP_4WALKCORR) {
135  // use amplitude instead of integral
136  tcorr = CalcWalkCorrAmplitude(hit);
137 
138  } else if (USE_NEW_4WALKCORR) {
139  // new functional form with 4 parameter but still using integral
140  tcorr = CalcWalkCorrNEW(hit);
141 
142  } else if (USE_NEWAMP_4WALKCORR) {
143  // new functional form with 2 functions and 4 parameter using amplitude
144  tcorr = CalcWalkCorrNEWAMP(hit);
145 
146  } else {
147  // use integral
148  tcorr = CalcWalkCorrIntegral(hit);
149 
150  }
151 
152  T -= tcorr;
153  }
154  hit->t=T;
155 */
156  hit->AddAssociatedObject(sipmtdchit);
157  }
158  }
159 
160  return NOERROR;
161 }
162 
163 //------------------
164 // FindMatch
165 //------------------
167 {
168  DDIRCLEDRef* best_match = NULL;
169 
170  // Loop over existing hits (from fADC) and look for a match
171  // in both the sector and the time.
172  for(unsigned int i=0; i<_data.size(); i++){
173  DDIRCLEDRef *hit = _data[i];
174 
175  if(!isfinite(hit->t_fADC)) continue; // only match to fADC hits, not bachelor TDC hits
176 
177  //double delta_T = fabs(hit->t - T);
178  double delta_T = fabs(T - hit->t);
179 
180  // if there are multiple hits, pick the one that is closest in time
181  if(best_match != NULL) {
182  if(delta_T < fabs(best_match->t - T))
183  best_match = hit;
184  } else {
185  best_match = hit;
186  }
187 
188  }
189 
190  return best_match;
191 }
192 
193 //------------------
194 // erun
195 //------------------
197 {
198  return NOERROR;
199 }
200 
201 //------------------
202 // fini
203 //------------------
205 {
206  return NOERROR;
207 }
208 
209 
bool has_TDC
Definition: DDIRCLEDRef.h:23
uint32_t fine_time
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
File: DDIRCLEDRef.h.
Definition: DDIRCLEDRef.h:12
double Convert_DigiTimeToNs_CAEN1290TDC(const JObject *locTDCDigiHit) const
uint32_t integral
DDIRCLEDRef * FindMatch(double T)
float t_fADC
Definition: DDIRCLEDRef.h:19
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
uint32_t channel
Definition: DDAQAddress.h:34
uint32_t pulse_peak
uint32_t rocid
Definition: DDAQAddress.h:32
uint32_t course_time
float integral
Definition: DDIRCLEDRef.h:18
float t_TDC
Definition: DDIRCLEDRef.h:20
bool has_fADC
Definition: DDIRCLEDRef.h:22
uint32_t slot
Definition: DDAQAddress.h:33