CMS 3D CMS Logo

HGCalTriggerNtupleHGCDigis.cc
Go to the documentation of this file.
8 
11 
15 
17 public:
20  void initialize(TTree&, const edm::ParameterSet&, edm::ConsumesCollector&&) final;
21  void fill(const edm::Event& e, const edm::EventSetup& es) final;
22 
23 private:
24  void simhits(const edm::Event& e,
25  std::unordered_map<uint32_t, double>& simhits_ee,
26  std::unordered_map<uint32_t, double>& simhits_fh,
27  std::unordered_map<uint32_t, double>& simhits_bh);
28  void clear() final;
29 
33 
35 
37  std::vector<int> hgcdigi_id_;
38  std::vector<int> hgcdigi_subdet_;
39  std::vector<int> hgcdigi_side_;
40  std::vector<int> hgcdigi_layer_;
41  std::vector<int> hgcdigi_wafertype_;
42  std::vector<float> hgcdigi_eta_;
43  std::vector<float> hgcdigi_phi_;
44  std::vector<float> hgcdigi_z_;
45  std::vector<uint32_t> hgcdigi_data_;
46  std::vector<int> hgcdigi_isadc_;
47  std::vector<float> hgcdigi_simenergy_;
48  // V8 detid scheme
49  std::vector<int> hgcdigi_wafer_;
50  std::vector<int> hgcdigi_cell_;
51  // V9 detid scheme
52  std::vector<int> hgcdigi_waferu_;
53  std::vector<int> hgcdigi_waferv_;
54  std::vector<int> hgcdigi_cellu_;
55  std::vector<int> hgcdigi_cellv_;
56 
57  int bhdigi_n_;
58  std::vector<int> bhdigi_id_;
59  std::vector<int> bhdigi_subdet_;
60  std::vector<int> bhdigi_side_;
61  std::vector<int> bhdigi_layer_;
62  std::vector<int> bhdigi_ieta_;
63  std::vector<int> bhdigi_iphi_;
64  std::vector<float> bhdigi_eta_;
65  std::vector<float> bhdigi_phi_;
66  std::vector<float> bhdigi_z_;
67  std::vector<uint32_t> bhdigi_data_;
68  std::vector<float> bhdigi_simenergy_;
69 
71 };
72 
74 
76  is_Simhit_comp_ = conf.getParameter<bool>("isSimhitComp");
77 }
78 
80  const edm::ParameterSet& conf,
81  edm::ConsumesCollector&& collector) {
82  ee_token_ = collector.consumes<HGCalDigiCollection>(conf.getParameter<edm::InputTag>("HGCDigisEE"));
83  fh_token_ = collector.consumes<HGCalDigiCollection>(conf.getParameter<edm::InputTag>("HGCDigisFH"));
84  bh_token_ = collector.consumes<HGCalDigiCollection>(conf.getParameter<edm::InputTag>("HGCDigisBH"));
85  if (is_Simhit_comp_) {
86  SimHits_inputee_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("eeSimHits"));
87  SimHits_inputfh_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("fhSimHits"));
88  SimHits_inputbh_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("bhSimHits"));
89  }
90  tree.Branch("hgcdigi_n", &hgcdigi_n_, "hgcdigi_n/I");
91  tree.Branch("hgcdigi_id", &hgcdigi_id_);
92  tree.Branch("hgcdigi_subdet", &hgcdigi_subdet_);
93  tree.Branch("hgcdigi_zside", &hgcdigi_side_);
94  tree.Branch("hgcdigi_layer", &hgcdigi_layer_);
95  tree.Branch("hgcdigi_wafertype", &hgcdigi_wafertype_);
96  tree.Branch("hgcdigi_eta", &hgcdigi_eta_);
97  tree.Branch("hgcdigi_phi", &hgcdigi_phi_);
98  tree.Branch("hgcdigi_z", &hgcdigi_z_);
99  tree.Branch("hgcdigi_data", &hgcdigi_data_);
100  tree.Branch("hgcdigi_isadc", &hgcdigi_isadc_);
101  // V9 detid scheme
102  tree.Branch("hgcdigi_waferu", &hgcdigi_waferu_);
103  tree.Branch("hgcdigi_waferv", &hgcdigi_waferv_);
104  tree.Branch("hgcdigi_cellu", &hgcdigi_cellu_);
105  tree.Branch("hgcdigi_cellv", &hgcdigi_cellv_);
106  // V8 detid scheme
107  tree.Branch("hgcdigi_wafer", &hgcdigi_wafer_);
108  tree.Branch("hgcdigi_cell", &hgcdigi_cell_);
109  if (is_Simhit_comp_)
110  tree.Branch("hgcdigi_simenergy", &hgcdigi_simenergy_);
111 
112  tree.Branch("bhdigi_n", &bhdigi_n_, "bhdigi_n/I");
113  tree.Branch("bhdigi_id", &bhdigi_id_);
114  tree.Branch("bhdigi_subdet", &bhdigi_subdet_);
115  tree.Branch("bhdigi_zside", &bhdigi_side_);
116  tree.Branch("bhdigi_layer", &bhdigi_layer_);
117  tree.Branch("bhdigi_ieta", &bhdigi_ieta_);
118  tree.Branch("bhdigi_iphi", &bhdigi_iphi_);
119  tree.Branch("bhdigi_eta", &bhdigi_eta_);
120  tree.Branch("bhdigi_phi", &bhdigi_phi_);
121  tree.Branch("bhdigi_z", &bhdigi_z_);
122  tree.Branch("bhdigi_data", &bhdigi_data_);
123  if (is_Simhit_comp_)
124  tree.Branch("bhdigi_simenergy", &bhdigi_simenergy_);
125 }
126 
129 
131  e.getByToken(ee_token_, ee_digis_h);
132  const HGCalDigiCollection& ee_digis = *ee_digis_h;
134  e.getByToken(fh_token_, fh_digis_h);
135  const HGCalDigiCollection& fh_digis = *fh_digis_h;
137  e.getByToken(bh_token_, bh_digis_h);
138  const HGCalDigiCollection& bh_digis = *bh_digis_h;
139 
141 
142  // sim hit association
143  std::unordered_map<uint32_t, double> simhits_ee;
144  std::unordered_map<uint32_t, double> simhits_fh;
145  std::unordered_map<uint32_t, double> simhits_bh;
146  if (is_Simhit_comp_)
147  simhits(e, simhits_ee, simhits_fh, simhits_bh);
148 
149  clear();
150  hgcdigi_n_ = ee_digis.size() + fh_digis.size();
151  hgcdigi_id_.reserve(hgcdigi_n_);
152  hgcdigi_subdet_.reserve(hgcdigi_n_);
153  hgcdigi_side_.reserve(hgcdigi_n_);
154  hgcdigi_layer_.reserve(hgcdigi_n_);
156  hgcdigi_eta_.reserve(hgcdigi_n_);
157  hgcdigi_phi_.reserve(hgcdigi_n_);
158  hgcdigi_z_.reserve(hgcdigi_n_);
159  hgcdigi_data_.reserve(hgcdigi_n_);
160  hgcdigi_isadc_.reserve(hgcdigi_n_);
162  hgcdigi_waferu_.reserve(hgcdigi_n_);
163  hgcdigi_waferv_.reserve(hgcdigi_n_);
164  hgcdigi_cellu_.reserve(hgcdigi_n_);
165  hgcdigi_cellv_.reserve(hgcdigi_n_);
166  } else {
167  hgcdigi_wafer_.reserve(hgcdigi_n_);
168  hgcdigi_cell_.reserve(hgcdigi_n_);
169  }
170  if (is_Simhit_comp_)
172 
173  bhdigi_n_ = bh_digis.size();
174  bhdigi_id_.reserve(bhdigi_n_);
175  bhdigi_subdet_.reserve(bhdigi_n_);
176  bhdigi_side_.reserve(bhdigi_n_);
177  bhdigi_layer_.reserve(bhdigi_n_);
178  bhdigi_ieta_.reserve(bhdigi_n_);
179  bhdigi_iphi_.reserve(bhdigi_n_);
180  bhdigi_eta_.reserve(bhdigi_n_);
181  bhdigi_phi_.reserve(bhdigi_n_);
182  bhdigi_z_.reserve(bhdigi_n_);
183  if (is_Simhit_comp_)
184  bhdigi_simenergy_.reserve(bhdigi_n_);
185 
186  const int kIntimeSample = 2;
187  for (const auto& digi : ee_digis) {
188  const DetId id(digi.id());
189  hgcdigi_id_.emplace_back(id.rawId());
190  hgcdigi_subdet_.emplace_back(id.subdetId());
191  hgcdigi_side_.emplace_back(triggerTools_.zside(id));
192  hgcdigi_layer_.emplace_back(triggerTools_.layerWithOffset(id));
193  GlobalPoint cellpos = triggerGeometry_->eeGeometry()->getPosition(id.rawId());
194  hgcdigi_eta_.emplace_back(cellpos.eta());
195  hgcdigi_phi_.emplace_back(cellpos.phi());
196  hgcdigi_z_.emplace_back(cellpos.z());
197  hgcdigi_data_.emplace_back(digi[kIntimeSample].data());
199  const HGCSiliconDetId idv9(digi.id());
200  hgcdigi_waferu_.emplace_back(idv9.waferU());
201  hgcdigi_waferv_.emplace_back(idv9.waferV());
202  hgcdigi_wafertype_.emplace_back(idv9.type());
203  hgcdigi_cellu_.emplace_back(idv9.cellU());
204  hgcdigi_cellv_.emplace_back(idv9.cellV());
205  } else {
206  const HGCalDetId idv8(digi.id());
207  hgcdigi_wafer_.emplace_back(idv8.wafer());
208  hgcdigi_wafertype_.emplace_back(idv8.waferType());
209  hgcdigi_cell_.emplace_back(idv8.cell());
210  }
211  int is_adc = 0;
212  if (!(digi[kIntimeSample].mode()))
213  is_adc = 1;
214  hgcdigi_isadc_.emplace_back(is_adc);
215  if (is_Simhit_comp_) {
216  double hit_energy = 0;
217  auto itr = simhits_ee.find(id);
218  if (itr != simhits_ee.end())
219  hit_energy = itr->second;
220  hgcdigi_simenergy_.emplace_back(hit_energy);
221  }
222  }
223 
224  for (const auto& digi : fh_digis) {
225  const DetId id(digi.id());
226  hgcdigi_id_.emplace_back(id.rawId());
227  hgcdigi_subdet_.emplace_back(id.subdetId());
228  hgcdigi_side_.emplace_back(triggerTools_.zside(id));
229  hgcdigi_layer_.emplace_back(triggerTools_.layerWithOffset(id));
230  GlobalPoint cellpos = triggerGeometry_->hsiGeometry()->getPosition(id.rawId());
231  hgcdigi_eta_.emplace_back(cellpos.eta());
232  hgcdigi_phi_.emplace_back(cellpos.phi());
233  hgcdigi_z_.emplace_back(cellpos.z());
234  hgcdigi_data_.emplace_back(digi[kIntimeSample].data());
236  const HGCSiliconDetId idv9(digi.id());
237  hgcdigi_waferu_.emplace_back(idv9.waferU());
238  hgcdigi_waferv_.emplace_back(idv9.waferV());
239  hgcdigi_wafertype_.emplace_back(idv9.type());
240  hgcdigi_cellu_.emplace_back(idv9.cellU());
241  hgcdigi_cellv_.emplace_back(idv9.cellV());
242  } else {
243  const HGCalDetId idv8(digi.id());
244  hgcdigi_wafer_.emplace_back(idv8.wafer());
245  hgcdigi_wafertype_.emplace_back(idv8.waferType());
246  hgcdigi_cell_.emplace_back(idv8.cell());
247  }
248  int is_adc = 0;
249  if (!(digi[kIntimeSample].mode()))
250  is_adc = 1;
251  hgcdigi_isadc_.emplace_back(is_adc);
252  if (is_Simhit_comp_) {
253  double hit_energy = 0;
254  auto itr = simhits_fh.find(id);
255  if (itr != simhits_fh.end())
256  hit_energy = itr->second;
257  hgcdigi_simenergy_.emplace_back(hit_energy);
258  }
259  }
260 
261  for (const auto& digi : bh_digis) {
262  const DetId id(digi.id());
263  bhdigi_id_.emplace_back(id.rawId());
264  bhdigi_subdet_.emplace_back(id.subdetId());
265  bhdigi_side_.emplace_back(triggerTools_.zside(id));
266  bhdigi_layer_.emplace_back(triggerTools_.layerWithOffset(id));
268  : triggerGeometry_->bhGeometry()->getPosition(id.rawId()));
269  bhdigi_eta_.emplace_back(cellpos.eta());
270  bhdigi_phi_.emplace_back(cellpos.phi());
271  bhdigi_z_.emplace_back(cellpos.z());
272  bhdigi_data_.emplace_back(digi[kIntimeSample].data());
274  const HGCScintillatorDetId idv9(digi.id());
275  bhdigi_ieta_.emplace_back(idv9.ietaAbs());
276  bhdigi_iphi_.emplace_back(idv9.iphi());
277  } else {
278  const HcalDetId idv8(digi.id());
279  bhdigi_ieta_.emplace_back(idv8.ieta());
280  bhdigi_iphi_.emplace_back(idv8.iphi());
281  }
282  if (is_Simhit_comp_) {
283  double hit_energy = 0;
284  auto itr = simhits_bh.find(id);
285  if (itr != simhits_bh.end())
286  hit_energy = itr->second;
287  bhdigi_simenergy_.emplace_back(hit_energy);
288  }
289  }
290 }
291 
293  std::unordered_map<uint32_t, double>& simhits_ee,
294  std::unordered_map<uint32_t, double>& simhits_fh,
295  std::unordered_map<uint32_t, double>& simhits_bh) {
297  e.getByToken(SimHits_inputee_, ee_simhits_h);
298  const edm::PCaloHitContainer& ee_simhits = *ee_simhits_h;
300  e.getByToken(SimHits_inputfh_, fh_simhits_h);
301  const edm::PCaloHitContainer& fh_simhits = *fh_simhits_h;
303  e.getByToken(SimHits_inputbh_, bh_simhits_h);
304  const edm::PCaloHitContainer& bh_simhits = *bh_simhits_h;
305 
306  //EE
307  for (const auto& simhit : ee_simhits) {
309  if (id.rawId() == 0)
310  continue;
311  auto itr_insert = simhits_ee.emplace(id, 0.);
312  itr_insert.first->second += simhit.energy();
313  }
314  // FH
315  for (const auto& simhit : fh_simhits) {
317  if (id.rawId() == 0)
318  continue;
319  auto itr_insert = simhits_fh.emplace(id, 0.);
320  itr_insert.first->second += simhit.energy();
321  }
322  // BH
323  for (const auto& simhit : bh_simhits) {
324  DetId id =
327  if (id.rawId() == 0)
328  continue;
329  auto itr_insert = simhits_bh.emplace(id, 0.);
330  itr_insert.first->second += simhit.energy();
331  }
332 }
333 
335  hgcdigi_n_ = 0;
336  hgcdigi_id_.clear();
337  hgcdigi_subdet_.clear();
338  hgcdigi_side_.clear();
339  hgcdigi_layer_.clear();
340  hgcdigi_wafer_.clear();
341  hgcdigi_waferu_.clear();
342  hgcdigi_waferv_.clear();
343  hgcdigi_wafertype_.clear();
344  hgcdigi_cell_.clear();
345  hgcdigi_cellu_.clear();
346  hgcdigi_cellv_.clear();
347  hgcdigi_eta_.clear();
348  hgcdigi_phi_.clear();
349  hgcdigi_z_.clear();
350  hgcdigi_data_.clear();
351  hgcdigi_isadc_.clear();
352  if (is_Simhit_comp_)
353  hgcdigi_simenergy_.clear();
354 
355  bhdigi_n_ = 0;
356  bhdigi_id_.clear();
357  bhdigi_subdet_.clear();
358  bhdigi_side_.clear();
359  bhdigi_layer_.clear();
360  bhdigi_ieta_.clear();
361  bhdigi_iphi_.clear();
362  bhdigi_eta_.clear();
363  bhdigi_phi_.clear();
364  bhdigi_z_.clear();
365  bhdigi_data_.clear();
366  if (is_Simhit_comp_)
367  bhdigi_simenergy_.clear();
368 }
T getParameter(std::string const &) const
std::vector< PCaloHit > PCaloHitContainer
void eventSetup(const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
edm::ESHandle< HGCalTriggerGeometryBase > triggerGeometry_
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)
GlobalPoint getPosition(const DetId &id) const
unsigned layerWithOffset(const DetId &) const
void fill(const edm::Event &e, const edm::EventSetup &es) final
std::vector< uint32_t > hgcdigi_data_
void initialize(TTree &, const edm::ParameterSet &, edm::ConsumesCollector &&) final
int zside(const DetId &) const
const HcalTopology & bhTopology() const
T z() const
Definition: PV3DBase.h:61
HGCalTriggerNtupleHGCDigis(const edm::ParameterSet &conf)
GlobalPoint getPosition(const DetId &id) const
const HcalGeometry * bhGeometry() const
const HGCalGeometry * hsiGeometry() const
Definition: DetId.h:17
std::vector< uint32_t > bhdigi_data_
const HGCalGeometry * hscGeometry() const
const HGCalTopology & hscTopology() const
T eta() const
Definition: PV3DBase.h:73
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
size_type size() const
T get() const
Definition: EventSetup.h:73
#define DEFINE_EDM_PLUGIN(factory, type, name)
DetId simToReco(const DetId &, const HGCalTopology &) const
Definition: tree.py:1
const HGCalTopology & fhTopology() const