Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1Trigger/L1TCalorimeter
0004 // Class:      L1TCaloRCTToUpgradeConverter
0005 //
0006 /**\class l1t::L1TCaloRCTToUpgradeConverter L1TCaloRCTToUpgradeConverter.cc L1Trigger/L1TCalorimeter/plugins/L1TCaloRCTToUpgradeConverter.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  James Brooke
0015 //         Created:  Thu, 05 Dec 2013 17:39:27 GMT
0016 //
0017 //
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/Framework/interface/Frameworkfwd.h"
0020 #include "FWCore/Framework/interface/global/EDProducer.h"
0021 #include "FWCore/Framework/interface/Event.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0024 #include "FWCore/Utilities/interface/EDGetToken.h"
0025 #include "FWCore/Utilities/interface/EDPutToken.h"
0026 #include "FWCore/Utilities/interface/InputTag.h"
0027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0028 
0029 #include "DataFormats/L1CaloTrigger/interface/L1CaloEmCand.h"
0030 #include "DataFormats/L1CaloTrigger/interface/L1CaloRegion.h"
0031 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
0032 
0033 #include "DataFormats/L1Trigger/interface/BXVector.h"
0034 
0035 #include "DataFormats/L1TCalorimeter/interface/CaloEmCand.h"
0036 #include "DataFormats/L1TCalorimeter/interface/CaloRegion.h"
0037 
0038 #include "DataFormats/Math/interface/LorentzVector.h"
0039 
0040 #include <vector>
0041 
0042 namespace l1t {
0043 
0044   class L1TCaloRCTToUpgradeConverter : public edm::global::EDProducer<> {
0045   public:
0046     explicit L1TCaloRCTToUpgradeConverter(const edm::ParameterSet& ps);
0047 
0048     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0049 
0050   private:
0051     void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0052 
0053     // ----------member data ---------------------------
0054 
0055     edm::EDGetTokenT<L1CaloRegionCollection> const rgnToken_;
0056     edm::EDGetTokenT<L1CaloEmCollection> const emToken_;
0057 
0058     edm::EDPutTokenT<CaloRegionBxCollection> const rgnPutToken_;
0059     edm::EDPutTokenT<CaloEmCandBxCollection> const emPutToken_;
0060   };
0061 
0062 }  // namespace l1t
0063 
0064 using namespace l1t;
0065 
0066 L1TCaloRCTToUpgradeConverter::L1TCaloRCTToUpgradeConverter(const edm::ParameterSet& ps)
0067     : rgnToken_{consumes<L1CaloRegionCollection>(ps.getParameter<edm::InputTag>("regionTag"))},
0068       emToken_{consumes<L1CaloEmCollection>(ps.getParameter<edm::InputTag>("emTag"))},
0069       rgnPutToken_{produces<CaloRegionBxCollection>()},
0070       emPutToken_{produces<CaloEmCandBxCollection>()} {}
0071 
0072 // ------------ method called to produce the data  ------------
0073 void L1TCaloRCTToUpgradeConverter::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0074   // check status of RCT conditions & renew if needed
0075 
0076   // store new formats
0077   BXVector<CaloEmCand> emcands;
0078   BXVector<CaloRegion> regions;
0079 
0080   // get old formats
0081   auto const& ems = iEvent.get(emToken_);
0082   auto const& rgns = iEvent.get(rgnToken_);
0083 
0084   // get the firstBx_ and lastBx_ from the input datatypes (assume bx for em same as rgn)
0085   int firstBx = 0;
0086   int lastBx = 0;
0087   for (auto const& em : ems) {
0088     int bx = em.bx();
0089     if (bx < firstBx)
0090       firstBx = bx;
0091     if (bx > lastBx)
0092       lastBx = bx;
0093   }
0094 
0095   emcands.setBXRange(firstBx, lastBx);
0096   regions.setBXRange(firstBx, lastBx);
0097 
0098   const ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<double> > p4(0, 0, 0, 0);
0099 
0100   // loop over EM
0101   for (auto const& em : ems) {
0102     // get physical units
0103     // double pt = 0.;
0104     // double eta = 0.;
0105     // double phi = 0.;
0106     //math::PtEtaPhiMLorentzVector p4( pt+1.e-6, eta, phi, 0. );
0107 
0108     //CaloStage1Cluster cluster;
0109     CaloEmCand EmCand(p4, (int)em.rank(), (int)em.regionId().ieta(), (int)em.regionId().iphi(), (int)em.index());
0110 
0111     EmCand.setHwIso((int)em.isolated());
0112     //std::cout<<"ISO:    "<<EmCand.hwIso()<<"    "<<em.isolated()<<std::endl;
0113 
0114     // create new format
0115     emcands.push_back(em.bx(), EmCand);
0116   }
0117 
0118   // loop over regions
0119   for (auto const& rgn : rgns) {
0120     // get physical units
0121     // double pt = 0.;
0122     // double eta = 0.;
0123     // double phi = 0.;
0124     //math::PtEtaPhiMLorentzVector p4( pt+1.e-6, eta, phi, 0 );
0125 
0126     bool tauVeto = rgn.fineGrain();  //equivalent to tauVeto for HB/HE, includes extra info for HF
0127     int hwQual = (int)tauVeto;
0128 
0129     // create new format
0130     // several values here are stage 2 only, leave empty
0131     CaloRegion region(p4,                    //  LorentzVector& p4,
0132                       0.,                    //  etEm,
0133                       0.,                    //  etHad,
0134                       (int)rgn.et(),         //  pt,
0135                       (int)rgn.id().ieta(),  //  eta,
0136                       (int)rgn.id().iphi(),  //  phi,
0137                       hwQual,                //  qual,
0138                       0,                     //  hwEtEm,
0139                       0);                    //  hwEtHad
0140 
0141     // add to output
0142     regions.push_back(rgn.bx(), region);
0143   }
0144 
0145   iEvent.emplace(emPutToken_, std::move(emcands));
0146   iEvent.emplace(rgnPutToken_, std::move(regions));
0147 }
0148 
0149 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0150 void L1TCaloRCTToUpgradeConverter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0151   edm::ParameterSetDescription desc;
0152   desc.add<edm::InputTag>("regionTag");
0153   desc.add<edm::InputTag>("emTag");
0154   descriptions.addDefault(desc);
0155 }
0156 
0157 //define this as a plug-in
0158 DEFINE_FWK_MODULE(L1TCaloRCTToUpgradeConverter);