00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 #include "StTrackTopologyMap.h"
00142 #include <vector>
00143 #include <algorithm>
00144 #include <numeric>
00145 #if !defined(ST_NO_NAMESPACES)
00146 using std::vector;
00147 using std::adjacent_difference;
00148 using std::max_element;
00149 #endif
00150
00151 static const char rcsid[] = "$Id: StTrackTopologyMap.cxx,v 2.17 2007/11/07 00:54:54 ullrich Exp $";
00152
00153 ClassImp(StTrackTopologyMap)
00154
00155 StTrackTopologyMap::StTrackTopologyMap()
00156 {
00157 mMap0 = mMap1 = 0;
00158 }
00159
00160 StTrackTopologyMap::StTrackTopologyMap(unsigned int m1, unsigned int m2) : mMap0(m1), mMap1(m2) { }
00161
00162 StTrackTopologyMap::StTrackTopologyMap(const unsigned int* m) : mMap0(m[0]), mMap1(m[1]) { }
00163
00164 StTrackTopologyMap::StTrackTopologyMap(const unsigned long* m) : mMap0(m[0]), mMap1(m[1]) { }
00165
00166 StTrackTopologyMap::~StTrackTopologyMap() { }
00167
00168 bool
00169 StTrackTopologyMap::bit(int i) const
00170 {
00171 return i>31 ? (mMap1>>(i-32) & 1U) : (mMap0>>i & 1U);
00172 }
00173
00174 bool
00175 StTrackTopologyMap::ftpcFormat() const
00176 {
00177 return bit(63);
00178 }
00179
00180 unsigned int
00181 StTrackTopologyMap::data(unsigned int i) const
00182 {
00183 return static_cast<unsigned int>(i<2 ? (i<1 ? mMap0 : mMap1) : 0);
00184 }
00185
00186 bool
00187 StTrackTopologyMap::primaryVertexUsed() const { return bit(0); }
00188
00189 bool
00190 StTrackTopologyMap::turnAroundFlag() const { return bit(62); }
00191
00192 bool
00193 StTrackTopologyMap::hasHitInDetector(StDetectorId id) const
00194 {
00195 return ((numberOfHits(id)) ? 1U : 0U);
00196 }
00197
00198
00199 bool
00200 StTrackTopologyMap::hasHitInDetector(StDetectorId d1, StDetectorId d2,
00201 StDetectorId d3, StDetectorId d4,
00202 StDetectorId d5, StDetectorId d6) const
00203 {
00204
00205
00206
00207
00208 return (hasHitInDetector(d1) && hasHitInDetector(d2) &&
00209 (d3 == kUnknownId ? true : hasHitInDetector(d3)) &&
00210 (d4 == kUnknownId ? true : hasHitInDetector(d4)) &&
00211 (d5 == kUnknownId ? true : hasHitInDetector(d5)) &&
00212 (d6 == kUnknownId ? true : hasHitInDetector(d6)));
00213 }
00214
00215 bool
00216 StTrackTopologyMap::hasHitInSvtLayer(unsigned int layer) const
00217 {
00218 if (ftpcFormat())
00219 return false;
00220 else
00221 return bit(layer);
00222 }
00223
00224 bool
00225 StTrackTopologyMap::hasHitInPxlLayer(unsigned int layer) const
00226 {
00227 if(ftpcFormat())
00228 return false;
00229 else
00230 return bit(layer);
00231 }
00232
00233 bool
00234 StTrackTopologyMap::hasHitInIstLayer(unsigned int layer) const
00235 {
00236 if(ftpcFormat())
00237 return false;
00238 else
00239 return bit(layer+2);
00240 }
00241
00242 bool
00243 StTrackTopologyMap::hasHitInRow(StDetectorId id, unsigned int row) const
00244 {
00245 switch (id) {
00246 case kTpcId:
00247 return !ftpcFormat() && bit(row+7);
00248 break;
00249 case kFtpcWestId:
00250 return ftpcFormat() && bit(row);
00251 break;
00252 case kFtpcEastId:
00253 return ftpcFormat() && bit(row+10);
00254 break;
00255 default:
00256 return false;
00257 break;
00258 }
00259 }
00260
00261 unsigned int
00262 StTrackTopologyMap::numberOfHits(StDetectorId id) const
00263 {
00264 if (ftpcFormat() &&
00265 !(id == kFtpcWestId || id == kFtpcEastId))
00266 return 0;
00267
00268 int i;
00269 int n = 0;
00270
00271 switch (id) {
00272 case kSvtId:
00273 for (i=1; i<7; i++)
00274 if (hasHitInSvtLayer(i)) n++;
00275 break;
00276 case kSsdId:
00277 if (bit(7)) n++;
00278 break;
00279 case kPxlId:
00280 for(i=1;i<3;i++)
00281 if(hasHitInPxlLayer(i)) n++;
00282 break;
00283 case kIstId:
00284 for(i=1;i<4;i++)
00285 if(hasHitInIstLayer(i)) n++;
00286 break;
00287 case kFtpcWestId:
00288 case kFtpcEastId:
00289 for (i=1; i<11; i++)
00290 if (hasHitInRow(id, i)) n++;
00291 break;
00292 case kTpcId:
00293 for (i=1; i<46; i++)
00294 if (hasHitInRow(id, i)) n++;
00295 break;
00296 case kMwpcWestId:
00297 case kMwpcEastId:
00298 if (bit(53)) n++;
00299 break;
00300 case kCtbId:
00301 if (bit(54)) n++;
00302 break;
00303 case kTofId:
00304 if (bit(55)) n++;
00305 break;
00306 case kRichId:
00307 if (bit(56)) n++;
00308 break;
00309 case kBarrelEmcTowerId:
00310 case kBarrelEmcPreShowerId:
00311 case kBarrelSmdEtaStripId:
00312 case kBarrelSmdPhiStripId:
00313 if (bit(57)) n++;
00314 break;
00315 case kEndcapEmcTowerId:
00316 case kEndcapEmcPreShowerId:
00317 case kEndcapSmdUStripId:
00318 case kEndcapSmdVStripId:
00319 if (bit(58)) n++;
00320 break;
00321 default:
00322 n = 0;
00323 break;
00324 }
00325 return n;
00326 }
00327
00328 bool
00329 StTrackTopologyMap::trackTpcOnly() const
00330 {
00331 return ((hasHitInDetector(kTpcId)) &
00332 ~((hasHitInDetector(kSvtId)) | (hasHitInDetector(kSsdId))));
00333 }
00334
00335 bool
00336 StTrackTopologyMap::trackSvtOnly() const
00337 {
00338 return ((hasHitInDetector(kSvtId)) & ~(hasHitInDetector(kTpcId)));
00339 }
00340
00341 bool
00342 StTrackTopologyMap::trackTpcSvt() const
00343 {
00344 return ((hasHitInDetector(kTpcId)) & (hasHitInDetector(kSvtId)));
00345 }
00346
00347 bool
00348 StTrackTopologyMap::trackFtpcEast() const
00349 {
00350 return (hasHitInDetector(kFtpcEastId));
00351 }
00352
00353 bool
00354 StTrackTopologyMap::trackFtpcWest() const
00355 {
00356 return (hasHitInDetector(kFtpcWestId));
00357 }
00358
00359 bool
00360 StTrackTopologyMap::trackFtpc() const
00361 {
00362 return ((hasHitInDetector(kFtpcWestId)) | (hasHitInDetector(kFtpcEastId)));
00363 }
00364
00365 int
00366 StTrackTopologyMap::largestGap(StDetectorId id) const
00367 {
00368 if (ftpcFormat() && !(id == kFtpcWestId || id == kFtpcEastId))
00369 return -1;
00370
00371 vector<int> rows;
00372 int i;
00373
00374 switch (id) {
00375 case kSvtId:
00376 for (i=1; i<7; i++)
00377 if (hasHitInSvtLayer(i)) rows.push_back(i);
00378 break;
00379 case kIstId:
00380 for (i=1; i<4; i++)
00381 if (hasHitInIstLayer(i)) rows.push_back(i);
00382 break;
00383 case kFtpcWestId:
00384 case kFtpcEastId:
00385 for (i=1; i<11; i++)
00386 if (hasHitInRow(id, i)) rows.push_back(i);
00387 break;
00388 case kTpcId:
00389 for (i=1; i<46; i++)
00390 if (hasHitInRow(id, i)) rows.push_back(i);
00391 break;
00392 default:
00393 return -1;
00394 }
00395
00396 if (rows.size() < 2) return -1;
00397
00398 vector<int> diffs(rows.size());
00399 adjacent_difference(rows.begin(), rows.end(), diffs.begin());
00400 return *max_element(diffs.begin()+1, diffs.end()) - 1;
00401 }
00402
00403 ostream& operator<< (ostream& os, const StTrackTopologyMap& m)
00404 {
00405 for (int i=0; i<64; i++) {
00406 if (i>31)
00407 os << ((m.data(1)>>(i-32) & 1U) ? 1 : 0);
00408 else
00409 os << ((m.data(0)>>i & 1U) ? 1 : 0);
00410 }
00411 return os;
00412 }
00413