| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

SimHists.cc

Go to the documentation of this file.
00001 
00007 #include "SimHists.h"
00008 
00009 #include "Event/SimHeader.h"
00010 #include "Event/SimHitHeader.h"
00011 #include "Event/SimHitCollection.h"
00012 #include "Event/SimHit.h"
00013 
00014 #include "Conventions/Detectors.h"
00015 #include "Conventions/Site.h"
00016 #include "Conventions/DetectorId.h"
00017 
00018 #include "GaudiKernel/ITHistSvc.h"
00019 
00020 #include "TH1I.h"
00021 #include "TH2F.h"
00022 
00023 #include <map>
00024 #include <string>
00025 using namespace std;
00026 
00027 typedef map<short int, pair<int,string> > detector_bins_t;
00028 static detector_bins_t detector_bins;
00029 
00030 SimHists::SimHists(const std::string& name, ISvcLocator* pSvcLocator)
00031     : GaudiAlgorithm(name,pSvcLocator)
00032     , m_hsvc(0)
00033     , m_nHitCollections(0)
00034     , m_nHitByDetector(0)
00035 {
00036     declareProperty("Location",m_location=DayaBay::SimHeaderLocation::Default,
00037                     "Location in the TES to get HepMCEvents");
00038     declareProperty("FilePath",m_filepath="/file1/sim/",
00039                     "File path with with to register histograms.");
00040 
00041     if (!detector_bins.size()) {
00042         DayaBay::Detector dets[] = {
00043             DayaBay::Detector(Site::kDayaBay,DetectorId::kAD1),
00044             DayaBay::Detector(Site::kDayaBay,DetectorId::kAD2),
00045             DayaBay::Detector(Site::kDayaBay,DetectorId::kOWS),
00046             DayaBay::Detector(Site::kDayaBay,DetectorId::kIWS),
00047             DayaBay::Detector(Site::kDayaBay,DetectorId::kRPC),
00048             DayaBay::Detector(Site::kLingAo,DetectorId::kAD1),
00049             DayaBay::Detector(Site::kLingAo,DetectorId::kAD2),
00050             DayaBay::Detector(Site::kLingAo,DetectorId::kOWS),
00051             DayaBay::Detector(Site::kLingAo,DetectorId::kIWS),
00052             DayaBay::Detector(Site::kLingAo,DetectorId::kRPC),
00053             DayaBay::Detector(Site::kFar,DetectorId::kAD1),
00054             DayaBay::Detector(Site::kFar,DetectorId::kAD2),
00055             DayaBay::Detector(Site::kFar,DetectorId::kAD3),
00056             DayaBay::Detector(Site::kFar,DetectorId::kAD4),
00057             DayaBay::Detector(Site::kFar,DetectorId::kOWS),
00058             DayaBay::Detector(Site::kFar,DetectorId::kIWS),
00059             DayaBay::Detector(Site::kFar,DetectorId::kRPC),
00060             DayaBay::Detector(),
00061         };
00062 
00063         detector_bins[0] = pair<int,string>(0,"unknown");
00064         for (int ind=0; dets[ind].site(); ++ind) {
00065             detector_bins[dets[ind].siteDetPackedData()] 
00066                 = pair<int,string>(ind+1,dets[ind].detName());
00067         }
00068     }
00069 }
00070 
00071 SimHists::~SimHists()
00072 {
00073 }
00074 
00075 StatusCode SimHists::initialize()
00076 {
00077     this->GaudiAlgorithm::initialize();
00078 
00079     // Get the histogram service
00080     if ( service("THistSvc", m_hsvc).isFailure()) {
00081         error() << " No THistSvc available." << endreq;
00082         return StatusCode::FAILURE;
00083     } 
00084 
00085     m_nHitCollections = new TH1I("nHitCollections","Number of Hit Collections",15,0,15);
00086     if (m_hsvc->regHist(m_filepath+"nHitCollections",m_nHitCollections).isFailure()) {
00087         error() << "Could not register " << m_filepath+"nHitCollections" << endreq;
00088         delete m_nHitCollections; m_nHitCollections = 0;
00089         return StatusCode::FAILURE;
00090     }
00091 
00092     m_nHitByDetector = new TH2F("nHitByDetector","Number of hits in each detector",
00093                                 15,0,15,1000,0,1000);
00094     if (m_hsvc->regHist(m_filepath+"nHitByDetector",m_nHitByDetector).isFailure()) {
00095         error() << "Could not register " << m_filepath+"nHitByDetector" << endreq;
00096         delete m_nHitByDetector; m_nHitByDetector = 0;
00097         return StatusCode::FAILURE;
00098     }
00099     // FIXME: label bins by detector name
00100 
00101     return StatusCode::SUCCESS;
00102 }
00103 
00104 StatusCode SimHists::execute()
00105 {
00106     DayaBay::SimHeader* shead = get<DayaBay::SimHeader>(m_location);
00107     const DayaBay::SimHitHeader* shith = shead->hits();
00108     const DayaBay::SimHitHeader::hc_map& hcmap = shith->hitCollection();
00109 
00110     m_nHitCollections->Fill(hcmap.size());
00111     
00112     DayaBay::SimHitHeader::hc_map::const_iterator it, done = hcmap.end();
00113     for (it=hcmap.begin(); it != done; ++it) {
00114         DayaBay::Detector det(it->first);
00115         pair<int,string> bin = detector_bins[det.siteDetPackedData()];
00116 
00117         info () << "Got hit collection from " << det.detName() 
00118                 << " in bin " << bin.first << endreq;
00119 
00120         size_t siz = it->second->collection().size();
00121         m_nHitByDetector->Fill(bin.first + 0.5,siz);
00122     }
00123 
00124     return StatusCode::SUCCESS;
00125 }
00126 
00127 StatusCode SimHists::finalize()
00128 {
00129 
00130     return this->GaudiAlgorithm::finalize();
00131 }
00132 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:57:27 2011 for SimHistsExample by doxygen 1.4.7