00001 #include "TkrRecon/SiClusters.h"
00002
00003
00004
00005
00006
00007
00008
00009 SiCluster::SiCluster(int id, int v, int ilayer,
00010 int istrip0, int istripf, double ToT, int tower)
00011
00012 {
00013 ini();
00014
00015 m_id = id;
00016 m_view = intToView(v);
00017
00018 m_plane = ilayer;
00019
00020 m_strip0 = istrip0;
00021 m_stripf = istripf;
00022 m_chip = (int) m_strip0/64;
00023
00024 m_strip = 0.5*(m_strip0+m_stripf);
00025 m_size = fabs(m_stripf-m_strip0+1);
00026
00027 m_ToT = ToT;
00028 m_tower = tower;
00029
00030 }
00031
00032
00033 void SiCluster::writeOut(MsgStream& log) const
00034
00035 {
00036
00037 log << MSG::DEBUG << " plane " << m_plane << " XY " << m_view;
00038 log << MSG::DEBUG << " xpos " << m_position.x() << " ypos " << m_position.y();
00039 log << MSG::DEBUG << " zpos " << m_position.z();
00040 log << MSG::DEBUG << " i0-if " << m_strip0 <<"-"<< m_stripf;
00041 log << MSG::DEBUG <<endreq;
00042 }
00043
00044 void SiCluster::draw(gui::DisplayRep& v, double stripPitch, double towerPitch)
00045
00046 {
00047 int nstrips = (int) m_size;
00048 double distance = stripPitch;
00049
00050 double delta = 1.2;
00051 double Offset = -0.5*towerPitch;
00052
00053 for (int istrip = m_strip0; istrip <= m_stripf; istrip++) {
00054 double x = m_position.x();
00055 double y = m_position.y();
00056 double z = m_position.z();
00057 double corr = (istrip-m_strip)*distance;
00058 if (m_view == SiCluster::X) {
00059 x = x+corr;
00060 y = Offset;
00061 } else {
00062 y = y+corr;
00063 x = Offset;
00064 }
00065 v.moveTo(Point(x,y,z));
00066 v.lineTo(Point(x,y,z+delta));
00067
00068
00069
00070 }
00071 }
00072
00073
00074 void SiCluster::ini()
00075
00076 {
00077 m_chip = -1;
00078 m_flag = 0;
00079 m_id = -1;
00080 m_plane = -1;
00081 m_position = Point(0.,0.,0.);
00082 m_size = 0;
00083 m_strip = 0;
00084 m_strip0 = 0;
00085 m_stripf = 0;
00086 m_ToT = 0.;
00087 m_tower = 0;
00088 m_view = SiCluster::XY;
00089 }
00090
00091 SiCluster::view SiCluster::intToView(int iv)
00092
00093 {
00094 SiCluster::view v = XY;
00095 if (iv == 0) v = X;
00096 else if (iv == 1) v =Y;
00097 return v;
00098 }
00099
00100
00101 int SiCluster::viewToInt(SiCluster::view v)
00102
00103 {
00104 if (v == SiCluster::XY) return 2;
00105 return (v == SiCluster::X? 0:1);
00106 }
00107
00108
00109
00110
00111
00112 SiClusters::SiClusters(int nViews, int nPlanes, double stripPitch, double towerPitch)
00113 {
00114 m_stripPitch = stripPitch;
00115 m_towerPitch = towerPitch;
00116 numViews = nViews;
00117 numPlanes = nPlanes;
00118
00119 ini();
00120 }
00121
00122 SiClusters::~SiClusters()
00123 {
00124 clear();
00125
00126 return;
00127 }
00128
00129
00130 void SiClusters::addCluster(SiCluster* cl)
00131
00132 {
00133 m_clustersList.push_back(cl);
00134 int iview = SiCluster::viewToInt(cl->v());
00135 m_clustersByPlaneList[iview][cl->plane()].push_back(cl);
00136 }
00137
00138 void SiClusters::clear()
00139
00140 {
00141 int nhits = m_clustersList.size();
00142 for (int ihit = 0; ihit < nhits; ihit++) {
00143 delete m_clustersList[ihit];
00144 }
00145 ini();
00146 }
00147
00148 void SiClusters::ini()
00149
00150 {
00151 m_clustersList.clear();
00152 for (int iview = 0; iview < numViews; iview++) {
00153 for (int iplane = 0; iplane < numPlanes; iplane++) {
00154 m_clustersByPlaneList[iview][iplane].clear();
00155 }
00156 }
00157 }
00158
00159
00160
00161 Point SiClusters::meanHit(SiCluster::view v, int iplane)
00162
00163 {
00164 Point Pini(0.,0.,0);
00165
00166 int nhits = nHits(v,iplane);
00167 if (nhits == 0) return Pini;
00168
00169 std::vector<SiCluster*> AuxList = getHits(v,iplane);
00170 for (int ihit=0; ihit<nhits; ihit++){
00171 Pini += AuxList[ihit]->position();
00172 }
00173 Point Pini2(Pini.x()/nhits,Pini.y()/nhits,Pini.z()/nhits);
00174 return Pini2;
00175 }
00176
00177
00178 Point SiClusters::meanHitInside(SiCluster::view v, int iplane, double inRadius,
00179 Point Pcenter)
00180
00181 {
00182 Point P(0.,0.,0);
00183 std::vector<SiCluster*> AuxList = getHits(v,iplane);
00184 int nhits = AuxList.size();
00185 if (nhits == 0) return P;
00186
00187 double nsum = 0.;
00188 double xsum = 0.;
00189 double ysum = 0.;
00190 double zsum = 0.;
00191
00192 for (int ihit=0; ihit<nhits; ihit++)
00193 {
00194 P = AuxList[ihit]->position();
00195
00196 double hitRadius = fabs(P.x() - Pcenter.x());
00197 double twrRadius = fabs(P.y() - Pcenter.y());
00198
00199 if (v == SiCluster::Y)
00200 {
00201 hitRadius = fabs(P.y() - Pcenter.y());
00202 twrRadius = fabs(P.x() - Pcenter.x());
00203 }
00204 else if (v != SiCluster::X)
00205 {
00206 hitRadius = (P-Pcenter).mag();
00207 twrRadius = 0.;
00208 }
00209
00210
00211 if (hitRadius < inRadius && twrRadius < 1.1 * m_towerPitch)
00212 {
00213 nsum += 1.;
00214 xsum += P.x();
00215 ysum += P.y();
00216 zsum += P.z();
00217 }
00218 }
00219
00220 if (nsum > 0.) P = Point(xsum/nsum, ysum/nsum, zsum/nsum);
00221
00222 return P;
00223 }
00224
00225
00226 Point SiClusters::nearestHitOutside(SiCluster::view v, int iplane,
00227 double inRadius, Point Pcenter, int& id)
00228
00229 {
00230 Point Pnear(0.,0.,0.);
00231 id = -1;
00232
00233 int nhits = nHits(v,iplane);
00234 if (nhits == 0) return Pnear;
00235
00236 std::vector<SiCluster*> AuxList;
00237 AuxList = getHits(v,iplane);
00238
00239 double minRadius = inRadius;
00240 double maxRadius = 1e6;
00241 Point Pini(0.,0.,0.);
00242 for (int ihit = 0; ihit< nhits; ihit++)
00243 {
00244 if (AuxList[ihit]->hitFlagged()) continue;
00245
00246 Pini = AuxList[ihit]->position();
00247
00248
00249 double hitRadius = fabs(Pini.x() - Pcenter.x());
00250 double twrRadius = fabs(Pini.y() - Pcenter.y());
00251
00252 if (v == SiCluster::Y)
00253 {
00254 hitRadius = fabs(Pini.y() - Pcenter.y());
00255 twrRadius = fabs(Pini.x() - Pcenter.x());
00256 }
00257 else if (v != SiCluster::X)
00258 {
00259 hitRadius = (Pini-Pcenter).mag();
00260 twrRadius = 0.;
00261 }
00262
00263 if ( hitRadius >= minRadius && hitRadius < maxRadius && twrRadius < 1.1*m_towerPitch)
00264 {
00265 maxRadius = hitRadius;
00266 Pnear = Pini;
00267 id = AuxList[ihit]->id();
00268 }
00269 }
00270 return Pnear;
00271 }
00272
00273
00274
00275
00276
00277 int SiClusters::numberOfHitsNear( int iPlane, double inRadius, Point& x0)
00278
00279 {
00280 return numberOfHitsNear(iPlane, inRadius, inRadius, x0);
00281 }
00282
00283
00284 int SiClusters::numberOfHitsNear( int iPlane, double dX, double dY, Point& x0)
00285
00286 {
00287 int numHits = 0;
00288
00289
00290 std::vector<SiCluster*> clusterList = getHits(SiCluster::X, iPlane);
00291 int nHitsInPlane = clusterList.size();
00292
00293 while(nHitsInPlane--)
00294 {
00295 double hitDiffX = x0.x() - clusterList[nHitsInPlane]->position().x();
00296 double hitDiffY = x0.y() - clusterList[nHitsInPlane]->position().y();
00297
00298 if (fabs(hitDiffX < dX) && fabs(hitDiffY) < m_towerPitch) numHits++;
00299 }
00300
00301
00302 clusterList = getHits(SiCluster::Y, iPlane);
00303 nHitsInPlane = clusterList.size();
00304
00305 while(nHitsInPlane--)
00306 {
00307 double hitDiffX = x0.x() - clusterList[nHitsInPlane]->position().x();
00308 double hitDiffY = x0.y() - clusterList[nHitsInPlane]->position().y();
00309
00310 if (fabs(hitDiffX) < m_towerPitch && fabs(hitDiffY) < dY) numHits++;
00311 }
00312
00313 return numHits;
00314 }
00315
00316
00317 int SiClusters::numberOfHitsNear( SiCluster::view v, int iPlane, double inRadius, Point& x0)
00318
00319 {
00320 int numHits = 0;
00321
00322
00323 std::vector<SiCluster*> clusterList = getHits(v, iPlane);
00324 int nHitsInPlane = clusterList.size();
00325
00326 while(nHitsInPlane--)
00327 {
00328 double hitDiffV = v == SiCluster::X
00329 ? x0.x() - clusterList[nHitsInPlane]->position().x()
00330 : x0.y() - clusterList[nHitsInPlane]->position().y();
00331 double hitDiffO = v == SiCluster::X
00332 ? x0.y() - clusterList[nHitsInPlane]->position().y()
00333 : x0.x() - clusterList[nHitsInPlane]->position().x();
00334
00335 if (fabs(hitDiffV) < inRadius && fabs(hitDiffO) < m_towerPitch) numHits++;
00336 }
00337
00338 return numHits;
00339 }
00340
00341
00342
00343 void SiClusters::flagHitsInPlane(SiCluster::view v, int iplane)
00344
00345 {
00346 std::vector<SiCluster*> AuxList = getHits(v,iplane);
00347 for (int ihit = 0; ihit< AuxList.size(); ihit++)
00348 AuxList[ihit]->flag();
00349 }
00350
00351 void SiClusters::writeOut(MsgStream& log) const
00352
00353 {
00354 if (nHits()<=0) return;
00355
00356 for (int ihit = 0; ihit < nHits(); ihit++) {
00357 m_clustersList[ihit]->writeOut(log);
00358 }
00359 }
00360
00361 void SiClusters::draw(gui::DisplayRep& v)
00362
00363 {
00364 v.setColor("black");
00365
00366 for (int ihit = 0; ihit < nHits(); ihit++) {
00367 m_clustersList[ihit]->draw(v, m_stripPitch, m_towerPitch);
00368 }
00369 }