CMS 3D CMS Logo

HcalTestAnalyzer.cc
Go to the documentation of this file.
1 // File: HcalTestAnalyzer.h
3 // Histogram managing class for analysis in HcalTest
5 
17 
18 // root objects
19 #include "TROOT.h"
20 #include "TSystem.h"
21 #include "TFile.h"
22 #include "TDirectory.h"
23 #include "TTree.h"
24 
25 #include <cmath>
26 #include <iostream>
27 #include <memory>
28 #include <string>
29 
30 class HcalTestAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
31 public:
33  ~HcalTestAnalyzer() override;
34 
35  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
36  void analyze(const edm::Event& e, const edm::EventSetup& c) override;
37 
38 private:
39  TTree* tree_;
42  int kount_;
43 };
44 
46  : tree_(nullptr), tokHist_(consumes<HcalTestHistoClass>(edm::InputTag("g4SimHits"))), kount_(0) {
47  usesResource(TFileService::kSharedResource);
49  if (fs.isAvailable()) {
50  tree_ = fs->make<TTree>("HcalTest", "HcalTest");
51  tree_->SetAutoSave(10000);
52  tree_->Branch("HcalTestHistoClass", &h_);
53  edm::LogVerbatim("HcalSim") << "HcalTestAnalyzer:===>>> Book the Tree";
54  } else {
55  edm::LogVerbatim("HcalSim") << "HcalTestAnalyzer:===>>> No file provided";
56  }
57 }
58 
60  edm::LogVerbatim("HcalSim") << "================================================================="
61  << "====================\n=== HcalTestAnalyzer: Start writing user "
62  << "histograms after " << kount_ << " events ";
63 }
64 
67  descriptions.add("hcalTestAnalyzer", desc);
68 }
69 
71  ++kount_;
72  const auto& histos = e.getHandle(tokHist_);
73  edm::LogVerbatim("HcalSim") << "HcalTestAnalyzer: [" << kount_ << "] event " << e.id().event() << " with "
74  << histos.isValid();
75 
76  if ((tree_) && histos.isValid()) {
77  auto histo = histos.product();
78  edm::LogVerbatim("HcalSim") << "HcalTestAnalyzer: tree pointer = " << histo;
79  h_ = *histo;
80  tree_->Fill();
81  }
82 }
83 
84 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
~HcalTestAnalyzer() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(const edm::Event &e, const edm::EventSetup &c) override
HcalTestAnalyzer(const edm::ParameterSet &)
HcalTestHistoClass h_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
histos
Definition: combine.py:4
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< HcalTestHistoClass > tokHist_