Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-23 01:39:01

0001 // -*- C++ -*-
0002 //
0003 // Package:    CherenkovAnalysis
0004 // Class:      CherenkovAnalysis
0005 //
0006 /**\class CherenkovAnalysis CherenkovAnalysis.cpp
0007 SimG4CMS/CherenkovAnalysis/test/CherenkovAnalysis.cpp
0008 
0009 Description: <one line class summary>
0010 
0011 Implementation:
0012 <Notes on implementation>
0013 */
0014 //
0015 // Original Author:  Frederic Ronga
0016 //         Created:  Wed Mar 12 17:39:55 CET 2008
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0025 #include "FWCore/Framework/interface/Frameworkfwd.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 
0028 #include "FWCore/Framework/interface/Event.h"
0029 #include "FWCore/Framework/interface/MakerMacros.h"
0030 
0031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0032 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0033 #include "FWCore/Utilities/interface/InputTag.h"
0034 
0035 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
0036 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
0037 
0038 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0039 #include "FWCore/ServiceRegistry/interface/Service.h"
0040 #include <TH1F.h>
0041 
0042 //#define EDM_ML_DEBUG
0043 
0044 class CherenkovAnalysis : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0045 public:
0046   explicit CherenkovAnalysis(const edm::ParameterSet &);
0047   ~CherenkovAnalysis() override {}
0048 
0049   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0050 
0051 private:
0052   const double maxEnergy_;
0053   const int nBinsEnergy_;
0054   const edm::EDGetTokenT<edm::PCaloHitContainer> tok_calo_;
0055   TH1F *hEnergy_;
0056 
0057   TH1F *hTimeStructure_;
0058 
0059   void beginJob() override {}
0060   void analyze(const edm::Event &, const edm::EventSetup &) override;
0061   void endJob() override {}
0062 };
0063 
0064 //__________________________________________________________________________________________________
0065 CherenkovAnalysis::CherenkovAnalysis(const edm::ParameterSet &iConfig)
0066     : maxEnergy_(iConfig.getParameter<double>("maxEnergy")),
0067       nBinsEnergy_(iConfig.getParameter<int>("nBinsEnergy")),
0068       tok_calo_(consumes<edm::PCaloHitContainer>(iConfig.getParameter<edm::InputTag>("caloHitSource"))) {
0069   usesResource(TFileService::kSharedResource);
0070 
0071   // Book histograms
0072   edm::Service<TFileService> tfile;
0073 
0074   if (!tfile.isAvailable())
0075     throw cms::Exception("BadConfig") << "TFileService unavailable: "
0076                                       << "please add it to config file";
0077 
0078   hEnergy_ = tfile->make<TH1F>("hEnergy", "Total energy deposit [GeV]", nBinsEnergy_, 0, maxEnergy_);
0079   hTimeStructure_ = tfile->make<TH1F>("hTimeStructure", "Time structure [ns]", 100, 0, 0.3);
0080 }
0081 
0082 void CherenkovAnalysis::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0083   edm::ParameterSetDescription desc;
0084   desc.add<edm::InputTag>("caloHitSource", edm::InputTag("g4SimHits", "EcalHitsEB"));
0085   desc.add<double>("maxEnergy", 2.0);
0086   desc.add<int>("nBinsEnergy", 50);
0087   descriptions.add("cherenkovAnalysis", desc);
0088 }
0089 
0090 //__________________________________________________________________________________________________
0091 void CherenkovAnalysis::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0092   const edm::Handle<edm::PCaloHitContainer> &pCaloHits = iEvent.getHandle(tok_calo_);
0093 
0094   double totalEnergy = 0;
0095 
0096   // Loop on all hits and calculate total energy loss
0097   edm::PCaloHitContainer::const_iterator it = pCaloHits.product()->begin();
0098   edm::PCaloHitContainer::const_iterator itend = pCaloHits.product()->end();
0099   for (; it != itend; ++it) {
0100     totalEnergy += (*it).energy();
0101     hTimeStructure_->Fill((*it).time(),
0102                           (*it).energy());  // Time weighted by energy...
0103     //     edm::LogInfo("CherenkovAnalysis") << "Time = " << (*it).time() <<
0104     //     std::endl;
0105   }
0106 #ifdef EDM_ML_DEBUG
0107   edm::LogVerbatim("CherenkovAnalysis") << "CherenkovAnalysis::Total energy = " << totalEnergy;
0108 #endif
0109   hEnergy_->Fill(totalEnergy);
0110 }
0111 
0112 DEFINE_FWK_MODULE(CherenkovAnalysis);