Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:41

0001 
0002 #include "RctDigiToRctText.h"
0003 #include <iomanip>
0004 
0005 using std::dec;
0006 using std::endl;
0007 using std::hex;
0008 using std::setfill;
0009 using std::setw;
0010 
0011 RctDigiToRctText::RctDigiToRctText(const edm::ParameterSet &iConfig)
0012     : m_rctInputLabel(iConfig.getParameter<edm::InputTag>("RctInputLabel")),
0013       m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
0014       m_hexUpperCase(iConfig.getParameter<bool>("HexUpperCase")) {
0015   /// open output text files
0016   for (unsigned i = 0; i < NUM_RCT_CRATES; i++) {
0017     std::stringstream fileStream;
0018     fileStream << m_textFileName << std::setw(2) << std::setfill('0') << i << ".txt";
0019     std::string fileName(fileStream.str());
0020     m_file[i].open(fileName.c_str(), std::ios::out);
0021 
0022     if (!m_file[i].good()) {
0023       throw cms::Exception("RctDigiToRctTextTextFileOpenError")
0024           << "RctDigiToRctText::RctDigiToRctText : "
0025           << " couldn't create the file " << fileName << std::endl;
0026     }
0027   }
0028 
0029   /// open info|debug file
0030   fdebug.open("rctdigitorcttext_debug.txt", std::ios::out);
0031 }
0032 
0033 RctDigiToRctText::~RctDigiToRctText() {
0034   /// close  files
0035   for (unsigned i = 0; i < NUM_RCT_CRATES; i++)
0036     m_file[i].close();
0037   fdebug.close();
0038 }
0039 
0040 void RctDigiToRctText::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0041   /// count bunch crossing
0042   nevt++;
0043 
0044   /// get the RCT data
0045   edm::Handle<L1CaloEmCollection> em;
0046   edm::Handle<L1CaloRegionCollection> rgn;
0047   iEvent.getByLabel(m_rctInputLabel, em);
0048   iEvent.getByLabel(m_rctInputLabel, rgn);
0049 
0050   /// debug flags and stream
0051   bool ldebug = false;
0052   bool debug_NOTEMPTY[18] = {false};
0053   for (int i = 0; i < 18; i++)
0054     debug_NOTEMPTY[i] = false;
0055   std::stringstream dstrm;
0056 
0057   /// --- ELECTRONS ---
0058 
0059   unsigned long int CAND[18][8];
0060   int n_iso[18] = {0};
0061   int n_niso[18] = {0};
0062   bool iso;
0063   int id;
0064 
0065   for (L1CaloEmCollection::const_iterator iem = em->begin(); iem != em->end(); iem++) {
0066     int crate = iem->rctCrate();
0067     iso = iem->isolated();
0068     unsigned data = iem->raw();
0069 
0070     id = iso ? n_iso[crate]++ : 4 + n_niso[crate]++;
0071 
0072     CAND[crate][id] = data;
0073 
0074     /// debug
0075     if (crate > 17 || id > 7)
0076       throw cms::Exception("RctDigiToRctTextElectronIndexOutBounds")
0077           << "out of bounds indices  crate:" << crate << "id:" << id << std::endl;
0078     if (ldebug && data != 0)
0079       debug_NOTEMPTY[crate] = true;
0080     dstrm.str("");
0081     dstrm << "electron "
0082           << " bx:" << nevt << " crate:" << crate << " iso:" << iso << " raw:" << data << " \t cand:" << *iem;
0083     if (debug_NOTEMPTY[crate])
0084       fdebug << dstrm.str() << std::endl;
0085   }
0086 
0087   /// --- REGIONS ---
0088 
0089   unsigned short MIPbits[18][7][2] = {{{0}}};
0090   unsigned short QIEbits[18][7][2] = {{{0}}};
0091   unsigned short RC[18][7][2] = {{{0}}};
0092   unsigned short RCof[18][7][2] = {{{0}}};
0093   unsigned short RCtau[18][7][2] = {{{0}}};
0094   unsigned short HF[18][4][2] = {{{0}}};
0095 
0096   for (L1CaloRegionCollection::const_iterator irgn = rgn->begin(); irgn != rgn->end(); irgn++) {
0097     int crate = irgn->rctCrate();
0098     int card = irgn->rctCard();
0099     int rgnidx = irgn->rctRegionIndex();
0100 
0101     dstrm.str("");
0102     if (!irgn->id().isHf()) {
0103       RC[crate][card][rgnidx] = irgn->et();
0104       RCof[crate][card][rgnidx] = irgn->overFlow();
0105       RCtau[crate][card][rgnidx] = irgn->tauVeto();
0106       MIPbits[crate][card][rgnidx] = irgn->mip();
0107       QIEbits[crate][card][rgnidx] = irgn->quiet();
0108       // debug info
0109       dstrm << hex << "Et=" << irgn->et() << " OverFlow=" << irgn->overFlow() << " tauVeto=" << irgn->tauVeto()
0110             << " mip=" << irgn->mip() << " quiet=" << irgn->quiet() << " Card=" << irgn->rctCard()
0111             << " Region=" << irgn->rctRegionIndex() << " Crate=" << irgn->rctCrate() << dec;
0112       if (ldebug)
0113         LogDebug("Regions") << dstrm.str();
0114     } else {
0115       HF[crate][irgn->id().rctEta() - 7][irgn->id().rctPhi()] = irgn->et();
0116       // debug info
0117       dstrm << hex << "Et=" << irgn->et() << " FGrain=" << irgn->fineGrain() << " Eta=" << irgn->id().rctEta()
0118             << " Phi=" << irgn->id().rctPhi() << " Crate=" << irgn->rctCrate() << dec;
0119       if (ldebug)
0120         LogDebug("HFRegions") << dstrm.str();
0121     }
0122 
0123     if (ldebug && irgn->et() != 0)
0124       debug_NOTEMPTY[crate] = true;  // debug
0125     if (debug_NOTEMPTY[crate]) {
0126       fdebug << "region"
0127              << " bx:" << nevt << " crate:" << crate << "\t";
0128       fdebug << dstrm.str() << std::endl;
0129     }
0130   }
0131 
0132   std::stringstream sstrm;
0133   if (m_hexUpperCase)
0134     sstrm << std::uppercase;
0135   else
0136     sstrm.unsetf(std::ios::uppercase);
0137 
0138   /// print electrons
0139 
0140   for (unsigned crate = 0; crate < NUM_RCT_CRATES; crate++) {
0141     sstrm.str("");
0142     sstrm << "Crossing " << nevt << std::endl;
0143 
0144     for (int j = 0; j < 8; j++) {
0145       sstrm << setw(3) << setfill('0') << hex << (CAND[crate][j] & 0x3ff);
0146       if (j < 7)
0147         sstrm << " ";
0148     }
0149     sstrm << setfill(' ') << dec;
0150     m_file[crate] << sstrm.str() << std::endl;
0151 
0152     // debug
0153     if (debug_NOTEMPTY[crate])
0154       fdebug << sstrm.str() << std::endl;
0155     if (ldebug)
0156       LogDebug("Electrons") << sstrm.str() << std::endl;
0157   }
0158 
0159   /// print regions
0160 
0161   for (unsigned crate = 0; crate < NUM_RCT_CRATES; crate++) {
0162     /// mip bits
0163     sstrm.str("");
0164     for (int card = 0; card < 7; card++) {
0165       for (int j = 0; j < 2; j++) {
0166         sstrm << " " << MIPbits[crate][card][j];
0167       }
0168     }
0169     m_file[crate] << sstrm.str() << std::endl;
0170     if (debug_NOTEMPTY[crate])
0171       fdebug << sstrm.str() << std::endl;  // debug
0172 
0173     /// quiet bits
0174     sstrm.str("");
0175     for (int card = 0; card < 7; card++) {
0176       for (int j = 0; j < 2; j++) {
0177         sstrm << " " << QIEbits[crate][card][j];
0178       }
0179     }
0180     m_file[crate] << sstrm.str() << std::endl;
0181     if (debug_NOTEMPTY[crate])
0182       fdebug << sstrm.str() << std::endl;  // debug
0183 
0184     /// region info
0185     sstrm.str("");
0186     for (int card = 0; card < 7; card++) {
0187       for (int j = 0; j < 2; j++) {
0188         unsigned long int tmp;
0189         unsigned et = RC[crate][card][j];
0190         unsigned ovf = RCof[crate][card][j];
0191         unsigned tau = RCtau[crate][card][j];
0192         // ovf = ovf || (et>=0x400);
0193         tmp = ((tau & 0x1) << 11) | ((ovf & 0x1) << 10) | ((et & 0x3ff));
0194         sstrm << " " << setw(3) << setfill('0') << hex << tmp;
0195       }
0196     }
0197     m_file[crate] << sstrm.str() << std::endl;
0198     if (debug_NOTEMPTY[crate])
0199       fdebug << sstrm.str() << std::endl << std::endl;  // debug
0200 
0201     /// HF
0202     sstrm.str("");
0203     for (int ip = 0; ip < 2; ip++) {
0204       for (int ie = 0; ie < 4; ie++) {
0205         unsigned et = HF[crate][ie][ip] & 0xff;
0206         sstrm << " " << setw(2) << setfill('0') << hex << et;
0207       }
0208     }
0209     m_file[crate] << sstrm.str() << std::endl;
0210     if (debug_NOTEMPTY[crate])
0211       fdebug << sstrm.str() << std::endl;  // debug
0212     sstrm << setfill(' ') << dec;
0213 
0214   }  // end crate loop
0215 
0216   /// flush data to files
0217   for (unsigned i = 0; i < NUM_RCT_CRATES; i++)
0218     m_file[i] << std::flush;
0219 
0220   fdebug << std::flush;
0221 }