10 #include "otsdaq-core/MonicelliInterface/ROC.h"
12 using namespace monicelli;
17 ROC::
ROC(
unsigned int position,
int chipID,
unsigned int degrees) :
25 ,standardPixelPitch_(std::pair<
double,
double>(-1,-1))
26 ,calibrationFilePath_("")
28 this->setOrientation(degrees);
32 double ROC::calibrationFitFunction(
double *x,
double *par)
34 return par[0]+par[1]*tanh(par[2]*x[0]+par[3]);
38 double ROC::calibrationFitFunctionInv(
double *x,
double *par)
40 return (atanh((x[0]-par[0])/par[1]) - par[3])/par[2];
44 void ROC::setOrientation(
unsigned int degrees)
46 if (degrees==0 || degrees==180)
47 orientation_ = degrees;
48 else if(degrees==90 || degrees==270)
50 STDLINE(
"ERROR: Only 0 and 180 degrees rotations are supported for a ROC!", ACRed);
55 STDLINE(
"ERROR: Only 0 and 180 degrees rotations are supported for a ROC!", ACRed);
61 bool ROC::goodRow(
unsigned int row)
63 if ( row < numberOfRows_ )
67 ss_ <<
"WARNING: no pixel found with col number " << row;
68 STDLINE(ss_.str(), ACRed);
74 bool ROC::goodCol(
unsigned int col)
76 if ( col < numberOfCols_ )
81 ss_ <<
"WARNING: no pixel found with col number " << col;
82 STDLINE(ss_.str(), ACRed);
88 void ROC::setRowPitchVector(
void)
90 if(numberOfRows_ == 0)
return;
91 rowPitches_.resize(numberOfRows_, standardPixelPitch_.first);
92 rowLowEdge_.resize(numberOfRows_,0);
93 for(nonStandardPitchMapDef::iterator it=nonStandardRowPitch_.begin(); it != nonStandardRowPitch_.end(); it++)
95 if(it->first < rowPitches_.size())
97 rowPitches_[it->first] = it->second;
101 for(
unsigned int r=1; r<rowPitches_.size(); r++)
103 rowLowEdge_[r] = rowLowEdge_[r-1] + rowPitches_[r-1];
105 rocLengthY_ = rowLowEdge_[rowLowEdge_.size()-1] + rowPitches_[rowPitches_.size()-1];
109 void ROC::setColPitchVector(
void)
111 if(numberOfCols_ == 0)
return;
112 colPitches_.resize(numberOfCols_, standardPixelPitch_.second);
113 colLowEdge_.resize(numberOfCols_,0);
114 for(nonStandardPitchMapDef::iterator it=nonStandardColPitch_.begin(); it != nonStandardColPitch_.end(); it++)
116 if(it->first < colPitches_.size())
118 colPitches_[it->first] = it->second;
122 for(
unsigned int c=1; c<colPitches_.size(); c++)
124 colLowEdge_[c] = colLowEdge_[c-1] + colPitches_[c-1];
126 rocLengthX_ = colLowEdge_[colLowEdge_.size()-1] + colPitches_[colPitches_.size()-1];
130 void ROC::setNumberOfRowsCols(
unsigned int numberOfRows,
unsigned int numberOfCols)
132 numberOfRows_=numberOfRows;
134 numberOfCols_=numberOfCols;
139 void ROC::setNumberOfRows(
unsigned int numberOfRows)
141 numberOfRows_=numberOfRows;
146 void ROC::setNumberOfCols(
unsigned int numberOfCols)
148 numberOfCols_=numberOfCols;
153 void ROC::setStandardPixPitch(
double row_cm,
double col_cm)
155 standardPixelPitch_=std::make_pair(row_cm,col_cm);
161 void ROC::setOneRowPitch(
unsigned int row,
double row_cm)
163 nonStandardRowPitch_[row] = row_cm;
168 void ROC::setOneColPitch(
unsigned int col,
double col_cm)
170 nonStandardColPitch_[col] = col_cm;
175 double ROC::getPixelCenterLocalX(
unsigned int pixelCol )
177 if ( !goodCol(pixelCol) )
return -1;
178 return (this->getPixelLowEdgeLocalX(pixelCol) + this->getPixelPitchLocalX(pixelCol)/2.);
182 double ROC::getPixelCenterLocalY(
unsigned int pixelRow )
184 if ( !goodRow(pixelRow) )
return -1;
185 return (this->getPixelLowEdgeLocalY(pixelRow) + this->getPixelPitchLocalY(pixelRow)/2.);
189 double ROC::getPixelLowEdgeLocalX(
unsigned int pixelCol )
191 if ( !goodCol(pixelCol) )
return -1;
193 if( orientation_ == 0)
194 return colLowEdge_[pixelCol];
195 else if(orientation_ == 180)
196 return rocLengthX_ - colLowEdge_[pixelCol] - colPitches_[pixelCol];
200 ss_ <<
"WARNING: orientation not supported " << orientation_;
201 STDLINE(ss_.str(), ACRed);
206 double ROC::getPixelLowEdgeLocalY(
unsigned int pixelRow )
208 if ( !goodRow(pixelRow) )
return -1;
210 if( orientation_ == 0)
211 return rowLowEdge_[pixelRow];
212 else if(orientation_ == 180)
213 return rocLengthY_ - rowLowEdge_[pixelRow] - rowPitches_[pixelRow];
217 ss_ <<
"WARNING: orientation not supported " << orientation_;
218 STDLINE(ss_.str(), ACRed);
224 double ROC::getPixelHiEdgeLocalX(
unsigned int pixelCol )
226 if ( !goodCol(pixelCol) )
return -1;
227 return (this->getPixelLowEdgeLocalX(pixelCol) + this->getPixelPitchLocalX(pixelCol));
231 double ROC::getPixelHiEdgeLocalY(
unsigned int pixelRow )
233 if ( !goodRow(pixelRow) )
return -1;
234 return (this->getPixelLowEdgeLocalY(pixelRow) + this->getPixelPitchLocalY(pixelRow));
238 double ROC::getPixelPitchLocalX(
unsigned int pixelCol )
240 if ( !goodCol(pixelCol) )
return -1;
241 return colPitches_[pixelCol];
245 double ROC::getPixelPitchLocalY(
unsigned int pixelRow )
247 if ( !goodRow(pixelRow) )
return -1;
248 return rowPitches_[pixelRow];
252 double ROC::getLengthLocalX(
void )
258 double ROC::getLengthLocalY(
void )
264 bool ROC::calibratePixel(
int row,
int col,
int adc,
int& charge)
267 double maxVCal[1] = {255*421};
269 double *par = this->getCalibrationFunction(row, col);
272 if(newAdc[0] > ROC::calibrationFitFunction(maxVCal, par))
273 newAdc[0] = (int)ROC::calibrationFitFunction(maxVCal, par);
274 charge = (int)ROC::calibrationFitFunctionInv(newAdc, par);
286 bool ROC::isPixelCalibrated(
int row,
int col)
288 if( pixelCalibrationFunctionTmp_.count(row) && pixelCalibrationFunctionTmp_[row].count(col))
295 void ROC::setCalibrationFunction(
int row,
int col,
double *par,
double *cov)
297 if( pixelCalibrationFunctionTmp_.count(row) && pixelCalibrationFunctionTmp_[row].count(col))
298 pixelCalibrationFunctionTmp_.clear();
302 for(
int i=0; i < 4; i++)
304 pixelCalibrationFunctionTmp_[row][col].push_back(par[i]);
311 double* ROC::getCalibrationFunction(
int row,
int col)
313 if( pixelCalibrationFunctionTmp_.count(row) && pixelCalibrationFunctionTmp_[row].count(col))
314 for(
unsigned int i=0; i < pixelCalibrationFunctionTmp_[row][col].size(); i++)
315 par_[i] = pixelCalibrationFunctionTmp_[row][col][i] ;
323 double ROC::getCalibrationError(
int ,
int ,
int )