38 chkenergyconservation(0)
59 cout <<
Name() <<
" DST Node missing, doing nothing." << std::endl;
76 cout <<
Name() <<
"DST Node missing, doing nothing." << endl;
94 cout <<
Name() <<
" Could not locate g4 hit node " <<
hitnodename << endl;
111 cout <<
Name() <<
" Could not locate geometry node " <<
geonodename << endl;
134 map<int, PHG4BlockGeom *>::const_iterator miter;
135 pair <map<int, PHG4BlockGeom *>::const_iterator, map<int, PHG4BlockGeom *>::const_iterator> begin_end = geo->
get_begin_end();
136 map<int, std::pair <double, double> >::iterator sizeiter;
137 for (miter = begin_end.first; miter != begin_end.second; ++miter)
143 cout <<
Name() <<
": No parameters for detid/layer " << layer
144 <<
", hits from this detid/layer will not be accumulated into cells" << endl;
151 double zmin = layergeom->
get_center_z() - length_in_z/2.;
152 double zmax = zmin + length_in_z;
158 cout <<
Name() <<
"no cell sizes for layer " << layer << endl;
174 zmin_max[layer] = make_pair(etamin, etamax);
175 double etastepsize = (sizeiter->second).first;
177 double fract = modf((etamax - etamin) / etastepsize, &d_etabins);
182 etastepsize = (etamax - etamin) / d_etabins;
183 (sizeiter->second).first = etastepsize;
184 int etabins = d_etabins;
185 double etahi = etamin + etastepsize;
186 for (
int i = 0; i < etabins; i++)
188 if (etahi > (etamax + 1.e-6))
190 cout <<
"etahi: " << etahi <<
", etamax: " << etamax << endl;
192 etahi += etastepsize;
195 double xmin = -layergeom->
get_width()/2.;
197 double xstepsize = (sizeiter->second).second;
199 fract = modf(width / xstepsize, &d_xbins);
205 xstepsize = width / d_xbins;
206 (sizeiter->second).second = xstepsize;
221 pair<int, int> x_z_bin = make_pair(xbins, etabins);
230 xstep[layer] = xstepsize;
255 cout <<
"Could not locate g4 hit node " <<
hitnodename << endl;
261 cout <<
"could not locate cell node " <<
cellnodename << endl;
273 pair<PHG4HitContainer::LayerIter, PHG4HitContainer::LayerIter> layer_begin_end = g4hit->
getLayers();
281 for (layer = layer_begin_end.first; layer != layer_begin_end.second; layer++)
293 unsigned int nbins = nxbins*nzbins;
303 for (hiter = hit_begin_end.first; hiter != hit_begin_end.second; hiter++)
306 if (hiter->second->get_t(0)>
tmin_max[*layer].second)
continue;
307 if (hiter->second->get_t(1)<
tmin_max[*layer].first)
continue;
309 pair<double, double> etax[2];
312 for (
int i = 0; i < 2; i++)
314 etax[i] =
get_etaphi(hiter->second->get_x(i), hiter->second->get_y(i), hiter->second->get_z(i));
316 xbin[i] = geo->
get_xbin( etax[i].second );
320 if (xbin[0] < 0 || xbin[0] >= nxbins || xbin[1] < 0 || xbin[1] >= nxbins)
324 if (etabin[0] < 0 || etabin[0] >= nzbins || etabin[1] < 0 || etabin[1] >= nzbins)
333 hiter->second->identify();
339 int intxbin = xbin[0];
340 int intetabin = etabin[0];
341 int intxbinout = xbin[1];
342 int intetabinout = etabin[1];
346 double ax = (etax[0]).second;
347 double ay = (etax[0]).first;
348 double bx = (etax[1]).second;
349 double by = (etax[1]).first;
350 if (intxbin > intxbinout)
353 intxbin = intxbinout;
357 if (intetabin > intetabinout)
360 intetabin = intetabinout;
364 double trklen = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
377 vector<double> vdedx;
379 if (intxbin == intxbinout && intetabin == intetabinout)
381 if (
verbosity > 0) cout <<
"SINGLE CELL FIRED: " << intxbin <<
" " << intetabin << endl;
382 vx.push_back(intxbin);
383 veta.push_back(intetabin);
384 vdedx.push_back(trklen);
388 for (
int ibp = intxbin; ibp <= intxbinout; ibp++)
390 for (
int ibz = intetabin; ibz <= intetabinout; ibz++)
402 if (
verbosity > 0) cout <<
"CELL FIRED: " << ibp <<
" " << ibz <<
" " << rr << endl;
410 if (
verbosity > 0) cout <<
"NUMBER OF FIRED CELLS = " << vx.size() << endl;
413 for (
unsigned int ii = 0; ii < vx.size(); ii++)
416 vdedx[ii] = vdedx[ii] / trklen;
417 if (
verbosity > 0) cout <<
" CELL " << ii <<
" dE/dX = " << vdedx[ii] << endl;
419 if (
verbosity > 0) cout <<
" TOTAL TRACK LENGTH = " << tmpsum <<
" " << trklen << endl;
422 for (
unsigned int i1 = 0; i1 < vx.size(); i1++)
426 int ietabin = veta[i1];
427 int ibin = ixbin*nzbins+ietabin;
433 cellptarray[ibin]->add_edep(hiter->first, hiter->second->get_edep()*vdedx[i1]);
434 cellptarray[ibin]->add_edep(hiter->second->get_edep()*vdedx[i1]);
437 cellptarray[ibin]->add_light_yield(hiter->second->get_light_yield()*vdedx[i1]);
439 cellptarray[ibin]->add_shower_edep(hiter->second->get_shower_id(), hiter->second->get_edep()*vdedx[i1]);
442 if (! isfinite(hiter->second->get_edep()*vdedx[i1]))
444 cout <<
PHWHERE <<
" invalid energy dep " << hiter->second->get_edep()
445 <<
" or path length: " << vdedx[i1] << endl;
454 for (
int ix = 0; ix < nxbins; ix++)
456 for (
int iz = 0; iz < nzbins; iz++)
458 int ibin = ix*nzbins + iz;
466 cout <<
"Adding cell in bin x: " << ix
468 <<
", eta bin: " << iz
470 <<
", energy dep: " <<
cellptarray[ibin]->get_edep()
481 cout <<
Name() <<
": found " << numcells <<
" eta/x cells with energy deposition" << endl;
517 cout <<
"size for layer " << i <<
" already set" << endl;
522 cell_size[i] = std::make_pair(sizeA, sizeB);
530 double radius = sqrt(x * x + y * y);
531 double phi = atan2(y, x);
532 double theta = atan2(radius, z);
533 double eta = -log(tan(theta / 2.));
534 return make_pair(eta, phi);
542 theta = atan2(radius, fabs(z));
543 eta = -log(tan(theta / 2.));
579 double bottom = fx * px + fy * py;
582 double top = gx * px + gy * py;
591 if (h > 0. && h < 1.)
596 if ((*rx > ax && *rx > bx) || (*rx < ax && *rx < bx) || (*ry < ay && *ry < by) || (*ry > ay && *ry > by))
633 if (cx > dx || cy > dy)
635 cerr <<
"ERROR: Bad rectangle definition!" << endl;
680 *rr = sqrt( (vx[0] - vx[1]) * (vx[0] - vx[1]) + (vy[0] - vy[1]) * (vy[0] - vy[1]) );
687 if (ax > cx && ay > cy && ax < dx && ay < dy)
690 *rr = sqrt((vx[0] - ax) * (vx[0] - ax) + (vy[0] - ay) * (vy[0] - ay));
692 if (bx > cx && by > cy && bx < dx && by < dy)
695 *rr = sqrt((vx[0] - bx) * (vx[0] - bx) + (vy[0] - by) * (vy[0] - by));
699 if (i1 || i2 || i3 || i4)
712 double sum_energy_cells = 0.;
713 double sum_energy_stored_hits = 0.;
714 double sum_energy_stored_showers = 0.;
718 for (citer = cell_begin_end.first; citer != cell_begin_end.second; ++citer)
720 sum_energy_cells += citer->second->get_edep();
724 sum_energy_stored_hits += iter->second;
729 sum_energy_stored_showers += iter->second;
734 if (sum_energy_stored_hits > 0)
736 if (fabs(sum_energy_cells-sum_energy_stored_hits)/sum_energy_cells > 1e-6)
738 cout <<
"energy mismatch between cell energy " << sum_energy_cells
739 <<
" and stored hit energies " << sum_energy_stored_hits
743 if (sum_energy_stored_showers > 0)
745 if (fabs(sum_energy_cells-sum_energy_stored_showers)/sum_energy_cells > 1e-6)
747 cout <<
"energy mismatch between cell energy " << sum_energy_cells
748 <<
" and stored shower energies " << sum_energy_stored_showers
755 cout <<
"energy mismatch between cells: " << sum_energy_cells
767 cout <<
Name() <<
": sum cell energy: " << sum_energy_cells <<
" GeV" << endl;
768 cout <<
Name() <<
": sum shower energy: " << sum_energy_stored_showers <<
" GeV" << endl;
769 cout <<
Name() <<
": sum stored hit energy: " << sum_energy_stored_hits <<
" GeV" << endl;
void SetDefaultParameters()
std::pair< LayerIter, LayerIter > getLayers() const
static double get_eta(const double radius, const double z)
static vector< PHG4Cell * > cellptarray
int verbosity
The verbosity level. 0 means not verbose at all.
Map::const_iterator ConstIterator
std::pair< std::map< int, PHG4BlockGeom * >::const_iterator, std::map< int, PHG4BlockGeom * >::const_iterator > get_begin_end() const
void set_double_param(const int id, const std::string &name, const double dval)
double get_etastep() const
PHTimer server for accessing external information.
PHG4ParametersContainer * GetParamsContainerModify()
PHNode * findFirst(const std::string &, const std::string &)
double get_etacenter(const int ibin) const
std::pair< ShowerEdepConstIterator, ShowerEdepConstIterator > ShowerEdepConstRange
virtual double get_size_x() const
std::map< int, std::pair< int, int > > n_x_z_bins
int CheckEnergy(PHCompositeNode *topNode)
void set_etabins(const int i)
double get_xcenter(const int ibin) const
unsigned long long keytype
PHBoolean addNode(PHNode *)
virtual double get_center_z() const
virtual double get_size_y() const
virtual double get_center_y() const
std::set< int > implemented_detid
int chkenergyconservation
ConstIterator AddCell(PHG4Cell *newCell)
bool lines_intersect(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy, double *rx, double *ry)
void identify(std::ostream &os=std::cout) const
void set_layer(const int i)
std::set< unsigned int >::const_iterator LayerIter
void identify(std::ostream &os=std::cout) const
std::map< int, std::pair< double, double > > cell_size
void set_xstep(const double x)
void set_size(const int i, const double sizeA, const double sizeB, const int what)
double get_double_param(const int id, const std::string &name) const
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 xbin)
std::map< int, int > binning
void UpdateParametersWithMacro()
virtual const std::string Name() const
Returns the name of this module.
PHG4BlockCellReco(const std::string &name="BLOCKRECO")
std::string seggeonodename
void stop()
stops the counter
const PHG4ParametersContainer * GetParamsContainer()
void set_xmin(const double x)
int get_xbin(const double x) const
void etaxsize(const int i, const double deltaeta, const double deltax)
ConstRange getHits(const unsigned int detid) const
return all hits matching a given detid
int process_event(PHCompositeNode *topNode)
event processing
void restart()
Restart timer.
void set_etamin(const double z)
PHTimeServer::timer _timer
void SaveToNodeTree(PHCompositeNode *runNode, const std::string &nodename)
std::pair< ConstIterator, ConstIterator > ConstRange
std::pair< ConstIterator, ConstIterator > ConstRange
Map::const_iterator ConstIterator
virtual int get_layer() const
int get_etabin(const double eta) const
std::map< int, double > xstep
virtual double get_width() const
void set_timing_window(const int detid, const double tmin, const double tmax)
void set_default_double_param(const std::string &name, const double dval)
void set_xbins(const int i)
void set_etastep(const double z)
virtual double get_size_z() const
std::pair< EdepConstIterator, EdepConstIterator > EdepConstRange
int InitRun(PHCompositeNode *topNode)
module initialization
for scintillation detectors, the amount of light produced
ShowerEdepMap::const_iterator ShowerEdepConstIterator
static std::pair< double, double > get_etaphi(const double x, const double y, const double z)
int ExistDetid(const int detid) const
std::map< int, std::pair< double, double > > tmin_max
int ResetEvent(PHCompositeNode *topNode)
Clean up after each event.
std::map< int, std::pair< double, double > > zmin_max
void set_name(const std::string &name)
bool line_and_rectangle_intersect(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy, double *rr)
EdepMap::const_iterator EdepConstIterator
PHG4BlockCellGeom * GetLayerCellGeom(const int i)
int AddLayerCellGeom(const int i, PHG4BlockCellGeom *mygeom)
std::map< int, double > etastep
virtual double get_center_x() const
void set_binning(const int i)