musrfit 1.12.1
PMusrT0.cpp
Go to the documentation of this file.
1/***************************************************************************
2
3 PMusrT0.cpp
4
5 Author: Andreas Suter
6 e-mail: andreas.suter@psi.ch
7
8***************************************************************************/
9
10/***************************************************************************
11 * Copyright (C) 2007-2026 by Andreas Suter *
12 * andreas.suter@psi.ch *
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program; if not, write to the *
26 * Free Software Foundation, Inc., *
27 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28 ***************************************************************************/
29
30#include <iostream>
31#include <fstream>
32
33#include <TColor.h>
34#include <TRandom.h>
35#include <TROOT.h>
36#include <TObjString.h>
37
38#include "PMusrT0.h"
39
40#include "icons/musrt0_icon.xpm"
41#ifdef __APPLE__
42#include "PMacDockIcon.h"
43#include "icons/musrt0_icon_png.h"
44#endif
45
46#define DETECTOR_TAG_FORWARD 0
47#define DETECTOR_TAG_BACKWARD 1
48
49//--------------------------------------------------------------------------
50// Constructor
51//--------------------------------------------------------------------------
61
62//--------------------------------------------------------------------------
63// Destructor
64//--------------------------------------------------------------------------
72{
73 fRawRunData.clear();
74 fHistoNo.clear();
75 fT0.clear();
76 for (UInt_t i=0; i<fAddT0.size(); i++)
77 fAddT0[i].clear();
78 fAddT0.clear();
79}
80
81//--------------------------------------------------------------------------
82// InitData
83//--------------------------------------------------------------------------
91{
92 fSingleHisto = true;
93 fRunNo = -1;
94 fAddRunIdx = -1;
95 fHistoNoIdx = -1;
96 fDetectorTag = -1;
97 fCmdTag = -1;
98 fRawRunData.clear();
99 fHistoNo.clear();
100 fT0.clear();
101 for (UInt_t i=0; i<fAddT0.size(); i++)
102 fAddT0[i].clear();
103 fAddT0.clear();
104 fT0Data = -1;
105}
106
107//--------------------------------------------------------------------------
108// GetRawRunData
109//--------------------------------------------------------------------------
117{
118 if ((idx < 0) || (idx >= static_cast<Int_t>(fRawRunData.size())))
119 return nullptr;
120
121 return fRawRunData[idx];
122}
123
124//--------------------------------------------------------------------------
125// GetHistoNo
126//--------------------------------------------------------------------------
133Int_t PMusrT0Data::GetHistoNo(UInt_t idx)
134{
135 if (idx >= fHistoNo.size())
136 return -1;
137
138 return fHistoNo[idx];
139}
140
141//--------------------------------------------------------------------------
142// GetT0Bin
143//--------------------------------------------------------------------------
150Int_t PMusrT0Data::GetT0Bin(UInt_t idx)
151{
152 if (idx >= fT0.size())
153 return -1;
154
155 return fT0[idx];
156}
157
158//--------------------------------------------------------------------------
159// GetAddT0BinSize
160//--------------------------------------------------------------------------
168{
169 if (idx >= fAddT0.size())
170 return 0;
171
172 return fAddT0[idx].size();
173}
174
175//--------------------------------------------------------------------------
176// GetAddT0Bin
177//--------------------------------------------------------------------------
185Int_t PMusrT0Data::GetAddT0Bin(UInt_t addRunIdx, UInt_t idx)
186{
187 if (addRunIdx >= fAddT0.size())
188 return -1;
189
190 if (idx >= fAddT0[addRunIdx].size())
191 return -1;
192
193 return fAddT0[addRunIdx][idx];
194}
195
196//--------------------------------------------------------------------------
197// SetT0Bin
198//--------------------------------------------------------------------------
207void PMusrT0Data::SetT0Bin(UInt_t val, UInt_t idx)
208{
209 if (idx >= fT0.size())
210 fT0.resize(idx+1);
211
212 fT0[idx] = val;
213}
214
215//--------------------------------------------------------------------------
216// SetAddT0Bin
217//--------------------------------------------------------------------------
227void PMusrT0Data::SetAddT0Bin(UInt_t val, UInt_t addRunIdx, UInt_t idx)
228{
229 if (addRunIdx >= fAddT0.size())
230 fAddT0.resize(addRunIdx+1);
231
232 if (idx >= fAddT0[addRunIdx].size())
233 fAddT0[addRunIdx].resize(idx+1);
234
235 fAddT0[addRunIdx][idx] = val;
236}
237
238//--------------------------------------------------------------------------
239
241
242//--------------------------------------------------------------------------
243// Constructor
244//--------------------------------------------------------------------------
252{
253 fTimeout = 0;
254
255 fValid = false;
256
257 fStatus = 0; // default is quit locally
258
259 fDataAndBkgEnabled = false;
260 fT0Enabled = false;
261 fShowT0DataChannel = false;
262
263 fDataRange[0] = 0;
264 fDataRange[1] = 0;
265 fBkgRange[0] = 0;
266 fBkgRange[1] = 0;
267}
268
269//--------------------------------------------------------------------------
270// Constructor
271//--------------------------------------------------------------------------
284{
285 fTimeout = 0;
286
287 fValid = true;
288
289 fStatus = 0; // default is quit locally
290
291 fDataAndBkgEnabled = false;
292 fT0Enabled = false;
293 fShowT0DataChannel = false;
294
295 fDataRange[0] = 0;
296 fDataRange[1] = 0;
297 fBkgRange[0] = 0;
298 fBkgRange[1] = 0;
299
300 // feed necessary objects
301 TString str;
302
303 if ((fMusrT0Data.GetCmdTag() == PMUSRT0_GET_T0) || (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_T0_DATA_AND_BKG_RANGE)) {
304 str = *fMusrT0Data.GetRawRunData(fMusrT0Data.GetAddRunIdx())->GetRunName() + TString(" : ");
305 str += fMusrT0Data.GetHistoNo(fMusrT0Data.GetHistoNoIdx());
306 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
307 str += " (f)";
308 else
309 str += " (b)";
310 str += ", msr runNo = ";
311 str += fMusrT0Data.GetRunNo()+1;
312
313
314 // feed raw data histo
315 PRawRunData *rawRunData = fMusrT0Data.GetRawRunData(fMusrT0Data.GetAddRunIdx());
316 if (rawRunData == nullptr) {
317 fValid = false;
318 return;
319 }
320 Int_t histoNo = fMusrT0Data.GetHistoNo(fMusrT0Data.GetHistoNoIdx());
321 if (!rawRunData->IsPresent(histoNo)) {
322 std::cerr << std::endl << ">> PMusrT0::PMusrT0: **ERROR** found histogram number " << histoNo+1 << " which is NOT present in the data file.";
323 std::cerr << std::endl << ">> Please try to fix this first ..." << std::endl;
324 fValid = false;
325 return;
326 }
327 Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size();
328 Double_t start = -0.5;
329 Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0
330 fHisto = std::make_unique<TH1F>("fHisto", str.Data(), noOfBins, start, end);
331 fHisto->SetMarkerStyle(21);
332 fHisto->SetMarkerSize(0.5);
333 fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black
334
335 Double_t maxVal = 0.0;
336 fT0Estimated = 0;
337 for (UInt_t i=0; i<rawRunData->GetDataBin(histoNo)->size(); i++) {
338 fHisto->SetBinContent(i+1, rawRunData->GetDataBin(histoNo)->at(i));
339 if (rawRunData->GetDataBin(histoNo)->at(i) > maxVal) {
340 maxVal = rawRunData->GetDataBin(histoNo)->at(i);
341 fT0Estimated = i;
342 }
343 }
344 } else {
345 str = *fMusrT0Data.GetRawRunData(0)->GetRunName() + TString(" : ");
346 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
347 str += " forward grouped and runs added";
348 else
349 str += " backward grouped and runs added";
350 str += ", msr runNo = ";
351 str += fMusrT0Data.GetRunNo()+1;
352
353 // feed raw data histo
354 PRawRunData *rawRunData = fMusrT0Data.GetRawRunData(0);
355 if (rawRunData == nullptr) {
356 fValid = false;
357 return;
358 }
359
360 // get run and first histo of grouping and feed it into fHisto
361 Int_t histoNo = fMusrT0Data.GetHistoNo(0);
362 Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size();
363 Double_t start = -0.5;
364 Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0
365 fHisto = std::make_unique<TH1F>("fHisto", str.Data(), noOfBins, start, end);
366 fHisto->SetMarkerStyle(21);
367 fHisto->SetMarkerSize(0.5);
368 fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black
369
370 // sum up all necessary histograms by taking care of the proper t0's
371 Int_t t00;
372 Int_t t0;
373 Double_t dval;
374
375 // check if asymmetry fit
376 UInt_t factor=1;
377 if (!fMusrT0Data.IsSingleHisto())
378 factor=2;
379
380 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
381 t00 = fMusrT0Data.GetT0Bin(0);
382 else
383 t00 = fMusrT0Data.GetT0Bin(1);
384
385 // check if there are addruns and grouping
386 if ((fMusrT0Data.GetRawRunDataSize() > 1) && (fMusrT0Data.GetHistoNoSize() > 1)) { // addruns and grouping present
387
388 for (Int_t i=0; i<noOfBins; i++) { // loop over all entries in fHisto
389
390 dval = 0;
391
392 for (UInt_t k=0; k<fMusrT0Data.GetHistoNoSize(); k++) { // loop over all histograms (grouping)
393
394 histoNo = fMusrT0Data.GetHistoNo(k);
395
396 // get t0
397 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
398 t0 = fMusrT0Data.GetT0Bin(factor*k);
399 else
400 t0 = fMusrT0Data.GetT0Bin(factor*k+1);
401
402 // get proper rawRunData
403 rawRunData = fMusrT0Data.GetRawRunData(0);
404
405 // get bin value from run/grouping
406 if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
407 dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
408
409 for (UInt_t j=1; j<fMusrT0Data.GetRawRunDataSize(); j++) { // loop over all potential addruns
410
411 rawRunData = fMusrT0Data.GetRawRunData(j);
412
413 // get t0
414 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
415 t0 = fMusrT0Data.GetAddT0Bin(j-1, factor*k);
416 else
417 t0 = fMusrT0Data.GetAddT0Bin(j-1, factor*k+1);
418
419 // get bin value from addrun/grouping
420 if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
421 dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
422 }
423 }
424 // set bin value of fHisto
425 fHisto->SetBinContent(i+1, dval);
426 }
427
428 } else if (fMusrT0Data.GetRawRunDataSize() > 1) { // only addruns present
429
430 for (Int_t i=0; i<noOfBins; i++) { // loop over all entries in fHisto
431
432 dval = 0;
433
434 histoNo = fMusrT0Data.GetHistoNo(0);
435
436 // get t0
437 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
438 t0 = fMusrT0Data.GetT0Bin(0);
439 else
440 t0 = fMusrT0Data.GetT0Bin(1);
441
442 // get proper rawRunData
443 rawRunData = fMusrT0Data.GetRawRunData(0);
444
445 // get bin value from run/grouping
446 if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
447 dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
448
449 for (UInt_t j=1; j<fMusrT0Data.GetRawRunDataSize(); j++) { // loop over all potential addruns
450
451 // get proper rawRunData
452 rawRunData = fMusrT0Data.GetRawRunData(j);
453
454 // get t0
455 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
456 t0 = fMusrT0Data.GetAddT0Bin(j-1, 0);
457 else
458 t0 = fMusrT0Data.GetAddT0Bin(j-1, 1);
459
460 // get bin value from addrun/grouping
461 if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
462 dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
463 }
464 // set bin value of fHisto
465 fHisto->SetBinContent(i+1, dval);
466 }
467
468 } else if (fMusrT0Data.GetHistoNoSize() > 1) { // only grouping persent
469
470 for (Int_t i=0; i<noOfBins; i++) { // loop over all entries in fHisto
471
472 dval = 0;
473
474 // get proper rawRunData
475 rawRunData = fMusrT0Data.GetRawRunData(0);
476
477 for (UInt_t k=0; k<fMusrT0Data.GetHistoNoSize(); k++) { // loop over all histograms (grouping)
478
479 histoNo = fMusrT0Data.GetHistoNo(k);
480
481 // get t0
482 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
483 t0 = fMusrT0Data.GetT0Bin(factor*k);
484 else
485 t0 = fMusrT0Data.GetT0Bin(factor*k+1);
486
487 // get bin value from run/grouping
488 if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
489 dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
490
491 }
492 // set bin value of fHisto
493 fHisto->SetBinContent(i+1, dval);
494 }
495
496 }
497 }
498
499 // generate canvas etc
500 fMainCanvas = std::make_unique<TCanvas>("fMainCanvas", str);
501 fMainCanvas->SetFillColor(TColor::GetColor(255,255,255));
502
503 // replace the generic ROOT window icon; the class hint lets the desktop match musrt0.desktop
504 TRootCanvas *imp = dynamic_cast<TRootCanvas*>(fMainCanvas->GetCanvasImp());
505 if (imp) {
506 imp->SetIconPixmap(const_cast<char**>(musrt0_icon_xpm));
507 imp->SetClassHints("musrt0", "musrt0");
508 }
509#ifdef __APPLE__
510 // on macOS, TGCocoa::SetIconPixmap()/SetClassHints() above are no-ops: the Dock icon
511 // is process-wide and must be set via NSApplication instead
512 SetMacDockIcon(musrt0_icon_png, musrt0_icon_png_len);
513#endif
514
515 fMainCanvas->Show();
516
517 fMainCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "PMusrT0",
518 this, "HandleCmdKey(Int_t,Int_t,Int_t,TObject*)");
519 fMainCanvas->Connect("Closed()", "PMusrT0", this, "Quit()");
520
521 if (fMusrT0Data.GetCmdTag() != PMUSRT0_GET_T0)
522 fDataAndBkgEnabled = true;
523 else
524 fDataAndBkgEnabled = false;
525
526 if (fMusrT0Data.GetCmdTag() != PMUSRT0_GET_DATA_AND_BKG_RANGE)
527 fT0Enabled = true;
528 else
529 fT0Enabled = false;
530
531 // do not show root statistics block
532 fHisto->SetStats(kFALSE);
533
534 // draw histos etc
535 fHisto->Draw("p0 9 hist");
536
537 if (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_T0) {
538 str = "please set t0 bin only.";
539 fToDoInfo = std::make_unique<TLatex>();
540 fToDoInfo->SetTextFont(51);
541 fToDoInfo->SetTextSize(0.030);
542 fToDoInfo->SetLineWidth(2);
543 fToDoInfo->SetNDC(kTRUE);
544 fToDoInfo->DrawLatex(0.1, 0.91, str.Data());
545 }
546 if (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_DATA_AND_BKG_RANGE) {
547 str = "please set data and bkg range.";
548 fToDoInfo = std::make_unique<TLatex>();
549 fToDoInfo->SetTextFont(51);
550 fToDoInfo->SetTextSize(0.030);
551 fToDoInfo->SetLineWidth(2);
552 fToDoInfo->SetNDC(kTRUE);
553 fToDoInfo->DrawLatex(0.1, 0.91, str.Data());
554 }
555}
556
557//--------------------------------------------------------------------------
558// Done (SIGNAL)
559//--------------------------------------------------------------------------
569{
570 Emit("Done(Int_t)", status);
571}
572
573//--------------------------------------------------------------------------
574// HandleCmdKey (SLOT)
575//--------------------------------------------------------------------------
601void PMusrT0::HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected)
602{
603 if (event != kKeyPress) {
604 fPx = x;
605 fPy = y;
606 return;
607 }
608
609 // handle keys and popup menu entries
610 if (x == 'q') { // quit
611 fStatus = 0; // will quit locally
612 Done(0);
613 } else if (x == 'Q') { // terminate musrt0
614 fStatus = 1; // will quit globally
615 Done(0);
616 } else if (x == 'u') { // unzoom to the original range
617 UnZoom();
618 } else if (x == 'z') { // zoom to the region around t0, and the estimated t0
619 ZoomT0();
620 } else if (x == 's') { // show the t0 of the data file (if present)
624 else
626 } else if (x == 'T') { // set estimated t0 channel
628 } else if (x == 't') { // set t0 channel
629 SetT0Channel();
630 } else if (x == 'b') { // set first background channel
632 } else if (x == 'B') { // set last background channel
634 } else if (x == 'd') { // set first data channel
636 } else if (x == 'D') { // set last data channel
638 }
639}
640
641//--------------------------------------------------------------------------
642// Quit (public)
643//--------------------------------------------------------------------------
651{
652 fStatus = 2; // will quit globally
653 Done(0);
654}
655
656//--------------------------------------------------------------------------
657// SetTimeout (public)
658//--------------------------------------------------------------------------
668{
670
671 if (fTimeout <= 0)
672 return;
673
674 fTimeoutTimer.reset(new TTimer());
675
676 fTimeoutTimer->Connect("Timeout()", "PMusrT0", this, "Quit()");
677
678 fTimeoutTimer->Start(1000*fTimeout, kTRUE);
679}
680
681//--------------------------------------------------------------------------
682// SetMsrHandler
683//--------------------------------------------------------------------------
693{
694 fMsrHandler = msrHandler;
695}
696
697//--------------------------------------------------------------------------
698// InitT0
699//--------------------------------------------------------------------------
709{
710 // t0 line
711 Double_t t0Bin = 0;
712 Int_t histoIdx = fMusrT0Data.GetHistoNoIdx();
713 Int_t addRunIdx = fMusrT0Data.GetAddRunIdx();
714 UInt_t factor=1;
715 if (!fMusrT0Data.IsSingleHisto())
716 factor=2;
717 switch (fMusrT0Data.GetDetectorTag() ) {
718 case PMUSRT0_FORWARD:
719 if (addRunIdx == 0)
720 t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetT0Bin(factor*histoIdx);
721 else if (addRunIdx > 0)
722 t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetAddT0Bin(addRunIdx-1, factor*histoIdx);
723 break;
724 case PMUSRT0_BACKWARD:
725 if (addRunIdx == 0)
726 t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetT0Bin(factor*histoIdx+1);
727 else if (addRunIdx > 0)
728 t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetAddT0Bin(addRunIdx-1, factor*histoIdx+1);
729 break;
730 default:
731 // not clear yet what to be done
732 break;
733 }
734 Double_t max = fHisto->GetMaximum();
735
736 fT0Line = std::make_unique<TLine>((Double_t)t0Bin, 0.0, (Double_t)t0Bin, max);
737 fT0Line->SetLineStyle(1); // solid
738 fT0Line->SetLineColor(TColor::GetColor(0,255,0)); // green
739 fT0Line->SetLineWidth(2);
740 fT0Line->Draw();
741}
742
743//--------------------------------------------------------------------------
744// InitDataAndBkg
745//--------------------------------------------------------------------------
757{
758 // feed data range histo
759 switch (fMusrT0Data.GetDetectorTag()) {
760 case PMUSRT0_FORWARD:
761 fDataRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(0);
762 fDataRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(1);
763 break;
764 case PMUSRT0_BACKWARD:
765 fDataRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(2);
766 fDataRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(3);
767 break;
768 default:
769 // not clear yet what to be done
770 break;
771 }
772
773 Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
774 Double_t start = fDataRange[0] - 0.5;
775 Double_t end = fDataRange[1] + 0.5;
776 fData = std::make_unique<TH1F>("fData", "fData", noOfBins, start, end);
777 fData->SetMarkerStyle(21);
778 fData->SetMarkerSize(0.5);
779 fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
780
781 for (Int_t i=0; i<noOfBins; i++) {
782 fData->SetBinContent(i+1, fHisto->GetBinContent(fDataRange[0]+i+1));
783 }
784 fData->Draw("p0 9 hist same");
785
786 // feed background histo
787 switch (fMusrT0Data.GetDetectorTag()) {
788 case PMUSRT0_FORWARD:
789 fBkgRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(0);
790 fBkgRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(1);
791 break;
792 case PMUSRT0_BACKWARD:
793 fBkgRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(2);
794 fBkgRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(3);
795 break;
796 default:
797 // not clear yet what to be done
798 break;
799 }
800
801 noOfBins = fBkgRange[1]-fBkgRange[0]+1;
802 start = fBkgRange[0] - 0.5;
803 end = fBkgRange[1] + 0.5;
804 fBkg = std::make_unique<TH1F>("fBkg", "fBkg", noOfBins, start, end);
805 fBkg->SetMarkerStyle(21);
806 fBkg->SetMarkerSize(0.5);
807 fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red
808
809 for (Int_t i=0; i<noOfBins; i++) {
810 fBkg->SetBinContent(i+1, fHisto->GetBinContent(fBkgRange[0]+i+1));
811 }
812 fBkg->Draw("p0 9 hist same");
813
814 // add lines
815 Double_t max = fHisto->GetMaximum();
816
817 // data lines
818 fFirstDataLine = std::make_unique<TLine>(static_cast<Double_t>(fDataRange[0]), 0.0, static_cast<Double_t>(fDataRange[0]), max);
819 fFirstDataLine->SetLineStyle(3); // doted
820 fFirstDataLine->SetLineColor(TColor::GetColor(0,0,255)); // blue
821 fFirstDataLine->SetLineWidth(2);
822 fFirstDataLine->Draw();
823
824 fLastDataLine = std::make_unique<TLine>(static_cast<Double_t>(fDataRange[1]), 0.0, static_cast<Double_t>(fDataRange[1]), max);
825 fLastDataLine->SetLineStyle(3); // doted
826 fLastDataLine->SetLineColor(TColor::GetColor(0,0,255)); // blue
827 fLastDataLine->SetLineWidth(2);
828 fLastDataLine->Draw();
829
830 // bkg lines
831 fFirstBkgLine = std::make_unique<TLine>(static_cast<Double_t>(fBkgRange[0]), 0.0, static_cast<Double_t>(fBkgRange[0]), max);
832 fFirstBkgLine->SetLineStyle(6); // _..._...
833 fFirstBkgLine->SetLineColor(TColor::GetColor(255,0,0)); // red
834 fFirstBkgLine->SetLineWidth(2);
835 fFirstBkgLine->Draw();
836
837 fLastBkgLine = std::make_unique<TLine>(static_cast<Double_t>(fBkgRange[1]), 0.0, static_cast<Double_t>(fBkgRange[1]), max);
838 fLastBkgLine->SetLineStyle(6); // _..._...
839 fLastBkgLine->SetLineColor(TColor::GetColor(255,0,0)); // red
840 fLastBkgLine->SetLineWidth(2);
841 fLastBkgLine->Draw();
842
843 fMainCanvas->Update();
844}
845
846//--------------------------------------------------------------------------
847// ShowDataFileT0Channel
848//--------------------------------------------------------------------------
856{
857 // t0 line
858 Int_t t0Bin = fMusrT0Data.GetT0BinData();
859 Double_t max = fHisto->GetMaximum();
860
861 if (!fT0DataLine) {
862 fT0DataLine = std::make_unique<TLine>(static_cast<Double_t>(t0Bin), 0.0, static_cast<Double_t>(t0Bin), max);
863 fT0DataLine->SetLineStyle(1); // solid
864 fT0DataLine->SetLineColor(kOrange-3);
865 fT0DataLine->SetLineWidth(2);
866 fT0DataLine->Draw();
867 }
868
869 fMainCanvas->Update();
870}
871
872//--------------------------------------------------------------------------
873// HideDataFileT0Channel
874//--------------------------------------------------------------------------
882{
883 if (fT0DataLine) {
884 fT0DataLine.reset();
885 }
886 fMainCanvas->Update();
887}
888
889//--------------------------------------------------------------------------
890// SetT0Channel
891//--------------------------------------------------------------------------
900{
901 if (!fT0Enabled)
902 return;
903
904 Double_t x=0, y=0;
905 fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
906
907 // get binx to set t0 corresponding to fPx
908 Int_t binx = fHisto->GetXaxis()->FindFixBin(x) - 1;
909
910 std::cout << std::endl << ">> PMusrT0::SetT0Channel(): t0 = " << binx << std::endl;
911
912 // set t0 bin in msr-Handler
913 UInt_t idx;
914 if (fMusrT0Data.IsSingleHisto()) {
915 idx = fMusrT0Data.GetHistoNoIdx();
916 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
917 idx += 1;
918 } else {
919 idx = 2*fMusrT0Data.GetHistoNoIdx();
920 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
921 idx += 1;
922 }
923
924 if (fMusrT0Data.GetAddRunIdx() == 0)
925 fMsrHandler->SetMsrT0Entry(fMusrT0Data.GetRunNo(), idx, binx);
926 else if (fMusrT0Data.GetAddRunIdx() > 0)
927 fMsrHandler->SetMsrAddT0Entry(fMusrT0Data.GetRunNo(), fMusrT0Data.GetAddRunIdx()-1, idx, binx);
928
929 // shift line to the proper position
930 fT0Line->SetX1(x);
931 fT0Line->SetX2(x);
932
933 fMainCanvas->Modified(); // needed that Update is actually working
934 fMainCanvas->Update();
935}
936
937//--------------------------------------------------------------------------
938// SetEstimatedT0Channel
939//--------------------------------------------------------------------------
948{
949 if (!fT0Enabled)
950 return;
951
952 // set t0 bin in msr-Handler
953 UInt_t idx;
954 if (fMusrT0Data.IsSingleHisto()) {
955 idx = fMusrT0Data.GetHistoNoIdx();
956 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
957 idx += 1;
958 } else {
959 idx = 2*fMusrT0Data.GetHistoNoIdx();
960 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
961 idx += 1;
962 }
963
964 if (fMusrT0Data.GetAddRunIdx() == 0)
965 fMsrHandler->SetMsrT0Entry(fMusrT0Data.GetRunNo(), idx, fT0Estimated);
966 else if (fMusrT0Data.GetAddRunIdx() > 0)
967 fMsrHandler->SetMsrAddT0Entry(fMusrT0Data.GetRunNo(), fMusrT0Data.GetAddRunIdx()-1, idx, fT0Estimated);
968
969 Double_t x = fHisto->GetXaxis()->GetBinCenter(fT0Estimated)+1.0; // +1.0 needed since the first bin == 1 not 0.
970
971 std::cout << std::endl << ">> PMusrT0::SetEstimatedT0Channel(): estimated t0 = " << fT0Estimated << std::endl;
972
973 // shift line to the proper position
974 fT0Line->SetX1(x);
975 fT0Line->SetX2(x);
976
977 fMainCanvas->Modified(); // needed that Update is actually working
978 fMainCanvas->Update();
979}
980
981//--------------------------------------------------------------------------
982// SetDataFirstChannel
983//--------------------------------------------------------------------------
992{
994 return;
995
996 Double_t x=0, y=0;
997 fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
998
999 // get binx to set the data first channel corresponding to fPx
1000 fDataRange[0] = fHisto->GetXaxis()->FindFixBin(x) - 1;
1001
1002 std::cout << std::endl << ">> PMusrT0::SetDataFirstChannel(): fDataRange[0] = " << fDataRange[0] << std::endl;
1003
1004 // set the data first bin in msr-Handler
1005 UInt_t idx = 0;
1006 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
1007 idx = 2;
1008 fMsrHandler->SetMsrDataRangeEntry(fMusrT0Data.GetRunNo(), idx, fDataRange[0]);
1009
1010 // shift line to the proper position
1011 fFirstDataLine->SetX1(x);
1012 fFirstDataLine->SetX2(x);
1013
1014 // refill data histo
1015 Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
1016 Double_t start = fDataRange[0] - 0.5;
1017 Double_t end = fDataRange[1] + 0.5;
1018 fData.reset(new TH1F("fData", "fData", noOfBins, start, end));
1019 fData->SetMarkerStyle(21);
1020 fData->SetMarkerSize(0.5);
1021 fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
1022 for (Int_t i=0; i<noOfBins; i++) {
1023 fData->SetBinContent(i+1, fHisto->GetBinContent(fDataRange[0]+i+1));
1024 }
1025 fData->Draw("p0 9 hist same");
1026
1027 fMainCanvas->Modified(); // needed that Update is actually working
1028 fMainCanvas->Update();
1029}
1030
1031//--------------------------------------------------------------------------
1032// SetDataLastChannel
1033//--------------------------------------------------------------------------
1042{
1043 if (!fDataAndBkgEnabled)
1044 return;
1045
1046 Double_t x=0, y=0;
1047 fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
1048
1049 // get binx to set the data last channel corresponding to fPx
1050 fDataRange[1] = fHisto->GetXaxis()->FindFixBin(x) - 1;
1051
1052 std::cout << std::endl << ">> PMusrT0::SetDataLastChannel(): fDataRange[1] = " << fDataRange[1] << std::endl;
1053
1054 // set the data first bin in msr-Handler
1055 UInt_t idx = 1;
1056 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
1057 idx = 3;
1058 fMsrHandler->SetMsrDataRangeEntry(fMusrT0Data.GetRunNo(), idx, fDataRange[1]);
1059
1060 // shift line to the proper position
1061 fLastDataLine->SetX1(x);
1062 fLastDataLine->SetX2(x);
1063
1064 // refill data histo
1065 Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
1066 Double_t start = fDataRange[0] - 0.5;
1067 Double_t end = fDataRange[1] + 0.5;
1068 fData.reset(new TH1F("fData", "fData", noOfBins, start, end));
1069 fData->SetMarkerStyle(21);
1070 fData->SetMarkerSize(0.5);
1071 fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
1072 for (Int_t i=0; i<noOfBins; i++) {
1073 fData->SetBinContent(i+1, fHisto->GetBinContent(fDataRange[0]+i+1));
1074 }
1075 fData->Draw("p0 9 hist same");
1076
1077 fMainCanvas->Modified(); // needed that Update is actually working
1078 fMainCanvas->Update();
1079}
1080
1081//--------------------------------------------------------------------------
1082// SetBkgFirstChannel
1083//--------------------------------------------------------------------------
1092{
1093 if (!fDataAndBkgEnabled)
1094 return;
1095
1096 Double_t x=0, y=0;
1097 fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
1098
1099 // get binx to set the background first channel corresponding to fPx
1100 fBkgRange[0] = fHisto->GetXaxis()->FindFixBin(x) - 1;
1101
1102 std::cout << std::endl << ">> PMusrT0::SetBkgFirstChannel(): fBkgRange[0] = " << fBkgRange[0] << std::endl;
1103
1104 // set the background first bin in msr-Handler
1105 UInt_t idx = 0;
1106 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
1107 idx = 2;
1108 fMsrHandler->SetMsrBkgRangeEntry(fMusrT0Data.GetRunNo(), idx, fBkgRange[0]);
1109
1110 // shift line to the proper position
1111 fFirstBkgLine->SetX1(x);
1112 fFirstBkgLine->SetX2(x);
1113
1114 // refill data histo
1115 Int_t noOfBins = fBkgRange[1]-fBkgRange[0]+1;
1116 Double_t start = fBkgRange[0] - 0.5;
1117 Double_t end = fBkgRange[1] + 0.5;
1118 fBkg.reset(new TH1F("fBkg", "fBkg", noOfBins, start, end));
1119 fBkg->SetMarkerStyle(21);
1120 fBkg->SetMarkerSize(0.5);
1121 fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red
1122 for (Int_t i=0; i<noOfBins; i++) {
1123 fBkg->SetBinContent(i+1, fHisto->GetBinContent(fBkgRange[0]+i+1));
1124 }
1125 fBkg->Draw("p0 9 hist same");
1126
1127 fMainCanvas->Modified(); // needed that Update is actually working
1128 fMainCanvas->Update();
1129}
1130
1131//--------------------------------------------------------------------------
1132// SetBkgLastChannel
1133//--------------------------------------------------------------------------
1142{
1143 if (!fDataAndBkgEnabled)
1144 return;
1145
1146 Double_t x=0, y=0;
1147 fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
1148
1149 // get binx to set the background last channel corresponding to fPx
1150 fBkgRange[1] = fHisto->GetXaxis()->FindFixBin(x) - 1;
1151
1152 std::cout << std::endl << ">> PMusrT0::SetBkgLastChannel(): fBkgRange[1] = " << fBkgRange[1] << std::endl;
1153
1154 // set the background first bin in msr-Handler
1155 UInt_t idx = 1;
1156 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
1157 idx = 3;
1158 fMsrHandler->SetMsrBkgRangeEntry(fMusrT0Data.GetRunNo(), idx, fBkgRange[1]);
1159
1160 // shift line to the proper position
1161 fLastBkgLine->SetX1(x);
1162 fLastBkgLine->SetX2(x);
1163
1164 // refill data histo
1165 Int_t noOfBins = fBkgRange[1]-fBkgRange[0]+1;
1166 Double_t start = fBkgRange[0] - 0.5;
1167 Double_t end = fBkgRange[1] + 0.5;
1168 fBkg.reset(new TH1F("fBkg", "fBkg", noOfBins, start, end));
1169 fBkg->SetMarkerStyle(21);
1170 fBkg->SetMarkerSize(0.5);
1171 fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red
1172 for (Int_t i=0; i<noOfBins; i++) {
1173 fBkg->SetBinContent(i+1, fHisto->GetBinContent(fBkgRange[0]+i+1));
1174 }
1175 fBkg->Draw("p0 9 hist same");
1176
1177 fMainCanvas->Modified(); // needed that Update is actually working
1178 fMainCanvas->Update();
1179}
1180
1181//--------------------------------------------------------------------------
1182// UnZoom
1183//--------------------------------------------------------------------------
1191{
1192 fHisto->GetXaxis()->UnZoom();
1193 fHisto->GetYaxis()->UnZoom();
1194
1195 fMainCanvas->Modified(); // needed that Update is actually working
1196 fMainCanvas->Update();
1197}
1198
1199//--------------------------------------------------------------------------
1200// ZoomT0
1201//--------------------------------------------------------------------------
1210{
1211 if (!fT0Enabled)
1212 return;
1213
1214 const Int_t range = 75;
1215
1216 // get current t0 position
1217 Double_t t0x = fT0Line->GetX1();
1218 Int_t t0 = fHisto->GetXaxis()->FindBin(t0x)-1;
1219
1220 Int_t min = t0 - range;
1221 Int_t max = t0 + range;
1222
1223 // check if t0 is defined at all
1224 if (t0 <= 0) {
1225 min = fT0Estimated - range;
1226 max = fT0Estimated + range;
1227 }
1228
1229 if (fT0Estimated < min) {
1230 min = fT0Estimated - range;
1231 }
1232 if (fT0Estimated > max) {
1233 max = fT0Estimated + range;
1234 }
1235
1236 fHisto->GetXaxis()->SetRangeUser(min, max);
1237
1238 fMainCanvas->Modified(); // needed that Update is actually working
1239 fMainCanvas->Update();
1240}
1241
1242//--------------------------------------------------------------------------
1243// END
1244//--------------------------------------------------------------------------
ClassImpQ(PMusrT0) PMusrT0
Default constructor that creates an invalid PMusrT0 instance.
Definition PMusrT0.cpp:240
#define PMUSRT0_GET_DATA_AND_BKG_RANGE
Mode: Determine data and background ranges only.
Definition PMusrT0.h:61
#define PMUSRT0_BACKWARD
Backward detector tag.
Definition PMusrT0.h:55
#define PMUSRT0_GET_T0
Mode: Determine t0 only.
Definition PMusrT0.h:60
#define PMUSRT0_GET_T0_DATA_AND_BKG_RANGE
Mode: Determine t0, data range, and background range.
Definition PMusrT0.h:62
#define PMUSRT0_FORWARD
Forward detector tag.
Definition PMusrT0.h:54
if(xmlFile.is_open())
return status
MSR file parser and manager for the musrfit framework.
Data container for musrt0 raw run data and histogram information.
Definition PMusrT0.h:82
virtual Int_t GetHistoNo(UInt_t idx)
Returns histogram number at given index.
Definition PMusrT0.cpp:133
PIntVector fT0
t0 bin values for main run histograms
Definition PMusrT0.h:157
virtual Int_t GetAddT0Bin(UInt_t addRunIdx, UInt_t idx)
Returns t0 bin for specific addrun and histogram.
Definition PMusrT0.cpp:185
Int_t fHistoNoIdx
Current histogram number index.
Definition PMusrT0.h:153
PMusrT0Data()
Default constructor.
Definition PMusrT0.cpp:57
virtual void InitData()
Initializes data structures (currently empty implementation).
Definition PMusrT0.cpp:90
std::vector< PRawRunData * > fRawRunData
Raw data: index 0 = main run, index >0 = addruns.
Definition PMusrT0.h:150
virtual Int_t GetT0Bin(UInt_t idx)
Returns t0 bin value at given index.
Definition PMusrT0.cpp:150
virtual void SetAddT0Bin(UInt_t val, UInt_t addRunIdx, UInt_t idx)
Sets t0 bin value for specific addrun and index.
Definition PMusrT0.cpp:227
virtual ~PMusrT0Data()
Destructor.
Definition PMusrT0.cpp:71
std::vector< PIntVector > fAddT0
t0 bin values for addrun histograms
Definition PMusrT0.h:158
PIntVector fHistoNo
Histogram numbers (with Red/Green offset applied).
Definition PMusrT0.h:154
virtual UInt_t GetAddT0BinSize(UInt_t idx)
Returns number of t0 bins for given addrun.
Definition PMusrT0.cpp:167
virtual PRawRunData * GetRawRunData(Int_t idx)
Returns raw run data for given index (0=main run, >0=addruns).
Definition PMusrT0.cpp:116
Int_t fT0Data
t0 bin found in current data file
Definition PMusrT0.h:159
Int_t fRunNo
MSR file run block number.
Definition PMusrT0.h:151
Int_t fCmdTag
Mode: 0=t0 only, 1=ranges only, 2=both t0 and ranges.
Definition PMusrT0.h:156
Int_t fAddRunIdx
Current addrun index being processed.
Definition PMusrT0.h:152
virtual void SetT0Bin(UInt_t val, UInt_t idx)
Sets t0 bin value at given index.
Definition PMusrT0.cpp:207
Bool_t fSingleHisto
True for single histogram fit, false for asymmetry fit.
Definition PMusrT0.h:149
Int_t fDetectorTag
Detector: PMUSRT0_FORWARD (0) or PMUSRT0_BACKWARD (1).
Definition PMusrT0.h:155
Interactive GUI for determining t0 and data/background ranges in μSR experiments.
Definition PMusrT0.h:198
Int_t fTimeout
Timeout in ms after which Done signal is emitted (≤0 disables timeout).
Definition PMusrT0.h:267
std::unique_ptr< TLine > fLastBkgLine
Vertical line marking background end bin.
Definition PMusrT0.h:294
std::unique_ptr< TLine > fFirstDataLine
Vertical line marking first good data bin.
Definition PMusrT0.h:295
std::unique_ptr< TTimer > fTimeoutTimer
Timer to emit Done signal if no user interaction occurs.
Definition PMusrT0.h:280
void SetDataLastChannel()
Sets last good data bin to cursor position.
Definition PMusrT0.cpp:1041
PMusrT0Data fMusrT0Data
Container for raw μSR run data and histogram information.
Definition PMusrT0.h:273
std::unique_ptr< TLine > fT0Line
Vertical line marking current t0 position.
Definition PMusrT0.h:291
Bool_t fValid
True if raw data sets are available and GUI is functional.
Definition PMusrT0.h:269
void UnZoom()
Resets zoom to show full histogram range.
Definition PMusrT0.cpp:1190
PMusrT0()
Default constructor (creates invalid instance).
void HideDataFileT0Channel()
Hides vertical line showing t0 from data file.
Definition PMusrT0.cpp:881
void SetBkgLastChannel()
Sets background end bin to cursor position.
Definition PMusrT0.cpp:1141
void SetEstimatedT0Channel()
Sets t0 to estimated value and updates display.
Definition PMusrT0.cpp:947
Bool_t fShowT0DataChannel
Flag to show/hide t0 value from data file.
Definition PMusrT0.h:278
virtual void SetMsrHandler(PMsrHandler *msrHandler)
Sets the MSR file handler for accessing run configuration.
Definition PMusrT0.cpp:692
std::unique_ptr< TLine > fLastDataLine
Vertical line marking last good data bin.
Definition PMusrT0.h:296
virtual void InitT0()
Initializes GUI for interactive t0 determination.
Definition PMusrT0.cpp:708
virtual void InitDataAndBkg()
Initializes GUI for interactive data and background range determination.
Definition PMusrT0.cpp:756
void SetT0Channel()
Sets t0 to cursor position and updates display.
Definition PMusrT0.cpp:899
virtual void Done(Int_t status=0)
Emits signal indicating completion of t0/range determination.
Definition PMusrT0.cpp:568
Bool_t fDataAndBkgEnabled
Enable/disable data and background range handling (required for grouping/addrun).
Definition PMusrT0.h:275
Int_t fDataRange[2]
Data range in bins: [0]=first good bin, [1]=last good bin.
Definition PMusrT0.h:301
Int_t fPx
Current cursor x-position in pixel coordinates.
Definition PMusrT0.h:298
void ShowDataFileT0Channel()
Displays vertical line showing t0 from data file.
Definition PMusrT0.cpp:855
Int_t fPy
Current cursor y-position in pixel coordinates.
Definition PMusrT0.h:299
std::unique_ptr< TH1F > fHisto
Full raw data histogram (all bins).
Definition PMusrT0.h:285
PMsrHandler * fMsrHandler
MSR file handler for accessing run configuration.
Definition PMusrT0.h:265
Int_t fBkgRange[2]
Background range in bins: [0]=first bkg bin, [1]=last bkg bin.
Definition PMusrT0.h:302
std::unique_ptr< TLine > fFirstBkgLine
Vertical line marking background start bin.
Definition PMusrT0.h:293
void SetBkgFirstChannel()
Sets background start bin to cursor position.
Definition PMusrT0.cpp:1091
Int_t fStatus
Exit status: 0=local quit (single canvas), 1=quit application.
Definition PMusrT0.h:271
std::unique_ptr< TLine > fT0DataLine
Vertical line marking t0 found in data file.
Definition PMusrT0.h:292
std::unique_ptr< TH1F > fBkg
Background region histogram (background start to end).
Definition PMusrT0.h:287
Bool_t fT0Enabled
Enable/disable t0 handling (required for grouping/addrun).
Definition PMusrT0.h:276
Int_t fT0Estimated
Estimated t0 value in bins (used as initial guess).
Definition PMusrT0.h:277
std::unique_ptr< TH1F > fData
Data region histogram (first good bin to last good bin).
Definition PMusrT0.h:286
virtual void HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected)
Handles keyboard input for interactive t0 and range selection.
Definition PMusrT0.cpp:601
void SetDataFirstChannel()
Sets first good data bin to cursor position.
Definition PMusrT0.cpp:991
void ZoomT0()
Zooms to region around t0 for precise adjustment.
Definition PMusrT0.cpp:1209
virtual void SetTimeout(Int_t timeout)
Sets automatic timeout for the interactive session.
Definition PMusrT0.cpp:667
virtual void Quit()
Quit slot that emits Done signal to close the current canvas.
Definition PMusrT0.cpp:650
std::unique_ptr< TCanvas > fMainCanvas
Main ROOT canvas for the interactive GUI.
Definition PMusrT0.h:283
virtual const PDoubleVector * GetDataBin(const UInt_t histoNo)
Definition PMusr.h:896
static int timeout
Definition musrfit.cpp:72
x3::rule< class factor, ast::operand > const factor
Factor: literal, constant, parameter, function, or parenthesized expression (highest precedence).