CMS 3D CMS Logo

HGCalTriggerNtupleHGCTriggerCells.cc
Go to the documentation of this file.
1 
13 
15 public:
18  void initialize(TTree&, const edm::ParameterSet&, edm::ConsumesCollector&&) final;
19  void fill(const edm::Event& e, const edm::EventSetup& es) final;
20 
21 private:
22  double calibrate(double, int, unsigned);
23  void simhits(const edm::Event& e,
24  std::unordered_map<uint32_t, double>& simhits_ee,
25  std::unordered_map<uint32_t, double>& simhits_fh,
26  std::unordered_map<uint32_t, double>& simhits_bh);
27  void clear() final;
28 
30 
35  double keV2fC_;
36  std::vector<double> fcPerMip_;
37  std::vector<double> layerWeights_;
38  std::vector<double> thicknessCorrections_;
40 
41  int tc_n_;
42  std::vector<uint32_t> tc_id_;
43  std::vector<int> tc_subdet_;
44  std::vector<int> tc_side_;
45  std::vector<int> tc_layer_;
46  std::vector<int> tc_wafer_;
47  std::vector<int> tc_wafertype_;
48  std::vector<int> tc_cell_;
49  std::vector<uint32_t> tc_data_;
50  std::vector<uint32_t> tc_uncompressedCharge_;
51  std::vector<uint32_t> tc_compressedCharge_;
52  std::vector<float> tc_mipPt_;
53  std::vector<float> tc_pt_;
54  std::vector<float> tc_energy_;
55  std::vector<float> tc_simenergy_;
56  std::vector<float> tc_eta_;
57  std::vector<float> tc_phi_;
58  std::vector<float> tc_x_;
59  std::vector<float> tc_y_;
60  std::vector<float> tc_z_;
61  std::vector<uint32_t> tc_cluster_id_;
62  std::vector<uint32_t> tc_multicluster_id_;
63  std::vector<float> tc_multicluster_pt_;
64 };
65 
67 
69  : HGCalTriggerNtupleBase(conf),
70  fill_simenergy_(conf.getParameter<bool>("FillSimEnergy")),
71  filter_cells_in_multiclusters_(conf.getParameter<bool>("FilterCellsInMulticlusters")) {
72  fill_simenergy_ = conf.getParameter<bool>("FillSimEnergy");
73  filter_cells_in_multiclusters_ = conf.getParameter<bool>("FilterCellsInMulticlusters");
74  keV2fC_ = conf.getParameter<double>("keV2fC");
75  fcPerMip_ = conf.getParameter<std::vector<double>>("fcPerMip");
76  layerWeights_ = conf.getParameter<std::vector<double>>("layerWeights");
77  thicknessCorrections_ = conf.getParameter<std::vector<double>>("thicknessCorrections");
78 }
79 
81  const edm::ParameterSet& conf,
82  edm::ConsumesCollector&& collector) {
84  collector.consumes<l1t::HGCalTriggerCellBxCollection>(conf.getParameter<edm::InputTag>("TriggerCells"));
86  collector.consumes<l1t::HGCalMulticlusterBxCollection>(conf.getParameter<edm::InputTag>("Multiclusters"));
87 
88  if (fill_simenergy_) {
89  simhits_ee_token_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("eeSimHits"));
90  simhits_fh_token_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("fhSimHits"));
91  simhits_bh_token_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("bhSimHits"));
92  }
93 
94  tree.Branch("tc_n", &tc_n_, "tc_n/I");
95  tree.Branch("tc_id", &tc_id_);
96  tree.Branch("tc_subdet", &tc_subdet_);
97  tree.Branch("tc_zside", &tc_side_);
98  tree.Branch("tc_layer", &tc_layer_);
99  tree.Branch("tc_wafer", &tc_wafer_);
100  tree.Branch("tc_wafertype", &tc_wafertype_);
101  tree.Branch("tc_cell", &tc_cell_);
102  tree.Branch("tc_data", &tc_data_);
103  tree.Branch("tc_uncompressedCharge", &tc_uncompressedCharge_);
104  tree.Branch("tc_compressedCharge", &tc_compressedCharge_);
105  tree.Branch("tc_pt", &tc_pt_);
106  tree.Branch("tc_mipPt", &tc_mipPt_);
107  tree.Branch("tc_energy", &tc_energy_);
108  if (fill_simenergy_)
109  tree.Branch("tc_simenergy", &tc_simenergy_);
110  tree.Branch("tc_eta", &tc_eta_);
111  tree.Branch("tc_phi", &tc_phi_);
112  tree.Branch("tc_x", &tc_x_);
113  tree.Branch("tc_y", &tc_y_);
114  tree.Branch("tc_z", &tc_z_);
115  tree.Branch("tc_cluster_id", &tc_cluster_id_);
116  tree.Branch("tc_multicluster_id", &tc_multicluster_id_);
117  tree.Branch("tc_multicluster_pt", &tc_multicluster_pt_);
118 }
119 
121  // retrieve trigger cells
123  e.getByToken(trigger_cells_token_, trigger_cells_h);
124  const l1t::HGCalTriggerCellBxCollection& trigger_cells = *trigger_cells_h;
125 
126  // retrieve clusters
128  e.getByToken(multiclusters_token_, multiclusters_h);
129  const l1t::HGCalMulticlusterBxCollection& multiclusters = *multiclusters_h;
130 
131  // retrieve geometry
132  es.get<CaloGeometryRecord>().get(geometry_);
133 
134  // sim hit association
135  std::unordered_map<uint32_t, double> simhits_ee;
136  std::unordered_map<uint32_t, double> simhits_fh;
137  std::unordered_map<uint32_t, double> simhits_bh;
138  if (fill_simenergy_)
139  simhits(e, simhits_ee, simhits_fh, simhits_bh);
140 
141  // Associate cells to clusters
142  std::unordered_map<uint32_t, uint32_t> cell2cluster;
143  std::unordered_map<uint32_t, l1t::HGCalMulticlusterBxCollection::const_iterator> cell2multicluster;
144  for (auto mcl_itr = multiclusters.begin(0); mcl_itr != multiclusters.end(0); mcl_itr++) {
145  // loop on 2D clusters inside 3D clusters
146  for (const auto& cl_ptr : mcl_itr->constituents()) {
147  // loop on TC inside 2D clusters
148  for (const auto& tc_ptr : cl_ptr.second->constituents()) {
149  cell2cluster.emplace(tc_ptr.second->detId(), cl_ptr.second->detId());
150  cell2multicluster.emplace(tc_ptr.second->detId(), mcl_itr);
151  }
152  }
153  }
154 
156 
157  clear();
158  for (auto tc_itr = trigger_cells.begin(0); tc_itr != trigger_cells.end(0); tc_itr++) {
159  if (tc_itr->hwPt() > 0) {
160  auto cl_itr = cell2cluster.find(tc_itr->detId());
161  auto mcl_itr = cell2multicluster.find(tc_itr->detId());
162  uint32_t cl_id = (cl_itr != cell2cluster.end() ? cl_itr->second : 0);
163  uint32_t mcl_id = (mcl_itr != cell2multicluster.end() ? mcl_itr->second->detId() : 0);
164  float mcl_pt = (mcl_itr != cell2multicluster.end() ? mcl_itr->second->pt() : 0.);
165  // Filter cells not included in a multicluster, if requested
166  if (filter_cells_in_multiclusters_ && mcl_id == 0)
167  continue;
168  tc_n_++;
169  // hardware data
170  HGCalDetId id(tc_itr->detId());
171  tc_id_.emplace_back(tc_itr->detId());
172  tc_subdet_.emplace_back(id.subdetId());
173  tc_side_.emplace_back(id.zside());
174  tc_layer_.emplace_back(triggerTools_.layerWithOffset(id));
175  tc_wafer_.emplace_back(id.wafer());
176  tc_wafertype_.emplace_back(id.waferType());
177  tc_cell_.emplace_back(id.cell());
178  tc_data_.emplace_back(tc_itr->hwPt());
179  tc_uncompressedCharge_.emplace_back(tc_itr->uncompressedCharge());
180  tc_compressedCharge_.emplace_back(tc_itr->compressedCharge());
181  tc_mipPt_.emplace_back(tc_itr->mipPt());
182  // physical values
183  tc_pt_.emplace_back(tc_itr->pt());
184  tc_energy_.emplace_back(tc_itr->energy());
185  tc_eta_.emplace_back(tc_itr->eta());
186  tc_phi_.emplace_back(tc_itr->phi());
187  tc_x_.emplace_back(tc_itr->position().x());
188  tc_y_.emplace_back(tc_itr->position().y());
189  tc_z_.emplace_back(tc_itr->position().z());
190  // Links between TC and clusters
191  tc_cluster_id_.emplace_back(cl_id);
192  tc_multicluster_id_.emplace_back(mcl_id);
193  tc_multicluster_pt_.emplace_back(mcl_pt);
194 
195  if (fill_simenergy_) {
196  double energy = 0;
197  int subdet = id.subdetId();
198  unsigned layer = triggerTools_.layerWithOffset(id);
199  // search for simhit for all the cells inside the trigger cell
200  for (uint32_t c_id : geometry_->getCellsFromTriggerCell(id)) {
201  int thickness = triggerTools_.thicknessIndex(c_id);
202  switch (subdet) {
204  auto itr = simhits_ee.find(c_id);
205  if (itr != simhits_ee.end())
206  energy += calibrate(itr->second, thickness, layer);
207  break;
208  }
210  auto itr = simhits_fh.find(c_id);
211  if (itr != simhits_fh.end())
212  energy += calibrate(itr->second, thickness, layer);
213  break;
214  }
216  auto itr = simhits_bh.find(c_id);
217  if (itr != simhits_bh.end())
218  energy += itr->second;
219  break;
220  }
221  default:
222  break;
223  }
224  }
225  tc_simenergy_.emplace_back(energy);
226  }
227  }
228  }
229 }
230 
231 double HGCalTriggerNtupleHGCTriggerCells::calibrate(double energy, int thickness, unsigned layer) {
232  double fcPerMip = fcPerMip_[thickness];
233  double thicknessCorrection = thicknessCorrections_[thickness];
234  double layerWeight = layerWeights_[layer];
235  double TeV2GeV = 1.e3;
236  return energy * keV2fC_ / fcPerMip * layerWeight * TeV2GeV / thicknessCorrection;
237 }
238 
240  std::unordered_map<uint32_t, double>& simhits_ee,
241  std::unordered_map<uint32_t, double>& simhits_fh,
242  std::unordered_map<uint32_t, double>& simhits_bh) {
244  e.getByToken(simhits_ee_token_, ee_simhits_h);
245  const edm::PCaloHitContainer& ee_simhits = *ee_simhits_h;
247  e.getByToken(simhits_fh_token_, fh_simhits_h);
248  const edm::PCaloHitContainer& fh_simhits = *fh_simhits_h;
250  e.getByToken(simhits_bh_token_, bh_simhits_h);
251  const edm::PCaloHitContainer& bh_simhits = *bh_simhits_h;
252 
253  //EE
254  for (const auto& simhit : ee_simhits) {
255  DetId id = triggerTools_.simToReco(simhit.id(), geometry_->eeTopology());
256  if (id.rawId() == 0)
257  continue;
258  auto itr_insert = simhits_ee.emplace(id, 0.);
259  itr_insert.first->second += simhit.energy();
260  }
261  // FH
262  for (const auto& simhit : fh_simhits) {
263  DetId id = triggerTools_.simToReco(simhit.id(), geometry_->fhTopology());
264  if (id.rawId() == 0)
265  continue;
266  auto itr_insert = simhits_fh.emplace(id, 0.);
267  itr_insert.first->second += simhit.energy();
268  }
269  // BH
270  for (const auto& simhit : bh_simhits) {
272  : triggerTools_.simToReco(simhit.id(), geometry_->bhTopology()));
273  if (id.rawId() == 0)
274  continue;
275  auto itr_insert = simhits_bh.emplace(id, 0.);
276  itr_insert.first->second += simhit.energy();
277  }
278 }
279 
281  tc_n_ = 0;
282  tc_id_.clear();
283  tc_subdet_.clear();
284  tc_side_.clear();
285  tc_layer_.clear();
286  tc_wafer_.clear();
287  tc_wafertype_.clear();
288  tc_cell_.clear();
289  tc_data_.clear();
290  tc_uncompressedCharge_.clear();
291  tc_compressedCharge_.clear();
292  tc_mipPt_.clear();
293  tc_pt_.clear();
294  tc_energy_.clear();
295  tc_simenergy_.clear();
296  tc_eta_.clear();
297  tc_phi_.clear();
298  tc_x_.clear();
299  tc_y_.clear();
300  tc_z_.clear();
301  tc_cluster_id_.clear();
302  tc_multicluster_id_.clear();
303  tc_multicluster_pt_.clear();
304 }
void initialize(TTree &, const edm::ParameterSet &, edm::ConsumesCollector &&) final
const_iterator end(int bx) const
T getParameter(std::string const &) const
edm::ESHandle< HGCalTriggerGeometryBase > geometry_
std::vector< PCaloHit > PCaloHitContainer
virtual geom_set getCellsFromTriggerCell(const unsigned cell_det_id) const =0
void eventSetup(const edm::EventSetup &)
void fill(const edm::Event &e, const edm::EventSetup &es) final
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const HGCalTopology & eeTopology() const
HGCalTriggerNtupleHGCTriggerCells(const edm::ParameterSet &conf)
unsigned layerWithOffset(const DetId &) const
int zside(DetId const &)
const HcalTopology & bhTopology() const
Definition: DetId.h:18
int thicknessIndex(const DetId &, bool tc=false) const
const HGCalTopology & hscTopology() const
T get() const
Definition: EventSetup.h:71
#define DEFINE_EDM_PLUGIN(factory, type, name)
DetId simToReco(const DetId &, const HGCalTopology &) const
Definition: tree.py:1
void simhits(const edm::Event &e, std::unordered_map< uint32_t, double > &simhits_ee, std::unordered_map< uint32_t, double > &simhits_fh, std::unordered_map< uint32_t, double > &simhits_bh)
const_iterator begin(int bx) const
const HGCalTopology & fhTopology() const