Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-15 04:27:29

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1Trigger/L1TCaloSummary
0004 // Class:      L1TCaloSummary
0005 //
0006 /**\class L1TCaloSummary L1TCaloSummary.cc L1Trigger/L1TCaloSummary/plugins/L1TCaloSummary.cc
0007 
0008    Description: The package L1Trigger/L1TCaloSummary is prepared for monitoring the CMS Layer-1 Calorimeter Trigger.
0009 
0010    Implementation:
0011    It prepares region objects and puts them in the event
0012 */
0013 //
0014 // Original Author:  Sridhara Dasu
0015 //         Created:  Sat, 14 Nov 2015 14:18:27 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/stream/EDProducer.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 
0031 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0032 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0033 
0034 #include "L1Trigger/L1TCaloLayer1/src/UCTLayer1.hh"
0035 #include "L1Trigger/L1TCaloLayer1/src/UCTCrate.hh"
0036 #include "L1Trigger/L1TCaloLayer1/src/UCTCard.hh"
0037 #include "L1Trigger/L1TCaloLayer1/src/UCTRegion.hh"
0038 #include "L1Trigger/L1TCaloLayer1/src/UCTTower.hh"
0039 #include "L1Trigger/L1TCaloLayer1/src/UCTGeometry.hh"
0040 
0041 #include "L1Trigger/L1TCaloLayer1/src/UCTObject.hh"
0042 #include "L1Trigger/L1TCaloLayer1/src/UCTSummaryCard.hh"
0043 #include "L1Trigger/L1TCaloLayer1/src/UCTGeometryExtended.hh"
0044 
0045 #include "DataFormats/L1Trigger/interface/L1EmParticle.h"
0046 #include "DataFormats/L1Trigger/interface/L1EmParticleFwd.h"
0047 #include "DataFormats/L1Trigger/interface/L1JetParticle.h"
0048 #include "DataFormats/L1Trigger/interface/L1JetParticleFwd.h"
0049 #include "DataFormats/L1Trigger/interface/L1EtMissParticle.h"
0050 #include "DataFormats/L1Trigger/interface/L1EtMissParticleFwd.h"
0051 
0052 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
0053 #include "DataFormats/L1CaloTrigger/interface/L1CaloRegion.h"
0054 
0055 #include "DataFormats/Math/interface/LorentzVector.h"
0056 
0057 #include "L1Trigger/L1TCaloLayer1/src/UCTLogging.hh"
0058 #include <bitset>
0059 
0060 using namespace l1tcalo;
0061 using namespace l1extra;
0062 using namespace std;
0063 
0064 //
0065 // class declaration
0066 //
0067 
0068 class L1TCaloSummary : public edm::stream::EDProducer<> {
0069 public:
0070   explicit L1TCaloSummary(const edm::ParameterSet&);
0071   ~L1TCaloSummary() override;
0072 
0073   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0074 
0075 private:
0076   //void beginJob() override;
0077   void produce(edm::Event&, const edm::EventSetup&) override;
0078   //void endJob() override;
0079 
0080   void beginRun(edm::Run const&, edm::EventSetup const&) override;
0081 
0082   void print();
0083 
0084   // ----------member data ---------------------------
0085 
0086   uint32_t nPumBins;
0087 
0088   std::vector<std::vector<std::vector<uint32_t>>> pumLUT;
0089 
0090   double caloScaleFactor;
0091 
0092   uint32_t jetSeed;
0093   uint32_t tauSeed;
0094   float tauIsolationFactor;
0095   uint32_t eGammaSeed;
0096   double eGammaIsolationFactor;
0097   double boostedJetPtFactor;
0098 
0099   bool verbose;
0100   int fwVersion;
0101 
0102   edm::EDGetTokenT<L1CaloRegionCollection> regionToken;
0103 
0104   UCTLayer1* layer1;
0105   UCTSummaryCard* summaryCard;
0106 };
0107 
0108 //
0109 // constants, enums and typedefs
0110 //
0111 
0112 //
0113 // static data member definitions
0114 //
0115 
0116 //
0117 // constructors and destructor
0118 //
0119 L1TCaloSummary::L1TCaloSummary(const edm::ParameterSet& iConfig)
0120     : nPumBins(iConfig.getParameter<unsigned int>("nPumBins")),
0121       pumLUT(nPumBins, std::vector<std::vector<uint32_t>>(2, std::vector<uint32_t>(13))),
0122       caloScaleFactor(iConfig.getParameter<double>("caloScaleFactor")),
0123       jetSeed(iConfig.getParameter<unsigned int>("jetSeed")),
0124       tauSeed(iConfig.getParameter<unsigned int>("tauSeed")),
0125       tauIsolationFactor(iConfig.getParameter<double>("tauIsolationFactor")),
0126       eGammaSeed(iConfig.getParameter<unsigned int>("eGammaSeed")),
0127       eGammaIsolationFactor(iConfig.getParameter<double>("eGammaIsolationFactor")),
0128       boostedJetPtFactor(iConfig.getParameter<double>("boostedJetPtFactor")),
0129       verbose(iConfig.getParameter<bool>("verbose")),
0130       fwVersion(iConfig.getParameter<int>("firmwareVersion")),
0131       regionToken(consumes<L1CaloRegionCollection>(edm::InputTag("simCaloStage2Layer1Digis"))) {
0132   std::vector<double> pumLUTData;
0133   char pumLUTString[10];
0134   for (uint32_t pumBin = 0; pumBin < nPumBins; pumBin++) {
0135     for (uint32_t side = 0; side < 2; side++) {
0136       if (side == 0)
0137         sprintf(pumLUTString, "pumLUT%2.2dp", pumBin);
0138       else
0139         sprintf(pumLUTString, "pumLUT%2.2dn", pumBin);
0140       pumLUTData = iConfig.getParameter<std::vector<double>>(pumLUTString);
0141       for (uint32_t iEta = 0; iEta < std::max((uint32_t)pumLUTData.size(), MaxUCTRegionsEta); iEta++) {
0142         pumLUT[pumBin][side][iEta] = (uint32_t)round(pumLUTData[iEta] / caloScaleFactor);
0143       }
0144       if (pumLUTData.size() != (MaxUCTRegionsEta))
0145         edm::LogError("L1TCaloSummary") << "PUM LUT Data size integrity check failed; Expected size = "
0146                                         << MaxUCTRegionsEta << "; Provided size = " << pumLUTData.size()
0147                                         << "; Will use what is provided :(" << std::endl;
0148     }
0149   }
0150   produces<L1JetParticleCollection>("Boosted");
0151   summaryCard = new UCTSummaryCard(&pumLUT, jetSeed, tauSeed, tauIsolationFactor, eGammaSeed, eGammaIsolationFactor);
0152 }
0153 
0154 L1TCaloSummary::~L1TCaloSummary() {
0155   if (summaryCard != nullptr)
0156     delete summaryCard;
0157 }
0158 
0159 //
0160 // member functions
0161 //
0162 
0163 // ------------ method called to produce the data  ------------
0164 void L1TCaloSummary::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0165   using namespace edm;
0166 
0167   std::unique_ptr<L1JetParticleCollection> bJetCands(new L1JetParticleCollection);
0168 
0169   UCTGeometry g;
0170 
0171   // Here we read region data from the region collection created by L1TCaloLayer1 instead of
0172   // independently creating regions from TPGs for processing by the summary card. This results
0173   // in a single region vector of size 252 whereas from independent creation we had 3*6 vectors
0174   // of size 7*2. Indices are mapped in UCTSummaryCard accordingly.
0175   summaryCard->clearRegions();
0176   std::vector<UCTRegion*> inputRegions;
0177   inputRegions.clear();
0178   edm::Handle<std::vector<L1CaloRegion>> regionCollection;
0179   if (!iEvent.getByToken(regionToken, regionCollection))
0180     edm::LogError("L1TCaloSummary") << "UCT: Failed to get regions from region collection!";
0181   iEvent.getByToken(regionToken, regionCollection);
0182   for (const L1CaloRegion& i : *regionCollection) {
0183     UCTRegionIndex r = g.getUCTRegionIndexFromL1CaloRegion(i.gctEta(), i.gctPhi());
0184     UCTTowerIndex t = g.getUCTTowerIndexFromL1CaloRegion(r, i.raw());
0185     uint32_t absCaloEta = std::abs(t.first);
0186     uint32_t absCaloPhi = std::abs(t.second);
0187     bool negativeEta = false;
0188     if (t.first < 0)
0189       negativeEta = true;
0190     uint32_t crate = g.getCrate(t.first, t.second);
0191     uint32_t card = g.getCard(t.first, t.second);
0192     uint32_t region = g.getRegion(absCaloEta, absCaloPhi);
0193     UCTRegion* test = new UCTRegion(crate, card, negativeEta, region, fwVersion);
0194     test->setRegionSummary(i.raw());
0195     inputRegions.push_back(test);
0196   }
0197   summaryCard->setRegionData(inputRegions);
0198 
0199   if (!summaryCard->process()) {
0200     edm::LogError("L1TCaloSummary") << "UCT: Failed to process summary card" << std::endl;
0201     exit(1);
0202   }
0203 
0204   double pt = 0;
0205   double eta = -999.;
0206   double phi = -999.;
0207   double mass = 0;
0208 
0209   std::list<UCTObject*> boostedJetObjs = summaryCard->getBoostedJetObjs();
0210   for (std::list<UCTObject*>::const_iterator i = boostedJetObjs.begin(); i != boostedJetObjs.end(); i++) {
0211     const UCTObject* object = *i;
0212     pt = ((double)object->et()) * caloScaleFactor * boostedJetPtFactor;
0213     eta = g.getUCTTowerEta(object->iEta());
0214     phi = g.getUCTTowerPhi(object->iPhi());
0215     bitset<3> activeRegionEtaPattern = 0;
0216     for (uint32_t iEta = 0; iEta < 3; iEta++) {
0217       bool activeStrip = false;
0218       for (uint32_t iPhi = 0; iPhi < 3; iPhi++) {
0219         if (object->boostedJetRegionET()[3 * iEta + iPhi] > 30 &&
0220             object->boostedJetRegionET()[3 * iEta + iPhi] > object->et() * 0.0625)
0221           activeStrip = true;
0222       }
0223       if (activeStrip)
0224         activeRegionEtaPattern |= (0x1 << iEta);
0225     }
0226     bitset<3> activeRegionPhiPattern = 0;
0227     for (uint32_t iPhi = 0; iPhi < 3; iPhi++) {
0228       bool activeStrip = false;
0229       for (uint32_t iEta = 0; iEta < 3; iEta++) {
0230         if (object->boostedJetRegionET()[3 * iEta + iPhi] > 30 &&
0231             object->boostedJetRegionET()[3 * iEta + iPhi] > object->et() * 0.0625)
0232           activeStrip = true;
0233       }
0234       if (activeStrip)
0235         activeRegionPhiPattern |= (0x1 << iPhi);
0236     }
0237     string regionEta = activeRegionEtaPattern.to_string<char, std::string::traits_type, std::string::allocator_type>();
0238     string regionPhi = activeRegionPhiPattern.to_string<char, std::string::traits_type, std::string::allocator_type>();
0239 
0240     bool centralHighest = object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[0] &&
0241                           object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[1] &&
0242                           object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[2] &&
0243                           object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[3] &&
0244                           object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[5] &&
0245                           object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[6] &&
0246                           object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[7] &&
0247                           object->boostedJetRegionET()[4] >= object->boostedJetRegionET()[8];
0248 
0249     if (abs(eta) < 2.5 && ((regionEta == "101" && (regionPhi == "110" || regionPhi == "101" || regionPhi == "010")) ||
0250                            ((regionEta == "110" || regionEta == "101" || regionEta == "010") && regionPhi == "101") ||
0251                            (regionEta == "111" && (regionPhi == "110" || regionPhi == "010")) ||
0252                            ((regionEta == "110" || regionEta == "010") && regionPhi == "111") ||
0253                            ((regionEta == "010" || regionPhi == "010" || regionEta == "110" || regionPhi == "110" ||
0254                              regionEta == "011" || regionPhi == "011") &&
0255                             centralHighest)))
0256       bJetCands->push_back(L1JetParticle(math::PtEtaPhiMLorentzVector(pt, eta, phi, mass), L1JetParticle::kCentral));
0257   }
0258 
0259   iEvent.put(std::move(bJetCands), "Boosted");
0260 }
0261 
0262 void L1TCaloSummary::print() {}
0263 
0264 // ------------ method called once each job just before starting event loop  ------------
0265 //void L1TCaloSummary::beginJob() {}
0266 
0267 // ------------ method called once each job just after ending the event loop  ------------
0268 //void L1TCaloSummary::endJob() {}
0269 
0270 // ------------ method called when starting to processes a run  ------------
0271 
0272 void L1TCaloSummary::beginRun(edm::Run const& iRun, edm::EventSetup const& iSetup) {}
0273 
0274 // ------------ method called when ending the processing of a run  ------------
0275 /*
0276   void
0277   L1TCaloSummary::endRun(edm::Run const&, edm::EventSetup const&)
0278   {
0279   }
0280 */
0281 
0282 // ------------ method called when starting to processes a luminosity block  ------------
0283 /*
0284   void
0285   L1TCaloSummary::beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0286   {
0287   }
0288 */
0289 
0290 // ------------ method called when ending the processing of a luminosity block  ------------
0291 /*
0292   void
0293   L1TCaloSummary::endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&)
0294   {
0295   }
0296 */
0297 
0298 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0299 void L1TCaloSummary::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0300   //The following says we do not know what parameters are allowed so do no validation
0301   // Please change this to state exactly what you do use, even if it is no parameters
0302   edm::ParameterSetDescription desc;
0303   desc.setUnknown();
0304   descriptions.addDefault(desc);
0305 }
0306 
0307 //define this as a plug-in
0308 DEFINE_FWK_MODULE(L1TCaloSummary);