36 chkenergyconservation(0),
37 sum_energy_before_cuts(0.),
61 std::cout <<
PHWHERE <<
"DST Node missing, doing nothing." << std::endl;
68 cout <<
Name() <<
"DST Node missing, doing nothing." << endl;
85 cout <<
"Could not locate g4 hit node " <<
hitnodename << endl;
110 cout <<
"Could not locate geometry node " <<
geonodename << endl;
132 map<int, PHG4CylinderGeom *>::const_iterator miter;
133 pair <map<int, PHG4CylinderGeom *>::const_iterator, map<int, PHG4CylinderGeom *>::const_iterator> begin_end = geo->
get_begin_end();
134 map<int, std::pair <double, double> >::iterator sizeiter;
135 for (miter = begin_end.first; miter != begin_end.second; ++miter)
141 cout <<
Name() <<
": No parameters for detid/layer " << layer
142 <<
", hits from this detid/layer will not be accumulated into cells" << endl;
148 double circumference = layergeom->
get_radius() * 2 * M_PI;
153 cout <<
"no cell sizes for layer " << layer << endl;
167 zmin_max[layer] = make_pair(etamin, etamax);
168 double etastepsize = (sizeiter->second).first;
170 double fract = modf((etamax - etamin) / etastepsize, &d_etabins);
175 etastepsize = (etamax - etamin) / d_etabins;
176 (sizeiter->second).first = etastepsize;
177 int etabins = d_etabins;
178 double etalow = etamin;
179 double etahi = etalow + etastepsize;
180 for (
int i = 0; i < etabins; i++)
182 if (etahi > (etamax + 1.e-6))
184 cout <<
"etahi: " << etahi <<
", etamax: " << etamax << endl;
186 etahi += etastepsize;
191 double phistepsize = (sizeiter->second).second;
193 fract = modf((phimax - phimin) / phistepsize, &d_phibins);
198 phistepsize = (phimax -
phimin) / d_phibins;
199 (sizeiter->second).second = phistepsize;
202 double phihi = philow + phistepsize;
203 for (
int i = 0; i <
phibins; i++)
207 cout <<
"phihi: " << phihi <<
", phimax: " << phimax << endl;
209 phihi += phistepsize;
211 pair<int, int> phi_z_bin = make_pair(phibins, etabins);
226 double size_z = (sizeiter->second).second;
227 double size_r = (sizeiter->second).first;
232 double fract = modf(circumference / size_r, &bins_r);
238 size_r = circumference / bins_r;
239 (sizeiter->second).first = size_r;
240 double phistepsize = 2 * M_PI / bins_r;
242 double phimax = phimin + phistepsize;
244 for (
int i = 0 ; i <
nbins[0]; i++)
246 if (phimax > (M_PI + 1e-9))
248 cout <<
"phimax: " << phimax <<
", M_PI: " << M_PI
249 <<
"phimax-M_PI: " << phimax - M_PI << endl;
251 phimax += phistepsize;
256 fract = modf(length_in_z / size_z, &bins_r);
262 pair<int, int> phi_z_bin = make_pair(nbins[0], nbins[1]);
265 size_z = length_in_z / bins_r;
266 (sizeiter->second).second = size_z;
267 double zlow = layergeom->
get_zmin();
268 double zhigh = zlow + size_z;;
269 for (
int i = 0 ; i < nbins[1]; i++)
271 if (zhigh > (layergeom->
get_zmax() + 1e-9))
273 cout <<
"zhigh: " << zhigh <<
", zmax "
275 <<
", zhigh-zmax: " << zhigh - layergeom->
get_zmax()
298 cout <<
"===================== PHG4CylinderCellReco::InitRun() =====================" << endl;
299 cout <<
" " <<
outdetector <<
" Segmentation Description: " << endl;
300 for (std::map<int, int>::iterator iter =
binning.begin();
303 int layer = iter->first;
309 cout <<
" Layer #" <<
binning.begin()->first <<
"-" <<
binning.rbegin()->first << endl;
311 cout <<
" Cell Size (phi,eta): (" <<
cell_size[layer].first <<
" rad, " <<
cell_size[layer].second <<
" units)" << endl;
316 cout <<
" Layer #" << layer << endl;
318 cout <<
" Cell Size (phi,z): (" <<
cell_size[layer].first <<
" cm, " <<
cell_size[layer].second <<
" cm)" << endl;
321 cout <<
"===========================================================================" << endl;
337 cout <<
"Could not locate g4 hit node " <<
hitnodename << endl;
343 cout <<
"could not locate cell node " <<
cellnodename << endl;
354 map<int, std::pair <double, double> >::iterator sizeiter;
356 pair<PHG4HitContainer::LayerIter, PHG4HitContainer::LayerIter> layer_begin_end = g4hit->
getLayers();
363 for (layer = layer_begin_end.first; layer != layer_begin_end.second; layer++)
379 for (hiter = hit_begin_end.first; hiter != hit_begin_end.second; hiter++)
383 if (hiter->second->get_t(0) >
tmin_max[*layer].second)
continue;
384 if (hiter->second->get_t(1) <
tmin_max[*layer].first)
continue;
386 pair<double, double> etaphi[2];
389 for (
int i = 0; i < 2; i++)
391 etaphi[i] =
get_etaphi(hiter->second->get_x(i), hiter->second->get_y(i), hiter->second->get_z(i));
392 etabin[i] = geo->
get_etabin( etaphi[i].first );
393 phibin[i] = geo->
get_phibin( etaphi[i].second );
396 if (phibin[0] < 0 || phibin[0] >= nphibins || phibin[1] < 0 || phibin[1] >= nphibins)
400 if (etabin[0] < 0 || etabin[0] >= nzbins || etabin[1] < 0 || etabin[1] >= nzbins)
409 hiter->second->identify();
414 int intphibin = phibin[0];
415 int intetabin = etabin[0];
416 int intphibinout = phibin[1];
417 int intetabinout = etabin[1];
421 double ax = (etaphi[0]).second;
422 double ay = (etaphi[0]).first;
423 double bx = (etaphi[1]).second;
424 double by = (etaphi[1]).first;
425 if (intphibin > intphibinout)
428 intphibin = intphibinout;
431 if (intetabin > intetabinout)
434 intetabin = intetabinout;
438 double trklen = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
451 vector<double> vdedx;
453 if (intphibin == intphibinout && intetabin == intetabinout)
455 if (
verbosity > 0) cout <<
"SINGLE CELL FIRED: " << intphibin <<
" " << intetabin << endl;
456 vphi.push_back(intphibin);
457 veta.push_back(intetabin);
458 vdedx.push_back(trklen);
464 for (
int ibp = intphibin; ibp <= intphibinout; ibp++)
468 for (
int ibz = intetabin; ibz <= intetabinout; ibz++)
478 if (
verbosity > 0) cout <<
"CELL FIRED: " << ibp <<
" " << ibz <<
" " << rr << endl;
486 if (
verbosity > 0) cout <<
"NUMBER OF FIRED CELLS = " << vphi.size() << endl;
489 for (
unsigned int ii = 0; ii < vphi.size(); ii++)
492 vdedx[ii] = vdedx[ii] / trklen;
493 if (
verbosity > 0) cout <<
" CELL " << ii <<
" dE/dX = " << vdedx[ii] << endl;
495 if (
verbosity > 0) cout <<
" TOTAL TRACK LENGTH = " << tmpsum <<
" " << trklen << endl;
497 for (
unsigned int i1 = 0; i1 < vphi.size(); i1++)
500 int iphibin = vphi[i1];
501 int ietabin = veta[i1];
506 unsigned long long tmp = iphibin;
507 unsigned long long key = tmp << 32;
511 cout <<
" iphibin " << iphibin <<
" ietabin " << ietabin <<
" key 0x" << hex << key << dec << endl;
525 if (! isfinite(hiter->second->get_edep()*vdedx[i1]))
527 cout <<
"hit 0x" << hex << hiter->first << dec <<
" not finite, edep: "
528 << hiter->second->
get_edep() <<
" weight " << vdedx[i1] << endl;
530 cell->
add_edep(hiter->first, hiter->second->get_edep()*vdedx[i1]);
531 cell->
add_edep(hiter->second->get_edep()*vdedx[i1]);
536 cell->
add_shower_edep(hiter->second->get_shower_id(), hiter->second->get_edep()*vdedx[i1]);
538 if (! isfinite(hiter->second->get_edep()*vdedx[i1]))
540 cout <<
PHWHERE <<
" invalid energy dep " << hiter->second->get_edep()
541 <<
" or path length: " << vdedx[i1] << endl;
561 <<
", energy dep: " <<
it->second->get_edep()
568 cout <<
Name() <<
": found " << numcells <<
" eta/phi cells with energy deposition" << endl;
579 cout <<
"logical screwup!!! no sizes for layer " << *layer << endl;
582 double zstepsize = (sizeiter->second).second;
583 double phistepsize =
phistep[*layer];
585 for (hiter = hit_begin_end.first; hiter != hit_begin_end.second; hiter++)
589 if (hiter->second->get_t(0) >
tmin_max[*layer].second)
continue;
590 if (hiter->second->get_t(1) <
tmin_max[*layer].first)
continue;
600 if (
verbosity > 0) cout <<
"--------- new hit in layer # " << *layer << endl;
602 for (
int i = 0; i < 2; i++)
604 xinout[i] = hiter->second->get_x(i);
605 yinout[i] = hiter->second->get_y(i);
606 px[i] = hiter->second->get_px(i);
607 py[i] = hiter->second->get_py(i);
608 phi[i] = atan2(hiter->second->get_y(i), hiter->second->get_x(i));
609 z[i] = hiter->second->get_z(i);
611 zbin[i] = geo->
get_zbin( hiter->second->get_z(i) );
613 if (
verbosity > 0) cout <<
" " << i <<
" phibin: " << phibin[i] <<
", phi: " << phi[i] <<
", stepsize: " << phistepsize << endl;
614 if (
verbosity > 0) cout <<
" " << i <<
" zbin: " << zbin[i] <<
", z = " << hiter->second->get_z(i) <<
", stepsize: " << zstepsize <<
" offset: " <<
zmin_max[*layer].first << endl;
617 if (phibin[0] < 0 || phibin[0] >= nphibins || phibin[1] < 0 || phibin[1] >= nphibins)
621 if (zbin[0] < 0 || zbin[0] >= nzbins || zbin[1] < 0 || zbin[1] >= nzbins)
629 hiter->second->identify();
634 int intphibin = phibin[0];
635 int intzbin = zbin[0];
636 int intphibinout = phibin[1];
637 int intzbinout = zbin[1];
641 cout <<
" phi bin range: " << intphibin <<
" to " << intphibinout <<
" phi: " << phi[0] <<
" to " << phi[1] << endl;
642 cout <<
" Z bin range: " << intzbin <<
" to " << intzbinout <<
" Z: " << z[0] <<
" to " << z[1] << endl;
643 cout <<
" phi difference: " << (phi[1] - phi[0]) * 1000. <<
" milliradians." << endl;
644 cout <<
" phi difference: " << 2.5 * (phi[1] - phi[0]) * 10000. <<
" microns." << endl;
645 cout <<
" path length = " << sqrt((xinout[1] - xinout[0]) * (xinout[1] - xinout[0]) + (yinout[1] - yinout[0]) * (yinout[1] - yinout[0])) << endl;
646 cout <<
" px = " << px[0] <<
" " << px[1] << endl;
647 cout <<
" py = " << py[0] <<
" " << py[1] << endl;
648 cout <<
" x = " << xinout[0] <<
" " << xinout[1] << endl;
649 cout <<
" y = " << yinout[0] <<
" " << yinout[1] << endl;
658 if (intphibin > intphibinout)
661 intphibin = intphibinout;
664 if (intzbin > intzbinout)
667 intzbin = intzbinout;
671 double trklen = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
684 vector<double> vdedx;
686 if (intphibin == intphibinout && intzbin == intzbinout)
690 cout <<
"SINGLE CELL FIRED: " << intphibin <<
" " << intzbin << endl;
692 vphi.push_back(intphibin);
693 vz.push_back(intzbin);
694 vdedx.push_back(trklen);
699 double zstep_half = geo->
get_zstep() / 2.;
700 for (
int ibp = intphibin; ibp <= intphibinout; ibp++)
704 for (
int ibz = intzbin; ibz <= intzbinout; ibz++)
714 if (
verbosity > 0) cout <<
"CELL FIRED: " << ibp <<
" " << ibz <<
" " << rr << endl;
722 if (
verbosity > 0) cout <<
"NUMBER OF FIRED CELLS = " << vz.size() << endl;
725 for (
unsigned int ii = 0; ii < vz.size(); ii++)
728 vdedx[ii] = vdedx[ii] / trklen;
729 if (
verbosity > 0) cout <<
" CELL " << ii <<
" dE/dX = " << vdedx[ii] << endl;
731 if (
verbosity > 0) cout <<
" TOTAL TRACK LENGTH = " << tmpsum <<
" " << trklen << endl;
733 for (
unsigned int i1 = 0; i1 < vphi.size(); i1++)
735 int iphibin = vphi[i1];
738 unsigned long long tmp = iphibin;
739 unsigned long long key = tmp << 32;
743 cout <<
" iphibin " << iphibin <<
" izbin " << izbin <<
" key 0x" << hex << key << dec << endl;
754 cout <<
" add energy to existing cell for key = " <<
cellptmap.find(key)->first << endl;
760 cout <<
" NAN lighy yield with vdedx[i1] = " << vdedx[i1]
761 <<
" and hiter->second->get_light_yield() = " << hiter->second->get_light_yield() << endl;
769 cout <<
" did not find a previous entry for key = " << key <<
" create a new one" << endl;
775 if (! isfinite(hiter->second->get_edep()*vdedx[i1]))
777 cout <<
"hit 0x" << hex << hiter->first << dec <<
" not finite, edep: "
778 << hiter->second->
get_edep() <<
" weight " << vdedx[i1] << endl;
780 cell->
add_edep(hiter->first, hiter->second->get_edep()*vdedx[i1]);
781 cell->
add_edep(hiter->second->get_edep()*vdedx[i1]);
785 if(
verbosity > 1 && !std::isfinite(hiter->second->get_light_yield()*vdedx[i1]))
787 cout <<
" NAN lighy yield with vdedx[i1] = " << vdedx[i1]
788 <<
" and hiter->second->get_light_yield() = " << hiter->second->get_light_yield() << endl;
791 cell->
add_shower_edep(hiter->second->get_shower_id(), hiter->second->get_edep()*vdedx[i1]);
811 <<
", energy dep: " <<
it->second->get_edep()
818 cout <<
"found " << numcells <<
" z/phi cells with energy deposition" << endl;
826 cout <<
"cellptmap for layer " << *layer <<
" has final length " <<
cellptmap.size();
835 cout <<
" reset it to " <<
cellptmap.size() << endl;
852 cout <<
"size for layer " << detid <<
" already set" << endl;
865 cout <<
"size for layer " << detid <<
" already set" << endl;
877 cell_size[i] = std::make_pair(sizeA, sizeB);
896 radius = sqrt(x * x + y * y);
898 theta = atan2(radius, z);
899 eta = -log(tan(theta / 2.));
900 return make_pair(eta, phi);
908 theta = atan2(radius, fabs(z));
909 eta = -log(tan(theta / 2.));
946 double bottom = fx * px + fy * py;
949 double top = gx * px + gy * py;
958 if (h > 0. && h < 1.)
963 if ((*rx > ax && *rx > bx) || (*rx < ax && *rx < bx) || (*ry < ay && *ry < by) || (*ry > ay && *ry > by))
1001 if (cx > dx || cy > dy)
1003 cerr <<
"ERROR: Bad rectangle definition!" << endl;
1048 *rr = sqrt( (vx[0] - vx[1]) * (vx[0] - vx[1]) + (vy[0] - vy[1]) * (vy[0] - vy[1]) );
1054 if (ax > cx && ay > cy && ax < dx && ay < dy)
1057 *rr = sqrt((vx[0] - ax) * (vx[0] - ax) + (vy[0] - ay) * (vy[0] - ay));
1059 if (bx > cx && by > cy && bx < dx && by < dy)
1062 *rr = sqrt((vx[0] - bx) * (vx[0] - bx) + (vy[0] - by) * (vy[0] - by));
1066 if (i1 || i2 || i3 || i4)
1078 double sum_energy_cells = 0.;
1079 double sum_energy_stored_hits = 0.;
1080 double sum_energy_stored_showers = 0.;
1083 for (citer = cell_begin_end.first; citer != cell_begin_end.second; ++citer)
1085 sum_energy_cells += citer->second->get_edep();
1089 sum_energy_stored_hits += iter->second;
1094 sum_energy_stored_showers += iter->second;
1098 if (sum_energy_stored_hits > 0)
1100 if (fabs(sum_energy_cells-sum_energy_stored_hits)/sum_energy_cells > 1e-6)
1102 cout <<
"energy mismatch between cell energy " << sum_energy_cells
1103 <<
" and stored hit energies " << sum_energy_stored_hits
1107 if (sum_energy_stored_showers > 0)
1109 if (fabs(sum_energy_cells-sum_energy_stored_showers)/sum_energy_cells > 1e-6)
1111 cout <<
"energy mismatch between cell energy " << sum_energy_cells
1112 <<
" and stored shower energies " << sum_energy_stored_showers
1118 cout <<
"energy mismatch between cells: " << sum_energy_cells
1124 cout <<
Name() <<
": sum cell energy: " << sum_energy_cells <<
" GeV" << endl;
1125 cout <<
Name() <<
": sum shower energy: " << sum_energy_stored_showers <<
" GeV" << endl;
1126 cout <<
Name() <<
": sum stored hit energy: " << sum_energy_stored_hits <<
" GeV" << endl;
1135 cout <<
Name() <<
": sum cell energy: " << sum_energy_cells <<
" GeV" << endl;
1136 cout <<
Name() <<
": sum shower energy: " << sum_energy_stored_showers <<
" GeV" << endl;
1137 cout <<
Name() <<
": sum stored hit energy: " << sum_energy_stored_hits <<
" GeV" << endl;
virtual int get_layer() const
std::pair< LayerIter, LayerIter > getLayers() const
int verbosity
The verbosity level. 0 means not verbose at all.
Map::const_iterator ConstIterator
std::map< unsigned long long, PHG4Cell * > cellptmap
void Detector(const std::string &d)
void set_zstep(const double z)
void set_double_param(const int id, const std::string &name, const double dval)
PHTimer server for accessing external information.
PHG4ParametersContainer * GetParamsContainerModify()
PHNode * findFirst(const std::string &, const std::string &)
std::pair< ShowerEdepConstIterator, ShowerEdepConstIterator > ShowerEdepConstRange
void set_thickness(const double t)
int ResetEvent(PHCompositeNode *topNode)
Clean up after each event.
unsigned short int get_phibin(const PHG4CellDefs::keytype key)
std::map< int, std::pair< double, double > > cell_size
virtual double get_thickness() const
unsigned short int get_phibin(const PHG4CellDefs::keytype key)
double sum_energy_before_cuts
unsigned long long keytype
PHBoolean addNode(PHNode *)
void SetDefaultParameters()
void set_phibins(const int i)
PHTimeServer::timer _timer
virtual void add_edep(const PHG4HitDefs::keytype g4hitid, const float edep)
ConstIterator AddCell(PHG4Cell *newCell)
unsigned short int get_etabin(const PHG4CellDefs::keytype key)
void OutputDetector(const std::string &d)
std::map< int, std::pair< double, double > > zmin_max
void set_etamin(const double z)
void set_binning(const int i)
std::set< unsigned int >::const_iterator LayerIter
std::string seggeonodename
PHG4CylinderCellReco(const std::string &name="CYLINDERRECO")
static double get_eta(const double radius, const double z)
std::map< int, double > etastep
std::map< unsigned long long, PHG4Cell * >::iterator it
double get_double_param(const int id, const std::string &name) const
void set_layer(const int i)
ConstRange getCells(const unsigned short int detid) const
return all Cells matching a given detid
keytype genkey(const unsigned short layer, const unsigned short etabin, const unsigned short phibin)
void set_size(const int i, const double sizeA, const double sizeB)
void set_etastep(const double z)
static std::pair< double, double > get_etaphi(const double x, const double y, const double z)
void UpdateParametersWithMacro()
virtual const std::string Name() const
Returns the name of this module.
void stop()
stops the counter
const PHG4ParametersContainer * GetParamsContainer()
void set_etabins(const int i)
void set_phistep(const double phi)
keytype genkey(const unsigned short layer, const unsigned short zbin, const unsigned short iphibin)
int InitRun(PHCompositeNode *topNode)
module initialization
virtual void add_light_yield(const float lightYield)
ConstRange getHits(const unsigned int detid) const
return all hits matching a given detid
double get_phistep() const
void identify(std::ostream &os=std::cout) const
virtual int get_etabin(const double eta) const
void restart()
Restart timer.
virtual double get_zmax() const
void SaveToNodeTree(PHCompositeNode *runNode, const std::string &nodename)
std::pair< ConstIterator, ConstIterator > ConstRange
std::pair< ConstIterator, ConstIterator > ConstRange
Map::const_iterator ConstIterator
bool lines_intersect(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy, double *rx, double *ry)
virtual int get_phibin(const double phi) const
virtual double get_phicenter(const int ibin) const
virtual int get_zbin(const double z) const
std::map< int, int > binning
void identify(std::ostream &os=std::cout) const
std::map< int, std::pair< double, double > > tmin_max
PHG4CylinderCellGeom * GetLayerCellGeom(const int i)
void set_phimin(const double phi)
std::map< int, std::pair< int, int > > n_phi_z_bins
virtual void add_shower_edep(const int g4showerid, const float edep)
void set_zbins(const int i)
void set_radius(const double r)
void set_default_double_param(const std::string &name, const double dval)
void set_zmin(const double z)
void etaphisize(const int i, const double deltaeta, const double deltaphi)
std::pair< EdepConstIterator, EdepConstIterator > EdepConstRange
for scintillation detectors, the amount of light produced
void set_timing_window(const int detid, const double tmin, const double tmax)
bool line_and_rectangle_intersect(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy, double *rr)
virtual double get_etacenter(const int ibin) const
double get_etastep() const
unsigned short int get_zbin(const PHG4CellDefs::keytype key)
void cellsize(const int i, const double sr, const double sz)
ShowerEdepMap::const_iterator ShowerEdepConstIterator
std::map< int, double > phistep
int ExistDetid(const int detid) const
virtual double get_radius() const
int process_event(PHCompositeNode *topNode)
event processing
virtual double get_zcenter(const int ibin) const
int AddLayerCellGeom(const int i, PHG4CylinderCellGeom *mygeom)
std::pair< std::map< int, PHG4CylinderGeom * >::const_iterator, std::map< int, PHG4CylinderGeom * >::const_iterator > get_begin_end() const
int chkenergyconservation
void set_name(const std::string &name)
EdepMap::const_iterator EdepConstIterator
int CheckEnergy(PHCompositeNode *topNode)
std::set< int > implemented_detid
virtual double get_zmin() const
virtual double get_edep() const