Commit 47cc72fa authored by Jérémie Dudouet's avatar Jérémie Dudouet Committed by Jérémie Dudouet
Browse files

correct the position of the fix FWHM, update the coding style

parent 54df1eb2
......@@ -79,7 +79,6 @@ CXHist1DPlayer::CXHist1DPlayer(const TGCompositeFrame *MotherFrame, UInt_t w, UI
fGroupFrame->AddFrame(fHorizontalFrame,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,-10,-10,5,10));
TGLabel *label;
fHorizontalFrame = new TGCompositeFrame(fGroupFrame, 60, 20, kHorizontalFrame);
......@@ -98,14 +97,6 @@ CXHist1DPlayer::CXHist1DPlayer(const TGCompositeFrame *MotherFrame, UInt_t w, UI
fHorizontalFrame->AddFrame(fFixAmpli,new TGLayoutHints(kLHintsTop | kLHintsLeft,15,5,0,0));
fGroupFrame->AddFrame(fHorizontalFrame,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,-10,-10,0,5));
fHorizontalFrame = new TGCompositeFrame(fGroupFrame, 60, 20, kHorizontalFrame);
fHorizontalFrame->AddFrame(label = new TGLabel(fHorizontalFrame, "FWHM:"),new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 24, 0, 0));
label->SetTextColor(CXblue);
fFixFWHM = new TGCheckButton(fHorizontalFrame, "Fixed", 0);
fFixFWHM->Connect("Clicked()", "CXHist1DPlayer", this, "HandleMyButton()");
fHorizontalFrame->AddFrame(fFixFWHM,new TGLayoutHints(kLHintsTop | kLHintsLeft,15,5,0,0));
fGroupFrame->AddFrame(fHorizontalFrame,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,-10,-10,0,5));
fHorizontalFrame = new TGCompositeFrame(fGroupFrame, 60, 20, kHorizontalFrame);
fHorizontalFrame->AddFrame(label = new TGLabel(fHorizontalFrame, "Background:"),new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 0, 0, 0));
label->SetTextColor(CXblue);
......@@ -119,6 +110,14 @@ CXHist1DPlayer::CXHist1DPlayer(const TGCompositeFrame *MotherFrame, UInt_t w, UI
fHorizontalFrame->AddFrame(fBckPol1,new TGLayoutHints(kLHintsTop | kLHintsLeft,5,5,0,0));
fGroupFrame->AddFrame(fHorizontalFrame,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,-10,-10,0,5));
fHorizontalFrame = new TGCompositeFrame(fGroupFrame, 60, 20, kHorizontalFrame);
fHorizontalFrame->AddFrame(label = new TGLabel(fHorizontalFrame, "FWHM:"),new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 24, 0, 0));
label->SetTextColor(CXblue);
fFixFWHM = new TGCheckButton(fHorizontalFrame, "Fixed", 0);
fFixFWHM->Connect("Clicked()", "CXHist1DPlayer", this, "HandleMyButton()");
fHorizontalFrame->AddFrame(fFixFWHM,new TGLayoutHints(kLHintsTop | kLHintsLeft,15,5,0,0));
fGroupFrame->AddFrame(fHorizontalFrame,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,-10,-10,0,5));
fHorizontalFrame = new TGCompositeFrame(fGroupFrame, 60, 20, kHorizontalFrame);
fHorizontalFrame->AddFrame(new TGLabel(fHorizontalFrame, "Val "),new TGLayoutHints(kLHintsTop | kLHintsLeft, 3, 3, 0, 0));
fNE_FWHM[0] = new TGNumberEntry(fHorizontalFrame, (Double_t)5, 7,0, TGNumberFormat::kNESReal, TGNumberFormat::kNEAPositive ,TGNumberFormat::kNELNoLimits);
......@@ -212,14 +211,12 @@ void CXHist1DPlayer::PeakClear()
{
TVirtualPad *pad = fMainWindow->GetSelectedPad();
if(pad==nullptr)
{
if(pad==nullptr) {
cout<<"No selected pad, ignored"<<endl;
return;
}
while(fListOfPSObjects->GetEntries())
{
while(fListOfPSObjects->GetEntries()) {
TObject *o = fListOfPSObjects->First();
pad->GetListOfPrimitives()->Remove(o);
fListOfPSObjects->Remove(o);
......@@ -238,8 +235,7 @@ void CXHist1DPlayer::PeakSearch()
fCurrentHist = fMainWindow->GetHisto();
if(fCurrentHist==nullptr || fCurrentHist->InheritsFrom("TH2"))
{
if(fCurrentHist==nullptr || fCurrentHist->InheritsFrom("TH2")) {
cout<<"No 1D histogram found, ignored"<<endl;
return;
}
......@@ -249,8 +245,7 @@ void CXHist1DPlayer::PeakSearch()
Int_t NPeaks = tspec->GetNPeaks();
for(int i=0 ; i<NPeaks ; i++)
{
for(int i=0 ; i<NPeaks ; i++) {
Float_t Energy = tspec->GetPositionX()[i];
Float_t Value = tspec->GetPositionY()[i];
Float_t MaxGlob = fCurrentHist->GetMaximum();
......@@ -294,8 +289,7 @@ void CXHist1DPlayer::NewFit()
fCurrentHist = fMainWindow->GetHisto();
if(fCurrentHist==nullptr || fCurrentHist->InheritsFrom("TH2"))
{
if(fCurrentHist==nullptr || fCurrentHist->InheritsFrom("TH2")) {
cout<<"No 1D istogram found, ignored"<<endl;
return;
}
......@@ -333,21 +327,18 @@ void CXHist1DPlayer::HandleMouse(Int_t EventType,Int_t EventX,Int_t EventY, TObj
AddFitValue(-1);
}
if(DoNewFit)
{
if(DoNewFit) {
if(EventType == kButton1Up && (!selected || !selected->InheritsFrom("CXArrow"))) {
if( pad->AbsPixeltoX(EventX)>gPad->GetUxmin() &&
pad->AbsPixeltoX(EventX)<gPad->GetUxmax() &&
pad->AbsPixeltoY(EventY)>gPad->GetUymin() &&
pad->AbsPixeltoY(EventY)<gPad->GetUymax()
)
{
) {
Float_t E = pad->AbsPixeltoX(EventX);
AddFitValue(E);
}
}
if(EventType == kButton1Double)
{
if(EventType == kButton1Double) {
DoNewFit = false;
DoFit();
}
......@@ -368,8 +359,7 @@ void CXHist1DPlayer::AddFitValue(Float_t energy)
if(energy>0) fEnergies.push_back(energy);
sort(fEnergies.begin(),fEnergies.end());
for(uint i=0 ; i<fEnergies.size() ; i++)
{
for(uint i=0 ; i<fEnergies.size() ; i++) {
if(i==0)
fFitBackgd.push_back(fEnergies[i]);
else if(i == (fEnergies.size()-1))
......@@ -386,20 +376,17 @@ void CXHist1DPlayer::UpdateFitLines()
{
TVirtualPad *pad = fMainWindow->GetSelectedPad();
if(fCurrentHist==nullptr)
{
if(fCurrentHist==nullptr) {
cout<<"No histogram found, ignored"<<endl;
return;
}
if(pad==nullptr)
{
if(pad==nullptr) {
cout<<"No selected pad, ignored"<<endl;
return;
}
for(uint i=0 ; i<fFitBackgd.size() ; i++)
{
for(uint i=0 ; i<fFitBackgd.size() ; i++) {
Float_t MaxGlob = fCurrentHist->GetMaximum();
Float_t Value = fCurrentHist->GetBinContent(fCurrentHist->FindBin(fFitBackgd[i]));
CXArrow *arrow = new CXArrow(fFitBackgd[i],(Value + MaxGlob/100.) ,(Value +MaxGlob/15.),0.01,"<|");
......@@ -414,8 +401,7 @@ void CXHist1DPlayer::UpdateFitLines()
fListOfFitObjects->Add(arrow);
}
for(uint i=0 ; i<fFitEnergies.size() ; i++)
{
for(uint i=0 ; i<fFitEnergies.size() ; i++) {
Float_t MaxGlob = fCurrentHist->GetMaximum();
Float_t Value = fCurrentHist->GetBinContent(fCurrentHist->FindBin(fFitEnergies[i]));
CXArrow *arrow = new CXArrow(fFitEnergies[i],(Value + MaxGlob/100.) , (Value +MaxGlob/15.),0.01,"<|");
......@@ -439,17 +425,14 @@ void CXHist1DPlayer::ClearFit(bool doend)
{
TVirtualPad *pad = fMainWindow->GetSelectedPad();
if(pad==nullptr)
{
if(pad==nullptr) {
cout<<"No selected pad, ignored"<<endl;
return;
}
for(int i=0 ; i<pad->GetListOfPrimitives()->GetEntries() ; i++)
{
for(int i=0 ; i<pad->GetListOfPrimitives()->GetEntries() ; i++) {
TObject *o = pad->GetListOfPrimitives()->At(i);
if(o->InheritsFrom("TF1"))
{
if(o->InheritsFrom("TF1")) {
pad->GetListOfPrimitives()->Remove(o);
i--;
}
......@@ -460,8 +443,7 @@ void CXHist1DPlayer::ClearFit(bool doend)
void CXHist1DPlayer::CleanFitMarkers()
{
while(fListOfFitObjects->GetEntries())
{
while(fListOfFitObjects->GetEntries()) {
TObject *o = fListOfFitObjects->First();
fMainWindow->GetCanvas()->GetListOfPrimitives()->Remove(o);
fListOfFitObjects->Remove(o);
......@@ -474,14 +456,12 @@ void CXHist1DPlayer::CleanFitMarkers()
void CXHist1DPlayer::DoFit()
{
if(DoNewFit==false && fEnergies.size()>=3)
{
if(DoNewFit==false && fEnergies.size()>=3) {
DoNewFit = true;
ClearFit(false);
}
if(fEnergies.size()<3)
{
if(fEnergies.size()<3) {
cout<<"At least one peak and two background are needed for a fit --> command ignored"<<endl;
return;
}
......@@ -491,16 +471,14 @@ void CXHist1DPlayer::DoFit()
gPad = fMainWindow->GetSelectedPad();
if(gPad==nullptr)
{
if(gPad==nullptr) {
cout<<"No selected pad, ignored"<<endl;
return;
}
fCurrentHist = fMainWindow->GetHisto();
if(fCurrentHist==nullptr || fCurrentHist->InheritsFrom("TH2"))
{
if(fCurrentHist==nullptr || fCurrentHist->InheritsFrom("TH2")) {
cout<<"No 1D histogram found, ignored"<<endl;
return;
}
......@@ -533,8 +511,7 @@ void CXHist1DPlayer::DoFit()
fFitFunction->SetParName(1, "BkgConst");
fFitFunction->SetParName(2, "BkgSlope");
for(uint i=0 ; i<fFitEnergies.size() ; i++)
{
for(uint i=0 ; i<fFitEnergies.size() ; i++) {
fFitFunction->SetParName(3+i*6+0, Form("Height_%d",i));
fFitFunction->SetParName(3+i*6+1, Form("Position_%d",i));
fFitFunction->SetParName(3+i*6+2, Form("FWHM_%d",i));
......@@ -563,8 +540,7 @@ void CXHist1DPlayer::DoFit()
if(fUsePol1==false)
fFitFunction->FixParameter(2,0);
for(uint i=0 ; i<fFitEnergies.size() ; i++)
{
for(uint i=0 ; i<fFitEnergies.size() ; i++) {
//Height
fFitFunction->SetParameter(3+i*6+0, fCurrentHist->GetBinContent(fCurrentHist->FindBin(fFitEnergies[i])) - (fCurrentHist->GetBinContent(fCurrentHist->FindBin(fFitBackgd[0]))+fCurrentHist->GetBinContent(fCurrentHist->FindBin(fFitBackgd[1])))*0.5 );
fFitFunction->SetParLimits(3+i*6+0, fCurrentHist->GetBinContent((fCurrentHist->FindBin(fFitEnergies[i]))-(fCurrentHist->GetBinContent(fCurrentHist->FindBin(fFitBackgd[0]))+fCurrentHist->GetBinContent(fCurrentHist->FindBin(fFitBackgd[1])))*0.5)*0.5, fCurrentHist->GetBinContent(fCurrentHist->GetMaximumBin()));
......@@ -603,8 +579,7 @@ void CXHist1DPlayer::DoFit()
TFitResultPtr r = fCurrentHist->Fit(fFitFunction,"R0S");
if(fFixAmpli->GetState() == kButtonDown)
{
if(fFixAmpli->GetState() == kButtonDown) {
//Extract Background
if(fBackFunction)
delete fBackFunction;
......@@ -612,11 +587,8 @@ void CXHist1DPlayer::DoFit()
fBackFunction = new TF1("Background", this, &CXHist1DPlayer::StepedBackground, fFitBackgd[0], fFitBackgd[1], NPars, "CXHist1DPlayer", "StepedBackground");
fBackFunction->SetParameters(fFitFunction->GetParameters());
for(uint i=0 ; i<fFitEnergies.size() ; i++)
{
Float_t Ampli = fCurrentHist->GetBinContent(fCurrentHist->FindBin(fFitEnergies[i]))-
fBackFunction->Eval(fFitEnergies[i]);
for(uint i=0 ; i<fFitEnergies.size() ; i++) {
Float_t Ampli = fCurrentHist->GetBinContent(fCurrentHist->FindBin(fFitEnergies[i]))- fBackFunction->Eval(fFitEnergies[i]);
fFitFunction->FixParameter(3+i*6+0,Ampli);
}
......@@ -666,8 +638,7 @@ void CXHist1DPlayer::DoFit()
text << "P val = "<< r->Prob();
cout<<text.str()<<endl;PrintInListBox(text.str(),kInfo);text.str("");
for(uint i=0 ; i< fFitEnergies.size() ; i++)
{
for(uint i=0 ; i< fFitEnergies.size() ; i++) {
text<<"Peak "<<i<<":";
cout<<text.str()<<endl;PrintInListBox(text.str(),kPrint);text.str("");
......@@ -759,73 +730,63 @@ void CXHist1DPlayer::HandleMyButton()
fUseStep = (Bool_t)fBckStep->GetState();
fUsePol1 = (Bool_t)fBckPol1->GetState();
if(fUseLT->GetState() == kButtonUp)
{
if(fUseLT->GetState() == kButtonUp) {
fFixLT->SetState(kButtonDisabled);
fNE_LT[0]->SetState(false);
fNE_LT[1]->SetState(false);
fNE_LT[2]->SetState(false);
}
else
{
else {
fFixLT->IsDown() ? fFixLT->SetState(kButtonDown) : fFixLT->SetState(kButtonUp);
fNE_LT[0]->SetState(true);
fNE_LT[1]->SetState(true);
fNE_LT[2]->SetState(true);
}
if(fUseLT->GetState() == kButtonDown && fFixLT->GetState() == kButtonDown)
{
if(fUseLT->GetState() == kButtonDown && fFixLT->GetState() == kButtonDown) {
fNE_LT[0]->SetState(true);
fNE_LT[1]->SetState(false);
fNE_LT[2]->SetState(false);
}
if(fUseLT->GetState() == kButtonDown && fFixLT->GetState() == kButtonUp)
{
if(fUseLT->GetState() == kButtonDown && fFixLT->GetState() == kButtonUp) {
fNE_LT[0]->SetState(true);
fNE_LT[1]->SetState(true);
fNE_LT[2]->SetState(true);
}
if(fUseRT->GetState() == kButtonUp)
{
if(fUseRT->GetState() == kButtonUp) {
fFixRT->SetState(kButtonDisabled);
fNE_RT[0]->SetState(false);
fNE_RT[1]->SetState(false);
fNE_RT[2]->SetState(false);
}
else
{
else {
fFixRT->IsDown() ? fFixRT->SetState(kButtonDown) : fFixRT->SetState(kButtonUp);
fNE_RT[0]->SetState(true);
fNE_RT[1]->SetState(true);
fNE_RT[2]->SetState(true);
}
if(fUseRT->GetState() == kButtonDown && fFixRT->GetState() == kButtonDown)
{
if(fUseRT->GetState() == kButtonDown && fFixRT->GetState() == kButtonDown) {
fNE_RT[0]->SetState(true);
fNE_RT[1]->SetState(false);
fNE_RT[2]->SetState(false);
}
if(fUseRT->GetState() == kButtonDown && fFixRT->GetState() == kButtonUp)
{
if(fUseRT->GetState() == kButtonDown && fFixRT->GetState() == kButtonUp) {
fNE_RT[0]->SetState(true);
fNE_RT[1]->SetState(true);
fNE_RT[2]->SetState(true);
}
if(fFixFWHM->GetState() == kButtonDown)
{
if(fFixFWHM->GetState() == kButtonDown) {
fNE_FWHM[0]->SetState(true);
fNE_FWHM[1]->SetState(false);
fNE_FWHM[2]->SetState(false);
}
if(fFixFWHM->GetState() == kButtonUp)
{
if(fFixFWHM->GetState() == kButtonUp) {
fNE_FWHM[0]->SetState(true);
fNE_FWHM[1]->SetState(true);
fNE_FWHM[2]->SetState(true);
......@@ -847,8 +808,7 @@ double CXHist1DPlayer::DoubleTailedStepedGaussian(double*xx,double*pp)
f_tot += Back_const + x*Back_slope;
for(int i=0 ; i<NSubPeaks ; i++)
{
for(int i=0 ; i<NSubPeaks ; i++) {
Float_t Ampli = pp[3+i*Npar+0];
Float_t Mean = pp[3+i*Npar+1];
Float_t Sigma = pp[3+i*Npar+2]*1./sqrt(8.*log(2.));
......@@ -887,8 +847,7 @@ double CXHist1DPlayer::StepedBackground(double*xx,double*pp)
f_tot += Back_const + x*Back_slope;
for(int i=0 ; i<NSubPeaks ; i++)
{
for(int i=0 ; i<NSubPeaks ; i++) {
Float_t Ampli = pp[3+i*Npar+0];
Float_t Mean = pp[3+i*Npar+1];
Float_t Sigma = pp[3+i*Npar+2]*1./sqrt(8.*log(2.));
......
......@@ -10,6 +10,7 @@ using namespace std;
class CXMainWindow;
class TGNumberEntry;
class TF1;
class TGraphErrors;
class TH1;
class TGCheckButton;
class TGListBox;
......@@ -31,6 +32,9 @@ public:
void SetList(TList *l){fList = l;}
void Remove(){if(fList){fList->Remove(this);} delete this;} // *MENU*
TGraphErrors *fEfficiencyGraph = nullptr;
TF1 *fEfficiencyFunc = nullptr;
ClassDef(CXArrow,0);
};
......
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