/scratch0/jsnuveri/BDSIM/BDSIMgit/bdsim/src/BDSAnalysisManager.cc

00001 #include "BDSAnalysisManager.hh"
00002 #include "BDSDebug.hh"
00003 #include "BDSHistogram.hh"
00004 #include "globals.hh"             // geant4 globals / types
00005 
00006 #include <vector>
00007 
00008 BDSAnalysisManager* BDSAnalysisManager::_instance = 0;
00009 
00010 BDSAnalysisManager* BDSAnalysisManager::Instance()
00011 {
00012   if (_instance == 0)
00013     {
00014       _instance = new BDSAnalysisManager();
00015     }
00016   return _instance;
00017 }
00018 
00019 BDSAnalysisManager::BDSAnalysisManager(){;}
00020 
00021 BDSAnalysisManager::~BDSAnalysisManager()
00022 {
00023   //delete all the 1d histograms created
00024   std::vector<BDSHistogram1D*>::iterator iter, end;
00025   for (iter = histograms1d.begin(), end = histograms1d.end(); iter != end; ++iter)
00026     {
00027       delete (*iter);
00028     }
00029   _instance = NULL;
00030 }
00031 
00032 G4int BDSAnalysisManager::Create1DHistogram(G4String name,
00033                                             G4String title,
00034                                             G4int    nbins,
00035                                             G4double xmin,
00036                                             G4double xmax)
00037 {
00038 #ifdef BDSDEBUG
00039   G4cout << __METHOD_NAME__   << "Name: " << name
00040          << ", Title: "       << title
00041          << ", # of Bins: "   << nbins
00042          << ", Lower limit: " << xmin
00043          << ", Upper limit: " << xmax << G4endl;
00044 #endif
00045   histograms1d.push_back(new BDSHistogram1D(xmin, xmax, nbins, name, title));
00046   return histograms1d.size();
00047 }
00048 
00049 G4int BDSAnalysisManager::Create1DHistogram(G4String name,
00050                                             G4String title,
00051                                             std::vector<double>& edges)
00052 {
00053 #ifdef BDSDEBUG
00054   G4cout << __METHOD_NAME__ << "Name: " << name
00055          << ", Title: " << title << G4endl
00056          << __METHOD_NAME__ << "Vector of bin edges - # of Bins: " << edges.size()
00057          << ", Lower limit: " << edges.front()
00058          << ", Upper limit: " << edges.back() << G4endl;
00059 #endif
00060   histograms1d.push_back(new BDSHistogram1D(edges,name, title));
00061   return histograms1d.size();
00062 }
00063 
00064 BDSHistogram1D* BDSAnalysisManager::GetHistogram(G4int histoIndex)
00065 {
00066   CheckHistogramIndex(histoIndex);
00067   return histograms1d[histoIndex];
00068 }
00069 
00070 void BDSAnalysisManager::Fill1DHistogram(G4int histoIndex, G4double value, G4double weight)
00071 {
00072   CheckHistogramIndex(histoIndex);
00073   histograms1d[histoIndex]->Fill(value,weight);
00074 }
00075 
00076 void BDSAnalysisManager::CheckHistogramIndex(G4int histoIndex)
00077 {
00078   if ( ((size_t)histoIndex > histograms1d.size()) || histoIndex < 0 )
00079   {
00080     G4cerr << __METHOD_NAME__ << "invalid histogram index" << G4endl;
00081     exit(1);
00082   }
00083   // else void - keep going
00084 }

Generated on 28 Jun 2015 for BDSIM by  doxygen 1.4.7