Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-10 05:44:06

0001 #include "DataFormats/L1THGCal/interface/HGCalTower.h"
0002 #include "L1Trigger/L1THGCalUtilities/interface/HGCalTriggerNtupleBase.h"
0003 
0004 class HGCalTriggerNtupleHGCTowers : public HGCalTriggerNtupleBase {
0005 public:
0006   HGCalTriggerNtupleHGCTowers(const edm::ParameterSet& conf);
0007   ~HGCalTriggerNtupleHGCTowers() override{};
0008   void initialize(TTree&, const edm::ParameterSet&, edm::ConsumesCollector&&) final;
0009   void fill(const edm::Event& e, const HGCalTriggerNtupleEventSetup& es) final;
0010 
0011 private:
0012   void clear() final;
0013 
0014   edm::EDGetToken towers_token_;
0015 
0016   int tower_n_;
0017   std::vector<float> tower_pt_;
0018   std::vector<float> tower_energy_;
0019   std::vector<float> tower_eta_;
0020   std::vector<float> tower_phi_;
0021   std::vector<float> tower_etEm_;
0022   std::vector<float> tower_etHad_;
0023   std::vector<int> tower_iEta_;
0024   std::vector<int> tower_iPhi_;
0025 };
0026 
0027 DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleHGCTowers, "HGCalTriggerNtupleHGCTowers");
0028 
0029 HGCalTriggerNtupleHGCTowers::HGCalTriggerNtupleHGCTowers(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf) {
0030   accessEventSetup_ = false;
0031 }
0032 
0033 void HGCalTriggerNtupleHGCTowers::initialize(TTree& tree,
0034                                              const edm::ParameterSet& conf,
0035                                              edm::ConsumesCollector&& collector) {
0036   towers_token_ = collector.consumes<l1t::HGCalTowerBxCollection>(conf.getParameter<edm::InputTag>("Towers"));
0037 
0038   std::string prefix(conf.getUntrackedParameter<std::string>("Prefix", "tower"));
0039 
0040   std::string bname;
0041   auto withPrefix([&prefix, &bname](char const* vname) -> char const* {
0042     bname = prefix + "_" + vname;
0043     return bname.c_str();
0044   });
0045 
0046   tree.Branch(withPrefix("n"), &tower_n_, (prefix + "_n/I").c_str());
0047   tree.Branch(withPrefix("pt"), &tower_pt_);
0048   tree.Branch(withPrefix("energy"), &tower_energy_);
0049   tree.Branch(withPrefix("eta"), &tower_eta_);
0050   tree.Branch(withPrefix("phi"), &tower_phi_);
0051   tree.Branch(withPrefix("etEm"), &tower_etEm_);
0052   tree.Branch(withPrefix("etHad"), &tower_etHad_);
0053   tree.Branch(withPrefix("iEta"), &tower_iEta_);
0054   tree.Branch(withPrefix("iPhi"), &tower_iPhi_);
0055 }
0056 
0057 void HGCalTriggerNtupleHGCTowers::fill(const edm::Event& e, const HGCalTriggerNtupleEventSetup& es) {
0058   // retrieve towers
0059   edm::Handle<l1t::HGCalTowerBxCollection> towers_h;
0060   e.getByToken(towers_token_, towers_h);
0061   const l1t::HGCalTowerBxCollection& towers = *towers_h;
0062 
0063   clear();
0064   for (auto tower_itr = towers.begin(0); tower_itr != towers.end(0); tower_itr++) {
0065     tower_n_++;
0066     // physical values
0067     tower_pt_.emplace_back(tower_itr->pt());
0068     tower_energy_.emplace_back(tower_itr->energy());
0069     tower_eta_.emplace_back(tower_itr->eta());
0070     tower_phi_.emplace_back(tower_itr->phi());
0071     tower_etEm_.emplace_back(tower_itr->etEm());
0072     tower_etHad_.emplace_back(tower_itr->etHad());
0073 
0074     tower_iEta_.emplace_back(tower_itr->id().iEta());
0075     tower_iPhi_.emplace_back(tower_itr->id().iPhi());
0076   }
0077 }
0078 
0079 void HGCalTriggerNtupleHGCTowers::clear() {
0080   tower_n_ = 0;
0081   tower_pt_.clear();
0082   tower_energy_.clear();
0083   tower_eta_.clear();
0084   tower_phi_.clear();
0085   tower_etEm_.clear();
0086   tower_etHad_.clear();
0087   tower_iEta_.clear();
0088   tower_iPhi_.clear();
0089 }