Bug Summary

File:libraries/TAGGER/DTAGMHit_factory.cc
Location:line 145, column 16
Description:Value stored to 'pedestal' during its initialization is never read

Annotated Source Code

1// $Id$
2//
3// File: DTAGMHit_factory.cc
4// Created: Sat Aug 2 12:23:43 EDT 2014
5// Creator: jonesrt (on Linux gluex.phys.uconn.edu)
6//
7
8
9#include <iostream>
10#include <iomanip>
11using namespace std;
12
13#include "DTAGMDigiHit.h"
14#include "DTAGMTDCDigiHit.h"
15#include "DTAGMGeometry.h"
16#include "DTAGMHit_factory.h"
17#include <DAQ/Df250PulseIntegral.h>
18#include <DAQ/Df250PulsePedestal.h>
19#include <DAQ/Df250Config.h>
20
21using namespace jana;
22
23const int DTAGMHit_factory::k_fiber_good;
24const int DTAGMHit_factory::k_fiber_bad;
25const int DTAGMHit_factory::k_fiber_noisy;
26
27//------------------
28// init
29//------------------
30jerror_t DTAGMHit_factory::init(void)
31{
32 DELTA_T_ADC_TDC_MAX = 10.0; // ns
33 gPARMS->SetDefaultParameter("TAGMHit:DELTA_T_ADC_TDC_MAX", DELTA_T_ADC_TDC_MAX,
34 "Maximum difference in ns between a (calibrated) fADC time and"
35 " F1TDC time for them to be matched in a single hit");
36 // initialize calibration constants
37 fadc_a_scale = 0;
38 fadc_t_scale = 0;
39 t_base = 0;
40 t_tdc_base=0;
41
42 // calibration constants stored in row, column format
43 for (int row = 0; row <= TAGM_MAX_ROW5; ++row) {
44 for (int col = 0; col <= TAGM_MAX_COLUMN102; ++col) {
45 fadc_gains[row][col] = 0;
46 fadc_pedestals[row][col] = 0;
47 fadc_time_offsets[row][col] = 0;
48 tdc_time_offsets[row][col] = 0;
49 fiber_quality[row][col] = 0;
50 }
51 }
52
53 return NOERROR;
54}
55
56//------------------
57// brun
58//------------------
59jerror_t DTAGMHit_factory::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
60{
61 // Only print messages for one thread whenever run number change
62 static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER{ { 0, 0, 0, 0, 0, 0, { 0, 0 } } };
63 static set<int> runs_announced;
64 pthread_mutex_lock(&print_mutex);
65 bool print_messages = false;
66 if(runs_announced.find(runnumber) == runs_announced.end()){
67 print_messages = true;
68 runs_announced.insert(runnumber);
69 }
70 pthread_mutex_unlock(&print_mutex);
71
72 /// set the base conversion scales
73 fadc_a_scale = 1.1; // pixels per count
74 fadc_t_scale = 0.0625; // ns per count
75 t_base = 0.; // ns
76
77 pthread_mutex_unlock(&print_mutex);
78 if(print_messages) jout << "In DTAGMHit_factory, loading constants..." << std::endl;
79
80 // load base time offset
81 map<string,double> base_time_offset;
82 if (eventLoop->GetCalib("/PHOTON_BEAM/microscope/base_time_offset",base_time_offset))
83 jout << "Error loading /PHOTON_BEAM/microscope/base_time_offset !" << endl;
84 if (base_time_offset.find("TAGM_BASE_TIME_OFFSET") != base_time_offset.end())
85 t_base = base_time_offset["TAGM_BASE_TIME_OFFSET"];
86 else
87 jerr << "Unable to get TAGM_BASE_TIME_OFFSET from /PHOTON_BEAM/microscope/base_time_offset !" << endl;
88 if (base_time_offset.find("TAGM_TDC_BASE_TIME_OFFSET") != base_time_offset.end())
89 t_tdc_base = base_time_offset["TAGM_TDC_BASE_TIME_OFFSET"];
90 else
91 jerr << "Unable to get TAGM_TDC_BASE_TIME_OFFSET from /PHOTON_BEAM/microscope/base_time_offset !" << endl;
92
93 if (load_ccdb_constants("fadc_gains", "gain", fadc_gains) &&
94 load_ccdb_constants("fadc_pedestals", "pedestal", fadc_pedestals) &&
95 load_ccdb_constants("fadc_time_offsets", "offset", fadc_time_offsets) &&
96 load_ccdb_constants("tdc_time_offsets", "offset", tdc_time_offsets) &&
97 load_ccdb_constants("fiber_quality", "code", fiber_quality) )
98 {
99 return NOERROR;
100 }
101 return UNRECOVERABLE_ERROR;
102}
103
104//------------------
105// evnt
106//------------------
107jerror_t DTAGMHit_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
108{
109 /// Generate DTAGMHit object for each DTAGMDigiHit object.
110 /// This is where the first set of calibration constants
111 /// is applied to convert from digitzed units into natural
112 /// units.
113 ///
114 /// Note that this code does NOT get called for simulated
115 /// data in HDDM format. The HDDM event source will copy
116 /// the precalibrated values directly into the _data vector.
117
118 // extract the TAGM geometry
119 vector<const DTAGMGeometry*> tagmGeomVect;
120 eventLoop->Get( tagmGeomVect );
121 if (tagmGeomVect.size() < 1)
122 return OBJECT_NOT_AVAILABLE;
123 const DTAGMGeometry& tagmGeom = *(tagmGeomVect[0]);
124
125 const DTTabUtilities* locTTabUtilities = NULL__null;
126 loop->GetSingle(locTTabUtilities);
127
128 // First loop over all TAGMDigiHits and make DTAGMHits out of them
129 vector<const DTAGMDigiHit*> digihits;
130 loop->Get(digihits);
131 for (unsigned int i=0; i < digihits.size(); i++) {
132 const DTAGMDigiHit *digihit = digihits[i];
133
134 // The following condition signals an error state in the flash algorithm
135 // Do not make hits out of these
136 const Df250PulsePedestal* PPobj = NULL__null;
137 digihit->GetSingle(PPobj);
138 if (PPobj != NULL__null){
139 if (PPobj->pedestal == 0 || PPobj->pulse_peak == 0) continue;
140 }
141 else continue;
142
143 // Get pedestal, prefer associated event pedestal if it exists,
144 // otherwise, use the average pedestal from CCDB
145 double pedestal = fadc_pedestals[digihit->row][digihit->column];
Value stored to 'pedestal' during its initialization is never read
146
147 const Df250PulseIntegral* PIobj = NULL__null;
148 digihit->GetSingle(PIobj);
149 if (PIobj != NULL__null) {
150 // the measured pedestal must be scaled by the ratio of the number
151 // of samples used to calculate the pedestal and the actual pulse
152 // Changed to match D. Lawrence Dec 4 2014 changes
153 double single_sample_ped = (double)PIobj->pedestal;
154 double nsamples_integral = (double)PIobj->nsamples_integral;
155 double nsamples_pedestal = (double)PIobj->nsamples_pedestal;
156 pedestal = single_sample_ped * nsamples_integral/nsamples_pedestal;
157 }
158 else continue;
159
160 // throw away hits from bad or noisy fibers
161 int quality = fiber_quality[digihit->row][digihit->column];
162 if (quality == k_fiber_bad || quality == k_fiber_noisy)
163 continue;
164
165 // Skip events where fADC algorithm fails
166 //if (digihit->pulse_time == 0) continue; // Should already be caught above
167
168 DTAGMHit *hit = new DTAGMHit;
169 int row = digihit->row;
170 int column = digihit->column;
171 hit->row = row;
172 hit->column = column;
173 double Elow = tagmGeom.getElow(column);
174 double Ehigh = tagmGeom.getEhigh(column);
175 hit->E = (Elow + Ehigh)/2;
176 hit->t = 0;
177
178 // Apply calibration constants
179 double P = PPobj->pulse_peak - PPobj->pedestal;
180 double A = digihit->pulse_integral;
181 double T = digihit->pulse_time;
182 A -= pedestal;
183 hit->integral = A;
184 hit->pulse_peak = P;
185 hit->npix_fadc = A * fadc_a_scale * fadc_gains[row][column];
186 hit->time_fadc = T * fadc_t_scale - fadc_time_offsets[row][column] + t_base;
187 hit->t=hit->time_fadc;
188 hit->has_TDC=false;
189 hit->has_fADC=true;
190
191 hit->AddAssociatedObject(digihit);
192 _data.push_back(hit);
193 }
194
195 // Next, loop over TDC hits, matching them to the existing fADC hits
196 // where possible and updating their time information. If no match is
197 // found, then create a new hit with just the TDC info.
198 vector<const DTAGMTDCDigiHit*> tdcdigihits;
199 loop->Get(tdcdigihits);
200 for (unsigned int i=0; i < tdcdigihits.size(); i++) {
201 const DTAGMTDCDigiHit *digihit = tdcdigihits[i];
202
203 // Apply calibration constants here
204 int row = digihit->row;
205 int column = digihit->column;
206 double T = locTTabUtilities->Convert_DigiTimeToNs_F1TDC(digihit) - tdc_time_offsets[row][column] + t_tdc_base;
207
208 // Look for existing hits to see if there is a match
209 // or create new one if there is no match
210 DTAGMHit *hit = 0;
211 for (unsigned int j=0; j < _data.size(); ++j) {
212 if (_data[j]->row == row && _data[j]->column == column &&
213 fabs(T - _data[j]->time_fadc) < DELTA_T_ADC_TDC_MAX)
214 {
215 hit = _data[j];
216 }
217 }
218 if (hit == 0) {
219 hit = new DTAGMHit;
220 hit->row = row;
221 hit->column = column;
222 double Elow = tagmGeom.getElow(column);
223 double Ehigh = tagmGeom.getEhigh(column);
224 hit->E = (Elow + Ehigh)/2;
225 hit->time_fadc = 0;
226 hit->npix_fadc = 0;
227 hit->integral = 0;
228 hit->pulse_peak = 0;
229 hit->has_fADC=false;
230 _data.push_back(hit);
231 }
232 hit->time_tdc=T;
233 hit->has_TDC=true;
234
235 hit->t = T;
236
237 // apply time-walk corrections?
238
239 hit->AddAssociatedObject(digihit);
240 }
241
242 return NOERROR;
243}
244
245//------------------
246// erun
247//------------------
248jerror_t DTAGMHit_factory::erun(void)
249{
250 return NOERROR;
251}
252
253//------------------
254// fini
255//------------------
256jerror_t DTAGMHit_factory::fini(void)
257{
258 return NOERROR;
259}
260
261//---------------------
262// load_ccdb_constants
263//---------------------
264bool DTAGMHit_factory::load_ccdb_constants(
265 std::string table_name,
266 std::string column_name,
267 double result[TAGM_MAX_ROW5+1][TAGM_MAX_COLUMN102+1])
268{
269 std::vector< std::map<std::string, double> > table;
270 std::string ccdb_key = "/PHOTON_BEAM/microscope/" + table_name;
271 if (eventLoop->GetCalib(ccdb_key, table))
272 {
273 jout << "Error loading " << ccdb_key << " from ccdb!" << std::endl;
274 return false;
275 }
276 for (unsigned int i=0; i < table.size(); ++i) {
277 int row = (table[i])["row"];
278 int col = (table[i])["column"];
279 result[row][col] = (table[i])[column_name];
280 }
281 return true;
282}