CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/RecoTBCalo/HcalTBObjectUnpacker/src/HcalTBQADCUnpacker.cc

Go to the documentation of this file.
00001 #include "RecoTBCalo/HcalTBObjectUnpacker/interface/HcalTBQADCUnpacker.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 
00004 // QADC channels
00005 static const int N_QADCS_ALLOWED = 6;
00006 
00007 // Channel to logical unit
00008 // TB04
00009 static const int aScint1          = 52;  // 14x14 cm
00010 static const int aScint2          = 53;  // 4x4 cm
00011 static const int aScint3          = 54;  // 2x2 cm
00012 static const int aScint4          = 66;  // 14x14 cm
00013 static const int aMuonV            = 56;  // Behind the table
00014 static const int aMuonV3           = 64;  // on HB1
00015 static const int aMuonV6           = 62;  // on HB2
00016 static const int aMuonVH1          = 67;  // Oct. muon veto wall
00017 static const int aMuonVH2          = 68;  // Oct. muon veto wall
00018 static const int aMuonVH3          = 69;  // Oct. muon veto wall
00019 static const int aMuonVH4          = 70;  // Oct. muon veto wall
00020 static const int aCerenkov2        = 49;  // el id
00021 static const int aCerenkov3        = 59;  // pi/proton separation
00022 static const int aSCI_VLE          = 65;  // VLE line 
00023 static const int aSCI_521          = 57;
00024 static const int aSCI_528          = 58;
00025 // TB06
00026 static const int bMuonV1           = 0;  // Muon veto wall
00027 static const int bMuonV2           = 1;  // Muon veto wall
00028 static const int bMuonV3           = 2;  // Muon veto wall
00029 static const int bMuonV4           = 3;  // Muon veto wall
00030 static const int bMuonV5           = 4;  // Muon veto wall
00031 static const int bMuonV6           = 5;  // Muon veto wall
00032 static const int bMuonV7           = 6;  // Muon veto wall
00033 static const int bMuonV8           = 7;  // Muon veto wall
00034 static const int bMuonVF           = 10;  // Behind the table
00035 static const int bMuonVB           = 11;  // Behind a beam dump
00036 static const int bScint1           = 12;  // 14x14 cm
00037 static const int bScint2           = 13;  // 4x4 cm
00038 static const int bScint3           = 14;  // 2x2 cm
00039 static const int bScint4           = 15;  // 14x14 cm
00040 static const int bCerenkov1        = 16;  // in HE line
00041 static const int bCerenkov2        = 17;  // el id in VLE
00042 static const int bCerenkov3        = 18;  // pi/proton id
00043 static const int bTOF1S            = 20;  // TOF1S (S=Saleve side, TOF1 upstream)
00044 static const int bTOF1J            = 21;  // TOF1J (J=Jura side)
00045 static const int bTOF2S            = 22;  // TOF2S (TOF2 downstream)
00046 static const int bTOF2J            = 23;  // TOF2J
00047 static const int bSCI_521          = 24;  // In HE beam line for now
00048 static const int bSCI_528          = 25;  // NC
00049 static const int bVH2              = 27;  // beam halo left from particle view
00050 static const int bVH4              = 28;  // beam halo down
00051 static const int bVH3              = 29;  // beam halo up
00052 static const int bVH1              = 30;  // beam halo right from particle view
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; // Count of QDC channels
00067     unsigned int n_tdc_hits; // upper/lower TDC counts    
00068     unsigned short qdc_values[4];
00069   };
00070 
00071 // Sets the pedestal and gain
00072 void HcalTBQADCUnpacker::setCalib(const std::vector<std::vector<std::string> >& calibLines_) {
00073 // The default pedestal and gain
00074         for(int i=0;i<N_QADCS_ALLOWED*32;i++)
00075          {
00076           qdc_ped[i]=0.;qdc_gain[i]=1.;
00077          }
00078 // Pedestal and gains from configuration file.
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         //        printf("Got QDC %i ped %f , gain %f\n",channel, qdc_ped[channel],qdc_gain[channel]);
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          } // End of calibLines.
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     // Applying mask, pedestal subtraction and gain.
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     // Ecal energy sum should go here.
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 }