Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 #include <algorithm>
0003 #include "DataFormats/L1THGCal/interface/HGCalCluster.h"
0004 #include "DataFormats/L1THGCal/interface/HGCalMulticluster.h"
0005 #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
0006 #include "L1Trigger/L1THGCalUtilities/interface/HGCalTriggerNtupleBase.h"
0007 #include "L1Trigger/L1THGCal/interface/HGCalTriggerTools.h"
0008 
0009 class HGCalTriggerNtupleHGCClusters : public HGCalTriggerNtupleBase {
0010 public:
0011   HGCalTriggerNtupleHGCClusters(const edm::ParameterSet& conf);
0012   ~HGCalTriggerNtupleHGCClusters() override{};
0013   void initialize(TTree&, const edm::ParameterSet&, edm::ConsumesCollector&&) final;
0014   void fill(const edm::Event& e, const HGCalTriggerNtupleEventSetup& es) final;
0015 
0016 private:
0017   void clear() final;
0018 
0019   bool filter_clusters_in_multiclusters_;
0020   edm::EDGetToken clusters_token_, multiclusters_token_;
0021   HGCalTriggerTools triggerTools_;
0022 
0023   int cl_n_;
0024   std::vector<uint32_t> cl_id_;
0025   std::vector<float> cl_mipPt_;
0026   std::vector<float> cl_pt_;
0027   std::vector<float> cl_energy_;
0028   std::vector<float> cl_eta_;
0029   std::vector<float> cl_phi_;
0030   std::vector<int> cl_layer_;
0031   std::vector<int> cl_subdet_;
0032   std::vector<int> cl_cells_n_;
0033   std::vector<std::vector<uint32_t>> cl_cells_id_;
0034   std::vector<uint32_t> cl_multicluster_id_;
0035   std::vector<float> cl_multicluster_pt_;
0036 };
0037 
0038 DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleHGCClusters, "HGCalTriggerNtupleHGCClusters");
0039 
0040 HGCalTriggerNtupleHGCClusters::HGCalTriggerNtupleHGCClusters(const edm::ParameterSet& conf)
0041     : HGCalTriggerNtupleBase(conf),
0042       filter_clusters_in_multiclusters_(conf.getParameter<bool>("FilterClustersInMulticlusters")) {
0043   accessEventSetup_ = false;
0044 }
0045 
0046 void HGCalTriggerNtupleHGCClusters::initialize(TTree& tree,
0047                                                const edm::ParameterSet& conf,
0048                                                edm::ConsumesCollector&& collector) {
0049   clusters_token_ = collector.consumes<l1t::HGCalClusterBxCollection>(conf.getParameter<edm::InputTag>("Clusters"));
0050   multiclusters_token_ =
0051       collector.consumes<l1t::HGCalMulticlusterBxCollection>(conf.getParameter<edm::InputTag>("Multiclusters"));
0052 
0053   std::string prefix(conf.getUntrackedParameter<std::string>("Prefix", "cl"));
0054 
0055   std::string bname;
0056   auto withPrefix([&prefix, &bname](char const* vname) -> char const* {
0057     bname = prefix + "_" + vname;
0058     return bname.c_str();
0059   });
0060 
0061   // note: can't use withPrefix() twice within a same statement because bname gets overwritten
0062   tree.Branch(withPrefix("n"), &cl_n_, (prefix + "_n/I").c_str());
0063   tree.Branch(withPrefix("id"), &cl_id_);
0064   tree.Branch(withPrefix("mipPt"), &cl_mipPt_);
0065   tree.Branch(withPrefix("pt"), &cl_pt_);
0066   tree.Branch(withPrefix("energy"), &cl_energy_);
0067   tree.Branch(withPrefix("eta"), &cl_eta_);
0068   tree.Branch(withPrefix("phi"), &cl_phi_);
0069   tree.Branch(withPrefix("layer"), &cl_layer_);
0070   tree.Branch(withPrefix("subdet"), &cl_subdet_);
0071   tree.Branch(withPrefix("cells_n"), &cl_cells_n_);
0072   tree.Branch(withPrefix("cells_id"), &cl_cells_id_);
0073   tree.Branch(withPrefix("multicluster_id"), &cl_multicluster_id_);
0074   tree.Branch(withPrefix("multicluster_pt"), &cl_multicluster_pt_);
0075 }
0076 
0077 void HGCalTriggerNtupleHGCClusters::fill(const edm::Event& e, const HGCalTriggerNtupleEventSetup& es) {
0078   // retrieve clusters
0079   edm::Handle<l1t::HGCalClusterBxCollection> clusters_h;
0080   e.getByToken(clusters_token_, clusters_h);
0081   const l1t::HGCalClusterBxCollection& clusters = *clusters_h;
0082   edm::Handle<l1t::HGCalMulticlusterBxCollection> multiclusters_h;
0083   e.getByToken(multiclusters_token_, multiclusters_h);
0084   const l1t::HGCalMulticlusterBxCollection& multiclusters = *multiclusters_h;
0085 
0086   triggerTools_.setGeometry(es.geometry.product());
0087 
0088   // Associate cells to clusters
0089   std::unordered_map<uint32_t, l1t::HGCalMulticlusterBxCollection::const_iterator> cluster2multicluster;
0090   for (auto mcl_itr = multiclusters.begin(0); mcl_itr != multiclusters.end(0); mcl_itr++) {
0091     // loop on 2D clusters inside 3D clusters
0092     for (const auto& cl_ptr : mcl_itr->constituents()) {
0093       cluster2multicluster.emplace(cl_ptr.second->detId(), mcl_itr);
0094     }
0095   }
0096 
0097   clear();
0098   for (auto cl_itr = clusters.begin(0); cl_itr != clusters.end(0); cl_itr++) {
0099     auto mcl_itr = cluster2multicluster.find(cl_itr->detId());
0100     uint32_t mcl_id = (mcl_itr != cluster2multicluster.end() ? mcl_itr->second->detId() : 0);
0101     float mcl_pt = (mcl_itr != cluster2multicluster.end() ? mcl_itr->second->pt() : 0.);
0102     if (filter_clusters_in_multiclusters_ && mcl_id == 0)
0103       continue;
0104     cl_n_++;
0105     cl_mipPt_.emplace_back(cl_itr->mipPt());
0106     // physical values
0107     cl_pt_.emplace_back(cl_itr->pt());
0108     cl_energy_.emplace_back(cl_itr->energy());
0109     cl_eta_.emplace_back(cl_itr->eta());
0110     cl_phi_.emplace_back(cl_itr->phi());
0111 
0112     cl_id_.emplace_back(cl_itr->detId());
0113     cl_layer_.emplace_back(triggerTools_.layerWithOffset(cl_itr->detId()));
0114     cl_subdet_.emplace_back(cl_itr->subdetId());
0115     cl_cells_n_.emplace_back(cl_itr->constituents().size());
0116     // Retrieve indices of trigger cells inside cluster
0117     cl_cells_id_.emplace_back(cl_itr->constituents().size());
0118     std::transform(
0119         cl_itr->constituents_begin(),
0120         cl_itr->constituents_end(),
0121         cl_cells_id_.back().begin(),
0122         [](const std::pair<uint32_t, edm::Ptr<l1t::HGCalTriggerCell>>& id_tc) { return id_tc.second->detId(); });
0123     cl_multicluster_id_.emplace_back(mcl_id);
0124     cl_multicluster_pt_.emplace_back(mcl_pt);
0125   }
0126 }
0127 
0128 void HGCalTriggerNtupleHGCClusters::clear() {
0129   cl_n_ = 0;
0130   cl_id_.clear();
0131   cl_mipPt_.clear();
0132   cl_pt_.clear();
0133   cl_energy_.clear();
0134   cl_eta_.clear();
0135   cl_phi_.clear();
0136   cl_layer_.clear();
0137   cl_subdet_.clear();
0138   cl_cells_n_.clear();
0139   cl_cells_id_.clear();
0140   cl_multicluster_id_.clear();
0141   cl_multicluster_pt_.clear();
0142 }