diff --git a/src/classes/PMsrHandler.cpp b/src/classes/PMsrHandler.cpp index dba7967b..f804ebc8 100644 --- a/src/classes/PMsrHandler.cpp +++ b/src/classes/PMsrHandler.cpp @@ -324,6 +324,14 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) for (UInt_t i=0; i addt0TagMissing; // needed for proper musrt0 handling + PBoolVector bvec; + for (UInt_t i=0; i 0) { fout.width(8); - fout << left << fRuns[runNo].GetBkgRange(j)+1; // +1 since internally the data start at 0 + fout << left << fRuns[runNo].GetBkgRange(j); } } fout << endl; @@ -737,7 +745,7 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) for (UInt_t j=0; j<4; j++) { if (fRuns[runNo].GetDataRange(j) > 0) { fout.width(8); - fout << left << fRuns[runNo].GetDataRange(j)+1; // +1 since internally the data start at 0 + fout << left << fRuns[runNo].GetDataRange(j); } } fout << endl; @@ -747,10 +755,11 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) fout << left << "t0"; for (UInt_t j=0; j> PMsrHandler::WriteMsrLogFile: **WARNING** 'addt0' tag without any data found!"; cerr << endl << ">> Something is VERY fishy, please check your msr-file carfully." << endl; @@ -759,7 +768,7 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) fout << left << "addt0"; for (Int_t j=0; j 0) { fout.width(16); @@ -798,13 +807,26 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) fout << endl; } } + for (UInt_t i=0; i 0) { + fout.width(16); + fout << left << "addt0"; + for (Int_t j=0; j= 0) { fout.width(16); fout << left << "background"; for (UInt_t j=0; j<2; j++) { fout.width(8); - fout << left << fRuns[runNo].GetBkgRange(j)+1; // +1 since internally the data start at 0 + fout << left << fRuns[runNo].GetBkgRange(j); } fout << endl; } @@ -815,7 +837,7 @@ Int_t PMsrHandler::WriteMsrLogFile(const Bool_t messages) fout << left << "data"; for (UInt_t j=0; j<2; j++) { fout.width(8); - fout << left << fRuns[runNo].GetDataRange(j)+1; // +1 since internally the data start at 0 + fout << left << fRuns[runNo].GetDataRange(j); } fout << endl; } @@ -1209,21 +1231,55 @@ Bool_t PMsrHandler::SetMsrParamPosError(UInt_t i, Double_t value) */ void PMsrHandler::SetMsrT0Entry(UInt_t runNo, UInt_t idx, Int_t bin) { - if ((runNo < 0) || (runNo > fRuns.size())) { // error - cerr << endl << "PMsrHandler::SetMsrT0Entry: **ERROR** runNo = " << runNo << ", is out of valid range 0.." << fRuns.size(); + if (runNo >= fRuns.size()) { // error + cerr << endl << ">> PMsrHandler::SetMsrT0Entry: **ERROR** runNo = " << runNo << ", is out of valid range 0.." << fRuns.size(); cerr << endl; return; } - if ((idx < 0) || (idx > fRuns[runNo].GetT0Size())) { // error - cerr << endl << "PMsrHandler::SetMsrT0Entry: **ERROR** idx = " << idx << ", is out of valid range 0.." << fRuns[runNo].GetT0Size(); + if (idx >= fRuns[runNo].GetT0Size()) { // error + cerr << endl << ">> PMsrHandler::SetMsrT0Entry: **WARNING** idx = " << idx << ", is out of valid range 0.." << fRuns[runNo].GetT0Size(); + cerr << endl << ">> Will add it anyway."; cerr << endl; - return; } fRuns[runNo].SetT0(bin, idx); } +//-------------------------------------------------------------------------- +// SetMsrAddT0Entry (public) +//-------------------------------------------------------------------------- +/** + *

Sets a t0 value for an addrun entry. + * + * \param runNo msr-file run number + * \param addRunIdx msr-file addrun index, e.g. if 2 addruns are present addRunIdx can take the values 0 or 1. + * \param histoIdx msr-file histogram index for an addrun. + * \param bin histogram t0 value. + */ +void PMsrHandler::SetMsrAddT0Entry(UInt_t runNo, UInt_t addRunIdx, UInt_t histoIdx, Int_t bin) +{ + if (runNo >= fRuns.size()) { // error + cerr << endl << ">> PMsrHandler::SetMsrAddT0Entry: **ERROR** runNo = " << runNo << ", is out of valid range 0.." << fRuns.size(); + cerr << endl; + return; + } + + if (addRunIdx >= fRuns[runNo].GetAddT0Entries()) { // error + cerr << endl << ">> PMsrHandler::SetMsrAddT0Entry: **WARNING** addRunIdx = " << addRunIdx << ", is out of valid range 0.." << fRuns[runNo].GetAddT0Entries(); + cerr << endl << ">> Will add it anyway."; + cerr << endl; + } + + if (histoIdx > fRuns[runNo].GetAddT0Size(addRunIdx)) { // error + cerr << endl << ">> PMsrHandler::SetMsrAddT0Entry: **WARNING** histoIdx = " << histoIdx << ", is out of valid range 0.." << fRuns[runNo].GetAddT0Size(addRunIdx); + cerr << endl << ">> Will add it anyway."; + cerr << endl; + } + + fRuns[runNo].SetAddT0(bin, addRunIdx, histoIdx); +} + //-------------------------------------------------------------------------- // SetMsrDataRangeEntry (public) //-------------------------------------------------------------------------- @@ -1236,18 +1292,12 @@ void PMsrHandler::SetMsrT0Entry(UInt_t runNo, UInt_t idx, Int_t bin) */ void PMsrHandler::SetMsrDataRangeEntry(UInt_t runNo, UInt_t idx, Int_t bin) { - if ((runNo < 0) || (runNo > fRuns.size())) { // error + if (runNo > fRuns.size()) { // error cerr << endl << "PMsrHandler::SetMsrDataRangeEntry: **ERROR** runNo = " << runNo << ", is out of valid range 0.." << fRuns.size(); cerr << endl; return; } - if (idx < 0) { // error - cerr << endl << "PMsrHandler::SetMsrDataRangeEntry: **ERROR** idx = " << idx << ", is out of valid range, i.e. idx >= 0 needed."; - cerr << endl; - return; - } - fRuns[runNo].SetDataRange(bin, idx); } @@ -1263,18 +1313,12 @@ void PMsrHandler::SetMsrDataRangeEntry(UInt_t runNo, UInt_t idx, Int_t bin) */ void PMsrHandler::SetMsrBkgRangeEntry(UInt_t runNo, UInt_t idx, Int_t bin) { - if ((runNo < 0) || (runNo > fRuns.size())) { // error + if (runNo > fRuns.size()) { // error cerr << endl << "PMsrHandler::SetMsrBkgRangeEntry: **ERROR** runNo = " << runNo << ", is out of valid range 0.." << fRuns.size(); cerr << endl; return; } - if (idx < 0) { // error - cerr << endl << "PMsrHandler::SetMsrBkgRangeEntry: idx = " << idx << ", is out of valid range, i.e. idx >= 0 needed."; - cerr << endl; - return; - } - fRuns[runNo].SetBkgRange(bin, idx); } @@ -3740,6 +3784,32 @@ Bool_t PMsrHandler::CheckHistoGrouping() break; } } + // check grouping entries are not identical, e.g. forward 1 1 2 + if (fRuns[i].GetForwardHistoNoSize() > 1) { + for (UInt_t j=0; j> PMsrHandler::CheckHistoGrouping: **WARNING** grouping identical histograms!!"; + cerr << endl << ">> run no " << i+1 << ", forward histo " << j+1 << " == forward histo " << k+1 << "."; + cerr << endl << ">> this really doesn't make any sense, but you are the boss."; + cerr << endl; + } + } + } + } + + if (fRuns[i].GetBackwardHistoNoSize() > 1) { + for (UInt_t j=0; j> PMsrHandler::CheckHistoGrouping: **WARNING** grouping identical histograms!!"; + cerr << endl << ">> run no " << i+1 << ", backward histo " << j+1 << " == backward histo " << k+1 << "."; + cerr << endl << ">> this really doesn't make any sense, but you are the boss."; + cerr << endl; + } + } + } + } } return result; diff --git a/src/classes/PMusr.cpp b/src/classes/PMusr.cpp index bf3af33d..6a940ce7 100644 --- a/src/classes/PMusr.cpp +++ b/src/classes/PMusr.cpp @@ -317,7 +317,7 @@ const Int_t PRawRunData::GetT0(const UInt_t idx) cerr << endl; return -1; } - return fT0s[idx]-1; // -1 because the counting of the data vector starts at 0! + return fT0s[idx]; } //-------------------------------------------------------------------------- @@ -335,7 +335,7 @@ const Int_t PRawRunData::GetT0Estimated(const UInt_t idx) cerr << endl; return -1; } - return fT0Estimated[idx]-1; // -1 because the counting of the data vector starts at 0! + return fT0Estimated[idx]; } //-------------------------------------------------------------------------- @@ -354,8 +354,8 @@ const PIntPair PRawRunData::GetBkgBin(const UInt_t idx) return pair; } - pair.first = fBkgBin[idx].first - 1; // -1 because the counting of the data vector starts at 0! - pair.second = fBkgBin[idx].second - 1; // -1 because the counting of the data vector starts at 0! + pair.first = fBkgBin[idx].first; + pair.second = fBkgBin[idx].second; return pair; } @@ -376,8 +376,8 @@ const PIntPair PRawRunData::GetGoodDataBin(const UInt_t idx) return pair; } - pair.first = fGoodDataBin[idx].first - 1; // -1 because the counting of the data vector starts at 0! - pair.second = fGoodDataBin[idx].second - 1; // -1 because the counting of the data vector starts at 0! + pair.first = fGoodDataBin[idx].first; + pair.second = fGoodDataBin[idx].second; return pair; } @@ -1062,7 +1062,7 @@ Int_t PMsrRunBlock::GetBkgRange(UInt_t idx) return -1; } - return fBkgRange[idx]-1; // -1 because the counting of the data vector starts at 0! + return fBkgRange[idx]; } //-------------------------------------------------------------------------- @@ -1100,7 +1100,7 @@ Int_t PMsrRunBlock::GetDataRange(UInt_t idx) return -1; } - return fDataRange[idx]-1; // -1 because the counting of the data vector starts at 0! + return fDataRange[idx]; } //-------------------------------------------------------------------------- @@ -1133,10 +1133,10 @@ void PMsrRunBlock::SetDataRange(Int_t ival, Int_t idx) */ Int_t PMsrRunBlock::GetT0(UInt_t idx) { - if (idx>fT0.size()) + if (idx >= fT0.size()) return -1; - return fT0[idx]-1; // -1 because the counting of the data vector starts at 0! + return fT0[idx]; } //-------------------------------------------------------------------------- @@ -1174,7 +1174,7 @@ Int_t PMsrRunBlock::GetAddT0Size(UInt_t addRunIdx) if (fAddT0.empty()) return -1; - if (addRunIdx > fAddT0.size()) + if (addRunIdx >= fAddT0.size()) return -1; return fAddT0[addRunIdx].size(); @@ -1194,16 +1194,16 @@ Int_t PMsrRunBlock::GetAddT0(UInt_t addRunIdx, UInt_t histoIdx) if (fAddT0.empty()) return -1; - if (addRunIdx > fAddT0.size()) + if (addRunIdx >= fAddT0.size()) return -1; if (fAddT0[addRunIdx].empty()) return -1; - if (histoIdx > fAddT0[addRunIdx].size()) + if (histoIdx >= fAddT0[addRunIdx].size()) return -1; - return fAddT0[addRunIdx][histoIdx]-1; // -1 because the counting of the data vector starts at 0! + return fAddT0[addRunIdx][histoIdx]; } //-------------------------------------------------------------------------- diff --git a/src/classes/PMusrT0.cpp b/src/classes/PMusrT0.cpp index c8778a8b..1e0f6c41 100644 --- a/src/classes/PMusrT0.cpp +++ b/src/classes/PMusrT0.cpp @@ -42,8 +42,167 @@ using namespace std; #define DETECTOR_TAG_FORWARD 0 #define DETECTOR_TAG_BACKWARD 1 -#define DETECTOR_TAG_RIGHT 2 -#define DETECTOR_TAG_LEFT 3 + +//-------------------------------------------------------------------------- +// Constructor +//-------------------------------------------------------------------------- +/** + * + */ +PMusrT0Data::PMusrT0Data() +{ + InitData(); +} + +//-------------------------------------------------------------------------- +// Destructor +//-------------------------------------------------------------------------- +/** + * + */ +PMusrT0Data::~PMusrT0Data() +{ + fRawRunData.clear(); + fHistoNo.clear(); + fT0.clear(); + for (UInt_t i=0; i= static_cast(fRawRunData.size()))) + return 0; + + return fRawRunData[idx]; +} + +//-------------------------------------------------------------------------- +// GetHistoNo +//-------------------------------------------------------------------------- +/** + * + */ +Int_t PMusrT0Data::GetHistoNo(UInt_t idx) +{ + if (idx >= fHistoNo.size()) + return -1; + + return fHistoNo[idx]; +} + +//-------------------------------------------------------------------------- +// GetT0 +//-------------------------------------------------------------------------- +/** + * + */ +Int_t PMusrT0Data::GetT0(UInt_t idx) +{ + if (idx >= fT0.size()) + return -1; + + return fT0[idx]; +} + +//-------------------------------------------------------------------------- +// GetAddT0Size +//-------------------------------------------------------------------------- +/** + * + */ +UInt_t PMusrT0Data::GetAddT0Size(UInt_t idx) +{ + if (idx >= fAddT0.size()) + return 0; + + return fAddT0[idx].size(); +} + +//-------------------------------------------------------------------------- +// GetAddT0 +//-------------------------------------------------------------------------- +/** + * + */ +Int_t PMusrT0Data::GetAddT0(UInt_t addRunIdx, UInt_t idx) +{ + if (addRunIdx >= fAddT0.size()) + return -1; + + if (idx >= fAddT0[addRunIdx].size()) + return -1; + + return fAddT0[addRunIdx][idx]; +} + +//-------------------------------------------------------------------------- +// SetT0 +//-------------------------------------------------------------------------- +/** + * + */ +void PMusrT0Data::SetT0(UInt_t val, UInt_t idx) +{ +//cout << endl << "debug+> SetT0: size=" << fT0.size(); +//cout << endl << "debug+> SetT0: val=" << val << ", idx=" << idx << endl; + + if (idx >= fT0.size()) + fT0.resize(idx+1); + + fT0[idx] = val; +} + +//-------------------------------------------------------------------------- +// SetAddT0 +//-------------------------------------------------------------------------- +/** + * + */ +void PMusrT0Data::SetAddT0(UInt_t val, UInt_t addRunIdx, UInt_t idx) +{ +//cout << endl << "debug+> SetAddT0: size=" << fAddT0.size(); +//cout << endl << "debug+> SetAddT0: val=" << val << ", addRunIdx=" << addRunIdx << ", idx=" << idx << endl; + + if (addRunIdx >= fAddT0.size()) + fAddT0.resize(addRunIdx+1); + + if (idx >= fAddT0[addRunIdx].size()) + fAddT0[addRunIdx].resize(idx+1); + + fAddT0[addRunIdx][idx] = val; +} + +//-------------------------------------------------------------------------- ClassImpQ(PMusrT0) @@ -55,8 +214,9 @@ ClassImpQ(PMusrT0) */ PMusrT0::PMusrT0() { - fRunNo = -1; - fDetectorTag = -1; + fValid = false; + + fStatus = 0; // default is quit locally fMainCanvas = 0; @@ -64,6 +224,11 @@ PMusrT0::PMusrT0() fData = 0; fBkg = 0; + fToDoInfo = 0; + + fDataAndBkgEnabled = false; + fT0Enabled = false; + fDataRange[0] = 0; fDataRange[1] = 0; fBkgRange[0] = 0; @@ -80,40 +245,241 @@ PMusrT0::PMusrT0() // Constructor //-------------------------------------------------------------------------- /** + *

* - * \param rawRunData - * \param histoNo + * \param data */ -PMusrT0::PMusrT0(PRawRunData *rawRunData, Int_t runNo, Int_t histoNo, Int_t detectorTag, Int_t addRunNo) : - fRunNo(runNo), fDetectorTag(detectorTag), fAddRunNo(addRunNo) +PMusrT0::PMusrT0(PMusrT0Data &data) : fMusrT0Data(data) { -cout << endl << "run Name = " << rawRunData->GetRunName()->Data() << ", runNo = " << fRunNo << ", histoNo = " << histoNo << endl; + fValid = true; fStatus = 0; // default is quit locally - fAddRunOffset = 0; + fMainCanvas = 0; - TString str = *rawRunData->GetRunName() + TString(" : "); - str += histoNo; + fHisto = 0; + fData = 0; + fBkg = 0; + + fToDoInfo = 0; + + fDataAndBkgEnabled = false; + fT0Enabled = false; + + fDataRange[0] = 0; + fDataRange[1] = 0; + fBkgRange[0] = 0; + fBkgRange[1] = 0; + + fT0Line = 0; + fFirstBkgLine = 0; + fLastBkgLine = 0; + fFirstDataLine = 0; + fLastDataLine = 0; // feed necessary objects + TString str; - // feed raw data histo - Int_t noOfBins = rawRunData->GetDataBin(histoNo-1)->size(); - Double_t start = -0.5; - Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0 - fHisto = new TH1F("fHisto", str.Data(), noOfBins, start, end); - fHisto->SetMarkerStyle(21); - fHisto->SetMarkerSize(0.5); - fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black + if ((fMusrT0Data.GetCmdTag() == PMUSRT0_GET_T0) || (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_T0_DATA_AND_BKG_RANGE)) { + str = *fMusrT0Data.GetRawRunData(fMusrT0Data.GetAddRunIdx())->GetRunName() + TString(" : "); + str += fMusrT0Data.GetHistoNo(fMusrT0Data.GetHistoNoIdx()); + if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD) + str += " (f)"; + else + str += " (b)"; + str += ", msr runNo = "; + str += fMusrT0Data.GetRunNo()+1; + + + // feed raw data histo + PRawRunData *rawRunData = fMusrT0Data.GetRawRunData(fMusrT0Data.GetAddRunIdx()); + if (rawRunData == 0) { + fValid = false; + return; + } + Int_t histoNo = fMusrT0Data.GetHistoNo(fMusrT0Data.GetHistoNoIdx())-1; + Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size(); + Double_t start = -0.5; + Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0 + fHisto = new TH1F("fHisto", str.Data(), noOfBins, start, end); + fHisto->SetMarkerStyle(21); + fHisto->SetMarkerSize(0.5); + fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black + + Double_t maxVal = 0.0; + fT0Estimated = 0; + for (UInt_t i=0; iGetDataBin(histoNo)->size(); i++) { + fHisto->SetBinContent(i+1, rawRunData->GetDataBin(histoNo)->at(i)); + if (rawRunData->GetDataBin(histoNo)->at(i) > maxVal) { + maxVal = rawRunData->GetDataBin(histoNo)->at(i); + fT0Estimated = i; + } + } + } else { +/* +cout << endl << "debug> all t0's:" << endl; +for (UInt_t i=0; i all addt0's:" << endl; +for (UInt_t j=0; j j=" << j << endl; + for (UInt_t i=0; iGetRunName() + TString(" : "); + if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD) + str += " forward grouped and runs added"; + else + str += " backward grouped and runs added"; + str += ", msr runNo = "; + str += fMusrT0Data.GetRunNo()+1; + + // feed raw data histo + PRawRunData *rawRunData = fMusrT0Data.GetRawRunData(0); + if (rawRunData == 0) { + fValid = false; + return; + } + + // get run and first histo of grouping and feed it into fHisto + Int_t histoNo = fMusrT0Data.GetHistoNo(0)-1; + Int_t noOfBins = rawRunData->GetDataBin(histoNo)->size(); + Double_t start = -0.5; + Double_t end = noOfBins - 0.5; // -0.5 is correct since the data start at 0.0 + fHisto = new TH1F("fHisto", str.Data(), noOfBins, start, end); + fHisto->SetMarkerStyle(21); + fHisto->SetMarkerSize(0.5); + fHisto->SetMarkerColor(TColor::GetColor(0,0,0)); // black + + // sum up all necessary histograms by taking care of the proper t0's + Int_t t00; + Int_t t0; + Double_t dval; + + // check if asymmetry fit + UInt_t factor=1; + if (!fMusrT0Data.IsSingleHisto()) + factor=2; + + if (fMusrT0Data.GetDetectorTag() == PMUSRT0_FORWARD) + t00 = fMusrT0Data.GetT0(0); + else + t00 = fMusrT0Data.GetT0(1); + + // check if there are addruns and grouping + if ((fMusrT0Data.GetRawRunDataSize() > 1) && (fMusrT0Data.GetHistoNoSize() > 1)) { // addruns and grouping present + + for (Int_t i=0; i 0) && (i+t0-t00 < static_cast(rawRunData->GetDataBin(histoNo)->size()))) + dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00); + + for (UInt_t j=1; j 0) && (i+t0-t00 < static_cast(rawRunData->GetDataBin(histoNo)->size()))) + dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00); + } + } + // set bin value of fHisto + fHisto->SetBinContent(i+1, dval); + } + + } else if (fMusrT0Data.GetRawRunDataSize() > 1) { // only addruns present + + for (Int_t i=0; i 0) && (i+t0-t00 < static_cast(rawRunData->GetDataBin(histoNo)->size()))) + dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00); + + for (UInt_t j=1; j 0) && (i+t0-t00 < static_cast(rawRunData->GetDataBin(histoNo)->size()))) + dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00); + } + // set bin value of fHisto + fHisto->SetBinContent(i+1, dval); + } + + } else if (fMusrT0Data.GetHistoNoSize() > 1) { // only grouping persent + + for (Int_t i=0; i 0) && (i+t0-t00 < static_cast(rawRunData->GetDataBin(histoNo)->size()))) + dval += rawRunData->GetDataBin(histoNo)->at(i+t0-t00); + + } + // set bin value of fHisto + fHisto->SetBinContent(i+1, dval); + } - Double_t maxVal = 0.0; - fT0Estimated = 0; - for (UInt_t i=0; iGetDataBin(histoNo-1)->size(); i++) { - fHisto->SetBinContent(i+1, rawRunData->GetDataBin(histoNo-1)->at(i)); - if (rawRunData->GetDataBin(histoNo-1)->at(i) > maxVal) { - maxVal = rawRunData->GetDataBin(histoNo-1)->at(i); - fT0Estimated = i; } } @@ -121,13 +487,46 @@ cout << endl << "run Name = " << rawRunData->GetRunName()->Data() << ", runNo = fMainCanvas = new TCanvas("fMainCanvas", str); fMainCanvas->SetFillColor(TColor::GetColor(255,255,255)); + fMainCanvas->Show(); fMainCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "PMusrT0", this, "HandleCmdKey(Int_t,Int_t,Int_t,TObject*)"); + if (fMusrT0Data.GetCmdTag() != PMUSRT0_GET_T0) + fDataAndBkgEnabled = true; + else + fDataAndBkgEnabled = false; + + if (fMusrT0Data.GetCmdTag() != PMUSRT0_GET_DATA_AND_BKG_RANGE) + fT0Enabled = true; + else + fT0Enabled = false; + + // do not show root statistics block + fHisto->SetStats(kFALSE); + // draw histos etc fHisto->Draw("p0 9 hist"); + + if (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_T0) { + str = "please set t0 bin only."; + fToDoInfo = new TLatex(); + fToDoInfo->SetTextFont(51); + fToDoInfo->SetTextSize(0.030); + fToDoInfo->SetLineWidth(2); + fToDoInfo->SetNDC(kTRUE); + fToDoInfo->DrawLatex(0.1, 0.91, str.Data()); + } + if (fMusrT0Data.GetCmdTag() == PMUSRT0_GET_DATA_AND_BKG_RANGE) { + str = "please set data and bkg range."; + fToDoInfo = new TLatex(); + fToDoInfo->SetTextFont(51); + fToDoInfo->SetTextSize(0.030); + fToDoInfo->SetLineWidth(2); + fToDoInfo->SetNDC(kTRUE); + fToDoInfo->DrawLatex(0.1, 0.91, str.Data()); + } } //-------------------------------------------------------------------------- @@ -150,6 +549,10 @@ PMusrT0::~PMusrT0() delete fBkg; fBkg = 0; } + if (fToDoInfo) { + delete fToDoInfo; + fToDoInfo = 0; + } if (fT0Line) { delete fT0Line; fT0Line = 0; @@ -212,6 +615,8 @@ void PMusrT0::HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected) Done(0); } else if (x == 'u') { // unzoom to the original range UnZoom(); + } else if (x == 'z') { // zoom to the region around t0, and the estimated t0 + ZoomT0(); } else if (x == 'T') { // set estimated t0 channel SetEstimatedT0Channel(); } else if (x == 't') { // set t0 channel @@ -237,8 +642,50 @@ void PMusrT0::HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected) void PMusrT0::SetMsrHandler(PMsrHandler *msrHandler) { fMsrHandler = msrHandler; +} - InitDataAndBkg(); +//-------------------------------------------------------------------------- +// InitT0 +//-------------------------------------------------------------------------- +/** + *

+ * + */ +void PMusrT0::InitT0() +{ + // t0 line + Int_t t0Bin = 0; + Int_t histoIdx = fMusrT0Data.GetHistoNoIdx(); + Int_t addRunIdx = fMusrT0Data.GetAddRunIdx(); + UInt_t factor=1; + if (!fMusrT0Data.IsSingleHisto()) + factor=2; + switch (fMusrT0Data.GetDetectorTag() ) { + case PMUSRT0_FORWARD: + if (addRunIdx == 0) + t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetT0(factor*histoIdx); + else if (addRunIdx > 0) + t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetAddT0(addRunIdx-1, factor*histoIdx); + break; + case PMUSRT0_BACKWARD: + if (addRunIdx == 0) + t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetT0(factor*histoIdx+1); + else if (addRunIdx > 0) + t0Bin = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetAddT0(addRunIdx-1, factor*histoIdx+1); + break; + default: + // not clear yet what to be done + break; + } + Double_t max = fHisto->GetMaximum(); + +//cout << "debug-> histoIdx=" << histoIdx << ", addRunIdx=" << addRunIdx << ", t0Bin=" << t0Bin << endl; + + fT0Line = new TLine((Double_t)t0Bin, 0.0, (Double_t)t0Bin, max); + fT0Line->SetLineStyle(1); // solid + fT0Line->SetLineColor(TColor::GetColor(0,255,0)); // green + fT0Line->SetLineWidth(2); + fT0Line->Draw(); } //-------------------------------------------------------------------------- @@ -250,31 +697,15 @@ void PMusrT0::SetMsrHandler(PMsrHandler *msrHandler) */ void PMusrT0::InitDataAndBkg() { - // get addRun offset which depends on the fit type - Int_t fitType = fMsrHandler->GetMsrRunList()->at(fRunNo).GetFitType(); - if (fitType == MSR_FITTYPE_SINGLE_HISTO) { - fAddRunOffset = 2; - } else if (fitType == MSR_FITTYPE_ASYM) { - fAddRunOffset = 4; - } else if (fitType == MSR_FITTYPE_MU_MINUS) { - fAddRunOffset = 2; - } - // feed data range histo - switch (fDetectorTag) { - case DETECTOR_TAG_FORWARD: - fDataRange[0] = fMsrHandler->GetMsrRunList()->at(fRunNo).GetDataRange(0 + fAddRunNo * fAddRunOffset); - fDataRange[1] = fMsrHandler->GetMsrRunList()->at(fRunNo).GetDataRange(1 + fAddRunNo * fAddRunOffset); + switch (fMusrT0Data.GetDetectorTag()) { + case PMUSRT0_FORWARD: + fDataRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(0); + fDataRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(1); break; - case DETECTOR_TAG_BACKWARD: - fDataRange[0] = fMsrHandler->GetMsrRunList()->at(fRunNo).GetDataRange(2 + fAddRunNo * fAddRunOffset); - fDataRange[1] = fMsrHandler->GetMsrRunList()->at(fRunNo).GetDataRange(3 + fAddRunNo * fAddRunOffset); - break; - case DETECTOR_TAG_RIGHT: - // not clear yet what to be done - break; - case DETECTOR_TAG_LEFT: - // not clear yet what to be done + case PMUSRT0_BACKWARD: + fDataRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(2); + fDataRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetDataRange(3); break; default: // not clear yet what to be done @@ -295,20 +726,14 @@ void PMusrT0::InitDataAndBkg() fData->Draw("p0 9 hist same"); // feed background histo - switch (fDetectorTag) { - case DETECTOR_TAG_FORWARD: - fBkgRange[0] = fMsrHandler->GetMsrRunList()->at(fRunNo).GetBkgRange(0 + fAddRunNo * fAddRunOffset); - fBkgRange[1] = fMsrHandler->GetMsrRunList()->at(fRunNo).GetBkgRange(1 + fAddRunNo * fAddRunOffset); + switch (fMusrT0Data.GetDetectorTag()) { + case PMUSRT0_FORWARD: + fBkgRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(0); + fBkgRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(1); break; - case DETECTOR_TAG_BACKWARD: - fBkgRange[0] = fMsrHandler->GetMsrRunList()->at(fRunNo).GetBkgRange(2 + fAddRunNo * fAddRunOffset); - fBkgRange[1] = fMsrHandler->GetMsrRunList()->at(fRunNo).GetBkgRange(3 + fAddRunNo * fAddRunOffset); - break; - case DETECTOR_TAG_RIGHT: - // not clear yet what to be done - break; - case DETECTOR_TAG_LEFT: - // not clear yet what to be done + case PMUSRT0_BACKWARD: + fBkgRange[0] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(2); + fBkgRange[1] = fMsrHandler->GetMsrRunList()->at(fMusrT0Data.GetRunNo()).GetBkgRange(3); break; default: // not clear yet what to be done @@ -329,31 +754,7 @@ void PMusrT0::InitDataAndBkg() fBkg->Draw("p0 9 hist same"); // add lines - // t0 line - Int_t t0Bin = 0; - switch (fDetectorTag) { - case DETECTOR_TAG_FORWARD: - t0Bin = fMsrHandler->GetMsrRunList()->at(fRunNo).GetT0(0 + fAddRunNo * fAddRunOffset/2); - break; - case DETECTOR_TAG_BACKWARD: - t0Bin = fMsrHandler->GetMsrRunList()->at(fRunNo).GetT0(1 + fAddRunNo * fAddRunOffset/2); - break; - case DETECTOR_TAG_RIGHT: - // not clear yet what to be done - break; - case DETECTOR_TAG_LEFT: - // not clear yet what to be done - break; - default: - // not clear yet what to be done - break; - } Double_t max = fHisto->GetMaximum(); - fT0Line = new TLine((Double_t)t0Bin, 0.0, (Double_t)t0Bin, max); - fT0Line->SetLineStyle(1); // solid - fT0Line->SetLineColor(TColor::GetColor(0,255,0)); // green - fT0Line->SetLineWidth(2); - fT0Line->Draw(); // data lines fFirstDataLine = new TLine((Double_t)fDataRange[0], 0.0, (Double_t)fDataRange[0], max); @@ -393,33 +794,35 @@ void PMusrT0::InitDataAndBkg() */ void PMusrT0::SetT0Channel() { + if (!fT0Enabled) + return; + Double_t x=0, y=0; fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y); // get binx to set t0 corresponding to fPx Int_t binx = fHisto->GetXaxis()->FindFixBin(x) - 1; -cout << endl << ">> PMusrT0::SetT0Channel(): binx = " << binx << endl; + cout << endl << ">> PMusrT0::SetT0Channel(): t0 = " << binx << endl; // set t0 bin in msr-Handler - UInt_t idx = 0; - switch(fDetectorTag) { - case DETECTOR_TAG_FORWARD: - idx = fAddRunNo * fAddRunOffset / 2; - break; - case DETECTOR_TAG_BACKWARD: - idx = 1 + fAddRunNo * fAddRunOffset / 2; - break; - case DETECTOR_TAG_LEFT: - idx = 2 + fAddRunNo * fAddRunOffset / 2; - break; - case DETECTOR_TAG_RIGHT: - idx = 3 + fAddRunNo * fAddRunOffset / 2; - break; - default: - break; + UInt_t idx; + if (fMusrT0Data.IsSingleHisto()) { + idx = fMusrT0Data.GetHistoNoIdx(); + if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD) + idx += 1; + } else { + idx = 2*fMusrT0Data.GetHistoNoIdx(); + if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD) + idx += 1; } - fMsrHandler->SetMsrT0Entry(fRunNo, idx, binx); + +//cout << endl << "debug> SetT0Channel: t0-idx=" << idx << ", t0-value=" << binx; + + if (fMusrT0Data.GetAddRunIdx() == 0) + fMsrHandler->SetMsrT0Entry(fMusrT0Data.GetRunNo(), idx, binx); + else if (fMusrT0Data.GetAddRunIdx() > 0) + fMsrHandler->SetMsrAddT0Entry(fMusrT0Data.GetRunNo(), fMusrT0Data.GetAddRunIdx()-1, idx, binx); // shift line to the proper position fT0Line->SetX1(x); @@ -438,27 +841,29 @@ cout << endl << ">> PMusrT0::SetT0Channel(): binx = " << binx << endl; */ void PMusrT0::SetEstimatedT0Channel() { - // set t0 bin in msr-Handler - UInt_t idx = 0; - switch(fDetectorTag) { - case DETECTOR_TAG_FORWARD: - idx = fAddRunNo * fAddRunOffset / 2; - break; - case DETECTOR_TAG_BACKWARD: - idx = 1 + fAddRunNo * fAddRunOffset / 2; - break; - case DETECTOR_TAG_LEFT: - idx = 2 + fAddRunNo * fAddRunOffset / 2; - break; - case DETECTOR_TAG_RIGHT: - idx = 3 + fAddRunNo * fAddRunOffset / 2; - break; - default: - break; - } - fMsrHandler->SetMsrT0Entry(fRunNo, idx, fT0Estimated); + if (!fT0Enabled) + return; - Double_t x = fHisto->GetXaxis()->GetBinCenter(fT0Estimated); + // set t0 bin in msr-Handler + UInt_t idx; + if (fMusrT0Data.IsSingleHisto()) { + idx = fMusrT0Data.GetHistoNoIdx(); + if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD) + idx += 1; + } else { + idx = 2*fMusrT0Data.GetHistoNoIdx(); + if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD) + idx += 1; + } + + if (fMusrT0Data.GetAddRunIdx() == 0) + fMsrHandler->SetMsrT0Entry(fMusrT0Data.GetRunNo(), idx, fT0Estimated); + else if (fMusrT0Data.GetAddRunIdx() > 0) + fMsrHandler->SetMsrAddT0Entry(fMusrT0Data.GetRunNo(), fMusrT0Data.GetAddRunIdx()-1, idx, fT0Estimated); + + Double_t x = fHisto->GetXaxis()->GetBinCenter(fT0Estimated)+1.0; // +1.0 needed since the first bin == 1 not 0. + + cout << endl << ">> PMusrT0::SetEstimatedT0Channel(): estimated t0 = " << fT0Estimated << endl; // shift line to the proper position fT0Line->SetX1(x); @@ -477,6 +882,9 @@ void PMusrT0::SetEstimatedT0Channel() */ void PMusrT0::SetDataFirstChannel() { + if (!fDataAndBkgEnabled) + return; + Double_t x=0, y=0; fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y); @@ -487,23 +895,9 @@ cout << endl << ">> PMusrT0::SetDataFirstChannel(): fDataRange[0] = " << fDataRa // set the data first bin in msr-Handler UInt_t idx = 0; - switch(fDetectorTag) { - case DETECTOR_TAG_FORWARD: - idx = fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_BACKWARD: - idx = 2 + fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_LEFT: - idx = 4 + fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_RIGHT: - idx = 6 + fAddRunNo * fAddRunOffset; - break; - default: - break; - } - fMsrHandler->SetMsrDataRangeEntry(fRunNo, idx, fDataRange[0]); + if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD) + idx = 2; + fMsrHandler->SetMsrDataRangeEntry(fMusrT0Data.GetRunNo(), idx, fDataRange[0]); // shift line to the proper position fFirstDataLine->SetX1(x); @@ -539,6 +933,9 @@ cout << endl << ">> PMusrT0::SetDataFirstChannel(): fDataRange[0] = " << fDataRa */ void PMusrT0::SetDataLastChannel() { + if (!fDataAndBkgEnabled) + return; + Double_t x=0, y=0; fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y); @@ -548,24 +945,10 @@ void PMusrT0::SetDataLastChannel() cout << endl << ">> PMusrT0::SetDataLastChannel(): fDataRange[1] = " << fDataRange[1] << endl; // set the data first bin in msr-Handler - UInt_t idx = 0; - switch(fDetectorTag) { - case DETECTOR_TAG_FORWARD: - idx = 1 + fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_BACKWARD: - idx = 3 + fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_LEFT: - idx = 5 + fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_RIGHT: - idx = 7 + fAddRunNo * fAddRunOffset; - break; - default: - break; - } - fMsrHandler->SetMsrDataRangeEntry(fRunNo, idx, fDataRange[1]); + UInt_t idx = 1; + if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD) + idx = 3; + fMsrHandler->SetMsrDataRangeEntry(fMusrT0Data.GetRunNo(), idx, fDataRange[1]); // shift line to the proper position fLastDataLine->SetX1(x); @@ -601,6 +984,9 @@ cout << endl << ">> PMusrT0::SetDataLastChannel(): fDataRange[1] = " << fDataRan */ void PMusrT0::SetBkgFirstChannel() { + if (!fDataAndBkgEnabled) + return; + Double_t x=0, y=0; fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y); @@ -611,23 +997,9 @@ cout << endl << ">> PMusrT0::SetBkgFirstChannel(): fBkgRange[0] = " << fBkgRange // set the background first bin in msr-Handler UInt_t idx = 0; - switch(fDetectorTag) { - case DETECTOR_TAG_FORWARD: - idx = fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_BACKWARD: - idx = 2 + fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_LEFT: - idx = 4 + fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_RIGHT: - idx = 6 + fAddRunNo * fAddRunOffset; - break; - default: - break; - } - fMsrHandler->SetMsrBkgRangeEntry(fRunNo, idx, fBkgRange[0]); + if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD) + idx = 2; + fMsrHandler->SetMsrBkgRangeEntry(fMusrT0Data.GetRunNo(), idx, fBkgRange[0]); // shift line to the proper position fFirstBkgLine->SetX1(x); @@ -663,6 +1035,9 @@ cout << endl << ">> PMusrT0::SetBkgFirstChannel(): fBkgRange[0] = " << fBkgRange */ void PMusrT0::SetBkgLastChannel() { + if (!fDataAndBkgEnabled) + return; + Double_t x=0, y=0; fMainCanvas->AbsPixeltoXY(fPx,fPy,x,y); @@ -672,24 +1047,10 @@ void PMusrT0::SetBkgLastChannel() cout << endl << ">> PMusrT0::SetBkgLastChannel(): fBkgRange[1] = " << fBkgRange[1] << endl; // set the background first bin in msr-Handler - UInt_t idx = 0; - switch(fDetectorTag) { - case DETECTOR_TAG_FORWARD: - idx = 1 + fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_BACKWARD: - idx = 3 + fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_LEFT: - idx = 5 + fAddRunNo * fAddRunOffset; - break; - case DETECTOR_TAG_RIGHT: - idx = 7 + fAddRunNo * fAddRunOffset; - break; - default: - break; - } - fMsrHandler->SetMsrBkgRangeEntry(fRunNo, idx, fBkgRange[1]); + UInt_t idx = 1; + if (fMusrT0Data.GetDetectorTag() == PMUSRT0_BACKWARD) + idx = 3; + fMsrHandler->SetMsrBkgRangeEntry(fMusrT0Data.GetRunNo(), idx, fBkgRange[1]); // shift line to the proper position fLastBkgLine->SetX1(x); @@ -731,6 +1092,48 @@ void PMusrT0::UnZoom() fMainCanvas->Update(); } +//-------------------------------------------------------------------------- +// ZoomT0 +//-------------------------------------------------------------------------- +/** + *

+ * + */ +void PMusrT0::ZoomT0() +{ + if (!fT0Enabled) + return; + + const Int_t range = 75; + + // get current t0 position + Double_t t0x = fT0Line->GetX1(); + Int_t t0 = fHisto->GetXaxis()->FindBin(t0x)-1; + + Int_t min = t0 - range; + Int_t max = t0 + range; + + // check if t0 is defined at all + if (t0 <= 0) { + min = fT0Estimated - range; + max = fT0Estimated + range; + } + + if (fT0Estimated < min) { + min = fT0Estimated - range; + } + if (fT0Estimated > max) { + max = fT0Estimated + range; + } + +// cout << endl << "debug> ZoomT0: min=" << min << ", max=" << max << endl; + + fHisto->GetXaxis()->SetRangeUser(min, max); + + fMainCanvas->Modified(); // needed that Update is actually working + fMainCanvas->Update(); +} + //-------------------------------------------------------------------------- // END //-------------------------------------------------------------------------- diff --git a/src/classes/PRunAsymmetry.cpp b/src/classes/PRunAsymmetry.cpp index 0043bc3c..d3b9b3cd 100644 --- a/src/classes/PRunAsymmetry.cpp +++ b/src/classes/PRunAsymmetry.cpp @@ -354,8 +354,8 @@ Bool_t PRunAsymmetry::PrepareData() fT0s.push_back(runData->GetT0Estimated(fRunInfo->GetBackwardHistoNo(i)-1)); cerr << endl << ">> PRunAsymmetry::PrepareData(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!"; cerr << endl << ">> run: " << fRunInfo->GetRunName()->Data(); - cerr << endl << ">> will try the estimated one: forward t0 = " << runData->GetT0Estimated(fRunInfo->GetForwardHistoNo(i)-1)+1; - cerr << endl << ">> will try the estimated one: backward t0 = " << runData->GetT0Estimated(fRunInfo->GetBackwardHistoNo(i)-1)+1; + cerr << endl << ">> will try the estimated one: forward t0 = " << runData->GetT0Estimated(fRunInfo->GetForwardHistoNo(i)-1); + cerr << endl << ">> will try the estimated one: backward t0 = " << runData->GetT0Estimated(fRunInfo->GetBackwardHistoNo(i)-1); cerr << endl << ">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!"; cerr << endl; } @@ -370,7 +370,7 @@ Bool_t PRunAsymmetry::PrepareData() fT0s.push_back(runData->GetT0Estimated(fRunInfo->GetForwardHistoNo(i)-1)); cerr << endl << ">> PRunSingleHisto::PrepareData(): **WARNING** NO t0's found, neither in the run data nor in the msr-file!"; cerr << endl << ">> run: " << fRunInfo->GetRunName()->Data(); - cerr << endl << ">> will try the estimated one: t0 = " << runData->GetT0Estimated(fRunInfo->GetForwardHistoNo(i)-1)+1; + cerr << endl << ">> will try the estimated one: t0 = " << runData->GetT0Estimated(fRunInfo->GetForwardHistoNo(i)-1); cerr << endl << ">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!"; cerr << endl; } @@ -380,7 +380,7 @@ Bool_t PRunAsymmetry::PrepareData() fT0s.push_back(runData->GetT0Estimated(fRunInfo->GetBackwardHistoNo(i)-1)); cerr << endl << ">> PRunSingleHisto::PrepareData(): **WARNING** NO t0's found, neither in the run data nor in the msr-file!"; cerr << endl << ">> run: " << fRunInfo->GetRunName()->Data(); - cerr << endl << ">> will try the estimated one: t0 = " << runData->GetT0Estimated(fRunInfo->GetBackwardHistoNo(i)-1)+1; + cerr << endl << ">> will try the estimated one: t0 = " << runData->GetT0Estimated(fRunInfo->GetBackwardHistoNo(i)-1); cerr << endl << ">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!"; cerr << endl; } @@ -394,14 +394,14 @@ Bool_t PRunAsymmetry::PrepareData() if (fabs(fRunInfo->GetT0(2*i)-runData->GetT0(fRunInfo->GetForwardHistoNo(i)-1))>5.0) { cerr << endl << ">> PRunAsymmetry::PrepareData(): **WARNING**: forward histo #" << i+1; cerr << endl << ">> t0 from the msr-file is " << fRunInfo->GetT0(2*i)+1; - cerr << endl << ">> t0 from the data file is " << runData->GetT0(fRunInfo->GetForwardHistoNo(i)-1)+1; + cerr << endl << ">> t0 from the data file is " << runData->GetT0(fRunInfo->GetForwardHistoNo(i)-1); cerr << endl << ">> This is quite a deviation! Is this done intentionally??"; cerr << endl; } if (fabs(fRunInfo->GetT0(2*i+1)-runData->GetT0(fRunInfo->GetBackwardHistoNo(i)-1))>5.0) { // given in bins!! cerr << endl << ">> PRunAsymmetry::PrepareData(): **WARNING**: backward histo #" << i+1; cerr << endl << ">> t0 from the msr-file is " << fRunInfo->GetT0(2*i+1)+1; - cerr << endl << ">> t0 from the data file is " << runData->GetT0(fRunInfo->GetBackwardHistoNo(i)-1)+1; + cerr << endl << ">> t0 from the data file is " << runData->GetT0(fRunInfo->GetBackwardHistoNo(i)-1); cerr << endl << ">> This is quite a deviation! Is this done intentionally??"; cerr << endl; } @@ -447,8 +447,8 @@ Bool_t PRunAsymmetry::PrepareData() t0Add.push_back(addRunData->GetT0Estimated(fRunInfo->GetBackwardHistoNo(j)-1)); cerr << endl << ">> PRunAsymmetry::PrepareData(): **WARRNING** NO t0's found, neither in the run data nor in the msr-file!"; cerr << endl << ">> addRun: " << fRunInfo->GetRunName()->Data(); - cerr << endl << ">> will try the estimated one: forward t0 = " << addRunData->GetT0Estimated(fRunInfo->GetForwardHistoNo(j)-1)+1; - cerr << endl << ">> will try the estimated one: backward t0 = " << addRunData->GetT0Estimated(fRunInfo->GetBackwardHistoNo(j)-1)+1; + cerr << endl << ">> will try the estimated one: forward t0 = " << addRunData->GetT0Estimated(fRunInfo->GetForwardHistoNo(j)-1); + cerr << endl << ">> will try the estimated one: backward t0 = " << addRunData->GetT0Estimated(fRunInfo->GetBackwardHistoNo(j)-1); cerr << endl << ">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!"; cerr << endl; } @@ -461,7 +461,7 @@ Bool_t PRunAsymmetry::PrepareData() if (fabs(fRunInfo->GetAddT0(i,2*j)-addRunData->GetT0(fRunInfo->GetForwardHistoNo(j)-1))>5.0) { // given in bins!! cerr << endl << ">> PRunSingleHisto::PrepareData(): **WARNING**:"; cerr << endl << ">> t0 from the msr-file is " << fRunInfo->GetAddT0(i,2*j)+1; // +1 since vector starts at 0 - cerr << endl << ">> t0 from the data file is " << addRunData->GetT0(fRunInfo->GetForwardHistoNo(j)-1)+1; // +1 since vector starts at 0 + cerr << endl << ">> t0 from the data file is " << addRunData->GetT0(fRunInfo->GetForwardHistoNo(j)-1); cerr << endl << ">> This is quite a deviation! Is this done intentionally??"; cerr << endl << ">> addrun: " << fRunInfo->GetRunName(i)->Data(); cerr << endl; @@ -469,7 +469,7 @@ Bool_t PRunAsymmetry::PrepareData() if (fabs(fRunInfo->GetAddT0(i,2*j+1)-addRunData->GetT0(fRunInfo->GetBackwardHistoNo(j)-1))>5.0) { // given in bins!! cerr << endl << ">> PRunSingleHisto::PrepareData(): **WARNING**:"; cerr << endl << ">> t0 from the msr-file is " << fRunInfo->GetAddT0(i,2*j+1)+1; // +1 since vector starts at 0 - cerr << endl << ">> t0 from the data file is " << addRunData->GetT0(fRunInfo->GetBackwardHistoNo(j)-1)+1; // +1 since vector starts at 0 + cerr << endl << ">> t0 from the data file is " << addRunData->GetT0(fRunInfo->GetBackwardHistoNo(j)-1); cerr << endl << ">> This is quite a deviation! Is this done intentionally??"; cerr << endl << ">> addrun: " << fRunInfo->GetRunName(i)->Data(); cerr << endl; @@ -497,8 +497,8 @@ Bool_t PRunAsymmetry::PrepareData() addRunSize = addRunData->GetDataBin(forwardHistoNo[k])->size(); for (UInt_t j=0; jGetDataBin(forwardHistoNo[k])->size(); j++) { // make sure that the index stays in the proper range - if ((j-t0Add[2*k]+fT0s[2*k] >= 0) && (j-t0Add[2*k]+fT0s[2*k] < addRunSize)) { - fForward[j] += addRunData->GetDataBin(forwardHistoNo[k])->at(j-t0Add[2*k]+fT0s[2*k]); + if ((j+t0Add[2*k]-fT0s[2*k] >= 0) && (j+t0Add[2*k]-fT0s[2*k] < addRunSize)) { + fForward[j] += addRunData->GetDataBin(forwardHistoNo[k])->at(j+t0Add[2*k]-fT0s[2*k]); } } } @@ -508,8 +508,8 @@ Bool_t PRunAsymmetry::PrepareData() addRunSize = addRunData->GetDataBin(backwardHistoNo[k])->size(); for (UInt_t j=0; jGetDataBin(backwardHistoNo[k])->size(); j++) { // make sure that the index stays in the proper range - if ((j-t0Add[2*k+1]+fT0s[2*k+1] >= 0) && (j-t0Add[2*k+1]+fT0s[2*k+1] < addRunSize)) { - fBackward[j] += addRunData->GetDataBin(backwardHistoNo[k])->at(j-t0Add[2*k+1]+fT0s[2*k+1]); + if ((j+t0Add[2*k+1]-fT0s[2*k+1] >= 0) && (j+t0Add[2*k+1]-fT0s[2*k+1] < addRunSize)) { + fBackward[j] += addRunData->GetDataBin(backwardHistoNo[k])->at(j+t0Add[2*k+1]-fT0s[2*k+1]); } } } @@ -523,8 +523,8 @@ Bool_t PRunAsymmetry::PrepareData() for (UInt_t i=1; iGetDataBin(forwardHistoNo[i])->size(); j++) { // make sure that the index stays within proper range - if ((j-fT0s[0]+fT0s[2*i] >= 0) && (j-fT0s[0]+fT0s[2*i] < runData->GetDataBin(forwardHistoNo[i])->size())) { - fForward[j] += runData->GetDataBin(forwardHistoNo[i])->at(j-fT0s[0]+fT0s[2*i]); + if ((j+fT0s[2*i]-fT0s[0] >= 0) && (j+fT0s[2*i]-fT0s[0] < runData->GetDataBin(forwardHistoNo[i])->size())) { + fForward[j] += runData->GetDataBin(forwardHistoNo[i])->at(j+fT0s[2*i]-fT0s[0]); } } } @@ -532,8 +532,8 @@ Bool_t PRunAsymmetry::PrepareData() for (UInt_t i=1; iGetDataBin(backwardHistoNo[i])->size(); j++) { // make sure that the index stays within proper range - if ((j-fT0s[1]+fT0s[2*i+1] >= 0) && (j-fT0s[1]+fT0s[2*i+1] < runData->GetDataBin(backwardHistoNo[i])->size())) { - fBackward[j] += runData->GetDataBin(backwardHistoNo[i])->at(j-fT0s[1]+fT0s[2*i+1]); + if ((j+fT0s[2*i+1]-fT0s[1] >= 0) && (j+fT0s[2*i+1]-fT0s[1] < runData->GetDataBin(backwardHistoNo[i])->size())) { + fBackward[j] += runData->GetDataBin(backwardHistoNo[i])->at(j+fT0s[2*i+1]-fT0s[1]); } } } @@ -788,6 +788,24 @@ Bool_t PRunAsymmetry::PrepareFitData(PRawRunData* runData, UInt_t histoNo[2]) } } + // check that start-t0 is the same for forward as for backward, otherwise take max(start[i]-t0[i]) + if (fabs(static_cast(start[0])-t0[0]) > fabs(static_cast(start[1])-t0[1])){ + start[1] = static_cast(t0[1] + static_cast(start[0]) - t0[0]); + end[1] = static_cast(t0[1] + static_cast(end[0]) - t0[0]); + cerr << endl << ">> PRunAsymmetry::PrepareFitData **WARNING** needed to shift backward data range."; + cerr << endl << ">> given: " << fRunInfo->GetDataRange(2) << ", " << fRunInfo->GetDataRange(3); + cerr << endl << ">> used : " << start[1] << ", " << end[1]; + cerr << endl; + } + if (fabs(static_cast(start[0])-t0[0]) < fabs(static_cast(start[1])-t0[1])){ + start[0] = static_cast(t0[0] + static_cast(start[1]) - t0[1]); + end[0] = static_cast(t0[0] + static_cast(end[1]) - t0[1]); + cerr << endl << ">> PRunAsymmetry::PrepareFitData **WARNING** needed to shift forward data range."; + cerr << endl << ">> given: " << fRunInfo->GetDataRange(0) << ", " << fRunInfo->GetDataRange(1); + cerr << endl << ">> used : " << start[0] << ", " << end[0]; + cerr << endl; + } + // everything looks fine, hence fill packed forward and backward histo PRunData forwardPacked; PRunData backwardPacked; @@ -919,24 +937,30 @@ Bool_t PRunAsymmetry::PrepareViewData(PRawRunData* runData, UInt_t histoNo[2]) Double_t t0[2] = {fT0s[0], fT0s[1]}; // check if data range has been provided, and if not try to estimate them if (fRunInfo->GetDataRange(0) < 0) { - start[0] = ((Int_t)t0[0]+5) - (((Int_t)t0[0]+5)/packing)*packing; + start[0] = (static_cast(t0[0])+5) - ((static_cast(t0[0])+5)/packing)*packing; cerr << endl << ">> PRunAsymmetry::PrepareViewData(): **WARNING** data range (forward) was not provided, will try data range start = " << start[0] << "."; cerr << endl << ">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE."; cerr << endl; } else if (fRunInfo->GetDataRange(2) < 0) { - start[1] = ((Int_t)t0[1]+5) - (((Int_t)t0[1]+5)/packing)*packing; + start[1] = (static_cast(t0[1])+5) - ((static_cast(t0[1])+5)/packing)*packing; cerr << endl << ">> PRunAsymmetry::PrepareViewData(): **WARNING** data range (backward) was not provided, will try data range start = " << start[1] << "."; cerr << endl << ">> NO WARRANTY THAT THIS DOES MAKE ANY SENSE."; cerr << endl; } else { - Int_t val = fRunInfo->GetDataRange(0)-packing*(fRunInfo->GetDataRange(0)/packing); + // calculate the max(data range start[i]-t0[i]) + Int_t diff = fRunInfo->GetDataRange(0)-static_cast(t0[0]); + if (abs(diff) < abs(fRunInfo->GetDataRange(2)-static_cast(t0[1]))) + diff = fRunInfo->GetDataRange(0)-static_cast(t0[0]); + + // calculate start position for plotting + Int_t val = static_cast(t0[1])+diff-packing*((static_cast(t0[1])+diff)/packing); do { - if (fRunInfo->GetDataRange(2) - fRunInfo->GetDataRange(0) < 0) + if (static_cast(val)+t0[1]-t0[0] < 0.0) val += packing; - } while (val + fRunInfo->GetDataRange(2) - fRunInfo->GetDataRange(0) < 0); + } while (static_cast(val) + t0[1] - t0[0] < 0.0); start[0] = val; - start[1] = val + fRunInfo->GetDataRange(2) - fRunInfo->GetDataRange(0); + start[1] = val + static_cast(t0[1] - t0[0]); } // make sure that there are equal number of rebinned bins in forward and backward @@ -1002,6 +1026,7 @@ Bool_t PRunAsymmetry::PrepareViewData(PRawRunData* runData, UInt_t histoNo[2]) error += fForwardErr[i]*fForwardErr[i]; } } + // backward for (Int_t i=start[1]; iGetT0Estimated(fRunInfo->GetForwardHistoNo(i)-1)); cerr << endl << ">> PRunSingleHisto::PrepareData(): **WARNING** NO t0's found, neither in the run data nor in the msr-file!"; cerr << endl << ">> run: " << fRunInfo->GetRunName()->Data(); - cerr << endl << ">> will try the estimated one: t0 = " << runData->GetT0Estimated(fRunInfo->GetForwardHistoNo(i)-1)+1; + cerr << endl << ">> will try the estimated one: t0 = " << runData->GetT0Estimated(fRunInfo->GetForwardHistoNo(i)-1); cerr << endl << ">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!"; cerr << endl; } @@ -343,13 +343,13 @@ Bool_t PRunSingleHisto::PrepareData() for (UInt_t i=0; iGetForwardHistoNoSize(); i++) { // check if enough t0's are given in the msr-file, if not try to get the rest from the data file if (fRunInfo->GetT0Size() <= i) { // t0 for i not present in the msr-file, i.e. #t0's != #forward histos - if (runData->GetT0Size() > fRunInfo->GetForwardHistoNo(i)-1) { // t0 for i present in the data file + if (static_cast(runData->GetT0Size()) > fRunInfo->GetForwardHistoNo(i)-1) { // t0 for i present in the data file fT0s.push_back(runData->GetT0(fRunInfo->GetForwardHistoNo(i)-1)); } else { // t0 is neither in the run data nor in the msr-file -> will try estimated ones! fT0s.push_back(runData->GetT0Estimated(fRunInfo->GetForwardHistoNo(i)-1)); cerr << endl << ">> PRunSingleHisto::PrepareData(): **WARNING** NO t0's found, neither in the run data nor in the msr-file!"; cerr << endl << ">> run: " << fRunInfo->GetRunName()->Data(); - cerr << endl << ">> will try the estimated one: t0 = " << runData->GetT0Estimated(fRunInfo->GetForwardHistoNo(i)-1)+1; + cerr << endl << ">> will try the estimated one: t0 = " << runData->GetT0Estimated(fRunInfo->GetForwardHistoNo(i)-1); cerr << endl << ">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!"; cerr << endl; } @@ -360,8 +360,8 @@ Bool_t PRunSingleHisto::PrepareData() // compare t0's of the msr-file with the one in the data file if (fabs(fRunInfo->GetT0(i)-runData->GetT0(fRunInfo->GetForwardHistoNo(i)-1))>5.0) { // given in bins!! cerr << endl << ">> PRunSingleHisto::PrepareData(): **WARNING**:"; - cerr << endl << ">> t0 from the msr-file is " << fRunInfo->GetT0(i)+1; - cerr << endl << ">> t0 from the data file is " << runData->GetT0(fRunInfo->GetForwardHistoNo(i)-1)+1; + cerr << endl << ">> t0 from the msr-file is " << fRunInfo->GetT0(i); + cerr << endl << ">> t0 from the data file is " << runData->GetT0(fRunInfo->GetForwardHistoNo(i)-1); cerr << endl << ">> This is quite a deviation! Is this done intentionally??"; cerr << endl; } @@ -407,7 +407,7 @@ Bool_t PRunSingleHisto::PrepareData() t0Add.push_back(addRunData->GetT0Estimated(fRunInfo->GetForwardHistoNo(j)-1)); cerr << endl << ">> PRunSingleHisto::PrepareData(): **WARNING** NO t0's found, neither in the addrun data nor in the msr-file!"; cerr << endl << ">> addrun: " << fRunInfo->GetRunName(i)->Data(); - cerr << endl << ">> will try the estimated one: t0 = " << addRunData->GetT0Estimated(fRunInfo->GetForwardHistoNo(j)-1)+1; + cerr << endl << ">> will try the estimated one: t0 = " << addRunData->GetT0Estimated(fRunInfo->GetForwardHistoNo(j)-1); cerr << endl << ">> NO WARRANTY THAT THIS OK!! For instance for LEM this is almost for sure rubbish!"; cerr << endl; } @@ -419,8 +419,8 @@ Bool_t PRunSingleHisto::PrepareData() // compare t0's of the msr-file with the one in the data file if (fabs(fRunInfo->GetAddT0(i,j)-addRunData->GetT0(fRunInfo->GetForwardHistoNo(j)-1))>5.0) { // given in bins!! cerr << endl << ">> PRunSingleHisto::PrepareData(): **WARNING**:"; - cerr << endl << ">> t0 from the msr-file is " << fRunInfo->GetAddT0(i,j)+1; // +1 since vector starts at 0 - cerr << endl << ">> t0 from the data file is " << addRunData->GetT0(fRunInfo->GetForwardHistoNo(j)-1)+1; // +1 since vector starts at 0 + cerr << endl << ">> t0 from the msr-file is " << fRunInfo->GetAddT0(i,j); + cerr << endl << ">> t0 from the data file is " << addRunData->GetT0(fRunInfo->GetForwardHistoNo(j)-1); cerr << endl << ">> This is quite a deviation! Is this done intentionally??"; cerr << endl << ">> addrun: " << fRunInfo->GetRunName(i)->Data(); cerr << endl; @@ -444,8 +444,8 @@ Bool_t PRunSingleHisto::PrepareData() for (UInt_t k=0; kGetForwardHistoNoSize(); k++) { for (UInt_t j=0; jGetDataBin(histoNo[k])->size(); j++) { // make sure that the index stays within proper range - if ((j-t0Add[k]+fT0s[k] >= 0) && (j-t0Add[k]+fT0s[k] < addRunData->GetDataBin(histoNo[k])->size())) { - runData->AddDataBin(histoNo[k], j, addRunData->GetDataBin(histoNo[k])->at(j-t0Add[k]+fT0s[k])); + if ((j+t0Add[k]-fT0s[k] >= 0) && (j+t0Add[k]-fT0s[k] < addRunData->GetDataBin(histoNo[k])->size())) { + runData->AddDataBin(histoNo[k], j, addRunData->GetDataBin(histoNo[k])->at(j+t0Add[k]-fT0s[k])); } } } @@ -459,8 +459,8 @@ Bool_t PRunSingleHisto::PrepareData() for (UInt_t i=1; iGetForwardHistoNoSize(); i++) { for (UInt_t j=0; jGetDataBin(histoNo[0])->size(); j++) { // make sure that the index stays within proper range - if ((j-fT0s[0]+fT0s[i] >= 0) && (j-fT0s[0]+fT0s[i] < runData->GetDataBin(histoNo[i])->size())) { - runData->AddDataBin(histoNo[0], j, runData->GetDataBin(histoNo[i])->at(j-fT0s[0]+fT0s[i])); + if ((j+fT0s[i]-fT0s[0] >= 0) && (j+fT0s[i]-fT0s[0] < runData->GetDataBin(histoNo[i])->size())) { + runData->AddDataBin(histoNo[0], j, runData->GetDataBin(histoNo[i])->at(j+fT0s[i]-fT0s[0])); } } } diff --git a/src/include/PMsrHandler.h b/src/include/PMsrHandler.h index 81e83b53..c0ca8139 100644 --- a/src/include/PMsrHandler.h +++ b/src/include/PMsrHandler.h @@ -76,6 +76,7 @@ class PMsrHandler virtual Bool_t SetMsrParamPosError(UInt_t i, Double_t value); virtual void SetMsrT0Entry(UInt_t runNo, UInt_t idx, Int_t bin); + virtual void SetMsrAddT0Entry(UInt_t runNo, UInt_t addRunIdx, UInt_t histoIdx, Int_t bin); virtual void SetMsrDataRangeEntry(UInt_t runNo, UInt_t idx, Int_t bin); virtual void SetMsrBkgRangeEntry(UInt_t runNo, UInt_t idx, Int_t bin); diff --git a/src/include/PMusrT0.h b/src/include/PMusrT0.h index 075f36e0..a168edd9 100644 --- a/src/include/PMusrT0.h +++ b/src/include/PMusrT0.h @@ -40,12 +40,76 @@ #include #include #include +#include #include "PMusr.h" #ifndef __MAKECINT__ #include "PMsrHandler.h" #endif // __MAKECINT__ +#define PMUSRT0_FORWARD 0 +#define PMUSRT0_BACKWARD 1 + +#define PMUSRT0_GET_T0 0 +#define PMUSRT0_GET_DATA_AND_BKG_RANGE 1 +#define PMUSRT0_GET_T0_DATA_AND_BKG_RANGE 2 + +/* +#define PMUSRT0_NOADDRUN_NOGROUPING 0 +#define PMUSRT0_ADDRUN_NOGROUPING 1 +#define PMUSRT0_NOADDRUN_GROUPING 2 +#define PMUSRT0_ADDRUN_GROUPING 3 +*/ + +class PMusrT0Data { + public: + PMusrT0Data(); + virtual ~PMusrT0Data(); + + + virtual void InitData(); + + virtual Bool_t IsSingleHisto() { return fSingleHisto; } + virtual UInt_t GetRawRunDataSize() { return fRawRunData.size(); } + virtual PRawRunData* GetRawRunData(Int_t idx); + virtual Int_t GetRunNo() { return fRunNo; } + virtual Int_t GetAddRunIdx() { return fAddRunIdx; } + virtual Int_t GetHistoNoIdx() { return fHistoNoIdx; } + virtual UInt_t GetHistoNoSize() { return fHistoNo.size(); } + virtual Int_t GetHistoNo(UInt_t idx); + virtual Int_t GetDetectorTag() { return fDetectorTag; } + virtual Int_t GetCmdTag() { return fCmdTag; } + virtual UInt_t GetT0Size() { return fT0.size(); } + virtual Int_t GetT0(UInt_t idx); + virtual UInt_t GetAddT0Entries() { return fAddT0.size(); } + virtual UInt_t GetAddT0Size(UInt_t idx); + virtual Int_t GetAddT0(UInt_t addRunIdx, UInt_t idx); + + virtual void SetSingleHisto(const Bool_t flag) { fSingleHisto = flag; } + virtual void SetRawRunData(const vector rawRunData) { fRawRunData = rawRunData; } + virtual void SetRunNo(const UInt_t runNo) { fRunNo = runNo; } + virtual void SetAddRunIdx(const UInt_t addRunIdx) { fAddRunIdx = addRunIdx; } + virtual void SetHistoNoIdx(const UInt_t histoNoIdx) { fHistoNoIdx = histoNoIdx; } + virtual void SetHistoNo(const PIntVector histoNo) { fHistoNo = histoNo; } + virtual void SetDetectorTag(const UInt_t detectorTag) { fDetectorTag = detectorTag; } + virtual void SetCmdTag(const UInt_t cmdTag) { fCmdTag = cmdTag; } + virtual void SetT0(UInt_t val, UInt_t idx); + virtual void SetAddT0(UInt_t val, UInt_t addRunIdx, UInt_t idx); + + private: + Bool_t fSingleHisto; ///< true if single histo fit, false for asymmetry fit + vector fRawRunData; ///< holds the raw data of the needed runs, idx=0 the run, idx>0 the addruns + Int_t fRunNo; ///< msr-file run number + Int_t fAddRunIdx; ///< msr-file addrun index + Int_t fHistoNoIdx; ///< msr-file histo number index + PIntVector fHistoNo; ///< msr-file histo numbers + Int_t fDetectorTag; ///< detector tag. forward=0,backward=1 + Int_t fCmdTag; ///< command tag. 0=get t0, 1=get data-/bkg-range, 2=get t0, and data-/bkg-range + PIntVector fT0; ///< holding the t0's of the run + vector fAddT0; ///< holding the t0's of the addruns +}; + + //-------------------------------------------------------------------------- /** *

The preprocessor tag __MAKECINT__ is used to hide away from rootcint @@ -55,10 +119,12 @@ class PMusrT0 : public TObject, public TQObject { public: PMusrT0(); - PMusrT0(PRawRunData *rawRunData, Int_t runNo, Int_t histoNo, Int_t detectorTag, Int_t addRunNo); + PMusrT0(PMusrT0Data &data); virtual ~PMusrT0(); + virtual Bool_t IsValid() { return fValid; } + virtual void Done(Int_t status=0); // *SIGNAL* virtual void HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected); // SLOT @@ -66,6 +132,8 @@ class PMusrT0 : public TObject, public TQObject virtual void SetMsrHandler(PMsrHandler *msrHandler); #endif // __MAKECINT__ + virtual void InitT0(); + virtual void InitDataAndBkg(); virtual Int_t GetStatus() { return fStatus; } private: @@ -73,13 +141,15 @@ class PMusrT0 : public TObject, public TQObject PMsrHandler *fMsrHandler; #endif // __MAKECINT__ + Bool_t fValid; + Int_t fStatus; - Int_t fRunNo; - Int_t fDetectorTag; - Int_t fAddRunNo; - Int_t fAddRunOffset; - Int_t fT0Estimated; + PMusrT0Data fMusrT0Data; + + Bool_t fDataAndBkgEnabled; + Bool_t fT0Enabled; + Int_t fT0Estimated; // canvas related variables TCanvas *fMainCanvas; @@ -88,6 +158,8 @@ class PMusrT0 : public TObject, public TQObject TH1F *fData; TH1F *fBkg; + TLatex *fToDoInfo; + TLine *fT0Line; TLine *fFirstBkgLine; TLine *fLastBkgLine; @@ -100,7 +172,6 @@ class PMusrT0 : public TObject, public TQObject Int_t fDataRange[2]; Int_t fBkgRange[2]; - void InitDataAndBkg(); void SetT0Channel(); void SetEstimatedT0Channel(); void SetDataFirstChannel(); @@ -108,6 +179,7 @@ class PMusrT0 : public TObject, public TQObject void SetBkgFirstChannel(); void SetBkgLastChannel(); void UnZoom(); + void ZoomT0(); ClassDef(PMusrT0, 1) }; diff --git a/src/musrt0.cpp b/src/musrt0.cpp index 8630e1b8..22accabc 100644 --- a/src/musrt0.cpp +++ b/src/musrt0.cpp @@ -47,7 +47,6 @@ using namespace std; #include "PRunDataHandler.h" #include "PMusrT0.h" - //-------------------------------------------------------------------------- /** *

@@ -69,36 +68,46 @@ void musrt0_syntax() * * \param app * \param msrHandler - * \param rawRunData - * \param runNo - * \param histoNo - * \param detectorTag 0=forward, 1=backward, 2=left, 3=right - * \param addRunNo + * \param data */ -bool musrt0_item(TApplication &app, PMsrHandler *msrHandler, PRawRunData *rawRunData, - unsigned int runNo, int histoNo, int detectorTag, int addRunNo) +Bool_t musrt0_item(TApplication &app, PMsrHandler *msrHandler, PMusrT0Data &data, UInt_t idx) { - PMusrT0 *musrT0 = new PMusrT0(rawRunData, runNo, histoNo, detectorTag, addRunNo); +//cout << endl << "debug> &app=" << &app << ", msrHandler=" << msrHandler << ", &data=" << &data << endl; + + PMusrT0 *musrT0 = new PMusrT0(data); if (musrT0 == 0) { - cout << endl << "**ERROR** Couldn't invoke musrT0 ..."; - cout << endl << " run name " << rawRunData->GetRunName()->Data(); - cout << endl << " histo No " << histoNo; - cout << endl; + cerr << endl << ">> **ERROR** Couldn't invoke musrT0 ..."; + cerr << endl << ">> run name " << data.GetRawRunData(idx)->GetRunName()->Data(); + cerr << endl; + return false; + } + + if (!musrT0->IsValid()) { + cerr << endl << ">> **ERROR** invalid item found! (idx=" << idx << ")"; + cerr << endl; return false; } musrT0->SetMsrHandler(msrHandler); + if (data.GetCmdTag() != PMUSRT0_GET_DATA_AND_BKG_RANGE) + musrT0->InitT0(); + + if (data.GetCmdTag() != PMUSRT0_GET_T0) + musrT0->InitDataAndBkg(); + musrT0->Connect("Done(Int_t)", "TApplication", &app, "Terminate(Int_t)"); app.Run(true); // true needed that Run will return after quit - bool result = true; + Bool_t result = true; if (musrT0->GetStatus() == 1) result = false; else result = true; + musrT0->Disconnect(musrT0); + delete musrT0; musrT0 = 0; @@ -131,12 +140,12 @@ void musrt0_cleanup(TSAXParser *saxParser, PStartupHandler *startupHandler, PMsr } //-------------------------------------------------------------------------- -int main(int argc, char *argv[]) +Int_t main(Int_t argc, Char_t *argv[]) { - bool show_syntax = false; - int status; - bool success = true; - char filename[1024]; + Bool_t show_syntax = false; + Int_t status; + Bool_t success = true; + Char_t filename[1024]; switch (argc) { case 1: @@ -169,7 +178,7 @@ int main(int argc, char *argv[]) } // read startup file - char startup_path_name[128]; + Char_t startup_path_name[128]; TSAXParser *saxParser = new TSAXParser(); PStartupHandler *startupHandler = new PStartupHandler(); if (!startupHandler->StartupFileFound()) { @@ -225,7 +234,7 @@ int main(int argc, char *argv[]) // check if the fittype is not NonMusr PMsrRunList *runList = msrHandler->GetMsrRunList(); - for (unsigned int i=0; isize(); i++) { + for (UInt_t i=0; isize(); i++) { if (runList->at(i).GetFitType() == MSR_FITTYPE_NON_MUSR) { cout << endl << "**ERROR** t0 setting for NonMusr fittype doesn't make any sense, will quit ..." << endl; success = false; @@ -248,59 +257,349 @@ int main(int argc, char *argv[]) } + // set t0's, data-range and bkg-range. There are 4 different cases, namely: + // 1. no addruns / no grouping of histos + // 2. addruns / no grouping of histos + // 3. no addruns / grouping of histos + // 4. addruns / grouping of histos + // case 1 is different form the others since t0, data-, and bkg-range can be collected for the given histogram + // cases 2-4 the procedure will be the following: + // 1) set for each given histogram the t0's + // 2) build the added up histogram, i.e. add all runs and/or histograms for the msr-run. + // 3) set the data-, and bkg-range if (success) { // generate Root application needed for PMusrCanvas TApplication app("App", &argc, argv); + PMusrT0Data musrT0Data; + vector rawRunData; + PIntVector forwardHistos; + PIntVector backwardHistos; // generate vector of all necessary PMusrT0 objects - for (unsigned int i=0; isize(); i++) { + for (UInt_t i=0; isize(); i++) { switch (runList->at(i).GetFitType()) { case MSR_FITTYPE_SINGLE_HISTO: - for (unsigned int j=0; jat(i).GetRunNameSize(); j++) { // necessary in case of ADDRUN - if (!musrt0_item(app, msrHandler, dataHandler->GetRunData(*(runList->at(i).GetRunName(j))), i, runList->at(i).GetForwardHistoNo(), 0, j)) { + if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping + // feed necessary data + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(true); + rawRunData.clear(); + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0)))); + musrT0Data.SetRawRunData(rawRunData); + musrT0Data.SetRunNo(i); + musrT0Data.SetAddRunIdx(0); // no addruns + musrT0Data.SetHistoNoIdx(0); + forwardHistos.clear(); + forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0)); + musrT0Data.SetHistoNo(forwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_FORWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0_DATA_AND_BKG_RANGE); + // execute cmd + if (!musrt0_item(app, msrHandler, musrT0Data, 0)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + } else { + // get t0's + if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping + // feed necessary data + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(true); + musrT0Data.SetRunNo(i); + musrT0Data.SetHistoNoIdx(0); + forwardHistos.clear(); + forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0)); + musrT0Data.SetHistoNo(forwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_FORWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0); + rawRunData.clear(); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j)))); + musrT0Data.SetRawRunData(rawRunData); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) { + // feed necessary data + musrT0Data.SetAddRunIdx(j); // addruns + if (!musrt0_item(app, msrHandler, musrT0Data, j)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + } + } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping + // feed necessary data + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(true); + musrT0Data.SetRunNo(i); + forwardHistos.clear(); + for (UInt_t j=0; jat(i).GetForwardHistoNoSize(); j++) + forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j)); + musrT0Data.SetHistoNo(forwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_FORWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0); + rawRunData.clear(); + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0)))); + musrT0Data.SetRawRunData(rawRunData); + musrT0Data.SetAddRunIdx(0); + for (UInt_t j=0; jat(i).GetForwardHistoNoSize(); j++) { + musrT0Data.SetHistoNoIdx(j); + if (!musrt0_item(app, msrHandler, musrT0Data, 0)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + } + } else { // addruns / grouping + // feed necessary data + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(true); + musrT0Data.SetRunNo(i); + forwardHistos.clear(); + for (UInt_t j=0; jat(i).GetForwardHistoNoSize(); j++) + forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j)); + musrT0Data.SetHistoNo(forwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_FORWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0); + rawRunData.clear(); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j)))); + musrT0Data.SetRawRunData(rawRunData); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) { // addrun / grouping + musrT0Data.SetAddRunIdx(j); // addruns + for (UInt_t k=0; kat(i).GetForwardHistoNoSize(); k++) { // forward histo grouping + musrT0Data.SetHistoNoIdx(k); + if (!musrt0_item(app, msrHandler, musrT0Data, j)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + } + } + } + // get data- and bkg-range + musrT0Data.SetCmdTag(PMUSRT0_GET_DATA_AND_BKG_RANGE); + // feed all t0's + for (UInt_t j=0; jat(i).GetT0Size(); j++) { + musrT0Data.SetT0(runList->at(i).GetT0(j), j); + for (UInt_t k=0; kat(i).GetAddT0Entries(); k++) { + musrT0Data.SetAddT0(runList->at(i).GetAddT0(k, j), k, j); + } + } + if (!musrt0_item(app, msrHandler, musrT0Data, 0)) { musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); exit(0); } } break; case MSR_FITTYPE_ASYM: - for (unsigned int j=0; jat(i).GetRunNameSize(); j++) { // necessary in case of ADDRUN - if (!musrt0_item(app, msrHandler, dataHandler->GetRunData(*(runList->at(i).GetRunName(j))), i, runList->at(i).GetForwardHistoNo(), 0, j)) { + if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // no addruns / no grouping + // feed necessary data forward + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(false); + rawRunData.clear(); + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0)))); + musrT0Data.SetRawRunData(rawRunData); + musrT0Data.SetRunNo(i); + musrT0Data.SetAddRunIdx(0); // no addruns + musrT0Data.SetHistoNoIdx(0); + forwardHistos.clear(); + forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0)); + musrT0Data.SetHistoNo(forwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_FORWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0_DATA_AND_BKG_RANGE); + // execute cmd + if (!musrt0_item(app, msrHandler, musrT0Data, 0)) { musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); exit(0); } - if (!musrt0_item(app, msrHandler, dataHandler->GetRunData(*(runList->at(i).GetRunName(j))), i, runList->at(i).GetBackwardHistoNo(), 1, j)) { + // feed necessary data backward + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(false); + rawRunData.clear(); + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0)))); + musrT0Data.SetRawRunData(rawRunData); + musrT0Data.SetRunNo(i); + musrT0Data.SetAddRunIdx(0); // no addruns + musrT0Data.SetHistoNoIdx(0); + backwardHistos.clear(); + backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(0)); + musrT0Data.SetHistoNo(backwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0_DATA_AND_BKG_RANGE); + // execute cmd + if (!musrt0_item(app, msrHandler, musrT0Data, 0)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + } else { + // get t0's + if ((runList->at(i).GetRunNameSize() > 1) && (runList->at(i).GetForwardHistoNoSize() == 1)) { // addruns / no grouping + // feed necessary forward data + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(false); + musrT0Data.SetRunNo(i); + musrT0Data.SetHistoNoIdx(0); + forwardHistos.clear(); + forwardHistos.push_back(runList->at(i).GetForwardHistoNo(0)); + musrT0Data.SetHistoNo(forwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_FORWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0); + rawRunData.clear(); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j)))); + musrT0Data.SetRawRunData(rawRunData); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) { + // feed necessary data + musrT0Data.SetAddRunIdx(j); // addruns + if (!musrt0_item(app, msrHandler, musrT0Data, j)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + } + // feed necessary backward data + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(false); + musrT0Data.SetRunNo(i); + musrT0Data.SetHistoNoIdx(0); + backwardHistos.clear(); + backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(0)); + musrT0Data.SetHistoNo(backwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0); + rawRunData.clear(); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j)))); + musrT0Data.SetRawRunData(rawRunData); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) { + // feed necessary data + musrT0Data.SetAddRunIdx(j); // addruns + if (!musrt0_item(app, msrHandler, musrT0Data, j)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + } + } else if ((runList->at(i).GetRunNameSize() == 1) && (runList->at(i).GetForwardHistoNoSize() > 1)) { // no addruns / grouping + // feed necessary forward data + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(false); + musrT0Data.SetRunNo(i); + forwardHistos.clear(); + for (UInt_t j=0; jat(i).GetForwardHistoNoSize(); j++) + forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j)); + musrT0Data.SetHistoNo(forwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_FORWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0); + rawRunData.clear(); + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0)))); + musrT0Data.SetRawRunData(rawRunData); + musrT0Data.SetAddRunIdx(0); + for (UInt_t j=0; jat(i).GetForwardHistoNoSize(); j++) { + musrT0Data.SetHistoNoIdx(j); + if (!musrt0_item(app, msrHandler, musrT0Data, 0)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + } + // feed necessary backward data + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(false); + musrT0Data.SetRunNo(i); + backwardHistos.clear(); + for (UInt_t j=0; jat(i).GetBackwardHistoNoSize(); j++) + backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(j)); + musrT0Data.SetHistoNo(backwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0); + rawRunData.clear(); + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(0)))); + musrT0Data.SetRawRunData(rawRunData); + musrT0Data.SetAddRunIdx(0); + for (UInt_t j=0; jat(i).GetBackwardHistoNoSize(); j++) { + musrT0Data.SetHistoNoIdx(j); + if (!musrt0_item(app, msrHandler, musrT0Data, 0)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + } + } else { // addruns / grouping + // feed necessary forward data + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(false); + musrT0Data.SetRunNo(i); + forwardHistos.clear(); + for (UInt_t j=0; jat(i).GetForwardHistoNoSize(); j++) + forwardHistos.push_back(runList->at(i).GetForwardHistoNo(j)); + musrT0Data.SetHistoNo(forwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_FORWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0); + rawRunData.clear(); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j)))); + musrT0Data.SetRawRunData(rawRunData); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) { // addrun / grouping + musrT0Data.SetAddRunIdx(j); // addruns + for (UInt_t k=0; kat(i).GetForwardHistoNoSize(); k++) { // forward histo grouping + musrT0Data.SetHistoNoIdx(k); + if (!musrt0_item(app, msrHandler, musrT0Data, j)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + } + } + // feed necessary backward data + musrT0Data.InitData(); + musrT0Data.SetSingleHisto(false); + musrT0Data.SetRunNo(i); + backwardHistos.clear(); + for (UInt_t j=0; jat(i).GetBackwardHistoNoSize(); j++) + backwardHistos.push_back(runList->at(i).GetBackwardHistoNo(j)); + musrT0Data.SetHistoNo(backwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD); + musrT0Data.SetCmdTag(PMUSRT0_GET_T0); + rawRunData.clear(); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) + rawRunData.push_back(dataHandler->GetRunData(*(runList->at(i).GetRunName(j)))); + musrT0Data.SetRawRunData(rawRunData); + for (UInt_t j=0; jat(i).GetRunNameSize(); j++) { // addrun / grouping + musrT0Data.SetAddRunIdx(j); // addruns + for (UInt_t k=0; kat(i).GetBackwardHistoNoSize(); k++) { // backward histo grouping + musrT0Data.SetHistoNoIdx(k); + if (!musrt0_item(app, msrHandler, musrT0Data, j)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + } + } + } + // get data- and bkg-range + musrT0Data.SetCmdTag(PMUSRT0_GET_DATA_AND_BKG_RANGE); + // feed all t0's + for (UInt_t j=0; jat(i).GetT0Size(); j++) { + musrT0Data.SetT0(runList->at(i).GetT0(j), j); + for (UInt_t k=0; kat(i).GetAddT0Entries(); k++) { + musrT0Data.SetAddT0(runList->at(i).GetAddT0(k, j), k, j); + } + } + musrT0Data.SetHistoNo(forwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_FORWARD); + if (!musrt0_item(app, msrHandler, musrT0Data, 0)) { + musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); + exit(0); + } + musrT0Data.SetHistoNo(backwardHistos); + musrT0Data.SetDetectorTag(PMUSRT0_BACKWARD); + if (!musrt0_item(app, msrHandler, musrT0Data, 0)) { musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); exit(0); } } break; case MSR_FITTYPE_MU_MINUS: -/* - for (unsigned int j=0; jat(i).GetRunNameSize(); j++) { // necessary in case of ADDRUN - if (!musrt0_item(app, msrHandler, dataHandler->GetRunData(*(runList->at(i).GetRunName(j))), i, runList->at(i).GetForwardHistoNo(), 0, j)) { - musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); - exit(0); - } - if (!musrt0_item(app, msrHandler, dataHandler->GetRunData(*(runList->at(i).GetRunName(j))), i, runList->at(i).GetBackwardHistoNo(), 1, j)) { - musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); - exit(0); - } - if (!musrt0_item(app, msrHandler, dataHandler->GetRunData(*(runList->at(i).GetRunName(j))), i, runList->at(i).GetRightHistoNo(), 2, j)) { - musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); - exit(0); - } - if (!musrt0_item(app, msrHandler, dataHandler->GetRunData(*(runList->at(i).GetRunName(j))), i, runList->at(i).GetLeftHistoNo(), 3, j)) { - musrt0_cleanup(saxParser, startupHandler, msrHandler, dataHandler); - exit(0); - } - } -*/ break; default: break; } } + // cleanup + rawRunData.clear(); + forwardHistos.clear(); + backwardHistos.clear(); } // write msr-file @@ -311,7 +610,7 @@ int main(int argc, char *argv[]) gSystem->CopyFile(filename, "__temp.msr", kTRUE); // copy mlog-file -> msr-file TString fln = TString(filename); - char ext[32]; + Char_t ext[32]; strcpy(ext, ".mlog"); fln.ReplaceAll(".msr", 4, ext, strlen(ext)); gSystem->CopyFile(fln.Data(), filename, kTRUE);