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

Add a DrawOption TextEntry, allowing do do standard plots options but also...

Add a DrawOption TextEntry, allowing do do standard plots options but also normalize and adding histo
parent 47cc72fa
......@@ -6,12 +6,14 @@
#include <sstream>
#include "TGButton.h"
#include "TGTextEntry.h"
#include "TFile.h"
#include "TGLabel.h"
#include "TROOT.h"
#include "TFrame.h"
#include "TGListBox.h"
#include "TError.h"
#include "TObjArray.h"
#include "CXMainWindow.h"
#include "CXTH1Proj.h"
......@@ -82,10 +84,11 @@ CXHist2DPlayer::CXHist2DPlayer(const TGCompositeFrame *MotherFrame, UInt_t w, UI
AddFrame(fSubGroupFrame, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandY | kLHintsExpandX, 3, 3, 0, 0));
fHorizontalFrame = new TGCompositeFrame(fSubGroupFrame, 60, 20, kHorizontalFrame);
fDrawSame = new TGCheckButton(fHorizontalFrame, "Draw same", 0);
fDrawSame->SetState(kButtonUp);
fHorizontalFrame->AddFrame(fDrawSame,new TGLayoutHints(kLHintsLeft | kLHintsCenterY ,5,10,0,0));
fSubGroupFrame->AddFrame(fHorizontalFrame,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,-10,-10,5,0));
fHorizontalFrame->AddFrame(new TGLabel(fHorizontalFrame, "Draw Options:"),new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 0, 5, 0, 0));
fDrawOpt = new TGTextEntry(fHorizontalFrame, "hist ");
fDrawOpt->SetToolTipText("hist, same, norm, add, add(fact)");
fHorizontalFrame->AddFrame(fDrawOpt,new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsCenterY ,0,0,0,0));
fSubGroupFrame->AddFrame(fHorizontalFrame,new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,-10,-10,5,5));
fStoredSpectraBox = new TGListBox(fSubGroupFrame);
fSubGroupFrame->AddFrame(fStoredSpectraBox, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,-10,-10,0,0));
......@@ -309,55 +312,90 @@ void CXHist2DPlayer::ClearStoredList(){
void CXHist2DPlayer::ProcessedButtonEvent(Event_t *event)
{
// char input[10];
// UInt_t keysym;
// char input[10];
// UInt_t keysym;
// gVirtualX->LookupString(event, input, sizeof(input), keysym);
// gVirtualX->LookupString(event, input, sizeof(input), keysym);
// // std::cout << "event : " << event->fCode << " " << event->fState <<" ; "<< event->fType << "; " << keysym << std::endl;
// // std::cout << "event : " << event->fCode << " " << event->fState <<" ; "<< event->fType << "; " << keysym << std::endl;
// // if(event->fType == kGKeyPress && keysym == kKey_Control)
// // fCtrl_On = true;
// // if(event->fType == kGKeyPress && keysym == kKey_Control)
// // fCtrl_On = true;
// if(event->fType == kButtonPress){
// if(event->fType == kButtonPress){
// if(fLastSelected){
// fLastSelected->SetBackgroundColor((Pixel_t)0x90f269);
// fLastSelected = nullptr;
// fStoredSpectraBox->Layout();
// }
// if(fLastSelected){
// fLastSelected->SetBackgroundColor((Pixel_t)0x90f269);
// fLastSelected = nullptr;
// fStoredSpectraBox->Layout();
// }
// if(fStoredSpectraBox->GetSelectedEntry()){
// fStoredSpectraBox->GetSelectedEntry()->SetBackgroundColor((Pixel_t) 0x87a7d2);
// fLastSelected = fStoredSpectraBox->GetSelectedEntry();
// fStoredSpectraBox->Select(fStoredSpectraBox->GetSelected(),false);
// fStoredSpectraBox->Layout();
// }
// }
// if(fStoredSpectraBox->GetSelectedEntry()){
// fStoredSpectraBox->GetSelectedEntry()->SetBackgroundColor((Pixel_t) 0x87a7d2);
// fLastSelected = fStoredSpectraBox->GetSelectedEntry();
// fStoredSpectraBox->Select(fStoredSpectraBox->GetSelected(),false);
// fStoredSpectraBox->Layout();
// }
// }
}
void CXHist2DPlayer::DoubleClicked(Int_t id){
TObject *o = fListOfStoredSpectra->FindObject(fStoredSpectraBox->GetSelectedEntry()->GetTitle());
if(fMainWindow->GetCanvas()->GetUniqueID() == 666)
{
if(fMainWindow->GetCanvas()->GetUniqueID() == 666){
cout<<"Cannot draw on this Canvas"<<endl;
return;
}
TString Options = "";
if(o->InheritsFrom("TH2"))
Options += "col";
else if(o->InheritsFrom("TH1"))
Options += "hist";
if(fDrawSame->GetState() == kButtonDown)
Options += " same";
gErrorIgnoreLevel = kError;
TObject *clone = o->Clone();
TString Options = fDrawOpt->GetText();
Options.ReplaceAll(" ","");
if(Options.Contains("norm") && clone->InheritsFrom("TH1")){
TH1 *hist = (TH1*)clone;
hist->Scale(1./((Float_t)hist->GetEntries()));
Options.ReplaceAll("norm","");
}
if(Options.Contains("add") && clone->InheritsFrom("TH1")){
TH1 * HistToadd = nullptr;
for(uint i=0 ; i<gPad->GetListOfPrimitives()->GetEntries() ; i++) {
TObject *obj = gPad->GetListOfPrimitives()->At(i);
if(obj->InheritsFrom(TH1::Class_Name())) {
HistToadd = (TH1*)obj;
break;
}
}
if(HistToadd == nullptr){
cout<<"No histogram to be added found in the current pad, ignored"<<endl;
}
else {
Float_t Fact=1;
if(Options.Contains("(") && Options.Contains(")")){
TObjArray *arr = Options.Copy().Tokenize("(");
TString opt = arr->At(1)->GetName();
delete arr;
arr = opt.Tokenize(")");
opt = arr->First()->GetName();
delete arr;
if(opt.IsFloat())
Fact = opt.Atof();
else
cout<<"could not decrypt the addition factor, 1 is used"<<endl;
}
HistToadd->Add(((TH1*)clone),Fact);
gPad->Update();
gPad->Modified();
return;
}
}
clone->Draw(Options);
gErrorIgnoreLevel = kPrint;
gPad->Update();
......
......@@ -12,6 +12,7 @@ class CXTH1Proj;
class TGListBox;
class TGLBEntry;
class TGCheckButton;
class TGTextEntry;
class CXHist2DPlayer : public TGVerticalFrame
{
......@@ -27,7 +28,7 @@ private:
TGListBox *fStoredSpectraBox = nullptr;
TList *fListOfStoredSpectra = nullptr;
TGCheckButton *fDrawSame = nullptr;
TGTextEntry *fDrawOpt = nullptr;
TGCheckButton *fFixRange = nullptr;
TList *fListOfSavedGates = nullptr;
......
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