CMS 3D CMS Logo

HGCalTriggerNtupleHGCDigis.cc
Go to the documentation of this file.
8 
11 
16 
18 {
19 
20  public:
23  virtual void initialize(TTree&, const edm::ParameterSet&, edm::ConsumesCollector&&) override final;
24  virtual void fill(const edm::Event& e, const edm::EventSetup& es) override final;
25 
26  private:
27  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);
28  virtual void clear() override final;
29 
33 
34  int hgcdigi_n_ ;
35  std::vector<int> hgcdigi_id_;
36  std::vector<int> hgcdigi_subdet_;
37  std::vector<int> hgcdigi_side_;
38  std::vector<int> hgcdigi_layer_;
39  std::vector<int> hgcdigi_wafer_;
40  std::vector<int> hgcdigi_wafertype_ ;
41  std::vector<int> hgcdigi_cell_;
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 
49  int bhdigi_n_ ;
50  std::vector<int> bhdigi_id_;
51  std::vector<int> bhdigi_subdet_;
52  std::vector<int> bhdigi_side_;
53  std::vector<int> bhdigi_layer_;
54  std::vector<int> bhdigi_ieta_;
55  std::vector<int> bhdigi_iphi_;
56  std::vector<float> bhdigi_eta_;
57  std::vector<float> bhdigi_phi_;
58  std::vector<float> bhdigi_z_;
59  std::vector<uint32_t> bhdigi_data_;
60  std::vector<float> bhdigi_simenergy_;
61 
63 
64 };
65 
68  "HGCalTriggerNtupleHGCDigis" );
69 
70 
73 {
74  is_Simhit_comp_ = conf.getParameter<bool>("isSimhitComp");
75 
76 }
77 
78 void
80 initialize(TTree& tree, const edm::ParameterSet& conf, edm::ConsumesCollector&& collector)
81 {
82 
83  ee_token_ = collector.consumes<HGCEEDigiCollection>(conf.getParameter<edm::InputTag>("HGCDigisEE"));
84  fh_token_ = collector.consumes<HGCHEDigiCollection>(conf.getParameter<edm::InputTag>("HGCDigisFH"));
85  bh_token_ = collector.consumes<HGCBHDigiCollection>(conf.getParameter<edm::InputTag>("HGCDigisBH"));
86  if (is_Simhit_comp_) {
87  SimHits_inputee_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("eeSimHits"));
88  SimHits_inputfh_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("fhSimHits"));
89  SimHits_inputbh_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("bhSimHits"));
90  }
91  tree.Branch("hgcdigi_n", &hgcdigi_n_, "hgcdigi_n/I");
92  tree.Branch("hgcdigi_id", &hgcdigi_id_);
93  tree.Branch("hgcdigi_subdet", &hgcdigi_subdet_);
94  tree.Branch("hgcdigi_zside", &hgcdigi_side_);
95  tree.Branch("hgcdigi_layer", &hgcdigi_layer_);
96  tree.Branch("hgcdigi_wafer", &hgcdigi_wafer_);
97  tree.Branch("hgcdigi_wafertype", &hgcdigi_wafertype_);
98  tree.Branch("hgcdigi_cell", &hgcdigi_cell_);
99  tree.Branch("hgcdigi_eta", &hgcdigi_eta_);
100  tree.Branch("hgcdigi_phi", &hgcdigi_phi_);
101  tree.Branch("hgcdigi_z", &hgcdigi_z_);
102  tree.Branch("hgcdigi_data", &hgcdigi_data_);
103  tree.Branch("hgcdigi_isadc", &hgcdigi_isadc_);
104  if (is_Simhit_comp_) tree.Branch("hgcdigi_simenergy", &hgcdigi_simenergy_);
105 
106  tree.Branch("bhdigi_n", &bhdigi_n_, "bhdigi_n/I");
107  tree.Branch("bhdigi_id", &bhdigi_id_);
108  tree.Branch("bhdigi_subdet", &bhdigi_subdet_);
109  tree.Branch("bhdigi_zside", &bhdigi_side_);
110  tree.Branch("bhdigi_layer", &bhdigi_layer_);
111  tree.Branch("bhdigi_ieta", &bhdigi_ieta_);
112  tree.Branch("bhdigi_iphi", &bhdigi_iphi_);
113  tree.Branch("bhdigi_eta", &bhdigi_eta_);
114  tree.Branch("bhdigi_phi", &bhdigi_phi_);
115  tree.Branch("bhdigi_z", &bhdigi_z_);
116  tree.Branch("bhdigi_data", &bhdigi_data_);
117  if (is_Simhit_comp_) tree.Branch("bhdigi_simenergy", &bhdigi_simenergy_);
118 }
119 
120 void
122 fill(const edm::Event& e, const edm::EventSetup& es)
123 {
125 
127  e.getByToken(ee_token_, ee_digis_h);
128  const HGCEEDigiCollection& ee_digis = *ee_digis_h;
130  e.getByToken(fh_token_, fh_digis_h);
131  const HGCHEDigiCollection& fh_digis = *fh_digis_h;
133  e.getByToken(bh_token_, bh_digis_h);
134  const HGCBHDigiCollection& bh_digis = *bh_digis_h;
135 
136  // sim hit association
137  std::unordered_map<uint32_t, double> simhits_ee;
138  std::unordered_map<uint32_t, double> simhits_fh;
139  std::unordered_map<uint32_t, double> simhits_bh;
140  if (is_Simhit_comp_) simhits(e, simhits_ee, simhits_fh, simhits_bh);
141 
142  clear();
143  hgcdigi_n_ = ee_digis.size() + fh_digis.size();
144  hgcdigi_id_.reserve(hgcdigi_n_);
145  hgcdigi_subdet_.reserve(hgcdigi_n_);
146  hgcdigi_side_.reserve(hgcdigi_n_);
147  hgcdigi_layer_.reserve(hgcdigi_n_);
148  hgcdigi_wafer_.reserve(hgcdigi_n_);
150  hgcdigi_cell_.reserve(hgcdigi_n_);
151  hgcdigi_eta_.reserve(hgcdigi_n_);
152  hgcdigi_phi_.reserve(hgcdigi_n_);
153  hgcdigi_z_.reserve(hgcdigi_n_);
154  hgcdigi_data_.reserve(hgcdigi_n_);
155  hgcdigi_isadc_.reserve(hgcdigi_n_);
157 
158  bhdigi_n_ = bh_digis.size();
159  bhdigi_id_.reserve(bhdigi_n_);
160  bhdigi_subdet_.reserve(bhdigi_n_);
161  bhdigi_side_.reserve(bhdigi_n_);
162  bhdigi_layer_.reserve(bhdigi_n_);
163  bhdigi_ieta_.reserve(bhdigi_n_);
164  bhdigi_iphi_.reserve(bhdigi_n_);
165  bhdigi_eta_.reserve(bhdigi_n_);
166  bhdigi_phi_.reserve(bhdigi_n_);
167  bhdigi_z_.reserve(bhdigi_n_);
169 
170  const int kIntimeSample = 2;
171  for(const auto& digi : ee_digis)
172  {
173  const HGCalDetId id(digi.id());
174  hgcdigi_id_.emplace_back(id.rawId());
176  hgcdigi_side_.emplace_back(id.zside());
177  hgcdigi_layer_.emplace_back(id.layer());
178  hgcdigi_wafer_.emplace_back(id.wafer());
179  hgcdigi_wafertype_.emplace_back(id.waferType());
180  hgcdigi_cell_.emplace_back(id.cell());
181  GlobalPoint cellpos = triggerGeometry_->eeGeometry().getPosition(id.rawId());
182  hgcdigi_eta_.emplace_back(cellpos.eta());
183  hgcdigi_phi_.emplace_back(cellpos.phi());
184  hgcdigi_z_.emplace_back(cellpos.z());
185  hgcdigi_data_.emplace_back(digi[kIntimeSample].data());
186  int is_adc=0;
187  if (!(digi[kIntimeSample].mode())) is_adc =1;
188  hgcdigi_isadc_.emplace_back(is_adc);
189  if (is_Simhit_comp_) {
190  double hit_energy=0;
191  auto itr = simhits_ee.find(id);
192  if(itr!=simhits_ee.end())hit_energy = itr->second;
193  hgcdigi_simenergy_.emplace_back(hit_energy);
194  }
195  }
196 
197  for(const auto& digi : fh_digis)
198  {
199  const HGCalDetId id(digi.id());
200  hgcdigi_id_.emplace_back(id.rawId());
202  hgcdigi_side_.emplace_back(id.zside());
203  hgcdigi_layer_.emplace_back(id.layer());
204  hgcdigi_wafer_.emplace_back(id.wafer());
205  hgcdigi_wafertype_.emplace_back(id.waferType());
206  hgcdigi_cell_.emplace_back(id.cell());
207  GlobalPoint cellpos = triggerGeometry_->fhGeometry().getPosition(id.rawId());
208  hgcdigi_eta_.emplace_back(cellpos.eta());
209  hgcdigi_phi_.emplace_back(cellpos.phi());
210  hgcdigi_z_.emplace_back(cellpos.z());
211  hgcdigi_data_.emplace_back(digi[kIntimeSample].data());
212  int is_adc=0;
213  if (!(digi[kIntimeSample].mode())) is_adc =1;
214  hgcdigi_isadc_.emplace_back(is_adc);
215  if (is_Simhit_comp_) {
216  double hit_energy=0;
217  auto itr = simhits_fh.find(id);
218  if(itr!=simhits_fh.end())hit_energy = itr->second;
219  hgcdigi_simenergy_.emplace_back(hit_energy);
220  }
221  }
222 
223  for(const auto& digi : bh_digis)
224  {
225  const HcalDetId id(digi.id());
226  bhdigi_id_.emplace_back(id.rawId());
227  bhdigi_subdet_.emplace_back(id.subdetId());
228  bhdigi_side_.emplace_back(id.zside());
229  bhdigi_layer_.emplace_back(id.depth());
230  bhdigi_ieta_.emplace_back(id.ieta());
231  bhdigi_iphi_.emplace_back(id.iphi());
232  GlobalPoint cellpos = triggerGeometry_->bhGeometry().getPosition(id.rawId());
233  bhdigi_eta_.emplace_back(cellpos.eta());
234  bhdigi_phi_.emplace_back(cellpos.phi());
235  bhdigi_z_.emplace_back(cellpos.z());
236  bhdigi_data_.emplace_back(digi[kIntimeSample].data());
237  if (is_Simhit_comp_) {
238  double hit_energy=0;
239  auto itr = simhits_bh.find(id);
240  if(itr!=simhits_bh.end())hit_energy = itr->second;
241  bhdigi_simenergy_.emplace_back(hit_energy);
242  }
243  }
244 }
245 
246 void
248 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)
249 {
250 
252  e.getByToken(SimHits_inputee_,ee_simhits_h);
253  const edm::PCaloHitContainer& ee_simhits = *ee_simhits_h;
255  e.getByToken(SimHits_inputfh_,fh_simhits_h);
256  const edm::PCaloHitContainer& fh_simhits = *fh_simhits_h;
258  e.getByToken(SimHits_inputbh_,bh_simhits_h);
259  const edm::PCaloHitContainer& bh_simhits = *bh_simhits_h;
260 
261  //EE
262  int layer=0,cell=0, sec=0, subsec=0, zp=0,subdet=0;
263  ForwardSubdetector mysubdet;
264 
265  for( const auto& simhit : ee_simhits ) {
266  HGCalTestNumbering::unpackHexagonIndex(simhit.id(), subdet, zp, layer, sec, subsec, cell);
267  mysubdet = (ForwardSubdetector)(subdet);
268  std::pair<int,int> recoLayerCell = triggerGeometry_->eeTopology().dddConstants().simToReco(cell,layer,sec,triggerGeometry_->eeTopology().detectorType());
269  cell = recoLayerCell.first;
270  layer = recoLayerCell.second;
271  if (layer<0 || cell<0) {
272  continue;
273  }
274  auto itr_insert = simhits_ee.emplace(HGCalDetId(mysubdet,zp,layer,subsec,sec,cell), 0.);
275  itr_insert.first->second += simhit.energy();
276  }
277 
278  // FH
279  layer=0; cell=0; sec=0; subsec=0; zp=0; subdet=0;
280 
281  for( const auto& simhit : fh_simhits ) {
282  HGCalTestNumbering::unpackHexagonIndex(simhit.id(), subdet, zp, layer, sec, subsec, cell);
283  mysubdet = (ForwardSubdetector)(subdet);
284  std::pair<int,int> recoLayerCell = triggerGeometry_->fhTopology().dddConstants().simToReco(cell,layer,sec,triggerGeometry_->fhTopology().detectorType());
285  cell = recoLayerCell.first;
286  layer = recoLayerCell.second;
287  if (layer<0 || cell<0) {
288  continue;
289  }
290  auto itr_insert = simhits_fh.emplace(HGCalDetId(mysubdet,zp,layer,subsec,sec,cell), 0.);
291  itr_insert.first->second += simhit.energy();
292  }
293  // BH
294  for( const auto& simhit : bh_simhits ) {
296  if (id.subdetId()!=HcalEndcap) continue;
297  auto itr_insert = simhits_bh.emplace(id, 0.);
298  itr_insert.first->second += simhit.energy();
299  }
300 }
301 
302 
303 void
306 {
307  hgcdigi_n_ = 0;
308  hgcdigi_id_.clear();
309  hgcdigi_subdet_.clear();
310  hgcdigi_side_.clear();
311  hgcdigi_layer_.clear();
312  hgcdigi_wafer_.clear();
313  hgcdigi_wafertype_.clear();
314  hgcdigi_cell_.clear();
315  hgcdigi_eta_.clear();
316  hgcdigi_phi_.clear();
317  hgcdigi_z_.clear();
318  hgcdigi_data_.clear();
319  hgcdigi_isadc_.clear();
320  if (is_Simhit_comp_) hgcdigi_simenergy_.clear();
321 
322  bhdigi_n_ = 0;
323  bhdigi_id_.clear();
324  bhdigi_subdet_.clear();
325  bhdigi_side_.clear();
326  bhdigi_layer_.clear();
327  bhdigi_ieta_.clear();
328  bhdigi_iphi_.clear();
329  bhdigi_eta_.clear();
330  bhdigi_phi_.clear();
331  bhdigi_z_.clear();
332  bhdigi_data_.clear();
333  if (is_Simhit_comp_) bhdigi_simenergy_.clear();
334 }
335 
336 
337 
338 
const HGCalGeometry & eeGeometry() const
T getParameter(std::string const &) const
const HcalDDDRecConstants * dddConstants() const
Definition: HcalTopology.h:161
std::vector< PCaloHit > PCaloHitContainer
const HGCalGeometry & fhGeometry() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
const HGCalTopology & eeTopology() const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
virtual void initialize(TTree &, const edm::ParameterSet &, edm::ConsumesCollector &&) override final
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
bool detectorType() const
ForwardSubdetector
std::vector< uint32_t > hgcdigi_data_
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
const HcalTopology & bhTopology() const
T z() const
Definition: PV3DBase.h:64
HGCalTriggerNtupleHGCDigis(const edm::ParameterSet &conf)
virtual void fill(const edm::Event &e, const edm::EventSetup &es) override final
GlobalPoint getPosition(const DetId &id) const
std::vector< uint32_t > bhdigi_data_
const HGCalDDDConstants & dddConstants() const
const T & get() const
Definition: EventSetup.h:55
T eta() const
Definition: PV3DBase.h:76
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
size_type size() const
virtual void clear() override final
#define DEFINE_EDM_PLUGIN(factory, type, name)
DetId relabel(const uint32_t testId) const
Definition: tree.py:1
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
const HGCalTopology & fhTopology() const
const HcalGeometry & bhGeometry() const