00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "RecoBase/Cluster.h"
00012 #include "JobControl/Exception.h"
00013 #include "Geometry/PlaneGeo.h"
00014
00015 #include <algorithm>
00016
00017 using namespace std;
00018 using namespace recobase;
00019
00020 ClassImp(Cluster);
00021
00022
00023
00024
00025 Cluster::Cluster() :
00026 fXPlane(0), fYPlane(0), fPlane(0), fStatus(0),
00027 fQ(0), fdQ(0)
00028 {
00029 Clear();
00030 }
00031
00032
00033 void Cluster::Clear()
00034 {
00035 fXPlane.clear();
00036 fYPlane.clear();
00037 fPlane.clear();
00038 fStatus=0;
00039 fQ=0;
00040 fdQ=0;
00041
00042
00043 for (int i=0; i<4; ++i) {
00044 f4Vec[i] = -1.e9;
00045 fd4Vec[i] = 0.;
00046 }
00047
00048 for (unsigned int i=0; i<fXCell.size(); ++i)
00049 delete fXCell[i];
00050
00051 for (unsigned int i=0; i<fYCell.size(); ++i)
00052 delete fYCell[i];
00053
00054 fXCell.clear();
00055 fYCell.clear();
00056
00057 }
00058
00059
00060
00061
00062
00063 Cluster::Cluster(vector<const CellHit*>& cell) :
00064 fXPlane(0),
00065 fYPlane(0),
00066 fPlane(0),
00067 fStatus(0),
00068 fQ(0),
00069 fdQ(0)
00070 {
00071 for (int i=0; i<4; ++i) {
00072 f4Vec[i] = -1.e9;
00073 fd4Vec[i] = 0.;
00074 }
00075
00076 for (unsigned int i=0; i<cell.size(); ++i) {
00077 if (cell[i]->View() == geo::kX) {
00078 fXCell.push_back(cell[i]);
00079 if (find(fXPlane.begin(),fXPlane.end(),cell[i]->Plane()) ==
00080 fXPlane.end()) fXPlane.push_back(cell[i]->Plane());
00081 }
00082 else {
00083 fYCell.push_back(cell[i]);
00084 if (find(fYPlane.begin(),fYPlane.end(),cell[i]->Plane()) ==
00085 fYPlane.end()) fYPlane.push_back(cell[i]->Plane());
00086 }
00087
00088 if (find(fPlane.begin(),fPlane.end(),cell[i]->Plane()) ==
00089 fPlane.end()) fPlane.push_back(cell[i]->Plane());
00090 }
00091
00092
00093 sort(fXPlane.begin(),fXPlane.end());
00094 sort(fYPlane.begin(),fYPlane.end());
00095 sort(fPlane.begin(),fPlane.end());
00096
00097 }
00098
00099
00100
00101
00102 Cluster::~Cluster()
00103 {
00104
00105 }
00106
00107
00108
00109 int Cluster::XPlane(int i) const
00110 {
00111 unsigned int j = i;
00112 assert_jobc((i >= 0 && j < fXPlane.size()),
00113 "Cluster::XPlane(): out of bounds exception!");
00114 return fXPlane[j];
00115 }
00116
00117
00118
00119 int Cluster::YPlane(int i) const
00120 {
00121 unsigned int j = i;
00122 assert_jobc((i >= 0 && j < fYPlane.size()),
00123 "Cluster::YPlane(): out of bounds exception!");
00124 return fYPlane[j];
00125 }
00126
00127
00128
00129 int Cluster::Plane(int i) const
00130 {
00131 unsigned int j = i;
00132
00133 if(!(i >= 0 && j < (fPlane.size()))) {
00134
00135 cout << "error.. out of bound request " << i << " has "
00136 << fYPlane.size() << ", " << fXPlane.size() << endl;
00137
00138 }
00139
00140 assert_jobc((i >= 0 && j < (fPlane.size())),
00141 "Cluster::Plane(): out of bounds exception!");
00142
00143 if (fYPlane.empty()) return this->XPlane(i);
00144 if (fXPlane.empty()) return this->YPlane(i);
00145
00146 return fPlane[j];
00147 }
00148
00149
00150
00151 int Cluster::NXCell() const
00152 {
00153 return fXCell.size();
00154 }
00155
00156
00157
00158 int Cluster::NYCell() const
00159 {
00160 return fYCell.size();
00161 }
00162
00163
00164
00165 int Cluster::NCell() const
00166 {
00167 return this->NXCell() + this->NYCell();
00168 }
00169
00170
00171
00172 int Cluster::NCell(geo::View_t view) const
00173 {
00174 if(view==geo::kX){
00175 return this->NXCell();
00176 }
00177 else if(view==geo::kY){
00178 return this->NYCell();
00179 }
00180 return this->NCell();
00181 }
00182
00183
00184
00185 const CellHit* Cluster::XCell(int i) const
00186 {
00187 assert_jobc((i >= 0) && (i < this->NXCell()),
00188 "Cluster::XCell(): out of bounds exception!");
00189
00190 unsigned int j = i;
00191 return fXCell[j];
00192 }
00193
00194
00195
00196 const CellHit* Cluster::XCell(int icell, int iplane) const
00197 {
00198 for (int i=0; i<this->NXCell(); ++i) {
00199 const CellHit* c2 = this->XCell(i);
00200 if (c2->Plane() == iplane &&
00201 c2->Cell() == icell)
00202 return c2;
00203 }
00204
00205 return 0;
00206 }
00207
00208
00209
00210 const CellHit* Cluster::YCell(int i) const
00211 {
00212 assert_jobc((i >= 0) && (i < this->NYCell()),
00213 "Cluster::YCell(): out of bounds exception!");
00214
00215 unsigned int j = i;
00216 return fYCell[j];
00217 }
00218
00219
00220
00221 const CellHit* Cluster::YCell(int icell, int iplane) const
00222 {
00223 for (int i=0; i<this->NYCell(); ++i) {
00224 const CellHit* c2 = this->YCell(i);
00225 if (c2->Plane() == iplane &&
00226 c2->Cell() == icell)
00227 return c2;
00228 }
00229
00230 return 0;
00231 }
00232
00233
00234
00235 const CellHit* Cluster::Cell(geo::View_t view, int i) const
00236 {
00237 if(view==geo::kX){
00238 return this->XCell(i);
00239 }
00240 else if(view==geo::kY){
00241 return this->YCell(i);
00242 }
00243
00244 return 0;
00245 }
00246
00247
00248
00249
00250
00251 const CellHit* Cluster::Cell(geo::View_t view, int icell, int iplane) const
00252 {
00253
00254 if(view==geo::kX){
00255 return this->XCell(icell,iplane);
00256 }
00257 else if(view==geo::kY){
00258 return this->YCell(icell,iplane);
00259 }
00260
00261 return 0;
00262
00263 }
00264
00265
00266 bool Cluster::Add(const CellHit* cell)
00267 {
00268 bool foundDup = false;
00269
00270 if (cell->View() == geo::kX) {
00271 for (int i=0; i<this->NXCell(); ++i) {
00272 const CellHit* c2 = this->XCell(i);
00273 if (c2->Plane() == cell->Plane() && c2->Cell() == cell->Cell()) {
00274 foundDup = true;
00275 break;
00276 }
00277 }
00278 if (!foundDup){
00279 fXCell.push_back(cell);
00280 fXPlane.push_back(cell->Plane());
00281 fPlane.push_back(cell->Plane());
00282 sort(fXPlane.begin(),fXPlane.end());
00283 }
00284 }
00285 else {
00286 for (int i=0; i<this->NYCell(); ++i) {
00287 const CellHit* c2 = this->YCell(i);
00288 if (c2->Plane() == cell->Plane() && c2->Cell() == cell->Cell()) {
00289 foundDup = true;
00290 break;
00291 }
00292 }
00293 if (!foundDup){
00294 fYCell.push_back(cell);
00295 fYPlane.push_back(cell->Plane());
00296 fPlane.push_back(cell->Plane());
00297 sort(fYPlane.begin(),fYPlane.end());
00298 }
00299
00300 }
00301
00302 if (!foundDup){
00303 sort(fPlane.begin(),fPlane.end());
00304 }
00305
00306 return !foundDup;
00307 }
00308