Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:54

0001 #include "L1Trigger/GlobalCaloTrigger/test/gctTestElectrons.h"
0002 
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 
0005 #include "L1Trigger/GlobalCaloTrigger/interface/L1GlobalCaloTrigger.h"
0006 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctElectronSorter.h"
0007 
0008 #include <fstream>  //for file IO
0009 #include <iostream>
0010 #include <sstream>  //for int->char conversion
0011 
0012 using std::cout;
0013 using std::endl;
0014 using std::string;
0015 using std::vector;
0016 
0017 //=================================================================================================================
0018 //
0019 /// Constructor and destructor
0020 
0021 gctTestElectrons::gctTestElectrons() {
0022   m_theIsoEmCandSorter = new L1GctElectronSorter(18, 0);
0023   m_nonIsoEmCandSorter = new L1GctElectronSorter(18, 1);
0024 }
0025 
0026 gctTestElectrons::~gctTestElectrons() {
0027   delete m_theIsoEmCandSorter;
0028   delete m_nonIsoEmCandSorter;
0029 }
0030 
0031 //=================================================================================================================
0032 //
0033 /// Load another event into the gct. Overloaded for the various ways of doing this.
0034 std::vector<L1CaloEmCand> gctTestElectrons::loadEvent(L1GlobalCaloTrigger*& gct,
0035                                                       const std::string fileName,
0036                                                       const int16_t bx) {
0037   m_fileNameUsed = fileName;
0038   //  gct->openSourceCardFiles(fileName);
0039   //Open the input files using the function LoadFile and send the EmCands to the gct
0040   for (int i = 0; i < 18; i++) {
0041     std::stringstream ss;
0042     string fileNo;
0043     ss << i;
0044     ss >> fileNo;
0045     LoadFileData(m_fileNameUsed + fileNo, bx);
0046   }
0047 
0048   // copy both local vectors of input candidates into a single vector
0049   std::vector<L1CaloEmCand> temp(m_theIsoEmCandsFromFileInput);
0050   temp.insert(temp.end(), m_nonIsoEmCandsFromFileInput.begin(), m_nonIsoEmCandsFromFileInput.end());
0051 
0052   // send the input candidates to the gct
0053   gct->fillEmCands(temp);
0054 
0055   return temp;
0056 }
0057 
0058 //=================================================================================================================
0059 //
0060 /// Read the input electron data (after GCT processing).
0061 void gctTestElectrons::fillElectronData(const L1GlobalCaloTrigger* gct) {
0062   m_theIsoEmCandsFromGct = gct->getIsoElectrons();
0063   m_nonIsoEmCandsFromGct = gct->getNonIsoElectrons();
0064 
0065   cout << "=========== From the GCT chain ===============" << endl;
0066   cout << "Iso electrons are: " << endl;
0067   print(m_theIsoEmCandsFromGct);
0068   cout << "Non-iso electrons are: " << endl;
0069   print(m_nonIsoEmCandsFromGct);
0070 }
0071 
0072 //=================================================================================================================
0073 //
0074 /// Repeat the sort locally and check the result
0075 bool gctTestElectrons::checkElectrons(const L1GlobalCaloTrigger* gct, const int bxStart, const int numOfBx) {
0076   bool testPass = true;
0077 
0078   // Process multiple bunch crossings
0079   m_theIsoEmCandsFromFileSorted.clear();
0080   m_nonIsoEmCandsFromFileSorted.clear();
0081 
0082   vector<L1GctEmCand>::iterator theIsoItr = m_theIsoEmCandsFromFileSorted.end();
0083   vector<L1GctEmCand>::iterator nonIsoItr = m_nonIsoEmCandsFromFileSorted.end();
0084 
0085   int16_t bx = bxStart;
0086   for (int i = 0; i < numOfBx; i++) {
0087     //Open the input files using the function LoadFile and sort them and see if same output is returned
0088     for (int i = 0; i < 18; i++) {
0089       std::stringstream ss;
0090       string fileNo;
0091       ss << i;
0092       ss >> fileNo;
0093       LoadFileData(m_fileNameUsed + fileNo, bx);
0094     }
0095 
0096     std::cout << "Filling sorters" << std::endl;
0097     for (unsigned int i = 0; i != 72; i++) {
0098       m_theIsoEmCandSorter->setInputEmCand(m_theIsoEmCandsFromFileInput[i]);
0099       m_nonIsoEmCandSorter->setInputEmCand(m_nonIsoEmCandsFromFileInput[i]);
0100     }
0101     m_theIsoEmCandSorter->process();
0102     m_nonIsoEmCandSorter->process();
0103 
0104     m_theIsoEmCandsFromFileSorted.insert(
0105         theIsoItr, m_theIsoEmCandSorter->getOutputCands().begin(), m_theIsoEmCandSorter->getOutputCands().end());
0106     m_nonIsoEmCandsFromFileSorted.insert(
0107         nonIsoItr, m_nonIsoEmCandSorter->getOutputCands().begin(), m_nonIsoEmCandSorter->getOutputCands().end());
0108 
0109     bx++;
0110   }
0111 
0112   cout << "=================From files externally sorted=============" << endl;
0113   cout << "Iso electrons are:" << endl;
0114   print(m_theIsoEmCandsFromFileSorted);
0115   cout << "Non-iso electrons are:" << endl;
0116   print(m_nonIsoEmCandsFromFileSorted);
0117 
0118   testPass &= m_theIsoEmCandsFromFileSorted == m_theIsoEmCandsFromGct;
0119   testPass &= m_nonIsoEmCandsFromFileSorted == m_nonIsoEmCandsFromGct;
0120 
0121   return testPass;
0122 }
0123 
0124 /// PRIVATE MEMBER FUNCTIONS
0125 // Function definition of function that reads in dummy data and load it into inputCands vector
0126 void gctTestElectrons::LoadFileData(const string& inputFile, const int16_t bx) {
0127   using namespace std;
0128 
0129   ifstream file;
0130 
0131   //Opens the file
0132   file.open(inputFile.c_str(), ios::in);
0133 
0134   if (!file) {
0135     throw cms::Exception("ErrorOpenFile") << "Cannot open input data file" << endl;
0136   }
0137 
0138   unsigned candRank = 0, candRegion = 0, candCard = 0, candCrate = 0;
0139   short dummy;
0140   string bxNo = "poels";
0141   bool candIso = false;
0142 
0143   //Reads in first crossing, then crossing no
0144   //then 8 electrons, 4 first is iso, next non iso.
0145   //The 3x14 jet stuff and 8 mip and quiet bits are skipped over.
0146 
0147   file >> bxNo;
0148   file >> std::dec >> dummy;
0149   for (int i = 0; i < 58; i++) {  //Loops over one bunch-crossing
0150     if (i < 8) {
0151       file >> std::hex >> dummy;
0152       candRank = dummy & 0x3f;
0153       candRegion = (dummy >> 6) & 0x1;
0154       candCard = (dummy >> 7) & 0x7;
0155       candIso = (i >= 4);
0156       L1CaloEmCand electron(candRank, candRegion, candCard, candCrate, candIso);
0157       electron.setBx(bx);
0158       if (candIso) {
0159         m_theIsoEmCandsFromFileInput.push_back(electron);
0160       } else {
0161         m_nonIsoEmCandsFromFileInput.push_back(electron);
0162       }
0163     } else {
0164       file >> std::hex >> dummy;
0165     }
0166   }
0167   file.close();
0168 
0169   return;
0170 }
0171 
0172 void gctTestElectrons::print(const vector<L1GctEmCand> cands) const {
0173   for (unsigned int i = 0; i != cands.size(); i++) {
0174     cout << "          Rank: " << cands[i].rank() << "  Eta: " << cands[i].etaIndex()
0175          << "  Phi: " << cands[i].phiIndex() << endl;
0176   }
0177   return;
0178 }