ATLAS Offline Software
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"
7 #include "AFP_RawEv/AFP_ROBID.h"
9 
10 #include "xAODForward/AFPSiHit.h"
13 
14 #include "xAODForward/AFPToFHit.h"
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 
34  ATH_CHECK( m_AFPSiHitsContainerName.initialize() );
35  ATH_CHECK( m_AFPHitsContainerNameToF.initialize() );
36 
37  m_totToChargeTransformation=TF1(m_totToChargeTransfName.toString().c_str(), m_totToChargeTransfExpr.toString().c_str());
38 
39  return StatusCode::SUCCESS;
40 }
41 
42 StatusCode 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 
50 StatusCode 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 
78 StatusCode 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 
116 void 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 
147 void AFP_Raw2DigiTool::newXAODHitSi (xAOD::AFPSiHitContainer* siHitContainer, const AFP_SiRawCollection& collection, const AFP_SiRawData& data) const
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 
191 void 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 
231 unsigned 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 }
AFP_Raw2DigiTool::recoAll
StatusCode recoAll(const EventContext &ctx) const override
Definition: AFP_Raw2DigiTool.cxx:42
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
AFP_Raw2DigiTool::decodeTimeOverThresholdSi
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.
Definition: AFP_Raw2DigiTool.cxx:231
AFP_Raw2DigiTool::finalize
virtual StatusCode finalize() override
Does nothing.
Definition: AFP_Raw2DigiTool.cxx:108
xAOD::AFPStationID::nearC
static const int nearC
station with at Z = -205 m
Definition: AFPStationID.h:51
AFP_Raw2DigiTool::AFP_Raw2DigiTool
AFP_Raw2DigiTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: AFP_Raw2DigiTool.cxx:20
AFP_Raw2DigiTool::~AFP_Raw2DigiTool
virtual ~AFP_Raw2DigiTool() override
Does nothing.
Definition: AFP_Raw2DigiTool.cxx:27
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AFP_ROBID.h
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
AFP_Raw2DigiTool::m_AFPHitsContainerNameToF
SG::WriteHandleKey< xAOD::AFPToFHitContainer > m_AFPHitsContainerNameToF
Definition: AFP_Raw2DigiTool.h:47
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AFP_Raw2DigiTool::newXAODHitToF
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.
Definition: AFP_Raw2DigiTool.cxx:116
xAOD::AFPSiHit
AFPSiHit_v2 AFPSiHit
Definition: AFPSiHit.h:12
xAOD::AFPSiHit_v2::setPixelColIDChip
void setPixelColIDChip(int colID)
Set pixel column index in the chip coordinate system.
AFP_Raw2DigiTool::recoToFHits
StatusCode recoToFHits(const EventContext &ctx) const override
Creates xAOD for time-of-flight detector.
Definition: AFP_Raw2DigiTool.cxx:78
AFPToFHit.h
xAOD::AFPToFHit
AFPToFHit_v1 AFPToFHit
Definition: AFPToFHit.h:12
AFP_Raw2DigiTool.h
xAOD::AFPSiHit_v2::pixelLayerID
int pixelLayerID() const
Index of the layer of pixels, i.e.
xAOD::AFPToFHit_v1::setBarInTrainID
void setBarInTrainID(const int barInTrainID)
xAOD::AFPSiHit_v2::setDepositedCharge
void setDepositedCharge(float charge)
Method setting value of the charge deposited in the pixel.
xAOD::AFPSiHit_v2
Class representing a hit in silicon detector.
Definition: AFPSiHit_v2.h:30
xAOD::AFPToFHit_v1::setTime
void setTime(float time)
AFP_RawContainer.h
AFP_ToFRawData_v2
Class representing data record for time-of-flight detectors.
Definition: AFP_ToFRawData_v2.h:22
AFP_Raw2DigiTool::setBarAndTrainID
void setBarAndTrainID(xAOD::AFPToFHit *tofHit, const EventContext &ctx) const
Method mapping hptdcID and hptdcChannel to train ID and bar in train ID.
Definition: AFP_Raw2DigiTool.cxx:191
AFP_ROBID::sideC
static constexpr unsigned int sideC
ROB ID of stations on C side.
Definition: AFP_ROBID.h:16
xAOD::AFPToFHit_v1::setPulseLength
void setPulseLength(float pulseLength)
AFP_Raw2DigiTool::newXAODHitSi
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.
Definition: AFP_Raw2DigiTool.cxx:147
AFP_Raw2DigiTool::s_timeConversionFactor
static constexpr double s_timeConversionFactor
Factor converting signal to time.
Definition: AFP_Raw2DigiTool.h:52
xAOD::AFPToFHit_v1
Class representing a hit in ToF detector.
Definition: AFPToFHit_v1.h:20
xAOD::AFPSiHit_v2::setPixelLayerID
void setPixelLayerID(int layerID)
Method setting index of the pixel layer with hit.
AFP_Raw2DigiTool::initialize
virtual StatusCode initialize() override
Does nothing.
Definition: AFP_Raw2DigiTool.cxx:29
AFP_Raw2DigiTool::m_totToChargeTransfName
Gaudi::Property< std::string > m_totToChargeTransfName
Definition: AFP_Raw2DigiTool.h:63
AFP_Raw2DigiTool::m_AFPSiHitsContainerName
SG::WriteHandleKey< xAOD::AFPSiHitContainer > m_AFPSiHitsContainerName
Definition: AFP_Raw2DigiTool.h:46
AFPSiHitAuxContainer.h
AFP_RawCollection
Class representing collection of silicon detector data.
Definition: AFP_RawCollection.h:14
xAOD::AFPSiHit_v2::pixelColIDChip
int pixelColIDChip() const
Index of the pixel column in chip coordinate system.
AFPToFHitAuxContainer.h
xAOD::AFPToFHit_v1::setHptdcID
void setHptdcID(int hptdcID)
AFP_Raw2DigiTool::m_rawDataContainerName
SG::ReadHandleKey< AFP_RawContainer > m_rawDataContainerName
Definition: AFP_Raw2DigiTool.h:45
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::AFPSiHit_v2::setTimeOverThreshold
void setTimeOverThreshold(float timeOverThreshold)
Method setting value of time over threshold.
xAOD::AFPSiHit_v2::depositedCharge
float depositedCharge() const
Charge deposited in the pixel.
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
xAOD::AFPToFHit_v1::setStationID
void setStationID(int side)
AFP_Raw2DigiTool::m_totToChargeTransfExpr
Gaudi::Property< std::string > m_totToChargeTransfExpr
Function that transforms time-over-threshold to charge.
Definition: AFP_Raw2DigiTool.h:62
AFPStationID.h
Definitions of AFP stations identification numbers.
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::AFPToFHit_v1::hptdcChannel
int hptdcChannel() const
HPTDC channel number.
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
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AFP_RawCollectionHead::robId
uint32_t robId() const
ROB in from which the collection was read.
Definition: AFP_RawCollectionHead.h:34
xAOD::AFPStationID::farA
static const int farA
station with at Z = 217 m
Definition: AFPStationID.h:49
AFPSiHit.h
xAOD::AFPToFHit_v1::hptdcID
int hptdcID() const
Identification number of the HPTDC module.
xAOD::AFPStationID::nearA
static const int nearA
station with at Z = 205 m
Definition: AFPStationID.h:50
AFP_ROBID::sideA
static constexpr unsigned int sideA
ROB ID of stations on A side.
Definition: AFP_ROBID.h:15
AFP_SiRawData
Class representing data record for silicon detectors.
Definition: AFP_SiRawData.h:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::AFPSiHit_v2::timeOverThreshold
float timeOverThreshold() const
Time over threshold of signal for a pixel.
AFPSiHitContainer.h
xAOD::AFPSiHit_v2::setStationID
void setStationID(int stationID)
Set index of the station with pixel hit.
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
xAOD::AFPSiHit_v2::pixelRowIDChip
int pixelRowIDChip() const
Index of the pixel row in chip coordinate system.
xAOD::AFPToFHit_v1::setTrainID
void setTrainID(const int barInTrainID)
xAOD::AFPSiHit_v2::setPixelRowIDChip
void setPixelRowIDChip(int rowID)
Set pixel row index in the chip coordinate system.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AFP_Raw2DigiTool::m_channel2train
const int m_channel2train[3][2][12]
Definition: AFP_Raw2DigiTool.h:86
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
xAOD::AFPStationID::farC
static const int farC
station with at Z = -217 m
Definition: AFPStationID.h:52
AFP_ROBID::sideC_2016
static constexpr unsigned int sideC_2016
ROB ID of stations on C side in 2016.
Definition: AFP_ROBID.h:17
AFP_Raw2DigiTool::recoSiHits
StatusCode recoSiHits(const EventContext &ctx) const override
Creates xAOD for silicon detector.
Definition: AFP_Raw2DigiTool.cxx:50
AFP_Raw2DigiTool::m_totToChargeTransformation
TF1 m_totToChargeTransformation
Definition: AFP_Raw2DigiTool.h:64
AFP_Raw2DigiTool::m_channel2bar
const int m_channel2bar[3][2][12]
Definition: AFP_Raw2DigiTool.h:89
AFPToFHitContainer.h
AFP_Raw2DigiTool::s_pulseLengthFactor
static constexpr double s_pulseLengthFactor
Factor converting pulse length to time.
Definition: AFP_Raw2DigiTool.h:57
xAOD::AFPToFHit_v1::setHptdcChannel
void setHptdcChannel(int hptdcChannel)