ATLAS Offline Software
Loading...
Searching...
No Matches
PixelToTPIDTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7// StoreGate, Athena, and Database stuff:
8#include "Identifier/Identifier.h"
10
11// Tracking:
12#include "TrkTrack/Track.h"
17#include "TrkSurfaces/Surface.h"
18#include "TrkTrack/TrackInfo.h"
19
20// Pixels:
24
25// CLHEP:
26#include "CLHEP/Matrix/Vector.h"
27
28// Particle masses
29
30// Math functions:
31#include <cmath>
32
34
35InDet::PixelToTPIDTool::PixelToTPIDTool(const std::string& t, const std::string& n, const IInterface* p )
36 :AthAlgTool(t,n,p),
37 m_IBLParameterSvc("IBLParameterSvc",n),
38 m_pixelid(nullptr)
39{
40 declareInterface<IPixelToTPIDTool>(this);
41
42 float energyPair = 3.68e-6; // Energy in MeV to create an electron-hole pair in silicon
43 float sidensity = 2.329; // silicon density in g cm^-3
44
45 //conversion Factor
46 //{.025,.023,.020}; //{Old Planars,IBL_3Ds,IBL_Planars} the sensors thickness will be take into account in dEdx calculation
47
48 m_conversionfactor=energyPair/sidensity;
49
50}
51
53
55
56 ATH_CHECK(AthAlgTool::initialize());
57
58 ATH_CHECK(detStore()->retrieve(m_pixelid,"PixelID"));
59
60 if (m_IBLParameterSvc.retrieve().isFailure()) {
61 ATH_MSG_FATAL("Could not retrieve IBLParameterSvc");
62 return StatusCode::FAILURE;
63 }
64
65 ATH_CHECK(m_moduleDataKey.initialize());
66
67 ATH_CHECK(m_dedxKey.initialize());
68
69 return StatusCode::SUCCESS;
70}
71
72//================ Finalisation =================================================
73
75{
76 StatusCode sc = AthAlgTool::finalize();
77 return sc;
78}
79
80
81//============================================================================================
82
83float
84InDet::PixelToTPIDTool::dEdx(const EventContext& ctx,
85 const Trk::Track& track,
86 int& nUsedHits,
87 int& nUsedIBLOverflowHits) const
88{
89
90 unsigned int pixelhits = 0;
91 nUsedHits=0;
92 nUsedIBLOverflowHits=0;
93 float Pixel_sensorthickness=.025; //250 microns Pixel Planars
94 float IBL_3D_sensorthickness=.023; //230 microns IBL 3D
95 float IBL_PLANAR_sensorthickness=.020;// 200 microns IBL Planars
96 float dEdxValue=0;
97
98 //std::multimap<float,int> chargesMap;
100 std::multimap<float,int> dEdxMap;
101
102 // Check for track states:
103 const Trk::TrackStates* recoTrackStates = track.trackStateOnSurfaces();
104 if (recoTrackStates) {
105 Trk::TrackStates::const_iterator tsosIter = recoTrackStates->begin();
106 Trk::TrackStates::const_iterator tsosIterEnd = recoTrackStates->end();
107
108 // Loop over track states on surfaces (i.e. generalized hits):
109 for (; tsosIter != tsosIterEnd; ++tsosIter) {
110 const Trk::MeasurementBase *measurement = (*tsosIter)->measurementOnTrack();
111 if (measurement && !(*tsosIter)->type(Trk::TrackStateOnSurface::Outlier)) {
112 if (!(*tsosIter)->trackParameters()) {
113 msg(MSG::WARNING) << "No track parameters available for a state of type measurement, returning -1" << endmsg;
114 msg(MSG::WARNING) << "Don't run this tool on slimmed tracks!" << endmsg;
115 return -1;
116 }
117
118 const InDet::PixelClusterOnTrack* pixclus = nullptr;
120 const Trk::RIO_OnTrack* tmpRio = static_cast<const Trk::RIO_OnTrack*>(measurement);
122 pixclus = static_cast<const InDet::PixelClusterOnTrack*>(tmpRio);
123 }
124 }
125 if (pixclus) {
126 //bool isok=false;
127 double locx=pixclus->localParameters()[Trk::locX];
128 double locy=pixclus->localParameters()[Trk::locY];
129 int bec=m_pixelid->barrel_ec(pixclus->identify());
130 int layer=m_pixelid->layer_disk(pixclus->identify());
131 int eta_module=m_pixelid->eta_module(pixclus->identify());//check eta module to select thickness
132
133 float dotProd = (*tsosIter)->trackParameters()->momentum().dot(
134 (*tsosIter)->trackParameters()->associatedSurface().normal());
135 float cosalpha =
136 fabs(dotProd / (*tsosIter)->trackParameters()->momentum().mag());
137
138 if (std::abs(cosalpha)<0.16) { continue; }
139
140 float charge=pixclus->prepRawData()->totalCharge()*cosalpha;
141
142 //keep track if this is an ibl cluster with overflow
143 int iblOverflow=0;
144 if ((m_IBLParameterSvc->containsIBL()) and (bec==0) and (layer==0)) { // check if IBL
145
146 //loop over ToT and check if anyone is overflow (ToT==14) check for IBL cluster overflow
147 int overflowIBLToT =
149 ->getFEI4OverflowToT();
150 const std::vector<int>& ToTs = pixclus->prepRawData()->totList();
151
152 for (int pixToT : ToTs) {
153 if (pixToT >= overflowIBLToT) {
154 //overflow pixel hit -- flag cluster
155 iblOverflow = 1;
156 break; //no need to check other hits of this cluster
157 }
158 }// end
159
160 // this is IBL layer -- @todo: check using proper service (safe
161 // against geometries)
162 if (((eta_module >= -10 && eta_module <= -7) ||
163 (eta_module >= 6 && eta_module <= 9)) &&
164 (fabs(locy) < 10. &&
165 (locx > -8.33 &&
166 locx < 8.3))) { // check if IBL 3D and good cluster selection
167 dEdxValue = charge * m_conversionfactor / IBL_3D_sensorthickness;
168 dEdxMap.insert(std::pair<float, int>(dEdxValue, iblOverflow));
169 pixelhits++;
170 if (iblOverflow == 1) {
171 nUsedIBLOverflowHits++;
172 }
173 } else if ((eta_module >= -6 && eta_module <= 5) &&
174 (fabs(locy) < 20. &&
175 (locx > -8.33 &&
176 locx < 8.3))) { // check if IBL planar and good cluster
177 // selection
178 dEdxValue =
179 charge * m_conversionfactor / IBL_PLANAR_sensorthickness;
180 dEdxMap.insert(std::pair<float, int>(dEdxValue, iblOverflow));
181 pixelhits++;
182 if (iblOverflow == 1) {
183 nUsedIBLOverflowHits++;
184 }
185 } else {
186 dEdxValue=-1;
187 } // end check which IBL Module
188
189 }
190 //PIXEL layer and ENDCAP
191 else if(bec==0 && fabs(locy)<30. && ((locx>-8.20 && locx<-0.60) || (locx>0.50 && locx<8.10))) {
192 dEdxValue=charge*m_conversionfactor/Pixel_sensorthickness;
193 dEdxMap.insert(std::pair<float,int>(dEdxValue, iblOverflow));
194 pixelhits++;
195 }
196 else if (std::abs(bec)==2 && fabs(locy)<30. && ((locx>-8.15 && locx<-0.55) || (locx>0.55 && locx<8.15))) {
197 dEdxValue=charge*m_conversionfactor/Pixel_sensorthickness;
198 dEdxMap.insert(std::pair<float,int>(dEdxValue, iblOverflow));
199 pixelhits++;
200 }
201 } //pixclus iterator
202 }
203 }
204 }
205
206 //Now calculate dEdx, multimap is already sorted in ascending order
207 float averagedEdx=0.;
208 nUsedHits=0;
209 int IBLOverflow=0;
210
211 for (std::pair<float,int> itdEdx : dEdxMap) {
212 if (itdEdx.second==0) {
213 averagedEdx += itdEdx.first;
214 nUsedHits++;
215 }
216 if (itdEdx.second>0) { IBLOverflow++; }
217
218 //break, skipping last or the two last elements depending on total measurements
219 if (((int)pixelhits>=5) and ((int)nUsedHits>=(int)pixelhits-2)) { break; }
220
221 //break, IBL Overflow case pixelhits==3 and 4
222 if ((int)IBLOverflow>0 and ((int)pixelhits==3) and (int)nUsedHits==1) { break; }
223 if ((int)IBLOverflow>0 and ((int)pixelhits==4) and (int)nUsedHits==2) { break; }
224
225 if (((int)pixelhits > 1) and ((int)nUsedHits >=(int)pixelhits-1)) { break; }
226
227 if ((int)IBLOverflow>0 and (int)pixelhits==1) { //only IBL in overflow
228 averagedEdx=itdEdx.first;
229 break;
230 }
231 }
232
233 if (nUsedHits>0 or (nUsedHits==0 and(int)IBLOverflow>0 and (int)pixelhits==1)) {
234 if (nUsedHits>0) { averagedEdx=averagedEdx/nUsedHits; }
235
236 ATH_MSG_DEBUG("NEW dEdx = " << averagedEdx);
237 ATH_MSG_DEBUG("Used hits: " << nUsedHits << ", IBL overflows: " << IBLOverflow );
238 ATH_MSG_DEBUG("Original number of measurements = " << pixelhits << "( map size = " << dEdxMap.size() << ")");
239 return averagedEdx;
240 }
241 return -1;
242}
243
244std::vector<float>
246 double dedx2,
247 double p2,
248 int nGoodPixels) const
249{
251 ->getLikelihoods(dedx2, p2, nGoodPixels);
252}
253
254float
255InDet::PixelToTPIDTool::getMass(const EventContext& ctx,
256 double dedx,
257 double p,
258 int nGoodPixels) const
259{
261 ->getMass(dedx, p / 1000, nGoodPixels);
262}
263
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_DEBUG(x)
double charge(const T &p)
Definition AtlasPID.h:997
static Double_t sc
This is an Identifier helper class for the Pixel subdetector.
Return pixel dEdx.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
MsgStream & msg() const
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
Specific class to represent the pixel measurements.
virtual const PixelCluster * prepRawData() const override final
returns the PrepRawData - is a SiCluster in this scope
virtual float dEdx(const EventContext &ctx, const Trk::Track &track, int &nUsedHits, int &nUsedIBLOverflowHits) const override final
particle identification function returning a probability.
virtual StatusCode finalize() override
virtual float getMass(const EventContext &ctx, double dedx, double p, int nGoodPixels) const override final
virtual StatusCode initialize() override
const PixelID * m_pixelid
PixelToTPIDTool(const std::string &, const std::string &, const IInterface *)
ServiceHandle< IIBLParameterSvc > m_IBLParameterSvc
SG::ReadCondHandleKey< PixeldEdxData > m_dedxKey
SG::ReadCondHandleKey< PixelChargeCalibCondData > m_moduleDataKey
virtual std::vector< float > getLikelihoods(const EventContext &ctx, double dedx, double p, int nGoodPixels) const override final
This class is the pure abstract base class for all fittable tracking measurements.
const LocalParameters & localParameters() const
Interface method to get the LocalParameters.
virtual bool type(MeasurementBaseType::Type type) const =0
Interface method checking the type.
Class to handle RIO On Tracks ROT) for InDet and Muons, it inherits from the common MeasurementBase.
Definition RIO_OnTrack.h:70
Identifier identify() const
return the identifier -extends MeasurementBase
virtual bool rioType(RIO_OnTrackType::Type type) const =0
Method checking the Rio On Track type.
@ Outlier
This TSoS contains an outlier, that is, it contains a MeasurementBase/RIO_OnTrack which was not used ...
DataVector< const Trk::TrackStateOnSurface > TrackStates
@ locY
local cartesian
Definition ParamDefs.h:38
@ locX
Definition ParamDefs.h:37