File indexing completed on 2023-03-17 11:22:04
0001 #include "RecoTBCalo/HcalTBObjectUnpacker/interface/HcalTBQADCUnpacker.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003
0004
0005 static const int N_QADCS_ALLOWED = 6;
0006
0007
0008
0009 static const int aScint1 = 52;
0010 static const int aScint2 = 53;
0011 static const int aScint3 = 54;
0012 static const int aScint4 = 66;
0013 static const int aMuonV = 56;
0014 static const int aMuonV3 = 64;
0015 static const int aMuonV6 = 62;
0016 static const int aMuonVH1 = 67;
0017 static const int aMuonVH2 = 68;
0018 static const int aMuonVH3 = 69;
0019 static const int aMuonVH4 = 70;
0020 static const int aCerenkov2 = 49;
0021 static const int aCerenkov3 = 59;
0022 static const int aSCI_VLE = 65;
0023 static const int aSCI_521 = 57;
0024 static const int aSCI_528 = 58;
0025
0026 static const int bMuonV1 = 0;
0027 static const int bMuonV2 = 1;
0028 static const int bMuonV3 = 2;
0029 static const int bMuonV4 = 3;
0030 static const int bMuonV5 = 4;
0031 static const int bMuonV6 = 5;
0032 static const int bMuonV7 = 6;
0033 static const int bMuonV8 = 7;
0034 static const int bMuonVF = 10;
0035 static const int bMuonVB = 11;
0036 static const int bScint1 = 12;
0037 static const int bScint2 = 13;
0038 static const int bScint3 = 14;
0039 static const int bScint4 = 15;
0040 static const int bCerenkov1 = 16;
0041 static const int bCerenkov2 = 17;
0042 static const int bCerenkov3 = 18;
0043 static const int bTOF1S = 20;
0044 static const int bTOF1J = 21;
0045 static const int bTOF2S = 22;
0046 static const int bTOF2J = 23;
0047 static const int bSCI_521 = 24;
0048 static const int bSCI_528 = 25;
0049 static const int bVH2 = 27;
0050 static const int bVH4 = 28;
0051 static const int bVH3 = 29;
0052 static const int bVH1 = 30;
0053
0054 namespace hcaltb {
0055
0056 HcalTBQADCUnpacker::HcalTBQADCUnpacker() {}
0057
0058 struct ClassicQADCDataFormat {
0059 unsigned int cdfHeader0, cdfHeader1, cdfHeader2, cdfHeader3;
0060 unsigned short data[N_QADCS_ALLOWED * 32];
0061 unsigned int cdfTrailer0, cdfTrailer1;
0062 };
0063
0064 struct CombinedTDCQDCDataFormat {
0065 unsigned int cdfHeader0, cdfHeader1, cdfHeader2, cdfHeader3;
0066 unsigned int n_qdc_hits;
0067 unsigned int n_tdc_hits;
0068 unsigned short qdc_values[4];
0069 };
0070
0071
0072 void HcalTBQADCUnpacker::setCalib(const std::vector<std::vector<std::string> >& calibLines_) {
0073
0074 for (int i = 0; i < N_QADCS_ALLOWED * 32; i++) {
0075 qdc_ped[i] = 0.;
0076 qdc_gain[i] = 1.;
0077 }
0078
0079 for (unsigned int ii = 0; ii < calibLines_.size(); ii++) {
0080 if (calibLines_[ii][0] == "QDC") {
0081 if (calibLines_[ii].size() == 4) {
0082 int channel = atoi(calibLines_[ii][1].c_str());
0083 qdc_ped[channel] = atof(calibLines_[ii][2].c_str());
0084 qdc_gain[channel] = atof(calibLines_[ii][3].c_str());
0085
0086 } else {
0087 throw cms::Exception("Incomplete configuration")
0088 << "Wrong QADC configuration format: expected 3 parameters, got " << calibLines_[ii].size() - 1;
0089 }
0090 }
0091 }
0092 }
0093
0094 void HcalTBQADCUnpacker::unpack(const FEDRawData& raw, HcalTBBeamCounters& beamadc, bool is04) const {
0095 if (raw.size() < 3 * 8) {
0096 throw cms::Exception("Missing Data") << "No data in the QDC block";
0097 }
0098
0099 if (is04) {
0100 const ClassicQADCDataFormat* qadc = (const ClassicQADCDataFormat*)raw.data();
0101 double qdc_calib_hits[N_QADCS_ALLOWED * 32];
0102
0103 for (unsigned int i = 0; i < N_QADCS_ALLOWED * 32; i++)
0104 qdc_calib_hits[i] = ((qadc->data[i] & 0xFFF) - qdc_ped[i]) / qdc_gain[i];
0105
0106
0107 double Ecal7x7 = 0.;
0108 for (int i = 0; i < 49; i++)
0109 Ecal7x7 += qdc_calib_hits[i];
0110
0111 beamadc.setADCs04(qdc_calib_hits[aMuonV],
0112 qdc_calib_hits[aMuonV3],
0113 qdc_calib_hits[aMuonV6],
0114 qdc_calib_hits[aMuonVH1],
0115 qdc_calib_hits[aMuonVH2],
0116 qdc_calib_hits[aMuonVH3],
0117 qdc_calib_hits[aMuonVH4],
0118 qdc_calib_hits[aCerenkov2],
0119 qdc_calib_hits[aCerenkov3],
0120 qdc_calib_hits[aSCI_VLE],
0121 qdc_calib_hits[aSCI_521],
0122 qdc_calib_hits[aSCI_528],
0123 qdc_calib_hits[aScint1],
0124 qdc_calib_hits[aScint2],
0125 qdc_calib_hits[aScint3],
0126 qdc_calib_hits[aScint4],
0127 Ecal7x7);
0128 } else {
0129 const CombinedTDCQDCDataFormat* qdctdc = (const CombinedTDCQDCDataFormat*)raw.data();
0130 double qdc_calib_hits[32];
0131 for (unsigned int i = 0; i < qdctdc->n_qdc_hits; i++)
0132 qdc_calib_hits[i] = ((qdctdc->qdc_values[i] & 0xFFF) - qdc_ped[i]) / qdc_gain[i];
0133
0134 beamadc.setADCs06(qdc_calib_hits[bMuonVF],
0135 qdc_calib_hits[bMuonVB],
0136 qdc_calib_hits[bMuonV1],
0137 qdc_calib_hits[bMuonV2],
0138 qdc_calib_hits[bMuonV3],
0139 qdc_calib_hits[bMuonV4],
0140 qdc_calib_hits[bMuonV5],
0141 qdc_calib_hits[bMuonV6],
0142 qdc_calib_hits[bMuonV7],
0143 qdc_calib_hits[bMuonV8],
0144 qdc_calib_hits[bCerenkov1],
0145 qdc_calib_hits[bCerenkov2],
0146 qdc_calib_hits[bCerenkov3],
0147 qdc_calib_hits[bScint1],
0148 qdc_calib_hits[bScint2],
0149 qdc_calib_hits[bScint3],
0150 qdc_calib_hits[bScint4],
0151 qdc_calib_hits[bTOF1S],
0152 qdc_calib_hits[bTOF1J],
0153 qdc_calib_hits[bTOF2S],
0154 qdc_calib_hits[bTOF2J],
0155 qdc_calib_hits[bSCI_521],
0156 qdc_calib_hits[bSCI_528],
0157 qdc_calib_hits[bVH1],
0158 qdc_calib_hits[bVH2],
0159 qdc_calib_hits[bVH3],
0160 qdc_calib_hits[bVH4]);
0161 }
0162 }
0163
0164 }