00001
00002
00003 #include "StEtaPhiGrid.h"
00004
00005 #include "StConePars.h"
00006 #include "StJetEtCellFactory.h"
00007
00008 #include <iostream>
00009
00010 using namespace std;
00011
00012 namespace StSpinJet {
00013
00014 StEtaPhiGrid::~StEtaPhiGrid()
00015 {
00016 for (CellList::iterator cell = _EtCellList.begin(); cell != _EtCellList.end(); ++cell)
00017 delete *cell;
00018 }
00019
00020 void StEtaPhiGrid::buildGrid(StJetEtCellFactory* cellFactory)
00021 {
00022 for(int i = 0; i < _pars.Neta(); ++i){
00023
00024 double etaMin = _pars.EtaMin() + static_cast<double>(i)*_pars.etaWidth();
00025 double etaMax = etaMin + _pars.etaWidth();
00026
00027 for(int j = 0; j < _pars.Nphi(); ++j){
00028
00029 double phiMin = _pars.PhiMin() + static_cast<double>(j)*_pars.phiWidth();
00030 double phiMax = phiMin + _pars.phiWidth();
00031
00032 StEtaPhiCell* cell = cellFactory->create(etaMin, etaMax, phiMin, phiMax);
00033
00034 _EtCellList.push_back(cell);
00035
00036 _EtCellMap.insert(CellMapValType(findKey(cell->eta(), cell->phi()), cell));
00037 }
00038 }
00039
00040 }
00041
00042 void StEtaPhiGrid::fillGridWith(JetList& protoJetList)
00043 {
00044 for(CellList::iterator etCell = _EtCellList.begin(); etCell != _EtCellList.end(); ++etCell) {
00045 (*etCell)->clear();
00046 }
00047
00048 for (JetList::iterator protoJet = protoJetList.begin(); protoJet != protoJetList.end(); ++protoJet) {
00049 CellMap::iterator where = _EtCellMap.find(findKey((*protoJet).eta(), (*protoJet).phi()));
00050 if (where != _EtCellMap.end())
00051 (*where).second->addProtoJet(*protoJet);
00052
00053
00054 }
00055
00056 for(CellList::iterator etCell = _EtCellList.begin(); etCell != _EtCellList.end(); ++etCell) {
00057 (*etCell)->update();
00058 }
00059 }
00060
00061 StEtaPhiGrid::CellList StEtaPhiGrid::EtSortedCellList()
00062 {
00063 _EtCellList.sort(StJetEtCellEtGreaterThan());
00064 return _EtCellList;
00065 }
00066
00067 StEtaPhiGrid::CellList StEtaPhiGrid::WithinTheConeRadiusCellList(const StEtaPhiCell& theCell) const
00068 {
00069 CellList ret;
00070
00071 StEtGridKey centerKey = findKey(theCell.eta(), theCell.phi());
00072
00073 int iEtaMin = centerKey.eta() - _pars.deltaEta();
00074 if (iEtaMin < 0) iEtaMin = 0 ;
00075
00076 for(int iEta = iEtaMin; (iEta <= centerKey.eta() + _pars.deltaEta()) && (iEta < _pars.Neta()); ++iEta) {
00077 for (int iPhi = centerKey.phi() - _pars.deltaPhi(); iPhi <= centerKey.phi() + _pars.deltaPhi(); ++iPhi) {
00078
00079 int iModPhi = iPhi;
00080 if (iModPhi < 0) iModPhi = iModPhi + _pars.Nphi();
00081 if (iModPhi >= _pars.Nphi()) iModPhi = iModPhi - _pars.Nphi();
00082
00083 StEtaPhiCell* otherCell = CellI(iEta, iModPhi);
00084
00085 if(theCell.distance(*otherCell) >= _pars.coneRadius()) continue;
00086
00087 ret.push_back(otherCell);
00088
00089 }
00090 }
00091
00092 return ret;
00093 }
00094
00095 StEtaPhiCell* StEtaPhiGrid::Cell(double eta, double phi)
00096 {
00097 CellMap::iterator it = _EtCellMap.find(findKey(eta, phi));
00098 return (it != _EtCellMap.end()) ? (*it).second : 0;
00099 }
00100
00101 StEtaPhiCell* StEtaPhiGrid::CellI(int iEta, int iPhi) const
00102 {
00103 CellMap::const_iterator it = _EtCellMap.find(StEtGridKey(iEta, iPhi));
00104 return (it != _EtCellMap.end()) ? (*it).second : 0;
00105 }
00106
00107 StEtGridKey StEtaPhiGrid::findKey(double eta, double phi) const
00108 {
00109 int iEta = findEtaKey(eta);
00110 int iPhi = findPhiKey(phi);
00111 if (iEta < 0 || iPhi < 0) {
00112
00113
00114
00115 }
00116 return StEtGridKey(iEta, iPhi);
00117 }
00118
00119
00120 int StEtaPhiGrid::findEtaKey(double eta) const
00121 {
00122 return int((_pars.Neta()/(_pars.EtaMax() - _pars.EtaMin()))*(eta - _pars.EtaMin()));
00123 }
00124
00125 int StEtaPhiGrid::findPhiKey(double phi) const
00126 {
00127 while(phi > M_PI) phi -= 2*M_PI;
00128 while(phi < -M_PI) phi += 2*M_PI;
00129 return int( _pars.Nphi()*((phi - _pars.PhiMin())/(_pars.PhiMax() - _pars.PhiMin())));
00130 }
00131
00132 double StEtaPhiGrid::midpoint(double v1, double v2)
00133 {
00134 double high, low;
00135 if (v1 > v2) {
00136 high =v1;
00137 low=v2;
00138 }
00139 else {
00140 high = v2;
00141 low=v1;
00142 }
00143 return (high - low)/2. + low;
00144 }
00145
00146 StEtaPhiCell* StEtaPhiGrid::findMidpointCell(const StEtaPhiCell& cell1, const StEtaPhiCell& cell2)
00147 {
00148
00149 return Cell(midpoint(cell1.eta(), cell2.eta()), midpoint(cell1.phi(), cell2.phi()));
00150 }
00151
00152
00153 }