]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
Anylyzer: Fixed summary and canvas drawing with ROOT 6
authorBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Fri, 8 May 2015 16:28:46 +0000 (18:28 +0200)
committerBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Fri, 8 May 2015 16:28:46 +0000 (18:28 +0200)
MABS_run_analyzer/ChargeSpektrum.c
MABS_run_analyzer/Run.c
MABS_run_analyzer/Run.h

index dccc79728e581964b9dbccca9b1ac60d4319eec0..0b5d8a18cbe7673bc1a7d3000c8385f86072b761 100644 (file)
@@ -85,20 +85,20 @@ void ChargeSpektrum(Int_t runnumber = -1)
         runs[runi]->setResultsPath("./results/");
         runs[runi]->setPlotStyle(runi);
         runs[runi]->useDynamicalNoise(true);
-        runs[runi]->analyzeRun(true); // creates or opens .root file, can analyze the RAW data
+        runs[runi]->analyzeRun(false); // creates or opens .root file, can analyze the RAW data
 //         gROOT->SetBatch(kTRUE);
 //           runs[runi]->plotSeed();
 //         runs[runi]->plotSum();
 //         runs[runi]->plotVeto();
-//         runs[runi]->plotNoise();
+        //         runs[runi]->plotNoise();
         if (!isBatch)
             gROOT->SetBatch(kFALSE);
         runs[runi]->plotAllHistograms();
         runs[runi]->plotAllHistogramsThresholdCluster();
-//          runs[runi]->plotAllHistogramsCalibrated(); 
+         runs[runi]->plotAllHistogramsCalibrated(); 
         runs[runi]->writeAllHistogramsToFile(); 
     }
-//     plotAllRuns();  
+    plotAllRuns();  
 }
 
 Int_t* ReadRunList()
@@ -132,63 +132,59 @@ Int_t* ReadRunList()
 
 void plotAllRuns()
 {
-    Float_t lastbin;
-    TTimeStamp* time = new TTimeStamp();
-    
-    cout << "-2" << endl;
-    TCanvas* canvas = new TCanvas(Form("%d",time->GetNanoSec()), "Summary", 1600, 1000);
-//     cout << "-1" << endl;
-//     if (isBatch)
-//         canvas->SetCanvasSize(1600,1000);
-//     
-//     cout << "0" << endl;
-//     canvas->Divide(2,2);
-//     Float_t height = numberRuns * 0.04;
-//     cout << "1" << endl;
-//     TLegend* leg1 = new TLegend(0.3,1.0-height,0.89,0.89);//(0.6,0.7,0.89,0.89);
-//     TLegend* leg2 = new TLegend(0.6,1.0-height,0.89,0.89);//(0.6,0.7,0.89,0.89);
-//     cout << "2" << endl;
-//     leg1->SetTextSize(0.02);
-//     leg2->SetTextSize(0.02);
-//     cout << "3" << endl;
-//     leg1->SetFillColor(0); leg1->SetBorderSize(0);
-//     leg2->SetFillColor(0); leg2->SetBorderSize(0);
-//     cout << "4" << endl;
-//     TString  legendEntry;
-//     
-//     for(Int_t runi=0;runi<numberRuns;runi++) // loop over runs read from file
-//     {
-//         canvas->cd(1);
-//         runs[runi]->histogram.Seed->Draw("SAME");
-//         lastbin = runs[runi]->histogram.Seed->GetBinCenter(runs[runi]->histogram.Seed->FindLastBinAbove(2,1));
-//         runs[runi]->histogram.Seed->SetAxisRange(0,lastbin*1.1,"X");
-//         gPad->SetLogy(1);
-//         legendEntry = Form("%s", runs[runi]->histogram.Seed->GetTitle());
-//         leg1->AddEntry(runs[runi]->histogram.Veto, legendEntry, "l");
-//         leg1->Draw("SAME");
-//         canvas->cd(2);
-//         runs[runi]->histogram.Sum->Draw("SAME");
-//         lastbin = runs[runi]->histogram.Sum->GetBinCenter(runs[runi]->histogram.Sum->FindLastBinAbove(2,1));
-//         runs[runi]->histogram.Sum->SetAxisRange(0,lastbin*1.1,"X");
-//         canvas->cd(3);
-//         runs[runi]->histogram.Veto->Draw("SAME");
-//         runs[runi]->histogram.Veto->SetAxisRange(runs[runi]->histogram.posVeto*0.7,runs[runi]->histogram.posVeto*1.4,"X");
-//         canvas->cd(4);
-//         runs[runi]->histogram.Noise->Draw("SAME");
-//         legendEntry = Form("%s, Noise: %.2f", runs[runi]->labbook.matrix.Data(), runs[runi]->histogram.avgNoise);
-//         leg2->AddEntry(runs[runi]->histogram.Veto, legendEntry, "l");
-//         leg2->Draw("SAME");
-//     }
-//     
-//     //         canvas -> Print( runs[0]->savepathresults + "/" + canvastitle + ".eps");
-//     TImageDump *img = new TImageDump(runs[0]->savepathresults + "/" + Form("%s - %s",runs[0]->runcode.Data(), runs[numberRuns-1]->runcode.Data()) + ".png");
-//     canvas->Paint();
-//     img->Close();
-//     
-//     TFile *f = new TFile(runs[0]->savepathresults + "/" + Form("%s - %s",runs[0]->runcode.Data(),runs[numberRuns-1]->runcode.Data()) + ".root","RECREATE");
-//     f->cd();
-//     f->Append(canvas);
-//     f->Append(img);
-//     f->Write();
+    if (numberRuns > 1)
+    {
+        Float_t lastbin;
+        TTimeStamp* time = new TTimeStamp();
+        
+        TCanvas* canvas = new TCanvas(Form("%d",time->GetNanoSec()), "Summary", 1600, 1000);
+        if (isBatch)
+            canvas->SetCanvasSize(3200,2000);
+        
+        canvas->Divide(2,2);
+        Float_t height = numberRuns * 0.04;
+        TLegend* leg1 = new TLegend(0.3,0.89-height,0.89,0.89);//(0.6,0.7,0.89,0.89);
+        TLegend* leg2 = new TLegend(0.6,0.89-height,0.89,0.89);//(0.6,0.7,0.89,0.89);
+        leg1->SetTextSize(0.02);
+        leg2->SetTextSize(0.02);
+        leg1->SetFillColor(0); leg1->SetBorderSize(0);
+        leg2->SetFillColor(0); leg2->SetBorderSize(0);
+        TString  legendEntry;
+        
+        for(Int_t runi=0;runi<numberRuns;runi++) // loop over runs read from file
+        {
+            canvas->cd(1);
+            runs[runi]->histogram.Seed->Draw("SAME");
+            lastbin = runs[runi]->histogram.Seed->GetBinCenter(runs[runi]->histogram.Seed->FindLastBinAbove(2,1));
+            runs[runi]->histogram.Seed->SetAxisRange(0,lastbin*1.1,"X");
+            gPad->SetLogy(1);
+            legendEntry = Form("%s", runs[runi]->histogram.Seed->GetTitle());
+            leg1->AddEntry(runs[runi]->histogram.Veto, legendEntry, "l");
+            leg1->Draw("SAME");
+            canvas->cd(2);
+            runs[runi]->histogram.Sum->Draw("SAME");
+            lastbin = runs[runi]->histogram.Sum->GetBinCenter(runs[runi]->histogram.Sum->FindLastBinAbove(2,1));
+            runs[runi]->histogram.Sum->SetAxisRange(0,lastbin*1.1,"X");
+            canvas->cd(3);
+            runs[runi]->histogram.Veto->Draw("SAME");
+            runs[runi]->histogram.Veto->SetAxisRange(runs[runi]->histogram.posVeto*0.7,runs[runi]->histogram.posVeto*1.4,"X");
+            canvas->cd(4);
+            runs[runi]->histogram.Noise->Draw("SAME");
+            legendEntry = Form("%s, Noise: %.2f", runs[runi]->labbook.matrix.Data(), runs[runi]->histogram.avgNoise);
+            leg2->AddEntry(runs[runi]->histogram.Veto, legendEntry, "l");
+            leg2->Draw("SAME");
+        }
+        
+        //         canvas -> Print( runs[0]->savepathresults + "/" + canvastitle + ".eps");
+        TImageDump *img = new TImageDump(runs[0]->savepathresults + "/" + Form("%s - %s",runs[0]->runcode.Data(), runs[numberRuns-1]->runcode.Data()) + ".png");
+        canvas->Paint();
+        img->Close();
+        
+        TFile *f = new TFile(runs[0]->savepathresults + "/" + Form("%s - %s",runs[0]->runcode.Data(),runs[numberRuns-1]->runcode.Data()) + ".root","RECREATE");
+        f->cd();
+        f->Append(canvas);
+        f->Append(img);
+        f->Write();
+    }
 }
 
index 0d82e87c5d08fc5cbaa36fe492537b311c00383e..dec78f3de90f247a719aa10058277014f90663c3 100644 (file)
@@ -241,8 +241,10 @@ Bool_t Run::calculteCCE()
 {
     if (labbook.source.Contains("Fe"))
     {
-        CCE_in_Perc_1 = histogram.posSeed / histogram.posVeto * 100.0;
-        CCE_in_Perc_25 = histogram.posSum / histogram.posVeto * 100.0;
+        if (histogram.posSeed > 0 && histogram.posVeto > 0)
+            CCE_in_Perc_1 = histogram.posSeed / histogram.posVeto * 100.0;
+        if (histogram.posSum > 0 && histogram.posVeto > 0)
+            CCE_in_Perc_25 = histogram.posSum / histogram.posVeto * 100.0;
     }
     return 0;
 }
@@ -508,12 +510,15 @@ void Run::getVetoPeakPositionFromFe55Run()
 
 void Run::constructUpdateString(string *sqlupdatequery, const string databasevaluename, const Float_t value, const int precision=3)
 {
-//     cout << colorred << databasevaluename << " :  " << value << endlr;
-    if (value>0)
+    //     cout << colorred << databasevaluename << " :  " << value << endlr;
+    if (!isinf(value))
     {
-        if ((*sqlupdatequery).length() > 0)
-            *sqlupdatequery+= ", ";
-        *sqlupdatequery += "`" + databasevaluename + "`="+ to_str_w_prec(value, precision);
+        if (value>0)
+        {
+            if ((*sqlupdatequery).length() > 0)
+                *sqlupdatequery+= ", ";
+            *sqlupdatequery += "`" + databasevaluename + "`="+ to_str_w_prec(value, precision);
+        }
     }
 }
 
@@ -625,16 +630,16 @@ Bool_t Run::binSeedSumVeto()
             }
         }
     }
-    gROOT->SetBatch(kTRUE);
+//     gROOT->SetBatch(kTRUE);
     if (labbook.source.Contains("Fe"))
-        histogram.posVeto=FitPerform(histogram.Veto, "gaus");
-    histogram.posSeed=FitPerform(histogram.Seed);
-    histogram.posSum=FitPerform(histogram.Sum, "gaus");
+        histogram.posVeto=FitPerform(histogram.Veto, "gaus", true);
+    histogram.posSeed=FitPerform(histogram.Seed, "landau", true);
+    histogram.posSum=FitPerform(histogram.Sum, "gaus", true);
     if (labbook.source.Contains("Fe"))
-        histogramthreshold.posVeto=FitPerform(histogram.Veto, "gaus");
-    histogramthreshold.posSeed=FitPerform(histogram.Seed);
-    histogramthreshold.posSum=FitPerform(histogram.Sum, "gaus");
-    gROOT->SetBatch(kFALSE);
+        histogramthreshold.posVeto=FitPerform(histogram.Veto, "gaus", false);
+    histogramthreshold.posSeed=FitPerform(histogram.Seed, "landau", false);
+    histogramthreshold.posSum=FitPerform(histogram.Sum, "gaus", false);
+    //     gROOT->SetBatch(kFALSE);    
     return 0;
 }
 
@@ -837,7 +842,7 @@ Float_t Run::FitPerform(TH1F* histogrampointer, TString fitFuncType, Bool_t verb
             Float_t sigma = fitFunc->GetParameter(2);
             posMax2 = fitFunc->GetMaximumX(); // Methode 2
             Float_t peakposdifperc = abs(posMax-posMax2)/min(posMax,posMax2);
-            if (sigma > 260 || peakposdifperc>0.2)
+            if (sigma > 260 || peakposdifperc>0.3)
             {
                 if (verbose)
                 {
@@ -846,13 +851,13 @@ Float_t Run::FitPerform(TH1F* histogrampointer, TString fitFuncType, Bool_t verb
                         cout << "Sigma suspiciously height when fitting " << histogrampointer->GetName() << " spectrum: " << sigma  << endl;
                         cout << colorred << "  Could not find " << histogrampointer->GetName() << " peak" << endlr;
                     }
-                    if (peakposdifperc>0.2)
+                    else if (peakposdifperc>0.3)
                     {
                         cout << "Maximum peak position and fit gaussian peak position doesn't match in " << histogrampointer->GetName() << " spectrum. Difference: " <<  peakposdifperc*100 <<" % " << endl;
                         cout << colorred << "  Could not find " << histogrampointer->GetName() << " peak" << endlr;
                     }
                 }
-                return posMax;
+                return 0;
             }
             else if (sigma > 40 || peakposdifperc>0.1)
             {
@@ -863,21 +868,21 @@ Float_t Run::FitPerform(TH1F* histogrampointer, TString fitFuncType, Bool_t verb
                         cout << "Sigma or  suspiciously height when fitting " << histogrampointer->GetName() << " spectrum: " << sigma  << endl;
                         cout << coloryellow << "  Please check " << histogrampointer->GetName() << " peak position: " << colorreset << colorwhite << posMax  << endlr;
                     }
-                    if (peakposdifperc>0.1)
+                    else if (peakposdifperc>0.1)
                     {
                         cout << "Maximum peak position and fit gaussian peak position in " << histogrampointer->GetName() << " have difference of " <<  peakposdifperc*100 <<" % " << endl;
                         cout << coloryellow << "  Please check " << histogrampointer->GetName() << " peak position: " << colorreset << colorwhite << posMax  << endlr;
                     }
                 }
             }       
-            fitFunc->DrawCopy("same");
+//             fitFunc->DrawCopy("same");
             TString  legendEntry = TString(Form("%s",runcode.Data()));
             TLegend* leg = new TLegend(0.5,0.5,0.89,0.89);//(0.6,0.7,0.89,0.89);
             //   leg->SetHeader();//"Legend Title");
             leg->SetFillStyle(0);
             leg->AddEntry((TObject*) 0, legendEntry, "");
             leg->SetTextSize(0.05);
-            leg->Draw();
+//               leg->Draw();
             
         }
         else if (fitFuncType=="landau") 
@@ -889,17 +894,17 @@ Float_t Run::FitPerform(TH1F* histogrampointer, TString fitFuncType, Bool_t verb
             Float_t maxFitMax = 1000;
             histogrampointer->Fit(fitFunc, "N,Q,W", "", noiseborder, posMaxValHist);
             fitMax1 = fitFunc->GetMaximumX();
-            fitFunc->DrawCopy("same");         
+//             fitFunc->DrawCopy("same");         
             histogrampointer->Fit(fitFunc, "N,Q,W", "", noiseborder, fitMax1*1.1);
             fitMax2 = fitFunc->GetMaximumX();
             fitFunc->SetLineColor(kBlue);
             fitFunc->SetLineStyle(2); // dashed
-            fitFunc->DrawCopy("same");
+//             fitFunc->DrawCopy("same");
             histogrampointer->Fit(fitFunc, "N,Q,W", "", fitMax1*0.9, posMaxValHist);
 //             histogrampointer->Fit(fitFunc, "N,Q,W", "", fitMax1, histogrampointer->GetBinCenter(bini));
             fitMax3 = fitFunc->GetMaximumX();
             fitFunc->SetLineColor(kGreen);
-            fitFunc->DrawCopy("same");
+//             fitFunc->DrawCopy("same");
             fitFunc->SetLineStyle(1); // normal for the following fits
             
             // Sort the three fits and save error estimation
@@ -927,7 +932,7 @@ void Run::plotVerticalLine(TH1F* histogrampointer, Float_t xVal) {
         l->Draw("same"); 
 
         TString  legendEntry = TString(Form("peak position: %.1f",xVal ));
-        TLegend* leg = new TLegend(0.5,0.8,0.89,0.89);//(0.6,0.7,0.89,0.89);
+        TLegend* leg = new TLegend(0.5,0.8,0.6,0.89);//(0.6,0.7,0.89,0.89);
         leg->SetFillColor(0);
         leg->SetBorderSize(0);
         leg->AddEntry((TObject*) 0, legendEntry, "");
@@ -946,7 +951,7 @@ TCanvas* Run::plot1DHistogram(TH1F* onehistogram, TString fitFuncType, TString t
     TCanvas* canvas = new TCanvas(canvasname, canvastitle, 900, 700);
     onehistogram->SetTitle(titlestr);
     onehistogram->Draw();
-    Float_t maxValue = FitPerform(onehistogram, fitFuncType, false);
+    Float_t maxValue = FitPerform(onehistogram, fitFuncType);
     plotVerticalLine(onehistogram, maxValue);
     TLegend* leg = new TLegend(0.8,0.8,0.89,0.89);//(0.6,0.7,0.89,0.89);
     leg->SetFillColor(0);
@@ -1128,24 +1133,29 @@ void Run::MakeGnuplotFile()
 }
 
 void Run::initHistograms(histogramstruct* histogramstructpointer, TString suffix)
-{
-    if (suffix.Contains("threshold"))
-        histogramstructpointer->thresholdcluster = 1;
-    
+{    
     initHistogram(histogramstructpointer->Seed, "Seed" + suffix);
     initHistogram(histogramstructpointer->Sum, "Sum" + suffix);
     initHistogram(histogramstructpointer->Veto, "Veto" + suffix);
     
     TString prefix = "Noise" + suffix;
     TString humanreadablestr = Form("%s, %s spectrum, Mi%s, chip %s, %s, T=%.1f",prefix.Data(), labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), labbook.temp);
-    histogramstructpointer->Noise=new TH1F(prefix.Data(), humanreadablestr.Data(), systemparamcur.nbinsnoise, 0, systemparamcur.maxbinnoise);  
-    histogramstructpointer->Noise->SetLineStyle(rootlinestyle[plotStyle]);
-    histogramstructpointer->Noise->SetLineColor(rootcolors[plotStyle]);
-    histogramstructpointer->Noise->SetLineWidth(3); 
-    histogramstructpointer->Noise->GetXaxis()->SetTitle("Q_coll [ADU]");
-    histogramstructpointer->Noise->GetYaxis()->SetTitle(Form("Entries [1/%.1f ADU]",histogramstructpointer->Noise->GetBinWidth(1)));
-    histogramstructpointer->Noise->GetXaxis()->CenterTitle();
-    histogramstructpointer->Noise->GetYaxis()->CenterTitle();
+    if (suffix.Contains("threshold"))
+    {
+        histogramstructpointer->thresholdcluster = 1;
+        histogramstructpointer->Noise = histogram.Noise;
+    }
+    else
+    {
+        histogramstructpointer->Noise=new TH1F(prefix.Data(), humanreadablestr.Data(), systemparamcur.nbinsnoise, 0, systemparamcur.maxbinnoise);  
+        histogramstructpointer->Noise->SetLineStyle(rootlinestyle[plotStyle]);
+        histogramstructpointer->Noise->SetLineColor(rootcolors[plotStyle]);
+        histogramstructpointer->Noise->SetLineWidth(3); 
+        histogramstructpointer->Noise->GetXaxis()->SetTitle("Q_coll [ADU]");
+        histogramstructpointer->Noise->GetYaxis()->SetTitle(Form("Entries [1/%.1f ADU]",histogramstructpointer->Noise->GetBinWidth(1)));
+        histogramstructpointer->Noise->GetXaxis()->CenterTitle();
+        histogramstructpointer->Noise->GetYaxis()->CenterTitle();
+    }
 }
 
 void Run::initHistogram(TH1F* &histogrampointer, TString prefix)
index 08e9d51bcd0a794fc4290ec8948dfe9875d8470a..9c42288b94ce1128689cca5cfeba5d65c4a0683c 100644 (file)
@@ -4,6 +4,7 @@
 #include <iomanip>
 #include <sstream>
 #include "sys/stat.h"
+#include <math.h>       /* isinf, sqrt */
 
 #include <TSQLServer.h>
 #include <TSQLResult.h>