Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:18

0001 // L1TCaloUpgradeToGCTConverter.cc
0002 // Authors: Ivan Cali
0003 //          R. Alex Barbieri
0004 
0005 // Stage 1 upgrade to old GT format converter
0006 // Assumes input collections are sorted, but not truncated.
0007 
0008 // In the 'gct' eta coordinates the HF is 0-3 and 18-21. Jets which
0009 // include any energy at all from the HF should be considered
0010 // 'forward' jets, however, so jets with centers in 0-4 and 17-21 are
0011 // considered 'forward'.
0012 
0013 #include "L1Trigger/L1TCalorimeter/plugins/L1TCaloUpgradeToGCTConverter.h"
0014 #include <memory>
0015 
0016 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
0017 #include "CondFormats/DataRecord/interface/L1JetEtScaleRcd.h"
0018 #include "CondFormats/DataRecord/interface/L1EmEtScaleRcd.h"
0019 
0020 using namespace std;
0021 using namespace edm;
0022 using namespace l1t;
0023 
0024 L1TCaloUpgradeToGCTConverter::L1TCaloUpgradeToGCTConverter(const ParameterSet& iConfig)
0025     :  // register what you consume and keep token for later access:
0026       EGammaToken_(consumes<EGammaBxCollection>(iConfig.getParameter<InputTag>("InputCollection"))),
0027       RlxTauToken_(consumes<TauBxCollection>(iConfig.getParameter<InputTag>("InputRlxTauCollection"))),
0028       IsoTauToken_(consumes<TauBxCollection>(iConfig.getParameter<InputTag>("InputIsoTauCollection"))),
0029       JetToken_(consumes<JetBxCollection>(iConfig.getParameter<InputTag>("InputCollection"))),
0030       EtSumToken_(consumes<EtSumBxCollection>(iConfig.getParameter<InputTag>("InputCollection"))),
0031       HfSumsToken_(consumes<CaloSpareBxCollection>(iConfig.getParameter<edm::InputTag>("InputHFSumsCollection"))),
0032       HfCountsToken_(consumes<CaloSpareBxCollection>(iConfig.getParameter<edm::InputTag>("InputHFCountsCollection"))),
0033       bxMin_(iConfig.getParameter<int>("bxMin")),
0034       bxMax_(iConfig.getParameter<int>("bxMax")) {
0035   produces<L1GctEmCandCollection>("isoEm");
0036   produces<L1GctEmCandCollection>("nonIsoEm");
0037   produces<L1GctJetCandCollection>("cenJets");
0038   produces<L1GctJetCandCollection>("forJets");
0039   produces<L1GctJetCandCollection>("tauJets");
0040   produces<L1GctJetCandCollection>("isoTauJets");
0041   produces<L1GctInternJetDataCollection>();
0042   produces<L1GctEtTotalCollection>();
0043   produces<L1GctEtHadCollection>();
0044   produces<L1GctEtMissCollection>();
0045   produces<L1GctHtMissCollection>();
0046   produces<L1GctInternEtSumCollection>();
0047   produces<L1GctInternHtMissCollection>();
0048   produces<L1GctHFBitCountsCollection>();
0049   produces<L1GctHFRingEtSumsCollection>();
0050 }
0051 
0052 // ------------ method called to produce the data ------------
0053 void L1TCaloUpgradeToGCTConverter::produce(StreamID, Event& e, const EventSetup& es) const {
0054   LogDebug("l1t|stage 1 Converter") << "L1TCaloUpgradeToGCTConverter::produce function called...\n";
0055 
0056   //inputs
0057   Handle<EGammaBxCollection> EGamma;
0058   e.getByToken(EGammaToken_, EGamma);
0059 
0060   Handle<TauBxCollection> RlxTau;
0061   e.getByToken(RlxTauToken_, RlxTau);
0062 
0063   Handle<TauBxCollection> IsoTau;
0064   e.getByToken(IsoTauToken_, IsoTau);
0065 
0066   Handle<JetBxCollection> Jet;
0067   e.getByToken(JetToken_, Jet);
0068 
0069   Handle<EtSumBxCollection> EtSum;
0070   e.getByToken(EtSumToken_, EtSum);
0071 
0072   Handle<CaloSpareBxCollection> HfSums;
0073   e.getByToken(HfSumsToken_, HfSums);
0074 
0075   Handle<CaloSpareBxCollection> HfCounts;
0076   e.getByToken(HfCountsToken_, HfCounts);
0077 
0078   // create the em and jet collections
0079   std::unique_ptr<L1GctEmCandCollection> isoEmResult(new L1GctEmCandCollection());
0080   std::unique_ptr<L1GctEmCandCollection> nonIsoEmResult(new L1GctEmCandCollection());
0081   std::unique_ptr<L1GctJetCandCollection> cenJetResult(new L1GctJetCandCollection());
0082   std::unique_ptr<L1GctJetCandCollection> forJetResult(new L1GctJetCandCollection());
0083   std::unique_ptr<L1GctJetCandCollection> tauJetResult(new L1GctJetCandCollection());
0084   std::unique_ptr<L1GctJetCandCollection> isoTauJetResult(new L1GctJetCandCollection());
0085 
0086   // create the energy sum digis
0087   std::unique_ptr<L1GctEtTotalCollection> etTotResult(new L1GctEtTotalCollection());
0088   std::unique_ptr<L1GctEtHadCollection> etHadResult(new L1GctEtHadCollection());
0089   std::unique_ptr<L1GctEtMissCollection> etMissResult(new L1GctEtMissCollection());
0090   std::unique_ptr<L1GctHtMissCollection> htMissResult(new L1GctHtMissCollection());
0091 
0092   // create the Hf sums digis
0093   std::unique_ptr<L1GctHFBitCountsCollection> hfBitCountResult(new L1GctHFBitCountsCollection());
0094   std::unique_ptr<L1GctHFRingEtSumsCollection> hfRingEtSumResult(new L1GctHFRingEtSumsCollection());
0095 
0096   // create internal data collections
0097   std::unique_ptr<L1GctInternJetDataCollection> internalJetResult(new L1GctInternJetDataCollection());
0098   std::unique_ptr<L1GctInternEtSumCollection> internalEtSumResult(new L1GctInternEtSumCollection());
0099   std::unique_ptr<L1GctInternHtMissCollection> internalHtMissResult(new L1GctInternHtMissCollection());
0100 
0101   int bxCounter = 0;
0102 
0103   for (int itBX = EGamma->getFirstBX(); itBX <= EGamma->getLastBX(); ++itBX) {
0104     if (itBX < bxMin_)
0105       continue;
0106     if (itBX > bxMax_)
0107       continue;
0108 
0109     bxCounter++;
0110 
0111     //looping over EGamma elments with a specific BX
0112     int nonIsoCount = 0;
0113     int isoCount = 0;
0114     for (EGammaBxCollection::const_iterator itEGamma = EGamma->begin(itBX); itEGamma != EGamma->end(itBX); ++itEGamma) {
0115       bool iso = itEGamma->hwIso();
0116 
0117       L1GctEmCand EmCand(itEGamma->hwPt(), itEGamma->hwPhi(), itEGamma->hwEta(), iso, 0, 0, itBX);
0118       //L1GctEmCand(unsigned rank, unsigned phi, unsigned eta,
0119       //                 bool iso, uint16_t block, uint16_t index, int16_t bx);
0120 
0121       if (iso) {
0122         if (isoCount != 4) {
0123           isoEmResult->push_back(EmCand);
0124           isoCount++;
0125         }
0126       } else {
0127         if (nonIsoCount != 4) {
0128           nonIsoEmResult->push_back(EmCand);
0129           nonIsoCount++;
0130         }
0131       }
0132     }
0133     isoEmResult->resize(4 * bxCounter);
0134     nonIsoEmResult->resize(4 * bxCounter);
0135   }
0136 
0137   bxCounter = 0;
0138   for (int itBX = RlxTau->getFirstBX(); itBX <= RlxTau->getLastBX(); ++itBX) {
0139     if (itBX < bxMin_)
0140       continue;
0141     if (itBX > bxMax_)
0142       continue;
0143 
0144     bxCounter++;
0145     //looping over Tau elments with a specific BX
0146     int tauCount = 0;  //max 4
0147     for (TauBxCollection::const_iterator itTau = RlxTau->begin(itBX); itTau != RlxTau->end(itBX); ++itTau) {
0148       // taus are not allowed to be forward
0149       const bool forward = false;
0150 
0151       L1GctJetCand TauCand(itTau->hwPt(), itTau->hwPhi(), itTau->hwEta(), true, forward, 0, 0, itBX);
0152       //L1GctJetCand(unsigned rank, unsigned phi, unsigned eta,
0153       //             bool isTau, bool isFor, uint16_t block, uint16_t index, int16_t bx);
0154       if (tauCount != 4) {
0155         tauJetResult->push_back(TauCand);
0156         tauCount++;
0157       }
0158     }
0159     tauJetResult->resize(4 * bxCounter);
0160   }
0161 
0162   bxCounter = 0;
0163   for (int itBX = IsoTau->getFirstBX(); itBX <= IsoTau->getLastBX(); ++itBX) {
0164     if (itBX < bxMin_)
0165       continue;
0166     if (itBX > bxMax_)
0167       continue;
0168 
0169     bxCounter++;
0170     //looping over Iso Tau elments with a specific BX
0171     int isoTauCount = 0;  //max 4
0172     for (TauBxCollection::const_iterator itTau = IsoTau->begin(itBX); itTau != IsoTau->end(itBX); ++itTau) {
0173       // taus are not allowed to be forward
0174       const bool forward = false;
0175 
0176       L1GctJetCand TauCand(itTau->hwPt(), itTau->hwPhi(), itTau->hwEta(), true, forward, 0, 0, itBX);
0177       //L1GctJetCand(unsigned rank, unsigned phi, unsigned eta,
0178       //             bool isTau, bool isFor, uint16_t block, uint16_t index, int16_t bx);
0179       if (isoTauCount != 4) {
0180         isoTauJetResult->push_back(TauCand);
0181         isoTauCount++;
0182       }
0183     }
0184     isoTauJetResult->resize(4 * bxCounter);
0185   }
0186 
0187   bxCounter = 0;
0188   for (int itBX = Jet->getFirstBX(); itBX <= Jet->getLastBX(); ++itBX) {
0189     if (itBX < bxMin_)
0190       continue;
0191     if (itBX > bxMax_)
0192       continue;
0193 
0194     bxCounter++;
0195     //looping over Jet elments with a specific BX
0196     int forCount = 0;  //max 4
0197     int cenCount = 0;  //max 4
0198     for (JetBxCollection::const_iterator itJet = Jet->begin(itBX); itJet != Jet->end(itBX); ++itJet) {
0199       // use 2nd quality bit to define forward
0200       const bool forward = ((itJet->hwQual() & 0x2) != 0);
0201       L1GctJetCand JetCand(itJet->hwPt(), itJet->hwPhi(), itJet->hwEta(), false, forward, 0, 0, itBX);
0202       //L1GctJetCand(unsigned rank, unsigned phi, unsigned eta,
0203       //             bool isTau, bool isFor, uint16_t block, uint16_t index, int16_t bx);
0204       if (forward) {
0205         if (forCount != 4) {
0206           forJetResult->push_back(JetCand);
0207           forCount++;
0208         }
0209       } else {
0210         if (cenCount != 4) {
0211           cenJetResult->push_back(JetCand);
0212           cenCount++;
0213         }
0214       }
0215     }
0216     forJetResult->resize(4 * bxCounter);
0217     cenJetResult->resize(4 * bxCounter);
0218   }
0219 
0220   bxCounter = 0;
0221   for (int itBX = EtSum->getFirstBX(); itBX <= EtSum->getLastBX(); ++itBX) {
0222     if (itBX < bxMin_)
0223       continue;
0224     if (itBX > bxMax_)
0225       continue;
0226 
0227     bxCounter++;
0228     //looping over EtSum elments with a specific BX
0229     for (EtSumBxCollection::const_iterator itEtSum = EtSum->begin(itBX); itEtSum != EtSum->end(itBX); ++itEtSum) {
0230       if (EtSum::EtSumType::kMissingEt == itEtSum->getType()) {
0231         L1GctEtMiss Cand(itEtSum->hwPt(), itEtSum->hwPhi(), itEtSum->hwQual() & 0x1, itBX);
0232         etMissResult->push_back(Cand);
0233       } else if (EtSum::EtSumType::kMissingHt == itEtSum->getType()) {
0234         L1GctHtMiss Cand(itEtSum->hwPt(), itEtSum->hwPhi(), itEtSum->hwQual() & 0x1, itBX);
0235         htMissResult->push_back(Cand);
0236       } else if (EtSum::EtSumType::kTotalEt == itEtSum->getType()) {
0237         L1GctEtTotal Cand(itEtSum->hwPt(), itEtSum->hwQual() & 0x1, itBX);
0238         etTotResult->push_back(Cand);
0239       } else if (EtSum::EtSumType::kTotalHt == itEtSum->getType()) {
0240         L1GctEtHad Cand(itEtSum->hwPt(), itEtSum->hwQual() & 0x1, itBX);
0241         etHadResult->push_back(Cand);
0242       } else {
0243         LogError("l1t|stage 1 Converter") << " Unknown EtSumType --- EtSum collection will not be saved...\n ";
0244       }
0245     }
0246     etMissResult->resize(1 * bxCounter);
0247     htMissResult->resize(1 * bxCounter);
0248     etTotResult->resize(1 * bxCounter);
0249     etHadResult->resize(1 * bxCounter);
0250   }
0251 
0252   bxCounter = 0;
0253   for (int itBX = HfSums->getFirstBX(); itBX <= HfSums->getLastBX(); ++itBX) {
0254     if (itBX < bxMin_)
0255       continue;
0256     if (itBX > bxMax_)
0257       continue;
0258 
0259     bxCounter++;
0260     L1GctHFRingEtSums sum = L1GctHFRingEtSums::fromGctEmulator(itBX, 0, 0, 0, 0);
0261     for (CaloSpareBxCollection::const_iterator itCaloSpare = HfSums->begin(itBX); itCaloSpare != HfSums->end(itBX);
0262          ++itCaloSpare) {
0263       // if (CaloSpare::CaloSpareType::V2 == itCaloSpare->getType())
0264       // {
0265       //    sum.setEtSum(3, itCaloSpare->hwPt());
0266       // } else if (CaloSpare::CaloSpareType::Centrality == itCaloSpare->getType())
0267       // {
0268       //    sum.setEtSum(0, itCaloSpare->hwPt());
0269       // } else if (CaloSpare::CaloSpareType::Tau == itCaloSpare->getType())
0270       // {
0271       //    sum.setEtSum(0, itCaloSpare->hwPt() & 0x7);
0272       //    sum.setEtSum(1, (itCaloSpare->hwPt() >> 3) & 0x7);
0273       //    sum.setEtSum(2, (itCaloSpare->hwPt() >> 6) & 0x7);
0274       //    sum.setEtSum(3, (itCaloSpare->hwPt() >> 9) & 0x7);
0275       // }
0276       for (int i = 0; i < 4; i++) {
0277         sum.setEtSum(i, itCaloSpare->GetRing(i));
0278       }
0279     }
0280     hfRingEtSumResult->push_back(sum);
0281 
0282     hfRingEtSumResult->resize(1 * bxCounter);
0283   }
0284 
0285   bxCounter = 0;
0286   for (int itBX = HfCounts->getFirstBX(); itBX <= HfCounts->getLastBX(); ++itBX) {
0287     if (itBX < bxMin_)
0288       continue;
0289     if (itBX > bxMax_)
0290       continue;
0291 
0292     bxCounter++;
0293     L1GctHFBitCounts count = L1GctHFBitCounts::fromGctEmulator(itBX, 0, 0, 0, 0);
0294     for (CaloSpareBxCollection::const_iterator itCaloSpare = HfCounts->begin(itBX); itCaloSpare != HfCounts->end(itBX);
0295          ++itCaloSpare) {
0296       for (int i = 0; i < 4; i++) {
0297         count.setBitCount(i, itCaloSpare->GetRing(i));
0298       }
0299     }
0300     hfBitCountResult->push_back(count);
0301     hfBitCountResult->resize(1 * bxCounter);
0302   }
0303 
0304   e.put(std::move(isoEmResult), "isoEm");
0305   e.put(std::move(nonIsoEmResult), "nonIsoEm");
0306   e.put(std::move(cenJetResult), "cenJets");
0307   e.put(std::move(forJetResult), "forJets");
0308   e.put(std::move(tauJetResult), "tauJets");
0309   e.put(std::move(isoTauJetResult), "isoTauJets");
0310   e.put(std::move(etTotResult));
0311   e.put(std::move(etHadResult));
0312   e.put(std::move(etMissResult));
0313   e.put(std::move(htMissResult));
0314   e.put(std::move(hfBitCountResult));
0315   e.put(std::move(hfRingEtSumResult));
0316 
0317   e.put(std::move(internalJetResult));
0318   e.put(std::move(internalEtSumResult));
0319   e.put(std::move(internalHtMissResult));
0320 }
0321 
0322 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
0323 void L1TCaloUpgradeToGCTConverter::fillDescriptions(ConfigurationDescriptions& descriptions) {
0324   ParameterSetDescription desc;
0325   desc.add<int>("bxMin", 0);
0326   desc.add<int>("bxMax", 0);
0327   desc.add<edm::InputTag>("InputCollection", edm::InputTag("caloStage1Digis"));
0328   desc.add<edm::InputTag>("InputRlxTauCollection", edm::InputTag("caloStage1Digis:rlxTaus"));
0329   desc.add<edm::InputTag>("InputIsoTauCollection", edm::InputTag("caloStage1Digis:isoTaus"));
0330   desc.add<edm::InputTag>("InputHFSumsCollection", edm::InputTag("caloStage1Digis:HFRingSums"));
0331   desc.add<edm::InputTag>("InputHFCountsCollection", edm::InputTag("caloStage1Digis:HFBitCounts"));
0332   descriptions.add("L1TCaloUpgradeToGCTConverter", desc);
0333 }
0334 
0335 //define this as a plug-in
0336 DEFINE_FWK_MODULE(L1TCaloUpgradeToGCTConverter);