12 #include <phparameter/PHParameterContainerInterface.h>
13 #include <phparameter/PHParametersContainer.h>
64 std::cout <<
PHWHERE <<
"DST Node missing, doing nothing." << std::endl;
71 cout <<
Name() <<
"DST Node missing, doing nothing." << endl;
86 cout <<
"Could not locate g4 hit node " <<
hitnodename << endl;
109 cout <<
"Could not locate geometry node " <<
geonodename << endl;
129 map<int, PHG4CylinderGeom *>::const_iterator miter;
130 pair<map<int, PHG4CylinderGeom *>::const_iterator, map<int, PHG4CylinderGeom *>::const_iterator> begin_end = geo->
get_begin_end();
131 map<int, std::pair<double, double> >::iterator sizeiter;
132 for (miter = begin_end.first; miter != begin_end.second; ++miter)
138 cout <<
Name() <<
": No parameters for detid/layer " << layer
139 <<
", hits from this detid/layer will not be accumulated into cells" << endl;
146 double circumference = layergeom->
get_radius() * 2 * M_PI;
151 cout <<
"no cell sizes for layer " << layer << endl;
166 double etastepsize = (sizeiter->second).first;
169 if (etastepsize > etamax - etamin)
178 double fract = modf((etamax - etamin) / etastepsize, &d_etabins);
184 etastepsize = (etamax -
etamin) / d_etabins;
185 (sizeiter->second).first = etastepsize;
186 int etabins = d_etabins;
188 double etahi = etalow + etastepsize;
189 for (
int i = 0;
i < etabins;
i++)
191 if (etahi > (etamax + 1.
e-6))
193 cout <<
"etahi: " << etahi <<
", etamax: " << etamax << endl;
195 etahi += etastepsize;
199 double phimax = M_PI;
200 double phistepsize = (sizeiter->second).second;
202 if (phistepsize >= phimax - phimin)
211 double fract = modf((phimax - phimin) / phistepsize, &d_phibins);
217 phistepsize = (phimax -
phimin) / d_phibins;
218 (sizeiter->second).second = phistepsize;
221 double phihi = philow + phistepsize;
226 cout <<
"phihi: " << phihi <<
", phimax: " << phimax << endl;
228 phihi += phistepsize;
230 pair<int, int> phi_z_bin = make_pair(phibins, etabins);
245 double size_z = (sizeiter->second).second;
246 double size_r = (sizeiter->second).first;
249 if (size_r >= circumference)
258 double fract = modf(circumference / size_r, &bins_r);
265 size_r = circumference / bins_r;
266 (sizeiter->second).first = size_r;
267 double phistepsize = 2 * M_PI / bins_r;
269 double phimax = phimin + phistepsize;
273 if (phimax > (M_PI + 1
e-9))
275 cout <<
"phimax: " << phimax <<
", M_PI: " << M_PI
276 <<
"phimax-M_PI: " << phimax - M_PI << endl;
278 phimax += phistepsize;
281 if (size_z >= length_in_z)
290 double fract = modf(length_in_z / size_z, &bins_r);
297 pair<int, int> phi_z_bin = make_pair(nbins[0], nbins[1]);
300 size_z = length_in_z / bins_r;
301 (sizeiter->second).second = size_z;
302 double zlow = layergeom->
get_zmin();
303 double zhigh = zlow +
size_z;
305 for (
int i = 0;
i < nbins[1];
i++)
307 if (zhigh > (layergeom->
get_zmax() + 1
e-9))
309 cout <<
"zhigh: " << zhigh <<
", zmax "
311 <<
", zhigh-zmax: " << zhigh - layergeom->
get_zmax()
334 cout <<
"===================== PHG4CylinderCellReco::InitRun() =====================" << endl;
335 cout <<
" " <<
outdetector <<
" Segmentation Description: " << endl;
336 for (std::map<int, int>::iterator iter =
binning.begin();
339 int layer = iter->first;
345 cout <<
" Layer #" <<
binning.begin()->first <<
"-" <<
binning.rbegin()->first << endl;
352 cout <<
" Layer #" << layer << endl;
357 cout <<
"===========================================================================" << endl;
369 cout <<
"Could not locate g4 hit node " <<
hitnodename << endl;
375 cout <<
"could not locate cell node " <<
cellnodename << endl;
386 map<int, std::pair<double, double> >::iterator sizeiter;
388 pair<PHG4HitContainer::LayerIter, PHG4HitContainer::LayerIter> layer_begin_end = g4hit->
getLayers();
395 for (layer = layer_begin_end.first; layer != layer_begin_end.second; layer++)
411 for (hiter = hit_begin_end.first; hiter != hit_begin_end.second; hiter++)
415 if (hiter->second->get_t(0) >
tmin_max[*
layer].second)
continue;
416 if (hiter->second->get_t(1) <
tmin_max[*
layer].first)
continue;
417 if (hiter->second->get_t(1) - hiter->second->get_t(0) >
m_DeltaTMap[*
layer])
continue;
420 pair<double, double> etaphi[2];
423 for (
int i = 0;
i < 2;
i++)
430 if (phibin[0] < 0 || phibin[0] >= nphibins || phibin[1] < 0 || phibin[1] >= nphibins)
434 if (etabin[0] < 0 || etabin[0] >= nzbins || etabin[1] < 0 || etabin[1] >= nzbins)
443 hiter->second->identify();
448 int intphibin = phibin[0];
449 int intetabin = etabin[0];
450 int intphibinout = phibin[1];
451 int intetabinout = etabin[1];
455 double ax = (etaphi[0]).second;
456 double ay = (etaphi[0]).first;
457 double bx = (etaphi[1]).second;
458 double by = (etaphi[1]).first;
459 if (intphibin > intphibinout)
462 intphibin = intphibinout;
465 if (intetabin > intetabinout)
468 intetabin = intetabinout;
472 double trklen = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
485 vector<double> vdedx;
487 if (intphibin == intphibinout && intetabin == intetabinout)
489 if (
Verbosity() > 0) cout <<
"SINGLE CELL FIRED: " << intphibin <<
" " << intetabin << endl;
490 vphi.push_back(intphibin);
491 veta.push_back(intetabin);
492 vdedx.push_back(trklen);
498 for (
int ibp = intphibin; ibp <= intphibinout; ibp++)
502 for (
int ibz = intetabin; ibz <= intetabinout; ibz++)
512 if (
Verbosity() > 0) cout <<
"CELL FIRED: " << ibp <<
" " << ibz <<
" " << intersect.second << endl;
515 vdedx.push_back(intersect.second);
520 if (
Verbosity() > 0) cout <<
"NUMBER OF FIRED CELLS = " << vphi.size() << endl;
523 for (
unsigned int ii = 0; ii < vphi.size(); ii++)
526 vdedx[ii] = vdedx[ii] / trklen;
527 if (
Verbosity() > 0) cout <<
" CELL " << ii <<
" dE/dX = " << vdedx[ii] << endl;
529 if (
Verbosity() > 0) cout <<
" TOTAL TRACK LENGTH = " << tmpsum <<
" " << trklen << endl;
531 for (
unsigned int i1 = 0; i1 < vphi.size(); i1++)
533 int iphibin = vphi[i1];
534 int ietabin = veta[i1];
539 unsigned long long tmp = iphibin;
540 unsigned long long key = tmp << 32;
544 cout <<
" iphibin " << iphibin <<
" ietabin " << ietabin <<
" key 0x" << hex << key << dec << endl;
558 if (!isfinite(hiter->second->get_edep() * vdedx[i1]))
560 cout <<
"hit 0x" << hex << hiter->first << dec <<
" not finite, edep: "
561 << hiter->second->
get_edep() <<
" weight " << vdedx[i1] << endl;
563 cell->
add_edep(hiter->first, hiter->second->get_edep() * vdedx[i1]);
564 cell->
add_edep(hiter->second->get_edep() * vdedx[i1]);
569 cell->
add_shower_edep(hiter->second->get_shower_id(), hiter->second->get_edep() * vdedx[i1]);
571 if (!isfinite(hiter->second->get_edep() * vdedx[i1]))
573 cout <<
PHWHERE <<
" invalid energy dep " << hiter->second->get_edep()
574 <<
" or path length: " << vdedx[i1] << endl;
594 <<
", energy dep: " <<
it->second->get_edep()
601 cout <<
Name() <<
": found " << numcells <<
" eta/phi cells with energy deposition" << endl;
610 cout <<
"logical screwup!!! no sizes for layer " << *layer << endl;
613 double zstepsize = (sizeiter->second).second;
616 for (hiter = hit_begin_end.first; hiter != hit_begin_end.second; hiter++)
620 if (hiter->second->get_t(0) >
tmin_max[*
layer].second)
continue;
621 if (hiter->second->get_t(1) <
tmin_max[*
layer].first)
continue;
622 if (hiter->second->get_t(1) - hiter->second->get_t(0) > 100)
continue;
632 if (
Verbosity() > 0) cout <<
"--------- new hit in layer # " << *layer << endl;
634 for (
int i = 0;
i < 2;
i++)
636 xinout[
i] = hiter->second->get_x(
i);
637 yinout[
i] = hiter->second->get_y(
i);
638 px[
i] = hiter->second->get_px(
i);
639 py[
i] = hiter->second->get_py(
i);
640 phi[
i] = atan2(hiter->second->get_y(
i), hiter->second->get_x(
i));
641 z[
i] = hiter->second->get_z(
i);
643 zbin[
i] = geo->
get_zbin(hiter->second->get_z(i));
645 if (
Verbosity() > 0) cout <<
" " << i <<
" phibin: " << phibin[i] <<
", phi: " << phi[i] <<
", stepsize: " << phistepsize << endl;
646 if (
Verbosity() > 0) cout <<
" " << i <<
" zbin: " << zbin[i] <<
", z = " << hiter->second->get_z(i) <<
", stepsize: " << zstepsize <<
" offset: " <<
zmin_max[*
layer].first << endl;
649 if (phibin[0] < 0 || phibin[0] >= nphibins || phibin[1] < 0 || phibin[1] >= nphibins)
653 if (zbin[0] < 0 || zbin[0] >= nzbins || zbin[1] < 0 || zbin[1] >= nzbins)
660 hiter->second->identify();
665 int intphibin = phibin[0];
666 int intzbin = zbin[0];
667 int intphibinout = phibin[1];
668 int intzbinout = zbin[1];
672 cout <<
" phi bin range: " << intphibin <<
" to " << intphibinout <<
" phi: " << phi[0] <<
" to " << phi[1] << endl;
673 cout <<
" Z bin range: " << intzbin <<
" to " << intzbinout <<
" Z: " << z[0] <<
" to " << z[1] << endl;
674 cout <<
" phi difference: " << (phi[1] - phi[0]) * 1000. <<
" milliradians." << endl;
675 cout <<
" phi difference: " << 2.5 * (phi[1] - phi[0]) * 10000. <<
" microns." << endl;
676 cout <<
" path length = " << sqrt((xinout[1] - xinout[0]) * (xinout[1] - xinout[0]) + (yinout[1] - yinout[0]) * (yinout[1] - yinout[0])) << endl;
677 cout <<
" px = " << px[0] <<
" " << px[1] << endl;
678 cout <<
" py = " << py[0] <<
" " << py[1] << endl;
679 cout <<
" x = " << xinout[0] <<
" " << xinout[1] << endl;
680 cout <<
" y = " << yinout[0] <<
" " << yinout[1] << endl;
689 if (intphibin > intphibinout)
692 intphibin = intphibinout;
695 if (intzbin > intzbinout)
698 intzbin = intzbinout;
702 double trklen = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
715 vector<double> vdedx;
717 if (intphibin == intphibinout && intzbin == intzbinout)
721 cout <<
"SINGLE CELL FIRED: " << intphibin <<
" " << intzbin << endl;
723 vphi.push_back(intphibin);
724 vz.push_back(intzbin);
725 vdedx.push_back(trklen);
730 double zstep_half = geo->
get_zstep() / 2.;
731 for (
int ibp = intphibin; ibp <= intphibinout; ibp++)
735 for (
int ibz = intzbin; ibz <= intzbinout; ibz++)
744 if (
Verbosity() > 0) cout <<
"CELL FIRED: " << ibp <<
" " << ibz <<
" " << intersect.second << endl;
747 vdedx.push_back(intersect.second);
752 if (
Verbosity() > 0) cout <<
"NUMBER OF FIRED CELLS = " << vz.size() << endl;
755 for (
unsigned int ii = 0; ii < vz.size(); ii++)
758 vdedx[ii] = vdedx[ii] / trklen;
759 if (
Verbosity() > 0) cout <<
" CELL " << ii <<
" dE/dX = " << vdedx[ii] << endl;
761 if (
Verbosity() > 0) cout <<
" TOTAL TRACK LENGTH = " << tmpsum <<
" " << trklen << endl;
763 for (
unsigned int i1 = 0; i1 < vphi.size(); i1++)
765 int iphibin = vphi[i1];
768 unsigned long long tmp = iphibin;
769 unsigned long long key = tmp << 32;
773 cout <<
" iphibin " << iphibin <<
" izbin " << izbin <<
" key 0x" << hex << key << dec << endl;
784 cout <<
" add energy to existing cell for key = " <<
cellptmap.find(key)->first << endl;
789 cout <<
" NAN lighy yield with vdedx[i1] = " << vdedx[i1]
790 <<
" and hiter->second->get_light_yield() = " << hiter->second->get_light_yield() << endl;
797 cout <<
" did not find a previous entry for key = 0x" << hex << key << dec <<
" create a new one" << endl;
803 if (!isfinite(hiter->second->get_edep() * vdedx[i1]))
805 cout <<
"hit 0x" << hex << hiter->first << dec <<
" not finite, edep: "
806 << hiter->second->
get_edep() <<
" weight " << vdedx[i1] << endl;
808 cell->
add_edep(hiter->first, hiter->second->get_edep() * vdedx[i1]);
809 cell->
add_edep(hiter->second->get_edep() * vdedx[i1]);
813 if (
Verbosity() > 1 && !std::isfinite(hiter->second->get_light_yield() * vdedx[i1]))
815 cout <<
" NAN lighy yield with vdedx[i1] = " << vdedx[i1]
816 <<
" and hiter->second->get_light_yield() = " << hiter->second->get_light_yield() << endl;
819 cell->
add_shower_edep(hiter->second->get_shower_id(), hiter->second->get_edep() * vdedx[i1]);
838 <<
", energy dep: " <<
it->second->get_edep()
845 cout <<
"found " << numcells <<
" z/phi cells with energy deposition" << endl;
853 cout <<
"cellptmap for layer " << *layer <<
" has final length " <<
cellptmap.size();
862 cout <<
" reset it to " <<
cellptmap.size() << endl;
877 cout <<
"size for layer " << detid <<
" already set" << endl;
889 cout <<
"size for layer " << detid <<
" already set" << endl;
914 double sum_energy_cells = 0.;
915 double sum_energy_stored_hits = 0.;
916 double sum_energy_stored_showers = 0.;
919 for (citer = cell_begin_end.first; citer != cell_begin_end.second; ++citer)
921 sum_energy_cells += citer->second->get_edep();
925 sum_energy_stored_hits += iter->second;
930 sum_energy_stored_showers += iter->second;
934 if (sum_energy_stored_hits > 0)
936 if (fabs(sum_energy_cells - sum_energy_stored_hits) / sum_energy_cells > 1
e-6)
938 cout <<
"energy mismatch between cell energy " << sum_energy_cells
939 <<
" and stored hit energies " << sum_energy_stored_hits
943 if (sum_energy_stored_showers > 0)
945 if (fabs(sum_energy_cells - sum_energy_stored_showers) / sum_energy_cells > 1
e-6)
947 cout <<
"energy mismatch between cell energy " << sum_energy_cells
948 <<
" and stored shower energies " << sum_energy_stored_showers
954 cout <<
"energy mismatch between cells: " << sum_energy_cells
960 cout <<
Name() <<
": sum cell energy: " << sum_energy_cells <<
" GeV" << endl;
961 cout <<
Name() <<
": sum shower energy: " << sum_energy_stored_showers <<
" GeV" << endl;
962 cout <<
Name() <<
": sum stored hit energy: " << sum_energy_stored_hits <<
" GeV" << endl;
971 cout <<
Name() <<
": sum cell energy: " << sum_energy_cells <<
" GeV" << endl;
972 cout <<
Name() <<
": sum shower energy: " << sum_energy_stored_showers <<
" GeV" << endl;
973 cout <<
Name() <<
": sum stored hit energy: " << sum_energy_stored_hits <<
" GeV" << endl;