File indexing completed on 2024-04-06 12:31:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0025 #include "FWCore/Framework/interface/Event.h"
0026 #include "FWCore/Framework/interface/MakerMacros.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "FWCore/Utilities/interface/InputTag.h"
0029 #include "FWCore/ServiceRegistry/interface/Service.h"
0030 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0031
0032 #include <TTree.h>
0033
0034
0035
0036
0037
0038 class TestGenTtbarCategories : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0039 public:
0040 explicit TestGenTtbarCategories(const edm::ParameterSet&);
0041
0042 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0043
0044 private:
0045 void beginJob() override;
0046 void analyze(const edm::Event&, const edm::EventSetup&) override;
0047
0048
0049
0050
0051 const edm::EDGetTokenT<int> genTtbarIdToken_;
0052
0053
0054 int ttbarId_;
0055 int ttbarAdditionalJetId_;
0056 int nBjetsFromTop_;
0057 int nBjetsFromW_;
0058 int nCjetsFromW_;
0059
0060
0061 TTree* tree_;
0062 };
0063
0064
0065
0066
0067 TestGenTtbarCategories::TestGenTtbarCategories(const edm::ParameterSet& iConfig)
0068 : genTtbarIdToken_(consumes<int>(iConfig.getParameter<edm::InputTag>("genTtbarId"))) {
0069 usesResource("TFileService");
0070 }
0071
0072
0073
0074
0075
0076
0077 void TestGenTtbarCategories::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0078 edm::Handle<int> genTtbarId;
0079 iEvent.getByToken(genTtbarIdToken_, genTtbarId);
0080
0081
0082 ttbarId_ = *genTtbarId;
0083
0084
0085 ttbarAdditionalJetId_ = ttbarId_ % 100;
0086
0087
0088 nBjetsFromTop_ = ttbarId_ % 1000 / 100;
0089 nBjetsFromW_ = ttbarId_ % 10000 / 1000;
0090 nCjetsFromW_ = ttbarId_ % 100000 / 10000;
0091
0092
0093 tree_->Fill();
0094 }
0095
0096
0097 void TestGenTtbarCategories::beginJob() {
0098 edm::Service<TFileService> fileService;
0099 if (!fileService)
0100 throw edm::Exception(edm::errors::Configuration, "TFileService is not registered in cfg file");
0101
0102 tree_ = fileService->make<TTree>("tree", "tree");
0103 tree_->Branch("ttbarId", &ttbarId_);
0104 tree_->Branch("ttbarAdditionalJetId", &ttbarAdditionalJetId_);
0105 tree_->Branch("nBjetsFromTop", &nBjetsFromTop_);
0106 tree_->Branch("nBjetsFromW", &nBjetsFromW_);
0107 tree_->Branch("nCjetsFromW", &nCjetsFromW_);
0108 }
0109
0110
0111 void TestGenTtbarCategories::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0112 edm::ParameterSetDescription desc;
0113 desc.add<edm::InputTag>("genTtbarId");
0114 descriptions.addDefault(desc);
0115 }
0116
0117
0118 DEFINE_FWK_MODULE(TestGenTtbarCategories);