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

Correct the problem of background subtraction (bad dynamical cast)

parent 35a023c5
Pipeline #160997 passed with stage
in 16 minutes and 15 seconds
......@@ -264,16 +264,14 @@ void CXBgdUtility::DoSubtract()
TH1 *hist = fMainWindow->GetHisto();
if(hist == nullptr || hist->InheritsFrom("TH2"))
{
if(hist == nullptr || hist->InheritsFrom("TH2")) {
cout<<"No 1D istogram found, ignored"<<endl;
return;
}
TH1 *bkgrd = dynamic_cast<TH1*>(gPad->GetListOfPrimitives()->FindObject(Form("%s_BG",hist->GetName())));
if(bkgrd == nullptr)
{
if(bkgrd == nullptr) {
cout<<"No background histogram built in the pad for hist: "<<hist->GetName()<<endl;
return;
}
......@@ -298,20 +296,16 @@ void CXBgdUtility::ToggleBckSupp()
if(gPad == nullptr)
return;
if(fActivate->GetState() == kButtonDown)
{
if(fActivate->GetState() == kButtonDown) {
SetButtonsStatus(true);
GetParams();
}
else
{
else {
SetButtonsStatus(false);
for(int i=gPad->GetListOfPrimitives()->GetEntries()-1 ; i>=0 ; i--)
{
for(int i=gPad->GetListOfPrimitives()->GetEntries()-1 ; i>=0 ; i--) {
TObject *o = gPad->GetListOfPrimitives()->At(i);
if(o->InheritsFrom("TH1") && ((TString)o->GetName()).EndsWith("_BG"))
{
if(o->InheritsFrom("TH1") && ((TString)o->GetName()).EndsWith("_BG")) {
delete o;
break;
}
......@@ -326,8 +320,7 @@ void CXBgdUtility::SetButtonsStatus(bool on)
{
fNItersButton1D->SetState(on);
for(int i=1 ; i<fListOfButtons1D->GetEntries() ; i++)
{
for(int i=1 ; i<fListOfButtons1D->GetEntries() ; i++) {
auto *btn = dynamic_cast<TGButton*>(fListOfButtons1D->At(i));
if(!fSmoothing && i>=8 && i<=14)
......@@ -359,8 +352,7 @@ void CXBgdUtility::GetParams()
else if(fFilterOrder1D == TSpectrum::kBackOrder8) Option += "BackOrder8";
if(!fSmoothing) Option += "nosmoothing";
else
{
else {
if(fSmoothingWindow == TSpectrum::kBackSmoothing3) Option += "BackSmoothing3";
else if(fSmoothingWindow == TSpectrum::kBackSmoothing5) Option += "BackSmoothing5";
else if(fSmoothingWindow == TSpectrum::kBackSmoothing7) Option += "BackSmoothing7";
......@@ -372,10 +364,9 @@ void CXBgdUtility::GetParams()
}
if(fCompton) Option += "Compton";
TH1 *hist = dynamic_cast<TH1F*>(fMainWindow->GetHisto());
TH1 *hist = dynamic_cast<TH1*>(fMainWindow->GetHisto());
if(hist == nullptr || hist->InheritsFrom("TH2"))
{
if(hist == nullptr || hist->InheritsFrom("TH2")) {
cout<<"No 1D istogram found, ignored"<<endl;
return;
}
......@@ -409,24 +400,19 @@ void CXBgdUtility::HandleWindowButtons(Int_t id)
if (id == -1)
id = btn->WidgetId();
if(id == 0)
{
if(id == 0) {
fDirectionButton1D[1]->SetState(kButtonUp);
fDirection1D = TSpectrum::kBackIncreasingWindow;
}
if(id == 1)
{
if(id == 1) {
fDirectionButton1D[0]->SetState(kButtonUp);
fDirection1D = TSpectrum::kBackDecreasingWindow;
}
if(id == 10)
{
if(id == 10) {
fDirectionButton2D[1]->SetState(kButtonUp);
fDirection2D = TSpectrum::kBackIncreasingWindow;
}
if(id == 11)
{
if(id == 11) {
fDirectionButton2D[0]->SetState(kButtonUp);
fDirection2D = TSpectrum::kBackDecreasingWindow;
}
......@@ -465,15 +451,11 @@ void CXBgdUtility::HandleSmoothButtons(Int_t id)
if (id == -1)
id = btn->WidgetId();
if(id == -2)
{
if(btn->GetState() == kButtonDown)
{
if(id == -2) {
if(btn->GetState() == kButtonDown) {
fSmoothing = true;
for(int i=0 ; i<7 ; i++)
{
if(fSmoothingButton1D.at(i)->IsDown())
{
for(int i=0 ; i<7 ; i++) {
if(fSmoothingButton1D.at(i)->IsDown()) {
fSmoothingButton1D.at(i)->SetState(kButtonDown);
fSmoothingWindow = 3+2*i;
}
......@@ -481,8 +463,7 @@ void CXBgdUtility::HandleSmoothButtons(Int_t id)
fSmoothingButton1D.at(i)->SetState(kButtonUp);
}
}
else
{
else {
fSmoothing = false;
for(int i=0 ; i<7 ; i++)
fSmoothingButton1D.at(i)->SetState(kButtonDisabled);
......@@ -490,8 +471,7 @@ void CXBgdUtility::HandleSmoothButtons(Int_t id)
return;
}
for(int i=0 ; i<7 ; i++)
{
for(int i=0 ; i<7 ; i++) {
if(id != i)
fSmoothingButton1D.at(i)->SetState(kButtonUp);
else
......@@ -510,8 +490,7 @@ void CXBgdUtility::Do2DEvaluation(TH1 *hist_in)
if(hist && hist->InheritsFrom("TH2"))
fCurrent2DHist = dynamic_cast<TH2*>(hist);
else
{
else {
cout<<"No 2D histogram found in the current pad, ignored"<<endl;
fCurrent2DHist = nullptr;
return;
......
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