00001 #include "RecoTBCalo/HcalTBObjectUnpacker/interface/HcalTBQADCUnpacker.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003
00004
00005 static const int N_QADCS_ALLOWED = 6;
00006
00007
00008
00009 static const int aScint1 = 52;
00010 static const int aScint2 = 53;
00011 static const int aScint3 = 54;
00012 static const int aScint4 = 66;
00013 static const int aMuonV = 56;
00014 static const int aMuonV3 = 64;
00015 static const int aMuonV6 = 62;
00016 static const int aMuonVH1 = 67;
00017 static const int aMuonVH2 = 68;
00018 static const int aMuonVH3 = 69;
00019 static const int aMuonVH4 = 70;
00020 static const int aCerenkov2 = 49;
00021 static const int aCerenkov3 = 59;
00022 static const int aSCI_VLE = 65;
00023 static const int aSCI_521 = 57;
00024 static const int aSCI_528 = 58;
00025
00026 static const int bMuonV1 = 0;
00027 static const int bMuonV2 = 1;
00028 static const int bMuonV3 = 2;
00029 static const int bMuonV4 = 3;
00030 static const int bMuonV5 = 4;
00031 static const int bMuonV6 = 5;
00032 static const int bMuonV7 = 6;
00033 static const int bMuonV8 = 7;
00034 static const int bMuonVF = 10;
00035 static const int bMuonVB = 11;
00036 static const int bScint1 = 12;
00037 static const int bScint2 = 13;
00038 static const int bScint3 = 14;
00039 static const int bScint4 = 15;
00040 static const int bCerenkov1 = 16;
00041 static const int bCerenkov2 = 17;
00042 static const int bCerenkov3 = 18;
00043 static const int bTOF1S = 20;
00044 static const int bTOF1J = 21;
00045 static const int bTOF2S = 22;
00046 static const int bTOF2J = 23;
00047 static const int bSCI_521 = 24;
00048 static const int bSCI_528 = 25;
00049 static const int bVH2 = 27;
00050 static const int bVH4 = 28;
00051 static const int bVH3 = 29;
00052 static const int bVH1 = 30;
00053
00054 namespace hcaltb {
00055
00056 HcalTBQADCUnpacker::HcalTBQADCUnpacker(){}
00057
00058 struct ClassicQADCDataFormat {
00059 unsigned int cdfHeader0,cdfHeader1,cdfHeader2,cdfHeader3;
00060 unsigned short data[N_QADCS_ALLOWED*32];
00061 unsigned int cdfTrailer0,cdfTrailer1;
00062 };
00063
00064 struct CombinedTDCQDCDataFormat {
00065 unsigned int cdfHeader0,cdfHeader1,cdfHeader2,cdfHeader3;
00066 unsigned int n_qdc_hits;
00067 unsigned int n_tdc_hits;
00068 unsigned short qdc_values[4];
00069 };
00070
00071
00072 void HcalTBQADCUnpacker::setCalib(const std::vector<std::vector<std::string> >& calibLines_) {
00073
00074 for(int i=0;i<N_QADCS_ALLOWED*32;i++)
00075 {
00076 qdc_ped[i]=0.;qdc_gain[i]=1.;
00077 }
00078
00079 for(unsigned int ii=0;ii<calibLines_.size();ii++)
00080 {
00081 if(calibLines_[ii][0]=="QDC")
00082 {
00083 if(calibLines_[ii].size()==4)
00084 {
00085 int channel=atoi(calibLines_[ii][1].c_str());
00086 qdc_ped[channel]=atof(calibLines_[ii][2].c_str());
00087 qdc_gain[channel]=atof(calibLines_[ii][3].c_str());
00088
00089 }
00090 else
00091 {
00092 throw cms::Exception("Incomplete configuration") <<
00093 "Wrong QADC configuration format: expected 3 parameters, got "<<calibLines_[ii].size()-1;
00094 }
00095 }
00096 }
00097 }
00098
00099 void HcalTBQADCUnpacker::unpack(const FEDRawData& raw,
00100 HcalTBBeamCounters& beamadc, bool is04) const {
00101
00102 if (raw.size()<3*8) {
00103 throw cms::Exception("Missing Data") << "No data in the QDC block";
00104 }
00105
00106
00107 if(is04){
00108 const ClassicQADCDataFormat* qadc=(const ClassicQADCDataFormat*)raw.data();
00109 double qdc_calib_hits[N_QADCS_ALLOWED*32];
00110
00111 for (unsigned int i=0;i<N_QADCS_ALLOWED*32;i++)
00112 qdc_calib_hits[i]=((qadc->data[i]&0xFFF)-qdc_ped[i])/qdc_gain[i];
00113
00114
00115 double Ecal7x7=0.;
00116 for(int i=0;i<49;i++)Ecal7x7+=qdc_calib_hits[i];
00117
00118
00119 beamadc.setADCs04(qdc_calib_hits[aMuonV],qdc_calib_hits[aMuonV3],qdc_calib_hits[aMuonV6],
00120 qdc_calib_hits[aMuonVH1],qdc_calib_hits[aMuonVH2],qdc_calib_hits[aMuonVH3],
00121 qdc_calib_hits[aMuonVH4],qdc_calib_hits[aCerenkov2],qdc_calib_hits[aCerenkov3],
00122 qdc_calib_hits[aSCI_VLE],qdc_calib_hits[aSCI_521],qdc_calib_hits[aSCI_528],
00123 qdc_calib_hits[aScint1],qdc_calib_hits[aScint2],qdc_calib_hits[aScint3],
00124 qdc_calib_hits[aScint4],Ecal7x7);
00125 }
00126 else{
00127 const CombinedTDCQDCDataFormat* qdctdc=(const CombinedTDCQDCDataFormat*)raw.data();
00128 double qdc_calib_hits[32];
00129 for (unsigned int i=0;i<qdctdc->n_qdc_hits;i++)
00130 qdc_calib_hits[i]=((qdctdc->qdc_values[i]&0xFFF)-qdc_ped[i])/qdc_gain[i];
00131
00132 beamadc.setADCs06( qdc_calib_hits[bMuonVF], qdc_calib_hits[bMuonVB],
00133 qdc_calib_hits[bMuonV1],qdc_calib_hits[bMuonV2],qdc_calib_hits[bMuonV3],
00134 qdc_calib_hits[bMuonV4],qdc_calib_hits[bMuonV5],qdc_calib_hits[bMuonV6],
00135 qdc_calib_hits[bMuonV7], qdc_calib_hits[bMuonV8],
00136 qdc_calib_hits[bCerenkov1], qdc_calib_hits[bCerenkov2], qdc_calib_hits[bCerenkov3],
00137 qdc_calib_hits[bScint1], qdc_calib_hits[bScint2],
00138 qdc_calib_hits[bScint3], qdc_calib_hits[bScint4],
00139 qdc_calib_hits[bTOF1S], qdc_calib_hits[bTOF1J],
00140 qdc_calib_hits[bTOF2S], qdc_calib_hits[bTOF2J],
00141 qdc_calib_hits[bSCI_521],qdc_calib_hits[bSCI_528],
00142 qdc_calib_hits[bVH1],qdc_calib_hits[bVH2],
00143 qdc_calib_hits[bVH3],qdc_calib_hits[bVH4]);
00144
00145 }
00146 }
00147
00148 }