musrfit 1.10.0
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#define DETECTOR_TAG_FORWARD 0
41#define DETECTOR_TAG_BACKWARD 1
42
43//--------------------------------------------------------------------------
44// Constructor
45//--------------------------------------------------------------------------
55
56//--------------------------------------------------------------------------
57// Destructor
58//--------------------------------------------------------------------------
66{
67 fRawRunData.clear();
68 fHistoNo.clear();
69 fT0.clear();
70 for (UInt_t i=0; i<fAddT0.size(); i++)
71 fAddT0[i].clear();
72 fAddT0.clear();
73}
74
75//--------------------------------------------------------------------------
76// InitData
77//--------------------------------------------------------------------------
85{
86 fSingleHisto = true;
87 fRunNo = -1;
88 fAddRunIdx = -1;
89 fHistoNoIdx = -1;
90 fDetectorTag = -1;
91 fCmdTag = -1;
92 fRawRunData.clear();
93 fHistoNo.clear();
94 fT0.clear();
95 for (UInt_t i=0; i<fAddT0.size(); i++)
96 fAddT0[i].clear();
97 fAddT0.clear();
98 fT0Data = -1;
99}
100
101//--------------------------------------------------------------------------
102// GetRawRunData
103//--------------------------------------------------------------------------
111{
112 if ((idx < 0) || (idx >= static_cast<Int_t>(fRawRunData.size())))
113 return nullptr;
114
115 return fRawRunData[idx];
116}
117
118//--------------------------------------------------------------------------
119// GetHistoNo
120//--------------------------------------------------------------------------
127Int_t PMusrT0Data::GetHistoNo(UInt_t idx)
128{
129 if (idx >= fHistoNo.size())
130 return -1;
131
132 return fHistoNo[idx];
133}
134
135//--------------------------------------------------------------------------
136// GetT0Bin
137//--------------------------------------------------------------------------
144Int_t PMusrT0Data::GetT0Bin(UInt_t idx)
145{
146 if (idx >= fT0.size())
147 return -1;
148
149 return fT0[idx];
150}
151
152//--------------------------------------------------------------------------
153// GetAddT0BinSize
154//--------------------------------------------------------------------------
162{
163 if (idx >= fAddT0.size())
164 return 0;
165
166 return fAddT0[idx].size();
167}
168
169//--------------------------------------------------------------------------
170// GetAddT0Bin
171//--------------------------------------------------------------------------
179Int_t PMusrT0Data::GetAddT0Bin(UInt_t addRunIdx, UInt_t idx)
180{
181 if (addRunIdx >= fAddT0.size())
182 return -1;
183
184 if (idx >= fAddT0[addRunIdx].size())
185 return -1;
186
187 return fAddT0[addRunIdx][idx];
188}
189
190//--------------------------------------------------------------------------
191// SetT0Bin
192//--------------------------------------------------------------------------
201void PMusrT0Data::SetT0Bin(UInt_t val, UInt_t idx)
202{
203 if (idx >= fT0.size())
204 fT0.resize(idx+1);
205
206 fT0[idx] = val;
207}
208
209//--------------------------------------------------------------------------
210// SetAddT0Bin
211//--------------------------------------------------------------------------
221void PMusrT0Data::SetAddT0Bin(UInt_t val, UInt_t addRunIdx, UInt_t idx)
222{
223 if (addRunIdx >= fAddT0.size())
224 fAddT0.resize(addRunIdx+1);
225
226 if (idx >= fAddT0[addRunIdx].size())
227 fAddT0[addRunIdx].resize(idx+1);
228
229 fAddT0[addRunIdx][idx] = val;
230}
231
232//--------------------------------------------------------------------------
233
235
236//--------------------------------------------------------------------------
237// Constructor
238//--------------------------------------------------------------------------
246{
247 fTimeout = 0;
248
249 fValid = false;
250
251 fStatus = 0; // default is quit locally
252
253 fDataAndBkgEnabled = false;
254 fT0Enabled = false;
255 fShowT0DataChannel = false;
256
257 fDataRange[0] = 0;
258 fDataRange[1] = 0;
259 fBkgRange[0] = 0;
260 fBkgRange[1] = 0;
261}
262
263//--------------------------------------------------------------------------
264// Constructor
265//--------------------------------------------------------------------------
278{
279 fTimeout = 0;
280
281 fValid = true;
282
283 fStatus = 0; // default is quit locally
284
285 fDataAndBkgEnabled = false;
286 fT0Enabled = false;
287 fShowT0DataChannel = false;
288
289 fDataRange[0] = 0;
290 fDataRange[1] = 0;
291 fBkgRange[0] = 0;
292 fBkgRange[1] = 0;
293
294 // feed necessary objects
295 TString str;
296
297 if ((fMusrT0Data.GetCmdTag() == PMUSRT0_GET_T0) || (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_T0_DATA_AND_BKG_RANGE)) {
298 str = *fMusrT0Data.GetRawRunData(fMusrT0Data.GetAddRunIdx())->GetRunName() + TString(" : ");
299 str += fMusrT0Data.GetHistoNo(fMusrT0Data.GetHistoNoIdx());
300 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
301 str += " (f)";
302 else
303 str += " (b)";
304 str += ", msr runNo = ";
305 str += fMusrT0Data.GetRunNo()+1;
306
307
308 // feed raw data histo
309 PRawRunData *rawRunData = fMusrT0Data.GetRawRunData(fMusrT0Data.GetAddRunIdx());
310 if (rawRunData == nullptr) {
311 fValid = false;
312 return;
313 }
314 Int_t histoNo = fMusrT0Data.GetHistoNo(fMusrT0Data.GetHistoNoIdx());
315 if (!rawRunData->IsPresent(histoNo)) {
316 std::cerr << std::endl << ">> PMusrT0::PMusrT0: **ERROR** found histogram number " << histoNo+1 << " which is NOT present in the data file.";
317 std::cerr << std::endl << ">> Please try to fix this first ..." << std::endl;
318 fValid = false;
319 return;
320 }
321 Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size();
322 Double_t start = -0.5;
323 Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0
324 fHisto = std::make_unique<TH1F>("fHisto", str.Data(), noOfBins, start, end);
325 fHisto->SetMarkerStyle(21);
326 fHisto->SetMarkerSize(0.5);
327 fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black
328
329 Double_t maxVal = 0.0;
330 fT0Estimated = 0;
331 for (UInt_t i=0; i<rawRunData->GetDataBin(histoNo)->size(); i++) {
332 fHisto->SetBinContent(i+1, rawRunData->GetDataBin(histoNo)->at(i));
333 if (rawRunData->GetDataBin(histoNo)->at(i) > maxVal) {
334 maxVal = rawRunData->GetDataBin(histoNo)->at(i);
335 fT0Estimated = i;
336 }
337 }
338 } else {
339 str = *fMusrT0Data.GetRawRunData(0)->GetRunName() + TString(" : ");
340 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
341 str += " forward grouped and runs added";
342 else
343 str += " backward grouped and runs added";
344 str += ", msr runNo = ";
345 str += fMusrT0Data.GetRunNo()+1;
346
347 // feed raw data histo
348 PRawRunData *rawRunData = fMusrT0Data.GetRawRunData(0);
349 if (rawRunData == nullptr) {
350 fValid = false;
351 return;
352 }
353
354 // get run and first histo of grouping and feed it into fHisto
355 Int_t histoNo = fMusrT0Data.GetHistoNo(0);
356 Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size();
357 Double_t start = -0.5;
358 Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0
359 fHisto = std::make_unique<TH1F>("fHisto", str.Data(), noOfBins, start, end);
360 fHisto->SetMarkerStyle(21);
361 fHisto->SetMarkerSize(0.5);
362 fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black
363
364 // sum up all necessary histograms by taking care of the proper t0's
365 Int_t t00;
366 Int_t t0;
367 Double_t dval;
368
369 // check if asymmetry fit
370 UInt_t factor=1;
371 if (!fMusrT0Data.IsSingleHisto())
372 factor=2;
373
374 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
375 t00 = fMusrT0Data.GetT0Bin(0);
376 else
377 t00 = fMusrT0Data.GetT0Bin(1);
378
379 // check if there are addruns and grouping
380 if ((fMusrT0Data.GetRawRunDataSize() > 1) && (fMusrT0Data.GetHistoNoSize() > 1)) { // addruns and grouping present
381
382 for (Int_t i=0; i<noOfBins; i++) { // loop over all entries in fHisto
383
384 dval = 0;
385
386 for (UInt_t k=0; k<fMusrT0Data.GetHistoNoSize(); k++) { // loop over all histograms (grouping)
387
388 histoNo = fMusrT0Data.GetHistoNo(k);
389
390 // get t0
391 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
392 t0 = fMusrT0Data.GetT0Bin(factor*k);
393 else
394 t0 = fMusrT0Data.GetT0Bin(factor*k+1);
395
396 // get proper rawRunData
397 rawRunData = fMusrT0Data.GetRawRunData(0);
398
399 // get bin value from run/grouping
400 if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
401 dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
402
403 for (UInt_t j=1; j<fMusrT0Data.GetRawRunDataSize(); j++) { // loop over all potential addruns
404
405 rawRunData = fMusrT0Data.GetRawRunData(j);
406
407 // get t0
408 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
409 t0 = fMusrT0Data.GetAddT0Bin(j-1, factor*k);
410 else
411 t0 = fMusrT0Data.GetAddT0Bin(j-1, factor*k+1);
412
413 // get bin value from addrun/grouping
414 if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
415 dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
416 }
417 }
418 // set bin value of fHisto
419 fHisto->SetBinContent(i+1, dval);
420 }
421
422 } else if (fMusrT0Data.GetRawRunDataSize() > 1) { // only addruns present
423
424 for (Int_t i=0; i<noOfBins; i++) { // loop over all entries in fHisto
425
426 dval = 0;
427
428 histoNo = fMusrT0Data.GetHistoNo(0);
429
430 // get t0
431 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
432 t0 = fMusrT0Data.GetT0Bin(0);
433 else
434 t0 = fMusrT0Data.GetT0Bin(1);
435
436 // get proper rawRunData
437 rawRunData = fMusrT0Data.GetRawRunData(0);
438
439 // get bin value from run/grouping
440 if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
441 dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
442
443 for (UInt_t j=1; j<fMusrT0Data.GetRawRunDataSize(); j++) { // loop over all potential addruns
444
445 // get proper rawRunData
446 rawRunData = fMusrT0Data.GetRawRunData(j);
447
448 // get t0
449 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
450 t0 = fMusrT0Data.GetAddT0Bin(j-1, 0);
451 else
452 t0 = fMusrT0Data.GetAddT0Bin(j-1, 1);
453
454 // get bin value from addrun/grouping
455 if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
456 dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
457 }
458 // set bin value of fHisto
459 fHisto->SetBinContent(i+1, dval);
460 }
461
462 } else if (fMusrT0Data.GetHistoNoSize() > 1) { // only grouping persent
463
464 for (Int_t i=0; i<noOfBins; i++) { // loop over all entries in fHisto
465
466 dval = 0;
467
468 // get proper rawRunData
469 rawRunData = fMusrT0Data.GetRawRunData(0);
470
471 for (UInt_t k=0; k<fMusrT0Data.GetHistoNoSize(); k++) { // loop over all histograms (grouping)
472
473 histoNo = fMusrT0Data.GetHistoNo(k);
474
475 // get t0
476 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD)
477 t0 = fMusrT0Data.GetT0Bin(factor*k);
478 else
479 t0 = fMusrT0Data.GetT0Bin(factor*k+1);
480
481 // get bin value from run/grouping
482 if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
483 dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
484
485 }
486 // set bin value of fHisto
487 fHisto->SetBinContent(i+1, dval);
488 }
489
490 }
491 }
492
493 // generate canvas etc
494 fMainCanvas = std::make_unique<TCanvas>("fMainCanvas", str);
495 fMainCanvas->SetFillColor(TColor::GetColor(255,255,255));
496
497
498 fMainCanvas->Show();
499
500 fMainCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "PMusrT0",
501 this, "HandleCmdKey(Int_t,Int_t,Int_t,TObject*)");
502 fMainCanvas->Connect("Closed()", "PMusrT0", this, "Quit()");
503
504 if (fMusrT0Data.GetCmdTag() != PMUSRT0_GET_T0)
505 fDataAndBkgEnabled = true;
506 else
507 fDataAndBkgEnabled = false;
508
509 if (fMusrT0Data.GetCmdTag() != PMUSRT0_GET_DATA_AND_BKG_RANGE)
510 fT0Enabled = true;
511 else
512 fT0Enabled = false;
513
514 // do not show root statistics block
515 fHisto->SetStats(kFALSE);
516
517 // draw histos etc
518 fHisto->Draw("p0 9 hist");
519
520 if (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_T0) {
521 str = "please set t0 bin only.";
522 fToDoInfo = std::make_unique<TLatex>();
523 fToDoInfo->SetTextFont(51);
524 fToDoInfo->SetTextSize(0.030);
525 fToDoInfo->SetLineWidth(2);
526 fToDoInfo->SetNDC(kTRUE);
527 fToDoInfo->DrawLatex(0.1, 0.91, str.Data());
528 }
529 if (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_DATA_AND_BKG_RANGE) {
530 str = "please set data and bkg range.";
531 fToDoInfo = std::make_unique<TLatex>();
532 fToDoInfo->SetTextFont(51);
533 fToDoInfo->SetTextSize(0.030);
534 fToDoInfo->SetLineWidth(2);
535 fToDoInfo->SetNDC(kTRUE);
536 fToDoInfo->DrawLatex(0.1, 0.91, str.Data());
537 }
538}
539
540//--------------------------------------------------------------------------
541// Done (SIGNAL)
542//--------------------------------------------------------------------------
552{
553 Emit("Done(Int_t)", status);
554}
555
556//--------------------------------------------------------------------------
557// HandleCmdKey (SLOT)
558//--------------------------------------------------------------------------
584void PMusrT0::HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected)
585{
586 if (event != kKeyPress) {
587 fPx = x;
588 fPy = y;
589 return;
590 }
591
592 // handle keys and popup menu entries
593 if (x == 'q') { // quit
594 fStatus = 0; // will quit locally
595 Done(0);
596 } else if (x == 'Q') { // terminate musrt0
597 fStatus = 1; // will quit globally
598 Done(0);
599 } else if (x == 'u') { // unzoom to the original range
600 UnZoom();
601 } else if (x == 'z') { // zoom to the region around t0, and the estimated t0
602 ZoomT0();
603 } else if (x == 's') { // show the t0 of the data file (if present)
607 else
609 } else if (x == 'T') { // set estimated t0 channel
611 } else if (x == 't') { // set t0 channel
612 SetT0Channel();
613 } else if (x == 'b') { // set first background channel
615 } else if (x == 'B') { // set last background channel
617 } else if (x == 'd') { // set first data channel
619 } else if (x == 'D') { // set last data channel
621 }
622}
623
624//--------------------------------------------------------------------------
625// Quit (public)
626//--------------------------------------------------------------------------
634{
635 fStatus = 2; // will quit globally
636 Done(0);
637}
638
639//--------------------------------------------------------------------------
640// SetTimeout (public)
641//--------------------------------------------------------------------------
651{
653
654 if (fTimeout <= 0)
655 return;
656
657 fTimeoutTimer.reset(new TTimer());
658
659 fTimeoutTimer->Connect("Timeout()", "PMusrT0", this, "Quit()");
660
661 fTimeoutTimer->Start(1000*fTimeout, kTRUE);
662}
663
664//--------------------------------------------------------------------------
665// SetMsrHandler
666//--------------------------------------------------------------------------
676{
677 fMsrHandler = msrHandler;
678}
679
680//--------------------------------------------------------------------------
681// InitT0
682//--------------------------------------------------------------------------
692{
693 // t0 line
694 Double_t t0Bin = 0;
695 Int_t histoIdx = fMusrT0Data.GetHistoNoIdx();
696 Int_t addRunIdx = fMusrT0Data.GetAddRunIdx();
697 UInt_t factor=1;
698 if (!fMusrT0Data.IsSingleHisto())
699 factor=2;
700 switch (fMusrT0Data.GetDetectorTag() ) {
701 case PMUSRT0_FORWARD:
702 if (addRunIdx == 0)
703 t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetT0Bin(factor*histoIdx);
704 else if (addRunIdx > 0)
705 t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetAddT0Bin(addRunIdx-1, factor*histoIdx);
706 break;
707 case PMUSRT0_BACKWARD:
708 if (addRunIdx == 0)
709 t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetT0Bin(factor*histoIdx+1);
710 else if (addRunIdx > 0)
711 t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetAddT0Bin(addRunIdx-1, factor*histoIdx+1);
712 break;
713 default:
714 // not clear yet what to be done
715 break;
716 }
717 Double_t max = fHisto->GetMaximum();
718
719 fT0Line = std::make_unique<TLine>((Double_t)t0Bin, 0.0, (Double_t)t0Bin, max);
720 fT0Line->SetLineStyle(1); // solid
721 fT0Line->SetLineColor(TColor::GetColor(0,255,0)); // green
722 fT0Line->SetLineWidth(2);
723 fT0Line->Draw();
724}
725
726//--------------------------------------------------------------------------
727// InitDataAndBkg
728//--------------------------------------------------------------------------
740{
741 // feed data range histo
742 switch (fMusrT0Data.GetDetectorTag()) {
743 case PMUSRT0_FORWARD:
744 fDataRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(0);
745 fDataRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(1);
746 break;
747 case PMUSRT0_BACKWARD:
748 fDataRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(2);
749 fDataRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(3);
750 break;
751 default:
752 // not clear yet what to be done
753 break;
754 }
755
756 Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
757 Double_t start = fDataRange[0] - 0.5;
758 Double_t end = fDataRange[1] + 0.5;
759 fData = std::make_unique<TH1F>("fData", "fData", noOfBins, start, end);
760 fData->SetMarkerStyle(21);
761 fData->SetMarkerSize(0.5);
762 fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
763
764 for (Int_t i=0; i<noOfBins; i++) {
765 fData->SetBinContent(i+1, fHisto->GetBinContent(fDataRange[0]+i+1));
766 }
767 fData->Draw("p0 9 hist same");
768
769 // feed background histo
770 switch (fMusrT0Data.GetDetectorTag()) {
771 case PMUSRT0_FORWARD:
772 fBkgRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(0);
773 fBkgRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(1);
774 break;
775 case PMUSRT0_BACKWARD:
776 fBkgRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(2);
777 fBkgRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(3);
778 break;
779 default:
780 // not clear yet what to be done
781 break;
782 }
783
784 noOfBins = fBkgRange[1]-fBkgRange[0]+1;
785 start = fBkgRange[0] - 0.5;
786 end = fBkgRange[1] + 0.5;
787 fBkg = std::make_unique<TH1F>("fBkg", "fBkg", noOfBins, start, end);
788 fBkg->SetMarkerStyle(21);
789 fBkg->SetMarkerSize(0.5);
790 fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red
791
792 for (Int_t i=0; i<noOfBins; i++) {
793 fBkg->SetBinContent(i+1, fHisto->GetBinContent(fBkgRange[0]+i+1));
794 }
795 fBkg->Draw("p0 9 hist same");
796
797 // add lines
798 Double_t max = fHisto->GetMaximum();
799
800 // data lines
801 fFirstDataLine = std::make_unique<TLine>(static_cast<Double_t>(fDataRange[0]), 0.0, static_cast<Double_t>(fDataRange[0]), max);
802 fFirstDataLine->SetLineStyle(3); // doted
803 fFirstDataLine->SetLineColor(TColor::GetColor(0,0,255)); // blue
804 fFirstDataLine->SetLineWidth(2);
805 fFirstDataLine->Draw();
806
807 fLastDataLine = std::make_unique<TLine>(static_cast<Double_t>(fDataRange[1]), 0.0, static_cast<Double_t>(fDataRange[1]), max);
808 fLastDataLine->SetLineStyle(3); // doted
809 fLastDataLine->SetLineColor(TColor::GetColor(0,0,255)); // blue
810 fLastDataLine->SetLineWidth(2);
811 fLastDataLine->Draw();
812
813 // bkg lines
814 fFirstBkgLine = std::make_unique<TLine>(static_cast<Double_t>(fBkgRange[0]), 0.0, static_cast<Double_t>(fBkgRange[0]), max);
815 fFirstBkgLine->SetLineStyle(6); // _..._...
816 fFirstBkgLine->SetLineColor(TColor::GetColor(255,0,0)); // red
817 fFirstBkgLine->SetLineWidth(2);
818 fFirstBkgLine->Draw();
819
820 fLastBkgLine = std::make_unique<TLine>(static_cast<Double_t>(fBkgRange[1]), 0.0, static_cast<Double_t>(fBkgRange[1]), max);
821 fLastBkgLine->SetLineStyle(6); // _..._...
822 fLastBkgLine->SetLineColor(TColor::GetColor(255,0,0)); // red
823 fLastBkgLine->SetLineWidth(2);
824 fLastBkgLine->Draw();
825
826 fMainCanvas->Update();
827}
828
829//--------------------------------------------------------------------------
830// ShowDataFileT0Channel
831//--------------------------------------------------------------------------
839{
840 // t0 line
841 Int_t t0Bin = fMusrT0Data.GetT0BinData();
842 Double_t max = fHisto->GetMaximum();
843
844 if (!fT0DataLine) {
845 fT0DataLine = std::make_unique<TLine>(static_cast<Double_t>(t0Bin), 0.0, static_cast<Double_t>(t0Bin), max);
846 fT0DataLine->SetLineStyle(1); // solid
847 fT0DataLine->SetLineColor(kOrange-3);
848 fT0DataLine->SetLineWidth(2);
849 fT0DataLine->Draw();
850 }
851
852 fMainCanvas->Update();
853}
854
855//--------------------------------------------------------------------------
856// HideDataFileT0Channel
857//--------------------------------------------------------------------------
865{
866 if (fT0DataLine) {
867 fT0DataLine.reset();
868 }
869 fMainCanvas->Update();
870}
871
872//--------------------------------------------------------------------------
873// SetT0Channel
874//--------------------------------------------------------------------------
883{
884 if (!fT0Enabled)
885 return;
886
887 Double_t x=0, y=0;
888 fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
889
890 // get binx to set t0 corresponding to fPx
891 Int_t binx = fHisto->GetXaxis()->FindFixBin(x) - 1;
892
893 std::cout << std::endl << ">> PMusrT0::SetT0Channel(): t0 = " << binx << std::endl;
894
895 // set t0 bin in msr-Handler
896 UInt_t idx;
897 if (fMusrT0Data.IsSingleHisto()) {
898 idx = fMusrT0Data.GetHistoNoIdx();
899 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
900 idx += 1;
901 } else {
902 idx = 2*fMusrT0Data.GetHistoNoIdx();
903 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
904 idx += 1;
905 }
906
907 if (fMusrT0Data.GetAddRunIdx() == 0)
908 fMsrHandler->SetMsrT0Entry(fMusrT0Data.GetRunNo(), idx, binx);
909 else if (fMusrT0Data.GetAddRunIdx() > 0)
910 fMsrHandler->SetMsrAddT0Entry(fMusrT0Data.GetRunNo(), fMusrT0Data.GetAddRunIdx()-1, idx, binx);
911
912 // shift line to the proper position
913 fT0Line->SetX1(x);
914 fT0Line->SetX2(x);
915
916 fMainCanvas->Modified(); // needed that Update is actually working
917 fMainCanvas->Update();
918}
919
920//--------------------------------------------------------------------------
921// SetEstimatedT0Channel
922//--------------------------------------------------------------------------
931{
932 if (!fT0Enabled)
933 return;
934
935 // set t0 bin in msr-Handler
936 UInt_t idx;
937 if (fMusrT0Data.IsSingleHisto()) {
938 idx = fMusrT0Data.GetHistoNoIdx();
939 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
940 idx += 1;
941 } else {
942 idx = 2*fMusrT0Data.GetHistoNoIdx();
943 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
944 idx += 1;
945 }
946
947 if (fMusrT0Data.GetAddRunIdx() == 0)
948 fMsrHandler->SetMsrT0Entry(fMusrT0Data.GetRunNo(), idx, fT0Estimated);
949 else if (fMusrT0Data.GetAddRunIdx() > 0)
950 fMsrHandler->SetMsrAddT0Entry(fMusrT0Data.GetRunNo(), fMusrT0Data.GetAddRunIdx()-1, idx, fT0Estimated);
951
952 Double_t x = fHisto->GetXaxis()->GetBinCenter(fT0Estimated)+1.0; // +1.0 needed since the first bin == 1 not 0.
953
954 std::cout << std::endl << ">> PMusrT0::SetEstimatedT0Channel(): estimated t0 = " << fT0Estimated << std::endl;
955
956 // shift line to the proper position
957 fT0Line->SetX1(x);
958 fT0Line->SetX2(x);
959
960 fMainCanvas->Modified(); // needed that Update is actually working
961 fMainCanvas->Update();
962}
963
964//--------------------------------------------------------------------------
965// SetDataFirstChannel
966//--------------------------------------------------------------------------
975{
977 return;
978
979 Double_t x=0, y=0;
980 fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
981
982 // get binx to set the data first channel corresponding to fPx
983 fDataRange[0] = fHisto->GetXaxis()->FindFixBin(x) - 1;
984
985 std::cout << std::endl << ">> PMusrT0::SetDataFirstChannel(): fDataRange[0] = " << fDataRange[0] << std::endl;
986
987 // set the data first bin in msr-Handler
988 UInt_t idx = 0;
989 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
990 idx = 2;
991 fMsrHandler->SetMsrDataRangeEntry(fMusrT0Data.GetRunNo(), idx, fDataRange[0]);
992
993 // shift line to the proper position
994 fFirstDataLine->SetX1(x);
995 fFirstDataLine->SetX2(x);
996
997 // refill data histo
998 Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
999 Double_t start = fDataRange[0] - 0.5;
1000 Double_t end = fDataRange[1] + 0.5;
1001 fData.reset(new TH1F("fData", "fData", noOfBins, start, end));
1002 fData->SetMarkerStyle(21);
1003 fData->SetMarkerSize(0.5);
1004 fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
1005 for (Int_t i=0; i<noOfBins; i++) {
1006 fData->SetBinContent(i+1, fHisto->GetBinContent(fDataRange[0]+i+1));
1007 }
1008 fData->Draw("p0 9 hist same");
1009
1010 fMainCanvas->Modified(); // needed that Update is actually working
1011 fMainCanvas->Update();
1012}
1013
1014//--------------------------------------------------------------------------
1015// SetDataLastChannel
1016//--------------------------------------------------------------------------
1025{
1026 if (!fDataAndBkgEnabled)
1027 return;
1028
1029 Double_t x=0, y=0;
1030 fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
1031
1032 // get binx to set the data last channel corresponding to fPx
1033 fDataRange[1] = fHisto->GetXaxis()->FindFixBin(x) - 1;
1034
1035 std::cout << std::endl << ">> PMusrT0::SetDataLastChannel(): fDataRange[1] = " << fDataRange[1] << std::endl;
1036
1037 // set the data first bin in msr-Handler
1038 UInt_t idx = 1;
1039 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
1040 idx = 3;
1041 fMsrHandler->SetMsrDataRangeEntry(fMusrT0Data.GetRunNo(), idx, fDataRange[1]);
1042
1043 // shift line to the proper position
1044 fLastDataLine->SetX1(x);
1045 fLastDataLine->SetX2(x);
1046
1047 // refill data histo
1048 Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
1049 Double_t start = fDataRange[0] - 0.5;
1050 Double_t end = fDataRange[1] + 0.5;
1051 fData.reset(new TH1F("fData", "fData", noOfBins, start, end));
1052 fData->SetMarkerStyle(21);
1053 fData->SetMarkerSize(0.5);
1054 fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
1055 for (Int_t i=0; i<noOfBins; i++) {
1056 fData->SetBinContent(i+1, fHisto->GetBinContent(fDataRange[0]+i+1));
1057 }
1058 fData->Draw("p0 9 hist same");
1059
1060 fMainCanvas->Modified(); // needed that Update is actually working
1061 fMainCanvas->Update();
1062}
1063
1064//--------------------------------------------------------------------------
1065// SetBkgFirstChannel
1066//--------------------------------------------------------------------------
1075{
1076 if (!fDataAndBkgEnabled)
1077 return;
1078
1079 Double_t x=0, y=0;
1080 fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
1081
1082 // get binx to set the background first channel corresponding to fPx
1083 fBkgRange[0] = fHisto->GetXaxis()->FindFixBin(x) - 1;
1084
1085 std::cout << std::endl << ">> PMusrT0::SetBkgFirstChannel(): fBkgRange[0] = " << fBkgRange[0] << std::endl;
1086
1087 // set the background first bin in msr-Handler
1088 UInt_t idx = 0;
1089 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
1090 idx = 2;
1091 fMsrHandler->SetMsrBkgRangeEntry(fMusrT0Data.GetRunNo(), idx, fBkgRange[0]);
1092
1093 // shift line to the proper position
1094 fFirstBkgLine->SetX1(x);
1095 fFirstBkgLine->SetX2(x);
1096
1097 // refill data histo
1098 Int_t noOfBins = fBkgRange[1]-fBkgRange[0]+1;
1099 Double_t start = fBkgRange[0] - 0.5;
1100 Double_t end = fBkgRange[1] + 0.5;
1101 fBkg.reset(new TH1F("fBkg", "fBkg", noOfBins, start, end));
1102 fBkg->SetMarkerStyle(21);
1103 fBkg->SetMarkerSize(0.5);
1104 fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red
1105 for (Int_t i=0; i<noOfBins; i++) {
1106 fBkg->SetBinContent(i+1, fHisto->GetBinContent(fBkgRange[0]+i+1));
1107 }
1108 fBkg->Draw("p0 9 hist same");
1109
1110 fMainCanvas->Modified(); // needed that Update is actually working
1111 fMainCanvas->Update();
1112}
1113
1114//--------------------------------------------------------------------------
1115// SetBkgLastChannel
1116//--------------------------------------------------------------------------
1125{
1126 if (!fDataAndBkgEnabled)
1127 return;
1128
1129 Double_t x=0, y=0;
1130 fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
1131
1132 // get binx to set the background last channel corresponding to fPx
1133 fBkgRange[1] = fHisto->GetXaxis()->FindFixBin(x) - 1;
1134
1135 std::cout << std::endl << ">> PMusrT0::SetBkgLastChannel(): fBkgRange[1] = " << fBkgRange[1] << std::endl;
1136
1137 // set the background first bin in msr-Handler
1138 UInt_t idx = 1;
1139 if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD)
1140 idx = 3;
1141 fMsrHandler->SetMsrBkgRangeEntry(fMusrT0Data.GetRunNo(), idx, fBkgRange[1]);
1142
1143 // shift line to the proper position
1144 fLastBkgLine->SetX1(x);
1145 fLastBkgLine->SetX2(x);
1146
1147 // refill data histo
1148 Int_t noOfBins = fBkgRange[1]-fBkgRange[0]+1;
1149 Double_t start = fBkgRange[0] - 0.5;
1150 Double_t end = fBkgRange[1] + 0.5;
1151 fBkg.reset(new TH1F("fBkg", "fBkg", noOfBins, start, end));
1152 fBkg->SetMarkerStyle(21);
1153 fBkg->SetMarkerSize(0.5);
1154 fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red
1155 for (Int_t i=0; i<noOfBins; i++) {
1156 fBkg->SetBinContent(i+1, fHisto->GetBinContent(fBkgRange[0]+i+1));
1157 }
1158 fBkg->Draw("p0 9 hist same");
1159
1160 fMainCanvas->Modified(); // needed that Update is actually working
1161 fMainCanvas->Update();
1162}
1163
1164//--------------------------------------------------------------------------
1165// UnZoom
1166//--------------------------------------------------------------------------
1174{
1175 fHisto->GetXaxis()->UnZoom();
1176 fHisto->GetYaxis()->UnZoom();
1177
1178 fMainCanvas->Modified(); // needed that Update is actually working
1179 fMainCanvas->Update();
1180}
1181
1182//--------------------------------------------------------------------------
1183// ZoomT0
1184//--------------------------------------------------------------------------
1193{
1194 if (!fT0Enabled)
1195 return;
1196
1197 const Int_t range = 75;
1198
1199 // get current t0 position
1200 Double_t t0x = fT0Line->GetX1();
1201 Int_t t0 = fHisto->GetXaxis()->FindBin(t0x)-1;
1202
1203 Int_t min = t0 - range;
1204 Int_t max = t0 + range;
1205
1206 // check if t0 is defined at all
1207 if (t0 <= 0) {
1208 min = fT0Estimated - range;
1209 max = fT0Estimated + range;
1210 }
1211
1212 if (fT0Estimated < min) {
1213 min = fT0Estimated - range;
1214 }
1215 if (fT0Estimated > max) {
1216 max = fT0Estimated + range;
1217 }
1218
1219 fHisto->GetXaxis()->SetRangeUser(min, max);
1220
1221 fMainCanvas->Modified(); // needed that Update is actually working
1222 fMainCanvas->Update();
1223}
1224
1225//--------------------------------------------------------------------------
1226// END
1227//--------------------------------------------------------------------------
ClassImpQ(PMusrT0) PMusrT0
Default constructor that creates an invalid PMusrT0 instance.
Definition PMusrT0.cpp:234
#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:127
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:179
Int_t fHistoNoIdx
Current histogram number index.
Definition PMusrT0.h:153
PMusrT0Data()
Default constructor.
Definition PMusrT0.cpp:51
virtual void InitData()
Initializes data structures (currently empty implementation)
Definition PMusrT0.cpp:84
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:144
virtual void SetAddT0Bin(UInt_t val, UInt_t addRunIdx, UInt_t idx)
Sets t0 bin value for specific addrun and index.
Definition PMusrT0.cpp:221
virtual ~PMusrT0Data()
Destructor.
Definition PMusrT0.cpp:65
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:161
virtual PRawRunData * GetRawRunData(Int_t idx)
Returns raw run data for given index (0=main run, >0=addruns)
Definition PMusrT0.cpp:110
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:201
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:1024
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:1173
PMusrT0()
Default constructor (creates invalid instance)
void HideDataFileT0Channel()
Hides vertical line showing t0 from data file.
Definition PMusrT0.cpp:864
void SetBkgLastChannel()
Sets background end bin to cursor position.
Definition PMusrT0.cpp:1124
void SetEstimatedT0Channel()
Sets t0 to estimated value and updates display.
Definition PMusrT0.cpp:930
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:675
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:691
virtual void InitDataAndBkg()
Initializes GUI for interactive data and background range determination.
Definition PMusrT0.cpp:739
void SetT0Channel()
Sets t0 to cursor position and updates display.
Definition PMusrT0.cpp:882
virtual void Done(Int_t status=0)
Emits signal indicating completion of t0/range determination.
Definition PMusrT0.cpp:551
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:838
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:1074
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:584
void SetDataFirstChannel()
Sets first good data bin to cursor position.
Definition PMusrT0.cpp:974
void ZoomT0()
Zooms to region around t0 for precise adjustment.
Definition PMusrT0.cpp:1192
virtual void SetTimeout(Int_t timeout)
Sets automatic timeout for the interactive session.
Definition PMusrT0.cpp:650
virtual void Quit()
Quit slot that emits Done signal to close the current canvas.
Definition PMusrT0.cpp:633
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:880
static int timeout
Definition musrfit.cpp:71
x3::rule< class factor, ast::operand > const factor
Factor: literal, constant, parameter, function, or parenthesized expression (highest precedence)