Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:04:12

0001 // -*- C++ -*-
0002 //
0003 // Package:     HcalTestBeam
0004 // Class  :     HcalTB02Histo
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:
0010 //         Created:  Sun May 21 10:14:34 CEST 2006
0011 //
0012 
0013 // system include files
0014 #include <iostream>
0015 #include <cmath>
0016 
0017 // user include files
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "FWCore/ServiceRegistry/interface/Service.h"
0020 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0021 #include "SimG4CMS/HcalTestBeam/interface/HcalTB02Histo.h"
0022 
0023 //#define EDM_ML_DEBUG
0024 //
0025 // constructors and destructor
0026 HcalTB02Histo::HcalTB02Histo(const edm::ParameterSet& ps) : rt_tbTimes(nullptr), rt_TransProf(nullptr) {
0027   verbose = ps.getUntrackedParameter<bool>("Verbose", false);
0028 #ifdef EDM_ML_DEBUG
0029   edm::LogVerbatim("HcalTBSim") << "HcalTB02Histo:: initialised with o/p file " << fileName << " verbosity " << verbose;
0030 #endif
0031   // Book histograms
0032   edm::Service<TFileService> tfile;
0033 
0034   if (!tfile.isAvailable())
0035     throw cms::Exception("BadConfig") << "TFileService unavailable: "
0036                                       << "please add it to config file";
0037 
0038   char title[80];
0039   for (int ilayer = 0; ilayer < 19; ilayer++) {
0040     sprintf(title, "Scint. Energy in Layer %d ", ilayer);
0041     TH1D* h = tfile->make<TH1D>(title, title, 500, 0., 1.5);
0042     rt_histoProf.push_back(h);
0043 #ifdef EDM_ML_DEBUG
0044     edm::LogVerbatim("HcalTBSim") << "HcalTB02Histo:: Initialise Histo " << title;
0045 #endif
0046   }
0047   sprintf(title, "All Hit Time slices");
0048   rt_tbTimes = tfile->make<TH1D>(title, title, 100, 0., 100.);
0049 #ifdef EDM_ML_DEBUG
0050   edm::LogVerbatim("HcalTBSim") << "HcalTB02Histo:: Initialise Histo " << title;
0051 #endif
0052   sprintf(title, "Transv. Shower Profile");
0053   rt_TransProf = tfile->make<TH2D>(title, title, 100, 0., 1., 1000, 0., 0.5);
0054 #ifdef EDM_ML_DEBUG
0055   edm::LogVerbatim("HcalTBSim") << "HcalTB02Histo:: Initialise Histo " << title;
0056 #endif
0057 }
0058 
0059 HcalTB02Histo::~HcalTB02Histo() {
0060 #ifdef EDM_ML_DEBUG
0061   edm::LogVerbatim("HcalTBSim") << " Deleting HcalTB02Histo";
0062 #endif
0063 }
0064 
0065 //
0066 // member functions
0067 //
0068 
0069 void HcalTB02Histo::fillAllTime(float v) {
0070 #ifdef EDM_ML_DEBUG
0071   edm::LogVerbatim("HcalTBSim") << "HcalTB02Histo::Fill Time histo with " << v;
0072 #endif
0073   if (rt_tbTimes) {
0074     rt_tbTimes->Fill(v);
0075   }
0076 }
0077 
0078 void HcalTB02Histo::fillTransProf(float u, float v) {
0079 #ifdef EDM_ML_DEBUG
0080   edm::LogVerbatim("HcalTBSim") << "HcalTB02Histo:::Fill Shower Transv. Profile histo"
0081                                 << " with " << u << " and " << v;
0082 #endif
0083   if (rt_TransProf) {
0084     rt_TransProf->Fill(u, v);
0085   }
0086 }
0087 
0088 void HcalTB02Histo::fillProfile(int ilayer, float value) {
0089   if (ilayer < (int)(rt_histoProf.size())) {
0090     rt_histoProf[ilayer]->Fill(value);
0091 #ifdef EDM_ML_DEBUG
0092     edm::LogVerbatim("HcalTBSim") << "HcalTB02Histo::Fill profile " << ilayer << " with " << value;
0093 #endif
0094   }
0095 }
0096 
0097 float HcalTB02Histo::getMean(int ilayer) {
0098   if (ilayer < (int)(rt_histoProf.size())) {
0099     return rt_histoProf[ilayer]->GetMean();
0100   } else {
0101     return 0;
0102   }
0103 }
0104 
0105 float HcalTB02Histo::getRMS(int ilayer) {
0106   if (ilayer < (int)(rt_histoProf.size())) {
0107     return rt_histoProf[ilayer]->GetRMS();
0108   } else {
0109     return 0;
0110   }
0111 }