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

Merge branch 'Cubix' into 'Cubix'

Add X,Y projections in standard GG mode

See merge request !47
parents d540e132 5f0f1794
Pipeline #43932 passed with stage
in 8 minutes and 14 seconds
......@@ -14,6 +14,7 @@
#include "TGListBox.h"
#include "TError.h"
#include "TObjArray.h"
#include "TGComboBox.h"
#include "CXMainWindow.h"
#include "CXTH1Proj.h"
......@@ -38,6 +39,16 @@ CXHist2DPlayer::CXHist2DPlayer(const TGCompositeFrame *MotherFrame, UInt_t w, UI
fGroupFrame->AddFrame(fSubGroupFrame, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, -10, -10, 0, 0));
TGCompositeFrame *fHorizontalFrame = new TGCompositeFrame(fSubGroupFrame, 60, 20, kHorizontalFrame);
fHorizontalFrame->AddFrame(new TGLabel(fHorizontalFrame, "Projection axis: "), new TGLayoutHints(kLHintsCenterY | kLHintsLeft,5,10,0,0));
fProjectionAxis = new TGComboBox(fHorizontalFrame);
fHorizontalFrame->AddFrame(fProjectionAxis,new TGLayoutHints(kLHintsCenterY | kLHintsLeft | kLHintsExpandX | kLHintsExpandY ,1,3,0,0));
fProjectionAxis->AddEntry("X",0);
fProjectionAxis->AddEntry("Y",1);
fProjectionAxis->Select(0);
fProjectionAxis->Connect("Selected(Int_t)", "CXHist2DPlayer", this, "UpdateProjection()");
fSubGroupFrame->AddFrame(fHorizontalFrame,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,-10,-10,5,5));
fHorizontalFrame = new TGCompositeFrame(fSubGroupFrame, 60, 20, kHorizontalFrame);
TGTextButton *GateButton = new TGTextButton(fHorizontalFrame, "Gate");
GateButton->SetTextColor(CXred);
GateButton->Connect("Clicked()", "CXHist2DPlayer", this, "AddGate()");
......@@ -184,6 +195,21 @@ void CXHist2DPlayer::SetMainWindow(CXMainWindow *w)
fMainWindow = w;
}
void CXHist2DPlayer::UpdateProjection()
{
if(fAxisProj == fProjectionAxis->GetSelected())
return;
if(fProjectionAxis->GetSelected()==0)
fAxisProj = 0;
else
fAxisProj = 1;
GetProj()->UpdateProjection(fAxisProj);
Project();
}
void CXHist2DPlayer::InitGG(TH2 *hist_in)
{
TH2 *hist;
......@@ -195,22 +221,25 @@ void CXHist2DPlayer::InitGG(TH2 *hist_in)
else
hist = hist_in;
if(hist == nullptr)
{
if(hist == nullptr) {
cout<<"No 2D histogram found in the current pad, ignored"<<endl;
return;
}
if(fTotProjX){
if(fAxisProj==0) {
TotalProj = hist->ProjectionX(Form("%s_2DTotProjX",hist->GetName()));
TotalProj->SetName(Form("%s_TotProjX",hist->GetName()));
TotalProj->SetTitle(Form("%s TotProjX",hist->GetTitle()));
}
else{
else if(fAxisProj==1){
TotalProj = hist->ProjectionY(Form("%s_2DTotProjY",hist->GetName()));
TotalProj->SetName(Form("%s_TotProjY",hist->GetName()));
TotalProj->SetTitle(Form("%s TotProjY",hist->GetTitle()));
}
else {
ERR_MESS << "Unkown projection axis... " << ENDL;
return;
}
CXTH1Proj *NewProj = new CXTH1Proj(*TotalProj);
NewProj->SetMainWindow(fMainWindow);
......
......@@ -13,6 +13,7 @@ class TGListBox;
class TGLBEntry;
class TGCheckButton;
class TGTextEntry;
class TGComboBox;
class CXHist2DPlayer : public TGVerticalFrame
{
......@@ -22,7 +23,7 @@ private:
CXMainWindow *fMainWindow = nullptr;
Bool_t fTotProjX = true;
Int_t fAxisProj = 0; // X => 0 ; Y => 1
CXTH1Proj *fCurrentProj = nullptr;
......@@ -31,6 +32,8 @@ private:
TGTextEntry *fDrawOpt = nullptr;
TGCheckButton *fFixRange = nullptr;
TGComboBox *fProjectionAxis = nullptr;
public:
CXHist2DPlayer(const TGCompositeFrame *MotherFrame, UInt_t w, UInt_t h, CXMainWindow *window);
~CXHist2DPlayer();
......@@ -38,6 +41,8 @@ public:
void SetMainWindow(CXMainWindow *w);
void InitGG(TH2 *hist_in =nullptr);
void UpdateProjection();
void Project();
void AddBackgd();
void AddGate();
......
......@@ -22,7 +22,7 @@ using namespace std;
CXTH1Proj::CXTH1Proj(const TH1D &hist): TH1D::TH1D(hist)
{
GetXaxis()->SetTitle("Energy (kev)");
GetXaxis()->SetTitle("Energy (kev) [X axis]");
GetXaxis()->SetTitleSize(0.05);
GetXaxis()->SetTitleOffset(0.8);
GetXaxis()->SetTitleFont(132);
......@@ -55,6 +55,34 @@ CXTH1Proj::~CXTH1Proj()
delete fListOfGates;
}
void CXTH1Proj::UpdateProjection(Int_t Axis)
{
if(fGGHist->GetXaxis()->GetNbins() != fGGHist->GetYaxis()->GetNbins()) {
WARN_MESS << "X and Y axis needs to have the same number of bins for GG projections" << ENDL;
return;
}
if(Axis == 0) {
GetXaxis()->SetTitle("Energy (kev) [X axis]");
TH1 *projtmp = fGGHist->ProjectionX();
for(int i=0 ; i<projtmp->GetNbinsX()+2 ; i++)
SetBinContent(i,projtmp->GetBinContent(i));
delete projtmp;
}
else if(Axis == 1) {
GetXaxis()->SetTitle("Energy (kev) [Y axis]");
TH1 *projtmp = fGGHist->ProjectionY();
for(int i=0 ; i<projtmp->GetNbinsX()+2 ; i++)
SetBinContent(i,projtmp->GetBinContent(i));
delete projtmp;
}
fProjectionAxis = Axis;
fCurrentPad->Modified();
fCurrentPad->Update();
}
void CXTH1Proj::SetPlayer(CXHist2DPlayer *p)
{
f2DPlayer = p;
......@@ -157,7 +185,13 @@ void CXTH1Proj::Project(Bool_t FixRange){
Float_t WidthRef = FinalProj->GetBinWidth(1);
FinalProj->GetXaxis()->SetTitle(GetXaxis()->GetTitle());
TString XAxis = GetXaxis()->GetTitle();
if(XAxis.Contains("[X"))
XAxis.ReplaceAll("[X","[Y");
else if(XAxis.Contains("[Y"))
XAxis.ReplaceAll("[Y","[X");
FinalProj->GetXaxis()->SetTitle(XAxis);
FinalProj->GetXaxis()->SetTitleSize(GetXaxis()->GetTitleSize());
FinalProj->GetXaxis()->SetTitleOffset(GetXaxis()->GetTitleOffset());
FinalProj->GetXaxis()->SetTitleFont(GetXaxis()->GetTitleFont());
......@@ -188,7 +222,12 @@ void CXTH1Proj::Project(Bool_t FixRange){
continue;
for(int ibin=BinX1 ; ibin<BinX2 ; ibin++) {
TH1D *temp = fGGHist->ProjectionX("tmp",ibin,ibin);
TH1D *temp = nullptr;
if(fProjectionAxis==0)
temp = fGGHist->ProjectionY("tmp",ibin,ibin);
else if(fProjectionAxis==1)
temp = fGGHist->ProjectionX("tmp",ibin,ibin);
temp->Scale(FinalProj->GetBinWidth(ibin)/WidthRef);
FinalProj->Add(temp,Weight);
delete temp;
......
......@@ -41,6 +41,8 @@ private:
CXHist2DPlayer *f2DPlayer = nullptr;
Int_t fProjectionAxis = 0;
public:
CXTH1Proj(const TH1D &hist);
CXTH1Proj();
......@@ -48,6 +50,7 @@ public:
void SetMainWindow(CXMainWindow *w);
void UpdateProjection(Int_t Axis);
void SetTH2(TH2 *hist);
void SetProjPad(TPad *pad);
void SetCurrentPad(TPad *pad);
......
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