Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1TMuonCaloSumProducer
0004 // Class:      L1TMuonCaloSumProducer
0005 //
0006 /**\class L1TMuonCaloSumProducer L1TMuonCaloSumProducer.cc L1Trigger/L1TGlobalMuon/plugins/L1TMuonCaloSumProducer.cc
0007 
0008  Description: takes generated muons and fills them in the expected collections for the MicroGMT
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Joschka Philip Lingemann,40 3-B01,+41227671598,
0015 //         Created:  Thu Oct  3 10:12:30 CEST 2013
0016 // $Id$
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 #include <fstream>
0023 
0024 // user include files
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/Framework/interface/stream/EDProducer.h"
0027 
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/Utilities/interface/Exception.h"
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034 
0035 #include "DataFormats/L1TMuon/interface/MuonCaloSumFwd.h"
0036 #include "DataFormats/L1TMuon/interface/MuonCaloSum.h"
0037 #include "DataFormats/L1TCalorimeter/interface/CaloTower.h"
0038 
0039 #include "TMath.h"
0040 #include "TRandom3.h"
0041 
0042 //
0043 // class declaration
0044 //
0045 using namespace l1t;
0046 
0047 class L1TMuonCaloSumProducer : public edm::stream::EDProducer<> {
0048 public:
0049   explicit L1TMuonCaloSumProducer(const edm::ParameterSet&);
0050 
0051   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0052 
0053 private:
0054   void produce(edm::Event&, const edm::EventSetup&) override;
0055 
0056   edm::EDGetTokenT<CaloTowerBxCollection> m_caloTowerToken;
0057   edm::InputTag m_caloLabel;
0058 };
0059 
0060 //
0061 // constants, enums and typedefs
0062 //
0063 
0064 //
0065 // static data member definitions
0066 //
0067 
0068 //
0069 // constructors and destructor
0070 //
0071 L1TMuonCaloSumProducer::L1TMuonCaloSumProducer(const edm::ParameterSet& iConfig) {
0072   //register your inputs:
0073   m_caloLabel = iConfig.getParameter<edm::InputTag>("caloStage2Layer2Label");
0074   m_caloTowerToken = consumes<CaloTowerBxCollection>(m_caloLabel);
0075   //register your products
0076   produces<MuonCaloSumBxCollection>("TriggerTowerSums");
0077   produces<MuonCaloSumBxCollection>("TriggerTower2x2s");
0078 }
0079 
0080 //
0081 // member functions
0082 //
0083 
0084 // ------------ method called to produce the data  ------------
0085 void L1TMuonCaloSumProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0086   using namespace edm;
0087   std::unique_ptr<MuonCaloSumBxCollection> towerSums(std::make_unique<MuonCaloSumBxCollection>());
0088   std::unique_ptr<MuonCaloSumBxCollection> tower2x2s(std::make_unique<MuonCaloSumBxCollection>());
0089 
0090   edm::Handle<CaloTowerBxCollection> caloTowers;
0091 
0092   if (iEvent.getByToken(m_caloTowerToken, caloTowers)) {
0093     int detamax = 4;
0094     int dphimax = 4;
0095 
0096     const int iFirstBx = caloTowers->getFirstBX();
0097     const int iLastBx = caloTowers->getLastBX();
0098 
0099     // set BX range for sums
0100     towerSums->setBXRange(iFirstBx, iLastBx);
0101     tower2x2s->setBXRange(iFirstBx, iLastBx);
0102 
0103     for (int bx = iFirstBx; bx <= iLastBx; ++bx) {
0104       std::map<int, MuonCaloSum> sums;
0105       std::map<int, MuonCaloSum> regs;
0106 
0107       for (auto it = caloTowers->begin(bx); it != caloTowers->end(bx); ++it) {
0108         const CaloTower& twr = *it;
0109         int hwEta = twr.hwEta();
0110         if (std::abs(hwEta) > 27) {
0111           continue;
0112         }
0113         int hwPt = twr.hwPt();
0114         if (hwPt < 1) {
0115           continue;
0116         }
0117         int hwPhi = twr.hwPhi();
0118 
0119         // calculating tower2x2s
0120         int ieta2x2 = (hwEta + 27) / 2;
0121         int iphi2x2 = hwPhi / 2;
0122         int muon_idx = iphi2x2 * 28 + ieta2x2;
0123         if (regs.count(muon_idx) == 0) {
0124           regs[muon_idx] = MuonCaloSum(hwPt, iphi2x2, ieta2x2, muon_idx);
0125         } else {
0126           regs.at(muon_idx).setEtBits(regs.at(muon_idx).etBits() + hwPt);
0127         }
0128 
0129         // std::cout << "iphi; phi " << hwPhi << "; " << phi << " .. ieta; eta" << hwEta << "; " << twr.eta() << std::endl;
0130 
0131         // calculating towerSums
0132         int ietamax = hwEta + detamax + 1;
0133         for (int ieta = hwEta - detamax; ieta < ietamax; ++ieta) {
0134           if (std::abs(ieta) > 27) {
0135             continue;
0136           }
0137           int ietamu = (ieta + 27) / 2;
0138           int iphimax = hwPhi + dphimax + 1;
0139           for (int iphi = hwPhi - dphimax; iphi < iphimax; ++iphi) {
0140             int iphiwrapped = iphi;
0141             if (iphiwrapped < 0) {
0142               iphiwrapped += 72;
0143             } else if (iphiwrapped > 71) {
0144               iphiwrapped -= 72;
0145             }
0146             int iphimu = iphiwrapped / 2;
0147             int idxmu = iphimu * 28 + ietamu;
0148             if (sums.count(idxmu) == 0) {
0149               sums[idxmu] = MuonCaloSum(hwPt, iphimu, ietamu, idxmu);
0150             } else {
0151               sums.at(idxmu).setEtBits(sums.at(idxmu).etBits() + hwPt);
0152             }
0153           }
0154         }
0155       }
0156 
0157       // fill towerSums output collection for this BX
0158       for (auto it = sums.begin(); it != sums.end(); ++it) {
0159         if (it->second.etBits() > 0) {
0160           MuonCaloSum sum = MuonCaloSum(it->second);
0161           // convert Et to correct scale:
0162           if (sum.etBits() > 31) {
0163             sum.setEtBits(31);
0164           }
0165           towerSums->push_back(bx, sum);
0166         }
0167       }
0168       // fill tower2x2s output collection for this BX
0169       for (auto it = regs.begin(); it != regs.end(); ++it) {
0170         if (it->second.etBits() > 0) {
0171           tower2x2s->push_back(bx, it->second);
0172         }
0173       }
0174     }
0175   } else {
0176     LogWarning("GlobalMuon") << "CaloTowers not found. Producing empty collections." << std::endl;
0177   }
0178 
0179   iEvent.put(std::move(towerSums), "TriggerTowerSums");
0180   iEvent.put(std::move(tower2x2s), "TriggerTower2x2s");
0181 }
0182 
0183 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0184 void L1TMuonCaloSumProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0185   //The following says we do not know what parameters are allowed so do no validation
0186   // Please change this to state exactly what you do use, even if it is no parameters
0187   edm::ParameterSetDescription desc;
0188   desc.setUnknown();
0189   descriptions.addDefault(desc);
0190 }
0191 
0192 //define this as a plug-in
0193 DEFINE_FWK_MODULE(L1TMuonCaloSumProducer);