Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0003 #include "DataFormats/L1THGCal/interface/HGCalTriggerSums.h"
0004 #include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
0005 #include "DataFormats/Common/interface/AssociationMap.h"
0006 #include "DataFormats/ForwardDetId/interface/HGCalTriggerDetId.h"
0007 #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
0008 #include "L1Trigger/L1THGCalUtilities/interface/HGCalTriggerNtupleBase.h"
0009 #include "L1Trigger/L1THGCal/interface/HGCalTriggerTools.h"
0010 
0011 class HGCalTriggerNtupleHGCTriggerSums : public HGCalTriggerNtupleBase {
0012 public:
0013   HGCalTriggerNtupleHGCTriggerSums(const edm::ParameterSet& conf);
0014   ~HGCalTriggerNtupleHGCTriggerSums() override{};
0015   void initialize(TTree&, const edm::ParameterSet&, edm::ConsumesCollector&&) final;
0016   void fill(const edm::Event& e, const HGCalTriggerNtupleEventSetup& es) final;
0017 
0018 private:
0019   void clear() final;
0020 
0021   HGCalTriggerTools triggerTools_;
0022 
0023   edm::EDGetToken trigger_sums_token_;
0024 
0025   int ts_n_;
0026   std::vector<uint32_t> ts_id_;
0027   std::vector<int> ts_subdet_;
0028   std::vector<int> ts_side_;
0029   std::vector<int> ts_layer_;
0030   std::vector<int> ts_panel_number_;
0031   std::vector<int> ts_panel_sector_;
0032   std::vector<int> ts_wafer_;
0033   std::vector<int> ts_wafertype_;
0034   std::vector<uint32_t> ts_data_;
0035   std::vector<float> ts_mipPt_;
0036   std::vector<float> ts_pt_;
0037   std::vector<float> ts_energy_;
0038   std::vector<float> ts_eta_;
0039   std::vector<float> ts_phi_;
0040   std::vector<float> ts_x_;
0041   std::vector<float> ts_y_;
0042   std::vector<float> ts_z_;
0043 };
0044 
0045 DEFINE_EDM_PLUGIN(HGCalTriggerNtupleFactory, HGCalTriggerNtupleHGCTriggerSums, "HGCalTriggerNtupleHGCTriggerSums");
0046 
0047 HGCalTriggerNtupleHGCTriggerSums::HGCalTriggerNtupleHGCTriggerSums(const edm::ParameterSet& conf)
0048     : HGCalTriggerNtupleBase(conf) {
0049   accessEventSetup_ = false;
0050 }
0051 
0052 void HGCalTriggerNtupleHGCTriggerSums::initialize(TTree& tree,
0053                                                   const edm::ParameterSet& conf,
0054                                                   edm::ConsumesCollector&& collector) {
0055   trigger_sums_token_ =
0056       collector.consumes<l1t::HGCalTriggerSumsBxCollection>(conf.getParameter<edm::InputTag>("TriggerSums"));
0057 
0058   std::string prefix(conf.getUntrackedParameter<std::string>("Prefix", "ts"));
0059 
0060   std::string bname;
0061   auto withPrefix([&prefix, &bname](char const* vname) -> char const* {
0062     bname = prefix + "_" + vname;
0063     return bname.c_str();
0064   });
0065 
0066   tree.Branch(withPrefix("n"), &ts_n_, (prefix + "_n/I").c_str());
0067   tree.Branch(withPrefix("id"), &ts_id_);
0068   tree.Branch(withPrefix("subdet"), &ts_subdet_);
0069   tree.Branch(withPrefix("zside"), &ts_side_);
0070   tree.Branch(withPrefix("layer"), &ts_layer_);
0071   tree.Branch(withPrefix("wafer"), &ts_wafer_);
0072   tree.Branch(withPrefix("wafertype"), &ts_wafertype_);
0073   tree.Branch(withPrefix("data"), &ts_data_);
0074   tree.Branch(withPrefix("pt"), &ts_pt_);
0075   tree.Branch(withPrefix("mipPt"), &ts_mipPt_);
0076   tree.Branch(withPrefix("energy"), &ts_energy_);
0077   tree.Branch(withPrefix("eta"), &ts_eta_);
0078   tree.Branch(withPrefix("phi"), &ts_phi_);
0079   tree.Branch(withPrefix("x"), &ts_x_);
0080   tree.Branch(withPrefix("y"), &ts_y_);
0081   tree.Branch(withPrefix("z"), &ts_z_);
0082 }
0083 
0084 void HGCalTriggerNtupleHGCTriggerSums::fill(const edm::Event& e, const HGCalTriggerNtupleEventSetup& es) {
0085   // retrieve trigger cells
0086   edm::Handle<l1t::HGCalTriggerSumsBxCollection> trigger_sums_h;
0087   e.getByToken(trigger_sums_token_, trigger_sums_h);
0088   const l1t::HGCalTriggerSumsBxCollection& trigger_sums = *trigger_sums_h;
0089 
0090   triggerTools_.setGeometry(es.geometry.product());
0091 
0092   clear();
0093   for (auto ts_itr = trigger_sums.begin(0); ts_itr != trigger_sums.end(0); ts_itr++) {
0094     if (ts_itr->pt() > 0) {
0095       ts_n_++;
0096       // hardware data
0097       DetId moduleId(ts_itr->detId());
0098       ts_id_.emplace_back(ts_itr->detId());
0099       ts_side_.emplace_back(triggerTools_.zside(moduleId));
0100       ts_layer_.emplace_back(triggerTools_.layerWithOffset(moduleId));
0101       if (moduleId.det() == DetId::HGCalTrigger) {
0102         HGCalTriggerDetId id(moduleId);
0103         ts_subdet_.emplace_back(id.subdet());
0104         ts_wafertype_.emplace_back(id.type());
0105       } else if (moduleId.det() == DetId::HGCalHSc) {
0106         HGCScintillatorDetId id(moduleId);
0107         ts_subdet_.emplace_back(id.subdet());
0108         ts_wafertype_.emplace_back(id.type());
0109       } else {
0110         ts_subdet_.emplace_back(-999);
0111         ts_wafertype_.emplace_back(-999);
0112       }
0113       ts_data_.emplace_back(ts_itr->hwPt());
0114       ts_mipPt_.emplace_back(ts_itr->mipPt());
0115       // physical values
0116       ts_pt_.emplace_back(ts_itr->pt());
0117       ts_energy_.emplace_back(ts_itr->energy());
0118       ts_eta_.emplace_back(ts_itr->eta());
0119       ts_phi_.emplace_back(ts_itr->phi());
0120       ts_x_.emplace_back(ts_itr->position().x());
0121       ts_y_.emplace_back(ts_itr->position().y());
0122       ts_z_.emplace_back(ts_itr->position().z());
0123     }
0124   }
0125 }
0126 
0127 void HGCalTriggerNtupleHGCTriggerSums::clear() {
0128   ts_n_ = 0;
0129   ts_id_.clear();
0130   ts_subdet_.clear();
0131   ts_side_.clear();
0132   ts_layer_.clear();
0133   ts_wafer_.clear();
0134   ts_wafertype_.clear();
0135   ts_data_.clear();
0136   ts_mipPt_.clear();
0137   ts_pt_.clear();
0138   ts_energy_.clear();
0139   ts_eta_.clear();
0140   ts_phi_.clear();
0141   ts_x_.clear();
0142   ts_y_.clear();
0143   ts_z_.clear();
0144 }