ATLAS Offline Software
ReadLArDigits.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "ReadLArDigits.h"
6 #include "LArRawEvent/LArDigit.h"
7 #include <vector>
8 // #include "GaudiKernel/IToolSvc.h"
10 #include "StoreGate/ReadHandle.h"
11 
12 
14 {m_onlineHelper=onlineHelper;
15 }
16 
17 ReadLArDigits::ReadLArDigits(const std::string& name, ISvcLocator* pSvcLocator) : AthAlgorithm(name, pSvcLocator),
18  m_emId(nullptr),
19  m_onlineHelper(nullptr),
20  m_ntuplePtr(nullptr)
21 
22 {m_count=0;
23  declareProperty("DumpFile",m_dumpFile="");
24  declareProperty("PrintCellLocation",m_printCellLoc=false);
25  declareProperty("PrintFebChan",m_printFebChan=true);
26 
27 }
28 
30 {//empty
31 }
32 
34 {
35  ATH_MSG_INFO( "Initialize" );
36 
37  const CaloCell_ID* idHelper = nullptr;
38  ATH_CHECK( detStore()->retrieve (idHelper, "CaloCell_ID") );
39  m_emId=idHelper->em_idHelper();
40 
42  ATH_CHECK( detStore()->retrieve(m_onlineHelper, "LArOnlineID") );
43 
44  if (!m_dumpFile.empty())
45  m_outfile.open(m_dumpFile.c_str(),std::ios::out);
46  //Ntuple booking
47 
48 
49  NTupleFilePtr file1(ntupleSvc(),"/NTUPLES/FILE1");
50  if (!file1) {
51  ATH_MSG_ERROR( "Booking of NTuple failed" );
52  return StatusCode::FAILURE;
53  }
54  NTuplePtr nt(ntupleSvc(),"/NTUPLES/FILE1/LARDIGITS");
55  if (!nt) {
56  nt=ntupleSvc()->book("/NTUPLES/FILE1/LARDIGITS",CLID_ColumnWiseTuple,"LArDigits");
57  }
58  if (!nt) {
59  ATH_MSG_ERROR( "Booking of NTuple failed" );
60  return StatusCode::FAILURE;
61  }
62 
63  ATH_CHECK( nt->addItem("icell",m_cellIndex,0,3600) );
64  ATH_CHECK( nt->addItem("layer",m_cellIndex,m_layer) );
65  ATH_CHECK( nt->addItem("ieta",m_cellIndex,m_eta) );
66  ATH_CHECK( nt->addItem("iphi",m_cellIndex,m_phi) );
67  ATH_CHECK( nt->addItem("barrel_ec",m_cellIndex,m_barrel_ec) );
68  ATH_CHECK( nt->addItem("pos_neg",m_cellIndex,m_pos_neg) );
69  ATH_CHECK( nt->addItem("FT",m_cellIndex,m_FT) );
70  ATH_CHECK( nt->addItem("slot",m_cellIndex,m_slot) );
71  ATH_CHECK( nt->addItem("channel",m_cellIndex,m_channel) );
72  ATH_CHECK( nt->addItem("gain",m_cellIndex,m_gain) );
73  ATH_CHECK( nt->addItem("NSamples",m_Nsamples,0,32) );
74  ATH_CHECK( nt->addItem("Samples",m_cellIndex,m_samples,32) );
75 
77 
79  m_count=0;
80  ATH_MSG_INFO( "======== ReadLArDigits initialize successfully ========" );
81  return StatusCode::SUCCESS;
82 }
83 
84 
86 {
87  m_count++;
88  ATH_MSG_VERBOSE( "======== executing event "<< m_count << " ========" );
89  ATH_MSG_VERBOSE( "Retrieving LArDigitContainer. Key= " << m_containerKey.key() );
90  const EventContext& ctx = Gaudi::Hive::currentContext();
92 
93  // View container copy.
94  LArDigitContainer larDigitCont (*larDigitContIn);
95 
97  const LArOnOffIdMapping* cabling{*cablingHdl};
98  if(!cabling) {
99  ATH_MSG_ERROR("Do not have mapping object " << m_cablingKey.key());
100  return StatusCode::FAILURE;
101  }
102 
103 
104  if (m_outfile.is_open()) {
105  SortDigits sortDigits(m_onlineHelper);
106  std::sort(larDigitCont.begin(),larDigitCont.end(),sortDigits);
107  }
108  unsigned cellCounter=0;
109  m_cellIndex=0;
110  if (!larDigitCont.empty())
111  m_Nsamples=larDigitCont.front()->samples().size();
112  else
113  m_Nsamples=0;
114  for (const LArDigit* digit : larDigitCont) {
115  HWIdentifier chid=digit->hardwareID();
116  const std::vector<short>& vSamples=digit->samples();
117  m_cellIndex++;
118  try {
119  const Identifier id=cabling->cnvToIdentifier(chid);
120  if (m_emId->is_lar_em(id))
121  {m_eta[cellCounter]=m_emId->eta(id);
122  m_phi[cellCounter]=m_emId->phi(id);
123  m_layer[cellCounter]=m_emId->sampling(id);
124  }
125  else {
126  m_eta[cellCounter]=0;
127  m_phi[cellCounter]=0;
128  m_layer[cellCounter]=0;
129  }
130  }
131  catch (LArID_Exception & except) {
132  m_eta[cellCounter]=-999;
133  m_phi[cellCounter]=-999;
134  m_layer[cellCounter]=-999;
135  }
136  m_barrel_ec[cellCounter]=m_onlineHelper->barrel_ec(chid);
137  m_pos_neg[cellCounter] = m_onlineHelper->pos_neg(chid);
138  m_FT[cellCounter] = m_onlineHelper->feedthrough(chid);
139  m_slot[cellCounter] = m_onlineHelper->slot(chid);
140  m_channel[cellCounter] = m_onlineHelper->channel(chid);
141  m_gain[cellCounter]=digit->gain();
142 
143  int nSamples=vSamples.size();
144  for (int i=0;i<nSamples && i<32;i++)
145  m_samples[cellCounter][i]=vSamples[i];
146 
147  if (m_outfile.is_open()) {
148  if (m_printCellLoc) {
149  if (m_eta[cellCounter]==-999 && m_phi[cellCounter]==-999 && m_layer[cellCounter]==-999)
150  m_outfile << "Cell l/e/p= <ILLEGAL IDENTIFIER> ";
151  else
152  m_outfile << "Cell l/e/p= " << m_layer[cellCounter] << "/" << m_eta[cellCounter]
153  << "/" << m_phi[cellCounter] << " ";
154  }
155  if (m_printFebChan)
156  m_outfile << "FebId= 0x" << std::hex << m_onlineHelper->feb_Id(chid).get_compact()
157  << std::dec << " Ch= " << m_channel[cellCounter] << " ";
158  for (int i=0;i<nSamples;i++) {
159  m_outfile << " " << vSamples[i];
160  }
161  m_outfile << " G=" << m_gain[cellCounter] << std::endl;
162  }
163  cellCounter++;
164  }
165  ATH_CHECK( ntupleSvc()->writeRecord(m_ntuplePtr) );
166 
167  if (m_count%1000==0)
168  ATH_MSG_INFO( "Event " << m_count << " contains " << cellCounter << " channels" );
169  return StatusCode::SUCCESS;
170 }
171 
173 {
174  if (m_outfile.is_open())
175  m_outfile.close();
176  ATH_MSG_INFO( "finalize ReadLarDigits" );
177  return StatusCode::SUCCESS;
178 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArEM_Base_ID::phi
int phi(const Identifier id) const
return phi according to :
ReadLArDigits::SortDigits
CTB: code to read digits.
Definition: ReadLArDigits.h:77
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
CaloCell_ID::em_idHelper
const LArEM_ID * em_idHelper() const
access to EM idHelper
Definition: CaloCell_ID.h:63
ReadLArDigits::ReadLArDigits
ReadLArDigits(const std::string &name, ISvcLocator *pSvcLocator)
Definition: ReadLArDigits.cxx:17
ReadLArDigits::execute
StatusCode execute()
Definition: ReadLArDigits.cxx:85
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
ReadLArDigits::finalize
StatusCode finalize()
Definition: ReadLArDigits.cxx:172
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
LArDigit::samples
const std::vector< short > & samples() const
Definition: LArDigit.h:78
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
LArOnlineID_Base::slot
int slot(const HWIdentifier id) const
Return the slot number of a hardware cell identifier: slot = [1,15] Slot-ID in top part of the crat...
Definition: LArOnlineID_Base.cxx:1961
ReadLArDigits::m_channel
NTuple::Array< long > m_channel
Definition: ReadLArDigits.h:62
LArEM_Base_ID::sampling
int sampling(const Identifier id) const
return sampling according to :
ReadLArDigits::m_cellIndex
NTuple::Item< long > m_cellIndex
Definition: ReadLArDigits.h:60
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SG::VarHandleKey::key
const std::string & key() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:141
checkRpcDigits.digit
digit
Definition: checkRpcDigits.py:186
HWIdentifier
Definition: HWIdentifier.h:13
LArOnlineID_Base::barrel_ec
int barrel_ec(const HWIdentifier id) const
Return the position barrel or endcap of a hardware cell identifier: barrel_ec = [0,...
Definition: LArOnlineID_Base.cxx:1942
LArEM_Base_ID::eta
int eta(const Identifier id) const
return eta according to :
CaloCell_ID.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
ReadLArDigits::m_layer
NTuple::Array< long > m_layer
Definition: ReadLArDigits.h:61
LArOnlineID_Base::channel
int channel(const HWIdentifier id) const
Return the channel number of a hardware cell identifier channel = [0,127] in all FEB.
Definition: LArOnlineID_Base.cxx:1967
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ReadLArDigits::m_printCellLoc
bool m_printCellLoc
Definition: ReadLArDigits.h:54
LArDigit.h
ReadLArDigits.h
ReadLArDigits::initialize
StatusCode initialize()
Definition: ReadLArDigits.cxx:33
LArDigit
Liquid Argon digit base class.
Definition: LArDigit.h:25
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ReadLArDigits::m_slot
NTuple::Array< long > m_slot
Definition: ReadLArDigits.h:62
DataVector::front
const T * front() const
Access the first element in the collection as an rvalue.
LArOnlineID_Base::pos_neg
int pos_neg(const HWIdentifier id) const
Return the side of a hardware cell identifier pos_neg = [0,1] positive-side or negative-side Barrel...
Definition: LArOnlineID_Base.cxx:1954
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
CaloCell_ID
Helper class for offline cell identifiers.
Definition: CaloCell_ID.h:34
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
ReadLArDigits::m_ntuplePtr
NTuple::Tuple * m_ntuplePtr
Definition: ReadLArDigits.h:58
AthAlgorithm
Definition: AthAlgorithm.h:47
LArOnlineID_Base::feb_Id
HWIdentifier feb_Id(int barrel_ec, int pos_neg, int feedthrough, int slot) const
Create feb_Id from fields.
Definition: LArOnlineID_Base.cxx:1483
ReadLArDigits::m_barrel_ec
NTuple::Array< long > m_barrel_ec
Definition: ReadLArDigits.h:62
ReadLArDigits::m_eta
NTuple::Array< long > m_eta
Definition: ReadLArDigits.h:61
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
ReadLArDigits::m_outfile
std::ofstream m_outfile
Definition: ReadLArDigits.h:50
ReadLArDigits::m_count
int m_count
Definition: ReadLArDigits.h:47
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArOnlineID
Definition: LArOnlineID.h:20
ReadLArDigits::m_containerKey
SG::ReadHandleKey< LArDigitContainer > m_containerKey
Definition: ReadLArDigits.h:52
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
ReadLArDigits::m_pos_neg
NTuple::Array< long > m_pos_neg
Definition: ReadLArDigits.h:62
LArOnlineID_Base::feedthrough
int feedthrough(const HWIdentifier id) const
Return the feedthrough of a hardware cell identifier : feedthrough = [0,31] Barrel - A/C side or H/...
Definition: LArOnlineID_Base.cxx:1948
ReadLArDigits::m_dumpFile
std::string m_dumpFile
Definition: ReadLArDigits.h:53
Identifier::get_compact
value_type get_compact(void) const
Get the compact id.
ReadLArDigits::m_Nsamples
NTuple::Item< long > m_Nsamples
Definition: ReadLArDigits.h:64
ReadLArDigits::m_samples
NTuple::Matrix< long > m_samples
Definition: ReadLArDigits.h:63
ReadLArDigits::m_onlineHelper
const LArOnlineID * m_onlineHelper
Definition: ReadLArDigits.h:49
ReadLArDigits::m_phi
NTuple::Array< long > m_phi
Definition: ReadLArDigits.h:61
LArDigitContainer
Container class for LArDigit.
Definition: LArDigitContainer.h:24
ReadLArDigits::~ReadLArDigits
~ReadLArDigits()
Definition: ReadLArDigits.cxx:29
ReadLArDigits::SortDigits::SortDigits
SortDigits(const LArOnlineID *onlineHelper)
Definition: ReadLArDigits.cxx:13
ReadLArDigits::m_cablingKey
SG::ReadCondHandleKey< LArOnOffIdMapping > m_cablingKey
Definition: ReadLArDigits.h:46
LArDigits2NtupleDumper.nSamples
nSamples
Definition: LArDigits2NtupleDumper.py:70
ReadLArDigits::m_printFebChan
bool m_printFebChan
Definition: ReadLArDigits.h:55
ReadLArDigits::SortDigits::m_onlineHelper
const LArOnlineID * m_onlineHelper
Definition: ReadLArDigits.h:82
beamspotnt.nt
def nt
Definition: bin/beamspotnt.py:1063
ReadHandle.h
Handle class for reading from StoreGate.
ReadLArDigits::m_emId
const LArEM_ID * m_emId
Definition: ReadLArDigits.h:48
ntupleSvc
INTupleSvc * ntupleSvc()
Definition: ServiceAccessor.h:14
ReadLArDigits::m_gain
NTuple::Array< long > m_gain
Definition: ReadLArDigits.h:61
AtlasDetectorID::is_lar_em
bool is_lar_em(Identifier id) const
Definition: AtlasDetectorID.h:818
LArID_Exception
Exception class for LAr Identifiers.
Definition: LArID_Exception.h:20
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
ReadLArDigits::m_FT
NTuple::Array< long > m_FT
Definition: ReadLArDigits.h:62
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
LArOnOffIdMapping
Definition: LArOnOffIdMapping.h:20