00001
00002
00003 #include "reconstruction/SiClusters.h"
00004 #include "DetectorData.h"
00005
00006 #include <float.h>
00007
00008 using namespace std;
00009
00010 void SiClusters::Tray::flagHit (unsigned int idx)
00011 {
00012 unsigned nx = xhitList.size();
00013 unsigned ix = idx%nx;
00014 unsigned iy = idx/nx;
00015
00016 xhitList[ix]->flag = 1;
00017 yhitList[iy]->flag = 1;
00018 }
00019
00020 void SiClusters::Tray::flagHit (enum SiData::Axis , unsigned int ) {}
00021
00022 void SiClusters::Tray::unflagHit (unsigned int idx)
00023 {
00024 unsigned nx = xhitList.size();
00025 unsigned ix = idx%nx;
00026 unsigned iy = idx/nx;
00027
00028 xhitList[ix]->flag = 0;
00029 yhitList[iy]->flag = 0;
00030 }
00031
00032 void SiClusters::Tray::unflagHit (enum SiData::Axis , unsigned int ) {}
00033
00034 void SiClusters::Tray::clearHitFlags ()
00035 {
00036 unsigned i;
00037 for( i =0; i<xhitList.size(); i++)
00038 xhitList[i]->flag = 0;
00039 for( i =0; i<yhitList.size(); i++)
00040 yhitList[i]->flag = 0;
00041 }
00042
00043
00044 SiClusters::SiClusters (int ntrays)
00045 {
00046 trayList.resize(ntrays);
00047 }
00048
00049 SiClusters::~SiClusters ()
00050 {
00051 clear();
00052 }
00053
00054 void SiClusters::loadFrom (const SiData& data)
00055 {
00056 for(unsigned i=0; i<trayList.size(); i++) {
00057
00058
00059 int nx = data.nHits(SiData::X, i);
00060 if(nx) {
00061
00062
00063 unsigned lastMod = 9999999;
00064 int start=0, stop;
00065 for(stop=0; stop<nx; stop++) {
00066 if(lastMod != data.moduleId(SiData::X, i, stop)) {
00067 if((stop-start) > 0)
00068 transferData(SiData::X, data, i, start, stop);
00069 lastMod = data.moduleId(SiData::X, i, stop);
00070 start = stop;
00071 }
00072 }
00073 if((stop-start) > 0) {
00074 transferData(SiData::X, data, i, start, stop);
00075 }
00076 }
00077
00078
00079 int ny = data.nHits(SiData::Y, i);
00080 if(ny) {
00081 unsigned lastMod = 9999999;
00082 int start=0, stop;
00083 for(stop=0; stop<ny; stop++) {
00084 if(lastMod != data.moduleId(SiData::Y, i, stop)) {
00085 if((stop-start) > 0)
00086 transferData(SiData::Y, data, i, start, stop);
00087 lastMod = data.moduleId(SiData::Y, i, stop);
00088 start = stop;
00089 }
00090 }
00091 if((stop-start) > 0) {
00092 transferData(SiData::Y, data, i, start, stop);
00093 }
00094 }
00095 }
00096
00097 }
00098
00099 void SiClusters::clear ()
00100 {
00101 for(unsigned i=0; i<trayList.size(); i++) {
00102 vector<Tray *> &moduleTrays = trayList[i];
00103 vector<Tray *>::iterator it = moduleTrays.begin();
00104 for ( ; it != moduleTrays.end(); it++ ) {
00105 delete *it;
00106 }
00107 moduleTrays.clear();
00108 }
00109 }
00110
00111 int SiClusters::nHits (enum SiData::Axis a, int trayNum) const
00112 {
00113 int count = 0;
00114 if ((trayNum < 0) || (trayNum >= trayList.size())) return 0;
00115 const vector<Tray *> &moduleTrays = trayList[trayNum];
00116 vector<Tray *>::const_iterator it = moduleTrays.begin();
00117 for( ; it != moduleTrays.end(); ++it ) {
00118 Tray *tray = *it;
00119 if(a==SiData::X) count += tray->xhitList.size();
00120 else count += tray->yhitList.size();
00121 }
00122 return count;
00123 }
00124
00125 Point SiClusters::nextHit (int trayN, int* index)
00126 {
00127 static int trayNum = 999;
00128 static int modNum = 999;
00129
00130 static int ix = 0, iy = 0, nx = 0, ny = 0, pairs = 0;
00131 static Tray *tray = 0;
00132
00133 *index = -1;
00134 if(trayN != trayNum) {
00135 modNum = 0;
00136 ix = iy = nx = ny = pairs = 0;
00137 if(trayN < 0) {
00138 trayNum = 999;
00139 return Point(0., 0., 0.);
00140 }
00141 else
00142 trayNum = trayN;
00143 }
00144
00145 if(pairs >= nx*ny) {
00146
00147 nx = ny = 0;
00148 vector <Tray *> &moduleTrays = trayList[trayNum];
00149 while(!nx || !ny) {
00150 if(modNum >= (int)moduleTrays.size()) return Point(0., 0., 0.);
00151 tray = moduleTrays[modNum++];
00152 nx = tray->xhitList.size();
00153 ny = tray->yhitList.size();
00154 }
00155 ix = iy = pairs = 0;
00156 }
00157 Point xpt , ypt;
00158 if(!tray->xhitList[ix]->flag)
00159 xpt = tray->xhitList[ix]->pos;
00160 else {
00161 pairs++;
00162 ix++;
00163 if(ix >= nx) {
00164 iy++;
00165 ix = 0;
00166 return nextHit(trayNum, index);
00167 }
00168 }
00169
00170 if(!tray->yhitList[iy]->flag)
00171 ypt = tray->yhitList[iy]->pos;
00172 else {
00173 pairs += nx;
00174 iy++;
00175 ix = 0;
00176 return nextHit(trayNum, index);
00177 }
00178
00179 float x = xpt.x();
00180 float y = ypt.y();
00181 float z = (xpt.z() + ypt.z())/2.;
00182
00183 *index = pairs + 10000*trayNum + 1000000*tray->module;
00184
00185 pairs++;
00186 ix++;
00187 if(ix >= nx) {
00188 iy++;
00189 ix = 0;
00190 }
00191
00192 return Point(x, y, z);
00193 }
00194
00195 Point SiClusters::nextHit (enum SiData::Axis a, int trayN, int* index)
00196 {
00197 static int trayNum = 999;
00198 static int modNum = 999;
00199
00200 static unsigned int ix = 0, nx = 0;
00201 static Tray *tray = 0;
00202 static vector<Cluster *> *hitList= 0;
00203
00204 *index = -1;
00205 if(trayN != trayNum) {
00206 modNum = 0;
00207 ix = nx = 0;
00208 if(trayN < 0) {
00209 trayNum = 999;
00210 return Point(0., 0., 0.);
00211 }
00212 else
00213 trayNum = trayN;
00214 }
00215
00216 if(ix >= nx) {
00217 nx = 0;
00218 vector<Tray *> &moduleTrays = trayList[trayNum];
00219 while(!nx) {
00220 if(modNum >= (int)moduleTrays.size()) return Point(0., 0., 0.);
00221 tray = moduleTrays[modNum++];
00222
00223 if(a==SiData::X) hitList = &tray->xhitList;
00224 else hitList = &tray->yhitList;
00225 nx = hitList->size();
00226 }
00227 ix = 0;
00228 }
00229 if ( ix >= hitList->size() ) {
00230
00231 *index = -1;
00232 return Point(0., 0., 0.);
00233 }
00234 Point xpt;
00235 if(!hitList->operator[](ix)->flag) xpt = hitList->operator[](ix)->pos;
00236 else {
00237 ix++;
00238 return nextHit(a, trayNum, index);
00239 }
00240
00241 *index = ix + 10000*trayNum + 1000000*tray->module;
00242
00243 ix++;
00244
00245 return xpt;
00246 }
00247
00248 Point SiClusters::nearestHitInside (unsigned int trayNum, float dR,
00249 const Point& x0, int* index)
00250 {
00251 float x = 0., y = 0., z = 0., test= fabs(dR);
00252
00253 *index = -1;
00254 if(test < 100000.) test *= test;
00255
00256 for(unsigned j=0; j<trayList[trayNum].size(); j++) {
00257 Tray *tray = trayList[trayNum][j];
00258
00259 for(unsigned ix=0; ix<tray->xhitList.size(); ix++) {
00260 float xtmp2 = x0.x() - tray->xhitList[ix]->pos.x();
00261 xtmp2 *= xtmp2;
00262 if(tray->xhitList[ix]->flag || xtmp2 > test) continue;
00263
00264 for(unsigned iy=0; iy<tray->yhitList.size(); iy++) {
00265 float ytmp2 = x0.y() - tray->yhitList[iy]->pos.y();
00266 ytmp2 *= ytmp2;
00267 if(tray->yhitList[iy]->flag || ytmp2 > test) continue;
00268
00269 if((xtmp2 + ytmp2) < test) {
00270 test = (xtmp2 + ytmp2);
00271 x = tray->xhitList[ix]->pos.x();
00272 y = tray->yhitList[iy]->pos.y();
00273 z = (tray->yhitList[iy]->pos.z()
00274 + tray->xhitList[ix]->pos.z())/2.;
00275 *index = 10000*trayNum + 1000000*tray->module;
00276 *index += ix + iy*tray->xhitList.size();
00277 }
00278 }
00279 }
00280 }
00281 return Point(x, y, z);
00282 }
00283
00284 Point SiClusters::nearestHitInside (unsigned int trayNum, float dX, float dY,
00285 const Point& x0, int* index)
00286 {
00287 float x = 0., y = 0., z = 0., test= FLT_MAX;
00288
00289 *index = -1;
00290
00291 for(unsigned j=0; j<trayList[trayNum].size(); j++) {
00292 Tray *tray = trayList[trayNum][j];
00293
00294 for(unsigned ix=0; ix<tray->xhitList.size(); ix++) {
00295 float xtmp = x0.x() - tray->xhitList[ix]->pos.x();
00296 if(tray->xhitList[ix]->flag || xtmp > dX) continue;
00297
00298 for(unsigned iy=0; iy<tray->yhitList.size(); iy++) {
00299 float ytmp = x0.y() - tray->yhitList[iy]->pos.y();
00300 if(tray->yhitList[iy]->flag || ytmp > dY) continue;
00301
00302 float dsq = xtmp*xtmp + ytmp*ytmp;
00303 if(dsq < test) {
00304 test = dsq;
00305 x = tray->xhitList[ix]->pos.x();
00306 y = tray->yhitList[iy]->pos.y();
00307 z = (tray->yhitList[iy]->pos.z()
00308 + tray->xhitList[ix]->pos.z())/2.;
00309 *index = 10000*trayNum + 1000000*tray->module;
00310 *index += ix + iy*tray->xhitList.size();
00311 }
00312 }
00313 }
00314 }
00315 return Point(x, y, z);
00316 }
00317
00318 Point SiClusters::nearestHitInside (enum SiData::Axis a, unsigned int trayNum,
00319 float dX, const Point& x0, int* index)
00320 {
00321 static vector<Cluster *> *hitList = 0;
00322 float test= FLT_MAX;
00323 Point hit(0.,0.,0.);
00324
00325 *index = -1;
00326
00327 for(unsigned j=0; j<trayList[trayNum].size(); j++) {
00328 Tray *tray = trayList[trayNum][j];
00329
00330 if(a==SiData::X) hitList = &tray->xhitList;
00331 else hitList = &tray->yhitList;
00332
00333 for(unsigned ix=0; ix<hitList->size(); ix++) {
00334 float xtmp;
00335 if(a==SiData::X) xtmp = fabs(x0.x()
00336 - hitList->operator[](ix)->pos.x());
00337 else xtmp = fabs(x0.y()
00338 - hitList->operator[](ix)->pos.y());
00339
00340 if( xtmp > dX) continue;
00341
00342 if(xtmp < test) {
00343 test = xtmp;
00344 hit = hitList->operator[](ix)->pos;
00345 *index = 10000*trayNum + 1000000*tray->module;
00346 *index += ix;
00347 }
00348 }
00349 }
00350 return hit;
00351 }
00352
00353 Point SiClusters::nearestHitOutside (unsigned int trayNum, float dR,
00354 const Point& x0, int* index)
00355 {
00356 float x = 0., y = 0., z = 0., test= FLT_MAX, dR2 = dR*dR;
00357
00358 if(dR < 0) dR2 = -dR2;
00359 *index = -1;
00360
00361 for(unsigned j=0; j<trayList[trayNum].size(); j++) {
00362 Tray *tray = trayList[trayNum][j];
00363
00364 for(unsigned ix=0; ix<tray->xhitList.size(); ix++) {
00365 if(tray->xhitList[ix]->flag) continue;
00366 float xtmp2 = x0.x() - tray->xhitList[ix]->pos.x();
00367 xtmp2 *= xtmp2;
00368
00369 for(unsigned iy=0; iy<tray->yhitList.size(); iy++) {
00370 if(tray->yhitList[iy]->flag) continue;
00371 float ytmp2 = x0.y() - tray->yhitList[iy]->pos.y();
00372 ytmp2 *= ytmp2;
00373
00374 if((xtmp2 + ytmp2) < test && (xtmp2 + ytmp2) > dR2) {
00375 test = (xtmp2 + ytmp2);
00376 x = tray->xhitList[ix]->pos.x();
00377 y = tray->yhitList[iy]->pos.y();
00378 z = (tray->yhitList[iy]->pos.z()
00379 + tray->xhitList[ix]->pos.z())/2.;
00380 *index = 10000*trayNum + 1000000*tray->module;
00381 *index += ix + iy*tray->xhitList.size();
00382 }
00383 }
00384 }
00385 }
00386 return Point(x, y, z);
00387 }
00388
00389 Point SiClusters::nearestHitOutside(enum SiData::Axis a, unsigned int trayNum,
00390 float dX, const Point& x0, int* index)
00391 {
00392 static vector<Cluster *> *hitList = 0;
00393 float test= FLT_MAX;
00394 Point hit(0.,0.,0.);
00395
00396 *index = -1;
00397
00398 for(unsigned j=0; j<trayList[trayNum].size(); j++) {
00399 Tray *tray = trayList[trayNum][j];
00400
00401 if(a==SiData::X) hitList = &tray->xhitList;
00402 else hitList = &tray->yhitList;
00403
00404 for(unsigned ix=0; ix<hitList->size(); ix++) {
00405 if(hitList->operator[](ix)->flag) continue;
00406 float xtmp;
00407 if(a==SiData::X) xtmp = fabs(x0.x()
00408 - hitList->operator[](ix)->pos.x());
00409 else xtmp = fabs(x0.y()
00410 - hitList->operator[](ix)->pos.y());
00411
00412 if(xtmp < test && xtmp > dX) {
00413 test = xtmp;
00414 hit = hitList->operator[](ix)->pos;
00415 *index = 10000*trayNum + 1000000*tray->module;
00416 *index += ix;
00417 }
00418 }
00419 }
00420 return hit;
00421 }
00422
00423 Point SiClusters::meanHit (unsigned int trayNum, float* rmsX, float* rmsY)
00424 {
00425 double x = 0., y = 0., z = 0., x2 = 0., y2 = 0.,
00426 xnum = 0., ynum = 0., znum = 0.;
00427
00428 *rmsX = 0.;
00429 *rmsY = 0.;
00430
00431 for(unsigned j=0; j<trayList[trayNum].size(); j++) {
00432 Tray *tray = trayList[trayNum][j];
00433
00434 for(unsigned ix=0; ix<tray->xhitList.size(); ix++) {
00435 x += tray->xhitList[ix]->pos.x();
00436 z += tray->xhitList[ix]->pos.z();
00437 x2 += tray->xhitList[ix]->pos.x()*tray->xhitList[ix]->pos.x();
00438 xnum += 1.;
00439 znum += 1.;
00440 }
00441
00442 for(unsigned iy=0; iy<tray->yhitList.size(); iy++) {
00443 y += tray->yhitList[iy]->pos.y();
00444 z += tray->yhitList[iy]->pos.z();
00445 y2 += tray->yhitList[iy]->pos.y()*tray->yhitList[iy]->pos.y();
00446 ynum += 1.;
00447 znum += 1.;
00448 }
00449 }
00450 if(xnum > 1) {
00451 x /= xnum;
00452 x2 /= xnum;
00453 double t = x2-x*x;
00454 *rmsX = t>0? sqrt(t):0;
00455 }
00456 if(ynum > 1) {
00457 y /= ynum;
00458 y2 /= ynum;
00459 double t = y2-y*y;
00460 *rmsY = t>0? sqrt(t):0;
00461 }
00462 if(xnum+ynum > 0.) z /= (xnum+ynum);
00463
00464 return Point(x, y, z);
00465 }
00466
00467 Point SiClusters::meanHit (SiData::Axis axis, unsigned int trayNum, float* rms)
00468
00469 {
00470 double x = 0., y = 0., z = 0., x2 = 0., y2 = 0.,
00471 xnum = 0., ynum = 0., znum = 0.;
00472
00473 *rms = 0.;
00474
00475 for(unsigned j=0; j<trayList[trayNum].size(); j++) {
00476 Tray *tray = trayList[trayNum][j];
00477
00478 if (axis == SiData::X) {
00479 for(unsigned ix=0; ix<tray->xhitList.size(); ix++) {
00480 x += tray->xhitList[ix]->pos.x();
00481 z += tray->xhitList[ix]->pos.z();
00482 x2 += tray->xhitList[ix]->pos.x()*tray->xhitList[ix]->pos.x();
00483 xnum += 1.;
00484 znum += 1.;
00485 }
00486 }
00487
00488 if (axis == SiData::Y) {
00489 for(unsigned iy=0; iy<tray->yhitList.size(); iy++) {
00490 y += tray->yhitList[iy]->pos.y();
00491 z += tray->yhitList[iy]->pos.z();
00492 y2 += tray->yhitList[iy]->pos.y()*tray->yhitList[iy]->pos.y();
00493 ynum += 1.;
00494 znum += 1.;
00495 }
00496 }
00497 }
00498 if(axis == SiData::X && xnum > 0) {
00499 x /= xnum;
00500 x2 /= xnum;
00501 double t = x2 - x*x;
00502 *rms = t>0? sqrt(t):0;
00503 }
00504 if (axis == SiData::Y && ynum > 0) {
00505 y /= ynum;
00506 y2 /= ynum;
00507 double t = y2 - y*y;
00508 *rms = t>0? sqrt(t):0;
00509 }
00510 if(xnum+ynum > 0.) z /= (xnum+ynum);
00511
00512 return Point(x, y, z);
00513 }
00514 Point SiClusters::meanHitInside (unsigned int trayNum, float dXY,
00515 const Point& x0)
00516 {
00517 float x = 0., y = 0., z = 0., num = 0.;
00518
00519 float dXYsq = dXY*dXY;
00520
00521 for(unsigned j=0; j<trayList[trayNum].size(); j++) {
00522 Tray *tray = trayList[trayNum][j];
00523
00524 for(unsigned ix=0; ix<tray->xhitList.size(); ix++) {
00525 float xtmp2 = x0.x() - tray->xhitList[ix]->pos.x();
00526 xtmp2 *= xtmp2;
00527 if(tray->xhitList[ix]->flag || xtmp2 > dXYsq) continue;
00528
00529 for(unsigned iy=0; iy<tray->yhitList.size(); iy++) {
00530 float ytmp2 = x0.y() - tray->yhitList[iy]->pos.y();
00531 ytmp2 *= ytmp2;
00532 if(tray->yhitList[iy]->flag || ytmp2 > dXYsq) continue;
00533
00534 if((xtmp2 + ytmp2) < dXYsq) {
00535 x += tray->xhitList[ix]->pos.x();
00536 y += tray->yhitList[iy]->pos.y();
00537 z += (tray->yhitList[iy]->pos.z()
00538 + tray->xhitList[ix]->pos.z())/2.;
00539 num += 1.;
00540 }
00541 }
00542 }
00543 }
00544 if(num > 0) return Point(x/num, y/num, z/num);
00545 else return Point(0., 0., 0.);
00546 }
00547
00548 int SiClusters::numberOfHitsNear (unsigned int trayNum, float dXY,
00549 const Point& x0)
00550 {
00551 return numberOfHitsNear(trayNum, dXY, dXY, x0);
00552 }
00553
00554 int SiClusters::numberOfHitsNear (unsigned int trayNum, float dX, float dY,
00555 const Point& x0)
00556 {
00557 int xnum = 0, ynum = 0;
00558 float d2_width = DetectorData::Tower::mod_width/2.;
00559
00560 for(unsigned j=0; j<trayList[trayNum].size(); j++) {
00561 Tray *tray = trayList[trayNum][j];
00562
00563 for(unsigned ix=0; ix<tray->xhitList.size(); ix++) {
00564 if(fabs(x0.x() - tray->xhitList[ix]->pos.x()) < dX &&
00565 fabs(x0.y() - tray->xhitList[ix]->pos.y()) < d2_width) xnum++;
00566 }
00567
00568 for(unsigned iy=0; iy<tray->yhitList.size(); iy++) {
00569 if(fabs(x0.y() - tray->yhitList[iy]->pos.y()) < dY &&
00570 fabs(x0.x() - tray->yhitList[iy]->pos.x()) < d2_width) ynum++;
00571 }
00572 }
00573 return xnum+ynum;
00574 }
00575 int SiClusters::numberOfHitsNear (enum SiData::Axis axis, unsigned int trayNum, float dR, const Point& x0)
00576 {
00577 int xnum = 0, ynum = 0;
00578 float d2_width = DetectorData::Tower::mod_width/2.;
00579
00580 for(unsigned j=0; j<trayList[trayNum].size(); j++) {
00581 Tray *tray = trayList[trayNum][j];
00582
00583 if (axis == SiData::X) {
00584 for(unsigned ix=0; ix<tray->xhitList.size(); ix++) {
00585 if(fabs(x0.x() - tray->xhitList[ix]->pos.x()) < dR &&
00586 fabs(x0.y() - tray->xhitList[ix]->pos.y()) < d2_width) xnum++;
00587 }
00588 } else {
00589 for(unsigned iy=0; iy<tray->yhitList.size(); iy++) {
00590 if(fabs(x0.y() - tray->yhitList[iy]->pos.y()) < dR &&
00591 fabs(x0.x() - tray->yhitList[iy]->pos.x()) < d2_width) ynum++;
00592 }
00593 }
00594 }
00595 return xnum+ynum;
00596 }
00597
00598 int SiClusters::clusterSize (enum SiData::Axis a, unsigned int index)
00599 {
00600 vector <Cluster *> *hitList = 0;
00601 unsigned ix = index%10000;
00602 unsigned lyr = (index/10000)%100;
00603 unsigned mod = (index/1000000);
00604
00605 Tray *tray = 0;
00606 vector<Tray *> &moduleTrays = trayList[lyr];
00607 for(unsigned j=0; j<moduleTrays.size(); j++) {
00608 if(moduleTrays[j]->module == mod) {
00609 tray = moduleTrays[j];
00610 if(a==SiData::X) hitList = &tray->xhitList;
00611 else hitList = &tray->yhitList;
00612
00613 break;
00614 }
00615 }
00616 unsigned int nx = hitList->size();
00617 int size = 0;
00618 if(ix<nx) size = hitList->operator[](ix)->number;
00619 return size;
00620 }
00621
00622 int SiClusters::tower(int indexhit)
00623 {
00624 int itower = indexhit/1000000;
00625
00626
00627 return itower;
00628 }
00629
00630 Point SiClusters::clusterPosition (enum SiData::Axis a, unsigned int index)
00631 {
00632 vector <Cluster *> *hitList = 0;
00633 unsigned ix = index%10000;
00634 unsigned lyr = (index/10000)%100;
00635 unsigned mod = (index/1000000);
00636
00637 Tray *tray = 0;
00638 vector<Tray *> &moduleTrays = trayList[lyr];
00639 for(unsigned j=0; j<moduleTrays.size(); j++) {
00640 if(moduleTrays[j]->module == mod) {
00641 tray = moduleTrays[j];
00642 if(a==SiData::X) hitList = &tray->xhitList;
00643 else hitList = &tray->yhitList;
00644
00645 break;
00646 }
00647 }
00648 unsigned int nx = hitList->size();
00649
00650 Point Pos(0.,0.,0.);
00651 if(ix<nx) Pos = hitList->operator[](ix)->pos;
00652 return Pos;
00653 }
00654
00655 int SiClusters::clusterNoise (enum SiData::Axis a, unsigned int index)
00656 {
00657 vector <Cluster *> *hitList = 0;
00658 unsigned ix = index%10000;
00659 unsigned lyr = (index/10000)%100;
00660 unsigned mod = (index/1000000);
00661
00662 Tray *tray = 0;
00663 if ( !(lyr < trayList.size() ) ) {
00664
00665 return 0;
00666 }
00667 vector<Tray *> &moduleTrays = trayList[lyr];
00668 for(unsigned j=0; j<moduleTrays.size(); j++) {
00669 if(moduleTrays[j]->module == mod) {
00670 tray = moduleTrays[j];
00671 if(a==SiData::X) hitList = &tray->xhitList;
00672 else hitList = &tray->yhitList;
00673
00674 break;
00675 }
00676 }
00677 if ( !hitList ) {
00678
00679 return 0;
00680 }
00681 unsigned int nx = hitList->size();
00682 int noise = 0;
00683 if(ix<nx) noise = hitList->operator[](ix)->num_noise;
00684 return noise;
00685 }
00686
00687 bool SiClusters::hitFlagged (enum SiData::Axis a, unsigned int index)
00688 {
00689 vector <Cluster *> *hitList = 0;
00690 unsigned ix = index%10000;
00691 unsigned lyr = (index/10000)%100;
00692 unsigned mod = (index/1000000);
00693
00694 Tray *tray = 0;
00695 vector<Tray *> &moduleTrays = trayList[lyr];
00696 for(unsigned j=0; j<moduleTrays.size(); j++) {
00697 if(moduleTrays[j]->module == mod) {
00698 tray = moduleTrays[j];
00699 if(a==SiData::X) hitList = &tray->xhitList;
00700 else hitList = &tray->yhitList;
00701
00702 break;
00703 }
00704 }
00705 unsigned int nx = hitList->size();
00706 if(ix<nx) {
00707 if(hitList->operator[](ix)->flag) return true;
00708 else return false;
00709 }
00710 return false;
00711 }
00712
00713 void SiClusters::flagHit (unsigned int index)
00714 {
00715 unsigned idx = index%10000;
00716 unsigned lyr = (index/10000)%100;
00717 unsigned mod = (index/1000000);
00718
00719 Tray *tray = 0;
00720 vector<Tray *> &moduleTrays = trayList[lyr];
00721 for(unsigned j=0; j<moduleTrays.size(); j++) {
00722 if(moduleTrays[j]->module == mod) {
00723 tray = moduleTrays[j];
00724 break;
00725 }
00726 }
00727 if(tray) tray->flagHit(idx);
00728 }
00729
00730 void SiClusters::flagHit (enum SiData::Axis a, unsigned int index)
00731 {
00732 vector<Cluster *> *hitList = 0;
00733 unsigned ix = index%10000;
00734 unsigned lyr = (index/10000)%100;
00735 unsigned mod = (index/1000000);
00736
00737 Tray *tray = 0;
00738 vector<Tray *> &moduleTrays = trayList[lyr];
00739 for(unsigned j=0; j<moduleTrays.size(); j++) {
00740 if(moduleTrays[j]->module == mod) {
00741 tray = moduleTrays[j];
00742 if(a==SiData::X) hitList = &tray->xhitList;
00743 else hitList = &tray->yhitList;
00744
00745 break;
00746 }
00747 }
00748 unsigned int nx = hitList->size();
00749 if(ix<nx) hitList->operator[](ix)->flag = 1;
00750 }
00751
00752 void SiClusters::unflagHit (unsigned int index)
00753 {
00754 unsigned idx = index%10000;
00755 unsigned lyr = (index/10000)%100;
00756 unsigned mod = (index/1000000);
00757
00758 Tray *tray = 0;
00759 vector<Tray *> &moduleTrays = trayList[lyr];
00760 for(unsigned j=0; j<moduleTrays.size(); j++) {
00761 if(moduleTrays[j]->module == mod) {
00762 tray = moduleTrays[j];
00763 break;
00764 }
00765 }
00766
00767 if(tray) tray->unflagHit(idx);
00768 }
00769
00770 void SiClusters::unflagHit (enum SiData::Axis a, unsigned int index)
00771 {
00772 vector<Cluster *> *hitList = 0;
00773 unsigned ix = index%10000;
00774 unsigned lyr = (index/10000)%100;
00775 unsigned mod = (index/1000000);
00776
00777 Tray *tray = 0;
00778 vector<Tray *> &moduleTrays = trayList[lyr];
00779 for(unsigned j=0; j<moduleTrays.size(); j++) {
00780 if(moduleTrays[j]->module == mod) {
00781 tray = moduleTrays[j];
00782 if(a==SiData::X) hitList = &tray->xhitList;
00783 else hitList = &tray->yhitList;
00784
00785 break;
00786 }
00787 }
00788 unsigned int nx = hitList->size();
00789 if(ix<nx) hitList->operator[](ix)->flag = 0;
00790 }
00791
00792 void SiClusters::clearHitFlags ()
00793 {
00794 for(unsigned trayNum=0; trayNum < trayList.size(); trayNum++) {
00795 int nx= nHits(SiData::X,trayNum), ny= nHits(SiData::Y,trayNum);
00796 if( nx==0 && ny==0 ) continue;
00797
00798 vector<Tray *> &moduleTrays = trayList[trayNum];
00799 unsigned j;
00800 for(j=0; j<moduleTrays.size(); j++)
00801 moduleTrays[j]->clearHitFlags();
00802 }
00803 }
00804
00805 void SiClusters::printOn (std::ostream& cout)
00806 {
00807 int trayNum, i, j;
00808 cout << "\nSiClusters:\n";
00809 for(trayNum=0; trayNum < (int)trayList.size(); trayNum++)
00810 {
00811 int nx= nHits(SiData::X,trayNum), ny= nHits(SiData::Y,trayNum);
00812 if( nx==0 && ny==0 ) continue;
00813
00814 cout << trayNum << "X hits =" << nx <<" Y hits = " <<ny;
00815 vector<Tray *> &moduleTrays = trayList[trayNum];
00816 for(j=0; j< (int)moduleTrays.size(); j++) {
00817 Tray *tray = moduleTrays[j];
00818 unsigned modId = tray->module;
00819 nx = (int)tray->xhitList.size();
00820 cout << " Module " << modId << " X hits = " <<nx;
00821 for( i =0; i<nx; i++)
00822 cout << '\t'<< tray->xhitList[i]->pos << '\n';
00823 ny = (int)tray->yhitList.size();
00824 cout << " Module " << modId << " Y hits = " <<ny;
00825 for( i =0; i<ny; i++)
00826 cout << '\t'<< tray->yhitList[i]->pos << '\n';
00827 }
00828 }
00829 return;
00830 }
00831
00832 SiClusters::Tray* SiClusters::getTrayFor (int lyr, int mod)
00833 {
00834
00835 vector<Tray *> &moduleTrays = trayList[lyr];
00836 for ( unsigned j=0; j<moduleTrays.size(); j++) {
00837 if ( (int)moduleTrays[j]->module == mod) {
00838 return moduleTrays[j];
00839 }
00840 }
00841
00842 Tray *tray = new Tray(mod);
00843 trayList[lyr].push_back(tray);
00844 return tray;
00845 }
00846
00847 void SiClusters::transferData (enum SiData::Axis a, const SiData& data,
00848 int lyr, int start, int stop)
00849 {
00850
00851 float sum = 0., x, y, z;
00852 int number, noise =0;
00853 Point xSum(0., 0., 0.);
00854 unsigned lstIndex = 999999999;
00855
00856 Tray *tray = getTrayFor(lyr, data.moduleId(a, lyr, start));
00857
00858 for(int i=start; i<stop; i++){
00859 if(data.hitId(a, lyr, i) != lstIndex-1 &&
00860 data.hitId(a, lyr, i) != lstIndex+1 && lstIndex < 999999999) {
00861
00862 number = (int)sum;
00863 x = xSum.x()/sum;
00864 y = xSum.y()/sum;
00865 z = xSum.z()/sum;
00866 if(a == SiData::X)
00867
00868 tray->xhitList.push_back( new Cluster(Point(x,y,z), number, noise) );
00869 else
00870 tray->yhitList.push_back( new Cluster(Point(x,y,z), number, noise) );
00871 sum = 0.; noise = 0;
00872 xSum = Point(0., 0., 0.);
00873 }
00874 xSum += data.hit(a, lyr, i);
00875 sum += 1.;
00876
00877 lstIndex = data.hitId(a, lyr, i);
00878 }
00879 if(lstIndex< 999999999) {
00880 number = (int)sum;
00881 x = xSum.x()/sum;
00882 y = xSum.y()/sum;
00883 z = xSum.z()/sum;
00884 if(a == SiData::X)
00885 tray->xhitList.push_back( new Cluster(Point(x,y,z), number, noise) );
00886 else
00887
00888 tray->yhitList.push_back( new Cluster(Point(x,y,z), number, noise) );
00889 }
00890 }