Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <iostream>
0002 #include "L1Trigger/GlobalCaloTrigger/test/L1GctTest.h"
0003 
0004 #include "L1Trigger/GlobalCaloTrigger/test/gctTestFunctions.h"
0005 
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 
0008 // Trigger configuration includes
0009 #include "CondFormats/L1TObjects/interface/L1GctJetFinderParams.h"
0010 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
0011 #include "CondFormats/L1TObjects/interface/L1GctChannelMask.h"
0012 #include "CondFormats/DataRecord/interface/L1GctJetFinderParamsRcd.h"
0013 #include "CondFormats/DataRecord/interface/L1JetEtScaleRcd.h"
0014 #include "CondFormats/DataRecord/interface/L1HtMissScaleRcd.h"
0015 #include "CondFormats/DataRecord/interface/L1HtMissScaleRcd.h"
0016 #include "CondFormats/DataRecord/interface/L1HfRingEtScaleRcd.h"
0017 #include "CondFormats/DataRecord/interface/L1GctChannelMaskRcd.h"
0018 
0019 // GCT include files
0020 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetEtCalibrationLut.h"
0021 #include "L1Trigger/GlobalCaloTrigger/interface/L1GlobalCaloTrigger.h"
0022 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctGlobalEnergyAlgos.h"
0023 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctHtMissLut.h"
0024 
0025 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
0026 
0027 //
0028 // constants, enums and typedefs
0029 //
0030 
0031 //
0032 // static data member definitions
0033 //
0034 
0035 //
0036 // constructors and destructor
0037 //
0038 L1GctTest::L1GctTest(const edm::ParameterSet& iConfig)
0039     : theElectronTestIsEnabled(iConfig.getUntrackedParameter<bool>("doElectrons", false)),
0040       theSingleEventTestIsEnabled(iConfig.getUntrackedParameter<bool>("doSingleEvent", false)),
0041       theEnergyAlgosTestIsEnabled(iConfig.getUntrackedParameter<bool>("doEnergyAlgos", false)),
0042       theFirmwareTestIsEnabled(iConfig.getUntrackedParameter<bool>("doFirmware", false)),
0043       theRealDataTestIsEnabled(iConfig.getUntrackedParameter<bool>("doRealData", false)),
0044       theUseNewTauAlgoFlag(iConfig.getUntrackedParameter<bool>("useNewTauAlgo", false)),
0045       theConfigParamsPrintFlag(iConfig.getUntrackedParameter<bool>("printConfig", false)),
0046       theInputDataFileName(iConfig.getUntrackedParameter<std::string>("inputFile", "")),
0047       theReferenceDataFileName(iConfig.getUntrackedParameter<std::string>("referenceFile", "")),
0048       theEnergySumsDataFileName(iConfig.getUntrackedParameter<std::string>("energySumsFile", "")),
0049       m_firstBx(-iConfig.getParameter<unsigned>("preSamples")),
0050       m_lastBx(iConfig.getParameter<unsigned>("postSamples")),
0051       m_eventNo(0),
0052       m_allGood(true) {
0053   //now do what ever initialization is needed
0054   // check the files are specified if required
0055   if (theElectronTestIsEnabled && theInputDataFileName == "") {
0056     throw cms::Exception("L1GctTestInitialisationError")
0057         << "no input filename provided for electron tests.\n"
0058         << "Specify non-blank parameter inputFile in cmsRun configuration\n";
0059   }
0060   if (theFirmwareTestIsEnabled && theInputDataFileName == "") {
0061     throw cms::Exception("L1GctTestInitialisationError")
0062         << "no input filename provided for firmware tests.\n"
0063         << "Specify non-blank parameter inputFile in cmsRun configuration\n";
0064   }
0065   if (theSingleEventTestIsEnabled && theInputDataFileName == "") {
0066     throw cms::Exception("L1GctTestInitialisationError")
0067         << "no input filename provided for single event tests.\n"
0068         << "Specify non-blank parameter inputFile in cmsRun configuration\n";
0069   }
0070   if (theFirmwareTestIsEnabled && theReferenceDataFileName == "") {
0071     throw cms::Exception("L1GctTestInitialisationError")
0072         << "no reference filename provided for firmware tests.\n"
0073         << "Specify non-blank parameter referenceFile in cmsRun configuration\n";
0074   }
0075 
0076   m_jfParsToken = esConsumes();
0077   m_chanMaskToken = esConsumes();
0078   m_etScaleToken = esConsumes();
0079   m_htMissScaleToken = esConsumes();
0080   m_hfRingEtScaleToken = esConsumes();
0081 }
0082 
0083 L1GctTest::~L1GctTest() {
0084   // do anything here that needs to be done at desctruction time
0085   // (e.g. close files, deallocate resources etc.)
0086   delete m_gct;
0087 }
0088 
0089 //
0090 // member functions
0091 //
0092 
0093 // ------------ method called to for each event  ------------
0094 void L1GctTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0095   using namespace edm;
0096 
0097   bool endOfFile = false;
0098 
0099   configureGct(iSetup);
0100   L1GctJetFinderParams const& jfPars = iSetup.getData(m_jfParsToken);
0101   L1GctChannelMask const& chanMask = iSetup.getData(m_chanMaskToken);
0102   L1CaloEtScale const& etScale = iSetup.getData(m_etScaleToken);
0103   L1CaloEtScale const& htMissScale = iSetup.getData(m_htMissScaleToken);
0104   L1CaloEtScale const& hfRingEtScale = iSetup.getData(m_hfRingEtScaleToken);
0105   m_tester->configure(jfPars, chanMask, etScale, htMissScale, hfRingEtScale);
0106 
0107   m_gct->setupTauAlgo(theUseNewTauAlgoFlag, false);
0108   if (theConfigParamsPrintFlag)
0109     configParamsPrint(std::cout);
0110 
0111   // Initialise the gct
0112   m_gct->reset();
0113   m_tester->reset();
0114 
0115   for (int bx = m_firstBx; bx <= m_lastBx; bx++) {
0116     // Load data into the gct according to the tests to be carried out
0117     if (theElectronTestIsEnabled) {
0118       m_tester->loadNextEvent(m_gct, theInputDataFileName, bx);
0119     }
0120 
0121     if (theEnergyAlgosTestIsEnabled) {
0122       m_tester->loadNextEvent(m_gct, (100 > m_eventNo), bx);
0123     }
0124 
0125     if (theFirmwareTestIsEnabled) {
0126       m_tester->loadNextEvent(m_gct, theInputDataFileName, endOfFile, bx);
0127       if (endOfFile)
0128         break;
0129     }
0130 
0131     if (theRealDataTestIsEnabled) {
0132       m_tester->loadNextEvent(m_gct, iEvent, bx);
0133     }
0134 
0135     if (theSingleEventTestIsEnabled) {
0136       m_tester->loadSingleEvent(m_gct, theInputDataFileName, bx);
0137     }
0138   }
0139 
0140   // Run the gct emulator on the input data
0141   m_gct->process();
0142 
0143   bool passAllTests = true;
0144 
0145   // Check the results of the emulator
0146   if (theElectronTestIsEnabled) {
0147     m_tester->fillElectronData(m_gct);
0148     passAllTests &= m_tester->checkElectrons(m_gct);
0149   }
0150 
0151   if (theFirmwareTestIsEnabled && !endOfFile) {
0152     m_tester->fillJetsFromFirmware(theReferenceDataFileName);
0153     passAllTests &= m_tester->checkJetFinder(m_gct);
0154     passAllTests &= m_tester->checkEnergySumsFromFirmware(m_gct, theEnergySumsDataFileName);
0155   }
0156 
0157   if (theEnergyAlgosTestIsEnabled || theSingleEventTestIsEnabled || theRealDataTestIsEnabled ||
0158       (theFirmwareTestIsEnabled && !endOfFile)) {
0159     m_tester->fillRawJetData(m_gct);
0160     passAllTests &= m_tester->checkEnergySums(m_gct);
0161     passAllTests &= m_tester->checkHtSums(m_gct);
0162     passAllTests &= m_tester->checkHfEtSums(m_gct);
0163   }
0164 
0165   if (theRealDataTestIsEnabled) {
0166     m_tester->checkHwResults(m_gct, iEvent);
0167     m_tester->checkEmResults(m_gct, iEvent);
0168   }
0169 
0170   m_eventNo++;
0171   if (theFirmwareTestIsEnabled && endOfFile) {
0172     edm::LogInfo("L1GctTest") << "Reached the end of input file after " << m_eventNo << " events\n";
0173   }
0174   theFirmwareTestIsEnabled &= !endOfFile;
0175 
0176   // bale out if we fail any test
0177   m_allGood &= passAllTests;
0178   if (passAllTests) {
0179     //edm::LogInfo("L1GctTest") << "All tests passed for this event!" << std::endl;
0180   } else {
0181     throw cms::Exception("L1GctTestError") << "\ntest failed\n\n";
0182   }
0183 }
0184 
0185 // ------------ method called once each job just before starting event loop  ------------
0186 void L1GctTest::beginJob() {
0187   // instantiate the GCT
0188   m_gct = new L1GlobalCaloTrigger(L1GctJetLeafCard::hardwareJetFinder);
0189   m_tester = std::make_unique<gctTestFunctions>();
0190 
0191   // Fill the jetEtCalibLuts vector
0192   lutPtr nextLut(new L1GctJetEtCalibrationLut());
0193 
0194   for (unsigned ieta = 0; ieta < L1GctJetFinderBase::COL_OFFSET; ieta++) {
0195     nextLut->setEtaBin(ieta);
0196     m_jetEtCalibLuts.push_back(nextLut);
0197     nextLut.reset(new L1GctJetEtCalibrationLut());
0198   }
0199 }
0200 
0201 // ------------ method called once each job just after ending the event loop  ------------
0202 void L1GctTest::endJob() {
0203   if (m_allGood) {
0204     edm::LogInfo("L1GctTest") << "\n\n=== All tests passed Ok! ===\n\n" << std::endl;
0205   } else {
0206     edm::LogInfo("L1GctTest") << "\n\n=== Tests unsuccessful, exiting after " << m_eventNo << " events ===\n\n"
0207                               << std::endl;
0208   }
0209 }
0210 
0211 void L1GctTest::configureGct(const edm::EventSetup& c) {
0212   // get data from EventSetup
0213 
0214   L1GctJetFinderParams const& jfPars = c.getData(m_jfParsToken);
0215   L1GctChannelMask const& chanMask = c.getData(m_chanMaskToken);
0216   L1CaloEtScale const& etScale = c.getData(m_etScaleToken);
0217   L1CaloEtScale const& htMissScale = c.getData(m_htMissScaleToken);
0218   L1CaloEtScale const& hfRingEtScale = c.getData(m_hfRingEtScaleToken);
0219 
0220   m_gct->setJetFinderParams(&jfPars);
0221 
0222   // tell the jet Et Luts about the scales
0223   for (unsigned ieta = 0; ieta < m_jetEtCalibLuts.size(); ieta++) {
0224     m_jetEtCalibLuts.at(ieta)->setFunction(&jfPars);
0225     m_jetEtCalibLuts.at(ieta)->setOutputEtScale(&etScale);
0226   }
0227 
0228   // pass all the setup info to the gct
0229   m_gct->setJetEtCalibrationLuts(m_jetEtCalibLuts);
0230   m_gct->setJetFinderParams(&jfPars);
0231   m_gct->setHtMissScale(&htMissScale);
0232   m_gct->setupHfSumLuts(&hfRingEtScale);
0233   m_gct->setChannelMask(&chanMask);
0234 }
0235 
0236 void L1GctTest::configParamsPrint(std::ostream& out) {
0237   out << "Printing configuration parameters" << std::endl;
0238   out << *m_gct->getJetFinderParams();
0239   out << "LSB for region Et is " << m_gct->getJetFinderParams()->getRgnEtLsbGeV() << "; LSB for Ht is "
0240       << m_gct->getJetFinderParams()->getHtLsbGeV() << std::endl;
0241   out << "Jet seed is " << m_gct->getJetFinderParams()->getCenJetEtSeedGeV() << " GeV; or "
0242       << m_gct->getJetFinderParams()->getCenJetEtSeedGct() << " GCT units" << std::endl;
0243   out << "Tau isolation threshold is " << m_gct->getJetFinderParams()->getTauIsoEtThresholdGeV() << " GeV; or "
0244       << m_gct->getJetFinderParams()->getTauIsoEtThresholdGct() << " GCT units" << std::endl;
0245   out << "Jet threshold for HTT is " << m_gct->getJetFinderParams()->getHtJetEtThresholdGeV() << " GeV; or "
0246       << m_gct->getJetFinderParams()->getHtJetEtThresholdGct() << " GCT units" << std::endl;
0247   out << "Jet threshold for HTM is " << m_gct->getJetFinderParams()->getMHtJetEtThresholdGeV() << " GeV; or "
0248       << m_gct->getJetFinderParams()->getMHtJetEtThresholdGct() << " GCT units" << std::endl;
0249   out << "HtMiss Lut details: " << *m_gct->getEnergyFinalStage()->getHtMissLut()->etScale() << std::endl;
0250 }