CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HGCalTriggerNtupleHGCDigis.cc
Go to the documentation of this file.
5 
8 
12 
14 public:
17  void initialize(TTree&, const edm::ParameterSet&, edm::ConsumesCollector&&) final;
18  void fill(const edm::Event& e, const HGCalTriggerNtupleEventSetup& es) final;
19 
20 private:
21  void simhits(const edm::Event& e,
22  std::unordered_map<uint32_t, double>& simhits_ee,
23  std::unordered_map<uint32_t, double>& simhits_fh,
24  std::unordered_map<uint32_t, double>& simhits_bh);
25  void clear() final;
26 
30 
31  std::vector<unsigned int> digiBXselect_;
32  static constexpr unsigned kDigiSize_ = 5;
33 
35 
37  std::vector<int> hgcdigi_id_;
39  std::vector<int> hgcdigi_side_;
42  std::vector<float> hgcdigi_eta_;
43  std::vector<float> hgcdigi_phi_;
44  std::vector<float> hgcdigi_z_;
45  std::vector<std::vector<uint32_t>> hgcdigi_data_;
46  std::vector<std::vector<int>> hgcdigi_isadc_;
52 
53  int bhdigi_n_;
54  std::vector<int> bhdigi_id_;
56  std::vector<int> bhdigi_side_;
57  std::vector<int> bhdigi_layer_;
58  std::vector<int> bhdigi_ieta_;
59  std::vector<int> bhdigi_iphi_;
60  std::vector<float> bhdigi_eta_;
61  std::vector<float> bhdigi_phi_;
62  std::vector<float> bhdigi_z_;
63  std::vector<std::vector<uint32_t>> bhdigi_data_;
64  std::vector<std::vector<int>> bhdigi_isadc_;
66 };
67 
69 
70 HGCalTriggerNtupleHGCDigis::HGCalTriggerNtupleHGCDigis(const edm::ParameterSet& conf) : HGCalTriggerNtupleBase(conf) {
71  accessEventSetup_ = false;
72  is_Simhit_comp_ = conf.getParameter<bool>("isSimhitComp");
73  digiBXselect_ = conf.getParameter<std::vector<unsigned int>>("digiBXselect");
74 
75  if (digiBXselect_.empty()) {
76  throw cms::Exception("BadInitialization") << "digiBXselect vector is empty";
77  }
78  if (*std::max_element(digiBXselect_.begin(), digiBXselect_.end()) >= kDigiSize_) {
79  throw cms::Exception("BadInitialization")
80  << "digiBXselect vector requests a BX outside of maximum size of digis (" << kDigiSize_ << " BX)";
81  }
82  //sort and check for duplicates
83  std::sort(digiBXselect_.begin(), digiBXselect_.end());
84  if (std::unique(digiBXselect_.begin(), digiBXselect_.end()) != digiBXselect_.end()) {
85  throw cms::Exception("BadInitialization") << "digiBXselect vector contains duplicate BX values";
86  }
87 }
88 
90  const edm::ParameterSet& conf,
91  edm::ConsumesCollector&& collector) {
92  ee_token_ = collector.consumes<HGCalDigiCollection>(conf.getParameter<edm::InputTag>("HGCDigisEE"));
93  fh_token_ = collector.consumes<HGCalDigiCollection>(conf.getParameter<edm::InputTag>("HGCDigisFH"));
94  bh_token_ = collector.consumes<HGCalDigiCollection>(conf.getParameter<edm::InputTag>("HGCDigisBH"));
95  if (is_Simhit_comp_) {
96  SimHits_inputee_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("eeSimHits"));
97  SimHits_inputfh_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("fhSimHits"));
98  SimHits_inputbh_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("bhSimHits"));
99  }
100 
101  hgcdigi_data_.resize(digiBXselect_.size());
102  hgcdigi_isadc_.resize(digiBXselect_.size());
103  bhdigi_data_.resize(digiBXselect_.size());
104  bhdigi_isadc_.resize(digiBXselect_.size());
105 
106  tree.Branch("hgcdigi_n", &hgcdigi_n_, "hgcdigi_n/I");
107  tree.Branch("hgcdigi_id", &hgcdigi_id_);
108  tree.Branch("hgcdigi_subdet", &hgcdigi_subdet_);
109  tree.Branch("hgcdigi_zside", &hgcdigi_side_);
110  tree.Branch("hgcdigi_layer", &hgcdigi_layer_);
111  tree.Branch("hgcdigi_wafertype", &hgcdigi_wafertype_);
112  tree.Branch("hgcdigi_eta", &hgcdigi_eta_);
113  tree.Branch("hgcdigi_phi", &hgcdigi_phi_);
114  tree.Branch("hgcdigi_z", &hgcdigi_z_);
115  std::string bname;
116  auto withBX([&bname](char const* vname, unsigned int bx) -> char const* {
117  bname = std::string(vname) + "_BX" + to_string(bx);
118  return bname.c_str();
119  });
120  for (unsigned int i = 0; i < digiBXselect_.size(); i++) {
121  unsigned int bxi = digiBXselect_[i];
122  tree.Branch(withBX("hgcdigi_data", bxi), &hgcdigi_data_[i]);
123  tree.Branch(withBX("hgcdigi_isadc", bxi), &hgcdigi_isadc_[i]);
124  }
125  tree.Branch("hgcdigi_waferu", &hgcdigi_waferu_);
126  tree.Branch("hgcdigi_waferv", &hgcdigi_waferv_);
127  tree.Branch("hgcdigi_cellu", &hgcdigi_cellu_);
128  tree.Branch("hgcdigi_cellv", &hgcdigi_cellv_);
129  if (is_Simhit_comp_)
130  tree.Branch("hgcdigi_simenergy", &hgcdigi_simenergy_);
131 
132  tree.Branch("bhdigi_n", &bhdigi_n_, "bhdigi_n/I");
133  tree.Branch("bhdigi_id", &bhdigi_id_);
134  tree.Branch("bhdigi_subdet", &bhdigi_subdet_);
135  tree.Branch("bhdigi_zside", &bhdigi_side_);
136  tree.Branch("bhdigi_layer", &bhdigi_layer_);
137  tree.Branch("bhdigi_ieta", &bhdigi_ieta_);
138  tree.Branch("bhdigi_iphi", &bhdigi_iphi_);
139  tree.Branch("bhdigi_eta", &bhdigi_eta_);
140  tree.Branch("bhdigi_phi", &bhdigi_phi_);
141  tree.Branch("bhdigi_z", &bhdigi_z_);
142  for (unsigned int i = 0; i < digiBXselect_.size(); i++) {
143  unsigned int bxi = digiBXselect_[i];
144  tree.Branch(withBX("bhdigi_data", bxi), &bhdigi_data_[i]);
145  tree.Branch(withBX("bhdigi_isadc", bxi), &bhdigi_isadc_[i]);
146  }
147  if (is_Simhit_comp_)
148  tree.Branch("bhdigi_simenergy", &bhdigi_simenergy_);
149 }
150 
153  e.getByToken(ee_token_, ee_digis_h);
154  const HGCalDigiCollection& ee_digis = *ee_digis_h;
156  e.getByToken(fh_token_, fh_digis_h);
157  const HGCalDigiCollection& fh_digis = *fh_digis_h;
159  e.getByToken(bh_token_, bh_digis_h);
160  const HGCalDigiCollection& bh_digis = *bh_digis_h;
161 
163 
164  // sim hit association
165  std::unordered_map<uint32_t, double> simhits_ee;
166  std::unordered_map<uint32_t, double> simhits_fh;
167  std::unordered_map<uint32_t, double> simhits_bh;
168  if (is_Simhit_comp_)
169  simhits(e, simhits_ee, simhits_fh, simhits_bh);
170 
171  clear();
172  hgcdigi_n_ = ee_digis.size() + fh_digis.size();
173  hgcdigi_id_.reserve(hgcdigi_n_);
174  hgcdigi_subdet_.reserve(hgcdigi_n_);
175  hgcdigi_side_.reserve(hgcdigi_n_);
176  hgcdigi_layer_.reserve(hgcdigi_n_);
178  hgcdigi_eta_.reserve(hgcdigi_n_);
179  hgcdigi_phi_.reserve(hgcdigi_n_);
180  hgcdigi_z_.reserve(hgcdigi_n_);
181  for (unsigned int i = 0; i < digiBXselect_.size(); i++) {
182  hgcdigi_data_[i].reserve(hgcdigi_n_);
183  hgcdigi_isadc_[i].reserve(hgcdigi_n_);
184  }
185  hgcdigi_waferu_.reserve(hgcdigi_n_);
186  hgcdigi_waferv_.reserve(hgcdigi_n_);
187  hgcdigi_cellu_.reserve(hgcdigi_n_);
188  hgcdigi_cellv_.reserve(hgcdigi_n_);
189  if (is_Simhit_comp_)
191 
192  bhdigi_n_ = bh_digis.size();
193  bhdigi_id_.reserve(bhdigi_n_);
194  bhdigi_subdet_.reserve(bhdigi_n_);
195  bhdigi_side_.reserve(bhdigi_n_);
196  bhdigi_layer_.reserve(bhdigi_n_);
197  bhdigi_ieta_.reserve(bhdigi_n_);
198  bhdigi_iphi_.reserve(bhdigi_n_);
199  bhdigi_eta_.reserve(bhdigi_n_);
200  bhdigi_phi_.reserve(bhdigi_n_);
201  bhdigi_z_.reserve(bhdigi_n_);
202  for (unsigned int i = 0; i < digiBXselect_.size(); i++) {
203  bhdigi_data_[i].reserve(bhdigi_n_);
204  bhdigi_isadc_[i].reserve(bhdigi_n_);
205  }
206  if (is_Simhit_comp_)
207  bhdigi_simenergy_.reserve(bhdigi_n_);
208 
209  for (const auto& digi : ee_digis) {
210  const DetId id(digi.id());
211  hgcdigi_id_.emplace_back(id.rawId());
212  hgcdigi_subdet_.emplace_back(id.det());
213  hgcdigi_side_.emplace_back(triggerTools_.zside(id));
214  hgcdigi_layer_.emplace_back(triggerTools_.layerWithOffset(id));
216  hgcdigi_eta_.emplace_back(cellpos.eta());
217  hgcdigi_phi_.emplace_back(cellpos.phi());
218  hgcdigi_z_.emplace_back(cellpos.z());
219  for (unsigned int i = 0; i < digiBXselect_.size(); i++) {
220  hgcdigi_data_[i].emplace_back(digi[digiBXselect_[i]].data());
221  hgcdigi_isadc_[i].emplace_back(!digi[digiBXselect_[i]].mode());
222  }
223  const HGCSiliconDetId idsi(digi.id());
224  hgcdigi_waferu_.emplace_back(idsi.waferU());
225  hgcdigi_waferv_.emplace_back(idsi.waferV());
226  hgcdigi_wafertype_.emplace_back(idsi.type());
227  hgcdigi_cellu_.emplace_back(idsi.cellU());
228  hgcdigi_cellv_.emplace_back(idsi.cellV());
229  if (is_Simhit_comp_) {
230  double hit_energy = 0;
231  auto itr = simhits_ee.find(id);
232  if (itr != simhits_ee.end())
233  hit_energy = itr->second;
234  hgcdigi_simenergy_.emplace_back(hit_energy);
235  }
236  }
237 
238  for (const auto& digi : fh_digis) {
239  const DetId id(digi.id());
240  hgcdigi_id_.emplace_back(id.rawId());
241  hgcdigi_subdet_.emplace_back(id.det());
242  hgcdigi_side_.emplace_back(triggerTools_.zside(id));
243  hgcdigi_layer_.emplace_back(triggerTools_.layerWithOffset(id));
245  hgcdigi_eta_.emplace_back(cellpos.eta());
246  hgcdigi_phi_.emplace_back(cellpos.phi());
247  hgcdigi_z_.emplace_back(cellpos.z());
248  for (unsigned int i = 0; i < digiBXselect_.size(); i++) {
249  hgcdigi_data_[i].emplace_back(digi[digiBXselect_[i]].data());
250  hgcdigi_isadc_[i].emplace_back(!digi[digiBXselect_[i]].mode());
251  }
252  const HGCSiliconDetId idsi(digi.id());
253  hgcdigi_waferu_.emplace_back(idsi.waferU());
254  hgcdigi_waferv_.emplace_back(idsi.waferV());
255  hgcdigi_wafertype_.emplace_back(idsi.type());
256  hgcdigi_cellu_.emplace_back(idsi.cellU());
257  hgcdigi_cellv_.emplace_back(idsi.cellV());
258  if (is_Simhit_comp_) {
259  double hit_energy = 0;
260  auto itr = simhits_fh.find(id);
261  if (itr != simhits_fh.end())
262  hit_energy = itr->second;
263  hgcdigi_simenergy_.emplace_back(hit_energy);
264  }
265  }
266 
267  for (const auto& digi : bh_digis) {
268  const DetId id(digi.id());
269  bhdigi_id_.emplace_back(id.rawId());
270  bhdigi_subdet_.emplace_back(id.det());
271  bhdigi_side_.emplace_back(triggerTools_.zside(id));
272  bhdigi_layer_.emplace_back(triggerTools_.layerWithOffset(id));
274  bhdigi_eta_.emplace_back(cellpos.eta());
275  bhdigi_phi_.emplace_back(cellpos.phi());
276  bhdigi_z_.emplace_back(cellpos.z());
277  for (unsigned int i = 0; i < digiBXselect_.size(); i++) {
278  bhdigi_data_[i].emplace_back(digi[digiBXselect_[i]].data());
279  bhdigi_isadc_[i].emplace_back(!digi[digiBXselect_[i]].mode());
280  }
281  const HGCScintillatorDetId idsci(digi.id());
282  bhdigi_ieta_.emplace_back(idsci.ietaAbs());
283  bhdigi_iphi_.emplace_back(idsci.iphi());
284  if (is_Simhit_comp_) {
285  double hit_energy = 0;
286  auto itr = simhits_bh.find(id);
287  if (itr != simhits_bh.end())
288  hit_energy = itr->second;
289  bhdigi_simenergy_.emplace_back(hit_energy);
290  }
291  }
292 }
293 
295  std::unordered_map<uint32_t, double>& simhits_ee,
296  std::unordered_map<uint32_t, double>& simhits_fh,
297  std::unordered_map<uint32_t, double>& simhits_bh) {
299  e.getByToken(SimHits_inputee_, ee_simhits_h);
300  const edm::PCaloHitContainer& ee_simhits = *ee_simhits_h;
302  e.getByToken(SimHits_inputfh_, fh_simhits_h);
303  const edm::PCaloHitContainer& fh_simhits = *fh_simhits_h;
305  e.getByToken(SimHits_inputbh_, bh_simhits_h);
306  const edm::PCaloHitContainer& bh_simhits = *bh_simhits_h;
307 
308  //EE
309  for (const auto& simhit : ee_simhits) {
311  if (id.rawId() == 0)
312  continue;
313  auto itr_insert = simhits_ee.emplace(id, 0.);
314  itr_insert.first->second += simhit.energy();
315  }
316  // FH
317  for (const auto& simhit : fh_simhits) {
319  if (id.rawId() == 0)
320  continue;
321  auto itr_insert = simhits_fh.emplace(id, 0.);
322  itr_insert.first->second += simhit.energy();
323  }
324  // BH
325  for (const auto& simhit : bh_simhits) {
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_waferu_.clear();
341  hgcdigi_waferv_.clear();
342  hgcdigi_wafertype_.clear();
343  hgcdigi_cellu_.clear();
344  hgcdigi_cellv_.clear();
345  hgcdigi_eta_.clear();
346  hgcdigi_phi_.clear();
347  hgcdigi_z_.clear();
348  for (unsigned int i = 0; i < digiBXselect_.size(); i++) {
349  hgcdigi_data_[i].clear();
350  hgcdigi_isadc_[i].clear();
351  }
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  for (unsigned int i = 0; i < digiBXselect_.size(); i++) {
366  bhdigi_data_[i].clear();
367  bhdigi_isadc_[i].clear();
368  }
369  if (is_Simhit_comp_)
370  bhdigi_simenergy_.clear();
371 }
std::vector< PCaloHit > PCaloHitContainer
std::vector< std::vector< uint32_t > > bhdigi_data_
uint16_t *__restrict__ id
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
static constexpr unsigned kDigiSize_
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
def unique
Definition: tier0.py:24
std::string to_string(const V &value)
Definition: OMSAccess.h:71
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 HGCalTriggerGeometryBase * getTriggerGeometry() const
unsigned layerWithOffset(const DetId &) const
edm::ESHandle< HGCalTriggerGeometryBase > geometry
void setGeometry(const HGCalTriggerGeometryBase *const)
void fill(const edm::Event &e, const HGCalTriggerNtupleEventSetup &es) final
void initialize(TTree &, const edm::ParameterSet &, edm::ConsumesCollector &&) final
std::vector< std::vector< int > > bhdigi_isadc_
int zside(const DetId &) const
T z() const
Definition: PV3DBase.h:61
HGCalTriggerNtupleHGCDigis(const edm::ParameterSet &conf)
const HGCalGeometry * hsiGeometry() const
Definition: DetId.h:17
const HGCalGeometry * hscGeometry() const
const HGCalTopology & hscTopology() const
T const * product() const
Definition: ESHandle.h:86
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
T eta() const
Definition: PV3DBase.h:73
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
std::vector< std::vector< int > > hgcdigi_isadc_
size_type size() const
GlobalPoint getPosition(const DetId &id, bool debug=false) const
std::vector< std::vector< uint32_t > > hgcdigi_data_
#define DEFINE_EDM_PLUGIN(factory, type, name)
DetId simToReco(const DetId &, const HGCalTopology &) const
std::vector< unsigned int > digiBXselect_
const HGCalTopology & fhTopology() const