ATLAS Offline Software
Loading...
Searching...
No Matches
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
9CscRdoToCscDigit::CscRdoToCscDigit(const std::string& name, ISvcLocator* pSvcLocator) : AthReentrantAlgorithm(name, pSvcLocator) {}
10
12 ATH_CHECK(m_idHelperSvc.retrieve());
14 ATH_CHECK(m_cscCalibTool.retrieve());
15 ATH_CHECK(m_cscRdoKey.initialize());
16 ATH_CHECK(m_cscDigitKey.initialize());
18 return StatusCode::SUCCESS;
19}
20
21StatusCode 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
const double width
#define ATLAS_THREAD_SAFE
An algorithm that can be simultaneously executed in multiple threads.
Use IdentifiableContainer with CscDigitCollection.
int charge() const
Return the charge.
Definition CscDigit.h:42
Collection of CSC Raw Hits, arranged according to CSC Detector Elements Author: Ketevi A.
uint8_t rate() const
the rate could be 25 or 50 ns
This container provides access to collections of CSC RDOs and a mechanism for recording them.
Class to hold the electronic output for a single CSC readout channel: n sampling ADC data + the addre...
Definition CscRawData.h:21
ToolHandle< Muon::ICSC_RDO_Decoder > m_cscRdoDecoderTool
virtual StatusCode execute(const EventContext &ctx) const override final
CscRdoToCscDigit(const std::string &name, ISvcLocator *pSvcLocator)
SG::ReadHandleKey< CscRawDataContainer > m_cscRdoKey
ToolHandle< ICscCalibTool > m_cscCalibTool
StatusCode decodeCsc(const CscRawDataCollection *, CscDigitContainer *, CscDigitCollection *&, Identifier &) const
virtual StatusCode initialize() override final
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
SG::WriteHandleKey< CscDigitContainer > m_cscDigitKey
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
size_type begin_index() const
Definition IdContext.h:45
size_type end_index() const
Definition IdContext.h:46
const_iterator end() const
return const_iterator for end of container
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,...
size_t size() const
Duplicate of fullSize for backwards compatability.
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,...
const_iterator begin() const
return const_iterator for first entry
This is a "hash" representation of an Identifier.
void show() const
Print out in hex form.
Identifier identify() const
Definition MuonDigit.h:30
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.