ATLAS Offline Software
TileMuToNtuple.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //*****************************************************************************
6 // Filename : TileMuToNtuple.cxx
7 //*****************************************************************************
8 
9 //Tile includes
11 
12 // Athena incldues
13 #include "StoreGate/ReadHandle.h"
14 
15 //Gaudi Includes
16 #include "GaudiKernel/Bootstrap.h"
17 #include "GaudiKernel/INTupleSvc.h"
18 #include "GaudiKernel/NTuple.h"
19 #include "GaudiKernel/IDataProviderSvc.h"
20 #include "GaudiKernel/SmartDataPtr.h"
21 
22 
23 // Constructor & deconstructor
24 TileMuToNtuple::TileMuToNtuple(const std::string& name, ISvcLocator* pSvcLocator)
25  : AthAlgorithm(name, pSvcLocator)
26  , m_ntuplePtr(0)
27  , m_ntupleID(100)
28  , m_maxNtag(50)
29  , m_close(1)
30  , m_ntupleLoc("/FILE1/TileMuTag")
31  , m_tileMuContainer("TileMuObj")
32 {
33 
34  declareProperty("NTupleLoc", m_ntupleLoc);
35  declareProperty("NTupleID", m_ntupleID);
36  declareProperty("MaxNtag", m_maxNtag);
37  declareProperty("CloseNtuple", m_close);
38 }
39 
41 }
42 
43 // Alg standard interface function
45 
46  m_ntupleLoc = "/NTUPLES/FILE1/TileMuTag";
47  // + m_ntupleLoc;
48 
49  SmartDataPtr<NTuple::Directory> DirPtr(ntupleSvc(), m_ntupleLoc);
50  if (!DirPtr) DirPtr = ntupleSvc()->createDirectory(m_ntupleLoc);
51  if (!DirPtr) {
52  ATH_MSG_ERROR( "Invalid Ntuple Directory: " << m_ntupleLoc );
53  return StatusCode::FAILURE;
54  }
55 
56  m_ntuplePtr = ntupleSvc()->book(DirPtr.ptr(), m_ntupleID, CLID_ColumnWiseTuple,
57  "TileMuTag-Ntuple");
58  if (!m_ntuplePtr) {
59  ATH_MSG_ERROR( "Failed to book ntuple: TileMuTagNtuple" );
60  return StatusCode::FAILURE;
61  }
62 
63  CHECK( m_ntuplePtr->addItem("TileMu/ntag", m_ntag, 0, m_maxNtag) );
64  CHECK( m_ntuplePtr->addItem("TileMu/etatag", m_ntag, m_eta, -1.5, 1.5) );
65  CHECK( m_ntuplePtr->addItem("TileMu/phitag", m_ntag, m_phi, 0., 6.3) );
66  CHECK( m_ntuplePtr->addItem("TileMu/energydepVec", m_ntag, m_energy, 4) );
67  CHECK( m_ntuplePtr->addItem("TileMu/quality", m_ntag, m_quality, 0., 1.) );
68 
69  ATH_CHECK( m_muContainerKey.initialize() );
70 
71  ATH_MSG_INFO( "initialisation completed" );
72 
73  return StatusCode::SUCCESS;
74 }
75 
77 
78  // step1: read from TDS
80  ATH_CHECK( muContainer.isValid() );
81 
82  m_ntag = 0;
83 
84  for (const TileMu* mu : *muContainer) {
85 
86  m_eta[m_ntag] = mu->eta();
87 
88  m_energy[m_ntag][0] = (mu->enedep())[0];
89  m_energy[m_ntag][1] = (mu->enedep())[1];
90  m_energy[m_ntag][2] = (mu->enedep())[2];
91  m_energy[m_ntag][3] = (mu->enedep())[3];
92  m_phi[m_ntag] = mu->phi();
93  m_quality[m_ntag] = mu->quality();
94  m_ntag++;
95 
96  if (m_ntag >= m_maxNtag) break;
97  }
98 
99  // write ntuple (is useful to keep it open to write also MC truth)
100  if (m_close == 1) {
101  CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
102  }
103 
104  // Execution completed.
105  ATH_MSG_DEBUG( "execute() completed successfully" );
106 
107  return StatusCode::SUCCESS;
108 }
109 
111  ATH_MSG_INFO( "finalize() successfully" );
112 
113  return StatusCode::SUCCESS;
114 }
115 
TileMuToNtuple::m_close
int m_close
Definition: TileMuToNtuple.h:52
TileMuToNtuple::m_phi
NTuple::Array< float > m_phi
Definition: TileMuToNtuple.h:57
TileMuToNtuple::m_muContainerKey
SG::ReadHandleKey< TileMuContainer > m_muContainerKey
Definition: TileMuToNtuple.h:63
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TileMuToNtuple::m_eta
NTuple::Array< float > m_eta
Definition: TileMuToNtuple.h:56
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TileMuToNtuple::finalize
StatusCode finalize()
Definition: TileMuToNtuple.cxx:110
TileMuToNtuple::m_ntupleLoc
std::string m_ntupleLoc
Definition: TileMuToNtuple.h:53
TileMuToNtuple::~TileMuToNtuple
virtual ~TileMuToNtuple()
Definition: TileMuToNtuple.cxx:40
TileMuToNtuple::TileMuToNtuple
TileMuToNtuple(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TileMuToNtuple.cxx:24
TileMuToNtuple::m_ntag
NTuple::Item< int > m_ntag
Definition: TileMuToNtuple.h:55
TileMuToNtuple.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TileMuToNtuple::m_energy
NTuple::Matrix< float > m_energy
Definition: TileMuToNtuple.h:58
TileMuToNtuple::m_ntuplePtr
NTuple::Tuple * m_ntuplePtr
Definition: TileMuToNtuple.h:49
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
AthAlgorithm
Definition: AthAlgorithm.h:47
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
TileMuToNtuple::m_maxNtag
int m_maxNtag
Definition: TileMuToNtuple.h:51
TileMuToNtuple::m_quality
NTuple::Array< float > m_quality
Definition: TileMuToNtuple.h:59
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TileMuToNtuple::m_ntupleID
int m_ntupleID
Definition: TileMuToNtuple.h:50
TileMuToNtuple::initialize
StatusCode initialize()
Definition: TileMuToNtuple.cxx:44
ReadHandle.h
Handle class for reading from StoreGate.
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
CaloNoise_fillDB.mu
mu
Definition: CaloNoise_fillDB.py:53
TileMu
Class to store TileMuId quantities.
Definition: TileMu.h:25
TileMuToNtuple::execute
StatusCode execute()
Definition: TileMuToNtuple.cxx:76