Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:27:17

0001 #include "RecoTBCalo/HcalTBObjectUnpacker/interface/HcalTBQADCUnpacker.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 
0004 // QADC channels
0005 static const int N_QADCS_ALLOWED = 6;
0006 
0007 // Channel to logical unit
0008 // TB04
0009 static const int aScint1 = 52;     // 14x14 cm
0010 static const int aScint2 = 53;     // 4x4 cm
0011 static const int aScint3 = 54;     // 2x2 cm
0012 static const int aScint4 = 66;     // 14x14 cm
0013 static const int aMuonV = 56;      // Behind the table
0014 static const int aMuonV3 = 64;     // on HB1
0015 static const int aMuonV6 = 62;     // on HB2
0016 static const int aMuonVH1 = 67;    // Oct. muon veto wall
0017 static const int aMuonVH2 = 68;    // Oct. muon veto wall
0018 static const int aMuonVH3 = 69;    // Oct. muon veto wall
0019 static const int aMuonVH4 = 70;    // Oct. muon veto wall
0020 static const int aCerenkov2 = 49;  // el id
0021 static const int aCerenkov3 = 59;  // pi/proton separation
0022 static const int aSCI_VLE = 65;    // VLE line
0023 static const int aSCI_521 = 57;
0024 static const int aSCI_528 = 58;
0025 // TB06
0026 static const int bMuonV1 = 0;      // Muon veto wall
0027 static const int bMuonV2 = 1;      // Muon veto wall
0028 static const int bMuonV3 = 2;      // Muon veto wall
0029 static const int bMuonV4 = 3;      // Muon veto wall
0030 static const int bMuonV5 = 4;      // Muon veto wall
0031 static const int bMuonV6 = 5;      // Muon veto wall
0032 static const int bMuonV7 = 6;      // Muon veto wall
0033 static const int bMuonV8 = 7;      // Muon veto wall
0034 static const int bMuonVF = 10;     // Behind the table
0035 static const int bMuonVB = 11;     // Behind a beam dump
0036 static const int bScint1 = 12;     // 14x14 cm
0037 static const int bScint2 = 13;     // 4x4 cm
0038 static const int bScint3 = 14;     // 2x2 cm
0039 static const int bScint4 = 15;     // 14x14 cm
0040 static const int bCerenkov1 = 16;  // in HE line
0041 static const int bCerenkov2 = 17;  // el id in VLE
0042 static const int bCerenkov3 = 18;  // pi/proton id
0043 static const int bTOF1S = 20;      // TOF1S (S=Saleve side, TOF1 upstream)
0044 static const int bTOF1J = 21;      // TOF1J (J=Jura side)
0045 static const int bTOF2S = 22;      // TOF2S (TOF2 downstream)
0046 static const int bTOF2J = 23;      // TOF2J
0047 static const int bSCI_521 = 24;    // In HE beam line for now
0048 static const int bSCI_528 = 25;    // NC
0049 static const int bVH2 = 27;        // beam halo left from particle view
0050 static const int bVH4 = 28;        // beam halo down
0051 static const int bVH3 = 29;        // beam halo up
0052 static const int bVH1 = 30;        // beam halo right from particle view
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;  // Count of QDC channels
0067     unsigned int n_tdc_hits;  // upper/lower TDC counts
0068     unsigned short qdc_values[4];
0069   };
0070 
0071   // Sets the pedestal and gain
0072   void HcalTBQADCUnpacker::setCalib(const std::vector<std::vector<std::string> >& calibLines_) {
0073     // The default pedestal and gain
0074     for (int i = 0; i < N_QADCS_ALLOWED * 32; i++) {
0075       qdc_ped[i] = 0.;
0076       qdc_gain[i] = 1.;
0077     }
0078     // Pedestal and gains from configuration file.
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           //      printf("Got QDC %i ped %f , gain %f\n",channel, qdc_ped[channel],qdc_gain[channel]);
0086         } else {
0087           throw cms::Exception("Incomplete configuration")
0088               << "Wrong QADC configuration format: expected 3 parameters, got " << calibLines_[ii].size() - 1;
0089         }
0090       }
0091     }  // End of calibLines.
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) {  ///this is TB04
0100       const ClassicQADCDataFormat* qadc = (const ClassicQADCDataFormat*)raw.data();
0101       double qdc_calib_hits[N_QADCS_ALLOWED * 32];
0102       // Applying mask, pedestal subtraction and gain.
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       // Ecal energy sum should go here.
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 {  /// this is TB06
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 }  // namespace hcaltb