CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
40  TTree* tree_;
43  int kount_;
44 };
45 
47  usesResource(TFileService::kSharedResource);
48  tokHist_ = consumes<HcalTestHistoClass>(edm::InputTag("g4SimHits"));
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  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
EventNumber_t event() const
Definition: EventID.h:40
const edm::EventSetup & c
kount_(0)
~HcalTestAnalyzer() override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
void analyze(const edm::Event &e, const edm::EventSetup &c) override
edm::EDGetTokenT< HcalTestHistoClass > tokHist_
HcalTestAnalyzer(const edm::ParameterSet &)
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
Definition: Event.h:563
bool isAvailable() const
Definition: Service.h:40
edm::Service< TFileService > fs_
HcalTestHistoClass h_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
edm::EventID id() const
Definition: EventBase.h:59
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)