ATLAS Offline Software
Loading...
Searching...
No Matches
AFP_Raw2DigiTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 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() == 1 && !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 setBarAndTrainID(xAODToFHit, ctx);
145}
146
148{
149 xAOD::AFPSiHit* xAODSiHit = new xAOD::AFPSiHit();
150 siHitContainer->push_back(xAODSiHit);
151
152 const unsigned int hitLink = data.link();
153 const unsigned int robID = collection.robId();
154 // decoding according to Outlink numbers in: https://twiki.cern.ch/twiki/bin/view/Atlas/AFPRunning#Tracker
155 if (hitLink <=3 ) { // not checking if larger or equal 0, because this is uint, which is always positive
156 // set near station ID selecting side based on ROB
157 if (robID == AFP_ROBID::sideA)
159 else if (robID == AFP_ROBID::sideC || robID == AFP_ROBID::sideC_2016)
161 else {
162 ATH_MSG_WARNING("Unrecognised robID: in dec="<<std::dec<<robID<<", in hex=0x"<<std::hex<<robID<<std::dec);
163 xAODSiHit->setStationID(-1);
164 }
165 } else if (hitLink >= 8 && hitLink <= 11) {
166 // set far station ID selecting side based on ROB
167 if (robID == AFP_ROBID::sideA)
169 else if (robID == AFP_ROBID::sideC || robID == AFP_ROBID::sideC_2016)
171 else {
172 ATH_MSG_WARNING("Unrecognised robID: in dec="<<std::dec<<robID<<", in hex=0x"<<std::hex<<robID<<std::dec);
173 xAODSiHit->setStationID(-1);
174 }
175 } else {
176 ATH_MSG_WARNING("Unrecognised value in hitLink = " << hitLink);
177 xAODSiHit->setStationID(-1);
178 } // end of switch
179
180 xAODSiHit->setPixelLayerID( hitLink%4 );
181 xAODSiHit->setPixelColIDChip( data.column() );
182 xAODSiHit->setPixelRowIDChip( data.row() );
183
184 const unsigned int ToT_value = decodeTimeOverThresholdSi( data.timeOverThreshold(), data.hitDiscConfig() );
185 xAODSiHit->setTimeOverThreshold(ToT_value);
186 xAODSiHit->setDepositedCharge( m_totToChargeTransformation(ToT_value) );
187
188 ATH_MSG_DEBUG("have AFPSiHit: pixelLayerID "<<xAODSiHit->pixelLayerID()<<", pixelColIDChip "<<xAODSiHit->pixelColIDChip()<<", pixelRowIDChip "<<xAODSiHit->pixelRowIDChip()<<", timeOverThreshold "<<xAODSiHit->timeOverThreshold()<<", depositedCharge "<<xAODSiHit->depositedCharge());
189}
190
191void AFP_Raw2DigiTool::setBarAndTrainID(xAOD::AFPToFHit* tofHit, const EventContext& ctx) const
192{
193 // mapping is implemented according to https://twiki.cern.ch/twiki/bin/view/Atlas/AFPHPTDC#Channel_Mapping
194
195 const int hptdcChannel = tofHit->hptdcChannel();
196 const int hptdcID = tofHit->hptdcID();
197
198 if((hptdcChannel<0 || hptdcChannel>=12) || (hptdcID<=0 || hptdcID>=3))
199 {
200 ATH_MSG_WARNING("Invalid hptdcID "<<hptdcID<<", or hptdcChannel "<<hptdcChannel);
201 return;
202 }
203
204 int RunID = (ctx.eventID().run_number() > 370000 ? (ctx.eventID().run_number() > 436657 ? 2 : 1) : 0);
205
206 int trainID=m_channel2train[RunID][hptdcID-1][hptdcChannel];
207 int barID=m_channel2bar[RunID][hptdcID-1][hptdcChannel];
208
209 if(trainID>=0 && barID>=0)
210 {
211 tofHit->setTrainID(trainID);
212 tofHit->setBarInTrainID(barID);
213 }
214 else if(trainID==-2 && barID==-2)
215 {
216 // this is known problem for Run2, channels 1 and 4
217 ATH_MSG_DEBUG("Unrecognised hptdcChannel "<<hptdcChannel<<", hptdcID "<<hptdcID);
218 }
219 else if(trainID==-1 && barID==-1)
220 {
221 // this is not known
222 ATH_MSG_WARNING("Unrecognised hptdcChannel "<<hptdcChannel<<", hptdcID "<<hptdcID);
223 }
224 else
225 {
226 // this shouldn't happen
227 ATH_MSG_WARNING("Unrecognised trainID "<<trainID<<" or barID "<<barID<<"; run "<<ctx.eventID().run_number()<<", hptdcChannel "<<hptdcChannel<<", hptdcID "<<hptdcID);
228 }
229}
230
231unsigned int AFP_Raw2DigiTool::decodeTimeOverThresholdSi (const unsigned int input, const unsigned int discConfig) const
232{
233 if (input <= 13)
234 return input + discConfig + 1;
235 else if (input == 14)
236 return discConfig;
237 else
238 return 0;
239}
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