ATLAS Offline Software
Loading...
Searching...
No Matches
Hist.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5*/
6
7// Hist.cxx
8// Implementation file for class AthEx::Hist
9// Author: S.Binet<binet@cern.ch>
11
12// AthExHistNtup includes
13#include "Hist.h"
14
15// STL includes
16
17// FrameWork includes
18#include "Gaudi/Property.h"
19
20// ROOT includes
21#include "TH1F.h"
22
23// event includes
25
26using namespace AthEx;
27
29// Public methods:
31
32// Constructors
34Hist::Hist( const std::string& name,
35 ISvcLocator* pSvcLocator ) :
36 ::AthAlgorithm( name, pSvcLocator ),
37 m_ntsvc("THistSvc/THistSvc", name),
38 m_hist (0)
39{
40 //
41 // Property declaration
42 //
43
44 declareProperty( "EvtInfo",
45 m_evtInfoName = "",
46 "key to the event-info instance to histogram-ize.");
47
48}
49
50// Destructor
54
55// Athena Algorithm's Hooks
57StatusCode Hist::initialize()
58{
59 ATH_MSG_INFO ("Initializing " << name() << "...");
60
61 if (!m_ntsvc.retrieve().isSuccess()) {
62 ATH_MSG_ERROR("could not retrieve handle to ntuple svc");
63 return StatusCode::FAILURE;
64 }
65
66 // register our histogram with the svc
67 m_hist = new TH1F("h1", "histogram title", 100,0.,100.);
68 if (!m_ntsvc->regHist("/stat/simple1D/h1", m_hist).isSuccess()) {
69 ATH_MSG_ERROR("could not register histogram [h1]");
70 delete m_hist; m_hist = 0;
71 return StatusCode::FAILURE;
72 }
73
74 return StatusCode::SUCCESS;
75}
76
77StatusCode Hist::finalize()
78{
79 ATH_MSG_INFO ("Finalizing " << name() << "...");
80
81 return StatusCode::SUCCESS;
82}
83
84StatusCode Hist::execute()
85{
86 ATH_MSG_DEBUG ("Executing " << name() << "...");
87
88 // get event data...
89 const xAOD::EventInfo* evt = 0;
90 if (!evtStore()->retrieve(evt, m_evtInfoName).isSuccess() ||
91 0==evt) {
92 ATH_MSG_ERROR("could not get event-info at [" << m_evtInfoName << "]");
93 return StatusCode::FAILURE;
94 }
95
96 int event = evt->eventNumber();
97
98 // fill the histogram
99 m_hist->Fill( float(event), 1.);
100
101 return StatusCode::SUCCESS;
102}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
std::string m_evtInfoName
key to the event-info
Definition Hist.h:67
ServiceHandle< ITHistSvc > m_ntsvc
handle to the n-tuple svc
Definition Hist.h:61
virtual ~Hist()
Destructor:
Definition Hist.cxx:52
Hist()
Default constructor:
virtual StatusCode initialize()
Definition Hist.cxx:57
virtual StatusCode execute()
Definition Hist.cxx:84
virtual StatusCode finalize()
Definition Hist.cxx:77
TH1F * m_hist
pointer to our histogram
Definition Hist.h:64
Definition Hist.h:25
EventInfo_v1 EventInfo
Definition of the latest event info version.