Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:25

0001 // -*- C++ -*-
0002 //
0003 // Package:    TopQuarkAnalysis/TopTools
0004 // Class:      TestGenTtbarCategories
0005 //
0006 /**\class TestGenTtbarCategories TestGenTtbarCategories.cc PhysicsTools/JetMCAlgos/test/TestGenTtbarCategories.cc
0007 
0008  Description: Analyzer for testing corresponding producer GenTtbarCategorizer
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Johannes Hauk, Nazar Bartosik
0015 //         Created:  Sun, 14 Jun 2015 21:00:23 GMT
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
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 // class declaration
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   // ----------member data ---------------------------
0049 
0050   // Input tags
0051   const edm::EDGetTokenT<int> genTtbarIdToken_;
0052 
0053   // Variables to fill
0054   int ttbarId_;
0055   int ttbarAdditionalJetId_;
0056   int nBjetsFromTop_;
0057   int nBjetsFromW_;
0058   int nCjetsFromW_;
0059 
0060   // Tree to be filled
0061   TTree* tree_;
0062 };
0063 
0064 //
0065 // constructors and destructor
0066 //
0067 TestGenTtbarCategories::TestGenTtbarCategories(const edm::ParameterSet& iConfig)
0068     : genTtbarIdToken_(consumes<int>(iConfig.getParameter<edm::InputTag>("genTtbarId"))) {
0069   usesResource("TFileService");
0070 }
0071 
0072 //
0073 // member functions
0074 //
0075 
0076 // ------------ method called for each event  ------------
0077 void TestGenTtbarCategories::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0078   edm::Handle<int> genTtbarId;
0079   iEvent.getByToken(genTtbarIdToken_, genTtbarId);
0080 
0081   // ID including information about b/c jets in acceptance from t->b/W->b/W->c decays as well as additional ones
0082   ttbarId_ = *genTtbarId;
0083 
0084   // ID based only on additional b/c jets
0085   ttbarAdditionalJetId_ = ttbarId_ % 100;
0086 
0087   // Number of b/c jets from t->b or W->b/c decays
0088   nBjetsFromTop_ = ttbarId_ % 1000 / 100;
0089   nBjetsFromW_ = ttbarId_ % 10000 / 1000;
0090   nCjetsFromW_ = ttbarId_ % 100000 / 10000;
0091 
0092   // Filling the tree
0093   tree_->Fill();
0094 }
0095 
0096 // ------------ method called once each job just before starting event loop  ------------
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 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0111 void TestGenTtbarCategories::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0112   edm::ParameterSetDescription desc;
0113   desc.add<edm::InputTag>("genTtbarId");
0114   descriptions.addDefault(desc);
0115 }
0116 
0117 //define this as a plug-in
0118 DEFINE_FWK_MODULE(TestGenTtbarCategories);