22#include "TStopwatch.h"
42 auto xDir = TMath::Cos(impactAng);
43 auto yDir = TMath::Sin(impactAng);
44 double slope = (TMath::Abs(xDir) < 1e-7) ? 1e7 : yDir / xDir;
45 auto laTan = TMath::Tan(laFit);
46 double lorentzSlope = (TMath::Abs(laTan) < 1e-7) ? 1e7 : 1. / laTan;
53 double xLorentzAnodeHit =
mAnodePlane / lorentzSlope;
57 double xLorentzDriftHit = xLorentzAnodeHit;
64 double impactAngleSim = TMath::ATan2(yAnodeHit, xAnodeHit);
66 double deltaXLorentzDriftHit = xAnodeHit - xLorentzDriftHitPreCorr;
67 double deltaYLorentzDriftHit = yAnodeHit - yLorentzDriftHitPreCorr;
68 double impactAngleRec = TMath::ATan2(deltaYLorentzDriftHit, deltaXLorentzDriftHit);
70 double deltaAngle = (impactAngleRec - impactAngleSim);
79 auto impactAngle = (
profiles[
currDet]->GetBinCenter(iBin) + 90) * TMath::DegToRad();
80 auto deltaAlpha =
profiles[
currDet]->GetBinContent(iBin) * TMath::DegToRad();
81 if (TMath::Abs(deltaAlpha) < 1e-7) {
88 sum += TMath::Power(deltaAlphaSim - deltaAlpha, 2);
99 mObjectVector.clear();
110 mFitFunctor.
mAnodePlane = GeometryBase::camHght() / (2.f * 100.f);
111 for (
int iDet = 0; iDet <
MAXCHAMBER; ++iDet) {
115 mFitter.SetFCN<
FitFunctor>(2, mFitFunctor, mParamsStart);
116 mFitter.Config().ParSettings(
ParamIndex::LA).SetLimits(-0.7, 0.7);
120 ROOT::Math::MinimizerOptions opt;
121 opt.SetMinimizerType(
"Minuit2");
122 opt.SetMinimizerAlgorithm(
"Migrad");
123 opt.SetPrintLevel(0);
124 opt.SetMaxFunctionCalls(1'000);
125 opt.SetTolerance(.001);
126 mFitter.Config().SetMinimizerOptions(opt);
130 mOutTree->Branch(
"lorentzAngle", &mFitFunctor.
laPreCorr);
131 mOutTree->Branch(
"vDrift", &mFitFunctor.
vdPreCorr);
132 for (
int iDet = 0; iDet <
MAXCHAMBER; ++iDet) {
133 mOutTree->Branch(fmt::format(
"residuals_{:d}", iDet).c_str(), mFitFunctor.
profiles[iDet].get());
145 std::string
msg =
"Default Object";
147 for (
int iDet = 0; iDet <
MAXCHAMBER; ++iDet) {
149 dataCalVdriftExB->getExB(iDet) !=
EXBDEFAULT) {
150 msg =
"Previous Object";
154 LOG(info) <<
"Calibrator: From CCDB retrieved " <<
msg;
157 for (
int iDet = 0; iDet <
MAXCHAMBER; ++iDet) {
158 mFitFunctor.
laPreCorr[iDet] = dataCalVdriftExB->getExB(iDet);
159 mFitFunctor.
vdPreCorr[iDet] = dataCalVdriftExB->getVdrift(iDet);
169 auto laFitResults = mFitFunctor.
laPreCorr;
170 auto vdFitResults = mFitFunctor.
vdPreCorr;
172 for (
int iDet = 0; iDet <
MAXCHAMBER; ++iDet) {
174 mFitFunctor.
profiles[iDet]->Reset();
178 auto angleDiffSum = residHists->getHistogramEntry(iDet *
NBINSANGLEDIFF + iBin);
179 auto nEntries = residHists->getBinCount(iDet *
NBINSANGLEDIFF + iBin);
180 sumEntries += nEntries;
186 if (sumEntries < mMinEntriesChamber) {
187 LOGF(
debug,
"Chamber %d did not reach minimum amount of entries for refit", iDet);
194 auto fitResult = mFitter.Result();
197 LOGF(
debug,
"Fit result for chamber %i: vd=%f, la=%f", iDet, vdFitResults[iDet], laFitResults[iDet] * TMath::RadToDeg());
199 mFitFunctor.
laPreCorr[iDet] = laFitResults[iDet];
200 mFitFunctor.
vdPreCorr[iDet] = vdFitResults[iDet];
203 LOGF(info,
"Done fitting angular residual histograms. CPU time: %f, real time: %f", timer.CpuTime(), timer.RealTime());
208 for (
int iDet = 0; iDet <
MAXCHAMBER; ++iDet) {
209 LOGF(
debug,
"Fit result for chamber %i: vd=%f, la=%f", iDet, vdFitResults[iDet], laFitResults[iDet] * TMath::RadToDeg());
215 for (
int iDet = 0; iDet <
MAXCHAMBER; ++iDet) {
218 calObject.
setVdrift(iDet, vdFitResults[iDet]);
219 calObject.
setExB(iDet, laFitResults[iDet]);
223 std::map<std::string, std::string> metadata;
226 mObjectVector.push_back(calObject);
232 auto& slot = front ? container.emplace_front(tStart, tEnd) : container.emplace_back(tStart, tEnd);
233 slot.setContainer(std::make_unique<AngularResidHistos>());
239 mEnableOutput =
true;
240 mOutFile = std::make_unique<TFile>(
"trd_calibVdriftExB.root",
"RECREATE");
241 if (mOutFile->IsZombie()) {
242 LOG(error) <<
"Failed to create output file!";
243 mEnableOutput =
false;
246 mOutTree = std::make_unique<TTree>(
"calib",
"VDrift&ExB calibration");
247 LOG(info) <<
"Created output file trd_calibVdriftExB.root";
252 if (!mEnableOutput) {
262 }
catch (std::exception
const& e) {
263 LOG(error) <<
"Failed to write calibration data file, reason: " << e.what();
266 mEnableOutput =
false;
TimeSlot-based calibration of vDrift and ExB.
Definition of the Names Generator class.
o2::calibration::TFType TFType
long getStartTimeMS() const
const Container * getContainer() const
static std::string generateFileName(const std::string &inp)
static constexpr long HOUR
static constexpr long SECOND
InputRecord & inputs()
The inputs associated with this processing context.
void setExB(int iDet, float exb)
void setVdrift(int iDet, float vd)
void retrievePrev(o2::framework::ProcessingContext &pc)
void finalizeSlot(Slot &slot) final
Slot & emplaceNewSlot(bool front, TFType tStart, TFType tEnd) final
float sum(float s, o2::dcs::DataPointValue v)
constexpr double EXBDEFAULT
default value for LorentzAngle
constexpr int MAXCHAMBER
the maximum number of installed chambers
constexpr double VDRIFTDEFAULT
default value for vDrift
constexpr int NBINSANGLEDIFF
the number of bins for the track angle used for the vDrift and ExB calibration based on the tracking
constexpr float MAXIMPACTANGLE
the maximum impact angle for tracks relative to the TRD detector plane to be considered for vDrift an...
std::array< double, constants::MAXCHAMBER > laPreCorr
LorentzAngle from previous Run.
double mAnodePlane
distance of the TRD anode plane from the drift cathodes in m
int currDet
the current TRD chamber number
double operator()(const double *par) const
std::array< std::unique_ptr< TProfile >, constants::MAXCHAMBER > profiles
profile histograms for each TRD chamber
double calculateDeltaAlphaSim(double vdFit, double laFit, double impactAng) const
std::array< double, constants::MAXCHAMBER > vdPreCorr
vDrift from previous Run
float upperBoundAngleFit
upper bound for fit angle
float lowerBoundAngleFit
lower bound for fit angle
static std::string getClassName(const T &obj)
get the class name of the object
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
uint64_t const void const *restrict const msg