Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-19 05:14:13

0001 // Producer for the CaloSummary cards emulator
0002 // Author: Andrew Loeliger
0003 // Presumably the L1TNtuple Format is going to last very long with the advent of L1NanoAOD,
0004 // But as of now, this is the only way to get CICADA into official menu studying tools
0005 
0006 #include <memory>
0007 
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 
0016 #include "FWCore/ServiceRegistry/interface/Service.h"
0017 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0018 #include "TTree.h"
0019 
0020 #include "L1Trigger/L1TNtuples/interface/L1AnalysisCaloSummaryDataFormat.h"
0021 
0022 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
0023 #include "DataFormats/L1CaloTrigger/interface/L1CaloRegion.h"
0024 #include "DataFormats/L1CaloTrigger/interface/CICADA.h"
0025 
0026 class L1CaloSummaryTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0027 public:
0028   explicit L1CaloSummaryTreeProducer(const edm::ParameterSet&);
0029   ~L1CaloSummaryTreeProducer() override;
0030 
0031 private:
0032   void beginJob() override {}
0033   void analyze(const edm::Event&, const edm::EventSetup&) override;
0034   void endJob() override {}
0035 
0036 public:
0037   L1Analysis::L1AnalysisCaloSummaryDataFormat* caloSummaryData_;
0038 
0039 private:
0040   const edm::EDGetTokenT<l1t::CICADABxCollection> scoreToken_;
0041   const edm::EDGetTokenT<L1CaloRegionCollection> regionToken_;
0042   edm::Service<TFileService> fs_;
0043   TTree* tree_;
0044 };
0045 
0046 L1CaloSummaryTreeProducer::L1CaloSummaryTreeProducer(const edm::ParameterSet& iConfig)
0047     : scoreToken_(consumes<l1t::CICADABxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("scoreToken"))),
0048       regionToken_(consumes<L1CaloRegionCollection>(iConfig.getUntrackedParameter<edm::InputTag>("regionToken"))) {
0049   usesResource(TFileService::kSharedResource);
0050   tree_ = fs_->make<TTree>("L1CaloSummaryTree", "L1CaloSummaryTree");
0051   tree_->Branch("CaloSummary", "L1Analysis::L1AnalysisCaloSummaryDataFormat", &caloSummaryData_, 32000, 3);
0052 
0053   caloSummaryData_ = new L1Analysis::L1AnalysisCaloSummaryDataFormat();
0054 }
0055 
0056 void L1CaloSummaryTreeProducer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0057   caloSummaryData_->Reset();
0058 
0059   edm::Handle<L1CaloRegionCollection> regions;
0060   iEvent.getByToken(regionToken_, regions);
0061 
0062   if (regions.isValid()) {
0063     for (const auto& itr : *regions) {
0064       caloSummaryData_->modelInput[itr.gctPhi()][itr.gctEta() - 4] =
0065           itr.et();  //4 is subtracted off of the Eta to account for the 4+4 forward/backward HF regions that are not used in CICADA. These take offset the iEta by 4
0066     }
0067   } else {
0068     edm::LogWarning("L1Ntuple") << "Could not find region regions. CICADA model input will not be filled";
0069   }
0070 
0071   edm::Handle<l1t::CICADABxCollection> score;
0072   iEvent.getByToken(scoreToken_, score);
0073   if (score.isValid())
0074     caloSummaryData_->CICADAScore = score->at(0, 0);
0075   else
0076     edm::LogWarning("L1Ntuple") << "Could not find a proper CICADA score. CICADA score will not be filled.";
0077 
0078   tree_->Fill();
0079 }
0080 
0081 L1CaloSummaryTreeProducer::~L1CaloSummaryTreeProducer() { delete caloSummaryData_; }
0082 
0083 DEFINE_FWK_MODULE(L1CaloSummaryTreeProducer);