ATLAS Offline Software
Loading...
Searching...
No Matches
AFP_Raw2DigiTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "AFP_Raw2DigiTool.h"
9
13
17
18#include <vector>
19
21 const std::string &name,
22 const IInterface *parent)
23 : base_class(type, name, parent),
24 m_totToChargeTransformation ("totToChargeTransformation", "1909 + x*363 + x*x*141")
25{}
26
28
30{
31 ATH_MSG_DEBUG("Initializing " << name() << "...");
32
33 ATH_CHECK( m_rawDataContainerName.initialize() );
34 ATH_CHECK( m_AFPSiHitsContainerName.initialize() );
36
37 m_totToChargeTransformation=TF1(m_totToChargeTransfName.toString().c_str(), m_totToChargeTransfExpr.toString().c_str());
38
39 return StatusCode::SUCCESS;
40}
41
42StatusCode AFP_Raw2DigiTool::recoAll(const EventContext &ctx) const
43{
44 ATH_CHECK( recoSiHits(ctx) );
45 ATH_CHECK( recoToFHits(ctx) );
46
47 return StatusCode::SUCCESS;
48}
49
50StatusCode AFP_Raw2DigiTool::recoSiHits(const EventContext &ctx) const
51{
52 ATH_MSG_DEBUG("AFP_Raw2DigiTool recoSiHits ");
53
54 // create output containers
55 auto siHitContainer = std::make_unique<xAOD::AFPSiHitContainer>();
56 auto siHitAuxContainer = std::make_unique<xAOD::AFPSiHitAuxContainer>();
57 siHitContainer->setStore(siHitAuxContainer.get());
58
59 // retrieve raw data
61 if (!container.isValid()) {
62 ATH_MSG_WARNING("AFP_Raw2DigiTool: Could not find raw data container");
63 return StatusCode::SUCCESS;
64 }
65 else
66 ATH_MSG_DEBUG("AFP_Raw2DigiTool: Raw data container retrieved");
67
68 for (const AFP_SiRawCollection& collection: container->collectionsSi())
69 for (const AFP_SiRawData& data : collection.dataRecords())
70 newXAODHitSi (siHitContainer.get(), collection, data);
71
73 ATH_CHECK( writeHandle.record(std::move(siHitContainer), std::move(siHitAuxContainer)) );
74
75 return StatusCode::SUCCESS;
76}
77
78StatusCode AFP_Raw2DigiTool::recoToFHits(const EventContext &ctx) const
79{
80 ATH_MSG_DEBUG("AFP_Raw2DigiTool recoToFHits ");
81
82 // create output containers
83 auto tofHitContainer = std::make_unique<xAOD::AFPToFHitContainer>();
84 auto tofHitAuxContainer = std::make_unique<xAOD::AFPToFHitAuxContainer>();
85 tofHitContainer->setStore(tofHitAuxContainer.get());
86
87 // retrieve raw data
89 if (!container.isValid()) {
90 ATH_MSG_WARNING("AFP_Raw2DigiTool: Could not find raw data container");
91 return StatusCode::SUCCESS;
92 }
93 else
94 ATH_MSG_DEBUG("AFP_Raw2DigiTool: Raw data container retrieved");
95
96 for (const AFP_ToFRawCollection& collection: container->collectionsToF())
97 for (const AFP_ToFRawData& data : collection.dataRecords())
98 if (data.hitDiscConfig() == 3 && (data.header() == 2 || (data.header() == 10 && !data.isTrigger())))
99 newXAODHitToF (tofHitContainer.get(), collection, data, ctx); // is_ToF && (is_HPTDC || (is_picoTDC && !is_trigger_word))
100
102 ATH_CHECK( writeHandle.record(std::move(tofHitContainer), std::move(tofHitAuxContainer)) );
103
104 return StatusCode::SUCCESS;
105}
106
107
109 ATH_MSG_INFO("Finalizing " << name() << "...");
110
111
112 return StatusCode::SUCCESS;
113}
114
115
116void AFP_Raw2DigiTool::newXAODHitToF (xAOD::AFPToFHitContainer* tofHitContainer, const AFP_ToFRawCollection& collection, const AFP_ToFRawData& data, const EventContext& ctx) const
117{
118 xAOD::AFPToFHit* xAODToFHit = new xAOD::AFPToFHit();
119 tofHitContainer->push_back(xAODToFHit);
120
121 const uint32_t hitLink = data.link();
122 const unsigned int robID = collection.robId();
123 xAODToFHit->setTime(data.time()*s_timeConversionFactor);
124 xAODToFHit->setPulseLength(data.pulseLength()*s_pulseLengthFactor);
125 xAODToFHit->setHptdcChannel(data.channel());
126
127 // set station ID
128 if (robID == AFP_ROBID::sideC) // no AFP_ROBID::sideC_2016 because there was no ToF in 2016
130 else if (robID == AFP_ROBID::sideA)
132 else
133 xAODToFHit->setStationID(-1);
134
135 // set hptdcID
136 if (hitLink == 12)
137 xAODToFHit->setHptdcID(2);
138 else if (hitLink == 13)
139 xAODToFHit->setHptdcID(1);
140 else
141 xAODToFHit->setHptdcID(-1);
142
143 // set barID
144 if (data.header()==0b1010) {
145 // PicoTDC
146 xAODToFHit->setTrainID(data.channel()/4);
147 xAODToFHit->setBarInTrainID(data.channel()%4);
148 } else {
149 // HPTDC
150 setBarAndTrainID(xAODToFHit, ctx);
151 }
152}
153
155{
156 xAOD::AFPSiHit* xAODSiHit = new xAOD::AFPSiHit();
157 siHitContainer->push_back(xAODSiHit);
158
159 const unsigned int hitLink = data.link();
160 const unsigned int robID = collection.robId();
161 // decoding according to Outlink numbers in: https://twiki.cern.ch/twiki/bin/view/Atlas/AFPRunning#Tracker
162 if (hitLink <=3 ) { // not checking if larger or equal 0, because this is uint, which is always positive
163 // set near station ID selecting side based on ROB
164 if (robID == AFP_ROBID::sideA)
166 else if (robID == AFP_ROBID::sideC || robID == AFP_ROBID::sideC_2016)
168 else {
169 ATH_MSG_WARNING("Unrecognised robID: in dec="<<std::dec<<robID<<", in hex=0x"<<std::hex<<robID<<std::dec);
170 xAODSiHit->setStationID(-1);
171 }
172 } else if (hitLink >= 8 && hitLink <= 11) {
173 // set far station ID selecting side based on ROB
174 if (robID == AFP_ROBID::sideA)
176 else if (robID == AFP_ROBID::sideC || robID == AFP_ROBID::sideC_2016)
178 else {
179 ATH_MSG_WARNING("Unrecognised robID: in dec="<<std::dec<<robID<<", in hex=0x"<<std::hex<<robID<<std::dec);
180 xAODSiHit->setStationID(-1);
181 }
182 } else {
183 ATH_MSG_WARNING("Unrecognised value in hitLink = " << hitLink);
184 xAODSiHit->setStationID(-1);
185 } // end of switch
186
187 xAODSiHit->setPixelLayerID( hitLink%4 );
188 xAODSiHit->setPixelColIDChip( data.column() );
189 xAODSiHit->setPixelRowIDChip( data.row() );
190
191 const unsigned int ToT_value = decodeTimeOverThresholdSi( data.timeOverThreshold(), data.hitDiscConfig() );
192 xAODSiHit->setTimeOverThreshold(ToT_value);
193 xAODSiHit->setDepositedCharge( m_totToChargeTransformation(ToT_value) );
194
195 ATH_MSG_DEBUG("have AFPSiHit: pixelLayerID "<<xAODSiHit->pixelLayerID()<<", pixelColIDChip "<<xAODSiHit->pixelColIDChip()<<", pixelRowIDChip "<<xAODSiHit->pixelRowIDChip()<<", timeOverThreshold "<<xAODSiHit->timeOverThreshold()<<", depositedCharge "<<xAODSiHit->depositedCharge());
196}
197
198void AFP_Raw2DigiTool::setBarAndTrainID(xAOD::AFPToFHit* tofHit, const EventContext& ctx) const
199{
200 // mapping is implemented according to https://twiki.cern.ch/twiki/bin/view/Atlas/AFPHPTDC#Channel_Mapping
201
202 const int hptdcChannel = tofHit->hptdcChannel();
203 const int hptdcID = tofHit->hptdcID();
204
205 if((hptdcChannel<0 || hptdcChannel>=12) || (hptdcID<=0 || hptdcID>=3))
206 {
207 ATH_MSG_WARNING("Invalid hptdcID "<<hptdcID<<", or hptdcChannel "<<hptdcChannel);
208 return;
209 }
210
211 int RunID = (ctx.eventID().run_number() > 370000 ? (ctx.eventID().run_number() > 436657 ? 2 : 1) : 0);
212
213 int trainID=m_channel2train[RunID][hptdcID-1][hptdcChannel];
214 int barID=m_channel2bar[RunID][hptdcID-1][hptdcChannel];
215
216 if(trainID>=0 && barID>=0)
217 {
218 tofHit->setTrainID(trainID);
219 tofHit->setBarInTrainID(barID);
220 }
221 else if(trainID==-2 && barID==-2)
222 {
223 // this is known problem for Run2, channels 1 and 4
224 ATH_MSG_DEBUG("Unrecognised hptdcChannel "<<hptdcChannel<<", hptdcID "<<hptdcID);
225 }
226 else if(trainID==-1 && barID==-1)
227 {
228 // this is not known
229 ATH_MSG_WARNING("Unrecognised hptdcChannel "<<hptdcChannel<<", hptdcID "<<hptdcID);
230 }
231 else
232 {
233 // this shouldn't happen
234 ATH_MSG_WARNING("Unrecognised trainID "<<trainID<<" or barID "<<barID<<"; run "<<ctx.eventID().run_number()<<", hptdcChannel "<<hptdcChannel<<", hptdcID "<<hptdcID);
235 }
236}
237
238unsigned int AFP_Raw2DigiTool::decodeTimeOverThresholdSi (const unsigned int input, const unsigned int discConfig) const
239{
240 if (input <= 13)
241 return input + discConfig + 1;
242 else if (input == 14)
243 return discConfig;
244 else
245 return 0;
246}
Definitions of AFP stations identification numbers.
AFP_RawCollection< AFP_SiRawData > AFP_SiRawCollection
Class representing collection of silicon detector data.
AFP_RawCollection< AFP_ToFRawData > AFP_ToFRawCollection
AFP_ToFRawData_v2 AFP_ToFRawData
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static constexpr unsigned int sideC_2016
ROB ID of stations on C side in 2016.
Definition AFP_ROBID.h:17
static constexpr unsigned int sideC
ROB ID of stations on C side.
Definition AFP_ROBID.h:16
static constexpr unsigned int sideA
ROB ID of stations on A side.
Definition AFP_ROBID.h:15
AFP_Raw2DigiTool(const std::string &type, const std::string &name, const IInterface *parent)
SG::WriteHandleKey< xAOD::AFPToFHitContainer > m_AFPHitsContainerNameToF
void newXAODHitSi(xAOD::AFPSiHitContainer *xAODSiHit, const AFP_SiRawCollection &collection, const AFP_SiRawData &data) const
Method that creates a new AFPSiHit and sets it valus according to data.
virtual StatusCode finalize() override
Does nothing.
Gaudi::Property< std::string > m_totToChargeTransfName
unsigned int decodeTimeOverThresholdSi(const unsigned int input, const unsigned int discConfig) const
Method that decodes raw information about time-over-threshold to number of clock ticks.
virtual ~AFP_Raw2DigiTool() override
Does nothing.
void newXAODHitToF(xAOD::AFPToFHitContainer *tofHitContainer, const AFP_ToFRawCollection &collection, const AFP_ToFRawData &data, const EventContext &ctx) const
Method that creates a new AFPToFHit and sets it valus according to data.
static constexpr double s_pulseLengthFactor
Factor converting pulse length to time.
StatusCode recoToFHits(const EventContext &ctx) const override
Creates xAOD for time-of-flight detector.
static constexpr double s_timeConversionFactor
Factor converting signal to time.
Gaudi::Property< std::string > m_totToChargeTransfExpr
Function that transforms time-over-threshold to charge.
SG::ReadHandleKey< AFP_RawContainer > m_rawDataContainerName
SG::WriteHandleKey< xAOD::AFPSiHitContainer > m_AFPSiHitsContainerName
void setBarAndTrainID(xAOD::AFPToFHit *tofHit, const EventContext &ctx) const
Method mapping hptdcID and hptdcChannel to train ID and bar in train ID.
virtual StatusCode initialize() override
Does nothing.
const int m_channel2train[3][2][12]
const int m_channel2bar[3][2][12]
StatusCode recoAll(const EventContext &ctx) const override
StatusCode recoSiHits(const EventContext &ctx) const override
Creates xAOD for silicon detector.
uint32_t robId() const
ROB in from which the collection was read.
Class representing data record for silicon detectors.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
void setPixelLayerID(int layerID)
Method setting index of the pixel layer with hit.
float depositedCharge() const
Charge deposited in the pixel.
int pixelColIDChip() const
Index of the pixel column in chip coordinate system.
int pixelLayerID() const
Index of the layer of pixels, i.e.
void setPixelRowIDChip(int rowID)
Set pixel row index in the chip coordinate system.
float timeOverThreshold() const
Time over threshold of signal for a pixel.
int pixelRowIDChip() const
Index of the pixel row in chip coordinate system.
void setDepositedCharge(float charge)
Method setting value of the charge deposited in the pixel.
void setTimeOverThreshold(float timeOverThreshold)
Method setting value of time over threshold.
void setStationID(int stationID)
Set index of the station with pixel hit.
void setPixelColIDChip(int colID)
Set pixel column index in the chip coordinate system.
static const int nearC
station with at Z = -205 m
static const int farC
station with at Z = -217 m
static const int farA
station with at Z = 217 m
static const int nearA
station with at Z = 205 m
void setBarInTrainID(const int barInTrainID)
void setPulseLength(float pulseLength)
void setHptdcID(int hptdcID)
void setTrainID(const int barInTrainID)
int hptdcChannel() const
HPTDC channel number.
void setStationID(int side)
int hptdcID() const
Identification number of the HPTDC module.
void setHptdcChannel(int hptdcChannel)
void setTime(float time)
AFPSiHit_v2 AFPSiHit
Definition AFPSiHit.h:12
AFPSiHitContainer_v2 AFPSiHitContainer
AFPToFHitContainer_v1 AFPToFHitContainer
AFPToFHit_v1 AFPToFHit
Definition AFPToFHit.h:12