Skip to content

Commit cb20ee1

Browse files
authored
Avoid InputRecord include in TRD data formats lib (#11734)
* Avoid InputRecord include in TRD data formats lib * Fix calib writer input spec
1 parent 072564d commit cb20ee1

7 files changed

Lines changed: 32 additions & 40 deletions

File tree

DataFormats/Detectors/TRD/include/DataFormatsTRD/GainCalibHistos.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
#define ALICEO2_GAINCALIBHISTOS_H
1717

1818
#include "DataFormatsTRD/Constants.h"
19-
#include "Framework/InputRecord.h"
2019
#include "Rtypes.h"
2120
#include <vector>
22-
#include <memory>
23-
#include <gsl/span>
2421

2522
namespace o2
2623
{
@@ -35,11 +32,10 @@ class GainCalibHistos
3532
~GainCalibHistos() = default;
3633
void reset();
3734
void init();
38-
void addEntry(float dEdx, int chamberId);
3935
auto getHistogramEntry(int index) const { return mdEdxEntries[index]; }
4036
auto getNEntries() const { return mNEntriesTot; }
4137

42-
void fill(const std::unique_ptr<const GainCalibHistos, o2::framework::InputRecord::Deleter<const o2::trd::GainCalibHistos>>& input);
38+
void fill(const std::vector<int>& input);
4339
void merge(const GainCalibHistos* prev);
4440
void print();
4541

DataFormats/Detectors/TRD/include/DataFormatsTRD/T0FitHistos.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717

1818
#include "DataFormatsTRD/Constants.h"
1919
#include "DataFormatsTRD/PHData.h"
20-
#include "Framework/InputRecord.h"
2120
#include "Rtypes.h"
2221
#include <vector>
2322
#include <memory>
24-
#include <gsl/span>
2523

2624
namespace o2
2725
{

DataFormats/Detectors/TRD/src/GainCalibHistos.cxx

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,15 @@ void GainCalibHistos::reset()
3131
mNEntriesTot = 0;
3232
}
3333

34-
void GainCalibHistos::addEntry(float dEdx, int chamberId)
35-
{
36-
// add entry for given dEdx
37-
int chamberOffset = chamberId * NBINSGAINCALIB;
38-
int iBin = (int)dEdx;
39-
if (iBin < 0 || iBin >= NBINSGAINCALIB) {
40-
// This could happen because of local gain correction but should be very rare, so we can just skip it
41-
return;
42-
}
43-
++mdEdxEntries[chamberOffset + iBin];
44-
++mNEntriesTot;
45-
}
46-
47-
void GainCalibHistos::fill(const std::unique_ptr<const GainCalibHistos, o2::framework::InputRecord::Deleter<const o2::trd::GainCalibHistos>>& input)
34+
void GainCalibHistos::fill(const std::vector<int>& input)
4835
{
4936
if (!mInitialized) {
5037
init();
5138
}
52-
for (int i = 0; i < MAXCHAMBER * NBINSGAINCALIB; ++i) {
53-
mdEdxEntries[i] += input->getHistogramEntry(i);
54-
mNEntriesTot += input->getHistogramEntry(i);
39+
for (auto elem : input) {
40+
++mdEdxEntries[elem];
5541
}
42+
mNEntriesTot += input.size();
5643
}
5744

5845
void GainCalibHistos::merge(const GainCalibHistos* prev)

Detectors/TRD/calibration/include/TRDCalibration/TrackBasedCalib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ class TrackBasedCalib
8282
bool propagateAndUpdate(TrackTRD& trk, int iLayer, bool doUpdate) const;
8383

8484
const AngularResidHistos& getAngResHistos() const { return mAngResHistos; }
85-
const GainCalibHistos& getGainCalibHistos() const { return mGainCalibHistos; }
85+
const auto& getGainCalibHistos() const { return mGainCalibHistos; }
8686

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

9696
// input arrays which should not be modified since they are provided externally

Detectors/TRD/calibration/src/TrackBasedCalib.cxx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,13 @@ using namespace o2::trd::constants;
2929
void TrackBasedCalib::reset()
3030
{
3131
mAngResHistos.reset();
32-
mGainCalibHistos.reset();
32+
mGainCalibHistos.clear();
3333
}
3434

3535
void TrackBasedCalib::init()
3636
{
3737
bz = o2::base::Propagator::Instance()->getNominalBz();
3838
mRecoParam.setBfield(bz);
39-
mGainCalibHistos.init();
4039
}
4140

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

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

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

134133
const auto& tracklet = mTrackletsRaw[trkltId];
135134

136-
float Q0 = tracklet.getQ0();
137-
float Q1 = tracklet.getQ1();
138-
float Q2 = tracklet.getQ2();
139-
if (Q0 == 0 || Q1 == 0 || Q2 == 0 || Q0 >= 127 || Q1 >= 127 || Q2 >= 62) {
135+
auto q0 = tracklet.getQ0();
136+
auto q1 = tracklet.getQ1();
137+
auto q2 = tracklet.getQ2();
138+
if (q0 == 0 || q1 == 0 || q2 == 0 || q0 >= 127 || q1 >= 127 || q2 >= 62) {
140139
continue;
141140
}
142141

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

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

163-
mGainCalibHistos.addEntry(dEdx, mTrackletsRaw[trkIn.getTrackletIndex(iLayer)].getDetector());
169+
unsigned int dEdx = (q0 + q1 + q2) / trkLength / localGainCorr;
170+
if (dEdx >= NBINSGAINCALIB) {
171+
continue;
172+
}
173+
int chamberOffset = trkltDet * NBINSGAINCALIB;
174+
mGainCalibHistos.push_back(chamberOffset + trkltDet + dEdx);
164175
}
165176

166177
// here we can count the number of successfully processed tracks

Detectors/TRD/workflow/include/TRDWorkflow/GainCalibSpec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ class GainCalibDevice : public o2::framework::Task
7070
return;
7171
}
7272
o2::base::GRPGeomHelper::instance().checkUpdates(pc);
73-
auto dataGainCalib = pc.inputs().get<o2::trd::GainCalibHistos*>("input");
73+
auto dataGainCalib = pc.inputs().get<std::vector<int>>("input");
7474
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo());
75-
LOG(info) << "Processing TF " << mCalibrator->getCurrentTFInfo().tfCounter << " with " << dataGainCalib->getNEntries() << " GainCalibHistos entries";
75+
LOG(info) << "Processing TF " << mCalibrator->getCurrentTFInfo().tfCounter << " with " << dataGainCalib.size() << " GainCalibHistos entries";
7676
mCalibrator->process(dataGainCalib);
7777
if (pc.transitionState() == TransitionHandlingState::Requested) {
7878
LOG(info) << "Run stop requested, finalizing";

Detectors/TRD/workflow/io/src/TRDCalibWriterSpec.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ o2::framework::DataProcessorSpec getTRDCalibWriterSpec(bool vdexb, bool gain, bo
3535
"calibdata",
3636
BranchDefinition<o2::trd::AngularResidHistos>{InputSpec{"calibdata", "TRD", "ANGRESHISTS"}, "AngularResids", (vdexb ? 1 : 0)},
3737
BranchDefinition<std::vector<o2::trd::PHData>>{InputSpec{"phValues", "TRD", "PULSEHEIGHT"}, "PulseHeight", (ph ? 1 : 0)},
38-
BranchDefinition<o2::trd::GainCalibHistos>{InputSpec{"calibdatagain", "TRD", "GAINCALIBHISTS"}, "GainHistograms", (gain ? 1 : 0)})();
38+
BranchDefinition<std::vector<int>>{InputSpec{"calibdatagain", "TRD", "GAINCALIBHISTS"}, "GainHistograms", (gain ? 1 : 0)})();
3939
};
4040

4141
} // end namespace trd

0 commit comments

Comments
 (0)