#include "FSMainWindow.h" #include #include /// Root includes #include "TGMenu.h" #include "TG3DLine.h" #include "TGLabel.h" #include "TGTextEntry.h" #include "TStyle.h" #include "TApplication.h" #include "TGMsgBox.h" #include "TFrame.h" #include "TGTab.h" #include "TGStatusBar.h" #include "TGFileDialog.h" #include "KeySymbols.h" #include "TH1.h" #include "TObjArray.h" #include "TROOT.h" #include "TCanvas.h" #include "TSystem.h" #include "TMath.h" #include "FSTab.h" #include "FSPad.h" #include "FSShutter.h" /// AGAPRO includes FSMainWindow::FSMainWindow(const TGWindow *p, UInt_t w, UInt_t h, TString RunInit) : TGMainFrame(p, w, h) { fLastRun = RunInit; if(fLastRun.Atoi()>0) INFO_MESS<<"Starting using run "<::iterator itr; for (itr = fListOfSpectra.begin(); itr != fListOfSpectra.end(); ++itr) { TH1D *hist = itr->second; fShutter->SetSpectrum(hist); } } FSMainWindow::~FSMainWindow() { } void FSMainWindow::InitParameters() { /// TSyle gStyle->SetPalette(1); } void FSMainWindow::LoadMainWindow() { fMainFrame = new TGHorizontalFrame(this,GetWidth(),GetHeight()); LoadMenuFile(); LoadToolBar(); LoadLeftSide(); LoadRightSide(); fVFLeft->SetWidth(GetWidth()*0.25); AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY) ); // What to clean up in destructor SetCleanup(kDeepCleanup); // Set a name to the main frame const char* FIPPSSpy_version = (char*) FIPPSSpy_VERSION; SetWindowName(Form("FIPPSSpy v%s", FIPPSSpy_version ) ); // SetIconPixmap("AgaSpy.png"); SetIconName("FIPPSSpy"); MapSubwindows(); Layout(); MapWindow(); } void FSMainWindow::LoadMenuFile() { fFSMenuBar = new FSMenuBar(this, 1, 1, kHorizontalFrame); AddFrame(fFSMenuBar, new TGLayoutHints(kLHintsExpandX)); TGHorizontal3DLine *fline = new TGHorizontal3DLine(this); AddFrame(fline,new TGLayoutHints(kLHintsExpandX)); } void FSMainWindow::LoadToolBar() { fFSToolBar = new FSToolBar(this); AddFrame(fFSToolBar, new TGLayoutHints(kLHintsExpandX)); TGHorizontal3DLine *fline = new TGHorizontal3DLine(this); AddFrame(fline,new TGLayoutHints(kLHintsExpandX)); } void FSMainWindow::LoadLeftSide() { fVFLeft = new TGVerticalFrame(fMainFrame, 10, 10, kFixedWidth); fMainFrame->AddFrame(fVFLeft, new TGLayoutHints(kLHintsLeft | kLHintsExpandY)); TGVerticalFrame *fV1 = new TGVerticalFrame(fVFLeft, 10, 50, kFixedHeight); fVFLeft->AddFrame(fV1, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY)); fMainTabL = new TGTab(fV1); fV1->AddFrame(fMainTabL, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0)); fLetfTab = fMainTabL->AddTab("Visu Tools"); fShutter = new FSShutter(fLetfTab, this); fLetfTab->AddFrame(fShutter, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0)); fLetfTab->MapSubwindows(); fLetfTab->MapWindow(); ///////////////////// ///*** SPLITER ***/// ///////////////////// fVSplitter = new TGVSplitter(fMainFrame,2,2); fVSplitter->SetFrame(fVFLeft, kTRUE); fMainFrame->AddFrame(fVSplitter, new TGLayoutHints(kLHintsLeft | kLHintsExpandY)); } void FSMainWindow::LoadRightSide() { fVFRight = new TGVerticalFrame(fMainFrame, 10, 10); fMainFrame->AddFrame(fVFRight, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); TGHorizontalFrame *fH3 = new TGHorizontalFrame(fVFRight, 10, 50, kFixedHeight); fVFRight->AddFrame(fH3, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY)); fListOfCanvases = new TList; fCanvasTab = new FSTab(fH3,this); fH3->AddFrame(fCanvasTab, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0)); fCanvasTab->Connect("CloseTab(Int_t)", "FSTab", fCanvasTab, "RemoveTab(Int_t)"); fCanvasTab->Connect("Selected(Int_t)", "FSTab", fCanvasTab, "cd()"); // status bar Int_t parts[] = {20 , 20 , 20 , 20 ,20}; fStatusBar = new TGStatusBar(fVFRight,50,10,kHorizontalFrame); fStatusBar->SetParts(parts,5); fStatusBar->Draw3DCorner(kFALSE); fVFRight->AddFrame(fStatusBar, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 0, 0, 2, 0)); // NewTab(); } void FSMainWindow::NewTab(TString name, Int_t npx, Int_t npy) { gErrorIgnoreLevel = kFatal; TString TabName = name; if(TabName == "") TabName = Form("Tab_%d",fCanvasTab->GetNumberOfTabs()); Bool_t IsInc = false; TObjArray *arr = TabName.Tokenize("_"); if(((TString)arr->Last()->GetName()).IsDec()) IsInc = true; if(IsInc==false && fCanvasTab->GetTabTab(TabName.Copy().Append("_1"))) { IsInc = true; TabName.Append("_1"); delete arr; arr = TabName.Tokenize("_"); } Int_t n; TString BaseName=""; if(IsInc) { n = ((TString)arr->Last()->GetName()).Atoi(); for(int i=0 ; iGetEntries()-1 ; i++) BaseName += Form("%s_",arr->At(i)->GetName()); } while(fCanvasTab->GetTabTab(TabName) != nullptr) { if(IsInc) { TabName = BaseName.Copy().Append(Form("%d",n++)); } else TabName.Append("_1"); } delete arr; fActiveTab = fCanvasTab->AddTab(TabName, npx, npy); fCanvasTab->GetTabTab(TabName)->ShowClose(); gErrorIgnoreLevel = kPrint; } void FSMainWindow::CloseWindow() { UnmapWindow(); DeleteWindow();// launch a delete but after a short time like a thread. cout << " Bye Bye FIPPSSpy!" <SetReturnFromRun(false); gApplication->Terminate(false); } TPad* FSMainWindow::GetSelectedPad() { //return the current seletected pad TPad *Selected_pad = (TPad *) gROOT->GetSelectedPad(); 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); } return Selected_pad; } Bool_t FSMainWindow::DoTab(TString TabName) { if(fCanvasTab->GetTabTab(TabName)) { fCanvasTab->SetTab(TabName); fCanvasTab->cd(); return true; } else return false; } void FSMainWindow::ZoomOnPad(FSPad* origin, bool same) { if(DoTab("Zoom") == false) NewTab("Zoom",1,1); FSPad *pad = dynamic_cast( GetSelectedPad() ); pad->GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "FSMainWindow", this, "HandleZoom(Int_t,Int_t,Int_t, TObject*)"); Int_t xmin = -1; Int_t xmax = -1; if(origin->GetHisto()==nullptr) return; xmin = origin->GetHisto()->GetXaxis()->GetFirst(); xmax = origin->GetHisto()->GetXaxis()->GetLast(); for(int i=0 ; iGetListOfPrimitives()->GetEntries() ; i++) { TObject *o = origin->GetListOfPrimitives()->At(i); if(same && o->InheritsFrom(TH1::Class())) o->Draw("hist same"); else if(!same) o->Draw(((TString)o->GetDrawOption()).ReplaceAll("same","")); } pad->GetHisto()->GetXaxis()->SetRange(xmin,xmax); pad->GetFrame()->SetBit(kCannotPick); } void FSMainWindow::HandleZoom(Int_t EventType, Int_t EventX, Int_t EventY, TObject *selected) { // cout<SetOwner(false); TList *listofids_out = new TList; listofids_out->SetOwner(false); FSPad *pad = static_cast(gPad); Int_t xmin = -1; Int_t xmax = -1; TH1 *hist = pad->GetHisto(); if(hist==nullptr) return; xmin = hist->GetXaxis()->GetFirst(); xmax = hist->GetXaxis()->GetLast(); Bool_t left = (EventXDraw(); hist2->GetXaxis()->SetRange(xmin,xmax); pad->Modified(); pad->Update(); pad->GetFrame()->SetBit(kCannotPick); } } fLastEventX = EventX; fLastEventY = EventY; } TH1 *FSMainWindow::GetNextHist(TH1 *hist_in, bool previous) { CanvasTypes type = kUndef; Int_t Num=-1; fShutter->GetType(hist_in,type,Num); FSGlobalCanvas *c = static_cast(fShutter->GetListOfCanvases()->FindObject(fNames[type])); if(c == nullptr) { WARN_MESS<<"Canvas "<GetListOfSpectra(); Int_t idx = list->IndexOf(hist_in); if(previous && idx>0) idx--; else if(!previous && idx<(list->GetEntries()-1)) idx++; histnext = (TH1*)list->At(idx); return histnext; } void FSMainWindow::SaveTabAs() { TCanvas *c = GetTabPage()->GetCurrentCanvas(); const char* SaveAsTypes[] = { "PDF", "*.pdf", // "PostScript", "*.ps", "Encapsulated PostScript", "*.eps", // "SVG", "*.svg", // "TeX", "*.tex", // "GIF", "*.gif", "ROOT macros", "*.C", "ROOT files", "*.root", // "XML", "*.xml", "PNG", "*.png", "XPM", "*.xpm", "JPEG", "*.jpg", // "TIFF", "*.tiff", // "XCF", "*.xcf", // "All files", "*", 0, 0 }; TString workdir = gSystem->WorkingDirectory(); static TString dir("."); static Int_t typeidx = 0; static Bool_t overwr = kFALSE; TGFileInfo fi; fi.fFileTypes = SaveAsTypes; fi.fIniDir = StrDup(dir); fi.fFileTypeIdx = typeidx; fi.fOverwrite = overwr; new TGFileDialog(gClient->GetDefaultRoot(), gClient->GetDefaultRoot(), kFDSave, &fi); gSystem->ChangeDirectory(workdir.Data()); if (!fi.fFilename) return; TString fn = fi.fFilename; dir = fi.fIniDir; typeidx = fi.fFileTypeIdx; overwr = fi.fOverwrite; if(fn.EndsWith(".root")) { cout<<"needs to be implemented"<SaveAs(fn); fSavedAs = fn; } void FSMainWindow::ReadCal() { if(getenv("FSCalFile") == nullptr) { ERR_MESS<<"Environment variable: FSCalFile needs to be define ==> ignored"< Exit"<GetEntries()-1; fCalOrder = Order; if((loa->GetEntries()-1) != Order) { WARN_MESS<<"Error in ECal.txt at line "<GetEntries()-1)<< "instead of " << Order << ") ==> skipped"<At(0)->GetName()).Atoi(); for(int i=1 ; iGetEntries() ; i++) fListOfCal[id][i-1] = ((TString)loa->At(i)->GetName()).Atof(); if(fListOfCal[id][1] == 0.) fListOfCal[id][1] = 0.00001; 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 "<GetEntries() == 2) { fListOfShiftTrack[linenb-1][0] = ((TString)loa->At(0)->GetName()).Atof(); fListOfShiftTrack[linenb-1][1] = ((TString)loa->At(1)->GetName()).Atof(); if(fListOfShiftTrack[linenb-1][1] == 0.) fListOfShiftTrack[linenb-1][1] = 0.00001; } else if(loa->GetEntries() == 3) { Int_t Id = ((TString)loa->At(0)->GetName()).Atoi(); fListOfShiftTrack[Id][0] = ((TString)loa->At(1)->GetName()).Atof(); fListOfShiftTrack[Id][1] = ((TString)loa->At(2)->GetName()).Atof(); if(fListOfShiftTrack[Id][1] == 0.) fListOfShiftTrack[Id][1] = 0.00001; } else { WARN_MESS<<"Error in "<< FileName << " at line "< file ignored"< Exit"<GetEntries() != 5) { ERR_MESS<<"Error in LUT.txt at line "<At(0)->GetName()).Atoi(); Int_t globdetid = ((TString)loa->At(1)->GetName()).Atoi(); Int_t detid = ((TString)loa->At(2)->GetName()).Atoi(); Int_t type = ((TString)loa->At(3)->GetName()).Atoi(); Int_t clover = ((TString)loa->At(4)->GetName()).Atoi(); delete loa; if(globdetid<0) continue; DetDef *det = new DetDef; fDetectors[adcval] = det; det->Type = type; det->adc = adcval; det->Id = detid; det->GlobId = globdetid; for(int i=0 ; i<10 ; i++) { if(i==1) fListOfCal[globdetid][i] = 1.; else fListOfCal[globdetid][i] = 0.; } fListOfShiftTrack[globdetid][0] = 0.; fListOfShiftTrack[globdetid][1] = 1.; } INFO_MESS<&1"); stream = popen(cmd.c_str(), "r"); if (stream) { while (!feof(stream)) if (fgets(buffer, max_buffer, stream) != NULL) data.append(buffer); pclose(stream); } TString FileName = data; FileName.ReplaceAll("\n",""); return FileName; } void FSMainWindow::ReadHistograms() { const char* FIPPSSpy_version = (char*) FIPPSSpy_VERSION; TString DataDir = getenv("FSRawDataDir"); TString FileName; TString Run; if(fLastRun.Atoi()==0){ TString Command = Form("ls -ltr %s | grep ^- | tail -1 | awk '{ print $(NF) }'",DataDir.Data()); Run = GetStdoutFromCommand(Command.Data()); Run.ReplaceAll(".lst",""); FileName = Form("%s/%s",getenv("FSRawDataDir"),Run.Data()); } else { bool ok = true; Int_t Test=fLastRun.Atoi(); while(ok){ Test++; FileName = Form("%s/%.06d",getenv("FSRawDataDir"),Test); ok = gSystem->IsFileInIncludePath(FileName); } if(getenv("FSModeLastRun")) Test=Test-2; else Test=Test-1; Run=Form("%.06d",Test); FileName = Form("%s/%s",getenv("FSRawDataDir"),Run.Data()); } ifstream file(FileName.Data()); if(!file){ ERR_MESS<::iterator itr; for (itr = fListOfSpectra.begin(); itr != fListOfSpectra.end(); ++itr) { TH1D *h = itr->second; h->Reset(); } TString Buffer; string line; TObjArray *arr; Int_t test=0; Bool_t ok=false; while(ok == false && test<200) { if(!file) file.open(FileName.Data()); Int_t NHistRead = 0; getline(file,line);getline(file,line);getline(file,line); Buffer=line; Buffer.ReplaceAll("FIPPintern ",""); while(Buffer.EndsWith(" ")) Buffer.Remove(Buffer.Length()-1); while(file) { getline(file,line);Buffer=line; while(!Buffer.BeginsWith("SSS") && file) {getline(file,line);Buffer=line;} if(!file) break; getline(file,line);Buffer=line; arr = Buffer.ReplaceAll("\t"," ").Tokenize(" "); Int_t adc = ((TString)arr->First()->GetName()).Atoi()-1; delete arr; if(fDetectors.count(adc)==0) continue; getline(file,line);getline(file,line);Buffer=line; arr = Buffer.Tokenize(" "); Int_t NBins = ((TString)arr->First()->GetName()).Atoi(); Double_t Array[NBins+2]; Double_t Val; delete arr; Array[0] = 0; Array[NBins+1]=0; for(int i=0 ; i>Val; Array[i+1] = Val; } Int_t id = fDetectors[adc]->GlobId; Int_t type=CanvasTypes::kUndef; Int_t DetNum=-1; DetDef *det = fDetectors[adc]; if(det->IsFIPPS()) { type = CanvasTypes::kFIPPS; DetNum = det->Id; } else if(det->IsIFIN()) { type = CanvasTypes::kIFIN; DetNum = det->Id; } else if(det->IsTAG()) { type = CanvasTypes::kTAG; DetNum = det->Id; } else if(det->IsAC()) { if(det->Type == 3) { type = CanvasTypes::kIFIN_AC; DetNum = det->Id; } else if(det->Type == 5) { type = CanvasTypes::kFIPPS_ACB; DetNum = det->Id/3; } else if(det->Type == 6) { type = CanvasTypes::kFIPPS_ACF; DetNum = det->Id/3; } else if(det->Type == 7) { type = CanvasTypes::kFIPPS_ACS; DetNum = det->Id/3; } } 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 ; ibinSetBinContent(ibin,Array[ibin]); } else memcpy(((TH1D*)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: read "< Done" << ENDL; fLastRun = Run; SetWindowName(Form("FIPPSSpy v%s: Run %s - %s", FIPPSSpy_version,fLastRun.Data(),fCurrentDate.Data())); } void FSMainWindow::DoCalMode(Bool_t on) { map::iterator itr; for (itr = fListOfSpectra.begin(); itr != fListOfSpectra.end(); ++itr) { TH1D *h = itr->second; if(on) { h->GetXaxis()->SetTitle("Energy (keV)"); h->GetYaxis()->SetTitle(Form("Counts (1 Chanel/bin)")); } else { h->GetXaxis()->SetTitle("Ampliture (Chanel)"); h->GetYaxis()->SetTitle(Form("Counts (1 Chanel/bin)")); } Double_t Bins[h->GetNbinsX()+1]; for(int i=0 ;i<=h->GetNbinsX() ; i++) { if(on == false) Bins[i] = i*h->GetBinWidth(1); else { 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 ; jfirst][j]*TMath::Power(ERaw,j); Bins[i] = ECal; } } h->GetXaxis()->Set(h->GetNbinsX(),Bins); } fCanvasTab->RefreshTab(); } void FSMainWindow::PrintShiftTrack() { if(fFSToolBar->IsFullMode()) { INFO_MESS << "Shift track values of run: " << fLastShiftTrackRun << endl; cout<<"File: "<::iterator itr; for (itr = fListOfShiftTrack.begin(); itr != fListOfShiftTrack.end(); ++itr) { cout<first<second[0]<second[1]<( 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: "<IsFullMode()) { INFO_MESS << "Calibration values:"<< endl; cout<<"File: "<::iterator itr; for (itr = fListOfCal.begin(); itr != fListOfCal.end(); ++itr) { cout<first; for(int i=0 ; ifirst][i]; cout<( 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: "<