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