Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-05 23:13:00

0001 #include "L1Trigger/GlobalCaloTrigger/test/gctTestFunctions.h"
0002 
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 
0005 // Trigger configuration includes
0006 #include "CondFormats/L1TObjects/interface/L1GctJetFinderParams.h"
0007 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
0008 #include "CondFormats/L1TObjects/interface/L1GctChannelMask.h"
0009 #include "CondFormats/DataRecord/interface/L1GctJetFinderParamsRcd.h"
0010 #include "CondFormats/DataRecord/interface/L1JetEtScaleRcd.h"
0011 #include "CondFormats/DataRecord/interface/L1HtMissScaleRcd.h"
0012 #include "CondFormats/DataRecord/interface/L1HfRingEtScaleRcd.h"
0013 #include "CondFormats/DataRecord/interface/L1GctChannelMaskRcd.h"
0014 
0015 #include "L1Trigger/GlobalCaloTrigger/test/gctTestElectrons.h"
0016 #include "L1Trigger/GlobalCaloTrigger/test/gctTestSingleEvent.h"
0017 #include "L1Trigger/GlobalCaloTrigger/test/gctTestUsingLhcData.h"
0018 #include "L1Trigger/GlobalCaloTrigger/test/gctTestEnergyAlgos.h"
0019 #include "L1Trigger/GlobalCaloTrigger/test/gctTestFirmware.h"
0020 #include "L1Trigger/GlobalCaloTrigger/test/gctTestHt.h"
0021 #include "L1Trigger/GlobalCaloTrigger/test/gctTestHfEtSums.h"
0022 
0023 #include "L1Trigger/GlobalCaloTrigger/interface/L1GlobalCaloTrigger.h"
0024 
0025 //=================================================================================================================
0026 //
0027 /// Constructor and destructor
0028 
0029 gctTestFunctions::gctTestFunctions()
0030     : theElectronsTester(new gctTestElectrons()),
0031       theSingleEventTester(new gctTestSingleEvent()),
0032       theEnergyAlgosTester(new gctTestEnergyAlgos()),
0033       theFirmwareTester(new gctTestFirmware()),
0034       theRealDataTester(new gctTestUsingLhcData()),
0035       theHtTester(new gctTestHt()),
0036       theHfEtSumsTester(new gctTestHfEtSums()),
0037       m_inputEmCands(),
0038       m_inputRegions(),
0039       m_bxStart(0),
0040       m_numOfBx(1) {}
0041 
0042 gctTestFunctions::~gctTestFunctions() {
0043   delete theElectronsTester;
0044   delete theEnergyAlgosTester;
0045   delete theFirmwareTester;
0046   delete theRealDataTester;
0047   delete theHtTester;
0048   delete theHfEtSumsTester;
0049 }
0050 
0051 //=================================================================================================================
0052 //
0053 /// Configuration method
0054 void gctTestFunctions::configure(const L1GctJetFinderParams& jfPars,
0055                                  const L1GctChannelMask& chanMask,
0056                                  const L1CaloEtScale& etScale,
0057                                  const L1CaloEtScale& htMissScale,
0058                                  const L1CaloEtScale& hfRingEtScale) {
0059   // get data from EventSetup
0060   /*
0061   edm::ESHandle<L1GctJetFinderParams> jfPars;
0062   c.get<L1GctJetFinderParamsRcd>().get(jfPars);  // which record?
0063   edm::ESHandle<L1GctChannelMask> chanMask;
0064   c.get<L1GctChannelMaskRcd>().get(chanMask);  // which record?
0065   edm::ESHandle<L1CaloEtScale> etScale;
0066   c.get<L1JetEtScaleRcd>().get(etScale);  // which record?
0067   edm::ESHandle<L1CaloEtScale> htMissScale;
0068   c.get<L1HtMissScaleRcd>().get(htMissScale);  // which record?
0069   edm::ESHandle<L1CaloEtScale> hfRingEtScale;
0070   c.get<L1HfRingEtScaleRcd>().get(hfRingEtScale);  // which record?
0071   */
0072 
0073   theEnergyAlgosTester->configure(&chanMask);
0074   theHtTester->configure(&etScale, &htMissScale, &jfPars);
0075   theHfEtSumsTester->configure(&hfRingEtScale);
0076 }
0077 
0078 //=================================================================================================================
0079 //
0080 /// Clear vectors of input data
0081 void gctTestFunctions::reset() {
0082   m_inputEmCands.clear();
0083   m_inputRegions.clear();
0084   m_inputEmCands.resize(1);
0085   m_inputRegions.resize(1);
0086   m_bxStart = 0;
0087   m_numOfBx = 1;
0088 }
0089 
0090 //=================================================================================================================
0091 //
0092 /// Load another event into the gct. Overloaded for the various ways of doing this.
0093 void gctTestFunctions::loadNextEvent(L1GlobalCaloTrigger*& gct, const bool simpleEvent, const int16_t bx) {
0094   bxRangeUpdate(bx);
0095   m_inputRegions.at(bx - m_bxStart) = theEnergyAlgosTester->loadEvent(gct, simpleEvent, bx);
0096 }
0097 
0098 void gctTestFunctions::loadNextEvent(L1GlobalCaloTrigger*& gct,
0099                                      const std::string fileName,
0100                                      bool& endOfFile,
0101                                      const int16_t bx) {
0102   bxRangeUpdate(bx);
0103   std::vector<L1CaloRegion> temp = theEnergyAlgosTester->loadEvent(gct, fileName, endOfFile, bx);
0104   if (endOfFile) {
0105     reset();
0106   } else {
0107     m_inputRegions.at(bx - m_bxStart) = temp;
0108   }
0109 }
0110 
0111 void gctTestFunctions::loadNextEvent(L1GlobalCaloTrigger*& gct, const std::string fileName, const int16_t bx) {
0112   bxRangeUpdate(bx);
0113   m_inputEmCands.at(bx - m_bxStart) = theElectronsTester->loadEvent(gct, fileName, bx);
0114 }
0115 
0116 void gctTestFunctions::loadNextEvent(L1GlobalCaloTrigger*& gct, const edm::Event& iEvent, const int16_t bx) {
0117   bxRangeUpdate(bx);
0118   m_inputRegions.at(bx - m_bxStart) =
0119       theEnergyAlgosTester->loadEvent(gct, theRealDataTester->loadEvent(iEvent, bx), bx);
0120 }
0121 
0122 void gctTestFunctions::loadSingleEvent(L1GlobalCaloTrigger*& gct, const std::string fileName, const int16_t bx) {
0123   bxRangeUpdate(bx);
0124   m_inputRegions.at(bx - m_bxStart) =
0125       theEnergyAlgosTester->loadEvent(gct, theSingleEventTester->loadEvent(fileName, bx), bx);
0126 }
0127 
0128 //=================================================================================================================
0129 //
0130 /// This method is called when we are asked to process a new bunch crossing.
0131 /// It expands the range of bunch crossings if necessary to include the new one,
0132 /// by adding bunch crossings before or after the existing range.
0133 /// It also calls the corresponding methods of the various testers.
0134 void gctTestFunctions::bxRangeUpdate(const int16_t bx) {
0135   // If bxrel is negative we insert crossings before the current range, while
0136   // if it's bigger than m_numOfBx we need crossings after the current range.
0137   int bxRel = bx - m_bxStart;
0138 
0139   // Update the constants defining the range
0140   if (bxRel < 0) {
0141     m_numOfBx -= bxRel;
0142     m_bxStart = bx;
0143   }
0144   if (bxRel >= m_numOfBx) {
0145     m_numOfBx = bxRel + 1;
0146   }
0147 
0148   // Take care of inserting earlier crossings
0149   std::vector<L1CaloEmCand> tempEmc;
0150   std::vector<L1CaloRegion> tempRgn;
0151   for (int i = bxRel; i < 0; i++) {
0152     m_inputEmCands.insert(m_inputEmCands.begin(), tempEmc);
0153     m_inputRegions.insert(m_inputRegions.begin(), tempRgn);
0154   }
0155 
0156   // Take care of inserting later crossings
0157   m_inputEmCands.resize(m_numOfBx);
0158   m_inputRegions.resize(m_numOfBx);
0159 
0160   // Do the same in the testers
0161   theEnergyAlgosTester->setBxRange(m_bxStart, m_numOfBx);
0162   theHtTester->setBxRange(m_bxStart, m_numOfBx);
0163 }
0164 
0165 //=================================================================================================================
0166 //
0167 /// Read the input electron data (after GCT processing).
0168 void gctTestFunctions::fillElectronData(const L1GlobalCaloTrigger* gct) { theElectronsTester->fillElectronData(gct); }
0169 
0170 //=================================================================================================================
0171 //
0172 /// Read the firmware results from a file for the next event
0173 void gctTestFunctions::fillJetsFromFirmware(const std::string& fileName) {
0174   theFirmwareTester->fillJetsFromFirmware(fileName, m_bxStart, m_numOfBx);
0175 }
0176 
0177 //=================================================================================================================
0178 //
0179 /// Read the input jet data from the jetfinders (after GCT processing).
0180 void gctTestFunctions::fillRawJetData(const L1GlobalCaloTrigger* gct) { theHtTester->fillRawJetData(gct); }
0181 
0182 //=================================================================================================================
0183 //
0184 /// Check the electron sort
0185 bool gctTestFunctions::checkElectrons(const L1GlobalCaloTrigger* gct) const {
0186   return theElectronsTester->checkElectrons(gct, m_bxStart, m_numOfBx);
0187 }
0188 
0189 /// Check the jet finder against results from the firmware
0190 bool gctTestFunctions::checkJetFinder(const L1GlobalCaloTrigger* gct) const {
0191   return theFirmwareTester->checkJetFinder(gct);
0192 }
0193 
0194 /// Check the energy sums algorithms
0195 bool gctTestFunctions::checkEnergySums(const L1GlobalCaloTrigger* gct) const {
0196   return theEnergyAlgosTester->checkEnergySums(gct);
0197 }
0198 
0199 //=================================================================================================================
0200 //
0201 /// Check the Ht summing algorithms
0202 bool gctTestFunctions::checkHtSums(const L1GlobalCaloTrigger* gct) const { return theHtTester->checkHtSums(gct); }
0203 
0204 //=================================================================================================================
0205 //
0206 /// Check the Hf Et sums
0207 bool gctTestFunctions::checkHfEtSums(const L1GlobalCaloTrigger* gct) const {
0208   theHfEtSumsTester->reset();
0209   theHfEtSumsTester->fillExpectedHfSums(m_inputRegions);
0210   return theHfEtSumsTester->checkHfEtSums(gct, m_numOfBx);
0211 }
0212 
0213 //=================================================================================================================
0214 //
0215 /// Analyse calculation of energy sums in firmware
0216 bool gctTestFunctions::checkEnergySumsFromFirmware(const L1GlobalCaloTrigger* gct, const std::string& fileName) const {
0217   return theFirmwareTester->checkEnergySumsFromFirmware(gct, fileName, m_numOfBx);
0218 }
0219 
0220 //=================================================================================================================
0221 //
0222 /// Check against data read from hardware or a different version of the emulator
0223 void gctTestFunctions::checkHwResults(const L1GlobalCaloTrigger* gct, const edm::Event& iEvent) const {
0224   theRealDataTester->checkHwResults(gct, iEvent);
0225 }
0226 
0227 void gctTestFunctions::checkEmResults(const L1GlobalCaloTrigger* gct, const edm::Event& iEvent) const {
0228   theRealDataTester->checkEmResults(gct, iEvent);
0229 }