File indexing completed on 2024-04-06 12:29:50
0001
0002
0003
0004
0005
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventSetup.h"
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0013 #include "FWCore/PluginManager/interface/PluginManager.h"
0014 #include "FWCore/ServiceRegistry/interface/Service.h"
0015 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0016 #include "SimDataFormats/CaloTest/interface/HcalTestHistoClass.h"
0017
0018
0019 #include "TROOT.h"
0020 #include "TSystem.h"
0021 #include "TFile.h"
0022 #include "TDirectory.h"
0023 #include "TTree.h"
0024
0025 #include <cmath>
0026 #include <iostream>
0027 #include <memory>
0028 #include <string>
0029
0030 class HcalTestAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0031 public:
0032 HcalTestAnalyzer(const edm::ParameterSet&);
0033 ~HcalTestAnalyzer() override;
0034
0035 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0036 void analyze(const edm::Event& e, const edm::EventSetup& c) override;
0037
0038 private:
0039 TTree* tree_;
0040 HcalTestHistoClass h_;
0041 const edm::EDGetTokenT<HcalTestHistoClass> tokHist_;
0042 int kount_;
0043 };
0044
0045 HcalTestAnalyzer::HcalTestAnalyzer(const edm::ParameterSet&)
0046 : tree_(nullptr), tokHist_(consumes<HcalTestHistoClass>(edm::InputTag("g4SimHits"))), kount_(0) {
0047 usesResource(TFileService::kSharedResource);
0048 edm::Service<TFileService> fs;
0049 if (fs.isAvailable()) {
0050 tree_ = fs->make<TTree>("HcalTest", "HcalTest");
0051 tree_->SetAutoSave(10000);
0052 tree_->Branch("HcalTestHistoClass", &h_);
0053 edm::LogVerbatim("HcalSim") << "HcalTestAnalyzer:===>>> Book the Tree";
0054 } else {
0055 edm::LogVerbatim("HcalSim") << "HcalTestAnalyzer:===>>> No file provided";
0056 }
0057 }
0058
0059 HcalTestAnalyzer::~HcalTestAnalyzer() {
0060 edm::LogVerbatim("HcalSim") << "================================================================="
0061 << "====================\n=== HcalTestAnalyzer: Start writing user "
0062 << "histograms after " << kount_ << " events ";
0063 }
0064
0065 void HcalTestAnalyzer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0066 edm::ParameterSetDescription desc;
0067 descriptions.add("hcalTestAnalyzer", desc);
0068 }
0069
0070 void HcalTestAnalyzer::analyze(const edm::Event& e, const edm::EventSetup&) {
0071 ++kount_;
0072 const auto& histos = e.getHandle(tokHist_);
0073 edm::LogVerbatim("HcalSim") << "HcalTestAnalyzer: [" << kount_ << "] event " << e.id().event() << " with "
0074 << histos.isValid();
0075
0076 if ((tree_) && histos.isValid()) {
0077 auto histo = histos.product();
0078 edm::LogVerbatim("HcalSim") << "HcalTestAnalyzer: tree pointer = " << histo;
0079 h_ = *histo;
0080 tree_->Fill();
0081 }
0082 }
0083
0084
0085 DEFINE_FWK_MODULE(HcalTestAnalyzer);