Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-24 01:14:46

0001 // -*- C++ -*-
0002 //
0003 // Package:    L1Trigger/L1Ntuples
0004 // Class:      L1CaloTowerTreeProducer
0005 //
0006 /**\class L1CaloTowerTreeProducer L1CaloTowerTreeProducer.cc L1TriggerDPG/L1Ntuples/src/L1CaloTowerTreeProducer.cc
0007 
0008 Description: Produce L1 Extra tree
0009 
0010 Implementation:
0011      
0012 */
0013 //
0014 // Original Author:
0015 //         Created:
0016 // $Id: L1CaloTowerTreeProducer.cc,v 1.8 2012/08/29 12:44:03 jbrooke Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // framework
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/ESHandle.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0031 
0032 // data formats
0033 #include "DataFormats/L1Trigger/interface/EGamma.h"
0034 #include "DataFormats/L1Trigger/interface/Tau.h"
0035 #include "DataFormats/L1Trigger/interface/Jet.h"
0036 #include "DataFormats/L1Trigger/interface/Muon.h"
0037 #include "DataFormats/L1Trigger/interface/EtSum.h"
0038 
0039 // cond formats
0040 #include "CalibFormats/CaloTPG/interface/CaloTPGTranscoder.h"
0041 #include "CalibFormats/CaloTPG/interface/CaloTPGRecord.h"
0042 
0043 // ROOT output stuff
0044 #include "FWCore/ServiceRegistry/interface/Service.h"
0045 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0046 #include "TTree.h"
0047 
0048 #include "L1Trigger/L1TNtuples/interface/L1AnalysisCaloTPDataFormat.h"
0049 #include "L1Trigger/L1TNtuples/interface/L1AnalysisL1CaloTowerDataFormat.h"
0050 #include "L1Trigger/L1TNtuples/interface/L1AnalysisL1CaloClusterDataFormat.h"
0051 
0052 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0053 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
0054 
0055 #include "DataFormats/L1TCalorimeter/interface/CaloTower.h"
0056 #include "DataFormats/L1TCalorimeter/interface/CaloCluster.h"
0057 
0058 //
0059 // class declaration
0060 //
0061 
0062 class L1CaloTowerTreeProducer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0063 public:
0064   explicit L1CaloTowerTreeProducer(const edm::ParameterSet&);
0065   ~L1CaloTowerTreeProducer() override = default;
0066 
0067 private:
0068   void beginJob(void) override;
0069   void analyze(const edm::Event&, const edm::EventSetup&) override;
0070   void endJob() override;
0071 
0072 public:
0073   L1Analysis::L1AnalysisCaloTPDataFormat* caloTPData_;
0074   L1Analysis::L1AnalysisL1CaloTowerDataFormat* l1CaloTowerData_;
0075   L1Analysis::L1AnalysisL1CaloClusterDataFormat* l1CaloClusterData_;
0076 
0077 private:
0078   const double ecalLSB_;
0079   const unsigned maxCaloTP_;
0080   const unsigned maxL1Tower_;
0081   const unsigned maxL1Cluster_;
0082 
0083   // EDM input tags
0084   const edm::EDGetTokenT<EcalTrigPrimDigiCollection> ecalToken_;
0085   const edm::EDGetTokenT<HcalTrigPrimDigiCollection> hcalToken_;
0086   const edm::EDGetTokenT<l1t::CaloTowerBxCollection> l1TowerToken_;
0087   const edm::ESGetToken<CaloTPGTranscoder, CaloTPGRecord> decoderToken_;
0088   edm::EDGetTokenT<l1t::CaloClusterBxCollection> l1ClusterToken_;
0089 
0090   // output file
0091   edm::Service<TFileService> fs_;
0092 
0093   // tree
0094   TTree* tree_;
0095 
0096   bool storeCaloClusters_;
0097 };
0098 
0099 L1CaloTowerTreeProducer::L1CaloTowerTreeProducer(const edm::ParameterSet& iConfig)
0100     : ecalLSB_(iConfig.getUntrackedParameter<double>("ecalLSB", 0.5)),
0101       maxCaloTP_(iConfig.getUntrackedParameter<unsigned int>("maxCaloTP", 5760)),
0102       maxL1Tower_(iConfig.getUntrackedParameter<unsigned int>("maxL1Tower", 5760)),
0103       maxL1Cluster_(iConfig.getUntrackedParameter<unsigned int>("maxL1Cluster", 5760)),
0104       ecalToken_(consumes<EcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("ecalToken"))),
0105       hcalToken_(consumes<HcalTrigPrimDigiCollection>(iConfig.getUntrackedParameter<edm::InputTag>("hcalToken"))),
0106       l1TowerToken_(consumes<l1t::CaloTowerBxCollection>(iConfig.getUntrackedParameter<edm::InputTag>("l1TowerToken"))),
0107       decoderToken_(esConsumes<CaloTPGTranscoder, CaloTPGRecord>()) {
0108   edm::InputTag clusterTag = iConfig.getUntrackedParameter<edm::InputTag>("l1ClusterToken");
0109   storeCaloClusters_ = true;
0110   if (clusterTag.label() == std::string("") or clusterTag.label() == std::string("none"))
0111     storeCaloClusters_ = false;
0112 
0113   if (clusterTag.instance() != std::string(""))
0114     l1ClusterToken_ = consumes<l1t::CaloClusterBxCollection>(clusterTag);
0115 
0116   usesResource(TFileService::kSharedResource);
0117 
0118   // set up output
0119   tree_ = fs_->make<TTree>("L1CaloTowerTree", "L1CaloTowerTree");
0120   tree_->Branch("CaloTP", "L1Analysis::L1AnalysisCaloTPDataFormat", &caloTPData_, 32000, 3);
0121   tree_->Branch("L1CaloTower", "L1Analysis::L1AnalysisL1CaloTowerDataFormat", &l1CaloTowerData_, 32000, 3);
0122 
0123   if (storeCaloClusters_)
0124     tree_->Branch("L1CaloCluster", "L1Analysis::L1AnalysisL1CaloClusterDataFormat", &l1CaloClusterData_, 32000, 3);
0125 
0126   caloTPData_ = new L1Analysis::L1AnalysisCaloTPDataFormat();
0127   l1CaloTowerData_ = new L1Analysis::L1AnalysisL1CaloTowerDataFormat();
0128   l1CaloClusterData_ = new L1Analysis::L1AnalysisL1CaloClusterDataFormat();
0129 }
0130 
0131 //
0132 // member functions
0133 //
0134 
0135 // ------------ method called to for each event  ------------
0136 void L1CaloTowerTreeProducer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0137   // do calo towers
0138   caloTPData_->Reset();
0139 
0140   edm::ESHandle<CaloTPGTranscoder> decoder;
0141   decoder = iSetup.getHandle(decoderToken_);
0142 
0143   edm::Handle<EcalTrigPrimDigiCollection> ecalTPs;
0144   edm::Handle<HcalTrigPrimDigiCollection> hcalTPs;
0145 
0146   iEvent.getByToken(ecalToken_, ecalTPs);
0147   iEvent.getByToken(hcalToken_, hcalTPs);
0148 
0149   if (ecalTPs.isValid()) {
0150     for (const auto& itr : *(ecalTPs.product())) {
0151       short ieta = (short)itr.id().ieta();
0152       //      unsigned short absIeta = (unsigned short) abs(ieta);
0153       //      short sign = ieta/absIeta;
0154 
0155       unsigned short cal_iphi = (unsigned short)itr.id().iphi();
0156       unsigned short iphi = (72 + 18 - cal_iphi) % 72;
0157       unsigned short compEt = itr.compressedEt();
0158       double et = ecalLSB_ * compEt;
0159       unsigned short fineGrain = (unsigned short)itr.fineGrain();
0160 
0161       if (compEt > 0) {
0162         caloTPData_->ecalTPieta.push_back(ieta);
0163         caloTPData_->ecalTPCaliphi.push_back(cal_iphi);
0164         caloTPData_->ecalTPiphi.push_back(iphi);
0165         caloTPData_->ecalTPet.push_back(et);
0166         caloTPData_->ecalTPcompEt.push_back(compEt);
0167         caloTPData_->ecalTPfineGrain.push_back(fineGrain);
0168         caloTPData_->nECALTP++;
0169       }
0170     }
0171 
0172   } else {
0173     edm::LogWarning("L1TNtuple") << "ECAL TPs not found, branch will not be filled";
0174   }
0175 
0176   if (hcalTPs.isValid()) {
0177     for (auto itr : (*hcalTPs.product())) {
0178       int ver = itr.id().version();
0179       short ieta = (short)itr.id().ieta();
0180       unsigned short absIeta = (unsigned short)abs(ieta);
0181       //      short sign = ieta/absIeta;
0182 
0183       unsigned short cal_iphi = (unsigned short)itr.id().iphi();
0184       unsigned short iphi = (72 + 18 - cal_iphi) % 72;
0185 
0186       unsigned short compEt = itr.SOI_compressedEt();
0187       double et = decoder->hcaletValue(itr.id(), itr.t0());
0188 
0189       unsigned short fineGrain = (unsigned short)itr.SOI_fineGrain();
0190 
0191       if (compEt > 0 && (absIeta < 29 || ver == 1)) {
0192         caloTPData_->hcalTPieta.push_back(ieta);
0193         caloTPData_->hcalTPCaliphi.push_back(cal_iphi);
0194         caloTPData_->hcalTPiphi.push_back(iphi);
0195         caloTPData_->hcalTPet.push_back(et);
0196         caloTPData_->hcalTPcompEt.push_back(compEt);
0197         caloTPData_->hcalTPfineGrain.push_back(fineGrain);
0198         caloTPData_->nHCALTP++;
0199       }
0200     }
0201 
0202   } else {
0203     edm::LogWarning("L1TNtuple") << "HCAL TPs not found, branch will not be filled";
0204   }
0205 
0206   // do L1 towers
0207   l1CaloTowerData_->Reset();
0208 
0209   edm::Handle<l1t::CaloTowerBxCollection> l1Towers;
0210   iEvent.getByToken(l1TowerToken_, l1Towers);
0211 
0212   if (l1Towers.isValid()) {
0213     for (int ibx = l1Towers->getFirstBX(); ibx <= l1Towers->getLastBX(); ++ibx) {
0214       for (auto itr = l1Towers->begin(ibx); itr != l1Towers->end(ibx); ++itr) {
0215         if (itr->hwPt() <= 0)
0216           continue;
0217 
0218         //  l1CaloTowerData_->bx.push_back( ibx );
0219         l1CaloTowerData_->et.push_back(itr->pt());
0220         l1CaloTowerData_->eta.push_back(itr->eta());
0221         l1CaloTowerData_->phi.push_back(itr->phi());
0222         l1CaloTowerData_->iet.push_back(itr->hwPt());
0223         l1CaloTowerData_->ieta.push_back(itr->hwEta());
0224         l1CaloTowerData_->iphi.push_back(itr->hwPhi());
0225         l1CaloTowerData_->iem.push_back(itr->hwEtEm());
0226         l1CaloTowerData_->ihad.push_back(itr->hwEtHad());
0227         l1CaloTowerData_->iratio.push_back(itr->hwEtRatio());
0228         l1CaloTowerData_->iqual.push_back(itr->hwQual());
0229 
0230         l1CaloTowerData_->nTower++;
0231       }
0232     }
0233 
0234   } else {
0235     edm::LogWarning("L1TNtuple") << "L1 Calo Towerss not found, branch will not be filled";
0236   }
0237 
0238   // do L1 clusters
0239   if (storeCaloClusters_) {
0240     l1CaloClusterData_->Reset();
0241 
0242     edm::Handle<l1t::CaloClusterBxCollection> l1Clusters;
0243     if (!l1ClusterToken_.isUninitialized())
0244       iEvent.getByToken(l1ClusterToken_, l1Clusters);
0245 
0246     if (l1Clusters.isValid()) {
0247       for (int ibx = l1Clusters->getFirstBX(); ibx <= l1Clusters->getLastBX(); ++ibx) {
0248         for (auto itr = l1Clusters->begin(ibx); itr != l1Clusters->end(ibx); ++itr) {
0249           if (itr->hwPt() <= 0)
0250             continue;
0251 
0252           //    l1CaloClusterData_->bx.push_back( ibx );
0253           l1CaloClusterData_->et.push_back(itr->pt());
0254           l1CaloClusterData_->eta.push_back(itr->eta());
0255           l1CaloClusterData_->phi.push_back(itr->phi());
0256           l1CaloClusterData_->iet.push_back(itr->hwPt());
0257           l1CaloClusterData_->ieta.push_back(itr->hwEta());
0258           l1CaloClusterData_->iphi.push_back(itr->hwPhi());
0259           l1CaloClusterData_->iqual.push_back(itr->hwQual());
0260 
0261           l1CaloClusterData_->nCluster++;
0262         }
0263       }
0264 
0265     } else {
0266       edm::LogWarning("L1TNtuple") << "L1 Calo Clusters not found, branch will not be filled";
0267     }
0268   }
0269 
0270   tree_->Fill();
0271 }
0272 
0273 // ------------ method called once each job just before starting event loop  ------------
0274 void L1CaloTowerTreeProducer::beginJob(void) {}
0275 
0276 // ------------ method called once each job just after ending the event loop  ------------
0277 void L1CaloTowerTreeProducer::endJob() {}
0278 
0279 //define this as a plug-in
0280 DEFINE_FWK_MODULE(L1CaloTowerTreeProducer);