MyMarlinTPC  170316
TimePixLocalRoadSearchProcessor.cc
Go to the documentation of this file.
1 // #ifdef USE_TPROADS
3 
5 
6 #include <iostream>
7 #include <string>
8 #include <ctime>
9 #include <cmath>
10 
11 //GEAR
12 #include <gear/TPCParameters.h>
13 #include <gear/BField.h>
14 #include <gearimpl/Vector3D.h>
15 
16 // include what you need from lcio
17 #include <EVENT/LCEvent.h>
18 #include <IMPL/LCCollectionVec.h>
19 #include <UTIL/BitField64.h>
20 #include <UTIL/ILDConf.h>
21 #include <IMPL/TrackerHitImpl.h>
22 #include <IMPL/TrackImpl.h>
23 #include <IMPL/LCFlagImpl.h>
24 #include <Exceptions.h>
25 
26 // this is the inserted part
27 
28 using namespace lcio;
29 using namespace marlin;
30 using namespace std;
31 using namespace gear;
32 
33 namespace marlintpc {
34 
35 static bool comparePixelsZ(tp_Pixel* one, tp_Pixel* two) {
36  return ((one->getZ()) < (two->getZ())); // increasing
37 }
38 
39 static bool comparePixelsS(tp_Pixel* one, tp_Pixel* two) {
40  return ((one->getArcLength()) < (two->getArcLength())); // increasing
41 }
42 
43 static bool compareSegments(tp_PixelSegment* one, tp_PixelSegment* two) {
44  return ((one->getLength()) > (two->getLength())); // decreasing
45 }
46 
48 
50 TimePixLocalRoadSearchProcessor::TimePixLocalRoadSearchProcessor() :
51  Processor("TimePixLocalRoadSearchProcessor") {
52  // the processor description
53  _description = "TimePixLocalRoadSearchProcessor is intended to ...";
54 
55  registerInputCollection(LCIO::TRACKERHIT, "InputHits", "Name of the input Hit Collection", _inputColName, string("TPCHits"));
56  registerOutputCollection(LCIO::TRACK, "OutputTracks", "Name of the output Track Collection", _outputColName,
57  string("RoadSearchTracks"));
58 
59  registerOptionalParameter("BFieldScaleFactor", "Scales magnetic field (map), use 1.0 (default) for field ON or 0.0 for field OFF",
60  _bfieldScaleFactor, double(1.0));
61 
62  registerProcessorParameter("MinTrackLevel", "Min. track level", _minTrackLevel, int(1));
63 
64  registerProcessorParameter("MacroPixelSize", "Macro pixel (bin) size", _mpSize, int(32));
65 
66  registerProcessorParameter("MinZmeas", "Min. measured Z value", _minZmeas, double(0.001));
67 
68  registerProcessorParameter("MaxZmeas", "Max. measured Z value", _maxZmeas, double(600.));
69 
70  registerProcessorParameter("SigmaZ", "Resolution in Z (for clustering)", _sigmaZ, double(3.0));
71 
72  registerProcessorParameter("Xoffset", "Offset in x of (local) coordinate system", _xOffset, double(0.));
73 
74  registerProcessorParameter("Yoffset", "Offset in y of (local) coordinate system", _yOffset, double(1500.));
75 
76  registerProcessorParameter("MaxMult", "Max. multiplicity for road seeding bins", _maxMult, int(3));
77 
78  registerProcessorParameter("MinPixels", "Min. number of pixels for road seeding macro pixel", _minPixels, int(3));
79 
80  registerOptionalParameter("MinDist", "Min. distance for road seeding bins", _minDist, int(2));
81 
82  registerOptionalParameter("MaxPull2XY", "Max. pull squared to road in XY", _maxPull2XY, double(15.));
83 
84  registerOptionalParameter("MaxPull2Z", "Max. pull squared to road in Z", _maxPull2Z, double(15.));
85 
86  registerOptionalParameter("MaxChi2", "Max. Chi2/Ndf for road", _maxChi2, double(5.));
87 
88  registerOptionalParameter("MaxSvar", "Max. relative arc-length variance for road", _maxSvar, double(0.15));
89 
90  registerOptionalParameter("MaxGap", "Max. (arc-length) gap for road", _maxGap, double(4.));
91 
92  registerOptionalParameter("OctoboardOffset", "Octoboard number offset (in module=(octo+offset)/scale)", _octoOffset, int(8));
93 
94  registerOptionalParameter("OctoboardScale", "Octoboard number scale (in module=(octo+offset)/scale)", _octoScale, int(12));
95 
96  registerOptionalParameter("Chi2CutChip", "Max. Chi2/Ndf for chip segment matching", _chi2CutChip, double(30.));
97 
98  registerOptionalParameter("Chi2CutOcto", "Max. Chi2/Ndf for octoboard segment matching", _chi2CutOcto, double(30.));
99 
100  registerOptionalParameter("Chi2CutMod", "Max. Chi2/Ndf for module segment matching", _chi2CutMod, double(50.));
101 
102  registerOptionalParameter("DistCut", "Max. relative (to track length sum) distance (of centers) for segment matching", _distCut,
103  double(2.));
104 
105  registerOptionalParameter("ReferencePointAtPca", "Use PCA as reference point, else 1. hit", _refAtPCA, bool(false));
106 
107 }
108 
111  streamlog_out(DEBUG) << " init() called " << endl;
112 }
113 
115  // do something for each run
116 }
117 
120  std::clock_t start1 = std::clock();
121 
122  streamlog_out(DEBUG) << "Event Number: " << evt->getEventNumber() << endl;
123 
124  //get input collection
125  LCCollection* inputCol = 0;
126 
127  LCCollectionVec* outputCol = new LCCollectionVec(LCIO::TRACK);
128  LCFlagImpl trkFlag(0);
129  trkFlag.setBit(LCIO::TRBIT_HITS);
130  outputCol->setFlag(trkFlag.getFlag());
131 
132  // do a try / catch in case there is an empty event
133  try {
134  inputCol = evt->getCollection(_inputColName);
135  } catch (DataNotAvailableException &e) {
136  // no input data, just return and process the next event
137  return;
138  }
139 
140  Vector3D theTPCCenter(_Xcenter, _Ycenter, 0.);
141  Vector3D bfield = marlin::Global::GEAR->getBField().at(theTPCCenter);
142 
143  const bool bOff(bfield.z() * _bfieldScaleFactor == 0.);
144  if (bOff) {
145  streamlog_out(DEBUG) << "BField(GEAR) is OFF" << std::endl;
146  } else {
147  streamlog_out(DEBUG) << "BField(GEAR) is ON" << std::endl;
148  }
149  // constant magnetic field (in z direction)
150  _Bzc = bfield.z() * _bfieldScaleFactor * 0.0002998; // Bz*c
151 
152  int iCuts[] = { _maxMult, _minPixels, _minDist };
153  double dCuts[] = { _maxPull2XY, _maxPull2Z, _maxChi2, _maxSvar, _maxGap };
154 
156  chipPixelMapType pixelData;
157 
158  int nInput = inputCol->getNumberOfElements();
159 
160  /*std::map<int,int> chipMap;
161  for (int iInput = 0; iInput < nInput; iInput++) {
162  TrackerHit* Hit = dynamic_cast<TrackerHit*>(inputCol->getElementAt(iInput));
163  int chip = Hit->getCellID1();
164  chipMap[chip]++;
165  }
166  for (std::map<int,int>::iterator itChip = chipMap.begin(); itChip != chipMap.end(); ++itChip) {
167  //std::cout << " chip Map " << itChip->first << " " << itChip->second << std::endl;
168  //pixelData[itChip->first].reserve(itChip->second);
169  } */
170 
171  int nAccepted = 0;
172  for (int iInput = 0; iInput < nInput; iInput++) {
173  TrackerHit* Hit = dynamic_cast<TrackerHit*>(inputCol->getElementAt(iInput));
174  int chip = Hit->getCellID1();
175  double zMeas = Hit->getPosition()[2];
176  if (zMeas > _minZmeas && zMeas < _maxZmeas) {
177  nAccepted++;
178  tp_Pixel* somePixel = new tp_Pixel(iInput, *Hit, _xOffset, _yOffset);
179  //somePixel->print();
180  pixelData[chip].push_back(somePixel);
181  }
182  }
183 
184  streamlog_out(DEBUG) << "Event " << evt->getEventNumber() << " in run " << evt->getRunNumber() << ", number of input hits: "
185  << nInput << ", accepted (in Z): " << nAccepted << endl;
186 
188  pixelChipListType pixelChips;
189  for (chipPixelMapType::iterator itChip = pixelData.begin(); itChip != pixelData.end(); ++itChip) {
190  tp_PixelChip* someChip = new tp_PixelChip(itChip->first, itChip->second, _mpSize, _sigmaZ);
191  //someChip->print();
192  if (someChip->getNumBins() > 1)
193  pixelChips.push_back(someChip);
194  else
195  delete someChip;
196  }
197 
199  int numSeg = 0;
200  for (pixelChipListType::iterator itChip = pixelChips.begin(); itChip != pixelChips.end(); ++itChip) {
201  //(*itChip)->print();
202  numSeg += (*itChip)->findSegments(_Bzc, iCuts, dCuts);
203  }
204  streamlog_out(DEBUG) << " found " << pixelChips.size() << " TimePix chips with " << numSeg << " segments " << endl;
206  tp_PixelSegmentCombiner segmentCombiner(_Bzc);
207  pixelSegmentListMapType chipSegmentMap, octoSegmentMap;
208  pixelSegmentListType modSegmentList;
209  for (pixelChipListType::iterator itChip = pixelChips.begin(); itChip != pixelChips.end(); ++itChip) {
210  const int iOcto = (*itChip)->getId() / 8;
211  pixelSegmentListType segments = (*itChip)->getPixelSegments();
212  if (segments.size() > 0) chipSegmentMap[iOcto].insert(chipSegmentMap[iOcto].end(), segments.begin(), segments.end());
213  //for (pixelSegmentListType::iterator itSeg = segments.begin(); itSeg != segments.end(); ++itSeg) (*itSeg)->print();
214  }
215  // combine chips on octoboards
216  for (pixelSegmentListMapType::iterator itOcto = chipSegmentMap.begin(); itOcto != chipSegmentMap.end(); ++itOcto) {
217  const int iOcto = itOcto->first;
218  // std::cout << " combine octoboard " << iOcto << " " << itOcto->second.size() << std::endl;
219  pixelSegmentListType combinedSegments = segmentCombiner.run(1, iOcto, itOcto->second, _chi2CutChip, _distCut);
220  // \todo variable octoboard to module mapping
221  const int iMod = (iOcto + _octoOffset) / _octoScale;
222  octoSegmentMap[iMod].insert(octoSegmentMap[iMod].end(), combinedSegments.begin(), combinedSegments.end());
223  }
224  // combine octoboards per module
225  for (pixelSegmentListMapType::iterator itMod = octoSegmentMap.begin(); itMod != octoSegmentMap.end(); ++itMod) {
226  const int iMod = itMod->first;
227  // std::cout << " combine module " << iMod << " " << itMod->second.size() << std::endl;
228  pixelSegmentListType combinedSegments = segmentCombiner.run(2, iMod, itMod->second, _chi2CutOcto, _distCut);
229  modSegmentList.insert(modSegmentList.end(), combinedSegments.begin(), combinedSegments.end());
230  }
231  // combine modules
232  // std::cout << " combine modules " << modSegmentList.size() << std::endl;
233  pixelSegmentListType trackCandidates = segmentCombiner.run(3, 0, modSegmentList, _chi2CutMod, _distCut);
234  // sort by length
235  sort(trackCandidates.begin(), trackCandidates.end(), compareSegments);
236  // std::cout << " === track condidates ===" << std::endl;
237  // for (pixelSegmentListType::iterator itSeg = trackCandidates.begin(); itSeg != trackCandidates.end(); ++itSeg) (*itSeg)->print();
238 
239  streamlog_out(DEBUG) << " found " << trackCandidates.size() << " track candidates " << endl;
240 
242  for (pixelSegmentListType::iterator itSeg = trackCandidates.begin(); itSeg != trackCandidates.end(); ++itSeg) {
243  if ((*itSeg)->getLevel() < _minTrackLevel) continue;
244  // new track
245  TrackImpl* theTrack = new TrackImpl();
246  // get hits/pixels
247  pixelListType allPixels;
248  macroPixelListType macroPixels = (*itSeg)->getMacroPixels();
249  for (macroPixelListType::iterator itMpix = macroPixels.begin(); itMpix != macroPixels.end(); ++itMpix) {
250  pixelListType pixels = (*itMpix)->getPixels();
251  allPixels.insert(allPixels.end(), pixels.begin(), pixels.end());
252  }
253  // sort by arc length
254  sort(allPixels.begin(), allPixels.end(), comparePixelsS);
255  // position of 1. hit
256  double posFirst[3];
257  allPixels.front()->getPos(posFirst);
258  // reference point, 1. hit or PCA (point of closest approach (to origin))
259  double refPos[] = { 0., 0., 0. };
260  if (!_refAtPCA) {
261  refPos[0] = posFirst[0];
262  refPos[1] = posFirst[1];
263  refPos[2] = posFirst[2];
264  }
265  float refPoint[3] = { refPos[0] - _xOffset, refPos[1] - _yOffset, refPos[2] };
266  // track parameters and covariance matrix
267  TVectorD parameters(5);
268  TMatrixDSym covariance(5);
269  (*itSeg)->getLCIOStateAtRefPoint(refPos, parameters, covariance); // ( d0, phi0, Omega, z0, tanLambda)
270 
271  theTrack->setOmega(parameters[2]);
272  theTrack->setTanLambda(parameters[4]);
273  theTrack->setPhi(parameters[1]);
274  theTrack->setD0(parameters[0]);
275  theTrack->setZ0(parameters[3]);
276  theTrack->setChi2((*itSeg)->getChi2());
277  theTrack->setNdf((*itSeg)->getNdf());
278  theTrack->setReferencePoint(refPoint);
279  /* prepare LCIO output; unknown parts:
280  *
281  * theTrack->setTypeBit (int index, bool val=true) // ?
282  * theTrack->setdEdx (float dEdx)
283  * theTrack->setdEdxError (float dEdxError) */
284  float rInner = sqrt(pow(posFirst[0], 2) + pow(posFirst[1], 2));
285  theTrack->setRadiusOfInnermostHit(rInner);
286  // compressed covariance matrix
287  float compressedCovariance[15];
288  int ind = 0;
289  for (int i = 0; i < 5; ++i)
290  for (int j = 0; j <= i; ++j)
291  compressedCovariance[ind++] = covariance[i][j];
292  theTrack->setCovMatrix(compressedCovariance);
293  // and finally add the hits to the track
294  for (pixelListType::iterator itP = allPixels.begin(); itP != allPixels.end(); ++itP) {
295  TrackerHit* Hit = dynamic_cast<TrackerHit*>(inputCol->getElementAt((*itP)->getHitNum()));
296  theTrack->addHit(Hit);
297  }
298 
299  streamlog_out(DEBUG) << " +++ the found track has a chi^2 value of " << theTrack->getChi2() << " for ndf = "
300  << theTrack->getNdf() << " and the parameters [omega, tanLambda, phi0, d0, z0] = [" << theTrack->getOmega() << ","
301  << theTrack->getTanLambda() << "," << theTrack->getPhi() << "," << theTrack->getD0() << "," << theTrack->getZ0()
302  << "] at the reference position [" << refPoint[0] << "," << refPoint[1] << "," << refPoint[2] << "]." << endl;
303 
304  outputCol->addElement(theTrack);
305  }
306 
307  streamlog_out(DEBUG) << "TimePixLocalRoadSearch ... done!" << endl;
308 
309  if (!outputCol->empty()) {
310  evt->addCollection(outputCol, _outputColName);
311  }
312 
313  streamlog_out(DEBUG) << ((std::clock() - start1) / (double) CLOCKS_PER_SEC) << " sec" << endl;
314 
315  // cleanup
316  for (pixelSegmentListType::iterator itSeg = trackCandidates.begin(); itSeg != trackCandidates.end(); ++itSeg) {
317  delete *itSeg;
318  }
319  trackCandidates.clear();
320 
321  for (pixelChipListType::iterator itChip = pixelChips.begin(); itChip != pixelChips.end(); ++itChip) {
322  delete *itChip;
323  }
324  pixelChips.clear();
325 
326  for (chipPixelMapType::iterator itChip = pixelData.begin(); itChip != pixelData.end(); ++itChip) {
327  for (pixelListType::iterator itP = itChip->second.begin(); itP != itChip->second.end(); ++itP) {
328  delete *itP;
329  }
330  }
331  pixelData.clear();
332 
333 }
334 
336  // check what is needed here
337 }
338 
340  // do something at the end of the processing, e.g. cleaning up
341 
342 }
343 
345 
351 tp_Pixel::tp_Pixel(const int iHit, const TrackerHit& aHit, const double xOffset, const double yOffset) :
352  _hitNum(iHit), _chipNum(aHit.getCellID1()), _rowNum(aHit.getCellID0() / 256), _colNum(aHit.getCellID0() % 256), _posX(
353  aHit.getPosition()[0] + xOffset), _posY(aHit.getPosition()[1] + yOffset), _posZ(aHit.getPosition()[2]), _sigma2XY(
354  0.5 * (aHit.getCovMatrix()[0] + aHit.getCovMatrix()[2])), _sigma2Z(aHit.getCovMatrix()[5]), _used(false), _sarc(0.) {
355 }
356 
358 void tp_Pixel::print() const {
359  std::cout << " tp_Pixel " << _hitNum << ", " << _chipNum << ", " << _rowNum << ", " << _colNum << ", " << _posX << ", " << _posY
360  << ", " << _posZ << "; " << _sigma2XY << ", " << _sigma2Z << std::endl;
361 }
362 
364 int tp_Pixel::getHitNum() const {
365  return _hitNum;
366 }
367 
369 int tp_Pixel::getChip() const {
370  return _chipNum;
371 }
372 
374 int tp_Pixel::getRow() const {
375  return _rowNum;
376 }
377 
379 int tp_Pixel::getCol() const {
380  return _colNum;
381 }
382 
384 double tp_Pixel::getX() const {
385  return _posX;
386 }
387 
389 double tp_Pixel::getY() const {
390  return _posY;
391 }
392 
394 double tp_Pixel::getZ() const {
395  return _posZ;
396 }
397 
399 
402 void tp_Pixel::getPos(double* position) const {
403  position[0] = _posX;
404  position[1] = _posY;
405  position[2] = _posZ;
406 }
407 
409 double tp_Pixel::getSigma2XY() const {
410  return _sigma2XY;
411 }
412 
414 double tp_Pixel::getSigma2Z() const {
415  return _sigma2Z;
416 }
417 
419 bool tp_Pixel::getUsed() const {
420  return _used;
421 }
422 
424 double tp_Pixel::getArcLength() const {
425  return _sarc;
426 }
427 
430  _used = true;
431 }
432 
434 void tp_Pixel::setArcLength(const double sArc) {
435  _sarc = sArc;
436 }
437 
439 
444 tp_MacroPixel::tp_MacroPixel(const int mpId, pixelListType& pixelList, const int mpSize) :
445  _mpId(mpId), _size(mpSize), _entries(pixelList.size()), _pixels(pixelList), _used(false) {
446  // analyze cluster, avaerge over pixels
447  int sr, sc;
448  sr = sc = 0;
449  double sx, sy, sz, sxx, sxy, syy, szz, srxy, srz;
450  sx = sy = sz = sxx = sxy = syy = szz = srxy = srz = 0.;
451  double pos[3];
452  for (pixelListType::iterator itP = _pixels.begin(); itP != _pixels.end(); ++itP) {
453  int row = (*itP)->getRow();
454  int col = (*itP)->getCol();
455  sr += row;
456  sc += col;
457  (*itP)->getPos(pos);
458  sx += pos[0];
459  sy += pos[1];
460  sz += pos[2];
461  sxx += pos[0] * pos[0];
462  sxy += pos[0] * pos[1];
463  syy += pos[1] * pos[1];
464  szz += pos[2] * pos[2];
465  srxy += (*itP)->getSigma2XY();
466  srz += (*itP)->getSigma2Z();
467  }
468  // local position
469  _locRow = sr / _entries;
470  _locCol = sc / _entries;
471  // (global) position
472  _posX = sx / _entries;
473  _posY = sy / _entries;
474  _posZ = sz / _entries;
475  // shape (variance)
476  _varXX = sxx / _entries - _posX * _posX;
477  _varXY = sxy / _entries - _posX * _posY;
478  _varYY = syy / _entries - _posY * _posY;
479  _varZZ = szz / _entries - _posZ * _posZ;
480  // resolution
481  _sigma2XY = srxy / _entries;
482  _sigma2Z = srz / _entries;
483 }
484 
487  //std::cout << " destroying tp_MacroPixel " << _mpId << std::endl;
488  _pixels.clear();
489 }
490 
492 void tp_MacroPixel::print() const {
493  std::cout << " tp_MacroPixel " << _mpId << ", " << _entries << ", " << _locRow << ", " << _locCol << ", " << _posX << ", "
494  << _posY << ", " << _posZ << "; " << _varXX << ", " << _varXY << ", " << _varYY << ", " << _varZZ << std::endl;
495 }
496 
498 int tp_MacroPixel::getId() const {
499  return _mpId;
500 }
501 
504  return _size;
505 }
506 
509  return _entries;
510 }
511 
514  return _locRow;
515 }
516 
519  return _locCol;
520 }
521 
524  return _sigma2XY;
525 }
526 
529  return _sigma2Z;
530 }
531 
533 double tp_MacroPixel::getX() const {
534  return _posX;
535 }
536 
538 double tp_MacroPixel::getY() const {
539  return _posY;
540 }
541 
543 
546 void tp_MacroPixel::getPos(double* position) const {
547  position[0] = _posX;
548  position[1] = _posY;
549  position[2] = _posZ;
550 }
551 
553 double tp_MacroPixel::getVarXY(const double ex, const double ey) const {
554  return ex * ex * _varXX + 2. * ex * ey * _varXY + ey * ey * _varYY;
555 }
556 
558 double tp_MacroPixel::getVarZ() const {
559  return _varZZ;
560 }
561 
564  return _used;
565 }
566 
569  _used = true;
570 }
571 
574  return _pixels;
575 }
576 
578 
589 tp_PixelBin::tp_PixelBin(const int iBin, const int binId, pixelListType& pixelList, const int mpSize, const double zCoreWidth,
590  const double zRoadWidth) :
591  _binId(binId), _size(mpSize), _numPix(0), _macroPixels() {
592  // check for cluster (core) in Z (using sliding window)
593  int numMp = 0;
594  int ntot = pixelList.size();
595  //std:: cout << " ntot " << ntot << " " << binId <<std::endl;
596  pixelListType::iterator itFirst = pixelList.begin();
597  pixelListType::iterator itLast = pixelList.end();
598  int ntry = 0;
599 
600  while (ntot > 1) {
601  ntry++;
602  int bestNumPix = 0;
603  double bestZPos = 0.;
604  pixelListType::iterator itStart = itFirst;
605  double zStart = (*itStart)->getZ();
606  pixelListType::iterator itBest = itStart;
607  int numPix = 1;
608  double sumZ = zStart;
609  // sliding window
610  pixelListType::iterator itP = itStart;
611  while (++itP < itLast) {
612  if ((*itP)->getUsed()) continue;
613  // unused
614  double z = (*itP)->getZ();
615  if (z - zStart > 2. * zCoreWidth) {
616  if (numPix > bestNumPix) {
617  itBest = itStart;
618  bestNumPix = numPix;
619  bestZPos = sumZ / numPix;
620  }
621  // new window start
622  while (++itStart < itLast) {
623  if ((*itStart)->getUsed()) continue;
624  // unused
625  numPix--;
626  sumZ -= zStart;
627  zStart = (*itStart)->getZ();
628  if (z - zStart < 2. * zCoreWidth) break;
629  }
630  }
631  numPix++;
632  sumZ += z;
633  }
634  if (numPix > bestNumPix) {
635  itBest = itStart;
636  bestNumPix = numPix;
637  bestZPos = sumZ / numPix;
638  }
639  //std::cout << " zbest1 " << itBest-pixelList.begin() << " " << itFirst-pixelList.begin() << " " << bestNumPix << " " << bestZPos << std::endl;
640  // too few?
641  if (bestNumPix < 2) break;
642 
643  pixelListType pixels;
644  // check for noisy row or column
645  int firstRow = -1;
646  int firstCol = -1;
647  bool singleRow = true;
648  bool singleCol = true;
649  for (pixelListType::iterator itP = itFirst; itP != itLast; ++itP) {
650  if ((*itP)->getUsed()) continue;
651  if (abs((*itP)->getZ() - bestZPos) < zRoadWidth) {
652  pixels.push_back(*itP);
653  (*itP)->setUsed();
654  if (firstRow < 0) {
655  firstRow = (*itP)->getRow();
656  firstCol = (*itP)->getCol();
657  itBest = itP;
658  } else {
659  singleRow = singleRow && (firstRow == (*itP)->getRow());
660  singleCol = singleCol && (firstCol == (*itP)->getCol());
661  }
662  }
663  }
664  bestNumPix = pixels.size();
665  //std::cout << " zbest2 " << itBest-pixelList.begin() << " " << itFirst-pixelList.begin() << " " << bestNumPix << " " << bestZPos << std::endl;
666  // new macro pixel (minimal noise cut >1)
667  if (bestNumPix > 1 && !singleRow && !singleCol) {
668  tp_MacroPixel* someMacroPixel = new tp_MacroPixel(iBin * 1000 + numMp, pixels, mpSize);
669  //someMacroPixel->print();
670  _macroPixels.push_back(someMacroPixel);
671  _numPix += pixels.size();
672  numMp += 1;
673  }
674  ntot -= bestNumPix;
675  // road at front?
676  if (itBest == itFirst) itFirst += bestNumPix;
677  // road at back?
678  if (itBest + bestNumPix == itLast) itLast -= bestNumPix;
679  }
680 }
681 
684  //std::cout << " destroying tp_PixelBin " << _binId << std::endl;
685  for (macroPixelListType::iterator itMpix = _macroPixels.begin(); itMpix != _macroPixels.end(); ++itMpix) {
686  delete *itMpix;
687  }
688  _macroPixels.clear();
689 }
690 
692 void tp_PixelBin::print() const {
693  std::cout << " tp_PixelBin " << _binId << ", " << _numPix << ", " << _macroPixels.size() << std::endl;
694 }
695 
697 int tp_PixelBin::getId() const {
698  return _binId;
699 }
700 
703  return _numPix;
704 }
705 
708  return _macroPixels.size();
709 }
710 
713  return _macroPixels;
714 }
715 
717 
722 tp_PixelRoad::tp_PixelRoad(macroPixelPairType mPixPair, pixelBinListType& pixelBins, const double* cuts) :
723  _mpId1(mPixPair.first->getId()), _mpId2(mPixPair.second->getId()), _valid(false), _numPix(0), _chi2ByNdf(0.), _sList(), _macroPixels() {
724  // get positions
725  double pos1[3], pos2[3];
726  mPixPair.first->getPos(pos1); // reference point
727  mPixPair.second->getPos(pos2);
728  // direction in XY
729  const double distX = pos2[0] - pos1[0];
730  const double distY = pos2[1] - pos1[1];
731  const double dist2D = sqrt(distX * distX + distY * distY);
732  const double ex = distX / dist2D;
733  const double ey = distY / dist2D;
734  // slope in (S,Z)
735  const double distZ = pos2[2] - pos1[2];
736  const double dzds = distZ / dist2D;
737  // check unused macro pixels
738  const double maxPull2XY = cuts[0];
739  const double maxPull2Z = cuts[1];
740  const double maxChi2 = cuts[2];
741  const double maxSvar = cuts[3];
742  const double maxGap = cuts[4];
743  // loop over bins and unused macro pixels
744  double sumChi2 = 0.;
745  for (pixelBinListType::iterator itBin = pixelBins.begin(); itBin != pixelBins.end(); ++itBin) {
746  macroPixelListType mPixList = (*itBin)->getMacroPixels();
747  for (macroPixelListType::iterator itMpix = mPixList.begin(); itMpix != mPixList.end(); ++itMpix) {
748  if ((*itMpix)->getUsed()) continue;
749  //position matching
750  (*itMpix)->getPos(pos2);
751  const double resXY = (pos2[0] - pos1[0]) * ey - (pos2[1] - pos1[1]) * ex;
752  const double sArc = (pos2[0] - pos1[0]) * ex + (pos2[1] - pos1[1]) * ey;
753  const double resZ = pos2[2] - (pos1[2] + sArc * dzds);
754  // std::cout << " res " << resXY << " " << resZ << " " << dist2D << " " << sArc << " " << _sumChi2 << std::endl;
755  // include macro pixel variance
756  const double pull2XY = (resXY * resXY + (*itMpix)->getVarXY(ey, -ex)) / (*itMpix)->getSigma2XY();
757  const double pull2Z = (resZ * resZ + (*itMpix)->getVarZ()) / (*itMpix)->getSigma2Z();
758  if (pull2XY > maxPull2XY || pull2Z > maxPull2Z) continue;
759  // accept macro pixel
760  const int nPix = (*itMpix)->getEntries();
761  _numPix += nPix;
762  _sList.push_back(sArc);
763  _macroPixels.push_back(*itMpix);
764  // Chi2
765  sumChi2 += nPix * (pull2XY + pull2Z);
766  }
767  }
768  //std::cout << " (m)pix " << _numPix << " " << _macroPixels.size() << " " << sumChi2 << std::endl;
769  // minimal content
770  if (_macroPixels.size() < 3) return;
771  // normalize to Ndf
772  _chi2ByNdf = sumChi2 / (2 * _numPix - 4);
773  if (_chi2ByNdf > maxChi2) return;
774  // rel. variance in arc length, max. gap
775  std::sort(_sList.begin(), _sList.end());
776  const double sLen = _sList.back() - _sList.front();
777  double sumS0 = 0.;
778  double sumS1 = 0.;
779  double sumS2 = 0.;
780  double mxGap = 0.;
781  for (std::vector<double>::iterator itS = _sList.begin(); itS != _sList.end(); ++itS) {
782  const double sArc = *itS;
783  sumS0 += 1.0;
784  sumS1 += sArc;
785  sumS2 += sArc * sArc;
786  if (itS != _sList.begin()) {
787  const double gap = sArc - *(itS - 1);
788  mxGap = max(mxGap, gap);
789  }
790  }
791  sumS1 /= sumS0;
792  sumS2 /= sumS0;
793  const double sVar = (sumS2 - sumS1 * sumS1) / (sLen * sLen);
794  //std::cout << " sVar " << sVar << " " << sLen << " " << mxGap << std::endl;
795  if (sVar > maxSvar || mxGap > maxGap) return;
796  // valid road
797  _valid = true;
798 }
799 
802  //std::cout << " destroying tp_PixelRoad " << _binId << std::endl;
803  _macroPixels.clear();
804 }
805 
807 void tp_PixelRoad::print() const {
808  std::cout << " tp_PixelRoad " << _mpId1 << " " << _mpId2 << ": " << _valid << ", " << _numPix << ", " << _macroPixels.size()
809  << ", " << _chi2ByNdf << std::endl;
810 }
811 
813 bool tp_PixelRoad::isValid() const {
814  return _valid;
815 }
816 
819  return _numPix;
820 }
821 
824  return _macroPixels.size();
825 }
826 
828 double tp_PixelRoad::getChi2() const {
829  return _chi2ByNdf;
830 }
831 
834  return _macroPixels;
835 }
836 
838 
844 tp_PixelSegment::tp_PixelSegment(const int segId, const int level, const double Bzc, macroPixelListType& macroPixels) :
845  _segId(segId), _level(level), _bzc(Bzc), _npar((Bzc != 0.) ? 5 : 4), _macroPixels(macroPixels), _parameters(_npar), _covariance(
846  _npar) {
847  // reference point
848  double sumX = 0.;
849  double sumY = 0.;
850  for (macroPixelListType::iterator itMpix = macroPixels.begin(); itMpix != macroPixels.end(); ++itMpix) {
851  sumX += (*itMpix)->getX();
852  sumY += (*itMpix)->getY();
853  }
854  _refX = sumX / macroPixels.size();
855  _refY = sumY / macroPixels.size();
856  _refZ = 0.;
857  double refPoint[] = { _refX, _refY, _refZ };
858  //
859  // fit segment
860  //
861  double pos[3], sArc, chi2XY, chi2ZS;
862  double parameters[] = { 0., 0., 0., 0., 0. };
864  int nParXY, nPointXY, nPointZS;
865  // xy fit
866  simpleFitXY xyFit((Bzc != 0.), _refX, _refY);
867  for (macroPixelListType::iterator itMpix = macroPixels.begin(); itMpix != macroPixels.end(); ++itMpix) {
868  pixelListType pixels = (*itMpix)->getPixels();
869  for (pixelListType::iterator itP = pixels.begin(); itP != pixels.end(); ++itP) {
870  xyFit.addPoint((*itP)->getX(), (*itP)->getY(), 1.0 / (*itP)->getSigma2XY());
871  }
872  }
873  nParXY = xyFit.fit(chi2XY, nPointXY);
874  _parameters.SetSub(0, xyFit.getPar());
875  _covariance.SetSub(0, 0, xyFit.getCov());
876  for (int i = 0; i < nParXY; ++i)
877  parameters[3 - nParXY + i] = _parameters[i];
878  // simple helix
879  simpleHelix hlx(parameters, refPoint, Bzc);
880  // zs fit
881  double sMin = 1.;
882  double sMax = 0.;
883  simpleFitZS zsFit;
884  for (macroPixelListType::iterator itMpix = macroPixels.begin(); itMpix != macroPixels.end(); ++itMpix) {
885  pixelListType pixels = (*itMpix)->getPixels();
886  for (pixelListType::iterator itP = pixels.begin(); itP != pixels.end(); ++itP) {
887  (*itP)->getPos(pos);
888  sArc = hlx.getArcLengthXY(pos);
889  (*itP)->setArcLength(sArc);
890  zsFit.addPoint(sArc, pos[2] - _refZ, 1.0 / (*itP)->getSigma2Z());
891  if (sMin > sMax) {
892  sMin = sMax = sArc;
893  } else {
894  sMin = min(sMin, sArc);
895  sMax = max(sMax, sArc);
896  }
897  }
898  }
899  _length = sMax - sMin;
900  zsFit.fit(chi2ZS, nPointZS);
901  _parameters.SetSub(nParXY, zsFit.getPar());
902  _covariance.SetSub(nParXY, nParXY, zsFit.getCov());
903  // combine
904  _ndf = nPointXY + nPointZS - _npar;
905  _chi2 = chi2XY + chi2ZS;
906  // cout << " cov " << endl; _covariance.Print();
907 }
908 
911  //std::cout << " destroying tp_PixelSegment " << _segId << std::endl;
912  _macroPixels.clear();
913 }
914 
917  std::cout << " tp_PixelSegment " << _segId << " " << _level << ": " << _macroPixels.size() << " (" << _refX << ", " << _refY
918  << ") " << _length << ", " << _npar << ", " << _ndf << ", " << _chi2 << "; ";
919  for (int i = 0; i < _npar; ++i)
920  std::cout << _parameters[i] << " ";
921  std::cout << std::endl;
922  //_parameters.Print();
923  //_covariance.Print();
924 }
925 
928  return _length;
929 }
930 
932 double tp_PixelSegment::getChi2() const {
933  return _chi2;
934 }
935 
938  return _ndf;
939 }
940 
943  return _npar;
944 }
945 
948  return _level;
949 }
950 
952 
955 void tp_PixelSegment::getRefPoint(double* position) const {
956  position[0] = _refX;
957  position[1] = _refY;
958  position[2] = _refZ;
959 }
960 
962 
965 void tp_PixelSegment::getPar(double* par) const {
966  par[0] = 0.;
967  for (int i = 0; i < _npar; ++i)
968  par[5 - _npar + i] = _parameters[i];
969 }
970 
972 const TVectorD& tp_PixelSegment::getPar() const {
973  return _parameters;
974 }
975 
977 const TMatrixDSym& tp_PixelSegment::getCov() const {
978  return _covariance;
979 }
980 
983  return _macroPixels;
984 }
985 
987 
995 void tp_PixelSegment::getLCIOStateAtRefPoint(const double* refPos, TVectorD& newPar, TMatrixDSym& newCov) const {
996  double refPoint[3], par[5];
997  this->getRefPoint(refPoint);
998  this->getPar(par);
999  simpleHelix hlx(par, refPoint, _bzc);
1000  TVectorD tmpPar(_npar);
1001  TMatrixDSym cov(this->getCov()), tmpCov(_npar);
1002  // track state at reference point
1003  hlx.getStateAt(refPos[0], refPos[1], refPos[2], cov, tmpPar, tmpCov);
1004  TMatrixD hlx2LCIO = hlx.helixToLCIOJacobian().GetSub(0, 4, 5 - _npar, 4);
1005  newPar = hlx2LCIO * tmpPar;
1006  newCov = tmpCov.Similarity(hlx2LCIO);
1007 }
1008 
1009 // Match segment with other segment.
1020 bool tp_PixelSegment::match(tp_PixelSegment* seg, const double chi2Cut, const double distCut) const {
1021  // check distance
1022  double refPoint1[3], refPoint2[3];
1023  this->getRefPoint(refPoint1);
1024  seg->getRefPoint(refPoint2);
1025  const double combinedLength = this->getLength() + seg->getLength();
1026  const double distX = refPoint2[0] - refPoint1[0];
1027  const double distY = refPoint2[1] - refPoint1[1];
1028  const double distZ = refPoint2[2] - refPoint1[2];
1029  // relative distance
1030  const double dist2D = sqrt(distX * distX + distY * distY) / combinedLength;
1031  // std::cout << " match " << dist2D << " " << combinedLength << std::endl;
1032  // minimal distance (avoid too much overlap)
1033  if (dist2D < 0.25) return false;
1034  // maximal distance (avoid too much extrapolation)
1035  if (dist2D > distCut) return false;
1036  // compare segment parameters at mid point
1037  double par1[5], par2[5];
1038  this->getPar(par1);
1039  simpleHelix hlx1(par1, refPoint1, _bzc);
1040  seg->getPar(par2);
1041  simpleHelix hlx2(par2, refPoint2, _bzc);
1042  // (weighted) mid point
1043  const double fraction = this->getLength() / combinedLength;
1044  const double xav = refPoint1[0] + fraction * distX;
1045  const double yav = refPoint1[1] + fraction * distY;
1046  const double zav = refPoint1[2] + fraction * distZ;
1047  TVectorD newPar1(_npar), newPar2(_npar);
1048  TMatrixDSym cov1(this->getCov()), cov2(seg->getCov()), newCov1(_npar), newCov2(_npar);
1049  // track states at midpoint
1050  hlx1.getStateAt(xav, yav, zav, cov1, newPar1, newCov1);
1051  hlx2.getStateAt(xav, yav, zav, cov2, newPar2, newCov2);
1052  TVectorD diffPar(newPar1 - newPar2);
1053  TMatrixDSym diffPrec(newCov1 + newCov2);
1054  diffPrec.Invert();
1055  // chi2
1056  double chi2 = diffPrec.Similarity(diffPar);
1057  // cout << " seg-match chi2 " << chi2 << " " << _npar << " " << dist2D << " " << this->getLength() << " " << seg->getLength() << " " << this->getLevel() << " " << seg->getLevel() << endl;
1058  return (chi2 < chi2Cut * _npar);
1059 }
1060 
1062 
1068 tp_PixelChip::tp_PixelChip(const int chipId, pixelListType& pixelList, const int mpSize, const double sigmaZ) :
1069  _chipId(chipId), _size(mpSize), _numPix(0), _numMPix(0), _pixelBins(), _pixelSegments() {
1070  // bin pixels into 2D histogram
1071  //std::cout << " >>> chip " << chipId << std::endl;
1072  std::map<int, pixelListType> pixHist;
1073  const int nBin = 256 / _size;
1074  const int nBorder = (256 % _size) / 2;
1075 
1076  for (pixelListType::iterator itP = pixelList.begin(); itP != pixelList.end(); ++itP) {
1077  int macroRow = min(max(((*itP)->getRow() - nBorder) / _size, 0), nBin - 1);
1078  int macroCol = min(max(((*itP)->getCol() - nBorder) / _size, 0), nBin - 1);
1079  int iBin = macroRow + 1000 * macroCol;
1080  pixHist[iBin].push_back(*itP);
1081  }
1082 
1083  // define macro pixels (needs at least 2 pixels)
1084  int numBin = 0;
1085  for (std::map<int, pixelListType>::iterator itBin = pixHist.begin(); itBin != pixHist.end(); ++itBin) {
1086  int iBin = itBin->first;
1087  pixelListType pixels = itBin->second;
1088  // minimal noise cut
1089  if (pixels.size() < 2) continue;
1090  // create bin with macro pixels separated in Z
1091  sort(pixels.begin(), pixels.end(), comparePixelsZ);
1092  tp_PixelBin* someBin = new tp_PixelBin(numBin, iBin, pixels, mpSize, 2.0 * sigmaZ, 3.5 * sigmaZ);
1093  //someBin->print();
1094  if (someBin->getNumMPix() > 0) {
1095  _pixelBins.push_back(someBin);
1096  _numMPix += someBin->getNumMPix();
1097  _numPix += someBin->getNumPix();
1098  numBin += 1;
1099  } else
1100  delete someBin;
1101  }
1102 }
1103 
1106  //std::cout << " destroying tp_PixelChip " << _chipId << std::endl;
1107  for (pixelBinListType::iterator itBin = _pixelBins.begin(); itBin != _pixelBins.end(); ++itBin) {
1108  delete *itBin;
1109  }
1110  _pixelBins.clear();
1111  // segments are partially deleted by combiner
1112  _pixelSegments.clear();
1113 }
1114 
1116 void tp_PixelChip::print() const {
1117  std::cout << " tp_PixelChip " << _chipId << ", " << _numPix << ", " << _numMPix << ", " << _pixelBins.size() << std::endl;
1118 }
1119 
1121 int tp_PixelChip::getId() const {
1122  return _chipId;
1123 }
1124 
1127  return _numPix;
1128 }
1129 
1132  return _numMPix;
1133 }
1134 
1137  return _pixelBins.size();
1138 }
1139 
1140 // Get pixel segments.
1142  return _pixelSegments;
1143 }
1144 
1146 
1163 int tp_PixelChip::findSegments(const double bfac, const int* iCuts, const double* dCuts) {
1164  // std::cout << " findSegments: "; this->print();
1165  int maxMult = iCuts[0];
1166  int minPixels = iCuts[1];
1167  int minDist = iCuts[2];
1168  // available macro pixels
1169  int freeMPix = _numMPix;
1170  while (freeMPix > 1) {
1171  macroPixelPairListMapType rankedPairs;
1172  // rank pairs according to distance (max(row, col))
1173  // bin 1
1174  for (pixelBinListType::iterator itBin1 = _pixelBins.begin(); itBin1 != _pixelBins.end(); ++itBin1) {
1175  if ((*itBin1)->getNumMPix() > maxMult) continue;
1176  // row and column
1177  int row1 = (*itBin1)->getId() % 1000;
1178  int col1 = (*itBin1)->getId() / 1000;
1179  // macro pixels
1180  macroPixelListType mPixList1 = (*itBin1)->getMacroPixels();
1181  // bin 2
1182  for (pixelBinListType::iterator itBin2 = itBin1 + 1; itBin2 != _pixelBins.end(); ++itBin2) {
1183  if ((*itBin2)->getNumMPix() > maxMult) continue;
1184  // row and column
1185  int row2 = (*itBin2)->getId() % 1000;
1186  int col2 = (*itBin2)->getId() / 1000;
1187  // rank (distance)
1188  int rank = max(abs(row1 - row2), abs(col1 - col2));
1189  if (rank < minDist) continue;
1190  // macro pixels
1191  macroPixelListType mPixList2 = (*itBin2)->getMacroPixels();
1192  // macro pixels from bin 1
1193  for (macroPixelListType::iterator itMpix1 = mPixList1.begin(); itMpix1 != mPixList1.end(); ++itMpix1) {
1194  if ((*itMpix1)->getUsed() || (*itMpix1)->getEntries() < minPixels) continue;
1195  // macro pixels from bin 2
1196  for (macroPixelListType::iterator itMpix2 = mPixList2.begin(); itMpix2 != mPixList2.end(); ++itMpix2) {
1197  if ((*itMpix2)->getUsed() || (*itMpix2)->getEntries() < minPixels) continue;
1198  rankedPairs[rank].push_back(make_pair(*itMpix1, *itMpix2));
1199  }
1200  }
1201  }
1202  }
1203  //std::cout << " ranked pairs " << rankedPairs.size() << std::endl;
1204  tp_PixelRoad* bestRoad = NULL;
1205  int stopRank = 0;
1206  // road search with pairs
1207  for (macroPixelPairListMapType::reverse_iterator itPairs = rankedPairs.rbegin(); itPairs != rankedPairs.rend(); ++itPairs) {
1208  int rank = itPairs->first;
1209  macroPixelPairListType pairList = itPairs->second;
1210  /* std::cout << " rank " << rank << " " << pairList.size();
1211  for (macroPixelPairListType::iterator itPair = pairList.begin(); itPair != pairList.end(); ++itPair) {
1212  std::cout << " (" << itPair->first->getId() << "," << itPair->second->getId() << "),";
1213  }
1214  std::cout << std::endl; */
1215  // check roads
1216  for (macroPixelPairListType::iterator itPair = pairList.begin(); itPair != pairList.end(); ++itPair) {
1217  tp_PixelRoad* someRoad = new tp_PixelRoad(*itPair, _pixelBins, dCuts);
1218  // someRoad->print();
1219  if (someRoad->isValid()) {
1220  if (bestRoad != NULL) {
1221  // minimize variance 'chi2/#Mpix'
1222  if (someRoad->getChi2() / someRoad->getNumMPix() < bestRoad->getChi2() / bestRoad->getNumMPix()) {
1223  delete bestRoad;
1224  bestRoad = someRoad; // new best road
1225  } else
1226  delete someRoad;
1227  } else
1228  bestRoad = someRoad; // first valid road
1229  stopRank = max(stopRank, rank - 1); // stop after next rank
1230  // all free macro pixels in this road?
1231  if (bestRoad->getNumMPix() == freeMPix) {
1232  stopRank = rank;
1233  break;
1234  } // stop road search
1235  } else
1236  delete someRoad; // not valid
1237  }
1238  // stop rank loop?
1239  if (rank <= stopRank) break;
1240  }
1241  // nothing found?
1242  if (bestRoad == NULL) break;
1243  // something found
1244  // std::cout << " best " << stopRank << " "; bestRoad->print();
1245  macroPixelListType macroPixels = bestRoad->getMacroPixels();
1246  // mark macro pixels as used
1247  for (macroPixelListType::iterator itMpix = macroPixels.begin(); itMpix != macroPixels.end(); ++itMpix)
1248  (*itMpix)->setUsed();
1249  // create (straight line) segment
1250  tp_PixelSegment* someSegment = new tp_PixelSegment(_chipId, 0, bfac, macroPixels);
1251  //someSegment->print();
1252  _pixelSegments.push_back(someSegment);
1253  // remaining free macro pixels
1254  freeMPix -= bestRoad->getNumMPix();
1255  delete bestRoad;
1256  }
1257  return _pixelSegments.size();
1258 }
1259 
1261 
1265  _bzc(Bzc) {
1266 }
1267 
1269 
1277 pixelSegmentListType tp_PixelSegmentCombiner::run(const int level, const int newId, pixelSegmentListType& segments,
1278  const double chi2Cut, const double distCut) {
1279  // std::cout << " combine for " << level << " " << newId << std::endl;
1280  // combined segments
1281  pixelSegmentListType combinedSegments;
1282  // equivalence classes for segment matching
1283  simpleEquiClasses segmentEquiClass;
1284  // define indices
1285  for (pixelSegmentListType::iterator itSeg = segments.begin(); itSeg != segments.end(); ++itSeg) {
1286  segmentEquiClass.addIndex(itSeg - segments.begin());
1287  }
1288  // look for matching pairs
1289  for (pixelSegmentListType::iterator itSeg1 = segments.begin(); itSeg1 != segments.end(); ++itSeg1) {
1290  for (pixelSegmentListType::iterator itSeg2 = itSeg1 + 1; itSeg2 != segments.end(); ++itSeg2) {
1291  if ((*itSeg1)->match((*itSeg2), chi2Cut, distCut))
1292  segmentEquiClass.addMatch(make_pair(itSeg1 - segments.begin(), itSeg2 - segments.begin()));
1293  }
1294  }
1295  // get classes with indices
1296  std::map<int, std::vector<int> > segmentClasses = segmentEquiClass.getClasses();
1297  for (std::map<int, std::vector<int> >::iterator itC = segmentClasses.begin(); itC != segmentClasses.end(); ++itC) {
1298  // std::cout << " class " << itC->first << " " << itC->second.size() << std::endl;
1299  if (itC->second.size() > 1) {
1300  // combine segments
1301  macroPixelListType allMacroPixels;
1302  for (std::vector<int>::iterator itInd = itC->second.begin(); itInd != itC->second.end(); ++itInd) {
1303  macroPixelListType macroPixels = segments[*itInd]->getMacroPixels();
1304  allMacroPixels.insert(allMacroPixels.end(), macroPixels.begin(), macroPixels.end());
1305  delete segments[*itInd];
1306  }
1307  // create combined segment
1308  tp_PixelSegment* someSegment = new tp_PixelSegment(newId, level, _bzc, allMacroPixels);
1309  // someSegment->print();
1310  combinedSegments.push_back(someSegment);
1311  } else {
1312  // uncombined segments
1313  combinedSegments.push_back(segments[itC->second.front()]);
1314  }
1315  }
1316  return combinedSegments;
1317 }
1318 
1319 } // close namespace brackets
1320 
1321 // #endif //#ifdef USE_TPROADS
const TMatrixDSym & getCov() const
Get covariance matrix.
double _sarc
arc length (from segment fitting)
int fit(double &, int &)
Perform fit.
int _octoScale
octoboard number scale (in module=(octo+offset)/scale) (default 12)
double _maxGap
max. (arc-length) gap for road (default: 4.0)
int _numPix
number of pixels in macro pixels
std::string _outputColName
Name of the output collection.
void getPos(double *) const
Get position.
const int _hitNum
input hit collection index
TMatrixDSym _covariance
covariance matrix
void getPar(double *) const
Get (all five helix) parameters from segment fit.
int _numMPix
number of macro pixels
double _minZmeas
min. measured Z value (default 0.)
std::map< int, pixelListType > chipPixelMapType
tp_MacroPixel(const int, pixelListType &, const int)
Construct TimePix macro pixel.
const double _sigma2XY
resolution (squared) for XY measurement
int getChip() const
Get chip number.
double getSigma2Z() const
Get Z variance.
int _numPix
number of pixels in macro pixels
int getNumMPix() const
Get (number of) pixels.
pixelSegmentListType _pixelSegments
pixel segments
int getNumPix() const
Get (number of) pixels.
double getY() const
Get Y coordinate.
std::vector< tp_Pixel * > pixelListType
double getSigma2Z() const
Get Z resolution (squared).
double _chi2CutChip
max. Chi2/Ndf for chip segment matching (default: 30.)
const double _posZ
Z position.
TMatrixDSym getCov() const
Get covariance matrix.
tp_PixelChip(const int, pixelListType &, const int, const double)
Construct TimePix (macro) pixel bin.
tp_Pixel(const int iHit, const EVENT::TrackerHit &aHit, const double xOffset, const double yOffset)
Construct TimePix pixel.
std::map< int, std::vector< int > > getClasses()
Get equivalence classes.
tp_PixelSegmentCombiner(const double)
Construct TimePix pixel segment combiner.
std::string _inputColName
Name of the input collection.
Track finder for TimePix data based on local road search.
const int _mpId2
ID of macro pixel 2.
pixelBinListType _pixelBins
(macro) pixel bins
macroPixelListType getMacroPixels() const
Get macro pixels.
void addPoint(double, double, double)
Add point.
void getRefPoint(double *) const
Get reference point.
std::vector< tp_PixelBin * > pixelBinListType
int _maxMult
max. multiplicity for road seeding bins (default: 3)
pixelSegmentListType run(const int, const int, pixelSegmentListType &, const double, const double)
Run segment combiner.
void getStateAt(const double, const double, const double, TMatrixDSym &, TVectorD &, TMatrixDSym &)
Get state (parameters, covariance matrix) at point.
virtual void processEvent(EVENT::LCEvent *evt)
Process event.
const TVectorD & getPar() const
Get parameter vector.
int _minDist
min. distance for road seeding bins (default: 2)
double _distCut
max. relative (to track length sum) distance (of centers) for segment matching (default: 2...
const double _posY
Y position.
const int _binId
bin Id (row, col)
int fit(double &, int &)
Perform fit.
bool isValid() const
Get validity flag.
void getPos(double *) const
Get position.
const double _bzc
magnetic field strength (Bz*c)
tp_PixelRoad(macroPixelPairType, pixelBinListType &, const double *)
Construct TimePix (macro) pixel road.
int _octoOffset
octoboard number offset (in module=(octo+offset)/scale) (default 8)
int getCol() const
Get column number.
int getNumPix() const
Get (number of) pixels.
std::vector< macroPixelPairType > macroPixelPairListType
virtual void processRunHeader(EVENT::LCRunHeader *run)
tp_PixelSegment(const int, const int, const double, macroPixelListType &)
Construct TimePix pixel segment.
int getRow() const
Get row number.
macroPixelListType _macroPixels
macro pixel
std::vector< tp_PixelSegment * > pixelSegmentListType
double _bzc
magnetic field strength (Bz*c)
int getHitNum() const
Get index to input hit collection.
bool getUsed() const
Get use flag.
int _minTrackLevel
min. track level for output (default 1)
double getVarZ() const
Get Z variance.
void setArcLength(const double)
Set arc length.
macroPixelListType getMacroPixels() const
Get macro pixels.
std::map< int, macroPixelPairListType > macroPixelPairListMapType
const double _posX
X position.
const int _mpId
ID (row/col bin: z bin)
double getY() const
Get Y-position.
std::map< int, pixelSegmentListType > pixelSegmentListMapType
TVectorD getPar() const
Get parameters vector.
int getNumMPix() const
Get (number of) macro pixels.
int _mpSize
macro pixel (bin) size (default: 32)
void addPoint(double, double, double)
Add point.
std::vector< tp_MacroPixel * > macroPixelListType
int getNumBins() const
Get (number of) pixels bins.
double _bfieldScaleFactor
scale factor for magnetic field (default: 1.0)
int _minPixels
min. number of pixels for road seeding maxro pixel (default: 3)
double getZ() const
Get Z coordinate.
int findSegments(const double, const int *, const double *)
Find segments.
int getCol() const
Get column number.
pixelSegmentListType getPixelSegments() const
double getVarXY(const double, const double) const
Get XY variance.
macroPixelListType getMacroPixels() const
Get macro pixels.
double _maxPull2Z
max. pull squared to road in Z (default: 15.)
double getX() const
Get X-position.
TMatrixDSym getCov() const
Get covariance matrix.
double getArcLength() const
Get arc length.
TimePix (macro) pixel road.
int getEntries() const
Get (number of) entries.
const int _npar
number of parameters (5: helix, 4: line)
double _sigma2Z
resolution (squared) for Z measurement
double getArcLengthXY(const double *) const
Get (2D) arc length for given point.
double getSigma2XY() const
Get XY variance.
int _ndf
number of degrees of freedom of segment fit
tp_PixelBin(const int, const int, pixelListType &, const int, const double, const double)
Construct TimePix (macro) pixel bin.
double getSigma2XY() const
Get XY resolution (squared).
TMatrixD helixToLCIOJacobian() const
Get transformation from helix to LCIO track parameters (at reference point)
double _maxSvar
max. relative arc-length variance for road (default: 0.15)
double _maxChi2
max. Chi2/Ndf for road (default 5.)
double _chi2CutOcto
max. Chi2/Ndf for octoboard segment matching (default: 30.)
bool match(tp_PixelSegment *, const double, const double) const
TimePixLocalRoadSearchProcessor aTimePixLocalRoadSearchProcessor
double _maxZmeas
max. measured Z value (default 600.)
TVectorD getPar() const
Get parameters vector.
int getNumPar() const
Get number of parameters.
std::vector< tp_PixelChip * > pixelChipListType
double getX() const
Get X coordinate.
std::vector< double > _sList
arc length list
double _sigma2XY
resolution (squared) for XY measurement
double _xOffset
offset in x of (local) coordinate system (default 0.)
pixelListType getPixels() const
Get pixels.
int _numPix
number of pixels in macro pixels
macroPixelListType _macroPixels
macro pixel
int getNumMPix() const
Get (number of) pixels.
int getNumPix() const
Get (number of) pixels.
macroPixelListType _macroPixels
macro pixels
double _yOffset
offset in y of (local) coordinate system (default 1500.)
void getLCIOStateAtRefPoint(const double *, TVectorD &, TMatrixDSym &) const
Get segment state at reference point.
std::pair< tp_MacroPixel *, tp_MacroPixel * > macroPixelPairType
double _chi2CutMod
max. Chi2/Ndf for module segment matching (default: 50.)
const double _sigma2Z
resolution (squared) for Z measurement
bool _refAtPCA
Use Pca as reference point (else 1. hit)
double _maxPull2XY
max. pull squared to road in XY (default: 15.)
const int _mpId1
ID of macro pixel 1.
void addMatch(std::pair< int, int >)
Add match.
double getChi2() const
Get Chi2/Ndf.