Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions DataFormats/Detectors/TRD/include/DataFormatsTRD/CalGain.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,42 @@

void setMPVdEdx(int iDet, float mpv) { mMPVdEdx[iDet] = mpv; }

float getMPVdEdx(int iDet) const { return mMPVdEdx[iDet]; }
float getMPVdEdx(int iDet, bool defaultAvg = false) const {

Check failure on line 36 in DataFormats/Detectors/TRD/include/DataFormatsTRD/CalGain.h

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
// if defaultAvg = false, we take the value stored whatever it is
// if defaultAvg = true and we have default value or bad value stored, we take the average on all chambers instead
if (!defaultAvg || isGoodGain(iDet)) return mMPVdEdx[iDet];
else return getAverageGain();
}

Check failure on line 42 in DataFormats/Detectors/TRD/include/DataFormatsTRD/CalGain.h

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.

Check failure on line 43 in DataFormats/Detectors/TRD/include/DataFormatsTRD/CalGain.h

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
float getAverageGain() const {
float averageGain = 0.;
int ngood = 0;

Check failure on line 47 in DataFormats/Detectors/TRD/include/DataFormatsTRD/CalGain.h

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
for (int iDet = 0; iDet < constants::MAXCHAMBER; iDet++) {
if (isGoodGain(iDet)) {
// The chamber has correct calibration
ngood ++;
averageGain += mMPVdEdx[iDet];
}
}
if (ngood == 0) {
// we should make sure it never happens
return constants::MPVDEDXDEFAULT;
}
averageGain /= ngood;
return averageGain;
}

Check failure on line 62 in DataFormats/Detectors/TRD/include/DataFormatsTRD/CalGain.h

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
bool isGoodGain(int iDet) const {
if (TMath::Abs(mMPVdEdx[iDet] - constants::MPVDEDXDEFAULT) > 1e-6) return true;
else return false;

Check failure on line 65 in DataFormats/Detectors/TRD/include/DataFormatsTRD/CalGain.h

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
}

private:
std::array<float, constants::MAXCHAMBER> mMPVdEdx{}; ///< Most probable value of dEdx distribution per TRD chamber

ClassDefNV(CalGain, 1);
ClassDefNV(CalGain, 2);
};

} // namespace trd
Expand Down
74 changes: 71 additions & 3 deletions DataFormats/Detectors/TRD/include/DataFormatsTRD/CalVdriftExB.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,83 @@

void setVdrift(int iDet, float vd) { mVdrift[iDet] = vd; }
void setExB(int iDet, float exb) { mExB[iDet] = exb; }

Check failure on line 36 in DataFormats/Detectors/TRD/include/DataFormatsTRD/CalVdriftExB.h

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
float getVdrift(int iDet, bool defaultAvg = false) const {
// if defaultAvg = false, we take the value stored whatever it is
// if defaultAvg = true and we have default value or bad value stored, we take the average on all chambers instead
if (!defaultAvg || (isGoodExB(iDet) && isGoodVdrift(iDet))) return mVdrift[iDet];
else return getAverageVdrift();
}
float getExB(int iDet, bool defaultAvg = false) const {
if (!defaultAvg || (isGoodExB(iDet) && isGoodVdrift(iDet))) return mExB[iDet];
else return getAverageExB();

Check failure on line 45 in DataFormats/Detectors/TRD/include/DataFormatsTRD/CalVdriftExB.h

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
}

Check failure on line 47 in DataFormats/Detectors/TRD/include/DataFormatsTRD/CalVdriftExB.h

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
float getAverageVdrift() const {
float averageVdrift = 0.;
int ngood = 0;

Check failure on line 51 in DataFormats/Detectors/TRD/include/DataFormatsTRD/CalVdriftExB.h

View workflow job for this annotation

GitHub Actions / PR formatting / whitespace

Trailing spaces

Remove the trailing spaces at the end of the line.
for (int iDet = 0; iDet < constants::MAXCHAMBER; iDet++) {
if (isGoodExB(iDet) && isGoodVdrift(iDet)) {
// Both values need to be correct to declare a chamber as well calibrated
ngood ++;
averageVdrift += mVdrift[iDet];
}
}
if (ngood == 0) {
// we should make sure it never happens
return constants::VDRIFTDEFAULT;
}
averageVdrift /= ngood;
return averageVdrift;
}

float getVdrift(int iDet) const { return mVdrift[iDet]; }
float getExB(int iDet) const { return mExB[iDet]; }
float getAverageExB() const {
float averageExB = 0.;
int ngood = 0;

for (int iDet = 0; iDet < constants::MAXCHAMBER; iDet++) {
if (isGoodExB(iDet) && isGoodVdrift(iDet)) {
// Both values need to be correct to declare a chamber as well calibrated
ngood ++;
averageExB += mExB[iDet];
}
}
if (ngood == 0) {
// we should make sure it never happens
return constants::EXBDEFAULT;
}
averageExB /= ngood;
return averageExB;
}

bool isGoodExB(int iDet) const {
// check if value is well calibrated or not
// default calibration if not enough entries
// close to boundaries indicate a failed fit
if (TMath::Abs(mExB[iDet] - constants::EXBDEFAULT) > 1e-6 &&
TMath::Abs(mExB[iDet] - constants::EXBMIN) > 0.01 &&
TMath::Abs(mExB[iDet] - constants::EXBMAX) > 0.01)
return true;
else return false;
}

bool isGoodVdrift(int iDet) const {
// check if value is well calibrated or not
// default calibration if not enough entries
// close to boundaries indicate a failed fit
if (TMath::Abs(mVdrift[iDet] - constants::VDRIFTDEFAULT) > 1e-6 &&
TMath::Abs(mVdrift[iDet] - constants::VDRIFTMIN) > 0.1 &&
TMath::Abs(mVdrift[iDet] - constants::VDRIFTMAX) > 0.1)
return true;
else return false;
}

private:
std::array<float, constants::MAXCHAMBER> mVdrift{}; ///< calibrated drift velocity per TRD chamber
std::array<float, constants::MAXCHAMBER> mExB{}; ///< calibrated Lorentz angle per TRD chamber

ClassDefNV(CalVdriftExB, 1);
ClassDefNV(CalVdriftExB, 2);
};

} // namespace trd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ constexpr int TIMEBINS = 30; ///< the number of time bins
constexpr float MAXIMPACTANGLE = 25.f; ///< the maximum impact angle for tracks relative to the TRD detector plane to be considered for vDrift and ExB calibration
constexpr int NBINSANGLEDIFF = 25; ///< the number of bins for the track angle used for the vDrift and ExB calibration based on the tracking
constexpr double VDRIFTDEFAULT = 1.546; ///< default value for vDrift
constexpr double VDRIFTMIN = 0.4; ///< min value for vDrift
constexpr double VDRIFTMAX = 2.0; ///< max value for vDrift
constexpr double EXBDEFAULT = 0.0; ///< default value for LorentzAngle
constexpr double EXBMIN = -0.4; ///< min value for LorentzAngle
constexpr double EXBMAX = 0.4; ///< max value for LorentzAngle
constexpr int NBINSGAINCALIB = 320; ///< number of bins in the charge (Q0+Q1+Q2) histogram for gain calibration
constexpr float MPVDEDXDEFAULT = 42.; ///< default Most Probable Value of TRD dEdx
constexpr float T0DEFAULT = 1.2; ///< default value for t0
Expand Down
7 changes: 6 additions & 1 deletion Detectors/Align/Workflow/src/BarrelAlignmentSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,12 @@ void BarrelAlignmentSpec::finaliseCCDB(o2::framework::ConcreteDataMatcher& match
}
if (matcher == ConcreteDataMatcher("TRD", "CALVDRIFTEXB", 0)) {
LOG(info) << "CalVdriftExB object has been updated";
mTRDTransformer->setCalVdriftExB((const o2::trd::CalVdriftExB*)obj);
for (int iDet = 0; iDet < o2::trd::constants::MAXCHAMBER; iDet++) {
// set to average value if the calibration is not correct
mTRDTransformer->setVdrift(iDet, ((const o2::trd::CalVdriftExB*)obj)->getVdrift(iDet, true));
mTRDTransformer->setExB(iDet, ((const o2::trd::CalVdriftExB*)obj)->getExB(iDet, true));
}
//mTRDTransformer->setCalVdriftExB((const o2::trd::CalVdriftExB*)obj);
return;
}
if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
Expand Down
8 changes: 6 additions & 2 deletions Detectors/TRD/base/include/TRDBase/TrackletTransformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ class TrackletTransformer

void init();

void setCalVdriftExB(const CalVdriftExB* cal) { mCalVdriftExB = cal; };
void setVdrift(int iDet, float vd) {mVdrift[iDet] = vd;}
void setExB(int iDet, float exb) {mExB[iDet] = exb;}
void setApplyXOR() { mApplyXOR = true; }
void setApplyShift(bool f) { mApplyShift = f; }
bool isShiftApplied() const { return mApplyShift; }



float calculateZ(int padrow, const PadPlane* padPlane) const;

Expand All @@ -54,7 +57,8 @@ class TrackletTransformer

float mXAnode;

const CalVdriftExB* mCalVdriftExB{nullptr};
std::array<float, constants::MAXCHAMBER> mVdrift{};
std::array<float, constants::MAXCHAMBER> mExB{};
};

} // namespace trd
Expand Down
15 changes: 9 additions & 6 deletions Detectors/TRD/base/src/TrackletTransformer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ float TrackletTransformer::calculateDy(int detector, int slope, const PadPlane*
{
double padWidth = padPlane->getWidthIPad();

float vDrift = mCalVdriftExB->getVdrift(detector);
float exb = mCalVdriftExB->getExB(detector);
//float vDrift = mCalVdriftExB->getVdrift(detector, true);
//float exb = mCalVdriftExB->getExB(detector, true);
float vDrift = mVdrift[detector];
float exb = mExB[detector];

// dy = slope * nTimeBins * padWidth * GRANULARITYTRKLSLOPE;
// nTimeBins should be number of timebins in drift region. 1 timebin is 100 nanosecond
Expand All @@ -50,11 +52,12 @@ float TrackletTransformer::calculateDy(int detector, int slope, const PadPlane*
// NOTE: check what drift height is used in calibration code to ensure consistency
// NOTE: check sign convention of Lorentz angle
// NOTE: confirm the direction in which vDrift is measured/determined. Is it in x or in direction of drift?
double lorentzCorrection = TMath::Tan(exb) * mXAnode;
// The Lorentz correction have to be applied both at the point of entrance and at the end of the drift region
double lorentzCorrection = TMath::Tan(exb) * mGeo->cdrHght();

// assuming angle in Bailhache, fig. 4.17 would be positive in our calibration code
double calibratedDy = rawDy - lorentzCorrection;

return calibratedDy;
}

Expand Down Expand Up @@ -96,7 +99,7 @@ CalibratedTracklet TrackletTransformer::transformTracklet(Tracklet64 tracklet, b
position = tracklet.getPositionBinSigned();
slope = tracklet.getSlopeBinSigned();
}

// calculate raw local chamber space point
const auto padPlane = mGeo->getPadPlane(detector);

Expand Down Expand Up @@ -124,7 +127,7 @@ CalibratedTracklet TrackletTransformer::transformTracklet(Tracklet64 tracklet, b
double TrackletTransformer::getTimebin(int detector, double x) const
{
// calculate timebin from x position within chamber
float vDrift = mCalVdriftExB->getVdrift(detector);
float vDrift = mVdrift[detector];
double t0 = 4.0; // time (in timebins) of start of drift region

double timebin;
Expand Down
6 changes: 3 additions & 3 deletions Detectors/TRD/calibration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ For 'o2-calibration-trd-workflow --vDriftAndExB' there are also the following ke

*Hint: You can get information on the meaning of the parameters by running `o2-calibration-trd-workflow --vDriftAndExB -b --help full`*

If you want to run the calibration from a local file with residuals, trdangreshistos.root, you can run:
If you want to run the calibration from a local file with residuals, trdcaliboutput.root, you can run:

o2-calibration-trd-workflow --vDriftAndExB -b --enable-root-input --calib-vdexb-calibration '--tf-per-slot 1' --configKeyValues "TRDCalibParams.minEntriesChamber=100;TRDCalibParams.minEntriesTotal=50000"
o2-calibration-trd-workflow --vDriftAndExB -b --enable-root-input --calib-vdexb-calibration '--tf-per-slot 1' --configKeyValues "TRDCalibParams.minEntriesChamber=100;TRDCalibParams.minEntriesTotal=50000" --trd-calib-infile trdcaliboutput.root

Additionally it is possible to perform the calibrations fit manually per chamber if you have TPC-TRD or ITS-TPC-TRD tracks, you can run:

o2-trd-global-tracking -b --enable-trackbased-calib

This produces `trdangreshistos.root` which holds the residuals of the angles and differences.
This produces `trdcaliboutput.root` which holds the residuals of the angles and differences.
Then run the macro `Detectors/TRD/calibration/macros/manualCalibFit.C`.
This produces a file of similar name with the fitted data and prints out the fit results.
This is equivalent to running:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ namespace trd
/// VDrift and ExB calibration parameters.
struct TRDCalibParams : public o2::conf::ConfigurableParamHelper<TRDCalibParams> {
unsigned int nTrackletsMin = 5; ///< minimum amount of tracklets
unsigned int nTrackletsMinLoose = 4; ///< minimum amount of tracklets if two layers with a large lever arm both have a hit
unsigned int chi2RedMax = 6; ///< maximum reduced chi2 acceptable for track quality
size_t minEntriesChamber = 75; ///< minimum number of entries per chamber to fit single time slot
size_t minEntriesTotal = 40'500; ///< minimum total required for meaningful fits
size_t minEntriesChamber = 200; ///< minimum number of entries per chamber to fit single time slot
size_t minEntriesTotal = 400'000; ///< minimum total required for meaningful fits

// For gain calibration
unsigned int nTrackletsMinGainCalib = 5;
unsigned int nTrackletsMinGainCalib = 3;
size_t minEntriesChamberGainCalib = 500; ///< minimum number of entries per chamber to fit single time slot
size_t minEntriesTotalGainCalib = 1'000'000; ///< minimum total required for meaningful fits
// Cuts for selecting clean pion candidates for gain calibration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ class CalibratorVdExB final : public o2::calibration::TimeSlotCalibration<o2::tr
private:
bool mInitDone{false}; ///< flag to avoid creating the TProfiles multiple times
const TRDCalibParams& mParams{TRDCalibParams::Instance()}; ///< reference to calibration parameters
size_t mMinEntriesTotal{mParams.minEntriesChamber}; ///< minimum total number of angular deviations (on average ~3 entries per bin for each TRD chamber)
size_t mMinEntriesChamber{mParams.minEntriesTotal}; ///< minimum number of angular deviations per chamber for accepting refitted value (~3 per bin)
size_t mMinEntriesTotal{mParams.minEntriesTotal}; ///< minimum total number of angular deviations (on average ~3 entries per bin for each TRD chamber)
size_t mMinEntriesChamber{mParams.minEntriesChamber}; ///< minimum number of angular deviations per chamber for accepting refitted value (~3 per bin)
bool mEnableOutput{false}; ///< enable output of calibration fits and tprofiles in a root file instead of the ccdb
std::unique_ptr<TFile> mOutFile{nullptr}; ///< output file
std::unique_ptr<TTree> mOutTree{nullptr}; ///< output tree
Expand Down
Loading
Loading