Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-26 02:43:54

0001 #include "RecoParticleFlow/PFClusterProducer/test/PFClusterAnalyzer.h"
0002 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
0003 
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 #include "FWCore/Utilities/interface/Exception.h"
0008 #include "FWCore/Framework/interface/EventSetup.h"
0009 
0010 using namespace std;
0011 using namespace edm;
0012 using namespace reco;
0013 
0014 PFClusterAnalyzer::PFClusterAnalyzer(const edm::ParameterSet& iConfig)
0015     : inputTagPFClusters_(iConfig.getParameter<InputTag>("PFClusters")),
0016       verbose_(iConfig.getUntrackedParameter<bool>("verbose", false)),
0017       printBlocks_(iConfig.getUntrackedParameter<bool>("printBlocks", false)) {
0018   LogDebug("PFClusterAnalyzer") << " input collection : " << inputTagPFClusters_;
0019 }
0020 
0021 void PFClusterAnalyzer::beginRun(const edm::Run& run, const edm::EventSetup& es) {}
0022 
0023 void PFClusterAnalyzer::analyze(const Event& iEvent, const EventSetup& iSetup) {
0024   LogDebug("PFClusterAnalyzer") << "START event: " << iEvent.id().event() << " in run " << iEvent.id().run() << endl;
0025 
0026   // get PFClusters
0027 
0028   Handle<PFClusterCollection> pfClusters;
0029   fetchCandidateCollection(pfClusters, inputTagPFClusters_, iEvent);
0030 
0031   // get PFClusters for isolation
0032 
0033   for (unsigned i = 0; i < pfClusters->size(); i++) {
0034     const reco::PFCluster& cluster = (*pfClusters)[i];
0035 
0036     if (verbose_) {
0037       cout << "PFCluster " << endl;
0038       cout << cluster << endl;
0039       cout << "CaloCluster " << endl;
0040 
0041       const CaloCluster* caloc = dynamic_cast<const CaloCluster*>(&cluster);
0042       assert(caloc);
0043       cout << *caloc << endl;
0044       cout << endl;
0045     }
0046   }
0047 
0048   LogDebug("PFClusterAnalyzer") << "STOP event: " << iEvent.id().event() << " in run " << iEvent.id().run() << endl;
0049 }
0050 
0051 void PFClusterAnalyzer::fetchCandidateCollection(Handle<reco::PFClusterCollection>& c,
0052                                                  const InputTag& tag,
0053                                                  const Event& iEvent) const {
0054   bool found = iEvent.getByLabel(tag, c);
0055 
0056   if (!found) {
0057     ostringstream err;
0058     err << " cannot get PFClusters: " << tag << endl;
0059     LogError("PFClusters") << err.str();
0060     throw cms::Exception("MissingProduct", err.str());
0061   }
0062 }
0063 
0064 DEFINE_FWK_MODULE(PFClusterAnalyzer);