CMS 3D CMS Logo

Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes

EcalSimRawData Class Reference

#include <EcalSimRawData.h>

Inheritance diagram for EcalSimRawData:
edm::EDAnalyzer

List of all members.

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 EcalSimRawData (const edm::ParameterSet &pset)
virtual ~EcalSimRawData ()

Private Types

enum  writeMode_t { littleEndian, bigEndian, ascii }

Private Member Functions

void checkGeometry (const edm::EventSetup &eventSetup)
void checkTriggerMap (const edm::EventSetup &eventSetup)
int cIndex2iTtEta (int iTtEta0) const
int cIndex2TtPhi (int iTtPhi0) const
void elec2GeomNum (int ittEta0, int ittPhi0, int strip1, int ch1, int &iEta0, int &iPhi0) const
void fwrite (std::ofstream &f, uint16_t data, int &iword, bool hpar=true) const
void genFeData (std::string basename, int iEvent, const std::vector< uint16_t > adcCount[nEbEta][nEbPhi]) const
void genSrData (std::string basename, int iEvent, int ttf[nEbTtEta][nTtPhi]) const
void genTccIn (std::string basename, int iEvent, const int tps[nTtEta][nTtPhi]) const
void genTccOut (std::string basename, int iEvent, const int tps[nTtEta][nTtPhi]) const
void getEbDigi (const edm::Event &event, std::vector< uint16_t > adc[nEbEta][nEbPhi]) const
std::string getExt () const
void getSrfs (const edm::Event &event, int ebSrf[nTtEta][nTtPhi], int eeSrf[nEndcaps][nScX][nScY]) const
void getTp (const edm::Event &event, const std::string &collName, int tp[nTtEta][nTtPhi]) const
int iEta2cIndex (int iEta) const
int iPhi2cIndex (int iPhi) const
int iTtEta2cIndex (int iTtEta) const
int iTtPhi2cIndex (int iTtPhi) const
void setHParity (uint16_t &a) const

Private Attributes

std::string basename_
int dccNum_
std::string digiProducer_
std::string ebDigiCollection_
std::string ebSrFlagCollection_
std::string eeDigiCollection_
std::string eeSrFlagCollection_
std::auto_ptr
< EcalSelectiveReadout
esr_
bool fe2dcc_
bool fe2tcc_
std::string srDigiProducer_
std::ofstream srfFile
bool srp2dcc_
bool tcc2dcc_
int tccInDefaultVal_
int tccNum_
std::string tcpDigiCollection_
const CaloGeometrytheGeometry
const
EcalTrigTowerConstituentsMap
theTriggerTowerMap
std::string tpDigiCollection_
std::string tpProducer_
bool tpVerbose_
std::ofstream ttfFile
writeMode_t writeMode_
bool xtalVerbose_

Static Private Attributes

static const int ebDccPhiEdge = 20
static const int ebTccPhiEdge = 20
static const int nDccEndcap = 9
static const int nDccInPhi = 18
static const int nEbEta = 170
static const int nEbPhi = 360
static const int nEbTtEta = nEbEta/ttEdge
static const int nEeTtEta = 11
static const int nEeX = 100
static const int nEeY = 100
static const int nEndcaps = 2
static const int nScX = 20
static const int nScY = 20
static const int nTccEndcap = 36
static const int nTccInPhi = 18
static const int nTtEta = nEbTtEta+2*nEeTtEta
static const int nTtPhi = nEbPhi/ttEdge
static const int nTtPhisPerEbDcc = 4
static const int nTtPhisPerEbTcc = 4
static const int nTtSmEta = 17
static const int nTtSmPhi = 4
static const int nTtTypes = 2
static const int scEdge = 5
static const int strip2Eta [nTtTypes][ttEdge]
static const int stripCh2Phi [nTtTypes][ttEdge][ttEdge]
static const int ttEdge = 5
static const int ttType [nEbTtEta]

Detailed Description

The EcalSimRawData CMSSW module produces raw data from digis. The raw data are written into files which can be loaded into the TCC DCC and SRP boards in order to emulate the front-end. Only barrel is fully supported. The produced files for TCC assumes a special LUT in the TCC forged for FE emulation mode.

Module Parameters:

Definition at line 42 of file EcalSimRawData.h.


Member Enumeration Documentation

Output format mode

littleEndian: little endian binary bigEndian: big endian binary ascii: ascii mode. The one accepted by the TCC, DCC and SRP board control software.

Enumerator:
littleEndian 
bigEndian 
ascii 

Definition at line 183 of file EcalSimRawData.h.


Constructor & Destructor Documentation

EcalSimRawData::EcalSimRawData ( const edm::ParameterSet pset) [explicit]

Constructor

Parameters:
psetCMSSW configuration

Definition at line 47 of file EcalSimRawData.cc.

References edm::ParameterSet::getParameter(), and edm::ParameterSet::getUntrackedParameter().

                                                           {
  //sets up parameters:
  digiProducer_ = params.getParameter<string>("unsuppressedDigiProducer");
  ebDigiCollection_ = params.getParameter<std::string>("EBdigiCollection");
  eeDigiCollection_ = params.getParameter<std::string>("EEdigiCollection");
  srDigiProducer_ = params.getParameter<string>("srProducer");
  ebSrFlagCollection_ = params.getParameter<std::string>("EBSrFlagCollection");
  eeSrFlagCollection_ = params.getParameter<std::string>("EESrFlagCollection");
  tpDigiCollection_
    = params.getParameter<std::string>("trigPrimDigiCollection");
  tcpDigiCollection_ = params.getParameter<std::string>("tcpDigiCollection");
  tpProducer_ = params.getParameter<string>("trigPrimProducer");
  xtalVerbose_ = params.getUntrackedParameter<bool>("xtalVerbose", false);
  tpVerbose_ = params.getUntrackedParameter<bool>("tpVerbose", false);
  tcc2dcc_ = params.getUntrackedParameter<bool>("tcc2dccData", true);
  srp2dcc_ = params.getUntrackedParameter<bool>("srp2dccData", true);
  fe2dcc_ = params.getUntrackedParameter<bool>("fe2dccData", true);
  fe2tcc_ = params.getUntrackedParameter<bool>("fe2tccData", true);
  dccNum_ = params.getUntrackedParameter<int>("dccNum", -1);
  tccNum_ = params.getUntrackedParameter<int>("tccNum", -1);
  tccInDefaultVal_ = params.getUntrackedParameter<int>("tccInDefaultVal", 0xffff);
  basename_ = params.getUntrackedParameter<std::string>("outputBaseName");


  string writeMode = params.getParameter<string>("writeMode");

  if(writeMode==string("littleEndian")){
    writeMode_ = littleEndian;
  } else if(writeMode==string("bigEndian")){
    writeMode_ = bigEndian;
  } else{
    writeMode_ = ascii;
  }
}
virtual EcalSimRawData::~EcalSimRawData ( ) [inline, virtual]

Destructor

Definition at line 51 of file EcalSimRawData.h.

{};

Member Function Documentation

void EcalSimRawData::analyze ( const edm::Event event,
const edm::EventSetup es 
) [virtual]

Main method. Called back for each event. This method produced the raw data and write them to disk.

Implements edm::EDAnalyzer.

Definition at line 83 of file EcalSimRawData.cc.

References ecalMGPA::adc(), gather_cfg::cout, iEvent, and nEndcaps.

                                                {
  //Event counter:
  static int iEvent = 0;
  ++iEvent; 
    
  if(xtalVerbose_ | tpVerbose_){
    cout << "======================================================================\n"
         << " Event " << iEvent << "\n"
         << "----------------------------------------------------------------------\n";
  }

  if(fe2dcc_){
    vector<uint16_t> adc[nEbEta][nEbPhi];
    getEbDigi(event, adc);
    genFeData(basename_, iEvent, adc);
  }

  if(fe2tcc_){
    int tcp[nTtEta][nTtPhi]={{0}};
    getTp(event, tcpDigiCollection_, tcp);
    genTccIn(basename_, iEvent, tcp);
  }
  
  if(tcc2dcc_){
    int tp[nTtEta][nTtPhi]={{0}};
    getTp(event, tpDigiCollection_, tp); 
    genTccOut(basename_, iEvent, tp);
  }
  
  //SR flags:
  int ebSrf[nTtEta][nTtPhi];
  int eeSrf[nEndcaps][nScX][nScY];

  if(srp2dcc_){
    getSrfs(event, ebSrf, eeSrf);
    genSrData(basename_, iEvent, ebSrf);
  }
  
}
void EcalSimRawData::checkGeometry ( const edm::EventSetup eventSetup) [private]

call these once an event, to make sure everything is up-to-date

void EcalSimRawData::checkTriggerMap ( const edm::EventSetup eventSetup) [private]
int EcalSimRawData::cIndex2iTtEta ( int  iTtEta0) const [inline, private]

Converse of iTtEta2cIndex

Parameters:
iTtEta0c eta index of TT
stdCMSSW TT eta index

Definition at line 238 of file EcalSimRawData.h.

                                      {
    return (iTtEta0<28)?(iTtEta0-28):(iTtEta0-27);
  }
int EcalSimRawData::cIndex2TtPhi ( int  iTtPhi0) const [inline, private]

Converse of iTtPhi2cIndex

Parameters:
iTtPhi0phi index of TT
Returns:
std CMSS TT index

Definition at line 246 of file EcalSimRawData.h.

                                     {
    return iTtPhi0+1;
  }
void EcalSimRawData::elec2GeomNum ( int  ittEta0,
int  ittPhi0,
int  strip1,
int  ch1,
int &  iEta0,
int &  iPhi0 
) const [private]

Converts electronic number of an ECAL barrel channel to geometrical indices

Parameters:
ittEta0trigger tower c index
ittPhi0trigger tower c index
strip1strip index within the TT. Runs from 1 to 5.
ch1channel electronics number within the VFE. Runs from 1 to 5.
[out]iEta0eta c index of the channel
[out]iPhi0eta c index of the channel

Definition at line 124 of file EcalSimRawData.cc.

                                                                        {
  assert(0<=ittEta0 && ittEta0<nEbTtEta);
  assert(0<=ittPhi0 && ittPhi0<nTtPhi);
  assert(1<=strip1&& strip1<=ttEdge);
  assert(1<=ch1 && ch1<=ttEdge);
  const int type = ttType[ittEta0];
  iEta0 = ittEta0*ttEdge + strip2Eta[type][strip1-1];
  iPhi0 = ittPhi0*ttEdge + stripCh2Phi[type][strip1-1][ch1-1];
  assert(0<=iEta0 && iEta0<nEbEta);
  assert(0<=iPhi0 && iPhi0<nEbPhi);
}
void EcalSimRawData::fwrite ( std::ofstream &  f,
uint16_t  data,
int &  iword,
bool  hpar = true 
) const [private]

Write a data 16-bit word into file according to selected format.

Parameters:
fthe file stream to write to
datathe peace of data to write
[in,out]iwordpass zero when writing for the first time in a file, then the value returned by the previous call. Counts the number of words written into the file.
hparif true the horizontal odd word parity is set before writing the word into the file.

Definition at line 137 of file EcalSimRawData.cc.

References trackerHits::c.

                                                        {

  if(hpar){
    //set horizontal odd parity bit:
    setHParity(data);
  }
  
  switch(writeMode_){
  case littleEndian:
    {
      char c = data & 0x00FF;
      f.write(&c, sizeof(c));
      c = (data >>8) & 0x00FF;
      f.write(&c, sizeof(c));
    }
    break;
  case bigEndian:
    {
      char c = (data >>8) & 0x00FF; 
      f.write(&c, sizeof(c));
      c = data & 0x00FF;
      f.write(&c, sizeof(c));
    }
    break;
  case ascii:
    f << ((iWord%8==0&&iWord!=0)?"\n":"")
      << "0x" << setfill('0') << setw(4) << hex << data << "\t"
      << dec << setfill(' ');
    break;
  }
  ++iWord;
}
void EcalSimRawData::genFeData ( std::string  basename,
int  iEvent,
const std::vector< uint16_t >  adcCount[nEbEta][nEbPhi] 
) const [private]

Generates FE crystal data

Parameters:
basenamebase for the output file name. DCC number is appended to the name
iEventevent index
adcCountthe payload, the ADC count of the channels.

stripHeader |= parity(stripHeader) << 15;

Definition at line 184 of file EcalSimRawData.cc.

References ecalMGPA::adc(), gather_cfg::cout, AlCaHLTBitMon_QueryRunRegistry::data, f, and alignCSCRings::s.

                                      {
  int smf = 0;
  int gmf = 0;
  int nPendingEvt = 0;
  int monitorFlag = 0;
  int chFrameLen = adcCount[0][0].size() + 1;
  
  int iWord = 0;
  
  for(int iZ0 = 0; iZ0<2; ++iZ0){
    for(int iDccPhi0 = 0; iDccPhi0<nDccInPhi; ++iDccPhi0){
      int iDcc1 = iDccPhi0 + iZ0*nDccInPhi + nDccEndcap + 1;

      if(dccNum_!=-1  && dccNum_!=iDcc1) continue;
      
      stringstream s;
      s.str("");
      const string& ext = getExt();
      s << basename << "_fe2dcc" << setfill('0') << setw(2) << iDcc1
        << setfill(' ') << ext;
      ofstream f(s.str().c_str(), (iEvent==1?ios::ate:ios::app));

      if(!f) return;


      if(writeMode_==ascii){
        f << (iEvent==1?"":"\n") << "[Event:" << iEvent << "]\n";
      }
      
      for(int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0){
        int iTtEta0 = iZ0*nTtSmEta + iTtEtaInSm0;
        for(int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0){
          //phi=0deg at middle of 1st barrel DCC:
          int iTtPhi0 = -nTtPhisPerEbDcc/2 + iDccPhi0*nTtPhisPerEbDcc
            + iTtPhiInSm0;
          if(iTtPhi0<0) iTtPhi0 += nTtPhi;
          for(int stripId1 = 1; stripId1 <= ttEdge; ++stripId1){
            uint16_t stripHeader =
              0xF << 11
              | (nPendingEvt & 0x3F) << 5
              | (gmf & 0x1) << 4
              | (smf & 0x1) << 3
              | (stripId1 & 0x7);
            fwrite(f,stripHeader, iWord);

            for(int xtalId1 = 1; xtalId1 <= ttEdge; ++xtalId1){
              
              uint16_t crystalHeader =
                1 <<14
                | (chFrameLen & 0xFF) <<4
                | (monitorFlag & 0x1) <<3
                | (xtalId1 & 0x7);
              //              crystalHeader |=parity(crystalHeader) << 15;
              fwrite(f, crystalHeader, iWord);
              
              int iEta0;
              int iPhi0;
              elec2GeomNum(iTtEta0, iTtPhi0, stripId1, xtalId1,
                           iEta0, iPhi0);
              if(xtalVerbose_){
                cout << dec
                     << "iDcc1 = " << iDcc1 << "\t"
                     << "iEbTtEta0 = " << iTtEta0 << "\t"
                     << "iEbTtPhi0 = " << iTtPhi0 << "\t"
                     << "stripId1 = " << stripId1 << "\t"
                     << "xtalId1 = " << xtalId1 << "\t"
                     << "iEta0 = " << iEta0 << "\t"
                     << "iPhi0 = " << iPhi0 << "\t"
                     << "adc[5] = 0x" << hex << adcCount[iEta0][iPhi0][5]
                     << dec << "\n";
              }
              

              const vector<uint16_t>& adc = adcCount[iEta0][iPhi0];
              for(unsigned iSample=0; iSample  < adc.size(); ++iSample){
                uint16_t data = adc[iSample] & 0x3FFF;
                //              data |= parity(data);
                fwrite(f, data, iWord);
              } //next time sample
            } //next crystal in strip
          } //next strip in TT
        } //next TT along phi
      } //next TT along eta
    } //next DCC
  } //next half-barrel
}
void EcalSimRawData::genSrData ( std::string  basename,
int  iEvent,
int  ttf[nEbTtEta][nTtPhi] 
) const [private]

Generates SR flags

Parameters:
basenamebase for the output file name. DCC number is appended to the name
iEventevent index
thetrigger tower flags

Definition at line 274 of file EcalSimRawData.cc.

References AlCaHLTBitMon_QueryRunRegistry::data, Exception, f, and alignCSCRings::s.

                                                               {
  for(int iZ0 = 0; iZ0<2; ++iZ0){
    for(int iDccPhi0 = 0; iDccPhi0<nDccInPhi; ++iDccPhi0){
      int iDcc1 = iDccPhi0 + iZ0*nDccInPhi + nDccEndcap + 1;
      if(dccNum_!=-1  && dccNum_!=iDcc1) continue;
      stringstream s;
      s.str("");
      s << basename << "_ab2dcc" << setfill('0') << setw(2) << iDcc1
        << setfill(' ') << getExt();
      ofstream f(s.str().c_str(), (iEvent==1?ios::ate:ios::app));
      
      if(!f) throw cms::Exception(string("Cannot create/open file ")
                                  + s.str() + ".");
      
      int iWord = 0;
  
      if(writeMode_==ascii){
        f << (iEvent==1?"":"\n")<< "[Event:" << iEvent << "]\n";
      }

      const uint16_t le1 = 0;
      const uint16_t le0 = 0;
      const uint16_t h1 = 1;
      const uint16_t nFlags = 68;
      uint16_t data =  (h1 & 0x1)<< 14
        | (le1 & 0x1) << 12
        | (le0 & 0x1) << 11
        | (nFlags & 0x7F);
      
      fwrite(f, data, iWord, true);
      
      int iFlag = 0;
      data = 0;

      for(int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0){
        //      int iTtEbEta0 = iZ0*nTtSmEta + iTtEtaInSm0;
        int iTtEta0 = nEeTtEta + iZ0*nTtSmEta + iTtEtaInSm0;
        for(int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0){
          //phi=0deg at middle of 1st barrel DCC:
          int iTtPhi0 = -nTtPhisPerEbDcc/2 + iDccPhi0*nTtPhisPerEbDcc
            + iTtPhiInSm0;
          if(iTtPhi0<0) iTtPhi0 += nTtPhi;
          //flags are packed by four:
          //|15 |14 |13-12 |11      9|8      6|5      3|2      0| 
          //| P | 0 | X  X |  srf i+3| srf i+2| srf i+1| srf i  |
          //|   |   |      | field 3 |field 2 | field 1| field 0|
          const int field = iFlag%4;
          //cout << "TtEta0: " << iTtEta0 << "\tTtPhi0: " << iTtPhi0 << "\n";
          //cout << "#" << oct << (int)srf[iTtEta0][iTtPhi0] << "o ****> #" << oct << (srf[iTtEta0][iTtPhi0] << (field*3)) << "o\n" << dec;
          
          data |= srf[iTtEta0][iTtPhi0] << (field*3);

          if(field==3){
            //cout <<  srf[iTtEta0][iTtPhi0] << "----> 0x" << hex << data << "\n";
            fwrite(f, data, iWord, true);
            data = 0;
          }
          ++iFlag;
        } //next TT along phi
      } //next TT along eta
    } //next DCC
  } //next half-barrel
}
void EcalSimRawData::genTccIn ( std::string  basename,
int  iEvent,
const int  tps[nTtEta][nTtPhi] 
) const [private]

Generates FE trigger primitives data

Parameters:
basenamebase for the output file name. DCC number is appended to the name
iEventevent index
tpsthe payload, the trigger primitives

Definition at line 340 of file EcalSimRawData.cc.

References gather_cfg::cout, Exception, and alignCSCRings::s.

                                                                  {
  for(int iZ0 = 0; iZ0<2; ++iZ0){
    for(int iTccPhi0 = 0; iTccPhi0<nTccInPhi; ++iTccPhi0){
      int iTcc1 = iTccPhi0 + iZ0*nTccInPhi + nTccEndcap + 1;
      
      if(tccNum_!=-1  && tccNum_!=iTcc1) continue;
      
      stringstream s;
      s.str("");
      const char* ext = ".txt"; //only ascii mode supported for TCP

      s << basename << "_tcc" << setfill('0') << setw(2) << iTcc1
        << setfill(' ') << ext;
      ofstream fe2tcc(s.str().c_str(), (iEvent==1?ios::ate:ios::app));

      if(!fe2tcc) throw cms::Exception(string("Failed to create file ")
                                       + s.str() + ".");
      
      int memPos = iEvent-1;
      int iCh1 = 1;
      for(int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0){
        int iTtEta0 = (iZ0==0) ? 27 - iTtEtaInSm0 : 28 + iTtEtaInSm0; 
        for(int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0){
          //phi=0deg at middle of 1st barrel DCC:
          int iTtPhi0 = -nTtPhisPerEbTcc/2 + iTccPhi0*nTtPhisPerEbTcc
            + iTtPhiInSm0;
          iTtPhi0 += nTtPhisPerEbTcc*iTccPhi0;
          if(iTtPhi0<0) iTtPhi0 += nTtPhi;
          uint16_t tp_fe2tcc = (tcp[iTtEta0][iTtPhi0] & 0x7ff) ; //keep only Et (9:0) and FineGrain (10)
          
          if(tpVerbose_ && tp_fe2tcc!=0){
            cout << dec
                 << "iTcc1 = " << iTcc1 << "\t"
                 << "iTtEta0 = " << iTtEta0 << "\t"
                 << "iTtPhi0 = " << iTtPhi0 << "\t"
                 << "iCh1 = " << iCh1 << "\t"
                 << "memPos = " << memPos << "\t" 
                 << "tp = 0x" << setfill('0') << hex << setw(3)
                 << tp_fe2tcc
                 << dec << setfill(' ') << "\n";
          }
          fe2tcc << iCh1 << "\t"
                 << memPos << "\t"
                 << setfill('0') << hex
                 << "0x" << setw(4) << tp_fe2tcc << "\t"
                 << "0"
                 << dec << setfill(' ') << "\n";
          ++iCh1;
        } //next TT along phi
      } //next TT along eta
      fe2tcc << std::flush;
      fe2tcc.close();
    } //next TCC
  } //next half-barrel
}
void EcalSimRawData::genTccOut ( std::string  basename,
int  iEvent,
const int  tps[nTtEta][nTtPhi] 
) const [private]

Generates TCC->DCC data

Parameters:
basenamebase for the output file name. DCC number is appended to the name
iEventevent index
tpsthe payload, the trigger primitives

Definition at line 398 of file EcalSimRawData.cc.

References gather_cfg::cout, AlCaHLTBitMon_QueryRunRegistry::data, and alignCSCRings::s.

                                                                   {
  int iDccWord = 0;

  for(int iZ0 = 0; iZ0<2; ++iZ0){
    for(int iTccPhi0 = 0; iTccPhi0<nTccInPhi; ++iTccPhi0){
      int iTcc1 = iTccPhi0 + iZ0*nTccInPhi + nTccEndcap + 1;

      if(tccNum_!=-1  && tccNum_!=iTcc1) continue;
      
      stringstream s;
      s.str("");
      const char* ext = ".txt"; //only ascii mode supported for TCP

      s << basename << "_tcc" << setfill('0') << setw(2) << iTcc1
        << setfill(' ') << ext;

      s.str("");
      s << basename << "_tcc2dcc" << setfill('0') << setw(2) << iTcc1
        << setfill(' ') << getExt();
      ofstream dccF(s.str().c_str(), (iEvent==1?ios::ate:ios::app));
      
      if(!dccF){
        cout << "Warning: failed to create or open file " << s << ".\n";
        return;
      }
      
      const uint16_t h1 = 1;
      const uint16_t le1 = 0;
      const uint16_t le0 = 0;
      const uint16_t nSamples = 1;
      const uint16_t nTts = 68;
      const uint16_t data = (h1 & 0x1) << 14
        | (le1 & 0x1) << 12
        | (le0 & 0x1) << 11
        | (nSamples & 0xF) << 7
        | (nTts & 0x7F);        
      dccF << (iEvent==1?"":"\n") << "[Event:" << iEvent << "]\n";
      fwrite(dccF, data, iDccWord, false);
      
      int memPos = iEvent-1;
      int iCh1 = 1;
      for(int iTtEtaInSm0 = 0; iTtEtaInSm0 < nTtSmEta; ++iTtEtaInSm0){
        int iTtEta0 = nEeTtEta + iZ0*nTtSmEta + iTtEtaInSm0;
        for(int iTtPhiInSm0 = 0; iTtPhiInSm0 < nTtSmPhi; ++iTtPhiInSm0){
          //phi=0deg at middle of 1st barrel DCC:
          int iTtPhi0 = -nTtPhisPerEbTcc/2 + iTccPhi0*nTtPhisPerEbTcc
            + iTtPhiInSm0;
          if(iTtPhi0<0) iTtPhi0 += nTtPhi;
          
          if(tpVerbose_){
            cout << dec
                 << "iTcc1 = " << iTcc1 << "\t"
                 << "iTtEta0 = " << iTtEta0 << "\t"
                 << "iTtPhi0 = " << iTtPhi0 << "\t"
                 << "iCh1 = " << iCh1 << "\t"
                 << "memPos = " << memPos << "\t" 
                 << "tp = 0x" << hex << tps[iTtEta0][iTtPhi0]
                 << dec << "\n";
          }
          fwrite(dccF, tps[iTtEta0][iTtPhi0], iDccWord, false);
          ++iCh1;
        } //next TT along phi
      } //next TT along eta
    } //next TCC
  } //next half-barrel
}
void EcalSimRawData::getEbDigi ( const edm::Event event,
std::vector< uint16_t >  adc[nEbEta][nEbPhi] 
) const [private]

Retrieves barrel digis (APD ADC count).

Parameters:
eventCMS event
adc[out] the adc counts: adc[iEta0][iPhi0][iTimeSample0]

Definition at line 531 of file EcalSimRawData.cc.

References ecalMGPA::adc(), gather_cfg::cout, Exception, EBDataFrame::id(), edm::HandleBase::isValid(), EcalMGPASample::raw(), EcalDataFrame::sample(), and EcalDataFrame::size().

                                                                          {

  edm::Handle<EBDigiCollection> hEbDigis;
  event.getByLabel(digiProducer_, ebDigiCollection_, hEbDigis);

  int nSamples = 0;
  if(hEbDigis.isValid() && hEbDigis->size()>0){//there is at least one digi
    nSamples  = hEbDigis->begin()->size();//gets the sample count from 1st digi
  }


  const uint16_t suppressed = 0xFFFF;

  adc[0][0] = vector<uint16_t>(nSamples, suppressed);
  
  for(int iEbEta=0; iEbEta<nEbEta; ++iEbEta){
    for(int iEbPhi=0; iEbPhi<nEbPhi; ++iEbPhi){
      adc[iEbEta][iEbPhi] = adc[0][0];
    }
  }
  if(hEbDigis.isValid()){
    if(xtalVerbose_) cout << setfill('0');
    for(EBDigiCollection::const_iterator it = hEbDigis->begin();
        it != hEbDigis->end(); ++it){
      const EBDataFrame& frame = *it;
      
      int iEta0 = iEta2cIndex((frame.id()).ieta());
      int iPhi0 = iPhi2cIndex((frame.id()).iphi());
      
      //     cout << "xtl indices conv: (" << frame.id().ieta() << ","
      //         << frame.id().iphi() << ") -> ("
      //         << iEta0 << "," << iPhi0 << ")\n";
    
      if(iEta0<0 || iEta0>=nEbEta){
        cout << "iEta0 (= " << iEta0 << ") is out of range ("
             << "[0," << nEbEta -1 << "])\n";
      }
      if(iPhi0<0 || iPhi0>=nEbPhi){
        cout << "iPhi0 (= " << iPhi0 << ") is out of range ("
             << "[0," << nEbPhi -1 << "])\n";
      }
    
      if(xtalVerbose_){
        cout << iEta0 << "\t" << iPhi0 << ":\t";
        cout << hex;
      }
      
      if(nSamples!=frame.size()){
        throw cms::Exception("EcalSimRawData", "Found EB digis with different sample count! This is not supported by EcalSimRawData.");
      }
    
      for(int iSample=0; iSample<nSamples; ++iSample){
        const EcalMGPASample& sample = frame.sample(iSample);
        uint16_t encodedAdc = sample.raw();
        adc[iEta0][iPhi0][iSample] = encodedAdc;  
        if(xtalVerbose_){
          cout << (iSample>0?" ":"") << "0x" << setw(4) 
               << encodedAdc;
        }
      }
      if(xtalVerbose_) cout << "\n" << dec;
    }
    if(xtalVerbose_) cout << setfill(' ');
  }
}
string EcalSimRawData::getExt ( ) const [private]

Help function to get the file extension which depends on the output formats.

Definition at line 171 of file EcalSimRawData.cc.

                                   {
  switch(writeMode_){
  case littleEndian:
    return ".le";
  case bigEndian:
    return ".be";
  case ascii:
    return ".txt";
  default:
    return".?";
  }  
}
void EcalSimRawData::getSrfs ( const edm::Event event,
int  ebSrf[nTtEta][nTtPhi],
int  eeSrf[nEndcaps][nScX][nScY] 
) const [private]

Computes the selective readout flags.

Parameters:
[in]eventCMS event
[out]ebSrfthe computed SR flags for barrel
[out]eeSrfthe computed SR flags for endcaps

Definition at line 477 of file EcalSimRawData.cc.

References i, EESrFlag::id(), EBSrFlag::id(), EcalTrigTowerDetId::ieta(), EcalTrigTowerDetId::iphi(), edm::HandleBase::isValid(), EcalScDetId::ix(), EcalScDetId::iy(), nEndcaps, EcalSrFlag::value(), and EcalScDetId::zside().

                                                                   {

  //EE
  edm::Handle<EESrFlagCollection> hEeSrFlags;
  event.getByLabel(srDigiProducer_, eeSrFlagCollection_, hEeSrFlags);
  for(size_t i=0; i < sizeof(eeSrf)/sizeof(int); ((int*)eeSrf)[i++] = -1){};
  if(hEeSrFlags.isValid()){
    for(EESrFlagCollection::const_iterator it = hEeSrFlags->begin();
        it != hEeSrFlags->end(); ++it){
      const EESrFlag& flag = *it;
      int iZ0 = flag.id().zside()>0?1:0;
      int iX0 = flag.id().ix()-1;
      int iY0 = flag.id().iy()-1;
      assert(iZ0>=0 && iZ0<nEndcaps);
      assert(iX0>=0 && iX0<nScX);
      assert(iY0>=0 && iY0<nScY);
      eeSrf[iZ0][iX0][iY0] = flag.value();
    }
  } else{
    LogWarning("EcalSimRawData") << "EE SR flag not found ("
                                 << "Product label: " << srDigiProducer_
                                 << "Producet instance: "
                                 << eeSrFlagCollection_ << ")";
  }

  //EB
  edm::Handle<EBSrFlagCollection> hEbSrFlags;
  event.getByLabel(srDigiProducer_, ebSrFlagCollection_, hEbSrFlags);
  for(size_t i=0; i<sizeof(ebSrf)/sizeof(int); ((int*)ebSrf)[i++] = -1){};
  if(hEbSrFlags.isValid()){
    for(EBSrFlagCollection::const_iterator it = hEbSrFlags->begin();
        it != hEbSrFlags->end(); ++it){
      
      const EBSrFlag& flag = *it;
      int iEta = flag.id().ieta();
      int iEta0 = iEta + nTtEta/2 - (iEta>=0?1:0); //0->55 from eta=-3 to eta=3
      int iEbEta0 = iEta0 - nEeTtEta;//0->33 from eta=-1.48 to eta=1.48
      int iPhi0 = flag.id().iphi() - 1;

      assert(iEbEta0>=0 && iEbEta0<nEbTtEta);
      assert(iPhi0>=0 && iPhi0<nTtPhi);
      
      ebSrf[iEbEta0][iPhi0] = flag.value();
    }
  } else{
    LogWarning("EcalSimRawData") << "EB SR flag not found ("
                                 << "Product label: " << srDigiProducer_
                                 << "Producet instance: "
                                 << ebSrFlagCollection_ << ")";
  }
}
void EcalSimRawData::getTp ( const edm::Event event,
const std::string &  collName,
int  tp[nTtEta][nTtPhi] 
) const [private]

Extracts the trigger primitive (TP). The collection name parameter permits to select either the TCP Fenix output or the TCC output. Note: TCP output is only valid for the barrel.

Parameters:
eventCMS event
collNamelabel of the EDM collection containing the TP.
tp[out] the trigger primitives

Definition at line 599 of file EcalSimRawData.cc.

References edm::SortedCollection< T, SORT >::begin(), gather_cfg::cout, edm::SortedCollection< T, SORT >::end(), EcalTriggerPrimitiveDigi::id(), EcalTrigTowerDetId::ieta(), EcalTrigTowerDetId::iphi(), edm::HandleBase::isValid(), edm::Handle< T >::product(), and EcalTriggerPrimitiveDigi::sampleOfInterest().

                                                         {
  edm::Handle<EcalTrigPrimDigiCollection> hTpDigis;
  event.getByLabel(tpProducer_, collName, hTpDigis);
  if(hTpDigis.isValid() && hTpDigis->size()>0){
    const EcalTrigPrimDigiCollection& tpDigis = *hTpDigis.product();

    //    EcalSelectiveReadout::ttFlag_t ttf[nTtEta][nTtPhi];
    for(int iTtEta0=0; iTtEta0 < nTtEta; ++iTtEta0){
      for(int iTtPhi0=0; iTtPhi0 < nTtPhi; ++iTtPhi0){
        tcp[iTtEta0][iTtPhi0] = tccInDefaultVal_ ;
      }
    }
    if(tpVerbose_){
      cout << setfill('0');
    }
    for(EcalTrigPrimDigiCollection::const_iterator it = tpDigis.begin();
        it != tpDigis.end(); ++it){
      const EcalTriggerPrimitiveDigi& tp = *it;
      int iTtEta0 = iTtEta2cIndex(tp.id().ieta());
      int iTtPhi0 = iTtPhi2cIndex(tp.id().iphi());
      if(iTtEta0<0 || iTtEta0>=nTtEta){
        cout << "iTtEta0 (= " << iTtEta0 << ") is out of range ("
             << "[0," << nEbTtEta -1 << "])\n";
      }
      if(iTtPhi0<0 || iTtPhi0>=nTtPhi){
        cout << "iTtPhi0 (= " << iTtPhi0 << ") is out of range ("
             << "[0," << nTtPhi -1 << "])\n";
      }

      tcp[iTtEta0][iTtPhi0] = tp[tp.sampleOfInterest()].raw();

      if(tpVerbose_){
        if(tcp[iTtEta0][iTtPhi0]!=0) //print non-zero values only
        cout << collName << (collName.size()==0?"":" ")
             << "TP(" << setw(2) << iTtEta0 << "," << iTtPhi0 << ") = "
             << "0x" << setw(4) 
             << tcp[iTtEta0][iTtPhi0]
             << "\tcmssw indices: "
             << tp.id().ieta() << " " << tp.id().iphi() << "\n";
      }
    }//next TP
    if(tpVerbose_) cout << setfill(' ');
  }
}
int EcalSimRawData::iEta2cIndex ( int  iEta) const [inline, private]

Converts std CMSSW crystal eta index into a c-index (contiguous integer starting from 0 and increasing with pseudo-rapidity).

Parameters:
iEtastd CMSSW crystal eta index
Returns:
the c-array index

Definition at line 209 of file EcalSimRawData.h.

                                 {
    return (iEta<0)?iEta+85:iEta+84;
  }
int EcalSimRawData::iPhi2cIndex ( int  iPhi) const [inline, private]

Converts std CMSSW crystal phi index into a c-index (contiguous integer starting from 0 at phi=0deg and increasing with phi).

Parameters:
iPhistd CMSSW crystal phi index
Returns:
the c-array index

Definition at line 218 of file EcalSimRawData.h.

References nEbPhi.

                                 {
    int iPhi0 = iPhi -11;
    if(iPhi0<0) iPhi0+=nEbPhi;
    return iPhi0;
  }
int EcalSimRawData::iTtEta2cIndex ( int  iTtEta) const [inline, private]

Converts std CMSSW ECAL trigger tower eta index into a c-index (contiguous integer starting from 0 and increasing with pseudo-rapidity).

Parameters:
iEtastd CMSSW trigger tower eta index
Returns:
the c-array index

Definition at line 230 of file EcalSimRawData.h.

                                     {
    return (iTtEta<0)?(iTtEta+28):(iTtEta+27);
  }
int EcalSimRawData::iTtPhi2cIndex ( int  iTtPhi) const [inline, private]

Converts std CMSSW ECAL trigger tower phi index into a c-index (contiguous integer starting from 0 at phi=0deg and increasing with phi).

Parameters:
iPhistd CMSSW ECAL trigger tower phi index
Returns:
the c-array index

Definition at line 255 of file EcalSimRawData.h.

                                     {
    return iTtPhi-1;
  }
void EcalSimRawData::setHParity ( uint16_t &  a) const [private]

Definition at line 467 of file EcalSimRawData.cc.

References AlCaHLTBitMon_ParallelJobs::p.

                                                {
  const int odd = 1 <<15;
  const int even = 0;
  //parity bit of numbers from 0x0 to 0xF:
  //                    0   1   2    3   4    5    6   7   8    9    A   B    C   D   E    F           
  const int p[16] = {even,odd,odd,even,odd,even,even,odd,odd,even,even,odd,even,odd,odd,even};
  //inverts parity bit (LSB) of 'a' in case of even parity:
  a ^= p[a&0xF] ^ p[(a>>4)&0xF] ^ p[(a>>8)&0xF] ^ p[a>>12&0xF] ^ odd;   
}

Member Data Documentation

std::string EcalSimRawData::basename_ [private]

basename for output files

Definition at line 467 of file EcalSimRawData.h.

int EcalSimRawData::dccNum_ [private]

Index of the DCC, FE data must be produced for. -1 for all TTCs

Definition at line 459 of file EcalSimRawData.h.

std::string EcalSimRawData::digiProducer_ [private]

Name of module/plugin/producer making digis

Definition at line 370 of file EcalSimRawData.h.

const int EcalSimRawData::ebDccPhiEdge = 20 [static, private]

Number of barrel crystals along phi covered by a DCC

Definition at line 141 of file EcalSimRawData.h.

std::string EcalSimRawData::ebDigiCollection_ [private]

EB digi product instance name

Definition at line 374 of file EcalSimRawData.h.

std::string EcalSimRawData::ebSrFlagCollection_ [private]

EB SRP flag digi product instance name

Definition at line 387 of file EcalSimRawData.h.

const int EcalSimRawData::ebTccPhiEdge = 20 [static, private]

number of TTs along phi of a TCC sector

Definition at line 129 of file EcalSimRawData.h.

std::string EcalSimRawData::eeDigiCollection_ [private]

EE digi product instance name

Definition at line 378 of file EcalSimRawData.h.

std::string EcalSimRawData::eeSrFlagCollection_ [private]

EE SRP flag digi product instancename

Definition at line 391 of file EcalSimRawData.h.

std::auto_ptr<EcalSelectiveReadout> EcalSimRawData::esr_ [private]

Selective readout simulator

Definition at line 443 of file EcalSimRawData.h.

bool EcalSimRawData::fe2dcc_ [private]

Switch for data of FE->DCC link

Definition at line 431 of file EcalSimRawData.h.

bool EcalSimRawData::fe2tcc_ [private]

Switch for data of FE->TCC link

Definition at line 435 of file EcalSimRawData.h.

const int EcalSimRawData::nDccEndcap = 9 [static, private]

Number of DCCs for a single endcap

Definition at line 125 of file EcalSimRawData.h.

const int EcalSimRawData::nDccInPhi = 18 [static, private]

Number of barrel DCCs along Phi

Definition at line 121 of file EcalSimRawData.h.

const int EcalSimRawData::nEbEta = 170 [static, private]

Number of crystals in ECAL barrel along eta

Definition at line 61 of file EcalSimRawData.h.

const int EcalSimRawData::nEbPhi = 360 [static, private]

Number of crystals in ECAL barrel along phi

Definition at line 65 of file EcalSimRawData.h.

Referenced by iPhi2cIndex().

const int EcalSimRawData::nEbTtEta = nEbEta/ttEdge [static, private]

Number of TTs along Ecal barrel eta

Definition at line 109 of file EcalSimRawData.h.

const int EcalSimRawData::nEeTtEta = 11 [static, private]

Number of TTs along eta for one endcap.

Definition at line 113 of file EcalSimRawData.h.

const int EcalSimRawData::nEeX = 100 [static, private]

X-edge of endcap (x,y)- crystal grid

Definition at line 69 of file EcalSimRawData.h.

const int EcalSimRawData::nEeY = 100 [static, private]

Y-edge of endcap (x,y)- crystal grid

Definition at line 73 of file EcalSimRawData.h.

const int EcalSimRawData::nEndcaps = 2 [static, private]

Number of endcaps

Definition at line 77 of file EcalSimRawData.h.

const int EcalSimRawData::nScX = 20 [static, private]

Maximum number of supercrystal along x axis

Definition at line 85 of file EcalSimRawData.h.

const int EcalSimRawData::nScY = 20 [static, private]

Maximum number of supercrystal along y axis

Definition at line 89 of file EcalSimRawData.h.

const int EcalSimRawData::nTccEndcap = 36 [static, private]

Number of TCCs for a single endcap

Definition at line 137 of file EcalSimRawData.h.

const int EcalSimRawData::nTccInPhi = 18 [static, private]

Number of Barrel TTCs along phi

Definition at line 133 of file EcalSimRawData.h.

const int EcalSimRawData::nTtEta = nEbTtEta+2*nEeTtEta [static, private]

Number of TTs along ECAL eta

Definition at line 117 of file EcalSimRawData.h.

const int EcalSimRawData::nTtPhi = nEbPhi/ttEdge [static, private]

Number of TTs along Ecal Phi

Definition at line 105 of file EcalSimRawData.h.

const int EcalSimRawData::nTtPhisPerEbDcc = 4 [static, private]

Number of trigger towers alng phi covered by a DCC

Definition at line 145 of file EcalSimRawData.h.

const int EcalSimRawData::nTtPhisPerEbTcc = 4 [static, private]

Number of trigger towers alng phi covered by a TCC

Definition at line 149 of file EcalSimRawData.h.

const int EcalSimRawData::nTtSmEta = 17 [static, private]

Number of TTs along SM eta

Definition at line 101 of file EcalSimRawData.h.

const int EcalSimRawData::nTtSmPhi = 4 [static, private]

Number of TTs along SM phi

Definition at line 97 of file EcalSimRawData.h.

const int EcalSimRawData::nTtTypes = 2 [static, private]

Number of barrel trigger tower types (in term of VFE card orientation)

Definition at line 153 of file EcalSimRawData.h.

const int EcalSimRawData::scEdge = 5 [static, private]

Supercrystal edge in number of crystals

Definition at line 81 of file EcalSimRawData.h.

std::string EcalSimRawData::srDigiProducer_ [private]

Label of SR flags and suppressed digis

Definition at line 383 of file EcalSimRawData.h.

std::ofstream EcalSimRawData::srfFile [private]

Output file for selective readout flags

Definition at line 451 of file EcalSimRawData.h.

bool EcalSimRawData::srp2dcc_ [private]

Switch for data of SRP->DCC link

Definition at line 423 of file EcalSimRawData.h.

const int EcalSimRawData::strip2Eta [static, private]
Initial value:
 {
  {4,3,2,1,0}, 
  {0,1,2,3,4}  
}

Maps strip_id to eta index within a TT. strip2Eta[iTtType][strip_id-1] will be the eta index of channels with strip_id 'strip_id'. The eta index runs from 0 to 4 and increasing with the eta of the std CMS coordinates.

Definition at line 174 of file EcalSimRawData.h.

const int EcalSimRawData::stripCh2Phi [static, private]
Initial value:
 {
  
  
  {{4,3,2,1,0},                 
   {0,1,2,3,4}, 
   {4,3,2,1,0}, 
   {0,1,2,3,4}, 
   {4,3,2,1,0}},
  
  {{0,1,2,3,4},
   {4,3,2,1,0},
   {0,1,2,3,4},
   {4,3,2,1,0},
   {0,1,2,3,4}}
}

Maps (strip_id, channel_id) to phi index within a TT. stripCh2Phi[iTtType][strip_id-1][ch_id-1] will be the phi index of the TT of type iTtType with strip ID 'strip_id' and channel VFE id 'ch_id'. The phi runs from 0 to 4 and increases with the phi of std CMS coordinates.

Definition at line 167 of file EcalSimRawData.h.

bool EcalSimRawData::tcc2dcc_ [private]

Switch for data of TCC->DCC link

Definition at line 427 of file EcalSimRawData.h.

default TriggerPrimitive values if the trigger tower is abscent

Definition at line 463 of file EcalSimRawData.h.

int EcalSimRawData::tccNum_ [private]

Index of the TCC, FE data must be produced for. -1 for all TTCs

Definition at line 455 of file EcalSimRawData.h.

std::string EcalSimRawData::tcpDigiCollection_ [private]

TCP Fenix output digi product instance name

Definition at line 399 of file EcalSimRawData.h.

Calorimeter geometry

Definition at line 403 of file EcalSimRawData.h.

ECAL endcap trigger tower map

Definition at line 439 of file EcalSimRawData.h.

std::string EcalSimRawData::tpDigiCollection_ [private]

Trigger primitive digi product instance name

Definition at line 395 of file EcalSimRawData.h.

std::string EcalSimRawData::tpProducer_ [private]

Name of the trigger primitive label

Definition at line 407 of file EcalSimRawData.h.

Verbosity switch for crystal data

Definition at line 419 of file EcalSimRawData.h.

const int EcalSimRawData::ttEdge = 5 [static, private]

Definition at line 93 of file EcalSimRawData.h.

std::ofstream EcalSimRawData::ttfFile [private]

Output file for trigger tower flags

Definition at line 447 of file EcalSimRawData.h.

const int EcalSimRawData::ttType [static, private]
Initial value:
 {
  0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1, 
  0,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1
}

Map of trigger tower types (in term of VFE card orientation). ttType[iTtEta0]: trigger tower type of TTs with eta 'c-arrary' index iTtEta0

Definition at line 159 of file EcalSimRawData.h.

output format

Definition at line 411 of file EcalSimRawData.h.

Verbosity switch for crystal data

Definition at line 415 of file EcalSimRawData.h.