Bug Summary

File:libraries/FMWPC/DFMWPCHit_factory.cc
Location:line 229, column 2
Description:Value stored to 'nsamples_integral' is never read

Annotated Source Code

1// $Id$
2//
3// File: DFMWPCHit_factory.cc
4//
5
6
7#include <iostream>
8#include <iomanip>
9using namespace std;
10
11
12#include <FMWPC/DFMWPCHit_factory.h>
13#include <DAQ/Df125PulseIntegral.h>
14#include <DAQ/Df125Config.h>
15#include <DAQ/Df125CDCPulse.h>
16
17using namespace jana;
18
19static int FMWPC_HIT_THRESHOLD = 700;
20
21//#define ENABLE_UPSAMPLING
22
23//------------------
24// init
25//------------------
26jerror_t DFMWPCHit_factory::init(void)
27{
28
29 gPARMS->SetDefaultParameter("FMWPC:FMWPC_HIT_THRESHOLD", FMWPC_HIT_THRESHOLD,
30 "Remove FMWPC Hits with peak amplitudes smaller than FMWPC_HIT_THRESHOLD");
31
32 // default values
33 a_scale = 0.;
34 t_scale = 0.;
35 t_base = 0.;
36
37 // Set default number of number of detector channels
38 maxChannels = 6*144;
39 // hardcode some geometry constants - should pull from DGeometry later on
40 Nlayers = 6;
41 Nwires = {144, 144, 144, 144, 144, 144};
42
43
44 /// set the base conversion scales
45 a_scale = 4.0E3/1.0E2;
46 amp_a_scale = a_scale*28.8;
47 t_scale = 8.0/10.0; // 8 ns/count and integer time is in 1/10th of sample
48 t_base = 0.; // ns
49
50 return NOERROR;
51}
52
53//------------------
54// brun
55//------------------
56jerror_t DFMWPCHit_factory::brun(jana::JEventLoop *eventLoop, int32_t runnumber)
57{
58 // Only print messages for one thread whenever run number change
59 static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER{ { 0, 0, 0, 0, 0, 0, 0, { 0, 0 } } };
60 static set<int> runs_announced;
61 pthread_mutex_lock(&print_mutex);
62 bool print_messages = false;
63 if(runs_announced.find(runnumber) == runs_announced.end()){
64 print_messages = true;
65 runs_announced.insert(runnumber);
66 }
67 pthread_mutex_unlock(&print_mutex);
68
69 // load geometry from XML here!!
70
71 if(print_messages) jout << "In DFMWPCHit_factory, loading constants..." << std::endl;
72
73 // load scale factors
74 map<string,double> scale_factors;
75 if (eventLoop->GetCalib("/FMWPC/digi_scales", scale_factors))
76 jout << "Error loading /FMWPC/digi_scales !" << endl;
77 if (scale_factors.find("FMWPC_ADC_ASCALE") != scale_factors.end())
78 a_scale = scale_factors["FMWPC_ADC_ASCALE"];
79 else
80 jerr << "Unable to get FMWPC_ADC_ASCALE from /FMWPC/digi_scales !" << endl;
81 amp_a_scale=a_scale*28.8;
82
83#ifdef ENABLE_UPSAMPLING
84 //t_scale=1.;
85#else
86 if (scale_factors.find("FMWPC_ADC_TSCALE") != scale_factors.end())
87 t_scale = scale_factors["FMWPC_ADC_TSCALE"];
88 else
89 jerr << "Unable to get FMWPC_ADC_TSCALE from /FMWPC/digi_scales !" << endl;
90#endif
91
92 // load base time offset
93 map<string,double> base_time_offset;
94 if (eventLoop->GetCalib("/FMWPC/base_time_offset",base_time_offset))
95 jout << "Error loading /FMWPC/base_time_offset !" << endl;
96 if (base_time_offset.find("FMWPC_BASE_TIME_OFFSET") != base_time_offset.end())
97 t_base = base_time_offset["FMWPC_BASE_TIME_OFFSET"];
98 else
99 jerr << "Unable to get FMWPC_BASE_TIME_OFFSET from /FMWPC/base_time_offset !" << endl;
100
101 // load constant tables
102 if (eventLoop->GetCalib("/FMWPC/wire_gains", gains))
103 jout << "Error loading /FMWPC/wire_gains !" << endl;
104 if (eventLoop->GetCalib("/FMWPC/pedestals", pedestals))
105 jout << "Error loading /FMWPC/pedestals !" << endl;
106 if (eventLoop->GetCalib("/FMWPC/timing_offsets", time_offsets))
107 jout << "Error loading /FMWPC/timing_offsets !" << endl;
108
109
110 // Verify that the right number of chambers was read for each set of constants
111 char str[256];
112 if (gains.size() != Nlayers) {
113 sprintf(str, "Bad # of layers for FMWPC gain from CCDB! CCDB=%zu , should be %d", gains.size(), Nlayers);
114 std::cerr << str << std::endl;
115 throw JException(str);
116 }
117 if (pedestals.size() != Nlayers) {
118 sprintf(str, "Bad # of rings for FMWPC pedestal from CCDB! CCDB=%zu , should be %d", pedestals.size(), Nlayers);
119 std::cerr << str << std::endl;
120 throw JException(str);
121 }
122 if (time_offsets.size() != Nlayers) {
123 sprintf(str, "Bad # of rings for FMWPC time offset from CCDB!"
124 " CCDB=%zu , should be %d", time_offsets.size(), Nlayers);
125 std::cerr << str << std::endl;
126 throw JException(str);
127 }
128
129 // Verify the right number of wires was read for each layer for each set of constants
130 for (unsigned int i=0; i < Nlayers; i++) {
131 if (gains[i].size() != Nwires[i]) {
132 sprintf(str, "Bad # of wires for FMWPC gain from CCDB!"
133 " CCDB=%zu , should be %d for ring %d",
134 gains[i].size(), Nwires[i], i+1);
135 std::cerr << str << std::endl;
136 throw JException(str);
137 }
138 if (pedestals[i].size() != Nwires[i]) {
139 sprintf(str, "Bad # of wires for FMWPC pedestal from CCDB!"
140 " CCDB=%zu , should be %d for ring %d",
141 pedestals[i].size(), Nwires[i], i+1);
142 std::cerr << str << std::endl;
143 throw JException(str);
144 }
145 if (time_offsets[i].size() != Nwires[i]) {
146 sprintf(str, "Bad # of wires for FMWPC time offset from CCDB!"
147 " CCDB=%zu , should be %d for ring %d",
148 time_offsets[i].size(), Nwires[i], i+1);
149 std::cerr << str << std::endl;
150 throw JException(str);
151 }
152 }
153
154 return NOERROR;
155}
156
157//------------------
158// evnt
159//------------------
160jerror_t DFMWPCHit_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
161{
162 /// Generate DCDCHit object for each DCDCDigiHit object.
163 /// This is where the first set of calibration constants
164 /// is applied to convert from digitzed units into natural
165 /// units.
166 ///
167 /// Note that this code does NOT get called for simulated
168 /// data in HDDM format. The HDDM event source will copy
169 /// the precalibrated values directly into the _data vector.
170
171 /// In order to use the new Flash125 data types and maintain compatibility with the old code, what is below is a bit of a mess
172
173 vector<const DFMWPCDigiHit*> digihits;
174 loop->Get(digihits);
175
176 char str[256];
177 for (unsigned int i=0; i < digihits.size(); i++) {
178 const DFMWPCDigiHit *digihit = digihits[i];
179
180 //if ( (digihit->QF & 0x1) != 0 ) continue; // Cut bad timing quality factor hits... (should check effect on efficiency)
181 if ( digihit->QF != 0 ) continue; // Cut bad timing quality factor hits... (should check effect on efficiency)
182
183 const int &layer = digihit->layer;
184 const int &wire = digihit->wire;
185
186 // Make sure layer and wire are in valid range
187 if ( (layer < 1) || (layer > (int)Nlayers)) {
188 sprintf(str, "DFMWPCDigiHit layer out of range!"
189 " layer=%d (should be 1-%d)", layer, Nlayers);
190 throw JException(str);
191 }
192 if ( (wire < 1) || (wire > (int)Nwires[layer-1])) {
193 sprintf(str, "DFMWPCDigiHit wire out of range!"
194 " wire=%d for layer=%d (should be 1-%d)",
195 wire, layer, Nwires[layer-1]);
196 throw JException(str);
197 }
198
199 // Grab the pedestal from the digihit since this should be consistent between the old and new formats
200 int raw_ped = digihit->pedestal;
201 int maxamp = digihit->pulse_peak;
202 int nsamples_integral = 0; // actual number computed below using config info
203
204 // There are a few values from the new data type that are critical for the interpretation of the data
205 uint16_t IBIT = 0; // 2^{IBIT} Scale factor for integral
206 uint16_t ABIT = 0; // 2^{ABIT} Scale factor for amplitude
207 uint16_t PBIT = 0; // 2^{PBIT} Scale factor for pedestal
208 uint16_t NW = 0;
209
210 // Configuration data needed to interpret the hits is stored in the data stream
211 vector<const Df125Config*> configs;
212 digihit->Get(configs);
213 if( configs.empty() ) {
214 static int Nwarnings = 0;
215 if(Nwarnings<10) {
216 _DBG_std::cerr<<"libraries/FMWPC/DFMWPCHit_factory.cc"<<
":"<<216<<" "
<< "NO Df125Config object associated with Df125CDCPulse object!" << endl;
217 Nwarnings++;
218 if(Nwarnings==10) _DBG_std::cerr<<"libraries/FMWPC/DFMWPCHit_factory.cc"<<
":"<<218<<" "
<< " --- LAST WARNING!! ---" << endl;
219 }
220 } else {
221 // Set some constants to defaults until they appear correctly in the config words in the future
222 const Df125Config *config = configs[0];
223 IBIT = config->IBIT == 0xffff ? 4 : config->IBIT;
224 ABIT = config->ABIT == 0xffff ? 3 : config->ABIT;
225 PBIT = config->PBIT == 0xffff ? 0 : config->PBIT;
226 NW = config->NW == 0xffff ? 200 : config->NW;
227 }
228
229 nsamples_integral = (NW - (digihit->pulse_time / 10));
Value stored to 'nsamples_integral' is never read
230
231 // Complete the pedestal subtraction here since we should know the correct number of samples.
232 int scaled_ped = raw_ped << PBIT;
233
234 if (maxamp > 0) maxamp = maxamp << ABIT;
235 if (maxamp <= scaled_ped) continue;
236
237 maxamp = maxamp - scaled_ped;
238
239 if (maxamp<FMWPC_HIT_THRESHOLD) {
240 continue;
241 }
242
243 // Apply calibration constants here
244 double t_raw = double(digihit->pulse_time);
245 if (t_raw < 250 || t_raw > 450)
246 continue;
247
248 // Scale factor to account for gain variation
249 unsigned int layer_i=layer-1;
250 unsigned int wire_i=wire-1;
251 double gain=gains[layer_i][wire_i];
252
253 // Charge and amplitude
254 // if ((digihit->pulse_integral<<IBIT) < scaled_ped*nsamples_integral)
255 // continue;
256 // double q = a_scale *gain * double((digihit->pulse_integral<<IBIT)
257 // - scaled_ped*nsamples_integral);
258 double q = amp_a_scale*gain*double(maxamp);
259 double amp = amp_a_scale*gain*double(maxamp);
260
261 double t = t_scale * t_raw - time_offsets[layer_i][wire_i] + t_base;
262
263 DFMWPCHit *hit = new DFMWPCHit;
264 hit->layer = layer;
265 hit->wire = wire;
266
267 // Values for d, itrack, ptype only apply to MC data
268 // note that wire counting starts at 1
269 hit->q = q;
270 hit->amp = amp;
271 hit->t = t;
272 // hit->d = 0.0;
273 hit->QF = digihit->QF;
274 // hit->itrack = -1;
275 // hit->ptype = 0;
276
277 hit->AddAssociatedObject(digihit);
278
279 _data.push_back(hit);
280
281 }
282
283 return NOERROR;
284}
285
286
287//------------------
288// erun
289//------------------
290jerror_t DFMWPCHit_factory::erun(void)
291{
292 return NOERROR;
293}
294
295//------------------
296// fini
297//------------------
298jerror_t DFMWPCHit_factory::fini(void)
299{
300 return NOERROR;
301}
302
303//------------------------------------
304// GetConstant
305// Allow a few different interfaces
306//------------------------------------
307const double DFMWPCHit_factory::GetConstant(const fmwpc_digi_constants_t &the_table,
308 const int in_layer, const int in_wire) const {
309
310 char str[256];
311
312 if ( (in_layer <= 0) || (static_cast<unsigned int>(in_layer) > Nlayers)) {
313 sprintf(str, "Bad layer # requested in DFMWPCHit_factory::GetConstant()!"
314 " requested=%d , should be %ud", in_layer, Nlayers);
315 std::cerr << str << std::endl;
316 throw JException(str);
317 }
318 if ( (in_wire <= 0) ||
319 (static_cast<unsigned int>(in_wire) > Nwires[in_layer]))
320 {
321 sprintf(str, "Bad wire # requested in DCDCHit_factory::GetConstant()!"
322 " requested=%d , should be %ud", in_wire, Nwires[in_layer]);
323 std::cerr << str << std::endl;
324 throw JException(str);
325 }
326
327 return the_table[in_layer][in_wire]; // depends on numbering
328}
329
330const double DFMWPCHit_factory::GetConstant(const fmwpc_digi_constants_t &the_table,
331 const DFMWPCDigiHit *in_digihit) const {
332
333 char str[256];
334
335 if ( (in_digihit->layer <= 0) ||
336 (static_cast<unsigned int>(in_digihit->layer) > Nlayers))
337 {
338 sprintf(str, "Bad layer # requested in DFMWPCHit_factory::GetConstant()!"
339 " requested=%d , should be %ud", in_digihit->layer, Nlayers);
340 std::cerr << str << std::endl;
341 throw JException(str);
342 }
343 if ( (in_digihit->wire <= 0) ||
344 (static_cast<unsigned int>(in_digihit->wire) > Nwires[in_digihit->layer]))
345 {
346 sprintf(str, "Bad wire # requested in DFMWPCHit_factory::GetConstant()!"
347 " requested=%d , should be %ud",
348 in_digihit->wire, Nwires[in_digihit->layer]);
349 std::cerr << str << std::endl;
350 throw JException(str);
351 }
352
353 return the_table[in_digihit->layer][in_digihit->wire]; // depends on numbering
354}
355
356const double DFMWPCHit_factory::GetConstant(const fmwpc_digi_constants_t &the_table,
357 const DFMWPCHit *in_hit) const {
358
359 char str[256];
360
361 if ( (in_hit->layer <= 0) || (static_cast<unsigned int>(in_hit->layer) > Nlayers)) {
362 sprintf(str, "Bad layer # requested in DFMWPCHit_factory::GetConstant()!"
363 " requested=%d , should be %ud", in_hit->layer, Nlayers);
364 std::cerr << str << std::endl;
365 throw JException(str);
366 }
367 if ( (in_hit->wire <= 0) ||
368 (static_cast<unsigned int>(in_hit->wire) > Nwires[in_hit->layer]) ) {
369 sprintf(str, "Bad wire # requested in DFMWPCHit_factory::GetConstant()!"
370 " requested=%d , should be %ud",
371 in_hit->wire, Nwires[in_hit->layer]);
372 std::cerr << str << std::endl;
373 throw JException(str);
374 }
375
376 return the_table[in_hit->layer][in_hit->wire]; // depends on numbering
377}
378