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

Correct colors

Print calibs
Corr gain of TAG
parent 0007b1d4
Pipeline #36415 passed with stage
in 6 minutes and 39 seconds
......@@ -13,12 +13,9 @@ class TInterruptHandler : public TSignalHandler {
public:
TInterruptHandler() : TSignalHandler(kSigInterrupt, kFALSE) { }
virtual Bool_t Notify()
{
virtual Bool_t Notify() {
// do anything
fFSMainWindow->CloseWindow();
return kTRUE;
}
};
......@@ -37,6 +34,10 @@ int main(int argc, char **argv)
ERR_MESS<<"Environment variable: FSLUTFile needs to be define ==> EXIT"<<ENDL;
return 1;
}
if(getenv("FSShiftTrackDir") == nullptr) {
WARN_MESS<<"Environment variable FSShiftTrackDir not defined ==> not used"<<ENDL;
}
gEnv->SetValue("Gui.IconPath",Form("%s/icons:%s/icons",getenv("ROOTSYS"),getenv("gammaSoftware_DIR")));
TString RunInit="";
......
......@@ -8,6 +8,7 @@
#include "TGIcon.h"
#include "TH1.h"
#include "TROOT.h"
#include "TError.h"
#include "FSMainWindow.h"
#include "FSPad.h"
......@@ -58,7 +59,6 @@ void FSGlobalCanvas::PlotCanvas()
fMain->GetTabPage()->ComputePadXY(NDets,&fNPadsx,&fNPadsy);
fNPads = fNPadsx*fNPadsy;
fMain->NewTab(GetName(),fNPadsx,fNPadsy);
}
TCanvas *c = fMain->GetTabPage()->GetCanvasAt(fMain->GetTabPage()->GetCurrent());
......@@ -70,17 +70,9 @@ void FSGlobalCanvas::PlotCanvas()
pad->cd();
fListOfHists->At(i)->Draw("hist");
pad->GetListOfPrimitives()->Remove(pad->GetListOfPrimitives()->FindObject("title"));
pad->Update();
pad->GetListOfPrimitives()->Remove(pad->GetListOfPrimitives()->FindObject("title"));
pad->Update();
pad->GetFrame()->SetBit(kCannotPick);
}
gROOT->SetSelectedPad(c->cd(1));
c->Update();
fMain->GetTabPage()->RefreshTab();
gErrorIgnoreLevel = kPrint;
}
......@@ -34,7 +34,7 @@ static Pixel_t FS_Wheat = 0xF5DEB3;
#define ERR_MESS std::cout<<"\e[0;3;31m -- ERROR : "
#define WARN_MESS std::cout<<"\e[0;3;33m -- WARNNING: "
#define INFO_MESS std::cout<<"\e[0;3;32m -- INFO : "
#define END_MESS "\e[0;3m"
#define END_MESS "\e[0;m"
#define ENDL END_MESS<<std::endl
#endif // FSGLOBALS_H
......@@ -35,7 +35,9 @@ FSMainWindow::FSMainWindow(const TGWindow *p, UInt_t w, UInt_t h, TString RunIni
{
fLastRun = RunInit;
if(fLastRun.Atoi()>0) INFO_MESS<<"Starting using run "<<fLastRun<<" as initializer"<<ENDL;
INFO_MESS<<"Reading data from: "<<getenv("FSRawDataDir")<<ENDL;
if(getenv("FSShiftTrackDir")) INFO_MESS<<"Shift track folder: "<<getenv("FSShiftTrackDir")<<ENDL;
ReadLUT();
ReadCal();
InitParameters();
......@@ -43,14 +45,11 @@ FSMainWindow::FSMainWindow(const TGWindow *p, UInt_t w, UInt_t h, TString RunIni
ReadHistograms();
DoCalMode(0);
map<Int_t, TH1I*>::iterator itr;
map<Int_t, TH1D*>::iterator itr;
for (itr = fListOfSpectra.begin(); itr != fListOfSpectra.end(); ++itr) {
TH1I *hist = itr->second;
TH1D *hist = itr->second;
fShutter->SetSpectrum(hist);
}
Color_t c[12] = {kBlue-6, kCyan-6, kGreen-6, kYellow-6 , kRed-6, kMagenta-6, kAzure, kTeal, kSpring, kOrange, kPink, kViolet};
for(int i=0 ; i<48 ; i++) fColor[i] = c[i%12] - (int)i/12;
}
FSMainWindow::~FSMainWindow()
......@@ -206,26 +205,30 @@ void FSMainWindow::NewTab(TString name, Int_t npx, Int_t npy)
fActiveTab = fCanvasTab->AddTab(TabName, npx, npy);
fCanvasTab->GetTabTab(TabName)->ShowClose();
gErrorIgnoreLevel = kPrint;
}
void FSMainWindow::CloseWindow() {
void FSMainWindow::CloseWindow()
{
while(true){
if(oktoclose == false) continue;
UnmapWindow();
DeleteWindow();// launch a delete but after a short time like a thread.
UnmapWindow();
DeleteWindow();// launch a delete but after a short time like a thread.
cout << " Bye Bye FIPPSSpy!" <<endl;
cout << " Bye Bye FIPPSSpy!" <<endl;
gApplication->SetReturnFromRun(false);
gApplication->Terminate(false);
gApplication->SetReturnFromRun(false);
gApplication->Terminate(false);
}
}
TPad* FSMainWindow::GetSelectedPad()
{
//return the current seletected pad
TPad *Selected_pad = (TPad *) gROOT->GetSelectedPad();
if (!(Selected_pad->InheritsFrom("TPad"))) {
if (Selected_pad && !(Selected_pad->InheritsFrom("TPad"))) {
int retval = 0;
EMsgBoxIcon icontype = kMBIconStop;
new TGMsgBox(gClient->GetRoot(), this, "Warning", "No seleted Pad", icontype, 1, &retval);
......@@ -260,27 +263,15 @@ void FSMainWindow::ZoomOnPad(FSPad* origin, bool same)
xmin = origin->GetHisto()->GetXaxis()->GetFirst();
xmax = origin->GetHisto()->GetXaxis()->GetLast();
for(int i=0 ; i<origin->GetListOfPrimitives()->GetEntries() ; i++) {
TObject *o = origin->GetListOfPrimitives()->At(i);
if(same && o->InheritsFrom(TH1::Class()))
o->Draw("hist same");
else if(!same)
o->Draw(o->GetDrawOption());
}
Int_t nHist = 0;
for(int i=0 ; i<pad->GetListOfPrimitives()->GetEntries() ; i++) {
TObject *o = pad->GetListOfPrimitives()->At(i);
if(o->InheritsFrom(TH1::Class())) {
((TH1*)o)->SetLineColor(fColor[nHist]);
nHist++;
}
o->Draw(((TString)o->GetDrawOption()).ReplaceAll("same",""));
}
pad->GetHisto()->GetXaxis()->SetRange(xmin,xmax);
pad->Modified();
pad->Update();
pad->GetFrame()->SetBit(kCannotPick);
}
......@@ -454,6 +445,83 @@ void FSMainWindow::ReadCal()
delete loa;
}
fCurrentCalFile = getenv("FSCalFile");
}
void FSMainWindow::GetLastShiftTrack()
{
if(getenv("FSShiftTrackDir") == nullptr) return;
TString FSShiftTrackDir = getenv("FSShiftTrackDir");
Int_t Run=0;
TString File="";
TString FileName="";
if(fLastShiftTrackRun==0) {
TString Command = Form("ls -ltr %s/r_*.txt | grep ^- | tail -1 | awk '{ print $(NF) }'",FSShiftTrackDir.Data());
File = GetStdoutFromCommand(Command.Data());
TObjArray *arr = File.Tokenize("/");
File = arr->Last()->GetName();
delete arr;
Run = File.Copy().ReplaceAll("r_","").ReplaceAll(".txt","").Atoi();
FileName = Form("%s/%s",FSShiftTrackDir.Data(),File.Data());
fLastShiftTrackRun = Run;
}
else {
bool ok = true;
Int_t Test=fLastShiftTrackRun;
while(ok){
Test++;
FileName = Form("%s/r_%.06d.txt",FSShiftTrackDir.Data(),Test);
ok = gSystem->IsFileInIncludePath(FileName);
}
Test=Test-1;
fLastShiftTrackRun = Test;
FileName = Form("%s/r_%.06d.txt",FSShiftTrackDir.Data(),fLastShiftTrackRun);
}
if(!gSystem->IsFileInIncludePath(FileName)) {
WARN_MESS<<"Shift track file "<<FileName<<" not found"<<ENDL;
return;
}
INFO_MESS << "Shift track of run "<< fLastShiftTrackRun <<" used " << ENDL;
TString Buffer;
string line;
std::ifstream FileConf;
FileConf.open(FileName, std::ifstream::in);
Int_t linenb=0;
while(FileConf){
getline(FileConf,line);
linenb++;
Buffer = line;
if(Buffer.BeginsWith("#") || Buffer.Length()==0 ) continue;
TObjArray *loa=Buffer.ReplaceAll("\t"," ").Tokenize(" ");
if(loa->GetEntries() != 2) {
WARN_MESS<<"Error in "<< FileName << " at line "<<linenb<<" ; bad number of parameters ==> file ignored"<<ENDL;
FileConf.close();
return;
}
fListOfShiftTrack[linenb-1][0] = ((TString)loa->At(0)->GetName()).Atof();
fListOfShiftTrack[linenb-1][1] = ((TString)loa->At(1)->GetName()).Atof();
// cout<<linenb-1<<" "<<fListOfShiftTrack[linenb-1][0]<<" "<<fListOfShiftTrack[linenb-1][1]<<endl;
delete loa;
}
FileConf.close();
fCurrentShiftTrackFile = FileName;
}
void FSMainWindow::ReadLUT()
......@@ -511,6 +579,8 @@ void FSMainWindow::ReadLUT()
if(i==1) fListOfCal[globdetid][i] = 1.;
else fListOfCal[globdetid][i] = 0.;
}
fListOfShiftTrack[globdetid][0] = 0.;
fListOfShiftTrack[globdetid][1] = 1.;
}
INFO_MESS<<fDetectors.size()<<" entries Read in the LUT"<<ENDL;
......@@ -562,7 +632,7 @@ void FSMainWindow::ReadHistograms()
FileName = Form("%s/%.06d",getenv("FSRawDataDir"),Test);
ok = gSystem->IsFileInIncludePath(FileName);
}
Test=Test-1;
Test=Test-2;
Run=Form("%.06d",Test);
FileName = Form("%s/%s",getenv("FSRawDataDir"),Run.Data());
}
......@@ -572,7 +642,10 @@ void FSMainWindow::ReadHistograms()
ERR_MESS<<FileName<<" not found"<<ENDL;
return;
}
else INFO_MESS<<"Reading run: "<<Run<<ENDL;
else {
INFO_MESS<<"Reading run: "<<Run<<ENDL;
INFO_MESS<<"File: "<<FileName<<ENDL;
}
struct stat result;
if(stat(FileName.Data(), &result)==0) {
......@@ -588,9 +661,15 @@ void FSMainWindow::ReadHistograms()
return;
}
map<Int_t, TH1I*>::iterator itr;
// Check Last ShiftTrackFile
GetLastShiftTrack();
// Reset spectra
map<Int_t, TH1D*>::iterator itr;
for (itr = fListOfSpectra.begin(); itr != fListOfSpectra.end(); ++itr) {
TH1I *h = itr->second;
TH1D *h = itr->second;
h->Reset();
}
......@@ -600,7 +679,7 @@ void FSMainWindow::ReadHistograms()
Int_t test=0;
Bool_t ok=false;
while(ok == false && test<10) {
while(ok == false && test<200) {
if(!file) file.open(FileName.Data());
Int_t NHistRead = 0;
......@@ -623,8 +702,8 @@ void FSMainWindow::ReadHistograms()
getline(file,line);getline(file,line);Buffer=line;
arr = Buffer.Tokenize(" ");
Int_t NBins = ((TString)arr->First()->GetName()).Atoi();
Int_t Array[NBins+2];
Int_t Val;
Double_t Array[NBins+2];
Double_t Val;
delete arr;
Array[0] = 0;
Array[NBins+1]=0;
......@@ -665,17 +744,33 @@ void FSMainWindow::ReadHistograms()
DetNum = det->Id/3;
}
}
TString HistName = Form("Hist_%s_%d",fNames[type].Data(),DetNum);
if(fListOfSpectra.count(id)==0) fListOfSpectra[id] = new TH1I(HistName,HistName,NBins,0,NBins);
TString HistName = Form("ADC%d_%s_%d",adc,fNames[type].Data(),DetNum);
if(fListOfSpectra.count(id)==0) {
if(type == CanvasTypes::kTAG) {
fListOfSpectra[id] = new TH1D(HistName,HistName,NBins/2,0,NBins);
}
else
fListOfSpectra[id] = new TH1D(HistName,HistName,NBins,0,NBins);
}
if(type == CanvasTypes::kTAG)
for(int ibin=1 ; ibin<NBins/2 ; ibin++) {
fListOfSpectra[id]->SetBinContent(ibin,Array[ibin]);
}
else
memcpy(((TH1D*)fListOfSpectra[id])->fArray,Array,sizeof(Array));
memcpy(((TH1I*)fListOfSpectra[id])->fArray,Array,sizeof(Array));
fListOfSpectra[id]->SetEntries(fListOfSpectra[id]->Integral());
NHistRead++;
}
if(NHistRead == fDetectors.size()) ok = true;
else {
test++;
WARN_MESS<<"Unable to read the full file, retry "<<test<<endl;
WARN_MESS<<"Unable to read the full file: read "<<NHistRead<<" histograms, wainting:"<<fDetectors.size()<<", retry num"<<test<<ENDL;
oktoclose = false;
sleep(3);
oktoclose = true;
}
file.close();
}
......@@ -687,9 +782,9 @@ void FSMainWindow::ReadHistograms()
void FSMainWindow::DoCalMode(Bool_t on)
{
map<Int_t, TH1I*>::iterator itr;
map<Int_t, TH1D*>::iterator itr;
for (itr = fListOfSpectra.begin(); itr != fListOfSpectra.end(); ++itr) {
TH1I *h = itr->second;
TH1D *h = itr->second;
if(on) {
h->GetXaxis()->SetTitle("Energy (keV)");
......@@ -702,12 +797,13 @@ void FSMainWindow::DoCalMode(Bool_t on)
Double_t Bins[h->GetNbinsX()+1];
for(int i=0 ;i<=h->GetNbinsX() ; i++) {
if(on == false) Bins[i] = i;
if(on == false) Bins[i] = i*h->GetBinWidth(1);
else {
Double_t E=0;
Double_t ERaw = fListOfShiftTrack[itr->first][0] + fListOfShiftTrack[itr->first][1]*((Double_t)i*h->GetBinWidth(1));
Double_t ECal = 0;
for(int j=0 ; j<fCalOrder ; j++)
E += fListOfCal[itr->first][j]*TMath::Power(((Double_t)i),j);
Bins[i] = E;
ECal += fListOfCal[itr->first][j]*TMath::Power(ERaw,j);
Bins[i] = ECal;
}
}
......@@ -717,4 +813,79 @@ void FSMainWindow::DoCalMode(Bool_t on)
fCanvasTab->RefreshTab();
}
void FSMainWindow::PrintShiftTrack()
{
if(fFSToolBar->IsFullMode()) {
INFO_MESS << "Shift track values of run: " << fLastShiftTrackRun << endl;
cout<<"File: "<<fCurrentShiftTrackFile<<endl;
cout<<left<<setw(10)<<"Det id"<<setw(15)<<"Offset"<<setw(15)<<"Gain"<<endl;
map<Int_t, Double_t[2]>::iterator itr;
for (itr = fListOfShiftTrack.begin(); itr != fListOfShiftTrack.end(); ++itr) {
cout<<left<<setw(10)<<itr->first<<setw(15)<<itr->second[0]<<setw(15)<<itr->second[1]<<endl;
}
cout<<ENDL;
}
else {
FSPad *pad = dynamic_cast<FSPad*>( GetSelectedPad() );
if(pad == nullptr) return;
TH1 *h = pad->GetHisto();
if(h==nullptr) return;
TString Name = h->GetName();
TObjArray *arr = Name.Tokenize("_");
Name=arr->First()->GetName();
delete arr;
Name.ReplaceAll("ADC","");
Int_t adc = Name.Atoi();
DetDef *det = fDetectors[adc];
Int_t Id = det->GlobId;
INFO_MESS << "Shift track values for Det: "<<Id<<" of run: " << fLastShiftTrackRun << endl;
cout<<"File: "<<fCurrentShiftTrackFile<<endl;
cout<<left<<setw(10)<<"Det id"<<setw(15)<<"Offset"<<setw(15)<<"Gain"<<endl;
cout<<left<<setw(10)<<Id<<setw(15)<<fListOfShiftTrack[Id][0]<<setw(15)<<fListOfShiftTrack[Id][1]<<endl;
cout<<ENDL;
}
}
void FSMainWindow::PrintCal()
{
if(fFSToolBar->IsFullMode()) {
INFO_MESS << "Calibration values:"<< endl;
cout<<"File: "<<fCurrentCalFile<<endl;
cout<<left<<setw(10)<<"Det id";
for(int i=0 ; i<fCalOrder ; i++) cout<<setw(15)<<Form("a%d",i);
cout<<endl;
map<Int_t, Double_t[10]>::iterator itr;
for (itr = fListOfCal.begin(); itr != fListOfCal.end(); ++itr) {
cout<<left<<setw(10)<<itr->first;
for(int i=0 ; i<fCalOrder ; i++) cout<<setw(15)<<fListOfCal[itr->first][i];
cout<<endl;
}
cout<<ENDL;
}
else {
FSPad *pad = dynamic_cast<FSPad*>( GetSelectedPad() );
if(pad == nullptr) return;
TH1 *h = pad->GetHisto();
if(h==nullptr) return;
TString Name = h->GetName();
TObjArray *arr = Name.Tokenize("_");
Name=arr->First()->GetName();
delete arr;
Name.ReplaceAll("ADC","");
Int_t adc = Name.Atoi();
DetDef *det = fDetectors[adc];
Int_t Id = det->GlobId;
INFO_MESS << "Calibration values:"<< endl;
cout<<"File: "<<fCurrentCalFile<<endl;
cout<<left<<setw(10)<<"Det id";
for(int i=0 ; i<fCalOrder ; i++) cout<<setw(15)<<Form("a%d",i);
cout<<endl;
cout<<left<<setw(10)<<Id;
for(int i=0 ; i<fCalOrder ; i++) cout<<setw(15)<<fListOfCal[Id][i];
cout<<endl;
cout<<ENDL;
}
}
ClassImp( FSMainWindow)
......@@ -6,7 +6,7 @@
#include "GuiTypes.h"
#include "TGSplitter.h"
#include "TGTab.h"
#include "TH1I.h"
#include "TH1D.h"
/// FS includes
#include "FSGlobals.h"
......@@ -61,8 +61,11 @@ private:
TGStatusBar *fStatusBar = nullptr;
map <Int_t, TH1I*> fListOfSpectra;
map <Int_t, TH1D*> fListOfSpectra;
map <Int_t, Double_t[10]> fListOfCal;
map <Int_t, Double_t[2]> fListOfShiftTrack;
bool oktoclose = true;
/// FIPPSSpy objects
......@@ -87,9 +90,10 @@ private:
Int_t fCalOrder = 0;
Color_t fColor[48];
TString fLastRun="";
Int_t fLastShiftTrackRun = 0;
TString fCurrentCalFile = "";
TString fCurrentShiftTrackFile = "";
public:
FSMainWindow(const TGWindow *p, UInt_t w, UInt_t h, TString RunInit="");
......@@ -97,7 +101,7 @@ public:
void CloseWindow();
void ReadHistograms();
map <Int_t, TH1I*> GetListOfSpectra(){return fListOfSpectra;}
map <Int_t, TH1D*> GetListOfSpectra(){return fListOfSpectra;}
TH1 *GetNextHist(TH1 *hist_in, bool previous);
FSTab *GetTabPage(){return fCanvasTab;}
......@@ -126,12 +130,16 @@ public:
void DoCalMode(Bool_t on);
void PrintShiftTrack();
void PrintCal();
protected:
private:
void InitParameters();
void ReadLUT();
void GetLastShiftTrack();
void ReadCal();
void LoadMainWindow();
void LoadMenuFile();
......
......@@ -5,7 +5,9 @@
enum ETestCommandIdentifiers {
M_FILE_EXIT,
M_FILE_SAVE,
M_CALIB
M_CALIB,
M_PRINTSHIFTTRACK,
M_PRINTCAL,
};
/*------------------------------------------------------*/
......@@ -31,11 +33,16 @@ FSMenuBar::FSMenuBar(const TGWindow *p, UInt_t w, UInt_t h, UInt_t option) :
AddPopup("&File", fMenuFile, fFSMenuBarItemLayout);
fMenuMode = new TGPopupMenu(gClient->GetRoot());
fMenuMode->Connect("Activated(Int_t)", "FSMenuBar", this, "HandleMenu(Int_t)");
fMenuMode->AddEntry("&Calibrated", M_CALIB);
AddPopup("&Mode", fMenuMode, fFSMenuBarItemLayout);
fToolsMode = new TGPopupMenu(gClient->GetRoot());
fToolsMode->Connect("Activated(Int_t)", "FSMenuBar", this, "HandleMenu(Int_t)");
fToolsMode->AddEntry("&Print shift track", M_PRINTSHIFTTRACK);
fToolsMode->AddEntry("&Print calibrations", M_PRINTCAL);
AddPopup("&Tools", fToolsMode, fFSMenuBarItemLayout);
}
FSMenuBar::~FSMenuBar() {
......@@ -55,6 +62,12 @@ void FSMenuBar::HandleMenu(Int_t id) {
else fMenuMode->CheckEntry(M_CALIB);
fMain->DoCalMode(IsCalMode());
break;
case M_PRINTSHIFTTRACK:
fMain->PrintShiftTrack();
break;
case M_PRINTCAL:
fMain->PrintCal();
break;
}
}
......
......@@ -12,7 +12,7 @@ private:
TGPopupMenu *fMenuFile = nullptr;
TGPopupMenu *fMenuMode = nullptr;
TGPopupMenu *fCalMode = nullptr;
TGPopupMenu *fToolsMode = nullptr;
public:
......
......@@ -24,6 +24,9 @@ FSTab::FSTab(const TGWindow *p, TGMainFrame *f) :
TGTab(p) {
fMain = (FSMainWindow*)f;
Connect("Selected(Int_t)", "FSTab", this, "SetPageAction(Int_t)");
Color_t c[12] = {kBlue-6, kCyan-6, kGreen-6, kYellow-6 , kRed-6, kMagenta-6, kAzure, kTeal, kSpring, kOrange, kPink, kViolet};
for(int i=0 ; i<72 ; i++) fColor[i] = c[i%12] + (int)i/12;
}
FSTab::~FSTab()
......@@ -277,11 +280,7 @@ void FSTab::RemoveTab(Int_t tabIndex)
void FSTab::cd()
{
TCanvas *canvas = GetCurrentCanvas();
if(canvas == nullptr)
return;
canvas->Update();
gROOT->SetSelectedPad(canvas->cd(1));
RefreshTab();
}
void FSTab::SetPageAction(Int_t id)
......@@ -309,13 +308,9 @@ void FSTab::CdFirstOrLastPad()
void FSTab::RefreshTab()
{