clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name Link.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/data/b2soft/buildbot/development/build -fcoverage-compilation-dir=/data/b2soft/buildbot/development/build -resource-dir /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++ -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/x86_64-redhat-linux -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/c++/backward -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/python3.12 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/CLHEP -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/Geant4 -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/root -isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/include/belle_legacy -I include/ -D _PACKAGE_="trg" -D G4UI_USE_TCSH -D RaveDllExport= -D HAS_SQLITE -D HAS_CALLGRIND -I include -I /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/include/libxml2 -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++ -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/x86_64-redhat-linux -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../include/c++/backward -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /cvmfs/belle.cern.ch/el9/externals/v02-04-00/Linux_x86_64/common/bin/../lib64/gcc/x86_64-redhat-linux/15.2.0/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-missing-braces -Wno-unused-command-line-argument -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /scan_build/2026-05-31-004316-385593-1 -x c++ trg/cdc/src/Link.cc
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #define TRG_SHORT_NAMES |
| 14 | #define TRGCDC_SHORT_NAMES |
| 15 | |
| 16 | #include <string> |
| 17 | #include <cstring> |
| 18 | #include <algorithm> |
| 19 | #include "trg/trg/Utilities.h" |
| 20 | #include "trg/cdc/Wire.h" |
| 21 | #include "trg/cdc/WireHit.h" |
| 22 | #include "trg/cdc/WireHitMC.h" |
| 23 | #include "trg/cdc/TRGCDCTrack.h" |
| 24 | #include "trg/cdc/TrackMC.h" |
| 25 | #include "trg/cdc/Segment.h" |
| 26 | #include "trg/cdc/Link.h" |
| 27 | |
| 28 | using namespace std; |
| 29 | |
| 30 | namespace Belle2 { |
| 31 | |
| 32 | bool TRGCDCLink::ms_smallcell(false); |
| 33 | bool TRGCDCLink::ms_superb(false); |
| 34 | unsigned TRGCDCLink::m_nL = 56; |
| 35 | unsigned TRGCDCLink::m_nSL = 9; |
| 36 | unsigned TRGCDCLink::m_nSLA = 5; |
| 37 | unsigned* TRGCDCLink::m_nHitsSL = 0; |
| 38 | vector<TCLink*> TRGCDCLink::m_all; |
| 39 | |
| 40 | TRGCDCLink::TRGCDCLink(TRGCDCTrack* t, |
| 41 | const TRGCDCCellHit* h, |
| 42 | const HepGeom::Point3D<double>& p) |
| 43 | : m_track(t), |
| 44 | m_hit(h), |
| 45 | m_position(p), |
| 46 | m_dPhi(0), |
| 47 | m_leftRight(0), |
| 48 | m_pull(0), |
| 49 | m_link(0), |
| 50 | m_fit2D(0) |
| 51 | { |
| 52 | if (h) { |
| 53 | m_drift[0] = h->drift(0); |
| 54 | m_drift[1] = h->drift(1); |
| 55 | m_dDrift[0] = h->dDrift(0); |
| 56 | m_dDrift[1] = h->dDrift(1); |
| 57 | } else { |
| 58 | m_drift[0] = 0.; |
| 59 | m_drift[1] = 0.; |
| 60 | m_dDrift[0] = 0.; |
| 61 | m_dDrift[1] = 0.; |
| 62 | } |
| 63 | |
| 64 | for (unsigned i = 0; i < 7; ++i) |
| 65 | m_neighbor[i] = NULL; |
| 66 | |
| 67 | if (h) { |
| 68 | m_onTrack = m_onWire = h->xyPosition(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | TRGCDCLink::TRGCDCLink(const TRGCDCLink& l) |
| 73 | : m_track(l.m_track), |
| 74 | m_hit(l.m_hit), |
| 75 | m_onTrack(l.m_onTrack), |
| 76 | m_onWire(l.m_onWire), |
| 77 | m_position(l.m_position), |
| 78 | m_dPhi(l.m_dPhi), |
| 79 | m_leftRight(l.m_leftRight), |
| 80 | m_zStatus(l.m_zStatus), |
| 81 | m_zPair(l.m_zPair), |
| 82 | m_pull(l.m_pull), |
| 83 | m_link(l.m_link), |
| 84 | m_fit2D(l.m_fit2D) |
| 85 | { |
| 86 | m_drift[0] = l.m_drift[0]; |
| 87 | m_drift[1] = l.m_drift[1]; |
| 88 | m_dDrift[0] = l.m_dDrift[0]; |
| 89 | m_dDrift[1] = l.m_dDrift[1]; |
| 90 | for (unsigned i = 0; i < 7; ++i) |
| 91 | m_neighbor[i] = l.m_neighbor[i]; |
| 92 | for (unsigned i = 0; i < 4; ++i) |
| 93 | m_arcZ[i] = l.m_arcZ[i]; |
| 94 | } |
| 95 | |
| 96 | TRGCDCLink::~TRGCDCLink() |
| 97 | { |
| 98 | } |
| 99 | |
| 100 | unsigned |
| 101 | TRGCDCLink::nLayers(const vector<TRGCDCLink*>& list) |
| 102 | { |
| 103 | unsigned l0 = 0; |
| 104 | unsigned l1 = 0; |
| 105 | unsigned n = list.size(); |
| 106 | for (unsigned i = 0; i < n; i++) { |
| 107 | unsigned id = list[i]->cell()->layerId(); |
| 108 | if (id < 32) l0 |= (1u << id); |
| 109 | else l1 |= (1 << (id - 32)); |
| 110 | } |
| 111 | |
| 112 | unsigned l = 0; |
| 113 | for (unsigned i = 0; i < 32; i++) { |
| 114 | if (l0 & (1u << i)) ++l; |
| 115 | if (l1 & (1u << i)) ++l; |
| 116 | } |
| 117 | return l; |
| 118 | } |
| 119 | |
| 120 | void |
| 121 | TRGCDCLink::nHits(const vector<TRGCDCLink*>& links, unsigned* nHits) |
| 122 | { |
| 123 | for (unsigned i = 0; i < m_nL; i++) |
| 124 | nHits[i] = 0; |
| 125 | unsigned nLinks = links.size(); |
| 126 | for (unsigned i = 0; i < nLinks; i++) |
| 127 | ++nHits[links[i]->cell()->layerId()]; |
| 128 | } |
| 129 | |
| 130 | void |
| 131 | TRGCDCLink::nHitsSuperLayer(const vector<TRGCDCLink*>& links, unsigned* nHits) |
| 132 | { |
| 133 | const unsigned nLinks = links.size(); |
| 134 | for (unsigned i = 0; i < nLinks; i++) |
| 7 | | Assuming 'i' is >= 'nLinks' | |
|
| 8 | | Loop condition is false. Execution continues on line 770 | |
|
| 135 | ++nHits[links[i]->cell()->superLayerId()]; |
| 136 | } |
| 137 | |
| 138 | void |
| 139 | TRGCDCLink::dump_base(const string& msg, const string& pre) const |
| 140 | { |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | bool pull = (msg.find("pull") != string::npos); |
| 146 | bool flag = (msg.find("flag") != string::npos); |
| 147 | bool stereo = (msg.find("stereo") != string::npos); |
| 148 | bool pos = (msg.find("position") != string::npos); |
| 149 | |
| 150 | |
| 151 | bool breif = (msg.find("breif") != string::npos); |
| 152 | bool detail = (msg.find("detail") != string::npos); |
| 153 | if (detail) |
| 154 | |
| 155 | pull = flag = stereo = pos = true; |
| 156 | if (breif) |
| 157 | pull = flag = true; |
| 158 | |
| 159 | |
| 160 | cout << pre; |
| 161 | if (m_hit) { |
| 162 | cout << cell()->name(); |
| 163 | } else { |
| 164 | cout << "No hit linked"; |
| 165 | } |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | if (pull) |
| 180 | cout << "[pul=" << this->pull() << "]"; |
| 181 | if (flag) { |
| 182 | if (m_hit) { |
| 183 | if (m_hit->state() & CellHitFindingValid) |
| 184 | cout << "o"; |
| 185 | if (m_hit->state() & CellHitFittingValid) |
| 186 | cout << "+"; |
| 187 | if (m_hit->state() & CellHitInvalidForFit) |
| 188 | cout << "x"; |
| 189 | } |
| 190 | } |
| 191 | if (stereo) { |
| 192 | cout << "{" << leftRight() << "," << m_zStatus << "}"; |
| 193 | } |
| 194 | if (pos) { |
| 195 | cout << ",pos=" << position(); |
| 196 | cout << ",drift=" << drift(0) << "," << drift(1); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | void |
| 201 | TRGCDCLink::dump(const string& msg, const string& pre) const |
| 202 | { |
| 203 | dump_base(msg, pre); |
| 204 | cout << endl; |
| 205 | } |
| 206 | |
| 207 | void |
| 208 | TRGCDCLink::dump(const vector<TRGCDCLink*>& links, |
| 209 | const string& msg, |
| 210 | const string& pre) |
| 211 | { |
| 212 | vector<const TRGCDCLink*> clinks; |
| 213 | for (unsigned i = 0; i < links.size(); i++) |
| 214 | clinks.push_back(links[i]); |
| 215 | TRGCDCLink::dump(clinks, msg, pre); |
| 216 | } |
| 217 | |
| 218 | void |
| 219 | TRGCDCLink::dump(const vector<const TRGCDCLink*>& links, |
| 220 | const string& msg, |
| 221 | const string& pre) |
| 222 | { |
| 223 | |
| 224 | |
| 225 | bool mc = (msg.find("mc") != string::npos); |
| 226 | bool sort = (msg.find("sort") != string::npos); |
| 227 | bool flag = (msg.find("flag") != string::npos); |
| 228 | |
| 229 | |
| 230 | bool detail = (msg.find("detail") != string::npos); |
| 231 | if (detail) |
| 232 | mc = flag = true; |
| 233 | |
| 234 | vector<const TRGCDCLink*> tmp = links; |
| 235 | if (sort) |
| 236 | std::sort(tmp.begin(), tmp.end(), TRGCDCLink::sortById); |
| 237 | |
| 238 | unsigned n = tmp.size(); |
| 239 | unsigned nForFit = 0; |
| 240 | #define MCC_MAX 1000 |
| 241 | unsigned MCC0[MCC_MAX]; |
| 242 | unsigned MCC1[MCC_MAX]; |
| 243 | memset((char*) MCC0, 0, sizeof(unsigned) * MCC_MAX); |
| 244 | memset((char*) MCC1, 0, sizeof(unsigned) * MCC_MAX); |
| 245 | bool MCCOverFlow = false; |
| 246 | |
| 247 | cout << pre; |
| 248 | for (unsigned i = 0; i < n; i++) { |
| 249 | const TRGCDCLink& l = * tmp[i]; |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | if (flag) { |
| 270 | if (l.hit()) { |
| 271 | if (l.hit()->state() & CellHitFittingValid) { |
| 272 | if (!(l.hit()->state() & CellHitInvalidForFit)) |
| 273 | ++nForFit; |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | if (i) |
| 278 | cout << ","; |
| 279 | l.dump_base(msg); |
| 280 | } |
| 281 | if (n) |
| 282 | cout << ",Total " << n << " links"; |
| 283 | else |
| 284 | cout << "no link"; |
| 285 | if (flag) cout << ",fv " << nForFit << " l(s)"; |
| 286 | if (mc) { |
| 287 | unsigned nMC = 0; |
| 288 | cout << ", mc"; |
| 289 | for (unsigned i = 0; i < MCC_MAX; i++) { |
| 290 | if (MCC0[i] > 0) { |
| 291 | ++nMC; |
| 292 | cout << i << ":" << MCC0[i] << ","; |
| 293 | } |
| 294 | } |
| 295 | cout << "total " << nMC << " mc contributions"; |
| 296 | if (flag) { |
| 297 | nMC = 0; |
| 298 | cout << ", fv mc"; |
| 299 | for (unsigned i = 0; i < MCC_MAX; i++) { |
| 300 | if (MCC1[i] > 0) { |
| 301 | ++nMC; |
| 302 | cout << i << ":" << MCC1[i] << ","; |
| 303 | } |
| 304 | } |
| 305 | cout << " total " << nMC << " mc fit valid contribution(s)"; |
| 306 | } |
| 307 | |
| 308 | |
| 309 | if (MCCOverFlow) |
| 310 | cout << "(counter overflow)"; |
| 311 | } |
| 312 | cout << endl; |
| 313 | |
| 314 | |
| 315 | if (mc) { |
| 316 | vector<const Belle2::TRGCDCTrackMC*> list = Belle2::TRGCDCTrackMC::list(); |
| 317 | if (! list.size()) return; |
| 318 | cout << pre; |
| 319 | |
| 320 | for (unsigned i = 0; i < MCC_MAX; i++) { |
| 321 | if (MCC0[i] > 0) { |
| 322 | const Belle2::TRGCDCTrackMC* h = list[i]; |
| 323 | |
| 324 | cout << ", mc" << i << "("; |
| 325 | if (h) |
| 326 | cout << h->pType() << ")"; |
| 327 | else |
| 328 | cout << "?)"; |
| 329 | while (h) { |
| 330 | const Belle2::TRGCDCTrackMC* m = h->mother(); |
| 331 | if (m) { |
| 332 | cout << "<-mc" << m->id(); |
| 333 | h = m; |
| 334 | } else { |
| 335 | break; |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | if (MCCOverFlow) |
| 341 | cout << "(counter overflow)"; |
| 342 | cout << endl; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | void |
| 347 | TRGCDCLink::dump(const TRGCDCLink& link, |
| 348 | const string& msg, |
| 349 | const string& pre) |
| 350 | { |
| 351 | vector<const TRGCDCLink*> tmp; |
| 352 | tmp.push_back(& link); |
| 353 | dump(tmp, msg, pre); |
| 354 | } |
| 355 | |
| 356 | unsigned |
| 357 | TRGCDCLink::nStereoHits(const vector<TRGCDCLink*>& links) |
| 358 | { |
| 359 | unsigned nLinks = links.size(); |
| 360 | unsigned n = 0; |
| 361 | for (unsigned i = 0; i < nLinks; i++) |
| 362 | if (links[i]->cell()->stereo()) |
| 363 | ++n; |
| 364 | return n; |
| 365 | } |
| 366 | |
| 367 | unsigned |
| 368 | TRGCDCLink::nAxialHits(const vector<TRGCDCLink*>& links) |
| 369 | { |
| 370 | unsigned nLinks = links.size(); |
| 371 | unsigned n = 0; |
| 372 | for (unsigned i = 0; i < nLinks; i++) |
| 373 | if (links[i]->cell()->axial()) |
| 374 | ++n; |
| 375 | return n; |
| 376 | } |
| 377 | |
| 378 | vector<TRGCDCLink*> |
| 379 | TRGCDCLink::axialHits(const vector<TRGCDCLink*>& links) |
| 380 | { |
| 381 | vector<TRGCDCLink*> a; |
| 382 | unsigned n = links.size(); |
| 383 | for (unsigned i = 0; i < n; i++) { |
| 384 | if (links[i]->cell()->axial()) |
| 385 | a.push_back(links[i]); |
| 386 | } |
| 387 | return a; |
| 388 | } |
| 389 | |
| 390 | vector<TRGCDCLink*> |
| 391 | TRGCDCLink::stereoHits(const vector<TRGCDCLink*>& links) |
| 392 | { |
| 393 | vector<TRGCDCLink*> a; |
| 394 | unsigned n = links.size(); |
| 395 | for (unsigned i = 0; i < n; i++) { |
| 396 | if (! links[i]->cell()->axial()) |
| 397 | a.push_back(links[i]); |
| 398 | } |
| 399 | return a; |
| 400 | } |
| 401 | |
| 402 | TRGCDCLink* |
| 403 | TRGCDCLink::innerMost(const vector<TRGCDCLink*>& a) |
| 404 | { |
| 405 | unsigned n = a.size(); |
| 406 | unsigned minId = 19999; |
| 407 | TRGCDCLink* t = 0; |
| 408 | for (unsigned i = 0; i < n; i++) { |
| 409 | unsigned id = a[i]->cell()->id(); |
| 410 | if (id < minId) { |
| 411 | minId = id; |
| 412 | t = a[i]; |
| 413 | } |
| 414 | } |
| 415 | return t; |
| 416 | } |
| 417 | |
| 418 | TRGCDCLink* |
| 419 | TRGCDCLink::outerMost(const vector<TRGCDCLink*>& a) |
| 420 | { |
| 421 | unsigned n = a.size(); |
| 422 | unsigned maxId = 0; |
| 423 | TRGCDCLink* t = 0; |
| 424 | for (unsigned i = 0; i < n; i++) { |
| 425 | unsigned id = a[i]->cell()->id(); |
| 426 | if (id >= maxId) { |
| 427 | maxId = id; |
| 428 | t = a[i]; |
| 429 | } |
| 430 | } |
| 431 | return t; |
| 432 | } |
| 433 | |
| 434 | void |
| 435 | TRGCDCLink::separateCores(const vector<TRGCDCLink*>& input, |
| 436 | vector<TRGCDCLink*>& cores, |
| 437 | vector<TRGCDCLink*>& nonCores) |
| 438 | { |
| 439 | unsigned n = input.size(); |
| 440 | for (unsigned i = 0; i < n; i++) { |
| 441 | TRGCDCLink& t = * input[i]; |
| 442 | const Belle2::TCCHit& h = * t.hit(); |
| 443 | if (h.state() & CellHitFittingValid) |
| 444 | cores.push_back(& t); |
| 445 | else |
| 446 | nonCores.push_back(& t); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | vector<TRGCDCLink*> |
| 451 | TRGCDCLink::cores(const vector<TRGCDCLink*>& input) |
| 452 | { |
| 453 | vector<TRGCDCLink*> a; |
| 454 | unsigned n = input.size(); |
| 455 | for (unsigned i = 0; i < n; i++) { |
| 456 | TRGCDCLink& t = * input[i]; |
| 457 | const Belle2::TCCHit& h = * t.hit(); |
| 458 | if (h.state() & CellHitFittingValid) |
| 459 | a.push_back(& t); |
| 460 | } |
| 461 | return a; |
| 462 | } |
| 463 | |
| 464 | bool |
| 465 | TRGCDCLink::sortById(const TRGCDCLink* a, const TRGCDCLink* b) |
| 466 | { |
| 467 | return a->cell()->id() < b->cell()->id(); |
| 468 | } |
| 469 | |
| 470 | int |
| 471 | TRGCDCLink::sortByX(const TRGCDCLink* a, const TRGCDCLink* b) |
| 472 | { |
| 473 | return a->position().x() < b->position().x(); |
| 474 | } |
| 475 | |
| 476 | unsigned |
| 477 | TRGCDCLink::width(const vector<TRGCDCLink*>& list) |
| 478 | { |
| 479 | const unsigned n = list.size(); |
| 480 | if (n < 2) return n; |
| 481 | |
| 482 | const TCCell* const w0 = list[0]->cell(); |
| 483 | |
| 484 | unsigned nWires = w0->layer().nCells(); |
| 485 | unsigned center = w0->localId(); |
| 486 | |
| 487 | if (ms_smallcell && w0->layerId() < 3) { |
| 488 | nWires /= 2; |
| 489 | center /= 2; |
| 490 | } |
| 491 | |
| 492 | unsigned left = 0; |
| 493 | unsigned right = 0; |
| 494 | for (unsigned i = 1; i < n; i++) { |
| 495 | const TCCell* const w = list[i]->cell(); |
| 496 | unsigned id = w->localId(); |
| 497 | |
| 498 | if (ms_smallcell && w->layerId() < 3) |
| 499 | id /= 2; |
| 500 | |
| 501 | unsigned distance0, distance1; |
| 502 | if (id > center) { |
| 503 | distance0 = id - center; |
| 504 | distance1 = nWires - distance0; |
| 505 | } else { |
| 506 | distance1 = center - id; |
| 507 | distance0 = nWires - distance1; |
| 508 | } |
| 509 | |
| 510 | if (distance0 < distance1) { |
| 511 | if (distance0 > right) right = distance0; |
| 512 | } else { |
| 513 | if (distance1 > left) left = distance1; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | return right + left + 1; |
| 518 | } |
| 519 | |
| 520 | vector<TRGCDCLink*> |
| 521 | TRGCDCLink::edges(const vector<TRGCDCLink*>& list) |
| 522 | { |
| 523 | vector<TRGCDCLink*> a; |
| 524 | |
| 525 | unsigned n = list.size(); |
| 526 | if (n < 2) return a; |
| 527 | else if (n == 2) return list; |
| 528 | |
| 529 | const TCCell* w = list[0]->cell(); |
| 530 | unsigned nWires = w->layer().nCells(); |
| 531 | unsigned center = w->localId(); |
| 532 | |
| 533 | unsigned left = 0; |
| 534 | unsigned right = 0; |
| 535 | TRGCDCLink* leftL = list[0]; |
| 536 | TRGCDCLink* rightL = list[0]; |
| 537 | for (unsigned i = 1; i < n; i++) { |
| 538 | w = list[i]->cell(); |
| 539 | unsigned id = w->localId(); |
| 540 | |
| 541 | unsigned distance0, distance1; |
| 542 | if (id > center) { |
| 543 | distance0 = id - center; |
| 544 | distance1 = nWires - distance0; |
| 545 | } else { |
| 546 | distance1 = center - id; |
| 547 | distance0 = nWires - distance1; |
| 548 | } |
| 549 | |
| 550 | if (distance0 < distance1) { |
| 551 | if (distance0 > right) { |
| 552 | right = distance0; |
| 553 | rightL = list[i]; |
| 554 | } |
| 555 | } else { |
| 556 | if (distance1 > left) { |
| 557 | left = distance1; |
| 558 | leftL = list[i]; |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | a.push_back(leftL); |
| 564 | a.push_back(rightL); |
| 565 | return a; |
| 566 | } |
| 567 | |
| 568 | vector<TRGCDCLink*> |
| 569 | TRGCDCLink::sameLayer(const vector<TRGCDCLink*>& list, const TRGCDCLink& a) |
| 570 | { |
| 571 | vector<TRGCDCLink*> same; |
| 572 | unsigned id = a.cell()->layerId(); |
| 573 | unsigned n = list.size(); |
| 574 | for (unsigned i = 0; i < n; i++) { |
| 575 | if (list[i]->cell()->layerId() == id) same.push_back(list[i]); |
| 576 | } |
| 577 | return same; |
| 578 | } |
| 579 | |
| 580 | vector<TRGCDCLink*> |
| 581 | TRGCDCLink::sameSuperLayer(const vector<TRGCDCLink*>& list, const TRGCDCLink& a) |
| 582 | { |
| 583 | vector<TRGCDCLink*> same; |
| 584 | unsigned id = a.cell()->superLayerId(); |
| 585 | unsigned n = list.size(); |
| 586 | for (unsigned i = 0; i < n; i++) { |
| 587 | if (list[i]->cell()->superLayerId() == id) same.push_back(list[i]); |
| 588 | } |
| 589 | return same; |
| 590 | } |
| 591 | |
| 592 | vector<TRGCDCLink*> |
| 593 | TRGCDCLink::sameLayer(const vector<TRGCDCLink*>& list, unsigned id) |
| 594 | { |
| 595 | vector<TRGCDCLink*> same; |
| 596 | unsigned n = list.size(); |
| 597 | for (unsigned i = 0; i < n; i++) { |
| 598 | if (list[i]->cell()->layerId() == id) same.push_back(list[i]); |
| 599 | } |
| 600 | return same; |
| 601 | } |
| 602 | |
| 603 | vector<TRGCDCLink*> |
| 604 | TRGCDCLink::sameSuperLayer(const vector<TRGCDCLink*>& list, unsigned id) |
| 605 | { |
| 606 | vector<TRGCDCLink*> same; |
| 607 | unsigned n = list.size(); |
| 608 | for (unsigned i = 0; i < n; i++) { |
| 609 | if (list[i]->cell()->superLayerId() == id) same.push_back(list[i]); |
| 610 | } |
| 611 | return same; |
| 612 | } |
| 613 | |
| 614 | vector<TRGCDCLink*> |
| 615 | TRGCDCLink::inOut(const vector<TRGCDCLink*>& list) |
| 616 | { |
| 617 | vector<TRGCDCLink*> inners; |
| 618 | vector<TRGCDCLink*> outers; |
| 619 | unsigned n = list.size(); |
| 620 | unsigned innerMostLayer = 999; |
| 621 | unsigned outerMostLayer = 0; |
| 622 | for (unsigned i = 0; i < n; i++) { |
| 623 | unsigned id = list[i]->cell()->layerId(); |
| 624 | if (id < innerMostLayer) innerMostLayer = id; |
| 625 | else if (id > outerMostLayer) outerMostLayer = id; |
| 626 | } |
| 627 | for (unsigned i = 0; i < n; i++) { |
| 628 | unsigned id = list[i]->cell()->layerId(); |
| 629 | if (id == innerMostLayer) inners.push_back(list[i]); |
| 630 | else if (id == outerMostLayer) outers.push_back(list[i]); |
| 631 | } |
| 632 | |
| 633 | inners.insert(inners.end(), outers.begin(), outers.end()); |
| 634 | return inners; |
| 635 | } |
| 636 | |
| 637 | unsigned |
| 638 | TRGCDCLink::superLayer(const vector<TRGCDCLink*>& list) |
| 639 | { |
| 640 | unsigned sl = 0; |
| 641 | unsigned n = list.size(); |
| 642 | for (unsigned i = 0; i < n; i++) |
| 643 | sl |= (1 << (list[i]->cell()->superLayerId())); |
| 644 | return sl; |
| 645 | } |
| 646 | |
| 647 | unsigned |
| 648 | TRGCDCLink::superLayer(const vector<TRGCDCLink*>& links, unsigned minN) |
| 649 | { |
| 650 | clearBufferSL(); |
| 651 | unsigned n = links.size(); |
| 652 | for (unsigned i = 0; i < n; i++) |
| 653 | ++m_nHitsSL[links[i]->cell()->superLayerId()]; |
| 654 | unsigned sl = 0; |
| 655 | for (unsigned i = 0; i < m_nSL; i++) |
| 656 | if (m_nHitsSL[i] >= minN) |
| 657 | sl |= (1 << i); |
| 658 | return sl; |
| 659 | } |
| 660 | |
| 661 | unsigned |
| 662 | TRGCDCLink::nSuperLayers(const vector<TRGCDCLink*>& list) |
| 663 | { |
| 664 | unsigned l0 = 0; |
| 665 | unsigned n = list.size(); |
| 666 | for (unsigned i = 0; i < n; i++) { |
| 667 | unsigned id = list[i]->cell()->superLayerId(); |
| 668 | l0 |= (1 << id); |
| 669 | } |
| 670 | |
| 671 | unsigned l = 0; |
| 672 | for (unsigned i = 0; i < m_nSL; i++) { |
| 673 | if (l0 & (1 << i)) ++l; |
| 674 | } |
| 675 | return l; |
| 676 | } |
| 677 | |
| 678 | unsigned |
| 679 | TRGCDCLink::nSuperLayers(const vector<TRGCDCLink*>& links, unsigned minN) |
| 680 | { |
| 681 | clearBufferSL(); |
| 682 | unsigned n = links.size(); |
| 683 | for (unsigned i = 0; i < n; i++) |
| 684 | ++m_nHitsSL[links[i]->cell()->superLayerId()]; |
| 685 | unsigned sl = 0; |
| 686 | for (unsigned i = 0; i < m_nSL; i++) |
| 687 | if (m_nHitsSL[i] >= minN) |
| 688 | ++sl; |
| 689 | return sl; |
| 690 | } |
| 691 | |
| 692 | unsigned |
| 693 | TRGCDCLink::nMissingAxialSuperLayers(const vector<TRGCDCLink*>& links) |
| 694 | { |
| 695 | clearBufferSL(); |
| 696 | const unsigned n = links.size(); |
| 697 | |
| 698 | for (unsigned i = 0; i < n; i++) |
| 699 | if (links[i]->cell()->axial()) |
| 700 | ++m_nHitsSL[links[i]->cell()->axialStereoSuperLayerId()]; |
| 701 | |
| 702 | unsigned j = 0; |
| 703 | while (m_nHitsSL[j] == 0) ++j; |
| 704 | unsigned nMissing = 0; |
| 705 | unsigned nMax = 0; |
| 706 | for (unsigned i = j; i < m_nSLA; i++) { |
| 707 | if (+m_nHitsSL[i] == 0) ++nMissing; |
| 708 | else { |
| 709 | if (nMax < nMissing) nMax = nMissing; |
| 710 | nMissing = 0; |
| 711 | } |
| 712 | } |
| 713 | return nMax; |
| 714 | } |
| 715 | |
| 716 | const Belle2::TRGCDCTrackMC& |
| 717 | TRGCDCLink::links2HEP(const vector<TRGCDCLink*>&) |
| 718 | { |
| 719 | const Belle2::TRGCDCTrackMC* best = TRGCDCTrackMC::_undefined; |
| 720 | const vector<const Belle2::TRGCDCTrackMC*> list = |
| 721 | Belle2::TRGCDCTrackMC::list(); |
| 722 | unsigned nHep = list.size(); |
| 723 | |
| 724 | if (! nHep) return * best; |
| 725 | |
| 726 | unsigned* N; |
| 727 | if (NULL == (N = (unsigned*) malloc(nHep * sizeof(unsigned)))) { |
| 728 | |
| 729 | exit(1); |
| 730 | } |
| 731 | for (unsigned i = 0; i < nHep; i++) N[i] = 0; |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | unsigned nMax = 0; |
| 742 | for (unsigned i = 0; i < nHep; i++) { |
| 743 | if (N[i] > nMax) { |
| 744 | best = list[i]; |
| 745 | nMax = N[i]; |
| 746 | } |
| 747 | } |
| 748 | |
| 749 | free(N); |
| 750 | |
| 751 | return * best; |
| 752 | } |
| 753 | |
| 754 | void |
| 755 | TRGCDCLink::nHitsSuperLayer(const vector<TRGCDCLink*>& links, vector<TRGCDCLink*>* list) |
| 756 | { |
| 757 | const unsigned nLinks = links.size(); |
| 758 | for (unsigned i = 0; i < nLinks; i++) |
| 759 | list[links[i]->cell()->superLayerId()].push_back(links[i]); |
| 760 | } |
| 761 | |
| 762 | string |
| 763 | TRGCDCLink::layerUsage(const vector<TRGCDCLink*>& links) |
| 764 | { |
| 765 | |
| 766 | static unsigned* n = new unsigned[Belle2::TRGCDC::getTRGCDC()->nSuperLayers()]; |
| 1 | Storing uninitialized value | |
|
| 767 | for (unsigned i = 0; i < m_nSL; i++) { |
| 2 | | Assuming 'i' is < 'm_nSL' | |
|
| 3 | | Loop condition is true. Entering loop body | |
|
| 4 | | Assuming 'i' is >= 'm_nSL' | |
|
| 5 | | Loop condition is false. Execution continues on line 770 | |
|
| 768 | n[i] = 0; |
| 769 | } |
| 770 | nHitsSuperLayer(links, n); |
| 6 | | Calling 'TRGCDCLink::nHitsSuperLayer' | |
|
| 9 | | Returning from 'TRGCDCLink::nHitsSuperLayer' | |
|
| 771 | string nh = ""; |
| 772 | for (unsigned i = 0; i < m_nSL; i++) { |
| 10 | | Loop condition is true. Entering loop body | |
|
| 13 | | The value 1 is assigned to 'i' | |
|
| 14 | | Assuming 'i' is < 'm_nSL' | |
|
| 15 | | Loop condition is true. Entering loop body | |
|
| 773 | nh += TRGUtil::itostring(n[i]); |
| 16 | | 1st function call argument is an uninitialized value |
|
| 774 | if (i % 2) nh += ","; |
| |
| 775 | else if (i < 10) nh += "-"; |
| |
| 776 | } |
| 777 | return nh; |
| 778 | } |
| 779 | |
| 780 | void |
| 781 | TRGCDCLink::remove(vector<TRGCDCLink*>& list, |
| 782 | const vector<TRGCDCLink*>& links) |
| 783 | { |
| 784 | const unsigned n = list.size(); |
| 785 | const unsigned m = links.size(); |
| 786 | |
| 787 | |
| 788 | for (unsigned i = 0; i < n; i++) { |
| 789 | for (unsigned j = 0; j < m; j++) { |
| 790 | if (list[i]->cell()->id() == links[j]->cell()->id()) |
| 791 | |
| 792 | |
| 793 | cout << "TCLink::remove !!! not implemented yet" << endl; |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | |
| 798 | } |
| 799 | |
| 800 | void |
| 801 | TRGCDCLink::initializeBuffers(void) |
| 802 | { |
| 803 | static bool first = true; |
| 804 | if (first) { |
| 805 | const Belle2::TRGCDC& cdc = * Belle2::TRGCDC::getTRGCDC(); |
| 806 | m_nL = cdc.nLayers(); |
| 807 | m_nSL = cdc.nSuperLayers(); |
| 808 | m_nSLA = cdc.nAxialSuperLayers(); |
| 809 | m_nHitsSL = new unsigned[m_nSL]; |
| 810 | first = false; |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | void |
| 815 | TRGCDCLink::separate(const vector<TRGCDCLink*>& links, |
| 816 | unsigned nLayers, |
| 817 | vector<TRGCDCLink*>* layers) |
| 818 | { |
| 819 | for (unsigned i = 0; i < links.size(); i++) { |
| 820 | const TCCell* c = links[i]->cell(); |
| 821 | if (c) { |
| 822 | unsigned lid = c->layer().id(); |
| 823 | if (lid < nLayers) |
| 824 | layers[lid].push_back(links[i]); |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | const TRGCDCWire* |
| 830 | TRGCDCLink::wire(void) const |
| 831 | { |
| 832 | if (m_hit) |
| 833 | return dynamic_cast<const TRGCDCWire*>(& m_hit->cell()); |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | void |
| 846 | TRGCDCLink::removeAll(void) |
| 847 | { |
| 848 | while (m_all.size()) |
| 849 | delete m_all.back(); |
| 850 | } |
| 851 | |
| 852 | void* |
| 853 | TRGCDCLink::operator new (size_t size) |
| 854 | { |
| 855 | void* p = malloc(size); |
| 856 | m_all.push_back(static_cast<TRGCDCLink*>(p)); |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | return p; |
| 863 | } |
| 864 | |
| 865 | void |
| 866 | TRGCDCLink::operator delete (void* t) |
| 867 | { |
| 868 | for (vector<TRGCDCLink*>::iterator it = m_all.begin(); |
| 869 | it != m_all.end(); |
| 870 | ++it) { |
| 871 | if ((* it) == static_cast<TRGCDCLink*>(t)) { |
| 872 | m_all.erase(it); |
| 873 | break; |
| 874 | } |
| 875 | } |
| 876 | free(t); |
| 877 | |
| 878 | |
| 879 | |
| 880 | |
| 881 | |
| 882 | } |
| 883 | |
| 884 | } |