CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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")), nBinsEnergy_(iConfig.getParameter<int>("nBinsEnergy")) {
67  usesResource(TFileService::kSharedResource);
68 
69  tok_calo_ = consumes<edm::PCaloHitContainer>(iConfig.getParameter<edm::InputTag>("caloHitSource"));
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 //__________________________________________________________________________________________________
93  iEvent.getByToken(tok_calo_, pCaloHits);
94 
95  double totalEnergy = 0;
96 
97  // Loop on all hits and calculate total energy loss
98  edm::PCaloHitContainer::const_iterator it = pCaloHits.product()->begin();
99  edm::PCaloHitContainer::const_iterator itend = pCaloHits.product()->end();
100  for (; it != itend; ++it) {
101  totalEnergy += (*it).energy();
102  hTimeStructure_->Fill((*it).time(),
103  (*it).energy()); // Time weighted by energy...
104  // edm::LogInfo("CherenkovAnalysis") << "Time = " << (*it).time() <<
105  // std::endl;
106  }
107 #ifdef EDM_ML_DEBUG
108  edm::LogVerbatim("CherenkovAnalysis") << "CherenkovAnalysis::Total energy = " << totalEnergy;
109 #endif
110  hEnergy_->Fill(totalEnergy);
111 }
112 
static const std::string kSharedResource
Definition: TFileService.h:76
Log< level::Info, true > LogVerbatim
~CherenkovAnalysis() override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void endJob() override
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
void beginJob() override
CherenkovAnalysis(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:224
bool isAvailable() const
Definition: Service.h:40
const double maxEnergy_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
T const * product() const
Definition: Handle.h:70
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void analyze(const edm::Event &, const edm::EventSetup &) override
tuple tfile
Definition: compare.py:324
edm::EDGetTokenT< edm::PCaloHitContainer > tok_calo_