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
00100 #define EMAP_NHBHECR 9
00101 #define EMAP_NHFCR 3
00102 #define EMAP_NHOCR 4
00103 #define EMAP_NFBR 8
00104 #define EMAP_NFCH 3
00105 #define EMAP_NHTRS 3
00106 #define EMAP_NHSETS 4
00107 #define EMAP_NTOPBOT 2
00108 #define EMAP_NHTRSHO 4
00109 #define EMAP_NHSETSHO 3
00110
00111 void CastorDbHardcode::makeHardcodeMap(CastorElectronicsMap& emap) {
00112
00113
00114 int hbhecrate[EMAP_NHBHECR]={0,1,4,5,10,11,14,15,17};
00115
00116 int hfcrate[EMAP_NHFCR]={2,9,12};
00117
00118 int hocrate[EMAP_NHOCR]={3,7,6,13};
00119
00120 int fedhbhenum[EMAP_NHBHECR][2]={{702,703},{704,705},{700,701},
00121 {706,707},{716,717},{708,709},
00122 {714,715},{710,711},{712,713}};
00123
00124 int fedhfnum[EMAP_NHFCR][2]={{718,719},{720,721},{722,723}};
00125
00126 int fedhonum[EMAP_NHOCR][2]={{724,725},{726,727},{728,729},{730,731}};
00127
00128 int ihslot[EMAP_NHSETS]={2,5,13,16};
00129
00130 int ihslotho[EMAP_NHSETSHO][EMAP_NHTRSHO]={{2,3,4,5},{6,7,13,14},{15,16,17,18}};
00131
00132 int ihbhephis[EMAP_NHBHECR]={11,19,3,27,67,35,59,43,51};
00133
00134 int ihfphis[EMAP_NHFCR]={3,27,51};
00135
00136 int ihophis[EMAP_NHOCR]={71,17,35,53};
00137
00138 int ihbheetadepth[EMAP_NHTRS][EMAP_NTOPBOT][EMAP_NFBR][EMAP_NFCH][2]={
00139 {{{{11,1},{ 7,1},{ 3,1}},
00140 {{ 5,1},{ 1,1},{ 9,1}},
00141 {{11,1},{ 7,1},{ 3,1}},
00142 {{ 5,1},{ 1,1},{ 9,1}},
00143 {{10,1},{ 6,1},{ 2,1}},
00144 {{ 8,1},{ 4,1},{12,1}},
00145 {{10,1},{ 6,1},{ 2,1}},
00146 {{ 8,1},{ 4,1},{12,1}}},
00147 {{{11,1},{ 7,1},{ 3,1}},
00148 {{ 5,1},{ 1,1},{ 9,1}},
00149 {{11,1},{ 7,1},{ 3,1}},
00150 {{ 5,1},{ 1,1},{ 9,1}},
00151 {{10,1},{ 6,1},{ 2,1}},
00152 {{ 8,1},{ 4,1},{12,1}},
00153 {{10,1},{ 6,1},{ 2,1}},
00154 {{ 8,1},{ 4,1},{12,1}}}},
00155 {{{{16,2},{15,2},{14,1}},
00156 {{15,1},{13,1},{16,1}},
00157 {{16,2},{15,2},{14,1}},
00158 {{15,1},{13,1},{16,1}},
00159 {{17,1},{16,3},{26,1}},
00160 {{18,1},{18,2},{26,2}},
00161 {{17,1},{16,3},{25,1}},
00162 {{18,1},{18,2},{25,2}}},
00163 {{{16,2},{15,2},{14,1}},
00164 {{15,1},{13,1},{16,1}},
00165 {{16,2},{15,2},{14,1}},
00166 {{15,1},{13,1},{16,1}},
00167 {{17,1},{16,3},{25,1}},
00168 {{18,1},{18,2},{25,2}},
00169 {{17,1},{16,3},{26,1}},
00170 {{18,1},{18,2},{26,2}}}},
00171 {{{{28,1},{28,2},{29,1}},
00172 {{28,3},{24,2},{24,1}},
00173 {{27,1},{27,2},{29,2}},
00174 {{27,3},{23,2},{23,1}},
00175 {{19,2},{20,1},{22,2}},
00176 {{19,1},{20,2},{22,1}},
00177 {{19,2},{20,1},{21,2}},
00178 {{19,1},{20,2},{21,1}}},
00179 {{{27,1},{27,2},{29,2}},
00180 {{27,3},{23,2},{23,1}},
00181 {{28,1},{28,2},{29,1}},
00182 {{28,3},{24,2},{24,1}},
00183 {{19,2},{20,1},{21,2}},
00184 {{19,1},{20,2},{21,1}},
00185 {{19,2},{20,1},{22,2}},
00186 {{19,1},{20,2},{22,1}}}}
00187 };
00188
00189 int ihfetadepth[EMAP_NTOPBOT][EMAP_NFBR][EMAP_NFCH][2]={
00190 {{{33,1},{31,1},{29,1}},
00191 {{32,1},{30,1},{34,1}},
00192 {{33,2},{31,2},{29,2}},
00193 {{32,2},{30,2},{34,2}},
00194 {{34,2},{32,2},{30,2}},
00195 {{31,2},{29,2},{33,2}},
00196 {{34,1},{32,1},{30,1}},
00197 {{31,1},{29,1},{33,1}}},
00198 {{{41,1},{37,1},{35,1}},
00199 {{38,1},{36,1},{39,1}},
00200 {{41,2},{37,2},{35,2}},
00201 {{38,2},{36,2},{39,2}},
00202 {{40,2},{38,2},{36,2}},
00203 {{37,2},{35,2},{39,2}},
00204 {{40,1},{38,1},{36,1}},
00205 {{37,1},{35,1},{39,1}}}
00206 };
00207
00208 int ihoetasidephi[EMAP_NHTRSHO][EMAP_NTOPBOT][EMAP_NFBR][EMAP_NFCH][3]={
00209 {{{{ 1,-1,0},{ 2,-1,0},{ 3,-1,0}},
00210 {{ 1,-1,1},{ 2,-1,1},{ 3,-1,1}},
00211 {{ 1,-1,2},{ 2,-1,2},{ 3,-1,2}},
00212 {{ 1,-1,3},{ 2,-1,3},{ 3,-1,3}},
00213 {{ 1,-1,4},{ 2,-1,4},{ 3,-1,4}},
00214 {{ 1,-1,5},{ 2,-1,5},{ 3,-1,5}},
00215 {{14, 1,0},{14, 1,1},{14, 1,2}},
00216 {{14, 1,3},{14, 1,4},{14, 1,5}}},
00217 {{{ 1, 1,0},{ 2, 1,0},{ 3, 1,0}},
00218 {{ 1, 1,1},{ 2, 1,1},{ 3, 1,1}},
00219 {{ 1, 1,2},{ 2, 1,2},{ 3, 1,2}},
00220 {{ 1, 1,3},{ 2, 1,3},{ 3, 1,3}},
00221 {{ 1, 1,4},{ 2, 1,4},{ 3, 1,4}},
00222 {{ 1, 1,5},{ 2, 1,5},{ 3, 1,5}},
00223 {{15, 1,0},{15, 1,1},{15, 1,2}},
00224 {{15, 1,3},{15, 1,4},{15, 1,5}}}},
00225 {{{{ 6, 1,0},{ 6, 1,1},{ 6, 1,2}},
00226 {{ 6, 1,3},{ 6, 1,4},{ 6, 1,5}},
00227 {{ 7, 1,0},{ 7, 1,1},{ 7, 1,2}},
00228 {{ 7, 1,3},{ 7, 1,4},{ 7, 1,5}},
00229 {{ 8, 1,0},{ 8, 1,1},{ 8, 1,2}},
00230 {{ 8, 1,3},{ 8, 1,4},{ 8, 1,5}},
00231 {{ 9, 1,0},{ 9, 1,1},{ 9, 1,2}},
00232 {{ 9, 1,3},{ 9, 1,4},{ 9, 1,5}}},
00233 {{{10, 1,0},{10, 1,1},{10, 1,2}},
00234 {{10, 1,3},{10, 1,4},{10, 1,5}},
00235 {{11, 1,0},{11, 1,1},{11, 1,2}},
00236 {{11, 1,3},{11, 1,4},{11, 1,5}},
00237 {{12, 1,0},{12, 1,1},{12, 1,2}},
00238 {{12, 1,3},{12, 1,4},{12, 1,5}},
00239 {{13, 1,0},{13, 1,1},{13, 1,2}},
00240 {{13, 1,3},{13, 1,4},{13, 1,5}}}},
00241 {{{{ 4,-1,0},{ 4,-1,1},{ 0, 0,0}},
00242 {{ 4,-1,2},{ 4,-1,3},{ 0, 0,0}},
00243 {{ 4,-1,4},{ 4,-1,5},{ 0, 0,0}},
00244 {{ 0, 0,0},{ 0, 0,0},{ 0, 0,0}},
00245 {{ 5,-1,0},{ 5,-1,1},{ 5,-1,2}},
00246 {{ 5,-1,3},{ 5,-1,4},{ 5,-1,5}},
00247 {{14,-1,0},{14,-1,1},{14,-1,2}},
00248 {{14,-1,3},{14,-1,4},{14,-1,5}}},
00249 {{{ 4, 1,0},{ 4, 1,1},{ 0, 0,0}},
00250 {{ 4, 1,2},{ 4, 1,3},{ 0, 0,0}},
00251 {{ 4, 1,4},{ 4, 1,5},{ 0, 0,0}},
00252 {{ 0, 0,0},{ 0, 0,0},{ 0, 0,0}},
00253 {{ 5, 1,0},{ 5, 1,1},{ 5, 1,2}},
00254 {{ 5, 1,3},{ 5, 1,4},{ 5, 1,5}},
00255 {{15,-1,0},{15,-1,1},{15,-1,2}},
00256 {{15,-1,3},{15,-1,4},{15,-1,5}}}},
00257 {{{{ 6,-1,0},{ 6,-1,1},{ 6,-1,2}},
00258 {{ 6,-1,3},{ 6,-1,4},{ 6,-1,5}},
00259 {{ 7,-1,0},{ 7,-1,1},{ 7,-1,2}},
00260 {{ 7,-1,3},{ 7,-1,4},{ 7,-1,5}},
00261 {{ 8,-1,0},{ 8,-1,1},{ 8,-1,2}},
00262 {{ 8,-1,3},{ 8,-1,4},{ 8,-1,5}},
00263 {{ 9,-1,0},{ 9,-1,1},{ 9,-1,2}},
00264 {{ 9,-1,3},{ 9,-1,4},{ 9,-1,5}}},
00265 {{{10,-1,0},{10,-1,1},{10,-1,2}},
00266 {{10,-1,3},{10,-1,4},{10,-1,5}},
00267 {{11,-1,0},{11,-1,1},{11,-1,2}},
00268 {{11,-1,3},{11,-1,4},{11,-1,5}},
00269 {{12,-1,0},{12,-1,1},{12,-1,2}},
00270 {{12,-1,3},{12,-1,4},{12,-1,5}},
00271 {{13,-1,0},{13,-1,1},{13,-1,2}},
00272 {{13,-1,3},{13,-1,4},{13,-1,5}}}}
00273 };
00274 int ic,is,ih,itb,ifb,ifc,ifwtb,iphi_loc;
00275 int iside,ieta,iphi,idepth,icrate,ihtr,ihtr_fi,ifi_ch,ispigot,idcc,ifed;
00276 std::string det;
00277 std::string fpga;
00278
00279
00280 for(ic=0; ic<EMAP_NHBHECR; ic++){
00281
00282 for(is=0; is<EMAP_NHSETS; is++){
00283
00284 for(ih=0; ih<EMAP_NHTRS; ih++){
00285
00286 for(itb=0; itb<EMAP_NTOPBOT; itb++){
00287
00288 for(ifb=0; ifb<EMAP_NFBR; ifb++){
00289
00290 for(ifc=0; ifc<EMAP_NFCH; ifc++){
00291 icrate=hbhecrate[ic];
00292 iside=is<EMAP_NHSETS/2?-1:1;
00293 ifwtb=(is/2+itb+1)%2;
00294 ieta=ihbheetadepth[ih][ifwtb][ifb][ifc][0];
00295 idepth=ihbheetadepth[ih][ifwtb][ifb][ifc][1];
00296 ihtr=ihslot[is]+ih;
00297 det=((ieta>16||idepth>2)?("HE"):("HB"));
00298 fpga=((itb%2)==1)?("bot"):("top");
00299 ihtr_fi=ifb+1;
00300 ifi_ch=ifc;
00301 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;
00302 ispigot=(is%2)*6+ih*2+itb;
00303 idcc=is<EMAP_NHSETS/2?1:2;
00304
00305 ifed=fedhbhenum[ic][idcc-1];
00307 CastorElectronicsId elId(ifi_ch, ihtr_fi, ispigot, ifed-700);
00308 elId.setHTR(icrate, ihtr, (fpga=="top")?(1):(0));
00309 HcalDetId hId((det=="HB")?(HcalBarrel):(HcalEndcap),ieta*iside,iphi,idepth);
00310 emap.mapEId2chId(elId,hId);
00311
00312
00313 }}}}}}
00314
00315 for(ic=0; ic<EMAP_NHFCR; ic++){
00316
00317 for(is=0; is<EMAP_NHSETS; is++){
00318
00319 for(ih=0; ih<EMAP_NHTRS; ih++){
00320
00321 for(itb=0; itb<EMAP_NTOPBOT; itb++){
00322
00323 for(ifb=0; ifb<EMAP_NFBR; ifb++){
00324
00325 for(ifc=0; ifc<EMAP_NFCH; ifc++){
00326 icrate=hfcrate[ic];
00327 iside=is<EMAP_NHSETS/2?-1:1;
00328 ieta=ihfetadepth[itb][ifb][ifc][0];
00329 idepth=ihfetadepth[itb][ifb][ifc][1];
00330 ihtr=ihslot[is]+ih;
00331 det="HF";
00332 fpga=((itb%2)==1)?("bot"):("top");
00333 ihtr_fi=ifb+1;
00334 ifi_ch=ifc;
00335 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;
00336 ispigot=(is%2)*6+ih*2+itb;
00337 idcc=is<EMAP_NHSETS/2?1:2;
00338
00339 ifed=fedhfnum[ic][idcc-1];
00340 CastorElectronicsId elId(ifi_ch, ihtr_fi, ispigot, ifed-700);
00341 elId.setHTR(icrate, ihtr, (fpga=="top")?(1):(0));
00342 HcalDetId hId(HcalForward,ieta*iside,iphi,idepth);
00343 emap.mapEId2chId(elId,hId);
00344
00345 }}}}}}
00346
00347 for(ic=0; ic<EMAP_NHOCR; ic++){
00348
00349 for(is=0; is<EMAP_NHSETSHO; is++){
00350
00351 for(ih=0; ih<EMAP_NHTRSHO; ih++){
00352
00353 for(itb=0; itb<EMAP_NTOPBOT; itb++){
00354
00355 for(ifb=0; ifb<EMAP_NFBR; ifb++){
00356
00357 for(ifc=0; ifc<EMAP_NFCH; ifc++){
00358 icrate=hocrate[ic];
00359 idepth=1;
00360 ieta=ihoetasidephi[ih][itb][ifb][ifc][0];
00361 iside=ihoetasidephi[ih][itb][ifb][ifc][1];
00362 iphi_loc=ihoetasidephi[ih][itb][ifb][ifc][2];
00363 ihtr=ihslotho[is][ih];
00364 det="HO";
00365 fpga=((itb%2)==1)?("bot"):("top");
00366 ihtr_fi=ifb+1;
00367 ifi_ch=ifc;
00368 iphi=(ihophis[ic]+is*6+iphi_loc-1)%72+1;
00369 ispigot=ihtr<9?(ihtr-2)*2+itb:(ihtr-13)*2+itb;
00370 idcc=ihtr<9?1:2;
00371
00372 ifed=fedhonum[ic][idcc-1];
00373 CastorElectronicsId elId(ifi_ch, ihtr_fi, ispigot, ifed-700);
00374 elId.setHTR(icrate, ihtr, (fpga=="top")?(1):(0));
00375 if (ieta==0) {
00376 emap.mapEId2chId(elId,DetId(HcalDetId::Undefined));
00377 } else {
00378 HcalDetId hId(HcalOuter,ieta*iside,iphi,idepth+3);
00379 emap.mapEId2chId(elId,hId);
00380 }
00381
00382 }}}}}}
00383
00384
00385 emap.sort();
00386
00387 }