24 #include <gsl/gsl_randist.h>
25 #include <gsl/gsl_rng.h>
39 , ChargeToPeakVolts(20)
40 , ADCSignalConversionGain(std::numeric_limits<float>::signaling_NaN())
41 , ADCNoiseConversionGain(std::numeric_limits<float>::signaling_NaN())
44 std::cout <<
Name() <<
" random seed: " << seed << std::endl;
50 std::cout <<
"Creating PHG4TpcDigitizer with name = " << name << std::endl;
81 std::cout <<
PHWHERE <<
"DST Node missing, doing nothing." << std::endl;
94 std::cout <<
"====================== PHG4TpcDigitizer::InitRun() =====================" << std::endl;
95 for (std::map<int, unsigned int>::iterator tpiter =
_max_adc.begin();
99 std::cout <<
" Max ADC in Layer #" << tpiter->first <<
" = " << tpiter->second << std::endl;
101 for (std::map<int, float>::iterator tpiter =
_energy_scale.begin();
105 std::cout <<
" Energy per ADC in Layer #" << tpiter->first <<
" = " << 1.0e6 * tpiter->second <<
" keV" << std::endl;
107 std::cout <<
"===========================================================================" << std::endl;
126 if (!geom_container)
return;
130 layeriter != layerrange.second;
133 int layer = layeriter->second->get_layer();
134 float thickness = (layeriter->second)->get_thickness();
135 float pitch = (layeriter->second)->get_phistep() * (layeriter->second)->get_radius();
138 float minpath = pitch;
139 if (length < minpath) minpath =
length;
140 if (thickness < minpath) minpath =
thickness;
141 float mip_e = 0.003876 * minpath;
156 unsigned int print_layer = 18;
226 findNode::getClass<PHG4TpcCylinderGeomContainer>(topNode,
"CYLINDERCELLGEOM_SVTX");
229 std::cout <<
PHWHERE <<
"ERROR: Can't find node CYLINDERCELLGEOM_SVTX" << std::endl;
233 TrkrHitSetContainer *trkrhitsetcontainer = findNode::getClass<TrkrHitSetContainer>(topNode,
"TRKR_HITSET");
234 if (!trkrhitsetcontainer)
236 std::cout <<
"Could not locate TRKR_HITSET node, quit! " << std::endl;
240 TrkrHitTruthAssoc *hittruthassoc = findNode::getClass<TrkrHitTruthAssoc>(topNode,
"TRKR_HITTRUTHASSOC");
243 std::cout <<
PHWHERE <<
" Could not locate TRKR_HITTRUTHASSOC node, quit! " << std::endl;
257 if (!layergeom) exit(1);
261 std::cout <<
" nphibins " << nphibins << std::endl;
263 for(
unsigned int side = 0; side < 2; ++side)
267 std::cout <<
"TPC layer " <<
layer <<
" side " << side << std::endl;
271 for (
int iphi = 0; iphi < nphibins; iphi++)
279 hitset_iter != hitset_range.second;
288 if(this_side != side)
continue;
291 if (
layer == print_layer)
292 std::cout <<
"new: PHG4TpcDigitizer: processing signal hits for layer " <<
layer
293 <<
" hitsetkey " << hitsetkey <<
" side " << side << std::endl;
299 hit_iter != hit_range.second;
320 for (
int it = 0;
it < ntbins;
it++)
322 t_sorted_hits.push_back(std::vector<TrkrHitSet::ConstIterator>());
333 if (
layer == print_layer)
336 std::cout <<
"iphi " << iphi <<
" adding existing signal hit to t vector for layer " <<
layer
338 <<
" tbin " << tbin <<
" hitkey " << hitkey
357 for (
int it = 0;
it < ntbins;
it++)
367 if (
layer == print_layer)
368 std::cout <<
"existing signal hit: layer " <<
layer <<
" iphi " << iphi <<
" it " <<
it
371 <<
" signal with noise " << signal_with_noise
384 if (
layer == print_layer)
385 std::cout <<
"noise hit: layer " <<
layer <<
" side " << side <<
" iphi " << iphi <<
" it " <<
it
387 <<
" noise " << noise
394 std::cout <<
"Impossible value of is_populated, it = " <<
it
407 for (
int it = 0;
it < ntbins;
it++)
409 if (
it < binpointer)
continue;
424 if (
layer == print_layer)
425 std::cout << std::endl
426 <<
"Hit above threshold of "
429 <<
" digitize this and 4 following bins: " << std::endl;
431 for (
int itup = 0; itup < 5; itup++)
433 if (
it + itup < ntbins && it + itup >= 0)
445 unsigned int adc_output = (
unsigned int) (input * 1024.0 / 2200.0);
447 if (input < 0) adc_output = 0;
448 if (input > 1023) adc_output = 1023;
455 if (
layer == print_layer)
456 std::cout <<
" Digitizing: iphi " << iphi <<
" it+itup " <<
it + itup
461 <<
" adc_output " << adc_output
462 <<
" hitkey " << hitkey
464 <<
" binpointer " << binpointer
476 unsigned int sector = 12 * iphi / nphibins;
481 hitset_iter->second->addHitSpecificKey(hitkey, hit);
484 if (
layer == print_layer)
485 std::cout <<
" adding noise TrkrHit for iphi " << iphi
486 <<
" tbin " <<
it + itup
488 <<
" created new hit with hitkey " << hitkey
489 <<
" energy " <<
adc_input[
it + itup] <<
" adc " << adc_output
490 <<
" binpointer " << binpointer
506 unsigned int sector = 12 * iphi / nphibins;
508 auto hitset = trkrhitsetcontainer->
findHitSet(hitsetkey);
514 hit = hitset->getHit(hitkey);
531 std::cout <<
"From PHG4TpcDigitizer: hitsetcontainer dump at end before cleaning:" << std::endl;
533 std::vector<std::pair<TrkrDefs::hitsetkey, TrkrDefs::hitkey>> delete_hitkey_list;
539 hitset_iter != hitset_range_now.second;
548 std::cout <<
"PHG4TpcDigitizer: hitset with key: " << hitsetkey <<
" in layer " << layer <<
" with sector " << sector <<
" side " << side << std::endl;
554 hit_iter != hit_range.second;
558 TrkrHit *tpchit = hit_iter->second;
561 std::cout <<
" layer " << layer <<
" hitkey " << hitkey <<
" pad " <<
TpcDefs::getPad(hitkey)
563 <<
" adc " << tpchit->
getAdc() << std::endl;
565 if (tpchit->
getAdc() == 0)
569 std::cout <<
" -- this hit not digitized - delete it" << std::endl;
572 delete_hitkey_list.push_back(std::make_pair(hitsetkey, hitkey));
578 for (
unsigned int i = 0;
i < delete_hitkey_list.size();
i++)
582 hitset->
removeHit(delete_hitkey_list[
i].second);
584 if (layer == print_layer)
585 std::cout <<
"removed hit with hitsetkey " << delete_hitkey_list[
i].first
586 <<
" and hitkey " << delete_hitkey_list[
i].second << std::endl;
594 std::cout <<
"From PHG4TpcDigitizer: hitsetcontainer dump at end after cleaning:" << std::endl;
598 hitset_iter != hitset_range_now.second;
604 if (layer != print_layer)
continue;
607 if (
Verbosity() > 5 && layer == print_layer)
608 std::cout <<
"PHG4TpcDigitizer: hitset with key: " << hitsetkey <<
" in layer " << layer <<
" with sector " << sector <<
" side " << side << std::endl;
614 hit_iter != hit_range.second;
618 TrkrHit *tpchit = hit_iter->second;
621 <<
" adc " << tpchit->
getAdc() << std::endl;
623 if (tpchit->
getAdc() == 0)
625 std::cout <<
" Oops! -- this hit not digitized and not deleted!" << std::endl;
640 adc_input_voltage += noise_voltage;
642 return adc_input_voltage;