musrfit  1.9.2
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-2023 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 //--------------------------------------------------------------------------
50 {
51  InitData();
52 }
53 
54 //--------------------------------------------------------------------------
55 // Destructor
56 //--------------------------------------------------------------------------
61 {
62  fRawRunData.clear();
63  fHistoNo.clear();
64  fT0.clear();
65  for (UInt_t i=0; i<fAddT0.size(); i++)
66  fAddT0[i].clear();
67  fAddT0.clear();
68 }
69 
70 //--------------------------------------------------------------------------
71 // InitData
72 //--------------------------------------------------------------------------
77 {
78  fSingleHisto = true;
79  fRunNo = -1;
80  fAddRunIdx = -1;
81  fHistoNoIdx = -1;
82  fDetectorTag = -1;
83  fCmdTag = -1;
84  fRawRunData.clear();
85  fHistoNo.clear();
86  fT0.clear();
87  for (UInt_t i=0; i<fAddT0.size(); i++)
88  fAddT0[i].clear();
89  fAddT0.clear();
90  fT0Data = -1;
91 }
92 
93 //--------------------------------------------------------------------------
94 // GetRawRunData
95 //--------------------------------------------------------------------------
106 {
107  if ((idx < 0) || (idx >= static_cast<Int_t>(fRawRunData.size())))
108  return nullptr;
109 
110  return fRawRunData[idx];
111 }
112 
113 //--------------------------------------------------------------------------
114 // GetHistoNo
115 //--------------------------------------------------------------------------
125 Int_t PMusrT0Data::GetHistoNo(UInt_t idx)
126 {
127  if (idx >= fHistoNo.size())
128  return -1;
129 
130  return fHistoNo[idx];
131 }
132 
133 //--------------------------------------------------------------------------
134 // GetT0Bin
135 //--------------------------------------------------------------------------
145 Int_t PMusrT0Data::GetT0Bin(UInt_t idx)
146 {
147  if (idx >= fT0.size())
148  return -1;
149 
150  return fT0[idx];
151 }
152 
153 //--------------------------------------------------------------------------
154 // GetAddT0BinSize
155 //--------------------------------------------------------------------------
166 {
167  if (idx >= fAddT0.size())
168  return 0;
169 
170  return fAddT0[idx].size();
171 }
172 
173 //--------------------------------------------------------------------------
174 // GetAddT0Bin
175 //--------------------------------------------------------------------------
186 Int_t PMusrT0Data::GetAddT0Bin(UInt_t addRunIdx, UInt_t idx)
187 {
188  if (addRunIdx >= fAddT0.size())
189  return -1;
190 
191  if (idx >= fAddT0[addRunIdx].size())
192  return -1;
193 
194  return fAddT0[addRunIdx][idx];
195 }
196 
197 //--------------------------------------------------------------------------
198 // SetT0Bin
199 //--------------------------------------------------------------------------
206 void PMusrT0Data::SetT0Bin(UInt_t val, UInt_t idx)
207 {
208  if (idx >= fT0.size())
209  fT0.resize(idx+1);
210 
211  fT0[idx] = val;
212 }
213 
214 //--------------------------------------------------------------------------
215 // SetAddT0Bin
216 //--------------------------------------------------------------------------
224 void PMusrT0Data::SetAddT0Bin(UInt_t val, UInt_t addRunIdx, UInt_t idx)
225 {
226  if (addRunIdx >= fAddT0.size())
227  fAddT0.resize(addRunIdx+1);
228 
229  if (idx >= fAddT0[addRunIdx].size())
230  fAddT0[addRunIdx].resize(idx+1);
231 
232  fAddT0[addRunIdx][idx] = val;
233 }
234 
235 //--------------------------------------------------------------------------
236 
238 
239 //--------------------------------------------------------------------------
240 // Constructor
241 //--------------------------------------------------------------------------
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 //--------------------------------------------------------------------------
271 PMusrT0::PMusrT0(PMusrT0Data &data) : fMusrT0Data(data)
272 {
273  fTimeout = 0;
274 
275  fValid = true;
276 
277  fStatus = 0; // default is quit locally
278 
279  fDataAndBkgEnabled = false;
280  fT0Enabled = false;
281  fShowT0DataChannel = false;
282 
283  fDataRange[0] = 0;
284  fDataRange[1] = 0;
285  fBkgRange[0] = 0;
286  fBkgRange[1] = 0;
287 
288  // feed necessary objects
289  TString str;
290 
292  str = *fMusrT0Data.GetRawRunData(fMusrT0Data.GetAddRunIdx())->GetRunName() + TString(" : ");
295  str += " (f)";
296  else
297  str += " (b)";
298  str += ", msr runNo = ";
299  str += fMusrT0Data.GetRunNo()+1;
300 
301 
302  // feed raw data histo
304  if (rawRunData == nullptr) {
305  fValid = false;
306  return;
307  }
308  Int_t histoNo = fMusrT0Data.GetHistoNo(fMusrT0Data.GetHistoNoIdx());
309  if (!rawRunData->IsPresent(histoNo)) {
310  std::cerr << std::endl << ">> PMusrT0::PMusrT0: **ERROR** found histogram number " << histoNo+1 << " which is NOT present in the data file.";
311  std::cerr << std::endl << ">> Please try to fix this first ..." << std::endl;
312  fValid = false;
313  return;
314  }
315  Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size();
316  Double_t start = -0.5;
317  Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0
318  fHisto = std::make_unique<TH1F>("fHisto", str.Data(), noOfBins, start, end);
319  fHisto->SetMarkerStyle(21);
320  fHisto->SetMarkerSize(0.5);
321  fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black
322 
323  Double_t maxVal = 0.0;
324  fT0Estimated = 0;
325  for (UInt_t i=0; i<rawRunData->GetDataBin(histoNo)->size(); i++) {
326  fHisto->SetBinContent(i+1, rawRunData->GetDataBin(histoNo)->at(i));
327  if (rawRunData->GetDataBin(histoNo)->at(i) > maxVal) {
328  maxVal = rawRunData->GetDataBin(histoNo)->at(i);
329  fT0Estimated = i;
330  }
331  }
332  } else {
333  str = *fMusrT0Data.GetRawRunData(0)->GetRunName() + TString(" : ");
335  str += " forward grouped and runs added";
336  else
337  str += " backward grouped and runs added";
338  str += ", msr runNo = ";
339  str += fMusrT0Data.GetRunNo()+1;
340 
341  // feed raw data histo
342  PRawRunData *rawRunData = fMusrT0Data.GetRawRunData(0);
343  if (rawRunData == nullptr) {
344  fValid = false;
345  return;
346  }
347 
348  // get run and first histo of grouping and feed it into fHisto
349  Int_t histoNo = fMusrT0Data.GetHistoNo(0);
350  Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size();
351  Double_t start = -0.5;
352  Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0
353  fHisto = std::make_unique<TH1F>("fHisto", str.Data(), noOfBins, start, end);
354  fHisto->SetMarkerStyle(21);
355  fHisto->SetMarkerSize(0.5);
356  fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black
357 
358  // sum up all necessary histograms by taking care of the proper t0's
359  Int_t t00;
360  Int_t t0;
361  Double_t dval;
362 
363  // check if asymmetry fit
364  UInt_t factor=1;
365  if (!fMusrT0Data.IsSingleHisto())
366  factor=2;
367 
369  t00 = fMusrT0Data.GetT0Bin(0);
370  else
371  t00 = fMusrT0Data.GetT0Bin(1);
372 
373  // check if there are addruns and grouping
374  if ((fMusrT0Data.GetRawRunDataSize() > 1) && (fMusrT0Data.GetHistoNoSize() > 1)) { // addruns and grouping present
375 
376  for (Int_t i=0; i<noOfBins; i++) { // loop over all entries in fHisto
377 
378  dval = 0;
379 
380  for (UInt_t k=0; k<fMusrT0Data.GetHistoNoSize(); k++) { // loop over all histograms (grouping)
381 
382  histoNo = fMusrT0Data.GetHistoNo(k);
383 
384  // get t0
386  t0 = fMusrT0Data.GetT0Bin(factor*k);
387  else
388  t0 = fMusrT0Data.GetT0Bin(factor*k+1);
389 
390  // get proper rawRunData
391  rawRunData = fMusrT0Data.GetRawRunData(0);
392 
393  // get bin value from run/grouping
394  if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
395  dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
396 
397  for (UInt_t j=1; j<fMusrT0Data.GetRawRunDataSize(); j++) { // loop over all potential addruns
398 
399  rawRunData = fMusrT0Data.GetRawRunData(j);
400 
401  // get t0
403  t0 = fMusrT0Data.GetAddT0Bin(j-1, factor*k);
404  else
405  t0 = fMusrT0Data.GetAddT0Bin(j-1, factor*k+1);
406 
407  // get bin value from addrun/grouping
408  if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
409  dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
410  }
411  }
412  // set bin value of fHisto
413  fHisto->SetBinContent(i+1, dval);
414  }
415 
416  } else if (fMusrT0Data.GetRawRunDataSize() > 1) { // only addruns present
417 
418  for (Int_t i=0; i<noOfBins; i++) { // loop over all entries in fHisto
419 
420  dval = 0;
421 
422  histoNo = fMusrT0Data.GetHistoNo(0);
423 
424  // get t0
426  t0 = fMusrT0Data.GetT0Bin(0);
427  else
428  t0 = fMusrT0Data.GetT0Bin(1);
429 
430  // get proper rawRunData
431  rawRunData = fMusrT0Data.GetRawRunData(0);
432 
433  // get bin value from run/grouping
434  if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
435  dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
436 
437  for (UInt_t j=1; j<fMusrT0Data.GetRawRunDataSize(); j++) { // loop over all potential addruns
438 
439  // get proper rawRunData
440  rawRunData = fMusrT0Data.GetRawRunData(j);
441 
442  // get t0
444  t0 = fMusrT0Data.GetAddT0Bin(j-1, 0);
445  else
446  t0 = fMusrT0Data.GetAddT0Bin(j-1, 1);
447 
448  // get bin value from addrun/grouping
449  if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
450  dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
451  }
452  // set bin value of fHisto
453  fHisto->SetBinContent(i+1, dval);
454  }
455 
456  } else if (fMusrT0Data.GetHistoNoSize() > 1) { // only grouping persent
457 
458  for (Int_t i=0; i<noOfBins; i++) { // loop over all entries in fHisto
459 
460  dval = 0;
461 
462  // get proper rawRunData
463  rawRunData = fMusrT0Data.GetRawRunData(0);
464 
465  for (UInt_t k=0; k<fMusrT0Data.GetHistoNoSize(); k++) { // loop over all histograms (grouping)
466 
467  histoNo = fMusrT0Data.GetHistoNo(k);
468 
469  // get t0
471  t0 = fMusrT0Data.GetT0Bin(factor*k);
472  else
473  t0 = fMusrT0Data.GetT0Bin(factor*k+1);
474 
475  // get bin value from run/grouping
476  if ((i+t0-t00 > 0) && (i+t0-t00 < static_cast<Int_t>(rawRunData->GetDataBin(histoNo)->size())))
477  dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00);
478 
479  }
480  // set bin value of fHisto
481  fHisto->SetBinContent(i+1, dval);
482  }
483 
484  }
485  }
486 
487  // generate canvas etc
488  fMainCanvas = std::make_unique<TCanvas>("fMainCanvas", str);
489  fMainCanvas->SetFillColor(TColor::GetColor(255,255,255));
490 
491 
492  fMainCanvas->Show();
493 
494  fMainCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "PMusrT0",
495  this, "HandleCmdKey(Int_t,Int_t,Int_t,TObject*)");
496  fMainCanvas->Connect("Closed()", "PMusrT0", this, "Quit()");
497 
499  fDataAndBkgEnabled = true;
500  else
501  fDataAndBkgEnabled = false;
502 
504  fT0Enabled = true;
505  else
506  fT0Enabled = false;
507 
508  // do not show root statistics block
509  fHisto->SetStats(kFALSE);
510 
511  // draw histos etc
512  fHisto->Draw("p0 9 hist");
513 
515  str = "please set t0 bin only.";
516  fToDoInfo = std::make_unique<TLatex>();
517  fToDoInfo->SetTextFont(51);
518  fToDoInfo->SetTextSize(0.030);
519  fToDoInfo->SetLineWidth(2);
520  fToDoInfo->SetNDC(kTRUE);
521  fToDoInfo->DrawLatex(0.1, 0.91, str.Data());
522  }
524  str = "please set data and bkg range.";
525  fToDoInfo = std::make_unique<TLatex>();
526  fToDoInfo->SetTextFont(51);
527  fToDoInfo->SetTextSize(0.030);
528  fToDoInfo->SetLineWidth(2);
529  fToDoInfo->SetNDC(kTRUE);
530  fToDoInfo->DrawLatex(0.1, 0.91, str.Data());
531  }
532 }
533 
534 //--------------------------------------------------------------------------
535 // Done (SIGNAL)
536 //--------------------------------------------------------------------------
541 {
542  Emit("Done(Int_t)", status);
543 }
544 
545 //--------------------------------------------------------------------------
546 // HandleCmdKey (SLOT)
547 //--------------------------------------------------------------------------
569 void PMusrT0::HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected)
570 {
571  if (event != kKeyPress) {
572  fPx = x;
573  fPy = y;
574  return;
575  }
576 
577  // handle keys and popup menu entries
578  if (x == 'q') { // quit
579  fStatus = 0; // will quit locally
580  Done(0);
581  } else if (x == 'Q') { // terminate musrt0
582  fStatus = 1; // will quit globally
583  Done(0);
584  } else if (x == 'u') { // unzoom to the original range
585  UnZoom();
586  } else if (x == 'z') { // zoom to the region around t0, and the estimated t0
587  ZoomT0();
588  } else if (x == 's') { // show the t0 of the data file (if present)
590  if (fShowT0DataChannel)
592  else
594  } else if (x == 'T') { // set estimated t0 channel
596  } else if (x == 't') { // set t0 channel
597  SetT0Channel();
598  } else if (x == 'b') { // set first background channel
600  } else if (x == 'B') { // set last background channel
602  } else if (x == 'd') { // set first data channel
604  } else if (x == 'D') { // set last data channel
606  }
607 }
608 
609 //--------------------------------------------------------------------------
610 // Quit (public)
611 //--------------------------------------------------------------------------
617 {
618  fStatus = 2; // will quit globally
619  Done(0);
620 }
621 
622 //--------------------------------------------------------------------------
623 // SetTimeout (public)
624 //--------------------------------------------------------------------------
631 {
632  fTimeout = timeout;
633 
634  if (fTimeout <= 0)
635  return;
636 
637  fTimeoutTimer.reset(new TTimer());
638 
639  fTimeoutTimer->Connect("Timeout()", "PMusrT0", this, "Quit()");
640 
641  fTimeoutTimer->Start(1000*fTimeout, kTRUE);
642 }
643 
644 //--------------------------------------------------------------------------
645 // SetMsrHandler
646 //--------------------------------------------------------------------------
653 {
654  fMsrHandler = msrHandler;
655 }
656 
657 //--------------------------------------------------------------------------
658 // InitT0
659 //--------------------------------------------------------------------------
664 {
665  // t0 line
666  Double_t t0Bin = 0;
667  Int_t histoIdx = fMusrT0Data.GetHistoNoIdx();
668  Int_t addRunIdx = fMusrT0Data.GetAddRunIdx();
669  UInt_t factor=1;
670  if (!fMusrT0Data.IsSingleHisto())
671  factor=2;
672  switch (fMusrT0Data.GetDetectorTag() ) {
673  case PMUSRT0_FORWARD:
674  if (addRunIdx == 0)
675  t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetT0Bin(factor*histoIdx);
676  else if (addRunIdx > 0)
677  t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetAddT0Bin(addRunIdx-1, factor*histoIdx);
678  break;
679  case PMUSRT0_BACKWARD:
680  if (addRunIdx == 0)
681  t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetT0Bin(factor*histoIdx+1);
682  else if (addRunIdx > 0)
683  t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetAddT0Bin(addRunIdx-1, factor*histoIdx+1);
684  break;
685  default:
686  // not clear yet what to be done
687  break;
688  }
689  Double_t max = fHisto->GetMaximum();
690 
691  fT0Line = std::make_unique<TLine>((Double_t)t0Bin, 0.0, (Double_t)t0Bin, max);
692  fT0Line->SetLineStyle(1); // solid
693  fT0Line->SetLineColor(TColor::GetColor(0,255,0)); // green
694  fT0Line->SetLineWidth(2);
695  fT0Line->Draw();
696 }
697 
698 //--------------------------------------------------------------------------
699 // InitDataAndBkg
700 //--------------------------------------------------------------------------
705 {
706  // feed data range histo
707  switch (fMusrT0Data.GetDetectorTag()) {
708  case PMUSRT0_FORWARD:
709  fDataRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(0);
710  fDataRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(1);
711  break;
712  case PMUSRT0_BACKWARD:
713  fDataRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(2);
714  fDataRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(3);
715  break;
716  default:
717  // not clear yet what to be done
718  break;
719  }
720 
721  Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
722  Double_t start = fDataRange[0] - 0.5;
723  Double_t end = fDataRange[1] + 0.5;
724  fData = std::make_unique<TH1F>("fData", "fData", noOfBins, start, end);
725  fData->SetMarkerStyle(21);
726  fData->SetMarkerSize(0.5);
727  fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
728 
729  for (Int_t i=0; i<noOfBins; i++) {
730  fData->SetBinContent(i+1, fHisto->GetBinContent(fDataRange[0]+i+1));
731  }
732  fData->Draw("p0 9 hist same");
733 
734  // feed background histo
735  switch (fMusrT0Data.GetDetectorTag()) {
736  case PMUSRT0_FORWARD:
737  fBkgRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(0);
738  fBkgRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(1);
739  break;
740  case PMUSRT0_BACKWARD:
741  fBkgRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(2);
742  fBkgRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(3);
743  break;
744  default:
745  // not clear yet what to be done
746  break;
747  }
748 
749  noOfBins = fBkgRange[1]-fBkgRange[0]+1;
750  start = fBkgRange[0] - 0.5;
751  end = fBkgRange[1] + 0.5;
752  fBkg = std::make_unique<TH1F>("fBkg", "fBkg", noOfBins, start, end);
753  fBkg->SetMarkerStyle(21);
754  fBkg->SetMarkerSize(0.5);
755  fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red
756 
757  for (Int_t i=0; i<noOfBins; i++) {
758  fBkg->SetBinContent(i+1, fHisto->GetBinContent(fBkgRange[0]+i+1));
759  }
760  fBkg->Draw("p0 9 hist same");
761 
762  // add lines
763  Double_t max = fHisto->GetMaximum();
764 
765  // data lines
766  fFirstDataLine = std::make_unique<TLine>(static_cast<Double_t>(fDataRange[0]), 0.0, static_cast<Double_t>(fDataRange[0]), max);
767  fFirstDataLine->SetLineStyle(3); // doted
768  fFirstDataLine->SetLineColor(TColor::GetColor(0,0,255)); // blue
769  fFirstDataLine->SetLineWidth(2);
770  fFirstDataLine->Draw();
771 
772  fLastDataLine = std::make_unique<TLine>(static_cast<Double_t>(fDataRange[1]), 0.0, static_cast<Double_t>(fDataRange[1]), max);
773  fLastDataLine->SetLineStyle(3); // doted
774  fLastDataLine->SetLineColor(TColor::GetColor(0,0,255)); // blue
775  fLastDataLine->SetLineWidth(2);
776  fLastDataLine->Draw();
777 
778  // bkg lines
779  fFirstBkgLine = std::make_unique<TLine>(static_cast<Double_t>(fBkgRange[0]), 0.0, static_cast<Double_t>(fBkgRange[0]), max);
780  fFirstBkgLine->SetLineStyle(6); // _..._...
781  fFirstBkgLine->SetLineColor(TColor::GetColor(255,0,0)); // red
782  fFirstBkgLine->SetLineWidth(2);
783  fFirstBkgLine->Draw();
784 
785  fLastBkgLine = std::make_unique<TLine>(static_cast<Double_t>(fBkgRange[1]), 0.0, static_cast<Double_t>(fBkgRange[1]), max);
786  fLastBkgLine->SetLineStyle(6); // _..._...
787  fLastBkgLine->SetLineColor(TColor::GetColor(255,0,0)); // red
788  fLastBkgLine->SetLineWidth(2);
789  fLastBkgLine->Draw();
790 
791  fMainCanvas->Update();
792 }
793 
794 //--------------------------------------------------------------------------
795 // ShowDataFileT0Channel
796 //--------------------------------------------------------------------------
801 {
802  // t0 line
803  Int_t t0Bin = fMusrT0Data.GetT0BinData();
804  Double_t max = fHisto->GetMaximum();
805 
806  if (!fT0DataLine) {
807  fT0DataLine = std::make_unique<TLine>(static_cast<Double_t>(t0Bin), 0.0, static_cast<Double_t>(t0Bin), max);
808  fT0DataLine->SetLineStyle(1); // solid
809  fT0DataLine->SetLineColor(kOrange-3);
810  fT0DataLine->SetLineWidth(2);
811  fT0DataLine->Draw();
812  }
813 
814  fMainCanvas->Update();
815 }
816 
817 //--------------------------------------------------------------------------
818 // HideDataFileT0Channel
819 //--------------------------------------------------------------------------
824 {
825  if (fT0DataLine) {
826  fT0DataLine.reset();
827  }
828  fMainCanvas->Update();
829 }
830 
831 //--------------------------------------------------------------------------
832 // SetT0Channel
833 //--------------------------------------------------------------------------
838 {
839  if (!fT0Enabled)
840  return;
841 
842  Double_t x=0, y=0;
843  fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
844 
845  // get binx to set t0 corresponding to fPx
846  Int_t binx = fHisto->GetXaxis()->FindFixBin(x) - 1;
847 
848  std::cout << std::endl << ">> PMusrT0::SetT0Channel(): t0 = " << binx << std::endl;
849 
850  // set t0 bin in msr-Handler
851  UInt_t idx;
852  if (fMusrT0Data.IsSingleHisto()) {
853  idx = fMusrT0Data.GetHistoNoIdx();
855  idx += 1;
856  } else {
857  idx = 2*fMusrT0Data.GetHistoNoIdx();
859  idx += 1;
860  }
861 
862  if (fMusrT0Data.GetAddRunIdx() == 0)
864  else if (fMusrT0Data.GetAddRunIdx() > 0)
866 
867  // shift line to the proper position
868  fT0Line->SetX1(x);
869  fT0Line->SetX2(x);
870 
871  fMainCanvas->Modified(); // needed that Update is actually working
872  fMainCanvas->Update();
873 }
874 
875 //--------------------------------------------------------------------------
876 // SetEstimatedT0Channel
877 //--------------------------------------------------------------------------
882 {
883  if (!fT0Enabled)
884  return;
885 
886  // set t0 bin in msr-Handler
887  UInt_t idx;
888  if (fMusrT0Data.IsSingleHisto()) {
889  idx = fMusrT0Data.GetHistoNoIdx();
891  idx += 1;
892  } else {
893  idx = 2*fMusrT0Data.GetHistoNoIdx();
895  idx += 1;
896  }
897 
898  if (fMusrT0Data.GetAddRunIdx() == 0)
900  else if (fMusrT0Data.GetAddRunIdx() > 0)
902 
903  Double_t x = fHisto->GetXaxis()->GetBinCenter(fT0Estimated)+1.0; // +1.0 needed since the first bin == 1 not 0.
904 
905  std::cout << std::endl << ">> PMusrT0::SetEstimatedT0Channel(): estimated t0 = " << fT0Estimated << std::endl;
906 
907  // shift line to the proper position
908  fT0Line->SetX1(x);
909  fT0Line->SetX2(x);
910 
911  fMainCanvas->Modified(); // needed that Update is actually working
912  fMainCanvas->Update();
913 }
914 
915 //--------------------------------------------------------------------------
916 // SetDataFirstChannel
917 //--------------------------------------------------------------------------
922 {
923  if (!fDataAndBkgEnabled)
924  return;
925 
926  Double_t x=0, y=0;
927  fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
928 
929  // get binx to set the data first channel corresponding to fPx
930  fDataRange[0] = fHisto->GetXaxis()->FindFixBin(x) - 1;
931 
932  std::cout << std::endl << ">> PMusrT0::SetDataFirstChannel(): fDataRange[0] = " << fDataRange[0] << std::endl;
933 
934  // set the data first bin in msr-Handler
935  UInt_t idx = 0;
937  idx = 2;
939 
940  // shift line to the proper position
941  fFirstDataLine->SetX1(x);
942  fFirstDataLine->SetX2(x);
943 
944  // refill data histo
945  Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
946  Double_t start = fDataRange[0] - 0.5;
947  Double_t end = fDataRange[1] + 0.5;
948  fData.reset(new TH1F("fData", "fData", noOfBins, start, end));
949  fData->SetMarkerStyle(21);
950  fData->SetMarkerSize(0.5);
951  fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
952  for (Int_t i=0; i<noOfBins; i++) {
953  fData->SetBinContent(i+1, fHisto->GetBinContent(fDataRange[0]+i+1));
954  }
955  fData->Draw("p0 9 hist same");
956 
957  fMainCanvas->Modified(); // needed that Update is actually working
958  fMainCanvas->Update();
959 }
960 
961 //--------------------------------------------------------------------------
962 // SetDataLastChannel
963 //--------------------------------------------------------------------------
968 {
969  if (!fDataAndBkgEnabled)
970  return;
971 
972  Double_t x=0, y=0;
973  fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
974 
975  // get binx to set the data last channel corresponding to fPx
976  fDataRange[1] = fHisto->GetXaxis()->FindFixBin(x) - 1;
977 
978  std::cout << std::endl << ">> PMusrT0::SetDataLastChannel(): fDataRange[1] = " << fDataRange[1] << std::endl;
979 
980  // set the data first bin in msr-Handler
981  UInt_t idx = 1;
983  idx = 3;
985 
986  // shift line to the proper position
987  fLastDataLine->SetX1(x);
988  fLastDataLine->SetX2(x);
989 
990  // refill data histo
991  Int_t noOfBins = fDataRange[1]-fDataRange[0]+1;
992  Double_t start = fDataRange[0] - 0.5;
993  Double_t end = fDataRange[1] + 0.5;
994  fData.reset(new TH1F("fData", "fData", noOfBins, start, end));
995  fData->SetMarkerStyle(21);
996  fData->SetMarkerSize(0.5);
997  fData->SetMarkerColor(TColor::GetColor(0,0,255)); // blue
998  for (Int_t i=0; i<noOfBins; i++) {
999  fData->SetBinContent(i+1, fHisto->GetBinContent(fDataRange[0]+i+1));
1000  }
1001  fData->Draw("p0 9 hist same");
1002 
1003  fMainCanvas->Modified(); // needed that Update is actually working
1004  fMainCanvas->Update();
1005 }
1006 
1007 //--------------------------------------------------------------------------
1008 // SetBkgFirstChannel
1009 //--------------------------------------------------------------------------
1014 {
1015  if (!fDataAndBkgEnabled)
1016  return;
1017 
1018  Double_t x=0, y=0;
1019  fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
1020 
1021  // get binx to set the background first channel corresponding to fPx
1022  fBkgRange[0] = fHisto->GetXaxis()->FindFixBin(x) - 1;
1023 
1024  std::cout << std::endl << ">> PMusrT0::SetBkgFirstChannel(): fBkgRange[0] = " << fBkgRange[0] << std::endl;
1025 
1026  // set the background first bin in msr-Handler
1027  UInt_t idx = 0;
1029  idx = 2;
1031 
1032  // shift line to the proper position
1033  fFirstBkgLine->SetX1(x);
1034  fFirstBkgLine->SetX2(x);
1035 
1036  // refill data histo
1037  Int_t noOfBins = fBkgRange[1]-fBkgRange[0]+1;
1038  Double_t start = fBkgRange[0] - 0.5;
1039  Double_t end = fBkgRange[1] + 0.5;
1040  fBkg.reset(new TH1F("fBkg", "fBkg", noOfBins, start, end));
1041  fBkg->SetMarkerStyle(21);
1042  fBkg->SetMarkerSize(0.5);
1043  fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red
1044  for (Int_t i=0; i<noOfBins; i++) {
1045  fBkg->SetBinContent(i+1, fHisto->GetBinContent(fBkgRange[0]+i+1));
1046  }
1047  fBkg->Draw("p0 9 hist same");
1048 
1049  fMainCanvas->Modified(); // needed that Update is actually working
1050  fMainCanvas->Update();
1051 }
1052 
1053 //--------------------------------------------------------------------------
1054 // SetBkgLastChannel
1055 //--------------------------------------------------------------------------
1060 {
1061  if (!fDataAndBkgEnabled)
1062  return;
1063 
1064  Double_t x=0, y=0;
1065  fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y);
1066 
1067  // get binx to set the background last channel corresponding to fPx
1068  fBkgRange[1] = fHisto->GetXaxis()->FindFixBin(x) - 1;
1069 
1070  std::cout << std::endl << ">> PMusrT0::SetBkgLastChannel(): fBkgRange[1] = " << fBkgRange[1] << std::endl;
1071 
1072  // set the background first bin in msr-Handler
1073  UInt_t idx = 1;
1075  idx = 3;
1077 
1078  // shift line to the proper position
1079  fLastBkgLine->SetX1(x);
1080  fLastBkgLine->SetX2(x);
1081 
1082  // refill data histo
1083  Int_t noOfBins = fBkgRange[1]-fBkgRange[0]+1;
1084  Double_t start = fBkgRange[0] - 0.5;
1085  Double_t end = fBkgRange[1] + 0.5;
1086  fBkg.reset(new TH1F("fBkg", "fBkg", noOfBins, start, end));
1087  fBkg->SetMarkerStyle(21);
1088  fBkg->SetMarkerSize(0.5);
1089  fBkg->SetMarkerColor(TColor::GetColor(255,0,0)); // red
1090  for (Int_t i=0; i<noOfBins; i++) {
1091  fBkg->SetBinContent(i+1, fHisto->GetBinContent(fBkgRange[0]+i+1));
1092  }
1093  fBkg->Draw("p0 9 hist same");
1094 
1095  fMainCanvas->Modified(); // needed that Update is actually working
1096  fMainCanvas->Update();
1097 }
1098 
1099 //--------------------------------------------------------------------------
1100 // UnZoom
1101 //--------------------------------------------------------------------------
1106 {
1107  fHisto->GetXaxis()->UnZoom();
1108  fHisto->GetYaxis()->UnZoom();
1109 
1110  fMainCanvas->Modified(); // needed that Update is actually working
1111  fMainCanvas->Update();
1112 }
1113 
1114 //--------------------------------------------------------------------------
1115 // ZoomT0
1116 //--------------------------------------------------------------------------
1121 {
1122  if (!fT0Enabled)
1123  return;
1124 
1125  const Int_t range = 75;
1126 
1127  // get current t0 position
1128  Double_t t0x = fT0Line->GetX1();
1129  Int_t t0 = fHisto->GetXaxis()->FindBin(t0x)-1;
1130 
1131  Int_t min = t0 - range;
1132  Int_t max = t0 + range;
1133 
1134  // check if t0 is defined at all
1135  if (t0 <= 0) {
1136  min = fT0Estimated - range;
1137  max = fT0Estimated + range;
1138  }
1139 
1140  if (fT0Estimated < min) {
1141  min = fT0Estimated - range;
1142  }
1143  if (fT0Estimated > max) {
1144  max = fT0Estimated + range;
1145  }
1146 
1147  fHisto->GetXaxis()->SetRangeUser(min, max);
1148 
1149  fMainCanvas->Modified(); // needed that Update is actually working
1150  fMainCanvas->Update();
1151 }
1152 
1153 //--------------------------------------------------------------------------
1154 // END
1155 //--------------------------------------------------------------------------
virtual void InitData()
Definition: PMusrT0.cpp:76
void SetDataLastChannel()
Definition: PMusrT0.cpp:967
std::unique_ptr< TCanvas > fMainCanvas
main canvas for the graphical user interface
Definition: PMusrT0.h:162
Int_t fPx
x-position of the cursor
Definition: PMusrT0.h:177
std::unique_ptr< TLine > fT0Line
line showing the position of t0
Definition: PMusrT0.h:170
Int_t fTimeout
timeout after which the Done signal should be emited. If timeout <= 0, no timeout is taking place ...
Definition: PMusrT0.h:146
virtual void HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected)
Definition: PMusrT0.cpp:569
virtual void InitDataAndBkg()
Definition: PMusrT0.cpp:704
std::vector< PRawRunData * > fRawRunData
holds the raw data of the needed runs, idx=0 the run, idx>0 the addruns
Definition: PMusrT0.h:102
Int_t fRunNo
msr-file run number
Definition: PMusrT0.h:103
virtual Bool_t IsSingleHisto()
Definition: PMusrT0.h:71
Int_t fPy
y-position of the cursor
Definition: PMusrT0.h:178
virtual Int_t GetCmdTag()
Definition: PMusrT0.h:80
virtual Int_t GetDetectorTag()
Definition: PMusrT0.h:79
virtual void SetMsrDataRangeEntry(UInt_t runNo, UInt_t idx, Int_t bin)
Bool_t fDataAndBkgEnabled
enable/disable data and background range handling (necessary in connection with grouping and addrun) ...
Definition: PMusrT0.h:154
void SetBkgFirstChannel()
Definition: PMusrT0.cpp:1013
std::unique_ptr< TTimer > fTimeoutTimer
timeout timer in order to terminate if no action is taking place for too long
Definition: PMusrT0.h:159
void SetEstimatedT0Channel()
Definition: PMusrT0.cpp:881
#define PMUSRT0_GET_DATA_AND_BKG_RANGE
Definition: PMusrT0.h:55
std::unique_ptr< TH1F > fData
ranged raw data histogram (first good bin, last good bin)
Definition: PMusrT0.h:165
virtual void SetMsrT0Entry(UInt_t runNo, UInt_t idx, Double_t bin)
void SetT0Channel()
Definition: PMusrT0.cpp:837
virtual UInt_t GetHistoNoSize()
Definition: PMusrT0.h:77
virtual void SetT0Bin(UInt_t val, UInt_t idx)
Definition: PMusrT0.cpp:206
PIntVector fHistoNo
msr-file histo numbers, i.e. idx + Red/Green offset
Definition: PMusrT0.h:106
Bool_t fT0Enabled
enable/disable t0 handling (necessary in connection with grouping and addrun)
Definition: PMusrT0.h:155
virtual UInt_t GetAddT0BinSize(UInt_t idx)
Definition: PMusrT0.cpp:165
virtual void SetTimeout(Int_t timeout)
Definition: PMusrT0.cpp:630
Int_t fAddRunIdx
msr-file addrun index
Definition: PMusrT0.h:104
Bool_t fValid
true if raw data set are available, otherwise false
Definition: PMusrT0.h:148
PMsrHandler * fMsrHandler
msr-file handler
Definition: PMusrT0.h:144
void ZoomT0()
Definition: PMusrT0.cpp:1120
virtual Int_t GetAddT0Bin(UInt_t addRunIdx, UInt_t idx)
Definition: PMusrT0.cpp:186
virtual const Bool_t IsPresent(UInt_t histoNo)
Definition: PMusr.h:430
virtual PMsrRunList * GetMsrRunList()
Definition: PMsrHandler.h:63
void UnZoom()
Definition: PMusrT0.cpp:1105
Bool_t fShowT0DataChannel
Definition: PMusrT0.h:157
Int_t fHistoNoIdx
msr-file histo number index
Definition: PMusrT0.h:105
std::unique_ptr< TH1F > fHisto
full raw data histogram
Definition: PMusrT0.h:164
PMusrT0Data fMusrT0Data
raw muSR run data sets.
Definition: PMusrT0.h:152
virtual void SetMsrHandler(PMsrHandler *msrHandler)
Definition: PMusrT0.cpp:652
virtual Int_t GetT0BinData()
Definition: PMusrT0.h:86
static int timeout
Definition: musrfit.cpp:71
virtual UInt_t GetRawRunDataSize()
Definition: PMusrT0.h:72
PIntVector fT0
holding the t0&#39;s of the run
Definition: PMusrT0.h:109
virtual Int_t GetAddRunIdx()
Definition: PMusrT0.h:75
virtual const TString * GetRunName()
Definition: PMusr.h:402
virtual void SetMsrAddT0Entry(UInt_t runNo, UInt_t addRunIdx, UInt_t histoIdx, Double_t bin)
virtual void SetAddT0Bin(UInt_t val, UInt_t addRunIdx, UInt_t idx)
Definition: PMusrT0.cpp:224
std::unique_ptr< TLine > fFirstDataLine
line showing the start of the data (first good data bin)
Definition: PMusrT0.h:174
void SetDataFirstChannel()
Definition: PMusrT0.cpp:921
std::unique_ptr< TLine > fT0DataLine
line showing the position of t0 found in the data file
Definition: PMusrT0.h:171
#define PMUSRT0_GET_T0
Definition: PMusrT0.h:54
Bool_t fSingleHisto
true if single histo fit, false for asymmetry fit
Definition: PMusrT0.h:101
ClassImpQ(PMusrT0) PMusrT0
Definition: PMusrT0.cpp:237
Int_t fT0Estimated
estimated t0 value (in bins)
Definition: PMusrT0.h:156
Int_t fDetectorTag
detector tag. forward=0,backward=1
Definition: PMusrT0.h:107
virtual void Quit()
Definition: PMusrT0.cpp:616
Int_t fT0Data
holding the t0 found in the current data set
Definition: PMusrT0.h:111
Int_t fStatus
0=quit locally, i.e. only a single musrt0 raw data canvas will terminate but not the application...
Definition: PMusrT0.h:150
void ShowDataFileT0Channel()
Definition: PMusrT0.cpp:800
virtual Int_t GetRunNo()
Definition: PMusrT0.h:74
Int_t fDataRange[2]
data range (first good bin, last good bin)
Definition: PMusrT0.h:180
std::unique_ptr< TLine > fLastDataLine
line showing the end of the data (last good data bin)
Definition: PMusrT0.h:175
#define PMUSRT0_GET_T0_DATA_AND_BKG_RANGE
Definition: PMusrT0.h:56
void HideDataFileT0Channel()
Definition: PMusrT0.cpp:823
#define PMUSRT0_FORWARD
Definition: PMusrT0.h:51
virtual PRawRunData * GetRawRunData(Int_t idx)
Definition: PMusrT0.cpp:105
virtual void Done(Int_t status=0)
Definition: PMusrT0.cpp:540
std::unique_ptr< TLine > fFirstBkgLine
line showing the start of the background
Definition: PMusrT0.h:172
std::vector< PIntVector > fAddT0
holding the t0&#39;s of the addruns
Definition: PMusrT0.h:110
void SetBkgLastChannel()
Definition: PMusrT0.cpp:1059
virtual Int_t GetHistoNo(UInt_t idx)
Definition: PMusrT0.cpp:125
virtual const PDoubleVector * GetDataBin(const UInt_t histoNo)
Definition: PMusr.h:438
#define PMUSRT0_BACKWARD
Definition: PMusrT0.h:52
std::unique_ptr< TLine > fLastBkgLine
line showing the end of the background
Definition: PMusrT0.h:173
virtual void SetMsrBkgRangeEntry(UInt_t runNo, UInt_t idx, Int_t bin)
Int_t fCmdTag
command tag. 0=get t0, 1=get data-/bkg-range, 2=get t0, and data-/bkg-range
Definition: PMusrT0.h:108
return status
std::unique_ptr< TLatex > fToDoInfo
clear text user instruction string
Definition: PMusrT0.h:168
virtual void InitT0()
Definition: PMusrT0.cpp:663
virtual Int_t GetHistoNoIdx()
Definition: PMusrT0.h:76
std::unique_ptr< TH1F > fBkg
histogram starting from &#39;bkg start&#39; up to &#39;bkg end&#39;
Definition: PMusrT0.h:166
virtual Int_t GetT0Bin(UInt_t idx)
Definition: PMusrT0.cpp:145
virtual ~PMusrT0Data()
Definition: PMusrT0.cpp:60
Int_t fBkgRange[2]
background range (first bkg bin, last bkg bin)
Definition: PMusrT0.h:181