00001 #include "CalibTracker/SiPixelESProducers/interface/SiPixelCPEGenericDBErrorParametrization.h"
00002 #include "CondFormats/DataRecord/interface/SiPixelCPEGenericErrorParmRcd.h"
00003 #include <iostream>
00004 #include <cmath>
00005
00006 const float math_pi = 3.14159265;
00007
00008
00009
00010 const float SiPixelCPEGenericDBErrorParametrization::bx_a_min[3] = {1.525, 1.475, 1.425};
00011 const float SiPixelCPEGenericDBErrorParametrization::bx_a_max[3] = {1.725, 1.675, 1.625};
00012
00013 const float SiPixelCPEGenericDBErrorParametrization::fx_a_min[2] = {0.165, 0.185};
00014 const float SiPixelCPEGenericDBErrorParametrization::fx_a_max[2] = {0.285, 0.465};
00015 const float SiPixelCPEGenericDBErrorParametrization::fx_b_min[2] = {998, 998};
00016 const float SiPixelCPEGenericDBErrorParametrization::fx_b_max[2] = {999, 999};
00017
00018 const float SiPixelCPEGenericDBErrorParametrization::by_a_min[6] = {1.47078, 1.47078, 1.47078, 1.47078, 1.47078, 1.47078};
00019 const float SiPixelCPEGenericDBErrorParametrization::by_a_max[6] = {1.67078, 1.67078, 1.67078, 1.67078, 1.67078, 1.67078};
00020 const float SiPixelCPEGenericDBErrorParametrization::by_b_min[6] = {0.05, 0.15, 0.70, 0.95, 1.15, 1.20};
00021 const float SiPixelCPEGenericDBErrorParametrization::by_b_max[6] = {0.50, 0.90, 1.05, 1.15, 1.20, 1.40};
00022
00023 const float SiPixelCPEGenericDBErrorParametrization::fy_a_min[2] = {998, 998};
00024 const float SiPixelCPEGenericDBErrorParametrization::fy_a_max[2] = {999, 999};
00025 const float SiPixelCPEGenericDBErrorParametrization::fy_b_min[2] = {0.31, 0.31};
00026 const float SiPixelCPEGenericDBErrorParametrization::fy_b_max[2] = {0.39, 0.39};
00027
00028
00029 const float SiPixelCPEGenericDBErrorParametrization::errors_big_pix[4] = {0.0070, 0.0030, 0.0068, 0.0040};
00030 const int SiPixelCPEGenericDBErrorParametrization::size_max[4] = {5, 2, 0, 0};
00031
00032
00033 const float garbage[1] = {-9999.99};
00034
00035 const float* SiPixelCPEGenericDBErrorParametrization::a_min[4] = {by_a_min, bx_a_min, fy_a_min, fx_a_min};
00036 const float* SiPixelCPEGenericDBErrorParametrization::a_max[4] = {by_a_max, bx_a_max, fy_a_max, fx_a_max};
00037 const float* SiPixelCPEGenericDBErrorParametrization::b_min[4] = {by_b_min, garbage, fy_b_min, fx_b_min};
00038 const float* SiPixelCPEGenericDBErrorParametrization::b_max[4] = {by_b_max, garbage, fy_b_max, fx_b_max};
00039
00040
00041 const int SiPixelCPEGenericDBErrorParametrization::part_bin_size[4] = { 0, 240, 360, 380};
00042 const int SiPixelCPEGenericDBErrorParametrization::size_bin_size[4] = {40, 40, 40, 40};
00043 const int SiPixelCPEGenericDBErrorParametrization::alpha_bin_size[4] = {10, 1, 10, 1};
00044 const int SiPixelCPEGenericDBErrorParametrization::beta_bin_size[4] = { 1, 10, 1, 10};
00045
00046 SiPixelCPEGenericDBErrorParametrization::SiPixelCPEGenericDBErrorParametrization(){}
00047
00048 SiPixelCPEGenericDBErrorParametrization::~SiPixelCPEGenericDBErrorParametrization(){}
00049
00050 void SiPixelCPEGenericDBErrorParametrization::setDBAccess(const edm::EventSetup& es)
00051 {
00052 es.get<SiPixelCPEGenericErrorParmRcd>().get(errorsH);
00053 }
00054
00055
00056 std::pair<float,float> SiPixelCPEGenericDBErrorParametrization::getError(const SiPixelCPEGenericErrorParm* parmErrors,
00057 GeomDetType::SubDetector pixelPart,
00058 int sizex, int sizey,
00059 float alpha, float beta,
00060 bool bigInX, bool bigInY)
00061 {
00062 std::pair<float,float> element;
00063 std::pair<float,float> errors;
00064
00065 switch (pixelPart)
00066 {
00067 case GeomDetEnumerators::PixelBarrel:
00068 element = std::pair<float,float>(index(1, sizex, alpha, beta, bigInX),
00069 index(0, sizey, alpha, beta, bigInY));
00070 break;
00071 case GeomDetEnumerators::PixelEndcap:
00072 element = std::pair<float,float>(index(3, sizex, alpha, beta, bigInX),
00073 index(2, sizey, alpha, beta, bigInY));
00074 break;
00075 default:
00076 throw cms::Exception("PixelCPEGenericDBErrorParametrization::getError")
00077 << "Non-pixel detector type !!!" ;
00078 }
00079
00080 if (bigInX && sizex == 1) errors.first = element.first;
00081 else errors.first = parmErrors->errors()[(int)element.first].sigma;
00082 if (bigInY && sizey == 1) errors.second = element.second;
00083 else errors.second = parmErrors->errors()[(int)element.second].sigma;
00084
00085 return errors;
00086 }
00087
00088
00089 std::pair<float,float> SiPixelCPEGenericDBErrorParametrization::getError(GeomDetType::SubDetector pixelPart,
00090 int sizex, int sizey,
00091 float alpha, float beta,
00092 bool bigInX, bool bigInY)
00093 {
00094 std::pair<float,float> element;
00095 std::pair<float,float> errors;
00096
00097 switch (pixelPart)
00098 {
00099 case GeomDetEnumerators::PixelBarrel:
00100 element = std::pair<float,float>(index(1, sizex, alpha, beta, bigInX),
00101 index(0, sizey, alpha, beta, bigInY));
00102 break;
00103 case GeomDetEnumerators::PixelEndcap:
00104 element = std::pair<float,float>(index(3, sizex, alpha, beta, bigInX),
00105 index(2, sizey, alpha, beta, bigInY));
00106 break;
00107 default:
00108 throw cms::Exception("PixelCPEGenericDBErrorParametrization::getError")
00109 << "Non-pixel detector type !!!" ;
00110 }
00111
00112 if (bigInX && sizex == 1) errors.first = element.first;
00113 else errors.first = errorsH->errors()[(int)element.first].sigma;
00114 if (bigInY && sizey == 1) errors.second = element.second;
00115 else errors.second = errorsH->errors()[(int)element.second].sigma;
00116
00117 return errors;
00118 }
00119
00120
00121
00122 float SiPixelCPEGenericDBErrorParametrization::index(int ind_subpart, int size, float alpha, float beta, bool big)
00123 {
00124
00125 if ( big && size == 1) return errors_big_pix[ind_subpart];
00126
00127 int ind_size = std::min(size - 1, size_max[ind_subpart]);
00128
00129 float alpha_rad = -999.9;
00130 float betap_rad = -999.9;
00131
00132 int ind_alpha = -99;
00133 int ind_beta = -99;
00134
00135 float binw_a = -999.9;
00136 float binw_b = -999.9;
00137 int maxbin_a = -99;
00138 int maxbin_b = -99;
00139
00140 betap_rad = fabs(math_pi/2.0 - beta);
00141
00142 if(ind_subpart == 3) alpha_rad = fabs(math_pi/2.0 - alpha);
00143 else alpha_rad = fabs(alpha);
00144
00145
00146 if(ind_subpart == 0||ind_subpart == 2)
00147 {
00148 binw_a = (a_max[ind_subpart][ind_size] - a_min[ind_subpart][ind_size])/2.0;
00149 binw_b = (b_max[ind_subpart][ind_size] - b_min[ind_subpart][ind_size])/8.0;
00150 maxbin_a = 3;
00151 maxbin_b = 9;
00152 }
00153 else
00154 {
00155 binw_a = (a_max[ind_subpart][ind_size] - a_min[ind_subpart][ind_size])/8.0;
00156 binw_b = (b_max[ind_subpart][ind_size] - b_min[ind_subpart][ind_size])/2.0;
00157 maxbin_a = 3;
00158 maxbin_b = 9;
00159 }
00160
00161
00162 if ( alpha_rad < a_min[ind_subpart][ind_size]) ind_alpha = 0;
00163 else if ( alpha_rad >= a_max[ind_subpart][ind_size]) ind_alpha = maxbin_a;
00164 else ind_alpha = 1 + (int)((alpha_rad - a_min[ind_subpart][ind_size])/binw_a);
00165
00166
00167 if(ind_subpart == 1)
00168 {
00169 if ( betap_rad <= 0.7 ) ind_beta = 0;
00170 else if ( 0.7 < betap_rad && betap_rad <= 1.0 ) ind_beta = 1;
00171 else if ( 1.0 < betap_rad && betap_rad <= 1.2 ) ind_beta = 2;
00172 else if ( 1.2 <= betap_rad ) ind_beta = 3;
00173 }
00174 else if ( betap_rad < b_min[ind_subpart][ind_size]) ind_beta = 0;
00175 else if ( betap_rad >= b_max[ind_subpart][ind_size]) ind_beta = maxbin_b;
00176 else ind_beta = 1 + (int)((betap_rad - b_min[ind_subpart][ind_size])/binw_b);
00177
00178
00179 int index = part_bin_size[ind_subpart] + size_bin_size[ind_subpart] * ind_size + alpha_bin_size[ind_subpart] * ind_alpha + beta_bin_size[ind_subpart] * ind_beta;
00180
00181 return index;
00182 }