// Mainframe macro generated from application: /home/dkramer/root/bin/root.exe // By ROOT version 5.17/06 on 2007-12-23 20:12:34 #include #include #include #ifndef ROOT_TGFileDialog #include "TGFileDialog.h" #endif #ifndef ROOT_TGNumberEntry #include "TGNumberEntry.h" #endif #ifndef ROOT_TGCanvas #include "TGCanvas.h" #endif #include "TGLabel.h" #include "Riostream.h" class MyMainFrame : public TGMainFrame { private: //TGCompositeFrame *fCframe; //TGMainFrame *fMyMainFrame; TGTextButton *fTextButtonRUN, *fPause, *fExit; TGTextButton *fGetFile, *fMakeRoot; TGNumberEntry *fNumEntryRSum, *fNumEntryCard, *fNumEntryChannel; TGCheckButton *fTextButtonGaps,*fCheckCounts,*fCheckSEM; TGGroupFrame *fGframe; TGGroupFrame *pupu; TGLabel *fLabel; Bool_t start, pause; TString rootFile2o,rootFile2s; TFile *f; TTree *t2; TTree *tTitle; ifstream in; //istringstream tmpSTR; Double_t DoseConv; Double_t BLMI_SemFactor; Int_t vars; // TString *fieldName; public: MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h); virtual ~MyMainFrame(); // slots void PrintMe(); void OpenFile(); void plotRunningSum(); TString OpenFileDialog(Int_t typeID=0); TString SaveFileDialog(); void ReadRSLogFile_andSaveRoot(); void Set2ndVariable(); ClassDef(MyMainFrame, 0) }; MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h),BLMI_SemFactor(74855) { this->SetLayoutBroken(kTRUE); fTextButtonRUN = new TGTextButton(this,"&Plot "); fTextButtonRUN->Connect("Clicked()", "MyMainFrame", this, "plotRunningSum()"); fTextButtonRUN->SetToolTipText("Plot the chosen RS from the opened .ROOT file"); fTextButtonRUN->SetTextJustify(36); fTextButtonRUN->Resize(112,48); this->AddFrame(fTextButtonRUN, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2)); fTextButtonRUN->MoveResize(288,304,112,48); fMakeRoot = new TGTextButton(this,"&Convert \nTimber File"); fMakeRoot->Connect("Clicked()", "MyMainFrame", this, "ReadRSLogFile_andSaveRoot()"); fMakeRoot->MoveResize(16,204,112,48); fMakeRoot->SetToolTipText("Dialog to open .csv timber file\nconverts data to ROOT file"); fExit = new TGTextButton(this,"&Exit", "gApplication->Terminate(0)"); fExit->MoveResize(16,304,112,48); fExit->SetToolTipText("Close all the windows and exit"); pupu = new TGGroupFrame(this,"Acquisitions in TTree"); pupu->SetLayoutBroken(kTRUE); fLabel = new TGLabel(pupu,"No Input"); fLabel->SetTextJustify(36); pupu->AddFrame(fLabel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2)); fLabel->MoveResize(32,32,112,30); pupu->SetLayoutManager(new TGVerticalLayout(pupu)); pupu->Resize(192,88); this->AddFrame(pupu, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2)); pupu->MoveResize(16,16,192,88); fGetFile = new TGTextButton(this,"&OpenFile"); fGetFile->MoveResize(152,304,112,48); fGetFile->Connect("Clicked()", "MyMainFrame", this, "OpenFile()"); fGetFile->SetToolTipText("Dialog to open .ROOT file with Expert logging data"); fTextButtonGaps = new TGCheckButton(this,"Plot another variable?"); fTextButtonGaps->MoveResize(16,120,112,40); fTextButtonGaps->SetToolTipText("Add second window to the plot\nGap between consecutive TimeStamps is plotted\nCorrect operation means 1second"); fTextButtonGaps->SetEnabled(true); fTextButtonGaps->Connect("Clicked()", "MyMainFrame", this, "Set2ndVariable()"); fCheckCounts = new TGCheckButton(this,"Output in Counts/s?"); fCheckCounts->MoveResize(16,154,140,40); fCheckCounts->SetToolTipText("Grays are converted to counts \nUnchecked means Grays/s"); fCheckSEM = new TGCheckButton(this,"SEM?"); fCheckSEM->MoveResize(170,154,100,40); fCheckSEM->SetToolTipText("Is this a SEM detector?\nDifferent dose to count calibration"); //fExit->Connect("Clicked()", "MyMainFrame", this, "gApplication->Terminate(0)"); // fTextButtonRUN->Connect("Clicked()", "fMyMainFrame", this, "PrintMe()"); // // fExit = new TGTextButton(fHor1, "&Exit", "gApplication->Terminate(0)"); // TGFont *ufont; // will reflect user font changes ufont = gClient->GetFont("-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1"); TGGC *uGC; // will reflect user GC changes // graphics context changes GCValues_t valEntry576; valEntry576.fMask = kGCForeground | kGCBackground | kGCFillStyle | kGCFont | kGCGraphicsExposures; gClient->GetColorByName("#000000",valEntry576.fForeground); gClient->GetColorByName("#c0c0c0",valEntry576.fBackground); valEntry576.fFillStyle = kFillSolid; valEntry576.fFont = ufont->GetFontHandle(); valEntry576.fGraphicsExposures = kFALSE; uGC = gClient->GetGC(&valEntry576, kTRUE); // TGTextEntry *fTextEntry576 = new TGTextEntry(this, new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBord // er | kOwnBackground); // fTextEntry576->SetMaxLength(255); // fTextEntry576->SetAlignment(kTextLeft); // fTextEntry576->SetText("file name"); // fTextEntry576->Resize(160,fTextEntry576->GetDefaultHeight()); // this->AddFrame(fTextEntry576, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2)); // fTextEntry576->MoveResize(16,296,160,22); // fNumEntryRSum = new TGNumberEntry(this, (Double_t) 9,6,-1,(TGNumberFormat::EStyle) 5,(TGNumberFormat::EAttribute) 2,(TGNumberFormat::ELimit) 3,1,12); this->AddFrame(fNumEntryRSum, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2)); fNumEntryRSum->MoveResize(368,24,59,22); fNumEntryRSum->SetState(kFALSE); TGLabel *fLabelRSum = new TGLabel(this,"Running Sum"); fLabelRSum->SetTextJustify(36); fLabelRSum->MoveResize(280,24,80,22); fNumEntryCard = new TGNumberEntry(this, (Double_t) 1,6,-1,(TGNumberFormat::EStyle) 5,(TGNumberFormat::EAttribute) 2,(TGNumberFormat::ELimit) 3,1,16); this->AddFrame(fNumEntryCard, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2)); fNumEntryCard->MoveResize(368,56,59,22); fNumEntryCard->SetState(kFALSE); TGLabel *fLabelCard = new TGLabel(this,"2nd variable"); fLabelCard->SetTextJustify(36); fLabelCard->MoveResize(280,56,80,22); fNumEntryChannel = new TGNumberEntry(this, (Double_t) 1,6,-1,(TGNumberFormat::EStyle) 5,(TGNumberFormat::EAttribute) 2,(TGNumberFormat::ELimit) 3,1,16); this->AddFrame(fNumEntryChannel, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2)); fNumEntryChannel->MoveResize(368,88,59,22); fNumEntryChannel->SetLimitValues(1,1); TGLabel *fLabelChannel = new TGLabel(this,"Variable Num."); fLabelChannel->SetTextJustify(36); fLabelChannel->MoveResize(280,88,80,22); this->SetMWMHints(kMWMDecorAll, kMWMFuncAll, kMWMInputModeless); this->MapSubwindows(); this->Resize(this->GetDefaultSize()); this->MapWindow(); SetWindowName("Running Sums plot GUI"); //this->Resize(490,372); } MyMainFrame::~MyMainFrame() { // Destructor. Cleanup(); } void MyMainFrame::PrintMe() { if(t2){ fLabel->SetText(Form("%d",t2->GetEntries() )); }else{ cout<<"data loading problem :o)"<SetText("Open File first!"); } } void MyMainFrame::OpenFile() { rootFile2o = OpenFileDialog(); f = new TFile(rootFile2o); t2 = (TTree*)f->Get("t2"); tTitle = (TTree*)f->Get("tTitle"); fNumEntryChannel->SetLimitValues(1,tTitle->GetEntries()-1); fNumEntryCard->SetLimitValues(1,tTitle->GetEntries()-1); PrintMe(); } void MyMainFrame::Set2ndVariable() { fNumEntryCard->SetState(kTRUE); if(tTitle) fNumEntryCard->SetLimitValues(1,tTitle->GetEntries()-1); else fNumEntryCard->SetLimitValues(1,1); } void guiPlotTimber() { // Popup the GUI...// new MyMainFrame(0, 490, 372); } #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void MyMainFrame::plotRunningSum() { if (!t2) { PrintMe(); return; } gROOT->SetStyle("Plain"); Int_t Chnl2plot = fNumEntryChannel->GetNumberEntry()->GetIntNumber(); // Int_t Card2plot = fNumEntryCard->GetNumberEntry()->GetIntNumber(); // Int_t RS2plot = fNumEntryRSum->GetNumberEntry()->GetIntNumber() -1; //cout<>RS2plot; Int_t firstStamp; Char_t myTitle[100]; TString strTitle; t2->SetBranchAddress("timeStmp",&firstStamp); t2->GetEntry(0);//Read TimeStamp of the Data (Beginning) TTimeStamp timeStamp(firstStamp,0);//time structure Int_t rsumID; tTitle->SetBranchAddress("fieldName",&myTitle); tTitle->GetEntry(Chnl2plot); strTitle = myTitle; TString RSstring = strTitle(strTitle.Length()-4,2); if(RSstring=="RS"){ RSstring = strTitle(strTitle.Length()-2,2); rsumID = RSstring.Atoi()-1; }else rsumID = -1; int markernb[] = {2,3,4,5,7,8,23,24,25,26,27,29}; int colornb[] = {4,1,2,3,5,6,21,7,8,2,1,2,3,2,21,5,6,7,8,9,1,2,3,21,4,5,6,7,8,9}; double aver[] = {1., 2., 8., 16., 64., 256., 2048., 16384., 32768., 131072., 524288., 2097152.}; double tau = 40e-6; //shortest integration time // aver * tau == integration time; Double_t integTime; if (rsumID>=0) integTime = aver[rsumID]*tau; else integTime = 1; TCanvas *mycc = new TCanvas("mycc","Labtest",0,0,760,480); if (fTextButtonGaps->IsOn()) { mycc->Divide(1,2); mycc->cd(1); } //TGraph *h0 = new TGraph(t2->GetEntries("chnl==1&&card==1&&vect[0]>0")); if (fCheckCounts->IsOn() && (rsumID>=0)) {// if (fCheckSEM->IsOn()) DoseConv = 1024*BLMI_SemFactor*3.38e-9;//2.33e-4;// Gy/count else DoseConv = 1024*3.38e-9;// Gy/count {// const TString ddraw = Form("timber[%d]/%e:timeStmp",Chnl2plot,DoseConv/integTime); //cout<Draw(ddraw,dcut,"pl"); TGraph *h0 = (TGraph*)gPad->GetPrimitive("Graph"); TH2F *ht0 = (TH2F*)gPad->GetPrimitive("htemp"); //h0->SetDirectory(0); h0->SetLineColor(colornb[0]); h0->SetMarkerColor(colornb[0]); h0->SetMarkerStyle(8); h0->SetMarkerSize(0.5); ht0->GetXaxis()->SetTitle("Time Stamp"); ht0->GetXaxis()->SetTimeDisplay(1); if (fCheckCounts->IsOn() && (rsumID>=0)) ht0->GetYaxis()->SetTitle("BLM signal [counts]"); else if (rsumID<0) ht0->GetYaxis()->SetTitle("signal [arb.units]"); else ht0->GetYaxis()->SetTitle("BLM dose rate [Gy/s]"); ht0->GetYaxis()->SetTitleOffset(1.25); // // ht0->SetTitle(Form("variable %i %i",Chnl2plot,timeStamp.GetDate()));//Card %i, Channel %i",Card2plot,Chnl2plot Char_t fieldNameStr[100]; tTitle->SetBranchAddress("fieldName",fieldNameStr); tTitle->GetEntry(Chnl2plot); //TString titlee = fieldNameStr;// + Form(" %i",timeStamp.GetDate()); ht0->SetTitle(fieldNameStr);//Card %i, Channel %i",Card2plot,Chnl2plot //h0->Draw("AP"); gPad->Update(); // xxxxxxxxxx ADD 2nd WINDOW xxxxxxxxxx if (fTextButtonGaps->IsOn()) { Int_t secondVar = fNumEntryCard->GetNumberEntry()->GetIntNumber(); // Int_t firstStamp; Char_t myTitle2[100]; TString strTitle2; // t2->SetBranchAddress("timeStmp",&firstStamp); // // t2->GetEntry(0);//Read TimeStamp of the Data (Beginning) // // TTimeStamp timeStamp(firstStamp,0);//time structure Int_t rsumID2; tTitle->SetBranchAddress("fieldName",&myTitle2); tTitle->GetEntry(secondVar); strTitle2 = myTitle2; TString RSstring2 = strTitle2(strTitle2.Length()-4,2); if(RSstring2=="RS"){ RSstring2 = strTitle2(strTitle2.Length()-2,2); rsumID2 = RSstring2.Atoi()-1; }else rsumID2 = -1; //cout<=0) integTime = aver[rsumID2]*tau; else integTime = 1; // TCanvas *mycc = new TCanvas("mycc","Labtest",0,0,760,480); mycc->cd(2); // if (fTextButtonGaps->IsOn()) // { // mycc->Divide(1,2); // mycc->cd(2); // } //TGraph *h0 = new TGraph(t2->GetEntries("chnl==1&&card==1&&vect[0]>0")); if (fCheckCounts->IsOn() && (rsumID2>=0)) {// if (fCheckSEM->IsOn()) DoseConv = 1024*BLMI_SemFactor*3.38e-9;//2.33e-4;// Gy/count else DoseConv = 1024*3.38e-9;// Gy/count {// const TString ddraw2 = Form("timber[%d]/%e:timeStmp",secondVar,DoseConv/integTime); //cout<Draw(ddraw2,dcut,"pl"); TGraph *h1 = (TGraph*)gPad->GetPrimitive("Graph"); TH2F *ht1 = (TH2F*)gPad->GetPrimitive("htemp"); //h1->SetDirectory(0); h1->SetLineColor(colornb[2]); h1->SetMarkerColor(colornb[2]); h1->SetMarkerStyle(8); h1->SetMarkerSize(0.5); ht1->GetXaxis()->SetTitle("Time Stamp"); ht1->GetXaxis()->SetTimeDisplay(1); if (fCheckCounts->IsOn() && (rsumID2>=0)) ht1->GetYaxis()->SetTitle("BLM signal [counts]"); else if (rsumID2<0) ht1->GetYaxis()->SetTitle("signal [arb.units]"); else ht1->GetYaxis()->SetTitle("BLM dose rate [Gy/s]"); ht1->GetYaxis()->SetTitleOffset(1.25); // // ht1->SetTitle(Form("variable %i %i",Chnl2plot,timeStamp.GetDate()));//Card %i, Channel %i",Card2plot,Chnl2plot Char_t fieldNameStr3[100]; tTitle->SetBranchAddress("fieldName",fieldNameStr3); tTitle->GetEntry(secondVar); //TString titlee = fieldNameStr;// + Form(" %i",timeStamp.GetDate()); ht1->SetTitle(fieldNameStr3);//Card %i, Channel %i",Card2plot,Chnl2plot //h0->Draw("AP"); gPad->Update(); } } TString MyMainFrame::OpenFileDialog(Int_t typeID) { // Prompt for file to be opened. Depending on navigation in // dialog the current working directory can be changed. // The returned file name is always with respect to the // current directory. // // const char *gOpenAsTypes[] = { // // "SDDS files", "*.sdds", // "ROOT files", "*.root", // // "ASCI files", "*.dat", // 0, 0 // }; if(typeID==0){ const char *gOpenAsTypes[] = { "ROOT files", "*.root", 0, 0 }; }else{ const char *gOpenAsTypes[] = { "TIMBER files", "*.csv", "All files", "*.*", 0, 0 }; } // static TGFileInfo fi; fi.fFileTypes = gOpenAsTypes; new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDOpen, &fi); return fi.fFilename; } TString MyMainFrame::SaveFileDialog() { // Prompt for file to be saved. Depending on navigation in // dialog the current working directory can be changed. // The returned file name is always with respect to the // current directory. const char *gSaveAsTypes[] = { "ROOT files", "*.root", "Encapsulated PostScript", "*.eps", "PostScript", "*.ps", "GIF", "*.gif", "SVG", "*.svg", "Macro files", "*.C", 0, 0 }; static TGFileInfo fi; fi.fFileTypes = gSaveAsTypes; new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDSave, &fi); return fi.fFilename; } void MyMainFrame::ReadRSLogFile_andSaveRoot() { cout<<" 100MB file takes ~1.5mins..."<SetText("This will take time.."); t2 = new TTree("t2","a Tree with data from LHC BLM logging - 1 crate"); tTitle = new TTree("tTitle","a Tree with names of arrays"); in.open(filename); if(!in.good()) {cout << "file error" <GetEntries();//entries including timestamp cout<<"vars "<SetLimitValues(1,vars-1); fNumEntryCard->SetLimitValues(1,tTitle->GetEntries()-1); Char_t fieldNamer[100];//[vars];// Names of variables from file header TString fNameTmp;//[vars];// Names of variables from file header tTitle->Branch("fieldName",&fieldNamer,"fieldName/C"); for(Int_t s = 0; sAt(s))->GetString(); strcpy(fieldNamer,fNameTmp.Data()); tTitle->Fill(); } Float_t *timberVect = new Float_t[vars]; Int_t timeStmp; t2->Branch("timber",timberVect,Form("timber[%i]/F",vars)); t2->Branch("timeStmp",&timeStmp,"timeStmp/I"); TString procLine; while(in.good()) { aLine.ReadLine(in); procLine = aLine.ReplaceAll(",,",",0,");//replace missing data by zeroes (except last point on line) procLine = procLine.ReplaceAll(",,",",0,"); // cout<GetEntries()>=vars){// // }else if(!((TObjString*)aLine.Tokenize(",")->At(i)) || (aLine.Tokenize(",")->GetEntries()At(i))){ timberVect[i] = 0.; // if(procLine.Tokenize(",")->GetEntries()At(i))){ tokenedStr = (((TObjString*)procLine.Tokenize(",")->At(i))->GetString()); // if(rows==239){ // cout<GetEntries()<<" "<At(i))->GetString()).Atof()<Fill(); rows+=1;//cout<<"row "<Print(); //t2->Scan("timber[0]:timber[1]:timber[3]:timber[4]:timber[5]"); // // // fCard = procLine(procLine.Index("Card",0),6); //cout<>timee; // // sscanf(timee.Data(),"%4d%2d%2d%2d%2d%2d%*s",&year,&month,&day,&hours,&mins,&secs); // sscanf(timee.Data(),"%*14c,%d,%d,%d",&dataa.cardNumber,&dataa.chNumber,&dataValue); // // //void Set(Int_t year, Int_t month, Int_t day, Int_t hour, Int_t min, Int_t sec, Int_t nsec, Bool_t isUTC, Int_t secOffset) // timeStamp.Set(year,month,day,hours,mins,secs,0,0,0); // // tstamp = hours + mins/60. + secs/3600.; // // //cout<Fill(); // // if(TMath::Abs(timeStamp.GetSec()-timePrevious.GetSec())>0.1){ // stampCnt++; // timePrevious=timeStamp; // } // // if((dataa.cardNumber==CARDS)&&(dataa.chNumber==CHANNELS)){ // cntr++; // } // // //if(cntr==1000) break; // // } // cout<<"number of acquisitions (zeros skipped!) "<Write(); tTitle->Write(); //PrintMe(); //t2 = (TTree*)f2saveRoot.Get("t2"); //t2->Delete(); t2->Reset(); t2=0; tTitle->Reset(); tTitle=0; f2saveRoot.Close(); f = new TFile(rootFile2s); t2 = (TTree*)f->Get("t2"); tTitle = (TTree*)f->Get("tTitle"); PrintMe(); }