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)
 
virtual void putInEvent (edm::Event &evt) override final
 
virtual void reset () override final
 
virtual void run (const l1t::HGCFETriggerDigiCollection &coll, const edm::EventSetup &es, edm::Event &evt)
 
virtual void setProduces (edm::stream::EDProducer<> &prod) const override final
 
- Public Member Functions inherited from HGCalTriggerBackend::Algorithm< FECODEC >
 Algorithm (const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
 
virtual void setGeometry (const HGCalTriggerGeometryBase *const geom) override 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 stringResolutionProvider_cfi::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 >
virtual void HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::putInEvent ( edm::Event evt)
inlinefinaloverridevirtual

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:122
std::unique_ptr< l1t::HGCalClusterBxCollection > cluster_product_
def move(src, dest)
Definition: eostools.py:510
template<typename FECODEC , typename DATA >
virtual void HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::reset ( void  )
inlinefinaloverridevirtual

Implements HGCalTriggerBackendAlgorithmBase.

Definition at line 143 of file HGCalSimCluster.cc.

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

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(), stringResolutionProvider_cfi::eta, Exception, dedxEstimators_cff::fraction, HGCalTriggerBackendAlgorithmBase::geometry_, edm::EventSetup::get(), edm::Event::getByToken(), HGCalTriggerGeometryBase::getCellsFromTriggerCell(), photonIsolationHIProducer_cfi::hf, HGCEE, HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::hgceeTopoHandle_, HGCHEB, HGCHEF, HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::hgchefTopoHandle_, edm::HandleBase::isValid(), AlCaHLTBitMon_ParallelJobs::p, reco::LeafCandidate::p4(), HadronAndPartonSelector_cfi::particles, sysUtil::pid, HGCalDDDConstants::simToReco(), DetId::subdetId(), 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  int subdet = tcellId.subdetId();
265  int cellThickness = 0;
266 
267  if( subdet == HGCEE ){
268  cellThickness = (hgceeTopoHandle_)->dddConstants().waferTypeL((unsigned int)tcellId.wafer() );
269  }else if( subdet == HGCHEF ){
270  cellThickness = (hgchefTopoHandle_)->dddConstants().waferTypeL((unsigned int)tcellId.wafer() );
271  }else if( subdet == HGCHEB ){
272  edm::LogWarning("DataNotFound") << "ATTENTION: the BH trgCells are not yet implemented !! ";
273  }
274 
275  l1t::HGCalTriggerCell calibratedtriggercell(triggercell);
276  calibration_.calibrateInGeV(calibratedtriggercell, cellThickness);
277  //uint32_t digiEnergy = data.payload;
278  //auto digiEnergy=triggercell.p4().E();
279  // using calibrated energy instead
280  auto calibratedDigiEnergy=calibratedtriggercell.p4().E();
281  double eta=triggercell.p4().Eta();
282  double phi=triggercell.p4().Phi();
283  double z = triggercell.position().z(); // may be useful for cluster shapes
284  //2.B get the HGCAL-base-cell associated to it / geometry
285 
286  // normalization loop
287  double norm=0.0;
288  map<unsigned, double> energy_for_cluster_shapes;
289 
290  for(const auto& cell : geometry_->getCellsFromTriggerCell( tcellId()) ) // HGCcell -- unsigned
291  {
292  HGCalDetId cellId(cell);
293 
294  //2.C0 find energy of the hgc cell. default is very small value
295  double hgc_energy=1.0e-10; //average if not found / bh
296  const auto &it = hgc_simhit_energy.find(cell);
297  if (it != hgc_simhit_energy.end()) { hgc_energy = it->second; }
298 
299  //2.C get the particleId and energy fractions
300  const auto & iterator= simclusters.find(cellId);
301  if (iterator == simclusters.end() ) continue;
302  const auto & particles = iterator->second;
303  for ( const auto& p: particles )
304  {
305  const auto & pid= p.first;
306  const auto & fraction=p.second;
307  norm += fraction * hgc_energy;
308  energy_for_cluster_shapes[pid] += calibratedDigiEnergy *fraction *hgc_energy; // norm will be done later, with the above norm
309  }
310  }
311 
312  // second loop counting the energy
313  for(const auto& cell : geometry_->getCellsFromTriggerCell( tcellId()) ) // HGCcell -- unsigned
314  {
315  HGCalDetId cellId(cell);
316  double hgc_energy=1.0e-10; // 1 -> average if not found / bh
317  const auto &it = hgc_simhit_energy.find(cell);
318  if (it != hgc_simhit_energy.end()) { hgc_energy = it->second; }
319  //2.C get the particleId and energy fractions
320  const auto & iterator= simclusters.find(cellId);
321  if (iterator == simclusters.end() ) continue;
322  const auto & particles = iterator->second;
323  for ( const auto& p: particles )
324  {
325  const auto & pid= p.first;
326  const auto & fraction=p.second;
327  //auto energy = fraction * calibratedDigiEnergy/norm;
328  auto energy = fraction * hgc_energy* calibratedDigiEnergy/norm; // THIS IS WHAT I WANT
329  //#warning FIXME_ENERGY
330  //auto energy = fraction * hgc_energy* hgc_energy/norm;
331 
332  //2.D add to the corresponding cluster
333  //eta/phi are the position of the trigger cell, to consider degradation
334  addToCluster(cluster_container, pid, 0,energy,eta,phi ) ;
335  }
336  }
337 
338  // third loop, cluster shapes to ensure the correct counts
339  for(const auto& iterator :energy_for_cluster_shapes)
340  {
341  double energy = iterator.second / norm;
342  unsigned pid = iterator.first;
343  addToClusterShapes(cluster_container, pid, 0,energy,eta,phi,z ) ;// only one for trigger cell
344  }
345  } //end of for-loop
346  }
347 
348  //3. Push the clusters in the cluster_product_
349  for (auto& p : cluster_container)
350  {
351  //std::unordered_map<uint64_t,std::pair<int,l1t::HGCalCluster> >
352  cluster_product_->push_back(p.second.first,p.second.second); // bx,cluster
353  }
354 
355  } // 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:460
bool detectorType() const
edm::EDGetTokenT< std::vector< SimCluster > > sim_token_
edm::ESHandle< HGCalTopology > hgchefTopoHandle_
void calibrateInGeV(l1t::HGCalTriggerCell &, int cellThickness)
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
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
edm::Handle< std::vector< SimCluster > > sim_handle_
const HGCalDDDConstants & dddConstants() const
const T & get() const
Definition: EventSetup.h:56
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_
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 >
virtual void HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::setProduces ( edm::stream::EDProducer<> &  prod) const
inlinefinaloverridevirtual

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
template<typename FECODEC , typename DATA >
edm::ESHandle<HGCalTopology> HGCalTriggerBackend::HGCalTriggerSimCluster< FECODEC, DATA >::hgchefTopoHandle_
private
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.