CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA > Class Template Reference
Inheritance diagram for HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >:
HGCalTriggerBackend::Algorithm< FECODEC > HGCalTriggerBackendAlgorithmBase

Public Member Functions

 HGCalTriggerSimCluster (const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
 
void putInEvent (edm::Event &evt) final
 
void reset () final
 
void run (const l1t::HGCFETriggerDigiCollection &coll, const edm::EventSetup &es, edm::Event &evt) override
 
void setProduces (edm::stream::EDProducer<> &prod) const final
 
- Public Member Functions inherited from HGCalTriggerBackend::Algorithm< FECODEC >
 Algorithm (const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
 
void setGeometry (const HGCalTriggerGeometryBase *const geom) final
 
- Public Member Functions inherited from HGCalTriggerBackendAlgorithmBase
 HGCalTriggerBackendAlgorithmBase (const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
 
const std::string & name () const
 
virtual ~HGCalTriggerBackendAlgorithmBase ()
 

Private Member Functions

void addToCluster (std::unordered_map< uint64_t, std::pair< int, l1t::HGCalCluster > > &cluster_container, uint64_t pid, int pdgid, float energy, float eta, float phi)
 
void addToClusterShapes (std::unordered_map< uint64_t, std::pair< int, l1t::HGCalCluster > > &cluster_container, uint64_t pid, int pdgid, float energy, float eta, float phi, float r=0.0)
 

Private Attributes

HGCalTriggerCellCalibration calibration_
 
std::unique_ptr< l1t::HGCalClusterBxCollectioncluster_product_
 
std::string HGCalEESensitive_
 
std::string HGCalHESiliconSensitive_
 
edm::ESHandle< HGCalTopologyhgceeTopoHandle_
 
edm::ESHandle< HGCalTopologyhgchefTopoHandle_
 
edm::EDGetToken inputbh_
 
edm::EDGetToken inputee_
 
edm::EDGetToken inputfh_
 
edm::Handle< std::vector< SimCluster > > sim_handle_
 
edm::EDGetTokenT< std::vector< SimCluster > > sim_token_
 

Additional Inherited Members

- Protected Attributes inherited from HGCalTriggerBackend::Algorithm< FECODEC >
FECODEC codec_
 
- Protected Attributes inherited from HGCalTriggerBackendAlgorithmBase
const HGCalTriggerGeometryBasegeometry_
 

Detailed Description

template<typename FECODEC, typename DATA>
class HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >

Definition at line 52 of file HGCalSimCluster.cc.

Constructor & Destructor Documentation

template<typename FECODEC , typename DATA >
HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::HGCalTriggerSimCluster ( const edm::ParameterSet conf,
edm::ConsumesCollector cc 
)
inline

Definition at line 117 of file HGCalSimCluster.cc.

References edm::ConsumesCollector::consumes(), and edm::ParameterSet::getParameter().

117  :
118  Algorithm<FECODEC>(conf,cc),
119  HGCalEESensitive_(conf.getParameter<std::string>("HGCalEESensitive_tag")),
120  HGCalHESiliconSensitive_(conf.getParameter<std::string>("HGCalHESiliconSensitive_tag")),
121  calibration_(conf.getParameterSet("calib_parameters"))
122  {
123  sim_token_ = cc.consumes< std::vector< SimCluster > >(conf.getParameter<edm::InputTag>("simcollection"));
126  // inputbh_ = cc.consumes<edm::PCaloHitContainer>(conf.getParameter<edm::InputTag>("g4SimHits:HGCHitsHEback"));
127  edm::LogWarning("HGCalTriggerSimCluster") <<"WARNING: BH simhits not loaded";
128  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
std::vector< PCaloHit > PCaloHitContainer
HGCalTriggerCellCalibration calibration_
edm::EDGetTokenT< std::vector< SimCluster > > sim_token_
ParameterSet const & getParameterSet(std::string const &) const

Member Function Documentation

template<typename FECODEC , typename DATA >
void HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::addToCluster ( std::unordered_map< uint64_t, std::pair< int, l1t::HGCalCluster > > &  cluster_container,
uint64_t  pid,
int  pdgid,
float  energy,
float  eta,
float  phi 
)
inlineprivate

Definition at line 80 of file HGCalSimCluster.cc.

References PVValHelper::eta, JetChargeProducer_cfi::exp, ResonanceBuilder::mass, p4, EnergyCorrector::pt, reco::return(), edm::second(), and lumiQTWidget::t.

Referenced by HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::run().

81  {
82 
83  auto pair = cluster_container.emplace(pid, std::pair<int,l1t::HGCalCluster>(0,l1t::HGCalCluster() ) ) ;
84  auto iterator = pair.first;
86  p4.SetPt ( iterator -> second . second . pt() ) ;
87  p4.SetEta( iterator -> second . second . eta() ) ;
88  p4.SetPhi( iterator -> second . second . phi() ) ;
89  p4.SetM ( iterator -> second . second . mass() ) ;
91  float t = std::exp (- eta);
92  pp4.SetPt ( energy * (2*t)/(1+t*t) ) ;
93  pp4.SetEta( eta ) ;
94  pp4.SetPhi( phi ) ;
95  pp4.SetM ( 0 ) ;
96  p4 += pp4;
97  iterator -> second . second . setP4(p4);
98  //iterator -> second . second . shapes().Add( energy,eta,phi,r); // last is r, for 3d clusters
99  return ;
100  }
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > PtEtaPhiMLorentzVectorD
Lorentz vector with cartesian internal representation.
Definition: LorentzVector.h:10
U second(std::pair< T, U > const &p)
double p4[4]
Definition: TauolaWrapper.h:92
return(e1-e2)*(e1-e2)+dp *dp
template<typename FECODEC , typename DATA >
void HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::addToClusterShapes ( std::unordered_map< uint64_t, std::pair< int, l1t::HGCalCluster > > &  cluster_container,
uint64_t  pid,
int  pdgid,
float  energy,
float  eta,
float  phi,
float  r = 0.0 
)
inlineprivate

Definition at line 74 of file HGCalSimCluster.cc.

References alignCSCRings::r, and edm::second().

Referenced by HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::run().

74  {
75  auto pair = cluster_container.emplace(pid, std::pair<int,l1t::HGCalCluster>(0,l1t::HGCalCluster() ) ) ;
76  auto iterator = pair.first;
77  iterator -> second . second . shapes().Add( energy,eta,phi,r); // last is r, for 3d clusters
78  }
U second(std::pair< T, U > const &p)
template<typename FECODEC , typename DATA >
void HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::putInEvent ( edm::Event evt)
inlinefinalvirtual

Implements HGCalTriggerBackendAlgorithmBase.

Definition at line 137 of file HGCalSimCluster.cc.

References eostools::move(), and HGCalTriggerBackendAlgorithmBase::name().

138  {
140  }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
std::unique_ptr< l1t::HGCalClusterBxCollection > cluster_product_
def move(src, dest)
Definition: eostools.py:510
template<typename FECODEC , typename DATA >
void HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::reset ( void  )
inlinefinalvirtual

Implements HGCalTriggerBackendAlgorithmBase.

Definition at line 143 of file HGCalSimCluster.cc.

144  {
146  }
std::unique_ptr< l1t::HGCalClusterBxCollection > cluster_product_
template<typename FECODEC , typename DATA >
void HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::run ( const l1t::HGCFETriggerDigiCollection coll,
const edm::EventSetup es,
edm::Event evt 
)
inlineoverridevirtual

FIXME TODO

Implements HGCalTriggerBackendAlgorithmBase.

Definition at line 149 of file HGCalSimCluster.cc.

References HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::addToCluster(), HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::addToClusterShapes(), HGCalTriggerCellCalibration::calibrateInGeV(), HGCalTriggerBackend::Algorithm< FECODEC >::codec_, cscdqm::DATA, data, HGCalTopology::dddConstants(), HGCalTopology::detectorType(), PVValHelper::eta, Exception, dedxEstimators_cff::fraction, HGCalTriggerBackendAlgorithmBase::geometry_, edm::EventSetup::get(), edm::Event::getByToken(), HGCalTriggerGeometryBase::getCellsFromTriggerCell(), photonIsolationHIProducer_cfi::hf, edm::HandleBase::isValid(), AlCaHLTBitMon_ParallelJobs::p, HadronAndPartonSelector_cfi::particles, sysUtil::pid, HGCalDDDConstants::simToReco(), and HGCalTestNumbering::unpackHexagonIndex().

153  {
154  //0.5. Get Digis, construct a map, detid -> energy
155 
157  evt.getByToken(inputee_,ee_simhits_h);
158 
160  evt.getByToken(inputfh_,fh_simhits_h);
161 
163  //evt.getByToken(inputbh_,bh_simhits_h);
164 
165 
166  if (not ee_simhits_h.isValid()){
167  throw cms::Exception("ContentError")<<"[HGCalTriggerSimCluster]::[run]::[ERROR] EE Digis from HGC not available";
168  }
169  if (not fh_simhits_h.isValid()){
170  throw cms::Exception("ContentError")<<"[HGCalTriggerSimCluster]::[run]::[ERROR] FH Digis from HGC not available";
171  }
172 
173  std::unordered_map<uint64_t, double> hgc_simhit_energy;
174 
175  edm::ESHandle<HGCalTopology> topo_ee, topo_fh;
176  es.get<IdealGeometryRecord>().get("HGCalEESensitive",topo_ee);
177  es.get<IdealGeometryRecord>().get("HGCalHESiliconSensitive",topo_fh);
178 
179  if (ee_simhits_h.isValid())
180  {
181  int layer=0,cell=0, sec=0, subsec=0, zp=0,subdet=0;
182  ForwardSubdetector mysubdet;
183  for (const auto& simhit : *ee_simhits_h)
184  {
185  HGCalTestNumbering::unpackHexagonIndex(simhit.id(), subdet, zp, layer, sec, subsec, cell);
186  mysubdet = (ForwardSubdetector)(subdet);
187  std::pair<int,int> recoLayerCell = topo_ee->dddConstants().simToReco(cell,layer,sec,topo_ee->detectorType());
188  cell = recoLayerCell.first;
189  layer = recoLayerCell.second;
190  if (layer<0 || cell<0) {
191  continue;
192  }
193  unsigned recoCell = HGCalDetId(mysubdet,zp,layer,subsec,sec,cell);
194 
195  hgc_simhit_energy[recoCell] += simhit.energy();
196  }
197  }
198  if (fh_simhits_h.isValid())
199  {
200  int layer=0,cell=0, sec=0, subsec=0, zp=0,subdet=0;
201  ForwardSubdetector mysubdet;
202  for (const auto& simhit : *fh_simhits_h)
203  {
204  HGCalTestNumbering::unpackHexagonIndex(simhit.id(), subdet, zp, layer, sec, subsec, cell);
205  mysubdet = (ForwardSubdetector)(subdet);
206  std::pair<int,int> recoLayerCell = topo_fh->dddConstants().simToReco(cell,layer,sec,topo_fh->detectorType());
207  cell = recoLayerCell.first;
208  layer = recoLayerCell.second;
209  if (layer<0 || cell<0) {
210  continue;
211  }
212  unsigned recoCell = HGCalDetId(mysubdet,zp,layer,subsec,sec,cell);
213  hgc_simhit_energy[recoCell] += simhit.energy();
214  }
215  }
216 
217  if (bh_simhits_h.isValid() )
218  {
219  throw cms::Exception("Not Implemented")<<"HGCalTriggerSimCluster: BH simhits not implemnted";
220 
221  }
222 
223  //1. construct a cluster container that hosts the cluster per truth-particle
224  std::unordered_map<uint64_t,std::pair<int,l1t::HGCalCluster> > cluster_container;// PID-> bx,cluster
226 
227  if (not sim_handle_.isValid()){
228  throw cms::Exception("ContentError")<<"[HGCalTriggerSimCluster]::[run]::[ERROR] Sim Cluster collection for HGC sim clustering not available";
229  }
230  // calibration
233 
234  // 1.5. pre-process the sim cluster to have easy accessible information
235  // I want a map cell-> [ (pid, fraction), ...
236  std::unordered_map<uint32_t, std::vector<std::pair< uint64_t, float > > > simclusters;
237  for (auto& cluster : *sim_handle_)
238  {
239  auto pid= cluster.particleId(); // not pdgId
240  const auto& hf = cluster.hits_and_fractions();
241  for (const auto & p : hf )
242  {
243  simclusters[p.first].push_back( std::pair<uint64_t, float>( pid,p.second) ) ;
244  }
245  }
246 
247  //2. run on the digits,
248  for( const auto& digi : coll )
249  {
250  DATA data;
251  digi.decode(codec_,data);
252  //2.A get the trigger-cell information energy/id
253  //const HGCTriggerDetId& moduleId = digi.getDetId<HGCTriggerDetId>(); // this is a module Det Id
254 
255  // there is a loss of generality here, due to the restriction imposed by the data formats
256  // it will work if inside a module there is a data.payload with an ordered list of all the energies
257  // one may think to add on top of it a wrapper if this stop to be the case for some of the data classes
258  for(const auto& triggercell : data.payload)
259  {
260  if(triggercell.hwPt()<=0) continue;
261 
262  const HGCalDetId tcellId(triggercell.detId());
263  // calbration
264 
265  l1t::HGCalTriggerCell calibratedtriggercell(triggercell);
266  calibration_.calibrateInGeV(calibratedtriggercell);
267  //uint32_t digiEnergy = data.payload;
268  //auto digiEnergy=triggercell.p4().E();
269  // using calibrated energy instead
270  auto calibratedDigiEnergy=calibratedtriggercell.p4().E();
271  double eta=triggercell.p4().Eta();
272  double phi=triggercell.p4().Phi();
273  double z = triggercell.position().z(); // may be useful for cluster shapes
274  //2.B get the HGCAL-base-cell associated to it / geometry
275 
276  // normalization loop
277  double norm=0.0;
278  map<unsigned, double> energy_for_cluster_shapes;
279 
280  for(const auto& cell : geometry_->getCellsFromTriggerCell( tcellId()) ) // HGCcell -- unsigned
281  {
282  HGCalDetId cellId(cell);
283 
284  //2.C0 find energy of the hgc cell. default is very small value
285  double hgc_energy=1.0e-10; //average if not found / bh
286  const auto &it = hgc_simhit_energy.find(cell);
287  if (it != hgc_simhit_energy.end()) { hgc_energy = it->second; }
288 
289  //2.C get the particleId and energy fractions
290  const auto & iterator= simclusters.find(cellId);
291  if (iterator == simclusters.end() ) continue;
292  const auto & particles = iterator->second;
293  for ( const auto& p: particles )
294  {
295  const auto & pid= p.first;
296  const auto & fraction=p.second;
297  norm += fraction * hgc_energy;
298  energy_for_cluster_shapes[pid] += calibratedDigiEnergy *fraction *hgc_energy; // norm will be done later, with the above norm
299  }
300  }
301 
302  // second loop counting the energy
303  for(const auto& cell : geometry_->getCellsFromTriggerCell( tcellId()) ) // HGCcell -- unsigned
304  {
305  HGCalDetId cellId(cell);
306  double hgc_energy=1.0e-10; // 1 -> average if not found / bh
307  const auto &it = hgc_simhit_energy.find(cell);
308  if (it != hgc_simhit_energy.end()) { hgc_energy = it->second; }
309  //2.C get the particleId and energy fractions
310  const auto & iterator= simclusters.find(cellId);
311  if (iterator == simclusters.end() ) continue;
312  const auto & particles = iterator->second;
313  for ( const auto& p: particles )
314  {
315  const auto & pid= p.first;
316  const auto & fraction=p.second;
317  //auto energy = fraction * calibratedDigiEnergy/norm;
318  auto energy = fraction * hgc_energy* calibratedDigiEnergy/norm; // THIS IS WHAT I WANT
319  //#warning FIXME_ENERGY
320  //auto energy = fraction * hgc_energy* hgc_energy/norm;
321 
322  //2.D add to the corresponding cluster
323  //eta/phi are the position of the trigger cell, to consider degradation
324  addToCluster(cluster_container, pid, 0,energy,eta,phi ) ;
325  }
326  }
327 
328  // third loop, cluster shapes to ensure the correct counts
329  for(const auto& iterator :energy_for_cluster_shapes)
330  {
331  double energy = iterator.second / norm;
332  unsigned pid = iterator.first;
333  addToClusterShapes(cluster_container, pid, 0,energy,eta,phi,z ) ;// only one for trigger cell
334  }
335  } //end of for-loop
336  }
337 
338  //3. Push the clusters in the cluster_product_
339  for (auto& p : cluster_container)
340  {
341  //std::unordered_map<uint64_t,std::pair<int,l1t::HGCalCluster> >
342  cluster_product_->push_back(p.second.first,p.second.second); // bx,cluster
343  }
344 
345  } // end run
const HGCalTriggerGeometryBase * geometry_
virtual geom_set getCellsFromTriggerCell(const unsigned cell_det_id) const =0
HGCalTriggerCellCalibration calibration_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
bool detectorType() const
edm::EDGetTokenT< std::vector< SimCluster > > sim_token_
edm::ESHandle< HGCalTopology > hgchefTopoHandle_
ForwardSubdetector
std::pair< int, int > simToReco(int cell, int layer, int mod, bool half) const
void addToCluster(std::unordered_map< uint64_t, std::pair< int, l1t::HGCalCluster > > &cluster_container, uint64_t pid, int pdgid, float energy, float eta, float phi)
bool isValid() const
Definition: HandleBase.h:74
edm::Handle< std::vector< SimCluster > > sim_handle_
const HGCalDDDConstants & dddConstants() const
const T & get() const
Definition: EventSetup.h:59
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void addToClusterShapes(std::unordered_map< uint64_t, std::pair< int, l1t::HGCalCluster > > &cluster_container, uint64_t pid, int pdgid, float energy, float eta, float phi, float r=0.0)
std::unique_ptr< l1t::HGCalClusterBxCollection > cluster_product_
void calibrateInGeV(l1t::HGCalTriggerCell &)
static void unpackHexagonIndex(const uint32_t &idx, int &subdet, int &z, int &lay, int &wafer, int &celltyp, int &cell)
edm::ESHandle< HGCalTopology > hgceeTopoHandle_
template<typename FECODEC , typename DATA >
void HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::setProduces ( edm::stream::EDProducer<> &  prod) const
inlinefinalvirtual

Implements HGCalTriggerBackendAlgorithmBase.

Definition at line 131 of file HGCalSimCluster.cc.

References HGCalTriggerBackendAlgorithmBase::name(), and parseEventContent::prod.

132  {
133  prod.produces<l1t::HGCalClusterBxCollection>(name());
134  }

Member Data Documentation

template<typename FECODEC , typename DATA >
HGCalTriggerCellCalibration HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::calibration_
private

Definition at line 66 of file HGCalSimCluster.cc.

template<typename FECODEC , typename DATA >
std::unique_ptr<l1t::HGCalClusterBxCollection> HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::cluster_product_
private

Definition at line 55 of file HGCalSimCluster.cc.

template<typename FECODEC , typename DATA >
std::string HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::HGCalEESensitive_
private

Definition at line 64 of file HGCalSimCluster.cc.

template<typename FECODEC , typename DATA >
std::string HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::HGCalHESiliconSensitive_
private

Definition at line 65 of file HGCalSimCluster.cc.

template<typename FECODEC , typename DATA >
edm::ESHandle<HGCalTopology> HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::hgceeTopoHandle_
private

Definition at line 59 of file HGCalSimCluster.cc.

template<typename FECODEC , typename DATA >
edm::ESHandle<HGCalTopology> HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::hgchefTopoHandle_
private

Definition at line 60 of file HGCalSimCluster.cc.

template<typename FECODEC , typename DATA >
edm::EDGetToken HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::inputbh_
private

Definition at line 71 of file HGCalSimCluster.cc.

template<typename FECODEC , typename DATA >
edm::EDGetToken HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::inputee_
private

Definition at line 71 of file HGCalSimCluster.cc.

template<typename FECODEC , typename DATA >
edm::EDGetToken HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::inputfh_
private

Definition at line 71 of file HGCalSimCluster.cc.

template<typename FECODEC , typename DATA >
edm::Handle< std::vector<SimCluster> > HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::sim_handle_
private

Definition at line 57 of file HGCalSimCluster.cc.

template<typename FECODEC , typename DATA >
edm::EDGetTokenT< std::vector<SimCluster> > HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::sim_token_
private

Definition at line 69 of file HGCalSimCluster.cc.