CMS 3D CMS Logo

CherenkovAnalysis.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CherenkovAnalysis
4 // Class: CherenkovAnalysis
5 //
14 //
15 // Original Author: Frederic Ronga
16 // Created: Wed Mar 12 17:39:55 CET 2008
17 //
18 //
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
27 
30 
34 
37 
40 #include <TH1F.h>
41 
42 //#define EDM_ML_DEBUG
43 
44 class CherenkovAnalysis : public edm::one::EDAnalyzer<edm::one::SharedResources> {
45 public:
46  explicit CherenkovAnalysis(const edm::ParameterSet &);
47  ~CherenkovAnalysis() override {}
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
50 
51 private:
52  const double maxEnergy_;
53  const int nBinsEnergy_;
55  TH1F *hEnergy_;
56 
58 
59  void beginJob() override {}
60  void analyze(const edm::Event &, const edm::EventSetup &) override;
61  void endJob() override {}
62 };
63 
64 //__________________________________________________________________________________________________
66  : maxEnergy_(iConfig.getParameter<double>("maxEnergy")),
67  nBinsEnergy_(iConfig.getParameter<int>("nBinsEnergy")),
68  tok_calo_(consumes<edm::PCaloHitContainer>(iConfig.getParameter<edm::InputTag>("caloHitSource"))) {
69  usesResource(TFileService::kSharedResource);
70 
71  // Book histograms
73 
74  if (!tfile.isAvailable())
75  throw cms::Exception("BadConfig") << "TFileService unavailable: "
76  << "please add it to config file";
77 
78  hEnergy_ = tfile->make<TH1F>("hEnergy", "Total energy deposit [GeV]", nBinsEnergy_, 0, maxEnergy_);
79  hTimeStructure_ = tfile->make<TH1F>("hTimeStructure", "Time structure [ns]", 100, 0, 0.3);
80 }
81 
84  desc.add<edm::InputTag>("caloHitSource", edm::InputTag("g4SimHits", "EcalHitsEB"));
85  desc.add<double>("maxEnergy", 2.0);
86  desc.add<int>("nBinsEnergy", 50);
87  descriptions.add("cherenkovAnalysis", desc);
88 }
89 
90 //__________________________________________________________________________________________________
92  const edm::Handle<edm::PCaloHitContainer> &pCaloHits = iEvent.getHandle(tok_calo_);
93 
94  double totalEnergy = 0;
95 
96  // Loop on all hits and calculate total energy loss
97  edm::PCaloHitContainer::const_iterator it = pCaloHits.product()->begin();
98  edm::PCaloHitContainer::const_iterator itend = pCaloHits.product()->end();
99  for (; it != itend; ++it) {
100  totalEnergy += (*it).energy();
101  hTimeStructure_->Fill((*it).time(),
102  (*it).energy()); // Time weighted by energy...
103  // edm::LogInfo("CherenkovAnalysis") << "Time = " << (*it).time() <<
104  // std::endl;
105  }
106 #ifdef EDM_ML_DEBUG
107  edm::LogVerbatim("CherenkovAnalysis") << "CherenkovAnalysis::Total energy = " << totalEnergy;
108 #endif
109  hEnergy_->Fill(totalEnergy);
110 }
111 
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
std::vector< PCaloHit > PCaloHitContainer
~CherenkovAnalysis() override
T const * product() const
Definition: Handle.h:70
void endJob() override
void beginJob() override
CherenkovAnalysis(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
Definition: tfile.py:1
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_calo_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const double maxEnergy_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
void analyze(const edm::Event &, const edm::EventSetup &) override