Skip to content
Open
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
30 changes: 18 additions & 12 deletions DataFormats/Detectors/TRD/include/DataFormatsTRD/CalGain.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,25 @@ class CalGain

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

float getMPVdEdx(int iDet, bool defaultAvg = false) const {
float getMPVdEdx(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 || isGoodGain(iDet)) return mMPVdEdx[iDet];
else return getAverageGain();
if (!defaultAvg || isGoodGain(iDet))
return mMPVdEdx[iDet];
else
return getAverageGain();
}

float getAverageGain() const {

float getAverageGain() const
{
float averageGain = 0.;
int ngood = 0;

for (int iDet = 0; iDet < constants::MAXCHAMBER; iDet++) {
if (isGoodGain(iDet)) {
// The chamber has correct calibration
ngood ++;
ngood++;
averageGain += mMPVdEdx[iDet];
}
}
Expand All @@ -59,10 +62,13 @@ class CalGain
averageGain /= ngood;
return averageGain;
}

bool isGoodGain(int iDet) const {
if (TMath::Abs(mMPVdEdx[iDet] - constants::MPVDEDXDEFAULT) > 1e-6) return true;
else return false;

bool isGoodGain(int iDet) const
{
if (TMath::Abs(mMPVdEdx[iDet] - constants::MPVDEDXDEFAULT) > 1e-6)
return true;
else
return false;
}

private:
Expand Down
48 changes: 30 additions & 18 deletions DataFormats/Detectors/TRD/include/DataFormatsTRD/CalVdriftExB.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,33 @@ class CalVdriftExB

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

float getVdrift(int iDet, bool defaultAvg = false) const {

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();
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();
float getExB(int iDet, bool defaultAvg = false) const
{
if (!defaultAvg || (isGoodExB(iDet) && isGoodVdrift(iDet)))
return mExB[iDet];
else
return getAverageExB();
}

float getAverageVdrift() const {

float getAverageVdrift() const
{
float averageVdrift = 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 ++;
ngood++;
averageVdrift += mVdrift[iDet];
}
}
Expand All @@ -64,14 +71,15 @@ class CalVdriftExB
return averageVdrift;
}

float getAverageExB() const {
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 ++;
ngood++;
averageExB += mExB[iDet];
}
}
Expand All @@ -83,26 +91,30 @@ class CalVdriftExB
return averageExB;
}

bool isGoodExB(int iDet) const {
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;
else
return false;
}

bool isGoodVdrift(int iDet) const {
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;
else
return false;
}

private:
Expand Down
8 changes: 4 additions & 4 deletions DataFormats/Detectors/TRD/include/DataFormatsTRD/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +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 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 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
2 changes: 1 addition & 1 deletion Detectors/Align/Workflow/src/BarrelAlignmentSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void BarrelAlignmentSpec::finaliseCCDB(o2::framework::ConcreteDataMatcher& match
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);
// mTRDTransformer->setCalVdriftExB((const o2::trd::CalVdriftExB*)obj);
return;
}
if (mTPCVDriftHelper.accountCCDBInputs(matcher, obj)) {
Expand Down
6 changes: 2 additions & 4 deletions Detectors/TRD/base/include/TRDBase/TrackletTransformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ class TrackletTransformer

void init();

void setVdrift(int iDet, float vd) {mVdrift[iDet] = vd;}
void setExB(int iDet, float exb) {mExB[iDet] = exb;}
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 Down
8 changes: 4 additions & 4 deletions Detectors/TRD/base/src/TrackletTransformer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ float TrackletTransformer::calculateDy(int detector, int slope, const PadPlane*
{
double padWidth = padPlane->getWidthIPad();

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

Expand All @@ -57,7 +57,7 @@ float TrackletTransformer::calculateDy(int detector, int slope, const PadPlane*

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

return calibratedDy;
}

Expand Down Expand Up @@ -99,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
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ 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 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 = 200; ///< minimum number of entries per chamber to fit single time slot
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
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.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)
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
47 changes: 25 additions & 22 deletions Detectors/TRD/calibration/macros/manualCalibFit.C
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,23 @@ void manualCalibFit(int runNumber = 563335, bool usePreCorrFromCCDB = false)
mNEntriesPerBinSum.fill(0);
tree->SetBranchAddress("mHistogramEntries[13500]", &mHistogramEntries);
tree->SetBranchAddress("mNEntriesPerBin[13500]", &mNEntriesPerBin);
// use precorr values from ccdb

// use precorr values from ccdb
// necessary when the angular residuals were calculated already using ccdb calibration (e.g. in a local run)

o2::trd::CalVdriftExB* calObject;
if (usePreCorrFromCCDB) {
auto& ccdbmgr = o2::ccdb::BasicCCDBManager::instance();

o2::ccdb::CcdbApi ccdb;
ccdb.init("http://alice-ccdb.cern.ch");
auto runDuration = ccdbmgr.getRunDuration(runNumber);

std::map<std::string, std::string> metadata;
std::map<std::string, std::string> headers;

calObject = ccdb.retrieveFromTFileAny<o2::trd::CalVdriftExB>("TRD/Calib/CalVdriftExB", metadata, runDuration.first + 60000, &headers, "", "", "1689478811721");
}


//----------------------------------------------------
// Configure Fitter
Expand All @@ -88,9 +87,11 @@ void manualCalibFit(int runNumber = 563335, bool usePreCorrFromCCDB = false)
for (int iDet = 0; iDet < 540; ++iDet) {
mFitFunctor.profiles[iDet] = std::make_unique<TProfile>(Form("profAngleDiff_%i", iDet), Form("profAngleDiff_%i", iDet), 25, -25.f, 25.f);
if (usePreCorrFromCCDB) {
std::cout<<iDet<<" "<<calObject->getVdrift(iDet)<<" "<<calObject->getExB(iDet)<<" ";
if (calObject->isGoodExB(iDet)) counter++;
if (iDet%6==5)std::cout<<std::endl;
std::cout << iDet << " " << calObject->getVdrift(iDet) << " " << calObject->getExB(iDet) << " ";
if (calObject->isGoodExB(iDet))
counter++;
if (iDet % 6 == 5)
std::cout << std::endl;
mFitFunctor.vdPreCorr[iDet] = calObject->getVdrift(iDet, true);
mFitFunctor.laPreCorr[iDet] = calObject->getExB(iDet, true);
}
Expand Down Expand Up @@ -128,7 +129,8 @@ void manualCalibFit(int runNumber = 563335, bool usePreCorrFromCCDB = false)
if (nEntries > 0) { // skip entries which have no entries; ?
// add to the respective profile for fitting later on
mFitFunctor.profiles[iDet]->Fill(2 * iBin - 25.f, angleDiffSum / nEntries, nEntries);
if (iDet == 207) std::cout<<iBin<<" "<<angleDiffSum<<" "<<nEntries<<" "<<angleDiffSum/nEntries<<" "<<mFitFunctor.profiles[iDet]->GetBinEntries(iBin+1)<<" "<<mFitFunctor.profiles[iDet]->GetBinEffectiveEntries(iBin+1)<<" "<<mFitFunctor.profiles[iDet]->GetBinError(iBin+1)<<std::endl;
if (iDet == 207)
std::cout << iBin << " " << angleDiffSum << " " << nEntries << " " << angleDiffSum / nEntries << " " << mFitFunctor.profiles[iDet]->GetBinEntries(iBin + 1) << " " << mFitFunctor.profiles[iDet]->GetBinEffectiveEntries(iBin + 1) << " " << mFitFunctor.profiles[iDet]->GetBinError(iBin + 1) << std::endl;
}
}
printf("Det %d: nEntries=%d \n", iDet, nEntriesDetTotal[iDet]);
Expand All @@ -140,13 +142,14 @@ void manualCalibFit(int runNumber = 563335, bool usePreCorrFromCCDB = false)
printf("-------- Started fits\n");
std::array<float, 540> laFitResults{};
std::array<float, 540> vdFitResults{};

TH1F* hVd = new TH1F("hVd", "v drift", 150, 0.5, 2.);
TH1F* hLa = new TH1F("hLa", "lorentz angle", 200, -25., 25.);
o2::trd::CalVdriftExB* calObjectOut = new o2::trd::CalVdriftExB();

for (int iDet = 0; iDet < 540; ++iDet) {
if (nEntriesDetTotal[iDet] < 75) continue;
if (nEntriesDetTotal[iDet] < 75)
continue;
mFitFunctor.currDet = iDet;
ROOT::Fit::Fitter fitter;
double paramsStart[2];
Expand All @@ -168,19 +171,20 @@ void manualCalibFit(int runNumber = 563335, bool usePreCorrFromCCDB = false)
auto fitResult = fitter.Result();
laFitResults[iDet] = fitResult.Parameter(0);
vdFitResults[iDet] = fitResult.Parameter(1);
if (fitResult.MinFcnValue() > 0.03) continue;
printf("Det %d: la=%.3f \tvd=%.3f \t100*minValue=%f \tentries=%d\n", iDet, laFitResults[iDet] * TMath::RadToDeg(), vdFitResults[iDet], 100*fitResult.MinFcnValue(), nEntriesDetTotal[iDet]);
if (fitResult.MinFcnValue() > 0.03)
continue;
printf("Det %d: la=%.3f \tvd=%.3f \t100*minValue=%f \tentries=%d\n", iDet, laFitResults[iDet] * TMath::RadToDeg(), vdFitResults[iDet], 100 * fitResult.MinFcnValue(), nEntriesDetTotal[iDet]);
hVd->Fill(vdFitResults[iDet]);
hLa->Fill(laFitResults[iDet]* TMath::RadToDeg());
hLa->Fill(laFitResults[iDet] * TMath::RadToDeg());
calObjectOut->setVdrift(iDet, vdFitResults[iDet]);
calObjectOut->setExB(iDet, laFitResults[iDet]);
}
printf("-------- Finished fits\n");
std::cout<<"number of chambers with enough entries: "<<hVd->GetEntries()<<std::endl;;
std::cout<<"vdrift mean: "<<hVd->GetMean()<<" sigma: "<<hVd->GetStdDev()<<std::endl;
std::cout<<"lorentz angle mean: "<<hLa->GetMean()<<" sigma: "<<hLa->GetStdDev()<<std::endl;

std::cout << "number of chambers with enough entries: " << hVd->GetEntries() << std::endl;
;
std::cout << "vdrift mean: " << hVd->GetMean() << " sigma: " << hVd->GetStdDev() << std::endl;
std::cout << "lorentz angle mean: " << hLa->GetMean() << " sigma: " << hLa->GetStdDev() << std::endl;

//----------------------------------------------------
// Write
Expand All @@ -191,5 +195,4 @@ void manualCalibFit(int runNumber = 563335, bool usePreCorrFromCCDB = false)
outFilePtr->WriteObjectAny(calObjectOut, "o2::trd::CalVdriftExB", "calObject");
for (auto& p : mFitFunctor.profiles)
p->Write();

}
6 changes: 3 additions & 3 deletions Detectors/TRD/calibration/src/CalibratorVdExB.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "CCDB/BasicCCDBManager.h"
#include "CommonUtils/NameConf.h"
#include "CommonUtils/MemFileHelper.h"
//#include "DetectorsBase/Propagator.h"
// #include "DetectorsBase/Propagator.h"
#include <TFile.h>
#include <TTree.h>

Expand Down Expand Up @@ -109,14 +109,14 @@ void CalibratorVdExB::initProcessing()
// fit is done in region where ion tails are small, close to lorentz angle
// we want an approximate value of the lorentz angle in order to define better fit boundaries
// TODO: find a way to obtain the magnetic field even in standalone calibration
//float bz = o2::base::Propagator::Instance()->getNominalBz();
// float bz = o2::base::Propagator::Instance()->getNominalBz();
// default angle with zero field is slightly shifted
float lorentzAngleAvg = -1.f;
/*if (TMath::Abs(bz - 2) < 0.1f) { lorentzAngleAvg = 2.f;}
if (TMath::Abs(bz + 2) < 0.1f) { lorentzAngleAvg = -4.f;}
if (TMath::Abs(bz - 5) < 0.1f) { lorentzAngleAvg = 7.f;}
if (TMath::Abs(bz + 5) < 0.1f) { lorentzAngleAvg = -9.5f;}

LOGP(info, "b field: {} lorentz angle start: {}", bz, lorentzAngleAvg);*/

mFitFunctor.lowerBoundAngleFit = (80 + lorentzAngleAvg) * TMath::DegToRad();
Expand Down
4 changes: 2 additions & 2 deletions Detectors/TRD/calibration/src/TrackBasedCalib.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ int TrackBasedCalib::doTrdOnlyTrackFits(gsl::span<const TrackTRD>& tracks)
for (const auto& trkIn : tracks) {
if (trkIn.getNtracklets() < params.nTrackletsMin) {
// with less than 3 tracklets the TRD-only refit not meaningful
if (trkIn.getNtracklets() < params.nTrackletsMinLoose || !((trkIn.getTrackletIndex(0) >= 0 && (trkIn.getTrackletIndex(NLAYER-1) >= 0 || trkIn.getTrackletIndex(NLAYER-2) >= 0))) || (trkIn.getTrackletIndex(1) >= 0 && trkIn.getTrackletIndex(NLAYER-1) >= 0)) {
// we check if we have enough lever arm, i.e. (first and last) or (second and last) or (first and before last) are present
if (trkIn.getNtracklets() < params.nTrackletsMinLoose || !((trkIn.getTrackletIndex(0) >= 0 && (trkIn.getTrackletIndex(NLAYER - 1) >= 0 || trkIn.getTrackletIndex(NLAYER - 2) >= 0))) || (trkIn.getTrackletIndex(1) >= 0 && trkIn.getTrackletIndex(NLAYER - 1) >= 0)) {
// we check if we have enough lever arm, i.e. (first and last) or (second and last) or (first and before last) are present
continue;
}
}
Expand Down
Loading