Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "L1Trigger/GlobalCaloTrigger/test/gctTestUsingLhcData.h"
0002 
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 #include "FWCore/Utilities/interface/InputTag.h"
0005 
0006 #include "FWCore/Framework/interface/Event.h"
0007 
0008 #include "DataFormats/Common/interface/Handle.h"
0009 
0010 #include "DataFormats/L1CaloTrigger/interface/L1CaloRegion.h"
0011 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctCollections.h"
0012 
0013 #include "L1Trigger/GlobalCaloTrigger/interface/L1GlobalCaloTrigger.h"
0014 
0015 #include <iostream>
0016 
0017 gctTestUsingLhcData::gctTestUsingLhcData() {}
0018 gctTestUsingLhcData::~gctTestUsingLhcData() {}
0019 
0020 // Read the region Et values for a single event from a text file and prepare them to be loaded into the GCT
0021 std::vector<L1CaloRegion> gctTestUsingLhcData::loadEvent(const edm::Event& iEvent, const int16_t bx) {
0022   std::vector<L1CaloRegion> result;
0023 
0024   edm::InputTag inputDataTag("l1GctHwDigis");
0025 
0026   edm::Handle<std::vector<L1CaloRegion> > inputRegions;
0027   iEvent.getByLabel(inputDataTag, inputRegions);
0028 
0029   for (std::vector<L1CaloRegion>::const_iterator reg = inputRegions->begin(); reg != inputRegions->end(); reg++) {
0030     if (reg->bx() == bx)
0031       result.push_back(*reg);
0032   }
0033   return result;
0034 }
0035 
0036 void gctTestUsingLhcData::checkHwResults(const L1GlobalCaloTrigger* gct, const edm::Event& iEvent) {
0037   edm::InputTag hwTag("l1GctHwDigis");
0038   bool passed = checkResults(gct, iEvent, hwTag);
0039   std::cout << "Check against hardware results " << (passed ? "ok" : "FAILED") << std::endl;
0040 }
0041 
0042 void gctTestUsingLhcData::checkEmResults(const L1GlobalCaloTrigger* gct, const edm::Event& iEvent) {
0043   edm::InputTag emTag("valGctDigis");
0044   bool passed = checkResults(gct, iEvent, emTag);
0045   std::cout << "Check against emulator results " << (passed ? "ok" : "FAILED") << std::endl;
0046 }
0047 
0048 bool gctTestUsingLhcData::checkResults(const L1GlobalCaloTrigger* gct,
0049                                        const edm::Event& iEvent,
0050                                        const edm::InputTag tag) {
0051   bool checkPassed = true;
0052   checkPassed &= checkJets(gct, iEvent, tag);
0053   checkPassed &= checkEtSums(gct, iEvent, tag);
0054   checkPassed &= checkHtSums(gct, iEvent, tag);
0055   return checkPassed;
0056 }
0057 
0058 bool gctTestUsingLhcData::checkJets(const L1GlobalCaloTrigger* gct, const edm::Event& iEvent, const edm::InputTag tag) {
0059   edm::InputTag cenJetsTag(tag.label(), "cenJets");
0060   edm::Handle<L1GctJetCandCollection> cenJetsColl;
0061   iEvent.getByLabel(cenJetsTag, cenJetsColl);
0062 
0063   edm::InputTag tauJetsTag(tag.label(), "tauJets");
0064   edm::Handle<L1GctJetCandCollection> tauJetsColl;
0065   iEvent.getByLabel(tauJetsTag, tauJetsColl);
0066 
0067   edm::InputTag forJetsTag(tag.label(), "forJets");
0068   edm::Handle<L1GctJetCandCollection> forJetsColl;
0069   iEvent.getByLabel(forJetsTag, forJetsColl);
0070 
0071   bool match = true;
0072 
0073   match &= (cenJetsColl->size() == gct->getCentralJets().size());
0074   match &= (tauJetsColl->size() == gct->getTauJets().size());
0075   match &= (forJetsColl->size() == gct->getForwardJets().size());
0076 
0077   if (match) {
0078     L1GctJetCandCollection::const_iterator j1, j2;
0079     L1GctJetCandCollection jetsFromThisGct;
0080 
0081     jetsFromThisGct = gct->getCentralJets();
0082     for (j1 = cenJetsColl->begin(), j2 = jetsFromThisGct.begin();
0083          j1 != cenJetsColl->end() && j2 != jetsFromThisGct.end();
0084          j1++, j2++) {
0085       if ((*j1) != (*j2)) {
0086         std::cout << "Jet mismatch; read from file: " << *j1 << "\nFrom this gct: " << *j2 << std::endl;
0087         match = false;
0088       }
0089     }
0090 
0091     jetsFromThisGct = gct->getTauJets();
0092     for (j1 = tauJetsColl->begin(), j2 = jetsFromThisGct.begin();
0093          j1 != tauJetsColl->end() && j2 != jetsFromThisGct.end();
0094          j1++, j2++) {
0095       if ((*j1) != (*j2)) {
0096         std::cout << "Jet mismatch; read from file: " << *j1 << "\nFrom this gct: " << *j2 << std::endl;
0097         match = false;
0098       }
0099     }
0100 
0101     jetsFromThisGct = gct->getForwardJets();
0102     for (j1 = forJetsColl->begin(), j2 = jetsFromThisGct.begin();
0103          j1 != forJetsColl->end() && j2 != jetsFromThisGct.end();
0104          j1++, j2++) {
0105       if ((*j1) != (*j2)) {
0106         std::cout << "Jet mismatch; read from file: " << *j1 << "\nFrom this gct: " << *j2 << std::endl;
0107         match = false;
0108       }
0109     }
0110 
0111   } else {
0112     std::cout << "Jet array size check failed!" << std::endl;
0113   }
0114   if (!match)
0115     std::cout << "Jet match checks FAILED" << std::endl;
0116   return match;
0117 }
0118 
0119 bool gctTestUsingLhcData::checkEtSums(const L1GlobalCaloTrigger* gct,
0120                                       const edm::Event& iEvent,
0121                                       const edm::InputTag tag) {
0122   edm::Handle<L1GctEtTotalCollection> ETTColl;
0123   iEvent.getByLabel(tag, ETTColl);
0124 
0125   edm::Handle<L1GctEtMissCollection> ETMColl;
0126   iEvent.getByLabel(tag, ETMColl);
0127 
0128   L1GctEtTotalCollection ETTFromThisGct = gct->getEtSumCollection();
0129   L1GctEtMissCollection ETMFromThisGct = gct->getEtMissCollection();
0130 
0131   L1GctEtTotalCollection::const_iterator ett1, ett2;
0132   L1GctEtMissCollection::const_iterator etm1, etm2;
0133 
0134   bool match = true;
0135   for (ett1 = ETTColl->begin(), ett2 = ETTFromThisGct.begin(); ett1 != ETTColl->end() && ett2 != ETTFromThisGct.end();
0136        ett1++, ett2++) {
0137     match &= ((*ett1) == (*ett2));
0138   }
0139   for (etm1 = ETMColl->begin(), etm2 = ETMFromThisGct.begin(); etm1 != ETMColl->end() && etm2 != ETMFromThisGct.end();
0140        etm1++, etm2++) {
0141     match &= ((*etm1) == (*etm2));
0142   }
0143   if (!match)
0144     std::cout << "Et sum match checks FAILED" << std::endl;
0145   return match;
0146 }
0147 
0148 bool gctTestUsingLhcData::checkHtSums(const L1GlobalCaloTrigger* gct,
0149                                       const edm::Event& iEvent,
0150                                       const edm::InputTag tag) {
0151   edm::Handle<L1GctEtHadCollection> HTTColl;
0152   iEvent.getByLabel(tag, HTTColl);
0153 
0154   edm::Handle<L1GctHtMissCollection> HTMColl;
0155   iEvent.getByLabel(tag, HTMColl);
0156 
0157   L1GctEtHadCollection HTTFromThisGct = gct->getEtHadCollection();
0158   L1GctHtMissCollection HTMFromThisGct = gct->getHtMissCollection();
0159 
0160   L1GctEtHadCollection::const_iterator htt1, htt2;
0161   L1GctHtMissCollection::const_iterator htm1, htm2;
0162 
0163   bool match = true;
0164   for (htt1 = HTTColl->begin(), htt2 = HTTFromThisGct.begin(); htt1 != HTTColl->end() && htt2 != HTTFromThisGct.end();
0165        htt1++, htt2++) {
0166     match &= ((*htt1) == (*htt2));
0167     if ((*htt1) != (*htt2)) {
0168       std::cout << "HTT from file " << *htt1 << "\nHTT from gct  " << *htt2 << std::endl;
0169     }
0170   }
0171   for (htm1 = HTMColl->begin(), htm2 = HTMFromThisGct.begin(); htm1 != HTMColl->end() && htm2 != HTMFromThisGct.end();
0172        htm1++, htm2++) {
0173     match &= ((*htm1) == (*htm2));
0174     if ((*htm1) != (*htm2)) {
0175       std::cout << "HTM from file " << *htm1 << "\nHTM from gct  " << *htm2 << std::endl;
0176     }
0177   }
0178   if (!match)
0179     std::cout << "Ht sum match checks FAILED" << std::endl;
0180   return match;
0181 }