00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "otsdaq-core/MonicelliInterface/ROC.h"
00011
00012 using namespace monicelli;
00013
00014 ClassImp(ROC)
00015
00016
00017 ROC::ROC(unsigned int position, int chipID, unsigned int degrees) :
00018 rocLengthX_(0)
00019 ,rocLengthY_(0)
00020 ,numberOfRows_(0)
00021 ,numberOfCols_(0)
00022 ,chipID_(chipID)
00023 ,orientation_(0)
00024 ,position_(position)
00025 ,standardPixelPitch_(std::pair<double,double>(-1,-1))
00026 ,calibrationFilePath_("")
00027 {
00028 this->setOrientation(degrees);
00029 }
00030
00031
00032 double ROC::calibrationFitFunction(double *x, double *par)
00033 {
00034 return par[0]+par[1]*tanh(par[2]*x[0]+par[3]);
00035 }
00036
00037
00038 double ROC::calibrationFitFunctionInv(double *x, double *par)
00039 {
00040 return (atanh((x[0]-par[0])/par[1]) - par[3])/par[2];
00041 }
00042
00043
00044 void ROC::setOrientation(unsigned int degrees)
00045 {
00046 if (degrees==0 || degrees==180)
00047 orientation_ = degrees;
00048 else if(degrees==90 || degrees==270)
00049 {
00050 STDLINE("ERROR: Only 0 and 180 degrees rotations are supported for a ROC!", ACRed);
00051 exit(EXIT_FAILURE);
00052 }
00053 else
00054 {
00055 STDLINE("ERROR: Only 0 and 180 degrees rotations are supported for a ROC!", ACRed);
00056 exit(EXIT_FAILURE);
00057 }
00058 }
00059
00060
00061 bool ROC::goodRow(unsigned int row)
00062 {
00063 if ( row < numberOfRows_ )
00064 return true;
00065 else{
00066 ss_.str("");
00067 ss_ << "WARNING: no pixel found with col number " << row;
00068 STDLINE(ss_.str(), ACRed);
00069 return false;
00070 }
00071 }
00072
00073
00074 bool ROC::goodCol(unsigned int col)
00075 {
00076 if ( col < numberOfCols_ )
00077 return true;
00078 else
00079 {
00080 ss_.str("");
00081 ss_ << "WARNING: no pixel found with col number " << col;
00082 STDLINE(ss_.str(), ACRed);
00083 return false;
00084 }
00085 }
00086
00087
00088 void ROC::setRowPitchVector(void)
00089 {
00090 if(numberOfRows_ == 0) return;
00091 rowPitches_.resize(numberOfRows_, standardPixelPitch_.first);
00092 rowLowEdge_.resize(numberOfRows_,0);
00093 for(nonStandardPitchMapDef::iterator it=nonStandardRowPitch_.begin(); it != nonStandardRowPitch_.end(); it++)
00094 {
00095 if(it->first < rowPitches_.size())
00096 {
00097 rowPitches_[it->first] = it->second;
00098 }
00099 }
00100 rowLowEdge_[0] = 0;
00101 for(unsigned int r=1; r<rowPitches_.size(); r++)
00102 {
00103 rowLowEdge_[r] = rowLowEdge_[r-1] + rowPitches_[r-1];
00104 }
00105 rocLengthY_ = rowLowEdge_[rowLowEdge_.size()-1] + rowPitches_[rowPitches_.size()-1];
00106 }
00107
00108
00109 void ROC::setColPitchVector(void)
00110 {
00111 if(numberOfCols_ == 0) return;
00112 colPitches_.resize(numberOfCols_, standardPixelPitch_.second);
00113 colLowEdge_.resize(numberOfCols_,0);
00114 for(nonStandardPitchMapDef::iterator it=nonStandardColPitch_.begin(); it != nonStandardColPitch_.end(); it++)
00115 {
00116 if(it->first < colPitches_.size())
00117 {
00118 colPitches_[it->first] = it->second;
00119 }
00120 }
00121 colLowEdge_[0] = 0;
00122 for(unsigned int c=1; c<colPitches_.size(); c++)
00123 {
00124 colLowEdge_[c] = colLowEdge_[c-1] + colPitches_[c-1];
00125 }
00126 rocLengthX_ = colLowEdge_[colLowEdge_.size()-1] + colPitches_[colPitches_.size()-1];
00127 }
00128
00129
00130 void ROC::setNumberOfRowsCols(unsigned int numberOfRows, unsigned int numberOfCols)
00131 {
00132 numberOfRows_=numberOfRows;
00133 setRowPitchVector();
00134 numberOfCols_=numberOfCols;
00135 setColPitchVector();
00136 }
00137
00138
00139 void ROC::setNumberOfRows(unsigned int numberOfRows)
00140 {
00141 numberOfRows_=numberOfRows;
00142 setRowPitchVector();
00143 }
00144
00145
00146 void ROC::setNumberOfCols(unsigned int numberOfCols)
00147 {
00148 numberOfCols_=numberOfCols;
00149 setColPitchVector();
00150 }
00151
00152
00153 void ROC::setStandardPixPitch(double row_cm, double col_cm)
00154 {
00155 standardPixelPitch_=std::make_pair(row_cm,col_cm);
00156 setRowPitchVector();
00157 setColPitchVector();
00158 }
00159
00160
00161 void ROC::setOneRowPitch(unsigned int row, double row_cm)
00162 {
00163 nonStandardRowPitch_[row] = row_cm;
00164 setRowPitchVector();
00165 }
00166
00167
00168 void ROC::setOneColPitch(unsigned int col, double col_cm)
00169 {
00170 nonStandardColPitch_[col] = col_cm;
00171 setColPitchVector();
00172 }
00173
00174
00175 double ROC::getPixelCenterLocalX( unsigned int pixelCol )
00176 {
00177 if ( !goodCol(pixelCol) ) return -1;
00178 return (this->getPixelLowEdgeLocalX(pixelCol) + this->getPixelPitchLocalX(pixelCol)/2.);
00179 }
00180
00181
00182 double ROC::getPixelCenterLocalY(unsigned int pixelRow )
00183 {
00184 if ( !goodRow(pixelRow) ) return -1;
00185 return (this->getPixelLowEdgeLocalY(pixelRow) + this->getPixelPitchLocalY(pixelRow)/2.);
00186 }
00187
00188
00189 double ROC::getPixelLowEdgeLocalX(unsigned int pixelCol )
00190 {
00191 if ( !goodCol(pixelCol) ) return -1;
00192
00193 if( orientation_ == 0)
00194 return colLowEdge_[pixelCol];
00195 else if(orientation_ == 180)
00196 return rocLengthX_ - colLowEdge_[pixelCol] - colPitches_[pixelCol];
00197 else
00198 {
00199 ss_.str("");
00200 ss_ << "WARNING: orientation not supported " << orientation_;
00201 STDLINE(ss_.str(), ACRed);
00202 return -1;
00203 }
00204 }
00205
00206 double ROC::getPixelLowEdgeLocalY(unsigned int pixelRow )
00207 {
00208 if ( !goodRow(pixelRow) ) return -1;
00209
00210 if( orientation_ == 0)
00211 return rowLowEdge_[pixelRow];
00212 else if(orientation_ == 180)
00213 return rocLengthY_ - rowLowEdge_[pixelRow] - rowPitches_[pixelRow];
00214 else
00215 {
00216 ss_.str("");
00217 ss_ << "WARNING: orientation not supported " << orientation_;
00218 STDLINE(ss_.str(), ACRed);
00219 return -1;
00220 }
00221 }
00222
00223
00224 double ROC::getPixelHiEdgeLocalX(unsigned int pixelCol )
00225 {
00226 if ( !goodCol(pixelCol) ) return -1;
00227 return (this->getPixelLowEdgeLocalX(pixelCol) + this->getPixelPitchLocalX(pixelCol));
00228 }
00229
00230
00231 double ROC::getPixelHiEdgeLocalY(unsigned int pixelRow )
00232 {
00233 if ( !goodRow(pixelRow) ) return -1;
00234 return (this->getPixelLowEdgeLocalY(pixelRow) + this->getPixelPitchLocalY(pixelRow));
00235 }
00236
00237
00238 double ROC::getPixelPitchLocalX(unsigned int pixelCol )
00239 {
00240 if ( !goodCol(pixelCol) ) return -1;
00241 return colPitches_[pixelCol];
00242 }
00243
00244
00245 double ROC::getPixelPitchLocalY(unsigned int pixelRow )
00246 {
00247 if ( !goodRow(pixelRow) ) return -1;
00248 return rowPitches_[pixelRow];
00249 }
00250
00251
00252 double ROC::getLengthLocalX(void )
00253 {
00254 return rocLengthX_;
00255 }
00256
00257
00258 double ROC::getLengthLocalY(void )
00259 {
00260 return rocLengthY_;
00261 }
00262
00263
00264 bool ROC::calibratePixel(int row, int col, int adc, int& charge)
00265 {
00266 double newAdc[1];
00267 double maxVCal[1] = {255*421};
00268 newAdc[0] = adc;
00269 double *par = this->getCalibrationFunction(row, col);
00270 if(par != 0)
00271 {
00272 if(newAdc[0] > ROC::calibrationFitFunction(maxVCal, par))
00273 newAdc[0] = (int)ROC::calibrationFitFunction(maxVCal, par);
00274 charge = (int)ROC::calibrationFitFunctionInv(newAdc, par);
00275 return true;
00276 }
00277 else
00278 {
00279
00280 charge = -999999;
00281 return false;
00282 }
00283 }
00284
00285
00286 bool ROC::isPixelCalibrated(int row, int col)
00287 {
00288 if( pixelCalibrationFunctionTmp_.count(row) && pixelCalibrationFunctionTmp_[row].count(col))
00289 return true;
00290 else
00291 return false;
00292 }
00293
00294
00295 void ROC::setCalibrationFunction(int row, int col, double *par, double *cov)
00296 {
00297 if( pixelCalibrationFunctionTmp_.count(row) && pixelCalibrationFunctionTmp_[row].count(col))
00298 pixelCalibrationFunctionTmp_.clear();
00299
00300 if(par != NULL)
00301 {
00302 for(int i=0; i < 4; i++)
00303 {
00304 pixelCalibrationFunctionTmp_[row][col].push_back(par[i]);
00305 *cov = 0;
00306 }
00307 }
00308 }
00309
00310
00311 double* ROC::getCalibrationFunction(int row, int col)
00312 {
00313 if( pixelCalibrationFunctionTmp_.count(row) && pixelCalibrationFunctionTmp_[row].count(col))
00314 for(unsigned int i=0; i < pixelCalibrationFunctionTmp_[row][col].size(); i++)
00315 par_[i] = pixelCalibrationFunctionTmp_[row][col][i] ;
00316 else
00317 return 0;
00318
00319 return par_;
00320 }
00321
00322
00323 double ROC::getCalibrationError(int , int , int )
00324 {
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 return -1;
00370 }