Bug Summary

File:libraries/FMWPC/DFMWPCHit_factory.cc
Location:line 235, column 3
Description:Value stored to 'IBIT' 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 = 0;
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 //vector<double> raw_gains;
72 //vector<double> raw_pedestals;
73 //vector<double> raw_time_offsets;
74
75 if(print_messages) jout << "In DFMWPCHit_factory, loading constants..." << std::endl;
76
77 // load scale factors
78 map<string,double> scale_factors;
79 if (eventLoop->GetCalib("/FMWPC/digi_scales", scale_factors))
80 jout << "Error loading /FMWPC/digi_scales !" << endl;
81 if (scale_factors.find("FMWPC_ADC_ASCALE") != scale_factors.end())
82 a_scale = scale_factors["FMWPC_ADC_ASCALE"];
83 else
84 jerr << "Unable to get FMWPC_ADC_ASCALE from /FMWPC/digi_scales !" << endl;
85 amp_a_scale=a_scale*28.8;
86
87#ifdef ENABLE_UPSAMPLING
88 //t_scale=1.;
89#else
90 if (scale_factors.find("FMWPC_ADC_TSCALE") != scale_factors.end())
91 t_scale = scale_factors["FMWPC_ADC_TSCALE"];
92 else
93 jerr << "Unable to get FMWPC_ADC_TSCALE from /FMWPC/digi_scales !" << endl;
94#endif
95
96 // load base time offset
97 map<string,double> base_time_offset;
98 if (eventLoop->GetCalib("/FMWPC/base_time_offset",base_time_offset))
99 jout << "Error loading /FMWPC/base_time_offset !" << endl;
100 if (base_time_offset.find("FMWPC_BASE_TIME_OFFSET") != base_time_offset.end())
101 t_base = base_time_offset["FMWPC_BASE_TIME_OFFSET"];
102 else
103 jerr << "Unable to get FMWPC_BASE_TIME_OFFSET from /FMWPC/base_time_offset !" << endl;
104
105 // load constant tables
106 if (eventLoop->GetCalib("/FMWPC/wire_gains", gains))
107 jout << "Error loading /FMWPC/wire_gains !" << endl;
108 if (eventLoop->GetCalib("/FMWPC/pedestals", pedestals))
109 jout << "Error loading /FMWPC/pedestals !" << endl;
110 if (eventLoop->GetCalib("/FMWPC/timing_offsets", time_offsets))
111 jout << "Error loading /FMWPC/timing_offsets !" << endl;
112
113 // fill the tables
114 //FillCalibTable(gains, raw_gains);
115 //FillCalibTable(pedestals, raw_pedestals);
116 //FillCalibTable(time_offsets, raw_time_offsets);
117
118
119 /* -- DISABLE THESE FOR NOW
120 // Verify that the right number of rings was read for each set of constants
121 char str[256];
122 if (gains.size() != Nlayers) {
123 sprintf(str, "Bad # of layers for FMWPC gain from CCDB! CCDB=%zu , should be %d", gains.size(), Nlayers);
124 std::cerr << str << std::endl;
125 throw JException(str);
126 }
127 if (pedestals.size() != Nlayers) {
128 sprintf(str, "Bad # of rings for FMWPC pedestal from CCDB! CCDB=%zu , should be %d", pedestals.size(), Nlayers);
129 std::cerr << str << std::endl;
130 throw JException(str);
131 }
132 if (time_offsets.size() != Nlayers) {
133 sprintf(str, "Bad # of rings for FMWPC time offset from CCDB!"
134 " CCDB=%zu , should be %d", time_offsets.size(), Nlayers);
135 std::cerr << str << std::endl;
136 throw JException(str);
137 }
138
139 // Verify the right number of wires was read for each layer for each set of constants
140 for (unsigned int i=0; i < Nlayers; i++) {
141 if (gains[i].size() != Nwires[i]) {
142 sprintf(str, "Bad # of wires for FMWPC gain from CCDB!"
143 " CCDB=%zu , should be %d for ring %d",
144 gains[i].size(), Nwires[i], i+1);
145 std::cerr << str << std::endl;
146 throw JException(str);
147 }
148 if (pedestals[i].size() != Nwires[i]) {
149 sprintf(str, "Bad # of wires for FMWPC pedestal from CCDB!"
150 " CCDB=%zu , should be %d for ring %d",
151 pedestals[i].size(), Nwires[i], i+1);
152 std::cerr << str << std::endl;
153 throw JException(str);
154 }
155 if (time_offsets[i].size() != Nwires[i]) {
156 sprintf(str, "Bad # of wires for FMWPC time offset from CCDB!"
157 " CCDB=%zu , should be %d for ring %d",
158 time_offsets[i].size(), Nwires[i], i+1);
159 std::cerr << str << std::endl;
160 throw JException(str);
161 }
162 }
163 -- */
164
165 return NOERROR;
166}
167
168//------------------
169// evnt
170//------------------
171jerror_t DFMWPCHit_factory::evnt(JEventLoop *loop, uint64_t eventnumber)
172{
173 /// Generate DCDCHit object for each DCDCDigiHit object.
174 /// This is where the first set of calibration constants
175 /// is applied to convert from digitzed units into natural
176 /// units.
177 ///
178 /// Note that this code does NOT get called for simulated
179 /// data in HDDM format. The HDDM event source will copy
180 /// the precalibrated values directly into the _data vector.
181
182 /// 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
183
184 vector<const DFMWPCDigiHit*> digihits;
185 loop->Get(digihits);
186
187 char str[256];
188 for (unsigned int i=0; i < digihits.size(); i++) {
189 const DFMWPCDigiHit *digihit = digihits[i];
190
191 //if ( (digihit->QF & 0x1) != 0 ) continue; // Cut bad timing quality factor hits... (should check effect on efficiency)
192
193 const int &layer = digihit->layer;
194 const int &wire = digihit->wire;
195
196 /* fill in sanity check when you decided the detector numbering
197 // Make sure ring and straw are in valid range
198 if ( (ring < 1) || (ring > (int)Nrings)) {
199 sprintf(str, "DCDCDigiHit ring out of range!"
200 " ring=%d (should be 1-%d)", ring, Nrings);
201 throw JException(str);
202 }
203 if ( (straw < 1) || (straw > (int)Nstraws[ring-1])) {
204 sprintf(str, "DCDCDigiHit straw out of range!"
205 " straw=%d for ring=%d (should be 1-%d)",
206 straw, ring, Nstraws[ring-1]);
207 throw JException(str);
208 }
209 */
210
211 // Grab the pedestal from the digihit since this should be consistent between the old and new formats
212 int raw_ped = digihit->pedestal;
213 int maxamp = digihit->pulse_peak;
214 int nsamples_integral = 0; // actual number computed below using config info
215
216 // There are a few values from the new data type that are critical for the interpretation of the data
217 uint16_t IBIT = 0; // 2^{IBIT} Scale factor for integral
218 uint16_t ABIT = 0; // 2^{ABIT} Scale factor for amplitude
219 uint16_t PBIT = 0; // 2^{PBIT} Scale factor for pedestal
220 uint16_t NW = 0;
221
222 // Configuration data needed to interpret the hits is stored in the data stream
223 vector<const Df125Config*> configs;
224 digihit->Get(configs);
225 if( configs.empty() ) {
226 static int Nwarnings = 0;
227 if(Nwarnings<10) {
228 _DBG_std::cerr<<"libraries/FMWPC/DFMWPCHit_factory.cc"<<
":"<<228<<" "
<< "NO Df125Config object associated with Df125CDCPulse object!" << endl;
229 Nwarnings++;
230 if(Nwarnings==10) _DBG_std::cerr<<"libraries/FMWPC/DFMWPCHit_factory.cc"<<
":"<<230<<" "
<< " --- LAST WARNING!! ---" << endl;
231 }
232 } else {
233 // Set some constants to defaults until they appear correctly in the config words in the future
234 const Df125Config *config = configs[0];
235 IBIT = config->IBIT == 0xffff ? 4 : config->IBIT;
Value stored to 'IBIT' is never read
236 ABIT = config->ABIT == 0xffff ? 3 : config->ABIT;
237 PBIT = config->PBIT == 0xffff ? 0 : config->PBIT;
238 NW = config->NW == 0xffff ? 180 : config->NW;
239 }
240
241 if(NW==0) NW=180; // some data was taken (<=run 4700) where NW was written as 0 to file
242
243 // The integration window in the CDC should always extend past the end
244 //of the window
245 // Only true after about run 4100
246 nsamples_integral = (NW - (digihit->pulse_time / 10));
247
248 // Complete the pedestal subtraction here since we should know the correct number of samples.
249 int scaled_ped = raw_ped << PBIT;
250
251 if (maxamp > 0) maxamp = maxamp << ABIT;
252 //if (maxamp <= scaled_ped) continue;
253
254 maxamp = maxamp - scaled_ped;
255
256 // if (maxamp<FMWPC_HIT_THRESHOLD) {
257 // continue;
258 // }
259
260 // Apply calibration constants here
261 double t_raw = double(digihit->pulse_time);
262
263 // Scale factor to account for gain variation
264 //double gain=gains[layer][wire]; // REMOVE CHANNEL-SPECIFIC CORRECTIONS
265 double gain=1.;
266
267 // Charge and amplitude
268 //double q = a_scale *gain * double((digihit->pulse_integral<<IBIT)
269 // - scaled_ped*nsamples_integral);
270 double q = digihit->pulse_integral;
271 double amp = amp_a_scale*gain*double(maxamp);
272
273 //double t = t_scale * t_raw - time_offsets[layer][wire] + t_base;
274 double t = t_scale * t_raw /*- time_offsets[layer][wire]*/ + t_base; // REMOVE CHANNEL-SPECIFIC CORRECTIONS
275
276 DFMWPCHit *hit = new DFMWPCHit;
277 hit->layer = layer;
278 hit->wire = wire;
279
280 // Values for d, itrack, ptype only apply to MC data
281 // note that wire counting starts at 1
282 hit->q = q;
283 hit->amp = amp;
284 hit->t = t;
285 // hit->d = 0.0;
286 // hit->QF = digihit->QF;
287 // hit->itrack = -1;
288 // hit->ptype = 0;
289
290 hit->AddAssociatedObject(digihit);
291
292 _data.push_back(hit);
293
294 }
295
296 return NOERROR;
297}
298
299
300//------------------
301// erun
302//------------------
303jerror_t DFMWPCHit_factory::erun(void)
304{
305 return NOERROR;
306}
307
308//------------------
309// fini
310//------------------
311jerror_t DFMWPCHit_factory::fini(void)
312{
313 return NOERROR;
314}
315
316/* -- shouldn't need this if you make the CCDB tables 2D tables
317//------------------
318// FillCalibTable
319//------------------
320void DFMWPCHit_factory::FillCalibTable(vector< vector<double> > &table, vector<double> &raw_table)
321{
322 int ring = 0;
323 int straw = 0;
324
325 // reset table before filling it
326 table.clear();
327 table.resize( Nstraws.size() );
328
329 for (unsigned int channel=0; channel<raw_table.size(); channel++,straw++) {
330 // make sure that we don't try to load info for channels that don't exist
331 if (channel == maxChannels) break;
332
333 // if we've hit the end of the ring, move on to the next
334 if (straw == (int)Nstraws[ring]) {
335 ring++;
336 straw = 0;
337 }
338
339 table[ring].push_back( raw_table[channel] );
340 }
341
342}
343*/
344
345//------------------------------------
346// GetConstant
347// Allow a few different interfaces
348//------------------------------------
349const double DFMWPCHit_factory::GetConstant(const fmwpc_digi_constants_t &the_table,
350 const int in_layer, const int in_wire) const {
351
352 char str[256];
353
354 if ( (in_layer <= 0) || (static_cast<unsigned int>(in_layer) > Nlayers)) {
355 sprintf(str, "Bad layer # requested in DFMWPCHit_factory::GetConstant()!"
356 " requested=%d , should be %ud", in_layer, Nlayers);
357 std::cerr << str << std::endl;
358 throw JException(str);
359 }
360 if ( (in_wire <= 0) ||
361 (static_cast<unsigned int>(in_wire) > Nwires[in_layer]))
362 {
363 sprintf(str, "Bad wire # requested in DCDCHit_factory::GetConstant()!"
364 " requested=%d , should be %ud", in_wire, Nwires[in_layer]);
365 std::cerr << str << std::endl;
366 throw JException(str);
367 }
368
369 return the_table[in_layer][in_wire]; // depends on numbering
370}
371
372const double DFMWPCHit_factory::GetConstant(const fmwpc_digi_constants_t &the_table,
373 const DFMWPCDigiHit *in_digihit) const {
374
375 char str[256];
376
377 if ( (in_digihit->layer <= 0) ||
378 (static_cast<unsigned int>(in_digihit->layer) > Nlayers))
379 {
380 sprintf(str, "Bad layer # requested in DFMWPCHit_factory::GetConstant()!"
381 " requested=%d , should be %ud", in_digihit->layer, Nlayers);
382 std::cerr << str << std::endl;
383 throw JException(str);
384 }
385 if ( (in_digihit->wire <= 0) ||
386 (static_cast<unsigned int>(in_digihit->wire) > Nwires[in_digihit->layer]))
387 {
388 sprintf(str, "Bad wire # requested in DFMWPCHit_factory::GetConstant()!"
389 " requested=%d , should be %ud",
390 in_digihit->wire, Nwires[in_digihit->layer]);
391 std::cerr << str << std::endl;
392 throw JException(str);
393 }
394
395 return the_table[in_digihit->layer][in_digihit->wire]; // depends on numbering
396}
397
398const double DFMWPCHit_factory::GetConstant(const fmwpc_digi_constants_t &the_table,
399 const DFMWPCHit *in_hit) const {
400
401 char str[256];
402
403 if ( (in_hit->layer <= 0) || (static_cast<unsigned int>(in_hit->layer) > Nlayers)) {
404 sprintf(str, "Bad ring # requested in DFMWPCHit_factory::GetConstant()!"
405 " requested=%d , should be %ud", in_hit->layer, Nlayers);
406 std::cerr << str << std::endl;
407 throw JException(str);
408 }
409 if ( (in_hit->wire <= 0) ||
410 (static_cast<unsigned int>(in_hit->wire) > Nwires[in_hit->layer]) ) {
411 sprintf(str, "Bad straw # requested in DFMWPCHit_factory::GetConstant()!"
412 " requested=%d , should be %ud",
413 in_hit->wire, Nwires[in_hit->layer]);
414 std::cerr << str << std::endl;
415 throw JException(str);
416 }
417
418 return the_table[in_hit->layer][in_hit->wire]; // depends on numbering
419}
420