Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-13 01:32:11

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1TMuonLegacyConverter
0004 // Class:      L1TMuonLegacyConverter
0005 //
0006 /**\class L1TMuonLegacyConverter \file L1TMuonLegacyConverter.cc src/L1TMuonLegacyConverter/src/L1TMuonLegacyConverter.cc
0007 */
0008 //
0009 // Original Author:  Bortignon Pierluigi
0010 //         Created:  Sun March 6 EDT 2016
0011 //
0012 //
0013 
0014 // system include files
0015 #include <memory>
0016 
0017 // user include files
0018 #include "L1Trigger/L1TCommon/plugins/L1TMuonLegacyConverter.h"
0019 
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/MakerMacros.h"
0022 
0023 #include "DataFormats/Common/interface/Handle.h"
0024 #include "FWCore/Framework/interface/ESHandle.h"
0025 #include "DataFormats/Common/interface/OrphanHandle.h"
0026 
0027 #include "CondFormats/L1TObjects/interface/L1CaloGeometry.h"
0028 #include "CondFormats/DataRecord/interface/L1CaloGeometryRecord.h"
0029 
0030 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
0031 #include "CondFormats/DataRecord/interface/L1EmEtScaleRcd.h"
0032 #include "CondFormats/DataRecord/interface/L1JetEtScaleRcd.h"
0033 #include "CondFormats/DataRecord/interface/L1HtMissScaleRcd.h"
0034 #include "CondFormats/DataRecord/interface/L1HfRingEtScaleRcd.h"
0035 #include "CondFormats/L1TObjects/interface/L1GctJetFinderParams.h"
0036 #include "CondFormats/DataRecord/interface/L1GctJetFinderParamsRcd.h"
0037 
0038 #include "CondFormats/L1TObjects/interface/L1MuTriggerScales.h"
0039 #include "CondFormats/DataRecord/interface/L1MuTriggerScalesRcd.h"
0040 #include "CondFormats/L1TObjects/interface/L1MuTriggerPtScale.h"
0041 #include "CondFormats/DataRecord/interface/L1MuTriggerPtScaleRcd.h"
0042 
0043 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0044 
0045 // #include "FWCore/Utilities/interface/EDMException.h"
0046 
0047 //
0048 // class decleration
0049 //
0050 
0051 //
0052 // constants, enums and typedefs
0053 //
0054 using namespace l1t;
0055 
0056 //
0057 // static data member definitions
0058 //
0059 
0060 double const L1TMuonLegacyConverter::muonMassGeV_ = 0.105658369;  // PDG06
0061 
0062 //
0063 // constructors and destructor
0064 //
0065 L1TMuonLegacyConverter::L1TMuonLegacyConverter(const edm::ParameterSet& iConfig) {
0066   using namespace l1extra;
0067 
0068   // moving inputTag here
0069   muonSource_InputTag = iConfig.getParameter<edm::InputTag>("muonSource");
0070   produceMuonParticles_ = iConfig.getUntrackedParameter<bool>("produceMuonParticles");
0071   centralBxOnly_ = iConfig.getUntrackedParameter<bool>("centralBxOnly");
0072 
0073   produces<MuonBxCollection>("imdMuonsLegacy");
0074   muonSource_InputToken = consumes<L1MuGMTReadoutCollection>(muonSource_InputTag);
0075 
0076   if (produceMuonParticles_) {
0077     muScalesToken_ = esConsumes();
0078     muPtScaleToken_ = esConsumes();
0079   }
0080 }
0081 
0082 L1TMuonLegacyConverter::~L1TMuonLegacyConverter() {
0083   // do anything here that needs to be done at desctruction time
0084   // (e.g. close files, deallocate resources etc.)
0085 }
0086 
0087 //
0088 // member functions
0089 //
0090 
0091 // ------------ method called to produce the data  ------------
0092 void L1TMuonLegacyConverter::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0093   using namespace edm;
0094   using namespace l1extra;
0095   using namespace std;
0096 
0097   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0098   // ~~~~~~~~~~~~~~~~~~~~ Muons ~~~~~~~~~~~~~~~~~~~~
0099   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0100 
0101   std::unique_ptr<MuonBxCollection> imdMuonsLegacy(new MuonBxCollection());
0102 
0103   LogDebug("L1TMuonLegacyConverter") << "\nWarning: L1MuGMTReadoutCollection with " << muonSource_InputTag
0104                                      << "\nrequested in configuration, but not found in the event." << std::endl;
0105 
0106   if (produceMuonParticles_) {
0107     ESHandle<L1MuTriggerScales> muScales = iSetup.getHandle(muScalesToken_);
0108 
0109     ESHandle<L1MuTriggerPtScale> muPtScale = iSetup.getHandle(muPtScaleToken_);
0110 
0111     Handle<L1MuGMTReadoutCollection> simMuCollection;
0112     iEvent.getByToken(muonSource_InputToken, simMuCollection);
0113 
0114     vector<L1MuGMTExtendedCand> simMuCands;
0115 
0116     if (!simMuCollection.isValid()) {
0117       LogDebug("L1TMuonLegacyConverter") << "\nWarning: L1MuGMTReadoutCollection with " << muonSource_InputTag
0118                                          << "\nrequested in configuration, but not found in the event." << std::endl;
0119     } else {
0120       if (centralBxOnly_) {
0121         // Get GMT candidates from central bunch crossing only
0122         simMuCands = simMuCollection->getRecord().getGMTCands();
0123       } else {
0124         // Get GMT candidates from all bunch crossings
0125         vector<L1MuGMTReadoutRecord> records = simMuCollection->getRecords();
0126         vector<L1MuGMTReadoutRecord>::const_iterator rItr = records.begin();
0127         vector<L1MuGMTReadoutRecord>::const_iterator rEnd = records.end();
0128 
0129         for (; rItr != rEnd; ++rItr) {
0130           vector<L1MuGMTExtendedCand> tmpCands = rItr->getGMTCands();
0131 
0132           simMuCands.insert(simMuCands.end(), tmpCands.begin(), tmpCands.end());
0133         }
0134       }
0135 
0136       vector<L1MuGMTExtendedCand>::const_iterator muItr = simMuCands.begin();
0137       vector<L1MuGMTExtendedCand>::const_iterator muEnd = simMuCands.end();
0138       for (int i = 0; muItr != muEnd; ++muItr, ++i) {
0139         if (!muItr->empty()) {
0140           // keep x and y components non-zero and protect against roundoff.
0141           double pt = muPtScale->getPtScale()->getLowEdge(muItr->ptIndex()) + 1.e-6;
0142           std::cout << "pt from muPtScale = " << pt << std::endl;
0143           double eta = muScales->getGMTEtaScale()->getCenter(muItr->etaIndex());
0144           double phi = muScales->getPhiScale()->getLowEdge(muItr->phiIndex());
0145 
0146           math::PtEtaPhiMLorentzVector p4(pt, eta, phi, muonMassGeV_);
0147 
0148           Muon outMu{p4,
0149                      (int)0,
0150                      (int)0,
0151                      (int)0,
0152                      (int)muItr->quality(),
0153                      (int)muItr->charge(),
0154                      (int)muItr->charge_valid(),
0155                      (int)muItr->isol(),
0156                      (int)0,
0157                      (int)0,
0158                      true,
0159                      (int)0,
0160                      (int)0,
0161                      (int)0,
0162                      (int)muItr->rank()};
0163           imdMuonsLegacy->push_back(muItr->bx(), outMu);
0164         }
0165       }
0166     }
0167   }
0168 
0169   iEvent.put(std::move(imdMuonsLegacy), "imdMuonsLegacy");
0170 
0171 }  // closing produce
0172 
0173 //define this as a plug-in
0174 DEFINE_FWK_MODULE(L1TMuonLegacyConverter);