97 "slope of X-res vs track x-slope",
98 "slope of X-res vs (x-slope * y)",
99 "slope of X-res vs (x-slope * x)",
100 "slope of X-res vs y"};
102 "mean of X-residual",
103 "mean of Y-residual",
104 "slope of Y-res vs track y-slope",
105 "slope of Y-res vs (y-slope * y)",
106 "slope of Y-res vs (y-slope * x)",
107 "slope of Y-res vs x"};
110 "track x-slope #beta_{x}",
111 "#beta_{x} #upoint y_{bar}, cm",
112 "#beta_{x} #upoint x_{bar}, cm",
116 "track y-slope #beta_{y}",
117 "#beta_{y} #upoint y_{bar}, cm",
118 "#beta_{y} #upoint x_{bar}, cm",
141#define RESIDUAL_RANGE_X 0.02
142#define RESIDUAL_RANGE_Y 0.4
143#define RESIDUAL_BINS 201
144#define PROFILE_BINS 201
145#define PAVE_TEXT_SIZE 0.04
158 if (!(std::abs(
line.Det()) > 0.0) ||
line.N() < 3)
162 return s2 > 0.0 ? std::sqrt(s2 *
line.SlopeVar()) : 0.0;
172 std::array<LinAcc, PARAM_CNT>
x,
y;
188 tcgetattr(STDIN_FILENO, saved);
189 struct termios raw{*saved};
190 raw.c_lflag &= ~(ICANON | ECHO);
193 tcsetattr(STDIN_FILENO, TCSANOW, &raw);
195 tcsetattr(STDIN_FILENO, TCSANOW, saved);
230int histo(
const char* fileListPath =
"/home/igor/bmnroot/align_new/cfg/run8/7466.noa_rlerr.list",
231 Int_t drawDetIdx = 0,
233 const char* pdfPath =
nullptr)
239 if (drawDetIdx < 0 || drawDetIdx >= nDet) {
240 std::cerr <<
" <!> histo: drawDetIdx " << drawDetIdx <<
" out of range [0, " << nDet <<
")" << std::endl;
243 if (drawMode < DM_PROFILE || drawMode >
DM_MIX) {
244 std::cerr <<
" <!> histo: drawMode " << drawMode <<
" out of range [" <<
DM_PROFILE <<
", " <<
DM_MIX <<
"]"
251 std::cerr <<
" <!> histo: failed to initialize iterator on " << fileListPath << std::endl;
255 std::cout <<
"\nInitializing ROOT reader for " << fileListPath <<
"\n";
258 std::vector<DetAcc> acc(nDet);
259 std::vector<DetDraw> draw(nDet);
262 std::cout <<
"Reading data...\n";
263 Long64_t usedTracks{0}, usedHits{0};
272 if (!(lineX.
Det() > 0.0) || !(lineY.
Det() > 0.0))
280 Double_t z{itr.
HitZ()}, xBar{alphaX + betaX * z}, yBar{alphaY + betaY * z}, rx{itr.
HitX() - xBar},
281 ry{itr.
HitY() - yBar};
284 acc[d].x[
P_dX].Add(0.0, rx);
285 acc[d].x[
P_dZ].Add(betaX, rx);
286 acc[d].x[
P_phi].Add(betaX * yBar, rx);
287 acc[d].x[
P_theta].Add(betaX * xBar, rx);
288 acc[d].x[
P_psi].Add(yBar, rx);
290 acc[d].y[
P_dY].Add(0.0, ry);
291 acc[d].y[
P_dZ].Add(betaY, ry);
292 acc[d].y[
P_phi].Add(betaY * yBar, ry);
293 acc[d].y[
P_theta].Add(betaY * xBar, ry);
294 acc[d].y[
P_psi].Add(xBar, ry);
299 dd.
betaX.push_back(betaX);
300 dd.
betaXY.push_back(betaX * yBar);
301 dd.
betaXX.push_back(betaX * xBar);
302 dd.
yBar.push_back(yBar);
303 dd.
betaY.push_back(betaY);
304 dd.
betaYY.push_back(betaY * yBar);
305 dd.
betaYX.push_back(betaY * xBar);
306 dd.
xBar.push_back(xBar);
311 if (usedTracks == 0) {
312 std::cerr <<
" <!> histo: no usable tracks found" << std::endl;
319 cout <<
"\nHistogramming method: first-order corrections read from residuals\n";
320 cout << usedTracks <<
" tracks, " << usedHits <<
" hits\n\n";
323 cout <<
"Primary readings (shifts from means, dZ/phi/theta/psi from X-residual):\n";
324 cout <<
" " << left << setw(8) <<
"det_idx" << setw(10) <<
"det_id" << setw(22) <<
"element";
325 cout << right << setw(11) <<
"samples";
328 cout << setw(13) <<
"RMS(rx)" << setw(13) <<
"RMS(ry)" <<
"\n";
329 for (
Int_t d = 0; d < nDet; d++) {
330 cout <<
" " << left << setw(8) << d << setw(10) << detModel.
EncodedID(d) << setw(22)
332 cout << right << setw(11) << acc[d].x[
P_dX].line.N();
333 cout << fixed << setprecision(6);
338 cout << setw(13) << acc[d].x[
P_dX].RmsY() << setw(13) << acc[d].y[
P_dY].RmsY() <<
"\n";
342 cout <<
"\nAlternative readings (dZ/phi/theta/psi from Y-residual):\n";
343 cout <<
" " << left << setw(8) <<
"det_idx" << setw(10) <<
"det_id" << setw(22) <<
"element" << right;
347 for (
Int_t d = 0; d < nDet; d++) {
348 cout <<
" " << left << setw(8) << d << setw(10) << detModel.
EncodedID(d) << setw(22)
350 cout << right << fixed << setprecision(6);
360 gStyle->SetOptStat(
"emr");
363 "canvas",
"BM@N histogramming",
RES_X,
RES_Y);
367 auto show = [&](
Int_t idx) {
368 const DetAcc& da{acc[idx]};
372 cout <<
"\nExtracted corrections for detector " << idx <<
" (id " << detModel.
EncodedID(idx) <<
", "
374 cout << fixed << setprecision(6);
375 cout <<
" " << left << setw(7) <<
"dX" <<
" = " << right << setw(11) << da.
x[
P_dX].Value(
P_dX,
PARAM_SIGN_X)
377 cout <<
" " << left << setw(7) <<
"dY" <<
" = " << right << setw(11) << da.
y[
P_dY].Value(
P_dY,
PARAM_SIGN_Y)
380 cout <<
" " << left << setw(7) <<
PARAM_NAMES[p] << right <<
" X: " << setw(11)
381 << da.
x[p].Value(p,
PARAM_SIGN_X) <<
" +/- " << setw(9) << da.
x[p].Error(p) <<
" Y: " << setw(11)
382 << da.
y[p].Value(p,
PARAM_SIGN_Y) <<
" +/- " << setw(9) << da.
y[p].Error(p) <<
"\n";
393 pPads[
i][j] =
new TPad(
Form(
"pad%u%u",
i, j),
Form(
"pad%u%u",
i, j), padW * j, padH *
i, padW * (j + 1),
403 std::vector<Panel> panels;
404 panels.push_back({0, 0,
P_dX,
kTRUE,
kFALSE,
kFALSE, &dd.
rx,
nullptr,
RESIDUAL_RANGE_X,
PARAM_DIAG[
P_dX],
406 panels.push_back({0, 1,
P_dY,
kTRUE,
kTRUE,
kFALSE, &dd.
ry,
nullptr,
RESIDUAL_RANGE_Y,
PARAM_DIAG[
P_dY],
408 for (
Int_t c = 0; c < 4; c++) {
416 panels.push_back({2, c, p,
kFALSE,
kFALSE,
kTRUE, &dd.
rx, covX[c],
RESIDUAL_RANGE_X,
PARAM_DIAG[p],
423 for (
const Panel& pn : panels) {
424 pPads[
PADS_Y - 1 - pn.row][pn.col]->
cd();
425 const char* tag{pn.isShift ?
"" : (pn.isY ?
" (Y)" :
" (X)")};
426 const char* suff{pn.isY ?
"y" :
"x"};
427 const char* axis{pn.isY ?
"Y" :
"X"};
435 Form(
"%s%s = %+.5f #pm %.5f",
PARAM_NAMES[pn.p], tag, pn.a->Value(pn.p, pn.sign), pn.a->Error(pn.p)));
475 lo - margin, hi + margin,
RESIDUAL_BINS, -pn.resRange, pn.resRange);
477 for (std::size_t
i = 0;
i < cov.size();
i++)
479 h2->
Fit(
"pol1",
"Q");
481 fit->SetLineColor(
kRed);
482 fit->SetLineWidth(2);
489 Form(
"%s;%s;#LT %s residual #GT, cm", pn.diag, pn.covTitle, axis),
492 for (std::size_t
i = 0;
i < cov.size();
i++)
497 pr->
Fit(
"pol1",
"Q");
509 if (pdfPath && pdfPath[0])
515 if (!
gROOT->IsBatch() && isatty(STDIN_FILENO)) {
516 cout <<
"\n[ Right / Left arrows: next / previous detector | q: quit ]\n" << flush;
517 struct termios saved;
523 if (!
gROOT->GetListOfCanvases()->FindObject(pCnv))
526 if (read(STDIN_FILENO, &c, 1) <= 0) {
530 if (c ==
'q' || c ==
'Q') {
532 }
else if (c == 27) {
533 unsigned char a{0}, b{0};
535 if (read(STDIN_FILENO, &a, 1) <= 0) {
539 read(STDIN_FILENO, &b, 1);
540 if (a ==
'[' && b ==
'C')
541 drawDetIdx = (drawDetIdx + 1) % nDet;
542 else if (a ==
'[' && b ==
'D')
543 drawDetIdx = (drawDetIdx - 1 + nDet) % nDet;
std::vector< Double_t > VecDouble_t
TrackFilter_t BmnDefaultTrackFilter(Bool_t wholeTrackOnly=kTRUE)
HitFilter_t BmnDefaultHitFilter(const BmnDetectorModel &model)
char * Form(const char *fmt,...)
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
Bool_t EndOfTracks() const noexcept
Bool_t EndOfHits() const noexcept
Bool_t Initialized() const noexcept
Int_t EncodedID(Int_t idx) const
Bool_t Init(const char *targetGeoFile=nullptr)
Int_t Idx(Int_t ID) const
virtual Double_t HitY() const override
virtual void ResetAll() override
virtual Double_t HitWy() const override
virtual Int_t HitDetectorID() const override
virtual Double_t HitZ() const override
virtual Double_t HitX() const override
virtual Double_t HitWx() const override
virtual void ResetHits() override
virtual void NextTrack() override
virtual void NextHit() override
virtual std::string DecodeID(Int_t id) const override
virtual Int_t Alignables() const noexcept override
Double_t Det() const noexcept
Double_t At0() const noexcept
void Add(Double_t z, Double_t v, Double_t w=1.0) noexcept
Double_t Slope() const noexcept
virtual void SetFillColor(Color_t fcolor)
virtual void SetLineStyle(Style_t lstyle)
virtual void SetLineWidth(Width_t lwidth)
virtual void SetLineColor(Color_t lcolor)
virtual void SetMarkerColor(Color_t mcolor=1)
virtual void SetMarkerStyle(Style_t mstyle=1)
virtual void SetTextSize(Float_t tsize=1)
void Clear(Option_t *option="") override
TVirtualPad * cd(Int_t subpadnumber=0) override
void SetCanvasSize(UInt_t ww, UInt_t wh) override
void SetTitle(const char *title="") override
virtual Double_t GetMean(Int_t axis=1) const
static void AddDirectory(Bool_t add=kTRUE)
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
void Draw(Option_t *option="") override
virtual Int_t Fill(const char *name, Double_t w)
virtual TF1 * GetFunction(const char *name) const
virtual void SetStats(Bool_t stats=kTRUE)
virtual Int_t Fill(const char *namex, const char *namey, Double_t w)
virtual void Draw(Option_t *option="")
void SaveAs(const char *filename="", Option_t *option="") const override
TVirtualPad * cd(Int_t subpadnumber=0) override
void Draw(Option_t *option="") override
virtual TText * AddText(const char *label)
void Draw(Option_t *option="") override
Int_t Fill(const char *namex, Double_t y) override
static constexpr const char * PARAM_NAMES[PARAM_CNT]
static constexpr const char * PARAM_DIAG_Y[PARAM_CNT]
static constexpr const Double_t PARAM_SIGN_X[PARAM_CNT]
static constexpr const char * COV_TITLE_Y[PARAM_CNT]
static constexpr const char * PARAM_DIAG[PARAM_CNT]
static constexpr const char * COV_TITLE_X[PARAM_CNT]
int histo(const char *fileListPath="/home/igor/bmnroot/align_new/cfg/run8/7466.noa_rlerr.list", Int_t drawDetIdx=0, Int_t drawMode=DM_MIX, const char *pdfPath=nullptr)
Per-element histogramming estimate of the alignment corrections.
static constexpr const Double_t PARAM_SIGN_Y[PARAM_CNT]
static void histoSetRawMode(bool on, struct termios *saved)
static constexpr const Bool_t PARAM_IS_SHIFT[PARAM_CNT]
std::array< LinAcc, PARAM_CNT > y
std::array< LinAcc, PARAM_CNT > x
Double_t SlopeErr() const
Double_t Value(Int_t p, const Double_t *sign) const
Double_t MeanYErr() const
Double_t Error(Int_t p) const
void Add(Double_t x, Double_t y)