From 48b009a8d11fa01ba72ee84be1ef44cad04d97d1 Mon Sep 17 00:00:00 2001
From: PA <philipp.azzarello@gmail.com>
Date: Fri, 19 May 2023 00:24:55 +0200
Subject: [PATCH 1/7] added a canvas with a cogY vs cogX TH2F

---
 DisPanOnline.cxx | 42 ++++++++++++++++++++++++++++++++++++------
 DisPanOnline.hxx |  4 ++--
 2 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/DisPanOnline.cxx b/DisPanOnline.cxx
index ebc615f..0e3e1a8 100644
--- a/DisPanOnline.cxx
+++ b/DisPanOnline.cxx
@@ -485,6 +485,9 @@ void MyMainFrame::InitVectors()
     vh2IntVsCog.assign(NLAD, 0);
     vh2IntVsCogCut.assign(NLAD, 0);
 
+    vh2CogXY.clear();
+    vh2CogXY.assign(NLAD, 0);
+
     vTH1Fp dummy;
     vvHisChHi.clear();
     vvHisChHiPe.clear();
@@ -3806,6 +3809,9 @@ void MyMainFrame::InitGraphHis()
 
         vh2IntVsCog.at(lad) = (new TH2F(Form("hisIntVsCog_lad%d", lad), Form("Int vs cog - Detector %d; channel;", lad), (vBoards.at(lad))->getNLCH() * 4, 0, (vBoards.at(lad))->getNLCH(), 5000, 0, 10000));
         vh2IntVsCogCut.at(lad) = (new TH2F(Form("hisIntVsCogCut_lad%d", lad), Form("Int vs cog (selection) - Detector %d; channel;", lad), (vBoards.at(lad))->getNLCH() * 4, 0, (vBoards.at(lad))->getNLCH(), 5000, 0, 10000));
+
+        vh2CogXY.at(lad) = (new TH2F(Form("hisCogXY_lad%d", lad), Form("Cog Y vs Cog X - Detector %d; CoG X (mm); CoG Y (mm)", lad), 140, -10, 60, 140, -10, 60));
+
         gr = new TGraph();
         gr->SetName(Form("clusters_ladder_%d", lad));
         gr->SetMarkerStyle(23);
@@ -3859,6 +3865,8 @@ void MyMainFrame::ResetHistos()
         vh2IntVsCog.at(lad)->ProfileX()->Reset();
         vh2IntVsCogCut.at(lad)->Reset();
         vh2IntVsCogCut.at(lad)->ProfileX()->Reset();
+
+        vh2CogXY.at(lad)->Reset();
     }
 }
 
@@ -6319,6 +6327,8 @@ void MyMainFrame::Reduction(bool dostats)
     // int nclus_K=0;
     // cluster *actual;
     // channel *actual_channel;
+    vdouble vladcog;
+    vdouble vcog;
 
     for (unsigned int ladder{0}; ladder < NLAD; ladder++)
     {
@@ -6335,16 +6345,26 @@ void MyMainFrame::Reduction(bool dostats)
         ResetGraph(vgrclusters.at(ladder));
         if (dostats)
         {
-            BuildClusterStats(Scluster, ladder);
+            vcog=BuildClusterStats(Scluster, ladder);
             if (TGCBSaveClusters->IsDown())
             {
                 eventNumber_map.at(ladder) = fEventNumberDAQ;
                 frameCounter_map.at(ladder) = fFramaCounterDAQ;
             }
         }
-        // BuildClusterStats(Kcluster, ladder);
-        // BuildGrCluster(Scluster, grclusters[ladder]);
-        // BuildGrCluster(Kcluster,grclusters[ladder]);
+        //cout << "vcog size: " << vcog.size() << endl;
+        if (vcog.size()==1)
+            vladcog.push_back(vcog.at(0));
+    }
+
+    //cout << "vladcog size: " << vladcog.size() << endl;
+
+    if ((fNstripY==1) and dostats) { // the last detector is Y, if it exists
+        if (vladcog.size()==(fNstripX+fNstripY)){
+            for (size_t lad{0}; lad<fNstripX; lad++) {
+                vh2CogXY.at(lad)->Fill(vladcog.at(lad)*0.025, vladcog.at(fNstripX)*0.4);
+            }
+        }   
     }
 
     if (dostats and TGCBSaveClusters->IsDown())
@@ -6402,9 +6422,9 @@ void MyMainFrame::ListChannels(channel *achannel)
     }
 }
 
-void MyMainFrame::BuildClusterStats(cluster *acluster, int ladder)
+vdouble MyMainFrame::BuildClusterStats(cluster *acluster, int ladder)
 {
-
+    vdouble vcog;
     cluster *actual = acluster;
     channel *achannel = 0;
     int nclus = 0;
@@ -6443,6 +6463,7 @@ void MyMainFrame::BuildClusterStats(cluster *acluster, int ladder)
         double cog{actual->cog};
         double sovern1{actual->sovern1};
         vector<double> sovernPerChannel = actual->sovernPerChannel;
+        vcog.push_back(cog);
         if (TGCBSaveClusters->IsDown())
         {
             (integral_map.at(ladder)).push_back(integral);
@@ -6487,6 +6508,7 @@ void MyMainFrame::BuildClusterStats(cluster *acluster, int ladder)
         sovernPerChannel.shrink_to_fit();
     }
     hnclus->Fill(nclus);
+    return vcog;
 }
 
 void MyMainFrame::BuildGrCluster(cluster *acluster, TGraph *gr)
@@ -6751,6 +6773,14 @@ void MyMainFrame::ComputeReduction()
         Reduction(true);
     }
 
+    TCanvas *aCanvas{new TCanvas("aCanvas", "aCanvas", 1000, 800)};
+    aCanvas->Divide(1, 2);
+    aCanvas->cd(1);
+    vh2CogXY.at(0)->Draw("colz");
+    aCanvas->cd(2);
+    vh2CogXY.at(1)->Draw("colz");
+    aCanvas->Update();
+
     if (TGCBSaveClusters->IsDown())
     {
         clusters_tree->Write(0, TObject::kOverwrite);
diff --git a/DisPanOnline.hxx b/DisPanOnline.hxx
index 8e74cdb..c49bda1 100644
--- a/DisPanOnline.hxx
+++ b/DisPanOnline.hxx
@@ -190,7 +190,7 @@ private:
   // vTH1Fp vHisChHi[NLAD], vHisChHiPe[NLAD];
   // TH2F *hisLenVsCog[NLAD], *hisLenVsCogCut[NLAD], *hisIntVsCog[NLAD], *hisIntVsCogCut[NLAD], *h2ChHi[NLAD], *h2ChHiPe[NLAD];
   vvTH1Fp vvHisChHi, vvHisChHiPe;
-  vTH2Fp vh2ChHi, vh2ChHiPe, vh2LenVsCog, vh2LenVsCogCut, vh2IntVsCog, vh2IntVsCogCut, vh2Sovern, vh2SovernCut;
+  vTH2Fp vh2ChHi, vh2ChHiPe, vh2LenVsCog, vh2LenVsCogCut, vh2IntVsCog, vh2IntVsCogCut, vh2Sovern, vh2SovernCut, vh2CogXY;
   TGHProgressBar *fTGHPBprogress;
   unsigned short fStrip[4608], fStripPrevious[4608]; // NCH-->4608
   unsigned int fEventNumberDAQ;
@@ -400,7 +400,7 @@ public:
   void DrawHis(TCanvas *canvas, int pad, TH1 *his);
   void ResetGraph(TGraph *gr);
   void DrawClusterGraph(TCanvas *c, int ipad, int lad);
-  void BuildClusterStats(cluster *acluster, int ladder);
+  vdouble BuildClusterStats(cluster *acluster, int ladder);
   // TF1 *peaks_finder(TH1F *h);
   // TF1 *FindPeaks(TH1F *h);
   void SetCNcut(double cut);
-- 
GitLab


From ba5ac569ce2723c22892d374f37a8271ce4a741b Mon Sep 17 00:00:00 2001
From: PA <philipp.azzarello@gmail.com>
Date: Fri, 19 May 2023 18:06:37 +0200
Subject: [PATCH 2/7] Implementationo of CogY vs CogX tab

---
 DisPanOnline.cxx | 477 +++++++++++++++++++++++++++--------------------
 DisPanOnline.hxx |  16 +-
 2 files changed, 285 insertions(+), 208 deletions(-)

diff --git a/DisPanOnline.cxx b/DisPanOnline.cxx
index 0e3e1a8..a4d6f7d 100644
--- a/DisPanOnline.cxx
+++ b/DisPanOnline.cxx
@@ -117,10 +117,9 @@ MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h, uint nStripX, ui
     TGCompositeFrame *TGCFPedCnSubtView = fDataTab->AddTab("CN-subt");
     AddPedCnSubtTab(TGCFPedCnSubtView);
 
-//    TGCompositeFrame *TGCFChannelHistoView = fDataTab->AddTab("Channel-h");
-//    AddChannelHistoTab(TGCFChannelHistoView);
+    //    TGCompositeFrame *TGCFChannelHistoView = fDataTab->AddTab("Channel-h");
+    //    AddChannelHistoTab(TGCFChannelHistoView);
 
-   
     // Signal over noise tab
 
     TGCompositeFrame *TGCFSovernView = fDataTab->AddTab("Signal over noise");
@@ -154,6 +153,9 @@ MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h, uint nStripX, ui
     TGCompositeFrame *TGCFNclusView = fDataTab->AddTab("Nclu");
     AddNclusTab(TGCFNclusView);
 
+    // CoGX vs CogY
+    TGCompositeFrame *TGCFCogxyView = fDataTab->AddTab("CogY vs. CogX");
+    AddCogxyTab(TGCFCogxyView);
 
     // FFT view (no ped subtraction)
     TGCompositeFrame *TGCFFftView = fDataTab->AddTab("FFT");
@@ -663,6 +665,11 @@ void MyMainFrame::InitAxes()
     fFftAxis[1][2] = 0;
     fFftAxis[1][3] = 100;
 
+    fCogxyAxis[0] = -10;
+    fCogxyAxis[1] = 60;
+    fCogxyAxis[2] = -10;
+    fCogxyAxis[3] = 60;
+
     fPhElCalAxis[0] = 0;
     fPhElCalAxis[1] = 384;
     fPhElCalAxis[2] = 0;
@@ -1843,7 +1850,7 @@ void MyMainFrame::UpdateAdcDisplay(int event, int refreshaxes)
             fAdcCanvas->cd(ConvertLad(lad));
             bool IsY{IsLadY(lad)};
             // fAdcCanvas->cd(1);
-            //fAdcAxis[1] = (vBoards.at(lad))->getNLCH();
+            // fAdcAxis[1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fAdcAxis[IsY][0], fAdcAxis[IsY][2], fAdcAxis[IsY][1], fAdcAxis[IsY][3]);
             frame->SetTitle(Form("ADC - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
             LinesVas(lad);
@@ -1886,7 +1893,7 @@ void MyMainFrame::UpdateSovernDisplay(int refreshaxes)
         {
             bool IsY{IsLadY(lad)};
             fSovernCanvas->cd(ConvertLad(lad));
-            //fSovernAxis[1] = (vBoards.at(lad))->getNLCH();
+            // fSovernAxis[1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fSovernAxis[IsY][0], fSovernAxis[IsY][2], fSovernAxis[IsY][1], fSovernAxis[IsY][3]);
             frame->SetTitle(Form("Signal over noise vs channel - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
             // LinesVas();
@@ -1901,7 +1908,7 @@ void MyMainFrame::UpdateSovernDisplay(int refreshaxes)
         gStyle->SetOptStat(1111111);
         his2->SetStats(kTRUE);
         // if (refreshaxes) {
-        //fSovernAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fSovernAxis[1] = (vBoards.at(lad))->getNLCH();
         his2->GetXaxis()->SetRangeUser(fSovernAxis[IsY][0], fSovernAxis[IsY][1]);
         his2->GetYaxis()->SetRangeUser(fSovernAxis[IsY][2], fSovernAxis[IsY][3]);
         //}
@@ -1940,7 +1947,7 @@ void MyMainFrame::UpdateOccupancyDisplay(int refreshaxes)
         {
             bool IsY{IsLadY(lad)};
             fOccupancyCanvas->cd(ConvertLad(lad));
-            //fOccupancyAxis[1] = (vBoards.at(lad))->getNLCH();
+            // fOccupancyAxis[1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fOccupancyAxis[IsY][0], fOccupancyAxis[IsY][2], fOccupancyAxis[IsY][1], fOccupancyAxis[IsY][3]);
             frame->SetTitle(Form("Occupancy - Detector %d; channel;", lad));
             LinesVas(lad);
@@ -1975,7 +1982,7 @@ void MyMainFrame::UpdateCogDisplay(int refreshaxes)
         {
             bool IsY{IsLadY(lad)};
             fCogCanvas->cd(ConvertLad(lad));
-            //fCogAxis[1] = (vBoards.at(lad))->getNLCH();
+            // fCogAxis[1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fCogAxis[IsY][0], fCogAxis[IsY][2], fCogAxis[IsY][1], fCogAxis[IsY][3]);
             frame->SetTitle(Form("Center of gravity - Detector %d; channel;", lad));
             LinesVas(lad);
@@ -2046,7 +2053,7 @@ void MyMainFrame::UpdateLenVsCogDisplay(int refreshaxes)
         {
             fLenVsCogCanvas->cd(ConvertLad(lad));
             bool IsY{IsLadY(lad)};
-            //fLenVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
+            // fLenVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fLenVsCogAxis[IsY][0], fLenVsCogAxis[IsY][2], fLenVsCogAxis[IsY][1], fLenVsCogAxis[IsY][3]);
             frame->SetTitle(Form("Len vs cog - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
             // LinesVas();
@@ -2061,7 +2068,7 @@ void MyMainFrame::UpdateLenVsCogDisplay(int refreshaxes)
         gStyle->SetOptStat(1111111);
         his2->SetStats(kTRUE);
         // if (refreshaxes) {
-        //fLenVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fLenVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
         his2->GetXaxis()->SetRangeUser(fLenVsCogAxis[IsY][0], fLenVsCogAxis[IsY][1]);
         his2->GetYaxis()->SetRangeUser(fLenVsCogAxis[IsY][2], fLenVsCogAxis[IsY][3]);
         //}
@@ -2102,7 +2109,7 @@ void MyMainFrame::UpdateIntVsCogDisplay(int refreshaxes)
         {
             fIntVsCogCanvas->cd(ConvertLad(lad));
             bool IsY{IsLadY(lad)};
-            //fIntVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
+            // fIntVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fIntVsCogAxis[IsY][0], fIntVsCogAxis[IsY][2], fIntVsCogAxis[IsY][1], fIntVsCogAxis[IsY][3]);
             frame->SetTitle(Form("Int vs cog - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
             // LinesVas();
@@ -2117,7 +2124,7 @@ void MyMainFrame::UpdateIntVsCogDisplay(int refreshaxes)
         gStyle->SetOptStat(1111111);
         his2->SetStats(kTRUE);
         // if (refreshaxes) {
-        //fIntVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fIntVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
         his2->GetXaxis()->SetRangeUser(fIntVsCogAxis[IsY][0], fIntVsCogAxis[IsY][1]);
         his2->GetYaxis()->SetRangeUser(fIntVsCogAxis[IsY][2], fIntVsCogAxis[IsY][3]);
         //}
@@ -2140,7 +2147,6 @@ void MyMainFrame::UpdateIntVsCogDisplay(int refreshaxes)
     fDisplayBusy = 0;
 }
 
-
 void MyMainFrame::UpdateIntsDisplay(int refreshaxes)
 {
 
@@ -2174,8 +2180,6 @@ void MyMainFrame::UpdateIntsDisplay(int refreshaxes)
     fDisplayBusy = 0;
 }
 
-
-
 void MyMainFrame::UpdateFftDisplay(int refreshaxes)
 {
 
@@ -2192,7 +2196,7 @@ void MyMainFrame::UpdateFftDisplay(int refreshaxes)
         {
             fFftCanvas->cd(ConvertLad(lad));
             bool IsY{IsLadY(lad)};
-            //fFftAxis[1] = (vBoards.at(lad))->getNLCH();
+            // fFftAxis[1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fFftAxis[IsY][0], fFftAxis[IsY][2], fFftAxis[IsY][1], fFftAxis[IsY][3]);
             frame->SetTitle(Form("FFT - Detector %d; frequency;", lad));
             // LinesVas();
@@ -2298,7 +2302,7 @@ void MyMainFrame::UpdatePedSubtDisplay(int event, int refreshaxes)
         {
             bool IsY{IsLadY(lad)};
             fPedSubtCanvas->cd(ConvertLad(lad));
-            //fPedSubtAxis[IsY][1] = (vBoards.at(lad))->getNLCH(); 
+            // fPedSubtAxis[IsY][1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fPedSubtAxis[IsY][0], fPedSubtAxis[IsY][2], fPedSubtAxis[IsY][1], fPedSubtAxis[IsY][3]);
             frame->SetTitle(Form("Ped. subt. - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
             LinesVas(lad);
@@ -2319,7 +2323,6 @@ void MyMainFrame::UpdatePedSubtDisplay(int event, int refreshaxes)
     fDisplayBusy = 0;
 }
 
-
 void MyMainFrame::UpdateAdcPedCnSubtDisplay(int event, int refreshaxes)
 {
 
@@ -2367,7 +2370,7 @@ void MyMainFrame::UpdatePedCnSubtDisplay(int event, int refreshaxes)
         {
             fPedCnSubtCanvas->cd(ConvertLad(lad));
             bool IsY{IsLadY(lad)};
-            //fPedCnSubtAxis[1] = (vBoards.at(lad))->getNLCH();
+            // fPedCnSubtAxis[1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fPedCnSubtAxis[IsY][0], fPedCnSubtAxis[IsY][2], fPedCnSubtAxis[IsY][1], fPedCnSubtAxis[IsY][3]);
             frame->SetTitle(Form("Signals - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
             LinesVas(lad);
@@ -3119,9 +3122,9 @@ void MyMainFrame::DisplayPedestals()
     for (uint lad{0}; lad < NLAD; lad++)
     {
         bool IsY{IsLadY(lad)};
-        //cout << " drawing: lad = " << lad << endl;
+        // cout << " drawing: lad = " << lad << endl;
         c->cd(ConvertLad(lad));
-        //fPedAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fPedAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame{gPad->DrawFrame(fPedAxis[IsY][0], fPedAxis[IsY][2], fPedAxis[IsY][1], fPedAxis[IsY][3])};
         frame->SetTitle(Form("Pedestals - Detector %d; %s", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
         ped[lad]->Draw("l");
@@ -3177,7 +3180,7 @@ void MyMainFrame::DisplaySovern()
             gPad->SetLogz();
         if (profile_x)
         {
-            //fSovernAxis[1] = (vBoards.at(lad))->getNLCH();
+            // fSovernAxis[1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fSovernAxis[IsY][0], (fSovernAxis[IsY][2] < 0) ? 0 : fSovernAxis[IsY][2], fSovernAxis[IsY][1], fSovernAxis[IsY][3]);
             frame->SetTitle(Form("Signal over noise vs channel - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
         }
@@ -3185,7 +3188,7 @@ void MyMainFrame::DisplaySovern()
         TH2F *his2 = (TGCBshowSovernCut->IsDown() ? vh2SovernCut.at(lad) : vh2Sovern.at(lad));
         gStyle->SetOptStat(1111111);
         his2->SetStats(kTRUE);
-        //fSovernAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fSovernAxis[1] = (vBoards.at(lad))->getNLCH();
         his2->GetXaxis()->SetRangeUser(fSovernAxis[IsY][0], fSovernAxis[IsY][1]);
         his2->GetYaxis()->SetRangeUser(fSovernAxis[IsY][2], fSovernAxis[IsY][3]);
         if (!profile_x)
@@ -3208,7 +3211,7 @@ void MyMainFrame::DisplayOccupancy()
         c->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
         // gPad->SetLogy();
-        //fOccupancyAxis[IsY][1] = (vBoards.at(lad))->getNLCH();
+        // fOccupancyAxis[IsY][1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fOccupancyAxis[IsY][0], fOccupancyAxis[IsY][2], fOccupancyAxis[IsY][1], fOccupancyAxis[IsY][3]);
         gStyle->SetOptStat(1111111);
         frame->SetTitle(Form("Occupancy - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
@@ -3230,7 +3233,7 @@ void MyMainFrame::DisplayCog()
     {
         bool IsY{IsLadY(lad)};
         c->cd(ConvertLad(lad));
-        //fCogAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fCogAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fCogAxis[IsY][0], fCogAxis[IsY][2], fCogAxis[IsY][1], fCogAxis[IsY][3]);
         gStyle->SetOptStat(1111111);
         frame->SetTitle(Form("Cog - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
@@ -3244,6 +3247,19 @@ void MyMainFrame::DisplayCog()
     c->Update();
 }
 
+
+void MyMainFrame::DisplayCogxy() {
+
+    TCanvas *c = fCogxyCanvas;
+
+    for (int det{0}; det < fNstripX; det++) {
+        c->cd(det+1);
+        vh2CogXY.at(det)->Draw("colz");
+    }
+    c->Update();
+}
+
+
 void MyMainFrame::DisplayLens()
 {
     TCanvas *c = fLensCanvas;
@@ -3280,7 +3296,7 @@ void MyMainFrame::DisplayLenVsCog()
             gPad->SetLogz();
         if (profile_x)
         {
-            //fLenVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
+            // fLenVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fLenVsCogAxis[IsY][0], (fLenVsCogAxis[IsY][2] < 0) ? 0 : fLenVsCogAxis[IsY][2], fLenVsCogAxis[IsY][1], fLenVsCogAxis[IsY][3]);
             frame->SetTitle(Form("Len vs cog - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
         }
@@ -3288,7 +3304,7 @@ void MyMainFrame::DisplayLenVsCog()
         TH2F *his2 = (TGCBshowLenVsCogCut->IsDown() ? vh2LenVsCogCut.at(lad) : vh2LenVsCog.at(lad));
         gStyle->SetOptStat(1111111);
         his2->SetStats(kTRUE);
-        //fLenVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fLenVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
         his2->GetXaxis()->SetRangeUser(fLenVsCogAxis[IsY][0], fLenVsCogAxis[IsY][1]);
         his2->GetYaxis()->SetRangeUser(fLenVsCogAxis[IsY][2], fLenVsCogAxis[IsY][3]);
         if (!profile_x)
@@ -3316,7 +3332,7 @@ void MyMainFrame::DisplayIntVsCog()
             gPad->SetLogz();
         if (profile_x)
         {
-            //fIntVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
+            // fIntVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
             TH1F *frame = gPad->DrawFrame(fIntVsCogAxis[IsY][0], (fIntVsCogAxis[IsY][2] < 0) ? 0 : fIntVsCogAxis[IsY][2], fIntVsCogAxis[IsY][1], fIntVsCogAxis[IsY][3]);
             // frame->SetTitle(Form("Int vs cog - Detector %d; %s;", lad, ChanLabel[fChanLabelMode].c_str()));
             frame->SetTitle(Form("Int vs cog - Detector %d; cog;integral", lad));
@@ -3325,7 +3341,7 @@ void MyMainFrame::DisplayIntVsCog()
         TH2F *his2 = (TGCBshowIntVsCogCut->IsDown() ? vh2IntVsCogCut.at(lad) : vh2IntVsCog.at(lad));
         gStyle->SetOptStat(1111111);
         his2->SetStats(kTRUE);
-        //fIntVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fIntVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
         his2->GetXaxis()->SetRangeUser(fIntVsCogAxis[IsY][0], fIntVsCogAxis[IsY][1]);
         his2->GetYaxis()->SetRangeUser(fIntVsCogAxis[IsY][2], fIntVsCogAxis[IsY][3]);
         if (!profile_x)
@@ -3364,17 +3380,19 @@ void MyMainFrame::DisplayInts()
         {
             flandau->SetRange(20, 60);
             flangau->SetParameters(5, 30, 100, 5);
+            flangau->SetParLimits(1, 10, 50);
         }
         else
         { // StripY
             flandau->SetRange(150, 400);
             flangau->SetParameters(5, 250, 100, 5);
+            flangau->SetParLimits(1, 150, 300);
         }
         TH1F *frame;
-        //if (!IsLadY(lad))
+        // if (!IsLadY(lad))
         frame = gPad->DrawFrame(fIntsAxis[IsY][0], (fIntsAxis[IsY][2] <= 0) ? 1 : fIntsAxis[IsY][2], fIntsAxis[IsY][1], fIntsAxis[IsY][3]);
-        //else
-          //  frame = gPad->DrawFrame(fIntsAxisY[0], (fIntsAxisY[2] <= 0) ? 1 : fIntsAxisY[2], fIntsAxisY[1], fIntsAxisY[3]);
+        // else
+        //   frame = gPad->DrawFrame(fIntsAxisY[0], (fIntsAxisY[2] <= 0) ? 1 : fIntsAxisY[2], fIntsAxisY[1], fIntsAxisY[3]);
         gStyle->SetOptStat(1111111);
         frame->SetTitle(Form("Ints - Detector %d; cluster integral (ADCc);", lad));
         TH1F *his = (TGCBshowIntsCut->IsDown() ? vhisIntSCut.at(lad) : vhisIntS.at(lad));
@@ -3390,25 +3408,26 @@ void MyMainFrame::DisplayInts()
         his->Fit(flangau, "RM");
 
         uint ndet{fNstripX + fNstripY};
-        double posx {0.5};
+        double posx{0.5};
         double posy{0.5};
         double size{0.05};
 
-        switch (ndet) {
-            case 2:
-                posx=0.6;
-                posy = 0.6;
-                size = 0.03;
-                break;
-            case 3:
-                posx = 0.7;
-                posy = 0.7;
-                size = 0.05;
-                break;
-            defaut:
-                posx = 0.5;
-                posy = 0.5;
-                size = 0.04;
+        switch (ndet)
+        {
+        case 2:
+            posx = 0.6;
+            posy = 0.6;
+            size = 0.03;
+            break;
+        case 3:
+            posx = 0.7;
+            posy = 0.7;
+            size = 0.05;
+            break;
+        defaut:
+            posx = 0.5;
+            posy = 0.5;
+            size = 0.04;
         }
         TLatex *tlt{new TLatex()};
         tlt->SetNDC();
@@ -3491,7 +3510,7 @@ void MyMainFrame::DisplayPedCompar()
     {
         c->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fPedCompAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fPedCompAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fPedCompAxis[IsY][0], fPedCompAxis[IsY][2], fPedCompAxis[IsY][1], fPedCompAxis[IsY][3]);
         frame->SetTitle(Form("Ped. diff. - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
         delped[lad]->Draw("l");
@@ -3543,7 +3562,7 @@ void MyMainFrame::DisplayRawSigmas()
     {
         c->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fSrawAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fSrawAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fSrawAxis[IsY][0], fSrawAxis[IsY][2], fSrawAxis[IsY][1], fSrawAxis[IsY][3]);
         frame->SetTitle(Form("Raw sigmas - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
         sraw[lad]->Draw("l");
@@ -3596,7 +3615,7 @@ void MyMainFrame::DisplaySigmas()
     {
         c->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fSigmaAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fSigmaAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fSigmaAxis[IsY][0], fSigmaAxis[IsY][2], fSigmaAxis[IsY][1], fSigmaAxis[IsY][3]);
         frame->SetTitle(Form("Sigmas - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
         sigma[lad]->Draw("l");
@@ -3685,7 +3704,7 @@ void MyMainFrame::DisplaySigmaCompar()
     {
         c->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fSigmaCompAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fSigmaCompAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fSigmaCompAxis[IsY][0], fSigmaCompAxis[IsY][2], fSigmaCompAxis[IsY][1], fSigmaCompAxis[IsY][3]);
         frame->SetTitle(Form("Sigma comparison - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str())),
             sigma[lad]->Draw("pl");
@@ -3914,7 +3933,7 @@ void MyMainFrame::AddAdcTab(TGCompositeFrame *cframe)
     {
         fAdcCanvas->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fAdcAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fAdcAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fAdcAxis[IsY][0], fAdcAxis[IsY][2], fAdcAxis[IsY][1], fAdcAxis[IsY][3]);
         frame->SetTitle(Form("ADC - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
         LinesVas(lad);
@@ -3946,7 +3965,7 @@ void MyMainFrame::AddSovernTab(TGCompositeFrame *cframe)
     {
         fSovernCanvas->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fSovernAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fSovernAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fSovernAxis[IsY][0], fSovernAxis[IsY][2], fSovernAxis[IsY][1], fSovernAxis[IsY][3]);
         frame->SetTitle(Form("Signal over noise vs channel - Detector %d; channel;", lad));
         // LinesVas();
@@ -3987,7 +4006,7 @@ void MyMainFrame::AddOccupancyTab(TGCompositeFrame *cframe)
     {
         fOccupancyCanvas->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fOccupancyAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fOccupancyAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fOccupancyAxis[IsY][0], fOccupancyAxis[IsY][2], fOccupancyAxis[IsY][1], fOccupancyAxis[IsY][3]);
         frame->SetTitle(Form("Occupancy - Detector %d; channel;", lad));
         LinesVas(lad);
@@ -4023,7 +4042,7 @@ void MyMainFrame::AddCogTab(TGCompositeFrame *cframe)
     {
         fCogCanvas->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fCogAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fCogAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fCogAxis[IsY][0], fCogAxis[IsY][2], fCogAxis[IsY][1], fCogAxis[IsY][3]);
         frame->SetTitle(Form("Center of gravity - Detector %d; channel;", lad));
         LinesVas(lad);
@@ -4093,7 +4112,7 @@ void MyMainFrame::AddLenVsCogTab(TGCompositeFrame *cframe)
     for (unsigned int lad{0}; lad < NLAD; lad++)
     {
         fLenVsCogCanvas->cd(ConvertLad(lad));
-        //fLenVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fLenVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
         bool IsY{IsLadY(lad)};
         TH1F *frame = gPad->DrawFrame(fLenVsCogAxis[IsY][0], fLenVsCogAxis[IsY][2], fLenVsCogAxis[IsY][1], fLenVsCogAxis[IsY][3]);
         frame->SetTitle(Form("Cluster length vs cog - Detector %d; channel;", lad));
@@ -4102,25 +4121,25 @@ void MyMainFrame::AddLenVsCogTab(TGCompositeFrame *cframe)
 
     TGHorizontalFrame *Hframe = new TGHorizontalFrame(Vframe, 200, 40);
     BuildAxisControls(Hframe, TGNElenvscogax, fLenVsCogAxis, "UpdateLenVsCogAxes");
-/*
-    TGLabel *minmax[4];
-    minmax[0] = new TGLabel(Hframe, "min x:");
-    minmax[1] = new TGLabel(Hframe, "max x:");
-    minmax[2] = new TGLabel(Hframe, "min y:");
-    minmax[3] = new TGLabel(Hframe, "max y:");
+    /*
+        TGLabel *minmax[4];
+        minmax[0] = new TGLabel(Hframe, "min x:");
+        minmax[1] = new TGLabel(Hframe, "max x:");
+        minmax[2] = new TGLabel(Hframe, "min y:");
+        minmax[3] = new TGLabel(Hframe, "max y:");
 
-    for (int i = 0; i < 4; i++)
-    {
-        TGNElenvscogax[i] = new TGNumberEntry(Hframe, fLenVsCogAxis[i]);
-        TGNElenvscogax[i]->Connect("ValueSet(Long_t)", "MyMainFrame", this, "UpdateLenVsCogAxes()");
-    }
+        for (int i = 0; i < 4; i++)
+        {
+            TGNElenvscogax[i] = new TGNumberEntry(Hframe, fLenVsCogAxis[i]);
+            TGNElenvscogax[i]->Connect("ValueSet(Long_t)", "MyMainFrame", this, "UpdateLenVsCogAxes()");
+        }
 
-    for (int i = 0; i < 4; i++)
-    {
-        Hframe->AddFrame(minmax[i], TGLHleft);
-        Hframe->AddFrame(TGNElenvscogax[i], TGLHleft);
-    }
-*/
+        for (int i = 0; i < 4; i++)
+        {
+            Hframe->AddFrame(minmax[i], TGLHleft);
+            Hframe->AddFrame(TGNElenvscogax[i], TGLHleft);
+        }
+    */
     TGCBshowProfileLenVsCog = new TGCheckButton(Hframe, "Show x-profile");
     TGCBshowProfileLenVsCog->Connect("Clicked()", "MyMainFrame", this, "DisplayLenVsCog()");
     Hframe->AddFrame(TGCBshowProfileLenVsCog, TGLHleft);
@@ -4152,7 +4171,7 @@ void MyMainFrame::AddIntVsCogTab(TGCompositeFrame *cframe)
     {
         fIntVsCogCanvas->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fIntVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fIntVsCogAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fIntVsCogAxis[IsY][0], fIntVsCogAxis[IsY][2], fIntVsCogAxis[IsY][1], fIntVsCogAxis[IsY][3]);
         frame->SetTitle(Form("Cluster integral vs cog - Detector %d; channel;", lad));
         // LinesVas();
@@ -4160,25 +4179,25 @@ void MyMainFrame::AddIntVsCogTab(TGCompositeFrame *cframe)
 
     TGHorizontalFrame *Hframe = new TGHorizontalFrame(Vframe, 200, 40);
     BuildAxisControls(Hframe, TGNEintvscogax, fIntVsCogAxis, "UpdateIntVsCogAxes");
-/*
-    TGLabel *minmax[4];
-    minmax[0] = new TGLabel(Hframe, "min x:");
-    minmax[1] = new TGLabel(Hframe, "max x:");
-    minmax[2] = new TGLabel(Hframe, "min y:");
-    minmax[3] = new TGLabel(Hframe, "max y:");
+    /*
+        TGLabel *minmax[4];
+        minmax[0] = new TGLabel(Hframe, "min x:");
+        minmax[1] = new TGLabel(Hframe, "max x:");
+        minmax[2] = new TGLabel(Hframe, "min y:");
+        minmax[3] = new TGLabel(Hframe, "max y:");
 
-    for (int i = 0; i < 4; i++)
-    {
-        TGNEintvscogax[i] = new TGNumberEntry(Hframe, fIntVsCogAxis[i]);
-        TGNEintvscogax[i]->Connect("ValueSet(Long_t)", "MyMainFrame", this, "UpdateIntVsCogAxes()");
-    }
+        for (int i = 0; i < 4; i++)
+        {
+            TGNEintvscogax[i] = new TGNumberEntry(Hframe, fIntVsCogAxis[i]);
+            TGNEintvscogax[i]->Connect("ValueSet(Long_t)", "MyMainFrame", this, "UpdateIntVsCogAxes()");
+        }
 
-    for (int i = 0; i < 4; i++)
-    {
-        Hframe->AddFrame(minmax[i], TGLHleft);
-        Hframe->AddFrame(TGNEintvscogax[i], TGLHleft);
-    }
-*/
+        for (int i = 0; i < 4; i++)
+        {
+            Hframe->AddFrame(minmax[i], TGLHleft);
+            Hframe->AddFrame(TGNEintvscogax[i], TGLHleft);
+        }
+    */
     TGCBshowProfileIntVsCog = new TGCheckButton(Hframe, "Show x-profile");
     TGCBshowProfileIntVsCog->Connect("Clicked()", "MyMainFrame", this, "DisplayIntVsCog()");
     Hframe->AddFrame(TGCBshowProfileIntVsCog, TGLHleft);
@@ -4214,7 +4233,6 @@ void MyMainFrame::AddIntsTab(TGCompositeFrame *cframe)
         // LinesVas();
     }
 
-
     TGHorizontalFrame *Hframe = new TGHorizontalFrame(Vframe, 200, 40);
 
     BuildAxisControls(Hframe, TGNEintsax, fIntsAxis, "UpdateIntsAxes");
@@ -4253,32 +4271,30 @@ void MyMainFrame::AddNclusTab(TGCompositeFrame *cframe)
 
     TGHorizontalFrame *Hframe = new TGHorizontalFrame(Vframe, 200, 40);
     BuildAxisControls(Hframe, TGNEnclusax, fNclusAxis, "UpdateNclusAxes");
-/*
-    TGLabel *minmax[4];
-    minmax[0] = new TGLabel(Hframe, "min x:");
-    minmax[1] = new TGLabel(Hframe, "max x:");
-    minmax[2] = new TGLabel(Hframe, "min y:");
-    minmax[3] = new TGLabel(Hframe, "max y:");
+    /*
+        TGLabel *minmax[4];
+        minmax[0] = new TGLabel(Hframe, "min x:");
+        minmax[1] = new TGLabel(Hframe, "max x:");
+        minmax[2] = new TGLabel(Hframe, "min y:");
+        minmax[3] = new TGLabel(Hframe, "max y:");
 
-    for (int i = 0; i < 4; i++)
-    {
-        TGNEnclusax[i] = new TGNumberEntry(Hframe, fNclusAxis[i]);
-        TGNEnclusax[i]->Connect("ValueSet(Long_t)", "MyMainFrame", this, "UpdateNclusAxes()");
-    }
+        for (int i = 0; i < 4; i++)
+        {
+            TGNEnclusax[i] = new TGNumberEntry(Hframe, fNclusAxis[i]);
+            TGNEnclusax[i]->Connect("ValueSet(Long_t)", "MyMainFrame", this, "UpdateNclusAxes()");
+        }
 
-    for (int i = 0; i < 4; i++)
-    {
-        Hframe->AddFrame(minmax[i], TGLHleft);
-        Hframe->AddFrame(TGNEnclusax[i], TGLHleft);
-    }
-*/
+        for (int i = 0; i < 4; i++)
+        {
+            Hframe->AddFrame(minmax[i], TGLHleft);
+            Hframe->AddFrame(TGNEnclusax[i], TGLHleft);
+        }
+    */
     Vframe->AddFrame(fEncluscanvas, TGLHexpandXexpandY);
     Vframe->AddFrame(Hframe, TGLHexpandX);
     cframe->AddFrame(Vframe, TGLHexpandXexpandY);
 }
 
-
-
 void MyMainFrame::AddFftTab(TGCompositeFrame *cframe)
 {
 
@@ -4297,7 +4313,7 @@ void MyMainFrame::AddFftTab(TGCompositeFrame *cframe)
     {
         fFftCanvas->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fFftAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fFftAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fFftAxis[IsY][0], fFftAxis[IsY][2], fFftAxis[IsY][1], fFftAxis[IsY][3]);
         frame->SetTitle(Form("FFT - Detector %d; frequency;", lad));
         // LinesVas();
@@ -4305,25 +4321,25 @@ void MyMainFrame::AddFftTab(TGCompositeFrame *cframe)
 
     TGHorizontalFrame *Hframe = new TGHorizontalFrame(Vframe, 200, 40);
     BuildAxisControls(Hframe, TGNEfftax, fFftAxis, "UpdateFftAxes");
-/*
-    TGLabel *minmax[4];
-    minmax[0] = new TGLabel(Hframe, "min x:");
-    minmax[1] = new TGLabel(Hframe, "max x:");
-    minmax[2] = new TGLabel(Hframe, "min y:");
-    minmax[3] = new TGLabel(Hframe, "max y:");
+    /*
+        TGLabel *minmax[4];
+        minmax[0] = new TGLabel(Hframe, "min x:");
+        minmax[1] = new TGLabel(Hframe, "max x:");
+        minmax[2] = new TGLabel(Hframe, "min y:");
+        minmax[3] = new TGLabel(Hframe, "max y:");
 
-    for (int i = 0; i < 4; i++)
-    {
-        TGNEfftax[i] = new TGNumberEntry(Hframe, fFftAxis[i]);
-        TGNEfftax[i]->Connect("ValueSet(Long_t)", "MyMainFrame", this, "UpdateFftAxes()");
-    }
+        for (int i = 0; i < 4; i++)
+        {
+            TGNEfftax[i] = new TGNumberEntry(Hframe, fFftAxis[i]);
+            TGNEfftax[i]->Connect("ValueSet(Long_t)", "MyMainFrame", this, "UpdateFftAxes()");
+        }
 
-    for (int i = 0; i < 4; i++)
-    {
-        Hframe->AddFrame(minmax[i], TGLHleft);
-        Hframe->AddFrame(TGNEfftax[i], TGLHleft);
-    }
-*/
+        for (int i = 0; i < 4; i++)
+        {
+            Hframe->AddFrame(minmax[i], TGLHleft);
+            Hframe->AddFrame(TGNEfftax[i], TGLHleft);
+        }
+    */
     //  normlabel=new TGLabel(Hframe,"
     TGCBShowFFTNorm = new TGCheckButton(Hframe, "Normalized");
     TGCBShowFFTNorm->SetDown();
@@ -4370,8 +4386,6 @@ void MyMainFrame::AddPedSubtTab(TGCompositeFrame *cframe)
     cframe->AddFrame(Vframe, TGLHexpandXexpandY);
 }
 
-
-
 void MyMainFrame::AddPedCnSubtTab(TGCompositeFrame *cframe)
 {
 
@@ -4390,7 +4404,7 @@ void MyMainFrame::AddPedCnSubtTab(TGCompositeFrame *cframe)
     {
         bool IsY{IsLadY(lad)};
         fPedCnSubtCanvas->cd(ConvertLad(lad));
-        //fPedCnSubtAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fPedCnSubtAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fPedCnSubtAxis[IsY][0], fPedCnSubtAxis[IsY][2], fPedCnSubtAxis[IsY][1], fPedCnSubtAxis[IsY][3]);
         frame->SetTitle(Form("Signals - Detector %d; %s;", lad, ChanLabel[(vBoards.at(lad))->getConvertMode()].c_str()));
         LinesVas(lad);
@@ -4422,7 +4436,7 @@ void MyMainFrame::AddPedTab(TGCompositeFrame *cframe)
     {
         fPedCanvas->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fPedAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fPedAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fPedAxis[IsY][0], fPedAxis[IsY][2], fPedAxis[IsY][1], fPedAxis[IsY][3]);
         frame->SetTitle(Form("Pedestals - Detector %d; channels;", lad));
         LinesVas(lad);
@@ -4459,7 +4473,7 @@ void MyMainFrame::AddPedCompTab(TGCompositeFrame *cframe)
     {
         fPedCompCanvas->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fPedCompAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fPedCompAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fPedCompAxis[IsY][0], fPedCompAxis[IsY][2], fPedCompAxis[IsY][1], fPedCompAxis[IsY][3]);
         frame->SetTitle(Form("Ped. diff. - Detector %d; channels;", lad));
         LinesVas(lad);
@@ -4467,25 +4481,7 @@ void MyMainFrame::AddPedCompTab(TGCompositeFrame *cframe)
 
     TGHorizontalFrame *Hframe = new TGHorizontalFrame(Vframe, 200, 40);
     BuildAxisControls(Hframe, TGNEpedcompax, fPedCompAxis, "UpdatePedCompAxes");
-/*
-    TGLabel *minmax[4];
-    minmax[0] = new TGLabel(Hframe, "min ch:");
-    minmax[1] = new TGLabel(Hframe, "max ch:");
-    minmax[2] = new TGLabel(Hframe, "min y:");
-    minmax[3] = new TGLabel(Hframe, "max y:");
 
-    for (int i = 0; i < 4; i++)
-    {
-        TGNEpedcompax[i] = new TGNumberEntry(Hframe, fPedCompAxis[i]);
-        TGNEpedcompax[i]->Connect("ValueSet(Long_t)", "MyMainFrame", this, "UpdatePedCompAxes()");
-    }
-
-    for (int i = 0; i < 4; i++)
-    {
-        Hframe->AddFrame(minmax[i], TGLHleft);
-        Hframe->AddFrame(TGNEpedcompax[i], TGLHleft);
-    }
-*/
     Vframe->AddFrame(fEpedcompcanvas, TGLHexpandXexpandY);
     Vframe->AddFrame(Hframe, TGLHexpandX);
     cframe->AddFrame(Vframe, TGLHexpandXexpandY);
@@ -4509,7 +4505,7 @@ void MyMainFrame::AddSrawTab(TGCompositeFrame *cframe)
     {
         bool IsY{IsLadY(lad)};
         fSrawCanvas->cd(ConvertLad(lad));
-        //fSrawAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fSrawAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fSrawAxis[IsY][0], fSrawAxis[IsY][2], fSrawAxis[IsY][1], fSrawAxis[IsY][3]);
         frame->SetTitle(Form("Raw sigmas- Detector %d; channels;", lad));
         LinesVas(lad);
@@ -4541,7 +4537,7 @@ void MyMainFrame::AddSigmaTab(TGCompositeFrame *cframe)
     {
         fSigmaCanvas->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fSigmaAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fSigmaAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fSigmaAxis[IsY][0], fSigmaAxis[IsY][2], fSigmaAxis[IsY][1], fSigmaAxis[IsY][3]);
         frame->SetTitle(Form("Sigmas - Detector %d; channels;", lad));
         LinesVas(lad);
@@ -4549,7 +4545,7 @@ void MyMainFrame::AddSigmaTab(TGCompositeFrame *cframe)
 
     TGHorizontalFrame *Hframe = new TGHorizontalFrame(Vframe, 200, 40);
     BuildAxisControls(Hframe, TGNEsigmaax, fSigmaAxis, "UpdateSigmaAxes");
- 
+
     TGCBshowrefsig = new TGCheckButton(Hframe, "Show reference");
     TGCBshowrefsig->Connect("Clicked()", "MyMainFrame", this, "DisplaySigmas()");
 
@@ -4578,7 +4574,7 @@ void MyMainFrame::AddSigmaCompTab(TGCompositeFrame *cframe)
     {
         fSigmaCompCanvas->cd(ConvertLad(lad));
         bool IsY{IsLadY(lad)};
-        //fSigmaCompAxis[1] = (vBoards.at(lad))->getNLCH();
+        // fSigmaCompAxis[1] = (vBoards.at(lad))->getNLCH();
         TH1F *frame = gPad->DrawFrame(fSigmaCompAxis[IsY][0], fSigmaCompAxis[IsY][2], fSigmaCompAxis[IsY][1], fSigmaCompAxis[IsY][3]);
         frame->SetTitle(Form("Sigmas comparison - Detector %d; channels;", lad));
         LinesVas(lad);
@@ -4586,26 +4582,44 @@ void MyMainFrame::AddSigmaCompTab(TGCompositeFrame *cframe)
 
     TGHorizontalFrame *Hframe = new TGHorizontalFrame(Vframe, 200, 40);
     BuildAxisControls(Hframe, TGNEsigmacompax, fSigmaCompAxis, "UpdateSigmaCompAxes");
-        /*
-        TGLabel *minmax[4];
-        minmax[0] = new TGLabel(Hframe, "min ch:");
-        minmax[1] = new TGLabel(Hframe, "max ch:");
-        minmax[2] = new TGLabel(Hframe, "min y:");
-        minmax[3] = new TGLabel(Hframe, "max y:");
 
-        for (int i = 0; i < 4; i++)
+    Vframe->AddFrame(fEsigmacompcanvas, TGLHexpandXexpandY);
+    Vframe->AddFrame(Hframe, TGLHexpandX);
+    cframe->AddFrame(Vframe, TGLHexpandXexpandY);
+}
+
+void MyMainFrame::AddCogxyTab(TGCompositeFrame *cframe)
+{
+
+    TGVerticalFrame *Vframe = new TGVerticalFrame(cframe, 200, 40);
+
+    fEcogxycanvas = new TRootEmbeddedCanvas("cogxycanvas", Vframe, fWidth, fHeight);
+    fCogxyCanvas = fEcogxycanvas->GetCanvas();
+    fCogxyCanvas->Clear();
+    if (fNstripY > 0)
+    {
+        CreateSquarePads(fCogxyCanvas, fNstripX, fNstripY);
+    }
+    // DivideCanvas(fCogxyCanvas);
+    //  fSigmaCompCanvas->Divide(3,2);
+
+    fCanvasNames.push_back("Cogxy");
+    fCanvasList.push_back(fCogxyCanvas);
+
+    for (unsigned int lady{0}; lady < fNstripY; lady++)
+        for (unsigned int lad{0}; lad < fNstripX; lad++)
         {
-            TGNEsigmacompax[i] = new TGNumberEntry(Hframe, fSigmaCompAxis[i]);
-            TGNEsigmacompax[i]->Connect("ValueSet(Long_t)", "MyMainFrame", this, "UpdateSigmaCompAxes()");
+            fCogxyCanvas->cd(ConvertLad(lad));
+            bool IsY{IsLadY(lad)};
+            TH1F *frame = gPad->DrawFrame(fCogxyAxis[0], fCogxyAxis[2], fCogxyAxis[1], fCogxyAxis[3]);
+            frame->SetTitle(Form("Cog Y vs Cog X - Detector %d; CoG X (mm); CoG Y (mm)", lad));
+        
         }
 
-        for (int i = 0; i < 4; i++)
-        {
-            Hframe->AddFrame(minmax[i], TGLHleft);
-            Hframe->AddFrame(TGNEsigmacompax[i], TGLHleft);
-        }*/
+    TGHorizontalFrame *Hframe = new TGHorizontalFrame(Vframe, 200, 40);
+    //BuildAxisControls(Hframe, TGNEsigmacompax, fSigmaCompAxis, "UpdateSigmaCompAxes");
 
-        Vframe->AddFrame(fEsigmacompcanvas, TGLHexpandXexpandY);
+    Vframe->AddFrame(fEcogxycanvas, TGLHexpandXexpandY);
     Vframe->AddFrame(Hframe, TGLHexpandX);
     cframe->AddFrame(Vframe, TGLHexpandXexpandY);
 }
@@ -4949,7 +4963,7 @@ void MyMainFrame::RefreshDisplay()
             UpdatePedSubtDisplay(fEventCounter);
         if (current == 2)
             UpdatePedCnSubtDisplay(fEventCounter);
-     
+
         //  if (current==4) UpdateAdcPedCnSubtDisplay(fEventCounter);
         if (current == 3)
             UpdateSovernDisplay();
@@ -4965,7 +4979,7 @@ void MyMainFrame::RefreshDisplay()
             UpdateIntsDisplay(fEventCounter);
         if (current == 9)
             UpdateIntVsCogDisplay();
-        if (current == 11)
+        if (current == 12)
             UpdateFftDisplay();
     }
     fEventCounter++;
@@ -5193,7 +5207,6 @@ void MyMainFrame::UpdateIntsAxes(bool isy)
     DisplayInts();
 }
 
-
 void MyMainFrame::UpdateNclusAxes(bool isy)
 {
     UpdateAxes(isy, TGNEnclusax, fNclusAxis);
@@ -5212,7 +5225,6 @@ void MyMainFrame::UpdatePedSubtAxes(bool isy)
     UpdatePedSubtDisplay(fEventCounter, 1);
 }
 
-
 void MyMainFrame::UpdatePedCnSubtAxes(bool isy)
 {
     UpdateAxes(isy, TGNEpedcnsubtax, fPedCnSubtAxis);
@@ -5249,7 +5261,6 @@ void MyMainFrame::UpdateSigmaCompAxes(bool isy)
     DisplaySigmaCompar();
 }
 
-
 void MyMainFrame::UpdateExcludeEvents()
 {
 
@@ -5276,8 +5287,6 @@ void MyMainFrame::UpdateCNcutval()
     SetCNcut(cut);
 }
 
-
-
 string MyMainFrame::GetDateTimeString()
 {
 
@@ -6345,26 +6354,29 @@ void MyMainFrame::Reduction(bool dostats)
         ResetGraph(vgrclusters.at(ladder));
         if (dostats)
         {
-            vcog=BuildClusterStats(Scluster, ladder);
+            vcog = BuildClusterStats(Scluster, ladder);
             if (TGCBSaveClusters->IsDown())
             {
                 eventNumber_map.at(ladder) = fEventNumberDAQ;
                 frameCounter_map.at(ladder) = fFramaCounterDAQ;
             }
         }
-        //cout << "vcog size: " << vcog.size() << endl;
-        if (vcog.size()==1)
+        // cout << "vcog size: " << vcog.size() << endl;
+        if (vcog.size() == 1)
             vladcog.push_back(vcog.at(0));
     }
 
-    //cout << "vladcog size: " << vladcog.size() << endl;
+    // cout << "vladcog size: " << vladcog.size() << endl;
 
-    if ((fNstripY==1) and dostats) { // the last detector is Y, if it exists
-        if (vladcog.size()==(fNstripX+fNstripY)){
-            for (size_t lad{0}; lad<fNstripX; lad++) {
-                vh2CogXY.at(lad)->Fill(vladcog.at(lad)*0.025, vladcog.at(fNstripX)*0.4);
+    if ((fNstripY == 1) and dostats)
+    { // the last detector is Y, if it exists
+        if (vladcog.size() == (fNstripX + fNstripY))
+        {
+            for (size_t lad{0}; lad < fNstripX; lad++)
+            {
+                vh2CogXY.at(lad)->Fill(vladcog.at(lad) * 0.025, vladcog.at(fNstripX) * 0.4);
             }
-        }   
+        }
     }
 
     if (dostats and TGCBSaveClusters->IsDown())
@@ -6772,7 +6784,7 @@ void MyMainFrame::ComputeReduction()
 
         Reduction(true);
     }
-
+/*
     TCanvas *aCanvas{new TCanvas("aCanvas", "aCanvas", 1000, 800)};
     aCanvas->Divide(1, 2);
     aCanvas->cd(1);
@@ -6780,6 +6792,8 @@ void MyMainFrame::ComputeReduction()
     aCanvas->cd(2);
     vh2CogXY.at(1)->Draw("colz");
     aCanvas->Update();
+    */
+    DisplayCogxy();
 
     if (TGCBSaveClusters->IsDown())
     {
@@ -6846,6 +6860,63 @@ void MyMainFrame::DivideCanvas(TCanvas *c)
     }
 }
 
+void MyMainFrame::CreateSquarePads(TCanvas *c, int nx, int ny)
+{
+
+    c->Divide(nx, ny);
+    for (int i{0}; i < (nx + ny); i++)
+    {
+        c->cd(i + 1);
+        SetSquareAspect(gPad, nx, ny);
+    }
+}
+
+void MyMainFrame::SetSquareAspect(TVirtualPad *pad, int nx, int ny)
+{
+    // modified code from an old suggestion in root forum (https://root-forum.cern.ch/t/resizing-pads-created-with-c1-divide-nx-ny/3080)
+
+    double xlo, ylo, xup, yup;
+    double xmid, ymid, xwid, xwid2, ywid, ywid2;
+
+    pad->GetPadPar(xlo, ylo, xup, yup);
+    xwid = (xup - xlo) / 2.;
+    ywid = (yup - ylo) / 2.;
+    xmid = (xlo + xup) / 2.;
+    ymid = (ylo + yup) / 2.;
+
+    double Ww = pad->GetWw(); // parent pad dimension in pixels
+    double Wh = pad->GetWh(); // parent pad dimension in pixels
+    double WW = pad->GetWNDC(); // pad width in NDC
+    double HH = pad->GetHNDC(); // pad height in NDC
+
+    double xabsw = xwid * Ww;
+    double yabsw = ywid * Wh;
+
+    if ((Ww / nx) > (Wh / ny))
+    {
+
+        xabsw = Wh / ny;
+        yabsw = xabsw;
+    }
+    else
+    {
+        xabsw = Ww / nx;
+        yabsw = xabsw;
+    }
+
+    WW = xabsw / Ww;
+    HH = yabsw / Wh;
+
+    xwid2 = WW / 2.;
+    ywid2 = HH / 2.;
+
+    xlo = xmid - xwid2;
+    xup = xmid + xwid2;
+    ylo = ymid - ywid2;
+    yup = ymid + ywid2;
+    pad->SetPad(xlo, ylo, xup, yup);
+}
+
 bool MyMainFrame::InitCommunication()
 {
 
@@ -7241,7 +7312,8 @@ bool MyMainFrame::IsLadY(uint lad)
     return (GetLadNCH(lad) == 128);
 }
 
-void MyMainFrame::UpdateAxes(bool isy, TGNumberEntry *tgne[2][4], double (&fAxis)[2][4]) {
+void MyMainFrame::UpdateAxes(bool isy, TGNumberEntry *tgne[2][4], double (&fAxis)[2][4])
+{
     double minx = tgne[isy][0]->GetNumber();
     double maxx = tgne[isy][1]->GetNumber();
     double miny = tgne[isy][2]->GetNumber();
@@ -7264,7 +7336,8 @@ void MyMainFrame::UpdateAxes(bool isy, TGNumberEntry *tgne[2][4], double (&fAxis
         fAxis[isy][i] = tgne[isy][i]->GetNumber();
 }
 
-void MyMainFrame::BuildAxisControls(TGHorizontalFrame *Hframe, TGNumberEntry *TGNEax[2][4], double fAxis[2][4], string FunConnect) {
+void MyMainFrame::BuildAxisControls(TGHorizontalFrame *Hframe, TGNumberEntry *TGNEax[2][4], double fAxis[2][4], string FunConnect)
+{
     TGLabel *minmax[4];
     TGLabel *minmaxY[4];
 
@@ -7272,35 +7345,35 @@ void MyMainFrame::BuildAxisControls(TGHorizontalFrame *Hframe, TGNumberEntry *TG
     minmax[1] = new TGLabel(Hframe, "max x (X):");
     minmax[2] = new TGLabel(Hframe, "min y (X):");
     minmax[3] = new TGLabel(Hframe, "max y (X):");
-    if (fNstripY>0) {
-    minmaxY[0] = new TGLabel(Hframe, "min x (Y):");
-    minmaxY[1] = new TGLabel(Hframe, "max x (Y):");
-    minmaxY[2] = new TGLabel(Hframe, "min y (Y):");
-    minmaxY[3] = new TGLabel(Hframe, "max y (Y):");
+    if (fNstripY > 0)
+    {
+        minmaxY[0] = new TGLabel(Hframe, "min x (Y):");
+        minmaxY[1] = new TGLabel(Hframe, "max x (Y):");
+        minmaxY[2] = new TGLabel(Hframe, "min y (Y):");
+        minmaxY[3] = new TGLabel(Hframe, "max y (Y):");
     }
     for (int i = 0; i < 4; i++)
     {
         TGNEax[0][i] = new TGNumberEntry(Hframe, fAxis[0][i]);
-        TGNEax[0][i]->Connect("Modified()", "MyMainFrame", this, Form("%s(=0)",FunConnect.c_str()));
-        if (fNstripY>0) {
+        TGNEax[0][i]->Connect("Modified()", "MyMainFrame", this, Form("%s(=0)", FunConnect.c_str()));
+        if (fNstripY > 0)
+        {
             TGNEax[1][i] = new TGNumberEntry(Hframe, fAxis[1][i]);
-            TGNEax[1][i]->Connect("Modified()", "MyMainFrame", this, Form("%s(=1)",FunConnect.c_str()));
+            TGNEax[1][i]->Connect("Modified()", "MyMainFrame", this, Form("%s(=1)", FunConnect.c_str()));
         }
     }
 
-
     for (int i = 0; i < 4; i++)
     {
         Hframe->AddFrame(minmax[i], TGLHleft);
         Hframe->AddFrame(TGNEax[0][i], TGLHleft);
     }
-    if (fNstripY>0)
+    if (fNstripY > 0)
         for (int i = 0; i < 4; i++)
         {
             Hframe->AddFrame(minmaxY[i], TGLHleft);
             Hframe->AddFrame(TGNEax[1][i], TGLHleft);
         }
-
 }
 
 int DisPanOnline(uint nStripX = 2, uint nStripY = 1)
diff --git a/DisPanOnline.hxx b/DisPanOnline.hxx
index c49bda1..97bc1f3 100644
--- a/DisPanOnline.hxx
+++ b/DisPanOnline.hxx
@@ -164,8 +164,8 @@ private:
   TGCheckButton *TGCBDoCalib, *TGCBComputeCN, *TGCBNegativeSignals, *TGCBNegativeSignals1, *TGCBStripMode, *TGCBSaveClusters;
   TGNumberEntry *TGNEevent, *TGNEsuperimpose, *TGNEadcax[2][4], *TGNEpedsubtax[2][4], *TGNEpedax[2][4], *TGNEsrawax[2][4], *TGNEsigmaax[2][4], *TGNEpedcnsubtax[2][4], *TGNEpedcompax[2][4], *TGNEsigmacompax[2][4], *TGNEfftax[2][4], *TGNEChHiax[4], *TGNEChannel, *TGNEoccupancyax[2][4], *TGNEcogax[2][4], *TGNElensax[2][4], *TGNElenvscogax[2][4], *TGNEintvscogax[2][4], *TGNEintsax[2][4], *TGNEintsaxY[4], *TGNEintkax[4], *TGNEadcpedsubtax[4], *TGNEadcpedcnsubtax[4], *TGNEnclusax[2][4], *TGNEPhElCalax[4], *TGNEcncutval, *TGNEexcludeevents, *TGNEcluHighThresh, *TGNEcluHighThreshY, *TGNEcluLowThresh, *TGNEminValidIntegral, *TGNEpixelSearchParam, *TGNEpixelSearchRebin, *TGNEsovernax[2][4];
   TGNumberEntry *TGNEFPSigma, *TGNEFPThreshold, *TGNEFPNIter, *TGNEFPAverWindow, *TGNEFPRangeMin, *TGNEFPRangeMax, *TGNBufferSize, *TGCalNBufferSize, *TGNEspreadCut, *TGNFrameSize, *TGNEPedestalsLowCut, *TGNEPedestalsHighCut, *TGNERawNoiseLowCut, *TGNERawNoiseHighCut, *TGNERawNoiseHighCutY, *TGNENoiseLowCut, *TGNENoiseHighCut, *TGNENoiseHighCutY, *TGNPort, *TGNPortData;
-  TRootEmbeddedCanvas *fEadccanvas, *fEpedsubtcanvas, *fEadcpedsubtcanvas, *fEadcpedcnsubtcanvas, *fEpedcanvas, *fEsrawcanvas, *fEsigmacanvas, *fEpedcnsubtcanvas, *fEpedcompcanvas, *fEsigmacompcanvas, *fEfftcanvas, *fEChHicanvas, *fEoccupancycanvas, *fEcogcanvas, *fElenscanvas, *fElenvscogcanvas, *fEintvscogcanvas, *fEintscanvas, *fEintkcanvas, *fEncluscanvas, *fEPhElCalcanvas, *fEsoverncanvas;
-  TCanvas *fPedSubtCanvas, *fAdcPedSubtCanvas, *fAdcPedCnSubtCanvas, *fAdcCanvas, *fPedCanvas, *fSrawCanvas, *fSigmaCanvas, *fPedCnSubtCanvas, *fPedCompCanvas, *fSigmaCompCanvas, *fFftCanvas, *fChHiCanvas, *fOccupancyCanvas, *fCogCanvas, *fLensCanvas, *fLenVsCogCanvas, *fIntVsCogCanvas, *fIntsCanvas, *fNclusCanvas, *fPhElCalCanvas, *fSovernCanvas;
+  TRootEmbeddedCanvas *fEadccanvas, *fEpedsubtcanvas, *fEadcpedsubtcanvas, *fEadcpedcnsubtcanvas, *fEpedcanvas, *fEsrawcanvas, *fEsigmacanvas, *fEpedcnsubtcanvas, *fEpedcompcanvas, *fEsigmacompcanvas, *fEfftcanvas, *fEChHicanvas, *fEoccupancycanvas, *fEcogcanvas, *fElenscanvas, *fElenvscogcanvas, *fEintvscogcanvas, *fEintscanvas, *fEintkcanvas, *fEncluscanvas, *fEsoverncanvas, *fEcogxycanvas;
+  TCanvas *fPedSubtCanvas, *fAdcPedSubtCanvas, *fAdcPedCnSubtCanvas, *fAdcCanvas, *fPedCanvas, *fSrawCanvas, *fSigmaCanvas, *fPedCnSubtCanvas, *fPedCompCanvas, *fSigmaCompCanvas, *fFftCanvas, *fChHiCanvas, *fOccupancyCanvas, *fCogCanvas, *fLensCanvas, *fLenVsCogCanvas, *fIntVsCogCanvas, *fIntsCanvas, *fNclusCanvas, *fPhElCalCanvas, *fSovernCanvas, *fCogxyCanvas;
     string fCurrentPath, fCalPath, fCalRefPath, fImagePath, fFilePath, fFilename, fFilenameWOPath, fPathOfFile, fFilenameWOExt, fConfigFilename, fDAQfileName{"/home/herduser/Data/tests/testdaq.daq"}, fIPaddress{"192.168.1.1"}, fIPaddressData{"192.168.1.12"};
   TPad *fPhElSubPad;
   int fCurrTab;
@@ -213,7 +213,7 @@ private:
   int fDisplayBusy;
   int fClearDisplay;
   int fChannel, fChannel_min, fChannel_max;
-  double fAdcAxis[2][4], fPedSubtAxis[2][4], fAdcPedSubtAxis[4], fAdcPedCnSubtAxis[4], fPedAxis[2][4], fSrawAxis[2][4], fSigmaAxis[2][4], fPedCnSubtAxis[2][4], fPedCompAxis[2][4], fSigmaCompAxis[2][4], fFftAxis[2][4], fOccupancyAxis[2][4], fCogAxis[2][4], fLensAxis[2][4], fLenVsCogAxis[2][4], fIntVsCogAxis[2][4], fIntsAxis[2][4], fIntsAxisY[4], fNclusAxis[2][4], fPhElCalAxis[4], fSovernAxis[2][4];
+  double fAdcAxis[2][4], fPedSubtAxis[2][4], fAdcPedSubtAxis[4], fAdcPedCnSubtAxis[4], fCogxyAxis[4], fPedAxis[2][4], fSrawAxis[2][4], fSigmaAxis[2][4], fPedCnSubtAxis[2][4], fPedCompAxis[2][4], fSigmaCompAxis[2][4], fFftAxis[2][4], fOccupancyAxis[2][4], fCogAxis[2][4], fLensAxis[2][4], fLenVsCogAxis[2][4], fIntVsCogAxis[2][4], fIntsAxis[2][4], fIntsAxisY[4], fNclusAxis[2][4], fPhElCalAxis[4], fSovernAxis[2][4];
   vector<string> fvRefCalFile, fvRedCalFile;
   vector<string> fCanvasNames;
   vector<TCanvas *> fCanvasList;
@@ -277,10 +277,11 @@ public:
   void AddIntkTab(TGCompositeFrame *cframe);
   void AddPedSubtTab(TGCompositeFrame *cframe);
   void AddPedCnSubtTab(TGCompositeFrame *cframe);
-  
+  void AddCogxyTab(TGCompositeFrame *cframe);
+
   // void AddPhotoElCalibTab(TGCompositeFrame *cframe);
-  //void AddAdcPedSubtTab(TGCompositeFrame *cframe);
-  //void AddAdcPedCnSubtTab(TGCompositeFrame *cframe);
+  // void AddAdcPedSubtTab(TGCompositeFrame *cframe);
+  // void AddAdcPedCnSubtTab(TGCompositeFrame *cframe);
   void AddSrawTab(TGCompositeFrame *cframe);
   void AddSigmaTab(TGCompositeFrame *cframe);
   void AddPedTab(TGCompositeFrame *cframe);
@@ -473,6 +474,9 @@ public:
     bool IsLadY(uint lad);
     void BuildAxisControls(TGHorizontalFrame *Hframe, TGNumberEntry *TGNEax[2][4], double fAxis[2][4], string FunConnect);
     void UpdateAxes(bool isy, TGNumberEntry *tgne[2][4], double (&fAxis)[2][4]);
+    void CreateSquarePads(TCanvas *c, int nx, int ny);
+    void SetSquareAspect(TVirtualPad *pad, int nx, int ny);
+    void DisplayCogxy();
     ClassDef(MyMainFrame, 0);
     };
 #endif
-- 
GitLab


From 25c9a7fa3e486989649962f9d23fd14b15d4c6a3 Mon Sep 17 00:00:00 2001
From: PA <philipp.azzarello@gmail.com>
Date: Fri, 19 May 2023 18:33:23 +0200
Subject: [PATCH 3/7] some code cleaning of SetSquareAspect()

---
 DisPanOnline.cxx | 48 +++++++++++++++++++++---------------------------
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/DisPanOnline.cxx b/DisPanOnline.cxx
index a4d6f7d..abea760 100644
--- a/DisPanOnline.cxx
+++ b/DisPanOnline.cxx
@@ -6876,39 +6876,33 @@ void MyMainFrame::SetSquareAspect(TVirtualPad *pad, int nx, int ny)
     // modified code from an old suggestion in root forum (https://root-forum.cern.ch/t/resizing-pads-created-with-c1-divide-nx-ny/3080)
 
     double xlo, ylo, xup, yup;
-    double xmid, ymid, xwid, xwid2, ywid, ywid2;
+    //double xwid2, ywid2;
 
-    pad->GetPadPar(xlo, ylo, xup, yup);
-    xwid = (xup - xlo) / 2.;
-    ywid = (yup - ylo) / 2.;
-    xmid = (xlo + xup) / 2.;
-    ymid = (ylo + yup) / 2.;
+    pad->GetPadPar(xlo, ylo, xup, yup); // in NDC
+    //double xwid{(xup - xlo) / 2.};
+    //double ywid{(yup - ylo) / 2.};
+    double xmid {(xlo + xup) / 2.};
+    double ymid {(ylo + yup) / 2.};
 
-    double Ww = pad->GetWw(); // parent pad dimension in pixels
-    double Wh = pad->GetWh(); // parent pad dimension in pixels
-    double WW = pad->GetWNDC(); // pad width in NDC
-    double HH = pad->GetHNDC(); // pad height in NDC
+    double canw{static_cast <double>(pad->GetWw())}; // parent canvas dimension in pixels
+    double canh{static_cast <double> (pad->GetWh())}; // parent canvas dimension in pixels
+    //double WW{pad->GetWNDC()}; // pad width in NDC
+    //double HH{pad->GetHNDC()}; // pad height in NDC
 
-    double xabsw = xwid * Ww;
-    double yabsw = ywid * Wh;
+    double xabsw{0};
+    double yabsw{0};
 
-    if ((Ww / nx) > (Wh / ny))
-    {
-
-        xabsw = Wh / ny;
-        yabsw = xabsw;
-    }
-    else
-    {
-        xabsw = Ww / nx;
-        yabsw = xabsw;
-    }
+    if ((canw / nx) > (canh / ny))
+        xabsw = canh / ny;
+    else xabsw = canw / nx;
+      
+    yabsw = xabsw;
 
-    WW = xabsw / Ww;
-    HH = yabsw / Wh;
+    double WW {xabsw / canw};
+    double HH {yabsw / canh};
 
-    xwid2 = WW / 2.;
-    ywid2 = HH / 2.;
+    double xwid2 {WW / 2.};
+    double ywid2 {HH / 2.};
 
     xlo = xmid - xwid2;
     xup = xmid + xwid2;
-- 
GitLab


From a21e9e198ef4dfd3638cccbf8a678e31ce760c8d Mon Sep 17 00:00:00 2001
From: PA <philipp.azzarello@gmail.com>
Date: Tue, 30 May 2023 10:57:08 +0200
Subject: [PATCH 4/7] DAQ to root conversion improved for X01Y files

---
 DisPanOnline.cxx | 68 +++++++++++++++++++++++++++++++++++-------------
 DisPanOnline.hxx |  7 ++---
 exDict.cxx       |  2 +-
 3 files changed, 55 insertions(+), 22 deletions(-)

diff --git a/DisPanOnline.cxx b/DisPanOnline.cxx
index abea760..b797d2e 100644
--- a/DisPanOnline.cxx
+++ b/DisPanOnline.cxx
@@ -77,7 +77,7 @@ MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h, uint nStripX, ui
     fPedestalsHighCut = 4090;
     fRawNoiseLowCut = 0.5;
     fRawNoiseHighCut = 10.0;
-    fRawNoiseHighCutY = 45.0;
+    fRawNoiseHighCutY = 50.0;
 
     fNoiseLowCut = 1.0;
     fNoiseHighCut = 2.5;
@@ -960,7 +960,7 @@ void MyMainFrame::ChooseFile()
 
     cout << "fIniDir = " << fi.fIniDir << endl;
 
-    new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
+    new TGNewFileDialog(fClient->GetRoot(), this, kNFDOpen, &fi);
 
     if (fi.fFilename == 0)
         return;
@@ -988,10 +988,10 @@ void MyMainFrame::ChooseFile()
     // StartScope();
 }
 
-vector<ULong64_t> MyMainFrame::ReadFourWords(FILE *afile)
+vector<unsigned int> MyMainFrame::ReadFourWords(FILE *afile)
 {
     unsigned int adcValue{0};
-    vector<ULong64_t> fourWords;
+    vector<unsigned int> fourWords;
     unsigned char val1, val2, val3, val4;
 
     for (int i{0}; i < 4; i++)
@@ -1032,8 +1032,8 @@ int MyMainFrame::ConvertDaqToRootNew()
     outputFileName += ".root";
 
     unsigned short adcArray[fNTOTCH], channel_type{0};
-    unsigned int eventNumber{0}, frameType{0}, eventTag{0}, event{0}, adc1{0}, adc2{0};
-    ULong64_t frame_counter{0}, frame_counter_prev{0}, current_word{0};
+    unsigned int eventNumber{0}, frameType{0}, eventTag{0}, event{0}, adc1{0}, adc2{0}, current_word{0};
+    ULong64_t frame_counter{0}, frame_counter_prev{0};
     bool eventTagChanged{false};
     TFile *out_file = new TFile(outputFileName.c_str(), "recreate");
 
@@ -1046,7 +1046,7 @@ int MyMainFrame::ConvertDaqToRootNew()
 
     FILE *file = fopen(inputFileName.c_str(), "rb");
 
-    vector<ULong64_t> data;
+    vector<unsigned int> data;
 
     if (file == 0)
     {
@@ -1077,9 +1077,10 @@ int MyMainFrame::ConvertDaqToRootNew()
                 nchannels = 128;
             if (code1 == 0x59 && code0 != 0x33)
             {
+                nchannels = 2048 / 2;
                 nchannels += 128;
                 if (code0 == 0x32)
-                    nchannels += 2048 / 8;
+                    nchannels += 2048 / 2;
             }
             unsigned int first{0};
             unsigned int channel{0}, stripYchannel{0}, stripX0channel{0}, stripX1channel{0};
@@ -1098,7 +1099,7 @@ int MyMainFrame::ConvertDaqToRootNew()
                         adc2 = (data.at(j) >> 13) & 0x1FFF;
                         if (((data.at(j) >> 26) & 0x7) != eventTag)
                         {
-                            std::cout << "event tag changed within the event, skipping to the next one..." << std::endl;
+                            std::cout << "A: event tag changed within the event, skipping to the next one..." << std::endl;
                             std::cout << "event: " << event << std::endl;
                             std::cout << "eventTag: " << eventTag << std::endl;
                             std::cout << "new eventTag: " << ((data.at(j) >> 26) & 0x7) << std::endl;
@@ -1124,7 +1125,7 @@ int MyMainFrame::ConvertDaqToRootNew()
                             adc2 = (data.at(j) >> 13) & 0x1FFF;
                             if (((data.at(j) >> 26) & 0x7) != eventTag)
                             {
-                                std::cout << "event tag changed within the event, skipping to the next one..." << std::endl;
+                                std::cout << "B: event tag changed within the event, skipping to the next one..." << std::endl;
                                 std::cout << "event: " << event << std::endl;
                                 std::cout << "eventTag: " << eventTag << std::endl;
                                 std::cout << "new eventTag: " << ((data.at(j) >> 26) & 0x7) << std::endl;
@@ -1152,13 +1153,30 @@ int MyMainFrame::ConvertDaqToRootNew()
                         adc2 = (current_word >> 13) & 0x1FFF;
                         if (((current_word >> 26) & 0x7) != eventTag)
                         {
-                            std::cout << "event tag changed within the event, skipping to the next one..." << std::endl;
+                            std::cout << "C: event tag changed within the event, skipping to the next one..." << std::endl;
                             std::cout << "event: " << event << std::endl;
                             std::cout << "eventTag: " << eventTag << std::endl;
                             std::cout << "new eventTag: " << ((current_word >> 26) & 0x7) << std::endl;
                             std::cout << "(eventNumber + 1) % 8 = " << (eventNumber + 1) % 8 << std::endl;
                             std::cout << "eventNumber: " << eventNumber << std::endl;
+                            std::cout << "current word = 0x" << hex << current_word << "    adc1 = 0x" << adc1 << "    adc2 = 0x" << adc2 << dec << std::endl;
                             eventTagChanged = true;
+                            while (!feof(file)) // important in particular if we are reading a file not closed yet (i.e. while DAQ is still running)
+                            {
+                                cout << "current_word = 0x" << hex << current_word << "  last 8 bits: 0x" << ((current_word >> 24) & 0xFF) << dec << endl;
+                                //if (((current_word >> 24) & 0xFF) == 0x84) {
+                                //    std::cout << "0x84 found - breaking" << std::endl;
+                                //    break;
+                                //}
+                                // there is a bug in the FW: the CRC word might not be written correcly anymore once we have an uncomplete event (the 0x84 identifier is not written - for the least), and this happens also for all the successive events
+                                if (current_word == 0x80333333){ // as a replacement: we find the end frame word, then we read 3 more words
+                                    ReadSingleWord(file);
+                                    ReadSingleWord(file);
+                                    ReadSingleWord(file);
+                                    break;
+                                }
+                                current_word = ReadSingleWord(file);
+                            }
                             break;
                         }
                         if (code0 != 0x32 || channel_type == 0)
@@ -1168,7 +1186,6 @@ int MyMainFrame::ConvertDaqToRootNew()
                             channel = (2 * stripX0adc + 1) * 2048 / 8 + stripX0channel;
                             adcArray[first + channel] = adc2;
                             stripX0adc++;
-                            i = stripYchannel + stripX0channel + 1;
                             if (stripX0adc > 3)
                             {
                                 stripX0adc = 0;
@@ -1188,21 +1205,25 @@ int MyMainFrame::ConvertDaqToRootNew()
                                 stripX1channel++;
                             }
                         }
-                        if (code0 == 0x32)
-                            i = stripYchannel + stripX0channel + stripX1channel + 2;
                     }
                     else
                     {
                         adc1 = current_word & 0x3FFFFFF;
                         if (((current_word >> 26) & 0x7) != eventTag)
                         {
-                            std::cout << "event tag changed within the event, skipping to the next one..." << std::endl;
+                            std::cout << "D: event tag changed within the event, skipping to the next one..." << std::endl;
                             std::cout << "event: " << event << std::endl;
                             std::cout << "eventTag: " << eventTag << std::endl;
                             std::cout << "new eventTag: " << ((current_word >> 26) & 0x7) << std::endl;
                             std::cout << "(eventNumber + 1) % 8 = " << (eventNumber + 1) % 8 << std::endl;
                             std::cout << "eventNumber: " << eventNumber << std::endl;
                             eventTagChanged = true;
+                            while (1)
+                            {
+                                if (current_word >> 24 == 0x84)
+                                    break;
+                                current_word = ReadSingleWord(file);
+                            }
                             break;
                         }
                         if (code0 != 0x32)
@@ -1227,7 +1248,7 @@ int MyMainFrame::ConvertDaqToRootNew()
                         adc1 = data.at(j) & 0x3FFFFFF;
                         if (((data.at(j) >> 26) & 0x7) != eventTag)
                         {
-                            std::cout << "event tag changed within the event, skipping to the next one..." << std::endl;
+                            std::cout << "E: event tag changed within the event, skipping to the next one..." << std::endl;
                             std::cout << "event: " << event << std::endl;
                             std::cout << "eventTag: " << eventTag << std::endl;
                             std::cout << "new eventTag: " << ((data.at(j) >> 26) & 0x7) << std::endl;
@@ -1544,7 +1565,7 @@ void MyMainFrame::ChoseConfigFile()
 {
 
     TGFileInfo fi;
-    new TGFileDialog(fClient->GetRoot(), this, kFDOpen, &fi);
+    new TGNewFileDialog(fClient->GetRoot(), this, kNFDOpen, &fi);
     if (fi.fFilename == 0)
         return;
     if (!fConfigFilename.empty())
@@ -3255,6 +3276,16 @@ void MyMainFrame::DisplayCogxy() {
     for (int det{0}; det < fNstripX; det++) {
         c->cd(det+1);
         vh2CogXY.at(det)->Draw("colz");
+        TPaveStats *St = (TPaveStats*)(vh2CogXY.at(det))->FindObject("stats");
+        if (St!=0) {
+            St->SetFillColorAlpha(kWhite, 0.3);
+            double WidthNDC{St->GetX2NDC()-St->GetX1NDC()};
+            double HeightDNC{St->GetY2NDC() - St->GetY1NDC()};
+            St->SetX1NDC(0.11);
+            St->SetX2NDC(0.11 + WidthNDC);
+            St->SetY2NDC(0.88);
+            St->SetY1NDC(0.88 - HeightDNC);
+        }
     }
     c->Update();
 }
@@ -3402,7 +3433,8 @@ void MyMainFrame::DisplayInts()
         flangau->SetParameter(1, flandau->GetParameter(1));
         flangau->SetParameter(2, flandau->GetParameter(2));
         if (IsY)
-            flangau->SetRange(flandau->GetParameter(1) - 100, flandau->GetParameter(1) + 250);
+            //flangau->SetRange(flandau->GetParameter(1) - 100, flandau->GetParameter(1) + 250);
+            flangau->SetRange(150, 450);
         else
             flangau->SetRange(flandau->GetParameter(1) - 10, flandau->GetParameter(1) + 80);
         his->Fit(flangau, "RM");
diff --git a/DisPanOnline.hxx b/DisPanOnline.hxx
index 97bc1f3..d08bc14 100644
--- a/DisPanOnline.hxx
+++ b/DisPanOnline.hxx
@@ -10,7 +10,7 @@
 #include <TRootEmbeddedCanvas.h>
 // #include <RQ_OBJECT.h>
 #include <TGTab.h>
-#include <TGFileDialog.h>
+//#include <TGFileDialog.h>
 #include <TGTab.h>
 #include <TFile.h>
 #include <TText.h>
@@ -62,7 +62,8 @@
 #include "TGComboBox.h"
 #include "TBrowser.h"
 #include "TLatex.h"
-
+#include "TPaveStats.h"
+#include "TGNewFileDialog.hxx"
 #include "GpioDaq/GpioDaq.hxx"
 #include "FitUdpServer/FitUdpServer.hxx"
 #include "Detector.hpp"
@@ -465,7 +466,7 @@ public:
     void UpdateNoiseHighCut();
     void UpdateNoiseHighCutY();
     void AddChannelHistoTab(TGCompositeFrame *cframe);
-    vector<ULong64_t> ReadFourWords(FILE *afile);
+    vector<unsigned int> ReadFourWords(FILE *afile);
     ULong64_t ReadSingleWord(FILE *afile);
     int ConvertDaqToRootNew();
     bool ComputeCNoneVA(uint va, uint lad, double fMaj, int mask_channelOK);
diff --git a/exDict.cxx b/exDict.cxx
index 74cc12e..7423066 100644
--- a/exDict.cxx
+++ b/exDict.cxx
@@ -54,7 +54,7 @@ namespace ROOT {
       ::MyMainFrame *ptr = nullptr;
       static ::TVirtualIsAProxy* isa_proxy = new ::TInstrumentedIsAProxy< ::MyMainFrame >(nullptr);
       static ::ROOT::TGenericClassInfo 
-         instance("MyMainFrame", ::MyMainFrame::Class_Version(), "DisPanOnline.hxx", 148,
+         instance("MyMainFrame", ::MyMainFrame::Class_Version(), "DisPanOnline.hxx", 149,
                   typeid(::MyMainFrame), ::ROOT::Internal::DefineBehavior(ptr, ptr),
                   &::MyMainFrame::Dictionary, isa_proxy, 16,
                   sizeof(::MyMainFrame) );
-- 
GitLab


From c3738a85af0a5d8ef7a135bd3bfb88afc9e7bf4c Mon Sep 17 00:00:00 2001
From: PA <philipp.azzarello@gmail.com>
Date: Wed, 31 May 2023 17:22:07 +0200
Subject: [PATCH 5/7] DAQ to root conversion with additional imrpovements in
 case of corrupt files

---
 DisPanOnline.cxx | 60 ++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 53 insertions(+), 7 deletions(-)

diff --git a/DisPanOnline.cxx b/DisPanOnline.cxx
index b797d2e..613e023 100644
--- a/DisPanOnline.cxx
+++ b/DisPanOnline.cxx
@@ -1032,8 +1032,12 @@ int MyMainFrame::ConvertDaqToRootNew()
     outputFileName += ".root";
 
     unsigned short adcArray[fNTOTCH], channel_type{0};
-    unsigned int eventNumber{0}, frameType{0}, eventTag{0}, event{0}, adc1{0}, adc2{0}, current_word{0};
+    unsigned int eventNumber{0}, frameType{0}, eventTag{0}, event{0}, adc1{0}, adc2{0}, current_word{0}, big_frame_counter{0}, MSB{0}, OldMSB{0};
     ULong64_t frame_counter{0}, frame_counter_prev{0};
+    Double_t eventTime[2];
+    Double_t oldTime{0};
+    eventTime[0]=0;
+    eventTime[1] = 0;
     bool eventTagChanged{false};
     TFile *out_file = new TFile(outputFileName.c_str(), "recreate");
 
@@ -1043,6 +1047,7 @@ int MyMainFrame::ConvertDaqToRootNew()
     T->Branch("frameType", &frameType, "frameType/i");
     T->Branch("eventTag", &eventTag, "eventTag/i");
     T->Branch("nframe", &frame_counter, "frame_counter/l");
+    T->Branch("eventTime", eventTime, "eventTimeSt/D:deltaTime/D");
 
     FILE *file = fopen(inputFileName.c_str(), "rb");
 
@@ -1163,7 +1168,7 @@ int MyMainFrame::ConvertDaqToRootNew()
                             eventTagChanged = true;
                             while (!feof(file)) // important in particular if we are reading a file not closed yet (i.e. while DAQ is still running)
                             {
-                                cout << "current_word = 0x" << hex << current_word << "  last 8 bits: 0x" << ((current_word >> 24) & 0xFF) << dec << endl;
+                                cout << "C: current_word = 0x" << hex << current_word << "  last 8 bits: 0x" << ((current_word >> 24) & 0xFF) << dec << endl;
                                 //if (((current_word >> 24) & 0xFF) == 0x84) {
                                 //    std::cout << "0x84 found - breaking" << std::endl;
                                 //    break;
@@ -1218,10 +1223,19 @@ int MyMainFrame::ConvertDaqToRootNew()
                             std::cout << "(eventNumber + 1) % 8 = " << (eventNumber + 1) % 8 << std::endl;
                             std::cout << "eventNumber: " << eventNumber << std::endl;
                             eventTagChanged = true;
-                            while (1)
+                            while (!feof(file))
                             {
-                                if (current_word >> 24 == 0x84)
+                                //if (current_word >> 24 == 0x84)
+                                //    break;
+                                //current_word = ReadSingleWord(file);
+                                cout << "D: current_word = 0x" << hex << current_word << "  last 8 bits: 0x" << ((current_word >> 24) & 0xFF) << dec << endl;
+                                if (current_word == 0x80333333)
+                                { // as a replacement: we find the end frame word, then we read 3 more words
+                                    ReadSingleWord(file);
+                                    ReadSingleWord(file);
+                                    ReadSingleWord(file);
                                     break;
+                                }
                                 current_word = ReadSingleWord(file);
                             }
                             break;
@@ -1268,9 +1282,22 @@ int MyMainFrame::ConvertDaqToRootNew()
         }
         else if (data.at(0) == FRAME_END)
         {
-            frame_counter = (data.at(1) & 0x3F) << 31;
-            frame_counter += data.at(2) & 0x7FFFFFFF;
-            frame_counter_prev = frame_counter;
+            MSB=(data.at(1) & 0x3F);
+            if (OldMSB>MSB){
+                cout << hex << "oldmsb =0x" << OldMSB << " MSB=0x" << MSB << dec << endl;
+                big_frame_counter++;
+            }
+            OldMSB = MSB;
+            frame_counter = ((ULong64_t) (data.at(1)) & 0x3F) << 31; // !!! very nasty !!! you need to force the conversion to ULong64_t else bits >31 will be cut (i.e. in this case all of them...).
+            frame_counter += (data.at(2) & 0x7FFFFFFF);
+            //if (frame_counter_prev > frame_counter)
+            //    big_frame_counter++;
+            //frame_counter_prev = frame_counter;
+            Long64_t TScounter= frame_counter+ ((long int)((long int)((big_frame_counter*0x40)) << 31));
+            eventTime[0] = TScounter * (1./50e6); // Clock freq is 50 MHz
+            eventTime[1] = eventTime[0]-oldTime;
+            oldTime = eventTime[0];
+            //cout << "trigger = " << data.at(3) << "  bigcnt = " << big_frame_counter << "  " << TScounter << "   " << eventTime[0] << endl;
             if (!eventTagChanged)
             {
                 T->Fill();
@@ -1278,6 +1305,25 @@ int MyMainFrame::ConvertDaqToRootNew()
             }
             event++;
             // counter = 0;
+        } else {
+            cout << "exception: 0x" << data.at(0) << "  0x" << data.at(1) << "  0x" << data.at(2) << "  0x" << data.at(3) << endl;
+            cout << "we try to locate again the end frame" << endl;
+            current_word = ReadSingleWord(file);
+            while (!feof(file))
+            {
+                // if (current_word >> 24 == 0x84)
+                //     break;
+                // current_word = ReadSingleWord(file);
+                cout << "Excpt: current_word = 0x" << hex << current_word << "  last 8 bits: 0x" << ((current_word >> 24) & 0xFF) << dec << endl;
+                if (current_word == 0x80333333)
+                { // as a replacement: we find the end frame word, then we read 3 more words
+                    ReadSingleWord(file);
+                    ReadSingleWord(file);
+                    ReadSingleWord(file);
+                    break;
+                }
+                current_word = ReadSingleWord(file);
+            }
         }
     }
     T->Write(0, TObject::kOverwrite);
-- 
GitLab


From 4689158dfe7e751122e93e17638bd07c408de398 Mon Sep 17 00:00:00 2001
From: PA <philipp.azzarello@gmail.com>
Date: Thu, 1 Jun 2023 20:42:54 +0200
Subject: [PATCH 6/7] some cleaning in the messages of DAQ to root conversion

---
 DisPanOnline.cxx | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/DisPanOnline.cxx b/DisPanOnline.cxx
index 613e023..25459fb 100644
--- a/DisPanOnline.cxx
+++ b/DisPanOnline.cxx
@@ -1059,11 +1059,21 @@ int MyMainFrame::ConvertDaqToRootNew()
         return 1;
     }
 
+    // to understand progress, let's find the file size
+    fseek(file, 0, SEEK_END);
+    long int FileSize{ftell(file)};
+    rewind(file);
+    int FileProgressStep{0};
+
     while (1)
     {
         if (feof(file))
             break;
-
+        double FileProgress{(double)(ftell(file))/FileSize*100};
+        if (FileProgress>=FileProgressStep*5) {
+            cout << "File conversion progress: " << round(FileProgress) << " %"<< endl;
+            FileProgressStep++;
+        }
         data.clear();
         data = ReadFourWords(file);
 
@@ -1228,7 +1238,7 @@ int MyMainFrame::ConvertDaqToRootNew()
                                 //if (current_word >> 24 == 0x84)
                                 //    break;
                                 //current_word = ReadSingleWord(file);
-                                cout << "D: current_word = 0x" << hex << current_word << "  last 8 bits: 0x" << ((current_word >> 24) & 0xFF) << dec << endl;
+                                //cout << "D: current_word = 0x" << hex << current_word << "  last 8 bits: 0x" << ((current_word >> 24) & 0xFF) << dec << endl;
                                 if (current_word == 0x80333333)
                                 { // as a replacement: we find the end frame word, then we read 3 more words
                                     ReadSingleWord(file);
@@ -1284,7 +1294,7 @@ int MyMainFrame::ConvertDaqToRootNew()
         {
             MSB=(data.at(1) & 0x3F);
             if (OldMSB>MSB){
-                cout << hex << "oldmsb =0x" << OldMSB << " MSB=0x" << MSB << dec << endl;
+                //cout << hex << "oldmsb =0x" << OldMSB << " MSB=0x" << MSB << dec << endl;
                 big_frame_counter++;
             }
             OldMSB = MSB;
@@ -1306,7 +1316,9 @@ int MyMainFrame::ConvertDaqToRootNew()
             event++;
             // counter = 0;
         } else {
-            cout << "exception: 0x" << data.at(0) << "  0x" << data.at(1) << "  0x" << data.at(2) << "  0x" << data.at(3) << endl;
+            if (feof(file))
+                break;
+            cout << "Event " << eventNumber <<  " :  Exception: 0x" << data.at(0) << "  0x" << data.at(1) << "  0x" << data.at(2) << "  0x" << data.at(3) << endl;
             cout << "we try to locate again the end frame" << endl;
             current_word = ReadSingleWord(file);
             while (!feof(file))
@@ -1314,7 +1326,7 @@ int MyMainFrame::ConvertDaqToRootNew()
                 // if (current_word >> 24 == 0x84)
                 //     break;
                 // current_word = ReadSingleWord(file);
-                cout << "Excpt: current_word = 0x" << hex << current_word << "  last 8 bits: 0x" << ((current_word >> 24) & 0xFF) << dec << endl;
+                //cout << "Excpt: current_word = 0x" << hex << current_word << "  last 8 bits: 0x" << ((current_word >> 24) & 0xFF) << dec << endl;
                 if (current_word == 0x80333333)
                 { // as a replacement: we find the end frame word, then we read 3 more words
                     ReadSingleWord(file);
@@ -2741,7 +2753,7 @@ void MyMainFrame::ComputePedestals(int startevent)
         if (PedCnt % 100 == 0)
         {
             // fTGHPBprogress->SetPosition((PedCnt*100.)/NPEDEVENTS); // in linux, this is enough to update the display of the progress bar
-            cout << "Progress: " << (PedCnt * 100.) / NPEDEVENTS << " %" << endl;
+            cout << "Progress: " << round((PedCnt * 100.) / NPEDEVENTS) << " %" << endl;
             // fTGHPBprogress->ShowPosition(); // in mac, you need to add this
             // gSystem->ProcessEvents(); // and this.
         }
@@ -2811,7 +2823,7 @@ bool MyMainFrame::ComputePedestals2(int startevent, double pedcut)
             if ((current_ch) % 40 == 0)
             {
                 // fTGHPBprogress->SetPosition((ch*100.)/fNTOTCH);
-                cout << "Progress: " << ((current_ch)*100.) / fNTOTCH << " %" << endl;
+                cout << "Progress: " << round(((current_ch)*100.) / fNTOTCH) << " %" << endl;
                 // fTGHPBprogress->ShowPosition();
                 // gSystem->ProcessEvents();
             }
@@ -2892,7 +2904,7 @@ void MyMainFrame::ComputeRawSigmas(int startevent)
         if (sRawCnt % 100 == 0)
         {
             // fTGHPBprogress->SetPosition((sRawCnt*100.)/NSRAWEVENTS); // in linux, this is enough to update the display of the progress bar
-            cout << "Progress: " << (sRawCnt * 100.) / NSRAWEVENTS << " %" << endl;
+            cout << "Progress: " << round((sRawCnt * 100.) / NSRAWEVENTS) << " %" << endl;
             // fTGHPBprogress->ShowPosition(); // in mac, you need to add this
             // gSystem->ProcessEvents(); // and this.
         }
@@ -2977,7 +2989,7 @@ void MyMainFrame::ComputeSigmas(int startevent, int maskCN)
         if (SigmaCnt % 100 == 0)
         {
             // fTGHPBprogress->SetPosition((SigmaCnt*100.)/NSIGEVENTS); // in linux, this is enough to update the display of the progress bar
-            std::cout << "Progress: " << (SigmaCnt * 100.) / NSIGEVENTS << " %" << std::endl;
+            std::cout << "Progress: " << round((SigmaCnt * 100.) / NSIGEVENTS) << " %" << std::endl;
             // fTGHPBprogress->ShowPosition(); // in mac, you need to add this
             // gSystem->ProcessEvents(); // and this.
         }
@@ -6800,7 +6812,7 @@ void MyMainFrame::ComputeReduction()
         if (event % (fNevents / 20) == 0)
         {
             // fTGHPBprogress->SetPosition((event*100.)/fNevents); // in linux, this is enough to update the display of the progress bar
-            std::cout << "Progress: " << (event * 100.) / fNevents << " %" << endl;
+            std::cout << "Progress: " << round((event * 100.) / fNevents) << " %" << endl;
             // fTGHPBprogress->ShowPosition(); // in mac, you need to add this
             // gSystem->ProcessEvents(); // and this.
             // fTGHPBprogress->DoRedraw(); // let's try this one - does not work, it is a protected method
-- 
GitLab


From 61ff6d58e8b6cf613d9dd9305edbdf0bbb10ecf3 Mon Sep 17 00:00:00 2001
From: PA <philipp.azzarello@gmail.com>
Date: Fri, 2 Jun 2023 16:48:38 +0200
Subject: [PATCH 7/7] Added the compilation files for TGNewFileDialog

---
 TGNewFileDialog.cxx       | 823 ++++++++++++++++++++++++++++++++++++++
 TGNewFileDialog.hxx       | 102 +++++
 TGNewFileDialog_LinkDef.h |  10 +
 compileDialog.sh          |   2 +
 4 files changed, 937 insertions(+)
 create mode 100644 TGNewFileDialog.cxx
 create mode 100644 TGNewFileDialog.hxx
 create mode 100644 TGNewFileDialog_LinkDef.h
 create mode 100644 compileDialog.sh

diff --git a/TGNewFileDialog.cxx b/TGNewFileDialog.cxx
new file mode 100644
index 0000000..5688309
--- /dev/null
+++ b/TGNewFileDialog.cxx
@@ -0,0 +1,823 @@
+// @(#)root/gui:$Id: f3cd439bd51d763ffd53693e89c42b2eaa27c520 $
+// Author: Fons Rademakers   20/01/98
+
+/*************************************************************************
+ * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
+ * All rights reserved.                                                  *
+ *                                                                       *
+ * For the licensing terms see $ROOTSYS/LICENSE.                         *
+ * For the list of contributors see $ROOTSYS/README/CREDITS.             *
+ *************************************************************************/
+
+/** \class TGNewFileDialog
+    \ingroup guiwidgets
+
+This class creates a file selection dialog. It contains a combo box
+to select the desired directory. A listview with the different
+files in the current directory and a combo box with which you can
+select a filter (on file extensions).
+When creating a file dialog one passes a pointer to a TGFileInfo
+object. In this object you can set the fFileTypes and fIniDir to
+specify the list of file types for the filter combo box and the
+initial directory. When the TGFileDialog ctor returns the selected
+file name can be found in the TGFileInfo::fFilename field and the
+selected directory in TGFileInfo::fIniDir. The fFilename and
+fIniDir are deleted by the TGFileInfo dtor.
+
+*/
+
+#include "TGNewFileDialog.hxx"
+#include "TGLabel.h"
+#include "TGTextEntry.h"
+#include "TGComboBox.h"
+#include "TGListView.h"
+#include "TGFSContainer.h"
+#include "TGFSComboBox.h"
+#include "TGMsgBox.h"
+#include "TGInputDialog.h"
+#include "TSystem.h"
+#include "TObjString.h"
+#include "strlcpy.h"
+
+#include <sys/stat.h>
+
+enum ENewFileFialog
+{
+    kIDF_CDUP,
+    kIDF_NEW_FOLDER,
+    kIDF_LIST,
+    kIDF_DETAILS,
+    kIDF_CHECKB,
+    kIDF_FSLB,
+    kIDF_FTYPESLB,
+    kIDF_OK,
+    kIDF_CANCEL
+};
+
+static const char *gDefTypes[] = {"All files", "*",
+                                  "ROOT files", "*.root",
+                                  "ROOT macros", "*.C",
+                                  nullptr, nullptr};
+
+static TGFileInfo gInfo;
+
+ClassImp(TGNewFileDialog);
+
+////////////////////////////////////////////////////////////////////////////////
+/// TGFileInfo Destructor.
+/*
+TGFileInfo::~TGFileInfo()
+{
+    delete[] fFilename;
+    delete[] fIniDir;
+    DeleteFileNamesList();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Delete file names list
+
+void TGFileInfo::DeleteFileNamesList()
+{
+    if (fFileNamesList)
+    {
+        fFileNamesList->Delete();
+        delete fFileNamesList;
+        fFileNamesList = nullptr;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Turn on/off multiple selection.
+
+void TGFileInfo::SetMultipleSelection(Bool_t option)
+{
+    if (fMultipleSelection != option)
+    {
+        fMultipleSelection = option;
+        DeleteFileNamesList();
+        if (fMultipleSelection)
+            fFileNamesList = new TList();
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Set file name
+
+void TGFileInfo::SetFilename(const char *fname)
+{
+    delete[] fFilename;
+    fFilename = fname ? StrDup(fname) : nullptr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Set directory name
+
+void TGFileInfo::SetIniDir(const char *inidir)
+{
+    delete[] fIniDir;
+    fIniDir = inidir ? StrDup(inidir) : nullptr;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Create a file selection dialog. Depending on the dlg_type it can be
+/// used for opening or saving a file.
+/// About the first two arguments, p is the parent Window, usually the
+/// desktop (root) window, and main is the main (TGMainFrame) application
+/// window (the one opening the dialog), onto which the dialog is
+/// usually centered, and which is waiting for it to close.
+*/
+TGNewFileDialog::TGNewFileDialog(const TGWindow *p, const TGWindow *main,
+                           ENewFileDialogMode dlg_type, TGFileInfo *file_info) : TGTransientFrame(p, main, 10, 10, kVerticalFrame), fTbfname(0), fName(0),
+                                                                              fTypes(0), fTreeLB(0), fCdup(0), fNewf(0), fList(0), fDetails(0), fCheckB(0),
+                                                                              fPcdup(0), fPnewf(0), fPlist(0), fPdetails(0), fOk(0), fCancel(0), fFv(0),
+                                                                              fFc(0), fFileInfo(0), fDlgType(dlg_type)
+{
+    SetCleanup(kDeepCleanup);
+    Connect("CloseWindow()", "TGNewFileDialog", this, "CloseWindow()");
+    DontCallClose();
+
+    int i;
+
+    if (!p && !main)
+    {
+        MakeZombie();
+        return;
+    }
+    if (!file_info)
+    {
+        Error("TGNewFileDialog", "file_info argument not set");
+        fFileInfo = &gInfo;
+        fFileInfo->SetIniDir(nullptr);
+        fFileInfo->SetFilename(nullptr);
+        fFileInfo->fFileTypeIdx = 0;
+    }
+    else
+        fFileInfo = file_info;
+
+    if (!fFileInfo->fFileTypes)
+        fFileInfo->fFileTypes = gDefTypes;
+
+    if (!fFileInfo->fIniDir)
+        fFileInfo->SetIniDir(".");
+
+    TGHorizontalFrame *fHtop = new TGHorizontalFrame(this, 10, 10);
+
+    //--- top toolbar elements
+    TGLabel *fLookin = new TGLabel(fHtop, new TGHotString((dlg_type == kNFDSave || dlg_type == kNDSave)
+                                                              ? "S&ave in:"
+                                                              : "&Look in:"));
+    fTreeLB = new TGFSComboBox(fHtop, kIDF_FSLB);
+    fTreeLB->Associate(this);
+
+    fPcdup = fClient->GetPicture("tb_uplevel.xpm");
+    fPnewf = fClient->GetPicture("tb_newfolder.xpm");
+    fPlist = fClient->GetPicture("tb_list.xpm");
+    fPdetails = fClient->GetPicture("tb_details.xpm");
+
+    if (!(fPcdup && fPnewf && fPlist && fPdetails))
+        Error("TGNewFileDialog", "missing toolbar pixmap(s).\n");
+
+    fCdup = new TGPictureButton(fHtop, fPcdup, kIDF_CDUP);
+    fNewf = new TGPictureButton(fHtop, fPnewf, kIDF_NEW_FOLDER);
+    fList = new TGPictureButton(fHtop, fPlist, kIDF_LIST);
+    fDetails = new TGPictureButton(fHtop, fPdetails, kIDF_DETAILS);
+
+    fCdup->SetStyle(gClient->GetStyle());
+    fNewf->SetStyle(gClient->GetStyle());
+    fList->SetStyle(gClient->GetStyle());
+    fDetails->SetStyle(gClient->GetStyle());
+
+    fCdup->SetToolTipText("Up One Level");
+    fNewf->SetToolTipText("Create New Folder");
+    fList->SetToolTipText("List");
+    fDetails->SetToolTipText("Details");
+
+    fCdup->Associate(this);
+    fNewf->Associate(this);
+    fList->Associate(this);
+    fDetails->Associate(this);
+
+    fList->AllowStayDown(kTRUE);
+    fDetails->AllowStayDown(kTRUE);
+
+    fTreeLB->Resize(200, fTreeLB->GetDefaultHeight());
+
+    fHtop->AddFrame(fLookin, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
+    fHtop->AddFrame(fTreeLB, new TGLayoutHints(kLHintsLeft | kLHintsExpandY, 3, 0, 2, 2));
+    fHtop->AddFrame(fCdup, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
+    fHtop->AddFrame(fNewf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
+    fHtop->AddFrame(fList, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 3, 0, 2, 2));
+    fHtop->AddFrame(fDetails, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 8, 2, 2));
+
+    if (dlg_type == kNFDSave)
+    {
+        fCheckB = new TGCheckButton(fHtop, "&Overwrite", kIDF_CHECKB);
+        fCheckB->SetToolTipText("Overwrite a file without displaying a message if selected");
+    }
+    else if (dlg_type == kNFDOpen)
+    {
+        fCheckB = new TGCheckButton(fHtop, "&Multiple files", kIDF_CHECKB);
+        fCheckB->SetToolTipText("Allows multiple file selection when SHIFT is pressed");
+        fCheckB->Connect("Toggled(Bool_t)", "TGFileInfo", fFileInfo, "SetMultipleSelection(Bool_t)");
+    }
+    if (fCheckB)
+    {
+        fHtop->AddFrame(fCheckB, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
+        fCheckB->SetOn(fFileInfo->fMultipleSelection);
+    }
+    AddFrame(fHtop, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 4, 3, 1));
+
+    //--- file view
+
+    fFv = new TGListView(this, 600, 161);
+
+    fFc = new TGFileContainer(fFv->GetViewPort(),
+                              10, 10, kHorizontalFrame, fgWhitePixel);
+    fFc->Associate(this);
+
+    fFv->GetViewPort()->SetBackgroundColor(fgWhitePixel);
+    fFv->SetContainer(fFc);
+    fFv->SetViewMode(kLVList);
+    //fFv->SetViewMode(kLVDetails);
+    fFv->SetIncrements(1, 19); // set vertical scroll one line height at a time
+
+    TGTextButton **buttons = fFv->GetHeaderButtons();
+    if (buttons)
+    {
+        buttons[0]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByName)");
+        buttons[1]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByType)");
+        buttons[2]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortBySize)");
+        buttons[3]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByOwner)");
+        buttons[4]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByGroup)");
+        buttons[5]->Connect("Clicked()", "TGFileContainer", fFc, "Sort(=kSortByDate)");
+    }
+
+    fFc->SetFilter(fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx + 1]);
+    //fFc->Sort(kSortByName);
+    fFc->Sort(kSortByDate);
+    fFc->ChangeDirectory(fFileInfo->fIniDir);
+    fFc->SetMultipleSelection(fFileInfo->fMultipleSelection);
+    fTreeLB->Update(fFc->GetDirectory());
+
+    //fList->SetState(kButtonEngaged);
+    fDetails->SetState(kButtonEngaged);
+
+    AddFrame(fFv, new TGLayoutHints(kLHintsTop | kLHintsExpandX | kLHintsExpandY, 4, 4, 3, 1));
+
+    if (dlg_type == kNFDOpen)
+    {
+        fCheckB->Connect("Toggled(Bool_t)", "TGFileContainer", fFc, "SetMultipleSelection(Bool_t)");
+        fCheckB->Connect("Toggled(Bool_t)", "TGFileContainer", fFc, "UnSelectAll()");
+    }
+
+    //--- file name and types
+
+    TGHorizontalFrame *fHf = new TGHorizontalFrame(this, 10, 10);
+
+    TGVerticalFrame *fVf = new TGVerticalFrame(fHf, 10, 10);
+
+    TGHorizontalFrame *fHfname = new TGHorizontalFrame(fVf, 10, 10);
+
+    TGLabel *fLfname = new TGLabel(fHfname, new TGHotString(
+                                                (dlg_type == kNDOpen || dlg_type == kNDSave) ? "Folder &name:" : "File &name:"));
+    fTbfname = new TGTextBuffer(1034);
+    fName = new TGTextEntry(fHfname, fTbfname);
+    fName->Resize(230, fName->GetDefaultHeight());
+    fName->Associate(this);
+
+    fHfname->AddFrame(fLfname, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
+    fHfname->AddFrame(fName, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 20, 2, 2));
+
+    fVf->AddFrame(fHfname, new TGLayoutHints(kLHintsLeft | kLHintsCenterY | kLHintsExpandX));
+
+    TGHorizontalFrame *fHftype = new TGHorizontalFrame(fVf, 10, 10);
+
+    TGLabel *fLftypes = new TGLabel(fHftype, new TGHotString("Files of &type:"));
+    fTypes = new TGComboBox(fHftype, kIDF_FTYPESLB);
+    fTypes->Associate(this);
+    fTypes->Resize(230, fName->GetDefaultHeight());
+
+    TString s;
+    for (i = 0; fFileInfo->fFileTypes[i] != 0; i += 2)
+    {
+        s.Form("%s (%s)", fFileInfo->fFileTypes[i], fFileInfo->fFileTypes[i + 1]);
+        fTypes->AddEntry(s.Data(), i);
+    }
+    fTypes->Select(fFileInfo->fFileTypeIdx);
+
+    // Show all items in combobox without scrollbar
+    // TGDimension fw = fTypes->GetListBox()->GetContainer()->GetDefaultSize();
+    // fTypes->GetListBox()->Resize(fw.fWidth, fw.fHeight);
+
+    if (fFileInfo->fFilename && fFileInfo->fFilename[0])
+    {
+        fTbfname->AddText(0, fFileInfo->fFilename);
+    }
+    else
+    {
+        fTbfname->Clear();
+        if (dlg_type == kNFDSave)
+        {
+            fTbfname->AddText(0, "unnamed");
+            fName->SelectAll();
+            if (fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx + 1] &&
+                strstr(fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx + 1], "*."))
+            {
+                TString ext = fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx + 1];
+                ext.ReplaceAll("*.", ".");
+                fTbfname->AddText(7, ext.Data());
+            }
+            fName->SetFocus();
+        }
+    }
+
+    fTypes->GetListBox()->Resize(230, 120);
+    if (dlg_type == kNDOpen || dlg_type == kNDSave)
+    {
+        fTypes->SetEnabled(kFALSE);
+    }
+
+    fHftype->AddFrame(fLftypes, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 5, 2, 2));
+    fHftype->AddFrame(fTypes, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 20, 2, 2));
+
+    fVf->AddFrame(fHftype, new TGLayoutHints(kLHintsLeft | kLHintsCenterY | kLHintsExpandX));
+
+    fHf->AddFrame(fVf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY | kLHintsExpandX));
+
+    //--- Open/Save and Cancel buttons
+
+    TGVerticalFrame *fVbf = new TGVerticalFrame(fHf, 10, 10, kFixedWidth);
+
+    fOk = new TGTextButton(fVbf, new TGHotString((dlg_type == kNFDSave || dlg_type == kNDSave) ? "&Save" : "&Open"), kIDF_OK);
+    fCancel = new TGTextButton(fVbf, new TGHotString("Cancel"), kIDF_CANCEL);
+
+    fOk->Associate(this);
+    fCancel->Associate(this);
+
+    fVbf->AddFrame(fOk, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));
+    fVbf->AddFrame(fCancel, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 0, 0, 2, 2));
+
+    UInt_t width = TMath::Max(fOk->GetDefaultWidth(), fCancel->GetDefaultWidth()) + 20;
+    fVbf->Resize(width + 20, fVbf->GetDefaultHeight());
+
+    fHf->AddFrame(fVbf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
+
+    AddFrame(fHf, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 4, 4, 3, 1));
+    SetEditDisabled(kEditDisable);
+
+    MapSubwindows();
+
+    TGDimension size = GetDefaultSize();
+
+    Resize(size);
+
+    //---- position relative to the parent's window
+
+    CenterOnParent();
+
+    //---- make the message box non-resizable
+
+    SetWMSize(size.fWidth, size.fHeight);
+    SetWMSizeHints(size.fWidth, size.fHeight, 10000, 10000, 1, 1);
+
+    const char *wname = (dlg_type == kNFDSave || dlg_type == kNDSave) ? "Save As..." : "Open";
+    SetWindowName(wname);
+    SetIconName(wname);
+    SetClassHints("ROOT", "FileDialog");
+
+    SetMWMHints(kMWMDecorAll | kMWMDecorResizeH | kMWMDecorMaximize |
+                    kMWMDecorMinimize | kMWMDecorMenu,
+                kMWMFuncAll | kMWMFuncResize | kMWMFuncMaximize |
+                    kMWMFuncMinimize,
+                kMWMInputModeless);
+
+    MapWindow();
+    fFc->DisplayDirectory();
+    if (dlg_type == kNFDSave || dlg_type == kNDSave)
+        fName->SetFocus();
+
+    fClient->NeedRedraw(fFc);
+    fFv->SetViewMode(kLVDetails);
+    fClient->NeedRedraw(fFc);
+    fClient->WaitFor(this);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Delete file dialog.
+
+TGNewFileDialog::~TGNewFileDialog()
+{
+    if (IsZombie())
+        return;
+    TString str = fCheckB ? fCheckB->GetString() : TString();
+    if (str.Contains("Multiple") && fCheckB)
+        fCheckB->Disconnect("Toggled(Bool_t)");
+    fClient->FreePicture(fPcdup);
+    fClient->FreePicture(fPnewf);
+    fClient->FreePicture(fPlist);
+    fClient->FreePicture(fPdetails);
+    delete fFc;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Close file dialog.
+
+void TGNewFileDialog::CloseWindow()
+{
+    fFileInfo->SetFilename(nullptr);
+    fFileInfo->DeleteFileNamesList();
+    DeleteWindow();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Small function used to prevent memory leaks with TSystem::ExpandPathName,
+/// which returns a string created by StrDup, that has to be deleted
+
+namespace
+{
+    static inline void pExpandUnixPathName(TGFileInfo &file_info)
+    {
+        char *tmpPath = gSystem->ExpandPathName(file_info.fFilename);
+        file_info.SetFilename(gSystem->UnixPathName(tmpPath));
+        delete[] tmpPath;
+    }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Process messages generated by the user input in the file dialog.
+
+Bool_t TGNewFileDialog::ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t)
+{
+    if (!fFc->GetDisplayStat())
+        return kTRUE; // Cancel button was pressed
+
+    TGTreeLBEntry *e;
+    TGTextLBEntry *te;
+    TGFileItem *f;
+    void *p = 0;
+    TString txt;
+    TString sdir = gSystem->WorkingDirectory();
+
+    switch (GET_MSG(msg))
+    {
+    case kC_COMMAND:
+        switch (GET_SUBMSG(msg))
+        {
+        case kCM_BUTTON:
+            switch (parm1)
+            {
+            case kIDF_OK:
+                // same code as under kTE_ENTER
+                if (fTbfname->GetTextLength() == 0)
+                {
+                    txt = "Please provide file name or use \"Cancel\"";
+                    new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
+                                 "Missing File Name", txt, kMBIconExclamation,
+                                 kMBOk);
+                    return kTRUE;
+                }
+                else if (!gSystem->AccessPathName(fTbfname->GetString(), kFileExists) &&
+                         !strcmp(fOk->GetTitle(), "Save") && fCheckB &&
+                         (!(fCheckB->GetState() == kButtonDown)))
+                {
+                    Int_t ret;
+                    txt = TString::Format("File name %s already exists, OK to overwrite it?",
+                                          fTbfname->GetString());
+                    new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
+                                 "File Name Exist", txt.Data(), kMBIconExclamation,
+                                 kMBYes | kMBNo, &ret);
+                    if (ret == kMBNo)
+                        return kTRUE;
+                }
+                if (fFileInfo->fMultipleSelection)
+                {
+                    fFileInfo->SetFilename(nullptr);
+                }
+                else
+                {
+                    fFileInfo->SetFilename(nullptr);
+                    // FIXME: once appropriate gSystem method exists, use SetFilename here
+                    if (gSystem->IsAbsoluteFileName(fTbfname->GetString()))
+                        fFileInfo->SetFilename(fTbfname->GetString());
+                    else
+                        fFileInfo->fFilename = gSystem->ConcatFileName(fFc->GetDirectory(),
+                                                                       fTbfname->GetString());
+                    pExpandUnixPathName(*fFileInfo);
+                }
+                if (fCheckB && (fCheckB->GetState() == kButtonDown))
+                    fFileInfo->fOverwrite = kTRUE;
+                else
+                    fFileInfo->fOverwrite = kFALSE;
+                DeleteWindow();
+                break;
+
+            case kIDF_CANCEL:
+                fFileInfo->SetFilename(nullptr);
+                if (fDlgType == kNDOpen || fDlgType == kNDSave)
+                    fFileInfo->SetIniDir(nullptr);
+                if (fFc->GetDisplayStat())
+                    fFc->SetDisplayStat(kFALSE);
+                fFileInfo->DeleteFileNamesList();
+                DeleteWindow();
+                return kTRUE; // no need to redraw fFc
+                break;
+
+            case kIDF_CDUP:
+                fFc->ChangeDirectory("..");
+                fTreeLB->Update(fFc->GetDirectory());
+                fFileInfo->SetIniDir(fFc->GetDirectory());
+                if (strcmp(gSystem->WorkingDirectory(), fFc->GetDirectory()))
+                {
+                    gSystem->cd(fFc->GetDirectory());
+                }
+                break;
+
+            case kIDF_NEW_FOLDER:
+            {
+                char answer[128];
+                strlcpy(answer, "(empty)", sizeof(answer));
+                new TGInputDialog(gClient->GetRoot(), GetMainFrame(),
+                                  "Enter directory name:",
+                                  answer /*"(empty)"*/, answer);
+
+                while (strcmp(answer, "(empty)") == 0)
+                {
+                    new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
+                                 "Please enter a valid directory name.",
+                                 kMBIconStop, kMBOk);
+                    new TGInputDialog(gClient->GetRoot(), GetMainFrame(),
+                                      "Enter directory name:",
+                                      answer, answer);
+                }
+                if (strcmp(answer, "") == 0) // Cancel button was pressed
+                    break;
+
+                if (strcmp(gSystem->WorkingDirectory(), fFc->GetDirectory()))
+                {
+                    gSystem->cd(fFc->GetDirectory());
+                }
+                if (gSystem->MakeDirectory(answer) != 0)
+                    new TGMsgBox(gClient->GetRoot(), GetMainFrame(), "Error",
+                                 TString::Format("Directory name \'%s\' already exists!", answer),
+                                 kMBIconStop, kMBOk);
+                else
+                {
+                    fFc->DisplayDirectory();
+                }
+                gSystem->ChangeDirectory(sdir.Data());
+                break;
+            }
+
+            case kIDF_LIST:
+                fFv->SetViewMode(kLVList);
+                fDetails->SetState(kButtonUp);
+                break;
+
+            case kIDF_DETAILS:
+                fFv->SetViewMode(kLVDetails);
+                fList->SetState(kButtonUp);
+                break;
+            }
+            break;
+
+        case kCM_COMBOBOX:
+            switch (parm1)
+            {
+            case kIDF_FSLB:
+                e = (TGTreeLBEntry *)fTreeLB->GetSelectedEntry();
+                if (e)
+                {
+                    fFc->ChangeDirectory(e->GetPath()->GetString());
+                    fTreeLB->Update(fFc->GetDirectory());
+                    fFileInfo->SetIniDir(fFc->GetDirectory());
+                    if (strcmp(gSystem->WorkingDirectory(), fFc->GetDirectory()))
+                    {
+                        gSystem->cd(fFc->GetDirectory());
+                    }
+                }
+                break;
+
+            case kIDF_FTYPESLB:
+                te = (TGTextLBEntry *)fTypes->GetSelectedEntry();
+                if (te)
+                {
+                    // fTbfname->Clear();
+                    // fTbfname->AddText(0, fFileInfo->fFileTypes[te->EntryId()+1]);
+                    fFileInfo->fFileTypeIdx = te->EntryId();
+                    fFc->SetFilter(fFileInfo->fFileTypes[fFileInfo->fFileTypeIdx + 1]);
+                    fFc->DisplayDirectory();
+                    fClient->NeedRedraw(fName);
+                }
+                break;
+            }
+            break;
+
+        default:
+            break;
+        } // switch(GET_SUBMSG(msg))
+        break;
+
+    case kC_CONTAINER:
+        switch (GET_SUBMSG(msg))
+        {
+        case kCT_ITEMCLICK:
+            if (parm1 == kButton1)
+            {
+                if (fFc->NumSelected() > 0)
+                {
+                    if (fFileInfo->fMultipleSelection == kFALSE)
+                    {
+                        TGLVEntry *e2 = (TGLVEntry *)fFc->GetNextSelected(&p);
+                        if (fDlgType == kNFDOpen || fDlgType == kNFDSave)
+                        {
+                            if ((e2) && !R_ISDIR(((TGFileItem *)e2)->GetType()))
+                            {
+                                fTbfname->Clear();
+                                if (e2->GetItemName())
+                                    fTbfname->AddText(0, e2->GetItemName()->GetString());
+                                fClient->NeedRedraw(fName);
+                            }
+                        }
+                        else
+                        {
+                            if ((e2) && R_ISDIR(((TGFileItem *)e2)->GetType()))
+                            {
+                                fTbfname->Clear();
+                                if (e2->GetItemName())
+                                    fTbfname->AddText(0, e2->GetItemName()->GetString());
+                                fClient->NeedRedraw(fName);
+                                fOk->SetEnabled(kTRUE);
+                            }
+                            else if ((e2))
+                            {
+                                fOk->SetEnabled(kFALSE);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        TString tmpString;
+                        TList *tmp = fFc->GetSelectedItems();
+                        TObjString *el;
+                        TIter next(tmp);
+                        if (fFileInfo->fFileNamesList)
+                        {
+                            fFileInfo->fFileNamesList->Delete();
+                        }
+                        else
+                        {
+                            fFileInfo->fFileNamesList = new TList();
+                        }
+                        while ((el = (TObjString *)next()))
+                        {
+                            char *s = gSystem->ConcatFileName(fFc->GetDirectory(),
+                                                              el->GetString());
+                            tmpString += "\"" + el->GetString() + "\" ";
+                            fFileInfo->fFileNamesList->Add(new TObjString(s));
+                            delete[] s;
+                        }
+                        tmp->Delete();
+                        delete tmp;
+                        fTbfname->Clear();
+                        fTbfname->AddText(0, tmpString);
+                        fClient->NeedRedraw(fName);
+                    }
+                }
+            }
+            break;
+
+        case kCT_ITEMDBLCLICK:
+
+            if (parm1 == kButton1)
+            {
+                if (fFc->NumSelected() == 1)
+                {
+                    f = (TGFileItem *)fFc->GetNextSelected(&p);
+                    if (f && R_ISDIR(f->GetType()))
+                    {
+                        fFc->ChangeDirectory(f->GetItemName()->GetString());
+                        fTreeLB->Update(fFc->GetDirectory());
+                        fFileInfo->SetIniDir(fFc->GetDirectory());
+                        if (strcmp(gSystem->WorkingDirectory(), fFc->GetDirectory()))
+                        {
+                            gSystem->cd(fFc->GetDirectory());
+                        }
+                        if (fDlgType == kNDOpen || fDlgType == kNDSave)
+                        {
+                            fTbfname->Clear();
+                            fTbfname->AddText(0, fFc->GetDirectory());
+                            fClient->NeedRedraw(fName);
+                        }
+                    }
+                    else if (fDlgType == kNFDOpen || fDlgType == kNFDSave)
+                    {
+                        if (!strcmp(fOk->GetTitle(), "Save") && fCheckB &&
+                            (!(fCheckB->GetState() == kButtonDown)))
+                        {
+
+                            Int_t ret;
+                            txt = TString::Format("File name %s already exists, OK to overwrite it?",
+                                                  fTbfname->GetString());
+                            new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
+                                         "File Name Exist", txt.Data(), kMBIconExclamation,
+                                         kMBYes | kMBNo, &ret);
+                            if (ret == kMBNo)
+                                return kTRUE;
+                        }
+                        fFileInfo->SetFilename(nullptr);
+                        // FIXME: once appropriate gSystem method exists, use SetFilename here
+                        if (gSystem->IsAbsoluteFileName(fTbfname->GetString()))
+                            fFileInfo->SetFilename(fTbfname->GetString());
+                        else
+                            fFileInfo->fFilename = gSystem->ConcatFileName(fFc->GetDirectory(),
+                                                                           fTbfname->GetString());
+                        pExpandUnixPathName(*fFileInfo);
+                        if (fCheckB && (fCheckB->GetState() == kButtonDown))
+                            fFileInfo->fOverwrite = kTRUE;
+                        else
+                            fFileInfo->fOverwrite = kFALSE;
+
+                        DeleteWindow();
+                    }
+                }
+            }
+
+            break;
+
+        default:
+            break;
+
+        } // switch(GET_SUBMSG(msg))
+        break;
+
+    case kC_TEXTENTRY:
+        // when typing, re-enable previously disabled button after having clicked on file instead of folder
+        if ((fDlgType == kNDOpen || fDlgType == kNDSave) && fOk->GetState() == kButtonDisabled)
+            fOk->SetEnabled(kTRUE);
+
+        switch (GET_SUBMSG(msg))
+        {
+        case kTE_ENTER:
+            // same code as under kIDF_OK
+            if (fTbfname->GetTextLength() == 0)
+            {
+                const char *txt2 = "Please provide file name or use \"Cancel\"";
+                new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
+                             "Missing File Name", txt2, kMBIconExclamation,
+                             kMBOk);
+                return kTRUE;
+            }
+            else if (!gSystem->AccessPathName(fTbfname->GetString(), kFileExists))
+            {
+                FileStat_t buf;
+                if (!gSystem->GetPathInfo(fTbfname->GetString(), buf) &&
+                    R_ISDIR(buf.fMode))
+                {
+                    fFc->ChangeDirectory(fTbfname->GetString());
+                    fTreeLB->Update(fFc->GetDirectory());
+                    if (strcmp(gSystem->WorkingDirectory(), fFc->GetDirectory()))
+                    {
+                        gSystem->cd(fFc->GetDirectory());
+                    }
+                    fName->SetText("", kFALSE);
+                    return kTRUE;
+                }
+                else if (!strcmp(fOk->GetTitle(), "Save") && fCheckB &&
+                         (!(fCheckB->GetState() == kButtonDown)))
+                {
+                    Int_t ret;
+                    txt = TString::Format("File name %s already exists, OK to overwrite it?",
+                                          fTbfname->GetString());
+                    new TGMsgBox(fClient->GetRoot(), GetMainFrame(),
+                                 "File Name Exist", txt.Data(), kMBIconExclamation,
+                                 kMBYes | kMBNo, &ret);
+                    if (ret == kMBNo)
+                        return kTRUE;
+                }
+            }
+            fFileInfo->SetFilename(nullptr);
+            // FIXME: once appropriate gSystem method exists, use SetFilename here
+            fFileInfo->fFilename = gSystem->ConcatFileName(fFc->GetDirectory(),
+                                                           fTbfname->GetString());
+            pExpandUnixPathName(*fFileInfo);
+            if (fCheckB && (fCheckB->GetState() == kButtonDown))
+                fFileInfo->fOverwrite = kTRUE;
+            else
+                fFileInfo->fOverwrite = kFALSE;
+            DeleteWindow();
+            break;
+
+        default:
+            break;
+        }
+        break;
+
+    default:
+        break;
+
+    } // switch(GET_MSG(msg))
+
+    fClient->NeedRedraw(fFc);
+    return kTRUE;
+}
+
diff --git a/TGNewFileDialog.hxx b/TGNewFileDialog.hxx
new file mode 100644
index 0000000..1686442
--- /dev/null
+++ b/TGNewFileDialog.hxx
@@ -0,0 +1,102 @@
+// @(#)root/gui:$Id$
+// Author: Fons Rademakers   20/01/98
+
+/*************************************************************************
+ * Copyright (C) 1995-2021, Rene Brun and Fons Rademakers.               *
+ * All rights reserved.                                                  *
+ *                                                                       *
+ * For the licensing terms see $ROOTSYS/LICENSE.                         *
+ * For the list of contributors see $ROOTSYS/README/CREDITS.             *
+ *************************************************************************/
+
+#ifndef ROOT_TGNewFileDialog
+#define ROOT_TGNewFileDialog
+
+#include "TGFrame.h"
+#include "TGFileDialog.h"
+enum ENewFileDialogMode
+{
+    kNFDOpen,
+    kNFDSave,
+    kNDOpen,
+    kNDSave
+};
+
+class TGTextBuffer;
+class TGTextEntry;
+class TGComboBox;
+class TGPictureButton;
+class TGTextButton;
+class TGCheckButton;
+class TGListView;
+class TGFileContainer;
+class TGFSComboBox;
+/*
+class TGFileInfo
+{
+
+private:
+    TGFileInfo(const TGFileInfo &) = delete;
+    TGFileInfo &operator=(const TGFileInfo &) = delete;
+
+public:
+    char *fFilename{nullptr};          ///< selected file name
+    char *fIniDir{nullptr};            ///< on input: initial directory, on output: new directory
+    const char **fFileTypes{nullptr};  ///< file types used to filter selectable files
+    Int_t fFileTypeIdx{0};             ///< selected file type, index in fFileTypes
+    Bool_t fOverwrite{kFALSE};         ///< if true overwrite the file with existing name on save
+    Bool_t fMultipleSelection{kFALSE}; ///< if true, allow multiple file selection
+    TList *fFileNamesList{nullptr};    ///< list of selected file names
+
+    TGFileInfo() = default;
+    ~TGFileInfo();
+
+    void SetFilename(const char *fname);
+    void SetIniDir(const char *inidir);
+    void DeleteFileNamesList();
+
+    void SetMultipleSelection(Bool_t option);
+};
+*/
+class TGNewFileDialog : public TGTransientFrame
+{
+
+protected:
+    TGTextBuffer *fTbfname;     ///< text buffer of file name
+    TGTextEntry *fName;         ///< file name text entry
+    TGComboBox *fTypes;         ///< file type combo box
+    TGFSComboBox *fTreeLB;      ///< file system path combo box
+    TGPictureButton *fCdup;     ///< top toolbar button
+    TGPictureButton *fNewf;     ///< top toolbar button
+    TGPictureButton *fList;     ///< top toolbar button
+    TGPictureButton *fDetails;  ///< top toolbar button
+    TGCheckButton *fCheckB;     ///< set on/off file overwriting for Open dialog
+                                ///< OR set on/off multiple file selection for SaveAs dialog
+    const TGPicture *fPcdup;    ///< picture for fCdup
+    const TGPicture *fPnewf;    ///< picture for fNewf
+    const TGPicture *fPlist;    ///< picture for fList
+    const TGPicture *fPdetails; ///< picture for fDetails
+    TGTextButton *fOk;          ///< ok button
+    TGTextButton *fCancel;      ///< cancel button
+    TGListView *fFv;            ///< file list view
+    TGFileContainer *fFc;       ///< file list view container (containing the files)
+    TGFileInfo *fFileInfo;      ///< file info passed to this dialog
+    ENewFileDialogMode fDlgType;   ///< the dialog type passed
+
+private:
+    TGNewFileDialog(const TGNewFileDialog &) = delete;
+    TGNewFileDialog &operator=(const TGNewFileDialog &) = delete;
+
+public:
+    TGNewFileDialog(const TGWindow *p = nullptr, const TGWindow *main = nullptr,
+                 ENewFileDialogMode dlg_type = kNFDOpen, TGFileInfo *file_info = nullptr);
+    virtual ~TGNewFileDialog();
+
+    Bool_t ProcessMessage(Longptr_t msg, Longptr_t parm1, Longptr_t parm2) override;
+    void CloseWindow() override;
+
+    ClassDefOverride(TGNewFileDialog, 0) // File selection dialog
+};
+
+#endif
+
diff --git a/TGNewFileDialog_LinkDef.h b/TGNewFileDialog_LinkDef.h
new file mode 100644
index 0000000..d0d299d
--- /dev/null
+++ b/TGNewFileDialog_LinkDef.h
@@ -0,0 +1,10 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class TGNewFileDialog;
+
+#endif
+
diff --git a/compileDialog.sh b/compileDialog.sh
new file mode 100644
index 0000000..76ea562
--- /dev/null
+++ b/compileDialog.sh
@@ -0,0 +1,2 @@
+rootcling -f newfdg.cxx TGNewFileDialog.hxx TGNewFileDialog_LinkDef.h
+g++ -fPIC -O2 -g -Wall -c newfdg.cxx TGNewFileDialog.cxx `root-config --cflags`
-- 
GitLab