diff --git a/CMakeLists.txt b/CMakeLists.txt index 20a7368d..3ac8b262 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -set(LibraryVersion "1.5") +set(LibraryVersion "1.6") add_definitions(-DLIBRARY_VERSION="${LibraryVersion}") COMPILELIB("") diff --git a/images/rawsignals.png b/images/rawsignals.png new file mode 100644 index 00000000..e4a1bf96 Binary files /dev/null and b/images/rawsignals.png differ diff --git a/inc/TRestRawSignalEvent.h b/inc/TRestRawSignalEvent.h index 3c796f6b..cf1b4ecd 100644 --- a/inc/TRestRawSignalEvent.h +++ b/inc/TRestRawSignalEvent.h @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -39,7 +38,6 @@ //! An event container for time rawdata signals with fixed length class TRestRawSignalEvent : public TRestEvent { protected: - TMultiGraph* mg; //! TGraph* gr; //! Double_t fMinTime; //! Double_t fMaxTime; //! @@ -147,6 +145,7 @@ class TRestRawSignalEvent : public TRestEvent { void PrintEvent(); TPad* DrawEvent(const TString& option = ""); + void DrawSignals(TPad* pad, const std::vector& signals); TPad* DrawSignal(Int_t signal, TString option = ""); // Constructor diff --git a/src/TRestRawSignalEvent.cxx b/src/TRestRawSignalEvent.cxx index 69c2795e..7cf9fca2 100644 --- a/src/TRestRawSignalEvent.cxx +++ b/src/TRestRawSignalEvent.cxx @@ -26,6 +26,10 @@ /// DOCUMENTATION TO BE WRITTEN (main description, figures, methods, data /// members) /// +/// \htmlonly \endhtmlonly +/// +/// ![Raw event signals produced with DrawEvent method](rawsignals.png) +/// ///
/// /// \warning **⚠ REST is under continous development.** This @@ -80,7 +84,6 @@ void TRestRawSignalEvent::Initialize() { TRestEvent::Initialize(); fSignal.clear(); fPad = nullptr; - mg = nullptr; gr = nullptr; fMinValue = 1E10; fMaxValue = -1E10; @@ -396,13 +399,12 @@ Double_t TRestRawSignalEvent::GetMaxTime() { /// \endcode /// TPad* TRestRawSignalEvent::DrawEvent(const TString& option) { - int nSignals = this->GetNumberOfSignals(); + const int nSignals = GetNumberOfSignals(); - if (fPad != nullptr) { - for (auto& signal : fSignal) { - delete signal.fGraph; - signal.fGraph = nullptr; - } + if (fPad) { + // for (auto& signal : fSignal) { + // if(signal.fGraph) delete signal.fGraph; + // } delete fPad; fPad = nullptr; } @@ -417,7 +419,7 @@ TPad* TRestRawSignalEvent::DrawEvent(const TString& option) { fMinTime = 1E10; fMaxTime = -1E10; - fPad = new TPad(this->GetName(), " ", 0, 0, 1, 1); + fPad = new TPad(GetName(), " ", 0, 0, 1, 1); fPad->Draw(); fPad->cd(); // fPad->DrawFrame(0, GetMinValue() - 1, GetMaxTime() + 1, GetMaxValue() + 1); @@ -434,16 +436,13 @@ TPad* TRestRawSignalEvent::DrawEvent(const TString& option) { int baseLineRangeInit = 0, baseLineRangeEnd = 0; int sRangeInit = 0, sRangeEnd = 0; - for (int j = 0; j < optList.size(); j++) { - string str = (string)optList[j]; - + for (const auto& opt : optList) { + std::string str = (std::string)opt; // Read threshold option - size_t goodSigOpt = str.find("onlyGoodSignals["); - - if (goodSigOpt != string::npos) { + if (str.find("onlyGoodSignals[") != string::npos) { size_t startPos = str.find("["); size_t endPos = str.find("]"); - TString tmpStr = optList[j](startPos + 1, endPos - startPos - 1); + TString tmpStr = opt(startPos + 1, endPos - startPos - 1); vector optList_2 = Vector_cast(Split((string)tmpStr, ",")); pointTh = StringToDouble((string)optList_2[0]); @@ -454,12 +453,10 @@ TPad* TRestRawSignalEvent::DrawEvent(const TString& option) { } // Read base line option - size_t BLOpt = str.find("baseLineRange["); - - if (BLOpt != string::npos) { + if (str.find("baseLineRange[") != string::npos) { size_t startPos2 = str.find("["); size_t endPos2 = str.find("]"); - TString tmpStr2 = optList[j](startPos2 + 1, endPos2 - startPos2 - 1); + TString tmpStr2 = opt(startPos2 + 1, endPos2 - startPos2 - 1); vector optList_3 = Vector_cast(Split((string)tmpStr2, ",")); baseLineRangeInit = StringToInteger((string)optList_3[0]); @@ -469,13 +466,10 @@ TPad* TRestRawSignalEvent::DrawEvent(const TString& option) { } // Read signal range ID option - size_t sRange = str.find("signalRangeID["); - size_t sRange2 = str.find("ids["); - - if (sRange != string::npos || sRange2 != string::npos) { + if (str.find("signalRangeID[") != string::npos || str.find("ids[") != string::npos) { size_t startPos3 = str.find("["); size_t endPos3 = str.find("]"); - TString tmpStr3 = optList[j](startPos3 + 1, endPos3 - startPos3 - 1); + TString tmpStr3 = opt(startPos3 + 1, endPos3 - startPos3 - 1); vector optList_4; if (str.find(",") != string::npos) optList_4 = Vector_cast(Split((string)tmpStr3, ",")); @@ -491,24 +485,20 @@ TPad* TRestRawSignalEvent::DrawEvent(const TString& option) { } // Read print ID option - size_t screenIDs = str.find("printIDs"); - - if (screenIDs != string::npos) { + if (str.find("printIDs") != string::npos) { printIDs = true; cout << "IDs of printed signals: " << endl; } } - ///// No specific signal selection //// - if ((optList.size() == 0) || (isANumber((string)optList[0]) == false)) { - delete mg; - sprintf(title, "Event ID %d", this->GetID()); - mg = new TMultiGraph(); + std::vector sIDs; // Signal IDs to print + ///// No specific signal selection //// + if ((optList.empty()) || !(isANumber((string)optList[0]))) { int sigPrinted = 0; // If threshold and baseline options are given - if (ThresCheck == true && BLCheck == true) { + if (ThresCheck && BLCheck) { debug << "Draw only good signals with: " << endl; debug << " Signal threshold: " << signalTh << endl; debug << " Point threshold: " << pointTh << endl; @@ -518,62 +508,31 @@ TPad* TRestRawSignalEvent::DrawEvent(const TString& option) { for (int n = 0; n < nSignals; n++) { fSignal[n].CalculateBaseLine(baseLineRangeInit, baseLineRangeEnd); fSignal[n].InitializePointsOverThreshold(TVector2(pointTh, signalTh), nOver); - if (fSignal[n].GetPointsOverThreshold().size() >= 2 && sRangeID == false) { - TGraph* gr = fSignal[n].GetGraph(n + 1); - mg->Add(gr); - sigPrinted++; - if (printIDs == true) { - cout << "id : " << fSignal[n].GetID() << endl; - } - } - if (fSignal[n].GetPointsOverThreshold().size() >= 2 && sRangeID == true) { - if (fSignal[n].GetID() >= sRangeInit && fSignal[n].GetID() <= sRangeEnd) { - TGraph* gr = fSignal[n].GetGraph(n + 1); - mg->Add(gr); - sigPrinted++; - if (printIDs == true) { - cout << fSignal[n].GetID() << endl; - } - } + if (fSignal[n].GetPointsOverThreshold().size() >= 2) { + sIDs.push_back(fSignal[n].GetID()); } } - } - // If no threshold and baseline options are given - else { + // If no threshold and baseline options are given + } else { for (int n = 0; n < nSignals; n++) { - if (sRangeID == false) { - TGraph* gr = fSignal[n].GetGraph(n + 1); - mg->Add(gr); - sigPrinted++; - if (printIDs == true) { - cout << fSignal[n].GetID() << endl; - } - } - if (sRangeID == true) { - if (fSignal[n].GetID() >= sRangeInit && fSignal[n].GetID() <= sRangeEnd) { - TGraph* gr = fSignal[n].GetGraph(n + 1); - mg->Add(gr); - sigPrinted++; - if (printIDs == true) { - cout << fSignal[n].GetID() << endl; - } - } - } + sIDs.push_back(fSignal[n].GetID()); } } - cout << "Number of drawn signals: " << sigPrinted << endl; - - fPad->cd(); - fPad->DrawFrame(0, GetMinValue() - 1, GetMaxTime() + 1, GetMaxValue() + 1); - mg->Draw(""); - mg->SetTitle(title); - mg->GetXaxis()->SetTitle("time bins"); - mg->GetYaxis()->SetTitleOffset(1.4); - mg->GetYaxis()->SetTitle("Amplitude [ADC units]"); - } - //// Signal selection (range or sigle signal) //// - else if (isANumber((string)optList[0]) == true) { + // Remove SIDs which are not in range + if (sRangeID) { + for (auto it = sIDs.begin(); it != sIDs.end();) + if (*it >= sRangeInit && *it <= sRangeEnd) { + ++it; + } else { + it = sIDs.erase(it); + } + } + + cout << "Number of drawn signals: " << sIDs.size() << endl; + + //// Signal selection (range or sigle signal) //// + } else if (isANumber((string)optList[0])) { string str = (string)optList[0]; size_t separation = str.find("-"); @@ -590,11 +549,9 @@ TPad* TRestRawSignalEvent::DrawEvent(const TString& option) { return fPad; } - delete mg; - mg = new TMultiGraph(); sprintf(title, "Event ID %d", this->GetID()); - if (ThresCheck == true && BLCheck == true) { + if (ThresCheck && BLCheck) { debug << "Draw only good signals with: " << endl; debug << " Signal threshold: " << signalTh << endl; debug << " Point threshold: " << pointTh << endl; @@ -602,73 +559,93 @@ TPad* TRestRawSignalEvent::DrawEvent(const TString& option) { debug << " Base line range: (" << baseLineRangeInit << "," << baseLineRangeEnd << ")" << endl; - int sigPrinted = 0; for (int n = 0; n < nSignals; n++) { + if (n < StringToInteger((string)firstSignal) || n > StringToInteger((string)lastSignal)) + continue; fSignal[n].CalculateBaseLine(baseLineRangeInit, baseLineRangeEnd); fSignal[n].InitializePointsOverThreshold(TVector2(pointTh, signalTh), nOver); - if (fSignal[n].GetPointsOverThreshold().size() >= 2 && - n >= StringToInteger((string)firstSignal) && - n <= StringToInteger((string)lastSignal)) { - TGraph* gr = fSignal[n].GetGraph(n + 1); - mg->Add(gr); - if (fMinValue > fSignal[n].GetMinValue()) fMinValue = fSignal[n].GetMinValue(); - if (fMaxValue < fSignal[n].GetMaxValue()) fMaxValue = fSignal[n].GetMaxValue(); - sigPrinted++; - if (printIDs == true) { - cout << fSignal[n].GetID() << endl; - } + if (fSignal[n].GetPointsOverThreshold().size() >= 2) { + sIDs.push_back(fSignal[n].GetID()); } } cout << "Number of good signals in range (" << firstSignal << "," << lastSignal - << "): " << sigPrinted << endl; - } - // If no threshold and baseline options are given - else { + << "): " << sIDs.size() << endl; + // If no threshold and baseline options are given + } else { for (int n = StringToInteger((string)firstSignal); n < StringToInteger((string)lastSignal) + 1; n++) { - TGraph* gr = fSignal[n].GetGraph(n + 1); - mg->Add(gr); - if (printIDs == true) { - cout << fSignal[n].GetID() << endl; - } - if (fMinValue > fSignal[n].GetMinValue()) fMinValue = fSignal[n].GetMinValue(); - if (fMaxValue < fSignal[n].GetMaxValue()) fMaxValue = fSignal[n].GetMaxValue(); + sIDs.push_back(fSignal[n].GetID()); } } - fPad->cd(); - fPad->DrawFrame(0, fMinValue - 1, GetMaxTime() + 1, fMaxValue + 1); - mg->SetTitle(title); - mg->Draw(""); - mg->GetXaxis()->SetTitle("time bins"); - mg->GetYaxis()->SetTitleOffset(1.4); - mg->GetYaxis()->SetTitle("Amplitude [ADC units]"); + // Single signal // + } else { + int signalid = StringToInteger((string)optList[0]); + sIDs.push_back(signalid); } + } - // Single signal // - if (separation == string::npos) { - int signalid = StringToInteger((string)optList[0]); + if (sIDs.empty()) { + fPad->SetTitle("No Such Signal"); + cout << "No signals found" << endl; + return fPad; + } - if (signalid >= fSignal.size()) { - fPad->SetTitle("No Such Signal"); - cout << "No such signal" << endl; - return fPad; - } - TRestRawSignal& sgn = fSignal[signalid]; + if (printIDs) + for (const auto& s : sIDs) cout << s << endl; - sprintf(title, "Event ID %d, Signal ID. %d", this->GetID(), sgn.GetID()); + DrawSignals(fPad, sIDs); - gr = sgn.GetGraph(1); - gr->SetTitle(title); - gr->GetXaxis()->SetTitle("time bins"); - gr->GetYaxis()->SetTitleOffset(1.4); - gr->GetYaxis()->SetTitle("Amplitude [a.u.]"); + return fPad; +} - fPad->cd(); - gr->Draw("ALP"); +/////////////////////////////////////////////// +/// \brief This method draws selected signal IDs, given by the vector +/// passed as reference +/// +void TRestRawSignalEvent::DrawSignals(TPad* pad, const std::vector& signals) { + int maxSID = -1; + int max = 0; + int color = 1; + + for (const auto& s : signals) { + TRestRawSignal* sgnl = GetSignalById(s); + if (!sgnl) continue; + TGraph* gr = sgnl->GetGraph(color); + const double maxV = TMath::MaxElement(gr->GetN(), gr->GetY()); + if (maxV > max) { + max = maxV; + maxSID = s; } + color++; } - return fPad; + debug << "Max SID " << maxSID << endl; + + if (maxSID == -1) { + cout << "No signals ID found" << endl; + return; + } + + TRestRawSignal* sgn = GetSignalById(maxSID); + std::string title = "Event ID " + std::to_string(GetID()); + if (signals.size() == 1) title += " Signal ID " + std::to_string(maxSID); + + sgn->fGraph->SetTitle(title.c_str()); + sgn->fGraph->GetXaxis()->SetTitle("Time bin"); + sgn->fGraph->GetYaxis()->SetTitleOffset(1.4); + sgn->fGraph->GetYaxis()->SetTitle("Amplitude [a.u.]"); + pad->Draw(); + pad->cd(); + sgn->fGraph->Draw("AL"); + + for (const auto& s : signals) { + if (s == maxSID) continue; + TRestRawSignal* sgnl = GetSignalById(s); + pad->cd(); + sgnl->fGraph->Draw("L"); + } + + pad->Update(); } ///////////////////////////////////////////////