| File: | trg/cdc/src/TRGCDC.cc |
| Warning: | line 2491, column 11 Value stored to 'lid' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /************************************************************************** |
| 2 | * basf2 (Belle II Analysis Software Framework) * |
| 3 | * Author: The Belle II Collaboration * |
| 4 | * * |
| 5 | * See git log for contributors and copyright holders. * |
| 6 | * This file is licensed under LGPL-3.0, see LICENSE.md. * |
| 7 | **************************************************************************/ |
| 8 | |
| 9 | //----------------------------------------------------------------------------- |
| 10 | // Description : A class to represent CDC. |
| 11 | //----------------------------------------------------------------------------- |
| 12 | |
| 13 | #define TRG_SHORT_NAMES |
| 14 | #define TRGCDC_SHORT_NAMES |
| 15 | |
| 16 | #include <math.h> |
| 17 | #include <TRandom.h> |
| 18 | #include <iostream> |
| 19 | #include <fstream> |
| 20 | #include "framework/datastore/StoreArray.h" |
| 21 | #include "framework/datastore/RelationArray.h" |
| 22 | #include "rawdata/dataobjects/RawDataBlock.h" |
| 23 | #include "rawdata/dataobjects/RawCOPPER.h" |
| 24 | #include <rawdata/dataobjects/RawTRG.h> |
| 25 | #include "cdc/geometry/CDCGeometryPar.h" |
| 26 | #include "cdc/dataobjects/CDCHit.h" |
| 27 | #include "cdc/dataobjects/CDCSimHit.h" |
| 28 | #include "mdst/dataobjects/MCParticle.h" |
| 29 | #include "trg/trg/Debug.h" |
| 30 | #include "trg/trg/Time.h" |
| 31 | #include "trg/trg/State.h" |
| 32 | #include "trg/trg/Signal.h" |
| 33 | #include "trg/trg/Channel.h" |
| 34 | #include "trg/trg/Utilities.h" |
| 35 | #include "trg/cdc/dataobjects/CDCTriggerSegmentHit.h" |
| 36 | #include "trg/cdc/dataobjects/CDCTriggerTrack.h" |
| 37 | #include "trg/trg/dataobjects/TRGTiming.h" |
| 38 | #include "trg/cdc/TRGCDC.h" |
| 39 | #include "trg/cdc/Wire.h" |
| 40 | #include "trg/cdc/Layer.h" |
| 41 | #include "trg/cdc/WireHit.h" |
| 42 | #include "trg/cdc/WireHitMC.h" |
| 43 | #include "trg/cdc/TrackMC.h" |
| 44 | #include "trg/cdc/Relation.h" |
| 45 | #include "trg/cdc/TRGCDCTrack.h" |
| 46 | #include "trg/cdc/Segment.h" |
| 47 | #include "trg/cdc/SegmentHit.h" |
| 48 | #include "trg/cdc/LUT.h" |
| 49 | #include "trg/cdc/FrontEnd.h" |
| 50 | #include "trg/cdc/Merger.h" |
| 51 | #include "trg/cdc/TrackSegmentFinder.h" |
| 52 | #include "trg/cdc/Tracker2D.h" |
| 53 | #include "trg/cdc/PerfectFinder.h" |
| 54 | #include "trg/cdc/HoughFinder.h" |
| 55 | #include "trg/cdc/Hough3DFinder.h" |
| 56 | #include "trg/cdc/Fitter3D.h" |
| 57 | #include "trg/cdc/Fitter3DUtility.h" |
| 58 | #include "trg/cdc/Link.h" |
| 59 | #include "trg/cdc/EventTime.h" |
| 60 | #include <framework/gearbox/Const.h> |
| 61 | #include <framework/geometry/B2Vector3.h> |
| 62 | #include <TObjString.h> |
| 63 | |
| 64 | #define NOT_USE_SOCKETLIB |
| 65 | //#define NOT_SEND |
| 66 | //#define DUMMY_DATA |
| 67 | #define TIME_MONITOR |
| 68 | //#define MULTIPLE_SEND |
| 69 | //#define MEMCPY_TO_ONE_BUFFER |
| 70 | #define SEND_BY_WRITEV |
| 71 | |
| 72 | #ifdef TRGCDC_DISPLAY |
| 73 | #include "trg/cdc/DisplayRphi.h" |
| 74 | #include "trg/cdc/DisplayHough.h" |
| 75 | namespace Belle2_TRGCDC { |
| 76 | Belle2::TRGCDCDisplayRphi* D = 0; |
| 77 | } |
| 78 | using namespace Belle2_TRGCDC; |
| 79 | #endif |
| 80 | |
| 81 | #define P3DHepGeom::Point3D<double> HepGeom::Point3D<double> |
| 82 | |
| 83 | using namespace std; |
| 84 | |
| 85 | namespace Belle2 { |
| 86 | |
| 87 | string |
| 88 | TRGCDC::name(void) const |
| 89 | { |
| 90 | return "TRGCDC"; |
| 91 | } |
| 92 | |
| 93 | string |
| 94 | TRGCDC::version(void) const |
| 95 | { |
| 96 | return string("TRGCDC 5.39"); |
| 97 | } |
| 98 | |
| 99 | TRGCDC* |
| 100 | TRGCDC::_cdc = 0; |
| 101 | |
| 102 | TRGCDC* |
| 103 | TRGCDC::getTRGCDC(const string& configFile, |
| 104 | unsigned simulationMode, |
| 105 | unsigned fastSimulationMode, |
| 106 | unsigned firmwareSimulationMode, |
| 107 | int firmwareSimulationStart, |
| 108 | int firmwareSimulationStop, |
| 109 | bool makeRootFile, |
| 110 | bool perfect2DFinder, |
| 111 | bool perfect3DFinder, |
| 112 | const string& innerTSLUTFile, |
| 113 | const string& outerTSLUTFile, |
| 114 | const string& rootTRGCDCFile, |
| 115 | const string& rootFitter3DFile, |
| 116 | unsigned houghFinderPeakMin, |
| 117 | const string& houghMappingFilePlus, |
| 118 | const string& houghMappingFileMinus, |
| 119 | unsigned houghDoit, |
| 120 | bool fLogicLUTTSF, |
| 121 | bool fLRLUT, |
| 122 | bool fFitter3Dsmclr, |
| 123 | bool fFitter3Ds2DFit, |
| 124 | bool fFitter3Ds2DFitDrift, |
| 125 | double inefficiency, |
| 126 | bool fileTSF, |
| 127 | bool fileETF, |
| 128 | int fverETF, |
| 129 | bool fprintFirmETF, |
| 130 | bool fileHough3D, |
| 131 | int finder3DMode, |
| 132 | bool fileFitter3D, |
| 133 | bool fXtSimpleFitter3D, |
| 134 | double TdcBinWidth, |
| 135 | int trgCDCDataInputMode, |
| 136 | const string& cdchitCollectionName) |
| 137 | { |
| 138 | if (_cdc) { |
| 139 | //delete _cdc; |
| 140 | _cdc = 0; |
| 141 | } |
| 142 | |
| 143 | if (configFile != "good-bye") { |
| 144 | _cdc = new TRGCDC(configFile, |
| 145 | simulationMode, |
| 146 | fastSimulationMode, |
| 147 | firmwareSimulationMode, |
| 148 | firmwareSimulationStart, |
| 149 | firmwareSimulationStop, |
| 150 | makeRootFile, |
| 151 | perfect2DFinder, |
| 152 | perfect3DFinder, |
| 153 | innerTSLUTFile, |
| 154 | outerTSLUTFile, |
| 155 | rootTRGCDCFile, |
| 156 | rootFitter3DFile, |
| 157 | houghFinderPeakMin, |
| 158 | houghMappingFilePlus, |
| 159 | houghMappingFileMinus, |
| 160 | houghDoit, |
| 161 | fLogicLUTTSF, |
| 162 | fLRLUT, |
| 163 | fFitter3Dsmclr, |
| 164 | fFitter3Ds2DFit, |
| 165 | fFitter3Ds2DFitDrift, |
| 166 | inefficiency, |
| 167 | fileTSF, |
| 168 | fileETF, |
| 169 | fverETF, |
| 170 | fprintFirmETF, |
| 171 | fileHough3D, |
| 172 | finder3DMode, |
| 173 | fileFitter3D, |
| 174 | fXtSimpleFitter3D, |
| 175 | TdcBinWidth, |
| 176 | trgCDCDataInputMode, |
| 177 | cdchitCollectionName); |
| 178 | } else { |
| 179 | cout << "TRGCDC::getTRGCDC ... good-bye" << endl; |
| 180 | // delete _cdc; |
| 181 | _cdc = 0; |
| 182 | } |
| 183 | |
| 184 | return _cdc; |
| 185 | } |
| 186 | |
| 187 | TRGCDC* |
| 188 | TRGCDC::getTRGCDC(void) |
| 189 | { |
| 190 | if (! _cdc) |
| 191 | cout << "TRGCDC::getTRGCDC !!! TRGCDC is not created yet" << endl; |
| 192 | return _cdc; |
| 193 | } |
| 194 | |
| 195 | vector<TCTrackTRGCDCTrack*> |
| 196 | TRGCDC::getTrackList2D(void) |
| 197 | { |
| 198 | return _trackList2D; |
| 199 | } |
| 200 | |
| 201 | vector<TCTrackTRGCDCTrack*> |
| 202 | TRGCDC::getTrackList2DFitted(void) |
| 203 | { |
| 204 | return _trackList2DFitted; |
| 205 | } |
| 206 | |
| 207 | vector<TCTrackTRGCDCTrack*> |
| 208 | TRGCDC::getTrackList3D(void) |
| 209 | { |
| 210 | return _trackList3D; |
| 211 | } |
| 212 | |
| 213 | TRGCDC::TRGCDC(const string& configFile, |
| 214 | unsigned simulationMode, |
| 215 | unsigned fastSimulationMode, |
| 216 | unsigned firmwareSimulationMode, |
| 217 | int firmwareSimulationStart, |
| 218 | int firmwareSimulationStop, |
| 219 | bool makeRootFile, |
| 220 | bool perfect2DFinder, |
| 221 | bool perfect3DFinder, |
| 222 | const string& innerTSLUTFile, |
| 223 | const string& outerTSLUTFile, |
| 224 | const string& rootTRGCDCFile, |
| 225 | const string& rootFitter3DFile, |
| 226 | unsigned houghFinderPeakMin, |
| 227 | const string& houghMappingFilePlus, |
| 228 | const string& houghMappingFileMinus, |
| 229 | unsigned houghDoit, |
| 230 | bool fLogicLUTTSF, |
| 231 | bool fLRLUT, |
| 232 | bool fFitter3Dsmclr, |
| 233 | bool fFitter3Ds2DFit, |
| 234 | bool fFitter3Ds2DFitDrift, |
| 235 | double inefficiency, |
| 236 | bool fileTSF, |
| 237 | bool fileETF, |
| 238 | int fverETF, |
| 239 | bool fprintFirmETF, |
| 240 | bool fileHough3D, |
| 241 | int finder3DMode, |
| 242 | bool fileFitter3D, |
| 243 | bool fXtSimpleFitter3D, |
| 244 | double TdcBinWidth, |
| 245 | int trgCDCDataInputMode, |
| 246 | const string& cdchitCollectionName): |
| 247 | _debugLevel(0), |
| 248 | _configFilename(configFile), |
| 249 | _simulationMode(simulationMode), |
| 250 | _fastSimulationMode(fastSimulationMode), |
| 251 | _firmwareSimulationMode(firmwareSimulationMode), |
| 252 | _firmwareSimulationStart(firmwareSimulationStart), |
| 253 | _firmwareSimulationStop(firmwareSimulationStop), |
| 254 | _returnValue(0), |
| 255 | _makeRootFile(makeRootFile), |
| 256 | _perfect2DFinder(perfect2DFinder), |
| 257 | _perfect3DFinder(perfect3DFinder), |
| 258 | _innerTSLUTFilename(innerTSLUTFile), |
| 259 | _outerTSLUTFilename(outerTSLUTFile), |
| 260 | _rootTRGCDCFilename(rootTRGCDCFile), |
| 261 | _rootFitter3DFilename(rootFitter3DFile), |
| 262 | _fLogicLUTTSF(fLogicLUTTSF), |
| 263 | _fLRLUT(fLRLUT), |
| 264 | _fFitter3Dsmclr(fFitter3Dsmclr), |
| 265 | _fFitter3Ds2DFit(fFitter3Ds2DFit), |
| 266 | _fFitter3Ds2DFitDrift(fFitter3Ds2DFitDrift), |
| 267 | _inefficiency(inefficiency), |
| 268 | _fileTSF(fileTSF), |
| 269 | _fileETF(fileETF), |
| 270 | _fverETF(fverETF), |
| 271 | _fprintFirmETF(fprintFirmETF), |
| 272 | _fileHough3D(fileHough3D), |
| 273 | _finder3DMode(finder3DMode), |
| 274 | _fileFitter3D(fileFitter3D), |
| 275 | _fXtSimpleFitter3D(fXtSimpleFitter3D), |
| 276 | _fudgeFactor(1.), |
| 277 | _width(0), |
| 278 | _r(0), |
| 279 | _r2(0), |
| 280 | _clock("CDCTrigger system clock", 0, 125. / TdcBinWidth), |
| 281 | _clockFE("CDCFE TDC clock", _clock, 8), |
| 282 | _clockTDC("CDCTrigger TDC clock (after mergers)", _clock, 4), |
| 283 | _clockD("CDCTrigger data clock", _clock, 1, 4), |
| 284 | _clockUser3125("CDCTrigger Aurora user clock (3.125Gbps)", |
| 285 | _clock, 25, 20), |
| 286 | _clockUser6250("CDCTrigger Aurora user clock (6.250Gbps)", |
| 287 | _clock, 50, 20), |
| 288 | _offset(5.3), |
| 289 | _pFinder(0), |
| 290 | _hFinder(0), |
| 291 | _h3DFinder(0), |
| 292 | _fitter3D(0), |
| 293 | _eventTime(0), |
| 294 | _trgCDCDataInputMode(trgCDCDataInputMode), |
| 295 | _cdchitCollectionName(cdchitCollectionName) |
| 296 | { |
| 297 | |
| 298 | TRGDebug::enterStage("TRGCDC constructor"); |
| 299 | |
| 300 | #ifdef TRGCDC_DISPLAY |
| 301 | int argc = 0; |
| 302 | char** argv = 0; |
| 303 | Gtk::Main main_instance(argc, argv); |
| 304 | if (! D) |
| 305 | D = new TCDisplayRphi(); |
| 306 | D->clear(); |
| 307 | D->show(); |
| 308 | cout << "TRGCDC ... GTK initialized" << endl; |
| 309 | #endif |
| 310 | |
| 311 | //...Clock summary... |
| 312 | _clock.dump(); |
| 313 | _clockFE.dump(); |
| 314 | _clockTDC.dump(); |
| 315 | _clockD.dump(); |
| 316 | |
| 317 | //...Firmware simulation time window... |
| 318 | TRGTime rise = TRGTime(_firmwareSimulationStart, true, _clockFE); |
| 319 | TRGTime fall = rise; |
| 320 | fall.shift(_firmwareSimulationStop).reverse(); |
| 321 | _firmwareSimulationWindow = TRGSignal(rise & fall); |
| 322 | _firmwareSimulationWindow.name("Firmware simulation window in FE clock"); |
| 323 | _firmwareSimulationWindow.dump(); |
| 324 | |
| 325 | //...Time window in other clocks... |
| 326 | _firmwareSimulationStartDataClock = |
| 327 | _clockD.position(_clockFE.absoluteTime(_firmwareSimulationStart)); |
| 328 | _firmwareSimulationStopDataClock = |
| 329 | _clockD.position(_clockFE.absoluteTime(_firmwareSimulationStop)); |
| 330 | |
| 331 | cout << "In " << _clock.name() << endl; |
| 332 | cout << " Start : " |
| 333 | << _clock.position(_clockFE.absoluteTime(_firmwareSimulationStart)) |
| 334 | << endl; |
| 335 | cout << " Stop : " |
| 336 | << _clock.position(_clockFE.absoluteTime(_firmwareSimulationStop)) |
| 337 | << endl; |
| 338 | cout << "In " << _clockTDC.name() << endl; |
| 339 | cout << " Start : " |
| 340 | << _clockTDC.position(_clockFE.absoluteTime(_firmwareSimulationStart)) |
| 341 | << endl; |
| 342 | cout << " Stop : " |
| 343 | << _clockTDC.position(_clockFE.absoluteTime(_firmwareSimulationStop)) |
| 344 | << endl; |
| 345 | cout << "In " << _clockD.name() << endl; |
| 346 | cout << " Start : " << _firmwareSimulationStartDataClock << endl; |
| 347 | cout << " Stop : " << _firmwareSimulationStopDataClock << endl; |
| 348 | |
| 349 | if (TRGDebug::level()) { |
| 350 | cout << "TRGCDC ... TRGCDC initializing with " << _configFilename |
| 351 | << endl |
| 352 | << "mode=0x" << hex << _simulationMode << dec << endl; |
| 353 | } |
| 354 | |
| 355 | initialize(houghFinderPeakMin, |
| 356 | houghMappingFilePlus, |
| 357 | houghMappingFileMinus, |
| 358 | houghDoit); |
| 359 | |
| 360 | if (TRGDebug::level()) { |
| 361 | cout << "TRGCDC ... TRGCDC created with " << _configFilename << endl; |
| 362 | } |
| 363 | |
| 364 | TRGDebug::leaveStage("TRGCDC constructor"); |
| 365 | } |
| 366 | |
| 367 | void |
| 368 | TRGCDC::initialize(unsigned houghFinderPeakMin, |
| 369 | const string& houghMappingFilePlus, |
| 370 | const string& houghMappingFileMinus, |
| 371 | unsigned houghDoit) |
| 372 | { |
| 373 | |
| 374 | TRGDebug::enterStage("TRGCDC initialize"); |
| 375 | |
| 376 | //...CDC... |
| 377 | m_cdcp = &(Belle2::CDC::CDCGeometryPar::Instance()); |
| 378 | const unsigned nLayers = m_cdcp->nWireLayers(); |
| 379 | |
| 380 | //...Loop over layers... |
| 381 | int superLayerId = -1; |
| 382 | vector<TRGCDCLayer*>* superLayer; |
| 383 | unsigned lastNWires = 0; |
| 384 | int lastShifts = -1000; |
| 385 | int ia = -1; |
| 386 | int is = -1; |
| 387 | int ias = -1; |
| 388 | int iss = -1; |
| 389 | unsigned nWires = 0; |
| 390 | float fwr = 0; |
| 391 | unsigned axialStereoSuperLayerId = 0; |
| 392 | for (unsigned i = 0; i < nLayers; i++) { |
| 393 | const unsigned nWiresInLayer = m_cdcp->nWiresInLayer(i); |
| 394 | |
| 395 | //...Axial or stereo?... |
| 396 | int nShifts = m_cdcp->nShifts(i); |
| 397 | bool axial = true; |
| 398 | if (nShifts != 0) |
| 399 | axial = false; |
| 400 | |
| 401 | unsigned axialStereoLayerId = 0; |
| 402 | if (axial) { |
| 403 | ++ia; |
| 404 | axialStereoLayerId = ia; |
| 405 | } else { |
| 406 | ++is; |
| 407 | axialStereoLayerId = is; |
| 408 | } |
| 409 | |
| 410 | if (TRGDebug::level() > 1) { |
| 411 | cout << TRGDebug::tab() << "No " << i << " nWiresInLayer: " |
| 412 | << nWiresInLayer << " axial: " << axial << " nShifts: " |
| 413 | << nShifts << endl; |
| 414 | } |
| 415 | |
| 416 | //...Is this in a new super layer?... |
| 417 | if ((lastNWires != nWiresInLayer) || (lastShifts != nShifts)) { |
| 418 | ++superLayerId; |
| 419 | superLayer = new vector<TRGCDCLayer*>; |
| 420 | _superLayers.push_back(superLayer); |
| 421 | if (axial) { |
| 422 | ++ias; |
| 423 | axialStereoSuperLayerId = ias; |
| 424 | _axialSuperLayers.push_back(superLayer); |
| 425 | } else { |
| 426 | ++iss; |
| 427 | axialStereoSuperLayerId = iss; |
| 428 | _stereoSuperLayers.push_back(superLayer); |
| 429 | } |
| 430 | lastNWires = nWiresInLayer; |
| 431 | lastShifts = nShifts; |
| 432 | } |
| 433 | |
| 434 | if (TRGDebug::level() > 1) { |
| 435 | cout << TRGDebug::tab() << "(lastNWires,nWiresInLayer) " |
| 436 | << lastNWires << " " << nWiresInLayer << endl; |
| 437 | cout << TRGDebug::tab() << "(lastShifts,nShifts) " << lastShifts |
| 438 | << " " << nShifts << endl; |
| 439 | cout << "superLayerId: " << superLayerId << endl; |
| 440 | cout << "ia: " << ia << " is: " << is << " ias: " << ias |
| 441 | << " iss: " << iss << endl; |
| 442 | } |
| 443 | |
| 444 | //...Calculate radius... |
| 445 | const float swr = m_cdcp->senseWireR(i); |
| 446 | if (i < nLayers - 1) |
| 447 | fwr = m_cdcp->fieldWireR(i); |
| 448 | else |
| 449 | fwr = swr + (swr - m_cdcp->fieldWireR(i - 1)); |
| 450 | const float innerRadius = swr - (fwr - swr); |
| 451 | const float outerRadius = swr + (fwr - swr); |
| 452 | |
| 453 | if (TRGDebug::level() > 1) |
| 454 | cout << TRGDebug::tab() << "lyr " << i << ", in=" << innerRadius |
| 455 | << ", out=" << outerRadius << ", swr=" << swr << ", fwr" |
| 456 | << fwr << endl; |
| 457 | |
| 458 | //...New layer... |
| 459 | TRGCDCLayer* layer = new TRGCDCLayer(i, |
| 460 | superLayerId, |
| 461 | _superLayers[superLayerId]->size(), |
| 462 | axialStereoLayerId, |
| 463 | axialStereoSuperLayerId, |
| 464 | m_cdcp->zOffsetWireLayer(i), |
| 465 | nShifts, |
| 466 | M_PI3.14159265358979323846 * m_cdcp->senseWireR(i) |
| 467 | * m_cdcp->senseWireR(i) |
| 468 | / double(nWiresInLayer), |
| 469 | nWiresInLayer, |
| 470 | innerRadius, |
| 471 | outerRadius); |
| 472 | _layers.push_back(layer); |
| 473 | superLayer->push_back(layer); |
| 474 | if (axial) |
| 475 | _axialLayers.push_back(layer); |
| 476 | else |
| 477 | _stereoLayers.push_back(layer); |
| 478 | |
| 479 | //...Loop over all wires in a layer... |
| 480 | for (unsigned j = 0; j < nWiresInLayer; j++) { |
| 481 | const P3DHepGeom::Point3D<double> fp = P3DHepGeom::Point3D<double>(m_cdcp->wireForwardPosition(i, j).x(), |
| 482 | m_cdcp->wireForwardPosition(i, j).y(), |
| 483 | m_cdcp->wireForwardPosition(i, j).z()); |
| 484 | const P3DHepGeom::Point3D<double> bp = P3DHepGeom::Point3D<double>(m_cdcp->wireBackwardPosition(i, j).x(), |
| 485 | m_cdcp->wireBackwardPosition(i, j).y(), |
| 486 | m_cdcp->wireBackwardPosition(i, j).z()); |
| 487 | TCWireTRGCDCWire* tw = new TCWireTRGCDCWire(nWires++, j, *layer, fp, bp, _clockFE); |
| 488 | if (_simulationMode & 1) |
| 489 | tw->_signal.clock(_clockTDC); |
| 490 | _wires.push_back(tw); |
| 491 | layer->push_back(tw); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | //...event Time... |
| 496 | _eventTime.push_back(new TCEventTimeTRGCDCEventTime(*this, _fileETF)); |
| 497 | _eventTime.back()->initialize(); |
| 498 | |
| 499 | //...Make TSF's... |
| 500 | const unsigned nWiresInTS[2] = {15, 11}; |
| 501 | const int shape[2][30] = { |
| 502 | { |
| 503 | -2, 0, // relative layer id, relative wire id |
| 504 | -1, -1, // assuming layer offset 0.0, not 0.5 |
| 505 | -1, 0, |
| 506 | 0, -1, |
| 507 | 0, 0, |
| 508 | 0, 1, |
| 509 | 1, -2, |
| 510 | 1, -1, |
| 511 | 1, 0, |
| 512 | 1, 1, |
| 513 | 2, -2, |
| 514 | 2, -1, |
| 515 | 2, 0, |
| 516 | 2, 1, |
| 517 | 2, 2 |
| 518 | //-2, 0, // relative layer id, relative wire id |
| 519 | //-1, 0, // assuming layer offset 0.5, not 0.0 |
| 520 | //-1, 1, |
| 521 | //0, -1, |
| 522 | //0, 0, |
| 523 | //0, 1, |
| 524 | //1, -1, |
| 525 | //1, -0, |
| 526 | //1, 1, |
| 527 | //1, 2, |
| 528 | //2, -2, |
| 529 | //2, -1, |
| 530 | //2, 0, |
| 531 | //2, 1, |
| 532 | //2, 2 |
| 533 | }, |
| 534 | { |
| 535 | -2, -1, |
| 536 | -2, 0, |
| 537 | -2, 1, |
| 538 | -1, -1, |
| 539 | -1, 0, |
| 540 | 0, 0, |
| 541 | 1, -1, |
| 542 | 1, 0, |
| 543 | 2, -1, |
| 544 | 2, 0, |
| 545 | 2, 1, |
| 546 | 0, 0, |
| 547 | 0, 0, |
| 548 | 0, 0, |
| 549 | 0, 0 |
| 550 | } |
| 551 | }; |
| 552 | const int layerOffset[2] = {5, 2}; |
| 553 | unsigned id = 0; |
| 554 | unsigned idTS = 0; |
| 555 | for (unsigned i = 0; i < nSuperLayers(); i++) { |
| 556 | unsigned tsType = 0; |
| 557 | if (i) |
| 558 | tsType = 1; |
| 559 | |
| 560 | // const unsigned nLayers = _superLayers[i]->size(); //'nLayers' shadows a previous local |
| 561 | // if (nLayers < 5) { |
| 562 | if (_superLayers[i]->size() < 5) { |
| 563 | cout << "TRGCDC !!! can not create TS because " |
| 564 | << "#layers is less than 5 in super layer " << i |
| 565 | << endl; |
| 566 | continue; |
| 567 | } |
| 568 | |
| 569 | //...TS layer... w is a central wire |
| 570 | const TCCellTRGCDCCell& ww = *(*_superLayers[i])[layerOffset[tsType]]->front(); |
| 571 | TRGCDCLayer* layer = new TRGCDCLayer(id++, ww); |
| 572 | _tsLayers.push_back(layer); |
| 573 | |
| 574 | //...Loop over all wires in a central wire layer... |
| 575 | const unsigned nWiresInLayer = ww.layer().nCells(); |
| 576 | for (unsigned j = 0; j < nWiresInLayer; j++) { |
| 577 | const TCWireTRGCDCWire& w = |
| 578 | *(TCWireTRGCDCWire*)(*(*_superLayers[i])[layerOffset[tsType]])[j]; |
| 579 | |
| 580 | const unsigned localId = w.localId(); |
| 581 | const unsigned layerId = w.layerId(); |
| 582 | vector<const TCWireTRGCDCWire*> cells; |
| 583 | |
| 584 | for (unsigned k = 0; k < nWiresInTS[tsType]; k++) { |
| 585 | const unsigned laid = layerId + shape[tsType][k * 2]; |
| 586 | const unsigned loid = localId + shape[tsType][k * 2 + 1]; |
| 587 | |
| 588 | const TCWireTRGCDCWire* c = wire(laid, loid); |
| 589 | if (! c) |
| 590 | cout << "TRGCDC !!! no such a wire for TS : " |
| 591 | << "layer id=" << laid << ", local id=" << loid |
| 592 | << endl; |
| 593 | |
| 594 | cells.push_back(c); |
| 595 | } |
| 596 | |
| 597 | TRGCDCSegment* ts; |
| 598 | if (w.superLayerId()) { |
| 599 | ts = new TRGCDCSegment(idTS++, |
| 600 | *layer, |
| 601 | w, |
| 602 | _clockD, |
| 603 | _outerTSLUTFilename, |
| 604 | cells); |
| 605 | } else { |
| 606 | ts = new TRGCDCSegment(idTS++, |
| 607 | *layer, |
| 608 | w, |
| 609 | _clockD, |
| 610 | _innerTSLUTFilename, |
| 611 | cells); |
| 612 | } |
| 613 | ts->initialize(); |
| 614 | |
| 615 | //...Store it... |
| 616 | _tss.push_back(ts); |
| 617 | _tsSL[i].push_back(ts); |
| 618 | layer->push_back(ts); |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | //...Fill caches... |
| 623 | if (_width) delete [] _width; |
| 624 | if (_r) delete [] _r; |
| 625 | if (_r2) delete [] _r2; |
| 626 | _width = new float[nSuperLayers()]; |
| 627 | _r = new float[nSuperLayers() + 1]; |
| 628 | _r2 = new float[nSuperLayers() + 1]; |
| 629 | for (unsigned i = 0; i < nSuperLayers(); i++) { |
| 630 | const vector<TRGCDCLayer*>& slayer = *_superLayers[i]; |
| 631 | _width[i] = M_PI3.14159265358979323846 * 2 / float(slayer.back()->nCells()); |
| 632 | _r[i] = slayer[0]->innerRadius(); |
| 633 | _r2[i] = _r[i] * _r[i]; |
| 634 | if (i == (nSuperLayers() - 1)) { |
| 635 | _r[i + 1] = slayer.back()->outerRadius(); |
| 636 | _r2[i + 1] = _r[i + 1] * _r[i + 1]; |
| 637 | } |
| 638 | |
| 639 | if (TRGDebug::level() > 9) { |
| 640 | const TCCellTRGCDCCell& wi = *slayer[0]->front(); |
| 641 | const unsigned layerId = wi.layerId(); |
| 642 | cout << layerId << "," << m_cdcp->senseWireR(layerId) << "," |
| 643 | << m_cdcp->fieldWireR(layerId) << endl; |
| 644 | cout << " super layer " << i << " radius=" << _r[i] |
| 645 | << "(r^2=" << _r2[i] << ")" << endl; |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | //...Track Segment Finder... |
| 650 | _tsFinder = new TSFinderTRGCDCTrackSegmentFinder(*this, _fileTSF, _fLogicLUTTSF); |
| 651 | |
| 652 | //...Perfect 2D Finder... |
| 653 | _pFinder = new TCPFinderTRGCDCPerfectFinder("Perfect2DFinder", *this); |
| 654 | |
| 655 | //...Perfect 3D Finder... |
| 656 | _p3DFinder = 0; |
| 657 | |
| 658 | //...Hough 2D Finder... |
| 659 | _hFinder = new TCHFinderTRGCDCHoughFinder("HoughFinder", |
| 660 | *this, |
| 661 | houghFinderPeakMin, |
| 662 | houghMappingFilePlus, |
| 663 | houghMappingFileMinus, |
| 664 | houghDoit); |
| 665 | |
| 666 | //...Hough 3D Finder... |
| 667 | _h3DFinder = new TCH3DFinderTRGCDCHough3DFinder(*this, _fileHough3D, _finder3DMode); |
| 668 | |
| 669 | //...3D fitter... |
| 670 | map<string, bool> flags = { |
| 671 | {"fLRLUT", _fLRLUT}, |
| 672 | {"fmcLR", _fFitter3Dsmclr}, |
| 673 | {"f2DFit", _fFitter3Ds2DFit}, |
| 674 | {"f2DFitDrift", _fFitter3Ds2DFitDrift}, |
| 675 | {"fRootFile", _fileFitter3D}, |
| 676 | {"fXtSimple", _fXtSimpleFitter3D} |
| 677 | }; |
| 678 | _fitter3D = new TCFitter3DTRGCDCFitter3D("Fitter3D", |
| 679 | _rootFitter3DFilename, |
| 680 | *this, |
| 681 | flags); |
| 682 | _fitter3D->initialize(); |
| 683 | |
| 684 | //...For module simulation (Front-end)... |
| 685 | configure(); |
| 686 | |
| 687 | //...Initialize root file... |
| 688 | if (_makeRootFile) { |
| 689 | m_file = new TFile((char*)_rootTRGCDCFilename.c_str(), "RECREATE"); |
| 690 | //m_file = new TFile("TRGCDC.root", "RECREATE"); |
| 691 | m_tree = new TTree("m_tree", "tree"); |
| 692 | m_treeAllTracks = new TTree("m_treeAllTracks", "treeAllTracks"); |
| 693 | |
| 694 | m_fitParameters = new TClonesArray("TVectorD"); |
| 695 | m_mcParameters = new TClonesArray("TVectorD"); |
| 696 | m_mcTrack4Vector = new TClonesArray("TLorentzVector"); |
| 697 | m_mcTrackVertexVector = new TClonesArray("TVector3"); |
| 698 | m_mcTrackStatus = new TClonesArray("TVectorD"); |
| 699 | // m_parameters2D = new TClonesArray("TVectorD"); |
| 700 | |
| 701 | m_tree->Branch("fitParameters", &m_fitParameters, 32000, 0); |
| 702 | m_tree->Branch("mcParameters", &m_mcParameters, 32000, 0); |
| 703 | m_treeAllTracks->Branch("mcTrack4Vector", &m_mcTrack4Vector, 32000, 0); |
| 704 | m_treeAllTracks->Branch("mcTrackVertexVector", &m_mcTrackVertexVector, 32000, 0); |
| 705 | m_treeAllTracks->Branch("mcTrackStatus", &m_mcTrackStatus, 32000, 0); |
| 706 | |
| 707 | m_evtTime = new TClonesArray("TVectorD"); |
| 708 | m_treeAllTracks->Branch("evtTime", &m_evtTime, 32000, 0); |
| 709 | |
| 710 | _tree2D = new TTree("tree2D", "2D Tracks"); |
| 711 | _tracks2D = new TClonesArray("TVectorD"); |
| 712 | _tree2D->Branch("track parameters", & _tracks2D, 32000, 0); |
| 713 | |
| 714 | //...Initialize firmware ROOT input |
| 715 | //m_minCDCTdc = 9999; |
| 716 | //m_maxCDCTdc = 0; |
| 717 | //m_minTRGTdc = 9999; |
| 718 | //m_maxTRGTdc = 0; |
| 719 | |
| 720 | m_treeROOTInput = new TTree("m_treeROOTInput", "treeRootInput"); |
| 721 | //m_CDCTRGTimeMatch = new TClonesArray("TVectorD"); |
| 722 | m_rootCDCHitInformation = new TClonesArray("TVectorD"); |
| 723 | m_rootTRGHitInformation = new TClonesArray("TVectorD"); |
| 724 | m_rootTRGRawInformation = new TClonesArray("TObjString"); |
| 725 | //m_treeROOTInput->Branch("CDCTRGTimeMatch", &m_CDCTRGTimeMatch,32000,0); |
| 726 | m_treeROOTInput->Branch("rootCDCHitInformation", &m_rootCDCHitInformation, 32000, 0); |
| 727 | m_treeROOTInput->Branch("rootTRGHitInformation", &m_rootTRGHitInformation, 32000, 0); |
| 728 | m_treeROOTInput->Branch("rootTRGRawInformation", &m_rootTRGRawInformation, 32000, 0); |
| 729 | } |
| 730 | |
| 731 | TRGDebug::leaveStage("TRGCDC initialize"); |
| 732 | } |
| 733 | |
| 734 | void |
| 735 | TRGCDC::terminate(void) |
| 736 | { |
| 737 | TRGDebug::enterStage("TRGCDC terminate"); |
| 738 | |
| 739 | if (_tsFinder) { |
| 740 | _tsFinder->terminate(); |
| 741 | } |
| 742 | if (_eventTime.back()) { |
| 743 | _eventTime.back()->terminate(); |
| 744 | } |
| 745 | if (_fitter3D) { |
| 746 | _fitter3D->terminate(); |
| 747 | } |
| 748 | if (_hFinder) { |
| 749 | _hFinder->terminate(); |
| 750 | } |
| 751 | if (_h3DFinder) { |
| 752 | _h3DFinder->terminate(); |
| 753 | } |
| 754 | if (_makeRootFile) { |
| 755 | m_file->Write(); |
| 756 | m_file->Close(); |
| 757 | } |
| 758 | |
| 759 | TRGDebug::leaveStage("TRGCDC terminate"); |
| 760 | } |
| 761 | |
| 762 | void |
| 763 | TRGCDC::dump(const string& msg) const |
| 764 | { |
| 765 | TRGDebug::enterStage("TRGCDC dump"); |
| 766 | |
| 767 | if (msg.find("name") != string::npos || |
| 768 | msg.find("version") != string::npos || |
| 769 | msg.find("detail") != string::npos || |
| 770 | msg == "") { |
| 771 | cout << name() << "(CDC version=" << versionCDC() << ", " |
| 772 | << version() << ") "; |
| 773 | } |
| 774 | if (msg.find("detail") != string::npos || |
| 775 | msg.find("state") != string::npos) { |
| 776 | cout << "Debug Level=" << _debugLevel; |
| 777 | } |
| 778 | cout << endl; |
| 779 | |
| 780 | string tab(" "); |
| 781 | |
| 782 | if (msg == "" || msg.find("geometry") != string::npos) { |
| 783 | //...Get information..." |
| 784 | unsigned nLayer = _layers.size(); |
| 785 | cout << " version : " << version() << endl; |
| 786 | cout << " cdc version: " << versionCDC() << endl; |
| 787 | cout << " # of wires : " << _wires.size() << endl; |
| 788 | cout << " # of layers: " << nLayer << endl; |
| 789 | cout << " super layer information" << endl; |
| 790 | cout << " # of super layers() = " |
| 791 | << nSuperLayers() << endl; |
| 792 | cout << " # of Axial super layers = " |
| 793 | << nAxialSuperLayers() << endl; |
| 794 | cout << " # of Stereo super layers = " |
| 795 | << nStereoSuperLayers() << endl; |
| 796 | |
| 797 | if (msg.find("superLayers") != string::npos) { |
| 798 | cout << " super layer detail" << endl; |
| 799 | cout << " id #layers (stereo type)" << endl; |
| 800 | for (unsigned i = 0; i < nSuperLayers(); ++i) { |
| 801 | const unsigned n = _superLayers[i]->size(); |
| 802 | cout << " " << i << " " << n << " ("; |
| 803 | for (unsigned j = 0; j < n; j++) { |
| 804 | cout << (* _superLayers[i])[0]->stereoType(); |
| 805 | } |
| 806 | cout << ")" << endl; |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | cout << " layer information" << endl; |
| 811 | cout << " # of Axial layers = " |
| 812 | << nAxialLayers() << endl; |
| 813 | cout << " # of Stereo layers = " |
| 814 | << nStereoLayers() << endl; |
| 815 | |
| 816 | if (msg.find("layers") != string::npos) { |
| 817 | cout << " layer detail" << endl; |
| 818 | cout << " id type sId #wires lId asId assId" |
| 819 | << endl; |
| 820 | for (unsigned int i = 0; i < nLayers(); ++i) { |
| 821 | const TRGCDCLayer& l = *_layers[i]; |
| 822 | cout << " " << i |
| 823 | << " " << l.stereoType() |
| 824 | << " " << l.superLayerId() |
| 825 | << " " << l.nCells() |
| 826 | << " " << l.localLayerId() |
| 827 | << " " << l.axialStereoLayerId() |
| 828 | << " " << l.axialStereoSuperLayerId() |
| 829 | << endl; |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | if (msg.find("wires") != string::npos) { |
| 834 | cout << " wire information" << endl; |
| 835 | for (unsigned i = 0; i < nWires(); i++) |
| 836 | (_wires[i])->dump("neighbor", tab); |
| 837 | } |
| 838 | |
| 839 | return; |
| 840 | } |
| 841 | if (msg.find("hits") != string::npos) { |
| 842 | cout << " hits : " << _hits.size() << endl; |
| 843 | for (unsigned i = 0; i < (unsigned) _hits.size(); i++) |
| 844 | _hits[i]->dump("mc drift", tab); |
| 845 | } |
| 846 | if (msg.find("axialHits") != string::npos) { |
| 847 | cout << " hits : " << _axialHits.size() << endl; |
| 848 | for (unsigned i = 0; i < (unsigned) _axialHits.size(); i++) |
| 849 | _axialHits[i]->dump("mc drift", tab); |
| 850 | } |
| 851 | if (msg.find("stereoHits") != string::npos) { |
| 852 | cout << " hits : " << _stereoHits.size() << endl; |
| 853 | for (unsigned i = 0; i < (unsigned) _stereoHits.size(); i++) |
| 854 | _stereoHits[i]->dump("mc drift", tab); |
| 855 | } |
| 856 | if (msg.find("trgWireHits") != string::npos) { |
| 857 | const string dumpOption = "trigger detail"; |
| 858 | cout << " wire hits" << endl; |
| 859 | for (unsigned i = 0; i < nWires(); i++) { |
| 860 | const TCWireTRGCDCWire& w = *wire(i); |
| 861 | if (w.signal().active()) |
| 862 | w.dump(dumpOption, TRGDebug::tab(4)); |
| 863 | } |
| 864 | } |
| 865 | if (msg.find("trgWireCentralHits") != string::npos) { |
| 866 | const string dumpOption = "trigger detail"; |
| 867 | cout << " wire hits" << endl; |
| 868 | for (unsigned i = 0; i < nSegments(); i++) { |
| 869 | const TCSegmentTRGCDCSegment& s = segment(i); |
| 870 | if (s.wires()[5]->signal().active()) |
| 871 | s.wires()[5]->dump(dumpOption, TRGDebug::tab(4)); |
| 872 | } |
| 873 | } |
| 874 | if (msg.find("trgTSHits") != string::npos) { |
| 875 | const string dumpOption = "trigger detail"; |
| 876 | cout << " TS hits" << endl; |
| 877 | for (unsigned i = 0; i < nSegments(); i++) { |
| 878 | const TCSegmentTRGCDCSegment& s = segment(i); |
| 879 | if (s.signal().active()) |
| 880 | s.dump(dumpOption, TRGDebug::tab(4)); |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | TRGDebug::leaveStage("TRGCDC dump"); |
| 885 | } |
| 886 | |
| 887 | const TCWireTRGCDCWire* |
| 888 | TRGCDC::wire(unsigned id) const |
| 889 | { |
| 890 | if (id < nWires()) |
| 891 | return _wires[id]; |
| 892 | return 0; |
| 893 | } |
| 894 | |
| 895 | const TCWireTRGCDCWire* |
| 896 | TRGCDC::wire(unsigned layerId, int localId) const |
| 897 | { |
| 898 | if (layerId < nLayers()) |
| 899 | return (TCWireTRGCDCWire*) & _layers[layerId]->cell(localId); |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | // const TCWire * |
| 904 | // TRGCDC::wire(const HepGeom::Point3D<double> & p) const { |
| 905 | // float r = p.mag(); |
| 906 | // float phi = p.phi(); |
| 907 | // return wire(r, phi); |
| 908 | // } |
| 909 | |
| 910 | const TCWireTRGCDCWire* |
| 911 | TRGCDC::wire(float, float) const |
| 912 | { |
| 913 | //...Not implemented yet... |
| 914 | return _wires[0]; |
| 915 | |
| 916 | // // cout << "r,phi = " << r << "," << p << endl; |
| 917 | |
| 918 | // // unsigned id = 25; |
| 919 | // // bool ok = false; |
| 920 | // // const TRGCDCLayer * l; |
| 921 | // // while (! ok) { |
| 922 | // // l = layer(id); |
| 923 | // // if (! l) return 0; |
| 924 | |
| 925 | // // const geocdc_layer * geo = l->geocdc(); |
| 926 | // // if (geo->m_r + geo->m_rcsiz2 < r) ++id; |
| 927 | // // else if (geo->m_r - geo->m_rcsiz1 > r) --id; |
| 928 | // // else ok = true; |
| 929 | // // } |
| 930 | // // float dPhi = 2. * M_PI / float(l->nCells()); |
| 931 | // // if (l->geocdc()->m_offset > 0.) p -= dPhi / 2.; |
| 932 | // // unsigned localId = unsigned(phi(p) / dPhi); |
| 933 | // // return l->wire(localId); |
| 934 | // } |
| 935 | } |
| 936 | |
| 937 | void |
| 938 | TRGCDC::clear(void) |
| 939 | { |
| 940 | TRGDebug::enterStage("TRGCDC clear"); |
| 941 | |
| 942 | TCWHitTRGCDCWireHit::removeAll(); |
| 943 | TCSHitTRGCDCSegmentHit::removeAll(); |
| 944 | TCLinkTRGCDCLink::removeAll(); |
| 945 | |
| 946 | // for (unsigned i = 0; i < _hits.size(); i++) |
| 947 | // delete _hits[i]; |
| 948 | for (unsigned i = 0; i < _hitsMC.size(); i++) |
| 949 | delete _hitsMC[i]; |
| 950 | // for (unsigned i = 0; i < _badHits.size(); i++) |
| 951 | // delete _badHits[i]; |
| 952 | // for (unsigned i = 0; i < _segmentHits.size(); i++) |
| 953 | // delete _segmentHits[i]; |
| 954 | |
| 955 | for (unsigned i = 0; i < _wires.size(); i++) { |
| 956 | TCWireTRGCDCWire* w = _wires[i]; |
| 957 | w->clear(); |
| 958 | } |
| 959 | for (unsigned i = 0; i < _tss.size(); i++) { |
| 960 | TCSegmentTRGCDCSegment* s = _tss[i]; |
| 961 | s->clear(); |
| 962 | } |
| 963 | _hitWires.clear(); |
| 964 | _hits.clear(); |
| 965 | _axialHits.clear(); |
| 966 | _stereoHits.clear(); |
| 967 | _badHits.clear(); |
| 968 | _hitsMC.clear(); |
| 969 | _segmentHits.clear(); |
| 970 | for (unsigned i = 0; i < 9; i++) |
| 971 | _segmentHitsSL[i].clear(); |
| 972 | |
| 973 | TRGDebug::leaveStage("TRGCDC clear"); |
| 974 | } |
| 975 | |
| 976 | void |
| 977 | TRGCDC::fastClear(void) {} |
| 978 | |
| 979 | void |
| 980 | TRGCDC::update() |
| 981 | { |
| 982 | _trackList2D.clear(); |
| 983 | _trackList2DFitted.clear(); |
| 984 | _trackList3D.clear(); |
| 985 | |
| 986 | TRGDebug::enterStage("TRGCDC update"); |
| 987 | |
| 988 | if (_trgCDCDataInputMode != 0) { |
| 989 | updateByData(_trgCDCDataInputMode); |
| 990 | } else { |
| 991 | |
| 992 | //...Clear old information... |
| 993 | // fastClear(); |
| 994 | clear(); |
| 995 | |
| 996 | //...CDCSimHit... |
| 997 | StoreArray<CDCSimHit> SimHits; |
| 998 | if (! SimHits) { |
| 999 | if (TRGDebug::level()) |
| 1000 | cout << "TRGCDC !!! can not access to CDCSimHits" << endl; |
| 1001 | TRGDebug::leaveStage("TRGCDC update"); |
| 1002 | return; |
| 1003 | } |
| 1004 | const unsigned n = SimHits.getEntries(); |
| 1005 | |
| 1006 | //...CDCHit... |
| 1007 | StoreArray<CDCHit> CDCHits(_cdchitCollectionName); |
| 1008 | if (! CDCHits) { |
| 1009 | if (TRGDebug::level()) |
| 1010 | cout << "TRGCDC !!! can not access to CDCHits" << endl; |
| 1011 | TRGDebug::leaveStage("TRGCDC update"); |
| 1012 | return; |
| 1013 | } |
| 1014 | const unsigned nHits = CDCHits.getEntries(); |
| 1015 | |
| 1016 | //...MCParticle... |
| 1017 | StoreArray<MCParticle> mcParticles; |
| 1018 | if (! mcParticles) { |
| 1019 | if (TRGDebug::level()) |
| 1020 | cout << "TRGCDC !!! can not access to MCParticles" << endl; |
| 1021 | TRGDebug::leaveStage("TRGCDC update"); |
| 1022 | return; |
| 1023 | } |
| 1024 | |
| 1025 | //...Relations... |
| 1026 | RelationArray rels(SimHits, CDCHits); |
| 1027 | const unsigned nRels = rels.getEntries(); |
| 1028 | RelationArray relsMC(mcParticles, CDCHits); |
| 1029 | const unsigned nRelsMC = relsMC.getEntries(); |
| 1030 | |
| 1031 | //...Loop over CDCHits... |
| 1032 | for (unsigned i = 0; i < nHits; i++) { |
| 1033 | const CDCHit& h = *CDCHits[i]; |
| 1034 | double tmp = gRandom->Uniform(0.0, 1.0) / (double(RAND_MAX2147483647)); |
| 1035 | if (tmp < _inefficiency) |
| 1036 | continue; |
| 1037 | |
| 1038 | // //...Check validity (skip broken channel)... |
| 1039 | // if (! (h->m_stat & CellHitFindingValid)) continue; |
| 1040 | |
| 1041 | //...Get CDCSimHit... This is expensive. Should be moved outside. |
| 1042 | unsigned iSimHit = 0; |
| 1043 | for (unsigned j = 0; j < nRels; j++) { |
| 1044 | const unsigned k = rels[j].getToIndices().size(); |
| 1045 | for (unsigned l = 0; l < k; l++) { |
| 1046 | if (rels[j].getToIndex(l) == i) |
| 1047 | iSimHit = rels[j].getFromIndex(); |
| 1048 | } |
| 1049 | |
| 1050 | if (TRGDebug::level()) |
| 1051 | if (k > 1) |
| 1052 | cout << "TRGCDC::update !!! CDCSimHit[" << iSimHit |
| 1053 | << "] has multiple CDCHit(" << k << " hits)" << endl; |
| 1054 | } |
| 1055 | |
| 1056 | //...Get MCParticle... This is expensive, again. |
| 1057 | // (Getting the first MCParticle only) |
| 1058 | unsigned iMCPart = 0; |
| 1059 | for (unsigned j = 0; j < nRelsMC; j++) { |
| 1060 | const unsigned k = relsMC[j].getToIndices().size(); |
| 1061 | for (unsigned l = 0; l < k; l++) { |
| 1062 | if (relsMC[j].getToIndex(l) == i) { |
| 1063 | iMCPart = relsMC[j].getFromIndex(); |
| 1064 | break; |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | if (TRGDebug::level()) |
| 1069 | if (k > 1) |
| 1070 | cout << "TRGCDC::update !!! MCParticle[" << iMCPart |
| 1071 | << "] has multiple CDCHit(" << k << " hits)" << endl; |
| 1072 | } |
| 1073 | |
| 1074 | //...Wire... |
| 1075 | int t_layerId; |
| 1076 | if (h.getISuperLayer() == 0) t_layerId = h.getILayer(); |
| 1077 | else t_layerId = h.getILayer() + 6 * h.getISuperLayer() + 2; |
| 1078 | const unsigned layerId = t_layerId; |
| 1079 | const unsigned wireId = h.getIWire(); |
| 1080 | const TCWireTRGCDCWire& w = * static_cast<const TCWireTRGCDCWire*>(wire(layerId, wireId)); |
| 1081 | |
| 1082 | //...TDC count... |
| 1083 | B2INFO("t0:" << m_cdcp->getT0(WireID(h.getID())) <<do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2:: LogConfig::c_Info, 0, "trg")) { { LogVariableStream varStream ; varStream << "t0:" << m_cdcp->getT0(WireID(h .getID())) << "binwidth:" << m_cdcp->getTdcBinWidth () << "tdc count:" << h.getTDCCount(); Belle2::LogSystem ::Instance().sendMessage(Belle2::LogMessage(Belle2::LogConfig ::c_Info, std::move(varStream), "trg", __PRETTY_FUNCTION__, "trg/cdc/src/TRGCDC.cc" , 1085, 0)); }; } } while(false) |
| 1084 | "binwidth:" << m_cdcp->getTdcBinWidth() <<do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2:: LogConfig::c_Info, 0, "trg")) { { LogVariableStream varStream ; varStream << "t0:" << m_cdcp->getT0(WireID(h .getID())) << "binwidth:" << m_cdcp->getTdcBinWidth () << "tdc count:" << h.getTDCCount(); Belle2::LogSystem ::Instance().sendMessage(Belle2::LogMessage(Belle2::LogConfig ::c_Info, std::move(varStream), "trg", __PRETTY_FUNCTION__, "trg/cdc/src/TRGCDC.cc" , 1085, 0)); }; } } while(false) |
| 1085 | "tdc count:" << h.getTDCCount())do { if (Belle2::LogSystem::Instance().isLevelEnabled(Belle2:: LogConfig::c_Info, 0, "trg")) { { LogVariableStream varStream ; varStream << "t0:" << m_cdcp->getT0(WireID(h .getID())) << "binwidth:" << m_cdcp->getTdcBinWidth () << "tdc count:" << h.getTDCCount(); Belle2::LogSystem ::Instance().sendMessage(Belle2::LogMessage(Belle2::LogConfig ::c_Info, std::move(varStream), "trg", __PRETTY_FUNCTION__, "trg/cdc/src/TRGCDC.cc" , 1085, 0)); }; } } while(false); |
| 1086 | const int tdcCount = floor(m_cdcp->getT0(WireID(h.getID())) / m_cdcp->getTdcBinWidth() |
| 1087 | - h.getTDCCount() + 0.5); |
| 1088 | |
| 1089 | //...Drift length from TDC... |
| 1090 | const float driftLength = tdcCount * m_cdcp->getTdcBinWidth() * m_cdcp->getNominalDriftV(); |
| 1091 | const float driftLengthError = 0.013; |
| 1092 | |
| 1093 | //...Trigger timing... |
| 1094 | TRGTime rise = TRGTime(tdcCount, true, _clockFE, w.name()); |
| 1095 | if (_simulationMode & 1) |
| 1096 | rise.clock(_clockTDC); |
| 1097 | TRGTime fall = rise; |
| 1098 | fall.shift(1).reverse(); |
| 1099 | if (_simulationMode & 1) |
| 1100 | w._signal |= TRGSignal(rise & fall); |
| 1101 | else |
| 1102 | w._signal |= (TRGSignal(rise & fall) & _firmwareSimulationWindow); |
| 1103 | w._signal.name(w.name()); |
| 1104 | |
| 1105 | //...Left/right... |
| 1106 | const int LRflag = SimHits[iSimHit]->getPosFlag(); |
| 1107 | |
| 1108 | //...TCWireHit... |
| 1109 | TCWHitTRGCDCWireHit* hit = new TCWHitTRGCDCWireHit(w, |
| 1110 | i, |
| 1111 | iSimHit, |
| 1112 | iMCPart, |
| 1113 | driftLength, |
| 1114 | driftLengthError, |
| 1115 | driftLength, |
| 1116 | driftLengthError, |
| 1117 | LRflag, |
| 1118 | 1); |
| 1119 | hit->state(CellHitFindingValid4194304 | CellHitFittingValid0x40000000); |
| 1120 | |
| 1121 | //...Store a hit... |
| 1122 | if (!(*_layers[layerId])[wireId]->hit()) |
| 1123 | ((TCWireTRGCDCWire*)(*_layers[layerId])[wireId])->hit(hit); |
| 1124 | _hits.push_back(hit); |
| 1125 | if (w.axial()) _axialHits.push_back(hit); |
| 1126 | else _stereoHits.push_back(hit); |
| 1127 | |
| 1128 | //...Debug... |
| 1129 | if (TRGDebug::level() > 2) { |
| 1130 | w._signal.dump("", TRGDebug::tab()); |
| 1131 | cout << TRGDebug::tab(4) << "CDCHit TDC count=" |
| 1132 | << h.getTDCCount() << std::endl; |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | //...Track segment... This part is moved to ::simulate(). |
| 1137 | |
| 1138 | //...Hit classification... |
| 1139 | // _hits.sort(TCWHit::sortByWireId); |
| 1140 | classification(); |
| 1141 | |
| 1142 | if (TRGDebug::level()) { |
| 1143 | cout << TRGDebug::tab() << "#CDCSimHit=" << n << ",#CDCHit=" |
| 1144 | << nHits << endl; |
| 1145 | } |
| 1146 | |
| 1147 | if (TRGDebug::level() > 2) { |
| 1148 | // StoreArray<CDCSimHit> simHits("CDCSimHits"); //TODO variable is not used, is it ok? |
| 1149 | _clock.dump("detail", TRGDebug::tab()); |
| 1150 | _clockFE.dump("detail", TRGDebug::tab()); |
| 1151 | if (TRGDebug::level() > 10) { |
| 1152 | for (unsigned i = 0; i < _hits.size(); i++) { |
| 1153 | const TCWHitTRGCDCWireHit& h = *_hits[i]; |
| 1154 | h.dump("detail", TRGDebug::tab(4)); |
| 1155 | } |
| 1156 | } else { |
| 1157 | //unsigned nh = 10; //TODO these two lines have no impact |
| 1158 | //if (nh > _hits.size()) nh = _hits.size(); |
| 1159 | cout << TRGDebug::tab() << "Dump of the first " << n |
| 1160 | << " hits of a wire" << endl; |
| 1161 | for (unsigned i = 0; i < n; i++) { |
| 1162 | const TCWHitTRGCDCWireHit& h = *_hits[i]; |
| 1163 | h.dump("detail", TRGDebug::tab(4)); |
| 1164 | } |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | } |
| 1169 | |
| 1170 | TRGDebug::leaveStage("TRGCDC update"); |
| 1171 | } |
| 1172 | |
| 1173 | |
| 1174 | void |
| 1175 | TRGCDC::updateByData(int inputMode) |
| 1176 | { |
| 1177 | TRGDebug::enterStage("TRGCDC updateByData"); |
| 1178 | |
| 1179 | //...Clear old information... |
| 1180 | clear(); |
| 1181 | |
| 1182 | // There is a 1 window difference between slow control parameter and actual data. |
| 1183 | // For SPrint-8 data |
| 1184 | int cdcDelay = 101; |
| 1185 | int nCDCWindows = 28 + 1; |
| 1186 | // For Fuji hall data |
| 1187 | //int cdcDelay = 87; |
| 1188 | //int nCDCWindows = 32+1; |
| 1189 | // For Fuji hall matching data |
| 1190 | //int cdcDelay = 79; |
| 1191 | //int nCDCWindows = 47+1; |
| 1192 | |
| 1193 | // For TRG parameters |
| 1194 | unsigned nTRGWindows = 48; |
| 1195 | int nTrgBitsInWindow = 352; |
| 1196 | |
| 1197 | vector<string> trgInformations; |
| 1198 | |
| 1199 | // ##### Store data into a common binary format ##### |
| 1200 | // inBinaryData[iBoard][iWord] |
| 1201 | vector<vector<unsigned> > inBinaryData; |
| 1202 | // Get data using Belle2Link |
| 1203 | if (inputMode == 1) { |
| 1204 | |
| 1205 | int nCdcBitsInWindow = 1536; |
| 1206 | //[FIXME] Getting data from ROOT file is fixed to 2 CDC FE, 1 TRG board. |
| 1207 | // Data should be in CDCFE0, CDCFE1, TRG sequence. |
| 1208 | |
| 1209 | // For Fuji data |
| 1210 | // Get data from root file. |
| 1211 | StoreArray<RawDataBlock> raw_datablkarray; |
| 1212 | // One block is one event. Take only first block = event. |
| 1213 | // Copper board 0 is for two CDC FE and one TRG. |
| 1214 | int iBlock = 0; |
| 1215 | int iCopper = 0; |
| 1216 | //cout<<"Number of blocks: "<<raw_cdcarray.getEntries()<<endl; |
| 1217 | //cout<<"Number of Copper: "<<raw_cdcarray[iBlock]->GetNumEntries()<<endl; |
| 1218 | int* temp_buf = raw_datablkarray[ iBlock ]->GetBuffer(iCopper); |
| 1219 | int nwords = raw_datablkarray[ iBlock ]->GetBlockNwords(iCopper); |
| 1220 | int malloc_flag = 0; |
| 1221 | int num_nodes = 1; |
| 1222 | int num_events = 1; |
| 1223 | RawCOPPER* raw_copper; |
| 1224 | RawCOPPER raw_copper_buf; |
| 1225 | raw_copper_buf.SetBuffer(temp_buf, nwords, malloc_flag, num_nodes, num_events); |
| 1226 | raw_copper = &raw_copper_buf; |
| 1227 | |
| 1228 | //// For SPring-8 data |
| 1229 | //StoreArray<RawCDC> raw_cdcarray; |
| 1230 | //int iBlock = 0; |
| 1231 | //int iCopper = 0; |
| 1232 | //RawCOPPER* raw_copper = raw_cdcarray[iBlock]; |
| 1233 | |
| 1234 | //// Print the data |
| 1235 | //printf("*******Start of BODY**********\n"); |
| 1236 | //printf("\n%.8d : ", 0); |
| 1237 | //for (int j = 0; j < raw_copper->GetBlockNwords(iCopper); j++) { |
| 1238 | // printf("0x%.8x ", (raw_copper->GetBuffer(iCopper))[ j ]); |
| 1239 | // if ((j + 1) % 10 == 0) { |
| 1240 | // printf("\n%.8d : ", j + 1); |
| 1241 | // } |
| 1242 | //} |
| 1243 | //printf("*******End of BODY**********\n"); |
| 1244 | |
| 1245 | // Number of words for data |
| 1246 | int daqHeader = 32; |
| 1247 | int cdcHeader = 5; |
| 1248 | int cdcTrailer = 2; |
| 1249 | int trgHeader = 1; |
| 1250 | //int trgTrailer = 1; |
| 1251 | // 3 for event data. -1 for lost word in DAQ. Each window is 48 words. |
| 1252 | int widthCDCFEData = 3 - 1 + nCdcBitsInWindow / 32 * nCDCWindows; |
| 1253 | int widthTRGData = nTrgBitsInWindow / 32 * nTRGWindows; |
| 1254 | |
| 1255 | // Remove headers and trailer from data. |
| 1256 | // rawBinaryData[iBoard][iWord] |
| 1257 | // CDCFE0, CDCFE1, TSF sequence. |
| 1258 | vector<vector<unsigned> > rawBinaryData; |
| 1259 | for (int iFe = 0; iFe < 2; iFe++) { |
| 1260 | int startCDCData = daqHeader + cdcHeader + (iFe * (widthCDCFEData + cdcTrailer + cdcHeader)) + 1; |
| 1261 | // 1 is due to missing data. |
| 1262 | vector<unsigned> t_feData(widthCDCFEData + 1); |
| 1263 | // Loop over all the words for CDC FE data |
| 1264 | for (int iWord = 0; iWord < widthCDCFEData; iWord++) { |
| 1265 | t_feData[iWord] = (raw_copper->GetBuffer(iCopper))[iWord + startCDCData]; |
| 1266 | } |
| 1267 | // Fill with 0 for last missing data |
| 1268 | t_feData[widthCDCFEData] = 0; |
| 1269 | rawBinaryData.push_back(t_feData); |
| 1270 | } |
| 1271 | vector<unsigned> t_trgData(widthTRGData); |
| 1272 | // Loop over all the words for TRG data |
| 1273 | int startTRGData = daqHeader + 2 * (cdcHeader + widthCDCFEData + cdcTrailer) + trgHeader + 1; |
| 1274 | for (int iWord = 0; iWord < widthTRGData; iWord++) { |
| 1275 | t_trgData[iWord] = (raw_copper->GetBuffer(iCopper))[iWord + startTRGData]; |
| 1276 | } |
| 1277 | rawBinaryData.push_back(t_trgData); |
| 1278 | //// Print data of rawBinaryData |
| 1279 | //for(unsigned iBoard=0; iBoard<rawBinaryData.size(); iBoard++){ |
| 1280 | // cout<<"Board"<<iBoard<<endl; |
| 1281 | // for(unsigned iWord=0; iWord<rawBinaryData[iBoard].size(); iWord++){ |
| 1282 | // cout<<setfill('0')<<setw(8)<<hex<<rawBinaryData[iBoard][iWord]; |
| 1283 | // } |
| 1284 | // cout<<dec<<endl; |
| 1285 | //} |
| 1286 | |
| 1287 | // Shift all binary data by 8 bits to the right for two CDC FE data |
| 1288 | for (unsigned iBoard = 0; iBoard < 2; iBoard++) { |
| 1289 | unsigned t_buf = 0; |
| 1290 | // 1 is due to missing data |
| 1291 | vector<unsigned> t_feData(widthCDCFEData + 1); |
| 1292 | for (unsigned iWord = 0; iWord < rawBinaryData[iBoard].size(); iWord++) { |
| 1293 | unsigned t_value = t_buf + (rawBinaryData[iBoard][iWord] >> 8); |
| 1294 | t_buf = rawBinaryData[iBoard][iWord] << 24; |
| 1295 | t_feData[iWord] = t_value; |
| 1296 | } |
| 1297 | inBinaryData.push_back(t_feData); |
| 1298 | } |
| 1299 | inBinaryData.push_back(rawBinaryData[2]); |
| 1300 | //// Print data of inBinaryData |
| 1301 | //for(unsigned iBoard=0; iBoard<inBinaryData.size(); iBoard++){ |
| 1302 | // cout<<"Board"<<iBoard<<endl; |
| 1303 | // for(unsigned iWord=0; iWord<inBinaryData[iBoard].size(); iWord++){ |
| 1304 | // cout<<setfill('0')<<setw(8)<<hex<<inBinaryData[iBoard][iWord]; |
| 1305 | // } |
| 1306 | // cout<<dec<<endl; |
| 1307 | //} |
| 1308 | } else if (inputMode == 2) { |
| 1309 | // get data from Belle2Link |
| 1310 | StoreArray<RawTRG> raw_trgarray; |
| 1311 | for (int i = 0; i < raw_trgarray.getEntries(); i++) { |
| 1312 | cout << "\n===== DataBlock(RawTRG) : Block # " << i << endl; |
| 1313 | for (int j = 0; j < raw_trgarray[ i ]->GetNumEntries(); j++) { |
| 1314 | RawCOPPER* raw_copper = raw_trgarray[ i ]; |
| 1315 | vector<vector<unsigned> > rawBinaryData; |
| 1316 | // Loop over 4 FINESSEs |
| 1317 | for (int iFinesse = 0; iFinesse < 4; iFinesse++) { |
| 1318 | int bufferNwords = raw_copper->GetDetectorNwords(j, iFinesse); |
| 1319 | if (bufferNwords > 0) { |
| 1320 | printf("===== Detector Buffer(FINESSE # %i) 0x%x words \n", iFinesse, bufferNwords); |
| 1321 | vector<unsigned> t_copperData(raw_copper->GetDetectorNwords(j, iFinesse)); |
| 1322 | // Loop over all the words for board data |
| 1323 | for (int iWord = 0; iWord < bufferNwords; iWord++) { |
| 1324 | t_copperData[iWord] = (raw_copper->GetDetectorBuffer(j, iFinesse))[iWord]; |
| 1325 | } |
| 1326 | rawBinaryData.push_back(t_copperData); |
| 1327 | inBinaryData.push_back(t_copperData); |
| 1328 | |
| 1329 | } |
| 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | //// Print data of inBinaryData |
| 1335 | //for(unsigned iBoard=0; iBoard<inBinaryData.size(); iBoard++){ |
| 1336 | // cout<<"Board"<<iBoard<<endl; |
| 1337 | // for(unsigned iWord=0; iWord<inBinaryData[iBoard].size(); iWord++){ |
| 1338 | // cout<<setfill('0')<<setw(8)<<hex<<inBinaryData[iBoard][iWord]; |
| 1339 | // } |
| 1340 | // cout<<dec<<endl; |
| 1341 | //} |
| 1342 | } else { |
| 1343 | cout << "[ERROR} TRGCDCDataInputMode is incorrect! No simulation will be done." << endl; |
| 1344 | return; |
| 1345 | } |
| 1346 | |
| 1347 | // #####Separate binary into meaningful data##### |
| 1348 | // CDC |
| 1349 | // cdcTrgTiming[iFE] |
| 1350 | vector<unsigned> cdcTrgTiming(2); |
| 1351 | for (unsigned iFe = 0; iFe < 2; iFe++) { |
| 1352 | cdcTrgTiming[iFe] = (inBinaryData[iFe][1]) >> 16; |
| 1353 | if (cdcTrgTiming[iFe] >= 32768) cout << "CDC trigger timing error. TDC is larger than 0x8000" << endl; |
| 1354 | } |
| 1355 | //// Print cdc trigger timing |
| 1356 | //for(unsigned iFe=0; ieE<2; iFe++){ |
| 1357 | // cout<<"FE"<<iFe<<" TRG Timing: "<<setfill('0')<<setw(8)<<hex<<cdcTrgTiming[0]<<dec<<endl; |
| 1358 | //} |
| 1359 | // [iHit] [0]: layerId, [1]: wireId, [2]: adc, [3]: tdc, [4]: FE trg timing |
| 1360 | vector<vector<unsigned>> hitCdcData; |
| 1361 | // Store information according to window,FE,Wire |
| 1362 | for (int iWindow = 0; iWindow < nCDCWindows; iWindow++) { |
| 1363 | for (int iFE = 0; iFE < 2; iFE++) { |
| 1364 | for (int iWire = 0; iWire < 48; iWire++) { |
| 1365 | unsigned t_adc; |
| 1366 | unsigned t_tdc; |
| 1367 | unsigned t_layerId = 3 * iFE + ((iWire / 8) % 3); |
| 1368 | unsigned t_wireId = 8 * (iWire / 24) + iWire % 8; |
| 1369 | // Take 16 bits according to wire. |
| 1370 | t_adc = ((inBinaryData[iFE][iWire / 2 + iWindow * 48 + 3] << (16 * (iWire % 2))) >> 16); |
| 1371 | t_tdc = ((inBinaryData[iFE][iWire / 2 + iWindow * 48 + 24 + 3] << (16 * (iWire % 2))) >> 16); |
| 1372 | if (t_tdc != 0) { |
| 1373 | if (t_tdc >= 32768) { |
| 1374 | // Calculate TDC. |
| 1375 | t_tdc -= 32768; |
| 1376 | // Round down and go back cdcDelay+nCDCWindows windows |
| 1377 | unsigned startTiming; |
| 1378 | if (unsigned(cdcTrgTiming[iFE] / 32) * 32 > (unsigned)(cdcDelay + nCDCWindows) * 32) { |
| 1379 | startTiming = unsigned(cdcTrgTiming[iFE] / 32) * 32 - (cdcDelay + nCDCWindows) * 32; |
| 1380 | } else { |
| 1381 | startTiming = unsigned(cdcTrgTiming[iFE] / 32) * 32 + 32768 - (cdcDelay + nCDCWindows) * 32; |
| 1382 | } |
| 1383 | if (t_tdc > startTiming) t_tdc -= startTiming; |
| 1384 | else t_tdc += 32768 - startTiming; |
| 1385 | // Fill data |
| 1386 | vector<unsigned> t_hitCdcData(5); |
| 1387 | t_hitCdcData[0] = t_layerId; |
| 1388 | t_hitCdcData[1] = t_wireId; |
| 1389 | t_hitCdcData[2] = t_adc; |
| 1390 | t_hitCdcData[3] = t_tdc; |
| 1391 | t_hitCdcData[4] = cdcTrgTiming[iFE]; |
| 1392 | hitCdcData.push_back(t_hitCdcData); |
| 1393 | } else { |
| 1394 | cout << "CDC TDC data error. TDC is smaller than 0x8000. " << hex << t_tdc << dec << endl; |
| 1395 | continue; |
| 1396 | } |
| 1397 | } // end tdc hit |
| 1398 | } // wire loop |
| 1399 | } // fe loop |
| 1400 | } // window loop |
| 1401 | //// Print hit information |
| 1402 | //for(unsigned iHit=0; iHit<hitCdcData.size(); iHit++){ |
| 1403 | // cout<<"["<<hitCdcData[iHit][0]<<"]["<<hitCdcData[iHit][1]<<"]: "<<hitCdcData[iHit][2]<<", "<<hitCdcData[iHit][3]<<endl; |
| 1404 | //} |
| 1405 | // TRG |
| 1406 | // Save data into string |
| 1407 | stringstream t_trgWindow; |
| 1408 | for (unsigned iWord = 0; iWord < inBinaryData[2].size(); iWord++) { |
| 1409 | t_trgWindow << setw(8) << setfill('0') << hex << inBinaryData[2][iWord]; |
| 1410 | if (iWord % 11 == 10) { |
| 1411 | trgInformations.push_back(t_trgWindow.str()); |
| 1412 | t_trgWindow.str(""); |
| 1413 | } |
| 1414 | } |
| 1415 | // Save data into hits |
| 1416 | // [iHit] [0]: layerId, [1]: wireId, [2]: window timing, [3]: priority timing |
| 1417 | // priority timing = -1 : No timing |
| 1418 | vector<vector<int> > hitTrgData; |
| 1419 | for (unsigned iWindow = 0; iWindow < nTRGWindows; iWindow++) { |
| 1420 | // Change binary into TRGState |
| 1421 | vector<unsigned> t_trgData(inBinaryData[2].begin() + 11 * iWindow, inBinaryData[2].begin() + 11 * iWindow + 11); |
| 1422 | TRGState t_trgState(t_trgData, 1); |
| 1423 | TRGState t_mergerState = t_trgState.subset(96, 256); |
| 1424 | TRGState t_hitMap = t_mergerState.subset(0, 80); |
| 1425 | TRGState t_priorityMap = t_mergerState.subset(32, 16); |
| 1426 | TRGState t_secondPriorityMap = t_mergerState.subset(48, 16); |
| 1427 | TRGState t_secondHitFlag = t_mergerState.subset(208, 16); |
| 1428 | TRGState t_priorityTiming = t_mergerState.subset(80, 64); |
| 1429 | TRGState t_fastestTiming = t_mergerState.subset(144, 64); |
| 1430 | //cout<<"["<<iWindow<<"] HM: "<<t_hitMap<<endl; |
| 1431 | //cout<<"["<<iWindow<<"] PHM: "<<t_priorityMap<<endl; |
| 1432 | //cout<<"["<<iWindow<<"] SHM: "<<t_secondPriorityMap<<endl; |
| 1433 | //cout<<"["<<iWindow<<"] SPF: "<<t_secondHitFlag<<endl; |
| 1434 | //cout<<"["<<iWindow<<"] PT: "<<setfill('0')<<setw(16)<<hex<<(unsigned long long) (t_priorityTiming)<<dec<<endl; |
| 1435 | //cout<<"["<<iWindow<<"] FT: "<<setfill('0')<<setw(16)<<hex<<(unsigned long long) (t_fastestTiming)<<dec<<endl; |
| 1436 | for (unsigned iWire = 0; iWire < t_hitMap.size(); iWire++) { |
| 1437 | unsigned t_layerId = iWire / 16; |
| 1438 | unsigned t_wireId = iWire % 16; |
| 1439 | if (t_hitMap[iWire] == 1) { |
| 1440 | vector<int> t_hitTrgData(4); |
| 1441 | t_hitTrgData[0] = t_layerId; |
| 1442 | t_hitTrgData[1] = t_wireId; |
| 1443 | t_hitTrgData[2] = iWindow; |
| 1444 | // Calculate priority timing |
| 1445 | if (t_layerId == 2) { |
| 1446 | t_hitTrgData[3] = (unsigned)t_priorityTiming.subset(4 * t_wireId, 4); |
| 1447 | //cout<<"["<<t_layerId<<"]["<<t_wireId<<"]: "<<iWindow<<", "<<t_hitTrgData[3]<<endl; |
| 1448 | } else if (t_layerId == 3) { |
| 1449 | // [1] Priority hit, [0] secondaryLR |
| 1450 | TRGState t_leftInformation(2); |
| 1451 | TRGState t_rightInformation(2); |
| 1452 | TRGState t_priorityHits(2); |
| 1453 | TRGState t_secondaryLR(2); |
| 1454 | if (t_wireId != 15) { |
| 1455 | t_priorityHits = t_priorityMap.subset(t_wireId, 2); |
| 1456 | t_secondaryLR = t_secondHitFlag.subset(t_wireId, 2); |
| 1457 | t_leftInformation.set(1, t_priorityMap.subset(t_wireId + 1, 1)); |
| 1458 | t_leftInformation.set(0, t_secondHitFlag.subset(t_wireId + 1, 1)); |
| 1459 | t_rightInformation.set(1, t_priorityMap.subset(t_wireId, 1)); |
| 1460 | t_rightInformation.set(0, t_secondHitFlag.subset(t_wireId, 1)); |
| 1461 | } else { |
| 1462 | t_priorityHits.set(0, t_priorityMap.subset(t_wireId, 1)); |
| 1463 | t_priorityHits.set(1, 0); |
| 1464 | t_secondaryLR.set(0, t_secondHitFlag.subset(t_wireId, 1)); |
| 1465 | t_secondaryLR.set(1, 0); |
| 1466 | t_leftInformation.set(1, 1); |
| 1467 | t_leftInformation.set(0, 0); |
| 1468 | t_rightInformation.set(1, t_priorityMap.subset(t_wireId, 1)); |
| 1469 | t_rightInformation.set(0, t_secondHitFlag.subset(t_wireId, 1)); |
| 1470 | } |
| 1471 | //cout<<"["<<iWindow<<"]["<<t_layerId<<"]["<<t_wireId<<"] PriorityHits: "<<t_priorityHits<<endl; |
| 1472 | //cout<<"["<<iWindow<<"]["<<t_layerId<<"]["<<t_wireId<<"] SecondaryLR: "<<t_secondaryLR<<endl; |
| 1473 | //cout<<"["<<iWindow<<"]["<<t_layerId<<"]["<<t_wireId<<"] Combine0: "<<t_leftInformation<<endl; |
| 1474 | //cout<<"["<<iWindow<<"]["<<t_layerId<<"]["<<t_wireId<<"] Combine1: "<<t_rightInformation<<endl; |
| 1475 | int secondaryFlag = -1; |
| 1476 | if ((unsigned)t_leftInformation == (unsigned)TRGState("00", 0)) secondaryFlag = 0; |
| 1477 | if ((unsigned)t_leftInformation == (unsigned)TRGState("01", 0)) secondaryFlag = 1; |
| 1478 | //cout<<"["<<iWindow<<"]["<<t_layerId<<"]["<<t_wireId<<"] SecondaryFlag: "<<secondaryFlag<<" timing: "; |
| 1479 | if (secondaryFlag != -1) { |
| 1480 | if (t_wireId + (1 - secondaryFlag) < 16) { |
| 1481 | //int t_priorityTiming = strtol(priorityTiming.substr(15-t_wireId-(1-secondaryFlag),1).c_str(),0,16); |
| 1482 | unsigned t_secondaryTiming = (unsigned)t_priorityTiming.subset(4 * (t_wireId + (1 - secondaryFlag)), 4); |
| 1483 | t_hitTrgData[3] = t_secondaryTiming; |
| 1484 | //cout<<t_secondaryTiming<<endl; |
| 1485 | } else { |
| 1486 | cout << "Error in TRGDATA for secondary priority hits" << endl; |
| 1487 | } |
| 1488 | //cout<<"Layer3end"<<endl; |
| 1489 | } else { |
| 1490 | t_hitTrgData[3] = -1; |
| 1491 | //cout<<"-1"<<endl; |
| 1492 | } |
| 1493 | } else { |
| 1494 | t_hitTrgData[3] = -1; |
| 1495 | } |
| 1496 | hitTrgData.push_back(t_hitTrgData); |
| 1497 | } // wire is hit |
| 1498 | } // wire loop |
| 1499 | } // window loop |
| 1500 | //// Print hitWires from Trigger |
| 1501 | //if(hitTrgData.size()) cout<<"TRG: "<<endl; |
| 1502 | //for(unsigned iHit=0; iHit<hitTrgData.size(); iHit++){ |
| 1503 | // cout<<"["<<hitTrgData[iHit][0]<<"]["<<hitTrgData[iHit][1]<<"]: "<<hitTrgData[iHit][2]*32+hitTrgData[iHit][3]*2<<"("<<hitTrgData[iHit][2]<<","<<hitTrgData[iHit][3]<<")"<<endl;; |
| 1504 | //} |
| 1505 | //if(hitTrgData.size()) { |
| 1506 | // for(unsigned iWindow=0; iWindow<nTRGWindows; iWindow++){ |
| 1507 | // vector<unsigned> t_trgData(inBinaryData[2].begin()+11*iWindow, inBinaryData[2].begin()+11*iWindow+11); |
| 1508 | // TRGState t_trgState(t_trgData,1); |
| 1509 | // TRGState t_mergerState = t_trgState.subset(96, 256); |
| 1510 | // TRGState t_hitMap = t_mergerState.subset(0,80); |
| 1511 | // TRGState t_priorityMap = t_mergerState.subset(32,16); |
| 1512 | // TRGState t_secondPriorityMap = t_mergerState.subset(48,16); |
| 1513 | // TRGState t_secondHitFlag= t_mergerState.subset(208,16); |
| 1514 | // TRGState t_priorityTiming = t_mergerState.subset(80,64); |
| 1515 | // TRGState t_fastestTiming = t_mergerState.subset(144,64); |
| 1516 | // cout<<"["<<iWindow<<"] HM: "<<t_hitMap<<endl; |
| 1517 | // cout<<"["<<iWindow<<"] PHM: "<<t_priorityMap<<endl; |
| 1518 | // cout<<"["<<iWindow<<"] SHM: "<<t_secondPriorityMap<<endl; |
| 1519 | // cout<<"["<<iWindow<<"] SPF: "<<t_secondHitFlag<<endl; |
| 1520 | // cout<<"["<<iWindow<<"] PT: "<<setfill('0')<<setw(16)<<hex<<(unsigned long long) (t_priorityTiming)<<dec<<endl; |
| 1521 | // cout<<"["<<iWindow<<"] FT: "<<setfill('0')<<setw(16)<<hex<<(unsigned long long) (t_fastestTiming)<<dec<<endl; |
| 1522 | // } |
| 1523 | //} |
| 1524 | |
| 1525 | const int trgOutput = 2; |
| 1526 | // Store TRG data to TRGSignalBundle. |
| 1527 | // 1 is FE output. 2 is Merger output. 3 is TRG output. |
| 1528 | //...Clock... |
| 1529 | const TRGClock& dClock = TRGCDC::getTRGCDC()->dataClock(); |
| 1530 | // Create signal bundle |
| 1531 | TRGSignalBundle* allTrgData; |
| 1532 | allTrgData = new TRGSignalBundle(string("TRGData"), dClock); |
| 1533 | // Create signal vector. Need to create signals for of signal vector. |
| 1534 | TRGSignalVector* trgData; |
| 1535 | trgData = new TRGSignalVector(string("TRGData"), dClock, nTrgBitsInWindow); |
| 1536 | // Loop over data and fill TRGSignalVector |
| 1537 | for (unsigned iWindow = 0; iWindow < nTRGWindows; iWindow++) { |
| 1538 | vector<unsigned> t_trgData(inBinaryData[2].begin() + 11 * iWindow, inBinaryData[2].begin() + 11 * iWindow + 11); |
| 1539 | TRGState t_trgState(t_trgData, 1); |
| 1540 | trgData->set(t_trgState, iWindow); |
| 1541 | } |
| 1542 | if (allTrgData) { |
| 1543 | allTrgData->push_back(trgData); |
| 1544 | // Clean up memory |
| 1545 | for (unsigned i = 0; i < allTrgData->size(); i++) delete (*allTrgData)[i]; |
| 1546 | delete allTrgData; |
| 1547 | } |
| 1548 | |
| 1549 | |
| 1550 | // Save CDC hit data and TRG hit data to ROOT file. |
| 1551 | if (_makeRootFile) { |
| 1552 | saveTRGRawInformation(trgInformations); |
| 1553 | saveCDCHitInformation(hitCdcData); |
| 1554 | // cppcheck-suppress knownConditionTrueFalse |
| 1555 | if (trgOutput == 2) { |
| 1556 | saveTRGHitInformation(hitTrgData); |
| 1557 | } |
| 1558 | m_treeROOTInput->Fill(); |
| 1559 | } |
| 1560 | |
| 1561 | // Update CDC wires using data. Start from layer 50. |
| 1562 | for (unsigned iHit = 0; iHit < hitCdcData.size(); iHit++) { |
| 1563 | unsigned t_layerId = hitCdcData[iHit][0] + 50; |
| 1564 | unsigned t_wireId = hitCdcData[iHit][1]; |
| 1565 | int t_rawTdc = hitCdcData[iHit][2]; |
| 1566 | const TCWireTRGCDCWire& currentWire = *static_cast<const TCWireTRGCDCWire*>(wire(t_layerId, t_wireId)); |
| 1567 | |
| 1568 | // Update currentWire._signal |
| 1569 | TRGTime rise = TRGTime(t_rawTdc, true, _clockFE, currentWire.name()); |
| 1570 | TRGTime fall = rise; |
| 1571 | fall.shift(1).reverse(); |
| 1572 | if (currentWire._signal.active()) { |
| 1573 | currentWire._signal = currentWire.signal() | TRGSignal(rise & fall); |
| 1574 | currentWire._signal.name(currentWire.name()); |
| 1575 | } else { |
| 1576 | currentWire._signal = TRGSignal(rise & fall); |
| 1577 | currentWire._signal.name(currentWire.name()); |
| 1578 | |
| 1579 | // Make TCWireHit and store in _layers. |
| 1580 | // [FIXME] TCWireHit can not accept wire being hit two times. |
| 1581 | TCWHitTRGCDCWireHit* hit = new TCWHitTRGCDCWireHit(currentWire, 0, 0, 0, t_rawTdc, 0, t_rawTdc, 0, 0, 1); |
| 1582 | hit->state(CellHitFindingValid4194304 | CellHitFittingValid0x40000000); |
| 1583 | ((TCWireTRGCDCWire*)(*_layers[t_layerId])[t_wireId])->hit(hit); |
| 1584 | _hits.push_back(hit); |
| 1585 | if (currentWire.axial()) _axialHits.push_back(hit); |
| 1586 | else _stereoHits.push_back(hit); |
| 1587 | } |
| 1588 | //cout<<"iLayer, iWire, iHit: "<<t_layerId<<" "<<t_wireId<<" "<<iHit<<endl; |
| 1589 | //currentWire.signal().dump(); |
| 1590 | |
| 1591 | } // End updating CDC wires |
| 1592 | |
| 1593 | //...Hit classification... |
| 1594 | classification(); |
| 1595 | |
| 1596 | TRGDebug::leaveStage("TRGCDC updateByData"); |
| 1597 | } |
| 1598 | |
| 1599 | void |
| 1600 | TRGCDC::classification(void) |
| 1601 | { |
| 1602 | TRGDebug::enterStage("TRGCDC classification"); |
| 1603 | |
| 1604 | unsigned n = _hits.size(); |
| 1605 | |
| 1606 | for (unsigned i = 0; i < n; i++) { |
| 1607 | TCWHitTRGCDCWireHit* h = _hits[i]; |
| 1608 | const TCWireTRGCDCWire& w = h->wire(); |
| 1609 | unsigned state = h->state(); |
| 1610 | |
| 1611 | //...Cache pointers to a neighbor... |
| 1612 | const TCWireTRGCDCWire* neighbor[7]; |
| 1613 | for (unsigned j = 0; j < 7; j++) neighbor[j] = w.neighbor(j); |
| 1614 | |
| 1615 | //...Decide hit pattern... |
| 1616 | unsigned pattern = 0; |
| 1617 | for (unsigned j = 0; j < 7; j++) { |
| 1618 | if (neighbor[j]) |
| 1619 | if (neighbor[j]->hit()) |
| 1620 | pattern += (1 << j); |
| 1621 | } |
| 1622 | state |= (pattern << CellHitNeighborHit12); |
| 1623 | |
| 1624 | //...Check isolation... |
| 1625 | const TCWHitTRGCDCWireHit* hr1 = neighbor[2]->hit(); |
| 1626 | const TCWHitTRGCDCWireHit* hl1 = neighbor[3]->hit(); |
| 1627 | if ((hr1 == 0) && (hl1 == 0)) { |
| 1628 | state |= CellHitIsolated1024; |
| 1629 | } else { |
| 1630 | const TCWHitTRGCDCWireHit* hr2 = neighbor[2]->neighbor(2)->hit(); |
| 1631 | const TCWHitTRGCDCWireHit* hl2 = neighbor[3]->neighbor(3)->hit(); |
| 1632 | if (((hr2 == 0) && (hr1 != 0) && (hl1 == 0)) || |
| 1633 | ((hl2 == 0) && (hl1 != 0) && (hr1 == 0))) |
| 1634 | state |= CellHitIsolated1024; |
| 1635 | } |
| 1636 | |
| 1637 | //...Check continuation... |
| 1638 | // unsigned superLayer = w.superLayerId(); |
| 1639 | bool previous = false; |
| 1640 | bool next = false; |
| 1641 | if (neighbor[0] == 0) previous = true; |
| 1642 | else { |
| 1643 | if ((neighbor[0]->hit()) || neighbor[1]->hit()) |
| 1644 | previous = true; |
| 1645 | // if (m_smallcell && w.layerId() == 3) |
| 1646 | // if (neighbor[6]->hit()) |
| 1647 | // previous = true; |
| 1648 | } |
| 1649 | if (neighbor[5] == 0) next = true; |
| 1650 | else { |
| 1651 | if ((neighbor[4]->hit()) || neighbor[5]->hit()) |
| 1652 | next = true; |
| 1653 | } |
| 1654 | // if (previous && next) state |= CellHitContinuous; |
| 1655 | if (previous || next) state |= CellHitContinuous2048; |
| 1656 | |
| 1657 | //...Solve LR locally... |
| 1658 | if ((pattern == 34) || (pattern == 42) || |
| 1659 | (pattern == 40) || (pattern == 10) || |
| 1660 | (pattern == 35) || (pattern == 50)) |
| 1661 | state |= CellHitPatternRight512; |
| 1662 | else if ((pattern == 17) || (pattern == 21) || |
| 1663 | (pattern == 20) || (pattern == 5) || |
| 1664 | (pattern == 19) || (pattern == 49)) |
| 1665 | state |= CellHitPatternLeft256; |
| 1666 | |
| 1667 | //...Store it... |
| 1668 | h->state(state); |
| 1669 | } |
| 1670 | |
| 1671 | TRGDebug::leaveStage("TRGCDC classification"); |
| 1672 | } |
| 1673 | |
| 1674 | vector<const TCWHitTRGCDCWireHit*> |
| 1675 | TRGCDC::axialHits(void) const |
| 1676 | { |
| 1677 | vector<const TCWHitTRGCDCWireHit*> t; |
| 1678 | t.assign(_axialHits.begin(), _axialHits.end()); |
| 1679 | return t; |
| 1680 | |
| 1681 | // if (! mask) return _axialHits; |
| 1682 | // else if (mask == CellHitFindingValid) return _axialHits; |
| 1683 | // cout << "TRGCDC::axialHits !!! unsupported mask given" << endl; |
| 1684 | // return _axialHits; |
| 1685 | } |
| 1686 | |
| 1687 | vector<const TCWHitTRGCDCWireHit*> |
| 1688 | TRGCDC::stereoHits(void) const |
| 1689 | { |
| 1690 | vector<const TCWHitTRGCDCWireHit*> t; |
| 1691 | t.assign(_stereoHits.begin(), _stereoHits.end()); |
| 1692 | return t; |
| 1693 | |
| 1694 | // if (! mask) return _stereoHits; |
| 1695 | // else if (mask == CellHitFindingValid) return _stereoHits; |
| 1696 | // cout << "TRGCDC::stereoHits !!! unsupported mask given" << endl; |
| 1697 | // return _stereoHits; |
| 1698 | } |
| 1699 | |
| 1700 | vector<const TCWHitTRGCDCWireHit*> |
| 1701 | TRGCDC::hits(void) const |
| 1702 | { |
| 1703 | vector<const TCWHitTRGCDCWireHit*> t; |
| 1704 | t.assign(_hits.begin(), _hits.end()); |
| 1705 | return t; |
| 1706 | |
| 1707 | // if (! mask) return _hits; |
| 1708 | // else if (mask == CellHitFindingValid) return _hits; |
| 1709 | // cout << "TRGCDC::hits !!! unsupported mask given" << endl; |
| 1710 | // return _hits; |
| 1711 | } |
| 1712 | |
| 1713 | // vector<const TCWHit *> |
| 1714 | // TRGCDC::badHits(void) const { |
| 1715 | // vector<const TCWHit *> t; |
| 1716 | // t.assign(_badHits.begin(), _badHits.end()); |
| 1717 | // return t; |
| 1718 | |
| 1719 | // //cnv if (! updated()) update(); |
| 1720 | // // if (_badHits.length()) return _badHits; |
| 1721 | |
| 1722 | // // //...Loop over RECCDC_WIRHIT bank... |
| 1723 | // // x unsigned nReccdc = BsCouTab(RECCDC_WIRHIT); |
| 1724 | // // for (unsigned i = 0; i < nReccdc; i++) { |
| 1725 | // // x struct reccdc_wirhit * h = |
| 1726 | // // (struct reccdc_wirhit *) |
| 1727 | // // BsGetEnt(RECCDC_WIRHIT, i + 1, BBS_No_Index); |
| 1728 | |
| 1729 | // // //...Check validity... |
| 1730 | // // if (h->m_stat & CellHitFindingValid) continue; |
| 1731 | |
| 1732 | // // //...Obtain a pointer to GEOCDC... |
| 1733 | // // x geocdc_wire * g = |
| 1734 | // // (geocdc_wire *) BsGetEnt(GEOCDC_WIRE, h->m_geo, BBS_No_Index); |
| 1735 | |
| 1736 | // // //...Get a pointer to a TRGCDCWire... |
| 1737 | // // TCWire * w = _wires[g->m_ID - 1]; |
| 1738 | |
| 1739 | // // //...Create TCWHit... |
| 1740 | // // _badHits.append(new TCWHit(w, h, _fudgeFactor)); |
| 1741 | // // } |
| 1742 | |
| 1743 | // // return _badHits; |
| 1744 | // } |
| 1745 | |
| 1746 | vector<const TCWHitMCTRGCDCWireHitMC*> |
| 1747 | TRGCDC::hitsMC(void) const |
| 1748 | { |
| 1749 | vector<const TCWHitMCTRGCDCWireHitMC*> t; |
| 1750 | t.assign(_hitsMC.begin(), _hitsMC.end()); |
| 1751 | return t; |
| 1752 | } |
| 1753 | |
| 1754 | string |
| 1755 | TRGCDC::wireName(unsigned wireId) const |
| 1756 | { |
| 1757 | string as = "-"; |
| 1758 | const TCWireTRGCDCWire* const w = wire(wireId); |
| 1759 | if (w) { |
| 1760 | if (w->stereo()) |
| 1761 | as = "="; |
| 1762 | } else { |
| 1763 | return "invalid_wire(" + TRGUtilTRGUtilities::itostring(wireId) + ")"; |
| 1764 | } |
| 1765 | return TRGUtilTRGUtilities::itostring(layerId(wireId)) + as + TRGUtilTRGUtilities::itostring(localId(wireId)); |
| 1766 | } |
| 1767 | |
| 1768 | unsigned |
| 1769 | TRGCDC::localId(unsigned id) const |
| 1770 | { |
| 1771 | cout << "TRGCDC::localId !!! this function is not tested yet" |
| 1772 | << endl; |
| 1773 | unsigned iLayer = 0; |
| 1774 | unsigned nW = 0; |
| 1775 | bool nextLayer = true; |
| 1776 | while (nextLayer) { |
| 1777 | unsigned nWLast = nW; |
| 1778 | nW += layer(iLayer++)->nCells(); |
| 1779 | if (id < (nW - 1)) |
| 1780 | return id - nWLast; |
| 1781 | if (nW >= nWires()) |
| 1782 | nextLayer = false; |
| 1783 | } |
| 1784 | cout << "TRGCDC::localId !!! no such a wire (id=" << id << endl; |
| 1785 | return TRGCDC_UNDEFINED999999; |
| 1786 | } |
| 1787 | |
| 1788 | unsigned |
| 1789 | TRGCDC::layerId(unsigned id) const |
| 1790 | { |
| 1791 | cout << "TRGCDC::layerId !!! this function is not tested yet" |
| 1792 | << endl; |
| 1793 | unsigned iLayer = 0; |
| 1794 | unsigned nW = 0; |
| 1795 | bool nextLayer = true; |
| 1796 | while (nextLayer) { |
| 1797 | nW += layer(iLayer++)->nCells(); |
| 1798 | if (id < (nW - 1)) |
| 1799 | return iLayer - 1; |
| 1800 | if (nW >= nWires()) |
| 1801 | nextLayer = false; |
| 1802 | } |
| 1803 | cout << "TRGCDC::layerId !!! no such a wire (id=" << id << endl; |
| 1804 | return TRGCDC_UNDEFINED999999; |
| 1805 | } |
| 1806 | |
| 1807 | unsigned |
| 1808 | TRGCDC::layerId(unsigned, unsigned) const |
| 1809 | { |
| 1810 | cout << "TRGCDC::layerId !!! this function is not implemented yet" |
| 1811 | << endl; |
| 1812 | return TRGCDC_UNDEFINED999999; |
| 1813 | } |
| 1814 | |
| 1815 | unsigned |
| 1816 | TRGCDC::superLayerId(unsigned id) const |
| 1817 | { |
| 1818 | unsigned iLayer = 0; |
| 1819 | unsigned nW = 0; |
| 1820 | bool nextLayer = true; |
| 1821 | while (nextLayer) { |
| 1822 | const vector<TRGCDCLayer*>& sl = *superLayer(iLayer); |
| 1823 | const unsigned nLayers = sl.size(); |
| 1824 | for (unsigned i = 0; i < nLayers; i++) |
| 1825 | nW += sl[i]->nCells(); |
| 1826 | |
| 1827 | if (id < (nW - 1)) |
| 1828 | return iLayer; |
| 1829 | if (nW >= nWires()) |
| 1830 | nextLayer = false; |
| 1831 | } |
| 1832 | cout << "TRGCDC::superLayerId !!! no such a wire (id=" << id |
| 1833 | << endl; |
| 1834 | return TRGCDC_UNDEFINED999999; |
| 1835 | } |
| 1836 | |
| 1837 | unsigned |
| 1838 | TRGCDC::localLayerId(unsigned id) const |
| 1839 | { |
| 1840 | unsigned iLayer = 0; |
| 1841 | unsigned nW = 0; |
| 1842 | bool nextLayer = true; |
| 1843 | while (nextLayer) { |
| 1844 | const vector<TRGCDCLayer*>& sl = *superLayer(iLayer); |
| 1845 | const unsigned nLayers = sl.size(); |
| 1846 | for (unsigned i = 0; i < nLayers; i++) { |
| 1847 | nW += sl[i]->nCells(); |
| 1848 | if (id < (nW - 1)) |
| 1849 | return i; |
| 1850 | } |
| 1851 | |
| 1852 | if (nW >= nWires()) |
| 1853 | nextLayer = false; |
| 1854 | } |
| 1855 | cout << "TRGCDC::localLayerId !!! no such a wire (id=" << id |
| 1856 | << endl; |
| 1857 | return TRGCDC_UNDEFINED999999; |
| 1858 | } |
| 1859 | |
| 1860 | unsigned |
| 1861 | TRGCDC::axialStereoSuperLayerId(unsigned aors, unsigned i) const |
| 1862 | { |
| 1863 | unsigned is = 99; |
| 1864 | // cout << "aors,i= " << aors <<" "<< i << std::endl; |
| 1865 | if (aors == 0) { //axial |
| 1866 | if (i <= 7) { |
| 1867 | is = 0; |
| 1868 | } else if (i <= 13) { |
| 1869 | is = 1; |
| 1870 | } else if (i <= 19) { |
| 1871 | is = 2; |
| 1872 | } else if (i <= 25) { |
| 1873 | is = 3; |
| 1874 | } else if (i <= 31) { |
| 1875 | is = 4; |
| 1876 | } |
| 1877 | } else if (aors == 1) { //stereo |
| 1878 | if (i <= 5) { |
| 1879 | is = 0; |
| 1880 | } else if (i <= 11) { |
| 1881 | is = 1; |
| 1882 | } else if (i <= 17) { |
| 1883 | is = 2; |
| 1884 | } else if (i <= 23) { |
| 1885 | is = 3; |
| 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | assert(is != 99)(static_cast <bool> (is != 99) ? void (0) : __assert_fail ("is != 99", "trg/cdc/src/TRGCDC.cc", 1889, __extension__ __PRETTY_FUNCTION__ )); |
| 1890 | return is; |
| 1891 | } |
| 1892 | |
| 1893 | // void |
| 1894 | // TRGCDC::driftDistance(TLink & l, |
| 1895 | // const TTrack & t, |
| 1896 | // unsigned flag, |
| 1897 | // float t0Offset) { |
| 1898 | |
| 1899 | // //...No correction... |
| 1900 | // if (flag == 0) { |
| 1901 | // if (l.hit()) { |
| 1902 | // // l.drift(0, l.hit()->drift(0)); |
| 1903 | // // l.drift(1, l.hit()->drift(1)); |
| 1904 | // // l.dDrift(0, l.hit()->dDrift(0)); |
| 1905 | // // l.dDrift(1, l.hit()->dDrift(1)); |
| 1906 | // l.drift(l.hit()->drift(0), 0); |
| 1907 | // l.drift(l.hit()->drift(1), 1); |
| 1908 | // l.dDrift(l.hit()->dDrift(0), 0); |
| 1909 | // l.dDrift(l.hit()->dDrift(1), 1); |
| 1910 | // } |
| 1911 | // else { |
| 1912 | // // l.drift(0, 0.); |
| 1913 | // // l.drift(1, 0.); |
| 1914 | // // l.dDrift(0, 0.); |
| 1915 | // // l.dDrift(1, 0.); |
| 1916 | // l.drift(0., 0); |
| 1917 | // l.drift(0., 1); |
| 1918 | // l.dDrift(0., 0); |
| 1919 | // l.dDrift(0., 1); |
| 1920 | // } |
| 1921 | |
| 1922 | // return; |
| 1923 | // } |
| 1924 | |
| 1925 | // //...TOF correction... |
| 1926 | // float tof = 0.; |
| 1927 | // if (flag && 1) { |
| 1928 | // int imass = 3; |
| 1929 | // float tl = t.helix().a()[4]; |
| 1930 | // float f = sqrt(1. + tl * tl); |
| 1931 | // float s = fabs(t.helix().curv()) * fabs(l.dPhi()) * f; |
| 1932 | // float p = f / fabs(t.helix().a()[2]); |
| 1933 | // calcdc_tof2_(& imass, & p, & s, & tof); |
| 1934 | // } |
| 1935 | |
| 1936 | // //...T0 correction.... |
| 1937 | // if (! (flag && 2)) t0Offset = 0.; |
| 1938 | |
| 1939 | // //...Propagation corrections... |
| 1940 | // const TCWHit & h = * l.hit(); |
| 1941 | // int wire = h.wire()->id(); |
| 1942 | // HepGeom::Vector3D<double> tp = t.helix().momentum(l.dPhi()); |
| 1943 | // float p[3] = {tp.x(), tp.y(), tp.z()}; |
| 1944 | // const HepGeom::Point3D<double> & onWire = l.positionOnWire(); |
| 1945 | // float x[3] = {onWire.x(), onWire.y(), onWire.z()}; |
| 1946 | // //cnv float time = h.reccdc()->m_tdc + t0Offset - tof; |
| 1947 | // float time = 0; |
| 1948 | // float dist; |
| 1949 | // float edist; |
| 1950 | // int prop = (flag & 4); |
| 1951 | |
| 1952 | // //...Calculation with left side... |
| 1953 | // int side = -1; |
| 1954 | // if (side == 0) side = -1; |
| 1955 | // calcdc_driftdist_(& prop, |
| 1956 | // & wire, |
| 1957 | // & side, |
| 1958 | // p, |
| 1959 | // x, |
| 1960 | // & time, |
| 1961 | // & dist, |
| 1962 | // & edist); |
| 1963 | // // l.drift(0, dist); |
| 1964 | // // l.dDrift(0, edist); |
| 1965 | // l.drift(dist, 0); |
| 1966 | // l.dDrift(edist, 0); |
| 1967 | |
| 1968 | // //...Calculation with left side... |
| 1969 | // side = 1; |
| 1970 | // calcdc_driftdist_(& prop, |
| 1971 | // & wire, |
| 1972 | // & side, |
| 1973 | // p, |
| 1974 | // x, |
| 1975 | // & time, |
| 1976 | // & dist, |
| 1977 | // & edist); |
| 1978 | // // l.drift(1, dist); |
| 1979 | // // l.dDrift(1, edist); |
| 1980 | // l.drift(dist, 1); |
| 1981 | // l.dDrift(edist, 1); |
| 1982 | |
| 1983 | // //...tan(lambda) correction... |
| 1984 | // if (flag && 8) { |
| 1985 | // float tanl = abs(p[2]) / tp.perp(); |
| 1986 | // float c; |
| 1987 | // if ((tanl >= 0.0) && (tanl < 0.5)) c = -0.48 * tanl + 1.3; |
| 1988 | // else if ((tanl >= 0.5) && (tanl < 1.0)) c = -0.28 * tanl + 1.2; |
| 1989 | // else if ((tanl >= 1.0) && (tanl < 1.5)) c = -0.16 * tanl + 1.08; |
| 1990 | // else c = 0.84; |
| 1991 | |
| 1992 | // // l.dDrift(0, l.dDrift(0) * c); |
| 1993 | // // l.dDrift(1, l.dDrift(1) * c); |
| 1994 | // l.dDrift(l.dDrift(0) * c, 0); |
| 1995 | // l.dDrift(l.dDrift(1) * c, 1); |
| 1996 | // } |
| 1997 | // } |
| 1998 | |
| 1999 | TRGCDC::~TRGCDC() |
| 2000 | { |
| 2001 | TRGDebug::enterStage("TRGCDC destructor"); |
| 2002 | clear(); |
| 2003 | |
| 2004 | delete [] _width; |
| 2005 | delete [] _r; |
| 2006 | delete [] _r2; |
| 2007 | |
| 2008 | if (_tsFinder) delete _tsFinder; |
| 2009 | if (_hFinder) |
| 2010 | delete _hFinder; |
| 2011 | if (_h3DFinder) |
| 2012 | delete _h3DFinder; |
| 2013 | if (_fitter3D) |
| 2014 | delete _fitter3D; |
| 2015 | |
| 2016 | #ifdef TRGCDC_DISPLAY |
| 2017 | if (D) |
| 2018 | delete D; |
| 2019 | cout << "TRGCDC ... rphi displays deleted" << endl; |
| 2020 | #endif |
| 2021 | |
| 2022 | TRGDebug::leaveStage("TRGCDC destructor"); |
| 2023 | } |
| 2024 | |
| 2025 | bool |
| 2026 | TRGCDC::neighbor(const TCWireTRGCDCWire& w0, const TCWireTRGCDCWire& w1) const |
| 2027 | { |
| 2028 | const int lyr0 = w0.layerId(); |
| 2029 | const int lyr1 = w1.layerId(); |
| 2030 | const int lyr = lyr0 - lyr1; |
| 2031 | |
| 2032 | if (abs(lyr) > 1) return false; |
| 2033 | if (w0.superLayerId() != w1.superLayerId()) return false; |
| 2034 | |
| 2035 | for (unsigned i = 0; i < 7; i++) { |
| 2036 | if (w0.neighbor(i)) { |
| 2037 | if (w0.neighbor(i)->id() == w1.id()) |
| 2038 | return true; |
| 2039 | } |
| 2040 | } |
| 2041 | return false; |
| 2042 | } |
| 2043 | |
| 2044 | void |
| 2045 | TRGCDC::simulate(void) |
| 2046 | { |
| 2047 | TRGDebug::enterStage("TRGCDC simulate"); |
| 2048 | |
| 2049 | const bool fast = (_simulationMode & 1); |
| 2050 | const bool firm = (_simulationMode & 2); |
| 2051 | if (fast) |
| 2052 | fastSimulation(); |
| 2053 | if (firm) |
| 2054 | firmwareSimulation(); |
| 2055 | |
| 2056 | TRGDebug::leaveStage("TRGCDC simulate"); |
| 2057 | } |
| 2058 | |
| 2059 | void |
| 2060 | TRGCDC::fastSimulation(void) |
| 2061 | { |
| 2062 | TRGDebug::enterStage("TRGCDC fastSimulation"); |
| 2063 | |
| 2064 | #ifdef TRGCDC_DISPLAY |
| 2065 | D->beginningOfEvent(); |
| 2066 | #endif |
| 2067 | |
| 2068 | //...Options... |
| 2069 | const bool trackSegmentSimulationOnly = _fastSimulationMode & 1; |
| 2070 | const bool trackSegmentClockSimulation = _fastSimulationMode & 2; |
| 2071 | |
| 2072 | //...TSF simulation... |
| 2073 | _tsFinder->doit(_tss, |
| 2074 | trackSegmentClockSimulation, |
| 2075 | _segmentHits, |
| 2076 | _segmentHitsSL); |
| 2077 | _eventTime.back()->doit(_fverETF, _fprintFirmETF); |
| 2078 | |
| 2079 | if (_segmentHits.size() == 0) setReturnValue(TSF, 1); |
| 2080 | |
| 2081 | if (trackSegmentSimulationOnly) { |
| 2082 | TRGDebug::leaveStage("TRGCDC fastSimulation"); |
| 2083 | return; |
| 2084 | } |
| 2085 | |
| 2086 | #ifdef TRGCDC_DISPLAY |
| 2087 | // dump("hits"); |
| 2088 | string stg = "fast simulation results"; |
| 2089 | string inf = "#segments=" + TRGUtilities::itostring(segmentHits().size()); |
| 2090 | D->clear(); |
| 2091 | D->stage(stg); |
| 2092 | D->information(inf); |
| 2093 | D->area().append(hits()); |
| 2094 | D->area().append(segmentHits()); |
| 2095 | D->show(); |
| 2096 | D->run(); |
| 2097 | #endif |
| 2098 | |
| 2099 | //...2D finder and fitter... |
| 2100 | if (_perfect2DFinder) |
| 2101 | _pFinder->doit(_trackList2D, _trackList2DFitted); |
| 2102 | else |
| 2103 | _hFinder->FindAndFit(_trackList2D, _trackList2DFitted); |
| 2104 | if (_trackList2D.size() == 0) setReturnValue(find2D, 1); |
| 2105 | if (_trackList2DFitted.size() == 0) setReturnValue(fit2D, 1); |
| 2106 | |
| 2107 | //cout<<"s3D"<<endl; |
| 2108 | //...Stereo finder... |
| 2109 | _h3DFinder->doit(_trackList2D, _trackList3D); |
| 2110 | |
| 2111 | //...Check tracks... |
| 2112 | if (TRGDebug::level()) { |
| 2113 | for (unsigned i = 0; i < _trackList3D.size(); i++) { |
| 2114 | const TCTrackTRGCDCTrack& t = *_trackList3D[i]; |
| 2115 | cout << "> links=" << t.links().size() << endl; |
| 2116 | t.dump(); |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | //...Check relations... |
| 2121 | if (TRGDebug::level()) { |
| 2122 | for (unsigned i = 0; i < _trackList3D.size(); i++) { |
| 2123 | // trackList[i]->relation().dump(); |
| 2124 | _trackList3D[i]->dump(); |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | //...Event Time... In ns scale. |
| 2129 | // [FIXME] This does nothing. |
| 2130 | _eventTime.back()->getT0(); |
| 2131 | |
| 2132 | //...3D tracker... |
| 2133 | _fitter3D->doit(_trackList3D); |
| 2134 | //_fitter3D->doitComplex(_trackList3D); |
| 2135 | //cout<<"e3D"<<endl; |
| 2136 | |
| 2137 | // Notify if track's debugValue is not 0 |
| 2138 | { |
| 2139 | // For any track |
| 2140 | int t_debugValue = 0; |
| 2141 | for (unsigned iTrack = 0; iTrack < _trackList3D.size(); iTrack++) { |
| 2142 | t_debugValue |= _trackList3D[iTrack]->getDebugValue(TRGCDCTrack::EDebugValueType::any); |
| 2143 | } |
| 2144 | //// For all tracks |
| 2145 | //int t_debugValue = TRGCDCTrack::EDebugValueType::any; |
| 2146 | //for(unsigned iTrack = 0; iTrack<_trackList3D.size(); iTrack++) { |
| 2147 | // t_debugValue &= _trackList3D[iTrack]->getDebugValue(TRGCDCTrack::EDebugValueType::any); |
| 2148 | //} |
| 2149 | setReturnValue(t_debugValue | getReturnValue()); |
| 2150 | } |
| 2151 | |
| 2152 | if (TRGDebug::level() > 1) { |
| 2153 | for (unsigned iTrack = 0; iTrack < _trackList3D.size(); iTrack++) { |
| 2154 | const TCTrackTRGCDCTrack& aTrack = *_trackList3D[iTrack]; |
| 2155 | if (aTrack.fitted()) { |
| 2156 | double fitPt = aTrack.pt(); |
| 2157 | double fitPhi0 = aTrack.helix().phi0(); |
| 2158 | int fitCharge = aTrack.charge(); |
| 2159 | if (fitCharge < 0) { |
| 2160 | fitPhi0 -= M_PI3.14159265358979323846; |
| 2161 | if (fitPhi0 < 0) fitPhi0 += 2 * M_PI3.14159265358979323846; |
| 2162 | } |
| 2163 | double fitZ0 = aTrack.helix().dz(); |
| 2164 | double fitCot = aTrack.helix().tanl(); |
| 2165 | cout << TRGDebug::tab() << "Track[" << iTrack << "]: charge=" << fitCharge |
| 2166 | << " pt=" << fitPt << " phi_c=" << fitPhi0 |
| 2167 | << " z0=" << fitZ0 << " cot=" << fitCot << endl; |
| 2168 | const TCRelationTRGCDCRelation& trackRelation = aTrack.relation(); |
| 2169 | const MCParticle& trackMCParticle = trackRelation.mcParticle(0); |
| 2170 | int mcCharge = trackMCParticle.getCharge(); |
| 2171 | double mcPt = trackMCParticle.getMomentum().Rho(); |
| 2172 | double mcPhi0 = 0.0; |
| 2173 | if (mcCharge > 0) mcPhi0 = trackMCParticle.getMomentum().Phi() - M_PI3.14159265358979323846 / 2; |
| 2174 | if (mcCharge < 0) mcPhi0 = trackMCParticle.getMomentum().Phi() + M_PI3.14159265358979323846 / 2; |
| 2175 | // Change range to [0,2pi] |
| 2176 | if (mcPhi0 < 0) mcPhi0 += 2 * M_PI3.14159265358979323846; |
| 2177 | // Calculated impact position |
| 2178 | ROOT::Math::XYZVector vertex = trackMCParticle.getVertex(); |
| 2179 | ROOT::Math::PxPyPzEVector vector4 = trackMCParticle.get4Vector(); |
| 2180 | ROOT::Math::XYVector helixCenter; |
| 2181 | ROOT::Math::XYZVector impactPosition; |
| 2182 | Fitter3DUtility::findImpactPosition(&vertex, &vector4, mcCharge, helixCenter, impactPosition); |
| 2183 | double mcZ0 = impactPosition.Z(); |
| 2184 | double mcCot = trackMCParticle.getMomentum().z() / trackMCParticle.getMomentum().Rho(); |
| 2185 | cout << TRGDebug::tab() << "Track[" << iTrack << "]: mcCharge=" << mcCharge |
| 2186 | << " mcPt=" << mcPt << " mcPhi_c=" << mcPhi0 |
| 2187 | << " mcZ0=" << mcZ0 << " mcCot=" << mcCot << endl; |
| 2188 | } |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | if (TRGDebug::level()) { |
| 2193 | cout << TRGDebug::tab() << "Number of 2D tracks : " |
| 2194 | << _trackList2D.size() << endl; |
| 2195 | cout << TRGDebug::tab() << "Number of 2D fitted tracks : " |
| 2196 | << _trackList2DFitted.size() << endl; |
| 2197 | cout << TRGDebug::tab() << "Number of 3D tracks : " |
| 2198 | << _trackList3D.size() << endl; |
| 2199 | } |
| 2200 | |
| 2201 | #ifdef TRGCDC_DISPLAY |
| 2202 | // dump("hits"); |
| 2203 | vector<const TCTrackTRGCDCTrack*> t2; |
| 2204 | t2.assign(_trackList2D.begin(), _trackList2D.end()); |
| 2205 | vector<const TCTrackTRGCDCTrack*> t2f; |
| 2206 | t2f.assign(_trackList2DFitted.begin(), _trackList2DFitted.end()); |
| 2207 | vector<const TCTrackTRGCDCTrack*> t3; |
| 2208 | t3.assign(_trackList3D.begin(), _trackList3D.end()); |
| 2209 | D->endOfEvent(); |
| 2210 | stg = "fast simulation results"; |
| 2211 | inf = "red:2D, blue:2DF, green:3D"; |
| 2212 | D->clear(); |
| 2213 | D->stage(stg); |
| 2214 | D->information(inf); |
| 2215 | D->area().append(hits()); |
| 2216 | D->area().append(segmentHits()); |
| 2217 | D->area().append(t2, Gdk::Color("red")); |
| 2218 | D->area().append(t2f, Gdk::Color("blue")); |
| 2219 | D->area().append(t3, Gdk::Color("green")); |
| 2220 | D->show(); |
| 2221 | D->run(); |
| 2222 | |
| 2223 | // unsigned iFront = 0; |
| 2224 | // while (const TCFrontEnd * f = _cdc.frontEnd(iFront++)) { |
| 2225 | // D->clear(); |
| 2226 | // D->beginEvent(); |
| 2227 | // D->area().append(* f); |
| 2228 | // D->run(); |
| 2229 | // } |
| 2230 | // unsigned iMerger = 0; |
| 2231 | // while (const TCMerger * f = _cdc.merger(iMerger++)) { |
| 2232 | // D->clear(); |
| 2233 | // D->beginEvent(); |
| 2234 | // D->area().append(* f); |
| 2235 | // D->run(); |
| 2236 | // } |
| 2237 | #endif |
| 2238 | |
| 2239 | TRGDebug::leaveStage("TRGCDC fastSimulation"); |
| 2240 | return; |
| 2241 | } |
| 2242 | |
| 2243 | void |
| 2244 | TRGCDC::storeSimulationResults(string collection2Dfinder, |
| 2245 | string collection2Dfitter, |
| 2246 | string collection3Dfitter) |
| 2247 | { |
| 2248 | TRGDebug::enterStage("TRGCDC storeSimulationResults"); |
| 2249 | |
| 2250 | // hits |
| 2251 | if (!(_fastSimulationMode & 2)) { |
| 2252 | StoreArray<CDCTriggerSegmentHit> storeSegmentHits; |
| 2253 | StoreArray<CDCHit> cdcHits(_cdchitCollectionName); |
| 2254 | for (unsigned its = 0; its < _segmentHits.size(); ++its) { |
| 2255 | const TCSHitTRGCDCSegmentHit* segmentHit = _segmentHits[its]; |
| 2256 | const CDCHit* priorityHit = cdcHits[segmentHit->iCDCHit()]; |
| 2257 | const TCSegmentTRGCDCSegment* segment = static_cast<const TCSegmentTRGCDCSegment*>(&segmentHit->cell()); |
| 2258 | const CDCTriggerSegmentHit* storeHit = |
| 2259 | storeSegmentHits.appendNew(*priorityHit, |
| 2260 | segment->id(), |
| 2261 | segment->priorityPosition(), |
| 2262 | segment->LUT()->getValue(segment->lutPattern()), |
| 2263 | segment->priorityTime(), |
| 2264 | segment->fastestTime(), |
| 2265 | segment->foundTime()); |
| 2266 | _tss[segment->id()]->addStoreHit(storeHit); |
| 2267 | // relation to all CDCHits in segment |
| 2268 | for (unsigned iw = 0; iw < segment->wires().size(); ++iw) { |
| 2269 | const TRGCDCWire* wire = (TRGCDCWire*)(*segment)[iw]; |
| 2270 | if (wire->signal().active()) { |
| 2271 | // priority wire has relation weight 2 |
| 2272 | double weight = (wire == &(segment->priority())) ? 2. : 1.; |
| 2273 | storeHit->addRelationTo(cdcHits[wire->hit()->iCDCHit()], weight); |
| 2274 | } |
| 2275 | } |
| 2276 | // relation to MCParticles (same as priority hit) |
| 2277 | RelationVector<MCParticle> mcrel = priorityHit->getRelationsFrom<MCParticle>(); |
| 2278 | for (unsigned imc = 0; imc < mcrel.size(); ++imc) { |
| 2279 | mcrel[imc]->addRelationTo(storeHit, mcrel.weight(imc)); |
| 2280 | } |
| 2281 | } |
| 2282 | } |
| 2283 | // event time |
| 2284 | StoreObjPtr<TRGTiming> eventTime("CDCTriggerEventTime"); |
| 2285 | eventTime.construct(Const::CDC, getEventTime()); |
| 2286 | // 2D finder tracks |
| 2287 | StoreArray<CDCTriggerTrack> storeTracks2Dfinder(collection2Dfinder); |
| 2288 | for (unsigned itr = 0; itr < _trackList2D.size(); ++itr) { |
| 2289 | const TCTrackTRGCDCTrack* track2D = _trackList2D[itr]; |
| 2290 | double phi0 = remainder(track2D->helix().phi0() + M_PI_21.57079632679489661923, 2. * M_PI3.14159265358979323846); |
| 2291 | double omega = track2D->charge() / track2D->helix().radius(); |
| 2292 | const CDCTriggerTrack* track = |
| 2293 | storeTracks2Dfinder.appendNew(phi0, omega, 0.); |
| 2294 | // relation to SegmentHits |
| 2295 | vector<TRGCDCLink*> links = track2D->links(); |
| 2296 | for (unsigned its = 0; its < links.size(); ++its) { |
| 2297 | const TRGCDCSegment* segment = static_cast<const TRGCDCSegment*>(links[its]->cell()); |
| 2298 | const vector<const CDCTriggerSegmentHit*> storeHits = segment->storeHits(); |
| 2299 | for (unsigned ihit = 0; ihit < storeHits.size(); ++ihit) { |
| 2300 | track->addRelationTo(storeHits[ihit]); |
| 2301 | } |
| 2302 | } |
| 2303 | } |
| 2304 | // 2D fitter tracks |
| 2305 | StoreArray<CDCTriggerTrack> storeTracks2Dfitter(collection2Dfitter); |
| 2306 | for (unsigned itr = 0; itr < _trackList2DFitted.size(); ++itr) { |
| 2307 | const TCTrackTRGCDCTrack* track2D = _trackList2DFitted[itr]; |
| 2308 | if (!track2D->fitted()) continue; |
| 2309 | double phi0 = remainder(track2D->helix().phi0() + M_PI_21.57079632679489661923, 2. * M_PI3.14159265358979323846); |
| 2310 | double omega = track2D->charge() / track2D->helix().radius(); |
| 2311 | double chi2 = track2D->get2DFitChi2(); |
| 2312 | const CDCTriggerTrack* track = |
| 2313 | storeTracks2Dfitter.appendNew(phi0, omega, chi2); |
| 2314 | // relation to SegmentHits |
| 2315 | vector<TRGCDCLink*> links = track2D->links(); |
| 2316 | for (unsigned its = 0; its < links.size(); ++its) { |
| 2317 | const TRGCDCSegment* segment = static_cast<const TRGCDCSegment*>(links[its]->cell()); |
| 2318 | const vector<const CDCTriggerSegmentHit*> storeHits = segment->storeHits(); |
| 2319 | for (unsigned ihit = 0; ihit < storeHits.size(); ++ihit) { |
| 2320 | track->addRelationTo(storeHits[ihit]); |
| 2321 | } |
| 2322 | } |
| 2323 | // relation to 2D finder, assuming same order in tracklist |
| 2324 | if (storeTracks2Dfinder.getEntries() > 0) |
| 2325 | storeTracks2Dfinder[itr]->addRelationTo(track); |
| 2326 | } |
| 2327 | // 3D tracks |
| 2328 | StoreArray<CDCTriggerTrack> storeTracks3Dfitter(collection3Dfitter); |
| 2329 | for (unsigned itr = 0; itr < _trackList3D.size(); ++itr) { |
| 2330 | const TCTrackTRGCDCTrack* track3D = _trackList3D[itr]; |
| 2331 | if (!track3D->fitted()) continue; |
| 2332 | double phi0 = remainder(track3D->helix().phi0() + M_PI_21.57079632679489661923, 2. * M_PI3.14159265358979323846); |
| 2333 | double omega = 1. / track3D->helix().radius(); |
| 2334 | double chi2 = track3D->get2DFitChi2(); |
| 2335 | double z = track3D->helix().dz(); |
| 2336 | double cot = track3D->helix().tanl(); |
| 2337 | double chi3 = track3D->get3DFitChi2(); |
| 2338 | const CDCTriggerTrack* track = |
| 2339 | storeTracks3Dfitter.appendNew(phi0, omega, chi2, z, cot, chi3); |
| 2340 | // relation to SegmentHits |
| 2341 | vector<TRGCDCLink*> links = track3D->links(); |
| 2342 | for (unsigned its = 0; its < links.size(); ++its) { |
| 2343 | const TRGCDCSegment* segment = static_cast<const TRGCDCSegment*>(links[its]->cell()); |
| 2344 | const vector<const CDCTriggerSegmentHit*> storeHits = segment->storeHits(); |
| 2345 | for (unsigned ihit = 0; ihit < storeHits.size(); ++ihit) { |
| 2346 | track->addRelationTo(storeHits[ihit]); |
| 2347 | } |
| 2348 | } |
| 2349 | // relation to 2D finder, assuming same order in tracklist |
| 2350 | if (storeTracks2Dfinder.getEntries() > 0) |
| 2351 | storeTracks2Dfinder[itr]->addRelationTo(track); |
| 2352 | } |
| 2353 | |
| 2354 | TRGDebug::leaveStage("TRGCDC storeSimulationResults"); |
| 2355 | return; |
| 2356 | } |
| 2357 | |
| 2358 | void |
| 2359 | TRGCDC::firmwareSimulation(void) |
| 2360 | { |
| 2361 | #ifdef TRGCDC_DISPLAY |
| 2362 | D->beginningOfEvent(); |
| 2363 | #endif |
| 2364 | |
| 2365 | TRGDebug::enterStage("TRGCDC firmwareSimulation"); |
| 2366 | |
| 2367 | //...Wire level simulation is in update(). |
| 2368 | |
| 2369 | //...Front ends... |
| 2370 | const unsigned nFronts = _fronts.size(); |
| 2371 | for (unsigned i = 0; i < nFronts; i++) { |
| 2372 | //...Skip inner-most FE because they have no contribution to TRG |
| 2373 | if (i < 10) |
| 2374 | continue; |
| 2375 | |
| 2376 | //...FE simulation... |
| 2377 | _fronts[i]->simulate(); |
| 2378 | } |
| 2379 | |
| 2380 | //...Mergers... |
| 2381 | const unsigned nMergers = _mergers.size(); |
| 2382 | for (unsigned i = 0; i < nMergers; i++) { |
| 2383 | _mergers[i]->simulate(); |
| 2384 | } |
| 2385 | |
| 2386 | //...TSFs... |
| 2387 | const unsigned nTSFBoards = _tsfboards.size(); |
| 2388 | for (unsigned i = 0; i < nTSFBoards; i++) { |
| 2389 | //iw _tsfboards[i]->simulateBoard(); |
| 2390 | // _tsfboards[i]->simulate(); |
| 2391 | _tsfboards[i]->simulate2(); |
| 2392 | } |
| 2393 | |
| 2394 | //...Event Time... In ns scale. |
| 2395 | // [FIXME] Not really firmware mode. Just for display. |
| 2396 | int t_eventTime = _eventTime.back()->getT0(); |
| 2397 | // Update WireHit driftTime using eventTime |
| 2398 | // [FIXME] This method is a temporary method. Next time change everything inside EventTime class. |
| 2399 | //cout<<"Hit timing "; |
| 2400 | for (unsigned iHits = 0; iHits < _hits.size(); iHits++) { |
| 2401 | //cout<<"["<<_hits[iHits]->wire().layerId()<<"]["<<_hits[iHits]->wire().localId()<<"]: "<<(_hits[iHits]->drift(0))<<" "; |
| 2402 | _hits[iHits]->setDriftTime((_hits[iHits]->drift(0) - t_eventTime) / 250, 0); |
| 2403 | _hits[iHits]->setDriftTime((_hits[iHits]->drift(1) - t_eventTime) / 250, 1); |
| 2404 | } |
| 2405 | //cout<< endl; |
| 2406 | //cout<<"Event timing: "<<t_eventTime<<endl; |
| 2407 | |
| 2408 | //...Tracker2D... |
| 2409 | const unsigned nTracker2Ds = _tracker2Ds.size(); |
| 2410 | for (unsigned i = 0; i < nTracker2Ds; i++) { |
| 2411 | _tracker2Ds[i]->simulate(); |
| 2412 | } |
| 2413 | |
| 2414 | #ifdef TRGCDC_DISPLAY |
| 2415 | dump("hits"); |
| 2416 | D->endOfEvent(); |
| 2417 | string stg = "Firmware simulation"; |
| 2418 | string inf = " "; |
| 2419 | D->clear(); |
| 2420 | D->stage(stg); |
| 2421 | D->information(inf); |
| 2422 | D->area().append(hits()); |
| 2423 | D->area().append(segmentHits()); |
| 2424 | D->show(); |
| 2425 | D->run(); |
| 2426 | // unsigned iFront = 0; |
| 2427 | // while (const TCFrontEnd * f = _cdc.frontEnd(iFront++)) { |
| 2428 | // D->clear(); |
| 2429 | // D->beginEvent(); |
| 2430 | // D->area().append(* f); |
| 2431 | // D->run(); |
| 2432 | // } |
| 2433 | // unsigned iMerger = 0; |
| 2434 | // while (const TCMerger * f = _cdc.merger(iMerger++)) { |
| 2435 | // D->clear(); |
| 2436 | // D->beginEvent(); |
| 2437 | // D->area().append(* f); |
| 2438 | // D->run(); |
| 2439 | // } |
| 2440 | #endif |
| 2441 | |
| 2442 | TRGDebug::leaveStage("TRGCDC firmwareSimulation"); |
| 2443 | } |
| 2444 | |
| 2445 | void |
| 2446 | TRGCDC::configure(void) |
| 2447 | { |
| 2448 | TRGDebug::enterStage("TRGCDC configure"); |
| 2449 | |
| 2450 | //...Open configuration file... |
| 2451 | ifstream infile(_configFilename.c_str(), ios::in); |
| 2452 | if (infile.fail()) { |
| 2453 | cout << "TRGCDC !!! can not open file" << endl |
| 2454 | << " " << _configFilename << endl; |
| 2455 | return; |
| 2456 | } |
| 2457 | |
| 2458 | //...Read configuration data... |
| 2459 | char b[800]; |
| 2460 | unsigned lines = 0; |
| 2461 | unsigned lastSl = 0; |
| 2462 | unsigned lastMergerLocalId = 0; |
| 2463 | while (! infile.eof()) { |
| 2464 | infile.getline(b, 800); |
| 2465 | const string l(b); |
| 2466 | string cdr = l; |
| 2467 | |
| 2468 | bool skip = false; |
| 2469 | unsigned wid = 0; |
| 2470 | unsigned lid = 0; |
| 2471 | unsigned fid = 0; |
| 2472 | unsigned mid = 0; |
| 2473 | unsigned tid = 0; |
| 2474 | // cppcheck-suppress knownConditionTrueFalse |
| 2475 | if (lid != 0) mid = lid + tid; //jb |
| 2476 | for (unsigned i = 0; i < 5; i++) { |
| 2477 | const string car = TRGUtilTRGUtilities::carstring(cdr); |
| 2478 | cdr = TRGUtilTRGUtilities::cdrstring(cdr); |
| 2479 | |
| 2480 | if (car == "#") { |
| 2481 | skip = true; |
| 2482 | break; |
| 2483 | } else if (car == "CDC") { |
| 2484 | skip = true; |
| 2485 | break; |
| 2486 | } |
| 2487 | |
| 2488 | if (i == 0) { |
| 2489 | wid = atoi(car.c_str()); |
| 2490 | } else if (i == 1) { |
| 2491 | lid = atoi(car.c_str()); |
Value stored to 'lid' is never read | |
| 2492 | } else if (i == 2) { |
| 2493 | fid = atoi(car.c_str()); |
| 2494 | } else if (i == 3) { |
| 2495 | mid = atoi(car.c_str()); |
| 2496 | } else if (i == 4) { |
| 2497 | tid = atoi(car.c_str()); |
| 2498 | } |
| 2499 | } |
| 2500 | |
| 2501 | if (skip) |
| 2502 | continue; |
| 2503 | if (lines != wid) |
| 2504 | continue; |
| 2505 | |
| 2506 | //...Super layer ID... |
| 2507 | const unsigned sl = _wires[wid]->superLayerId(); |
| 2508 | if (sl != lastSl) |
| 2509 | lastMergerLocalId = 0; |
| 2510 | |
| 2511 | //...Make a front-end board if necessary... |
| 2512 | bool newFrontEnd = false; |
| 2513 | TCFrontEndTRGCDCFrontEnd* f = 0; |
| 2514 | if (fid < _fronts.size()) |
| 2515 | f = _fronts[fid]; |
| 2516 | if (! f) { |
| 2517 | newFrontEnd = true; |
| 2518 | const string name = "CDCFrontEnd" + TRGUtilTRGUtilities::itostring(fid); |
| 2519 | TCFrontEndTRGCDCFrontEnd::boardType t; |
| 2520 | if (sl == 0) { |
| 2521 | if (_wires[wid]->localLayerId() < 5) |
| 2522 | t = TCFrontEndTRGCDCFrontEnd::innerInside; |
| 2523 | else |
| 2524 | t = TCFrontEndTRGCDCFrontEnd::innerOutside; |
| 2525 | } else { |
| 2526 | if (_wires[wid]->localLayerId() < 3) |
| 2527 | t = TCFrontEndTRGCDCFrontEnd::outerInside; |
| 2528 | else |
| 2529 | t = TCFrontEndTRGCDCFrontEnd::outerOutside; |
| 2530 | } |
| 2531 | f = new TCFrontEndTRGCDCFrontEnd(name, t, _clock, _clockD, _clockUser3125); |
| 2532 | |
| 2533 | _fronts.push_back(f); |
| 2534 | } |
| 2535 | f->push_back(_wires[wid]); |
| 2536 | |
| 2537 | //...Make a merger board if necessary... 2013,0908: physjg: I |
| 2538 | // think this should be done only when a new frontboard is |
| 2539 | // created. i.e., included in the if(!f) { .... } block. |
| 2540 | // Or I can put this part inside the new FrontEnd creation |
| 2541 | // part, well, seems not good in coding |
| 2542 | // |
| 2543 | bool newMerger = false; |
| 2544 | TCMergerTRGCDCMerger* m = nullptr; |
| 2545 | if (newFrontEnd) { |
| 2546 | if (mid != 99999) { |
| 2547 | if (mid < _mergers.size()) |
| 2548 | m = _mergers[mid]; |
| 2549 | if (! m) { |
| 2550 | newMerger = true; |
| 2551 | const string name = "CDCMerger" + TRGUtilTRGUtilities::itostring(sl) + |
| 2552 | "-" + TRGUtilTRGUtilities::itostring(lastMergerLocalId); |
| 2553 | TCMergerTRGCDCMerger::unitType mt; |
| 2554 | if (sl == 0) |
| 2555 | mt = TCMergerTRGCDCMerger::innerType; |
| 2556 | else |
| 2557 | mt = TCMergerTRGCDCMerger::outerType; |
| 2558 | m = new TCMergerTRGCDCMerger(name, |
| 2559 | mt, |
| 2560 | _clock, |
| 2561 | _clockD, |
| 2562 | _clockUser3125, |
| 2563 | _clockUser6250); |
| 2564 | _mergers.push_back(m); |
| 2565 | ++lastMergerLocalId; |
| 2566 | lastSl = sl; |
| 2567 | //cout << "new merger : " << name << endl; |
| 2568 | } |
| 2569 | m->push_back(f); |
| 2570 | } |
| 2571 | |
| 2572 | //...Make Aurora channel... |
| 2573 | if (f && m) { |
| 2574 | const string n = f->name() + string("-") + m->name(); |
| 2575 | TRGChannel* ch = new TRGChannel(n, *f, *m); |
| 2576 | f->appendOutput(ch); |
| 2577 | m->appendInput(ch); |
| 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | //...Make a TSF board if necessary... |
| 2582 | if (newMerger) { |
| 2583 | TSFinderTRGCDCTrackSegmentFinder* t = 0; |
| 2584 | if (tid != 99999) { |
| 2585 | if (tid < _tsfboards.size()) |
| 2586 | t = _tsfboards[tid]; |
| 2587 | if (!t) { |
| 2588 | const string name = "CDCTSFBoard" + TRGUtilTRGUtilities::itostring(tid); |
| 2589 | TSFinderTRGCDCTrackSegmentFinder::boardType tt; |
| 2590 | if (_wires[wid]->superLayerId() == 0) |
| 2591 | tt = TSFinderTRGCDCTrackSegmentFinder::innerType; |
| 2592 | else |
| 2593 | tt = TSFinderTRGCDCTrackSegmentFinder::outerType; |
| 2594 | t = new TSFinderTRGCDCTrackSegmentFinder(*this, |
| 2595 | name, |
| 2596 | tt, |
| 2597 | _clock, |
| 2598 | _clockD, |
| 2599 | _clockUser3125, |
| 2600 | _clockUser6250, |
| 2601 | _tsSL[tid]); |
| 2602 | _tsfboards.push_back(t); |
| 2603 | } |
| 2604 | t->push_back(m); |
| 2605 | } |
| 2606 | |
| 2607 | if (m && t) { |
| 2608 | const string n = m->name() + string("-") + t->name(); |
| 2609 | TRGChannel* chmt = new TRGChannel(n, *m, *t); |
| 2610 | m->appendOutput(chmt); |
| 2611 | t->appendInput(chmt); |
| 2612 | } |
| 2613 | } |
| 2614 | |
| 2615 | ++lines; |
| 2616 | } |
| 2617 | infile.close(); |
| 2618 | |
| 2619 | //...Make a 2D finder... |
| 2620 | for (unsigned i = 0; i < 4; i++) { |
| 2621 | const string name = "CDC2DBoard" + TRGUtilTRGUtilities::itostring(i); |
| 2622 | TCTracker2DTRGCDCTracker2D* t = new TCTracker2DTRGCDCTracker2D(name, |
| 2623 | _clock, |
| 2624 | _clockD, |
| 2625 | _clockUser6250, |
| 2626 | _clockUser6250); |
| 2627 | _tracker2Ds.push_back(t); |
| 2628 | for (unsigned j = 0; j < 9; j++) { |
| 2629 | TCTSFinderTRGCDCTrackSegmentFinder* tsf = _tsfboards[j]; |
| 2630 | const string n = tsf->name() + string("-") + t->name(); |
| 2631 | TRGChannel* ch = new TRGChannel(n, *tsf, *t); |
| 2632 | tsf->appendOutput(ch); |
| 2633 | t->appendInput(ch); |
| 2634 | } |
| 2635 | const string n = t->name() + string("-") + "CDC3DBoard" + TRGUtilTRGUtilities::itostring(i); |
| 2636 | TRGChannel* ch = new TRGChannel(n, *t, *t); |
| 2637 | // last (* t) should be 3D tracker in future |
| 2638 | t->appendOutput(ch); |
| 2639 | } |
| 2640 | |
| 2641 | //...For debug... |
| 2642 | if (TRGDebug::level()) { |
| 2643 | cout << TRGDebug::tab() << "TSF configuration" << endl; |
| 2644 | for (unsigned i = 0; i < _tsfboards.size(); i++) { |
| 2645 | const TSFinderTRGCDCTrackSegmentFinder& t = *_tsfboards[i]; |
| 2646 | t.dump("detail", TRGDebug::tab() + " "); |
| 2647 | } |
| 2648 | cout << TRGDebug::tab() << "Tracker2D configuration" << endl; |
| 2649 | for (unsigned i = 0; i < _tracker2Ds.size(); i++) { |
| 2650 | const TCTracker2DTRGCDCTracker2D& t = *_tracker2Ds[i]; |
| 2651 | t.dump("detail", TRGDebug::tab() + " "); |
| 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | TRGDebug::leaveStage("TRGCDC configure"); |
| 2656 | } |
| 2657 | |
| 2658 | const TRGCDCSegment& |
| 2659 | TRGCDC::segment(unsigned lid, unsigned id) const |
| 2660 | { |
| 2661 | return *(const TRGCDCSegment*)(* _tsLayers[lid])[id]; |
| 2662 | } |
| 2663 | |
| 2664 | //jb void |
| 2665 | //jb TRGCDC::perfect3DFinder(vector<TCTrack*> trackList) const { |
| 2666 | //jb |
| 2667 | //jb TRGDebug::enterStage("Perfect 3D Finder"); |
| 2668 | //jb if (TRGDebug::level()) |
| 2669 | //jb cout << TRGDebug::tab() << "givenTrk#=" << trackList.size() << endl; |
| 2670 | //jb |
| 2671 | //jb //...Track loop.... |
| 2672 | //jb for (unsigned j = 0; j < trackList.size(); j++) { |
| 2673 | //jb |
| 2674 | //jb //...G4 trackID... |
| 2675 | //jb TCTrack * trk = trackList[j]; |
| 2676 | //jb unsigned id = trackList[j]->relation().contributor(0); |
| 2677 | //jb vector<const TCSHit*> tsList[9]; |
| 2678 | //jb |
| 2679 | //jb //...Segment loop... |
| 2680 | //jb const vector<const TCSHit*> hits = segmentHits(); |
| 2681 | //jb for (unsigned i = 0; i < hits.size(); i++) { |
| 2682 | //jb const TCSHit & ts = * hits[i]; |
| 2683 | //jb if (ts.segment().axial()) continue; |
| 2684 | //jb if (! ts.signal().active()) continue; |
| 2685 | //jb const TCWHit * wh = ts.segment().center().hit(); |
| 2686 | //jb if (! wh) continue; |
| 2687 | //jb const unsigned trackId = wh->iMCParticle(); |
| 2688 | //jb |
| 2689 | //jb if (id == trackId) |
| 2690 | //jb tsList[wh->wire().superLayerId()].push_back(& ts); |
| 2691 | //jb } |
| 2692 | //jb |
| 2693 | //jb if (TRGDebug::level()) { |
| 2694 | //jb cout << TRGDebug::tab() << "trk#" << j << endl; |
| 2695 | //jb for (unsigned k = 0; k < 9; k++) { |
| 2696 | //jb if (k % 2) { |
| 2697 | //jb cout << TRGDebug::tab(4) << "superlayer " << k << ":"; |
| 2698 | //jb for (unsigned l = 0; l < tsList[k].size(); l++) { |
| 2699 | //jb if (l) |
| 2700 | //jb cout << ","; |
| 2701 | //jb cout << tsList[k][l]->cell().name(); |
| 2702 | //jb } |
| 2703 | //jb cout << endl; |
| 2704 | //jb } |
| 2705 | //jb } |
| 2706 | //jb } |
| 2707 | //jb |
| 2708 | //jb //...Select best one in each super layer... |
| 2709 | //jb for (unsigned i = 0; i < 9; i++) { |
| 2710 | //jb const TCSHit * best = 0; |
| 2711 | //jb if (tsList[i].size() == 0) { |
| 2712 | //jb continue; |
| 2713 | //jb } else if (tsList[i].size() == 1) { |
| 2714 | //jb best = tsList[i][0]; |
| 2715 | //jb } else { |
| 2716 | //jb int timeMin = 99999; |
| 2717 | //jb for (unsigned k = 0; k < tsList[i].size(); k++) { |
| 2718 | //jb const TRGSignal & signal = tsList[i][k]->signal(); |
| 2719 | //jb const TRGTime & t = * signal[0]; |
| 2720 | //jb if (t.time() < timeMin) { |
| 2721 | //jb timeMin = t.time(); |
| 2722 | //jb best = tsList[i][k]; |
| 2723 | //jb } |
| 2724 | //jb } |
| 2725 | //jb } |
| 2726 | //jb //trk->append(new TCLink(0, |
| 2727 | //jb // best, |
| 2728 | //jb // best->cell().xyPosition())); |
| 2729 | //jb } |
| 2730 | //jb |
| 2731 | //jb if (TRGDebug::level()) |
| 2732 | //jb trk->dump("", "> "); |
| 2733 | //jb |
| 2734 | //jb } |
| 2735 | //jb |
| 2736 | //jb TRGDebug::leaveStage("Perfect 3D Finder"); |
| 2737 | //jb } |
| 2738 | |
| 2739 | int TRGCDC::getEventTime(void) const |
| 2740 | { |
| 2741 | return _eventTime.back()->getT0(); |
| 2742 | } |
| 2743 | |
| 2744 | void TRGCDC::setReturnValue(EReturnValueType const& moduleName, bool flag) |
| 2745 | { |
| 2746 | if (flag) _returnValue |= moduleName; |
| 2747 | else _returnValue &= ~moduleName; |
| 2748 | } |
| 2749 | |
| 2750 | int TRGCDC::getReturnValue(EReturnValueType const& moduleName) const |
| 2751 | { |
| 2752 | return _returnValue & moduleName; |
| 2753 | } |
| 2754 | |
| 2755 | |
| 2756 | void TRGCDC::saveCDCHitInformation(vector<vector<unsigned>>& hitWiresFromCDC) |
| 2757 | { |
| 2758 | TClonesArray& rootCDCHitInformation = *m_rootCDCHitInformation; |
| 2759 | rootCDCHitInformation.Clear(); |
| 2760 | for (unsigned iHit = 0; iHit < hitWiresFromCDC.size(); iHit++) { |
| 2761 | TVectorD t_rootCDCHitInformation(5); |
| 2762 | t_rootCDCHitInformation[0] = hitWiresFromCDC[iHit][0]; |
| 2763 | t_rootCDCHitInformation[1] = hitWiresFromCDC[iHit][1]; |
| 2764 | t_rootCDCHitInformation[2] = hitWiresFromCDC[iHit][2]; |
| 2765 | t_rootCDCHitInformation[3] = hitWiresFromCDC[iHit][3]; |
| 2766 | t_rootCDCHitInformation[4] = hitWiresFromCDC[iHit][4]; |
| 2767 | new (rootCDCHitInformation[iHit]) TVectorD(t_rootCDCHitInformation); |
| 2768 | } // End of hit loop |
| 2769 | } |
| 2770 | |
| 2771 | void TRGCDC::saveTRGHitInformation(vector<vector<int>>& hitWiresFromTRG) |
| 2772 | { |
| 2773 | TClonesArray& rootTRGHitInformation = *m_rootTRGHitInformation; |
| 2774 | rootTRGHitInformation.Clear(); |
| 2775 | for (unsigned iHit = 0; iHit < hitWiresFromTRG.size(); iHit++) { |
| 2776 | TVectorD t_rootTRGHitInformation(4); |
| 2777 | t_rootTRGHitInformation[0] = hitWiresFromTRG[iHit][0]; |
| 2778 | t_rootTRGHitInformation[1] = hitWiresFromTRG[iHit][1]; |
| 2779 | t_rootTRGHitInformation[2] = hitWiresFromTRG[iHit][2]; |
| 2780 | t_rootTRGHitInformation[3] = hitWiresFromTRG[iHit][3]; |
| 2781 | new (rootTRGHitInformation[iHit]) TVectorD(t_rootTRGHitInformation); |
| 2782 | } // End of hit loop |
| 2783 | } |
| 2784 | |
| 2785 | void TRGCDC::saveTRGRawInformation(vector<string >& trgInformations) |
| 2786 | { |
| 2787 | TClonesArray& rootTRGRawInformation = *m_rootTRGRawInformation; |
| 2788 | rootTRGRawInformation.Clear(); |
| 2789 | for (unsigned iWindow = 0; iWindow < trgInformations.size(); iWindow++) { |
| 2790 | TObjString t_rootTRGRawInformation; |
| 2791 | t_rootTRGRawInformation.SetString(trgInformations[iWindow].c_str()); |
| 2792 | new (rootTRGRawInformation[iWindow]) TObjString(t_rootTRGRawInformation); |
| 2793 | } // End of hit loop |
| 2794 | } |
| 2795 | |
| 2796 | //void TRGCDC::saveCDCTRGTimeMatchInformation(vector<vector<map<int, int> > >& hitTimingComp) { |
| 2797 | // |
| 2798 | // TClonesArray& CDCTRGTimeMatch = *m_CDCTRGTimeMatch; |
| 2799 | // CDCTRGTimeMatch.Clear(); |
| 2800 | // int nTotalHits = 0; |
| 2801 | // for(unsigned iLayer=0; iLayer<5; iLayer++){ |
| 2802 | // for(unsigned iWire=0; iWire<16; iWire++){ |
| 2803 | // for(map<int, int>::iterator it = hitTimingComp[iLayer][iWire].begin(); it != hitTimingComp[iLayer][iWire].end(); it++){ |
| 2804 | // TVectorD t_CDCTRGTimeMatch(4); |
| 2805 | // t_CDCTRGTimeMatch[0] = iLayer; |
| 2806 | // t_CDCTRGTimeMatch[1] = iWire; |
| 2807 | // t_CDCTRGTimeMatch[2] = (*it).first; |
| 2808 | // t_CDCTRGTimeMatch[3] = (*it).second; |
| 2809 | // new(CDCTRGTimeMatch[nTotalHits++]) TVectorD(t_CDCTRGTimeMatch); |
| 2810 | // } |
| 2811 | // } // End of wire loop |
| 2812 | // } // End of layer loop |
| 2813 | // |
| 2814 | //} |
| 2815 | |
| 2816 | unsigned |
| 2817 | TRGCDC::nSegments(unsigned id) const |
| 2818 | { |
| 2819 | if (id < _tsLayers.size()) |
| 2820 | return _tsLayers[id]->size(); |
| 2821 | return 0; |
| 2822 | } |
| 2823 | |
| 2824 | } // namespace Belle2 |