38 std::unique_ptr<o2::gpu::GPUO2InterfaceRefit> refit;
39 if (!mPropagateTrack) {
40 refit = std::make_unique<o2::gpu::GPUO2InterfaceRefit>(mClusterIndex, mTPCCorrMapsHelper, mFieldNominalGPUBz, mTPCTrackClIdxVecInput->data(), 0, mTPCRefitterShMap.data(), mTPCRefitterOccMap.data(), mTPCRefitterOccMap.size());
43 const size_t loopEnd = (nMaxTracks < 0) ? mTracks->size() : ((nMaxTracks > mTracks->size()) ? mTracks->size() : size_t(nMaxTracks));
45 if (loopEnd < mTracks->
size()) {
47 std::vector<size_t> ind(mTracks->size());
48 std::iota(ind.begin(), ind.end(), 0);
49 std::minstd_rand rng(std::time(
nullptr));
50 std::shuffle(ind.begin(), ind.end(), rng);
51 for (
size_t i = 0;
i < loopEnd; ++
i) {
52 processTrack((*mTracks)[ind[
i]], refit.get());
55 for (
const auto& trk : *mTracks) {
56 processTrack(trk, refit.get());
64 const float mom = track.getP();
65 const int nClusters = track.getNClusterReferences();
66 if (mom < mMomMin || mom > mMomMax || std::abs(track.getEta()) > mEtaMax ||
nClusters < mMinClusters) {
71 for (
auto&
buffer : mDEdxBuffer) {
76 for (
int iCl = 0; iCl <
nClusters; iCl++) {
79 const auto flagsCl = cl.getFlags();
84 unsigned char sectorIndex = 0;
85 unsigned char rowIndex = 0;
86 unsigned int clusterIndexNumb = 0;
89 track.getClusterReference(*mTPCTrackClIdxVecInput, iCl, sectorIndex, rowIndex, clusterIndexNumb);
91 if (!mPropagateTrack) {
94 track.rotate(o2::math_utils::detail::sector2Angle<float>(sectorIndex));
98 if (!
check || std::isnan(track.getParam(1))) {
104 const float effectiveLength = mCalibTrackTopologyPol ? getTrackTopologyCorrectionPol(track, cl,
region,
charge) : getTrackTopologyCorrection(track,
region);
107 const float gain = mGainMapRef ? mGainMapRef->getValue(sectorIndex, rowIndex, pad) : 1;
108 const float chargeNorm =
charge / (effectiveLength * gain);
111 const auto& dEdx = track.getdEdx();
115 if (mDedxRegion ==
stack) {
116 const auto stack = cru.gemStack();
118 dedx = getdEdxIROC(dEdx);
120 dedx = getdEdxOROC1(dEdx);
122 dedx = getdEdxOROC2(dEdx);
124 dedx = getdEdxOROC3(dEdx);
126 }
else if (mDedxRegion ==
chamber) {
127 if (cru.isIROC() && dEdx.NHitsIROC > mMinClusters) {
128 dedx = getdEdxIROC(dEdx);
131 if (dEdx.NHitsOROC1 > mMinClusters) {
132 dedx += getdEdxOROC1(dEdx);
135 if (dEdx.NHitsOROC2 > mMinClusters) {
136 dedx += getdEdxOROC2(dEdx);
139 if (dEdx.NHitsOROC3 > mMinClusters) {
140 dedx += getdEdxOROC3(dEdx);
147 }
else if (mDedxRegion ==
sector) {
148 dedx = getdEdxTPC(dEdx);
155 if (dedx < mDedxMin || (mDedxMax > 0 && dedx > mDedxMax)) {
159 const float fillVal = mDoNotNormCharge ? chargeNorm : chargeNorm /
dedx;
169 const int indexBuffer = getdEdxBufferIndex(
region);
172 const int isSectorCentre = std::abs(
static_cast<int>(pad) -
static_cast<int>(
Mapper::PADSPERROW[
region][rowIndex] / 2));
173 const int nPadsSector = 1;
175 if (!isEdge && (isSectorCentre > nPadsSector)) {
176 mDEdxBuffer[indexBuffer].emplace_back(chargeNorm);
179 mClTrk.emplace_back(std::make_tuple(sectorIndex, rowIndex, pad, chargeNorm));
187 for (
auto&
x : mClTrk) {
188 const unsigned char globRow = std::get<1>(
x);
190 const int indexBuffer = getdEdxBufferIndex(
region);
192 const float dedxTmp = mDedxTmp[indexBuffer];
193 if (dedxTmp <= 0 || dedxTmp < mDedxMin || (mDedxMax > 0 && dedxTmp > mDedxMax)) {
197 const unsigned char pad = std::get<2>(
x);
205 float fillVal = mDoNotNormCharge ? std::get<3>(
x) :
std::
get<3>(
x) / dedxTmp;
207 fillVal = std::log(1 + fillVal);
215void CalibPadGainTracks::getTruncMean(
float low,
float high)
218 mDedxTmp.reserve(mDEdxBuffer.size());
220 for (
auto&
charge : mDEdxBuffer) {
221 const int nClustersUsed =
static_cast<int>(
charge.size());
222 if (nClustersUsed < mMinClusters) {
223 mDedxTmp.emplace_back(-1);
229 const int startInd =
static_cast<int>(low * nClustersUsed);
230 const int endInd =
static_cast<int>(high * nClustersUsed);
232 if (endInd <= startInd) {
233 mDedxTmp.emplace_back(-1);
237 const float dEdx = std::accumulate(
charge.begin() + startInd,
charge.begin() + endInd, 0.f);
238 const int nClustersTrunc = endInd - startInd;
239 mDedxTmp.emplace_back(dEdx / nClustersTrunc);
243float CalibPadGainTracks::getTrackTopologyCorrection(
const o2::tpc::TrackTPC& track,
const unsigned int region)
const
246 const float sinPhi = track.getSnp();
247 const float tgl = track.getTgl();
248 const float snp2 = sinPhi * sinPhi;
249 const float effectiveLength = padLength * std::sqrt((1 + tgl * tgl) / (1 - snp2));
250 return effectiveLength;
255 const float trackSnp = std::abs(track.getSnp());
256 float snp2 = trackSnp * trackSnp;
257 const float sec2 = 1.f / (1.f - snp2);
258 const float trackTgl = track.getTgl();
259 const float tgl2 = trackTgl * trackTgl;
260 const float tanTheta = std::sqrt(tgl2 * sec2);
262 const float z = std::abs(track.getParam(1));
263 const float padTmp = cl.getPad();
264 const float absRelPad = std::abs(padTmp -
int(padTmp + 0.5f));
265 const float relTime = cl.getTime() -
int(cl.getTime() + 0.5f);
267 const float effectiveLength = (mChargeType ==
ChargeType::Max) ? mCalibTrackTopologyPol->getCorrectionqMax(
region, tanTheta, trackSnp,
z, absRelPad, relTime) : mCalibTrackTopologyPol->getCorrectionqTot(
region, tanTheta, trackSnp,
z, 3.5f ,
charge);
268 return effectiveLength;
271void CalibPadGainTracks::reserveMemory()
277void CalibPadGainTracks::resizedEdxBuffer()
279 if (mDedxRegion ==
stack) {
280 mDEdxBuffer.resize(4);
285 }
else if (mDedxRegion ==
chamber) {
286 mDEdxBuffer.resize(2);
289 }
else if (mDedxRegion ==
sector) {
290 mDEdxBuffer.resize(1);
293 LOGP(warning,
"wrong dE/dx type");
305 TFile fOut(outFileName,
"RECREATE");
306 fOut.WriteObject(
this, outName);
312 mTracks = vTPCTracksArrayInp;
313 mTPCTrackClIdxVecInput = tpcTrackClIdxVecInput;
314 mClusterIndex = &clIndex;
315 mTPCRefitterShMap = TPCRefitterShMap;
316 mTPCRefitterOccMap = TPCRefitterOccMap;
327 TFile
f(inpFile,
"READ");
329 f.GetObject(mapName, gainMap);
332 LOGP(info,
"GainMap {} not found returning", mapName);
339int CalibPadGainTracks::getdEdxBufferIndex(
const int region)
const
341 if (mDedxRegion ==
stack) {
343 }
else if (mDedxRegion ==
chamber) {
345 }
else if (mDedxRegion ==
sector) {
348 LOGP(warning,
"wrong dE/dx type");
355 mCalibTrackTopologyPol = std::make_unique<CalibdEdxTrackTopologyPol>();
356 mCalibTrackTopologyPol->loadFromFile(fileName.data(),
"CalibdEdxTrackTopologyPol");
361 mCalibTrackTopologyPol = std::make_unique<CalibdEdxTrackTopologyPol>();
362 mCalibTrackTopologyPol->setFromContainer(polynomials);
365void CalibPadGainTracks::drawRefGainMapHelper(
const bool type,
const Sector sector,
const std::string
filename,
const float minZ,
const float maxZ)
const
368 LOGP(error,
"Map not set");
372 std::function<float(
const unsigned int,
const unsigned int,
const unsigned int,
const unsigned int)> idcFunc = [mapTmp = mGainMapRef.get()](
const unsigned int sector,
const unsigned int region,
const unsigned int lrow,
const unsigned int pad) {
378 const std::string zAxisTitle =
"rel. gain";
379 type ?
IDCDrawHelper::drawSide(drawFun,
sector.side(), zAxisTitle,
filename,
minZ,
maxZ) :
IDCDrawHelper::drawSector(drawFun, 0,
Mapper::NREGIONS,
sector, zAxisTitle,
filename,
minZ,
maxZ);
385 LOGP(error,
"Map not set");
388 CalDet gainMapRef(*mGainMapRef.get());
391 TFile
f(outFileName,
"RECREATE");
392 f.WriteObject(&gainMapRef, outName);
395int CalibPadGainTracks::getIndex(
o2::tpc::PadSubset padSub,
int padSubsetNumber,
const int row,
const int pad)
403 mTPCVDrift =
v.getVDrift();
404 mTPCVDriftCorrFact =
v.corrFact;
405 mTPCVDriftRef =
v.refVDrift;
406 mTPCDriftTimeOffset =
v.getTimeOffset();
412 mTPCCorrMapsHelper = maph;
Class of a TPC cluster in TPC-native coordinates (row, time)
Helper class to access correction maps.
helper class for drawing IDCs per region/side
calibration data from laser track calibration
GPUd() value_type estimateLTFast(o2 static GPUd() float estimateLTIncrement(const o2 PropagatorImpl * Instance(bool uninitialized=false)
void setTrackReferenceX(float v)
int32_t RefitTrackAsGPU(o2::tpc::TrackTPC &trk, bool outward=false, bool resetCov=false)
GEMstack gemStack() const
const CalPad & getPadGainMap() const
@ region
normalization per region
void fillPadByPadHistogram(const size_t roc, const size_t padInROC, const float val)
bool getLogTransformQ() const
void setTPCCorrMaps(o2::gpu::CorrectionMapsHelper *maph)
set cluster correction maps helper
void setTPCVDrift(const o2::tpc::VDriftCorrFact &v)
set VDrift correction
void setPolTopologyCorrectionFromContainer(const CalibdEdxTrackTopologyPolContainer &polynomials)
void setMomentumRange(const float momMin, const float momMax)
void setRefGainMap(const char *inpFile, const char *mapName)
void loadPolTopologyCorrectionFromFile(std::string_view fileName)
void processTracks(const int nMaxTracks=-1)
void setdEdxRegion(const DEdxRegion dedx)
set how the dedx is calculated which is used for normalizing the cluster charge
@ sector
use the dE/dx from the whole sector
@ chamber
use the dE/dx from IROC and OROC
@ stack
use the dE/dx from IROC, OROC1, OROC2, OROC3
@ dedxTrack
normalize qMax using the truncated mean from the track
@ dedxTracking
normalize qMax using the dEdx which was calculated during the tracking
void dumpToFile(const char *outFileName="calPadGainTracks.root", const char *outName="calPadGain") const
void setMembers(gsl::span< const o2::tpc::TrackTPC > *vTPCTracksArrayInp, gsl::span< const o2::tpc::TPCClRefElem > *tpcTrackClIdxVecInput, const o2::tpc::ClusterNativeAccess &clIndex, gsl::span< const unsigned char > TPCRefitterShMap, gsl::span< const unsigned int > TPCRefitterOccMap)
void dumpReferenceExtractedGainMap(const char *outFileName="GainMapRefExtracted.root", const char *outName="GainMap") const
static void drawSide(const IDCDraw &idc, const o2::tpc::Side side, const std::string zAxisTitle, const std::string filename, const float minZ=0, const float maxZ=-1)
static GlobalPadNumber getGlobalPadNumber(const unsigned int lrow, const unsigned int pad, const unsigned int region)
static constexpr auto getNumberOfRowsInIROC()
static const std::vector< unsigned int > PADSPERROW[NREGIONS]
number of pads per row in region
static constexpr unsigned int GLOBALPADOFFSET[NREGIONS]
offset of number of pads for region
static unsigned int getLocalRowFromGlobalRow(const unsigned int row)
static Mapper & instance(const std::string mappingDir="")
GlobalPadNumber getPadNumber(const PadSubset padSubset, const size_t padSubsetNumber, const int row, const int pad) const
static constexpr unsigned short getPadsInIROC()
const PadRegionInfo & getPadRegionInfo(const unsigned char region) const
static constexpr auto getNumberOfRowsInOROC()
static constexpr unsigned int PADROWS
total number of pad rows
static constexpr unsigned int OFFSETCRUGLOBAL[PADROWS]
row offset in cru for given global pad row
GlobalPosition2D getPadCentre(const PadSecPos &padSec) const
static constexpr unsigned REGION[PADROWS]
region for global pad row
float getPadHeight() const
GLint GLint GLsizei GLint GLenum GLenum type
GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat maxZ
GLdouble GLdouble GLdouble z
void check(const std::vector< std::string > &arguments, const std::vector< ConfigParamSpec > &workflowOptions, const std::vector< DeviceSpec > &deviceSpecs, CheckMatrix &matrix)
Global TPC definitions and constants.
PadSubset
Definition of the different pad subsets.
Defining DataPointCompositeObject explicitly as copiable.
simple struct to enable writing the MultivariatePolynomialCT to file
std::function< float(const unsigned int, const unsigned int, const unsigned int, const unsigned int)> mIDCFunc
function returning the value which will be drawn for sector, region, row, pad