CMS 3D CMS Logo

HGCalTriggerNtupleHGCDigis.cc
Go to the documentation of this file.
7 
11 
13 {
14 
15  public:
18  virtual void initialize(TTree&, const edm::ParameterSet&, edm::ConsumesCollector&&) override final;
19  virtual void fill(const edm::Event& e, const edm::EventSetup& es) override final;
20 
21  private:
22  void simhits(const edm::Event& e, std::unordered_map<uint32_t, double>& simhits_ee, std::unordered_map<uint32_t, double>& simhits_fh);
23  virtual void clear() override final;
24 
28 
29  int hgcdigi_n_ ;
30  std::vector<int> hgcdigi_id_;
31  std::vector<int> hgcdigi_subdet_;
32  std::vector<int> hgcdigi_side_;
33  std::vector<int> hgcdigi_layer_;
34  std::vector<int> hgcdigi_wafer_;
35  std::vector<int> hgcdigi_wafertype_ ;
36  std::vector<int> hgcdigi_cell_;
37  std::vector<float> hgcdigi_eta_;
38  std::vector<float> hgcdigi_phi_;
39  std::vector<float> hgcdigi_z_;
40  std::vector<uint32_t> hgcdigi_data_;
41  std::vector<int> hgcdigi_isadc_;
42  std::vector<float> hgcdigi_simenergy_;
43 
46 
47 };
48 
51  "HGCalTriggerNtupleHGCDigis" );
52 
53 
56 {
57  is_Simhit_comp_ = conf.getParameter<bool>("isSimhitComp");
58 
59 }
60 
61 void
63 initialize(TTree& tree, const edm::ParameterSet& conf, edm::ConsumesCollector&& collector)
64 {
65 
66  ee_token_ = collector.consumes<HGCEEDigiCollection>(conf.getParameter<edm::InputTag>("HGCDigisEE"));
67  fh_token_ = collector.consumes<HGCHEDigiCollection>(conf.getParameter<edm::InputTag>("HGCDigisFH"));
68  if (is_Simhit_comp_) {
69  SimHits_inputee_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("eeSimHits"));
70  SimHits_inputfh_ = collector.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("fhSimHits"));
71  }
72  tree.Branch("hgcdigi_n", &hgcdigi_n_, "hgcdigi_n/I");
73  tree.Branch("hgcdigi_id", &hgcdigi_id_);
74  tree.Branch("hgcdigi_subdet", &hgcdigi_subdet_);
75  tree.Branch("hgcdigi_zside", &hgcdigi_side_);
76  tree.Branch("hgcdigi_layer", &hgcdigi_layer_);
77  tree.Branch("hgcdigi_wafer", &hgcdigi_wafer_);
78  tree.Branch("hgcdigi_wafertype", &hgcdigi_wafertype_);
79  tree.Branch("hgcdigi_cell", &hgcdigi_cell_);
80  tree.Branch("hgcdigi_eta", &hgcdigi_eta_);
81  tree.Branch("hgcdigi_phi", &hgcdigi_phi_);
82  tree.Branch("hgcdigi_z", &hgcdigi_z_);
83  tree.Branch("hgcdigi_data", &hgcdigi_data_);
84  tree.Branch("hgcdigi_isadc", &hgcdigi_isadc_);
85  if (is_Simhit_comp_) tree.Branch("hgcdigi_simenergy", &hgcdigi_simenergy_);
86 }
87 
88 void
90 fill(const edm::Event& e, const edm::EventSetup& es)
91 {
92 
93  es.get<IdealGeometryRecord>().get("HGCalEESensitive", geom_ee);
94  es.get<IdealGeometryRecord>().get("HGCalHESiliconSensitive", geom_fh);
95  es.get<IdealGeometryRecord>().get("HGCalEESensitive",topo_ee);
96  es.get<IdealGeometryRecord>().get("HGCalHESiliconSensitive",topo_fh);
98  e.getByToken(ee_token_, ee_digis_h);
99  const HGCEEDigiCollection& ee_digis = *ee_digis_h;
101  e.getByToken(fh_token_, fh_digis_h);
102  const HGCHEDigiCollection& fh_digis = *fh_digis_h;
103 
104  // sim hit association
105  std::unordered_map<uint32_t, double> simhits_ee;
106  std::unordered_map<uint32_t, double> simhits_fh;
107  if (is_Simhit_comp_) simhits(e, simhits_ee, simhits_fh);
108 
109  clear();
110  hgcdigi_n_ = ee_digis.size() + fh_digis.size();
111  hgcdigi_id_.reserve(hgcdigi_n_);
112  hgcdigi_subdet_.reserve(hgcdigi_n_);
113  hgcdigi_side_.reserve(hgcdigi_n_);
114  hgcdigi_layer_.reserve(hgcdigi_n_);
115  hgcdigi_wafer_.reserve(hgcdigi_n_);
117  hgcdigi_cell_.reserve(hgcdigi_n_);
118  hgcdigi_eta_.reserve(hgcdigi_n_);
119  hgcdigi_phi_.reserve(hgcdigi_n_);
120  hgcdigi_z_.reserve(hgcdigi_n_);
121  hgcdigi_data_.reserve(hgcdigi_n_);
122  hgcdigi_isadc_.reserve(hgcdigi_n_);
124 
125  for(const auto& digi : ee_digis)
126  {
127  const HGCalDetId id(digi.id());
128  hgcdigi_id_.emplace_back(id.rawId());
130  hgcdigi_side_.emplace_back(id.zside());
131  hgcdigi_layer_.emplace_back(id.layer());
132  hgcdigi_wafer_.emplace_back(id.wafer());
133  hgcdigi_wafertype_.emplace_back(id.waferType());
134  hgcdigi_cell_.emplace_back(id.cell());
135  GlobalPoint cellpos = geom_ee->getPosition(id.rawId());
136  hgcdigi_eta_.emplace_back(cellpos.eta());
137  hgcdigi_phi_.emplace_back(cellpos.phi());
138  hgcdigi_z_.emplace_back(cellpos.z());
139  hgcdigi_data_.emplace_back(digi[2].data());
140  int is_adc=0;
141  if (!(digi[2].mode())) is_adc =1;
142  hgcdigi_isadc_.emplace_back(is_adc);
143  if (is_Simhit_comp_) {
144  double hit_energy=0;
145  auto itr = simhits_ee.find(id);
146  if(itr!=simhits_ee.end())hit_energy = itr->second;
147  hgcdigi_simenergy_.emplace_back(hit_energy);
148  }
149  }
150 
151  for(const auto& digi : fh_digis)
152  {
153  const HGCalDetId id(digi.id());
154  hgcdigi_id_.emplace_back(id.rawId());
156  hgcdigi_side_.emplace_back(id.zside());
157  hgcdigi_layer_.emplace_back(id.layer());
158  hgcdigi_wafer_.emplace_back(id.wafer());
159  hgcdigi_wafertype_.emplace_back(id.waferType());
160  hgcdigi_cell_.emplace_back(id.cell());
161  GlobalPoint cellpos = geom_fh->getPosition(id.rawId());
162  hgcdigi_eta_.emplace_back(cellpos.eta());
163  hgcdigi_phi_.emplace_back(cellpos.phi());
164  hgcdigi_z_.emplace_back(cellpos.z());
165  hgcdigi_data_.emplace_back(digi[2].data());
166  int is_adc=0;
167  if (!(digi[2].mode())) is_adc =1;
168  hgcdigi_isadc_.emplace_back(is_adc);
169  if (is_Simhit_comp_) {
170  double hit_energy=0;
171  auto itr = simhits_fh.find(id);
172  if(itr!=simhits_fh.end())hit_energy = itr->second;
173  hgcdigi_simenergy_.emplace_back(hit_energy);
174  }
175  }
176 }
177 
178 void
180 simhits(const edm::Event& e, std::unordered_map<uint32_t, double>& simhits_ee, std::unordered_map<uint32_t, double>& simhits_fh)
181 {
182 
184  e.getByToken(SimHits_inputee_,ee_simhits_h);
185  const edm::PCaloHitContainer& ee_simhits = *ee_simhits_h;
187  e.getByToken(SimHits_inputfh_,fh_simhits_h);
188  const edm::PCaloHitContainer& fh_simhits = *fh_simhits_h;
189 
190  //EE
191  int layer=0,cell=0, sec=0, subsec=0, zp=0,subdet=0;
192  ForwardSubdetector mysubdet;
193 
194  for( const auto& simhit : ee_simhits ) {
195  HGCalTestNumbering::unpackHexagonIndex(simhit.id(), subdet, zp, layer, sec, subsec, cell);
196  mysubdet = (ForwardSubdetector)(subdet);
197  std::pair<int,int> recoLayerCell = topo_ee->dddConstants().simToReco(cell,layer,sec,topo_ee->detectorType());
198  cell = recoLayerCell.first;
199  layer = recoLayerCell.second;
200  if (layer<0 || cell<0) {
201  continue;
202  }
203  auto itr_insert = simhits_ee.emplace(HGCalDetId(mysubdet,zp,layer,subsec,sec,cell), 0.);
204  itr_insert.first->second += simhit.energy();
205  }
206 
207  // FH
208  layer=0; cell=0; sec=0; subsec=0; zp=0; subdet=0;
209 
210  for( const auto& simhit : fh_simhits ) {
211  HGCalTestNumbering::unpackHexagonIndex(simhit.id(), subdet, zp, layer, sec, subsec, cell);
212  mysubdet = (ForwardSubdetector)(subdet);
213  std::pair<int,int> recoLayerCell = topo_fh->dddConstants().simToReco(cell,layer,sec,topo_fh->detectorType());
214  cell = recoLayerCell.first;
215  layer = recoLayerCell.second;
216  if (layer<0 || cell<0) {
217  continue;
218  }
219  auto itr_insert = simhits_fh.emplace(HGCalDetId(mysubdet,zp,layer,subsec,sec,cell), 0.);
220  itr_insert.first->second += simhit.energy();
221  }
222 }
223 
224 
225 void
228 {
229  hgcdigi_n_ = 0;
230  hgcdigi_id_.clear();
231  hgcdigi_subdet_.clear();
232  hgcdigi_side_.clear();
233  hgcdigi_layer_.clear();
234  hgcdigi_wafer_.clear();
235  hgcdigi_wafertype_.clear();
236  hgcdigi_cell_.clear();
237  hgcdigi_eta_.clear();
238  hgcdigi_phi_.clear();
239  hgcdigi_z_.clear();
240  hgcdigi_data_.clear();
241  hgcdigi_isadc_.clear();
242  if (is_Simhit_comp_) hgcdigi_simenergy_.clear();
243 }
244 
245 
246 
247 
edm::ESHandle< HGCalTopology > topo_fh
T getParameter(std::string const &) const
std::vector< PCaloHit > PCaloHitContainer
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
edm::ESHandle< HGCalGeometry > geom_fh
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
edm::ESHandle< HGCalGeometry > geom_ee
virtual void initialize(TTree &, const edm::ParameterSet &, edm::ConsumesCollector &&) override final
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
T z() const
Definition: PV3DBase.h:64
HGCalTriggerNtupleHGCDigis(const edm::ParameterSet &conf)
void simhits(const edm::Event &e, std::unordered_map< uint32_t, double > &simhits_ee, std::unordered_map< uint32_t, double > &simhits_fh)
virtual void fill(const edm::Event &e, const edm::EventSetup &es) override final
edm::ESHandle< HGCalTopology > topo_ee
const HGCalDDDConstants & dddConstants() const
const T & get() const
Definition: EventSetup.h:56
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)
Definition: tree.py:1
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)