CMS 3D CMS Logo

HGCalTriggerNtupleHGCClusters.cc
Go to the documentation of this file.
1 
2 #include <algorithm>
10 
11 
12 
14 {
15 
16  public:
19  void initialize(TTree&, const edm::ParameterSet&, edm::ConsumesCollector&&) final;
20  void fill(const edm::Event& e, const edm::EventSetup& es) final;
21 
22  private:
23  void clear() final;
24 
25 
29 
30 
31  int cl_n_ ;
32  std::vector<uint32_t> cl_id_;
33  std::vector<float> cl_mipPt_;
34  std::vector<float> cl_pt_;
35  std::vector<float> cl_energy_;
36  std::vector<float> cl_eta_;
37  std::vector<float> cl_phi_;
38  std::vector<int> cl_layer_;
39  std::vector<int> cl_subdet_;
40  std::vector<int> cl_cells_n_;
41  std::vector<std::vector<uint32_t>> cl_cells_id_;
42  std::vector<uint32_t> cl_multicluster_id_;
43  std::vector<float> cl_multicluster_pt_;
44 
45 
46 };
47 
50  "HGCalTriggerNtupleHGCClusters" );
51 
52 
55  filter_clusters_in_multiclusters_(conf.getParameter<bool>("FilterClustersInMulticlusters"))
56 {
57 }
58 
59 void
61 initialize(TTree& tree, const edm::ParameterSet& conf, edm::ConsumesCollector&& collector)
62 {
63  clusters_token_ = collector.consumes<l1t::HGCalClusterBxCollection>(conf.getParameter<edm::InputTag>("Clusters"));
64  multiclusters_token_ = collector.consumes<l1t::HGCalMulticlusterBxCollection>(conf.getParameter<edm::InputTag>("Multiclusters"));
65 
66  tree.Branch("cl_n", &cl_n_, "cl_n/I");
67  tree.Branch("cl_id", &cl_id_);
68  tree.Branch("cl_mipPt", &cl_mipPt_);
69  tree.Branch("cl_pt", &cl_pt_);
70  tree.Branch("cl_energy", &cl_energy_);
71  tree.Branch("cl_eta", &cl_eta_);
72  tree.Branch("cl_phi", &cl_phi_);
73  tree.Branch("cl_layer", &cl_layer_);
74  tree.Branch("cl_subdet", &cl_subdet_);
75  tree.Branch("cl_cells_n", &cl_cells_n_);
76  tree.Branch("cl_cells_id", &cl_cells_id_);
77  tree.Branch("cl_multicluster_id", &cl_multicluster_id_);
78  tree.Branch("cl_multicluster_pt", &cl_multicluster_pt_);
79 }
80 
81 void
83 fill(const edm::Event& e, const edm::EventSetup& es)
84 {
85 
86  // retrieve clusters
88  e.getByToken(clusters_token_, clusters_h);
89  const l1t::HGCalClusterBxCollection& clusters = *clusters_h;
91  e.getByToken(multiclusters_token_, multiclusters_h);
92  const l1t::HGCalMulticlusterBxCollection& multiclusters = *multiclusters_h;
93 
94  // retrieve geometry
96  es.get<CaloGeometryRecord>().get(geometry);
97 
99 
100  // Associate cells to clusters
101  std::unordered_map<uint32_t, l1t::HGCalMulticlusterBxCollection::const_iterator> cluster2multicluster;
102  for(auto mcl_itr=multiclusters.begin(0); mcl_itr!=multiclusters.end(0); mcl_itr++)
103  {
104  // loop on 2D clusters inside 3D clusters
105  for(const auto& cl_ptr : mcl_itr->constituents())
106  {
107  cluster2multicluster.emplace(cl_ptr.second->detId(), mcl_itr);
108  }
109  }
110 
111 
112 
113  clear();
114  for(auto cl_itr=clusters.begin(0); cl_itr!=clusters.end(0); cl_itr++)
115  {
116  auto mcl_itr = cluster2multicluster.find(cl_itr->detId());
117  uint32_t mcl_id = (mcl_itr!=cluster2multicluster.end() ? mcl_itr->second->detId() : 0);
118  float mcl_pt = (mcl_itr!=cluster2multicluster.end() ? mcl_itr->second->pt() : 0.);
119  if(filter_clusters_in_multiclusters_ && mcl_id==0) continue;
120  cl_n_++;
121  cl_mipPt_.emplace_back(cl_itr->mipPt());
122  // physical values
123  cl_pt_.emplace_back(cl_itr->pt());
124  cl_energy_.emplace_back(cl_itr->energy());
125  cl_eta_.emplace_back(cl_itr->eta());
126  cl_phi_.emplace_back(cl_itr->phi());
127 
128  cl_id_.emplace_back(cl_itr->detId());
129  cl_layer_.emplace_back(triggerTools_.layerWithOffset(cl_itr->detId()));
130  cl_subdet_.emplace_back(cl_itr->subdetId());
131  cl_cells_n_.emplace_back(cl_itr->constituents().size());
132  // Retrieve indices of trigger cells inside cluster
133  cl_cells_id_.emplace_back(cl_itr->constituents().size());
134  std::transform(cl_itr->constituents_begin(), cl_itr->constituents_end(),
135  cl_cells_id_.back().begin(), [](const std::pair<uint32_t,edm::Ptr<l1t::HGCalTriggerCell>>& id_tc){return id_tc.second->detId();}
136  );
137  cl_multicluster_id_.emplace_back(mcl_id);
138  cl_multicluster_pt_.emplace_back(mcl_pt);
139  }
140 }
141 
142 
143 void
146 {
147  cl_n_ = 0;
148  cl_id_.clear();
149  cl_mipPt_.clear();
150  cl_pt_.clear();
151  cl_energy_.clear();
152  cl_eta_.clear();
153  cl_phi_.clear();
154  cl_layer_.clear();
155  cl_subdet_.clear();
156  cl_cells_n_.clear();
157  cl_cells_id_.clear();
158  cl_multicluster_id_.clear();
159  cl_multicluster_pt_.clear();
160 }
const_iterator end(int bx) const
T getParameter(std::string const &) const
void eventSetup(const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
unsigned layerWithOffset(const DetId &) const
std::vector< std::vector< uint32_t > > cl_cells_id_
void initialize(TTree &, const edm::ParameterSet &, edm::ConsumesCollector &&) final
const T & get() const
Definition: EventSetup.h:59
ESHandle< TrackerGeometry > geometry
HGCalTriggerNtupleHGCClusters(const edm::ParameterSet &conf)
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: tree.py:1
const_iterator begin(int bx) const
void fill(const edm::Event &e, const edm::EventSetup &es) final