CMS 3D CMS Logo

PFHGCalRecHitCreator.h
Go to the documentation of this file.
1 #ifndef RecoParticleFlow_PFClusterProducer_PFHGCalRecHitCreator_h
2 #define RecoParticleFlow_PFClusterProducer_PFHGCalRecHitCreator_h
3 
5 
9 
16 
23 
25 
26 template <typename DET,PFLayer::Layer Layer,unsigned subdet>
28 
29  public:
31  PFRecHitCreatorBase(iConfig,iC)
32  {
34  geometryInstance_ = iConfig.getParameter<std::string>("geometryInstance");
35  }
36 
37  void importRecHits(std::unique_ptr<reco::PFRecHitCollection>&out,std::unique_ptr<reco::PFRecHitCollection>& cleaned ,const edm::Event& iEvent,const edm::EventSetup& iSetup) override {
38 
39  // Setup RecHitTools to properly compute the position of the HGCAL Cells vie their DetIds
41 
42  for (unsigned int i=0;i<qualityTests_.size();++i) {
43  qualityTests_.at(i)->beginEvent(iEvent,iSetup);
44  }
45 
47  iEvent.getByToken(recHitToken_,recHitHandle);
48  const HGCRecHitCollection& rechits = *recHitHandle;
49 
51  iSetup.get<CaloGeometryRecord>().get(geoHandle);
52  const CaloGeometry* geom = geoHandle.product();
53 
54  // Get rid of the content of the previous event
55  for (auto c : caloCells_)
56  delete c;
57 
58  caloCells_.clear();
59  caloCells_.reserve(rechits.size());
60 
61  unsigned skipped_rechits = 0;
62  for (const auto & hgrh : rechits) {
63  const DET detid(hgrh.detid());
64 
65  if( subdet != detid.subdetId() ) {
66  throw cms::Exception("IncorrectHGCSubdetector")
67  << "subdet expected: " << subdet
68  << " subdet gotten: " << detid.subdetId() << std::endl;
69  }
70 
71  double energy = hgrh.energy();
72  double time = hgrh.time();
73 
74  const CaloCellGeometry *thisCell;
75  if( detid.det() == DetId::Hcal ) {
76  thisCell = geom->getSubdetectorGeometry(detid.det(),detid.subdetId())->getGeometry(detid);
77  } else {
78  const auto* hg = static_cast<const HGCalGeometry*>(geom->getSubdetectorGeometry(detid.det(),detid.subdetId()));
79  caloCells_.push_back(new CaloCellGeometryHGCALAdapter(static_cast<const FlatTrd*>(hg->getGeometry(detid)),
80  recHitTools_.getPosition(detid)));
81  thisCell = caloCells_.back();
82  }
83 
84  // find rechit geometry
85  if(!thisCell) {
86  LogDebug("PFHGCalRecHitCreator")
87  <<"warning detid "<<detid.rawId()
88  <<" not found in geometry"<<std::endl;
89  ++skipped_rechits;
90  continue;
91  }
92 
93 
94  reco::PFRecHit rh(thisCell, detid.rawId(),Layer,
95  energy);
96  // rh.setOriginalRecHit(edm::Ref<HGCRecHitCollection>(recHitHandle,i));
97 
98 
99  bool rcleaned = false;
100  bool keep=true;
101 
102  //Apply Q tests
103  for (unsigned int i=0;i<qualityTests_.size();++i) {
104  if (!qualityTests_.at(i)->test(rh,hgrh,rcleaned)) {
105  keep = false;
106  }
107  }
108 
109  if(keep) {
110  rh.setTime(time);
111  out->push_back(rh);
112  }
113  else if (rcleaned)
114  cleaned->push_back(rh);
115  }
116  edm::LogInfo("HGCalRecHitCreator")
117  << "Skipped " << skipped_rechits
118  << " out of " << rechits.size() << " rechits!" << std::endl;
119  edm::LogInfo("HGCalRecHitCreator")
120  << "Created " << out->size() << " PFRecHits!" << std::endl;
121  }
122 
123 
124 
125  protected:
128  private:
130  std::vector<const CaloCellGeometryHGCALAdapter*> caloCells_;
131 };
132 
135 
139 
140 
141 #endif
#define LogDebug(id)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:45
PFHGCalRecHitCreator< HGCalDetId, PFLayer::HGCAL, HGCHEF > PFHGCHEFRecHitCreator
std::vector< std::unique_ptr< PFRecHitQTestBase > > qualityTests_
PFHGCalRecHitCreator< HcalDetId,PFLayer::HGCAL, HcalEndcap > PFHGCHEBRecHitCreator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
void importRecHits(std::unique_ptr< reco::PFRecHitCollection > &out, std::unique_ptr< reco::PFRecHitCollection > &cleaned, const edm::Event &iEvent, const edm::EventSetup &iSetup) override
PFHGCalRecHitCreator< HGCalDetId, PFLayer::HGCAL, HGCEE > PFHGCEERecHitCreator
PFHGCalRecHitCreator(const edm::ParameterSet &iConfig, edm::ConsumesCollector &iC)
CaloGeometry const * getGeometry()
void getEventSetup(const edm::EventSetup &)
Definition: RecHitTools.cc:61
SeedingLayerSetsHits::SeedingLayer Layer
Definition: LayerTriplets.h:14
const int keep
hgcal::RecHitTools recHitTools_
int iEvent
Definition: GenABIO.cc:230
Particle flow rechit (rechit + geometry and topology information). See clustering algorithm in PFClus...
Definition: PFRecHit.h:31
edm::EDGetTokenT< HGCRecHitCollection > recHitToken_
const T & get() const
Definition: EventSetup.h:55
GlobalPoint getPosition(const DetId &id) const
Definition: RecHitTools.cc:77
std::vector< const CaloCellGeometryHGCALAdapter * > caloCells_
size_type size() const
T const * product() const
Definition: ESHandle.h:86