otsdaq  v2_00_00
ROC.h
1 /****************************************************************************
2 ** Authors: Dario Menasce, Stefano Terzo
3 **
4 ** I.N.F.N. Milan-Bicocca
5 ** Piazza della Scienza 3, Edificio U2
6 ** Milano, 20126
7 **
8 ****************************************************************************/
9 
10 #ifndef ROC_H
11 #define ROC_H
12 
13 #include <string>
14 #include <map>
15 #include <string>
16 #include <vector>
17 #include <TObject.h>
18 
19 #include <Math/SMatrix.h>
20 #include <Math/SVector.h>
21 
22 #include "MessageTools.h"
23 
24 namespace monicelli
25 {
26 
27 class ROC : public TObject
28 {
29  public:
30  ROC(unsigned int position=0, int chipID=-1, unsigned int degrees=0);
31  ~ROC(void) {;}
32 
33  //only 0, 90, 180, 270
34  // Y
35  // ^
36  // |
37  // |-------------| //an example of chip orientations
38  // | max row|
39  // | ^| 90 degrees
40  // |max col...< 0|
41  // |-------------|
42  // |max col...< 0|
43  // | :| 180 degrees
44  // | max row|
45  // |-------------|
46  // |0 >...max col|
47  // |: | 270 degrees
48  // |max row |
49  // |-------------|
50  // |max row |
51  // |^ | 0 degrees
52  // |0 >...max col|
53  // o--------------------->X
54  // Z
55 
56 
57 // typedef std::map< int, std::map<int, double> > covMatMapDef ;
58 // typedef std::pair<double*, ROC::covMatMapDef> fitResultPairDef ;
59 
60  static double calibrationFitFunction (double * x, double * par );
61  double calibrationFitFunctionInv(double * x, double * par );
62  bool calibratePixel (int row, int col, int adc, int& charge );
63 
64  void setCalibrationFilePath (std::string path ) {calibrationFilePath_= path; }
65 // void setCalibrationFunction (int row, int col, double *par, double *cov, int nPars) ;
66  void setCalibrationFunction (int row, int col, double *par, double *cov) ;
67  void setStandardPixPitch (double raw_cm , double col_cm ) ;
68  void setOneRowPitch (unsigned int raw , double row_cm ) ;
69  void setOneColPitch (unsigned int col , double col_cm ) ;
70  void setOrientation (unsigned int degrees ) ;
71  void setNumberOfRowsCols (unsigned int maxRows , unsigned int maxCols ) ;
72  void setNumberOfRows (unsigned int maxRows ) ;
73  void setNumberOfCols (unsigned int maxCols ) ;
74  void setLocalXPosition (unsigned int xLocalPosition ) {xLocalPosition_ = xLocalPosition;}
75  void setLocalYPosition (unsigned int yLocalPosition ) {yLocalPosition_ = yLocalPosition;}
76  void setFirstRow (unsigned int firstRow ) {firstRow_ = firstRow; }
77  void setLastRow (unsigned int lastRow ) {lastRow_ = lastRow; }
78  void setFirstCol (unsigned int firstCol ) {firstCol_ = firstCol; }
79  void setLastCol (unsigned int lastCol ) {lastCol_ = lastCol; }
80 
81  std::string getCalibrationFilePath (void ) {return calibrationFilePath_; }
82  int getID (void ) {return chipID_; }
83  unsigned int getOrientation (void ) {return orientation_; }
84  unsigned int getPosition (void ) {return position_; }
85  double getPixelCenterLocalX (unsigned int col ) ;
86  double getPixelCenterLocalY (unsigned int row ) ;
87  double getPixelHiEdgeLocalX (unsigned int col ) ;
88  double getPixelHiEdgeLocalY (unsigned int row ) ;
89  double getPixelLowEdgeLocalX (unsigned int col ) ;
90  double getPixelLowEdgeLocalY (unsigned int row ) ;
91  double getPixelPitchLocalX (unsigned int col ) ;
92  double getPixelPitchLocalY (unsigned int row ) ;
93  double getLengthLocalX (void ) ;
94  double getLengthLocalY (void ) ;
95 
96  double getCalibrationError (int row, int col ,int adc ) ;
97  double* getCalibrationFunction (int row, int col ) ;
98  bool isPixelCalibrated (int row, int col ) ;
99 
100  unsigned int getNumberOfRows (void ) {return numberOfRows_; }
101  unsigned int getNumberOfCols (void ) {return numberOfCols_; }
102  unsigned int getPositionLocalX (void ) {return xLocalPosition_; }
103  unsigned int getPositionLocalY (void ) {return yLocalPosition_; }
104  unsigned int getFirstRow (void ) {return firstRow_; }
105  unsigned int getLastRow (void ) {return lastRow_; }
106  unsigned int getFirstCol (void ) {return firstCol_; }
107  unsigned int getLastCol (void ) {return lastCol_; }
108 
109 
110 
111  private:
112 
113  typedef std::map< int,std::map<int, ROOT::Math::SMatrix<double,4> > > pixelCalibrationsCovDef ;
114  //row picth , col pitch
115  typedef std::pair<double, double > rowColPitchPairDef ;
116  //key: row or col Pitch
117  typedef std::map<unsigned int , double> nonStandardPitchMapDef ;
118  // row col pars
119  typedef std::map< int,std::map<int, double*> > pixelCalibrationsMapDef ;
120 
121  typedef std::map< int,std::map<int, std::vector<double> > > pixelCalibrationsTmpMapDef ;
122 
123  bool goodRow (unsigned int row);
124  bool goodCol (unsigned int col);
125  void setRowPitchVector(void);
126  void setColPitchVector(void);
127  std::vector<double> rowPitches_;
128  std::vector<double> colPitches_;
129  std::vector<double> rowLowEdge_;
130  std::vector<double> colLowEdge_;
131  double rocLengthX_;
132  double rocLengthY_;
133 
134  unsigned int numberOfRows_ ;//the number of rows for a chip
135  //it will be used to check merged data integrity
136  unsigned int numberOfCols_ ;//the number of columns for a chip
137  //it will be used to check merged data integrity
138 
139  int chipID_ ;
140  unsigned int orientation_ ;
141  unsigned int position_ ;
142  rowColPitchPairDef standardPixelPitch_ ;
143  nonStandardPitchMapDef nonStandardRowPitch_ ;
144  nonStandardPitchMapDef nonStandardColPitch_ ;
145  std::string calibrationFilePath_ ;
146 // pixelCalibrationsMapDef pixelCalibrationFunction_ ;//! temporary state value
147  pixelCalibrationsTmpMapDef pixelCalibrationFunctionTmp_ ;
148  pixelCalibrationsCovDef pixelCalibrationCovMat_ ;
149  double par_[4] ;
150 
151  //Roc properties set by the detector (plaquette) the rocs belong to
152  unsigned int xLocalPosition_;
153  unsigned int yLocalPosition_;
154  unsigned int firstRow_;
155  unsigned int lastRow_;
156  unsigned int firstCol_;
157  unsigned int lastCol_;
158 
159 
160  std::stringstream ss_ ;
161 
162  ClassDef(ROC,5)
163 
164 } ;
165 }
166 #endif // ROC_H