Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:09

0001 #include "FWCore/Framework/interface/global/EDProducer.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "DataFormats/RecoCandidate/interface/CaloRecHitCandidate.h"
0004 
0005 namespace reco {
0006   namespace modules {
0007 
0008     template <typename HitCollection>
0009     class CaloRecHitCandidateProducer : public edm::global::EDProducer<> {
0010     public:
0011       /// constructor
0012       CaloRecHitCandidateProducer(const edm::ParameterSet &cfg)
0013           : srcToken_(consumes<HitCollection>(cfg.template getParameter<edm::InputTag>("src"))) {}
0014       /// destructor
0015       ~CaloRecHitCandidateProducer() override {}
0016 
0017     private:
0018       /// process one event
0019       void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override;
0020       /// source collection tag
0021       const edm::EDGetTokenT<HitCollection> srcToken_;
0022     };
0023   }  // namespace modules
0024 }  // namespace reco
0025 
0026 #include "DataFormats/Common/interface/Handle.h"
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "DataFormats/Math/interface/Vector3D.h"
0029 
0030 namespace reco {
0031   namespace modules {
0032 
0033     template <typename HitCollection>
0034     void CaloRecHitCandidateProducer<HitCollection>::produce(edm::StreamID,
0035                                                              edm::Event &evt,
0036                                                              const edm::EventSetup &) const {
0037       using namespace edm;
0038       using namespace reco;
0039       using namespace std;
0040       Handle<HitCollection> hits;
0041       evt.getByToken(srcToken_, hits);
0042       unique_ptr<CandidateCollection> cands(new CandidateCollection);
0043       size_t size = hits->size();
0044       cands->reserve(size);
0045       for (size_t idx = 0; idx != size; ++idx) {
0046         const CaloRecHit &hit = (*hits)[idx];
0047         /// don't know how to set eta and phi
0048         double eta = 0, phi = 0, energy = hit.energy();
0049         math::RhoEtaPhiVector p(1, eta, phi);
0050         p *= (energy / p.r());
0051         CaloRecHitCandidate *c = new CaloRecHitCandidate(Candidate::LorentzVector(p.x(), p.y(), p.z(), energy));
0052         c->setCaloRecHit(Ptr<CaloRecHit>(hits, idx));
0053         cands->push_back(c);
0054       }
0055       evt.put(std::move(cands));
0056     }
0057 
0058   }  // namespace modules
0059 }  // namespace reco
0060 
0061 #include "FWCore/Framework/interface/MakerMacros.h"
0062 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
0063 
0064 typedef reco::modules::CaloRecHitCandidateProducer<HFRecHitCollection> HFRecHitCandidateProducer;
0065 typedef reco::modules::CaloRecHitCandidateProducer<ZDCRecHitCollection> ZDCRecHitCandidateProducer;
0066 typedef reco::modules::CaloRecHitCandidateProducer<HBHERecHitCollection> HBHERecHitCandidateProducer;
0067 typedef reco::modules::CaloRecHitCandidateProducer<HORecHitCollection> HORecHitCandidateProducer;
0068 
0069 DEFINE_FWK_MODULE(HFRecHitCandidateProducer);
0070 DEFINE_FWK_MODULE(ZDCRecHitCandidateProducer);
0071 DEFINE_FWK_MODULE(HBHERecHitCandidateProducer);
0072 DEFINE_FWK_MODULE(HORecHitCandidateProducer);