00001
00002
00003
00004
00005
00006 #include <vector>
00007 #include <string>
00008
00009 #include "CLHEP/Random/RandGauss.h"
00010 #include "CondFormats/CastorObjects/interface/CastorElectronicsMap.h"
00011 #include "CalibCalorimetry/CastorCalib/interface/CastorDbHardcode.h"
00012
00013
00014 CastorPedestal CastorDbHardcode::makePedestal (HcalGenericDetId fId, bool fSmear) {
00015 CastorPedestalWidth width = makePedestalWidth (fId);
00016 float value0 = fId.genericSubdet() == HcalGenericDetId::HcalGenForward ? 11. : 4.;
00017 float value [4] = {value0, value0, value0, value0};
00018 if (fSmear) {
00019 for (int i = 0; i < 4; i++) {
00020 value [i] = CLHEP::RandGauss::shoot (value0, width.getWidth (i) / 100.);
00021 while (value [i] <= 0) value [i] = CLHEP::RandGauss::shoot (value0, width.getWidth (i));
00022 }
00023 }
00024 CastorPedestal result (fId.rawId (),
00025 value[0], value[1], value[2], value[3]
00026 );
00027 return result;
00028 }
00029
00030 CastorPedestalWidth CastorDbHardcode::makePedestalWidth (HcalGenericDetId fId) {
00031 float value = 0;
00032
00033
00034
00035
00036
00037
00038
00039 CastorPedestalWidth result (fId.rawId ());
00040 for (int i = 0; i < 4; i++) {
00041 double width = value;
00042 for (int j = 0; j < 4; j++) {
00043 result.setSigma (i, j, i == j ? width * width : 0);
00044 }
00045 }
00046 return result;
00047 }
00048
00049 CastorGain CastorDbHardcode::makeGain (HcalGenericDetId fId, bool fSmear) {
00050 CastorGainWidth width = makeGainWidth (fId);
00051 float value0 = 0;
00052 if (fId.genericSubdet() != HcalGenericDetId::HcalGenForward) value0 = 0.177;
00053 else {
00054 if (HcalDetId(fId).depth() == 1) value0 = 0.2146;
00055 else if (HcalDetId(fId).depth() == 2) value0 = 0.3375;
00056 }
00057 float value [4] = {value0, value0, value0, value0};
00058 if (fSmear) for (int i = 0; i < 4; i++) value [i] = CLHEP::RandGauss::shoot (value0, width.getValue (i));
00059 CastorGain result (fId.rawId (), value[0], value[1], value[2], value[3]);
00060 return result;
00061 }
00062
00063 CastorGainWidth CastorDbHardcode::makeGainWidth (HcalGenericDetId fId) {
00064 float value = 0;
00065 CastorGainWidth result (fId.rawId (), value, value, value, value);
00066 return result;
00067 }
00068
00069 CastorQIECoder CastorDbHardcode::makeQIECoder (HcalGenericDetId fId) {
00070 CastorQIECoder result (fId.rawId ());
00071 float offset = 0;
00072 float slope = fId.genericSubdet () == HcalGenericDetId::HcalGenForward ? 0.36 : 0.92;
00073 for (unsigned range = 0; range < 4; range++) {
00074 for (unsigned capid = 0; capid < 4; capid++) {
00075 result.setOffset (capid, range, offset);
00076 result.setSlope (capid, range, slope);
00077 }
00078 }
00079 return result;
00080 }
00081
00082 CastorCalibrationQIECoder CastorDbHardcode::makeCalibrationQIECoder (HcalGenericDetId fId) {
00083 CastorCalibrationQIECoder result (fId.rawId ());
00084 float lowEdges [32];
00085 for (int i = 0; i < 32; i++) lowEdges[i] = -1.5 + i*0.35;
00086 result.setMinCharges (lowEdges);
00087 return result;
00088 }
00089
00090 CastorQIEShape CastorDbHardcode::makeQIEShape () {
00091 return CastorQIEShape ();
00092 }
00093
00094 CastorRecoParam CastorDbHardcode::makeRecoParam (HcalGenericDetId fId) {
00095 CastorRecoParam result(fId.rawId(), 4, 2);
00096 return result;
00097 }
00098
00099 CastorSaturationCorr CastorDbHardcode::makeSaturationCorr (HcalGenericDetId fId) {
00100 CastorSaturationCorr result(fId.rawId(), 1);
00101 return result;
00102 }
00103
00104 #define EMAP_NHBHECR 9
00105 #define EMAP_NHFCR 3
00106 #define EMAP_NHOCR 4
00107 #define EMAP_NFBR 8
00108 #define EMAP_NFCH 3
00109 #define EMAP_NHTRS 3
00110 #define EMAP_NHSETS 4
00111 #define EMAP_NTOPBOT 2
00112 #define EMAP_NHTRSHO 4
00113 #define EMAP_NHSETSHO 3
00114
00115 void CastorDbHardcode::makeHardcodeMap(CastorElectronicsMap& emap) {
00116
00117
00118 int hbhecrate[EMAP_NHBHECR]={0,1,4,5,10,11,14,15,17};
00119
00120 int hfcrate[EMAP_NHFCR]={2,9,12};
00121
00122 int hocrate[EMAP_NHOCR]={3,7,6,13};
00123
00124 int fedhbhenum[EMAP_NHBHECR][2]={{702,703},{704,705},{700,701},
00125 {706,707},{716,717},{708,709},
00126 {714,715},{710,711},{712,713}};
00127
00128 int fedhfnum[EMAP_NHFCR][2]={{718,719},{720,721},{722,723}};
00129
00130 int fedhonum[EMAP_NHOCR][2]={{724,725},{726,727},{728,729},{730,731}};
00131
00132 int ihslot[EMAP_NHSETS]={2,5,13,16};
00133
00134 int ihslotho[EMAP_NHSETSHO][EMAP_NHTRSHO]={{2,3,4,5},{6,7,13,14},{15,16,17,18}};
00135
00136 int ihbhephis[EMAP_NHBHECR]={11,19,3,27,67,35,59,43,51};
00137
00138 int ihfphis[EMAP_NHFCR]={3,27,51};
00139
00140 int ihophis[EMAP_NHOCR]={71,17,35,53};
00141
00142 int ihbheetadepth[EMAP_NHTRS][EMAP_NTOPBOT][EMAP_NFBR][EMAP_NFCH][2]={
00143 {{{{11,1},{ 7,1},{ 3,1}},
00144 {{ 5,1},{ 1,1},{ 9,1}},
00145 {{11,1},{ 7,1},{ 3,1}},
00146 {{ 5,1},{ 1,1},{ 9,1}},
00147 {{10,1},{ 6,1},{ 2,1}},
00148 {{ 8,1},{ 4,1},{12,1}},
00149 {{10,1},{ 6,1},{ 2,1}},
00150 {{ 8,1},{ 4,1},{12,1}}},
00151 {{{11,1},{ 7,1},{ 3,1}},
00152 {{ 5,1},{ 1,1},{ 9,1}},
00153 {{11,1},{ 7,1},{ 3,1}},
00154 {{ 5,1},{ 1,1},{ 9,1}},
00155 {{10,1},{ 6,1},{ 2,1}},
00156 {{ 8,1},{ 4,1},{12,1}},
00157 {{10,1},{ 6,1},{ 2,1}},
00158 {{ 8,1},{ 4,1},{12,1}}}},
00159 {{{{16,2},{15,2},{14,1}},
00160 {{15,1},{13,1},{16,1}},
00161 {{16,2},{15,2},{14,1}},
00162 {{15,1},{13,1},{16,1}},
00163 {{17,1},{16,3},{26,1}},
00164 {{18,1},{18,2},{26,2}},
00165 {{17,1},{16,3},{25,1}},
00166 {{18,1},{18,2},{25,2}}},
00167 {{{16,2},{15,2},{14,1}},
00168 {{15,1},{13,1},{16,1}},
00169 {{16,2},{15,2},{14,1}},
00170 {{15,1},{13,1},{16,1}},
00171 {{17,1},{16,3},{25,1}},
00172 {{18,1},{18,2},{25,2}},
00173 {{17,1},{16,3},{26,1}},
00174 {{18,1},{18,2},{26,2}}}},
00175 {{{{28,1},{28,2},{29,1}},
00176 {{28,3},{24,2},{24,1}},
00177 {{27,1},{27,2},{29,2}},
00178 {{27,3},{23,2},{23,1}},
00179 {{19,2},{20,1},{22,2}},
00180 {{19,1},{20,2},{22,1}},
00181 {{19,2},{20,1},{21,2}},
00182 {{19,1},{20,2},{21,1}}},
00183 {{{27,1},{27,2},{29,2}},
00184 {{27,3},{23,2},{23,1}},
00185 {{28,1},{28,2},{29,1}},
00186 {{28,3},{24,2},{24,1}},
00187 {{19,2},{20,1},{21,2}},
00188 {{19,1},{20,2},{21,1}},
00189 {{19,2},{20,1},{22,2}},
00190 {{19,1},{20,2},{22,1}}}}
00191 };
00192
00193 int ihfetadepth[EMAP_NTOPBOT][EMAP_NFBR][EMAP_NFCH][2]={
00194 {{{33,1},{31,1},{29,1}},
00195 {{32,1},{30,1},{34,1}},
00196 {{33,2},{31,2},{29,2}},
00197 {{32,2},{30,2},{34,2}},
00198 {{34,2},{32,2},{30,2}},
00199 {{31,2},{29,2},{33,2}},
00200 {{34,1},{32,1},{30,1}},
00201 {{31,1},{29,1},{33,1}}},
00202 {{{41,1},{37,1},{35,1}},
00203 {{38,1},{36,1},{39,1}},
00204 {{41,2},{37,2},{35,2}},
00205 {{38,2},{36,2},{39,2}},
00206 {{40,2},{38,2},{36,2}},
00207 {{37,2},{35,2},{39,2}},
00208 {{40,1},{38,1},{36,1}},
00209 {{37,1},{35,1},{39,1}}}
00210 };
00211
00212 int ihoetasidephi[EMAP_NHTRSHO][EMAP_NTOPBOT][EMAP_NFBR][EMAP_NFCH][3]={
00213 {{{{ 1,-1,0},{ 2,-1,0},{ 3,-1,0}},
00214 {{ 1,-1,1},{ 2,-1,1},{ 3,-1,1}},
00215 {{ 1,-1,2},{ 2,-1,2},{ 3,-1,2}},
00216 {{ 1,-1,3},{ 2,-1,3},{ 3,-1,3}},
00217 {{ 1,-1,4},{ 2,-1,4},{ 3,-1,4}},
00218 {{ 1,-1,5},{ 2,-1,5},{ 3,-1,5}},
00219 {{14, 1,0},{14, 1,1},{14, 1,2}},
00220 {{14, 1,3},{14, 1,4},{14, 1,5}}},
00221 {{{ 1, 1,0},{ 2, 1,0},{ 3, 1,0}},
00222 {{ 1, 1,1},{ 2, 1,1},{ 3, 1,1}},
00223 {{ 1, 1,2},{ 2, 1,2},{ 3, 1,2}},
00224 {{ 1, 1,3},{ 2, 1,3},{ 3, 1,3}},
00225 {{ 1, 1,4},{ 2, 1,4},{ 3, 1,4}},
00226 {{ 1, 1,5},{ 2, 1,5},{ 3, 1,5}},
00227 {{15, 1,0},{15, 1,1},{15, 1,2}},
00228 {{15, 1,3},{15, 1,4},{15, 1,5}}}},
00229 {{{{ 6, 1,0},{ 6, 1,1},{ 6, 1,2}},
00230 {{ 6, 1,3},{ 6, 1,4},{ 6, 1,5}},
00231 {{ 7, 1,0},{ 7, 1,1},{ 7, 1,2}},
00232 {{ 7, 1,3},{ 7, 1,4},{ 7, 1,5}},
00233 {{ 8, 1,0},{ 8, 1,1},{ 8, 1,2}},
00234 {{ 8, 1,3},{ 8, 1,4},{ 8, 1,5}},
00235 {{ 9, 1,0},{ 9, 1,1},{ 9, 1,2}},
00236 {{ 9, 1,3},{ 9, 1,4},{ 9, 1,5}}},
00237 {{{10, 1,0},{10, 1,1},{10, 1,2}},
00238 {{10, 1,3},{10, 1,4},{10, 1,5}},
00239 {{11, 1,0},{11, 1,1},{11, 1,2}},
00240 {{11, 1,3},{11, 1,4},{11, 1,5}},
00241 {{12, 1,0},{12, 1,1},{12, 1,2}},
00242 {{12, 1,3},{12, 1,4},{12, 1,5}},
00243 {{13, 1,0},{13, 1,1},{13, 1,2}},
00244 {{13, 1,3},{13, 1,4},{13, 1,5}}}},
00245 {{{{ 4,-1,0},{ 4,-1,1},{ 0, 0,0}},
00246 {{ 4,-1,2},{ 4,-1,3},{ 0, 0,0}},
00247 {{ 4,-1,4},{ 4,-1,5},{ 0, 0,0}},
00248 {{ 0, 0,0},{ 0, 0,0},{ 0, 0,0}},
00249 {{ 5,-1,0},{ 5,-1,1},{ 5,-1,2}},
00250 {{ 5,-1,3},{ 5,-1,4},{ 5,-1,5}},
00251 {{14,-1,0},{14,-1,1},{14,-1,2}},
00252 {{14,-1,3},{14,-1,4},{14,-1,5}}},
00253 {{{ 4, 1,0},{ 4, 1,1},{ 0, 0,0}},
00254 {{ 4, 1,2},{ 4, 1,3},{ 0, 0,0}},
00255 {{ 4, 1,4},{ 4, 1,5},{ 0, 0,0}},
00256 {{ 0, 0,0},{ 0, 0,0},{ 0, 0,0}},
00257 {{ 5, 1,0},{ 5, 1,1},{ 5, 1,2}},
00258 {{ 5, 1,3},{ 5, 1,4},{ 5, 1,5}},
00259 {{15,-1,0},{15,-1,1},{15,-1,2}},
00260 {{15,-1,3},{15,-1,4},{15,-1,5}}}},
00261 {{{{ 6,-1,0},{ 6,-1,1},{ 6,-1,2}},
00262 {{ 6,-1,3},{ 6,-1,4},{ 6,-1,5}},
00263 {{ 7,-1,0},{ 7,-1,1},{ 7,-1,2}},
00264 {{ 7,-1,3},{ 7,-1,4},{ 7,-1,5}},
00265 {{ 8,-1,0},{ 8,-1,1},{ 8,-1,2}},
00266 {{ 8,-1,3},{ 8,-1,4},{ 8,-1,5}},
00267 {{ 9,-1,0},{ 9,-1,1},{ 9,-1,2}},
00268 {{ 9,-1,3},{ 9,-1,4},{ 9,-1,5}}},
00269 {{{10,-1,0},{10,-1,1},{10,-1,2}},
00270 {{10,-1,3},{10,-1,4},{10,-1,5}},
00271 {{11,-1,0},{11,-1,1},{11,-1,2}},
00272 {{11,-1,3},{11,-1,4},{11,-1,5}},
00273 {{12,-1,0},{12,-1,1},{12,-1,2}},
00274 {{12,-1,3},{12,-1,4},{12,-1,5}},
00275 {{13,-1,0},{13,-1,1},{13,-1,2}},
00276 {{13,-1,3},{13,-1,4},{13,-1,5}}}}
00277 };
00278 int ic,is,ih,itb,ifb,ifc,ifwtb,iphi_loc;
00279 int iside,ieta,iphi,idepth,icrate,ihtr,ihtr_fi,ifi_ch,ispigot,idcc,ifed;
00280 std::string det;
00281 std::string fpga;
00282
00283
00284 for(ic=0; ic<EMAP_NHBHECR; ic++){
00285
00286 for(is=0; is<EMAP_NHSETS; is++){
00287
00288 for(ih=0; ih<EMAP_NHTRS; ih++){
00289
00290 for(itb=0; itb<EMAP_NTOPBOT; itb++){
00291
00292 for(ifb=0; ifb<EMAP_NFBR; ifb++){
00293
00294 for(ifc=0; ifc<EMAP_NFCH; ifc++){
00295 icrate=hbhecrate[ic];
00296 iside=is<EMAP_NHSETS/2?-1:1;
00297 ifwtb=(is/2+itb+1)%2;
00298 ieta=ihbheetadepth[ih][ifwtb][ifb][ifc][0];
00299 idepth=ihbheetadepth[ih][ifwtb][ifb][ifc][1];
00300 ihtr=ihslot[is]+ih;
00301 det=((ieta>16||idepth>2)?("HE"):("HB"));
00302 fpga=((itb%2)==1)?("bot"):("top");
00303 ihtr_fi=ifb+1;
00304 ifi_ch=ifc;
00305 iphi=(ieta>20)?(ihbhephis[ic]+(is%2)*4+itb*2-1)%72+1:(ihbhephis[ic]+(is%2)*4+itb*2+(ifb/2+is/2+1)%2-1)%72+1;
00306 ispigot=(is%2)*6+ih*2+itb;
00307 idcc=is<EMAP_NHSETS/2?1:2;
00308
00309 ifed=fedhbhenum[ic][idcc-1];
00311 CastorElectronicsId elId(ifi_ch, ihtr_fi, ispigot, ifed-700);
00312 elId.setHTR(icrate, ihtr, (fpga=="top")?(1):(0));
00313 HcalDetId hId((det=="HB")?(HcalBarrel):(HcalEndcap),ieta*iside,iphi,idepth);
00314 emap.mapEId2chId(elId,hId);
00315
00316
00317 }}}}}}
00318
00319 for(ic=0; ic<EMAP_NHFCR; ic++){
00320
00321 for(is=0; is<EMAP_NHSETS; is++){
00322
00323 for(ih=0; ih<EMAP_NHTRS; ih++){
00324
00325 for(itb=0; itb<EMAP_NTOPBOT; itb++){
00326
00327 for(ifb=0; ifb<EMAP_NFBR; ifb++){
00328
00329 for(ifc=0; ifc<EMAP_NFCH; ifc++){
00330 icrate=hfcrate[ic];
00331 iside=is<EMAP_NHSETS/2?-1:1;
00332 ieta=ihfetadepth[itb][ifb][ifc][0];
00333 idepth=ihfetadepth[itb][ifb][ifc][1];
00334 ihtr=ihslot[is]+ih;
00335 det="HF";
00336 fpga=((itb%2)==1)?("bot"):("top");
00337 ihtr_fi=ifb+1;
00338 ifi_ch=ifc;
00339 iphi=(ieta>39)?(ihfphis[ic]+(is%2)*12+ih*4-3)%72+1:(ihfphis[ic]+(is%2)*12+ih*4+(ifb/4)*2-1)%72+1;
00340 ispigot=(is%2)*6+ih*2+itb;
00341 idcc=is<EMAP_NHSETS/2?1:2;
00342
00343 ifed=fedhfnum[ic][idcc-1];
00344 CastorElectronicsId elId(ifi_ch, ihtr_fi, ispigot, ifed-700);
00345 elId.setHTR(icrate, ihtr, (fpga=="top")?(1):(0));
00346 HcalDetId hId(HcalForward,ieta*iside,iphi,idepth);
00347 emap.mapEId2chId(elId,hId);
00348
00349 }}}}}}
00350
00351 for(ic=0; ic<EMAP_NHOCR; ic++){
00352
00353 for(is=0; is<EMAP_NHSETSHO; is++){
00354
00355 for(ih=0; ih<EMAP_NHTRSHO; ih++){
00356
00357 for(itb=0; itb<EMAP_NTOPBOT; itb++){
00358
00359 for(ifb=0; ifb<EMAP_NFBR; ifb++){
00360
00361 for(ifc=0; ifc<EMAP_NFCH; ifc++){
00362 icrate=hocrate[ic];
00363 idepth=1;
00364 ieta=ihoetasidephi[ih][itb][ifb][ifc][0];
00365 iside=ihoetasidephi[ih][itb][ifb][ifc][1];
00366 iphi_loc=ihoetasidephi[ih][itb][ifb][ifc][2];
00367 ihtr=ihslotho[is][ih];
00368 det="HO";
00369 fpga=((itb%2)==1)?("bot"):("top");
00370 ihtr_fi=ifb+1;
00371 ifi_ch=ifc;
00372 iphi=(ihophis[ic]+is*6+iphi_loc-1)%72+1;
00373 ispigot=ihtr<9?(ihtr-2)*2+itb:(ihtr-13)*2+itb;
00374 idcc=ihtr<9?1:2;
00375
00376 ifed=fedhonum[ic][idcc-1];
00377 CastorElectronicsId elId(ifi_ch, ihtr_fi, ispigot, ifed-700);
00378 elId.setHTR(icrate, ihtr, (fpga=="top")?(1):(0));
00379 if (ieta==0) {
00380 emap.mapEId2chId(elId,DetId(HcalDetId::Undefined));
00381 } else {
00382 HcalDetId hId(HcalOuter,ieta*iside,iphi,idepth+3);
00383 emap.mapEId2chId(elId,hId);
00384 }
00385
00386 }}}}}}
00387
00388
00389 emap.sort();
00390
00391 }