Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:23:11

0001 // -*- C++ -*-
0002 //
0003 // L1TMuonQualityAdjuster
0004 //
0005 // Fictitious module which filters/remaps TF qualities for studies
0006 //
0007 //
0008 
0009 // system include files
0010 #include <memory>
0011 #include <fstream>
0012 
0013 // user include files
0014 #include "FWCore/Framework/interface/Frameworkfwd.h"
0015 #include "FWCore/Framework/interface/stream/EDProducer.h"
0016 
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/Utilities/interface/Exception.h"
0022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0023 
0024 #include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h"
0025 #include "DataFormats/L1TMuon/interface/RegionalMuonCand.h"
0026 
0027 using namespace l1t;
0028 
0029 #include <iostream>
0030 //
0031 // class declaration
0032 //
0033 
0034 class L1TMuonQualityAdjuster : public edm::stream::EDProducer<> {
0035 public:
0036   explicit L1TMuonQualityAdjuster(const edm::ParameterSet&);
0037   ~L1TMuonQualityAdjuster() override;
0038 
0039   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0040 
0041 private:
0042   void produce(edm::Event&, const edm::EventSetup&) override;
0043   void beginRun(const edm::Run&, edm::EventSetup const&) override;
0044   void endRun(const edm::Run&, edm::EventSetup const&) override;
0045   void beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override;
0046   void endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) override;
0047   // ----------member data ---------------------------
0048   edm::EDGetTokenT<l1t::RegionalMuonCandBxCollection> m_barrelTfInputToken;
0049   edm::EDGetTokenT<l1t::RegionalMuonCandBxCollection> m_overlapTfInputToken;
0050   edm::EDGetTokenT<l1t::RegionalMuonCandBxCollection> m_endCapTfInputToken;
0051   // edm::InputTag m_barrelTfInputTag;
0052   edm::InputTag m_barrelTfInputTag;
0053   edm::InputTag m_overlapTfInputTag;
0054   edm::InputTag m_endCapTfInputTag;
0055   int m_bmtfBxOffset;  // Hack while sorting our source of -3 BX offset when re-Emulating...
0056 };
0057 
0058 //
0059 // constants, enums and typedefs
0060 //
0061 
0062 //
0063 // static data member definitions
0064 //
0065 
0066 //
0067 // constructors and destructor
0068 //
0069 L1TMuonQualityAdjuster::L1TMuonQualityAdjuster(const edm::ParameterSet& iConfig) {
0070   m_barrelTfInputTag = iConfig.getParameter<edm::InputTag>("bmtfInput");
0071   m_overlapTfInputTag = iConfig.getParameter<edm::InputTag>("omtfInput");
0072   m_endCapTfInputTag = iConfig.getParameter<edm::InputTag>("emtfInput");
0073   m_bmtfBxOffset = iConfig.getParameter<int>("bmtfBxOffset");
0074   m_barrelTfInputToken = consumes<l1t::RegionalMuonCandBxCollection>(m_barrelTfInputTag);
0075   m_overlapTfInputToken = consumes<l1t::RegionalMuonCandBxCollection>(m_overlapTfInputTag);
0076   m_endCapTfInputToken = consumes<l1t::RegionalMuonCandBxCollection>(m_endCapTfInputTag);
0077   //register your products
0078   produces<RegionalMuonCandBxCollection>("BMTF");
0079   produces<RegionalMuonCandBxCollection>("OMTF");
0080   produces<RegionalMuonCandBxCollection>("EMTF");
0081 }
0082 
0083 L1TMuonQualityAdjuster::~L1TMuonQualityAdjuster() {
0084   // do anything here that needs to be done at desctruction time
0085   // (e.g. close files, deallocate resources etc.)
0086 }
0087 
0088 //
0089 // member functions
0090 //
0091 
0092 // ------------ method called to produce the data  ------------
0093 void L1TMuonQualityAdjuster::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0094   using namespace edm;
0095 
0096   std::unique_ptr<l1t::RegionalMuonCandBxCollection> filteredBMTFMuons(new l1t::RegionalMuonCandBxCollection());
0097   std::unique_ptr<l1t::RegionalMuonCandBxCollection> filteredOMTFMuons(new l1t::RegionalMuonCandBxCollection());
0098   std::unique_ptr<l1t::RegionalMuonCandBxCollection> filteredEMTFMuons(new l1t::RegionalMuonCandBxCollection());
0099 
0100   Handle<l1t::RegionalMuonCandBxCollection> bmtfMuons;
0101   Handle<l1t::RegionalMuonCandBxCollection> omtfMuons;
0102   Handle<l1t::RegionalMuonCandBxCollection> emtfMuons;
0103 
0104   iEvent.getByToken(m_barrelTfInputToken, bmtfMuons);
0105   iEvent.getByToken(m_overlapTfInputToken, omtfMuons);
0106   iEvent.getByToken(m_endCapTfInputToken, emtfMuons);
0107 
0108   if (bmtfMuons.isValid()) {
0109     filteredBMTFMuons->setBXRange(bmtfMuons->getFirstBX(), bmtfMuons->getLastBX());
0110     for (int bx = bmtfMuons->getFirstBX(); bx <= bmtfMuons->getLastBX(); ++bx) {
0111       for (auto mu = bmtfMuons->begin(bx); mu != bmtfMuons->end(bx); ++mu) {
0112         int newqual = 12;
0113         l1t::RegionalMuonCand newMu((*mu));
0114         newMu.setHwQual(newqual);
0115         filteredBMTFMuons->push_back(bx + m_bmtfBxOffset, newMu);
0116       }
0117     }
0118   } else {
0119     //cout << "ERROR:  did not find BMTF muons in event with label:  " << m_barrelTfInputTag << "\n";
0120   }
0121 
0122   if (emtfMuons.isValid()) {
0123     filteredEMTFMuons->setBXRange(emtfMuons->getFirstBX(), emtfMuons->getLastBX());
0124     for (int bx = emtfMuons->getFirstBX(); bx <= emtfMuons->getLastBX(); ++bx) {
0125       for (auto mu = emtfMuons->begin(bx); mu != emtfMuons->end(bx); ++mu) {
0126         int newqual = 0;
0127         if (mu->hwQual() == 11 || mu->hwQual() > 12)
0128           newqual = 12;
0129         l1t::RegionalMuonCand newMu((*mu));
0130         newMu.setHwQual(newqual);
0131         filteredEMTFMuons->push_back(bx, newMu);
0132       }
0133     }
0134   } else {
0135     //cout << "ERROR:  did not find EMTF muons in event with label:  " << m_endCapTfInputTag << "\n";
0136   }
0137 
0138   if (omtfMuons.isValid()) {
0139     filteredOMTFMuons->setBXRange(omtfMuons->getFirstBX(), omtfMuons->getLastBX());
0140     for (int bx = omtfMuons->getFirstBX(); bx <= omtfMuons->getLastBX(); ++bx) {
0141       for (auto mu = omtfMuons->begin(bx); mu != omtfMuons->end(bx); ++mu) {
0142         int newqual = 0;
0143         if (mu->hwQual() > 0)
0144           newqual = 12;
0145         l1t::RegionalMuonCand newMu((*mu));
0146         newMu.setHwQual(newqual);
0147         filteredOMTFMuons->push_back(bx, newMu);
0148       }
0149     }
0150   } else {
0151     //cout << "ERROR:  did not find OMTF muons in event with label:  " << m_overlapTfInputTag << "\n";
0152   }
0153 
0154   //cout << "Size BMTF(-3):  " << filteredBMTFMuons->size(-3) << "\n";
0155   //cout << "Size BMTF:  " << filteredBMTFMuons->size(0) << "\n";
0156   //cout << "Size OMTF:  " << filteredOMTFMuons->size(0) << "\n";
0157   //cout << "Size EMTF:  " << filteredEMTFMuons->size(0) << "\n";
0158 
0159   iEvent.put(std::move(filteredBMTFMuons), "BMTF");
0160   iEvent.put(std::move(filteredOMTFMuons), "OMTF");
0161   iEvent.put(std::move(filteredEMTFMuons), "EMTF");
0162 }
0163 
0164 // ------------ method called when starting to processes a run  ------------
0165 void L1TMuonQualityAdjuster::beginRun(const edm::Run&, edm::EventSetup const&) {}
0166 
0167 // ------------ method called when ending the processing of a run  ------------
0168 void L1TMuonQualityAdjuster::endRun(const edm::Run&, edm::EventSetup const&) {}
0169 
0170 // ------------ method called when starting to processes a luminosity block  ------------
0171 void L1TMuonQualityAdjuster::beginLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) {}
0172 
0173 // ------------ method called when ending the processing of a luminosity block  ------------
0174 void L1TMuonQualityAdjuster::endLuminosityBlock(const edm::LuminosityBlock&, edm::EventSetup const&) {}
0175 
0176 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0177 void L1TMuonQualityAdjuster::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0178   //The following says we do not know what parameters are allowed so do no validation
0179   // Please change this to state exactly what you do use, even if it is no parameters
0180   edm::ParameterSetDescription desc;
0181   desc.setUnknown();
0182   descriptions.addDefault(desc);
0183 }
0184 
0185 //define this as a plug-in
0186 DEFINE_FWK_MODULE(L1TMuonQualityAdjuster);