ATLAS Offline Software
CscRdoToCscDigit.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "CscRdoToCscDigit.h"
6 
8 
9 CscRdoToCscDigit::CscRdoToCscDigit(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
10 
12  ATH_CHECK(m_idHelperSvc.retrieve());
14  ATH_CHECK(m_cscCalibTool.retrieve());
17  ATH_CHECK(m_cscRdoDecoderTool.retrieve());
18  return StatusCode::SUCCESS;
19 }
20 
21 StatusCode CscRdoToCscDigit::execute(const EventContext& ctx) const {
22  ATH_MSG_DEBUG("in execute()");
23  // retrieve the collection of RDO
25  if (!rdoRH.isValid()) {
26  ATH_MSG_WARNING("No CSC RDO container found!");
27  return StatusCode::SUCCESS;
28  }
29  const CscRawDataContainer* rdoContainer = rdoRH.cptr();
30  ATH_MSG_DEBUG("Retrieved " << rdoContainer->size() << " CSC RDOs.");
31 
33  ATH_CHECK(wh_cscDigit.record(std::make_unique<CscDigitContainer>(m_idHelperSvc->cscIdHelper().module_hash_max())));
34  ATH_MSG_DEBUG("Decoding CSC RDO into CSC Digit");
35 
36  Identifier oldId;
37  CscDigitCollection* collection(nullptr);
38  // now decode RDO into digits
39  auto it_rdoColl = rdoContainer->begin();
40  auto lastRdoColl = rdoContainer->end();
41 
42  for (; it_rdoColl != lastRdoColl; ++it_rdoColl) { ATH_CHECK(this->decodeCsc(*it_rdoColl, wh_cscDigit.ptr(), collection, oldId)); }
43 
44  return StatusCode::SUCCESS;
45 }
46 
48  CscDigitCollection*& collection, Identifier& oldId) const {
49  ATH_MSG_DEBUG(" Number of RawData in this rdo " << rdoColl->size());
50 
51  const double samplingTime = rdoColl->rate();
52  const unsigned int numSamples = rdoColl->numSamples();
53 
54  // decoder.setParams(samplingTime);
55 
56  const IdContext cscContext = m_idHelperSvc->cscIdHelper().module_context();
57 
60  for (const CscRawData* data : *rdoColl) {
61  if (!data) {
62  ATH_MSG_WARNING("NULL pointer to Digit!");
63  continue;
64  }
65  const uint16_t width = data->width();
66  Identifier stationId = m_cscRdoDecoderTool->stationIdentifier(data, &m_idHelperSvc->cscIdHelper());
67  for (int j = 0; j < width; ++j) {
68  Identifier channelId = m_cscRdoDecoderTool->channelIdentifier(data, &m_idHelperSvc->cscIdHelper(), j);
69  std::vector<uint16_t> samples;
70  const bool extractSamples = data->samples(j, numSamples, samples);
71  if (!extractSamples) {
72  ATH_MSG_WARNING("Unable to extract samples for strip " << j << " Online Cluster width = " << width
73  << " for number of Samples = " << numSamples << " continuing ...");
74  continue;
75  }
76  std::vector<float> charges;
77  const bool adctocharge = m_cscCalibTool->adcToCharge(samples, data->hashId(), charges);
78  double charge = 0.0;
79  double time = 0.0;
80  unsigned int samplingPhase = 0;
81  const int errorfindCharge = m_cscCalibTool->findCharge(samplingTime, samplingPhase, charges, charge, time);
82  // WPARK: Potential problem! error code includes time out of range and aa>0
83  // If this is the case, only very nice samples are converted to Digit. Sep 11, 2009
84  if (!adctocharge || !errorfindCharge) {
85  ATH_MSG_WARNING(" CSC conversion ADC to Charge failed "
86  << "CSC Digit not build ... "
87  << " or charge finding failed "
88  << " ... skipping ");
89  continue;
90  }
91  ATH_MSG_DEBUG("CSC RDO->CscDigit: " << m_idHelperSvc->cscIdHelper().show_to_string(channelId));
92  const int theCharge = static_cast<int>(charge);
93  CscDigit* newDigit = new CscDigit(channelId, theCharge, time);
94  ATH_MSG_DEBUG("CSC RDO->Digit: " << m_idHelperSvc->cscIdHelper().show_to_string(newDigit->identify()) << " "
95  << newDigit->charge() << " " << charge << " time= " << time);
96 
97  for (uint16_t i = 0; i < samples.size(); ++i) { ATH_MSG_DEBUG("CSC RDO->Digit: " << samples[i]); }
98  IdentifierHash coll_hash;
99  if (m_idHelperSvc->cscIdHelper().get_hash(stationId, coll_hash, &cscContext)) {
100  ATH_MSG_WARNING("Unable to get CSC digiti collection hash id "
101  << "context begin_index = " << cscContext.begin_index()
102  << " context end_index = " << cscContext.end_index() << " the identifier is ");
103  stationId.show();
104  }
105 
106  if (oldId != stationId) {
107  const CscDigitCollection* coll = cscContainer->indexFindPtr(coll_hash);
108  if (nullptr == coll) {
109  CscDigitCollection* newCollection = new CscDigitCollection(stationId, coll_hash);
110  newCollection->push_back(newDigit);
111  collection = newCollection;
112  if (cscContainer->addCollection(newCollection, coll_hash).isFailure()) {
113  ATH_MSG_WARNING("Couldn't record CscDigitCollection with key=" << coll_hash << " in StoreGate!");
114  }
115  } else {
116  CscDigitCollection* oldCollection ATLAS_THREAD_SAFE = const_cast<CscDigitCollection*>(coll); // FIXME
117  oldCollection->push_back(newDigit);
118  collection = oldCollection;
119  }
120  oldId = stationId;
121  } else {
122  collection->push_back(newDigit);
123  }
124  }
125  }
126  return StatusCode::SUCCESS;
127 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CscDigitContainer
Use IdentifiableContainer with CscDigitCollection.
Definition: CscDigitContainer.h:50
CscRdoToCscDigit::m_cscCalibTool
ToolHandle< ICscCalibTool > m_cscCalibTool
Definition: CscRdoToCscDigit.h:28
SG::ReadHandle::cptr
const_pointer_type cptr()
Dereference the pointer.
IdentifiableContainerMT::addCollection
virtual StatusCode addCollection(const T *coll, IdentifierHash hashId) override final
insert collection into container with id hash if IDC should not take ownership of collection,...
Definition: IdentifiableContainerMT.h:297
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
CscRdoToCscDigit::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: CscRdoToCscDigit.cxx:21
IdContext::end_index
size_type end_index() const
Definition: IdContext.h:46
CscRdoToCscDigit::m_cscDigitKey
SG::WriteHandleKey< CscDigitContainer > m_cscDigitKey
Definition: CscRdoToCscDigit.h:32
IdentifiableContainerMT::size
size_t size() const
Duplicate of fullSize for backwards compatability.
Definition: IdentifiableContainerMT.h:206
IMuonDigitizationTool.h
CscRdoToCscDigit::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: CscRdoToCscDigit.h:30
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
IdContext::begin_index
size_type begin_index() const
Definition: IdContext.h:45
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
CscRdoToCscDigit.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CscDigit
Definition: CscDigit.h:17
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IdentifiableContainerMT::end
const_iterator end() const
return const_iterator for end of container
Definition: IdentifiableContainerMT.h:239
CscDigit::charge
int charge() const
Return the charge.
Definition: CscDigit.h:42
IdentifiableContainerMT::begin
const_iterator begin() const
return const_iterator for first entry
Definition: IdentifiableContainerMT.h:233
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
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
Identifier::show
void show() const
Print out in hex form.
Definition: Identifier.cxx:30
CscRawDataCollection
Collection of CSC Raw Hits, arranged according to CSC Detector Elements Author: Ketevi A.
Definition: CscRawDataCollection.h:24
CscRdoToCscDigit::initialize
virtual StatusCode initialize() override final
Definition: CscRdoToCscDigit.cxx:11
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
CscRawDataCollection::numSamples
uint16_t numSamples() const
Definition: CscRawDataCollection.cxx:8
CscDigitCollection
Definition: CscDigitCollection.h:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
charge
double charge(const T &p)
Definition: AtlasPID.h:756
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
IdentifiableContainerMT::indexFindPtr
virtual const T * indexFindPtr(IdentifierHash hashId) const override final
return pointer on the found entry or null if out of range using hashed index - fast version,...
Definition: IdentifiableContainerMT.h:289
MuonDigit::identify
Identifier identify() const
Definition: MuonDigit.h:30
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
CscRawData
Class to hold the electronic output for a single CSC readout channel: n sampling ADC data + the addre...
Definition: CscRawData.h:21
CscRdoToCscDigit::m_cscRdoDecoderTool
ToolHandle< Muon::ICSC_RDO_Decoder > m_cscRdoDecoderTool
Definition: CscRdoToCscDigit.h:29
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
CscRawDataContainer
This container provides access to collections of CSC RDOs and a mechanism for recording them.
Definition: CscRawDataContainer.h:23
CscRdoToCscDigit::CscRdoToCscDigit
CscRdoToCscDigit(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CscRdoToCscDigit.cxx:9
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
IdContext
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition: IdContext.h:26
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
CscRdoToCscDigit::m_cscRdoKey
SG::ReadHandleKey< CscRawDataContainer > m_cscRdoKey
Definition: CscRdoToCscDigit.h:31
CscRawDataCollection::rate
uint8_t rate() const
the rate could be 25 or 50 ns
Definition: CscRawDataCollection.cxx:24
CscRdoToCscDigit::decodeCsc
StatusCode decodeCsc(const CscRawDataCollection *, CscDigitContainer *, CscDigitCollection *&, Identifier &) const
Definition: CscRdoToCscDigit.cxx:47
Identifier
Definition: IdentifierFieldParser.cxx:14