10 #include "otsdaq-core/MonicelliInterface/Detector.h"
13 #define PI TMath::Pi()
15 using namespace monicelli;
24 , xPositionCorrection_ (0)
27 , yPositionCorrection_ (0)
30 , zPositionCorrection_ (0)
37 , xBackFlipped_ (false)
38 , yBackFlipped_ (false)
40 , xRotationCorrection_ (0)
41 , xRotationCorrectionError_(0)
43 , yRotationCorrection_ (0)
44 , yRotationCorrectionError_(0)
46 , zRotationCorrection_ (0)
47 , zRotationCorrectionError_(0)
53 Detector::~Detector(
void)
56 for(ROCsMapDef::iterator it=ROCsChipIDMap_.begin(); it!=ROCsChipIDMap_.end(); it++)
60 ROCsChipIDMap_ .clear();
61 ROCsPositionMap_.clear();
66 void Detector::setupVariables(
void)
70 for(ROCsMapDef::iterator it=ROCsChipIDMap_.begin(); it!=ROCsChipIDMap_.end(); it++)
72 unsigned int ROCPosition = it->second->getPosition();
73 unsigned int yPosition = ROCPosition/xNumberOfROCs_;
75 it->second->setLocalYPosition(yPosition);
76 if( yPosition%2 != 0 ) it->second->setLocalXPosition((yPosition+1) * xNumberOfROCs_ - (ROCPosition+1));
77 else it->second->setLocalXPosition(ROCPosition - yPosition * xNumberOfROCs_) ;
78 if(it->second->getPositionLocalY() == 0)
79 numberOfCols_ += it->second->getNumberOfCols();
80 if(it->second->getPositionLocalX() == 0)
81 numberOfRows_ += it->second->getNumberOfRows();
82 it->second->getNumberOfCols();
85 ROCsPositionMap_[0]->setFirstCol(0);
86 ROCsPositionMap_[0]->setLastCol(ROCsPositionMap_[0]->getNumberOfCols()-1);
87 for(
unsigned int posX=1; posX < xNumberOfROCs_; posX++)
89 ROCsPositionMap_[posX]->setFirstCol(ROCsPositionMap_[(posX-1)]->getLastCol()+1);
90 ROCsPositionMap_[posX]->setLastCol (ROCsPositionMap_[posX]->getFirstCol()+ROCsPositionMap_[posX]->getNumberOfCols()-1);
93 ROCsPositionMap_[0]->setFirstRow(0);
94 ROCsPositionMap_[0]->setLastRow(ROCsPositionMap_[0]->getNumberOfRows()-1);
95 for(
unsigned int posY=xNumberOfROCs_; posY<yNumberOfROCs_*xNumberOfROCs_; posY+=xNumberOfROCs_)
97 ROCsPositionMap_[posY]->setFirstRow(ROCsPositionMap_[(posY-xNumberOfROCs_)]->getLastRow()+1);
98 ROCsPositionMap_[posY]->setLastRow (ROCsPositionMap_[posY]->getFirstRow()+ROCsPositionMap_[posY]->getNumberOfRows()-1);
101 for(ROCsMapDef::iterator it=ROCsChipIDMap_.begin(); it!=ROCsChipIDMap_.end(); it++)
103 it->second->setFirstCol(ROCsPositionMap_[it->second->getPositionLocalX()]->getFirstCol());
104 it->second->setLastCol (ROCsPositionMap_[it->second->getPositionLocalX()]->getLastCol());
105 it->second->setFirstRow(ROCsPositionMap_[it->second->getPositionLocalY()*xNumberOfROCs_]->getFirstRow());
106 it->second->setLastRow (ROCsPositionMap_[it->second->getPositionLocalY()*xNumberOfROCs_]->getLastRow());
111 Detector::matrix33Def Detector::rotationMatrix(
double alpha,
double beta,
double gamma)
113 Detector::matrix33Def R;
115 R(0,0) = cos(beta )*cos(gamma);
116 R(0,1) =-cos(alpha)*sin(gamma)+sin(alpha)*sin(beta )*cos(gamma);
117 R(0,2) = sin(alpha)*sin(gamma)+cos(alpha)*sin(beta )*cos(gamma);
118 R(1,0) = cos(beta)*sin(gamma);
119 R(1,1) = cos(alpha)*cos(gamma)+sin(alpha)*sin(beta)*sin(gamma);
120 R(1,2) =-sin(alpha)*cos(gamma)+cos(alpha)*sin(beta)*sin(gamma);
122 R(2,1) = sin(alpha)*cos(beta);
123 R(2,2) = cos(alpha)*cos(beta);
129 ROC* Detector::addROC(
unsigned int chipPosition,
int chipID,
unsigned int rotationDegrees)
131 if( chipPosition > numberOfROCs_ )
133 std::stringstream ss;
136 STDLINE(
"ERROR: there is no ROC position: " + ss.str() +
" in current detector!!",ACRed);
137 STDLINE(
"ERROR: Maybe you have to use setComposition first",ACRed);
139 if( ROCsChipIDMap_.find( chipID ) == ROCsChipIDMap_.end() && ROCsPositionMap_.find( chipID ) == ROCsPositionMap_.end() )
141 ROCsChipIDMap_ [ chipID ] =
new ROC(chipPosition, chipID, rotationDegrees );
142 ROCsPositionMap_ [ chipPosition ] = ROCsChipIDMap_[ chipID ] ;
146 std::stringstream ss;
148 ss <<
"WARNING: ROC: " << chipID <<
" in position " << chipPosition <<
"was already set!!";
149 STDLINE(ss.str(),ACRed);
151 return ROCsChipIDMap_[ chipID ];
155 void Detector::setNumberOfROCs(
unsigned int xNumberOfROCs,
unsigned int yNumberOfROCs)
157 xNumberOfROCs_ = xNumberOfROCs;
158 yNumberOfROCs_ = yNumberOfROCs;
159 this->updateNumberOfROCs();
163 unsigned int Detector::getNumberOfCols(
bool global)
165 if( !global || (zRotation_ < 45 && zRotation_ >= 0) || (zRotation_ <= 360 && zRotation_ > 315) || (zRotation_ > 135 && zRotation_ < 225) )
166 return numberOfCols_;
168 return this->getNumberOfRows();
172 unsigned int Detector::getNumberOfRows(
bool global)
174 if( !global || (zRotation_ < 45 && zRotation_ >= 0) || (zRotation_ <= 360 && zRotation_ > 315) || (zRotation_ > 135 && zRotation_ < 225) )
175 return numberOfRows_;
177 return this->getNumberOfCols();
181 ROC* Detector::getROC(
int chipID)
183 if( ROCsChipIDMap_.find( chipID ) != ROCsChipIDMap_.end() )
184 return ROCsChipIDMap_[chipID] ;
187 STDLINE(
"WARNING: No ROC found",ACRed);
193 ROC* Detector::getROCByPosition(
unsigned int chipPosition)
195 if( ROCsPositionMap_.find( chipPosition ) != ROCsPositionMap_.end() )
196 return ROCsPositionMap_[chipPosition] ;
199 STDLINE(
"WARNING: No ROC found",ACRed);
205 int Detector::getPixelColFromLocalX(
double xLocal)
207 if(xLocal < 0 || xLocal >= this->getDetectorLengthX())
212 unsigned int col = 0;
214 for(
unsigned int posX=0; posX<xNumberOfROCs_; posX++)
216 roc = getROCByPosition(posX);
217 if( xLocal < l+roc->getLengthLocalX())
221 l += roc->getLengthLocalX();
222 if(posX+1 == xNumberOfROCs_)
224 col += roc->getNumberOfCols();
228 for(
unsigned int rocCol=0; rocCol<roc->getNumberOfCols(); rocCol++)
230 l += roc->getPixelPitchLocalX(rocCol);
238 int Detector::getPixelRowFromLocalY(
double yLocal)
240 if(yLocal < 0 || yLocal >= this->getDetectorLengthY())
244 for(
unsigned int row=0; row<this->getNumberOfRows(); row++)
246 l+=this->getPixelPitchLocalY(row);
247 if(yLocal < l)
return row;
253 Detector::rowColPair Detector::getPixelCellFromLocal(
double x,
double y)
255 Detector::rowColPair rowCol;
256 rowCol.first = this->getPixelRowFromLocalY(y);
257 rowCol.second = this->getPixelColFromLocalX(x);
262 Detector::rowColPair Detector::getPixelCellFromGlobal(
double x,
double y,
double z)
264 fromGlobalToLocal(&x,&y,&z);
265 Detector::rowColPair rowCol;
266 rowCol.first = this->getPixelRowFromLocalY(y);
267 rowCol.second = this->getPixelColFromLocalX(x);
272 double Detector::getPixelCenterLocalX(
unsigned int col)
274 return this->getPixelLowEdgeLocalX(col) + this->getPixelPitchLocalX(col)/2.;
278 double Detector::getPixelCenterLocalY(
unsigned int row)
280 return this->getPixelLowEdgeLocalY(row) + this->getPixelPitchLocalY(row)/2.;
284 double Detector::getPixelLowEdgeLocalX(
unsigned int col)
287 for (
unsigned int pos=0; pos < xNumberOfROCs_; pos++)
289 ROC *roc = getROCByPosition(pos);
291 if(col > roc->getLastCol())
292 lowEdge += roc->getLengthLocalX();
295 unsigned int rocRow = 0;
296 roc = this->convertPixelToROC(&rocRow,&col);
297 lowEdge += roc->getPixelLowEdgeLocalX(col) ;
301 STDLINE(
"WARNING: pixel column is out of range, returning detector's length X", ACRed);
306 double Detector::getPixelLowEdgeLocalY(
unsigned int row)
309 for (
unsigned int pos=0; pos < numberOfROCs_ ; pos+=xNumberOfROCs_)
311 ROC *roc = getROCByPosition(pos);
312 if(row > roc->getLastRow())
313 lowEdge += roc->getLengthLocalY();
316 unsigned int rocCol = 0;
317 roc = this->convertPixelToROC(&row,&rocCol);
318 lowEdge += roc->getPixelLowEdgeLocalY(row) ;
322 STDLINE(
"WARNING: pixel row is out of range, returning detector's length Y", ACRed);
327 double Detector::getPixelPitchLocalX(
unsigned int col)
329 unsigned int rocRow = 0;
330 ROC* roc = this->convertPixelToROC(&rocRow,&col);
331 return roc->getPixelPitchLocalX(col);
335 double Detector::getPixelPitchLocalY(
unsigned int row)
337 unsigned int rocCol = 0;
338 ROC* roc = this->convertPixelToROC(&row,&rocCol);
339 return roc->getPixelPitchLocalY(row);
343 double Detector::getDetectorLengthX(
bool global)
345 if( !global || (zRotation_ < 45 && zRotation_ >= 0) || (zRotation_ <= 360 && zRotation_ > 315) || (zRotation_ > 135 && zRotation_ < 225) )
348 for (
unsigned int pos=0; pos < xNumberOfROCs_; pos++)
349 length += getROCByPosition(pos)->getLengthLocalX();
353 return this->getDetectorLengthY(
false);
357 double Detector::getDetectorLengthY(
bool global)
359 if( !global || (zRotation_ < 45 && zRotation_ >= 0) || (zRotation_ <= 360 && zRotation_ > 315) || (zRotation_ > 135 && zRotation_ < 225) )
362 for (
unsigned int pos=0; pos < numberOfROCs_ ; pos+=xNumberOfROCs_)
363 length += getROCByPosition(pos)->getLengthLocalY();
367 return this->getDetectorLengthX(
false);
372 unsigned int Detector::getROCPositionLocalX(
int chipID)
374 return getROC(chipID)->getPositionLocalX();
378 unsigned int Detector::getROCPositionLocalY(
int chipID)
380 return getROC(chipID)->getPositionLocalY();
385 void Detector::convertPixelFromROC(
ROC* roc,
unsigned int *row,
unsigned int *col)
387 if(roc->getOrientation() == 0)
389 *row += roc->getFirstRow();
390 *col += roc->getFirstCol();
392 else if(roc->getOrientation() == 180)
394 *row = roc->getLastRow() - *row;
395 *col = roc->getLastCol() - *col;
399 STDLINE(
"ERROR: Only 0 and 180 degrees rotations are supported for a ROC!", ACRed);
406 ROC* Detector::convertPixelToROC(
unsigned int *row,
unsigned int *col)
408 ROC *roc = this->findROC(*row, *col);
409 if(roc->getOrientation() == 0)
411 *row -= roc->getFirstRow();
412 *col -= roc->getFirstCol();
414 else if(roc->getOrientation() == 180)
416 *row = roc->getLastRow() - *row;
417 *col = roc->getLastCol() - *col;
421 STDLINE(
"ERROR: Only 0 and 180 degrees rotations are supported for a ROC!", ACRed);
428 ROC* Detector::findROC(
unsigned int row,
unsigned int col)
430 unsigned int posX = getROCPositionLocalXFromCol(col);
431 unsigned int posY = getROCPositionLocalYFromRow(row);
432 if(posX != xNumberOfROCs_ && posY != yNumberOfROCs_)
435 return getROCByPosition(posX+posY*xNumberOfROCs_);
437 return getROCByPosition(xNumberOfROCs_-1-posX+posY*xNumberOfROCs_);
439 STDLINE(
"WARNING: pixel column or pixel row is out of detector's range, return NULL", ACRed);
444 unsigned int Detector::getROCPositionLocalXFromCol(
unsigned int col)
446 unsigned int posX = 0;
447 for (posX=0; posX < xNumberOfROCs_; posX++)
448 if ( col <= getROCByPosition(posX)->getLastCol() )
454 unsigned int Detector::getROCPositionLocalYFromRow(
unsigned int row)
456 unsigned int posY = 0;
457 for (posY=0; posY < numberOfROCs_; posY+=xNumberOfROCs_)
458 if ( row <= getROCByPosition(posY)->getLastRow() )
460 return posY/xNumberOfROCs_;
464 void Detector::flipPixel(
unsigned int *row,
unsigned int *col)
466 unsigned int lastRow = this->getLastRow();
467 unsigned int lastCol = this->getLastCol();
470 if( this->isXBackFlipped() )
471 *col = lastCol - *col;
473 if( this->isYBackFlipped() )
474 *row = lastRow - *row ;
479 if(zRotation_ > 225 && zRotation_ < 315)
483 *row = lastCol - tmp ;
486 else if(zRotation_ > 45 && zRotation_ < 135)
489 *col = lastRow - *row ;
493 else if(zRotation_ >= 135 && zRotation_ <= 225)
495 *row = lastRow - *row ;
496 *col = lastCol - *col ;
501 void Detector::flipBackPixel(
unsigned int *row,
unsigned int *col )
503 unsigned int lastRow = this->getLastRow();
504 unsigned int lastCol = this->getLastCol();
508 if(zRotation_ > 225 && zRotation_ < 315)
512 *col = lastCol - tmp ;
515 else if(zRotation_ > 45 && zRotation_ < 135)
518 *row = lastRow - *col ;
522 else if(zRotation_ >= 135 && zRotation_ <= 225)
524 *col = lastCol - *col ;
525 *row = lastRow - *row ;
529 if( this->isXBackFlipped() )
530 *col = lastCol - *col;
532 if( this->isYBackFlipped() )
533 *row = lastRow - *row ;
537 void Detector::flipPositionLocal(
double *x,
double *y,
double *xErr,
double *yErr)
539 double yLength = this->getDetectorLengthY();
540 double xLength = this->getDetectorLengthX();
548 if( this->isXBackFlipped() )
551 if( this->isYBackFlipped() )
556 if(zRotation_ > 225 && zRotation_ < 315)
561 if(xErr != 0 && yErr != 0)
569 else if(zRotation_ > 45 && zRotation_ < 135)
574 if(xErr != 0 && yErr != 0)
582 else if(zRotation_ >= 135 && zRotation_ <= 225)
590 void Detector::flipBackPositionLocal(
double *x,
double *y,
double *xErr,
double *yErr)
592 double yLength = this->getDetectorLengthY();
593 double xLength = this->getDetectorLengthX();
598 if(zRotation_ > 225 && zRotation_ < 315)
603 if(xErr != 0 && yErr != 0)
611 else if(zRotation_ > 45 && zRotation_ < 135)
616 if(xErr != 0 && yErr != 0)
624 else if(zRotation_ >= 135 && zRotation_ <= 225)
631 if( this->isXBackFlipped() )
634 if( this->isYBackFlipped() )
639 void Detector::flipDistance(
double* deltaX,
double* deltaY)
642 if( this->isXBackFlipped() )
645 if( this->isYBackFlipped() )
651 if(zRotation_ > 225 && zRotation_ < 315)
658 else if(zRotation_ > 45 && zRotation_ < 135)
665 else if(zRotation_ >= 135 && zRotation_ <= 225)
673 void Detector::flipBackDistance(
double* deltaX,
double* deltaY)
678 if(zRotation_ > 225 && zRotation_ < 315)
685 else if(zRotation_ > 45 && zRotation_ < 135)
692 else if(zRotation_ >= 135 && zRotation_ <= 225)
699 if( this->isXBackFlipped() )
702 if( this->isYBackFlipped() )
707 bool Detector::switchXYFromLocaToGlobal(
void)
710 if( (zRotation_ > 225 && zRotation_ < 315) || (zRotation_ > 45 && zRotation_ < 135) )
return true;
714 double Detector::getXRotation(
bool global)
716 if(global)
return xRotation_;
720 if (zRotation_ > 225 && zRotation_ < 315 )
return -yRotation_;
722 else if(zRotation_ > 45 && zRotation_ < 135 )
return yRotation_;
724 else if(zRotation_ >= 135 && zRotation_ <= 225)
return -xRotation_;
726 else return xRotation_;
731 double Detector::getYRotation(
bool global)
733 if (global)
return yRotation_;
737 if (zRotation_ > 225 && zRotation_ < 315 )
return -xRotation_;
739 else if(zRotation_ > 45 && zRotation_ < 135 )
return xRotation_;
741 else if(zRotation_ >= 135 && zRotation_ <= 225)
return -yRotation_;
743 else return yRotation_;
748 double Detector::fromLocalToGlobal(
double* x,
double* y,
double* z,
double* xErr,
double* yErr,
double* zErr)
751 this->flipPositionLocal(x,y,xErr,yErr);
752 this->translateXY(x,y);
753 this->translateCorrection(x,y);
754 Detector::matrix33Def R = this->getRotationMatrix();
756 double sigxy = R(0,0)*R(1,0)*pow(*xErr,2)+R(0,1)*R(1,1)*pow(*yErr,2);
761 this->XYZRotation(x,y,z,xErr,yErr,zErr);
762 *z += this->getZPositionTotal();
767 void Detector::fromLocalToGlobal(
double* x,
double* y,
double* z)
770 this->flipPositionLocal(x,y);
771 this->translateXY(x,y);
772 this->translateCorrection(x,y);
777 this->XYZRotation(x,y,z);
778 *z += this->getZPositionTotal();
782 void Detector::fromLocalToGlobalNoRotation(
double* x,
double* y,
double* xErr,
double* yErr)
784 this->flipPositionLocal(x,y,xErr,yErr);
785 this->translateXY(x,y);
786 this->translateCorrection(x,y);
790 void Detector::fromGlobalToLocal(
double* x,
double* y,
double* z,
double* xErr,
double *yErr,
double* zErr)
792 *z -= this->getZPositionTotal();
797 this->XYZRotation(x,y,z,xErr,yErr,zErr,
true);
799 this->translateXY(x,y,
true);
800 this->translateCorrection(x,y,
true);
801 this->flipBackPositionLocal(x,y,xErr,yErr);
807 void Detector::fromGlobalToLocal(
double* x,
double* y,
double* z)
809 *z -= this->getZPositionTotal();
814 this->XYZRotation(x,y,z,
true);
816 this->translateXY(x,y,
true);
817 this->translateCorrection(x,y,
true);
818 this->flipBackPositionLocal(x,y);
823 void Detector::XYZRotation(
double* x,
double* y,
double* z,
double* xErr,
double* yErr,
double* zErr,
bool backward)
825 XYZRotation(x,y,z,backward);
826 XYZRotation(xErr,yErr,zErr,backward);
830 void Detector::XYZRotation(
double* x,
double* y,
double* z,
bool backward)
832 Detector::matrix33Def R = this->getRotationMatrix();
834 double xv[3] = {*x,*y,*z};
835 double* xPrimev[3] = {x,y,z};
837 for(
int i=0; i<3; i++)
840 for(
int j=0; j<3; j++)
842 *(xPrimev[i]) += R(j,i)*xv[j];
844 *(xPrimev[i]) += R(i,j)*xv[j];
849 void Detector::XRotation(
double* y,
double* z,
double* yErr,
double* zErr,
bool backward)
851 XRotation(y,z,backward);
852 XRotation(yErr,zErr,backward);
874 void Detector::XRotation(
double* y,
double* z,
bool backward)
878 double alpha = (xRotation_ + xRotationCorrection_)*PI/180. ;
883 *y = (yTmp)*cos(alpha) - (zTmp)*sin(alpha);
884 *z = (yTmp)*sin(alpha) + (zTmp)*cos(alpha);
888 void Detector::YRotation(
double *x,
double *z,
double *xErr,
double *zErr,
bool backward)
890 YRotation(x,z,backward);
891 YRotation(xErr,zErr,backward);
913 void Detector::YRotation(
double *x,
double *z,
bool backward)
917 double beta = (yRotation_+ yRotationCorrection_)*PI/180. ;
922 *x = (xTmp)*cos(beta) + (zTmp)*sin(beta);
923 *z = -(xTmp)*sin(beta) + (zTmp)*cos(beta);
927 void Detector::ZRotation(
double* x,
double* y,
double* xErr,
double* yErr,
bool backward)
929 ZRotation(x,y,backward);
930 ZRotation(xErr,yErr,backward);
952 void Detector::ZRotation(
double* x,
double* y,
bool backward)
956 double gamma = (zRotationCorrection_)*PI/180.;
961 *x = (xTmp)*cos(gamma) - (yTmp)*sin(gamma);
962 *y = (xTmp)*sin(gamma) + (yTmp)*cos(gamma);
966 void Detector::translateXY(
double* x,
double* y,
bool backward)
981 void Detector::translateCorrection(
double* x,
double* y,
bool backward)
985 *x += xPositionCorrection_ ;
986 *y += yPositionCorrection_ ;
990 *x -= xPositionCorrection_ ;
991 *y -= yPositionCorrection_ ;
996 Detector::matrix33Def Detector::getRotationMatrix()
998 double alpha,beta,gamma;
999 alpha = (xRotation_ + xRotationCorrection_)*PI/180. ;
1000 beta = (yRotation_ + yRotationCorrection_)*PI/180. ;
1001 gamma = (zRotationCorrection_)*PI/180. ;
1003 return Detector::rotationMatrix(alpha, beta, gamma);
1007 double Detector::getAlignmentPredictedGlobal(ROOT::Math::SVector<double,4>& trackPars, matrix33Def& RInv,
double z,
double& predX,
double& predY)
1009 double numX,numY,den;
1010 numX=(trackPars[0]*z+trackPars[1])*(RInv[1][1]-trackPars[2]*RInv[2][1])-(trackPars[2]*z+trackPars[3])*(RInv[0][1]-trackPars[0]*RInv[2][1]);
1011 numY=(trackPars[2]*z+trackPars[3])*(RInv[0][0]-trackPars[0]*RInv[2][0])-(trackPars[0]*z+trackPars[1])*(RInv[1][0]-trackPars[2]*RInv[2][0]);
1012 den =(RInv[0][0]-trackPars[0]*RInv[2][0])*(RInv[1][1]-trackPars[2]*RInv[2][1])-(RInv[1][0]-trackPars[2]*RInv[2][0])*(RInv[0][1]-trackPars[0]*RInv[2][1]);
1019 void Detector::getPredictedGlobal(ROOT::Math::SVector<double,4>& trackPars,
double& predX,
double& predY,
double& predZ)
1024 fromLocalToGlobal(&x0,&y0,&z0);
1026 Detector::matrix33Def R = this->getRotationMatrix();
1027 predZ = (R(0,2)*(x0-trackPars[1])+R(1,2)*(y0-trackPars[3])+R(2,2)*z0)/(R(0,2)*trackPars[0]+R(1,2)*trackPars[2]+R(2,2));
1029 predX = trackPars[0]*predZ + trackPars[1];
1030 predY = trackPars[2]*predZ + trackPars[3];
1092 void Detector::getPredictedLocal(ROOT::Math::SVector<double,4>& trackPars,
double& predX,
double& predY)
1095 getPredictedGlobal(trackPars,predX,predY,predZ);
1096 fromGlobalToLocal(&predX,&predY,&predZ);
1100 Detector::xyPair Detector::getTrackErrorsOnPlane(ROOT::Math::SVector<double,4>& trackPars, matrix44Def& AtVAInv)
1102 Detector::matrix33Def RInv = this->getRotationMatrix();
1103 return propagateTrackErrors(trackPars, AtVAInv, RInv, this->getZPositionTotal());
1107 Detector::xyPair Detector::propagateTrackErrors(ROOT::Math::SVector<double,4>& trackPars,
1108 matrix44Def& AtVAInv,
1113 double predSigmaXX,predSigmaYY;
1115 double den = getAlignmentPredictedGlobal(trackPars,RInv,z,predX,predY);
1117 double dfNX_dslx = z*(RInv[1][1]-trackPars[2]*RInv[2][1])-(trackPars[2]*z+trackPars[3])*(-RInv[2][1]);
1118 double dfNX_dqx = (RInv[1][1]-trackPars[2]*RInv[2][1]);
1119 double dfNX_dsly = (trackPars[0]*z+trackPars[1])*(-RInv[2][1])-(z)*(RInv[0][1]-trackPars[0]*RInv[2][1]);
1120 double dfNX_dqy =-(RInv[0][1]-trackPars[0]*RInv[2][1]);
1121 double dfNY_dslx = (trackPars[2]*z+trackPars[3])*(-RInv[2][0])-(z+trackPars[1])*(RInv[1][0]-trackPars[2]*RInv[2][0]);
1122 double dfNY_dqx =-(RInv[1][0]-trackPars[2]*RInv[2][0]);
1123 double dfNY_dsly = (z)*(RInv[0][0]-trackPars[0]*RInv[2][0])-(trackPars[0]*z+trackPars[1])*(-RInv[2][0]);
1124 double dfNY_dqy = (RInv[0][0]-trackPars[0]*RInv[2][0]);
1125 double dfD_dslx = (-RInv[2][0])*(RInv[1][1]-trackPars[2]*RInv[2][1])-(RInv[1][0]-trackPars[2]*RInv[2][0])*(-RInv[2][1]);
1127 double dfD_dsly = (RInv[0][0]-trackPars[0]*RInv[2][0])*(-RInv[2][1])-(-RInv[2][0])*(RInv[0][1]-trackPars[0]*RInv[2][1]);
1129 double dpredx_dslx= dfNX_dslx/den-predX*dfD_dslx/den;
1130 double dpredx_dqx = dfNX_dqx/den;
1131 double dpredx_dsly= dfNX_dsly/den-predX*dfD_dsly/den;
1132 double dpredx_dqy = dfNX_dqy/den;
1133 double dpredy_dslx= dfNY_dslx/den-predY*dfD_dslx/den;
1134 double dpredy_dqx = dfNY_dqx/den;
1135 double dpredy_dsly= dfNY_dsly/den-predY*dfD_dsly/den;
1136 double dpredy_dqy = dfNY_dqy/den;
1138 predSigmaXX = dpredx_dslx*dpredx_dslx*AtVAInv(0,0)+dpredx_dqx*dpredx_dqx*AtVAInv(1,1)+dpredx_dsly*dpredx_dsly*AtVAInv(2,2)+dpredx_dqy*dpredx_dqy*AtVAInv(3,3)+
1139 2*dpredx_dslx*dpredx_dqx*AtVAInv(0,1)+2*dpredx_dslx*dpredx_dsly*AtVAInv(0,2)+2*dpredx_dslx*dpredx_dqy*AtVAInv(0,3)+
1140 2*dpredx_dqx*dpredx_dsly*AtVAInv(1,2)+2*dpredx_dqx*dpredx_dqy*AtVAInv(1,3)+
1141 2*dpredx_dsly*dpredx_dqy*AtVAInv(2,3);
1142 predSigmaYY = dpredy_dslx*dpredy_dslx*AtVAInv(0,0)+dpredy_dqx*dpredy_dqx*AtVAInv(1,1)+dpredy_dsly*dpredy_dsly*AtVAInv(2,2)+dpredy_dqy*dpredy_dqy*AtVAInv(3,3)+
1143 2*dpredy_dslx*dpredy_dqx*AtVAInv(0,1)+2*dpredy_dslx*dpredy_dsly*AtVAInv(0,2)+2*dpredy_dslx*dpredy_dqy*AtVAInv(0,3)+
1144 2*dpredy_dqx*dpredy_dsly*AtVAInv(1,2)+2*dpredy_dqx*dpredy_dqy*AtVAInv(1,3)+
1145 2*dpredy_dsly*dpredy_dqy*AtVAInv(2,3);
1147 return std::make_pair(predSigmaXX,predSigmaYY);
1151 void Detector::test(
double* x,
double* y,
double* z,
double* xErr,
double* yErr,
double* zErr)
1153 std::stringstream ss;
1209 double xErrc = *xErr;
1210 double yErrc = *yErr;
1211 double zErrc = *zErr;
1214 Detector::matrix33Def R = this->getRotationMatrix();
1218 ss <<
"************************ " << ID_ <<
" **************************************";
1219 STDLINE(ss.str(),ACYellow);
1220 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"Original Values->"
1221 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1222 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1223 STDLINE(ss.str(),ACGreen);
1225 this->flipPositionLocal(x,y,xErr,yErr);
1226 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After flipping ->"
1227 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1228 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1231 this->translateXY(x,y);
1232 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After translate->"
1233 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1234 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1237 this->translateCorrection(x,y);
1238 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After tran corr->"
1239 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1240 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1249 this->XRotation(y,z,yErr,zErr);
1250 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After XRotation->"
1251 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1252 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1255 this->YRotation(x,z,xErr,zErr);
1256 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After YRotation->"
1257 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1258 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1259 STDLINE(ss.str(),ACRed);
1261 this->ZRotation(x,y,xErr,yErr);
1262 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After ZRotation->"
1263 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1264 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1267 this->XYZRotation(&xc,&yc,&zc,&xErrc,&yErrc,&zErrc);
1268 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After XYZRot ->"
1269 <<
" x: " << xc <<
" y: " << yc <<
" z:" << zc
1270 <<
" xErr: " << xErrc <<
" yErr: " << yErrc <<
" zErr:" << zErrc;
1273 *z += this->getZPositionTotal();
1275 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"Final ->"
1276 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1277 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1278 STDLINE(ss.str(),ACPurple);
1281 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"Original Values->"
1282 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1283 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1285 *z -= this->getZPositionTotal();
1287 this->ZRotation(x,y,xErr,yErr,
true);
1288 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After ZRotation->"
1289 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1290 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1293 this->YRotation(x,z,xErr,zErr,
true);
1294 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After YRotation->"
1295 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1296 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1299 this->XRotation(y,z,yErr,zErr,
true);
1300 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After XRotation->"
1301 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1302 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1303 STDLINE(ss.str(),ACRed);
1306 this->XYZRotation(&xc,&yc,&zc,&xErrc,&yErrc,&zErrc,
true);
1307 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After XYZRot ->"
1308 <<
" x: " << xc <<
" y: " << yc <<
" z:" << zc
1309 <<
" xErr: " << xErrc <<
" yErr: " << yErrc <<
" zErr:" << zErrc;
1312 this->translateXY(x,y,
true);
1313 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After translate->"
1314 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1315 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1318 this->translateCorrection(x,y,
true);
1319 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After tran corr->"
1320 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1321 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1325 this->flipBackPositionLocal(x,y,xErr,yErr);
1326 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"Final AfterFlip->"
1327 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1328 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1329 STDLINE(ss.str(),ACGreen);
1331 this->fromLocalToGlobal(x,y,z,xErr,yErr,zErr);
1332 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After DetToGlob->"
1333 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1334 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1335 STDLINE(ss.str(),ACPurple);
1337 this->fromGlobalToLocal(x,y,z,xErr,yErr,zErr);
1338 ss.str(
""); ss << __PRETTY_FUNCTION__ <<
"After GlobToDet->"
1339 <<
" x: " << *x <<
" y: " << *y <<
" z:" << *z
1340 <<
" xErr: " << *xErr <<
" yErr: " << *yErr <<
" zErr:" << *zErr;
1341 STDLINE(ss.str(),ACGreen);
1346 void Detector::dump(
void)
1349 sprintf (buffer,
"Alpha -> Total = %10.2f (%10.2f + %7.2f) deg", getXRotation() + getXRotationCorrection(), getXRotation(), getXRotationCorrection());STDLINE(buffer,ACCyan);
1350 sprintf (buffer,
"Beta -> Total = %10.2f (%10.2f + %7.2f) deg", getYRotation() + getYRotationCorrection(), getYRotation(), getYRotationCorrection());STDLINE(buffer,ACCyan);
1351 sprintf (buffer,
"Gamma -> Total = %10.2f (%10.2f + %7.2f) deg", getZRotation() + getZRotationCorrection(), getZRotation(), getZRotationCorrection());STDLINE(buffer,ACCyan);
1352 sprintf (buffer,
"X -> Total = %10.2f (%10.2f + %7.2f) um", 10*(getXPositionTotal()), 10*getXPosition(), 10*getXPositionCorrection());STDLINE(buffer,ACCyan);
1353 sprintf (buffer,
"Y -> Total = %10.2f (%10.2f + %7.2f) um", 10*(getYPositionTotal()), 10*getYPosition(), 10*getYPositionCorrection());STDLINE(buffer,ACCyan);
1354 sprintf (buffer,
"Z -> Total = %10.2f (%10.2f + %7.2f) um", 10*(getZPositionTotal()), 10*getZPosition(), 10*getZPositionCorrection());STDLINE(buffer,ACCyan);