Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-21 04:25:49

0001 /** \class CaloTowerCandidateCreator
0002  *
0003  * Framework module that produces a collection
0004  * of candidates with a CaloTowerCandidate compoment
0005  *
0006  * \author Luca Lista, INFN
0007  * modifyed by: F.Ratnikov UMd
0008  *
0009  *
0010  */
0011 #include "DataFormats/CaloTowers/interface/CaloTower.h"
0012 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
0013 #include "DataFormats/Common/interface/Handle.h"
0014 #include "DataFormats/RecoCandidate/interface/RecoCaloTowerCandidate.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/stream/EDProducer.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 
0019 #include <cmath>
0020 #include <string>
0021 
0022 class CaloTowerCandidateCreator : public edm::stream::EDProducer<> {
0023 public:
0024   /// constructor from parameter set
0025   CaloTowerCandidateCreator(const edm::ParameterSet&);
0026   /// destructor
0027   ~CaloTowerCandidateCreator() override;
0028 
0029 private:
0030   /// process one event
0031   void produce(edm::Event& e, const edm::EventSetup&) override;
0032   /// verbosity
0033   int mVerbose;
0034   /// token of source collection
0035   edm::EDGetTokenT<CaloTowerCollection> tok_src_;
0036   /// ET threshold
0037   double mEtThreshold;
0038   /// E threshold
0039   double mEThreshold;
0040 };
0041 
0042 #include "FWCore/Framework/interface/MakerMacros.h"
0043 // remove following line after Jet/Met move to using
0044 // exclusively CaloTowers
0045 DEFINE_FWK_MODULE(CaloTowerCandidateCreator);
0046 
0047 using namespace edm;
0048 using namespace reco;
0049 using namespace std;
0050 
0051 CaloTowerCandidateCreator::CaloTowerCandidateCreator(const ParameterSet& p)
0052     : mVerbose(p.getUntrackedParameter<int>("verbose", 0)),
0053       mEtThreshold(p.getParameter<double>("minimumEt")),
0054       mEThreshold(p.getParameter<double>("minimumE")) {
0055   tok_src_ = consumes<CaloTowerCollection>(p.getParameter<edm::InputTag>("src"));
0056 
0057   produces<CandidateCollection>();
0058 }
0059 
0060 CaloTowerCandidateCreator::~CaloTowerCandidateCreator() {}
0061 
0062 void CaloTowerCandidateCreator::produce(Event& evt, const EventSetup&) {
0063   Handle<CaloTowerCollection> caloTowers;
0064   evt.getByToken(tok_src_, caloTowers);
0065 
0066   auto cands = std::make_unique<CandidateCollection>();
0067   cands->reserve(caloTowers->size());
0068   unsigned idx = 0;
0069   for (; idx < caloTowers->size(); idx++) {
0070     const CaloTower* cal = &((*caloTowers)[idx]);
0071     if (mVerbose >= 2) {
0072       std::cout << "CaloTowerCandidateCreator::produce-> " << idx << " tower et/eta/phi/e: " << cal->et() << '/'
0073                 << cal->eta() << '/' << cal->phi() << '/' << cal->energy() << " is...";
0074     }
0075     if (cal->et() >= mEtThreshold && cal->energy() >= mEThreshold) {
0076       math::PtEtaPhiMLorentzVector p(cal->et(), cal->eta(), cal->phi(), 0);
0077       RecoCaloTowerCandidate* c = new RecoCaloTowerCandidate(0, Candidate::LorentzVector(p));
0078       c->setCaloTower(CaloTowerRef(caloTowers, idx));
0079       cands->push_back(c);
0080       if (mVerbose >= 2)
0081         std::cout << "accepted: pT/eta/phi:" << c->pt() << '/' << c->eta() << '/' << c->phi() << std::endl;
0082     } else {
0083       if (mVerbose >= 2)
0084         std::cout << "rejected" << std::endl;
0085     }
0086   }
0087   if (mVerbose >= 1) {
0088     std::cout << "CaloTowerCandidateCreator::produce-> " << cands->size() << " candidates created" << std::endl;
0089   }
0090   evt.put(std::move(cands));
0091 }