Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:38

0001 // -*- C++ -*-

0002 //

0003 // Package:    RctDigiToSourceCardText

0004 // Class:      RctDigiToSourceCardText

0005 //

0006 /**\class RctDigiToSourceCardText RctDigiToSourceCardText.cc

0007 L1Trigger/TextToDigi/src/RctDigiToSourceCardText.cc

0008 

0009 Description: Input RCT digis and output GCT text file to be loaded into the

0010 source cards for pattern tests.

0011 

0012 */
0013 //

0014 // Original Author:  Alex Tapper

0015 //         Created:  Fri Feb 16 14:52:19 CET 2007

0016 //

0017 //

0018 
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"  // Logger
0020 #include "FWCore/ServiceRegistry/interface/Service.h"      // Framework services
0021 #include "RctDigiToSourceCardText.h"
0022 
0023 using namespace edm;
0024 using namespace std;
0025 
0026 // Set constant

0027 const static int NUM_RCT_CRATES = 18;
0028 
0029 RctDigiToSourceCardText::RctDigiToSourceCardText(const edm::ParameterSet &iConfig)
0030     : m_rctInputLabel(iConfig.getParameter<edm::InputTag>("RctInputLabel")),
0031       m_textFileName(iConfig.getParameter<std::string>("TextFileName")),
0032       m_nevt(0) {
0033   // Open the output file

0034   m_file.open(m_textFileName.c_str(), std::ios::out);
0035 
0036   if (!m_file.good()) {
0037     throw cms::Exception("RctDigiToSourceCardTextFileOpenError")
0038         << "RctDigiToSourceCardText::RctDigiToSourceCardText : "
0039         << " couldn't open the file " << m_textFileName << " for writing" << std::endl;
0040   }
0041 
0042   // Make a SC routing object

0043   SourceCardRouting m_scRouting;
0044 }
0045 
0046 RctDigiToSourceCardText::~RctDigiToSourceCardText() {
0047   // Close the output file

0048   m_file.close();
0049 }
0050 
0051 // ------------ method called to for each event  ------------

0052 void RctDigiToSourceCardText::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0053   // get the RCT data

0054   Handle<L1CaloEmCollection> em;
0055   Handle<L1CaloRegionCollection> rgn;
0056   iEvent.getByLabel(m_rctInputLabel, em);
0057   iEvent.getByLabel(m_rctInputLabel, rgn);
0058 
0059   // General variables

0060   int RoutingMode;
0061   unsigned short logicalCardID;
0062   std::string dataString;
0063 
0064   // Arrays to hold electron variables

0065   unsigned short eIsoRank[18][4] = {{0}};
0066   unsigned short eIsoCardId[18][4] = {{0}};
0067   unsigned short eIsoRegionId[18][4] = {{0}};
0068   unsigned short eNonIsoRank[18][4] = {{0}};
0069   unsigned short eNonIsoCardId[18][4] = {{0}};
0070   unsigned short eNonIsoRegionId[18][4] = {{0}};
0071 
0072   // Fill electrons

0073   unsigned numIsoEM[18] = {0};
0074   unsigned numNonIsoEM[18] = {0};
0075 
0076   for (L1CaloEmCollection::const_iterator iem = em->begin(); iem != em->end(); iem++) {
0077     if (iem->isolated()) {
0078       eIsoRank[iem->rctCrate()][numIsoEM[iem->rctCrate()]] = iem->rank();
0079       eIsoCardId[iem->rctCrate()][numIsoEM[iem->rctCrate()]] = iem->rctCard();
0080       eIsoRegionId[iem->rctCrate()][numIsoEM[iem->rctCrate()]] = iem->rctRegion();
0081       numIsoEM[iem->rctCrate()]++;
0082     } else {
0083       eNonIsoRank[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]] = iem->rank();
0084       eNonIsoCardId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]] = iem->rctCard();
0085       eNonIsoRegionId[iem->rctCrate()][numNonIsoEM[iem->rctCrate()]] = iem->rctRegion();
0086       numNonIsoEM[iem->rctCrate()]++;
0087     }
0088     // Debug info

0089     LogDebug("Electrons") << "Rank=" << iem->rank() << " Card=" << iem->rctCard() << " Region=" << iem->rctRegion()
0090                           << " Crate=" << iem->rctCrate() << " Isolated=" << iem->isolated();
0091   }
0092 
0093   // Arrays to hold region variables

0094   unsigned short RC[18][7][2] = {{{0}}};
0095   unsigned short RCof[18][7][2] = {{{0}}};
0096   unsigned short RCtau[18][7][2] = {{{0}}};
0097   unsigned short HF[18][4][2] = {{{0}}};
0098   unsigned short HFQ[18][4][2] = {{{0}}};
0099   unsigned short MIPbits[18][7][2] = {{{0}}};
0100   unsigned short Qbits[18][7][2] = {{{0}}};
0101 
0102   // Fill regions

0103   for (L1CaloRegionCollection::const_iterator irgn = rgn->begin(); irgn != rgn->end(); irgn++) {
0104     if (irgn->id().isHf()) {
0105       HF[irgn->rctCrate()][irgn->id().rctEta() - 7][irgn->id().rctPhi()] = irgn->et();
0106       HFQ[irgn->rctCrate()][irgn->id().rctEta() - 7][irgn->id().rctPhi()] = irgn->fineGrain();
0107       // Debug info

0108       LogDebug("HFRegions") << "Et=" << irgn->et() << " FineGrain=" << irgn->fineGrain()
0109                             << " Eta=" << irgn->id().rctEta() << " Phi=" << irgn->id().rctPhi()
0110                             << " Crate=" << irgn->rctCrate();
0111     } else {
0112       RC[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] = irgn->et();
0113       RCof[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] = irgn->overFlow();
0114       RCtau[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] = irgn->tauVeto();
0115       MIPbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] = irgn->mip();
0116       Qbits[irgn->rctCrate()][irgn->rctCard()][irgn->rctRegionIndex()] = irgn->quiet();
0117       // Debug info

0118       LogDebug("Regions") << "Et=" << irgn->et() << " OverFlow=" << irgn->overFlow() << " tauVeto=" << irgn->tauVeto()
0119                           << " mip=" << irgn->mip() << " quiet=" << irgn->quiet() << " Card=" << irgn->rctCard()
0120                           << " Region=" << irgn->rctRegionIndex() << " Crate=" << irgn->rctCrate();
0121     }
0122   }
0123 
0124   for (int crate = 0; crate < NUM_RCT_CRATES; crate++) {
0125     // Logical Card ID = Source Card number

0126     RoutingMode = 0;
0127     m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
0128 
0129     // Convert electrons to SC format

0130     m_scRouting.EMUtoSTRING(logicalCardID,
0131                             m_nevt,
0132                             eIsoRank[crate],
0133                             eIsoCardId[crate],
0134                             eIsoRegionId[crate],
0135                             eNonIsoRank[crate],
0136                             eNonIsoCardId[crate],
0137                             eNonIsoRegionId[crate],
0138                             MIPbits[crate],
0139                             Qbits[crate],
0140                             dataString);
0141 
0142     // Write electrons

0143     m_file << dataString;
0144 
0145     // Logical Card ID = Source Card number

0146     RoutingMode = 1;
0147     m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
0148 
0149     // Convert regions to SC format

0150     m_scRouting.RC56HFtoSTRING(
0151         logicalCardID, m_nevt, RC[crate], RCof[crate], RCtau[crate], HF[crate], HFQ[crate], dataString);
0152 
0153     // Write regions

0154     m_file << dataString;
0155 
0156     // Logical Card ID = Source Card number

0157     RoutingMode = 2;
0158     m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
0159 
0160     // Convert regions to SC format

0161     m_scRouting.RC012toSTRING(logicalCardID, m_nevt, RC[crate], RCof[crate], RCtau[crate], dataString);
0162 
0163     // Write regions

0164     m_file << dataString;
0165 
0166     // This is to 9 only as this is the shared source card

0167     if (crate < 9) {
0168       // Logical Card ID = Source Card number

0169       RoutingMode = 3;
0170       m_scRouting.RoutingModetoLogicalCardID(logicalCardID, RoutingMode, crate);
0171 
0172       // Convert regions to SC format

0173       m_scRouting.RC234toSTRING(logicalCardID,
0174                                 m_nevt,
0175                                 RC[crate],
0176                                 RCof[crate],
0177                                 RCtau[crate],
0178                                 RC[crate + 9],
0179                                 RCof[crate + 9],
0180                                 RCtau[crate + 9],
0181                                 dataString);
0182 
0183       // Write regions

0184       m_file << dataString;
0185     }
0186   }
0187 
0188   // Force write to file

0189   m_file << flush;
0190 
0191   m_nevt++;
0192 }