Skip to content

Commit

Permalink
Avoid InputRecord include in TRD data formats lib
Browse files Browse the repository at this point in the history
  • Loading branch information
martenole committed Aug 8, 2023
1 parent c3d759a commit f4bea48
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
#define ALICEO2_GAINCALIBHISTOS_H

#include "DataFormatsTRD/Constants.h"
#include "Framework/InputRecord.h"
#include "Rtypes.h"
#include <vector>
#include <memory>
#include <gsl/span>

namespace o2
{
Expand All @@ -35,11 +32,10 @@ class GainCalibHistos
~GainCalibHistos() = default;
void reset();
void init();
void addEntry(float dEdx, int chamberId);
auto getHistogramEntry(int index) const { return mdEdxEntries[index]; }
auto getNEntries() const { return mNEntriesTot; }

void fill(const std::unique_ptr<const GainCalibHistos, o2::framework::InputRecord::Deleter<const o2::trd::GainCalibHistos>>& input);
void fill(const std::vector<int>& input);
void merge(const GainCalibHistos* prev);
void print();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

#include "DataFormatsTRD/Constants.h"
#include "DataFormatsTRD/PHData.h"
#include "Framework/InputRecord.h"
#include "Rtypes.h"
#include <vector>
#include <memory>
#include <gsl/span>

namespace o2
{
Expand Down
21 changes: 4 additions & 17 deletions DataFormats/Detectors/TRD/src/GainCalibHistos.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,15 @@ void GainCalibHistos::reset()
mNEntriesTot = 0;
}

void GainCalibHistos::addEntry(float dEdx, int chamberId)
{
// add entry for given dEdx
int chamberOffset = chamberId * NBINSGAINCALIB;
int iBin = (int)dEdx;
if (iBin < 0 || iBin >= NBINSGAINCALIB) {
// This could happen because of local gain correction but should be very rare, so we can just skip it
return;
}
++mdEdxEntries[chamberOffset + iBin];
++mNEntriesTot;
}

void GainCalibHistos::fill(const std::unique_ptr<const GainCalibHistos, o2::framework::InputRecord::Deleter<const o2::trd::GainCalibHistos>>& input)
void GainCalibHistos::fill(const std::vector<int>& input)
{
if (!mInitialized) {
init();
}
for (int i = 0; i < MAXCHAMBER * NBINSGAINCALIB; ++i) {
mdEdxEntries[i] += input->getHistogramEntry(i);
mNEntriesTot += input->getHistogramEntry(i);
for (auto elem : input) {
++mdEdxEntries[elem];
}
mNEntriesTot += input.size();
}

void GainCalibHistos::merge(const GainCalibHistos* prev)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ class TrackBasedCalib
bool propagateAndUpdate(TrackTRD& trk, int iLayer, bool doUpdate) const;

const AngularResidHistos& getAngResHistos() const { return mAngResHistos; }
const GainCalibHistos& getGainCalibHistos() const { return mGainCalibHistos; }
const auto& getGainCalibHistos() const { return mGainCalibHistos; }

private:
float mMaxSnp{o2::base::Propagator::MAX_SIN_PHI}; ///< max snp when propagating tracks
float mMaxStep{o2::base::Propagator::MAX_STEP}; ///< maximum step for propagation
MatCorrType mMatCorr{MatCorrType::USEMatCorrNONE}; ///< if material correction should be done
RecoParam mRecoParam; ///< parameters required for TRD reconstruction
AngularResidHistos mAngResHistos; ///< aggregated data for the track based calibration
GainCalibHistos mGainCalibHistos; ///< aggregated data for the track based calibration
std::vector<int> mGainCalibHistos; ///< aggregated input data for gain calibration
float bz; ///< magnetic field

// input arrays which should not be modified since they are provided externally
Expand Down
33 changes: 22 additions & 11 deletions Detectors/TRD/calibration/src/TrackBasedCalib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ using namespace o2::trd::constants;
void TrackBasedCalib::reset()
{
mAngResHistos.reset();
mGainCalibHistos.reset();
mGainCalibHistos.clear();
}

void TrackBasedCalib::init()
{
bz = o2::base::Propagator::Instance()->getNominalBz();
mRecoParam.setBfield(bz);
mGainCalibHistos.init();
}

void TrackBasedCalib::setInput(const o2::globaltracking::RecoContainer& input)
Expand All @@ -58,8 +57,8 @@ void TrackBasedCalib::calculateGainCalibObjs()
int nTracksSuccessTPCTRD = filldEdx(mTracksInTPCTRD, true);
int nTracksSuccessITSTPCTRD = filldEdx(mTracksInITSTPCTRD, false);

LOGF(info, "Gain Calibration: Successfully processed %i tracks (%i from ITS-TPC-TRD and %i from TPC-TRD) and collected %d tracklets",
nTracksSuccessITSTPCTRD + nTracksSuccessTPCTRD, nTracksSuccessITSTPCTRD, nTracksSuccessTPCTRD, mGainCalibHistos.getNEntries());
LOGP(info, "Gain Calibration: Successfully processed {} tracks ({} from ITS-TPC-TRD and {} from TPC-TRD) and collected {} data points",
nTracksSuccessITSTPCTRD + nTracksSuccessTPCTRD, nTracksSuccessITSTPCTRD, nTracksSuccessTPCTRD, mGainCalibHistos.size());
}

void TrackBasedCalib::calculateAngResHistos()
Expand Down Expand Up @@ -133,10 +132,10 @@ int TrackBasedCalib::filldEdx(gsl::span<const TrackTRD>& tracks, bool isTPCTRD)

const auto& tracklet = mTrackletsRaw[trkltId];

float Q0 = tracklet.getQ0();
float Q1 = tracklet.getQ1();
float Q2 = tracklet.getQ2();
if (Q0 == 0 || Q1 == 0 || Q2 == 0 || Q0 >= 127 || Q1 >= 127 || Q2 >= 62) {
auto q0 = tracklet.getQ0();
auto q1 = tracklet.getQ1();
auto q2 = tracklet.getQ2();
if (q0 == 0 || q1 == 0 || q2 == 0 || q0 >= 127 || q1 >= 127 || q2 >= 62) {
continue;
}

Expand All @@ -153,14 +152,26 @@ int TrackBasedCalib::filldEdx(gsl::span<const TrackTRD>& tracks, bool isTPCTRD)
// l/l0 = sqrt(dx^2 + dy^2 + dz^2)/dx = sqrt(1 + (dy/dx)^2 + (dz/dx)^2)
// (dz/dx)^2 = tan^2(lambda), (dy/dx)^2 = tan^2(phi) = sin^2(phi)/(1-sin^2(phi))
float trkLength = sqrt(1 + snp * snp / (1 - snp * snp) + tgl * tgl);
if (TMath::Abs(trkLength) < 1) {
LOGP(warn, "Invalid track length {} for angles snp {} and tgl {}", trkLength, snp, tgl);
continue;
}

float localGainCorr = 1.;
if (mLocalGain) {
localGainCorr = mLocalGain->getValue(tracklet.getDetector(), tracklet.getPadCol(), tracklet.getPadRow());
localGainCorr = mLocalGain->getValue(trkltDet, tracklet.getPadCol(), tracklet.getPadRow());
}
if (TMath::Abs(localGainCorr) < 0.0001f) {
LOGP(warn, "Invalid localGainCorr {} for det {}, pad col {}, pad row {}", localGainCorr, trkltDet, tracklet.getPadCol(), tracklet.getPadRow());
continue;
}
float dEdx = (Q0 + Q1 + Q2) / trkLength / localGainCorr;

mGainCalibHistos.addEntry(dEdx, mTrackletsRaw[trkIn.getTrackletIndex(iLayer)].getDetector());
unsigned int dEdx = (q0 + q1 + q2) / trkLength / localGainCorr;
if (dEdx >= NBINSGAINCALIB) {
continue;
}
int chamberOffset = trkltDet * NBINSGAINCALIB;
mGainCalibHistos.push_back(chamberOffset + trkltDet + dEdx);
}

// here we can count the number of successfully processed tracks
Expand Down
4 changes: 2 additions & 2 deletions Detectors/TRD/workflow/include/TRDWorkflow/GainCalibSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ class GainCalibDevice : public o2::framework::Task
return;
}
o2::base::GRPGeomHelper::instance().checkUpdates(pc);
auto dataGainCalib = pc.inputs().get<o2::trd::GainCalibHistos*>("input");
auto dataGainCalib = pc.inputs().get<std::vector<int>>("input");
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo());
LOG(info) << "Processing TF " << mCalibrator->getCurrentTFInfo().tfCounter << " with " << dataGainCalib->getNEntries() << " GainCalibHistos entries";
LOG(info) << "Processing TF " << mCalibrator->getCurrentTFInfo().tfCounter << " with " << dataGainCalib.size() << " GainCalibHistos entries";
mCalibrator->process(dataGainCalib);
if (pc.transitionState() == TransitionHandlingState::Requested) {
LOG(info) << "Run stop requested, finalizing";
Expand Down

0 comments on commit f4bea48

Please sign in to comment.