Commit 0b02b060 authored by Jérémie Dudouet's avatar Jérémie Dudouet
Browse files

TH1D fitter updated:

It is now possible to move the arrows of the fit by hand, or direclty by setting the energy using right click
parent 9825ca28
......@@ -8,7 +8,6 @@
#include "TGNumberEntry.h"
#include "TGButton.h"
#include "TGLabel.h"
#include "TArrow.h"
#include "TSpectrum.h"
#include "TROOT.h"
#include "TLatex.h"
......@@ -243,7 +242,7 @@ void CXHist1DPlayer::PeakSearch()
Float_t Value = tspec->GetPositionY()[i];
Float_t MaxGlob = fCurrentHist->GetMaximum();
TArrow *GammaArrow = new TArrow(Energy,(Value + MaxGlob/100.) ,Energy,(Value +MaxGlob/15.),0.01,"<|");
CXArrow *GammaArrow = new CXArrow(Energy,(Value + MaxGlob/100.) ,(Value +MaxGlob/15.),0.01,"<|");
GammaArrow->SetAngle(40);
GammaArrow->SetLineColor(fCurrentHist->GetLineColor());
......@@ -313,10 +312,17 @@ void CXHist1DPlayer::HandleMouse(Int_t EventType,Int_t EventX,Int_t EventY, TObj
if(pad==nullptr)
return;
if(EventType == kButton1Up && selected && selected->InheritsFrom("CXArrow")) {
CXArrow *arr = dynamic_cast<CXArrow*>(selected);
arr->SetEnergy(pad->AbsPixeltoX(EventX));
AddFitValue(-1);
}
if(DoNewFit)
{
if(EventType == kButton1Up)
{
{
if(EventType == kButton1Up && (!selected || !selected->InheritsFrom("CXArrow"))) {
if( pad->AbsPixeltoX(EventX)>gPad->GetUxmin() &&
pad->AbsPixeltoX(EventX)<gPad->GetUxmax() &&
pad->AbsPixeltoY(EventY)>gPad->GetUymin() &&
......@@ -337,11 +343,16 @@ void CXHist1DPlayer::HandleMouse(Int_t EventType,Int_t EventX,Int_t EventY, TObj
void CXHist1DPlayer::AddFitValue(Float_t energy)
{
CleanFitMarkers();
fFitBackgd.clear();
fFitEnergies.clear();
fEnergies.push_back(energy);
fEnergies.clear();
for(uint i=0 ; i<fListOfFitObjects->GetEntries() ; i++) {
CXArrow *arr = dynamic_cast<CXArrow*>(fListOfFitObjects->At(i));
fEnergies.push_back(arr->GetX1());
}
if(energy>0) fEnergies.push_back(energy);
sort(fEnergies.begin(),fEnergies.end());
for(uint i=0 ; i<fEnergies.size() ; i++)
......@@ -354,6 +365,7 @@ void CXHist1DPlayer::AddFitValue(Float_t energy)
fFitEnergies.push_back(fEnergies[i]);
}
CleanFitMarkers();
UpdateFitLines();
}
......@@ -377,15 +389,15 @@ void CXHist1DPlayer::UpdateFitLines()
{
Float_t MaxGlob = fCurrentHist->GetMaximum();
Float_t Value = fCurrentHist->GetBinContent(fCurrentHist->FindBin(fFitBackgd[i]));
TArrow *arrow = new TArrow(fFitBackgd[i],(Value + MaxGlob/100.) ,fFitBackgd[i],(Value +MaxGlob/15.),0.01,"<|");
CXArrow *arrow = new CXArrow(fFitBackgd[i],(Value + MaxGlob/100.) ,(Value +MaxGlob/15.),0.01,"<|");
arrow->SetList(fListOfFitObjects);
arrow->SetAngle(30);
arrow->SetLineColor(kBlue);
arrow->SetFillColor(kBlue);
arrow->SetLineWidth(2);
arrow->Draw();
arrow->SetBit(TObject::kCannotPick);
// arrow->SetBit(TObject::kCannotPick);
fListOfFitObjects->Add(arrow);
}
......@@ -393,15 +405,15 @@ void CXHist1DPlayer::UpdateFitLines()
{
Float_t MaxGlob = fCurrentHist->GetMaximum();
Float_t Value = fCurrentHist->GetBinContent(fCurrentHist->FindBin(fFitEnergies[i]));
TArrow *arrow = new TArrow(fFitEnergies[i],(Value + MaxGlob/100.) ,fFitEnergies[i],(Value +MaxGlob/15.),0.01,"<|");
CXArrow *arrow = new CXArrow(fFitEnergies[i],(Value + MaxGlob/100.) , (Value +MaxGlob/15.),0.01,"<|");
arrow->SetList(fListOfFitObjects);
arrow->SetAngle(30);
arrow->SetLineColor(kRed);
arrow->SetFillColor(kRed);
arrow->SetLineWidth(2);
arrow->Draw();
arrow->SetBit(TObject::kCannotPick);
// arrow->SetBit(TObject::kCannotPick);
fListOfFitObjects->Add(arrow);
}
......@@ -480,6 +492,8 @@ void CXHist1DPlayer::DoFit()
return;
}
AddFitValue(-1);
fFitResultsBox->RemoveAll();
Float_t DefFWHM = fNE_FWHM[0]->GetNumber();
......
......@@ -3,6 +3,7 @@
#include "RQ_OBJECT.h"
#include "TGFrame.h"
#include "TArrow.h"
using namespace std;
......@@ -13,6 +14,26 @@ class TH1;
class TGCheckButton;
class TGListBox;
class CXArrow : public TArrow
{
RQ_OBJECT("CXArrow");
private:
TList *fList = nullptr;
public:
CXArrow(Double_t E,Double_t y1 ,Double_t y2,Float_t arrowsize=0.05,Option_t *option=">") : TArrow(E, y1, E, y2, arrowsize, option){;}
~CXArrow(){;}
void SetEnergy(Float_t E){SetX1(E);SetX2(E);} // *MENU* *ARGS={E=>fX1}*
void SetList(TList *l){fList = l;}
void Remove(){if(fList){fList->Remove(this);} delete this;} // *MENU*
ClassDef(CXArrow,0);
};
class CXHist1DPlayer : public TGVerticalFrame
{
RQ_OBJECT("CXHist1DPlayer");
......
......@@ -824,6 +824,17 @@ void CXMainWindow::UpdateContextMenus()
ml->AddAt(n,12);
// n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl);ml->AddAt(n,ml->GetEntries()-4);
/// CXArrow ///
cl = gROOT->GetClass("CXArrow");
cl->MakeCustomMenuList();
ml = cl->GetMenuList();
for(int i=0 ; i<18 ; i++)
ml->RemoveAt(ml->GetEntries()-1);
// n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl);ml->AddAt(n,ml->GetEntries()-4);
}
void CXMainWindow::Rebin2D(Int_t RebinX, Int_t RebinY, TObject *c)
......
......@@ -22,5 +22,6 @@
#pragma link C++ class CXGammaSearch;
#pragma link C++ class CXSpreadIntensityMatrix;
#pragma link C++ class CXGateBox;
#pragma link C++ class CXArrow;
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment