Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-10 06:14:07

0001 // user include files
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0009 #include "SimGeneral/HepPDTRecord/interface/ParticleDataTable.h"
0010 #include "DataFormats/Candidate/interface/CandidateFwd.h"
0011 #include "DataFormats/Common/interface/Ref.h"
0012 #include "DataFormats/JetReco/interface/Jet.h"
0013 #include "DataFormats/JetReco/interface/GenJet.h"
0014 #include "PhysicsTools/JetMCUtils/interface/JetMCTag.h"
0015 #include "PhysicsTools/JetMCUtils/interface/CandMCTag.h"
0016 
0017 class printEvent : public edm::one::EDAnalyzer<> {
0018 public:
0019   explicit printEvent(const edm::ParameterSet&);
0020   ~printEvent(){};
0021   void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup);
0022 
0023 private:
0024   edm::EDGetTokenT<edm::View<reco::Jet> > sourceToken_;
0025   edm::Handle<edm::View<reco::Jet> > genJets;
0026   edm::ESGetToken<ParticleDataTable, edm::DefaultRecord> pdtToken_;
0027   edm::ESHandle<ParticleDataTable> pdt_;
0028 };
0029 
0030 // system include files
0031 #include <memory>
0032 #include <string>
0033 #include <iostream>
0034 #include <vector>
0035 
0036 using namespace std;
0037 using namespace reco;
0038 using namespace edm;
0039 using namespace JetMCTagUtils;
0040 using namespace CandMCTagUtils;
0041 
0042 printEvent::printEvent(const edm::ParameterSet& iConfig) {
0043   sourceToken_ = consumes<edm::View<reco::Jet> >(iConfig.getParameter<InputTag>("src"));
0044   pdtToken_ = esConsumes();
0045 }
0046 
0047 void printEvent::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0048   typedef edm::RefToBase<reco::Jet> JetRef;
0049 
0050   cout << "[printGenJet] analysing event " << iEvent.id() << endl;
0051 
0052   try {
0053     iEvent.getByToken(sourceToken_, genJets);
0054     pdt_ = iSetup.getHandle(pdtToken_);
0055   } catch (std::exception& ce) {
0056     cerr << "[printGenJet] caught std::exception " << ce.what() << endl;
0057     return;
0058   }
0059 
0060   cout << endl;
0061   cout << "**********************" << endl;
0062   cout << "* GenJetCollection   *" << endl;
0063   cout << "**********************" << endl;
0064 
0065   for (View<Jet>::const_iterator f = genJets->begin(); f != genJets->end(); f++) {
0066     double bRatio = EnergyRatioFromBHadrons(*f);
0067     double cRatio = EnergyRatioFromCHadrons(*f);
0068 
0069     printf("[GenJetTest] (pt,eta,phi | bRatio cRatio) = %6.2f %5.2f %5.2f | %5.3f %5.3f |\n",
0070            f->pt(),
0071            f->eta(),
0072            f->phi(),
0073            bRatio,
0074            cRatio);
0075 
0076     for (Candidate::const_iterator c = f->begin(); c != f->end(); c++) {
0077       bool isB = false;
0078       bool isC = false;
0079       isB = decayFromBHadron(*c);
0080       isC = decayFromCHadron(*c);
0081       printf("        [Constituents] (pt,eta,phi | isB,isC) = %6.2f %5.2f %5.2f | %1d %1d |\n",
0082              c->et(),
0083              c->eta(),
0084              c->phi(),
0085              isB,
0086              isC);
0087     }
0088   }
0089 }
0090 
0091 DEFINE_FWK_MODULE(printEvent);